@causyne/agent 1.10.21 → 1.12.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 (82) hide show
  1. package/docs/THIRD_PARTY_NOTICES.md +12 -0
  2. package/native-skills/media/professional-document-publishing/SKILL.md +44 -0
  3. package/native-skills/media/screenplay-and-shotlist-forge/SKILL.md +42 -0
  4. package/package.json +1 -1
  5. package/src/acp/client.js +235 -0
  6. package/src/acp/client.ts +282 -0
  7. package/src/acp/peerProfiles.js +122 -0
  8. package/src/acp/peerProfiles.ts +128 -0
  9. package/src/acp/protocol.js +55 -0
  10. package/src/acp/protocol.ts +456 -0
  11. package/src/acp/server.js +746 -0
  12. package/src/acp/server.ts +822 -0
  13. package/src/agentLoop.d.ts +64 -0
  14. package/src/agentLoop.js +156 -12
  15. package/src/approvalGrants.js +33 -0
  16. package/src/approvalGrants.ts +50 -0
  17. package/src/commands.js +203 -0
  18. package/src/compiledSkills.js +10 -0
  19. package/src/decisionPolicy.js +2 -0
  20. package/src/decisionPolicy.ts +1 -0
  21. package/src/documentEngine/antiSlopAuditor.js +156 -0
  22. package/src/documentEngine/antiSlopAuditor.ts +221 -0
  23. package/src/documentEngine/documentForge.js +443 -0
  24. package/src/documentEngine/documentForge.ts +519 -0
  25. package/src/documentEngine/screenplayFormatter.js +336 -0
  26. package/src/documentEngine/screenplayFormatter.ts +407 -0
  27. package/src/engines/cad.js +113 -0
  28. package/src/engines/cad.ts +128 -0
  29. package/src/engines/film.js +108 -0
  30. package/src/engines/film.ts +104 -0
  31. package/src/engines/installer.js +226 -0
  32. package/src/engines/installer.ts +248 -0
  33. package/src/engines/photo.js +126 -0
  34. package/src/engines/photo.ts +137 -0
  35. package/src/engines/registry.js +186 -0
  36. package/src/engines/registry.ts +185 -0
  37. package/src/engines/sound.js +117 -0
  38. package/src/engines/sound.ts +130 -0
  39. package/src/engines/types.js +1 -0
  40. package/src/engines/types.ts +73 -0
  41. package/src/entrypoint.js +13 -0
  42. package/src/execSafe.js +10 -13
  43. package/src/execSafe.ts +25 -0
  44. package/src/memoryManager.js +9 -3
  45. package/src/modelRouter.js +56 -123
  46. package/src/modelRouter.ts +134 -0
  47. package/src/observer/advisory.js +164 -0
  48. package/src/observer/advisory.ts +171 -0
  49. package/src/observer/coldObserver.js +462 -0
  50. package/src/observer/coldObserver.ts +540 -0
  51. package/src/observer/evidence.js +435 -0
  52. package/src/observer/evidence.ts +499 -0
  53. package/src/perception.js +303 -118
  54. package/src/perception.ts +387 -0
  55. package/src/procSignal.js +15 -16
  56. package/src/procSignal.ts +31 -0
  57. package/src/promptMentions.js +170 -0
  58. package/src/promptMentions.ts +212 -0
  59. package/src/sandbox.js +9 -1
  60. package/src/sessionJournal.js +12 -2
  61. package/src/sessionJournal.ts +12 -2
  62. package/src/textDiff.js +117 -109
  63. package/src/textDiff.ts +169 -0
  64. package/src/toolPacks.js +19 -8
  65. package/src/tools/documentForge.js +215 -0
  66. package/src/tools/documentForge.ts +265 -0
  67. package/src/tools/generateMediaViaApi.js +1 -1
  68. package/src/tools/nativeEngine.js +464 -0
  69. package/src/tools/nativeEngine.ts +433 -0
  70. package/src/tools/openSourceToolProvisioner.js +510 -0
  71. package/src/tools/openSourceToolProvisioner.ts +590 -0
  72. package/src/tools/peerAgent.js +102 -0
  73. package/src/tools/peerAgent.ts +116 -0
  74. package/src/tools/registry.js +6 -1
  75. package/src/tui/completion.js +98 -42
  76. package/src/tui/prompt.js +17 -17
  77. package/src/uncertainty.js +93 -205
  78. package/src/uncertainty.ts +255 -0
  79. package/src/utils/paths.js +15 -18
  80. package/src/utils/paths.ts +36 -0
  81. package/src/vfeTracker.js +122 -181
  82. package/src/vfeTracker.ts +242 -0
