@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,671 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: codesnipe
|
|
3
|
+
description:
|
|
4
|
+
Dual-codebase precision comparison via ast-grep. Builds a symbol registry for YOUR (HOME) codebase first, then surgically snipes a TARGET codebase to find what is relevant, inspiring, addable, or comparable — scored and ranked before a single implementation line is read. Companion to codemunch; where codemunch holistically maps one codebase, codesnipe triangulates two.
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# CodeSnipe — Dual-Codebase Precision Intelligence
|
|
8
|
+
|
|
9
|
+
**IMPORTANT**: CodeSnipe is NOT a code reader. It is a code comparator. Before reading
|
|
10
|
+
a single implementation line from the TARGET, you MUST first build a symbol registry
|
|
11
|
+
of the HOME codebase. Every TARGET symbol you retrieve must first earn a relevance score
|
|
12
|
+
against the HOME registry. Low-scoring symbols are DISCARDED — not read, not summarised,
|
|
13
|
+
not discussed. The sniper does not spray. The sniper fires once, and only at verified targets.
|
|
14
|
+
|
|
15
|
+
**The Two-Question Contract** (borrowed from jcodemunch-mcp's dual-server philosophy):
|
|
16
|
+
1. "What does TARGET *do* relative to HOME?" — answered by OUTLINE phase only.
|
|
17
|
+
2. "How does TARGET *do it*?" — answered only for symbols that scored ≥ 8 in relevance.
|
|
18
|
+
|
|
19
|
+
Reading a symbol that scored < 8 is a token waste and a protocol violation.
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## 0. ACE Role Declaration
|
|
24
|
+
|
|
25
|
+
CodeSnipe operates as a `capability-research` module with a **comparative output contract**.
|
|
26
|
+
|
|
27
|
+
- **Emits** `SOURCE_VALIDATED` events per symbol snipe (with relevance score attached).
|
|
28
|
+
- **Emits** `GATE_FAILED` if the HOME registry is empty when TARGET sniping begins.
|
|
29
|
+
- **Writes** to `./agent-state/snipe/` (separate namespace from codemunch artifacts).
|
|
30
|
+
- **Blocks** downstream modules from acting on TARGET patterns that lack HOME context.
|
|
31
|
+
- **Hands off** via `HANDOFF.json` once `SNIPE_COMPARISON.md` is locked and scored.
|
|
32
|
+
|
|
33
|
+
ACE Clarity Protocol headers must be used at each phase boundary.
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
## 0.1 MICE Boundaries
|
|
38
|
+
|
|
39
|
+
| Rule | Enforcement |
|
|
40
|
+
|---|---|
|
|
41
|
+
| **Modular** | Compares codebases at symbol level; does NOT modify HOME or TARGET code. |
|
|
42
|
+
| **Interoperable** | All findings written as standardized artifacts in `./agent-state/snipe/`. |
|
|
43
|
+
| **Customizable** | Intent parameter (`steal/compare/debug/integrate`) controls scoring weights. |
|
|
44
|
+
| **Extensible** | New comparison criteria added via scoring formula weights, not ad-hoc rules. |
|
|
45
|
+
|
|
46
|
+
## 0.2 Goal Orientation
|
|
47
|
+
|
|
48
|
+
- `DELETE_PROTOCOL`: Discard all TARGET symbols scoring < 8. No token waste on irrelevant code.
|
|
49
|
+
- `ARTIFACT_PROTOCOL`: Session MUST produce `SNIPE_COMPARISON.md` minimum. No artifact = failed session.
|
|
50
|
+
- `AGENCY_PROTOCOL`: HOME registry drives all TARGET queries. Never read TARGET without HOME context.
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
## 1. The Dual-Context Model
|
|
57
|
+
|
|
58
|
+
Every CodeSnipe session operates with two explicit roles:
|
|
59
|
+
|
|
60
|
+
```
|
|
61
|
+
HOME = the codebase you OWN, MAINTAIN, or are WORKING ON.
|
|
62
|
+
Source of truth for "what we already do."
|
|
63
|
+
|
|
64
|
+
TARGET = the codebase you are STUDYING, COMPARING AGAINST, or DRAWING FROM.
|
|
65
|
+
Source of potential patterns, ideas, missing features, or alternative
|
|
66
|
+
implementations.
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
**The Relevance Score** gates all TARGET reads:
|
|
70
|
+
|
|
71
|
+
| Score | Signal | Action |
|
|
72
|
+
|---|---|---|
|
|
73
|
+
| 20 | Exact symbol name match in HOME | Read TARGET implementation; direct comparison possible |
|
|
74
|
+
| 12–19 | Structural/semantic overlap with HOME | Read TARGET implementation; likely inspiration or divergence |
|
|
75
|
+
| 8–11 | Partial name or pattern overlap | Read signature only; decide before reading body |
|
|
76
|
+
| 4–7 | Weak thematic connection | Log to KNOWN_UNKNOWNS; do not read |
|
|
77
|
+
| 0–3 | No meaningful connection to HOME | Discard |
|
|
78
|
+
|
|
79
|
+
The scoring formula (adapted from jcodemunch-mcp's weighted search):
|
|
80
|
+
```
|
|
81
|
+
score = 0
|
|
82
|
+
score += 20 if exact name match (HOME symbol name == TARGET symbol name)
|
|
83
|
+
score += 10 if name substring match
|
|
84
|
+
score += 5 per shared word in name
|
|
85
|
+
score += 8 if full signature pattern match (same function shape)
|
|
86
|
+
score += 4 if return type matches a HOME type
|
|
87
|
+
score += 3 if parameter types overlap with HOME types
|
|
88
|
+
score += 5 if TARGET docstring mentions a concept present in HOME
|
|
89
|
+
score += 2 per shared decorator/attribute
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Compute this BEFORE running any `ast-grep` pattern to read an implementation.
|
|
93
|
+
|
|
94
|
+
---
|
|
95
|
+
|
|
96
|
+
## 2. The Snipe Socratic Stack
|
|
97
|
+
|
|
98
|
+
Run this stack in order. **The first question you cannot answer from the HOME registry
|
|
99
|
+
is your first ast-grep snipe into the TARGET.**
|
|
100
|
+
|
|
101
|
+
**Tier 0 — Establish HOME Baseline**
|
|
102
|
+
1. What symbols does HOME export publicly? (functions, types, classes, constants)
|
|
103
|
+
2. What are HOME's primary design patterns? (builder, registry, pipeline, actor, etc.)
|
|
104
|
+
3. What problems does HOME solve? (one sentence per module)
|
|
105
|
+
4. Where are HOME's extension/plugin points?
|
|
106
|
+
5. What does HOME conspicuously NOT do? (known gaps, TODOs, deferred features)
|
|
107
|
+
|
|
108
|
+
**Tier 1 — Profile TARGET at Outline Level**
|
|
109
|
+
6. What languages and structure does TARGET use?
|
|
110
|
+
7. What is TARGET's stated purpose? Does it overlap with HOME's domain?
|
|
111
|
+
8. What public symbols does TARGET expose? (names only — no implementations yet)
|
|
112
|
+
9. Which TARGET symbol names appear verbatim or approximately in HOME?
|
|
113
|
+
10. Which TARGET module names map to HOME module names?
|
|
114
|
+
|
|
115
|
+
**Tier 2 — Score and Rank**
|
|
116
|
+
11. Which TARGET symbols scored ≥ 12 against HOME? (prime snipe candidates)
|
|
117
|
+
12. Which TARGET symbols represent concepts HOME has TODOs for?
|
|
118
|
+
13. Which TARGET patterns appear 3+ times but are absent from HOME?
|
|
119
|
+
14. Does TARGET solve any HOME Tier-5 Socratic question (known gaps)?
|
|
120
|
+
|
|
121
|
+
**Tier 3 — Precision Extraction (only for score ≥ 8 symbols)**
|
|
122
|
+
15. How does TARGET implement the high-score symbol? (read body now)
|
|
123
|
+
16. What does TARGET do that HOME does differently? (divergence analysis)
|
|
124
|
+
17. Is TARGET's approach adoptable in HOME's architecture without breaking changes?
|
|
125
|
+
18. What would adoption cost? (new dependencies, refactors, interface changes)
|
|
126
|
+
|
|
127
|
+
> **Rule**: Write every scored symbol into `SNIPE_RELEVANCE_MAP.md` immediately.
|
|
128
|
+
> A symbol discussed without a recorded score is a protocol violation.
|
|
129
|
+
|
|
130
|
+
---
|
|
131
|
+
|
|
132
|
+
## 3. Execution Protocol
|
|
133
|
+
|
|
134
|
+
### Phase 0 — HOME Registry Build `[STATE_ANALYSIS]`
|
|
135
|
+
|
|
136
|
+
**Never skip this phase.** No TARGET sniping without a complete HOME registry.
|
|
137
|
+
|
|
138
|
+
**Step 1 — HOME public API surface**
|
|
139
|
+
```bash
|
|
140
|
+
# Rust
|
|
141
|
+
ast-grep --pattern 'pub fn $NAME($$$)' --lang rust --json | \
|
|
142
|
+
jq '.[] | {name: .metaVariables.NAME, file: .file, line: .range.start.line}' \
|
|
143
|
+
>> ./agent-state/snipe/HOME_REGISTRY.jsonl
|
|
144
|
+
|
|
145
|
+
ast-grep --pattern 'pub struct $NAME' --lang rust --json | \
|
|
146
|
+
jq '.[] | {name: .metaVariables.NAME, kind: "struct", file: .file}' \
|
|
147
|
+
>> ./agent-state/snipe/HOME_REGISTRY.jsonl
|
|
148
|
+
|
|
149
|
+
ast-grep --pattern 'pub trait $NAME' --lang rust --json | \
|
|
150
|
+
jq '.[] | {name: .metaVariables.NAME, kind: "trait", file: .file}' \
|
|
151
|
+
>> ./agent-state/snipe/HOME_REGISTRY.jsonl
|
|
152
|
+
|
|
153
|
+
# Python
|
|
154
|
+
ast-grep --pattern 'def $NAME($$$):' --lang python --json | \
|
|
155
|
+
jq '.[] | {name: .metaVariables.NAME, kind: "function", file: .file}' \
|
|
156
|
+
>> ./agent-state/snipe/HOME_REGISTRY.jsonl
|
|
157
|
+
|
|
158
|
+
ast-grep --pattern 'class $NAME:' --lang python --json | \
|
|
159
|
+
jq '.[] | {name: .metaVariables.NAME, kind: "class", file: .file}' \
|
|
160
|
+
>> ./agent-state/snipe/HOME_REGISTRY.jsonl
|
|
161
|
+
|
|
162
|
+
# TypeScript / JavaScript
|
|
163
|
+
ast-grep --pattern 'export function $NAME($$$)' --lang ts --json | \
|
|
164
|
+
jq '.[] | {name: .metaVariables.NAME, kind: "function", file: .file}' \
|
|
165
|
+
>> ./agent-state/snipe/HOME_REGISTRY.jsonl
|
|
166
|
+
|
|
167
|
+
ast-grep --pattern 'export class $NAME' --lang ts --json | \
|
|
168
|
+
jq '.[] | {name: .metaVariables.NAME, kind: "class", file: .file}' \
|
|
169
|
+
>> ./agent-state/snipe/HOME_REGISTRY.jsonl
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
**Step 2 — HOME gap map (known unknowns)**
|
|
173
|
+
```bash
|
|
174
|
+
# Extract TODOs, FIXMEs, unimplemented stubs — these are prime adoption targets
|
|
175
|
+
grep -rn "TODO\|FIXME\|HACK\|unimplemented!\|todo!()" \
|
|
176
|
+
--include="*.rs" --include="*.py" --include="*.ts" \
|
|
177
|
+
| grep -v ".git" | head -50 \
|
|
178
|
+
>> ./agent-state/snipe/HOME_GAP_MAP.txt
|
|
179
|
+
|
|
180
|
+
# Rust: unimplemented/todo macros (structural, not comment)
|
|
181
|
+
ast-grep --pattern 'unimplemented!()' --lang rust
|
|
182
|
+
ast-grep --pattern 'todo!()' --lang rust
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
**Step 3 — HOME pattern fingerprint**
|
|
186
|
+
```bash
|
|
187
|
+
# What recurring structural patterns define HOME's style?
|
|
188
|
+
# Rust: error enum pattern
|
|
189
|
+
ast-grep --pattern 'pub enum $NAME { $$$ }' --lang rust | grep -i "err\|Error\|Fail"
|
|
190
|
+
|
|
191
|
+
# Rust: Result-returning public functions (count as percentage of all pub fns)
|
|
192
|
+
ast-grep --pattern 'pub fn $NAME($$$) -> Result<$$$>' --lang rust
|
|
193
|
+
|
|
194
|
+
# Python: decorator usage (marks framework patterns)
|
|
195
|
+
ast-grep --pattern '@$DECORATOR' --lang python --json | \
|
|
196
|
+
jq -r '.[] | .metaVariables.DECORATOR' | sort | uniq -c | sort -rn | head -15
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
**Output**: Write `SNIPE_HOME_REGISTRY.md`:
|
|
200
|
+
```markdown
|
|
201
|
+
# SNIPE_HOME_REGISTRY.md
|
|
202
|
+
Generated: <timestamp>
|
|
203
|
+
HOME Path: <path>
|
|
204
|
+
Language(s): <langs>
|
|
205
|
+
|
|
206
|
+
## Public Symbol Inventory
|
|
207
|
+
| Symbol | Kind | File | Notes |
|
|
208
|
+
|--------|------|------|-------|
|
|
209
|
+
| <name> | fn/class/trait/type | <file> | |
|
|
210
|
+
|
|
211
|
+
## Pattern Fingerprint
|
|
212
|
+
- Primary error handling: <Result/Exception/Either>
|
|
213
|
+
- Primary concurrency: <async/sync/threaded>
|
|
214
|
+
- Decorator/attribute patterns: <list>
|
|
215
|
+
- Extension points: <list>
|
|
216
|
+
|
|
217
|
+
## Known Gaps (from TODOs/unimplemented)
|
|
218
|
+
- <file:line>: <todo text>
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
**Gate**: HOME registry must contain ≥ 1 symbol before proceeding to Phase 1.
|
|
222
|
+
If HOME is empty or inaccessible, emit `GATE_FAILED` and halt.
|
|
223
|
+
|
|
224
|
+
---
|
|
225
|
+
|
|
226
|
+
### Phase 1 — TARGET Outline (No Reads Yet) `[STRATEGY_SELECTOR]`
|
|
227
|
+
|
|
228
|
+
Extract TARGET structure at the symbol-name level only. Zero implementations read.
|
|
229
|
+
|
|
230
|
+
**Step 4 — TARGET skeleton**
|
|
231
|
+
```bash
|
|
232
|
+
# Run from TARGET directory. Mirror HOME's Phase 0 queries exactly.
|
|
233
|
+
cd <TARGET_PATH>
|
|
234
|
+
|
|
235
|
+
# Rust
|
|
236
|
+
ast-grep --pattern 'pub fn $NAME($$$)' --lang rust --json | \
|
|
237
|
+
jq '.[] | {name: .metaVariables.NAME, kind: "function", file: .file}' \
|
|
238
|
+
>> ./agent-state/snipe/TARGET_OUTLINE.jsonl
|
|
239
|
+
|
|
240
|
+
# Python
|
|
241
|
+
ast-grep --pattern 'def $NAME($$$):' --lang python --json | \
|
|
242
|
+
jq '.[] | {name: .metaVariables.NAME, kind: "function", file: .file}' \
|
|
243
|
+
>> ./agent-state/snipe/TARGET_OUTLINE.jsonl
|
|
244
|
+
|
|
245
|
+
# TypeScript
|
|
246
|
+
ast-grep --pattern 'export function $NAME($$$)' --lang ts --json | \
|
|
247
|
+
jq '.[] | {name: .metaVariables.NAME, kind: "function", file: .file}' \
|
|
248
|
+
>> ./agent-state/snipe/TARGET_OUTLINE.jsonl
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
**Step 5 — TARGET structural shape (without reading bodies)**
|
|
252
|
+
```bash
|
|
253
|
+
# Module/file structure
|
|
254
|
+
find . -type f \( -name "*.rs" -o -name "*.py" -o -name "*.ts" \) \
|
|
255
|
+
| grep -v ".git" | sort
|
|
256
|
+
|
|
257
|
+
# Public type surface
|
|
258
|
+
ast-grep --pattern 'pub struct $NAME { $$$ }' --lang rust # Rust types
|
|
259
|
+
ast-grep --pattern 'class $NAME:' --lang python # Python classes
|
|
260
|
+
ast-grep --pattern 'interface $NAME' --lang ts # TS interfaces
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
**Step 6 — TARGET dependency profile**
|
|
264
|
+
```bash
|
|
265
|
+
# What external deps does TARGET use that HOME does not?
|
|
266
|
+
# (Compare against HOME's Cargo.toml / pyproject.toml / package.json)
|
|
267
|
+
cat Cargo.toml | grep -A50 "\[dependencies\]" # Rust
|
|
268
|
+
cat pyproject.toml | grep -A30 "dependencies" # Python
|
|
269
|
+
cat package.json | python3 -c "import sys,json; d=json.load(sys.stdin); [print(k) for k in d.get('dependencies',{}).keys()]" # Node
|
|
270
|
+
|
|
271
|
+
# New deps in TARGET but not HOME = potential new capabilities
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
**Output**: Write `SNIPE_TARGET_OUTLINE.md`:
|
|
275
|
+
```markdown
|
|
276
|
+
# SNIPE_TARGET_OUTLINE.md
|
|
277
|
+
TARGET Path/URL: <path>
|
|
278
|
+
Language(s): <langs>
|
|
279
|
+
Symbol Count: <n>
|
|
280
|
+
|
|
281
|
+
## Symbol Names (outline only)
|
|
282
|
+
| Symbol | Kind | File |
|
|
283
|
+
|--------|------|------|
|
|
284
|
+
| <name> | fn/class/type | <file> |
|
|
285
|
+
|
|
286
|
+
## Dependencies Not in HOME
|
|
287
|
+
- <dep>: <apparent purpose>
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
---
|
|
291
|
+
|
|
292
|
+
### Phase 2 — Relevance Scoring `[EXECUTION_LOG]`
|
|
293
|
+
|
|
294
|
+
This is the **core of CodeSnipe**. No TARGET implementation is read until every symbol
|
|
295
|
+
has a score. Score computation is done against the HOME registry in memory.
|
|
296
|
+
|
|
297
|
+
**Step 7 — Name-match pass**
|
|
298
|
+
```bash
|
|
299
|
+
# For each TARGET symbol name, check if it exists in HOME registry
|
|
300
|
+
# (Run this as a shell one-liner using the JSONL registries)
|
|
301
|
+
|
|
302
|
+
# Exact matches (score += 20)
|
|
303
|
+
comm -12 \
|
|
304
|
+
<(jq -r '.name' ./agent-state/snipe/HOME_REGISTRY.jsonl | sort) \
|
|
305
|
+
<(jq -r '.name' ./agent-state/snipe/TARGET_OUTLINE.jsonl | sort) \
|
|
306
|
+
> ./agent-state/snipe/EXACT_MATCHES.txt
|
|
307
|
+
|
|
308
|
+
# Substring matches (score += 10 each)
|
|
309
|
+
while IFS= read -r target_name; do
|
|
310
|
+
grep -i "$target_name" ./agent-state/snipe/HOME_REGISTRY.jsonl && echo "SUBSTR_MATCH: $target_name"
|
|
311
|
+
done < <(jq -r '.name' ./agent-state/snipe/TARGET_OUTLINE.jsonl) \
|
|
312
|
+
>> ./agent-state/snipe/SUBSTR_MATCHES.txt
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
**Step 8 — Structural pattern match (signature shape)**
|
|
316
|
+
```bash
|
|
317
|
+
# For each TARGET symbol, check if HOME has similar signatures
|
|
318
|
+
# Use ast-grep on TARGET to find signatures matching HOME patterns
|
|
319
|
+
|
|
320
|
+
# Example: if HOME uses Result<T, E> returns extensively,
|
|
321
|
+
# check if TARGET also returns Result-like types
|
|
322
|
+
ast-grep --pattern 'fn $NAME($$$) -> Result<$T, $E>' --lang rust # (run in TARGET)
|
|
323
|
+
ast-grep --pattern 'def $NAME($$$) -> $RETURN:' --lang python # (run in TARGET)
|
|
324
|
+
|
|
325
|
+
# Cross-reference: which TARGET fns return types that exist in HOME?
|
|
326
|
+
ast-grep --pattern 'fn $NAME($$$) -> $RET' --lang rust --json | \
|
|
327
|
+
jq -r '.[] | .metaVariables.RET' \
|
|
328
|
+
| grep -Ff <(jq -r '.name' ./agent-state/snipe/HOME_REGISTRY.jsonl)
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
**Step 9 — Gap alignment pass**
|
|
332
|
+
```bash
|
|
333
|
+
# Does TARGET have implementations for HOME's known gaps?
|
|
334
|
+
# For each TODO in HOME_GAP_MAP.txt, search TARGET for related symbols
|
|
335
|
+
|
|
336
|
+
while IFS= read -r gap; do
|
|
337
|
+
keyword=$(echo "$gap" | grep -oP '(?<=TODO|FIXME)[^$]+' | tr -cs 'a-zA-Z' ' ' | head -c50)
|
|
338
|
+
echo "=== Gap: $keyword ===" >> ./agent-state/snipe/GAP_COVERAGE.txt
|
|
339
|
+
grep -i "$keyword" ./agent-state/snipe/TARGET_OUTLINE.jsonl \
|
|
340
|
+
>> ./agent-state/snipe/GAP_COVERAGE.txt
|
|
341
|
+
done < ./agent-state/snipe/HOME_GAP_MAP.txt
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
**Output**: Write `SNIPE_RELEVANCE_MAP.md`:
|
|
345
|
+
```markdown
|
|
346
|
+
# SNIPE_RELEVANCE_MAP.md
|
|
347
|
+
|
|
348
|
+
## Tier A — Prime Snipe Targets (score ≥ 12)
|
|
349
|
+
| TARGET Symbol | Score | Reason | HOME Counterpart | File |
|
|
350
|
+
|---|---|---|---|---|
|
|
351
|
+
| `parse_file` | 20 | Exact name match | `parse_file` | extractor.py |
|
|
352
|
+
| `LanguageSpec` | 15 | Name+type overlap | `LangConfig` | languages.py |
|
|
353
|
+
|
|
354
|
+
## Tier B — Worth Reading Signature (score 8–11)
|
|
355
|
+
| TARGET Symbol | Score | Reason | File |
|
|
356
|
+
|---|---|---|---|
|
|
357
|
+
|
|
358
|
+
## Tier C — Gap Coverage (HOME TODO resolved by TARGET)
|
|
359
|
+
| HOME Gap | TARGET Symbol | File |
|
|
360
|
+
|---|---|---|
|
|
361
|
+
|
|
362
|
+
## Discarded (score < 8)
|
|
363
|
+
Count: <n> symbols discarded. Not read. Not discussed.
|
|
364
|
+
```
|
|
365
|
+
|
|
366
|
+
---
|
|
367
|
+
|
|
368
|
+
### Phase 3 — Precision Extraction `[EXECUTION_LOG]`
|
|
369
|
+
|
|
370
|
+
**Only Tier A and Tier B symbols reach this phase.**
|
|
371
|
+
|
|
372
|
+
**Step 10 — Snipe Tier A implementations**
|
|
373
|
+
```bash
|
|
374
|
+
# For each Tier A symbol, extract full implementation via ast-grep
|
|
375
|
+
# Replace SYMBOL_NAME with actual name from SNIPE_RELEVANCE_MAP.md
|
|
376
|
+
|
|
377
|
+
# Rust function body
|
|
378
|
+
ast-grep --pattern 'fn SYMBOL_NAME($$$) { $$$ }' --lang rust
|
|
379
|
+
|
|
380
|
+
# Rust with impl context (method)
|
|
381
|
+
ast-grep --pattern 'impl $TYPE { $$$ fn SYMBOL_NAME($$$) { $$$ } $$$ }' --lang rust
|
|
382
|
+
|
|
383
|
+
# Python function body
|
|
384
|
+
ast-grep --pattern 'def SYMBOL_NAME($$$): $$$' --lang python
|
|
385
|
+
|
|
386
|
+
# TypeScript
|
|
387
|
+
ast-grep --pattern 'function SYMBOL_NAME($$$): $RET { $$$ }' --lang ts
|
|
388
|
+
ast-grep --pattern 'SYMBOL_NAME($$$): $RET { $$$ }' --lang ts # method
|
|
389
|
+
```
|
|
390
|
+
|
|
391
|
+
**Step 11 — Divergence extraction (how HOME and TARGET differ)**
|
|
392
|
+
```bash
|
|
393
|
+
# For exact-match symbols (score == 20), extract both HOME and TARGET implementations
|
|
394
|
+
# to compare approaches
|
|
395
|
+
|
|
396
|
+
# HOME implementation
|
|
397
|
+
cd <HOME_PATH>
|
|
398
|
+
ast-grep --pattern 'fn SYMBOL_NAME($$$) { $$$ }' --lang rust > /tmp/home_impl.txt
|
|
399
|
+
|
|
400
|
+
# TARGET implementation
|
|
401
|
+
cd <TARGET_PATH>
|
|
402
|
+
ast-grep --pattern 'fn SYMBOL_NAME($$$) { $$$ }' --lang rust > /tmp/target_impl.txt
|
|
403
|
+
|
|
404
|
+
# Structural diff: how many lines? How many patterns differ?
|
|
405
|
+
wc -l /tmp/home_impl.txt /tmp/target_impl.txt
|
|
406
|
+
diff /tmp/home_impl.txt /tmp/target_impl.txt | head -40
|
|
407
|
+
```
|
|
408
|
+
|
|
409
|
+
**Step 12 — Pattern sniping (recurring TARGET idioms absent from HOME)**
|
|
410
|
+
```bash
|
|
411
|
+
# Idioms seen 3+ times in TARGET but absent from HOME
|
|
412
|
+
|
|
413
|
+
# Example: if TARGET uses a registry pattern
|
|
414
|
+
ast-grep --pattern '$REGISTRY.insert($KEY, $VAL)' --lang rust # (run in TARGET)
|
|
415
|
+
ast-grep --pattern '$REGISTRY[$KEY] = $VAL' --lang python # (run in TARGET)
|
|
416
|
+
|
|
417
|
+
# Check if HOME has equivalent
|
|
418
|
+
ast-grep --pattern '$REGISTRY.insert($KEY, $VAL)' --lang rust # (run in HOME)
|
|
419
|
+
# If 0 results → this is a pattern gap
|
|
420
|
+
|
|
421
|
+
# Extract TARGET's registry pattern instances
|
|
422
|
+
ast-grep --pattern 'PATTERN' --lang rust --json | \
|
|
423
|
+
jq '.[] | {file: .file, line: .range.start.line, text: .text}' \
|
|
424
|
+
>> ./agent-state/snipe/SNIPE_EXTRACTS.jsonl
|
|
425
|
+
```
|
|
426
|
+
|
|
427
|
+
---
|
|
428
|
+
|
|
429
|
+
### Phase 4 — Artifact Generation `[ARTIFACT_UPDATE]`
|
|
430
|
+
|
|
431
|
+
All snipe findings are crystallised into locked artifacts.
|
|
432
|
+
|
|
433
|
+
**Required artifacts:**
|
|
434
|
+
|
|
435
|
+
| Artifact | Contents |
|
|
436
|
+
|---|---|
|
|
437
|
+
| `SNIPE_HOME_REGISTRY.md` | HOME symbol inventory, pattern fingerprint, gap map |
|
|
438
|
+
| `SNIPE_TARGET_OUTLINE.md` | TARGET symbol names, module structure (no implementations) |
|
|
439
|
+
| `SNIPE_RELEVANCE_MAP.md` | Scored symbol table, Tier A/B/C/Discarded |
|
|
440
|
+
| `SNIPE_EXTRACTS.jsonl` | Raw ast-grep output for Tier A/B symbols |
|
|
441
|
+
| `SNIPE_COMPARISON.md` | Final comparison: divergence, adoption cost, inspiration |
|
|
442
|
+
| `EVIDENCE_LOG.md` | All ast-grep command outputs (append-only, shared with codemunch) |
|
|
443
|
+
|
|
444
|
+
**Artifact write protocol:**
|
|
445
|
+
```bash
|
|
446
|
+
# Every snipe command appends to EVIDENCE_LOG
|
|
447
|
+
echo "## Snipe: fn parse_file (TARGET extractor.py)" >> ./agent-state/snipe/EVIDENCE_LOG.md
|
|
448
|
+
ast-grep --pattern 'def parse_file($$$):' --lang python --json \
|
|
449
|
+
>> ./agent-state/snipe/EVIDENCE_LOG.md
|
|
450
|
+
```
|
|
451
|
+
|
|
452
|
+
**Optional artifacts by intent:**
|
|
453
|
+
|
|
454
|
+
| Intent | Extra Artifact |
|
|
455
|
+
|---|---|
|
|
456
|
+
| `steal` | `ADOPTION_PLAN.md` — step-by-step integration into HOME |
|
|
457
|
+
| `compare` | `DIVERGENCE_ANALYSIS.md` — side-by-side of same-named symbols |
|
|
458
|
+
| `debug` | `BUG_TRIANGULATION.md` — TARGET's solution to HOME's bug |
|
|
459
|
+
| `integrate` | `INTERFACE_BRIDGE.md` — data schema + API contract between HOME and TARGET |
|
|
460
|
+
|
|
461
|
+
---
|
|
462
|
+
|
|
463
|
+
### Phase 5 — Synthesis `[VERIFICATION]`
|
|
464
|
+
|
|
465
|
+
Read ONLY the artifacts. Final reasoning pass over structured data, not raw code.
|
|
466
|
+
|
|
467
|
+
**Step 13 — Snipe self-verification checklist**
|
|
468
|
+
- [ ] `SNIPE_HOME_REGISTRY.md` contains ≥ 5 symbols (HOME is meaningfully mapped)
|
|
469
|
+
- [ ] `SNIPE_RELEVANCE_MAP.md` has at least 1 Tier A symbol
|
|
470
|
+
- [ ] Every Tier A symbol in `SNIPE_EXTRACTS.jsonl` has an evidence entry
|
|
471
|
+
- [ ] Tier C gap coverage attempted for all HOME TODO items
|
|
472
|
+
- [ ] Discarded symbol count is documented (proof that low-signal symbols were filtered)
|
|
473
|
+
- [ ] `SNIPE_COMPARISON.md` exists and contains a recommendation
|
|
474
|
+
|
|
475
|
+
**Step 14 — SNIPE_COMPARISON.md structure**
|
|
476
|
+
|
|
477
|
+
```markdown
|
|
478
|
+
# SNIPE_COMPARISON.md
|
|
479
|
+
|
|
480
|
+
## Executive Summary
|
|
481
|
+
HOME: <one sentence>
|
|
482
|
+
TARGET: <one sentence>
|
|
483
|
+
Overlap: <n> exact matches, <n> structural matches
|
|
484
|
+
Key Finding: <one sentence — what's the most important thing TARGET has?>
|
|
485
|
+
|
|
486
|
+
## Tier A Analysis (Direct Comparisons)
|
|
487
|
+
### `symbol_name`
|
|
488
|
+
- **HOME approach**: <2-3 sentences from HOME impl>
|
|
489
|
+
- **TARGET approach**: <2-3 sentences from TARGET impl>
|
|
490
|
+
- **Divergence**: <where/why they differ>
|
|
491
|
+
- **Recommendation**: adopt / adapt / ignore
|
|
492
|
+
|
|
493
|
+
## Tier C Gap Coverage (TARGET solves HOME TODOs)
|
|
494
|
+
| HOME Gap | TARGET Solution | Adoption Complexity |
|
|
495
|
+
|---|---|---|
|
|
496
|
+
|
|
497
|
+
## Pattern Gaps (TARGET idioms absent from HOME)
|
|
498
|
+
| Pattern | Frequency in TARGET | Adoption Note |
|
|
499
|
+
|---|---|---|
|
|
500
|
+
|
|
501
|
+
## Inspiration Extracts
|
|
502
|
+
<curated list of TARGET patterns worth considering, with ast-grep evidence refs>
|
|
503
|
+
```
|
|
504
|
+
|
|
505
|
+
**Step 15 — HANDOFF**
|
|
506
|
+
```json
|
|
507
|
+
{
|
|
508
|
+
"meta": { "timestamp": "<ISO8601>", "skill": "codesnipe", "session_id": "<uuid>" },
|
|
509
|
+
"transition": {
|
|
510
|
+
"from": "capability-research",
|
|
511
|
+
"to": "capability-spec",
|
|
512
|
+
"status": "READY_FOR_HANDOFF",
|
|
513
|
+
"reason": "Dual-codebase comparison complete. Adoption candidates identified."
|
|
514
|
+
},
|
|
515
|
+
"payload": {
|
|
516
|
+
"primary_artifact": "./agent-state/snipe/SNIPE_COMPARISON.md",
|
|
517
|
+
"home_registry": "./agent-state/snipe/SNIPE_HOME_REGISTRY.md",
|
|
518
|
+
"target_outline": "./agent-state/snipe/SNIPE_TARGET_OUTLINE.md",
|
|
519
|
+
"relevance_map": "./agent-state/snipe/SNIPE_RELEVANCE_MAP.md",
|
|
520
|
+
"evidence_pointer": "./agent-state/snipe/EVIDENCE_LOG.md",
|
|
521
|
+
"tier_a_count": "<n>",
|
|
522
|
+
"adoption_candidates": ["<symbol1>", "<symbol2>"]
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
```
|
|
526
|
+
|
|
527
|
+
---
|
|
528
|
+
|
|
529
|
+
## 4. Intent-Specific Modes
|
|
530
|
+
|
|
531
|
+
### `--intent steal`
|
|
532
|
+
Focus: Extract and integrate a specific TARGET pattern into HOME.
|
|
533
|
+
- Phase 0–1 run as normal.
|
|
534
|
+
- Phase 2: Restrict scoring to symbols related to the stated feature.
|
|
535
|
+
- Phase 3: Extract full implementation + dependencies.
|
|
536
|
+
- Phase 4+: Generate `ADOPTION_PLAN.md` with interface changes needed in HOME.
|
|
537
|
+
|
|
538
|
+
### `--intent compare`
|
|
539
|
+
Focus: Understand how TARGET solves a problem HOME also solves.
|
|
540
|
+
- Run Phase 0–3 fully.
|
|
541
|
+
- Phase 4: Generate `DIVERGENCE_ANALYSIS.md` for every Tier A symbol.
|
|
542
|
+
- Emphasis: WHY do they differ, not just HOW.
|
|
543
|
+
|
|
544
|
+
### `--intent debug`
|
|
545
|
+
Focus: HOME has a bug; TARGET may have fixed it.
|
|
546
|
+
- Phase 0: Map HOME bug site via ast-grep (find the failing pattern).
|
|
547
|
+
- Phase 1: Search TARGET for same pattern, look for fixes.
|
|
548
|
+
- Phase 2: Score TARGET fixes by structural similarity to HOME's bug site.
|
|
549
|
+
- Phase 4: Generate `BUG_TRIANGULATION.md`.
|
|
550
|
+
|
|
551
|
+
```bash
|
|
552
|
+
# Snipe a specific bug pattern in TARGET
|
|
553
|
+
# Example: HOME has panics on unwrap(), does TARGET handle this better?
|
|
554
|
+
ast-grep --pattern '$EXPR.unwrap()' --lang rust # (HOME: find all panic sites)
|
|
555
|
+
ast-grep --pattern '$EXPR.unwrap()' --lang rust # (TARGET: compare frequency)
|
|
556
|
+
ast-grep --pattern '$EXPR.unwrap_or($DEFAULT)' --lang rust # (TARGET: safer pattern?)
|
|
557
|
+
ast-grep --pattern 'match $EXPR { Ok($V) => $OK, Err($E) => $ERR }' --lang rust
|
|
558
|
+
```
|
|
559
|
+
|
|
560
|
+
### `--intent integrate`
|
|
561
|
+
Focus: HOME needs to consume or extend TARGET as a library/module.
|
|
562
|
+
- Phase 0: Map HOME's consumption points (where would TARGET connect?).
|
|
563
|
+
- Phase 1: Map TARGET's public API surface (exports, entry points only).
|
|
564
|
+
- Phase 2: Score TARGET exports against HOME consumption points.
|
|
565
|
+
- Phase 4: Generate `INTERFACE_BRIDGE.md` with schema + integration plan.
|
|
566
|
+
|
|
567
|
+
---
|
|
568
|
+
|
|
569
|
+
## 5. ast-grep Snipe Commands Reference
|
|
570
|
+
|
|
571
|
+
### Surgical Symbol Extraction (Tier A reads)
|
|
572
|
+
```bash
|
|
573
|
+
# Named function (any language variant)
|
|
574
|
+
ast-grep --pattern 'fn TARGET_FN($$$) { $$$ }' --lang rust
|
|
575
|
+
ast-grep --pattern 'def TARGET_FN($$$): $$$' --lang python
|
|
576
|
+
ast-grep --pattern 'function TARGET_FN($$$) { $$$ }' --lang ts
|
|
577
|
+
ast-grep --pattern 'TARGET_FN($$$): $RET { $$$ }' --lang ts # method
|
|
578
|
+
|
|
579
|
+
# Named type/class
|
|
580
|
+
ast-grep --pattern 'struct TARGET_TYPE { $$$ }' --lang rust
|
|
581
|
+
ast-grep --pattern 'class TARGET_CLASS: $$$' --lang python
|
|
582
|
+
ast-grep --pattern 'interface TARGET_IFACE { $$$ }' --lang ts
|
|
583
|
+
```
|
|
584
|
+
|
|
585
|
+
### Cross-Codebase Pattern Search
|
|
586
|
+
```bash
|
|
587
|
+
# Run identical patterns in both HOME and TARGET; compare match counts
|
|
588
|
+
# HOME:
|
|
589
|
+
cd <HOME_PATH> && ast-grep --pattern '$EXPR?' --lang rust --json | jq length
|
|
590
|
+
# TARGET:
|
|
591
|
+
cd <TARGET_PATH> && ast-grep --pattern '$EXPR?' --lang rust --json | jq length
|
|
592
|
+
# If TARGET has 5× more ? usage → different error philosophy
|
|
593
|
+
```
|
|
594
|
+
|
|
595
|
+
### Relevance Scoring Helpers
|
|
596
|
+
```bash
|
|
597
|
+
# Count shared symbol names between HOME and TARGET registries
|
|
598
|
+
comm -12 \
|
|
599
|
+
<(jq -r '.name' ./agent-state/snipe/HOME_REGISTRY.jsonl | sort -u) \
|
|
600
|
+
<(jq -r '.name' ./agent-state/snipe/TARGET_OUTLINE.jsonl | sort -u) \
|
|
601
|
+
| wc -l
|
|
602
|
+
|
|
603
|
+
# List all shared names
|
|
604
|
+
comm -12 \
|
|
605
|
+
<(jq -r '.name' ./agent-state/snipe/HOME_REGISTRY.jsonl | sort -u) \
|
|
606
|
+
<(jq -r '.name' ./agent-state/snipe/TARGET_OUTLINE.jsonl | sort -u)
|
|
607
|
+
```
|
|
608
|
+
|
|
609
|
+
---
|
|
610
|
+
|
|
611
|
+
## 6.1 Wrong-Stuff Protocol
|
|
612
|
+
|
|
613
|
+
When comparison reveals issues:
|
|
614
|
+
|
|
615
|
+
| Finding | Classification | Route To |
|
|
616
|
+
|---|---|---|
|
|
617
|
+
| HOME symbol contradicts its own spec | `spec_violation` | `agent-spec` |
|
|
618
|
+
| TARGET pattern reveals HOME implementation gap | `implementation_bug` | `agent-builder` |
|
|
619
|
+
| HOME registry incomplete for comparison | `invalid_source` | re-run Phase 0 |
|
|
620
|
+
| HOME documentation mismatches code structure | `documentation_drift` | `agent-docs` |
|
|
621
|
+
|
|
622
|
+
## 6.2 Anti-Patterns
|
|
623
|
+
|
|
624
|
+
| Anti-Pattern | Correct Behavior |
|
|
625
|
+
|---|---|
|
|
626
|
+
| Reading TARGET without HOME registry | Build HOME registry first (Phase 0); always |
|
|
627
|
+
| Reading symbols scoring < 8 | Discard; log to `KNOWN_UNKNOWNS` only |
|
|
628
|
+
| Comparing without intent parameter | Intent controls scoring weights; always specify |
|
|
629
|
+
| Spraying reads across all TARGET files | Snipe only scored, ranked symbols |
|
|
630
|
+
| Session ends without `SNIPE_COMPARISON.md` | Every session produces comparison artifact |
|
|
631
|
+
|
|
632
|
+
---
|
|
633
|
+
|
|
634
|
+
## 6. Failure Modes & Circuit Breakers
|
|
635
|
+
|
|
636
|
+
| Failure | Signal | Recovery |
|
|
637
|
+
|---|---|---|
|
|
638
|
+
| HOME registry empty | Gate blocks Phase 1 | Re-run Phase 0 with correct HOME path |
|
|
639
|
+
| All TARGET symbols score < 8 | Zero Tier A/B symbols | Log to DECISIONS.md: "TARGET unrelated to HOME"; abort |
|
|
640
|
+
| TARGET language ≠ HOME language | Phase 2 scoring can't use signatures | Score by name and pattern concept only; flag in SNIPE_COMPARISON.md |
|
|
641
|
+
| Target is too large (>500 files) | Outline phase takes too long | Restrict to top-level modules only; flag as `PARTIAL_SNIPE` |
|
|
642
|
+
| Intent changes mid-session | New focus discovered | Re-enter Phase 2 with updated scoring weights; do NOT re-run Phase 0 |
|
|
643
|
+
|
|
644
|
+
---
|
|
645
|
+
|
|
646
|
+
## 7. Activation
|
|
647
|
+
|
|
648
|
+
```
|
|
649
|
+
snipe --home <path> --target <path|repo> --intent <steal|compare|debug|integrate> [--lang <lang>]
|
|
650
|
+
```
|
|
651
|
+
|
|
652
|
+
**Example invocations:**
|
|
653
|
+
```bash
|
|
654
|
+
# Study how fastapi handles dependency injection vs our framework
|
|
655
|
+
snipe --home ./myapi --target fastapi/fastapi --intent compare
|
|
656
|
+
|
|
657
|
+
# Steal incremental indexing pattern from jcodemunch into our build tool
|
|
658
|
+
snipe --home ./build-tool --target ./jcodemunch-mcp --intent steal
|
|
659
|
+
|
|
660
|
+
# Find how TARGET fixed the panic we have in our parser
|
|
661
|
+
snipe --home ./myparser --target nom-rs/nom --intent debug
|
|
662
|
+
|
|
663
|
+
# Understand how to consume TARGET as a library in HOME
|
|
664
|
+
snipe --home ./myapp --target ./some-sdk --intent integrate
|
|
665
|
+
```
|
|
666
|
+
|
|
667
|
+
CodeSnipe will automatically build the HOME registry, profile TARGET at outline level,
|
|
668
|
+
score all symbols, extract only what earned it, and produce `SNIPE_COMPARISON.md`
|
|
669
|
+
with concrete adoption recommendations.
|
|
670
|
+
|
|
671
|
+
**No raw file reads. No unscored symbol access. Precision only.**
|