@causyne/agent 1.20.112 → 1.20.117

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 (169) hide show
  1. package/docs/ARCHITECTURE.md +29 -0
  2. package/package.json +1 -1
  3. package/src/agentLoop.js +153 -68
  4. package/src/agentLoop.ts +152 -71
  5. package/src/browser/browserRuntime.js +13 -8
  6. package/src/browser/browserRuntime.ts +16 -8
  7. package/src/browser/causyneBrowser.js +37 -9
  8. package/src/browser/causyneBrowser.ts +37 -9
  9. package/src/browser/searchProviders.js +18 -7
  10. package/src/browser/searchProviders.ts +17 -5
  11. package/src/browser/snapshotWindow.js +1 -1
  12. package/src/browser/snapshotWindow.ts +1 -1
  13. package/src/browser/urlPolicy.js +21 -10
  14. package/src/browser/urlPolicy.ts +19 -10
  15. package/src/browser/workspacePreview.js +13 -1
  16. package/src/browser/workspacePreview.ts +11 -1
  17. package/src/cliMode.js +5 -1
  18. package/src/computerUse/visionGrounding.js +31 -27
  19. package/src/computerUse/visionGrounding.ts +27 -27
  20. package/src/continuum/ui/continuumPicker.js +14 -6
  21. package/src/continuum/ui/continuumPicker.ts +13 -6
  22. package/src/continuum/ui/continuumPickerView.js +24 -15
  23. package/src/continuum/ui/continuumPickerView.ts +24 -16
  24. package/src/memory/scopedFacts.js +171 -0
  25. package/src/memory/scopedFacts.ts +214 -0
  26. package/src/memory.d.ts +13 -1
  27. package/src/memory.js +9 -12
  28. package/src/observer/advisory.js +32 -22
  29. package/src/observer/advisory.ts +30 -18
  30. package/src/observer/coldObserver.js +21 -33
  31. package/src/observer/coldObserver.ts +20 -33
  32. package/src/observer/evidence.js +20 -13
  33. package/src/observer/evidence.ts +21 -13
  34. package/src/observer.js +47 -12
  35. package/src/observer.ts +50 -18
  36. package/src/perception.js +124 -3
  37. package/src/perception.ts +128 -4
  38. package/src/planCache.js +17 -3
  39. package/src/planCache.ts +17 -3
  40. package/src/pluginsFactory/discovery.js +28 -16
  41. package/src/pluginsFactory/discovery.ts +29 -16
  42. package/src/pluginsFactory/pluginsFactory.js +213 -38
  43. package/src/pluginsFactory/pluginsFactory.ts +218 -39
  44. package/src/pluginsFactory/strategy.js +26 -16
  45. package/src/pluginsFactory/strategy.ts +34 -19
  46. package/src/pluginsFactory/templates.js +183 -62
  47. package/src/pluginsFactory/templates.ts +174 -54
  48. package/src/smartToolsUse.js +4 -5
  49. package/src/smartToolsUse.ts +4 -6
  50. package/src/taskShape.js +49 -7
  51. package/src/taskShape.ts +55 -7
  52. package/src/timeMachine.js +43 -22
  53. package/src/timeMachine.ts +44 -22
  54. package/src/tool-scripts/desktop_act.applescript +1 -0
  55. package/src/toolPacks.js +27 -5
  56. package/src/toolPacks.ts +32 -5
  57. package/src/tools/computerUse.js +23 -10
  58. package/src/tools/computerUse.ts +19 -8
  59. package/src/tools/desktopAct.js +12 -1
  60. package/src/tools/memoryWrite.js +8 -10
  61. package/src/tools/memoryWrite.ts +13 -11
  62. package/src/tools/pluginsFactory.js +108 -5
  63. package/src/tools/pluginsFactory.ts +115 -5
  64. package/src/tui/CausyneRotor.js +24 -10
  65. package/src/tui/CausyneRotor.ts +25 -10
  66. package/src/tui/activityLayout.js +9 -5
  67. package/src/tui/activityLayout.ts +9 -5
  68. package/src/tui/ask.js +34 -14
  69. package/src/tui/banner.js +55 -18
  70. package/src/tui/banner.ts +52 -17
  71. package/src/tui/block.js +47 -20
  72. package/src/tui/block.ts +54 -27
  73. package/src/tui/chatRenderer.js +139 -84
  74. package/src/tui/chatboxClipboard.js +12 -5
  75. package/src/tui/chatboxClipboard.ts +10 -4
  76. package/src/tui/clipboardImage.js +52 -42
  77. package/src/tui/clipboardImage.ts +50 -39
  78. package/src/tui/clipboardSync.js +12 -1
  79. package/src/tui/clipboardSync.ts +9 -1
  80. package/src/tui/codeProgress.js +60 -28
  81. package/src/tui/codeProgress.ts +60 -27
  82. package/src/tui/codeStreamRenderer.js +94 -23
  83. package/src/tui/codeStreamRenderer.ts +92 -23
  84. package/src/tui/commandPresentation.js +9 -2
  85. package/src/tui/commandPresentation.ts +9 -2
  86. package/src/tui/completion.js +45 -23
  87. package/src/tui/composerControls.js +21 -10
  88. package/src/tui/composerControls.ts +18 -10
  89. package/src/tui/composerGeometry.js +6 -4
  90. package/src/tui/composerGeometry.ts +6 -4
  91. package/src/tui/consoleGuard.js +29 -7
  92. package/src/tui/consoleGuard.ts +28 -7
  93. package/src/tui/dialogs.js +134 -71
  94. package/src/tui/diff.js +8 -4
  95. package/src/tui/history.js +6 -5
  96. package/src/tui/home.js +25 -13
  97. package/src/tui/homeView.js +37 -18
  98. package/src/tui/homeView.ts +38 -18
  99. package/src/tui/inlineSlash.js +6 -5
  100. package/src/tui/inlineSlash.ts +6 -5
  101. package/src/tui/keys.js +36 -18
  102. package/src/tui/layout.js +27 -9
  103. package/src/tui/layout.ts +26 -9
  104. package/src/tui/lineEditor.js +49 -23
  105. package/src/tui/markdownMath.js +64 -14
  106. package/src/tui/markdownMath.ts +69 -13
  107. package/src/tui/messageActionPlacement.js +28 -13
  108. package/src/tui/messageActionPlacement.ts +28 -13
  109. package/src/tui/messageInteraction.js +111 -46
  110. package/src/tui/messageInteraction.ts +115 -47
  111. package/src/tui/modelPicker.js +44 -15
  112. package/src/tui/modelPicker.ts +48 -15
  113. package/src/tui/observerPicker.js +56 -13
  114. package/src/tui/observerPicker.ts +73 -30
  115. package/src/tui/overlay.js +79 -35
  116. package/src/tui/overlay.ts +81 -34
  117. package/src/tui/prompt.js +186 -94
  118. package/src/tui/runningLight.js +1 -1
  119. package/src/tui/runningLight.ts +1 -1
  120. package/src/tui/scrollInteraction.js +64 -36
  121. package/src/tui/scrollInteraction.ts +70 -37
  122. package/src/tui/selectList.js +60 -32
  123. package/src/tui/sessionLayout.js +11 -3
  124. package/src/tui/sessionLayout.ts +10 -3
  125. package/src/tui/sessionPicker.js +74 -46
  126. package/src/tui/sessionPicker.ts +73 -48
  127. package/src/tui/sessionPickerView.js +32 -19
  128. package/src/tui/sessionPickerView.ts +31 -18
  129. package/src/tui/sessionSidebar.js +87 -57
  130. package/src/tui/sessionSidebar.ts +90 -54
  131. package/src/tui/setup.js +28 -3
  132. package/src/tui/setup.ts +27 -3
  133. package/src/tui/skillAuthoring.js +11 -5
  134. package/src/tui/skillAuthoring.ts +11 -5
  135. package/src/tui/smartLinkClick.js +75 -23
  136. package/src/tui/smartLinkClick.ts +86 -26
  137. package/src/tui/stage.js +47 -16
  138. package/src/tui/stage.ts +53 -18
  139. package/src/tui/stageSurface.js +232 -51
  140. package/src/tui/statusLine.js +85 -53
  141. package/src/tui/statusLine.ts +82 -46
  142. package/src/tui/terminalInputFramer.js +5 -2
  143. package/src/tui/text.js +117 -46
  144. package/src/tui/text.ts +113 -43
  145. package/src/tui/textLayout.js +6 -4
  146. package/src/tui/textLayout.ts +11 -5
  147. package/src/tui/theme.js +17 -8
  148. package/src/tui/thinkingBox.js +95 -95
  149. package/src/tui/thinkingBox.ts +105 -80
  150. package/src/tui/toolActivityPolicy.js +8 -1
  151. package/src/tui/toolActivityPolicy.ts +7 -1
  152. package/src/tui/toolDisplay.js +15 -6
  153. package/src/tui/toolDisplay.ts +16 -6
  154. package/src/tui/toolOutputNormalizer.js +16 -3
  155. package/src/tui/toolOutputNormalizer.ts +13 -3
  156. package/src/tui/transcript.js +15 -9
  157. package/src/tui/turnRail.js +176 -80
  158. package/src/tui/turnRail.ts +173 -71
  159. package/src/tui/usageCard.js +136 -80
  160. package/src/tui/usageCard.ts +145 -103
  161. package/src/tui/viewport.js +48 -23
  162. package/src/tui/viewport.ts +48 -27
  163. package/src/tui/viewportAnchor.js +2 -2
  164. package/src/tui/viewportAnchor.ts +2 -2
  165. package/src/tui/workspaceFileIndex.js +8 -6
  166. package/src/tui/workspaceFileIndex.ts +8 -6
  167. package/src/tui/workspaceSwitch.js +13 -10
  168. package/src/tui/workspaceSwitch.ts +11 -7
  169. package/src/types/contracts.ts +3 -0
