agents-relay 2.0.55 → 2.0.56
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/dist/cli-escalation.js +55 -30
- package/package.json +1 -1
package/dist/cli-escalation.js
CHANGED
|
@@ -1,37 +1,62 @@
|
|
|
1
1
|
import { spawn } from 'node:child_process';
|
|
2
|
+
import { mkdtemp, rm, writeFile } from 'node:fs/promises';
|
|
3
|
+
import { tmpdir } from 'node:os';
|
|
4
|
+
import { join } from 'node:path';
|
|
2
5
|
import { textOption, arg } from './cli-support.js';
|
|
3
6
|
import { runEscalationGraph } from './workflow/escalation.js';
|
|
4
|
-
function
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
return
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
|
|
7
|
+
export function neoEscalationArgs(handoffPath, policyPath, cwd) {
|
|
8
|
+
return [
|
|
9
|
+
'escalation', '--handoff-file', handoffPath,
|
|
10
|
+
...(policyPath ? ['--on-needs-user-file', policyPath] : []),
|
|
11
|
+
...(cwd ? ['--cwd', cwd] : []),
|
|
12
|
+
];
|
|
13
|
+
}
|
|
14
|
+
function handoffText(request) {
|
|
15
|
+
return [
|
|
16
|
+
'# Intent', request.intent.trim(),
|
|
17
|
+
'', '# Blocked on', request.blockedOn.trim(),
|
|
18
|
+
...(request.context?.trim() ? ['', '# Context', request.context.trim()] : []),
|
|
19
|
+
'',
|
|
20
|
+
].join('\n');
|
|
21
|
+
}
|
|
22
|
+
export async function runNeoEscalation(request) {
|
|
23
|
+
const tempRoot = await mkdtemp(join(tmpdir(), 'agents-relay-escalation-'));
|
|
24
|
+
try {
|
|
25
|
+
const handoffPath = join(tempRoot, 'handoff.md');
|
|
26
|
+
await writeFile(handoffPath, handoffText(request), { encoding: 'utf8', mode: 0o600 });
|
|
27
|
+
let policyPath;
|
|
28
|
+
if (request.onNeedsUser) {
|
|
29
|
+
policyPath = join(tempRoot, 'on-needs-user.md');
|
|
30
|
+
await writeFile(policyPath, request.onNeedsUser, { encoding: 'utf8', mode: 0o600 });
|
|
31
|
+
}
|
|
32
|
+
const args = neoEscalationArgs(handoffPath, policyPath, request.cwd);
|
|
33
|
+
return await new Promise((resolve, reject) => {
|
|
34
|
+
const child = spawn('neo', args, { cwd: request.cwd ?? process.cwd(), stdio: ['ignore', 'pipe', 'pipe'] });
|
|
35
|
+
let stdout = '';
|
|
36
|
+
let stderr = '';
|
|
37
|
+
child.stdout.setEncoding('utf8').on('data', chunk => { stdout += chunk; });
|
|
38
|
+
child.stderr.setEncoding('utf8').on('data', chunk => { stderr += chunk; });
|
|
39
|
+
child.on('error', reject);
|
|
40
|
+
child.on('close', code => {
|
|
41
|
+
let parsed;
|
|
42
|
+
try {
|
|
43
|
+
parsed = JSON.parse(stdout.trim());
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
reject(new Error(`neo escalation returned invalid JSON (exit ${code ?? 'unknown'}): ${stderr || stdout}`));
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
if (!['resolved', 'failed', 'needs_user'].includes(parsed.status)) {
|
|
50
|
+
reject(new Error(`neo escalation returned invalid status ${String(parsed.status)}`));
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
resolve(parsed);
|
|
54
|
+
});
|
|
33
55
|
});
|
|
34
|
-
}
|
|
56
|
+
}
|
|
57
|
+
finally {
|
|
58
|
+
await rm(tempRoot, { recursive: true, force: true });
|
|
59
|
+
}
|
|
35
60
|
}
|
|
36
61
|
export async function runEscalationCommand(args) {
|
|
37
62
|
const intent = await textOption(args, '--intent', '--intent-file');
|