@causyne/agent 1.20.11 → 1.20.12

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 (86) hide show
  1. package/LICENSE +1 -1
  2. package/docs/ARCHITECTURE.md +24 -1
  3. package/package.json +1 -1
  4. package/src/acp/client.js +9 -2
  5. package/src/acp/client.ts +11 -2
  6. package/src/acp/protocol.ts +9 -0
  7. package/src/agentLoop.js +504 -119
  8. package/src/agentLoop.ts +477 -121
  9. package/src/browser/browserRuntime.js +47 -0
  10. package/src/browser/browserRuntime.ts +45 -0
  11. package/src/browser/causyneBrowser.js +60 -31
  12. package/src/browser/causyneBrowser.ts +37 -12
  13. package/src/browser/workspacePreview.js +52 -0
  14. package/src/browser/workspacePreview.ts +49 -0
  15. package/src/core/planCache.js +5 -0
  16. package/src/core/planCache.ts +5 -0
  17. package/src/decisionPolicy.js +9 -0
  18. package/src/decisionPolicy.ts +8 -0
  19. package/src/historyPruner.js +251 -0
  20. package/src/historyPruner.ts +263 -0
  21. package/src/infra/atomicWriter.js +49 -0
  22. package/src/infra/atomicWriter.ts +63 -0
  23. package/src/infra/telemetry.js +38 -0
  24. package/src/infra/telemetry.ts +68 -0
  25. package/src/observer/coldObserver.js +12 -7
  26. package/src/observer/coldObserver.ts +12 -7
  27. package/src/observer/evidence.js +8 -2
  28. package/src/observer/evidence.ts +9 -2
  29. package/src/outputRecovery.js +36 -0
  30. package/src/outputRecovery.ts +33 -0
  31. package/src/providers/acp.js +114 -46
  32. package/src/providers/acp.ts +129 -46
  33. package/src/providers/antigravity.js +264 -82
  34. package/src/providers/antigravity.ts +273 -87
  35. package/src/providers/antigravityBridge.js +58 -0
  36. package/src/providers/antigravityBridge.ts +51 -0
  37. package/src/providers/base.d.ts +9 -0
  38. package/src/providers/budgetEnforcer.js +110 -0
  39. package/src/providers/budgetEnforcer.ts +122 -0
  40. package/src/providers/collaborationPolicy.js +6 -0
  41. package/src/providers/collaborationPolicy.ts +7 -0
  42. package/src/providers/loopGuard.js +84 -0
  43. package/src/providers/loopGuard.ts +105 -0
  44. package/src/providers/pi.js +19 -6
  45. package/src/providers/pi.ts +19 -7
  46. package/src/providers/toolContracts.js +36 -0
  47. package/src/providers/toolContracts.ts +48 -0
  48. package/src/session/sidechainEvents.js +49 -0
  49. package/src/session/sidechainEvents.ts +98 -0
  50. package/src/skillsManager.d.ts +1 -0
  51. package/src/smartToolsUse.js +123 -4
  52. package/src/smartToolsUse.ts +136 -4
  53. package/src/subagent/sidechainHarness.js +66 -0
  54. package/src/subagent/sidechainHarness.ts +91 -0
  55. package/src/taskContinuation.js +12 -0
  56. package/src/taskContinuation.ts +13 -0
  57. package/src/tokenTracker.js +406 -539
  58. package/src/tokenTracker.ts +569 -0
  59. package/src/toolPacks.d.ts +2 -0
  60. package/src/toolPacks.js +1 -1
  61. package/src/tools/argumentValidation.js +56 -0
  62. package/src/tools/argumentValidation.ts +50 -0
  63. package/src/tools/browserAutomator.js +2 -2
  64. package/src/tools/browserAutomator.ts +3 -2
  65. package/src/tools/deferredMcpSearch.js +188 -201
  66. package/src/tools/deferredMcpSearch.ts +250 -0
  67. package/src/tools/generateMediaViaApi.js +305 -331
  68. package/src/tools/generateMediaViaApi.ts +330 -0
  69. package/src/tools/historyPruner.js +5 -0
  70. package/src/tools/historyPruner.ts +5 -0
  71. package/src/tools/payloadSanitizer.js +92 -0
  72. package/src/tools/payloadSanitizer.ts +113 -0
  73. package/src/tools/registry.d.ts +1 -0
  74. package/src/tools/sysRun.js +47 -18
  75. package/src/tools/sysRun.ts +52 -20
  76. package/src/tools/toolOutputStore.js +180 -0
  77. package/src/tools/toolOutputStore.ts +209 -0
  78. package/src/tools/toolSelfRepair.js +26 -1
  79. package/src/tools/toolSelfRepair.ts +25 -1
  80. package/src/tui/chatRenderer.d.ts +1 -0
  81. package/src/tui/chatRenderer.js +4 -2
  82. package/src/tui/codeStreamRenderer.js +36 -8
  83. package/src/tui/codeStreamRenderer.ts +38 -8
  84. package/src/tui/stageSurface.js +1 -0
  85. package/src/tui/text.js +4 -1
  86. package/src/tokenTracker.d.ts +0 -1
