@agentskit/doc-bridge 1.7.45 → 1.10.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.
Files changed (213) hide show
  1. package/CHANGELOG.md +488 -0
  2. package/CONTRIBUTING.md +23 -0
  3. package/README.md +87 -40
  4. package/SECURITY.md +7 -0
  5. package/action.yml +1 -1
  6. package/bin/ak-docs.js +2 -2
  7. package/bin/ak-verify.js +13 -7
  8. package/dist/cli/program.d.ts +3 -1
  9. package/dist/cli/program.js +15871 -6218
  10. package/dist/cli/program.js.map +1 -1
  11. package/dist/config/index.d.ts +1 -1
  12. package/dist/config/index.js +95 -6
  13. package/dist/config/index.js.map +1 -1
  14. package/dist/{index-BUL0q7s8.d.ts → index-7wYGbllW.d.ts} +134 -1
  15. package/dist/index.d.ts +9880 -1062
  16. package/dist/index.js +16143 -6127
  17. package/dist/index.js.map +1 -1
  18. package/docs/MARKETPLACE.md +1 -1
  19. package/docs/PRD-documentation-efficiency-study.md +406 -0
  20. package/docs/PRD-knowledge-retrieval-and-enrichment.md +466 -0
  21. package/docs/adr/0002-documentation-audit-boundary.md +22 -0
  22. package/docs/adr/0003-study-protocol-and-historical-evidence.md +40 -0
  23. package/docs/adr/0004-controlled-study-runner.md +25 -0
  24. package/docs/adr/0005-documentation-quality-and-criticality.md +20 -0
  25. package/docs/adr/0006-registry-semantic-grounding.md +20 -0
  26. package/docs/adr/0007-longitudinal-study-metrics.md +21 -0
  27. package/docs/adr/0008-study-verification-boundary.md +21 -0
  28. package/docs/adr/0009-study-provider-cli-adapter.md +25 -0
  29. package/docs/agent-corpus/INDEX.md +12 -1
  30. package/docs/agent-corpus/OVERVIEW.md +25 -0
  31. package/docs/agent-corpus/chat.md +5 -1
  32. package/docs/agent-corpus/cli.md +16 -0
  33. package/docs/agent-corpus/conformance.md +12 -0
  34. package/docs/agent-corpus/doc-bridge.md +47 -0
  35. package/docs/agent-corpus/doctor.md +8 -0
  36. package/docs/agent-corpus/gates.md +4 -0
  37. package/docs/agent-corpus/mcp.md +13 -0
  38. package/docs/agent-corpus/memory.md +4 -0
  39. package/docs/agent-corpus/query.md +33 -0
  40. package/docs/bench/README.md +122 -0
  41. package/docs/bench/retrieval-baseline-v1.json +28 -0
  42. package/docs/bench/retrieval-suite-v1.json +1033 -0
  43. package/docs/chat-and-rag.md +3 -2
  44. package/docs/for-agents.md +9 -1
  45. package/docs/getting-started.md +4 -11
  46. package/docs/guides/gate-ci.md +11 -1
  47. package/docs/guides/install-and-run.md +9 -65
  48. package/docs/index.md +22 -1
  49. package/docs/knowledge-engine-runbook.md +38 -3
  50. package/docs/landing/assets/context-payload-reduction.svg +21 -0
  51. package/docs/landing/assets/controlled-ab-comparison.svg +30 -0
  52. package/docs/landing/index.html +119 -5
  53. package/docs/loop-workflow.md +117 -0
  54. package/docs/mcp.md +6 -1
  55. package/docs/parity/public-claims-v1.json +145 -0
  56. package/docs/playbook/doc-bridge-pattern.md +1 -1
  57. package/docs/query.md +90 -2
  58. package/docs/recipes/index-pipeline.md +1 -1
  59. package/docs/schemas/agent-handoff-v1.md +15 -0
  60. package/docs/schemas/doc-bridge-index-v1.md +65 -0
  61. package/docs/spec/benchmark-v1.md +33 -1
  62. package/docs/spec/cli.md +30 -10
  63. package/docs/spec/config-v1.md +157 -8
  64. package/docs/spec/documentation-audit-v1.md +61 -0
  65. package/docs/spec/enrichment-overlay-v1.md +241 -0
  66. package/docs/spec/graph-signals-v1.md +92 -0
  67. package/docs/spec/incremental-scan-v1.md +102 -0
  68. package/docs/spec/markdown-analyzer-v1.md +73 -0
  69. package/docs/spec/mcp-knowledge-tools-v1.md +147 -0
  70. package/docs/spec/measured-enrichment-v1.md +229 -0
  71. package/docs/spec/public-parity-v1.md +119 -0
  72. package/docs/spec/registry-agents.md +6 -0
  73. package/docs/spec/render-v1.md +122 -0
  74. package/docs/spec/retrieval-index-v1.md +164 -0
  75. package/docs/spec/study-metrics-v1.md +58 -0
  76. package/docs/spec/study-protocol-v1.md +46 -0
  77. package/docs/spec/study-provider-cli-v1.md +116 -0
  78. package/docs/spec/study-runner-v1.md +35 -0
  79. package/docs/spec/study-task-suite-v1.md +41 -0
  80. package/docs/spec/study-verification-v1.md +40 -0
  81. package/docs/study/README.md +84 -0
  82. package/docs/study/ab-adjudicated-cost-analysis-v1.md +29 -0
  83. package/docs/study/ab-adjudicated-cost-plan-v1.json +33 -0
  84. package/docs/study/ab-adjudicated-cost-plan-v2-v1.json +33 -0
  85. package/docs/study/ab-adjudicated-cost-result-v1.json +80 -0
  86. package/docs/study/ab-baseline-analysis-v1.md +21 -0
  87. package/docs/study/ab-baseline-plan-v1.json +33 -0
  88. package/docs/study/ab-baseline-recovery-plan-v1.json +33 -0
  89. package/docs/study/ab-baseline-result-v1.json +79 -0
  90. package/docs/study/documentation-audit-round-2026-08-31.json +183 -0
  91. package/docs/study/historical-evidence-v1.json +252 -0
  92. package/docs/study/observation-ledger-v1.json +30632 -0
  93. package/docs/study/phase3-task-coverage-v1.json +34 -0
  94. package/docs/study/phase4-public-pilot-ledger-v1.json +1344 -0
  95. package/docs/study/phase4-public-pilot-result-v1.json +52 -0
  96. package/docs/study/phase4-public-pilot-run-plan-v1.json +26 -0
  97. package/docs/study/phase4-public-pilot-task-suite-v1.json +71 -0
  98. package/docs/study/pilot-round-2026-08-31.json +46 -0
  99. package/docs/study/protocol-v1.json +90 -0
  100. package/docs/study/publication-gate-v1.md +45 -0
  101. package/docs/study/quality-scorecard-cycle-plan.md +545 -0
  102. package/docs/study/quality-scorecard-v1.json +38 -0
  103. package/docs/study/round-1-adjudicated-smoke-v1.json +30642 -0
  104. package/docs/study/round-1-instrumentation-plan-v1.md +39 -0
  105. package/docs/study/round-2-expanded-adjudication-v1.json +91 -0
  106. package/docs/study/round-2-expanded-validation-v1.md +58 -0
  107. package/docs/study/round-3-evidence-contract-v1.json +75 -0
  108. package/docs/study/round-3-evidence-contract-v1.md +57 -0
  109. package/docs/study/round-4-confirmation-v1.json +75 -0
  110. package/docs/study/round-4-confirmation-v1.md +55 -0
  111. package/docs/study/run-plan-v1.json +33 -0
  112. package/docs/study/semantic-adjudication-cycle-8.md +20 -0
  113. package/docs/study/task-suite-v1.json +96 -0
  114. package/docs/study/token-efficiency-plan-v1.md +337 -0
  115. package/docs/study/token-efficiency-protocol-v2.json +62 -0
  116. package/docs/study/verification-binding-v1.json +27 -0
  117. package/docs/validation-cycle-plan.md +14 -0
  118. package/docs/verification-harness.md +11 -6
  119. package/ecosystem-claims.json +2 -2
  120. package/ecosystem-upstream.json +2 -2
  121. package/ecosystem.json +4 -4
  122. package/mcpb/manifest.json +9 -1
  123. package/package.json +34 -15
  124. package/scripts/check-ecosystem-upstream.mjs +34 -6
  125. package/skills/doc-bridge-handoff/fixtures/synthetic-repo/docs/for-agents/packages/payments.md +7 -0
  126. package/skills/doc-bridge-handoff/scripts/resolve-handoff.mjs +1 -1
  127. package/src/agents/registry-adapter.ts +192 -24
  128. package/src/audit/documentation.ts +513 -0
  129. package/src/bench/baseline.ts +198 -0
  130. package/src/bench/overlay-delta.ts +139 -0
  131. package/src/bench/retrieval.ts +319 -0
  132. package/src/budget/compile.ts +91 -0
  133. package/src/budget/sections.ts +70 -0
  134. package/src/cli/program.ts +684 -74
  135. package/src/cli/usage.ts +71 -0
  136. package/src/config/defaults.ts +1 -0
  137. package/src/config/index.ts +4 -0
  138. package/src/config/schema.ts +126 -2
  139. package/src/conformance/documentation-standard-v1.ts +8 -6
  140. package/src/discovery/areas.ts +197 -0
  141. package/src/discovery/documentation.ts +211 -5
  142. package/src/discovery/identity.ts +24 -0
  143. package/src/discovery/incremental.ts +314 -0
  144. package/src/discovery/inputs.ts +110 -0
  145. package/src/discovery/markdown.ts +481 -0
  146. package/src/discovery/repository.ts +485 -101
  147. package/src/doctor/run-doctor.ts +244 -12
  148. package/src/enrich/approvals.ts +190 -0
  149. package/src/enrich/cache.ts +93 -0
  150. package/src/enrich/context-pack.ts +272 -0
  151. package/src/enrich/overlay.ts +255 -0
  152. package/src/enrich/review.ts +106 -0
  153. package/src/enrich/stage.ts +374 -0
  154. package/src/enrich/stats.ts +100 -0
  155. package/src/enrich/validate.ts +410 -0
  156. package/src/federation/llms.ts +2 -4
  157. package/src/findings/report.ts +103 -0
  158. package/src/graph/build.ts +356 -0
  159. package/src/graph/memory.ts +208 -0
  160. package/src/index-builder/build-handoffs.ts +22 -11
  161. package/src/index-builder/build-index.ts +132 -3
  162. package/src/index-builder/llms-txt.ts +48 -8
  163. package/src/index-builder/project-corpus.ts +111 -0
  164. package/src/index.ts +630 -2
  165. package/src/lib/fuzzy-match.ts +235 -0
  166. package/src/mcp/knowledge.ts +554 -0
  167. package/src/mcp/server.ts +113 -18
  168. package/src/metrics/benchmark.ts +21 -0
  169. package/src/parity/check.ts +309 -0
  170. package/src/parity/claims.ts +259 -0
  171. package/src/parity/resolve.ts +160 -0
  172. package/src/query/handoff.ts +326 -0
  173. package/src/query/load-index.ts +53 -1
  174. package/src/query/query.ts +92 -59
  175. package/src/query/search.ts +289 -92
  176. package/src/query/text.ts +155 -0
  177. package/src/reconciliation/reconcile.ts +101 -10
  178. package/src/render/data.ts +356 -0
  179. package/src/render/engine.ts +398 -0
  180. package/src/render/generated.ts +77 -0
  181. package/src/render/render.ts +209 -0
  182. package/src/render/template-source.ts +52 -0
  183. package/src/render/templates.ts +289 -0
  184. package/src/report/html.ts +2 -2
  185. package/src/retrieval/bm25.ts +161 -0
  186. package/src/retrieval/project.ts +495 -0
  187. package/src/retrieval/rank.ts +383 -0
  188. package/src/retrieval/weights.ts +39 -0
  189. package/src/retriever/doc-bridge-retriever.ts +100 -15
  190. package/src/rules/engine.ts +30 -10
  191. package/src/schemas/agent-handoff.ts +56 -0
  192. package/src/schemas/budget.ts +37 -0
  193. package/src/schemas/doc-bridge-index.ts +53 -2
  194. package/src/schemas/enrichment.ts +369 -0
  195. package/src/schemas/json-schemas.ts +39 -2
  196. package/src/schemas/knowledge.ts +14 -1
  197. package/src/schemas/retrieval-index.ts +152 -0
  198. package/src/shims/graphology.d.ts +91 -0
  199. package/src/study/adjudication.ts +196 -0
  200. package/src/study/execution.ts +350 -0
  201. package/src/study/expectations.ts +219 -0
  202. package/src/study/metrics.ts +467 -0
  203. package/src/study/protocol.ts +271 -0
  204. package/src/study/provider-cli.ts +115 -0
  205. package/src/study/provider-telemetry.ts +47 -0
  206. package/src/study/quality-scorecard.ts +164 -0
  207. package/src/study/runner.ts +461 -0
  208. package/src/study/task-suite.ts +321 -0
  209. package/src/study/verification.ts +134 -0
  210. package/src/validate.ts +1 -4
  211. package/src/version.ts +1 -1
  212. package/src/workflow/engine.ts +36 -11
  213. package/scripts/verification-harness.mjs +0 -482
