@opengsd/gsd-pi 1.1.1-dev.9f86580 → 1.1.1-dev.b2556262

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 (261) hide show
  1. package/dist/headless-recover.js +56 -1
  2. package/dist/resources/.managed-resources-content-hash +1 -1
  3. package/dist/resources/extensions/browser-tools/index.js +39 -22
  4. package/dist/resources/extensions/browser-tools/state.js +12 -0
  5. package/dist/resources/extensions/browser-tools/tools/session.js +3 -2
  6. package/dist/resources/extensions/browser-tools/utils.js +3 -3
  7. package/dist/resources/extensions/gsd/auto/loop.js +4 -2
  8. package/dist/resources/extensions/gsd/auto/phases.js +43 -10
  9. package/dist/resources/extensions/gsd/auto/session.js +20 -1
  10. package/dist/resources/extensions/gsd/auto/workflow-kernel.js +1 -0
  11. package/dist/resources/extensions/gsd/auto-dispatch.js +72 -12
  12. package/dist/resources/extensions/gsd/auto-model-selection.js +128 -9
  13. package/dist/resources/extensions/gsd/auto-post-unit.js +19 -2
  14. package/dist/resources/extensions/gsd/auto-prompts.js +24 -19
  15. package/dist/resources/extensions/gsd/auto-recovery.js +4 -2
  16. package/dist/resources/extensions/gsd/auto-runtime-state.js +3 -0
  17. package/dist/resources/extensions/gsd/auto-start.js +1 -1
  18. package/dist/resources/extensions/gsd/auto.js +14 -11
  19. package/dist/resources/extensions/gsd/bootstrap/db-tools.js +3 -3
  20. package/dist/resources/extensions/gsd/bootstrap/register-hooks.js +172 -65
  21. package/dist/resources/extensions/gsd/closeout-wizard.js +32 -9
  22. package/dist/resources/extensions/gsd/commands/handlers/ops.js +2 -9
  23. package/dist/resources/extensions/gsd/commands-maintenance.js +93 -15
  24. package/dist/resources/extensions/gsd/commands-prefs-wizard.js +2 -2
  25. package/dist/resources/extensions/gsd/db-writer.js +35 -0
  26. package/dist/resources/extensions/gsd/docs/preferences-reference.md +50 -1
  27. package/dist/resources/extensions/gsd/gsd-db.js +480 -172
  28. package/dist/resources/extensions/gsd/markdown-renderer.js +37 -53
  29. package/dist/resources/extensions/gsd/md-importer.js +38 -3
  30. package/dist/resources/extensions/gsd/migration-auto-check.js +126 -31
  31. package/dist/resources/extensions/gsd/parsers-legacy.js +23 -0
  32. package/dist/resources/extensions/gsd/planning-path-scope.js +22 -4
  33. package/dist/resources/extensions/gsd/pre-execution-checks.js +10 -2
  34. package/dist/resources/extensions/gsd/preferences-models.js +110 -43
  35. package/dist/resources/extensions/gsd/preferences-types.js +13 -0
  36. package/dist/resources/extensions/gsd/preferences-validation.js +68 -3
  37. package/dist/resources/extensions/gsd/preferences.js +4 -1
  38. package/dist/resources/extensions/gsd/prompts/gate-evaluate.md +1 -1
  39. package/dist/resources/extensions/gsd/prompts/plan-slice.md +1 -1
  40. package/dist/resources/extensions/gsd/prompts/refine-slice.md +1 -1
  41. package/dist/resources/extensions/gsd/roadmap-slices.js +5 -1
  42. package/dist/resources/extensions/gsd/safety/content-validator.js +6 -4
  43. package/dist/resources/extensions/gsd/source-observations.js +306 -0
  44. package/dist/resources/extensions/gsd/state-reconciliation/drift/completion.js +15 -8
  45. package/dist/resources/extensions/gsd/state-reconciliation/drift/stale-render.js +33 -5
  46. package/dist/resources/extensions/gsd/state-reconciliation/drift/stale-worker.js +34 -13
  47. package/dist/resources/extensions/gsd/state-reconciliation/index.js +39 -14
  48. package/dist/resources/extensions/gsd/state-reconciliation/spawn-gate.js +4 -4
  49. package/dist/resources/extensions/gsd/state.js +7 -3
  50. package/dist/resources/extensions/gsd/tool-contract.js +14 -0
  51. package/dist/resources/extensions/gsd/tool-presentation-plan.js +1 -9
  52. package/dist/resources/extensions/gsd/tools/complete-slice.js +7 -6
  53. package/dist/resources/extensions/gsd/tools/plan-slice.js +42 -11
  54. package/dist/resources/extensions/gsd/tools/plan-task.js +7 -1
  55. package/dist/resources/extensions/gsd/tools/workflow-tool-executors.js +57 -429
  56. package/dist/resources/extensions/gsd/uat-policy.js +130 -0
  57. package/dist/resources/extensions/gsd/uat-run.js +414 -0
  58. package/dist/resources/extensions/gsd/unit-context-manifest.js +3 -4
  59. package/dist/resources/extensions/gsd/verdict-parser.js +3 -8
  60. package/dist/resources/extensions/gsd/workflow-manifest.js +132 -5
  61. package/dist/resources/extensions/gsd/workflow-projections.js +8 -0
  62. package/dist/resources/extensions/gsd/worktree-state-projection.js +18 -17
  63. package/dist/resources/extensions/subagent/agents.js +1 -0
  64. package/dist/resources/extensions/subagent/index.js +27 -12
  65. package/dist/resources/extensions/subagent/launch.js +7 -2
  66. package/dist/web/standalone/.next/BUILD_ID +1 -1
  67. package/dist/web/standalone/.next/app-path-routes-manifest.json +8 -8
  68. package/dist/web/standalone/.next/build-manifest.json +2 -2
  69. package/dist/web/standalone/.next/prerender-manifest.json +3 -3
  70. package/dist/web/standalone/.next/server/app/_global-error.html +1 -1
  71. package/dist/web/standalone/.next/server/app/_global-error.rsc +1 -1
  72. package/dist/web/standalone/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  73. package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
  74. package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error.segment.rsc +1 -1
  75. package/dist/web/standalone/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  76. package/dist/web/standalone/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  77. package/dist/web/standalone/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  78. package/dist/web/standalone/.next/server/app/_not-found.html +1 -1
  79. package/dist/web/standalone/.next/server/app/_not-found.rsc +1 -1
  80. package/dist/web/standalone/.next/server/app/_not-found.segments/_full.segment.rsc +1 -1
  81. package/dist/web/standalone/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
  82. package/dist/web/standalone/.next/server/app/_not-found.segments/_index.segment.rsc +1 -1
  83. package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
  84. package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
  85. package/dist/web/standalone/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
  86. package/dist/web/standalone/.next/server/app/index.html +1 -1
  87. package/dist/web/standalone/.next/server/app/index.rsc +1 -1
  88. package/dist/web/standalone/.next/server/app/index.segments/__PAGE__.segment.rsc +1 -1
  89. package/dist/web/standalone/.next/server/app/index.segments/_full.segment.rsc +1 -1
  90. package/dist/web/standalone/.next/server/app/index.segments/_head.segment.rsc +1 -1
  91. package/dist/web/standalone/.next/server/app/index.segments/_index.segment.rsc +1 -1
  92. package/dist/web/standalone/.next/server/app/index.segments/_tree.segment.rsc +1 -1
  93. package/dist/web/standalone/.next/server/app-paths-manifest.json +8 -8
  94. package/dist/web/standalone/.next/server/chunks/8357.js +1 -1
  95. package/dist/web/standalone/.next/server/middleware-build-manifest.js +1 -1
  96. package/dist/web/standalone/.next/server/pages/404.html +1 -1
  97. package/dist/web/standalone/.next/server/pages/500.html +1 -1
  98. package/dist/web/standalone/.next/server/server-reference-manifest.json +1 -1
  99. package/dist/web/standalone/node_modules/@gsd/native/dist/native.js +22 -0
  100. package/dist/web/standalone/node_modules/node-pty/build/Makefile +1 -1
  101. package/package.json +4 -4
  102. package/packages/cloud-mcp-gateway/package.json +2 -2
  103. package/packages/contracts/package.json +1 -1
  104. package/packages/daemon/package.json +4 -4
  105. package/packages/gsd-agent-core/package.json +5 -5
  106. package/packages/gsd-agent-modes/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
  107. package/packages/gsd-agent-modes/dist/modes/interactive/components/assistant-message.js +21 -23
  108. package/packages/gsd-agent-modes/dist/modes/interactive/components/assistant-message.js.map +1 -1
  109. package/packages/gsd-agent-modes/dist/modes/interactive/components/tool-execution.d.ts +3 -0
  110. package/packages/gsd-agent-modes/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  111. package/packages/gsd-agent-modes/dist/modes/interactive/components/tool-execution.js +25 -0
  112. package/packages/gsd-agent-modes/dist/modes/interactive/components/tool-execution.js.map +1 -1
  113. package/packages/gsd-agent-modes/dist/modes/interactive/components/transcript-design.d.ts +1 -0
  114. package/packages/gsd-agent-modes/dist/modes/interactive/components/transcript-design.d.ts.map +1 -1
  115. package/packages/gsd-agent-modes/dist/modes/interactive/components/transcript-design.js +66 -12
  116. package/packages/gsd-agent-modes/dist/modes/interactive/components/transcript-design.js.map +1 -1
  117. package/packages/gsd-agent-modes/dist/modes/interactive/controllers/chat-controller.d.ts.map +1 -1
  118. package/packages/gsd-agent-modes/dist/modes/interactive/controllers/chat-controller.js +18 -11
  119. package/packages/gsd-agent-modes/dist/modes/interactive/controllers/chat-controller.js.map +1 -1
  120. package/packages/gsd-agent-modes/dist/modes/interactive/interactive-chat-render.d.ts.map +1 -1
  121. package/packages/gsd-agent-modes/dist/modes/interactive/interactive-chat-render.js +16 -0
  122. package/packages/gsd-agent-modes/dist/modes/interactive/interactive-chat-render.js.map +1 -1
  123. package/packages/gsd-agent-modes/package.json +7 -7
  124. package/packages/mcp-server/dist/workflow-tools.js +1 -1
  125. package/packages/mcp-server/dist/workflow-tools.js.map +1 -1
  126. package/packages/mcp-server/package.json +3 -3
  127. package/packages/native/dist/native.js +22 -0
  128. package/packages/native/package.json +1 -1
  129. package/packages/pi-agent-core/package.json +1 -1
  130. package/packages/pi-ai/dist/image-models.generated.d.ts +30 -0
  131. package/packages/pi-ai/dist/image-models.generated.d.ts.map +1 -1
  132. package/packages/pi-ai/dist/image-models.generated.js +30 -0
  133. package/packages/pi-ai/dist/image-models.generated.js.map +1 -1
  134. package/packages/pi-ai/dist/models.generated.d.ts +23 -17
  135. package/packages/pi-ai/dist/models.generated.d.ts.map +1 -1
  136. package/packages/pi-ai/dist/models.generated.js +25 -24
  137. package/packages/pi-ai/dist/models.generated.js.map +1 -1
  138. package/packages/pi-ai/package.json +1 -1
  139. package/packages/pi-coding-agent/dist/core/settings-manager.js +1 -1
  140. package/packages/pi-coding-agent/dist/core/settings-manager.js.map +1 -1
  141. package/packages/pi-coding-agent/dist/theme/themes.js +1 -1
  142. package/packages/pi-coding-agent/dist/theme/themes.js.map +1 -1
  143. package/packages/pi-coding-agent/package.json +7 -7
  144. package/packages/pi-tui/dist/utils.d.ts +11 -0
  145. package/packages/pi-tui/dist/utils.d.ts.map +1 -1
  146. package/packages/pi-tui/dist/utils.js +119 -6
  147. package/packages/pi-tui/dist/utils.js.map +1 -1
  148. package/packages/pi-tui/package.json +2 -1
  149. package/packages/rpc-client/package.json +2 -2
  150. package/pkg/dist/theme/themes.js +1 -1
  151. package/pkg/dist/theme/themes.js.map +1 -1
  152. package/pkg/package.json +1 -1
  153. package/src/resources/extensions/browser-tools/index.ts +39 -22
  154. package/src/resources/extensions/browser-tools/state.ts +13 -0
  155. package/src/resources/extensions/browser-tools/tests/browser-tools-unit.test.cjs +57 -0
  156. package/src/resources/extensions/browser-tools/tools/session.ts +4 -2
  157. package/src/resources/extensions/browser-tools/utils.ts +3 -3
  158. package/src/resources/extensions/gsd/auto/loop-deps.ts +1 -0
  159. package/src/resources/extensions/gsd/auto/loop.ts +4 -2
  160. package/src/resources/extensions/gsd/auto/phases.ts +42 -10
  161. package/src/resources/extensions/gsd/auto/session.ts +22 -1
  162. package/src/resources/extensions/gsd/auto/workflow-kernel.ts +1 -0
  163. package/src/resources/extensions/gsd/auto-dispatch.ts +85 -12
  164. package/src/resources/extensions/gsd/auto-model-selection.ts +164 -12
  165. package/src/resources/extensions/gsd/auto-post-unit.ts +20 -2
  166. package/src/resources/extensions/gsd/auto-prompts.ts +23 -20
  167. package/src/resources/extensions/gsd/auto-recovery.ts +22 -3
  168. package/src/resources/extensions/gsd/auto-runtime-state.ts +5 -0
  169. package/src/resources/extensions/gsd/auto-start.ts +1 -1
  170. package/src/resources/extensions/gsd/auto.ts +13 -10
  171. package/src/resources/extensions/gsd/bootstrap/db-tools.ts +3 -3
  172. package/src/resources/extensions/gsd/bootstrap/register-hooks.ts +225 -72
  173. package/src/resources/extensions/gsd/closeout-wizard.ts +47 -13
  174. package/src/resources/extensions/gsd/commands/handlers/ops.ts +2 -17
  175. package/src/resources/extensions/gsd/commands-maintenance.ts +124 -13
  176. package/src/resources/extensions/gsd/commands-prefs-wizard.ts +2 -2
  177. package/src/resources/extensions/gsd/db-writer.ts +38 -0
  178. package/src/resources/extensions/gsd/docs/preferences-reference.md +50 -1
  179. package/src/resources/extensions/gsd/gsd-db.ts +564 -186
  180. package/src/resources/extensions/gsd/markdown-renderer.ts +44 -66
  181. package/src/resources/extensions/gsd/md-importer.ts +49 -2
  182. package/src/resources/extensions/gsd/migration-auto-check.ts +154 -34
  183. package/src/resources/extensions/gsd/parsers-legacy.ts +20 -0
  184. package/src/resources/extensions/gsd/planning-path-scope.ts +22 -4
  185. package/src/resources/extensions/gsd/pre-execution-checks.ts +9 -2
  186. package/src/resources/extensions/gsd/preferences-models.ts +112 -43
  187. package/src/resources/extensions/gsd/preferences-types.ts +39 -0
  188. package/src/resources/extensions/gsd/preferences-validation.ts +76 -2
  189. package/src/resources/extensions/gsd/preferences.ts +5 -0
  190. package/src/resources/extensions/gsd/prompts/gate-evaluate.md +1 -1
  191. package/src/resources/extensions/gsd/prompts/plan-slice.md +1 -1
  192. package/src/resources/extensions/gsd/prompts/refine-slice.md +1 -1
  193. package/src/resources/extensions/gsd/roadmap-slices.ts +6 -1
  194. package/src/resources/extensions/gsd/safety/content-validator.ts +8 -5
  195. package/src/resources/extensions/gsd/source-observations.ts +402 -0
  196. package/src/resources/extensions/gsd/state-reconciliation/drift/completion.ts +20 -8
  197. package/src/resources/extensions/gsd/state-reconciliation/drift/stale-render.ts +44 -5
  198. package/src/resources/extensions/gsd/state-reconciliation/drift/stale-worker.ts +39 -11
  199. package/src/resources/extensions/gsd/state-reconciliation/index.ts +45 -15
  200. package/src/resources/extensions/gsd/state-reconciliation/spawn-gate.ts +4 -4
  201. package/src/resources/extensions/gsd/state.ts +7 -4
  202. package/src/resources/extensions/gsd/tests/auto-loop.test.ts +15 -0
  203. package/src/resources/extensions/gsd/tests/auto-model-selection.test.ts +299 -1
  204. package/src/resources/extensions/gsd/tests/auto-paused-ui-cleanup.test.ts +32 -0
  205. package/src/resources/extensions/gsd/tests/auto-phases-lifecycle.test.ts +75 -3
  206. package/src/resources/extensions/gsd/tests/auto-recovery.test.ts +22 -1
  207. package/src/resources/extensions/gsd/tests/before-provider-context-management.test.ts +145 -0
  208. package/src/resources/extensions/gsd/tests/closeout-wizard.test.ts +44 -0
  209. package/src/resources/extensions/gsd/tests/commands-dispatcher-unmerged-milestone.test.ts +26 -1
  210. package/src/resources/extensions/gsd/tests/content-validator.test.ts +74 -0
  211. package/src/resources/extensions/gsd/tests/custom-engine-loop-integration.test.ts +16 -2
  212. package/src/resources/extensions/gsd/tests/doctor-scope-db-unavailable.test.ts +1 -11
  213. package/src/resources/extensions/gsd/tests/gate-dispatch.test.ts +64 -0
  214. package/src/resources/extensions/gsd/tests/gate-storage.test.ts +15 -0
  215. package/src/resources/extensions/gsd/tests/gsd-recover.test.ts +62 -1
  216. package/src/resources/extensions/gsd/tests/journal-integration.test.ts +15 -0
  217. package/src/resources/extensions/gsd/tests/markdown-renderer.test.ts +42 -0
  218. package/src/resources/extensions/gsd/tests/migration-auto-check.test.ts +99 -0
  219. package/src/resources/extensions/gsd/tests/plan-slice.test.ts +99 -2
  220. package/src/resources/extensions/gsd/tests/plan-task.test.ts +19 -0
  221. package/src/resources/extensions/gsd/tests/preferences.test.ts +14 -0
  222. package/src/resources/extensions/gsd/tests/prefs-wizard-coverage.test.ts +1 -0
  223. package/src/resources/extensions/gsd/tests/prompt-contracts.test.ts +9 -0
  224. package/src/resources/extensions/gsd/tests/register-hooks-depth-verification.test.ts +101 -1
  225. package/src/resources/extensions/gsd/tests/repository-registry.test.ts +2 -2
  226. package/src/resources/extensions/gsd/tests/runtime-invariant-modules.test.ts +8 -0
  227. package/src/resources/extensions/gsd/tests/schema-v21-sequence.test.ts +5 -3
  228. package/src/resources/extensions/gsd/tests/schema-v27-v28-sequence.test.ts +162 -18
  229. package/src/resources/extensions/gsd/tests/skipped-validation-db-atomicity.test.ts +8 -0
  230. package/src/resources/extensions/gsd/tests/source-observations.test.ts +275 -0
  231. package/src/resources/extensions/gsd/tests/stale-queued-milestone.test.ts +43 -0
  232. package/src/resources/extensions/gsd/tests/state-reconciliation-drift.test.ts +76 -21
  233. package/src/resources/extensions/gsd/tests/thinking-level-resolution.test.ts +203 -0
  234. package/src/resources/extensions/gsd/tests/uat-policy.test.ts +170 -0
  235. package/src/resources/extensions/gsd/tests/unit-context-manifest.test.ts +7 -1
  236. package/src/resources/extensions/gsd/tests/workflow-kernel.test.ts +7 -0
  237. package/src/resources/extensions/gsd/tests/workflow-manifest.test.ts +306 -1
  238. package/src/resources/extensions/gsd/tests/workflow-tool-executors.test.ts +73 -6
  239. package/src/resources/extensions/gsd/tests/worktree-db.test.ts +511 -1
  240. package/src/resources/extensions/gsd/tests/worktree-state-projection.test.ts +44 -0
  241. package/src/resources/extensions/gsd/tool-contract.ts +28 -0
  242. package/src/resources/extensions/gsd/tool-presentation-plan.ts +1 -11
  243. package/src/resources/extensions/gsd/tools/complete-slice.ts +7 -6
  244. package/src/resources/extensions/gsd/tools/plan-slice.ts +54 -12
  245. package/src/resources/extensions/gsd/tools/plan-task.ts +8 -1
  246. package/src/resources/extensions/gsd/tools/workflow-tool-executors.ts +66 -526
  247. package/src/resources/extensions/gsd/types.ts +1 -0
  248. package/src/resources/extensions/gsd/uat-policy.ts +191 -0
  249. package/src/resources/extensions/gsd/uat-run.ts +550 -0
  250. package/src/resources/extensions/gsd/unit-context-manifest.ts +3 -4
  251. package/src/resources/extensions/gsd/verdict-parser.ts +3 -10
  252. package/src/resources/extensions/gsd/workflow-manifest.ts +193 -7
  253. package/src/resources/extensions/gsd/workflow-projections.ts +9 -0
  254. package/src/resources/extensions/gsd/worktree-state-projection.ts +22 -22
  255. package/src/resources/extensions/shared/tests/format-utils.test.ts +8 -3
  256. package/src/resources/extensions/subagent/agents.ts +4 -0
  257. package/src/resources/extensions/subagent/index.ts +28 -3
  258. package/src/resources/extensions/subagent/launch.ts +8 -0
  259. package/src/resources/extensions/subagent/tests/model-override.test.ts +31 -0
  260. /package/dist/web/standalone/.next/static/{zzYMrKpPGfRQRxSFO32Jr → tJOKQbQRO-9MiFDO8DIDS}/_buildManifest.js +0 -0
  261. /package/dist/web/standalone/.next/static/{zzYMrKpPGfRQRxSFO32Jr → tJOKQbQRO-9MiFDO8DIDS}/_ssgManifest.js +0 -0
