@vibgrate/cli 2026.818.2 → 2026.819.1

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 (117) hide show
  1. package/dist/{agent-X6VYCE63.js → agent-3CKNTCRX.js} +12 -12
  2. package/dist/{agent-X6VYCE63.js.map → agent-3CKNTCRX.js.map} +1 -1
  3. package/dist/{approvals-TPQFQSWG.js → approvals-DHTG3HI4.js} +5 -5
  4. package/dist/{approvals-TPQFQSWG.js.map → approvals-DHTG3HI4.js.map} +1 -1
  5. package/dist/{attach-G5JUIWIT.js → attach-OCQ3I76L.js} +3 -3
  6. package/dist/{attach-G5JUIWIT.js.map → attach-OCQ3I76L.js.map} +1 -1
  7. package/dist/baseline-QDC6OQ2X.js +9 -0
  8. package/dist/{baseline-DXI64VLW.js.map → baseline-QDC6OQ2X.js.map} +1 -1
  9. package/dist/{chunk-NJQZRM55.js → chunk-4VAA2XSM.js} +3 -3
  10. package/dist/{chunk-NJQZRM55.js.map → chunk-4VAA2XSM.js.map} +1 -1
  11. package/dist/{chunk-YF54UMOU.js → chunk-5O6O7DJH.js} +3 -3
  12. package/dist/{chunk-YF54UMOU.js.map → chunk-5O6O7DJH.js.map} +1 -1
  13. package/dist/{chunk-6ABMV74F.js → chunk-5XY4EFR7.js} +4 -4
  14. package/dist/{chunk-6ABMV74F.js.map → chunk-5XY4EFR7.js.map} +1 -1
  15. package/dist/{chunk-MRZHNUN7.js → chunk-6F52QR6F.js} +4 -4
  16. package/dist/{chunk-MRZHNUN7.js.map → chunk-6F52QR6F.js.map} +1 -1
  17. package/dist/{chunk-ZUOBPKVK.js → chunk-D33M2ARL.js} +3 -3
  18. package/dist/{chunk-ZUOBPKVK.js.map → chunk-D33M2ARL.js.map} +1 -1
  19. package/dist/{chunk-X2MQ7UFL.js → chunk-D44PGMH7.js} +9 -9
  20. package/dist/{chunk-X2MQ7UFL.js.map → chunk-D44PGMH7.js.map} +1 -1
  21. package/dist/chunk-DHU3OOEI.js +6 -0
  22. package/dist/{chunk-4NTNMT6T.js.map → chunk-DHU3OOEI.js.map} +1 -1
  23. package/dist/{chunk-BMOFJIMG.js → chunk-EI5AKDSC.js} +3 -3
  24. package/dist/{chunk-BMOFJIMG.js.map → chunk-EI5AKDSC.js.map} +1 -1
  25. package/dist/{chunk-AEJYA6HZ.js → chunk-EIESBKLW.js} +5 -5
  26. package/dist/{chunk-AEJYA6HZ.js.map → chunk-EIESBKLW.js.map} +1 -1
  27. package/dist/{chunk-B4EXD5LK.js → chunk-EMEMHNE3.js} +9 -7
  28. package/dist/chunk-EMEMHNE3.js.map +1 -0
  29. package/dist/{chunk-VQ5KMHW6.js → chunk-F46Q3AEI.js} +7 -7
  30. package/dist/{chunk-VQ5KMHW6.js.map → chunk-F46Q3AEI.js.map} +1 -1
  31. package/dist/{chunk-VMAIDM4K.js → chunk-FFY6NW7P.js} +3 -3
  32. package/dist/{chunk-VMAIDM4K.js.map → chunk-FFY6NW7P.js.map} +1 -1
  33. package/dist/{chunk-PRHH4DVO.js → chunk-FQVAQVJV.js} +3 -3
  34. package/dist/{chunk-PRHH4DVO.js.map → chunk-FQVAQVJV.js.map} +1 -1
  35. package/dist/{chunk-E3O5UKNA.js → chunk-JGBOYZAF.js} +7 -7
  36. package/dist/{chunk-E3O5UKNA.js.map → chunk-JGBOYZAF.js.map} +1 -1
  37. package/dist/{chunk-L2OS4WHT.js → chunk-KFEM6FWP.js} +4 -4
  38. package/dist/{chunk-L2OS4WHT.js.map → chunk-KFEM6FWP.js.map} +1 -1
  39. package/dist/{chunk-RHKOUPWT.js → chunk-KKQX3F5F.js} +3 -3
  40. package/dist/{chunk-RHKOUPWT.js.map → chunk-KKQX3F5F.js.map} +1 -1
  41. package/dist/{chunk-V6WONSIK.js → chunk-NWWLUFN5.js} +3 -3
  42. package/dist/{chunk-V6WONSIK.js.map → chunk-NWWLUFN5.js.map} +1 -1
  43. package/dist/{chunk-KU7FI5EV.js → chunk-O5ASXWKF.js} +3 -3
  44. package/dist/{chunk-KU7FI5EV.js.map → chunk-O5ASXWKF.js.map} +1 -1
  45. package/dist/{chunk-V2UGRUTL.js → chunk-OQT3JBWW.js} +11 -11
  46. package/dist/{chunk-V2UGRUTL.js.map → chunk-OQT3JBWW.js.map} +1 -1
  47. package/dist/{chunk-NG4KIJW6.js → chunk-PVNALGTG.js} +10 -6
  48. package/dist/chunk-PVNALGTG.js.map +1 -0
  49. package/dist/{chunk-2C33WR5O.js → chunk-QMRSCJUN.js} +3 -3
  50. package/dist/{chunk-2C33WR5O.js.map → chunk-QMRSCJUN.js.map} +1 -1
  51. package/dist/{chunk-NKLYDSB7.js → chunk-QSLVOVNZ.js} +8 -8
  52. package/dist/{chunk-NKLYDSB7.js.map → chunk-QSLVOVNZ.js.map} +1 -1
  53. package/dist/{chunk-6PFHDHOL.js → chunk-TS25WFAT.js} +16 -14
  54. package/dist/chunk-TS25WFAT.js.map +1 -0
  55. package/dist/{chunk-5I4VSBWQ.js → chunk-TS7STRMI.js} +370 -111
  56. package/dist/chunk-TS7STRMI.js.map +1 -0
  57. package/dist/{chunk-FFXGWFAE.js → chunk-U7A7D2HP.js} +3 -3
  58. package/dist/{chunk-FFXGWFAE.js.map → chunk-U7A7D2HP.js.map} +1 -1
  59. package/dist/{chunk-O5IJDMTB.js → chunk-VYSDR2QE.js} +3 -3
  60. package/dist/{chunk-O5IJDMTB.js.map → chunk-VYSDR2QE.js.map} +1 -1
  61. package/dist/{chunk-JGA63RGF.js → chunk-WJYJCDNY.js} +11 -11
  62. package/dist/{chunk-JGA63RGF.js.map → chunk-WJYJCDNY.js.map} +1 -1
  63. package/dist/{chunk-HF6R73UC.js → chunk-YIEP5GK5.js} +22 -12
  64. package/dist/chunk-YIEP5GK5.js.map +1 -0
  65. package/dist/cli.js +61 -67
  66. package/dist/cli.js.map +1 -1
  67. package/dist/{daemon-GUMWMKCA.js → daemon-UNL65PTP.js} +10 -11
  68. package/dist/{daemon-GUMWMKCA.js.map → daemon-UNL65PTP.js.map} +1 -1
  69. package/dist/embed-worker-main.js +3 -3
  70. package/dist/{ensure-map-FHDJTO7Y.js → ensure-map-4D2HJ6MA.js} +17 -18
  71. package/dist/{ensure-map-FHDJTO7Y.js.map → ensure-map-4D2HJ6MA.js.map} +1 -1
  72. package/dist/federation-SZYVHYB2.js +8 -0
  73. package/dist/{federation-MDQPO3PW.js.map → federation-SZYVHYB2.js.map} +1 -1
  74. package/dist/fs-FO3NQHPT.js +4 -0
  75. package/dist/fs-FO3NQHPT.js.map +1 -0
  76. package/dist/{graph-backend-W2D3HRRD.js → graph-backend-36EIAAPQ.js} +7 -7
  77. package/dist/{graph-backend-W2D3HRRD.js.map → graph-backend-36EIAAPQ.js.map} +1 -1
  78. package/dist/index.d.ts +1 -1
  79. package/dist/index.js +17 -18
  80. package/dist/index.js.map +1 -1
  81. package/dist/{interactive-2MK4TLRD.js → interactive-ZZMHSZ3W.js} +27 -28
  82. package/dist/interactive-ZZMHSZ3W.js.map +1 -0
  83. package/dist/load-6CYLMUT5.js +11 -0
  84. package/dist/{load-4R4HYMBB.js.map → load-6CYLMUT5.js.map} +1 -1
  85. package/dist/parse-worker.js +2 -2
  86. package/dist/{run-outcome-H5GVDDZJ.js → run-outcome-ADEAKXHH.js} +5 -5
  87. package/dist/{run-outcome-H5GVDDZJ.js.map → run-outcome-ADEAKXHH.js.map} +1 -1
  88. package/dist/{runtime-session-JBIHHH5N.js → runtime-session-VNSXQAEO.js} +10 -11
  89. package/dist/{runtime-session-JBIHHH5N.js.map → runtime-session-VNSXQAEO.js.map} +1 -1
  90. package/dist/{session-N5IU4K5Q.js → session-3A6LKJHD.js} +8 -8
  91. package/dist/{session-N5IU4K5Q.js.map → session-3A6LKJHD.js.map} +1 -1
  92. package/dist/{stream-json-4WLSUF6I.js → stream-json-S2TP2VPU.js} +12 -12
  93. package/dist/{stream-json-4WLSUF6I.js.map → stream-json-S2TP2VPU.js.map} +1 -1
  94. package/dist/version-SZI6I3A2.js +4 -0
  95. package/dist/{version-DTEU3SQD.js.map → version-SZI6I3A2.js.map} +1 -1
  96. package/dist/{vg-mcp-bridge-KDVYIMFX.js → vg-mcp-bridge-IIBEAOEB.js} +12 -11
  97. package/dist/vg-mcp-bridge-IIBEAOEB.js.map +1 -0
  98. package/dist/{vgd-M7UOPWLB.js → vgd-KGXIKGOS.js} +9 -10
  99. package/dist/vgd-KGXIKGOS.js.map +1 -0
  100. package/package.json +1 -1
  101. package/dist/baseline-DXI64VLW.js +0 -9
  102. package/dist/chunk-4NTNMT6T.js +0 -6
  103. package/dist/chunk-5I4VSBWQ.js.map +0 -1
  104. package/dist/chunk-6PFHDHOL.js.map +0 -1
  105. package/dist/chunk-B4EXD5LK.js.map +0 -1
  106. package/dist/chunk-HF6R73UC.js.map +0 -1
  107. package/dist/chunk-NG4KIJW6.js.map +0 -1
  108. package/dist/chunk-POOL355F.js +0 -237
  109. package/dist/chunk-POOL355F.js.map +0 -1
  110. package/dist/federation-MDQPO3PW.js +0 -7
  111. package/dist/fs-TLPOWC2D.js +0 -4
  112. package/dist/fs-TLPOWC2D.js.map +0 -1
  113. package/dist/interactive-2MK4TLRD.js.map +0 -1
  114. package/dist/load-4R4HYMBB.js +0 -11
  115. package/dist/version-DTEU3SQD.js +0 -4
  116. package/dist/vg-mcp-bridge-KDVYIMFX.js.map +0 -1
  117. package/dist/vgd-M7UOPWLB.js.map +0 -1
@@ -1,30 +1,30 @@
1
- export { CONTEXT_POLICY_VERSION, DISCOVERY_TOOLS, MUTATION_TOOLS, compact, compactWithModel, runAgent } from './chunk-JGA63RGF.js';
1
+ export { CONTEXT_POLICY_VERSION, DISCOVERY_TOOLS, MUTATION_TOOLS, compact, compactWithModel, runAgent } from './chunk-WJYJCDNY.js';
2
2
  import './chunk-543E6WDJ.js';
3
- import './chunk-ZUOBPKVK.js';
4
- import './chunk-O5IJDMTB.js';
3
+ import './chunk-D33M2ARL.js';
4
+ import './chunk-VYSDR2QE.js';
5
5
  import './chunk-74UBGF4P.js';
6
6
  import './chunk-3HNPVXUK.js';
7
7
  import './chunk-5HYCB55P.js';
8
8
  import './chunk-VIWZ4QT7.js';
9
- import './chunk-RHKOUPWT.js';
10
- export { summarizeCapsule } from './chunk-YF54UMOU.js';
9
+ import './chunk-KKQX3F5F.js';
10
+ export { summarizeCapsule } from './chunk-5O6O7DJH.js';
11
11
  import './chunk-EZ7UC5Y5.js';
12
12
  import './chunk-6BEBJCK4.js';
13
13
  import './chunk-J7LKEB2R.js';
14
- import './chunk-MRZHNUN7.js';
14
+ import './chunk-6F52QR6F.js';
15
15
  import './chunk-E53WBVUQ.js';
16
16
  import './chunk-NDNNOAS6.js';
17
- import './chunk-PRHH4DVO.js';
17
+ import './chunk-FQVAQVJV.js';
18
18
  import './chunk-T7RSQ5WD.js';
19
19
  import './chunk-6WRG7VDO.js';
20
- import './chunk-2C33WR5O.js';
21
- import './chunk-VMAIDM4K.js';
20
+ import './chunk-QMRSCJUN.js';
21
+ import './chunk-FFY6NW7P.js';
22
22
  import './chunk-MVPRPSXU.js';
23
23
  import './chunk-O3LABX6I.js';
24
- import './chunk-4NTNMT6T.js';
24
+ import './chunk-DHU3OOEI.js';
25
25
  import './chunk-BWPBB45M.js';
26
26
  import './chunk-JFGYT6BI.js';
27
27
  import './chunk-BPF3YX2U.js';
28
28
  import './chunk-Z6ZWNWWR.js';
29
- //# sourceMappingURL=agent-X6VYCE63.js.map
30
- //# sourceMappingURL=agent-X6VYCE63.js.map
29
+ //# sourceMappingURL=agent-3CKNTCRX.js.map
30
+ //# sourceMappingURL=agent-3CKNTCRX.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"agent-X6VYCE63.js"}
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"agent-3CKNTCRX.js"}
@@ -1,10 +1,10 @@
1
- export { addApprovalRule, approvalsPath, findMatchingRule, globMatch, loadApprovalRules, normalizeCommandPrefix, removeApprovalRule, ruleForAction, ruleKey, ruleLabel, saveApprovalRules } from './chunk-ZUOBPKVK.js';
2
- import './chunk-VMAIDM4K.js';
1
+ export { addApprovalRule, approvalsPath, findMatchingRule, globMatch, loadApprovalRules, normalizeCommandPrefix, removeApprovalRule, ruleForAction, ruleKey, ruleLabel, saveApprovalRules } from './chunk-D33M2ARL.js';
2
+ import './chunk-FFY6NW7P.js';
3
3
  import './chunk-O3LABX6I.js';
4
- import './chunk-4NTNMT6T.js';
4
+ import './chunk-DHU3OOEI.js';
5
5
  import './chunk-BWPBB45M.js';
6
6
  import './chunk-JFGYT6BI.js';
7
7
  import './chunk-BPF3YX2U.js';
8
8
  import './chunk-Z6ZWNWWR.js';
9
- //# sourceMappingURL=approvals-TPQFQSWG.js.map
10
- //# sourceMappingURL=approvals-TPQFQSWG.js.map
9
+ //# sourceMappingURL=approvals-DHTG3HI4.js.map
10
+ //# sourceMappingURL=approvals-DHTG3HI4.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"approvals-TPQFQSWG.js"}
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"approvals-DHTG3HI4.js"}
@@ -1,4 +1,4 @@
1
- export { attachVgd, daemonDisabledReason } from './chunk-NJQZRM55.js';
1
+ export { attachVgd, daemonDisabledReason } from './chunk-4VAA2XSM.js';
2
2
  import './chunk-LJSJX6U4.js';
3
3
  import './chunk-E53WBVUQ.js';
4
4
  import './chunk-NDNNOAS6.js';
@@ -6,5 +6,5 @@ import './chunk-BWPBB45M.js';
6
6
  import './chunk-JFGYT6BI.js';
7
7
  import './chunk-BPF3YX2U.js';
8
8
  import './chunk-Z6ZWNWWR.js';