@@ -5,7 +5,6 @@ import { auditLog } from '../auditLog.js';
5
5
  import { isLaunchOnlyPrompt } from '../launchIntent.js';
6
6
  import { causyneHome } from '../utils/paths.js';
7
7
  import {
8
- boundedArgs,
9
8
  outcomeFromResult,
10
9
  scanMutation
11
10
  } from './evidence.js';
@@ -176,39 +175,18 @@ function confirmThreshold(strictness: ObserverStrictness): number {
176
175
  return 0.62;
177
176
  }
178
177
 
179
- function nestedError(result: unknown): string {
180
- if (result === null || typeof result !== 'object' || Array.isArray(result)) return '';
181
- const record = result as Record<string, unknown>;
182
- return typeof record.error === 'string' ? record.error : '';
183
- }
184
-
185
178
  function normalizeOutcome(entry: TurnToolEvidence): ToolOutcome {
186
179
  const args = entry.args && typeof entry.args === 'object' && !Array.isArray(entry.args)
187
180
  ? entry.args
188
181
  : {};
189
- const result = entry.result;
190
- const error = nestedError(result);
191
- const command = entry.command
192
- || (typeof args.command === 'string' ? args.command : '')
193
- || (typeof args.CommandLine === 'string' ? args.CommandLine : '')
194
- || (typeof args.commandLine === 'string' ? args.commandLine : '')
195
- || (typeof args.cmd === 'string' ? args.cmd : '')
196
- || (typeof args.script === 'string' ? args.script : '')
197
- || (['run_command', 'run', 'execute', 'exec', 'bash', 'terminal', 'sh', 'zsh', 'sysrun'].includes(String(entry.tool || '').toLowerCase()) && typeof args.detail === 'string' ? args.detail : '');
182
+ const normalized = outcomeFromResult(entry.tool, args, entry.result, 0);
183
+ const command = typeof entry.command === 'string' && entry.command.trim() ? entry.command : normalized.command;
184
+ const targetPath = typeof entry.path === 'string' && entry.path.trim() ? entry.path : normalized.path;
198
185
  return {
199
- tool: entry.tool,
200
- args: boundedArgs(args),
201
- success: entry.success === true && !error,
202
- error: error.slice(0, 600),
203
- exitCode: result !== null && typeof result === 'object' && !Array.isArray(result)
204
- && typeof (result as Record<string, unknown>).exitCode === 'number'
205
- ? (result as Record<string, unknown>).exitCode as number
206
- : null,
186
+ ...normalized,
187
+ success: entry.success === true && normalized.success,
207
188
  command: command.slice(0, 600),
208
- path: entry.path
209
- || (typeof args.path === 'string' ? args.path : '')
210
- || (typeof args.file_path === 'string' ? args.file_path : ''),
211
- at: 0
189
+ path: targetPath.slice(0, 400)
212
190
  };
213
191
  }
