@voybio/ace-swarm 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +109 -0
- package/LICENSE +186 -0
- package/README.md +229 -0
- package/assets/.agents/ACE/ACE-Init/AGENTS.md +210 -0
- package/assets/.agents/ACE/ACE-Init/instructions.md +118 -0
- package/assets/.agents/ACE/ACE_coders/AGENTS.md +154 -0
- package/assets/.agents/ACE/ACE_coders/INSTRUCTIONS.md +216 -0
- package/assets/.agents/ACE/AGENT_REGISTRY.md +70 -0
- package/assets/.agents/ACE/AGENT_REGISTRY_7.md +9 -0
- package/assets/.agents/ACE/DIRECTIVE_KERNEL.md +234 -0
- package/assets/.agents/ACE/UI/AGENTS.md +115 -0
- package/assets/.agents/ACE/UI/instructions.md +178 -0
- package/assets/.agents/ACE/VOS/ACE_VOS_MISSING_INFO_MATRIX.md +42 -0
- package/assets/.agents/ACE/VOS/AGENTS.md +72 -0
- package/assets/.agents/ACE/VOS/instructions.md +211 -0
- package/assets/.agents/ACE/agent-astgrep/AGENTS.md +123 -0
- package/assets/.agents/ACE/agent-astgrep/instructions.md +91 -0
- package/assets/.agents/ACE/agent-builder/AGENTS.md +172 -0
- package/assets/.agents/ACE/agent-builder/instructions.md +137 -0
- package/assets/.agents/ACE/agent-docs/AGENTS.md +159 -0
- package/assets/.agents/ACE/agent-docs/instructions.md +133 -0
- package/assets/.agents/ACE/agent-eval/AGENTS.md +46 -0
- package/assets/.agents/ACE/agent-eval/instructions.md +56 -0
- package/assets/.agents/ACE/agent-memory/AGENTS.md +49 -0
- package/assets/.agents/ACE/agent-memory/instructions.md +50 -0
- package/assets/.agents/ACE/agent-observability/AGENTS.md +46 -0
- package/assets/.agents/ACE/agent-observability/instructions.md +50 -0
- package/assets/.agents/ACE/agent-ops/AGENTS.md +201 -0
- package/assets/.agents/ACE/agent-ops/instructions.md +136 -0
- package/assets/.agents/ACE/agent-qa/AGENTS.md +189 -0
- package/assets/.agents/ACE/agent-qa/instructions.md +121 -0
- package/assets/.agents/ACE/agent-release/AGENTS.md +48 -0
- package/assets/.agents/ACE/agent-release/instructions.md +49 -0
- package/assets/.agents/ACE/agent-research/AGENTS.md +160 -0
- package/assets/.agents/ACE/agent-research/instructions.md +118 -0
- package/assets/.agents/ACE/agent-security/AGENTS.md +48 -0
- package/assets/.agents/ACE/agent-security/instructions.md +50 -0
- package/assets/.agents/ACE/agent-skeptic/AGENTS.md +178 -0
- package/assets/.agents/ACE/agent-skeptic/instructions.md +196 -0
- package/assets/.agents/ACE/agent-spec/AGENTS.md +169 -0
- package/assets/.agents/ACE/agent-spec/instructions.md +116 -0
- package/assets/.agents/ACE/orchestrator/AGENTS.md +365 -0
- package/assets/.agents/ACE/orchestrator/instructions.md +231 -0
- package/assets/.agents/skills/ace-orchestrator/SKILL.md +63 -0
- package/assets/.agents/skills/ace-orchestrator/references/engineering-bootstrap-playbook.md +360 -0
- package/assets/.agents/skills/astgrep-index/SKILL.md +58 -0
- package/assets/.agents/skills/codemunch/SKILL.md +65 -0
- package/assets/.agents/skills/codemunch/references/ast-driven-protocol.md +543 -0
- package/assets/.agents/skills/codesnipe/SKILL.md +64 -0
- package/assets/.agents/skills/codesnipe/references/dual-codebase-playbook.md +671 -0
- package/assets/.agents/skills/eval-harness/SKILL.md +203 -0
- package/assets/.agents/skills/handoff-lint/SKILL.md +164 -0
- package/assets/.agents/skills/incident-commander/SKILL.md +174 -0
- package/assets/.agents/skills/landing-review-watcher/SKILL.md +68 -0
- package/assets/.agents/skills/memory-curator/SKILL.md +179 -0
- package/assets/.agents/skills/problem-triage/SKILL.md +57 -0
- package/assets/.agents/skills/problem-triage/agents/openai.yaml +3 -0
- package/assets/.agents/skills/release-sentry/SKILL.md +189 -0
- package/assets/.agents/skills/risk-quant/SKILL.md +190 -0
- package/assets/.agents/skills/schema-forge/SKILL.md +174 -0
- package/assets/.agents/skills/skill-auditor/SKILL.md +52 -0
- package/assets/.agents/skills/state-auditor/SKILL.md +182 -0
- package/assets/.github/hooks/ace-copilot.json +68 -0
- package/assets/agent-state/ACE_WORKFLOW.md +131 -0
- package/assets/agent-state/ARTIFACT_MANIFEST.json +5 -0
- package/assets/agent-state/AST_GREP_COMMANDS.md +121 -0
- package/assets/agent-state/AST_GREP_INDEX.json +13 -0
- package/assets/agent-state/AST_GREP_INDEX.md +15 -0
- package/assets/agent-state/DECISIONS.md +7 -0
- package/assets/agent-state/EVIDENCE_LOG.md +7 -0
- package/assets/agent-state/HANDOFF.json +24 -0
- package/assets/agent-state/INTERFACE_REGISTRY.md +75 -0
- package/assets/agent-state/MODULES/gates/gate-autonomy.json +7 -0
- package/assets/agent-state/MODULES/gates/gate-completeness.json +7 -0
- package/assets/agent-state/MODULES/gates/gate-correctness.json +7 -0
- package/assets/agent-state/MODULES/gates/gate-evaluation.json +7 -0
- package/assets/agent-state/MODULES/gates/gate-operability.json +7 -0
- package/assets/agent-state/MODULES/gates/gate-security.json +7 -0
- package/assets/agent-state/MODULES/gates/gate-typescript-public-surface.json +7 -0
- package/assets/agent-state/MODULES/registry.json +41 -0
- package/assets/agent-state/MODULES/roles/capability-astgrep.json +49 -0
- package/assets/agent-state/MODULES/roles/capability-build.json +39 -0
- package/assets/agent-state/MODULES/roles/capability-docs.json +38 -0
- package/assets/agent-state/MODULES/roles/capability-eval.json +20 -0
- package/assets/agent-state/MODULES/roles/capability-memory.json +20 -0
- package/assets/agent-state/MODULES/roles/capability-observability.json +20 -0
- package/assets/agent-state/MODULES/roles/capability-ops.json +45 -0
- package/assets/agent-state/MODULES/roles/capability-qa.json +40 -0
- package/assets/agent-state/MODULES/roles/capability-release.json +21 -0
- package/assets/agent-state/MODULES/roles/capability-research.json +44 -0
- package/assets/agent-state/MODULES/roles/capability-security.json +21 -0
- package/assets/agent-state/MODULES/roles/capability-skeptic.json +48 -0
- package/assets/agent-state/MODULES/roles/capability-spec.json +42 -0
- package/assets/agent-state/MODULES/schemas/ACE_RUNTIME_PROFILE.schema.json +289 -0
- package/assets/agent-state/MODULES/schemas/ARTIFACT_MANIFEST.schema.json +185 -0
- package/assets/agent-state/MODULES/schemas/HANDOFF.agent-state.schema.json +124 -0
- package/assets/agent-state/MODULES/schemas/HANDOFF.schema.json +55 -0
- package/assets/agent-state/MODULES/schemas/RUNTIME_EXECUTOR_SESSION_REGISTRY.schema.json +290 -0
- package/assets/agent-state/MODULES/schemas/RUNTIME_TOOL_SPEC_REGISTRY.schema.json +144 -0
- package/assets/agent-state/MODULES/schemas/STATUS_EVENT.schema.json +84 -0
- package/assets/agent-state/MODULES/schemas/SWARM_HANDOFF.schema.json +138 -0
- package/assets/agent-state/MODULES/schemas/TRACKER_SNAPSHOT.schema.json +134 -0
- package/assets/agent-state/MODULES/schemas/VERICIFY_BRIDGE_SNAPSHOT.schema.json +157 -0
- package/assets/agent-state/MODULES/schemas/VERICIFY_PROCESS_POST_LOG.schema.json +93 -0
- package/assets/agent-state/MODULES/schemas/WORKSPACE_SESSION_REGISTRY.schema.json +133 -0
- package/assets/agent-state/PROVENANCE_LOG.md +28 -0
- package/assets/agent-state/QUALITY_GATES.md +15 -0
- package/assets/agent-state/RISKS.md +8 -0
- package/assets/agent-state/SCOPE.md +20 -0
- package/assets/agent-state/SKILL_CATALOG.md +48 -0
- package/assets/agent-state/STATUS.md +8 -0
- package/assets/agent-state/STATUS_EVENTS.ndjson +1 -0
- package/assets/agent-state/TASK.md +18 -0
- package/assets/agent-state/TEAL_CONFIG.md +117 -0
- package/assets/agent-state/handoff-registry.json +5 -0
- package/assets/agent-state/index-fingerprints.json +7 -0
- package/assets/agent-state/index.json +32 -0
- package/assets/agent-state/run-ledger.json +5 -0
- package/assets/agent-state/runtime-executor-sessions.json +5 -0
- package/assets/agent-state/runtime-tool-specs.json +5 -0
- package/assets/agent-state/runtime-workspaces.json +5 -0
- package/assets/agent-state/todo-state.json +7 -0
- package/assets/agent-state/tracker-snapshot.json +7 -0
- package/assets/agent-state/vericify/ace-bridge.json +60 -0
- package/assets/agent-state/vericify/process-posts.json +5 -0
- package/assets/instructions/ACE.instructions.md +187 -0
- package/assets/instructions/ACE_Coder.instructions.md +146 -0
- package/assets/instructions/ACE_UI.instructions.md +178 -0
- package/assets/instructions/ACE_VOS.instructions.md +211 -0
- package/assets/scripts/ace-hook-dispatch.mjs +538 -0
- package/assets/scripts/bootstrap-workspace.sh +27 -0
- package/assets/scripts/copilot-hook-dispatch.mjs +3 -0
- package/assets/scripts/eval-harness.sh +68 -0
- package/assets/scripts/render-mcp-configs.sh +396 -0
- package/assets/tasks/README.md +48 -0
- package/assets/tasks/SWARM_HANDOFF.example.json +53 -0
- package/assets/tasks/SWARM_HANDOFF.example_ui_to_coders.json +55 -0
- package/assets/tasks/SWARM_HANDOFF.example_vos_to_ui.json +55 -0
- package/assets/tasks/SWARM_HANDOFF.template.json +52 -0
- package/assets/tasks/cli_work_split.md +22 -0
- package/assets/tasks/lessons.md +17 -0
- package/assets/tasks/role_tasks.md +206 -0
- package/assets/tasks/todo.md +23 -0
- package/dist/ace-autonomy.d.ts +137 -0
- package/dist/ace-autonomy.js +472 -0
- package/dist/ace-context.d.ts +29 -0
- package/dist/ace-context.js +240 -0
- package/dist/ace-internal-tools.d.ts +8 -0
- package/dist/ace-internal-tools.js +76 -0
- package/dist/ace-server-instructions.d.ts +12 -0
- package/dist/ace-server-instructions.js +324 -0
- package/dist/agent-runtime/role-adapters.d.ts +29 -0
- package/dist/agent-runtime/role-adapters.js +573 -0
- package/dist/astgrep-index.d.ts +24 -0
- package/dist/astgrep-index.js +476 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.js +591 -0
- package/dist/git-ops.d.ts +53 -0
- package/dist/git-ops.js +238 -0
- package/dist/handoff-registry.d.ts +71 -0
- package/dist/handoff-registry.js +422 -0
- package/dist/helpers.d.ts +126 -0
- package/dist/helpers.js +1687 -0
- package/dist/index-store.d.ts +51 -0
- package/dist/index-store.js +328 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +7 -0
- package/dist/internal-tool-runtime.d.ts +21 -0
- package/dist/internal-tool-runtime.js +136 -0
- package/dist/job-scheduler.d.ts +175 -0
- package/dist/job-scheduler.js +1217 -0
- package/dist/kanban.d.ts +27 -0
- package/dist/kanban.js +339 -0
- package/dist/local-model-runtime.d.ts +40 -0
- package/dist/local-model-runtime.js +174 -0
- package/dist/model-bridge.d.ts +54 -0
- package/dist/model-bridge.js +587 -0
- package/dist/orchestrator-supervisor.d.ts +100 -0
- package/dist/orchestrator-supervisor.js +399 -0
- package/dist/problem-triage.d.ts +23 -0
- package/dist/problem-triage.js +448 -0
- package/dist/prompts.d.ts +7 -0
- package/dist/prompts.js +628 -0
- package/dist/public-surface.d.ts +30 -0
- package/dist/public-surface.js +316 -0
- package/dist/resources.d.ts +7 -0
- package/dist/resources.js +545 -0
- package/dist/run-ledger.d.ts +36 -0
- package/dist/run-ledger.js +257 -0
- package/dist/runtime-command.d.ts +18 -0
- package/dist/runtime-command.js +76 -0
- package/dist/runtime-executor.d.ts +104 -0
- package/dist/runtime-executor.js +985 -0
- package/dist/runtime-profile.d.ts +116 -0
- package/dist/runtime-profile.js +532 -0
- package/dist/runtime-tool-specs.d.ts +68 -0
- package/dist/runtime-tool-specs.js +527 -0
- package/dist/safe-edit.d.ts +52 -0
- package/dist/safe-edit.js +255 -0
- package/dist/schemas.d.ts +44 -0
- package/dist/schemas.js +830 -0
- package/dist/semantic-cache.d.ts +147 -0
- package/dist/semantic-cache.js +552 -0
- package/dist/semantic-hash.d.ts +83 -0
- package/dist/semantic-hash.js +346 -0
- package/dist/server.d.ts +10 -0
- package/dist/server.js +46 -0
- package/dist/shared.d.ts +136 -0
- package/dist/shared.js +269 -0
- package/dist/skill-auditor.d.ts +26 -0
- package/dist/skill-auditor.js +184 -0
- package/dist/skill-catalog.d.ts +60 -0
- package/dist/skill-catalog.js +305 -0
- package/dist/status-events.d.ts +40 -0
- package/dist/status-events.js +269 -0
- package/dist/store/ace-packed-store.d.ts +69 -0
- package/dist/store/ace-packed-store.js +434 -0
- package/dist/store/bootstrap-store.d.ts +46 -0
- package/dist/store/bootstrap-store.js +242 -0
- package/dist/store/catalog-builder.d.ts +21 -0
- package/dist/store/catalog-builder.js +68 -0
- package/dist/store/importer.d.ts +19 -0
- package/dist/store/importer.js +157 -0
- package/dist/store/knowledge-bake.d.ts +59 -0
- package/dist/store/knowledge-bake.js +339 -0
- package/dist/store/materializers/hook-context-materializer.d.ts +25 -0
- package/dist/store/materializers/hook-context-materializer.js +100 -0
- package/dist/store/materializers/host-file-materializer.d.ts +37 -0
- package/dist/store/materializers/host-file-materializer.js +271 -0
- package/dist/store/materializers/todo-syncer.d.ts +30 -0
- package/dist/store/materializers/todo-syncer.js +140 -0
- package/dist/store/materializers/vericify-projector.d.ts +38 -0
- package/dist/store/materializers/vericify-projector.js +239 -0
- package/dist/store/repositories/discovery-repository.d.ts +24 -0
- package/dist/store/repositories/discovery-repository.js +58 -0
- package/dist/store/repositories/handoff-repository.d.ts +31 -0
- package/dist/store/repositories/handoff-repository.js +67 -0
- package/dist/store/repositories/ledger-repository.d.ts +26 -0
- package/dist/store/repositories/ledger-repository.js +49 -0
- package/dist/store/repositories/runtime-kv-repository.d.ts +16 -0
- package/dist/store/repositories/runtime-kv-repository.js +36 -0
- package/dist/store/repositories/scheduler-repository.d.ts +50 -0
- package/dist/store/repositories/scheduler-repository.js +123 -0
- package/dist/store/repositories/session-repository.d.ts +33 -0
- package/dist/store/repositories/session-repository.js +82 -0
- package/dist/store/repositories/todo-repository.d.ts +31 -0
- package/dist/store/repositories/todo-repository.js +77 -0
- package/dist/store/repositories/tracker-repository.d.ts +25 -0
- package/dist/store/repositories/tracker-repository.js +43 -0
- package/dist/store/repositories/vericify-repository.d.ts +32 -0
- package/dist/store/repositories/vericify-repository.js +58 -0
- package/dist/store/skills-install.d.ts +28 -0
- package/dist/store/skills-install.js +86 -0
- package/dist/store/state-reader.d.ts +49 -0
- package/dist/store/state-reader.js +111 -0
- package/dist/store/store-artifacts.d.ts +12 -0
- package/dist/store/store-artifacts.js +138 -0
- package/dist/store/store-snapshot.d.ts +19 -0
- package/dist/store/store-snapshot.js +140 -0
- package/dist/store/topology-bake.d.ts +15 -0
- package/dist/store/topology-bake.js +215 -0
- package/dist/store/types.d.ts +155 -0
- package/dist/store/types.js +35 -0
- package/dist/store/workspace-snapshot.d.ts +26 -0
- package/dist/store/workspace-snapshot.js +107 -0
- package/dist/store/write-queue.d.ts +7 -0
- package/dist/store/write-queue.js +26 -0
- package/dist/todo-state.d.ts +41 -0
- package/dist/todo-state.js +399 -0
- package/dist/tools-agent.d.ts +7 -0
- package/dist/tools-agent.js +1542 -0
- package/dist/tools-discovery.d.ts +6 -0
- package/dist/tools-discovery.js +178 -0
- package/dist/tools-drift.d.ts +13 -0
- package/dist/tools-drift.js +357 -0
- package/dist/tools-files.d.ts +6 -0
- package/dist/tools-files.js +679 -0
- package/dist/tools-framework.d.ts +7 -0
- package/dist/tools-framework.js +1414 -0
- package/dist/tools-git.d.ts +6 -0
- package/dist/tools-git.js +183 -0
- package/dist/tools-handoff.d.ts +32 -0
- package/dist/tools-handoff.js +489 -0
- package/dist/tools-lifecycle.d.ts +6 -0
- package/dist/tools-lifecycle.js +205 -0
- package/dist/tools-memory.d.ts +6 -0
- package/dist/tools-memory.js +260 -0
- package/dist/tools-scheduler.d.ts +6 -0
- package/dist/tools-scheduler.js +228 -0
- package/dist/tools-skills.d.ts +3 -0
- package/dist/tools-skills.js +104 -0
- package/dist/tools-todo.d.ts +6 -0
- package/dist/tools-todo.js +154 -0
- package/dist/tools.d.ts +9 -0
- package/dist/tools.js +33 -0
- package/dist/tracker-adapters.d.ts +74 -0
- package/dist/tracker-adapters.js +776 -0
- package/dist/tracker-sync.d.ts +10 -0
- package/dist/tracker-sync.js +84 -0
- package/dist/tui/agent-runner.d.ts +137 -0
- package/dist/tui/agent-runner.js +466 -0
- package/dist/tui/agent-worker.d.ts +10 -0
- package/dist/tui/agent-worker.js +347 -0
- package/dist/tui/chat.d.ts +84 -0
- package/dist/tui/chat.js +368 -0
- package/dist/tui/commands.d.ts +57 -0
- package/dist/tui/commands.js +432 -0
- package/dist/tui/dashboard.d.ts +24 -0
- package/dist/tui/dashboard.js +110 -0
- package/dist/tui/index.d.ts +114 -0
- package/dist/tui/index.js +1059 -0
- package/dist/tui/input.d.ts +49 -0
- package/dist/tui/input.js +336 -0
- package/dist/tui/layout.d.ts +116 -0
- package/dist/tui/layout.js +367 -0
- package/dist/tui/ollama.d.ts +116 -0
- package/dist/tui/ollama.js +192 -0
- package/dist/tui/openai-compatible.d.ts +63 -0
- package/dist/tui/openai-compatible.js +370 -0
- package/dist/tui/provider-discovery.d.ts +59 -0
- package/dist/tui/provider-discovery.js +530 -0
- package/dist/tui/renderer.d.ts +166 -0
- package/dist/tui/renderer.js +304 -0
- package/dist/tui/tabs.d.ts +70 -0
- package/dist/tui/tabs.js +208 -0
- package/dist/tui/telemetry.d.ts +56 -0
- package/dist/tui/telemetry.js +106 -0
- package/dist/vericify-bridge.d.ts +146 -0
- package/dist/vericify-bridge.js +571 -0
- package/dist/vericify-context.d.ts +10 -0
- package/dist/vericify-context.js +72 -0
- package/dist/workspace-manager.d.ts +107 -0
- package/dist/workspace-manager.js +636 -0
- package/package.json +83 -0
|
@@ -0,0 +1,543 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: codemunch
|
|
3
|
+
description:
|
|
4
|
+
Holistic AST-driven codebase comprehension. Uses ast-grep to surgically extract structural knowledge into lightweight artifacts, enabling deep understanding of any foreign codebase without reading raw files. Operates as a capability-research module inside the ACE Framework.
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# CodeMunch — AST-Driven Codebase Intelligence
|
|
8
|
+
|
|
9
|
+
**IMPORTANT**: NEVER read raw source files to understand a codebase. Every structural fact MUST
|
|
10
|
+
be extracted via an `ast-grep` query. Raw file reads burn 10–100× more tokens than equivalent
|
|
11
|
+
AST queries. The only exception is a single-file glance at an entry point to confirm language
|
|
12
|
+
and project purpose. The goal is to **produce artifacts, not chat**. If a CodeMunch session
|
|
13
|
+
ends without writing at least `CODEBASE_MAP.md`, it has failed.
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## 0. ACE Role Declaration
|
|
18
|
+
|
|
19
|
+
CodeMunch is a `capability-research` module. In every session it:
|
|
20
|
+
|
|
21
|
+
- **Emits** a `SOURCE_VALIDATED` event when a structural claim is confirmed by ast-grep output.
|
|
22
|
+
- **Writes** findings to `./agent-state/` as append-only artifacts.
|
|
23
|
+
- **Blocks** downstream modules (`capability-spec`, `capability-build`) from acting on unverifiable structural assumptions.
|
|
24
|
+
- **Hands off** via `HANDOFF.json` once `CODEBASE_MAP.md` and `PATTERNS.md` are locked.
|
|
25
|
+
|
|
26
|
+
ACE Clarity Protocol headers (`[STATE_ANALYSIS]`, `[STRATEGY_SELECTOR]`, `[EXECUTION_LOG]`,
|
|
27
|
+
`[ARTIFACT_UPDATE]`, `[VERIFICATION]`) must be used at each phase boundary in your response.
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## 0.1 MICE Boundaries
|
|
32
|
+
|
|
33
|
+
| Rule | Enforcement |
|
|
34
|
+
|---|---|
|
|
35
|
+
| **Modular** | Extracts structural knowledge only; does NOT modify code, write specs, or make build decisions. |
|
|
36
|
+
| **Interoperable** | All findings written as standardized artifacts (`CODEBASE_MAP.md`, `PATTERNS.md`, `EVIDENCE_LOG.md`). |
|
|
37
|
+
| **Customizable** | Goal parameter (`understand/debug/contribute/inspire`) controls depth and focus of analysis. |
|
|
38
|
+
| **Extensible** | New language patterns added via ast-grep pattern sets, not prose guessing. |
|
|
39
|
+
|
|
40
|
+
## 0.2 Goal Orientation
|
|
41
|
+
|
|
42
|
+
- `DELETE_PROTOCOL`: Skip Socratic questions already answered by prior runs. No redundant queries.
|
|
43
|
+
- `ARTIFACT_PROTOCOL`: Session MUST produce `CODEBASE_MAP.md` minimum. No artifact = failed session.
|
|
44
|
+
- `AGENCY_PROTOCOL`: Infer next ast-grep target from unanswered Socratic questions. Never ask "what should I query?"
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
## 1. Socratic Question Stack
|
|
50
|
+
|
|
51
|
+
Before running a single command, answer these questions in order. Stop at the first one you cannot answer — that is your first ast-grep target.
|
|
52
|
+
|
|
53
|
+
**Tier 0 — Orientation (answer from README or a 30-second scan)**
|
|
54
|
+
1. What is the primary language and build system?
|
|
55
|
+
2. What is the stated purpose of this codebase in one sentence?
|
|
56
|
+
3. Where is the entry point (`main`, `__init__`, `index`, `lib.rs`, etc.)?
|
|
57
|
+
|
|
58
|
+
**Tier 1 — Skeleton (answer via ast-grep)**
|
|
59
|
+
4. What are the top-level public types / classes / structs / enums?
|
|
60
|
+
5. What are the primary exported functions or public API symbols?
|
|
61
|
+
6. How many modules/crates/packages exist, and how are they named?
|
|
62
|
+
7. What external dependencies are imported at the top level?
|
|
63
|
+
|
|
64
|
+
**Tier 2 — Relationships (answer via ast-grep)**
|
|
65
|
+
8. Which modules call which other modules? (call-site mapping)
|
|
66
|
+
9. Where does data enter the system and where does it leave?
|
|
67
|
+
10. What trait / interface / protocol implementations exist?
|
|
68
|
+
11. Where is error handling centralised? What error types exist?
|
|
69
|
+
|
|
70
|
+
**Tier 3 — Patterns (answer via ast-grep)**
|
|
71
|
+
12. What repeated structural idioms appear 3+ times? (factory, builder, strategy, etc.)
|
|
72
|
+
13. What test coverage patterns exist? (unit, integration, property-based?)
|
|
73
|
+
14. Are there any TODO/FIXME/HACK/unsafe markers that signal risk areas?
|
|
74
|
+
15. What configuration / deserialisation surface exists?
|
|
75
|
+
|
|
76
|
+
**Tier 4 — Goal Alignment (answer from the task)**
|
|
77
|
+
16. What is the specific goal? (understand / debug / add feature / contribute / get inspired)
|
|
78
|
+
17. Which modules are in the critical path for this goal?
|
|
79
|
+
18. What is the simplest change that would advance this goal?
|
|
80
|
+
|
|
81
|
+
> **Rule**: Each unanswered question maps to exactly one ast-grep command in Phase 2.
|
|
82
|
+
> Write the question → answer pairs into `SOCRATIC_LOG.md` as you go.
|
|
83
|
+
|
|
84
|
+
---
|
|
85
|
+
|
|
86
|
+
## 2. Execution Protocol
|
|
87
|
+
|
|
88
|
+
### Phase 0 — Bootstrap `[STATE_ANALYSIS]`
|
|
89
|
+
|
|
90
|
+
Detect the language, structure, and project skeleton without reading any source files.
|
|
91
|
+
|
|
92
|
+
**Step 1 — Language detection**
|
|
93
|
+
```bash
|
|
94
|
+
# Count files by extension to confirm language mix
|
|
95
|
+
find . -type f | sed 's/.*\.//' | sort | uniq -c | sort -rn | head -20
|
|
96
|
+
|
|
97
|
+
# Confirm primary language for ast-grep --lang flag
|
|
98
|
+
# Common values: rust, python, js, ts, tsx, go, java, cpp, c, cs, ruby
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
**Step 2 — Entry point identification**
|
|
102
|
+
```bash
|
|
103
|
+
# Rust
|
|
104
|
+
ast-grep --pattern 'fn main() { $$$ }' --lang rust --json
|
|
105
|
+
|
|
106
|
+
# Python
|
|
107
|
+
ast-grep --pattern 'if __name__ == "__main__": $$$' --lang python --json
|
|
108
|
+
|
|
109
|
+
# JS/TS
|
|
110
|
+
ast-grep --pattern 'export default $EXPR' --lang ts --json
|
|
111
|
+
ast-grep --pattern 'module.exports = $EXPR' --lang js --json
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
**Step 3 — Top-level module map**
|
|
115
|
+
```bash
|
|
116
|
+
# Count lines and files per directory (structural overview, no source reading)
|
|
117
|
+
find . -name "*.rs" | head -60
|
|
118
|
+
find . -name "*.py" | head -60
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
**Output**: Write `CODEBASE_MAP.md` stub:
|
|
122
|
+
```markdown
|
|
123
|
+
# CODEBASE_MAP.md
|
|
124
|
+
Language: <lang>
|
|
125
|
+
Entry Point: <path>
|
|
126
|
+
Build System: <cargo/pip/npm/make>
|
|
127
|
+
Module Count: <n>
|
|
128
|
+
Purpose: <one sentence from README>
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
---
|
|
132
|
+
|
|
133
|
+
### Phase 1 — Skeleton Extraction `[STRATEGY_SELECTOR]`
|
|
134
|
+
|
|
135
|
+
Extract the full public API surface using targeted ast-grep patterns. Do NOT read
|
|
136
|
+
implementations — extract signatures only.
|
|
137
|
+
|
|
138
|
+
**Step 4 — Public types**
|
|
139
|
+
```bash
|
|
140
|
+
# Rust: structs, enums, traits
|
|
141
|
+
ast-grep --pattern 'pub struct $NAME { $$$ }' --lang rust
|
|
142
|
+
ast-grep --pattern 'pub enum $NAME { $$$ }' --lang rust
|
|
143
|
+
ast-grep --pattern 'pub trait $NAME { $$$ }' --lang rust
|
|
144
|
+
|
|
145
|
+
# Python: classes
|
|
146
|
+
ast-grep --pattern 'class $NAME: $$$' --lang python
|
|
147
|
+
|
|
148
|
+
# TypeScript: interfaces, types, classes
|
|
149
|
+
ast-grep --pattern 'export interface $NAME { $$$ }' --lang ts
|
|
150
|
+
ast-grep --pattern 'export type $NAME = $TYPE' --lang ts
|
|
151
|
+
ast-grep --pattern 'export class $NAME { $$$ }' --lang ts
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
**Step 5 — Public functions / methods**
|
|
155
|
+
```bash
|
|
156
|
+
# Rust: public fns (with --json for machine-parseable output)
|
|
157
|
+
ast-grep --pattern 'pub fn $NAME($$$) -> $RET { $$$ }' --lang rust --json
|
|
158
|
+
|
|
159
|
+
# Rust: public fns (no return type)
|
|
160
|
+
ast-grep --pattern 'pub fn $NAME($$$) { $$$ }' --lang rust
|
|
161
|
+
|
|
162
|
+
# Python: top-level defs
|
|
163
|
+
ast-grep --pattern 'def $NAME($$$): $$$' --lang python
|
|
164
|
+
|
|
165
|
+
# TypeScript: exported functions
|
|
166
|
+
ast-grep --pattern 'export function $NAME($$$): $RET { $$$ }' --lang ts
|
|
167
|
+
ast-grep --pattern 'export const $NAME = ($$$) => $BODY' --lang ts
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
**Step 6 — External dependencies**
|
|
171
|
+
```bash
|
|
172
|
+
# Rust: use statements (top-level imports)
|
|
173
|
+
ast-grep --pattern 'use $PATH' --lang rust
|
|
174
|
+
|
|
175
|
+
# Python: imports
|
|
176
|
+
ast-grep --pattern 'import $MODULE' --lang python
|
|
177
|
+
ast-grep --pattern 'from $MODULE import $NAME' --lang python
|
|
178
|
+
|
|
179
|
+
# JS/TS: imports
|
|
180
|
+
ast-grep --pattern 'import $NAME from "$PATH"' --lang ts
|
|
181
|
+
ast-grep --pattern 'import { $$$ } from "$PATH"' --lang ts
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
**Output**: Append to `CODEBASE_MAP.md`:
|
|
185
|
+
```markdown
|
|
186
|
+
## Public API Surface
|
|
187
|
+
### Types
|
|
188
|
+
- `TypeName` — <kind: struct/enum/class> — <file:line>
|
|
189
|
+
|
|
190
|
+
### Functions
|
|
191
|
+
- `fn_name(args) -> ret` — <file:line>
|
|
192
|
+
|
|
193
|
+
### Key Dependencies
|
|
194
|
+
- <dep_name>: <apparent purpose>
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
---
|
|
198
|
+
|
|
199
|
+
### Phase 2 — Relationship Mapping `[EXECUTION_LOG]`
|
|
200
|
+
|
|
201
|
+
Find how components connect. This answers Socratic questions 8–11.
|
|
202
|
+
|
|
203
|
+
**Step 7 — Trait/interface implementations**
|
|
204
|
+
```bash
|
|
205
|
+
# Rust: impl blocks (what implements what)
|
|
206
|
+
ast-grep --pattern 'impl $TRAIT for $TYPE { $$$ }' --lang rust
|
|
207
|
+
|
|
208
|
+
# Rust: plain impl blocks
|
|
209
|
+
ast-grep --pattern 'impl $TYPE { $$$ }' --lang rust
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
**Step 8 — Call-site mapping (who calls what)**
|
|
213
|
+
```bash
|
|
214
|
+
# Find all calls to a specific function (replace TARGET with function name)
|
|
215
|
+
ast-grep --pattern '$OBJ.TARGET($$$)' --lang rust
|
|
216
|
+
ast-grep --pattern 'TARGET($$$)' --lang rust
|
|
217
|
+
|
|
218
|
+
# Find all method calls on a type
|
|
219
|
+
ast-grep --pattern '$VAR: $TYPE' --lang rust # find variable declarations of a type
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
**Step 9 — Error handling topology**
|
|
223
|
+
```bash
|
|
224
|
+
# Rust: Result types and ? operator usage
|
|
225
|
+
ast-grep --pattern 'Result<$T, $E>' --lang rust
|
|
226
|
+
ast-grep --pattern '$EXPR?' --lang rust
|
|
227
|
+
|
|
228
|
+
# Rust: custom error enums
|
|
229
|
+
ast-grep --pattern 'pub enum $NAME { $$$ }' --lang rust # filter for Error suffix
|
|
230
|
+
|
|
231
|
+
# Python: exception definitions
|
|
232
|
+
ast-grep --pattern 'class $NAME(Exception): $$$' --lang python
|
|
233
|
+
ast-grep --pattern 'except $EXC: $$$' --lang python
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
**Step 10 — Configuration and deserialization surface**
|
|
237
|
+
```bash
|
|
238
|
+
# Rust: serde derives (anything Deserialize is config/data entry)
|
|
239
|
+
ast-grep --pattern '#[derive($$$Deserialize$$$)] $STRUCT' --lang rust
|
|
240
|
+
|
|
241
|
+
# Python: dataclasses, pydantic models
|
|
242
|
+
ast-grep --pattern '@dataclass' --lang python
|
|
243
|
+
ast-grep --pattern 'class $NAME(BaseModel): $$$' --lang python
|
|
244
|
+
|
|
245
|
+
# TypeScript: zod schemas, JSON parse points
|
|
246
|
+
ast-grep --pattern 'z.object({ $$$ })' --lang ts
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
**Output**: Write `DEPENDENCY_GRAPH.md`:
|
|
250
|
+
```markdown
|
|
251
|
+
# DEPENDENCY_GRAPH.md
|
|
252
|
+
## Module Relationships
|
|
253
|
+
- `module_a` → calls → `module_b` (via fn_name)
|
|
254
|
+
|
|
255
|
+
## Trait Implementations
|
|
256
|
+
- `TypeX` implements `TraitY`
|
|
257
|
+
|
|
258
|
+
## Error Taxonomy
|
|
259
|
+
- `ErrorVariant`: exits at <file:line>
|
|
260
|
+
|
|
261
|
+
## Config / Data Entry Points
|
|
262
|
+
- `StructName` (Deserialize): loaded at <file>
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
---
|
|
266
|
+
|
|
267
|
+
### Phase 3 — Pattern & Idiom Mining `[EXECUTION_LOG]`
|
|
268
|
+
|
|
269
|
+
Identify recurring structural decisions. These reveal the codebase's philosophy.
|
|
270
|
+
|
|
271
|
+
**Step 11 — Test patterns**
|
|
272
|
+
```bash
|
|
273
|
+
# Rust: test functions
|
|
274
|
+
ast-grep --pattern '#[test] fn $NAME() { $$$ }' --lang rust
|
|
275
|
+
ast-grep --pattern '#[tokio::test] async fn $NAME() { $$$ }' --lang rust
|
|
276
|
+
|
|
277
|
+
# Python: pytest / unittest
|
|
278
|
+
ast-grep --pattern 'def test_$NAME($$$): $$$' --lang python
|
|
279
|
+
ast-grep --pattern 'class $NAME(TestCase): $$$' --lang python
|
|
280
|
+
|
|
281
|
+
# JS/TS: jest / vitest
|
|
282
|
+
ast-grep --pattern 'it("$DESC", $$$)' --lang ts
|
|
283
|
+
ast-grep --pattern 'describe("$DESC", $$$)' --lang ts
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
**Step 12 — Unsafe / risk markers**
|
|
287
|
+
```bash
|
|
288
|
+
# Rust: unsafe blocks (security/correctness hotspots)
|
|
289
|
+
ast-grep --pattern 'unsafe { $$$ }' --lang rust
|
|
290
|
+
ast-grep --pattern 'unsafe fn $NAME($$$)' --lang rust
|
|
291
|
+
|
|
292
|
+
# TODO/FIXME markers (language-agnostic comment scan)
|
|
293
|
+
grep -rn "TODO\|FIXME\|HACK\|SAFETY\|PANIC\|unwrap()" --include="*.rs" | head -40
|
|
294
|
+
grep -rn "TODO\|FIXME\|HACK\|BUG" --include="*.py" | head -40
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
**Step 13 — Builder / factory / newtype patterns**
|
|
298
|
+
```bash
|
|
299
|
+
# Rust: builder pattern (fn new / fn build)
|
|
300
|
+
ast-grep --pattern 'fn new($$$) -> Self { $$$ }' --lang rust
|
|
301
|
+
ast-grep --pattern 'fn build(self) -> $TYPE { $$$ }' --lang rust
|
|
302
|
+
|
|
303
|
+
# Rust: newtype wrappers
|
|
304
|
+
ast-grep --pattern 'pub struct $NAME($INNER);' --lang rust
|
|
305
|
+
|
|
306
|
+
# Python: class methods / factories
|
|
307
|
+
ast-grep --pattern '@classmethod' --lang python
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
**Step 14 — Async / concurrency patterns**
|
|
311
|
+
```bash
|
|
312
|
+
# Rust: async functions
|
|
313
|
+
ast-grep --pattern 'async fn $NAME($$$)' --lang rust
|
|
314
|
+
ast-grep --pattern 'tokio::spawn($$$)' --lang rust
|
|
315
|
+
|
|
316
|
+
# Python: async
|
|
317
|
+
ast-grep --pattern 'async def $NAME($$$): $$$' --lang python
|
|
318
|
+
|
|
319
|
+
# JS/TS
|
|
320
|
+
ast-grep --pattern 'await $EXPR' --lang ts
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
**Output**: Append to `PATTERNS.md`:
|
|
324
|
+
```markdown
|
|
325
|
+
# PATTERNS.md
|
|
326
|
+
## Design Patterns Detected
|
|
327
|
+
- Builder: <count> usages, primary in <module>
|
|
328
|
+
- Newtype: <count> usages
|
|
329
|
+
|
|
330
|
+
## Test Coverage Profile
|
|
331
|
+
- Unit tests: <count>
|
|
332
|
+
- Integration tests: <count>
|
|
333
|
+
- Async tests: <count>
|
|
334
|
+
|
|
335
|
+
## Risk Markers
|
|
336
|
+
- unsafe blocks: <count> in <files>
|
|
337
|
+
- TODOs: <list of top ones>
|
|
338
|
+
|
|
339
|
+
## Concurrency Model
|
|
340
|
+
- <async/sync/threaded/actor> — evidence: <fn names>
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
---
|
|
344
|
+
|
|
345
|
+
### Phase 4 — Artifact Generation `[ARTIFACT_UPDATE]`
|
|
346
|
+
|
|
347
|
+
All findings are now crystallised into locked artifacts. No reasoning from memory — only
|
|
348
|
+
from the written artifacts below.
|
|
349
|
+
|
|
350
|
+
**Required artifacts** (write all before Phase 5):
|
|
351
|
+
|
|
352
|
+
| Artifact | Purpose |
|
|
353
|
+
|---|---|
|
|
354
|
+
| `CODEBASE_MAP.md` | Language, entry points, module list, public API surface |
|
|
355
|
+
| `DEPENDENCY_GRAPH.md` | Module relationships, trait impls, error taxonomy |
|
|
356
|
+
| `PATTERNS.md` | Design patterns, test profile, risk markers, concurrency model |
|
|
357
|
+
| `SOCRATIC_LOG.md` | Every question + its ast-grep-verified answer |
|
|
358
|
+
| `EVIDENCE_LOG.md` | Raw ast-grep output snippets used as evidence (append-only) |
|
|
359
|
+
|
|
360
|
+
**Artifact write protocol:**
|
|
361
|
+
```bash
|
|
362
|
+
# Each ast-grep query output MUST be appended to EVIDENCE_LOG.md immediately
|
|
363
|
+
echo "## Query: pub fn signatures (rust)" >> ./agent-state/EVIDENCE_LOG.md
|
|
364
|
+
ast-grep --pattern 'pub fn $NAME($$$) -> $RET { $$$ }' --lang rust --json >> ./agent-state/EVIDENCE_LOG.md
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
**Optional artifacts** (generate when goal demands it):
|
|
368
|
+
|
|
369
|
+
| Artifact | When to generate |
|
|
370
|
+
|---|---|
|
|
371
|
+
| `CALL_GRAPH.md` | Goal = debug / trace data flow |
|
|
372
|
+
| `CONTRIBUTION_GUIDE.md` | Goal = contribute / extend |
|
|
373
|
+
| `INSPIRATION_NOTES.md` | Goal = extract ideas for new project |
|
|
374
|
+
| `BUG_HYPOTHESIS.md` | Goal = debug specific issue |
|
|
375
|
+
|
|
376
|
+
---
|
|
377
|
+
|
|
378
|
+
### Phase 5 — Synthesis Pass `[VERIFICATION]`
|
|
379
|
+
|
|
380
|
+
**ONLY after all Phase 4 artifacts are written**, perform a final reasoning pass.
|
|
381
|
+
Read ONLY the artifacts — not any source files.
|
|
382
|
+
|
|
383
|
+
**Step 15 — Self-verification checklist**
|
|
384
|
+
- [ ] Can I describe the codebase architecture in 3 sentences from `CODEBASE_MAP.md` alone?
|
|
385
|
+
- [ ] Can I name the 5 most important types/functions without looking at source?
|
|
386
|
+
- [ ] Can I explain the data flow from entry to exit from `DEPENDENCY_GRAPH.md`?
|
|
387
|
+
- [ ] Have all Tier 2 Socratic questions been answered in `SOCRATIC_LOG.md`?
|
|
388
|
+
- [ ] Does `EVIDENCE_LOG.md` have at least one ast-grep snippet per structural claim?
|
|
389
|
+
|
|
390
|
+
**Step 16 — Goal-aligned synthesis**
|
|
391
|
+
|
|
392
|
+
*Mode: UNDERSTAND*
|
|
393
|
+
> Synthesise `CODEBASE_MAP.md` + `PATTERNS.md` into a plain-English architecture document.
|
|
394
|
+
|
|
395
|
+
*Mode: DEBUG*
|
|
396
|
+
> Trace the bug-relevant call path using `CALL_GRAPH.md`. Write `BUG_HYPOTHESIS.md`
|
|
397
|
+
> with: symptom → suspected module → ast-grep evidence → falsification criteria.
|
|
398
|
+
|
|
399
|
+
*Mode: CONTRIBUTE / ADD FEATURE*
|
|
400
|
+
> From `DEPENDENCY_GRAPH.md`, identify the minimum insertion point. Write
|
|
401
|
+
> `CONTRIBUTION_GUIDE.md` with: interface contract, which existing tests to extend,
|
|
402
|
+
> which patterns to follow (from `PATTERNS.md`).
|
|
403
|
+
|
|
404
|
+
*Mode: INSPIRE*
|
|
405
|
+
> Extract architectural decisions, naming conventions, idioms from `PATTERNS.md` into
|
|
406
|
+
> `INSPIRATION_NOTES.md` with annotations on what can be adapted.
|
|
407
|
+
|
|
408
|
+
**Step 17 — HANDOFF**
|
|
409
|
+
|
|
410
|
+
Emit `HANDOFF.json` when synthesis is complete:
|
|
411
|
+
```json
|
|
412
|
+
{
|
|
413
|
+
"meta": { "timestamp": "<ISO8601>", "skill": "codemunch", "session_id": "<uuid>" },
|
|
414
|
+
"transition": {
|
|
415
|
+
"from": "capability-research",
|
|
416
|
+
"to": "capability-spec",
|
|
417
|
+
"status": "READY_FOR_HANDOFF",
|
|
418
|
+
"reason": "Codebase map and pattern artifacts are locked."
|
|
419
|
+
},
|
|
420
|
+
"payload": {
|
|
421
|
+
"primary_artifact": "./agent-state/CODEBASE_MAP.md",
|
|
422
|
+
"supporting_artifacts": [
|
|
423
|
+
"./agent-state/DEPENDENCY_GRAPH.md",
|
|
424
|
+
"./agent-state/PATTERNS.md",
|
|
425
|
+
"./agent-state/SOCRATIC_LOG.md"
|
|
426
|
+
],
|
|
427
|
+
"evidence_pointer": "./agent-state/EVIDENCE_LOG.md",
|
|
428
|
+
"known_unknowns": ["<list any unanswered Tier 3/4 questions>"]
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
```
|
|
432
|
+
|
|
433
|
+
---
|
|
434
|
+
|
|
435
|
+
## 3. ast-grep Quick Reference
|
|
436
|
+
|
|
437
|
+
### Universal Flags
|
|
438
|
+
```bash
|
|
439
|
+
--lang <lang> # rust | python | js | ts | tsx | go | java | cpp | c | html | css
|
|
440
|
+
--pattern / -p # inline pattern
|
|
441
|
+
--rule <file.yml> # YAML rule file for complex patterns
|
|
442
|
+
--json / -j # machine-readable JSON output (use for artifact writing)
|
|
443
|
+
--no-ignore # scan files ignored by .gitignore
|
|
444
|
+
--color never # disable ANSI in output (use when piping to artifact files)
|
|
445
|
+
```
|
|
446
|
+
|
|
447
|
+
### Meta-variable Syntax
|
|
448
|
+
```
|
|
449
|
+
$NAME — single AST node (identifier, expression, etc.)
|
|
450
|
+
$$$ — zero or more AST nodes (variadic / body capture)
|
|
451
|
+
$$ARGS — named multi-match capture
|
|
452
|
+
$_ — anonymous wildcard (matches anything, not captured)
|
|
453
|
+
```
|
|
454
|
+
|
|
455
|
+
### YAML Rule Template (complex structural queries)
|
|
456
|
+
```yaml
|
|
457
|
+
# Save as ./codemunch-rules/<rule-name>.yml
|
|
458
|
+
id: find-pattern-name
|
|
459
|
+
language: rust
|
|
460
|
+
rule:
|
|
461
|
+
pattern: pub fn $NAME($$$) -> Result<$T, $E> { $$$ }
|
|
462
|
+
# Optional filters:
|
|
463
|
+
inside:
|
|
464
|
+
pattern: impl $TRAIT for $TYPE { $$$ }
|
|
465
|
+
has:
|
|
466
|
+
pattern: $EXPR? # contains at least one ? operator
|
|
467
|
+
not:
|
|
468
|
+
pattern: todo!() # exclude unimplemented stubs
|
|
469
|
+
```
|
|
470
|
+
Run: `ast-grep scan --rule ./codemunch-rules/<rule-name>.yml`
|
|
471
|
+
|
|
472
|
+
### Language Cheat Sheet
|
|
473
|
+
|
|
474
|
+
**Rust**
|
|
475
|
+
```bash
|
|
476
|
+
ast-grep -p 'pub fn $N($$$)' -l rust # public functions
|
|
477
|
+
ast-grep -p 'impl $T for $U { $$$ }' -l rust # trait impls
|
|
478
|
+
ast-grep -p '#[derive($$$)]' -l rust # all derives
|
|
479
|
+
ast-grep -p 'Err($E)' -l rust # error emission sites
|
|
480
|
+
ast-grep -p '$V.unwrap()' -l rust # panic hotspots
|
|
481
|
+
```
|
|
482
|
+
|
|
483
|
+
**Python**
|
|
484
|
+
```bash
|
|
485
|
+
ast-grep -p 'def $N($$$) -> $R: $$$' -l python # typed functions
|
|
486
|
+
ast-grep -p '@$DECORATOR' -l python # all decorators
|
|
487
|
+
ast-grep -p 'raise $E' -l python # exception sites
|
|
488
|
+
ast-grep -p '__all__ = [$$$]' -l python # public exports
|
|
489
|
+
```
|
|
490
|
+
|
|
491
|
+
**TypeScript / JavaScript**
|
|
492
|
+
```bash
|
|
493
|
+
ast-grep -p 'export { $$$ }' -l ts # barrel exports
|
|
494
|
+
ast-grep -p 'const $N = useCallback($$$)' -l tsx # React hooks
|
|
495
|
+
ast-grep -p 'throw new $E($$$)' -l ts # throw sites
|
|
496
|
+
ast-grep -p 'satisfies $TYPE' -l ts # type constraints
|
|
497
|
+
```
|
|
498
|
+
|
|
499
|
+
---
|
|
500
|
+
|
|
501
|
+
## 3.1 Wrong-Stuff Protocol
|
|
502
|
+
|
|
503
|
+
When ast-grep analysis reveals structural issues:
|
|
504
|
+
|
|
505
|
+
| Finding | Classification | Route To |
|
|
506
|
+
|---|---|---|
|
|
507
|
+
| Code contradicts spec claims | `spec_violation` | `agent-spec` |
|
|
508
|
+
| Unsafe/risky patterns detected | `implementation_bug` | `agent-builder` |
|
|
509
|
+
| Evidence source unreliable | `invalid_source` | `agent-research` (self-correct) |
|
|
510
|
+
| Codebase documentation stale | `documentation_drift` | `agent-docs` |
|
|
511
|
+
|
|
512
|
+
## 3.2 Anti-Patterns
|
|
513
|
+
|
|
514
|
+
| Anti-Pattern | Correct Behavior |
|
|
515
|
+
|---|---|
|
|
516
|
+
| Reading raw source files | Use ast-grep queries exclusively |
|
|
517
|
+
| Guessing structure without AST evidence | Every claim backed by ast-grep output |
|
|
518
|
+
| Session ends without artifacts | Minimum output: `CODEBASE_MAP.md` |
|
|
519
|
+
| Querying all languages blindly | Detect primary language first (Phase 0), then query |
|
|
520
|
+
| Capturing > 500 lines of raw output | Summarize into bullet points; keep exemplars only |
|
|
521
|
+
|
|
522
|
+
---
|
|
523
|
+
|
|
524
|
+
## 4. Failure Modes & Circuit Breakers
|
|
525
|
+
|
|
526
|
+
| Failure | Signal | Recovery |
|
|
527
|
+
|---|---|---|
|
|
528
|
+
| `ast-grep` returns no matches | Pattern may be wrong for this dialect | Use `--json` + inspect one sample node kind first |
|
|
529
|
+
| Artifact file > 500 lines | Too much raw output captured | Summarise into bullet points; keep only exemplars in EVIDENCE_LOG |
|
|
530
|
+
| Socratic question unresolvable via AST | Deep runtime behaviour | Mark as `KNOWN_UNKNOWN` in SOCRATIC_LOG; do NOT guess |
|
|
531
|
+
| Goal changes mid-session | New task injected | Emit `GATE_FAILED`, re-enter Phase 0 with updated goal |
|
|
532
|
+
|
|
533
|
+
---
|
|
534
|
+
|
|
535
|
+
## 5. Activation
|
|
536
|
+
|
|
537
|
+
When you receive a codebase (path, repo, or CXML dump) with a goal, type:
|
|
538
|
+
|
|
539
|
+
**`munch <path> --goal <understand|debug|contribute|inspire> [--lang <lang>]`**
|
|
540
|
+
|
|
541
|
+
CodeMunch will automatically enter Phase 0, execute the Socratic Question Stack, run
|
|
542
|
+
ast-grep queries in order, and produce the Phase 4 artifacts before delivering the
|
|
543
|
+
Phase 5 synthesis. No raw file reading. No token waste. Only structure.
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: codesnipe
|
|
3
|
+
description:
|
|
4
|
+
Compare a HOME codebase with a TARGET codebase by scoring TARGET symbols against HOME first. Use when you need adoption candidates, divergence analysis, bug triangulation, or integration ideas instead of broad repo browsing.
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# CodeSnipe
|
|
8
|
+
|
|
9
|
+
Use this skill to perform evidence-backed, dual-codebase comparison without wasting attention on low-signal TARGET code.
|
|
10
|
+
|
|
11
|
+
## Purpose
|
|
12
|
+
|
|
13
|
+
Build a HOME-aware relevance map so only the most comparable or adoptable TARGET symbols are extracted, analyzed, and handed off.
|
|
14
|
+
|
|
15
|
+
## Canonical Use Cases
|
|
16
|
+
|
|
17
|
+
1. A team wants to adopt a pattern from another repository and needs ranked implementation candidates instead of broad comparison notes.
|
|
18
|
+
2. A bug or gap in the HOME codebase might already be solved in a TARGET codebase, and the team wants precise triangulation.
|
|
19
|
+
3. An integration or competitor study requires knowing what TARGET does relative to HOME before deeper reading begins.
|
|
20
|
+
|
|
21
|
+
## Inputs
|
|
22
|
+
|
|
23
|
+
- HOME codebase path
|
|
24
|
+
- TARGET codebase path or checkout
|
|
25
|
+
- Comparison intent such as `steal`, `compare`, `debug`, or `integrate`
|
|
26
|
+
- ast-grep plus any lightweight registry artifacts already available under `agent-state/snipe/`
|
|
27
|
+
|
|
28
|
+
## Workflow
|
|
29
|
+
|
|
30
|
+
1. Build a HOME symbol registry and pattern fingerprint first.
|
|
31
|
+
2. Outline TARGET at the symbol-name and module-shape level without reading implementations.
|
|
32
|
+
3. Score TARGET symbols against HOME and record the relevance map.
|
|
33
|
+
4. Extract only symbols that meet the score threshold, then analyze divergence or adoption fit.
|
|
34
|
+
5. Write the comparison artifacts and handoff recommendation under `agent-state/snipe/`.
|
|
35
|
+
|
|
36
|
+
## Outputs
|
|
37
|
+
|
|
38
|
+
- `agent-state/snipe/SNIPE_HOME_REGISTRY.md`
|
|
39
|
+
- `agent-state/snipe/SNIPE_TARGET_OUTLINE.md`
|
|
40
|
+
- `agent-state/snipe/SNIPE_RELEVANCE_MAP.md`
|
|
41
|
+
- `agent-state/snipe/SNIPE_EXTRACTS.jsonl`
|
|
42
|
+
- `agent-state/snipe/SNIPE_COMPARISON.md`
|
|
43
|
+
|
|
44
|
+
## Validation
|
|
45
|
+
|
|
46
|
+
- Verify the HOME registry exists before any TARGET implementation read occurs.
|
|
47
|
+
- Verify every discussed TARGET symbol has a recorded relevance score in `SNIPE_RELEVANCE_MAP.md`.
|
|
48
|
+
- Verify the final comparison artifact contains at least one explicit recommendation: adopt, adapt, ignore, or unrelated.
|
|
49
|
+
|
|
50
|
+
## References
|
|
51
|
+
|
|
52
|
+
- `references/dual-codebase-playbook.md` preserves the detailed scoring formula, phase recipes, and intent-specific extraction playbooks.
|
|
53
|
+
|
|
54
|
+
## Compatibility
|
|
55
|
+
|
|
56
|
+
- `SKILL.md` is the canonical portable contract for this skill.
|
|
57
|
+
- The detailed comparison cookbook lives under `references/` for progressive disclosure and should not replace the top-level contract.
|
|
58
|
+
- The workflow remains portable anywhere HOME/TARGET code can be queried structurally with ast-grep and basic shell tooling.
|
|
59
|
+
|
|
60
|
+
## Failure Policy
|
|
61
|
+
|
|
62
|
+
- If the HOME registry is empty or cannot be built, halt before reading TARGET implementations.
|
|
63
|
+
- If all TARGET symbols score below the threshold, report that the TARGET is unrelated or low-yield instead of forcing comparison.
|
|
64
|
+
- Do not read or summarize unscored TARGET symbols; treat that as a protocol violation.
|