token-goat 2.9.28 → 2.9.30

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 (134) hide show
  1. package/README.md +36 -40
  2. package/SECURITY.md +28 -10
  3. package/THIRD_PARTY_NOTICES.md +40 -3
  4. package/dist/native/linux-arm64/tg-hook +0 -0
  5. package/dist/native/linux-x64/tg-hook +0 -0
  6. package/dist/ort-wasm-simd-threaded.mjs +59 -0
  7. package/dist/token-goat-chunk-3CHUNJ2O.mjs +53 -0
  8. package/dist/token-goat-chunk-3Z5S4KGM.mjs +918 -0
  9. package/dist/token-goat-chunk-4FVIAHSI.mjs +211 -0
  10. package/dist/{token-goat-chunk-66LODAUT.mjs → token-goat-chunk-4JJS54TR.mjs} +4 -3
  11. package/dist/token-goat-chunk-4LCCNRTG.mjs +313 -0
  12. package/dist/token-goat-chunk-54K3EUV3.mjs +35 -0
  13. package/dist/token-goat-chunk-56EIMS3E.mjs +159 -0
  14. package/dist/token-goat-chunk-5BCIJXMO.mjs +609 -0
  15. package/dist/token-goat-chunk-5KDMCMF2.mjs +362 -0
  16. package/dist/token-goat-chunk-5RG5SBL6.mjs +221 -0
  17. package/dist/{token-goat-chunk-RRNZMM3A.mjs → token-goat-chunk-5Y6ZYL6U.mjs} +21 -2
  18. package/dist/{token-goat-chunk-NILVK7XM.mjs → token-goat-chunk-64FBPDTK.mjs} +12 -6
  19. package/dist/{token-goat-chunk-LEG3JNJ6.mjs → token-goat-chunk-664RTTUV.mjs} +31 -15
  20. package/dist/token-goat-chunk-67TQJ76B.mjs +57 -0
  21. package/dist/token-goat-chunk-6QMAS7AB.mjs +42 -0
  22. package/dist/token-goat-chunk-7BXSNBY5.mjs +253 -0
  23. package/dist/{token-goat-chunk-F7QZRIWM.mjs → token-goat-chunk-7F2UBPD3.mjs} +42 -35
  24. package/dist/{token-goat-chunk-CC2PYJM7.mjs → token-goat-chunk-7IN2MKDS.mjs} +718 -595
  25. package/dist/token-goat-chunk-7NADEDKJ.mjs +124 -0
  26. package/dist/{token-goat-chunk-6SGLIPQB.mjs → token-goat-chunk-A3CK6N5Z.mjs} +621 -72
  27. package/dist/{token-goat-chunk-HXNAC4ZF.mjs → token-goat-chunk-AFLYLHDH.mjs} +48 -33
  28. package/dist/token-goat-chunk-AM5V6GSX.mjs +367 -0
  29. package/dist/{token-goat-chunk-I7CB3X4K.mjs → token-goat-chunk-APGZXSPS.mjs} +44 -148
  30. package/dist/{token-goat-chunk-BJBRGPBX.mjs → token-goat-chunk-ARDNEC2U.mjs} +11 -7
  31. package/dist/token-goat-chunk-ATCPY7EQ.mjs +134 -0
  32. package/dist/token-goat-chunk-B2RZZCSS.mjs +354 -0
  33. package/dist/{token-goat-chunk-QM76S6YS.mjs → token-goat-chunk-B45VMIIH.mjs} +6 -5
  34. package/dist/token-goat-chunk-BPGCUMR7.mjs +30 -0
  35. package/dist/{token-goat-chunk-GGLEE35R.mjs → token-goat-chunk-C63JQV5K.mjs} +49 -10
  36. package/dist/{token-goat-chunk-RJH64KQH.mjs → token-goat-chunk-COBQGL5S.mjs} +2661 -2440
  37. package/dist/token-goat-chunk-COTXZHTS.mjs +39 -0
  38. package/dist/token-goat-chunk-CYCEYAEO.mjs +265 -0
  39. package/dist/token-goat-chunk-CZ3LUXYZ.mjs +4115 -0
  40. package/dist/token-goat-chunk-DZX2YDPT.mjs +15 -0
  41. package/dist/token-goat-chunk-E3OQX2XT.mjs +824 -0
  42. package/dist/token-goat-chunk-EFHMMIGP.mjs +68 -0
  43. package/dist/token-goat-chunk-ETBHVDB6.mjs +328 -0
  44. package/dist/token-goat-chunk-EVMZJ27Z.mjs +147 -0
  45. package/dist/token-goat-chunk-EXKGNHEG.mjs +2096 -0
  46. package/dist/{token-goat-chunk-6Z5ULNE5.mjs → token-goat-chunk-FBNQNSJK.mjs} +2490 -4957
  47. package/dist/{token-goat-chunk-NMTKNYGF.mjs → token-goat-chunk-FNFBKLRD.mjs} +74 -9
  48. package/dist/{token-goat-chunk-XI2VFAV6.mjs → token-goat-chunk-FZ3NEW5O.mjs} +33 -19
  49. package/dist/token-goat-chunk-G5PJ7AGM.mjs +36 -0
  50. package/dist/{token-goat-chunk-VE27HPIF.mjs → token-goat-chunk-GFBSN7BD.mjs} +30 -398
  51. package/dist/{token-goat-chunk-L45ZQRT7.mjs → token-goat-chunk-GOLEOXZP.mjs} +780 -786
  52. package/dist/token-goat-chunk-H2K3QP6H.mjs +24 -0
  53. package/dist/token-goat-chunk-H2PHHGM5.mjs +188 -0
  54. package/dist/token-goat-chunk-HAVAOB3S.mjs +87 -0
  55. package/dist/token-goat-chunk-HG45AF2B.mjs +2228 -0
  56. package/dist/{token-goat-chunk-CBMY2FGI.mjs → token-goat-chunk-HOJLCGDP.mjs} +17113 -15554
  57. package/dist/{token-goat-chunk-HUDC5GS5.mjs → token-goat-chunk-HYBFA5X3.mjs} +120 -19
  58. package/dist/token-goat-chunk-IVALLT3S.mjs +48 -0
  59. package/dist/token-goat-chunk-IVE6U7KV.mjs +53 -0
  60. package/dist/{token-goat-chunk-UBUKHVYW.mjs → token-goat-chunk-IVKIZWAB.mjs} +3 -3
  61. package/dist/{token-goat-chunk-4JMWPWCS.mjs → token-goat-chunk-JB6QN6VF.mjs} +6 -4
  62. package/dist/{token-goat-chunk-Q4S3UQGO.mjs → token-goat-chunk-JDHE26RP.mjs} +10 -3
  63. package/dist/{token-goat-chunk-7R2XYKC5.mjs → token-goat-chunk-JDU3EXSU.mjs} +14 -10
  64. package/dist/token-goat-chunk-JDWCRD6M.mjs +253 -0
  65. package/dist/{token-goat-chunk-XBESNWEX.mjs → token-goat-chunk-JN4XMLSD.mjs} +7 -4
  66. package/dist/token-goat-chunk-JTQQGXZH.mjs +733 -0
  67. package/dist/token-goat-chunk-KKUFXAPD.mjs +25 -0
  68. package/dist/token-goat-chunk-KQNZDCBD.mjs +47 -0
  69. package/dist/{token-goat-chunk-4RN64ZND.mjs → token-goat-chunk-KWPNJBDH.mjs} +28 -3
  70. package/dist/token-goat-chunk-LOBGHXPB.mjs +242 -0
  71. package/dist/token-goat-chunk-MKPF4CL5.mjs +37 -0
  72. package/dist/token-goat-chunk-MNWKPRAL.mjs +13 -0
  73. package/dist/{token-goat-chunk-YWSP6IU7.mjs → token-goat-chunk-N2NMER56.mjs} +25 -15
  74. package/dist/token-goat-chunk-NYKZLXMK.mjs +218 -0
  75. package/dist/token-goat-chunk-OJBNYTJP.mjs +3087 -0
  76. package/dist/token-goat-chunk-P4QMM4WK.mjs +295 -0
  77. package/dist/token-goat-chunk-PD5VKH46.mjs +184 -0
  78. package/dist/token-goat-chunk-PEPTHRFF.mjs +129 -0
  79. package/dist/{token-goat-chunk-VWZKZPSR.mjs → token-goat-chunk-PU7V3FD6.mjs} +8752 -11098
  80. package/dist/token-goat-chunk-PY533T7F.mjs +46 -0
  81. package/dist/token-goat-chunk-Q5VTGRH7.mjs +761 -0
  82. package/dist/{token-goat-chunk-IHKZ3QNA.mjs → token-goat-chunk-QCLDAQTS.mjs} +33 -19
  83. package/dist/{token-goat-chunk-LKSXAMJB.mjs → token-goat-chunk-QSBRTGM2.mjs} +9 -2
  84. package/dist/{token-goat-chunk-4STDIGYC.mjs → token-goat-chunk-RC35RBUL.mjs} +7 -5
  85. package/dist/{token-goat-chunk-D5ICEPSB.mjs → token-goat-chunk-RHXKCZX3.mjs} +887 -507
  86. package/dist/{token-goat-chunk-RSS3TLXU.mjs → token-goat-chunk-RZRTDST7.mjs} +17 -7
  87. package/dist/{token-goat-chunk-MAMQPC43.mjs → token-goat-chunk-SJHWVNDQ.mjs} +15 -21
  88. package/dist/token-goat-chunk-SMVRN2HU.mjs +188 -0
  89. package/dist/{token-goat-chunk-EL7M26WP.mjs → token-goat-chunk-SQSSNQPE.mjs} +2100 -1442
  90. package/dist/{token-goat-chunk-OZRSREKR.mjs → token-goat-chunk-T4FK7VOV.mjs} +3 -3
  91. package/dist/token-goat-chunk-U4N3BN2W.mjs +92 -0
  92. package/dist/token-goat-chunk-UA5V6P3P.mjs +122 -0
  93. package/dist/{token-goat-chunk-XKY4VKJ4.mjs → token-goat-chunk-UQ5UK2T7.mjs} +15 -4
  94. package/dist/token-goat-chunk-USILZ3T3.mjs +53 -0
  95. package/dist/token-goat-chunk-VES7EL7O.mjs +205 -0
  96. package/dist/{token-goat-chunk-M56BWPBN.mjs → token-goat-chunk-VL3YIFHZ.mjs} +550 -49
  97. package/dist/{token-goat-chunk-IZXKVT4A.mjs → token-goat-chunk-VPBBTSJR.mjs} +362 -128
  98. package/dist/{token-goat-chunk-F2ARFHLJ.mjs → token-goat-chunk-W3QCJS6G.mjs} +10 -2
  99. package/dist/{token-goat-chunk-FSTWAOW6.mjs → token-goat-chunk-WY3L4DVT.mjs} +11 -5
  100. package/dist/{token-goat-chunk-OSUFN2FV.mjs → token-goat-chunk-XB5KKOCG.mjs} +5 -25
  101. package/dist/token-goat-chunk-XKI4SEMX.mjs +66 -0
  102. package/dist/token-goat-chunk-XU4P6Z24.mjs +133 -0
  103. package/dist/{token-goat-chunk-6CCQDAYY.mjs → token-goat-chunk-Y776AENC.mjs} +138 -33
  104. package/dist/token-goat-chunk-YARZFCZS.mjs +359 -0
  105. package/dist/{token-goat-chunk-EEIDFMEM.mjs → token-goat-chunk-YZAAZU2S.mjs} +12 -3
  106. package/dist/{token-goat-chunk-E3K3BTEQ.mjs → token-goat-chunk-Z44YO3QZ.mjs} +12 -6
  107. package/dist/token-goat-chunk-Z57YODA2.mjs +35 -0
  108. package/dist/{token-goat-chunk-DA43OE7L.mjs → token-goat-chunk-ZCDTCVIS.mjs} +49 -30
  109. package/dist/token-goat-chunk-ZEJVMUQH.mjs +48 -0
  110. package/dist/{token-goat-chunk-BGHSSJUA.mjs → token-goat-chunk-ZFOBKUWH.mjs} +1 -1
  111. package/dist/token-goat-chunk-ZMBL6UVV.mjs +110 -0
  112. package/dist/{token-goat-chunk-SJEKA7Y2.mjs → token-goat-chunk-ZQSJMO2R.mjs} +381 -201
  113. package/dist/token-goat-hook-client.cjs +539 -0
  114. package/dist/token-goat-hook-client.mjs +26 -0
  115. package/dist/token-goat-hook.mjs +48 -28
  116. package/dist/token-goat.core.mjs +10 -45
  117. package/docs/C4_RUNTIME_ARCHITECTURE.md +3 -3
  118. package/docs/cli.md +82 -47
  119. package/docs/install.md +58 -23
  120. package/docs/security.md +7 -7
  121. package/package.json +17 -7
  122. package/scripts/verify-native-dist.mjs +386 -0
  123. package/dist/token-goat-chunk-4JJBFT7V.mjs +0 -20
  124. package/dist/token-goat-chunk-5NNYIUGV.mjs +0 -143
  125. package/dist/token-goat-chunk-6DQNNFJ6.mjs +0 -294
  126. package/dist/token-goat-chunk-7MAFDRVR.mjs +0 -47
  127. package/dist/token-goat-chunk-BCN2YQC6.mjs +0 -32
  128. package/dist/token-goat-chunk-D7GHQKQD.mjs +0 -30
  129. package/dist/token-goat-chunk-GMOUBOX4.mjs +0 -386
  130. package/dist/token-goat-chunk-IFORDBGC.mjs +0 -192
  131. package/dist/token-goat-chunk-JXK2HQXS.mjs +0 -318
  132. package/dist/token-goat-chunk-L7SDVGBT.mjs +0 -430
  133. package/dist/token-goat-chunk-MMLMALWK.mjs +0 -1381
  134. package/dist/token-goat-chunk-MVSWBNMD.mjs +0 -1985
