token-goat 2.9.28 → 2.9.29

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 (77) hide show
  1. package/README.md +2 -0
  2. package/dist/{token-goat-chunk-OZRSREKR.mjs → token-goat-chunk-2AWQ2R5X.mjs} +2 -2
  3. package/dist/{token-goat-chunk-5NNYIUGV.mjs → token-goat-chunk-2NNUA2LR.mjs} +4 -4
  4. package/dist/{token-goat-chunk-4RN64ZND.mjs → token-goat-chunk-2WOUYWLM.mjs} +2 -1
  5. package/dist/{token-goat-chunk-HUDC5GS5.mjs → token-goat-chunk-435UQTKD.mjs} +5 -3
  6. package/dist/{token-goat-chunk-6DQNNFJ6.mjs → token-goat-chunk-44BM7DDQ.mjs} +3 -3
  7. package/dist/{token-goat-chunk-4JMWPWCS.mjs → token-goat-chunk-52NSDWYY.mjs} +2 -2
  8. package/dist/{token-goat-chunk-IHKZ3QNA.mjs → token-goat-chunk-67BNIKKO.mjs} +19 -16
  9. package/dist/{token-goat-chunk-XBESNWEX.mjs → token-goat-chunk-6AK46ZT7.mjs} +2 -3
  10. package/dist/{token-goat-chunk-M56BWPBN.mjs → token-goat-chunk-7CPMDFGB.mjs} +166 -40
  11. package/dist/token-goat-chunk-ASLWOQ3I.mjs +14 -0
  12. package/dist/{token-goat-chunk-QM76S6YS.mjs → token-goat-chunk-BGYOZ6DO.mjs} +6 -4
  13. package/dist/{token-goat-chunk-JXK2HQXS.mjs → token-goat-chunk-C5YPNZKQ.mjs} +3 -3
  14. package/dist/{token-goat-chunk-MVSWBNMD.mjs → token-goat-chunk-CIQ2FTY3.mjs} +19 -14
  15. package/dist/{token-goat-chunk-BJBRGPBX.mjs → token-goat-chunk-D4ETHJD6.mjs} +6 -4
  16. package/dist/{token-goat-chunk-VE27HPIF.mjs → token-goat-chunk-DNRPXHYH.mjs} +21 -17
  17. package/dist/{token-goat-chunk-YWSP6IU7.mjs → token-goat-chunk-DNSPXQXQ.mjs} +2 -2
  18. package/dist/token-goat-chunk-DPNLUJWB.mjs +220 -0
  19. package/dist/{token-goat-chunk-I7CB3X4K.mjs → token-goat-chunk-E4ZOJIZK.mjs} +10 -7
  20. package/dist/{token-goat-chunk-IZXKVT4A.mjs → token-goat-chunk-E5TK5DNO.mjs} +11 -4
  21. package/dist/{token-goat-chunk-MMLMALWK.mjs → token-goat-chunk-EUSDXRXU.mjs} +60 -12
  22. package/dist/{token-goat-chunk-7R2XYKC5.mjs → token-goat-chunk-FTP4U4QA.mjs} +12 -9
  23. package/dist/{token-goat-chunk-LEG3JNJ6.mjs → token-goat-chunk-G23DWHV4.mjs} +17 -14
  24. package/dist/{token-goat-chunk-L7SDVGBT.mjs → token-goat-chunk-G7IWXCFF.mjs} +49 -23
  25. package/dist/{token-goat-chunk-NILVK7XM.mjs → token-goat-chunk-GLXRTTLE.mjs} +7 -5
  26. package/dist/{token-goat-chunk-6CCQDAYY.mjs → token-goat-chunk-H5J3C56Q.mjs} +35 -16
  27. package/dist/{token-goat-chunk-Q4S3UQGO.mjs → token-goat-chunk-HNFZZHFW.mjs} +2 -2
  28. package/dist/{token-goat-chunk-CBMY2FGI.mjs → token-goat-chunk-HUYUHODZ.mjs} +572 -230
  29. package/dist/token-goat-chunk-IVE6U7KV.mjs +53 -0
  30. package/dist/{token-goat-chunk-F7QZRIWM.mjs → token-goat-chunk-IVWI2OCK.mjs} +8 -30
  31. package/dist/{token-goat-chunk-GMOUBOX4.mjs → token-goat-chunk-JTKCQMQA.mjs} +37 -5
  32. package/dist/{token-goat-chunk-6SGLIPQB.mjs → token-goat-chunk-KOPIR3KZ.mjs} +12 -9
  33. package/dist/token-goat-chunk-L7H3U27L.mjs +35 -0
  34. package/dist/{token-goat-chunk-FSTWAOW6.mjs → token-goat-chunk-LZNBQTDK.mjs} +6 -4
  35. package/dist/token-goat-chunk-MELOKFDJ.mjs +199 -0
  36. package/dist/{token-goat-chunk-VWZKZPSR.mjs → token-goat-chunk-NMBWLRHW.mjs} +76 -39
  37. package/dist/{token-goat-chunk-HXNAC4ZF.mjs → token-goat-chunk-O6I2XU4P.mjs} +12 -10
  38. package/dist/{token-goat-chunk-MAMQPC43.mjs → token-goat-chunk-ONXH6NZ5.mjs} +1 -1
  39. package/dist/token-goat-chunk-ORNFMIER.mjs +295 -0
  40. package/dist/{token-goat-chunk-66LODAUT.mjs → token-goat-chunk-PGTH2U4C.mjs} +1 -1
  41. package/dist/{token-goat-chunk-SJEKA7Y2.mjs → token-goat-chunk-PKRWMHVP.mjs} +76 -64
  42. package/dist/{token-goat-chunk-DA43OE7L.mjs → token-goat-chunk-PQ53BSCF.mjs} +1 -1
  43. package/dist/{token-goat-chunk-RSS3TLXU.mjs → token-goat-chunk-PYSUADX4.mjs} +2 -2
  44. package/dist/{token-goat-chunk-EL7M26WP.mjs → token-goat-chunk-QO3LXVVR.mjs} +185 -104
  45. package/dist/{token-goat-chunk-XI2VFAV6.mjs → token-goat-chunk-RLP6J7WR.mjs} +6 -6
  46. package/dist/token-goat-chunk-RQGGMPCR.mjs +205 -0
  47. package/dist/{token-goat-chunk-6Z5ULNE5.mjs → token-goat-chunk-RTMVLHWX.mjs} +165 -60
  48. package/dist/{token-goat-chunk-E3K3BTEQ.mjs → token-goat-chunk-S4VSXURL.mjs} +8 -6
  49. package/dist/{token-goat-chunk-LKSXAMJB.mjs → token-goat-chunk-SE6E4BKJ.mjs} +1 -1
  50. package/dist/token-goat-chunk-TCQANXYC.mjs +351 -0
  51. package/dist/{token-goat-chunk-GGLEE35R.mjs → token-goat-chunk-TDUT2CL6.mjs} +7 -7
  52. package/dist/{token-goat-chunk-CC2PYJM7.mjs → token-goat-chunk-TGOXNAHW.mjs} +54 -112
  53. package/dist/{token-goat-chunk-XKY4VKJ4.mjs → token-goat-chunk-UA5BKWWQ.mjs} +1 -1
  54. package/dist/{token-goat-chunk-UBUKHVYW.mjs → token-goat-chunk-UXSXQQIY.mjs} +1 -1
  55. package/dist/{token-goat-chunk-D5ICEPSB.mjs → token-goat-chunk-VMFWNHGR.mjs} +79 -68
  56. package/dist/token-goat-chunk-VQ6F6T7X.mjs +36 -0
  57. package/dist/{token-goat-chunk-4STDIGYC.mjs → token-goat-chunk-VZQEWRVH.mjs} +6 -4
  58. package/dist/{token-goat-chunk-OSUFN2FV.mjs → token-goat-chunk-XB5KKOCG.mjs} +5 -25
  59. package/dist/{token-goat-chunk-L45ZQRT7.mjs → token-goat-chunk-XYWPOSCN.mjs} +57 -615
  60. package/dist/{token-goat-chunk-4JJBFT7V.mjs → token-goat-chunk-YAGLESS3.mjs} +8 -5
  61. package/dist/token-goat-chunk-YKSRAWUU.mjs +33 -0
  62. package/dist/{token-goat-chunk-F2ARFHLJ.mjs → token-goat-chunk-YOOVFPTP.mjs} +2 -2
  63. package/dist/{token-goat-chunk-EEIDFMEM.mjs → token-goat-chunk-YZAAZU2S.mjs} +12 -3
  64. package/dist/token-goat-chunk-Z6KBMOBI.mjs +53 -0
  65. package/dist/{token-goat-chunk-RJH64KQH.mjs → token-goat-chunk-ZER6EAXZ.mjs} +3 -3
  66. package/dist/token-goat-hook-client.cjs +475 -0
  67. package/dist/token-goat-hook-client.mjs +26 -0
  68. package/dist/token-goat-hook.mjs +31 -27
  69. package/dist/token-goat.core.mjs +9 -44
  70. package/docs/C4_RUNTIME_ARCHITECTURE.md +2 -2
  71. package/docs/cli.md +3 -2
  72. package/docs/install.md +16 -14
  73. package/package.json +1 -1
  74. package/dist/token-goat-chunk-7MAFDRVR.mjs +0 -47
  75. package/dist/token-goat-chunk-BCN2YQC6.mjs +0 -32
  76. package/dist/token-goat-chunk-D7GHQKQD.mjs +0 -30
  77. package/dist/token-goat-chunk-IFORDBGC.mjs +0 -192
