@chances-ai/tui 16.0.0 → 18.0.0

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.
Files changed (47) hide show
  1. package/dist/app.d.ts +1 -1
  2. package/dist/app.d.ts.map +1 -1
  3. package/dist/app.js +2 -2
  4. package/dist/app.js.map +1 -1
  5. package/dist/code-view.js +1 -1
  6. package/dist/code-view.js.map +1 -1
  7. package/dist/diff-view.js +1 -1
  8. package/dist/diff-view.js.map +1 -1
  9. package/dist/help-view.d.ts +46 -0
  10. package/dist/help-view.d.ts.map +1 -0
  11. package/dist/help-view.js +52 -0
  12. package/dist/help-view.js.map +1 -0
  13. package/dist/index.d.ts +5 -4
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/index.js +5 -3
  16. package/dist/index.js.map +1 -1
  17. package/dist/select.d.ts +5 -0
  18. package/dist/select.d.ts.map +1 -1
  19. package/dist/select.js +11 -1
  20. package/dist/select.js.map +1 -1
  21. package/dist/theme.d.ts +15 -101
  22. package/dist/theme.d.ts.map +1 -1
  23. package/dist/theme.js +18 -109
  24. package/dist/theme.js.map +1 -1
  25. package/dist/tool-message.js +1 -1
  26. package/dist/tool-message.js.map +1 -1
  27. package/package.json +6 -5
  28. package/dist/diff-model.d.ts +0 -64
  29. package/dist/diff-model.d.ts.map +0 -1
  30. package/dist/diff-model.js +0 -156
  31. package/dist/diff-model.js.map +0 -1
  32. package/dist/frame-scheduler.d.ts +0 -44
  33. package/dist/frame-scheduler.d.ts.map +0 -1
  34. package/dist/frame-scheduler.js +0 -58
  35. package/dist/frame-scheduler.js.map +0 -1
  36. package/dist/highlight-to-segments.d.ts +0 -18
  37. package/dist/highlight-to-segments.d.ts.map +0 -1
  38. package/dist/highlight-to-segments.js +0 -224
  39. package/dist/highlight-to-segments.js.map +0 -1
  40. package/dist/tool-line.d.ts +0 -33
  41. package/dist/tool-line.d.ts.map +0 -1
  42. package/dist/tool-line.js +0 -168
  43. package/dist/tool-line.js.map +0 -1
  44. package/dist/view-model.d.ts +0 -226
  45. package/dist/view-model.d.ts.map +0 -1
  46. package/dist/view-model.js +0 -488
  47. package/dist/view-model.js.map +0 -1
