blun-king-cli 9.1.519 → 9.1.520

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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 9.1.520 - 2026-08-31
4
+
5
+ - Gives AgentSpine's `SessionStart` hook a 60-second cold-project budget, so startup and `/reload` can persist the automatic briefing even when the measured source scan exceeds the former 15-second limit.
6
+ - Keeps prompt, tool, compact, stop, and subagent hook budgets unchanged; only the full SessionStart briefing receives the larger allowance.
7
+ - Extends the SessionStart regression with the packaged AgentSpine manifests and a real hook-process output probe instead of relying only on a simulated result.
8
+
3
9
  ## 9.1.519 - 2026-08-31
4
10
 
5
11
  - Persists successful `SessionStart` hook output before startup or reload returns, so AgentSpine readiness reaches the resumed model context automatically instead of waiting for the first user prompt.
package/LIESMICH.txt CHANGED
@@ -9,7 +9,7 @@ Installation
9
9
  ------------
10
10
  Die geprüfte Version exakt global installieren:
11
11
 
12
- npm install -g blun-king-cli@9.1.519
12
+ npm install -g blun-king-cli@9.1.520
13
13
 
14
14
  AgentSpine 0.10.1
15
15
  -----------------
package/README.md CHANGED
@@ -9,7 +9,7 @@ Voraussetzung ist Node.js 24.15 oder neuer. Die geprüfte Version wird exakt
9
9
  installiert:
10
10
 
11
11
  ```powershell
12
- npm install -g blun-king-cli@9.1.519
12
+ npm install -g blun-king-cli@9.1.520
13
13
  ```
14
14
 
15
15
  ## AgentSpine 0.10.1
@@ -15,7 +15,7 @@
15
15
  }
16
16
  },
