Skip to content

SIDDARTHA577/envguard-node / .agents/skills/envguard-load-test

envguard-load-test

Verified

Guides capacity planning, workload profile design, local performance benchmarking, and threshold validation without fabricating production metrics or executing unauthorized traffic.

FileKindSize
SKILL.mdskill md7.7 KB
scripts/readiness-auditor.mjsscript27.1 KB
scripts/readiness/adapters/android-adapter.mjsscript30.0 KB
scripts/readiness/adapters/base-adapter.mjsscript4.6 KB
scripts/readiness/adapters/flutter-adapter.mjsscript28.9 KB
scripts/readiness/adapters/generic-adapter.mjsscript15.9 KB
scripts/readiness/adapters/index.mjsscript661 B
scripts/readiness/adapters/ios-adapter.mjsscript21.0 KB
scripts/readiness/adapters/java-spring-adapter.mjsscript39.9 KB
scripts/readiness/adapters/nextjs-react-adapter.mjsscript30.5 KB
scripts/readiness/adapters/node-typescript-adapter.mjsscript115.8 KB
scripts/readiness/adapters/python-adapter.mjsscript44.0 KB
scripts/readiness/adapters/react-native-adapter.mjsscript34.6 KB
scripts/readiness/adapters/registry.mjsscript3.7 KB
scripts/readiness/architecture/applicability.mjsscript21.8 KB
scripts/readiness/architecture/architecture-inventory.mjsscript16.9 KB
scripts/readiness/architecture/architecture-reporter.mjsscript9.4 KB
scripts/readiness/architecture/capacity-model.mjsscript16.9 KB
scripts/readiness/architecture/design-decisions.mjsscript42.0 KB
scripts/readiness/architecture/failure-modes.mjsscript13.3 KB
scripts/readiness/architecture/index.mjsscript895 B
scripts/readiness/architecture/requirements.mjsscript22.0 KB
scripts/readiness/architecture/tradeoffs.mjsscript4.5 KB
scripts/readiness/capacity/benchmark-runner.mjsscript13.4 KB
scripts/readiness/constants.mjsscript6.0 KB
scripts/readiness/deployment/cicd-gate-validator.mjsscript6.1 KB
scripts/readiness/deployment/container-validator.mjsscript10.1 KB
scripts/readiness/deployment/deployment-gate.mjsscript4.8 KB
scripts/readiness/deployment/index.mjsscript411 B
scripts/readiness/deployment/k8s-validator.mjsscript8.8 KB
scripts/readiness/deployment/reliability-validator.mjsscript9.4 KB
scripts/readiness/engine/discovery.mjsscript15.4 KB
scripts/readiness/engine/index.mjsscript341 B
scripts/readiness/engine/orchestrator.mjsscript21.0 KB
scripts/readiness/engine/planner.mjsscript4.2 KB
scripts/readiness/engine/sarif.mjsscript12.7 KB
scripts/readiness/engine/skills-selector.mjsscript10.0 KB
scripts/readiness/execution/git.mjsscript2.3 KB
scripts/readiness/execution/runner.mjsscript11.9 KB
scripts/readiness/index.mjsscript516 B
scripts/readiness/orchestration/engineering-workflow.mjsscript18.5 KB
scripts/readiness/orchestration/index.mjsscript170 B
scripts/readiness/policies/index.mjsscript189 B
scripts/readiness/policies/release-policy.mjsscript9.5 KB
scripts/readiness/remediation/checkpoint-manager.mjsscript34.0 KB
scripts/readiness/remediation/diff-viewer.mjsscript2.5 KB
scripts/readiness/remediation/index.mjsscript778 B
scripts/readiness/remediation/patch-generator.mjsscript17.5 KB
scripts/readiness/remediation/remediation-runner.mjsscript9.9 KB
scripts/readiness/reporters/comparator.mjsscript20.7 KB
scripts/readiness/reporters/index.mjsscript293 B
scripts/readiness/reporters/json-reporter.mjsscript193 B
scripts/readiness/reporters/markdown-reporter.mjsscript18.8 KB
scripts/readiness/validation/evidence-matrix.mjsscript21.5 KB
scripts/readiness/validation/independent-app-runner.mjsscript26.2 KB
scripts/readiness/validation/index.mjsscript328 B

