xiaotime 0.5.12 → 0.6.1
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/ansi_tags.js +1 -4
- package/dist/ansi_tags.js.map +1 -1
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +11 -50
- package/dist/auth.js.map +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +9 -11
- package/dist/config.js.map +1 -1
- package/dist/display.js +164 -201
- package/dist/display.js.map +1 -1
- package/dist/index.js +29 -25
- package/dist/index.js.map +1 -1
- package/dist/ink/App.d.ts +9 -0
- package/dist/ink/App.d.ts.map +1 -0
- package/dist/ink/App.js +152 -0
- package/dist/ink/App.js.map +1 -0
- package/dist/ink/execToolInk.d.ts +13 -0
- package/dist/ink/execToolInk.d.ts.map +1 -0
- package/dist/ink/execToolInk.js +239 -0
- package/dist/ink/execToolInk.js.map +1 -0
- package/dist/ink/runSessionInk.d.ts +2 -0
- package/dist/ink/runSessionInk.d.ts.map +1 -0
- package/dist/ink/runSessionInk.js +184 -0
- package/dist/ink/runSessionInk.js.map +1 -0
- package/dist/ink/store.d.ts +102 -0
- package/dist/ink/store.d.ts.map +1 -0
- package/dist/ink/store.js +144 -0
- package/dist/ink/store.js.map +1 -0
- package/dist/input_box.js +9 -16
- package/dist/input_box.js.map +1 -1
- package/dist/projectContext.d.ts +38 -0
- package/dist/projectContext.d.ts.map +1 -0
- package/dist/projectContext.js +135 -0
- package/dist/projectContext.js.map +1 -0
- package/dist/session.js +8 -14
- package/dist/session.js.map +1 -1
- package/dist/session_match.js +1 -4
- package/dist/session_match.js.map +1 -1
- package/dist/settings.js +8 -48
- package/dist/settings.js.map +1 -1
- package/dist/sidebar.js +13 -20
- package/dist/sidebar.js.map +1 -1
- package/dist/tool_result_client.js +6 -11
- package/dist/tool_result_client.js.map +1 -1
- package/dist/tools.d.ts +5 -0
- package/dist/tools.d.ts.map +1 -1
- package/dist/tools.js +33 -71
- package/dist/tools.js.map +1 -1
- package/dist/ui_state.js +22 -63
- package/dist/ui_state.js.map +1 -1
- package/dist/ws.d.ts.map +1 -1
- package/dist/ws.js +77 -111
- package/dist/ws.js.map +1 -1
- package/package.json +8 -2
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ink tool executor — the render-safe counterpart to tools.ts::executeTool.
|
|
3
|
+
*
|
|
4
|
+
* executeTool interleaves execution with stdout writes (console.log, the styled
|
|
5
|
+
* diff/approval boxes) and reads approval over readline — both incompatible
|
|
6
|
+
* with Ink, which owns stdout + stdin. This runs the same tools but routes all
|
|
7
|
+
* display through the session store and all approval through the Ink approval
|
|
8
|
+
* surface (store.requestApproval → the <App> menu).
|
|
9
|
+
*
|
|
10
|
+
* The security-critical logic is SHARED, not duplicated:
|
|
11
|
+
* - allowlist match / pattern derivation / persistence → settings.ts
|
|
12
|
+
* - path resolution, recursive listing, globbing, the list cap → tools.ts
|
|
13
|
+
* Only the thin per-tool orchestration is restated here. Once the Ink layer is
|
|
14
|
+
* the default, tools.ts::executeTool and this file collapse into one execution
|
|
15
|
+
* path behind a UI interface (the classic readline path goes away).
|
|
16
|
+
*
|
|
17
|
+
* Note: client tools execute synchronously (execSync/writeFileSync), matching
|
|
18
|
+
* the classic client; the event loop blocks during a tool, so the live spinner
|
|
19
|
+
* doesn't animate mid-exec. Approval, by contrast, is async — the UI stays
|
|
20
|
+
* responsive while it waits on the user.
|
|
21
|
+
*/
|
|
22
|
+
import * as fs from "fs";
|
|
23
|
+
import * as path from "path";
|
|
24
|
+
import * as child_process from "child_process";
|
|
25
|
+
import { resolvePath, getSessionCwd, listRecursive, globToRegex, _listDirectoryMax, } from "../tools.js";
|
|
26
|
+
import { loadAllowlist, matchAllowlist, derivePattern, appendAllowlist, } from "../settings.js";
|
|
27
|
+
import * as store from "./store.js";
|
|
28
|
+
function detail(input) {
|
|
29
|
+
if (typeof input.path === "string")
|
|
30
|
+
return input.path;
|
|
31
|
+
if (typeof input.command === "string")
|
|
32
|
+
return input.command;
|
|
33
|
+
if (typeof input.query === "string")
|
|
34
|
+
return input.query;
|
|
35
|
+
if (typeof input.message === "string")
|
|
36
|
+
return input.message;
|
|
37
|
+
return "";
|
|
38
|
+
}
|
|
39
|
+
/** A bounded preview of what write_file will write — not a full positional diff. */
|
|
40
|
+
function writePreview(oldContent, newContent) {
|
|
41
|
+
const CAP = 20;
|
|
42
|
+
const out = [];
|
|
43
|
+
if (oldContent !== null) {
|
|
44
|
+
out.push({ op: "-", text: `(replacing ${oldContent.split("\n").length} existing lines)` });
|
|
45
|
+
}
|
|
46
|
+
const lines = newContent.split("\n");
|
|
47
|
+
for (const l of lines.slice(0, CAP))
|
|
48
|
+
out.push({ op: "+", text: l });
|
|
49
|
+
if (lines.length > CAP)
|
|
50
|
+
out.push({ op: "+", text: `… (${lines.length - CAP} more lines)` });
|
|
51
|
+
return out;
|
|
52
|
+
}
|
|
53
|
+
function rejected(toolUseId, decision) {
|
|
54
|
+
const tail = decision.rejectReason ? `: ${decision.rejectReason}` : ".";
|
|
55
|
+
return { tool_use_id: toolUseId, content: `Rejected by user${tail}`, is_error: false };
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Approval gate — allowlist first (auto-approve), else ask the user via the Ink
|
|
59
|
+
* surface; persist the derived pattern when they choose "don't ask again".
|
|
60
|
+
* Mirrors tools.ts::_gateApproval, sharing the same settings.ts allowlist API.
|
|
61
|
+
*/
|
|
62
|
+
async function gate(tool, input, approval) {
|
|
63
|
+
if (matchAllowlist(tool, input, loadAllowlist())) {
|
|
64
|
+
return { approved: true, allowlistRequested: false };
|
|
65
|
+
}
|
|
66
|
+
const decision = await store.requestApproval({ tool, ...approval });
|
|
67
|
+
if (decision.approved && decision.allowlistRequested) {
|
|
68
|
+
const pattern = derivePattern(tool, input);
|
|
69
|
+
if (pattern !== null) {
|
|
70
|
+
try {
|
|
71
|
+
appendAllowlist({ tool, pattern });
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
// non-fatal — allowlist persistence failure doesn't block the run
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return decision;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Execute one client-side tool call for the Ink session. Commits a tool line to
|
|
82
|
+
* history (✓/✗) and returns the result to POST back to the server.
|
|
83
|
+
*/
|
|
84
|
+
export async function execToolInk(call) {
|
|
85
|
+
const { tool_use_id, name, input } = call;
|
|
86
|
+
try {
|
|
87
|
+
switch (name) {
|
|
88
|
+
// ── read-only tools — no approval ──────────────────────────────────────
|
|
89
|
+
case "read_file": {
|
|
90
|
+
store.startTool({ id: tool_use_id, name, summary: detail(input) });
|
|
91
|
+
const filePath = resolvePath(input.path);
|
|
92
|
+
const content = fs.readFileSync(filePath, "utf-8");
|
|
93
|
+
const lines = content.split("\n");
|
|
94
|
+
const offset = (input.offset || 1) - 1;
|
|
95
|
+
const limit = input.limit;
|
|
96
|
+
const slice = limit ? lines.slice(offset, offset + limit) : lines.slice(offset);
|
|
97
|
+
store.finishTool();
|
|
98
|
+
return {
|
|
99
|
+
tool_use_id,
|
|
100
|
+
content: slice.map((l, i) => `${offset + i + 1}: ${l}`).join("\n"),
|
|
101
|
+
is_error: false,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
case "list_directory": {
|
|
105
|
+
store.startTool({ id: tool_use_id, name, summary: detail(input) });
|
|
106
|
+
const dirPath = resolvePath(input.path);
|
|
107
|
+
const pattern = input.pattern;
|
|
108
|
+
const recursive = input.recursive;
|
|
109
|
+
const cap = _listDirectoryMax();
|
|
110
|
+
let entries;
|
|
111
|
+
let truncated = false;
|
|
112
|
+
if (recursive) {
|
|
113
|
+
entries = listRecursive(dirPath, pattern, cap + 1);
|
|
114
|
+
if (entries.length > cap) {
|
|
115
|
+
entries = entries.slice(0, cap);
|
|
116
|
+
truncated = true;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
let raw = fs.readdirSync(dirPath).map((e) => {
|
|
121
|
+
const full = path.join(dirPath, e);
|
|
122
|
+
return fs.statSync(full).isDirectory() ? `${e}/` : e;
|
|
123
|
+
});
|
|
124
|
+
if (pattern) {
|
|
125
|
+
const regex = globToRegex(pattern);
|
|
126
|
+
raw = raw.filter((e) => regex.test(e));
|
|
127
|
+
}
|
|
128
|
+
if (raw.length > cap) {
|
|
129
|
+
entries = raw.slice(0, cap);
|
|
130
|
+
truncated = true;
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
entries = raw;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
const truncMarker = truncated
|
|
137
|
+
? `\n... (truncated to ${cap}; narrow with a pattern or list a subdirectory)`
|
|
138
|
+
: "";
|
|
139
|
+
store.finishTool();
|
|
140
|
+
return { tool_use_id, content: entries.join("\n") + truncMarker, is_error: false };
|
|
141
|
+
}
|
|
142
|
+
case "git_status": {
|
|
143
|
+
store.startTool({ id: tool_use_id, name, summary: "" });
|
|
144
|
+
const out = child_process.execSync("git status", { cwd: getSessionCwd(), encoding: "utf-8" });
|
|
145
|
+
store.finishTool();
|
|
146
|
+
return { tool_use_id, content: out, is_error: false };
|
|
147
|
+
}
|
|
148
|
+
case "git_diff": {
|
|
149
|
+
store.startTool({ id: tool_use_id, name, summary: input.staged ? "--staged" : "" });
|
|
150
|
+
const staged = input.staged;
|
|
151
|
+
const filePath = input.path;
|
|
152
|
+
const args = staged ? "diff --staged" : "diff";
|
|
153
|
+
const cmd = filePath ? `git ${args} -- ${filePath}` : `git ${args}`;
|
|
154
|
+
const out = child_process.execSync(cmd, { cwd: getSessionCwd(), encoding: "utf-8" });
|
|
155
|
+
store.finishTool();
|
|
156
|
+
return { tool_use_id, content: out || "(no changes)", is_error: false };
|
|
157
|
+
}
|
|
158
|
+
// ── prompting tools — approval gate ────────────────────────────────────
|
|
159
|
+
case "write_file": {
|
|
160
|
+
const filePath = resolvePath(input.path);
|
|
161
|
+
const newContent = input.content;
|
|
162
|
+
const oldContent = fs.existsSync(filePath) ? fs.readFileSync(filePath, "utf-8") : null;
|
|
163
|
+
const diff = writePreview(oldContent, newContent);
|
|
164
|
+
const decision = await gate("write_file", input, {
|
|
165
|
+
summary: filePath,
|
|
166
|
+
body: oldContent === null
|
|
167
|
+
? `New file — ${newContent.split("\n").length} lines`
|
|
168
|
+
: "Modifying existing file",
|
|
169
|
+
diff,
|
|
170
|
+
});
|
|
171
|
+
if (!decision.approved) {
|
|
172
|
+
store.startTool({ id: tool_use_id, name, summary: filePath });
|
|
173
|
+
store.finishTool({ error: true });
|
|
174
|
+
return rejected(tool_use_id, decision);
|
|
175
|
+
}
|
|
176
|
+
store.startTool({ id: tool_use_id, name, summary: filePath });
|
|
177
|
+
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
178
|
+
fs.writeFileSync(filePath, newContent, "utf-8");
|
|
179
|
+
store.finishTool({ diff });
|
|
180
|
+
return { tool_use_id, content: `File written: ${filePath}`, is_error: false };
|
|
181
|
+
}
|
|
182
|
+
case "shell_command": {
|
|
183
|
+
const command = input.command;
|
|
184
|
+
const cwd = input.cwd ? resolvePath(input.cwd) : getSessionCwd();
|
|
185
|
+
const decision = await gate("shell_command", input, {
|
|
186
|
+
summary: command,
|
|
187
|
+
body: `${command}\ncwd: ${cwd}`,
|
|
188
|
+
});
|
|
189
|
+
if (!decision.approved) {
|
|
190
|
+
store.startTool({ id: tool_use_id, name, summary: command });
|
|
191
|
+
store.finishTool({ error: true });
|
|
192
|
+
return rejected(tool_use_id, decision);
|
|
193
|
+
}
|
|
194
|
+
store.startTool({ id: tool_use_id, name, summary: command });
|
|
195
|
+
const result = child_process.execSync(command, {
|
|
196
|
+
cwd,
|
|
197
|
+
encoding: "utf-8",
|
|
198
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
199
|
+
timeout: 60000,
|
|
200
|
+
});
|
|
201
|
+
store.finishTool();
|
|
202
|
+
return { tool_use_id, content: result, is_error: false };
|
|
203
|
+
}
|
|
204
|
+
case "git_commit": {
|
|
205
|
+
const message = input.message;
|
|
206
|
+
const staged = child_process.execSync("git diff --staged --stat", {
|
|
207
|
+
cwd: getSessionCwd(),
|
|
208
|
+
encoding: "utf-8",
|
|
209
|
+
});
|
|
210
|
+
const decision = await gate("git_commit", input, {
|
|
211
|
+
summary: message,
|
|
212
|
+
body: `Message: ${message}\n\nStaged:\n${staged}`,
|
|
213
|
+
});
|
|
214
|
+
if (!decision.approved) {
|
|
215
|
+
store.startTool({ id: tool_use_id, name, summary: message });
|
|
216
|
+
store.finishTool({ error: true });
|
|
217
|
+
return rejected(tool_use_id, decision);
|
|
218
|
+
}
|
|
219
|
+
store.startTool({ id: tool_use_id, name, summary: message });
|
|
220
|
+
const out = child_process.execSync(`git commit -m ${JSON.stringify(message)}`, {
|
|
221
|
+
cwd: getSessionCwd(),
|
|
222
|
+
encoding: "utf-8",
|
|
223
|
+
});
|
|
224
|
+
store.finishTool();
|
|
225
|
+
return { tool_use_id, content: out, is_error: false };
|
|
226
|
+
}
|
|
227
|
+
default:
|
|
228
|
+
store.startTool({ id: tool_use_id, name, summary: detail(input) });
|
|
229
|
+
store.finishTool({ error: true });
|
|
230
|
+
return { tool_use_id, content: `Unknown tool: ${name}`, is_error: true };
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
catch (err) {
|
|
234
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
235
|
+
store.finishTool({ error: true });
|
|
236
|
+
return { tool_use_id, content: msg, is_error: true };
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
//# sourceMappingURL=execToolInk.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"execToolInk.js","sourceRoot":"","sources":["../../src/ink/execToolInk.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CA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AAC;IACvD,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runSessionInk.d.ts","sourceRoot":"","sources":["../../src/ink/runSessionInk.ts"],"names":[],"mappings":"AAuBA,wBAAsB,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAyKpE"}
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ink session runner — the render-layer counterpart to ws.ts::runSession.
|
|
3
|
+
*
|
|
4
|
+
* Same protocol, auth, and connect handshake as the classic client (so the
|
|
5
|
+
* server behaves identically — including loading the operator skills it keys
|
|
6
|
+
* off the connect message's cwd + tools). The only difference is the display
|
|
7
|
+
* layer: messages drive the session store and the <App> renders it, instead of
|
|
8
|
+
* readline + display.ts + input_box.ts hand-rolled ANSI.
|
|
9
|
+
*
|
|
10
|
+
* Client-side tools execute through execToolInk, which routes approval through
|
|
11
|
+
* the Ink approval surface (no readline conflict). Server-side tools
|
|
12
|
+
* (server_tool_call) display normally.
|
|
13
|
+
*/
|
|
14
|
+
import WebSocket from "ws";
|
|
15
|
+
import { WS_URL, CLI_VERSION } from "../config.js";
|
|
16
|
+
import { getToken } from "../auth.js";
|
|
17
|
+
import { setSessionCwd, TOOL_MANIFEST } from "../tools.js";
|
|
18
|
+
import { postToolResults } from "../tool_result_client.js";
|
|
19
|
+
import { execToolInk } from "./execToolInk.js";
|
|
20
|
+
import { connectProjectContextField } from "../projectContext.js";
|
|
21
|
+
import { startInkUI } from "./App.js";
|
|
22
|
+
import * as store from "./store.js";
|
|
23
|
+
export async function runSessionInk(sessionId) {
|
|
24
|
+
const wsUrl = `${WS_URL}/terminal/sessions/${sessionId}/stream`;
|
|
25
|
+
return new Promise((resolve, reject) => {
|
|
26
|
+
const ws = new WebSocket(wsUrl);
|
|
27
|
+
let connected = false;
|
|
28
|
+
let firstTokenThisTurn = true;
|
|
29
|
+
let pendingServerTool = false;
|
|
30
|
+
let settled = false;
|
|
31
|
+
let pingInterval;
|
|
32
|
+
// Mount the Ink UI. Submitting a line commits the user turn (which also
|
|
33
|
+
// marks the agent busy) and sends it over the socket.
|
|
34
|
+
const ink = startInkUI({
|
|
35
|
+
onSubmit: (text) => {
|
|
36
|
+
if (!connected || ws.readyState !== WebSocket.OPEN)
|
|
37
|
+
return;
|
|
38
|
+
store.addUserTurn(text);
|
|
39
|
+
firstTokenThisTurn = true;
|
|
40
|
+
ws.send(JSON.stringify({ type: "message", content: text }));
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
function finish(err) {
|
|
44
|
+
if (settled)
|
|
45
|
+
return;
|
|
46
|
+
settled = true;
|
|
47
|
+
if (pingInterval)
|
|
48
|
+
clearInterval(pingInterval);
|
|
49
|
+
try {
|
|
50
|
+
ink.unmount();
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
// already unmounted — nothing to do
|
|
54
|
+
}
|
|
55
|
+
if (err)
|
|
56
|
+
reject(err);
|
|
57
|
+
else
|
|
58
|
+
resolve();
|
|
59
|
+
}
|
|
60
|
+
function flushPendingServerTool() {
|
|
61
|
+
if (pendingServerTool) {
|
|
62
|
+
store.finishTool();
|
|
63
|
+
pendingServerTool = false;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
// Client tool calls drain serially — one approval in flight at a time, and
|
|
67
|
+
// tool results post in order (mirrors ws.ts::drainToolCallQueue).
|
|
68
|
+
const toolQueue = [];
|
|
69
|
+
let draining = false;
|
|
70
|
+
async function drainTools() {
|
|
71
|
+
if (draining)
|
|
72
|
+
return;
|
|
73
|
+
draining = true;
|
|
74
|
+
try {
|
|
75
|
+
while (toolQueue.length > 0) {
|
|
76
|
+
const tc = toolQueue.shift();
|
|
77
|
+
store.flushStreaming();
|
|
78
|
+
const result = await execToolInk(tc);
|
|
79
|
+
try {
|
|
80
|
+
await postToolResults(sessionId, [
|
|
81
|
+
{ tool_use_id: result.tool_use_id, content: result.content, is_error: result.is_error },
|
|
82
|
+
]);
|
|
83
|
+
}
|
|
84
|
+
catch {
|
|
85
|
+
store.pushError("Couldn't return the tool result to the server.");
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
finally {
|
|
90
|
+
draining = false;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
ws.on("open", () => {
|
|
94
|
+
// Identical handshake to the classic client — auth, then connect with the
|
|
95
|
+
// cwd + tool manifest the server keys skill-loading off.
|
|
96
|
+
ws.send(JSON.stringify({ type: "auth", token: getToken(), version: CLI_VERSION }));
|
|
97
|
+
ws.send(JSON.stringify({
|
|
98
|
+
type: "connect",
|
|
99
|
+
cwd: process.cwd(),
|
|
100
|
+
tools: TOOL_MANIFEST,
|
|
101
|
+
...connectProjectContextField(process.cwd()),
|
|
102
|
+
}));
|
|
103
|
+
});
|
|
104
|
+
ws.on("message", async (raw) => {
|
|
105
|
+
const msg = JSON.parse(raw.toString());
|
|
106
|
+
switch (msg.type) {
|
|
107
|
+
case "connected": {
|
|
108
|
+
connected = true;
|
|
109
|
+
setSessionCwd(process.cwd());
|
|
110
|
+
store.setConnected(true);
|
|
111
|
+
// Server-advertised tenant assistant name wins over the env/default.
|
|
112
|
+
const name = msg.bot_name ?? msg.assistant_name;
|
|
113
|
+
store.setBotName(name);
|
|
114
|
+
const shortId = String(msg.session_id ?? sessionId).slice(0, 4);
|
|
115
|
+
store.setSessionLabel(`${(name ?? "session").toLowerCase()} · ${shortId}`);
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
118
|
+
case "text_delta":
|
|
119
|
+
if (firstTokenThisTurn) {
|
|
120
|
+
flushPendingServerTool();
|
|
121
|
+
firstTokenThisTurn = false;
|
|
122
|
+
}
|
|
123
|
+
store.appendStreaming(msg.content);
|
|
124
|
+
break;
|
|
125
|
+
case "tool_call":
|
|
126
|
+
toolQueue.push({
|
|
127
|
+
tool_use_id: msg.tool_use_id,
|
|
128
|
+
name: msg.name,
|
|
129
|
+
input: (msg.input ?? {}),
|
|
130
|
+
});
|
|
131
|
+
drainTools();
|
|
132
|
+
break;
|
|
133
|
+
case "server_tool_call":
|
|
134
|
+
flushPendingServerTool();
|
|
135
|
+
store.flushStreaming();
|
|
136
|
+
firstTokenThisTurn = false;
|
|
137
|
+
store.startTool({
|
|
138
|
+
id: String(msg.tool_use_id ?? msg.name),
|
|
139
|
+
name: msg.name,
|
|
140
|
+
summary: msg.input_summary || "",
|
|
141
|
+
});
|
|
142
|
+
pendingServerTool = true;
|
|
143
|
+
break;
|
|
144
|
+
case "message_stop":
|
|
145
|
+
flushPendingServerTool();
|
|
146
|
+
store.endTurn();
|
|
147
|
+
break;
|
|
148
|
+
case "error":
|
|
149
|
+
flushPendingServerTool();
|
|
150
|
+
store.pushError(String(msg.message ?? "Unknown error"));
|
|
151
|
+
if (!connected) {
|
|
152
|
+
ws.close();
|
|
153
|
+
finish(new Error(String(msg.message ?? "connect error")));
|
|
154
|
+
}
|
|
155
|
+
break;
|
|
156
|
+
case "pong":
|
|
157
|
+
break;
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
ws.on("close", () => {
|
|
161
|
+
store.setConnected(false);
|
|
162
|
+
finish();
|
|
163
|
+
});
|
|
164
|
+
ws.on("error", (err) => {
|
|
165
|
+
finish(err);
|
|
166
|
+
});
|
|
167
|
+
pingInterval = setInterval(() => {
|
|
168
|
+
if (ws.readyState === WebSocket.OPEN) {
|
|
169
|
+
ws.send(JSON.stringify({ type: "ping" }));
|
|
170
|
+
}
|
|
171
|
+
}, 30000);
|
|
172
|
+
// When the user quits the UI (ctrl+c → Ink unmounts), close the socket;
|
|
173
|
+
// the close handler then settles the promise.
|
|
174
|
+
ink.waitUntilExit().then(() => {
|
|
175
|
+
try {
|
|
176
|
+
ws.close();
|
|
177
|
+
}
|
|
178
|
+
catch {
|
|
179
|
+
// socket already closing
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
//# sourceM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
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
export interface DiffLine {
|
|
2
|
+
op: "+" | "-";
|
|
3
|
+
text: string;
|
|
4
|
+
}
|
|
5
|
+
export interface ToolCall {
|
|
6
|
+
/** Stable id from the server tool_call, used to match the finish event. */
|
|
7
|
+
id: string;
|
|
8
|
+
name: string;
|
|
9
|
+
/** One-line target (path, command, …) shown dim after the tool name. */
|
|
10
|
+
summary: string;
|
|
11
|
+
status: "running" | "done" | "error";
|
|
12
|
+
diff?: DiffLine[];
|
|
13
|
+
}
|
|
14
|
+
export type Turn = {
|
|
15
|
+
kind: "user";
|
|
16
|
+
text: string;
|
|
17
|
+
} | {
|
|
18
|
+
kind: "bot";
|
|
19
|
+
text: string;
|
|
20
|
+
} | {
|
|
21
|
+
kind: "tool";
|
|
22
|
+
tool: ToolCall;
|
|
23
|
+
};
|
|
24
|
+
/** The user's decision on a tool approval — mirrors ui_state.ApprovalMenuResult. */
|
|
25
|
+
export type ApprovalDecision = {
|
|
26
|
+
approved: true;
|
|
27
|
+
allowlistRequested: boolean;
|
|
28
|
+
} | {
|
|
29
|
+
approved: false;
|
|
30
|
+
rejectReason: string;
|
|
31
|
+
};
|
|
32
|
+
/** A client-side tool waiting on the user's approval. */
|
|
33
|
+
export interface PendingApproval {
|
|
34
|
+
/** Tool label, e.g. "shell_command". */
|
|
35
|
+
tool: string;
|
|
36
|
+
/** One-line target (command, path) shown next to the label. */
|
|
37
|
+
summary: string;
|
|
38
|
+
/** Detail body — command + cwd, or a write summary. */
|
|
39
|
+
body: string;
|
|
40
|
+
/** Edit preview for write_file. */
|
|
41
|
+
diff?: DiffLine[];
|
|
42
|
+
}
|
|
43
|
+
export interface SessionState {
|
|
44
|
+
/** Committed history — rendered once via <Static>, never repainted. */
|
|
45
|
+
turns: Turn[];
|
|
46
|
+
/** The tool currently executing (spinner), or null. */
|
|
47
|
+
liveTool: ToolCall | null;
|
|
48
|
+
/** The streaming bot reply so far, or null when not streaming. */
|
|
49
|
+
streaming: string | null;
|
|
50
|
+
/** Agent is working — input is disabled and dimmed while true. */
|
|
51
|
+
busy: boolean;
|
|
52
|
+
connected: boolean;
|
|
53
|
+
/** Resolved server-side, via the `connected` message. */
|
|
54
|
+
botName: string;
|
|
55
|
+
/** Quiet status-line label, e.g. "doctorwhiskers · 0a16". */
|
|
56
|
+
sessionLabel: string;
|
|
57
|
+
/** Short connection note: "connecting…" / "connected" / "reconnecting…". */
|
|
58
|
+
statusNote: string;
|
|
59
|
+
/** A tool awaiting the user's approval, or null. */
|
|
60
|
+
pendingApproval: PendingApproval | null;
|
|
61
|
+
}
|
|
62
|
+
export declare function getSnapshot(): SessionState;
|
|
63
|
+
export declare function useSession(): SessionState;
|
|
64
|
+
export declare function setConnected(connected: boolean): void;
|
|
65
|
+
export declare function setBotName(name: string | undefined | null): void;
|
|
66
|
+
export declare function setSessionLabel(label: string): void;
|
|
67
|
+
/** User submitted a message: commit it to history and mark the agent busy. */
|
|
68
|
+
export declare function addUserTurn(text: string): void;
|
|
69
|
+
/** A text_delta arrived — append to the streaming reply. */
|
|
70
|
+
export declare function appendStreaming(delta: string): void;
|
|
71
|
+
/**
|
|
72
|
+
* Commit the streamed reply so far as a bot turn (if any) without ending the
|
|
73
|
+
* turn. Called before a tool line so history order stays correct when the agent
|
|
74
|
+
* streams text, runs a tool, then streams more.
|
|
75
|
+
*/
|
|
76
|
+
export declare function flushStreaming(): void;
|
|
77
|
+
/** Turn finished (message_stop): commit any streamed reply, clear busy. */
|
|
78
|
+
export declare function endTurn(): void;
|
|
79
|
+
/** A tool started executing — show it with a live spinner. */
|
|
80
|
+
export declare function startTool(tool: {
|
|
81
|
+
id: string;
|
|
82
|
+
name: string;
|
|
83
|
+
summary: string;
|
|
84
|
+
}): void;
|
|
85
|
+
/** The live tool finished — commit it to history (✓ or error), with any diff. */
|
|
86
|
+
export declare function finishTool(result?: {
|
|
87
|
+
diff?: DiffLine[];
|
|
88
|
+
error?: boolean;
|
|
89
|
+
}): void;
|
|
90
|
+
/** Surface a server/protocol error as a bot turn so it lands in history. */
|
|
91
|
+
export declare function pushError(message: string): void;
|
|
92
|
+
/**
|
|
93
|
+
* Ask the user to approve a client-side tool. Resolves when the App calls
|
|
94
|
+
* resolveApproval(). Only one approval is in flight at a time (tool calls drain
|
|
95
|
+
* serially in the runner).
|
|
96
|
+
*/
|
|
97
|
+
export declare function requestApproval(p: PendingApproval): Promise<ApprovalDecision>;
|
|
98
|
+
/** The App resolves the pending approval with the user's decision. */
|
|
99
|
+
export declare function resolveApproval(decision: ApprovalDecision): void;
|
|
100
|
+
/** Test/diagnostic helper — reset to initial state. */
|
|
101
|
+
export declare function _resetForTest(): void;
|
|
102
|
+
//# sourceMappingURL=store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../src/ink/store.ts"],"names":[],"mappings":"AAeA,MAAM,WAAW,QAAQ;IACvB,EAAE,EAAE,GAAG,GAAG,GAAG,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,QAAQ;IACvB,2EAA2E;IAC3E,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,wEAAwE;IACxE,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,SAAS,GAAG,MAAM,GAAG,OAAO,CAAC;IACrC,IAAI,CAAC,EAAE,QAAQ,EAAE,CAAC;CACnB;AAED,MAAM,MAAM,IAAI,GACZ;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAC9B;IAAE,IAAI,EAAE,KAAK,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAC7B;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,QAAQ,CAAA;CAAE,CAAC;AAErC,oFAAoF;AACpF,MAAM,MAAM,gBAAgB,GACxB;IAAE,QAAQ,EAAE,IAAI,CAAC;IA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