token-goat 2.9.18 → 2.9.20

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 (55) hide show
  1. package/README.md +5 -1
  2. package/dist/token-goat-chunk-2CLWWRFR.mjs +26 -0
  3. package/dist/{token-goat-chunk-LTYWLKAG.mjs → token-goat-chunk-2Q3N5KUQ.mjs} +1283 -1012
  4. package/dist/{token-goat-chunk-6LGVCCMY.mjs → token-goat-chunk-3OGZOFLS.mjs} +26 -16
  5. package/dist/{token-goat-chunk-QML7ITHJ.mjs → token-goat-chunk-3VTJC7KU.mjs} +693 -438
  6. package/dist/{token-goat-chunk-QIDLJGXZ.mjs → token-goat-chunk-6LJNM4ZZ.mjs} +29 -5
  7. package/dist/{token-goat-chunk-CA6V36KW.mjs → token-goat-chunk-74ADIZZX.mjs} +68 -50
  8. package/dist/{token-goat-chunk-52IMXJ2L.mjs → token-goat-chunk-ASTBLE2R.mjs} +4 -4
  9. package/dist/token-goat-chunk-AU2K2QHR.mjs +20 -0
  10. package/dist/token-goat-chunk-BQIC3AVL.mjs +292 -0
  11. package/dist/token-goat-chunk-CBXLE54Q.mjs +30 -0
  12. package/dist/{token-goat-chunk-LMFO66YD.mjs → token-goat-chunk-DA43OE7L.mjs} +1 -1
  13. package/dist/{token-goat-chunk-ARNRFR6M.mjs → token-goat-chunk-DNAF26L4.mjs} +1 -1
  14. package/dist/{token-goat-chunk-BFEWOMA3.mjs → token-goat-chunk-DPHJU3P7.mjs} +1186 -4573
  15. package/dist/{token-goat-chunk-OWSJJY5R.mjs → token-goat-chunk-DW4VKU7D.mjs} +5 -5
  16. package/dist/token-goat-chunk-DYUBZZNP.mjs +198 -0
  17. package/dist/{token-goat-chunk-W3E65QOW.mjs → token-goat-chunk-ERGHDBC6.mjs} +310 -47
  18. package/dist/token-goat-chunk-EUZKG7ZO.mjs +304 -0
  19. package/dist/{token-goat-chunk-5MMJAJF3.mjs → token-goat-chunk-FWYZVS3E.mjs} +324 -31
  20. package/dist/token-goat-chunk-G6SYQQO7.mjs +41 -0
  21. package/dist/{token-goat-chunk-YQZE5NS6.mjs → token-goat-chunk-GIPMOGOI.mjs} +6 -6
  22. package/dist/{token-goat-chunk-BWCRC23L.mjs → token-goat-chunk-H4VC5TR6.mjs} +29 -20
  23. package/dist/{token-goat-chunk-V3ZWBEHM.mjs → token-goat-chunk-I5PQRHFE.mjs} +103 -24
  24. package/dist/token-goat-chunk-ITWYDOKP.mjs +341 -0
  25. package/dist/{token-goat-chunk-I67CPTDD.mjs → token-goat-chunk-K3ZNBN4U.mjs} +19 -14
  26. package/dist/{token-goat-chunk-HPOFR6QX.mjs → token-goat-chunk-K5XPIUVB.mjs} +222 -61
  27. package/dist/token-goat-chunk-KT75DZK4.mjs +1989 -0
  28. package/dist/{token-goat-chunk-H3FONFBO.mjs → token-goat-chunk-MNJWG2ZO.mjs} +3 -3
  29. package/dist/{token-goat-chunk-GRI6HWX3.mjs → token-goat-chunk-MUJV7BR3.mjs} +1 -1
  30. package/dist/{token-goat-chunk-ERTXEKB6.mjs → token-goat-chunk-NMTKNYGF.mjs} +2 -0
  31. package/dist/{token-goat-chunk-LA3O4JGD.mjs → token-goat-chunk-ODF7H7WS.mjs} +3 -3
  32. package/dist/{token-goat-chunk-K4DG6EEF.mjs → token-goat-chunk-ONMU7BON.mjs} +7 -8
  33. package/dist/{token-goat-chunk-4EXFN2AW.mjs → token-goat-chunk-OZRSREKR.mjs} +2 -2
  34. package/dist/{token-goat-chunk-EPXNOKIV.mjs → token-goat-chunk-P4XBHZXU.mjs} +2 -2
  35. package/dist/{token-goat-chunk-CTOYJ232.mjs → token-goat-chunk-PAVWB4L4.mjs} +173 -1840
  36. package/dist/{token-goat-chunk-UENEL6KX.mjs → token-goat-chunk-PTW22MRC.mjs} +2 -2
  37. package/dist/token-goat-chunk-SL454EN5.mjs +1816 -0
  38. package/dist/token-goat-chunk-SP5QR2HN.mjs +1379 -0
  39. package/dist/{token-goat-chunk-7VLWNQDQ.mjs → token-goat-chunk-T46UKRFM.mjs} +1 -1
  40. package/dist/{token-goat-chunk-L7VCX33I.mjs → token-goat-chunk-T63VHOL3.mjs} +40 -10
  41. package/dist/token-goat-chunk-VSJGPEBB.mjs +248 -0
  42. package/dist/{token-goat-chunk-HIZXQVNU.mjs → token-goat-chunk-VYXGHGUY.mjs} +4 -4
  43. package/dist/token-goat-chunk-W6QYCWAT.mjs +128 -0
  44. package/dist/{token-goat-chunk-WFX2V3OF.mjs → token-goat-chunk-Z4ALQADF.mjs} +579 -422
  45. package/dist/token-goat-chunk-ZHFM4DHJ.mjs +324 -0
  46. package/dist/token-goat-hook.mjs +18 -12
  47. package/dist/token-goat.core.mjs +29 -20
  48. package/docs/C4_RUNTIME_ARCHITECTURE.md +1 -1
  49. package/docs/cli.md +15 -13
  50. package/docs/install.md +1 -1
  51. package/docs/security.md +2 -2
  52. package/package.json +3 -2
  53. package/dist/token-goat-chunk-2KTZ6J7T.mjs +0 -173
  54. package/dist/token-goat-chunk-34OUJ2IE.mjs +0 -35
  55. package/dist/token-goat-chunk-RHHFEXKF.mjs +0 -93
