@cirtium/acent-connect 1.1.2 → 1.1.4
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/acent/.claude-plugin/plugin.json +1 -1
- package/acent/.codex-plugin/plugin.json +1 -1
- package/acent/.cursor-plugin/plugin.json +1 -1
- package/acent/scripts/acent-connect.mjs +43 -26
- package/acent/scripts/bridge-capture.mjs +120 -0
- package/acent/scripts/bridge-checks.mjs +12 -2
- package/acent/scripts/bridge-finalize.mjs +10 -1
- package/acent/scripts/bridge-refinement.mjs +93 -22
- package/acent/scripts/bridge-review-result.mjs +12 -0
- package/acent/scripts/bridge-runners.mjs +170 -86
- package/acent/scripts/bridge.mjs +70 -13
- package/acent/scripts/capture-activity.mjs +5 -3
- package/acent/scripts/hook.mjs +11 -0
- package/acent/scripts/mcp-proxy.mjs +17 -1
- package/acent/skills/acent-bridge/SKILL.md +25 -2
- package/antigravity/plugin.json +1 -1
- package/package.json +1 -1
|
@@ -308,6 +308,48 @@ export async function drain(config, directory) {
|
|
|
308
308
|
}
|
|
309
309
|
})
|
|
310
310
|
}
|
|
311
|
+
export async function queueManagedCapture(config, directory, policy, events, at = Date.now()) {
|
|
312
|
+
if (!events.length) return
|
|
313
|
+
const credentials = await readCredentials(directory)
|
|
314
|
+
if (!credentials.client_id || credentials.client_id.startsWith("ac_private_client_") ||
|
|
315
|
+
credentials.captureBlocked ||
|
|
316
|
+
!credentials.scope?.split(" ").includes("conversation:write")) return
|
|
317
|
+
const queue = join(directory, "managed-queue", hash(credentials.client_id))
|
|
318
|
+
await mkdir(queue, { recursive: true, mode: 0o700 })
|
|
319
|
+
const packets = events.map(event => ({
|
|
320
|
+
...capturePayload(event, policy.code === true, policy.activity === true),
|
|
321
|
+
acent_destination: policy.destination,
|
|
322
|
+
}))
|
|
323
|
+
const eventBytes = packets.reduce((sum, event) => {
|
|
324
|
+
const bytes = Buffer.byteLength(JSON.stringify(event))
|
|
325
|
+
if (bytes > 2 * 1024 * 1024) throw new Error("Collected event exceeds 2 MiB.")
|
|
326
|
+
return sum + bytes
|
|
327
|
+
}, 0)
|
|
328
|
+
async function capacityError() {
|
|
329
|
+
const files = (await readdir(queue)).filter(file => file.endsWith(".json"))
|
|
330
|
+
if (files.length + packets.length > 500) return "Capture queue is full."
|
|
331
|
+
const sizes = await Promise.all(files.map(file =>
|
|
332
|
+
stat(join(queue, file)).catch(error => {
|
|
333
|
+
if (error.code === "ENOENT") return { size: 0 }
|
|
334
|
+
throw error
|
|
335
|
+
})
|
|
336
|
+
))
|
|
337
|
+
if (sizes.reduce((sum, file) => sum + file.size, eventBytes) > 32 * 1024 * 1024)
|
|
338
|
+
return "Capture queue exceeds 32 MiB."
|
|
339
|
+
}
|
|
340
|
+
if (await capacityError()) {
|
|
341
|
+
await drain(config, directory)
|
|
342
|
+
const error = await capacityError()
|
|
343
|
+
if (error) throw new Error(error + " Retry after pending events are sent.")
|
|
344
|
+
}
|
|
345
|
+
for (const packet of packets) {
|
|
346
|
+
const bridgeId = packet.hook_event_name === "AcentBridge"
|
|
347
|
+
? packet.acent_code_changes?.[0]?.id ?? packet.acent_activity?.[0]?.id
|
|
348
|
+
: null
|
|
349
|
+
const key = bridgeId ? hash(JSON.stringify([packet.acent_destination, packet.session_id, bridgeId])) : random()
|
|
350
|
+
await atomicJson(join(queue, `${at}-${key}.json`), packet)
|
|
351
|
+
}
|
|
352
|
+
}
|
|
311
353
|
function openBrowser(url) {
|
|
312
354
|
const command =
|
|
313
355
|
process.platform === "darwin"
|
|
@@ -459,32 +501,7 @@ export async function main(args = process.argv.slice(2), eventText) {
|
|
|
459
501
|
...toolActivities.map(record => ({ ...payload, acent_code_changes: undefined, acent_activity: [record] })),
|
|
460
502
|
]
|
|
461
503
|
: [payload]
|
|
462
|
-
|
|
463
|
-
throw new Error("Collected event exceeds 2 MiB.")
|
|
464
|
-
const queue = join(directory, "managed-queue", hash(credentials.client_id))
|
|
465
|
-
await mkdir(queue, { recursive: true, mode: 0o700 })
|
|
466
|
-
const packets = events.map(event => ({ ...capturePayload(event, code, activity), acent_destination: policy.destination }))
|
|
467
|
-
const eventBytes = packets.reduce((sum, event) => sum + Buffer.byteLength(JSON.stringify(event)), 0)
|
|
468
|
-
async function capacityError() {
|
|
469
|
-
const files = (await readdir(queue)).filter(file => file.endsWith(".json"))
|
|
470
|
-
if (files.length + events.length > 500) return "Capture queue is full."
|
|
471
|
-
const sizes = await Promise.all(files.map(file =>
|
|
472
|
-
stat(join(queue, file)).catch(error => {
|
|
473
|
-
if (error.code === "ENOENT") return { size: 0 }
|
|
474
|
-
throw error
|
|
475
|
-
})
|
|
476
|
-
))
|
|
477
|
-
if (sizes.reduce((sum, file) => sum + file.size, eventBytes) > 32 * 1024 * 1024)
|
|
478
|
-
return "Capture queue exceeds 32 MiB."
|
|
479
|
-
}
|
|
480
|
-
if (await capacityError()) {
|
|
481
|
-
await drain(config, directory)
|
|
482
|
-
const error = await capacityError()
|
|
483
|
-
if (error) throw new Error(error + " Retry after pending events are sent.")
|
|
484
|
-
}
|
|
485
|
-
for (const event of packets) await atomicJson(
|
|
486
|
-
join(queue, `${Date.now()}-${random()}.json`), event
|
|
487
|
-
)
|
|
504
|
+
await queueManagedCapture(config, directory, policy, events)
|
|
488
505
|
return drain(config, directory)
|
|
489
506
|
}
|
|
490
507
|
if (config.command === "flush") {
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { createHash } from "node:crypto"
|
|
2
|
+
import { redactActivity } from "./capture-activity.mjs"
|
|
3
|
+
import { delegateWorkspacePath } from "./bridge-workspace.mjs"
|
|
4
|
+
|
|
5
|
+
const hash = (parts) => createHash("sha256").update(JSON.stringify(parts)).digest("hex")
|
|
6
|
+
const iso = (at) => new Date(at).toISOString()
|
|
7
|
+
const empty = { text: null, truncated: false }
|
|
8
|
+
const modelName = (value) =>
|
|
9
|
+
typeof value === "string" && value.trim() ? value.trim().slice(0, 200) : null
|
|
10
|
+
const versionHash = (version) =>
|
|
11
|
+
/^[x-]:[a-f0-9]{64}$/.test(version) ? version.slice(2) : null
|
|
12
|
+
|
|
13
|
+
function contributor(job) {
|
|
14
|
+
return {
|
|
15
|
+
taskId: job.id,
|
|
16
|
+
...(job.attempt && { attemptId: job.attempt }),
|
|
17
|
+
tool: job.tool,
|
|
18
|
+
actualModel: modelName(job.actualModel),
|
|
19
|
+
requestedModel: modelName(job.model),
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function bridgeChangeContributors(job, changes, beforeAttempt) {
|
|
24
|
+
const previous = new Map((job.changes ?? []).map((change) => [change.path, change.after]))
|
|
25
|
+
return Object.fromEntries(changes.map(({ path, before, after }) => {
|
|
26
|
+
const start = beforeAttempt ? beforeAttempt[path] ?? null : before
|
|
27
|
+
const prior = start !== before && previous.get(path) === start
|
|
28
|
+
? job.changeContributors?.[path] ?? []
|
|
29
|
+
: []
|
|
30
|
+
return [path, start === after ? prior : [...prior, contributor(job)].slice(-8)]
|
|
31
|
+
}))
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function edits({ id, phase, changes, patch, jobs, at, job, result }) {
|
|
35
|
+
// Git reports --name-only and emits --no-renames patches in the same order.
|
|
36
|
+
const chunks = patch?.split(/(?=^diff --git )/m) ?? []
|
|
37
|
+
const aligned = chunks.length === changes.length && chunks.every((chunk) => chunk.startsWith("diff --git "))
|
|
38
|
+
const callId = `bridge:${id}:${phase}`
|
|
39
|
+
return changes.flatMap(({ path, before, after }, index) => {
|
|
40
|
+
if (!delegateWorkspacePath(path) || path.split("/").some((part) => /^(?:\.ssh|\.aws|\.env(?:\..*)?)$/i.test(part)) ||
|
|
41
|
+
/\.(?:pfx|p12)$/i.test(path)) return []
|
|
42
|
+
const raw = aligned ? chunks[index] : null
|
|
43
|
+
const binary = raw && /^(?:GIT binary patch|Binary files .+ differ)$/m.test(raw)
|
|
44
|
+
const oversized = raw && Buffer.byteLength(raw) > 262144
|
|
45
|
+
const diff = raw && !binary && !oversized ? redactActivity(raw, 262144).text : null
|
|
46
|
+
return [{
|
|
47
|
+
id: hash([callId, path]),
|
|
48
|
+
path,
|
|
49
|
+
diff,
|
|
50
|
+
status: diff ? "captured" : binary ? "binary" : oversized ? "oversized" : "diff_failed",
|
|
51
|
+
basis: "before_after",
|
|
52
|
+
beforeHash: versionHash(before),
|
|
53
|
+
afterHash: versionHash(after),
|
|
54
|
+
beforeExists: before !== null,
|
|
55
|
+
afterExists: after !== null,
|
|
56
|
+
callId,
|
|
57
|
+
capturedAt: iso(at),
|
|
58
|
+
request: null,
|
|
59
|
+
agentNote: redactActivity(job?.task ?? result?.task, 4000).text,
|
|
60
|
+
toolFailed: false,
|
|
61
|
+
attribution: "observed_during_tool",
|
|
62
|
+
bridge: {
|
|
63
|
+
contributors: jobs
|
|
64
|
+
.filter((job) => job.changes?.some((change) => change.path === path))
|
|
65
|
+
.flatMap((job) => job.changeContributors
|
|
66
|
+
? job.changeContributors[path] ?? []
|
|
67
|
+
: job.history?.length ? [] : [contributor(job)])
|
|
68
|
+
.slice(-8),
|
|
69
|
+
...(diff && raw !== diff ? { redacted: true } : {}),
|
|
70
|
+
},
|
|
71
|
+
}]
|
|
72
|
+
})
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function bridgeCaptureEvents(evidence, policy) {
|
|
76
|
+
const { id, phase, status, at, attempt, job, result } = evidence
|
|
77
|
+
const session = `bridge:${id}`
|
|
78
|
+
const envelope = {
|
|
79
|
+
session_id: session,
|
|
80
|
+
conversation_id: session,
|
|
81
|
+
conversationId: session,
|
|
82
|
+
hook_event_name: "AcentBridge",
|
|
83
|
+
}
|
|
84
|
+
const changes = policy.code && evidence.changes ? edits(evidence) : []
|
|
85
|
+
const packets = changes.map((change) => ({ ...envelope, acent_code_changes: [change] }))
|
|
86
|
+
if (!policy.activity) return packets
|
|
87
|
+
const callId = `bridge:${id}:${phase}`
|
|
88
|
+
const outcome = ["applied", "completed", "verified", "no_changes"].includes(status)
|
|
89
|
+
? "succeeded"
|
|
90
|
+
: ["needs_context", "changes_requested", "cancelled", "expired"].includes(status)
|
|
91
|
+
? "unknown"
|
|
92
|
+
: "failed"
|
|
93
|
+
const details = {
|
|
94
|
+
status,
|
|
95
|
+
...(job && { worker: contributor(job), task: job.task, summary: job.summary, findings: job.findings }),
|
|
96
|
+
...result,
|
|
97
|
+
}
|
|
98
|
+
const editIds = changes.map(({ id }) => id)
|
|
99
|
+
// Keep each batch within the existing activity-to-changes link limit.
|
|
100
|
+
for (let index = 0; index < Math.max(1, editIds.length); index += 32) {
|
|
101
|
+
packets.push({
|
|
102
|
+
...envelope,
|
|
103
|
+
acent_activity: [{
|
|
104
|
+
id: hash([callId, attempt ?? status, index]),
|
|
105
|
+
callId,
|
|
106
|
+
name: `Acent Bridge · ${phase} · ${status}`,
|
|
107
|
+
kind: "integration",
|
|
108
|
+
status: outcome,
|
|
109
|
+
capturedAt: iso(at),
|
|
110
|
+
startedAt: null,
|
|
111
|
+
durationMs: null,
|
|
112
|
+
request: null,
|
|
113
|
+
input: empty,
|
|
114
|
+
output: policy.code ? redactActivity(details) : empty,
|
|
115
|
+
changeIds: editIds.slice(index, index + 32),
|
|
116
|
+
}],
|
|
117
|
+
})
|
|
118
|
+
}
|
|
119
|
+
return packets
|
|
120
|
+
}
|
|
@@ -50,6 +50,15 @@ export function bridgeCheckPlan({ commands, setupCommands }) {
|
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
+
const checkName = ({ command, args }) =>
|
|
54
|
+
[command, ...args].join(" ").slice(0, 1500)
|
|
55
|
+
|
|
56
|
+
export function bridgeChecksNotRun(commands = [], results = [], setup = []) {
|
|
57
|
+
const failed = ({ outcome }) => outcome === "failed"
|
|
58
|
+
if (!results.some(failed) && !setup.some(failed)) return []
|
|
59
|
+
return commands.slice(results.length).map(checkName)
|
|
60
|
+
}
|
|
61
|
+
|
|
53
62
|
async function readCheckFile(path) {
|
|
54
63
|
try {
|
|
55
64
|
return JSON.parse(await readFile(path, "utf8"))
|
|
@@ -182,7 +191,8 @@ async function runCheckCommands(request, directory, signal) {
|
|
|
182
191
|
XDG_CACHE_HOME: join(scratch, "cache"),
|
|
183
192
|
npm_config_cache: join(scratch, "npm"),
|
|
184
193
|
}
|
|
185
|
-
async function runCheck(
|
|
194
|
+
async function runCheck(check) {
|
|
195
|
+
const { command, args } = check
|
|
186
196
|
let deadline
|
|
187
197
|
const run = runProcess(sandbox, [...prefix, command, ...args], {
|
|
188
198
|
cwd,
|
|
@@ -204,7 +214,7 @@ async function runCheckCommands(request, directory, signal) {
|
|
|
204
214
|
]).finally(() => clearTimeout(deadline))
|
|
205
215
|
const outcome = result.code === 0 && !result.failure ? "passed" : "failed"
|
|
206
216
|
return {
|
|
207
|
-
name:
|
|
217
|
+
name: checkName(check),
|
|
208
218
|
outcome,
|
|
209
219
|
evidence: [
|
|
210
220
|
result.failure ?? `Exit code ${result.code}`,
|
|
@@ -4,8 +4,10 @@ import { join } from "node:path"
|
|
|
4
4
|
import {
|
|
5
5
|
bridgeCheckPlan,
|
|
6
6
|
bridgeCheckState,
|
|
7
|
+
bridgeChecksNotRun,
|
|
7
8
|
startBridgeCheckWorker,
|
|
8
9
|
} from "./bridge-checks.mjs"
|
|
10
|
+
import { bridgeReviewResult } from "./bridge-review-result.mjs"
|
|
9
11
|
import {
|
|
10
12
|
appliedBridgeChanges,
|
|
11
13
|
bridgeFileVersions,
|
|
@@ -67,7 +69,12 @@ export function createBridgeFinalizer({
|
|
|
67
69
|
if (paths.length) return { status: "review_scope_incomplete", ids, paths }
|
|
68
70
|
}
|
|
69
71
|
|
|
70
|
-
const base = {
|
|
72
|
+
const base = {
|
|
73
|
+
ids: taskIds,
|
|
74
|
+
reviewId,
|
|
75
|
+
reviewSummary: review.summary,
|
|
76
|
+
reviewResult: bridgeReviewResult(review),
|
|
77
|
+
}
|
|
71
78
|
let stored = await readJson(record, null)
|
|
72
79
|
if (stored?.version !== 2) stored = null
|
|
73
80
|
const sameTasks = JSON.stringify(stored?.ids) === JSON.stringify(taskIds)
|
|
@@ -77,6 +84,7 @@ export function createBridgeFinalizer({
|
|
|
77
84
|
const publicResult = ({
|
|
78
85
|
status,
|
|
79
86
|
checks,
|
|
87
|
+
plan: checkPlan,
|
|
80
88
|
setup,
|
|
81
89
|
details,
|
|
82
90
|
paths,
|
|
@@ -85,6 +93,7 @@ export function createBridgeFinalizer({
|
|
|
85
93
|
...base,
|
|
86
94
|
status,
|
|
87
95
|
checks,
|
|
96
|
+
checksNotRun: bridgeChecksNotRun(checkPlan?.commands, checks, setup),
|
|
88
97
|
setup,
|
|
89
98
|
details,
|
|
90
99
|
paths,
|
|
@@ -3,9 +3,11 @@ import { mkdir } from "node:fs/promises"
|
|
|
3
3
|
import { join } from "node:path"
|
|
4
4
|
import { setTimeout } from "node:timers"
|
|
5
5
|
import { modelFamily } from "./bridge-runners.mjs"
|
|
6
|
+
import { bridgeReviewResult } from "./bridge-review-result.mjs"
|
|
6
7
|
import {
|
|
7
8
|
bridgeCheckPlan,
|
|
8
9
|
bridgeCheckState,
|
|
10
|
+
bridgeChecksNotRun,
|
|
9
11
|
startBridgeCheckWorker,
|
|
10
12
|
} from "./bridge-checks.mjs"
|
|
11
13
|
import {
|
|
@@ -192,7 +194,57 @@ const waitingForCoordinator = (cycle) =>
|
|
|
192
194
|
cycle.waiting.length > 0 &&
|
|
193
195
|
!cycle.waiting.some(({ status }) => retryableWaits.has(status))
|
|
194
196
|
|
|
195
|
-
function publicCycle(cycle) {
|
|
197
|
+
async function publicCycle(cycle, getJob, jobState) {
|
|
198
|
+
const waiting = new Map(cycle.waiting.map(({ id, status }) => [id, status]))
|
|
199
|
+
async function describeReview(review, status) {
|
|
200
|
+
const job = await getJob(review.id)
|
|
201
|
+
if (job) return bridgeReviewResult(job, status ?? jobState(job))
|
|
202
|
+
if (status === "completed") return bridgeReviewResult(review, status)
|
|
203
|
+
return {
|
|
204
|
+
...bridgeReviewResult(review, "not_run"),
|
|
205
|
+
...(status ? { reason: status } : {}),
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
async function reviewsInRound(round, reviews) {
|
|
209
|
+
const replaced = (cycle.replacedReviews ?? []).filter(
|
|
210
|
+
(review) => review.round === round
|
|
211
|
+
)
|
|
212
|
+
return Promise.all([
|
|
213
|
+
...replaced.map(async (review) => ({
|
|
214
|
+
...(await describeReview(review, review.status)),
|
|
215
|
+
replaced: true,
|
|
216
|
+
})),
|
|
217
|
+
...reviews,
|
|
218
|
+
])
|
|
219
|
+
}
|
|
220
|
+
const [reviewResults, history] = await Promise.all([
|
|
221
|
+
reviewsInRound(
|
|
222
|
+
cycle.round,
|
|
223
|
+
cycle.reviews.map((review) =>
|
|
224
|
+
describeReview(review, waiting.get(review.id))
|
|
225
|
+
)
|
|
226
|
+
),
|
|
227
|
+
Promise.all(
|
|
228
|
+
cycle.history.map(async ({ round, reviewIds, repairId, findings }) => ({
|
|
229
|
+
round,
|
|
230
|
+
reviewIds,
|
|
231
|
+
repairId,
|
|
232
|
+
reviewResults: await reviewsInRound(
|
|
233
|
+
round,
|
|
234
|
+
reviewIds.map((id) => describeReview({ id }, "completed"))
|
|
235
|
+
),
|
|
236
|
+
findings: findings.map(
|
|
237
|
+
({ path, line, issue, severity, reviewerIds }) => ({
|
|
238
|
+
path,
|
|
239
|
+
line,
|
|
240
|
+
issue,
|
|
241
|
+
severity,
|
|
242
|
+
reviewerIds,
|
|
243
|
+
})
|
|
244
|
+
),
|
|
245
|
+
}))
|
|
246
|
+
),
|
|
247
|
+
])
|
|
196
248
|
return {
|
|
197
249
|
id: cycle.id,
|
|
198
250
|
status:
|
|
@@ -204,25 +256,14 @@ function publicCycle(cycle) {
|
|
|
204
256
|
repairsApplied: cycle.repairsApplied,
|
|
205
257
|
reviews: cycle.reviews.map(({ id, tool, model }) => ({ id, tool, model })),
|
|
206
258
|
repairId: cycle.repairId,
|
|
207
|
-
history
|
|
208
|
-
|
|
209
|
-
reviewIds,
|
|
210
|
-
repairId,
|
|
211
|
-
findings: findings.map(
|
|
212
|
-
({ path, line, issue, severity, reviewerIds }) => ({
|
|
213
|
-
path,
|
|
214
|
-
line,
|
|
215
|
-
issue,
|
|
216
|
-
severity,
|
|
217
|
-
reviewerIds,
|
|
218
|
-
})
|
|
219
|
-
),
|
|
220
|
-
})),
|
|
259
|
+
history,
|
|
260
|
+
reviewResults,
|
|
221
261
|
findings: cycle.findings,
|
|
222
262
|
waiting: cycle.waiting,
|
|
223
263
|
patchPath: cycle.patchPath,
|
|
224
264
|
details: cycle.details,
|
|
225
265
|
checks: cycle.checks,
|
|
266
|
+
checksNotRun: bridgeChecksNotRun(cycle.commands, cycle.checks, cycle.setup),
|
|
226
267
|
setup: cycle.setup,
|
|
227
268
|
checkRevision: ["needs_checks", "checks_failed", "patch_ready"].includes(
|
|
228
269
|
cycle.status
|
|
@@ -268,6 +309,18 @@ export function createBridgeRefinement({
|
|
|
268
309
|
select,
|
|
269
310
|
cancelJob,
|
|
270
311
|
} = operations
|
|
312
|
+
const checkResults = (cycle) => cycle.checks?.map(({ name, outcome }) => ({ name, outcome }))
|
|
313
|
+
const respond = async (cycle) => {
|
|
314
|
+
const result = await publicCycle(cycle, getJob, jobState)
|
|
315
|
+
if (settings.captureEvidence &&
|
|
316
|
+
["checks_failed", "changes_requested", "cancelled", "expired"].includes(result.status))
|
|
317
|
+
await settings.captureEvidence({
|
|
318
|
+
id: cycle.id, phase: "refine", status: result.status, at: Date.now(),
|
|
319
|
+
attempt: `${cycle.round}:${cycle.checkAttempt ?? ""}:${result.status}`,
|
|
320
|
+
result: { reviews: result.reviewResults, findings: result.findings, checks: checkResults(cycle) },
|
|
321
|
+
})
|
|
322
|
+
return result
|
|
323
|
+
}
|
|
271
324
|
const action = args.action ?? "status"
|
|
272
325
|
if (
|
|
273
326
|
![
|
|
@@ -722,6 +775,12 @@ export function createBridgeRefinement({
|
|
|
722
775
|
throw new Error(
|
|
723
776
|
"Select an available replacement from the Bridge candidate list."
|
|
724
777
|
)
|
|
778
|
+
cycle.replacedReviews ??= []
|
|
779
|
+
cycle.replacedReviews.push({
|
|
780
|
+
...cycle.reviews[index],
|
|
781
|
+
round: cycle.round,
|
|
782
|
+
status: failure,
|
|
783
|
+
})
|
|
725
784
|
cycle.reviews[index] = { id: randomUUID(), tool, model }
|
|
726
785
|
cycle.waiting = cycle.waiting.filter(({ id }) => id !== args.reviewId)
|
|
727
786
|
await save(cycle)
|
|
@@ -836,7 +895,8 @@ export function createBridgeRefinement({
|
|
|
836
895
|
}
|
|
837
896
|
|
|
838
897
|
async function apply(cycle) {
|
|
839
|
-
|
|
898
|
+
const current = await allowed(cycle)
|
|
899
|
+
if (!current) return
|
|
840
900
|
await lockWorkspace(async () => {
|
|
841
901
|
if (await cancellationRequested()) return
|
|
842
902
|
if (await preparingWorkspace()) {
|
|
@@ -845,6 +905,7 @@ export function createBridgeRefinement({
|
|
|
845
905
|
}
|
|
846
906
|
const expected = await expectedFiles(cycle)
|
|
847
907
|
const actual = await originalVersions()
|
|
908
|
+
const change = cycle.patchPath ? await readJson(cycle.patchPath, null) : null
|
|
848
909
|
// A restarted process can recognize the exact patch it previously started applying.
|
|
849
910
|
if (
|
|
850
911
|
!cycle.applying ||
|
|
@@ -853,7 +914,6 @@ export function createBridgeRefinement({
|
|
|
853
914
|
if (stale(cycle, expected.original, actual)) return
|
|
854
915
|
if (!(await checkDependencies(cycle, folder))) return
|
|
855
916
|
if (cycle.patchPath) {
|
|
856
|
-
const change = await readJson(cycle.patchPath, null)
|
|
857
917
|
if (!change || patchDigest(change) !== cycle.patchDigest) {
|
|
858
918
|
cycle.status = "changes_requested"
|
|
859
919
|
cycle.details = { reason: "verified_patch_unavailable" }
|
|
@@ -888,6 +948,17 @@ export function createBridgeRefinement({
|
|
|
888
948
|
await lock(promotionGate, async () => {
|
|
889
949
|
if (!cycle.applying && (await cancellationRequested())) return
|
|
890
950
|
cycle.status = "verified"
|
|
951
|
+
const at = Date.now()
|
|
952
|
+
if (current.captureEvidence) {
|
|
953
|
+
const jobs = await Promise.all(cycle.history
|
|
954
|
+
.filter(({ repairId }) => repairId)
|
|
955
|
+
.map(({ repairId }) => getJob(repairId)))
|
|
956
|
+
await current.captureEvidence({
|
|
957
|
+
id: cycle.id, phase: "refine", status: "verified", at,
|
|
958
|
+
changes: change?.changes, patch: change?.patch, jobs: jobs.filter(Boolean),
|
|
959
|
+
result: { task: cycle.input.task, reviews: cycle.reviews, checks: checkResults(cycle) },
|
|
960
|
+
})
|
|
961
|
+
}
|
|
891
962
|
cycle.patchPath = undefined
|
|
892
963
|
await save(cycle)
|
|
893
964
|
})
|
|
@@ -950,9 +1021,9 @@ export function createBridgeRefinement({
|
|
|
950
1021
|
if (
|
|
951
1022
|
["verified", "cancelled", "expired", "applying"].includes(value.status)
|
|
952
1023
|
)
|
|
953
|
-
return
|
|
1024
|
+
return respond(value)
|
|
954
1025
|
schedule(value, true)
|
|
955
|
-
return
|
|
1026
|
+
return respond({ ...value, status: "cancelling" })
|
|
956
1027
|
}
|
|
957
1028
|
if (action === "status") {
|
|
958
1029
|
const active = await readJson(record, null)
|
|
@@ -962,14 +1033,14 @@ export function createBridgeRefinement({
|
|
|
962
1033
|
(await cancellationRequested())
|
|
963
1034
|
) {
|
|
964
1035
|
schedule(active, true)
|
|
965
|
-
return
|
|
1036
|
+
return respond({ ...active, status: "cancelling" })
|
|
966
1037
|
}
|
|
967
1038
|
if (
|
|
968
1039
|
timers.has(record) &&
|
|
969
1040
|
active?.status === "running" &&
|
|
970
1041
|
active.phase === "checks"
|
|
971
1042
|
)
|
|
972
|
-
return
|
|
1043
|
+
return respond(active)
|
|
973
1044
|
}
|
|
974
1045
|
const cycle = await lock(directory, async () => {
|
|
975
1046
|
let value = await readJson(record, null)
|
|
@@ -1077,6 +1148,6 @@ export function createBridgeRefinement({
|
|
|
1077
1148
|
return value
|
|
1078
1149
|
})
|
|
1079
1150
|
schedule(cycle)
|
|
1080
|
-
return
|
|
1151
|
+
return respond(cycle)
|
|
1081
1152
|
}
|
|
1082
1153
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export function bridgeReviewResult(review, status = review.status) {
|
|
2
|
+
const { id, tool, model, actualModel, findings } = review
|
|
3
|
+
const result = { id, tool, model, actualModel, status }
|
|
4
|
+
if (status !== "completed") return result
|
|
5
|
+
|
|
6
|
+
if (!Array.isArray(findings)) return { ...result, outcome: "unclassified" }
|
|
7
|
+
return {
|
|
8
|
+
...result,
|
|
9
|
+
outcome: findings.length ? "findings_reported" : "no_findings",
|
|
10
|
+
findings,
|
|
11
|
+
}
|
|
12
|
+
}
|