-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcommands.test.ts
More file actions
547 lines (490 loc) · 21.2 KB
/
Copy pathcommands.test.ts
File metadata and controls
547 lines (490 loc) · 21.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
import { describe, expect, it } from "vitest";
import { commandPlacement, parseCommand, paletteCommands } from "../commands";
import { buildLinearToolRequest, parseLinearArgs } from "../linearCommands";
describe("commands", () => {
it("parses multi-word ADE commands before generic slash commands", () => {
const parsed = parseCommand("/linear pull ADE-123");
expect(parsed?.name).toBe("/linear pull");
expect(parsed?.args).toBe("ADE-123");
expect(parsed ? commandPlacement(parsed) : null).toBe("right");
});
it("routes the generic ADE action escape hatch to the right pane", () => {
const parsed = parseCommand("/ade git.listBranches {\"laneId\":\"lane-1\"}");
expect(parsed?.name).toBe("/ade");
expect(parsed?.args).toBe("git.listBranches {\"laneId\":\"lane-1\"}");
expect(parsed ? commandPlacement(parsed) : null).toBe("right");
});
it("routes PR comments to the right pane", () => {
const parsed = parseCommand("/pr comments");
expect(parsed?.name).toBe("/pr comments");
expect(parsed ? commandPlacement(parsed) : null).toBe("right");
expect(paletteCommands("/pr comm")).toContainEqual(expect.objectContaining({
name: "/pr comments",
source: "ade",
description: "Show actionable PR comments",
}));
});
it("parses /pr update-branch as a multi-word ADE command with a strategy arg", () => {
const withStrategy = parseCommand("/pr update-branch rebase");
expect(withStrategy?.name).toBe("/pr update-branch");
expect(withStrategy?.args).toBe("rebase");
expect(withStrategy ? commandPlacement(withStrategy) : null).toBe("right");
const bare = parseCommand("/pr update-branch");
expect(bare?.name).toBe("/pr update-branch");
expect(bare?.args).toBe("");
// Must not shadow the sibling /pr land command.
expect(parseCommand("/pr land confirm squash bypass")?.name).toBe("/pr land");
expect(paletteCommands("/pr update")).toContainEqual(expect.objectContaining({
name: "/pr update-branch",
source: "ade",
}));
});
it("routes lane reparent to the right pane", () => {
const parsed = parseCommand("/reparent lane-parent origin/main");
expect(parsed?.name).toBe("/reparent");
expect(parsed?.args).toBe("lane-parent origin/main");
expect(parsed ? commandPlacement(parsed) : null).toBe("right");
expect(paletteCommands("/rep")).toContainEqual(expect.objectContaining({
name: "/reparent",
source: "ade",
description: "Move the active lane under another lane",
}));
});
it("parses the /lane management commands as multi-word ADE commands", () => {
const rename = parseCommand("/lane rename My New Lane");
expect(rename?.name).toBe("/lane rename");
expect(rename?.args).toBe("My New Lane");
expect(rename ? commandPlacement(rename) : null).toBe("right");
const archive = parseCommand("/lane archive");
expect(archive?.name).toBe("/lane archive");
expect(archive?.args).toBe("");
const unarchive = parseCommand("/lane unarchive feat/x");
expect(unarchive?.name).toBe("/lane unarchive");
expect(unarchive?.args).toBe("feat/x");
// /lane delete must still match (longest-name-first ordering).
expect(parseCommand("/lane delete")?.name).toBe("/lane delete");
expect(paletteCommands("/lane").map((c) => c.name)).toEqual(
expect.arrayContaining(["/lane rename", "/lane archive", "/lane unarchive", "/lane archived", "/lane delete"]),
);
});
it("routes /effort to the ADE Code right pane", () => {
const parsed = parseCommand("/effort");
expect(parsed?.spec?.name).toBe("/effort");
expect(parsed ? commandPlacement(parsed) : null).toBe("right");
expect(paletteCommands("/eff")).toContainEqual(expect.objectContaining({
name: "/effort",
source: "ade",
description: "Open the reasoning-effort picker",
}));
});
it("routes /feedback to the ADE Code right pane", () => {
const parsed = parseCommand("/feedback");
expect(parsed?.spec?.name).toBe("/feedback");
expect(parsed ? commandPlacement(parsed) : null).toBe("right");
expect(paletteCommands("/feed")).toContainEqual(expect.objectContaining({
name: "/feedback",
source: "ade",
description: "Submit ADE feedback to GitHub issues",
}));
});
it("routes runtime commands to chat", () => {
const parsed = parseCommand("/ship now", [
{ name: "/ship", description: "Ship it", source: "sdk" },
]);
expect(parsed?.userCommand?.name).toBe("/ship");
expect(parsed ? commandPlacement(parsed) : null).toBe("chat");
});
it("routes Codex /fast arguments to chat", () => {
const parsed = parseCommand("/fast on", [
{ name: "/fast", description: "Toggle Fast mode for supported models", source: "sdk", argumentHint: "[on|off|status]" },
]);
expect(parsed?.name).toBe("/fast");
expect(parsed?.args).toBe("on");
expect(parsed?.userCommand?.name).toBe("/fast");
expect(parsed ? commandPlacement(parsed) : null).toBe("chat");
});
it("keeps single-word ADE pane commands local on exact name", () => {
const parsed = parseCommand("/status please", [
{ name: "/status", description: "Runtime status", source: "sdk" },
]);
expect(parsed?.spec?.name).toBe("/status");
expect(parsed?.userCommand).toBeNull();
expect(parsed ? commandPlacement(parsed) : null).toBe("right");
const feedback = parseCommand("/feedback", [
{ name: "/feedback", description: "Runtime feedback", source: "sdk" },
]);
expect(feedback?.spec?.name).toBe("/feedback");
expect(feedback?.userCommand).toBeNull();
expect(feedback ? commandPlacement(feedback) : null).toBe("right");
});
it("keeps provider login as an ADE-code terminal command", () => {
const parsed = parseCommand("/login", [
{ name: "/login", description: "Claude SDK login", source: "sdk" },
]);
expect(parsed?.spec?.name).toBe("/login");
expect(parsed?.userCommand).toBeNull();
expect(parsed ? commandPlacement(parsed) : null).toBe("inline");
});
it("keeps terminal control commands in ADE Code", () => {
const parsed = parseCommand("/quit", [
{ name: "/quit", description: "Runtime quit", source: "sdk" },
]);
expect(parsed?.spec?.name).toBe("/quit");
expect(parsed?.userCommand).toBeNull();
expect(parsed ? commandPlacement(parsed) : null).toBe("inline");
});
it("keeps multi-word ADE commands ahead of first-token runtime commands", () => {
const parsed = parseCommand("/new lane perf-pass", [
{ name: "/new", description: "Start a new runtime chat", source: "sdk" },
]);
expect(parsed?.name).toBe("/new lane");
expect(parsed?.args).toBe("perf-pass");
expect(parsed ? commandPlacement(parsed) : null).toBe("right");
});
it("tags built-ins and user commands in the palette", () => {
const rows = paletteCommands("/ship", [
{ name: "/ship", description: "Ship it", source: "sdk" },
]);
expect(rows).toContainEqual(expect.objectContaining({ name: "/ship", source: "user" }));
});
it("surfaces SDK commands like /compact when filtering", () => {
const rows = paletteCommands("/comp", [
{ name: "/compact", description: "Free up context by summarizing", source: "sdk" },
]);
expect(rows).toContainEqual(expect.objectContaining({
name: "/compact",
source: "ade",
description: "Compact the active chat context",
}));
});
it("includes Claude parity builtins plus provider-agnostic skills", () => {
const rows = paletteCommands("/", [], { provider: "claude" });
for (const name of ["/agents", "/skills", "/init"]) {
expect(rows).toContainEqual(expect.objectContaining({ name, source: "ade" }));
const parsed = parseCommand(`${name} arg`, []);
expect(parsed?.spec?.placement).toBe("right");
}
for (const name of ["/compact", "/usage", "/insights", "/fast", "/goal"]) {
expect(rows).toContainEqual(expect.objectContaining({ name, source: "ade" }));
const parsed = parseCommand(`${name} arg`, []);
expect(parsed?.spec?.placement).toBe("chat");
}
});
it("keeps provider-agnostic skills visible outside Claude chats", () => {
const rows = paletteCommands("/", [], { provider: "codex" });
for (const name of ["/agents", "/init", "/usage", "/insights", "/fast"]) {
expect(rows).not.toContainEqual(expect.objectContaining({ name }));
}
expect(rows).toContainEqual(expect.objectContaining({
name: "/skills",
description: "List agent skills from project, user, and ADE bundled roots",
}));
expect(rows).toContainEqual(expect.objectContaining({
name: "/compact",
description: "Compact the active chat context",
}));
expect(rows).toContainEqual(expect.objectContaining({
name: "/goal",
description: "Set, clear, or inspect the active chat goal",
}));
});
it("shows one provider-gated row for shared Claude and Codex chat commands", () => {
const rows = paletteCommands("/");
const compactRows = rows.filter((row) => row.name === "/compact");
const goalRows = rows.filter((row) => row.name === "/goal");
expect(compactRows).toEqual([
expect.objectContaining({ description: "Compact the active chat context" }),
]);
expect(goalRows).toEqual([
expect.objectContaining({ description: "Set, clear, or inspect the active chat goal" }),
]);
});
it("filters provider-specific ADE commands outside supported chats", () => {
expect(paletteCommands("/context", [], { provider: "codex" })).toContainEqual(
expect.objectContaining({ name: "/context" }),
);
expect(paletteCommands("/output-style", [], { provider: "codex" })).not.toContainEqual(
expect.objectContaining({ name: "/output-style" }),
);
expect(paletteCommands("/mcp", [], { provider: "codex" })).not.toContainEqual(
expect.objectContaining({ name: "/mcp" }),
);
expect(paletteCommands("/plugin", [], { provider: "codex" })).not.toContainEqual(
expect.objectContaining({ name: "/plugin" }),
);
expect(paletteCommands("/context", [], { provider: "claude" })).toContainEqual(
expect.objectContaining({ name: "/context" }),
);
expect(paletteCommands("/output-style", [], { provider: "claude" })).toContainEqual(
expect.objectContaining({ name: "/output-style" }),
);
expect(paletteCommands("/mcp", [], { provider: "claude" })).not.toContainEqual(
expect.objectContaining({ name: "/mcp" }),
);
expect(paletteCommands("/plugin", [], { provider: "claude" })).toContainEqual(
expect.objectContaining({ name: "/plugin" }),
);
});
it("keeps ADE-owned inline commands aligned with dispatch when deduping", () => {
// /clear is an ADE terminal control, so the palette must not advertise the SDK command.
const rows = paletteCommands("/clear", [
{ name: "/clear", description: "Start a new conversation with empty context", source: "sdk" },
]);
const clearRows = rows.filter((row) => row.name === "/clear");
expect(clearRows).toHaveLength(1);
expect(clearRows[0]?.source).toBe("ade");
expect(clearRows[0]?.description).toBe("Clear the local terminal transcript view");
const parsed = parseCommand("/clear", [
{ name: "/clear", description: "Start a new conversation with empty context", source: "sdk" },
]);
expect(parsed?.spec?.name).toBe("/clear");
expect(parsed?.userCommand).toBeNull();
});
it("does not reserve /copy as an ADE built-in", () => {
const rows = paletteCommands("/copy", [
{ name: "/copy", description: "Runtime copy command", source: "sdk" },
]);
expect(rows).toContainEqual(expect.objectContaining({
name: "/copy",
source: "user",
description: "Runtime copy command",
}));
const parsed = parseCommand("/copy all", [
{ name: "/copy", description: "Runtime copy command", source: "sdk" },
]);
expect(parsed?.spec).toBeNull();
expect(parsed?.userCommand?.name).toBe("/copy");
expect(parsed ? commandPlacement(parsed) : null).toBe("chat");
});
it("dedupes slash command case variants and keeps runtime casing", () => {
const rows = paletteCommands("/ship", [
{ name: "/shipLane", description: "Ship the lane", source: "sdk" },
{ name: "/shiplane", description: "Duplicate lower-case command", source: "sdk" },
]);
expect(rows.filter((row) => row.name.toLowerCase() === "/shiplane")).toHaveLength(1);
expect(rows.find((row) => row.name.toLowerCase() === "/shiplane")?.name).toBe("/shiplane");
const parsed = parseCommand("/shipLane now", [
{ name: "/shiplane", description: "Ship the lane", source: "sdk" },
]);
expect(parsed?.userCommand?.name).toBe("/shiplane");
expect(parsed?.args).toBe("now");
});
it("returns more than 9 results for empty/short queries", () => {
const userCommands = Array.from({ length: 20 }, (_, i) => ({
name: `/sdk-cmd-${i}`,
description: `SDK command ${i}`,
source: "sdk" as const,
}));
const rows = paletteCommands("/", userCommands);
expect(rows.length).toBeGreaterThan(20);
});
it("ranks prefix matches above substring matches", () => {
const rows = paletteCommands("/compact", [
{ name: "/compact", description: "Free up context", source: "sdk" },
{ name: "/something-compact-related", description: "Other", source: "sdk" },
]);
expect(rows[0]?.name).toBe("/compact");
});
it("registers /compact and /goal as chat-placement builtins", () => {
const compact = parseCommand("/compact");
expect(compact?.spec?.name).toBe("/compact");
expect(compact ? commandPlacement(compact) : null).toBe("chat");
const goal = parseCommand("/goal Ship the migration");
expect(goal?.spec?.name).toBe("/goal");
expect(goal?.args).toBe("Ship the migration");
expect(goal ? commandPlacement(goal) : null).toBe("chat");
const goalStatus = parseCommand("/goal status active");
expect(goalStatus?.spec?.name).toBe("/goal");
expect(goalStatus?.args).toBe("status active");
});
it("drops the legacy /resume builtin", () => {
const rows = paletteCommands("/resume", []);
expect(rows.find((row) => row.name === "/resume" && row.source === "ade")).toBeUndefined();
});
it("registers /info as the active-chat info command", () => {
const info = parseCommand("/info");
expect(info?.spec?.name).toBe("/info");
expect(info?.spec?.placement).toBe("right");
expect(info ? commandPlacement(info) : null).toBe("right");
const parsed = parseCommand("/subagents");
expect(parsed?.spec).toBeNull();
});
it("surfaces active ADE Code panes in the palette and not removed aliases", () => {
const infoRows = paletteCommands("info");
expect(infoRows.some((row) => row.name === "/info")).toBe(true);
const effortRows = paletteCommands("effort");
expect(effortRows.some((row) => row.name === "/effort" && row.source === "ade")).toBe(true);
const subagentRows = paletteCommands("subagents");
expect(subagentRows.some((row) => row.name === "/subagents")).toBe(false);
const allRows = paletteCommands("");
expect(allRows.some((row) => row.name === "/plan" && row.source === "ade")).toBe(false);
});
});
describe("linear command routing", () => {
it("parses flags and quoted values", () => {
expect(parseLinearArgs("run cancel run-1 --reason \"not ready\" --launch false")).toEqual({
positionals: ["run", "cancel", "run-1"],
options: { reason: "not ready", launch: false },
});
});
it("shows usage for bare /linear instead of running a default tool", () => {
const result = buildLinearToolRequest("");
expect(result.kind).toBe("usage");
if (result.kind !== "usage") return;
expect(result.title).toBe("Linear");
expect(result.body).toContain("attach");
expect(result.body).toContain("comment");
expect(result.body).toContain("workflows");
});
it("routes /linear attach to a session attach action with the active-session placeholder", () => {
expect(buildLinearToolRequest("attach --issue-id ENG-431")).toEqual({
kind: "action",
title: "Linear attach",
domain: "lane",
action: "attachLinearIssueToSession",
args: { chatSessionId: "__ACTIVE_SESSION__", issues: [{ id: "ENG-431", identifier: "ENG-431" }] },
});
});
it("routes /linear attach --lane to a lane-scoped link", () => {
expect(buildLinearToolRequest("attach --issue-id ENG-431 --lane lane-1")).toEqual({
kind: "action",
title: "Linear attach (lane)",
domain: "lane",
action: "linkLinearIssues",
args: { laneId: "lane-1", issues: [{ id: "ENG-431", identifier: "ENG-431" }] },
});
});
it("routes /linear detach, with or without a specific issue id", () => {
expect(buildLinearToolRequest("detach ENG-431 --session s1")).toEqual({
kind: "action",
title: "Linear detach",
domain: "lane",
action: "detachLinearIssueFromSession",
args: { chatSessionId: "s1", issueId: "ENG-431" },
});
// No issue id: detach-all (issueId omitted by compactArgs).
expect(buildLinearToolRequest("detach --session s1")).toEqual({
kind: "action",
title: "Linear detach",
domain: "lane",
action: "detachLinearIssueFromSession",
args: { chatSessionId: "s1" },
});
// --lane (no session) routes to the lane-scoped unlink action.
expect(buildLinearToolRequest("detach --lane lane-1")).toEqual({
kind: "action",
title: "Linear detach (lane)",
domain: "lane",
action: "unlinkLinearIssues",
args: { laneId: "lane-1" },
});
});
it("routes /linear issues to a session list action", () => {
expect(buildLinearToolRequest("issues")).toEqual({
kind: "action",
title: "Linear attached issues",
domain: "lane",
action: "listLinearIssuesForSession",
args: { chatSessionId: "__ACTIVE_SESSION__" },
});
});
it("routes the /linear write-bridge commands to linear_issue_tracker positional actions", () => {
expect(buildLinearToolRequest("comment ENG-431 done")).toEqual({
kind: "actionList",
title: "Linear comment",
domain: "linear_issue_tracker",
action: "createComment",
argsList: ["ENG-431", "done"],
});
expect(buildLinearToolRequest("set-state ENG-431 state-done")).toEqual({
kind: "actionList",
title: "Linear set-state",
domain: "linear_issue_tracker",
action: "updateIssueState",
argsList: ["ENG-431", "state-done"],
});
expect(buildLinearToolRequest("assign ENG-431 none")).toEqual({
kind: "actionList",
title: "Linear assign",
domain: "linear_issue_tracker",
action: "updateIssueAssignee",
argsList: ["ENG-431", null],
});
});
it("routes /linear graphql through the linear_issue_tracker action domain", () => {
expect(
buildLinearToolRequest("graphql --query 'query Viewer { viewer { id } }' --variables-json '{\"first\":10}' --max-retries 99"),
).toEqual({
kind: "action",
title: "Linear GraphQL",
domain: "linear_issue_tracker",
action: "graphql",
args: {
query: "query Viewer { viewer { id } }",
variables: { first: 10 },
maxRetries: 10,
},
});
});
it("rejects malformed /linear graphql variables", () => {
expect(
buildLinearToolRequest("graphql --query 'query Viewer { viewer { id } }' --variables-json nope"),
).toMatchObject({
kind: "usage",
title: "Linear GraphQL",
body: expect.stringContaining("--variables-json must be valid JSON"),
});
expect(
buildLinearToolRequest("graphql --query 'query Viewer { viewer { id } }' --variables-json '[1]'"),
).toMatchObject({
kind: "usage",
title: "Linear GraphQL",
body: expect.stringContaining("--variables-json must be a JSON object"),
});
expect(
buildLinearToolRequest("graphql --query 'query Viewer { viewer { id } }' --max-retries nope"),
).toMatchObject({
kind: "usage",
title: "Linear GraphQL",
body: expect.stringContaining("'maxRetries' must be a number"),
});
});
it("keeps fallback usage in sync with /linear graphql", () => {
expect(buildLinearToolRequest("unknown")).toMatchObject({
kind: "usage",
title: "Linear",
body: expect.stringContaining("graphql"),
});
});
it("routes sync dashboard and queue resolution", () => {
expect(buildLinearToolRequest("sync dashboard")).toEqual({
kind: "tool",
title: "Linear sync dashboard",
toolName: "getLinearSyncDashboard",
args: {},
});
expect(buildLinearToolRequest("sync resolve queue-1 approve --note ok")).toEqual({
kind: "tool",
title: "Linear sync resolve",
toolName: "resolveLinearSyncQueueItem",
args: {
queueItemId: "queue-1",
action: "approve",
note: "ok",
},
});
});
it("routes worker handoff and reports usage for missing fields", () => {
expect(buildLinearToolRequest("route worker LIN-123 agent-1")).toEqual({
kind: "tool",
title: "Linear route worker",
toolName: "routeLinearIssueToWorker",
args: { issueId: "LIN-123", agentId: "agent-1" },
});
expect(buildLinearToolRequest("run cancel run-1")).toEqual({
kind: "usage",
title: "Linear run cancel",
body: "Usage: /linear run cancel <run-id> --reason <reason>",
});
});
});