@@ -1,226 +0,0 @@
1
- import type { ApprovalMode, ApprovalState, EventBus } from "@chances-ai/runtime";
2
- import type { AuthorizationDecision, PermissionDecision, PermissionRequest, QuestionDecision } from "@chances-ai/tools";
3
- import { type FrameScheduler } from "./frame-scheduler.js";
4
- /** (5.9) Extract the `linesDiff` block (from the first `@@ -d` hunk header to
5
- * the end) out of a write/edit permission summary, or null when the summary
6
- * carries no diff (single-line edits, "diff preview skipped", non-write tools). */
7
- export declare function extractDiff(summary: string): string | null;
8
- export type LineKind = "user" | "assistant" | "tool" | "error" | "info";
9
- export interface Line {
10
- kind: LineKind;
11
- /** user/assistant/info/error body — OR, for a `tool` line, the pure arg
12
- * summary from `formatToolCall`. */
13
- text: string;
14
- /** `tool`: undefined while running, then the result's ok/err. */
15
- ok?: boolean;
16
- /** `tool`: raw tool name (drives the ⏺ header + display-name mapping). */
17
- toolName?: string;
18
- /** `tool`: correlates the call / permission / result bus events. */
19
- callId?: string;
20
- /** `tool`: result preview shown under the ⎿ branch. */
21
- result?: string;
22
- /** `tool`: raw `linesDiff` text for write/edit, rendered under ⎿ (5.9). */
23
- diff?: string;
24
- /** `tool`: whether `diff` is whole-file-anchored (write) vs snippet (edit). */
25
- anchored?: boolean;
26
- }
27
- interface Pending {
28
- req: PermissionRequest;
29
- resolve: (decision: PermissionDecision) => void;
30
- }
31
- export interface ChatViewModelOptions {
32
- /** (5.8) Injectable frame coalescer. Production uses the default ~16 ms
33
- * `setTimeout` batcher; tests inject a manual queue for determinism. */
34
- scheduler?: FrameScheduler;
35
- /** (5.8) See `config.tui.toolResultPreviewLines`. Default 12. */
36
- toolResultPreviewLines?: number;
37
- }
38
- /**
39
- * Observable view-model. The Ink tree subscribes via useSyncExternalStore and
40
- * never touches domain objects directly — the only inputs are bus events and the
41
- * permission resolver. This is the seam that keeps the UI decoupled from core.
42
- *
43
- * (5.8) Rendering is split into a committed prefix (frozen scrollback fed to
44
- * Ink `<Static>`, rendered once) and a small live tail (re-rendered each
45
- * frame). Streamed `assistant:delta` re-renders are coalesced to one per frame
46
- * via {@link FrameScheduler}; every structural event force-flushes immediately.
47
- */
48
- export declare class ChatViewModel {
49
- private readonly approval?;
50
- lines: Line[];
51
- busy: boolean;
52
- pending: Pending | null;
53
- /** (5.3) True while the Shift+Tab-into-yolo confirmation overlay is up.
54
- * app.tsx renders the red confirm box; `resolveYoloConfirm` clears it. */
55
- yoloConfirmPending: boolean;
56
- /**
57
- * (5.8) Count of leading `lines` that are committed (frozen). Lines
58
- * `[0, committedCount)` are append-only — an index's content never changes
59
- * once committed — and feed Ink `<Static>`. Lines `[committedCount, end)`
60
- * are the live tail. Advanced ONLY forward (monotonic) so `<Static>` never
61
- * has to un-render anything. The only line that ever mutates in place is an
62
- * open assistant line (text grows per delta) and it is always live.
63
- */
64
- committedCount: number;
65
- /**
66
- * (5.8) Bumped by `clearLines()` and used as the Ink `<Static key>`. Ink
67
- * `<Static>` can't be emptied by replacing its items, so `/clear` remounts
68
- * it under a fresh key (needs `ink >= 7.0.3`, which fixes the
69
- * remount-with-different-key drop-new-items bug).
70
- */
71
- clearGeneration: number;
72
- private version;
73
- private readonly listeners;
74
- private assistantOpen;
75
- private busUnsubscribers;
76
- private readonly scheduler;
77
- private readonly toolResultPreviewLines;
78
- /** Non-null while a coalesced delta frame is queued (see `scheduleBump`). */
79
- private pendingFrame;
80
- /**
81
- * (5.9) Diff blocks parsed from `tool:permission` summaries, keyed by callId,
82
- * awaiting their `tool:result` so they can be attached to the tool line and
83
- * rendered under the `⎿` branch. Emitted before `gate.evaluate` for every
84
- * write/edit call (engine.ts:763) — so this populates even under
85
- * auto-edit/yolo, giving transcript diffs in all approval modes with zero
86
- * engine/contract change. Cleared on detach/clear so it can't leak.
87
- */
88
- private readonly diffStash;
89
- /**
90
- * (5.3) Optional session approval-mode holder. When wired (interactive
91
- * `chat`), the footer reflects `approvalMode` and Shift+Tab / `/approval`
92
- * mutate it. Left undefined in tests that don't exercise modes — every
93
- * approval method then no-ops and `approvalMode` reads `"default"`.
94
- *
95
- * (5.8) `options` injects the frame scheduler + tool-result preview length;
96
- * both default so existing callers (`new ChatViewModel()`,
97
- * `new ChatViewModel(approval)`) keep working unchanged.
98
- */
99
- constructor(approval?: ApprovalState | undefined, options?: ChatViewModelOptions);
100
- subscribe: (fn: () => void) => (() => void);
101
- getSnapshot: () => number;
102
- /**
103
- * (5.8) The frozen scrollback prefix — fed to Ink `<Static>` and rendered
104
- * once. Guaranteed append-only: the element at index `i` never changes once
105
- * it appears here. A fresh array is returned each call, but the prefix
106
- * content is stable, which is all `<Static>` relies on.
107
- */
108
- committedLines(): Line[];
109
- /** (5.8) The live tail re-rendered each frame: the open assistant line while
110
- * streaming, or an in-flight tool / tool-result line awaiting its terminal
111
- * event. Usually 0–1 entries. */
112
- liveLines(): Line[];
113
- /** (5.9) The still-live `tool` line for a callId (normally the last line).
114
- * Returns a mutable ref so `tool:result` can fill it in place — safe because
115
- * it is in the live region (index ≥ committedCount), not yet committed. */
116
- private findLiveTool;
117
- /**
118
- * (5.9 codex R2 MUST-1) Advance `committedCount` toward `target` but NEVER
119
- * past the earliest still-running tool line (`kind:"tool"` with `ok ===
120
- * undefined`). A sync/background subagent emits its own `tool:call` /
121
- * `assistant:delta` frames on the SAME bus BETWEEN a parent `task` tool's
122
- * call and its result; without this clamp those frames would commit the
123
- * parent's tool line, after which `findLiveTool` could no longer fill it
124
- * (mutating a committed line breaks the `<Static>` append-only invariant) and
125
- * the parent result would spawn a duplicate empty block. Keeping every
126
- * unresolved tool line live until its result arrives makes the fill always
127
- * append-only-safe. `turn:end` force-commits unconditionally (the turn is
128
- * over). Monotonic: `target ≥ committedCount`, and the result is in
129
- * `[committedCount, target]`.
130
- */
131
- private commitThrough;
132
- private bump;
133
- /**
134
- * (5.8) Coalesce a streamed-token re-render onto the next frame. The first
135
- * delta in a window arms the scheduler; later deltas in the same window are
136
- * no-ops (the text is already accumulated on the line), so N tokens cause
137
- * at most one render per frame instead of N.
138
- */
139
- private scheduleBump;
140
- /** (5.8) Drop a queued delta frame if one is pending. */
141
- private cancelPendingBump;
142
- /**
143
- * (5.8) Immediate notify that first drops any pending coalesced delta frame.
144
- * Used by every structural mutation (finished message, tool call/result,
145
- * turn boundary, user action) so the UI never renders a structural change
146
- * behind a stale token-stream frame, and a cancelled frame can't fire into a
147
- * later epoch.
148
- */
149
- private forceFlush;
150
- /**
151
- * Push a standalone, immutable line and commit everything (it and any prior
152
- * live tail are terminal-on-creation).
153
- *
154
- * Closing `assistantOpen` here means a standalone line pushed while a stream
155
- * is open ends that stream: the next `assistant:delta` opens a FRESH line
156
- * rather than appending to the committed one — so the committed line is
157
- * genuinely final (append-only holds; see the interleaving regression test).
158
- * That a mid-stream user submit / mode-cycle visually splits the assistant
159
- * message is a pre-existing interaction behavior (NOT a v13 regression — the
160
- * pre-v13 `pushUser` closed the stream the same way); richer mid-turn input
161
- * handling (queueing) is a v15 interaction-model concern, out of v13 scope.
162
- */
163
- private pushCommitted;
164
- pushUser(text: string): void;
165
- pushInfo(text: string): void;
166
- pushError(text: string): void;
167
- /** Empties the rendered scrollback — used by `/clear` so the user sees a
168
- * fresh view alongside the session.clearTurns() that drops the conversation
169
- * history. The view-model and the underlying session are intentionally
170
- * separate operations; the slash command sequences both.
171
- *
172
- * (5.8) Because Ink `<Static>` keeps everything ever handed to it, emptying
173
- * `lines` is not enough — `clearGeneration` is bumped so app.tsx can remount
174
- * `<Static>` under a fresh key. Any pending delta frame is dropped so it
175
- * can't fire into the cleared epoch. */
176
- clearLines(): void;
177
- attach(bus: EventBus): void;
178
- /**
179
- * (3.4 — codex Round-2 MUST-FIX #2) Once a VM is detached (engine
180
- * respawn via `/resume`, `/clear` shouldn't detach but if a future
181
- * caller does), any in-flight `requestPermission` is rejected with
182
- * a synthetic "denied" decision so the closing-over-stale-resolver
183
- * call sites (notably the background-task child engine that holds
184
- * `deps.gate` from before the respawn) don't hang waiting for a
185
- * prompt that will never reach a user. Any *future* call to
186
- * `requestPermission` on this detached VM short-circuits the same
187
- * way — same reasoning.
188
- *
189
- * (5.8) Also drops any pending coalesced frame so a scheduled bump
190
- * can't fire into a remounted/stale epoch.
191
- */
192
- detach(): void;
193
- private detached;
194
- /** Returned to the PermissionGate as its resolver. After `detach()`,
195
- * any call resolves denied synchronously — see `detach()` docstring. */
196
- requestPermission: (req: PermissionRequest) => Promise<PermissionDecision>;
197
- /**
198
- * (5.3) Resolve the open permission prompt with a full decision:
199
- * - `{allow:true}` — approve once (not remembered).
200
- * - `{allow:true, remember:true}` — approve & don't ask again (the gate
201
- * caches it even for un-scoped tools like file-write).
202
- * - `{allow:false}` — plain deny.
203
- * - `{allow:false, feedback}` — deny + relay the user's note to the model.
204
- */
205
- resolvePermission(decision: AuthorizationDecision): void;
206
- /**
207
- * (5.10b) Resolve an open QUESTION prompt with the user's answers (or a
208
- * decline). Mirrors {@link resolvePermission} for the `question` pending
209
- * variant — the `ask_user_question` tool turns the decision into the
210
- * model-facing tool result.
211
- */
212
- resolveQuestion(decision: QuestionDecision): void;
213
- /** The current session approval mode (`"default"` when unwired). */
214
- get approvalMode(): ApprovalMode;
215
- /**
216
- * Shift+Tab handler. Advances the cycle; cycling INTO `yolo` without a prior
217
- * confirmation opens the confirm overlay instead of switching (the typed
218
- * `/approval yolo` path counts as consent and skips this — see
219
- * `setApprovalMode`).
220
- */
221
- cycleApprovalMode(): void;
222
- /** Resolve the yolo confirm overlay. `confirm` latches yolo for the session. */
223
- resolveYoloConfirm(confirm: boolean): void;
224
- }
225
- export {};
226
- //# sourceMappingURL=view-model.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"view-model.d.ts","sourceRoot":"","sources":["../src/view-model.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,qBAA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