@steerable/agent-protocol 0.14.1 → 0.14.3

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.
@@ -0,0 +1,92 @@
1
+ /**
2
+ * Zero-dependency transcript parsing helpers shared by `@steerable/agent-shell-web`
3
+ * and `@steerable/agent-cli` (TUI).
4
+ *
5
+ * Lives in Tier-1 `@steerable/agent-protocol` (alongside `turn-failure-kind.ts`)
6
+ * so browser bundles and Node TUI share one implementation for:
7
+ * 1. Unwrapping serialized / 300-char-truncated `ToolResult` JSON envelopes;
8
+ * 2. Extracting clean terminal `command`, `stdout`, `stderr`, `exitCode`;
9
+ * 3. Extracting or synthesizing Unified Diff + `+added / -removed` stats;
10
+ * 4. Detecting skill invocations (`skill` tool or reading `.../SKILL.md`);
11
+ * 5. Codex-style head + tail middle output truncation (`truncateOutputMiddle`).
12
+ */
13
+ import { type ClassifiedShellAction } from './shell-command-classifier.js';
14
+ export interface ToolEnvelope {
15
+ success: boolean | null;
16
+ error: string | null;
17
+ message: string | null;
18
+ fields: Record<string, unknown>;
19
+ }
20
+ export interface TerminalExecutionView {
21
+ settled: boolean;
22
+ command: string | null;
23
+ language: string | null;
24
+ cwd: string | null;
25
+ packages?: string[];
26
+ stdout: string;
27
+ stderr: string;
28
+ error: string | null;
29
+ exitCode: number | null;
30
+ timedOut: boolean;
31
+ }
32
+ export interface FileChangePreview {
33
+ path: string;
34
+ isWrite: boolean;
35
+ addedLines: number;
36
+ removedLines: number;
37
+ totalLines: number | null;
38
+ diff: string | null;
39
+ contentPreview: string | null;
40
+ error?: string | null;
41
+ }
42
+ export interface TruncatedOutput {
43
+ truncated: boolean;
44
+ totalLines: number;
45
+ head: string;
46
+ tail: string;
47
+ omittedLines: number;
48
+ }
49
+ /** Parse a JSON object/array string when well-formed; return original value otherwise. */
50
+ export declare function parseJsonValue(value: unknown): unknown;
51
+ export declare function extractPartialJsonStringFieldWithState(raw: string, field: string): {
52
+ value: string;
53
+ complete: boolean;
54
+ } | null;
55
+ export declare function extractPartialJsonStringField(raw: string, field: string): string | null;
56
+ export declare function extractPartialJsonExitCode(raw: string): number | null;
57
+ /** Unwrap a sidecar `ToolResult` (object or JSON/truncated-JSON string) into normalized envelope fields. */
58
+ export declare function parseToolEnvelope(result: unknown): ToolEnvelope;
59
+ /** Unwrap a terminal/snippet tool call into clean command + stdout/stderr without internal `_sandbox` keys. */
60
+ export declare function parseTerminalExecution(action: {
61
+ arguments?: unknown;
62
+ result?: unknown;
63
+ }): TerminalExecutionView;
64
+ /** True when a classified search command (`rg`/`grep`) exited with code 1 and empty stderr (standard "no matches"). */
65
+ export declare function isBenignSearchNoMatch(classified: ClassifiedShellAction | null, terminal: TerminalExecutionView): boolean;
66
+ /** Detect `skill` tool calls or `SKILL.md` file/shell reads. */
67
+ export declare function extractSkillInvocation(action: {
68
+ tool: string;
69
+ arguments?: unknown;
70
+ }): {
71
+ skillName: string;
72
+ path: string | null;
73
+ } | null;
74
+ /**
75
+ * Extract unified diff + `+added / -removed` counts for file mutation tools.
76
+ * Recovers full unified diffs from `arguments.edits` when persisted `result`
77
+ * strings were truncated to 300 characters.
78
+ */
79
+ export declare function extractFileChangePreview(action: {
80
+ tool: string;
81
+ arguments?: unknown;
82
+ result?: unknown;
83
+ }): FileChangePreview | null;
84
+ /**
85
+ * Keep head + tail lines of multi-line command output so both the command header
86
+ * and trailing error/summary stay visible on screen without scrolling.
87
+ */
88
+ export declare function truncateOutputMiddle(text: string, options?: {
89
+ headLines?: number;
90
+ tailLines?: number;
91
+ minTotalLines?: number;
92
+ }): TruncatedOutput;