@agent-relay/factory 0.1.37 → 0.1.38
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 +44 -6
- package/dist/cli/fleet.d.ts.map +1 -1
- package/dist/cli/fleet.js +39 -4
- package/dist/cli/fleet.js.map +1 -1
- package/dist/fleet/internal-fleet-client.d.ts.map +1 -1
- package/dist/fleet/internal-fleet-client.js +13 -0
- package/dist/fleet/internal-fleet-client.js.map +1 -1
- package/dist/fleet/relay-fleet-client.d.ts +1 -0
- package/dist/fleet/relay-fleet-client.d.ts.map +1 -1
- package/dist/fleet/relay-fleet-client.js +4 -0
- package/dist/fleet/relay-fleet-client.js.map +1 -1
- package/dist/github/repo-identity.d.ts +8 -0
- package/dist/github/repo-identity.d.ts.map +1 -0
- package/dist/github/repo-identity.js +28 -0
- package/dist/github/repo-identity.js.map +1 -0
- package/dist/hosted/index.d.ts +5 -0
- package/dist/hosted/index.d.ts.map +1 -0
- package/dist/hosted/index.js +3 -0
- package/dist/hosted/index.js.map +1 -0
- package/dist/hosted/orchestrator.d.ts +12 -0
- package/dist/hosted/orchestrator.d.ts.map +1 -0
- package/dist/hosted/orchestrator.js +513 -0
- package/dist/hosted/orchestrator.js.map +1 -0
- package/dist/hosted/state-store.d.ts +48 -0
- package/dist/hosted/state-store.d.ts.map +1 -0
- package/dist/hosted/state-store.js +210 -0
- package/dist/hosted/state-store.js.map +1 -0
- package/dist/hosted/types.d.ts +173 -0
- package/dist/hosted/types.d.ts.map +1 -0
- package/dist/hosted/types.js +2 -0
- package/dist/hosted/types.js.map +1 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/mount/relayfile-cloud-mount-client.d.ts +20 -2
- package/dist/mount/relayfile-cloud-mount-client.d.ts.map +1 -1
- package/dist/mount/relayfile-cloud-mount-client.js +209 -22
- package/dist/mount/relayfile-cloud-mount-client.js.map +1 -1
- package/dist/orchestrator/batch-tracker.d.ts.map +1 -1
- package/dist/orchestrator/batch-tracker.js +17 -1
- package/dist/orchestrator/batch-tracker.js.map +1 -1
- package/dist/orchestrator/factory.d.ts.map +1 -1
- package/dist/orchestrator/factory.js +588 -87
- package/dist/orchestrator/factory.js.map +1 -1
- package/dist/state/file-state-store.d.ts.map +1 -1
- package/dist/state/file-state-store.js +13 -1
- package/dist/state/file-state-store.js.map +1 -1
- package/dist/state/in-memory-state-store.d.ts.map +1 -1
- package/dist/state/in-memory-state-store.js +13 -1
- package/dist/state/in-memory-state-store.js.map +1 -1
- package/dist/triage/schema.d.ts +14 -14
- package/dist/types.d.ts +6 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/writeback/index.d.ts +2 -0
- package/dist/writeback/index.d.ts.map +1 -1
- package/dist/writeback/index.js +1 -0
- package/dist/writeback/index.js.map +1 -1
- package/dist/writeback/mount-health.d.ts +15 -0
- package/dist/writeback/mount-health.d.ts.map +1 -0
- package/dist/writeback/mount-health.js +15 -0
- package/dist/writeback/mount-health.js.map +1 -0
- package/package.json +6 -2
|
@@ -0,0 +1,513 @@
|
|
|
1
|
+
import { TieredTriage } from '../triage/tiered.js';
|
|
2
|
+
import { isInFactoryScope } from '../safety/factory-scope.js';
|
|
3
|
+
const DEFAULT_LEASE_TTL_MS = 5 * 60_000;
|
|
4
|
+
const DEFAULT_MAX_ISSUES_PER_RUN = 100;
|
|
5
|
+
const TERMINAL_INVOCATION_STATUSES = new Set(['completed', 'failed', 'cancelled']);
|
|
6
|
+
const ACTIVE_ISSUE_PHASES = new Set(['dispatching', 'running', 'merge-gate']);
|
|
7
|
+
class HostedFactoryLeaseLostError extends Error {
|
|
8
|
+
constructor() {
|
|
9
|
+
super('hosted Factory workspace lease was lost');
|
|
10
|
+
this.name = 'HostedFactoryLeaseLostError';
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export class HostedFactoryLoop {
|
|
14
|
+
#options;
|
|
15
|
+
#ports;
|
|
16
|
+
#triage;
|
|
17
|
+
#now;
|
|
18
|
+
#operationSequence = 0;
|
|
19
|
+
constructor(options, ports) {
|
|
20
|
+
if (!options.workspaceId.trim())
|
|
21
|
+
throw new Error('hosted Factory requires a workspaceId');
|
|
22
|
+
if (!options.ownerId.trim())
|
|
23
|
+
throw new Error('hosted Factory requires a unique ownerId');
|
|
24
|
+
if (options.config.workspaceId && options.config.workspaceId !== options.workspaceId) {
|
|
25
|
+
throw new Error('hosted Factory workspaceId must match config.workspaceId');
|
|
26
|
+
}
|
|
27
|
+
this.#options = {
|
|
28
|
+
...options,
|
|
29
|
+
leaseTtlMs: options.leaseTtlMs ?? DEFAULT_LEASE_TTL_MS,
|
|
30
|
+
maxIssuesPerRun: options.maxIssuesPerRun ?? DEFAULT_MAX_ISSUES_PER_RUN,
|
|
31
|
+
};
|
|
32
|
+
this.#ports = ports;
|
|
33
|
+
this.#triage = ports.triage ?? new TieredTriage();
|
|
34
|
+
this.#now = ports.now ?? (() => new Date());
|
|
35
|
+
}
|
|
36
|
+
async runOnce() {
|
|
37
|
+
const report = emptyReport();
|
|
38
|
+
const claim = await this.#claim('sweep');
|
|
39
|
+
if (!claim.acquired) {
|
|
40
|
+
return { ...report, status: 'fenced' };
|
|
41
|
+
}
|
|
42
|
+
let lease = claim.lease;
|
|
43
|
+
try {
|
|
44
|
+
lease = await this.#reconcileAll(lease, report);
|
|
45
|
+
lease = await this.#renew(lease);
|
|
46
|
+
const issues = dedupeIssues(await this.#ports.discovery.discoverReady({
|
|
47
|
+
workspaceId: this.#options.workspaceId,
|
|
48
|
+
limit: this.#options.maxIssuesPerRun,
|
|
49
|
+
})).slice(0, this.#options.maxIssuesPerRun);
|
|
50
|
+
report.discovered = issues.length;
|
|
51
|
+
let records = await this.#ports.state.listIssues(this.#options.workspaceId);
|
|
52
|
+
let activeCount = records.filter((record) => ACTIVE_ISSUE_PHASES.has(record.phase)).length;
|
|
53
|
+
for (const issue of issues) {
|
|
54
|
+
lease = await this.#renew(lease);
|
|
55
|
+
let record = records.find((candidate) => candidate.issue.uuid === issue.uuid);
|
|
56
|
+
if (record?.phase === 'complete' || record?.phase === 'blocked') {
|
|
57
|
+
report.skipped.push({ issueKey: issue.key, reason: `already ${record.phase}` });
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
if (record?.phase === 'running' || record?.phase === 'merge-gate') {
|
|
61
|
+
report.skipped.push({ issueKey: issue.key, reason: `already ${record.phase}` });
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
if (!isInFactoryScope(issue, this.#options.config.safety)) {
|
|
65
|
+
report.skipped.push({ issueKey: issue.key, reason: 'outside configured Factory safety scope' });
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
try {
|
|
69
|
+
if (record?.phase === 'dispatching' && record.decision) {
|
|
70
|
+
lease = await this.#dispatchRecord(record, lease, report);
|
|
71
|
+
records = replaceRecord(records, record);
|
|
72
|
+
activeCount = records.filter((candidate) => ACTIVE_ISSUE_PHASES.has(candidate.phase)).length;
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
if (!record && activeCount >= this.#options.config.batchSize) {
|
|
76
|
+
report.skipped.push({ issueKey: issue.key, reason: 'hosted Factory batch is full' });
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
const now = this.#timestamp();
|
|
80
|
+
record = record
|
|
81
|
+
? { ...record, issue: structuredClone(issue), phase: 'triaging', updatedAt: now }
|
|
82
|
+
: {
|
|
83
|
+
workspaceId: this.#options.workspaceId,
|
|
84
|
+
issue: structuredClone(issue),
|
|
85
|
+
phase: 'triaging',
|
|
86
|
+
invocations: [],
|
|
87
|
+
createdAt: now,
|
|
88
|
+
updatedAt: now,
|
|
89
|
+
};
|
|
90
|
+
await this.#save(record, lease);
|
|
91
|
+
const decision = await this.#triage.triage(issue, {
|
|
92
|
+
config: this.#options.config,
|
|
93
|
+
repoMap: repoMapFromConfig(this.#options.config),
|
|
94
|
+
});
|
|
95
|
+
report.triaged.push(issue.key);
|
|
96
|
+
lease = await this.#renew(lease);
|
|
97
|
+
const clarificationReason = triageEscalationReason(decision);
|
|
98
|
+
if (clarificationReason) {
|
|
99
|
+
record = {
|
|
100
|
+
...record,
|
|
101
|
+
decision: structuredClone(decision),
|
|
102
|
+
phase: 'awaiting-clarification',
|
|
103
|
+
clarificationReason,
|
|
104
|
+
updatedAt: this.#timestamp(),
|
|
105
|
+
};
|
|
106
|
+
await this.#save(record, lease);
|
|
107
|
+
lease = await this.#ensureWriteback(record, lease, 'clarification');
|
|
108
|
+
report.awaitingClarification.push(issue.key);
|
|
109
|
+
records = replaceRecord(records, record);
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
const invocations = dispatchSpecs(decision).map((spec) => ({
|
|
113
|
+
invocationId: hostedFactoryInvocationId(this.#options.workspaceId, decision, spec),
|
|
114
|
+
spec: structuredClone(spec),
|
|
115
|
+
status: 'pending',
|
|
116
|
+
}));
|
|
117
|
+
if (invocations.length === 0) {
|
|
118
|
+
record = {
|
|
119
|
+
...record,
|
|
120
|
+
decision: structuredClone(decision),
|
|
121
|
+
phase: 'awaiting-clarification',
|
|
122
|
+
clarificationReason: 'Factory triage produced no dispatchable agent or workflow.',
|
|
123
|
+
invocations,
|
|
124
|
+
updatedAt: this.#timestamp(),
|
|
125
|
+
};
|
|
126
|
+
await this.#save(record, lease);
|
|
127
|
+
lease = await this.#ensureWriteback(record, lease, 'clarification');
|
|
128
|
+
report.awaitingClarification.push(issue.key);
|
|
129
|
+
records = replaceRecord(records, record);
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
record = {
|
|
133
|
+
...record,
|
|
134
|
+
decision: structuredClone(decision),
|
|
135
|
+
phase: 'dispatching',
|
|
136
|
+
clarificationReason: undefined,
|
|
137
|
+
invocations,
|
|
138
|
+
updatedAt: this.#timestamp(),
|
|
139
|
+
};
|
|
140
|
+
await this.#save(record, lease);
|
|
141
|
+
activeCount += 1;
|
|
142
|
+
lease = await this.#dispatchRecord(record, lease, report);
|
|
143
|
+
records = replaceRecord(records, record);
|
|
144
|
+
}
|
|
145
|
+
catch (error) {
|
|
146
|
+
if (error instanceof HostedFactoryLeaseLostError)
|
|
147
|
+
throw error;
|
|
148
|
+
report.errors.push({ issueKey: issue.key, message: errorMessage(error) });
|
|
149
|
+
this.#ports.logger?.error?.('[factory:hosted] issue sweep failed', {
|
|
150
|
+
workspaceId: this.#options.workspaceId,
|
|
151
|
+
issueKey: issue.key,
|
|
152
|
+
error: errorMessage(error),
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
return report;
|
|
157
|
+
}
|
|
158
|
+
catch (error) {
|
|
159
|
+
if (error instanceof HostedFactoryLeaseLostError) {
|
|
160
|
+
return { ...report, status: 'lease-lost' };
|
|
161
|
+
}
|
|
162
|
+
report.errors.push({ message: errorMessage(error) });
|
|
163
|
+
return report;
|
|
164
|
+
}
|
|
165
|
+
finally {
|
|
166
|
+
await this.#release(lease);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
async ingestCompletion(completion) {
|
|
170
|
+
const claim = await this.#claim('completion');
|
|
171
|
+
if (!claim.acquired) {
|
|
172
|
+
return { status: 'fenced', invocationId: completion.invocationId };
|
|
173
|
+
}
|
|
174
|
+
let lease = claim.lease;
|
|
175
|
+
try {
|
|
176
|
+
const record = await this.#ports.state.findIssueByInvocation(this.#options.workspaceId, completion.invocationId);
|
|
177
|
+
if (!record)
|
|
178
|
+
return { status: 'not-found', invocationId: completion.invocationId };
|
|
179
|
+
if (isTerminalIssue(record)) {
|
|
180
|
+
return {
|
|
181
|
+
status: 'terminal',
|
|
182
|
+
invocationId: completion.invocationId,
|
|
183
|
+
issueKey: record.issue.key,
|
|
184
|
+
phase: record.phase,
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
applyCompletion(record, completion, this.#timestamp());
|
|
188
|
+
await this.#save(record, lease);
|
|
189
|
+
if (record.invocations.every(isTerminalInvocation)) {
|
|
190
|
+
lease = await this.#finishRecord(record, lease);
|
|
191
|
+
}
|
|
192
|
+
return {
|
|
193
|
+
status: isTerminalIssue(record) ? 'terminal' : 'updated',
|
|
194
|
+
invocationId: completion.invocationId,
|
|
195
|
+
issueKey: record.issue.key,
|
|
196
|
+
phase: record.phase,
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
catch (error) {
|
|
200
|
+
if (error instanceof HostedFactoryLeaseLostError) {
|
|
201
|
+
return { status: 'fenced', invocationId: completion.invocationId };
|
|
202
|
+
}
|
|
203
|
+
throw error;
|
|
204
|
+
}
|
|
205
|
+
finally {
|
|
206
|
+
await this.#release(lease);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
async #reconcileAll(initialLease, report) {
|
|
210
|
+
let lease = initialLease;
|
|
211
|
+
const records = await this.#ports.state.listIssues(this.#options.workspaceId);
|
|
212
|
+
for (const record of records) {
|
|
213
|
+
try {
|
|
214
|
+
if (record.phase === 'awaiting-clarification') {
|
|
215
|
+
lease = await this.#ensureWriteback(record, lease, 'clarification');
|
|
216
|
+
continue;
|
|
217
|
+
}
|
|
218
|
+
if (record.phase === 'dispatching' && record.decision) {
|
|
219
|
+
lease = await this.#dispatchRecord(record, lease, report);
|
|
220
|
+
continue;
|
|
221
|
+
}
|
|
222
|
+
if (record.phase !== 'running' && record.phase !== 'merge-gate')
|
|
223
|
+
continue;
|
|
224
|
+
lease = await this.#renew(lease);
|
|
225
|
+
if (record.phase === 'running') {
|
|
226
|
+
lease = await this.#ensureWriteback(record, lease, 'dispatch');
|
|
227
|
+
}
|
|
228
|
+
let changed = false;
|
|
229
|
+
for (const invocation of record.invocations) {
|
|
230
|
+
if (isTerminalInvocation(invocation))
|
|
231
|
+
continue;
|
|
232
|
+
const completion = await this.#ports.completions.getInvocation({
|
|
233
|
+
workspaceId: this.#options.workspaceId,
|
|
234
|
+
invocationId: invocation.invocationId,
|
|
235
|
+
});
|
|
236
|
+
if (!completion || completion.status === invocation.status)
|
|
237
|
+
continue;
|
|
238
|
+
applyCompletion(record, completion, this.#timestamp());
|
|
239
|
+
changed = true;
|
|
240
|
+
}
|
|
241
|
+
if (changed) {
|
|
242
|
+
await this.#save(record, lease);
|
|
243
|
+
report.reconciled.push(record.issue.key);
|
|
244
|
+
}
|
|
245
|
+
if (record.invocations.every(isTerminalInvocation)) {
|
|
246
|
+
lease = await this.#finishRecord(record, lease);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
catch (error) {
|
|
250
|
+
if (error instanceof HostedFactoryLeaseLostError)
|
|
251
|
+
throw error;
|
|
252
|
+
report.errors.push({ issueKey: record.issue.key, message: errorMessage(error) });
|
|
253
|
+
this.#ports.logger?.error?.('[factory:hosted] reconciliation failed', {
|
|
254
|
+
workspaceId: this.#options.workspaceId,
|
|
255
|
+
issueKey: record.issue.key,
|
|
256
|
+
error: errorMessage(error),
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
return lease;
|
|
261
|
+
}
|
|
262
|
+
async #dispatchRecord(record, initialLease, report) {
|
|
263
|
+
let lease = initialLease;
|
|
264
|
+
for (const invocation of record.invocations) {
|
|
265
|
+
if (invocation.status !== 'pending')
|
|
266
|
+
continue;
|
|
267
|
+
lease = await this.#renew(lease);
|
|
268
|
+
const result = await this.#ports.fleet.spawn({
|
|
269
|
+
...structuredClone(invocation.spec),
|
|
270
|
+
invocationId: invocation.invocationId,
|
|
271
|
+
});
|
|
272
|
+
if (result.invocationId && result.invocationId !== invocation.invocationId) {
|
|
273
|
+
throw new Error(`fleet changed deterministic invocation ID ${invocation.invocationId} to ${result.invocationId}`);
|
|
274
|
+
}
|
|
275
|
+
invocation.status = 'dispatched';
|
|
276
|
+
invocation.dispatchedAt = this.#timestamp();
|
|
277
|
+
invocation.sessionRef = result.sessionRef;
|
|
278
|
+
invocation.node = result.node;
|
|
279
|
+
record.updatedAt = this.#timestamp();
|
|
280
|
+
lease = await this.#renew(lease);
|
|
281
|
+
await this.#save(record, lease);
|
|
282
|
+
}
|
|
283
|
+
if (record.invocations.every((invocation) => invocation.status !== 'pending')) {
|
|
284
|
+
record.phase = 'running';
|
|
285
|
+
record.updatedAt = this.#timestamp();
|
|
286
|
+
await this.#save(record, lease);
|
|
287
|
+
lease = await this.#ensureWriteback(record, lease, 'dispatch');
|
|
288
|
+
if (!report.dispatched.includes(record.issue.key))
|
|
289
|
+
report.dispatched.push(record.issue.key);
|
|
290
|
+
}
|
|
291
|
+
return lease;
|
|
292
|
+
}
|
|
293
|
+
async #finishRecord(record, initialLease) {
|
|
294
|
+
let lease = await this.#renew(initialLease);
|
|
295
|
+
record.phase = 'merge-gate';
|
|
296
|
+
record.updatedAt = this.#timestamp();
|
|
297
|
+
await this.#save(record, lease);
|
|
298
|
+
const mergeGate = await (this.#ports.mergeGate?.evaluate({
|
|
299
|
+
workspaceId: this.#options.workspaceId,
|
|
300
|
+
record: structuredClone(record),
|
|
301
|
+
}) ?? Promise.resolve(defaultMergeGate(record, this.#timestamp())));
|
|
302
|
+
lease = await this.#renew(lease);
|
|
303
|
+
record.mergeGate = {
|
|
304
|
+
...structuredClone(mergeGate),
|
|
305
|
+
...(mergeGate.status === 'pending' ? {} : { decidedAt: mergeGate.decidedAt ?? this.#timestamp() }),
|
|
306
|
+
};
|
|
307
|
+
record.updatedAt = this.#timestamp();
|
|
308
|
+
await this.#save(record, lease);
|
|
309
|
+
if (mergeGate.status === 'pending')
|
|
310
|
+
return lease;
|
|
311
|
+
lease = await this.#ensureWriteback(record, lease, 'completion');
|
|
312
|
+
if (record.completionWriteback?.status === 'posted') {
|
|
313
|
+
record.phase = mergeGate.status === 'ready' ? 'complete' : 'blocked';
|
|
314
|
+
record.updatedAt = this.#timestamp();
|
|
315
|
+
await this.#save(record, lease);
|
|
316
|
+
}
|
|
317
|
+
return lease;
|
|
318
|
+
}
|
|
319
|
+
async #ensureWriteback(record, initialLease, kind) {
|
|
320
|
+
const field = writebackField(kind);
|
|
321
|
+
if (record[field]?.status === 'posted')
|
|
322
|
+
return initialLease;
|
|
323
|
+
const attempts = (record[field]?.attempts ?? 0) + 1;
|
|
324
|
+
record[field] = { status: 'pending', attempts };
|
|
325
|
+
record.updatedAt = this.#timestamp();
|
|
326
|
+
await this.#save(record, initialLease);
|
|
327
|
+
let lease = await this.#renew(initialLease);
|
|
328
|
+
try {
|
|
329
|
+
const input = {
|
|
330
|
+
workspaceId: this.#options.workspaceId,
|
|
331
|
+
idempotencyKey: `factory:${this.#options.workspaceId}:${record.issue.uuid}:${kind}`,
|
|
332
|
+
record: structuredClone(record),
|
|
333
|
+
};
|
|
334
|
+
if (kind === 'clarification') {
|
|
335
|
+
await this.#ports.writeback.requestClarification({
|
|
336
|
+
...input,
|
|
337
|
+
reason: record.clarificationReason ?? 'Factory needs more issue context.',
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
else if (kind === 'dispatch') {
|
|
341
|
+
await this.#ports.writeback.dispatched(input);
|
|
342
|
+
}
|
|
343
|
+
else {
|
|
344
|
+
if (!record.mergeGate || record.mergeGate.status === 'pending')
|
|
345
|
+
return lease;
|
|
346
|
+
await this.#ports.writeback.completed({ ...input, mergeGate: record.mergeGate });
|
|
347
|
+
}
|
|
348
|
+
lease = await this.#renew(lease);
|
|
349
|
+
record[field] = { status: 'posted', attempts, postedAt: this.#timestamp() };
|
|
350
|
+
}
|
|
351
|
+
catch (error) {
|
|
352
|
+
record[field] = { status: 'failed', attempts, error: errorMessage(error) };
|
|
353
|
+
this.#ports.logger?.warn?.('[factory:hosted] writeback failed', {
|
|
354
|
+
workspaceId: this.#options.workspaceId,
|
|
355
|
+
issueKey: record.issue.key,
|
|
356
|
+
kind,
|
|
357
|
+
error: errorMessage(error),
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
record.updatedAt = this.#timestamp();
|
|
361
|
+
await this.#save(record, lease);
|
|
362
|
+
return lease;
|
|
363
|
+
}
|
|
364
|
+
async #claim(operation) {
|
|
365
|
+
this.#operationSequence += 1;
|
|
366
|
+
return await this.#ports.state.claimRunLease(this.#options.workspaceId, `${this.#options.ownerId}:${operation}:${this.#operationSequence}`, this.#options.leaseTtlMs);
|
|
367
|
+
}
|
|
368
|
+
async #renew(lease) {
|
|
369
|
+
const renewed = await this.#ports.state.renewRunLease(lease, this.#options.leaseTtlMs);
|
|
370
|
+
if (!renewed)
|
|
371
|
+
throw new HostedFactoryLeaseLostError();
|
|
372
|
+
return renewed;
|
|
373
|
+
}
|
|
374
|
+
async #save(record, lease) {
|
|
375
|
+
if (!await this.#ports.state.saveIssue(record, lease)) {
|
|
376
|
+
throw new HostedFactoryLeaseLostError();
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
async #release(lease) {
|
|
380
|
+
try {
|
|
381
|
+
await this.#ports.state.releaseRunLease(lease);
|
|
382
|
+
}
|
|
383
|
+
catch (error) {
|
|
384
|
+
this.#ports.logger?.warn?.('[factory:hosted] workspace lease release failed', {
|
|
385
|
+
workspaceId: this.#options.workspaceId,
|
|
386
|
+
error: errorMessage(error),
|
|
387
|
+
});
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
#timestamp() {
|
|
391
|
+
return this.#now().toISOString();
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
export function createHostedFactory(options, ports) {
|
|
395
|
+
return new HostedFactoryLoop(options, ports);
|
|
396
|
+
}
|
|
397
|
+
export function hostedFactoryInvocationId(workspaceId, decision, spec) {
|
|
398
|
+
const identity = [
|
|
399
|
+
workspaceId,
|
|
400
|
+
decision.issue.uuid,
|
|
401
|
+
spec.role,
|
|
402
|
+
spec.name,
|
|
403
|
+
spec.repo,
|
|
404
|
+
spec.workflow ?? '',
|
|
405
|
+
].join(':');
|
|
406
|
+
return `factory:${stableHash(identity)}`;
|
|
407
|
+
}
|
|
408
|
+
function defaultMergeGate(record, decidedAt) {
|
|
409
|
+
const failure = record.invocations.find((invocation) => invocation.status !== 'completed');
|
|
410
|
+
return failure
|
|
411
|
+
? {
|
|
412
|
+
status: 'blocked',
|
|
413
|
+
reason: `${failure.spec.name} ended with ${failure.status}.`,
|
|
414
|
+
decidedAt,
|
|
415
|
+
}
|
|
416
|
+
: {
|
|
417
|
+
status: 'ready',
|
|
418
|
+
reason: 'All hosted Factory invocations completed successfully.',
|
|
419
|
+
decidedAt,
|
|
420
|
+
};
|
|
421
|
+
}
|
|
422
|
+
function applyCompletion(record, completion, updatedAt) {
|
|
423
|
+
const invocation = record.invocations.find((candidate) => candidate.invocationId === completion.invocationId);
|
|
424
|
+
if (!invocation)
|
|
425
|
+
return;
|
|
426
|
+
// Invocation delivery is at-least-once and can arrive out of order. Once a
|
|
427
|
+
// terminal observation wins, a late dispatched/failed/completed event must
|
|
428
|
+
// not rewrite the merge-gate input.
|
|
429
|
+
if (isTerminalInvocation(invocation))
|
|
430
|
+
return;
|
|
431
|
+
invocation.status = completion.status;
|
|
432
|
+
invocation.completedAt = completion.completedAt ?? (TERMINAL_INVOCATION_STATUSES.has(completion.status) ? updatedAt : undefined);
|
|
433
|
+
invocation.output = completion.output;
|
|
434
|
+
invocation.error = completion.error;
|
|
435
|
+
record.updatedAt = updatedAt;
|
|
436
|
+
}
|
|
437
|
+
function dispatchSpecs(decision) {
|
|
438
|
+
return decision.scope === 'workflow'
|
|
439
|
+
? (decision.workflow ? [decision.workflow] : [])
|
|
440
|
+
: [...decision.implementers, decision.reviewer];
|
|
441
|
+
}
|
|
442
|
+
function triageEscalationReason(decision) {
|
|
443
|
+
const reasons = [
|
|
444
|
+
decision.confidence === 'low' ? 'low-confidence triage' : undefined,
|
|
445
|
+
decision.thin ? 'thin issue context' : undefined,
|
|
446
|
+
].filter((reason) => Boolean(reason));
|
|
447
|
+
return reasons.length > 0
|
|
448
|
+
? `${reasons.join(' and ')}${decision.rationale ? `: ${decision.rationale}` : ''}`
|
|
449
|
+
: undefined;
|
|
450
|
+
}
|
|
451
|
+
function repoMapFromConfig(config) {
|
|
452
|
+
const entries = [];
|
|
453
|
+
for (const [key, repo] of Object.entries(config.repos.byLabel)) {
|
|
454
|
+
entries.push({ repo, clonePath: config.repos.clonePaths[repo], source: 'label', key });
|
|
455
|
+
}
|
|
456
|
+
for (const [key, repo] of Object.entries(config.repos.byProject)) {
|
|
457
|
+
entries.push({ repo, clonePath: config.repos.clonePaths[repo], source: 'project', key });
|
|
458
|
+
}
|
|
459
|
+
for (const rule of config.repos.keywordRules) {
|
|
460
|
+
entries.push({ repo: rule.repo, clonePath: config.repos.clonePaths[rule.repo], source: 'keyword', key: rule.pattern });
|
|
461
|
+
}
|
|
462
|
+
if (config.repos.default) {
|
|
463
|
+
entries.push({
|
|
464
|
+
repo: config.repos.default,
|
|
465
|
+
clonePath: config.repos.clonePaths[config.repos.default],
|
|
466
|
+
source: 'default',
|
|
467
|
+
});
|
|
468
|
+
}
|
|
469
|
+
return entries;
|
|
470
|
+
}
|
|
471
|
+
function writebackField(kind) {
|
|
472
|
+
if (kind === 'clarification')
|
|
473
|
+
return 'clarificationWriteback';
|
|
474
|
+
if (kind === 'dispatch')
|
|
475
|
+
return 'dispatchWriteback';
|
|
476
|
+
return 'completionWriteback';
|
|
477
|
+
}
|
|
478
|
+
function isTerminalInvocation(invocation) {
|
|
479
|
+
return TERMINAL_INVOCATION_STATUSES.has(invocation.status);
|
|
480
|
+
}
|
|
481
|
+
function isTerminalIssue(record) {
|
|
482
|
+
return record.phase === 'complete' || record.phase === 'blocked';
|
|
483
|
+
}
|
|
484
|
+
function dedupeIssues(issues) {
|
|
485
|
+
return [...new Map(issues.map((issue) => [issue.uuid, issue])).values()];
|
|
486
|
+
}
|
|
487
|
+
function replaceRecord(records, record) {
|
|
488
|
+
return [...records.filter((candidate) => candidate.issue.uuid !== record.issue.uuid), record];
|
|
489
|
+
}
|
|
490
|
+
function stableHash(input) {
|
|
491
|
+
let hash = 0xcbf29ce484222325n;
|
|
492
|
+
for (let index = 0; index < input.length; index += 1) {
|
|
493
|
+
hash ^= BigInt(input.charCodeAt(index));
|
|
494
|
+
hash = BigInt.asUintN(64, hash * 0x100000001b3n);
|
|
495
|
+
}
|
|
496
|
+
return hash.toString(36);
|
|
497
|
+
}
|
|
498
|
+
function emptyReport() {
|
|
499
|
+
return {
|
|
500
|
+
status: 'completed',
|
|
501
|
+
discovered: 0,
|
|
502
|
+
triaged: [],
|
|
503
|
+
dispatched: [],
|
|
504
|
+
reconciled: [],
|
|
505
|
+
awaitingClarification: [],
|
|
506
|
+
skipped: [],
|
|
507
|
+
errors: [],
|
|
508
|
+
};
|
|
509
|
+
}
|
|
510
|
+
function errorMessage(error) {
|
|
511
|
+
return error instanceof Error ? error.message : String(error);
|
|
512
|
+
}
|
|
513
|
+
//# sourceMappingURL=orchestrator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"orchestrator.js","sourceRoot":"","sources":["../../src/hosted/orchestrator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAC/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAA;AAkB1D,MAAM,oBAAoB,GAAG,CAAC,GAAG,MAAM,CAAA;AACvC,MAAM,0BAA0B,GAAG,GAAG,CAAA;AACtC,MAAM,4BAA4B,GAAG,IAAI,GAAG,CAAC,CAAC,WAAW,EAAE,QAAQ,EAAE,WAAW,CAAC,CAAC,CAAA;AAClF,MAAM,mBAAmB,GAAG,IAAI,GAAG,CAAC,CAAC,aAAa,EAAE,SAAS,EAAE,YAAY,CAAC,CAAC,CAAA;AAE7E,MAAM,2BAA4B,SAAQ,KAAK;IAC7C;QACE,KAAK,CAAC,yCAAyC,CAAC,CAAA;QAChD,IAAI,CAAC,IAAI,GAAG,6BAA6B,CAAA;IAC3C,CAAC;CACF;AAED,MAAM,OAAO,iBAAiB;IACnB,QAAQ,CAA+F;IACvG,MAAM,CAAoB;IAC1B,OAAO,CAA2C;IAClD,IAAI,CAAY;IACzB,kBAAkB,GAAG,CAAC,CA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WAAW;IAClB,OAAO;QACL,MAAM,EAAE,WAAW;QACnB,UAAU,EAAE,CAAC;QACb,OAAO,EAAE,EAAE;QACX,UAAU,EAAE,EAAE;QACd,UAAU,EAAE,EAAE;QACd,qBAAqB,EAAE,EAAE;QACzB,OAAO,EAAE,EAAE;QACX,MAAM,EAAE,EAAE;KACX,CAAA;AACH,CAAC;AAED,SAAS,YAAY,CAAC,KAAc;IAClC,OAAO,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;AAC/D,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { HostedFactoryIssueRecord, HostedFactoryLease, HostedFactoryLeaseClaim, HostedFactoryStateStore } from './types.js';
|
|
2
|
+
export type InMemoryHostedFactoryStateStoreOptions = {
|
|
3
|
+
now?: () => number;
|
|
4
|
+
};
|
|
5
|
+
/** Test/local implementation with the same owner+epoch+expiry semantics as the DO store. */
|
|
6
|
+
export declare class InMemoryHostedFactoryStateStore implements HostedFactoryStateStore {
|
|
7
|
+
#private;
|
|
8
|
+
constructor(options?: InMemoryHostedFactoryStateStoreOptions);
|
|
9
|
+
claimRunLease(workspaceId: string, ownerId: string, ttlMs: number): Promise<HostedFactoryLeaseClaim>;
|
|
10
|
+
renewRunLease(lease: HostedFactoryLease, ttlMs: number): Promise<HostedFactoryLease | null>;
|
|
11
|
+
releaseRunLease(lease: HostedFactoryLease): Promise<void>;
|
|
12
|
+
getIssue(workspaceId: string, issueId: string): Promise<HostedFactoryIssueRecord | null>;
|
|
13
|
+
listIssues(workspaceId: string): Promise<HostedFactoryIssueRecord[]>;
|
|
14
|
+
findIssueByInvocation(workspaceId: string, invocationId: string): Promise<HostedFactoryIssueRecord | null>;
|
|
15
|
+
saveIssue(record: HostedFactoryIssueRecord, lease: HostedFactoryLease): Promise<boolean>;
|
|
16
|
+
}
|
|
17
|
+
export interface HostedFactoryDurableObjectTransaction {
|
|
18
|
+
get<T>(key: string): Promise<T | undefined>;
|
|
19
|
+
put<T>(key: string, value: T): Promise<void>;
|
|
20
|
+
delete(key: string): Promise<boolean>;
|
|
21
|
+
list<T>(options?: {
|
|
22
|
+
prefix?: string;
|
|
23
|
+
}): Promise<Map<string, T>>;
|
|
24
|
+
}
|
|
25
|
+
export interface HostedFactoryDurableObjectStorage extends HostedFactoryDurableObjectTransaction {
|
|
26
|
+
transaction<T>(closure: (transaction: HostedFactoryDurableObjectTransaction) => Promise<T>): Promise<T>;
|
|
27
|
+
}
|
|
28
|
+
export type DurableObjectHostedFactoryStateStoreOptions = {
|
|
29
|
+
now?: () => number;
|
|
30
|
+
keyPrefix?: string;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Durable-Object-backed hosted state. All lease claims and fenced writes run in
|
|
34
|
+
* storage transactions; storing records without this class's fence checks
|
|
35
|
+
* would reintroduce active/active split brain.
|
|
36
|
+
*/
|
|
37
|
+
export declare class DurableObjectHostedFactoryStateStore implements HostedFactoryStateStore {
|
|
38
|
+
#private;
|
|
39
|
+
constructor(storage: HostedFactoryDurableObjectStorage, options?: DurableObjectHostedFactoryStateStoreOptions);
|
|
40
|
+
claimRunLease(workspaceId: string, ownerId: string, ttlMs: number): Promise<HostedFactoryLeaseClaim>;
|
|
41
|
+
renewRunLease(lease: HostedFactoryLease, ttlMs: number): Promise<HostedFactoryLease | null>;
|
|
42
|
+
releaseRunLease(lease: HostedFactoryLease): Promise<void>;
|
|
43
|
+
getIssue(workspaceId: string, issueId: string): Promise<HostedFactoryIssueRecord | null>;
|
|
44
|
+
listIssues(workspaceId: string): Promise<HostedFactoryIssueRecord[]>;
|
|
45
|
+
findIssueByInvocation(workspaceId: string, invocationId: string): Promise<HostedFactoryIssueRecord | null>;
|
|
46
|
+
saveIssue(record: HostedFactoryIssueRecord, lease: HostedFactoryLease): Promise<boolean>;
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=state-store.d.ts.map
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