@agentskit/doc-bridge 1.7.45 → 1.9.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 +465 -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 +15861 -6223
  10. package/dist/cli/program.js.map +1 -1
  11. package/dist/config/index.d.ts +1 -1
  12. package/dist/config/index.js +86 -6
  13. package/dist/config/index.js.map +1 -1
  14. package/dist/{index-BUL0q7s8.d.ts → index-Beor6Yhi.d.ts} +133 -1
  15. package/dist/index.d.ts +9871 -1062
  16. package/dist/index.js +16126 -6125
  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 +147 -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 +25 -6
  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 +117 -2
  139. package/src/conformance/documentation-standard-v1.ts +8 -6
  140. package/src/discovery/areas.ts +182 -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 +484 -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,91 @@
1
+ /**
2
+ * Token budgets, in the shape `@agentskit/core` gives them.
3
+ *
4
+ * `compileBudget` and `approximateCounter` below mirror the functions of the same name in
5
+ * `@agentskit/core`, restricted to what a deterministic payload needs: the `drop-oldest`
6
+ * strategy over plain role/content messages, with no system prompt, tools or summariser. The
7
+ * core package is an optional peer and every query surface must answer with no peer installed,
8
+ * so the algorithm lives here and a test runs the real `compileBudget` over the same messages
9
+ * and asserts the two agree on every token count, every dropped message and `fits`.
10
+ *
11
+ * The mirror is synchronous where the original is a promise: nothing here can await, and the
12
+ * MCP handlers that call it answer in one turn.
13
+ */
14
+
15
+ export type BudgetMessage = {
16
+ readonly role: string
17
+ readonly content: string
18
+ }
19
+
20
+ export type BudgetTokenCounter = {
21
+ readonly name: string
22
+ readonly count: (messages: readonly BudgetMessage[]) => number
23
+ }
24
+
25
+ /**
26
+ * Four characters per token, plus two per message, over role and content — the rule of thumb
27
+ * `@agentskit/core` uses. Good enough for budget planning, and reported as such.
28
+ */
29
+ export const approximateCounter: BudgetTokenCounter = {
30
+ name: 'approximate',
31
+ count: (messages) => messages.reduce((total, message) => total + Math.ceil((message.role.length + message.content.length) / 4) + 2, 0),
32
+ }
33
+
34
+ export const TOKEN_METHOD = 'approximate' as const
35
+
36
+ export type CompileBudgetInput = {
37
+ /** Hard upper bound on the tokens of what is kept. */
38
+ readonly budget: number
39
+ /** Oldest first: the front of the list is dropped first. */
40
+ readonly messages: readonly BudgetMessage[]
41
+ readonly counter?: BudgetTokenCounter
42
+ /** Never drop below this many messages, counted from the end. Default 1. */
43
+ readonly keepRecent?: number
44
+ readonly reserveForOutput?: number
45
+ }
46
+
47
+ export type CompileBudgetResult = {
48
+ readonly messages: readonly BudgetMessage[]
49
+ readonly tokens: {
50
+ readonly system: number
51
+ readonly messages: number
52
+ readonly tools: number
53
+ readonly total: number
54
+ readonly budget: number
55
+ }
56
+ readonly dropped: readonly BudgetMessage[]
57
+ readonly fits: boolean
58
+ readonly strategy: 'drop-oldest'
59
+ }
60
+
61
+ /**
62
+ * Drop the oldest messages until the rest fits the budget, keeping at least `keepRecent`.
63
+ *
64
+ * The last message is never dropped by default, which is what makes the strategy usable for a
65
+ * payload: the section that must survive is placed last, and the sections that may go are placed
66
+ * first, in the order they may go. `fits` is false only when what could not be dropped still
67
+ * exceeds the budget — an honest answer rather than a truncated one.
68
+ */
69
+ export const compileBudget = (input: CompileBudgetInput): CompileBudgetResult => {
70
+ const counter = input.counter ?? approximateCounter
71
+ const keepRecent = Math.max(1, input.keepRecent ?? 1)
72
+ const reserve = input.reserveForOutput ?? 0
73
+ const budget = input.budget - reserve
74
+ if (budget <= 0) throw new Error(`Budget must exceed reserveForOutput (${input.budget} ≤ ${reserve})`)
75
+
76
+ const messages = [...input.messages]
77
+ const dropped: BudgetMessage[] = []
78
+ let total = counter.count(messages)
79
+ while (messages.length > keepRecent && total > budget) {
80
+ dropped.push(messages.shift() as BudgetMessage)
81
+ total = counter.count(messages)
82
+ }
83
+
84
+ return {
85
+ messages,
86
+ tokens: { system: 0, messages: total, tools: 0, total, budget },
87
+ dropped,
88
+ fits: total <= budget,
89
+ strategy: 'drop-oldest',
90
+ }
91
+ }
@@ -0,0 +1,70 @@
1
+ import { BUDGET_SECTION_ORDER, type BudgetReport, type BudgetSection } from '../schemas/budget.js'
2
+ import { compileBudget, TOKEN_METHOD, type BudgetMessage } from './compile.js'
3
+
4
+ /**
5
+ * One droppable section of a payload: what it contributes, and the payload without it.
6
+ *
7
+ * `content` is what the section costs — the strings a reader would lose — and `strip` removes
8
+ * exactly that from the payload, so the payload with the section stripped and the section's
9
+ * content together are the whole payload. A section whose content is empty is absent from the
10
+ * report rather than reported kept: nothing was there to keep.
11
+ */
12
+ export type BudgetedSection<T> = {
13
+ readonly name: BudgetSection
14
+ readonly content: unknown
15
+ readonly strip: (payload: T) => T
16
+ }
17
+
18
+ /** Every message wears the same role, so the role's length never favours one section over another. */
19
+ const ROLE = 'user'
20
+
21
+ const isEmpty = (value: unknown): boolean =>
22
+ value === undefined ||
23
+ value === null ||
24
+ (Array.isArray(value) && value.length === 0) ||
25
+ (typeof value === 'object' && Object.keys(value as object).length === 0) ||
26
+ (typeof value === 'string' && value.length === 0)
27
+
28
+ /**
29
+ * Trim a payload to a token budget, section by section, in the declared order.
30
+ *
31
+ * Each present section becomes one message, oldest first in the order they may be dropped, and
32
+ * the payload with every section stripped becomes the last message — the one `compileBudget`
33
+ * never drops. The result is the payload with the dropped sections stripped and a report of what
34
+ * it cost, what was dropped and whether it fits. Two calls over the same payload and budget give
35
+ * the same report: the counter is arithmetic over the serialised sections.
36
+ */
37
+ export const applyBudget = <T>(payload: T, sections: readonly BudgetedSection<T>[], budgetTokens: number): { readonly payload: T; readonly budget: BudgetReport } => {
38
+ const present = BUDGET_SECTION_ORDER.map((name) => sections.find((section) => section.name === name)).filter(
39
+ (section): section is BudgetedSection<T> => section !== undefined && !isEmpty(section.content),
40
+ )
41
+ const core = present.reduce((value, section) => section.strip(value), payload)
42
+ const messages: BudgetMessage[] = [
43
+ ...present.map((section) => ({ role: ROLE, content: JSON.stringify(section.content) })),
44
+ { role: ROLE, content: JSON.stringify(core) },
45
+ ]
46
+ const compiled = compileBudget({ budget: budgetTokens, messages, keepRecent: 1 })
47
+
48
+ const droppedNames = present.slice(0, compiled.dropped.length).map((section) => section.name)
49
+ const keptSections = present.slice(compiled.dropped.length)
50
+ const tokensOf = (message: BudgetMessage): number => compileBudget({ budget: budgetTokens, messages: [message] }).tokens.total
51
+ const sectionTokens = Object.fromEntries(present.map((section, position) => [section.name, tokensOf(messages[position] as BudgetMessage)])) as Record<BudgetSection, number>
52
+
53
+ return {
54
+ payload: present.slice(0, compiled.dropped.length).reduce((value, section) => section.strip(value), payload),
55
+ budget: {
56
+ budgetTokens,
57
+ tokens: {
58
+ total: compiled.tokens.total,
59
+ budget: compiled.tokens.budget,
60
+ core: tokensOf(messages[messages.length - 1] as BudgetMessage),
61
+ sections: sectionTokens,
62
+ },
63
+ fits: compiled.fits,
64
+ order: [...BUDGET_SECTION_ORDER],
65
+ kept: keptSections.map((section) => section.name),
66
+ dropped: droppedNames,
67
+ tokenMethod: TOKEN_METHOD,
68
+ },
69
+ }
70
+ }