agents-relay 2.0.263 → 2.0.264

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 (64) hide show
  1. package/README.md +57 -52
  2. package/bin/migrate-task-ids.mjs +12 -0
  3. package/dist/blocker-recovery.js +9 -16
  4. package/dist/cli-blocker.js +2 -1
  5. package/dist/cli-coordinator.js +19 -7
  6. package/dist/cli-foreground.js +82 -0
  7. package/dist/cli-help.js +61 -72
  8. package/dist/cli-job-create.js +15 -9
  9. package/dist/cli-prompt.js +9 -5
  10. package/dist/cli-support.js +21 -8
  11. package/dist/cli-worker-task.js +9 -3
  12. package/dist/cli.js +50 -36
  13. package/dist/dag-task-runtime.js +16 -12
  14. package/dist/dashboard-html.js +28 -14
  15. package/dist/dashboard-jel.js +87 -31
  16. package/dist/dashboard-style.js +2 -8
  17. package/dist/dependency-revision-execution.js +15 -6
  18. package/dist/final-review-role.js +0 -12
  19. package/dist/job-local-repository-migration.js +137 -0
  20. package/dist/job-pr-number-migration.js +0 -4
  21. package/dist/job-task-id-sequence.js +18 -9
  22. package/dist/job-worktree-cleanup.js +3 -3
  23. package/dist/local-job-registry.js +2 -2
  24. package/dist/local-managed-store.js +2 -2
  25. package/dist/local-merge-delivery.js +16 -3
  26. package/dist/local-merge-projection.js +192 -49
  27. package/dist/no-github.js +2 -1
  28. package/dist/planner-recovery.js +8 -3
  29. package/dist/planner.js +5 -5
  30. package/dist/pool.js +3 -3
  31. package/dist/projection-failure-recovery.js +6 -46
  32. package/dist/reconciler-context.js +5 -5
  33. package/dist/reconciler-review.js +12 -37
  34. package/dist/reconciler-runtime.js +1 -4
  35. package/dist/reconciler.js +5 -5
  36. package/dist/relay-job-merge.js +33 -0
  37. package/dist/relay-store.js +8 -30
  38. package/dist/relay-workflow-operations.js +2 -0
  39. package/dist/relayd-control.js +22 -25
  40. package/dist/relayd-dashboard-actions.js +4 -5
  41. package/dist/relayd-utilities.js +15 -20
  42. package/dist/relayd.js +59 -299
  43. package/dist/review-generation-fence.js +1 -1
  44. package/dist/review-replan.js +6 -1
  45. package/dist/review-revision-model.js +11 -6
  46. package/dist/task-context.js +1 -1
  47. package/dist/task-id-migration.js +229 -0
  48. package/dist/task-transitions.js +1 -1
  49. package/dist/troubleshooter.js +13 -16
  50. package/dist/unified-job-registry.js +9 -0
  51. package/dist/workflow/projection-conflict-v2.js +30 -26
  52. package/dist/workflow/task-related-action-v2.js +1 -2
  53. package/dist/workspace.js +52 -56
  54. package/package.json +4 -2
  55. package/skills/agents-relay/SKILL.md +35 -60
  56. package/skills/agents-relay/agents/planner.agent.md +5 -5
  57. package/skills/agents-relay/bin/services.mjs +21 -3
  58. package/skills/agents-relay/contracts/task-job-contract.md +11 -2
  59. package/skills/agents-relay/evals/capabilities.json +6 -1
  60. package/workflow/projection-conflict.mmd +59 -56
  61. package/workflow/projection-outbox-conflict.mmd +20 -0
  62. package/dist/cli-projection.js +0 -29
  63. package/dist/projection-recovery-runtime.js +0 -121
  64. package/dist/projection-recovery.js +0 -101
