Open History to see the last commit
1import { filterComposerPullRequestMatches } from "@t3tools/shared/composerPullRequestMatches";
2import { EnvironmentId, MessageId, ThreadId, type AssistantCitation } from "@t3tools/contracts";
3import {
4 collectAssistantCitations,
5 expandAssistantCitationsForProvider,
6 serializeAssistantCitation,
7} from "@t3tools/shared/assistantCitations";
8import { describe, expect, it } from "vite-plus/test";
9β
10import {
11 clampCollapsedComposerCursor,
12 collapseExpandedComposerCursor,
13 composerSubmissionIntentForEnter,
14 detectComposerTrigger,
15 expandCollapsedComposerCursor,
16 formatAssistantCitationForComposer,
17 isCollapsedCursorAdjacentToInlineToken,
18 parseStandaloneComposerSlashCommand,
19 replaceTextRange,
20} from "./composer-logic";
21import { formatTerminalContextReference } from "./lib/terminalContext";
22β
23const terminalReference = formatTerminalContextReference({
24 id: "ctx-1",
25 terminalLabel: "Terminal 1",
26 lineStart: 3,
27 lineEnd: 4,
28});
29β
30const citation: AssistantCitation = {
31 version: 1,
32 environmentId: EnvironmentId.make("environment-1"),
33 threadId: ThreadId.make("thread-1"),
34 messageId: MessageId.make("message-1"),
35 text: "Keep Unicode π and punctuation (here).",
36 start: 3,
37 end: 40,
38 prefix: "ε: ",
39 suffix: " εΎ",
40};
41const citationSource = serializeAssistantCitation(citation).replaceAll("+", "%20");
42β
43describe("formatAssistantCitationForComposer", () => {
44 it.each([undefined, "", " \n\t "])(
45 "keeps citation-only insertion for a blank comment %j",
46 (comment) => {
47 expect(formatAssistantCitationForComposer(citation, comment)).toBe(
48 `${serializeAssistantCitation(citation)} `,
49 );
50 },
51 );
52β
53 it("binds a multiline comment to its citation without adding standalone prompt text", () => {
54 const comment = 'What does "keep" mean? π\n Please show an example.';
55 const text = formatAssistantCitationForComposer(citation, ` ${comment}\n`);
56 const boundCitation = { ...citation, comment };
57 expect(text).toBe(`${serializeAssistantCitation(boundCitation)} `);
58 expect(collectAssistantCitations(text).map((entry) => entry.citation)).toEqual([boundCitation]);
59 expect(expandAssistantCitationsForProvider(text)).toMatch(/^\[assistant-quote-1\] \n\n/);
60 });
61});
62β
63describe("composerSubmissionIntentForEnter", () => {
64 it.each([
65 ["enter", "one line", false, "foreground"],
66 ["enter", "two\nlines", false, "foreground"],
67 ["mod-enter-multiline", "one line", false, "foreground"],
68 ["mod-enter-multiline", "two\nlines", false, null],
69 ["mod-enter-multiline", "two\nlines", true, "foreground"],
70 ["mod-enter", "one line", false, null],
71 ["mod-enter", "one line", true, "foreground"],
72 ] as const)("uses %s for %j with modifier=%s", (sendShortcut, prompt, modifierKey, expected) => {
73 expect(
74 composerSubmissionIntentForEnter({
75 isMobileViewport: false,
76 shiftKey: false,
77 modifierKey,
78 isDraftThread: false,
79 sendShortcut,
80 prompt,
81 }),
82 ).toBe(expected);
83 });
84β
85 it.each([
86 ["enter", false, "alternate"],
87 ["enter", true, null],
88 ["mod-enter-multiline", false, "foreground"],
89 ["mod-enter-multiline", true, "alternate"],
90 ["mod-enter", false, "foreground"],
91 ["mod-enter", true, "alternate"],
92 ] as const)(
93 "resolves running follow-ups with %s and shift=%s",
94 (sendShortcut, shiftKey, expected) => {
95 expect(
96 composerSubmissionIntentForEnter({
97 isMobileViewport: false,
98 shiftKey,
99 modifierKey: true,
100 isDraftThread: false,
101 isRunning: true,
102 sendShortcut,
103 prompt: "two\nlines",
104 }),
105 ).toBe(expected);
106 },
107 );
108β
109 it("submits plain Enter on desktop", () => {
110 expect(
111 composerSubmissionIntentForEnter({
112 isMobileViewport: false,
113 shiftKey: false,
114 modifierKey: false,
115 isDraftThread: true,
116 }),
117 ).toBe("foreground");
118 });
119β
120 it("inserts a newline for plain Enter on mobile", () => {
121 expect(
122 composerSubmissionIntentForEnter({
123 isMobileViewport: true,
124 shiftKey: false,
125 modifierKey: false,
126 isDraftThread: true,
127 }),
128 ).toBeNull();
129 });
130β
131 it("inserts a newline for Shift+Enter", () => {
132 expect(
133 composerSubmissionIntentForEnter({
134 isMobileViewport: false,
135 shiftKey: true,
136 modifierKey: false,
137 isDraftThread: true,
138 }),
139 ).toBeNull();
140 });
141β
142 it("submits a new thread in the background with Mod+Enter", () => {
143 expect(
144 composerSubmissionIntentForEnter({
145 isMobileViewport: false,
146 shiftKey: false,
147 modifierKey: true,
148 isDraftThread: true,
149 }),
150 ).toBe("background");
151 });
152β
153 it("keeps Mod+Enter in the foreground for an active thread", () => {
154 expect(
155 composerSubmissionIntentForEnter({
156 isMobileViewport: false,
157 shiftKey: false,
158 modifierKey: true,
159 isDraftThread: false,
160 }),
161 ).toBe("foreground");
162 });
163});
164β
165describe("detectComposerTrigger", () => {
166 it("detects @path trigger at cursor", () => {
167 const text = "Please check @src/com";
168 const trigger = detectComposerTrigger(text, text.length);
169β
170 expect(trigger).toEqual({
171 kind: "path",
172 query: "src/com",
173 rangeStart: "Please check ".length,
174 rangeEnd: text.length,
175 });
176 });
177β
178 it("detects slash command token while typing command name", () => {
179 const text = "/mo";
180 const trigger = detectComposerTrigger(text, text.length);
181β
182 expect(trigger).toEqual({
183 kind: "slash-command",
184 query: "mo",
185 rangeStart: 0,
186 rangeEnd: text.length,
187 });
188 });
189β
190 it("keeps /model as a slash command item", () => {
191 const text = "/model";
192 const trigger = detectComposerTrigger(text, text.length);
193β
194 expect(trigger).toEqual({
195 kind: "slash-command",
196 query: "model",
197 rangeStart: 0,
198 rangeEnd: text.length,
199 });
200 });
201β
202 it("does not keep a subcommand trigger active after /model arguments", () => {
203 const text = "/model spark";
204 const trigger = detectComposerTrigger(text, text.length);
205β
206 expect(trigger).toBeNull();
207 });
208β
209 it("detects non-model slash commands while typing", () => {
210 const text = "/pl";
211 const trigger = detectComposerTrigger(text, text.length);
212β
213 expect(trigger).toEqual({
214 kind: "slash-command",
215 query: "pl",
216 rangeStart: 0,
217 rangeEnd: text.length,
218 });
219 });
220β
221 it("keeps slash command detection active for provider commands", () => {
222 const text = "/rev";
223 const trigger = detectComposerTrigger(text, text.length);
224β
225 expect(trigger).toEqual({
226 kind: "slash-command",
227 query: "rev",
228 rangeStart: 0,
229 rangeEnd: text.length,
230 });
231 });
232β
233 it("detects $skill trigger at cursor", () => {
234 const text = "Use $gh-fi";
235 const trigger = detectComposerTrigger(text, text.length);
236β
237 expect(trigger).toEqual({
238 kind: "skill",
239 query: "gh-fi",
240 rangeStart: "Use ".length,
241 rangeEnd: text.length,
242 });
243 });
244β
245 it("detects a pull request number at a token boundary", () => {
246 const text = "Compare this with #8737";
247β
248 expect(detectComposerTrigger(text, text.length)).toEqual({
249 kind: "pull-request",
250 query: "8737",
251 rangeStart: "Compare this with ".length,
252 rangeEnd: text.length,
253 });
254 });
255β
256 it("opens pull request completion from a bare hash", () => {
257 const text = "Compare with #";
258β
259 expect(detectComposerTrigger(text, text.length)).toEqual({
260 kind: "pull-request",
261 query: "",
262 rangeStart: "Compare with ".length,
263 rangeEnd: text.length,
264 });
265 });
266β
267 it("detects a one-word pull request search", () => {
268 const text = "Compare with #composer";
269β
270 expect(detectComposerTrigger(text, text.length)).toEqual({
271 kind: "pull-request",
272 query: "composer",
273 rangeStart: "Compare with ".length,
274 rangeEnd: text.length,
275 });
276 });
277β
278 it("supports hyphenated pull request search terms", () => {
279 const text = "Find #inline-context";
280β
281 expect(detectComposerTrigger(text, text.length)).toEqual({
282 kind: "pull-request",
283 query: "inline-context",
284 rangeStart: "Find ".length,
285 rangeEnd: text.length,
286 });
287 });
288β
289 it("does not keep pull request completion active for headings or embedded hashes", () => {
290 expect(detectComposerTrigger("# Heading", "# Heading".length)).toBeNull();
291 expect(detectComposerTrigger("issue#123", "issue#123".length)).toBeNull();
292 });
293β
294 it("detects @path trigger in the middle of existing text", () => {
295 // User typed @ between "inspect " and "in this sentence"
296 const text = "Please inspect @in this sentence";
297 const cursorAfterAt = "Please inspect @".length;
298β
299 const trigger = detectComposerTrigger(text, cursorAfterAt);
300 expect(trigger).toEqual({
301 kind: "path",
302 query: "",
303 rangeStart: "Please inspect ".length,
304 rangeEnd: cursorAfterAt,
305 });
306 });
307β
308 it("detects @path trigger with query typed mid-text", () => {
309 // User typed @sr between "inspect " and "in this sentence"
310 const text = "Please inspect @srin this sentence";
311 const cursorAfterQuery = "Please inspect @sr".length;
312β
313 const trigger = detectComposerTrigger(text, cursorAfterQuery);
314 expect(trigger).toEqual({
315 kind: "path",
316 query: "sr",
317 rangeStart: "Please inspect ".length,
318 rangeEnd: cursorAfterQuery,
319 });
320 });
321β
322 it("detects trigger with true cursor even when regex-based mention detection would false-match", () => {
323 // MENTION_TOKEN_REGEX can false-match plain text like "@in" as a mention.
324 // The fix bypasses it by computing the expanded cursor from the Lexical node tree.
325 const text = "Please inspect @in this sentence";
326 const cursorAfterAt = "Please inspect @".length;
327β
328 const trigger = detectComposerTrigger(text, cursorAfterAt);
329 expect(trigger).not.toBeNull();
330 expect(trigger?.kind).toBe("path");
331 expect(trigger?.query).toBe("");
332 });
333});
334β
335describe("filterComposerPullRequestMatches", () => {
336 const entries = [
337 {
338 number: 7,
339 projectId: "project-1",
340 repository: "t3tools/t3code",
341 updatedAt: "2026-09-01T12:00:00.000Z",
342 },
343 {
344 number: 8987,
345 projectId: "project-1",
346 repository: "T3Tools/T3Code",
347 updatedAt: "2026-09-03T12:00:00.000Z",
348 },
349 {
350 number: 27,
351 projectId: "project-1",
352 repository: "t3tools/t3code",
353 updatedAt: "2026-09-02T12:00:00.000Z",
354 },
355 {
356 number: 27,
357 projectId: "project-1",
358 repository: "t3tools/t3code",
359 updatedAt: "2026-09-01T13:00:00.000Z",
360 },
361 {
362 number: 70,
363 projectId: "project-2",
364 repository: "t3tools/other",
365 updatedAt: "2026-09-04T12:00:00.000Z",
366 },
367 ];
368β
369 it("matches and de-duplicates number fragments within one repository, exact match first", () => {
370 expect(
371 filterComposerPullRequestMatches({
372 entries,
373 projectId: "project-1",
374 repository: "t3tools/t3code",
375 query: "7",
376 limit: 10,
377 }).map((entry) => entry.number),
378 ).toEqual([7, 8987, 27]);
379 });
380β
381 it("keeps an older exact match when newer substring matches would fill the limit", () => {
382 const exact = {
383 number: 7,
384 projectId: "project-1",
385 repository: "t3tools/t3code",
386 updatedAt: "2020-01-01T00:00:00.000Z",
387 };
388 const newerSubstringMatches = Array.from({ length: 12 }, (_unused, index) => ({
389 number: 700 + index,
390 projectId: "project-1",
391 repository: "t3tools/t3code",
392 updatedAt: `2026-09-${String(index + 1).padStart(2, "0")}T12:00:00.000Z`,
393 }));
394 const matches = filterComposerPullRequestMatches({
395 entries: [...newerSubstringMatches, exact],
396 projectId: "project-1",
397 repository: "t3tools/t3code",
398 query: "7",
399 limit: 10,
400 });
401 expect(matches[0]?.number).toBe(7);
402 expect(matches).toHaveLength(10);
403 });
404β
405 it("uses an empty query for a capped recent list", () => {
406 expect(
407 filterComposerPullRequestMatches({
408 entries,
409 projectId: "project-1",
410 repository: "t3tools/t3code",
411 query: "",
412 limit: 2,
413 }).map((entry) => entry.number),
414 ).toEqual([8987, 27]);
415 });
416});
417β
418describe("replaceTextRange", () => {
419 it("replaces a text range and returns new cursor", () => {
420 const replaced = replaceTextRange("hello @src", 6, 10, "");
421 expect(replaced).toEqual({
422 text: "hello ",
423 cursor: 6,
424 });
425 });
426});
427β
428describe("expandCollapsedComposerCursor", () => {
429 it("keeps cursor unchanged when no mention segment is present", () => {
430 expect(expandCollapsedComposerCursor("plain text", 5)).toBe(5);
431 });
432β
433 it("maps collapsed mention cursor to expanded text cursor", () => {
434 const text = "what's in my @AGENTS.md fsfdas";
435 const collapsedCursorAfterMention = "what's in my ".length + 2;
436 const expandedCursorAfterMention = "what's in my @AGENTS.md ".length;
437β
438 expect(expandCollapsedComposerCursor(text, collapsedCursorAfterMention)).toBe(
439 expandedCursorAfterMention,
440 );
441 });
442β
443 it("maps collapsed quoted mention cursor to expanded text cursor", () => {
444 const text = 'what is in @"My File.md" please';
445 const collapsedCursorAfterMention = "what is in ".length + 2;
446 const expandedCursorAfterMention = 'what is in @"My File.md" '.length;
447β
448 expect(expandCollapsedComposerCursor(text, collapsedCursorAfterMention)).toBe(
449 expandedCursorAfterMention,
450 );
451 });
452β
453 it("maps collapsed markdown file links to their expanded source offsets", () => {
454 const text = "what's in [AGENTS.md](AGENTS.md) please";
455 const collapsedCursorAfterMention = "what's in ".length + 2;
456 const expandedCursorAfterMention = "what's in [AGENTS.md](AGENTS.md) ".length;
457β
458 expect(expandCollapsedComposerCursor(text, collapsedCursorAfterMention)).toBe(
459 expandedCursorAfterMention,
460 );
461 });
462β
463 it("allows path trigger detection to close after selecting a mention", () => {
464 const text = "what's in my @AGENTS.md ";
465 const collapsedCursorAfterMention = "what's in my ".length + 2;
466 const expandedCursor = expandCollapsedComposerCursor(text, collapsedCursorAfterMention);
467β
468 expect(detectComposerTrigger(text, expandedCursor)).toBeNull();
469 });
470β
471 it("maps collapsed skill cursor to expanded text cursor", () => {
472 const text = "run $review-follow-up then";
473 const collapsedCursorAfterSkill = "run ".length + 2;
474 const expandedCursorAfterSkill = "run $review-follow-up ".length;
475β
476 expect(expandCollapsedComposerCursor(text, collapsedCursorAfterSkill)).toBe(
477 expandedCursorAfterSkill,
478 );
479 });
480});
481β
482describe("collapseExpandedComposerCursor", () => {
483 it("keeps cursor unchanged when no mention segment is present", () => {
484 expect(collapseExpandedComposerCursor("plain text", 5)).toBe(5);
485 });
486β
487 it("maps expanded mention cursor back to collapsed cursor", () => {
488 const text = "what's in my @AGENTS.md fsfdas";
489 const collapsedCursorAfterMention = "what's in my ".length + 2;
490 const expandedCursorAfterMention = "what's in my @AGENTS.md ".length;
491β
492 expect(collapseExpandedComposerCursor(text, expandedCursorAfterMention)).toBe(
493 collapsedCursorAfterMention,
494 );
495 });
496β
497 it("maps expanded quoted mention cursor back to collapsed cursor", () => {
498 const text = 'what is in @"My File.md" please';
499 const collapsedCursorAfterMention = "what is in ".length + 2;
500 const expandedCursorAfterMention = 'what is in @"My File.md" '.length;
501β
502 expect(collapseExpandedComposerCursor(text, expandedCursorAfterMention)).toBe(
503 collapsedCursorAfterMention,
504 );
505 });
506β
507 it("maps expanded markdown file link cursors back to collapsed offsets", () => {
508 const text = "what's in [AGENTS.md](AGENTS.md) please";
509 const collapsedCursorAfterMention = "what's in ".length + 2;
510 const expandedCursorAfterMention = "what's in [AGENTS.md](AGENTS.md) ".length;
511β
512 expect(collapseExpandedComposerCursor(text, expandedCursorAfterMention)).toBe(
513 collapsedCursorAfterMention,
514 );
515 });
516β
517 it("keeps package-like text expanded when another mention already exists earlier", () => {
518 const text = "open @AGENTS.md then @src/index.ts ";
519 const expandedCursor = text.length;
520 const collapsedCursor = collapseExpandedComposerCursor(text, expandedCursor);
521β
522 expect(collapsedCursor).toBe("open ".length + 1 + " then @src/index.ts ".length);
523 expect(expandCollapsedComposerCursor(text, collapsedCursor)).toBe(expandedCursor);
524 });
525β
526 it("collapses only genuine mentions when package-like text exists earlier", () => {
527 const text = "install @scope/pkg then @README.md ";
528 const expandedCursor = text.length;
529 const collapsedCursor = collapseExpandedComposerCursor(text, expandedCursor);
530β
531 expect(collapsedCursor).toBe("install @scope/pkg then ".length + 1 + " ".length);
532 expect(expandCollapsedComposerCursor(text, collapsedCursor)).toBe(expandedCursor);
533 });
534β
535 it("maps expanded skill cursor back to collapsed cursor", () => {
536 const text = "run $review-follow-up then";
537 const collapsedCursorAfterSkill = "run ".length + 2;
538 const expandedCursorAfterSkill = "run $review-follow-up ".length;
539β
540 expect(collapseExpandedComposerCursor(text, expandedCursorAfterSkill)).toBe(
541 collapsedCursorAfterSkill,
542 );
543 });
544});
545β
546describe("clampCollapsedComposerCursor", () => {
547 it("clamps to collapsed prompt length when mentions are present", () => {
548 const text = "open @AGENTS.md then ";
549β
550 expect(clampCollapsedComposerCursor(text, text.length)).toBe(
551 "open ".length + 1 + " then ".length,
552 );
553 expect(clampCollapsedComposerCursor(text, Number.POSITIVE_INFINITY)).toBe(
554 "open ".length + 1 + " then ".length,
555 );
556 });
557});
558β
559describe("assistant citation cursor offsets", () => {
560 it("roundtrips every collapsed offset across citations, mentions, skills, and Unicode", () => {
561 const prefix = "π(";
562 const between = "),ιͺ";
563 const after = " @AGENTS.md $review ";
564 const text = `${prefix}${citationSource}${between}${citationSource}${after}${terminalReference}!`;
565 const collapsedLength = `${prefix}β‘${between}β‘ β‘ β‘ β‘!`.length;
566 const boundaries = [
567 [prefix.length, prefix.length],
568 [prefix.length + 1, prefix.length + citationSource.length],
569 [prefix.length + 1 + between.length, prefix.length + citationSource.length + between.length],
570 [
571 prefix.length + 2 + between.length,
572 prefix.length + citationSource.length * 2 + between.length,
573 ],
574 [collapsedLength, text.length],
575 ] as const;
576β
577 for (const [collapsed, expanded] of boundaries) {
578 expect(expandCollapsedComposerCursor(text, collapsed)).toBe(expanded);
579 expect(collapseExpandedComposerCursor(text, expanded)).toBe(collapsed);
580 }
581 for (let cursor = 0; cursor <= collapsedLength; cursor += 1) {
582 expect(
583 collapseExpandedComposerCursor(text, expandCollapsedComposerCursor(text, cursor)),
584 ).toBe(cursor);
585 }
586 expect(clampCollapsedComposerCursor(text, Number.POSITIVE_INFINITY)).toBe(collapsedLength);
587 });
588β
589 it("snaps serialized offsets inside a citation to the end of its chip", () => {
590 const prefix = "επ";
591 const text = `${prefix}${citationSource}.`;
592β
593 for (const offset of [1, citationSource.length - 1, citationSource.length]) {
594 expect(collapseExpandedComposerCursor(text, prefix.length + offset)).toBe(prefix.length + 1);
595 }
596 expect(isCollapsedCursorAdjacentToInlineToken(text, prefix.length, "right")).toBe(true);
597 expect(isCollapsedCursorAdjacentToInlineToken(text, prefix.length + 1, "left")).toBe(true);
598 expect(isCollapsedCursorAdjacentToInlineToken(text, prefix.length + 2, "left")).toBe(false);
599 });
600β
601 it("deletes one collapsed citation without changing its neighbor or surrounding punctuation", () => {
602 const text = `(${citationSource}),${citationSource}!`;
603 const result = replaceTextRange(
604 text,
605 expandCollapsedComposerCursor(text, 1),
606 expandCollapsedComposerCursor(text, 2),
607 "",
608 );
609β
610 expect(result).toEqual({ text: `(),${citationSource}!`, cursor: 1 });
611 expect(collapseExpandedComposerCursor(result.text, result.text.length)).toBe("(),β‘!".length);
612 });
613});
614β
615describe("replaceTextRange trailing space consumption", () => {
616 it("double space after insertion when replacement ends with space", () => {
617 // Simulates: "and then |@AG| summarize" where | marks replacement range
618 // The replacement is "@AGENTS.md " (with trailing space)
619 // But if we don't extend rangeEnd, the existing space stays
620 const text = "and then @AG summarize";
621 const rangeStart = "and then ".length;
622 const rangeEnd = "and then @AG".length;
623β
624 // Without consuming trailing space: double space
625 const withoutConsume = replaceTextRange(text, rangeStart, rangeEnd, "@AGENTS.md ");
626 expect(withoutConsume.text).toBe("and then @AGENTS.md summarize");
627β
628 // With consuming trailing space: single space
629 const extendedEnd = text[rangeEnd] === " " ? rangeEnd + 1 : rangeEnd;
630 const withConsume = replaceTextRange(text, rangeStart, extendedEnd, "@AGENTS.md ");
631 expect(withConsume.text).toBe("and then @AGENTS.md summarize");
632 });
633});
634β
635describe("isCollapsedCursorAdjacentToInlineToken", () => {
636 it("returns false when no mention exists", () => {
637 expect(isCollapsedCursorAdjacentToInlineToken("plain text", 6, "left")).toBe(false);
638 expect(isCollapsedCursorAdjacentToInlineToken("plain text", 6, "right")).toBe(false);
639 });
640β
641 it("keeps @query typing non-adjacent while no mention pill exists", () => {
642 const text = "hello @pac";
643 expect(isCollapsedCursorAdjacentToInlineToken(text, text.length, "left")).toBe(false);
644 expect(isCollapsedCursorAdjacentToInlineToken(text, text.length, "right")).toBe(false);
645 });
646β
647 it("detects left adjacency only when cursor is directly after a mention", () => {
648 const text = "open @AGENTS.md next";
649 const mentionStart = "open ".length;
650 const mentionEnd = mentionStart + 1;
651β
652 expect(isCollapsedCursorAdjacentToInlineToken(text, mentionEnd, "left")).toBe(true);
653 expect(isCollapsedCursorAdjacentToInlineToken(text, mentionStart, "left")).toBe(false);
654 expect(isCollapsedCursorAdjacentToInlineToken(text, mentionEnd + 1, "left")).toBe(false);
655 });
656β
657 it("detects right adjacency only when cursor is directly before a mention", () => {
658 const text = "open @AGENTS.md next";
659 const mentionStart = "open ".length;
660 const mentionEnd = mentionStart + 1;
661β
662 expect(isCollapsedCursorAdjacentToInlineToken(text, mentionStart, "right")).toBe(true);
663 expect(isCollapsedCursorAdjacentToInlineToken(text, mentionEnd, "right")).toBe(false);
664 expect(isCollapsedCursorAdjacentToInlineToken(text, mentionStart - 1, "right")).toBe(false);
665 });
666β
667 it("treats context reference pills as inline tokens for adjacency checks", () => {
668 const text = `open ${terminalReference} next`;
669 const tokenStart = "open ".length;
670 const tokenEnd = tokenStart + 1;
671β
672 expect(isCollapsedCursorAdjacentToInlineToken(text, tokenEnd, "left")).toBe(true);
673 expect(isCollapsedCursorAdjacentToInlineToken(text, tokenStart, "right")).toBe(true);
674 });
675β
676 it("treats skill pills as inline tokens for adjacency checks", () => {
677 const text = "run $review-follow-up next";
678 const tokenStart = "run ".length;
679 const tokenEnd = tokenStart + 1;
680β
681 expect(isCollapsedCursorAdjacentToInlineToken(text, tokenEnd, "left")).toBe(true);
682 expect(isCollapsedCursorAdjacentToInlineToken(text, tokenStart, "right")).toBe(true);
683 });
684});
685β
686describe("parseStandaloneComposerSlashCommand", () => {
687 it("parses standalone /plan command", () => {
688 expect(parseStandaloneComposerSlashCommand(" /plan ")).toBe("plan");
689 });
690β
691 it("parses standalone /default command", () => {
692 expect(parseStandaloneComposerSlashCommand("/default")).toBe("default");
693 });
694β
695 it("ignores slash commands with extra message text", () => {
696 expect(parseStandaloneComposerSlashCommand("/plan explain this")).toBeNull();
697 });
698});