specdojo 0.3.0 → 0.4.0

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 (245) hide show
  1. package/CHANGELOG.md +65 -0
  2. package/README.md +77 -18
  3. package/dist/catalog/build-references.js +144 -0
  4. package/dist/catalog/build-render.js +32 -0
  5. package/dist/{catalog-build.js → catalog/build.js} +18 -295
  6. package/dist/{catalog.js → catalog/catalog.js} +11 -11
  7. package/dist/{catalog-generate.js → catalog/generate.js} +13 -16
  8. package/dist/catalog/paths.js +1 -0
  9. package/dist/{catalog-plan-generate.js → catalog/plan-generate.js} +5 -5
  10. package/dist/{catalog-plan.js → catalog/plan.js} +9 -9
  11. package/dist/{catalog-scaffold.js → catalog/scaffold.js} +6 -6
  12. package/dist/{agent.js → commands/agent.js} +11 -11
  13. package/dist/{build-command.js → commands/build.js} +2 -2
  14. package/dist/{init-command.js → commands/init.js} +103 -37
  15. package/dist/{orchestrator.js → commands/orchestrator.js} +2 -2
  16. package/dist/{watch.js → commands/watch.js} +3 -3
  17. package/dist/dashboard/dashboard-timeline.js +175 -0
  18. package/dist/{dashboard.js → dashboard/dashboard.js} +16 -549
  19. package/dist/dashboard/exec-records.js +105 -0
  20. package/dist/dashboard/routines.js +256 -0
  21. package/dist/dashboard/shared.js +14 -0
  22. package/dist/{timeline-build.js → dashboard/timeline-build.js} +2 -1
  23. package/dist/{timeline.js → dashboard/timeline.js} +1 -1
  24. package/dist/{deliverable.js → deliverable/deliverable.js} +5 -5
  25. package/dist/{deliverable-trash.js → deliverable/trash.js} +7 -7
  26. package/dist/{devcontainer-command.js → devcontainer/command.js} +5 -3
  27. package/dist/{devcontainer-scaffold.js → devcontainer/scaffold.js} +94 -2
  28. package/dist/{doc-index.js → docs/doc-index.js} +3 -3
  29. package/dist/{frontmatter-namespace.js → docs/frontmatter-namespace.js} +2 -2
  30. package/dist/{index-command.js → docs/index-command.js} +1 -1
  31. package/dist/docs/template-resolution.js +1 -0
  32. package/dist/{viewpoint-document-kinds-check.js → docs/viewpoint-document-kinds-check.js} +3 -3
  33. package/dist/{yaml-pages-command.js → docs/yaml-pages-command.js} +1 -1
  34. package/dist/{yaml-pages.js → docs/yaml-pages.js} +5 -5
  35. package/dist/{exec-agent-config.js → exec/agent-config.js} +33 -4
  36. package/dist/{exec-agent-git-state.js → exec/agent-git-state.js} +1 -1
  37. package/dist/{exec-agent-protected-config.js → exec/agent-protected-config.js} +1 -1
  38. package/dist/{exec.js → exec/commands.js} +22 -467
  39. package/dist/exec/core.js +457 -0
  40. package/dist/{exec-events.js → exec/events.js} +2 -2
  41. package/dist/{exec-evidence.js → exec/evidence.js} +11 -6
  42. package/dist/exec/exec.js +2 -0
  43. package/dist/exec/format.js +1 -0
  44. package/dist/{exec-handoff.js → exec/handoff.js} +13 -12
  45. package/dist/{exec-limit.js → exec/limit.js} +93 -12
  46. package/dist/{exec-parent-validation.js → exec/parent-validation.js} +4 -4
  47. package/dist/{exec-pipeline-state.js → exec/pipeline-state.js} +16 -2
  48. package/dist/{exec-plans.js → exec/plans-core.js} +97 -468
  49. package/dist/exec/plans-generation.js +249 -0
  50. package/dist/exec/plans-storage.js +131 -0
  51. package/dist/exec/plans.js +3 -0
  52. package/dist/{exec-project.js → exec/project.js} +1 -1
  53. package/dist/{exec-protection-handoff.js → exec/protection-handoff.js} +3 -3
  54. package/dist/{exec-register-resume.js → exec/register-resume.js} +2 -2
  55. package/dist/{exec-register.js → exec/register.js} +92 -9
  56. package/dist/exec/repo-integration-git.js +23 -0
  57. package/dist/exec/repo-integration-sync.js +264 -0
  58. package/dist/{exec-repo-integration.js → exec/repo-integration.js} +13 -287
  59. package/dist/{exec-repo-trace.js → exec/repo-trace.js} +3 -3
  60. package/dist/exec/reporter-output.js +206 -0
  61. package/dist/{exec-reporter.js → exec/reporter.js} +29 -216
  62. package/dist/{exec-results.js → exec/results.js} +277 -36
  63. package/dist/exec/run/agent-pipeline.js +276 -0
  64. package/dist/exec/run/agent.js +583 -0
  65. package/dist/exec/run/in-place.js +570 -0
  66. package/dist/exec/run/job.js +746 -0
  67. package/dist/exec/run/lifecycle-commands.js +530 -0
  68. package/dist/{exec-run-lock.js → exec/run/lock.js} +4 -3
  69. package/dist/exec/run/mode-shared.js +140 -0
  70. package/dist/exec/run/register-command.js +252 -0
  71. package/dist/exec/run/register-core.js +411 -0
  72. package/dist/exec/run/register-mode.js +210 -0
  73. package/dist/exec/run/register-resume.js +398 -0
  74. package/dist/exec/run/register-state.js +325 -0
  75. package/dist/exec/run/register-worktree.js +540 -0
  76. package/dist/exec/run/run.js +11 -0
  77. package/dist/exec/run/schedule-mode.js +294 -0
  78. package/dist/exec/run/schedule-prepare.js +366 -0
  79. package/dist/exec/run/schedule-task.js +599 -0
  80. package/dist/exec/run/shared.js +449 -0
  81. package/dist/{exec-schedule-calendar.js → exec/schedule/calendar.js} +1 -1
  82. package/dist/{exec-schedule-cpm.js → exec/schedule/cpm.js} +2 -2
  83. package/dist/{exec-schedule-gantt-chart-render.js → exec/schedule/gantt-chart-render.js} +2 -2
  84. package/dist/exec/schedule/gantt-chart.js +2 -0
  85. package/dist/{exec-schedule-hash.js → exec/schedule/hash.js} +2 -2
  86. package/dist/exec/schedule/index.js +1 -0
  87. package/dist/{exec-schedule-initial.js → exec/schedule/initial.js} +2 -2
  88. package/dist/{exec-schedule-progress.js → exec/schedule/progress.js} +2 -2
  89. package/dist/{exec-schedule-ready.js → exec/schedule/ready.js} +2 -2
  90. package/dist/{exec-schedule.js → exec/schedule/schedule.js} +11 -11
  91. package/dist/exec/shared.js +63 -0
  92. package/dist/exec/slot-lock.js +1 -0
  93. package/dist/{exec-strategy.js → exec/strategy.js} +2 -2
  94. package/dist/{exec-task-repos.js → exec/task-repos.js} +2 -2
  95. package/dist/{exec-task-view.js → exec/task-view.js} +4 -4
  96. package/dist/{exec-trial.js → exec/trial-commands.js} +23 -388
  97. package/dist/exec/trial-core.js +371 -0
  98. package/dist/exec/trial.js +2 -0
  99. package/dist/{exec-worktree-command.js → exec/worktree-command.js} +25 -23
  100. package/dist/exec/worktree-ops-commit.js +672 -0
  101. package/dist/exec/worktree-ops-lifecycle.js +297 -0
  102. package/dist/exec/worktree-ops-merge.js +344 -0
  103. package/dist/exec/worktree-ops.js +3 -0
  104. package/dist/exec/worktree.js +305 -0
  105. package/dist/grade/apply.js +734 -0
  106. package/dist/grade/command-apply.js +250 -0
  107. package/dist/grade/command-inspect.js +138 -0
  108. package/dist/grade/command-plan.js +101 -0
  109. package/dist/grade/command-shared.js +68 -0
  110. package/dist/grade/core.js +307 -0
  111. package/dist/grade/grade.js +19 -0
  112. package/dist/grade/markdown.js +274 -0
  113. package/dist/grade/pipeline-state.js +184 -0
  114. package/dist/grade/plan.js +507 -0
  115. package/dist/{grade-result.js → grade/result.js} +7 -96
  116. package/dist/grade/target-discovery.js +265 -0
  117. package/dist/grade/targets.js +435 -0
  118. package/dist/{job.js → job/definition.js} +32 -574
  119. package/dist/job/job.js +568 -0
  120. package/dist/{kata-command.js → kata/command.js} +4 -4
  121. package/dist/{kata.js → kata/kata.js} +5 -5
  122. package/dist/register/approach.js +134 -0
  123. package/dist/register/command-types.js +1 -0
  124. package/dist/register/core.js +369 -0
  125. package/dist/register/create-commands.js +352 -0
  126. package/dist/{register-date.js → register/date.js} +1 -1
  127. package/dist/register/derivation.js +163 -0
  128. package/dist/{register-event-merge.js → register/event-merge.js} +32 -3
  129. package/dist/{register-events.js → register/events.js} +12 -6
  130. package/dist/{register-history.js → register/history.js} +7 -6
  131. package/dist/{register-item.js → register/item.js} +28 -10
  132. package/dist/register/lifecycle-lock.js +5 -0
  133. package/dist/register/maintenance-commands.js +193 -0
  134. package/dist/{register-migrate-timestamps.js → register/migrate-timestamps.js} +3 -3
  135. package/dist/register/migration.js +268 -0
  136. package/dist/register/register.js +404 -0
  137. package/dist/register/renumber.js +341 -0
  138. package/dist/register/transition-commands.js +248 -0
  139. package/dist/register/update.js +230 -0
  140. package/dist/register/views.js +296 -0
  141. package/dist/{review-grade.js → review/grade.js} +2 -2
  142. package/dist/{review-plan.js → review/plan.js} +5 -5
  143. package/dist/routine/definition.js +401 -0
  144. package/dist/{routine.js → routine/routine.js} +50 -419
  145. package/dist/{schedule-approach.js → schedule/approach.js} +9 -9
  146. package/dist/{schedule-build.js → schedule/build.js} +7 -4
  147. package/dist/{schedule.js → schedule/schedule.js} +9 -9
  148. package/dist/schedule/strategy-generate-document.js +273 -0
  149. package/dist/schedule/strategy-generate-scope.js +199 -0
  150. package/dist/schedule/strategy-generate.js +348 -0
  151. package/dist/shared/agent-types.js +23 -0
  152. package/dist/shared/artifact-path.js +9 -0
  153. package/dist/{build-if-stale.js → shared/build-if-stale.js} +1 -1
  154. package/dist/shared/catalog-render.js +115 -0
  155. package/dist/{exec-slot-lock.js → shared/cross-process-lock.js} +3 -1
  156. package/dist/shared/fs.js +30 -0
  157. package/dist/shared/git.js +316 -0
  158. package/dist/shared/grade-result.js +94 -0
  159. package/dist/{package-paths.js → shared/package-paths.js} +3 -3
  160. package/dist/shared/plan-templates.js +114 -0
  161. package/dist/{exec-provider-scaffold.js → shared/provider-scaffold.js} +3 -1
  162. package/dist/shared/random.js +4 -0
  163. package/dist/{exec-schedule-index.js → shared/schedule-index.js} +3 -1
  164. package/dist/shared/schedule-paths.js +9 -0
  165. package/dist/{specdojo-config.js → shared/specdojo-config.js} +96 -9
  166. package/dist/{exec-shared.js → shared/text.js} +0 -134
  167. package/dist/shared/time.js +28 -0
  168. package/dist/shared/yaml.js +28 -0
  169. package/dist/specdojo.js +22 -22
  170. package/docs/ja/specdojo/exec-templates/xep-common-conventions-template.md +29 -17
  171. package/docs/ja/specdojo/exec-templates/xep-register-investigate-template.md +1 -2
  172. package/docs/ja/specdojo/exec-templates/xep-register-template.md +1 -2
  173. package/docs/ja/specdojo/exec-templates/xer-template.md +1 -3
  174. package/docs/ja/specdojo/exec-templates/xrp-job-template.md +6 -4
  175. package/docs/ja/specdojo/guides/exec-config-guide.md +97 -22
  176. package/docs/ja/specdojo/guides/exec-operation-guide.md +145 -12
  177. package/docs/ja/specdojo/guides/exec-worktree-guide.md +2 -0
  178. package/docs/ja/specdojo/guides/orchestrator-operation-guide.md +51 -18
  179. package/docs/ja/specdojo/guides/quick-start-guide.md +81 -16
  180. package/docs/ja/specdojo/guides/register-operation-guide.md +2 -1
  181. package/docs/ja/specdojo/guides/remote-host-development-guide.md +10 -1
  182. package/docs/ja/specdojo/guides/review-guide.md +1 -1
  183. package/docs/ja/specdojo/guides/routine-operation-guide.md +6 -6
  184. package/docs/ja/specdojo/guides/use-case-guide.md +1 -1
  185. package/docs/ja/specdojo/references/command-reference.md +52 -28
  186. package/docs/ja/specdojo/rulebooks/pjr-rulebook.md +17 -11
  187. package/docs/ja/specdojo/standards/job-definition-standard.md +20 -18
  188. package/docs/ja/specdojo/standards/rulebook-authoring-standard.md +2 -2
  189. package/docs/ja/specdojo/templates/pjr-derived-items-template.md +22 -0
  190. package/docs/ja/specdojo/templates/pjr-index-template.md +1 -0
  191. package/docs/specdojo/schemas/v1/agent-members.schema.yaml +29 -2
  192. package/docs/specdojo/schemas/v1/exec-defaults.schema.yaml +20 -0
  193. package/docs/specdojo/schemas/v1/exec-evidence.schema.yaml +23 -0
  194. package/docs/specdojo/schemas/v1/job-run.schema.yaml +2 -2
  195. package/docs/specdojo/schemas/v1/job.schema.yaml +7 -0
  196. package/docs/specdojo/schemas/v1/pipeline-state.schema.yaml +26 -0
  197. package/docs/specdojo/schemas/v1/register-events.schema.yaml +3 -0
  198. package/docs/specdojo/schemas/v1/register-item-frontmatter.schema.yaml +70 -7
  199. package/docs/specdojo/schemas/v1/routine-run.schema.yaml +1 -1
  200. package/docs/specdojo/schemas/v1/specdojo-config.schema.yaml +1 -1
  201. package/package.json +4 -5
  202. package/templates/antigravity/README.md +7 -3
  203. package/templates/antigravity/agent-members-snippet.yaml +108 -12
  204. package/templates/antigravity/exec-defaults-snippet.yaml +10 -13
  205. package/templates/claude/README.md +27 -3
  206. package/templates/claude/agents/claude-executor.md +0 -1
  207. package/templates/claude/agents/claude-reporter.md +2 -1
  208. package/templates/claude/agents/claude-review-executor.md +0 -1
  209. package/templates/codex/README.md +23 -4
  210. package/templates/devcontainer/devcontainer.json +2 -2
  211. package/templates/devcontainer/remote-host/specdojo-tmux.sh.sample +69 -0
  212. package/templates/devcontainer/remote-host/ssh-config.sample +16 -0
  213. package/templates/init-agent-members.yaml +75 -25
  214. package/templates/init-exec-defaults.yaml +26 -8
  215. package/templates/opencode/README.md +17 -3
  216. package/templates/opencode/agents/opencode-executor.md +0 -1
  217. package/templates/opencode/agents/opencode-reporter.md +2 -1
  218. package/templates/opencode/agents/opencode-review-executor.md +0 -1
  219. package/dist/exec-run.js +0 -6182
  220. package/dist/exec-schedule-gantt-chart.js +0 -2
  221. package/dist/exec-worktree-ops.js +0 -1292
  222. package/dist/exec-worktree.js +0 -446
  223. package/dist/grade.js +0 -3193
  224. package/dist/register.js +0 -2407
  225. package/dist/schedule-strategy-generate.js +0 -812
  226. package/templates/claude/agents/claude-expert-review-executor.md +0 -14
  227. /package/dist/{catalog-plan-prompt.js → catalog/plan-prompt.js} +0 -0
  228. /package/dist/{catalog-types.js → catalog/types.js} +0 -0
  229. /package/dist/{template-frontmatter.js → docs/template-frontmatter.js} +0 -0
  230. /package/dist/{role-types.js → exec/role-types.js} +0 -0
  231. /package/dist/{exec-schedule-gantt-chart-scope.js → exec/schedule/gantt-chart-scope.js} +0 -0
  232. /package/dist/{exec-types.js → exec/types.js} +0 -0
  233. /package/dist/{review-types.js → review/types.js} +0 -0
  234. /package/dist/{schedule-phase-sets.js → schedule/phase-sets.js} +0 -0
  235. /package/dist/{schedule-strategy-profiles.js → schedule/strategy-profiles.js} +0 -0
  236. /package/dist/{agent-response.js → shared/agent-response.js} +0 -0
  237. /package/dist/{catalog-paths.js → shared/catalog-paths.js} +0 -0
  238. /package/dist/{dist-freshness.js → shared/dist-freshness.js} +0 -0
  239. /package/dist/{git-environment.js → shared/git-environment.js} +0 -0
  240. /package/dist/{exec-format.js → shared/markdown-format.js} +0 -0
  241. /package/dist/{practice-id.js → shared/practice-id.js} +0 -0
  242. /package/dist/{spawn-self.js → shared/spawn-self.js} +0 -0
  243. /package/dist/{specdojo-gitignore.js → shared/specdojo-gitignore.js} +0 -0
  244. /package/dist/{template-resolution.js → shared/template-resolution.js} +0 -0
  245. /package/dist/{yaml-schema-modeline.js → shared/yaml-schema-modeline.js} +0 -0
