cueloop 0.1.0-alpha.4 → 0.1.0-alpha.40

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/package.json CHANGED
@@ -1,32 +1,38 @@
1
1
  {
2
2
  "name": "cueloop",
3
- "version": "0.1.0-alpha.4",
3
+ "version": "0.1.0-alpha.40",
4
+ "description": "Terminal review surface for coding agents: annotate plans and diffs, return a verdict, send structured feedback back",
5
+ "homepage": "https://github.com/mmurakaru/cueloop#readme",
6
+ "bugs": {
7
+ "url": "https://github.com/mmurakaru/cueloop/issues"
8
+ },
4
9
  "license": "Apache-2.0",
5
- "type": "module",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/mmurakaru/cueloop.git",
13
+ "directory": "packages/cli"
14
+ },
6
15
  "bin": {
7
16
  "cueloop": "./src/main.ts"
8
17
  },
18
+ "files": [
19
+ "src",
20
+ "README.md"
21
+ ],
22
+ "type": "module",
9
23
  "exports": {
10
24
  ".": "./src/main.ts"
11
25
  },
12
- "dependencies": {
13
- "@cueloop/schema": "0.1.0-alpha.4",
14
- "@cueloop/daemon": "0.1.0-alpha.4",
15
- "@cueloop/client": "0.1.0-alpha.4"
16
- },
17
26
  "publishConfig": {
18
27
  "access": "public"
19
28
  },
20
- "files": [
21
- "src",
22
- "README.md"
23
- ],
29
+ "dependencies": {
30
+ "@cueloop/adapters": "0.1.0-alpha.40",
31
+ "@cueloop/client": "0.1.0-alpha.40",
32
+ "@cueloop/daemon": "0.1.0-alpha.40",
33
+ "@cueloop/schema": "0.1.0-alpha.40"
34
+ },
24
35
  "engines": {
25
36
  "bun": ">=1.3.0"
26
- },
27
- "repository": {
28
- "type": "git",
29
- "url": "git+https://github.com/mmurakaru/cueloop.git",
30
- "directory": "packages/cli"
31
37
  }
32
38
  }