@@ -0,0 +1,117 @@
1
+ ---
2
+ title: Keep-pushing loop for the knowledge-retrieval workstreams
3
+ description: How the @agentskit/harness loop and Orca develop the KR-01…KR-11 workstreams one at a time, and what a human still has to do.
4
+ ---
5
+
6
+ # Keep-pushing loop for the knowledge-retrieval workstreams
7
+
8
+ `ak-harness loop` drains one person's Linear queue through Orca worktrees: it freezes an orchestrator contract per issue, opens a worker terminal in a fresh worktree, then drives the resulting pull request through checks, adversarial review and squash merge. This repository ships [`loop.config.example.yaml`](../loop.config.example.yaml) with every project-specific value already tuned.
9
+
10
+ **The real `loop.config.yaml` is gitignored.** Its `linear` block names a workspace, a team and a person by id, and this repository is public, so the working config stays local:
11
+
12
+ ```bash
13
+ cp loop.config.example.yaml loop.config.yaml
14
+ ak-harness loop install -f loop.config.yaml # fills the identity block interactively
15
+ ```
16
+
17
+ `loop install` lists the Linear team members through Orca and asks whose queue this machine drains, so the identifiers never have to be typed by hand or pasted into a commit.
18
+
19
+ Two facts decide how everything below is laid out:
20
+
21
+ - **The queue is Linear, not GitHub.** GitHub is where a pull request is reviewed and merged, and `github.intakeLabel` (`loop:review`) lets a human ask the loop to review a pull request it never dispatched. It is not a work queue.
22
+ - **The loop runs on a machine with Orca**, not in CI and not in an ephemeral container. `orca.runtime` is a blocking doctor check.
23
+
24
+ So the eleven workstreams live in two places on purpose: the GitHub sub-issues of [#169](https://github.com/AgentsKit-io/doc-bridge/issues/169) are the **specification**, and the Linear issues are the **queue item** the orchestrator actually reads. Each Linear issue carries the scope, the acceptance checklist, the verify command and a "do not" section, and links back to its GitHub spec.
25
+
26
+ ## Workstream map
27
+
28
+ | Workstream | Linear | GitHub spec | Start state | Blocked by |
29
+ | --- | --- | --- | --- | --- |
30
+ | KR-07 Retrieval benchmark and CI gate | AGE-1660 | [#176](https://github.com/AgentsKit-io/doc-bridge/issues/176) | Todo, Urgent | — |
31
+ | KR-01 Lexical ranking and full corpus | AGE-1661 | [#170](https://github.com/AgentsKit-io/doc-bridge/issues/170) | Todo, High | — |
32
+ | KR-02 Markdown analyzer on remark | AGE-1662 | [#171](https://github.com/AgentsKit-io/doc-bridge/issues/171) | Todo, High | — |
33
+ | KR-03 Code areas and area scope | AGE-1663 | [#172](https://github.com/AgentsKit-io/doc-bridge/issues/172) | Todo, High | — |
34
+ | KR-05 Per-entity hashes, incremental scan | AGE-1664 | [#174](https://github.com/AgentsKit-io/doc-bridge/issues/174) | Todo, High | — |
35
+ | KR-04 Graph layer on graphology | AGE-1665 | [#173](https://github.com/AgentsKit-io/doc-bridge/issues/173) | Backlog | KR-02, KR-03 |
36
+ | KR-06 Retrieval projection and ranking | AGE-1666 | [#175](https://github.com/AgentsKit-io/doc-bridge/issues/175) | Backlog | KR-01…KR-05 |
37
+ | KR-08 Budgeted MCP tools, measured doctor | AGE-1667 | [#177](https://github.com/AgentsKit-io/doc-bridge/issues/177) | Backlog | KR-06, KR-07 |
38
+ | KR-09 Markdown renderings on knap | AGE-1668 | [#178](https://github.com/AgentsKit-io/doc-bridge/issues/178) | Backlog | KR-03, KR-05, KR-06 |
39
+ | KR-10 Enrichment overlay | AGE-1669 | [#179](https://github.com/AgentsKit-io/doc-bridge/issues/179) | Backlog | KR-04, KR-05, KR-06 |
40
+ | KR-11 Overlay stats, assisted study arm | AGE-1670 | [#180](https://github.com/AgentsKit-io/doc-bridge/issues/180) | Backlog | KR-07, KR-10 |
41
+
42
+ ## One workstream at a time
43
+
44
+ Two mechanisms, both deliberate:
45
+
46
+ 1. **`machine.ceiling: 1`.** The loop admits at most one worker regardless of how many CPUs or how much RAM the machine has. Six of the eleven workstreams extend a contract an earlier one defines (the retrieval projection, the ranking formula, the proposal schema), so two concurrent workers would write conflicting schemas.
47
+ 2. **Dependency gating through Linear state.** `linear.states: [Todo, Ready]` is the dispatchable set. A blocked workstream sits in **Backlog**, which the loop never reads, and carries a `blockedBy` relation so the reason is visible in Linear. Priority orders the five that are dispatchable today.
48
+
49
+ **Promoting a workstream** when its dependencies have merged: move it from Backlog to Todo in Linear. Nothing else is needed; the next tick picks it up. Never promote a workstream whose `blockedBy` issues are not yet Done: its contract would be frozen against code that does not exist.
50
+
51
+ ## Prerequisites on the operating machine
52
+
53
+ None of these live in this repository, and the loop doctor blocks on the first two.
54
+
55
+ | Requirement | Why | Check |
56
+ | --- | --- | --- |
57
+ | Orca runtime at or above 1.4.200 | worktrees, terminals, Linear access, scheduling | `orca --version`, `orca status --json` |
58
+ | `ak-harness` resolvable in Orca's environment | the scheduled automations invoke it | `npm i -g @agentskit/harness` |
59
+ | `agentskit-review` on PATH | the deliver stage reviews every green head before merge | `agentskit-review --help` |
60
+ | `gh` authenticated | pull request status and the merge call | `gh auth status` |
61
+ | At least one provider CLI logged in | orchestrator, builder, reviewer and watcher roles | `claude`, `codex`, `grok` or `opencode` |
62
+ | A built Doc Bridge index in the main checkout | deterministic context for the orchestrator | `node bin/ak-docs.js index` |
63
+
64
+ `orca.bin` is set to `orca`. **On Linux outside an Orca terminal, change it to `orca-ide`**: bare `orca` is the GNOME screen reader and the doctor will report that it did not answer `--version`.
65
+
66
+ The Doc Bridge index is gitignored, so a fresh clone has none until `ak-docs index` runs. `contract.docBridgeMaxAgeHours` (168) warns when it goes stale, and `contract.requireDocBridge` is `false`, so a missing index degrades context rather than blocking a dispatch. That default is deliberate for these workstreams: their whole point is that Doc Bridge retrieval is currently weak. Revisit it once KR-01 and KR-06 have merged.
67
+
68
+ ## First run
69
+
70
+ ```bash
71
+ # from the main checkout
72
+ cp loop.config.example.yaml loop.config.yaml # then fill in the linear: identity block
73
+ node bin/ak-docs.js index # deterministic context for the orchestrator
74
+ ak-harness loop validate -f loop.config.yaml # schema + effective config + hash
75
+ ak-harness loop doctor -f loop.config.yaml --json # readiness; exit 1 on a blocking check
76
+ ak-harness loop tick --dry-run --max 1 # plan one dispatch, print the orca argv, write nothing
77
+ ```
78
+
79
+ `loop install` is the guided path: it offers to create the gitignored `loop.config.local.yaml` overlay, runs the doctor and the automation-environment checks, offers a dry-run rehearsal, and only then creates the two Orca automations (`loop-docbridge-tick` and `loop-docbridge-deliver`). Both run under `schedule.runner: precheck`, so the stage *is* the precheck command: Orca records each run as `skipped_precheck` with the report in its output and never opens an agent session.
80
+
81
+ ```bash
82
+ ak-harness loop install -f loop.config.yaml # guided; --dry-run to see the plan only
83
+ ak-harness loop status # what Orca knows: enabled, trigger, last run
84
+ ```
85
+
86
+ ## Daily operation
87
+
88
+ ```bash
89
+ ak-harness loop debrief # in flight, held, escalated, cooldowns — reads local state only
90
+ ak-harness loop watch --issue AGE-1661 # DONE | FAILED | ACTION_REQUIRED | PROGRESS
91
+ ak-harness loop paused # workstreams auto-paused after repeated failures
92
+ ak-harness loop resume AGE-1661 # clear a pause, or remove the loop:paused label in Linear
93
+ ak-harness loop retro --since 7d # digest plus one knob to turn in loop.config.yaml
94
+ ```
95
+
96
+ `loop debrief` touches neither Orca nor `gh`, so it is safe from a session hook or a chat agent that needs context before acting.
97
+
98
+ ## What a human still decides
99
+
100
+ - **Promoting a blocked workstream** out of Backlog. The loop never reorders its own queue.
101
+ - **Anything touching `delivery.selfEditPaths`.** A pull request that edits `loop.config.yaml`, `.github/**`, `.codex/verification.json` or the PRD is held with a comment and never auto-merged, even with a clean review.
102
+ - **A workstream that exhausts `maxFixRounds` (2).** It is labelled `blocked`, commented, returned to Todo, and its worktree and pull request are kept for inspection.
103
+ - **A `needs-info` escalation.** The orchestrator could not freeze a contract with at least one executable outcome and no blocking ambiguity, so it commented instead of consuming a slot. Usually the Linear description needs a decision a human owns.
104
+ - **Review findings the loop cannot resolve.** `delivery.review.minSeverity: med` is the floor that blocks auto-merge.
105
+
106
+ ## Configuration notes specific to this repository
107
+
108
+ | Setting | Value | Why |
109
+ | --- | --- | --- |
110
+ | `delivery.verifyCommand` | `pnpm typecheck && pnpm test` | doc-bridge has no `lint` script; this is what CI enforces on `master` |
111
+ | `project.setup.command` | `pnpm install --frozen-lockfile` | a fresh Orca worktree has no `node_modules`; without it every dispatch loses its first minutes |
112
+ | `contract.briefScopes` | `[agent-corpus]` | `corpus.agent.root` is `docs/agent-corpus`, the only surface in the index, so it is the only scope worth listing in a brief |
113
+ | `brief.skills` | `CONTRIBUTING.md`, `docs/for-agents.md`, `docs/agent-corpus/OVERVIEW.md`, `docs/skills/doc-bridge.md` | pinned verbatim and hashed into `dispatch.json`; a missing path fails the dispatch rather than sending a worker without promised guidance. This repository has no root `AGENTS.md`, so the routing convention comes from the corpus overview |
114
+ | `models.effort.builder` | `high` | these workstreams are contract-heavy (schema compatibility, hashing, determinism); a wrong contract costs a full fix round |
115
+ | `memory.enabled` | `false` | no approved learnings exist yet; enable after the first `loop retro` promotes some |
116
+
117
+ `loop.config.yaml`, `loop.config.local.yaml` and `.codex/loop/` are all gitignored: the first identifies a Linear workspace and person, the second is machine-specific (queue owner, RAM reserve, worker ceiling), and the third is runtime state (ledger, contracts, cooldowns, `events.ndjson`). Only `loop.config.example.yaml` is tracked, so a change to the tuned settings is reviewable without publishing anyone's identifiers. When you change a tuned setting locally, mirror it into the example file; a pull request touching either is held by `delivery.selfEditPaths` and never auto-merged.
package/docs/mcp.md CHANGED
@@ -61,12 +61,17 @@ The stdio server accepts the newline-delimited JSON transport used by current MC
61
61
  | Tool | Purpose |
62
62
  |------|---------|
63
63
  | `handoff.resolve` | Package/ownership → AgentHandoff |
64
- | `doc.search` | Deterministic index search |
64
+ | `doc.search` | Deterministic index search; set `agent: true` with `mode` and `contextBudgetTokens` for bounded agent context |
65
65
  | `doc.get` | Read an indexed agent doc |
66
66
  | `gate.status` | Freshness / configured gates |
67
67
  | `retriever.query` | Local retriever chunks |
68
68
  | `memory.classify` / `memory.promoteDraft` | Memory pipeline |
69
69
  | `registry.topology` | Static curator and delegate topology |
70
+ | `knowledge.search` | Ranked entries for a query, by kind, explained, within a `budgetTokens` |
71
+ | `knowledge.lookup` | One entity with neighbours, documents, handoff, open diagnostics and evidence, within a `budgetTokens` |
72
+ | `docbridge.diagnostics { format: 'finding' }` | Diagnostics as ecosystem `Finding`s |
73
+
74
+ Budgets, the drop order and the lookup shape are specified in [MCP knowledge tools v1](./spec/mcp-knowledge-tools-v1.md).
70
75
 
71
76
  Every tool is annotated read-only. None of these MCP calls writes project files or publishes a memory promotion.
72
77
 
@@ -0,0 +1,145 @@
1
+ {
2
+ "type": "public-claims",
3
+ "schemaVersion": 1,
4
+ "registryVersion": "v1",
5
+ "claims": [
6
+ {
7
+ "claimId": "study-token-reduction",
8
+ "statement": "The published A/B round measured fewer paired provider token-equivalent units for the deterministic arm",
9
+ "owner": "platform",
10
+ "valueType": "percent",
11
+ "template": "{value}% fewer paired provider token-equivalent units",
12
+ "evidence": {
13
+ "kind": "artifact-field",
14
+ "path": "docs/study/ab-adjudicated-cost-result-v1.json",
15
+ "field": "pairedDeltas.providerTokenCostUnitsRelative",
16
+ "transform": "negative-percent-2dp"
17
+ },
18
+ "required": [
19
+ "README.md",
20
+ "docs/study/README.md"
21
+ ],
22
+ "severity": "error",
23
+ "remediation": "Restate the figure from pairedDeltas.providerTokenCostUnitsRelative in the published A/B result, on every surface that quotes it."
24
+ },
25
+ {
26
+ "claimId": "study-token-pairs",
27
+ "statement": "The token comparison rests on the token-complete pairs the round recorded",
28
+ "owner": "platform",
29
+ "valueType": "number",
30
+ "template": "across {value} token-complete pairs",
31
+ "evidence": {
32
+ "kind": "artifact-field",
33
+ "path": "docs/study/ab-adjudicated-cost-result-v1.json",
34
+ "field": "pairedDeltas.providerTokenPairCount"
35
+ },
36
+ "required": [
37
+ "README.md",
38
+ "docs/study/README.md"
39
+ ],
40
+ "severity": "error",
41
+ "remediation": "Restate the pair count from pairedDeltas.providerTokenPairCount; a denominator that drifts makes the percentage unreadable."
42
+ },
43
+ {
44
+ "claimId": "study-completion-bridge",
45
+ "statement": "Operational completion in the deterministic Doc Bridge arm",
46
+ "owner": "platform",
47
+ "valueType": "percent",
48
+ "template": "{value}% operationally completed executions",
49
+ "evidence": {
50
+ "kind": "artifact-field",
51
+ "path": "docs/study/ab-adjudicated-cost-result-v1.json",
52
+ "field": "arms.1.completedRate",
53
+ "transform": "percent-1dp"
54
+ },
55
+ "templates": {
56
+ "docs/study/README.md": "Operational completion was {value}% versus"
57
+ },
58
+ "required": [
59
+ "README.md",
60
+ "docs/study/README.md"
61
+ ],
62
+ "severity": "error",
63
+ "remediation": "Restate the completion rate from arms[1].completedRate in the published A/B result."
64
+ },
65
+ {
66
+ "claimId": "study-completion-baseline",
67
+ "statement": "Operational completion in the repository-only arm",
68
+ "owner": "platform",
69
+ "valueType": "percent",
70
+ "template": "operationally completed executions vs. {value}%",
71
+ "evidence": {
72
+ "kind": "artifact-field",
73
+ "path": "docs/study/ab-adjudicated-cost-result-v1.json",
74
+ "field": "arms.0.completedRate",
75
+ "transform": "percent-1dp"
76
+ },
77
+ "templates": {
78
+ "docs/study/README.md": "versus {value}%"
79
+ },
80
+ "required": [
81
+ "README.md",
82
+ "docs/study/README.md"
83
+ ],
84
+ "severity": "error",
85
+ "remediation": "Restate the baseline completion rate from arms[0].completedRate; a comparison needs both arms."
86
+ },
87
+ {
88
+ "claimId": "study-latency-p95",
89
+ "statement": "The P95 latency difference the round measured",
90
+ "owner": "platform",
91
+ "valueType": "number",
92
+ "template": "{value} seconds lower P95 latency",
93
+ "evidence": {
94
+ "kind": "artifact-field",
95
+ "path": "docs/study/ab-adjudicated-cost-result-v1.json",
96
+ "field": "pairedDeltas.latencyP95Ms",
97
+ "transform": "negative-seconds-2dp"
98
+ },
99
+ "required": [
100
+ "docs/study/README.md"
101
+ ],
102
+ "optional": [
103
+ "README.md"
104
+ ],
105
+ "severity": "error",
106
+ "remediation": "Restate the P95 difference from pairedDeltas.latencyP95Ms, in seconds, and drop the word \"lower\" if the sign ever turns."
107
+ },
108
+ {
109
+ "claimId": "study-executions",
110
+ "statement": "The size of the published controlled round",
111
+ "owner": "platform",
112
+ "valueType": "number",
113
+ "template": "controlled A/B study with {value} executions",
114
+ "evidence": {
115
+ "kind": "artifact-sum",
116
+ "path": "docs/study/ab-adjudicated-cost-result-v1.json",
117
+ "arrayField": "arms",
118
+ "field": "observationCount"
119
+ },
120
+ "required": [
121
+ "docs/study/README.md"
122
+ ],
123
+ "severity": "warn",
124
+ "remediation": "Restate the execution count as the sum of both arms' observationCount in the published A/B result."
125
+ },
126
+ {
127
+ "claimId": "cli-parity-command",
128
+ "statement": "The CLI offers the parity gate this registry drives",
129
+ "owner": "platform",
130
+ "valueType": "text",
131
+ "evidence": {
132
+ "kind": "cli-command",
133
+ "command": "ak-docs parity"
134
+ },
135
+ "required": [
136
+ "docs/spec/cli.md"
137
+ ],
138
+ "severity": "error",
139
+ "remediation": "Document `ak-docs parity` in the CLI reference, or remove the command."
140
+ }
141
+ ],
142
+ "exceptions": [],
143
+ "contentHash": "e188a7b2776a3c7c495016b462fd2c053faec9d29d0b824b607458b922fbd118",
144
+ "contentHashAlgo": "sha256-normalized-v1"
145
+ }
@@ -77,7 +77,7 @@ Agents call `handoff.resolve` before editing `packages/*`:
77
77
  ## CI gate
78
78
 
79
79
  ```yaml
80
- - uses: AgentsKit-io/doc-bridge@v1.4.0
80
+ - uses: AgentsKit-io/doc-bridge@ee756a13c006c597445c31e2643c1e8cece715d7 # v1.7.45
81
81
  ```
82
82
 
83
83
  Or: `ak-docs index && ak-docs gate run` — stale index fails the PR.
package/docs/query.md CHANGED
@@ -5,7 +5,7 @@ description: Deterministic ownership and documentation lookup — no model, no r
5
5
 
6
6
  # Query
7
7
 
8
- The query layer reads `.doc-bridge/index.json` only. It does **not** re-scan the repository and does **not** call a model.
8
+ The query layer reads `.doc-bridge/index.json` and performs a deterministic freshness check against the current repository inputs. It does **not** call a model. CLI and MCP query surfaces reject stale indexes before returning results; when it is stale, run `ak-docs index` first.
9
9
 
10
10
  ## Commands
11
11
 
@@ -32,9 +32,96 @@ An **AgentHandoff** (v1) with stable fields:
32
32
  | `editRoots` | Allowed write paths |
33
33
  | `checks` | Verification commands |
34
34
  | `humanDoc` | Parallel human documentation |
35
+ | `related` | The areas this unit's code depends on and that depend on it, with the import that proves each |
36
+ | `explain` | Which relation produced each field |
37
+
38
+ A handoff answers for a package, an area, a module or a document — by ownership id, entity id,
39
+ alias or path (`ak-docs query ownership src/query --agent` works). `startHere` is the document that
40
+ covers the target, then one that mentions it, then one linking to those; `checks` report their
41
+ origin in `metadata.checksSource`. See [Retrieval index v1](./spec/retrieval-index-v1.md#handoffs-for-any-entity).
35
42
 
36
43
  Schema: [AgentHandoff v1](./schemas/agent-handoff-v1.md) · Index: [DocBridgeIndex v1](./schemas/doc-bridge-index-v1.md)
37
44
 
45
+ `ak-docs search <term> --agent` returns a bounded **AgentSearch** payload. The
46
+ default discovery mode keeps up to eight matches; task-specific modes reduce
47
+ that ceiling further:
48
+
49
+ ```bash
50
+ ak-docs search "authentication" --agent --mode=editing --context-budget=128
51
+ ```
52
+
53
+ Supported modes are `discovery`, `editing`, `debugging`, and `documentation`.
54
+ `context-budget` is measured in estimated tokens for the selected matches and
55
+ next commands. Summaries and follow-up commands are removed before matches are
56
+ dropped. If even the minimum grounded result does not fit, the command fails
57
+ closed instead of exceeding the budget. The response telemetry reports
58
+ `contextBudgetTokens`, `mode`, and `truncated` so a benchmark can distinguish
59
+ an intentionally bounded result from a complete result.
60
+
61
+ Agent searches default to a compact 32-token budget. Increase it explicitly
62
+ when the task requires additional alternatives or follow-up commands.
63
+
64
+ The agent shape omits ranking scores because they are diagnostic, not routing
65
+ instructions. `telemetry.contextBytes` and `telemetry.estimatedTokens` measure
66
+ only the selected context fields; `tokenMethod: "estimate"` is explicit and
67
+ must not be reported as provider usage.
68
+
69
+ Natural-language discovery is deterministic as well: terms such as `find package`
70
+ can resolve a declared intent route, while change-oriented queries such as
71
+ `change zod schema` can resolve a declared change route. When one of these
72
+ routes is the best match, the agent payload is focused on up to three routes of
73
+ that type and provides the corresponding follow-up command. A change route is
74
+ demoted when the query expresses no change intent, so it stays reachable when
75
+ nothing better matches without crowding an ordinary question.
76
+
77
+ ## How results are ranked
78
+
79
+ Ranking is deterministic — no model, no embeddings — and reads the
80
+ [retrieval projection](./spec/retrieval-index-v1.md) of the snapshot: every document, module,
81
+ area and package discovery observed, plus the routes the configuration declares. Each result carries
82
+ evidence, provenance and a confidence.
83
+
84
+ **Evidence** is field-weighted BM25 over each entry's title, headings, exported symbols, path,
85
+ aliases, summary and body. BM25 is what makes a term appearing in nearly every document worth almost
86
+ nothing, and a term in a short title worth more than the same term buried in a long body. Weights
87
+ and parameters are [configuration](./spec/config-v1.md#retrieval-optional), recorded in the index
88
+ so a retuned ranking is a visibly different artifact.
89
+
90
+ **Identity** boosts a record the query names rather than describes: an exact id or alias, an exact
91
+ file path, a directory, or an exported symbol. This is why `reconcileKnowledge` resolves to the
92
+ module that exports it and `src/mcp/server.ts` resolves to that file, instead of to whichever
93
+ document mentions them most often.
94
+
95
+ **Graph** signals come from the snapshot's relations: proximity to what the query clearly found,
96
+ and canonicality — the page other pages point at outranks the leaf that mentions the same thing.
97
+
98
+ **Priors** nudge toward the kind of record the query shape asks for — an ownership route for a
99
+ routing question, a module for a symbol or path, a document for a sentence. They multiply the
100
+ evidence rather than adding to it, so a favoured record still needs a real match: a prior can
101
+ never invent an answer, only order the ones that exist.
102
+
103
+ Results below a third of the best score are dropped. Retrieval exists to spend fewer tokens, and
104
+ a list of weak matches spends them for nothing.
105
+
106
+ `ak-docs search <term> --explain` names every scoring component with its contribution and the
107
+ terms that matched in each field, so a wrong ranking is reportable as a bug rather than argued as
108
+ an opinion. Explaining never changes the ranking.
109
+
110
+ ### What the lexicon does
111
+
112
+ Queries and indexed text go through one tokenizer, so a term can never be present on one side and
113
+ absent on the other:
114
+
115
+ - English and Portuguese stopwords are dropped, which is why `search and` returns nothing at all
116
+ - `reconcileKnowledge` also indexes `reconcile` and `knowledge`; `src/mcp/server.ts` also indexes
117
+ its segments
118
+ - accents fold, so `reconciliação` and `reconciliacao` are the same term
119
+ - plurals collapse, so `schema` finds `schemas`
120
+ - CJK text, which has no spaces, is indexed by character and character bigram
121
+
122
+ The lexicon's version is recorded in `index.retrieval.lexiconVersion` and is part of the index
123
+ content hash, so changing it is a new artifact rather than a silent change of behaviour.
124
+
38
125
  ## When to use which surface
39
126
 
40
127
  | Need | Surface |
@@ -48,10 +135,11 @@ Schema: [AgentHandoff v1](./schemas/agent-handoff-v1.md) · Index: [DocBridgeInd
48
135
 
49
136
  - Same inputs → same handoff JSON (deterministic)
50
137
  - Breaking field meaning requires a **new schema version**, not silent reinterpretation of v1
51
- - Gate/CI can require a fresh index so agents never see stale ownership
138
+ - Query surfaces and Gate/CI require a fresh index so agents never receive stale ownership
52
139
 
53
140
  ## Related
54
141
 
142
+ - [Retrieval benchmark](./bench/README.md) — what "the right result" measures, and the gate
55
143
  - [Guide: Index and query](./guides/index-and-query.md)
56
144
  - [For agents](./for-agents.md)
57
145
  - [CLI reference](./spec/cli.md)
@@ -71,7 +71,7 @@ Root `package.json`:
71
71
  ## CI (GitHub Action)
72
72
 
73
73
  ```yaml
74
- - uses: AgentsKit-io/doc-bridge@v1.4.0
74
+ - uses: AgentsKit-io/doc-bridge@ee756a13c006c597445c31e2643c1e8cece715d7 # v1.7.45
75
75
  ```
76
76
 
77
77
  Or manual:
@@ -26,6 +26,21 @@ Portable JSON Schema export: `AgentHandoffV1JsonSchema`.
26
26
  }
27
27
  ```
28
28
 
29
+ ## Optional additions
30
+
31
+ `related`, `explain`, `evidence` and `metadata` are optional, and `target.type` also accepts `area`
32
+ and `document`. A handoff written without them is still a valid handoff, and a reader that predates
33
+ them sees the same fields it always did.
34
+
35
+ ```json
36
+ {
37
+ "related": [{ "id": "area:src/ranking", "path": "src/ranking", "direction": "imports", "strength": 3, "evidence": ["src/query/search.ts → src/ranking/bm25.ts"] }],
38
+ "explain": { "startHere": ["covers area:src/query"], "checks": ["routing.options.ownership.doc-bridge-query.checks"] },
39
+ "evidence": [{ "source": "derived", "path": "src/query", "contentHash": "…" }],
40
+ "metadata": { "entityId": "area:src/query", "kind": "area", "checksSource": "ownership", "confidence": "observed" }
41
+ }
42
+ ```
43
+
29
44
  ## Legacy compatibility
30
45
 
31
46
  Legacy `--agent` payloads may omit `schemaVersion`. Use `normalizeAgentHandoff()` or `safeParseAgentHandoff()` to upgrade.
@@ -25,6 +25,24 @@ Portable JSON Schema export: `DocBridgeIndexV1JsonSchema`.
25
25
  "title": "Authentication",
26
26
  "path": "docs/for-agents/auth.md",
27
27
  "description": "Auth ownership and edit workflow."
28
+ },
29
+ {
30
+ "id": "document:docs/auth.md",
31
+ "type": "document",
32
+ "title": "Authentication",
33
+ "path": "docs/auth.md",
34
+ "description": "How sign-in works.",
35
+ "tags": ["document", "human"],
36
+ "contentHash": "2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae"
37
+ },
38
+ {
39
+ "id": "module:packages/auth/src/session.ts",
40
+ "type": "module",
41
+ "title": "session.ts",
42
+ "path": "packages/auth/src/session.ts",
43
+ "symbols": ["createSession", "revokeSession"],
44
+ "tags": ["module", "ts", "src"],
45
+ "contentHash": "fcde2b2edba56bf408601fb721fe9b5c338d10ee429ea04fae5511b68fbf8fb9"
28
46
  }
29
47
  ],
30
48
  "handoffs": {
@@ -50,10 +68,55 @@ Portable JSON Schema export: `DocBridgeIndexV1JsonSchema`.
50
68
  "agentDoc": "docs/for-agents/auth.md"
51
69
  }
52
70
  }
71
+ },
72
+ "inputs": {
73
+ "hash": "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08",
74
+ "fileCount": 318,
75
+ "projectionVersion": 1
76
+ },
77
+ "retrieval": {
78
+ "lexiconVersion": 1,
79
+ "weights": { "id": 8, "symbols": 7, "title": 6, "path": 4, "tags": 3, "description": 2, "body": 1 },
80
+ "params": { "k1": 1.2, "b": 0.75 }
53
81
  }
54
82
  }
55
83
  ```
56
84
 
85
+ ## Entry kinds
86
+
87
+ `knowledge` holds two kinds of record, and ranking treats them differently.
88
+
89
+ **Curated** entries (`type: "agent-doc"`) come from the agent corpus a human wrote. They are what
90
+ `llms.txt` lists, and ranking favours them slightly, because they were authored to be the answer
91
+ to a question.
92
+
93
+ **Projected** entries (`type: "document"` or `"module"`) are every documentation file and source
94
+ module the [discovery snapshot](../knowledge-engine-runbook.md) observed, projected from it rather
95
+ than scanned again, so the two cannot disagree about what exists. A module carries its exported
96
+ `symbols`; both carry the `contentHash` of the file they were projected from, so a single stale
97
+ entry is detectable without rebuilding. Body text is not here: it lives once, in the projection.
98
+ `retrieval.corpus.enabled: false` omits them.
99
+
100
+ ## Projection
101
+
102
+ `projection` is the [retrieval index](../spec/retrieval-index-v1.md): what search ranks. It holds
103
+ every snapshot entity — documents, modules, areas, packages — and the routes the configuration
104
+ declares, each with the text the ranker indexes, its graph position, its content hash, provenance
105
+ and confidence. It is a pure function of the snapshot, the accepted overlay and the configuration,
106
+ and its `contentHash` is over those three inputs. `knowledge[]` above stays in step with it for
107
+ readers that predate it.
108
+
109
+ ## Freshness
110
+
111
+ `inputs` fingerprints the repository the index was built from: every input file and its content
112
+ hash, plus the configuration sections the index derives from, hashed together. Query surfaces
113
+ verify freshness by re-hashing those inputs rather than rebuilding the index, which is what keeps
114
+ a search cheap on a large repository. `retrieval.lexiconVersion` is checked too, because a changed
115
+ stopword list changes ranking without changing a single file.
116
+
117
+ An index written before `inputs` existed is still validated, by the full rebuild-and-compare it
118
+ always used.
119
+
57
120
  ## Content Hash
58
121
 
59
122
  `contentHashAlgo` is `sha256-normalized-v1`.
@@ -64,6 +127,8 @@ The hash input is deterministic JSON containing only:
64
127
  - `knowledge`
65
128
  - `handoffs`
66
129
  - `lookup`
130
+ - `retrieval`
131
+ - `inputs` (when the corpus projection is enabled)
67
132
 
68
133
  `generatedAt` is not part of the hash input. When the hash is unchanged, `ak-docs index` preserves the existing `generatedAt` so regenerated `index.json` bytes stay stable.
69
134
 
@@ -27,10 +27,42 @@ The fixture contains only stable identifiers and explicitly supported cases:
27
27
 
28
28
  The observation contains the same three sets, plus optional evidence identifiers and finding-category counts. The result reports true positives, false positives, false negatives, precision, recall, duplicate observations, evidence ratio, finding density, excluded cases, thresholds, and regressions. Excluded cases are removed from denominators only because they are explicitly listed and their counts remain visible.
29
29
 
30
- Benchmark output is aggregate by default: it does not include repository contents, prompts, credentials, or the member lists used to calculate the result. Baselines are not changed by `benchmark` or by a verification run. Use the verification harness's explicit audited baseline command when a new baseline is intentionally approved.
30
+ Benchmark output is aggregate by default: it does not include repository contents, prompts, credentials, or the member lists used to calculate the result. Baselines are not changed by `benchmark` or by a verification run. When a new baseline is intentionally approved, use the study tooling's separate audited baseline operation and record its artifact hash and human decision; the official `@agentskit/harness@0.9.0` verification CLI does not replace baselines.
31
+
32
+ ## Deterministic agent retrieval gate
33
+
34
+ The query contract also measures the real `--agent` payload for a fixed query
35
+ fixture. It records hit rate, p95 estimated tokens, p95 response bytes, and
36
+ context reduction relative to the indexed fixture. This proves bounded,
37
+ repeatable retrieval behavior; it does not prove that a model completed a
38
+ semantic task correctly or that estimated tokens equal provider usage.
39
+
40
+ The task-efficiency contract adds a separate, deterministic layer: each fixed
41
+ task declares an expected evidence identifier, and the benchmark records task
42
+ count, exact-evidence correctness rate, p95 tokens/bytes, and p95 tokens/time
43
+ among correctly grounded tasks. A retrieval hit is not automatically a task
44
+ success. These fixture results measure whether the bounded context is
45
+ sufficient for the declared task; they are not LLM semantic-success data.
46
+
47
+ The repository verification contract runs the same class of check through the
48
+ real CLI artifact (`scripts/agent-task-efficiency-check.mjs`). This is a
49
+ required regression gate for bounded retrieval and measurement, but it remains
50
+ separate from semantic adjudication of an agent's prose or implementation.
51
+
52
+ The CLI check also records p95 wall-clock latency for each isolated baseline and
53
+ optimized invocation. These latency values are operational measurements, not a
54
+ claim that the optimized context is faster: process startup, indexing, and host
55
+ load are included, so latency must be compared separately from token and
56
+ context-size reduction. The provider pilot independently records process
57
+ duration and time to the first observed tool event; neither is a semantic
58
+ correctness metric.
31
59
 
32
60
  ## Semantic reconciliation gate
33
61
 
34
62
  The semantic gate runs labeled, synthetic cases through the real reconciliation implementation. The required v1 cases are `confirmed`, `undocumented`, `stale`, `not-analyzed`, `conflict`, and `unresolved`. Each case declares its exact expected diagnostic-code set and requires every emitted diagnostic to contain evidence.
35
63
 
36
64
  The gate is passing only when finding precision, finding recall, and evidence ratio are all `1.000`, with no regressions. The conflict case may legitimately emit the additional `RELATION_CONFIRMED` and `RELATION_NOT_ANALYZED` diagnostics because both declarations are evaluated independently; the expected set records that behavior explicitly. These cases prove classifier behavior, not coverage of every language analyzer or runtime-only relationship.
65
+
66
+ Study task success also requires exact coverage of the task's required evidence
67
+ identifiers. Matching only the number of evidence items is insufficient and is
68
+ treated as partial, preventing inflated correctness or token-efficiency claims.