token-goat 2.6.35 → 2.8.0

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 (35) hide show
  1. package/README.md +35 -7
  2. package/SECURITY.md +47 -16
  3. package/dist/{token-goat-chunk-I2KCEGIP.mjs → token-goat-chunk-2F6TFBZE.mjs} +1355 -408
  4. package/dist/token-goat-chunk-324QOJYZ.mjs +91 -0
  5. package/dist/{token-goat-chunk-K7W3P2TJ.mjs → token-goat-chunk-44Y77VHR.mjs} +425 -39
  6. package/dist/{token-goat-chunk-UIZVX3HN.mjs → token-goat-chunk-4KZILRZN.mjs} +2 -2
  7. package/dist/token-goat-chunk-5CVKO3DA.mjs +185 -0
  8. package/dist/token-goat-chunk-A62K4XW2.mjs +23 -0
  9. package/dist/{token-goat-chunk-SIHYQCTM.mjs → token-goat-chunk-AO6MFFTW.mjs} +331 -13
  10. package/dist/{token-goat-chunk-DRAIYVUI.mjs → token-goat-chunk-FBGBTICM.mjs} +4 -4
  11. package/dist/{token-goat-chunk-YF67EWRH.mjs → token-goat-chunk-J35AKWEQ.mjs} +5 -5
  12. package/dist/{token-goat-hook-chunk-4POU6OHK.mjs → token-goat-chunk-LVCBDJVE.mjs} +318 -51
  13. package/dist/token-goat-chunk-R4SR7MQY.mjs +486 -0
  14. package/dist/{token-goat-chunk-D5IZEGN2.mjs → token-goat-chunk-SRAR6DOK.mjs} +144 -147
  15. package/dist/{token-goat-hook-chunk-NIPXIAPA.mjs → token-goat-chunk-TUPJRK7R.mjs} +1 -1
  16. package/dist/{token-goat-chunk-HW4VUKJ5.mjs → token-goat-chunk-VXSYZGBA.mjs} +589 -141
  17. package/dist/{token-goat-chunk-DG53MVNJ.mjs → token-goat-chunk-WN5T5EW5.mjs} +212 -212
  18. package/dist/token-goat-hook.mjs +7 -7
  19. package/dist/token-goat.core.mjs +5 -5
  20. package/package.json +18 -15
  21. package/scripts/install-git-hooks.mjs +55 -0
  22. package/dist/token-goat-chunk-DQIT5JIF.mjs +0 -13659
  23. package/dist/token-goat-chunk-Y2NH6DGZ.mjs +0 -10048
  24. package/dist/token-goat-hook-chunk-2O7P4Z6Q.mjs +0 -6419
  25. package/dist/token-goat-hook-chunk-3AAH72SO.mjs +0 -15970
  26. package/dist/token-goat-hook-chunk-3QYSN4QV.mjs +0 -14764
  27. package/dist/token-goat-hook-chunk-BUOCULAM.mjs +0 -29
  28. package/dist/token-goat-hook-chunk-CRBMPT74.mjs +0 -900
  29. package/dist/token-goat-hook-chunk-D6UJEFHX.mjs +0 -153
  30. package/dist/token-goat-hook-chunk-J4HKWUWZ.mjs +0 -23
  31. package/dist/token-goat-hook-chunk-NXVT4F3S.mjs +0 -10406
  32. package/dist/token-goat-hook-chunk-RFRLWOQH.mjs +0 -11
  33. package/dist/token-goat-hook-chunk-VU6VGZBM.mjs +0 -706
  34. package/dist/token-goat-hook-chunk-XM4W3WCO.mjs +0 -18144
  35. package/dist/token-goat-hook-chunk-XUMIVYEN.mjs +0 -109