17
17
  "hooks": [
18
- { "event": "SessionStart", "command": "node \"./src/hook.js\"", "timeout": 15 },
18
+ { "event": "SessionStart", "command": "node \"./src/hook.js\"", "timeout": 60 },
19
19
  { "event": "UserPromptSubmit", "command": "node \"./src/hook.js\"", "timeout": 15 },
20
20
  { "event": "PreToolUse", "matcher": "Edit|Write|apply_patch|Bash|exec_command", "command": "node \"./src/hook.js\"", "timeout": 15 },
21
21
  { "event": "PostToolUse", "command": "node \"./src/hook.js\"", "timeout": 15 },
@@ -4,7 +4,7 @@
4
4
  "SessionStart": [
5
5
  {
6
6
  "matcher": "startup|resume|clear|compact",
7
- "hooks": [{ "type": "command", "command": "node \"${PLUGIN_ROOT}/src/hook.js\"", "timeout": 15 }]
7
+ "hooks": [{ "type": "command", "command": "node \"${PLUGIN_ROOT}/src/hook.js\"", "timeout": 60 }]
8
8
  }
9
9
  ],
10
10
  "UserPromptSubmit": [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "blun-king-cli",
3
- "version": "9.1.519",
3
+ "version": "9.1.520",
4
4
  "description": "BLUN CLI - your own AI agent with a Telegram channel. Get it done. With BLUN.",
5
5
  "license": "MIT",
6
6
  "bin": {
@@ -2,7 +2,9 @@
2
2
  'use strict';
3
3
 
4
4
  const fs = require('node:fs');
5
+ const os = require('node:os');
5
6
  const path = require('node:path');
7
+ const { spawnSync } = require('node:child_process');
6
8
 
7
9
  const bundlePath = process.env.BLUN_BUNDLE_UNDER_TEST
8
10
  ? path.resolve(process.env.BLUN_BUNDLE_UNDER_TEST)
@@ -59,6 +61,67 @@ assert(
59
61
  'SESSION_START_HOOK_CONTEXT_REGRESSION: SessionStart reminder is not flushed before reload returns',
60
62
  );
61
63
 
64
+ const packageRoot = path.resolve(__dirname, '..');
65
+ const agentSpineRoot = path.join(packageRoot, 'agent-spine-plugin');
66
+ const agentSpineManifest = JSON.parse(
67
+ fs.readFileSync(path.join(agentSpineRoot, 'blun.plugin.json'), 'utf8'),
68
+ );
69
+ const agentSpineCodexHooks = JSON.parse(
70
+ fs.readFileSync(path.join(agentSpineRoot, 'hooks', 'codex.json'), 'utf8'),
71
+ );
72
+ const blunSessionStart = agentSpineManifest.hooks.find(
73
+ (hook) => hook.event === 'SessionStart',
74
+ );
75
+ const codexSessionStart = agentSpineCodexHooks.hooks.SessionStart?.[0]?.hooks?.[0];
76
+
77
+ assert(
78
+ blunSessionStart?.timeout >= 60,
79
+ 'SESSION_START_HOOK_CONTEXT_REGRESSION: BLUN AgentSpine SessionStart timeout must cover a cold project scan',
80
+ );
81
+ assert(
82
+ codexSessionStart?.timeout >= 60,
83
+ 'SESSION_START_HOOK_CONTEXT_REGRESSION: Codex AgentSpine SessionStart timeout must match the BLUN runtime budget',
84
+ );
85
+
86
+ const probeRoot = fs.mkdtempSync(path.join(os.tmpdir(), 'blun-session-start-hook-'));
87
+ try {
88
+ fs.mkdirSync(path.join(probeRoot, '.git'));
89
+ fs.writeFileSync(
90
+ path.join(probeRoot, 'AGENTS.md'),
91
+ '# SessionStart probe\n\nLoad this project instruction automatically.\n',
92
+ );
93
+ const stateRoot = path.join(probeRoot, '.agentspine-state');
94
+ const hookRun = spawnSync(process.execPath, [path.join(agentSpineRoot, 'src', 'hook.js')], {
95
+ cwd: agentSpineRoot,
96
+ input: JSON.stringify({
97
+ hook_event_name: 'SessionStart',
98
+ session_id: 'session-start-regression',
99
+ cwd: probeRoot,
100
+ source: 'resume',
101
+ }),
102
+ encoding: 'utf8',
103
+ timeout: 30_000,
104
+ env: {
105
+ ...process.env,
106
+ BLUN_HOME: probeRoot,
107
+ BLUN_PLUGIN_ROOT: agentSpineRoot,
108
+ AGENTSPINE_STATE_DIR: stateRoot,
109
+ },
110
+ });
111
+ assert(
112
+ hookRun.error === undefined && hookRun.status === 0,
113
+ `SESSION_START_HOOK_CONTEXT_REGRESSION: real AgentSpine hook failed: ${hookRun.error?.message || hookRun.stderr}`,
114
+ );
115
+ const hookOutput = JSON.parse(hookRun.stdout.trim());
116
+ assert(
117
+ hookOutput.hookSpecificOutput?.hookEventName === 'SessionStart'
118
+ && hookOutput.hookSpecificOutput?.message?.includes('AgentSpine'),
119
+ `SESSION_START_HOOK_CONTEXT_REGRESSION: real AgentSpine process output is not injectable: ${hookRun.stdout.trim()}`,
120
+ );
121
+ } finally {
122
+ fs.rmSync(probeRoot, { recursive: true, force: true });
123
+ }
124
+
62
125
  const triggerFunction = trigger[0].replace(
63
126
  /^async triggerSessionStart/,
64
127
  'async function triggerSessionStart',
@@ -1,317 +0,0 @@
1
- 'use strict';
2
-
3
- const TOOL_RESULT_MAX_CHARS = 12_000;
4
- const TOOL_RESULT_PREVIEW_CHARS = 2_000;
5
- const TOOL_RESULT_RECOVERY_PAGE_LINES = 20;
6
- const TOOL_RESULT_OFFLOAD_MARKER = '[Tool result offloaded]';
7
- const TOOL_RESULT_BATCH_MAX_CHARS = TOOL_RESULT_MAX_CHARS;
8
- const TOOL_RESULT_BATCH_MIN_ITEM_CHARS = 3_000;
9
- const TOOL_RESULT_BATCH_REPLACEMENT_BUDGET_CHARS = 2_500;
10
- const TOOL_RESULT_HISTORICAL_KEEP_RECENT_MESSAGES = 4;
11
- const TOOL_RESULT_HISTORICAL_MAX_CHARS = TOOL_RESULT_BATCH_MAX_CHARS;
12
- const TOOL_RESULT_HISTORICAL_MIN_ITEM_CHARS = 600;
13
- const TOOL_RESULT_HISTORICAL_REPLACEMENT_BUDGET_CHARS = 600;
14
- const TOOL_RESULT_SUCCESS_KEEP_RECENT_MESSAGES = 12;
15
- const TOOL_RESULT_HISTORICAL_SUCCESS_MARKER = '[Old tool result content cleared]';
16
- const TOOL_RESULT_REPEAT_MARKER = '[Repeated tool result omitted]';
17
- const READ_CONTINUATION_LINE_OFFSET_RE = /^Continue reading with line_offset=(\d+)\. Do not assume you have reached the end of the file\.$/mu;
18
-
19
- function shouldOffloadToolResult(textLength) {
20
- return Number.isFinite(textLength) && textLength > TOOL_RESULT_MAX_CHARS;
21
- }
22
-
23
- function shouldKeepFreshToolResult(toolName) {
24
- return toolName === 'Read';
25
- }
26
-
27
- function createToolResultPreview(text) {
28
- if (text.length <= TOOL_RESULT_PREVIEW_CHARS) return text;
29
-
30
- const headChars = Math.ceil(TOOL_RESULT_PREVIEW_CHARS / 2);
31
- const tailChars = TOOL_RESULT_PREVIEW_CHARS - headChars;
32
- const omittedChars = text.length - headChars - tailChars;
33
- return `${text.slice(0, headChars)}\n\n[... ${String(omittedChars)} characters omitted ...]\n\n${text.slice(-tailChars)}`;
34
- }
35
-
36
- function readContinuationLineOffset(text) {
37
- if (typeof text !== 'string') return undefined;
38
- const value = Number(text.match(READ_CONTINUATION_LINE_OFFSET_RE)?.[1]);
39
- return Number.isSafeInteger(value) && value >= 1 ? value : undefined;
40
- }
41
-
42
- function isPersistedToolResultReference(content) {
43
- if (!Array.isArray(content)) return false;
44
-
45
- return content.some((part) => {
46
- if (part?.type !== 'text' || typeof part.text !== 'string') return false;
47
- if (!part.text.includes('\noutput_path: ')) return false;
48
- return part.text.startsWith(`${TOOL_RESULT_OFFLOAD_MARKER}\n`)
49
- || /^Tool output exceeded \d+ characters; showing a preview only\.\n/u.test(part.text);
50
- });
51
- }
52
-
53
- function freshToolResultIds(messages) {
54
- if (!Array.isArray(messages) || messages.length === 0) return new Set();
55
-
56
- let assistantIndex = -1;
57
- for (let index = messages.length - 1; index >= 0; index -= 1) {
58
- if (messages[index]?.role !== 'assistant') continue;
59
- assistantIndex = index;
60
- break;
61
- }
62
- if (assistantIndex < 0 || !Array.isArray(messages[assistantIndex].toolCalls)) return new Set();
63
-
64
- const requestedIds = new Set(messages[assistantIndex].toolCalls
65
- .map((call) => call?.id ?? call?.toolCallId)
66
- .filter((id) => typeof id === 'string' && id.length > 0));
67
- if (requestedIds.size === 0) return new Set();
68
-
69
- const resultIds = new Set();
70
- for (let index = assistantIndex + 1; index < messages.length; index += 1) {
71
- const message = messages[index];
72
- if (message?.role === 'tool' && requestedIds.has(message.toolCallId)) {
73
- resultIds.add(message.toolCallId);
74
- }
75
- }
76
- return resultIds;
77
- }
78
-
79
- function compactPersistedToolResultReference(content) {
80
- if (!isPersistedToolResultReference(content)) return content;
81
-
82
- let changed = false;
83
- const compacted = content.map((part) => {
84
- if (part?.type !== 'text' || typeof part.text !== 'string') return part;
85
- const previewIndex = part.text.indexOf('\n[preview: head and tail]\n');
86
- const referenceText = previewIndex < 0
87
- ? part.text
88
- : part.text.slice(0, previewIndex).trimEnd();
89
- if (!referenceText.startsWith(`${TOOL_RESULT_OFFLOAD_MARKER}\n`)) {
90
- if (referenceText === part.text) return part;
91
- changed = true;
92
- return { ...part, text: referenceText };
93
- }
94
-
95
- const lines = referenceText.split(/\r?\n/u);
96
- const outputPath = lines.find((line) => line.startsWith('output_path: '));
97
- if (outputPath === undefined) return part;
98
- const recoveryLines = [TOOL_RESULT_OFFLOAD_MARKER];
99
- for (const prefix of ['tool_name: ', 'output_size_chars: ', 'next_line_offset: ']) {
100
- const line = lines.find((candidate) => candidate.startsWith(prefix));
101
- if (line !== undefined) recoveryLines.push(line);
102
- }
103
- if (recoveryLines.some((line) => line.startsWith('next_line_offset: '))) {
104
- const nextStep = lines.find((line) => line.startsWith('next_step: '));
105
- if (nextStep !== undefined) recoveryLines.push(nextStep);
106
- }
107
- recoveryLines.push(outputPath);
108
- const text = recoveryLines.join('\n');
109
- if (text === part.text) return part;
110
- changed = true;
111
- return {
112
- ...part,
113
- text,
114
- };
115
- });
116
-
117
- return changed ? compacted : content;
118
- }
119
-
120
- function compactHistoricalSuccessfulToolResults(messages) {
121
- if (!Array.isArray(messages) || messages.length === 0) return messages;
122
-
123
- const recentStart = Math.max(0, messages.length - TOOL_RESULT_SUCCESS_KEEP_RECENT_MESSAGES);
124
- const freshIds = freshToolResultIds(messages);
125
- let changed = false;
126
- const projected = messages.map((message, index) => {
127
- if (
128
- index >= recentStart
129
- || message?.role !== 'tool'
130
- || freshIds.has(message.toolCallId)
131
- || message.isError === true
132
- || !Array.isArray(message.content)
133
- || isPersistedToolResultReference(message.content)
134
- || !message.content.every((part) => part?.type === 'text' && typeof part.text === 'string')
135
- ) return message;
136
-
137
- const textChars = message.content.reduce((total, part) => total + part.text.length, 0);
138
- if (textChars <= TOOL_RESULT_HISTORICAL_SUCCESS_MARKER.length) return message;
139
- changed = true;
140
- return {
141
- ...message,
142
- content: [{ type: 'text', text: TOOL_RESULT_HISTORICAL_SUCCESS_MARKER }],
143
- };
144
- });
145
-
146
- return changed ? projected : messages;
147
- }
148
-
149
- function toolCallSignaturesById(messages) {
150
- const signatures = new Map();
151
-
152
- for (const message of messages) {
153
- if (!Array.isArray(message?.toolCalls)) continue;
154
- for (const call of message.toolCalls) {
155
- const id = call?.id ?? call?.toolCallId;
156
- if (typeof id !== 'string' || typeof call?.name !== 'string') continue;
157
- const args = typeof call.arguments === 'string'
158
- ? call.arguments
159
- : JSON.stringify(call.arguments ?? null);
160
- signatures.set(id, `${call.name}\n${args}`);
161
- }
162
- }
163
-
164
- return signatures;
165
- }
166
-
167
- function repeatedToolResultReference(newestToolCallId) {
168
- return [
169
- TOOL_RESULT_REPEAT_MARKER,
170
- `same_as_tool_call_id: ${newestToolCallId}`,
171
- 'reason: identical successful result for the same tool call arguments',
172
- ].join('\n');
173
- }
174
-
175
- function dedupeRepeatedSuccessfulToolResults(sourceMessages, projectedMessages = sourceMessages) {
176
- if (
177
- !Array.isArray(sourceMessages)
178
- || !Array.isArray(projectedMessages)
179
- || sourceMessages.length === 0
180
- || sourceMessages.length !== projectedMessages.length
181
- ) return projectedMessages;
182
-
183
- const callSignatures = toolCallSignaturesById(sourceMessages);
184
- const seenResultsByCall = new Map();
185
- let changed = false;
186
- const projected = projectedMessages.slice();
187
-
188
- for (let index = sourceMessages.length - 1; index >= 0; index -= 1) {
189
- const message = sourceMessages[index];
190
- const toolCallId = message?.toolCallId;
191
- if (
192
- message?.role !== 'tool'
193
- || message.isError === true
194
- || typeof toolCallId !== 'string'
195
- || !Array.isArray(message.content)
196
- || message.content.length === 0
197
- || isPersistedToolResultReference(message.content)
198
- || !message.content.every((part) => part?.type === 'text' && typeof part.text === 'string')
199
- ) continue;
200
-
201
- const callSignature = callSignatures.get(toolCallId);
202
- if (callSignature === undefined) continue;
203
- const resultShape = message.content.length;
204
- const resultSignature = resultShape === 1
205
- ? message.content[0].text
206
- : JSON.stringify(message.content.map((part) => part.text));
207
- let seenResults = seenResultsByCall.get(callSignature);
208
- if (seenResults === undefined) {
209
- seenResults = new Map();
210
- seenResultsByCall.set(callSignature, seenResults);
211
- }
212
- let seenResultsForShape = seenResults.get(resultShape);
213
- if (seenResultsForShape === undefined) {
214
- seenResultsForShape = new Map();
215
- seenResults.set(resultShape, seenResultsForShape);
216
- }
217
- const newest = seenResultsForShape.get(resultSignature);
218
- if (newest === undefined) {
219
- seenResultsForShape.set(resultSignature, { toolCallId, index });
220
- continue;
221
- }
222
-
223
- const reference = repeatedToolResultReference(newest.toolCallId);
224
- const textChars = message.content.reduce((total, part) => total + part.text.length, 0);
225
- const projectedMessage = projected[index];
226
- if (
227
- reference.length >= textChars
228
- || projectedMessage?.role !== 'tool'
229
- || projectedMessage.toolCallId !== toolCallId
230
- ) continue;
231
- projected[index] = {
232
- ...projectedMessage,
233
- content: [{ type: 'text', text: reference }],
234
- };
235
- projected[newest.index] = {
236
- ...projected[newest.index],
237
- content: sourceMessages[newest.index].content,
238
- };
239
- changed = true;
240
- }
241
-
242
- return changed ? projected : projectedMessages;
243
- }
244
-
245
- function selectToolResultBatchOffloads(textLengths) {
246
- if (!Array.isArray(textLengths) || textLengths.length < 2) return [];
247
-
248
- const normalized = textLengths.map((length) => (
249
- Number.isFinite(length) && length > 0 ? Math.floor(length) : 0
250
- ));
251
- const totalChars = normalized.reduce((total, length) => total + length, 0);
252
- if (totalChars <= TOOL_RESULT_BATCH_MAX_CHARS) return [];
253
-
254
- let projectedChars = totalChars;
255
- const selected = [];
256
- const candidates = normalized
257
- .map((length, index) => ({ index, length }))
258
- .filter(({ length }) => (
259
- length >= TOOL_RESULT_BATCH_MIN_ITEM_CHARS
260
- && length <= TOOL_RESULT_MAX_CHARS
261
- && length > TOOL_RESULT_BATCH_REPLACEMENT_BUDGET_CHARS
262
- ))
263
- .sort((left, right) => right.length - left.length || left.index - right.index);
264
-
265
- for (const candidate of candidates) {
266
- if (projectedChars <= TOOL_RESULT_BATCH_MAX_CHARS) break;
267
- projectedChars -= candidate.length - TOOL_RESULT_BATCH_REPLACEMENT_BUDGET_CHARS;
268
- selected.push(candidate.index);
269
- }
270
-
271
- return projectedChars <= TOOL_RESULT_BATCH_MAX_CHARS
272
- ? selected.sort((left, right) => left - right)
273
- : [];
274
- }
275
-
276
- function selectHistoricalToolResultOffloads(textLengths) {
277
- if (!Array.isArray(textLengths) || textLengths.length === 0) return [];
278
-
279
- const normalized = textLengths.map((length) => (
280
- Number.isFinite(length) && length > 0 ? Math.floor(length) : 0
281
- ));
282
- return normalized
283
- .map((length, index) => ({ index, length }))
284
- .filter(({ length }) => (
285
- length >= TOOL_RESULT_HISTORICAL_MIN_ITEM_CHARS
286
- && length > TOOL_RESULT_HISTORICAL_REPLACEMENT_BUDGET_CHARS
287
- ))
288
- .map(({ index }) => index);
289
- }
290
-
291
- module.exports = {
292
- TOOL_RESULT_BATCH_MAX_CHARS,
293
- TOOL_RESULT_BATCH_MIN_ITEM_CHARS,
294
- TOOL_RESULT_BATCH_REPLACEMENT_BUDGET_CHARS,
295
- TOOL_RESULT_HISTORICAL_KEEP_RECENT_MESSAGES,
296
- TOOL_RESULT_HISTORICAL_MAX_CHARS,
297
- TOOL_RESULT_HISTORICAL_MIN_ITEM_CHARS,
298
- TOOL_RESULT_HISTORICAL_REPLACEMENT_BUDGET_CHARS,
299
- TOOL_RESULT_HISTORICAL_SUCCESS_MARKER,
300
- TOOL_RESULT_REPEAT_MARKER,
301
- TOOL_RESULT_MAX_CHARS,
302
- TOOL_RESULT_PREVIEW_CHARS,
303
- TOOL_RESULT_RECOVERY_PAGE_LINES,
304
- TOOL_RESULT_OFFLOAD_MARKER,
305
- TOOL_RESULT_SUCCESS_KEEP_RECENT_MESSAGES,
306
- compactHistoricalSuccessfulToolResults,
307
- compactPersistedToolResultReference,
308
- createToolResultPreview,
309
- dedupeRepeatedSuccessfulToolResults,
310
- freshToolResultIds,
311
- isPersistedToolResultReference,
312
- readContinuationLineOffset,
313
- selectHistoricalToolResultOffloads,
314
- selectToolResultBatchOffloads,
315
- shouldKeepFreshToolResult,
316
- shouldOffloadToolResult,
317
- };