@luckydraw/cumulus 1.0.12 → 1.0.14
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.
- package/CHANGELOG.md +14 -0
- package/dist/lib/agentic-loop.d.ts +10 -0
- package/dist/lib/agentic-loop.d.ts.map +1 -1
- package/dist/lib/agentic-loop.js +64 -1
- package/dist/lib/agentic-loop.js.map +1 -1
- package/dist/lib/content-store.d.ts +82 -3
- package/dist/lib/content-store.d.ts.map +1 -1
- package/dist/lib/content-store.js +159 -21
- package/dist/lib/content-store.js.map +1 -1
- package/dist/lib/embeddings.d.ts +14 -0
- package/dist/lib/embeddings.d.ts.map +1 -1
- package/dist/lib/embeddings.js +1 -1
- package/dist/lib/embeddings.js.map +1 -1
- package/dist/lib/gateway.d.ts +17 -0
- package/dist/lib/gateway.d.ts.map +1 -1
- package/dist/lib/gateway.js +64 -28
- package/dist/lib/gateway.js.map +1 -1
- package/dist/lib/tools/bash.d.ts.map +1 -1
- package/dist/lib/tools/bash.js +83 -22
- package/dist/lib/tools/bash.js.map +1 -1
- package/package.json +1 -1
package/dist/lib/tools/bash.js
CHANGED
|
@@ -5,6 +5,8 @@ import { spawn } from 'child_process';
|
|
|
5
5
|
const DEFAULT_TIMEOUT = 120_000; // 2 minutes
|
|
6
6
|
const MAX_TIMEOUT = 600_000; // 10 minutes
|
|
7
7
|
const MAX_OUTPUT = 100_000; // 100KB output cap
|
|
8
|
+
/** Grace period after `exit` for buffered output to arrive when `close` cannot fire. */
|
|
9
|
+
const EXIT_DRAIN_MS = 500;
|
|
8
10
|
export const bashTool = {
|
|
9
11
|
definition: {
|
|
10
12
|
name: 'Bash',
|
|
@@ -32,23 +34,81 @@ export const bashTool = {
|
|
|
32
34
|
return new Promise(resolve => {
|
|
33
35
|
let stdout = '';
|
|
34
36
|
let stderr = '';
|
|
35
|
-
let
|
|
37
|
+
let timedOut = false;
|
|
38
|
+
let outputCapped = false;
|
|
39
|
+
let settled = false;
|
|
40
|
+
let exitCode = null;
|
|
41
|
+
let drainTimer;
|
|
42
|
+
// `detached` makes the child a process-group leader, so signalling `-pid`
|
|
43
|
+
// reaches everything it spawned. Without it a timeout kills only `bash`
|
|
44
|
+
// and leaves its children running, orphaned, holding our stdout pipe.
|
|
36
45
|
const proc = spawn('bash', ['-c', command], {
|
|
37
46
|
cwd,
|
|
38
47
|
env: { ...process.env, TERM: 'dumb' },
|
|
39
48
|
stdio: ['ignore', 'pipe', 'pipe'],
|
|
49
|
+
detached: true,
|
|
40
50
|
});
|
|
51
|
+
/** Signal the whole process group; the process may already be gone. */
|
|
52
|
+
const killTree = (signal) => {
|
|
53
|
+
if (proc.pid === undefined)
|
|
54
|
+
return;
|
|
55
|
+
try {
|
|
56
|
+
process.kill(-proc.pid, signal);
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
// Already exited, or the group is gone — nothing to do.
|
|
60
|
+
}
|
|
61
|
+
};
|
|
41
62
|
const timer = setTimeout(() => {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
setTimeout(() =>
|
|
63
|
+
timedOut = true;
|
|
64
|
+
killTree('SIGTERM');
|
|
65
|
+
setTimeout(() => killTree('SIGKILL'), 5000).unref();
|
|
45
66
|
}, timeout);
|
|
67
|
+
/**
|
|
68
|
+
* Finalize. `viaClose` is false when the process exited but a surviving
|
|
69
|
+
* child still holds our stdout pipe — the case that used to hang forever.
|
|
70
|
+
*/
|
|
71
|
+
const finish = (viaClose) => {
|
|
72
|
+
if (settled)
|
|
73
|
+
return;
|
|
74
|
+
settled = true;
|
|
75
|
+
clearTimeout(timer);
|
|
76
|
+
if (drainTimer)
|
|
77
|
+
clearTimeout(drainTimer);
|
|
78
|
+
let result = '';
|
|
79
|
+
if (stdout)
|
|
80
|
+
result += stdout;
|
|
81
|
+
if (stderr) {
|
|
82
|
+
if (result)
|
|
83
|
+
result += '\n';
|
|
84
|
+
result += `STDERR:\n${stderr}`;
|
|
85
|
+
}
|
|
86
|
+
if (timedOut) {
|
|
87
|
+
result +=
|
|
88
|
+
`\n\n[Command timed out after ${timeout}ms; its process group was killed. ` +
|
|
89
|
+
`For work that outlives a turn, use run_job instead.]`;
|
|
90
|
+
}
|
|
91
|
+
else if (outputCapped) {
|
|
92
|
+
result += `\n\n[Command killed after exceeding the ${MAX_OUTPUT}-byte output cap]`;
|
|
93
|
+
}
|
|
94
|
+
else if (exitCode !== 0 && exitCode !== null) {
|
|
95
|
+
result += `\nExit code: ${exitCode}`;
|
|
96
|
+
}
|
|
97
|
+
if (!viaClose) {
|
|
98
|
+
result +=
|
|
99
|
+
`\n\n[The command exited but left a background process holding its output stream, ` +
|
|
100
|
+
`so output may be incomplete and that process is still running. ` +
|
|
101
|
+
`Use run_job for work that should outlive the command.]`;
|
|
102
|
+
}
|
|
103
|
+
resolve(result || `(no output, exit code ${exitCode})`);
|
|
104
|
+
};
|
|
46
105
|
proc.stdout.on('data', (data) => {
|
|
47
106
|
stdout += data.toString();
|
|
48
107
|
if (stdout.length > MAX_OUTPUT) {
|
|
49
108
|
stdout = stdout.slice(0, MAX_OUTPUT) + '\n\n[Output truncated at 100KB]';
|
|
50
|
-
|
|
51
|
-
|
|
109
|
+
outputCapped = true;
|
|
110
|
+
killTree('SIGTERM');
|
|
111
|
+
setTimeout(() => killTree('SIGKILL'), 5000).unref();
|
|
52
112
|
}
|
|
53
113
|
});
|
|
54
114
|
proc.stderr.on('data', (data) => {
|
|
@@ -57,26 +117,27 @@ export const bashTool = {
|
|
|
57
117
|
stderr = stderr.slice(0, MAX_OUTPUT);
|
|
58
118
|
}
|
|
59
119
|
});
|
|
120
|
+
// `close` fires only once every stdio stream is closed, which a surviving
|
|
121
|
+
// grandchild can defer indefinitely. `exit` fires when the process itself
|
|
122
|
+
// ends, so it is the signal we actually depend on; `close` is preferred
|
|
123
|
+
// when it arrives because it guarantees the output is complete.
|
|
124
|
+
proc.on('exit', code => {
|
|
125
|
+
exitCode = code;
|
|
126
|
+
drainTimer = setTimeout(() => finish(false), EXIT_DRAIN_MS);
|
|
127
|
+
drainTimer.unref();
|
|
128
|
+
});
|
|
60
129
|
proc.on('close', code => {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
result += stdout;
|
|
65
|
-
if (stderr) {
|
|
66
|
-
if (result)
|
|
67
|
-
result += '\n';
|
|
68
|
-
result += `STDERR:\n${stderr}`;
|
|
69
|
-
}
|
|
70
|
-
if (killed) {
|
|
71
|
-
result += `\n\n[Command timed out after ${timeout}ms]`;
|
|
72
|
-
}
|
|
73
|
-
else if (code !== 0 && code !== null) {
|
|
74
|
-
result += `\nExit code: ${code}`;
|
|
75
|
-
}
|
|
76
|
-
resolve(result || `(no output, exit code ${code})`);
|
|
130
|
+
if (exitCode === null)
|
|
131
|
+
exitCode = code;
|
|
132
|
+
finish(true);
|
|
77
133
|
});
|
|
78
134
|
proc.on('error', err => {
|
|
135
|
+
if (settled)
|
|
136
|
+
return;
|
|
137
|
+
settled = true;
|
|
79
138
|
clearTimeout(timer);
|
|
139
|
+
if (drainTimer)
|
|
140
|
+
clearTimeout(drainTimer);
|
|
80
141
|
resolve(`Error executing command: ${err.message}`);
|
|
81
142
|
});
|
|
82
143
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bash.js","sourceRoot":"","sources":["../../../src/lib/tools/bash.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAItC,MAAM,eAAe,GAAG,OAAO,CAAC,CAAC,YAAY;AAC7C,MAAM,WAAW,GAAG,OAAO,CAAC,CAAC,aAAa;AAC1C,MAAM,UAAU,GAAG,OAAO,CAAC,CAAC,mBAAmB;
|
|
1
|
+
{"version":3,"file":"bash.js","sourceRoot":"","sources":["../../../src/lib/tools/bash.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAItC,MAAM,eAAe,GAAG,OAA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