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
@@ -5,50 +5,50 @@ import {
5
5
  fenceUntrusted,
6
6
  getTrackedFiles,
7
7
  scanAndRecord
8
- } from "./token-goat-chunk-6Z5ULNE5.mjs";
8
+ } from "./token-goat-chunk-RTMVLHWX.mjs";
9
9
  import {
10
10
  getToolName
11
- } from "./token-goat-chunk-IZXKVT4A.mjs";
11
+ } from "./token-goat-chunk-E5TK5DNO.mjs";
12
12
  import {
13
13
  RECALL_DEFAULT_LIMIT,
14
14
  indexRecallEntry,
15
15
  listRecentRecall,
16
16
  searchRecall
17
- } from "./token-goat-chunk-HXNAC4ZF.mjs";
17
+ } from "./token-goat-chunk-O6I2XU4P.mjs";
18
18
  import {
19
19
  isBlobStale,
20
20
  loadBlob,
21
21
  storeBlob
22
- } from "./token-goat-chunk-BJBRGPBX.mjs";
22
+ } from "./token-goat-chunk-D4ETHJD6.mjs";
23
23
  import {
24
24
  redactSecrets
25
- } from "./token-goat-chunk-MVSWBNMD.mjs";
25
+ } from "./token-goat-chunk-CIQ2FTY3.mjs";
26
26
  import {
27
27
  parserFingerprintForLanguage
28
- } from "./token-goat-chunk-D5ICEPSB.mjs";
28
+ } from "./token-goat-chunk-VMFWNHGR.mjs";
29
29
  import {
30
30
  getProjectFileEntries,
31
31
  projectScopeClause
32
- } from "./token-goat-chunk-HUDC5GS5.mjs";
32
+ } from "./token-goat-chunk-435UQTKD.mjs";
33
33
  import {
34
34
  getDb
35
- } from "./token-goat-chunk-M56BWPBN.mjs";
35
+ } from "./token-goat-chunk-7CPMDFGB.mjs";
36
36
  import {
37
37
  fingerprintFile,
38
38
  getDisplayRoot,
39
39
  shortFingerprint
40
- } from "./token-goat-chunk-CC2PYJM7.mjs";
40
+ } from "./token-goat-chunk-TGOXNAHW.mjs";
41
41
  import {
42
42
  registerReset
43
- } from "./token-goat-chunk-EEIDFMEM.mjs";
43
+ } from "./token-goat-chunk-YZAAZU2S.mjs";
44
44
  import {
45
- SYMBOL_BODY_CHAR_CAP,
46
45
  countNoun,
47
46
  extractErrorMessage,
48
- foldPath,
49
- globalDbPath,
50
47
  pad
51
- } from "./token-goat-chunk-L45ZQRT7.mjs";
48
+ } from "./token-goat-chunk-XYWPOSCN.mjs";
49
+ import {
50
+ foldPath
51
+ } from "./token-goat-chunk-TCQANXYC.mjs";
52
52
  import {
53
53
  UNTRUSTED_TOOL_TAG,
54
54
  UNTRUSTED_WEB_TAG,
@@ -58,9 +58,13 @@ import {
58
58
  resolveIndexPath,
59
59
  toDisplayPath
60
60
  } from "./token-goat-chunk-NMTKNYGF.mjs";
61
+ import {
62
+ SYMBOL_BODY_CHAR_CAP,
63
+ globalDbPath
64
+ } from "./token-goat-chunk-MELOKFDJ.mjs";
61
65
  import {
62
66
  compileGuardedRegex
63
- } from "./token-goat-chunk-GMOUBOX4.mjs";
67
+ } from "./token-goat-chunk-JTKCQMQA.mjs";
64
68
  import {
65
69
  init_define_import_meta_env
66
70
  } from "./token-goat-chunk-A37V4PBF.mjs";
@@ -120,7 +124,7 @@ registerReset(() => {
120
124
  _byId = /* @__PURE__ */ new Map();
121
125
  _rawById = /* @__PURE__ */ new Map();
122
126
  _urlIndex = /* @__PURE__ */ new Map();
123
- });
127
+ }, { perRequest: true });
124
128
 
125
129
  // src/stdin_json.ts
126
130
  init_define_import_meta_env();
