@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
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { spawn } from 'node:child_process';
|
|
4
|
+
import { causyneHome, resolveUserPath } from '../utils/paths.js';
|
|
5
|
+
import { filmEngine } from './film.js';
|
|
6
|
+
import { deckEngine } from './deck.js';
|
|
7
|
+
import { photoEngine } from './photo.js';
|
|
8
|
+
import { soundEngine } from './sound.js';
|
|
9
|
+
import { cadEngine } from './cad.js';
|
|
10
|
+
import { designEngine } from './design.js';
|
|
11
|
+
import { wordEngine } from './word.js';
|
|
12
|
+
import { gridEngine } from './grid.js';
|
|
13
|
+
import { lightEngine } from './light.js';
|
|
14
|
+
import { pdfEngine } from './pdf.js';
|
|
15
|
+
import { effectEngine } from './effect.js';
|
|
16
|
+
import type { NativeEngineAdapter, NativeEngineRun } from './types.js';
|
|
17
|
+
|
|
18
|
+
const MAX_STDOUT = 8 * 1024 * 1024;
|
|
19
|
+
const MAX_STDERR = 1024 * 1024;
|
|
20
|
+
|
|
21
|
+
export const NATIVE_ENGINES: Record<string, NativeEngineAdapter> = {
|
|
22
|
+
[filmEngine.id]: filmEngine,
|
|
23
|
+
[deckEngine.id]: deckEngine,
|
|
24
|
+
[photoEngine.id]: photoEngine,
|
|
25
|
+
[soundEngine.id]: soundEngine,
|
|
26
|
+
[cadEngine.id]: cadEngine,
|
|
27
|
+
[designEngine.id]: designEngine,
|
|
28
|
+
[wordEngine.id]: wordEngine,
|
|
29
|
+
[gridEngine.id]: gridEngine,
|
|
30
|
+
[lightEngine.id]: lightEngine,
|
|
31
|
+
[pdfEngine.id]: pdfEngine,
|
|
32
|
+
[effectEngine.id]: effectEngine
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export function nativeEngine(id: string): NativeEngineAdapter | null {
|
|
36
|
+
return NATIVE_ENGINES[id] ?? null;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function engineInstallDir(adapter: NativeEngineAdapter): string {
|
|
40
|
+
return path.join(causyneHome(), 'engines', adapter.id);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function inside(root: string, target: string): boolean {
|
|
44
|
+
const relative = path.relative(root, target);
|
|
45
|
+
return relative !== '..' && !relative.startsWith(`..${path.sep}`) && !path.isAbsolute(relative);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function currentEngineBinary(adapter: NativeEngineAdapter): string | null {
|
|
49
|
+
const root = engineInstallDir(adapter);
|
|
50
|
+
const suffix = process.platform === 'win32' ? '.exe' : '';
|
|
51
|
+
try {
|
|
52
|
+
const value = JSON.parse(fs.readFileSync(path.join(root, 'current.json'), 'utf8')) as Record<string, unknown>;
|
|
53
|
+
if (typeof value.version !== 'string' || !/^[0-9A-Za-z][0-9A-Za-z._+-]{0,63}$/.test(value.version)) return null;
|
|
54
|
+
if (typeof value.platform !== 'string' || !/^[a-z0-9]+-[a-z0-9]+$/.test(value.platform)) return null;
|
|
55
|
+
const file = path.join(root, 'versions', value.version, value.platform, `${adapter.binaryName}${suffix}`);
|
|
56
|
+
return inside(root, file) ? file : null;
|
|
57
|
+
} catch {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function engineBinaryCandidates(adapter: NativeEngineAdapter): string[] {
|
|
63
|
+
const suffix = process.platform === 'win32' ? '.exe' : '';
|
|
64
|
+
const name = `${adapter.binaryName}${suffix}`;
|
|
65
|
+
const root = engineInstallDir(adapter);
|
|
66
|
+
return [
|
|
67
|
+
path.join(root, 'current', 'bin', name),
|
|
68
|
+
path.join(root, 'current', name),
|
|
69
|
+
path.join(root, 'bin', name),
|
|
70
|
+
path.join(root, name)
|
|
71
|
+
];
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function executable(file: string): boolean {
|
|
75
|
+
try {
|
|
76
|
+
if (!fs.statSync(file).isFile()) return false;
|
|
77
|
+
if (process.platform === 'win32') return true;
|
|
78
|
+
fs.accessSync(file, fs.constants.X_OK);
|
|
79
|
+
return true;
|
|
80
|
+
} catch {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function isShebangScript(file: string): boolean {
|
|
86
|
+
try {
|
|
87
|
+
const fd = fs.openSync(file, 'r');
|
|
88
|
+
const buf = Buffer.alloc(2);
|
|
89
|
+
const read = fs.readSync(fd, buf, 0, 2, 0);
|
|
90
|
+
fs.closeSync(fd);
|
|
91
|
+
return read === 2 && buf[0] === 0x23 && buf[1] === 0x21;
|
|
92
|
+
} catch {
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export function findEngineBinary(adapter: NativeEngineAdapter): string | null {
|
|
98
|
+
const override = process.env[adapter.envVar];
|
|
99
|
+
if (override && override.trim()) {
|
|
100
|
+
const candidate = resolveUserPath(override.trim());
|
|
101
|
+
const file = (() => {
|
|
102
|
+
try { return fs.statSync(candidate).isDirectory(); } catch { return false; }
|
|
103
|
+
})() ? path.join(candidate, adapter.binaryName + (process.platform === 'win32' ? '.exe' : '')) : candidate;
|
|
104
|
+
if (executable(file)) return fs.realpathSync(file);
|
|
105
|
+
}
|
|
106
|
+
const current = currentEngineBinary(adapter);
|
|
107
|
+
if (current && executable(current)) return fs.realpathSync(current);
|
|
108
|
+
for (const candidate of engineBinaryCandidates(adapter)) {
|
|
109
|
+
if (executable(candidate)) return fs.realpathSync(candidate);
|
|
110
|
+
}
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function childEnv(): NodeJS.ProcessEnv {
|
|
115
|
+
const keys = [
|
|
116
|
+
'PATH', 'HOME', 'USERPROFILE', 'SystemRoot', 'SYSTEMROOT', 'TEMP', 'TMP', 'TMPDIR',
|
|
117
|
+
'LANG', 'LC_ALL', 'LC_CTYPE', 'TZ', 'XDG_CONFIG_HOME', 'XDG_DATA_HOME', 'XDG_CACHE_HOME'
|
|
118
|
+
];
|
|
119
|
+
const env: NodeJS.ProcessEnv = {};
|
|
120
|
+
for (const key of keys) {
|
|
121
|
+
const value = process.env[key];
|
|
122
|
+
if (value !== undefined) env[key] = value;
|
|
123
|
+
}
|
|
124
|
+
env.NO_COLOR = '1';
|
|
125
|
+
return env;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export function runEngineBinary(
|
|
129
|
+
binary: string,
|
|
130
|
+
args: string[],
|
|
131
|
+
options: { cwd: string; timeoutMs: number; stdin?: string; signal?: AbortSignal }
|
|
132
|
+
): Promise<NativeEngineRun> {
|
|
133
|
+
options.signal?.throwIfAborted();
|
|
134
|
+
const isScript = process.platform === 'win32' && isShebangScript(binary);
|
|
135
|
+
const command = isScript ? process.execPath : binary;
|
|
136
|
+
const commandArgs = isScript ? [binary, ...args] : args;
|
|
137
|
+
|
|
138
|
+
return new Promise((resolve, reject) => {
|
|
139
|
+
const child = spawn(command, commandArgs, {
|
|
140
|
+
cwd: options.cwd,
|
|
141
|
+
env: childEnv(),
|
|
142
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
143
|
+
windowsHide: true,
|
|
144
|
+
...(options.signal ? { signal: options.signal } : {})
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
let stdout = '';
|
|
148
|
+
let stderr = '';
|
|
149
|
+
let settled = false;
|
|
150
|
+
let timer: NodeJS.Timeout | undefined;
|
|
151
|
+
const finish = (run: NativeEngineRun): void => {
|
|
152
|
+
if (settled) return;
|
|
153
|
+
settled = true;
|
|
154
|
+
if (timer) clearTimeout(timer);
|
|
155
|
+
resolve(run);
|
|
156
|
+
};
|
|
157
|
+
const fail = (error: Error): void => {
|
|
158
|
+
if (settled) return;
|
|
159
|
+
settled = true;
|
|
160
|
+
if (timer) clearTimeout(timer);
|
|
161
|
+
reject(error);
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
child.stdout.on('data', (chunk: Buffer) => {
|
|
165
|
+
if (stdout.length + chunk.length > MAX_STDOUT) {
|
|
166
|
+
child.kill('SIGKILL');
|
|
167
|
+
stderr += '\nEngine output exceeded the 8 MB limit.';
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
stdout += chunk.toString('utf8');
|
|
171
|
+
});
|
|
172
|
+
child.stderr.on('data', (chunk: Buffer) => {
|
|
173
|
+
if (stderr.length < MAX_STDERR) stderr += chunk.toString('utf8');
|
|
174
|
+
});
|
|
175
|
+
child.on('error', fail);
|
|
176
|
+
if (options.stdin !== undefined) {
|
|
177
|
+
child.stdin.on('error', () => {});
|
|
178
|
+
child.stdin.end(options.stdin);
|
|
179
|
+
} else {
|
|
180
|
+
child.stdin.end();
|
|
181
|
+
}
|
|
182
|
+
child.on('close', (code, signal) => {
|
|
183
|
+
const exitCode = typeof code === 'number' ? code : signal ? 1 : 0;
|
|
184
|
+
if (stderr.length > MAX_STDERR) stderr = stderr.slice(0, MAX_STDERR) + '\n...(stderr truncated)';
|
|
185
|
+
finish({ exitCode, stdout, stderr });
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
timer = setTimeout(() => {
|
|
189
|
+
stderr += `\nEngine timed out after ${options.timeoutMs} ms.`;
|
|
190
|
+
child.kill('SIGKILL');
|
|
191
|
+
}, options.timeoutMs);
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
export async function engineVersion(binary: string, workspace: string, signal?: AbortSignal): Promise<string | null> {
|
|
196
|
+
const run = await runEngineBinary(binary, ['--version'], { cwd: workspace, timeoutMs: 10_000, ...(signal ? { signal } : {}) });
|
|
197
|
+
const match = run.stdout.match(/\b(\d+\.\d+(?:\.\d+)?)\b/);
|
|
198
|
+
return match?.[1] ?? null;
|
|
199
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
// Audio engine for Causyne Agent (headless multi-track audio workstation, bounce, and conversion).
|
|
3
|
+
// 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 soundEngine = {
|
|
37
|
+
id: 'sound',
|
|
38
|
+
label: 'Causyne Sound Engine',
|
|
39
|
+
envVar: 'CAUSYNE_ENGINE_SOUND',
|
|
40
|
+
binaryName: 'causyne-engine-sound',
|
|
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 = ['describe', 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('--in', positional(context.project));
|
|
69
|
+
}
|
|
70
|
+
else if (context.demo) {
|
|
71
|
+
args.push('--demo');
|
|
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('--bounce', 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
|
+
// Bounce session mix to output audio file
|
|
96
|
+
const output = request.output ?? '';
|
|
97
|
+
args = ['run'];
|
|
98
|
+
if (context.project) {
|
|
99
|
+
args.push('--in', positional(context.project));
|
|
100
|
+
}
|
|
101
|
+
else if (context.demo) {
|
|
102
|
+
args.push('--demo');
|
|
103
|
+
}
|
|
104
|
+
args.push('--bounce', positional(output));
|
|
105
|
+
if (request.start !== undefined)
|
|
106
|
+
args.push('--start', String(request.start));
|
|
107
|
+
if (request.end !== undefined)
|
|
108
|
+
args.push('--end', String(request.end));
|
|
109
|
+
artifacts = [output];
|
|
110
|
+
break;
|
|
111
|
+
}
|
|
112
|
+
default:
|
|
113
|
+
throw new Error(`Unsupported sound engine action: ${request.action}`);
|
|
114
|
+
}
|
|
115
|
+
return { args, artifacts: artifacts.filter(Boolean), timeoutMs: TIMEOUTS[request.action] };
|
|
116
|
+
}
|
|
117
|
+
};
|
|
@@ -0,0 +1,130 @@
|
|
|
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
|
+
// Audio engine for Causyne Agent (headless multi-track audio workstation, bounce, and conversion).
|
|
12
|
+
// 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 soundEngine: NativeEngineAdapter = {
|
|
49
|
+
id: 'sound',
|
|
50
|
+
label: 'Causyne Sound Engine',
|
|
51
|
+
envVar: 'CAUSYNE_ENGINE_SOUND',
|
|
52
|
+
binaryName: 'causyne-engine-sound',
|
|
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 = ['describe', 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('--in', positional(context.project));
|
|
83
|
+
} else if (context.demo) {
|
|
84
|
+
args.push('--demo');
|
|
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('--bounce', 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
|
+
// Bounce session mix to output audio file
|
|
111
|
+
const output = request.output ?? '';
|
|
112
|
+
args = ['run'];
|
|
113
|
+
if (context.project) {
|
|
114
|
+
args.push('--in', positional(context.project));
|
|
115
|
+
} else if (context.demo) {
|
|
116
|
+
args.push('--demo');
|
|
117
|
+
}
|
|
118
|
+
args.push('--bounce', positional(output));
|
|
119
|
+
if (request.start !== undefined) args.push('--start', String(request.start));
|
|
120
|
+
if (request.end !== undefined) args.push('--end', String(request.end));
|
|
121
|
+
artifacts = [output];
|
|
122
|
+
break;
|
|
123
|
+
}
|
|
124
|
+
default:
|
|
125
|
+
throw new Error(`Unsupported sound engine action: ${request.action}`);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return { args, artifacts: artifacts.filter(Boolean), timeoutMs: TIMEOUTS[request.action] };
|
|
129
|
+
}
|
|
130
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
export type NativeEngineAction =
|
|
2
|
+
| 'status'
|
|
3
|
+
| 'catalog'
|
|
4
|
+
| 'describe'
|
|
5
|
+
| 'inspect'
|
|
6
|
+
| 'execute'
|
|
7
|
+
| 'batch'
|
|
8
|
+
| 'export'
|
|
9
|
+
| 'render'
|
|
10
|
+
| 'probe'
|
|
11
|
+
| 'install';
|
|
12
|
+
|
|
13
|
+
export interface NativeEngineStep {
|
|
14
|
+
id: string;
|
|
15
|
+
params?: Record<string, unknown>;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface NativeEngineRequest {
|
|
19
|
+
engine: string;
|
|
20
|
+
action: NativeEngineAction;
|
|
21
|
+
command?: string;
|
|
22
|
+
params?: Record<string, unknown>;
|
|
23
|
+
steps?: NativeEngineStep[];
|
|
24
|
+
project?: string;
|
|
25
|
+
saveAs?: string;
|
|
26
|
+
save?: boolean;
|
|
27
|
+
demo?: boolean;
|
|
28
|
+
output?: string;
|
|
29
|
+
preset?: string;
|
|
30
|
+
format?: string;
|
|
31
|
+
seconds?: number;
|
|
32
|
+
scale?: number;
|
|
33
|
+
quality?: number;
|
|
34
|
+
range?: string;
|
|
35
|
+
start?: number;
|
|
36
|
+
end?: number;
|
|
37
|
+
allowOffline?: boolean;
|
|
38
|
+
keepGoing?: boolean;
|
|
39
|
+
query?: string;
|
|
40
|
+
open?: boolean;
|
|
41
|
+
confirm?: boolean;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface NativeEngineContext {
|
|
45
|
+
workspace: string;
|
|
46
|
+
project?: string;
|
|
47
|
+
saveAs?: string;
|
|
48
|
+
save: boolean;
|
|
49
|
+
demo: boolean;
|
|
50
|
+
keepGoing: boolean;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export interface NativeEngineInvocation {
|
|
54
|
+
args: string[];
|
|
55
|
+
stdin?: string;
|
|
56
|
+
artifacts: string[];
|
|
57
|
+
timeoutMs: number;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export interface NativeEngineAdapter {
|
|
61
|
+
id: string;
|
|
62
|
+
label: string;
|
|
63
|
+
envVar: string;
|
|
64
|
+
binaryName: string;
|
|
65
|
+
actions: readonly NativeEngineAction[];
|
|
66
|
+
invoke(request: NativeEngineRequest, context: NativeEngineContext): NativeEngineInvocation;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export interface NativeEngineRun {
|
|
70
|
+
exitCode: number;
|
|
71
|
+
stdout: string;
|
|
72
|
+
stderr: string;
|
|
73
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
// Document typesetting, DOCX/PDF formatting, and text processing engine for Causyne Agent.
|
|
3
|
+
// Headless word processor, document structural inspector, and batch runner.
|
|
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 wordEngine = {
|
|
38
|
+
id: 'word',
|
|
39
|
+
label: 'Causyne Word Engine',
|
|
40
|
+
envVar: 'CAUSYNE_ENGINE_WORD',
|
|
41
|
+
binaryName: 'causyne-engine-word',
|
|
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', '--json'];
|
|
52
|
+
break;
|
|
53
|
+
case 'describe':
|
|
54
|
+
args = ['commands', '--json'];
|
|
55
|
+
break;
|
|
56
|
+
case 'inspect':
|
|
57
|
+
args = ['info', requireProject(context, 'inspect')];
|
|
58
|
+
break;
|
|
59
|
+
case 'probe':
|
|
60
|
+
args = ['info', positional(request.query ?? '')];
|
|
61
|
+
break;
|
|
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('--file', positional(context.project));
|
|
70
|
+
}
|
|
71
|
+
else if (context.demo) {
|
|
72
|
+
args.push('--template', 'blank');
|
|
73
|
+
}
|
|
74
|
+
args.push(...commandArgs(steps));
|
|
75
|
+
if (context.saveAs) {
|
|
76
|
+
args.push('--save', context.saveAs);
|
|
77
|
+
artifacts.push(context.saveAs);
|
|
78
|
+
}
|
|
79
|
+
else if (context.save && context.project) {
|
|
80
|
+
args.push('--save', context.project);
|
|
81
|
+
artifacts.push(context.project);
|
|
82
|
+
}
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
case 'export': {
|
|
86
|
+
const output = request.output ?? '';
|
|
87
|
+
args = ['convert', requireProject(context, 'export'), positional(output)];
|
|
88
|
+
artifacts = [output];
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
case 'render': {
|
|
92
|
+
const output = request.output ?? '';
|
|
93
|
+
args = ['render', requireProject(context, 'render'), positional(output)];
|
|
94
|
+
if (request.range) {
|
|
95
|
+
args.push('--page', request.range);
|
|
96
|
+
}
|
|
97
|
+
if (request.scale !== undefined) {
|
|
98
|
+
args.push('--scale', String(request.scale));
|
|
99
|
+
}
|
|
100
|
+
artifacts = [output];
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
default:
|
|
104
|
+
throw new Error(`Unsupported word engine action: ${request.action}`);
|
|
105
|
+
}
|
|
106
|
+
return {
|
|
107
|
+
args,
|
|
108
|
+
artifacts,
|
|
109
|
+
timeoutMs: TIMEOUTS[request.action] ?? 60_000
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
};
|