@linghun/tui 0.1.2 → 0.1.4
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/dist/background-control-runtime.js +37 -37
- package/dist/cache-command-runtime.js +3 -3
- package/dist/capability-runtime.js +24 -24
- package/dist/{chunk-QD4SCW4A.js → chunk-2JFSRRK7.js} +21 -21
- package/dist/{chunk-PPUOHBAK.js → chunk-2JZBPXHF.js} +15 -15
- package/dist/{chunk-7BHMBWG2.js → chunk-33WA4BDG.js} +4 -4
- package/dist/{chunk-YKOXJQGX.js → chunk-3KRRVLS4.js} +111 -3
- package/dist/{chunk-42ZZUF7P.js → chunk-6C32YAB5.js} +17 -5
- package/dist/{chunk-OSFBVVEP.js → chunk-7ODJHN53.js} +2 -2
- package/dist/{chunk-6DBBXNEG.js → chunk-7VGFNZPN.js} +38 -2
- package/dist/{chunk-3PG7I3LA.js → chunk-AFNWUI6R.js} +1 -1
- package/dist/{chunk-YMEMN5FG.js → chunk-BRNV6757.js} +1 -1
- package/dist/{chunk-CJRJR7TP.js → chunk-CL3U56EI.js} +2 -2
- package/dist/{chunk-HPIHFENG.js → chunk-HMGGPN4J.js} +1 -1
- package/dist/{chunk-HZ5XNKWS.js → chunk-HMGYFENJ.js} +1 -1
- package/dist/{chunk-HPQ2IHOW.js → chunk-IU7NZO6B.js} +3 -3
- package/dist/{chunk-3LT6OWQ2.js → chunk-IWBV4CEI.js} +1 -1
- package/dist/{chunk-YDTJ7UBG.js → chunk-JMUAQUQQ.js} +1 -1
- package/dist/{chunk-NK4NMYF5.js → chunk-JY2DO7OF.js} +127 -12
- package/dist/{chunk-X7E34LKV.js → chunk-KI7NO6IF.js} +219 -8
- package/dist/{chunk-UIKN3CDF.js → chunk-NMOVU75L.js} +1 -1
- package/dist/{chunk-ZJDPYOTK.js → chunk-NR3MFRPO.js} +2 -2
- package/dist/{chunk-WXTHKLNH.js → chunk-OI5TZ37D.js} +27 -0
- package/dist/{chunk-DIDRFIIW.js → chunk-OMWSM2DA.js} +1 -1
- package/dist/{chunk-HGCTHBUY.js → chunk-PHPEPZAA.js} +1 -1
- package/dist/{chunk-EKYXI6C7.js → chunk-R7BB45CP.js} +1 -1
- package/dist/{chunk-7R4YXN7Z.js → chunk-RKFC3V6A.js} +178 -67
- package/dist/{chunk-PBIPV4LD.js → chunk-RMXEIZYR.js} +1 -1
- package/dist/{chunk-4TO2LDMP.js → chunk-SEVD3KES.js} +2 -2
- package/dist/{chunk-AGI6GFFL.js → chunk-T2V2USR3.js} +2 -2
- package/dist/{chunk-3MRYQO7X.js → chunk-T7LHFTVM.js} +3 -3
- package/dist/{chunk-7RZE45OT.js → chunk-UN3MMVE4.js} +1 -1
- package/dist/{chunk-LBC75QAB.js → chunk-UUWG4VXV.js} +10 -4
- package/dist/{chunk-FGGY5KNM.js → chunk-UYEVRXUA.js} +3 -3
- package/dist/{chunk-O2U4XQVM.js → chunk-UYU4QN3P.js} +1 -1
- package/dist/{chunk-J6CYFWSW.js → chunk-VDQTNA4W.js} +20 -1
- package/dist/{chunk-RDGM4RUE.js → chunk-VZFP7NWI.js} +1 -1
- package/dist/{chunk-7ZMDQZ22.js → chunk-W6O7KDNM.js} +1 -1
- package/dist/{chunk-2YL5VKJ5.js → chunk-WO56RSMP.js} +1 -1
- package/dist/{chunk-YLOJWSHB.js → chunk-WRVHCSM2.js} +25 -9
- package/dist/{chunk-5IFNLTOF.js → chunk-WXQSF2AS.js} +3 -3
- package/dist/{chunk-JY3LI63F.js → chunk-YGXPS5F2.js} +1 -1
- package/dist/{chunk-ZF36LULR.js → chunk-ZNAYWBBI.js} +2 -2
- package/dist/command-panel-runtime.js +23 -23
- package/dist/compact-cache-command-runtime.js +37 -37
- package/dist/compact-preflight-runtime.js +12 -12
- package/dist/connector-runtime.js +25 -25
- package/dist/deferred-tools-catalog.d.ts +2 -1
- package/dist/deferred-tools-catalog.d.ts.map +1 -1
- package/dist/deferred-tools-catalog.js +3 -1
- package/dist/details-status-runtime.js +23 -23
- package/dist/evidence-runtime.d.ts.map +1 -1
- package/dist/evidence-runtime.js +7 -6
- package/dist/extension-command-runtime.js +5 -5
- package/dist/extension-slash-runtime.js +24 -24
- package/dist/failure-learning-command-runtime.js +24 -24
- package/dist/final-answer-gate.d.ts.map +1 -1
- package/dist/final-answer-gate.js +2 -2
- package/dist/git-command-runtime.js +24 -24
- package/dist/handoff-session-runtime.js +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +103 -45
- package/dist/job-agent-command-runtime.js +23 -23
- package/dist/job-runtime.js +4 -4
- package/dist/mcp-index-command-runtime.js +3 -3
- package/dist/mcp-index-runtime.d.ts +8 -0
- package/dist/mcp-index-runtime.d.ts.map +1 -1
- package/dist/mcp-index-runtime.js +28 -26
- package/dist/mcp-stdio-runtime.js +2 -2
- package/dist/memory-command-runtime.js +24 -24
- package/dist/model-command-runtime.js +24 -24
- package/dist/model-doctor-runtime.d.ts +1 -0
- package/dist/model-doctor-runtime.d.ts.map +1 -1
- package/dist/model-doctor-runtime.js +1 -1
- package/dist/model-loop-runtime.d.ts +15 -1
- package/dist/model-loop-runtime.d.ts.map +1 -1
- package/dist/model-loop-runtime.js +29 -1
- package/dist/model-prompt-runtime.d.ts.map +1 -1
- package/dist/model-prompt-runtime.js +5 -5
- package/dist/model-stream-runtime.d.ts.map +1 -1
- package/dist/model-stream-runtime.js +37 -37
- package/dist/model-tool-runtime.d.ts +7 -0
- package/dist/model-tool-runtime.d.ts.map +1 -1
- package/dist/model-tool-runtime.js +39 -37
- package/dist/permission-approval-runtime.js +37 -37
- package/dist/permission-continuation-runtime.d.ts.map +1 -1
- package/dist/permission-continuation-runtime.js +2 -2
- package/dist/process-command-runtime.js +2 -2
- package/dist/process-guard.d.ts +3 -0
- package/dist/process-guard.d.ts.map +1 -1
- package/dist/process-guard.js +5 -1
- package/dist/provider-loop-runtime.js +3 -3
- package/dist/remote-command-runtime.js +24 -24
- package/dist/runner-runtime.js +3 -3
- package/dist/shell/components/ProductBlock.js +2 -2
- package/dist/shell/components/ShellApp.js +12 -12
- package/dist/shell/ink-renderer.js +12 -12
- package/dist/shell/view-model.js +6 -6
- package/dist/slash-command-runtime.js +37 -37
- package/dist/terminal-readiness-runtime.js +3 -3
- package/dist/tool-output-presenter.d.ts +1 -0
- package/dist/tool-output-presenter.d.ts.map +1 -1
- package/dist/tool-output-presenter.js +3 -1
- package/dist/tui-agent-job-runtime.js +8 -8
- package/dist/tui-context-runtime.d.ts +2 -0
- package/dist/tui-context-runtime.d.ts.map +1 -1
- package/dist/tui-context-runtime.js +3 -3
- package/dist/tui-data-types.d.ts +1 -0
- package/dist/tui-data-types.d.ts.map +1 -1
- package/dist/tui-details-runtime.js +5 -5
- package/dist/tui-model-runtime.js +2 -2
- package/dist/tui-output-surface.js +7 -7
- package/dist/tui-permission-runtime.js +3 -3
- package/dist/verification-command-runtime.js +9 -9
- package/dist/workflow-command-runtime.js +23 -23
- package/package.json +5 -5
- package/dist/{chunk-Z265MCGC.js → chunk-VWEAK3UV.js} +3 -3
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
getDurableJobPaths,
|
|
10
10
|
getDurableJobsRoot,
|
|
11
11
|
listDurableJobs
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-NMOVU75L.js";
|
|
13
13
|
import {
|
|
14
14
|
formatJobNextAction,
|
|
15
15
|
mapDurableJobToBackgroundResult,
|
|
@@ -17,7 +17,7 @@ import {
|
|
|
17
17
|
} from "./chunk-PI6T2AGS.js";
|
|
18
18
|
import {
|
|
19
19
|
MAX_BACKGROUND_TASKS
|
|
20
|
-
} from "./chunk-
|
|
20
|
+
} from "./chunk-VZFP7NWI.js";
|
|
21
21
|
import {
|
|
22
22
|
formatIndexRuntimeRef
|
|
23
23
|
} from "./chunk-TYTVAFGB.js";
|
|
@@ -75,6 +75,28 @@ var CODEBASE_MEMORY_DESCRIPTIONS = {
|
|
|
75
75
|
trace_path: "Trace a function call chain from -> to in an indexed project.",
|
|
76
76
|
search_graph: "Find similar implementations / SIMILAR_TO entries in a project."
|
|
77
77
|
};
|
|
78
|
+
var PRE_ENGINE_DESCRIPTIONS = {
|
|
79
|
+
pre_context: "Repository analysis: provide structured code facts (AST-based) for the current task context.",
|
|
80
|
+
pre_impact: "Repository impact analysis: analyze planned change scope via AST cross-references.",
|
|
81
|
+
pre_plan: "Repository edit planning: generate structured implementation hints from AST analysis.",
|
|
82
|
+
pre_verify: "Repository analysis verification: verify code change correctness via AST structural checks."
|
|
83
|
+
};
|
|
84
|
+
var PRE_ENGINE_REQUIRED_ARGS = {
|
|
85
|
+
pre_context: ["symbol"],
|
|
86
|
+
pre_impact: ["changes"],
|
|
87
|
+
pre_plan: ["task"],
|
|
88
|
+
pre_verify: ["changed_files"]
|
|
89
|
+
};
|
|
90
|
+
function listPreEngineDeferredTools() {
|
|
91
|
+
return Object.keys(PRE_ENGINE_DESCRIPTIONS).sort((a, b) => a.localeCompare(b)).map((name) => ({
|
|
92
|
+
name,
|
|
93
|
+
kind: "pre-engine",
|
|
94
|
+
description: PRE_ENGINE_DESCRIPTIONS[name] ?? `pre-engine tool: ${name}`,
|
|
95
|
+
requiredArgs: PRE_ENGINE_REQUIRED_ARGS[name] ?? [],
|
|
96
|
+
executable: true,
|
|
97
|
+
reason: "pre-engine static whitelist; readonly AST query, no mutation."
|
|
98
|
+
}));
|
|
99
|
+
}
|
|
78
100
|
function listCodebaseMemoryDeferredTools() {
|
|
79
101
|
const required = codebaseMemoryRequiredArgs();
|
|
80
102
|
return Object.keys(required).sort((a, b) => a.localeCompare(b)).map((name) => ({
|
|
@@ -161,6 +183,7 @@ function pluginManifestHasContribution(plugin) {
|
|
|
161
183
|
function listDeferredTools(context) {
|
|
162
184
|
return [
|
|
163
185
|
...listCodebaseMemoryDeferredTools(),
|
|
186
|
+
...listPreEngineDeferredTools(),
|
|
164
187
|
...listMcpDeferredTools(context),
|
|
165
188
|
...listSkillDeferredTools(context),
|
|
166
189
|
...listPluginDeferredTools(context)
|
|
@@ -170,6 +193,7 @@ function snapshotDeferredTools(context) {
|
|
|
170
193
|
const tools = listDeferredTools(context);
|
|
171
194
|
const byKind = {
|
|
172
195
|
"codebase-memory": 0,
|
|
196
|
+
"pre-engine": 0,
|
|
173
197
|
mcp: 0,
|
|
174
198
|
skill: 0,
|
|
175
199
|
plugin: 0
|
|
@@ -195,6 +219,13 @@ function snapshotDeferredToolsSummary(context) {
|
|
|
195
219
|
executableCount: snapshot.executableCount
|
|
196
220
|
};
|
|
197
221
|
}
|
|
222
|
+
function registerPreEngineDeferredToolsForRuntime(context, snapshot) {
|
|
223
|
+
const names = snapshot.tools.filter((tool) => tool.kind === "pre-engine" && tool.executable).map((tool) => tool.name).sort((a, b) => a.localeCompare(b));
|
|
224
|
+
for (const name of names) {
|
|
225
|
+
context.discoveredDeferredToolNames.add(name);
|
|
226
|
+
}
|
|
227
|
+
return names;
|
|
228
|
+
}
|
|
198
229
|
var DISCOVERED_NAME_MAX_LEN = 80;
|
|
199
230
|
var DISCOVERED_NAMES_MAX_COUNT = 32;
|
|
200
231
|
function sanitizeDiscoveredDeferredToolName(name) {
|
|
@@ -217,9 +248,13 @@ function snapshotDiscoveredDeferredToolsSummary(context) {
|
|
|
217
248
|
function searchDeferredTools(query, tools) {
|
|
218
249
|
const trimmed = query.trim().toLowerCase();
|
|
219
250
|
if (trimmed === "") return tools;
|
|
251
|
+
const tokens = trimmed.split(/[^a-z0-9_:.-]+/u).filter((token) => token.length >= 3);
|
|
220
252
|
return tools.filter((tool) => {
|
|
221
253
|
const haystack = `${tool.name} ${tool.description} ${tool.kind}`.toLowerCase();
|
|
222
|
-
|
|
254
|
+
if (haystack.includes(trimmed)) return true;
|
|
255
|
+
if (tokens.length === 0) return false;
|
|
256
|
+
const hits = tokens.filter((token) => haystack.includes(token)).length;
|
|
257
|
+
return hits >= Math.min(2, tokens.length);
|
|
223
258
|
});
|
|
224
259
|
}
|
|
225
260
|
function findDeferredTool(toolName, tools) {
|
|
@@ -235,7 +270,7 @@ function deferredToolListHashInput(tools) {
|
|
|
235
270
|
}
|
|
236
271
|
function formatDeferredToolsSystemReminder(language, snapshot) {
|
|
237
272
|
if (snapshot.total === 0) return void 0;
|
|
238
|
-
return language === "en-US" ? "Additional tools must be discovered via SearchExtraTools, then invoked via ExecuteExtraTool. Built-in tools (Read/ReadSnippets/SourcePack/Edit/Write/Bash/Grep/Glob/Todo) are still called directly." : "Additional tools must be discovered via SearchExtraTools, then invoked via ExecuteExtraTool.";
|
|
273
|
+
return language === "en-US" ? "Additional tools must be discovered via SearchExtraTools, then invoked via ExecuteExtraTool. For repository code understanding, impact analysis, edit planning, or quick verification, discover specialized repository tools before broad manual exploration. If codebase-memory index is ready, prefer index-backed search/graph/architecture tools for broad repository discovery, then use pre-engine for AST precision; if the index is missing or stale, use pre-engine as the fast repository-analysis entry. Built-in tools (Read/ReadSnippets/SourcePack/Edit/Write/Bash/Grep/Glob/Todo) are still called directly." : "Additional tools must be discovered via SearchExtraTools, then invoked via ExecuteExtraTool. For repository code understanding, impact analysis, edit planning, or quick verification, discover specialized repository tools before broad manual exploration. If codebase-memory index is ready, prefer index-backed search/graph/architecture tools for broad repository discovery, then use pre-engine for AST precision; if the index is missing or stale, use pre-engine as the fast repository-analysis entry.";
|
|
239
274
|
}
|
|
240
275
|
function isCodebaseMemoryToolName(name) {
|
|
241
276
|
return name in codebaseMemoryRequiredArgs();
|
|
@@ -268,6 +303,7 @@ export {
|
|
|
268
303
|
listDeferredTools,
|
|
269
304
|
snapshotDeferredTools,
|
|
270
305
|
snapshotDeferredToolsSummary,
|
|
306
|
+
registerPreEngineDeferredToolsForRuntime,
|
|
271
307
|
sanitizeDiscoveredDeferredToolName,
|
|
272
308
|
snapshotDiscoveredDeferredToolsSummary,
|
|
273
309
|
searchDeferredTools,
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ensureSession,
|
|
3
3
|
showCommandPanel
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-2JZBPXHF.js";
|
|
5
5
|
import {
|
|
6
6
|
decidePermission
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-PHPEPZAA.js";
|
|
8
8
|
import {
|
|
9
9
|
appendSystemEvent,
|
|
10
10
|
budgetToolResultTranscriptContent,
|
|
11
11
|
createEvidenceRecord,
|
|
12
12
|
rememberEvidence
|
|
13
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-JY2DO7OF.js";
|
|
14
14
|
import {
|
|
15
15
|
sanitizeDiagnosticText,
|
|
16
16
|
truncateDisplay,
|
|
@@ -1,21 +1,24 @@
|
|
|
1
1
|
import {
|
|
2
2
|
MAX_EVIDENCE_RECORDS
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-VZFP7NWI.js";
|
|
4
4
|
import {
|
|
5
5
|
applyToolResultBudgetToMessages,
|
|
6
6
|
formatToolResultBudgetEvidenceSummary,
|
|
7
7
|
formatToolResultBudgetSystemEvent
|
|
8
8
|
} from "./chunk-O7S3HYE6.js";
|
|
9
|
+
import {
|
|
10
|
+
formatToolDiagnosticsSummary
|
|
11
|
+
} from "./chunk-OI5TZ37D.js";
|
|
9
12
|
import {
|
|
10
13
|
LINGHUN_DEFAULT_TOOL_RESULT_CHARS,
|
|
11
14
|
LINGHUN_MAX_TOOL_RESULT_BYTES
|
|
12
15
|
} from "./chunk-IWUIOLMF.js";
|
|
13
16
|
import {
|
|
14
17
|
writeHandoffPacket
|
|
15
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-W6O7KDNM.js";
|
|
16
19
|
import {
|
|
17
20
|
deriveToolSupportsClaims
|
|
18
|
-
} from "./chunk-
|
|
21
|
+
} from "./chunk-3KRRVLS4.js";
|
|
19
22
|
import {
|
|
20
23
|
mergeFailureRecord,
|
|
21
24
|
writeFailureRecord
|
|
@@ -37,6 +40,7 @@ var TRANSCRIPT_TOOL_OUTPUT_MAX_CHARS = 8e3;
|
|
|
37
40
|
var MAX_ROUND_ASSISTANT_CHARS_FOR_PROVIDER = 16e3;
|
|
38
41
|
var ROUND_ASSISTANT_HEAD_CHARS = 4e3;
|
|
39
42
|
var ROUND_ASSISTANT_TAIL_CHARS = 4e3;
|
|
43
|
+
var RECENT_DIAGNOSTICS_LIMIT = 20;
|
|
40
44
|
function createEvidenceRecord(kind, summary, source, supportsClaims) {
|
|
41
45
|
return {
|
|
42
46
|
id: randomUUID(),
|
|
@@ -220,14 +224,15 @@ async function recordToolEvidence(context, sessionId, name, output, input) {
|
|
|
220
224
|
return null;
|
|
221
225
|
}
|
|
222
226
|
const readOnlyEvidence = name === "Read" || name === "ReadSnippets" || name === "SourcePack" || name === "Grep" || name === "Glob";
|
|
227
|
+
const supportsClaims = [
|
|
228
|
+
...deriveToolSupportsClaims(name, input, output),
|
|
229
|
+
...readOnlyEvidence ? ["readonly_low_noise_evidence"] : []
|
|
230
|
+
];
|
|
223
231
|
const evidence = createEvidenceRecord(
|
|
224
232
|
kind,
|
|
225
233
|
readOnlyEvidence ? formatReadOnlyToolEvidenceSummary(name, output, input) : `${name}: ${truncateDisplay(output.text.replace(/\s+/g, " "), 120)}`,
|
|
226
234
|
output.fullOutputPath ?? name,
|
|
227
|
-
|
|
228
|
-
...deriveToolSupportsClaims(name, input, output),
|
|
229
|
-
...readOnlyEvidence ? ["readonly_low_noise_evidence"] : []
|
|
230
|
-
]
|
|
235
|
+
supportsClaims
|
|
231
236
|
);
|
|
232
237
|
rememberEvidence(context, evidence);
|
|
233
238
|
await context.store.appendEvent(sessionId, {
|
|
@@ -420,8 +425,12 @@ function createToolEndEvent(id, output) {
|
|
|
420
425
|
};
|
|
421
426
|
}
|
|
422
427
|
function summarizeToolEndOutputForTranscript(output) {
|
|
428
|
+
const diagnostics = formatToolDiagnosticsSummary(output);
|
|
423
429
|
const text = compactToolEndTextForTranscript(
|
|
424
|
-
|
|
430
|
+
appendCompactDiagnostics(
|
|
431
|
+
output.summary || output.preview || output.text || "tool call completed",
|
|
432
|
+
diagnostics
|
|
433
|
+
),
|
|
425
434
|
output.fullOutputPath
|
|
426
435
|
);
|
|
427
436
|
return {
|
|
@@ -431,9 +440,15 @@ function summarizeToolEndOutputForTranscript(output) {
|
|
|
431
440
|
truncated: output.truncated,
|
|
432
441
|
fullOutputPath: output.fullOutputPath,
|
|
433
442
|
evidenceId: output.evidenceId,
|
|
434
|
-
changedFiles: output.changedFiles
|
|
443
|
+
changedFiles: output.changedFiles,
|
|
444
|
+
data: compactToolStructuredDataForTranscript(output.data)
|
|
435
445
|
};
|
|
436
446
|
}
|
|
447
|
+
function appendCompactDiagnostics(text, diagnostics) {
|
|
448
|
+
if (!diagnostics || text.includes("Linghun diagnostics:")) return text;
|
|
449
|
+
return `${diagnostics}
|
|
450
|
+
${text}`;
|
|
451
|
+
}
|
|
437
452
|
function compactToolEndTextForTranscript(text, fullOutputPath) {
|
|
438
453
|
const bytes = Buffer.byteLength(text, "utf8");
|
|
439
454
|
if (text.length <= TRANSCRIPT_TOOL_OUTPUT_MAX_CHARS && bytes <= TRANSCRIPT_TOOL_OUTPUT_MAX_CHARS) {
|
|
@@ -474,12 +489,60 @@ function compactToolOutputDataForTranscript(data) {
|
|
|
474
489
|
return {
|
|
475
490
|
truncated: true,
|
|
476
491
|
originalChars: serialized.length,
|
|
477
|
-
preview: serialized.slice(0, TRANSCRIPT_TOOL_OUTPUT_PREVIEW_CHARS)
|
|
492
|
+
preview: serialized.slice(0, TRANSCRIPT_TOOL_OUTPUT_PREVIEW_CHARS),
|
|
493
|
+
...compactToolStructuredDataForTranscript(data)
|
|
494
|
+
};
|
|
495
|
+
}
|
|
496
|
+
function compactToolStructuredDataForTranscript(data) {
|
|
497
|
+
const diagnostics = compactDiagnosticsDataForTranscript(data);
|
|
498
|
+
return diagnostics;
|
|
499
|
+
}
|
|
500
|
+
function compactDiagnosticsDataForTranscript(data) {
|
|
501
|
+
const diagnostics = readDiagnosticsForTranscript(data);
|
|
502
|
+
if (!diagnostics) return void 0;
|
|
503
|
+
return { diagnostics };
|
|
504
|
+
}
|
|
505
|
+
function readDiagnosticsForTranscript(data) {
|
|
506
|
+
if (!data || typeof data !== "object") return void 0;
|
|
507
|
+
const diagnostics = data.diagnostics;
|
|
508
|
+
if (!Array.isArray(diagnostics) || diagnostics.length === 0) return void 0;
|
|
509
|
+
return diagnostics.slice(0, 5).map(compactDiagnosticForTranscript).filter((diagnostic) => Boolean(diagnostic));
|
|
510
|
+
}
|
|
511
|
+
function compactDiagnosticForTranscript(value) {
|
|
512
|
+
if (!value || typeof value !== "object") return void 0;
|
|
513
|
+
const record = value;
|
|
514
|
+
const type = typeof record.type === "string" ? record.type : void 0;
|
|
515
|
+
const severity = typeof record.severity === "string" ? record.severity : void 0;
|
|
516
|
+
const evidence = typeof record.evidence === "string" ? truncateDisplay(record.evidence.replace(/\s+/g, " "), 160) : void 0;
|
|
517
|
+
if (!type || !evidence) return void 0;
|
|
518
|
+
return {
|
|
519
|
+
type,
|
|
520
|
+
severity,
|
|
521
|
+
evidence,
|
|
522
|
+
...readCompactDiagnosticTargetFields(record)
|
|
523
|
+
};
|
|
524
|
+
}
|
|
525
|
+
function readCompactDiagnosticTargetFields(record) {
|
|
526
|
+
const target = typeof record.target === "string" ? record.target : void 0;
|
|
527
|
+
const path = typeof record.path === "string" ? record.path : void 0;
|
|
528
|
+
const command = typeof record.command === "string" ? record.command : void 0;
|
|
529
|
+
const fallback = typeof record.fallback === "string" ? record.fallback : void 0;
|
|
530
|
+
const targetHost = typeof record.targetHost === "string" ? record.targetHost : void 0;
|
|
531
|
+
const targetPort = typeof record.targetPort === "number" ? record.targetPort : void 0;
|
|
532
|
+
return {
|
|
533
|
+
...command ? { command } : {},
|
|
534
|
+
...fallback ? { fallback } : {},
|
|
535
|
+
...target ? { target } : {},
|
|
536
|
+
...path ? { path } : {},
|
|
537
|
+
...targetHost ? { targetHost } : {},
|
|
538
|
+
...targetPort !== void 0 ? { targetPort } : {}
|
|
478
539
|
};
|
|
479
540
|
}
|
|
480
541
|
function isToolOutputFailure(name, output) {
|
|
481
542
|
if (name === "Bash") {
|
|
482
|
-
const
|
|
543
|
+
const data = output.data;
|
|
544
|
+
if (data?.isError === false) return false;
|
|
545
|
+
const exitCode = data?.exitCode;
|
|
483
546
|
return typeof exitCode === "number" && exitCode !== 0;
|
|
484
547
|
}
|
|
485
548
|
return false;
|
|
@@ -525,11 +588,14 @@ async function appendDeferredToolResultEvent(context, sessionId, toolUseId, disp
|
|
|
525
588
|
});
|
|
526
589
|
}
|
|
527
590
|
async function appendToolResultEvent(context, sessionId, toolUseId, toolName, content, isError, evidenceId) {
|
|
591
|
+
rememberRecentDiagnostics(context, toolName, content, toolUseId, evidenceId);
|
|
592
|
+
rememberToolEvidenceData(context, evidenceId, content);
|
|
593
|
+
const contentWithDiagnostics = appendToolResultContentDiagnostics(content);
|
|
528
594
|
const budgetedContent = await budgetToolResultTranscriptContent(
|
|
529
595
|
context,
|
|
530
596
|
sessionId,
|
|
531
597
|
toolUseId,
|
|
532
|
-
|
|
598
|
+
contentWithDiagnostics
|
|
533
599
|
);
|
|
534
600
|
await context.store.appendEvent(sessionId, {
|
|
535
601
|
type: "tool_result",
|
|
@@ -541,6 +607,55 @@ async function appendToolResultEvent(context, sessionId, toolUseId, toolName, co
|
|
|
541
607
|
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
542
608
|
});
|
|
543
609
|
}
|
|
610
|
+
function rememberToolEvidenceData(context, evidenceId, content) {
|
|
611
|
+
if (!evidenceId || !content || typeof content !== "object") return;
|
|
612
|
+
if (!Array.isArray(context.evidence)) return;
|
|
613
|
+
const output = content;
|
|
614
|
+
const compact = compactToolEvidenceData(output.data);
|
|
615
|
+
if (!compact) return;
|
|
616
|
+
const evidence = context.evidence.find((item) => item.id === evidenceId);
|
|
617
|
+
if (evidence) {
|
|
618
|
+
evidence.data = { ...typeof evidence.data === "object" && evidence.data ? evidence.data : {}, ...compact };
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
function compactToolEvidenceData(data) {
|
|
622
|
+
if (!data || typeof data !== "object") return void 0;
|
|
623
|
+
const record = data;
|
|
624
|
+
const compact = {};
|
|
625
|
+
for (const key of ["service", "serviceHint", "artifactHint", "binaryHint", "binaryPreflight"]) {
|
|
626
|
+
if (record[key] !== void 0) compact[key] = record[key];
|
|
627
|
+
}
|
|
628
|
+
return Object.keys(compact).length > 0 ? compact : void 0;
|
|
629
|
+
}
|
|
630
|
+
function rememberRecentDiagnostics(context, source, content, toolUseId, evidenceId) {
|
|
631
|
+
const diagnostics = readDiagnosticsForTranscript(content?.data);
|
|
632
|
+
if (!diagnostics || diagnostics.length === 0) return;
|
|
633
|
+
const createdAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
634
|
+
const entries = diagnostics.map((diagnostic) => ({
|
|
635
|
+
source,
|
|
636
|
+
...diagnostic,
|
|
637
|
+
createdAt,
|
|
638
|
+
toolUseId,
|
|
639
|
+
evidenceId
|
|
640
|
+
}));
|
|
641
|
+
context.tools.recentDiagnostics = [
|
|
642
|
+
...entries,
|
|
643
|
+
...context.tools.recentDiagnostics ?? []
|
|
644
|
+
].slice(0, RECENT_DIAGNOSTICS_LIMIT);
|
|
645
|
+
}
|
|
646
|
+
function appendToolResultContentDiagnostics(content) {
|
|
647
|
+
if (!content || typeof content !== "object") return content;
|
|
648
|
+
const output = content;
|
|
649
|
+
if (typeof output.text !== "string") return content;
|
|
650
|
+
const diagnostics = formatToolDiagnosticsSummary(output);
|
|
651
|
+
const compactData = compactToolStructuredDataForTranscript(output.data);
|
|
652
|
+
if (!diagnostics && !compactData) return content;
|
|
653
|
+
return {
|
|
654
|
+
...output,
|
|
655
|
+
data: compactData,
|
|
656
|
+
text: diagnostics ? appendCompactDiagnostics(output.text, diagnostics) : output.text
|
|
657
|
+
};
|
|
658
|
+
}
|
|
544
659
|
async function budgetToolResultTranscriptContent(context, sessionId, toolUseId, content) {
|
|
545
660
|
const contentText = stringifyToolResultContentForBudget(content);
|
|
546
661
|
if (!contentText || contentText.startsWith("<persisted-tool-result>")) return content;
|