@cirtium/acent-connect 1.1.1 → 1.1.3
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 +26 -4
- package/acent/scripts/bridge-refinement.mjs +104 -24
- package/acent/scripts/bridge-review-result.mjs +12 -0
- package/acent/scripts/bridge-runners.mjs +136 -34
- package/acent/scripts/bridge-workspace.mjs +64 -5
- package/acent/scripts/bridge.mjs +257 -52
- package/acent/scripts/capture-activity.mjs +5 -3
- package/acent/scripts/mcp-proxy.mjs +17 -1
- package/acent/skills/acent-bridge/SKILL.md +16 -3
- 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,15 +4,20 @@ 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,
|
|
12
14
|
changedBridgePaths,
|
|
15
|
+
delegateScopes,
|
|
16
|
+
delegateWorkspacePath,
|
|
13
17
|
mismatchedBridgePaths,
|
|
14
18
|
projectFileVersions,
|
|
15
19
|
projectSnapshot,
|
|
20
|
+
withinPaths,
|
|
16
21
|
} from "./bridge-workspace.mjs"
|
|
17
22
|
|
|
18
23
|
export function createBridgeFinalizer({
|
|
@@ -52,8 +57,24 @@ export function createBridgeFinalizer({
|
|
|
52
57
|
return { status: "integration_required", ids }
|
|
53
58
|
const baseline = await readJson(join(jobDir, "baseline.json"), null)
|
|
54
59
|
if (!baseline) return { status: "review_required", ids }
|
|
60
|
+
const reviewedSource = baseline.sourceFiles ?? baseline.files
|
|
61
|
+
const applied = appliedBridgeChanges(tasks)
|
|
62
|
+
if (baseline.scoped) {
|
|
63
|
+
const scopes = baseline.scopes ?? delegateScopes(review)
|
|
64
|
+
const paths = applied
|
|
65
|
+
.map(({ path }) => path)
|
|
66
|
+
.filter(
|
|
67
|
+
(path) => !delegateWorkspacePath(path) || !withinPaths(path, scopes)
|
|
68
|
+
)
|
|
69
|
+
if (paths.length) return { status: "review_scope_incomplete", ids, paths }
|
|
70
|
+
}
|
|
55
71
|
|
|
56
|
-
const base = {
|
|
72
|
+
const base = {
|
|
73
|
+
ids: taskIds,
|
|
74
|
+
reviewId,
|
|
75
|
+
reviewSummary: review.summary,
|
|
76
|
+
reviewResult: bridgeReviewResult(review),
|
|
77
|
+
}
|
|
57
78
|
let stored = await readJson(record, null)
|
|
58
79
|
if (stored?.version !== 2) stored = null
|
|
59
80
|
const sameTasks = JSON.stringify(stored?.ids) === JSON.stringify(taskIds)
|
|
@@ -63,6 +84,7 @@ export function createBridgeFinalizer({
|
|
|
63
84
|
const publicResult = ({
|
|
64
85
|
status,
|
|
65
86
|
checks,
|
|
87
|
+
plan: checkPlan,
|
|
66
88
|
setup,
|
|
67
89
|
details,
|
|
68
90
|
paths,
|
|
@@ -71,14 +93,14 @@ export function createBridgeFinalizer({
|
|
|
71
93
|
...base,
|
|
72
94
|
status,
|
|
73
95
|
checks,
|
|
96
|
+
checksNotRun: bridgeChecksNotRun(checkPlan?.commands, checks, setup),
|
|
74
97
|
setup,
|
|
75
98
|
details,
|
|
76
99
|
paths,
|
|
77
100
|
checkedAt,
|
|
78
101
|
})
|
|
79
|
-
const applied = appliedBridgeChanges(tasks)
|
|
80
102
|
const readStalePaths = async () =>
|
|
81
|
-
changedBridgePaths(
|
|
103
|
+
changedBridgePaths(reviewedSource, await bridgeFileVersions(folder))
|
|
82
104
|
async function checkOriginal() {
|
|
83
105
|
const stale = await readStalePaths()
|
|
84
106
|
if (stale.length) return { status: "review_stale", paths: stale }
|
|
@@ -168,7 +190,7 @@ export function createBridgeFinalizer({
|
|
|
168
190
|
if (!(await readJson(requestFile, null))) {
|
|
169
191
|
await rm(attemptDir, { recursive: true, force: true })
|
|
170
192
|
await projectSnapshot(folder, work, async (snapshot) => {
|
|
171
|
-
const changed = changedBridgePaths(
|
|
193
|
+
const changed = changedBridgePaths(reviewedSource, snapshot.files)
|
|
172
194
|
if (!changed.length)
|
|
173
195
|
await writeJson(requestFile, {
|
|
174
196
|
cwd: work,
|
|
@@ -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 {
|
|
@@ -16,6 +18,7 @@ import {
|
|
|
16
18
|
changedBridgePaths,
|
|
17
19
|
checkpointBridgeWorkspace,
|
|
18
20
|
cloneBridgeSnapshot,
|
|
21
|
+
delegateWorkspacePath,
|
|
19
22
|
inspectBridgeChanges,
|
|
20
23
|
mismatchedBridgePaths,
|
|
21
24
|
projectFileVersions,
|
|
@@ -46,6 +49,7 @@ const resumableRepairStates = new Set([
|
|
|
46
49
|
"model_unavailable",
|
|
47
50
|
"login_required",
|
|
48
51
|
"not_installed",
|
|
52
|
+
"workspace_untrusted",
|
|
49
53
|
])
|
|
50
54
|
const terminal = new Set([
|
|
51
55
|
"verified",
|
|
@@ -117,11 +121,15 @@ function cycleInput(args, targets, isId) {
|
|
|
117
121
|
throw new Error(
|
|
118
122
|
"Select a repair model and one to four independent review models from distinct eligible families."
|
|
119
123
|
)
|
|
124
|
+
const readPaths = args.readPaths ?? []
|
|
120
125
|
if (
|
|
121
126
|
!Array.isArray(args.paths) ||
|
|
122
127
|
!args.paths.length ||
|
|
123
128
|
args.paths.length > 64 ||
|
|
124
|
-
!args.paths.every(
|
|
129
|
+
!args.paths.every(delegateWorkspacePath) ||
|
|
130
|
+
!Array.isArray(readPaths) ||
|
|
131
|
+
readPaths.length > 64 ||
|
|
132
|
+
!readPaths.every(delegateWorkspacePath)
|
|
125
133
|
)
|
|
126
134
|
throw new Error("Select one to 64 project-relative paths for refinement.")
|
|
127
135
|
if (
|
|
@@ -152,6 +160,7 @@ function cycleInput(args, targets, isId) {
|
|
|
152
160
|
acceptance: args.acceptance,
|
|
153
161
|
context: args.context,
|
|
154
162
|
paths: [...new Set(args.paths)].sort(),
|
|
163
|
+
...(readPaths.length ? { readPaths: [...new Set(readPaths)].sort() } : {}),
|
|
155
164
|
originModel: args.originModel,
|
|
156
165
|
repair: pick(args.repair),
|
|
157
166
|
reviewers: reviewers.map(pick),
|
|
@@ -185,7 +194,57 @@ const waitingForCoordinator = (cycle) =>
|
|
|
185
194
|
cycle.waiting.length > 0 &&
|
|
186
195
|
!cycle.waiting.some(({ status }) => retryableWaits.has(status))
|
|
187
196
|
|
|
188
|
-
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
|
+
])
|
|
189
248
|
return {
|
|
190
249
|
id: cycle.id,
|
|
191
250
|
status:
|
|
@@ -197,25 +256,14 @@ function publicCycle(cycle) {
|
|
|
197
256
|
repairsApplied: cycle.repairsApplied,
|
|
198
257
|
reviews: cycle.reviews.map(({ id, tool, model }) => ({ id, tool, model })),
|
|
199
258
|
repairId: cycle.repairId,
|
|
200
|
-
history
|
|
201
|
-
|
|
202
|
-
reviewIds,
|
|
203
|
-
repairId,
|
|
204
|
-
findings: findings.map(
|
|
205
|
-
({ path, line, issue, severity, reviewerIds }) => ({
|
|
206
|
-
path,
|
|
207
|
-
line,
|
|
208
|
-
issue,
|
|
209
|
-
severity,
|
|
210
|
-
reviewerIds,
|
|
211
|
-
})
|
|
212
|
-
),
|
|
213
|
-
})),
|
|
259
|
+
history,
|
|
260
|
+
reviewResults,
|
|
214
261
|
findings: cycle.findings,
|
|
215
262
|
waiting: cycle.waiting,
|
|
216
263
|
patchPath: cycle.patchPath,
|
|
217
264
|
details: cycle.details,
|
|
218
265
|
checks: cycle.checks,
|
|
266
|
+
checksNotRun: bridgeChecksNotRun(cycle.commands, cycle.checks, cycle.setup),
|
|
219
267
|
setup: cycle.setup,
|
|
220
268
|
checkRevision: ["needs_checks", "checks_failed", "patch_ready"].includes(
|
|
221
269
|
cycle.status
|
|
@@ -261,6 +309,18 @@ export function createBridgeRefinement({
|
|
|
261
309
|
select,
|
|
262
310
|
cancelJob,
|
|
263
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
|
+
}
|
|
264
324
|
const action = args.action ?? "status"
|
|
265
325
|
if (
|
|
266
326
|
![
|
|
@@ -505,6 +565,7 @@ export function createBridgeRefinement({
|
|
|
505
565
|
.filter(Boolean)
|
|
506
566
|
.join("\n"),
|
|
507
567
|
paths: cycle.input.paths,
|
|
568
|
+
readPaths: cycle.input.readPaths,
|
|
508
569
|
dependsOn: cycle.round === 1 ? cycle.input.dependsOn : [],
|
|
509
570
|
automatic: cycle.input.automatic,
|
|
510
571
|
},
|
|
@@ -518,7 +579,7 @@ export function createBridgeRefinement({
|
|
|
518
579
|
const families = new Set()
|
|
519
580
|
for (const [index, job] of jobs.entries()) {
|
|
520
581
|
const baseline = await getBaseline(job.id)
|
|
521
|
-
if (baseline?.head !== cycle.stage.head) {
|
|
582
|
+
if ((baseline?.sourceHead ?? baseline?.head) !== cycle.stage.head) {
|
|
522
583
|
cycle.waiting.push({
|
|
523
584
|
id: job.id,
|
|
524
585
|
status: "review_snapshot_unavailable",
|
|
@@ -595,6 +656,7 @@ export function createBridgeRefinement({
|
|
|
595
656
|
.filter(Boolean)
|
|
596
657
|
.join("\n"),
|
|
597
658
|
paths: cycle.input.paths,
|
|
659
|
+
readPaths: cycle.input.readPaths,
|
|
598
660
|
automatic: cycle.input.automatic,
|
|
599
661
|
},
|
|
600
662
|
current,
|
|
@@ -713,6 +775,12 @@ export function createBridgeRefinement({
|
|
|
713
775
|
throw new Error(
|
|
714
776
|
"Select an available replacement from the Bridge candidate list."
|
|
715
777
|
)
|
|
778
|
+
cycle.replacedReviews ??= []
|
|
779
|
+
cycle.replacedReviews.push({
|
|
780
|
+
...cycle.reviews[index],
|
|
781
|
+
round: cycle.round,
|
|
782
|
+
status: failure,
|
|
783
|
+
})
|
|
716
784
|
cycle.reviews[index] = { id: randomUUID(), tool, model }
|
|
717
785
|
cycle.waiting = cycle.waiting.filter(({ id }) => id !== args.reviewId)
|
|
718
786
|
await save(cycle)
|
|
@@ -827,7 +895,8 @@ export function createBridgeRefinement({
|
|
|
827
895
|
}
|
|
828
896
|
|
|
829
897
|
async function apply(cycle) {
|
|
830
|
-
|
|
898
|
+
const current = await allowed(cycle)
|
|
899
|
+
if (!current) return
|
|
831
900
|
await lockWorkspace(async () => {
|
|
832
901
|
if (await cancellationRequested()) return
|
|
833
902
|
if (await preparingWorkspace()) {
|
|
@@ -836,6 +905,7 @@ export function createBridgeRefinement({
|
|
|
836
905
|
}
|
|
837
906
|
const expected = await expectedFiles(cycle)
|
|
838
907
|
const actual = await originalVersions()
|
|
908
|
+
const change = cycle.patchPath ? await readJson(cycle.patchPath, null) : null
|
|
839
909
|
// A restarted process can recognize the exact patch it previously started applying.
|
|
840
910
|
if (
|
|
841
911
|
!cycle.applying ||
|
|
@@ -844,7 +914,6 @@ export function createBridgeRefinement({
|
|
|
844
914
|
if (stale(cycle, expected.original, actual)) return
|
|
845
915
|
if (!(await checkDependencies(cycle, folder))) return
|
|
846
916
|
if (cycle.patchPath) {
|
|
847
|
-
const change = await readJson(cycle.patchPath, null)
|
|
848
917
|
if (!change || patchDigest(change) !== cycle.patchDigest) {
|
|
849
918
|
cycle.status = "changes_requested"
|
|
850
919
|
cycle.details = { reason: "verified_patch_unavailable" }
|
|
@@ -879,6 +948,17 @@ export function createBridgeRefinement({
|
|
|
879
948
|
await lock(promotionGate, async () => {
|
|
880
949
|
if (!cycle.applying && (await cancellationRequested())) return
|
|
881
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
|
+
}
|
|
882
962
|
cycle.patchPath = undefined
|
|
883
963
|
await save(cycle)
|
|
884
964
|
})
|
|
@@ -941,9 +1021,9 @@ export function createBridgeRefinement({
|
|
|
941
1021
|
if (
|
|
942
1022
|
["verified", "cancelled", "expired", "applying"].includes(value.status)
|
|
943
1023
|
)
|
|
944
|
-
return
|
|
1024
|
+
return respond(value)
|
|
945
1025
|
schedule(value, true)
|
|
946
|
-
return
|
|
1026
|
+
return respond({ ...value, status: "cancelling" })
|
|
947
1027
|
}
|
|
948
1028
|
if (action === "status") {
|
|
949
1029
|
const active = await readJson(record, null)
|
|
@@ -953,14 +1033,14 @@ export function createBridgeRefinement({
|
|
|
953
1033
|
(await cancellationRequested())
|
|
954
1034
|
) {
|
|
955
1035
|
schedule(active, true)
|
|
956
|
-
return
|
|
1036
|
+
return respond({ ...active, status: "cancelling" })
|
|
957
1037
|
}
|
|
958
1038
|
if (
|
|
959
1039
|
timers.has(record) &&
|
|
960
1040
|
active?.status === "running" &&
|
|
961
1041
|
active.phase === "checks"
|
|
962
1042
|
)
|
|
963
|
-
return
|
|
1043
|
+
return respond(active)
|
|
964
1044
|
}
|
|
965
1045
|
const cycle = await lock(directory, async () => {
|
|
966
1046
|
let value = await readJson(record, null)
|
|
@@ -1068,6 +1148,6 @@ export function createBridgeRefinement({
|
|
|
1068
1148
|
return value
|
|
1069
1149
|
})
|
|
1070
1150
|
schedule(cycle)
|
|
1071
|
-
return
|
|
1151
|
+
return respond(cycle)
|
|
1072
1152
|
}
|
|
1073
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
|
+
}
|