@@ -0,0 +1,44 @@
1
+ /**
2
+ * `cueloop actions list [--session <id>]` - print the quick-action vocabulary
3
+ * (the same presets a human picks in the marker popover) so a review-side agent
4
+ * can reference one by name or index via `session annotate --action`. With
5
+ * `--session`, the vocabulary comes from that session's repo (matching what
6
+ * `--action` will resolve); otherwise from the caller's cwd. JSON on stdout.
7
+ */
8
+
9
+ import { loadConfig } from "@cueloop/client/config";
10
+ import { DaemonClient } from "@cueloop/daemon/client";
11
+ import { parseArgs, stringFlag } from "./args";
12
+
13
+ export async function actionsCommand(argv: string[]): Promise<number> {
14
+ const { positional, flags } = parseArgs(argv);
15
+ const verb = positional[0] ?? "list";
16
+ if (verb !== "list") {
17
+ console.error("usage: cueloop actions list [--session <id>]");
18
+ return 2;
19
+ }
20
+ const role = stringFlag(flags, "role") === "agent" ? "agent" : undefined;
21
+ const repoRoot = await repoRootForSession(stringFlag(flags, "session"), role);
22
+ const actions = loadConfig({ repoRoot }).actions;
23
+ const numbered = actions.map((action, index) => ({
24
+ index: index + 1,
25
+ prompt: action.prompt,
26
+ metadata: action.metadata,
27
+ }));
28
+ console.log(JSON.stringify(numbered, null, 2));
29
+ return 0;
30
+ }
31
+
32
+ /** The repo the given session lives in, or the caller's cwd when no session is named. */
33
+ async function repoRootForSession(
34
+ sessionId: string | undefined,
35
+ role: "agent" | undefined,
36
+ ): Promise<string> {
37
+ if (sessionId === undefined) return process.cwd();
38
+ const client = await DaemonClient.connect({ autostart: true, role });
39
+ try {
40
+ return (await client.sessionGet(sessionId)).workspace.repoRoot;
41
+ } finally {
42
+ client.close();
43
+ }
44
+ }
package/src/args.ts CHANGED
@@ -9,16 +9,16 @@ export function parseArgs(argv: string[]): ParsedArgs {
9
9
  const positional: string[] = [];
10
10
  const flags: Record<string, string | boolean> = {};
11
11
  for (let i = 0; i < argv.length; i++) {
12
- const a = argv[i]!;
13
- if (!a.startsWith("--")) {
14
- positional.push(a);
12
+ const argument = argv[i]!;
13
+ if (!argument.startsWith("--")) {
14
+ positional.push(argument);
15
15
  continue;
16
16
  }
17
- const eq = a.indexOf("=");
18
- if (eq !== -1) {
19
- flags[a.slice(2, eq)] = a.slice(eq + 1);
17
+ const equalsIndex = argument.indexOf("=");
18
+ if (equalsIndex !== -1) {
19
+ flags[argument.slice(2, equalsIndex)] = argument.slice(equalsIndex + 1);
20
20
  } else {
21
- const key = a.slice(2);
21
+ const key = argument.slice(2);
22
22
  const next = argv[i + 1];
23
23
  if (next !== undefined && !next.startsWith("--")) {
24
24
  flags[key] = next;
@@ -31,7 +31,10 @@ export function parseArgs(argv: string[]): ParsedArgs {
31
31
  return { positional, flags };
32
32
  }
33
33
 
34
- export function flagStr(flags: Record<string, string | boolean>, key: string): string | undefined {
35
- const v = flags[key];
36
- return typeof v === "string" ? v : undefined;
34
+ export function stringFlag(
35
+ flags: Record<string, string | boolean>,
36
+ key: string,
37
+ ): string | undefined {
38
+ const value = flags[key];
39
+ return typeof value === "string" ? value : undefined;
37
40
  }
package/src/main.ts CHANGED
@@ -1,16 +1,28 @@
1
1
  #!/usr/bin/env bun
2
2
  /**
3
- * cueloop entry points (#18): `cueloop` opens the TUI on the inbox,
4
- * `cueloop diff` reviews the working tree, `cueloop review <pr>` a PR,
5
- * `cueloop session *` mirrors the daemon API for agents and scripts,
6
- * `cueloop serve` shares a session over ssh (read-only observers),
7
- * `cueloop daemon` runs the daemon in the foreground.
3
+ * cueloop entry points: `cueloop` opens the TUI on the inbox, the verb-first
4
+ * openers `cueloop plan|diff|review` open the latest pending review of that
5
+ * type (or address one by id/title), `cueloop diff`/`cueloop review <pr>` also
6
+ * keep their create paths, `cueloop session *` mirrors the daemon API for
7
+ * agents and scripts, `cueloop serve` shares a session over ssh (read-only
8
+ * observers), `cueloop daemon` runs the daemon in the foreground.
8
9
  */
9
10
 
10
- import { parseArgs, flagStr } from "./args";
11
- import { sessionCommand } from "./session-cmds";
12
- import { resolveWorkspace, workingTreeDiff } from "./workspace";
11
+ import { parseArgs, stringFlag, type ParsedArgs } from "./args";
12
+ import {
13
+ isDiffReview,
14
+ isPlanReview,
15
+ isPrReview,
16
+ isSessionId,
17
+ openTargetMessage,
18
+ resolveOpenTarget,
19
+ } from "./open-target";
20
+ import { sessionCommand } from "./session-commands";
21
+ import { CLI_VERSION } from "./version";
22
+ import { workingTreeDiff } from "./working-tree";
13
23
  import { DaemonClient } from "@cueloop/daemon/client";
24
+ import type { ReviewSession } from "@cueloop/schema";
25
+ import { openReview, resolveWorkspace } from "@cueloop/daemon/review";
14
26
 
15
27
  const argv = process.argv.slice(2);
16
28
  const cmd = argv[0];
@@ -31,29 +43,17 @@ async function main(): Promise<number> {
31
43
  await new Promise(() => {}); // run until signalled
32
44
  return 0;
33
45
  }
34
- case "diff": {
35
- const workspace = await resolveWorkspace();
36
- const diff = await workingTreeDiff();
37
- if (!diff.trim()) {
38
- console.error("working tree is clean - nothing to review");
39
- return 1;
40
- }
41
- const client = await DaemonClient.connect({ autostart: true });
42
- const session = await client.sessionCreate(workspace, {
43
- type: "diff",
44
- content: diff,
45
- meta: { title: `working tree @ ${workspace.branch}`, cwd: process.cwd() },
46
- });
47
- client.close();
48
- return runTui(session.id);
49
- }
46
+ case "plan":
47
+ return planCommand(argv.slice(1));
48
+ case "diff":
49
+ return diffCommand(argv.slice(1));
50
50
  case "serve": {
51
51
  const { positional, flags } = parseArgs(argv.slice(1));
52
- const port = flagStr(flags, "port");
52
+ const port = stringFlag(flags, "port");
53
53
  const { serveClient } = await import("@cueloop/client");
54
54
  const handle = await serveClient({
55
55
  port: port !== undefined ? Number(port) : undefined,
56
- host: flagStr(flags, "host"),
56
+ host: stringFlag(flags, "host"),
57
57
  sessionId: positional[0],
58
58
  });
59
59
  console.log(
@@ -73,14 +73,38 @@ async function main(): Promise<number> {
73
73
  await new Promise(() => {}); // serve until signalled
74
74
  return 0;
75
75
  }
76
- case "review": {
77
- const { reviewCommand } = await import("./pr");
78
- return reviewCommand(argv.slice(1));
76
+ case "share": {
77
+ const { positional, flags } = parseArgs(argv.slice(1));
78
+ const { shareCommand, sharePullCommand } = await import("./share-command");
79
+ const port = stringFlag(flags, "port");
80
+ const target = {
81
+ host: stringFlag(flags, "host"),
82
+ port: port !== undefined ? Number(port) : undefined,
83
+ };
84
+ if (positional[0] === "pull")
85
+ return sharePullCommand({ ...target, sessionId: positional[1] });
86
+ return shareCommand({ ...target, sessionId: positional[0] });
79
87
  }
88
+ case "wake": {
89
+ const { wakeCommand } = await import("./wake-command");
90
+ return wakeCommand(argv.slice(1));
91
+ }
92
+ case "actions": {
93
+ const { actionsCommand } = await import("./actions-command");
94
+ return actionsCommand(argv.slice(1));
95
+ }
96
+ case "review":
97
+ return reviewEntry(argv.slice(1));
80
98
  case "review-post": {
81
99
  const { reviewPostCommand } = await import("./pr");
82
100
  return reviewPostCommand(argv.slice(1));
83
101
  }
102
+ case "-v":
103
+ case "--version":
104
+ case "version":
105
+ console.log(CLI_VERSION);
106
+ return 0;
107
+ case "-h":
84
108
  case "--help":
85
109
  case "help":
86
110
  printHelp();
@@ -96,6 +120,110 @@ async function main(): Promise<number> {
96
120
  }
97
121
  }
98
122
 
123
+ /**
124
+ * The id-or-title selector for a verb-first opener: the bare positional, or a
125
+ * value handed to `--open`/`--latest`. A bare `--latest`/`--open` flag carries
126
+ * no value, so the selector stays undefined and the opener defaults to the
127
+ * latest pending review.
128
+ */
129
+ function openSelector(parsed: ParsedArgs): string | undefined {
130
+ return (
131
+ parsed.positional[0] ?? stringFlag(parsed.flags, "open") ?? stringFlag(parsed.flags, "latest")
132
+ );
133
+ }
134
+
135
+ /**
136
+ * Resolve one review of the verb's scope and open it in the TUI, or print the
137
+ * miss and fail. `emptyMessage` overrides the default no-pending line for the
138
+ * one caller that needs a scope-specific hint (a clean working tree).
139
+ */
140
+ async function openReviewOfKind(
141
+ match: (session: ReviewSession) => boolean,
142
+ label: string,
143
+ selector: string | undefined,
144
+ emptyMessage?: string,
145
+ ): Promise<number> {
146
+ const client = await DaemonClient.connect({ autostart: true });
147
+ let sessions: ReviewSession[];
148
+ try {
149
+ sessions = await client.sessionList();
150
+ } finally {
151
+ client.close();
152
+ }
153
+ const target = resolveOpenTarget(sessions, { match, selector });
154
+ if (target.kind === "session") return runTui(target.sessionId);
155
+ if (target.kind === "no-pending" && emptyMessage !== undefined) {
156
+ console.error(emptyMessage);
157
+ return 1;
158
+ }
159
+ console.error(openTargetMessage(label, target));
160
+ return 1;
161
+ }
162
+
163
+ /** `cueloop plan [id|title]` - open the latest pending plan, or address one. */
164
+ async function planCommand(argv: string[]): Promise<number> {
165
+ return openReviewOfKind(isPlanReview, "plan", openSelector(parseArgs(argv)));
166
+ }
167
+
168
+ /**
169
+ * `cueloop diff` disambiguates create from open by intent:
170
+ * - a selector (`cueloop diff <id|title>`) or an explicit `--open`/`--latest`
171
+ * opens a pending diff review;
172
+ * - otherwise a dirty working tree still creates a review as before;
173
+ * - a clean working tree carries no create input, so it opens the latest
174
+ * pending diff review instead of erroring.
175
+ */
176
+ async function diffCommand(argv: string[]): Promise<number> {
177
+ const parsed = parseArgs(argv);
178
+ const selector = openSelector(parsed);
179
+ const wantsOpen = selector !== undefined || "open" in parsed.flags || "latest" in parsed.flags;
180
+ if (wantsOpen) return openReviewOfKind(isDiffReview, "diff", selector);
181
+
182
+ const workspace = await resolveWorkspace();
183
+ const diff = await workingTreeDiff();
184
+ if (!diff.patch.trim()) {
185
+ return openReviewOfKind(
186
+ isDiffReview,
187
+ "diff",
188
+ undefined,
189
+ "working tree is clean and no pending diff review - nothing to open",
190
+ );
191
+ }
192
+ const client = await DaemonClient.connect({ autostart: true });
193
+ const review = await openReview(client, {
194
+ type: "diff",
195
+ content: diff.patch,
196
+ files: diff.files,
197
+ workspace,
198
+ title: `working tree @ ${workspace.branch}`,
199
+ });
200
+ client.close();
201
+ return runTui(review.id);
202
+ }
203
+
204
+ /**
205
+ * `cueloop review` disambiguates create from open by intent:
206
+ * - bare `cueloop review`, `--open`/`--latest`, or a `ses_*` selector opens a
207
+ * pending PR review (a diff carrying a `pr` reference);
208
+ * - any other positional is a PR reference and takes the create path in pr.ts.
209
+ */
210
+ async function reviewEntry(argv: string[]): Promise<number> {
211
+ const parsed = parseArgs(argv);
212
+ const explicitOpen = "open" in parsed.flags || "latest" in parsed.flags;
213
+ const selector = openSelector(parsed);
214
+ const looksLikeSessionId = selector !== undefined && isSessionId(selector);
215
+ const wantsCreate = !explicitOpen && !looksLikeSessionId && selector !== undefined;
216
+ if (wantsCreate) {
217
+ const { reviewCommand } = await import("./pr");
218
+ return reviewCommand(argv);
219
+ }
220
+ return openReviewOfKind(
221
+ isPrReview,
222
+ "PR",
223
+ explicitOpen || looksLikeSessionId ? selector : undefined,
224
+ );
225
+ }
226
+
99
227
  async function runTui(sessionId?: string): Promise<number> {
100
228
  const { runClient } = await import("@cueloop/client");
101
229
  return runClient({ sessionId });
@@ -106,17 +234,37 @@ function printHelp(): void {
106
234
  [
107
235
  "cueloop - review surface for coding agents",
108
236
  "",
109
- "usage:",
237
+ "usage: cueloop [command] [options]",
238
+ "",
239
+ "common commands:",
110
240
  " cueloop open the inbox",
111
- " cueloop <session-id> open one session",
112
- " cueloop diff review the working tree",
241
+ " cueloop plan [id|title] open the latest pending plan review (or one by id/title)",
242
+ " cueloop diff [id|title] review your working tree (untracked files included);",
243
+ " with a clean tree, open the latest pending diff review",
113
244
  " cueloop review <pr> review a pull request (--no-tui prints the session)",
114
- " cueloop review-post <id> <pr> post a resolved session's verdict back to the PR",
245
+ "",
246
+ "share:",
115
247
  " cueloop serve [session-id] share over ssh: observers are read-only,",
116
248
  " you stay the controller (--port 2222, --host 127.0.0.1;",
117
249
  " password-less - share the address deliberately)",
250
+ " cueloop share [session-id] hand a plan to a teammate: copies one",
251
+ " ssh line (--host cueloop.dev, --port 22)",
252
+ " cueloop share pull [session-id] pull a teammate's annotations back into the plan",
253
+ "",
254
+ "open a specific review:",
255
+ " cueloop <session-id> open one session",
256
+ " cueloop review [id|title] open the latest pending PR review (or one by id/title)",
257
+ " cueloop <plan|diff|review> --latest open the latest pending review of that type",
258
+ "",
259
+ "scripting:",
118
260
  " cueloop session <verb> [flags] script the daemon (create|get|list|wait|annotate|resolve|submit-revision)",
261
+ " cueloop actions list list the quick-action vocabulary (for annotate --action)",
262
+ " cueloop wake <id> [--harness codex --thread <id>] resume the agent with the verdict (spawn detached)",
263
+ " cueloop review-post <id> <pr> post a resolved session's verdict back to the PR",
119
264
  " cueloop daemon run the daemon in the foreground",
265
+ "",
266
+ " cueloop -v, --version print the installed version",
267
+ " cueloop -h, --help print this help",
120
268
  ].join("\n"),
121
269
  );
122
270
  }
@@ -0,0 +1,226 @@
1
+ /** Verb-first open resolution over a plain session list: latest-pending default, by-id, and fuzzy-by-title (exact wins, unique substring wins, else ambiguous). Pure over the array - no daemon, no TUI. */
2
+
3
+ import { describe, expect, test } from "bun:test";
4
+ import type { ArtifactType, ReviewSession } from "@cueloop/schema";
5
+ import {
6
+ isDiffReview,
7
+ isPlanReview,
8
+ isPrReview,
9
+ isSessionId,
10
+ openTargetMessage,
11
+ resolveOpenTarget,
12
+ } from "./open-target";
13
+
14
+ function session(overrides: {
15
+ id: string;
16
+ type?: ArtifactType;
17
+ title?: string;
18
+ status?: "pending" | "resolved";
19
+ createdAt?: string;
20
+ pr?: string;
21
+ }): ReviewSession {
22
+ return {
23
+ schemaVersion: "1",
24
+ id: overrides.id,
25
+ workspace: { repoRoot: "/repo", branch: "main" },
26
+ artifact: {
27
+ type: overrides.type ?? "plan",
28
+ content: "",
29
+ meta: { title: overrides.title, pr: overrides.pr },
30
+ },
31
+ revisions: [],
32
+ annotations: [],
33
+ verdict:
34
+ overrides.status === "resolved"
35
+ ? { kind: "approve", summary: "", feedback: "", resolvedAt: "" }
36
+ : null,
37
+ status: overrides.status ?? "pending",
38
+ createdAt: overrides.createdAt ?? "2026-01-01T00:00:00.000Z",
39
+ };
40
+ }
41
+
42
+ const isPlan = isPlanReview;
43
+
44
+ describe("verb scope predicates are disjoint", () => {
45
+ test("isPlanReview matches only plan artifacts", () => {
46
+ expect(isPlanReview(session({ id: "ses_p", type: "plan" }))).toBe(true);
47
+ expect(isPlanReview(session({ id: "ses_d", type: "diff" }))).toBe(false);
48
+ });
49
+
50
+ test("isDiffReview matches a plain diff but NOT a diff carrying meta.pr", () => {
51
+ expect(isDiffReview(session({ id: "ses_d", type: "diff" }))).toBe(true);
52
+ expect(isDiffReview(session({ id: "ses_pr", type: "diff", pr: "42" }))).toBe(false);
53
+ expect(isDiffReview(session({ id: "ses_p", type: "plan" }))).toBe(false);
54
+ });
55
+
56
+ test("isPrReview matches a diff carrying meta.pr, and only that", () => {
57
+ expect(isPrReview(session({ id: "ses_pr", type: "diff", pr: "42" }))).toBe(true);
58
+ expect(isPrReview(session({ id: "ses_d", type: "diff" }))).toBe(false);
59
+ expect(isPrReview(session({ id: "ses_p", type: "plan" }))).toBe(false);
60
+ });
61
+
62
+ test("a PR review resolves under exactly one scope - never both diff and review", () => {
63
+ // Arrange
64
+ const prReview = session({ id: "ses_pr", type: "diff", pr: "42" });
65
+
66
+ // Assert
67
+ expect(isDiffReview(prReview)).toBe(false);
68
+ expect(isPrReview(prReview)).toBe(true);
69
+ });
70
+ });
71
+
72
+ describe("isSessionId", () => {
73
+ test("only the ses_ prefix reads as an id", () => {
74
+ expect(isSessionId("ses_abc")).toBe(true);
75
+ expect(isSessionId("some title")).toBe(false);
76
+ expect(isSessionId("42")).toBe(false);
77
+ });
78
+ });
79
+
80
+ describe("resolveOpenTarget: latest pending default", () => {
81
+ test("picks the most recent pending session in scope", () => {
82
+ // Arrange
83
+ const sessions = [
84
+ session({ id: "ses_old", createdAt: "2026-01-01T00:00:00.000Z" }),
85
+ session({ id: "ses_new", createdAt: "2026-03-01T00:00:00.000Z" }),
86
+ session({ id: "ses_mid", createdAt: "2026-02-01T00:00:00.000Z" }),
87
+ ];
88
+
89
+ // Assert
90
+ expect(resolveOpenTarget(sessions, { match: isPlan })).toEqual({
91
+ kind: "session",
92
+ sessionId: "ses_new",
93
+ });
94
+ });
95
+
96
+ test("ignores resolved sessions and other artifact types", () => {
97
+ // Arrange
98
+ const sessions = [
99
+ session({ id: "ses_resolved", createdAt: "2026-05-01T00:00:00.000Z", status: "resolved" }),
100
+ session({ id: "ses_diff", type: "diff", createdAt: "2026-04-01T00:00:00.000Z" }),
101
+ session({ id: "ses_plan", createdAt: "2026-02-01T00:00:00.000Z" }),
102
+ ];
103
+
104
+ // Assert
105
+ expect(resolveOpenTarget(sessions, { match: isPlan })).toEqual({
106
+ kind: "session",
107
+ sessionId: "ses_plan",
108
+ });
109
+ });
110
+
111
+ test("no pending session in scope reports no-pending", () => {
112
+ // Arrange
113
+ const sessions = [session({ id: "ses_done", status: "resolved" })];
114
+
115
+ // Assert
116
+ expect(resolveOpenTarget(sessions, { match: isPlan })).toEqual({ kind: "no-pending" });
117
+ });
118
+ });
119
+
120
+ describe("resolveOpenTarget: by id", () => {
121
+ test("an exact session id in scope opens that session, pending or not", () => {
122
+ // Arrange
123
+ const sessions = [session({ id: "ses_a" }), session({ id: "ses_b", status: "resolved" })];
124
+
125
+ // Assert
126
+ expect(resolveOpenTarget(sessions, { match: isPlan, selector: "ses_b" })).toEqual({
127
+ kind: "session",
128
+ sessionId: "ses_b",
129
+ });
130
+ });
131
+
132
+ test("an id outside the scope does not match", () => {
133
+ // Arrange
134
+ const sessions = [session({ id: "ses_diff", type: "diff" })];
135
+
136
+ // Assert
137
+ expect(resolveOpenTarget(sessions, { match: isPlan, selector: "ses_diff" })).toEqual({
138
+ kind: "no-match",
139
+ selector: "ses_diff",
140
+ });
141
+ });
142
+ });
143
+
144
+ describe("resolveOpenTarget: fuzzy by title", () => {
145
+ test("case-insensitive exact title wins over substring rivals", () => {
146
+ // Arrange
147
+ const sessions = [
148
+ session({ id: "ses_exact", title: "Rollout" }),
149
+ session({ id: "ses_sub", title: "Rollout plan v2" }),
150
+ ];
151
+
152
+ // Assert
153
+ expect(resolveOpenTarget(sessions, { match: isPlan, selector: "rollout" })).toEqual({
154
+ kind: "session",
155
+ sessionId: "ses_exact",
156
+ });
157
+ });
158
+
159
+ test("a unique case-insensitive substring match wins", () => {
160
+ // Arrange
161
+ const sessions = [
162
+ session({ id: "ses_auth", title: "Auth rewrite" }),
163
+ session({ id: "ses_cache", title: "Cache warmup" }),
164
+ ];
165
+
166
+ // Assert
167
+ expect(resolveOpenTarget(sessions, { match: isPlan, selector: "AUTH" })).toEqual({
168
+ kind: "session",
169
+ sessionId: "ses_auth",
170
+ });
171
+ });
172
+
173
+ test("several substring matches are ambiguous and list the candidate titles", () => {
174
+ // Arrange
175
+ const sessions = [
176
+ session({ id: "ses_1", title: "Payments rollout" }),
177
+ session({ id: "ses_2", title: "Rollout of search" }),
178
+ ];
179
+
180
+ // Assert
181
+ expect(resolveOpenTarget(sessions, { match: isPlan, selector: "rollout" })).toEqual({
182
+ kind: "ambiguous",
183
+ selector: "rollout",
184
+ titles: ["Payments rollout", "Rollout of search"],
185
+ });
186
+ });
187
+
188
+ test("no title match reports no-match", () => {
189
+ // Arrange
190
+ const sessions = [session({ id: "ses_1", title: "Auth rewrite" })];
191
+
192
+ // Assert
193
+ expect(resolveOpenTarget(sessions, { match: isPlan, selector: "billing" })).toEqual({
194
+ kind: "no-match",
195
+ selector: "billing",
196
+ });
197
+ });
198
+ });
199
+
200
+ describe("openTargetMessage", () => {
201
+ test("no-pending mirrors the clean-tree tone", () => {
202
+ expect(openTargetMessage("plan", { kind: "no-pending" })).toBe(
203
+ "no pending plan review - nothing to open",
204
+ );
205
+ });
206
+
207
+ test("no-match names the selector", () => {
208
+ expect(openTargetMessage("diff", { kind: "no-match", selector: "billing" })).toBe(
209
+ 'no diff review matches "billing" - nothing to open',
210
+ );
211
+ });
212
+
213
+ test("ambiguous lists the candidate titles", () => {
214
+ // Act
215
+ const message = openTargetMessage("plan", {
216
+ kind: "ambiguous",
217
+ selector: "rollout",
218
+ titles: ["A", "B"],
219
+ });
220
+
221
+ // Assert
222
+ expect(message).toContain('"rollout" matches several plan reviews');
223
+ expect(message).toContain(" - A");
224
+ expect(message).toContain(" - B");
225
+ });
226
+ });