@loucompanion/forge-bridge 0.1.4-dev.24bdf60b0b53 → 0.1.4-dev.297b5afcac9e

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 (201) hide show
  1. package/README.md +57 -2
  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.base.d.ts +9 -0
  7. package/dist/bridge/bridge.service.d.ts +85 -3
  8. package/dist/bridge/bridge.service.js +361 -122
  9. package/dist/bridge/bridge.types.d.ts +22 -0
  10. package/dist/bridge/dispatch-result-outbox.d.ts +11 -1
  11. package/dist/bridge/dispatch-result-outbox.js +31 -6
  12. package/dist/bridge/local-yield-flag.d.ts +6 -0
  13. package/dist/bridge/local-yield-flag.js +34 -0
  14. package/dist/bridge/runner-host-capabilities.d.ts +5 -0
  15. package/dist/bridge/runner-host-capabilities.js +17 -0
  16. package/dist/bridge/test-postgres-capability.d.ts +14 -0
  17. package/dist/bridge/test-postgres-capability.js +120 -0
  18. package/dist/cleanup/cleanup.service.d.ts +9 -0
  19. package/dist/cleanup/cleanup.service.js +72 -109
  20. package/dist/cleanup/cleanup.types.d.ts +4 -0
  21. package/dist/cleanup/forge-owned-paths.d.ts +9 -0
  22. package/dist/cleanup/forge-owned-paths.js +53 -0
  23. package/dist/cleanup/host-runtime-ledger.d.ts +5 -0
  24. package/dist/cleanup/host-runtime-ledger.js +109 -0
  25. package/dist/cleanup/managed-branch-sweep.d.ts +27 -0
  26. package/dist/cleanup/managed-branch-sweep.js +111 -0
  27. package/dist/cli/cli.help.js +18 -0
  28. package/dist/cli/cli.service.d.ts +16 -0
  29. package/dist/cli/cli.service.js +142 -16
  30. package/dist/cli/local-config.d.ts +4 -0
  31. package/dist/cli/local-config.js +26 -4
  32. package/dist/runtime/aspnet-runtime-prebuild.d.ts +5 -0
  33. package/dist/runtime/aspnet-runtime-prebuild.js +138 -6
  34. package/dist/runtime/attempt-database-broker.d.ts +1 -1
  35. package/dist/runtime/docker-engine-probe.d.ts +5 -0
  36. package/dist/runtime/docker-engine-probe.js +7 -0
  37. package/dist/runtime/ephemeral-test-postgres-grant.d.ts +37 -0
  38. package/dist/runtime/ephemeral-test-postgres-grant.js +85 -0
  39. package/dist/runtime/ephemeral-test-postgres.d.ts +57 -0
  40. package/dist/runtime/ephemeral-test-postgres.js +303 -0
  41. package/dist/runtime/host-database-capability-boundary.d.ts +1 -1
  42. package/dist/runtime/host-database-capability-boundary.js +1 -0
  43. package/dist/runtime/host-facts.d.ts +36 -0
  44. package/dist/runtime/host-facts.js +95 -0
  45. package/dist/runtime/host-load-admission.d.ts +67 -0
  46. package/dist/runtime/host-load-admission.js +99 -0
  47. package/dist/runtime/host-load-child-environment.d.ts +27 -0
  48. package/dist/runtime/host-load-child-environment.js +76 -0
  49. package/dist/runtime/host-load-forge-cgroups.d.ts +49 -0
  50. package/dist/runtime/host-load-forge-cgroups.js +140 -0
  51. package/dist/runtime/host-load-governor-config.d.ts +52 -0
  52. package/dist/runtime/host-load-governor-config.js +83 -0
  53. package/dist/runtime/host-load-governor.d.ts +184 -0
  54. package/dist/runtime/host-load-governor.js +632 -0
  55. package/dist/runtime/host-load-ledger-lock.d.ts +69 -0
  56. package/dist/runtime/host-load-ledger-lock.js +185 -0
  57. package/dist/runtime/host-load-runtime-settings.d.ts +25 -0
  58. package/dist/runtime/host-load-runtime-settings.js +78 -0
  59. package/dist/runtime/host-load-sampler.d.ts +156 -0
  60. package/dist/runtime/host-load-sampler.js +298 -0
  61. package/dist/runtime/host-load-step-class.d.ts +70 -0
  62. package/dist/runtime/host-load-step-class.js +161 -0
  63. package/dist/runtime/host-load-step-reaper.d.ts +27 -0
  64. package/dist/runtime/host-load-step-reaper.js +95 -0
  65. package/dist/runtime/host-load-step-run.d.ts +73 -0
  66. package/dist/runtime/host-load-step-run.js +102 -0
  67. package/dist/runtime/host-load-test-slot.d.ts +43 -0
  68. package/dist/runtime/host-load-test-slot.js +81 -0
  69. package/dist/runtime/host-load-token-ledger.d.ts +200 -0
  70. package/dist/runtime/host-load-token-ledger.js +453 -0
  71. package/dist/runtime/host-load-windows-cpu.d.ts +34 -0
  72. package/dist/runtime/host-load-windows-cpu.js +85 -0
  73. package/dist/runtime/host-pressure-stall.d.ts +61 -0
  74. package/dist/runtime/host-pressure-stall.js +168 -0
  75. package/dist/runtime/host-runtime-contract.d.ts +16 -0
  76. package/dist/runtime/host-runtime-contract.js +35 -2
  77. package/dist/runtime/host-runtime-lease.d.ts +74 -4
  78. package/dist/runtime/host-runtime-lease.js +285 -55
  79. package/dist/runtime/host-runtime-promotion.d.ts +23 -0
  80. package/dist/runtime/host-runtime-promotion.js +48 -0
  81. package/dist/runtime/host-runtime-requirements-check.d.ts +17 -0
  82. package/dist/runtime/host-runtime-requirements-check.js +29 -0
  83. package/dist/runtime/host-runtime-requirements.d.ts +36 -0
  84. package/dist/runtime/host-runtime-requirements.js +117 -0
  85. package/dist/runtime/native-test-postgres-fallback.d.ts +51 -7
  86. package/dist/runtime/native-test-postgres-fallback.js +60 -8
  87. package/dist/runtime/playwright-host-runtime-adapter.d.ts +7 -0
  88. package/dist/runtime/playwright-host-runtime-adapter.js +13 -1
  89. package/dist/runtime/runner-settings.d.ts +100 -0
  90. package/dist/runtime/runner-settings.js +214 -0
  91. package/dist/sandbox/host-capacity-broker.d.ts +113 -0
  92. package/dist/sandbox/host-capacity-broker.js +334 -0
  93. package/dist/sandbox/runtime.d.ts +10 -1
  94. package/dist/sandbox/runtime.js +45 -2
  95. package/dist/sandbox/sandbox-cgroups.d.ts +14 -0
  96. package/dist/sandbox/sandbox-cgroups.js +42 -0
  97. package/dist/session/architect-waits.d.ts +2 -0
  98. package/dist/session/architect-waits.js +138 -0
  99. package/dist/session/managed-attempt-tools.d.ts +2 -7
  100. package/dist/session/managed-attempt-tools.js +200 -92
  101. package/dist/session/managed-command-host-load.d.ts +47 -0
  102. package/dist/session/managed-command-host-load.js +83 -0
  103. package/dist/session/mcp-argument-coercion.d.ts +23 -0
  104. package/dist/session/mcp-argument-coercion.js +121 -0
  105. package/dist/session/phase-completion.artifacts.d.ts +7 -0
  106. package/dist/session/phase-completion.artifacts.js +100 -26
  107. package/dist/session/phase-completion.command-validation.d.ts +7 -0
  108. package/dist/session/phase-completion.command-validation.js +77 -0
  109. package/dist/session/phase-completion.d.ts +12 -0
  110. package/dist/session/phase-completion.helpers.js +13 -12
  111. package/dist/session/phase-completion.js +5 -0
  112. package/dist/session/phase-completion.mcp-args.d.ts +9 -0
  113. package/dist/session/phase-completion.mcp-args.js +156 -0
  114. package/dist/session/phase-completion.prompts.js +6 -1
  115. package/dist/session/phase-completion.runtime.d.ts +5 -11
  116. package/dist/session/phase-completion.runtime.js +86 -186
  117. package/dist/session/phase-completion.schema-parts.d.ts +19 -0
  118. package/dist/session/phase-completion.schema-parts.js +188 -0
  119. package/dist/session/phase-completion.schemas.d.ts +3 -3
  120. package/dist/session/phase-completion.schemas.js +208 -231
  121. package/dist/session/phase-completion.validation.d.ts +2 -3
  122. package/dist/session/phase-completion.validation.js +49 -93
  123. package/dist/session/pre-publication-host-load.d.ts +27 -0
  124. package/dist/session/pre-publication-host-load.js +111 -0
  125. package/dist/session/pre-publication-native-postgres.d.ts +30 -0
  126. package/dist/session/pre-publication-native-postgres.js +111 -0
  127. package/dist/session/pre-publication-pass.d.ts +61 -0
  128. package/dist/session/pre-publication-pass.js +148 -0
  129. package/dist/session/pre-publication-process.d.ts +3 -0
  130. package/dist/session/pre-publication-process.js +25 -12
  131. package/dist/session/pre-publication-skipped-tests.d.ts +21 -0
  132. package/dist/session/pre-publication-skipped-tests.js +109 -0
  133. package/dist/session/pre-publication-step-execution.d.ts +12 -0
  134. package/dist/session/pre-publication-step-execution.js +50 -0
  135. package/dist/session/pre-publication-validation.d.ts +37 -21
  136. package/dist/session/pre-publication-validation.js +224 -166
  137. package/dist/session/provider-cli/claude-background-work.d.ts +66 -0
  138. package/dist/session/provider-cli/claude-background-work.js +180 -0
  139. package/dist/session/provider-cli/pre-publication-repair.d.ts +56 -0
  140. package/dist/session/provider-cli/pre-publication-repair.js +276 -0
  141. package/dist/session/provider-cli/provider-cli.artifacts.d.ts +2 -1
  142. package/dist/session/provider-cli/provider-cli.artifacts.js +21 -15
  143. package/dist/session/provider-cli/provider-cli.child-environment.d.ts +7 -0
  144. package/dist/session/provider-cli/provider-cli.child-environment.js +73 -0
  145. package/dist/session/provider-cli/provider-cli.codex-models-cache.d.ts +3 -0
  146. package/dist/session/provider-cli/provider-cli.codex-models-cache.js +37 -0
  147. package/dist/session/provider-cli/provider-cli.merge-integrity.d.ts +89 -0
  148. package/dist/session/provider-cli/provider-cli.merge-integrity.js +310 -0
  149. package/dist/session/provider-cli/provider-cli.process.d.ts +41 -31
  150. package/dist/session/provider-cli/provider-cli.process.js +139 -438
  151. package/dist/session/provider-cli/provider-cli.prompts.d.ts +10 -0
  152. package/dist/session/provider-cli/provider-cli.prompts.js +78 -10
  153. package/dist/session/provider-cli/provider-cli.runtime.js +7 -0
  154. package/dist/session/provider-cli/provider-cli.service.d.ts +7 -1
  155. package/dist/session/provider-cli/provider-cli.service.js +195 -183
  156. package/dist/session/provider-cli/provider-cli.types.d.ts +30 -0
  157. package/dist/session/provider-cli/provider-cli.windows-environment.d.ts +10 -0
  158. package/dist/session/provider-cli/provider-cli.windows-environment.js +151 -0
  159. package/dist/session/provider-cli/provider-cli.windows-launch.d.ts +23 -0
  160. package/dist/session/provider-cli/provider-cli.windows-launch.js +131 -0
  161. package/dist/session/provider-cli/provider-in-flight-work.d.ts +10 -0
  162. package/dist/session/provider-cli/provider-in-flight-work.js +92 -0
  163. package/dist/session/provider-cli/provider-output-pipes.d.ts +30 -0
  164. package/dist/session/provider-cli/provider-output-pipes.js +67 -0
  165. package/dist/session/provider-cli/provider-output-state.d.ts +8 -0
  166. package/dist/session/provider-cli/provider-output-state.js +15 -0
  167. package/dist/session/publishable-worktree-changes.d.ts +54 -0
  168. package/dist/session/publishable-worktree-changes.js +193 -0
  169. package/dist/session/qa-sidecar-validation.d.ts +6 -0
  170. package/dist/session/qa-sidecar-validation.js +28 -0
  171. package/dist/session/sandbox-host-capacity-gate.d.ts +30 -0
  172. package/dist/session/sandbox-host-capacity-gate.js +238 -0
  173. package/dist/session/session-redaction.js +31 -181
  174. package/dist/session/session.base.d.ts +9 -1
  175. package/dist/session/session.service.d.ts +9 -2
  176. package/dist/session/session.service.js +120 -5
  177. package/dist/session/session.types.d.ts +3 -0
  178. package/dist/session/session.types.js +15 -3
  179. package/dist/session/sidecar-json-shape.d.ts +31 -0
  180. package/dist/session/sidecar-json-shape.js +217 -0
  181. package/dist/session/workspace-runtime-fingerprint.d.ts +32 -0
  182. package/dist/session/workspace-runtime-fingerprint.js +138 -0
  183. package/dist/shared/process/host-process-supervisor.d.ts +1 -0
  184. package/dist/shared/process/host-process-supervisor.js +1 -1
  185. package/dist/shared/process/process-tree.d.ts +52 -0
  186. package/dist/shared/process/process-tree.js +144 -0
  187. package/dist/shared/process/process.d.ts +67 -0
  188. package/dist/shared/process/process.js +213 -11
  189. package/dist/shared/process/windows-app-execution-alias.d.ts +19 -0
  190. package/dist/shared/process/windows-app-execution-alias.js +45 -0
  191. package/dist/shared/process/windows-launch.d.ts +18 -0
  192. package/dist/shared/process/windows-launch.js +68 -0
  193. package/dist/shared/provider-capabilities.js +5 -6
  194. package/dist/version.d.ts +1 -1
  195. package/dist/version.js +1 -1
  196. package/dist/worktree/dependency-warmer.d.ts +25 -0
  197. package/dist/worktree/dependency-warmer.js +46 -10
  198. package/dist/worktree/worktree.service.d.ts +10 -1
  199. package/dist/worktree/worktree.service.js +42 -2
  200. package/dist/worktree/worktree.types.d.ts +7 -0
  201. package/package.json +2 -2
