@causyne/agent 1.12.0 → 1.14.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.
Files changed (45) hide show
  1. package/docs/THIRD_PARTY_NOTICES.md +1 -1
  2. package/package.json +2 -2
  3. package/src/acp/agentCatalog.js +389 -0
  4. package/src/acp/agentCatalog.ts +455 -0
  5. package/src/acp/client.js +127 -4
  6. package/src/acp/client.ts +145 -5
  7. package/src/acp/peerProfiles.js +81 -3
  8. package/src/acp/peerProfiles.ts +85 -4
  9. package/src/acp/protocol.js +2 -0
  10. package/src/acp/protocol.ts +19 -0
  11. package/src/agentLoop.js +33 -12
  12. package/src/commands.js +108 -0
  13. package/src/engines/deck.js +105 -0
  14. package/src/engines/deck.ts +109 -0
  15. package/src/engines/design.js +123 -0
  16. package/src/engines/design.ts +141 -0
  17. package/src/engines/effect.js +128 -0
  18. package/src/engines/effect.ts +142 -0
  19. package/src/engines/grid.js +106 -0
  20. package/src/engines/grid.ts +121 -0
  21. package/src/engines/light.js +107 -0
  22. package/src/engines/light.ts +122 -0
  23. package/src/engines/pdf.js +108 -0
  24. package/src/engines/pdf.ts +124 -0
  25. package/src/engines/registry.js +15 -1
  26. package/src/engines/registry.ts +15 -1
  27. package/src/engines/word.js +112 -0
  28. package/src/engines/word.ts +127 -0
  29. package/src/entrypoint.js +11 -0
  30. package/src/providers/anthropic.js +5 -13
  31. package/src/providers/dashscope-byok.js +3 -4
  32. package/src/providers/deepseek.js +3 -4
  33. package/src/providers/gemini.js +17 -101
  34. package/src/providers/moonshot.js +3 -4
  35. package/src/providers/ollama.js +3 -4
  36. package/src/providers/openai-compatible.js +3 -4
  37. package/src/providers/qwen-byok.js +3 -4
  38. package/src/providers/xai.js +3 -4
  39. package/src/tools/peerAgent.js +115 -31
  40. package/src/tools/peerAgent.ts +143 -32
  41. package/src/tools/registry.js +144 -16
  42. package/src/tools/toolScanner.js +349 -0
  43. package/src/tools/toolScanner.ts +451 -0
  44. package/src/tools/toolSelfRepair.js +759 -0
  45. package/src/tools/toolSelfRepair.ts +846 -0
package/src/commands.js CHANGED
@@ -27,6 +27,12 @@ import {
27
27
  } from './mcp/mcpRegistry.js';
28
28
  import { analyzeFiles, formatFindings } from './slopDetector.js';
29
29
  import { suggestMovements, formatMovementBrief, DESIGN_MOVEMENTS } from './designPalettes.js';
30
+ import {
31
+ loadPeerProfiles, addPeerProfile, removePeerProfile, listAllPeers, getPeerProfile
32
+ } from './acp/peerProfiles.js';
33
+ import {
34
+ detectAllPeers, testPeerHandshake, BUILTIN_PEER_PRESETS
35
+ } from './acp/agentCatalog.js';
30
36
  import fs from 'fs';
31
37
  import os from 'os';
32
38
  import path from 'path';
@@ -856,6 +862,108 @@ export const COMMANDS = [
856
862
  }
857
863
  },
858
864
 