package/README.md CHANGED
@@ -440,6 +440,8 @@ The file-by-file table for each harness, and the path that file sits at: **[What
440
440
 
441
441
  Hooks fire automatically on every tool call once installed — nothing to start or restart there. The background worker is a separate, manual step: `token-goat worker start` launches it as a detached process, `token-goat worker status` checks it, `token-goat worker stop` kills it. It restarts itself automatically if it crashes or gets killed while the machine is running — an edit hook checks its liveness and respawns it, rate-limited to about once every 5 minutes. It does not survive a reboot or logout, though; re-run `worker start` after either. `token-goat uninstall` removes the hook entries, `CLAUDE.md` block, and skill directory, but does not touch a running worker — stop it separately with `token-goat worker stop` if you no longer want it running.
442
442
 
443
+ Hooks also answer faster after the first call. That call starts a small resident process, the hook server, and later hook calls go to it instead of starting Node and loading token-goat each time. In measurements on Windows that took a hook call from 110 to 135 ms down to about 70 ms in Claude Code, Codex, Copilot CLI and VS Code chat, and a read command such as `token-goat section` from 122 ms to 60 ms when its output goes to the agent rather than a terminal. You never start it yourself. It stops after 30 minutes idle, after an upgrade, when you turn it off, and when `uninstall --purge` runs. `token-goat hook-server status` shows what is running and `token-goat hook-server stop` stops it. To turn it off, set `server = false` under `[hooks]` in your global config, or `TOKEN_GOAT_HOOK_SERVER=0`. A project's `.token-goat.toml` cannot change this setting, because one server answers every project.
444
+
443
445
  To move to a newer release, `token-goat upgrade` installs it from npm and then re-runs `token-goat install`, so your hooks and integration manifests point at the build that just landed. `token-goat upgrade --check` reports whether one is available without installing anything, and `--json` gives the same answer for a script. Both go quiet when `network.offline` is set, and `token-goat doctor` mentions an available update at the end of its report.
444
446
 
445
447
  ## Verify
@@ -11,8 +11,8 @@ import {
11
11
  openReadonlySqlite,
12
12
  runReadOnlySqliteQuery,
13
13
  validateReadOnlySelect
14
- } from "./token-goat-chunk-DA43OE7L.mjs";
15
- import "./token-goat-chunk-OSUFN2FV.mjs";
14
+ } from "./token-goat-chunk-PQ53BSCF.mjs";
15
+ import "./token-goat-chunk-XB5KKOCG.mjs";
16
16
  import "./token-goat-chunk-NMTKNYGF.mjs";