9
- //# sourceMappingURL=attach-G5JUIWIT.js.map
10
- //# sourceMappingURL=attach-G5JUIWIT.js.map
9
+ //# sourceMappingURL=attach-OCQ3I76L.js.map
10
+ //# sourceMappingURL=attach-OCQ3I76L.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"attach-G5JUIWIT.js"}
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"attach-OCQ3I76L.js"}
@@ -0,0 +1,9 @@
1
+ export { baselineCommand, runBaseline } from './chunk-5XY4EFR7.js';
2
+ import './chunk-OQT3JBWW.js';
3
+ import './chunk-PVNALGTG.js';
4
+ import './chunk-CRAMOEBE.js';
5
+ import './chunk-T7RSQ5WD.js';
6
+ import './chunk-DHU3OOEI.js';
7
+ import './chunk-Z6ZWNWWR.js';
8
+ //# sourceMappingURL=baseline-QDC6OQ2X.js.map
9
+ //# sourceMappingURL=baseline-QDC6OQ2X.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"baseline-DXI64VLW.js"}
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"baseline-QDC6OQ2X.js"}
@@ -91,10 +91,10 @@ async function currentSlot(root, socketPath, request) {
91
91
  return { repositoryId: reg.workspace.id, gitRef: summary.gitRef, corpusHash: summary.summary.corpusHash };
92
92
  }
93
93
  async function defaultEnsure() {
94
- const { ensureVgdSoft } = await import('./daemon-GUMWMKCA.js');
94
+ const { ensureVgdSoft } = await import('./daemon-UNL65PTP.js');
95
95
  return (socketPath, readyBudgetMs) => ensureVgdSoft(socketPath, readyBudgetMs);
96
96
  }
97
97
 
98
98
  export { attachVgd, daemonDisabledReason };