@@ -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
+ }
@@ -76,6 +76,7 @@ Complete the Draft cycle in order inside this same provider session:
76
76
  5. Follow the returned draft-plan instruction, draft the requested final JSON shape for the current Draft kind, then call \`forge.complete_draft_work_order_plan(...)\`.
77
77
  6. Follow the returned critic instruction, critique literalism, wrong-project scope, and decomposition quality, then call \`forge.complete_draft_critic(...)\`.
78
78
  7. Follow the returned proposal instruction, then call \`forge.complete_draft_proposal(...)\` with the final Draft JSON payload in \`draft_json\`.
79
+ Every gate before the proposal needs a \`summary\` of what it checked or decided.
79
80
  The final proposal tool writes \`draft.proposal.json\` under \`.forge/work-items/{workItemId}/artifacts/\`. Reporting Draft completion in prose is not enough.`;
80
81
  }
81
82
  export function completionPromptForDecomposeCycle(currentGate = "decompose_subject_intake") {
@@ -92,6 +93,7 @@ Required order:
92
93
  5. Follow the returned dependency-graph instruction, validate keys/dependencies/order, then call \`forge.complete_decompose_dependency_graph(...)\`.
93
94
  6. Follow the returned critic instruction, critique scope, DAG safety, manual reconciliation risk, and missing acceptance detail, then call \`forge.complete_decompose_critic(...)\`.
94
95
  7. Follow the returned proposal instruction, then call \`forge.complete_decompose_proposal(...)\` with final JSON in \`proposal_json\`.
96
+ Every gate before the proposal needs a \`summary\` of what it checked or decided.
95
97
  The final proposal tool writes \`decompose.proposal.json\` under \`.forge/work-items/{workItemId}/artifacts/\`. The proposal_json object must contain summary, optional blockedReason, and candidates. Work Order-to-Feature candidates may include \`estimated_qa_scope\`; Feature-to-Story candidates should include \`qa_scope\` with schema_version 1 plus scheduleIndex, waveIndex, expectedOutput, handoffSummary, and dependencyReason for dependency handoff. Set \`qa_scope.required_capabilities\` to \`["docker_engine"]\` when implementation or validation starts containers or needs a Docker daemon; repository-specific service and image versions do not belong in the runner capability name.`;
96
98
  }