@@ -1,173 +0,0 @@
1
- import { createRequire as __cjsRequire } from 'node:module';
2
- const require = __cjsRequire(import.meta.url);
3
- import {
4
- deliveredOutputBytes,
5
- wrappedShell
6
- } from "./token-goat-chunk-RHHFEXKF.mjs";
7
- import {
8
- ToolFilter,
9
- capTokens,
10
- compressedTokensSaved,
11
- deliverCompressed,
12
- dispatchArgv,
13
- filterByName,
14
- selectFilter,
15
- shlexSplit,
16
- storeBashOutputSync
17
- } from "./token-goat-chunk-CTOYJ232.mjs";
18
- import {
19
- recordStat
20
- } from "./token-goat-chunk-HPOFR6QX.mjs";
21
- import "./token-goat-chunk-I67CPTDD.mjs";
22
- import "./token-goat-chunk-L7VCX33I.mjs";
23
- import {
24
- loadConfig
25
- } from "./token-goat-chunk-CA6V36KW.mjs";
26
- import "./token-goat-chunk-EEIDFMEM.mjs";
27
- import "./token-goat-chunk-OSUFN2FV.mjs";
28
- import "./token-goat-chunk-QIDLJGXZ.mjs";
29
- import "./token-goat-chunk-ERTXEKB6.mjs";
30
- import "./token-goat-chunk-GMOUBOX4.mjs";
31
- import {
32
- init_define_import_meta_env
33
- } from "./token-goat-chunk-A37V4PBF.mjs";
34
-
35
- // src/bash_runner.ts
36
- init_define_import_meta_env();
37
- import { spawnSync } from "node:child_process";
38
- import * as os from "node:os";
39
- var IdentityFilter = class extends ToolFilter {
40
- name = "passthrough";
41
- };
42
- var DEFAULT_TIMEOUT_SECONDS = 600;
43
- var MAX_CAPTURE_BYTES = 32 * 1024 * 1024;
44
- var MIN_RECORD_STAT_BYTES = 32;
45
- function resolveFilter(command, filterName, cwd) {
46
- let split;
47
- try {
48
- split = shlexSplit(command);
49
- } catch {
50
- split = null;
51
- }
52
- const argv = split === null ? [command] : dispatchArgv(split, cwd).argv;
53
- if (filterName) {
54
- const named = filterByName(filterName);
55
- if (named !== null) return { filter: named, argv };
56
- }
57
- if (split === null) return { filter: null, argv };
58
- return { filter: selectFilter(split, cwd), argv };
59
- }
60
- function baseSpawnOptions(timeout, cwd, env, nativeShell) {
61
- return { shell: nativeShell ? true : wrappedShell(), timeout: timeout * 1e3, cwd, env };
62
- }
63
- function signalExitCode(signal) {
64
- const num = os.constants.signals[signal];
65
- return 128 + (num ?? 0);
66
- }
67
- function resolveProfile(explicit) {
68
- if (explicit) return explicit;
69
- try {
70
- const p = loadConfig().compression.profile;
71
- return p && p !== "auto" ? p : "balanced";
72
- } catch {
73
- return "balanced";
74
- }
75
- }
76
- function resolveCompressLimits() {
77
- try {
78
- const bc = loadConfig().bash_compress;
79
- return { maxLines: bc.max_lines, maxBytes: bc.max_bytes };
80
- } catch {
81
- return { maxLines: 1e3, maxBytes: 64 * 1024 };
82
- }
83
- }
84
- function run(command, opts = {}) {
85
- const timeout = opts.timeout ?? DEFAULT_TIMEOUT_SECONDS;
86
- const { filter, argv } = resolveFilter(command, opts.filterName, opts.cwd);
87
- if (filter === null) {
88
- if ((opts.maxTokens ?? 0) > 0 || opts.quietSuccess) {
89
- return wrapAndCompress(command, argv, new IdentityFilter(), timeout, resolveProfile(opts.compressionProfile), opts);
90
- }
91
- return passthrough(command, timeout, opts.cwd, opts.env, opts.nativeShell);
92
- }
93
- return wrapAndCompress(command, argv, filter, timeout, resolveProfile(opts.compressionProfile), opts);
94
- }
95
- function runRaw(command, timeout = DEFAULT_TIMEOUT_SECONDS) {
96
- return passthrough(command, timeout, void 0, void 0);
97
- }
98
- function passthrough(command, timeout, cwd, env, nativeShell) {
99
- const result = spawnSync(command, { ...baseSpawnOptions(timeout, cwd, env, nativeShell), stdio: "inherit" });
100
- if (isTimeout(result.error)) return 124;
101
- if (result.status !== null) return result.status;
102
- if (result.signal) return signalExitCode(result.signal);
103
- return 0;
104
- }
105
- function isTimeout(error) {
106
- return !!error && error.code === "ETIMEDOUT";
107
- }
108
- function decode(buf) {
109
- if (buf == null) return "";
110
- return typeof buf === "string" ? buf : buf.toString("utf8");
111
- }
112
- function wrapAndCompress(command, argv, filter, timeout, profile, opts) {
113
- const writeStdout = opts.writeStdout ?? ((s) => process.stdout.write(s));
114
- const startTime = Date.now();
115
- const result = spawnSync(command, {
116
- ...baseSpawnOptions(timeout, opts.cwd, opts.env, opts.nativeShell),
117
- stdio: ["ignore", "pipe", "pipe"],
118
- maxBuffer: MAX_CAPTURE_BYTES
119
- });
120
- const timedOut = isTimeout(result.error);
121
- const overflowed = !!result.error && result.error.code === "ENOBUFS";
122
- let stdoutText = decode(result.stdout);
123
- let stderrText = decode(result.stderr);
124
- if (overflowed) {
125
- stdoutText += `
126
- [token-goat: capture capped at ${MAX_CAPTURE_BYTES / (1024 * 1024)} MiB]`;
127
- }
128
- let exitCode;
129
- if (timedOut) {
130
- exitCode = 124;
131
- stderrText = (stderrText ? stderrText + "\n" : "") + `[token-goat: command exceeded ${timeout}s timeout and was killed]`;
132
- } else if (result.status !== null) {
133
- exitCode = result.status;
134
- } else if (result.signal) {
135
- exitCode = signalExitCode(result.signal);
136
- } else {
137
- exitCode = 0;
138
- }
139
- if (opts.quietSuccess && exitCode === 0) {
140
- const duration = ((Date.now() - startTime) / 1e3).toFixed(1) + "s";
141
- const fullRaw = (stdoutText + (stderrText ? "\n" + stderrText : "")).trim();
142
- const id = storeBashOutputSync(command, fullRaw, 0, opts.cwd ?? null);
143
- const summary = `[tg: ok] ${command} (${duration}, recall: token-goat bash-output ${id})
144
- `;
145
- writeStdout(summary);
146
- return 0;
147
- }
148
- const limits = resolveCompressLimits();
149
- const { applied, marker, compressed, text: delivered } = deliverCompressed(filter, stdoutText, stderrText, exitCode, argv, {
150
- compressionProfile: profile,
151
- maxLines: limits.maxLines,
152
- maxBytes: limits.maxBytes
153
- });
154
- let text = delivered;
155
- const maxTokens = opts.maxTokens ?? 0;
156
- if (maxTokens > 0) text = capTokens(text, maxTokens);
157
- const body = text + marker;
158
- writeStdout(body.endsWith("\n") ? body : body + "\n");
159
- if (applied) recordSavings(compressed);
160
- return exitCode;
161
- }
162
- function recordSavings(result) {
163
- const delivered = deliveredOutputBytes(result.originalBytes);
164
- const bytesSaved = Math.max(0, delivered - result.compressedBytes);
165
- if (bytesSaved < MIN_RECORD_STAT_BYTES) return;
166
- recordStat(`bash_compress:${result.filterName}`, bytesSaved, compressedTokensSaved(bytesSaved));
167
- }
168
- export {
169
- DEFAULT_TIMEOUT_SECONDS,
170
- MAX_CAPTURE_BYTES,
171
- run,
172
- runRaw
173
- };
@@ -1,35 +0,0 @@
1
- import { createRequire as __cjsRequire } from 'node:module';
2
- const require = __cjsRequire(import.meta.url);
3
- import {
4
- buildEvent,
5
- relay,
6
- relayInProcess
7
- } from "./token-goat-chunk-WFX2V3OF.mjs";
8
- import "./token-goat-chunk-RHHFEXKF.mjs";
9
- import {
10
- MAX_STDIN_BYTES,
11
- readStdinJson
12
- } from "./token-goat-chunk-V3ZWBEHM.mjs";
13
- import "./token-goat-chunk-BFEWOMA3.mjs";
14
- import "./token-goat-chunk-CTOYJ232.mjs";
15
- import "./token-goat-chunk-HPOFR6QX.mjs";
16
- import "./token-goat-chunk-3BTK54F3.mjs";
17
- import "./token-goat-chunk-W3E65QOW.mjs";
18
- import "./token-goat-chunk-I67CPTDD.mjs";
19
- import "./token-goat-chunk-L7VCX33I.mjs";
20
- import "./token-goat-chunk-CA6V36KW.mjs";
21
- import "./token-goat-chunk-EEIDFMEM.mjs";
22
- import "./token-goat-chunk-OSUFN2FV.mjs";
23
- import "./token-goat-chunk-QIDLJGXZ.mjs";
24
- import "./token-goat-chunk-ERTXEKB6.mjs";
25
- import "./token-goat-chunk-Y4AFKTHK.mjs";
26
- import "./token-goat-chunk-GMOUBOX4.mjs";
27
- import "./token-goat-chunk-RRNZMM3A.mjs";
28
- import "./token-goat-chunk-A37V4PBF.mjs";
29
- export {
30
- MAX_STDIN_BYTES,
31
- buildEvent,
32
- readStdinJson,
33
- relay,
34
- relayInProcess
35
- };
@@ -1,93 +0,0 @@
1
- import { createRequire as __cjsRequire } from 'node:module';
2
- const require = __cjsRequire(import.meta.url);
3
- import {
4
- detectHarness
5
- } from "./token-goat-chunk-CA6V36KW.mjs";
6
- import {
7
- init_define_import_meta_env
8
- } from "./token-goat-chunk-A37V4PBF.mjs";
9
-
10
- // src/delivery_cap.ts
11
- init_define_import_meta_env();
12
- var CLAUDE_CODE_BASH_OUTPUT_CAP_BYTES = 2e4;
13
- function bashOutputCapBytes(harness = detectHarness()) {
14
- return harness === "claudecode" ? CLAUDE_CODE_BASH_OUTPUT_CAP_BYTES : null;
15
- }
16
- function clipToDeliveryCap(text, reserveBytes) {
17
- const cap = bashOutputCapBytes();
18
- const room = cap === null ? null : cap - reserveBytes;
19
- if (room === null || room <= 0 || Buffer.byteLength(text, "utf-8") <= room) return { text, clipped: false };
20
- const sliced = Buffer.from(text, "utf-8").subarray(0, room).toString("utf-8");
21
- const lastNewline = sliced.lastIndexOf("\n");
22
- return { text: lastNewline > 0 ? sliced.slice(0, lastNewline) : sliced, clipped: true };
23
- }
24
- function deliveredOutputBytes(originalBytes, harness) {
25
- const cap = bashOutputCapBytes(harness);
26
- if (cap === null) return Math.max(0, originalBytes);
27
- return Math.max(0, Math.min(originalBytes, cap));
28
- }
29
-
30
- // src/shell.ts
31
- init_define_import_meta_env();
32
- import * as fs from "node:fs";
33
- import * as path from "node:path";
34
- var WSL_LAUNCHER_SEGMENTS = /* @__PURE__ */ new Set(["system32", "syswow64", "windowsapps"]);
35
- function isExecutable(p) {
36
- try {
37
- return fs.statSync(p).isFile();
38
- } catch {
39
- return false;
40
- }
41
- }
42
- function isWslLauncherDir(dir) {
43
- return dir.toLowerCase().split(/[\\/]+/).some((seg) => WSL_LAUNCHER_SEGMENTS.has(seg));
44
- }
45
- function locateBashOnPath(pathValue, isExe = isExecutable) {
46
- for (const dir of (pathValue ?? "").split(path.delimiter)) {
47
- if (!dir || isWslLauncherDir(dir)) continue;
48
- const cand = path.join(dir, "bash.exe");
49
- if (isExe(cand)) return cand;
50
- }
51
- return null;
52
- }
53
- function knownGitBashPaths() {
54
- const localPrograms = process.env["LOCALAPPDATA"] ? path.join(process.env["LOCALAPPDATA"], "Programs") : void 0;
55
- const bases = [
56
- process.env["ProgramFiles"],
57
- process.env["ProgramFiles(x86)"],
58
- process.env["ProgramW6432"],
59
- localPrograms
60
- ];
61
- const out = [];
62
- for (const base of bases) {
63
- if (!base) continue;
64
- out.push(path.join(base, "Git", "bin", "bash.exe"));
65
- out.push(path.join(base, "Git", "usr", "bin", "bash.exe"));
66
- }
67
- return out;
68
- }
69
- function resolveWindowsBash() {
70
- if (process.platform !== "win32") return null;
71
- const override = process.env["TOKEN_GOAT_BASH"];
72
- if (override && isExecutable(override)) return override;
73
- const onPath = locateBashOnPath(process.env["PATH"]);
74
- if (onPath) return onPath;
75
- for (const cand of knownGitBashPaths()) {
76
- if (isExecutable(cand)) return cand;
77
- }
78
- return null;
79
- }
80
- function wrappedShell() {
81
- if (process.platform !== "win32") return true;
82
- return resolveWindowsBash() ?? true;
83
- }
84
- function canRunWrappedShell() {
85
- return process.platform !== "win32" || resolveWindowsBash() !== null;
86
- }
87
-
88
- export {
89
- clipToDeliveryCap,
90
- deliveredOutputBytes,
91
- wrappedShell,
92
- canRunWrappedShell
93
- };