@loucompanion/forge-bridge 0.1.4-dev.a5a3a7ab2f02 → 0.1.4-dev.a7b2e9125fed

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.
Files changed (103) hide show
  1. package/README.md +22 -0
  2. package/dist/bridge/bridge-chat-provider-command.d.ts +16 -0
  3. package/dist/bridge/bridge-chat-provider-command.js +137 -0
  4. package/dist/bridge/bridge-chat.types.d.ts +10 -0
  5. package/dist/bridge/bridge-chat.types.js +16 -1
  6. package/dist/bridge/bridge.service.d.ts +1 -1
  7. package/dist/bridge/bridge.service.js +4 -110
  8. package/dist/bridge/runner-host-capabilities.d.ts +3 -0
  9. package/dist/bridge/runner-host-capabilities.js +13 -0
  10. package/dist/runtime/attempt-database-broker.d.ts +1 -1
  11. package/dist/runtime/docker-engine-probe.d.ts +5 -0
  12. package/dist/runtime/docker-engine-probe.js +7 -0
  13. package/dist/runtime/ephemeral-test-postgres-grant.d.ts +37 -0
  14. package/dist/runtime/ephemeral-test-postgres-grant.js +85 -0
  15. package/dist/runtime/ephemeral-test-postgres.d.ts +57 -0
  16. package/dist/runtime/ephemeral-test-postgres.js +303 -0
  17. package/dist/runtime/host-facts.d.ts +2 -1
  18. package/dist/runtime/host-load-admission.d.ts +9 -2
  19. package/dist/runtime/host-load-child-environment.d.ts +11 -6
  20. package/dist/runtime/host-load-child-environment.js +19 -10
  21. package/dist/runtime/host-load-governor-config.d.ts +10 -1
  22. package/dist/runtime/host-load-governor-config.js +7 -0
  23. package/dist/runtime/host-load-governor.d.ts +10 -0
  24. package/dist/runtime/host-load-governor.js +125 -34
  25. package/dist/runtime/host-load-sampler.d.ts +34 -4
  26. package/dist/runtime/host-load-sampler.js +73 -7
  27. package/dist/runtime/host-load-step-class.d.ts +3 -1
  28. package/dist/runtime/host-load-step-class.js +60 -5
  29. package/dist/runtime/host-load-test-slot.d.ts +43 -0
  30. package/dist/runtime/host-load-test-slot.js +81 -0
  31. package/dist/runtime/host-load-token-ledger.d.ts +26 -0
  32. package/dist/runtime/host-load-token-ledger.js +93 -61
  33. package/dist/runtime/host-load-windows-cpu.d.ts +34 -0
  34. package/dist/runtime/host-load-windows-cpu.js +85 -0
  35. package/dist/runtime/host-runtime-lease.d.ts +1 -1
  36. package/dist/runtime/host-runtime-lease.js +1 -1
  37. package/dist/runtime/native-test-postgres-fallback.d.ts +51 -7
  38. package/dist/runtime/native-test-postgres-fallback.js +60 -8
  39. package/dist/sandbox/host-capacity-broker.d.ts +7 -1
  40. package/dist/sandbox/host-capacity-broker.js +23 -4
  41. package/dist/session/architect-waits.d.ts +2 -0
  42. package/dist/session/architect-waits.js +138 -0
  43. package/dist/session/managed-attempt-tools.d.ts +0 -7
  44. package/dist/session/managed-attempt-tools.js +51 -62
  45. package/dist/session/managed-command-host-load.d.ts +2 -0
  46. package/dist/session/managed-command-host-load.js +2 -1
  47. package/dist/session/phase-completion.artifacts.js +2 -1
  48. package/dist/session/phase-completion.d.ts +8 -0
  49. package/dist/session/phase-completion.js +1 -0
  50. package/dist/session/phase-completion.mcp-args.d.ts +9 -0
  51. package/dist/session/phase-completion.mcp-args.js +156 -0
  52. package/dist/session/phase-completion.runtime.d.ts +0 -8
  53. package/dist/session/phase-completion.runtime.js +38 -168
  54. package/dist/session/phase-completion.schemas.js +25 -23
  55. package/dist/session/phase-completion.validation.js +3 -1
  56. package/dist/session/pre-publication-native-postgres.d.ts +30 -0
  57. package/dist/session/pre-publication-native-postgres.js +111 -0
  58. package/dist/session/pre-publication-pass.d.ts +61 -0
  59. package/dist/session/pre-publication-pass.js +148 -0
  60. package/dist/session/pre-publication-step-execution.d.ts +2 -1
  61. package/dist/session/pre-publication-step-execution.js +6 -5
  62. package/dist/session/pre-publication-validation.d.ts +30 -14
  63. package/dist/session/pre-publication-validation.js +207 -134
  64. package/dist/session/provider-cli/claude-background-work.d.ts +66 -0
  65. package/dist/session/provider-cli/claude-background-work.js +180 -0
  66. package/dist/session/provider-cli/pre-publication-repair.d.ts +56 -0
  67. package/dist/session/provider-cli/pre-publication-repair.js +276 -0
  68. package/dist/session/provider-cli/provider-cli.child-environment.d.ts +7 -0
  69. package/dist/session/provider-cli/provider-cli.child-environment.js +73 -0
  70. package/dist/session/provider-cli/provider-cli.codex-models-cache.d.ts +3 -0
  71. package/dist/session/provider-cli/provider-cli.codex-models-cache.js +37 -0
  72. package/dist/session/provider-cli/provider-cli.process.d.ts +15 -36
  73. package/dist/session/provider-cli/provider-cli.process.js +39 -430
  74. package/dist/session/provider-cli/provider-cli.prompts.d.ts +5 -0
  75. package/dist/session/provider-cli/provider-cli.prompts.js +58 -8
  76. package/dist/session/provider-cli/provider-cli.runtime.js +7 -0
  77. package/dist/session/provider-cli/provider-cli.service.d.ts +5 -5
  78. package/dist/session/provider-cli/provider-cli.service.js +65 -257
  79. package/dist/session/provider-cli/provider-cli.windows-environment.d.ts +10 -0
  80. package/dist/session/provider-cli/provider-cli.windows-environment.js +151 -0
  81. package/dist/session/provider-cli/provider-cli.windows-launch.d.ts +23 -0
  82. package/dist/session/provider-cli/provider-cli.windows-launch.js +131 -0
  83. package/dist/session/provider-cli/provider-in-flight-work.d.ts +4 -0
  84. package/dist/session/provider-cli/provider-in-flight-work.js +45 -0
  85. package/dist/session/provider-cli/provider-output-pipes.d.ts +30 -0
  86. package/dist/session/provider-cli/provider-output-pipes.js +67 -0
  87. package/dist/session/provider-cli/provider-output-state.d.ts +2 -0
  88. package/dist/session/provider-cli/provider-output-state.js +6 -0
  89. package/dist/session/qa-sidecar-validation.d.ts +6 -0
  90. package/dist/session/qa-sidecar-validation.js +28 -0
  91. package/dist/session/sandbox-host-capacity-gate.js +12 -3
  92. package/dist/session/session-redaction.js +31 -181
  93. package/dist/session/session.types.js +2 -2
  94. package/dist/session/sidecar-json-shape.d.ts +31 -0
  95. package/dist/session/sidecar-json-shape.js +217 -0
  96. package/dist/shared/process/windows-app-execution-alias.d.ts +19 -0
  97. package/dist/shared/process/windows-app-execution-alias.js +45 -0
  98. package/dist/shared/process/windows-launch.d.ts +18 -0
  99. package/dist/shared/process/windows-launch.js +68 -0
  100. package/dist/shared/provider-capabilities.js +5 -6
  101. package/dist/version.d.ts +1 -1
  102. package/dist/version.js +1 -1
  103. package/package.json +1 -1
