@causyne/agent 1.20.62 → 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 (59) hide show
  1. package/README.md +2 -2
  2. package/package.json +1 -1
  3. package/src/acp/client.js +48 -0
  4. package/src/acp/client.ts +44 -0
  5. package/src/agentLoop.js +181 -11
  6. package/src/agentLoop.ts +184 -11
  7. package/src/cliMode.js +9 -0
  8. package/src/commands.js +31 -0
  9. package/src/decisionPolicy.js +18 -1
  10. package/src/decisionPolicy.ts +18 -1
  11. package/src/implementationPlan.js +26 -0
  12. package/src/implementationPlan.ts +25 -0
  13. package/src/observer/coldObserver.js +6 -1
  14. package/src/observer/coldObserver.ts +6 -1
  15. package/src/observer.js +24 -2
  16. package/src/observer.ts +24 -2
  17. package/src/providers/acp.js +2 -8
  18. package/src/providers/acp.ts +2 -8
  19. package/src/providers/antigravity.js +7 -10
  20. package/src/providers/antigravity.ts +7 -10
  21. package/src/smartToolsUse.js +1 -1
  22. package/src/smartToolsUse.ts +1 -1
  23. package/src/toolPacks.js +1 -1
  24. package/src/toolPacks.ts +1 -1
  25. package/src/tools/toolSelfRepair.js +51 -8
  26. package/src/tools/toolSelfRepair.ts +42 -9
  27. package/src/tui/CausyneRotor.js +234 -0
  28. package/src/tui/CausyneRotor.ts +280 -0
  29. package/src/tui/activityLayout.js +1 -1
  30. package/src/tui/activityLayout.ts +1 -1
  31. package/src/tui/chatRenderer.js +56 -7
  32. package/src/tui/chatboxClipboard.js +96 -10
  33. package/src/tui/chatboxClipboard.ts +121 -11
  34. package/src/tui/clipboardImage.js +308 -0
  35. package/src/tui/clipboardImage.ts +320 -0
  36. package/src/tui/codeStreamRenderer.js +89 -1
  37. package/src/tui/codeStreamRenderer.ts +109 -1
  38. package/src/tui/dialogs.js +5 -2
  39. package/src/tui/engineSpinner.js +20 -0
  40. package/src/tui/engineSpinner.ts +46 -0
  41. package/src/tui/lineEditor.js +44 -12
  42. package/src/tui/messageInteraction.js +16 -5
  43. package/src/tui/messageInteraction.ts +14 -5
  44. package/src/tui/observerPicker.js +4 -8
  45. package/src/tui/observerPicker.ts +4 -8
  46. package/src/tui/prompt.js +70 -40
  47. package/src/tui/runningLight.js +213 -0
  48. package/src/tui/runningLight.ts +271 -0
  49. package/src/tui/sessionSidebar.js +7 -1
  50. package/src/tui/sessionSidebar.ts +7 -1
  51. package/src/tui/stage.js +4 -4
  52. package/src/tui/stageSurface.js +21 -14
  53. package/src/tui/statusLine.js +27 -4
  54. package/src/tui/statusLine.ts +27 -4
  55. package/src/tui/theme.js +5 -2
  56. package/src/tui/thinkingBox.js +41 -10
  57. package/src/tui/thinkingBox.ts +43 -10
  58. package/src/tui/turnRail.js +155 -24
  59. package/src/tui/turnRail.ts +170 -22
@@ -9,7 +9,7 @@ import { BUILTIN_PEER_PRESETS } from '../acp/agentCatalog.js';
9
9
  import { createHash } from 'node:crypto';
10
10
  import path from 'node:path';
11
11
  import { PEER_COLLABORATION_POLICY } from './collaborationPolicy.js';
12
- import { extractToolCallJsonObjects, stripToolCallMarkup } from '../implementationPlan.js';
12
+ import { extractToolCallJsonObjects, stripToolCallMarkup, resolveToolCallEnvelopeArguments } from '../implementationPlan.js';
13
13
  function fingerprint(value) {
14
14
  return createHash('sha256').update(JSON.stringify(value)).digest('hex');
15
15
  }
