@causyne/agent 1.20.45 → 1.20.53

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.45",
3
+ "version": "1.20.53",
4
4
  "description": "Agentic AI for software, tools, and computer workflows",
5
5
  "main": "bin/causyne.js",
6
6
  "type": "module",
package/src/agentLoop.js CHANGED
@@ -1290,6 +1290,28 @@ export class AgentLoop {
1290
1290
  completed: this._implementationPlan.filter((item) => item.status === 'completed').length
1291
1291
  });
1292
1292
  }
1293
+ inferCurrentActivity() {
1294
+ if (this._implementationPlan && this._implementationPlan.length > 0) {
1295
+ const activeStep = this._implementationPlan.find((s) => s && (s.status === 'in_progress' || s.status === 'running'));
1296
+ const text = activeStep ? (activeStep.step || activeStep.text || activeStep.title || '') : '';
1297
+ if (text && typeof text === 'string') {
1298
+ const lower = text.toLowerCase();
1299
+ if (lower.includes('verify') || lower.includes('test'))
1300
+ return 'Verifying';
1301
+ if (lower.includes('implement') || lower.includes('build') || lower.includes('code'))
1302
+ return 'Implementing';
1303
+ if (lower.includes('scaffold') || lower.includes('setup'))
1304
+ return 'Scaffolding';
1305
+ if (lower.includes('plan'))
1306
+ return 'Planning';
1307
+ return text.slice(0, 30);
1308
+ }
1309
+ }
1310
+ if (this.stepsCompleted > 0) {
1311
+ return 'Analyzing & executing';
1312
+ }
1313
+ return 'Analyzing & planning';
1314
+ }
1293
1315
  seedTaskPhasePlanIfEmpty() {
1294
1316
  if (this._implementationPlan.length > 0) {
1295
1317
  this.emitEvent({
@@ -1840,7 +1862,8 @@ export class AgentLoop {
1840
1862
  auditLog.log({ event: 'task_killed', taskId: this.taskId });
1841
1863
  break;
1842
1864
  }
1843
- this.emitEvent({ type: 'status', message: 'Thinking...' });
1865
+ const currentActivity = this.inferCurrentActivity();
1866
+ this.emitEvent({ type: 'status', message: `${currentActivity}…` });
1844
1867
  try {
1845
1868
  this.smartToolsGovernor.beginModelStep();
1846
1869
  // Insert at the model boundary, never between one assistant tool-call
@@ -2264,8 +2287,9 @@ You are operating in a text-and-code modality without direct image pixel renderi
2264
2287
  elapsedMs
2265
2288
  });
2266
2289
  };
2267
- this.emitEvent({ type: 'status', message: 'Thinking…' });
2268
- this.emitEvent({ type: 'agent_activity', activity: 'Thinking…' });
2290
+ const currentActivity = this.inferCurrentActivity();
2291
+ this.emitEvent({ type: 'status', message: `${currentActivity}…` });
2292
+ this.emitEvent({ type: 'agent_activity', activity: `${currentActivity}…` });
2269
2293
  const planStepStart = performance.now();
2270
2294
  const nativeControl = new AbortController();
2271
2295
  const invocation = ++modelCallIndex;
@@ -2488,7 +2512,14 @@ You are operating in a text-and-code modality without direct image pixel renderi
2488
2512
  }
2489
2513
  else if (action.status === 'completed') {
2490
2514
  this.emitEvent({ type: 'status', message: '' });
2491
- this.emitEvent({ type: 'notice', tone: 'muted', nativeStep: true, message: `${this.config.provider || 'Provider'} ${action.name}${detail}` });
2515
+ this.emitEvent({
2516
+ type: 'notice',
2517
+ tone: 'muted',
2518
+ nativeStep: true,
2519
+ actionName: action.name,
2520
+ detail: action.detail,
2521
+ message: `${this.config.provider || 'Provider'} ${action.name}${detail}`
2522
+ });
2492
2523
  }
2493
2524
  else if (action.status === 'failed') {
2494
2525
  this.emitEvent({ type: 'status', message: '' });
@@ -2693,12 +2724,15 @@ You are operating in a text-and-code modality without direct image pixel renderi
2693
2724
  if (response.thinkingBlocks) {
2694
2725
  assistantMsg.thinking_blocks = response.thinkingBlocks;
2695
2726
  }
2696
- this.messages.push(assistantMsg);
2697
- // Prose accompanying pending actions is not an execution result.
2698
- // Tool events provide progress; terminal claims pass completion gates below.
2699
2727
  const externalActions = Array.isArray(response.externalActions)
2700
2728
  ? response.externalActions
2701
2729
  : [];
2730
+ if (externalActions.length > 0) {
2731
+ assistantMsg.external_actions = externalActions;
2732
+ }
2733
+ this.messages.push(assistantMsg);
2734
+ // Prose accompanying pending actions is not an execution result.
2735
+ // Tool events provide progress; terminal claims pass completion gates below.
2702
2736
  const completedExternalActions = externalActions.filter((a) => a && a.status === 'completed');
2703
2737
  const failedExternalActions = externalActions.filter((a) => a && a.status === 'failed');
2704
2738
  const hasExternalActions = completedExternalActions.length > 0;
@@ -2878,6 +2912,28 @@ You are operating in a text-and-code modality without direct image pixel renderi
2878
2912
  this.memoryManager.saveHistory(this.messages);
2879
2913
  continue;
2880
2914
  }
2915
+ if (hasExternalActions && (isIncompleteTurn || isMidTaskProgress) && incompleteTurnContinuations === 3) {
2916
+ incompleteTurnContinuations++;
2917
+ if (response.content) {
2918
+ this.emitEvent({ type: 'agent_message', content: response.content });
2919
+ }
2920
+ this.emitEvent({ type: 'status', message: 'Requesting final deliverable and response...' });
2921
+ this.emitEvent({ type: 'agent_activity', activity: 'Synthesizing final deliverable…' });
2922
+ this.messages.push({
2923
+ role: 'system',
2924
+ content: `[TASK COMPLETION MANDATE: You have completed your tool execution steps (${this.stepsCompleted} steps performed). Provide your complete final response, deliverables, and conclusions directly to the user now. Do not run any more background commands.]`
2925
+ });
2926
+ this.memoryManager.saveHistory(this.messages);
2927
+ continue;
2928
+ }
2929
+ if (hasExternalActions && (isIncompleteTurn || isMidTaskProgress || (typeof contentText === 'string' && (contentText.startsWith('Antigravity executed:') || /^Turn completed by .+ over ACP\.$/i.test(contentText.trim()))))) {
2930
+ this.emitEvent({
2931
+ type: 'error',
2932
+ message: 'The task stopped before completion after repeated incomplete turns without a final response. Work remains unfinished.'
2933
+ });
2934
+ this.memoryManager.saveHistory(this.messages);
2935
+ break;
2936
+ }
2881
2937
  if (hasExternalActions && !isIncompleteTurn && !isMidTaskProgress) {
2882
2938
  incompleteTurnContinuations = 0;
2883
2939
  }
package/src/agentLoop.ts CHANGED
@@ -1374,6 +1374,25 @@ export class AgentLoop {
1374
1374
  });