@@ -538,7 +542,7 @@ async function describeTarget(target, table, opts) {
538
542
  const absPath = resolve(process.cwd(), target);
539
543
  if (existsSync(absPath)) {
540
544
  try {
541
- const { isSqliteFile, getSqliteSchema, formatSqliteSchema } = await import("./token-goat-chunk-OZRSREKR.mjs");
545
+ const { isSqliteFile, getSqliteSchema, formatSqliteSchema } = await import("./token-goat-chunk-2AWQ2R5X.mjs");
542
546
  if (isSqliteFile(absPath)) {
543
547
  const schema = getSqliteSchema(absPath);
544
548
  if (table) {
@@ -5,13 +5,13 @@ import {
5
5
  } from "./token-goat-chunk-3BTK54F3.mjs";
6
6
  import {
7
7
  filtersFilteredToEmptyNotice
8
- } from "./token-goat-chunk-L45ZQRT7.mjs";
8
+ } from "./token-goat-chunk-XYWPOSCN.mjs";
9
9
  import {
10
10
  displaySafeText
11
11
  } from "./token-goat-chunk-NMTKNYGF.mjs";
12
12
  import {
13
13
  compileGuardedRegexCached
14
- } from "./token-goat-chunk-GMOUBOX4.mjs";
14
+ } from "./token-goat-chunk-JTKCQMQA.mjs";
15
15
  import {
16
16
  init_define_import_meta_env
17
17
  } from "./token-goat-chunk-A37V4PBF.mjs";
@@ -0,0 +1,220 @@
1
+ import { createRequire as __cjsRequire } from 'node:module';
2
+ const require = __cjsRequire(import.meta.url);
3
+ import {
4
+ configPath,
5
+ dataDir
6
+ } from "./token-goat-chunk-MELOKFDJ.mjs";
7
+ import {
8
+ init_define_import_meta_env
9
+ } from "./token-goat-chunk-A37V4PBF.mjs";
10
+
11
+ // src/hook_ipc.ts
12
+ init_define_import_meta_env();
13
+ import * as crypto from "node:crypto";
14
+ import * as fs from "node:fs";
15
+ import * as os from "node:os";
16
+ import * as path from "node:path";
17
+ import { fileURLToPath } from "node:url";
18
+ var PROTOCOL_VERSION = 1;
19
+ var SERVER_SLOTS = 3;
20
+ var MAX_FRAME_BYTES = 64 * 1024 * 1024;
21
+ var KEY_BYTES = 32;
22
+ function bundleDir() {
23
+ const dir = path.dirname(fileURLToPath(import.meta.url));
24
+ try {
25
+ return fs.realpathSync.native(dir);
26
+ } catch {
27
+ return dir;
28
+ }
29
+ }
30
+ function endpointId(dir) {
31
+ const fold = (p) => process.platform === "win32" ? p.toLowerCase() : p;
32
+ return crypto.createHash("sha256").update(`${fold(dir)}\0${fold(bundleDir())}`).digest("hex").slice(0, 16);
33
+ }
34
+ function endpointFor(slot, dir = dataDir()) {
35
+ const id = `${endpointId(dir)}-${slot}`;
36
+ if (process.platform === "win32") return String.raw`\\.\pipe\token-goat-hooks-` + id;
37
+ const inData = path.join(dir, `hooks-${id}.sock`);
38
+ if (Buffer.byteLength(inData) < 100) return inData;
39
+ const own = privateTempDir();
40
+ return own === void 0 ? inData : path.join(own, `${id}.sock`);
41
+ }
42
+ function privateTempDir() {
43
+ const uid = process.getuid?.();
44
+ if (uid === void 0) return void 0;
45
+ const own = path.join(os.tmpdir(), `token-goat-${uid}`);
46
+ try {
47
+ fs.mkdirSync(own, { mode: 448 });
48
+ } catch {
49
+ }
50
+ try {
51
+ const st = fs.lstatSync(own);
52
+ return st.isDirectory() && st.uid === uid && (st.mode & 63) === 0 ? own : void 0;
53
+ } catch {
54
+ return void 0;
55
+ }
56
+ }
57
+ function serverKeyPath(dir = dataDir()) {
58
+ return path.join(dir, "hook-server.key");
59
+ }
60
+ function keyIsPrivate(st) {
61
+ if (process.platform === "win32") return true;
62
+ return (st.mode & 63) === 0 && (process.getuid === void 0 || st.uid === process.getuid());
63
+ }
64
+ function readServerKey(dir = dataDir()) {
65
+ try {
66
+ const p = serverKeyPath(dir);
67
+ if (!keyIsPrivate(fs.statSync(p))) return void 0;
68
+ const key = fs.readFileSync(p);
69
+ return key.length === KEY_BYTES ? key : void 0;
70
+ } catch {
71
+ return void 0;
72
+ }
73
+ }
74
+ function ensureServerKey(dir = dataDir()) {
75
+ const p = serverKeyPath(dir);
76
+ for (let attempt = 0; attempt < 50; attempt++) {
77
+ const existing = readServerKey(dir);
78
+ if (existing !== void 0) return existing;
79
+ const fresh = crypto.randomBytes(KEY_BYTES);
80
+ try {
81
+ fs.mkdirSync(dir, { recursive: true });
82
+ fs.writeFileSync(p, fresh, { flag: "wx", mode: 384 });
83
+ return fresh;
84
+ } catch (e) {
85
+ if (e.code !== "EEXIST") throw e;
86
+ try {
87
+ const st = fs.statSync(p);
88
+ if (!keyIsPrivate(st) || st.size !== 0 && st.size !== KEY_BYTES || Date.now() - st.mtimeMs > 1e3) fs.rmSync(p, { force: true });
89
+ } catch {
90
+ }
91
+ }
92
+ Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 10);
93
+ }
94
+ throw new Error(`could not establish ${p}`);
95
+ }
96
+ function nonce() {
97
+ return crypto.randomBytes(16).toString("hex");
98
+ }
99
+ function mac(key, ...parts) {
100
+ const h = crypto.createHmac("sha256", key);
101
+ for (const part of parts) h.update(`${Buffer.byteLength(part)}:`).update(part);
102
+ return h.digest("hex");
103
+ }
104
+ function macMatches(expected, actual) {
105
+ if (typeof actual !== "string" || actual.length !== expected.length) return false;
106
+ return crypto.timingSafeEqual(Buffer.from(expected), Buffer.from(actual));
107
+ }
108
+ function writeFrame(socket, message) {
109
+ socket.write(encodeFrame(message));
110
+ }
111
+ function encodeFrame(message) {
112
+ const body = Buffer.from(JSON.stringify(message), "utf8");
113
+ const header = Buffer.alloc(4);
114
+ header.writeUInt32BE(body.length, 0);
115
+ return Buffer.concat([header, body]);
116
+ }
117
+ function frameFits(frame) {
118
+ return frame.length - 4 <= MAX_FRAME_BYTES;
119
+ }
120
+ function readFrames(socket, onFrame, onError) {
121
+ let buffered = Buffer.alloc(0);
122
+ socket.on("data", (chunk) => {
123
+ buffered = buffered.length === 0 ? chunk : Buffer.concat([buffered, chunk]);
124
+ while (buffered.length >= 4) {
125
+ const len = buffered.readUInt32BE(0);
126
+ if (len > MAX_FRAME_BYTES) {
127
+ onError(new Error(`frame of ${len} bytes exceeds ${MAX_FRAME_BYTES}`));
128
+ socket.destroy();
129
+ return;
130
+ }
131
+ if (buffered.length < 4 + len) return;
132
+ const body = buffered.subarray(4, 4 + len);
133
+ buffered = buffered.subarray(4 + len);
134
+ let message;
135
+ try {
136
+ message = JSON.parse(body.toString("utf8"));
137
+ } catch (e) {
138
+ onError(e);
139
+ socket.destroy();
140
+ return;
141
+ }
142
+ if (message === null || typeof message !== "object" || Array.isArray(message)) {
143
+ onError(new Error("frame is not a JSON object"));
144
+ socket.destroy();
145
+ return;
146
+ }
147
+ onFrame(message);
148
+ }
149
+ });
150
+ }
151
+ function envSnapshot() {
152
+ const env = {};
153
+ for (const [k, v] of Object.entries(process.env)) if (v !== void 0) env[k] = v;
154
+ return env;
155
+ }
156
+ function markerPath(name, dir = dataDir()) {
157
+ return path.join(dir, `hook-server.${name}`);
158
+ }
159
+ function markerAgeMs(name, dir = dataDir()) {
160
+ try {
161
+ return Date.now() - fs.statSync(markerPath(name, dir)).mtimeMs;
162
+ } catch {
163
+ return Infinity;
164
+ }
165
+ }
166
+ function touchMarker(name, content = String(process.pid), dir = dataDir()) {
167
+ try {
168
+ fs.mkdirSync(dir, { recursive: true });
169
+ fs.writeFileSync(markerPath(name, dir), content);
170
+ } catch {
171
+ }
172
+ }
173
+ function configStamp() {
174
+ try {
175
+ return String(fs.statSync(configPath()).mtimeMs);
176
+ } catch {
177
+ return "absent";
178
+ }
179
+ }
180
+ function readMarker(name, dir = dataDir()) {
181
+ try {
182
+ return fs.readFileSync(markerPath(name, dir), "utf8");
183
+ } catch {
184
+ return void 0;
185
+ }
186
+ }
187
+ function removeMarker(name, dir = dataDir()) {
188
+ fs.rmSync(markerPath(name, dir), { force: true });
189
+ }
190
+ function bundleEntryFiles() {
191
+ const dir = bundleDir();
192
+ return ["token-goat.core.mjs", "token-goat-hook.mjs", "token-goat-hook-client.mjs", "token-goat-hook-client.cjs"].map((f) => path.join(dir, f));
193
+ }
194
+ function launcherPath() {
195
+ return path.join(bundleDir(), "token-goat.mjs");
196
+ }
197
+
198
+ export {
199
+ PROTOCOL_VERSION,
200
+ SERVER_SLOTS,
201
+ endpointFor,
202
+ serverKeyPath,
203
+ readServerKey,
204
+ ensureServerKey,
205
+ nonce,
206
+ mac,
207
+ macMatches,
208
+ writeFrame,
209
+ encodeFrame,
210
+ frameFits,
211
+ readFrames,
212
+ envSnapshot,
213
+ markerAgeMs,
214
+ touchMarker,
215
+ configStamp,
216
+ readMarker,
217
+ removeMarker,
218
+ bundleEntryFiles,
219
+ launcherPath
220
+ };
@@ -4,23 +4,25 @@ import {
4
4
  DELIVERS_CONTENT_RE,
5
5
  commandPathIsTouchable,
6
6
  leadWithCommand
7
- } from "./token-goat-chunk-IZXKVT4A.mjs";
7
+ } from "./token-goat-chunk-E5TK5DNO.mjs";
8
8
  import {
9
9
  getFileLineRanges
10
- } from "./token-goat-chunk-GGLEE35R.mjs";
10
+ } from "./token-goat-chunk-TDUT2CL6.mjs";
11
11
  import {
12
12
  hasBareBackgroundOrNewline,
13
13
  hasUnquotedOperator,
14
14
  isRedirectAmpersand
15
- } from "./token-goat-chunk-4RN64ZND.mjs";
15
+ } from "./token-goat-chunk-2WOUYWLM.mjs";
16
16
  import {
17
- FALSY_ENV_VALUES,
18
17
  isUnderSystemTemp
19
- } from "./token-goat-chunk-CC2PYJM7.mjs";
18
+ } from "./token-goat-chunk-TGOXNAHW.mjs";
19
+ import {
20
+ FALSY_ENV_VALUES
21
+ } from "./token-goat-chunk-IVE6U7KV.mjs";
20
22
  import {
21
23
  escapeRegExp,
22
24
  safeSlice
23
- } from "./token-goat-chunk-L45ZQRT7.mjs";
25
+ } from "./token-goat-chunk-XYWPOSCN.mjs";
24
26
  import {
25
27
  TOOL_RESULTS_ID_CHARS,
26
28
  normalizePath,
@@ -754,7 +756,7 @@ function taskOutputIsJsonlTranscript(outPath) {
754
756
  }
755
757
  }