214
192
 
@@ -240,7 +218,16 @@ export class ColdObserver {
240
218
  private static instance: ColdObserver | null = null;
241
219
 
242
220
  constructor(configPartial?: Partial<ObserverConfig>) {
243
- this.config = { ...DEFAULT_CONFIG, ...readStoredConfig(), ...(configPartial || {}) };
221
+ const base = { ...DEFAULT_CONFIG, ...readStoredConfig() };
222
+ const partial = configPartial || {};
223
+ this.config = {
224
+ enabled: typeof partial.enabled === 'boolean' ? partial.enabled : base.enabled,
225
+ mode: normalizeMode(partial.mode) ?? base.mode,
226
+ endpoint: typeof partial.endpoint === 'string' ? partial.endpoint.trim().replace(/\/+$/, '') : base.endpoint,
227
+ model: typeof partial.model === 'string' ? partial.model.trim().slice(0, 200) : base.model,
228
+ timeoutMs: boundedTimeout(partial.timeoutMs) ?? base.timeoutMs,
229
+ strictness: normalizeStrictness(partial.strictness) ?? base.strictness
230
+ };
244
231
  }
245
232
 
246
233
  static getInstance(): ColdObserver {
@@ -478,10 +465,10 @@ export class ColdObserver {
478
465
  && /\.(?:[cm]?[jt]sx?|py|rb|php|go|rs|java|kt|kts|swift|c|cc|cpp|h|hpp|cs|fs|sh|sql|html|css|scss|sass|vue|svelte)$/i.test(outcome.path);
479
466
  const lastCodeChange = outcomes.findLastIndex(isCodeMutation);
480
467
  const checks = outcomes.slice(lastCodeChange + 1);
481
- const hasTestRun = checks.some((outcome) => outcome.success
482
- && (TEST_COMMAND.test(outcome.command) || TEST_COMMAND.test(outcome.tool)));
483
- const hasBuildRun = checks.some((outcome) => outcome.success
484
- && (BUILD_OR_CHECK_COMMAND.test(outcome.command) || outcome.tool === 'code_verify_syntax'));
468
+ const testChecks = checks.filter((outcome) => TEST_COMMAND.test(outcome.command) || TEST_COMMAND.test(outcome.tool));
469
+ const buildChecks = checks.filter((outcome) => BUILD_OR_CHECK_COMMAND.test(outcome.command) || outcome.tool === 'code_verify_syntax');
470
+ const hasTestRun = testChecks.length > 0 && testChecks[testChecks.length - 1]!.success;
471
+ const hasBuildRun = buildChecks.length > 0 && buildChecks[buildChecks.length - 1]!.success;
485
472
  const isLaunch = isLaunchOnlyPrompt(turnState.userPrompt || '');
486
473
  const modifiedCode = lastCodeChange >= 0;
487
474
  const declarativeOnly = modifiedCode && outcomes.filter(isCodeMutation).every(outcome => /\.(?:html|css)$/i.test(outcome.path));
@@ -93,7 +93,10 @@ function physicalRoot(workspaceRoot) {
93
93
  return realpathLoose(path.resolve(workspaceRoot));
94
94
  }
95
95
  function resolveTarget(workspaceRoot, raw) {
96
- const lexical = resolveUserPath(raw);
96
+ const trimmed = String(raw ?? '').trim();
97
+ const lexical = trimmed === '~' || trimmed.startsWith('~/') || trimmed.startsWith('~\\') || path.isAbsolute(trimmed)
98
+ ? resolveUserPath(trimmed)
99
+ : path.resolve(workspaceRoot, trimmed);
97
100
  const physical = realpathLoose(lexical);
98
101
  const root = physicalRoot(workspaceRoot);
99
102
  const relative = path.relative(root, physical);
@@ -114,6 +117,9 @@ export function toolPath(args) {
114
117
  export function isCodePath(target) {
115
118
  return CODE_EXTENSIONS.has(path.extname(target).toLowerCase());
116
119
  }
120
+ export function isRenderedNativeBrowserAction(tool) {
121
+ return ['browser_act', 'preview', 'snapshot'].includes(tool.toLowerCase());
122
+ }
117
123
  export function isVerificationCommand(command) {
118
124
  return VERIFICATION_COMMAND.test(command);
119
125
  }
@@ -279,7 +285,7 @@ function scanWrite(toolName, args, workspaceRoot, evidence) {
279
285
  }
280
286
  }
281
287
  else {
282
- const edits = Array.isArray(args.edits) ? args.edits : [];
288
+ const edits = Array.isArray(args.edits) && args.edits.length > 0 ? args.edits : [args];
283
289
  let delta = 0;
284
290
  let sawEdit = false;
285
291
  for (const edit of edits) {
@@ -288,20 +294,24 @@ function scanWrite(toolName, args, workspaceRoot, evidence) {
288
294
  const record = edit;
289
295
  const before = typeof record.old_string === 'string'
290
296
  ? record.old_string
291
- : typeof record.searchContent === 'string' ? record.searchContent : null;
297
+ : typeof record.searchContent === 'string'
298
+ ? record.searchContent
299
+ : typeof record.oldText === 'string' ? record.oldText : null;
292
300
  const after = typeof record.new_string === 'string'
293
301
  ? record.new_string
294
- : typeof record.replaceContent === 'string' ? record.replaceContent : null;
302
+ : typeof record.replaceContent === 'string'
303
+ ? record.replaceContent
304
+ : typeof record.newText === 'string' ? record.newText : null;
295
305
  if (before === null || after === null)
296
306
  continue;
297
307
  delta += Buffer.byteLength(after, 'utf8') - Buffer.byteLength(before, 'utf8');
298
308
  sawEdit = true;
299
309
  }
300
310
  if (sawEdit && originalSize !== null)
301
- replacementSize = originalSize + delta;
311
+ replacementSize = Math.max(0, originalSize + delta);
302
312
  }
303
313
  if (originalSize !== null && replacementSize !== null && originalSize > 1024 && replacementSize < originalSize * 0.2) {
304
- const lost = Math.round((1 - replacementSize / originalSize) * 100);
314
+ const lost = Math.min(100, Math.max(0, Math.round((1 - replacementSize / originalSize) * 100)));
305
315
  add(evidence, 'write-large-shrink', 'high', `edit removes about ${lost}% of ${base}`, 0.78);
306
316
  }
307
317
  }
@@ -426,13 +436,10 @@ export function outcomeFromResult(tool, args, result, at) {
426
436
  && !(typeof record.exitCode === 'number' && (!Number.isFinite(record.exitCode) || record.exitCode !== 0));
427
437
  const rawError = typeof record.error === 'string' ? record.error : '';
428
438
  const exitCode = typeof record.exitCode === 'number' && Number.isFinite(record.exitCode) ? record.exitCode : null;
429
- const rawCommand = typeof args.command === 'string' ? args.command
430
- : typeof args.CommandLine === 'string' ? args.CommandLine
431
- : typeof args.commandLine === 'string' ? args.commandLine
432
- : typeof args.cmd === 'string' ? args.cmd
433
- : typeof args.script === 'string' ? args.script
434
- : (['run_command', 'run', 'execute', 'exec', 'bash', 'terminal', 'sh', 'zsh', 'sysrun'].includes((tool || '').toLowerCase()) && typeof args.detail === 'string') ? args.detail
435
- : '';
439
+ const detailFallback = ['run_command', 'run', 'execute', 'exec', 'bash', 'terminal', 'sh', 'zsh', 'sysrun']
440
+ .includes((tool || '').toLowerCase()) ? args.detail : undefined;
441
+ const rawCommand = [args.command, args.CommandLine, args.commandLine, args.cmd, args.script, detailFallback]
442
+ .find((value) => typeof value === 'string' && value.trim().length > 0) ?? '';
436
443
  const command = rawCommand.trim();
437
444
  const browserData = Array.isArray(record.data) ? record.data : [];
438
445
  const imageCaptured = success && record._is_image_marker === true;
@@ -147,7 +147,10 @@ function physicalRoot(workspaceRoot: string): string {
147
147
  }
148
148
 
149
149
  function resolveTarget(workspaceRoot: string, raw: string): { lexical: string; physical: string; inside: boolean } {
150
- const lexical = resolveUserPath(raw);
150
+ const trimmed = String(raw ?? '').trim();
151
+ const lexical = trimmed === '~' || trimmed.startsWith('~/') || trimmed.startsWith('~\\') || path.isAbsolute(trimmed)
152
+ ? resolveUserPath(trimmed)
153
+ : path.resolve(workspaceRoot, trimmed);
151
154
  const physical = realpathLoose(lexical);
152
155
  const root = physicalRoot(workspaceRoot);
153
156
  const relative = path.relative(root, physical);
@@ -171,6 +174,10 @@ export function isCodePath(target: string): boolean {
171
174
  return CODE_EXTENSIONS.has(path.extname(target).toLowerCase());
172
175
  }
173
176
 
177
+ export function isRenderedNativeBrowserAction(tool: string): boolean {
178
+ return ['browser_act', 'preview', 'snapshot'].includes(tool.toLowerCase());
179
+ }
180
+
174
181
  export function isVerificationCommand(command: string): boolean {
175
182
  return VERIFICATION_COMMAND.test(command);
176
183
  }
@@ -346,7 +353,7 @@ function scanWrite(toolName: string, args: Record<string, unknown>, workspaceRoo
346
353
  }
347
354
  }
348
355
  } else {
349
- const edits = Array.isArray(args.edits) ? args.edits : [];
356
+ const edits = Array.isArray(args.edits) && args.edits.length > 0 ? args.edits : [args];
350
357
  let delta = 0;
351
358
  let sawEdit = false;
352
359
  for (const edit of edits) {
@@ -354,19 +361,23 @@ function scanWrite(toolName: string, args: Record<string, unknown>, workspaceRoo
354
361
  const record = edit as Record<string, unknown>;
355
362
  const before = typeof record.old_string === 'string'
356
363
  ? record.old_string
357
- : typeof record.searchContent === 'string' ? record.searchContent : null;
364
+ : typeof record.searchContent === 'string'
365
+ ? record.searchContent
366
+ : typeof record.oldText === 'string' ? record.oldText : null;
358
367
  const after = typeof record.new_string === 'string'
359
368
  ? record.new_string
360
- : typeof record.replaceContent === 'string' ? record.replaceContent : null;
369
+ : typeof record.replaceContent === 'string'
370
+ ? record.replaceContent
371
+ : typeof record.newText === 'string' ? record.newText : null;
361
372
  if (before === null || after === null) continue;
362
373
  delta += Buffer.byteLength(after, 'utf8') - Buffer.byteLength(before, 'utf8');
363
374
  sawEdit = true;
364
375
  }
365
- if (sawEdit && originalSize !== null) replacementSize = originalSize + delta;
376
+ if (sawEdit && originalSize !== null) replacementSize = Math.max(0, originalSize + delta);
366
377
  }
367
378
 
368
379
  if (originalSize !== null && replacementSize !== null && originalSize > 1024 && replacementSize < originalSize * 0.2) {
369
- const lost = Math.round((1 - replacementSize / originalSize) * 100);
380
+ const lost = Math.min(100, Math.max(0, Math.round((1 - replacementSize / originalSize) * 100)));
370
381
  add(evidence, 'write-large-shrink', 'high', `edit removes about ${lost}% of ${base}`, 0.78);
371
382
  }
372
383
  }
@@ -490,13 +501,10 @@ export function outcomeFromResult(tool: string, args: Record<string, unknown>, r
490
501
  && !(typeof record.exitCode === 'number' && (!Number.isFinite(record.exitCode) || record.exitCode !== 0));
491
502
  const rawError = typeof record.error === 'string' ? record.error : '';
492
503
  const exitCode = typeof record.exitCode === 'number' && Number.isFinite(record.exitCode) ? record.exitCode : null;
493
- const rawCommand = typeof args.command === 'string' ? args.command
494
- : typeof args.CommandLine === 'string' ? args.CommandLine
495
- : typeof args.commandLine === 'string' ? args.commandLine
496
- : typeof args.cmd === 'string' ? args.cmd
497
- : typeof args.script === 'string' ? args.script
498
- : (['run_command', 'run', 'execute', 'exec', 'bash', 'terminal', 'sh', 'zsh', 'sysrun'].includes((tool || '').toLowerCase()) && typeof args.detail === 'string') ? args.detail
499
- : '';
504
+ const detailFallback = ['run_command', 'run', 'execute', 'exec', 'bash', 'terminal', 'sh', 'zsh', 'sysrun']
505
+ .includes((tool || '').toLowerCase()) ? args.detail : undefined;
506
+ const rawCommand = [args.command, args.CommandLine, args.commandLine, args.cmd, args.script, detailFallback]
507
+ .find((value): value is string => typeof value === 'string' && value.trim().length > 0) ?? '';
500
508
  const command = rawCommand.trim();
501
509
  const browserData = Array.isArray(record.data) ? record.data : [];
502
510
  const imageCaptured = success && record._is_image_marker === true;
package/src/observer.js CHANGED
@@ -3,22 +3,51 @@ import path from 'node:path';
3
3
  import http from 'node:http';
4
4
  import { createHash } from 'node:crypto';
5
5
  import { coldObserver } from './observer/coldObserver.js';
6
+ import { isVerificationCommand } from './observer/evidence.js';
6
7
  export function extractClaimedLocalUrls(text) {
7
8
  if (!text)
8
9
  return [];
9
- const matches = text.match(/https?:\/\/(?:localhost|127\.0\.0\.1|\[::1\]):\d+(?:\/[^\s)>'"`\]]*)?/gi) || [];
10
+ const matches = text.match(/https?:\/\/[^\s)>'"`]+/gi) || [];
10
11
  const unique = new Set();
11
12
  for (const raw of matches) {
12
13
  let end = raw.length;
13
- while (end > 0 && '.,;:!?'.includes(raw[end - 1])) {
14
- end--;
14
+ while (end > 0) {
15
+ const ch = raw[end - 1];
16
+ if ('.,;:!?'.includes(ch)) {
17
+ end--;
18
+ continue;
19
+ }
20
+ if (ch === ']') {
21
+ const prefix = raw.slice(0, end);
22
+ const opens = prefix.split('[').length - 1;
23
+ const closes = prefix.split(']').length - 1;
24
+ if (closes > opens) {
25
+ end--;
26
+ continue;
27
+ }
28
+ }
29
+ break;
15
30
  }
16
31
  const cleaned = raw.slice(0, end);
17
- if (cleaned)
32
+ if (!cleaned)
33
+ continue;
34
+ try {
35
+ const url = new URL(cleaned);
36
+ if (!['localhost', '127.0.0.1', '[::1]'].includes(url.hostname) || url.username || url.password)
37
+ continue;
18
38
  unique.add(cleaned);
39
+ }
40
+ catch {
41
+ // Ignore malformed and lookalike URLs rather than verifying a false localhost claim.
42
+ }
19
43
  }
20
44
  return [...unique];
21
45
  }
46
+ const FILE_MUTATION_TOOLS = new Set([
47
+ 'fs_write', 'fs_edit', 'MultiEdit', 'fs_delete', 'fs_move',
48
+ 'write_file', 'write_to_file', 'edit_file', 'replace_file_content',
49
+ 'multi_replace_file_content', 'write', 'edit', 'multiedit'
50
+ ]);
22
51
  function isWorkspaceArtifact(workspaceRoot, targetPath) {
23
52
  try {
24
53
  const root = fs.realpathSync(workspaceRoot);
@@ -95,17 +124,20 @@ export class CausyneObserver {
95
124
  const claimsCompletion = /\b(?:done|complete|completed|finished|implemented|fixed|verified)\b|\b(?:is\s+(?:running|live|available|listening|served)\s+(?:at|on)|application\s+is\s+running)\b/i.test(claim);
96
125
  if (claimsCompletion) {
97
126
  // Run deterministic verification checks based on domain
98
- const hasMutations = outcomes.some(o => ['fs_write', 'fs_edit', 'MultiEdit', 'write_file', 'edit_file'].includes(o.tool));
99
- const hasPassingVerification = outcomes.slice(outcomes.findLastIndex(o => ['fs_write', 'fs_edit', 'MultiEdit', 'write_file', 'edit_file'].includes(o.tool)) + 1).some(o => o.success && (o.exitCode == null || o.exitCode === 0) && (o.rendered === true ||
127
+ const lastMutationIndex = outcomes.findLastIndex(o => FILE_MUTATION_TOOLS.has(o.tool));
128
+ const hasMutations = lastMutationIndex >= 0;
129
+ const verifications = outcomes.slice(lastMutationIndex + 1).filter(o => o.rendered === true ||
100
130
  o.tool === 'verify_local_web' ||
101
- (o.command && /\b(?:test|build|check|typecheck|vitest|jest|pytest)\b/i.test(o.command))));
102
- if (hasMutations && !hasPassingVerification) {
131
+ Boolean(o.command && isVerificationCommand(o.command)));
132
+ const lastVerif = verifications[verifications.length - 1];
133
+ const hasPassingVerification = Boolean(lastVerif && lastVerif.success && (lastVerif.exitCode == null || lastVerif.exitCode === 0));
134
+ if (!hasPassingVerification) {
103
135
  return {
104
- status: 'ready-to-verify',
136
+ status: hasMutations ? 'ready-to-verify' : 'progressing',
105
137
  evidenceRefs,
106
138
  verified: false,
107
139
  confidence: 0.6,
108
- message: 'Mutations performed but automated test/build verification has not yet run.',
140
+ message: hasMutations ? 'Mutations performed but automated test/build verification has not yet run.' : 'Completion claimed without supporting verification evidence.',
109
141
  nextAction: 'Run targeted verification tests or build checks to confirm completion.'
110
142
  };
111
143
  }
@@ -209,7 +241,7 @@ export class CausyneObserver {
209
241
  try {
210
242
  const url = new URL(req.endpoint);
211
243
  // Security gate: only loopback is permitted for local verification
212
- if (!['localhost', '127.0.0.1', '::1'].includes(url.hostname)) {
244
+ if (!['localhost', '127.0.0.1', '[::1]'].includes(url.hostname)) {
213
245
  resolve({ verified: false, error: 'Only local loopback endpoints (127.0.0.1, localhost) may be verified.' });
214
246
  return;
215
247
  }
@@ -217,7 +249,10 @@ export class CausyneObserver {
217
249
  resolve({ verified: false, error: 'Local verification URL must not contain credentials.' });
218
250
  return;
219
251
  }
220
- const clientReq = http.get(req.endpoint, { timeout: req.timeoutMs ?? 3000 }, (res) => {
252
+ const safeTimeoutMs = typeof req.timeoutMs === 'number' && Number.isFinite(req.timeoutMs) && req.timeoutMs > 0
253
+ ? Math.max(100, Math.min(30_000, Math.floor(req.timeoutMs)))
254
+ : 3000;
255
+ const clientReq = http.get(req.endpoint, { timeout: safeTimeoutMs }, (res) => {
221
256
  res.resume();
222
257
  const expected = req.expectedStatus ?? 200;
223
258
  const ok = req.expectedStatus === undefined
package/src/observer.ts CHANGED
@@ -3,7 +3,7 @@ import path from 'node:path';
3
3
  import http from 'node:http';
4
4
  import { createHash } from 'node:crypto';
5
5
  import { coldObserver } from './observer/coldObserver.js';
6
- import type { ToolOutcome } from './observer/evidence.js';
6
+ import { isVerificationCommand, type ToolOutcome } from './observer/evidence.js';
7
7
 
8
8
  export type ObservationStatus =
9
9
  | 'progressing'
@@ -63,19 +63,46 @@ export interface TaskObservationContext {
63
63
 
64
64
  export function extractClaimedLocalUrls(text: string): string[] {
65
65
  if (!text) return [];
66
- const matches = text.match(/https?:\/\/(?:localhost|127\.0\.0\.1|\[::1\]):\d+(?:\/[^\s)>'"`\]]*)?/gi) || [];
66
+ const matches = text.match(/https?:\/\/[^\s)>'"`]+/gi) || [];
67
67
  const unique = new Set<string>();
68
68
  for (const raw of matches) {
69
69
  let end = raw.length;
70
- while (end > 0 && '.,;:!?'.includes(raw[end - 1]!)) {
71
- end--;
70
+ while (end > 0) {
71
+ const ch = raw[end - 1]!;
72
+ if ('.,;:!?'.includes(ch)) {
73
+ end--;
74
+ continue;
75
+ }
76
+ if (ch === ']') {
77
+ const prefix = raw.slice(0, end);
78
+ const opens = prefix.split('[').length - 1;
79
+ const closes = prefix.split(']').length - 1;
80
+ if (closes > opens) {
81
+ end--;
82
+ continue;
83
+ }
84
+ }
85
+ break;
72
86
  }
73
87
  const cleaned = raw.slice(0, end);
74
- if (cleaned) unique.add(cleaned);
88
+ if (!cleaned) continue;
89
+ try {
90
+ const url = new URL(cleaned);
91
+ if (!['localhost', '127.0.0.1', '[::1]'].includes(url.hostname) || url.username || url.password) continue;
92
+ unique.add(cleaned);
93
+ } catch {
94
+ // Ignore malformed and lookalike URLs rather than verifying a false localhost claim.
95
+ }
75
96
  }
76
97
  return [...unique];
77
98
  }
78
99
 
100
+ const FILE_MUTATION_TOOLS = new Set([
101
+ 'fs_write', 'fs_edit', 'MultiEdit', 'fs_delete', 'fs_move',
102
+ 'write_file', 'write_to_file', 'edit_file', 'replace_file_content',
103
+ 'multi_replace_file_content', 'write', 'edit', 'multiedit'
104
+ ]);
105
+
79
106
  function isWorkspaceArtifact(workspaceRoot: string, targetPath: string): boolean {
80
107
  try {
81
108
  const root = fs.realpathSync(workspaceRoot);
@@ -158,24 +185,25 @@ export class CausyneObserver {
158
185
 
159
186
  if (claimsCompletion) {
160
187
  // Run deterministic verification checks based on domain
161
- const hasMutations = outcomes.some(o =>
162
- ['fs_write', 'fs_edit', 'MultiEdit', 'write_file', 'edit_file'].includes(o.tool)
188
+ const lastMutationIndex = outcomes.findLastIndex(o => FILE_MUTATION_TOOLS.has(o.tool));
189
+ const hasMutations = lastMutationIndex >= 0;
190
+ const verifications = outcomes.slice(lastMutationIndex + 1).filter(o =>
191
+ o.rendered === true ||
192
+ o.tool === 'verify_local_web' ||
193
+ Boolean(o.command && isVerificationCommand(o.command))
163
194
  );
164
- const hasPassingVerification = outcomes.slice(outcomes.findLastIndex(o => ['fs_write', 'fs_edit', 'MultiEdit', 'write_file', 'edit_file'].includes(o.tool)) + 1).some(o =>
165
- o.success && (o.exitCode == null || o.exitCode === 0) && (
166
- o.rendered === true ||
167
- o.tool === 'verify_local_web' ||
168
- (o.command && /\b(?:test|build|check|typecheck|vitest|jest|pytest)\b/i.test(o.command))
169
- )
195
+ const lastVerif = verifications[verifications.length - 1];
196
+ const hasPassingVerification = Boolean(
197
+ lastVerif && lastVerif.success && (lastVerif.exitCode == null || lastVerif.exitCode === 0)
170
198
  );
171
199
 
172
- if (hasMutations && !hasPassingVerification) {
200
+ if (!hasPassingVerification) {
173
201
  return {
174
- status: 'ready-to-verify',
202
+ status: hasMutations ? 'ready-to-verify' : 'progressing',
175
203
  evidenceRefs,
176
204
  verified: false,
177
205
  confidence: 0.6,
178
- message: 'Mutations performed but automated test/build verification has not yet run.',
206
+ message: hasMutations ? 'Mutations performed but automated test/build verification has not yet run.' : 'Completion claimed without supporting verification evidence.',
179
207
  nextAction: 'Run targeted verification tests or build checks to confirm completion.'
180
208
  };
181
209
  }
@@ -285,7 +313,7 @@ export class CausyneObserver {
285
313
  try {
286
314
  const url = new URL(req.endpoint);
287
315
  // Security gate: only loopback is permitted for local verification
288
- if (!['localhost', '127.0.0.1', '::1'].includes(url.hostname)) {
316
+ if (!['localhost', '127.0.0.1', '[::1]'].includes(url.hostname)) {
289
317
  resolve({ verified: false, error: 'Only local loopback endpoints (127.0.0.1, localhost) may be verified.' });
290
318
  return;
291
319
  }
@@ -295,7 +323,11 @@ export class CausyneObserver {
295
323
  return;
296
324
  }
297
325
 
298
- const clientReq = http.get(req.endpoint, { timeout: req.timeoutMs ?? 3000 }, (res) => {
326
+ const safeTimeoutMs =
327
+ typeof req.timeoutMs === 'number' && Number.isFinite(req.timeoutMs) && req.timeoutMs > 0
328
+ ? Math.max(100, Math.min(30_000, Math.floor(req.timeoutMs)))
329
+ : 3000;
330
+ const clientReq = http.get(req.endpoint, { timeout: safeTimeoutMs }, (res) => {
299
331
  res.resume();
300
332
  const expected = req.expectedStatus ?? 200;
301
333
  const ok = req.expectedStatus === undefined
package/src/perception.js CHANGED
@@ -30,10 +30,20 @@ export class WorkspacePerception {
30
30
  }
31
31
  // 2b. Design system detection (Anti-Slop: tells the brain what's already installed)
32
32
  context.designSystem = await this.detectDesignContext(resolvedPath);
33
- // 2c. Subprojects detection (find subfolders like 'pixel2d games', 'causyne-agent', etc.)
33
+ // 2c. Subprojects & nested stacks discovery
34
34
  context.subprojects = await this.detectSubprojects(resolvedPath);
35
- // 2d. Key files discovery
36
- context.keyFiles = await this.detectKeyFiles(resolvedPath);
35
+ const repoArtifacts = await this.detectRepoArtifacts(resolvedPath, context.subprojects);
36
+ context.subprojectStacks = repoArtifacts.subprojectStacks;
37
+ context.docFiles = repoArtifacts.docFiles;
38
+ context.buildFiles = repoArtifacts.buildFiles;
39
+ context.topEntries = repoArtifacts.topEntries;
40
+ // 2d. Key files discovery (root entrypoints + key docs & build scripts)
41
+ const rootKeyFiles = await this.detectKeyFiles(resolvedPath);
42
+ context.keyFiles = [...new Set([
43
+ ...rootKeyFiles,
44
+ ...repoArtifacts.buildFiles.slice(0, 8),
45
+ ...repoArtifacts.docFiles.slice(0, 8)
46
+ ])];
37
47
  // 2e. Package manager detection
38
48
  context.packageManager = await this.detectPackageManager(resolvedPath);
39
49
  // 2f. Git branch and status
@@ -196,6 +206,114 @@ export class WorkspacePerception {
196
206
  }
197
207
  return subprojects;
198
208
  }
209
+ async detectRepoArtifacts(dir, subprojects) {
210
+ const subprojectStacks = [];
211
+ const docFiles = [];
212
+ const buildFiles = [];
213
+ const topEntries = [];
214
+ const existsFile = async (rel) => {
215
+ try {
216
+ const stat = await fs.stat(path.join(dir, rel));
217
+ return stat.isFile();
218
+ }
219
+ catch {
220
+ return false;
221
+ }
222
+ };
223
+ try {
224
+ const entries = await fs.readdir(dir, { withFileTypes: true });
225
+ for (const entry of entries) {
226
+ if (entry.name.startsWith('.') || SKIP_DIRECTORIES.has(entry.name))
227
+ continue;
228
+ if (topEntries.length >= 25)
229
+ break;
230
+ topEntries.push(entry.isDirectory() ? `${entry.name}/` : entry.name);
231
+ }
232
+ }
233
+ catch {
234
+ // ignore
235
+ }
236
+ const rootDocs = ['AGENTS.md', 'CLAUDE.md', 'README.md', 'ARCHITECTURE.md', 'CONTRIBUTING.md', 'RELEASE.md', 'ANDROID_RELEASE.md', 'ENGINEERING.md'];
237
+ for (const rel of rootDocs) {
238
+ if (await existsFile(rel))
239
+ docFiles.push(rel);
240
+ }
241
+ const priorityDocScore = (name) => {
242
+ const lower = name.toLowerCase();
243
+ if (/(?:release|android|build|architecture|engineering)/.test(lower))
244
+ return 0;
245
+ if (/(?:readme|agents|claude|work_log|qa|guide)/.test(lower))
246
+ return 1;
247
+ return 2;
248
+ };
249
+ for (const docDir of ['docs', 'doc']) {
250
+ try {
251
+ const docEntries = await fs.readdir(path.join(dir, docDir), { withFileTypes: true });
252
+ const mdFiles = docEntries
253
+ .filter(e => e.isFile() && /\.(?:md|txt)$/i.test(e.name) && !e.name.startsWith('.'))
254
+ .map(e => `${docDir}/${e.name}`)
255
+ .sort((a, b) => priorityDocScore(a) - priorityDocScore(b) || a.localeCompare(b));
256
+ for (const rel of mdFiles) {
257
+ if (docFiles.length >= 16)
258
+ break;
259
+ if (!docFiles.includes(rel))
260
+ docFiles.push(rel);
261
+ }
262
+ }
263
+ catch {
264
+ // ignore missing docs dir
265
+ }
266
+ }
267
+ const rootBuildCandidates = [
268
+ 'Makefile', 'CMakeLists.txt', 'package.json', 'tsconfig.json',
269
+ 'project.godot', 'export_presets.cfg', 'build.gradle', 'build.gradle.kts',
270
+ 'settings.gradle', 'settings.gradle.kts', 'Cargo.toml', 'pyproject.toml',
271
+ 'go.mod', 'pubspec.yaml', 'Dockerfile', 'docker-compose.yml', 'wrangler.toml'
272
+ ];
273
+ for (const rel of rootBuildCandidates) {
274
+ if (await existsFile(rel))
275
+ buildFiles.push(rel);
276
+ }
277
+ try {
278
+ const scriptEntries = await fs.readdir(path.join(dir, 'scripts'), { withFileTypes: true });
279
+ for (const entry of scriptEntries.sort((a, b) => a.name.localeCompare(b.name))) {
280
+ if (!entry.isFile() || entry.name.startsWith('.'))
281
+ continue;
282
+ if (/\.(?:sh|bash|py|js|cjs|mjs|ts|ps1)$/i.test(entry.name)) {
283
+ const rel = `scripts/${entry.name}`;
284
+ if (!buildFiles.includes(rel) && buildFiles.length < 18)
285
+ buildFiles.push(rel);
286
+ }
287
+ }
288
+ }
289
+ catch {
290
+ // ignore missing scripts dir
291
+ }
292
+ const nestedCheckDirs = [...new Set([...subprojects, 'godot', 'android', 'app', 'mobile', 'desktop', 'server', 'backend', 'frontend', 'web'])];
293
+ for (const sub of nestedCheckDirs) {
294
+ if (sub.includes('..') || path.isAbsolute(sub))
295
+ continue;
296
+ const subBuildChecks = [
297
+ { rel: `${sub}/project.godot`, stack: `godot (gdscript) @ ${sub}/` },
298
+ { rel: `${sub}/export_presets.cfg` },
299
+ { rel: `${sub}/build.gradle.kts`, stack: `android (kotlin/gradle) @ ${sub}/` },
300
+ { rel: `${sub}/build.gradle`, stack: `android (gradle) @ ${sub}/` },
301
+ { rel: `${sub}/Cargo.toml`, stack: `rust @ ${sub}/` },
302
+ { rel: `${sub}/go.mod`, stack: `go @ ${sub}/` },
303
+ { rel: `${sub}/pyproject.toml`, stack: `python @ ${sub}/` },
304
+ { rel: `${sub}/package.json`, stack: `node @ ${sub}/` }
305
+ ];
306
+ for (const check of subBuildChecks) {
307
+ if (await existsFile(check.rel)) {
308
+ if (!buildFiles.includes(check.rel) && buildFiles.length < 22)
309
+ buildFiles.push(check.rel);
310
+ if (check.stack && !subprojectStacks.includes(check.stack))
311
+ subprojectStacks.push(check.stack);
312
+ }
313
+ }
314
+ }
315
+ return { subprojectStacks, docFiles, buildFiles, topEntries };
316
+ }
199
317
  async detectKeyFiles(dir) {
200
318
  const candidateFiles = [
201
319
  'package.json', 'tsconfig.json', 'index.html', 'main.js',
@@ -285,6 +403,9 @@ export class WorkspacePerception {
285
403
  catch {
286
404
  // ignore
287
405
  }
406
+ if (context.subprojectStacks?.some(s => s.startsWith('godot '))) {
407
+ return 'Godot Game Project';
408
+ }
288
409
  // Check directory name or key files for game patterns
289
410
  const baseName = path.basename(dir).toLowerCase();
290
411
  if (baseName.includes('game') || baseName.includes('pixel') || baseName.includes('arcade')) {