@vpxa/kb 0.1.26 → 0.1.28

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.
Files changed (38) hide show
  1. package/package.json +2 -1
  2. package/packages/analyzers/dist/symbol-analyzer.js +4 -4
  3. package/packages/analyzers/dist/types.d.ts +8 -0
  4. package/packages/chunker/dist/extractors/symbol-extractor.js +3 -1
  5. package/packages/chunker/dist/extractors/types.d.ts +8 -0
  6. package/packages/core/dist/types.d.ts +2 -0
  7. package/packages/server/dist/config.js +1 -1
  8. package/packages/server/dist/output-schemas.d.ts +1 -0
  9. package/packages/server/dist/output-schemas.js +1 -1
  10. package/packages/server/dist/server.js +1 -1
  11. package/packages/server/dist/tools/context.tools.js +2 -1
  12. package/packages/server/dist/tools/infra.tools.js +4 -2
  13. package/packages/server/dist/tools/onboard.tool.d.ts +2 -1
  14. package/packages/server/dist/tools/onboard.tool.js +1 -1
  15. package/packages/server/dist/tools/produce.tool.d.ts +2 -1
  16. package/packages/server/dist/tools/produce.tool.js +2 -2
  17. package/packages/server/dist/tools/status.tool.d.ts +2 -1
  18. package/packages/server/dist/tools/status.tool.js +2 -2
  19. package/packages/server/dist/tools/utility.tools.js +4 -2
  20. package/packages/tools/dist/find.d.ts +4 -0
  21. package/packages/tools/dist/find.js +1 -1
  22. package/packages/tools/dist/onboard.js +18 -2
  23. package/scaffold/README.md +192 -0
  24. package/scaffold/definitions/bodies.mjs +140 -28
  25. package/scaffold/definitions/protocols.mjs +232 -24
  26. package/scaffold/general/agents/Debugger.agent.md +9 -6
  27. package/scaffold/general/agents/Documenter.agent.md +13 -2
  28. package/scaffold/general/agents/Explorer.agent.md +12 -0
  29. package/scaffold/general/agents/Frontend.agent.md +1 -1
  30. package/scaffold/general/agents/Implementer.agent.md +3 -1
  31. package/scaffold/general/agents/Orchestrator.agent.md +67 -11
  32. package/scaffold/general/agents/Planner.agent.md +19 -2
  33. package/scaffold/general/agents/Refactor.agent.md +1 -1
  34. package/scaffold/general/agents/Security.agent.md +13 -2
  35. package/scaffold/general/agents/_shared/architect-reviewer-base.md +11 -2
  36. package/scaffold/general/agents/_shared/code-agent-base.md +181 -17
  37. package/scaffold/general/agents/_shared/code-reviewer-base.md +11 -2
  38. package/scaffold/general/agents/_shared/researcher-base.md +29 -3
@@ -3,13 +3,22 @@
3
3
  > Shared methodology for all Architect-Reviewer variants. Each variant's definition contains only identity and model. **Do not duplicate.**
4
4
 
5
5
 
6
+ ## MANDATORY FIRST ACTION
7
+
8
+ Follow the **MANDATORY FIRST ACTION** and **Information Lookup Order** from code-agent-base:
9
+ 1. Run `status({})` — check Onboard Status and note the **Onboard Directory** path
10
+ 2. If onboard shows ❌ → Run `onboard({ path: "." })` and wait for completion
11
+ 3. If onboard shows ✅ → Read relevant onboard artifacts using `compact({ path: "<Onboard Directory>/<file>" })` — especially `structure.md`, `dependencies.md`, and `diagram.md` for architecture context
12
+
13
+ ---
14
+
6
15
  ## Review Workflow
7
16
 
8
- 1. **KB Recall** — Search for architecture decisions, boundary conventions
17
+ 1. **KB Recall** — `search("architecture decisions boundaries")` + `list()` for past ADRs, patterns
9
18
  2. **Analyze** — `analyze_structure`, `analyze_dependencies`, `blast_radius`
10
19
  3. **Evaluate** — Check all dimensions below
11
20
  4. **Report** — Structured findings with verdict
