blun-king-cli 9.1.79 → 9.1.81
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/LIESMICH.txt +21 -1
- package/README.md +22 -1
- package/bin/tool-result-offload-telemetry.cjs +12 -0
- package/blun.mjs +9 -2
- package/package.json +1 -1
- package/standard-skills/blun-session-inspector/SKILL.md +39 -0
- package/standard-skills/blun-session-inspector/scripts/inspect-session.cjs +364 -0
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.
|
|
12
|
+
npm install -g blun-king-cli@9.1.81
|
|
13
13
|
|
|
14
14
|
Start
|
|
15
15
|
-----
|
|
@@ -86,6 +86,26 @@ Exportieren und die sichtbare Historie behalten die ursprünglichen
|
|
|
86
86
|
Werkzeugergebnisse. Das Telemetrieereignis `micro_compaction_finished` nennt den
|
|
87
87
|
Auslöser, den Schnitt und die geschätzte Tokenzahl vor und nach der Entlastung.
|
|
88
88
|
|
|
89
|
+
## Große Werkzeugausgaben und isolierte Teilagenten
|
|
90
|
+
|
|
91
|
+
Werkzeugausgaben mit mehr als 50.000 Zeichen werden vollständig unter `<agent-home>/tool-results/` gespeichert. Im Modellkontext bleiben nur eine Vorschau der ersten 2.000 Zeichen, der genaue `output_path` und der Hinweis, die Datei bei Bedarf mit `Read` zu öffnen. Dadurch bleibt die vollständige Ausgabe wiederauffindbar, ohne in jedem weiteren Modellschritt erneut als großer Textblock mitzufahren.
|
|
92
|
+
|
|
93
|
+
Das Telemetrieereignis `tool_result_offloaded` enthält ausschließlich `tool_name`, `output_size_chars`, `output_size_bytes` und `preview_size_chars`. Es enthält weder den Inhalt noch den Speicherpfad. Beispiel: Eine Ausgabe mit 80.000 Zeichen erzeugt eine Vorschau mit 2.000 Zeichen; die Telemetrie zeigt die Größenersparnis, ohne Nutzdaten zu protokollieren.
|
|
94
|
+
|
|
95
|
+
Reguläre `Agent`-Teilaufgaben verwenden eine eigene `ContextMemory` und eine eigene `wire.jsonl` in einem getrennten Agentenverzeichnis. Der Hauptagent erhält nur die Ergebniszusammenfassung, sodass lange Teilaufgaben nicht den Hauptverlauf füllen. `TodoList` speichert Pläne weiterhin maschinenlesbar im Sitzungs-Wire; `blun handoff` übergibt sie zusammen mit prüfbaren Hashes zwischen CLI, Desktop und Web.
|
|
96
|
+
|
|
97
|
+
Rein lesende Sitzungsdiagnose
|
|
98
|
+
--------------------------------
|
|
99
|
+
|
|
100
|
+
Der mitgelieferte Standardskill `blun-session-inspector` untersucht den nur ergänzten Sitzungs-Wire und die zugehörigen Telemetriedateien, ohne eine Sitzung zu verändern. Er meldet Modellschritte, Werkzeugaufrufe, Zähler zum Tokenverbrauch, Voll- und Mikroverdichtungen, fehlgeschlagene Verdichtungen sowie ausgelagerte Werkzeugergebnisse. Prompts, Systemanweisungen, Werkzeugargumente, Werkzeugergebnisse, private Pfade und verborgenes Denken erscheinen nicht in der Standardausgabe.
|
|
101
|
+
|
|
102
|
+
Beispiele:
|
|
103
|
+
|
|
104
|
+
node "$SKILL_DIR/scripts/inspect-session.cjs" --list 20
|
|
105
|
+
node "$SKILL_DIR/scripts/inspect-session.cjs" SESSION_ID
|
|
106
|
+
|
|
107
|
+
Ein eindeutiger Präfix der Sitzungs-ID genügt. `--profile NAME` wählt ein anderes Profil. `--include-metadata` zeigt zusätzlich Arbeits- und Sitzungsverzeichnis und sollte nur verwendet werden, wenn diese Pfade wirklich gebraucht werden. Der Inspektor setzt eine Sitzung niemals fort, lädt sie nicht neu, verdichtet sie nicht und löscht sie nicht.
|
|
108
|
+
|
|
89
109
|
Zug-Wächter
|
|
90
110
|
-----------
|
|
91
111
|
Läuft ein Zug 20 Minuten ohne neues Werkzeugergebnis, meldet die Konsole den
|
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.
|
|
12
|
+
npm install -g blun-king-cli@9.1.81
|
|
13
13
|
```
|
|
14
14
|
|
|
15
15
|
## Reproduzierbares Staging und Packen
|
|
@@ -108,6 +108,27 @@ Exportieren und die sichtbare Historie behalten die ursprünglichen
|
|
|
108
108
|
Werkzeugergebnisse. Das Telemetrieereignis `micro_compaction_finished` nennt den
|
|
109
109
|
Auslöser, den Schnitt und die geschätzte Tokenzahl vor und nach der Entlastung.
|
|
110
110
|
|
|
111
|
+
## Große Werkzeugausgaben und isolierte Teilagenten
|
|
112
|
+
|
|
113
|
+
Werkzeugausgaben mit mehr als 50.000 Zeichen werden vollständig unter `<agent-home>/tool-results/` gespeichert. Im Modellkontext bleiben nur eine Vorschau der ersten 2.000 Zeichen, der genaue `output_path` und der Hinweis, die Datei bei Bedarf mit `Read` zu öffnen. Dadurch bleibt die vollständige Ausgabe wiederauffindbar, ohne in jedem weiteren Modellschritt erneut als großer Textblock mitzufahren.
|
|
114
|
+
|
|
115
|
+
Das Telemetrieereignis `tool_result_offloaded` enthält ausschließlich `tool_name`, `output_size_chars`, `output_size_bytes` und `preview_size_chars`. Es enthält weder den Inhalt noch den Speicherpfad. Beispiel: Eine Ausgabe mit 80.000 Zeichen erzeugt eine Vorschau mit 2.000 Zeichen; die Telemetrie zeigt die Größenersparnis, ohne Nutzdaten zu protokollieren.
|
|
116
|
+
|
|
117
|
+
Reguläre `Agent`-Teilaufgaben verwenden eine eigene `ContextMemory` und eine eigene `wire.jsonl` in einem getrennten Agentenverzeichnis. Der Hauptagent erhält nur die Ergebniszusammenfassung, sodass lange Teilaufgaben nicht den Hauptverlauf füllen. `TodoList` speichert Pläne weiterhin maschinenlesbar im Sitzungs-Wire; `blun handoff` übergibt sie zusammen mit prüfbaren Hashes zwischen CLI, Desktop und Web.
|
|
118
|
+
|
|
119
|
+
## Rein lesende Sitzungsdiagnose
|
|
120
|
+
|
|
121
|
+
Der mitgelieferte Standardskill `blun-session-inspector` untersucht den nur ergänzten Sitzungs-Wire und die zugehörigen Telemetriedateien, ohne eine Sitzung zu verändern. Er meldet Modellschritte, Werkzeugaufrufe, Zähler zum Tokenverbrauch, Voll- und Mikroverdichtungen, fehlgeschlagene Verdichtungen sowie ausgelagerte Werkzeugergebnisse. Prompts, Systemanweisungen, Werkzeugargumente, Werkzeugergebnisse, private Pfade und verborgenes Denken erscheinen nicht in der Standardausgabe.
|
|
122
|
+
|
|
123
|
+
Beispiele:
|
|
124
|
+
|
|
125
|
+
```text
|
|
126
|
+
node "$SKILL_DIR/scripts/inspect-session.cjs" --list 20
|
|
127
|
+
node "$SKILL_DIR/scripts/inspect-session.cjs" SESSION_ID
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
Ein eindeutiger Präfix der Sitzungs-ID genügt. `--profile NAME` wählt ein anderes Profil. `--include-metadata` zeigt zusätzlich Arbeits- und Sitzungsverzeichnis und sollte nur verwendet werden, wenn diese Pfade wirklich gebraucht werden. Der Inspektor setzt eine Sitzung niemals fort, lädt sie nicht neu, verdichtet sie nicht und löscht sie nicht.
|
|
131
|
+
|
|
111
132
|
## Zug-Wächter
|
|
112
133
|
|
|
113
134
|
Läuft ein Zug 20 Minuten ohne neues Werkzeugergebnis, meldet die Konsole den
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function buildToolResultOffloadTelemetry(options) {
|
|
4
|
+
return {
|
|
5
|
+
tool_name: options.toolName,
|
|
6
|
+
output_size_chars: options.text.length,
|
|
7
|
+
output_size_bytes: Buffer.byteLength(options.text, 'utf8'),
|
|
8
|
+
preview_size_chars: Math.min(options.text.length, options.previewChars),
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
module.exports = { buildToolResultOffloadTelemetry };
|
package/blun.mjs
CHANGED
|
@@ -259897,6 +259897,11 @@ async function budgetToolResultForModel(options) {
|
|
|
259897
259897
|
toolCallId: options.toolCallId
|
|
259898
259898
|
}, text);
|
|
259899
259899
|
if (outputPath === void 0) return options.result;
|
|
259900
|
+
options.telemetry?.track("tool_result_offloaded", buildToolResultOffloadTelemetry({
|
|
259901
|
+
toolName: options.toolName,
|
|
259902
|
+
text,
|
|
259903
|
+
previewChars: TOOL_RESULT_PREVIEW_CHARS
|
|
259904
|
+
}));
|
|
259900
259905
|
const output = renderPersistedToolResult(options.toolName, options.toolCallId, text, outputPath);
|
|
259901
259906
|
return options.result.isError === true ? {
|
|
259902
259907
|
...options.result,
|
|
@@ -259945,9 +259950,10 @@ function renderPersistedToolResult(toolName, toolCallId, text, outputPath) {
|
|
|
259945
259950
|
function safeToolResultFileStem(toolName, toolCallId) {
|
|
259946
259951
|
return `${toolName}-${toolCallId}`.replace(/[^a-zA-Z0-9._-]+/g, "_").replace(/^_+|_+$/g, "").slice(0, 80) || "tool-result";
|
|
259947
259952
|
}
|
|
259948
|
-
var TOOL_RESULT_MAX_CHARS, TOOL_RESULT_PREVIEW_CHARS;
|
|
259953
|
+
var TOOL_RESULT_MAX_CHARS, TOOL_RESULT_PREVIEW_CHARS, buildToolResultOffloadTelemetry;
|
|
259949
259954
|
var init_tool_result_budget = __esmMin((() => {
|
|
259950
259955
|
init_dist$6();
|
|
259956
|
+
({ buildToolResultOffloadTelemetry } = createRequire(import.meta.url)("./bin/tool-result-offload-telemetry.cjs"));
|
|
259951
259957
|
TOOL_RESULT_MAX_CHARS = 5e4;
|
|
259952
259958
|
TOOL_RESULT_PREVIEW_CHARS = 2e3;
|
|
259953
259959
|
}));
|
|
@@ -261038,7 +261044,8 @@ var init_turn = __esmMin((() => {
|
|
|
261038
261044
|
homedir: this.agent.homedir,
|
|
261039
261045
|
toolName: ctx.toolCall.name,
|
|
261040
261046
|
toolCallId: ctx.toolCall.id,
|
|
261041
|
-
result: finalResult
|
|
261047
|
+
result: finalResult,
|
|
261048
|
+
telemetry: this.agent.telemetry
|
|
261042
261049
|
});
|
|
261043
261050
|
}
|
|
261044
261051
|
}
|
package/package.json
CHANGED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: blun-session-inspector
|
|
3
|
+
description: Inspect local BLUN Code session health read-only. Use when asked about compactions, token usage, tool-call volume, offloaded tool results, provider steps, or a session that appears slow or stuck.
|
|
4
|
+
license: MIT
|
|
5
|
+
compatibility: designed for BLUN Code
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# BLUN Session Inspector
|
|
9
|
+
|
|
10
|
+
Use the bundled script instead of manually reading `wire.jsonl` or telemetry files. It reports counts and timing metadata without returning prompts, system instructions, tool arguments, tool results, private paths, or hidden reasoning.
|
|
11
|
+
|
|
12
|
+
Resolve `SKILL_DIR` to the directory containing this file. Do not assume a user-specific installation path.
|
|
13
|
+
|
|
14
|
+
List recent sessions:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
node "$SKILL_DIR/scripts/inspect-session.cjs" --list 20
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Inspect one session by full ID or unique prefix:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
node "$SKILL_DIR/scripts/inspect-session.cjs" SESSION_ID
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Use another profile or app home only when needed:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
node "$SKILL_DIR/scripts/inspect-session.cjs" SESSION_ID --profile PROFILE
|
|
30
|
+
node "$SKILL_DIR/scripts/inspect-session.cjs" SESSION_ID --blun-home PATH
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Add `--include-metadata` only when the work directory and session directory are relevant. Summarize the JSON instead of pasting it verbatim. Distinguish stored counts from your interpretation, mention warnings, and do not claim that telemetry covers periods before an event was introduced.
|
|
34
|
+
|
|
35
|
+
Keep inspection read-only. Never edit, delete, compact, resume, reload, or restart a session as part of diagnosis.
|
|
36
|
+
|
|
37
|
+
This skill adopts the read-only, smallest-useful-view approach from the MIT-licensed Deep Agents Thread Inspector while using BLUN Code's append-only wire and telemetry formats.
|
|
38
|
+
|
|
39
|
+
Source: https://github.com/langchain-ai/deepagents/tree/main/libs/code/deepagents_code/built_in_skills/deepagents-thread-inspector
|
|
@@ -0,0 +1,364 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const fs = require('node:fs');
|
|
5
|
+
const os = require('node:os');
|
|
6
|
+
const path = require('node:path');
|
|
7
|
+
const readline = require('node:readline');
|
|
8
|
+
|
|
9
|
+
function fail(code, details) {
|
|
10
|
+
process.stderr.write(`${JSON.stringify({ error: code, ...details })}\n`);
|
|
11
|
+
process.exitCode = 1;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function parseArgs(argv) {
|
|
15
|
+
const options = {
|
|
16
|
+
blunHome: process.env.BLUN_HOME || path.join(os.homedir(), '.blun'),
|
|
17
|
+
profile: 'default',
|
|
18
|
+
list: null,
|
|
19
|
+
includeMetadata: false,
|
|
20
|
+
selector: null,
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
for (let index = 0; index < argv.length; index += 1) {
|
|
24
|
+
const argument = argv[index];
|
|
25
|
+
if (argument === '--blun-home') {
|
|
26
|
+
options.blunHome = argv[index += 1];
|
|
27
|
+
} else if (argument === '--profile') {
|
|
28
|
+
options.profile = argv[index += 1];
|
|
29
|
+
} else if (argument === '--list') {
|
|
30
|
+
const raw = argv[index + 1];
|
|
31
|
+
if (raw && !raw.startsWith('--')) index += 1;
|
|
32
|
+
options.list = raw && !raw.startsWith('--') ? Number(raw) : 20;
|
|
33
|
+
} else if (argument === '--include-metadata') {
|
|
34
|
+
options.includeMetadata = true;
|
|
35
|
+
} else if (argument.startsWith('--')) {
|
|
36
|
+
throw new Error(`unknown_option:${argument}`);
|
|
37
|
+
} else if (options.selector === null) {
|
|
38
|
+
options.selector = argument;
|
|
39
|
+
} else {
|
|
40
|
+
throw new Error('too_many_session_selectors');
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (!options.blunHome) throw new Error('missing_blun_home');
|
|
45
|
+
if (!/^[a-z0-9][a-z0-9_-]{0,31}$/u.test(options.profile)) throw new Error('invalid_profile');
|
|
46
|
+
if (options.list !== null && (!Number.isInteger(options.list) || options.list < 1 || options.list > 1000)) {
|
|
47
|
+
throw new Error('invalid_list_limit');
|
|
48
|
+
}
|
|
49
|
+
if (options.list === null && !options.selector) throw new Error('missing_session_selector');
|
|
50
|
+
return options;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async function readJsonLines(filePath, onRecord, onWarning) {
|
|
54
|
+
const input = fs.createReadStream(filePath, { encoding: 'utf8' });
|
|
55
|
+
const lines = readline.createInterface({ input, crlfDelay: Infinity });
|
|
56
|
+
let lineNumber = 0;
|
|
57
|
+
for await (const line of lines) {
|
|
58
|
+
lineNumber += 1;
|
|
59
|
+
if (!line.trim()) continue;
|
|
60
|
+
try {
|
|
61
|
+
const record = JSON.parse(line);
|
|
62
|
+
if (!record || typeof record !== 'object' || Array.isArray(record)) {
|
|
63
|
+
onWarning({ code: 'unsupported_record', line: lineNumber });
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
await onRecord(record, lineNumber);
|
|
67
|
+
} catch {
|
|
68
|
+
onWarning({ code: 'invalid_json', line: lineNumber });
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
async function loadSessionIndex(profileRoot) {
|
|
74
|
+
const indexPath = path.join(profileRoot, 'session_index.jsonl');
|
|
75
|
+
if (!fs.existsSync(indexPath)) throw new Error('session_index_not_found');
|
|
76
|
+
const sessions = new Map();
|
|
77
|
+
const warnings = [];
|
|
78
|
+
await readJsonLines(indexPath, (entry) => {
|
|
79
|
+
if (typeof entry.sessionId !== 'string' || typeof entry.sessionDir !== 'string') {
|
|
80
|
+
warnings.push({ scope: 'session_index', code: 'invalid_session_entry' });
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
sessions.set(entry.sessionId, entry);
|
|
84
|
+
}, (warning) => warnings.push({ scope: 'session_index', ...warning }));
|
|
85
|
+
return { sessions: [...sessions.values()], warnings };
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function sessionModifiedTime(sessionDir) {
|
|
89
|
+
try {
|
|
90
|
+
return fs.statSync(sessionDir).mtime.toISOString();
|
|
91
|
+
} catch {
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function isPathInside(parent, candidate) {
|
|
97
|
+
const relative = path.relative(path.resolve(parent), path.resolve(candidate));
|
|
98
|
+
return relative !== ''
|
|
99
|
+
&& relative !== '..'
|
|
100
|
+
&& !relative.startsWith(`..${path.sep}`)
|
|
101
|
+
&& !path.isAbsolute(relative);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function requireSafeSessionPath(profileRoot, sessionDir) {
|
|
105
|
+
if (!isPathInside(path.join(profileRoot, 'sessions'), sessionDir)) {
|
|
106
|
+
throw new Error('unsafe_session_path');
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function agentWireFiles(sessionDir) {
|
|
111
|
+
const agentsDir = path.join(sessionDir, 'agents');
|
|
112
|
+
if (!fs.existsSync(agentsDir)) return [];
|
|
113
|
+
return fs.readdirSync(agentsDir, { withFileTypes: true })
|
|
114
|
+
.filter((entry) => entry.isDirectory())
|
|
115
|
+
.map((entry) => ({
|
|
116
|
+
agent: entry.name,
|
|
117
|
+
wirePath: path.join(agentsDir, entry.name, 'wire.jsonl'),
|
|
118
|
+
}))
|
|
119
|
+
.filter((entry) => fs.existsSync(entry.wirePath))
|
|
120
|
+
.sort((left, right) => left.agent.localeCompare(right.agent));
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function emptyUsage() {
|
|
124
|
+
return {
|
|
125
|
+
records: 0,
|
|
126
|
+
input_other: 0,
|
|
127
|
+
input_cache_read: 0,
|
|
128
|
+
input_cache_creation: 0,
|
|
129
|
+
input_total: 0,
|
|
130
|
+
output: 0,
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function emptyCompactions() {
|
|
135
|
+
return { begun: 0, applied: 0, completed: 0, cancelled: 0, compacted_records: 0 };
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function numberValue(value) {
|
|
139
|
+
return Number.isFinite(Number(value)) ? Number(value) : 0;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function usageValue(usage, camelName, snakeName) {
|
|
143
|
+
return numberValue(usage?.[camelName] ?? usage?.[snakeName]);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
async function summarizeWire(agent, wirePath, warnings) {
|
|
147
|
+
const summary = {
|
|
148
|
+
agent,
|
|
149
|
+
records: 0,
|
|
150
|
+
first_time: null,
|
|
151
|
+
last_time: null,
|
|
152
|
+
turn_prompts: 0,
|
|
153
|
+
turn_steers: 0,
|
|
154
|
+
turn_cancellations: 0,
|
|
155
|
+
messages: 0,
|
|
156
|
+
loop_events: 0,
|
|
157
|
+
provider_steps_started: 0,
|
|
158
|
+
provider_steps_finished: 0,
|
|
159
|
+
tool_calls: 0,
|
|
160
|
+
tool_results: 0,
|
|
161
|
+
top_tools: [],
|
|
162
|
+
usage: emptyUsage(),
|
|
163
|
+
full_compactions: emptyCompactions(),
|
|
164
|
+
};
|
|
165
|
+
const toolCounts = new Map();
|
|
166
|
+
|
|
167
|
+
await readJsonLines(wirePath, (record) => {
|
|
168
|
+
summary.records += 1;
|
|
169
|
+
const time = numberValue(record.time ?? record.created_at);
|
|
170
|
+
if (time > 0) {
|
|
171
|
+
summary.first_time = summary.first_time === null ? time : Math.min(summary.first_time, time);
|
|
172
|
+
summary.last_time = summary.last_time === null ? time : Math.max(summary.last_time, time);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
if (record.type === 'turn.prompt') summary.turn_prompts += 1;
|
|
176
|
+
else if (record.type === 'turn.steer') summary.turn_steers += 1;
|
|
177
|
+
else if (record.type === 'turn.cancel') summary.turn_cancellations += 1;
|
|
178
|
+
else if (record.type === 'context.append_message') summary.messages += 1;
|
|
179
|
+
else if (record.type === 'context.append_loop_event') {
|
|
180
|
+
summary.loop_events += 1;
|
|
181
|
+
if (record.event?.type === 'step.begin') summary.provider_steps_started += 1;
|
|
182
|
+
else if (record.event?.type === 'step.end') summary.provider_steps_finished += 1;
|
|
183
|
+
else if (record.event?.type === 'tool.call') {
|
|
184
|
+
summary.tool_calls += 1;
|
|
185
|
+
const name = typeof record.event.name === 'string' && record.event.name ? record.event.name : '<unknown>';
|
|
186
|
+
toolCounts.set(name, (toolCounts.get(name) || 0) + 1);
|
|
187
|
+
} else if (record.event?.type === 'tool.result') summary.tool_results += 1;
|
|
188
|
+
} else if (record.type === 'usage.record') {
|
|
189
|
+
const usage = record.usage || {};
|
|
190
|
+
const inputOther = usageValue(usage, 'inputOther', 'input_other');
|
|
191
|
+
const inputCacheRead = usageValue(usage, 'inputCacheRead', 'input_cache_read');
|
|
192
|
+
const inputCacheCreation = usageValue(usage, 'inputCacheCreation', 'input_cache_creation');
|
|
193
|
+
summary.usage.records += 1;
|
|
194
|
+
summary.usage.input_other += inputOther;
|
|
195
|
+
summary.usage.input_cache_read += inputCacheRead;
|
|
196
|
+
summary.usage.input_cache_creation += inputCacheCreation;
|
|
197
|
+
summary.usage.input_total += inputOther + inputCacheRead + inputCacheCreation;
|
|
198
|
+
summary.usage.output += usageValue(usage, 'output', 'output_tokens');
|
|
199
|
+
} else if (record.type === 'full_compaction.begin') summary.full_compactions.begun += 1;
|
|
200
|
+
else if (record.type === 'context.apply_compaction') {
|
|
201
|
+
summary.full_compactions.applied += 1;
|
|
202
|
+
summary.full_compactions.compacted_records += numberValue(record.compactedCount ?? record.compacted_count);
|
|
203
|
+
} else if (record.type === 'full_compaction.complete') summary.full_compactions.completed += 1;
|
|
204
|
+
else if (record.type === 'full_compaction.cancel') summary.full_compactions.cancelled += 1;
|
|
205
|
+
}, (warning) => warnings.push({ scope: 'wire', agent, ...warning }));
|
|
206
|
+
|
|
207
|
+
summary.top_tools = [...toolCounts.entries()]
|
|
208
|
+
.map(([name, calls]) => ({ name, calls }))
|
|
209
|
+
.sort((left, right) => right.calls - left.calls || left.name.localeCompare(right.name));
|
|
210
|
+
return summary;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
function addUsage(target, source) {
|
|
214
|
+
for (const key of Object.keys(target)) target[key] += source[key];
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
function addCompactions(target, source) {
|
|
218
|
+
for (const key of Object.keys(target)) target[key] += source[key];
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
function combineAgents(agents) {
|
|
222
|
+
const totals = {
|
|
223
|
+
records: 0,
|
|
224
|
+
turn_prompts: 0,
|
|
225
|
+
turn_steers: 0,
|
|
226
|
+
turn_cancellations: 0,
|
|
227
|
+
messages: 0,
|
|
228
|
+
loop_events: 0,
|
|
229
|
+
provider_steps_started: 0,
|
|
230
|
+
provider_steps_finished: 0,
|
|
231
|
+
tool_calls: 0,
|
|
232
|
+
tool_results: 0,
|
|
233
|
+
top_tools: [],
|
|
234
|
+
usage: emptyUsage(),
|
|
235
|
+
full_compactions: emptyCompactions(),
|
|
236
|
+
};
|
|
237
|
+
const toolCounts = new Map();
|
|
238
|
+
const numericKeys = [
|
|
239
|
+
'records',
|
|
240
|
+
'turn_prompts',
|
|
241
|
+
'turn_steers',
|
|
242
|
+
'turn_cancellations',
|
|
243
|
+
'messages',
|
|
244
|
+
'loop_events',
|
|
245
|
+
'provider_steps_started',
|
|
246
|
+
'provider_steps_finished',
|
|
247
|
+
'tool_calls',
|
|
248
|
+
'tool_results',
|
|
249
|
+
];
|
|
250
|
+
|
|
251
|
+
for (const agent of agents) {
|
|
252
|
+
for (const key of numericKeys) totals[key] += agent[key];
|
|
253
|
+
addUsage(totals.usage, agent.usage);
|
|
254
|
+
addCompactions(totals.full_compactions, agent.full_compactions);
|
|
255
|
+
for (const tool of agent.top_tools) toolCounts.set(tool.name, (toolCounts.get(tool.name) || 0) + tool.calls);
|
|
256
|
+
}
|
|
257
|
+
totals.top_tools = [...toolCounts.entries()]
|
|
258
|
+
.map(([name, calls]) => ({ name, calls }))
|
|
259
|
+
.sort((left, right) => right.calls - left.calls || left.name.localeCompare(right.name));
|
|
260
|
+
return totals;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
async function summarizeTelemetry(telemetryDir, sessionId, warnings) {
|
|
264
|
+
const summary = {
|
|
265
|
+
micro_compactions: 0,
|
|
266
|
+
full_compaction_failures: 0,
|
|
267
|
+
offloaded_tool_results: 0,
|
|
268
|
+
offloaded_output_chars: 0,
|
|
269
|
+
truncated_tool_results: 0,
|
|
270
|
+
};
|
|
271
|
+
if (!fs.existsSync(telemetryDir)) return summary;
|
|
272
|
+
|
|
273
|
+
const files = fs.readdirSync(telemetryDir, { withFileTypes: true })
|
|
274
|
+
.filter((entry) => entry.isFile() && entry.name.endsWith('.jsonl'))
|
|
275
|
+
.map((entry) => ({ name: entry.name, filePath: path.join(telemetryDir, entry.name) }));
|
|
276
|
+
for (const file of files) {
|
|
277
|
+
await readJsonLines(file.filePath, (record) => {
|
|
278
|
+
if (record.session_id !== sessionId) return;
|
|
279
|
+
if (record.event === 'micro_compaction_finished') {
|
|
280
|
+
summary.micro_compactions += 1;
|
|
281
|
+
summary.truncated_tool_results += numberValue(record.properties?.truncated_tool_result_count);
|
|
282
|
+
} else if (record.event === 'compaction_failed') {
|
|
283
|
+
summary.full_compaction_failures += 1;
|
|
284
|
+
} else if (record.event === 'tool_result_offloaded') {
|
|
285
|
+
summary.offloaded_tool_results += 1;
|
|
286
|
+
summary.offloaded_output_chars += numberValue(record.properties?.output_size_chars);
|
|
287
|
+
}
|
|
288
|
+
}, (warning) => warnings.push({ scope: 'telemetry', file: file.name, ...warning }));
|
|
289
|
+
}
|
|
290
|
+
return summary;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
function listSessions(options, profileRoot, sessions, warnings) {
|
|
294
|
+
const listed = sessions
|
|
295
|
+
.filter((entry) => {
|
|
296
|
+
try {
|
|
297
|
+
requireSafeSessionPath(profileRoot, entry.sessionDir);
|
|
298
|
+
return true;
|
|
299
|
+
} catch {
|
|
300
|
+
warnings.push({ scope: 'session_index', code: 'unsafe_session_path', session_id: entry.sessionId });
|
|
301
|
+
return false;
|
|
302
|
+
}
|
|
303
|
+
})
|
|
304
|
+
.map((entry) => {
|
|
305
|
+
const item = {
|
|
306
|
+
session_id: entry.sessionId,
|
|
307
|
+
agents: agentWireFiles(entry.sessionDir).length,
|
|
308
|
+
last_modified: sessionModifiedTime(entry.sessionDir),
|
|
309
|
+
};
|
|
310
|
+
if (options.includeMetadata) {
|
|
311
|
+
item.session_dir = entry.sessionDir;
|
|
312
|
+
item.work_dir = entry.workDir || null;
|
|
313
|
+
}
|
|
314
|
+
return item;
|
|
315
|
+
})
|
|
316
|
+
.sort((left, right) => String(right.last_modified).localeCompare(String(left.last_modified)))
|
|
317
|
+
.slice(0, options.list);
|
|
318
|
+
return { mode: 'list', profile: options.profile, sessions: listed, warnings };
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
async function inspectSession(options, profileRoot, sessions, inheritedWarnings) {
|
|
322
|
+
const matches = sessions.filter((entry) => entry.sessionId === options.selector || entry.sessionId.startsWith(options.selector));
|
|
323
|
+
if (matches.length === 0) throw new Error('session_not_found');
|
|
324
|
+
if (matches.length > 1) throw new Error('ambiguous_session_prefix');
|
|
325
|
+
const entry = matches[0];
|
|
326
|
+
requireSafeSessionPath(profileRoot, entry.sessionDir);
|
|
327
|
+
const warnings = [...inheritedWarnings];
|
|
328
|
+
const wires = agentWireFiles(entry.sessionDir);
|
|
329
|
+
if (wires.length === 0) warnings.push({ scope: 'session', code: 'wire_not_found' });
|
|
330
|
+
const agents = [];
|
|
331
|
+
for (const wire of wires) agents.push(await summarizeWire(wire.agent, wire.wirePath, warnings));
|
|
332
|
+
|
|
333
|
+
const result = {
|
|
334
|
+
mode: 'summary',
|
|
335
|
+
profile: options.profile,
|
|
336
|
+
session_id: entry.sessionId,
|
|
337
|
+
agents,
|
|
338
|
+
totals: combineAgents(agents),
|
|
339
|
+
telemetry: await summarizeTelemetry(path.join(options.blunHome, 'telemetry'), entry.sessionId, warnings),
|
|
340
|
+
warnings,
|
|
341
|
+
};
|
|
342
|
+
if (options.includeMetadata) {
|
|
343
|
+
result.session_dir = entry.sessionDir;
|
|
344
|
+
result.work_dir = entry.workDir || null;
|
|
345
|
+
}
|
|
346
|
+
return result;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
async function main() {
|
|
350
|
+
let options;
|
|
351
|
+
try {
|
|
352
|
+
options = parseArgs(process.argv.slice(2));
|
|
353
|
+
const profileRoot = path.join(options.blunHome, 'profile', options.profile);
|
|
354
|
+
const { sessions, warnings } = await loadSessionIndex(profileRoot);
|
|
355
|
+
const result = options.list !== null
|
|
356
|
+
? listSessions(options, profileRoot, sessions, warnings)
|
|
357
|
+
: await inspectSession(options, profileRoot, sessions, warnings);
|
|
358
|
+
process.stdout.write(`${JSON.stringify(result, null, 2)}\n`);
|
|
359
|
+
} catch (error) {
|
|
360
|
+
fail(String(error?.message || error), options?.selector ? { selector: options.selector } : {});
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
void main();
|