@causyne/agent 1.20.54 → 1.20.55

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.54",
3
+ "version": "1.20.55",
4
4
  "description": "Agentic AI for software, tools, and computer workflows",
5
5
  "main": "bin/causyne.js",
6
6
  "type": "module",
@@ -18,8 +18,78 @@ const MUTATING_TOOLS = new Set([
18
18
  'fs_write', 'fs_edit', 'MultiEdit', 'fs_delete', 'fs_move', 'sysRun', 'sysRunBg',
19
19
  'gitOp', 'manage_local_dependencies', 'plugin_manage', 'tool_forge', 'plugins_factory', 'create_skill',
20
20
  'write_file', 'write_to_file', 'edit_file', 'replace_file_content', 'multi_replace_file_content',
21
- 'write', 'edit', 'multiedit', 'bash', 'terminal', 'execute'
21
+ 'write', 'edit', 'multiedit', 'bash', 'terminal', 'execute', 'run_command'
22
22
  ]);
23
+ function splitCommandSegments(command) {
24
+ const segments = [];
25
+ let current = '';
26
+ let inSingle = false;
27
+ let inDouble = false;
28
+ let escape = false;
29
+ for (let i = 0; i < command.length; i++) {
30
+ const ch = command[i];
31
+ if (escape) {
32
+ current += ch;
33
+ escape = false;
34
+ continue;
35
+ }
36
+ if (ch === '\\') {
37
+ escape = true;
38
+ current += ch;
39
+ continue;
40
+ }
41
+ if (ch === "'" && !inDouble) {
42
+ inSingle = !inSingle;
43
+ current += ch;
44
+ continue;
45
+ }
46
+ if (ch === '"' && !inSingle) {
47
+ inDouble = !inDouble;
48
+ current += ch;
49
+ continue;
50
+ }
51
+ if (!inSingle && !inDouble) {
52
+ if (ch === ';') {
53
+ if (current.trim())
54
+ segments.push(current.trim());
55
+ current = '';
56
+ continue;
57
+ }
58
+ if (ch === '&' && command[i + 1] === '&') {
59
+ if (current.trim())
60
+ segments.push(current.trim());
61
+ current = '';
62
+ i++;
63
+ continue;
64
+ }
65
+ if (ch === '|' && command[i + 1] === '|') {
66
+ if (current.trim())
67
+ segments.push(current.trim());
68
+ current = '';
69
+ i++;
70
+ continue;
71
+ }
72
+ }
73
+ current += ch;
74
+ }
75
+ if (current.trim())
76
+ segments.push(current.trim());
77
+ return segments;
78
+ }
79
+ const READ_ONLY_CMD_REGEX = /^\s*(?:(?:pwd|ls|find|rg|grep|cat|sed|awk|head|tail|wc|diff|file|stat|which|whereis|type|du|df|pdfinfo|pdftotext|identify|mediainfo|ffprobe|otool|readelf|nm|ps|lsof|top|uptime|whoami|id|uname|env|printenv|echo|printf|pytest)\b|git\s+(?:status|diff|log|show|branch|tag|remote|rev-parse|describe)\b|npm\s+(?:view|audit|test|ls|list|explain|run\s+(?:test|check|lint|typecheck|verify))\b|pnpm\s+(?:test|view|audit|ls|list|run\s+(?:test|check|lint|typecheck|verify))\b|yarn\s+(?:test|audit|list|run\s+(?:test|check|lint|typecheck|verify))\b|bun\s+(?:test|pm)\b|npx\s+(?:jest|vitest|mocha|ava|playwright\s+test|cypress\s+run|tsc\s+--noEmit)\b|tsc\s+--noEmit\b|node\s+(?:--check|--test|-e\b|--eval\b|-p\b|--print\b|.*?(?:test|spec|verify|check))|(?:python3?|py)\s+(?:-m\s+(?:unittest|pytest|doctest|py_compile)|-c\b|.*?(?:test|spec|verify))|cargo\s+(?:test|check)\b|go\s+test\b|curl\s+(?:-I|-sI|-s\b|--head)\b)/i;
80
+ export function isReadOnlyShellCommand(command) {
81
+ const trimmed = command.trim();
82
+ if (!trimmed)
83
+ return true;
84
+ const segments = splitCommandSegments(trimmed);
85
+ return segments.length > 0 && segments.every(seg => {
86
+ const s = seg.trim();
87
+ if (!s)
88
+ return true;
89
+ const stripped = s.replace(/^(?:[a-zA-Z_][a-zA-Z0-9_]*=[^\s]+\s+)+/, '');
90
+ return READ_ONLY_CMD_REGEX.test(stripped);
91
+ });
92
+ }
23
93
  function containsAny(text, terms) {
24
94
  return terms.some(term => text.includes(term));
25
95
  }
