@loucompanion/forge-bridge 0.1.4-dev.f22f5e3d01fe → 0.2.1-dev.0f07274d438b
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 +128 -4
- package/dist/bridge/bridge-chat-giphy-look.d.ts +48 -0
- package/dist/bridge/bridge-chat-giphy-look.js +55 -0
- package/dist/bridge/bridge-chat-provider-command.d.ts +27 -3
- package/dist/bridge/bridge-chat-provider-command.js +131 -26
- package/dist/bridge/bridge-chat.types.d.ts +20 -0
- package/dist/bridge/bridge-chat.types.js +28 -1
- package/dist/bridge/bridge-state-file.d.ts +161 -0
- package/dist/bridge/bridge-state-file.js +376 -0
- package/dist/bridge/bridge-state-io.d.ts +15 -0
- package/dist/bridge/bridge-state-io.js +68 -0
- package/dist/bridge/bridge-state-lock.d.ts +11 -0
- package/dist/bridge/bridge-state-lock.js +102 -0
- package/dist/bridge/bridge-state-unpublished.d.ts +17 -0
- package/dist/bridge/bridge-state-unpublished.js +111 -0
- package/dist/bridge/bridge.service.d.ts +29 -12
- package/dist/bridge/bridge.service.js +215 -380
- package/dist/bridge/bridge.types.d.ts +21 -0
- package/dist/bridge/bridge.types.js +2 -1
- package/dist/bridge/default-session-service.d.ts +13 -0
- package/dist/bridge/default-session-service.js +22 -0
- package/dist/bridge/dispatch-offer-policy.d.ts +22 -0
- package/dist/bridge/dispatch-offer-policy.js +58 -0
- package/dist/bridge/in-flight-registry.d.ts +62 -0
- package/dist/bridge/in-flight-registry.js +207 -0
- package/dist/bridge/readiness-result-outbox.d.ts +5 -1
- package/dist/bridge/readiness-result-outbox.js +20 -0
- package/dist/bridge/runner-host-capabilities.js +14 -1
- package/dist/bridge/sandbox-resource-accounting.d.ts +16 -0
- package/dist/bridge/sandbox-resource-accounting.js +150 -0
- package/dist/bridge/windows-bash-resolution.d.ts +31 -0
- package/dist/bridge/windows-bash-resolution.js +153 -0
- package/dist/cleanup/cleanup-wip.d.ts +12 -0
- package/dist/cleanup/cleanup-wip.js +66 -0
- package/dist/cleanup/cleanup.service.d.ts +11 -1
- package/dist/cleanup/cleanup.service.js +80 -62
- package/dist/cleanup/cleanup.types.d.ts +2 -0
- package/dist/cleanup/forge-owned-paths.d.ts +2 -0
- package/dist/cleanup/forge-owned-paths.js +9 -0
- package/dist/cleanup/host-runtime-ledger.d.ts +2 -0
- package/dist/cleanup/host-runtime-ledger.js +30 -9
- package/dist/cli/cli.help.js +57 -13
- package/dist/cli/cli.service.d.ts +3 -10
- package/dist/cli/cli.service.js +20 -213
- package/dist/cli/idle-status.d.ts +84 -0
- package/dist/cli/idle-status.js +181 -0
- package/dist/cli/local-config.d.ts +14 -1
- package/dist/cli/local-config.js +42 -2
- package/dist/cli/provider-cli-advertising.d.ts +24 -0
- package/dist/cli/provider-cli-advertising.js +88 -0
- package/dist/cli/provider-cli-detection.d.ts +10 -0
- package/dist/cli/provider-cli-detection.js +160 -0
- package/dist/runtime/aspnet-runtime-prebuild.d.ts +20 -0
- package/dist/runtime/aspnet-runtime-prebuild.js +104 -26
- package/dist/runtime/attempt-database-broker.d.ts +1 -1
- package/dist/runtime/attempt-node-runtime-launcher.d.ts +36 -0
- package/dist/runtime/attempt-node-runtime-launcher.js +169 -0
- package/dist/runtime/attempt-process-supervisor.d.ts +2 -0
- package/dist/runtime/attempt-process-supervisor.js +12 -6
- package/dist/runtime/docker-engine-probe.d.ts +5 -0
- package/dist/runtime/docker-engine-probe.js +7 -0
- package/dist/runtime/dotnet-build-outputs.d.ts +107 -0
- package/dist/runtime/dotnet-build-outputs.js +402 -0
- package/dist/runtime/ephemeral-test-postgres-grant.d.ts +37 -0
- package/dist/runtime/ephemeral-test-postgres-grant.js +85 -0
- package/dist/runtime/ephemeral-test-postgres.d.ts +57 -0
- package/dist/runtime/ephemeral-test-postgres.js +303 -0
- package/dist/runtime/host-listener-inspector.d.ts +26 -0
- package/dist/runtime/host-listener-inspector.js +84 -3
- package/dist/runtime/host-load-admission.d.ts +5 -0
- package/dist/runtime/host-load-capacity.d.ts +198 -0
- package/dist/runtime/host-load-capacity.js +353 -0
- package/dist/runtime/host-load-child-environment.d.ts +13 -0
- package/dist/runtime/host-load-child-environment.js +35 -1
- package/dist/runtime/host-load-governor-config.d.ts +33 -3
- package/dist/runtime/host-load-governor-config.js +24 -3
- package/dist/runtime/host-load-governor.d.ts +91 -2
- package/dist/runtime/host-load-governor.js +217 -18
- package/dist/runtime/host-load-ledger-lock.js +6 -4
- package/dist/runtime/host-load-live-test-slots.d.ts +61 -0
- package/dist/runtime/host-load-live-test-slots.js +193 -0
- package/dist/runtime/host-load-runtime-settings.js +4 -2
- package/dist/runtime/host-load-sampler.d.ts +25 -1
- package/dist/runtime/host-load-sampler.js +38 -7
- package/dist/runtime/host-load-step-run.d.ts +37 -3
- package/dist/runtime/host-load-step-run.js +63 -7
- package/dist/runtime/host-load-test-slot.d.ts +3 -0
- package/dist/runtime/host-load-test-slot.js +26 -7
- package/dist/runtime/host-runtime-contract.d.ts +12 -0
- package/dist/runtime/host-runtime-contract.js +35 -5
- package/dist/runtime/host-runtime-lease.d.ts +28 -3
- package/dist/runtime/host-runtime-lease.js +140 -296
- package/dist/runtime/host-runtime-ledger-recovery.d.ts +20 -0
- package/dist/runtime/host-runtime-ledger-recovery.js +134 -0
- package/dist/runtime/host-runtime-promotion.d.ts +78 -2
- package/dist/runtime/host-runtime-promotion.js +307 -14
- package/dist/runtime/managed-command-teardown.js +5 -16
- package/dist/runtime/native-test-postgres-fallback.d.ts +51 -7
- package/dist/runtime/native-test-postgres-fallback.js +60 -8
- package/dist/runtime/prepared-runtime-identity.d.ts +4 -0
- package/dist/runtime/prepared-runtime-identity.js +130 -9
- package/dist/runtime/prepared-runtime-readiness.d.ts +23 -1
- package/dist/runtime/prepared-runtime-readiness.js +89 -18
- package/dist/runtime/runner-settings.d.ts +4 -0
- package/dist/runtime/runner-settings.js +22 -0
- package/dist/runtime/supervised-runtime-build-guard.d.ts +45 -0
- package/dist/runtime/supervised-runtime-build-guard.js +112 -0
- package/dist/sandbox/host-capacity-broker.d.ts +3 -1
- package/dist/sandbox/host-capacity-broker.js +4 -2
- package/dist/sandbox/managed-branch.d.ts +13 -0
- package/dist/sandbox/managed-branch.js +90 -0
- package/dist/sandbox/provider-auth/codex.js +11 -11
- package/dist/sandbox/runtime.d.ts +1 -2
- package/dist/sandbox/runtime.js +9 -19
- package/dist/sandbox/sandbox-input.d.ts +22 -0
- package/dist/sandbox/sandbox-input.js +49 -0
- package/dist/sandbox/workspace.service.js +15 -2
- package/dist/session/managed-attempt-tools.d.ts +0 -7
- package/dist/session/managed-attempt-tools.js +54 -109
- package/dist/session/managed-build-coordinator.d.ts +16 -0
- package/dist/session/managed-build-coordinator.js +10 -0
- package/dist/session/managed-build-receipt.d.ts +7 -0
- package/dist/session/managed-build-receipt.js +11 -3
- package/dist/session/managed-command-environment.d.ts +8 -0
- package/dist/session/managed-command-environment.js +28 -0
- package/dist/session/managed-command-host-load.d.ts +10 -5
- package/dist/session/managed-command-host-load.js +18 -14
- package/dist/session/phase-completion.artifact-bundle.d.ts +20 -0
- package/dist/session/phase-completion.artifact-bundle.js +167 -0
- package/dist/session/phase-completion.artifacts.d.ts +2 -17
- package/dist/session/phase-completion.artifacts.js +65 -166
- package/dist/session/phase-completion.d.ts +27 -2
- package/dist/session/phase-completion.helpers.js +5 -53
- package/dist/session/phase-completion.js +15 -32
- package/dist/session/phase-completion.mcp-args.d.ts +9 -0
- package/dist/session/phase-completion.mcp-args.js +195 -0
- package/dist/session/phase-completion.phase-aliases.d.ts +5 -0
- package/dist/session/phase-completion.phase-aliases.js +43 -0
- package/dist/session/phase-completion.pr-review-schema.d.ts +1 -0
- package/dist/session/phase-completion.pr-review-schema.js +75 -0
- package/dist/session/phase-completion.pr-review-validation.d.ts +11 -0
- package/dist/session/phase-completion.pr-review-validation.js +212 -0
- package/dist/session/phase-completion.pr-review.d.ts +36 -0
- package/dist/session/phase-completion.pr-review.js +294 -0
- package/dist/session/phase-completion.prompts.d.ts +1 -1
- package/dist/session/phase-completion.prompts.js +14 -0
- package/dist/session/phase-completion.runtime.d.ts +8 -9
- package/dist/session/phase-completion.runtime.js +65 -196
- package/dist/session/phase-completion.schemas.js +12 -2
- package/dist/session/phase-completion.validation.d.ts +1 -0
- package/dist/session/phase-completion.validation.js +9 -1
- package/dist/session/pr-review-diff-base.d.ts +18 -0
- package/dist/session/pr-review-diff-base.js +44 -0
- package/dist/session/pr-review-placement.d.ts +50 -0
- package/dist/session/pr-review-placement.js +91 -0
- package/dist/session/pre-publication-change-set.d.ts +62 -0
- package/dist/session/pre-publication-change-set.js +166 -0
- package/dist/session/pre-publication-host-load.js +6 -5
- package/dist/session/pre-publication-native-postgres.d.ts +30 -0
- package/dist/session/pre-publication-native-postgres.js +111 -0
- package/dist/session/pre-publication-process.js +13 -12
- package/dist/session/pre-publication-step-execution.d.ts +2 -1
- package/dist/session/pre-publication-step-execution.js +6 -5
- package/dist/session/pre-publication-validation.d.ts +9 -4
- package/dist/session/pre-publication-validation.js +62 -65
- package/dist/session/provider-cli/claude-background-work.d.ts +3 -2
- package/dist/session/provider-cli/claude-background-work.js +4 -3
- package/dist/session/provider-cli/dispatch-target-branch.d.ts +7 -0
- package/dist/session/provider-cli/dispatch-target-branch.js +8 -0
- package/dist/session/provider-cli/host-build-lock.d.ts +18 -0
- package/dist/session/provider-cli/host-build-lock.js +30 -0
- package/dist/session/provider-cli/pr-review-credential-isolation.d.ts +83 -0
- package/dist/session/provider-cli/pr-review-credential-isolation.js +144 -0
- package/dist/session/provider-cli/pr-review-guardrails.d.ts +70 -0
- package/dist/session/provider-cli/pr-review-guardrails.js +360 -0
- package/dist/session/provider-cli/pr-review-prompt.d.ts +2 -0
- package/dist/session/provider-cli/pr-review-prompt.js +119 -0
- package/dist/session/provider-cli/pre-publication-repair.d.ts +16 -0
- package/dist/session/provider-cli/pre-publication-repair.js +41 -3
- package/dist/session/provider-cli/provider-cli.base.d.ts +1 -0
- package/dist/session/provider-cli/provider-cli.child-environment.js +4 -2
- package/dist/session/provider-cli/provider-cli.deterministic.d.ts +1 -0
- package/dist/session/provider-cli/provider-cli.deterministic.js +5 -0
- package/dist/session/provider-cli/provider-cli.merge-integrity.d.ts +6 -3
- package/dist/session/provider-cli/provider-cli.merge-integrity.js +29 -10
- package/dist/session/provider-cli/provider-cli.pr-review.d.ts +23 -0
- package/dist/session/provider-cli/provider-cli.pr-review.js +213 -0
- package/dist/session/provider-cli/provider-cli.process.d.ts +2 -14
- package/dist/session/provider-cli/provider-cli.process.js +4 -94
- package/dist/session/provider-cli/provider-cli.prompts.d.ts +13 -3
- package/dist/session/provider-cli/provider-cli.prompts.js +137 -84
- package/dist/session/provider-cli/provider-cli.reapply-conflicts.d.ts +10 -0
- package/dist/session/provider-cli/provider-cli.reapply-conflicts.js +37 -0
- package/dist/session/provider-cli/provider-cli.runtime.d.ts +15 -0
- package/dist/session/provider-cli/provider-cli.runtime.js +37 -2
- package/dist/session/provider-cli/provider-cli.service-support.d.ts +37 -0
- package/dist/session/provider-cli/provider-cli.service-support.js +146 -0
- package/dist/session/provider-cli/provider-cli.service.d.ts +15 -18
- package/dist/session/provider-cli/provider-cli.service.js +59 -190
- package/dist/session/provider-cli/provider-cli.types.d.ts +7 -2
- package/dist/session/provider-cli/provider-cli.windows-launch.d.ts +23 -0
- package/dist/session/provider-cli/provider-cli.windows-launch.js +131 -0
- package/dist/session/provider-cli/provider-user-config-isolation.d.ts +69 -0
- package/dist/session/provider-cli/provider-user-config-isolation.js +164 -0
- package/dist/session/qa-sidecar-validation.d.ts +6 -0
- package/dist/session/qa-sidecar-validation.js +28 -0
- package/dist/session/sandbox-host-capacity-gate.d.ts +22 -1
- package/dist/session/sandbox-host-capacity-gate.js +63 -22
- package/dist/session/session-host-project.d.ts +22 -0
- package/dist/session/session-host-project.js +98 -0
- package/dist/session/session-redaction.js +31 -181
- package/dist/session/session.parse-helpers.d.ts +10 -0
- package/dist/session/session.parse-helpers.js +84 -0
- package/dist/session/session.runtime-refresh.d.ts +46 -0
- package/dist/session/session.runtime-refresh.js +116 -0
- package/dist/session/session.service.d.ts +8 -1
- package/dist/session/session.service.js +177 -239
- package/dist/session/session.types.d.ts +5 -0
- package/dist/session/session.types.js +9 -79
- package/dist/session/session.types.pr-review.d.ts +48 -0
- package/dist/session/session.types.pr-review.js +51 -0
- package/dist/session/sidecar-json-shape.d.ts +31 -0
- package/dist/session/sidecar-json-shape.js +217 -0
- package/dist/shared/fs/file-identity.d.ts +10 -0
- package/dist/shared/fs/file-identity.js +15 -0
- package/dist/shared/fs/replace-file.d.ts +7 -0
- package/dist/shared/fs/replace-file.js +33 -0
- package/dist/shared/process/host-process-recovery.d.ts +14 -3
- package/dist/shared/process/host-process-recovery.js +23 -3
- package/dist/shared/process/host-process-supervisor.d.ts +13 -1
- package/dist/shared/process/host-process-supervisor.js +66 -14
- package/dist/shared/provider-capabilities.d.ts +2 -0
- package/dist/shared/provider-capabilities.js +18 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/worktree/artifact-injector.js +24 -0
- package/dist/worktree/orphan-relink.d.ts +19 -0
- package/dist/worktree/orphan-relink.js +106 -0
- package/dist/worktree/wip-git.d.ts +58 -0
- package/dist/worktree/wip-git.js +182 -0
- package/dist/worktree/wip-refs.d.ts +85 -0
- package/dist/worktree/wip-refs.js +169 -0
- package/dist/worktree/wip-restore.d.ts +51 -0
- package/dist/worktree/wip-restore.js +324 -0
- package/dist/worktree/wip-snapshot.d.ts +53 -0
- package/dist/worktree/wip-snapshot.js +270 -0
- package/dist/worktree/worktree-inputs.d.ts +8 -0
- package/dist/worktree/worktree-inputs.js +134 -0
- package/dist/worktree/worktree-origin-sync.d.ts +35 -0
- package/dist/worktree/worktree-origin-sync.js +128 -0
- package/dist/worktree/worktree-wip-events.d.ts +20 -0
- package/dist/worktree/worktree-wip-events.js +148 -0
- package/dist/worktree/worktree-wip.d.ts +57 -0
- package/dist/worktree/worktree-wip.js +200 -0
- package/dist/worktree/worktree.base.d.ts +7 -1
- package/dist/worktree/worktree.service.d.ts +49 -5
- package/dist/worktree/worktree.service.js +223 -187
- package/dist/worktree/worktree.types.d.ts +47 -0
- package/package.json +1 -1
- package/runtime/windows-listener-owner.ps1 +12 -1
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import crypto from "node:crypto";
|
|
2
|
+
import fs from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { isNodeError, stableStringify } from "./phase-completion.validation.js";
|
|
5
|
+
/**
|
|
6
|
+
* Stages a complete phase bundle outside the live artifact directory, then
|
|
7
|
+
* publishes its canonical verdict/marker last. Consumers treat the marker as
|
|
8
|
+
* the bundle's commit point, so they can observe either the old complete bundle
|
|
9
|
+
* or the new complete bundle, never a partially written set. A failed or
|
|
10
|
+
* cancelled publication rolls every touched file back before rejecting.
|
|
11
|
+
*/
|
|
12
|
+
export async function publishArtifactBundleAtomic(artifactRoot, files, commitFileName, options = {}) {
|
|
13
|
+
validateArtifactBundleFiles(files, commitFileName);
|
|
14
|
+
throwIfPublicationCancelled(options.signal);
|
|
15
|
+
const parent = path.dirname(artifactRoot);
|
|
16
|
+
const transactionId = `${process.pid}.${crypto.randomUUID()}`;
|
|
17
|
+
const stagingRoot = path.join(parent, `.${path.basename(artifactRoot)}.${transactionId}.publish`);
|
|
18
|
+
const backupRoot = path.join(stagingRoot, ".previous");
|
|
19
|
+
const orderedFiles = [
|
|
20
|
+
...files.filter((file) => file.fileName !== commitFileName),
|
|
21
|
+
files.find((file) => file.fileName === commitFileName)
|
|
22
|
+
];
|
|
23
|
+
const backedUp = new Set();
|
|
24
|
+
const published = new Set();
|
|
25
|
+
try {
|
|
26
|
+
await fs.mkdir(parent, { recursive: true });
|
|
27
|
+
await fs.mkdir(stagingRoot, { recursive: false });
|
|
28
|
+
for (const file of orderedFiles) {
|
|
29
|
+
throwIfPublicationCancelled(options.signal);
|
|
30
|
+
const handle = await fs.open(path.join(stagingRoot, file.fileName), "wx");
|
|
31
|
+
try {
|
|
32
|
+
await handle.writeFile(file.content, { encoding: "utf8", signal: options.signal });
|
|
33
|
+
await handle.sync();
|
|
34
|
+
}
|
|
35
|
+
finally {
|
|
36
|
+
await handle.close();
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
throwIfPublicationCancelled(options.signal);
|
|
40
|
+
await fs.mkdir(artifactRoot, { recursive: true });
|
|
41
|
+
await fs.mkdir(backupRoot, { recursive: true });
|
|
42
|
+
// Hide the previous commit marker before changing any supporting file.
|
|
43
|
+
for (const fileName of [commitFileName, ...orderedFiles.map((file) => file.fileName).filter((name) => name !== commitFileName)]) {
|
|
44
|
+
const livePath = path.join(artifactRoot, fileName);
|
|
45
|
+
try {
|
|
46
|
+
await fs.rename(livePath, path.join(backupRoot, fileName));
|
|
47
|
+
backedUp.add(fileName);
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
if (!isNodeError(error) || error.code !== "ENOENT") {
|
|
51
|
+
throw error;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
for (const [index, file] of orderedFiles.entries()) {
|
|
56
|
+
throwIfPublicationCancelled(options.signal);
|
|
57
|
+
await options.beforePublishFile?.(file.fileName, index);
|
|
58
|
+
await fs.rename(path.join(stagingRoot, file.fileName), path.join(artifactRoot, file.fileName));
|
|
59
|
+
published.add(file.fileName);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
const rollbackErrors = [];
|
|
64
|
+
for (const file of [...orderedFiles].reverse()) {
|
|
65
|
+
if (!published.has(file.fileName))
|
|
66
|
+
continue;
|
|
67
|
+
await fs.rm(path.join(artifactRoot, file.fileName), { force: true }).catch(() => {
|
|
68
|
+
rollbackErrors.push(file.fileName);
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
// Restore the previous marker last for the same observable commit boundary.
|
|
72
|
+
const restoreOrder = [
|
|
73
|
+
...orderedFiles.filter((file) => file.fileName !== commitFileName),
|
|
74
|
+
orderedFiles.find((file) => file.fileName === commitFileName)
|
|
75
|
+
];
|
|
76
|
+
for (const file of restoreOrder) {
|
|
77
|
+
if (!backedUp.has(file.fileName))
|
|
78
|
+
continue;
|
|
79
|
+
await fs.rename(path.join(backupRoot, file.fileName), path.join(artifactRoot, file.fileName)).catch(() => {
|
|
80
|
+
rollbackErrors.push(file.fileName);
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
if (rollbackErrors.length === 0
|
|
84
|
+
&& error instanceof Error
|
|
85
|
+
&& error.message.startsWith("artifact_atomic_publish_cancelled:")) {
|
|
86
|
+
throw error;
|
|
87
|
+
}
|
|
88
|
+
const suffix = rollbackErrors.length > 0 ? " Rollback did not restore every bundle file." : "";
|
|
89
|
+
throw new Error(`artifact_atomic_publish_failure: completion artifact bundle was not published.${suffix}`, { cause: error });
|
|
90
|
+
}
|
|
91
|
+
finally {
|
|
92
|
+
await fs.rm(stagingRoot, { recursive: true, force: true }).catch(() => undefined);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
function validateArtifactBundleFiles(files, commitFileName) {
|
|
96
|
+
if (files.length === 0 || !files.some((file) => file.fileName === commitFileName)) {
|
|
97
|
+
throw new Error("artifact_atomic_publish_failure: bundle commit file is missing.");
|
|
98
|
+
}
|
|
99
|
+
const names = new Set();
|
|
100
|
+
for (const file of files) {
|
|
101
|
+
if (!file.fileName || path.basename(file.fileName) !== file.fileName || names.has(file.fileName)) {
|
|
102
|
+
throw new Error("artifact_atomic_publish_failure: bundle file names must be unique safe base names.");
|
|
103
|
+
}
|
|
104
|
+
names.add(file.fileName);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
function throwIfPublicationCancelled(signal) {
|
|
108
|
+
if (signal?.aborted) {
|
|
109
|
+
throw new Error("artifact_atomic_publish_cancelled: completion artifact bundle publication was cancelled.");
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
export function validatePostRedaction(validate) {
|
|
113
|
+
try {
|
|
114
|
+
validate();
|
|
115
|
+
}
|
|
116
|
+
catch (error) {
|
|
117
|
+
throw postRedactionValidationError(error);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
export function postRedactionValidationError(error) {
|
|
121
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
122
|
+
return new Error(`artifact_post_redaction_validation_failed: ${message}`, { cause: error });
|
|
123
|
+
}
|
|
124
|
+
export function assertStructuralFieldsUnchanged(original, redacted) {
|
|
125
|
+
if (structuralFieldFingerprint(original) !== structuralFieldFingerprint(redacted)) {
|
|
126
|
+
// This stable code is intentionally safe for telemetry: it does not include
|
|
127
|
+
// the structural value or any candidate secret.
|
|
128
|
+
throw new Error("artifact_redaction_changed_structural_field: redaction changed a structural identifier; the bundle was not published.");
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
function structuralFieldFingerprint(value, key = "", result = []) {
|
|
132
|
+
if (Array.isArray(value)) {
|
|
133
|
+
if (isStructuralFieldKey(key) && value.every((item) => item === null || typeof item !== "object")) {
|
|
134
|
+
result.push(stableStringify(value));
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
for (const item of value)
|
|
138
|
+
structuralFieldFingerprint(item, key, result);
|
|
139
|
+
}
|
|
140
|
+
return result.join("\n");
|
|
141
|
+
}
|
|
142
|
+
if (!value || typeof value !== "object") {
|
|
143
|
+
if (isStructuralFieldKey(key))
|
|
144
|
+
result.push(stableStringify(value));
|
|
145
|
+
return result.join("\n");
|
|
146
|
+
}
|
|
147
|
+
for (const [childKey, child] of Object.entries(value)) {
|
|
148
|
+
if (isStructuralFieldKey(childKey)) {
|
|
149
|
+
result.push(`${childKey}:${stableStringify(child)}`);
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
structuralFieldFingerprint(child, childKey, result);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return result.join("\n");
|
|
156
|
+
}
|
|
157
|
+
function isStructuralFieldKey(key) {
|
|
158
|
+
return key === "id"
|
|
159
|
+
|| key === "before"
|
|
160
|
+
|| key === "after"
|
|
161
|
+
|| key === "from"
|
|
162
|
+
|| key === "to"
|
|
163
|
+
|| key === "tasks"
|
|
164
|
+
|| key === "phases"
|
|
165
|
+
|| /(?:^|_)(?:id|ids)$/i.test(key)
|
|
166
|
+
|| /(?:Id|Ids)$/.test(key);
|
|
167
|
+
}
|
|
@@ -15,20 +15,5 @@ export declare function writeQaGateCompletionArtifact(config: CompletionToolServ
|
|
|
15
15
|
export declare function writeQaCompletionArtifact(config: CompletionToolServerConfig, payload: Record<string, unknown>, status: string, producedBy: string): Promise<CompletionArtifactReference>;
|
|
16
16
|
export declare function readQaGateArtifact(config: CompletionToolServerConfig, gate: QaCompletionGate): Promise<Record<string, unknown>>;
|
|
17
17
|
export declare function readCompletionArtifact(worktreePath: string, workItemId: string, phase: CompletionPhase, ownerType?: string | null, ownerId?: string | null): Promise<RunnerDispatchArtifact | null>;
|
|
18
|
-
export
|
|
19
|
-
|
|
20
|
-
readonly content: string;
|
|
21
|
-
}
|
|
22
|
-
export interface ArtifactBundlePublicationOptions {
|
|
23
|
-
readonly signal?: AbortSignal;
|
|
24
|
-
/** Fault-injection hook used by publication tests. */
|
|
25
|
-
readonly beforePublishFile?: (fileName: string, index: number) => void | Promise<void>;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Stages a complete phase bundle outside the live artifact directory, then
|
|
29
|
-
* publishes its canonical verdict/marker last. Consumers treat the marker as
|
|
30
|
-
* the bundle's commit point, so they can observe either the old complete bundle
|
|
31
|
-
* or the new complete bundle, never a partially written set. A failed or
|
|
32
|
-
* cancelled publication rolls every touched file back before rejecting.
|
|
33
|
-
*/
|
|
34
|
-
export declare function publishArtifactBundleAtomic(artifactRoot: string, files: readonly ArtifactBundleFile[], commitFileName: string, options?: ArtifactBundlePublicationOptions): Promise<void>;
|
|
18
|
+
export { publishArtifactBundleAtomic } from "./phase-completion.artifact-bundle.js";
|
|
19
|
+
export type { ArtifactBundleFile, ArtifactBundlePublicationOptions } from "./phase-completion.artifact-bundle.js";
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import crypto from "node:crypto";
|
|
2
1
|
import fs from "node:fs/promises";
|
|
3
2
|
import path from "node:path";
|
|
4
3
|
import { redactSecrets } from "../shared/redaction/redaction.js";
|
|
5
|
-
import { ensureNoSymbolicLinkPathSegments, isPathUnderRoot, sha256File } from "./qa-sidecar-validation.js";
|
|
4
|
+
import { assertQaSidecarJsonShape, ensureNoSymbolicLinkPathSegments, isPathUnderRoot, sha256File } from "./qa-sidecar-validation.js";
|
|
6
5
|
import { assertClaimedChangedFilesMatchPublishableDiff } from "./publishable-worktree-changes.js";
|
|
7
6
|
import { coerceJsonStringArguments } from "./mcp-argument-coercion.js";
|
|
7
|
+
import { assertStructuralFieldsUnchanged, postRedactionValidationError, publishArtifactBundleAtomic, validatePostRedaction } from "./phase-completion.artifact-bundle.js";
|
|
8
8
|
import { toolInputSchema } from "./phase-completion.schemas.js";
|
|
9
9
|
import { artifactRootFor, artifactRootForOwner, completionArtifactJsonPath, completionArtifactReportPath, decomposeGateFileNames, draftGateFileNames, phaseFiles, qaGateFileNames, decomposeStatuses, draftStatuses } from "./phase-completion.js";
|
|
10
|
-
import {
|
|
10
|
+
import { assertPrReviewMatchesRepository, prReviewReportMarkdown } from "./phase-completion.pr-review.js";
|
|
11
|
+
import { artifactOwnerFields, artifactReferenceOwnerFields, artifactOwnerRelativeRoot, defaultQaChecklist, fallbackReport, isNodeError, jsonText, normalizeArtifactPayload, normalizeCompletionStatus, normalizeQaGateArtifactPayload, normalizeQaGateStatus, normalizedString, optionalString, numberOrDefault, parseJsonObject, parseOptionalJsonObject, phaseFromToolName, qaArray, qaArtifactRelativePath, qaArtifactRelativePathForOwner, qaEvidenceSource, qaObjectArray, qaPolicyWarnings, qaEvidenceGates, qaStringArray, readOptionalFile, reportMarkdown, requireField, requiredRecord, requiredString, qaGateFromToolName, sha256, stableStringify, validateOptionalWorkItemId, validatePayloadShape, validatePrReviewPayloadShape, validateQaGatePayloadShape, validateQaScopeRecord, writeFileAtomic, asRecord } from "./phase-completion.validation.js";
|
|
11
12
|
export async function writeDecomposeGateCompletionArtifact(config, gate, toolName, input) {
|
|
12
13
|
const payload = asRecord(input, "Decompose completion payload");
|
|
13
14
|
const status = validateDecomposeGatePayload(gate, payload);
|
|
@@ -184,6 +185,9 @@ export async function writeCompletionArtifact(config, toolName, input) {
|
|
|
184
185
|
if (qaGate && qaGate !== "qa_verdict") {
|
|
185
186
|
return await writeQaGateCompletionArtifact(config, qaGate, input);
|
|
186
187
|
}
|
|
188
|
+
if (phase === "pr_review") {
|
|
189
|
+
return await writePrReviewCompletionArtifact(config, input);
|
|
190
|
+
}
|
|
187
191
|
const payload = asRecord(input, "completion payload");
|
|
188
192
|
const status = normalizeCompletionStatus(requiredString(payload, "status"), phase);
|
|
189
193
|
let validationPayload = { ...payload, status };
|
|
@@ -244,6 +248,62 @@ export async function writeCompletionArtifact(config, toolName, input) {
|
|
|
244
248
|
producedBy
|
|
245
249
|
};
|
|
246
250
|
}
|
|
251
|
+
/**
|
|
252
|
+
* Writes pr-review.result.json and pr-review.report.md. This gate only records the review:
|
|
253
|
+
* Forge posts it to the pull request afterwards, so a pass ends the lane without any
|
|
254
|
+
* publication step here. `stale_head` and `blocked` are accepted terminal outcomes.
|
|
255
|
+
*/
|
|
256
|
+
async function writePrReviewCompletionArtifact(config, input) {
|
|
257
|
+
const phase = "pr_review";
|
|
258
|
+
const payload = asRecord(input, "completion payload");
|
|
259
|
+
const status = normalizeCompletionStatus(requiredString(payload, "status"), phase);
|
|
260
|
+
const validationPayload = { ...payload, status };
|
|
261
|
+
validatePrReviewPayloadShape(validationPayload, status, config.prReview);
|
|
262
|
+
validateOptionalWorkItemId(validationPayload, config.workItemId);
|
|
263
|
+
if (status === "reviewed") {
|
|
264
|
+
await assertPrReviewMatchesRepository(config.worktreePath, validationPayload, config.prReview);
|
|
265
|
+
}
|
|
266
|
+
const redactedPayload = redactSecrets(validationPayload, config.redactionSecrets ?? []);
|
|
267
|
+
assertStructuralFieldsUnchanged(validationPayload, redactedPayload);
|
|
268
|
+
validatePostRedaction(() => {
|
|
269
|
+
validatePrReviewPayloadShape(redactedPayload, status, config.prReview);
|
|
270
|
+
validateOptionalWorkItemId(redactedPayload, config.workItemId);
|
|
271
|
+
});
|
|
272
|
+
const producedBy = optionalString(redactedPayload, "produced_by")
|
|
273
|
+
?? optionalString(redactedPayload, "producedBy")
|
|
274
|
+
?? config.producedBy
|
|
275
|
+
?? "forge-completion-tool";
|
|
276
|
+
const artifactWithoutHash = normalizeArtifactPayload(redactedPayload, {
|
|
277
|
+
phase,
|
|
278
|
+
workItemId: config.workItemId,
|
|
279
|
+
ownerType: config.ownerType,
|
|
280
|
+
ownerId: config.ownerId,
|
|
281
|
+
producedBy,
|
|
282
|
+
status
|
|
283
|
+
});
|
|
284
|
+
const contentHash = sha256(stableStringify(artifactWithoutHash));
|
|
285
|
+
const artifactJson = `${JSON.stringify({ ...artifactWithoutHash, content_hash: contentHash }, null, 2)}\n`;
|
|
286
|
+
const report = optionalString(redactedPayload, "report_markdown")
|
|
287
|
+
? reportMarkdown(redactedPayload, phase, status, producedBy, contentHash)
|
|
288
|
+
: prReviewReportMarkdown(artifactWithoutHash, contentHash);
|
|
289
|
+
const artifactPath = completionArtifactJsonPath(config.worktreePath, config.workItemId, phase);
|
|
290
|
+
const reportPath = completionArtifactReportPath(config.worktreePath, config.workItemId, phase);
|
|
291
|
+
await publishArtifactBundleAtomic(path.dirname(artifactPath), [
|
|
292
|
+
{ fileName: path.basename(reportPath), content: report },
|
|
293
|
+
{ fileName: path.basename(artifactPath), content: artifactJson }
|
|
294
|
+
], path.basename(artifactPath));
|
|
295
|
+
return {
|
|
296
|
+
phase,
|
|
297
|
+
workItemId: config.workItemId,
|
|
298
|
+
...artifactReferenceOwnerFields(config),
|
|
299
|
+
repoPath: path.resolve(config.worktreePath),
|
|
300
|
+
path: artifactPath,
|
|
301
|
+
reportPath,
|
|
302
|
+
contentHash,
|
|
303
|
+
status,
|
|
304
|
+
producedBy
|
|
305
|
+
};
|
|
306
|
+
}
|
|
247
307
|
export async function writeArchitectCompletionArtifact(config, payload, status, producedBy) {
|
|
248
308
|
const ownerFields = artifactOwnerFields(config);
|
|
249
309
|
const artifactRoot = ownerFields.owner_type && ownerFields.owner_id
|
|
@@ -690,6 +750,7 @@ async function validateQaSidecarReferences(worktreePath, workItemId, sidecars, o
|
|
|
690
750
|
if (actualHash !== normalizeSha256ContentHash(contentHash)) {
|
|
691
751
|
throw new Error(`sidecars[${index}].content_hash does not match the referenced file.`);
|
|
692
752
|
}
|
|
753
|
+
await assertQaSidecarJsonShape(fullPath, sidecarPath, `sidecars[${index}]`);
|
|
693
754
|
const canonicalPath = path.relative(worktreePath, fullPath).split(path.sep).join("/");
|
|
694
755
|
const duplicateKey = canonicalPath.toLowerCase();
|
|
695
756
|
const existing = validatedByPath.get(duplicateKey);
|
|
@@ -737,166 +798,4 @@ export async function readCompletionArtifact(worktreePath, workItemId, phase, ow
|
|
|
737
798
|
phase
|
|
738
799
|
};
|
|
739
800
|
}
|
|
740
|
-
|
|
741
|
-
* Stages a complete phase bundle outside the live artifact directory, then
|
|
742
|
-
* publishes its canonical verdict/marker last. Consumers treat the marker as
|
|
743
|
-
* the bundle's commit point, so they can observe either the old complete bundle
|
|
744
|
-
* or the new complete bundle, never a partially written set. A failed or
|
|
745
|
-
* cancelled publication rolls every touched file back before rejecting.
|
|
746
|
-
*/
|
|
747
|
-
export async function publishArtifactBundleAtomic(artifactRoot, files, commitFileName, options = {}) {
|
|
748
|
-
validateArtifactBundleFiles(files, commitFileName);
|
|
749
|
-
throwIfPublicationCancelled(options.signal);
|
|
750
|
-
const parent = path.dirname(artifactRoot);
|
|
751
|
-
const transactionId = `${process.pid}.${crypto.randomUUID()}`;
|
|
752
|
-
const stagingRoot = path.join(parent, `.${path.basename(artifactRoot)}.${transactionId}.publish`);
|
|
753
|
-
const backupRoot = path.join(stagingRoot, ".previous");
|
|
754
|
-
const orderedFiles = [
|
|
755
|
-
...files.filter((file) => file.fileName !== commitFileName),
|
|
756
|
-
files.find((file) => file.fileName === commitFileName)
|
|
757
|
-
];
|
|
758
|
-
const backedUp = new Set();
|
|
759
|
-
const published = new Set();
|
|
760
|
-
try {
|
|
761
|
-
await fs.mkdir(parent, { recursive: true });
|
|
762
|
-
await fs.mkdir(stagingRoot, { recursive: false });
|
|
763
|
-
for (const file of orderedFiles) {
|
|
764
|
-
throwIfPublicationCancelled(options.signal);
|
|
765
|
-
const handle = await fs.open(path.join(stagingRoot, file.fileName), "wx");
|
|
766
|
-
try {
|
|
767
|
-
await handle.writeFile(file.content, { encoding: "utf8", signal: options.signal });
|
|
768
|
-
await handle.sync();
|
|
769
|
-
}
|
|
770
|
-
finally {
|
|
771
|
-
await handle.close();
|
|
772
|
-
}
|
|
773
|
-
}
|
|
774
|
-
throwIfPublicationCancelled(options.signal);
|
|
775
|
-
await fs.mkdir(artifactRoot, { recursive: true });
|
|
776
|
-
await fs.mkdir(backupRoot, { recursive: true });
|
|
777
|
-
// Hide the previous commit marker before changing any supporting file.
|
|
778
|
-
for (const fileName of [commitFileName, ...orderedFiles.map((file) => file.fileName).filter((name) => name !== commitFileName)]) {
|
|
779
|
-
const livePath = path.join(artifactRoot, fileName);
|
|
780
|
-
try {
|
|
781
|
-
await fs.rename(livePath, path.join(backupRoot, fileName));
|
|
782
|
-
backedUp.add(fileName);
|
|
783
|
-
}
|
|
784
|
-
catch (error) {
|
|
785
|
-
if (!isNodeError(error) || error.code !== "ENOENT") {
|
|
786
|
-
throw error;
|
|
787
|
-
}
|
|
788
|
-
}
|
|
789
|
-
}
|
|
790
|
-
for (const [index, file] of orderedFiles.entries()) {
|
|
791
|
-
throwIfPublicationCancelled(options.signal);
|
|
792
|
-
await options.beforePublishFile?.(file.fileName, index);
|
|
793
|
-
await fs.rename(path.join(stagingRoot, file.fileName), path.join(artifactRoot, file.fileName));
|
|
794
|
-
published.add(file.fileName);
|
|
795
|
-
}
|
|
796
|
-
}
|
|
797
|
-
catch (error) {
|
|
798
|
-
const rollbackErrors = [];
|
|
799
|
-
for (const file of [...orderedFiles].reverse()) {
|
|
800
|
-
if (!published.has(file.fileName))
|
|
801
|
-
continue;
|
|
802
|
-
await fs.rm(path.join(artifactRoot, file.fileName), { force: true }).catch(() => {
|
|
803
|
-
rollbackErrors.push(file.fileName);
|
|
804
|
-
});
|
|
805
|
-
}
|
|
806
|
-
// Restore the previous marker last for the same observable commit boundary.
|
|
807
|
-
const restoreOrder = [
|
|
808
|
-
...orderedFiles.filter((file) => file.fileName !== commitFileName),
|
|
809
|
-
orderedFiles.find((file) => file.fileName === commitFileName)
|
|
810
|
-
];
|
|
811
|
-
for (const file of restoreOrder) {
|
|
812
|
-
if (!backedUp.has(file.fileName))
|
|
813
|
-
continue;
|
|
814
|
-
await fs.rename(path.join(backupRoot, file.fileName), path.join(artifactRoot, file.fileName)).catch(() => {
|
|
815
|
-
rollbackErrors.push(file.fileName);
|
|
816
|
-
});
|
|
817
|
-
}
|
|
818
|
-
if (rollbackErrors.length === 0
|
|
819
|
-
&& error instanceof Error
|
|
820
|
-
&& error.message.startsWith("artifact_atomic_publish_cancelled:")) {
|
|
821
|
-
throw error;
|
|
822
|
-
}
|
|
823
|
-
const suffix = rollbackErrors.length > 0 ? " Rollback did not restore every bundle file." : "";
|
|
824
|
-
throw new Error(`artifact_atomic_publish_failure: completion artifact bundle was not published.${suffix}`, { cause: error });
|
|
825
|
-
}
|
|
826
|
-
finally {
|
|
827
|
-
await fs.rm(stagingRoot, { recursive: true, force: true }).catch(() => undefined);
|
|
828
|
-
}
|
|
829
|
-
}
|
|
830
|
-
function validateArtifactBundleFiles(files, commitFileName) {
|
|
831
|
-
if (files.length === 0 || !files.some((file) => file.fileName === commitFileName)) {
|
|
832
|
-
throw new Error("artifact_atomic_publish_failure: bundle commit file is missing.");
|
|
833
|
-
}
|
|
834
|
-
const names = new Set();
|
|
835
|
-
for (const file of files) {
|
|
836
|
-
if (!file.fileName || path.basename(file.fileName) !== file.fileName || names.has(file.fileName)) {
|
|
837
|
-
throw new Error("artifact_atomic_publish_failure: bundle file names must be unique safe base names.");
|
|
838
|
-
}
|
|
839
|
-
names.add(file.fileName);
|
|
840
|
-
}
|
|
841
|
-
}
|
|
842
|
-
function throwIfPublicationCancelled(signal) {
|
|
843
|
-
if (signal?.aborted) {
|
|
844
|
-
throw new Error("artifact_atomic_publish_cancelled: completion artifact bundle publication was cancelled.");
|
|
845
|
-
}
|
|
846
|
-
}
|
|
847
|
-
function validatePostRedaction(validate) {
|
|
848
|
-
try {
|
|
849
|
-
validate();
|
|
850
|
-
}
|
|
851
|
-
catch (error) {
|
|
852
|
-
throw postRedactionValidationError(error);
|
|
853
|
-
}
|
|
854
|
-
}
|
|
855
|
-
function postRedactionValidationError(error) {
|
|
856
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
857
|
-
return new Error(`artifact_post_redaction_validation_failed: ${message}`, { cause: error });
|
|
858
|
-
}
|
|
859
|
-
function assertStructuralFieldsUnchanged(original, redacted) {
|
|
860
|
-
if (structuralFieldFingerprint(original) !== structuralFieldFingerprint(redacted)) {
|
|
861
|
-
// This stable code is intentionally safe for telemetry: it does not include
|
|
862
|
-
// the structural value or any candidate secret.
|
|
863
|
-
throw new Error("artifact_redaction_changed_structural_field: redaction changed a structural identifier; the bundle was not published.");
|
|
864
|
-
}
|
|
865
|
-
}
|
|
866
|
-
function structuralFieldFingerprint(value, key = "", result = []) {
|
|
867
|
-
if (Array.isArray(value)) {
|
|
868
|
-
if (isStructuralFieldKey(key) && value.every((item) => item === null || typeof item !== "object")) {
|
|
869
|
-
result.push(stableStringify(value));
|
|
870
|
-
}
|
|
871
|
-
else {
|
|
872
|
-
for (const item of value)
|
|
873
|
-
structuralFieldFingerprint(item, key, result);
|
|
874
|
-
}
|
|
875
|
-
return result.join("\n");
|
|
876
|
-
}
|
|
877
|
-
if (!value || typeof value !== "object") {
|
|
878
|
-
if (isStructuralFieldKey(key))
|
|
879
|
-
result.push(stableStringify(value));
|
|
880
|
-
return result.join("\n");
|
|
881
|
-
}
|
|
882
|
-
for (const [childKey, child] of Object.entries(value)) {
|
|
883
|
-
if (isStructuralFieldKey(childKey)) {
|
|
884
|
-
result.push(`${childKey}:${stableStringify(child)}`);
|
|
885
|
-
}
|
|
886
|
-
else {
|
|
887
|
-
structuralFieldFingerprint(child, childKey, result);
|
|
888
|
-
}
|
|
889
|
-
}
|
|
890
|
-
return result.join("\n");
|
|
891
|
-
}
|
|
892
|
-
function isStructuralFieldKey(key) {
|
|
893
|
-
return key === "id"
|
|
894
|
-
|| key === "before"
|
|
895
|
-
|| key === "after"
|
|
896
|
-
|| key === "from"
|
|
897
|
-
|| key === "to"
|
|
898
|
-
|| key === "tasks"
|
|
899
|
-
|| key === "phases"
|
|
900
|
-
|| /(?:^|_)(?:id|ids)$/i.test(key)
|
|
901
|
-
|| /(?:Id|Ids)$/.test(key);
|
|
902
|
-
}
|
|
801
|
+
export { publishArtifactBundleAtomic } from "./phase-completion.artifact-bundle.js";
|
|
@@ -2,8 +2,10 @@ import type { RunOnceDispatchPacket } from "./session.types.js";
|
|
|
2
2
|
import type { WorktreeHandle } from "../worktree/worktree.types.js";
|
|
3
3
|
export { isDebugCompletionPhase } from "./phase-completion.validation.js";
|
|
4
4
|
export { readCompletionArtifact, writeCompletionArtifact } from "./phase-completion.artifacts.js";
|
|
5
|
+
export { recordedPrReviewArtifactProblem } from "./phase-completion.pr-review.js";
|
|
5
6
|
export * from "./phase-completion.prompts.js";
|
|
6
7
|
export * from "./phase-completion.runtime.js";
|
|
8
|
+
export * from "./phase-completion.mcp-args.js";
|
|
7
9
|
export type DevelopCompletionPhase = "implementation" | "self_review" | "validation";
|
|
8
10
|
export type DebugCompletionPhase = "debug_repro" | "debug_root_cause" | "debug_fix" | "debug_regression";
|
|
9
11
|
export type ArchitectCompletionPhase = "architect";
|
|
@@ -11,7 +13,8 @@ export type DraftCompletionPhase = "draft";
|
|
|
11
13
|
export type DecomposeCompletionPhase = "decompose";
|
|
12
14
|
export type CiRepairCompletionPhase = "ci_repair";
|
|
13
15
|
export type CommentRepairCompletionPhase = "comment_repair";
|
|
14
|
-
export type
|
|
16
|
+
export type PrReviewCompletionPhase = "pr_review";
|
|
17
|
+
export type CompletionPhase = DevelopCompletionPhase | "qa" | DebugCompletionPhase | ArchitectCompletionPhase | DraftCompletionPhase | DecomposeCompletionPhase | CiRepairCompletionPhase | CommentRepairCompletionPhase | PrReviewCompletionPhase;
|
|
15
18
|
export type QaCompletionGate = "qa_plan" | "qa_regression" | "qa_api" | "qa_manual_web" | "qa_bug_repro" | "qa_findings" | "qa_verdict";
|
|
16
19
|
export type DraftCompletionGate = "draft_intent" | "draft_repo_context" | "draft_graph_context" | "draft_product_scope" | "draft_work_order_plan" | "draft_critic" | "draft_proposal";
|
|
17
20
|
export type DecomposeCompletionGate = "decompose_subject_intake" | "decompose_context_review" | "decompose_breakdown_strategy" | "decompose_child_items" | "decompose_dependency_graph" | "decompose_critic" | "decompose_proposal";
|
|
@@ -31,6 +34,23 @@ export interface CompletionToolRuntimeOptions {
|
|
|
31
34
|
readonly runtimeEnvironment?: Readonly<Record<string, string>>;
|
|
32
35
|
/** Host load governor variables; only the MCP server receives them. */
|
|
33
36
|
readonly hostLoadEnvironment?: Readonly<Record<string, string>>;
|
|
37
|
+
/**
|
|
38
|
+
* Serve only the managed-attempt tools (managed commands, verification, waits), never a
|
|
39
|
+
* completion tool. A pre-publication repair turn uses this: its phase's completion artifacts are
|
|
40
|
+
* already recorded and validated, and the repair prompt forbids rewriting them.
|
|
41
|
+
*/
|
|
42
|
+
readonly managedToolsOnly?: boolean;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* What Forge knows about the pull request under review, handed to the pr_review completion
|
|
46
|
+
* tool so it can reject a review bound to the wrong head or citing threads the dispatch never
|
|
47
|
+
* listed. Every field is optional: whatever is absent is verified against the worktree instead.
|
|
48
|
+
*/
|
|
49
|
+
export interface PrReviewCompletionContext {
|
|
50
|
+
readonly headSha?: string;
|
|
51
|
+
readonly baseSha?: string;
|
|
52
|
+
/** Thread ids the dispatch lists as prior review threads. Enforced only when non-empty. */
|
|
53
|
+
readonly threadIds?: readonly string[];
|
|
34
54
|
}
|
|
35
55
|
export interface CompletionToolServerConfig {
|
|
36
56
|
readonly worktreePath: string;
|
|
@@ -46,6 +66,8 @@ export interface CompletionToolServerConfig {
|
|
|
46
66
|
readonly architectCycle?: boolean;
|
|
47
67
|
readonly draftCycle?: boolean;
|
|
48
68
|
readonly decomposeCycle?: boolean;
|
|
69
|
+
readonly prReview?: PrReviewCompletionContext;
|
|
70
|
+
readonly managedToolsOnly?: boolean;
|
|
49
71
|
}
|
|
50
72
|
export interface CompletionToolCallResult {
|
|
51
73
|
readonly content: readonly {
|
|
@@ -69,7 +91,7 @@ export interface CompletionToolCallResult {
|
|
|
69
91
|
readonly allowed: boolean;
|
|
70
92
|
readonly reason: string;
|
|
71
93
|
};
|
|
72
|
-
readonly nextPhase: CompletionPhase | "dev_test_ready" | "qa_ready" | "sign_off_ready" | "provider_checks_ready";
|
|
94
|
+
readonly nextPhase: CompletionPhase | "dev_test_ready" | "qa_ready" | "sign_off_ready" | "provider_checks_ready" | "pr_review_complete";
|
|
73
95
|
readonly nextInstruction: string;
|
|
74
96
|
};
|
|
75
97
|
}
|
|
@@ -119,6 +141,9 @@ export declare const qaScopeAuthorities: Set<string>;
|
|
|
119
141
|
export declare const qaScopeConfidence: Set<string>;
|
|
120
142
|
export declare const qaScopeFields: Set<string>;
|
|
121
143
|
export declare const phaseFiles: Record<CompletionPhase, CompletionArtifactFiles>;
|
|
144
|
+
/** Statuses `forge.complete_pr_review` accepts; each one ends the review lane. */
|
|
145
|
+
export declare const prReviewStatuses: readonly ["reviewed", "stale_head", "blocked"];
|
|
146
|
+
export type PrReviewStatus = (typeof prReviewStatuses)[number];
|
|
122
147
|
export declare function completionPhaseFromDispatch(dispatch: RunOnceDispatchPacket): CompletionPhase;
|
|
123
148
|
export declare function normalizeCompletionPhase(value: string | null | undefined): CompletionPhase;
|
|
124
149
|
export declare function usesDevelopCycleCompletion(dispatch: RunOnceDispatchPacket): boolean;
|
|
@@ -4,6 +4,7 @@ import path from "node:path";
|
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
5
|
import { debugCompletionPhaseOrder, debugGateToolNames, decomposeCompletionGateOrder, decomposeGateToolNames, draftCompletionGateOrder, draftGateToolNames, qaCompletionGateOrder, qaGateToolNames, resolvedFindingStatuses } from "./phase-completion.js";
|
|
6
6
|
import { structuredTypeHint } from "./mcp-argument-coercion.js";
|
|
7
|
+
import { completionPhaseFromAlias, singleGatePhaseFromToolName } from "./phase-completion.phase-aliases.js";
|
|
7
8
|
export function normalizeArtifactPayload(payload, defaults) {
|
|
8
9
|
const normalized = stripUndefined({ ...payload });
|
|
9
10
|
delete normalized.report_markdown;
|
|
@@ -61,38 +62,7 @@ ${summary}
|
|
|
61
62
|
}
|
|
62
63
|
export function parseStrictCompletionPhase(value) {
|
|
63
64
|
const normalized = (value ?? "").trim().toLowerCase().replace(/-/g, "_");
|
|
64
|
-
|
|
65
|
-
if (debugPhase) {
|
|
66
|
-
return debugPhase;
|
|
67
|
-
}
|
|
68
|
-
if (normalized === "implementation" || normalized === "implement" || normalized === "develop") {
|
|
69
|
-
return "implementation";
|
|
70
|
-
}
|
|
71
|
-
if (normalized === "self_review" || normalized === "selfreview" || normalized === "review") {
|
|
72
|
-
return "self_review";
|
|
73
|
-
}
|
|
74
|
-
if (normalized === "validate" || normalized === "validation") {
|
|
75
|
-
return "validation";
|
|
76
|
-
}
|
|
77
|
-
if (normalized === "qa" || normalized === "quality_assurance" || normalized === "qualityassurance") {
|
|
78
|
-
return "qa";
|
|
79
|
-
}
|
|
80
|
-
if (normalized === "architect" || normalized === "architect_plan" || normalized === "planning" || normalized === "plan") {
|
|
81
|
-
return "architect";
|
|
82
|
-
}
|
|
83
|
-
if (normalized === "draft" || normalized === "drafting" || normalized === "draft_work_order") {
|
|
84
|
-
return "draft";
|
|
85
|
-
}
|
|
86
|
-
if (normalized === "decompose" || normalized === "decomposition" || normalized === "work_order_decomposition" || normalized === "feature_decomposition") {
|
|
87
|
-
return "decompose";
|
|
88
|
-
}
|
|
89
|
-
if (normalized === "ci_repair" || normalized === "pr_checks" || normalized === "repair_pr_checks") {
|
|
90
|
-
return "ci_repair";
|
|
91
|
-
}
|
|
92
|
-
if (normalized === "comment_repair" || normalized === "pr_comments" || normalized === "repair_pr_comments") {
|
|
93
|
-
return "comment_repair";
|
|
94
|
-
}
|
|
95
|
-
return null;
|
|
65
|
+
return normalizeDebugCompletionPhase(normalized) ?? completionPhaseFromAlias(normalized);
|
|
96
66
|
}
|
|
97
67
|
export function normalizeDebugCompletionPhase(value) {
|
|
98
68
|
const normalized = (value ?? "").trim().toLowerCase().replace(/-/g, "_");
|
|
@@ -147,27 +117,9 @@ export function parseCompletionRedactionSecrets(raw) {
|
|
|
147
117
|
}
|
|
148
118
|
}
|
|
149
119
|
export function phaseFromToolName(toolName) {
|
|
150
|
-
const
|
|
151
|
-
if (
|
|
152
|
-
return
|
|
153
|
-
}
|
|
154
|
-
if (normalized === "forge.complete_self_review" || normalized === "complete_self_review") {
|
|
155
|
-
return "self_review";
|
|
156
|
-
}
|
|
157
|
-
if (normalized === "forge.complete_validation" || normalized === "complete_validation") {
|
|
158
|
-
return "validation";
|
|
159
|
-
}
|
|
160
|
-
if (normalized === "forge.complete_qa" || normalized === "complete_qa") {
|
|
161
|
-
return "qa";
|
|
162
|
-
}
|
|
163
|
-
if (normalized === "forge.complete_architect_plan" || normalized === "complete_architect_plan") {
|
|
164
|
-
return "architect";
|
|
165
|
-
}
|
|
166
|
-
if (normalized === "forge.complete_ci_repair" || normalized === "complete_ci_repair") {
|
|
167
|
-
return "ci_repair";
|
|
168
|
-
}
|
|
169
|
-
if (normalized === "forge.complete_comment_repair" || normalized === "complete_comment_repair") {
|
|
170
|
-
return "comment_repair";
|
|
120
|
+
const singleGatePhase = singleGatePhaseFromToolName(toolName);
|
|
121
|
+
if (singleGatePhase) {
|
|
122
|
+
return singleGatePhase;
|
|
171
123
|
}
|
|
172
124
|
if (draftGateFromToolName(toolName)) {
|
|
173
125
|
return "draft";
|