@causyne/agent 1.20.96 → 1.20.97

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@causyne/agent",
3
- "version": "1.20.96",
3
+ "version": "1.20.97",
4
4
  "description": "Agentic AI for software, tools, and computer workflows",
5
5
  "main": "bin/causyne.js",
6
6
  "type": "module",
@@ -18,6 +18,7 @@ import { listCommands } from '../commands.js';
18
18
  import { listCompiledSkills as listSkillsForCompletion } from '../skillsManager.js';
19
19
  import { sanitize, shortenHome } from './text.js';
20
20
  import { WorkspaceFileIndex } from './workspaceFileIndex.js';
21
+ import { detectInlineSlashTrigger } from './inlineSlash.js';
21
22
  export { WorkspaceFileIndex as FileIndex };
22
23
 
23
24
  export const MAX_VISIBLE = 8;
@@ -312,44 +313,14 @@ function directoryItems(root, partial) {
312
313
  // ---------------------------------------------------------------------------
313
314
 
314
315
  /**
315
- * What, if anything, should be completed at the cursor.
316
- *
317
- * `/` only counts at the very start of the input — that is what keeps a task
318
- * that merely mentions `/usr/local/bin` from opening a command picker, the same
319
- * rule parseCommand() enforces when the line is finally submitted.
316
+ * Find a slash command or @ reference at the current caret position.
317
+ * Slash detection works at any whitespace-delimited token boundary. Execution
318
+ * remains exclusive to explicit selection; normal prompt dispatch is unchanged.
320
319
  */
321
320
  export function detectTrigger(text, cursor) {
322
321
  const before = text.slice(0, cursor);
323
-
324
- if (/^\/[a-z0-9_?-]*$/i.test(before)) {
325
- return { kind: 'command', start: 0, query: before.slice(1) };
326
- }
327
-
328
- // `/command <argument>` — the command's OWN suggestions.
329
- //
330
- // Completion used to stop dead at the space: `/skills d` offered nothing, so
331
- // the only way to reach a skill was to submit `/skills` bare and browse. With
332
- // a hundred of them that is a poor trade for someone who already knows the
333
- // name they want.
334
- //
335
- // openclaw's contract (src/tui/commands.ts): a command declares its argument
336
- // completions and the prompt asks it for the ones matching what has been typed
337
- // — `getArgumentCompletions(prefix)`. Same shape here, generic over every
338
- // command, so `/mcp`, `/model` and the rest can adopt it by adding one
339
- // function and nothing in this file changes.
340
- //
341
- // Anchored, and a single argument token only: a second word ends the
342
- // completion rather than trying to complete inside a sentence. opencode hides
343
- // its picker on exactly the same condition.
344
- const argument = before.match(/^\/([a-z0-9_?-]+)[ \t]+(\S*)$/i);
345
- if (argument) {
346
- return {
347
- kind: 'command-argument',
348
- command: argument[1],
349
- start: cursor - argument[2].length,
350
- query: argument[2]
351
- };
352
- }
322
+ const slash = detectInlineSlashTrigger(text, cursor);
323
+ if (slash) return slash;
353
324
 
354
325
  // 1. Quoted @ file mention: @"pixel2d games/ or @'pixel2d games/
355
326
  // Supports spaces in directory or file names
@@ -0,0 +1,93 @@
1
+ /**
2
+ * Slash completion framing for the Causyne chat composer.
3
+ *
4
+ * This is intentionally a lexical, zero-model operation. It never executes a
5
+ * command. Only an explicit picker selection can hand a command to ChatPrompt.
6
+ * Existing command dispatch keeps its beginning-of-input parser unchanged.
7
+ */
8
+ const ARGUMENT = /(?:^|[ \t\r\n])\/([a-z0-9_?-]+)[ \t]+([^\s]*)$/i;
9
+ const COMMAND = /(?:^|[ \t\r\n])\/([a-z0-9_?-]*)$/i;
10
+ /**
11
+ * Find a complete slash prefix at the caret, even when other prose precedes it.
12
+ * A slash must start a whitespace-delimited token: URLs, division, and paths
13
+ * with inner slashes do not open the command menu.
14
+ *
15
+ * Offsets are UTF-16 code units, which is the existing completion.js contract.
16
+ */
17
+ export function detectInlineSlashTrigger(text, cursor) {
18
+ if (typeof text !== 'string' || !Number.isFinite(cursor))
19
+ return null;
20
+ if (cursor < 0 || cursor > text.length)
21
+ return null;
22
+ const before = text.slice(0, cursor);
23
+ const argument = ARGUMENT.exec(before);
24
+ if (argument) {
25
+ const fragment = argument[0];
26
+ const offset = cursor - fragment.length + fragment.indexOf('/');
27
+ const query = argument[2] ?? '';
28
+ return {
29
+ kind: 'command-argument',
30
+ command: argument[1] ?? '',
31
+ query,
32
+ start: cursor - query.length,
33
+ tokenStart: offset,
34
+ inline: before.slice(0, offset).trim().length > 0
35
+ };
36
+ }
37
+ const command = COMMAND.exec(before);
38
+ if (!command)
39
+ return null;
40
+ const fragment = command[0];
41
+ const offset = cursor - fragment.length + fragment.indexOf('/');
42
+ return {
43
+ kind: 'command',
44
+ query: command[1] ?? '',
45
+ start: offset,
46
+ tokenStart: offset,
47
+ inline: before.slice(0, offset).trim().length > 0
48
+ };
49
+ }
50
+ /**
51
+ * Remove the command token, NOT the surrounding draft.
52
+ * An editor caret can sit in the middle of a token. In that case, remove the
53
+ * untyped suffix of the same token too, stopping at the following whitespace.
54
+ */
55
+ export function removeInlineSlashToken(text, cursor, trigger) {
56
+ if (typeof text !== 'string' || !Number.isFinite(cursor)) {
57
+ throw new TypeError('Invalid inline command text or cursor');
58
+ }
59
+ const position = Math.trunc(cursor);
60
+ const start = trigger.tokenStart;
61
+ if (!Number.isInteger(start) || start < 0 || start >= text.length ||
62
+ position < start || position > text.length || text[start] !== '/') {
63
+ throw new RangeError('Stale inline command selection');
64
+ }
65
+ const actual = text.slice(start, position);
66
+ if (trigger.kind === 'command') {
67
+ if (actual !== `/${trigger.query}`) {
68
+ throw new RangeError('Stale inline command selection');
69
+ }
70
+ }
71
+ else {
72
+ const argument = /^\/([a-z0-9_?-]+)[ \t]+([^\s]*)$/i.exec(actual);
73
+ if (!argument || argument[1] !== trigger.command || argument[2] !== trigger.query) {
74
+ throw new RangeError('Stale inline command selection');
75
+ }
76
+ }
77
+ const suffix = text.slice(position);
78
+ const trailingToken = trigger.kind === 'command'
79
+ ? /^[a-z0-9_?-]*/i.exec(suffix)?.[0] ?? ''
80
+ : /^[^\s]*/.exec(suffix)?.[0] ?? '';
81
+ const end = position + trailingToken.length;
82
+ return {
83
+ text: text.slice(0, start) + text.slice(end),
84
+ cursor: start
85
+ };
86
+ }
87
+ /**
88
+ * Compiled-skill menu entries are the only commands that consume the current
89
+ * draft as their task instruction. Management commands keep the draft intact.
90
+ */
91
+ export function isInlineSkillInvocation(command) {
92
+ return /^\/skills\s+[a-z0-9_.-]+\/[a-z0-9_.-]+$/i.test(command);
93
+ }
@@ -0,0 +1,121 @@
1
+ /**
2
+ * Slash completion framing for the Causyne chat composer.
3
+ *
4
+ * This is intentionally a lexical, zero-model operation. It never executes a
5
+ * command. Only an explicit picker selection can hand a command to ChatPrompt.
6
+ * Existing command dispatch keeps its beginning-of-input parser unchanged.
7
+ */
8
+
9
+ export type SlashTrigger =
10
+ | {
11
+ readonly kind: 'command';
12
+ readonly query: string;
13
+ readonly start: number;
14
+ readonly tokenStart: number;
15
+ readonly inline: boolean;
16
+ }
17
+ | {
18
+ readonly kind: 'command-argument';
19
+ readonly command: string;
20
+ readonly query: string;
21
+ readonly start: number;
22
+ readonly tokenStart: number;
23
+ readonly inline: boolean;
24
+ };
25
+
26
+ export interface RemovedSlashToken {
27
+ readonly text: string;
28
+ readonly cursor: number;
29
+ }
30
+
31
+ const ARGUMENT = /(?:^|[ \t\r\n])\/([a-z0-9_?-]+)[ \t]+([^\s]*)$/i;
32
+ const COMMAND = /(?:^|[ \t\r\n])\/([a-z0-9_?-]*)$/i;
33
+
34
+ /**
35
+ * Find a complete slash prefix at the caret, even when other prose precedes it.
36
+ * A slash must start a whitespace-delimited token: URLs, division, and paths
37
+ * with inner slashes do not open the command menu.
38
+ *
39
+ * Offsets are UTF-16 code units, which is the existing completion.js contract.
40
+ */
41
+ export function detectInlineSlashTrigger(text: string, cursor: number): SlashTrigger | null {
42
+ if (typeof text !== 'string' || !Number.isFinite(cursor)) return null;
43
+ if (cursor < 0 || cursor > text.length) return null;
44
+
45
+ const before = text.slice(0, cursor);
46
+ const argument = ARGUMENT.exec(before);
47
+ if (argument) {
48
+ const fragment = argument[0];
49
+ const offset = cursor - fragment.length + fragment.indexOf('/');
50
+ const query = argument[2] ?? '';
51
+ return {
52
+ kind: 'command-argument',
53
+ command: argument[1] ?? '',
54
+ query,
55
+ start: cursor - query.length,
56
+ tokenStart: offset,
57
+ inline: before.slice(0, offset).trim().length > 0
58
+ };
59
+ }
60
+
61
+ const command = COMMAND.exec(before);
62
+ if (!command) return null;
63
+ const fragment = command[0];
64
+ const offset = cursor - fragment.length + fragment.indexOf('/');
65
+ return {
66
+ kind: 'command',
67
+ query: command[1] ?? '',
68
+ start: offset,
69
+ tokenStart: offset,
70
+ inline: before.slice(0, offset).trim().length > 0
71
+ };
72
+ }
73
+
74
+ /**
75
+ * Remove the command token, NOT the surrounding draft.
76
+ * An editor caret can sit in the middle of a token. In that case, remove the
77
+ * untyped suffix of the same token too, stopping at the following whitespace.
78
+ */
79
+ export function removeInlineSlashToken(
80
+ text: string,
81
+ cursor: number,
82
+ trigger: SlashTrigger
83
+ ): RemovedSlashToken {
84
+ if (typeof text !== 'string' || !Number.isFinite(cursor)) {
85
+ throw new TypeError('Invalid inline command text or cursor');
86
+ }
87
+ const position = Math.trunc(cursor);
88
+ const start = trigger.tokenStart;
89
+ if (!Number.isInteger(start) || start < 0 || start >= text.length ||
90
+ position < start || position > text.length || text[start] !== '/') {
91
+ throw new RangeError('Stale inline command selection');
92
+ }
93
+ const actual = text.slice(start, position);
94
+ if (trigger.kind === 'command') {
95
+ if (actual !== `/${trigger.query}`) {
96
+ throw new RangeError('Stale inline command selection');
97
+ }
98
+ } else {
99
+ const argument = /^\/([a-z0-9_?-]+)[ \t]+([^\s]*)$/i.exec(actual);
100
+ if (!argument || argument[1] !== trigger.command || argument[2] !== trigger.query) {
101
+ throw new RangeError('Stale inline command selection');
102
+ }
103
+ }
104
+ const suffix = text.slice(position);
105
+ const trailingToken = trigger.kind === 'command'
106
+ ? /^[a-z0-9_?-]*/i.exec(suffix)?.[0] ?? ''
107
+ : /^[^\s]*/.exec(suffix)?.[0] ?? '';
108
+ const end = position + trailingToken.length;
109
+ return {
110
+ text: text.slice(0, start) + text.slice(end),
111
+ cursor: start
112
+ };
113
+ }
114
+
115
+ /**
116
+ * Compiled-skill menu entries are the only commands that consume the current
117
+ * draft as their task instruction. Management commands keep the draft intact.
118
+ */
119
+ export function isInlineSkillInvocation(command: string): boolean {
120
+ return /^\/skills\s+[a-z0-9_.-]+\/[a-z0-9_.-]+$/i.test(command);
121
+ }
package/src/tui/prompt.js CHANGED
@@ -22,6 +22,7 @@ import { TerminalInputFramer, INPUT_PREFIX_TIMEOUT_MS, shouldTreatAsAtomicPaste
22
22
  import { LineEditor } from './lineEditor.js';
23
23
  import { PromptHistory } from './history.js';
24
24
  import { FileIndex, suggest, applyCompletion, detectTrigger, renderPicker, MAX_VISIBLE } from './completion.js';
25
+ import { removeInlineSlashToken, isInlineSkillInvocation } from './inlineSlash.js';
25
26
  import { paint, dim, bold, GLYPHS, terminalWidth, HAS_COLOR } from './theme.js';
26
27
  import { barBlock, GUTTER } from './block.js';
27
28
  import { composerGeometry } from './composerGeometry.js';
@@ -1446,6 +1447,12 @@ export class ChatPrompt {
1446
1447
  }
1447
1448
 
1448
1449
  if (item) {
1450
+ if (this.completion.inline && (this.completion.kind === 'command' || this.completion.kind === 'command-argument')) {
1451
+ const selectedCommand = this.completion.kind === 'command'
1452
+ ? item.value : `/${this.completion.command} ${item.value}`;
1453
+ this.runInlineSlashSelection(selectedCommand);
1454
+ return true;
1455
+ }
1449
1456
  if (this.completion.kind === 'command') {
1450
1457
  // A skill entry goes onto the line so the user can say what to do
1451
1458
  // with it; clicking it used to invoke it immediately with no task.
@@ -1466,8 +1473,14 @@ export class ChatPrompt {
1466
1473
  }
1467
1474
  return true;
1468
1475
  }
1469
- if (key.name === 'enter' && !key.alt) {
1476
+ if (key.name === 'enter' && !key.alt && !key.shift) {
1470
1477
  const item = this.completion.items && this.completion.items[this.selected];
1478
+ if (item && this.completion.inline && (this.completion.kind === 'command' || this.completion.kind === 'command-argument')) {
1479
+ const selectedCommand = this.completion.kind === 'command'
1480
+ ? item.value : `/${this.completion.command} ${item.value}`;
1481
+ this.runInlineSlashSelection(selectedCommand);
1482
+ return true;
1483
+ }
1471
1484
  if (this.completion.kind === 'command' && item) {
1472
1485
  if (typeof item.value === 'string' && (item.value.startsWith('/skills ') || item.value.startsWith('/skill '))) {
1473
1486
  this.acceptCompletion();
@@ -1486,10 +1499,22 @@ export class ChatPrompt {
1486
1499
  this.acceptCompletion();
1487
1500
  return true;
1488
1501
  }
1489
- if (key.name === 'tab') { this.acceptCompletion(); return true; }
1502
+ if (key.name === 'tab') {
1503
+ if (this.completion?.inline && (this.completion.kind === 'command' || this.completion.kind === 'command-argument')) {
1504
+ // Tab must never silently turn an unsent message into a local command.
1505
+ this.notice = 'Press Enter to run the selected command; your unsent draft is preserved.';
1506
+ this.scheduleDraw();
1507
+ return true;
1508
+ }
1509
+ this.acceptCompletion();
1510
+ return true;
1511
+ }
1490
1512
  if (key.name === 'escape') {
1513
+ const dismissed = this.completion;
1491
1514
  this.completion = null;
1492
- if (this.editor.getText().startsWith('/')) {
1515
+ // Only discard a standalone leading command token. Never erase a
1516
+ // longer draft just because its first character happens to be /.
1517
+ if (!dismissed?.inline && /^\s*\/[a-z0-9_?-]*$/i.test(this.editor.getText())) {
1493
1518
  this.editor.clear();
1494
1519
  }
1495
1520
  this.scheduleDraw();
@@ -1523,6 +1548,56 @@ export class ChatPrompt {
1523
1548
  this.submit();
1524
1549
  }
1525
1550
 
1551
+ /**
1552
+ * Execute an explicitly selected slash action from anywhere in a draft.
1553
+ * Ordinary commands run through submit() with the unsent draft suspended;
1554
+ * selecting a compiled skill applies it to the draft as its instruction.
1555
+ * Neither path changes parseCommand() or interprets ambient prose as control.
1556
+ */
1557
+ runInlineSlashSelection(value) {
1558
+ const trigger = this.completion;
1559
+ if (!trigger?.inline || (trigger.kind !== 'command' && trigger.kind !== 'command-argument')) {
1560
+ this.submitPickedCommand(value);
1561
+ return;
1562
+ }
1563
+
1564
+ const currentText = this.editor.getText();
1565
+ const currentCursor = this.cursorOffset();
1566
+ let remaining;
1567
+ try {
1568
+ remaining = removeInlineSlashToken(currentText, currentCursor, trigger);
1569
+ } catch (error) {
1570
+ // The draft might have changed since the last render. Never execute a
1571
+ // command selected against stale input or erase user-authored text.
1572
+ this.notice = 'The command text changed. Reopen the / menu and select again.';
1573
+ this.completion = null;
1574
+ this.scheduleDraw();
1575
+ return;
1576
+ }
1577
+
1578
+ const consumeDraft = isInlineSkillInvocation(value) && remaining.text.trim().length > 0;
1579
+ const commandText = consumeDraft ? `${value} ${remaining.text.trim()}` : value;
1580
+
1581
+ // submit() itself protects the queue, but return early here to avoid
1582
+ // discarding the unfinished inline token when the command was not queued.
1583
+ if (this.busy && this.queue.length >= 32 && !/^\/(?:stop|interrupt)$/i.test(commandText)) {
1584
+ this.notice = '32 queued messages: command not submitted; your draft is unchanged.';
1585
+ this.scheduleDraw();
1586
+ return;
1587
+ }
1588
+
1589
+ this.completion = null;
1590
+ try {
1591
+ this.editor.setText(commandText);
1592
+ this.submit(); // existing history, permission and command-dispatch boundary
1593
+ } finally {
1594
+ this.editor.setText(consumeDraft ? '' : remaining.text);
1595
+ if (!consumeDraft) this.setCursorOffset(remaining.cursor);
1596
+ this.completion = null;
1597
+ this.scheduleDraw();
1598
+ }
1599
+ }
1600
+
1526
1601
  acceptCompletion() {
1527
1602
  const item = this.completion.items[this.selected];
1528
1603
  if (!item) { this.completion = null; return; }
@@ -1845,6 +1920,9 @@ export class ChatPrompt {
1845
1920
  const matched = this.completion.total || this.completion.items.length;
1846
1921
  const hidden = matched - drawn.length;
1847
1922
  if (hidden > 0) drawn.push(dim(` ${GLYPHS.ellipsis} ${hidden} more`));
1923
+ if (this.completion?.inline && (this.completion.kind === 'command' || this.completion.kind === 'command-argument')) {
1924
+ drawn.push(dim(' ' + truncate('Enter run · Esc dismiss · draft protected', Math.max(0, width - 5))));
1925
+ }
1848
1926
  return drawn;
1849
1927
  }
1850
1928
  }