complete-work

workflow claude_code
Created by Prasham Trivedi

Copy This Prompt

export const meta = {
  name: 'complete-work',
  description: 'Verified task completion: confirm diff, build/test until green, bounded review-fix loop, QA + docs agents, commit, walkthrough, nested Parakh evidence, push',
  whenToUse: 'Finalizing a planned task (taskFindings.md exists) β€” the deterministic successor to the completeWork command',
  phases: [
    { title: 'Confirm', detail: 'diff vs requirements' },
    { title: 'Green', detail: 'build/typecheck/test, fix until green' },
    { title: 'Review', detail: 'sonnet finders -> judge verifies + fixes (bounded)' },
    { title: 'Validate', detail: 'qa-validator + documentation-updater' },
    { title: 'Finalize', detail: 'commit, walkthrough, parakh, push' },
  ],
}

// args: { taskDir, mode: 'backend'|'frontend', autonomous?, baseUrl?, docsUrl? }
const A = args || {}
const TASK = A.taskDir
const MODE = A.mode === 'frontend' ? 'frontend' : 'backend'
const AUTO = !!A.autonomous
if (!TASK) return { error: 'Pass args.taskDir (the taskNotes/<name> directory holding taskFindings.md).' }
const validationFile = MODE === 'backend' ? 'backend-validation.md' : 'frontend-validation.md'

const GATE = { type: 'object', additionalProperties: false, required: ['ok', 'detail'], properties: { ok: { type: 'boolean' }, detail: { type: 'string' } } }
const REVIEW = { type: 'object', additionalProperties: false, required: ['findingsRemaining', 'applied'], properties: { findingsRemaining: { type: 'integer' }, applied: { type: 'string' } } }

phase('Confirm')
const confirm = await agent(
  `Read taskNotes context for "${TASK}": taskFindings.md (the plan) and currentCommitHash if present.
If taskFindings.md is missing: ${AUTO ? 'STOP and report ok=false β€” cannot proceed without a plan.' : 'report ok=false and note the user should run /codePlanner.'}
If in a git repo, diff the working tree against currentCommitHash; otherwise inspect recent file changes. Read the changed code carefully and judge whether it satisfies the requirements in taskFindings.md. Return ok=true only if it does.`,
  { label: 'confirm-diff', phase: 'Confirm', schema: GATE }
)
if (!confirm || !confirm.ok) return { stoppedAt: 'Confirm', reason: confirm ? confirm.detail : 'confirm agent failed' }

phase('Green')
// Sequential, bounded: one working tree, build must pass before we proceed.
let green = null
for (let i = 0; i < 3; i++) {
  green = await agent(
    `Build and verify the codebase. Run (as applicable): npm run typecheck, npm run build, npm test (or the project's equivalents).
If anything fails, think hard and fix the code in one focused pass so it satisfies the requirements in taskNotes/${TASK}/taskFindings.md. Return ok=true only when all commands pass.`,
    { label: `green#${i + 1}`, phase: 'Green', schema: GATE }
  )
  if (green && green.ok) break
  log(`Build/test not green yet (attempt ${i + 1}).`)
}
if (!green || !green.ok) return { stoppedAt: 'Green', reason: green ? green.detail : 'build agent failed' }

phase('Review')
// Replicates `/code-review high --fix`, Cloudflare-style: scoped sonnet finders
// scan the diff in parallel (read-only), then the default-model judge dedups,
// verifies against the code, drops false positives, and applies the real fixes.
// Barrier per pass is correct: the judge needs ALL findings at once to dedup.
const FINDING = {
  type: 'object', additionalProperties: false, required: ['findings'],
  properties: {
    findings: {
      type: 'array',
      items: {
        type: 'object', additionalProperties: false, required: ['title', 'file', 'severity', 'detail'],
        properties: {
          title: { type: 'string' },
          file: { type: 'string' },
          severity: { type: 'string', enum: ['critical', 'warning', 'suggestion'] },
          detail: { type: 'string' },
        },
      },
    },
  },
}
const LENSES = [
  { key: 'bugs', focus: 'correctness bugs ONLY: logic errors, broken edge cases, missing error handling, regressions against the requirements. Ignore style, security, and performance.' },
  { key: 'security', focus: 'security issues ONLY: injection, secrets/credentials in code, authn/authz gaps, unsafe input handling. Ignore style, correctness, and performance.' },
  { key: 'quality', focus: 'reuse/simplification/efficiency cleanups ONLY: duplication, dead code, needless complexity, obvious perf smells. Ignore bugs and security.' },
]
for (let i = 0; i < 3; i++) {
  const found = (await parallel(LENSES.map(l => () => agent(
    `Review the current working-tree diff for ${l.focus}
Read the diff and affected files. Do NOT modify anything β€” report only. Skip speculative issues and nitpicks; report only actionable findings with file references.`,
    { label: `find:${l.key}#${i + 1}`, phase: 'Review', schema: FINDING, model: 'sonnet' }
  )))).filter(Boolean).flatMap(r => r.findings)
  if (!found.length) { log(`Review pass ${i + 1}: clean.`); break }
  log(`Review pass ${i + 1}: ${found.length} raw finding(s) β€” judging and fixing.`)
  const r = await agent(
    `You are the review judge and fixer (HIGH effort). Scoped reviewers reported the findings below about the current working-tree diff. Deduplicate them, verify each against the actual code, and drop false positives, speculation, and nitpicks. Apply fixes for the real findings directly to the working tree, keeping the requirements in taskNotes/${TASK}/taskFindings.md satisfied. Return how many actionable findings REMAIN unfixed (0 means clean) and what you applied.

FINDINGS:
${JSON.stringify(found, null, 2)}`,
    { label: `judge-fix#${i + 1}`, phase: 'Review', schema: REVIEW }
  )
  if (!r || r.findingsRemaining === 0) break
}