@@ -1,121 +0,0 @@
1
- import { eventFor } from './events.js';
2
- import { deliverLocalMerge, localSourceHead } from './local-git-merge.js';
3
- import { dispatchWorkflowGraph } from './workflow/dispatcher.js';
4
- import { projectionConflictV2 } from './workflow/projection-conflict-v2.js';
5
- /** Executes only the retry or escalation selected by the projection-conflict graph. */
6
- export async function reconcileProjectionRecovery(job, store, options) {
7
- const recovery = job.projectionRecovery;
8
- if (!recovery)
9
- return null;
10
- if (recovery.status === 'projected' || recovery.status === 'escalated')
11
- return { state: recovery.status };
12
- const repair = job.tasks.find(task => task.id === recovery.taskId);
13
- const reviewTask = job.review?.taskId ? job.tasks.find(task => task.id === job.review?.taskId) : undefined;
14
- const expectedReviewTaskId = job.review?.taskId;
15
- const expectedReviewOutcome = job.review?.outcome;
16
- const expectedReviewHeadSha = job.review?.headSha;
17
- let projectedMerge;
18
- let claimed = false;
19
- let escalated = false;
20
- let projectionCompleted = false;
21
- const decision = await dispatchWorkflowGraph(projectionConflictV2, {
22
- initialState: recovery.status, input: { transport: 'event', id: 'reconcile', payload: {} },
23
- durableFacts: {
24
- repairTaskState: repair?.state,
25
- reviewTaskState: reviewTask?.state,
26
- reviewOutcome: job.review?.outcome,
27
- taskRetryAvailable: repair?.state !== 'FAILED',
28
- attempts: recovery.attempts,
29
- maxAttempts: recovery.maxAttempts,
30
- }, graphName: 'projection-conflict', maxSteps: 1,
31
- persistTransition: async (source, target) => {
32
- if (target === 'retry') {
33
- if (!store.mutateJob)
34
- throw new Error('Atomic SQLite mutation is required for projection recovery attempts');
35
- await store.mutateJob(job.id, current => {
36
- const currentRecovery = current.projectionRecovery;
37
- const currentRepair = current.tasks.find(task => task.id === currentRecovery?.taskId);
38
- const currentReviewTask = current.review?.taskId
39
- ? current.tasks.find(task => task.id === current.review?.taskId) : undefined;
40
- if (current.state !== 'COMPLETED' || currentRecovery?.key !== recovery.key
41
- || currentRecovery.taskId !== recovery.taskId || currentRecovery.status !== source
42
- || currentRecovery.attempts !== recovery.attempts || currentRepair?.state !== repair?.state
43
- || currentReviewTask?.id !== expectedReviewTaskId || current.review?.outcome !== expectedReviewOutcome
44
- || current.review?.headSha !== expectedReviewHeadSha)
45
- return current;
46
- claimed = true;
47
- return { ...current, projectionRecovery: { ...currentRecovery, status: 'retry',
48
- attempts: currentRecovery.attempts + 1, updatedAt: new Date().toISOString() } };
49
- });
50
- }
51
- else if (target === 'escalated') {
52
- if (!store.mutateJob)
53
- throw new Error('Atomic SQLite mutation is required for projection recovery status');
54
- await store.mutateJob(job.id, current => current.projectionRecovery?.key === recovery.key
55
- && current.projectionRecovery.taskId === recovery.taskId
56
- && current.projectionRecovery.status === source
57
- && current.projectionRecovery.attempts === recovery.attempts
58
- ? (escalated = true, { ...current, projectionRecovery: { ...current.projectionRecovery, status: 'escalated', updatedAt: new Date().toISOString() } })
59
- : current);
60
- }
61
- else if (source !== target)
62
- throw new Error(`Unexpected projection recovery transition ${source} -> ${target}`);
63
- },
64
- executeAction: async (actionId) => {
65
- if (actionId === 'effect.projectLocalMerge') {
66
- if (!claimed)
67
- return {};
68
- const localMerge = job.localMerge;
69
- if (!localMerge)
70
- throw new Error('Projection recovery requires a durable local merge receipt');
71
- const sourceSha = localSourceHead(options.projectPath, localMerge.sourceRef);
72
- if (job.review?.headSha !== sourceSha)
73
- throw new Error('Projection recovery source changed after review');
74
- const delivered = deliverLocalMerge(options.projectPath, { ...localMerge, sourceSha,
75
- correlationJobId: job.id, displayPrNumber: job.prNumber > 0 ? job.prNumber : undefined });
76
- await options.verifyObservedRemote(recovery.remoteSha);
77
- const projectedJob = { ...job, localMerge: { ...localMerge, sourceSha: delivered.sourceSha,
78
- mergedCommitSha: delivered.mergedCommitSha, status: 'succeeded', error: undefined,
79
- nextAttemptAt: undefined, updatedAt: new Date().toISOString() } };
80
- projectedMerge = await options.project(projectedJob);
81
- let finalized = false;
82
- const deliveredDecision = await dispatchWorkflowGraph(projectionConflictV2, {
83
- initialState: 'retry', input: { transport: 'event', id: 'projection.delivered', payload: {} },
84
- durableFacts: {}, graphName: 'projection-conflict', maxSteps: 1,
85
- persistTransition: async (source, target) => {
86
- if (source !== 'retry' || target !== 'projected' || !store.mutateJob)
87
- return;
88
- await store.mutateJob(job.id, current => {
89
- const currentMerge = current.localMerge;
90
- if (current.projectionRecovery?.key !== recovery.key
91
- || current.projectionRecovery.taskId !== recovery.taskId
92
- || current.projectionRecovery.status !== 'retry'
93
- || current.projectionRecovery.attempts !== recovery.attempts + 1
94
- || currentMerge?.sourceRef !== localMerge.sourceRef || currentMerge.targetRef !== localMerge.targetRef
95
- || currentMerge.status !== localMerge.status || currentMerge.sourceSha !== localMerge.sourceSha
96
- || currentMerge.mergedCommitSha !== localMerge.mergedCommitSha)
97
- return current;
98
- finalized = true;
99
- return { ...current, localMerge: projectedJob.localMerge,
100
- projectionRecovery: { ...current.projectionRecovery, status: 'projected', updatedAt: new Date().toISOString() },
101
- updatedAt: new Date().toISOString() };
102
- });
103
- },
104
- });
105
- projectionCompleted = finalized;
106
- if (!deliveredDecision.accepted || deliveredDecision.target !== 'projected' || !finalized)
107
- projectedMerge = undefined;
108
- return {};
109
- }
110
- if (actionId === 'projection.escalate') {
111
- if (escalated)
112
- await options.eventBus?.publish(eventFor(job.id, 'projection', null, 'projection.recovery_escalated', 'failed', 'Projection recovery exhausted its bounded retry path', 'user', { idempotencyKey: recovery.key, attempts: recovery.attempts }, { agent: 'relay', component: 'projection-conflict' })).catch(() => { });
113
- return {};
114
- }
115
- if (actionId === 'projection.createRecoveryTask')
116
- return {};
117
- throw new Error(`Unexpected projection recovery action ${actionId}`);
118
- },
119
- });
120
- return { state: projectionCompleted ? 'projected' : decision.accepted ? decision.target : '', projectedMerge };
121
- }
@@ -1,101 +0,0 @@
1
- import { createTaskEntity } from './workflow/entity-creation.js';
2
- import { dispatchWorkflowGraph } from './workflow/dispatcher.js';
3
- import { projectionConflictV2 } from './workflow/projection-conflict-v2.js';
4
- import { taskOverallTimeoutMs } from './types.js';
5
- const MAX_RECOVERY_ATTEMPTS = 2;
6
- function taskFor(job, remoteSha, now) {
7
- const key = `${job.id}:${remoteSha}`;
8
- const id = `projection-recovery-${remoteSha}`;
9
- return createTaskEntity(job, {
10
- jobId: job.id, id, title: `Reconcile main divergence for ${job.title}`, kind: 'work',
11
- priority: job.priority ?? 'P1', storySize: 'M', projectName: job.title,
12
- agentName: 'implementation', parentTaskId: null, dependencies: [],
13
- capabilities: ['implementation'], workerRequirements: { capabilities: ['implementation'] },
14
- adapter: 'codex', input: [
15
- `Projection recovery key: ${key}`,
16
- `Observed origin/main SHA: ${remoteSha}`,
17
- `Job ${job.id} is already COMPLETED; preserve that Job state.`,
18
- 'Inspect local main and origin/main, reconcile their divergence with a normal merge or rebase that preserves both histories, and never force-push.',
19
- 'Do not publish or rewrite refs. Record the resulting local main SHA and verify it contains the completed Job merge and the observed remote main history.',
20
- 'If the histories cannot be reconciled safely, stop and explain the exact blocker.',
21
- ].join('\n'), output: { kind: 'task_pr' }, continuation: null, continuationDeliveredAt: null,
22
- attempt: 0, maxAttempts: 2, leaseOwner: null, leaseExpiresAt: null,
23
- executionId: null, threadId: null, result: null, plannerResult: null, error: null,
24
- timeoutMs: taskOverallTimeoutMs('M'), createdAt: now, updatedAt: now,
25
- });
26
- }
27
- /** Select graph policy from SQLite facts, then atomically materialize its selected recovery action. */
28
- export async function beginProjectionRecovery(store, jobId, remoteSha, error) {
29
- if (!store.mutateJob)
30
- throw new Error('Projection recovery requires atomic SQLite Job mutation');
31
- let created = false;
32
- let escalated = false;
33
- const snapshot = await store.loadJob(jobId);
34
- if (!snapshot)
35
- return false;
36
- const sameKey = snapshot.projectionRecovery?.key === `${jobId}:${remoteSha}`;
37
- const expectedRecoveryKey = snapshot.projectionRecovery?.key ?? null;
38
- const expectedAttempts = snapshot.projectionRecovery?.attempts ?? 0;
39
- const expectedRecoveryStatus = snapshot.projectionRecovery?.status ?? null;
40
- const expectedRecoveryRemoteSha = snapshot.projectionRecovery?.remoteSha ?? null;
41
- const recoveryInProgress = snapshot.projectionRecovery?.status === 'repairing'
42
- || (snapshot.projectionRecovery?.status === 'retry' && snapshot.projectionRecovery.remoteSha === remoteSha);
43
- const decision = await dispatchWorkflowGraph(projectionConflictV2, {
44
- initialState: 'classify', input: { transport: 'event', id: 'projection.delivery_failed', payload: {} },
45
- durableFacts: {
46
- jobState: snapshot.state,
47
- mergeSucceeded: snapshot.localMerge?.status === 'succeeded',
48
- projectionStrategy: snapshot.localMerge?.projectionStrategy,
49
- divergenceConfirmed: /non-fast-forward|fetch first|diverg|not a fast-forward|rejected/i.test(error),
50
- remoteShaAvailable: /^[0-9a-f]{40,64}$/i.test(remoteSha),
51
- sameIdempotencyKey: sameKey,
52
- recoveryInProgress,
53
- attempts: snapshot.projectionRecovery?.attempts ?? 0,
54
- maxAttempts: MAX_RECOVERY_ATTEMPTS,
55
- }, graphName: 'projection-conflict', maxSteps: 1,
56
- executeAction: async (actionId) => {
57
- if (actionId === 'projection.escalate') {
58
- await store.mutateJob(jobId, current => {
59
- if (current.state === 'COMPLETED'
60
- && (current.projectionRecovery?.key ?? null) === expectedRecoveryKey
61
- && (current.projectionRecovery?.attempts ?? 0) === expectedAttempts
62
- && current.projectionRecovery?.status === snapshot.projectionRecovery?.status
63
- && current.projectionRecovery) {
64
- current.projectionRecovery = { ...current.projectionRecovery, key: `${jobId}:${remoteSha}`, remoteSha,
65
- status: 'escalated', error, updatedAt: new Date().toISOString() };
66
- escalated = true;
67
- }
68
- return current;
69
- });
70
- return {};
71
- }
72
- if (actionId !== 'projection.createRecoveryTask')
73
- throw new Error(`Unexpected projection action ${actionId}`);
74
- const now = new Date().toISOString();
75
- await store.mutateJob(jobId, current => {
76
- if (current.state !== 'COMPLETED' || current.localMerge?.status !== 'succeeded'
77
- || (current.projectionRecovery?.key ?? null) !== expectedRecoveryKey
78
- || (current.projectionRecovery?.attempts ?? 0) !== expectedAttempts
79
- || (current.projectionRecovery?.status ?? null) !== expectedRecoveryStatus
80
- || (current.projectionRecovery?.remoteSha ?? null) !== expectedRecoveryRemoteSha
81
- || current.projectionRecovery?.status === 'repairing'
82
- || current.projectionRecovery?.key === `${jobId}:${remoteSha}`)
83
- return current;
84
- const task = taskFor(current, remoteSha, now);
85
- if (!current.tasks.some(item => item.id === task.id))
86
- current.tasks.push(task);
87
- const recovery = {
88
- key: `${jobId}:${remoteSha}`, remoteSha, status: 'repairing', taskId: task.id,
89
- attempts: current.projectionRecovery?.attempts ?? 0,
90
- maxAttempts: MAX_RECOVERY_ATTEMPTS, error, updatedAt: now,
91
- };
92
- current.projectionRecovery = recovery;
93
- current.updatedAt = now;
94
- created = true;
95
- return current;
96
- });
97
- return {};
98
- },
99
- });
100
- return decision.accepted ? (created ? 'created' : escalated ? 'escalated' : false) : false;
101
- }