agents-relay 2.0.223 → 2.0.224

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.
@@ -1,13 +1,13 @@
1
1
  import { createHash, randomUUID } from 'node:crypto';
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';
2
+ import { readFile, realpath, stat } from 'node:fs/promises';
3
+ import { resolve, relative, isAbsolute, sep, dirname, basename, join } from 'node:path';
6
4
  import { once } from 'node:events';
7
5
  import { pathToFileURL } from 'node:url';
8
6
  import { spawnOwnedProcess } from './owned-process.js';
9
7
  import { validateShortcutStageGate } from './shortcut-stage-contract.js';
10
8
  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,24 +98,50 @@ 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. */
101
103
  async function discoverShortcut(agent, projectPath, neoRoot) {
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');
104
+ let sources;
105
+ try {
106
+ ({ sources } = await resolveAgentMarkdown(agent, BUNDLED_AGENTS_ROOT, projectPath, neoRoot));
107
+ }
108
+ catch (error) {
109
+ if (error instanceof Error && error.message === `Unknown agent ${agent}`)
110
+ return null;
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}`);
109
142
  return actual;
110
143
  }
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;
144
+ return null;
119
145
  }
120
146
  export async function missingShortcutNodes(agentGraph, projectPath, neoRoot) {
121
147
  const graph = parseAgentGraph(agentGraph);
@@ -197,7 +223,7 @@ export async function runAgentShortcut(options) {
197
223
  const path = await discoverShortcut(node.agent, projectReal, neoRoot);
198
224
  return { nodeId: node.id, path, hash: path ? digestBytes(await readFile(path)) : 'missing' };
199
225
  }));
200
- const shortcutHash = digest(canonical(shortcuts.map(item => [item.nodeId, item.hash])));
226
+ const shortcutHash = digest(canonical(shortcuts.map(item => [item.nodeId, item.path, item.hash])));
201
227
  const transitions = new DurableTaskTransitionRuntime(store);
202
228
  const owner = `shortcut-${process.pid}-${randomUUID()}`;
203
229
  let currentJob = await store.load(job.id);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agents-relay",
3
- "version": "2.0.223",
3
+ "version": "2.0.224",
4
4
  "description": "Durable async agent jobs coordinated through GitHub pull requests",
5
5
  "repository": {
6
6
  "type": "git",