@linxiraos/pi-wire 1.4.11 → 1.4.12

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,180 @@
1
+ /**
2
+ * `ShellTrace`: the live model of one embedded-shell run, produced by pi-shell's
3
+ * `RunTrace` (`crates/pi-shell/src/bash/trace.rs`), polled over napi, carried in
4
+ * the bash tool's `details.trace`, and forwarded verbatim to Tern as the `shell`
5
+ * node's props. Every offset is a BYTE offset; UIs convert bytes to characters
6
+ * when the script is not ASCII. Fields at their default are omitted.
7
+ */
8
+ /**
9
+ * Bytes a run produced (expansions, assignments, eval bodies, diagnostics):
10
+ * a string when they are UTF-8, else the raw byte values. Nothing is replaced,
11
+ * so values and byte offsets stay exactly what the engine recorded.
12
+ */
13
+ export type ShellTraceBytes = string | number[];
14
+ /** NodeKind of the engine's AST, snake_case. `assign` and `word` are not statements. */
15
+ export type ShellTraceNodeKind = "and_or" | "pipeline" | "simple" | "brace" | "subshell" | "if" | "while" | "until" | "for" | "arith_for" | "select" | "case" | "arith" | "cond" | "func_def" | "coproc" | "assign" | "word";
16
+ /** How the engine resolved a simple command's name. */
17
+ export type ShellTraceResolved = "function" | "intrinsic" | "tool" | "native" | "device" | "self_shell" | "external" | "not_found" | "none";
18
+ /** Derived at snapshot time (contract §3); always present. */
19
+ export type ShellTraceState = "pending" | "running" | "ok" | "fail" | "skipped";
20
+ export interface ShellTraceRedir {
21
+ fd: number;
22
+ op: string;
23
+ target: ShellTraceBytes;
24
+ }
25
+ export interface ShellTraceDiag {
26
+ code: string;
27
+ message: ShellTraceBytes;
28
+ }
29
+ /** One AST node of a unit; the unit's `nodes` index is the AstNodeId. */
30
+ export interface ShellTraceNode {
31
+ k: ShellTraceNodeKind;
32
+ /** Byte span relative to the unit source. */
33
+ lo: number;
34
+ hi: number;
35
+ /** Parent node id; absent for the root. */
36
+ p?: number;
37
+ state: ShellTraceState;
38
+ /** CmdStart count. */
39
+ runs?: number;
40
+ /** CmdStart − CmdEnd. */
41
+ live?: number;
42
+ /** Status of the last CmdEnd. */
43
+ st?: number;
44
+ /** CmdEnds with a non-zero status. */
45
+ fails?: number;
46
+ /** Sum of `dur_ns` over the ended runs. */
47
+ ns?: number;
48
+ /** `t_ns` of the last CmdStart, relative to RunStart. */
49
+ at?: number;
50
+ /** Last CmdExpanded argv (each arg ≤ 256 bytes, ≤ 64 args). */
51
+ argv?: ShellTraceBytes[];
52
+ /** The full argv length when `argv` was cut. */
53
+ argc?: number;
54
+ /** Last CmdExpanded assigns. */
55
+ env?: [ShellTraceBytes, ShellTraceBytes][];
56
+ res?: ShellTraceResolved;
57
+ redirs?: ShellTraceRedir[];
58
+ /** Pipestatus of the last CmdEnd. */
59
+ pipe?: number[];
60
+ /** Last IterStart n. */
61
+ iter?: number;
62
+ /** LoopEnd iterations. */
63
+ iters?: number;
64
+ /** Last Branch decision. */
65
+ taken?: boolean;
66
+ /** A Background event named this node. */
67
+ bg?: boolean;
68
+ /** Last Spawn pid. */
69
+ pid?: number;
70
+ /** Actual last command completion timestamp and trace revision. */
71
+ end_ns?: number;
72
+ end_seq?: number;
73
+ }
74
+ /** One compiled unit (a top-level command, or an eval/function body). */
75
+ export interface ShellTraceUnit {
76
+ /** Byte offset of the unit inside `script`; absent when the unit is not part of the script. */
77
+ at?: number;
78
+ /** 1-based script line. */
79
+ line: number;
80
+ /** Exact UTF-8 source byte length, including heredocs; absent in older traces. */
81
+ bytes?: number;
82
+ /** The unit's source; present only for unlocated units (an eval or function body). */
83
+ source?: ShellTraceBytes;
84
+ /** Opaque canonical native syntax archive. Only pi-shell may interpret it. */
85
+ syntax?: unknown;
86
+ /** Compiler-known wrapper bytes removed from this unit's displayed source. */
87
+ projection?: number;
88
+ /** Script a callout (`timeout`, `git`, `xargs`, …) ran for its operands; its calling command stands for it. */
89
+ callout?: boolean;
90
+ nodes: ShellTraceNode[];
91
+ }
92
+ /** Exact output/execution identity; repeated visits to one node have distinct seq values. */
93
+ export interface ShellTraceCommandTag {
94
+ /** Actual engine field: descendant vprocs without a root run queue use 0.
95
+ * Do not reject those tags; capture generation and explicit fork events
96
+ * establish run ownership, while vpid/seq distinguish the producer. */
97
+ run: number;
98
+ vpid: number;
99
+ seq: number;
100
+ }
101
+ /** Proven byte fragment of a decoded scalar spanning different producers.
102
+ * The containing Output has no single primary producer; these at-most-four
103
+ * bytes retain the exact contributing executions without guessing ownership. */
104
+ export interface ShellTraceOutputContributor {
105
+ t_ns: number;
106
+ bytes: number[];
107
+ command?: ShellTraceCommandTag;
108
+ vpid?: number;
109
+ u?: number;
110
+ n?: number;
111
+ }
112
+ /** Bounded replay journal entry. Missing u/n explicitly means unknown attribution. */
113
+ export interface ShellTraceHistoryEvent {
114
+ /** Trace revision, including coalesced output growth. */
115
+ seq: number;
116
+ /** Measured monotonic engine/host nanoseconds since RunStart, like node.at. */
117
+ t_ns: number;
118
+ /** Original engine event sequence; absent for Output callbacks. */
119
+ event_seq?: number;
120
+ /** Zero-based actual minimizer segment submission; lifecycle entries remain real engine events. */
121
+ segment?: number;
122
+ /** The last real root RunEnd finalized the entire logical segmented call. */
123
+ logicalEnd?: boolean;
124
+ /** Actual host outcome after output/close draining, without replacing engine status. */
125
+ logicalStatus?: number;
126
+ /** Actual emitting vproc, present on semantic entries even without a command tag. */
127
+ vpid?: number;
128
+ kind: "CmdStart" | "CmdExpanded" | "CmdEnd" | "Pipeline" | "Branch" | "IterStart" | "LoopEnd" | "Background" | "FuncEnter" | "FuncExit" | "Assign" | "RunStart" | "RunEnd" | "Output" | "Diag" | "Exit" | "ErrExit" | "Spawn";
129
+ u?: number;
130
+ n?: number;
131
+ command?: ShellTraceCommandTag;
132
+ status?: number;
133
+ dur_ns?: number;
134
+ pipestatus?: number[];
135
+ argv?: ShellTraceBytes[];
136
+ assigns?: [ShellTraceBytes, ShellTraceBytes][];
137
+ resolved?: ShellTraceResolved;
138
+ redirs?: ShellTraceRedir[];
139
+ name?: ShellTraceBytes;
140
+ value?: ShellTraceBytes;
141
+ full_len?: number;
142
+ scope?: string;
143
+ iteration?: number;
144
+ iterations?: number;
145
+ taken?: boolean;
146
+ construct?: string;
147
+ /** `Output` text is always a string (undecodable bytes arrive as U+FFFD); `Diag` text is run bytes. */
148
+ text?: ShellTraceBytes;
149
+ contributors?: ShellTraceOutputContributor[];
150
+ /** Final visible capture descriptor; merged stderr uses stdout's descriptor. */
151
+ fd?: number;
152
+ pid?: number;
153
+ }
154
+ export interface ShellTrace {
155
+ v: 1;
156
+ /** Semantic/output revision, including assignments/coalesced bytes; monotonic poll key. */
157
+ seq: number;
158
+ /** Root RunEnd status; absent while running. */
159
+ status?: number;
160
+ /** Actual root vproc, even if history trimming removed its RunStart. */
161
+ rootVpid?: number;
162
+ /** Run clock (ns since RunStart) at the last folded event. */
163
+ t_ns: number;
164
+ /** The command text given at construction. */
165
+ script: string;
166
+ /** Compiled units, in announce order. */
167
+ units: ShellTraceUnit[];
168
+ /** Newest ≤20,000 semantic/output records, ≤2 MiB visible output and ≤8 MiB retained payload.
169
+ * Adjacent output from the same execution may coalesce; its seq changes
170
+ * when text grows. Consumers must replace the full journal on revision. */
171
+ history?: ShellTraceHistoryEvent[];
172
+ /** True when any replay record or output byte was evicted. */
173
+ historyTruncated?: boolean;
174
+ /** The last ≤ 8 diagnostics. */
175
+ diags?: ShellTraceDiag[];
176
+ }
177
+ /** Validate an untrusted persisted/native trace, including nested nodes and replay entries.
178
+ * Callers should memoize by input reference; validating a journal is linear in its retained size.
179
+ * This guard never caches mutable input objects as trusted. */
180
+ export declare function isShellTrace(value: unknown): value is ShellTrace;
@@ -0,0 +1,114 @@
1
+ import type { ShellTraceState } from "./shell-trace.js";
2
+ /** Supported shell presentation modes. */
3
+ export type ShellVizView = "raw" | "pseudo";
4
+ /** Independently toggleable, non-executing presentation transformations. */
5
+ export type ShellVizLayer = "color" | "inline" | "idioms" | "effects" | "unwrap";
6
+ /** Every layer is explicit so persisted preferences have deterministic meaning. */
7
+ export interface ShellVizLayers {
8
+ color: boolean;
9
+ inline: boolean;
10
+ idioms: boolean;
11
+ effects: boolean;
12
+ unwrap: boolean;
13
+ }
14
+ /** Per-tool-call preferences. Node identifiers are opaque native `unit:source:node` keys. */
15
+ export interface ShellVizPreferences {
16
+ view: ShellVizView;
17
+ layers: ShellVizLayers;
18
+ split: boolean;
19
+ /** Number of retained history records applied; absent means live. */
20
+ cursor?: number;
21
+ playing: boolean;
22
+ speed: number;
23
+ selectedNode?: string;
24
+ expandedNodes: string[];
25
+ }
26
+ /** Semantic text. All ranges are UTF-16 [lo, hi) in the original outermost source. */
27
+ export interface ShellVizSegment {
28
+ text: string;
29
+ /** True only on an executing leaf span; dim other spans while presentation.running. */
30
+ active?: boolean;
31
+ /** Actual governing leaf outcome, including failures inside otherwise successful pipelines/chains. */
32
+ state?: ShellTraceState;
33
+ /** Actual last leaf CmdEnd clock/sequence; identity is executionNode (or node) + executionSeq. */
34
+ executedAtNs?: number;
35
+ executionSeq?: number;
36
+ /** Space-separated semantic tokens; structural chip/badge tokens survive Color off. */
37
+ style?: string;
38
+ /** Source-token identity used only for selection and source links. */
39
+ node?: string;
40
+ /** Actual command owning state/completion when this token has a different source identity. */
41
+ executionNode?: string;
42
+ range?: [number, number];
43
+ tip?: string;
44
+ /** Complete original text revealed by inspection or expansion. */
45
+ expanded?: string;
46
+ /** Embedded language, with semantic tokenization already performed. */
47
+ language?: string;
48
+ }
49
+ /** Heuristic effect annotation, never a guarantee of safety or completeness. */
50
+ export interface ShellVizEffect {
51
+ kind: "network" | "write" | "destructive" | "secret" | "privilege" | "background";
52
+ glyph: string;
53
+ label: string;
54
+ why: string;
55
+ }
56
+ /** One physical Raw/Pseudo presentation row; structural line breaks are separate rows, not terminal LF text. */
57
+ export interface ShellVizRow {
58
+ id: string;
59
+ depth: number;
60
+ node?: string;
61
+ range?: [number, number];
62
+ /** This row contains an active executable leaf, not merely an enclosing scope. */
63
+ active?: boolean;
64
+ role?: "stmt" | "head" | "mid" | "tail" | "raw" | "document";
65
+ state?: ShellTraceState;
66
+ segments: ShellVizSegment[];
67
+ effects: ShellVizEffect[];
68
+ /** Actual last leaf completion, never copied onto enclosing scope/scaffold rows. */
69
+ executedAtNs?: number;
70
+ executionSeq?: number;
71
+ /** Human-readable runtime metadata, not a machine-readable protocol. */
72
+ meta?: string;
73
+ detail?: string;
74
+ /** Latest real variable values whose last setter is represented by this row; never a detached watch strip. */
75
+ annotations?: ShellVizWatch[];
76
+ }
77
+ /** Latest observed setter of one scoped variable, never a statically guessed runtime value. */
78
+ export interface ShellVizWatch {
79
+ name: string;
80
+ value: string;
81
+ fullLength?: number;
82
+ scope?: string;
83
+ /** Proven scope/process identity; unknown binding identity is not replaced with a guessed function frame. */
84
+ scopeId?: string;
85
+ /** Owning executable/header AST node, promoted from assignment/word event ids. Absent means unlocated. */
86
+ node?: string;
87
+ /** Actual setter span in original outer-script UTF-16 coordinates; absent for unlocated dynamic source. */
88
+ range?: [number, number];
89
+ /** Retained journal seq of the actual last setter, so replay moves or removes the annotation. */
90
+ setterSeq?: number;
91
+ }
92
+ /** Browser-independent presentation shared by ANSI and native GUI renderers. */
93
+ export interface ShellVizPresentation {
94
+ preferences: ShellVizPreferences;
95
+ rows: ShellVizRow[];
96
+ /** Raw counterpart for Pseudo split; empty when that pane is not requested. */
97
+ original: ShellVizRow[];
98
+ /** Actual captured stdout/stderr through the replay cursor, in event order. */
99
+ output: string;
100
+ /** At least one actual executable leaf is running; dim all inactive content. */
101
+ running?: boolean;
102
+ /** Native run has not ended, even when currently between executable leaves. */
103
+ executing: boolean;
104
+ /** Canonical latest observed values; consumers render row.annotations, not a detached strip. */
105
+ watches: ShellVizWatch[];
106
+ timeline: {
107
+ length: number;
108
+ cursor: number;
109
+ elapsedNs: number;
110
+ durationNs: number;
111
+ trimmed?: boolean;
112
+ };
113
+ message?: string;
114
+ }
@@ -15,6 +15,7 @@
15
15
  * vocabulary. Unknown fields and verbs are ignored in both directions, so