@@ -1,127 +1,29 @@
1
1
  import { createRequire as __cjsRequire } from 'node:module';
2
2
  const require = __cjsRequire(import.meta.url);
3
- import {
4
- enqueueDirtyPathsSafe,
5
- fenceUntrusted,
6
- getTrackedFiles,
7
- scanAndRecord
8
- } from "./token-goat-chunk-6Z5ULNE5.mjs";
9
3
  import {
10
4
  getToolName
11
- } from "./token-goat-chunk-IZXKVT4A.mjs";
12
- import {
13
- RECALL_DEFAULT_LIMIT,
14
- indexRecallEntry,
15
- listRecentRecall,
16
- searchRecall
17
- } from "./token-goat-chunk-HXNAC4ZF.mjs";
18
- import {
19
- isBlobStale,
20
- loadBlob,
21
- storeBlob
22
- } from "./token-goat-chunk-BJBRGPBX.mjs";
5
+ } from "./token-goat-chunk-VPBBTSJR.mjs";
23
6
  import {
24
- redactSecrets
25
- } from "./token-goat-chunk-MVSWBNMD.mjs";
26
- import {
27
- parserFingerprintForLanguage
28
- } from "./token-goat-chunk-D5ICEPSB.mjs";
29
- import {
30
- getProjectFileEntries,
31
- projectScopeClause
32
- } from "./token-goat-chunk-HUDC5GS5.mjs";
7
+ countSymbols
8
+ } from "./token-goat-chunk-HYBFA5X3.mjs";
33
9
  import {
34
10
  getDb
35
- } from "./token-goat-chunk-M56BWPBN.mjs";
11
+ } from "./token-goat-chunk-VL3YIFHZ.mjs";
36
12
  import {
37
- fingerprintFile,
38
- getDisplayRoot,
39
- shortFingerprint
40
- } from "./token-goat-chunk-CC2PYJM7.mjs";
13
+ compileGuardedRegex,
14
+ extractErrorMessage
15
+ } from "./token-goat-chunk-GOLEOXZP.mjs";
41
16
  import {
42
- registerReset
43
- } from "./token-goat-chunk-EEIDFMEM.mjs";
17
+ displaySafeJson
18
+ } from "./token-goat-chunk-FNFBKLRD.mjs";
44
19
  import {
45
20
  SYMBOL_BODY_CHAR_CAP,
46
- countNoun,
47
- extractErrorMessage,
48
- foldPath,
49
- globalDbPath,
50
- pad
51
- } from "./token-goat-chunk-L45ZQRT7.mjs";
52
- import {
53
- UNTRUSTED_TOOL_TAG,
54
- UNTRUSTED_WEB_TAG,
55
- displaySafeJson,
56
- fenceUntrustedContent,
57
- normalizePath,
58
- resolveIndexPath,
59
- toDisplayPath
60
- } from "./token-goat-chunk-NMTKNYGF.mjs";
61
- import {
62
- compileGuardedRegex
63
- } from "./token-goat-chunk-GMOUBOX4.mjs";
21
+ globalDbPath
22
+ } from "./token-goat-chunk-VES7EL7O.mjs";
64
23
  import {
65
24
  init_define_import_meta_env
66
25
  } from "./token-goat-chunk-A37V4PBF.mjs";