@@ -10,6 +10,7 @@ import {
10
10
  getMilestone,
11
11
  getSliceStatusSummary,
12
12
  getSliceTaskCounts,
13
+ insertAssessment,
13
14
  insertGateRun,
14
15
  readTransaction,
15
16
  saveGateResult,
@@ -19,9 +20,8 @@ import { GATE_REGISTRY } from "../gate-registry.js";
19
20
  import { generateRequirementsMd, saveArtifactToDb } from "../db-writer.js";
20
21
  import { clearPathCache, relSliceFile, resolveGsdPathContract, resolveMilestoneFile, resolveSliceFile } from "../paths.js";
21
22
  import { saveFile, clearParseCache } from "../files.js";
22
- import { buildManualValidationGuidance, resolveCanonicalMilestoneRoot } from "../worktree-manager.js";
23
- import { existsSync, readdirSync, readFileSync, unlinkSync } from "node:fs";
24
- import { isAbsolute, join, resolve } from "node:path";
23
+ import { unlinkSync } from "node:fs";
24
+ import { join } from "node:path";
25
25
  import type { CompleteMilestoneParams } from "./complete-milestone.js";
26
26
  import { handleCompleteMilestone } from "./complete-milestone.js";
27
27
  import { handleCompleteTask } from "./complete-task.js";
@@ -48,14 +48,17 @@ import { invalidateStateCache } from "../state.js";
48
48
  import { loadEffectiveGSDPreferences } from "../preferences.js";
49
49
  import { parseProject } from "../schemas/parsers.js";
50
50
  import { getAutoRuntimeSnapshot } from "../auto-runtime-state.js";
51
+ import { renderPlanFromDb } from "../markdown-renderer.js";
51
52
  import {
52
- buildRunUatPresentationForType,
53
- canonicalWorkflowToolName,
54
- parseMcpToolName,
55
- RUN_UAT_FORBIDDEN_TOOL_NAMES,
56
- RUN_UAT_TOOL_PRESENTATION_PLAN_ID,
57
- RUN_UAT_WORKFLOW_TOOL_NAMES,
58
- } from "../tool-presentation-plan.js";
53
+ prepareUatRun,
54
+ saveUatAttemptArtifact,
55
+ type UatResultSaveParams,
56
+ } from "../uat-run.js";
57
+ export type {
58
+ UatCheckResultInput,
59
+ UatEvidenceRef,
60
+ UatPresentationInput,
61
+ } from "../uat-run.js";
59
62
 