scripts/readiness/remediation/remediation-runner.mjs

View on GitHub
import { runReadinessAudit } from '../engine/orchestrator.mjs';
import { compareReadinessReports } from '../reporters/comparator.mjs';
import { collectProjectFiles } from '../constants.mjs';
import { generateRemediationPatches } from './patch-generator.mjs';
import {
  assertSafeProjectRelativePathDetails,
  atomicWriteWithinRootSync,
  computeSha256,
  createCheckpoint,
  finalizeCheckpointPostApply,
  lstatSafe,
  resolveCanonicalProjectRoot,
  restoreCheckpoint,
  safeReadFileBufferSync,
} from './checkpoint-manager.mjs';

/**
 * Standardized status outcomes for the remediation workflow.
 */
export const REMEDIATION_STATUSES = {
  PROPOSED_PENDING_APPROVAL: 'PROPOSED_PENDING_APPROVAL',
  NO_ACTIONABLE_PATCHES: 'NO_ACTIONABLE_PATCHES',
  REMEDIATED_AND_VERIFIED: 'REMEDIATED_AND_VERIFIED',
  REVERTED_DUE_TO_REGRESSION: 'REVERTED_DUE_TO_REGRESSION',
  CONFLICT: 'CONFLICT',
  FAILED: 'FAILED',
};

/**
 * Verifies that every patch target matches its pre-approval baseline state on disk.
 * Prevents silently overwriting concurrent changes made between diff preview and application.
 *
 * @param {string} canonicalBase
 * @param {Array<object>} patches
 * @returns {Array<{ targetFile: string, reason: string }>}
 */
export function detectPreApplyConflicts(canonicalBase, patches = []) {
  const conflicts = [];

  for (const patch of patches) {
    let details;
    try {
      details = assertSafeProjectRelativePathDetails(canonicalBase, patch.targetFile);
    } catch (err) {
      conflicts.push({
        targetFile: patch.targetFile,
        reason: err.message,
      });
      continue;
    }

    const { resolvedTarget, normalizedRelPath } = details;
    const st = lstatSafe(resolvedTarget);

    if (st && st.isSymbolicLink()) {
      conflicts.push({
        targetFile: normalizedRelPath,
        reason: `Target "${normalizedRelPath}" is a symbolic link or junction.`,
      });
      continue;
    }

    const expectedExisted =
      typeof patch.expectedExisted === 'boolean' ? patch.expectedExisted : patch.action !== 'create';

    if (!expectedExisted) {
      if (st) {
        conflicts.push({
          targetFile: normalizedRelPath,
          reason: `Target file "${normalizedRelPath}" already exists on disk (created concurrently since patch formulation).`,
        });
      }
      continue;
    }

    // Expected file to exist prior to modification
    if (!st) {
      conflicts.push({
        targetFile: normalizedRelPath,
        reason: `Target file "${normalizedRelPath}" no longer exists on disk (deleted concurrently since patch formulation).`,
      });
      continue;
    }

    let expectedHash = patch.expectedOriginalHash;
    if (!expectedHash && typeof patch.currentContent === 'string') {
      expectedHash = computeSha256(Buffer.from(patch.currentContent, 'utf8'));
    }

    if (expectedHash) {
      const { buffer: currentBuffer } = safeReadFileBufferSync(resolvedTarget);
      const currentHash = computeSha256(currentBuffer);
      if (currentHash !== expectedHash) {
        conflicts.push({
          targetFile: normalizedRelPath,
          reason: `Concurrent modification detected in "${normalizedRelPath}": disk hash does not match approved baseline.`,
        });
      }
    }
  }

  return conflicts;
}

