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
@@ -0,0 +1,449 @@
1
+ import { basename, resolve } from "node:path";
2
+ import { defaultExecDefaultsPath, hasMemberCommandSource, loadExecDefaultsConfig, resolveMaxConcurrentRuns, resolveMemberCommand, resolveRegisterExecution, resolvePinnedRateLimitPolicy, } from "../agent-config.js";
3
+ import { resolveProjectPaths } from "../project.js";
4
+ import { buildInitialStateFromStrategy } from "../schedule/initial.js";
5
+ import { buildScheduleIndex } from "../schedule/schedule.js";
6
+ import { listFilesRecursive, readYaml } from "../shared.js";
7
+ import { getProjectSchedulePath, loadConfig, resolveAgentMember, specdojoRootDir, } from "../../shared/specdojo-config.js";
8
+ import { acquireExecRunLock, EXEC_RUN_LOCK_TOKEN_ENV, execLocksDir, inheritsExecRunLock, releaseExecRunLock, ROUTINE_BUSY_SKIP_EXIT_CODE, ROUTINE_EXEC_ENV, } from "./lock.js";
9
+ import { getActiveExecLocksDir, setActiveExecLocksDir } from "../slot-lock.js";
10
+ import { readAllEventFiles, foldEventsToState } from "../events.js";
11
+ import { extractPhaseSuffix, normalizePhaseSetSelection, phaseSetNames, } from "../../schedule/phase-sets.js";
12
+ export function rateLimitRecoveryReason(events) {
13
+ return events
14
+ .map((event) => event.action === "wait"
15
+ ? `rate limit wait: ${event.to_actor} resumed at ${event.resumed_at}`
16
+ : `rate limit fallback: ${event.from_actor} -> ${event.to_actor} at ${event.resumed_at}`)
17
+ .join("; ");
18
+ }
19
+ export function isPinnedRateLimitAction(value) {
20
+ return value === "stop" || value === "wait" || value === "fallback";
21
+ }
22
+ /**
23
+ * Resolve CLI-over-config recovery for one pinned pipeline stage. A fallback action without a
24
+ * fallback nickname intentionally degrades to stop, preserving the historical non-switching
25
+ * behaviour instead of choosing an arbitrary agent.
26
+ */
27
+ export function resolvePinnedRateLimitRunOptions(opts, execDefaults, roster, stageRole, primary) {
28
+ const configured = resolvePinnedRateLimitPolicy(execDefaults, primary.provider);
29
+ const requested = opts.onRateLimit;
30
+ if (requested !== undefined && !isPinnedRateLimitAction(requested)) {
31
+ throw new Error(`--on-rate-limit must be "stop", "wait", or "fallback": ${requested}`);
32
+ }
33
+ const action = requested ?? configured.action;
34
+ const nickname = stageRole === "executor"
35
+ ? (opts.fallbackExecutorBy ?? configured.fallbackExecutorBy)
36
+ : (opts.fallbackReporterBy ?? configured.fallbackReporterBy);
37
+ if (action !== "fallback" || !nickname) {
38
+ return {
39
+ action: action === "fallback" ? "stop" : action,
40
+ maxWaitSeconds: configured.maxWaitSeconds,
41
+ };
42
+ }
43
+ const resolution = resolveAgentOverride("edit", nickname, {}, roster, execDefaults, stageRole);
44
+ if (resolution.kind !== "command") {
45
+ const flag = stageRole === "executor" ? "--fallback-executor-by" : "--fallback-reporter-by";
46
+ const detail = resolution.kind === "error" ? resolution.message : `agent not found: ${nickname}`;
47
+ throw new Error(`${flag}: ${detail.replace(/^--by/, flag)}`);
48
+ }
49
+ if (resolution.actor === primary.actor) {
50
+ throw new Error(`Fallback ${stageRole} must differ from the pinned agent: ${nickname}`);
51
+ }
52
+ return {
53
+ action,
54
+ maxWaitSeconds: configured.maxWaitSeconds,
55
+ fallbackCandidate: {
56
+ command: resolution.command,
57
+ actor: resolution.actor ?? nickname,
58
+ provider: resolution.provider,
59
+ },
60
+ };
61
+ }
62
+ export function pinnedExecutor(task) {
63
+ return typeof task?.agent === "string" ? task.agent : task?.agent?.executor;
64
+ }
65
+ export function pinnedReporter(task) {
66
+ return typeof task?.agent === "object" ? task.agent.reporter : undefined;
67
+ }
68
+ // Resolve the agent override for a task's mode. A single explicit --by nickname wins for every
69
+ // mode. Otherwise the mode-specific --edit-by / --review-by nickname applies. Commands are always
70
+ // resolved from agent-members.yaml and exec-defaults.yaml; raw command strings are not accepted.
71
+ export function resolveAgentOverride(mode, agentNicknameOverride, modeAgentOverrides, roster, execDefaults = {}, stageRole) {
72
+ const nickname = agentNicknameOverride ??
73
+ (mode === "review" ? modeAgentOverrides.review : modeAgentOverrides.edit);
74
+ if (!nickname)
75
+ return { kind: "none" };
76
+ const flag = agentNicknameOverride ? "--by" : mode === "review" ? "--review-by" : "--edit-by";
77
+ const member = resolveAgentMember(roster, nickname);
78
+ if (member && stageRole !== undefined && member.stage_role !== stageRole) {
79
+ return {
80
+ kind: "error",
81
+ message: `${flag} agent must have stage_role: ${stageRole} for this pipeline stage: ${nickname}`,
82
+ };
83
+ }
84
+ let command;
85
+ try {
86
+ command = member ? resolveMemberCommand(execDefaults, member) : undefined;
87
+ }
88
+ catch (error) {
89
+ return { kind: "error", message: error instanceof Error ? error.message : String(error) };
90
+ }
91
+ if (!member || !command) {
92
+ return {
93
+ kind: "error",
94
+ message: `${flag} agent nickname not found in agent-members.yaml (or has no resolvable command): ${nickname}`,
95
+ };
96
+ }
97
+ return {
98
+ kind: "command",
99
+ command,
100
+ actor: member.nickname,
101
+ provider: member.provider,
102
+ };
103
+ }
104
+ export class SerialAsyncLock {
105
+ tail = Promise.resolve();
106
+ async runExclusive(fn) {
107
+ const previous = this.tail;
108
+ let release;
109
+ this.tail = new Promise((resolveTail) => {
110
+ release = resolveTail;
111
+ });
112
+ await previous;
113
+ try {
114
+ return await fn();
115
+ }
116
+ finally {
117
+ release();
118
+ }
119
+ }
120
+ }
121
+ export async function runCompletionDrivenWorkerPool(options) {
122
+ const running = new Map();
123
+ let nextToken = 1;
124
+ let stop = false;
125
+ let launched = 0;
126
+ let completed = 0;
127
+ const start = (item) => {
128
+ const token = nextToken++;
129
+ running.set(token, {
130
+ token,
131
+ item,
132
+ promise: options.runItem(item).then((result) => ({ token, item, result })),
133
+ });
134
+ launched++;
135
+ };
136
+ const refill = async () => {
137
+ if (stop || running.size >= options.maxParallel)
138
+ return;
139
+ const items = await options.fillSlots(options.maxParallel - running.size);
140
+ for (const item of items) {
141
+ if (running.size >= options.maxParallel)
142
+ break;
143
+ start(item);
144
+ }
145
+ };
146
+ await refill();
147
+ while (running.size > 0) {
148
+ const outcome = await Promise.race([...running.values()].map((runningItem) => runningItem.promise));
149
+ running.delete(outcome.token);
150
+ completed++;
151
+ const action = await options.onSettled?.(outcome.item, outcome.result);
152
+ if (action?.stop)
153
+ stop = true;
154
+ await refill();
155
+ }
156
+ return { launched, completed };
157
+ }
158
+ export function buildTaskPhaseMap(schedulePath) {
159
+ const localIdToPhaseSets = new Map();
160
+ const phaseSetSuffixToId = new Map();
161
+ const strategyFiles = listFilesRecursive(schedulePath).filter((f) => /sch-strategy-.*\.(yaml|yml)$/.test(f));
162
+ for (const filePath of strategyFiles) {
163
+ let strategy;
164
+ try {
165
+ strategy = readYaml(filePath);
166
+ }
167
+ catch {
168
+ continue;
169
+ }
170
+ if (!strategy?.phase_sets || !Array.isArray(strategy.owner_rules))
171
+ continue;
172
+ let defaultPhaseSets;
173
+ try {
174
+ defaultPhaseSets = phaseSetNames(normalizePhaseSetSelection(strategy.default_phase_sets, strategy.default_phase_set
175
+ ? [strategy.default_phase_set]
176
+ : Object.keys(strategy.phase_sets)));
177
+ }
178
+ catch {
179
+ continue;
180
+ }
181
+ for (const [phaseSetName, phases] of Object.entries(strategy.phase_sets)) {
182
+ for (const phase of phases) {
183
+ phaseSetSuffixToId.set(`${phaseSetName}:${phase.task_suffix}`, phase.id);
184
+ }
185
+ }
186
+ for (const rule of strategy.owner_rules) {
187
+ let phaseSets;
188
+ try {
189
+ phaseSets = rule.phase_sets
190
+ ? phaseSetNames(normalizePhaseSetSelection(rule.phase_sets, []))
191
+ : rule.phase_set
192
+ ? [rule.phase_set]
193
+ : defaultPhaseSets;
194
+ }
195
+ catch {
196
+ continue;
197
+ }
198
+ for (const localId of rule.local_ids) {
199
+ localIdToPhaseSets.set(localId, phaseSets);
200
+ }
201
+ }
202
+ }
203
+ return { localIdToPhaseSets, phaseSetSuffixToId };
204
+ }
205
+ export function resolveTaskPhaseContext(task, localIdToPhaseSets, phaseSetSuffixToId) {
206
+ // ready.json/schedule 側で phase_set・phase_id が既に確定しているタスクは、それを正として
207
+ // 直接返す。cross-deliverable-pass タスク(single local_id を持たず target_local_ids のみを
208
+ // 持つ)はこの分岐でしか解決できないため、local_id の有無より先に判定する。ここで local_id
209
+ // チェックを先にすると、target_local_ids しか持たないタスクは常に「not found in sch-strategy
210
+ // files」で失敗する。
211
+ if (task.phase_set && task.phase_id) {
212
+ return { localId: task.local_id ?? "", phaseSet: task.phase_set, phaseId: task.phase_id };
213
+ }
214
+ const localId = task.local_id;
215
+ if (!localId)
216
+ return null;
217
+ const suffix = task.phase_suffix ?? extractPhaseSuffix(task.id);
218
+ if (!suffix)
219
+ return null;
220
+ const phaseSets = localIdToPhaseSets.get(localId);
221
+ if (!phaseSets)
222
+ return null;
223
+ for (const phaseSet of task.phase_set ? [task.phase_set] : phaseSets) {
224
+ const phaseId = phaseSetSuffixToId.get(`${phaseSet}:${suffix}`);
225
+ if (phaseId)
226
+ return { localId, phaseSet, phaseId };
227
+ }
228
+ return null;
229
+ }
230
+ export function selectCandidates(requirements, roster, taskMode, busyActors, execDefaults = {}) {
231
+ if (!roster)
232
+ return [];
233
+ const { capabilities: required, proficiency, stage_role: stageRole } = requirements;
234
+ return roster.members
235
+ .filter((m) => {
236
+ // Runnable agents need a command source: a provider command_template or an
237
+ // explicit member-level command override.
238
+ if (m.type !== "agent" || !hasMemberCommandSource(execDefaults, m))
239
+ return false;
240
+ // Temporarily disabled agents (e.g. to isolate one provider while testing rate limits)
241
+ // are skipped during auto-selection.
242
+ if (m.disabled === true)
243
+ return false;
244
+ const caps = m.capabilities ?? [];
245
+ if (!required.every((c) => caps.includes(c)))
246
+ return false;
247
+ if (proficiency !== undefined && m.proficiency !== proficiency)
248
+ return false;
249
+ // Pipeline agents and legacy agents form disjoint auto-selection pools. This keeps newly
250
+ // introduced executor/reporter definitions out of existing single-agent tasks while also
251
+ // preventing legacy agents from silently filling a pipeline stage.
252
+ if (stageRole === undefined) {
253
+ if (m.stage_role !== undefined)
254
+ return false;
255
+ }
256
+ else if (m.stage_role !== stageRole) {
257
+ return false;
258
+ }
259
+ // If agent declares a mode and task has a mode, they must match.
260
+ // Agents without a mode field are mode-agnostic and match any task.
261
+ if (m.mode !== undefined && taskMode !== undefined && m.mode !== taskMode)
262
+ return false;
263
+ return true;
264
+ })
265
+ .sort((a, b) => {
266
+ // Primary: agents already busy on a "doing" task sort last. This spreads parallel runs
267
+ // across agents instead of piling every task onto the same top-priority command and
268
+ // hitting its rate limit.
269
+ const aBusy = busyActors?.has(a.nickname) ? 1 : 0;
270
+ const bBusy = busyActors?.has(b.nickname) ? 1 : 0;
271
+ if (aBusy !== bBusy)
272
+ return aBusy - bBusy;
273
+ // Secondary: priority (lower number = tried first)
274
+ const aPriority = a.priority ?? 999;
275
+ const bPriority = b.priority ?? 999;
276
+ if (aPriority !== bPriority)
277
+ return aPriority - bPriority;
278
+ // Tertiary: fewest extra capabilities (tie-breaker within same priority)
279
+ const aExtra = (a.capabilities?.length ?? 0) - required.length;
280
+ const bExtra = (b.capabilities?.length ?? 0) - required.length;
281
+ return aExtra - bExtra;
282
+ });
283
+ }
284
+ // Collect the nicknames of actors currently working a "doing" task, derived from the event log
285
+ // (not the state.json cache) so freshly claimed tasks within the same parallel round are seen.
286
+ // Used to deprioritize busy agents during auto-selection. Failures degrade to "no busy info".
287
+ export function collectBusyActors(schedulePath) {
288
+ const busy = new Set();
289
+ try {
290
+ const sch = buildScheduleIndex(schedulePath);
291
+ const evts = readAllEventFiles(schedulePath);
292
+ const initTasks = buildInitialStateFromStrategy(schedulePath, sch);
293
+ const snap = foldEventsToState(evts, sch, schedulePath, initTasks);
294
+ for (const taskState of Object.values(snap.tasks ?? {})) {
295
+ if (taskState?.state === "doing" && taskState.last_by)
296
+ busy.add(taskState.last_by);
297
+ }
298
+ }
299
+ catch {
300
+ // ignore; selection falls back to priority-only ordering
301
+ }
302
+ return busy;
303
+ }
304
+ export function isRateLimitError(exitCode, output, detection) {
305
+ if (!detection)
306
+ return false;
307
+ // exit_codes is a standalone signal: an exact configured code identifies a rate limit
308
+ // on its own. Keep this list minimal (see exec-defaults.yaml) since generic codes like 1
309
+ // also mean ordinary failure.
310
+ if (detection.exit_codes && exitCode !== null && detection.exit_codes.includes(exitCode)) {
311
+ return true;
312
+ }
313
+ if (detection.stderr_patterns) {
314
+ // `output` is the agent's combined stdout+stderr: some CLIs print the limit notice to
315
+ // stdout, not stderr (e.g. claude's "You've hit your session limit"), so scanning stderr
316
+ // alone misses it. By default a pattern only counts when the process also failed (non-zero
317
+ // or null exit). A successful run (exit 0) that merely echoes the phrase — e.g. an agent
318
+ // editing a file containing the literal text "rate limit" — is not a rate limit.
319
+ const requireNonzeroExit = detection.stderr_requires_nonzero_exit ?? true;
320
+ if (!requireNonzeroExit || exitCode !== 0) {
321
+ const lower = output.toLowerCase();
322
+ for (const pattern of detection.stderr_patterns) {
323
+ if (lower.includes(pattern.toLowerCase()))
324
+ return true;
325
+ }
326
+ }
327
+ }
328
+ return false;
329
+ }
330
+ export function resolveExecDefaultsPath(opts, schedulePath) {
331
+ if (opts.execDefaults)
332
+ return opts.execDefaults;
333
+ if (opts.agentConfig)
334
+ return opts.agentConfig;
335
+ const { config } = loadConfig();
336
+ if (config) {
337
+ const rootDir = specdojoRootDir();
338
+ for (const project of Object.values(config.projects)) {
339
+ const projSchedulePath = resolve(rootDir, getProjectSchedulePath(project));
340
+ if (projSchedulePath === schedulePath && project.run?.exec_defaults) {
341
+ return resolve(rootDir, project.run.exec_defaults);
342
+ }
343
+ if (projSchedulePath === schedulePath && project.run?.agent_config) {
344
+ return resolve(rootDir, project.run.agent_config);
345
+ }
346
+ }
347
+ }
348
+ return defaultExecDefaultsPath();
349
+ }
350
+ export function configuredWorktreeBase(schedulePath) {
351
+ const { config } = loadConfig();
352
+ if (!config)
353
+ return undefined;
354
+ const rootDir = specdojoRootDir();
355
+ for (const project of Object.values(config.projects)) {
356
+ if (resolve(rootDir, getProjectSchedulePath(project)) === schedulePath) {
357
+ return project.run?.worktree_base;
358
+ }
359
+ }
360
+ return undefined;
361
+ }
362
+ export function parseParallel(value) {
363
+ const text = value ?? "1";
364
+ if (!/^\d+$/.test(text)) {
365
+ throw new Error(`--parallel must be a positive integer: ${value ?? ""}`);
366
+ }
367
+ const parsed = Number.parseInt(text, 10);
368
+ if (!Number.isSafeInteger(parsed) || parsed < 1) {
369
+ throw new Error(`--parallel must be a positive integer: ${value ?? ""}`);
370
+ }
371
+ return parsed;
372
+ }
373
+ export function parseExecRunBusyPolicy(value) {
374
+ const policy = value ?? "fail";
375
+ if (policy !== "skip" && policy !== "wait" && policy !== "fail") {
376
+ throw new Error(`--if-busy must be "skip", "wait", or "fail": ${value ?? ""}`);
377
+ }
378
+ return policy;
379
+ }
380
+ export function resolveRegisterWorktree(opts, execDefaults) {
381
+ if (opts.worktree && opts.inPlace) {
382
+ throw new Error("Specify either --worktree or --in-place, not both.");
383
+ }
384
+ if (opts.worktree)
385
+ return true;
386
+ if (opts.inPlace)
387
+ return false;
388
+ return resolveRegisterExecution(execDefaults) === "worktree";
389
+ }
390
+ export const EXCLUSIVE_EXEC_RUN = { shareable: false, join: false };
391
+ function resolveJoinSlotLimit(opts, schedulePath, executionPath) {
392
+ const execDefaults = loadExecDefaultsConfig(resolveExecDefaultsPath(opts, schedulePath), executionPath);
393
+ return resolveMaxConcurrentRuns(execDefaults) - 1;
394
+ }
395
+ export async function withProjectExecRunLock(opts, commandLabel, action, sharing = EXCLUSIVE_EXEC_RUN) {
396
+ const resolvedPaths = resolveProjectPaths({ project: opts.project });
397
+ const locksDir = execLocksDir(resolvedPaths.executionPath);
398
+ const previousLocksDir = getActiveExecLocksDir();
399
+ if (inheritsExecRunLock(resolvedPaths.executionPath)) {
400
+ setActiveExecLocksDir(locksDir);
401
+ try {
402
+ await action();
403
+ }
404
+ finally {
405
+ setActiveExecLocksDir(previousLocksDir);
406
+ }
407
+ return;
408
+ }
409
+ const policy = parseExecRunBusyPolicy(opts.ifBusy);
410
+ const joinLimit = sharing.join
411
+ ? resolveJoinSlotLimit(opts, resolvedPaths.schedulePath, resolvedPaths.executionPath)
412
+ : 0;
413
+ if (sharing.join && joinLimit < 1) {
414
+ throw new Error("--join is disabled: run.max_concurrent_runs in exec-defaults is 1 (raise it to allow joining runs)");
415
+ }
416
+ const handle = await acquireExecRunLock(resolvedPaths.executionPath, {
417
+ actor: opts.by ?? `exec-${commandLabel}`,
418
+ ifBusy: policy,
419
+ shareable: sharing.shareable || sharing.join,
420
+ ...(sharing.join ? { join: { limit: joinLimit } } : {}),
421
+ onWait: () => process.stdout.write(sharing.join
422
+ ? `[${commandLabel}] exec busy — waiting for a join slot (see "exec slots")\n`
423
+ : `[${commandLabel}] exec busy — waiting\n`),
424
+ });
425
+ if (!handle) {
426
+ process.stdout.write(`[${commandLabel}] skipped: exec busy\n`);
427
+ if (process.env[ROUTINE_EXEC_ENV] === "1") {
428
+ process.exitCode = ROUTINE_BUSY_SKIP_EXIT_CODE;
429
+ }
430
+ return;
431
+ }
432
+ if (sharing.join) {
433
+ process.stdout.write(`[${commandLabel}] running as a joined exec (${basename(handle.lockDir)})\n`);
434
+ }
435
+ const previousInheritedToken = process.env[EXEC_RUN_LOCK_TOKEN_ENV];
436
+ process.env[EXEC_RUN_LOCK_TOKEN_ENV] = handle.token;
437
+ setActiveExecLocksDir(locksDir);
438
+ try {
439
+ await action();
440
+ }
441
+ finally {
442
+ setActiveExecLocksDir(previousLocksDir);
443
+ if (previousInheritedToken === undefined)
444
+ delete process.env[EXEC_RUN_LOCK_TOKEN_ENV];
445
+ else
446
+ process.env[EXEC_RUN_LOCK_TOKEN_ENV] = previousInheritedToken;
447
+ releaseExecRunLock(handle);
448
+ }
449
+ }
@@ -1,4 +1,4 @@
1
- import { formatDateOnlyUtc } from "./exec-shared.js";
1
+ import { formatDateOnlyUtc } from "../shared.js";
2
2
  function scheduleAnchorDateUtc() {
3
3
  return Date.UTC(2000, 0, 1, 0, 0, 0, 0);
4
4
  }