99
- //# sourceMappingURL=chunk-NJQZRM55.js.map
100
- //# sourceMappingURL=chunk-NJQZRM55.js.map
99
+ //# sourceMappingURL=chunk-4VAA2XSM.js.map
100
+ //# sourceMappingURL=chunk-4VAA2XSM.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/runtime/vgd/attach.ts"],"names":[],"mappings":";;;;;AA0EA,SAAS,OAAO,KAAA,EAAoC;AAClD,EAAA,IAAI,CAAC,OAAO,OAAO,KAAA;AACnB,EAAA,MAAM,CAAA,GAAI,KAAA,CAAM,IAAA,EAAK,CAAE,WAAA,EAAY;AACnC,EAAA,OAAO,MAAM,EAAA,IAAM,CAAA,KAAM,GAAA,IAAO,CAAA,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OAAO,IAAA;AACnD,EAAA,OAAO,EAAE,YAAA,EAAc,GAAA,CAAI,SAAA,CAAU,EAAA,EAAI,MAAA,EAAQ,OAAA,CAAQ,MAAA,EAAQ,UAAA,EAAY,OAAA,CAAQ,OAAA,CAAQ,UAAA,EAAW;AAC1G;AAEA,eAAe,aAAA,GAAyH;AAGtI,EAAA,MAAM,EAAE,aAAA,EAAc,GAAI,MAAM,OAAO,sBAA0B,CAAA;AACjE,EAAA,OAAO,CAAC,UAAA,EAAY,aAAA,KAAkB,aAAA,CAAc,YAAY,aAAa,CAAA;AAC/E","file":"chunk-NJQZRM55.js","sourcesContent":["import { vgdIsRunning, vgdRequest } from './client.js';\nimport { vgdSocketPath } from './paths.js';\nimport { publishGraphToVgd, type VgdPublishOutcome } from './publish.js';\n\n/**\n * The one way an ordinary command joins the local runtime.\n *\n * Until now vgd only ever existed because `vg code` or the VS Code extension\n * started it, so a developer running `vg`, `vg build` and `vg ask` all day\n * never had a runtime at all — every invocation re-read the map and re-loaded\n * the embedder from cold. Auto-start makes the daemon the normal case, and\n * publishing on attach makes it hold the thing it is supposed to accelerate.\n *\n * Three rules keep this safe to put in front of every command:\n *\n * - **Never blocking.** `ensureVgdSoft` spawns and waits ~1.5s, not the 30s\n * `vg daemon ensure` waits. A daemon that is still coming up simply is not\n * used this time; the command runs its in-process path and finds a warm\n * runtime on the next call.\n * - **Never fatal.** Every outcome is a value, never a throw. \"No daemon\" is a\n * supported configuration, and it must stay one — the fallbacks are the\n * code paths that exist today.\n * - **Always escapable.** `--no-daemon`, `VG_NO_DAEMON=1`, and `CI` all turn\n * auto-start off. A one-shot CI job should not leave a background process\n * behind, and a user who does not want one must be able to say so once.\n */\n\nexport type AttachStatus = 'attached' | 'disabled' | 'unavailable';\n\nexport interface AttachResult {\n status: AttachStatus;\n /** Why, when not attached — safe to show verbatim. */\n reason?: string;\n /** True when this call is what started the daemon. */\n started?: boolean;\n socketPath?: string;\n repositoryId?: string;\n gitRef?: string;\n /** Outcome of the map publish, when one was requested. */\n published?: VgdPublishOutcome;\n}\n\nexport interface AttachOptions {\n socketPath?: string;\n /** Spawn a daemon when none is listening (default true). */\n autoStart?: boolean;\n /** How long to wait for a just-spawned daemon before giving up (default 1500ms). */\n readyBudgetMs?: number;\n /** Publish this repo's map after attaching (default true). */\n publish?: boolean;\n /**\n * The corpus hash of the map the caller already holds. When the daemon's\n * slot reports the same hash the publish is skipped entirely.\n *\n * This matters more than it looks: `load-graph` runs the registry's slot\n * funnel, and `onGraphPut` deliberately drops the slot's vectors — so\n * re-publishing an unchanged map on every `vg ask` invalidated and re-seeded\n * the semantic index once per command, for nothing.\n */\n corpusHash?: string;\n /** Also wait for the slot's semantic index (default false — warming is background work). */\n warmSemantic?: boolean;\n gitRef?: string;\n /** Custom `--graph` artifact path. */\n graphPath?: string;\n /** Explicit opt-out from the caller's parsed flags (`--no-daemon`). */\n disabled?: boolean;\n /** Injected (tests). */\n isRunning?: typeof vgdIsRunning;\n request?: typeof vgdRequest;\n ensure?: (socketPath: string, readyBudgetMs: number) => Promise<{ running: boolean; started: boolean }>;\n env?: NodeJS.ProcessEnv;\n}\n\nfunction truthy(value: string | undefined): boolean {\n if (!value) return false;\n const v = value.trim().toLowerCase();\n return v !== '' && v !== '0' && v !== 'false' && v !== 'no';\n}\n\n/**\n * Why auto-start is off, or null when it is on. Exposed so `vg doctor` can\n * explain a missing daemon instead of leaving the user to guess.\n */\nexport function daemonDisabledReason(\n options: { disabled?: boolean; env?: NodeJS.ProcessEnv } = {},\n): string | null {\n const env = options.env ?? process.env;\n if (options.disabled) return 'disabled by --no-daemon';\n if (truthy(env.VG_NO_DAEMON) || truthy(env.VIBGRATE_NO_DAEMON)) return 'disabled by VG_NO_DAEMON';\n // A CI job is one-shot by definition: starting a background daemon there\n // costs a cold start and leaves a process behind for no second call.\n if (truthy(env.CI)) return 'skipped in CI';\n return null;\n}\n\n/**\n * Ensure a local vgd is running and knows about this repository's map.\n * Resolves to a description of what happened; never throws.\n */\nexport async function attachVgd(root: string, options: AttachOptions = {}): Promise<AttachResult> {\n const disabled = daemonDisabledReason(options);\n if (disabled) return { status: 'disabled', reason: disabled };\n\n const socketPath = options.socketPath ?? vgdSocketPath();\n const isRunning = options.isRunning ?? vgdIsRunning;\n const readyBudgetMs = options.readyBudgetMs ?? 1500;\n\n try {\n let running = await isRunning({ socketPath });\n let started = false;\n if (!running && options.autoStart !== false) {\n const ensure = options.ensure ?? (await defaultEnsure());\n const r = await ensure(socketPath, readyBudgetMs);\n running = r.running;\n started = r.started;\n }\n if (!running) {\n return {\n status: 'unavailable',\n reason: started ? 'vgd is still starting — this run uses the in-process path' : 'no vgd is running',\n started,\n socketPath,\n };\n }\n\n const request = options.request ?? vgdRequest;\n\n // Register even when not publishing: \"attached\" should always mean the\n // caller knows which slot it is talking to, or `embed-rank` has no target.\n if (options.publish === false) {\n const reg = await request({ op: 'register', root }, { socketPath });\n const workspace = reg.ok && 'workspace' in reg ? reg.workspace : undefined;\n return {\n status: 'attached',\n started,\n socketPath,\n repositoryId: workspace?.id,\n gitRef: workspace?.gitRef,\n };\n }\n\n // Already current? Then registering is all this call needs to do.\n if (options.corpusHash) {\n const current = await currentSlot(root, socketPath, request);\n if (current && current.corpusHash === options.corpusHash) {\n return {\n status: 'attached',\n started,\n socketPath,\n repositoryId: current.repositoryId,\n gitRef: current.gitRef,\n published: { status: 'current', repositoryId: current.repositoryId, gitRef: current.gitRef },\n };\n }\n }\n\n const published = await publishGraphToVgd(root, {\n socketPath,\n gitRef: options.gitRef,\n graphPath: options.graphPath,\n warmSemantic: options.warmSemantic,\n isRunning: () => Promise.resolve(true),\n request: options.request,\n });\n return {\n status: 'attached',\n started,\n socketPath,\n repositoryId: published.status === 'published' ? published.repositoryId : undefined,\n gitRef: published.status === 'published' ? published.gitRef : undefined,\n published,\n };\n } catch (e) {\n return { status: 'unavailable', reason: e instanceof Error ? e.message : String(e), socketPath };\n }\n}\n\n/**\n * Register the workspace and ask what the daemon already holds for it.\n * Returns null when there is no slot yet (the common first-run case).\n */\nasync function currentSlot(\n root: string,\n socketPath: string,\n request: typeof vgdRequest,\n): Promise<{ repositoryId: string; gitRef: string; corpusHash: string | null } | null> {\n const reg = await request({ op: 'register', root }, { socketPath });\n if (!reg.ok || !('workspace' in reg)) return null;\n const summary = await request({ op: 'graph-summary', repositoryId: reg.workspace.id }, { socketPath });\n if (!summary.ok || !('summary' in summary)) return null;\n return { repositoryId: reg.workspace.id, gitRef: summary.gitRef, corpusHash: summary.summary.corpusHash };\n}\n\nasync function defaultEnsure(): Promise<(socketPath: string, readyBudgetMs: number) => Promise<{ running: boolean; started: boolean }>> {\n // Imported lazily: `commands/daemon.ts` pulls in commander and the whole\n // daemon command surface, which no fast path should pay for up front.\n const { ensureVgdSoft } = await import('../../commands/daemon.js');\n return (socketPath, readyBudgetMs) => ensureVgdSoft(socketPath, readyBudgetMs);\n}\n"]}
1
+ {"version":3,"sources":["../src/runtime/vgd/attach.ts"],"names":[],"mappings":";;;;;AA0EA,SAAS,OAAO,KAAA,EAAoC;AAClD,EAAA,IAAI,CAAC,OAAO,OAAO,KAAA;AACnB,EAAA,MAAM,CAAA,GAAI,KAAA,CAAM,IAAA,EAAK,CAAE,WAAA,EAAY;AACnC,EAAA,OAAO,MAAM,EAAA,IAAM,CAAA,KAAM,GAAA,IAAO,CAAA,KAAM,WAAW,CAAA,KAAM,IAAA;AACzD;AAMO,SAAS,oBAAA,CACd,OAAA,GAA2D,EAAC,EAC7C;AACf,EAAA,MAAM,GAAA,GAAM,OAAA,CAAQ,GAAA,IAAO,OAAA,CAAQ,GAAA;AACnC,EAAA,IAAI,OAAA,CAAQ,UAAU,OAAO,yBAAA;AAC7B,EAAA,IAAI,MAAA,CAAO,IAAI,YAAY,CAAA,IAAK,OAAO,GAAA,CAAI,kBAAkB,GAAG,OAAO,0BAAA;AAGvE,EAAA,IAAI,MAAA,CAAO,GAAA,CAAI,EAAE,CAAA,EAAG,OAAO,eAAA;AAC3B,EAAA,OAAO,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unning, vgdRequest } from './client.js';\nimport { vgdSocketPath } from './paths.js';\nimport { publishGraphToVgd, type VgdPublishOutcome } from './publish.js';\n\n/**\n * The one way an ordinary command joins the local runtime.\n *\n * Until now vgd only ever existed because `vg code` or the VS Code extension\n * started it, so a developer running `vg`, `vg build` and `vg ask` all day\n * never had a runtime at all — every invocation re-read the map and re-loaded\n * the embedder from cold. Auto-start makes the daemon the normal case, and\n * publishing on attach makes it hold the thing it is supposed to accelerate.\n *\n * Three rules keep this safe to put in front of every command:\n *\n * - **Never blocking.** `ensureVgdSoft` spawns and waits ~1.5s, not the 30s\n * `vg daemon ensure` waits. A daemon that is still coming up simply is not\n * used this time; the command runs its in-process path and finds a warm\n * runtime on the next call.\n * - **Never fatal.** Every outcome is a value, never a throw. \"No daemon\" is a\n * supported configuration, and it must stay one — the fallbacks are the\n * code paths that exist today.\n * - **Always escapable.** `--no-daemon`, `VG_NO_DAEMON=1`, and `CI` all turn\n * auto-start off. A one-shot CI job should not leave a background process\n * behind, and a user who does not want one must be able to say so once.\n */\n\nexport type AttachStatus = 'attached' | 'disabled' | 'unavailable';\n\nexport interface AttachResult {\n status: AttachStatus;\n /** Why, when not attached — safe to show verbatim. */\n reason?: string;\n /** True when this call is what started the daemon. */\n started?: boolean;\n socketPath?: string;\n repositoryId?: string;\n gitRef?: string;\n /** Outcome of the map publish, when one was requested. */\n published?: VgdPublishOutcome;\n}\n\nexport interface AttachOptions {\n socketPath?: string;\n /** Spawn a daemon when none is listening (default true). */\n autoStart?: boolean;\n /** How long to wait for a just-spawned daemon before giving up (default 1500ms). */\n readyBudgetMs?: number;\n /** Publish this repo's map after attaching (default true). */\n publish?: boolean;\n /**\n * The corpus hash of the map the caller already holds. When the daemon's\n * slot reports the same hash the publish is skipped entirely.\n *\n * This matters more than it looks: `load-graph` runs the registry's slot\n * funnel, and `onGraphPut` deliberately drops the slot's vectors — so\n * re-publishing an unchanged map on every `vg ask` invalidated and re-seeded\n * the semantic index once per command, for nothing.\n */\n corpusHash?: string;\n /** Also wait for the slot's semantic index (default false — warming is background work). */\n warmSemantic?: boolean;\n gitRef?: string;\n /** Custom `--graph` artifact path. */\n graphPath?: string;\n /** Explicit opt-out from the caller's parsed flags (`--no-daemon`). */\n disabled?: boolean;\n /** Injected (tests). */\n isRunning?: typeof vgdIsRunning;\n request?: typeof vgdRequest;\n ensure?: (socketPath: string, readyBudgetMs: number) => Promise<{ running: boolean; started: boolean }>;\n env?: NodeJS.ProcessEnv;\n}\n\nfunction truthy(value: string | undefined): boolean {\n if (!value) return false;\n const v = value.trim().toLowerCase();\n return v !== '' && v !== '0' && v !== 'false' && v !== 'no';\n}\n\n/**\n * Why auto-start is off, or null when it is on. Exposed so `vg doctor` can\n * explain a missing daemon instead of leaving the user to guess.\n */\nexport function daemonDisabledReason(\n options: { disabled?: boolean; env?: NodeJS.ProcessEnv } = {},\n): string | null {\n const env = options.env ?? process.env;\n if (options.disabled) return 'disabled by --no-daemon';\n if (truthy(env.VG_NO_DAEMON) || truthy(env.VIBGRATE_NO_DAEMON)) return 'disabled by VG_NO_DAEMON';\n // A CI job is one-shot by definition: starting a background daemon there\n // costs a cold start and leaves a process behind for no second call.\n if (truthy(env.CI)) return 'skipped in CI';\n return null;\n}\n\n/**\n * Ensure a local vgd is running and knows about this repository's map.\n * Resolves to a description of what happened; never throws.\n */\nexport async function attachVgd(root: string, options: AttachOptions = {}): Promise<AttachResult> {\n const disabled = daemonDisabledReason(options);\n if (disabled) return { status: 'disabled', reason: disabled };\n\n const socketPath = options.socketPath ?? vgdSocketPath();\n const isRunning = options.isRunning ?? vgdIsRunning;\n const readyBudgetMs = options.readyBudgetMs ?? 1500;\n\n try {\n let running = await isRunning({ socketPath });\n let started = false;\n if (!running && options.autoStart !== false) {\n const ensure = options.ensure ?? (await defaultEnsure());\n const r = await ensure(socketPath, readyBudgetMs);\n running = r.running;\n started = r.started;\n }\n if (!running) {\n return {\n status: 'unavailable',\n reason: started ? 'vgd is still starting — this run uses the in-process path' : 'no vgd is running',\n started,\n socketPath,\n };\n }\n\n const request = options.request ?? vgdRequest;\n\n // Register even when not publishing: \"attached\" should always mean the\n // caller knows which slot it is talking to, or `embed-rank` has no target.\n if (options.publish === false) {\n const reg = await request({ op: 'register', root }, { socketPath });\n const workspace = reg.ok && 'workspace' in reg ? reg.workspace : undefined;\n return {\n status: 'attached',\n started,\n socketPath,\n repositoryId: workspace?.id,\n gitRef: workspace?.gitRef,\n };\n }\n\n // Already current? Then registering is all this call needs to do.\n if (options.corpusHash) {\n const current = await currentSlot(root, socketPath, request);\n if (current && current.corpusHash === options.corpusHash) {\n return {\n status: 'attached',\n started,\n socketPath,\n repositoryId: current.repositoryId,\n gitRef: current.gitRef,\n published: { status: 'current', repositoryId: current.repositoryId, gitRef: current.gitRef },\n };\n }\n }\n\n const published = await publishGraphToVgd(root, {\n socketPath,\n gitRef: options.gitRef,\n graphPath: options.graphPath,\n warmSemantic: options.warmSemantic,\n isRunning: () => Promise.resolve(true),\n request: options.request,\n });\n return {\n status: 'attached',\n started,\n socketPath,\n repositoryId: published.status === 'published' ? published.repositoryId : undefined,\n gitRef: published.status === 'published' ? published.gitRef : undefined,\n published,\n };\n } catch (e) {\n return { status: 'unavailable', reason: e instanceof Error ? e.message : String(e), socketPath };\n }\n}\n\n/**\n * Register the workspace and ask what the daemon already holds for it.\n * Returns null when there is no slot yet (the common first-run case).\n */\nasync function currentSlot(\n root: string,\n socketPath: string,\n request: typeof vgdRequest,\n): Promise<{ repositoryId: string; gitRef: string; corpusHash: string | null } | null> {\n const reg = await request({ op: 'register', root }, { socketPath });\n if (!reg.ok || !('workspace' in reg)) return null;\n const summary = await request({ op: 'graph-summary', repositoryId: reg.workspace.id }, { socketPath });\n if (!summary.ok || !('summary' in summary)) return null;\n return { repositoryId: reg.workspace.id, gitRef: summary.gitRef, corpusHash: summary.summary.corpusHash };\n}\n\nasync function defaultEnsure(): Promise<(socketPath: string, readyBudgetMs: number) => Promise<{ running: boolean; started: boolean }>> {\n // Imported lazily: `commands/daemon.ts` pulls in commander and the whole\n // daemon command surface, which no fast path should pay for up front.\n const { ensureVgdSoft } = await import('../../commands/daemon.js');\n return (socketPath, readyBudgetMs) => ensureVgdSoft(socketPath, readyBudgetMs);\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { indexFor, userAskFromInstruction, queryGraph, impactOf, conceptMapLines, extractLiteralNeedles } from './chunk-MRZHNUN7.js';
1
+ import { indexFor, userAskFromInstruction, queryGraph, impactOf, conceptMapLines, extractLiteralNeedles } from './chunk-6F52QR6F.js';
2
2
  import { cacheDir } from './chunk-MVPRPSXU.js';
3
3
  import { hashString } from './chunk-JFGYT6BI.js';
4
4
  import * as fs from 'fs';
@@ -642,5 +642,5 @@ function estimateTokens2(text) {
642
642
  }
643
643
 
644
644
  export { CAPSULE_COMPILER_ID, CAPSULE_RANKING_VERSION, CLI_TOOL_ALIASES, PER_FILE_TOKENS, SAVINGS_TOOLS, TASK_CAPSULE_SCHEMA_VERSION, buildCodeContext, buildTaskCapsule, capsuleToCodeContext, clearSavings, readModelSavings, readSavings, readUsage, recordCliCall, recordSaving, sanitizeClient, savingsLedgerPath, savingsRecorded, summarizeCapsule };
645
- //# sourceMappingURL=chunk-YF54UMOU.js.map
646
- //# sourceMappingURL=chunk-YF54UMOU.js.map
645
+ //# sourceMappingURL=chunk-5O6O7DJH.js.map
646
+ //# sourceMappingURL=chunk-5O6O7DJH.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/engine/savings.ts","../src/code/context.ts","../src/code/capsule.ts"],"names":["estimateTokens","normalize"],"mappings":";;;;;;AAmBA,IAAM,MAAA,GAAS,eAAA;AAER,IAAM,eAAA,GAAkB;AAQxB,IAAM,gCAAgB,IAAI,GAAA,CAAI,CAAC,aAAA,EAAe,UAAA,EAAY,gBAAgB,CAAC;AAoB3E,IAAM,gBAAA,GAAqD;AAAA,EAChE,GAAA,EAAK,aAAA;AAAA,EACL,IAAA,EAAM,UAAA;AAAA,EACN,MAAA,EAAQ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A,IACL,EAAA,EAAI,IAAA;AAAA,IACJ,GAAA,EAAK,KAAA;AAAA,IACL,GAAA,EAAK,IAAA;AAAA,IACL,GAAA,EAAK,IAAA;AAAA,IACL,EAAA,EAAI,QAAA;AAAA,IACJ,EAAA,EAAI,MAAA;AAAA,IACJ,EAAA,EAAI,IAAA;AAAA,IACJ,IAAA,EAAM,MAAA;AAAA,IACN,EAAA,EAAI,QAAA;AAAA,IACJ,EAAA,EAAI,IAAA;AAAA,IACJ,IAAA,EAAM;AAAA,GACR;AACA,EAAA,OAAO,GAAA,CAAI,GAAG,CAAA,IAAK,EAAA;AACrB;AAEA,SAASC,WAAU,IAAA,EAAsB;AACvC,EAAA,OAAO,KAAK,OAAA,CAAQ,KAAA,EAAO,GAAG,CAAA,CAAE,OAAA,CAAQ,SAAS,EAAE,CAAA;AACrD;AAEA,SAASD,gBAAe,IAAA,EAAsB;AAC5C,EAAA,OAAO,IAAA,CAAK,IAAA,CAAK,IAAA,CAAK,MAAA,GAAS,CAAC,CAAA;AAClC","file":"chunk-YF54UMOU.js","sourcesContent":["import * as fs from 'node:fs';\nimport * as path from 'node:path';\nimport { cacheDir } from './cache.js';\n\n/**\n * Usage-savings tracking (VG-DEVELOPMENT-PLAN §5) — local, privacy-safe, and\n * **opt-in**. We record *counts only* — never code, never the question text —\n * comparing the context tokens vg returned against a grep/read baseline estimate.\n * `vg savings` reports it with the assumptions shown; figures are labelled\n * estimates, never a hero number.\n *\n * Each entry also carries which path served the call (`source`: an MCP tool call\n * vs a `vg <subcommand>` CLI invocation) and, when known, a coarse `client` label\n * (the AI on the other end). That powers the command-vs-MCP split and the\n * per-client breakdown in `vg savings`, and is the basis for the opt-in\n * `vg serve --share-stats` upload (see ./stats-share.ts). Nothing here leaves the\n * machine unless the operator explicitly enables sharing.\n */\n\nconst LEDGER = 'savings.jsonl';\n// A conservative, documented estimate: tokens an agent reads per file it opens.\nexport const PER_FILE_TOKENS = 400;\n\n/** The tools whose grep/read token baseline the savings summary is computed from.\n * search_symbols belongs here: it is the direct grep replacement (the server\n * instructions steer agents to it INSTEAD of grep), yet it used to contribute\n * zero to the estimate — on search-heavy sessions most of the real saving went\n * uncounted. Its baseline is the same measure as query_graph's: the distinct\n * files its matches point at, at PER_FILE_TOKENS each. */\nexport const SAVINGS_TOOLS = new Set(['query_graph', 'get_node', 'search_symbols']);\n\n/**\n * How a navigation call reached the map:\n * - `mcp` — a tool call over the local `vg serve` MCP server;\n * - `cli` — a `vg <subcommand>` invocation that identified itself with `--client`.\n * Both are recorded into one ledger under a shared tool vocabulary (CLI\n * subcommands are normalised to their MCP tool names via CLI_TOOL_ALIASES), so\n * `(tool, source)` is the command-vs-MCP split and the token math stays unified.\n * Absent on ledger lines written before sources existed → read as `mcp` (the\n * only path that recorded then).\n */\nexport type Source = 'mcp' | 'cli';\n\n/**\n * Canonical tool name a CLI navigation subcommand maps to — the same vocabulary\n * the MCP tools use, so a `vg ask --client=claude` and an MCP `query_graph` call\n * land on one row distinguished only by `source`. A subcommand with no MCP twin\n * (e.g. `tree`) keeps its own name.\n */\nexport const CLI_TOOL_ALIASES: Readonly<Record<string, string>> = {\n ask: 'query_graph',\n show: 'get_node',\n impact: 'impact_of',\n path: 'find_path',\n hubs: 'list_hubs',\n areas: 'list_areas',\n tree: 'tree',\n};\n\n/**\n * Normalise a free-form client name (from `--client` or the MCP `initialize`\n * handshake) to a short, bounded, non-PII token: lowercase, `[a-z0-9._-]` only,\n * ≤ 40 chars. Never carries arbitrary user input into the ledger or an upload —\n * it is a coarse client label (e.g. `claude`, `cursor`, `cline`), not identity.\n * Returns `'unknown'` when nothing usable is provided.\n */\nexport function sanitizeClient(name: string | undefined | null): string {\n if (typeof name !== 'string') return 'unknown';\n const cleaned = name\n .trim()\n .toLowerCase()\n .replace(/[^a-z0-9._-]+/g, '-')\n .replace(/^-+|-+$/g, '')\n .slice(0, 40);\n return cleaned || 'unknown';\n}\n\n/**\n * Outcome of a recorded navigation call:\n * - `complete` — returned results, with nothing capped or paginated;\n * - `partial` — returned results, but more were available/truncated;\n * - `miss` — returned no result (no match, not-found, not-connected).\n */\nexport type Outcome = 'complete' | 'partial' | 'miss';\n\nexport interface SavingEntry {\n ts: number; // epoch ms (runtime ledger state, not part of any artifact)\n tool: string;\n // Optional for back-compat with ledger lines written before outcomes existed;\n // an absent value is read as `complete` (those lines only recorded hits).\n outcome?: Outcome;\n vgTokens: number;\n baselineTokens: number;\n // Optional for back-compat: absent `source` reads as `mcp`. `client` is a\n // sanitized coarse label (see sanitizeClient) or absent when unidentified.\n source?: Source;\n client?: string;\n // The model that made the call, for per-model savings auditing. `provider` is\n // a coarse provider label (e.g. `anthropic`, `ollama`), `model` the sanitized\n // model slug. VG Code sets both so `vg savings` can break usage down per model.\n // Absent on lines from callers that don't identify a model.\n provider?: string;\n model?: string;\n // Wall time of the call, ms. Optional: absent on lines written before timing\n // existed (and on CLI-sourced lines) — absent means \"not measured\", never 0.\n ms?: number;\n}\n\n/**\n * Normalise a model slug to a bounded, non-PII token — like {@link sanitizeClient}\n * but keeping the `/` and `:` that model ids use (`anthropic/claude-3.5-sonnet`,\n * `qwen2.5-coder:7b`). Returns undefined when nothing usable is given.\n */\nexport function sanitizeModelId(name: string | undefined | null): string | undefined {\n if (typeof name !== 'string') return undefined;\n const cleaned = name\n .trim()\n .toLowerCase()\n .replace(/[^a-z0-9._:/-]+/g, '-')\n .replace(/^-+|-+$/g, '')\n .slice(0, 60);\n return cleaned || undefined;\n}\n\n/**\n * Record a CLI navigation call (`vg <subcommand> --client=<ai>`) into the same\n * local ledger the MCP path uses. Only ever called when the caller passed\n * `--client` — i.e. an AI host explicitly identified itself — so a human's bare\n * `vg ask` still records nothing. Counts only; never the question or code.\n */\nexport function recordCliCall(\n root: string,\n entry: { tool: string; client?: string; provider?: string; model?: string; outcome: Outcome; vgTokens?: number; baselineFiles?: number },\n now: number,\n): void {\n recordSaving(\n root,\n {\n tool: entry.tool,\n source: 'cli',\n client: sanitizeClient(entry.client),\n provider: entry.provider ? sanitizeClient(entry.provider) : undefined,\n model: sanitizeModelId(entry.model),\n outcome: entry.outcome,\n vgTokens: entry.vgTokens ?? 0,\n baselineTokens: (entry.baselineFiles ?? 0) * PER_FILE_TOKENS,\n },\n now,\n );\n}\n\n/**\n * Absolute path of the local usage ledger for this repo. Exported so the serve\n * status display can tail it live (mcp/ledger-tail.ts) — the file itself stays\n * local-only (GUARDRAILS §3.4; upload is the separate opt-in stats-share path).\n */\nexport function savingsLedgerPath(root: string): string {\n return path.join(cacheDir(root), LEDGER);\n}\n\nfunction ledgerPath(root: string): string {\n return savingsLedgerPath(root);\n}\n\n/** Whether a savings ledger exists for this repo (i.e. `vg serve --savings` has recorded). */\nexport function savingsRecorded(root: string): boolean {\n return fs.existsSync(ledgerPath(root));\n}\n\n/**\n * Delete the recorded usage data for this repo: the ledger itself plus the\n * stats-share state that indexes into it (a byte offset into the ledger and the\n * random per-install id) — a stale offset against a fresh ledger would silently\n * skip new entries, and clearing \"my data\" should also reset the id. Everything\n * removed lives under `.vibgrate/cache/`; nothing else is touched. Returns\n * whether a ledger existed.\n */\nexport function clearSavings(root: string): boolean {\n const file = ledgerPath(root);\n const existed = fs.existsSync(file);\n fs.rmSync(file, { force: true });\n fs.rmSync(path.join(cacheDir(root), 'stats-share.json'), { force: true });\n return existed;\n}\n\nexport function recordSaving(root: string, entry: Omit<SavingEntry, 'ts'>, now: number): void {\n try {\n fs.mkdirSync(cacheDir(root), { recursive: true });\n const line = JSON.stringify({ ts: now, ...entry });\n fs.appendFileSync(ledgerPath(root), line + '\\n');\n } catch {\n /* never let telemetry break a tool call */\n }\n}\n\nexport interface SavingsReport {\n enabled: boolean;\n days: number;\n queries: number;\n vgTokens: number;\n baselineTokens: number;\n ratio: number;\n estCostVg: number;\n estCostBaseline: number;\n saved: number;\n rateLabel: string;\n}\n\n// Published-style input rate ($/1M tokens), shipped with the CLI. Labelled\n// estimate; the user can pass their own model rate.\nconst DEFAULT_RATE_PER_M = 3.0; // e.g. a mid-tier model input rate\nconst DEFAULT_RATE_LABEL = 'input @ $3/1M';\n\nexport function readSavings(root: string, days: number, now: number, ratePerM = DEFAULT_RATE_PER_M): SavingsReport {\n const file = ledgerPath(root);\n const cutoff = now - days * 24 * 60 * 60 * 1000;\n let queries = 0;\n let vgTokens = 0;\n let baselineTokens = 0;\n if (fs.existsSync(file)) {\n for (const line of fs.readFileSync(file, 'utf8').split('\\n')) {\n if (!line.trim()) continue;\n try {\n const e = JSON.parse(line) as SavingEntry;\n if (e.ts < cutoff) continue;\n // The token-savings figures compare only the tools with a meaningful\n // grep/read baseline; the full per-command breakdown lives in readUsage.\n if (!SAVINGS_TOOLS.has(e.tool)) continue;\n queries++;\n vgTokens += e.vgTokens;\n baselineTokens += e.baselineTokens;\n } catch {\n /* skip corrupt line */\n }\n }\n }\n const estCostVg = (vgTokens / 1e6) * ratePerM;\n const estCostBaseline = (baselineTokens / 1e6) * ratePerM;\n return {\n enabled: savingsRecorded(root),\n days,\n queries,\n vgTokens,\n baselineTokens,\n ratio: vgTokens > 0 ? Math.round((baselineTokens / vgTokens) * 100) / 100 : 0,\n estCostVg: round2(estCostVg),\n estCostBaseline: round2(estCostBaseline),\n saved: round2(estCostBaseline - estCostVg),\n rateLabel: DEFAULT_RATE_LABEL,\n };\n}\n\nfunction round2(x: number): number {\n return Math.round(x * 100) / 100;\n}\n\n/** Token + cost savings attributed to one model (VG Code per-model auditing). */\nexport interface ModelSaving {\n /** `provider/model`, the ledger's per-model key. */\n key: string;\n provider: string;\n model: string;\n queries: number;\n vgTokens: number;\n baselineTokens: number;\n saved: number;\n}\n\n/**\n * Per-model breakdown of the token-savings figures — the basis of \"full savings\n * auditing per model\". Only entries that carry a `model` and are savings-baseline\n * tools contribute, so it lines up with the headline `readSavings` totals.\n * Sorted by dollars saved (desc), then key.\n */\nexport function readModelSavings(root: string, days: number, now: number, ratePerM = DEFAULT_RATE_PER_M): ModelSaving[] {\n const file = ledgerPath(root);\n const cutoff = now - days * 24 * 60 * 60 * 1000;\n const byModel = new Map<string, { provider: string; model: string; queries: number; vg: number; base: number }>();\n if (fs.existsSync(file)) {\n for (const line of fs.readFileSync(file, 'utf8').split('\\n')) {\n if (!line.trim()) continue;\n try {\n const e = JSON.parse(line) as SavingEntry;\n if (e.ts < cutoff || !e.model || !SAVINGS_TOOLS.has(e.tool)) continue;\n const provider = e.provider ?? 'unknown';\n const key = `${provider}/${e.model}`;\n const row = byModel.get(key) ?? { provider, model: e.model, queries: 0, vg: 0, base: 0 };\n row.queries++;\n row.vg += e.vgTokens;\n row.base += e.baselineTokens;\n byModel.set(key, row);\n } catch {\n /* skip corrupt line */\n }\n }\n }\n return [...byModel.entries()]\n .map(([key, r]) => ({\n key,\n provider: r.provider,\n model: r.model,\n queries: r.queries,\n vgTokens: r.vg,\n baselineTokens: r.base,\n saved: round2(((r.base - r.vg) / 1e6) * ratePerM),\n }))\n .sort((a, b) => b.saved - a.saved || a.key.localeCompare(b.key));\n}\n\n/** Per-command usage stats over the ledger window (all recorded tools). */\nexport interface CommandStat {\n tool: string;\n calls: number;\n complete: number;\n partial: number;\n miss: number;\n /** (complete + partial) / calls, as a whole-number percentage. */\n successPct: number;\n /** Mean wall time over the calls that recorded one; null when none did. */\n avgMs: number | null;\n}\n\n/** Calls attributed to one dimension value (a source, or a client). */\nexport interface DimensionStat {\n key: string;\n calls: number;\n complete: number;\n partial: number;\n miss: number;\n successPct: number;\n}\n\nexport interface UsageReport {\n enabled: boolean;\n days: number;\n /** One row per tool used, ordered by call count (desc), then name. */\n commands: CommandStat[];\n /** The command-vs-MCP split: calls grouped by `source` (`cli` / `mcp`). */\n sources: DimensionStat[];\n /** Which AI is calling: calls grouped by coarse `client` label. */\n clients: DimensionStat[];\n /** Column sums across all commands. */\n totals: { calls: number; complete: number; partial: number; miss: number };\n /** The mean of the per-command success percentages (each command weighted equally). */\n avgSuccessPct: number;\n}\n\ninterface OutcomeCounts {\n complete: number;\n partial: number;\n miss: number;\n}\n\n/** Turn a name→outcome-count map into sorted DimensionStat rows. */\nfunction toDimensionStats(byKey: Map<string, OutcomeCounts>): DimensionStat[] {\n return [...byKey.entries()]\n .map(([key, r]) => {\n const calls = r.complete + r.partial + r.miss;\n return {\n key,\n calls,\n complete: r.complete,\n partial: r.partial,\n miss: r.miss,\n successPct: calls ? Math.round(((r.complete + r.partial) / calls) * 100) : 0,\n };\n })\n .sort((a, b) => b.calls - a.calls || a.key.localeCompare(b.key));\n}\n\n/**\n * Per-command breakdown of recorded navigation calls: how often each tool was\n * used and how those calls resolved (complete / partial / miss), plus column\n * totals and the average success rate. Complements the token-savings summary —\n * this counts *every* recorded tool, not just the grep-baseline ones.\n */\nexport function readUsage(root: string, days: number, now: number): UsageReport {\n const file = ledgerPath(root);\n const cutoff = now - days * 24 * 60 * 60 * 1000;\n const byTool = new Map<string, OutcomeCounts>();\n const bySource = new Map<string, OutcomeCounts>();\n const byClient = new Map<string, OutcomeCounts>();\n // Per-tool timing over the entries that recorded a duration (older ledger\n // lines and CLI-sourced calls carry none — \"not measured\", never zero).\n const msByTool = new Map<string, { sum: number; n: number }>();\n const bump = (m: Map<string, OutcomeCounts>, key: string, outcome: Outcome): void => {\n const row = m.get(key) ?? { complete: 0, partial: 0, miss: 0 };\n row[outcome]++;\n m.set(key, row);\n };\n if (fs.existsSync(file)) {\n for (const line of fs.readFileSync(file, 'utf8').split('\\n')) {\n if (!line.trim()) continue;\n try {\n const e = JSON.parse(line) as SavingEntry;\n if (e.ts < cutoff) continue;\n const outcome: Outcome = e.outcome ?? 'complete';\n // Back-compat: lines written before these dims existed are MCP calls\n // from an unidentified client.\n bump(byTool, e.tool, outcome);\n bump(bySource, e.source ?? 'mcp', outcome);\n bump(byClient, e.client ?? 'unknown', outcome);\n if (typeof e.ms === 'number' && e.ms >= 0) {\n const timing = msByTool.get(e.tool) ?? { sum: 0, n: 0 };\n timing.sum += e.ms;\n timing.n++;\n msByTool.set(e.tool, timing);\n }\n } catch {\n /* skip corrupt line */\n }\n }\n }\n const commands: CommandStat[] = toDimensionStats(byTool).map((d) => {\n const timing = msByTool.get(d.key);\n return {\n tool: d.key,\n calls: d.calls,\n complete: d.complete,\n partial: d.partial,\n miss: d.miss,\n successPct: d.successPct,\n avgMs: timing && timing.n > 0 ? Math.round(timing.sum / timing.n) : null,\n };\n });\n const totals = commands.reduce(\n (t, c) => ({\n calls: t.calls + c.calls,\n complete: t.complete + c.complete,\n partial: t.partial + c.partial,\n miss: t.miss + c.miss,\n }),\n { calls: 0, complete: 0, partial: 0, miss: 0 },\n );\n const avgSuccessPct = commands.length\n ? Math.round(commands.reduce((s, c) => s + c.successPct, 0) / commands.length)\n : 0;\n return {\n enabled: savingsRecorded(root),\n days,\n commands,\n sources: toDimensionStats(bySource),\n clients: toDimensionStats(byClient),\n totals,\n avgSuccessPct,\n };\n}\n","/**\n * Graph-grounded context assembly for `vg code` (VG-CLI-CODE §3).\n *\n * A generic coding agent starts blind and reconstructs structure by grepping and\n * reading whole files — which is exactly what blows the context window and\n * degrades the model. This module instead uses the deterministic code graph to\n * hand the planner a *small, high-signal, budget-bounded* context: the symbols\n * most relevant to the instruction, their immediate relations, the blast radius\n * of changing them, and any declared facts (hard constraints) that must not be\n * dropped by later compaction. Deterministic given a graph + instruction, so it\n * is fully offline-testable and benchmarkable.\n */\n\nimport { conceptMapLines, extractLiteralNeedles, queryGraph } from '../engine/query.js';\nimport type { RelevanceAnalysis } from '../engine/relevance-provider.js';\nimport { indexFor } from '../engine/relations.js';\nimport { impactOf } from '../engine/impact.js';\nimport type { CodeContext } from './types.js';\nimport type { GraphNode, VgGraph } from '../schema.js';\nimport { userAskFromInstruction } from '../engine/user-ask.js';\n\nexport interface BuildContextOptions {\n /** Approx token budget for the rendered block (default 3000). */\n budget?: number;\n /** How many retrieval seeds to expand (default 8). */\n seeds?: number;\n /** Impact BFS depth for the blast radius (default 2). */\n impactDepth?: number;\n /** Restrict the edit surface to these files (from `--file`), if given. */\n files?: string[];\n /** Optional pre-computed relevance analysis (engine/relevance-provider.ts),\n * loaded by the async caller; widens seed vocabulary deterministically. */\n relevance?: RelevanceAnalysis | null;\n /** Optional per-node topic tags (engine/relevance-enrich.ts). */\n topicTags?: Map<string, readonly string[]> | null;\n /** The previous conversational ask (multi-turn `vg code`). Its content\n * terms join seed ranking at a damped weight so follow-ups (\"do we\n * support direct debits?\" after \"where is stripe used?\") stay anchored to\n * the conversation's topic. Absent → single-turn behaviour, unchanged. */\n priorInstruction?: string | null;\n}\n\n/**\n * Build the context block for a coding instruction. The ordering is\n * cache-stable by design (see router.ts): the invariant, repo-derived material\n * (facts, symbols, relations) comes first and the volatile instruction is\n * echoed last, so a provider's prompt cache can reuse the stable prefix across\n * turns.\n */\nexport function buildCodeContext(graph: VgGraph, instruction: string, options: BuildContextOptions = {}): CodeContext {\n const budget = options.budget ?? 3000;\n const seedLimit = options.seeds ?? 8;\n const impactDepth = options.impactDepth ?? 2;\n const index = indexFor(graph);\n\n // Hosts (VS Code panel) append a \"User attachments\" block with backticked\n // filenames/paths. Ranking and literal-locate pins must use only the user's\n // ask — otherwise `image.png` becomes a hard constraint that aborts the task.\n // The full instruction (with attachments) still goes in the Task section.\n const ask = userAskFromInstruction(instruction);\n const priorAsk = options.priorInstruction\n ? userAskFromInstruction(options.priorInstruction)\n : options.priorInstruction;\n\n // Retrieval seeds: reuse the deterministic lexical/structural retrieval that\n // backs `vg ask`. When `--file` narrows the surface, keep only seeds in those\n // files (but still let impact reach outside them, so the review is honest).\n // URL / quoted-string needles are stripped inside queryGraph so path tokens\n // cannot poison seeds (dash→dashboard, exist→NonExisting, …).\n const q = queryGraph(graph, ask, {\n budget: Math.floor(budget * 0.6),\n limit: seedLimit * 2,\n relevance: options.relevance,\n topicTags: options.topicTags,\n priorQuestion: priorAsk,\n });\n let seeds = q.matches.map((m) => ({ node: m.node, why: m.why }));\n if (options.files && options.files.length) {\n const set = new Set(options.files.map(normalize));\n const inScope = seeds.filter((s) => set.has(normalize(s.node.file)));\n // If nothing matched inside the named files, keep the best global seeds but\n // still steer target files to what the caller asked for.\n if (inScope.length) seeds = inScope;\n }\n seeds = seeds.slice(0, seedLimit);\n\n // Blast radius: who depends on the seeds. This is the impact-aware review\n // signal — an edit to a hub is riskier and the context says so.\n const impacted = new Map<string, { node: GraphNode; via: string }>();\n for (const s of seeds) {\n const impact = impactOf(graph, s.node.id, { depth: impactDepth });\n for (const item of impact.affected.slice(0, 6)) {\n const node = index.node(item.id);\n if (node && !impacted.has(node.id)) impacted.set(node.id, { node, via: s.node.qualifiedName });\n }\n }\n\n // Target files: the seed files (or the explicit --file set), stable order.\n const targetFiles = options.files?.length\n ? [...new Set(options.files.map(normalize))].sort()\n : [...new Set(seeds.map((s) => s.node.file))].sort();\n\n // Pinned facts: declared invariants/contracts that touch the seeds. These are\n // hard constraints; they are surfaced explicitly and never summarized away.\n const seedIds = new Set(seeds.map((s) => s.node.id));\n const pinnedFacts = [\n ...literalNeedleFacts(ask),\n ...pinnedFactsFor(graph, seedIds),\n ];\n\n const conceptMap = conceptMapLines(ask, options.relevance, priorAsk);\n const rendered = render(instruction, seeds, [...impacted.values()], targetFiles, pinnedFacts, conceptMap, index, budget);\n return {\n instruction,\n seeds,\n targetFiles,\n impacted: [...impacted.values()],\n pinnedFacts,\n conceptMap,\n rendered,\n tokensEstimate: estimateTokens(rendered),\n };\n}\n\n/** Pin URL / quoted needles so the agent does not treat path tokens as symbols. */\nfunction literalNeedleFacts(ask: string): string[] {\n const needles = extractLiteralNeedles(ask);\n if (!needles.length) return [];\n return needles.map(\n (n) =>\n `literal-locate: search the workspace for the exact string \\`${n}\\` (use search_code with the quoted needle). This is not a graph symbol name. If there are zero hits, report that honestly and finish — do not invent an edit.`,\n );\n}\n\nfunction pinnedFactsFor(graph: VgGraph, seedIds: Set<string>): string[] {\n if (!graph.facts?.length) return [];\n const out: string[] = [];\n for (const f of graph.facts) {\n if (f.kind === 'characterization') continue; // keep hard constraints only\n if (!f.subjectIds.some((id) => seedIds.has(id))) continue;\n const subjects = f.subjectIds\n .map((id) => graph.nodes.find((n) => n.id === id)?.qualifiedName ?? id)\n .join(', ');\n out.push(`${f.kind}: ${subjects} — ${JSON.stringify(f.predicate)}`);\n }\n return out.sort().slice(0, 12);\n}\n\nfunction render(\n instruction: string,\n seeds: { node: GraphNode; why: string }[],\n impacted: { node: GraphNode; via: string }[],\n targetFiles: string[],\n pinnedFacts: string[],\n conceptMap: string[],\n index: ReturnType<typeof indexFor>,\n budget: number,\n): string {\n const lines: string[] = [];\n lines.push('# Repository context (from the deterministic code graph)');\n lines.push('');\n\n if (pinnedFacts.length) {\n lines.push('## Hard constraints (do not violate)');\n for (const f of pinnedFacts) lines.push(`- ${f}`);\n lines.push('');\n }\n\n if (conceptMap.length) {\n lines.push('## How the ask was interpreted');\n for (const l of conceptMap) lines.push(l);\n lines.push('');\n }\n\n lines.push('## Relevant symbols');\n for (const { node, why } of seeds) {\n const block: string[] = [];\n block.push(`### ${node.qualifiedName} (${node.kind}, ${node.file}:${node.span.start}-${node.span.end})`);\n if (node.signature) block.push('`' + node.signature + '`');\n const callees = uniqueNames(index.callees(node.id).map((x) => x.node.qualifiedName)).slice(0, 6);\n const callers = uniqueNames(index.callers(node.id).map((x) => x.node.qualifiedName)).slice(0, 6);\n if (callees.length) block.push(`calls: ${callees.join(', ')}`);\n if (callers.length) block.push(`called by: ${callers.join(', ')}`);\n block.push(`importance ${node.importance.toFixed(3)}${node.isHub ? ' · hub (high blast radius)' : ''} · ${why}`);\n block.push('');\n const candidate = lines.concat(block).join('\\n');\n if (estimateTokens(candidate) > budget && lines.length > 3) break;\n lines.push(...block);\n }\n\n if (impacted.length) {\n lines.push('## Blast radius (would be affected by a change here)');\n for (const { node, via } of impacted.slice(0, 10)) {\n lines.push(`- ${node.qualifiedName} (${node.file}:${node.span.start}) — depends on ${via}`);\n }\n lines.push('');\n }\n\n lines.push('## Files in scope for this edit');\n for (const f of targetFiles) lines.push(`- ${f}`);\n lines.push('');\n\n lines.push('## Task');\n lines.push(instruction);\n return lines.join('\\n');\n}\n\nfunction uniqueNames(xs: string[]): string[] {\n return [...new Set(xs)];\n}\n\nfunction normalize(file: string): string {\n return file.replace(/\\\\/g, '/').replace(/^\\.\\//, '');\n}\n\nfunction estimateTokens(text: string): number {\n return Math.ceil(text.length / 4);\n}\n","/**\n * Source-bearing Task Capsule compiler (Fusion Runtime Phase 0).\n *\n * Today's {@link buildCodeContext} pays for graph metadata, then the model still\n * calls `read_file` — double payment. This module compiles a Task Capsule that\n * includes exact source ranges (from Tree-sitter spans already on graph nodes)\n * so the first inference can solve without navigation tool calls (ZNS@1 path).\n *\n * Deterministic given (graph, instruction, file contents, options). Injectable\n * `readFile` keeps unit tests offline and pure.\n *\n * Schema: docs/fusion/task-capsule-v0.schema.json\n */\n\nimport { queryGraph } from '../engine/query.js';\nimport { indexFor } from '../engine/relations.js';\nimport { impactOf } from '../engine/impact.js';\nimport { hashString } from '../engine/hash.js';\nimport type { GraphNode, VgGraph } from '../schema.js';\nimport type { CodeContext } from './types.js';\nimport { buildCodeContext, type BuildContextOptions } from './context.js';\n\nexport const TASK_CAPSULE_SCHEMA_VERSION = 'task-capsule/0' as const;\n/** Frozen ranking policy id — bump when the heuristic changes (benchmark gate). */\n/** Bumped 2026.07.1: strip URL/quoted needles from seed ranking (no path-token false positives). */\n/** Bumped 2026.08.1: term roles (weak process verbs never seed alone), concept/bigram\n * expansion (payments→stripe, \"direct debit\"→sepa/bacs/mandate), multi-term coverage\n * bonus, directory-segment evidence — gated by the ask-quality corpus (bench/ask-corpus.mjs). */\n/** Bumped 2026.08.2: optional relevance-provider seam — sanitized provider expansions\n * join term preparation (own 0..1 weight capped at EXPANSION_WEIGHT; weak-provenance\n * dropped); provider version recorded as `relevanceVersion` provenance. Absent\n * provider = 2026.08.1 behaviour exactly — gated by the same corpus, dual-mode. */\n/** Bumped 2026.08.3: multi-turn field report (\"do we support direct debits?\" after a\n * stripe ask seeded direct* distractors). (a) Tokens consumed by a fired bigram\n * concept are demoted to the weak role — \"direct\" corroborates, never seeds.\n * (b) Conversation carry-over: the previous ask's content terms join ranking at\n * CARRY_WEIGHT when the caller passes `priorInstruction`. (c) A plain-language\n * \"how the ask was interpreted\" concept map is rendered for small local models.\n * No prior instruction + no bigram ask = 2026.08.2 behaviour exactly. */\nexport const CAPSULE_RANKING_VERSION = 'capsule-rank@2026.08.3' as const;\nexport const CAPSULE_COMPILER_ID = 'vg-task-capsule/0' as const;\n\nexport interface BuildCapsuleOptions extends BuildContextOptions {\n /**\n * Read file contents relative to the repository root. Required for source\n * slices; when omitted, the capsule still builds metadata + empty slices\n * (useful for schema/shape tests).\n */\n readFile?: (relativePath: string) => string | null;\n /** Extra lines of context around each symbol span (default 1). */\n padding?: number;\n /** Max source slices after merge (default 12). */\n maxSlices?: number;\n repositoryId?: string | null;\n /** Optional provenance from the Model Execution Profile / security ladder. */\n provenance?: CapsuleProvenanceExtras;\n /**\n * Extra pinned facts (e.g. high-confidence federation bridge edges) appended\n * after graph-derived facts. Secret-free, short strings only.\n */\n extraPinnedFacts?: string[];\n}\n\nexport interface CapsuleSymbolRef {\n id: string;\n qualifiedName: string;\n kind: string;\n file: string;\n span: { start: number; end: number };\n signature?: string | null;\n why: string;\n importance: number;\n}\n\nexport interface SourceSlice {\n file: string;\n start: number;\n end: number;\n content: string;\n contentHash: string;\n symbolIds: string[];\n}\n\nexport interface CapsuleRelationship {\n kind: 'calls' | 'called-by' | 'impacts' | 'contains' | 'other';\n from: string;\n to: string;\n}\n\nexport interface VerificationPlan {\n syntaxFiles: string[];\n suggestedTests: string[];\n notes: string[];\n}\n\nexport interface TaskCapsule {\n schemaVersion: typeof TASK_CAPSULE_SCHEMA_VERSION;\n instruction: string;\n primary: CapsuleSymbolRef[];\n supporting: CapsuleSymbolRef[];\n sourceSlices: SourceSlice[];\n relationships: CapsuleRelationship[];\n pinnedFacts: string[];\n /** Plain-language interpretation of the ask (concept expansions, relevance\n * topics, carried prior-turn terms) — see engine/query.ts conceptMapLines. */\n conceptMap: string[];\n targetFiles: string[];\n verificationPlan: VerificationPlan;\n rendered: string;\n tokensEstimate: number;\n provenance: {\n compiler: string;\n rankingVersion: string;\n graphCorpusHash: string | null;\n repositoryId: string | null;\n /** Model Execution Profile id when resolved (Fusion Phase 4/7). */\n modelProfileId?: string | null;\n /** Security tier for shell during this task. */\n securityTier?: string | null;\n /** Frozen policy / ranking patch id if any. */\n policyVersion?: string | null;\n /** Version of the optional relevance provider that widened seed\n * vocabulary for this capsule, or null when none was active. */\n relevanceVersion?: string | null;\n };\n}\n\nexport interface CapsuleProvenanceExtras {\n modelProfileId?: string | null;\n securityTier?: string | null;\n policyVersion?: string | null;\n}\n\n/** Host-safe capsule summary for VS Code / stream-json capsule transparency. */\nexport interface CapsuleSummary {\n schemaVersion: string;\n instruction: string;\n primary: Array<{ qualifiedName: string; file: string; kind: string }>;\n supporting: Array<{ qualifiedName: string; file: string; kind: string }>;\n sourceSliceCount: number;\n sourceFiles: string[];\n tokensEstimate: number;\n rankingVersion: string;\n /** Truncated rendered capsule for display (not the full prompt dump). */\n preview: string;\n}\n\n/** Host-safe capsule summary (capsule transparency UI / stream-json). */\nexport function summarizeCapsule(capsule: TaskCapsule): CapsuleSummary {\n const sourceFiles = [...new Set(capsule.sourceSlices.map((s) => s.file))].sort();\n const preview = capsule.rendered.length > 4000 ? `${capsule.rendered.slice(0, 4000)}\\n… (truncated)` : capsule.rendered;\n return {\n schemaVersion: capsule.schemaVersion,\n instruction: capsule.instruction,\n primary: capsule.primary.map((p) => ({ qualifiedName: p.qualifiedName, file: p.file, kind: p.kind })),\n supporting: capsule.supporting.map((p) => ({ qualifiedName: p.qualifiedName, file: p.file, kind: p.kind })),\n sourceSliceCount: capsule.sourceSlices.length,\n sourceFiles,\n tokensEstimate: capsule.tokensEstimate,\n rankingVersion: capsule.provenance.rankingVersion,\n preview,\n };\n}\n\n/**\n * Compile a source-bearing Task Capsule. Reuses the same seed / impact /\n * fact-pinning path as {@link buildCodeContext}, then attaches exact source\n * slices and a verification sketch.\n */\nexport function buildTaskCapsule(graph: VgGraph, instruction: string, options: BuildCapsuleOptions = {}): TaskCapsule {\n const base = buildCodeContext(graph, instruction, options);\n const padding = options.padding ?? 1;\n const maxSlices = options.maxSlices ?? 12;\n const budget = options.budget ?? 3000;\n const index = indexFor(graph);\n\n const primary = base.seeds.map((s) => toRef(s.node, s.why));\n const primaryIds = new Set(primary.map((p) => p.id));\n\n const supporting: CapsuleSymbolRef[] = [];\n for (const { node, via } of base.impacted) {\n if (primaryIds.has(node.id)) continue;\n supporting.push(toRef(node, `depends on ${via}`));\n }\n\n const relationships = collectRelationships(base, index);\n const sourceSlices = options.readFile\n ? buildSourceSlices(\n [...base.seeds.map((s) => s.node), ...base.impacted.map((i) => i.node)],\n options.readFile,\n padding,\n maxSlices,\n )\n : [];\n\n const extraFacts = (options.extraPinnedFacts ?? []).filter((f) => typeof f === 'string' && f.trim());\n const pinnedFacts = [...base.pinnedFacts, ...extraFacts];\n const verificationPlan = buildVerificationPlan(graph, base);\n const rendered = renderCapsule(instruction, primary, supporting, sourceSlices, pinnedFacts, base.conceptMap, base.targetFiles, verificationPlan, relationships, budget);\n\n return {\n schemaVersion: TASK_CAPSULE_SCHEMA_VERSION,\n instruction,\n primary,\n supporting,\n sourceSlices,\n relationships,\n pinnedFacts,\n conceptMap: base.conceptMap,\n targetFiles: base.targetFiles,\n verificationPlan,\n rendered,\n tokensEstimate: estimateTokens(rendered),\n provenance: {\n compiler: CAPSULE_COMPILER_ID,\n rankingVersion: CAPSULE_RANKING_VERSION,\n graphCorpusHash: graph.provenance?.corpusHash ?? null,\n repositoryId: options.repositoryId ?? null,\n modelProfileId: options.provenance?.modelProfileId ?? null,\n securityTier: options.provenance?.securityTier ?? null,\n policyVersion: options.provenance?.policyVersion ?? null,\n relevanceVersion: options.relevance?.version ?? null,\n },\n };\n}\n\n/**\n * Project a capsule into the legacy {@link CodeContext} shape so the existing\n * agent prompt path can consume it without a full rewrite (A/B flag).\n */\nexport function capsuleToCodeContext(capsule: TaskCapsule): CodeContext {\n return {\n instruction: capsule.instruction,\n seeds: capsule.primary.map((p) => ({\n node: {\n id: p.id,\n qualifiedName: p.qualifiedName,\n kind: p.kind,\n file: p.file,\n span: p.span,\n signature: p.signature ?? undefined,\n importance: p.importance,\n } as GraphNode,\n why: p.why,\n })),\n targetFiles: capsule.targetFiles,\n conceptMap: capsule.conceptMap,\n impacted: capsule.supporting.map((s) => ({\n node: {\n id: s.id,\n qualifiedName: s.qualifiedName,\n kind: s.kind,\n file: s.file,\n span: s.span,\n signature: s.signature ?? undefined,\n importance: s.importance,\n } as GraphNode,\n via: s.why.replace(/^depends on /, ''),\n })),\n pinnedFacts: capsule.pinnedFacts,\n rendered: capsule.rendered,\n tokensEstimate: capsule.tokensEstimate,\n };\n}\n\nfunction toRef(node: GraphNode, why: string): CapsuleSymbolRef {\n return {\n id: node.id,\n qualifiedName: node.qualifiedName,\n kind: node.kind,\n file: normalize(node.file),\n span: { start: node.span.start, end: node.span.end },\n signature: node.signature ?? null,\n why,\n importance: node.importance,\n };\n}\n\nfunction collectRelationships(\n base: CodeContext,\n index: ReturnType<typeof indexFor>,\n): CapsuleRelationship[] {\n const out: CapsuleRelationship[] = [];\n const seen = new Set<string>();\n const push = (kind: CapsuleRelationship['kind'], from: string, to: string) => {\n const key = `${kind}|${from}|${to}`;\n if (seen.has(key)) return;\n seen.add(key);\n out.push({ kind, from, to });\n };\n\n for (const { node } of base.seeds) {\n for (const c of index.callees(node.id).slice(0, 6)) {\n push('calls', node.qualifiedName, c.node.qualifiedName);\n }\n for (const c of index.callers(node.id).slice(0, 6)) {\n push('called-by', node.qualifiedName, c.node.qualifiedName);\n }\n }\n for (const { node, via } of base.impacted.slice(0, 10)) {\n push('impacts', via, node.qualifiedName);\n }\n\n // Stable order for determinism.\n return out.sort((a, b) => a.kind.localeCompare(b.kind) || a.from.localeCompare(b.from) || a.to.localeCompare(b.to));\n}\n\nfunction buildSourceSlices(\n nodes: GraphNode[],\n readFile: (relativePath: string) => string | null,\n padding: number,\n maxSlices: number,\n): SourceSlice[] {\n // Prefer concrete symbols over file/module containers for source evidence.\n const eligible = nodes.filter((n) => !['file', 'module', 'package'].includes(n.kind));\n const byFile = new Map<string, GraphNode[]>();\n for (const n of eligible) {\n const file = normalize(n.file);\n const list = byFile.get(file) ?? [];\n list.push(n);\n byFile.set(file, list);\n }\n\n type Range = { file: string; start: number; end: number; symbolIds: string[]; score: number };\n const ranges: Range[] = [];\n\n for (const [file, fileNodes] of [...byFile.entries()].sort(([a], [b]) => a.localeCompare(b))) {\n const sorted = [...fileNodes].sort((a, b) => a.span.start - b.span.start || b.importance - a.importance);\n let current: Range | null = null;\n for (const n of sorted) {\n const start = Math.max(1, n.span.start - padding);\n const end = n.span.end + padding;\n const score = n.importance + (n.isHub ? 0.25 : 0);\n if (current && current.file === file && start <= current.end + 2) {\n current.end = Math.max(current.end, end);\n current.symbolIds.push(n.id);\n current.score = Math.max(current.score, score);\n } else {\n if (current) ranges.push(current);\n current = { file, start, end, symbolIds: [n.id], score };\n }\n }\n if (current) ranges.push(current);\n }\n\n ranges.sort((a, b) => b.score - a.score || a.file.localeCompare(b.file) || a.start - b.start);\n\n const slices: SourceSlice[] = [];\n for (const range of ranges) {\n if (slices.length >= maxSlices) break;\n const raw = readFile(range.file);\n if (raw === null) continue;\n const lines = raw.split('\\n');\n const start = Math.min(range.start, lines.length);\n const end = Math.min(range.end, lines.length);\n if (start < 1 || end < start) continue;\n const content = lines.slice(start - 1, end).join('\\n');\n slices.push({\n file: range.file,\n start,\n end,\n content,\n contentHash: hashString(content),\n symbolIds: [...new Set(range.symbolIds)].sort(),\n });\n }\n\n // Stable final order: file then start line (score only used for selection).\n return slices.sort((a, b) => a.file.localeCompare(b.file) || a.start - b.start);\n}\n\nfunction buildVerificationPlan(graph: VgGraph, base: CodeContext): VerificationPlan {\n const syntaxFiles = [...base.targetFiles].sort();\n const seedIds = new Set(base.seeds.map((s) => s.node.id));\n const suggestedTests: string[] = [];\n\n for (const n of graph.nodes) {\n if (n.kind !== 'test') continue;\n // Prefer tests that share a file with seeds or whose name mentions a seed.\n const sameFile = base.seeds.some((s) => normalize(s.node.file) === normalize(n.file));\n const nameHit = base.seeds.some((s) => n.qualifiedName.toLowerCase().includes(s.node.name.toLowerCase()));\n if (sameFile || nameHit || seedIds.has(n.id)) {\n suggestedTests.push(n.qualifiedName);\n }\n }\n suggestedTests.sort();\n\n const notes: string[] = [];\n if (!suggestedTests.length) {\n notes.push('No graph-linked tests found for seed symbols; run the nearest project test command after apply.');\n }\n if (base.impacted.some((i) => i.node.isHub || i.node.importance >= 0.7)) {\n notes.push('High-importance dependents in blast radius — prefer targeted tests before a full build.');\n }\n\n return {\n syntaxFiles,\n suggestedTests: suggestedTests.slice(0, 12),\n notes,\n };\n}\n\nfunction renderCapsule(\n instruction: string,\n primary: CapsuleSymbolRef[],\n supporting: CapsuleSymbolRef[],\n slices: SourceSlice[],\n pinnedFacts: string[],\n conceptMap: string[],\n targetFiles: string[],\n verification: VerificationPlan,\n relationships: CapsuleRelationship[],\n budget: number,\n): string {\n const lines: string[] = [];\n lines.push('# Task capsule (source-bearing, from the deterministic code graph)');\n lines.push('');\n lines.push('Use the exact source evidence below. Search or read outside it only if this capsule is insufficient.');\n lines.push('');\n\n if (pinnedFacts.length) {\n lines.push('## Hard constraints (do not violate)');\n for (const f of pinnedFacts) lines.push(`- ${f}`);\n lines.push('');\n }\n\n // Rendered before the symbol list on purpose: a small local model reads the\n // interpretation first, so the `a→b` provenance slugs on each seed line are\n // decodable instead of noise.\n if (conceptMap.length) {\n lines.push('## How the ask was interpreted');\n for (const l of conceptMap) lines.push(l);\n lines.push('');\n }\n\n lines.push('## Primary symbols');\n for (const s of primary) {\n lines.push(`- ${s.qualifiedName} (${s.kind}, ${s.file}:${s.span.start}-${s.span.end})${s.signature ? ` — \\`${s.signature}\\`` : ''} — ${s.why}`);\n }\n lines.push('');\n\n if (supporting.length) {\n lines.push('## Supporting / blast radius');\n for (const s of supporting.slice(0, 10)) {\n lines.push(`- ${s.qualifiedName} (${s.file}:${s.span.start}) — ${s.why}`);\n }\n lines.push('');\n }\n\n if (relationships.length) {\n lines.push('## Relationships');\n for (const r of relationships.slice(0, 24)) {\n lines.push(`- ${r.kind}: ${r.from} → ${r.to}`);\n }\n lines.push('');\n }\n\n lines.push('## Exact source evidence');\n if (!slices.length) {\n lines.push('_No source slices available (file reader missing or spans unreadable)._');\n lines.push('');\n } else {\n let included = 0;\n for (const slice of slices) {\n const block = [\n `### ${slice.file}:${slice.start}-${slice.end}`,\n `\\`\\`\\`${langFor(slice.file)}`,\n slice.content,\n '```',\n '',\n ];\n const candidate = [...lines, ...block, '## Task', instruction].join('\\n');\n if (estimateTokens(candidate) > budget && included > 0) break;\n lines.push(...block);\n included += 1;\n }\n }\n\n lines.push('## Files in scope');\n for (const f of targetFiles) lines.push(`- ${f}`);\n lines.push('');\n\n lines.push('## Verification plan');\n for (const f of verification.syntaxFiles) lines.push(`- syntax: ${f}`);\n for (const t of verification.suggestedTests) lines.push(`- test: ${t}`);\n for (const n of verification.notes) lines.push(`- note: ${n}`);\n lines.push('');\n\n lines.push('## Task');\n lines.push(instruction);\n return lines.join('\\n');\n}\n\nfunction langFor(file: string): string {\n const ext = file.split('.').pop()?.toLowerCase() ?? '';\n const map: Record<string, string> = {\n ts: 'ts',\n tsx: 'tsx',\n js: 'js',\n jsx: 'jsx',\n mjs: 'js',\n cjs: 'js',\n py: 'python',\n rs: 'rust',\n go: 'go',\n java: 'java',\n cs: 'csharp',\n md: 'md',\n json: 'json',\n };\n return map[ext] ?? '';\n}\n\nfunction normalize(file: string): string {\n return file.replace(/\\\\/g, '/').replace(/^\\.\\//, '');\n}\n\nfunction estimateTokens(text: string): number {\n return Math.ceil(text.length / 4);\n}\n\n// Re-export query touch so tree-shaking keeps the dependency explicit for tests.\nexport const __testing = { queryGraph, impactOf };\n"]}
1
+ {"version":3,"sources":["../src/engine/savings.ts","../src/code/context.ts","../src/code/caps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WAAW,CAAA;AACtB,EAAA,OAAO,KAAA,CAAM,KAAK,IAAI,CAAA;AACxB;AAEA,SAAS,QAAQ,IAAA,EAAsB;AACrC,EAAA,MAAM,GAAA,GAAM,KAAK,KAAA,CAAM,GAAG,EAAE,GAAA,EAAI,EAAG,aAAY,IAAK,EAAA;AACpD,EAAA,MAAM,GAAA,GAA8B;AAAA,IAClC,EAAA,EAAI,IAAA;AAAA,IACJ,GAAA,EAAK,KAAA;AAAA,IACL,EAAA,EAAI,IAAA;AAAA,IACJ,GAAA,EAAK,KAAA;AAAA,IACL,GAAA,EAAK,IAAA;AAAA,IACL,GAAA,EAAK,IAAA;AAAA,IACL,EAAA,EAAI,QAAA;AAAA,IACJ,EAAA,EAAI,MAAA;AAAA,IACJ,EAAA,EAAI,IAAA;AAAA,IACJ,IAAA,EAAM,MAAA;AAAA,IACN,EAAA,EAAI,QAAA;AAAA,IACJ,EAAA,EAAI,IAAA;AAAA,IACJ,IAAA,EAAM;AAAA,GACR;AACA,EAAA,OAAO,GAAA,CAAI,GAAG,CAAA,IAAK,EAAA;AACrB;AAEA,SAASC,WAAU,IAAA,EAAsB;AACvC,EAAA,OAAO,KAAK,OAAA,CAAQ,KAAA,EAAO,GAAG,CAAA,CAAE,OAAA,CAAQ,SAAS,EAAE,CAAA;AACrD;AAEA,SAASD,gBAAe,IAAA,EAAsB;AAC5C,EAAA,OAAO,IAAA,CAAK,IAAA,CAAK,IAAA,CAAK,MAAA,GAAS,CAAC,CAAA;AAClC","file":"chunk-5O6O7DJH.js","sourcesContent":["import * as fs from 'node:fs';\nimport * as path from 'node:path';\nimport { cacheDir } from './cache.js';\n\n/**\n * Usage-savings tracking (VG-DEVELOPMENT-PLAN §5) — local, privacy-safe, and\n * **opt-in**. We record *counts only* — never code, never the question text —\n * comparing the context tokens vg returned against a grep/read baseline estimate.\n * `vg savings` reports it with the assumptions shown; figures are labelled\n * estimates, never a hero number.\n *\n * Each entry also carries which path served the call (`source`: an MCP tool call\n * vs a `vg <subcommand>` CLI invocation) and, when known, a coarse `client` label\n * (the AI on the other end). That powers the command-vs-MCP split and the\n * per-client breakdown in `vg savings`, and is the basis for the opt-in\n * `vg serve --share-stats` upload (see ./stats-share.ts). Nothing here leaves the\n * machine unless the operator explicitly enables sharing.\n */\n\nconst LEDGER = 'savings.jsonl';\n// A conservative, documented estimate: tokens an agent reads per file it opens.\nexport const PER_FILE_TOKENS = 400;\n\n/** The tools whose grep/read token baseline the savings summary is computed from.\n * search_symbols belongs here: it is the direct grep replacement (the server\n * instructions steer agents to it INSTEAD of grep), yet it used to contribute\n * zero to the estimate — on search-heavy sessions most of the real saving went\n * uncounted. Its baseline is the same measure as query_graph's: the distinct\n * files its matches point at, at PER_FILE_TOKENS each. */\nexport const SAVINGS_TOOLS = new Set(['query_graph', 'get_node', 'search_symbols']);\n\n/**\n * How a navigation call reached the map:\n * - `mcp` — a tool call over the local `vg serve` MCP server;\n * - `cli` — a `vg <subcommand>` invocation that identified itself with `--client`.\n * Both are recorded into one ledger under a shared tool vocabulary (CLI\n * subcommands are normalised to their MCP tool names via CLI_TOOL_ALIASES), so\n * `(tool, source)` is the command-vs-MCP split and the token math stays unified.\n * Absent on ledger lines written before sources existed → read as `mcp` (the\n * only path that recorded then).\n */\nexport type Source = 'mcp' | 'cli';\n\n/**\n * Canonical tool name a CLI navigation subcommand maps to — the same vocabulary\n * the MCP tools use, so a `vg ask --client=claude` and an MCP `query_graph` call\n * land on one row distinguished only by `source`. A subcommand with no MCP twin\n * (e.g. `tree`) keeps its own name.\n */\nexport const CLI_TOOL_ALIASES: Readonly<Record<string, string>> = {\n ask: 'query_graph',\n show: 'get_node',\n impact: 'impact_of',\n path: 'find_path',\n hubs: 'list_hubs',\n areas: 'list_areas',\n tree: 'tree',\n};\n\n/**\n * Normalise a free-form client name (from `--client` or the MCP `initialize`\n * handshake) to a short, bounded, non-PII token: lowercase, `[a-z0-9._-]` only,\n * ≤ 40 chars. Never carries arbitrary user input into the ledger or an upload —\n * it is a coarse client label (e.g. `claude`, `cursor`, `cline`), not identity.\n * Returns `'unknown'` when nothing usable is provided.\n */\nexport function sanitizeClient(name: string | undefined | null): string {\n if (typeof name !== 'string') return 'unknown';\n const cleaned = name\n .trim()\n .toLowerCase()\n .replace(/[^a-z0-9._-]+/g, '-')\n .replace(/^-+|-+$/g, '')\n .slice(0, 40);\n return cleaned || 'unknown';\n}\n\n/**\n * Outcome of a recorded navigation call:\n * - `complete` — returned results, with nothing capped or paginated;\n * - `partial` — returned results, but more were available/truncated;\n * - `miss` — returned no result (no match, not-found, not-connected).\n */\nexport type Outcome = 'complete' | 'partial' | 'miss';\n\nexport interface SavingEntry {\n ts: number; // epoch ms (runtime ledger state, not part of any artifact)\n tool: string;\n // Optional for back-compat with ledger lines written before outcomes existed;\n // an absent value is read as `complete` (those lines only recorded hits).\n outcome?: Outcome;\n vgTokens: number;\n baselineTokens: number;\n // Optional for back-compat: absent `source` reads as `mcp`. `client` is a\n // sanitized coarse label (see sanitizeClient) or absent when unidentified.\n source?: Source;\n client?: string;\n // The model that made the call, for per-model savings auditing. `provider` is\n // a coarse provider label (e.g. `anthropic`, `ollama`), `model` the sanitized\n // model slug. VG Code sets both so `vg savings` can break usage down per model.\n // Absent on lines from callers that don't identify a model.\n provider?: string;\n model?: string;\n // Wall time of the call, ms. Optional: absent on lines written before timing\n // existed (and on CLI-sourced lines) — absent means \"not measured\", never 0.\n ms?: number;\n}\n\n/**\n * Normalise a model slug to a bounded, non-PII token — like {@link sanitizeClient}\n * but keeping the `/` and `:` that model ids use (`anthropic/claude-3.5-sonnet`,\n * `qwen2.5-coder:7b`). Returns undefined when nothing usable is given.\n */\nexport function sanitizeModelId(name: string | undefined | null): string | undefined {\n if (typeof name !== 'string') return undefined;\n const cleaned = name\n .trim()\n .toLowerCase()\n .replace(/[^a-z0-9._:/-]+/g, '-')\n .replace(/^-+|-+$/g, '')\n .slice(0, 60);\n return cleaned || undefined;\n}\n\n/**\n * Record a CLI navigation call (`vg <subcommand> --client=<ai>`) into the same\n * local ledger the MCP path uses. Only ever called when the caller passed\n * `--client` — i.e. an AI host explicitly identified itself — so a human's bare\n * `vg ask` still records nothing. Counts only; never the question or code.\n */\nexport function recordCliCall(\n root: string,\n entry: { tool: string; client?: string; provider?: string; model?: string; outcome: Outcome; vgTokens?: number; baselineFiles?: number },\n now: number,\n): void {\n recordSaving(\n root,\n {\n tool: entry.tool,\n source: 'cli',\n client: sanitizeClient(entry.client),\n provider: entry.provider ? sanitizeClient(entry.provider) : undefined,\n model: sanitizeModelId(entry.model),\n outcome: entry.outcome,\n vgTokens: entry.vgTokens ?? 0,\n baselineTokens: (entry.baselineFiles ?? 0) * PER_FILE_TOKENS,\n },\n now,\n );\n}\n\n/**\n * Absolute path of the local usage ledger for this repo. Exported so the serve\n * status display can tail it live (mcp/ledger-tail.ts) — the file itself stays\n * local-only (GUARDRAILS §3.4; upload is the separate opt-in stats-share path).\n */\nexport function savingsLedgerPath(root: string): string {\n return path.join(cacheDir(root), LEDGER);\n}\n\nfunction ledgerPath(root: string): string {\n return savingsLedgerPath(root);\n}\n\n/** Whether a savings ledger exists for this repo (i.e. `vg serve --savings` has recorded). */\nexport function savingsRecorded(root: string): boolean {\n return fs.existsSync(ledgerPath(root));\n}\n\n/**\n * Delete the recorded usage data for this repo: the ledger itself plus the\n * stats-share state that indexes into it (a byte offset into the ledger and the\n * random per-install id) — a stale offset against a fresh ledger would silently\n * skip new entries, and clearing \"my data\" should also reset the id. Everything\n * removed lives under `.vibgrate/cache/`; nothing else is touched. Returns\n * whether a ledger existed.\n */\nexport function clearSavings(root: string): boolean {\n const file = ledgerPath(root);\n const existed = fs.existsSync(file);\n fs.rmSync(file, { force: true });\n fs.rmSync(path.join(cacheDir(root), 'stats-share.json'), { force: true });\n return existed;\n}\n\nexport function recordSaving(root: string, entry: Omit<SavingEntry, 'ts'>, now: number): void {\n try {\n fs.mkdirSync(cacheDir(root), { recursive: true });\n const line = JSON.stringify({ ts: now, ...entry });\n fs.appendFileSync(ledgerPath(root), line + '\\n');\n } catch {\n /* never let telemetry break a tool call */\n }\n}\n\nexport interface SavingsReport {\n enabled: boolean;\n days: number;\n queries: number;\n vgTokens: number;\n baselineTokens: number;\n ratio: number;\n estCostVg: number;\n estCostBaseline: number;\n saved: number;\n rateLabel: string;\n}\n\n// Published-style input rate ($/1M tokens), shipped with the CLI. Labelled\n// estimate; the user can pass their own model rate.\nconst DEFAULT_RATE_PER_M = 3.0; // e.g. a mid-tier model input rate\nconst DEFAULT_RATE_LABEL = 'input @ $3/1M';\n\nexport function readSavings(root: string, days: number, now: number, ratePerM = DEFAULT_RATE_PER_M): SavingsReport {\n const file = ledgerPath(root);\n const cutoff = now - days * 24 * 60 * 60 * 1000;\n let queries = 0;\n let vgTokens = 0;\n let baselineTokens = 0;\n if (fs.existsSync(file)) {\n for (const line of fs.readFileSync(file, 'utf8').split('\\n')) {\n if (!line.trim()) continue;\n try {\n const e = JSON.parse(line) as SavingEntry;\n if (e.ts < cutoff) continue;\n // The token-savings figures compare only the tools with a meaningful\n // grep/read baseline; the full per-command breakdown lives in readUsage.\n if (!SAVINGS_TOOLS.has(e.tool)) continue;\n queries++;\n vgTokens += e.vgTokens;\n baselineTokens += e.baselineTokens;\n } catch {\n /* skip corrupt line */\n }\n }\n }\n const estCostVg = (vgTokens / 1e6) * ratePerM;\n const estCostBaseline = (baselineTokens / 1e6) * ratePerM;\n return {\n enabled: savingsRecorded(root),\n days,\n queries,\n vgTokens,\n baselineTokens,\n ratio: vgTokens > 0 ? Math.round((baselineTokens / vgTokens) * 100) / 100 : 0,\n estCostVg: round2(estCostVg),\n estCostBaseline: round2(estCostBaseline),\n saved: round2(estCostBaseline - estCostVg),\n rateLabel: DEFAULT_RATE_LABEL,\n };\n}\n\nfunction round2(x: number): number {\n return Math.round(x * 100) / 100;\n}\n\n/** Token + cost savings attributed to one model (VG Code per-model auditing). */\nexport interface ModelSaving {\n /** `provider/model`, the ledger's per-model key. */\n key: string;\n provider: string;\n model: string;\n queries: number;\n vgTokens: number;\n baselineTokens: number;\n saved: number;\n}\n\n/**\n * Per-model breakdown of the token-savings figures — the basis of \"full savings\n * auditing per model\". Only entries that carry a `model` and are savings-baseline\n * tools contribute, so it lines up with the headline `readSavings` totals.\n * Sorted by dollars saved (desc), then key.\n */\nexport function readModelSavings(root: string, days: number, now: number, ratePerM = DEFAULT_RATE_PER_M): ModelSaving[] {\n const file = ledgerPath(root);\n const cutoff = now - days * 24 * 60 * 60 * 1000;\n const byModel = new Map<string, { provider: string; model: string; queries: number; vg: number; base: number }>();\n if (fs.existsSync(file)) {\n for (const line of fs.readFileSync(file, 'utf8').split('\\n')) {\n if (!line.trim()) continue;\n try {\n const e = JSON.parse(line) as SavingEntry;\n if (e.ts < cutoff || !e.model || !SAVINGS_TOOLS.has(e.tool)) continue;\n const provider = e.provider ?? 'unknown';\n const key = `${provider}/${e.model}`;\n const row = byModel.get(key) ?? { provider, model: e.model, queries: 0, vg: 0, base: 0 };\n row.queries++;\n row.vg += e.vgTokens;\n row.base += e.baselineTokens;\n byModel.set(key, row);\n } catch {\n /* skip corrupt line */\n }\n }\n }\n return [...byModel.entries()]\n .map(([key, r]) => ({\n key,\n provider: r.provider,\n model: r.model,\n queries: r.queries,\n vgTokens: r.vg,\n baselineTokens: r.base,\n saved: round2(((r.base - r.vg) / 1e6) * ratePerM),\n }))\n .sort((a, b) => b.saved - a.saved || a.key.localeCompare(b.key));\n}\n\n/** Per-command usage stats over the ledger window (all recorded tools). */\nexport interface CommandStat {\n tool: string;\n calls: number;\n complete: number;\n partial: number;\n miss: number;\n /** (complete + partial) / calls, as a whole-number percentage. */\n successPct: number;\n /** Mean wall time over the calls that recorded one; null when none did. */\n avgMs: number | null;\n}\n\n/** Calls attributed to one dimension value (a source, or a client). */\nexport interface DimensionStat {\n key: string;\n calls: number;\n complete: number;\n partial: number;\n miss: number;\n successPct: number;\n}\n\nexport interface UsageReport {\n enabled: boolean;\n days: number;\n /** One row per tool used, ordered by call count (desc), then name. */\n commands: CommandStat[];\n /** The command-vs-MCP split: calls grouped by `source` (`cli` / `mcp`). */\n sources: DimensionStat[];\n /** Which AI is calling: calls grouped by coarse `client` label. */\n clients: DimensionStat[];\n /** Column sums across all commands. */\n totals: { calls: number; complete: number; partial: number; miss: number };\n /** The mean of the per-command success percentages (each command weighted equally). */\n avgSuccessPct: number;\n}\n\ninterface OutcomeCounts {\n complete: number;\n partial: number;\n miss: number;\n}\n\n/** Turn a name→outcome-count map into sorted DimensionStat rows. */\nfunction toDimensionStats(byKey: Map<string, OutcomeCounts>): DimensionStat[] {\n return [...byKey.entries()]\n .map(([key, r]) => {\n const calls = r.complete + r.partial + r.miss;\n return {\n key,\n calls,\n complete: r.complete,\n partial: r.partial,\n miss: r.miss,\n successPct: calls ? Math.round(((r.complete + r.partial) / calls) * 100) : 0,\n };\n })\n .sort((a, b) => b.calls - a.calls || a.key.localeCompare(b.key));\n}\n\n/**\n * Per-command breakdown of recorded navigation calls: how often each tool was\n * used and how those calls resolved (complete / partial / miss), plus column\n * totals and the average success rate. Complements the token-savings summary —\n * this counts *every* recorded tool, not just the grep-baseline ones.\n */\nexport function readUsage(root: string, days: number, now: number): UsageReport {\n const file = ledgerPath(root);\n const cutoff = now - days * 24 * 60 * 60 * 1000;\n const byTool = new Map<string, OutcomeCounts>();\n const bySource = new Map<string, OutcomeCounts>();\n const byClient = new Map<string, OutcomeCounts>();\n // Per-tool timing over the entries that recorded a duration (older ledger\n // lines and CLI-sourced calls carry none — \"not measured\", never zero).\n const msByTool = new Map<string, { sum: number; n: number }>();\n const bump = (m: Map<string, OutcomeCounts>, key: string, outcome: Outcome): void => {\n const row = m.get(key) ?? { complete: 0, partial: 0, miss: 0 };\n row[outcome]++;\n m.set(key, row);\n };\n if (fs.existsSync(file)) {\n for (const line of fs.readFileSync(file, 'utf8').split('\\n')) {\n if (!line.trim()) continue;\n try {\n const e = JSON.parse(line) as SavingEntry;\n if (e.ts < cutoff) continue;\n const outcome: Outcome = e.outcome ?? 'complete';\n // Back-compat: lines written before these dims existed are MCP calls\n // from an unidentified client.\n bump(byTool, e.tool, outcome);\n bump(bySource, e.source ?? 'mcp', outcome);\n bump(byClient, e.client ?? 'unknown', outcome);\n if (typeof e.ms === 'number' && e.ms >= 0) {\n const timing = msByTool.get(e.tool) ?? { sum: 0, n: 0 };\n timing.sum += e.ms;\n timing.n++;\n msByTool.set(e.tool, timing);\n }\n } catch {\n /* skip corrupt line */\n }\n }\n }\n const commands: CommandStat[] = toDimensionStats(byTool).map((d) => {\n const timing = msByTool.get(d.key);\n return {\n tool: d.key,\n calls: d.calls,\n complete: d.complete,\n partial: d.partial,\n miss: d.miss,\n successPct: d.successPct,\n avgMs: timing && timing.n > 0 ? Math.round(timing.sum / timing.n) : null,\n };\n });\n const totals = commands.reduce(\n (t, c) => ({\n calls: t.calls + c.calls,\n complete: t.complete + c.complete,\n partial: t.partial + c.partial,\n miss: t.miss + c.miss,\n }),\n { calls: 0, complete: 0, partial: 0, miss: 0 },\n );\n const avgSuccessPct = commands.length\n ? Math.round(commands.reduce((s, c) => s + c.successPct, 0) / commands.length)\n : 0;\n return {\n enabled: savingsRecorded(root),\n days,\n commands,\n sources: toDimensionStats(bySource),\n clients: toDimensionStats(byClient),\n totals,\n avgSuccessPct,\n };\n}\n","/**\n * Graph-grounded context assembly for `vg code` (VG-CLI-CODE §3).\n *\n * A generic coding agent starts blind and reconstructs structure by grepping and\n * reading whole files — which is exactly what blows the context window and\n * degrades the model. This module instead uses the deterministic code graph to\n * hand the planner a *small, high-signal, budget-bounded* context: the symbols\n * most relevant to the instruction, their immediate relations, the blast radius\n * of changing them, and any declared facts (hard constraints) that must not be\n * dropped by later compaction. Deterministic given a graph + instruction, so it\n * is fully offline-testable and benchmarkable.\n */\n\nimport { conceptMapLines, extractLiteralNeedles, queryGraph } from '../engine/query.js';\nimport type { RelevanceAnalysis } from '../engine/relevance-provider.js';\nimport { indexFor } from '../engine/relations.js';\nimport { impactOf } from '../engine/impact.js';\nimport type { CodeContext } from './types.js';\nimport type { GraphNode, VgGraph } from '../schema.js';\nimport { userAskFromInstruction } from '../engine/user-ask.js';\n\nexport interface BuildContextOptions {\n /** Approx token budget for the rendered block (default 3000). */\n budget?: number;\n /** How many retrieval seeds to expand (default 8). */\n seeds?: number;\n /** Impact BFS depth for the blast radius (default 2). */\n impactDepth?: number;\n /** Restrict the edit surface to these files (from `--file`), if given. */\n files?: string[];\n /** Optional pre-computed relevance analysis (engine/relevance-provider.ts),\n * loaded by the async caller; widens seed vocabulary deterministically. */\n relevance?: RelevanceAnalysis | null;\n /** Optional per-node topic tags (engine/relevance-enrich.ts). */\n topicTags?: Map<string, readonly string[]> | null;\n /** The previous conversational ask (multi-turn `vg code`). Its content\n * terms join seed ranking at a damped weight so follow-ups (\"do we\n * support direct debits?\" after \"where is stripe used?\") stay anchored to\n * the conversation's topic. Absent → single-turn behaviour, unchanged. */\n priorInstruction?: string | null;\n}\n\n/**\n * Build the context block for a coding instruction. The ordering is\n * cache-stable by design (see router.ts): the invariant, repo-derived material\n * (facts, symbols, relations) comes first and the volatile instruction is\n * echoed last, so a provider's prompt cache can reuse the stable prefix across\n * turns.\n */\nexport function buildCodeContext(graph: VgGraph, instruction: string, options: BuildContextOptions = {}): CodeContext {\n const budget = options.budget ?? 3000;\n const seedLimit = options.seeds ?? 8;\n const impactDepth = options.impactDepth ?? 2;\n const index = indexFor(graph);\n\n // Hosts (VS Code panel) append a \"User attachments\" block with backticked\n // filenames/paths. Ranking and literal-locate pins must use only the user's\n // ask — otherwise `image.png` becomes a hard constraint that aborts the task.\n // The full instruction (with attachments) still goes in the Task section.\n const ask = userAskFromInstruction(instruction);\n const priorAsk = options.priorInstruction\n ? userAskFromInstruction(options.priorInstruction)\n : options.priorInstruction;\n\n // Retrieval seeds: reuse the deterministic lexical/structural retrieval that\n // backs `vg ask`. When `--file` narrows the surface, keep only seeds in those\n // files (but still let impact reach outside them, so the review is honest).\n // URL / quoted-string needles are stripped inside queryGraph so path tokens\n // cannot poison seeds (dash→dashboard, exist→NonExisting, …).\n const q = queryGraph(graph, ask, {\n budget: Math.floor(budget * 0.6),\n limit: seedLimit * 2,\n relevance: options.relevance,\n topicTags: options.topicTags,\n priorQuestion: priorAsk,\n });\n let seeds = q.matches.map((m) => ({ node: m.node, why: m.why }));\n if (options.files && options.files.length) {\n const set = new Set(options.files.map(normalize));\n const inScope = seeds.filter((s) => set.has(normalize(s.node.file)));\n // If nothing matched inside the named files, keep the best global seeds but\n // still steer target files to what the caller asked for.\n if (inScope.length) seeds = inScope;\n }\n seeds = seeds.slice(0, seedLimit);\n\n // Blast radius: who depends on the seeds. This is the impact-aware review\n // signal — an edit to a hub is riskier and the context says so.\n const impacted = new Map<string, { node: GraphNode; via: string }>();\n for (const s of seeds) {\n const impact = impactOf(graph, s.node.id, { depth: impactDepth });\n for (const item of impact.affected.slice(0, 6)) {\n const node = index.node(item.id);\n if (node && !impacted.has(node.id)) impacted.set(node.id, { node, via: s.node.qualifiedName });\n }\n }\n\n // Target files: the seed files (or the explicit --file set), stable order.\n const targetFiles = options.files?.length\n ? [...new Set(options.files.map(normalize))].sort()\n : [...new Set(seeds.map((s) => s.node.file))].sort();\n\n // Pinned facts: declared invariants/contracts that touch the seeds. These are\n // hard constraints; they are surfaced explicitly and never summarized away.\n const seedIds = new Set(seeds.map((s) => s.node.id));\n const pinnedFacts = [\n ...literalNeedleFacts(ask),\n ...pinnedFactsFor(graph, seedIds),\n ];\n\n const conceptMap = conceptMapLines(ask, options.relevance, priorAsk);\n const rendered = render(instruction, seeds, [...impacted.values()], targetFiles, pinnedFacts, conceptMap, index, budget);\n return {\n instruction,\n seeds,\n targetFiles,\n impacted: [...impacted.values()],\n pinnedFacts,\n conceptMap,\n rendered,\n tokensEstimate: estimateTokens(rendered),\n };\n}\n\n/** Pin URL / quoted needles so the agent does not treat path tokens as symbols. */\nfunction literalNeedleFacts(ask: string): string[] {\n const needles = extractLiteralNeedles(ask);\n if (!needles.length) return [];\n return needles.map(\n (n) =>\n `literal-locate: search the workspace for the exact string \\`${n}\\` (use search_code with the quoted needle). This is not a graph symbol name. If there are zero hits, report that honestly and finish — do not invent an edit.`,\n );\n}\n\nfunction pinnedFactsFor(graph: VgGraph, seedIds: Set<string>): string[] {\n if (!graph.facts?.length) return [];\n const out: string[] = [];\n for (const f of graph.facts) {\n if (f.kind === 'characterization') continue; // keep hard constraints only\n if (!f.subjectIds.some((id) => seedIds.has(id))) continue;\n const subjects = f.subjectIds\n .map((id) => graph.nodes.find((n) => n.id === id)?.qualifiedName ?? id)\n .join(', ');\n out.push(`${f.kind}: ${subjects} — ${JSON.stringify(f.predicate)}`);\n }\n return out.sort().slice(0, 12);\n}\n\nfunction render(\n instruction: string,\n seeds: { node: GraphNode; why: string }[],\n impacted: { node: GraphNode; via: string }[],\n targetFiles: string[],\n pinnedFacts: string[],\n conceptMap: string[],\n index: ReturnType<typeof indexFor>,\n budget: number,\n): string {\n const lines: string[] = [];\n lines.push('# Repository context (from the deterministic code graph)');\n lines.push('');\n\n if (pinnedFacts.length) {\n lines.push('## Hard constraints (do not violate)');\n for (const f of pinnedFacts) lines.push(`- ${f}`);\n lines.push('');\n }\n\n if (conceptMap.length) {\n lines.push('## How the ask was interpreted');\n for (const l of conceptMap) lines.push(l);\n lines.push('');\n }\n\n lines.push('## Relevant symbols');\n for (const { node, why } of seeds) {\n const block: string[] = [];\n block.push(`### ${node.qualifiedName} (${node.kind}, ${node.file}:${node.span.start}-${node.span.end})`);\n if (node.signature) block.push('`' + node.signature + '`');\n const callees = uniqueNames(index.callees(node.id).map((x) => x.node.qualifiedName)).slice(0, 6);\n const callers = uniqueNames(index.callers(node.id).map((x) => x.node.qualifiedName)).slice(0, 6);\n if (callees.length) block.push(`calls: ${callees.join(', ')}`);\n if (callers.length) block.push(`called by: ${callers.join(', ')}`);\n block.push(`importance ${node.importance.toFixed(3)}${node.isHub ? ' · hub (high blast radius)' : ''} · ${why}`);\n block.push('');\n const candidate = lines.concat(block).join('\\n');\n if (estimateTokens(candidate) > budget && lines.length > 3) break;\n lines.push(...block);\n }\n\n if (impacted.length) {\n lines.push('## Blast radius (would be affected by a change here)');\n for (const { node, via } of impacted.slice(0, 10)) {\n lines.push(`- ${node.qualifiedName} (${node.file}:${node.span.start}) — depends on ${via}`);\n }\n lines.push('');\n }\n\n lines.push('## Files in scope for this edit');\n for (const f of targetFiles) lines.push(`- ${f}`);\n lines.push('');\n\n lines.push('## Task');\n lines.push(instruction);\n return lines.join('\\n');\n}\n\nfunction uniqueNames(xs: string[]): string[] {\n return [...new Set(xs)];\n}\n\nfunction normalize(file: string): string {\n return file.replace(/\\\\/g, '/').replace(/^\\.\\//, '');\n}\n\nfunction estimateTokens(text: string): number {\n return Math.ceil(text.length / 4);\n}\n","/**\n * Source-bearing Task Capsule compiler (Fusion Runtime Phase 0).\n *\n * Today's {@link buildCodeContext} pays for graph metadata, then the model still\n * calls `read_file` — double payment. This module compiles a Task Capsule that\n * includes exact source ranges (from Tree-sitter spans already on graph nodes)\n * so the first inference can solve without navigation tool calls (ZNS@1 path).\n *\n * Deterministic given (graph, instruction, file contents, options). Injectable\n * `readFile` keeps unit tests offline and pure.\n *\n * Schema: docs/fusion/task-capsule-v0.schema.json\n */\n\nimport { queryGraph } from '../engine/query.js';\nimport { indexFor } from '../engine/relations.js';\nimport { impactOf } from '../engine/impact.js';\nimport { hashString } from '../engine/hash.js';\nimport type { GraphNode, VgGraph } from '../schema.js';\nimport type { CodeContext } from './types.js';\nimport { buildCodeContext, type BuildContextOptions } from './context.js';\n\nexport const TASK_CAPSULE_SCHEMA_VERSION = 'task-capsule/0' as const;\n/** Frozen ranking policy id — bump when the heuristic changes (benchmark gate). */\n/** Bumped 2026.07.1: strip URL/quoted needles from seed ranking (no path-token false positives). */\n/** Bumped 2026.08.1: term roles (weak process verbs never seed alone), concept/bigram\n * expansion (payments→stripe, \"direct debit\"→sepa/bacs/mandate), multi-term coverage\n * bonus, directory-segment evidence — gated by the ask-quality corpus (bench/ask-corpus.mjs). */\n/** Bumped 2026.08.2: optional relevance-provider seam — sanitized provider expansions\n * join term preparation (own 0..1 weight capped at EXPANSION_WEIGHT; weak-provenance\n * dropped); provider version recorded as `relevanceVersion` provenance. Absent\n * provider = 2026.08.1 behaviour exactly — gated by the same corpus, dual-mode. */\n/** Bumped 2026.08.3: multi-turn field report (\"do we support direct debits?\" after a\n * stripe ask seeded direct* distractors). (a) Tokens consumed by a fired bigram\n * concept are demoted to the weak role — \"direct\" corroborates, never seeds.\n * (b) Conversation carry-over: the previous ask's content terms join ranking at\n * CARRY_WEIGHT when the caller passes `priorInstruction`. (c) A plain-language\n * \"how the ask was interpreted\" concept map is rendered for small local models.\n * No prior instruction + no bigram ask = 2026.08.2 behaviour exactly. */\nexport const CAPSULE_RANKING_VERSION = 'capsule-rank@2026.08.3' as const;\nexport const CAPSULE_COMPILER_ID = 'vg-task-capsule/0' as const;\n\nexport interface BuildCapsuleOptions extends BuildContextOptions {\n /**\n * Read file contents relative to the repository root. Required for source\n * slices; when omitted, the capsule still builds metadata + empty slices\n * (useful for schema/shape tests).\n */\n readFile?: (relativePath: string) => string | null;\n /** Extra lines of context around each symbol span (default 1). */\n padding?: number;\n /** Max source slices after merge (default 12). */\n maxSlices?: number;\n repositoryId?: string | null;\n /** Optional provenance from the Model Execution Profile / security ladder. */\n provenance?: CapsuleProvenanceExtras;\n /**\n * Extra pinned facts (e.g. high-confidence federation bridge edges) appended\n * after graph-derived facts. Secret-free, short strings only.\n */\n extraPinnedFacts?: string[];\n}\n\nexport interface CapsuleSymbolRef {\n id: string;\n qualifiedName: string;\n kind: string;\n file: string;\n span: { start: number; end: number };\n signature?: string | null;\n why: string;\n importance: number;\n}\n\nexport interface SourceSlice {\n file: string;\n start: number;\n end: number;\n content: string;\n contentHash: string;\n symbolIds: string[];\n}\n\nexport interface CapsuleRelationship {\n kind: 'calls' | 'called-by' | 'impacts' | 'contains' | 'other';\n from: string;\n to: string;\n}\n\nexport interface VerificationPlan {\n syntaxFiles: string[];\n suggestedTests: string[];\n notes: string[];\n}\n\nexport interface TaskCapsule {\n schemaVersion: typeof TASK_CAPSULE_SCHEMA_VERSION;\n instruction: string;\n primary: CapsuleSymbolRef[];\n supporting: CapsuleSymbolRef[];\n sourceSlices: SourceSlice[];\n relationships: CapsuleRelationship[];\n pinnedFacts: string[];\n /** Plain-language interpretation of the ask (concept expansions, relevance\n * topics, carried prior-turn terms) — see engine/query.ts conceptMapLines. */\n conceptMap: string[];\n targetFiles: string[];\n verificationPlan: VerificationPlan;\n rendered: string;\n tokensEstimate: number;\n provenance: {\n compiler: string;\n rankingVersion: string;\n graphCorpusHash: string | null;\n repositoryId: string | null;\n /** Model Execution Profile id when resolved (Fusion Phase 4/7). */\n modelProfileId?: string | null;\n /** Security tier for shell during this task. */\n securityTier?: string | null;\n /** Frozen policy / ranking patch id if any. */\n policyVersion?: string | null;\n /** Version of the optional relevance provider that widened seed\n * vocabulary for this capsule, or null when none was active. */\n relevanceVersion?: string | null;\n };\n}\n\nexport interface CapsuleProvenanceExtras {\n modelProfileId?: string | null;\n securityTier?: string | null;\n policyVersion?: string | null;\n}\n\n/** Host-safe capsule summary for VS Code / stream-json capsule transparency. */\nexport interface CapsuleSummary {\n schemaVersion: string;\n instruction: string;\n primary: Array<{ qualifiedName: string; file: string; kind: string }>;\n supporting: Array<{ qualifiedName: string; file: string; kind: string }>;\n sourceSliceCount: number;\n sourceFiles: string[];\n tokensEstimate: number;\n rankingVersion: string;\n /** Truncated rendered capsule for display (not the full prompt dump). */\n preview: string;\n}\n\n/** Host-safe capsule summary (capsule transparency UI / stream-json). */\nexport function summarizeCapsule(capsule: TaskCapsule): CapsuleSummary {\n const sourceFiles = [...new Set(capsule.sourceSlices.map((s) => s.file))].sort();\n const preview = capsule.rendered.length > 4000 ? `${capsule.rendered.slice(0, 4000)}\\n… (truncated)` : capsule.rendered;\n return {\n schemaVersion: capsule.schemaVersion,\n instruction: capsule.instruction,\n primary: capsule.primary.map((p) => ({ qualifiedName: p.qualifiedName, file: p.file, kind: p.kind })),\n supporting: capsule.supporting.map((p) => ({ qualifiedName: p.qualifiedName, file: p.file, kind: p.kind })),\n sourceSliceCount: capsule.sourceSlices.length,\n sourceFiles,\n tokensEstimate: capsule.tokensEstimate,\n rankingVersion: capsule.provenance.rankingVersion,\n preview,\n };\n}\n\n/**\n * Compile a source-bearing Task Capsule. Reuses the same seed / impact /\n * fact-pinning path as {@link buildCodeContext}, then attaches exact source\n * slices and a verification sketch.\n */\nexport function buildTaskCapsule(graph: VgGraph, instruction: string, options: BuildCapsuleOptions = {}): TaskCapsule {\n const base = buildCodeContext(graph, instruction, options);\n const padding = options.padding ?? 1;\n const maxSlices = options.maxSlices ?? 12;\n const budget = options.budget ?? 3000;\n const index = indexFor(graph);\n\n const primary = base.seeds.map((s) => toRef(s.node, s.why));\n const primaryIds = new Set(primary.map((p) => p.id));\n\n const supporting: CapsuleSymbolRef[] = [];\n for (const { node, via } of base.impacted) {\n if (primaryIds.has(node.id)) continue;\n supporting.push(toRef(node, `depends on ${via}`));\n }\n\n const relationships = collectRelationships(base, index);\n const sourceSlices = options.readFile\n ? buildSourceSlices(\n [...base.seeds.map((s) => s.node), ...base.impacted.map((i) => i.node)],\n options.readFile,\n padding,\n maxSlices,\n )\n : [];\n\n const extraFacts = (options.extraPinnedFacts ?? []).filter((f) => typeof f === 'string' && f.trim());\n const pinnedFacts = [...base.pinnedFacts, ...extraFacts];\n const verificationPlan = buildVerificationPlan(graph, base);\n const rendered = renderCapsule(instruction, primary, supporting, sourceSlices, pinnedFacts, base.conceptMap, base.targetFiles, verificationPlan, relationships, budget);\n\n return {\n schemaVersion: TASK_CAPSULE_SCHEMA_VERSION,\n instruction,\n primary,\n supporting,\n sourceSlices,\n relationships,\n pinnedFacts,\n conceptMap: base.conceptMap,\n targetFiles: base.targetFiles,\n verificationPlan,\n rendered,\n tokensEstimate: estimateTokens(rendered),\n provenance: {\n compiler: CAPSULE_COMPILER_ID,\n rankingVersion: CAPSULE_RANKING_VERSION,\n graphCorpusHash: graph.provenance?.corpusHash ?? null,\n repositoryId: options.repositoryId ?? null,\n modelProfileId: options.provenance?.modelProfileId ?? null,\n securityTier: options.provenance?.securityTier ?? null,\n policyVersion: options.provenance?.policyVersion ?? null,\n relevanceVersion: options.relevance?.version ?? null,\n },\n };\n}\n\n/**\n * Project a capsule into the legacy {@link CodeContext} shape so the existing\n * agent prompt path can consume it without a full rewrite (A/B flag).\n */\nexport function capsuleToCodeContext(capsule: TaskCapsule): CodeContext {\n return {\n instruction: capsule.instruction,\n seeds: capsule.primary.map((p) => ({\n node: {\n id: p.id,\n qualifiedName: p.qualifiedName,\n kind: p.kind,\n file: p.file,\n span: p.span,\n signature: p.signature ?? undefined,\n importance: p.importance,\n } as GraphNode,\n why: p.why,\n })),\n targetFiles: capsule.targetFiles,\n conceptMap: capsule.conceptMap,\n impacted: capsule.supporting.map((s) => ({\n node: {\n id: s.id,\n qualifiedName: s.qualifiedName,\n kind: s.kind,\n file: s.file,\n span: s.span,\n signature: s.signature ?? undefined,\n importance: s.importance,\n } as GraphNode,\n via: s.why.replace(/^depends on /, ''),\n })),\n pinnedFacts: capsule.pinnedFacts,\n rendered: capsule.rendered,\n tokensEstimate: capsule.tokensEstimate,\n };\n}\n\nfunction toRef(node: GraphNode, why: string): CapsuleSymbolRef {\n return {\n id: node.id,\n qualifiedName: node.qualifiedName,\n kind: node.kind,\n file: normalize(node.file),\n span: { start: node.span.start, end: node.span.end },\n signature: node.signature ?? null,\n why,\n importance: node.importance,\n };\n}\n\nfunction collectRelationships(\n base: CodeContext,\n index: ReturnType<typeof indexFor>,\n): CapsuleRelationship[] {\n const out: CapsuleRelationship[] = [];\n const seen = new Set<string>();\n const push = (kind: CapsuleRelationship['kind'], from: string, to: string) => {\n const key = `${kind}|${from}|${to}`;\n if (seen.has(key)) return;\n seen.add(key);\n out.push({ kind, from, to });\n };\n\n for (const { node } of base.seeds) {\n for (const c of index.callees(node.id).slice(0, 6)) {\n push('calls', node.qualifiedName, c.node.qualifiedName);\n }\n for (const c of index.callers(node.id).slice(0, 6)) {\n push('called-by', node.qualifiedName, c.node.qualifiedName);\n }\n }\n for (const { node, via } of base.impacted.slice(0, 10)) {\n push('impacts', via, node.qualifiedName);\n }\n\n // Stable order for determinism.\n return out.sort((a, b) => a.kind.localeCompare(b.kind) || a.from.localeCompare(b.from) || a.to.localeCompare(b.to));\n}\n\nfunction buildSourceSlices(\n nodes: GraphNode[],\n readFile: (relativePath: string) => string | null,\n padding: number,\n maxSlices: number,\n): SourceSlice[] {\n // Prefer concrete symbols over file/module containers for source evidence.\n const eligible = nodes.filter((n) => !['file', 'module', 'package'].includes(n.kind));\n const byFile = new Map<string, GraphNode[]>();\n for (const n of eligible) {\n const file = normalize(n.file);\n const list = byFile.get(file) ?? [];\n list.push(n);\n byFile.set(file, list);\n }\n\n type Range = { file: string; start: number; end: number; symbolIds: string[]; score: number };\n const ranges: Range[] = [];\n\n for (const [file, fileNodes] of [...byFile.entries()].sort(([a], [b]) => a.localeCompare(b))) {\n const sorted = [...fileNodes].sort((a, b) => a.span.start - b.span.start || b.importance - a.importance);\n let current: Range | null = null;\n for (const n of sorted) {\n const start = Math.max(1, n.span.start - padding);\n const end = n.span.end + padding;\n const score = n.importance + (n.isHub ? 0.25 : 0);\n if (current && current.file === file && start <= current.end + 2) {\n current.end = Math.max(current.end, end);\n current.symbolIds.push(n.id);\n current.score = Math.max(current.score, score);\n } else {\n if (current) ranges.push(current);\n current = { file, start, end, symbolIds: [n.id], score };\n }\n }\n if (current) ranges.push(current);\n }\n\n ranges.sort((a, b) => b.score - a.score || a.file.localeCompare(b.file) || a.start - b.start);\n\n const slices: SourceSlice[] = [];\n for (const range of ranges) {\n if (slices.length >= maxSlices) break;\n const raw = readFile(range.file);\n if (raw === null) continue;\n const lines = raw.split('\\n');\n const start = Math.min(range.start, lines.length);\n const end = Math.min(range.end, lines.length);\n if (start < 1 || end < start) continue;\n const content = lines.slice(start - 1, end).join('\\n');\n slices.push({\n file: range.file,\n start,\n end,\n content,\n contentHash: hashString(content),\n symbolIds: [...new Set(range.symbolIds)].sort(),\n });\n }\n\n // Stable final order: file then start line (score only used for selection).\n return slices.sort((a, b) => a.file.localeCompare(b.file) || a.start - b.start);\n}\n\nfunction buildVerificationPlan(graph: VgGraph, base: CodeContext): VerificationPlan {\n const syntaxFiles = [...base.targetFiles].sort();\n const seedIds = new Set(base.seeds.map((s) => s.node.id));\n const suggestedTests: string[] = [];\n\n for (const n of graph.nodes) {\n if (n.kind !== 'test') continue;\n // Prefer tests that share a file with seeds or whose name mentions a seed.\n const sameFile = base.seeds.some((s) => normalize(s.node.file) === normalize(n.file));\n const nameHit = base.seeds.some((s) => n.qualifiedName.toLowerCase().includes(s.node.name.toLowerCase()));\n if (sameFile || nameHit || seedIds.has(n.id)) {\n suggestedTests.push(n.qualifiedName);\n }\n }\n suggestedTests.sort();\n\n const notes: string[] = [];\n if (!suggestedTests.length) {\n notes.push('No graph-linked tests found for seed symbols; run the nearest project test command after apply.');\n }\n if (base.impacted.some((i) => i.node.isHub || i.node.importance >= 0.7)) {\n notes.push('High-importance dependents in blast radius — prefer targeted tests before a full build.');\n }\n\n return {\n syntaxFiles,\n suggestedTests: suggestedTests.slice(0, 12),\n notes,\n };\n}\n\nfunction renderCapsule(\n instruction: string,\n primary: CapsuleSymbolRef[],\n supporting: CapsuleSymbolRef[],\n slices: SourceSlice[],\n pinnedFacts: string[],\n conceptMap: string[],\n targetFiles: string[],\n verification: VerificationPlan,\n relationships: CapsuleRelationship[],\n budget: number,\n): string {\n const lines: string[] = [];\n lines.push('# Task capsule (source-bearing, from the deterministic code graph)');\n lines.push('');\n lines.push('Use the exact source evidence below. Search or read outside it only if this capsule is insufficient.');\n lines.push('');\n\n if (pinnedFacts.length) {\n lines.push('## Hard constraints (do not violate)');\n for (const f of pinnedFacts) lines.push(`- ${f}`);\n lines.push('');\n }\n\n // Rendered before the symbol list on purpose: a small local model reads the\n // interpretation first, so the `a→b` provenance slugs on each seed line are\n // decodable instead of noise.\n if (conceptMap.length) {\n lines.push('## How the ask was interpreted');\n for (const l of conceptMap) lines.push(l);\n lines.push('');\n }\n\n lines.push('## Primary symbols');\n for (const s of primary) {\n lines.push(`- ${s.qualifiedName} (${s.kind}, ${s.file}:${s.span.start}-${s.span.end})${s.signature ? ` — \\`${s.signature}\\`` : ''} — ${s.why}`);\n }\n lines.push('');\n\n if (supporting.length) {\n lines.push('## Supporting / blast radius');\n for (const s of supporting.slice(0, 10)) {\n lines.push(`- ${s.qualifiedName} (${s.file}:${s.span.start}) — ${s.why}`);\n }\n lines.push('');\n }\n\n if (relationships.length) {\n lines.push('## Relationships');\n for (const r of relationships.slice(0, 24)) {\n lines.push(`- ${r.kind}: ${r.from} → ${r.to}`);\n }\n lines.push('');\n }\n\n lines.push('## Exact source evidence');\n if (!slices.length) {\n lines.push('_No source slices available (file reader missing or spans unreadable)._');\n lines.push('');\n } else {\n let included = 0;\n for (const slice of slices) {\n const block = [\n `### ${slice.file}:${slice.start}-${slice.end}`,\n `\\`\\`\\`${langFor(slice.file)}`,\n slice.content,\n '```',\n '',\n ];\n const candidate = [...lines, ...block, '## Task', instruction].join('\\n');\n if (estimateTokens(candidate) > budget && included > 0) break;\n lines.push(...block);\n included += 1;\n }\n }\n\n lines.push('## Files in scope');\n for (const f of targetFiles) lines.push(`- ${f}`);\n lines.push('');\n\n lines.push('## Verification plan');\n for (const f of verification.syntaxFiles) lines.push(`- syntax: ${f}`);\n for (const t of verification.suggestedTests) lines.push(`- test: ${t}`);\n for (const n of verification.notes) lines.push(`- note: ${n}`);\n lines.push('');\n\n lines.push('## Task');\n lines.push(instruction);\n return lines.join('\\n');\n}\n\nfunction langFor(file: string): string {\n const ext = file.split('.').pop()?.toLowerCase() ?? '';\n const map: Record<string, string> = {\n ts: 'ts',\n tsx: 'tsx',\n js: 'js',\n jsx: 'jsx',\n mjs: 'js',\n cjs: 'js',\n py: 'python',\n rs: 'rust',\n go: 'go',\n java: 'java',\n cs: 'csharp',\n md: 'md',\n json: 'json',\n };\n return map[ext] ?? '';\n}\n\nfunction normalize(file: string): string {\n return file.replace(/\\\\/g, '/').replace(/^\\.\\//, '');\n}\n\nfunction estimateTokens(text: string): number {\n return Math.ceil(text.length / 4);\n}\n\n// Re-export query touch so tree-shaking keeps the dependency explicit for tests.\nexport const __testing = { queryGraph, impactOf };\n"]}
@@ -1,5 +1,5 @@
1
- import { runCoreScan, compactUiPurpose, scanArchitectureBundle, mermaidFromArchitecture, aggregateSolutionArchitecture } from './chunk-V2UGRUTL.js';
2
- import { findPackageJsonFiles, readJsonFile, findFiles, readTextFile, pathExists } from './chunk-NG4KIJW6.js';
1
+ import { runCoreScan, compactUiPurpose, scanArchitectureBundle, mermaidFromArchitecture, aggregateSolutionArchitecture } from './chunk-OQT3JBWW.js';
2
+ import { findPackageJsonFiles, readJsonFile, findFiles, readTextFile, pathExists } from './chunk-PVNALGTG.js';
3
3
  import { writeJsonFile } from './chunk-CRAMOEBE.js';
4
4
  import * as path3 from 'path';
5
5
  import { Command } from 'commander';
@@ -3760,5 +3760,5 @@ var baselineCommand = new Command("baseline").description("Create a drift baseli
3760
3760
  });
3761
3761
 
3762
3762
  export { baselineCommand, loadAdvancedScanHook, runBaseline };
3763
- //# sourceMappingURL=chunk-6ABMV74F.js.map
3764
- //# sourceMappingURL=chunk-6ABMV74F.js.map
3763
+ //# sourceMappingURL=chunk-5XY4EFR7.js.map
3764
+ //# sourceMappingURL=chunk-5XY4EFR7.js.map