phase('Validate')
// qa-validator then documentation-updater. Sequential β€” both mutate the one working tree.
const qa = await agent(
  MODE === 'backend'
    ? `Run integration tests for the latest change and write your verdict to taskNotes/${TASK}/${validationFile}.`
    : `Test the site for the latest change using browser MCP tools (critical user flows) and write your verdict to taskNotes/${TASK}/${validationFile}.`,
  { label: 'qa-validator', phase: 'Validate', schema: GATE, agentType: 'qa-validator' }
)
await agent(
  `Ensure no documentation is missing or outdated for the change in taskNotes/${TASK}. Update READMEs, code comments, and other relevant docs to match the implementation.`,
  { label: 'docs-updater', phase: 'Validate', agentType: 'documentation-updater' }
)

phase('Finalize')
// Commit (single-line conventional message), then walkthrough, then nested Parakh, then push.
await agent(
  `If in a git repository, stage and commit all uncommitted files for task "${TASK}" using a Conventional Commit style message. The message MUST be a single line with NO body/description. If not a git repo, skip.`,
  { label: 'commit', phase: 'Finalize', model: 'haiku' }
)
await agent(
  `Write taskNotes/${TASK}/taskWalkthrough.md: a human walkthrough of the completed task containing
- Setup: ${MODE === 'backend' ? 'curl commands' : 'UI steps'} to set up the task
- Verify end-to-end: ${MODE === 'backend' ? 'relevant curls' : 'UI steps'} to run it
- What to verify: database/user states or curls that prove completion for a human reviewer.`,
  { label: 'walkthrough', phase: 'Finalize', model: 'sonnet' }
)

// Composability: nest the parakh-testing workflow for API evidence (one level deep).
let parakh = null
if (A.baseUrl) {
  log('Running nested parakh-testing workflow for API evidence…')
  try {
    parakh = await workflow('parakh-testing', {
      baseUrl: A.baseUrl,
      docsUrl: A.docsUrl,
      feature: `taskNotes/${TASK}/taskWalkthrough.md`,
      outputDir: `taskNotes/${TASK}`,
    })
  } catch (e) {
    log(`Nested parakh-testing skipped/failed: ${String(e)}`)
  }
} else {
  log('No args.baseUrl provided β€” skipping nested parakh-testing (API evidence).')
}

await agent(
  `If in a git repository, push the committed code. If not a git repo, skip.`,
  { label: 'push', phase: 'Finalize', model: 'haiku' }
)

const next = await agent(
  `Read taskNotes/${TASK}/ (taskFindings, ${validationFile}, taskWalkthrough, testEvidence if present). Pragmatically judge readiness and suggest the next step: for backend β†’ implementing the frontend if one is needed; for frontend β†’ releasing.`,
  { label: 'next-step', phase: 'Finalize' }
)

return {
  task: TASK, mode: MODE,
  qaPassed: !!(qa && qa.ok),
  validationFile: `taskNotes/${TASK}/${validationFile}`,
  walkthrough: `taskNotes/${TASK}/taskWalkthrough.md`,
  parakh: parakh ? { evidence: parakh.outputFile, passed: parakh.passed, total: parakh.total } : null,
  nextStep: next,
}

Workflow Details

Format Availability

Workflows are available in Claude Code format only and are delivered as-is. They cannot be converted to Codex or Gemini.

Actions

(Clears cached conversions and forces re-processing)
← Back to List