blun-king-cli 9.1.526 → 9.1.536

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 (44) hide show
  1. package/CHANGELOG.md +67 -0
  2. package/LIESMICH.txt +36 -1
  3. package/README.md +35 -1
  4. package/bin/agent-resume-snapshot.cjs +31 -0
  5. package/bin/assistant-message-offload-policy.cjs +21 -2
  6. package/bin/codebase-search-runtime.cjs +23 -0
  7. package/bin/empty-response-retry-policy.cjs +29 -0
  8. package/bin/fredrik-glm-provider.cjs +256 -0
  9. package/bin/history-offload-pressure-policy.cjs +33 -0
  10. package/bin/programmatic-context-isolation.cjs +25 -0
  11. package/bin/programmatic-tool-runtime.mjs +301 -0
  12. package/bin/skill-activation-performance-policy.cjs +9 -0
  13. package/bin/structured-subagent-output.cjs +252 -0
  14. package/bin/telegram-direct-focus-policy.cjs +25 -1
  15. package/bin/todo-list-turn-policy.cjs +111 -1
  16. package/bin/tool-result-offload-policy.cjs +29 -0
  17. package/bin/turn-thinking-policy.cjs +6 -15
  18. package/bin/turn-tool-performance-policy.cjs +5 -4
  19. package/bin/user-message-offload-policy.cjs +10 -1
  20. package/blun.mjs +709 -127
  21. package/codebase-index/README.md +70 -0
  22. package/codebase-index/codebase_index.py +358 -0
  23. package/fredrik-glm-profile.toml.example +26 -0
  24. package/package.json +25 -3
  25. package/scripts/check-active-work-steer-regression.js +46 -0
  26. package/scripts/check-codebase-search-packaging-regression.js +92 -0
  27. package/scripts/check-copy-command-regression.js +74 -0
  28. package/scripts/check-current-turn-read-pin-mutation-regression.js +72 -0
  29. package/scripts/check-current-turn-read-pin-regression.js +94 -0
  30. package/scripts/check-deepseek-native-max-regression.js +49 -0
  31. package/scripts/check-empty-response-effort-downgrade-regression.js +48 -0
  32. package/scripts/check-fredrik-glm-mutation-regression.js +18 -0
  33. package/scripts/check-fredrik-glm-regression.js +169 -0
  34. package/scripts/check-history-pressure-offload-regression.js +77 -0
  35. package/scripts/check-programmatic-context-isolation-regression.js +193 -0
  36. package/scripts/check-programmatic-tool-regression.js +294 -0
  37. package/scripts/check-resume-replay-regression.js +2 -0
  38. package/scripts/check-startup-swarm-command-regression.js +24 -0
  39. package/scripts/check-structured-subagent-output-regression.js +331 -0
  40. package/scripts/check-telegram-direct-work-resume-regression.js +53 -0
  41. package/scripts/check-todo-progress-regression.js +416 -0
  42. package/scripts/check-tool-schema-capacity-regression.js +40 -0
  43. package/scripts/programmatic-tool-runtime.test.mjs +365 -0
  44. package/scripts/structured-subagent-output.test.cjs +170 -0