@@ -1,381 +1,18 @@
1
- import { spawn } from "node:child_process";
2
- import { createHash, randomUUID } from "node:crypto";
3
- import { copyFileSync, existsSync, readFileSync, renameSync, writeFileSync } from "node:fs";
4
- import { basename, dirname, join, relative, resolve, sep } from "node:path";
5
- import { defaultExecDefaultsPath, loadExecDefaultsConfig, resolveMemberCommand, resolveRateLimitDetection, } from "./exec-agent-config.js";
6
- import { agentProtectedConfigViolation, captureAgentProtectedConfigSnapshot, changedAgentProtectedConfigPaths, isAgentProtectedConfigPath, } from "./exec-agent-protected-config.js";
7
- import { agentGitStateViolation, captureAgentGitStateSnapshot, changedAgentGitStateFields, } from "./exec-agent-git-state.js";
8
- import { recordExecutorEvidence, recordParentValidationFailureOutput, } from "./exec-evidence.js";
9
- import { parentValidationLabels, } from "./exec-parent-validation.js";
10
- import { activateResolvedProjectPaths, resolveProjectPaths } from "./exec-project.js";
11
- import { buildExecutorPrompt, isRateLimitError, loadRosterForExecutionPath, runConfiguredParentValidationBatch, } from "./exec-run.js";
12
- import { parsePlanTaskIdentity } from "./exec-plans.js";
13
- import { deriveReporterFacts, evidenceForReporter, runReporterWithFormatRetry, } from "./exec-reporter.js";
14
- import { ensureDir, safeSlug } from "./exec-shared.js";
15
- import { ensureExecWorktree, execBranchExists, findExecWorktree, gitEnvironment, gitOutput, gitResult, resolveWorktreeBase, worktreeNameFromTaskId, } from "./exec-worktree.js";
16
- import { getProjectSchedulePath, loadConfig, specdojoRootDir, } from "./specdojo-config.js";
17
- const TRIAL_PROMPT_SUFFIX = `
18
-
19
- ---
20
-
21
- # Agent comparison trial instructions
22
-
23
- This is an isolated comparison trial. Edit and validate the artifacts required by the plan, but
24
- do not update task lifecycle state or create/update the result file. End the final response with
25
- exactly one machine-readable executor evidence envelope as documented by SpecDojo.
26
- `;
27
- function sha256(value) {
28
- return createHash("sha256").update(value).digest("hex");
29
- }
30
- function normalizePlanPathCandidate(value) {
31
- const candidate = value
32
- .trim()
33
- .replace(/^\.\//u, "")
34
- .replace(/:\d+(?::\d+)?$/u, "")
35
- .replace(/[.,;]$/u, "");
36
- if (!candidate ||
37
- candidate.startsWith("/") ||
38
- candidate.includes("://") ||
39
- /[\s<>{}*?$]/u.test(candidate) ||
40
- candidate === ".env" ||
41
- candidate.startsWith("secrets/")) {
42
- return null;
43
- }
44
- if (/^(?:\.specdojo|docs|scripts|src|tests|tools)\//u.test(candidate) ||
45
- /^(?:lefthook\.yml|package\.json|tsconfig[^/]*\.json|vitest[^/]*\.ts)$/u.test(candidate)) {
46
- return candidate;
47
- }
48
- return null;
49
- }
50
- export function extractPlanRepoPaths(plan) {
51
- const candidates = [];
52
- for (const match of plan.matchAll(/`([^`\n]+)`/gu))
53
- candidates.push(match[1]);
54
- for (const match of plan.matchAll(/\]\(([^)\s]+)(?:\s+[^)]*)?\)/gu))
55
- candidates.push(match[1]);
56
- return [
57
- ...new Set(candidates
58
- .map(normalizePlanPathCandidate)
59
- .filter((candidate) => candidate !== null)),
60
- ].sort();
61
- }
62
- function objectExistsAtCommit(repoRoot, commit, path) {
63
- return gitResult(repoRoot, ["cat-file", "-e", `${commit}:${path}`]).status === 0;
64
- }
65
- export function buildTrialBaseValidation(params) {
66
- const referencedPaths = extractPlanRepoPaths(params.planContent).map((path) => ({
67
- path,
68
- exists_at_base: objectExistsAtCommit(params.repoRoot, params.resolvedCommit, path),
69
- }));
70
- const missingReferencedPaths = referencedPaths
71
- .filter((entry) => !entry.exists_at_base)
72
- .map((entry) => entry.path);
73
- const planPathExistsAtBase = objectExistsAtCommit(params.repoRoot, params.resolvedCommit, params.planPath);
74
- const warnings = [];
75
- const baseIsAncestorOfHead = gitResult(params.repoRoot, [
76
- "merge-base",
77
- "--is-ancestor",
78
- params.resolvedCommit,
79
- params.headCommit,
80
- ]).status === 0;
81
- if (!baseIsAncestorOfHead) {
82
- warnings.push("The base commit is not an ancestor of HEAD; the current HEAD cannot be used as a linear reference result.");
83
- }
84
- if (!planPathExistsAtBase) {
85
- warnings.push("The plan file is not present at the base commit; the current plan content will still be supplied to every trial.");
86
- }
87
- if (missingReferencedPaths.length > 0) {
88
- warnings.push(`Referenced paths missing at the base commit: ${missingReferencedPaths.join(", ")}`);
89
- }
90
- return {
91
- requested_revision: params.requestedRevision,
92
- resolved_commit: params.resolvedCommit,
93
- head_commit_at_start: params.headCommit,
94
- base_is_ancestor_of_head: baseIsAncestorOfHead,
95
- defaulted_to_head: params.defaultedToHead,
96
- plan_path_exists_at_base: planPathExistsAtBase,
97
- compatible: baseIsAncestorOfHead && missingReferencedPaths.length === 0,
98
- referenced_paths: referencedPaths,
99
- missing_referenced_paths: missingReferencedPaths,
100
- warnings,
101
- };
102
- }
103
- export function classifyReporterFailure(result, reason) {
104
- if (result === "rate_limit")
105
- return "rate_limit";
106
- return reason.startsWith("reporter output invalid after")
107
- ? "invalid_output"
108
- : "invocation_failure";
109
- }
110
- function hasValidExecutorEnvelope(stdout) {
111
- const matches = [
112
- ...stdout.matchAll(/<specdojo_executor_evidence>\s*([\s\S]*?)\s*<\/specdojo_executor_evidence>/gu),
113
- ];
114
- const raw = matches.at(-1)?.[1];
115
- if (!raw)
116
- return false;
117
- try {
118
- const value = JSON.parse(raw);
119
- if (!value || typeof value !== "object" || Array.isArray(value))
120
- return false;
121
- const report = value;
122
- return typeof report.final_message === "string" && Array.isArray(report.validations);
123
- }
124
- catch {
125
- return false;
126
- }
127
- }
128
- function repoRelative(repoRoot, path) {
129
- const value = relative(repoRoot, path);
130
- if (!value || value === ".." || value.startsWith(`..${sep}`)) {
131
- throw new Error(`Path is outside repository root: ${path}`);
132
- }
133
- return value.split(sep).join("/");
134
- }
135
- function comparisonDir(executionPath, comparisonId) {
136
- return join(executionPath, "exec", "trials", safeSlug(comparisonId));
137
- }
138
- function comparisonPath(executionPath, comparisonId) {
139
- return join(comparisonDir(executionPath, comparisonId), "comparison.json");
140
- }
141
- function writeComparison(path, value) {
142
- ensureDir(dirname(path));
143
- const temporary = `${path}.${process.pid}.${randomUUID()}.tmp`;
144
- writeFileSync(temporary, `${JSON.stringify(value, null, 2)}\n`, "utf8");
145
- renameSync(temporary, path);
146
- }
147
- function readComparison(path) {
148
- if (!existsSync(path))
149
- throw new Error(`Comparison not found: ${path}`);
150
- return JSON.parse(readFileSync(path, "utf8"));
151
- }
152
- function configuredWorktreeBase(schedulePath) {
153
- const { config } = loadConfig();
154
- if (!config)
155
- return undefined;
156
- const rootDir = specdojoRootDir();
157
- for (const project of Object.values(config.projects)) {
158
- if (resolve(rootDir, getProjectSchedulePath(project)) === schedulePath) {
159
- return project.run?.worktree_base;
160
- }
161
- }
162
- return undefined;
163
- }
164
- function parsePositiveInteger(value, flag) {
165
- if (!value || !/^\d+$/.test(value) || Number(value) < 1) {
166
- throw new Error(`${flag} must be a positive integer: ${value ?? ""}`);
167
- }
168
- return Number(value);
169
- }
170
- function parseRating(value, flag) {
171
- if (value === undefined)
172
- return undefined;
173
- if (!/^[1-5]$/.test(value))
174
- throw new Error(`${flag} must be an integer from 1 to 5.`);
175
- return Number(value);
176
- }
177
- function resolveMember(roster, nickname, stageRole) {
178
- const member = roster?.members.find((candidate) => candidate.type === "agent" && candidate.nickname === nickname);
179
- if (!member)
180
- throw new Error(`Agent nickname not found in agent-members.yaml: ${nickname}`);
181
- if (member.disabled)
182
- throw new Error(`Agent is disabled in agent-members.yaml: ${nickname}`);
183
- if ((stageRole === "reporter" && member.stage_role !== "reporter") ||
184
- (stageRole === "executor" && member.stage_role === "reporter")) {
185
- throw new Error(`Agent must have stage_role: ${stageRole}: ${nickname}`);
186
- }
187
- return member;
188
- }
189
- function spawnAgent(command, prompt, cwd, env) {
190
- return new Promise((resolveOutcome) => {
191
- const protectedConfigBefore = captureAgentProtectedConfigSnapshot(cwd);
192
- const gitStateBefore = captureAgentGitStateSnapshot(cwd);
193
- const child = spawn(command, { cwd, env, shell: true, stdio: ["pipe", "pipe", "pipe"] });
194
- let stdout = "";
195
- let stderr = "";
196
- let settled = false;
197
- child.stdin.on("error", () => undefined);
198
- child.stdout.setEncoding("utf8");
199
- child.stderr.setEncoding("utf8");
200
- child.stdout.on("data", (chunk) => {
201
- stdout += chunk;
202
- process.stdout.write(chunk);
203
- });
204
- child.stderr.on("data", (chunk) => {
205
- stderr += chunk;
206
- process.stderr.write(chunk);
207
- });
208
- const finish = (outcome) => {
209
- if (settled)
210
- return;
211
- settled = true;
212
- const protectedChanges = changedAgentProtectedConfigPaths(cwd, protectedConfigBefore);
213
- if (protectedChanges.length > 0) {
214
- outcome.stderr += `${agentProtectedConfigViolation(protectedChanges)}\n`;
215
- outcome.exitCode = 1;
216
- }
217
- const gitStateChanges = changedAgentGitStateFields(cwd, gitStateBefore);
218
- if (gitStateChanges.length > 0) {
219
- outcome.stderr += `${agentGitStateViolation(gitStateChanges)}\n`;
220
- outcome.exitCode = 1;
221
- }
222
- resolveOutcome(outcome);
223
- };
224
- child.once("error", (error) => {
225
- stderr += `${error.message}\n`;
226
- finish({ exitCode: null, stdout, stderr });
227
- });
228
- child.once("close", (exitCode) => finish({ exitCode, stdout, stderr }));
229
- child.stdin.end(prompt);
230
- });
231
- }
232
- function worktreeEnvironment(repoRoot, worktreePath, schedulePath, executionPath) {
233
- return {
234
- ...gitEnvironment(),
235
- SPECDOJO_SCHEDULE_PATH: resolve(worktreePath, repoRelative(repoRoot, schedulePath)),
236
- SPECDOJO_EXECUTION_PATH: resolve(worktreePath, repoRelative(repoRoot, executionPath)),
237
- };
238
- }
239
- function blankTrial(params) {
240
- const trialId = safeSlug(params.trialId ?? params.agent);
241
- const worktreeTaskId = `${params.projectId}:trial:${params.comparisonId}:${trialId}`;
242
- const name = worktreeNameFromTaskId(worktreeTaskId);
243
- return {
244
- trial_id: trialId,
245
- agent: params.agent,
246
- reporter_agent: params.reporter ?? null,
247
- worktree: resolve(params.worktreeBase, name),
248
- branch: `exec/${name}`,
249
- status: "pending",
250
- started_at: null,
251
- completed_at: null,
252
- duration_ms: null,
253
- executor: {
254
- exit_code: null,
255
- attempts: 0,
256
- duration_ms: null,
257
- structured_output: false,
258
- validations_reported: 0,
259
- validations_passed: 0,
260
- validations_failed: 0,
261
- validations_not_run: 0,
262
- validations_requires_human: 0,
263
- files_changed: 0,
264
- evidence_ref: null,
265
- final_message: "",
266
- validations: [],
267
- changes: [],
268
- diff_summary: "",
269
- },
270
- parent_validation: {
271
- configured_ids: [...(params.parentValidationIds ?? [])],
272
- status: params.parentValidationIds?.length ? "not_run" : "not_configured",
273
- duration_ms: null,
274
- validations_passed: 0,
275
- validations_failed: 0,
276
- validations_not_run: 0,
277
- },
278
- reporter: {
279
- status: "not_run",
280
- structured_output: false,
281
- format_attempts: 0,
282
- format_retries: 0,
283
- outcome: null,
284
- output: null,
285
- failure_category: null,
286
- failure_reason: "",
287
- },
288
- subjective: {
289
- judgment_quality: null,
290
- writing_quality: null,
291
- scope_adherence: null,
292
- notes: "",
293
- },
294
- };
295
- }
296
- export function buildComparisonRecord(params) {
297
- const reporterMode = params.pairs ? "paired" : params.reporter ? "shared" : "none";
298
- const definitions = params.pairs ??
299
- (params.agents ?? []).map((agent) => ({ executor: agent, reporter: params.reporter }));
300
- const trialIds = definitions.map(({ executor, reporter }) => safeSlug(reporterMode === "paired" ? `${executor}-${reporter}` : executor));
301
- if (new Set(trialIds).size !== trialIds.length) {
302
- throw new Error("Trial executor/reporter selections must produce distinct trial ids.");
303
- }
304
- const baseValidation = params.baseValidation ??
305
- {
306
- requested_revision: "HEAD",
307
- resolved_commit: params.baseCommit,
308
- head_commit_at_start: params.baseCommit,
309
- base_is_ancestor_of_head: true,
310
- defaulted_to_head: true,
311
- plan_path_exists_at_base: true,
312
- compatible: true,
313
- referenced_paths: [],
314
- missing_referenced_paths: [],
315
- warnings: [],
316
- };
317
- return {
318
- schema_version: 1,
319
- comparison_id: params.comparisonId,
320
- project_id: params.projectId,
321
- task_id: params.taskId,
322
- status: "active",
323
- created_at: params.createdAt,
324
- completed_at: null,
325
- base_commit: params.baseCommit,
326
- base: baseValidation,
327
- reporter_mode: reporterMode,
328
- plan: {
329
- path: params.planPath,
330
- sha256: sha256(params.planContent),
331
- prompt_sha256: sha256(params.prompt),
332
- },
333
- selected_trial_id: null,
334
- trials: definitions.map(({ executor, reporter }, index) => blankTrial({
335
- projectId: params.projectId,
336
- comparisonId: params.comparisonId,
337
- agent: executor,
338
- trialId: trialIds[index],
339
- reporter,
340
- worktreeBase: params.worktreeBase,
341
- parentValidationIds: params.parentValidationIds,
342
- })),
343
- agent_selection: {
344
- policy: "manual",
345
- target: "agent-members.yaml",
346
- rationale: "A single comparison does not automatically change agent assignment. A human reviews objective and subjective results, then updates agent-members.yaml priority/capabilities when repeated evidence supports the change.",
347
- },
348
- };
349
- }
350
- export function updateObjectiveMetrics(trial, evidence, structuredOutput) {
351
- trial.executor.structured_output = structuredOutput;
352
- trial.executor.files_changed = evidence.diff_summary.files_changed;
353
- trial.executor.final_message = evidence.final_message;
354
- trial.executor.validations = evidence.validations;
355
- trial.executor.changes = evidence.changes;
356
- trial.executor.diff_summary = evidence.diff_summary.summary;
357
- const executorValidations = evidence.validations.filter((validation) => validation.source !== "runner");
358
- trial.executor.validations_reported = executorValidations.length;
359
- trial.executor.validations_passed = 0;
360
- trial.executor.validations_failed = 0;
361
- trial.executor.validations_not_run = 0;
362
- trial.executor.validations_requires_human = 0;
363
- for (const validation of executorValidations) {
364
- if (validation.status === "passed")
365
- trial.executor.validations_passed++;
366
- else if (validation.status === "failed")
367
- trial.executor.validations_failed++;
368
- else if (validation.status === "not_run")
369
- trial.executor.validations_not_run++;
370
- else if (validation.status === "requires_human") {
371
- trial.executor.validations_requires_human++;
372
- }
373
- }
374
- const parentValidations = evidence.validations.filter((validation) => validation.source === "runner");
375
- trial.parent_validation.validations_passed = parentValidations.filter((validation) => validation.status === "passed").length;
376
- trial.parent_validation.validations_failed = parentValidations.filter((validation) => validation.status === "failed").length;
377
- trial.parent_validation.validations_not_run = parentValidations.filter((validation) => validation.status === "not_run").length;
378
- }
1
+ import { randomUUID } from "node:crypto";
2
+ import { copyFileSync, existsSync, readFileSync, writeFileSync } from "node:fs";
3
+ import { basename, dirname, join, resolve } from "node:path";
4
+ import { defaultExecDefaultsPath, loadExecDefaultsConfig, resolveMemberCommand, resolveRateLimitDetection, } from "./agent-config.js";
5
+ import { agentProtectedConfigViolation, isAgentProtectedConfigPath, } from "./agent-protected-config.js";
6
+ import { recordExecutorEvidence, recordParentValidationFailureOutput, } from "./evidence.js";
7
+ import { parentValidationLabels } from "./parent-validation.js";
8
+ import { activateResolvedProjectPaths, resolveProjectPaths } from "./project.js";
9
+ import { buildExecutorPrompt, isRateLimitError, loadRosterForExecutionPath, runConfiguredParentValidationBatch, } from "./run/run.js";
10
+ import { parsePlanTaskIdentity } from "./plans.js";
11
+ import { deriveReporterFacts, evidenceForReporter, runReporterWithFormatRetry, } from "./reporter.js";
12
+ import { ensureDir, safeSlug } from "./shared.js";
13
+ import { ensureExecWorktree, execBranchExists, findExecWorktree, formatGitResultFailure, gitOutput, gitResult, resolveWorktreeBase, } from "./worktree.js";
14
+ import { specdojoRootDir } from "../shared/specdojo-config.js";
15
+ import { TRIAL_PROMPT_SUFFIX, buildComparisonRecord, buildTrialBaseValidation, classifyReporterFailure, comparisonDir, comparisonPath, configuredWorktreeBase, hasValidExecutorEnvelope, parsePositiveInteger, parseRating, readComparison, repoRelative, resolveMember, spawnAgent, updateObjectiveMetrics, worktreeEnvironment, writeComparison, } from "./trial-core.js";
379
16
  async function runOneTrial(params) {
380
17
  const { trial, worktree } = params;
381
18
  const startedAt = new Date();
@@ -549,14 +186,11 @@ function resolveTrialDefinitions(opts) {
549
186
  return { agents };
550
187
  }
551
188
  function resolveBaseCommit(repoRoot, revision) {
552
- const result = gitResult(repoRoot, [
553
- "rev-parse",
554
- "--verify",
555
- "--end-of-options",
556
- `${revision}^{commit}`,
557
- ]);
558
- if (result.status !== 0)
559
- throw new Error(`Trial base is not a commit: ${revision}`);
189
+ const args = ["rev-parse", "--verify", "--end-of-options", `${revision}^{commit}`];
190
+ const result = gitResult(repoRoot, args);
191
+ if (result.status !== 0) {
192
+ throw new Error(`Trial base is not a commit: ${revision}; ${formatGitResultFailure(args, result)}`);
193
+ }
560
194
  return String(result.stdout).trim();
561
195
  }
562
196
  async function runTrials(opts) {
@@ -771,7 +405,8 @@ function commitSelectedTrial(repoRoot, record, trial) {
771
405
  if (protectedPaths.length > 0)
772
406
  throw new Error(agentProtectedConfigViolation(protectedPaths));
773
407
  gitOutput(trial.worktree, ["add", "-A"]);
774
- const staged = gitResult(trial.worktree, ["diff", "--cached", "--quiet"]);
408
+ const stagedArgs = ["diff", "--cached", "--quiet"];
409
+ const staged = gitResult(trial.worktree, stagedArgs);
775
410
  if (staged.status === 1) {
776
411
  const commit = gitResult(trial.worktree, [
777
412
  "commit",
@@ -784,7 +419,7 @@ function commitSelectedTrial(repoRoot, record, trial) {
784
419
  }
785
420
  }
786
421
  else if (staged.status !== 0) {
787
- throw new Error("Failed to inspect selected trial changes.");
422
+ throw new Error(`Failed to inspect selected trial changes: ${formatGitResultFailure(stagedArgs, staged)}`);
788
423
  }
789
424
  const ahead = Number(gitOutput(trial.worktree, ["rev-list", "--count", `${record.base_commit}..HEAD`]).trim());
790
425
  if (!Number.isFinite(ahead) || ahead < 1)