60
63
  export const SUPPORTED_SUMMARY_ARTIFACT_TYPES = [
61
64
  "SUMMARY",
@@ -437,58 +440,7 @@ export interface SaveGateResultParams {
437
440
  findings?: string;
438
441
  }
439
442
 
440
- export type UatType =
441
- | "artifact-driven"
442
- | "browser-executable"
443
- | "runtime-executable"
444
- | "live-runtime"
445
- | "mixed"
446
- | "human-experience";
447
-
448
- export type UatVerdict = "PASS" | "FAIL" | "PARTIAL";
449
- export type UatCheckResult = "PASS" | "FAIL" | "NEEDS-HUMAN";
450
-
451
- export interface UatEvidenceRef {
452
- kind: "gsd_uat_exec" | "gsd_exec" | "screenshot" | "log" | "url" | "browser";
453
- ref: string;
454
- note?: string;
455
- unitType?: string;
456
- tool?: string;
457
- executionId?: string;
458
- }
459
-
460
- export interface UatCheckResultInput {
461
- id: string;
462
- description: string;
463
- mode: "artifact" | "runtime" | "browser" | "human-follow-up";
464
- result: UatCheckResult;
465
- evidence?: UatEvidenceRef[];
466
- notes?: string;
467
- nonAutomatable?: boolean;
468
- }
469
-
470
- export interface UatPresentationInput {
471
- surface: "provider-tools" | "claude-code-sdk" | "mcp" | "hybrid";
472
- model?: { provider?: string; api?: string; id?: string };
473
- presentedTools: string[];
474
- blockedTools: Array<{ name: string; reason: string }>;
475
- aliases?: Array<{ requested: string; canonical: string }>;
476
- fallbackToolsUsed?: string[];
477
- toolPresentationPlanId?: string;
478
- notes?: string;
479
- }
480
-
481
- export interface UatResultSaveParams {
482
- milestoneId: string;
483
- sliceId: string;
484
- uatType: UatType;
485
- verdict: UatVerdict;
486
- checks: UatCheckResultInput[];
487
- presentation: UatPresentationInput;
488
- notes?: string;
489
- attempt?: number | string | "auto";
490
- previousAttemptId?: string;
491
- }
443
+ export type { UatResultSaveParams };
492
444
 
493
445
  export async function executeTaskComplete(
494
446
  params: TaskCompleteParams,
@@ -994,6 +946,7 @@ export async function executeSaveGateResult(
994
946
  rationale: params.rationale,
995
947
  findings: params.findings ?? "",
996
948
  });
949
+ await renderPlanFromDb(basePath, params.milestoneId, params.sliceId);
997
950
  invalidateStateCache();
998
951
  return {
999
952
  content: [{ type: "text", text: `Gate ${params.gateId} result saved: verdict=${params.verdict}` }],
@@ -1018,397 +971,6 @@ function errorResult(operation: string, message: string, error: string): ToolExe
1018
971
  };
1019
972
  }