/**
 * Executes the safe, reviewable remediation workflow.
 * Formulates non-destructive patches, displays unified diffs, enforces approval gates,
 * detects concurrent developer edits, creates rollback checkpoints, applies writes atomically,
 * and reruns comparative assessments.
 *
 * @param {object} options
 * @param {string} [options.projectDir='.'] - Target project directory
 * @param {boolean} [options.applyFix=false] - Explicit approval gate to apply edits
 * @param {boolean} [options.autoRollbackOnRegression=true] - Revert on regression
 * @param {boolean} [options.allowExec=false] - Authorization for follow-up dynamic tests
 * @param {boolean} [options.trustProject=false] - Explicit host trust
 * @param {number} [options.timeoutMs=10000] - Subprocess execution timeout
 * @param {string[]} [options.categories] - Assessment categories
 * @param {object|null} [options.baselineReport=null] - Pre-computed baseline report
 * @param {Array<object>|null} [options.patches=null] - Pre-approved patches to apply directly
 * @param {Function|null} [options.writeHook=null] - Optional internal hook invoked per patch write (for testing partial failures)
 * @returns {object} Structured remediation result
 */
export function executeRemediationWorkflow({
  projectDir = '.',
  applyFix = false,
  autoRollbackOnRegression = true,
  allowExec = false,
  trustProject = false,
  timeoutMs = 10000,
  categories,
  baselineReport = null,
  patches: providedPatches = null,
  writeHook = null,
} = {}) {
  const safeProjectDir = resolveCanonicalProjectRoot(projectDir);

  // 1. Baseline Assessment
  let beforeReport = baselineReport;
  if (!beforeReport) {
    beforeReport = runReadinessAudit({
      projectDir: safeProjectDir,
      categories,
      allowExec,
      trustProject,
      timeoutMs,
    });
  }

  // 2. Formulate or use pre-approved patches
  const files = collectProjectFiles(safeProjectDir);
  const patches = providedPatches ?? generateRemediationPatches(safeProjectDir, beforeReport.findings, files);

  if (patches.length === 0) {
    return {
      status: REMEDIATION_STATUSES.NO_ACTIONABLE_PATCHES,
      projectDir: safeProjectDir,
      applied: false,
      reverted: false,
      patches: [],
      diffPreview: '',
      message: 'No actionable remediation patches available for current findings.',
    };
  }

  const diffPreview = patches.map((p) => p.unifiedDiff).join('\n');

  // 3. Approval Gate / Dry-Run Mode
  if (!applyFix) {
    return {
      status: REMEDIATION_STATUSES.PROPOSED_PENDING_APPROVAL,
      approvalRequired: true,
      applied: false,
      reverted: false,
      projectDir: safeProjectDir,
      patches,
      diffPreview,
      summary: {
        totalPatches: patches.length,
        filesToCreate: patches.filter((p) => p.action === 'create').length,
        filesToModify: patches.filter((p) => p.action === 'modify').length,
      },
      message:
        'Remediation patches formulated with zero destructive changes. Review unified diffs above. Pass --apply-fix to apply with rollback checkpointing.',
    };
  }

  // 4. Concurrent-Change Pre-Flight Check before creating backup or writing disk
  const preApplyConflicts = detectPreApplyConflicts(safeProjectDir, patches);
  if (preApplyConflicts.length > 0) {
    return {
      status: REMEDIATION_STATUSES.CONFLICT,
      applied: false,
      reverted: false,
      conflictDetected: true,
      conflicts: preApplyConflicts,
      projectDir: safeProjectDir,
      patches,
      diffPreview,
      error: `Remediation refused due to concurrent modifications or unsafe paths: ${preApplyConflicts.map((c) => c.reason).join('; ')}`,
    };
  }

  // 5. Approved Application with Secure Checkpoint & Atomic Writes
  let checkpoint = null;
  const postApplyStatusMap = new Map();
  for (const p of patches) {
    const details = assertSafeProjectRelativePathDetails(safeProjectDir, p.targetFile);
    postApplyStatusMap.set(details.normalizedRelPath, { applied: false, appliedHash: null });
  }

  try {
    checkpoint = createCheckpoint(safeProjectDir, patches);

    for (let i = 0; i < patches.length; i++) {
      const patch = patches[i];
      const { normalizedRelPath } = assertSafeProjectRelativePathDetails(safeProjectDir, patch.targetFile);

      if (typeof writeHook === 'function') {
        writeHook(patch, i);
      }

      const appliedHash = atomicWriteWithinRootSync(safeProjectDir, normalizedRelPath, patch.proposedContent);
      postApplyStatusMap.set(normalizedRelPath, { applied: true, appliedHash });
    }

    // Record exact applied hashes on manifest so subsequent rollbacks preserve concurrent developer edits
    checkpoint = finalizeCheckpointPostApply(checkpoint, postApplyStatusMap);

    // 6. Automated Retesting & Comparison
    const afterReport = runReadinessAudit({
      projectDir: safeProjectDir,
      categories,
      allowExec,
      trustProject,
      timeoutMs,
    });

    const comparison = compareReadinessReports(beforeReport, afterReport);

    // 7. Regression Guard & Verified Rollback
    if (comparison.statusTransition.regressed && autoRollbackOnRegression) {
      const rollbackResult = restoreCheckpoint(checkpoint, {
        projectDir: safeProjectDir,
        preserveConcurrentChanges: true,
      });
      return {
        status: REMEDIATION_STATUSES.REVERTED_DUE_TO_REGRESSION,
        applied: false,
        reverted: rollbackResult.restored === true,
        projectDir: safeProjectDir,
        checkpoint,
        rollbackResult,
        patches,
        diffPreview,
        comparison,
        beforeReport,
        afterReport,
        error:
          'Remediation patches introduced regressions in follow-up assessment. Changes rolled back to pristine checkpoint.',
      };
    }

    return {
      status: REMEDIATION_STATUSES.REMEDIATED_AND_VERIFIED,
      applied: true,
      reverted: false,
      projectDir: safeProjectDir,
      checkpoint,
      patches,
      diffPreview,
      comparison,
      beforeReport,
      afterReport,
      verdict: comparison.statusTransition.verdict,
    };
  } catch (err) {
    let reverted = false;
    let rollbackResult = null;

    if (checkpoint) {
      try {
        checkpoint = finalizeCheckpointPostApply(checkpoint, postApplyStatusMap);
        rollbackResult = restoreCheckpoint(checkpoint, {
          projectDir: safeProjectDir,
          preserveConcurrentChanges: true,
        });
        reverted = rollbackResult.restored === true;
      } catch (rbErr) {
        rollbackResult = { restored: false, error: rbErr.message, restoredFiles: [] };
      }
    }

    return {
      status: REMEDIATION_STATUSES.FAILED,
      applied: false,
      reverted,
      rollbackResult,
      projectDir: safeProjectDir,
      checkpoint,
      error: err.message,
    };
  }
}
finishing-a-development-branchobra/superpowersUse when implementation is complete, all tests pass, and you need to decide how to integrate the workStars: 322kUpdated Claude CodeCodexVerifiedInstall
systematic-debuggingobra/superpowersUse when encountering any bug, test failure, or unexpected behavior, before proposing fixesStars: 322kUpdated Claude CodeCodexVerifiedInstall
test-driven-developmentobra/superpowersUse when implementing any feature or bugfix, before writing implementation codeStars: 322kUpdated Claude CodeCodexVerifiedInstall
skill-creatoranthropics/skillsCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy.Stars: 197kUpdated Claude CodeCodexVerifiedInstall