@@ -0,0 +1,66 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { causyneHome } from '../utils/paths.js';
4
+ function sanitizeSubagentId(id) {
5
+ const cleaned = String(id || '').replace(/[^a-zA-Z0-9_-]/g, '_');
6
+ return cleaned.length > 0 ? cleaned.slice(0, 120) : 'subagent';
7
+ }
8
+ export class SidechainSubagentHarness {
9
+ spec;
10
+ sidechainLogPath;
11
+ constructor(spec, customStorageDir) {
12
+ this.spec = {
13
+ ...spec,
14
+ maxSteps: spec.maxSteps ?? 15,
15
+ tokenBudget: spec.tokenBudget ?? 60_000
16
+ };
17
+ const baseDir = customStorageDir ?? path.join(causyneHome(), 'sidechains');
18
+ fs.mkdirSync(baseDir, { recursive: true, mode: 0o700 });
19
+ const safeName = sanitizeSubagentId(spec.subagentId);
20
+ this.sidechainLogPath = path.join(baseDir, `${safeName}.jsonl`);
21
+ }
22
+ recordStep(stepData) {
23
+ const serialized = JSON.stringify({
24
+ timestamp: Date.now(),
25
+ subagentId: this.spec.subagentId,
26
+ ...stepData
27
+ }) + '\n';
28
+ fs.appendFileSync(this.sidechainLogPath, serialized, 'utf8');
29
+ }
30
+ readTranscript() {
31
+ if (!fs.existsSync(this.sidechainLogPath))
32
+ return [];
33
+ const lines = fs.readFileSync(this.sidechainLogPath, 'utf8').split('\n').filter(Boolean);
34
+ const parsed = [];
35
+ for (const line of lines) {
36
+ try {
37
+ parsed.push(JSON.parse(line));
38
+ }
39
+ catch {
40
+ // Skip corrupted line
41
+ }
42
+ }
43
+ return parsed;
44
+ }
45
+ formatSummaryForParent(summary) {
46
+ const files = summary.modifiedFiles.length > 0
47
+ ? summary.modifiedFiles.map(f => ` - \`${f}\``).join('\n')
48
+ : ' - None';
49
+ const observations = summary.verifiedObservations.length > 0
50
+ ? summary.verifiedObservations.map(o => ` - ${o}`).join('\n')
51
+ : ' - None';
52
+ const artifacts = summary.outputArtifacts.length > 0
53
+ ? summary.outputArtifacts.map(a => ` - \`${a}\``).join('\n')
54
+ : ' - None';
55
+ return [
56
+ `### Subagent [${this.spec.subagentId}] Execution Report`,
57
+ `- **Status:** ${summary.status}`,
58
+ `- **Total Steps:** ${summary.totalSteps} (Sidechain log: ${this.sidechainLogPath})`,
59
+ `- **Tokens Consumed:** ${summary.tokensConsumed.toLocaleString()}`,
60
+ `- **Modified Files:**\n${files}`,
61
+ `- **Key Verified Facts:**\n${observations}`,
62
+ `- **Output Artifacts:**\n${artifacts}`,
63
+ summary.error ? `- **Error Details:** ${summary.error}` : ''
64
+ ].filter(Boolean).join('\n');
65
+ }
66
+ }
@@ -0,0 +1,91 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { causyneHome } from '../utils/paths.js';
4
+
5
+ export interface SubagentTaskSpec {
6
+ subagentId: string;
7
+ parentSessionId: string;
8
+ goal: string;
9
+ allowedTools: string[];
10
+ maxSteps?: number; // Default: 15
11
+ tokenBudget?: number; // Default: 60,000
12
+ }
13
+
14
+ export interface SubagentExecutionSummary {
15
+ subagentId: string;
16
+ status: 'COMPLETED' | 'FAILED' | 'BUDGET_EXHAUSTED';
17
+ totalSteps: number;
18
+ tokensConsumed: number;
19
+ modifiedFiles: string[];
20
+ verifiedObservations: string[];
21
+ outputArtifacts: string[];
22
+ error?: string;
23
+ }
24
+
25
+ function sanitizeSubagentId(id: string): string {
26
+ const cleaned = String(id || '').replace(/[^a-zA-Z0-9_-]/g, '_');
27
+ return cleaned.length > 0 ? cleaned.slice(0, 120) : 'subagent';
28
+ }
29
+
30
+ export class SidechainSubagentHarness {
31
+ public readonly spec: SubagentTaskSpec;
32
+ public readonly sidechainLogPath: string;
33
+
34
+ constructor(spec: SubagentTaskSpec, customStorageDir?: string) {
35
+ this.spec = {
36
+ ...spec,
37
+ maxSteps: spec.maxSteps ?? 15,
38
+ tokenBudget: spec.tokenBudget ?? 60_000
39
+ };
40
+ const baseDir = customStorageDir ?? path.join(causyneHome(), 'sidechains');
41
+ fs.mkdirSync(baseDir, { recursive: true, mode: 0o700 });
42
+ const safeName = sanitizeSubagentId(spec.subagentId);
43
+ this.sidechainLogPath = path.join(baseDir, `${safeName}.jsonl`);
44
+ }
45
+
46
+ public recordStep(stepData: Record<string, unknown>): void {
47
+ const serialized = JSON.stringify({
48
+ timestamp: Date.now(),
49
+ subagentId: this.spec.subagentId,
50
+ ...stepData
51
+ }) + '\n';
52
+ fs.appendFileSync(this.sidechainLogPath, serialized, 'utf8');
53
+ }
54
+
55
+ public readTranscript(): Array<Record<string, unknown>> {
56
+ if (!fs.existsSync(this.sidechainLogPath)) return [];
57
+ const lines = fs.readFileSync(this.sidechainLogPath, 'utf8').split('\n').filter(Boolean);
58
+ const parsed: Array<Record<string, unknown>> = [];
59
+ for (const line of lines) {
60
+ try {
61
+ parsed.push(JSON.parse(line));
62
+ } catch {
63
+ // Skip corrupted line
64
+ }
65
+ }
66
+ return parsed;
67
+ }
68
+
69
+ public formatSummaryForParent(summary: SubagentExecutionSummary): string {
70
+ const files = summary.modifiedFiles.length > 0
71
+ ? summary.modifiedFiles.map(f => ` - \`${f}\``).join('\n')
72
+ : ' - None';
73
+ const observations = summary.verifiedObservations.length > 0
74
+ ? summary.verifiedObservations.map(o => ` - ${o}`).join('\n')
75
+ : ' - None';
76
+ const artifacts = summary.outputArtifacts.length > 0
77
+ ? summary.outputArtifacts.map(a => ` - \`${a}\``).join('\n')
78
+ : ' - None';
79
+
80
+ return [
81
+ `### Subagent [${this.spec.subagentId}] Execution Report`,
82
+ `- **Status:** ${summary.status}`,
83
+ `- **Total Steps:** ${summary.totalSteps} (Sidechain log: ${this.sidechainLogPath})`,
84
+ `- **Tokens Consumed:** ${summary.tokensConsumed.toLocaleString()}`,
85
+ `- **Modified Files:**\n${files}`,
86
+ `- **Key Verified Facts:**\n${observations}`,
87
+ `- **Output Artifacts:**\n${artifacts}`,
88
+ summary.error ? `- **Error Details:** ${summary.error}` : ''
89
+ ].filter(Boolean).join('\n');
90
+ }
91
+ }
@@ -0,0 +1,12 @@
1
+ /** Detect a peer's plan-review stop without turning a planning request into execution. */
2
+ export function isPlanReviewHandoff(content) {
3
+ return /\b(?:click|press|select)\s+["'`*]*(?:proceed|implement|approve)\b/i.test(content)
4
+ || /\b(?:review|approve)\b[\s\S]{0,100}\b(?:plan|implementation outline)\b/i.test(content)
5
+ || /\b(?:silakan tinjau|tinjau rencananya|klik\s+["'`*]*proceed)\b/i.test(content);
6
+ }
7
+ export function isPlanningOnlyRequest(prompt) {
8
+ return /\b(?:only|just)\s+(?:a\s+)?(?:plan|planning|research|analysis)\b/i.test(prompt)
9
+ || /\b(?:do not|don't|without)\s+(?:implement|code|edit|build|chang(?:e|ing))\b/i.test(prompt)
10
+ || /\b(?:plan|research|analy[sz]e)\s+(?:only|first)\b[\s\S]{0,80}\b(?:stop|wait|approval|review)\b/i.test(prompt)
11
+ || /\b(?:rencana saja|hanya rencana|jangan\s+(?:implementasi|eksekusi|mengubah))\b/i.test(prompt);
12
+ }
@@ -0,0 +1,13 @@
1
+ /** Detect a peer's plan-review stop without turning a planning request into execution. */
2
+ export function isPlanReviewHandoff(content: string): boolean {
3
+ return /\b(?:click|press|select)\s+["'`*]*(?:proceed|implement|approve)\b/i.test(content)
4
+ || /\b(?:review|approve)\b[\s\S]{0,100}\b(?:plan|implementation outline)\b/i.test(content)
5
+ || /\b(?:silakan tinjau|tinjau rencananya|klik\s+["'`*]*proceed)\b/i.test(content);
6
+ }
7
+
8
+ export function isPlanningOnlyRequest(prompt: string): boolean {
9
+ return /\b(?:only|just)\s+(?:a\s+)?(?:plan|planning|research|analysis)\b/i.test(prompt)
10
+ || /\b(?:do not|don't|without)\s+(?:implement|code|edit|build|chang(?:e|ing))\b/i.test(prompt)
11
+ || /\b(?:plan|research|analy[sz]e)\s+(?:only|first)\b[\s\S]{0,80}\b(?:stop|wait|approval|review)\b/i.test(prompt)
12
+ || /\b(?:rencana saja|hanya rencana|jangan\s+(?:implementasi|eksekusi|mengubah))\b/i.test(prompt);
13
+ }