1020
973
 
1021
- function isNonEmptyString(value: unknown): value is string {
1022
- return typeof value === "string" && value.trim().length > 0;
1023
- }
1024
-
1025
- function mergeBlockedTools(
1026
- current: UatPresentationInput["blockedTools"] | undefined,
1027
- canonical: UatPresentationInput["blockedTools"],
1028
- ): UatPresentationInput["blockedTools"] {
1029
- const merged = new Map<string, { name: string; reason: string }>();
1030
- for (const entry of [...(current ?? []), ...canonical]) {
1031
- merged.set(canonicalWorkflowToolName(parseMcpToolName(entry.name)?.tool ?? entry.name), entry);
1032
- }
1033
- return [...merged.values()];
1034
- }
1035
-
1036
- function mergePresentedTools(current: readonly string[] | undefined, canonical: readonly string[]): string[] {
1037
- return [...new Set([...(current ?? []), ...canonical])];
1038
- }
1039
-
1040
- function normalizeUatVerdict(params: UatResultSaveParams): UatResultSaveParams {
1041
- const raw = params as Partial<UatResultSaveParams> & Record<string, unknown>;
1042
- if (typeof raw.verdict === "string") {
1043
- return { ...params, verdict: raw.verdict.toUpperCase() as UatVerdict };
1044
- }
1045
- return params;
1046
- }
1047
-
1048
- function supplyDefaultPresentation(params: UatResultSaveParams): UatResultSaveParams {
1049
- const raw = params as Partial<UatResultSaveParams> & Record<string, unknown>;
1050
- if (!raw.presentation) {
1051
- return { ...params, presentation: buildRunUatPresentationForType(params.uatType) };
1052
- }
1053
- return params;
1054
- }
1055
-
1056
- function mergeCanonicalPresentation(params: UatResultSaveParams): UatResultSaveParams {
1057
- const canonicalPresentation = buildRunUatPresentationForType(params.uatType);
1058
- const providedPresentation = params.presentation as Partial<UatPresentationInput>;
1059
- return {
1060
- ...params,
1061
- presentation: {
1062
- ...providedPresentation,
1063
- surface: providedPresentation.surface ?? canonicalPresentation.surface,
1064
- presentedTools: mergePresentedTools(providedPresentation.presentedTools, canonicalPresentation.presentedTools),
1065
- blockedTools: mergeBlockedTools(providedPresentation.blockedTools, canonicalPresentation.blockedTools),
1066
- toolPresentationPlanId: RUN_UAT_TOOL_PRESENTATION_PLAN_ID,
1067
- } as UatPresentationInput,
1068
- };
1069
- }
1070
-
1071
- const VALID_UAT_TYPES: readonly UatType[] = [
1072
- "artifact-driven",
1073
- "browser-executable",
1074
- "runtime-executable",
1075
- "live-runtime",
1076
- "mixed",
1077
- "human-experience",
1078
- ];
1079
-
1080
- function ensureUatRequiredFields(params: UatResultSaveParams): string | null {
1081
- if (!isNonEmptyString(params.milestoneId)) return "milestoneId is required";
1082
- if (!isNonEmptyString(params.sliceId)) return "sliceId is required";
1083
- if (!isNonEmptyString(params.uatType)) return "uatType is required";
1084
- if (!(VALID_UAT_TYPES as readonly string[]).includes(params.uatType)) {
1085
- return `uatType must be one of: ${VALID_UAT_TYPES.join(", ")}`;
1086
- }
1087
- if (!["PASS", "FAIL", "PARTIAL"].includes(params.verdict)) return "verdict must be PASS, FAIL, or PARTIAL";
1088
- if (!Array.isArray(params.checks) || params.checks.length === 0) return "checks must contain at least one UAT check";
1089
- if (!params.presentation || !Array.isArray(params.presentation.presentedTools)) return "presentation.presentedTools is required";
1090
- if (!Array.isArray(params.presentation.blockedTools)) return "presentation.blockedTools is required";
1091
- return null;
1092
- }
1093
-
1094
- function approvedEvidenceRoots(basePath: string): string[] {
1095
- const contract = resolveGsdPathContract(basePath);
1096
- return [contract.worktreeGsd, contract.projectGsd].filter((root): root is string => typeof root === "string");
1097
- }
1098
-
1099
- function approvedBrowserArtifactRoots(basePath: string): string[] {
1100
- const contract = resolveGsdPathContract(basePath);
1101
- const roots = [contract.workRoot, contract.projectRoot].map((root) => join(root, ".artifacts", "browser"));
1102
- return [...new Set(roots)];
1103
- }
1104
-
1105
- function pathStartsWithin(parent: string, target: string): boolean {
1106
- const normalizedParent = parent.replace(/\\/g, "/").replace(/\/+$/, "");
1107
- const normalizedTarget = target.replace(/\\/g, "/").replace(/\/+$/, "");
1108
- return normalizedTarget === normalizedParent || normalizedTarget.startsWith(`${normalizedParent}/`);
1109
- }
1110
-
1111
- function pushUnique(paths: string[], candidate: string): void {
1112
- if (!paths.includes(candidate)) paths.push(candidate);
1113
- }
1114
-
1115
- function execMetaPathCandidates(basePath: string, ref: string): string[] {
1116
- const trimmed = ref.trim();
1117
- const candidates: string[] = [];
1118
- const execDirs = approvedEvidenceRoots(basePath).map((root) => join(root, "exec"));
1119
- const normalizedRef = trimmed.replace(/\\/g, "/");
1120
- const pathLike = normalizedRef.endsWith(".meta.json") || normalizedRef.includes("/.gsd/exec/");
1121
-
1122
- if (pathLike) {
1123
- const rawPath = isAbsolute(trimmed) ? resolve(trimmed) : resolve(basePath, trimmed);
1124
- pushUnique(candidates, rawPath);
1125
-
1126
- const relativeExecMarker = ".gsd/exec/";
1127
- const markerIndex = normalizedRef.indexOf(relativeExecMarker);
1128
- if (markerIndex >= 0) {
1129
- const execRelative = normalizedRef.slice(markerIndex + relativeExecMarker.length);
1130
- for (const execDir of execDirs) {
1131
- pushUnique(candidates, join(execDir, execRelative));
1132
- }
1133
- }
1134
-
1135
- return candidates.filter((candidate) =>
1136
- execDirs.some((execDir) => pathStartsWithin(execDir, candidate))
1137
- );
1138
- }
1139
-
1140
- for (const execDir of execDirs) {
1141
- pushUnique(candidates, join(execDir, `${trimmed}.meta.json`));
1142
- }
1143
- return candidates;
1144
- }
1145
-
1146
- function resolveExecMetaPath(basePath: string, ref: string): string | null {
1147
- for (const candidate of execMetaPathCandidates(basePath, ref)) {
1148
- if (existsSync(candidate)) return candidate;
1149
- }
1150
- return null;
1151
- }
1152
-
1153
- function evidencePathIsApproved(basePath: string, ref: string): boolean {
1154
- const normalizedRef = ref.replace(/\\/g, "/");
1155
- if (normalizedRef.startsWith(".gsd/exec/") || normalizedRef.startsWith(".gsd/uat/")) return true;
1156
- if (normalizedRef.startsWith(".artifacts/browser/")) {
1157
- const resolvedRef = resolve(basePath, ref);
1158
- return approvedBrowserArtifactRoots(basePath).some((root) => pathStartsWithin(root, resolvedRef));
1159
- }
1160
- const gsdEvidenceApproved = approvedEvidenceRoots(basePath).some((root) => {
1161
- return pathStartsWithin(join(root, "exec"), ref) || pathStartsWithin(join(root, "uat"), ref);
1162
- });
1163
- if (gsdEvidenceApproved) return true;
1164
- return approvedBrowserArtifactRoots(basePath).some((root) => pathStartsWithin(root, ref));
1165
- }
1166
-
1167
- function validateEvidenceRef(basePath: string, evidence: UatEvidenceRef): string | null {
1168
- if (!isNonEmptyString(evidence.ref)) return "evidence.ref is required";
1169
- if (evidence.kind === "gsd_uat_exec" || evidence.kind === "gsd_exec") {
1170
- const path = resolveExecMetaPath(basePath, evidence.ref.trim());
1171
- if (!path) return `missing gsd_exec metadata for evidence id "${evidence.ref}"`;
1172
- if (evidence.kind === "gsd_uat_exec") {
1173
- try {
1174
- const meta = JSON.parse(readFileSync(path, "utf-8")) as { metadata?: { kind?: unknown } };
1175
- if (meta.metadata?.kind !== "uat_exec") return `evidence id "${evidence.ref}" is not typed as uat_exec`;
1176
- } catch {
1177
- return `invalid gsd_exec metadata JSON for evidence id "${evidence.ref}"`;
1178
- }
1179
- }
1180
- return null;
1181
- }
1182
- if (evidence.kind === "url") {
1183
- try {
1184
- const parsed = new URL(evidence.ref);
1185
- return parsed.protocol === "http:" || parsed.protocol === "https:"
1186
- ? null
1187
- : `invalid URL evidence ref "${evidence.ref}"`;
1188
- } catch {
1189
- return `invalid URL evidence ref "${evidence.ref}"`;
1190
- }
1191
- }
1192
- return evidencePathIsApproved(basePath, evidence.ref)
1193
- ? null
1194
- : `evidence ref "${evidence.ref}" is outside approved evidence locations`;
1195
- }
1196
-
1197
- function validateUatChecks(basePath: string, params: UatResultSaveParams): string | null {
1198
- for (const check of params.checks) {
1199
- if (!isNonEmptyString(check.id)) return "every check must have a non-empty id";
1200
- if (!isNonEmptyString(check.description)) return `check ${check.id} must have a description`;
1201
- if (!["artifact", "runtime", "browser", "human-follow-up"].includes(check.mode)) {
1202
- return `check ${check.id} has invalid mode "${check.mode}"`;
1203
- }
1204
- if (!["PASS", "FAIL", "NEEDS-HUMAN"].includes(check.result)) {
1205
- return `check ${check.id} has invalid result "${check.result}"`;
1206
- }
1207
- if (check.result === "PASS" || check.result === "FAIL") {
1208
- if (!Array.isArray(check.evidence) || check.evidence.length === 0) {
1209
- return `check ${check.id} is ${check.result} but has no objective evidence`;
1210
- }
1211
- for (const evidence of check.evidence) {
1212
- const error = validateEvidenceRef(basePath, evidence);
1213
- if (error) return `check ${check.id}: ${error}`;
1214
- }
1215
- } else if (!isNonEmptyString(check.notes)) {
1216
- return `check ${check.id} is NEEDS-HUMAN but has no manual instruction or reason`;
1217
- }
1218
- }
1219
- return null;
1220
- }
1221
-
1222
- function validateFreshUatOwnedEvidence(params: UatResultSaveParams): string | null {
1223
- const hasFreshUatEvidence = params.checks.some((check) =>
1224
- (check.evidence ?? []).some((evidence) => evidence.kind === "gsd_uat_exec")
1225
- );
1226
- return hasFreshUatEvidence
1227
- ? null
1228
- : "UAT Assessment requires at least one fresh gsd_uat_exec evidence reference from run-uat";
1229
- }
1230
-
1231
- function validateUatMode(params: UatResultSaveParams): string | null {
1232
- const modes = new Set(params.checks.map((check) => check.mode));
1233
- const hasHuman = params.checks.some((check) => check.result === "NEEDS-HUMAN");
1234
- if (params.uatType === "artifact-driven" && hasHuman && params.verdict === "PASS") {
1235
- return "artifact-driven UAT cannot PASS with human-only checks";
1236
- }
1237
- if (
1238
- hasHuman &&
1239
- params.verdict === "PASS" &&
1240
- !["human-experience", "mixed", "live-runtime"].includes(params.uatType) &&
1241
- !params.checks.every((check) => check.result !== "NEEDS-HUMAN" || check.nonAutomatable === true)
1242
- ) {
1243
- return "NEEDS-HUMAN checks can only coexist with PASS for human-experience, mixed, live-runtime, or explicitly non-automatable checks";
1244
- }
1245
- if (params.uatType === "runtime-executable" && !modes.has("runtime")) {
1246
- return "runtime-executable UAT requires at least one runtime check";
1247
- }
1248
- if (params.uatType === "browser-executable" && !modes.has("browser")) {
1249
- return "browser-executable UAT requires at least one browser check";
1250
- }
1251
- if (params.uatType === "live-runtime" && !modes.has("runtime") && !modes.has("browser")) {
1252
- return "live-runtime UAT requires runtime or browser evidence";
1253
- }
1254
- return null;
1255
- }
1256
-
1257
- function quoteToolNames(toolNames: readonly string[]): string {
1258
- return toolNames.map((toolName) => `"${toolName}"`).join(", ");
1259
- }
1260
-
1261
- function validateCanonicalPresentation(params: UatResultSaveParams): string | null {
1262
- const aliasHints: Record<string, string> = {
1263
- gsd_save_summary: "gsd_summary_save",
1264
- gsd_complete_task: "gsd_task_complete",
1265
- gsd_complete_slice: "gsd_slice_complete",
1266
- gsd_milestone_complete: "gsd_complete_milestone",
1267
- };
1268
- const errors: string[] = [];
1269
- for (const toolName of params.presentation.presentedTools) {
1270
- const baseName = parseMcpToolName(toolName)?.tool ?? toolName;
1271
- const canonical = aliasHints[baseName];
1272
- if (canonical) errors.push(`presentation tool "${toolName}" uses an alias; use canonical "${canonical}"`);
1273
- }
1274
-
1275
- const presentedCanonical = new Set(
1276
- params.presentation.presentedTools.map((toolName) =>
1277
- canonicalWorkflowToolName(parseMcpToolName(toolName)?.tool ?? toolName)
1278
- ),
1279
- );
1280
- const missingRequiredTools = RUN_UAT_WORKFLOW_TOOL_NAMES.filter(
1281
- (requiredTool) => !presentedCanonical.has(requiredTool),
1282
- );
1283
- if (missingRequiredTools.length === 1) {
1284
- errors.push(`presentation is missing required UAT tool "${missingRequiredTools[0]}"`);
1285
- } else if (missingRequiredTools.length > 1) {
1286
- errors.push(`presentation is missing required UAT tools ${quoteToolNames(missingRequiredTools)}`);
1287
- }
1288
-
1289
- const forbiddenCanonical = new Set(
1290
- RUN_UAT_FORBIDDEN_TOOL_NAMES
1291
- .filter((toolName) => !toolName.includes("*"))
1292
- .map((toolName) => canonicalWorkflowToolName(parseMcpToolName(toolName)?.tool ?? toolName)),
1293
- );
1294
- const forbiddenPresentedTools: string[] = [];
1295
- for (const toolName of params.presentation.presentedTools) {
1296
- const canonical = canonicalWorkflowToolName(parseMcpToolName(toolName)?.tool ?? toolName);
1297
- if (toolName === "mcp__gsd-workflow__*" || forbiddenCanonical.has(canonical)) {
1298
- forbiddenPresentedTools.push(toolName);
1299
- }
1300
- }
1301
- if (forbiddenPresentedTools.length === 1) {
1302
- errors.push(`presentation includes forbidden run-uat tool "${forbiddenPresentedTools[0]}"`);
1303
- } else if (forbiddenPresentedTools.length > 1) {
1304
- errors.push(`presentation includes forbidden run-uat tools ${quoteToolNames(forbiddenPresentedTools)}`);
1305
- }
1306
-
1307
- const blockedCanonical = new Set(
1308
- params.presentation.blockedTools.map((entry) =>
1309
- canonicalWorkflowToolName(parseMcpToolName(entry.name)?.tool ?? entry.name)
1310
- ),
1311
- );
1312
- const missingBlockedTools = ["gsd_exec", "gsd_summary_save", "gsd_save_gate_result"].filter(
1313
- (blockedTool) => !blockedCanonical.has(blockedTool),
1314
- );
1315
- if (missingBlockedTools.length === 1) {
1316
- errors.push(`presentation must record "${missingBlockedTools[0]}" as blocked during run-uat`);
1317
- } else if (missingBlockedTools.length > 1) {
1318
- errors.push(`presentation must record ${quoteToolNames(missingBlockedTools)} as blocked during run-uat`);
1319
- }
1320
- return errors.length > 0 ? errors.join("; ") : null;
1321
- }
1322
-
1323
- function nextUatAttempt(basePath: string, milestoneId: string, sliceId: string): number {
1324
- const contract = resolveGsdPathContract(basePath);
1325
- const dir = join(contract.projectGsd, "uat", milestoneId, sliceId);
1326
- if (!existsSync(dir)) return 1;
1327
- let max = 0;
1328
- for (const entry of readdirSync(dir)) {
1329
- const match = /^attempt-(\d+)\.json$/.exec(entry);
1330
- if (match) max = Math.max(max, Number(match[1]));
1331
- }
1332
- return max + 1;
1333
- }
1334
-
1335
- function escapeMarkdownTableCell(value: unknown): string {
1336
- return String(value ?? "")
1337
- .replace(/[\\|]/g, (char) => `\\${char}`)
1338
- .replace(/\r?\n/g, "<br>");
1339
- }
1340
-
1341
- function renderUatAssessment(
1342
- params: UatResultSaveParams,
1343
- attempt: number,
1344
- gateVerdict: "pass" | "flag",
1345
- basePath: string,
1346
- ): string {
1347
- const lines = [
1348
- "---",
1349
- `sliceId: ${params.sliceId}`,
1350
- `uatType: ${params.uatType}`,
1351
- `verdict: ${params.verdict}`,
1352
- `attempt: ${attempt}`,
1353
- `date: ${new Date().toISOString()}`,
1354
- "---",
1355
- "",
1356
- `# UAT Result - ${params.sliceId}`,
1357
- "",
1358
- "## Checks",
1359
- "",
1360
- "| Check | Mode | Result | Evidence | Notes |",
1361
- "|-------|------|--------|----------|-------|",
1362
- ...params.checks.map((check) => {
1363
- const evidence = (check.evidence ?? []).map((entry) => `${entry.kind}:${entry.ref}`).join("<br>") || "-";
1364
- return `| ${escapeMarkdownTableCell(check.description)} | ${escapeMarkdownTableCell(check.mode)} | ${escapeMarkdownTableCell(check.result)} | ${escapeMarkdownTableCell(evidence)} | ${escapeMarkdownTableCell(check.notes)} |`;
1365
- }),
1366
- "",
1367
- "## Overall Verdict",
1368
- "",
1369
- `${params.verdict} - ${params.notes ?? "UAT result saved."}`,
1370
- "",
1371
- "## Tool Presentation",
1372
- "",
1373
- "```json",
1374
- JSON.stringify(params.presentation, null, 2),
1375
- "```",
1376
- "",
1377
- "## Gate",
1378
- "",
1379
- `Aggregate UAT gate saved as ${gateVerdict}.`,
1380
- ];
1381
-
1382
- // When any check still needs a human, point them at the exact checkout to
1383
- // validate — critical for worktree milestones whose code sits under a hidden
1384
- // `.gsd/worktrees/` path the reviewer would otherwise have to hunt for.
1385
- const hasHuman = params.checks.some((check) => check.result === "NEEDS-HUMAN");
1386
- if (hasHuman) {
1387
- const guidance = buildManualValidationGuidance(basePath, params.milestoneId, {
1388
- uatPath: relSliceFile(basePath, params.milestoneId, params.sliceId, "UAT"),
1389
- });
1390
- if (guidance) {
1391
- lines.push(
1392
- "",
1393
- "## Manual Validation",
1394
- "",
1395
- "One or more checks are marked `NEEDS-HUMAN` and require a person to validate:",
1396
- "",
1397
- ...guidance.split("\n").map((line) => `- ${line}`),
1398
- );
1399
- }
1400
- }
1401
-
1402
- return `${lines.join("\n")}\n`;
1403
- }
1404
-
1405
- async function saveUatAttemptArtifact(basePath: string, params: UatResultSaveParams, attempt: number): Promise<string> {
1406
- const contract = resolveGsdPathContract(basePath);
1407
- const relativePath = `uat/${params.milestoneId}/${params.sliceId}/attempt-${attempt}.json`;
1408
- await saveFile(join(contract.projectGsd, relativePath), `${JSON.stringify({ ...params, attempt }, null, 2)}\n`);
1409
- return relativePath;
1410
- }
1411
-
1412
974
  export async function executeUatResultSave(
1413
975
  params: UatResultSaveParams,
1414
976
  basePath: string = process.cwd(),
@@ -1416,110 +978,88 @@ export async function executeUatResultSave(
1416
978
  const unitGuard = blockIfWrongAutoUnit("run-uat", "save_uat_result");
1417
979
  if (unitGuard) return unitGuard;
1418
980
 
1419
- // Phase 1: normalize verdict and supply the canonical presentation when none was provided.
1420
- params = normalizeUatVerdict(params);
1421
- params = supplyDefaultPresentation(params);
1422
-
1423
981
  const dbAvailable = await ensureDbOpen(basePath);
1424
982
  if (!dbAvailable) return errorResult("save_uat_result", "GSD database is not available.", "db_unavailable");
1425
983
 
1426
- // Phase 2: validate the submitted presentation before the canonical merge so that
1427
- // presentations missing required workflow tools are rejected rather than silently patched.
1428
- const requiredError = ensureUatRequiredFields(params);
1429
- if (requiredError) return errorResult("save_uat_result", requiredError, "invalid_params");
1430
- const presentationError = validateCanonicalPresentation(params);
1431
- if (presentationError) return errorResult("save_uat_result", presentationError, "alias_tool_name");
1432
-
1433
- // Phase 3: merge in the canonical plan ID and read-only audit tools so the persisted
1434
- // artifact always carries the full audit surface even when the provider omitted them.
1435
- params = mergeCanonicalPresentation(params);
1436
- const checkError = validateUatChecks(basePath, params);
1437
- if (checkError) return errorResult("save_uat_result", checkError, "invalid_evidence");
1438
- const freshEvidenceError = validateFreshUatOwnedEvidence(params);
1439
- if (freshEvidenceError) return errorResult("save_uat_result", freshEvidenceError, "missing_fresh_uat_evidence");
1440
- const modeError = validateUatMode(params);
1441
- if (modeError) return errorResult("save_uat_result", modeError, "uat_mode_mismatch");
984
+ const prepared = prepareUatRun(basePath, params);
985
+ if (!prepared.ok) {
986
+ return errorResult("save_uat_result", prepared.error.message, prepared.error.code);
987
+ }
988
+ const { run } = prepared;
1442
989
 
1443
990
  try {
1444
- const attempt = params.attempt === "auto" || params.attempt === undefined
1445
- ? nextUatAttempt(basePath, params.milestoneId, params.sliceId)
1446
- : typeof params.attempt === "string"
1447
- ? Number.parseInt(params.attempt, 10)
1448
- : params.attempt;
1449
- if (!Number.isInteger(attempt) || attempt < 1) {
1450
- return errorResult("save_uat_result", "attempt must be a positive integer or auto", "invalid_attempt");
1451
- }
1452
- const gateVerdict = params.verdict === "PASS" ? "pass" : "flag";
1453
- const rationale = params.notes ?? `UAT ${params.verdict} for ${params.sliceId}.`;
1454
- const assessment = renderUatAssessment(params, attempt, gateVerdict, basePath);
1455
991
  const summary = await executeSummarySave(
1456
992
  {
1457
- milestone_id: params.milestoneId,
1458
- slice_id: params.sliceId,
993
+ milestone_id: run.params.milestoneId,
994
+ slice_id: run.params.sliceId,
1459
995
  artifact_type: "ASSESSMENT",
1460
- content: assessment,
996
+ content: run.assessment,
1461
997
  },
1462
998
  basePath,
1463
999
  );
1464
1000
  if (summary.isError) return summary;
1465
- const attemptPath = await saveUatAttemptArtifact(basePath, params, attempt);
1466
- const evaluatedAt = new Date().toISOString();
1001
+ const assessmentPath = relSliceFile(basePath, run.params.milestoneId, run.params.sliceId, "ASSESSMENT");
1002
+ insertAssessment({
1003
+ path: assessmentPath,
1004
+ milestoneId: run.params.milestoneId,
1005
+ sliceId: run.params.sliceId,
1006
+ taskId: null,
1007
+ status: run.params.verdict.toLowerCase(),
1008
+ scope: "run-uat",
1009
+ fullContent: run.assessment,
1010
+ });
1011
+ const attemptPath = await saveUatAttemptArtifact(basePath, run);
1467
1012
  upsertQualityGate({
1468
- milestoneId: params.milestoneId,
1469
- sliceId: params.sliceId,
1013
+ milestoneId: run.params.milestoneId,
1014
+ sliceId: run.params.sliceId,
1470
1015
  gateId: "UAT",
1471
1016
  scope: "slice",
1472
1017
  taskId: "",
1473
1018
  status: "complete",
1474
- verdict: gateVerdict,
1475
- rationale,
1476
- findings: assessment,
1477
- evaluatedAt,
1019
+ verdict: run.gateVerdict,
1020
+ rationale: run.rationale,
1021
+ findings: run.assessment,
1022
+ evaluatedAt: run.evaluatedAt,
1478
1023
  });
1479
1024
  insertGateRun({
1480
- traceId: `uat:${params.milestoneId}:${params.sliceId}`,
1481
- turnId: `uat:${params.sliceId}:attempt-${attempt}`,
1025
+ traceId: `uat:${run.params.milestoneId}:${run.params.sliceId}`,
1026
+ turnId: run.runId,
1482
1027
  gateId: "UAT",
1483
1028
  gateType: "uat",
1484
1029
  unitType: "run-uat",
1485
- unitId: `run-uat:${params.milestoneId}/${params.sliceId}`,
1486
- milestoneId: params.milestoneId,
1487
- sliceId: params.sliceId,
1488
- outcome: params.verdict === "PASS" ? "pass" : "fail",
1489
- failureClass: params.verdict === "PASS" ? "none" : "verification",
1490
- rationale,
1491
- findings: assessment,
1492
- attempt,
1493
- maxAttempts: attempt,
1494
- retryable: params.verdict !== "PASS",
1495
- evaluatedAt,
1030
+ unitId: `run-uat:${run.params.milestoneId}/${run.params.sliceId}`,
1031
+ milestoneId: run.params.milestoneId,
1032
+ sliceId: run.params.sliceId,
1033
+ outcome: run.gateOutcome,
1034
+ failureClass: run.params.verdict === "PASS" ? "none" : "verification",
1035
+ rationale: run.rationale,
1036
+ findings: run.assessment,
1037
+ attempt: run.attempt,
1038
+ maxAttempts: run.attempt,
1039
+ retryable: run.params.verdict !== "PASS",
1040
+ evaluatedAt: run.evaluatedAt,
1496
1041
  });
1497
1042
  invalidateStateCache();
1498
- // Surface where to validate when checks are left for a human, so the path
1499
- // (often a buried worktree checkout) reaches the reviewer, not just the file.
1500
- const hasHuman = params.checks.some((check) => check.result === "NEEDS-HUMAN");
1501
- const manualGuidance = hasHuman
1502
- ? buildManualValidationGuidance(basePath, params.milestoneId, {
1503
- uatPath: relSliceFile(basePath, params.milestoneId, params.sliceId, "UAT"),
1504
- })
1505
- : null;
1506
- const savedText = `UAT result saved for ${params.milestoneId}/${params.sliceId}: ${params.verdict}`;
1043
+ const savedText = `UAT result saved for ${run.params.milestoneId}/${run.params.sliceId}: ${run.params.verdict}`;
1507
1044
  return {
1508
1045
  content: [{
1509
1046
  type: "text",
1510
- text: manualGuidance ? `${savedText}\n\nManual validation needed:\n${manualGuidance}` : savedText,
1047
+ text: run.manualGuidance ? `${savedText}\n\nManual validation needed:\n${run.manualGuidance}` : savedText,
1511
1048
  }],
1512
1049
  details: {
1513
1050
  operation: "save_uat_result",
1514
- milestoneId: params.milestoneId,
1515
- sliceId: params.sliceId,
1516
- verdict: params.verdict,
1517
- gateVerdict,
1518
- attempt,
1051
+ milestoneId: run.params.milestoneId,
1052
+ sliceId: run.params.sliceId,
1053
+ verdict: run.params.verdict,
1054
+ gateVerdict: run.gateVerdict,
1055
+ attempt: run.attempt,
1519
1056
  attemptPath,
1520
- recommendedNextUnit: params.verdict === "PASS" ? null : "reactive-execute",
1521
- ...(hasHuman
1522
- ? { manualValidationPath: resolveCanonicalMilestoneRoot(basePath, params.milestoneId) }
1057
+ runId: run.runId,
1058
+ worktreeRoot: run.worktreeRoot,
1059
+ browserToolsPresented: run.browserToolsPresented,
1060
+ recommendedNextUnit: run.params.verdict === "PASS" ? null : "reactive-execute",
1061
+ ...(run.hasHuman
1062
+ ? { manualValidationPath: run.worktreeRoot }
1523
1063
  : {}),
1524
1064
  },
1525
1065
  };
@@ -35,6 +35,7 @@ export interface RoadmapSliceEntry {
35
35
  depends: string[]; // e.g. ["S01", "S02"]
36
36
  done: boolean;
37
37
  demo: string; // the "After this:" sentence
38
+ isSketch?: boolean; // ADR-011: true when the roadmap shows the `[sketch]` badge
38
39
  }
39
40
 
40
41
  export interface BoundaryMapEntry {