865
+ {
866
+ name: 'peers',
867
+ scope: 'local',
868
+ usage: '/peers [detect | test <id> | add <id> <command…> | remove <id>]',
869
+ description: 'Manage, discover, and test external ACP peer agents (Claude Code, OpenCode, Codex, Gemini, Hermes, etc.)',
870
+ dialogTitle: 'ACP peer agents',
871
+ run: async (argv) => {
872
+ const [action, peerId, ...rest] = argv;
873
+
874
+ if (action === 'detect') {
875
+ const detected = await detectAllPeers();
876
+ const lines = ['Discovered ACP Peer Agents', ''];
877
+ for (const item of detected) {
878
+ const statusIcon = item.status === 'ready' ? '✅' : (item.status === 'needs_auth' ? '⚠️ ' : '❌');
879
+ lines.push(` ${statusIcon} ${item.id} (${item.label}) — ${item.status.toUpperCase()}`);
880
+ lines.push(` Command: ${item.command} ${item.args.join(' ')}`);
881
+ if (item.details) lines.push(` Details: ${item.details}`);
882
+ if (item.setupInstruction) lines.push(` Setup: ${item.setupInstruction}`);
883
+ }
884
+ lines.push('');
885
+ lines.push('Use /peers test <id> to test zero-token handshake against a specific peer.');
886
+ return ok(lines.join('\n'));
887
+ }
888
+
889
+ if (action === 'test') {
890
+ if (!peerId) return fail('Usage: /peers test <id>');
891
+ const profile = getPeerProfile(peerId);
892
+ if (!profile) return fail(`No peer agent found for "${peerId}". Try /peers detect to see available agents.`);
893
+
894
+ const handshake = await testPeerHandshake({
895
+ command: profile.command,
896
+ args: profile.args,
897
+ cwd: profile.cwd || process.cwd(),
898
+ timeoutMs: 15000
899
+ });
900
+
901
+ if (handshake.ready) {
902
+ const name = handshake.agentInfo ? `${handshake.agentInfo.name} ${handshake.agentInfo.version}` : profile.label;
903
+ return ok(
904
+ `✅ ACP Peer Test Passed: "${peerId}"\n\n`
905
+ + `Agent: ${name}\n`
906
+ + `Command: ${profile.command} ${profile.args.join(' ')}\n`
907
+ + `Policy: ${profile.policy}\n`
908
+ + `Auth Methods: ${handshake.authMethods?.join(', ') || 'none'}\n\n`
909
+ + `Ready to receive delegated tasks via peer_agent_delegate.`
910
+ );
911
+ } else {
912
+ return fail(
913
+ `❌ ACP Peer Test Failed: "${peerId}"\n\n`
914
+ + `Error: ${handshake.error || 'Handshake failed'}\n`
915
+ + `Command: ${profile.command} ${profile.args.join(' ')}`
916
+ );
917
+ }
918
+ }
919
+
920
+ if (action === 'add') {
921
+ if (!peerId) return fail('Usage: /peers add <id> <command> [args…]');
922
+ if (rest.length === 0) return fail(`Give "${peerId}" a command to run (e.g. opencode acp).`);
923
+
924
+ const newProfile = {
925
+ id: peerId.trim().toLowerCase(),
926
+ label: peerId,
927
+ command: rest[0],
928
+ args: rest.slice(1),
929
+ cwd: null,
930
+ policy: 'read-only',
931
+ timeoutSeconds: 180,
932
+ env: {}
933
+ };
934
+
935
+ const res = addPeerProfile(newProfile);
936
+ if (!res.ok) return fail(`Could not save peer: ${res.error}`);
937
+ return ok(`Added peer "${peerId}" [policy: read-only]. Edit ~/.causyne/peers.json to customize policy, timeout, or environment.`);
938
+ }
939
+
940
+ if (action === 'remove') {
941
+ if (!peerId) return fail('Usage: /peers remove <id>');
942
+ const res = removePeerProfile(peerId);
943
+ if (!res.ok) return fail(res.error || `Could not remove peer "${peerId}".`);
944
+ return ok(`Removed peer profile "${peerId}".`);
945
+ }
946
+
947
+ if (action) {
948
+ return fail(`Unknown peers action "${action}". Try: detect, test, add, remove, or peers on its own to list.`);
949
+ }
950
+
951
+ // Default: list all configured and discovered peers
952
+ const peers = listAllPeers();
953
+ const lines = ['Configured & Preset ACP Peer Agents', ''];
954
+ for (const peer of peers) {
955
+ lines.push(` • ${peer.id} (${peer.label}) [policy: ${peer.policy}, timeout: ${peer.timeoutSeconds}s]`);
956
+ lines.push(` Command: ${peer.command} ${peer.args.join(' ')}`);
957
+ }
958
+ lines.push('');
959
+ lines.push('Commands:');
960
+ lines.push(' /peers detect Scan local system for installed ACP agents');
961
+ lines.push(' /peers test <id> Verify zero-token connection to an agent');
962
+ lines.push(' /peers add <id> Add or override a peer command');
963
+ return ok(lines.join('\n'));
964
+ }
965
+ },
966
+
859
967
  {
860
968
  name: 'slop',
861
969
  scope: 'local',
@@ -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
+ };
@@ -0,0 +1,123 @@
1
+ import path from 'node:path';
2
+ // Multi-page layout, vector illustration, and publication engine for Causyne Agent.
3
+ // Headless document composer, IDML/ePub/PDF/SVG/PNG renderer, and batch pipeline.
4
+ // Operates deterministically via clean CLI subcommands.
5
+ const TIMEOUTS = {
6
+ status: 10_000,
7
+ catalog: 30_000,
8
+ describe: 30_000,
9
+ inspect: 60_000,
10
+ execute: 180_000,
11
+ batch: 600_000,
12
+ export: 300_000,
13
+ render: 300_000,
14
+ probe: 60_000,
15
+ install: 600_000
16
+ };
17
+ function positional(value) {
18
+ return value.startsWith('-') ? `.${path.sep}${value}` : value;
19
+ }
20
+ function requireProject(context, action) {
21
+ if (!context.project)
22
+ throw new Error(`${action} requires project`);
23
+ return positional(context.project);
24
+ }
25
+ function commandArgs(steps) {
26
+ const args = [];
27
+ for (const step of steps) {
28
+ if (step.params && Object.keys(step.params).length > 0) {
29
+ args.push('--cmd', `${step.id}=${JSON.stringify(step.params)}`);
30
+ }
31
+ else {
32
+ args.push('--cmd', step.id);
33
+ }
34
+ }
35
+ return args;
36
+ }
37
+ export const designEngine = {
38
+ id: 'design',
39
+ label: 'Causyne Design Engine',
40
+ envVar: 'CAUSYNE_ENGINE_DESIGN',
41
+ binaryName: 'causyne-engine-design',
42
+ actions: ['catalog', 'describe', 'inspect', 'execute', 'batch', 'export', 'render', 'probe'],
43
+ invoke(request, context) {
44
+ let args;
45
+ let artifacts = [];
46
+ switch (request.action) {
47
+ case 'status':
48
+ args = ['--version'];
49
+ break;
50
+ case 'catalog':
51
+ args = ['commands', ...(request.query ? [request.query] : [])];
52
+ break;
53
+ case 'describe':
54
+ args = ['describe', request.command ?? ''];
55
+ break;
56
+ case 'inspect':
57
+ case 'probe': {
58
+ const file = request.action === 'inspect' ? requireProject(context, 'inspect') : positional(request.query ?? '');
59
+ args = ['run', '--in', file, '--export', '/dev/null'];
60
+ break;
61
+ }
62
+ case 'execute':
63
+ case 'batch': {
64
+ const steps = request.action === 'execute'
65
+ ? [{ id: request.command ?? '', ...(request.params ? { params: request.params } : {}) }]
66
+ : (request.steps ?? []);
67
+ args = ['run'];
68
+ if (context.project) {
69
+ args.push('--in', positional(context.project));
70
+ }
71
+ else if (context.demo) {
72
+ args.push('--sample');
73
+ }
74
+ args.push(...commandArgs(steps));
75
+ if (context.saveAs) {
76
+ args.push('--export', context.saveAs);
77
+ artifacts.push(context.saveAs);
78
+ }
79
+ else if (context.save && context.project) {
80
+ args.push('--export', context.project);
81
+ artifacts.push(context.project);
82
+ }
83
+ if (request.output) {
84
+ args.push('--export', request.output);
85
+ artifacts.push(request.output);
86
+ }
87
+ break;
88
+ }
89
+ case 'export': {
90
+ const output = request.output ?? '';
91
+ args = ['run', '--in', requireProject(context, 'export'), '--export', positional(output)];
92
+ artifacts = [output];
93
+ break;
94
+ }
95
+ case 'render': {
96
+ const output = request.output ?? '';
97
+ args = ['run'];
98
+ if (context.project) {
99
+ args.push('--in', positional(context.project));
100
+ }
101
+ else {
102
+ args.push('--sample');
103
+ }
104
+ if (request.range) {
105
+ args.push('--page', request.range);
106
+ }
107
+ if (request.scale !== undefined) {
108
+ args.push('--scale', String(request.scale));
109
+ }
110
+ args.push('--export', positional(output));
111
+ artifacts = [output];
112
+ break;
113
+ }
114
+ default:
115
+ throw new Error(`Unsupported design engine action: ${request.action}`);
116
+ }
117
+ return {
118
+ args,
119
+ artifacts,
120
+ timeoutMs: TIMEOUTS[request.action] ?? 60_000
121
+ };
122
+ }
123
+ };
@@ -0,0 +1,141 @@
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
+ // Multi-page layout, vector illustration, and publication engine for Causyne Agent.
12
+ // Headless document composer, IDML/ePub/PDF/SVG/PNG renderer, and batch pipeline.
13
+ // Operates deterministically via clean CLI subcommands.
14
+
15
+ const TIMEOUTS: Record<NativeEngineAction, number> = {
16
+ status: 10_000,
17
+ catalog: 30_000,
18
+ describe: 30_000,
19
+ inspect: 60_000,
20
+ execute: 180_000,
21
+ batch: 600_000,
22
+ export: 300_000,
23
+ render: 300_000,
24
+ probe: 60_000,
25
+ install: 600_000
26
+ };
27
+
28
+ function positional(value: string): string {
29
+ return value.startsWith('-') ? `.${path.sep}${value}` : value;
30
+ }
31
+
32
+ function requireProject(context: NativeEngineContext, action: string): string {
33
+ if (!context.project) throw new Error(`${action} requires project`);
34
+ return positional(context.project);
35
+ }
36
+
37
+ function commandArgs(steps: NativeEngineStep[]): string[] {
38
+ const args: string[] = [];
39
+ for (const step of steps) {
40
+ if (step.params && Object.keys(step.params).length > 0) {
41
+ args.push('--cmd', `${step.id}=${JSON.stringify(step.params)}`);
42
+ } else {
43
+ args.push('--cmd', step.id);
44
+ }
45
+ }
46
+ return args;
47
+ }
48
+
49
+ export const designEngine: NativeEngineAdapter = {
50
+ id: 'design',
51
+ label: 'Causyne Design Engine',
52
+ envVar: 'CAUSYNE_ENGINE_DESIGN',
53
+ binaryName: 'causyne-engine-design',
54
+ actions: ['catalog', 'describe', 'inspect', 'execute', 'batch', 'export', 'render', 'probe'],
55
+ invoke(request: NativeEngineRequest, context: NativeEngineContext): NativeEngineInvocation {
56
+ let args: string[];
57
+ let artifacts: string[] = [];
58
+
59
+ switch (request.action) {
60
+ case 'status':
61
+ args = ['--version'];
62
+ break;
63
+ case 'catalog':
64
+ args = ['commands', ...(request.query ? [request.query] : [])];
65
+ break;
66
+ case 'describe':
67
+ args = ['describe', request.command ?? ''];
68
+ break;
69
+ case 'inspect':
70
+ case 'probe': {
71
+ const file = request.action === 'inspect' ? requireProject(context, 'inspect') : positional(request.query ?? '');
72
+ args = ['run', '--in', file, '--export', '/dev/null'];
73
+ break;
74
+ }
75
+ case 'execute':
76
+ case 'batch': {
77
+ const steps: NativeEngineStep[] = request.action === 'execute'
78
+ ? [{ id: request.command ?? '', ...(request.params ? { params: request.params } : {}) }]
79
+ : (request.steps ?? []);
80
+
81
+ args = ['run'];
82
+ if (context.project) {
83
+ args.push('--in', positional(context.project));
84
+ } else if (context.demo) {
85
+ args.push('--sample');
86
+ }
87
+
88
+ args.push(...commandArgs(steps));
89
+
90
+ if (context.saveAs) {
91
+ args.push('--export', context.saveAs);
92
+ artifacts.push(context.saveAs);
93
+ } else if (context.save && context.project) {
94
+ args.push('--export', context.project);
95
+ artifacts.push(context.project);
96
+ }
97
+
98
+ if (request.output) {
99
+ args.push('--export', request.output);
100
+ artifacts.push(request.output);
101
+ }
102
+ break;
103
+ }
104
+ case 'export': {
105
+ const output = request.output ?? '';
106
+ args = ['run', '--in', requireProject(context, 'export'), '--export', positional(output)];
107
+ artifacts = [output];
108
+ break;
109
+ }
110
+ case 'render': {
111
+ const output = request.output ?? '';
112
+ args = ['run'];
113
+ if (context.project) {
114
+ args.push('--in', positional(context.project));
115
+ } else {
116
+ args.push('--sample');
117
+ }
118
+
119
+ if (request.range) {
120
+ args.push('--page', request.range);
121
+ }
122
+
123
+ if (request.scale !== undefined) {
124
+ args.push('--scale', String(request.scale));
125
+ }
126
+
127
+ args.push('--export', positional(output));
128
+ artifacts = [output];
129
+ break;
130
+ }
131
+ default:
132
+ throw new Error(`Unsupported design engine action: ${request.action}`);
133
+ }
134
+
135
+ return {
136
+ args,
137
+ artifacts,
138
+ timeoutMs: TIMEOUTS[request.action] ?? 60_000
139
+ };
140
+ }
141
+ };