@causyne/agent 1.20.60 → 1.20.63

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.
Files changed (90) hide show
  1. package/README.md +2 -2
  2. package/package.json +1 -1
  3. package/src/acp/agentCatalog.js +1 -1
  4. package/src/acp/agentCatalog.ts +1 -1
  5. package/src/acp/client.js +48 -0
  6. package/src/acp/client.ts +44 -0
  7. package/src/acp/peerProfiles.js +3 -3
  8. package/src/acp/peerProfiles.ts +3 -3
  9. package/src/agentLoop.js +239 -33
  10. package/src/agentLoop.ts +248 -36
  11. package/src/checkpoints.js +23 -5
  12. package/src/cliMode.js +13 -2
  13. package/src/commands.js +534 -78
  14. package/src/contextManager.d.ts +3 -0
  15. package/src/contextManager.js +78 -5
  16. package/src/cortex/autoCondenser.js +105 -145
  17. package/src/cortex/autoCondenser.ts +185 -0
  18. package/src/cortex/cortexEngine.js +179 -0
  19. package/src/cortex/cortexEngine.ts +209 -0
  20. package/src/cortex/provisioner.js +12 -14
  21. package/src/cortex/provisioner.ts +29 -0
  22. package/src/cortex/vectorDb.js +307 -386
  23. package/src/cortex/vectorDb.ts +473 -0
  24. package/src/decisionPolicy.js +18 -1
  25. package/src/decisionPolicy.ts +18 -1
  26. package/src/implementationPlan.js +26 -0
  27. package/src/implementationPlan.ts +25 -0
  28. package/src/observer/coldObserver.js +6 -1
  29. package/src/observer/coldObserver.ts +6 -1
  30. package/src/observer.js +24 -2
  31. package/src/observer.ts +24 -2
  32. package/src/providers/acp.js +2 -8
  33. package/src/providers/acp.ts +2 -8
  34. package/src/providers/antigravity.js +7 -10
  35. package/src/providers/antigravity.ts +7 -10
  36. package/src/reporting.js +30 -7
  37. package/src/sessionJournal.js +13 -0
  38. package/src/sessionJournal.ts +13 -0
  39. package/src/smartToolsUse.js +1 -1
  40. package/src/smartToolsUse.ts +1 -1
  41. package/src/tokenTracker.js +22 -0
  42. package/src/tokenTracker.ts +28 -0
  43. package/src/toolPacks.js +1 -1
  44. package/src/toolPacks.ts +1 -1
  45. package/src/tools/toolSelfRepair.js +51 -8
  46. package/src/tools/toolSelfRepair.ts +42 -9
  47. package/src/tui/CausyneRotor.js +234 -0
  48. package/src/tui/CausyneRotor.ts +280 -0
  49. package/src/tui/activityLayout.js +1 -1
  50. package/src/tui/activityLayout.ts +1 -1
  51. package/src/tui/chatRenderer.js +62 -9
  52. package/src/tui/chatboxClipboard.js +96 -10
  53. package/src/tui/chatboxClipboard.ts +121 -11
  54. package/src/tui/clipboardImage.js +308 -0
  55. package/src/tui/clipboardImage.ts +320 -0
  56. package/src/tui/codeStreamRenderer.js +89 -1
  57. package/src/tui/codeStreamRenderer.ts +109 -1
  58. package/src/tui/completion.js +34 -15
  59. package/src/tui/composerControls.js +5 -0
  60. package/src/tui/composerControls.ts +5 -0
  61. package/src/tui/dialogs.js +5 -2
  62. package/src/tui/engineSpinner.js +20 -0
  63. package/src/tui/engineSpinner.ts +46 -0
  64. package/src/tui/layout.js +1 -1
  65. package/src/tui/layout.ts +1 -1
  66. package/src/tui/lineEditor.js +44 -12
  67. package/src/tui/messageInteraction.js +16 -5
  68. package/src/tui/messageInteraction.ts +14 -5
  69. package/src/tui/observerPicker.js +319 -0
  70. package/src/tui/observerPicker.ts +382 -0
  71. package/src/tui/prompt.js +247 -55
  72. package/src/tui/runningLight.js +213 -0
  73. package/src/tui/runningLight.ts +271 -0
  74. package/src/tui/sessionSidebar.js +7 -1
  75. package/src/tui/sessionSidebar.ts +7 -1
  76. package/src/tui/stage.js +4 -4
  77. package/src/tui/stageSurface.js +27 -10
  78. package/src/tui/statusLine.js +27 -4
  79. package/src/tui/statusLine.ts +27 -4
  80. package/src/tui/theme.js +5 -2
  81. package/src/tui/thinkingBox.js +41 -10
  82. package/src/tui/thinkingBox.ts +43 -10
  83. package/src/tui/turnRail.js +155 -24
  84. package/src/tui/turnRail.ts +170 -22
  85. package/src/tui/usageCard.js +178 -0
  86. package/src/tui/usageCard.ts +240 -0
  87. package/src/utils/paths.js +30 -1
  88. package/src/utils/paths.ts +32 -1
  89. package/src/cortex/autoCondenser.d.ts +0 -2
  90. package/src/cortex/vectorDb.d.ts +0 -1