@@ -1,5 +1,5 @@
1
- import { toArtifactPath, toScheduleFilePath } from "./exec-shared.js";
2
- import { workingDayOffsetForDate } from "./exec-schedule-calendar.js";
1
+ import { toArtifactPath, toScheduleFilePath } from "../shared.js";
2
+ import { workingDayOffsetForDate } from "./calendar.js";
3
3
  export function topoSort(schedule) {
4
4
  const indeg = new Map();
5
5
  const out = new Map();
@@ -1,5 +1,5 @@
1
- import { formatDateOnlyUtc, formatDays } from "./exec-shared.js";
2
- import { buildWorkingTaskSegments, dateForWorkingOffset, ganttChartStartDate, isWorkingDateUtc, workingMinutesPerDay, } from "./exec-schedule-calendar.js";
1
+ import { formatDateOnlyUtc, formatDays } from "../shared.js";
2
+ import { buildWorkingTaskSegments, dateForWorkingOffset, ganttChartStartDate, isWorkingDateUtc, workingMinutesPerDay, } from "./calendar.js";
3
3
  function xmlEscape(text) {
4
4
  return text
5
5
  .replace(/&/g, "&amp;")
@@ -0,0 +1,2 @@
1
+ export { buildGanttChartMarkdown, buildGanttChartSvg } from "./gantt-chart-render.js";
2
+ export { buildProgressSummaryLines } from "./progress.js";
@@ -1,8 +1,8 @@
1
1
  import { createHash } from "node:crypto";
2
2
  import { existsSync, writeFileSync } from "node:fs";
3
3
  import { basename, join } from "node:path";
4
- import { ensureDir, isRecord, isStringArray, readJson, toArtifactPath, toScheduleFilePath, writeJson, } from "./exec-shared.js";
5
- import { generatedDirForProject } from "./exec-project.js";
4
+ import { ensureDir, isRecord, isStringArray, readJson, toArtifactPath, toScheduleFilePath, writeJson, } from "../shared.js";
5
+ import { generatedDirForProject } from "../project.js";
6
6
  function isScheduleHash(value) {
7
7
  return (isRecord(value) &&
8
8
  value.schema_version === 1 &&
@@ -0,0 +1 @@
1
+ export * from "../../shared/schedule-index.js";
@@ -1,5 +1,5 @@
1
- import { listFilesRecursive, normalizeDateOnly, readYaml } from "./exec-shared.js";
2
- import { expandPhaseSetSelection, normalizePhaseSetSelection, } from "./schedule-phase-sets.js";
1
+ import { listFilesRecursive, normalizeDateOnly, readYaml } from "../shared.js";
2
+ import { expandPhaseSetSelection, normalizePhaseSetSelection, } from "../../schedule/phase-sets.js";
3
3
  export function buildInitialStateFromStrategy(schedulePath, schedule) {
4
4
  const initial = {};
5
5
  const strategyFiles = listFilesRecursive(schedulePath).filter((f) => /sch-strategy-.*\.(yaml|yml)$/.test(f));
@@ -1,5 +1,5 @@
1
- import { formatDateOnlyUtc } from "./exec-shared.js";
2
- import { dateForWorkingOffset, isWorkingDateUtc } from "./exec-schedule-calendar.js";
1
+ import { formatDateOnlyUtc } from "../shared.js";
2
+ import { dateForWorkingOffset, isWorkingDateUtc } from "./calendar.js";
3
3
  function parseDateOnlyUtc(value) {
4
4
  const [year, month, day] = value.split("-").map(Number);
5
5
  return new Date(Date.UTC(year, month - 1, day, 0, 0, 0, 0));
@@ -1,7 +1,7 @@
1
1
  import { writeFileSync } from "node:fs";
2
2
  import { join } from "node:path";
3
- import { executionRootForProject, generatedDirForProject } from "./exec-project.js";
4
- import { ensureDir, formatDays, isRecord, isStringArray, readJson, toArtifactPath, toScheduleFilePath, writeJson, } from "./exec-shared.js";
3
+ import { executionRootForProject, generatedDirForProject } from "../project.js";
4
+ import { ensureDir, formatDays, isRecord, isStringArray, readJson, toArtifactPath, toScheduleFilePath, writeJson, } from "../shared.js";
5
5
  function isStrategyOrder(value) {
6
6
  return (isRecord(value) &&
7
7
  (typeof value.next_task_id === "string" || value.next_task_id === null) &&
@@ -1,16 +1,16 @@
1
1
  import { existsSync, statSync, writeFileSync } from "node:fs";
2
2
  import { basename, extname, join } from "node:path";
3
- import { computeReadyIds, foldEventsToState, isExecEventV1, validateEventShape, } from "./exec-events.js";
4
- import { ensureDir, formatDays, listFilesRecursive, readJson, toArtifactPath, toScheduleFilePath, writeJson, } from "./exec-shared.js";
5
- import { eventsDirForProject, executionRootForProject, generatedDirForProject, } from "./exec-project.js";
6
- import { buildGanttChartMarkdown, buildGanttChartSvg, buildProgressSummaryLines, } from "./exec-schedule-gantt-chart.js";
7
- import { buildScheduleIndex } from "./exec-schedule-index.js";
8
- import { buildGanttChartScopeSpecs, filterCpmNodes, scheduleTrackNames, } from "./exec-schedule-gantt-chart-scope.js";
9
- import { computeCpm, topoSort } from "./exec-schedule-cpm.js";
10
- import { buildReadySnapshot, orderReadyIds, writeReadyFiles, selectNextTask, } from "./exec-schedule-ready.js";
11
- import { writeScheduleHashAndDiff } from "./exec-schedule-hash.js";
12
- import { buildInitialStateFromStrategy } from "./exec-schedule-initial.js";
13
- import { buildPhaseModeIndex, resolveAgentAssignment, resolveAgentPipeline, resolveApproach, resolveTaskCapabilities, resolveTaskExecution, resolveTaskMode, resolveTaskProficiency, } from "./exec-strategy.js";
3
+ import { computeReadyIds, foldEventsToState, isExecEventV1, validateEventShape, } from "../events.js";
4
+ import { ensureDir, formatDays, listFilesRecursive, readJson, toArtifactPath, toScheduleFilePath, writeJson, } from "../shared.js";
5
+ import { eventsDirForProject, executionRootForProject, generatedDirForProject, } from "../project.js";
6
+ import { buildGanttChartMarkdown, buildGanttChartSvg, buildProgressSummaryLines, } from "./gantt-chart.js";
7
+ import { buildScheduleIndex } from "./index.js";
8
+ import { buildGanttChartScopeSpecs, filterCpmNodes, scheduleTrackNames, } from "./gantt-chart-scope.js";
9
+ import { computeCpm, topoSort } from "./cpm.js";
10
+ import { buildReadySnapshot, orderReadyIds, writeReadyFiles, selectNextTask } from "./ready.js";
11
+ import { writeScheduleHashAndDiff } from "./hash.js";
12
+ import { buildInitialStateFromStrategy } from "./initial.js";
13
+ import { buildPhaseModeIndex, resolveAgentAssignment, resolveAgentPipeline, resolveApproach, resolveTaskCapabilities, resolveTaskExecution, resolveTaskMode, resolveTaskProficiency, } from "../strategy.js";
14
14
  export function findStaleGeneratedTracks(projectPath) {
15
15
  const files = listFilesRecursive(projectPath);
16
16
  const trackFiles = new Map();
@@ -0,0 +1,63 @@
1
+ export { toArtifactPath, toPortablePath } from "../shared/artifact-path.js";
2
+ export { ensureDir, listFilesRecursive, readJson, readYaml, writeJson } from "../shared/fs.js";
3
+ export { displayWidth, escapeMarkdownInline, expandTemplate, inlineCodeAnglePlaceholders, padEndDisplay, redactSensitiveText, stripTerminalControlSequences, } from "../shared/text.js";
4
+ export { formatDateOnlyUtc, isUtcIsoSeconds, normalizeDateOnly, nowUtcIsoSeconds, } from "../shared/time.js";
5
+ export { randomHex } from "../shared/random.js";
6
+ export { isSchYamlFilename, toScheduleFilePath } from "../shared/schedule-paths.js";
7
+ export function tsForFilenameUtc(ts) {
8
+ return ts.replace(/[-:]/g, "").replace("T", "T");
9
+ }
10
+ // worktree/branch 生成専用。project 修飾した task ID(`<projectId>:<taskId>`)を返す。
11
+ // projectId が未解決(env path override 等)の場合は bare のままにして後方互換を保つ。
12
+ // schedule 検索・plan/result ファイル名・claim には使わない(bare の task ID を使う)。
13
+ export function qualifyTaskId(projectId, taskId) {
14
+ return projectId ? `${projectId}:${taskId}` : taskId;
15
+ }
16
+ export function safeSlug(s) {
17
+ return s
18
+ .trim()
19
+ .replace(/\s+/g, "-")
20
+ .replace(/[^A-Za-z0-9._-]/g, "_")
21
+ .slice(0, 80);
22
+ }
23
+ export function requireNonEmpty(name, v) {
24
+ if (typeof v !== "string" || v.trim().length === 0)
25
+ throw new Error(`${name} is required`);
26
+ return v.trim();
27
+ }
28
+ export function collectRepeatable(value, previous) {
29
+ return previous.concat([value]);
30
+ }
31
+ // CPM 由来の日数値(ES / EF / slack / duration 等)の表示用フォーマット。
32
+ // 浮動小数点誤差(例: 6.2509999999999994)を吸収し、小数点以下を最大2桁に丸める。
33
+ // JSON 等のデータ出力には使わず、Markdown 表示にのみ使う。
34
+ export function formatDays(value) {
35
+ return String(Math.round(value * 100) / 100);
36
+ }
37
+ export function parseKeyValuePairs(pairs) {
38
+ if (!pairs || pairs.length === 0)
39
+ return undefined;
40
+ const out = {};
41
+ for (const p of pairs) {
42
+ const idx = p.indexOf("=");
43
+ if (idx <= 0)
44
+ throw new Error(`Invalid key=value: ${p}`);
45
+ const k = p.slice(0, idx).trim();
46
+ const v = p.slice(idx + 1).trim();
47
+ if (!k)
48
+ throw new Error(`Empty key in: ${p}`);
49
+ out[k] = v;
50
+ }
51
+ return Object.keys(out).length ? out : undefined;
52
+ }
53
+ export function isRecord(value) {
54
+ return typeof value === "object" && value !== null && !Array.isArray(value);
55
+ }
56
+ export function isStringArray(value) {
57
+ return Array.isArray(value) && value.every((item) => typeof item === "string");
58
+ }
59
+ export function sleepMs(ms) {
60
+ const sab = new SharedArrayBuffer(4);
61
+ const int32 = new Int32Array(sab);
62
+ Atomics.wait(int32, 0, 0, ms);
63
+ }
@@ -0,0 +1 @@
1
+ export * from "../shared/cross-process-lock.js";
@@ -1,5 +1,5 @@
1
- import { listFilesRecursive, readYaml } from "./exec-shared.js";
2
- import { extractPhaseSuffix, normalizePhaseSetSelection, phaseSetNames, } from "./schedule-phase-sets.js";
1
+ import { listFilesRecursive, readYaml } from "./shared.js";
2
+ import { extractPhaseSuffix, normalizePhaseSetSelection, phaseSetNames, } from "../schedule/phase-sets.js";
3
3
  function isTaskMode(value) {
4
4
  return value === "edit" || value === "review";
5
5
  }
@@ -1,7 +1,7 @@
1
1
  import { existsSync, readdirSync, rmdirSync } from "node:fs";
2
2
  import { dirname, resolve } from "node:path";
3
- import { getProjectRepos, getProjectSchedulePath, loadConfig, PROJECT_REPO_WORKTREE_DIRNAME, resolveRepoRoot, specdojoRootDir, } from "./specdojo-config.js";
4
- import { ensureExecWorktree, execBranchExists, execWorktreePath, findExecWorktree, generateWorktreeArtifacts, gitOutput, gitResult, installWorktreeDependencies, listRegisteredWorktrees, worktreeNameFromTaskId, } from "./exec-worktree.js";
3
+ import { getProjectRepos, getProjectSchedulePath, loadConfig, PROJECT_REPO_WORKTREE_DIRNAME, resolveRepoRoot, specdojoRootDir, } from "../shared/specdojo-config.js";
4
+ import { ensureExecWorktree, execBranchExists, execWorktreePath, findExecWorktree, generateWorktreeArtifacts, gitOutput, gitResult, installWorktreeDependencies, listRegisteredWorktrees, worktreeNameFromTaskId, } from "./worktree.js";
5
5
  // PJR-98G4: 1 つのタスクがプロジェクトリポジトリと宣言済みのプロダクトリポジトリ(`repos`)を
6
6
  // 変更する場合の worktree を扱う。`repos` を持たない project では、ここの関数はどれも空の結果を
7
7
  // 返し、既存の 1 リポジトリ・`<worktree_base>/<task-id>/` 直下の配置を変えない。
@@ -1,9 +1,9 @@
1
1
  import { existsSync } from "node:fs";
2
2
  import { join } from "node:path";
3
- import { buildScheduleIndex } from "./exec-schedule.js";
4
- import { readReadySnapshot } from "./exec-schedule-ready.js";
5
- import { buildPhaseModeIndex, resolveAgentAssignment, resolveAgentPipeline, resolveApproach, resolveTaskCapabilities, resolveTaskExecution, resolveTaskMode, resolveTaskProficiency, } from "./exec-strategy.js";
6
- import { extractLocalId, extractPhaseSuffix } from "./schedule-phase-sets.js";
3
+ import { buildScheduleIndex } from "./schedule/schedule.js";
4
+ import { readReadySnapshot } from "./schedule/ready.js";
5
+ import { buildPhaseModeIndex, resolveAgentAssignment, resolveAgentPipeline, resolveApproach, resolveTaskCapabilities, resolveTaskExecution, resolveTaskMode, resolveTaskProficiency, } from "./strategy.js";
6
+ import { extractLocalId, extractPhaseSuffix } from "../schedule/phase-sets.js";
7
7
  // Reconstruct a full ReadyTaskView for a task from the schedule (+ ready.json when
8
8
  // present), filling mode/execution/approach/capabilities/proficiency/pipeline from strategy
9
9
  // metadata. Works for any scheduled task regardless of its current state.