@@ -250,13 +250,7 @@ export class AcpProvider extends LLMProvider {
250
250
  const name = String(parsed.name || parsed.tool || fnObj?.name || '').trim();
251
251
  if (!name)
252
252
  continue;
253
- const rawArgs = parsed.arguments !== undefined
254
- ? parsed.arguments
255
- : parsed.parameters !== undefined
256
- ? parsed.parameters
257
- : parsed.input !== undefined
258
- ? parsed.input
259
- : (fnObj?.arguments ?? {});
253
+ const rawArgs = resolveToolCallEnvelopeArguments(parsed);
260
254
  calls.push({
261
255
  id: `acp_call_${Date.now()}_${index++}`,
262
256
  type: 'function',
@@ -10,7 +10,7 @@ import type { RequestPermissionRequest, SessionUpdate, ToolKind } from '../acp/p
10
10
  import { createHash } from 'node:crypto';
11
11
  import path from 'node:path';
12
12
  import { PEER_COLLABORATION_POLICY } from './collaborationPolicy.js';
13
- import { extractToolCallJsonObjects, stripToolCallMarkup } from '../implementationPlan.js';
13
+ import { extractToolCallJsonObjects, stripToolCallMarkup, resolveToolCallEnvelopeArguments } from '../implementationPlan.js';
14
14
 
15
15
  interface AcpTransportSnapshot {
16
16
  conversationId: string;
@@ -271,13 +271,7 @@ export class AcpProvider extends LLMProvider {
271
271
  : null;
272
272
  const name = String(parsed.name || parsed.tool || fnObj?.name || '').trim();
273
273
  if (!name) continue;
274
- const rawArgs = parsed.arguments !== undefined
275
- ? parsed.arguments
276
- : parsed.parameters !== undefined
277
- ? parsed.parameters
278
- : parsed.input !== undefined
279
- ? parsed.input
280
- : (fnObj?.arguments ?? {});
274
+ const rawArgs = resolveToolCallEnvelopeArguments(parsed);
281
275
  calls.push({
282
276
  id: `acp_call_${Date.now()}_${index++}`,
283
277
  type: 'function',
@@ -17,7 +17,7 @@ import fs from 'node:fs';
17
17
  import path from 'node:path';
18
18
  import { isLaunchOnlyPrompt } from '../launchIntent.js';
19
19
  import { LLMProvider } from './base.js';
20
- import { extractToolCallJsonObjects, stripToolCallMarkup, stripThinkBlocks } from '../implementationPlan.js';
20
+ import { extractToolCallJsonObjects, stripToolCallMarkup, stripThinkBlocks, resolveToolCallEnvelopeArguments } from '../implementationPlan.js';
21
21
  /**
22
22
  * Baseline fallback models for instant offline availability.
23
23
  * Live models are autodetected dynamically from `agy models`
@@ -848,13 +848,7 @@ export class AntigravityProvider extends LLMProvider {
848
848
  const name = String(parsed.name || parsed.tool || fnObj?.name || '').trim();
849
849
  if (!name)
850
850
  continue;
851
- const rawArgs = parsed.arguments !== undefined
852
- ? parsed.arguments
853
- : parsed.parameters !== undefined
854
- ? parsed.parameters
855
- : parsed.input !== undefined
856
- ? parsed.input
857
- : (fnObj?.arguments ?? {});
851
+ const rawArgs = resolveToolCallEnvelopeArguments(parsed);
858
852
  calls.push({
859
853
  id: `agy_call_${Date.now()}_${index++}`,
860
854
  type: 'function',
@@ -944,7 +938,8 @@ export class AntigravityProvider extends LLMProvider {
944
938
  'Causyne provides native host tools for browser verification: `browser_act` (preview and snapshot) and `screenshot`/`vision_inspect_ui`. ' +
945
939
  'DO NOT write custom Node.js/Python headless Chrome or CDP WebSocket scripts to inspect console logs or take screenshots. ' +
946
940
  'Causyne automatically captures browser console errors and renders WebGL/Canvas with hardware acceleration. ' +
947
- 'Use <tool_call>{"name": "browser_act", "arguments": {"action": "preview", "filePath": "index.html"}}</tool_call> to verify rendered output directly.\n\n' + promptText;
941
+ 'Use <tool_call>{"name": "browser_act", "arguments": {"actions": [{"type": "preview", "filePath": "index.html"}, {"type": "snapshot"}]}}</tool_call> to verify rendered output directly. ' +
942
+ 'If you start a persistent local HTTP server, use `sysRunBg` or redirect stdio (`nohup ... </dev/null >/dev/null 2>&1 &`) so the server does not break with EIO when the turn pseudo-terminal closes.\n\n' + promptText;
948
943
  }
949
944
  const modelSlug = resolveAgyModelId(this.model);
950
945
  const effort = resolveAgyEffort(this.model);
@@ -1306,7 +1301,9 @@ export class AntigravityProvider extends LLMProvider {
1306
1301
  ...(detail ? { detail } : {})
1307
1302
  };
1308
1303
  if (status !== 'running') {
1309
- const existing = nativeActions.find(a => a.name === action.name && a.detail === action.detail);
1304
+ const existing = nativeActions.find(a => action.id
1305
+ ? a.id === action.id
1306
+ : a.name === action.name && a.detail === action.detail);
1310
1307
  if (existing)
1311
1308
  existing.status = status;
1312
1309
  else
@@ -16,7 +16,7 @@ import fs from 'node:fs';
16
16
  import path from 'node:path';
17
17
  import { isLaunchOnlyPrompt } from '../launchIntent.js';
18
18
  import { LLMProvider, type ProviderConfig, type ChatOptions, type ChatResponse, type ChatResponseAction, type ChatResponseToolCall, type ChatResponseUsage } from './base.js';
19
- import { extractToolCallJsonObjects, stripToolCallMarkup, stripThinkBlocks } from '../implementationPlan.js';
19
+ import { extractToolCallJsonObjects, stripToolCallMarkup, stripThinkBlocks, resolveToolCallEnvelopeArguments } from '../implementationPlan.js';
20
20
 
21
21
  /**
22
22
  * Baseline fallback models for instant offline availability.
@@ -875,13 +875,7 @@ export class AntigravityProvider extends LLMProvider {
875
875
  : null;
876
876
  const name = String(parsed.name || parsed.tool || fnObj?.name || '').trim();
877
877
  if (!name) continue;
878
- const rawArgs = parsed.arguments !== undefined
879
- ? parsed.arguments
880
- : parsed.parameters !== undefined
881
- ? parsed.parameters
882
- : parsed.input !== undefined
883
- ? parsed.input
884
- : (fnObj?.arguments ?? {});
878
+ const rawArgs = resolveToolCallEnvelopeArguments(parsed);
885
879
  calls.push({
886
880
  id: `agy_call_${Date.now()}_${index++}`,
887
881
  type: 'function',
@@ -975,7 +969,8 @@ export class AntigravityProvider extends LLMProvider {
975
969
  'Causyne provides native host tools for browser verification: `browser_act` (preview and snapshot) and `screenshot`/`vision_inspect_ui`. ' +
976
970
  'DO NOT write custom Node.js/Python headless Chrome or CDP WebSocket scripts to inspect console logs or take screenshots. ' +
977
971
  'Causyne automatically captures browser console errors and renders WebGL/Canvas with hardware acceleration. ' +
978
- 'Use <tool_call>{"name": "browser_act", "arguments": {"action": "preview", "filePath": "index.html"}}</tool_call> to verify rendered output directly.\n\n' + promptText;
972
+ 'Use <tool_call>{"name": "browser_act", "arguments": {"actions": [{"type": "preview", "filePath": "index.html"}, {"type": "snapshot"}]}}</tool_call> to verify rendered output directly. ' +
973
+ 'If you start a persistent local HTTP server, use `sysRunBg` or redirect stdio (`nohup ... </dev/null >/dev/null 2>&1 &`) so the server does not break with EIO when the turn pseudo-terminal closes.\n\n' + promptText;
979
974
  }
980
975
 
981
976
  const modelSlug = resolveAgyModelId(this.model);
@@ -1363,7 +1358,9 @@ export class AntigravityProvider extends LLMProvider {
1363
1358
  ...(detail ? { detail } : {})
1364
1359
  };
1365
1360
  if (status !== 'running') {
1366
- const existing = nativeActions.find(a => a.name === action.name && a.detail === action.detail);
1361
+ const existing = nativeActions.find(a => action.id
1362
+ ? a.id === action.id
1363
+ : a.name === action.name && a.detail === action.detail);
1367
1364
  if (existing) existing.status = status;
1368
1365
  else nativeActions.push(action);
1369
1366
  }
@@ -131,7 +131,7 @@ const SIMPLE_FILE_OP_PATTERN = /\b(list (the )?files|show files|count files|rena
131
131
  // Media generation intent (explicit creation of 3D, video, audio, or synthesized speech)
132
132
  const EXPLICIT_MEDIA_GENERATION_PATTERN = /\b(blender|3d model|render 3d|render frame|render animation|da vinci|resolve|photoshop|premiere|after\s*effects|illustrator|indesign|media\s*encoder|uxp|audio synth|synthesizer|text to speech|tts|voiceover|dubbing)\b|\.(blend\d*|psd|prproj|aep|ai|indd|ccx)\b/i;
133
133
  // Explicit web engineering intent
134
- const EXPLICIT_WEB_ENGINEERING_PATTERN = /\b(build|create|make|design|develop|implement|redesign|buat\w*)\b[\s\S]*\b(web|website|webpage|webapp|landing page|dashboard|ui|frontend|threejs|three\.js|thre\.?js|3js|webgl|canvas)\b/i;
134
+ const EXPLICIT_WEB_ENGINEERING_PATTERN = /\b(build|create|make|design|develop|implement|redesign|buat\w*)\b[\s\S]*(?:\b(web|website|webpage|webapp|landing page|dashboard|ui|frontend|webgl|canvas|cad view|cad viewer|cad style view|3d view|3d viewer|3d configurator|3d visualizer)\b|(?:threejs|three\.js|thre\.?js|3js|babylon\.?js|pixi\.js|d3\.js|p5\.js|chart\.js)\b)/i;
135
135
  // Explicit game development intent
136
136
  const EXPLICIT_GAME_DEV_PATTERN = /(?:\b(?:build|create|make|design|develop|scaffold|render|animate|code|program|buat\w*|bikin\w*)[\s\S]*(?:game|simulation|simulator|simulasi|interactive|3d|three\.?js|threejs|webgl|canvas3d|babylonjs|godot|unity|unreal|platformer|rpg|arcade)\b|\b(?:game|gamedev|godot|unity|unreal|platformer|rpg|arcade|simulator|simulation|simulasi|interactive)\b|\b3d\s*(?:game|app|simulator|simulation|scene|city|world|view|body|human|anatomy|model|mesh|character|rendering|visualization|experience|space|environment)\b|\bin 3d\b|[-_]3d\b|\b3d[-_]|\b(?:threejs|three\.js|webgl|canvas3d|babylonjs)\b)/i;
137
137
  // Explicit reverse engineering and binary analysis intent
@@ -175,7 +175,7 @@ const EXPLICIT_MEDIA_GENERATION_PATTERN =
175
175
 
176
176
  // Explicit web engineering intent
177
177
  const EXPLICIT_WEB_ENGINEERING_PATTERN =
178
- /\b(build|create|make|design|develop|implement|redesign|buat\w*)\b[\s\S]*\b(web|website|webpage|webapp|landing page|dashboard|ui|frontend|threejs|three\.js|thre\.?js|3js|webgl|canvas)\b/i;
178
+ /\b(build|create|make|design|develop|implement|redesign|buat\w*)\b[\s\S]*(?:\b(web|website|webpage|webapp|landing page|dashboard|ui|frontend|webgl|canvas|cad view|cad viewer|cad style view|3d view|3d viewer|3d configurator|3d visualizer)\b|(?:threejs|three\.js|thre\.?js|3js|babylon\.?js|pixi\.js|d3\.js|p5\.js|chart\.js)\b)/i;
179
179
 
180
180
  // Explicit game development intent
181
181
  const EXPLICIT_GAME_DEV_PATTERN =
package/src/toolPacks.js CHANGED
@@ -331,7 +331,7 @@ When the user asks you to build, create, test, expand, or develop a game, follow
331
331
  // raw prompt only.
332
332
  // ---------------------------------------------------------------------------
333
333
  const GAME_INTENT = /\b(game|games|gamedev|godot|unity|unreal|ue5|rpg|platformer|roguelike|arcade|sprite|spritesheet|tilemap|voxel|minecraft|aetheria|voxellia|nes|snes|gameplay|player character|level design|boss fight|simulator|simulation|simulasi)\b|\.(tscn|gd|uproject|umap)\b|[-_]3d\b|\b3d[-_]/i;
334
- const WEB_INTENT = /\b(web|webpage|website|frontend|front-end|landing page|homepage|dashboard|portfolio|html|css|scss|tailwind|bootstrap|react|vue|svelte|angular|next\.?js|nuxt|astro|ui|ux|user interface|web app|webapp|spa|dom|responsive|ui forge|component forge|component generation|ui component|three?\.?js|three?js|webgl|canvas|babylon)\b/i;
334
+ const WEB_INTENT = /\b(web|webpage|website|frontend|front-end|landing page|homepage|dashboard|portfolio|html|html5|css|scss|tailwind|bootstrap|react|vue|svelte|angular|next\.?js|nuxt|astro|ui|ux|user interface|web app|webapp|spa|dom|responsive|ui forge|component forge|component generation|ui component|webgl|canvas|babylon|cad view|cad viewer|cad style view|3d view|3d viewer|3d configurator|3d visualizer)\b|(?:three\.js|threejs|thre\.js|3js|webgl|babylon\.js|babylonjs|pixi\.js|d3\.js|p5\.js|chart\.js)\b/i;
335
335
  const MEDIA_INTENT = /\b(image|images|picture|photo|photoshop|premiere|after\s*effects|illustrator|indesign|media\s*encoder|uxp|render|3d model|blender|animation|animate|video|movie|film|audio|sound|sfx|music|song|voice|tts|text.to.speech|narration|podcast|thumbnail|poster|illustration|logo)\b|\.(psd|prproj|aep|ai|indd|ccx)\b/i;
336
336
  const SYSTEM_INTENT = /\b(process|processes|pid|kill|port|zip|unzip|tar|archive|compress|extract|clipboard|copy to clipboard|print|printer|open in browser|launch app|computer use|vision grounding|desktop vision|gui agent|coordinate click|desktop control)\b/i;
337
337
  const ADVANCED_INTENT = /\b(pdf|document|proposal|screenplay|shotlist|shot list|voiceover|dubbing|forge a tool|custom tool|new tool|plugin|plugins|custom plugin|plugins? factory|python bridge|mcp|mcp server|subagent|sub-agent|parallel agent|swarm|ast|symbols|refactor across)\b/i;
package/src/toolPacks.ts CHANGED
@@ -372,7 +372,7 @@ When the user asks you to build, create, test, expand, or develop a game, follow
372
372
 
373
373
  const GAME_INTENT = /\b(game|games|gamedev|godot|unity|unreal|ue5|rpg|platformer|roguelike|arcade|sprite|spritesheet|tilemap|voxel|minecraft|aetheria|voxellia|nes|snes|gameplay|player character|level design|boss fight|simulator|simulation|simulasi)\b|\.(tscn|gd|uproject|umap)\b|[-_]3d\b|\b3d[-_]/i;
374
374
 
375
- const WEB_INTENT = /\b(web|webpage|website|frontend|front-end|landing page|homepage|dashboard|portfolio|html|css|scss|tailwind|bootstrap|react|vue|svelte|angular|next\.?js|nuxt|astro|ui|ux|user interface|web app|webapp|spa|dom|responsive|ui forge|component forge|component generation|ui component|three?\.?js|three?js|webgl|canvas|babylon)\b/i;
375
+ const WEB_INTENT = /\b(web|webpage|website|frontend|front-end|landing page|homepage|dashboard|portfolio|html|html5|css|scss|tailwind|bootstrap|react|vue|svelte|angular|next\.?js|nuxt|astro|ui|ux|user interface|web app|webapp|spa|dom|responsive|ui forge|component forge|component generation|ui component|webgl|canvas|babylon|cad view|cad viewer|cad style view|3d view|3d viewer|3d configurator|3d visualizer)\b|(?:three\.js|threejs|thre\.js|3js|webgl|babylon\.js|babylonjs|pixi\.js|d3\.js|p5\.js|chart\.js)\b/i;
376
376
 
377
377
  const MEDIA_INTENT = /\b(image|images|picture|photo|photoshop|premiere|after\s*effects|illustrator|indesign|media\s*encoder|uxp|render|3d model|blender|animation|animate|video|movie|film|audio|sound|sfx|music|song|voice|tts|text.to.speech|narration|podcast|thumbnail|poster|illustration|logo)\b|\.(psd|prproj|aep|ai|indd|ccx)\b/i;
378
378
 
@@ -634,19 +634,62 @@ export function resolveParameterAliases(toolName, args, schema) {
634
634
  }
635
635
  }
636
636
  else if (canonicalName === 'update_plan') {
637
- if (!modified.plan && (modified.steps || modified.items || modified.tasks)) {
638
- modified.plan = modified.steps || modified.items || modified.tasks;
639
- delete modified.steps;
640
- delete modified.items;
641
- delete modified.tasks;
642
- repairs.push("Mapped 'steps' to 'plan' parameter for 'update_plan'");
637
+ // Peer checklist tools (TodoWrite / todowrite) are aliased to update_plan by
638
+ // name, so their argument shapes must be mapped here as well.
639
+ const planAliases = ['steps', 'items', 'tasks', 'todos', 'entries', 'checklist'];
640
+ if (modified.plan === undefined || modified.plan === null || modified.plan === '') {
641
+ const source = planAliases.find((key) => modified[key] !== undefined && modified[key] !== null);
642
+ if (source) {
643
+ modified.plan = modified[source];
644
+ repairs.push(`Mapped '${source}' to 'plan' parameter for 'update_plan'`);
645
+ }
646
+ }
647
+ for (const key of planAliases)
648
+ delete modified[key];
649
+ if (typeof modified.plan === 'string') {
650
+ const text = modified.plan.trim();
651
+ let parsed;
652
+ if (text.startsWith('[') || text.startsWith('{')) {
653
+ try {
654
+ parsed = JSON.parse(text);
655
+ }
656
+ catch {
657
+ parsed = undefined;
658
+ }
659
+ }
660
+ if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {
661
+ const inner = parsed;
662
+ parsed = inner.plan ?? inner.todos ?? inner.steps ?? inner.items ?? parsed;
663
+ }
664
+ if (Array.isArray(parsed)) {
665
+ modified.plan = parsed;
666
+ repairs.push("Parsed JSON-encoded 'plan' for 'update_plan'");
667
+ }
668
+ else if (text) {
669
+ const lines = text.split(/\r?\n/)
670
+ .map((line) => line.replace(/^\s*(?:[-*+]|\d+[.)])?\s*(?:\[[ xX]\])?\s*/, '').trim())
671
+ .filter(Boolean);
672
+ if (lines.length > 0) {
673
+ modified.plan = lines;
674
+ repairs.push("Split plain-text 'plan' into steps for 'update_plan'");
675
+ }
676
+ }
643
677
  }
644
678
  if (Array.isArray(modified.plan)) {
645
679
  let activeCount = 0;
646
- modified.plan = modified.plan.map((raw, idx) => {
647
- if (!raw || typeof raw !== 'object')
680
+ modified.plan = modified.plan.map((entry, idx) => {
681
+ const raw = typeof entry === 'string' && entry.trim()
682
+ ? { step: entry.trim(), status: 'pending' }
683
+ : entry;
684
+ if (!raw || typeof raw !== 'object' || Array.isArray(raw))
648
685
  return raw;
649
686
  const item = { ...raw };
687
+ if (item.activeForm !== undefined)
688
+ delete item.activeForm;
689
+ if (item.priority !== undefined)
690
+ delete item.priority;
691
+ if (item.id !== undefined && typeof item.id !== 'string')
692
+ item.id = String(item.id);
650
693
  if (!item.id)
651
694
  item.id = `step-${idx + 1}`;
652
695
  if (!item.step && (item.content || item.title || item.name || item.description)) {
@@ -680,18 +680,51 @@ export function resolveParameterAliases(
680
680
  });
681
681
  }
682
682
  } else if (canonicalName === 'update_plan') {
683
- if (!modified.plan && (modified.steps || modified.items || modified.tasks)) {
684
- modified.plan = modified.steps || modified.items || modified.tasks;
685
- delete modified.steps;
686
- delete modified.items;
687
- delete modified.tasks;
688
- repairs.push("Mapped 'steps' to 'plan' parameter for 'update_plan'");
683
+ // Peer checklist tools (TodoWrite / todowrite) are aliased to update_plan by
684
+ // name, so their argument shapes must be mapped here as well.
685
+ const planAliases = ['steps', 'items', 'tasks', 'todos', 'entries', 'checklist'] as const;
686
+ if (modified.plan === undefined || modified.plan === null || modified.plan === '') {
687
+ const source = planAliases.find((key) => modified[key] !== undefined && modified[key] !== null);
688
+ if (source) {
689
+ modified.plan = modified[source];
690
+ repairs.push(`Mapped '${source}' to 'plan' parameter for 'update_plan'`);
691
+ }
692
+ }
693
+ for (const key of planAliases) delete modified[key];
694
+ if (typeof modified.plan === 'string') {
695
+ const text = modified.plan.trim();
696
+ let parsed: unknown;
697
+ if (text.startsWith('[') || text.startsWith('{')) {
698
+ try { parsed = JSON.parse(text); } catch { parsed = undefined; }
699
+ }
700
+ if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {
701
+ const inner = parsed as Record<string, unknown>;
702
+ parsed = inner.plan ?? inner.todos ?? inner.steps ?? inner.items ?? parsed;
703
+ }
704
+ if (Array.isArray(parsed)) {
705
+ modified.plan = parsed;
706
+ repairs.push("Parsed JSON-encoded 'plan' for 'update_plan'");
707
+ } else if (text) {
708
+ const lines = text.split(/\r?\n/)
709
+ .map((line) => line.replace(/^\s*(?:[-*+]|\d+[.)])?\s*(?:\[[ xX]\])?\s*/, '').trim())
710
+ .filter(Boolean);
711
+ if (lines.length > 0) {
712
+ modified.plan = lines;
713
+ repairs.push("Split plain-text 'plan' into steps for 'update_plan'");
714
+ }
715
+ }
689
716
  }
690
717
  if (Array.isArray(modified.plan)) {
691
718
  let activeCount = 0;
692
- modified.plan = (modified.plan as Record<string, unknown>[]).map((raw, idx) => {
693
- if (!raw || typeof raw !== 'object') return raw;
694
- const item = { ...raw };
719
+ modified.plan = (modified.plan as unknown[]).map((entry, idx) => {
720
+ const raw: unknown = typeof entry === 'string' && entry.trim()
721
+ ? { step: entry.trim(), status: 'pending' }
722
+ : entry;
723
+ if (!raw || typeof raw !== 'object' || Array.isArray(raw)) return raw;
724
+ const item: Record<string, unknown> = { ...(raw as Record<string, unknown>) };
725
+ if (item.activeForm !== undefined) delete item.activeForm;
726
+ if (item.priority !== undefined) delete item.priority;
727
+ if (item.id !== undefined && typeof item.id !== 'string') item.id = String(item.id);
695
728
  if (!item.id) item.id = `step-${idx + 1}`;
696
729
  if (!item.step && (item.content || item.title || item.name || item.description)) {
697
730
  item.step = item.content || item.title || item.name || item.description;
@@ -0,0 +1,234 @@
1
+ /**
2
+ * CausyneRotor.ts
3
+ * Dependency-free, terminal-native animation for a Causyne CLI/TUI.
4
+ * Uses Unicode Braille pixels (2x4 subpixels per character) and ANSI colors.
5
+ * The logo is drawn geometrically, not played from an image/GIF.
6
+ *
7
+ * If an existing TUI (Ink, Blessed, etc.) owns the terminal screen, call
8
+ * renderCausyneRotor(...) in THAT renderer. Do not also start the standalone
9
+ * interval-based renderer.
10
+ */
11
+ import { stdout } from 'node:process';
12
+ const BRAILLE_DOTS = [
13
+ [0, 0, 0x01], [0, 1, 0x02], [0, 2, 0x04], [0, 3, 0x40],
14
+ [1, 0, 0x08], [1, 1, 0x10], [1, 2, 0x20], [1, 3, 0x80],
15
+ ];
16
+ const TAU = Math.PI * 2;
17
+ const STEP = TAU / 6;
18
+ export const COLORS = {
19
+ charcoal: '\x1b[38;2;115;124;137m',
20
+ lime: '\x1b[38;2;181;214;106m',
21
+ outline: '\x1b[38;2;224;230;229m',
22
+ text: '\x1b[38;2;185;192;196m',
23
+ reset: '\x1b[0m',
24
+ };
25
+ // One triangular blade, defined relative to the hub at (0, 0).
26
+ // The remaining five are exact 60-degree rotations of this triangle.
27
+ // Negative space between blades forms the central hexagonal aperture.
28
+ const BASE_BLADE = [
29
+ { x: -0.86, y: -0.64 },
30
+ { x: 0.06, y: -1.06 },
31
+ { x: -0.42, y: -0.105 },
32
+ ];
33
+ function rotate(p, angle) {
34
+ const c = Math.cos(angle);
35
+ const s = Math.sin(angle);
36
+ return { x: p.x * c - p.y * s, y: p.x * s + p.y * c };
37
+ }
38
+ function insideTriangle(p, a, b, c) {
39
+ const cross = (v, w, q) => (w.x - v.x) * (q.y - v.y) - (w.y - v.y) * (q.x - v.x);
40
+ const u = cross(a, b, p);
41
+ const v = cross(b, c, p);
42
+ const w = cross(c, a, p);
43
+ return (u >= 0 && v >= 0 && w >= 0) || (u <= 0 && v <= 0 && w <= 0);
44
+ }
45
+ function distanceToSegment(p, a, b) {
46
+ const dx = b.x - a.x;
47
+ const dy = b.y - a.y;
48
+ const lengthSq = dx * dx + dy * dy;
49
+ const t = lengthSq === 0 ? 0 : Math.max(0, Math.min(1, ((p.x - a.x) * dx + (p.y - a.y) * dy) / lengthSq));
50
+ return Math.hypot(p.x - (a.x + t * dx), p.y - (a.y + t * dy));
51
+ }
52
+ function smoothstep(t) {
53
+ const x = Math.max(0, Math.min(1, t));
54
+ return x * x * (3 - 2 * x);
55
+ }
56
+ export function getAngle(elapsedMs, motion = 'heavy') {
57
+ const t = Math.max(0, elapsedMs);
58
+ if (motion === 'smooth')
59
+ return (t / 4200) * TAU;
60
+ if (motion === 'pulse') {
61
+ const cycle = t / 1000;
62
+ return (Math.floor(cycle) + smoothstep(Math.min(1, (cycle % 1) / 0.75))) * STEP;
63
+ }
64
+ // Heavy engine: deliberate acceleration, high-momentum travel, short settle.
65
+ const cycle = t / 860;
66
+ const index = Math.floor(cycle);
67
+ const progress = (cycle % 1) / 0.88; // final 12% holds precisely on an index
68
+ return (index + smoothstep(progress)) * STEP;
69
+ }
70
+ function sample(p, blades) {
71
+ for (let i = 0; i < 6; i++) {
72
+ const blade = blades[i];
73
+ if (!blade)
74
+ continue;
75
+ const [a, b, c] = blade;
76
+ if (!a || !b || !c || !insideTriangle(p, a, b, c))
77
+ continue;
78
+ // 1.5~2 subpixels: subtle white perimeter like your outlined SVG.
79
+ const edge = Math.min(distanceToSegment(p, a, b), distanceToSegment(p, b, c), distanceToSegment(p, c, a));
80
+ if (edge < 0.018)
81
+ return 3;
82
+ return i === 1 ? 2 : 1;
83
+ }
84
+ return 0;
85
+ }
86
+ function paint(text, kind, color) {
87
+ if (!color)
88
+ return text;
89
+ const code = kind === 2 ? COLORS.lime : kind === 3 ? COLORS.outline : COLORS.charcoal;
90
+ return code + text + COLORS.reset;
91
+ }
92
+ /**
93
+ * Returns an ANSI-colored multi-line string. No side effects or timers.
94
+ * Intended for an existing TUI's render() method.
95
+ */
96
+ export function renderCausyneRotor(elapsedMs, options = {}) {
97
+ const columns = Math.max(12, Math.min(56, Math.floor(options.columns ?? 24)));
98
+ const rows = Math.max(6, Math.min(28, Math.floor(options.rows ?? 12)));
99
+ const color = options.color ?? true;
100
+ const angle = getAngle(elapsedMs, options.motion ?? 'heavy');
101
+ const blades = Array.from({ length: 6 }, (_, i) => {
102
+ const rotAngle = angle + i * STEP;
103
+ return BASE_BLADE.map((p) => rotate(p, rotAngle));
104
+ });
105
+ const widthDots = columns * 2;
106
+ const heightDots = rows * 4;
107
+ const scale = Math.min(widthDots, heightDots) / 2.42;
108
+ const lines = [];
109
+ for (let row = 0; row < rows; row++) {
110
+ let line = '';
111
+ for (let col = 0; col < columns; col++) {
112
+ let mask = 0;
113
+ let dark = 0;
114
+ let lime = 0;
115
+ let outline = 0;
116
+ for (const [dx, dy, bit] of BRAILLE_DOTS) {
117
+ const px = col * 2 + dx + 0.5;
118
+ const py = row * 4 + dy + 0.5;
119
+ const p = {
120
+ x: (px - widthDots / 2) / scale,
121
+ y: (py - heightDots / 2) / scale,
122
+ };
123
+ const hit = sample(p, blades);
124
+ if (!hit)
125
+ continue;
126
+ mask |= bit;
127
+ if (hit === 1)
128
+ dark++;
129
+ else if (hit === 2)
130
+ lime++;
131
+ else
132
+ outline++;
133
+ }
134
+ if (!mask) {
135
+ line += ' ';
136
+ }
137
+ else {
138
+ // A Braille cell has a single foreground color. Choose the dominant fill.
139
+ const kind = lime > 0 && lime >= dark ? 2 :
140
+ outline >= 3 && dark === 0 && lime === 0 ? 3 : 1;
141
+ line += paint(String.fromCodePoint(0x2800 + mask), kind, color);
142
+ }
143
+ }
144
+ lines.push(line);
145
+ }
146
+ if (options.label !== '') {
147
+ const label = options.label ?? 'working';
148
+ const status = color
149
+ ? `${COLORS.lime}●${COLORS.reset} ${COLORS.text}${label}${COLORS.reset}`
150
+ : `● ${label}`;
151
+ lines.push(status);
152
+ }
153
+ return lines.join('\n');
154
+ }
155
+ /**
156
+ * Standalone demo/CLI renderer. It owns its multi-line cursor region.
157
+ * If your app uses Ink/Blessed/another renderer, DO NOT call this function;
158
+ * use renderCausyneRotor() inside the existing renderer instead.
159
+ */
160
+ export function startCausyneRotor(options = {}) {
161
+ const color = options.color ?? (Boolean(stdout.isTTY) && !process.env.NO_COLOR && !process.env.CAUSYNE_NO_COLOR);
162
+ if (!stdout.isTTY) {
163
+ stdout.write((options.label ?? 'working') + '\n');
164
+ return { stop() { } };
165
+ }
166
+ const fps = Math.max(4, Math.min(30, options.fps ?? 16));
167
+ const started = Date.now();
168
+ let stopped = false;
169
+ let lastLines = 0;
170
+ function draw() {
171
+ const frame = renderCausyneRotor(Date.now() - started, { ...options, color });
172
+ const lines = frame.split('\n');
173
+ // Redraw only our reserved lines, never clear the whole terminal.
174
+ if (lastLines > 0)
175
+ stdout.write(`\x1b[${lastLines}A\r`);
176
+ stdout.write(lines.map((line) => `\x1b[2K${line}\n`).join(''));
177
+ lastLines = lines.length;
178
+ }
179
+ stdout.write('\x1b[?25l'); // temporarily hide cursor
180
+ draw();
181
+ const timer = setInterval(draw, Math.round(1000 / fps));
182
+ return {
183
+ stop() {
184
+ if (stopped)
185
+ return;
186
+ stopped = true;
187
+ clearInterval(timer);
188
+ stdout.write('\x1b[?25h'); // restore cursor
189
+ },
190
+ };
191
+ }
192
+ // ---------------------------------------------------------------------------------------------------------
193
+ // Single-Line Status Row / Inline Spinner Integration
194
+ // ---------------------------------------------------------------------------------------------------------
195
+ /**
196
+ * 2-character Braille rotor frames using the CausyneRotor palette (lime + charcoal).
197
+ * 6-phase rotation corresponding directly to the 60-degree indexed rotor blades.
198
+ */
199
+ export const ROTOR_SPINNER_FRAMES = [
200
+ `${COLORS.charcoal}⠇${COLORS.lime}⠙${COLORS.reset}`,
201
+ `${COLORS.charcoal}⠋${COLORS.lime}⠸${COLORS.reset}`,
202
+ `${COLORS.charcoal}⠙${COLORS.lime}⠴${COLORS.reset}`,
203
+ `${COLORS.lime}⠸${COLORS.charcoal}⠦${COLORS.reset}`,
204
+ `${COLORS.lime}⠴${COLORS.charcoal}⠇${COLORS.reset}`,
205
+ `${COLORS.lime}⠦${COLORS.charcoal}⠋${COLORS.reset}`,
206
+ ];
207
+ export const ROTOR_SPINNER_FRAMES_NO_COLOR = [
208
+ '⠇⠙', '⠋⠸', '⠙⠴', '⠸⠦', '⠴⠇', '⠦⠋',
209
+ ];
210
+ export const ROTOR_SPINNER_FRAMES_ASCII = [
211
+ '[-]', '[\\]', '[|]', '[/]',
212
+ ];
213
+ export function getRotorSpinnerFrames(color = true, unicode = true) {
214
+ if (!unicode)
215
+ return ROTOR_SPINNER_FRAMES_ASCII;
216
+ return color ? ROTOR_SPINNER_FRAMES : ROTOR_SPINNER_FRAMES_NO_COLOR;
217
+ }
218
+ export function getRotorSpinnerFrame(tick, color = true, unicode = true) {
219
+ const frames = getRotorSpinnerFrames(color, unicode);
220
+ const index = Math.abs(Math.floor(tick)) % frames.length;
221
+ return frames[index] ?? frames[0] ?? '⠇⠙';
222
+ }
223
+ const DOT_FRAMES = [' ', '. ', '.. ', '...'];
224
+ export function getAnimatedDots(tick) {
225
+ const stage = Math.floor(Math.abs(Math.floor(tick)) / 2) % DOT_FRAMES.length;
226
+ return DOT_FRAMES[stage] ?? ' ';
227
+ }
228
+ export function formatAnimatedStatus(message, tick) {
229
+ let base = (message || 'working').trimEnd();
230
+ while (base.endsWith('.') || base.endsWith('…')) {
231
+ base = base.slice(0, -1).trimEnd();
232
+ }
233
+ return `${base}${getAnimatedDots(tick)}`;
234
+ }