97
99
  export function completionPromptForDebugCycle(currentGate = "debug_repro") {
@@ -144,6 +146,9 @@ export function completionToolNextInstructionForDraftGate(completedGate, status,
144
146
  if (status === "blocked") {
145
147
  return `Stay in ${completedGate}; record the blocker and retry the same Draft gate when unblocked.`;
146
148
  }
149
+ if (status !== "pass") {
150
+ return `Stay in ${completedGate}; revise the work and call the same Draft gate again with status pass when it is complete.`;
151
+ }
147
152
  if (!nextGate) {
148
153
  return "Draft proposal accepted. Forge has the structured Work Order draft JSON needed to populate the form.";
149
154
  }
@@ -216,7 +221,7 @@ export function completionToolNextInstructionForDebugGate(completedGate, status,
216
221
  function qaGateInstruction(gate) {
217
222
  switch (gate) {
218
223
  case "qa_regression":
219
- return "Run or explicitly skip applicable regression/build/lint/typecheck/e2e checks, then call forge.complete_qa_regression. For normal Story QA, prefer focused checks and runner-authored forge.start_managed_verification tier profiles; reserve dotnet_solution for shared infrastructure, Feature/PR integration, or an explicit plan requirement. Use forge.start_managed_command only for other commands expected to exceed two minutes, continue independent QA, then call forge.wait_managed_command and include its terminal managed_command_id in command evidence. If the wait returns command_continues=true, continue useful work or wait again after retry_after_ms; do not poll get_managed_command. Normalize negative assertions so an expected no-match exits 0. A reproduced failure outside the current diff and acceptance criteria may remain non-blocking only when the current item has independent passing evidence: preserve it as an out_of_scope_failure with candidate_bug_id, scope_evidence, acceptance_criteria_independent: true, and a failing focused repro command/exit code. Never classify an unexplained, in-scope, or infrastructure failure this way.";
224
+ return "Run or explicitly skip applicable regression/build/lint/typecheck/e2e checks, then call forge.complete_qa_regression. For normal Story QA, prefer focused checks and runner-authored forge.start_managed_verification .NET tier profiles (run_all_shards needs shard_count of at least 2 and no no_build); run Playwright e2e through forge.start_managed_command with the attempt's FORGE_PLAYWRIGHT_CONFIG and the spec files you need; reserve dotnet_solution for shared infrastructure, Feature/PR integration, or an explicit plan requirement. Use forge.start_managed_command only for other commands expected to exceed two minutes, continue independent QA, then call forge.wait_managed_command and include its terminal managed_command_id in command evidence. If the wait returns command_continues=true, continue useful work or wait again after retry_after_ms; do not poll get_managed_command. Normalize negative assertions so an expected no-match exits 0. A reproduced failure outside the current diff and acceptance criteria may remain non-blocking only when the current item has independent passing evidence: preserve it as an out_of_scope_failure with candidate_bug_id, scope_evidence, acceptance_criteria_independent: true, and a failing focused repro command/exit code. Never classify an unexplained, in-scope, or infrastructure failure this way.";
220
225
  case "qa_api":
221
226
  return "Run or explicitly skip applicable API/backend contract checks, then call forge.complete_qa_api.";
222
227
  case "qa_manual_web":
@@ -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;
@@ -17,7 +16,7 @@ export declare class CompletionToolServerSession {
17
16
  constructor(config: CompletionToolServerConfig);
18
17
  get instructions(): string;
19
18
  toolDefinitions(): readonly unknown[];
20
- callTool(toolName: string, input: unknown): Promise<CompletionToolCallResult | ManagedAttemptToolResult>;
19
+ callTool(toolName: string, rawInput: unknown): Promise<CompletionToolCallResult | ManagedAttemptToolResult>;
21
20
  private callDecomposeGateTool;
22
21
  private callDraftGateTool;
23
22
  private callDebugGateTool;
@@ -28,7 +27,7 @@ export declare class CompletionToolServerSession {
28
27
  private advanceAfterQaGate;
29
28
  private advanceAfterDebugGate;
30
29
  }
31
- export declare function completionToolRuntimeEnvironment(runtimeEnvironment?: Readonly<Record<string, string>>, nativeTestPostgresFallbackPath?: string | null): Readonly<Record<string, string>>;
30
+ export declare function completionToolRuntimeEnvironment(runtimeEnvironment?: Readonly<Record<string, string>>, nativeTestPostgresFallbackPath?: string | null, hostLoadEnvironment?: Readonly<Record<string, string>>): Readonly<Record<string, string>>;
32
31
  /**
33
32
  * A solution-wide Forge test is long enough that a generic provider shell can
34
33
  * expire while VSTest is still healthy. On managed host attempts, only the
@@ -38,12 +37,7 @@ 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
- export declare function completionToolRejectedResult(toolName: string, error: unknown): Readonly<Record<string, unknown>>;
41
+ export declare function completionToolRejectedResult(toolName: string, error: unknown, input?: unknown): Readonly<Record<string, unknown>>;
42
+ /** The input schema a completion tool advertises; also the shape its arguments are coerced to. */
43
+ export declare function completionToolInputSchema(name: string): unknown;
@@ -1,20 +1,24 @@
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";
8
+ import { isHostLoadChildEnvironmentName } from "../runtime/host-load-child-environment.js";
9
9
  import { toolDescription, toolInputSchema } from "./phase-completion.schemas.js";
10
+ import { coerceJsonStringArguments, emptyToolInputHint, isEmptyToolInput } from "./mcp-argument-coercion.js";
10
11
  import { writeCompletionArtifact, writeDecomposeGateCompletionArtifact, writeDraftGateCompletionArtifact } from "./phase-completion.artifacts.js";
11
- import { callManagedAttemptTool, isManagedAttemptTool, managedAttemptToolDefinition, managedAttemptToolNames, runWithOwnerShutdown, } from "./managed-attempt-tools.js";
12
+ import { buildCompletionToolServerArgs } from "./phase-completion.mcp-args.js";
13
+ import { callManagedAttemptTool, isManagedAttemptTool, managedAttemptToolDefinition, managedAttemptToolInputSchema, managedAttemptToolNames, runWithOwnerShutdown, } from "./managed-attempt-tools.js";
12
14
  export async function prepareCompletionToolRuntime(options) {
13
15
  const phase = options.phase ?? completionPhaseFromDispatch(options.dispatch);
14
16
  const worktreePath = path.resolve(options.worktree.worktreePath);
15
17
  const workItemId = options.dispatch.workItem.id;
16
18
  const ownerType = normalizedOwnerType(options.dispatch.cycleRun.ownerType) ?? "work_item";
17
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;
18
22
  const mcpArgs = buildCompletionToolServerArgs({
19
23
  worktreePath,
20
24
  workItemId,
@@ -22,21 +26,23 @@ export async function prepareCompletionToolRuntime(options) {
22
26
  ownerId,
23
27
  phase,
24
28
  producedBy: `${options.dispatch.execution.provider}-cli`,
25
- developCycle: usesDevelopCycleCompletion(options.dispatch),
26
- qaCycle: usesQaCycleCompletion(options.dispatch),
27
- debugCycle: usesDebugCycleCompletion(options.dispatch),
28
- architectCycle: usesArchitectCycleCompletion(options.dispatch),
29
- draftCycle: (phase === "draft"
30
- || options.dispatch.execution.lane.trim().toLowerCase() === "draft"
31
- || 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")
32
38
  && !isDecomposeDispatch(options.dispatch),
33
- decomposeCycle: isDecomposeDispatch(options.dispatch)
39
+ decomposeCycle: cycles && isDecomposeDispatch(options.dispatch)
34
40
  });
35
41
  const runtime = {
36
42
  serverName: toolServerName,
37
43
  command: process.execPath,
38
44
  args: [forgeBridgeCliBinPath(), ...mcpArgs],
39
- env: completionToolRuntimeEnvironment(options.runtimeEnvironment, configuredNativeTestPostgresFallbackPath()),
45
+ env: completionToolRuntimeEnvironment(options.runtimeEnvironment, configuredNativeTestPostgresFallbackPath(), options.hostLoadEnvironment),
40
46
  cleanup: async () => undefined
41
47
  };
42
48
  const provider = options.dispatch.execution.provider.trim().toLowerCase();
@@ -48,42 +54,6 @@ export async function prepareCompletionToolRuntime(options) {
48
54
  }
49
55
  return runtime;
50
56
  }
51
- export function buildCompletionToolServerArgs(config) {
52
- const args = [
53
- "mcp",
54
- "--worktree",
55
- path.resolve(config.worktreePath),
56
- "--work-item-id",
57
- config.workItemId,
58
- "--phase",
59
- config.phase,
60
- "--produced-by",
61
- config.producedBy ?? "forge-completion-tool"
62
- ];
63
- if (config.ownerType || config.ownerId) {
64
- args.push("--owner-type", normalizedOwnerType(config.ownerType) ?? "work_item");
65
- args.push("--owner-id", config.ownerId ?? config.workItemId);
66
- }
67
- if (config.developCycle) {
68
- args.push("--develop-cycle");
69
- }
70
- if (config.qaCycle) {
71
- args.push("--qa-cycle");
72
- }
73
- if (config.debugCycle) {
74
- args.push("--debug-cycle");
75
- }
76
- if (config.architectCycle) {
77
- args.push("--architect-cycle");
78
- }
79
- if (config.draftCycle) {
80
- args.push("--draft-cycle");
81
- }
82
- if (config.decomposeCycle) {
83
- args.push("--decompose-cycle");
84
- }
85
- return args;
86
- }
87
57
  export function codexMcpConfigArgs(runtime) {
88
58
  const prefix = `mcp_servers.${runtime.serverName}`;
89
59
  const args = [
@@ -131,6 +101,10 @@ export function completionToolNamesForServer(config) {
131
101
  ? completionToolNamesForPhase("architect")
132
102
  : completionToolNamesForPhase(config.phase);
133
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.";
134
108
  export class CompletionToolServerSession {
135
109
  config;
136
110
  currentPhase;
@@ -144,36 +118,46 @@ export class CompletionToolServerSession {
144
118
  this.currentPhase = config.phase;
145
119
  }
146
120
  get instructions() {
147
- return this.config.decomposeCycle
148
- ? completionPromptForDecomposeCycle(this.currentDecomposeGate)
149
- : this.config.draftCycle
150
- ? completionPromptForDraftCycle(this.currentDraftGate)
151
- : this.config.debugCycle
152
- ? completionPromptForDebugCycle(asDebugCompletionPhase(this.currentPhase))
153
- : this.config.qaCycle
154
- ? completionPromptForQaCycle(this.currentQaGate, artifactOwnerRelativeRoot(this.config.ownerType, this.config.ownerId, this.config.workItemId))
155
- : this.config.developCycle
156
- ? completionPromptForDevelopCycle(this.currentPhase)
157
- : 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));
158
134
  }
159
135
  toolDefinitions() {
160
- const completionTools = completionToolNamesForServer(this.config).map((name) => toolDefinition(name, phaseFromToolName(name), qaGateFromToolName(name), decomposeGateFromToolName(name)));
136
+ const completionTools = this.config.managedToolsOnly
137
+ ? []
138
+ : completionToolNamesForServer(this.config).map(toolDefinition);
161
139
  return managedAttemptToolsAvailable()
162
140
  ? [...completionTools, ...managedAttemptToolNames.map(managedAttemptToolDefinition)]
163
141
  : completionTools;
164
142
  }
165
- async callTool(toolName, input) {
143
+ async callTool(toolName, rawInput) {
166
144
  if (isManagedAttemptTool(toolName)) {
167
145
  if (!managedAttemptToolsAvailable()) {
168
146
  throw new Error("Forge managed-attempt tools require an active managed host runtime.");
169
147
  }
170
- const result = await callManagedAttemptTool(toolName, input, this.config.worktreePath);
148
+ const managedInput = coerceJsonStringArguments(rawInput, managedAttemptToolInputSchema(toolName));
149
+ const result = await callManagedAttemptTool(toolName, managedInput, this.config.worktreePath);
171
150
  if (Array.isArray(result.structuredContent.command)) {
172
151
  this.managedCommandReceipts.push(result.structuredContent);
173
152
  }
174
153
  return result;
175
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
+ }
176
158
  const requestedPhase = phaseFromToolName(toolName);
159
+ // Clients sometimes send a declared array/object argument as its JSON text.
160
+ const input = coerceJsonStringArguments(rawInput, completionToolInputSchema(toolName));
177
161
  if (this.completed) {
178
162
  throw new Error("Forge completion cycle is already complete; no more completion calls are accepted.");
179
163
  }
@@ -270,15 +254,26 @@ export class CompletionToolServerSession {
270
254
  const completedGate = this.currentDraftGate;
271
255
  const reference = await writeDraftGateCompletionArtifact(this.config, completedGate, toolName, input);
272
256
  const status = reference.status.trim().toLowerCase();
273
- const nextGate = this.advanceAfterDraftGate(completedGate);
274
- const nextPhase = nextGate ? "draft" : "sign_off_ready";
275
- const nextInstruction = completionToolNextInstructionForDraftGate(completedGate, status, nextGate);
257
+ // Only a pass completes a Draft gate; needs_revision, needs_rework, and blocked keep the same
258
+ // gate selected so it is retried, never skipped.
259
+ const pass = status === "pass";
260
+ const nextGate = pass ? this.advanceAfterDraftGate(completedGate) : completedGate;
261
+ const nextPhase = pass ? (nextGate ? "draft" : "sign_off_ready") : "draft";
262
+ const nextInstruction = completionToolNextInstructionForDraftGate(completedGate, status, pass ? nextGate : null);
276
263
  return {
277
264
  content: [{ type: "text", text: `Forge recorded ${completedGate} artifact ${path.relative(reference.repoPath, reference.path)} (${reference.status}, ${reference.contentHash}). ${nextInstruction}` }],
278
265
  structuredContent: {
279
266
  ...reference,
280
267
  ...acceptedArtifactReceipt(reference),
281
- gate: { phase: "draft", draftGate: completedGate, status, allowed: status !== "blocked", reason: nextGate ? `${completedGate} artifact accepted; continue to ${nextGate}.` : `Draft proposal artifact accepted with status ${status}.` },
268
+ gate: {
269
+ phase: "draft",
270
+ draftGate: completedGate,
271
+ status,
272
+ allowed: pass,
273
+ reason: !pass
274
+ ? `${completedGate} artifact recorded with status ${status}; rework is required before continuing.`
275
+ : nextGate ? `${completedGate} artifact accepted; continue to ${nextGate}.` : `Draft proposal artifact accepted with status ${status}.`
276
+ },
282
277
  nextPhase,
283
278
  nextInstruction
284
279
  }
@@ -458,18 +453,25 @@ const completionToolRuntimeEnvironmentNames = [
458
453
  "TMP",
459
454
  "TEMP",
460
455
  ];
461
- export function completionToolRuntimeEnvironment(runtimeEnvironment, nativeTestPostgresFallbackPath) {
462
- if (!runtimeEnvironment)
463
- return {};
456
+ export function completionToolRuntimeEnvironment(runtimeEnvironment, nativeTestPostgresFallbackPath, hostLoadEnvironment) {
464
457
  const env = {};
458
+ // Without a runtime environment the server gets nothing from it, but it still
459
+ // joins the host ledger when the bridge handed it the governor's variables.
460
+ if (!runtimeEnvironment && !hostLoadEnvironment)
461
+ return env;
465
462
  for (const name of completionToolRuntimeEnvironmentNames) {
466
- const value = runtimeEnvironment[name]?.trim();
463
+ const value = runtimeEnvironment?.[name]?.trim();
467
464
  if (value)
468
465
  env[name] = value;
469
466
  }
467
+ // The host load governor's flag, state root and tuning: managed commands join its ledger.
468
+ for (const [name, value] of Object.entries(hostLoadEnvironment ?? {})) {
469
+ if (isHostLoadChildEnvironmentName(name) && value.trim())
470
+ env[name] = value.trim();
471
+ }
470
472
  // Managed verification reads the operator's native test cluster only through
471
- // this explicit path, and only while Docker is unavailable.
472
- if (nativeTestPostgresFallbackPath) {
473
+ // this explicit path; the file's `use` decides whether Docker comes first.
474
+ if (runtimeEnvironment && nativeTestPostgresFallbackPath) {
473
475
  env[nativeTestPostgresFallbackConfigEnvironment] = nativeTestPostgresFallbackPath;
474
476
  }
475
477
  return env;
@@ -576,115 +578,6 @@ export async function runCompletionMcpServer(config) {
576
578
  }
577
579
  });
578
580
  }
579
- export function parseCompletionMcpArgs(argv) {
580
- let worktreePath = null;
581
- let workItemId = null;
582
- let phase = "implementation";
583
- let ownerType;
584
- let ownerId;
585
- let producedBy;
586
- let developCycle = false;
587
- let qaCycle = false;
588
- let debugCycle = false;
589
- let architectCycle = false;
590
- let draftCycle = false;
591
- let decomposeCycle = false;
592
- for (let index = 1; index < argv.length; index += 1) {
593
- const arg = argv[index];
594
- if (arg === "--worktree") {
595
- worktreePath = argv[++index] ?? null;
596
- }
597
- else if (arg === "--work-item-id") {
598
- workItemId = argv[++index] ?? null;
599
- }
600
- else if (arg === "--owner-type") {
601
- ownerType = normalizedOwnerType(argv[++index]);
602
- if (!ownerType) {
603
- return { ok: false, error: "mcp --owner-type must be work_item or story." };
604
- }
605
- }
606
- else if (arg === "--owner-id") {
607
- ownerId = argv[++index] ?? undefined;
608
- }
609
- else if (arg === "--phase") {
610
- const rawPhase = argv[++index];
611
- const parsedPhase = parseStrictCompletionPhase(rawPhase);
612
- if (!parsedPhase) {
613
- 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." };
614
- }
615
- phase = parsedPhase;
616
- }
617
- else if (arg === "--produced-by") {
618
- producedBy = argv[++index] ?? undefined;
619
- }
620
- else if (arg === "--develop-cycle") {
621
- developCycle = true;
622
- }
623
- else if (arg === "--qa-cycle") {
624
- qaCycle = true;
625
- }
626
- else if (arg === "--debug-cycle") {
627
- debugCycle = true;
628
- }
629
- else if (arg === "--architect-cycle") {
630
- architectCycle = true;
631
- }
632
- else if (arg === "--draft-cycle") {
633
- draftCycle = true;
634
- }
635
- else if (arg === "--decompose-cycle") {
636
- decomposeCycle = true;
637
- }
638
- else {
639
- return { ok: false, error: `Unknown mcp argument: ${arg}` };
640
- }
641
- }
642
- if (!worktreePath?.trim() || !workItemId?.trim()) {
643
- return { ok: false, error: "mcp requires --worktree and --work-item-id." };
644
- }
645
- if ([developCycle, qaCycle, debugCycle, architectCycle, draftCycle, decomposeCycle].filter(Boolean).length > 1) {
646
- return { ok: false, error: "mcp accepts only one cycle mode." };
647
- }
648
- if (developCycle && !isDevelopCompletionPhase(phase)) {
649
- return { ok: false, error: "mcp --develop-cycle requires --phase implementation, self-review, or validation." };
650
- }
651
- if (qaCycle && phase !== "qa") {
652
- return { ok: false, error: "mcp --qa-cycle requires --phase qa." };
653
- }
654
- if (debugCycle && !isDebugCompletionPhase(phase)) {
655
- return { ok: false, error: "mcp --debug-cycle requires --phase debug-repro, debug-root-cause, debug-fix, or debug-regression." };
656
- }
657
- if (architectCycle && phase !== "architect") {
658
- return { ok: false, error: "mcp --architect-cycle requires --phase architect." };
659
- }
660
- if (draftCycle && phase !== "draft") {
661
- return { ok: false, error: "mcp --draft-cycle requires --phase draft." };
662
- }
663
- if (decomposeCycle && phase !== "decompose") {
664
- return { ok: false, error: "mcp --decompose-cycle requires --phase decompose." };
665
- }
666
- return {
667
- ok: true,
668
- config: {
669
- worktreePath: path.resolve(worktreePath),
670
- workItemId,
671
- ownerType,
672
- ownerId,
673
- phase,
674
- producedBy,
675
- redactionSecrets: [
676
- ...parseCompletionRedactionSecrets(process.env[completionRedactionSecretsEnv]),
677
- ...attemptDatabaseCapabilitySecrets(process.env[attemptDatabaseCapabilityEnvironment]),
678
- ],
679
- developCycle,
680
- qaCycle,
681
- debugCycle,
682
- architectCycle,
683
- draftCycle,
684
- decomposeCycle
685
- }
686
- };
687
- }
688
581
  export function completionRedactionEnv(secrets) {
689
582
  const filtered = secrets.filter((secret) => secret.length > 0);
690
583
  return filtered.length > 0
@@ -800,15 +693,18 @@ async function handleJsonRpcRequest(session, method, params) {
800
693
  catch (error) {
801
694
  if (isManagedAttemptTool(name))
802
695
  throw error;
803
- return completionToolRejectedResult(name, error);
696
+ return completionToolRejectedResult(name, error, args);
804
697
  }
805
698
  }
806
699
  throw new Error(`Unsupported MCP method: ${method}`);
807
700
  }
808
- export function completionToolRejectedResult(toolName, error) {
701
+ export function completionToolRejectedResult(toolName, error, input) {
809
702
  const issues = error instanceof CompletionPayloadValidationError
810
703
  ? [...error.issues]
811
704
  : [errorMessage(error)];
705
+ if (input !== undefined && isEmptyToolInput(input)) {
706
+ issues.push(`${emptyToolInputHint} Keep long free text such as report_markdown short.`);
707
+ }
812
708
  const repairInstruction = "Repair every listed issue and resubmit this same gate once. Do not inspect the artifact path: rejected calls never write or replace completion artifacts.";
813
709
  return {
814
710
  content: [{
@@ -836,10 +732,14 @@ function acceptedArtifactReceipt(reference) {
836
732
  },
837
733
  };
838
734
  }
839
- function toolDefinition(name, phase, qaGate = null, decomposeGate = null) {
735
+ function toolDefinition(name) {
840
736
  return {
841
737
  name,
842
- description: toolDescription(phase, qaGate, decomposeGate),
843
- inputSchema: toolInputSchema(phase, qaGate, decomposeGate)
738
+ description: toolDescription(phaseFromToolName(name), qaGateFromToolName(name), decomposeGateFromToolName(name), draftGateFromToolName(name)),
739
+ inputSchema: completionToolInputSchema(name)
844
740
  };
845
741
  }
742
+ /** The input schema a completion tool advertises; also the shape its arguments are coerced to. */
743
+ export function completionToolInputSchema(name) {
744
+ return toolInputSchema(phaseFromToolName(name), qaGateFromToolName(name), decomposeGateFromToolName(name), draftGateFromToolName(name));
745
+ }
@@ -0,0 +1,19 @@
1
+ export declare function browserCheckSchema(required: readonly string[]): unknown;
2
+ export declare function qaSidecarsSchema(): unknown;
3
+ export declare function qaEvidenceWrapperSchema(): unknown;
4
+ /** QA evidence gates read only sidecars from the nested wrapper; the other evidence fields go at the top level. */
5
+ export declare function qaGateEvidenceWrapperSchema(): unknown;
6
+ export declare function findingEvidenceSchema(rule: string): unknown;
7
+ export declare function objectToolSchema(properties: Record<string, unknown>, required: readonly string[], description: string): unknown;
8
+ export declare function evidenceObjectSchema(required: readonly string[], properties: Record<string, unknown>): unknown;
9
+ export declare function qaScopeSchema(description: string): unknown;
10
+ export declare function commandEvidenceSchema(): unknown;
11
+ export declare function resolvedFindingSchema(): unknown;
12
+ export declare function acceptanceCriteriaSchema(): unknown;
13
+ export declare function reviewSectionSchema(): {
14
+ readonly type: "object";
15
+ readonly description: string;
16
+ readonly additionalProperties: true;
17
+ readonly properties: Record<string, unknown>;
18
+ };
19
+ export declare function reviewSectionProperties(): Record<string, unknown>;