@causyne/agent 1.20.120 → 1.20.122
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/README.md +3 -3
- package/package.json +1 -1
- package/src/acp/agentCatalog.js +81 -26
- package/src/acp/agentCatalog.ts +73 -29
- package/src/acp/client.js +210 -53
- package/src/acp/client.ts +202 -52
- package/src/acp/peerProfiles.js +55 -22
- package/src/acp/peerProfiles.ts +51 -22
- package/src/acp/protocol.js +37 -8
- package/src/acp/protocol.ts +30 -8
- package/src/acp/server.js +123 -25
- package/src/acp/server.ts +124 -24
- package/src/agent/errorClassifier.js +117 -0
- package/src/agent/errorClassifier.ts +165 -0
- package/src/agent/promptIntent.js +200 -0
- package/src/agent/promptIntent.ts +203 -0
- package/src/agent/toolArgValidator.js +97 -0
- package/src/agent/toolArgValidator.ts +112 -0
- package/src/agentLoop.js +33 -344
- package/src/agentLoop.ts +51 -352
- package/src/approvalGrants.js +19 -7
- package/src/approvalGrants.ts +20 -7
- package/src/approvalPolicy.js +48 -15
- package/src/approvalPolicy.ts +46 -15
- package/src/autoUpdate.js +116 -10
- package/src/autoUpdate.ts +149 -10
- package/src/browser/causyneBrowser.js +3 -2
- package/src/browser/causyneBrowser.ts +3 -2
- package/src/browser/searchProviders.js +1 -1
- package/src/browser/searchProviders.ts +1 -1
- package/src/cliMode.js +16 -2
- package/src/commands.js +10 -9
- package/src/config.js +288 -272
- package/src/config.ts +342 -0
- package/src/configVault.js +271 -0
- package/src/configVault.ts +273 -0
- package/src/continuum/compactor.js +2 -1
- package/src/continuum/compactor.ts +2 -1
- package/src/continuum/sanitizer.js +10 -3
- package/src/continuum/sanitizer.ts +9 -3
- package/src/continuum/ui/continuumPickerView.js +3 -2
- package/src/continuum/ui/continuumPickerView.ts +3 -2
- package/src/core/contextCompactor.js +70 -11
- package/src/core/contextCompactor.ts +83 -11
- package/src/cortex/vectorDb.js +26 -15
- package/src/cortex/vectorDb.ts +26 -16
- package/src/creative/liveBridge.js +7 -5
- package/src/creative/liveBridge.ts +7 -5
- package/src/creative/studioScripts.js +16 -5
- package/src/creative/studioScripts.ts +14 -5
- package/src/decisionPolicy.js +16 -4
- package/src/decisionPolicy.ts +14 -4
- package/src/documentEngine/antiSlopAuditor.js +10 -5
- package/src/documentEngine/antiSlopAuditor.ts +11 -5
- package/src/documentEngine/documentForge.js +47 -15
- package/src/documentEngine/documentForge.ts +43 -14
- package/src/dynamicCatalogue.js +42 -73
- package/src/dynamicCatalogue.ts +74 -60
- package/src/engines/design.js +2 -1
- package/src/engines/design.ts +2 -1
- package/src/engines/film.js +4 -4
- package/src/engines/film.ts +2 -2
- package/src/engines/light.js +2 -1
- package/src/engines/light.ts +2 -1
- package/src/engines/registry.js +1 -1
- package/src/engines/registry.ts +1 -1
- package/src/engines/reverseHarness.js +4 -3
- package/src/engines/reverseHarness.ts +4 -3
- package/src/entrypoint.js +77 -4
- package/src/headlessCli.js +305 -0
- package/src/headlessCli.ts +381 -0
- package/src/historyPruner.js +3 -2
- package/src/historyPruner.ts +3 -2
- package/src/hooks.js +3 -0
- package/src/hooks.ts +3 -0
- package/src/implementationPlan.js +21 -11
- package/src/implementationPlan.ts +21 -11
- package/src/infra/atomicWriter.js +4 -1
- package/src/infra/atomicWriter.ts +4 -1
- package/src/launchIntent.js +1 -1
- package/src/launchIntent.ts +1 -1
- package/src/mcp/mcpClient.js +38 -11
- package/src/mcp/mcpClient.ts +44 -11
- package/src/mcp/mcpRegistry.js +2 -5
- package/src/mcp/mcpRegistry.ts +2 -5
- package/src/mcp/mcpSecurity.js +189 -0
- package/src/mcp/mcpSecurity.ts +190 -0
- package/src/memory/scopedFacts.js +1 -1
- package/src/memory/scopedFacts.ts +1 -1
- package/src/memory/symbolFolder.js +1 -1
- package/src/memory/symbolFolder.ts +1 -1
- package/src/modelRouter.js +1 -1
- package/src/modelRouter.ts +1 -1
- package/src/observer/evidence.js +10 -4
- package/src/observer/evidence.ts +10 -4
- package/src/osKeychain.js +263 -0
- package/src/osKeychain.ts +287 -0
- package/src/perception.js +3 -2
- package/src/perception.ts +3 -2
- package/src/planCache.js +2 -2
- package/src/planCache.ts +2 -2
- package/src/pluginsFactory/pluginsFactory.js +19 -11
- package/src/pluginsFactory/pluginsFactory.ts +18 -11
- package/src/promptMentions.js +2 -2
- package/src/promptMentions.ts +2 -2
- package/src/providers/acp.js +1 -1
- package/src/providers/acp.ts +1 -1
- package/src/providers/anthropic.js +328 -385
- package/src/providers/anthropic.ts +386 -0
- package/src/providers/antigravity.js +10 -4
- package/src/providers/antigravity.ts +10 -4
- package/src/providers/base.js +221 -319
- package/src/providers/base.ts +340 -0
- package/src/providers/byokHttp.js +397 -0
- package/src/providers/byokHttp.ts +497 -0
- package/src/providers/byokStream.js +748 -0
- package/src/providers/byokStream.ts +863 -0
- package/src/providers/dashscope-byok.js +98 -81
- package/src/providers/dashscope-byok.ts +114 -0
- package/src/providers/deepseek.js +74 -64
- package/src/providers/deepseek.ts +99 -0
- package/src/providers/factory.js +35 -28
- package/src/providers/factory.ts +40 -0
- package/src/providers/gemini.js +229 -253
- package/src/providers/gemini.ts +261 -0
- package/src/providers/loopGuard.js +9 -5
- package/src/providers/loopGuard.ts +10 -5
- package/src/providers/moonshot.js +71 -64
- package/src/providers/moonshot.ts +93 -0
- package/src/providers/muse.js +82 -152
- package/src/providers/muse.ts +122 -0
- package/src/providers/ollama.js +116 -93
- package/src/providers/ollama.ts +135 -0
- package/src/providers/openai-compatible.js +114 -65
- package/src/providers/openai-compatible.ts +139 -0
- package/src/providers/openai.js +22 -15
- package/src/providers/openai.ts +30 -0
- package/src/providers/openrouter.js +194 -98
- package/src/providers/openrouter.ts +202 -97
- package/src/providers/pi.js +6 -0
- package/src/providers/pi.ts +6 -0
- package/src/providers/qwen-byok.js +97 -71
- package/src/providers/qwen-byok.ts +113 -0
- package/src/providers/toolContracts.js +40 -14
- package/src/providers/toolContracts.ts +35 -14
- package/src/providers/wireNormalizer.js +78 -11
- package/src/providers/wireNormalizer.ts +68 -12
- package/src/providers/xai.js +74 -64
- package/src/providers/xai.ts +97 -0
- package/src/reliability/assetEvidence.js +4 -2
- package/src/reliability/assetEvidence.ts +4 -2
- package/src/sandbox.js +486 -530
- package/src/sandbox.ts +552 -0
- package/src/sandboxPolicy.js +1287 -0
- package/src/sandboxPolicy.ts +1381 -0
- package/src/sessionJournal.js +55 -3
- package/src/sessionJournal.ts +58 -3
- package/src/skills/skillResourceSafety.js +19 -8
- package/src/skills/skillResourceSafety.ts +16 -7
- package/src/skillsManager.js +3 -3
- package/src/skillsManager.ts +3 -3
- package/src/smartToolsUse.js +28 -4
- package/src/smartToolsUse.ts +29 -7
- package/src/stallGuard.js +45 -22
- package/src/stallGuard.ts +46 -22
- package/src/subagentJournal.js +6 -4
- package/src/subagentJournal.ts +6 -4
- package/src/textDiff.js +6 -1
- package/src/textDiff.ts +6 -1
- package/src/timeMachine.js +7 -1
- package/src/timeMachine.ts +7 -1
- package/src/tokenTracker.js +43 -28
- package/src/tokenTracker.ts +44 -30
- package/src/toolPacks.js +3 -1
- package/src/toolPacks.ts +3 -1
- package/src/tools/archive.js +245 -35
- package/src/tools/archive.ts +244 -35
- package/src/tools/computerUse.js +7 -3
- package/src/tools/computerUse.ts +7 -3
- package/src/tools/creativeApps.js +13 -8
- package/src/tools/creativeApps.ts +22 -9
- package/src/tools/deferredMcpSearch.js +26 -14
- package/src/tools/deferredMcpSearch.ts +26 -14
- package/src/tools/desktopOpen.js +69 -10
- package/src/tools/desktopOpen.ts +70 -11
- package/src/tools/documentForge.js +167 -82
- package/src/tools/documentForge.ts +169 -84
- package/src/tools/fsEdit.js +101 -30
- package/src/tools/fsEdit.ts +105 -32
- package/src/tools/fsFind.js +8 -5
- package/src/tools/fsFind.ts +7 -4
- package/src/tools/fsRead.js +119 -13
- package/src/tools/fsRead.ts +124 -13
- package/src/tools/fsWrite.js +17 -5
- package/src/tools/fsWrite.ts +17 -7
- package/src/tools/generateMediaViaApi.js +82 -19
- package/src/tools/generateMediaViaApi.ts +80 -19
- package/src/tools/memoryRecall.js +62 -11
- package/src/tools/memoryRecall.ts +70 -13
- package/src/tools/memoryWrite.js +27 -14
- package/src/tools/memoryWrite.ts +30 -14
- package/src/tools/multiEdit.js +100 -30
- package/src/tools/multiEdit.ts +104 -32
- package/src/tools/nativeEngine.js +33 -18
- package/src/tools/nativeEngine.ts +31 -18
- package/src/tools/openSourceToolProvisioner.js +49 -14
- package/src/tools/openSourceToolProvisioner.ts +54 -15
- package/src/tools/osSandbox.js +513 -0
- package/src/tools/osSandbox.ts +588 -0
- package/src/tools/payloadSanitizer.js +40 -8
- package/src/tools/payloadSanitizer.ts +39 -8
- package/src/tools/peerAgent.js +96 -34
- package/src/tools/peerAgent.ts +114 -37
- package/src/tools/persistentShell.js +8 -3
- package/src/tools/pluginsFactory.js +38 -6
- package/src/tools/pluginsFactory.ts +42 -6
- package/src/tools/readNativeSkill.js +10 -8
- package/src/tools/readNativeSkill.ts +10 -8
- package/src/tools/requestDecision.js +10 -3
- package/src/tools/requestDecision.ts +10 -3
- package/src/tools/resolveAutomator.js +91 -17
- package/src/tools/resolveAutomator.ts +102 -17
- package/src/tools/reverseEngineering.js +168 -41
- package/src/tools/reverseEngineering.ts +161 -41
- package/src/tools/subprocessEnv.js +197 -0
- package/src/tools/subprocessEnv.ts +212 -0
- package/src/tools/sysRun.js +108 -35
- package/src/tools/sysRun.ts +119 -31
- package/src/tools/toolDispatch.js +24 -1
- package/src/tools/toolDispatch.ts +21 -1
- package/src/tools/toolOutputStore.js +62 -23
- package/src/tools/toolOutputStore.ts +56 -23
- package/src/tools/toolScanner.js +13 -10
- package/src/tools/toolScanner.ts +13 -10
- package/src/tools/toolSelfRepair.js +94 -28
- package/src/tools/toolSelfRepair.ts +96 -28
- package/src/tools/uiForge.js +71 -6
- package/src/tools/uiForge.ts +74 -6
- package/src/tools/viewImage.js +62 -17
- package/src/tools/viewImage.ts +57 -12
- package/src/tools/visionInspector.js +15 -3
- package/src/tools/visionInspector.ts +15 -3
- package/src/tools/walkerSafety.js +2 -0
- package/src/tools/walkerSafety.ts +1 -0
- package/src/tools/webFetch.js +105 -10
- package/src/tools/webFetch.ts +105 -11
- package/src/tui/banner.js +3 -2
- package/src/tui/banner.ts +3 -2
- package/src/tui/consoleGuard.js +12 -4
- package/src/tui/consoleGuard.ts +9 -4
- package/src/tui/messageInteraction.js +2 -3
- package/src/tui/messageInteraction.ts +2 -3
- package/src/tui/modelPicker.js +1 -0
- package/src/tui/modelPicker.ts +1 -0
- package/src/tui/overlay.js +3 -1
- package/src/tui/overlay.ts +3 -1
- package/src/tui/sessionPicker.js +3 -2
- package/src/tui/sessionPicker.ts +3 -2
- package/src/tui/sessionPickerView.js +7 -1
- package/src/tui/sessionPickerView.ts +6 -1
- package/src/tui/toolOutputNormalizer.js +2 -3
- package/src/tui/toolOutputNormalizer.ts +4 -3
- package/src/tui/viewport.js +4 -4
- package/src/tui/viewport.ts +5 -5
- package/src/tui/workspaceIdentity.js +2 -1
- package/src/tui/workspaceIdentity.ts +2 -1
- package/src/uncertainty.js +8 -3
- package/src/uncertainty.ts +8 -3
- package/src/utils/paths.js +8 -5
- package/src/utils/paths.ts +9 -7
- package/src/vfeTracker.js +9 -3
- package/src/vfeTracker.ts +9 -3
- package/src/config.d.ts +0 -2
- package/src/providers/base.d.ts +0 -94
- package/src/providers/factory.d.ts +0 -1
- package/src/sandbox.d.ts +0 -1
package/src/engines/design.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import os from 'node:os';
|
|
1
2
|
import path from 'node:path';
|
|
2
3
|
import type {
|
|
3
4
|
NativeEngineAction,
|
|
@@ -69,7 +70,7 @@ export const designEngine: NativeEngineAdapter = {
|
|
|
69
70
|
case 'inspect':
|
|
70
71
|
case 'probe': {
|
|
71
72
|
const file = request.action === 'inspect' ? requireProject(context, 'inspect') : positional(request.query ?? '');
|
|
72
|
-
args = ['run', '--in', file, '--export',
|
|
73
|
+
args = ['run', '--in', file, '--export', os.devNull];
|
|
73
74
|
break;
|
|
74
75
|
}
|
|
75
76
|
case 'execute':
|
package/src/engines/film.js
CHANGED
|
@@ -94,10 +94,10 @@ export const filmEngine = {
|
|
|
94
94
|
break;
|
|
95
95
|
}
|
|
96
96
|
args.push('--compact');
|
|
97
|
-
if (
|
|
98
|
-
artifacts
|
|
99
|
-
else if (
|
|
100
|
-
artifacts
|
|
97
|
+
if (context.saveAs)
|
|
98
|
+
artifacts.push(context.saveAs);
|
|
99
|
+
else if (context.save && context.project)
|
|
100
|
+
artifacts.push(context.project);
|
|
101
101
|
return {
|
|
102
102
|
args,
|
|
103
103
|
...(stdin === undefined ? {} : { stdin }),
|
package/src/engines/film.ts
CHANGED
|
@@ -91,8 +91,8 @@ export const filmEngine: NativeEngineAdapter = {
|
|
|
91
91
|
}
|
|
92
92
|
|
|
93
93
|
args.push('--compact');
|
|
94
|
-
if (
|
|
95
|
-
else if (
|
|
94
|
+
if (context.saveAs) artifacts.push(context.saveAs);
|
|
95
|
+
else if (context.save && context.project) artifacts.push(context.project);
|
|
96
96
|
|
|
97
97
|
return {
|
|
98
98
|
args,
|
package/src/engines/light.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import os from 'node:os';
|
|
1
2
|
import path from 'node:path';
|
|
2
3
|
// RAW photo development, color grading, HDR merge, and tone-mapping engine for Causyne Agent.
|
|
3
4
|
// Headless RAW pipeline, non-destructive develop adjustments, and photo library automation.
|
|
@@ -56,7 +57,7 @@ export const lightEngine = {
|
|
|
56
57
|
case 'inspect':
|
|
57
58
|
case 'probe': {
|
|
58
59
|
const file = request.action === 'inspect' ? requireProject(context, 'inspect') : positional(request.query ?? '');
|
|
59
|
-
args = ['render', file, '-o',
|
|
60
|
+
args = ['render', file, '-o', os.devNull];
|
|
60
61
|
break;
|
|
61
62
|
}
|
|
62
63
|
case 'execute':
|
package/src/engines/light.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import os from 'node:os';
|
|
1
2
|
import path from 'node:path';
|
|
2
3
|
import type {
|
|
3
4
|
NativeEngineAction,
|
|
@@ -69,7 +70,7 @@ export const lightEngine: NativeEngineAdapter = {
|
|
|
69
70
|
case 'inspect':
|
|
70
71
|
case 'probe': {
|
|
71
72
|
const file = request.action === 'inspect' ? requireProject(context, 'inspect') : positional(request.query ?? '');
|
|
72
|
-
args = ['render', file, '-o',
|
|
73
|
+
args = ['render', file, '-o', os.devNull];
|
|
73
74
|
break;
|
|
74
75
|
}
|
|
75
76
|
case 'execute':
|
package/src/engines/registry.js
CHANGED
|
@@ -29,7 +29,7 @@ export const NATIVE_ENGINES = {
|
|
|
29
29
|
[effectEngine.id]: effectEngine
|
|
30
30
|
};
|
|
31
31
|
export function nativeEngine(id) {
|
|
32
|
-
return NATIVE_ENGINES[id]
|
|
32
|
+
return Object.hasOwn(NATIVE_ENGINES, id) ? NATIVE_ENGINES[id] : null;
|
|
33
33
|
}
|
|
34
34
|
export function engineInstallDir(adapter) {
|
|
35
35
|
return path.join(causyneHome(), 'engines', adapter.id);
|
package/src/engines/registry.ts
CHANGED
|
@@ -33,7 +33,7 @@ export const NATIVE_ENGINES: Record<string, NativeEngineAdapter> = {
|
|
|
33
33
|
};
|
|
34
34
|
|
|
35
35
|
export function nativeEngine(id: string): NativeEngineAdapter | null {
|
|
36
|
-
return NATIVE_ENGINES[id]
|
|
36
|
+
return Object.hasOwn(NATIVE_ENGINES, id) ? NATIVE_ENGINES[id]! : null;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
export function engineInstallDir(adapter: NativeEngineAdapter): string {
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
// Encapsulates on-demand process lifecycle, error containment, execution timeouts,
|
|
7
7
|
// and graceful fallback mechanisms to guarantee zero crashes on Causyne host processes.
|
|
8
8
|
import fs from 'node:fs';
|
|
9
|
+
import os from 'node:os';
|
|
9
10
|
import path from 'node:path';
|
|
10
11
|
import { McpClient } from '../mcp/mcpClient.js';
|
|
11
12
|
import { resolveUserPath } from '../utils/paths.js';
|
|
@@ -51,8 +52,9 @@ export class SovereignReverseHarness {
|
|
|
51
52
|
// 1. Locate local rea binary if installed (sub-second launch, zero network lag)
|
|
52
53
|
let command = 'npx';
|
|
53
54
|
let args = ['--yes', 'rea-agents@6.8.0', '--mcp'];
|
|
55
|
+
const homeDir = os.homedir();
|
|
54
56
|
const candidatePaths = [
|
|
55
|
-
path.join(
|
|
57
|
+
path.join(homeDir, '.local', 'bin', 'rea'),
|
|
56
58
|
'/usr/local/bin/rea',
|
|
57
59
|
'/opt/homebrew/bin/rea'
|
|
58
60
|
];
|
|
@@ -64,7 +66,6 @@ export class SovereignReverseHarness {
|
|
|
64
66
|
}
|
|
65
67
|
}
|
|
66
68
|
const nodeDir = path.dirname(process.execPath);
|
|
67
|
-
const homeDir = process.env.HOME || '';
|
|
68
69
|
const buildToolsDirs = [
|
|
69
70
|
path.join(homeDir, 'Library/Android/sdk/build-tools/36.1.0'),
|
|
70
71
|
path.join(homeDir, 'Library/Android/sdk/build-tools/35.0.0'),
|
|
@@ -72,7 +73,7 @@ export class SovereignReverseHarness {
|
|
|
72
73
|
'/opt/homebrew/bin',
|
|
73
74
|
'/usr/local/bin'
|
|
74
75
|
].filter(d => fs.existsSync(d));
|
|
75
|
-
const augmentedPath = [nodeDir, ...buildToolsDirs, process.env.PATH || ''].join(
|
|
76
|
+
const augmentedPath = [nodeDir, ...buildToolsDirs, process.env.PATH || ''].filter(Boolean).join(path.delimiter);
|
|
76
77
|
const mcpClient = new McpClient({
|
|
77
78
|
name: 'causyne_reverse_engineering',
|
|
78
79
|
command,
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
// and graceful fallback mechanisms to guarantee zero crashes on Causyne host processes.
|
|
8
8
|
|
|
9
9
|
import fs from 'node:fs';
|
|
10
|
+
import os from 'node:os';
|
|
10
11
|
import path from 'node:path';
|
|
11
12
|
import { McpClient, type McpToolCallResult } from '../mcp/mcpClient.js';
|
|
12
13
|
import { resolveUserPath } from '../utils/paths.js';
|
|
@@ -66,8 +67,9 @@ export class SovereignReverseHarness {
|
|
|
66
67
|
let command = 'npx';
|
|
67
68
|
let args = ['--yes', 'rea-agents@6.8.0', '--mcp'];
|
|
68
69
|
|
|
70
|
+
const homeDir = os.homedir();
|
|
69
71
|
const candidatePaths = [
|
|
70
|
-
path.join(
|
|
72
|
+
path.join(homeDir, '.local', 'bin', 'rea'),
|
|
71
73
|
'/usr/local/bin/rea',
|
|
72
74
|
'/opt/homebrew/bin/rea'
|
|
73
75
|
];
|
|
@@ -81,7 +83,6 @@ export class SovereignReverseHarness {
|
|
|
81
83
|
}
|
|
82
84
|
|
|
83
85
|
const nodeDir = path.dirname(process.execPath);
|
|
84
|
-
const homeDir = process.env.HOME || '';
|
|
85
86
|
const buildToolsDirs = [
|
|
86
87
|
path.join(homeDir, 'Library/Android/sdk/build-tools/36.1.0'),
|
|
87
88
|
path.join(homeDir, 'Library/Android/sdk/build-tools/35.0.0'),
|
|
@@ -90,7 +91,7 @@ export class SovereignReverseHarness {
|
|
|
90
91
|
'/usr/local/bin'
|
|
91
92
|
].filter(d => fs.existsSync(d));
|
|
92
93
|
|
|
93
|
-
const augmentedPath = [nodeDir, ...buildToolsDirs, process.env.PATH || ''].join(
|
|
94
|
+
const augmentedPath = [nodeDir, ...buildToolsDirs, process.env.PATH || ''].filter(Boolean).join(path.delimiter);
|
|
94
95
|
|
|
95
96
|
const mcpClient = new McpClient({
|
|
96
97
|
name: 'causyne_reverse_engineering',
|
package/src/entrypoint.js
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import { program } from 'commander';
|
|
2
2
|
|
|
3
3
|
import { runTask, chatMode, execCommand, interactiveConfig } from './cliMode.js';
|
|
4
|
+
import {
|
|
5
|
+
runHeadlessTask,
|
|
6
|
+
composeHeadlessPrompt,
|
|
7
|
+
readBoundedStdin,
|
|
8
|
+
parseOutputFormat,
|
|
9
|
+
parsePermissionMode,
|
|
10
|
+
parseMaxTurns
|
|
11
|
+
} from './headlessCli.js';
|
|
4
12
|
import { runLicenseCommand } from './licensing/entitlements.js';
|
|
5
13
|
import { runSelfUpdate, diagnoseInstallation, formatDoctorReport } from './autoUpdate.js';
|
|
6
14
|
import { printContextReport, printUsageReport, printCheckpoints, printUndo, buildStatusText, printReport } from './reporting.js';
|
|
@@ -67,7 +75,43 @@ program
|
|
|
67
75
|
.name('causyne')
|
|
68
76
|
.description('Causyne — Local desktop AI harness (alias: causyne-agent)')
|
|
69
77
|
.option('-C, --cwd <directory>', 'Use this directory as the workspace')
|
|
70
|
-
.
|
|
78
|
+
.option('-p, --print [prompt]', 'Run a single non-interactive prompt and print the response')
|
|
79
|
+
.option('--output-format <format>', 'Output format for headless runs: text, json, stream-json')
|
|
80
|
+
.option('-m, --model <name>', 'Override model for this run without modifying saved config')
|
|
81
|
+
.option('--provider <name>', 'Override provider for this run without modifying saved config')
|
|
82
|
+
.option('--max-turns <count>', 'Maximum agent turns/steps for this run')
|
|
83
|
+
.option('--permission-mode <mode>', 'Autonomy mode override for this run (A, B, or C)')
|
|
84
|
+
.version(pkgVersion)
|
|
85
|
+
.action(async (options) => {
|
|
86
|
+
if (options.print === undefined && !options.outputFormat) {
|
|
87
|
+
if (program.args.length > 0) {
|
|
88
|
+
console.error('Invalid command: %s\nSee --help for a list of available commands.', program.args.join(' '));
|
|
89
|
+
process.exit(1);
|
|
90
|
+
}
|
|
91
|
+
program.outputHelp();
|
|
92
|
+
process.exit(0);
|
|
93
|
+
}
|
|
94
|
+
try {
|
|
95
|
+
parseOutputFormat(options.outputFormat);
|
|
96
|
+
parsePermissionMode(options.permissionMode);
|
|
97
|
+
parseMaxTurns(options.maxTurns);
|
|
98
|
+
const stdinText = await readBoundedStdin(process.stdin);
|
|
99
|
+
const trailing = program.args.length > 0 && typeof options.print === 'boolean'
|
|
100
|
+
? program.args.join(' ')
|
|
101
|
+
: options.print;
|
|
102
|
+
const prompt = composeHeadlessPrompt(trailing, stdinText);
|
|
103
|
+
await runHeadlessTask(prompt, {
|
|
104
|
+
outputFormat: options.outputFormat || 'text',
|
|
105
|
+
model: options.model,
|
|
106
|
+
provider: options.provider,
|
|
107
|
+
maxTurns: options.maxTurns,
|
|
108
|
+
permissionMode: options.permissionMode
|
|
109
|
+
});
|
|
110
|
+
} catch (err) {
|
|
111
|
+
console.error(err instanceof Error ? err.message : String(err));
|
|
112
|
+
process.exit(2);
|
|
113
|
+
}
|
|
114
|
+
});
|
|
71
115
|
|
|
72
116
|
program
|
|
73
117
|
.command('update')
|
|
@@ -101,12 +145,41 @@ program
|
|
|
101
145
|
});
|
|
102
146
|
|
|
103
147
|
program
|
|
104
|
-
.command('run
|
|
105
|
-
.description('Run a single task directly from the CLI')
|
|
148
|
+
.command('run [task]')
|
|
149
|
+
.description('Run a single task directly from the CLI (supports piped stdin and --output-format)')
|
|
106
150
|
.option('--dev-emulator', 'Retired compatibility flag; grants no additional permissions')
|
|
151
|
+
.option('--output-format <format>', 'Output format: text, json, stream-json')
|
|
152
|
+
.option('-m, --model <name>', 'Override model for this run without modifying saved config')
|
|
153
|
+
.option('--provider <name>', 'Override provider for this run without modifying saved config')
|
|
154
|
+
.option('--max-turns <count>', 'Maximum agent turns/steps for this run')
|
|
155
|
+
.option('--permission-mode <mode>', 'Autonomy mode override for this run (A, B, or C)')
|
|
107
156
|
.action(async (task, options) => {
|
|
108
157
|
announceDevEmulator(options.devEmulator);
|
|
109
|
-
|
|
158
|
+
try {
|
|
159
|
+
if (options.outputFormat) parseOutputFormat(options.outputFormat);
|
|
160
|
+
parsePermissionMode(options.permissionMode);
|
|
161
|
+
parseMaxTurns(options.maxTurns);
|
|
162
|
+
const stdinText = await readBoundedStdin(process.stdin);
|
|
163
|
+
const prompt = composeHeadlessPrompt(task, stdinText);
|
|
164
|
+
if (!prompt) {
|
|
165
|
+
console.error('No task provided. Pass a task argument or pipe input on stdin.');
|
|
166
|
+
process.exit(2);
|
|
167
|
+
}
|
|
168
|
+
if (options.outputFormat || task === '-' || !task) {
|
|
169
|
+
await runHeadlessTask(prompt, {
|
|
170
|
+
outputFormat: options.outputFormat || 'text',
|
|
171
|
+
model: options.model,
|
|
172
|
+
provider: options.provider,
|
|
173
|
+
maxTurns: options.maxTurns,
|
|
174
|
+
permissionMode: options.permissionMode
|
|
175
|
+
});
|
|
176
|
+
} else {
|
|
177
|
+
await runTask(prompt, options);
|
|
178
|
+
}
|
|
179
|
+
} catch (err) {
|
|
180
|
+
console.error(err instanceof Error ? err.message : String(err));
|
|
181
|
+
process.exit(2);
|
|
182
|
+
}
|
|
110
183
|
});
|
|
111
184
|
|
|
112
185
|
program
|
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Causyne Agent — Headless / CI Automation CLI Runner
|
|
3
|
+
*
|
|
4
|
+
* Provides non-interactive single-task execution (`-p/--print`, `run`),
|
|
5
|
+
* bounded stdin piping, per-invocation overrides (`--model`, `--provider`,
|
|
6
|
+
* `--max-turns`, `--permission-mode`) without mutating saved config, and
|
|
7
|
+
* machine-readable output formats (`text`, `json`, `stream-json`).
|
|
8
|
+
*/
|
|
9
|
+
import { AgentLoop } from './agentLoop.js';
|
|
10
|
+
import { safeDisplay } from './tui/text.js';
|
|
11
|
+
export const MAX_STDIN_PROMPT_BYTES = 1_048_576;
|
|
12
|
+
export const MAX_HEADLESS_TURNS = 500;
|
|
13
|
+
export function parseOutputFormat(raw) {
|
|
14
|
+
if (raw === undefined || raw === null || raw === '')
|
|
15
|
+
return 'text';
|
|
16
|
+
const normalized = String(raw).trim().toLowerCase();
|
|
17
|
+
if (normalized === 'text' || normalized === 'json' || normalized === 'stream-json') {
|
|
18
|
+
return normalized;
|
|
19
|
+
}
|
|
20
|
+
throw new Error(`Invalid --output-format "${raw}". Expected one of: text, json, stream-json.`);
|
|
21
|
+
}
|
|
22
|
+
export function parsePermissionMode(raw) {
|
|
23
|
+
if (raw === undefined || raw === null || raw === '')
|
|
24
|
+
return undefined;
|
|
25
|
+
const normalized = String(raw).trim().toUpperCase();
|
|
26
|
+
if (normalized === 'A' || normalized === 'SUPERVISED' || normalized === 'STRICT')
|
|
27
|
+
return 'A';
|
|
28
|
+
if (normalized === 'B' || normalized === 'BALANCED' || normalized === 'DEFAULT')
|
|
29
|
+
return 'B';
|
|
30
|
+
if (normalized === 'C' || normalized === 'AUTONOMOUS' || normalized === 'AUTO')
|
|
31
|
+
return 'C';
|
|
32
|
+
throw new Error(`Invalid --permission-mode "${raw}". Expected A (supervised), B (balanced), or C (autonomous).`);
|
|
33
|
+
}
|
|
34
|
+
export function parseMaxTurns(raw) {
|
|
35
|
+
if (raw === undefined || raw === null || raw === '')
|
|
36
|
+
return undefined;
|
|
37
|
+
const trimmed = String(raw).trim();
|
|
38
|
+
const parsed = typeof raw === 'number' ? raw : (/^\d+$/.test(trimmed) ? Number(trimmed) : Number.NaN);
|
|
39
|
+
if (!Number.isInteger(parsed) || parsed < 1 || parsed > MAX_HEADLESS_TURNS) {
|
|
40
|
+
throw new Error(`Invalid --max-turns "${raw}". Expected an integer between 1 and ${MAX_HEADLESS_TURNS}.`);
|
|
41
|
+
}
|
|
42
|
+
return parsed;
|
|
43
|
+
}
|
|
44
|
+
export function composeHeadlessPrompt(promptArg, stdinText) {
|
|
45
|
+
const cleanStdin = stdinText.trim();
|
|
46
|
+
const rawPrompt = typeof promptArg === 'string' ? promptArg.trim() : '';
|
|
47
|
+
const effectivePrompt = rawPrompt === '-' ? '' : rawPrompt;
|
|
48
|
+
if (effectivePrompt && cleanStdin) {
|
|
49
|
+
return `${effectivePrompt}\n\n<stdin>\n${cleanStdin}\n</stdin>`;
|
|
50
|
+
}
|
|
51
|
+
if (effectivePrompt)
|
|
52
|
+
return effectivePrompt;
|
|
53
|
+
if (cleanStdin)
|
|
54
|
+
return cleanStdin;
|
|
55
|
+
return '';
|
|
56
|
+
}
|
|
57
|
+
export async function readBoundedStdin(stream = process.stdin, maxBytes = MAX_STDIN_PROMPT_BYTES) {
|
|
58
|
+
if (!stream || stream.isTTY)
|
|
59
|
+
return '';
|
|
60
|
+
return await new Promise((resolve, reject) => {
|
|
61
|
+
const chunks = [];
|
|
62
|
+
let totalBytes = 0;
|
|
63
|
+
let truncated = false;
|
|
64
|
+
const onData = (chunk) => {
|
|
65
|
+
const buf = Buffer.isBuffer(chunk) ? chunk : Buffer.from(String(chunk), 'utf8');
|
|
66
|
+
if (truncated)
|
|
67
|
+
return;
|
|
68
|
+
const remaining = maxBytes - totalBytes;
|
|
69
|
+
if (buf.length <= remaining) {
|
|
70
|
+
chunks.push(buf);
|
|
71
|
+
totalBytes += buf.length;
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
if (remaining > 0)
|
|
75
|
+
chunks.push(buf.subarray(0, remaining));
|
|
76
|
+
totalBytes = maxBytes;
|
|
77
|
+
truncated = true;
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
const cleanup = () => {
|
|
81
|
+
stream.removeListener('data', onData);
|
|
82
|
+
stream.removeListener('end', onEnd);
|
|
83
|
+
stream.removeListener('error', onError);
|
|
84
|
+
};
|
|
85
|
+
const onEnd = () => {
|
|
86
|
+
cleanup();
|
|
87
|
+
const text = Buffer.concat(chunks).toString('utf8');
|
|
88
|
+
resolve(truncated ? `${text}\n\n[stdin truncated at ${maxBytes} bytes]` : text);
|
|
89
|
+
};
|
|
90
|
+
const onError = (err) => {
|
|
91
|
+
cleanup();
|
|
92
|
+
reject(err);
|
|
93
|
+
};
|
|
94
|
+
stream.on('data', onData);
|
|
95
|
+
stream.on('end', onEnd);
|
|
96
|
+
stream.on('error', onError);
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
function isRecord(value) {
|
|
100
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
101
|
+
}
|
|
102
|
+
export class HeadlessEventSink {
|
|
103
|
+
readyState = 1;
|
|
104
|
+
response = '';
|
|
105
|
+
errors = [];
|
|
106
|
+
toolCalls = [];
|
|
107
|
+
usage = null;
|
|
108
|
+
format;
|
|
109
|
+
stdout;
|
|
110
|
+
streamedPrefix = '';
|
|
111
|
+
constructor(format, stdout = process.stdout) {
|
|
112
|
+
this.format = format;
|
|
113
|
+
this.stdout = stdout;
|
|
114
|
+
}
|
|
115
|
+
emitStreamLine(payload) {
|
|
116
|
+
if (this.format !== 'stream-json')
|
|
117
|
+
return;
|
|
118
|
+
this.stdout.write(`${JSON.stringify(payload)}\n`);
|
|
119
|
+
}
|
|
120
|
+
send(data) {
|
|
121
|
+
let parsed;
|
|
122
|
+
try {
|
|
123
|
+
parsed = JSON.parse(data);
|
|
124
|
+
}
|
|
125
|
+
catch {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
if (!isRecord(parsed) || typeof parsed.type !== 'string')
|
|
129
|
+
return;
|
|
130
|
+
const type = parsed.type;
|
|
131
|
+
if (type === 'agent_message') {
|
|
132
|
+
const content = typeof parsed.content === 'string' ? safeDisplay(parsed.content) : '';
|
|
133
|
+
const streaming = Boolean(parsed.streaming);
|
|
134
|
+
if (streaming) {
|
|
135
|
+
const delta = content.startsWith(this.streamedPrefix)
|
|
136
|
+
? content.slice(this.streamedPrefix.length)
|
|
137
|
+
: content;
|
|
138
|
+
this.streamedPrefix = content;
|
|
139
|
+
this.response = content;
|
|
140
|
+
if (delta) {
|
|
141
|
+
this.emitStreamLine({ type: 'delta', text: delta });
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
this.streamedPrefix = '';
|
|
146
|
+
if (content) {
|
|
147
|
+
this.response = content;
|
|
148
|
+
this.emitStreamLine({ type: 'message', role: 'assistant', text: content });
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
if (type === 'step_start') {
|
|
154
|
+
const tool = typeof parsed.tool === 'string' ? safeDisplay(parsed.tool) : 'tool';
|
|
155
|
+
this.toolCalls.push({ tool, status: 'started' });
|
|
156
|
+
this.emitStreamLine({ type: 'tool_call', tool });
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
if (type === 'step_complete') {
|
|
160
|
+
const tool = typeof parsed.tool === 'string' ? safeDisplay(parsed.tool) : 'tool';
|
|
161
|
+
const last = [...this.toolCalls].reverse().find(entry => entry.tool === tool && entry.status === 'started');
|
|
162
|
+
if (last)
|
|
163
|
+
last.status = 'completed';
|
|
164
|
+
else
|
|
165
|
+
this.toolCalls.push({ tool, status: 'completed' });
|
|
166
|
+
this.emitStreamLine({ type: 'tool_result', tool, ok: true });
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
if (type === 'step_error') {
|
|
170
|
+
const tool = typeof parsed.tool === 'string' ? safeDisplay(parsed.tool) : 'tool';
|
|
171
|
+
const errText = typeof parsed.error === 'string' ? safeDisplay(parsed.error) : 'Tool failed';
|
|
172
|
+
const last = [...this.toolCalls].reverse().find(entry => entry.tool === tool && entry.status === 'started');
|
|
173
|
+
if (last) {
|
|
174
|
+
last.status = 'error';
|
|
175
|
+
last.error = errText;
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
this.toolCalls.push({ tool, status: 'error', error: errText });
|
|
179
|
+
}
|
|
180
|
+
this.emitStreamLine({ type: 'tool_result', tool, ok: false, error: errText });
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
if (type === 'error') {
|
|
184
|
+
const message = typeof parsed.message === 'string' ? safeDisplay(parsed.message) : 'Unknown error';
|
|
185
|
+
this.errors.push(message);
|
|
186
|
+
this.emitStreamLine({ type: 'error', message });
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
if (type === 'usage_update') {
|
|
190
|
+
const summary = {};
|
|
191
|
+
if (typeof parsed.inputTokens === 'number')
|
|
192
|
+
summary.inputTokens = parsed.inputTokens;
|
|
193
|
+
if (typeof parsed.outputTokens === 'number')
|
|
194
|
+
summary.outputTokens = parsed.outputTokens;
|
|
195
|
+
if (typeof parsed.totalTokens === 'number')
|
|
196
|
+
summary.totalTokens = parsed.totalTokens;
|
|
197
|
+
if (typeof parsed.estimatedCostUsd === 'number')
|
|
198
|
+
summary.estimatedCostUsd = parsed.estimatedCostUsd;
|
|
199
|
+
if (Object.keys(summary).length > 0) {
|
|
200
|
+
this.usage = summary;
|
|
201
|
+
this.emitStreamLine({ type: 'usage', ...summary });
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
export async function runHeadlessTask(taskPrompt, options = {}) {
|
|
207
|
+
const startedAt = Date.now();
|
|
208
|
+
const format = parseOutputFormat(options.outputFormat);
|
|
209
|
+
const permissionMode = parsePermissionMode(options.permissionMode);
|
|
210
|
+
const maxTurns = parseMaxTurns(options.maxTurns);
|
|
211
|
+
const stdout = options.stdout ?? process.stdout;
|
|
212
|
+
const stderr = options.stderr ?? process.stderr;
|
|
213
|
+
const cleanPrompt = String(taskPrompt ?? '').trim();
|
|
214
|
+
const taskId = `cli_headless_${startedAt}`;
|
|
215
|
+
const sink = new HeadlessEventSink(format, stdout);
|
|
216
|
+
if (!cleanPrompt) {
|
|
217
|
+
const emptyResult = {
|
|
218
|
+
ok: false,
|
|
219
|
+
status: 'error',
|
|
220
|
+
taskId,
|
|
221
|
+
sessionId: null,
|
|
222
|
+
provider: '',
|
|
223
|
+
model: '',
|
|
224
|
+
response: '',
|
|
225
|
+
error: 'No prompt provided. Pass a prompt argument or pipe input on stdin.',
|
|
226
|
+
steps: 0,
|
|
227
|
+
toolCalls: [],
|
|
228
|
+
usage: null,
|
|
229
|
+
durationMs: Date.now() - startedAt
|
|
230
|
+
};
|
|
231
|
+
if (format === 'json' || format === 'stream-json') {
|
|
232
|
+
stdout.write(`${JSON.stringify(format === 'stream-json' ? { type: 'result', ...emptyResult } : emptyResult)}\n`);
|
|
233
|
+
}
|
|
234
|
+
else {
|
|
235
|
+
stderr.write(`${emptyResult.error}\n`);
|
|
236
|
+
}
|
|
237
|
+
process.exitCode = 2;
|
|
238
|
+
return emptyResult;
|
|
239
|
+
}
|
|
240
|
+
const loop = options.loopFactory
|
|
241
|
+
? options.loopFactory(sink, taskId, cleanPrompt)
|
|
242
|
+
: new AgentLoop(sink, taskId, cleanPrompt, {
|
|
243
|
+
...(options.workspaceRoot ? { workspaceRoot: options.workspaceRoot } : {}),
|
|
244
|
+
...(options.provider ? { provider: options.provider } : {}),
|
|
245
|
+
...(options.model ? { model: options.model } : {})
|
|
246
|
+
});
|
|
247
|
+
if (permissionMode)
|
|
248
|
+
loop.autonomyOverride = permissionMode;
|
|
249
|
+
if (options.provider)
|
|
250
|
+
loop.providerOverride = options.provider;
|
|
251
|
+
if (options.model)
|
|
252
|
+
loop.modelOverride = options.model;
|
|
253
|
+
if (maxTurns !== undefined)
|
|
254
|
+
loop.maxStepsCeiling = maxTurns;
|
|
255
|
+
// Non-interactive approval boundary: never hang waiting for a TTY prompt.
|
|
256
|
+
loop.waitForApproval = async () => false;
|
|
257
|
+
loop.waitForDecision = async () => null;
|
|
258
|
+
if (format === 'stream-json') {
|
|
259
|
+
stdout.write(`${JSON.stringify({
|
|
260
|
+
type: 'start',
|
|
261
|
+
taskId,
|
|
262
|
+
provider: options.provider || loop.config?.provider || '',
|
|
263
|
+
model: options.model || loop.config?.model || ''
|
|
264
|
+
})}\n`);
|
|
265
|
+
}
|
|
266
|
+
let fatalError = null;
|
|
267
|
+
try {
|
|
268
|
+
await loop.run();
|
|
269
|
+
}
|
|
270
|
+
catch (err) {
|
|
271
|
+
fatalError = safeDisplay(err instanceof Error ? err.message : String(err));
|
|
272
|
+
}
|
|
273
|
+
const completed = fatalError === null && loop._causyneTaskOutcome === 'completed';
|
|
274
|
+
const lastError = fatalError ?? (sink.errors.length > 0 ? sink.errors[sink.errors.length - 1] ?? null : null);
|
|
275
|
+
const result = {
|
|
276
|
+
ok: completed,
|
|
277
|
+
status: fatalError ? 'error' : (completed ? 'completed' : 'incomplete'),
|
|
278
|
+
taskId,
|
|
279
|
+
sessionId: loop.memoryManager?.sessionId ?? null,
|
|
280
|
+
provider: String(options.provider || loop.config?.provider || ''),
|
|
281
|
+
model: String(options.model || loop.config?.model || ''),
|
|
282
|
+
response: sink.response,
|
|
283
|
+
error: completed ? null : (lastError || 'No verified task completion was recorded.'),
|
|
284
|
+
steps: typeof loop.stepsCompleted === 'number' ? loop.stepsCompleted : 0,
|
|
285
|
+
toolCalls: sink.toolCalls,
|
|
286
|
+
usage: sink.usage,
|
|
287
|
+
durationMs: Date.now() - startedAt
|
|
288
|
+
};
|
|
289
|
+
if (format === 'json') {
|
|
290
|
+
stdout.write(`${JSON.stringify(result, null, 2)}\n`);
|
|
291
|
+
}
|
|
292
|
+
else if (format === 'stream-json') {
|
|
293
|
+
stdout.write(`${JSON.stringify({ type: 'result', ...result })}\n`);
|
|
294
|
+
}
|
|
295
|
+
else {
|
|
296
|
+
if (result.response) {
|
|
297
|
+
stdout.write(result.response.endsWith('\n') ? result.response : `${result.response}\n`);
|
|
298
|
+
}
|
|
299
|
+
if (!result.ok && result.error) {
|
|
300
|
+
stderr.write(`${result.error}\n`);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
process.exitCode = result.ok ? 0 : 1;
|
|
304
|
+
return result;
|
|
305
|
+
}
|