16
16
  * every addition here is optional.
17
17
  */
18
+ import type { ShellVizPresentation } from "./shell-viz.js";
18
19
  /** Protocol version this build speaks. */
19
20
  export declare const TSP_VERSION = 1;
20
21
  /** APC identifier: every TSP message body starts with `tsp;`. */
@@ -26,7 +27,7 @@ export declare const TSP_DEFAULT_CREDITS = 2;
26
27
  /** One-letter message verb. */
27
28
  export type TspVerb = "q" | "o" | "f" | "b" | "x" | "r" | "e";
28
29
  /** Every component kind in the v1 vocabulary. */
29
- export declare const TSP_KINDS: readonly ["col", "row", "card", "section", "rule", "spacer", "text", "md", "code", "diff", "ansi", "math", "image", "media", "kv", "table", "tree", "json", "badge", "kbd", "icon", "spinner", "shimmer", "elapsed", "progress", "rate", "list", "item", "tabs", "editor", "input", "button", "status", "seg", "overlay", "toast", "rows", "picker", "prefs", "tool", "checklist", "agent", "chart", "meter", "effort"];
30
+ export declare const TSP_KINDS: readonly ["col", "row", "card", "section", "rule", "spacer", "text", "md", "code", "diff", "ansi", "math", "image", "media", "kv", "table", "tree", "json", "badge", "kbd", "icon", "spinner", "shimmer", "elapsed", "progress", "rate", "list", "item", "tabs", "editor", "input", "button", "status", "seg", "overlay", "toast", "rows", "picker", "prefs", "tool", "checklist", "agent", "chart", "meter", "effort", "shell"];
30
31
  export type TspKind = (typeof TSP_KINDS)[number];