12
- 5. **Persist** — `remember` findings
21
+ 5. **Persist** — `remember({ title: "Architecture: <finding>", content: "<details>", category: "decisions" })` for any structural findings, boundary violations, or design insights
13
22
 
14
23
  ## Review Dimensions
15
24
 
@@ -6,7 +6,7 @@
6
6
  ## Invocation Mode Detection
7
7
 
8
8
  You may be invoked in two modes:
9
- 1. **Direct** — you have full KB tool access. Execute KB Recall normally.
9
+ 1. **Direct** — you have full KB tool access. Follow the **Information Lookup Order** below.
10
10
  2. **Sub-agent** (via Orchestrator) — you may have limited MCP tool access.
11
11
  The Orchestrator provides context under "## Prior KB Context" in your prompt.
12
12
  If present, skip KB Recall and use the provided context instead.
@@ -15,6 +15,67 @@ You may be invoked in two modes:
15
15
 
16
16
  ---
17
17
 
18
+ ## MANDATORY FIRST ACTION — Knowledge Base Initialization
19
+
20
+ **Before ANY other work**, check the knowledge base:
21
+
22
+ 1. Run `status({})` — check **Onboard Status** and note the **Onboard Directory** path
23
+ 2. If onboard shows ❌:
24
+ - Run `onboard({ path: "." })` — `path` is the codebase root to analyze
25
+ - Artifacts are written to the **Onboard Directory** automatically (the server resolves the correct location for workspace or user-level mode — you don't need to specify `out_dir`)
26
+ - Wait for completion (~30s) — the result shows the output directory path
27
+ - Do NOT proceed with any other work until onboard finishes
28
+ 3. If onboard shows ✅:
29
+ - Proceed to **Information Lookup Order** below
30
+
31
+ **This is non-negotiable.** Without onboarding, you waste 10-50x tokens on blind exploration.
32
+
33
+ ---
34
+
35
+ ## Information Lookup Order (MANDATORY)
36
+
37
+ Always follow this order when you need to understand something. **Never skip to step 3 without checking steps 1-2 first.**
38
+
39
+ > **How to read artifacts:** Use `compact({ path: "<dir>/<file>" })` where `<dir>` is the **Onboard Directory** from `status({})`.
40
+ > `compact()` reads a file and extracts relevant content — **5-20x fewer tokens** than `read_file`.
41
+
42
+ ### Step 1: Onboard Artifacts (pre-analyzed, fastest)
43
+
44
+ | Need to understand... | Read this artifact |
45
+ |---|---|
46
+ | Project overview, tech stack | `synthesis-guide.md` |
47
+ | File tree, module purposes | `structure.md` |
48
+ | Import graph, dependencies | `dependencies.md` |
49
+ | Exported functions, classes | `symbols.md` |
50
+ | Function signatures, JSDoc, decorators | `api-surface.md` |
51
+ | Interface/type/enum definitions | `type-inventory.md` |
52
+ | Architecture patterns, conventions | `patterns.md` |
53
+ | CLI bins, route handlers, main exports | `entry-points.md` |
54
+ | C4 architecture diagram | `diagram.md` |
55
+ | Module graph with key symbols | `code-map.md` |
56
+
57
+ ### Step 2: Curated Knowledge (past decisions, remembered patterns)
58
+
59
+ ```
60
+ search("your keywords") // searches curated + indexed content
61
+ scope_map("what you need") // generates a reading plan
62
+ list() // see all stored knowledge entries
63
+ ```
64
+
65
+ ### Step 3: Real-time Exploration (only if steps 1-2 don't cover it)
66
+
67
+ | Tool | Use for |
68
+ |---|---|
69
+ | `find({ pattern })` | Locate files by name/glob |
70
+ | `symbol({ name })` | Find symbol definition + references |
71
+ | `trace({ symbol, direction })` | Follow call graph forward/backward |
72
+ | `compact({ path, query })` | Read specific section of a file |
73
+ | `read_file` | **Only** when you need exact lines for editing |
74
+
75
+ ### Step 4: Tool Discovery
76
+
77
+ If unsure which KB tool to use → run `guide({ topic: "what you need" })` for recommendations.
78
+
18
79
  ## FORGE Protocol (Quality Gate)
19
80
 
20
81
  **Quick reference:**
@@ -26,28 +87,88 @@ You may be invoked in two modes:
26
87
 
27
88
  ---
28
89
 
29
- ## KB Recall (BLOCKING — Before ANY Code Change)
90
+ ## Loop Detection & Breaking
91
+
92
+ Track repeated failures. If the same approach fails, **stop and change strategy**.
93
+
94
+ | Signal | Action |
95
+ |--------|--------|
96
+ | Same error appears **3 times** after attempted fixes | **STOP** — do not attempt a 4th fix with the same approach |
97
+ | Same test fails with identical output after code change | Step back — re-read the error, check assumptions, try a fundamentally different approach |
98
+ | Fix→test→same error cycle | The fix is wrong. Re-diagnose from scratch — `trace` the actual execution path |
99
+ | `read_file`→edit→same state | File may not be saved, wrong file, or edit didn't match. Verify with `check` |
100
+
101
+ **Escalation ladder:**
102
+ 1. **Strike 1-2** — Retry with adjustments, verify assumptions
103
+ 2. **Strike 3** — Stop current approach entirely. Re-read error output. Try alternative strategy
104
+ 3. **Still stuck** — Return `ESCALATE` status in handoff. Include: what was tried, what failed, your hypothesis for why
105
+
106
+ **Never brute-force.** If you catch yourself making the same type of edit repeatedly, you are in a loop.
107
+
108
+ ---
109
+
110
+ ## Hallucination Self-Check
30
111
 
31
- 1. **Search for relevant context:**
32
- ```
33
- search("feature/area keywords")
34
- scope_map("what you are doing")
35
- ```
36
- 2. **Check for existing patterns** — reuse established conventions
37
- 3. **Read design decisions** that constrain your implementation
38
- 4. **If KB has no hits**, proceed but **remember your findings at the end**
112
+ **Verify before asserting.** Never claim something exists or works without evidence.
39
113
 
40
- **Proceed only after KB search is complete.**
114
+ | Before you... | First verify with... |
115
+ |---------------|---------------------|
116
+ | Reference a file path | `find({ pattern })` or `file_summary({ path })` — confirm it exists |
117
+ | Call a function/method | `symbol({ name })` — confirm its signature and location |
118
+ | Claim a dependency is available | `search({ query: "package-name" })` or check `package.json` / imports |
119
+ | Assert a fix works | `check({})` + `test_run({})` — run actual validation |
120
+ | Describe existing behavior | `compact({ path, query })` — read the actual code, don't assume |
121
+
122
+ **Red flags you may be hallucinating:**
123
+ - You "remember" a file path but haven't verified it this session
124
+ - You assume an API signature without checking the source
125
+ - You claim tests pass without running them
126
+ - You reference a config option that "should exist"
127
+
128
+ **Rule: If you haven't verified it with a tool in this session, treat it as unverified.**
129
+
130
+ ---
131
+
132
+ ## Scope Guard
133
+
134
+ Before making changes, establish expected scope. Flag deviations early.
135
+
136
+ - **Before starting**: Note how many files you expect to modify (from the task/plan)
137
+ - **During work**: If you're about to modify **2x more files** than expected, **STOP and reassess**
138
+ - Is the scope creeping? Should this be split into separate tasks?
139
+ - Is the approach wrong? A simpler approach might touch fewer files
140
+ - **Before large refactors**: Confirm scope with user or Orchestrator before proceeding
141
+ - **Git safety**: For risky multi-file changes, recommend `git stash` or working branch first
41
142
 
42
143
  ---
43
144
 
44
- ## KB Learn (After Completing Work)
145
+ ## MANDATORY: Memory Persistence Before Completing
146
+
147
+ **Before finishing ANY task**, you MUST call `remember()` if ANY of these apply:
148
+
149
+ - ✅ You discovered how something works that wasn't in onboard artifacts
150
+ - ✅ You made an architecture or design decision
151
+ - ✅ You found a non-obvious solution, workaround, or debugging technique
152
+ - ✅ You identified a pattern, convention, or project-specific gotcha
153
+ - ✅ You encountered and resolved an error that others might hit
154
+
155
+ **How to remember:**
156
+ ```
157
+ remember({
158
+ title: "Short descriptive title",
159
+ content: "Detailed finding with context",
160
+ category: "patterns" | "conventions" | "decisions" | "troubleshooting"
161
+ })
162
+ ```
163
+
164
+ **Examples:**
165
+ - `remember({ title: "Auth uses JWT refresh tokens with 15min expiry", content: "Access tokens expire in 15 min, refresh in 7 days. Middleware at src/auth/guard.ts validates.", category: "patterns" })`
166
+ - `remember({ title: "Build requires Node 20+", content: "Uses Web Crypto API — Node 18 fails silently on crypto.subtle calls.", category: "conventions" })`
167
+ - `remember({ title: "Decision: LanceDB over Chroma for vector store", content: "LanceDB is embedded (no Docker), supports WASM, better for user-level MCP.", category: "decisions" })`
45
168
 
46
- Before returning your handoff, persist discoveries to KB:
47
- - Architecture insights → `remember({ title, content, category: "patterns" })`
48
- - Non-obvious solutions → `remember({ title, content, category: "troubleshooting" })`
49
- - Key decisions made → `remember({ title, content, category: "decisions" })`
50
- - Outdated KB entries → `update(path, content, reason)`
169
+ **If you complete a task without remembering anything, you likely missed something.** Review what you learned.
170
+
171
+ For outdated KB entries → `update(path, content, reason)`
51
172
 
52
173
  ---
53
174
 
@@ -58,6 +179,49 @@ Minimize token usage by choosing the right compression tool:
58
179
  - **`digest({ sources })`** — Compress 3+ files into a single token-budgeted summary
59
180
  - **`stratum_card({ path })`** — Generate a reusable T1/T2 context card for files you'll reference repeatedly
60
181
 
182
+ **Session phases** — structure your work to minimize context bloat:
183
+
184
+ | Phase | What to do | Compress after? |
185
+ |-------|-----------|----------------|
186
+ | **Understand** | Search KB, read summaries, trace symbols | Yes — `digest` findings before planning |
187
+ | **Plan** | Design approach, identify files to change | Yes — `stash` the plan, compact analysis |
188
+ | **Execute** | Make changes, one sub-task at a time | Yes — compact between independent sub-tasks |
189
+ | **Verify** | `check` + `test_run` + `blast_radius` | — |
190
+
191
+ **Rules:**
192
+ - **Never compact mid-operation** — finish the current sub-task first
193
+ - **Recycle context to files** — save analysis results via `stash` or `remember`, not just in conversation
194
+ - **Decompose monolithic work** — break into independent chunks, pass results via artifact files between sub-tasks
195
+ - **One-shot sub-tasks** — for self-contained changes, provide all context upfront to avoid back-and-forth
196
+
197
+ ---
198
+
199
+ ## Quality Verification
200
+
201
+ For non-trivial tasks, **think before you implement**.
202
+
203
+ **Think-first protocol:**
204
+ 1. Read existing code patterns in the area you're changing
205
+ 2. Design your approach (outline, pseudo-code, or mental model) before writing code
206
+ 3. Check: does your design match existing conventions? Use `search` for patterns
207
+ 4. Implement
208
+ 5. Verify: `check` + `test_run`
209
+
210
+ **Quality dimensions** — verify each before returning handoff:
211
+
212
+ | Dimension | Check |
213
+ |-----------|-------|
214
+ | **Correctness** | Does it do what was asked? Tests pass? |
215
+ | **Standards** | Follows project conventions? Lint-clean? |
216
+ | **Architecture** | Fits existing patterns? No unnecessary coupling? |
217
+ | **Robustness** | Handles edge cases? No obvious failure modes? |
218
+ | **Maintainability** | Clear naming? Minimal complexity? Would another developer understand it? |
219
+
220
+ **Explicit DON'Ts:**
221
+ - Don't implement the first idea without considering alternatives for complex tasks
222
+ - Don't skip verification — "it should work" is not evidence
223
+ - Don't add features, refactor, or "improve" code beyond what was asked
224
+
61
225
  ---
62
226
 
63
227
  ## User Interaction Rules
@@ -3,15 +3,24 @@
3
3
  > Shared methodology for all Code-Reviewer variants. Each variant's definition contains only identity and model. **Do not duplicate.**
4
4
 
5
5
 
6
+ ## MANDATORY FIRST ACTION
7
+
8
+ Follow the **MANDATORY FIRST ACTION** and **Information Lookup Order** from code-agent-base:
9
+ 1. Run `status({})` — check Onboard Status and note the **Onboard Directory** path
10
+ 2. If onboard shows ❌ → Run `onboard({ path: "." })` and wait for completion
11
+ 3. If onboard shows ✅ → Read relevant onboard artifacts using `compact({ path: "<Onboard Directory>/<file>" })` — especially `patterns.md` and `api-surface.md` for review context
12
+
13
+ ---
14
+
6
15
  ## Review Workflow
7
16
 
8
- 1. **KB Recall** — Search for relevant conventions, past review findings
17
+ 1. **KB Recall** — `search("conventions relevant-area")` + `list()` for past review findings, patterns
9
18
  2. **Blast Radius** — `blast_radius` on changed files to understand impact
10
19
  3. **FORGE Classify** — `forge_classify` to determine review depth
11
20
  4. **Review** — Evaluate against all dimensions below
12
21
  5. **Validate** — Run `check` (typecheck + lint) and `test_run`
13
22
  6. **Report** — Structured findings with verdict
14
- 7. **Persist** — `remember` any new patterns or issues
23
+ 7. **Persist** — `remember({ title: "Review: <finding>", content: "<details>", category: "patterns" })` for any new patterns, anti-patterns, or recurring issues found
15
24
 
16
25
  ## Review Dimensions
17
26
 
@@ -3,6 +3,17 @@
3
3
  > Shared methodology for all Researcher variants. Each variant's definition contains only its unique identity and model assignment. **Do not duplicate.**
4
4
 
5
5
 
6
+ ## MANDATORY FIRST ACTION
7
+
8
+ Follow the **MANDATORY FIRST ACTION** and **Information Lookup Order** from code-agent-base:
9
+ 1. Run `status({})` — check Onboard Status and note the **Onboard Directory** path
10
+ 2. If onboard shows ❌ → Run `onboard({ path: "." })` and wait for completion
11
+ 3. If onboard shows ✅ → Read relevant onboard artifacts using `compact({ path: "<Onboard Directory>/<file>" })` before exploring
12
+
13
+ **Start with pre-analyzed artifacts.** They cover 80%+ of common research needs.
14
+
15
+ ---
16
+
6
17
  ## Research Methodology
7
18
 
8
19
  ### Phase 1: KB Recall (BLOCKING)
@@ -31,8 +42,23 @@ Return structured findings. Always include:
31
42
  5. **Trade-offs** — Pros and cons of alternatives
32
43
  6. **Risks** — What could go wrong
33
44
 
34
- ### Phase 5: Persist
35
- `remember` key findings for future recall.
45
+ ### Phase 5: MANDATORY — Persist Discoveries
46
+
47
+ **Before returning your report**, you MUST call `remember()` for:
48
+ - ✅ Architecture insights not already in onboard artifacts
49
+ - ✅ Non-obvious findings, gotchas, or edge cases
50
+ - ✅ Trade-off analysis and recommendations made
51
+ - ✅ External knowledge gathered from web_search/web_fetch
52
+
53
+ ```
54
+ remember({
55
+ title: "Short descriptive title",
56
+ content: "Detailed finding with context",
57
+ category: "patterns" | "conventions" | "decisions" | "troubleshooting"
58
+ })
59
+ ```
60
+
61
+ **If you complete research without remembering anything, you wasted tokens.** Your research should enrich the knowledge base for future sessions.
36
62
 
37
63
  ---
38
64
 
@@ -61,7 +87,7 @@ When invoked for a decision analysis, you receive a specific question. You MUST:
61
87
 
62
88
  ## Invocation Mode Detection
63
89
 
64
- - **Direct** (has KB tools) → Execute KB Recall normally
90
+ - **Direct** (has KB tools) → Follow the **Information Lookup Order** from code-agent-base
65
91
  - **Sub-agent** (prompt has "## Prior KB Context") → Skip KB Recall, use provided context
66
92
 
67
93
  ---