@@ -68,9 +138,9 @@ export function isMutatingToolCall(toolName, args = {}) {
68
138
  if (toolName === 'native_engine')
69
139
  return !['status', 'catalog', 'describe', 'inspect', 'probe'].includes(String(args.action ?? ''));
70
140
  if (MUTATING_TOOLS.has(toolName)) {
71
- if (['sysRun', 'sysRunBg', 'bash', 'terminal', 'execute', 'sh', 'zsh'].includes(toolName)) {
141
+ if (['sysRun', 'sysRunBg', 'bash', 'terminal', 'execute', 'sh', 'zsh', 'run_command'].includes(toolName)) {
72
142
  const command = String(args.command ?? args.cmd ?? '');
73
- return !/^\s*(?:pwd|ls|find|rg|grep|cat|sed|head|tail|git\s+(?:status|diff|log|show)|npm\s+(?:view|audit|test)|node\s+--check)\b/i.test(command);
143
+ return !isReadOnlyShellCommand(command);
74
144
  }
75
145
  if (toolName === 'gitOp') {
76
146
  const action = String(args.action ?? args.command ?? args.operation ?? '');
@@ -52,9 +52,77 @@ const MUTATING_TOOLS = new Set([
52
52
  'fs_write', 'fs_edit', 'MultiEdit', 'fs_delete', 'fs_move', 'sysRun', 'sysRunBg',
53
53
  'gitOp', 'manage_local_dependencies', 'plugin_manage', 'tool_forge', 'plugins_factory', 'create_skill',
54
54
  'write_file', 'write_to_file', 'edit_file', 'replace_file_content', 'multi_replace_file_content',
55
- 'write', 'edit', 'multiedit', 'bash', 'terminal', 'execute'
55
+ 'write', 'edit', 'multiedit', 'bash', 'terminal', 'execute', 'run_command'
56
56
  ]);
57
57
 
58
+ function splitCommandSegments(command: string): string[] {
59
+ const segments: string[] = [];
60
+ let current = '';
61
+ let inSingle = false;
62
+ let inDouble = false;
63
+ let escape = false;
64
+
65
+ for (let i = 0; i < command.length; i++) {
66
+ const ch = command[i]!;
67
+ if (escape) {
68
+ current += ch;
69
+ escape = false;
70
+ continue;
71
+ }
72
+ if (ch === '\\') {
73
+ escape = true;
74
+ current += ch;
75
+ continue;
76
+ }
77
+ if (ch === "'" && !inDouble) {
78
+ inSingle = !inSingle;
79
+ current += ch;
80
+ continue;
81
+ }
82
+ if (ch === '"' && !inSingle) {
83
+ inDouble = !inDouble;
84
+ current += ch;
85
+ continue;
86
+ }
87
+ if (!inSingle && !inDouble) {
88
+ if (ch === ';') {
89
+ if (current.trim()) segments.push(current.trim());
90
+ current = '';
91
+ continue;
92
+ }
93
+ if (ch === '&' && command[i + 1] === '&') {
94
+ if (current.trim()) segments.push(current.trim());
95
+ current = '';
96
+ i++;
97
+ continue;
98
+ }
99
+ if (ch === '|' && command[i + 1] === '|') {
100
+ if (current.trim()) segments.push(current.trim());
101
+ current = '';
102
+ i++;
103
+ continue;
104
+ }
105
+ }
106
+ current += ch;
107
+ }
108
+ if (current.trim()) segments.push(current.trim());
109
+ return segments;
110
+ }
111
+
112
+ const READ_ONLY_CMD_REGEX = /^\s*(?:(?:pwd|ls|find|rg|grep|cat|sed|awk|head|tail|wc|diff|file|stat|which|whereis|type|du|df|pdfinfo|pdftotext|identify|mediainfo|ffprobe|otool|readelf|nm|ps|lsof|top|uptime|whoami|id|uname|env|printenv|echo|printf|pytest)\b|git\s+(?:status|diff|log|show|branch|tag|remote|rev-parse|describe)\b|npm\s+(?:view|audit|test|ls|list|explain|run\s+(?:test|check|lint|typecheck|verify))\b|pnpm\s+(?:test|view|audit|ls|list|run\s+(?:test|check|lint|typecheck|verify))\b|yarn\s+(?:test|audit|list|run\s+(?:test|check|lint|typecheck|verify))\b|bun\s+(?:test|pm)\b|npx\s+(?:jest|vitest|mocha|ava|playwright\s+test|cypress\s+run|tsc\s+--noEmit)\b|tsc\s+--noEmit\b|node\s+(?:--check|--test|-e\b|--eval\b|-p\b|--print\b|.*?(?:test|spec|verify|check))|(?:python3?|py)\s+(?:-m\s+(?:unittest|pytest|doctest|py_compile)|-c\b|.*?(?:test|spec|verify))|cargo\s+(?:test|check)\b|go\s+test\b|curl\s+(?:-I|-sI|-s\b|--head)\b)/i;
113
+
114
+ export function isReadOnlyShellCommand(command: string): boolean {
115
+ const trimmed = command.trim();
116
+ if (!trimmed) return true;
117
+ const segments = splitCommandSegments(trimmed);
118
+ return segments.length > 0 && segments.every(seg => {
119
+ const s = seg.trim();
120
+ if (!s) return true;
121
+ const stripped = s.replace(/^(?:[a-zA-Z_][a-zA-Z0-9_]*=[^\s]+\s+)+/, '');
122
+ return READ_ONLY_CMD_REGEX.test(stripped);
123
+ });
124
+ }
125
+
58
126
  function containsAny(text: string, terms: readonly string[]): boolean {
59
127
  return terms.some(term => text.includes(term));
60
128
  }
@@ -107,9 +175,9 @@ export function isMutatingToolCall(toolName: string, args: Record<string, unknow
107
175
  }
108
176
  if (toolName === 'native_engine') return !['status', 'catalog', 'describe', 'inspect', 'probe'].includes(String(args.action ?? ''));
109
177
  if (MUTATING_TOOLS.has(toolName)) {
110
- if (['sysRun', 'sysRunBg', 'bash', 'terminal', 'execute', 'sh', 'zsh'].includes(toolName)) {
178
+ if (['sysRun', 'sysRunBg', 'bash', 'terminal', 'execute', 'sh', 'zsh', 'run_command'].includes(toolName)) {
111
179
  const command = String(args.command ?? args.cmd ?? '');
112
- return !/^\s*(?:pwd|ls|find|rg|grep|cat|sed|head|tail|git\s+(?:status|diff|log|show)|npm\s+(?:view|audit|test)|node\s+--check)\b/i.test(command);
180
+ return !isReadOnlyShellCommand(command);
113
181
  }
114
182
  if (toolName === 'gitOp') {
115
183
  const action = String(args.action ?? args.command ?? args.operation ?? '');
@@ -28,6 +28,7 @@ import { activityRows } from './activityLayout.js';
28
28
  import { cleanToolOutputPreview, normalizeHistoricalToolResult, normalizeHistoricalExternalAction } from './toolOutputNormalizer.js';
29
29
  import { formatMarkdownMath } from './markdownMath.js';
30
30
  import { renderThinkingFrame } from './thinkingBox.js';
31
+ import { measureMessages, resolveCharPool } from '../contextManager.js';
31
32
 
32
33
  // Bound the preview AFTER wrapping, not by source newlines: one 400 KB line of
33
34
  // minified output would otherwise become thousands of rows and lock the
@@ -566,6 +567,11 @@ export class ChatRenderer {
566
567
  if (info.messagesCount === undefined || info.messagesCount === null) {
567
568
  info.messagesCount = messages.filter(m => m && m.role !== 'system').length;
568
569
  }
570
+ const measuredChars = measureMessages(messages);
571
+ if (measuredChars > 0) {
572
+ this.status.contextChars = measuredChars;
573
+ info.contextChars = measuredChars;
574
+ }
569
575
 
570
576
  if (info.title || info.id) {
571
577
  this.renderSessionDivider(info);
@@ -704,6 +710,21 @@ export class ChatRenderer {
704
710
  }
705
711
  }
706
712
 
713
+ const finalMeasured = measureMessages(messages);
714
+ if (finalMeasured > 0) {
715
+ this.status.contextChars = finalMeasured;
716
+ }
717
+ if (!this.status.contextLimit) {
718
+ this.status.contextLimit = resolveCharPool(this.status.tier);
719
+ }
720
+ if (sessionInfo) {
721
+ this.status.setSession({
722
+ ...sessionInfo,
723
+ contextChars: this.status.contextChars || finalMeasured,
724
+ contextLimit: sessionInfo.contextLimit || this.status.contextLimit
725
+ });
726
+ }
727
+
707
728
  if (this.transcript?.surface?.viewport) {
708
729
  this.transcript.surface.viewport.manual = false;
709
730
  this.transcript.surface.viewport.unseen = 0;
@@ -41,11 +41,9 @@ export function sessionSidebarRows(facts, height) {
41
41
  styled(bold('Context'));
42
42
  const limit = Number.isFinite(facts.contextLimit) ? Number(facts.contextLimit) : 0;
43
43
  const used = Number.isFinite(facts.contextChars) ? Number(facts.contextChars) : 0;
44
- if (limit > 0) {
44
+ if (limit > 0 && used > 0) {
45
45
  const rawPercent = (used / limit) * 100;
46
- const percent = used > 0
47
- ? Math.max(1, Math.min(100, Math.round(rawPercent)))
48
- : 0;
46
+ const percent = Math.max(1, Math.min(100, Math.round(rawPercent)));
49
47
  styled(dim(`${percent}% of available window`));
50
48
  }
51
49
  else {
@@ -56,11 +56,9 @@ export function sessionSidebarRows(facts: SidebarFacts, height: number): string[
56
56
  styled(bold('Context'));
57
57
  const limit = Number.isFinite(facts.contextLimit) ? Number(facts.contextLimit) : 0;
58
58
  const used = Number.isFinite(facts.contextChars) ? Number(facts.contextChars) : 0;
59
- if (limit > 0) {
59
+ if (limit > 0 && used > 0) {
60
60
  const rawPercent = (used / limit) * 100;
61
- const percent = used > 0
62
- ? Math.max(1, Math.min(100, Math.round(rawPercent)))
63
- : 0;
61
+ const percent = Math.max(1, Math.min(100, Math.round(rawPercent)));
64
62
  styled(dim(`${percent}% of available window`));
65
63
  } else {
66
64
  styled(dim('No context measurement yet'));