@causyne/agent 1.11.0 → 1.13.0
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/docs/THIRD_PARTY_NOTICES.md +12 -0
- package/package.json +2 -2
- package/src/acp/protocol.js +1 -0
- package/src/acp/protocol.ts +22 -0
- package/src/acp/server.js +158 -21
- package/src/acp/server.ts +167 -21
- package/src/agentLoop.d.ts +22 -1
- package/src/agentLoop.js +15 -5
- package/src/approvalGrants.js +33 -0
- package/src/approvalGrants.ts +50 -0
- package/src/decisionPolicy.js +2 -0
- package/src/decisionPolicy.ts +1 -0
- package/src/engines/cad.js +113 -0
- package/src/engines/cad.ts +128 -0
- package/src/engines/deck.js +105 -0
- package/src/engines/deck.ts +109 -0
- package/src/engines/design.js +123 -0
- package/src/engines/design.ts +141 -0
- package/src/engines/effect.js +128 -0
- package/src/engines/effect.ts +142 -0
- package/src/engines/film.js +108 -0
- package/src/engines/film.ts +104 -0
- package/src/engines/grid.js +106 -0
- package/src/engines/grid.ts +121 -0
- package/src/engines/installer.js +226 -0
- package/src/engines/installer.ts +248 -0
- package/src/engines/light.js +107 -0
- package/src/engines/light.ts +122 -0
- package/src/engines/pdf.js +108 -0
- package/src/engines/pdf.ts +124 -0
- package/src/engines/photo.js +126 -0
- package/src/engines/photo.ts +137 -0
- package/src/engines/registry.js +200 -0
- package/src/engines/registry.ts +199 -0
- package/src/engines/sound.js +117 -0
- package/src/engines/sound.ts +130 -0
- package/src/engines/types.js +1 -0
- package/src/engines/types.ts +73 -0
- package/src/engines/word.js +112 -0
- package/src/engines/word.ts +127 -0
- package/src/memoryManager.js +9 -3
- package/src/promptMentions.js +1 -1
- package/src/promptMentions.ts +1 -1
- package/src/sandbox.js +8 -0
- package/src/sessionJournal.js +12 -2
- package/src/sessionJournal.ts +12 -2
- package/src/toolPacks.js +15 -7
- package/src/tools/generateMediaViaApi.js +1 -1
- package/src/tools/nativeEngine.js +464 -0
- package/src/tools/nativeEngine.ts +433 -0
- package/src/tools/openSourceToolProvisioner.js +510 -0
- package/src/tools/openSourceToolProvisioner.ts +590 -0
- package/src/tools/registry.js +4 -1
- package/src/tui/completion.js +2 -2
package/src/agentLoop.d.ts
CHANGED
|
@@ -20,13 +20,33 @@ export interface ApprovalDecision {
|
|
|
20
20
|
[key: string]: unknown;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
+
export interface AgentLoopApprovalScope {
|
|
24
|
+
grantAlways(toolName: unknown): void;
|
|
25
|
+
isAlwaysAllowed(toolName: unknown): boolean;
|
|
26
|
+
listAlwaysAllowed(): string[];
|
|
27
|
+
revokeAllAlways(): number;
|
|
28
|
+
revokeAlways(toolName: unknown): boolean;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface AgentLoopOptions {
|
|
32
|
+
workspaceRoot?: string;
|
|
33
|
+
memorySessionId?: string | null;
|
|
34
|
+
approvalScope?: AgentLoopApprovalScope;
|
|
35
|
+
}
|
|
36
|
+
|
|
23
37
|
export class AgentLoop {
|
|
24
|
-
constructor(
|
|
38
|
+
constructor(
|
|
39
|
+
eventSink: AgentLoopEventSink | null,
|
|
40
|
+
taskId: string,
|
|
41
|
+
userPrompt: string | null,
|
|
42
|
+
options?: AgentLoopOptions
|
|
43
|
+
);
|
|
25
44
|
|
|
26
45
|
eventSink: AgentLoopEventSink | null;
|
|
27
46
|
taskId: string;
|
|
28
47
|
userPrompt: string | null;
|
|
29
48
|
workspaceRoot: string;
|
|
49
|
+
approvalScope: AgentLoopApprovalScope;
|
|
30
50
|
autonomyOverride: string | null;
|
|
31
51
|
config: AgentLoopConfig;
|
|
32
52
|
stepsCompleted: number;
|
|
@@ -35,6 +55,7 @@ export class AgentLoop {
|
|
|
35
55
|
abort(): void;
|
|
36
56
|
rearmAbortController(): void;
|
|
37
57
|
setAutonomyMode(mode: 'A' | 'B' | 'C' | string): void;
|
|
58
|
+
isAlwaysAllowed(toolName: unknown): boolean;
|
|
38
59
|
emitEvent(event: AgentLoopEvent): void;
|
|
39
60
|
waitForApproval(toolCallId: string): Promise<boolean>;
|
|
40
61
|
handleApprovalResponse(toolCallId: string, decision: ApprovalDecision | boolean): void;
|
package/src/agentLoop.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createHash } from 'crypto';
|
|
2
|
-
import {
|
|
2
|
+
import { processApprovalScope } from './approvalGrants.js';
|
|
3
3
|
import { pruneSessions as pruneEmbodimentSessions, describeSession } from './embodimentSession.js';
|
|
4
4
|
import { WorkspacePerception } from './perception.js';
|
|
5
5
|
import { audioFormatForMimeType } from './providers/base.js';
|
|
@@ -319,12 +319,17 @@ export class AgentLoop {
|
|
|
319
319
|
* endpoint is reported in seconds rather than after the whole step budget.
|
|
320
320
|
*/
|
|
321
321
|
static MAX_CONSECUTIVE_FAILURES = 3;
|
|
322
|
-
constructor(eventSink, taskId, userPrompt) {
|
|
322
|
+
constructor(eventSink, taskId, userPrompt, options = {}) {
|
|
323
323
|
this.eventSink = eventSink;
|
|
324
324
|
this.taskId = taskId;
|
|
325
325
|
this.userPrompt = userPrompt;
|
|
326
|
-
this.workspaceRoot =
|
|
326
|
+
this.workspaceRoot = typeof options.workspaceRoot === 'string' && options.workspaceRoot
|
|
327
|
+
? options.workspaceRoot
|
|
328
|
+
: process.cwd();
|
|
327
329
|
this.autonomyOverride = null;
|
|
330
|
+
this.approvalScope = options.approvalScope && typeof options.approvalScope.isAlwaysAllowed === 'function'
|
|
331
|
+
? options.approvalScope
|
|
332
|
+
: processApprovalScope;
|
|
328
333
|
|
|
329
334
|
this.config = loadConfig();
|
|
330
335
|
this.sandbox = new Sandbox();
|
|
@@ -346,7 +351,7 @@ export class AgentLoop {
|
|
|
346
351
|
this.tokenTracker = new TokenTracker();
|
|
347
352
|
|
|
348
353
|
this.llm = this.initializeProvider();
|
|
349
|
-
this.memoryManager = new MemoryManager();
|
|
354
|
+
this.memoryManager = new MemoryManager(this.workspaceRoot, options.memorySessionId || null);
|
|
350
355
|
this.messages = this.memoryManager.loadHistory(); // Persistent context window
|
|
351
356
|
this.stepsCompleted = 0;
|
|
352
357
|
this.consecutiveCommands = 0;
|
|
@@ -422,6 +427,11 @@ export class AgentLoop {
|
|
|
422
427
|
this.toolScope = null;
|
|
423
428
|
}
|
|
424
429
|
|
|
430
|
+
/** True when this loop's own conversation scope has a standing approval. */
|
|
431
|
+
isAlwaysAllowed(toolName) {
|
|
432
|
+
return this.approvalScope.isAlwaysAllowed(toolName);
|
|
433
|
+
}
|
|
434
|
+
|
|
425
435
|
// V6: Adaptive Temperature based on task intent
|
|
426
436
|
determineTemperature(prompt) {
|
|
427
437
|
if (!prompt) return 0.1;
|
|
@@ -2043,7 +2053,7 @@ export class AgentLoop {
|
|
|
2043
2053
|
// Nothing else is bypassed: the sandbox has already run above, so a
|
|
2044
2054
|
// FORBIDDEN command is still refused and a path outside the workspace
|
|
2045
2055
|
// is still blocked. This waives the QUESTION, not the guard.
|
|
2046
|
-
const standingApproval = isAlwaysAllowed(functionName);
|
|
2056
|
+
const standingApproval = this.isAlwaysAllowed(functionName);
|
|
2047
2057
|
if (standingApproval) {
|
|
2048
2058
|
auditLog.log({
|
|
2049
2059
|
event: 'approval_auto_granted', taskId: this.taskId,
|
package/src/approvalGrants.js
CHANGED
|
@@ -46,3 +46,36 @@ export function revokeAllAlways() {
|
|
|
46
46
|
export function revokeAlways(toolName) {
|
|
47
47
|
return standingApprovals.delete(normalizeToolName(toolName));
|
|
48
48
|
}
|
|
49
|
+
/** A fresh, empty standing-approval scope that is not shared with anything. */
|
|
50
|
+
export function createApprovalScope() {
|
|
51
|
+
const approvals = new Set();
|
|
52
|
+
return {
|
|
53
|
+
grantAlways(toolName) {
|
|
54
|
+
const name = normalizeToolName(toolName);
|
|
55
|
+
if (name)
|
|
56
|
+
approvals.add(name);
|
|
57
|
+
},
|
|
58
|
+
isAlwaysAllowed(toolName) {
|
|
59
|
+
return approvals.has(normalizeToolName(toolName));
|
|
60
|
+
},
|
|
61
|
+
listAlwaysAllowed() {
|
|
62
|
+
return [...approvals].sort();
|
|
63
|
+
},
|
|
64
|
+
revokeAllAlways() {
|
|
65
|
+
const count = approvals.size;
|
|
66
|
+
approvals.clear();
|
|
67
|
+
return count;
|
|
68
|
+
},
|
|
69
|
+
revokeAlways(toolName) {
|
|
70
|
+
return approvals.delete(normalizeToolName(toolName));
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
/** The process-wide scope, for callers that do not create their own. */
|
|
75
|
+
export const processApprovalScope = {
|
|
76
|
+
grantAlways,
|
|
77
|
+
isAlwaysAllowed,
|
|
78
|
+
listAlwaysAllowed,
|
|
79
|
+
revokeAllAlways,
|
|
80
|
+
revokeAlways
|
|
81
|
+
};
|
package/src/approvalGrants.ts
CHANGED
|
@@ -18,6 +18,22 @@
|
|
|
18
18
|
// should be an explicit, listed, revocable config entry — not a quiet
|
|
19
19
|
// side-effect of a keypress in a modal.
|
|
20
20
|
|
|
21
|
+
/**
|
|
22
|
+
* One set of standing approvals, isolated from every other scope.
|
|
23
|
+
*
|
|
24
|
+
* The process-wide scope below is what a terminal session uses. A server-owned
|
|
25
|
+
* conversation (ACP) gets its own scope instead, so "allow always" in one
|
|
26
|
+
* conversation can never leak into another one — and never into a fork, which
|
|
27
|
+
* starts with a scope that has never been granted anything.
|
|
28
|
+
*/
|
|
29
|
+
export interface ApprovalScope {
|
|
30
|
+
grantAlways(toolName: unknown): void;
|
|
31
|
+
isAlwaysAllowed(toolName: unknown): boolean;
|
|
32
|
+
listAlwaysAllowed(): string[];
|
|
33
|
+
revokeAllAlways(): number;
|
|
34
|
+
revokeAlways(toolName: unknown): boolean;
|
|
35
|
+
}
|
|
36
|
+
|
|
21
37
|
/** Tool names approved for the rest of this process. Deliberately in memory. */
|
|
22
38
|
const standingApprovals = new Set<string>();
|
|
23
39
|
|
|
@@ -52,3 +68,37 @@ export function revokeAllAlways(): number {
|
|
|
52
68
|
export function revokeAlways(toolName: unknown): boolean {
|
|
53
69
|
return standingApprovals.delete(normalizeToolName(toolName));
|
|
54
70
|
}
|
|
71
|
+
|
|
72
|
+
/** A fresh, empty standing-approval scope that is not shared with anything. */
|
|
73
|
+
export function createApprovalScope(): ApprovalScope {
|
|
74
|
+
const approvals = new Set<string>();
|
|
75
|
+
return {
|
|
76
|
+
grantAlways(toolName) {
|
|
77
|
+
const name = normalizeToolName(toolName);
|
|
78
|
+
if (name) approvals.add(name);
|
|
79
|
+
},
|
|
80
|
+
isAlwaysAllowed(toolName) {
|
|
81
|
+
return approvals.has(normalizeToolName(toolName));
|
|
82
|
+
},
|
|
83
|
+
listAlwaysAllowed() {
|
|
84
|
+
return [...approvals].sort();
|
|
85
|
+
},
|
|
86
|
+
revokeAllAlways() {
|
|
87
|
+
const count = approvals.size;
|
|
88
|
+
approvals.clear();
|
|
89
|
+
return count;
|
|
90
|
+
},
|
|
91
|
+
revokeAlways(toolName) {
|
|
92
|
+
return approvals.delete(normalizeToolName(toolName));
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** The process-wide scope, for callers that do not create their own. */
|
|
98
|
+
export const processApprovalScope: ApprovalScope = {
|
|
99
|
+
grantAlways,
|
|
100
|
+
isAlwaysAllowed,
|
|
101
|
+
listAlwaysAllowed,
|
|
102
|
+
revokeAllAlways,
|
|
103
|
+
revokeAlways
|
|
104
|
+
};
|
package/src/decisionPolicy.js
CHANGED
|
@@ -53,6 +53,8 @@ export function requiresImplementationPlan(prompt, archetype = '', confidence =
|
|
|
53
53
|
export function isMutatingToolCall(toolName, args = {}) {
|
|
54
54
|
if (toolName === 'creative_apps')
|
|
55
55
|
return args.action !== 'status';
|
|
56
|
+
if (toolName === 'native_engine')
|
|
57
|
+
return !['status', 'catalog', 'describe', 'inspect', 'probe'].includes(String(args.action ?? ''));
|
|
56
58
|
if (MUTATING_TOOLS.has(toolName)) {
|
|
57
59
|
if (toolName === 'sysRun' || toolName === 'sysRunBg') {
|
|
58
60
|
const command = String(args.command ?? '');
|
package/src/decisionPolicy.ts
CHANGED
|
@@ -91,6 +91,7 @@ export function requiresImplementationPlan(prompt: string, archetype = '', confi
|
|
|
91
91
|
|
|
92
92
|
export function isMutatingToolCall(toolName: string, args: Record<string, unknown> = {}): boolean {
|
|
93
93
|
if (toolName === 'creative_apps') return args.action !== 'status';
|
|
94
|
+
if (toolName === 'native_engine') return !['status', 'catalog', 'describe', 'inspect', 'probe'].includes(String(args.action ?? ''));
|
|
94
95
|
if (MUTATING_TOOLS.has(toolName)) {
|
|
95
96
|
if (toolName === 'sysRun' || toolName === 'sysRunBg') {
|
|
96
97
|
const command = String(args.command ?? '');
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
// CAD engine for Causyne Agent (headless 2D/3D CAD editing, conversion, and export).
|
|
3
|
+
// Speaks DXF, DWG, SVG, PNG, PDF. Operates deterministically via clean CLI subcommands.
|
|
4
|
+
const TIMEOUTS = {
|
|
5
|
+
status: 10_000,
|
|
6
|
+
catalog: 30_000,
|
|
7
|
+
describe: 30_000,
|
|
8
|
+
inspect: 60_000,
|
|
9
|
+
execute: 180_000,
|
|
10
|
+
batch: 600_000,
|
|
11
|
+
export: 300_000,
|
|
12
|
+
render: 300_000,
|
|
13
|
+
probe: 60_000,
|
|
14
|
+
install: 600_000
|
|
15
|
+
};
|
|
16
|
+
function positional(value) {
|
|
17
|
+
return value.startsWith('-') ? `.${path.sep}${value}` : value;
|
|
18
|
+
}
|
|
19
|
+
function requireProject(context, action) {
|
|
20
|
+
if (!context.project)
|
|
21
|
+
throw new Error(`${action} requires project`);
|
|
22
|
+
return positional(context.project);
|
|
23
|
+
}
|
|
24
|
+
function commandArgs(steps) {
|
|
25
|
+
const args = [];
|
|
26
|
+
for (const step of steps) {
|
|
27
|
+
if (step.params && Object.keys(step.params).length > 0) {
|
|
28
|
+
args.push('--cmd', `${step.id} ${JSON.stringify(step.params)}`);
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
args.push('--cmd', step.id);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return args;
|
|
35
|
+
}
|
|
36
|
+
export const cadEngine = {
|
|
37
|
+
id: 'cad',
|
|
38
|
+
label: 'Causyne CAD Engine',
|
|
39
|
+
envVar: 'CAUSYNE_ENGINE_CAD',
|
|
40
|
+
binaryName: 'causyne-engine-cad',
|
|
41
|
+
actions: ['catalog', 'describe', 'inspect', 'execute', 'batch', 'export', 'render', 'probe'],
|
|
42
|
+
invoke(request, context) {
|
|
43
|
+
let args;
|
|
44
|
+
let artifacts = [];
|
|
45
|
+
switch (request.action) {
|
|
46
|
+
case 'status':
|
|
47
|
+
args = ['--version'];
|
|
48
|
+
break;
|
|
49
|
+
case 'catalog':
|
|
50
|
+
args = ['commands', ...(request.query ? [request.query] : [])];
|
|
51
|
+
break;
|
|
52
|
+
case 'describe':
|
|
53
|
+
args = ['commands', request.command ?? ''];
|
|
54
|
+
break;
|
|
55
|
+
case 'inspect':
|
|
56
|
+
args = ['info', requireProject(context, 'inspect')];
|
|
57
|
+
break;
|
|
58
|
+
case 'probe':
|
|
59
|
+
args = ['info', positional(request.query ?? '')];
|
|
60
|
+
break;
|
|
61
|
+
case 'execute':
|
|
62
|
+
case 'batch': {
|
|
63
|
+
const steps = request.action === 'execute'
|
|
64
|
+
? [{ id: request.command ?? '', ...(request.params ? { params: request.params } : {}) }]
|
|
65
|
+
: (request.steps ?? []);
|
|
66
|
+
args = ['run'];
|
|
67
|
+
if (context.project) {
|
|
68
|
+
args.push(positional(context.project));
|
|
69
|
+
}
|
|
70
|
+
else if (context.demo) {
|
|
71
|
+
args.push('--sample');
|
|
72
|
+
}
|
|
73
|
+
args.push(...commandArgs(steps));
|
|
74
|
+
if (context.saveAs) {
|
|
75
|
+
args.push('--save', context.saveAs);
|
|
76
|
+
artifacts.push(context.saveAs);
|
|
77
|
+
}
|
|
78
|
+
else if (context.save && context.project) {
|
|
79
|
+
args.push('--save', context.project);
|
|
80
|
+
artifacts.push(context.project);
|
|
81
|
+
}
|
|
82
|
+
if (request.output) {
|
|
83
|
+
args.push('--export', request.output);
|
|
84
|
+
artifacts.push(request.output);
|
|
85
|
+
}
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
case 'export': {
|
|
89
|
+
const output = request.output ?? '';
|
|
90
|
+
args = ['convert', requireProject(context, 'export'), positional(output)];
|
|
91
|
+
artifacts = [output];
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
case 'render': {
|
|
95
|
+
// Render 2D/3D view directly to PNG, SVG, or PDF
|
|
96
|
+
const output = request.output ?? '';
|
|
97
|
+
args = ['run'];
|
|
98
|
+
if (context.project) {
|
|
99
|
+
args.push(positional(context.project));
|
|
100
|
+
}
|
|
101
|
+
else if (context.demo) {
|
|
102
|
+
args.push('--sample');
|
|
103
|
+
}
|
|
104
|
+
args.push('--export', positional(output));
|
|
105
|
+
artifacts = [output];
|
|
106
|
+
break;
|
|
107
|
+
}
|
|
108
|
+
default:
|
|
109
|
+
throw new Error(`Unsupported CAD engine action: ${request.action}`);
|
|
110
|
+
}
|
|
111
|
+
return { args, artifacts: artifacts.filter(Boolean), timeoutMs: TIMEOUTS[request.action] };
|
|
112
|
+
}
|
|
113
|
+
};
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import type {
|
|
3
|
+
NativeEngineAction,
|
|
4
|
+
NativeEngineAdapter,
|
|
5
|
+
NativeEngineContext,
|
|
6
|
+
NativeEngineInvocation,
|
|
7
|
+
NativeEngineRequest,
|
|
8
|
+
NativeEngineStep
|
|
9
|
+
} from './types.js';
|
|
10
|
+
|
|
11
|
+
// CAD engine for Causyne Agent (headless 2D/3D CAD editing, conversion, and export).
|
|
12
|
+
// Speaks DXF, DWG, SVG, PNG, PDF. Operates deterministically via clean CLI subcommands.
|
|
13
|
+
|
|
14
|
+
const TIMEOUTS: Record<NativeEngineAction, number> = {
|
|
15
|
+
status: 10_000,
|
|
16
|
+
catalog: 30_000,
|
|
17
|
+
describe: 30_000,
|
|
18
|
+
inspect: 60_000,
|
|
19
|
+
execute: 180_000,
|
|
20
|
+
batch: 600_000,
|
|
21
|
+
export: 300_000,
|
|
22
|
+
render: 300_000,
|
|
23
|
+
probe: 60_000,
|
|
24
|
+
install: 600_000
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
function positional(value: string): string {
|
|
28
|
+
return value.startsWith('-') ? `.${path.sep}${value}` : value;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function requireProject(context: NativeEngineContext, action: string): string {
|
|
32
|
+
if (!context.project) throw new Error(`${action} requires project`);
|
|
33
|
+
return positional(context.project);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function commandArgs(steps: NativeEngineStep[]): string[] {
|
|
37
|
+
const args: string[] = [];
|
|
38
|
+
for (const step of steps) {
|
|
39
|
+
if (step.params && Object.keys(step.params).length > 0) {
|
|
40
|
+
args.push('--cmd', `${step.id} ${JSON.stringify(step.params)}`);
|
|
41
|
+
} else {
|
|
42
|
+
args.push('--cmd', step.id);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return args;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export const cadEngine: NativeEngineAdapter = {
|
|
49
|
+
id: 'cad',
|
|
50
|
+
label: 'Causyne CAD Engine',
|
|
51
|
+
envVar: 'CAUSYNE_ENGINE_CAD',
|
|
52
|
+
binaryName: 'causyne-engine-cad',
|
|
53
|
+
actions: ['catalog', 'describe', 'inspect', 'execute', 'batch', 'export', 'render', 'probe'],
|
|
54
|
+
invoke(request: NativeEngineRequest, context: NativeEngineContext): NativeEngineInvocation {
|
|
55
|
+
let args: string[];
|
|
56
|
+
let artifacts: string[] = [];
|
|
57
|
+
|
|
58
|
+
switch (request.action) {
|
|
59
|
+
case 'status':
|
|
60
|
+
args = ['--version'];
|
|
61
|
+
break;
|
|
62
|
+
case 'catalog':
|
|
63
|
+
args = ['commands', ...(request.query ? [request.query] : [])];
|
|
64
|
+
break;
|
|
65
|
+
case 'describe':
|
|
66
|
+
args = ['commands', request.command ?? ''];
|
|
67
|
+
break;
|
|
68
|
+
case 'inspect':
|
|
69
|
+
args = ['info', requireProject(context, 'inspect')];
|
|
70
|
+
break;
|
|
71
|
+
case 'probe':
|
|
72
|
+
args = ['info', positional(request.query ?? '')];
|
|
73
|
+
break;
|
|
74
|
+
case 'execute':
|
|
75
|
+
case 'batch': {
|
|
76
|
+
const steps: NativeEngineStep[] = request.action === 'execute'
|
|
77
|
+
? [{ id: request.command ?? '', ...(request.params ? { params: request.params } : {}) }]
|
|
78
|
+
: (request.steps ?? []);
|
|
79
|
+
|
|
80
|
+
args = ['run'];
|
|
81
|
+
if (context.project) {
|
|
82
|
+
args.push(positional(context.project));
|
|
83
|
+
} else if (context.demo) {
|
|
84
|
+
args.push('--sample');
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
args.push(...commandArgs(steps));
|
|
88
|
+
|
|
89
|
+
if (context.saveAs) {
|
|
90
|
+
args.push('--save', context.saveAs);
|
|
91
|
+
artifacts.push(context.saveAs);
|
|
92
|
+
} else if (context.save && context.project) {
|
|
93
|
+
args.push('--save', context.project);
|
|
94
|
+
artifacts.push(context.project);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (request.output) {
|
|
98
|
+
args.push('--export', request.output);
|
|
99
|
+
artifacts.push(request.output);
|
|
100
|
+
}
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
case 'export': {
|
|
104
|
+
const output = request.output ?? '';
|
|
105
|
+
args = ['convert', requireProject(context, 'export'), positional(output)];
|
|
106
|
+
artifacts = [output];
|
|
107
|
+
break;
|
|
108
|
+
}
|
|
109
|
+
case 'render': {
|
|
110
|
+
// Render 2D/3D view directly to PNG, SVG, or PDF
|
|
111
|
+
const output = request.output ?? '';
|
|
112
|
+
args = ['run'];
|
|
113
|
+
if (context.project) {
|
|
114
|
+
args.push(positional(context.project));
|
|
115
|
+
} else if (context.demo) {
|
|
116
|
+
args.push('--sample');
|
|
117
|
+
}
|
|
118
|
+
args.push('--export', positional(output));
|
|
119
|
+
artifacts = [output];
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
default:
|
|
123
|
+
throw new Error(`Unsupported CAD engine action: ${request.action}`);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return { args, artifacts: artifacts.filter(Boolean), timeoutMs: TIMEOUTS[request.action] };
|
|
127
|
+
}
|
|
128
|
+
};
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
const TIMEOUTS = {
|
|
3
|
+
status: 10_000,
|
|
4
|
+
catalog: 30_000,
|
|
5
|
+
describe: 20_000,
|
|
6
|
+
inspect: 60_000,
|
|
7
|
+
execute: 180_000,
|
|
8
|
+
batch: 600_000,
|
|
9
|
+
export: 300_000,
|
|
10
|
+
render: 120_000,
|
|
11
|
+
probe: 60_000,
|
|
12
|
+
install: 600_000
|
|
13
|
+
};
|
|
14
|
+
function positional(value) {
|
|
15
|
+
return value.startsWith('-') ? `.${path.sep}${value}` : value;
|
|
16
|
+
}
|
|
17
|
+
function sourceArgs(context) {
|
|
18
|
+
if (context.demo)
|
|
19
|
+
return ['--sample'];
|
|
20
|
+
if (context.project)
|
|
21
|
+
return ['--in', positional(context.project)];
|
|
22
|
+
return [];
|
|
23
|
+
}
|
|
24
|
+
function saveArgs(context) {
|
|
25
|
+
if (context.saveAs)
|
|
26
|
+
return { args: ['--save', positional(context.saveAs)], artifact: context.saveAs };
|
|
27
|
+
if (context.save && context.project)
|
|
28
|
+
return { args: ['--save', positional(context.project)], artifact: context.project };
|
|
29
|
+
return { args: [] };
|
|
30
|
+
}
|
|
31
|
+
function commandArgs(steps) {
|
|
32
|
+
const args = [];
|
|
33
|
+
for (const step of steps) {
|
|
34
|
+
args.push('--cmd', step.params && Object.keys(step.params).length > 0 ? `${step.id}=${JSON.stringify(step.params)}` : step.id);
|
|
35
|
+
}
|
|
36
|
+
return args;
|
|
37
|
+
}
|
|
38
|
+
export const deckEngine = {
|
|
39
|
+
id: 'deck',
|
|
40
|
+
label: 'Causyne Deck Engine',
|
|
41
|
+
envVar: 'CAUSYNE_ENGINE_DECK',
|
|
42
|
+
binaryName: 'causyne-engine-deck',
|
|
43
|
+
actions: ['catalog', 'describe', 'inspect', 'execute', 'batch', 'export', 'render', 'probe'],
|
|
44
|
+
invoke(request, context) {
|
|
45
|
+
let args;
|
|
46
|
+
let artifacts = [];
|
|
47
|
+
switch (request.action) {
|
|
48
|
+
case 'status':
|
|
49
|
+
args = ['--version'];
|
|
50
|
+
break;
|
|
51
|
+
case 'catalog':
|
|
52
|
+
args = ['commands', ...(request.query ? [request.query] : [])];
|
|
53
|
+
break;
|
|
54
|
+
case 'describe':
|
|
55
|
+
args = ['describe', '--json', request.command ?? ''];
|
|
56
|
+
break;
|
|
57
|
+
case 'inspect': {
|
|
58
|
+
if (context.project) {
|
|
59
|
+
args = ['info', positional(context.project)];
|
|
60
|
+
}
|
|
61
|
+
else if (context.demo) {
|
|
62
|
+
args = ['exec', '--sample', 'document.inspect'];
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
throw new Error('inspect requires project or demo');
|
|
66
|
+
}
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
case 'probe':
|
|
70
|
+
args = ['info', positional(request.query ?? '')];
|
|
71
|
+
break;
|
|
72
|
+
case 'execute': {
|
|
73
|
+
const out = saveArgs(context);
|
|
74
|
+
args = ['exec', ...sourceArgs(context), ...out.args, request.command ?? '', JSON.stringify(request.params ?? {})];
|
|
75
|
+
if (context.keepGoing)
|
|
76
|
+
throw new Error('The deck engine stops at the first failed command; keepGoing is not supported');
|
|
77
|
+
if (out.artifact)
|
|
78
|
+
artifacts = [out.artifact];
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
case 'batch': {
|
|
82
|
+
const out = saveArgs(context);
|
|
83
|
+
args = ['run', ...sourceArgs(context), ...commandArgs(request.steps ?? []), ...out.args, '--json'];
|
|
84
|
+
if (context.keepGoing)
|
|
85
|
+
throw new Error('The deck engine stops at the first failed command; keepGoing is not supported');
|
|
86
|
+
if (out.artifact)
|
|
87
|
+
artifacts = [out.artifact];
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
case 'export':
|
|
91
|
+
args = ['convert', positional(context.project ?? ''), positional(request.output ?? '')];
|
|
92
|
+
artifacts = [request.output ?? ''];
|
|
93
|
+
break;
|
|
94
|
+
case 'render': {
|
|
95
|
+
const slide = Math.max(0, Math.trunc(request.seconds ?? 0));
|
|
96
|
+
args = ['render', ...sourceArgs(context), '--slide', String(slide), ...(request.scale !== undefined ? ['--scale', String(request.scale)] : []), positional(request.output ?? '')];
|
|
97
|
+
artifacts = [request.output ?? ''];
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
default:
|
|
101
|
+
throw new Error(`Unsupported deck engine action: ${request.action}`);
|
|
102
|
+
}
|
|
103
|
+
return { args, artifacts: artifacts.filter(Boolean), timeoutMs: TIMEOUTS[request.action] };
|
|
104
|
+
}
|
|
105
|
+
};
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import type {
|
|
3
|
+
NativeEngineAction,
|
|
4
|
+
NativeEngineAdapter,
|
|
5
|
+
NativeEngineContext,
|
|
6
|
+
NativeEngineInvocation,
|
|
7
|
+
NativeEngineRequest,
|
|
8
|
+
NativeEngineStep
|
|
9
|
+
} from './types.js';
|
|
10
|
+
|
|
11
|
+
const TIMEOUTS: Record<NativeEngineAction, number> = {
|
|
12
|
+
status: 10_000,
|
|
13
|
+
catalog: 30_000,
|
|
14
|
+
describe: 20_000,
|
|
15
|
+
inspect: 60_000,
|
|
16
|
+
execute: 180_000,
|
|
17
|
+
batch: 600_000,
|
|
18
|
+
export: 300_000,
|
|
19
|
+
render: 120_000,
|
|
20
|
+
probe: 60_000,
|
|
21
|
+
install: 600_000
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
function positional(value: string): string {
|
|
25
|
+
return value.startsWith('-') ? `.${path.sep}${value}` : value;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function sourceArgs(context: NativeEngineContext): string[] {
|
|
29
|
+
if (context.demo) return ['--sample'];
|
|
30
|
+
if (context.project) return ['--in', positional(context.project)];
|
|
31
|
+
return [];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function saveArgs(context: NativeEngineContext): { args: string[]; artifact?: string } {
|
|
35
|
+
if (context.saveAs) return { args: ['--save', positional(context.saveAs)], artifact: context.saveAs };
|
|
36
|
+
if (context.save && context.project) return { args: ['--save', positional(context.project)], artifact: context.project };
|
|
37
|
+
return { args: [] };
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function commandArgs(steps: NativeEngineStep[]): string[] {
|
|
41
|
+
const args: string[] = [];
|
|
42
|
+
for (const step of steps) {
|
|
43
|
+
args.push('--cmd', step.params && Object.keys(step.params).length > 0 ? `${step.id}=${JSON.stringify(step.params)}` : step.id);
|
|
44
|
+
}
|
|
45
|
+
return args;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export const deckEngine: NativeEngineAdapter = {
|
|
49
|
+
id: 'deck',
|
|
50
|
+
label: 'Causyne Deck Engine',
|
|
51
|
+
envVar: 'CAUSYNE_ENGINE_DECK',
|
|
52
|
+
binaryName: 'causyne-engine-deck',
|
|
53
|
+
actions: ['catalog', 'describe', 'inspect', 'execute', 'batch', 'export', 'render', 'probe'],
|
|
54
|
+
invoke(request: NativeEngineRequest, context: NativeEngineContext): NativeEngineInvocation {
|
|
55
|
+
let args: string[];
|
|
56
|
+
let artifacts: string[] = [];
|
|
57
|
+
switch (request.action) {
|
|
58
|
+
case 'status':
|
|
59
|
+
args = ['--version'];
|
|
60
|
+
break;
|
|
61
|
+
case 'catalog':
|
|
62
|
+
args = ['commands', ...(request.query ? [request.query] : [])];
|
|
63
|
+
break;
|
|
64
|
+
case 'describe':
|
|
65
|
+
args = ['describe', '--json', request.command ?? ''];
|
|
66
|
+
break;
|
|
67
|
+
case 'inspect': {
|
|
68
|
+
if (context.project) {
|
|
69
|
+
args = ['info', positional(context.project)];
|
|
70
|
+
} else if (context.demo) {
|
|
71
|
+
args = ['exec', '--sample', 'document.inspect'];
|
|
72
|
+
} else {
|
|
73
|
+
throw new Error('inspect requires project or demo');
|
|
74
|
+
}
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
case 'probe':
|
|
78
|
+
args = ['info', positional(request.query ?? '')];
|
|
79
|
+
break;
|
|
80
|
+
case 'execute': {
|
|
81
|
+
const out = saveArgs(context);
|
|
82
|
+
args = ['exec', ...sourceArgs(context), ...out.args, request.command ?? '', JSON.stringify(request.params ?? {})];
|
|
83
|
+
if (context.keepGoing) throw new Error('The deck engine stops at the first failed command; keepGoing is not supported');
|
|
84
|
+
if (out.artifact) artifacts = [out.artifact];
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
case 'batch': {
|
|
88
|
+
const out = saveArgs(context);
|
|
89
|
+
args = ['run', ...sourceArgs(context), ...commandArgs(request.steps ?? []), ...out.args, '--json'];
|
|
90
|
+
if (context.keepGoing) throw new Error('The deck engine stops at the first failed command; keepGoing is not supported');
|
|
91
|
+
if (out.artifact) artifacts = [out.artifact];
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
case 'export':
|
|
95
|
+
args = ['convert', positional(context.project ?? ''), positional(request.output ?? '')];
|
|
96
|
+
artifacts = [request.output ?? ''];
|
|
97
|
+
break;
|
|
98
|
+
case 'render': {
|
|
99
|
+
const slide = Math.max(0, Math.trunc(request.seconds ?? 0));
|
|
100
|
+
args = ['render', ...sourceArgs(context), '--slide', String(slide), ...(request.scale !== undefined ? ['--scale', String(request.scale)] : []), positional(request.output ?? '')];
|
|
101
|
+
artifacts = [request.output ?? ''];
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
default:
|
|
105
|
+
throw new Error(`Unsupported deck engine action: ${request.action}`);
|
|
106
|
+
}
|
|
107
|
+
return { args, artifacts: artifacts.filter(Boolean), timeoutMs: TIMEOUTS[request.action] };
|
|
108
|
+
}
|
|
109
|
+
};
|