@@ -0,0 +1,156 @@
1
+ import path from "node:path";
2
+ import { attemptDatabaseCapabilityEnvironment, attemptDatabaseCapabilitySecrets, } from "../runtime/attempt-database-broker.js";
3
+ import { completionRedactionSecretsEnv, } from "./phase-completion.js";
4
+ import { isDebugCompletionPhase, isDevelopCompletionPhase, normalizedOwnerType, parseCompletionRedactionSecrets, parseStrictCompletionPhase, } from "./phase-completion.validation.js";
5
+ // The `forge-bridge mcp` command line: the arguments the Bridge launches its completion-tool server
6
+ // with, and the parsing that server applies to them.
7
+ export function buildCompletionToolServerArgs(config) {
8
+ const args = [
9
+ "mcp",
10
+ "--worktree",
11
+ path.resolve(config.worktreePath),
12
+ "--work-item-id",
13
+ config.workItemId,
14
+ "--phase",
15
+ config.phase,
16
+ "--produced-by",
17
+ config.producedBy ?? "forge-completion-tool"
18
+ ];
19
+ if (config.ownerType || config.ownerId) {
20
+ args.push("--owner-type", normalizedOwnerType(config.ownerType) ?? "work_item");
21
+ args.push("--owner-id", config.ownerId ?? config.workItemId);
22
+ }
23
+ if (config.developCycle) {
24
+ args.push("--develop-cycle");
25
+ }
26
+ if (config.qaCycle) {
27
+ args.push("--qa-cycle");
28
+ }
29
+ if (config.debugCycle) {
30
+ args.push("--debug-cycle");
31
+ }
32
+ if (config.architectCycle) {
33
+ args.push("--architect-cycle");
34
+ }
35
+ if (config.draftCycle) {
36
+ args.push("--draft-cycle");
37
+ }
38
+ if (config.decomposeCycle) {
39
+ args.push("--decompose-cycle");
40
+ }
41
+ if (config.managedToolsOnly) {
42
+ args.push("--managed-tools-only");
43
+ }
44
+ return args;
45
+ }
46
+ const completionMcpFlags = {
47
+ "--develop-cycle": "developCycle",
48
+ "--qa-cycle": "qaCycle",
49
+ "--debug-cycle": "debugCycle",
50
+ "--architect-cycle": "architectCycle",
51
+ "--draft-cycle": "draftCycle",
52
+ "--decompose-cycle": "decomposeCycle",
53
+ "--managed-tools-only": "managedToolsOnly",
54
+ };
55
+ const completionMcpValues = {
56
+ "--worktree": "worktreePath",
57
+ "--work-item-id": "workItemId",
58
+ "--owner-id": "ownerId",
59
+ "--produced-by": "producedBy",
60
+ };
61
+ export function parseCompletionMcpArgs(argv) {
62
+ let phase = "implementation";
63
+ let ownerType;
64
+ const values = {};
65
+ const flags = {
66
+ developCycle: false,
67
+ qaCycle: false,
68
+ debugCycle: false,
69
+ architectCycle: false,
70
+ draftCycle: false,
71
+ decomposeCycle: false,
72
+ managedToolsOnly: false,
73
+ };
74
+ for (let index = 1; index < argv.length; index += 1) {
75
+ const arg = argv[index];
76
+ if (Object.hasOwn(completionMcpFlags, arg)) {
77
+ flags[completionMcpFlags[arg]] = true;
78
+ }
79
+ else if (Object.hasOwn(completionMcpValues, arg)) {
80
+ values[completionMcpValues[arg]] = argv[++index];
81
+ }
82
+ else if (arg === "--owner-type") {
83
+ ownerType = normalizedOwnerType(argv[++index]);
84
+ if (!ownerType) {
85
+ return { ok: false, error: "mcp --owner-type must be work_item or story." };
86
+ }
87
+ }
88
+ else if (arg === "--phase") {
89
+ const rawPhase = argv[++index];
90
+ const parsedPhase = parseStrictCompletionPhase(rawPhase);
91
+ if (!parsedPhase) {
92
+ return { ok: false, error: "mcp --phase must be one of: implementation, self-review, validation, qa, architect, draft, decompose, ci-repair, comment-repair, debug-repro, debug-root-cause, debug-fix, debug-regression." };
93
+ }
94
+ phase = parsedPhase;
95
+ }
96
+ else {
97
+ return { ok: false, error: `Unknown mcp argument: ${arg}` };
98
+ }
99
+ }
100
+ const { worktreePath, workItemId, ownerId, producedBy } = values;
101
+ if (!worktreePath?.trim() || !workItemId?.trim()) {
102
+ return { ok: false, error: "mcp requires --worktree and --work-item-id." };
103
+ }
104
+ const { managedToolsOnly, ...cycles } = flags;
105
+ const config = {
106
+ worktreePath: path.resolve(worktreePath),
107
+ workItemId,
108
+ ownerType,
109
+ ownerId,
110
+ phase,
111
+ producedBy,
112
+ redactionSecrets: redactionSecretsFromEnvironment(),
113
+ ...cycles,
114
+ ...(managedToolsOnly ? { managedToolsOnly } : {})
115
+ };
116
+ const modeError = completionMcpModeError(config);
117
+ return modeError ? { ok: false, error: modeError } : { ok: true, config };
118
+ }
119
+ /** The secrets the server redacts from what it records: the Bridge's list and the attempt database capability. */
120
+ function redactionSecretsFromEnvironment() {
121
+ return [
122
+ ...parseCompletionRedactionSecrets(process.env[completionRedactionSecretsEnv]),
123
+ ...attemptDatabaseCapabilitySecrets(process.env[attemptDatabaseCapabilityEnvironment]),
124
+ ];
125
+ }
126
+ /** Why the parsed cycle mode, phase and tool scope cannot run together, or null when they can. */
127
+ function completionMcpModeError(config) {
128
+ const { phase } = config;
129
+ const cycleModes = [config.developCycle, config.qaCycle, config.debugCycle, config.architectCycle, config.draftCycle, config.decomposeCycle]
130
+ .filter(Boolean).length;
131
+ if (cycleModes > 1) {
132
+ return "mcp accepts only one cycle mode.";
133
+ }
134
+ if (config.managedToolsOnly && cycleModes > 0) {
135
+ return "mcp --managed-tools-only serves no completion tools, so it accepts no cycle mode.";
136
+ }
137
+ if (config.developCycle && !isDevelopCompletionPhase(phase)) {
138
+ return "mcp --develop-cycle requires --phase implementation, self-review, or validation.";
139
+ }
140
+ if (config.qaCycle && phase !== "qa") {
141
+ return "mcp --qa-cycle requires --phase qa.";
142
+ }
143
+ if (config.debugCycle && !isDebugCompletionPhase(phase)) {
144
+ return "mcp --debug-cycle requires --phase debug-repro, debug-root-cause, debug-fix, or debug-regression.";
145
+ }
146
+ if (config.architectCycle && phase !== "architect") {
147
+ return "mcp --architect-cycle requires --phase architect.";
148
+ }
149
+ if (config.draftCycle && phase !== "draft") {
150
+ return "mcp --draft-cycle requires --phase draft.";
151
+ }
152
+ if (config.decomposeCycle && phase !== "decompose") {
153
+ return "mcp --decompose-cycle requires --phase decompose.";
154
+ }
155
+ return null;
156
+ }
@@ -1,7 +1,6 @@
1
1
  import { type CompletionToolCallResult, type CompletionToolRuntime, type CompletionToolRuntimeOptions, type CompletionToolServerConfig } from "./phase-completion.js";
