{"version":3,"file":"deepcode.d.ts","sourceRoot":"","sources":["../../../src/pack/templates/deepcode.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,mBAAmB,EAAqB,MAAM,iBAAiB,CAAC;AAE9E,eAAO,MAAM,oBAAoB,aAAa,CAAC;AAC/C,eAAO,MAAM,gBAAgB,cAAc,CAAC;AAE5C;;;;;;GAMG;AACH,eAAO,MAAM,sBAAsB,QAgIlC,CAAC;AAEF,0EAA0E;AAC1E,wBAAgB,yBAAyB,IAAI,OAAO,CAAC,MAAM,CAAC,CAE3D;AAED,iFAAiF;AACjF,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC,CASjF","sourcesContent":["import { composeWorkflowEntrypoint } from \"../../components/workflow-sdk/index.ts\";\nimport { type WrittenWorkflowPack, writeWorkflowPack } from \"./write-pack.ts\";\n\nexport const DEEPCODE_WORKFLOW_ID = \"deepcode\";\nexport const DEEPCODE_TRIGGER = \"/deepcode\";\n\n/**\n * The /deepcode workflow body: dynamic-workflow style multi-agent coding.\n * Parallel read-only explorers map the codebase, a planner freezes a step\n * plan, one coder implements each step in order (steps share the working\n * tree, so implementation is deliberately serial), and a verify-fix loop runs\n * the project check until it passes or stops making progress.\n */\nexport const DEEPCODE_WORKFLOW_BODY = String.raw`\nconst NOTES_SCHEMA = {\n\ttype: \"object\",\n\trequired: [\"notes\"],\n\tproperties: { notes: { type: \"string\" } },\n};\nconst PLAN_SCHEMA = {\n\ttype: \"object\",\n\trequired: [\"steps\", \"checkCommand\"],\n\tproperties: {\n\t\tsteps: {\n\t\t\ttype: \"array\",\n\t\t\titems: {\n\t\t\t\ttype: \"object\",\n\t\t\t\trequired: [\"title\", \"instructions\"],\n\t\t\t\tproperties: {\n\t\t\t\t\ttitle: { type: \"string\" },\n\t\t\t\t\tinstructions: { type: \"string\" },\n\t\t\t\t\tfiles: { type: \"array\", items: { type: \"string\" } },\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t\tcheckCommand: { type: \"string\" },\n\t},\n};\nconst STEP_SCHEMA = {\n\ttype: \"object\",\n\trequired: [\"done\", \"summary\"],\n\tproperties: { done: { type: \"boolean\" }, summary: { type: \"string\" } },\n};\nconst CHECK_SCHEMA = {\n\ttype: \"object\",\n\trequired: [\"passed\", \"detail\"],\n\tproperties: { passed: { type: \"boolean\" }, detail: { type: \"string\" } },\n};\n\nconst MAX_STEPS = 8;\nconst MAX_FIX_ROUNDS = 3;\n\nrunWorkflow(async ({ args }) => {\n\tconst task = typeof args.text === \"string\" && args.text.trim() ? args.text.trim() : \"\";\n\tif (!task) throw new Error(\"Usage: /deepcode <task description>\");\n\n\t// Phase 1: parallel read-only understanding (three complementary lenses).\n\tconst lenses = [\n\t\t\"Map the architecture relevant to this task: entry points, key modules, data flow. Read files; do not modify anything.\",\n\t\t\"Find every file this task will need to touch or understand, with one line each on why. Read files; do not modify anything.\",\n\t\t\"Describe the project's conventions this task must follow: test layout, lint/build commands, code style, error handling. Read files; do not modify anything.\",\n\t];\n\tconst understanding = await parallel(\n\t\tlenses.map((lens) => () => agent(\"Task: \" + task + \"\\n\\n\" + lens, { schema: NOTES_SCHEMA })),\n\t);\n\tconst notes = understanding\n\t\t.filter(Boolean)\n\t\t.map((entry, index) => \"## Lens \" + (index + 1) + \"\\n\" + entry.notes)\n\t\t.join(\"\\n\\n\");\n\tlog(\"deepcode: understanding collected from \" + understanding.filter(Boolean).length + \" explorer(s)\");\n\n\t// Phase 2: freeze a step plan. The planner reads but never writes.\n\tconst plan = await agent(\n\t\t\"Task: \" +\n\t\t\ttask +\n\t\t\t\"\\n\\nCodebase notes from parallel explorers:\\n\" +\n\t\t\tnotes +\n\t\t\t\"\\n\\nWrite an implementation plan of at most \" +\n\t\t\tMAX_STEPS +\n\t\t\t\" ordered steps. Each step must be independently completable by one coding agent and name the files it touches. Also give the single shell command that verifies the whole task (the project's own check or test command). Read files to confirm your plan; do not modify anything.\",\n\t\t{ schema: PLAN_SCHEMA },\n\t);\n\tconst steps = plan.steps.slice(0, MAX_STEPS);\n\tlog(\"deepcode: \" + steps.length + \" step(s), check: \" + plan.checkCommand);\n\n\t// Phase 3: implement steps in order. Steps share one working tree, so\n\t// implementation is serial by design; breadth lives in phases 1 and 4.\n\tconst stepResults = [];\n\tfor (const [index, step] of steps.entries()) {\n\t\tconst result = await agent(\n\t\t\t\"You are implementing step \" +\n\t\t\t\t(index + 1) +\n\t\t\t\t\"/\" +\n\t\t\t\tsteps.length +\n\t\t\t\t\" of this task: \" +\n\t\t\t\ttask +\n\t\t\t\t\"\\n\\nStep: \" +\n\t\t\t\tstep.title +\n\t\t\t\t\"\\nInstructions: \" +\n\t\t\t\tstep.instructions +\n\t\t\t\t(step.files?.length ? \"\\nExpected files: \" + step.files.join(\", \") : \"\") +\n\t\t\t\t\"\\n\\nEarlier steps already done: \" +\n\t\t\t\tJSON.stringify(stepResults.map((entry) => entry.title)) +\n\t\t\t\t\"\\n\\nImplement the step completely (edit/write/run as needed). Do not start later steps.\",\n\t\t\t{ schema: STEP_SCHEMA },\n\t\t);\n\t\tstepResults.push({ title: step.title, done: result.done, summary: result.summary });\n\t\tlog(\"deepcode: step \" + (index + 1) + \" \" + (result.done ? \"done\" : \"incomplete\") + \": \" + step.title);\n\t}\n\n\t// Phase 4: verify-fix loop until the check passes or progress stalls.\n\tlet verification = { passed: false, detail: \"not run\" };\n\tlet lastDetail = \"\";\n\tfor (let round = 0; round < MAX_FIX_ROUNDS; round += 1) {\n\t\tverification = await agent(\n\t\t\t\"Run this check command with bash and report the outcome truthfully: \" +\n\t\t\t\tplan.checkCommand +\n\t\t\t\t\"\\nIf it fails, include the essential failure output in detail. Do not fix anything in this run.\",\n\t\t\t{ schema: CHECK_SCHEMA },\n\t\t);\n\t\tif (verification.passed) break;\n\t\tif (verification.detail === lastDetail) {\n\t\t\tlog(\"deepcode: no progress between fix rounds, stopping\");\n\t\t\tbreak;\n\t\t}\n\t\tlastDetail = verification.detail;\n\t\tlog(\"deepcode: check failed, fix round \" + (round + 1));\n\t\tawait agent(\n\t\t\t\"The check '\" +\n\t\t\t\tplan.checkCommand +\n\t\t\t\t\"' failed while finishing this task: \" +\n\t\t\t\ttask +\n\t\t\t\t\"\\n\\nFailure output:\\n\" +\n\t\t\t\tverification.detail +\n\t\t\t\t\"\\n\\nDiagnose and fix the failures, then re-run the check yourself to confirm.\",\n\t\t\t{ schema: STEP_SCHEMA },\n\t\t);\n\t}\n\n\treturn { task, steps: stepResults, checkCommand: plan.checkCommand, verification };\n});\n`;\n\n/** The composed single-file component entrypoint (SDK prelude + body). */\nexport function composeDeepcodeEntrypoint(): Promise<string> {\n\treturn composeWorkflowEntrypoint(DEEPCODE_WORKFLOW_BODY);\n}\n\n/** Write a complete, importable /deepcode optimization pack into `directory`. */\nexport function writeDeepcodePack(directory: string): Promise<WrittenWorkflowPack> {\n\treturn writeWorkflowPack(directory, {\n\t\tid: DEEPCODE_WORKFLOW_ID,\n\t\ttrigger: DEEPCODE_TRIGGER,\n\t\tversion: \"1.0.0\",\n\t\tdescription:\n\t\t\t\"Dynamic-workflow style multi-agent coding: parallel explorers, a frozen step plan, serial implementation, and a verify-fix loop.\",\n\t\tbody: DEEPCODE_WORKFLOW_BODY,\n\t});\n}\n"]}