31
32
  /** Semantic colour of a node's chrome. */
32
33
  export type TspTone = "neutral" | "accent" | "info" | "success" | "warning" | "error" | "pending" | "muted" | "user";
@@ -168,6 +169,33 @@ export interface TspMarkdownProps {
168
169
  /** Literal runs drawn as these spans wherever they occur in prose (a sent prompt's chip tokens). */
169
170
  marks?: readonly TspSpan[];
170
171
  }
172
+ /** One marked line of a {@link TspCodeProps.marks}. */
173
+ export interface TspCodeMark {
174
+ line: number;
175
+ tone?: TspTone;
176
+ heat?: number;
177
+ /**
178
+ * Scores in [0, 1] washing the row on the `heat` ramp in place of `heat`'s wash: one flat, several a gradient across
179
+ * the row, an evenly spaced stop per score from left to right. `heat` still sizes the line's overview bar.
180
+ */
181
+ wash?: readonly number[];
182
+ }
183
+ /** A run of lines a {@link TspCodeProps} draws as one row until it is opened. */
184
+ export interface TspCodeFold {
185
+ /** First and last folded line, in the gutter's numbering. */
186
+ from: number;
187
+ to: number;
188
+ /** The folded row's text, in the code's face (default `… [lines {from}-{to}]`, `… [line {from}]` for one line). */
189
+ label?: string;
190
+ /** What the fold hides, after a sparkline of its lines' mark `heat`. */
191
+ note?: TspText;
192
+ /** `error` tints the row; any tone colors the note. */
193
+ tone?: TspTone;
194
+ /** Drawn open; a click on the folded row (or on an open fold's head) toggles it in place. */
195
+ open?: boolean;
196
+ /** A card shown while the pointer rests on the folded row, as the common {@link TspCommonProps.hovercard}. */
197
+ hovercard?: TspPropNode;
198
+ }
171
199
  export interface TspCodeProps {
172
200
  text?: string;
173
201
  /** The language of text that is no file's (`bash`, `json`); wins over `path`. */
@@ -184,13 +212,23 @@ export interface TspCodeProps {
184
212
  */
185
213
  nums?: readonly number[];
186
214
  numbers?: boolean;
187
- marks?: readonly {
188
- line: number;
189
- tone: TspTone;
190
- }[];
215
+ /**
216
+ * Marked lines (`line` is the drawn line number). `heat` in [0, 1] washes the row in a heat ramp, `wash` runs that
217
+ * ramp across it; `tone` draws a bar, and any tone but `accent` also tints an unwashed row. A mark without `heat`
218
+ * or `wash` has tone `accent` by default; one with only those draws no bar.
219
+ */
220
+ marks?: readonly TspCodeMark[];
191
221
  wrap?: boolean;
192
222
  /** Clamp to the first `lines` drawn lines under a "N more lines" button; gives way inside an open disclosure. */
193
223
  preview?: TspPreview;
224
+ /** Runs of lines drawn folded: sorted, not overlapping; marks inside apply once a fold is open. */
225
+ folds?: readonly TspCodeFold[];
226
+ /**
227
+ * An overview strip above the lines: one bar per line (its height the mark's `heat`, its color the mark's tone),
228
+ * a band under it over the lines outside folds, and a bracket over the lines in view. A click or drag on it
229
+ * scrolls the code there.
230
+ */
231
+ overview?: boolean;
194
232
  }
195
233
  export interface TspDiffHunk {
196
234
  oldStart: number;
@@ -928,6 +966,27 @@ export interface TspChartProps {
928
966
  /** Pixel-free size hint: cell size step for heatmaps, height in lines for bars/spark. */
929
967
  size?: "sm" | "md" | "lg";
930
968
  }
969
+ /** Engine-produced shell presentation; hosts render rows and forward controls, never syntax or history. */
970
+ export interface TspShellProps {
971
+ /** Canonical semantic presentation, shared with the ANSI inspector. */
972
+ presentation: ShellVizPresentation;
973
+ /** Show replay controls only in the explicitly opened inspector. */
974
+ inspector?: boolean;
975
+ /** Changed only by explicit seek/reset/live-mode transitions, clearing native highlight trails. */
976
+ replayEpoch?: number;
977
+ /** This mounted call received a real execution-start event, not a settled historical load. */
978
+ liveOrigin?: boolean;
979
+ /** Working directory shown ahead of the script when it differs from the project's. */
980
+ cwd?: string;
981
+ lang?: "bash" | "zsh";
982
+ /**
983
+ * Clamp the command to its first `lines` drawn lines under a "N more lines" button; gives way inside an open
984
+ * disclosure, and never applies in the inspector. The Raw/Pseudo switch and menu stay on the first line.
985
+ */
986
+ preview?: {
987
+ lines: number;
988
+ };
989
+ }
931
990
  /** Kind-specific props, indexed by kind. */
932
991
  export interface TspPropsByKind {
933
992
  col: TspColProps;
@@ -975,6 +1034,7 @@ export interface TspPropsByKind {
975
1034
  chart: TspChartProps;
976
1035
  meter: TspMeterProps;
977
1036
  effort: TspEffortProps;
1037
+ shell: TspShellProps;
978
1038
  }
979
1039
  /**
980
1040
  * Props of a node of kind `K`: its kind-specific props plus the common ones.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "@linxiraos/pi-wire",
4
- "version": "1.4.11",
4
+ "version": "1.4.12",
5
5
  "description": "Shared wire protocol types for omp packages",
6
6
  "homepage": "https://linxira-os.github.io/zeta/",
7
7
  "author": "Can Boluk",
@@ -24,7 +24,7 @@
24
24
  "types": "./dist/types/index.d.ts",
25
25
  "scripts": {
26
26
  "check": "oxlint . && oxfmt --check --no-error-on-unmatched-pattern 'src/**/*.{ts,tsx}' '{test,bench,examples,scripts}/**/*.ts' '*.ts' && bun run check:types",
27
- "check:types": "tsc -p tsconfig.json --noEmit",
27
+ "check:types": "bun check --no-script -p tsconfig.json",
28
28
  "lint": "oxlint .",
29
29
  "fix": "oxlint --fix --fix-suggestions . && bun run fmt",
30
30
  "fmt": "oxfmt --no-error-on-unmatched-pattern 'src/**/*.{ts,tsx}' '{test,bench,examples,scripts}/**/*.ts' '*.ts'"