agents-relay 1.0.72 → 1.0.73
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/README.md +4 -4
- package/dist/cli.js +0 -1
- package/dist/markers.js +13 -3
- package/dist/store.js +40 -17
- package/package.json +1 -1
- package/skills/agents-relay/contracts/task-job-contract.md +2 -2
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Agents Relay
|
|
2
2
|
|
|
3
|
-
Agents Relay is a generic TypeScript runtime for durable asynchronous agent jobs coordinated through GitHub pull requests.
|
|
3
|
+
Agents Relay is a generic TypeScript runtime for durable asynchronous agent jobs coordinated through GitHub pull requests. The PR body stores the durable Job marker plus human-readable Job objective, while PR comments store durable Task and other append-friendly records; correlated terminal events are authoritative for model-backed task lifecycle transitions.
|
|
4
4
|
|
|
5
5
|
## Quick start
|
|
6
6
|
|
|
@@ -53,7 +53,7 @@ Lifecycle transition authority lives in the directly renderable canonical source
|
|
|
53
53
|
|
|
54
54
|
Graph-engine rollout is confidence-gated with `AGENTS_RELAY_WORKFLOW_MODE=legacy|shadow|graph` (default `legacy`). `shadow` keeps legacy authoritative while comparing the Mermaid decision and exposing `{mode,matches,mismatches}` at `/api/workflow-rollout`; `graph` is explicit opt-in until the shadow cutover gate is approved.
|
|
55
55
|
|
|
56
|
-
Job objectives and Task inputs are Markdown. Prefer `--objective-file` / `--input-file` (use `-` for stdin) for durable long-form context; inline `--objective` / `--input` remain for short/simple text and are mutually exclusive with the file variants. When a diagram materially clarifies the work, put Mermaid first and then Markdown detail. A newly created Job must capture enough context to finish independently of the originating chat
|
|
56
|
+
Job objectives and Task inputs are Markdown. Prefer `--objective-file` / `--input-file` (use `-` for stdin) for durable long-form context; inline `--objective` / `--input` remain for short/simple text and are mutually exclusive with the file variants. When a diagram materially clarifies the work, put Mermaid first and then Markdown detail. A newly created Job must capture enough context to finish independently of the originating chat. Its PR body contains exactly one hidden `agents-relay:job:v1` metadata marker followed by the objective Markdown; there is no separate Job comment duplicating the objective. Objective and Job metadata updates rewrite that same PR body. Legacy Job-comment markers remain readable and are migrated into the PR body on the next Job save.
|
|
57
57
|
|
|
58
58
|
Jobs default to `fixed`. `job create` persists only the durable job and never
|
|
59
59
|
creates executable tasks. The top-level orchestrator decides whether the user's
|
|
@@ -141,7 +141,7 @@ reconcile leases and launches ready tasks without waiting inside the runtime sch
|
|
|
141
141
|
|
|
142
142
|
For automation, Agents Relay can use GitHub App installation authentication via `AGENTS_RELAY_GITHUB_APP_ID`, `AGENTS_RELAY_GITHUB_APP_INSTALLATION_ID`, and `AGENTS_RELAY_GITHUB_APP_PRIVATE_KEY_FILE` (or matching CLI flags). Webhook mode is cache-first: targeted webhook reconciliation is primary, dashboard auto-refresh reads cached job state, and the broad watchdog drops to a 30-minute fallback. See [docs/github-app-rate-limit.md](docs/github-app-rate-limit.md).
|
|
143
143
|
|
|
144
|
-
V1 assumes one active runner/daemon per job. Use a distributed atomic lease before running multiple reconcilers. Do not put secrets, credentials, private prompts, or large private payloads in PR marker
|
|
144
|
+
V1 assumes one active runner/daemon per job. Use a distributed atomic lease before running multiple reconcilers. Do not put secrets, credentials, private prompts, or large private payloads in the PR-body Job marker or PR-comment Task markers; store only summaries and artifact references.
|
|
145
145
|
|
|
146
146
|
Codex/model-backed tasks require --provider and --model (or equivalent routing metadata) before launch. See [docs/architecture.md](docs/architecture.md) and [skills/agents-relay/SKILL.md](skills/agents-relay/SKILL.md).
|
|
147
147
|
|
|
@@ -176,4 +176,4 @@ npx agents-relay task create --repo OWNER/REPO --pr 5 --id job-1 \
|
|
|
176
176
|
|
|
177
177
|
GitHub PR state is authoritative for terminal lifecycle: a merged PR reconciles its managed job to `COMPLETED`; a closed, unmerged PR reconciles to `CANCELLED` and cannot launch queued work. The dashboard exposes `/api/jobs` and shows PR state, durable Job lifecycle, and derived runtime status separately. A merged PR reconciles lifecycle to `COMPLETED`; a closed, unmerged PR reconciles lifecycle to `CANCELLED`.
|
|
178
178
|
|
|
179
|
-
For work that was completed outside the relay but must be represented truthfully in durable history, use `npx agents-relay record --task-id <id> --summary <summary> --commit <sha>`. Recorded tasks use the `orchestrator` adapter and terminal `SUCCEEDED` state; they do not pretend a shell/model worker executed the work. This is a repair/backfill mechanism—normal work should be created as a durable Task before execution.
|
|
179
|
+
For work that was completed outside the relay but must be represented truthfully in durable history, use `npx agents-relay record --task-id <id> --summary <summary> --commit <sha>`. Recorded tasks use the `orchestrator` adapter and terminal `SUCCEEDED` state; they do not pretend a shell/model worker executed the work. This is a repair/backfill mechanism—normal work should be created as a durable Task before execution. For managed jobs, the GitHub PR body is the canonical Job surface: hidden Job metadata marker plus the visible Markdown objective.
|
package/dist/cli.js
CHANGED
|
@@ -635,7 +635,6 @@ async function runJobCommand(action, args) {
|
|
|
635
635
|
if (!objective.trim())
|
|
636
636
|
throw new Error('Job objective cannot be empty');
|
|
637
637
|
job.objective = objective;
|
|
638
|
-
await store.updatePullRequestBody?.(objective);
|
|
639
638
|
}
|
|
640
639
|
if (hasArg(args, '--priority'))
|
|
641
640
|
job.priority = priority(args, job.priority ?? 'P2');
|
package/dist/markers.js
CHANGED
|
@@ -32,10 +32,18 @@ function contentBeforeDelimiter(body, heading, end) {
|
|
|
32
32
|
return undefined;
|
|
33
33
|
return body.slice(contentStart, endAt);
|
|
34
34
|
}
|
|
35
|
+
function jobMetadata(job) {
|
|
36
|
+
const { objective: _objective, description: _description, tasks: _tasks, ...metadata } = job;
|
|
37
|
+
return metadata;
|
|
38
|
+
}
|
|
39
|
+
export function renderJobBody(job) {
|
|
40
|
+
const objective = job.objective?.trim() || '_No objective recorded._';
|
|
41
|
+
return `${marker(JOB_MARKER, jobMetadata(job))}
|
|
42
|
+
${objective}`;
|
|
43
|
+
}
|
|
35
44
|
export function renderJobComment(job) {
|
|
36
45
|
const objective = job.objective?.trim() || '_No objective recorded._';
|
|
37
|
-
|
|
38
|
-
return `${marker(JOB_MARKER, metadata)}
|
|
46
|
+
return `${marker(JOB_MARKER, jobMetadata(job))}
|
|
39
47
|
# Agents Relay job: ${job.title}
|
|
40
48
|
|
|
41
49
|
- **State:** ${job.state}
|
|
@@ -70,7 +78,9 @@ export function parseJob(body) {
|
|
|
70
78
|
const job = parseMarker(body, JOB_MARKER);
|
|
71
79
|
if (!job)
|
|
72
80
|
return null;
|
|
73
|
-
const
|
|
81
|
+
const markerEnd = body.indexOf('-->');
|
|
82
|
+
const bodyObjective = markerEnd >= 0 ? body.slice(markerEnd + 3).trim() || undefined : undefined;
|
|
83
|
+
const objective = job.objective ?? job.description ?? contentBeforeDelimiter(body, '\n## Objective\n\n', JOB_OBJECTIVE_END) ?? markdownSection(body, '\n## Objective\n') ?? bodyObjective;
|
|
74
84
|
const parsed = { ...job, objective };
|
|
75
85
|
if (parsed.executionMode === undefined)
|
|
76
86
|
return { ...parsed, executionMode: 'fixed' };
|
package/dist/store.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { spawn } from 'node:child_process';
|
|
2
2
|
import { createSign } from 'node:crypto';
|
|
3
|
-
import { parseAgent, parseJob, parseTask, renderAgentComment, renderJobComment, renderTaskComment, AGENT_MARKER, JOB_MARKER, TASK_MARKER } from './markers.js';
|
|
3
|
+
import { parseAgent, parseJob, parseTask, renderAgentComment, renderJobBody, renderJobComment, renderTaskComment, AGENT_MARKER, JOB_MARKER, TASK_MARKER } from './markers.js';
|
|
4
4
|
export async function loadManagedGitHubPullRequestGraphql(client, repository, prNumber, trustedAuthors) {
|
|
5
5
|
const [owner, name] = repository.split('/', 2);
|
|
6
6
|
if (!owner || !name || !Number.isInteger(prNumber) || prNumber <= 0 || !client.graphql)
|
|
@@ -17,7 +17,9 @@ export async function loadManagedGitHubPullRequestGraphql(client, repository, pr
|
|
|
17
17
|
const author = row.author;
|
|
18
18
|
return typeof author?.login === 'string' && trustedAuthors.has(author.login);
|
|
19
19
|
});
|
|
20
|
-
const
|
|
20
|
+
const bodyJob = parseJob(typeof pr.body === 'string' ? pr.body : '');
|
|
21
|
+
const commentJobs = trusted.map(item => parseJob(String(item.body ?? ''))).filter((item) => item !== null);
|
|
22
|
+
const jobs = bodyJob ? [bodyJob] : commentJobs;
|
|
21
23
|
const tasks = trusted.map(item => parseTask(String(item.body ?? ''))).filter((item) => item !== null);
|
|
22
24
|
const state = String(pr.state ?? '').toUpperCase();
|
|
23
25
|
const githubState = pr.merged === true ? 'MERGED' : state === 'CLOSED' ? 'CLOSED' : 'OPEN';
|
|
@@ -424,13 +426,17 @@ export class GitHubStore {
|
|
|
424
426
|
}
|
|
425
427
|
async prNode() {
|
|
426
428
|
const { owner, name } = this.repoParts();
|
|
427
|
-
const data = await this.graphql('query($owner:String!,$name:String!,$number:Int!){repository(owner:$owner,name:$name){pullRequest(number:$number){id state merged mergedAt closedAt}}}', { owner, name, number: this.prNumber });
|
|
429
|
+
const data = await this.graphql('query($owner:String!,$name:String!,$number:Int!){repository(owner:$owner,name:$name){pullRequest(number:$number){id state merged mergedAt closedAt body}}}', { owner, name, number: this.prNumber });
|
|
428
430
|
const repository = data.repository;
|
|
429
431
|
const pr = repository?.pullRequest;
|
|
430
432
|
if (!pr)
|
|
431
433
|
throw new Error(`Pull request #${this.prNumber} not found in ${this.repository}`);
|
|
432
434
|
return pr;
|
|
433
435
|
}
|
|
436
|
+
async pullRequestBody() {
|
|
437
|
+
const pr = await this.prNode();
|
|
438
|
+
return typeof pr.body === 'string' ? pr.body : '';
|
|
439
|
+
}
|
|
434
440
|
async list() {
|
|
435
441
|
const { owner, name } = this.repoParts();
|
|
436
442
|
const all = [];
|
|
@@ -490,10 +496,16 @@ export class GitHubStore {
|
|
|
490
496
|
}
|
|
491
497
|
async load(jobId) {
|
|
492
498
|
const comments = (await this.list()).filter(comment => this.isTrusted(comment));
|
|
493
|
-
const
|
|
499
|
+
const bodyJob = parseJob(await this.pullRequestBody());
|
|
500
|
+
const commentJobs = comments.map(x => parseJob(x.body)).filter((x) => x !== null && typeof x.id === 'string' && x.id.length > 0);
|
|
501
|
+
const jobs = bodyJob ? [bodyJob] : commentJobs;
|
|
494
502
|
const job = jobs.find(x => x.id === jobId);
|
|
495
|
-
if (!job)
|
|
503
|
+
if (!job) {
|
|
504
|
+
const conflicting = bodyJob ?? commentJobs[0];
|
|
505
|
+
if (conflicting)
|
|
506
|
+
throw new Error(`JOB_ID_MISMATCH: PR #${this.prNumber} is bound to ${conflicting.id}, not ${jobId}`);
|
|
496
507
|
throw new Error(`JOB_MARKER_MISSING: Managed GitHub job ${jobId} has no durable ${JOB_MARKER} marker in PR #${this.prNumber}`);
|
|
508
|
+
}
|
|
497
509
|
const soleTrustedJob = jobs.length === 1;
|
|
498
510
|
job.tasks = comments.map(comment => {
|
|
499
511
|
const task = parseTask(comment.body);
|
|
@@ -505,6 +517,16 @@ export class GitHubStore {
|
|
|
505
517
|
return job;
|
|
506
518
|
}
|
|
507
519
|
async validateJobBinding(jobId) {
|
|
520
|
+
const body = await this.pullRequestBody();
|
|
521
|
+
const bodyHasMarker = body.includes(`<!-- ${JOB_MARKER} `);
|
|
522
|
+
const bodyJob = parseJob(body);
|
|
523
|
+
if (bodyHasMarker && !bodyJob)
|
|
524
|
+
throw new Error(`JOB_MARKER_MALFORMED: PR #${this.prNumber} body contains a ${JOB_MARKER} marker that cannot be parsed`);
|
|
525
|
+
if (bodyJob) {
|
|
526
|
+
if (bodyJob.id !== jobId)
|
|
527
|
+
throw new Error(`JOB_ID_MISMATCH: PR #${this.prNumber} is bound to ${bodyJob.id}, not ${jobId}`);
|
|
528
|
+
return;
|
|
529
|
+
}
|
|
508
530
|
const comments = (await this.list()).filter(comment => this.isTrusted(comment));
|
|
509
531
|
const markerComments = comments.filter(comment => comment.body.includes(JOB_MARKER));
|
|
510
532
|
const parsed = markerComments.map(comment => parseJob(comment.body));
|
|
@@ -539,22 +561,21 @@ export class GitHubStore {
|
|
|
539
561
|
await this.graphql('mutation($id:ID!){deleteIssueComment(input:{id:$id}){clientMutationId}}', { id: comment.nodeId });
|
|
540
562
|
}
|
|
541
563
|
async saveJob(job) {
|
|
564
|
+
const currentBody = await this.pullRequestBody();
|
|
565
|
+
const bodyJob = parseJob(currentBody);
|
|
566
|
+
if (bodyJob && bodyJob.id !== job.id)
|
|
567
|
+
throw new Error(`PR #${this.prNumber} body already has a different ${JOB_MARKER} marker`);
|
|
542
568
|
const comments = (await this.list()).filter(comment => this.isTrusted(comment));
|
|
543
569
|
const jobComments = comments.filter(comment => parseJob(comment.body) !== null);
|
|
544
570
|
const conflicts = jobComments.filter(comment => parseJob(comment.body)?.id !== job.id);
|
|
545
571
|
if (conflicts.length > 0)
|
|
546
572
|
throw new Error(`PR #${this.prNumber} already has a different ${JOB_MARKER} marker`);
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
await this.deleteComment(duplicate);
|
|
554
|
-
}
|
|
555
|
-
const durable = (await this.list()).filter(comment => this.isTrusted(comment)).filter(comment => parseJob(comment.body)?.id === job.id);
|
|
556
|
-
if (durable.length !== 1)
|
|
557
|
-
throw new Error(`Failed to persist exactly one ${JOB_MARKER} marker for job ${job.id}`);
|
|
573
|
+
await this.updatePullRequestBody(renderJobBody(job));
|
|
574
|
+
const persisted = parseJob(await this.pullRequestBody());
|
|
575
|
+
if (!persisted || persisted.id !== job.id)
|
|
576
|
+
throw new Error(`Failed to persist ${JOB_MARKER} marker in PR #${this.prNumber} body for job ${job.id}`);
|
|
577
|
+
for (const legacy of jobComments.filter(comment => parseJob(comment.body)?.id === job.id))
|
|
578
|
+
await this.deleteComment(legacy);
|
|
558
579
|
}
|
|
559
580
|
async appendTask(task) {
|
|
560
581
|
if (!task.jobId)
|
|
@@ -615,7 +636,9 @@ export async function listManagedGitHubJobs(client, repository, trustedAuthors)
|
|
|
615
636
|
const author = item.author;
|
|
616
637
|
return typeof author?.login === 'string' && trustedAuthors.has(author.login);
|
|
617
638
|
});
|
|
618
|
-
const
|
|
639
|
+
const bodyJob = parseJob(typeof pr.body === 'string' ? pr.body : '');
|
|
640
|
+
const commentJobs = trusted.map(item => parseJob(String(item.body ?? ''))).filter((item) => item !== null);
|
|
641
|
+
const jobs = bodyJob ? [bodyJob] : commentJobs;
|
|
619
642
|
const tasks = trusted.map(item => parseTask(String(item.body ?? ''))).filter((item) => item !== null);
|
|
620
643
|
const state = String(pr.state ?? '').toUpperCase();
|
|
621
644
|
const githubState = pr.merged === true || state === 'MERGED' ? 'MERGED' : state === 'CLOSED' ? 'CLOSED' : 'OPEN';
|
package/package.json
CHANGED
|
@@ -6,7 +6,7 @@ This contract is the shared protocol for every component that creates, schedules
|
|
|
6
6
|
|
|
7
7
|
Job objectives and Task inputs are **Markdown** and are durable execution context, not short labels. Use Mermaid where a diagram materially explains a workflow, state model, architecture, dependency graph, relationship, or other visual structure. **Mermaid-first applies to that explanation/section, not to the entire Job objective or Task input.** Put the diagram before the prose that explains that visual model, but keep normal document structure: start with the goal/context when that is what the reader needs first. Do not force a Mermaid block at the top of every objective/input, and do not add decorative or redundant diagrams when Markdown is clearer.
|
|
8
8
|
|
|
9
|
-
The trusted machine-readable Job/Task marker stores lifecycle and execution metadata only. Do **not** duplicate the Job objective or Task input inside
|
|
9
|
+
The trusted machine-readable Job/Task marker stores lifecycle and execution metadata only. Do **not** duplicate the Job objective or Task input inside marker JSON. The Job marker lives in the PR body immediately before the human-readable Job objective; Task markers live in their Task comments immediately before the human-readable Task input/result. Readers reconstruct `objective` / `input` from that visible Markdown while remaining backward-compatible with legacy markers that embedded long-form content or stored the Job marker in a separate comment.
|
|
10
10
|
|
|
11
11
|
For long-form content, use files instead of shell-quoted arguments:
|
|
12
12
|
|
|
@@ -15,7 +15,7 @@ For long-form content, use files instead of shell-quoted arguments:
|
|
|
15
15
|
|
|
16
16
|
When creating a new Job from an active discussion, the orchestrator must consolidate **all context needed to finish the Job without the originating thread** into the Job objective before creation. Include, as applicable: goal, relevant background, decisions already made, requirements, constraints, lifecycle/workflow semantics, non-goals, implementation boundaries, acceptance criteria, delivery/review instructions, and any important known issues. Do not create a Job whose objective is only a one-line summary when the discussion contains material implementation context.
|
|
17
17
|
|
|
18
|
-
For a newly created PR (`job create --head`), standalone objective Markdown is required
|
|
18
|
+
For a newly created PR (`job create --head`), standalone objective Markdown is required. The PR body is the single durable Job surface: one hidden `agents-relay:job:v1` marker followed by the objective Markdown. Updating Job metadata or objective updates that same body. New Jobs must not create a separate Job comment that repeats the objective. Readers must remain backward-compatible with legacy Job-comment markers, and a successful Job save may migrate such a legacy marker into the PR body only after validating the replacement before deleting the redundant legacy Job comment.
|
|
19
19
|
|
|
20
20
|
## Task producers
|
|
21
21
|
|