17
17
  import "./token-goat-chunk-A37V4PBF.mjs";
18
18
  export {
@@ -2,13 +2,13 @@ import { createRequire as __cjsRequire } from 'node:module';
2
2
  const require = __cjsRequire(import.meta.url);
3
3
  import {
4
4
  loadConfig
5
- } from "./token-goat-chunk-CC2PYJM7.mjs";
6
- import {
7
- VERSION
8
- } from "./token-goat-chunk-L45ZQRT7.mjs";
5
+ } from "./token-goat-chunk-TGOXNAHW.mjs";
9
6
  import {
10
7
  displaySafeJson
11
8
  } from "./token-goat-chunk-NMTKNYGF.mjs";
9
+ import {
10
+ VERSION
11
+ } from "./token-goat-chunk-MELOKFDJ.mjs";
12
12
  import {
13
13
  init_define_import_meta_env
14
14
  } from "./token-goat-chunk-A37V4PBF.mjs";
@@ -2,7 +2,7 @@ import { createRequire as __cjsRequire } from 'node:module';
2
2
  const require = __cjsRequire(import.meta.url);
3
3
  import {
4
4
  stripAnsiEscapes
5
- } from "./token-goat-chunk-MVSWBNMD.mjs";
5
+ } from "./token-goat-chunk-CIQ2FTY3.mjs";
6
6
  import {
7
7
  init_define_import_meta_env
8
8
  } from "./token-goat-chunk-A37V4PBF.mjs";
@@ -917,6 +917,7 @@ export {
917
917
  ERROR_SIGNAL_RE,
918
918
  TIMESTAMP_PREFIX_RE,
919
919
  REDIRECT_TOKEN_RE,
920
+ maskQuotedSpans,
920
921
  hasBareBackgroundOrNewline,
921
922
  hasBareBackground,
922
923
  isRedirectAmpersand,
@@ -2,15 +2,17 @@ import { createRequire as __cjsRequire } from 'node:module';
2
2
  const require = __cjsRequire(import.meta.url);
3
3
  import {
4
4
  getDb
5
- } from "./token-goat-chunk-M56BWPBN.mjs";
5
+ } from "./token-goat-chunk-7CPMDFGB.mjs";
6
6
  import {
7
7
  foldPath,
8
- globalDbPath,
9
8
  isCaseInsensitiveFs
10
- } from "./token-goat-chunk-L45ZQRT7.mjs";
9
+ } from "./token-goat-chunk-TCQANXYC.mjs";
11
10
  import {
12
11
  normalizePath
13
12
  } from "./token-goat-chunk-NMTKNYGF.mjs";
13
+ import {
14
+ globalDbPath
15
+ } from "./token-goat-chunk-MELOKFDJ.mjs";
14
16
  import {
15
17
  init_define_import_meta_env
16
18
  } from "./token-goat-chunk-A37V4PBF.mjs";
@@ -5,15 +5,15 @@ import {
5
5
  claudeConfigDir,
6
6
  createResidentContextStats,
7
7
  summarizeResidentContext
8
- } from "./token-goat-chunk-MAMQPC43.mjs";
8
+ } from "./token-goat-chunk-ONXH6NZ5.mjs";
9
9
  import {
10
10
  commandHash,
11
11
  getBashOutput,
12
12
  normalizeCommandForCacheKey
13
- } from "./token-goat-chunk-HXNAC4ZF.mjs";
13
+ } from "./token-goat-chunk-O6I2XU4P.mjs";
14
14
  import {
15
15
  estimateTokens
16
- } from "./token-goat-chunk-4JMWPWCS.mjs";
16
+ } from "./token-goat-chunk-52NSDWYY.mjs";
17
17
  import {
18
18
  init_define_import_meta_env
19
19
  } from "./token-goat-chunk-A37V4PBF.mjs";
