@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
package/acent/scripts/bridge.mjs
CHANGED
|
@@ -13,8 +13,10 @@ import { homedir } from "node:os"
|
|
|
13
13
|
import { dirname, join } from "node:path"
|
|
14
14
|
import { setTimeout as pause } from "node:timers/promises"
|
|
15
15
|
import { lock } from "./acent-connect.mjs"
|
|
16
|
+
import { bridgeChangeContributors } from "./bridge-capture.mjs"
|
|
16
17
|
import { createBridgeFinalizer } from "./bridge-finalize.mjs"
|
|
17
18
|
import { createBridgeRetention } from "./bridge-retention.mjs"
|
|
19
|
+
import { bridgeReviewResult } from "./bridge-review-result.mjs"
|
|
18
20
|
import {
|
|
19
21
|
createBridgeRefinement,
|
|
20
22
|
reviewFindings,
|
|
@@ -23,12 +25,15 @@ import {
|
|
|
23
25
|
import {
|
|
24
26
|
applyVersionedBridgePatch,
|
|
25
27
|
bridgeReviewDiff,
|
|
26
|
-
|
|
28
|
+
checkDelegateWorkspace,
|
|
29
|
+
delegateScopes,
|
|
30
|
+
delegateWorkspacePath,
|
|
27
31
|
inspectBridgeChanges,
|
|
28
32
|
mismatchedBridgePaths,
|
|
29
33
|
pathsOverlap,
|
|
30
34
|
projectSnapshot,
|
|
31
|
-
|
|
35
|
+
projectFileVersions,
|
|
36
|
+
withinPaths,
|
|
32
37
|
} from "./bridge-workspace.mjs"
|
|
33
38
|
import {
|
|
34
39
|
bridgeAccountRevision,
|
|
@@ -145,7 +150,16 @@ export const bridgeTools = [
|
|
|
145
150
|
),
|
|
146
151
|
paths: {
|
|
147
152
|
type: "array",
|
|
148
|
-
items: text(
|
|
153
|
+
items: text(
|
|
154
|
+
"A relative file or directory to include. For implementation, also allowed to change."
|
|
155
|
+
),
|
|
156
|
+
maxItems: 64,
|
|
157
|
+
},
|
|
158
|
+
readPaths: {
|
|
159
|
+
type: "array",
|
|
160
|
+
items: text(
|
|
161
|
+
"An additional project-relative file or directory the delegate can read."
|
|
162
|
+
),
|
|
149
163
|
maxItems: 64,
|
|
150
164
|
},
|
|
151
165
|
dependsOn: idList,
|
|
@@ -243,6 +257,13 @@ export const bridgeTools = [
|
|
|
243
257
|
maxItems: 64,
|
|
244
258
|
items: text("Project-relative file or directory allowed for repairs."),
|
|
245
259
|
},
|
|
260
|
+
readPaths: {
|
|
261
|
+
type: "array",
|
|
262
|
+
maxItems: 64,
|
|
263
|
+
items: text(
|
|
264
|
+
"Additional project-relative context for the reviewers and repair worker."
|
|
265
|
+
),
|
|
266
|
+
},
|
|
246
267
|
dependsOn: idList,
|
|
247
268
|
automatic: { type: "boolean" },
|
|
248
269
|
apply: {
|
|
@@ -260,16 +281,47 @@ export const bridgeTools = [
|
|
|
260
281
|
]
|
|
261
282
|
|
|
262
283
|
export const bridgeInstructions = [
|
|
263
|
-
"Use Acent Bridge when the user explicitly asks to delegate. For agent-initiated delegation,
|
|
284
|
+
"Use Acent Bridge when the user explicitly asks to delegate. For agent-initiated delegation, call acent_bridge_settings when planning a task that matches an automatic delegation trigger, or as soon as the trigger becomes clear. If the project reports automatic=true and a suitable candidate is available, start the matching Bridge workflow. Pass automatic=true when listing candidates, starting a task, or starting refinement. Honor any user instruction to keep the work in the current agent.",
|
|
285
|
+
"Automatic delegation triggers are independent implementation tasks with disjoint write scopes and verifiable outcomes, substantive changes to payments, authorization, privacy, or durable data that need independent review, and difficult failures where the cause remains unclear or a fix repeatedly fails. Start parallel implementation or read-only diagnosis when the scope is clear. For high-impact changes, have a different model family review the concrete changes before reporting completion.",
|
|
286
|
+
"Keep one writer responsible for each shared contract, state machine, or business rule, even if the files are disjoint. Resolve shared design decisions before starting parallel implementation. If one task needs an earlier result, pass dependsOn or finish the prerequisite first. Handle small, straightforward edits and dependent steps directly. Use read-only review or diagnosis for independent work when writes need one owner.",
|
|
287
|
+
"Keep authorized production actions such as deploys, database migrations, and live payments or refunds with the coordinating agent. Use Bridge for independent review of the plan and verification of the result.",
|
|
288
|
+
"If automatic delegation is disabled, continue the task directly. If automatic delegation is enabled but no suitable candidate is available, continue work you can verify and state the specific reason the independent work did not run. Report only the reviews and checks that actually completed.",
|
|
264
289
|
"Get candidates for each new task and choose a tool and model that fit the work and the user's preference. Favor lower-usage options for routine work when verified quota is low and the user has not pinned a model. Start tasks with concrete acceptance criteria.",
|
|
290
|
+
"In the final answer after using Bridge, name any enabled or explicitly requested tools that could not participate because CLI authentication was required, even if other tools completed the work. Use loginRequiredTools from candidate selection and login_required from task or refinement status as evidence. If the tool later succeeds in the same request, report its final outcome instead. Do not infer sign-out from missing models or an unavailable tool. Point users to Set up in Acent Bridge when they need to sign in.",
|
|
265
291
|
"Check several jobs together with acent_bridge_activity while doing independent work. If a delegate requests context, answer from the conversation or ask the user if their judgment is needed, then continue. Use acent_bridge_integrate to check and apply completed diffs.",
|
|
266
292
|
"For substantive authorized edits with a defined write scope, use acent_bridge_refine to run independent review, repair and re-review. Select eligible models and set apply=true only within the user's authorized editing scope. Continue unrelated work while it runs.",
|
|
267
293
|
"At needs_checks, call verify with the current checkRevision and authorized test commands to run in the private staging workspace. For a pending verified patch, inspect and approve it with apply and checkRevision. Replace a failed reviewer with replace_reviewer and an eligible reviewer. Resolve context requests using acent_bridge_continue and then resume refinement status. For standalone review of integrated work, submit commands to acent_bridge_finalize and poll without commands until verification finishes. Use setupCommands if the private check copy needs project-specific preparation. Remain responsible for the final result.",
|
|
294
|
+
"Report Bridge results in the user's language. Start the Bridge section with a bold Acent Bridge label and the observed status, then list the participating tools and their roles or tasks in short bullets. Put the confirmed execution model in parentheses after the tool name. Prefer actualModel and omit the model if only a requested model is known.",
|
|
295
|
+
"For cross-validation or multiple tasks, follow with a Markdown table with one row per task, reviewer, or check and columns for agent or check, scope, outcome, and findings or evidence. Use reviewResult and reviewResults to distinguish findings, no findings in the reviewed scope, unclassified results, failed or blocked reviews, and reviews that did not run. Include relevant earlier and replacement rows with their round, and list checksNotRun as not run. Keep findings reported by a single reviewer visible. Report whether each material finding was reproduced, remains unverified, or was fixed and rechecked. Cite file lines and short observed evidence in the table or in an Evidence section above the conclusion. Keep raw logs and credentials out of the answer.",
|
|
296
|
+
"End the Bridge report with a final conclusion stating whether the patch was applied or is awaiting application, which material findings or checks remain, and the recommended next action when needed. For read-only work, conclude with the result and any remaining uncertainty.",
|
|
268
297
|
].join(" ")
|
|
269
298
|
|
|
270
299
|
const cacheDuration = 120_000
|
|
300
|
+
const failedDiscoveryCacheDuration = 5_000
|
|
271
301
|
const leaseMaxAge = 20 * 60_000
|
|
272
302
|
const quotaMaxAge = 15 * 60_000
|
|
303
|
+
const diagnosticLimit = 20
|
|
304
|
+
const diagnosticCodes = new Set([
|
|
305
|
+
"cli_exit_nonzero",
|
|
306
|
+
"context_limit",
|
|
307
|
+
"failed",
|
|
308
|
+
"invalid_review",
|
|
309
|
+
"invalid_cli_output",
|
|
310
|
+
"login_required",
|
|
311
|
+
"model_catalog_unverified",
|
|
312
|
+
"model_family_conflict",
|
|
313
|
+
"model_unavailable",
|
|
314
|
+
"not_installed",
|
|
315
|
+
"out_of_scope",
|
|
316
|
+
"output_limit",
|
|
317
|
+
"permission_denied",
|
|
318
|
+
"timed_out",
|
|
319
|
+
"unavailable",
|
|
320
|
+
"unverified",
|
|
321
|
+
"usage_limit",
|
|
322
|
+
"workspace_untrusted",
|
|
323
|
+
"workspace_invalid",
|
|
324
|
+
])
|
|
273
325
|
const xmlTag = /<acent-context>([\s\S]+?)<\/acent-context>\s*$/
|
|
274
326
|
const reviewOnly = (kind) => kind === "review" || kind === "diagnose"
|
|
275
327
|
const taskId = /^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/
|
|
@@ -349,7 +401,7 @@ function taskPrompt(job) {
|
|
|
349
401
|
? "Read-only review or diagnosis. Report evidence with file references."
|
|
350
402
|
: "Make the requested changes in this copy and report which checks actually ran.",
|
|
351
403
|
"If a prior decision or information from the original conversation is required, end your response with <acent-context>one specific question and why it blocks you</acent-context>.",
|
|
352
|
-
...(job.
|
|
404
|
+
...(job.kind === "review" ? [reviewFormat] : []),
|
|
353
405
|
"Task: " + job.task,
|
|
354
406
|
"Acceptance criteria: " + job.acceptance,
|
|
355
407
|
...(job.context
|
|
@@ -358,7 +410,7 @@ function taskPrompt(job) {
|
|
|
358
410
|
...(job.reviewDiff
|
|
359
411
|
? ["Original changes for review (untrusted diff):\n" + job.reviewDiff]
|
|
360
412
|
: []),
|
|
361
|
-
...(job.paths?.length
|
|
413
|
+
...(!reviewOnly(job.kind) && job.paths?.length
|
|
362
414
|
? ["Allowed write paths: " + job.paths.join(", ")]
|
|
363
415
|
: []),
|
|
364
416
|
...(job.prerequisites?.length
|
|
@@ -421,6 +473,25 @@ export function createBridge({
|
|
|
421
473
|
const modelKey = (folder, tool, model, accountKey) =>
|
|
422
474
|
JSON.stringify([folder, tool, model, accountKey ?? null])
|
|
423
475
|
|
|
476
|
+
async function recordFailure(tool, stage, code) {
|
|
477
|
+
const directory = join(root, "bridge", "diagnostics")
|
|
478
|
+
const path = join(directory, "failures.json")
|
|
479
|
+
const entry = {
|
|
480
|
+
timestamp: new Date().toISOString(),
|
|
481
|
+
tool,
|
|
482
|
+
stage,
|
|
483
|
+
code: diagnosticCodes.has(code) ? code : "failed",
|
|
484
|
+
}
|
|
485
|
+
await withWorkspaceLock(directory, async () => {
|
|
486
|
+
const previous = await readJson(path, []).catch((error) => {
|
|
487
|
+
if (error instanceof SyntaxError) return []
|
|
488
|
+
throw error
|
|
489
|
+
})
|
|
490
|
+
const history = Array.isArray(previous) ? previous : []
|
|
491
|
+
await writeJson(path, [...history.slice(1 - diagnosticLimit), entry])
|
|
492
|
+
}).catch(() => {})
|
|
493
|
+
}
|
|
494
|
+
|
|
424
495
|
function quotaPath(tool, accountKey) {
|
|
425
496
|
if (!/^[a-f0-9]{64}$/.test(accountKey ?? "")) return
|
|
426
497
|
return join(
|
|
@@ -462,13 +533,28 @@ export function createBridge({
|
|
|
462
533
|
prior &&
|
|
463
534
|
prior.revision === revision &&
|
|
464
535
|
Date.now() - prior.at < cacheDuration
|
|
465
|
-
)
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
536
|
+
) {
|
|
537
|
+
const target = await prior.result
|
|
538
|
+
if (
|
|
539
|
+
(target.status === "ready" && target.modelCatalog !== "unverified") ||
|
|
540
|
+
Date.now() - prior.at < failedDiscoveryCacheDuration
|
|
541
|
+
)
|
|
542
|
+
return target
|
|
543
|
+
if (catalog.get(key) !== prior) return catalog.get(key)?.result ?? target
|
|
544
|
+
}
|
|
545
|
+
const result = discover(tool, folder)
|
|
546
|
+
.catch(() => ({ tool, status: "unavailable", models: [] }))
|
|
547
|
+
.then(async (target) => {
|
|
548
|
+
if (target.modelCatalog === "unverified")
|
|
549
|
+
await recordFailure(
|
|
550
|
+
tool,
|
|
551
|
+
"model_discovery",
|
|
552
|
+
target.modelCatalogFailure ?? "model_catalog_unverified"
|
|
553
|
+
)
|
|
554
|
+
else if (target.status !== "ready")
|
|
555
|
+
await recordFailure(tool, "target_status", target.status)
|
|
556
|
+
return target
|
|
557
|
+
})
|
|
472
558
|
catalog.set(key, { at: Date.now(), revision, result })
|
|
473
559
|
return result
|
|
474
560
|
}
|
|
@@ -485,6 +571,13 @@ export function createBridge({
|
|
|
485
571
|
.filter((tool) => !args.tool || tool === args.tool)
|
|
486
572
|
.map((tool) => getTarget(tool, folder))
|
|
487
573
|
)
|
|
574
|
+
const loginRequiredTools = targets
|
|
575
|
+
.filter(
|
|
576
|
+
({ tool, status }) =>
|
|
577
|
+
status === "login_required" &&
|
|
578
|
+
(settings.targets.includes(tool) || args.tool === tool)
|
|
579
|
+
)
|
|
580
|
+
.map(({ tool }) => tool)
|
|
488
581
|
const choices = targets.flatMap((item) =>
|
|
489
582
|
item.status !== "ready"
|
|
490
583
|
? []
|
|
@@ -509,11 +602,15 @@ export function createBridge({
|
|
|
509
602
|
return {
|
|
510
603
|
status: choices.length ? "ready" : "no_candidate",
|
|
511
604
|
candidates: choices,
|
|
605
|
+
...(loginRequiredTools.length ? { loginRequiredTools } : {}),
|
|
512
606
|
tools: await Promise.all(
|
|
513
607
|
targets.map(async (item) => ({
|
|
514
608
|
tool: item.tool,
|
|
515
609
|
status: item.status,
|
|
516
610
|
modelCatalog: item.modelCatalog,
|
|
611
|
+
...(item.modelCatalogFailure
|
|
612
|
+
? { modelCatalogFailure: item.modelCatalogFailure }
|
|
613
|
+
: {}),
|
|
517
614
|
remainingQuota:
|
|
518
615
|
item.status === "ready"
|
|
519
616
|
? await cachedQuota(item)
|
|
@@ -556,7 +653,8 @@ export function createBridge({
|
|
|
556
653
|
projectDir,
|
|
557
654
|
coordination,
|
|
558
655
|
prepare,
|
|
559
|
-
snapshot
|
|
656
|
+
snapshot,
|
|
657
|
+
captureEvidence
|
|
560
658
|
) {
|
|
561
659
|
const jobDir = join(projectDir, job.id)
|
|
562
660
|
const record = join(jobDir, "job.json")
|
|
@@ -592,6 +690,8 @@ export function createBridge({
|
|
|
592
690
|
if (prepare && job.dependsOn?.length) {
|
|
593
691
|
const blocked = []
|
|
594
692
|
const prerequisites = []
|
|
693
|
+
const dependencyPaths = new Set()
|
|
694
|
+
const requestedScopes = delegateScopes(job)
|
|
595
695
|
for (const id of job.dependsOn) {
|
|
596
696
|
const dependency = await readJson(
|
|
597
697
|
join(projectDir, id, "job.json"),
|
|
@@ -604,11 +704,25 @@ export function createBridge({
|
|
|
604
704
|
) {
|
|
605
705
|
blocked.push({ id, status: state })
|
|
606
706
|
} else {
|
|
607
|
-
const
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
707
|
+
const changedPaths = (dependency.changes ?? []).map(
|
|
708
|
+
({ path }) => path
|
|
709
|
+
)
|
|
710
|
+
const visiblePaths = changedPaths.filter(
|
|
711
|
+
(path) =>
|
|
712
|
+
delegateWorkspacePath(path) &&
|
|
713
|
+
(!requestedScopes.length || withinPaths(path, requestedScopes))
|
|
714
|
+
)
|
|
715
|
+
for (const path of visiblePaths) dependencyPaths.add(path)
|
|
716
|
+
const paths = visiblePaths.join(", ").slice(0, 1200)
|
|
717
|
+
const earlierScopes = delegateScopes(dependency)
|
|
718
|
+
const includeSummary =
|
|
719
|
+
!requestedScopes.length ||
|
|
720
|
+
(earlierScopes.length > 0 &&
|
|
721
|
+
earlierScopes.every((path) =>
|
|
722
|
+
withinPaths(path, requestedScopes)
|
|
723
|
+
))
|
|
611
724
|
const patch =
|
|
725
|
+
visiblePaths.length === changedPaths.length &&
|
|
612
726
|
dependency.patchBytes && dependency.patchBytes <= 3500
|
|
613
727
|
? await readFile(
|
|
614
728
|
join(projectDir, id, "changes.patch"),
|
|
@@ -617,8 +731,10 @@ export function createBridge({
|
|
|
617
731
|
: ""
|
|
618
732
|
prerequisites.push(
|
|
619
733
|
[
|
|
620
|
-
dependency.task.slice(0, 600),
|
|
621
|
-
|
|
734
|
+
includeSummary ? dependency.task.slice(0, 600) : "",
|
|
735
|
+
includeSummary
|
|
736
|
+
? (dependency.summary || "").slice(0, 1200)
|
|
737
|
+
: "",
|
|
622
738
|
paths ? "Changed paths: " + paths : "",
|
|
623
739
|
patch,
|
|
624
740
|
]
|
|
@@ -629,7 +745,8 @@ export function createBridge({
|
|
|
629
745
|
}
|
|
630
746
|
if (blocked.length)
|
|
631
747
|
return { status: "waiting_for_dependencies", dependencies: blocked }
|
|
632
|
-
job.prerequisites = prerequisites
|
|
748
|
+
job.prerequisites = prerequisites.filter(Boolean)
|
|
749
|
+
job.dependencyPaths = [...dependencyPaths]
|
|
633
750
|
}
|
|
634
751
|
const current = await leases(coordination)
|
|
635
752
|
if (
|
|
@@ -676,6 +793,7 @@ export function createBridge({
|
|
|
676
793
|
startedAt: lease.startedAt,
|
|
677
794
|
finishedAt: undefined,
|
|
678
795
|
lastRunTokens: undefined,
|
|
796
|
+
lastRunErrorCode: undefined,
|
|
679
797
|
remainingQuota: undefined,
|
|
680
798
|
})
|
|
681
799
|
await writeJson(join(coordination, "active.json"), [...current, lease])
|
|
@@ -704,16 +822,23 @@ export function createBridge({
|
|
|
704
822
|
if (prepare) {
|
|
705
823
|
await cancelled()
|
|
706
824
|
if (abort.signal.aborted) throw abort.signal.reason
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
await
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
writeJson(baselineFile,
|
|
715
|
-
|
|
716
|
-
|
|
825
|
+
const scopes = delegateScopes(job)
|
|
826
|
+
if (!snapshot && reviewOnly(job.kind) && scopes.length)
|
|
827
|
+
job.reviewDiff = await bridgeReviewDiff(folder, scopes)
|
|
828
|
+
await projectSnapshot(
|
|
829
|
+
snapshot?.work ?? folder,
|
|
830
|
+
work,
|
|
831
|
+
(baseline) =>
|
|
832
|
+
writeJson(baselineFile, {
|
|
833
|
+
...baseline,
|
|
834
|
+
...(snapshot ? { sourceHead: snapshot.baseline.head } : {}),
|
|
835
|
+
}),
|
|
836
|
+
{
|
|
837
|
+
scopes,
|
|
838
|
+
trackSource:
|
|
839
|
+
!snapshot && reviewOnly(job.kind) && Boolean(job.dependsOn?.length),
|
|
840
|
+
}
|
|
841
|
+
)
|
|
717
842
|
await updateLease(coordination, attempt, (entries, key) =>
|
|
718
843
|
entries.map((item) =>
|
|
719
844
|
item.attempt === key ? { ...item, preparing: false } : item
|
|
@@ -722,14 +847,28 @@ export function createBridge({
|
|
|
722
847
|
}
|
|
723
848
|
job.phase = "executing"
|
|
724
849
|
await writeJson(record, job)
|
|
725
|
-
const
|
|
850
|
+
const baseline = await readJson(baselineFile, null)
|
|
851
|
+
const invalidWorkspace =
|
|
852
|
+
baseline?.scoped &&
|
|
853
|
+
!prepare &&
|
|
854
|
+
!(await checkDelegateWorkspace(
|
|
855
|
+
work,
|
|
856
|
+
baseline.scopes ?? delegateScopes(job)
|
|
857
|
+
))
|
|
858
|
+
const target = invalidWorkspace ? {} : await getTarget(job.tool, folder)
|
|
859
|
+
const beforeAttempt = !prepare && !invalidWorkspace && !reviewOnly(job.kind)
|
|
860
|
+
? await projectFileVersions(work, job.paths.length ? job.paths : undefined)
|
|
861
|
+
: null
|
|
726
862
|
await cancelled()
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
863
|
+
let result
|
|
864
|
+
if (abort.signal.aborted) result = { failure: "cancelled" }
|
|
865
|
+
else if (invalidWorkspace) result = { failure: "workspace_invalid" }
|
|
866
|
+
else
|
|
867
|
+
result = await execute({
|
|
730
868
|
tool: job.tool,
|
|
731
869
|
model: job.model,
|
|
732
870
|
readOnly: reviewOnly(job.kind),
|
|
871
|
+
managedWorkspace: baseline?.scoped === true,
|
|
733
872
|
cwd: work,
|
|
734
873
|
prompt: taskPrompt(job),
|
|
735
874
|
signal: abort.signal,
|
|
@@ -745,9 +884,10 @@ export function createBridge({
|
|
|
745
884
|
job.status = abort.signal.aborted
|
|
746
885
|
? "cancelled"
|
|
747
886
|
: (result.failure ?? (question ? "needs_context" : "completed"))
|
|
748
|
-
if (job.
|
|
749
|
-
job.findings = reviewFindings(job.summary)
|
|
750
|
-
if (!job.findings
|
|
887
|
+
if (job.kind === "review" && job.status === "completed") {
|
|
888
|
+
job.findings = reviewFindings(job.summary) ?? undefined
|
|
889
|
+
if (!job.findings && job.structuredReview)
|
|
890
|
+
job.status = "invalid_review"
|
|
751
891
|
}
|
|
752
892
|
job.actualModel = result.actualModel
|
|
753
893
|
if (
|
|
@@ -758,18 +898,31 @@ export function createBridge({
|
|
|
758
898
|
)
|
|
759
899
|
job.status = "model_family_conflict"
|
|
760
900
|
job.lastRunTokens = result.tokens
|
|
901
|
+
job.lastRunErrorCode = result.failureCode
|
|
761
902
|
job.remainingQuota = { status: "unknown" }
|
|
762
903
|
job.rateLimitResetAt = result.rateLimitResetAt
|
|
763
|
-
|
|
764
|
-
|
|
904
|
+
if (invalidWorkspace) {
|
|
905
|
+
job.patchBytes = 0
|
|
906
|
+
job.changes = []
|
|
907
|
+
job.summary =
|
|
908
|
+
"Restart the Bridge task to prepare a clean, scoped workspace."
|
|
909
|
+
} else if (baseline) {
|
|
765
910
|
const changes = await inspectBridgeChanges(work, baseline, job.paths)
|
|
911
|
+
const restrictedPaths = baseline.scoped
|
|
912
|
+
? changes.changes
|
|
913
|
+
.map(({ path }) => path)
|
|
914
|
+
.filter((path) => !delegateWorkspacePath(path))
|
|
915
|
+
: []
|
|
916
|
+
const violations = [
|
|
917
|
+
...new Set([...changes.violations, ...restrictedPaths]),
|
|
918
|
+
]
|
|
766
919
|
if (
|
|
767
|
-
|
|
920
|
+
violations.length ||
|
|
768
921
|
(reviewOnly(job.kind) && changes.changes.length)
|
|
769
922
|
) {
|
|
770
923
|
job.status = "out_of_scope"
|
|
771
|
-
job.violations =
|
|
772
|
-
?
|
|
924
|
+
job.violations = violations.length
|
|
925
|
+
? violations
|
|
773
926
|
: changes.changes.map((change) => change.path)
|
|
774
927
|
job.patchBytes = 0
|
|
775
928
|
job.changes = []
|
|
@@ -778,6 +931,7 @@ export function createBridge({
|
|
|
778
931
|
mode: 0o600,
|
|
779
932
|
})
|
|
780
933
|
job.patchBytes = Buffer.byteLength(changes.patch)
|
|
934
|
+
job.changeContributors = bridgeChangeContributors(job, changes.changes, beforeAttempt)
|
|
781
935
|
job.changes = changes.changes
|
|
782
936
|
if (job.status === "completed" && !changes.patch)
|
|
783
937
|
job.status = "no_changes"
|
|
@@ -832,6 +986,20 @@ export function createBridge({
|
|
|
832
986
|
job.summary = error.message
|
|
833
987
|
} finally {
|
|
834
988
|
clearInterval(watcher)
|
|
989
|
+
if (
|
|
990
|
+
!["cancelled", "completed", "needs_context", "no_changes"].includes(
|
|
991
|
+
job.status === "failed"
|
|
992
|
+
? job.lastRunErrorCode ?? job.status
|
|
993
|
+
: job.status
|
|
994
|
+
)
|
|
995
|
+
)
|
|
996
|
+
await recordFailure(
|
|
997
|
+
job.tool,
|
|
998
|
+
job.phase === "executing"
|
|
999
|
+
? "task_execution"
|
|
1000
|
+
: "workspace_preparation",
|
|
1001
|
+
job.status
|
|
1002
|
+
)
|
|
835
1003
|
job.phase = undefined
|
|
836
1004
|
job.finishedAt = Date.now()
|
|
837
1005
|
await withWorkspaceLock(coordination, async () => {
|
|
@@ -847,13 +1015,17 @@ export function createBridge({
|
|
|
847
1015
|
entries.filter((item) => item.attempt !== attempt)
|
|
848
1016
|
)
|
|
849
1017
|
})
|
|
1018
|
+
if (captureEvidence) await captureEvidence({
|
|
1019
|
+
id: job.id, phase: job.kind, status: job.status, at: job.finishedAt,
|
|
1020
|
+
attempt, job,
|
|
1021
|
+
})
|
|
850
1022
|
}
|
|
851
1023
|
})()
|
|
852
1024
|
task.catch(() => {})
|
|
853
1025
|
return { id: job.id, status: "running", tool: job.tool, model: job.model }
|
|
854
1026
|
}
|
|
855
1027
|
|
|
856
|
-
async function integrate(folder, projectDir, coordination, ids, apply) {
|
|
1028
|
+
async function integrate(folder, projectDir, coordination, ids, apply, captureEvidence) {
|
|
857
1029
|
if (!safeIds(ids) || (apply !== undefined && typeof apply !== "boolean"))
|
|
858
1030
|
throw new Error("Select one to four completed Bridge task IDs.")
|
|
859
1031
|
return withWorkspaceLock(coordination, async () => {
|
|
@@ -910,7 +1082,17 @@ export function createBridge({
|
|
|
910
1082
|
if (overlaps.length)
|
|
911
1083
|
return { status: "patch_overlap", paths: [...new Set(overlaps)] }
|
|
912
1084
|
const paths = changes.map((change) => change.path)
|
|
1085
|
+
const captureApplied = async (at) => {
|
|
1086
|
+
if (!captureEvidence) return
|
|
1087
|
+
for (const { job, directory } of records)
|
|
1088
|
+
await captureEvidence({
|
|
1089
|
+
id: job.id, phase: "apply", status: "applied", at, job,
|
|
1090
|
+
patch: await readFile(join(directory, "changes.patch"), "utf8").catch(() => ""),
|
|
1091
|
+
changes: job.changes ?? [], jobs: [job],
|
|
1092
|
+
})
|
|
1093
|
+
}
|
|
913
1094
|
if (receipt?.status === "applied") {
|
|
1095
|
+
if (apply) await captureApplied(receipt.appliedAt)
|
|
914
1096
|
const conflicts = await mismatchedBridgePaths(folder, changes)
|
|
915
1097
|
return conflicts.length
|
|
916
1098
|
? { status: "working_copy_changed", paths: conflicts }
|
|
@@ -925,6 +1107,7 @@ export function createBridge({
|
|
|
925
1107
|
appliedAt,
|
|
926
1108
|
})
|
|
927
1109
|
await writeJson(receiptPath, { status: "applied", paths, appliedAt })
|
|
1110
|
+
await captureApplied(appliedAt)
|
|
928
1111
|
return {
|
|
929
1112
|
status: "applied",
|
|
930
1113
|
ids,
|
|
@@ -1058,6 +1241,8 @@ export function createBridge({
|
|
|
1058
1241
|
rm(stageDir, { recursive: true, force: true }),
|
|
1059
1242
|
launch: async (task, currentSettings, snapshot) => {
|
|
1060
1243
|
const available = await candidates(task, folder, currentSettings)
|
|
1244
|
+
if (available.loginRequiredTools?.includes(task.tool))
|
|
1245
|
+
return { status: "login_required" }
|
|
1061
1246
|
if (
|
|
1062
1247
|
!available.candidates.some(
|
|
1063
1248
|
({ tool, model }) => tool === task.tool && model === task.model
|
|
@@ -1079,7 +1264,8 @@ export function createBridge({
|
|
|
1079
1264
|
projectDir,
|
|
1080
1265
|
coordination,
|
|
1081
1266
|
true,
|
|
1082
|
-
snapshot && (await snapshot())
|
|
1267
|
+
snapshot && (await snapshot()),
|
|
1268
|
+
settings.captureEvidence
|
|
1083
1269
|
)
|
|
1084
1270
|
},
|
|
1085
1271
|
readRepairPatch: (id) =>
|
|
@@ -1100,9 +1286,18 @@ export function createBridge({
|
|
|
1100
1286
|
},
|
|
1101
1287
|
})
|
|
1102
1288
|
if (name === "acent_bridge_integrate")
|
|
1103
|
-
return integrate(folder, projectDir, coordination, args.ids, args.apply)
|
|
1104
|
-
if (name === "acent_bridge_finalize")
|
|
1105
|
-
|
|
1289
|
+
return integrate(folder, projectDir, coordination, args.ids, args.apply, settings.captureEvidence)
|
|
1290
|
+
if (name === "acent_bridge_finalize") {
|
|
1291
|
+
const result = await finalize(folder, projectDir, coordination, args)
|
|
1292
|
+
if (settings.captureEvidence && result.checkedAt)
|
|
1293
|
+
await settings.captureEvidence({
|
|
1294
|
+
id: args.reviewId, phase: "verify", status: result.status, at: result.checkedAt,
|
|
1295
|
+
attempt: result.checkedAt,
|
|
1296
|
+
result: { review: result.reviewResult, checks: result.checks?.map(({ name, outcome }) => ({ name, outcome })),
|
|
1297
|
+
checksNotRun: result.checksNotRun?.length },
|
|
1298
|
+
})
|
|
1299
|
+
return result
|
|
1300
|
+
}
|
|
1106
1301
|
if (name === "acent_bridge_activity") {
|
|
1107
1302
|
const entries = await readdir(projectDir).catch((error) => {
|
|
1108
1303
|
if (error.code === "ENOENT") return []
|
|
@@ -1144,11 +1339,15 @@ export function createBridge({
|
|
|
1144
1339
|
)
|
|
1145
1340
|
}
|
|
1146
1341
|
const paths = args.paths ?? []
|
|
1342
|
+
const readPaths = args.readPaths ?? []
|
|
1147
1343
|
const dependsOn = args.dependsOn ?? []
|
|
1148
1344
|
if (
|
|
1149
1345
|
!Array.isArray(paths) ||
|
|
1150
1346
|
paths.length > 64 ||
|
|
1151
|
-
!paths.every(
|
|
1347
|
+
!paths.every(delegateWorkspacePath) ||
|
|
1348
|
+
!Array.isArray(readPaths) ||
|
|
1349
|
+
readPaths.length > 64 ||
|
|
1350
|
+
!readPaths.every(delegateWorkspacePath)
|
|
1152
1351
|
)
|
|
1153
1352
|
throw new Error(
|
|
1154
1353
|
"Use relative project file or directory paths for the Bridge scope."
|
|
@@ -1181,6 +1380,7 @@ export function createBridge({
|
|
|
1181
1380
|
acceptance: args.acceptance,
|
|
1182
1381
|
context: args.context,
|
|
1183
1382
|
paths: [...new Set(paths)].sort(),
|
|
1383
|
+
...(readPaths.length ? { readPaths: [...new Set(readPaths)].sort() } : {}),
|
|
1184
1384
|
dependsOn,
|
|
1185
1385
|
automatic: args.automatic === true,
|
|
1186
1386
|
history: [],
|
|
@@ -1214,9 +1414,9 @@ export function createBridge({
|
|
|
1214
1414
|
return available.status === "ready"
|
|
1215
1415
|
? { ...available, status: "selection_unavailable" }
|
|
1216
1416
|
: available
|
|
1217
|
-
if (
|
|
1417
|
+
if (!reviewOnly(job.kind) && !paths.length)
|
|
1218
1418
|
return { status: "write_scope_required" }
|
|
1219
|
-
return start(job, folder, projectDir, coordination, true)
|
|
1419
|
+
return start(job, folder, projectDir, coordination, true, undefined, settings.captureEvidence)
|
|
1220
1420
|
}
|
|
1221
1421
|
|
|
1222
1422
|
if (typeof args.id !== "string" || !taskId.test(args.id))
|
|
@@ -1251,6 +1451,7 @@ export function createBridge({
|
|
|
1251
1451
|
question,
|
|
1252
1452
|
patchBytes,
|
|
1253
1453
|
lastRunTokens,
|
|
1454
|
+
lastRunErrorCode,
|
|
1254
1455
|
remainingQuota,
|
|
1255
1456
|
rateLimitResetAt,
|
|
1256
1457
|
violations,
|
|
@@ -1269,6 +1470,7 @@ export function createBridge({
|
|
|
1269
1470
|
status,
|
|
1270
1471
|
summary,
|
|
1271
1472
|
findings,
|
|
1473
|
+
...(job.kind === "review" ? { reviewResult: bridgeReviewResult(job) } : {}),
|
|
1272
1474
|
question,
|
|
1273
1475
|
patch,
|
|
1274
1476
|
patchPath,
|
|
@@ -1276,6 +1478,7 @@ export function createBridge({
|
|
|
1276
1478
|
violations,
|
|
1277
1479
|
changedPaths: changes?.map((change) => change.path),
|
|
1278
1480
|
lastRunTokens,
|
|
1481
|
+
...(lastRunErrorCode ? { errorCode: lastRunErrorCode } : {}),
|
|
1279
1482
|
rateLimitResetAt,
|
|
1280
1483
|
remainingQuota: remainingQuota ?? { status: "unknown" },
|
|
1281
1484
|
}
|
|
@@ -1324,7 +1527,9 @@ export function createBridge({
|
|
|
1324
1527
|
folder,
|
|
1325
1528
|
projectDir,
|
|
1326
1529
|
coordination,
|
|
1327
|
-
false
|
|
1530
|
+
false,
|
|
1531
|
+
undefined,
|
|
1532
|
+
settings.captureEvidence
|
|
1328
1533
|
)
|
|
1329
1534
|
}
|
|
1330
1535
|
}
|
|
@@ -9,7 +9,7 @@ async function save(path, value) {
|
|
|
9
9
|
await writeFile(temp, JSON.stringify(value), { mode: 0o600 })
|
|
10
10
|
await rename(temp, path)
|
|
11
11
|
}
|
|
12
|
-
export function redactActivity(value) {
|
|
12
|
+
export function redactActivity(value, limit = 16000) {
|
|
13
13
|
const secret = /authorization|cookie|password|passwd|secret|token|api[-_]?key|private[-_]?key/i
|
|
14
14
|
let clipped = false
|
|
15
15
|
function visit(v, depth = 0) {
|
|
@@ -29,7 +29,7 @@ export function redactActivity(value) {
|
|
|
29
29
|
if (typeof value === "string") { try { value = JSON.parse(value) } catch {} }
|
|
30
30
|
const clean = visit(value)
|
|
31
31
|
const text = typeof clean === "string" ? clean : JSON.stringify(clean, null, 2)
|
|
32
|
-
return { text: text.slice(0,
|
|
32
|
+
return { text: text.slice(0, limit), truncated: clipped || text.length > limit || JSON.stringify(value).length > limit }
|
|
33
33
|
}
|
|
34
34
|
export async function captureActivity(p, config, directory, includeContent = true) {
|
|
35
35
|
const event = p.acent_hook || p.hook_event_name
|
|
@@ -73,6 +73,8 @@ export async function captureActivity(p, config, directory, includeContent = tru
|
|
|
73
73
|
}
|
|
74
74
|
return true
|
|
75
75
|
}
|
|
76
|
+
// Bridge publishes applied edits and structured outcomes through its own capture.
|
|
77
|
+
const bridge = /(?:^|__)acent_bridge_/.test(name)
|
|
76
78
|
const raw = p.tool_response ?? p.tool_output ?? p.toolResult ?? p.error_message ?? p.error
|
|
77
79
|
let output = raw
|
|
78
80
|
if (typeof output === "string") { try { output = JSON.parse(output) } catch {} }
|
|
@@ -86,7 +88,7 @@ export async function captureActivity(p, config, directory, includeContent = tru
|
|
|
86
88
|
startedAt: state?.at ?? null, durationMs: duration == null ? null : Math.min(Math.round(duration), 604800000),
|
|
87
89
|
request: includeContent ? (state ? state.request : hostTurn || p.acent_request ? request : null) : null,
|
|
88
90
|
input: includeContent && input.text === null && state ? state.input : input,
|
|
89
|
-
output: redactActivity(includeContent ? raw : null),
|
|
91
|
+
output: redactActivity(includeContent && !bridge ? raw : null),
|
|
90
92
|
changeIds: (p.acent_code_changes ?? []).map(change => change.id).slice(0, 32),
|
|
91
93
|
}
|
|
92
94
|
await save(path, { completed: record })
|
|
@@ -8,6 +8,7 @@ import { connectionContext, createRootsChannel, projectFolder } from "./connecti
|
|
|
8
8
|
import { memoryInstructions } from "./memory-instructions.mjs"
|
|
9
9
|
import { attachmentTool, saveAttachments } from "./capture-attachments.mjs"
|
|
10
10
|
import { bridgeInstructions, bridgeTools, createBridge } from "./bridge.mjs"
|
|
11
|
+
import { bridgeCaptureEvents } from "./bridge-capture.mjs"
|
|
11
12
|
import { createInterface } from "node:readline"
|
|
12
13
|
import { mkdir } from "node:fs/promises"
|
|
13
14
|
import { dirname } from "node:path"
|
|
@@ -19,6 +20,8 @@ import {
|
|
|
19
20
|
accessToken,
|
|
20
21
|
request,
|
|
21
22
|
connect,
|
|
23
|
+
drain,
|
|
24
|
+
queueManagedCapture,
|
|
22
25
|
} from "./acent-connect.mjs"
|
|
23
26
|
const launchArgs = process.argv.slice(2)
|
|
24
27
|
// Hosts can leave workspaceFolder unsubstituted in a projectless window.
|
|
@@ -218,9 +221,22 @@ async function handleLine(line) {
|
|
|
218
221
|
])
|
|
219
222
|
try {
|
|
220
223
|
const access = await accessToken(projectConfig, configDirectory(projectConfig))
|
|
221
|
-
|
|
224
|
+
const settings = await request(projectConfig, "/api/external/bridge", {
|
|
222
225
|
headers: { Authorization: `Bearer ${access}` },
|
|
223
226
|
})
|
|
227
|
+
if (settings.capture?.code || settings.capture?.activity) {
|
|
228
|
+
const directory = configDirectory(projectConfig)
|
|
229
|
+
settings.captureEvidence = async (evidence) => {
|
|
230
|
+
try {
|
|
231
|
+
await queueManagedCapture(projectConfig, directory, settings.capture,
|
|
232
|
+
bridgeCaptureEvents(evidence, settings.capture), evidence.at)
|
|
233
|
+
void drain(projectConfig, directory).catch(() => {})
|
|
234
|
+
} catch {
|
|
235
|
+
console.error("Acent could not queue Bridge history.")
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
return settings
|
|
224
240
|
} catch (error) {
|
|
225
241
|
if (needsConnection(error))
|
|
226
242
|
throw new Error("Connect this project folder to Acent before using Bridge.")
|