@@ -0,0 +1,433 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { spawn } from 'node:child_process';
4
+ import {
5
+ NATIVE_ENGINES,
6
+ engineInstallDir,
7
+ findEngineBinary,
8
+ engineVersion,
9
+ nativeEngine,
10
+ runEngineBinary
11
+ } from '../engines/registry.js';
12
+ import { defaultEngineManifestUrl, installNativeEngine } from '../engines/installer.js';
13
+ import type {
14
+ NativeEngineAction,
15
+ NativeEngineAdapter,
16
+ NativeEngineContext,
17
+ NativeEngineRequest,
18
+ NativeEngineStep
19
+ } from '../engines/types.js';
20
+
21
+ const ACTIONS: readonly NativeEngineAction[] = [
22
+ 'status', 'catalog', 'describe', 'inspect', 'execute', 'batch', 'export', 'render', 'probe', 'install'
23
+ ];
24
+ const PATH_KEYS = new Set([
25
+ 'path', 'paths', 'file', 'files', 'input', 'source', 'destination', 'media',
26
+ 'directory', 'dir', 'output', 'outputPath', 'out', 'outputFile'
27
+ ]);
28
+ const OUTPUT_KEYS = new Set(['output', 'outputPath', 'out', 'outputFile']);
29
+
30
+ type ToolContext = {
31
+ signal?: AbortSignal;
32
+ workspacePaths?: string[];
33
+ };
34
+
35
+ function object(value: unknown, name: string): Record<string, unknown> {
36
+ if (!value || typeof value !== 'object' || Array.isArray(value)) throw new Error(`${name} must be an object`);
37
+ return value as Record<string, unknown>;
38
+ }
39
+
40
+ function text(value: unknown, name: string, max = 4096): string {
41
+ if (typeof value !== 'string' || !value.trim() || value.length > max || value.includes('\0') || /[\x00-\x1f]/.test(value)) {
42
+ throw new Error(`Invalid ${name}`);
43
+ }
44
+ return value;
45
+ }
46
+
47
+ function optionalText(value: unknown, name: string, max = 4096): string | undefined {
48
+ if (value === undefined) return undefined;
49
+ return text(value, name, max);
50
+ }
51
+
52
+ function boolean(value: unknown, name: string): boolean | undefined {
53
+ if (value === undefined) return undefined;
54
+ if (typeof value !== 'boolean') throw new Error(`${name} must be a boolean`);
55
+ return value;
56
+ }
57
+
58
+ function number(value: unknown, name: string, min: number, max: number): number | undefined {
59
+ if (value === undefined) return undefined;
60
+ if (typeof value !== 'number' || !Number.isFinite(value) || value < min || value > max) {
61
+ throw new Error(`${name} must be between ${min} and ${max}`);
62
+ }
63
+ return value;
64
+ }
65
+
66
+ function inside(root: string, target: string): boolean {
67
+ const relative = path.relative(root, target);
68
+ return relative !== '..' && !relative.startsWith(`..${path.sep}`) && !path.isAbsolute(relative);
69
+ }
70
+
71
+ function nearestExisting(target: string): string {
72
+ let current = target;
73
+ while (!fs.existsSync(current)) {
74
+ const parent = path.dirname(current);
75
+ if (parent === current) break;
76
+ current = parent;
77
+ }
78
+ return current;
79
+ }
80
+
81
+ function resolveExisting(root: string, value: string, name: string): string {
82
+ const target = path.resolve(root, value);
83
+ if (!fs.existsSync(target)) throw new Error(`${name} does not exist: ${value}`);
84
+ if (!fs.statSync(target).isFile()) throw new Error(`${name} must be a file`);
85
+ const actual = fs.realpathSync(target);
86
+ if (!inside(root, actual)) throw new Error(`${name} must stay inside the workspace`);
87
+ return actual;
88
+ }
89
+
90
+ function resolveNew(root: string, value: string, name: string): string {
91
+ const target = path.resolve(root, value);
92
+ try {
93
+ fs.lstatSync(target);
94
+ throw new Error(`${name} already exists; select a new path`);
95
+ } catch (error) {
96
+ if ((error as NodeJS.ErrnoException).code !== 'ENOENT') throw error;
97
+ }
98
+ const existing = nearestExisting(path.dirname(target));
99
+ const actualBase = fs.realpathSync(existing);
100
+ const actual = path.join(actualBase, path.relative(existing, target));
101
+ if (!inside(root, actual)) throw new Error(`${name} must stay inside the workspace`);
102
+ return actual;
103
+ }
104
+
105
+ function resolveForParams(root: string, value: string, name: string, isOutput: boolean): string {
106
+ const target = path.resolve(root, value);
107
+ const existing = nearestExisting(target);
108
+ const actualBase = fs.realpathSync(existing);
109
+ const actual = path.join(actualBase, path.relative(existing, target));
110
+ if (!inside(root, actual)) throw new Error(`${name} must stay inside the workspace`);
111
+ if (isOutput && fs.existsSync(actual)) throw new Error(`${name} already exists; select a new path`);
112
+ return actual;
113
+ }
114
+
115
+ function validateParamPaths(value: unknown, root: string, key: string, depth: number, seen: { count: number }): void {
116
+ if (depth > 8) throw new Error('Engine parameters are nested too deeply');
117
+ if (++seen.count > 2000) throw new Error('Engine parameters are too large');
118
+ if (typeof value === 'string') {
119
+ if (!PATH_KEYS.has(key)) return;
120
+ if (!value.trim() || value.includes('\0')) throw new Error(`Invalid ${key}`);
121
+ resolveForParams(root, value, key, OUTPUT_KEYS.has(key));
122
+ return;
123
+ }
124
+ if (Array.isArray(value)) {
125
+ for (const item of value) validateParamPaths(item, root, key, depth + 1, seen);
126
+ return;
127
+ }
128
+ if (value && typeof value === 'object') {
129
+ for (const [childKey, child] of Object.entries(value)) {
130
+ validateParamPaths(child, root, childKey, depth + 1, seen);
131
+ }
132
+ }
133
+ }
134
+
135
+ function workspaceFrom(context: ToolContext): string {
136
+ const candidate = context.workspacePaths?.find((item): item is string => typeof item === 'string' && item.trim().length > 0);
137
+ return fs.realpathSync(path.resolve(candidate || process.cwd()));
138
+ }
139
+
140
+ function normalizeSteps(value: unknown): NativeEngineStep[] | undefined {
141
+ if (value === undefined) return undefined;
142
+ if (!Array.isArray(value) || value.length < 1 || value.length > 128) {
143
+ throw new Error('steps must contain 1..128 commands');
144
+ }
145
+ return value.map((raw, index) => {
146
+ const step = object(raw, `steps[${index}]`);
147
+ const id = text(step.id, `steps[${index}].id`, 200);
148
+ const params = step.params === undefined ? undefined : object(step.params, `steps[${index}].params`);
149
+ return params ? { id, params } : { id };
150
+ });
151
+ }
152
+
153
+ function parseRequest(value: unknown): NativeEngineRequest {
154
+ const raw = object(value, 'Native engine arguments');
155
+ const action = text(raw.action, 'action', 40) as NativeEngineAction;
156
+ if (!ACTIONS.includes(action)) throw new Error(`Unknown native engine action: ${action}`);
157
+ const engine = optionalText(raw.engine, 'engine', 64) ?? 'film';
158
+ if (!/^[a-z][a-z0-9-]*$/.test(engine)) throw new Error('Invalid engine id');
159
+
160
+ const request: NativeEngineRequest = { engine, action };
161
+ const command = optionalText(raw.command, 'command', 200);
162
+ if (command !== undefined) request.command = command;
163
+ if (raw.params !== undefined) request.params = object(raw.params, 'params');
164
+ const steps = normalizeSteps(raw.steps);
165
+ if (steps !== undefined) request.steps = steps;
166
+ const project = optionalText(raw.project, 'project');
167
+ if (project !== undefined) request.project = project;
168
+ const saveAs = optionalText(raw.saveAs, 'saveAs');
169
+ if (saveAs !== undefined) request.saveAs = saveAs;
170
+ const save = boolean(raw.save, 'save');
171
+ if (save !== undefined) request.save = save;
172
+ const demo = boolean(raw.demo, 'demo');
173
+ if (demo !== undefined) request.demo = demo;
174
+ const output = optionalText(raw.output, 'output');
175
+ if (output !== undefined) request.output = output;
176
+ const preset = optionalText(raw.preset, 'preset', 200);
177
+ if (preset !== undefined) request.preset = preset;
178
+ const format = optionalText(raw.format, 'format', 40);
179
+ if (format !== undefined) request.format = format;
180
+ const seconds = number(raw.seconds, 'seconds', 0, 86400);
181
+ if (seconds !== undefined) request.seconds = seconds;
182
+ const scale = number(raw.scale, 'scale', 0.01, 4);
183
+ if (scale !== undefined) request.scale = scale;
184
+ const quality = number(raw.quality, 'quality', 0, 100);
185
+ if (quality !== undefined) request.quality = quality;
186
+ const range = optionalText(raw.range, 'range', 20);
187
+ if (range !== undefined) request.range = range;
188
+ const start = number(raw.start, 'start', 0, 86400);
189
+ if (start !== undefined) request.start = start;
190
+ const end = number(raw.end, 'end', 0, 86400);
191
+ if (end !== undefined) request.end = end;
192
+ const allowOffline = boolean(raw.allowOffline, 'allowOffline');
193
+ if (allowOffline !== undefined) request.allowOffline = allowOffline;
194
+ const keepGoing = boolean(raw.keepGoing, 'keepGoing');
195
+ if (keepGoing !== undefined) request.keepGoing = keepGoing;
196
+ const query = optionalText(raw.query, 'query');
197
+ if (query !== undefined) request.query = query;
198
+ const open = boolean(raw.open, 'open');
199
+ if (open !== undefined) request.open = open;
200
+ const confirm = boolean(raw.confirm, 'confirm');
201
+ if (confirm !== undefined) request.confirm = confirm;
202
+ return request;
203
+ }
204
+
205
+ function validateRequest(request: NativeEngineRequest, workspace: string): NativeEngineContext {
206
+ const project = request.project ? resolveExisting(workspace, request.project, 'project') : undefined;
207
+ const saveAs = request.saveAs ? resolveNew(workspace, request.saveAs, 'saveAs') : undefined;
208
+ if (saveAs) fs.mkdirSync(path.dirname(saveAs), { recursive: true, mode: 0o700 });
209
+ if (request.demo && project) throw new Error('demo and project cannot be combined');
210
+ if (request.save && !project) throw new Error('save requires an existing project');
211
+ if (request.save && saveAs) throw new Error('save and saveAs cannot be combined');
212
+ if (request.output && (request.action === 'export' || request.action === 'render')) {
213
+ const output = resolveNew(workspace, request.output, 'output');
214
+ fs.mkdirSync(path.dirname(output), { recursive: true, mode: 0o700 });
215
+ }
216
+ if (request.action === 'execute' && !request.command) throw new Error('execute requires command');
217
+ if (request.action === 'describe' && !request.command) throw new Error('describe requires command');
218
+ if (request.action === 'batch' && !request.steps?.length) throw new Error('batch requires steps');
219
+ if (request.action === 'export' && !request.output) throw new Error('export requires output');
220
+ if (request.action === 'render' && !request.output) throw new Error('render requires output');
221
+ if (request.action === 'inspect' && request.query && !['all', 'project', 'sequence'].includes(request.query)) {
222
+ throw new Error('inspect query must be all, project, or sequence');
223
+ }
224
+ if (request.action === 'probe') {
225
+ if (!request.query) throw new Error('probe requires query (media path)');
226
+ resolveExisting(workspace, request.query, 'media');
227
+ }
228
+ if (request.range && !['entire', 'inOut', 'workArea', 'custom'].includes(request.range)) {
229
+ throw new Error('range must be entire, inOut, workArea, or custom');
230
+ }
231
+ if (request.params) validateParamPaths(request.params, workspace, 'params', 0, { count: 0 });
232
+ if (request.steps) {
233
+ for (const step of request.steps) {
234
+ if (step.params) validateParamPaths(step.params, workspace, 'params', 0, { count: 0 });
235
+ }
236
+ }
237
+ return {
238
+ workspace,
239
+ ...(project === undefined ? {} : { project }),
240
+ ...(saveAs === undefined ? {} : { saveAs }),
241
+ save: request.save === true,
242
+ demo: request.demo === true,
243
+ keepGoing: request.keepGoing === true
244
+ };
245
+ }
246
+
247
+ function relativeArtifact(workspace: string, file: string): string {
248
+ const relative = path.relative(workspace, file);
249
+ return (relative || path.basename(file)).split(path.sep).join('/');
250
+ }
251
+
252
+ function clean(text: string): string {
253
+ return text.replace(/\x1b\[[0-9;]*m/g, '').trim();
254
+ }
255
+
256
+ function parseOutput(action: NativeEngineAction, stdout: string): { data?: unknown; lines?: unknown[]; output?: string } {
257
+ const raw = clean(stdout);
258
+ if (!raw) return {};
259
+ if (action === 'batch') {
260
+ const lines = raw.split(/\r?\n/).filter(Boolean).map(line => {
261
+ try { return JSON.parse(line); } catch { return line; }
262
+ });
263
+ return { lines };
264
+ }
265
+ try {
266
+ return { data: JSON.parse(raw) };
267
+ } catch {
268
+ return { output: raw };
269
+ }
270
+ }
271
+
272
+ function reveal(file: string): Promise<boolean> {
273
+ return new Promise(resolve => {
274
+ const command = process.platform === 'darwin' ? 'open' : process.platform === 'win32' ? 'cmd.exe' : 'xdg-open';
275
+ const args = process.platform === 'win32' ? ['/c', 'start', '', file] : [file];
276
+ const child = spawn(command, args, { detached: true, stdio: 'ignore', windowsHide: true });
277
+ child.once('error', () => resolve(false));
278
+ child.once('spawn', () => {
279
+ child.unref();
280
+ resolve(true);
281
+ });
282
+ });
283
+ }
284
+
285
+ async function engineStatus(workspace: string, signal?: AbortSignal): Promise<Record<string, unknown>> {
286
+ const engines = [];
287
+ for (const adapter of Object.values(NATIVE_ENGINES)) {
288
+ const binary = findEngineBinary(adapter);
289
+ let version: string | null = null;
290
+ if (binary) {
291
+ try { version = await engineVersion(binary, workspace, signal); } catch { version = null; }
292
+ }
293
+ engines.push({
294
+ id: adapter.id,
295
+ label: adapter.label,
296
+ installed: Boolean(binary),
297
+ version,
298
+ ...(binary ? { binary } : { envVar: adapter.envVar, installDir: engineInstallDir(adapter), installAction: 'install', requiresConsent: true })
299
+ });
300
+ }
301
+ return { success: true, manifestUrl: defaultEngineManifestUrl(), engines };
302
+ }
303
+
304
+ export const nativeEngineTool = {
305
+ schema: {
306
+ name: 'native_engine',
307
+ description: 'Run an installed headless native engine directly. No MCP, no GUI automation, no screenshots. Start with status, then catalog. Use execute or batch with command ids from catalog; project/saveAs scope the document. export and render return artifact paths for immediate GUI/TUI preview. probe inspects media. If the engine is missing, install only after explicit user consent; install never downloads silently. Set open=true only when the user wants the artifact revealed in the OS.',
308
+ parameters: {
309
+ type: 'object',
310
+ properties: {
311
+ engine: { type: 'string', default: 'film', description: 'Engine id, default film. status lists installed engines.' },
312
+ action: { type: 'string', enum: [...ACTIONS] },
313
+ command: { type: 'string', description: 'Command id for execute or describe.' },
314
+ params: { type: 'object', description: 'Command parameters for execute.' },
315
+ steps: {
316
+ type: 'array',
317
+ minItems: 1,
318
+ maxItems: 128,
319
+ items: {
320
+ type: 'object',
321
+ properties: {
322
+ id: { type: 'string' },
323
+ params: { type: 'object' }
324
+ },
325
+ required: ['id'],
326
+ additionalProperties: false
327
+ },
328
+ description: 'Ordered {id, params} commands for batch.'
329
+ },
330
+ project: { type: 'string', description: 'Existing project file inside the workspace.' },
331
+ saveAs: { type: 'string', description: 'New project file inside the workspace.' },
332
+ save: { type: 'boolean', description: 'Save edits back to project.' },
333
+ demo: { type: 'boolean', description: 'Open the engine demo document.' },
334
+ output: { type: 'string', description: 'New export or render file inside the workspace.' },
335
+ preset: { type: 'string' },
336
+ format: { type: 'string' },
337
+ seconds: { type: 'number', description: 'Render position in seconds.' },
338
+ scale: { type: 'number', description: 'Render scale, default 1.' },
339
+ quality: { type: 'number' },
340
+ range: { type: 'string', enum: ['entire', 'inOut', 'workArea', 'custom'] },
341
+ start: { type: 'number' },
342
+ end: { type: 'number' },
343
+ allowOffline: { type: 'boolean' },
344
+ keepGoing: { type: 'boolean', description: 'Batch continues after a failed command.' },
345
+ query: { type: 'string', description: 'Catalog filter, inspect target, or media path for probe.' },
346
+ open: { type: 'boolean', description: 'Reveal the resulting artifact in the OS after success.' },
347
+ confirm: { type: 'boolean', description: 'Explicit consent to download and install a missing engine. install without confirm only describes the download.' }
348
+ },
349
+ required: ['action'],
350
+ additionalProperties: false
351
+ }
352
+ },
353
+ async execute(value: unknown, context: ToolContext = {}) {
354
+ let request: NativeEngineRequest | null = null;
355
+ try {
356
+ request = parseRequest(value);
357
+ const workspace = workspaceFrom(context);
358
+ if (request.action === 'status') return await engineStatus(workspace, context.signal);
359
+
360
+ const adapter: NativeEngineAdapter | null = nativeEngine(request.engine);
361
+ if (!adapter) return { success: false, error: `Unknown engine: ${request.engine}`, available: Object.keys(NATIVE_ENGINES) };
362
+ if (request.action === 'install') {
363
+ return await installNativeEngine(adapter, {
364
+ confirm: request.confirm === true,
365
+ ...(context.signal ? { signal: context.signal } : {})
366
+ });
367
+ }
368
+ if (!adapter.actions.includes(request.action)) {
369
+ return { success: false, error: `${adapter.label} does not support ${request.action}`, actions: adapter.actions };
370
+ }
371
+ const binary = findEngineBinary(adapter);
372
+ if (!binary) {
373
+ return {
374
+ success: false,
375
+ error: `${adapter.label} is not installed`,
376
+ installed: false,
377
+ envVar: adapter.envVar,
378
+ installDir: engineInstallDir(adapter),
379
+ installAction: 'install',
380
+ manifestUrl: defaultEngineManifestUrl(),
381
+ requiresConsent: true
382
+ };
383
+ }
384
+ const loopContext = validateRequest(request, workspace);
385
+ const invocation = adapter.invoke(request, loopContext);
386
+ let run;
387
+ try {
388
+ run = await runEngineBinary(binary, invocation.args, {
389
+ cwd: workspace,
390
+ timeoutMs: invocation.timeoutMs,
391
+ ...(invocation.stdin === undefined ? {} : { stdin: invocation.stdin }),
392
+ ...(context.signal ? { signal: context.signal } : {})
393
+ });
394
+ } catch (error) {
395
+ if ((error as NodeJS.ErrnoException).name === 'AbortError') throw error;
396
+ return { success: false, error: `Could not start ${adapter.label}: ${error instanceof Error ? error.message : String(error)}` };
397
+ }
398
+
399
+ const artifacts = invocation.artifacts
400
+ .map(file => path.resolve(workspace, file))
401
+ .filter(file => {
402
+ try {
403
+ const actual = fs.realpathSync(file);
404
+ return inside(workspace, actual) && fs.statSync(actual).isFile();
405
+ } catch { return false; }
406
+ })
407
+ .map(file => relativeArtifact(workspace, fs.realpathSync(file)));
408
+ let opened = false;
409
+ if (request.open && artifacts.length > 0) {
410
+ opened = await reveal(path.resolve(workspace, artifacts[0]!));
411
+ }
412
+ const parsed = parseOutput(request.action, run.stdout);
413
+ const diagnostics = clean(run.stderr);
414
+ const success = run.exitCode === 0;
415
+ return {
416
+ success,
417
+ engine: adapter.id,
418
+ action: request.action,
419
+ ...(success ? {} : { error: diagnostics.split(/\r?\n/).filter(Boolean).slice(-4).join('\n') || `Engine exited with code ${run.exitCode}`, exitCode: run.exitCode }),
420
+ ...parsed,
421
+ ...(artifacts.length > 0 ? { artifacts } : {}),
422
+ ...(opened ? { opened: true } : {}),
423
+ ...(diagnostics && success ? { diagnostics: diagnostics.slice(-4000) } : {})
424
+ };
425
+ } catch (error) {
426
+ return {
427
+ success: false,
428
+ error: error instanceof Error ? error.message : String(error),
429
+ ...(request ? { engine: request.engine, action: request.action } : {})
430
+ };
431
+ }
432
+ }
433
+ };