agents-relay 2.0.224 → 2.0.225
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/agent-shortcut.js +20 -46
- package/package.json +1 -1
package/dist/agent-shortcut.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { createHash, randomUUID } from 'node:crypto';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { existsSync } from 'node:fs';
|
|
3
|
+
import { readFile } from 'node:fs/promises';
|
|
4
|
+
import { resolve, relative, isAbsolute, sep, dirname } from 'node:path';
|
|
5
|
+
import { realpath } from 'node:fs/promises';
|
|
4
6
|
import { once } from 'node:events';
|
|
5
7
|
import { pathToFileURL } from 'node:url';
|
|
6
8
|
import { spawnOwnedProcess } from './owned-process.js';
|
|
7
9
|
import { validateShortcutStageGate } from './shortcut-stage-contract.js';
|
|
8
10
|
import { parseAgentGraph } from './agent-graph.js';
|
|
9
|
-
import { resolveAgentMarkdown } from './agent-content-resolver.js';
|
|
10
|
-
import { BUNDLED_AGENTS_ROOT } from './execution-context.js';
|
|
11
11
|
import { DurableTaskTransitionRuntime } from './workflow/durable-transition.js';
|
|
12
12
|
import { dispatchJobLifecycleSync } from './workflow/lifecycle.js';
|
|
13
13
|
import { dependencyReady, tryTransitionTaskEvent } from './task-transitions.js';
|
|
@@ -98,50 +98,24 @@ async function runCommand(args, cwd, signal) {
|
|
|
98
98
|
const [code] = await once(child, 'close');
|
|
99
99
|
return { stdout, stderr, code: code ?? -1 };
|
|
100
100
|
}
|
|
101
|
-
/** A Shortcut belongs to an Agent source, not to an independent name search.
|
|
102
|
-
* Only explicit Agent inheritance permits falling back to a parent's Shortcut. */
|
|
103
101
|
async function discoverShortcut(agent, projectPath, neoRoot) {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
if (
|
|
110
|
-
|
|
111
|
-
throw error;
|
|
112
|
-
}
|
|
113
|
-
for (const source of [...sources].reverse()) {
|
|
114
|
-
const agentDir = dirname(source);
|
|
115
|
-
const name = basename(source).replace(/(?:\.agent)?\.md$/, '');
|
|
116
|
-
const shortcutDir = join(agentDir, '.shortcut');
|
|
117
|
-
let shortcutRoot;
|
|
118
|
-
try {
|
|
119
|
-
shortcutRoot = await realpath(shortcutDir);
|
|
120
|
-
}
|
|
121
|
-
catch (error) {
|
|
122
|
-
if (error.code === 'ENOENT')
|
|
123
|
-
continue;
|
|
124
|
-
throw error;
|
|
125
|
-
}
|
|
126
|
-
if (shortcutRoot !== shortcutDir)
|
|
127
|
-
throw new Error(`Agent shortcut directory symlink escapes Agent source: ${shortcutDir}`);
|
|
128
|
-
const candidate = join(shortcutDir, `${name}.agent.mjs`);
|
|
129
|
-
let actual;
|
|
130
|
-
try {
|
|
131
|
-
actual = await realpath(candidate);
|
|
132
|
-
}
|
|
133
|
-
catch (error) {
|
|
134
|
-
if (error.code === 'ENOENT')
|
|
135
|
-
continue;
|
|
136
|
-
throw error;
|
|
137
|
-
}
|
|
138
|
-
if (dirname(actual) !== shortcutRoot)
|
|
139
|
-
throw new Error(`Agent shortcut symlink escapes source directory: ${candidate}`);
|
|
140
|
-
if (!(await stat(actual)).isFile())
|
|
141
|
-
throw new Error(`Agent shortcut is not a regular file: ${candidate}`);
|
|
102
|
+
const file = `${agent}.agent.mjs`;
|
|
103
|
+
const root = await realpath(projectPath);
|
|
104
|
+
const project = resolve(root, 'agents', '.shortcut', file);
|
|
105
|
+
if (existsSync(project)) {
|
|
106
|
+
const actual = await realpath(project);
|
|
107
|
+
if (!inside(root, actual))
|
|
108
|
+
throw new Error('Project shortcut symlink escapes project root');
|
|
142
109
|
return actual;
|
|
143
110
|
}
|
|
144
|
-
|
|
111
|
+
const shared = neoRoot ? resolve(neoRoot, 'agents', '.shortcut', file) : null;
|
|
112
|
+
if (!shared || !existsSync(shared))
|
|
113
|
+
return null;
|
|
114
|
+
const sharedRoot = await realpath(resolve(neoRoot, 'agents', '.shortcut'));
|
|
115
|
+
const actual = await realpath(shared);
|
|
116
|
+
if (!inside(sharedRoot, actual))
|
|
117
|
+
throw new Error('Shared shortcut symlink escapes shortcut root');
|
|
118
|
+
return actual;
|
|
145
119
|
}
|
|
146
120
|
export async function missingShortcutNodes(agentGraph, projectPath, neoRoot) {
|
|
147
121
|
const graph = parseAgentGraph(agentGraph);
|
|
@@ -223,7 +197,7 @@ export async function runAgentShortcut(options) {
|
|
|
223
197
|
const path = await discoverShortcut(node.agent, projectReal, neoRoot);
|
|
224
198
|
return { nodeId: node.id, path, hash: path ? digestBytes(await readFile(path)) : 'missing' };
|
|
225
199
|
}));
|
|
226
|
-
const shortcutHash = digest(canonical(shortcuts.map(item => [item.nodeId, item.
|
|
200
|
+
const shortcutHash = digest(canonical(shortcuts.map(item => [item.nodeId, item.hash])));
|
|
227
201
|
const transitions = new DurableTaskTransitionRuntime(store);
|
|
228
202
|
const owner = `shortcut-${process.pid}-${randomUUID()}`;
|
|
229
203
|
let currentJob = await store.load(job.id);
|