@@ -4,10 +4,10 @@ import {
4
4
  classifyContent,
5
5
  guardDivisor,
6
6
  stripAnsiEscapes
7
- } from "./token-goat-chunk-MVSWBNMD.mjs";
7
+ } from "./token-goat-chunk-CIQ2FTY3.mjs";
8
8
  import {
9
9
  safeSlice
10
- } from "./token-goat-chunk-L45ZQRT7.mjs";
10
+ } from "./token-goat-chunk-XYWPOSCN.mjs";
11
11
  import {
12
12
  init_define_import_meta_env
13
13
  } from "./token-goat-chunk-A37V4PBF.mjs";
@@ -6,29 +6,32 @@ import {
6
6
  findProjectSession,
7
7
  isCopilotTranscript,
8
8
  unusedMcpServers
9
- } from "./token-goat-chunk-JXK2HQXS.mjs";
9
+ } from "./token-goat-chunk-C5YPNZKQ.mjs";
10
10
  import {
11
11
  buildWasteReport
12
- } from "./token-goat-chunk-6DQNNFJ6.mjs";
13
- import "./token-goat-chunk-MMLMALWK.mjs";
14
- import "./token-goat-chunk-MAMQPC43.mjs";
15
- import "./token-goat-chunk-HXNAC4ZF.mjs";
16
- import "./token-goat-chunk-BJBRGPBX.mjs";
17
- import "./token-goat-chunk-4JMWPWCS.mjs";
18
- import "./token-goat-chunk-4RN64ZND.mjs";
19
- import "./token-goat-chunk-MVSWBNMD.mjs";
20
- import "./token-goat-chunk-HUDC5GS5.mjs";
21
- import "./token-goat-chunk-M56BWPBN.mjs";
12
+ } from "./token-goat-chunk-44BM7DDQ.mjs";
13
+ import "./token-goat-chunk-EUSDXRXU.mjs";
14
+ import "./token-goat-chunk-ONXH6NZ5.mjs";
15
+ import "./token-goat-chunk-O6I2XU4P.mjs";
16
+ import "./token-goat-chunk-D4ETHJD6.mjs";
17
+ import "./token-goat-chunk-52NSDWYY.mjs";
18
+ import "./token-goat-chunk-2WOUYWLM.mjs";
19
+ import "./token-goat-chunk-CIQ2FTY3.mjs";
20
+ import "./token-goat-chunk-435UQTKD.mjs";
21
+ import "./token-goat-chunk-7CPMDFGB.mjs";
22
22
  import {
23
23
  resolveProjectRoot
24
- } from "./token-goat-chunk-CC2PYJM7.mjs";
25
- import "./token-goat-chunk-EEIDFMEM.mjs";
26
- import "./token-goat-chunk-OSUFN2FV.mjs";
27
- import "./token-goat-chunk-L45ZQRT7.mjs";
24
+ } from "./token-goat-chunk-TGOXNAHW.mjs";
25
+ import "./token-goat-chunk-XB5KKOCG.mjs";
26
+ import "./token-goat-chunk-YZAAZU2S.mjs";
27
+ import "./token-goat-chunk-IVE6U7KV.mjs";
28
+ import "./token-goat-chunk-XYWPOSCN.mjs";
29
+ import "./token-goat-chunk-TCQANXYC.mjs";
28
30
  import {
29
31
  displaySafeJson
30
32
  } from "./token-goat-chunk-NMTKNYGF.mjs";
31
- import "./token-goat-chunk-GMOUBOX4.mjs";
33
+ import "./token-goat-chunk-MELOKFDJ.mjs";
34
+ import "./token-goat-chunk-JTKCQMQA.mjs";
32
35
  import {
33
36
  init_define_import_meta_env
34
37
  } from "./token-goat-chunk-A37V4PBF.mjs";
