@chances-ai/tui 15.0.0 → 17.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.
- package/dist/app.d.ts +1 -1
- package/dist/app.d.ts.map +1 -1
- package/dist/app.js +54 -9
- package/dist/app.js.map +1 -1
- package/dist/code-view.js +1 -1
- package/dist/code-view.js.map +1 -1
- package/dist/diff-view.js +1 -1
- package/dist/diff-view.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/select-multi.d.ts +36 -0
- package/dist/select-multi.d.ts.map +1 -0
- package/dist/select-multi.js +104 -0
- package/dist/select-multi.js.map +1 -0
- package/dist/select.d.ts +5 -1
- package/dist/select.d.ts.map +1 -1
- package/dist/select.js +14 -6
- package/dist/select.js.map +1 -1
- package/dist/theme.d.ts +15 -101
- package/dist/theme.d.ts.map +1 -1
- package/dist/theme.js +18 -109
- package/dist/theme.js.map +1 -1
- package/dist/tool-message.js +1 -1
- package/dist/tool-message.js.map +1 -1
- package/dist/user-question.d.ts +26 -0
- package/dist/user-question.d.ts.map +1 -0
- package/dist/user-question.js +140 -0
- package/dist/user-question.js.map +1 -0
- package/package.json +7 -6
- package/dist/diff-model.d.ts +0 -64
- package/dist/diff-model.d.ts.map +0 -1
- package/dist/diff-model.js +0 -156
- package/dist/diff-model.js.map +0 -1
- package/dist/frame-scheduler.d.ts +0 -44
- package/dist/frame-scheduler.d.ts.map +0 -1
- package/dist/frame-scheduler.js +0 -58
- package/dist/frame-scheduler.js.map +0 -1
- package/dist/highlight-to-segments.d.ts +0 -18
- package/dist/highlight-to-segments.d.ts.map +0 -1
- package/dist/highlight-to-segments.js +0 -224
- package/dist/highlight-to-segments.js.map +0 -1
- package/dist/tool-line.d.ts +0 -33
- package/dist/tool-line.d.ts.map +0 -1
- package/dist/tool-line.js +0 -168
- package/dist/tool-line.js.map +0 -1
- package/dist/view-model.d.ts +0 -219
- package/dist/view-model.d.ts.map +0 -1
- package/dist/view-model.js +0 -460
- package/dist/view-model.js.map +0 -1
package/dist/tool-line.js
DELETED
|
@@ -1,168 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* (5.9 / v14) Pure view-side tool-call label. Renders `⏺ Name(argSummary)` —
|
|
3
|
-
* see `tool-message.tsx`. This is a MINIMAL, NON-AUTHORITATIVE label (codex R1
|
|
4
|
-
* SHOULD-1): it only echoes the call's own args (available on the `tool:call`
|
|
5
|
-
* bus event, which carries no `ToolContext`). It deliberately does NOT claim
|
|
6
|
-
* create-vs-overwrite, byte counts, or diffs — that fidelity comes only from
|
|
7
|
-
* the richer permission summary (`tool:permission`), which the view stashes
|
|
8
|
-
* and renders under the `⎿` branch (see `view-model.ts`).
|
|
9
|
-
*
|
|
10
|
-
* Pure `(name, args) => string`, so it is fully unit-testable without Ink.
|
|
11
|
-
*/
|
|
12
|
-
import { homedir } from "node:os";
|
|
13
|
-
/** Read a string property from an unknown JSON args bag, or "" if absent. */
|
|
14
|
-
function s(args, key) {
|
|
15
|
-
if (args && typeof args === "object" && key in args) {
|
|
16
|
-
const v = args[key];
|
|
17
|
-
if (typeof v === "string")
|
|
18
|
-
return v;
|
|
19
|
-
if (typeof v === "number" || typeof v === "boolean")
|
|
20
|
-
return String(v);
|
|
21
|
-
}
|
|
22
|
-
return "";
|
|
23
|
-
}
|
|
24
|
-
/** Collapse a leading home-dir to `~`. `home` is injectable for deterministic
|
|
25
|
-
* tests; defaults to the real home directory. Handles both POSIX (`/`) and
|
|
26
|
-
* Windows (`\`) separators after the home prefix (codex R2 NICE-8). */
|
|
27
|
-
export function homeRelative(path, home = homedir()) {
|
|
28
|
-
if (!path || !home)
|
|
29
|
-
return path;
|
|
30
|
-
if (path === home)
|
|
31
|
-
return "~";
|
|
32
|
-
if (path.startsWith(`${home}/`) || path.startsWith(`${home}\\`)) {
|
|
33
|
-
return `~${path.slice(home.length)}`;
|
|
34
|
-
}
|
|
35
|
-
return path;
|
|
36
|
-
}
|
|
37
|
-
/** Truncate a single-line value for the inline label. */
|
|
38
|
-
function clip(text, max = 60) {
|
|
39
|
-
const oneLine = text.replace(/\s+/g, " ").trim();
|
|
40
|
-
return oneLine.length <= max ? oneLine : `${oneLine.slice(0, max - 1)}…`;
|
|
41
|
-
}
|
|
42
|
-
/** Display name for a tool: builtin names verbatim; `mcp__<server>__<tool>`
|
|
43
|
-
* shown as `<server›>`. Edit/write get a claude-code-style verb. */
|
|
44
|
-
export function toolDisplayName(name) {
|
|
45
|
-
const mcp = parseMcpName(name);
|
|
46
|
-
if (mcp)
|
|
47
|
-
return mcp.server;
|
|
48
|
-
switch (name) {
|
|
49
|
-
case "edit":
|
|
50
|
-
return "Edit";
|
|
51
|
-
case "write":
|
|
52
|
-
return "Write";
|
|
53
|
-
case "read":
|
|
54
|
-
return "Read";
|
|
55
|
-
case "bash":
|
|
56
|
-
return "Bash";
|
|
57
|
-
case "grep":
|
|
58
|
-
return "Grep";
|
|
59
|
-
case "glob":
|
|
60
|
-
return "Glob";
|
|
61
|
-
case "diff":
|
|
62
|
-
return "Diff";
|
|
63
|
-
case "web_fetch":
|
|
64
|
-
return "Fetch";
|
|
65
|
-
case "task":
|
|
66
|
-
return "Task";
|
|
67
|
-
case "lsp":
|
|
68
|
-
return "Lsp";
|
|
69
|
-
case "pty":
|
|
70
|
-
return "Pty";
|
|
71
|
-
case "memory_save":
|
|
72
|
-
return "Memory";
|
|
73
|
-
case "memory_delete":
|
|
74
|
-
return "Memory";
|
|
75
|
-
case "memory_list":
|
|
76
|
-
return "Memory";
|
|
77
|
-
default:
|
|
78
|
-
return name;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
/** `mcp__<server>__<tool>` → `{server, tool}`; null for non-MCP or malformed
|
|
82
|
-
* names (empty server — codex R2 NICE-9). A `mcp__<server>` with no `__tool`
|
|
83
|
-
* is allowed (server-level), but an empty server component is rejected. */
|
|
84
|
-
export function parseMcpName(name) {
|
|
85
|
-
if (!name.startsWith("mcp__"))
|
|
86
|
-
return null;
|
|
87
|
-
const rest = name.slice("mcp__".length);
|
|
88
|
-
const sep = rest.indexOf("__");
|
|
89
|
-
const server = sep < 0 ? rest : rest.slice(0, sep);
|
|
90
|
-
if (server.length === 0)
|
|
91
|
-
return null;
|
|
92
|
-
return { server, tool: sep < 0 ? "" : rest.slice(sep + 2) };
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* The parenthesized argument summary for the header. Empty string ⇒ the header
|
|
96
|
-
* renders just `⏺ Name` with no parens.
|
|
97
|
-
*/
|
|
98
|
-
export function formatToolCall(name, args, opts) {
|
|
99
|
-
const home = opts?.home;
|
|
100
|
-
const rel = (p) => homeRelative(p, home ?? homedir());
|
|
101
|
-
const mcp = parseMcpName(name);
|
|
102
|
-
if (mcp)
|
|
103
|
-
return mcp.tool;
|
|
104
|
-
switch (name) {
|
|
105
|
-
case "read":
|
|
106
|
-
case "edit":
|
|
107
|
-
case "write":
|
|
108
|
-
case "diff":
|
|
109
|
-
return clip(rel(s(args, "path")));
|
|
110
|
-
case "bash": {
|
|
111
|
-
const desc = s(args, "description");
|
|
112
|
-
return clip(desc || s(args, "command"));
|
|
113
|
-
}
|
|
114
|
-
case "grep": {
|
|
115
|
-
const pattern = s(args, "pattern");
|
|
116
|
-
const path = s(args, "path");
|
|
117
|
-
return clip(path ? `${pattern} in ${rel(path)}` : pattern);
|
|
118
|
-
}
|
|
119
|
-
case "glob": {
|
|
120
|
-
const pattern = s(args, "pattern");
|
|
121
|
-
const path = s(args, "path");
|
|
122
|
-
return clip(path ? `${pattern} in ${rel(path)}` : pattern);
|
|
123
|
-
}
|
|
124
|
-
case "web_fetch":
|
|
125
|
-
return clip(s(args, "url"));
|
|
126
|
-
case "task": {
|
|
127
|
-
const sub = s(args, "subagent_type");
|
|
128
|
-
const desc = s(args, "description");
|
|
129
|
-
return clip([sub, desc].filter(Boolean).join(": ") || desc || sub);
|
|
130
|
-
}
|
|
131
|
-
case "lsp": {
|
|
132
|
-
const op = s(args, "op");
|
|
133
|
-
const path = s(args, "path");
|
|
134
|
-
const query = s(args, "query");
|
|
135
|
-
const detail = path ? rel(path) : query;
|
|
136
|
-
return clip([op, detail].filter(Boolean).join(" "));
|
|
137
|
-
}
|
|
138
|
-
case "pty": {
|
|
139
|
-
const op = s(args, "op");
|
|
140
|
-
const cmd = s(args, "command");
|
|
141
|
-
return clip([op, cmd].filter(Boolean).join(" "));
|
|
142
|
-
}
|
|
143
|
-
case "memory_save":
|
|
144
|
-
case "memory_delete":
|
|
145
|
-
return clip(s(args, "name"));
|
|
146
|
-
case "memory_list":
|
|
147
|
-
return clip(s(args, "scope"));
|
|
148
|
-
default:
|
|
149
|
-
return compactArgs(args);
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
/** Fallback for unknown tools: a compact `key=value` join of scalar args. */
|
|
153
|
-
function compactArgs(args) {
|
|
154
|
-
if (!args || typeof args !== "object")
|
|
155
|
-
return "";
|
|
156
|
-
const parts = [];
|
|
157
|
-
for (const [k, v] of Object.entries(args)) {
|
|
158
|
-
if (v === null || v === undefined)
|
|
159
|
-
continue;
|
|
160
|
-
if (typeof v === "object")
|
|
161
|
-
continue; // skip nested for a one-liner
|
|
162
|
-
parts.push(`${k}=${String(v)}`);
|
|
163
|
-
if (parts.length >= 3)
|
|
164
|
-
break;
|
|
165
|
-
}
|
|
166
|
-
return clip(parts.join(" "));
|
|
167
|
-
}
|
|
168
|
-
//# sourceMappingURL=tool-line.js.map
|
package/dist/tool-line.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tool-line.js","sourceRoot":"","sources":["../src/tool-line.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAElC,6EAA6E;AAC7E,SAAS,CAAC,CAAC,IAAa,EAAE,GAAW;IACnC,IAAI,IAAI,IAAI,OAA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provalMode, ApprovalState, EventBus } from "@chances-ai/runtime";
|
|
2
|
-
import type { PermissionDecision, PermissionRequest } 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: PermissionDecision): void;
|
|
206
|
-
/** The current session approval mode (`"default"` when unwired). */
|
|
207
|
-
get approvalMode(): ApprovalMode;
|
|
208
|
-
/**
|
|
209
|
-
* Shift+Tab handler. Advances the cycle; cycling INTO `yolo` without a prior
|
|
210
|
-
* confirmation opens the confirm overlay instead of switching (the typed
|
|
211
|
-
* `/approval yolo` path counts as consent and skips this — see
|
|
212
|
-
* `setApprovalMode`).
|
|
213
|
-
*/
|
|
214
|
-
cycleApprovalMode(): void;
|
|
215
|
-
/** Resolve the yolo confirm overlay. `confirm` latches yolo for the session. */
|
|
216
|
-
resolveYoloConfirm(confirm: boolean): void;
|
|
217
|
-
}
|
|
218
|
-
export {};
|
|
219
|
-
//# sourceMappingURL=view-model.d.ts.map
|
package/dist/view-model.d.ts.map
DELETED
|
@@ -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,qBAAqB,CAAC;AACjF,OAAO,KAAK,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAC/E,OAAO,EAEL,KAAK,cAAc,EAEpB,MAAM,sBAAsB,CAAC;AAG9B;;oFAEoF;AACpF,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAI1D;AAED,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,WAAW,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,CAAC;AACxE,MAAM,WAAW,IAAI;IACnB,IAAI,EAAE,QAAQ,CAAC;IACf;yCACqC;IACrC,IAAI,EAAE,MAAM,CAAC;IACb,iEAAiE;IACjE,EAAE,CAAC,EAAE,OAAO,CAAC;IACb,0EAA0E;IAC1E,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,oEAAoE;IACpE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,uDAAuD;IACvD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,2EAA2E;IAC3E,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,+EAA+E;IAC/E,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,UAAU,OAAO;IACf,GAAG,EAAE,iBAAiB,CAAC;IACvB,OAAO,EAAE,CAAC,QAAQ,EAAE,kBAAkB,KAAK,IAAI,CAAC;CACjD;AAOD,MAAM,WAAW,oBAAoB;IACnC;6EACyE;IACzE,SAAS,C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