756
758
  function extractTasksOutput(cmd) {
757
- const taskOutputRe = /[/\\]tasks[/\\]([a-z0-9]+)\.output$/;
759
+ const taskOutputRe = /(?:^|[/\\])tasks[/\\]([a-z0-9]+)\.output$/;
758
760
  const catM = /^cat(?:\s+(?:-[a-zA-Z]+|--[a-zA-Z-]+))*\s+(?:"([^"]+)"|'([^']+)'|(\S+))\s*$/.exec(cmd);
759
761
  if (catM) {
760
762
  const fp = catM[1] ?? catM[2] ?? catM[3];
@@ -1327,6 +1329,7 @@ export {
1327
1329
  surgicalHintForConfigDoc,
1328
1330
  splitShellSegments,
1329
1331
  extractCatSourceFile,
1332
+ classifyCatPath,
1330
1333
  extractCatFile,
1331
1334
  extractCatFilesMulti,
1332
1335
  extractPowerShellWrappedGetContent,
@@ -4,22 +4,25 @@ import {
4
4
  COPILOT_CLI_TOOL_NAME_MAP,
5
5
  foldToolName,
6
6
  readCopilotMcpTools
7
- } from "./token-goat-chunk-MMLMALWK.mjs";
7
+ } from "./token-goat-chunk-EUSDXRXU.mjs";
8
8
  import {
9
9
  countRedactionPlaceholders,
10
10
  recordStat,
11
11
  savedTokensFromBytes
12
- } from "./token-goat-chunk-MVSWBNMD.mjs";
12
+ } from "./token-goat-chunk-CIQ2FTY3.mjs";
13
13
  import {
14
14
  detectHarness,
15
15
  loadConfig,
16
16
  ownGet
17
- } from "./token-goat-chunk-CC2PYJM7.mjs";
17
+ } from "./token-goat-chunk-TGOXNAHW.mjs";
18
+ import {
19
+ registerReset
20
+ } from "./token-goat-chunk-YZAAZU2S.mjs";
18
21
  import {
19
22
  escapesOntoNetworkThroughLinks,
20
23
  foldPathForContainment,
21
24
  isInsideRoot
22
- } from "./token-goat-chunk-L45ZQRT7.mjs";
25
+ } from "./token-goat-chunk-TCQANXYC.mjs";
23
26
  import {
24
27
  displaySafeText,
25
28
  isUncOrDevicePath,
@@ -52,6 +55,10 @@ function copilotMcpToolNameMap() {
52
55
  function canonicalizeCopilotMcpToolName(toolName) {
53
56
  return copilotMcpToolNameMap().get(toolName) ?? toolName;
54
57
  }
58
+ function resetCopilotMcpToolNameCache() {
59
+ _cached = null;
60
+ }
61
+ registerReset(resetCopilotMcpToolNameCache, { perRequest: true });
55
62
 
56
63
  // src/hooks_cli.ts
57
64
  var _LOG = {
@@ -2,10 +2,10 @@ import { createRequire as __cjsRequire } from 'node:module';
2
2
  const require = __cjsRequire(import.meta.url);
3
3
  import {
4
4
  estimateTokensFromLength
5
- } from "./token-goat-chunk-4JMWPWCS.mjs";
5
+ } from "./token-goat-chunk-52NSDWYY.mjs";
6
6
  import {
7
7
  loadConfig
8
- } from "./token-goat-chunk-CC2PYJM7.mjs";
8
+ } from "./token-goat-chunk-TGOXNAHW.mjs";
9
9
  import {
10
10
  atomicWriteText,
11
11
  backupFile,
@@ -21,7 +21,7 @@ import {
21
21
  upsertDelimitedBlock,
22
22
  withInstallScope,
23
23
  writeIfDifferent
24
- } from "./token-goat-chunk-L45ZQRT7.mjs";
24
+ } from "./token-goat-chunk-XYWPOSCN.mjs";
25
25
  import {
26
26
  init_define_import_meta_env
27
27
  } from "./token-goat-chunk-A37V4PBF.mjs";
@@ -370,6 +370,30 @@ function foldToolName(name) {
370
370
  return typeof name === "string" ? name.toLowerCase().replace(/[_-]/g, "") : "";
371
371
  }
372
372
 
373
+ // src/bridges/shim_try_server.ts
374
+ init_define_import_meta_env();
375
+ var SHIM_TRY_SERVER = `// Attempts the resident hook server (src/hook_server.ts): the sibling hook client sends this
376
+ // call to an already-running token-goat process, so neither Node's module loading nor the hook
377
+ // graph is paid for again. The CommonJS client comes first: this shim is CommonJS, and loading
378
+ // the ES module one starts Node's ESM loader, about 5ms of a call the server answers. The ES
379
+ // module one is for an install built before the CommonJS file existed. It returns undefined
380
+ // whenever nothing was dispatched -- no server yet (it starts one in the background), all busy,
381
+ // replaced by a newer build, turned off, or an install predating the client -- and the caller
382
+ // then runs the call itself.
383
+ async function tryServer(entryPath, eventName, input, harnessWaitMs) {
384
+ if (!entryPath) return undefined
385
+ try {
386
+ const fs = require('node:fs')
387
+ const cjsPath = path.join(path.dirname(entryPath), 'token-goat-hook-client.cjs')
388
+ const mjsPath = path.join(path.dirname(entryPath), 'token-goat-hook-client.mjs')
389
+ const client = fs.existsSync(cjsPath) ? require(cjsPath) : fs.existsSync(mjsPath) ? await import(pathToFileURL(mjsPath).href) : undefined
390
+ if (client === undefined) return undefined
391
+ return await client.relayViaServer(eventName, input, harnessWaitMs)
392
+ } catch {
393
+ return undefined
394
+ }
395
+ }`;
396
+
373
397
  // src/bridges/shrink_block.ts
374
398
  init_define_import_meta_env();
375
399
  var MATERIALIZE_SHRUNK_IMAGE_JS = `// Best-effort sweep of previously materialized shrunk copies in the OS temp dir. The temp file only needs to outlive the single tool call whose path argument was rewritten to it, so anything older than an hour is finished with; the "token-goat-shrink-" prefix check confines the sweep to this mechanism's own files (same defense-in-depth rule as pruneShrinkCache in src/image_shrink.ts). Throttled per process; runs only when a shrink payload actually arrives, so the common no-image path never pays for it.
@@ -666,7 +690,9 @@ function remapToolInput(copilotToolName, input) {
666
690
  return out
667
691
  }
668
692
 
669
- // Attempts the in-process hook call: import()s dist/token-goat-hook.mjs (a sibling of
693
+ ${SHIM_TRY_SERVER}
694
+
695
+ // Attempts the resident server (tryServer above), then the in-process hook call: import()s dist/token-goat-hook.mjs (a sibling of
670
696
  // the baked token-goat entry path, built with zero load-time side effects -- unlike
671
697
  // the CLI entry, which runs the full argv-parsing CLI as a side effect of being
672
698
  // loaded) and calls its exported relayInProcess() directly, avoiding a second node
@@ -676,14 +702,17 @@ function remapToolInput(copilotToolName, input) {
676
702
  async function tryInProcess(entryPath, tgEvent, canonical, harness) {
677
703
  if (!entryPath) return undefined
678
704
  try {
679
- const hookLibPath = path.join(path.dirname(entryPath), 'token-goat-hook.mjs')
680
- if (!require('node:fs').existsSync(hookLibPath)) return undefined
681
- const mod = await import(pathToFileURL(hookLibPath).href)
705
+ // Set before either path: the resident server runs the call under this process's environment.
682
706
  process.env.TOKEN_GOAT_HARNESS_OVERRIDE = harness
683
707
  // Which hooks directory VS Code loaded this shim from is the only thing separating a
684
708
  // user-scope copy from a project-scope one -- the two files are byte-identical and so are
685
709
  // their payloads. vscode_duplicate.ts needs it to stand the redundant copy down.
686
710
  if (harness === 'vscode') process.env.TOKEN_GOAT_VSCODE_HOOKS_DIR = __dirname
711
+ const served = await tryServer(entryPath, tgEvent, canonical)
712
+ if (served !== undefined) return served
713
+ const hookLibPath = path.join(path.dirname(entryPath), 'token-goat-hook.mjs')
714
+ if (!require('node:fs').existsSync(hookLibPath)) return undefined
715
+ const mod = await import(pathToFileURL(hookLibPath).href)
687
716
  return await mod.relayInProcess(tgEvent, canonical)
688
717
  } catch {
689
718
  return undefined
@@ -1174,13 +1203,26 @@ function buildConfig(scriptPath) {
1174
1203
  return { version: 1, hooks };
1175
1204
  }
1176
1205
  var HOOKS_CONFIG_FILE = "token-goat.json";
1177
- var HOOKS_SCRIPT_FILE = "token-goat-shim.js";
1206
+ var HOOKS_SCRIPT_FILE = "token-goat-shim.cjs";
1207
+ var LEGACY_HOOKS_SCRIPT_FILE = "token-goat-shim.js";
1178
1208
  var HOOKS_OWNERS_FILE = "token-goat.owners";
1209
+ var HOOKS_SCRIPT_FORWARDER = `#!/usr/bin/env node
1210
+ // Forwarder for compatibility with cached hook definitions in running Copilot CLI sessions.
1211
+ import('./token-goat-shim.cjs').catch(() => {
1212
+ try { process.stdout.write('{}') } catch {}
1213
+ process.exitCode = 0
1214
+ });
1215
+ `;
1179
1216
  function copilotHooksOwnersPath(hooksDir) {
1180
1217
  return path3.join(hooksDir, HOOKS_OWNERS_FILE);
1181
1218
  }
1182
1219
  function copilotHooksFilePaths(hooksDir) {
1183
- return [path3.join(hooksDir, HOOKS_CONFIG_FILE), path3.join(hooksDir, HOOKS_SCRIPT_FILE), copilotHooksOwnersPath(hooksDir)];
1220
+ return [
1221
+ path3.join(hooksDir, HOOKS_CONFIG_FILE),
1222
+ path3.join(hooksDir, HOOKS_SCRIPT_FILE),
1223
+ path3.join(hooksDir, LEGACY_HOOKS_SCRIPT_FILE),
1224
+ copilotHooksOwnersPath(hooksDir)
1225
+ ];
1184
1226
  }
1185
1227
  function readCopilotHooksOwners(hooksDir) {
1186
1228
  const owners = /* @__PURE__ */ new Set();
@@ -1200,14 +1242,16 @@ function readCopilotHooksOwners(hooksDir) {
1200
1242
  function installCopilotHooksFile(hooksDir, owner) {
1201
1243
  const configPath = path3.join(hooksDir, HOOKS_CONFIG_FILE);
1202
1244
  const scriptPath = path3.join(hooksDir, HOOKS_SCRIPT_FILE);
1245
+ const legacyScriptPath = path3.join(hooksDir, LEGACY_HOOKS_SCRIPT_FILE);
1203
1246
  const owners = readCopilotHooksOwners(hooksDir);
1204
1247
  const scriptChanged = writeIfDifferent(scriptPath, COPILOT_CLI_HOOK_SCRIPT);
1248
+ const legacyScriptChanged = writeIfDifferent(legacyScriptPath, HOOKS_SCRIPT_FORWARDER);
1205
1249
  const desiredText = JSON.stringify(buildConfig(scriptPath), null, 2) + "\n";
1206
1250
  const configChanged = writeIfDifferent(configPath, desiredText, true);
1207
1251
  recordCreatedConfig(configPath);
1208
1252
  owners.add(owner);
1209
1253
  const ownersChanged = writeIfDifferent(copilotHooksOwnersPath(hooksDir), [...owners].sort().join("\n") + "\n");
1210
- return { configPath, scriptPath, changed: scriptChanged || configChanged || ownersChanged };
1254
+ return { configPath, scriptPath, changed: scriptChanged || legacyScriptChanged || configChanged || ownersChanged };
1211
1255
  }
1212
1256
  function releaseCopilotHooksFile(hooksDir, owner, keepBackups = false) {
1213
1257
  const ownersPath = copilotHooksOwnersPath(hooksDir);
@@ -1223,8 +1267,9 @@ function releaseCopilotHooksFile(hooksDir, owner, keepBackups = false) {
1223
1267
  if (!keepBackups) removeCreatedBackups(path3.join(hooksDir, HOOKS_CONFIG_FILE));
1224
1268
  takeCreatedConfig(path3.join(hooksDir, HOOKS_CONFIG_FILE));
1225
1269
  const scriptRemoved = removeFileInScope(path3.join(hooksDir, HOOKS_SCRIPT_FILE));
1270
+ const legacyScriptRemoved = removeFileInScope(path3.join(hooksDir, LEGACY_HOOKS_SCRIPT_FILE));
1226
1271
  const ownersRemoved = removeFileInScope(ownersPath);
1227
- return configRemoved || scriptRemoved || ownersRemoved;
1272
+ return configRemoved || scriptRemoved || legacyScriptRemoved || ownersRemoved;
1228
1273
  }
1229
1274
  function installCopilotCli(opts = {}) {
1230
1275
  return withInstallScope(projectScopeRoot(opts), () => installCopilotCliScoped(opts));
@@ -1259,7 +1304,8 @@ function uninstallCopilotCli(opts = {}) {
1259
1304
  return userRemoved || localRemoved;
1260
1305
  }
1261
1306
  function isCopilotCliInstalled(opts = {}) {
1262
- if (!fs3.existsSync(copilotCliConfigPath(opts)) || !fs3.existsSync(copilotCliScriptPath(opts))) {
1307
+ const scriptPresent = fs3.existsSync(copilotCliScriptPath(opts)) || fs3.existsSync(path3.join(copilotCliHooksDir(opts), LEGACY_HOOKS_SCRIPT_FILE));
1308
+ if (!fs3.existsSync(copilotCliConfigPath(opts)) || !scriptPresent) {
1263
1309
  return false;
1264
1310
  }
1265
1311
  if (!readCopilotHooksOwners(copilotCliHooksDir(opts)).has("copilot")) return false;
@@ -1339,6 +1385,7 @@ function readCopilotMcpTools(dir = copilotCliMcpToolsDir()) {
1339
1385
  export {
1340
1386
  foldToolName,
1341
1387
  COPILOT_CLI_TOOL_NAME_MAP,
1388
+ SHIM_TRY_SERVER,
1342
1389
  MATERIALIZE_SHRUNK_IMAGE_JS,
1343
1390
  COPILOT_CLI_HOOK_SCRIPT,
1344
1391
  buildGuidanceBody,
@@ -1370,6 +1417,7 @@ export {
1370
1417
  copilotCliConfigPath,
1371
1418
  copilotCliScriptPath,
1372
1419
  HOOKS_SCRIPT_FILE,
1420
+ LEGACY_HOOKS_SCRIPT_FILE,
1373
1421
  copilotHooksFilePaths,
1374
1422
  readCopilotHooksOwners,
1375
1423
  installCopilotHooksFile,
@@ -20,20 +20,23 @@ import {
20
20
  setOcrTimeoutForTesting,
21
21
  setTesseractEntryForTesting,
22
22
  verifyOcrLangCache
23
- } from "./token-goat-chunk-4STDIGYC.mjs";
24
- import "./token-goat-chunk-BJBRGPBX.mjs";
25
- import "./token-goat-chunk-MVSWBNMD.mjs";
26
- import "./token-goat-chunk-M56BWPBN.mjs";
23
+ } from "./token-goat-chunk-VZQEWRVH.mjs";
24
+ import "./token-goat-chunk-D4ETHJD6.mjs";
25
+ import "./token-goat-chunk-CIQ2FTY3.mjs";
26
+ import "./token-goat-chunk-7CPMDFGB.mjs";
27
27
  import {
28
28
  DEFAULT_OCR_LANG,
29
29
  isSupportedOcrLang,
30
30
  resolveOcrLangs
31
- } from "./token-goat-chunk-CC2PYJM7.mjs";
32
- import "./token-goat-chunk-EEIDFMEM.mjs";
33
- import "./token-goat-chunk-OSUFN2FV.mjs";
34
- import "./token-goat-chunk-L45ZQRT7.mjs";
31
+ } from "./token-goat-chunk-TGOXNAHW.mjs";
32
+ import "./token-goat-chunk-XB5KKOCG.mjs";
33
+ import "./token-goat-chunk-YZAAZU2S.mjs";
34
+ import "./token-goat-chunk-IVE6U7KV.mjs";
35
+ import "./token-goat-chunk-XYWPOSCN.mjs";
36
+ import "./token-goat-chunk-TCQANXYC.mjs";
35
37
  import "./token-goat-chunk-NMTKNYGF.mjs";
36
- import "./token-goat-chunk-GMOUBOX4.mjs";
38
+ import "./token-goat-chunk-MELOKFDJ.mjs";
39
+ import "./token-goat-chunk-JTKCQMQA.mjs";
37
40
  import "./token-goat-chunk-A37V4PBF.mjs";
38
41
  export {
39
42
  DEFAULT_OCR_LANG,
@@ -4,23 +4,26 @@ import {
4
4
  CONTENT_DELIVERED_REASON,
5
5
  classifyToolError,
6
6
  errorPrefix
7
- } from "./token-goat-chunk-I7CB3X4K.mjs";
8
- import "./token-goat-chunk-IZXKVT4A.mjs";
9
- import "./token-goat-chunk-RJH64KQH.mjs";
10
- import "./token-goat-chunk-MMLMALWK.mjs";
11
- import "./token-goat-chunk-GGLEE35R.mjs";
12
- import "./token-goat-chunk-4JMWPWCS.mjs";
13
- import "./token-goat-chunk-4RN64ZND.mjs";
14
- import "./token-goat-chunk-MVSWBNMD.mjs";
15
- import "./token-goat-chunk-M56BWPBN.mjs";
16
- import "./token-goat-chunk-CC2PYJM7.mjs";
17
- import "./token-goat-chunk-EEIDFMEM.mjs";
18
- import "./token-goat-chunk-OSUFN2FV.mjs";
19
- import "./token-goat-chunk-L45ZQRT7.mjs";
7
+ } from "./token-goat-chunk-E4ZOJIZK.mjs";
8
+ import "./token-goat-chunk-E5TK5DNO.mjs";
9
+ import "./token-goat-chunk-ZER6EAXZ.mjs";
10
+ import "./token-goat-chunk-EUSDXRXU.mjs";
11
+ import "./token-goat-chunk-TDUT2CL6.mjs";
12
+ import "./token-goat-chunk-52NSDWYY.mjs";
13
+ import "./token-goat-chunk-2WOUYWLM.mjs";
14
+ import "./token-goat-chunk-CIQ2FTY3.mjs";
15
+ import "./token-goat-chunk-7CPMDFGB.mjs";
16
+ import "./token-goat-chunk-TGOXNAHW.mjs";
17
+ import "./token-goat-chunk-XB5KKOCG.mjs";
18
+ import "./token-goat-chunk-YZAAZU2S.mjs";
19
+ import "./token-goat-chunk-IVE6U7KV.mjs";
20
+ import "./token-goat-chunk-XYWPOSCN.mjs";
21
+ import "./token-goat-chunk-TCQANXYC.mjs";
20
22
  import {
21
23
  displaySafeText
22
24
  } from "./token-goat-chunk-NMTKNYGF.mjs";
23
- import "./token-goat-chunk-GMOUBOX4.mjs";
25
+ import "./token-goat-chunk-MELOKFDJ.mjs";
26
+ import "./token-goat-chunk-JTKCQMQA.mjs";
24
27
  import {
25
28
  init_define_import_meta_env
26
29
  } from "./token-goat-chunk-A37V4PBF.mjs";