1375
1375
  }
1376
1376
 
1377
+ inferCurrentActivity(): string {
1378
+ if (this._implementationPlan && this._implementationPlan.length > 0) {
1379
+ const activeStep = this._implementationPlan.find((s: any) => s && (s.status === 'in_progress' || s.status === 'running'));
1380
+ const text = activeStep ? (activeStep.step || activeStep.text || activeStep.title || '') : '';
1381
+ if (text && typeof text === 'string') {
1382
+ const lower = text.toLowerCase();
1383
+ if (lower.includes('verify') || lower.includes('test')) return 'Verifying';
1384
+ if (lower.includes('implement') || lower.includes('build') || lower.includes('code')) return 'Implementing';
1385
+ if (lower.includes('scaffold') || lower.includes('setup')) return 'Scaffolding';
1386
+ if (lower.includes('plan')) return 'Planning';
1387
+ return text.slice(0, 30);
1388
+ }
1389
+ }
1390
+ if (this.stepsCompleted > 0) {
1391
+ return 'Analyzing & executing';
1392
+ }
1393
+ return 'Analyzing & planning';
1394
+ }
1395
+
1377
1396
  seedTaskPhasePlanIfEmpty(): void {
1378
1397
  if (this._implementationPlan.length > 0) {
1379
1398
  this.emitEvent({
@@ -1929,7 +1948,8 @@ export class AgentLoop {
1929
1948
  auditLog.log({ event: 'task_killed', taskId: this.taskId });
1930
1949
  break;
1931
1950
  }
1932
- this.emitEvent({ type: 'status', message: 'Thinking...' });
1951
+ const currentActivity = this.inferCurrentActivity();
1952
+ this.emitEvent({ type: 'status', message: `${currentActivity}…` });
1933
1953
 
1934
1954
  try {
1935
1955
  this.smartToolsGovernor.beginModelStep();
@@ -2379,8 +2399,9 @@ You are operating in a text-and-code modality without direct image pixel renderi
2379
2399
  });
2380
2400
  };
2381
2401
 
2382
- this.emitEvent({ type: 'status', message: 'Thinking…' });
2383
- this.emitEvent({ type: 'agent_activity', activity: 'Thinking…' });
2402
+ const currentActivity = this.inferCurrentActivity();
2403
+ this.emitEvent({ type: 'status', message: `${currentActivity}…` });
2404
+ this.emitEvent({ type: 'agent_activity', activity: `${currentActivity}…` });
2384
2405
 
2385
2406
  const planStepStart = performance.now();
2386
2407
  const nativeControl = new AbortController();
@@ -2592,7 +2613,14 @@ You are operating in a text-and-code modality without direct image pixel renderi
2592
2613
  this.emitEvent({ type: 'status', message: `Acting: ${action.name}${detail}` });
2593
2614
  } else if (action.status === 'completed') {
2594
2615
  this.emitEvent({ type: 'status', message: '' });
2595
- this.emitEvent({ type: 'notice', tone: 'muted', nativeStep: true, message: `${this.config.provider || 'Provider'} ${action.name}${detail}` });
2616
+ this.emitEvent({
2617
+ type: 'notice',
2618
+ tone: 'muted',
2619
+ nativeStep: true,
2620
+ actionName: action.name,
2621
+ detail: action.detail,
2622
+ message: `${this.config.provider || 'Provider'} ${action.name}${detail}`
2623
+ });
2596
2624
  } else if (action.status === 'failed') {
2597
2625
  this.emitEvent({ type: 'status', message: '' });
2598
2626
  this.emitEvent({ type: 'warning', message: `${this.config.provider || 'Provider'} could not ${action.name}${detail}` });
@@ -2816,14 +2844,19 @@ You are operating in a text-and-code modality without direct image pixel renderi
2816
2844
  if (response.thinkingBlocks) {
2817
2845
  assistantMsg.thinking_blocks = response.thinkingBlocks;
2818
2846
  }
2847
+
2848
+ const externalActions = Array.isArray((response as any).externalActions)
2849
+ ? (response as any).externalActions
2850
+ : [];
2851
+ if (externalActions.length > 0) {
2852
+ assistantMsg.external_actions = externalActions;
2853
+ }
2854
+
2819
2855
  this.messages.push(assistantMsg);
2820
2856
 
2821
2857
  // Prose accompanying pending actions is not an execution result.
2822
2858
  // Tool events provide progress; terminal claims pass completion gates below.
2823
2859
 
2824
- const externalActions = Array.isArray((response as any).externalActions)
2825
- ? (response as any).externalActions
2826
- : [];
2827
2860
  const completedExternalActions = externalActions.filter((a: any) => a && a.status === 'completed');
2828
2861
  const failedExternalActions = externalActions.filter((a: any) => a && a.status === 'failed');
2829
2862
  const hasExternalActions = completedExternalActions.length > 0;
@@ -3017,6 +3050,30 @@ You are operating in a text-and-code modality without direct image pixel renderi
3017
3050
  continue;
3018
3051
  }
3019
3052
 
3053
+ if (hasExternalActions && (isIncompleteTurn || isMidTaskProgress) && incompleteTurnContinuations === 3) {
3054
+ incompleteTurnContinuations++;
3055
+ if (response.content) {
3056
+ this.emitEvent({ type: 'agent_message', content: response.content });
3057
+ }
3058
+ this.emitEvent({ type: 'status', message: 'Requesting final deliverable and response...' });
3059
+ this.emitEvent({ type: 'agent_activity', activity: 'Synthesizing final deliverable…' });
3060
+ this.messages.push({
3061
+ role: 'system',
3062
+ content: `[TASK COMPLETION MANDATE: You have completed your tool execution steps (${this.stepsCompleted} steps performed). Provide your complete final response, deliverables, and conclusions directly to the user now. Do not run any more background commands.]`
3063
+ });
3064
+ this.memoryManager.saveHistory(this.messages);
3065
+ continue;
3066
+ }
3067
+
3068
+ if (hasExternalActions && (isIncompleteTurn || isMidTaskProgress || (typeof contentText === 'string' && (contentText.startsWith('Antigravity executed:') || /^Turn completed by .+ over ACP\.$/i.test(contentText.trim()))))) {
3069
+ this.emitEvent({
3070
+ type: 'error',
3071
+ message: 'The task stopped before completion after repeated incomplete turns without a final response. Work remains unfinished.'
3072
+ });
3073
+ this.memoryManager.saveHistory(this.messages);
3074
+ break;
3075
+ }
3076
+
3020
3077
  if (hasExternalActions && !isIncompleteTurn && !isMidTaskProgress) {
3021
3078
  incompleteTurnContinuations = 0;
3022
3079
  }
@@ -1,5 +1,11 @@
1
- const LAUNCH_VERBS = /\b(open|launch|start|run|play|serve|preview)\b/i;
2
- const CHANGE_VERBS = /\b(create|build|make|write|edit|fix|modify|change|update|implement|generate|refactor|delete|remove|install|deploy)\b/i;
1
+ const CREATIVE_WORDS = /\b(?:story|novel|fiction|narrative|lore|essay|poem|poetry|chapter|character|plot|dialogue|scene|cerita|kisah|dongeng|karangan|buku|tulisan|bab|paragraf|halaman)\b/i;
2
+ const INQUIRY_WORDS = /\b(?:explain|why|what|how|who|where|when|analyze|describe|tell\s+me|show\s+me\s+how|difference|summary|summarize|review|audit|jelaskan|kenapa|mengapa|bagaimana|siapa|apakah|analisis)\b/i;
3
+ const CHANGE_VERBS = /\b(?:create|build|make|write|edit|fix|modify|change|update|implement|generate|refactor|delete|remove|install|deploy|add|append|expand|continue|improve|refine|compose|draft|author|design|buat(?:kan)?|bikin|tulis(?:kan)?|ubah|ganti|perbaiki|tambah(?:kan)?|kembangkan|lanjut(?:kan)?|sambung(?:kan)?|membaut|maembuat|merancang|susun|crear|escribir|construir|modificar|actualizar|créer|écrire|modifier|erstellen|schreiben|bauen)\b/i;
4
+ const NON_LAUNCH_PHRASES = /\b(?:(?:run|runs|running)\s+(?:by|on|in|with|out|through)|(?:play|plays|playing)\s+(?:a\s+role|with)|(?:open|opens|opening)\s+(?:to|world|source|mind|ended|door)|(?:start|starts|starting)\s+(?:with|from)|(?:serve|serves|serving)\s+(?:as|to)|in\s+the\s+long\s+run|home\s+run)\b/i;
5
+ const IMPERATIVE_LAUNCH = /^\s*(?:please\s+|can\s+you\s+)?(?:open|launch|start|run|play|serve|preview)(?:\s+(?:it|this|that|app|application|project|game|server|service|dev|preview|up|now|here|locally))?\s*[.!?]?\s*$/i;
6
+ const TARGETED_LAUNCH = /\b(?:open|launch|start|run|play|serve|preview)\s+(?:up\s+)?(?:the\s+|this\s+|an?\s+)?(?:app|application|project|game|server|dev\s+server|website|site|page|ui|preview|demo|localhost|frontend|backend)\b/i;
7
+ const URL_OR_FILE_LAUNCH = /^\s*(?:open|preview)\s+(?:https?:\/\/|\/|~\/|\.\/|[a-zA-Z0-9_\-\.\/]+\.(?:html|htm|php|py|js|ts))\b/i;
8
+ const BROWSER_LAUNCH = /\b(?:open|view)\s+(?:in\s+)?(?:browser|chrome|safari)\b/i;
3
9
  const SERVER_COMMAND = /^\s*(?:python(?:3(?:\.\d+)?)?\s+(?:-u\s+)?(?:\S*\/)?server\.py\b|python(?:3(?:\.\d+)?)?\s+-m\s+http\.server\b|(?:npm|pnpm|yarn|bun)\s+(?:run\s+)?(?:dev|start|serve)\b|(?:npx|bunx)\s+(?:vite|next\s+dev|http-server)\b|uvicorn\b|gunicorn\b|flask\s+run\b)/i;
4
10
  const READ_ONLY_COMMAND = /^\s*(?:pwd|ls|rg|grep|cat|head|tail|find|which|where|ps|pgrep|lsof|netstat|ss|git\s+(?:status|diff|log|show)|node\s+(?:-v|--version)|python(?:3(?:\.\d+)?)?\s+(?:-V|--version))\b/i;
5
11
  const OPEN_COMMAND = /^\s*(?:open|xdg-open|start)\s+\S+/i;
@@ -11,11 +17,29 @@ const MUTATION_TOOLS = new Set([
11
17
  'create_skill', 'manage_local_dependencies'
12
18
  ]);
13
19
  export function isLaunchOnlyPrompt(prompt) {
20
+ if (!prompt || typeof prompt !== 'string')
21
+ return false;
22
+ const trimmed = prompt.trim();
23
+ if (trimmed.length === 0)
24
+ return false;
25
+ if (trimmed.split(/\s+/).length > 25 || trimmed.length > 150)
26
+ return false;
14
27
  if (/\b(?:run|execute)\s+(?:the\s+)?(?:tests?|checks?|lint|benchmarks?|scripts?|commands?|tools?|creative_apps|resolve_act|memory_recall|native_engine|browser_act|fs_read|sysRun)\b/i.test(prompt))
15
28
  return false;
16
29
  if (/\b(?:verify|verification|verify_bridge|inspectActive|simulate|probe|audit|analyze|diagnose)\b/i.test(prompt))
17
30
  return false;
18
- return LAUNCH_VERBS.test(prompt) && !CHANGE_VERBS.test(prompt);
31
+ if (CREATIVE_WORDS.test(prompt))
32
+ return false;
33
+ if (INQUIRY_WORDS.test(prompt))
34
+ return false;
35
+ if (CHANGE_VERBS.test(prompt))
36
+ return false;
37
+ if (NON_LAUNCH_PHRASES.test(prompt))
38
+ return false;
39
+ return IMPERATIVE_LAUNCH.test(prompt)
40
+ || TARGETED_LAUNCH.test(prompt)
41
+ || URL_OR_FILE_LAUNCH.test(prompt)
42
+ || BROWSER_LAUNCH.test(prompt);
19
43
  }
20
44
  export function isServerLaunchCommand(command) {
21
45
  return SERVER_COMMAND.test(command.trim());
@@ -1,5 +1,12 @@
1
- const LAUNCH_VERBS = /\b(open|launch|start|run|play|serve|preview)\b/i;
2
- const CHANGE_VERBS = /\b(create|build|make|write|edit|fix|modify|change|update|implement|generate|refactor|delete|remove|install|deploy)\b/i;
1
+ const CREATIVE_WORDS = /\b(?:story|novel|fiction|narrative|lore|essay|poem|poetry|chapter|character|plot|dialogue|scene|cerita|kisah|dongeng|karangan|buku|tulisan|bab|paragraf|halaman)\b/i;
2
+ const INQUIRY_WORDS = /\b(?:explain|why|what|how|who|where|when|analyze|describe|tell\s+me|show\s+me\s+how|difference|summary|summarize|review|audit|jelaskan|kenapa|mengapa|bagaimana|siapa|apakah|analisis)\b/i;
3
+ const CHANGE_VERBS = /\b(?:create|build|make|write|edit|fix|modify|change|update|implement|generate|refactor|delete|remove|install|deploy|add|append|expand|continue|improve|refine|compose|draft|author|design|buat(?:kan)?|bikin|tulis(?:kan)?|ubah|ganti|perbaiki|tambah(?:kan)?|kembangkan|lanjut(?:kan)?|sambung(?:kan)?|membaut|maembuat|merancang|susun|crear|escribir|construir|modificar|actualizar|créer|écrire|modifier|erstellen|schreiben|bauen)\b/i;
4
+ const NON_LAUNCH_PHRASES = /\b(?:(?:run|runs|running)\s+(?:by|on|in|with|out|through)|(?:play|plays|playing)\s+(?:a\s+role|with)|(?:open|opens|opening)\s+(?:to|world|source|mind|ended|door)|(?:start|starts|starting)\s+(?:with|from)|(?:serve|serves|serving)\s+(?:as|to)|in\s+the\s+long\s+run|home\s+run)\b/i;
5
+
6
+ const IMPERATIVE_LAUNCH = /^\s*(?:please\s+|can\s+you\s+)?(?:open|launch|start|run|play|serve|preview)(?:\s+(?:it|this|that|app|application|project|game|server|service|dev|preview|up|now|here|locally))?\s*[.!?]?\s*$/i;
7
+ const TARGETED_LAUNCH = /\b(?:open|launch|start|run|play|serve|preview)\s+(?:up\s+)?(?:the\s+|this\s+|an?\s+)?(?:app|application|project|game|server|dev\s+server|website|site|page|ui|preview|demo|localhost|frontend|backend)\b/i;
8
+ const URL_OR_FILE_LAUNCH = /^\s*(?:open|preview)\s+(?:https?:\/\/|\/|~\/|\.\/|[a-zA-Z0-9_\-\.\/]+\.(?:html|htm|php|py|js|ts))\b/i;
9
+ const BROWSER_LAUNCH = /\b(?:open|view)\s+(?:in\s+)?(?:browser|chrome|safari)\b/i;
3
10
  const SERVER_COMMAND = /^\s*(?:python(?:3(?:\.\d+)?)?\s+(?:-u\s+)?(?:\S*\/)?server\.py\b|python(?:3(?:\.\d+)?)?\s+-m\s+http\.server\b|(?:npm|pnpm|yarn|bun)\s+(?:run\s+)?(?:dev|start|serve)\b|(?:npx|bunx)\s+(?:vite|next\s+dev|http-server)\b|uvicorn\b|gunicorn\b|flask\s+run\b)/i;
4
11
  const READ_ONLY_COMMAND = /^\s*(?:pwd|ls|rg|grep|cat|head|tail|find|which|where|ps|pgrep|lsof|netstat|ss|git\s+(?:status|diff|log|show)|node\s+(?:-v|--version)|python(?:3(?:\.\d+)?)?\s+(?:-V|--version))\b/i;
5
12
  const OPEN_COMMAND = /^\s*(?:open|xdg-open|start)\s+\S+/i;
@@ -13,9 +20,23 @@ const MUTATION_TOOLS = new Set([
13
20
  ]);
14
21
 
15
22
  export function isLaunchOnlyPrompt(prompt: string): boolean {
23
+ if (!prompt || typeof prompt !== 'string') return false;
24
+ const trimmed = prompt.trim();
25
+ if (trimmed.length === 0) return false;
26
+ if (trimmed.split(/\s+/).length > 25 || trimmed.length > 150) return false;
27
+
16
28
  if (/\b(?:run|execute)\s+(?:the\s+)?(?:tests?|checks?|lint|benchmarks?|scripts?|commands?|tools?|creative_apps|resolve_act|memory_recall|native_engine|browser_act|fs_read|sysRun)\b/i.test(prompt)) return false;
17
29
  if (/\b(?:verify|verification|verify_bridge|inspectActive|simulate|probe|audit|analyze|diagnose)\b/i.test(prompt)) return false;
18
- return LAUNCH_VERBS.test(prompt) && !CHANGE_VERBS.test(prompt);
30
+
31
+ if (CREATIVE_WORDS.test(prompt)) return false;
32
+ if (INQUIRY_WORDS.test(prompt)) return false;
33
+ if (CHANGE_VERBS.test(prompt)) return false;
34
+ if (NON_LAUNCH_PHRASES.test(prompt)) return false;
35
+
36
+ return IMPERATIVE_LAUNCH.test(prompt)
37
+ || TARGETED_LAUNCH.test(prompt)
38
+ || URL_OR_FILE_LAUNCH.test(prompt)
39
+ || BROWSER_LAUNCH.test(prompt);
19
40
  }
20
41
 
21
42
  export function isServerLaunchCommand(command: string): boolean {
package/src/tui/block.js CHANGED
@@ -21,62 +21,39 @@
21
21
  // It degrades in two steps rather than one: without truecolor/256 there is no
22
22
  // fill and the bar alone carries the block; without colour at all the bar is an
23
23
  // ASCII `|`. A transcript piped to a file stays clean either way.
24
- //
25
- // Pure Node over ./theme.js and ./text.js. No dependency, no shell.
26
-
24
+ // @ts-expect-error theme.js has no TypeScript declaration yet.
27
25
  import { paint, fill, dim, GLYPHS, HAS_COLOR } from './theme.js';
28
26
  import { visibleWidth, padEnd, truncate, wrap } from './text.js';
29
-
30
27
  // Columns between the bar and the text. opencode uses paddingLeft={2} inside its
31
28
  // bordered box; one column belongs to the bar, so the gutter is one more.
32
29
  const GUTTER = 1;
33
-
34
30
  /**
35
31
  * Render `lines` as one block with a left accent bar.
32
+ * Uses a continuous unbroken box-drawing heavy rule (barHeavy '┃')
33
+ * that dynamically spans the exact length of lines without gaps or bullet interruptions.
36
34
  *
37
- * @param {string[]} lines already-styled rows; NOT re-wrapped (see blockOf)
38
- * @param {object} options
39
- * @param {number} options.width total columns the block may occupy
40
- * @param {string} options.role accent role for the bar (user, agent, accent…)
41
- * @param {boolean} options.filled paint the surface behind the text
42
- * @param {string} options.surface which surface role to fill with
43
- * @returns {string[]} rows, each exactly `width` columns wide
35
+ * @param lines already-styled rows; NOT re-wrapped (see blockOf)
36
+ * @param options configuration options
37
+ * @returns rows, each exactly `width` columns wide
44
38
  */
45
- export function barBlock(lines, {
46
- width = 80,
47
- role = 'accent',
48
- filled = true,
49
- surface = 'surface',
50
- punctuate = false
51
- } = {}) {
52
- // The input box asks for a continuous heavy rule with a dot at its middle —
53
- // long line, dot, long line. Everything else keeps the half-block bar, because
54
- // a message block is content and the input box is chrome you type INTO; the
55
- // reference draws that distinction too, giving its prompt box custom border
56
- // characters no message uses (component/prompt/index.tsx:1354-1358).
57
- //
58
- // Punctuation needs three rows to read as "middle": below that it would land
59
- // on the only row there is, and a dot alone is not a rule.
60
- const glyph = punctuate ? GLYPHS.barHeavy : GLYPHS.bar;
61
- const middle = punctuate && lines.length >= 3 ? Math.floor(lines.length / 2) : -1;
62
-
63
- const barWidth = visibleWidth(glyph);
64
- const body = Math.max(1, width - barWidth - GUTTER);
65
- const bar = paint(role, glyph);
66
- const marked = paint(role, GLYPHS.bullet);
67
- const gutter = ' '.repeat(GUTTER);
68
-
69
- return lines.map((line, index) => {
70
- // Clip first, then pad: a line longer than the block would otherwise push
71
- // the fill past the right edge and wrap, which is the failure ChatPrompt
72
- // clampRows() exists to prevent one layer up.
73
- const clipped = visibleWidth(line) > body ? truncate(line, body, GLYPHS.ellipsis) : line;
74
- const padded = padEnd(clipped, body);
75
- const inner = filled ? fill(surface, gutter + padded) : gutter + padded;
76
- return (index === middle ? marked : bar) + inner;
77
- });
39
+ export function barBlock(lines, { width = 80, role = 'accent', filled = true, surface = 'surface', punctuate = false } = {}) {
40
+ // Use continuous heavy vertical line ('┃') for clean, solid, unbroken alignment.
41
+ // Box-drawing characters connect seamlessly across lines in all terminal fonts without line-height leading gaps.
42
+ const glyph = GLYPHS.barHeavy || GLYPHS.bar || '┃';
43
+ const barWidth = visibleWidth(glyph);
44
+ const body = Math.max(1, width - barWidth - GUTTER);
45
+ const bar = paint(role, glyph);
46
+ const gutter = ' '.repeat(GUTTER);
47
+ return lines.map((line) => {
48
+ // Clip first, then pad: a line longer than the block would otherwise push
49
+ // the fill past the right edge and wrap, which is the failure ChatPrompt
50
+ // clampRows() exists to prevent one layer up.
51
+ const clipped = visibleWidth(line) > body ? truncate(line, body, GLYPHS.ellipsis) : line;
52
+ const padded = padEnd(clipped, body);
53
+ const inner = filled ? fill(surface, gutter + padded) : gutter + padded;
54
+ return bar + inner;
55
+ });
78
56
  }
79
-
80
57
  /**
81
58
  * Wrap `text` to the block's inner width, then render it as a block.
82
59
  *
@@ -84,69 +61,48 @@ export function barBlock(lines, {
84
61
  * rows individually (the prompt editor, a status row) use barBlock directly.
85
62
  */
86
63
  export function blockOf(text, options = {}) {
87
- const width = options.width || 80;
88
- const inner = Math.max(1, width - visibleWidth(GLYPHS.bar) - GUTTER);
89
- const lines = wrap(String(text == null ? '' : text), inner);
90
- return barBlock(lines.length ? lines : [''], options);
64
+ const width = options.width || 80;
65
+ const glyph = GLYPHS.barHeavy || GLYPHS.bar || '┃';
66
+ const inner = Math.max(1, width - visibleWidth(glyph) - GUTTER);
67
+ const lines = wrap(String(text == null ? '' : text), inner);
68
+ return barBlock(lines.length ? lines : [''], options);
91
69
  }
92
-
93
70
  /**
94
71
  * A bordered panel with its title inset into the top border.
95
- *
96
- * The session header used to be two horizontal rules with label/value rows
97
- * between them, which reads as a table of settings rather than as a greeting.
98
- * Both references open with a bordered panel instead — claude-code insets the
99
- * product name and version into the top rule exactly this way.
100
- *
101
- * `rows` are already-styled strings. Returns rows of exactly `width` columns.
102
72
  */
103
73
  export function panel(rows, { width = 80, title = '', role = 'rule' } = {}) {
104
- const inner = Math.max(4, width - 2);
105
- const h = GLYPHS.hLine;
106
- const label = title ? ` ${title} ` : '';
107
- const clippedLabel = visibleWidth(label) > inner - 2 ? '' : label;
108
- const lead = clippedLabel ? h : '';
109
- const trail = h.repeat(Math.max(0, inner - visibleWidth(clippedLabel) - visibleWidth(lead)));
110
-
111
- const top = paint(role, GLYPHS.topLeft + lead)
112
- + (clippedLabel ? paint('accent', clippedLabel) : '')
113
- + paint(role, trail + GLYPHS.topRight);
114
- const bottom = paint(role, GLYPHS.bottomLeft + h.repeat(inner) + GLYPHS.bottomRight);
115
-
116
- const side = paint(role, GLYPHS.vLine);
117
- const middle = rows.map((row) => {
118
- const clipped = visibleWidth(row) > inner ? truncate(row, inner, GLYPHS.ellipsis) : row;
119
- return side + padEnd(clipped, inner) + side;
120
- });
121
-
122
- return [top, ...middle, bottom];
74
+ const inner = Math.max(4, width - 2);
75
+ const h = GLYPHS.hLine;
76
+ const label = title ? ` ${title} ` : '';
77
+ const clippedLabel = visibleWidth(label) > inner - 2 ? '' : label;
78
+ const lead = clippedLabel ? h : '';
79
+ const trail = h.repeat(Math.max(0, inner - visibleWidth(clippedLabel) - visibleWidth(lead)));
80
+ const top = paint(role, GLYPHS.topLeft + lead)
81
+ + (clippedLabel ? paint('accent', clippedLabel) : '')
82
+ + paint(role, trail + GLYPHS.topRight);
83
+ const bottom = paint(role, GLYPHS.bottomLeft + h.repeat(inner) + GLYPHS.bottomRight);
84
+ const side = paint(role, GLYPHS.vLine);
85
+ const middle = rows.map((row) => {
86
+ const clipped = visibleWidth(row) > inner ? truncate(row, inner, GLYPHS.ellipsis) : row;
87
+ return side + padEnd(clipped, inner) + side;
88
+ });
89
+ return [top, ...middle, bottom];
123
90
  }
124
-
125
91
  /**
126
92
  * `9.2K (5%)` — what the context window has left, at a glance.
127
- *
128
- * Returns '' rather than a misleading 0% when no limit is known: an invented
129
- * denominator is worse than a missing number.
130
- *
131
- * BOTH ARGUMENTS MUST BE IN THE SAME UNIT. The caller was passing a cumulative
132
- * TOKEN count and a CHARACTER pool, which is how a quarter-full window came to
133
- * report 99%.
134
93
  */
135
94
  export function contextMeter(usedTokens, limitTokens) {
136
- const used = Number(usedTokens) || 0;
137
- const limit = Number(limitTokens) || 0;
138
- if (used <= 0) return '';
139
- const compact = used < 1000
140
- ? String(Math.round(used))
141
- : used < 1000000
142
- ? `${(used / 1000).toFixed(used < 10000 ? 1 : 0)}K`
143
- : `${(used / 1000000).toFixed(1)}M`;
144
- if (limit <= 0) return compact;
145
- // NOT clamped to 99. The clamp was there to keep the meter from looking like
146
- // a hard stop, and its real effect was to hide a 242% reading behind a
147
- // plausible-looking one for a whole session. A meter that cannot report
148
- // "over" is a meter that cannot report the only thing worth acting on.
149
- return `${compact} (${Math.round((used / limit) * 100)}%)`;
95
+ const used = Number(usedTokens) || 0;
96
+ const limit = Number(limitTokens) || 0;
97
+ if (used <= 0)
98
+ return '';
99
+ const compact = used < 1000
100
+ ? String(Math.round(used))
101
+ : used < 1000000
102
+ ? `${(used / 1000).toFixed(used < 10000 ? 1 : 0)}K`
103
+ : `${(used / 1000000).toFixed(1)}M`;
104
+ if (limit <= 0)
105
+ return compact;
106
+ return `${compact} (${Math.round((used / limit) * 100)}%)`;
150
107
  }
151
-
152
108
  export { GUTTER };