67
26
 
68
- // src/web_cache.ts
69
- init_define_import_meta_env();
70
- var WEB_OUTPUT_SUBDIR = "web_outputs";
71
- var _byId = /* @__PURE__ */ new Map();
72
- var _rawById = /* @__PURE__ */ new Map();
73
- var _urlIndex = /* @__PURE__ */ new Map();
74
- function cacheIdForUrl(url) {
75
- return shortFingerprint(url);
76
- }
77
- function storeWebOutput(url, content, dedupKey = url, rawContent) {
78
- const cacheId = cacheIdForUrl(dedupKey);
79
- const redactedContent = redactSecrets(content).text;
80
- _byId.set(cacheId, redactedContent);
81
- _urlIndex.set(url, cacheId);
82
- const redactedRaw = rawContent !== void 0 && rawContent !== content ? redactSecrets(rawContent).text : void 0;
83
- if (redactedRaw !== void 0) _rawById.set(cacheId, redactedRaw);
84
- else _rawById.delete(cacheId);
85
- storeBlob(WEB_OUTPUT_SUBDIR, cacheId, redactedRaw !== void 0 ? { url, content: redactedContent, raw: redactedRaw } : { url, content: redactedContent });
86
- const redactedUrl = redactSecrets(url).text;
87
- indexRecallEntry("web", cacheId, redactedUrl, `${redactedUrl}
88
- ${redactedContent}`, Date.now());
89
- return cacheId;
90
- }
91
- function coerceWebBlob(raw) {
92
- if (raw === null || typeof raw !== "object") return null;
93
- const o = raw;
94
- if (typeof o["content"] !== "string") return null;
95
- return { url: typeof o["url"] === "string" ? o["url"] : null, content: o["content"], raw: typeof o["raw"] === "string" ? o["raw"] : null };
96
- }
97
- function getWebOutput(cacheId) {
98
- const hit = _byId.get(cacheId);
99
- if (hit !== void 0) return hit;
100
- if (isBlobStale(WEB_OUTPUT_SUBDIR, cacheId)) return null;
101
- const blob = coerceWebBlob(loadBlob(WEB_OUTPUT_SUBDIR, cacheId));
102
- if (blob === null) return null;
103
- _byId.set(cacheId, blob.content);
104
- if (blob.raw !== null) _rawById.set(cacheId, blob.raw);
105
- if (blob.url !== null) _urlIndex.set(blob.url, cacheId);
106
- return blob.content;
107
- }
108
- function getWebOutputRaw(cacheId) {
109
- const cleaned = getWebOutput(cacheId);
110
- if (cleaned === null) return null;
111
- return _rawById.get(cacheId) ?? cleaned;
112
- }
113
- function getWebOutputByUrlFromDisk(url, dedupKey = url) {
114
- const cacheId = cacheIdForUrl(dedupKey);
115
- const content = getWebOutput(cacheId);
116
- if (content === null) return null;
117
- return { cacheId, content };
118
- }
119
- registerReset(() => {
120
- _byId = /* @__PURE__ */ new Map();
121
- _rawById = /* @__PURE__ */ new Map();
122
- _urlIndex = /* @__PURE__ */ new Map();
123
- });
124
-
125
27
  // src/stdin_json.ts