@@ -0,0 +1,193 @@
1
+ 'use strict';
2
+
3
+ const assert = require('node:assert/strict');
4
+ const { readFileSync } = require('node:fs');
5
+ const { join } = require('node:path');
6
+ const vm = require('node:vm');
7
+ const {
8
+ PROGRAMMATIC_WIRE_ONLY,
9
+ isWireOnlyProgrammaticEvent,
10
+ markProgrammaticNestedEvent,
11
+ } = require('../bin/programmatic-context-isolation.cjs');
12
+ const { projectLoopEventForRecord } = require('../bin/loop-event-record-policy.cjs');
13
+
14
+ const root = join(__dirname, '..');
15
+ const bundlePath = process.env.BLUN_PROGRAMMATIC_CONTEXT_BUNDLE || join(root, 'blun.mjs');
16
+ const source = readFileSync(bundlePath, 'utf8');
17
+
18
+ function between(text, startMarker, endMarker) {
19
+ const start = text.indexOf(startMarker);
20
+ const end = text.indexOf(endMarker, start + startMarker.length);
21
+ assert.ok(start >= 0 && end > start, `missing source region ${startMarker}`);
22
+ return text.slice(start, end);
23
+ }
24
+
25
+ function assertRuntimePolicy() {
26
+ const nestedCall = {
27
+ type: 'tool.call',
28
+ toolCallId: 'outer:ptc:ptc_Read_1',
29
+ name: 'Read',
30
+ args: { path: 'fixture.txt' },
31
+ };
32
+ const markedCall = markProgrammaticNestedEvent(nestedCall);
33
+ assert.notEqual(markedCall, nestedCall);
34
+ assert.equal(markedCall.contextVisibility, PROGRAMMATIC_WIRE_ONLY);
35
+ assert.equal(isWireOnlyProgrammaticEvent(markedCall), true);
36
+
37
+ const markedResult = markProgrammaticNestedEvent({
38
+ type: 'tool.result',
39
+ toolCallId: nestedCall.toolCallId,
40
+ result: { output: 'private nested payload' },
41
+ });
42
+ assert.equal(isWireOnlyProgrammaticEvent(markedResult), true);
43
+
44
+ const contentPart = { type: 'content.part', part: { type: 'text', text: 'visible' } };
45
+ assert.equal(markProgrammaticNestedEvent(contentPart), contentPart);
46
+ assert.equal(isWireOnlyProgrammaticEvent({ ...contentPart, contextVisibility: PROGRAMMATIC_WIRE_ONLY }), false);
47
+ assert.equal(isWireOnlyProgrammaticEvent({ ...nestedCall, contextVisibility: 'other' }), false);
48
+
49
+ const recorded = projectLoopEventForRecord(markedCall);
50
+ assert.equal(recorded.contextVisibility, PROGRAMMATIC_WIRE_ONLY, 'wire projection must preserve the isolation marker for resume');
51
+ }
52
+
53
+ function assertBundleContract(bundle) {
54
+ assert.match(bundle, /markProgrammaticNestedEvent\(event\)/u, 'nested dispatcher must mark internal tool events');
55
+ assert.match(bundle, /isWireOnlyProgrammaticEvent\(event\)/u, 'context fold must recognize wire-only events');
56
+ assert.match(bundle, /\.\/bin\/programmatic-context-isolation\.cjs/u, 'bundle must load the isolation policy');
57
+
58
+ const nestedRegion = between(bundle, 'function createNestedToolInvoker(', 'function nestedToolResultText(');
59
+ assert.match(
60
+ nestedRegion,
61
+ /dispatchEvent:\s*\(event\)\s*=>\s*step\.dispatchEvent\(markProgrammaticNestedEvent\(event\)\)/u,
62
+ 'every nested tool event must cross the wire-only marker boundary',
63
+ );
64
+
65
+ const contextRegion = between(bundle, '\t\tappendLoopEvent(event) {', '\n\t\tappendMessage(message) {');
66
+ const logIndex = contextRegion.indexOf('this.agent.records.logRecord({');
67
+ const skipIndex = contextRegion.indexOf('if (isWireOnlyProgrammaticEvent(event)) return;');
68
+ const switchIndex = contextRegion.indexOf('switch (event.type)');
69
+ assert.ok(skipIndex >= 0, 'context fold must exclude wire-only events');
70
+ assert.ok(logIndex >= 0 && skipIndex > logIndex, 'wire record must be written before context exclusion');
71
+ assert.ok(switchIndex > skipIndex, 'wire-only event must be excluded before any context mutation');
72
+
73
+ assert.match(
74
+ bundle,
75
+ /case "context\.append_loop_event":\s*agent\.context\.appendLoopEvent\(input\.event\)/u,
76
+ 'resume must reuse the same guarded context fold',
77
+ );
78
+ }
79
+
80
+ function loadContextMemoryFromBundle(bundle) {
81
+ const classBody = between(
82
+ bundle,
83
+ '\tContextMemory = class {',
84
+ '\n\t};\n}));\n//#endregion\n//#region ../../packages/agent-core/src/agent/injection',
85
+ );
86
+ const sandbox = {
87
+ ContextMemory: null,
88
+ USER_PROMPT_ORIGIN: { kind: 'user' },
89
+ createPendingTokenEstimateCache: () => ({}),
90
+ createToolMessage: (toolCallId, output) => ({
91
+ role: 'tool',
92
+ content: [{ type: 'text', text: output }],
93
+ toolCalls: [],
94
+ toolCallId,
95
+ }),
96
+ estimateTokensForMessages: () => 0,
97
+ isWireOnlyProgrammaticEvent,
98
+ projectLoopEventForRecord,
99
+ resolveCompletedStepUuid: () => 'outer-step',
100
+ resolveStepEventUuid: () => 'outer-step',
101
+ toolResultOutputForModel: (result) => String(result.output ?? ''),
102
+ };
103
+ vm.runInNewContext(`${classBody}\n};`, sandbox, { filename: 'ContextMemory.extracted.js' });
104
+ return sandbox.ContextMemory;
105
+ }
106
+
107
+ function createAgentRecordHarness() {
108
+ const records = [];
109
+ return {
110
+ agent: {
111
+ background: { markDeliveredNotification() {} },
112
+ log: { warn() {} },
113
+ records: {
114
+ restoring: null,
115
+ logRecord(record) { records.push(record); },
116
+ },
117
+ replayBuilder: { push() {} },
118
+ },
119
+ records,
120
+ };
121
+ }
122
+
123
+ function assertContextFoldRuntime(bundle) {
124
+ const ContextMemory = loadContextMemoryFromBundle(bundle);
125
+ const { agent, records } = createAgentRecordHarness();
126
+ const memory = new ContextMemory(agent);
127
+ const outerCall = {
128
+ type: 'tool.call',
129
+ toolCallId: 'outer-call',
130
+ name: 'ProgrammaticTool',
131
+ args: { code: 'return tools.Read({ path: "fixture.txt" })' },
132
+ };
133
+ const nestedCall = markProgrammaticNestedEvent({
134
+ type: 'tool.call',
135
+ toolCallId: 'outer-call:ptc:ptc_Read_1',
136
+ name: 'Read',
137
+ args: { path: 'fixture.txt' },
138
+ });
139
+ const nestedResult = markProgrammaticNestedEvent({
140
+ type: 'tool.result',
141
+ toolCallId: nestedCall.toolCallId,
142
+ result: { output: 'private nested payload' },
143
+ });
144
+ const outerResult = {
145
+ type: 'tool.result',
146
+ toolCallId: outerCall.toolCallId,
147
+ result: { output: 'bounded outer summary' },
148
+ };
149
+
150
+ for (const event of [outerCall, nestedCall, nestedResult, outerResult]) {
151
+ memory.appendLoopEvent(event);
152
+ }
153
+
154
+ assert.equal(records.length, 4, 'wire must retain outer and nested events');
155
+ assert.equal(records[1].event.contextVisibility, PROGRAMMATIC_WIRE_ONLY);
156
+ assert.equal(records[2].event.contextVisibility, PROGRAMMATIC_WIRE_ONLY);
157
+ const historyJson = JSON.stringify(memory._history);
158
+ assert.match(historyJson, /outer-call/u);
159
+ assert.match(historyJson, /bounded outer summary/u);
160
+ assert.doesNotMatch(historyJson, /ptc_Read_1/u, 'nested call must stay out of model history');
161
+ assert.doesNotMatch(historyJson, /private nested payload/u, 'nested result must stay out of model history');
162
+
163
+ const resumedHarness = createAgentRecordHarness();
164
+ const resumed = new ContextMemory(resumedHarness.agent);
165
+ for (const record of records) resumed.appendLoopEvent(record.event);
166
+ assert.deepEqual(
167
+ JSON.parse(JSON.stringify(resumed._history)),
168
+ JSON.parse(historyJson),
169
+ 'resume must rebuild the same bounded model history',
170
+ );
171
+ assert.equal(resumedHarness.records[1].event.contextVisibility, PROGRAMMATIC_WIRE_ONLY);
172
+ assert.equal(resumedHarness.records[2].event.contextVisibility, PROGRAMMATIC_WIRE_ONLY);
173
+ }
174
+
175
+ function assertMutationCoverage() {
176
+ assert.throws(
177
+ () => assertBundleContract(source.replace(
178
+ 'if (isWireOnlyProgrammaticEvent(event)) return;',
179
+ 'if (isWireOnlyProgrammaticEvent(event)) void 0;',
180
+ )),
181
+ /context fold must exclude wire-only events/u,
182
+ );
183
+ assert.throws(
184
+ () => assertBundleContract(source.replace('markProgrammaticNestedEvent(event)', 'event')),
185
+ /nested dispatcher must mark/u,
186
+ );
187
+ }
188
+
189
+ assertRuntimePolicy();
190
+ assertBundleContract(source);
191
+ assertContextFoldRuntime(source);
192
+ assertMutationCoverage();
193
+ process.stdout.write('programmatic-context-isolation-regression PASS\n');
@@ -0,0 +1,294 @@
1
+ 'use strict';
2
+
3
+ const assert = require('node:assert/strict');
4
+ const { spawnSync } = require('node:child_process');
5
+ const { readFileSync } = require('node:fs');
6
+ const { join } = require('node:path');
7
+ const { pathToFileURL } = require('node:url');
8
+ const {
9
+ PROGRAMMATIC_WIRE_ONLY,
10
+ markProgrammaticNestedEvent,
11
+ } = require('../bin/programmatic-context-isolation.cjs');
12
+
13
+ const root = join(__dirname, '..');
14
+ const bundlePath = join(root, 'blun.mjs');
15
+ const runtimePath = join(root, 'bin', 'programmatic-tool-runtime.mjs');
16
+
17
+ function assertBundleContract(source) {
18
+ assert.match(source, /ProgrammaticTool = class/u, 'ProgrammaticTool class must exist');
19
+ assert.match(source, /new ProgrammaticTool\(\)/u, 'ProgrammaticTool must be registered as a builtin');
20
+ assert.match(
21
+ source,
22
+ /CodebaseSearch\\n - ProgrammaticTool\\n/u,
23
+ 'the default agent profile must expose ProgrammaticTool',
24
+ );
25
+ assert.match(
26
+ source,
27
+ /DEFAULT_APPROVE_TOOLS = new Set\(\[[\s\S]{0,500}"ProgrammaticTool"/u,
28
+ 'the host-isolated outer interpreter must not add a redundant approval dialog',
29
+ );
30
+ assert.match(source, /function createNestedToolInvoker\(/u, 'nested tool invoker must exist');
31
+ assert.match(
32
+ source,
33
+ /preflightToolCall\(nestedStep, nestedToolCall\)/u,
34
+ 'nested calls must enter the normal preflight path',
35
+ );
36
+ assert.match(
37
+ source,
38
+ /prepareToolCall\(nestedStep, preflight\)/u,
39
+ 'nested calls must enter preparation and authorization',
40
+ );
41
+ assert.match(
42
+ source,
43
+ /finalizePendingToolResult\(nestedStep,/u,
44
+ 'nested calls must enter result finalization',
45
+ );
46
+ assert.match(
47
+ source,
48
+ /if \(finalized\.stopTurn === true\) invoke\.stopTurn = true/u,
49
+ 'nested turn-stop results must propagate to the outer tool result',
50
+ );
51
+ assert.match(
52
+ source,
53
+ /if \(context\.invokeTool\.stopTurn === true\) result\.stopTurn = true/u,
54
+ 'ProgrammaticTool must return the propagated turn-stop marker',
55
+ );
56
+ assert.match(
57
+ source,
58
+ /Nested ProgrammaticTool calls are not allowed/u,
59
+ 'recursive interpreter calls must fail closed',
60
+ );
61
+ assert.match(
62
+ source,
63
+ /toolName === PROGRAMMATIC_TOOL_NAME[\s\S]{0,240}createNestedToolInvoker/u,
64
+ 'only ProgrammaticTool may receive the nested invocation capability',
65
+ );
66
+
67
+ const { CORE_TOOL_NAMES } = require(join(root, 'bin', 'turn-tool-performance-policy.cjs'));
68
+ assert.equal(
69
+ CORE_TOOL_NAMES.includes('ProgrammaticTool'),
70
+ false,
71
+ 'ProgrammaticTool must remain eligible for schema deferral',
72
+ );
73
+ }
74
+
75
+ function extractBetween(source, startNeedle, endNeedle) {
76
+ const start = source.indexOf(startNeedle);
77
+ assert.notEqual(start, -1, `missing source start: ${startNeedle}`);
78
+ const end = source.indexOf(endNeedle, start + startNeedle.length);
79
+ assert.notEqual(end, -1, `missing source end: ${endNeedle}`);
80
+ return source.slice(start, end);
81
+ }
82
+
83
+ async function exerciseBundledProgrammaticTool(source) {
84
+ const assignment = extractBetween(
85
+ source,
86
+ 'ProgrammaticTool = class {',
87
+ '\n\t};\n}));\n//#endregion',
88
+ );
89
+ const classSource = `${assignment.slice('ProgrammaticTool = '.length)}\n\t}`
90
+ .replaceAll('import.meta.url', JSON.stringify(pathToFileURL(bundlePath).href));
91
+ const ProgrammaticTool = Function(
92
+ 'PROGRAMMATIC_TOOL_NAME',
93
+ `"use strict"; return (${classSource});`,
94
+ )('ProgrammaticTool');
95
+ const tool = new ProgrammaticTool();
96
+ const updates = [];
97
+ const nestedCalls = [];
98
+ const invokeTool = async (call) => {
99
+ nestedCalls.push(call);
100
+ return { output: JSON.stringify(call.args) };
101
+ };
102
+ invokeTool.stopTurn = true;
103
+
104
+ const execution = tool.resolveExecution({
105
+ code: 'state.done = true; return tools.echo({ value: 12 });',
106
+ state: {},
107
+ tools: [{ name: 'Echo', alias: 'echo' }],
108
+ });
109
+ const result = await execution.execute({
110
+ signal: new AbortController().signal,
111
+ invokeTool,
112
+ onUpdate: (update) => updates.push(update),
113
+ });
114
+ assert.equal(result.isError, false);
115
+ assert.equal(result.stopTurn, true);
116
+ assert.equal(nestedCalls.length, 1);
117
+ assert.equal(nestedCalls[0].name, 'Echo');
118
+ assert.deepEqual(JSON.parse(result.output).state, { done: true });
119
+ assert.deepEqual(updates.map((update) => update.event.type), [
120
+ 'interpreter.started',
121
+ 'interpreter.tool_call',
122
+ 'interpreter.tool_result',
123
+ 'interpreter.completed',
124
+ ]);
125
+
126
+ const unavailable = await tool.resolveExecution({ code: 'return 1;' }).execute({
127
+ signal: new AbortController().signal,
128
+ onUpdate: () => {},
129
+ });
130
+ assert.equal(unavailable.isError, true);
131
+ assert.match(unavailable.output, /invocation boundary is unavailable/u);
132
+ }
133
+
134
+ async function exerciseBundledNestedPipeline(source) {
135
+ const nestedSource = extractBetween(
136
+ source,
137
+ 'function createNestedToolInvoker(',
138
+ 'function nestedToolResultText(',
139
+ );
140
+ const calls = [];
141
+ let stopNext = true;
142
+ const preflightToolCall = (step, toolCall) => {
143
+ calls.push(['preflight', toolCall.name]);
144
+ return { kind: 'runnable', toolCall, toolName: toolCall.name, args: JSON.parse(toolCall.arguments) };
145
+ };
146
+ const prepareToolCall = async (_step, call) => {
147
+ calls.push(['prepare', call.toolName]);
148
+ return {
149
+ task: {
150
+ start: async () => ({
151
+ result: Promise.resolve({
152
+ toolCall: call.toolCall,
153
+ toolName: call.toolName,
154
+ args: call.args,
155
+ result: { output: 'nested-ok' },
156
+ }),
157
+ }),
158
+ },
159
+ };
160
+ };
161
+ const finalizePendingToolResult = async (_step, pending) => {
162
+ calls.push(['finalize', pending.toolName]);
163
+ return { ...pending, stopTurn: stopNext };
164
+ };
165
+ const nestedToolResultText = (result) => String(result.output || 'nested failure');
166
+ const createNestedToolInvoker = Function(
167
+ 'preflightToolCall',
168
+ 'prepareToolCall',
169
+ 'finalizePendingToolResult',
170
+ 'nestedToolResultText',
171
+ 'PROGRAMMATIC_TOOL_NAME',
172
+ 'markProgrammaticNestedEvent',
173
+ `"use strict"; ${nestedSource}; return createNestedToolInvoker;`,
174
+ )(
175
+ preflightToolCall,
176
+ prepareToolCall,
177
+ finalizePendingToolResult,
178
+ nestedToolResultText,
179
+ 'ProgrammaticTool',
180
+ markProgrammaticNestedEvent,
181
+ );
182
+ const events = [];
183
+ const step = {
184
+ signal: new AbortController().signal,
185
+ tools: [],
186
+ dispatchEvent: async (event) => events.push(event),
187
+ };
188
+ const invoke = createNestedToolInvoker(step, { id: 'outer' });
189
+ const result = await invoke({ name: 'Echo', args: { value: 3 }, callId: 'one' });
190
+ assert.equal(result.output, 'nested-ok');
191
+ assert.deepEqual(calls, [
192
+ ['preflight', 'Echo'],
193
+ ['prepare', 'Echo'],
194
+ ['finalize', 'Echo'],
195
+ ]);
196
+ assert.equal(events[0].type, 'tool.result');
197
+ assert.equal(events[0].toolCallId, 'outer:ptc:one');
198
+ assert.equal(events[0].contextVisibility, PROGRAMMATIC_WIRE_ONLY);
199
+ assert.equal(invoke.stopTurn, true);
200
+ await assert.rejects(
201
+ invoke({ name: 'Echo', args: {}, callId: 'two' }),
202
+ /after a turn-stop result/u,
203
+ );
204
+
205
+ stopNext = false;
206
+ const recursive = createNestedToolInvoker(step, { id: 'outer-two' });
207
+ await assert.rejects(
208
+ recursive({ name: 'ProgrammaticTool', args: {}, callId: 'recursive' }),
209
+ /Nested ProgrammaticTool calls are not allowed/u,
210
+ );
211
+ }
212
+
213
+ async function main() {
214
+ const suite = spawnSync(
215
+ process.execPath,
216
+ ['--test', join(__dirname, 'programmatic-tool-runtime.test.mjs')],
217
+ { stdio: 'inherit' },
218
+ );
219
+ assert.equal(suite.status, 0, 'programmatic runtime test suite must pass');
220
+
221
+ const source = readFileSync(bundlePath, 'utf8');
222
+ assertBundleContract(source);
223
+ await exerciseBundledProgrammaticTool(source);
224
+ await exerciseBundledNestedPipeline(source);
225
+ assert.throws(
226
+ () => assertBundleContract(source.replace('prepareToolCall(nestedStep, preflight)', 'prepareToolCallBypassed(nestedStep, preflight)')),
227
+ /preparation and authorization/u,
228
+ 'mutation probe must reject bypassing the authorization path',
229
+ );
230
+ assert.throws(
231
+ () => assertBundleContract(source.replace('CodebaseSearch\\n - ProgrammaticTool\\n', 'CodebaseSearch\\n')),
232
+ /default agent profile/u,
233
+ 'mutation probe must reject an unreachable builtin tool',
234
+ );
235
+
236
+ const { createProgrammaticToolRuntime } = await import(pathToFileURL(runtimePath).href);
237
+ const calls = [];
238
+ const events = [];
239
+ const runtime = createProgrammaticToolRuntime({
240
+ allowedTools: [{ name: 'Echo', alias: 'echo' }],
241
+ invokeTool: async (call) => {
242
+ calls.push(call);
243
+ return { output: JSON.stringify(call.args) };
244
+ },
245
+ onEvent: (event) => events.push(event),
246
+ });
247
+
248
+ const outcome = await runtime.run({
249
+ code: 'state.completed = true; return tools.echo({ value: 7 });',
250
+ state: {},
251
+ });
252
+ assert.deepEqual(outcome.result, { output: '{"value":7}' });
253
+ assert.deepEqual(outcome.state, { completed: true });
254
+ assert.equal(calls.length, 1);
255
+ assert.deepEqual(events.map((event) => event.type), [
256
+ 'interpreter.started',
257
+ 'interpreter.tool_call',
258
+ 'interpreter.tool_result',
259
+ 'interpreter.completed',
260
+ ]);
261
+
262
+ const isolated = await createProgrammaticToolRuntime({
263
+ allowedTools: [],
264
+ invokeTool: async () => assert.fail('no tool call expected'),
265
+ }).run({
266
+ code: 'return [typeof process, typeof require, typeof fetch, typeof Date, typeof eval];',
267
+ state: {},
268
+ });
269
+ assert.deepEqual(isolated.result, ['undefined', 'undefined', 'undefined', 'undefined', 'undefined']);
270
+
271
+ await assert.rejects(
272
+ createProgrammaticToolRuntime({
273
+ allowedTools: [],
274
+ invokeTool: async () => assert.fail('no tool call expected'),
275
+ limits: { timeoutMs: 30 },
276
+ }).run({ code: 'while (true) {}', state: {} }),
277
+ /execution deadline exceeded/u,
278
+ );
279
+
280
+ for (let index = 0; index < 10; index += 1) {
281
+ const repeated = await runtime.run({
282
+ code: `return tools.echo({ value: ${index} });`,
283
+ state: {},
284
+ });
285
+ assert.equal(repeated.callCount, 1);
286
+ }
287
+
288
+ process.stdout.write('programmatic tool regression: ok\n');
289
+ }
290
+
291
+ main().catch((error) => {
292
+ console.error(error.stack || error);
293
+ process.exitCode = 1;
294
+ });
@@ -4,6 +4,7 @@
4
4
  const assert = require('node:assert/strict');
5
5
  const fs = require('node:fs');
6
6
  const path = require('node:path');
7
+ const { isWireOnlyProgrammaticEvent } = require('../bin/programmatic-context-isolation.cjs');
7
8
 
8
9
  const bundlePath = process.env.BLUN_BUNDLE_UNDER_TEST
9
10
  ? path.resolve(process.env.BLUN_BUNDLE_UNDER_TEST)
@@ -49,6 +50,7 @@ const appendLoopEvent = compileMethod(
49
50
  'appendMessage',
50
51
  {
51
52
  projectLoopEventForRecord: (event) => event,
53
+ isWireOnlyProgrammaticEvent,
52
54
  resolveCompletedStepUuid,
53
55
  createToolMessage: (toolCallId, content) => ({ toolCallId, content, toolCalls: [] }),
54
56
  toolResultOutputForModel: (result) => result.output,
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ const assert = require('node:assert/strict');
5
+ const fs = require('node:fs');
6
+ const path = require('node:path');
7
+
8
+ const packageRoot = process.env.BLUN_PACKAGE_UNDER_TEST
9
+ ? path.resolve(process.env.BLUN_PACKAGE_UNDER_TEST)
10
+ : path.resolve(__dirname, '..');
11
+ const bundle = fs.readFileSync(path.join(packageRoot, 'blun.mjs'), 'utf8');
12
+
13
+ for (const needle of [
14
+ '.option("--swarm", "Start in swarm mode.", false)',
15
+ 'swarm: raw["swarm"] === true,',
16
+ 'thinking: startup.effort,',
17
+ 'if (startup.effort !== void 0) await session.setThinking(startup.effort);',
18
+ 'if (startup.swarm && !(await session.getStatus()).swarmMode) await session.setSwarmMode(true, "effort");',
19
+ 'if (startup.swarm) this.setAppState({ swarmMode: true, swarmModeEntry: "effort" });',
20
+ ]) {
21
+ assert.ok(bundle.includes(needle), `startup swarm command wiring missing: ${needle}`);
22
+ }
23
+
24
+ process.stdout.write('startup-swarm-command-regression PASS\n');