@akanjs/code 0.0.0-stage → 3.3.0-rc.70
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/README.ko.md +31 -0
- package/README.md +30 -2
- package/agent/AkanCodeCompaction.ts +49 -0
- package/agent/AkanCodeServices.ts +122 -0
- package/agent/AkanContextFiles.ts +94 -0
- package/agent/CodeAgent.ts +598 -0
- package/agent/CodeAgentAllowed.ts +35 -0
- package/agent/CodeAgentAsks.ts +66 -0
- package/agent/CodeAgentCommandLine.ts +372 -0
- package/agent/CodeAgentEventMapper.ts +225 -0
- package/agent/CodeAgentFrames.ts +57 -0
- package/agent/CodeAgentGate.ts +258 -0
- package/agent/CodeAgentProxy.ts +83 -0
- package/agent/CodeAgentRpcHost.ts +109 -0
- package/agent/CodeAgentRpcListener.ts +195 -0
- package/agent/CodeAgentStreamPrinter.ts +86 -0
- package/agent/CodeAgentSuspended.ts +85 -0
- package/agent/CodeAgentUi.ts +47 -0
- package/agent/CodeMailbox.ts +148 -0
- package/agent/CodeSessionFork.ts +56 -0
- package/agent/CodeSessionIndex.ts +78 -0
- package/agent/SubagentPool.ts +222 -0
- package/agent/WorkspaceTrust.ts +200 -0
- package/agent/akanCodeCompaction.test.ts +36 -0
- package/agent/akanCodeModel.ts +47 -0
- package/agent/akanCodeServices.test.ts +54 -0
- package/agent/akanContextFiles.test.ts +116 -0
- package/agent/akanSystemPrompt.ts +50 -0
- package/agent/codeAgent.test.ts +337 -0
- package/agent/codeAgentCommandLine.test.ts +212 -0
- package/agent/codeAgentContract.test.ts +757 -0
- package/agent/codeAgentHosts.ts +30 -0
- package/agent/codeAgentProxy.test.ts +125 -0
- package/agent/codeAgentRpcListener.test.ts +215 -0
- package/agent/codeAgentSuspended.test.ts +47 -0
- package/agent/codeMailbox.test.ts +76 -0
- package/agent/codeSessionFork.test.ts +58 -0
- package/agent/codeSessionIndex.test.ts +77 -0
- package/agent/consoleToStderr.ts +8 -0
- package/agent/jsonLines.ts +29 -0
- package/agent/stringArg.ts +5 -0
- package/bunfig.toml +2 -0
- package/feedback/DevLogFeedback.ts +82 -0
- package/feedback/PreviewFeedback.ts +46 -0
- package/feedback/TurnFeedback.ts +98 -0
- package/feedback/VerifyFeedback.ts +39 -0
- package/host/AkanCodeRunner.ts +297 -0
- package/host/CodeTrustPrompt.ts +57 -0
- package/host/codeRunnerPrompt.test.ts +181 -0
- package/host/hostGraph.test.ts +33 -0
- package/host/index.ts +2 -0
- package/index.ts +49 -0
- package/package.json +50 -4
- package/piDependencyPins.test.ts +45 -0
- package/test/preload.ts +3 -0
- package/tools/AkanCli.ts +56 -0
- package/tools/AkanCodePlugins.ts +145 -0
- package/tools/AkanEditScope.ts +53 -0
- package/tools/AkanEnvKeys.ts +50 -0
- package/tools/AkanToolPack.ts +87 -0
- package/tools/AkanVerifier.ts +30 -0
- package/tools/AskToolPack.ts +99 -0
- package/tools/DeepSeekWeb.ts +127 -0
- package/tools/MailToolPack.ts +76 -0
- package/tools/McpClient.ts +209 -0
- package/tools/McpOAuth.ts +233 -0
- package/tools/McpOAuthLoopback.ts +64 -0
- package/tools/McpServerConfig.ts +131 -0
- package/tools/McpSignIn.ts +158 -0
- package/tools/McpTokenStore.ts +128 -0
- package/tools/McpToolPack.ts +206 -0
- package/tools/SessionToolPack.ts +91 -0
- package/tools/WebToolPack.ts +315 -0
- package/tools/akanCodePlugins.test.ts +954 -0
- package/tools/askToolPack.test.ts +116 -0
- package/tools/deepSeekWeb.test.ts +113 -0
- package/tools/mcpOAuth.test.ts +648 -0
- package/tools/mcpServerConfig.test.ts +341 -0
- package/tsconfig.json +29 -0
- package/tui/CodeTui.tsx +394 -0
- package/tui/CodeTuiAgents.ts +65 -0
- package/tui/CodeTuiApp.test.tsx +251 -0
- package/tui/CodeTuiApp.tsx +312 -0
- package/tui/CodeTuiAutoCompact.ts +33 -0
- package/tui/CodeTuiClipboard.ts +94 -0
- package/tui/CodeTuiCommandRunner.ts +242 -0
- package/tui/CodeTuiCommands.ts +59 -0
- package/tui/CodeTuiEditor.ts +168 -0
- package/tui/CodeTuiFiles.ts +45 -0
- package/tui/CodeTuiFrame.ts +133 -0
- package/tui/CodeTuiLines.ts +117 -0
- package/tui/CodeTuiMarkdown.ts +159 -0
- package/tui/CodeTuiMcp.ts +111 -0
- package/tui/CodeTuiModels.ts +82 -0
- package/tui/CodeTuiMouse.ts +39 -0
- package/tui/CodeTuiOverlay.ts +148 -0
- package/tui/CodeTuiParts.ts +168 -0
- package/tui/CodeTuiPrompt.ts +271 -0
- package/tui/CodeTuiQuestion.ts +170 -0
- package/tui/codeTranscript.test.ts +445 -0
- package/tui/codeTui.test.tsx +1104 -0
- package/tui/codeTuiAgents.test.ts +61 -0
- package/tui/codeTuiClipboard.test.ts +16 -0
- package/tui/codeTuiCommands.test.ts +38 -0
- package/tui/codeTuiEditor.test.ts +122 -0
- package/tui/codeTuiFiles.test.ts +43 -0
- package/tui/codeTuiMarkdown.test.ts +91 -0
- package/tui/codeTuiMcp.test.ts +160 -0
- package/tui/codeTuiMouse.test.ts +61 -0
|
@@ -0,0 +1,1104 @@
|
|
|
1
|
+
import { afterEach, beforeAll, describe, expect, test } from "bun:test";
|
|
2
|
+
import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { rm } from "node:fs/promises";
|
|
4
|
+
import { tmpdir } from "node:os";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { akanCodePaths } from "@akanjs/devkit/codeAgent";
|
|
7
|
+
import { csi, esc, FakeStdout, makeStdin } from "@akanjs/devkit/test/fakeTerminal";
|
|
8
|
+
import type {
|
|
9
|
+
CodeAgentAnswer,
|
|
10
|
+
CodeAgentEvent,
|
|
11
|
+
CodeAgentEventBody,
|
|
12
|
+
CodeAgentMcpStatus,
|
|
13
|
+
CodeAgentSessionInfo,
|
|
14
|
+
} from "akanjs/common";
|
|
15
|
+
import type { CodeAgent } from "../agent/CodeAgent";
|
|
16
|
+
import { McpServerConfig } from "../tools/McpServerConfig";
|
|
17
|
+
import { CodeTui, type CodeTuiExit } from "./CodeTui";
|
|
18
|
+
import { CodeTuiClipboard } from "./CodeTuiClipboard";
|
|
19
|
+
import { CodeTuiMouse } from "./CodeTuiMouse";
|
|
20
|
+
|
|
21
|
+
const info: CodeAgentSessionInfo = {
|
|
22
|
+
sessionId: "s1",
|
|
23
|
+
cwd: "/repo",
|
|
24
|
+
profile: "local",
|
|
25
|
+
model: { provider: "deepseek", id: "deepseek-v4-flash", name: "DeepSeek V4 Flash" },
|
|
26
|
+
tools: ["read", "bash"],
|
|
27
|
+
contextTokens: 1_000_000,
|
|
28
|
+
effort: "medium",
|
|
29
|
+
autoCompactAt: undefined,
|
|
30
|
+
name: undefined,
|
|
31
|
+
interaction: { question: "await", approval: "await" },
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
class FakeAgent {
|
|
35
|
+
readonly calls: string[] = [];
|
|
36
|
+
readonly profile: CodeAgent["profile"];
|
|
37
|
+
canSeeImages = true;
|
|
38
|
+
stored: { id: string; name?: string; opening: string; updatedAt: number; turns: number }[] = [];
|
|
39
|
+
mcp: CodeAgentMcpStatus[] = [];
|
|
40
|
+
refusal: string | undefined;
|
|
41
|
+
readonly workspaceRoot: string;
|
|
42
|
+
#listener: ((event: CodeAgentEvent) => void) | undefined;
|
|
43
|
+
#seq = 0;
|
|
44
|
+
streaming = false;
|
|
45
|
+
|
|
46
|
+
constructor(root: string) {
|
|
47
|
+
this.profile = { paths: { root } } as CodeAgent["profile"];
|
|
48
|
+
this.workspaceRoot = root;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
sessions() {
|
|
52
|
+
return this.stored;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
mcpServers() {
|
|
56
|
+
return this.mcp;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
catalogue() {
|
|
60
|
+
return [
|
|
61
|
+
{
|
|
62
|
+
id: "deepseek",
|
|
63
|
+
name: "DeepSeek",
|
|
64
|
+
authorized: true,
|
|
65
|
+
models: [{ id: "deepseek-v4-flash", name: "DeepSeek V4 Flash", contextWindow: 1_000_000, current: true }],
|
|
66
|
+
},
|
|
67
|
+
{ id: "anthropic", name: "Anthropic", authorized: false, models: [{ id: "opus", name: "Opus", current: false }] },
|
|
68
|
+
];
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
setName(name: string) {
|
|
72
|
+
this.calls.push(`setName:${name}`);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
efforts() {
|
|
76
|
+
return ["low", "medium", "high"];
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
setEffort(effort: string) {
|
|
80
|
+
this.calls.push(`setEffort:${effort}`);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
setAutoCompactAt(percent: number) {
|
|
84
|
+
this.calls.push(`setAutoCompactAt:${percent}`);
|
|
85
|
+
this.emit({ type: "session", info: { ...info, autoCompactAt: percent === 100 ? undefined : percent } });
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
on(listener: (event: CodeAgentEvent) => void) {
|
|
89
|
+
this.#listener = listener;
|
|
90
|
+
return () => {
|
|
91
|
+
this.#listener = undefined;
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
announce() {
|
|
96
|
+
this.emit({ type: "session", info });
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
emit(body: CodeAgentEventBody) {
|
|
100
|
+
this.#seq += 1;
|
|
101
|
+
this.#listener?.({ ...body, seq: this.#seq } as CodeAgentEvent);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
async prompt(message: string, images?: { path: string }[]) {
|
|
105
|
+
const attached = (images ?? []).map((image) => `:${image.path}`).join("");
|
|
106
|
+
this.calls.push(`prompt:${message}${attached}`);
|
|
107
|
+
if (this.refusal) throw new Error(this.refusal);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
async abort() {
|
|
111
|
+
this.calls.push("abort");
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
async compact(instructions?: string) {
|
|
115
|
+
this.calls.push(`compact:${instructions ?? ""}`);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
async setModel(ref: { provider: string; id: string }) {
|
|
119
|
+
this.calls.push(`setModel:${ref.provider}/${ref.id}`);
|
|
120
|
+
if (this.refusal) throw new Error(this.refusal);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
async answer(questionId: string, answer: CodeAgentAnswer) {
|
|
124
|
+
this.calls.push(`answer:${questionId}:${JSON.stringify(answer)}`);
|
|
125
|
+
return true;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
async approve(approvalId: string, approved: boolean, remember?: "session") {
|
|
129
|
+
this.calls.push(["approve", approvalId, approved, ...(remember ? [remember] : [])].join(":"));
|
|
130
|
+
return true;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
readonly allowedNames: string[] = [];
|
|
134
|
+
readonly allowed = {
|
|
135
|
+
names: this.allowedNames,
|
|
136
|
+
clear: () => this.allowedNames.splice(0).length,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const keys = { backspace: String.fromCharCode(127) };
|
|
141
|
+
|
|
142
|
+
// Ink writes a cursor move ("up N from the line after the last") alone when no text changed, so the latest move wins.
|
|
143
|
+
const caretOf = (stdout: FakeStdout) => {
|
|
144
|
+
const suffix = new RegExp(`(?:${esc}\\[(\\d+)A)?${esc}\\[(\\d+)G${esc}\\[\\?25h`);
|
|
145
|
+
let move: RegExpExecArray | undefined;
|
|
146
|
+
for (let at = stdout.frames.length - 1; at >= 0; at -= 1) {
|
|
147
|
+
const frame = stdout.frames[at] ?? "";
|
|
148
|
+
const match = suffix.exec(frame);
|
|
149
|
+
if (!match) continue;
|
|
150
|
+
move ??= match;
|
|
151
|
+
const text = frame.replace(csi, "");
|
|
152
|
+
if (!text.trim()) continue;
|
|
153
|
+
const lines = text.split("\n");
|
|
154
|
+
return {
|
|
155
|
+
row: (text.endsWith("\n") ? lines.length - 1 : lines.length) - Number(move[1] ?? 0),
|
|
156
|
+
column: Number(move[2] ?? 1) - 1,
|
|
157
|
+
lines,
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
return undefined;
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
const eventually = async (assertion: () => void, timeoutMs = 2_000) => {
|
|
164
|
+
const deadline = Date.now() + timeoutMs;
|
|
165
|
+
for (;;) {
|
|
166
|
+
try {
|
|
167
|
+
assertion();
|
|
168
|
+
return;
|
|
169
|
+
} catch (error) {
|
|
170
|
+
if (Date.now() >= deadline) throw error;
|
|
171
|
+
}
|
|
172
|
+
await Bun.sleep(5);
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
// Ink emits a lone ESC from a setImmediate, and useInput re-binds its handler in a passive effect React schedules on
|
|
177
|
+
// one after every render, so a key written before those turns pass meets the previous mode's handler.
|
|
178
|
+
const turns = async () => {
|
|
179
|
+
for (let at = 0; at < 4; at += 1) await new Promise<void>((resolve) => setImmediate(resolve));
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
const send = async (stdin: ReturnType<typeof makeStdin>, input: string) => {
|
|
183
|
+
await turns();
|
|
184
|
+
stdin.write(input);
|
|
185
|
+
while (stdin.writableLength > 0 || stdin.readableLength > 0) await turns();
|
|
186
|
+
await turns();
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
// Only for a check that something did not appear, which no frame marks: the host's 34ms frame timer, then Ink's 30fps.
|
|
190
|
+
const quiet = () => Bun.sleep(CodeTui.frameMs * 3);
|
|
191
|
+
|
|
192
|
+
// `/mcp add` writes the home config, so without this the suite would declare its fixtures in the runner's ~/.akan.
|
|
193
|
+
beforeAll(() => {
|
|
194
|
+
const home = mkdtempSync(path.join(tmpdir(), "akan-tui-home-"));
|
|
195
|
+
process.env.AKAN_CODE_HOME = home;
|
|
196
|
+
expect(akanCodePaths.globalMcpFile().startsWith(home)).toBe(true);
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
//? The session's `git ls-files` runs in the repo root, and Windows refuses to delete a folder a live process is in.
|
|
200
|
+
const removeOnceReleased = async (root: string) => {
|
|
201
|
+
for (let attempt = 1; ; attempt++) {
|
|
202
|
+
try {
|
|
203
|
+
return await rm(root, { recursive: true, force: true });
|
|
204
|
+
} catch (error) {
|
|
205
|
+
if ((error as NodeJS.ErrnoException).code !== "EBUSY" || attempt >= 30) throw error;
|
|
206
|
+
await Bun.sleep(100);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
const running: { tui: CodeTui; done: Promise<CodeTuiExit | undefined> }[] = [];
|
|
212
|
+
|
|
213
|
+
const mount = (root = "/repo") => {
|
|
214
|
+
// Only a tty reaches Ink's fullscreen branch, which the caret assertions below must be able to tell apart.
|
|
215
|
+
const stdout = new FakeStdout(90, 20, true);
|
|
216
|
+
const stdin = makeStdin();
|
|
217
|
+
const agent = new FakeAgent(root);
|
|
218
|
+
const tui = new CodeTui(agent as unknown as CodeAgent, {
|
|
219
|
+
openBrowser: () => {},
|
|
220
|
+
stdout: stdout as unknown as NodeJS.WriteStream,
|
|
221
|
+
stdin: stdin as unknown as NodeJS.ReadStream,
|
|
222
|
+
});
|
|
223
|
+
const done = tui.run();
|
|
224
|
+
running.push({ tui, done });
|
|
225
|
+
const drawn = (text: string, timeoutMs?: number) =>
|
|
226
|
+
eventually(() => expect(stdout.lastFrame).toContain(text), timeoutMs);
|
|
227
|
+
return {
|
|
228
|
+
agent,
|
|
229
|
+
stdout,
|
|
230
|
+
done,
|
|
231
|
+
tui,
|
|
232
|
+
drawn,
|
|
233
|
+
ready: () => drawn("DeepSeek V4 Flash"),
|
|
234
|
+
press: (input: string) => send(stdin, input),
|
|
235
|
+
emit: (body: CodeAgentEventBody) => agent.emit(body),
|
|
236
|
+
};
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
afterEach(async () => {
|
|
240
|
+
for (const entry of running.splice(0)) {
|
|
241
|
+
entry.tui.close();
|
|
242
|
+
await entry.done;
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
describe("CodeTui", () => {
|
|
247
|
+
test("announces the session and draws its line", async () => {
|
|
248
|
+
const { stdout, ready } = mount();
|
|
249
|
+
await ready();
|
|
250
|
+
await eventually(() => {
|
|
251
|
+
expect(stdout.lastFrame).toContain("DeepSeek V4 Flash");
|
|
252
|
+
expect(stdout.lastFrame).toContain("1000k ctx");
|
|
253
|
+
});
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
test("a typed prompt is echoed locally and sent once", async () => {
|
|
257
|
+
const harness = mount();
|
|
258
|
+
await harness.ready();
|
|
259
|
+
await harness.press("hi there");
|
|
260
|
+
await harness.press("\r");
|
|
261
|
+
await eventually(() => expect(harness.agent.calls).toEqual(["prompt:hi there"]));
|
|
262
|
+
await harness.drawn("› hi there");
|
|
263
|
+
harness.emit({ type: "message", turnId: "t1", role: "user", text: "hi there" });
|
|
264
|
+
await quiet();
|
|
265
|
+
expect(harness.stdout.lastFrame.split("› hi there").length - 1).toBe(1);
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
test("a streamed answer appears as it arrives and keeps one bubble", async () => {
|
|
269
|
+
const harness = mount();
|
|
270
|
+
await harness.ready();
|
|
271
|
+
harness.emit({ type: "turn_start", turnId: "t1" });
|
|
272
|
+
harness.emit({ type: "text_delta", turnId: "t1", text: "the answer" });
|
|
273
|
+
await eventually(() => {
|
|
274
|
+
expect(harness.stdout.lastFrame).toContain("the answer");
|
|
275
|
+
expect(harness.stdout.lastFrame).toContain("◐");
|
|
276
|
+
});
|
|
277
|
+
harness.emit({ type: "message", turnId: "t1", role: "assistant", text: "the whole answer" });
|
|
278
|
+
harness.emit({ type: "turn_end", turnId: "t1", stopReason: "done" });
|
|
279
|
+
await eventually(() => {
|
|
280
|
+
expect(harness.stdout.lastFrame).toContain("the whole answer");
|
|
281
|
+
expect(harness.stdout.lastFrame).not.toContain("◐");
|
|
282
|
+
});
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
test("a running sub-agent draws a rail under the prompt and leaves with the turn", async () => {
|
|
286
|
+
const harness = mount();
|
|
287
|
+
await harness.ready();
|
|
288
|
+
const rows = harness.stdout.lastFrame.split("\n").length;
|
|
289
|
+
harness.emit({
|
|
290
|
+
type: "subagent",
|
|
291
|
+
agents: [
|
|
292
|
+
{ id: "c0", kind: "explore", description: "Counting desc strings", startedAt: Date.now(), tokens: 12_400 },
|
|
293
|
+
],
|
|
294
|
+
});
|
|
295
|
+
await eventually(() => {
|
|
296
|
+
expect(harness.stdout.lastFrame).toContain("◯ explore Counting desc strings");
|
|
297
|
+
expect(harness.stdout.lastFrame).toContain("↓ 12.4k tokens");
|
|
298
|
+
});
|
|
299
|
+
expect(harness.stdout.lastFrame.split("\n").length).toBe(rows);
|
|
300
|
+
harness.emit({ type: "idle" });
|
|
301
|
+
await eventually(() => expect(harness.stdout.lastFrame).not.toContain("◯ explore"));
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
test("the wheel scrolls the transcript, and the terminal is asked for it and released again", async () => {
|
|
305
|
+
const harness = mount();
|
|
306
|
+
await harness.ready();
|
|
307
|
+
expect(harness.stdout.frames.join("")).toContain(CodeTuiMouse.on);
|
|
308
|
+
for (let at = 0; at < 40; at += 1)
|
|
309
|
+
harness.agent.emit({ type: "message", turnId: `t${at}`, role: "assistant", text: `line ${at}` });
|
|
310
|
+
await harness.drawn("line 39");
|
|
311
|
+
expect(harness.stdout.lastFrame).not.toContain("paused");
|
|
312
|
+
await harness.press("\u001b[<64;10;5M");
|
|
313
|
+
await harness.drawn("paused");
|
|
314
|
+
expect(harness.stdout.lastFrame).not.toContain("64;10;5");
|
|
315
|
+
await harness.press("\u001b[<65;10;5M");
|
|
316
|
+
await harness.press("\u001b[<65;10;5M");
|
|
317
|
+
await eventually(() => expect(harness.stdout.lastFrame).not.toContain("paused"));
|
|
318
|
+
harness.tui.close();
|
|
319
|
+
expect(harness.stdout.frames.join("")).toContain(CodeTuiMouse.off);
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
test("/mcp lists the servers this session reached, and says where they are declared", async () => {
|
|
323
|
+
const harness = mount();
|
|
324
|
+
harness.agent.mcp = [
|
|
325
|
+
{ name: "github", transport: "stdio", target: "npx -y server-github", tools: ["mcp__github__search"] },
|
|
326
|
+
];
|
|
327
|
+
await harness.ready();
|
|
328
|
+
await harness.press("/mcp");
|
|
329
|
+
await harness.press("\r");
|
|
330
|
+
await eventually(() => {
|
|
331
|
+
expect(harness.stdout.lastFrame).toContain("github");
|
|
332
|
+
expect(harness.stdout.lastFrame).toContain("1 tool");
|
|
333
|
+
});
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
test("/mcp add writes the home file and reopens this session to pick it up", async () => {
|
|
337
|
+
const root = mkdtempSync(path.join(tmpdir(), "akan-tui-mcp-"));
|
|
338
|
+
const harness = mount(root);
|
|
339
|
+
harness.agent.stored = [{ id: "s1", opening: "hi", updatedAt: Date.now(), turns: 1 }];
|
|
340
|
+
await harness.ready();
|
|
341
|
+
await harness.press("/mcp add github npx -y server-github");
|
|
342
|
+
await harness.press("\r");
|
|
343
|
+
expect(await harness.done).toEqual({ id: "s1", notice: "added github · npx -y server-github · every repo" });
|
|
344
|
+
const file = JSON.parse(readFileSync(akanCodePaths.globalMcpFile(), "utf8")) as {
|
|
345
|
+
mcpServers: Record<string, unknown>;
|
|
346
|
+
};
|
|
347
|
+
expect(file.mcpServers.github).toEqual({ command: "npx", args: ["-y", "server-github"] });
|
|
348
|
+
rmSync(akanCodePaths.globalMcpFile(), { force: true });
|
|
349
|
+
await removeOnceReleased(root);
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
test("/mcp add --local writes the workspace file instead", async () => {
|
|
353
|
+
const root = mkdtempSync(path.join(tmpdir(), "akan-tui-mcp-"));
|
|
354
|
+
const harness = mount(root);
|
|
355
|
+
harness.agent.stored = [{ id: "s1", opening: "hi", updatedAt: Date.now(), turns: 1 }];
|
|
356
|
+
await harness.ready();
|
|
357
|
+
await harness.press("/mcp add --local repobot bun run bot.ts");
|
|
358
|
+
await harness.press("\r");
|
|
359
|
+
expect(await harness.done).toEqual({ id: "s1", notice: "added repobot · bun run bot.ts · this repo" });
|
|
360
|
+
const file = JSON.parse(readFileSync(path.join(root, ".akan", "code", "mcp.json"), "utf8")) as {
|
|
361
|
+
mcpServers: Record<string, unknown>;
|
|
362
|
+
};
|
|
363
|
+
expect(file.mcpServers.repobot).toEqual({ command: "bun", args: ["run", "bot.ts"] });
|
|
364
|
+
expect(existsSync(akanCodePaths.globalMcpFile())).toBe(false);
|
|
365
|
+
await removeOnceReleased(root);
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
test("/mcp remove says when the home file still declares the name it took from this repo", async () => {
|
|
369
|
+
const root = mkdtempSync(path.join(tmpdir(), "akan-tui-mcp-"));
|
|
370
|
+
McpServerConfig.add(root, "shared", ["home"], "global");
|
|
371
|
+
McpServerConfig.add(root, "shared", ["repo"], "workspace");
|
|
372
|
+
const harness = mount(root);
|
|
373
|
+
harness.agent.stored = [{ id: "s1", opening: "hi", updatedAt: Date.now(), turns: 1 }];
|
|
374
|
+
await harness.ready();
|
|
375
|
+
await harness.press("/mcp remove shared");
|
|
376
|
+
await harness.press("\r");
|
|
377
|
+
const exit = await harness.done;
|
|
378
|
+
expect(exit?.notice).toStartWith("removed shared from the workspace file");
|
|
379
|
+
expect(exit?.notice).toContain("the global file still declares it, so it still applies");
|
|
380
|
+
expect(McpServerConfig.declared(root).map((entry) => entry.scope)).toEqual(["global"]);
|
|
381
|
+
rmSync(akanCodePaths.globalMcpFile(), { force: true });
|
|
382
|
+
await removeOnceReleased(root);
|
|
383
|
+
});
|
|
384
|
+
|
|
385
|
+
test("/mcp remove --local leaves a name only the home file declares where it is", async () => {
|
|
386
|
+
const root = mkdtempSync(path.join(tmpdir(), "akan-tui-mcp-"));
|
|
387
|
+
McpServerConfig.add(root, "office", ["https://office.example/mcp"], "global");
|
|
388
|
+
const harness = mount(root);
|
|
389
|
+
harness.agent.stored = [{ id: "s1", opening: "hi", updatedAt: Date.now(), turns: 1 }];
|
|
390
|
+
await harness.ready();
|
|
391
|
+
await harness.press("/mcp remove --local office");
|
|
392
|
+
await harness.press("\r");
|
|
393
|
+
await harness.drawn(`"office" is not declared in this repo's file`);
|
|
394
|
+
expect(McpServerConfig.declared(root).map((entry) => entry.scope)).toEqual(["global"]);
|
|
395
|
+
rmSync(akanCodePaths.globalMcpFile(), { force: true });
|
|
396
|
+
await removeOnceReleased(root);
|
|
397
|
+
});
|
|
398
|
+
|
|
399
|
+
test("a session with nothing on disk is told a reload has nothing to reopen", async () => {
|
|
400
|
+
const harness = mount();
|
|
401
|
+
await harness.ready();
|
|
402
|
+
await harness.press("/mcp reload");
|
|
403
|
+
await harness.press("\r");
|
|
404
|
+
await harness.drawn("not on disk yet");
|
|
405
|
+
});
|
|
406
|
+
|
|
407
|
+
const question = {
|
|
408
|
+
questionId: "q1",
|
|
409
|
+
prompt: "Which database?",
|
|
410
|
+
kind: "select" as const,
|
|
411
|
+
options: [
|
|
412
|
+
{ key: "0", label: "Postgres" },
|
|
413
|
+
{ key: "1", label: "SQLite", recommended: true },
|
|
414
|
+
],
|
|
415
|
+
freeText: true,
|
|
416
|
+
};
|
|
417
|
+
|
|
418
|
+
test("a recommended option is labelled and waiting under the cursor", async () => {
|
|
419
|
+
const harness = mount();
|
|
420
|
+
await harness.ready();
|
|
421
|
+
harness.emit({ type: "question", question });
|
|
422
|
+
await harness.drawn("SQLite (recommended)");
|
|
423
|
+
await harness.press("\r");
|
|
424
|
+
await eventually(() => expect(harness.agent.calls).toEqual(['answer:q1:{"keys":["1"]}']));
|
|
425
|
+
});
|
|
426
|
+
|
|
427
|
+
test("a question offering free text grows a choice that opens the prompt", async () => {
|
|
428
|
+
const harness = mount();
|
|
429
|
+
await harness.ready();
|
|
430
|
+
harness.emit({ type: "question", question });
|
|
431
|
+
await harness.drawn("Something else…");
|
|
432
|
+
await harness.press("\u001b[B");
|
|
433
|
+
await harness.press("\r");
|
|
434
|
+
await harness.drawn("esc back to the choices");
|
|
435
|
+
expect(harness.agent.calls).toEqual([]);
|
|
436
|
+
await harness.press("mysql, actually");
|
|
437
|
+
await harness.press("\r");
|
|
438
|
+
await eventually(() => expect(harness.agent.calls).toEqual(['answer:q1:{"text":"mysql, actually"}']));
|
|
439
|
+
});
|
|
440
|
+
|
|
441
|
+
test("escape out of typing goes back to the choices rather than skipping the question", async () => {
|
|
442
|
+
const harness = mount();
|
|
443
|
+
await harness.ready();
|
|
444
|
+
harness.emit({ type: "question", question });
|
|
445
|
+
await harness.drawn("Which database?");
|
|
446
|
+
await harness.press("\u001b[B");
|
|
447
|
+
await harness.press("\r");
|
|
448
|
+
await harness.drawn("esc back to the choices");
|
|
449
|
+
await harness.press("\u001b");
|
|
450
|
+
await eventually(() => {
|
|
451
|
+
expect(harness.stdout.lastFrame).toContain("SQLite (recommended)");
|
|
452
|
+
expect(harness.stdout.lastFrame).not.toContain("esc back to the choices");
|
|
453
|
+
});
|
|
454
|
+
expect(harness.agent.calls).toEqual([]);
|
|
455
|
+
await harness.press("\u001b[A");
|
|
456
|
+
await harness.press("\r");
|
|
457
|
+
await eventually(() => expect(harness.agent.calls).toEqual(['answer:q1:{"keys":["1"]}']));
|
|
458
|
+
});
|
|
459
|
+
|
|
460
|
+
test("a question with no options is answered in prose", async () => {
|
|
461
|
+
const harness = mount();
|
|
462
|
+
await harness.ready();
|
|
463
|
+
harness.emit({
|
|
464
|
+
type: "question",
|
|
465
|
+
question: { questionId: "q2", prompt: "Why is it slow?", kind: "text", freeText: true },
|
|
466
|
+
});
|
|
467
|
+
await harness.drawn("Why is it slow?");
|
|
468
|
+
await harness.press("the index is missing");
|
|
469
|
+
await harness.press("\r");
|
|
470
|
+
await eventually(() => expect(harness.agent.calls).toEqual(['answer:q2:{"text":"the index is missing"}']));
|
|
471
|
+
});
|
|
472
|
+
|
|
473
|
+
test("escape interrupts a running turn instead of clearing the line", async () => {
|
|
474
|
+
const harness = mount();
|
|
475
|
+
await harness.ready();
|
|
476
|
+
harness.emit({ type: "turn_start", turnId: "t1" });
|
|
477
|
+
await harness.press(esc);
|
|
478
|
+
await eventually(() => expect(harness.agent.calls).toEqual(["abort"]));
|
|
479
|
+
});
|
|
480
|
+
|
|
481
|
+
test("a select question is answered by key, not by the label a host happened to draw", async () => {
|
|
482
|
+
const harness = mount();
|
|
483
|
+
await harness.ready();
|
|
484
|
+
harness.emit({
|
|
485
|
+
type: "question",
|
|
486
|
+
question: {
|
|
487
|
+
questionId: "q1",
|
|
488
|
+
prompt: "Which app?",
|
|
489
|
+
kind: "select",
|
|
490
|
+
options: [
|
|
491
|
+
{ key: "akan", label: "akan" },
|
|
492
|
+
{ key: "minimal", label: "minimal" },
|
|
493
|
+
],
|
|
494
|
+
},
|
|
495
|
+
});
|
|
496
|
+
await harness.drawn("Which app?");
|
|
497
|
+
await harness.press(`${esc}[B`);
|
|
498
|
+
await harness.press("\r");
|
|
499
|
+
await eventually(() => expect(harness.agent.calls).toEqual(['answer:q1:{"keys":["minimal"]}']));
|
|
500
|
+
});
|
|
501
|
+
|
|
502
|
+
test("a multi-select keeps every ticked key, which is what a reconnecting client restores from", async () => {
|
|
503
|
+
const harness = mount();
|
|
504
|
+
await harness.ready();
|
|
505
|
+
harness.emit({
|
|
506
|
+
type: "question",
|
|
507
|
+
question: {
|
|
508
|
+
questionId: "q1",
|
|
509
|
+
prompt: "Which apps?",
|
|
510
|
+
kind: "select",
|
|
511
|
+
multiSelect: true,
|
|
512
|
+
options: [
|
|
513
|
+
{ key: "akan", label: "akan" },
|
|
514
|
+
{ key: "minimal", label: "minimal" },
|
|
515
|
+
],
|
|
516
|
+
},
|
|
517
|
+
});
|
|
518
|
+
await harness.drawn("Which apps?");
|
|
519
|
+
await harness.press(" ");
|
|
520
|
+
await harness.press(`${esc}[B`);
|
|
521
|
+
await harness.press(" ");
|
|
522
|
+
await harness.press("\r");
|
|
523
|
+
await eventually(() => expect(harness.agent.calls).toEqual(['answer:q1:{"keys":["akan","minimal"]}']));
|
|
524
|
+
});
|
|
525
|
+
|
|
526
|
+
test("an approval takes y or n and nothing else", async () => {
|
|
527
|
+
const harness = mount();
|
|
528
|
+
await harness.ready();
|
|
529
|
+
harness.emit({
|
|
530
|
+
type: "approval",
|
|
531
|
+
request: { approvalId: "a1", toolCallId: "c0", name: "write", summary: "write a.ts", policy: "writes" },
|
|
532
|
+
});
|
|
533
|
+
await harness.drawn("approve? write a.ts");
|
|
534
|
+
await harness.press("q");
|
|
535
|
+
expect(harness.agent.calls).toEqual([]);
|
|
536
|
+
await harness.press("n");
|
|
537
|
+
await eventually(() => expect(harness.agent.calls).toEqual(["approve:a1:false"]));
|
|
538
|
+
});
|
|
539
|
+
|
|
540
|
+
test("an approval that offers it takes a, which answers yes for the rest of the session", async () => {
|
|
541
|
+
const harness = mount();
|
|
542
|
+
await harness.ready();
|
|
543
|
+
harness.emit({
|
|
544
|
+
type: "approval",
|
|
545
|
+
request: {
|
|
546
|
+
approvalId: "a1",
|
|
547
|
+
toolCallId: "c0",
|
|
548
|
+
name: "bash",
|
|
549
|
+
summary: "run: bun test",
|
|
550
|
+
policy: "commands",
|
|
551
|
+
remember: ["bun test"],
|
|
552
|
+
},
|
|
553
|
+
});
|
|
554
|
+
await harness.drawn("approve? run: bun test [y/n/a]");
|
|
555
|
+
await harness.drawn("a yes, and stop asking about bun test this session");
|
|
556
|
+
await harness.press("a");
|
|
557
|
+
await eventually(() => expect(harness.agent.calls).toEqual(["approve:a1:true:session"]));
|
|
558
|
+
harness.emit({ type: "approval_resolved", approvalId: "a1", approved: true, remembered: ["bun test"] });
|
|
559
|
+
await harness.drawn("approved · bun test runs unasked until this session ends");
|
|
560
|
+
});
|
|
561
|
+
|
|
562
|
+
test("an approval that does not offer it ignores a", async () => {
|
|
563
|
+
const harness = mount();
|
|
564
|
+
await harness.ready();
|
|
565
|
+
harness.emit({
|
|
566
|
+
type: "approval",
|
|
567
|
+
request: { approvalId: "a1", toolCallId: "c0", name: "bash", summary: "run: git push", policy: "commands" },
|
|
568
|
+
});
|
|
569
|
+
await harness.drawn("approve? run: git push [y/n]");
|
|
570
|
+
expect(harness.stdout.lastFrame).not.toContain("stop asking");
|
|
571
|
+
await harness.press("a");
|
|
572
|
+
expect(harness.agent.calls).toEqual([]);
|
|
573
|
+
await harness.press("y");
|
|
574
|
+
await eventually(() => expect(harness.agent.calls).toEqual(["approve:a1:true"]));
|
|
575
|
+
});
|
|
576
|
+
|
|
577
|
+
test("/allowed lists what the session runs without asking, and /allowed clear forgets it", async () => {
|
|
578
|
+
const harness = mount();
|
|
579
|
+
await harness.ready();
|
|
580
|
+
await harness.press("/allowed");
|
|
581
|
+
await harness.press("\r");
|
|
582
|
+
await harness.drawn("Nothing is allowed for this session yet.");
|
|
583
|
+
await harness.press(esc);
|
|
584
|
+
harness.agent.allowedNames.push("bun test", "git status");
|
|
585
|
+
await harness.press("/allowed");
|
|
586
|
+
await harness.press("\r");
|
|
587
|
+
await eventually(() => {
|
|
588
|
+
expect(harness.stdout.lastFrame).toContain("bun test");
|
|
589
|
+
expect(harness.stdout.lastFrame).toContain("git status");
|
|
590
|
+
expect(harness.stdout.lastFrame).toContain("/allowed clear forgets them");
|
|
591
|
+
});
|
|
592
|
+
await harness.press(esc);
|
|
593
|
+
await harness.press("/allowed clear");
|
|
594
|
+
await harness.press("\r");
|
|
595
|
+
await harness.drawn("every command is asked about again");
|
|
596
|
+
expect(harness.agent.allowedNames).toEqual([]);
|
|
597
|
+
});
|
|
598
|
+
|
|
599
|
+
test("slash commands reach the core rather than the model", async () => {
|
|
600
|
+
const harness = mount();
|
|
601
|
+
await harness.ready();
|
|
602
|
+
await harness.press("/compact keep the plan");
|
|
603
|
+
await harness.press("\r");
|
|
604
|
+
await harness.press("/model deepseek/deepseek-v4-pro");
|
|
605
|
+
await harness.press("\r");
|
|
606
|
+
await eventually(() =>
|
|
607
|
+
expect(harness.agent.calls).toEqual(["compact:keep the plan", "setModel:deepseek/deepseek-v4-pro"]),
|
|
608
|
+
);
|
|
609
|
+
});
|
|
610
|
+
|
|
611
|
+
test("what the agent refuses, from a prompt or a command, lands in the transcript as an error", async () => {
|
|
612
|
+
const harness = mount();
|
|
613
|
+
await harness.ready();
|
|
614
|
+
harness.agent.refusal = "the provider is down";
|
|
615
|
+
await harness.press("hi");
|
|
616
|
+
await harness.press("\r");
|
|
617
|
+
await harness.drawn("the provider is down");
|
|
618
|
+
harness.agent.refusal = "no such model";
|
|
619
|
+
await harness.press("/model deepseek/nope");
|
|
620
|
+
await harness.press("\r");
|
|
621
|
+
await harness.drawn("no such model");
|
|
622
|
+
});
|
|
623
|
+
|
|
624
|
+
test("an unknown slash command answers in an overlay and leaves the transcript alone", async () => {
|
|
625
|
+
const harness = mount();
|
|
626
|
+
await harness.ready();
|
|
627
|
+
await harness.press("hello there");
|
|
628
|
+
await harness.press("\r");
|
|
629
|
+
await harness.press("/nope");
|
|
630
|
+
await harness.press("\r");
|
|
631
|
+
await eventually(() => {
|
|
632
|
+
expect(harness.stdout.lastFrame).toContain("There is no /nope");
|
|
633
|
+
expect(harness.stdout.lastFrame).not.toContain("› hello there");
|
|
634
|
+
});
|
|
635
|
+
expect(harness.agent.calls).toEqual(["prompt:hello there"]);
|
|
636
|
+
await harness.press(esc);
|
|
637
|
+
await eventually(() => {
|
|
638
|
+
expect(harness.stdout.lastFrame).toContain("› hello there");
|
|
639
|
+
expect(harness.stdout.lastFrame).not.toContain("There is no /nope");
|
|
640
|
+
});
|
|
641
|
+
});
|
|
642
|
+
|
|
643
|
+
test("the arrows scroll an overlay longer than the pane, not the transcript under it", async () => {
|
|
644
|
+
const harness = mount();
|
|
645
|
+
await harness.ready();
|
|
646
|
+
for (let at = 0; at < 40; at += 1)
|
|
647
|
+
harness.agent.emit({ type: "message", turnId: `t${at}`, role: "assistant", text: `line ${at}` });
|
|
648
|
+
await harness.press("/help");
|
|
649
|
+
await harness.press("\r");
|
|
650
|
+
await harness.drawn("help ▲0 ▼");
|
|
651
|
+
await harness.press(`${esc}[B`);
|
|
652
|
+
await harness.drawn("help ▲1 ▼");
|
|
653
|
+
await harness.press(esc);
|
|
654
|
+
await harness.drawn("line 39");
|
|
655
|
+
expect(harness.stdout.lastFrame).not.toContain("paused");
|
|
656
|
+
});
|
|
657
|
+
|
|
658
|
+
test("the arrows replay what was already sent", async () => {
|
|
659
|
+
const harness = mount();
|
|
660
|
+
await harness.ready();
|
|
661
|
+
await harness.press("first");
|
|
662
|
+
await harness.press("\r");
|
|
663
|
+
const promptRow = () => {
|
|
664
|
+
const caret = caretOf(harness.stdout);
|
|
665
|
+
return caret?.lines[caret.row];
|
|
666
|
+
};
|
|
667
|
+
await eventually(() => expect(promptRow()).toContain("ask for something"));
|
|
668
|
+
await harness.press(`${esc}[A`);
|
|
669
|
+
await eventually(() => expect(promptRow()).toBe("› first"));
|
|
670
|
+
await harness.press("\r");
|
|
671
|
+
await eventually(() => expect(harness.agent.calls).toEqual(["prompt:first", "prompt:first"]));
|
|
672
|
+
});
|
|
673
|
+
|
|
674
|
+
test("a tool call is one row from start to end", async () => {
|
|
675
|
+
const harness = mount();
|
|
676
|
+
await harness.ready();
|
|
677
|
+
const tool = { toolCallId: "c0", name: "read", op: "read" as const, title: "read(a.ts)" };
|
|
678
|
+
harness.emit({ type: "tool_start", turnId: "t1", tool });
|
|
679
|
+
harness.emit({ type: "tool_end", turnId: "t1", tool, outcome: "ok", output: "", truncated: false });
|
|
680
|
+
await eventually(() => {
|
|
681
|
+
const frame = harness.stdout.lastFrame;
|
|
682
|
+
expect(frame.split("read(a.ts)").length - 1).toBe(1);
|
|
683
|
+
expect(frame).toContain("⏺ read(a.ts)");
|
|
684
|
+
});
|
|
685
|
+
});
|
|
686
|
+
|
|
687
|
+
test("a pasted block keeps its newlines instead of sending a fragment", async () => {
|
|
688
|
+
const harness = mount();
|
|
689
|
+
await harness.ready();
|
|
690
|
+
await harness.press("fix this:\r at foo (a.ts:1)\r at bar (b.ts:2)");
|
|
691
|
+
await eventually(() => {
|
|
692
|
+
expect(harness.stdout.lastFrame).toContain("fix this:");
|
|
693
|
+
expect(harness.stdout.lastFrame).toContain("at foo (a.ts:1)");
|
|
694
|
+
expect(harness.stdout.lastFrame).toContain("at bar (b.ts:2)");
|
|
695
|
+
});
|
|
696
|
+
expect(harness.agent.calls).toEqual([]);
|
|
697
|
+
await harness.press("\r");
|
|
698
|
+
await eventually(() =>
|
|
699
|
+
expect(harness.agent.calls).toEqual(["prompt:fix this:\n at foo (a.ts:1)\n at bar (b.ts:2)"]),
|
|
700
|
+
);
|
|
701
|
+
});
|
|
702
|
+
|
|
703
|
+
test("typing a slash opens a menu of commands above the input", async () => {
|
|
704
|
+
const harness = mount();
|
|
705
|
+
await harness.ready();
|
|
706
|
+
await harness.press("/");
|
|
707
|
+
await eventually(() => {
|
|
708
|
+
expect(harness.stdout.lastFrame).toContain("/compact");
|
|
709
|
+
expect(harness.stdout.lastFrame).toContain("/model");
|
|
710
|
+
});
|
|
711
|
+
await harness.press("mo");
|
|
712
|
+
await eventually(() => {
|
|
713
|
+
const frame = harness.stdout.lastFrame;
|
|
714
|
+
expect(frame).toContain("/model");
|
|
715
|
+
expect(frame).not.toContain("/compact");
|
|
716
|
+
});
|
|
717
|
+
});
|
|
718
|
+
|
|
719
|
+
test("tab completes the highlighted command, with the space its argument needs", async () => {
|
|
720
|
+
const harness = mount();
|
|
721
|
+
await harness.ready();
|
|
722
|
+
await harness.press("/mo");
|
|
723
|
+
await harness.press("\t");
|
|
724
|
+
await eventually(() => {
|
|
725
|
+
const frame = harness.stdout.lastFrame;
|
|
726
|
+
expect(frame).toContain("› /model");
|
|
727
|
+
expect(frame).not.toContain("switch model");
|
|
728
|
+
});
|
|
729
|
+
await quiet();
|
|
730
|
+
expect(harness.agent.calls).toEqual([]);
|
|
731
|
+
});
|
|
732
|
+
|
|
733
|
+
test("the arrows walk the menu while it is open, not the history", async () => {
|
|
734
|
+
const harness = mount();
|
|
735
|
+
await harness.ready();
|
|
736
|
+
await harness.press("/");
|
|
737
|
+
await harness.press(`${esc}[B`);
|
|
738
|
+
await harness.press("\t");
|
|
739
|
+
await harness.drawn("› /tools");
|
|
740
|
+
});
|
|
741
|
+
|
|
742
|
+
test("a line feed opens a second line and enter still sends the whole buffer", async () => {
|
|
743
|
+
const harness = mount();
|
|
744
|
+
await harness.ready();
|
|
745
|
+
await harness.press("first");
|
|
746
|
+
await harness.press(String.fromCharCode(10));
|
|
747
|
+
await harness.press("second");
|
|
748
|
+
await eventually(() => {
|
|
749
|
+
const frame = harness.stdout.lastFrame;
|
|
750
|
+
expect(frame).toContain("› first");
|
|
751
|
+
expect(frame).toContain("second");
|
|
752
|
+
});
|
|
753
|
+
await harness.press("\r");
|
|
754
|
+
await eventually(() => expect(harness.agent.calls).toEqual(["prompt:first\nsecond"]));
|
|
755
|
+
});
|
|
756
|
+
|
|
757
|
+
test("a shift+enter binding breaks the line without leaving its backslash behind", async () => {
|
|
758
|
+
for (const ending of [String.fromCharCode(13), String.fromCharCode(10), `${esc}${String.fromCharCode(13)}`]) {
|
|
759
|
+
const harness = mount();
|
|
760
|
+
await harness.ready();
|
|
761
|
+
await harness.press("first");
|
|
762
|
+
await harness.press(`\\${ending}`);
|
|
763
|
+
await harness.press("second");
|
|
764
|
+
await harness.drawn("second");
|
|
765
|
+
expect(harness.stdout.lastFrame).not.toContain("\\");
|
|
766
|
+
await harness.press("\r");
|
|
767
|
+
await eventually(() => expect(harness.agent.calls).toEqual(["prompt:first\nsecond"]));
|
|
768
|
+
}
|
|
769
|
+
});
|
|
770
|
+
|
|
771
|
+
test("a backslash the user typed survives the line break after it", async () => {
|
|
772
|
+
const harness = mount();
|
|
773
|
+
await harness.ready();
|
|
774
|
+
await harness.press("a\\");
|
|
775
|
+
await harness.press(`\\${String.fromCharCode(13)}`);
|
|
776
|
+
await harness.press("b");
|
|
777
|
+
await harness.press("\r");
|
|
778
|
+
await eventually(() => expect(harness.agent.calls).toEqual(["prompt:a\\\nb"]));
|
|
779
|
+
});
|
|
780
|
+
|
|
781
|
+
test("the arrows move inside a multi-line prompt before they reach history", async () => {
|
|
782
|
+
const harness = mount();
|
|
783
|
+
await harness.ready();
|
|
784
|
+
await harness.press("sent");
|
|
785
|
+
await harness.press("\r");
|
|
786
|
+
await harness.press("one");
|
|
787
|
+
await harness.press(String.fromCharCode(10));
|
|
788
|
+
await harness.press("two");
|
|
789
|
+
const promptRow = () => {
|
|
790
|
+
const caret = caretOf(harness.stdout);
|
|
791
|
+
return caret?.lines[caret.row];
|
|
792
|
+
};
|
|
793
|
+
await eventually(() => expect(promptRow()).toContain("two"));
|
|
794
|
+
await harness.press(`${esc}[A`);
|
|
795
|
+
await eventually(() => expect(promptRow()).toBe("› one"));
|
|
796
|
+
await harness.press(`${esc}[A`);
|
|
797
|
+
await eventually(() => expect(promptRow()).toBe("› sent"));
|
|
798
|
+
});
|
|
799
|
+
|
|
800
|
+
test("the terminal cursor lands on the prompt row, after what has been typed", async () => {
|
|
801
|
+
const harness = mount();
|
|
802
|
+
await harness.ready();
|
|
803
|
+
await harness.press("hello");
|
|
804
|
+
await eventually(() => {
|
|
805
|
+
const caret = caretOf(harness.stdout);
|
|
806
|
+
expect(caret).toBeDefined();
|
|
807
|
+
expect(caret?.lines[caret.row]).toContain("› hello");
|
|
808
|
+
expect(caret?.column).toBe("› hello".length);
|
|
809
|
+
});
|
|
810
|
+
});
|
|
811
|
+
|
|
812
|
+
test("the prompt sits between two rules", async () => {
|
|
813
|
+
const harness = mount();
|
|
814
|
+
await harness.ready();
|
|
815
|
+
await eventually(() => {
|
|
816
|
+
expect(harness.stdout.lastFrame.split("─").length - 1).toBeGreaterThan(2);
|
|
817
|
+
expect(harness.stdout.lastFrame).not.toContain("│");
|
|
818
|
+
});
|
|
819
|
+
});
|
|
820
|
+
|
|
821
|
+
test("enter runs the highlighted command, whether or not it was typed out in full", async () => {
|
|
822
|
+
const harness = mount();
|
|
823
|
+
await harness.ready();
|
|
824
|
+
await harness.press("/help");
|
|
825
|
+
await harness.press("\r");
|
|
826
|
+
await harness.drawn("list these commands and the keys");
|
|
827
|
+
expect(harness.agent.calls).toEqual([]);
|
|
828
|
+
await harness.press(esc);
|
|
829
|
+
await harness.press("/ab");
|
|
830
|
+
await harness.press("\r");
|
|
831
|
+
await eventually(() => expect(harness.agent.calls).toEqual(["abort"]));
|
|
832
|
+
});
|
|
833
|
+
|
|
834
|
+
test("reasoning is folded to one line until it is asked for", async () => {
|
|
835
|
+
const harness = mount();
|
|
836
|
+
await harness.ready();
|
|
837
|
+
harness.emit({ type: "turn_start", turnId: "t1" });
|
|
838
|
+
harness.emit({ type: "thinking_delta", turnId: "t1", text: "the user said hi\nkeep it short" });
|
|
839
|
+
await eventually(() => {
|
|
840
|
+
expect(harness.stdout.lastFrame).toContain("thinking · 2 lines");
|
|
841
|
+
expect(harness.stdout.lastFrame).not.toContain("keep it short");
|
|
842
|
+
});
|
|
843
|
+
await harness.press("/thinking");
|
|
844
|
+
await harness.press("\r");
|
|
845
|
+
await harness.drawn("keep it short");
|
|
846
|
+
});
|
|
847
|
+
|
|
848
|
+
test("ZZ down walks history back", async () => {
|
|
849
|
+
const harness = mount();
|
|
850
|
+
await harness.ready();
|
|
851
|
+
await harness.press("one");
|
|
852
|
+
await harness.press("\r");
|
|
853
|
+
await harness.press("two");
|
|
854
|
+
await harness.press("\r");
|
|
855
|
+
const promptRow = () => {
|
|
856
|
+
const caret = caretOf(harness.stdout);
|
|
857
|
+
return caret?.lines[caret.row];
|
|
858
|
+
};
|
|
859
|
+
await harness.press(`${esc}[A`);
|
|
860
|
+
await eventually(() => expect(promptRow()).toBe("› two"));
|
|
861
|
+
await harness.press(`${esc}[A`);
|
|
862
|
+
await eventually(() => expect(promptRow()).toBe("› one"));
|
|
863
|
+
await harness.press(`${esc}[B`);
|
|
864
|
+
await eventually(() => expect(promptRow()).toBe("› two"));
|
|
865
|
+
await harness.press(`${esc}[B`);
|
|
866
|
+
await eventually(() => expect(promptRow()).toContain("ask for something"));
|
|
867
|
+
});
|
|
868
|
+
|
|
869
|
+
test("model, window, profile and effort ride the prompt's lower rule", async () => {
|
|
870
|
+
const harness = mount();
|
|
871
|
+
await harness.ready();
|
|
872
|
+
harness.emit({ type: "context", used: 250_000, max: 1_000_000 });
|
|
873
|
+
await eventually(() => {
|
|
874
|
+
expect(harness.stdout.lastFrame).toContain("DeepSeek V4 Flash · 25% of 1000k · local · medium");
|
|
875
|
+
expect(harness.stdout.lastFrame).toContain("s1 ─");
|
|
876
|
+
});
|
|
877
|
+
});
|
|
878
|
+
|
|
879
|
+
test("/effort lists what the model offers when it is given nothing it knows", async () => {
|
|
880
|
+
const harness = mount();
|
|
881
|
+
await harness.ready();
|
|
882
|
+
await harness.press("/effort");
|
|
883
|
+
await harness.press("\r");
|
|
884
|
+
await harness.drawn("low · medium · high");
|
|
885
|
+
expect(harness.agent.calls).toEqual([]);
|
|
886
|
+
await harness.press(esc);
|
|
887
|
+
await harness.press("/effort high");
|
|
888
|
+
await harness.press("\r");
|
|
889
|
+
await eventually(() => expect(harness.agent.calls).toEqual(["setEffort:high"]));
|
|
890
|
+
});
|
|
891
|
+
|
|
892
|
+
test("/autocompact says where compaction starts, and the lower rule keeps a chosen share in view", async () => {
|
|
893
|
+
const harness = mount();
|
|
894
|
+
await harness.ready();
|
|
895
|
+
await harness.press("/autocompact 55");
|
|
896
|
+
await harness.press("\r");
|
|
897
|
+
await harness.drawn("now: autocompact default · compacts above 967k of 1000k");
|
|
898
|
+
expect(harness.agent.calls).toEqual([]);
|
|
899
|
+
await harness.press(esc);
|
|
900
|
+
await harness.press("/autocompact 60%");
|
|
901
|
+
await harness.press("\r");
|
|
902
|
+
await eventually(() => expect(harness.agent.calls).toEqual(["setAutoCompactAt:60"]));
|
|
903
|
+
await harness.drawn("autocompact 60% · compacts above 600k of 1000k");
|
|
904
|
+
harness.emit({ type: "context", used: 250_000, max: 1_000_000 });
|
|
905
|
+
await harness.drawn("DeepSeek V4 Flash · 25% of 1000k · compacts at 60% · local · medium");
|
|
906
|
+
});
|
|
907
|
+
|
|
908
|
+
test("a session takes a name from what it was first asked, and /name replaces it", async () => {
|
|
909
|
+
const harness = mount();
|
|
910
|
+
await harness.ready();
|
|
911
|
+
await harness.press("/name refactor the store layer");
|
|
912
|
+
await harness.press("\r");
|
|
913
|
+
await eventually(() => expect(harness.agent.calls).toEqual(["setName:refactor the store layer"]));
|
|
914
|
+
harness.emit({ type: "session", info: { ...info, name: "refactor-the-store-layer" } });
|
|
915
|
+
await harness.drawn("refactor-the-store-layer");
|
|
916
|
+
});
|
|
917
|
+
|
|
918
|
+
test("left at the start lists stored sessions, and enter leaves for the one chosen", async () => {
|
|
919
|
+
const harness = mount();
|
|
920
|
+
harness.agent.stored = [
|
|
921
|
+
{ id: "s1", name: "current-one", opening: "fix the gateway", updatedAt: Date.now(), turns: 2 },
|
|
922
|
+
{ id: "s2", name: "older-one", opening: "add a comment module", updatedAt: Date.now() - 7_200_000, turns: 9 },
|
|
923
|
+
];
|
|
924
|
+
await harness.ready();
|
|
925
|
+
await harness.press(`${esc}[D`);
|
|
926
|
+
await eventually(() => {
|
|
927
|
+
expect(harness.stdout.lastFrame).toContain("older-one");
|
|
928
|
+
expect(harness.stdout.lastFrame).toContain("add a comment module");
|
|
929
|
+
expect(harness.stdout.lastFrame).toContain("2h ago");
|
|
930
|
+
});
|
|
931
|
+
await harness.press(`${esc}[B`);
|
|
932
|
+
await harness.press("\r");
|
|
933
|
+
expect((await harness.done)?.id).toBe("s2");
|
|
934
|
+
});
|
|
935
|
+
|
|
936
|
+
test("ctrl+v says so rather than attaching when the model cannot read images", async () => {
|
|
937
|
+
const harness = mount();
|
|
938
|
+
harness.agent.canSeeImages = false;
|
|
939
|
+
await harness.ready();
|
|
940
|
+
await harness.press(String.fromCharCode(22));
|
|
941
|
+
await eventually(() => {
|
|
942
|
+
const frame = harness.stdout.lastFrame;
|
|
943
|
+
expect(frame).toContain("declares deepseek/deepseek-v4-flash text-only");
|
|
944
|
+
expect(frame).toContain("modelOverrides");
|
|
945
|
+
});
|
|
946
|
+
});
|
|
947
|
+
|
|
948
|
+
test("an empty bracketed paste attaches the picture the clipboard was holding", async () => {
|
|
949
|
+
const harness = mount();
|
|
950
|
+
await harness.ready();
|
|
951
|
+
const file = path.join(tmpdir(), "clipboard.png");
|
|
952
|
+
await Bun.write(file, new Uint8Array([0x89, 0x50, 0x4e, 0x47]));
|
|
953
|
+
const had = { has: CodeTuiClipboard.has, image: CodeTuiClipboard.image };
|
|
954
|
+
CodeTuiClipboard.has = () => true;
|
|
955
|
+
CodeTuiClipboard.image = () => Promise.resolve(file);
|
|
956
|
+
try {
|
|
957
|
+
await harness.press(`${esc}[200~${esc}[201~`);
|
|
958
|
+
await harness.drawn("[image #1]");
|
|
959
|
+
} finally {
|
|
960
|
+
Object.assign(CodeTuiClipboard, had);
|
|
961
|
+
}
|
|
962
|
+
});
|
|
963
|
+
|
|
964
|
+
test("an empty bracketed paste with an empty clipboard does nothing at all", async () => {
|
|
965
|
+
const harness = mount();
|
|
966
|
+
await harness.ready();
|
|
967
|
+
const had = CodeTuiClipboard.has;
|
|
968
|
+
CodeTuiClipboard.has = () => false;
|
|
969
|
+
try {
|
|
970
|
+
await harness.press(`${esc}[200~${esc}[201~`);
|
|
971
|
+
await quiet();
|
|
972
|
+
expect(harness.stdout.lastFrame).toContain("ask for something");
|
|
973
|
+
expect(harness.stdout.lastFrame).not.toContain("[image");
|
|
974
|
+
} finally {
|
|
975
|
+
CodeTuiClipboard.has = had;
|
|
976
|
+
}
|
|
977
|
+
});
|
|
978
|
+
|
|
979
|
+
test("an image arriving on the clipboard is offered above the prompt", async () => {
|
|
980
|
+
const had = CodeTuiClipboard.has;
|
|
981
|
+
CodeTuiClipboard.has = () => true;
|
|
982
|
+
try {
|
|
983
|
+
const harness = mount();
|
|
984
|
+
await harness.drawn("an image is on your clipboard", 2 * CodeTui.clipboardMs);
|
|
985
|
+
} finally {
|
|
986
|
+
CodeTuiClipboard.has = had;
|
|
987
|
+
}
|
|
988
|
+
}, 10_000);
|
|
989
|
+
|
|
990
|
+
test("a bracketed paste keeps its newlines instead of sending the prompt", async () => {
|
|
991
|
+
const harness = mount();
|
|
992
|
+
await harness.ready();
|
|
993
|
+
await harness.press(`${esc}[200~fix this:\rat foo (a.ts:1)\r${esc}[201~`);
|
|
994
|
+
await harness.drawn("at foo (a.ts:1)");
|
|
995
|
+
expect(harness.agent.calls).toEqual([]);
|
|
996
|
+
await harness.press("\r");
|
|
997
|
+
await eventually(() => expect(harness.agent.calls).toEqual(["prompt:fix this:\nat foo (a.ts:1)"]));
|
|
998
|
+
});
|
|
999
|
+
|
|
1000
|
+
test("a bracketed paste ending in a newline runs nothing", async () => {
|
|
1001
|
+
const harness = mount();
|
|
1002
|
+
await harness.ready();
|
|
1003
|
+
await harness.press(`${esc}[200~/help\r${esc}[201~`);
|
|
1004
|
+
await harness.drawn("/help");
|
|
1005
|
+
await quiet();
|
|
1006
|
+
const frame = harness.stdout.lastFrame;
|
|
1007
|
+
expect(frame).not.toContain("list these commands");
|
|
1008
|
+
expect(frame).not.toContain("200~");
|
|
1009
|
+
});
|
|
1010
|
+
|
|
1011
|
+
test("a pasted image path becomes a marker in the prompt, and the marker is the attachment", async () => {
|
|
1012
|
+
const harness = mount();
|
|
1013
|
+
await harness.ready();
|
|
1014
|
+
const file = path.join(tmpdir(), "Screenshot at 20.11.02.png");
|
|
1015
|
+
await Bun.write(file, new Uint8Array([0x89, 0x50, 0x4e, 0x47]));
|
|
1016
|
+
// Escaped spaces, the way a terminal writes a dragged or pasted path.
|
|
1017
|
+
await harness.press(file.replace(/[\\ ]/g, "\\$&"));
|
|
1018
|
+
await harness.drawn("[image #1]");
|
|
1019
|
+
expect(harness.stdout.lastFrame).not.toContain("Screenshot at");
|
|
1020
|
+
await harness.press("look at this");
|
|
1021
|
+
await harness.press("\r");
|
|
1022
|
+
await eventually(() => expect(harness.agent.calls).toEqual([`prompt:look at this:${file}`]));
|
|
1023
|
+
await harness.drawn("⧉ 1 image");
|
|
1024
|
+
harness.emit({ type: "message", turnId: "t1", role: "user", text: "look at this" });
|
|
1025
|
+
await quiet();
|
|
1026
|
+
expect(harness.stdout.lastFrame.split("› look at this").length - 1).toBe(1);
|
|
1027
|
+
});
|
|
1028
|
+
|
|
1029
|
+
test("deleting the marker before sending un-attaches the image", async () => {
|
|
1030
|
+
const harness = mount();
|
|
1031
|
+
await harness.ready();
|
|
1032
|
+
const file = path.join(tmpdir(), "akan-paste.png");
|
|
1033
|
+
await Bun.write(file, new Uint8Array([0x89, 0x50, 0x4e, 0x47]));
|
|
1034
|
+
await harness.press(file);
|
|
1035
|
+
await harness.press("never mind");
|
|
1036
|
+
for (let at = 0; at < "never mind".length + "[image #1] ".length; at += 1) await harness.press(keys.backspace);
|
|
1037
|
+
await harness.press("just text");
|
|
1038
|
+
await harness.press("\r");
|
|
1039
|
+
await eventually(() => expect(harness.agent.calls).toEqual(["prompt:just text"]));
|
|
1040
|
+
});
|
|
1041
|
+
|
|
1042
|
+
//? Retried: it timed out once in CI with the file list still pending (run 42854281601, attempt 1).
|
|
1043
|
+
test(
|
|
1044
|
+
"an @ token completes a file in the repo",
|
|
1045
|
+
async () => {
|
|
1046
|
+
//? A repo of its own: CI unpacks the workspace from a tarball without `.git`, so the checkout lists nothing.
|
|
1047
|
+
const root = mkdtempSync(path.join(tmpdir(), "akan-tui-files-"));
|
|
1048
|
+
mkdirSync(path.join(root, "pkgs/cli/code"), { recursive: true });
|
|
1049
|
+
writeFileSync(path.join(root, "pkgs/cli/code/CodeTuiFiles.ts"), "");
|
|
1050
|
+
Bun.spawnSync(["git", "init", "--quiet"], { cwd: root });
|
|
1051
|
+
const harness = mount(root);
|
|
1052
|
+
await harness.ready();
|
|
1053
|
+
await harness.press("read @codeTuiFiles");
|
|
1054
|
+
await harness.drawn("@pkgs/cli/code/CodeTuiFiles.ts", 5_000);
|
|
1055
|
+
await harness.press("\t");
|
|
1056
|
+
await harness.drawn("› read @pkgs/cli/code/CodeTuiFiles.ts");
|
|
1057
|
+
await removeOnceReleased(root);
|
|
1058
|
+
},
|
|
1059
|
+
{ timeout: 10_000, retry: 1 },
|
|
1060
|
+
);
|
|
1061
|
+
|
|
1062
|
+
test("the banner names the session at the top and survives what clears the conversation", async () => {
|
|
1063
|
+
const harness = mount();
|
|
1064
|
+
await harness.ready();
|
|
1065
|
+
await harness.drawn("Akan — write one line, deploy every stack");
|
|
1066
|
+
await harness.press("remember this");
|
|
1067
|
+
await harness.press("\r");
|
|
1068
|
+
await eventually(() => expect(harness.agent.calls).toEqual(["prompt:remember this"]));
|
|
1069
|
+
await harness.drawn("› remember this");
|
|
1070
|
+
await harness.press("/clear");
|
|
1071
|
+
await harness.press("\r");
|
|
1072
|
+
await eventually(() => {
|
|
1073
|
+
expect(harness.stdout.lastFrame).not.toContain("› remember this");
|
|
1074
|
+
expect(harness.stdout.lastFrame).toContain("Akan — write one line, deploy every stack");
|
|
1075
|
+
expect(harness.stdout.lastFrame).toContain("the model still remembers");
|
|
1076
|
+
});
|
|
1077
|
+
});
|
|
1078
|
+
|
|
1079
|
+
test("down walks back through history, whatever the recalled entry's height", async () => {
|
|
1080
|
+
const harness = mount();
|
|
1081
|
+
await harness.ready();
|
|
1082
|
+
await harness.press(`one ${"long ".repeat(30)}`);
|
|
1083
|
+
await harness.press("\r");
|
|
1084
|
+
await harness.press("two");
|
|
1085
|
+
await harness.press("\r");
|
|
1086
|
+
// The transcript echoes each entry as ` › …`, so only the rows from the prompt's `› ` down to the caret are read.
|
|
1087
|
+
const prompt = () => {
|
|
1088
|
+
const caret = caretOf(harness.stdout);
|
|
1089
|
+
let top = caret?.row ?? 0;
|
|
1090
|
+
while (top > 0 && !caret?.lines[top]?.startsWith("› ")) top -= 1;
|
|
1091
|
+
return caret ? caret.lines.slice(top, caret.row + 1) : [];
|
|
1092
|
+
};
|
|
1093
|
+
await harness.press(`${esc}[A`);
|
|
1094
|
+
await harness.press(`${esc}[A`);
|
|
1095
|
+
await eventually(() => {
|
|
1096
|
+
expect(prompt()[0]).toStartWith("› one long");
|
|
1097
|
+
expect(prompt().length).toBeGreaterThan(1);
|
|
1098
|
+
});
|
|
1099
|
+
await harness.press(`${esc}[B`);
|
|
1100
|
+
await eventually(() => expect(prompt()).toEqual(["› two"]));
|
|
1101
|
+
await harness.press(`${esc}[B`);
|
|
1102
|
+
await eventually(() => expect(prompt().join("\n")).toContain("ask for something"));
|
|
1103
|
+
});
|
|
1104
|
+
});
|