126
28
  init_define_import_meta_env();
127
29
  var DEFAULT_STDIN_TIMEOUT_MS = 5e3;
@@ -538,7 +440,7 @@ async function describeTarget(target, table, opts) {
538
440
  const absPath = resolve(process.cwd(), target);
539
441
  if (existsSync(absPath)) {
540
442
  try {
541
- const { isSqliteFile, getSqliteSchema, formatSqliteSchema } = await import("./token-goat-chunk-OZRSREKR.mjs");
443
+ const { isSqliteFile, getSqliteSchema, formatSqliteSchema } = await import("./token-goat-chunk-T4FK7VOV.mjs");
542
444
  if (isSqliteFile(absPath)) {
543
445
  const schema = getSqliteSchema(absPath);
544
446
  if (table) {
@@ -560,6 +462,7 @@ async function describeTarget(target, table, opts) {
560
462
  for (const col of found.columns) {
561
463
  lines.push(`| \`${col.name}\` | \`${col.type}\` | ${col.notNull ? "NO" : "YES"} | ${col.defaultValue ?? "NULL"} | ${col.primaryKey ? "YES" : "NO"} |`);
562
464
  }
465
+ if (found.createSql !== void 0) lines.push("", `Module ${found.module ?? "?"} is not loaded here, so columns are not available. Declared as:`, found.createSql);
563
466
  return { exitCode: 0, text: lines.join("\n") };
564
467
  }
565
468
  if (opts?.json === true) {
@@ -657,21 +560,6 @@ async function cmdDescribe(target, table, opts) {
657
560
  process.exitCode = await runDescribe({ target, table, json: opts?.json });
658
561
  }
659
562
 
660
- // src/types.ts
661
- init_define_import_meta_env();
662
- var HOOK_EVENTS = [
663
- "pre_tool_use",
664
- "post_tool_use",
665
- "notification",
666
- "stop",
667
- "pre_compact",
668
- "post_compact",
669
- "user_prompt_submit",
670
- "subagent_stop",
671
- "session_start",
672
- "post_tool_use_failure"
673
- ];
674
-
675
563
  // src/cli_commands.ts
676
564
  init_define_import_meta_env();
677
565
  function toEntry(cmd) {
@@ -765,294 +653,38 @@ function checkSymbolBodySize(dbPath) {
765
653
  }
766
654
  }
767
655
 
768
- // src/mcp_tool_pattern.ts
656
+ // src/session_reminder.ts
769
657
  init_define_import_meta_env();
770
- var MCP_TOOL_PATTERN = "^mcp__";
771
-
772
- // src/reconcile.ts
773
- init_define_import_meta_env();
774
- import * as fs2 from "node:fs";
775
- var DEFAULT_RECONCILE_BUDGET_MS = 1500;
776
- function readReconcileCursor(dbPath, root) {
777
- try {
778
- const row = getDb(dbPath).prepare("SELECT last_scanned_path FROM reconcile_cursor WHERE root = ?").get(root);
779
- return row?.last_scanned_path ?? null;
780
- } catch {
781
- return null;
782
- }
783
- }
784
- function writeReconcileCursor(dbPath, root, lastScannedPath) {
785
- try {
786
- getDb(dbPath).prepare(
787
- "INSERT INTO reconcile_cursor (root, last_scanned_path, updated_at) VALUES (?, ?, ?) ON CONFLICT(root) DO UPDATE SET last_scanned_path = excluded.last_scanned_path, updated_at = excluded.updated_at"
788
- ).run(root, lastScannedPath, Date.now());
789
- } catch {
790
- }
791
- }
792
- function clearReconcileCursor(dbPath, root) {
658
+ var GENERIC_REMINDER = 'token-goat: prefer surgical reads over the Read/Grep tools on this codebase; shell commands like `rg`, `grep`, `fd`, `sed`, `cat`, `find`, and `ls` are just commands, not tool names -- `token-goat symbol <name>`, `token-goat read "file::symbol"`, `token-goat section "file::Heading"`, `token-goat semantic "description"`, `token-goat outline <file>`. Run `token-goat index .` if this project is not indexed yet.';
659
+ var INDEXED_REMINDER = 'token-goat: this project is indexed. Prefer `symbol <name>`, `read "file::symbol"`, `section "file::Heading"`, `semantic "description"`, or `outline <file>` over a full Read/Grep tool call; for JSON/YAML use `json-query file \'a.b.c\'` or `yaml-query` (nested keys are not symbols); shell commands like `rg`, `grep`, `fd`, `sed`, `cat`, `find`, and `ls` are still just commands.';
660
+ var NOTE_REMINDER = ' Record a finding that must outlive a compaction with `token-goat note set <key> "<finding>"`; notes come back at every session start.';
661
+ function isIndexedProject(cwd) {
662
+ if (cwd === void 0) return false;
793
663
  try {
794
- getDb(dbPath).prepare("DELETE FROM reconcile_cursor WHERE root = ?").run(root);
664
+ return countSymbols({ rootDir: cwd }, globalDbPath()) > 0;
795
665
  } catch {
666
+ return false;
796
667
  }
797
668
  }
798
- function runReconcile(opts = {}) {
799
- const raw = reconcileProject(opts);
800
- const root = getDisplayRoot(opts.cwd ?? process.cwd());
801
- const display = (paths) => paths.map((p) => toDisplayPath(root, p)).sort();
802
- const result = {
803
- ...raw,
804
- changed: display(raw.changed),
805
- added: display(raw.added),
806
- removed: display(raw.removed)
807
- };
808
- if (opts.json === true) {
809
- process.stdout.write(`${displaySafeJson(result)}
810
- `);
811
- return 0;
812
- }
813
- const lines = [];
814
- if (isReconcileClean(result)) {
815
- if (!result.trackedUnavailable) {
816
- lines.push(`Index matches disk: ${countNoun(result.scanned, "file")} checked in ${result.elapsedMs}ms.`);
817
- }
818
- } else {
819
- const verb = opts.dryRun === true ? "would reindex" : "queued for reindexing";
820
- const dropVerb = opts.dryRun === true ? "would drop from the index" : "queued for removal";
821
- if (result.changed.length > 0) lines.push(`${countNoun(result.changed.length, "file")} changed since indexing (${verb}):`);
822
- for (const f of result.changed) lines.push(` ~ ${f}`);
823
- if (result.added.length > 0) lines.push(`${countNoun(result.added.length, "file")} not in the index (${verb}):`);
824
- for (const f of result.added) lines.push(` + ${f}`);
825
- if (result.removed.length > 0) lines.push(`${countNoun(result.removed.length, "file")} indexed but gone from disk (${dropVerb}):`);
826
- for (const f of result.removed) lines.push(` - ${f}`);
827
- lines.push(`Checked ${countNoun(result.scanned, "file")} in ${result.elapsedMs}ms.`);
828
- }
829
- if (result.mtimeOnly > 0) {
830
- lines.push(`${countNoun(result.mtimeOnly, "file")} had a newer timestamp but identical content, so ${result.mtimeOnly === 1 ? "it was" : "they were"} left alone.`);
831
- }
832
- if (result.parserStale > 0) {
833
- const reparseVerb = opts.dryRun === true ? "would reparse" : "queued for reparse";
834
- lines.push(`${countNoun(result.parserStale, "file")} of the above ${result.parserStale === 1 ? "was" : "were"} unchanged on disk but indexed by an older parser (${reparseVerb}).`);
835
- }
836
- if (result.embedStale > 0) {
837
- const reembedVerb = opts.dryRun === true ? "would re-embed" : "queued for re-embedding";
838
- lines.push(`${countNoun(result.embedStale, "file")} of the above ${result.embedStale === 1 ? "was" : "were"} unchanged on disk but held out-of-date embeddings (${reembedVerb}).`);
839
- }
840
- if (result.trackedUnavailable) {
841
- lines.push("This project has an index but git listed no files in it, so nothing on disk was compared against it and changed or new files could not be found. Files gone from disk were still detected. Run token-goat inside the repository, or reindex with --walk if this directory is deliberately not under git.");
842
- }
843
- if (result.budgetExhausted) {
844
- lines.push(`Stopped at the ${result.elapsedMs}ms budget with ${countNoun(result.unscanned, "file")} unchecked, so there may be more drift; deletions were not computed at all, because an unchecked file is indistinguishable from a deleted one. Raise --budget-ms for a complete sweep.`);
845
- }
846
- process.stdout.write(`${lines.join("\n")}
847
- `);
848
- return 0;
849
- }
850
- function isReconcileClean(r) {
851
- return r.changed.length === 0 && r.added.length === 0 && r.removed.length === 0;
852
- }
853
- function reconcileProject(opts = {}) {
854
- const cwd = opts.cwd ?? process.cwd();
855
- const budgetMs = opts.budgetMs ?? DEFAULT_RECONCILE_BUDGET_MS;
856
- const startedAt = Date.now();
857
- const dbPath = opts.dbPath ?? globalDbPath();
858
- const tracked = getTrackedFiles(cwd);
859
- const projectRoot = resolveIndexPath(".", cwd);
860
- const indexed = getProjectFileEntries(projectRoot, dbPath);
861
- const chunkScope = projectScopeClause("file_path");
862
- const chunked = new Set(
863
- getDb(dbPath).prepare(`SELECT DISTINCT file_path FROM chunks WHERE ${chunkScope.clause}`).pluck().all(...chunkScope.params(projectRoot)).map((p) => foldPath(normalizePath(p)))
864
- );
865
- let scanOrder = tracked;
866
- const cursorPath = tracked.length > 0 ? readReconcileCursor(dbPath, projectRoot) : null;
867
- if (cursorPath !== null) {
868
- const cursorFolded = foldPath(normalizePath(cursorPath));
869
- const cursorIdx = tracked.findIndex((f) => foldPath(normalizePath(f)) === cursorFolded);
870
- if (cursorIdx !== -1) {
871
- scanOrder = [...tracked.slice(cursorIdx + 1), ...tracked.slice(0, cursorIdx + 1)];
872
- }
873
- }
874
- const changed = [];
875
- const added = [];
876
- const seenOnDisk = /* @__PURE__ */ new Set();
877
- let mtimeOnly = 0;
878
- let parserStale = 0;
879
- let embedStale = 0;
880
- let scanned = 0;
881
- let budgetExhausted = false;
882
- let lastScanned = null;
883
- for (const file of scanOrder) {
884
- if (Date.now() - startedAt > budgetMs) {
885
- budgetExhausted = true;
886
- break;
887
- }
888
- scanned++;
889
- lastScanned = file;
890
- const folded = foldPath(normalizePath(file));
891
- seenOnDisk.add(folded);
892
- const entry = indexed.get(folded);
893
- if (entry === void 0) {
894
- added.push(file);
895
- continue;
896
- }
897
- if (entry.parserSha !== parserFingerprintForLanguage(entry.language)) {
898
- changed.push(file);
899
- parserStale++;
900
- continue;
901
- }
902
- if (entry.embedSha === "" && chunked.has(folded)) {
903
- changed.push(file);
904
- embedStale++;
905
- continue;
906
- }
907
- let mtimeMs;
908
- try {
909
- mtimeMs = fs2.statSync(file).mtimeMs;
910
- } catch {
911
- changed.push(file);
912
- continue;
913
- }
914
- if (entry.mtime !== 0 && mtimeMs / 1e3 === entry.mtime) continue;
915
- const diskSha = fingerprintFile(file);
916
- if (diskSha === null) {
917
- changed.push(file);
918
- continue;
919
- }
920
- if (diskSha === entry.sha) {
921
- mtimeOnly++;
922
- continue;
923
- }
924
- changed.push(file);
925
- }
926
- const trackedUnavailable = tracked.length === 0 && indexed.size > 0;
927
- const removed = [];
928
- if (!budgetExhausted) {
929
- for (const [folded, entry] of indexed) {
930
- if (seenOnDisk.has(folded)) continue;
931
- if (Date.now() - startedAt > budgetMs) {
932
- budgetExhausted = true;
933
- removed.length = 0;
934
- break;
935
- }
936
- try {
937
- fs2.statSync(entry.filePath);
938
- } catch (err) {
939
- const code = err?.code;
940
- if (code === "ENOENT" || code === "ENOTDIR") removed.push(entry.filePath);
941
- }
942
- }
943
- }
944
- let enqueued = 0;
945
- if (opts.dryRun !== true) {
946
- const toEnqueue = [...changed, ...added, ...removed].map((p) => resolveIndexPath(p, cwd));
947
- enqueueDirtyPathsSafe(toEnqueue, { alreadyResolved: true });
948
- enqueued = toEnqueue.length;
949
- if (budgetExhausted) {
950
- if (lastScanned !== null) writeReconcileCursor(dbPath, projectRoot, lastScanned);
951
- } else if (tracked.length > 0) {
952
- clearReconcileCursor(dbPath, projectRoot);
953
- }
954
- }
955
- return {
956
- scanned,
957
- changed,
958
- added,
959
- removed,
960
- mtimeOnly,
961
- parserStale,
962
- embedStale,
963
- budgetExhausted,
964
- trackedUnavailable,
965
- unscanned: Math.max(0, tracked.length - scanned),
966
- enqueued,
967
- elapsedMs: Date.now() - startedAt
968
- };
669
+ function buildReminder(indexed) {
670
+ return (indexed ? INDEXED_REMINDER : GENERIC_REMINDER) + NOTE_REMINDER;
969
671
  }
970
672
 
971
- // src/cli_recall.ts
673
+ // src/mcp_tool_pattern.ts
972
674
  init_define_import_meta_env();
973
- var RECALL_COMMAND = {
974
- bash: "bash-output",
975
- web: "web-output",
976
- mcp: "mcp-output"
977
- };
978
- function fenceTagForCacheType(cacheType) {
979
- return cacheType === "web" ? UNTRUSTED_WEB_TAG : UNTRUSTED_TOOL_TAG;
980
- }
981
- function fenceRecallListing(text, hits) {
982
- const tags = new Set(hits.map((hit) => fenceTagForCacheType(hit.cacheType)));
983
- const tag = tags.size === 1 ? [...tags][0] ?? UNTRUSTED_TOOL_TAG : UNTRUSTED_TOOL_TAG;
984
- return fenceUntrusted(text, tag);
985
- }
986
- function fenceSnippetIfMatched(hit) {
987
- const matches = scanAndRecord(hit.snippet);
988
- if (matches.length === 0) return hit.snippet;
989
- return fenceUntrustedContent(hit.snippet, matches, fenceTagForCacheType(hit.cacheType));
990
- }
991
- function printHits(query, hits) {
992
- const w = (text) => {
993
- process.stdout.write(text);
994
- };
995
- if (hits.length === 0) {
996
- w(query === void 0 ? "No cache entries yet.\n" : `No cache entries match: ${query}
997
- `);
998
- return;
999
- }
1000
- const body = hits.map((hit) => {
1001
- const label = hit.label.length > 80 ? hit.label.slice(0, 77) + "..." : hit.label;
1002
- const pointer = hit.blobPresent ? ` (token-goat ${RECALL_COMMAND[hit.cacheType]} ${hit.id})` : " (blob expired -- content below is all that remains)";
1003
- return `[${pad(hit.cacheType, 4)}] ${hit.id}
1004
- ${pointer}
1005
- ${label}
1006
- ${hit.snippet}
1007
- `;
1008
- }).join("\n");
1009
- w(`${fenceRecallListing(body, hits)}
1010
- `);
1011
- }
1012
- function runRecallCommand(query, opts = {}) {
1013
- const browse = query === void 0 || query.trim() === "";
1014
- const scope = {
1015
- ...opts.type !== void 0 ? { type: opts.type } : {},
1016
- ...opts.limit !== void 0 ? { limit: opts.limit } : {}
1017
- };
1018
- const effectiveLimit = opts.limit ?? RECALL_DEFAULT_LIMIT;
1019
- const fetched = browse ? listRecentRecall({ ...scope, limit: effectiveLimit + 1 }) : searchRecall(query, { ...scope, limit: effectiveLimit + 1 });
1020
- const hits = fetched.slice(0, effectiveLimit);
1021
- if (fetched.length > hits.length) {
1022
- process.stderr.write(`Showing ${hits.length} entries; more are available (raise --limit to see them).
1023
- `);
1024
- }
1025
- if (opts.json === true) {
1026
- const fenced = hits.map((hit) => ({ ...hit, snippet: fenceSnippetIfMatched(hit) }));
1027
- process.stdout.write(`${displaySafeJson(fenced, 0)}
1028
- `);
1029
- return;
1030
- }
1031
- printHits(browse ? void 0 : query, hits);
1032
- }
675
+ var MCP_TOOL_PATTERN = "^mcp__";
1033
676
 
1034
677
  export {
1035
- checkSymbolBodySize,
1036
- MCP_TOOL_PATTERN,
1037
- WEB_OUTPUT_SUBDIR,
1038
- storeWebOutput,
1039
- getWebOutput,
1040
- getWebOutputRaw,
1041
- getWebOutputByUrlFromDisk,
1042
- DEFAULT_RECONCILE_BUDGET_MS,
1043
- runReconcile,
1044
- isReconcileClean,
1045
- reconcileProject,
1046
- RECALL_COMMAND,
1047
- runRecallCommand,
1048
- MAX_STDIN_BYTES,
1049
678
  readStdinJson,
1050
679
  diagnoseSqlFailure,
1051
680
  cmdSessionSchema,
1052
681
  cmdDescribe,
1053
- HOOK_EVENTS,
1054
682
  buildCommandManifest,
1055
683
  flattenCommandNames,
1056
684
  filterCommandManifest,
1057
- formatCommandManifest
685
+ formatCommandManifest,
686
+ checkSymbolBodySize,
687
+ isIndexedProject,
688
+ buildReminder,
689
+ MCP_TOOL_PATTERN
1058
690
  };