@@ -20,13 +20,12 @@ var SUPPORTED_PROTOCOL_VERSIONS = [
20
20
  var JSONRPC_INVALID_REQUEST = -32600;
21
21
  var JSONRPC_METHOD_NOT_FOUND = -32601;
22
22
  var JSONRPC_INVALID_PARAMS = -32602;
23
- var DRAFT_07_SCHEMA_ID = "http://json-schema.org/draft-07/schema#";
24
23
  var MCP_INVALID_PARAMS_PREFIX = `MCP error ${JSONRPC_INVALID_PARAMS}: `;
25
24
  var EMPTY_OBJECT_JSON_SCHEMA = { type: "object", properties: {} };
26
25
  function buildJsonSchema(shape) {
27
26
  if (shape === void 0 || Object.keys(shape).length === 0) return { ...EMPTY_OBJECT_JSON_SCHEMA };
28
- const schema = external_exports.toJSONSchema(external_exports.object(shape), { io: "input" });
29
- return { ...schema, $schema: DRAFT_07_SCHEMA_ID };
27
+ const { $schema: _dialect, ...schema } = external_exports.toJSONSchema(external_exports.object(shape), { io: "input" });
28
+ return schema;
30
29
  }
31
30
  function describeParseError(error) {
32
31
  return error.issues.map((issue) => {
@@ -1,24 +1,28 @@
1
1
  import { createRequire as __cjsRequire } from 'node:module';
2
2
  const require = __cjsRequire(import.meta.url);
3
- import {
4
- registerReset
5
- } from "./token-goat-chunk-EEIDFMEM.mjs";
6
3
  import {
7
4
  Database
8
- } from "./token-goat-chunk-OSUFN2FV.mjs";
5
+ } from "./token-goat-chunk-XB5KKOCG.mjs";
6
+ import {
7
+ registerReset
8
+ } from "./token-goat-chunk-YZAAZU2S.mjs";
9
9
  import {
10
- SYMBOL_BODY_CHAR_CAP,
11
10
  countContentLines,
12
- dataDir,
13
11
  ensureDirSync,
14
- escapeRegExp,
12
+ escapeRegExp
13
+ } from "./token-goat-chunk-XYWPOSCN.mjs";
14
+ import {
15
15
  foldCase,
16
16
  foldPath,
17
17
  sleepSync
18
- } from "./token-goat-chunk-L45ZQRT7.mjs";
18
+ } from "./token-goat-chunk-TCQANXYC.mjs";
19
19
  import {
20
20
  safeJoin
21
21
  } from "./token-goat-chunk-NMTKNYGF.mjs";
22
+ import {
23
+ SYMBOL_BODY_CHAR_CAP,
24
+ dataDir
25
+ } from "./token-goat-chunk-MELOKFDJ.mjs";
22
26
  import {
23
27
  init_define_import_meta_env
24
28
  } from "./token-goat-chunk-A37V4PBF.mjs";
@@ -2313,7 +2317,7 @@ function runMigrations(conn, fromVersion, toVersion) {
2313
2317
  }
2314
2318
  }
2315
2319
  var WAL_SWITCH_DEADLINE_MS = 15e3;
2316
- function enableWalWithRetry(conn, budgetMs = WAL_SWITCH_DEADLINE_MS) {
2320
+ function enableWalWithRetry(conn, budgetMs = WAL_SWITCH_DEADLINE_MS, stopOn) {
2317
2321
  const deadline = Date.now() + budgetMs;
2318
2322
  let lastError;
2319
2323
  for (; ; ) {
@@ -2323,55 +2327,147 @@ function enableWalWithRetry(conn, budgetMs = WAL_SWITCH_DEADLINE_MS) {
2323
2327
  lastError = new Error(`got: ${String(mode)}`);
2324
2328
  } catch (e) {
2325
2329
  lastError = e;
2330
+ if (isDamagedDatabaseError(e) || stopOn?.(e) === true) throw walSwitchError(e);
2326
2331
  }
2327
2332
  try {
2328
2333
  if (String(conn.pragma("journal_mode", { simple: true })).toLowerCase() === "wal") return;
2329
2334
  } catch {
2330
2335
  }
2331
- if (Date.now() >= deadline) {
2332
- throw new Error(`db: failed to enable WAL mode (${lastError instanceof Error ? lastError.message : String(lastError)})`);
2333
- }
2336
+ if (Date.now() >= deadline) throw walSwitchError(lastError);
2334
2337
  sleepSync(25);
2335
2338
  }
2336
2339
  }
2337
- function initConnection(conn) {
2340
+ function isDamagedDatabaseError(e) {
2341
+ const code = e?.code;
2342
+ return typeof code === "string" && /^SQLITE_(?:NOTADB|CORRUPT)/.test(code);
2343
+ }
2344
+ function walSwitchError(lastError) {
2345
+ return new Error(`db: failed to enable WAL mode (${lastError instanceof Error ? lastError.message : String(lastError)})`, { cause: lastError });
2346
+ }
2347
+ function initConnection(conn, walStopOn) {
2338
2348
  conn.pragma("busy_timeout = 15000");
2339
- enableWalWithRetry(conn);
2349
+ enableWalWithRetry(conn, WAL_SWITCH_DEADLINE_MS, walStopOn);
2340
2350
  conn.pragma("synchronous = NORMAL");
2341
2351
  conn.pragma("cache_size = -32000");
2342
2352
  conn.pragma("temp_store = MEMORY");
2343
2353
  conn.pragma("mmap_size = 134217728");
2344
- conn.function(
2345
- "TG_LOWER",
2346
- { deterministic: true },
2347
- (value) => value === null ? null : foldCase(String(value))
2348
- );
2354
+ registerTgLower(conn);
2349
2355
  const storedVersion = Number(conn.pragma("user_version", { simple: true }));
2350
- if (storedVersion > SCHEMA_VERSION) {
2351
- throw new Error(
2352
- `db: index schema version ${storedVersion} is newer than this token-goat build supports (expected ${SCHEMA_VERSION}). Update token-goat, or delete the stale index database and let it rebuild.`
2353
- );
2354
- }
2356
+ if (storedVersion > SCHEMA_VERSION) throw newerSchemaError(storedVersion);
2355
2357
  conn.exec(SCHEMA_SQL);
2356
2358
  try {
2357
2359
  conn.exec(FTS_SQL);
2358
2360
  } catch {
2359
2361
  }
2360
- try {
2361
- const sqliteVec = _require("sqlite-vec");
2362
- sqliteVec.load(conn);
2363
- conn.exec(
2364
- `CREATE VIRTUAL TABLE IF NOT EXISTS chunk_vectors USING vec0(
2362
+ if (loadSqliteVec(conn)) {
2363
+ try {
2364
+ conn.exec(
2365
+ `CREATE VIRTUAL TABLE IF NOT EXISTS chunk_vectors USING vec0(
2365
2366
  embedding float[384]
2366
2367
  );`
2367
- );
2368
- } catch {
2368
+ );
2369
+ } catch {
2370
+ }
2369
2371
  }
2370
2372
  if (storedVersion < SCHEMA_VERSION) {
2371
2373
  runMigrations(conn, storedVersion, SCHEMA_VERSION);
2372
2374
  conn.pragma(`user_version = ${SCHEMA_VERSION}`);
2373
2375
  }
2374
2376
  }
2377
+ function newerSchemaError(storedVersion) {
2378
+ return new Error(
2379
+ `db: index schema version ${storedVersion} is newer than this token-goat build supports (expected ${SCHEMA_VERSION}). Update token-goat, or delete the stale index database and let it rebuild.`
2380
+ );
2381
+ }
2382
+ function registerTgLower(conn) {
2383
+ conn.function(
2384
+ "TG_LOWER",
2385
+ { deterministic: true },
2386
+ (value) => value === null ? null : foldCase(String(value))
2387
+ );
2388
+ }
2389
+ function loadSqliteVec(conn) {
2390
+ try {
2391
+ const sqliteVec = _require("sqlite-vec");
2392
+ sqliteVec.load(conn);
2393
+ return true;
2394
+ } catch {
2395
+ return false;
2396
+ }
2397
+ }
2398
+ var _readOnlyFallback;
2399
+ var _readOnlyConnections = /* @__PURE__ */ new Map();
2400
+ function allowReadOnlyIndex(onFirstUse) {
2401
+ _readOnlyFallback = { onFirstUse, used: false };
2402
+ }
2403
+ function isReadOnlyDb(dbPath) {
2404
+ if (_readOnlyFallback === void 0) return false;
2405
+ try {
2406
+ getDb(dbPath);
2407
+ } catch {
2408
+ return false;
2409
+ }
2410
+ return _readOnlyConnections.has(connectionKey(dbPath).key);
2411
+ }
2412
+ var WRITE_ACCESS_SQLITE_CODE_RE = /^SQLITE_(?:CANTOPEN|READONLY|PERM|IOERR_ACCESS|IOERR_SHMOPEN)/;
2413
+ var WRITE_ACCESS_FS_CODES = /* @__PURE__ */ new Set(["EACCES", "EPERM", "EROFS"]);
2414
+ function isWriteAccessError(e) {
2415
+ for (let cur = e, depth = 0; cur instanceof Error && depth < 4; cur = cur.cause, depth++) {
2416
+ const code = cur.code;
2417
+ if (typeof code === "string" && (WRITE_ACCESS_SQLITE_CODE_RE.test(code) || WRITE_ACCESS_FS_CODES.has(code))) return true;
2418
+ }
2419
+ return false;
2420
+ }
2421
+ function writeRefusal(resolved) {
2422
+ let fd;
2423
+ try {
2424
+ fd = fs2.openSync(resolved, "r+");
2425
+ } catch (e) {
2426
+ return isWriteAccessError(e) ? e : void 0;
2427
+ }
2428
+ fs2.closeSync(fd);
2429
+ return void 0;
2430
+ }
2431
+ function openReadOnlyAt(resolved, immutable) {
2432
+ const conn = new Database(resolved, { readonly: true, fileMustExist: true, immutable });
2433
+ try {
2434
+ conn.pragma("busy_timeout = 15000");
2435
+ return { conn, storedVersion: Number(conn.pragma("user_version", { simple: true })) };
2436
+ } catch (e) {
2437
+ try {
2438
+ conn.close();
2439
+ } catch {
2440
+ }
2441
+ throw e;
2442
+ }
2443
+ }
2444
+ function openIndexReadOnly(resolved) {
2445
+ let opened;
2446
+ try {
2447
+ opened = openReadOnlyAt(resolved, false);
2448
+ } catch (e) {
2449
+ if (!isWriteAccessError(e)) throw e;
2450
+ opened = openReadOnlyAt(resolved, true);
2451
+ }
2452
+ const { conn, storedVersion } = opened;
2453
+ try {
2454
+ if (storedVersion > SCHEMA_VERSION) throw newerSchemaError(storedVersion);
2455
+ if (storedVersion < SCHEMA_VERSION) {
2456
+ throw new Error(
2457
+ `db: index schema version ${storedVersion} predates this token-goat build (expected ${SCHEMA_VERSION}) and cannot be upgraded without write access. Run token-goat once where its data directory is writable.`
2458
+ );
2459
+ }
2460
+ registerTgLower(conn);
2461
+ loadSqliteVec(conn);
2462
+ } catch (e) {
2463
+ try {
2464
+ conn.close();
2465
+ } catch {
2466
+ }
2467
+ throw e;
2468
+ }
2469
+ return conn;
2470
+ }
2375
2471
  function resolveDbPath(dbPath) {
2376
2472
  if (path2.isAbsolute(dbPath)) return dbPath;
2377
2473
  if (dbPath.includes("/") || dbPath.includes("\\")) return path2.resolve(dbPath);
@@ -2385,35 +2481,63 @@ function getDb(dbPath) {
2385
2481
  const { resolved, key } = connectionKey(dbPath);
2386
2482
  const existing = _connections.get(key);
2387
2483
  if (existing !== void 0) return existing;
2484
+ const fallback = _readOnlyFallback;
2485
+ if (fallback !== void 0) {
2486
+ const readOnly = _readOnlyConnections.get(key);
2487
+ if (readOnly !== void 0) return readOnly;
2488
+ const refused = writeRefusal(resolved);
2489
+ if (refused !== void 0) return openReadOnlyFallback(resolved, key, fallback, refused);
2490
+ }
2388
2491
  const dir = path2.dirname(resolved);
2389
2492
  try {
2390
2493
  ensureDirSync(dir);
2391
2494
  } catch (e) {
2392
2495
  if (e.code !== "EEXIST" || !fs2.existsSync(dir)) throw e;
2393
2496
  }
2394
- const conn = new Database(resolved);
2497
+ let conn;
2395
2498
  try {
2396
- initConnection(conn);
2499
+ conn = new Database(resolved);
2500
+ initConnection(conn, fallback !== void 0 ? isWriteAccessError : void 0);
2397
2501
  } catch (e) {
2398
2502
  try {
2399
- conn.close();
2503
+ conn?.close();
2400
2504
  } catch {
2401
2505
  }
2506
+ if (fallback !== void 0 && isWriteAccessError(e)) return openReadOnlyFallback(resolved, key, fallback, e);
2402
2507
  throw e;
2403
2508
  }
2404
2509
  _connections.set(key, conn);
2405
2510
  return conn;
2406
2511
  }
2512
+ function openReadOnlyFallback(resolved, key, fallback, writeError) {
2513
+ let conn;
2514
+ try {
2515
+ conn = openIndexReadOnly(resolved);
2516
+ } catch (e) {
2517
+ throw isWriteAccessError(e) || !fs2.existsSync(resolved) ? writeError : e;
2518
+ }
2519
+ _readOnlyConnections.set(key, conn);
2520
+ if (!fallback.used) {
2521
+ fallback.used = true;
2522
+ fallback.onFirstUse();
2523
+ }
2524
+ return conn;
2525
+ }
2407
2526
  function closeAllDbs() {
2408
- for (const conn of _connections.values()) {
2409
- try {
2410
- conn.close();
2411
- } catch {
2527
+ for (const cache of [_connections, _readOnlyConnections]) {
2528
+ for (const conn of cache.values()) {
2529
+ try {
2530
+ conn.close();
2531
+ } catch {
2532
+ }
2412
2533
  }
2534
+ cache.clear();
2413
2535
  }
2414
- _connections.clear();
2415
2536
  }
2416
- registerReset(closeAllDbs);
2537
+ registerReset(closeAllDbs, { perRequest: true });
2538
+ registerReset(() => {
2539
+ _readOnlyFallback = void 0;
2540
+ }, { perRequest: true });
2417
2541
 
2418
2542
  export {
2419
2543
  precedingDocComment,
@@ -2470,5 +2594,7 @@ export {
2470
2594
  unsupportedLanguageName,
2471
2595
  isDotenvPath,
2472
2596
  redactIfDotenv,
2597
+ allowReadOnlyIndex,
2598
+ isReadOnlyDb,
2473
2599
  getDb
2474
2600
  };
@@ -0,0 +1,14 @@
1
+ import { createRequire as __cjsRequire } from 'node:module';
2
+ const require = __cjsRequire(import.meta.url);
3
+ import {
4
+ serveBatch,
5
+ serveOne,
6
+ swapEnv
7
+ } from "./token-goat-chunk-S4VSXURL.mjs";
8
+ import "./token-goat-chunk-YZAAZU2S.mjs";
9
+ import "./token-goat-chunk-A37V4PBF.mjs";
10
+ export {
11
+ serveBatch,
12
+ serveOne,
13
+ swapEnv
14
+ };
@@ -5,14 +5,16 @@ import {
5
5
  docxTables,
6
6
  docxText,
7
7
  formatDocxTables
8
- } from "./token-goat-chunk-XKY4VKJ4.mjs";
9
- import "./token-goat-chunk-UBUKHVYW.mjs";
8
+ } from "./token-goat-chunk-UA5BKWWQ.mjs";
9
+ import "./token-goat-chunk-UXSXQQIY.mjs";
10
10
  import "./token-goat-chunk-XTQAOTSO.mjs";
11
11
  import "./token-goat-chunk-AH6QILZM.mjs";
12
- import "./token-goat-chunk-L45ZQRT7.mjs";
12
+ import "./token-goat-chunk-XYWPOSCN.mjs";
13
+ import "./token-goat-chunk-TCQANXYC.mjs";
13
14
  import "./token-goat-chunk-NMTKNYGF.mjs";
15
+ import "./token-goat-chunk-MELOKFDJ.mjs";
14
16
  import "./token-goat-chunk-Y4AFKTHK.mjs";
15
- import "./token-goat-chunk-GMOUBOX4.mjs";
17
+ import "./token-goat-chunk-JTKCQMQA.mjs";
16
18
  import "./token-goat-chunk-A37V4PBF.mjs";
17
19
  export {
18
20
  docxOutline,
@@ -3,14 +3,14 @@ const require = __cjsRequire(import.meta.url);
3
3
  import {
4
4
  findLatestTranscript,
5
5
  readFileLines
6
- } from "./token-goat-chunk-6DQNNFJ6.mjs";
6
+ } from "./token-goat-chunk-44BM7DDQ.mjs";
7
7
  import {
8
8
  copilotCliUserRoot,
9
9
  readCopilotMcpTools
10
- } from "./token-goat-chunk-MMLMALWK.mjs";
10
+ } from "./token-goat-chunk-EUSDXRXU.mjs";
11
11
  import {
12
12
  canonicalize
13
- } from "./token-goat-chunk-L45ZQRT7.mjs";
13
+ } from "./token-goat-chunk-TCQANXYC.mjs";
14
14
  import {
15
15
  init_define_import_meta_env
16
16
  } from "./token-goat-chunk-A37V4PBF.mjs";
@@ -1,33 +1,36 @@
1
1
  import { createRequire as __cjsRequire } from 'node:module';
2
2
  const require = __cjsRequire(import.meta.url);
3
3
  import {
4
- getDb
5
- } from "./token-goat-chunk-M56BWPBN.mjs";
4
+ getDb,
5
+ isReadOnlyDb
6
+ } from "./token-goat-chunk-7CPMDFGB.mjs";
6
7
  import {
7
8
  getHarnessName,
8
9
  loadConfig
9
- } from "./token-goat-chunk-CC2PYJM7.mjs";
10
- import {
11
- registerReset
12
- } from "./token-goat-chunk-EEIDFMEM.mjs";
10
+ } from "./token-goat-chunk-TGOXNAHW.mjs";
13
11
  import {
14
12
  Database
15
- } from "./token-goat-chunk-OSUFN2FV.mjs";
13
+ } from "./token-goat-chunk-XB5KKOCG.mjs";
14
+ import {
15
+ registerReset
16
+ } from "./token-goat-chunk-YZAAZU2S.mjs";
16
17
  import {
17
- VERSION,
18
18
  countNoun,
19
- dataDir,
20
- dataDirForHome,
21
19
  ensureDirSync,
22
20
  extractErrorMessage
23
- } from "./token-goat-chunk-L45ZQRT7.mjs";
21
+ } from "./token-goat-chunk-XYWPOSCN.mjs";
24
22
  import {
25
23
  displaySafeText
26
24
  } from "./token-goat-chunk-NMTKNYGF.mjs";
25
+ import {
26
+ VERSION,
27
+ dataDir,
28
+ dataDirForHome
29
+ } from "./token-goat-chunk-MELOKFDJ.mjs";
27
30
  import {
28
31
  growsExponentially,
29
32
  hasNestedQuantifier
30
- } from "./token-goat-chunk-GMOUBOX4.mjs";
33
+ } from "./token-goat-chunk-JTKCQMQA.mjs";
31
34
  import {
32
35
  init_define_import_meta_env
33
36
  } from "./token-goat-chunk-A37V4PBF.mjs";
@@ -1202,7 +1205,7 @@ CREATE TABLE IF NOT EXISTS unmapped_tools (
1202
1205
  );
1203
1206
  `;
1204
1207
  var _globalSchemaApplied = /* @__PURE__ */ new Set();
1205
- registerReset(() => _globalSchemaApplied.clear());
1208
+ registerReset(() => _globalSchemaApplied.clear(), { perRequest: true });
1206
1209
  function migrateGlobalSchema(db) {
1207
1210
  try {
1208
1211
  db.exec("ALTER TABLE stats ADD COLUMN harness TEXT");
@@ -1307,7 +1310,7 @@ function getGlobalDb(homeDir) {
1307
1310
  const basePath = homeDir ? dataDirForHome(homeDir) : dataDir();
1308
1311
  const dbPath = path.join(basePath, "global.db");
1309
1312
  const db = getDb(dbPath);
1310
- if (!_globalSchemaApplied.has(dbPath)) {
1313
+ if (!_globalSchemaApplied.has(dbPath) && !isReadOnlyDb(dbPath)) {
1311
1314
  db.exec(GLOBAL_SCHEMA_SQL);
1312
1315
  migrateGlobalSchema(db);
1313
1316
  _globalSchemaApplied.add(dbPath);
@@ -1421,7 +1424,9 @@ function recordStat(kind, bytesSaved = 0, tokensSaved = 0, _testDb, detail, trac
1421
1424
  let db;
1422
1425
  try {
1423
1426
  if (!_testDb) getGlobalDb();
1427
+ if (!_testDb && isReadOnlyDb(path.join(dataDir(), "global.db"))) return;
1424
1428
  db = _testDb ?? new Database(path.join(dataDir(), "global.db"), { timeout: STATS_WRITE_BUSY_TIMEOUT_MS });
1429
+ if (!_testDb && String(db.pragma("journal_mode", { simple: true })).toLowerCase() === "wal") db.pragma("synchronous = NORMAL");
1425
1430
  const ts = Math.floor(Date.now() / 1e3);
1426
1431
  const tp = traceparent ?? process.env["TRACEPARENT"] ?? process.env["traceparent"] ?? null;
1427
1432
  const cols = ["ts", "kind", "bytes_saved", "tokens_saved", "detail"];
@@ -3,16 +3,18 @@ const require = __cjsRequire(import.meta.url);
3
3
  import {
4
4
  recordStat,
5
5
  redactSecrets
6
- } from "./token-goat-chunk-MVSWBNMD.mjs";
6
+ } from "./token-goat-chunk-CIQ2FTY3.mjs";
7
7
  import {
8
8
  loadConfig
9
- } from "./token-goat-chunk-CC2PYJM7.mjs";
9
+ } from "./token-goat-chunk-TGOXNAHW.mjs";
10
10
  import {
11
11
  atomicWriteText,
12
12
  ensureDirSync,
13
- sanitizeIdForFilename,
13
+ sanitizeIdForFilename
14
+ } from "./token-goat-chunk-XYWPOSCN.mjs";
15
+ import {
14
16
  tokenGoatHome
15
- } from "./token-goat-chunk-L45ZQRT7.mjs";
17
+ } from "./token-goat-chunk-MELOKFDJ.mjs";
16
18
  import {
17
19
  init_define_import_meta_env
18
20
  } from "./token-goat-chunk-A37V4PBF.mjs";