2
2
  import { type ManagedAttemptToolResult } from "./managed-attempt-tools.js";
3
3
  export declare function prepareCompletionToolRuntime(options: CompletionToolRuntimeOptions): Promise<CompletionToolRuntime>;
4
- export declare function buildCompletionToolServerArgs(config: CompletionToolServerConfig): readonly string[];
5
4
  export declare function codexMcpConfigArgs(runtime: CompletionToolRuntime): readonly string[];
6
5
  export declare function cursorMcpServerConfig(runtime: CompletionToolRuntime): unknown;
7
6
  export declare function claudeMcpServerConfig(runtime: CompletionToolRuntime): unknown;
@@ -38,13 +37,6 @@ export declare function completionToolRuntimeEnvironment(runtimeEnvironment?: Re
38
37
  */
39
38
  export declare function assertManagedQaRegressionEvidence(input: unknown, receipts: readonly Readonly<Record<string, unknown>>[]): void;
40
39
  export declare function runCompletionMcpServer(config: CompletionToolServerConfig): Promise<void>;
41
- export declare function parseCompletionMcpArgs(argv: readonly string[]): {
42
- readonly ok: true;
43
- readonly config: CompletionToolServerConfig;
44
- } | {
45
- readonly ok: false;
46
- readonly error: string;
47
- };
48
40
  export declare function completionRedactionEnv(secrets: readonly string[]): Readonly<Record<string, string>>;
49
41
  export declare function completionToolRejectedResult(toolName: string, error: unknown, input?: unknown): Readonly<Record<string, unknown>>;
50
42
  /** The input schema a completion tool advertises; also the shape its arguments are coerced to. */
@@ -1,15 +1,15 @@
1
1
  import fs from "node:fs/promises";
2
2
  import os from "node:os";
3
3
  import path from "node:path";
4
- import { attemptDatabaseCapabilityEnvironment, attemptDatabaseCapabilitySecrets, } from "../runtime/attempt-database-broker.js";
5
4
  import { completionPhaseFromDispatch, completionPhaseOrder, completionRedactionSecretsEnv, completionToolNamesForDebugGate, completionToolNamesForDecomposeGate, completionToolNamesForDraftGate, completionToolNamesForPhase, completionToolNamesForQaGate, debugCompletionPhaseOrder, decomposeCompletionGateOrder, draftCompletionGateOrder, qaCompletionGateOrder, toolServerName, usesArchitectCycleCompletion, usesDebugCycleCompletion, usesDevelopCycleCompletion, usesQaCycleCompletion } from "./phase-completion.js";
6
- import { CompletionPayloadValidationError, asDebugCompletionPhase, asJsonRpcMessage, asMutableRecord, asRecord, artifactOwnerRelativeRoot, decomposeGateFromToolName, draftGateFromToolName, errorMessage, forgeBridgeCliBinPath, isDebugCompletionPhase, isDecomposeDispatch, isDevelopCompletionPhase, normalizedOwnerType, parseCompletionRedactionSecrets, parseOptionalJsonObject, parseStrictCompletionPhase, phaseFromToolName, qaGateFromToolName, requiredString, rpcError, tomlString, tomlStringArray, writeFileAtomic, writeJsonRpc } from "./phase-completion.validation.js";
5
+ import { CompletionPayloadValidationError, asDebugCompletionPhase, asJsonRpcMessage, asMutableRecord, asRecord, artifactOwnerRelativeRoot, decomposeGateFromToolName, draftGateFromToolName, errorMessage, forgeBridgeCliBinPath, isDebugCompletionPhase, isDecomposeDispatch, normalizedOwnerType, parseOptionalJsonObject, phaseFromToolName, qaGateFromToolName, requiredString, rpcError, tomlString, tomlStringArray, writeFileAtomic, writeJsonRpc } from "./phase-completion.validation.js";
7
6
  import { completionPromptForDebugCycle, completionPromptForDecomposeCycle, completionPromptForDevelopCycle, completionPromptForDraftCycle, completionPromptForPhase, completionPromptForQaCycle, completionToolNextInstruction, completionToolNextInstructionForDebugGate, completionToolNextInstructionForDecomposeGate, completionToolNextInstructionForDraftGate, completionToolNextInstructionForQaGate, nextDebugPhaseAfter, nextPhaseAfter } from "./phase-completion.prompts.js";
8
7
  import { configuredNativeTestPostgresFallbackPath, nativeTestPostgresFallbackConfigEnvironment, } from "../runtime/native-test-postgres-fallback.js";
9
8
  import { isHostLoadChildEnvironmentName } from "../runtime/host-load-child-environment.js";
10
9
  import { toolDescription, toolInputSchema } from "./phase-completion.schemas.js";
11
10
  import { coerceJsonStringArguments, emptyToolInputHint, isEmptyToolInput } from "./mcp-argument-coercion.js";
12
11
  import { writeCompletionArtifact, writeDecomposeGateCompletionArtifact, writeDraftGateCompletionArtifact } from "./phase-completion.artifacts.js";
12
+ import { buildCompletionToolServerArgs } from "./phase-completion.mcp-args.js";
13
13
  import { callManagedAttemptTool, isManagedAttemptTool, managedAttemptToolDefinition, managedAttemptToolInputSchema, managedAttemptToolNames, runWithOwnerShutdown, } from "./managed-attempt-tools.js";
14
14
  export async function prepareCompletionToolRuntime(options) {
15
15
  const phase = options.phase ?? completionPhaseFromDispatch(options.dispatch);
@@ -17,6 +17,8 @@ export async function prepareCompletionToolRuntime(options) {
17
17
  const workItemId = options.dispatch.workItem.id;
18
18
  const ownerType = normalizedOwnerType(options.dispatch.cycleRun.ownerType) ?? "work_item";
19
19
  const ownerId = options.dispatch.cycleRun.ownerId ?? workItemId;
20
+ // A managed-tools-only server records no completion artifact, so it takes no cycle mode.
21
+ const cycles = !options.managedToolsOnly;
20
22
  const mcpArgs = buildCompletionToolServerArgs({
21
23
  worktreePath,
22
24
  workItemId,
@@ -24,15 +26,17 @@ export async function prepareCompletionToolRuntime(options) {
24
26
  ownerId,
25
27
  phase,
26
28
  producedBy: `${options.dispatch.execution.provider}-cli`,
27
- developCycle: usesDevelopCycleCompletion(options.dispatch),
28
- qaCycle: usesQaCycleCompletion(options.dispatch),
29
- debugCycle: usesDebugCycleCompletion(options.dispatch),
30
- architectCycle: usesArchitectCycleCompletion(options.dispatch),
31
- draftCycle: (phase === "draft"
32
- || options.dispatch.execution.lane.trim().toLowerCase() === "draft"
33
- || options.dispatch.cycleRun.kind.trim().toLowerCase() === "draft")
29
+ managedToolsOnly: options.managedToolsOnly,
30
+ developCycle: cycles && usesDevelopCycleCompletion(options.dispatch),
31
+ qaCycle: cycles && usesQaCycleCompletion(options.dispatch),
32
+ debugCycle: cycles && usesDebugCycleCompletion(options.dispatch),
33
+ architectCycle: cycles && usesArchitectCycleCompletion(options.dispatch),
34
+ draftCycle: cycles
35
+ && (phase === "draft"
36
+ || options.dispatch.execution.lane.trim().toLowerCase() === "draft"
37
+ || options.dispatch.cycleRun.kind.trim().toLowerCase() === "draft")
34
38
  && !isDecomposeDispatch(options.dispatch),
35
- decomposeCycle: isDecomposeDispatch(options.dispatch)
39
+ decomposeCycle: cycles && isDecomposeDispatch(options.dispatch)
36
40
  });
37
41
  const runtime = {
38
42
  serverName: toolServerName,
@@ -50,42 +54,6 @@ export async function prepareCompletionToolRuntime(options) {
50
54
  }
51
55
  return runtime;
52
56
  }
53
- export function buildCompletionToolServerArgs(config) {
54
- const args = [
55
- "mcp",
56
- "--worktree",
57
- path.resolve(config.worktreePath),
58
- "--work-item-id",
59
- config.workItemId,
60
- "--phase",
61
- config.phase,
62
- "--produced-by",
63
- config.producedBy ?? "forge-completion-tool"
64
- ];
65
- if (config.ownerType || config.ownerId) {
66
- args.push("--owner-type", normalizedOwnerType(config.ownerType) ?? "work_item");
67
- args.push("--owner-id", config.ownerId ?? config.workItemId);
68
- }
69
- if (config.developCycle) {
70
- args.push("--develop-cycle");
71
- }
72
- if (config.qaCycle) {
73
- args.push("--qa-cycle");
74
- }
75
- if (config.debugCycle) {
76
- args.push("--debug-cycle");
77
- }
78
- if (config.architectCycle) {
79
- args.push("--architect-cycle");
80
- }
81
- if (config.draftCycle) {
82
- args.push("--draft-cycle");
83
- }
84
- if (config.decomposeCycle) {
85
- args.push("--decompose-cycle");
86
- }
87
- return args;
88
- }
89
57
  export function codexMcpConfigArgs(runtime) {
90
58
  const prefix = `mcp_servers.${runtime.serverName}`;
91
59
  const args = [
@@ -133,6 +101,10 @@ export function completionToolNamesForServer(config) {
133
101
  ? completionToolNamesForPhase("architect")
134
102
  : completionToolNamesForPhase(config.phase);
135
103
  }
104
+ const managedToolsOnlyInstructions = "Forge serves only its managed-attempt tools in this turn: "
105
+ + "forge.start_managed_verification, forge.start_managed_command, forge.wait_managed_command, forge.get_managed_command, "
106
+ + "forge.run_managed_command and forge.reset_generated_outputs. No completion tool is available; the phase's completion "
107
+ + "artifacts are already recorded and must stay as they are.";
136
108
  export class CompletionToolServerSession {
137
109
  config;
138
110
  currentPhase;
@@ -146,20 +118,24 @@ export class CompletionToolServerSession {
146
118
  this.currentPhase = config.phase;
147
119
  }
148
120
  get instructions() {
149
- return this.config.decomposeCycle
150
- ? completionPromptForDecomposeCycle(this.currentDecomposeGate)
151
- : this.config.draftCycle
152
- ? completionPromptForDraftCycle(this.currentDraftGate)
153
- : this.config.debugCycle
154
- ? completionPromptForDebugCycle(asDebugCompletionPhase(this.currentPhase))
155
- : this.config.qaCycle
156
- ? completionPromptForQaCycle(this.currentQaGate, artifactOwnerRelativeRoot(this.config.ownerType, this.config.ownerId, this.config.workItemId))
157
- : this.config.developCycle
158
- ? completionPromptForDevelopCycle(this.currentPhase)
159
- : completionPromptForPhase(this.currentPhase, artifactOwnerRelativeRoot(this.config.ownerType, this.config.ownerId, this.config.workItemId));
121
+ return this.config.managedToolsOnly
122
+ ? managedToolsOnlyInstructions
123
+ : this.config.decomposeCycle
124
+ ? completionPromptForDecomposeCycle(this.currentDecomposeGate)
125
+ : this.config.draftCycle
126
+ ? completionPromptForDraftCycle(this.currentDraftGate)
127
+ : this.config.debugCycle
128
+ ? completionPromptForDebugCycle(asDebugCompletionPhase(this.currentPhase))
129
+ : this.config.qaCycle
130
+ ? completionPromptForQaCycle(this.currentQaGate, artifactOwnerRelativeRoot(this.config.ownerType, this.config.ownerId, this.config.workItemId))
131
+ : this.config.developCycle
132
+ ? completionPromptForDevelopCycle(this.currentPhase)
133
+ : completionPromptForPhase(this.currentPhase, artifactOwnerRelativeRoot(this.config.ownerType, this.config.ownerId, this.config.workItemId));
160
134
  }
161
135
  toolDefinitions() {
162
- const completionTools = completionToolNamesForServer(this.config).map(toolDefinition);
136
+ const completionTools = this.config.managedToolsOnly
137
+ ? []
138
+ : completionToolNamesForServer(this.config).map(toolDefinition);
163
139
  return managedAttemptToolsAvailable()
164
140
  ? [...completionTools, ...managedAttemptToolNames.map(managedAttemptToolDefinition)]
165
141
  : completionTools;
@@ -176,6 +152,9 @@ export class CompletionToolServerSession {
176
152
  }
177
153
  return result;
178
154
  }
155
+ if (this.config.managedToolsOnly) {
156
+ throw new Error(`${toolName} is not available in this turn: Forge serves only its managed-attempt tools during a pre-publication repair turn, and the phase's completion artifacts are already recorded. Fix the failing checks and stop; Bridge reruns validation.`);
157
+ }
179
158
  const requestedPhase = phaseFromToolName(toolName);
180
159
  // Clients sometimes send a declared array/object argument as its JSON text.
181
160
  const input = coerceJsonStringArguments(rawInput, completionToolInputSchema(toolName));
@@ -491,7 +470,7 @@ export function completionToolRuntimeEnvironment(runtimeEnvironment, nativeTestP
491
470
  env[name] = value.trim();
492
471
  }
493
472
  // Managed verification reads the operator's native test cluster only through
494
- // this explicit path, and only while Docker is unavailable.
473
+ // this explicit path; the file's `use` decides whether Docker comes first.
495
474
  if (runtimeEnvironment && nativeTestPostgresFallbackPath) {
496
475
  env[nativeTestPostgresFallbackConfigEnvironment] = nativeTestPostgresFallbackPath;
497
476
  }
@@ -599,115 +578,6 @@ export async function runCompletionMcpServer(config) {
599
578
  }
600
579
  });
601
580
  }
602
- export function parseCompletionMcpArgs(argv) {
603
- let worktreePath = null;
604
- let workItemId = null;
605
- let phase = "implementation";
606
- let ownerType;
607
- let ownerId;
608
- let producedBy;
609
- let developCycle = false;
610
- let qaCycle = false;
611
- let debugCycle = false;
612
- let architectCycle = false;
613
- let draftCycle = false;
614
- let decomposeCycle = false;
615
- for (let index = 1; index < argv.length; index += 1) {
616
- const arg = argv[index];
617
- if (arg === "--worktree") {
618
- worktreePath = argv[++index] ?? null;
619
- }
620
- else if (arg === "--work-item-id") {
621
- workItemId = argv[++index] ?? null;
622
- }
623
- else if (arg === "--owner-type") {
624
- ownerType = normalizedOwnerType(argv[++index]);
625
- if (!ownerType) {
626
- return { ok: false, error: "mcp --owner-type must be work_item or story." };
627
- }
628
- }
629
- else if (arg === "--owner-id") {
630
- ownerId = argv[++index] ?? undefined;
631
- }
632
- else if (arg === "--phase") {
633
- const rawPhase = argv[++index];
634
- const parsedPhase = parseStrictCompletionPhase(rawPhase);
635
- if (!parsedPhase) {
636
- return { ok: false, error: "mcp --phase must be one of: implementation, self-review, validation, qa, architect, draft, decompose, ci-repair, comment-repair, debug-repro, debug-root-cause, debug-fix, debug-regression." };
637
- }
638
- phase = parsedPhase;
639
- }
640
- else if (arg === "--produced-by") {
641
- producedBy = argv[++index] ?? undefined;
642
- }
643
- else if (arg === "--develop-cycle") {
644
- developCycle = true;
645
- }
646
- else if (arg === "--qa-cycle") {
647
- qaCycle = true;
648
- }
649
- else if (arg === "--debug-cycle") {
650
- debugCycle = true;
651
- }
652
- else if (arg === "--architect-cycle") {
653
- architectCycle = true;
654
- }
655
- else if (arg === "--draft-cycle") {
656
- draftCycle = true;
657
- }
658
- else if (arg === "--decompose-cycle") {
659
- decomposeCycle = true;
660
- }
661
- else {
662
- return { ok: false, error: `Unknown mcp argument: ${arg}` };
663
- }
664
- }
665
- if (!worktreePath?.trim() || !workItemId?.trim()) {
666
- return { ok: false, error: "mcp requires --worktree and --work-item-id." };
667
- }
668
- if ([developCycle, qaCycle, debugCycle, architectCycle, draftCycle, decomposeCycle].filter(Boolean).length > 1) {
669
- return { ok: false, error: "mcp accepts only one cycle mode." };
670
- }
671
- if (developCycle && !isDevelopCompletionPhase(phase)) {
672
- return { ok: false, error: "mcp --develop-cycle requires --phase implementation, self-review, or validation." };
673
- }
674
- if (qaCycle && phase !== "qa") {
675
- return { ok: false, error: "mcp --qa-cycle requires --phase qa." };
676
- }
677
- if (debugCycle && !isDebugCompletionPhase(phase)) {
678
- return { ok: false, error: "mcp --debug-cycle requires --phase debug-repro, debug-root-cause, debug-fix, or debug-regression." };
679
- }
680
- if (architectCycle && phase !== "architect") {
681
- return { ok: false, error: "mcp --architect-cycle requires --phase architect." };
682
- }
683
- if (draftCycle && phase !== "draft") {
684
- return { ok: false, error: "mcp --draft-cycle requires --phase draft." };
685
- }
686
- if (decomposeCycle && phase !== "decompose") {
687
- return { ok: false, error: "mcp --decompose-cycle requires --phase decompose." };
688
- }
689
- return {
690
- ok: true,
691
- config: {
692
- worktreePath: path.resolve(worktreePath),
693
- workItemId,
694
- ownerType,
695
- ownerId,
696
- phase,
697
- producedBy,
698
- redactionSecrets: [
699
- ...parseCompletionRedactionSecrets(process.env[completionRedactionSecretsEnv]),
700
- ...attemptDatabaseCapabilitySecrets(process.env[attemptDatabaseCapabilityEnvironment]),
701
- ],
702
- developCycle,
703
- qaCycle,
704
- debugCycle,
705
- architectCycle,
706
- draftCycle,
707
- decomposeCycle
708
- }
709
- };
710
- }
711
581
  export function completionRedactionEnv(secrets) {
712
582
  const filtered = secrets.filter((secret) => secret.length > 0);
713
583
  return filtered.length > 0
@@ -1,5 +1,6 @@
1
1
  import { decomposeGateFileNames, decomposeStatuses, draftStatuses, isDebugCompletionPhase, phaseFiles, qaBlockerReasons, qaGateFileNames } from "./phase-completion.js";
2
2
  import { browserCheckSchema, qaSidecarsSchema, qaEvidenceWrapperSchema, qaGateEvidenceWrapperSchema, findingEvidenceSchema, objectToolSchema, evidenceObjectSchema, qaScopeSchema, commandEvidenceSchema, resolvedFindingSchema, acceptanceCriteriaSchema, reviewSectionSchema, reviewSectionProperties } from "./phase-completion.schema-parts.js";
3
+ import { architectNonPassProperties } from "./architect-waits.js";
3
4
  export function toolDescription(phase, qaGate = null, decomposeGate = null, draftGate = null) {
4
5
  if (qaGate) {
5
6
  return qaGate === "qa_verdict"
@@ -499,17 +500,8 @@ export function toolInputSchema(phase, qaGate = null, decomposeGate = null, draf
499
500
  report_markdown: { type: "string", description: "Human-readable Architect report. Use report as an alias only when the client cannot send report_markdown." },
500
501
  report: { type: "string", description: "Alias for report_markdown." },
501
502
  blockers: baseProperties.blockers,
502
- revision_questions: {
503
- type: "array",
504
- description: "Required for needs_revision when blockers are not used.",
505
- items: { type: "string" }
506
- },
507
- revision_reasons: {
508
- type: "array",
509
- description: "Concrete reasons that prevent pass status.",
510
- items: { type: "string" }
511
- }
512
- }, ["status", "summary"], "For status pass, include implementation_plan and qa_plan at the top level of the MCP tool arguments, as JSON objects rather than quoted strings. implementation_plan.phases must be a top-level array inside implementation_plan, not nested under another object. For needs_revision or blocked, implementation_plan and qa_plan may be omitted; include blockers, revision_questions, or revision_reasons instead.");
503
+ ...architectNonPassProperties()
504
+ }, ["status", "summary"], "For status pass, include implementation_plan and qa_plan at the top level of the MCP tool arguments, as JSON objects rather than quoted strings. implementation_plan.phases must be a top-level array inside implementation_plan, not nested under another object. For needs_revision or blocked, implementation_plan and qa_plan may be omitted; include blockers, revision_questions, or revision_reasons instead. When blocked because another Story or pull request must merge first, also list it in waits_on; when the owner must choose, also set owner_decision.");
513
505
  }
514
506
  return objectToolSchema({
515
507
  ...baseProperties,
@@ -536,6 +528,27 @@ export function toolInputSchema(phase, qaGate = null, decomposeGate = null, draf
536
528
  ready_for_dev_test: { type: "boolean", default: true, description: "Required for pass and must be true." }
537
529
  }, ["status", "summary"], "For status pass, commands must include at least one passing deterministic command, acceptance criteria entries must use status: satisfied plus evidence, and ready_for_dev_test must be true.");
538
530
  }
531
+ // Feature-to-Story candidate fields: schedule order, handoff to dependents, and whether the Story
532
+ // needs a design reference before Forge builds it.
533
+ const storyCandidateScheduleProperties = {
534
+ scheduleIndex: { type: "number", description: "Feature-to-Story total schedule order for dependency-safe execution." },
535
+ schedule_index: { type: "number", description: "Snake_case alias for scheduleIndex." },
536
+ waveIndex: { type: "number", description: "Feature-to-Story parallel wave number." },
537
+ wave_index: { type: "number", description: "Snake_case alias for waveIndex." },
538
+ featureScheduleIndex: { type: "number", description: "Optional ordering within the Feature." },
539
+ feature_schedule_index: { type: "number", description: "Snake_case alias for featureScheduleIndex." },
540
+ expectedOutput: { type: "string", description: "Durable output this Story should produce for dependents." },
541
+ expected_output: { type: "string", description: "Snake_case alias for expectedOutput." },
542
+ handoffSummary: { type: "string", description: "How dependent Stories should consume this Story output." },
543
+ handoff_summary: { type: "string", description: "Snake_case alias for handoffSummary." },
544
+ dependencyReason: { type: "string", description: "Why this Story depends on its dependsOn predecessors." },
545
+ dependency_reason: { type: "string", description: "Snake_case alias for dependencyReason." },
546
+ requiresDesign: {
547
+ type: "boolean",
548
+ description: "Feature-to-Story only. True when the Story adds or changes user-visible UI; Forge holds it until a design reference is attached. False for non-visual Stories."
549
+ },
550
+ requires_design: { type: "boolean", description: "Snake_case alias for requiresDesign." }
551
+ };
539
552
  function decomposeGateToolInputSchema(gate, phaseProperties) {
540
553
  // Advertise every status the Decompose writer accepts, so the schema and the runtime agree.
541
554
  const baseProperties = {
@@ -572,18 +585,7 @@ function decomposeGateToolInputSchema(gate, phaseProperties) {
572
585
  acceptanceCriteria: { type: "string" },
573
586
  planningPacket: { type: "string" },
574
587
  sortOrder: { type: "number" },
575
- scheduleIndex: { type: "number", description: "Feature-to-Story total schedule order for dependency-safe execution." },
576
- schedule_index: { type: "number", description: "Snake_case alias for scheduleIndex." },
577
- waveIndex: { type: "number", description: "Feature-to-Story parallel wave number." },
578
- wave_index: { type: "number", description: "Snake_case alias for waveIndex." },
579
- featureScheduleIndex: { type: "number", description: "Optional ordering within the Feature." },
580
- feature_schedule_index: { type: "number", description: "Snake_case alias for featureScheduleIndex." },
581
- expectedOutput: { type: "string", description: "Durable output this Story should produce for dependents." },
582
- expected_output: { type: "string", description: "Snake_case alias for expectedOutput." },
583
- handoffSummary: { type: "string", description: "How dependent Stories should consume this Story output." },
584
- handoff_summary: { type: "string", description: "Snake_case alias for handoffSummary." },
585
- dependencyReason: { type: "string", description: "Why this Story depends on its dependsOn predecessors." },
586
- dependency_reason: { type: "string", description: "Snake_case alias for dependencyReason." },
588
+ ...storyCandidateScheduleProperties,
587
589
  points: { type: "number" },
588
590
  dependsOn: { type: "array", items: { type: "string" } },
589
591
  estimatedQaScope: qaScopeSchema("Work Order-to-Feature planning QA estimate. This is not dispatch-authoritative QA scope."),
@@ -1,5 +1,6 @@
1
1
  import { qaBlockerReasons, qaCandidateBugActions, qaFindingScopes, qaFindingSeverities, qaGateToolNames, qaScopeAuthorities, qaScopeCapabilities, qaScopeConfidence, qaScopeEvidence, qaScopeFields, qaScopeSources, qaScopeSurfaces } from "./phase-completion.js";
2
2
  import { structuredTypeHint } from "./mcp-argument-coercion.js";
3
+ import { validateArchitectWaits } from "./architect-waits.js";
3
4
  import { validateQaGatePassingCommands } from "./phase-completion.command-validation.js";
4
5
  export { validateQaGatePassingCommands } from "./phase-completion.command-validation.js";
5
6
  export const qaEvidenceGates = new Set(["qa_regression", "qa_api", "qa_manual_web", "qa_bug_repro"]);
@@ -353,6 +354,7 @@ export function validateQaGatePayloadShape(gate, payload, status) {
353
354
  }
354
355
  }
355
356
  export function validateArchitectPayloadShape(payload, status) {
357
+ validateArchitectWaits(payload, status);
356
358
  if (status !== "pass") {
357
359
  requireArchitectNonPassEvidence(payload);
358
360
  return;
@@ -706,7 +708,7 @@ export function hasArchitectDependencyCycle(edges) {
706
708
  return false;
707
709
  }
708
710
  export function requireArchitectNonPassEvidence(payload) {
709
- const evidenceKeys = ["blockers", "revision_questions", "revision_reasons", "known_gaps", "findings", "remaining_risks", "failures"];
711
+ const evidenceKeys = ["blockers", "revision_questions", "revision_reasons", "waits_on", "owner_decision", "known_gaps", "findings", "remaining_risks", "failures"];
710
712
  const hasEvidence = evidenceKeys.some((key) => {
711
713
  const value = payload[key];
712
714
  if (typeof value === "string") {
@@ -0,0 +1,30 @@
1
+ import type { DockerEngineProbe } from "../runtime/docker-engine-probe.js";
2
+ import { startEphemeralTestPostgresGrant } from "../runtime/ephemeral-test-postgres-grant.js";
3
+ import { type NativeTestPostgresFallback, type NativeTestPostgresGrant } from "../runtime/native-test-postgres-fallback.js";
4
+ import type { RunnerDispatchEvent } from "./session.types.js";
5
+ /**
6
+ * A provisioned native test cluster whose file prefers it serves this check's shared
7
+ * test server without waiting on Docker (owner policy 2026-11-16: native PostgreSQL
8
+ * first). Docker is still probed, never recovered, so the fixtures know whether
9
+ * pinned-engine tests can start their own containers. An unreadable file leaves the
10
+ * check on Docker.
11
+ */
12
+ export declare function preferredNativeTestPostgres(checkId: string, requiredPrerequisite: string | undefined, readCluster: () => NativeTestPostgresFallback | null, dockerEngineProbe: DockerEngineProbe | undefined, emit?: (event: RunnerDispatchEvent) => Promise<void>, startEphemeral?: typeof startEphemeralTestPostgresGrant): Promise<NativeTestPostgresGrant | undefined>;
13
+ /** Whether this check already has its isolated PostgreSQL without Docker. */
14
+ export declare function isolatedPostgresProvided(checkId: string, environment?: Readonly<Record<string, string>>, postgresAdminConnection?: NativeTestPostgresGrant): boolean;
15
+ /**
16
+ * The grant, when it makes its check Docker-free. A native_preferred grant still lets
17
+ * pinned-engine tests start Docker containers, so a Docker loss during its check stays
18
+ * retryable infrastructure; only a native_fallback grant (Docker was already down) does not.
19
+ */
20
+ export declare function dockerFreeGrant(grant: NativeTestPostgresGrant | undefined): NativeTestPostgresGrant | undefined;
21
+ /**
22
+ * Releases a check's ephemeral cluster once the check has ended. A cluster that would not stop
23
+ * is left disowned for the next start's reap and does not change the check's own result.
24
+ */
25
+ export declare function releaseCheckPostgres(checkId: string, grant: NativeTestPostgresGrant | undefined, emit?: (event: RunnerDispatchEvent) => Promise<void>): Promise<void>;
26
+ /** The native cluster grant for a check while Docker stays down, or null when it cannot use one. */
27
+ export declare function dockerUnavailableNativeTestPostgres(checkId: string, requiredPrerequisite: string | undefined, readCluster: () => NativeTestPostgresFallback | null): NativeTestPostgresGrant | null;
28
+ export type { NativeTestPostgresFallback, NativeTestPostgresGrant };
29
+ /** Starts a check's ephemeral cluster; injectable so tests need no PostgreSQL install. */
30
+ export type StartEphemeralTestPostgresGrant = typeof startEphemeralTestPostgresGrant;