package/src/commands.js CHANGED
@@ -45,7 +45,13 @@ import {
45
45
  import fs from 'fs';
46
46
  import os from 'os';
47
47
  import path from 'path';
48
+ import { execSync } from 'child_process';
48
49
  import { runCopyCommand, runPasteCommand } from './tui/chatboxClipboard.js';
50
+ import { loadLocalImageAttachment, formatByteSize } from './tui/clipboardImage.js';
51
+ import { getPackageVersion } from './version.js';
52
+ import { listGroups } from './checkpoints.js';
53
+ import { renameSession, getSession } from './sessionStore.js';
54
+ import { listPlugins } from './plugins/pluginManager.js';
49
55
 
50
56
  export const SCOPES = ['local'];
51
57
 
@@ -79,6 +85,13 @@ export const COMMANDS = [
79
85
  usage: '/help [command]',
80
86
  description: 'List the available commands',
81
87
  dialogTitle: 'Commands',
88
+ complete: () => {
89
+ return listCommands('terminal').map((c) => ({
90
+ value: c.name,
91
+ label: c.name,
92
+ description: c.description
93
+ }));
94
+ },
82
95
  run: (argv, ctx) => {
83
96
  const [wanted] = argv;
84
97
  if (wanted) {
@@ -368,7 +381,28 @@ export const COMMANDS = [
368
381
  scope: 'local',
369
382
  usage: '/undo [taskId] [--step] [--full] [--apply]',
370
383
  description: "Preview rolling back the last task's file changes (--apply to write)",
371
- run: (argv) => {
384
+ dialogTitle: 'Undo',
385
+ complete: () => {
386
+ try {
387
+ const groups = listGroups(10);
388
+ return [
389
+ { value: '--apply', label: '--apply', description: 'apply rollback directly to workspace' },
390
+ { value: '--step', label: '--step', description: 'roll back just the single last file change' },
391
+ { value: '--full', label: '--full', description: 'roll back entire workspace tree drift' },
392
+ ...groups.map((g) => ({
393
+ value: g.taskId,
394
+ label: g.taskId,
395
+ description: g.prompt ? `${g.prompt.slice(0, 36)} (${g.fileEntries.length} files)` : `${g.fileEntries.length} files`
396
+ }))
397
+ ];
398
+ } catch (e) {
399
+ return [
400
+ { value: '--apply', label: '--apply', description: 'apply rollback directly' },
401
+ { value: '--step', label: '--step', description: 'roll back just the single last file change' }
402
+ ];
403
+ }
404
+ },
405
+ run: (argv, ctx = {}) => {
372
406
  const flags = new Set(argv.filter(a => a.startsWith('--')));
373
407
  const taskId = argv.find(a => !a.startsWith('--'));
374
408
 
@@ -378,15 +412,17 @@ export const COMMANDS = [
378
412
  // should be able to overwrite a day's work, so the destructive form has
379
413
  // to be asked for by name.
380
414
  const apply = flags.has('--apply');
415
+ const workspaceRoot = ctx.loop?.workspaceRoot || process.cwd();
381
416
 
382
417
  const { ok: succeeded, text } = buildUndoText(taskId, {
383
418
  step: flags.has('--step'),
384
419
  full: flags.has('--full'),
385
- dryRun: !apply
420
+ dryRun: !apply,
421
+ workspaceRoot
386
422
  });
387
423
 
388
424
  if (!succeeded) return fail(text);
389
- if (apply) return ok(text);
425
+ if (apply) return ok(text, { effect: 'inline' });
390
426
  return ok(`${text}\n\nNothing was written. Run the same command with --apply to restore these files.`);
391
427
  }
392
428
  },
@@ -438,70 +474,61 @@ export const COMMANDS = [
438
474
  usage: '/usage',
439
475
  description: 'Show token usage and estimated cost',
440
476
  dialogTitle: 'Usage',
441
- run: async () => ok(await buildUsageText())
477
+ run: async (argv, ctx = {}) => {
478
+ if (ctx.prompt && typeof ctx.prompt.toggleUsageCard === 'function') {
479
+ await ctx.prompt.toggleUsageCard(ctx.loop);
480
+ return ok('', { effect: 'silent' });
481
+ }
482
+ return ok(await buildUsageText());
483
+ }
442
484
  },
443
485
 
444
486
  {
445
- name: 'cortex',
446
- aliases: ['brain'],
487
+ name: 'diff',
488
+ aliases: ['changes', 'git-diff'],
447
489
  scope: 'local',
448
- usage: '/cortex [list | forget <id> | forget-here]',
449
- description: 'Inspect what the agent has learned, and forget any of it',
450
- dialogTitle: 'Cortex',
451
- // A memory store you cannot read is not a memory, it is a black box that
452
- // occasionally changes the agent's behaviour. Section 4 asks for intelligent
453
- // safety rather than opacity, and section 10 layer 5 asks for a trail a
454
- // human can review. This is that surface.
455
- run: async (args = []) => {
456
- const { cortexDb } = await import('./cortex/vectorDb.js');
457
- const verb = String(args[0] || '').toLowerCase();
458
-
490
+ usage: '/diff [staged | stat]',
491
+ description: 'Show working tree or staged diff for the active workspace',
492
+ dialogTitle: 'Diff',
493
+ complete: () => [
494
+ { value: 'staged', label: 'staged', description: 'show staged changes only (--cached)' },
495
+ { value: 'stat', label: 'stat', description: 'show diff summary statistics' }
496
+ ],
497
+ run: (argv, ctx = {}) => {
498
+ const ws = ctx.loop?.workspaceRoot || process.cwd();
499
+ const sub = (argv[0] || '').toLowerCase();
459
500
  try {
460
- if (verb === 'forget' && args[1]) {
461
- const removed = await cortexDb.forget({ id: args[1] });
462
- return removed ? ok('Forgotten.') : fail(`No memory "${args[1]}".`);
463
- }
464
-
465
- if (verb === 'forget-here') {
466
- const removed = await cortexDb.forget({ workspace: process.cwd() });
467
- return ok(removed === 0
468
- ? 'Nothing was learned in this project yet.'
469
- : `Forgot ${removed} memor${removed === 1 ? 'y' : 'ies'} from this project. Global lessons are untouched.`);
501
+ let isGit = fs.existsSync(path.join(ws, '.git'));
502
+ if (!isGit) {
503
+ try {
504
+ execSync('git rev-parse --is-inside-work-tree', { cwd: ws, stdio: 'pipe' });
505
+ isGit = true;
506
+ } catch {
507
+ isGit = false;
508
+ }
470
509
  }
471
510
 
472
- const stats = await cortexDb.stats();
473
- if (stats.total === 0) {
474
- return ok('Nothing learned yet. Cortex records a lesson when a task recovers from a real error.');
511
+ if (!isGit) {
512
+ return ok(`Workspace "${ws}" is not a git repository.`);
475
513
  }
476
514
 
477
- const kinds = stats.byKind.map((k) => `${k.c} ${k.kind}`).join(', ');
478
- const age = stats.newest ? new Date(stats.newest).toISOString().slice(0, 10) : 'never';
479
- const header = `${stats.total} memories (${kinds}) across ${stats.workspaces} project(s). Newest: ${age}.`;
480
-
481
- if (verb !== 'list') {
482
- return ok(header + '\n\nSee them with /cortex list. Forget this project\'s with /cortex forget-here.');
515
+ const status = execSync('git status --short', { cwd: ws, encoding: 'utf8' }).trim();
516
+ if (!status) {
517
+ return ok('Working tree is clean. No uncommitted changes in this workspace.');
483
518
  }
484
519
 
485
- const rows = await cortexDb.inventory({ workspace: process.cwd() });
486
- if (rows.length === 0) {
487
- return ok(header + '\n\nNothing applies to this project.');
520
+ let diffCmd = 'git diff';
521
+ if (sub === 'staged' || sub === '--cached') {
522
+ diffCmd = 'git diff --cached';
523
+ } else if (sub === 'stat') {
524
+ diffCmd = 'git diff --stat HEAD';
488
525
  }
489
526
 
490
- const home = process.env.HOME || '';
491
- const lines = rows.slice(0, 15).map((r) => {
492
- const when = new Date(r.timestamp).toISOString().slice(0, 10);
493
- const where = r.workspace ? (home ? r.workspace.replace(home, '~') : r.workspace) : 'global';
494
- const first = String(r.text).split('\n').filter(Boolean).slice(0, 2).join(' — ').slice(0, 96);
495
- return ` ${r.id} ${when} ${String(r.hits).padStart(3)} hits [${r.kind}] ${where}\n ${first}`;
496
- });
497
-
498
- return ok(header + '\n\nApplying to this project:\n' + lines.join('\n')
499
- + '\n\nForget one with /cortex forget <id>.');
500
- } catch (e) {
501
- // The neural engine is provisioned at runtime and can be absent. Saying
502
- // so is the point: a silent Cortex is indistinguishable from an empty
503
- // one, and the user is entitled to know which they have.
504
- return fail(`Cortex is unavailable: ${e.message}. Memories are not being recorded or retrieved.`);
527
+ const diffOutput = execSync(diffCmd, { cwd: ws, encoding: 'utf8', maxBuffer: 1024 * 1024 }).trim();
528
+ const header = `Git Status (${ws}):\n${status}\n\n${'─'.repeat(50)}\n${diffCmd}:\n`;
529
+ return ok(diffOutput ? `${header}\n${diffOutput}` : `${header}\n(no file diff for ${diffCmd})`);
530
+ } catch (err) {
531
+ return fail(`Could not inspect git diff: ${err.message}`);
505
532
  }
506
533
  }
507
534
  },
@@ -512,6 +539,10 @@ export const COMMANDS = [
512
539
  usage: '/plans [import <json-file> | forget]',
513
540
  description: 'Inspect, pre-warm, or clear reusable task plans',
514
541
  dialogTitle: 'Plan cache',
542
+ complete: () => [
543
+ { value: 'import', label: 'import', description: 'import seed plans from a JSON file' },
544
+ { value: 'forget', label: 'forget', description: 'clear all cached plans' }
545
+ ],
515
546
  run: async (args = []) => {
516
547
  const cache = await import('./planCache.js');
517
548
  const verb = String(args[0] || '').toLowerCase();
@@ -557,9 +588,33 @@ export const COMMANDS = [
557
588
  {
558
589
  name: 'plugins',
559
590
  scope: 'local',
560
- usage: '/plugins [enable <name> | disable <name>]',
591
+ usage: '/plugins [list | enable <name> | disable <name>]',
561
592
  description: 'Inspect or change trust for local plugins',
562
593
  dialogTitle: 'Plugins',
594
+ complete: () => {
595
+ try {
596
+ const rows = listPlugins();
597
+ return [
598
+ { value: 'list', label: 'list', description: 'list local plugins and trust status' },
599
+ ...rows.map((p) => ({
600
+ value: `enable ${p.name}`,
601
+ label: `enable ${p.name}`,
602
+ description: `enable plugin ${p.name}`
603
+ })),
604
+ ...rows.map((p) => ({
605
+ value: `disable ${p.name}`,
606
+ label: `disable ${p.name}`,
607
+ description: `disable plugin ${p.name}`
608
+ }))
609
+ ];
610
+ } catch (e) {
611
+ return [
612
+ { value: 'list', label: 'list', description: 'list local plugins' },
613
+ { value: 'enable', label: 'enable', description: 'enable a local plugin' },
614
+ { value: 'disable', label: 'disable', description: 'disable a local plugin' }
615
+ ];
616
+ }
617
+ },
563
618
  run: async (args = []) => {
564
619
  const manager = await import('./plugins/pluginManager.js');
565
620
  const verb = String(args[0] || '').toLowerCase();
@@ -863,6 +918,11 @@ export const COMMANDS = [
863
918
  usage: '/continuum [list | read <id> | adopt <id>]',
864
919
  description: 'Cross-agent session extraction and resumption (Antigravity, OpenCode, Codex, Claude Code)',
865
920
  dialogTitle: 'Continuum',
921
+ complete: () => [
922
+ { value: 'list', label: 'list', description: 'scan and list cross-agent sessions' },
923
+ { value: 'adopt', label: 'adopt', description: 'adopt and resume a peer agent session' },
924
+ { value: 'read', label: 'read', description: 'preview transcript of a peer session' }
925
+ ],
866
926
  run: async (args = [], context = {}) => {
867
927
  const {
868
928
  ContinuumScanner,
@@ -936,6 +996,9 @@ export const COMMANDS = [
936
996
  usage: '/approvals [clear]',
937
997
  description: 'List tools granted "Allow always", or revoke them',
938
998
  dialogTitle: 'Approvals',
999
+ complete: () => [
1000
+ { value: 'clear', label: 'clear', description: 'revoke all standing "Allow always" grants' }
1001
+ ],
939
1002
  // A standing grant with no way to see or revoke it is a trap, not a
940
1003
  // convenience. This is the way out, and the confirm dialog that grants one
941
1004
  // names this command so the user is told about it at the moment it matters.
@@ -967,16 +1030,17 @@ export const COMMANDS = [
967
1030
  scope: 'local',
968
1031
  usage: '/thinking [toggle|expand|collapse]',
969
1032
  description: 'Toggle or fold thinking process chunks in the conversation transcript',
1033
+ complete: () => [
1034
+ { value: 'toggle', label: 'toggle', description: 'toggle collapsed state of thinking blocks' },
1035
+ { value: 'expand', label: 'expand', description: 'expand all thinking blocks' },
1036
+ { value: 'collapse', label: 'collapse', description: 'collapse all thinking blocks' }
1037
+ ],
970
1038
  run: (argv, ctx) => {
971
1039
  const surface = ctx?.prompt?.surface;
972
1040
  const transcript = surface?.transcript;
973
- if (!transcript || !Array.isArray(transcript.frames)) {
974
- return ok('No active interactive transcript available.');
975
- }
976
- const reasoningFrames = transcript.frames.filter((f) => f.kind === 'reasoning');
977
- if (reasoningFrames.length === 0) {
978
- return ok('No thinking process frames found in the current conversation.');
979
- }
1041
+ const reasoningFrames = Array.isArray(transcript?.frames)
1042
+ ? transcript.frames.filter((f) => f.kind === 'reasoning' || f.meta?.reasoning === true)
1043
+ : [];
980
1044
  const sub = (argv[0] || 'toggle').toLowerCase();
981
1045
  let newCollapsed;
982
1046
  if (sub === 'expand') {
@@ -994,11 +1058,22 @@ export const COMMANDS = [
994
1058
  frame.renderedWidth = -1;
995
1059
  }
996
1060
  }
997
- transcript.cache = null;
998
- transcript.revision++;
999
- transcript.changed?.();
1000
- if (ctx.prompt?.scheduleDraw) ctx.prompt.scheduleDraw();
1001
- return ok(`${newCollapsed ? 'Collapsed' : 'Expanded'} ${reasoningFrames.length} thinking frame${reasoningFrames.length === 1 ? '' : 's'}.`);
1061
+ if (transcript) {
1062
+ transcript.cache = null;
1063
+ transcript.revision++;
1064
+ transcript.changed?.();
1065
+ }
1066
+
1067
+ const msg = reasoningFrames.length === 0
1068
+ ? 'No thinking process frames found in the current conversation.'
1069
+ : `${newCollapsed ? 'Collapsed' : 'Expanded'} ${reasoningFrames.length} thinking frame${reasoningFrames.length === 1 ? '' : 's'}.`;
1070
+
1071
+ if (ctx.prompt) {
1072
+ ctx.prompt.notice = msg;
1073
+ if (ctx.prompt.scheduleDraw) ctx.prompt.scheduleDraw();
1074
+ return ok(msg, { effect: 'silent' });
1075
+ }
1076
+ return ok(msg);
1002
1077
  }
1003
1078
  },
1004
1079
 
@@ -1053,9 +1128,15 @@ export const COMMANDS = [
1053
1128
  scope: 'local',
1054
1129
  usage: '/copy [input | last | <text>]',
1055
1130
  description: 'Copy chatbox input, last assistant response, or text to system clipboard',
1131
+ complete: () => [
1132
+ { value: 'last', label: 'last', description: 'copy last assistant response to clipboard' },
1133
+ { value: 'input', label: 'input', description: 'copy current chatbox input to clipboard' }
1134
+ ],
1056
1135
  run: (argv, ctx) => {
1057
1136
  const res = runCopyCommand(argv, ctx);
1058
- return res.ok ? ok(res.output) : fail(res.output);
1137
+ return res.ok
1138
+ ? ok(res.output, { effect: ctx.prompt ? 'silent' : undefined })
1139
+ : fail(res.output);
1059
1140
  }
1060
1141
  },
1061
1142
 
@@ -1067,7 +1148,39 @@ export const COMMANDS = [
1067
1148
  description: 'Paste clipboard content or text into the chatbox input',
1068
1149
  run: (argv, ctx) => {
1069
1150
  const res = runPasteCommand(argv, ctx);
1070
- return res.ok ? ok(res.output) : fail(res.output);
1151
+ return res.ok
1152
+ ? ok(res.output, { effect: ctx.prompt ? 'silent' : undefined })
1153
+ : fail(res.output);
1154
+ }
1155
+ },
1156
+
1157
+ {
1158
+ name: 'image',
1159
+ aliases: ['attach', 'screenshot'],
1160
+ scope: 'local',
1161
+ usage: '/image [path]',
1162
+ description: 'Attach a screenshot from clipboard or a local image file to the chat prompt',
1163
+ run: (argv, ctx) => {
1164
+ if (!ctx.prompt) {
1165
+ return fail('The /image command is only available in interactive chat mode.');
1166
+ }
1167
+ if (argv.length === 0) {
1168
+ const res = runPasteCommand([], ctx);
1169
+ return res.ok ? ok(res.output, { effect: 'silent' }) : fail(res.output);
1170
+ }
1171
+ const rawPath = argv.join(' ');
1172
+ const img = loadLocalImageAttachment(rawPath);
1173
+ if (!img) {
1174
+ return fail(`Could not load image at "${rawPath}". Ensure file exists and is a valid image (PNG, JPEG, WebP, GIF).`);
1175
+ }
1176
+ if (!Array.isArray(ctx.prompt.pendingAttachments)) {
1177
+ ctx.prompt.pendingAttachments = [];
1178
+ }
1179
+ ctx.prompt.pendingAttachments.push(img);
1180
+ ctx.prompt.editor.insert(`[Image: ${img.name}] `);
1181
+ ctx.prompt.notice = `attached image ${img.name} (${formatByteSize(img.size)})`;
1182
+ ctx.prompt.scheduleDraw();
1183
+ return ok(`Attached image ${img.name} (${formatByteSize(img.size)}) to chat prompt.`, { effect: 'silent' });
1071
1184
  }
1072
1185
  },
1073
1186
 
@@ -1081,7 +1194,8 @@ export const COMMANDS = [
1081
1194
  const loop = ctx.loop;
1082
1195
  if (loop && typeof loop.abort === 'function') {
1083
1196
  loop.abort();
1084
- return ok('Stop requested.');
1197
+ if (ctx.prompt) ctx.prompt.notice = 'stop requested';
1198
+ return ok('Stop requested.', { effect: ctx.prompt ? 'silent' : undefined });
1085
1199
  }
1086
1200
  return fail('Nothing is running.');
1087
1201
  }
@@ -1453,6 +1567,25 @@ export const COMMANDS = [
1453
1567
  usage: '/mcp [add <name> <cmd…> | add <name> --url <url> | remove|grant|revoke|connect|disconnect|test|refresh <name>]',
1454
1568
  description: 'Manage and diagnose MCP server connections',
1455
1569
  dialogTitle: 'MCP servers',
1570
+ complete: () => {
1571
+ try {
1572
+ const servers = serverStatus();
1573
+ const base = [
1574
+ { value: 'add', label: 'add', description: 'add a new stdio or SSE/HTTP MCP server' }
1575
+ ];
1576
+ for (const s of servers) {
1577
+ base.push({ value: `test ${s.name}`, label: `test ${s.name}`, description: `test ${s.name} connection` });
1578
+ base.push({ value: `grant ${s.name}`, label: `grant ${s.name}`, description: `grant consent to ${s.name}` });
1579
+ base.push({ value: `revoke ${s.name}`, label: `revoke ${s.name}`, description: `revoke consent from ${s.name}` });
1580
+ base.push({ value: `remove ${s.name}`, label: `remove ${s.name}`, description: `remove ${s.name}` });
1581
+ base.push({ value: `refresh ${s.name}`, label: `refresh ${s.name}`, description: `refresh tools for ${s.name}` });
1582
+ base.push({ value: `disconnect ${s.name}`, label: `disconnect ${s.name}`, description: `disconnect ${s.name}` });
1583
+ }
1584
+ return base;
1585
+ } catch (e) {
1586
+ return [{ value: 'add', label: 'add', description: 'add an MCP server' }];
1587
+ }
1588
+ },
1456
1589
  run: async (argv) => {
1457
1590
  const [action, serverName, ...rest] = argv;
1458
1591
 
@@ -1554,6 +1687,26 @@ export const COMMANDS = [
1554
1687
  usage: '/peers [detect | test <id> | add <id> <command…> | remove <id>]',
1555
1688
  description: 'Manage, discover, and test external ACP peer agents (Claude Code, OpenCode, Codex, Gemini, Hermes, etc.)',
1556
1689
  dialogTitle: 'ACP peer agents',
1690
+ complete: () => {
1691
+ try {
1692
+ const peers = listAllPeers();
1693
+ return [
1694
+ { value: 'detect', label: 'detect', description: 'scan system for installed ACP agents' },
1695
+ ...peers.map((p) => ({
1696
+ value: `test ${p.id}`,
1697
+ label: `test ${p.id}`,
1698
+ description: `test zero-token handshake with ${p.label}`
1699
+ })),
1700
+ ...peers.map((p) => ({
1701
+ value: `remove ${p.id}`,
1702
+ label: `remove ${p.id}`,
1703
+ description: `remove peer profile for ${p.label}`
1704
+ }))
1705
+ ];
1706
+ } catch (e) {
1707
+ return [{ value: 'detect', label: 'detect', description: 'scan system for installed ACP agents' }];
1708
+ }
1709
+ },
1557
1710
  run: async (argv) => {
1558
1711
  const [action, peerId, ...rest] = argv;
1559
1712
 
@@ -1626,14 +1779,14 @@ export const COMMANDS = [
1626
1779
  command: rest[0],
1627
1780
  args: rest.slice(1),
1628
1781
  cwd: null,
1629
- policy: 'read-only',
1782
+ policy: 'workspace',
1630
1783
  timeoutSeconds: 180,
1631
1784
  env: {}
1632
1785
  };
1633
1786
 
1634
1787
  const res = addPeerProfile(newProfile);
1635
1788
  if (!res.ok) return fail(`Could not save peer: ${res.error}`);
1636
- return ok(`Added peer "${peerId}" [policy: read-only]. Edit ~/.causyne/peers.json to customize policy, timeout, or environment.`);
1789
+ return ok(`Added peer "${peerId}" [policy: workspace]. Edit ~/.causyne/peers.json to customize policy, timeout, or environment.`);
1637
1790
  }
1638
1791
 
1639
1792
  if (action === 'remove') {
@@ -1668,6 +1821,10 @@ export const COMMANDS = [
1668
1821
  scope: 'local',
1669
1822
  usage: '/slop <file… | directory> [--movements]',
1670
1823
  description: 'Score HTML/CSS against the anti-AI-slop rules (Vision §7)',
1824
+ dialogTitle: 'Slop audit',
1825
+ complete: () => [
1826
+ { value: '--movements', label: '--movements', description: 'show recommended design movements' }
1827
+ ],
1671
1828
  run: (argv) => {
1672
1829
  const wantsMovements = argv.includes('--movements');
1673
1830
  const targets = argv.filter(a => !a.startsWith('--'));
@@ -1675,9 +1832,7 @@ export const COMMANDS = [
1675
1832
  if (wantsMovements && targets.length === 0) {
1676
1833
  return ok('Design movements to commit to:\n\n' + formatMovementBrief(DESIGN_MOVEMENTS));
1677
1834
  }
1678
- if (targets.length === 0) {
1679
- return fail('Usage: slop <file… | directory> (or: slop --movements to see the catalogue)');
1680
- }
1835
+ const scanTargets = targets.length > 0 ? targets : ['.'];
1681
1836
 
1682
1837
  const files = [];
1683
1838
  const collect = (target) => {
@@ -1708,9 +1863,9 @@ export const COMMANDS = [
1708
1863
  return null;
1709
1864
  };
1710
1865
 
1711
- const problems = targets.map(collect).filter(Boolean);
1866
+ const problems = scanTargets.map(collect).filter(Boolean);
1712
1867
  if (files.length === 0) {
1713
- return fail(problems.length > 0 ? problems.join('\n') : 'Nothing to scan.');
1868
+ return ok(problems.length > 0 ? problems.join('\n') : 'No HTML/CSS/component files found — nothing to score. Try: /slop <path> or /slop --movements.');
1714
1869
  }
1715
1870
 
1716
1871
  const result = analyzeFiles(files);
@@ -1741,8 +1896,27 @@ export const COMMANDS = [
1741
1896
  usage: '/observer [status|toggle|mode <deterministic|advisory>|endpoint <url|none>|model <name>|strictness <relaxed|standard|strict>|test|audit|reset]',
1742
1897
  description: 'Inspect or configure the Cold Observer',
1743
1898
  dialogTitle: 'Cold Observer',
1744
- run: async (argv) => {
1899
+ complete: () => [
1900
+ { value: 'status', label: 'status', description: 'view Cold Observer status and audits' },
1901
+ { value: 'toggle', label: 'toggle', description: 'toggle Cold Observer on/off' },
1902
+ { value: 'mode deterministic', label: 'mode deterministic', description: 'fast deterministic rules' },
1903
+ { value: 'mode advisory', label: 'mode advisory', description: 'neural advisory verification' },
1904
+ { value: 'strictness standard', label: 'strictness standard', description: 'standard safety strictness' },
1905
+ { value: 'strictness strict', label: 'strictness strict', description: 'maximum safety strictness' },
1906
+ { value: 'test', label: 'test', description: 'test advisory endpoint' },
1907
+ { value: 'audit', label: 'audit', description: 'show recent audit history' },
1908
+ { value: 'reset', label: 'reset', description: 'restore default settings' }
1909
+ ],
1910
+ run: async (argv, ctx = {}) => {
1745
1911
  const { coldObserver } = await import('./observer/coldObserver.js');
1912
+
1913
+ // If interactive prompt is active and no sub-arguments or 'status' is given, open the interactive setup menu
1914
+ if ((!argv || argv.length === 0 || argv[0] === '' || argv[0] === 'status') && ctx.prompt) {
1915
+ const { runInteractiveObserverPicker } = await import('./tui/observerPicker.js');
1916
+ const message = await runInteractiveObserverPicker(ctx.prompt);
1917
+ return ok(message, { effect: 'silent' });
1918
+ }
1919
+
1746
1920
  const sub = (argv[0] || 'status').toLowerCase();
1747
1921
 
1748
1922
  if (sub === 'toggle') {
@@ -1858,6 +2032,10 @@ export const COMMANDS = [
1858
2032
  usage: '/acp [status|peers]',
1859
2033
  description: 'Agent Client Protocol (ACP) server and peer delegation status',
1860
2034
  dialogTitle: 'Agent Client Protocol',
2035
+ complete: () => [
2036
+ { value: 'status', label: 'status', description: 'view ACP protocol server status' },
2037
+ { value: 'peers', label: 'peers', description: 'view ACP peer delegation configuration' }
2038
+ ],
1861
2039
  run: async (argv) => {
1862
2040
  const sub = (argv[0] || 'status').toLowerCase();
1863
2041
  if (sub === 'peer' || sub === 'peers') {
@@ -1888,6 +2066,284 @@ export const COMMANDS = [
1888
2066
  }
1889
2067
  },
1890
2068
 
2069
+ {
2070
+ name: 'init',
2071
+ aliases: ['initialize'],
2072
+ scope: 'local',
2073
+ usage: '/init',
2074
+ description: 'Inspect active workspace architecture and generate or update AGENTS.md instructions',
2075
+ dialogTitle: 'Workspace Init',
2076
+ run: async (argv, ctx = {}) => {
2077
+ const ws = ctx.loop?.workspaceRoot || process.cwd();
2078
+ const files = fs.existsSync(ws) ? fs.readdirSync(ws) : [];
2079
+ const hasPkg = files.includes('package.json');
2080
+ const hasCargo = files.includes('Cargo.toml');
2081
+ const hasPy = files.includes('pyproject.toml') || files.includes('requirements.txt');
2082
+ const hasGo = files.includes('go.mod');
2083
+ const hasAgents = files.includes('AGENTS.md');
2084
+
2085
+ const detected = [];
2086
+ if (hasPkg) detected.push('Node.js / JavaScript / TypeScript');
2087
+ if (hasCargo) detected.push('Rust / Cargo');
2088
+ if (hasPy) detected.push('Python');
2089
+ if (hasGo) detected.push('Go');
2090
+ if (detected.length === 0) detected.push('Generic workspace');
2091
+
2092
+ const summary = [
2093
+ `Workspace Initializer: ${ws}`,
2094
+ `Ecosystem: ${detected.join(', ')}`,
2095
+ `AGENTS.md: ${hasAgents ? 'Present (ready for refresh)' : 'Not found (needs creation)'}`,
2096
+ '',
2097
+ 'To have Causyne Agent inspect and establish conventions for this project,',
2098
+ 'run this turn or press Enter to prompt the agent:'
2099
+ ].join('\n');
2100
+
2101
+ if (ctx.prompt) {
2102
+ ctx.prompt.editor.setText('Analyze this project architecture, testing setup, and style conventions, then create or update AGENTS.md for this workspace.');
2103
+ ctx.prompt.scheduleDraw();
2104
+ return ok(summary, { effect: 'inline' });
2105
+ }
2106
+ return ok(summary);
2107
+ }
2108
+ },
2109
+
2110
+ {
2111
+ name: 'review',
2112
+ aliases: ['code-review', 'pr-review'],
2113
+ scope: 'local',
2114
+ usage: '/review [target]',
2115
+ description: 'Run an immediate code review on working tree changes or a file',
2116
+ dialogTitle: 'Code Review',
2117
+ run: async (argv, ctx = {}) => {
2118
+ const ws = ctx.loop?.workspaceRoot || process.cwd();
2119
+ const target = argv.join(' ').trim();
2120
+ let promptText = '';
2121
+ if (target) {
2122
+ promptText = `Please review ${target} for security vulnerabilities, logic correctness, performance, and best practices.`;
2123
+ } else {
2124
+ try {
2125
+ const status = execSync('git status --short', { cwd: ws, encoding: 'utf8' }).trim();
2126
+ if (!status) {
2127
+ return ok('Working tree is clean. To review a specific file, run: /review <path>');
2128
+ }
2129
+ promptText = `Please review current uncommitted workspace changes (git diff) for correctness, edge cases, regression risk, and code quality.`;
2130
+ } catch {
2131
+ promptText = `Please review the files in this workspace for code quality, architectural consistency, and potential bugs.`;
2132
+ }
2133
+ }
2134
+
2135
+ if (ctx.prompt) {
2136
+ ctx.prompt.editor.setText(promptText);
2137
+ ctx.prompt.scheduleDraw();
2138
+ return ok(`Ready to review: "${promptText}"`, { effect: 'inline' });
2139
+ }
2140
+ return ok(`Code review target: ${promptText}`);
2141
+ }
2142
+ },
2143
+
2144
+ {
2145
+ name: 'retry',
2146
+ aliases: ['again', 'redo'],
2147
+ scope: 'local',
2148
+ usage: '/retry',
2149
+ description: 'Re-send the last user prompt in this session',
2150
+ run: async (argv, ctx = {}) => {
2151
+ const messages = ctx.loop?.messages || [];
2152
+ const lastUser = [...messages].reverse().find(m => m.role === 'user' && typeof m.content === 'string');
2153
+ if (!lastUser || !lastUser.content) {
2154
+ return fail('No previous user prompt found in this session to retry.');
2155
+ }
2156
+ const promptText = lastUser.content;
2157
+ if (ctx.prompt) {
2158
+ ctx.prompt.editor.setText(promptText);
2159
+ ctx.prompt.scheduleDraw();
2160
+ return ok(`Re-loaded last prompt: "${promptText.slice(0, 80)}"`, { effect: 'inline' });
2161
+ }
2162
+ return ok(`Last prompt: ${promptText}`);
2163
+ }
2164
+ },
2165
+
2166
+ {
2167
+ name: 'title',
2168
+ aliases: ['rename'],
2169
+ scope: 'local',
2170
+ usage: '/title [new title]',
2171
+ description: 'View or rename the active chat session title',
2172
+ dialogTitle: 'Session Title',
2173
+ run: async (argv, ctx = {}) => {
2174
+ const activeId = getActiveSessionId();
2175
+ if (!activeId) return fail('No active session.');
2176
+ const session = getSession(activeId);
2177
+ const currentTitle = session ? session.title : 'Untitled';
2178
+
2179
+ const newTitle = argv.join(' ').trim();
2180
+ if (!newTitle) {
2181
+ return ok(`Active session ID: ${activeId}\nCurrent title: "${currentTitle}"\n\nTo rename, run: /title <new name>`);
2182
+ }
2183
+
2184
+ const renamed = renameSession(activeId, newTitle);
2185
+ if (!renamed) return fail(`Could not rename session "${activeId}".`);
2186
+
2187
+ if (ctx.loop?.memoryManager?.session) {
2188
+ ctx.loop.memoryManager.session.title = newTitle;
2189
+ }
2190
+ if (ctx.prompt?.renderer?.status) {
2191
+ ctx.prompt.renderer.status.setSession({ title: newTitle });
2192
+ }
2193
+ if (ctx.prompt?.surface?.stage) {
2194
+ ctx.prompt.scheduleDraw();
2195
+ }
2196
+
2197
+ return ok(`Session renamed to: "${newTitle}"`, { effect: 'inline' });
2198
+ }
2199
+ },
2200
+
2201
+ {
2202
+ name: 'mode',
2203
+ aliases: ['autonomy'],
2204
+ scope: 'local',
2205
+ usage: '/mode [A | B | C]',
2206
+ description: 'View or switch autonomy mode (A: Ask, B: Balanced, C: Autonomous)',
2207
+ dialogTitle: 'Autonomy Mode',
2208
+ complete: () => [
2209
+ { value: 'A', label: 'A', description: 'Ask — review actions before execution' },
2210
+ { value: 'B', label: 'B', description: 'Balanced — normal supervised autonomy' },
2211
+ { value: 'C', label: 'C', description: 'Autonomous — maximum runway within policy' }
2212
+ ],
2213
+ run: async (argv, ctx = {}) => {
2214
+ const config = loadConfig();
2215
+ const target = (argv[0] || '').toUpperCase().trim();
2216
+ if (!target) {
2217
+ if (ctx.prompt) {
2218
+ const { openModeControl } = await import('./tui/composerControls.js');
2219
+ if (ctx.loop) {
2220
+ openModeControl(ctx.prompt, ctx.loop);
2221
+ return ok('Opened mode selector.', { effect: 'silent' });
2222
+ }
2223
+ }
2224
+ return ok(`Current autonomy mode: ${config.autonomyMode || 'B'}\nModes:\n A: Ask (confirm gated actions)\n B: Balanced (supervised execution)\n C: Autonomous (independent execution)`);
2225
+ }
2226
+
2227
+ if (!['A', 'B', 'C'].includes(target)) {
2228
+ return fail(`Invalid mode "${target}". Choose A, B, or C.`);
2229
+ }
2230
+
2231
+ config.autonomyMode = target;
2232
+ saveConfig(config);
2233
+ if (ctx.loop && typeof ctx.loop.setAutonomyMode === 'function') {
2234
+ ctx.loop.setAutonomyMode(target);
2235
+ }
2236
+ if (ctx.prompt) {
2237
+ ctx.prompt.notice = `Mode ${target} active`;
2238
+ if (ctx.prompt.scheduleDraw) ctx.prompt.scheduleDraw();
2239
+ return ok(`Autonomy mode switched to ${target}.`, { effect: 'inline' });
2240
+ }
2241
+ return ok(`Autonomy mode switched to ${target}.`);
2242
+ }
2243
+ },
2244
+
2245
+ {
2246
+ name: 'doctor',
2247
+ aliases: ['health', 'diagnostics'],
2248
+ scope: 'local',
2249
+ usage: '/doctor',
2250
+ description: 'Run environment, provider, and tool health diagnostics',
2251
+ dialogTitle: 'Doctor',
2252
+ run: async (_argv, ctx = {}) => {
2253
+ const config = loadConfig();
2254
+ const lines = ['Causyne Health & Diagnostics', ''];
2255
+
2256
+ const nodeVer = process.version;
2257
+ const nodeOk = parseInt(nodeVer.slice(1).split('.')[0], 10) >= 24;
2258
+ lines.push(` ${nodeOk ? '✅' : '⚠️'} Node.js version : ${nodeVer} ${nodeOk ? '(supported)' : '(Node >= 24 required)'}`);
2259
+ lines.push(` ℹ️ Platform : ${process.platform} (${process.arch})`);
2260
+
2261
+ const ws = ctx.loop?.workspaceRoot || process.cwd();
2262
+ let isGit = false;
2263
+ try {
2264
+ execSync('git rev-parse --is-inside-work-tree', { cwd: ws, stdio: 'pipe' });
2265
+ isGit = true;
2266
+ } catch {}
2267
+ lines.push(` ✅ Workspace root : ${ws}`);
2268
+ lines.push(` ${isGit ? '✅' : 'ℹ️'} Git repository : ${isGit ? 'active' : 'not a git repo'}`);
2269
+
2270
+ const provider = config.provider || 'not configured';
2271
+ const model = config.model || 'default';
2272
+ lines.push(` ℹ️ Provider / Model : ${provider} / ${model}`);
2273
+
2274
+ const servers = serverStatus();
2275
+ const grantedCount = servers.filter(s => s.granted).length;
2276
+ lines.push(` ℹ️ MCP Servers : ${servers.length} configured (${grantedCount} granted)`);
2277
+
2278
+ const peers = listAllPeers();
2279
+ lines.push(` ℹ️ ACP Peers : ${peers.length} available`);
2280
+
2281
+ lines.push('');
2282
+ lines.push('All diagnostic invariants passed. Run /peers detect or /model list for component details.');
2283
+ return ok(lines.join('\n'));
2284
+ }
2285
+ },
2286
+
2287
+ {
2288
+ name: 'export',
2289
+ aliases: ['share', 'save'],
2290
+ scope: 'local',
2291
+ usage: '/export [filename.md]',
2292
+ description: 'Export conversation transcript to a Markdown document in the workspace',
2293
+ dialogTitle: 'Export Conversation',
2294
+ run: async (argv, ctx = {}) => {
2295
+ const activeId = getActiveSessionId();
2296
+ if (!activeId) return fail('No active session to export.');
2297
+ const session = getSession(activeId);
2298
+ if (!session || !session.messages || session.messages.length === 0) {
2299
+ return fail('Session has no messages to export.');
2300
+ }
2301
+
2302
+ const ws = ctx.loop?.workspaceRoot || process.cwd();
2303
+ const defaultFilename = `causyne-session-${activeId}.md`;
2304
+ const filename = argv.join(' ').trim() || defaultFilename;
2305
+ const targetPath = path.resolve(ws, filename);
2306
+
2307
+ const header = `# Causyne Agent Conversation Export\n\n- **Session ID**: \`${session.id}\`\n- **Title**: ${session.title}\n- **Date**: ${new Date(session.createdAt).toISOString()}\n- **Workspace**: \`${session.workspace}\`\n- **Total Messages**: ${session.messages.length}\n\n---\n\n`;
2308
+
2309
+ const body = session.messages
2310
+ .filter(m => m.role !== 'system')
2311
+ .map(m => {
2312
+ const roleLabel = m.role === 'user' ? '### 👤 User' : '### 🤖 Causyne Agent';
2313
+ return `${roleLabel}\n\n${typeof m.content === 'string' ? m.content : JSON.stringify(m.content, null, 2)}\n`;
2314
+ })
2315
+ .join('\n---\n\n');
2316
+
2317
+ try {
2318
+ fs.writeFileSync(targetPath, header + body, { encoding: 'utf8', mode: 0o644 });
2319
+ return ok(`Exported conversation to: ${targetPath}`);
2320
+ } catch (err) {
2321
+ return fail(`Could not export conversation: ${err.message}`);
2322
+ }
2323
+ }
2324
+ },
2325
+
2326
+ {
2327
+ name: 'version',
2328
+ aliases: ['v', 'about'],
2329
+ scope: 'local',
2330
+ usage: '/version',
2331
+ description: 'Display Causyne Agent version and runtime environment',
2332
+ dialogTitle: 'Version',
2333
+ run: async () => {
2334
+ const version = getPackageVersion();
2335
+ const config = loadConfig();
2336
+ return ok([
2337
+ `Causyne Agent v${version}`,
2338
+ ` Runtime : Node.js ${process.version} (${process.platform} ${process.arch})`,
2339
+ ` Provider : ${config.provider || 'default'}`,
2340
+ ` Model : ${config.model || 'default'}`,
2341
+ ` License : Business Source License 1.1 (BUSL-1.1)`,
2342
+ ` Website : https://causyne.com`
2343
+ ].join('\n'));
2344
+ }
2345
+ },
2346
+
1891
2347
  {
1892
2348
  name: 'exit',
1893
2349
  aliases: ['quit'],