agents-relay 2.0.42 → 2.0.43

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,7 +1,7 @@
1
1
  import { GitHubStore } from './store.js';
2
2
  import { githubAuthContext } from './github-auth.js';
3
3
  import { registerBlockerDependency } from './blockers.js';
4
- import { arg, eventBus, publishDependentUnblocked, repository } from './cli-support.js';
4
+ import { arg, publishDependentUnblocked, repository, withEventBus } from './cli-support.js';
5
5
  import { usage } from './cli-help.js';
6
6
  export async function runBlockerCommand(action, args) {
7
7
  if (!['add', 'resolve', 'show'].includes(action))
@@ -19,7 +19,7 @@ export async function runBlockerCommand(action, args) {
19
19
  }
20
20
  if (action === 'resolve') {
21
21
  const summary = await blockerStore.resolveBlockerDependents(id, 'verified');
22
- await publishDependentUnblocked(await eventBus(args), summary.unblocked, `Blocker Job ${id} resolved (verified)`);
22
+ await withEventBus(args, bus => publishDependentUnblocked(bus, summary.unblocked, `Blocker Job ${id} resolved (verified)`));
23
23
  console.log(JSON.stringify({ blocker: id, resolution: 'verified', ...summary }, null, 2));
24
24
  return;
25
25
  }
@@ -139,6 +139,15 @@ export async function eventBus(args) {
139
139
  process.stderr.write(`${eventBusResolutionMessage(resolution)}\n`);
140
140
  return resolution.bus;
141
141
  }
142
+ export async function withEventBus(args, work, resolve = eventBus) {
143
+ const bus = await resolve(args);
144
+ try {
145
+ return await work(bus);
146
+ }
147
+ finally {
148
+ await bus?.close?.();
149
+ }
150
+ }
142
151
  export async function publishWake(bus, job, taskId, message) { if (!bus)
143
152
  return; try {
144
153
  await bus.publish(eventFor(job.id, taskId, null, 'job.wake', 'queued', message, 'orchestrator', { repository: job.repository, prNumber: job.prNumber }));
@@ -1,4 +1,4 @@
1
- import { arg, eventBus, publishTaskUnblocked, publishWake, saveLocal } from './cli-support.js';
1
+ import { arg, publishTaskUnblocked, publishWake, saveLocal, withEventBus } from './cli-support.js';
2
2
  import { isEffectivelyBlocked, unblockAutonomousTasks, unblockTask } from './unblock.js';
3
3
  export async function runTaskUnblockCommand(args, store, job, task, localFile) {
4
4
  const reason = arg(args, '--reason');
@@ -7,9 +7,10 @@ export async function runTaskUnblockCommand(args, store, job, task, localFile) {
7
7
  const result = await unblockTask({ store, job, task, trigger: { source: 'cli', reason } });
8
8
  const refreshed = await store.load(job.id);
9
9
  await saveLocal(localFile, refreshed);
10
- const bus = await eventBus(args);
11
- await publishTaskUnblocked(bus, refreshed, task.id, reason);
12
- await publishWake(bus, refreshed, task.id, `Task ${task.id} unblocked${result.replanning ? ' for replanning' : ''}`);
10
+ await withEventBus(args, async (bus) => {
11
+ await publishTaskUnblocked(bus, refreshed, task.id, reason);
12
+ await publishWake(bus, refreshed, task.id, `Task ${task.id} unblocked${result.replanning ? ' for replanning' : ''}`);
13
+ });
13
14
  console.log(JSON.stringify({ taskId: task.id, ...result, task: refreshed.tasks.find(item => item.id === task.id) }, null, 2));
14
15
  }
15
16
  export async function runJobUnblockCommand(args, store, job) {
@@ -22,19 +23,21 @@ export async function runJobUnblockCommand(args, store, job) {
22
23
  if (job.executionMode === 'autonomous') {
23
24
  const planTrigger = await unblockAutonomousTasks({ store, job, tasks: blocked, trigger: { source: 'cli', reason } });
24
25
  const refreshed = await store.load(job.id);
25
- const bus = await eventBus(args);
26
- for (const task of blocked)
27
- await publishTaskUnblocked(bus, refreshed, task.id, reason);
28
- await publishWake(bus, refreshed, 'job', `Job ${job.id} unblocked for replanning`);
26
+ await withEventBus(args, async (bus) => {
27
+ for (const task of blocked)
28
+ await publishTaskUnblocked(bus, refreshed, task.id, reason);
29
+ await publishWake(bus, refreshed, 'job', `Job ${job.id} unblocked for replanning`);
30
+ });
29
31
  console.log(JSON.stringify({ jobId: job.id, replanning: true, planTrigger }, null, 2));
30
32
  return;
31
33
  }
32
34
  for (const task of blocked)
33
35
  await unblockTask({ store, job, task, trigger: { source: 'cli', reason } });
34
36
  const refreshed = await store.load(job.id);
35
- const bus = await eventBus(args);
36
- for (const task of blocked)
37
- await publishTaskUnblocked(bus, refreshed, task.id, reason);
38
- await publishWake(bus, refreshed, 'job', `Job ${job.id} unblocked`);
37
+ await withEventBus(args, async (bus) => {
38
+ for (const task of blocked)
39
+ await publishTaskUnblocked(bus, refreshed, task.id, reason);
40
+ await publishWake(bus, refreshed, 'job', `Job ${job.id} unblocked`);
41
+ });
39
42
  console.log(JSON.stringify({ jobId: job.id, replanning: false, resumedTasks: blocked.map(task => task.id) }, null, 2));
40
43
  }
package/dist/cli.js CHANGED
@@ -29,7 +29,7 @@ import { parseAgentGraph } from './agent-graph.js';
29
29
  import { runJobUnblockCommand, runTaskUnblockCommand } from './cli-unblock.js';
30
30
  import { createJobEntity, createTaskEntity } from './workflow/entity-creation.js';
31
31
  export { helpText } from './cli-help.js';
32
- import { SERVICE_DEFAULTS, ServiceEventBus, arg, hasArg, textOption, integerArg, repository, storeFor, saveLocal, githubStore, eventBus, publishWake, publishDependentUnblocked, priority, storySize, executionMode, chatGptTabClosePolicy, requestedExecutionMode, continuation, scheduleFromArgs, jobTagFromArgs, requestManagedReconciliation, relayControlJob, relayTaskCommand, } from './cli-support.js';
32
+ import { SERVICE_DEFAULTS, ServiceEventBus, arg, hasArg, textOption, integerArg, repository, storeFor, saveLocal, githubStore, eventBus, publishWake, publishDependentUnblocked, priority, storySize, executionMode, chatGptTabClosePolicy, requestedExecutionMode, continuation, scheduleFromArgs, jobTagFromArgs, requestManagedReconciliation, relayControlJob, relayTaskCommand, withEventBus, } from './cli-support.js';
33
33
  export { SERVICE_DEFAULTS, eventBus, executionMode, chatGptTabClosePolicy } from './cli-support.js';
34
34
  export async function ensureManagedGitHubJob(client, repositoryName, trustedAuthors, options) {
35
35
  if (!options.id)
@@ -185,7 +185,7 @@ async function runTaskCommand(action, args) {
185
185
  }
186
186
  const durableTask = (await store.load(job.id)).tasks.find(item => item.id === task.id) ?? task;
187
187
  await saveLocal(localFile, await store.load(job.id));
188
- await publishWake(await eventBus(args), refreshed, task.id, `Task ${task.id} created`);
188
+ await withEventBus(args, bus => publishWake(bus, refreshed, task.id, `Task ${task.id} created`));
189
189
  console.log(JSON.stringify(durableTask, null, 2));
190
190
  return;
191
191
  }
@@ -228,7 +228,7 @@ async function runTaskCommand(action, args) {
228
228
  outputTask = outputJob.tasks.find(item => item.id === id) ?? result.task;
229
229
  }
230
230
  await saveLocal(localFile, outputJob);
231
- await publishWake(await eventBus(args), outputJob, outputTask.id, `${outputTask.id} ${action} requested`);
231
+ await withEventBus(args, bus => publishWake(bus, outputJob, outputTask.id, `${outputTask.id} ${action} requested`));
232
232
  console.log(JSON.stringify(outputTask, null, 2));
233
233
  return;
234
234
  }
@@ -397,7 +397,7 @@ async function runJobCommand(action, args) {
397
397
  await transitionJobEvent(job, 'pr.merged');
398
398
  await store.saveJob(job);
399
399
  const resolved = await store.resolveBlockerDependents(id, 'merge');
400
- await publishDependentUnblocked(await eventBus(args), resolved.unblocked, `Blocker Job ${id} resolved (merge)`);
400
+ await withEventBus(args, bus => publishDependentUnblocked(bus, resolved.unblocked, `Blocker Job ${id} resolved (merge)`));
401
401
  console.log(JSON.stringify(await store.load(id), null, 2));
402
402
  return;
403
403
  }
@@ -597,7 +597,6 @@ async function main() {
597
597
  console.log(`Initialized ${job.id}`);
598
598
  return;
599
599
  }
600
- const bus = await eventBus(args);
601
600
  if (command === 'status') {
602
601
  const host = arg(args, '--host', '127.0.0.1');
603
602
  const port = Number(arg(args, '--port', String(SERVICE_DEFAULTS.port)));
@@ -619,15 +618,12 @@ async function main() {
619
618
  const { store, job, localFile } = loaded;
620
619
  if (command === 'plan') {
621
620
  const guidance = hasArg(args, '--prompt') || hasArg(args, '--prompt-file') ? await textOption(args, '--prompt', '--prompt-file') : undefined;
622
- try {
621
+ await withEventBus(args, async (bus) => {
623
622
  const result = await runtime(store, args, bus).planJob(job.id, guidance?.trim() || undefined);
624
623
  await saveLocal(localFile, result.job);
625
624
  await publishWake(bus, result.job, result.round.id, `Planning round ${result.round.id} completed`);
626
625
  console.log(JSON.stringify(result.round, null, 2));
627
- }
628
- finally {
629
- await bus?.close?.();
630
- }
626
+ });
631
627
  return;
632
628
  }
633
629
  if (command === 'agent-register') {
@@ -659,27 +655,24 @@ async function main() {
659
655
  console.log(`Recorded ${id}`);
660
656
  return;
661
657
  }
662
- if (command === 'reconcile' && !localFile) {
663
- try {
664
- await requestManagedReconciliation(bus, job);
665
- console.log(JSON.stringify(await store.load(job.id), null, 2));
666
- }
667
- finally {
668
- await bus?.close?.();
669
- }
658
+ if (command === 'serve') {
659
+ await startService(args);
670
660
  return;
671
661
  }
672
- const reconciler = runtime(store, args, bus);
673
662
  if (command === 'reconcile') {
674
- await reconciler.reconcile(job.id);
675
- await reconciler.idle();
676
- const finalState = await store.load(job.id);
677
- await saveLocal(localFile, finalState);
678
- console.log(JSON.stringify(finalState, null, 2));
679
- return;
680
- }
681
- if (command === 'serve') {
682
- await startService(args);
663
+ await withEventBus(args, async (bus) => {
664
+ if (!localFile) {
665
+ await requestManagedReconciliation(bus, job);
666
+ console.log(JSON.stringify(await store.load(job.id), null, 2));
667
+ return;
668
+ }
669
+ const reconciler = runtime(store, args, bus);
670
+ await reconciler.reconcile(job.id);
671
+ await reconciler.idle();
672
+ const finalState = await store.load(job.id);
673
+ await saveLocal(localFile, finalState);
674
+ console.log(JSON.stringify(finalState, null, 2));
675
+ });
683
676
  return;
684
677
  }
685
678
  throw new Error(usage);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agents-relay",
3
- "version": "2.0.42",
3
+ "version": "2.0.43",
4
4
  "description": "Durable async agent jobs coordinated through GitHub pull requests",
5
5
  "type": "module",
6
6
  "bin": {