@@ -1,153 +0,0 @@
1
- import { createRequire as __cjsRequire } from 'node:module';
2
- const require = __cjsRequire(import.meta.url);
3
- import {
4
- ToolFilter,
5
- capTokens,
6
- combineStreams,
7
- compressOutput,
8
- filterByName,
9
- resolveMinNetSavingsBytes,
10
- selectFilter,
11
- shlexSplit,
12
- wrappedShell
13
- } from "./token-goat-hook-chunk-NIPXIAPA.mjs";
14
- import {
15
- loadConfig,
16
- recordStat
17
- } from "./token-goat-hook-chunk-2O7P4Z6Q.mjs";
18
- import "./token-goat-hook-chunk-BUOCULAM.mjs";
19
- import "./token-goat-hook-chunk-RFRLWOQH.mjs";
20
-
21
- // src/bash_runner.ts
22
- import { spawnSync } from "node:child_process";
23
- import * as os from "node:os";
24
- var IdentityFilter = class extends ToolFilter {
25
- name = "passthrough";
26
- };
27
- var DEFAULT_TIMEOUT_SECONDS = 600;
28
- var MAX_CAPTURE_BYTES = 32 * 1024 * 1024;
29
- var MIN_RECORD_STAT_BYTES = 32;
30
- function resolveFilter(command, filterName, cwd) {
31
- if (filterName) {
32
- const named = filterByName(filterName);
33
- if (named !== null) return named;
34
- }
35
- let argv;
36
- try {
37
- argv = shlexSplit(command);
38
- } catch {
39
- return null;
40
- }
41
- return selectFilter(argv, cwd);
42
- }
43
- function baseSpawnOptions(timeout, cwd, env) {
44
- return { shell: wrappedShell(), timeout: timeout * 1e3, cwd, env };
45
- }
46
- function signalExitCode(signal) {
47
- const num = os.constants.signals[signal];
48
- return 128 + (num ?? 0);
49
- }
50
- function resolveProfile(explicit) {
51
- if (explicit) return explicit;
52
- try {
53
- const p = loadConfig().compression.profile;
54
- return p && p !== "auto" ? p : "balanced";
55
- } catch {
56
- return "balanced";
57
- }
58
- }
59
- function resolveCompressLimits() {
60
- try {
61
- const bc = loadConfig().bash_compress;
62
- return { maxLines: bc.max_lines, maxBytes: bc.max_bytes };
63
- } catch {
64
- return { maxLines: 1e3, maxBytes: 64 * 1024 };
65
- }
66
- }
67
- function run(command, opts = {}) {
68
- const timeout = opts.timeout ?? DEFAULT_TIMEOUT_SECONDS;
69
- const filter = resolveFilter(command, opts.filterName, opts.cwd);
70
- if (filter === null) {
71
- if ((opts.maxTokens ?? 0) > 0) {
72
- return wrapAndCompress(command, new IdentityFilter(), timeout, resolveProfile(opts.compressionProfile), opts);
73
- }
74
- return passthrough(command, timeout, opts.cwd, opts.env);
75
- }
76
- return wrapAndCompress(command, filter, timeout, resolveProfile(opts.compressionProfile), opts);
77
- }
78
- function runRaw(command, timeout = DEFAULT_TIMEOUT_SECONDS) {
79
- return passthrough(command, timeout, void 0, void 0);
80
- }
81
- function passthrough(command, timeout, cwd, env) {
82
- const result = spawnSync(command, { ...baseSpawnOptions(timeout, cwd, env), stdio: "inherit" });
83
- if (isTimeout(result.error)) return 124;
84
- if (result.status !== null) return result.status;
85
- if (result.signal) return signalExitCode(result.signal);
86
- return 0;
87
- }
88
- function isTimeout(error) {
89
- return !!error && error.code === "ETIMEDOUT";
90
- }
91
- function decode(buf) {
92
- if (buf == null) return "";
93
- return typeof buf === "string" ? buf : buf.toString("utf8");
94
- }
95
- function wrapAndCompress(command, filter, timeout, profile, opts) {
96
- const writeStdout = opts.writeStdout ?? ((s) => process.stdout.write(s));
97
- const result = spawnSync(command, {
98
- ...baseSpawnOptions(timeout, opts.cwd, opts.env),
99
- stdio: ["ignore", "pipe", "pipe"],
100
- maxBuffer: MAX_CAPTURE_BYTES
101
- });
102
- const timedOut = isTimeout(result.error);
103
- const overflowed = !!result.error && result.error.code === "ENOBUFS";
104
- let stdoutText = decode(result.stdout);
105
- let stderrText = decode(result.stderr);
106
- if (overflowed) {
107
- stdoutText += `
108
- [token-goat: capture capped at ${MAX_CAPTURE_BYTES / (1024 * 1024)} MiB]`;
109
- }
110
- let exitCode;
111
- if (timedOut) {
112
- exitCode = 124;
113
- stderrText = (stderrText ? stderrText + "\n" : "") + `[token-goat: command exceeded ${timeout}s timeout and was killed]`;
114
- } else if (result.status !== null) {
115
- exitCode = result.status;
116
- } else if (result.signal) {
117
- exitCode = signalExitCode(result.signal);
118
- } else {
119
- exitCode = 0;
120
- }
121
- let argv;
122
- try {
123
- argv = shlexSplit(command);
124
- } catch {
125
- argv = [command];
126
- }
127
- const limits = resolveCompressLimits();
128
- const compressed = compressOutput(filter, stdoutText, stderrText, exitCode, argv, {
129
- compressionProfile: profile,
130
- maxLines: limits.maxLines,
131
- maxBytes: limits.maxBytes
132
- });
133
- const minNetSavingsBytes = resolveMinNetSavingsBytes();
134
- const applied = compressed.worthApplying(minNetSavingsBytes);
135
- let text = applied ? compressed.text : combineStreams(stdoutText, stderrText);
136
- const maxTokens = opts.maxTokens ?? 0;
137
- if (maxTokens > 0) text = capTokens(text, maxTokens);
138
- const marker = applied ? compressed.withMarker(minNetSavingsBytes).slice(compressed.text.length) : "";
139
- const body = text + marker;
140
- writeStdout(body.endsWith("\n") ? body : body + "\n");
141
- if (applied) recordSavings(compressed);
142
- return exitCode;
143
- }
144
- function recordSavings(result) {
145
- if (result.bytesSaved < MIN_RECORD_STAT_BYTES) return;
146
- recordStat(`bash_compress:${result.filterName}`, result.bytesSaved, result.tokensSaved);
147
- }
148
- export {
149
- DEFAULT_TIMEOUT_SECONDS,
150
- MAX_CAPTURE_BYTES,
151
- run,
152
- runRaw
153
- };
@@ -1,23 +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-hook-chunk-4POU6OHK.mjs";
8
- import "./token-goat-hook-chunk-NIPXIAPA.mjs";
9
- import {
10
- MAX_STDIN_BYTES,
11
- readStdinJson
12
- } from "./token-goat-hook-chunk-CRBMPT74.mjs";
13
- import "./token-goat-hook-chunk-XM4W3WCO.mjs";
14
- import "./token-goat-hook-chunk-2O7P4Z6Q.mjs";
15
- import "./token-goat-hook-chunk-BUOCULAM.mjs";
16
- import "./token-goat-hook-chunk-RFRLWOQH.mjs";
17
- export {
18
- MAX_STDIN_BYTES,
19
- buildEvent,
20
- readStdinJson,
21
- relay,
22
- relayInProcess
23
- };