specdojo 0.4.0 → 0.4.2

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 (93) hide show
  1. package/.github/agents/specdojo-orchestrator.md +61 -2
  2. package/CHANGELOG.md +65 -0
  3. package/README.md +8 -7
  4. package/dist/commands/init.js +88 -15
  5. package/dist/commands/night-orchestrator.js +287 -0
  6. package/dist/commands/orchestrator.js +10 -3
  7. package/dist/dashboard/timeline-build.js +4 -151
  8. package/dist/devcontainer/command.js +3 -1
  9. package/dist/devcontainer/scaffold.js +166 -5
  10. package/dist/exec/agent-config.js +60 -2
  11. package/dist/exec/events.js +17 -6
  12. package/dist/exec/parent-validation.js +14 -0
  13. package/dist/exec/pipeline-state.js +13 -0
  14. package/dist/exec/plans-core.js +16 -5
  15. package/dist/exec/plans-storage.js +11 -3
  16. package/dist/exec/register.js +23 -1
  17. package/dist/exec/repo-integration.js +1 -1
  18. package/dist/exec/reporter.js +113 -13
  19. package/dist/exec/results.js +36 -14
  20. package/dist/exec/run/agent-pipeline.js +3 -0
  21. package/dist/exec/run/agent.js +40 -5
  22. package/dist/exec/run/job.js +2 -2
  23. package/dist/exec/run/lifecycle-commands.js +2 -2
  24. package/dist/exec/run/register-command.js +23 -4
  25. package/dist/exec/run/register-core.js +17 -0
  26. package/dist/exec/run/register-mode.js +39 -16
  27. package/dist/exec/run/register-post-review.js +420 -0
  28. package/dist/exec/run/register-resume.js +27 -11
  29. package/dist/exec/run/register-worktree.js +66 -2
  30. package/dist/exec/run/run.js +1 -1
  31. package/dist/exec/run/shared.js +22 -24
  32. package/dist/exec/task-repos.js +102 -15
  33. package/dist/kata/kata.js +1 -1
  34. package/dist/register/core.js +17 -4
  35. package/dist/register/create-commands.js +62 -6
  36. package/dist/register/cross-project.js +134 -0
  37. package/dist/register/derivation.js +28 -7
  38. package/dist/register/event-merge.js +13 -1
  39. package/dist/register/events.js +4 -0
  40. package/dist/register/item.js +35 -5
  41. package/dist/register/migration.js +1 -0
  42. package/dist/register/register.js +47 -30
  43. package/dist/schedule/strategy-generate-scope.js +2 -1
  44. package/dist/shared/catalog-files.js +31 -0
  45. package/dist/shared/git.js +45 -15
  46. package/dist/shared/lefthook-scaffold.js +177 -0
  47. package/dist/shared/provider-scaffold.js +3 -2
  48. package/dist/shared/specdojo-config.js +87 -17
  49. package/dist/shared/text.js +4 -1
  50. package/dist/shared/timeline-index.js +125 -0
  51. package/dist/shared/workspace-scaffold.js +69 -0
  52. package/docs/ja/specdojo/exec-templates/xep-common-conventions-template.md +2 -1
  53. package/docs/ja/specdojo/exec-templates/xep-register-template.md +2 -0
  54. package/docs/ja/specdojo/exec-templates/xrp-register-post-run-template.md +46 -0
  55. package/docs/ja/specdojo/guides/branch-workflow-guide.md +34 -1
  56. package/docs/ja/specdojo/guides/docs-structure-guide.md +2 -0
  57. package/docs/ja/specdojo/guides/exec-config-guide.md +79 -11
  58. package/docs/ja/specdojo/guides/exec-operation-guide.md +39 -1
  59. package/docs/ja/specdojo/guides/orchestrator-operation-guide.md +9 -3
  60. package/docs/ja/specdojo/guides/plan-result-lifecycle-guide.md +4 -2
  61. package/docs/ja/specdojo/guides/quick-start-guide.md +31 -6
  62. package/docs/ja/specdojo/guides/register-operation-guide.md +54 -0
  63. package/docs/ja/specdojo/guides/remote-host-development-guide.md +52 -6
  64. package/docs/ja/specdojo/guides/specdojo-overview-guide.md +1 -1
  65. package/docs/ja/specdojo/guides/waza-guide.md +1 -1
  66. package/docs/ja/specdojo/references/command-reference.md +138 -64
  67. package/docs/ja/specdojo/references/specdojo-config-reference.md +41 -12
  68. package/docs/ja/specdojo/rulebooks/pjr-rulebook.md +5 -2
  69. package/docs/specdojo/schemas/v1/exec-defaults.schema.yaml +92 -18
  70. package/docs/specdojo/schemas/v1/exec-evidence.schema.yaml +6 -1
  71. package/docs/specdojo/schemas/v1/pipeline-state.schema.yaml +12 -0
  72. package/docs/specdojo/schemas/v1/register-events.schema.yaml +2 -0
  73. package/docs/specdojo/schemas/v1/register-item-frontmatter.schema.yaml +21 -0
  74. package/docs/specdojo/schemas/v1/specdojo-config.schema.yaml +40 -0
  75. package/package.json +17 -17
  76. package/templates/antigravity/README.md +1 -1
  77. package/templates/antigravity/orchestrator.md +61 -2
  78. package/templates/claude/agents/specdojo-orchestrator.md +61 -2
  79. package/templates/codex/README.md +17 -0
  80. package/templates/codex/agents/specdojo-orchestrator.toml +61 -2
  81. package/templates/codex/orchestrator.md +61 -2
  82. package/templates/devcontainer/devcontainer.json +3 -0
  83. package/templates/devcontainer/post-create.sh +15 -7
  84. package/templates/devcontainer/remote-host/specdojo-tmux.sh.sample +38 -5
  85. package/templates/devcontainer/remote-host/ssh-config.sample +3 -0
  86. package/templates/devcontainer/vim/vimrc +37 -0
  87. package/templates/init-agent-members.yaml +6 -6
  88. package/templates/init-exec-defaults.yaml +20 -1
  89. package/templates/lefthook/tools/install-lefthook.mjs +46 -0
  90. package/templates/lefthook/tools/specdojo-pre-commit.mjs +207 -0
  91. package/templates/opencode/README.md +6 -1
  92. package/templates/opencode/agents/specdojo-orchestrator.md +62 -3
  93. /package/dist/{shared → kata}/yaml-schema-modeline.js +0 -0
@@ -1,6 +1,70 @@
1
1
  import { existsSync } from "node:fs";
2
2
  import { readFile, writeFile, mkdir } from "node:fs/promises";
3
3
  import * as path from "node:path";
4
+ const RECOMMENDED_VSCODE_EXTENSIONS = [
5
+ "mhutchie.git-graph",
6
+ "davidanson.vscode-markdownlint",
7
+ "redhat.vscode-yaml",
8
+ "esbenp.prettier-vscode",
9
+ "unifiedjs.vscode-remark",
10
+ "yzhang.markdown-all-in-one",
11
+ "streetsidesoftware.code-spell-checker",
12
+ "editorconfig.editorconfig",
13
+ "usernamehw.errorlens",
14
+ "tamasfe.even-better-toml",
15
+ ];
16
+ const PROVIDER_VSCODE_EXTENSIONS = {
17
+ claude: ["anthropic.claude-code"],
18
+ codex: ["openai.chatgpt"],
19
+ copilot: ["github.copilot", "github.copilot-chat"],
20
+ };
21
+ const RECOMMENDED_VSCODE_SETTINGS = {
22
+ "[markdown]": {
23
+ "editor.defaultFormatter": "esbenp.prettier-vscode",
24
+ "editor.formatOnSave": true,
25
+ },
26
+ "[yaml]": {
27
+ "editor.defaultFormatter": "esbenp.prettier-vscode",
28
+ "editor.formatOnSave": true,
29
+ },
30
+ "yaml.schemas": {
31
+ "./docs/specdojo/schemas/v1/agent-members.schema.yaml": ".specdojo/agent-members.yaml",
32
+ "./docs/specdojo/schemas/v1/exec-defaults.schema.yaml": ".specdojo/exec-defaults.yaml",
33
+ "./docs/specdojo/schemas/v1/job.schema.yaml": "docs/**/jobs/*.yaml",
34
+ "./docs/specdojo/schemas/v1/pm-members.schema.yaml": "docs/**/pm-members.yaml",
35
+ "./docs/specdojo/schemas/v1/pm-review-viewpoints.schema.yaml": "docs/**/pm-review-viewpoints.yaml",
36
+ "./docs/specdojo/schemas/v1/pm-roles.schema.yaml": "docs/**/pm-roles.yaml",
37
+ "./docs/specdojo/schemas/v1/routine.schema.yaml": "docs/**/routines/*.yaml",
38
+ "./docs/specdojo/schemas/v1/sch-defaults.schema.yaml": "docs/**/sch-defaults.yaml",
39
+ "./docs/specdojo/schemas/v1/sch-milestones.schema.yaml": "docs/**/sch-milestones.yaml",
40
+ "./docs/specdojo/schemas/v1/sch-strategy.schema.yaml": "docs/**/sch-strategy-*.yaml",
41
+ "./docs/specdojo/schemas/v1/sch-track.schema.yaml": "docs/**/sch-track-*.yaml",
42
+ },
43
+ };
44
+ function unique(values) {
45
+ return [...new Set(values)];
46
+ }
47
+ function providerExtensions(providers) {
48
+ return unique(providers.flatMap((provider) => PROVIDER_VSCODE_EXTENSIONS[provider] ?? []));
49
+ }
50
+ function objectValue(value) {
51
+ return value && typeof value === "object" && !Array.isArray(value)
52
+ ? value
53
+ : {};
54
+ }
55
+ async function readExtensionsRecommendations(pathname) {
56
+ if (!existsSync(pathname))
57
+ return { recommendations: [] };
58
+ const parsed = JSON.parse(await readFile(pathname, "utf8"));
59
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
60
+ throw new Error(`Invalid VS Code extensions file: ${pathname}`);
61
+ }
62
+ const result = parsed;
63
+ if (result.recommendations !== undefined && !Array.isArray(result.recommendations)) {
64
+ throw new Error(`Invalid recommendations in VS Code extensions file: ${pathname}`);
65
+ }
66
+ return result;
67
+ }
4
68
  function resolveWorkspaceName(repoRoot, override) {
5
69
  const workspaceName = override ?? path.basename(path.dirname(path.resolve(repoRoot)));
6
70
  if (workspaceName === "." || workspaceName === ".." || !/^[A-Za-z0-9._-]+$/.test(workspaceName)) {
@@ -64,6 +128,9 @@ export function generateSshConfigSample(ports) {
64
128
  " User <user>",
65
129
  "",
66
130
  "# devcontainer 内の tmux セッションへ直接入る接続用",
131
+ "# RemoteCommand は非対話シェルで動くため、接続先端末の ~/.zshrc などの PATH 設定は読み込まれません。",
132
+ "# 接続元から「ssh <host> 'command -v devcontainer'」を実行して Dev Container CLI が見つかるか確認できます。",
133
+ "# 見つからない場合は、ホスト側の ~/bin/specdojo-tmux.sh の node_bin_dir を設定してください。",
67
134
  "Host <host>-tmux",
68
135
  " HostName <host>",
69
136
  " User <user>",
@@ -82,7 +149,13 @@ export function generateSshConfigSample(ports) {
82
149
  return lines.join("\n");
83
150
  }
84
151
  export async function runDevcontainerScaffold(opts) {
85
- const { packageRoot, repoRoot, workspaceName: workspaceNameOverride, providers, editors, ollama, cron, tmux, force, dryRun, } = opts;
152
+ const { packageRoot, repoRoot, workspaceName: workspaceNameOverride, preset, providers, editors, ollama, cron, tmux, force, dryRun, } = opts;
153
+ if (preset !== undefined && preset !== "recommended") {
154
+ throw new Error(`Unknown Dev Container preset: ${preset}. Available: recommended`);
155
+ }
156
+ const recommended = preset === "recommended";
157
+ const effectiveEditors = unique([...editors, ...(recommended ? ["emacs", "vim"] : [])]);
158
+ const effectiveTmux = tmux || recommended;
86
159
  const devcontainerDir = path.join(repoRoot, ".devcontainer");
87
160
  const workspaceName = resolveWorkspaceName(repoRoot, workspaceNameOverride);
88
161
  if (existsSync(devcontainerDir) && !force) {
@@ -114,15 +187,16 @@ export async function runDevcontainerScaffold(opts) {
114
187
  const aptPackages = [];
115
188
  const extraScripts = [];
116
189
  let emacsInitTemplate;
117
- if (tmux) {
190
+ let vimrcTemplate;
191
+ if (effectiveTmux) {
118
192
  aptPackages.push("tmux");
119
193
  }
120
194
  if (cron) {
121
195
  aptPackages.push("cron");
122
196
  devcontainer.postAttachCommand = "sudo service cron start";
123
197
  }
124
- const knownEditors = new Set(["emacs"]);
125
- for (const editor of editors) {
198
+ const knownEditors = new Set(["emacs", "vim"]);
199
+ for (const editor of effectiveEditors) {
126
200
  if (!knownEditors.has(editor)) {
127
201
  process.stdout.write(`Warning: unknown editor "${editor}"\n`);
128
202
  }
@@ -170,9 +244,52 @@ if [ ! -f "$HOME/.emacs" ] && \\
170
244
  mkdir -p "$(dirname "$EMACS_INIT")"
171
245
  cp .devcontainer/emacs/init.el "$EMACS_INIT"
172
246
  echo "Installed Emacs init: $EMACS_INIT"
247
+ fi`);
248
+ }
249
+ else if (editor === "vim") {
250
+ aptPackages.push("vim-nox");
251
+ vimrcTemplate = await readFile(path.join(templateDir, "vim", "vimrc"), "utf8");
252
+ extraScripts.push(`# Keep dotfiles authoritative: install the bundled defaults only when Vim has no user config.
253
+ if [ ! -f "$HOME/.vimrc" ] && [ ! -f "$HOME/.vim/vimrc" ]; then
254
+ cp .devcontainer/vim/vimrc "$HOME/.vimrc"
255
+ echo "Installed Vim config: $HOME/.vimrc"
173
256
  fi`);
174
257
  }
175
258
  }
259
+ let vscodeExtensions = [];
260
+ let extensionsFile;
261
+ if (recommended) {
262
+ vscodeExtensions = unique([...RECOMMENDED_VSCODE_EXTENSIONS, ...providerExtensions(providers)]);
263
+ const customizations = (devcontainer.customizations ??= {});
264
+ const vscode = (customizations.vscode ??= {});
265
+ const existingExtensions = Array.isArray(vscode.extensions)
266
+ ? vscode.extensions.filter((value) => typeof value === "string")
267
+ : [];
268
+ vscode.extensions = unique([...existingExtensions, ...vscodeExtensions]);
269
+ const existingSettings = objectValue(vscode.settings);
270
+ vscode.settings = {
271
+ ...existingSettings,
272
+ "[markdown]": {
273
+ ...objectValue(existingSettings["[markdown]"]),
274
+ ...RECOMMENDED_VSCODE_SETTINGS["[markdown]"],
275
+ },
276
+ "[yaml]": {
277
+ ...objectValue(existingSettings["[yaml]"]),
278
+ ...RECOMMENDED_VSCODE_SETTINGS["[yaml]"],
279
+ },
280
+ "yaml.schemas": {
281
+ ...objectValue(existingSettings["yaml.schemas"]),
282
+ ...RECOMMENDED_VSCODE_SETTINGS["yaml.schemas"],
283
+ },
284
+ };
285
+ const extensionsPath = path.join(repoRoot, ".vscode", "extensions.json");
286
+ extensionsFile = await readExtensionsRecommendations(extensionsPath);
287
+ const existingRecommendations = (extensionsFile.recommendations ?? []);
288
+ extensionsFile.recommendations = unique([
289
+ ...existingRecommendations.filter((value) => typeof value === "string"),
290
+ ...vscodeExtensions,
291
+ ]);
292
+ }
176
293
  if (aptPackages.length > 0) {
177
294
  devcontainer.features["ghcr.io/rocker-org/devcontainer-features/apt-packages:1"] = {
178
295
  packages: aptPackages.join(","),
@@ -219,7 +336,31 @@ fi`);
219
336
  postCreateScript = postCreateScript.replace("npm install", extraScripts.join("\n\n") + "\n\nnpm install");
220
337
  }
221
338
  const specdojoTmuxTemplatePath = path.join(templateDir, "remote-host", "specdojo-tmux.sh.sample");
222
- const specdojoTmuxScript = await readFile(specdojoTmuxTemplatePath, "utf8");
339
+ let specdojoTmuxScript = await readFile(specdojoTmuxTemplatePath, "utf8");
340
+ const remoteUser = typeof devcontainer.remoteUser === "string" && devcontainer.remoteUser.trim()
341
+ ? devcontainer.remoteUser.trim()
342
+ : "node";
343
+ const userLocalBin = `/home/${remoteUser}/.local/bin`;
344
+ const existingRemoteEnv = objectValue(devcontainer.remoteEnv);
345
+ const existingPath = typeof existingRemoteEnv.PATH === "string" ? existingRemoteEnv.PATH : undefined;
346
+ let remotePath;
347
+ if (existingPath) {
348
+ if (existingPath === "/home/node/.local/bin:${containerEnv:PATH}") {
349
+ remotePath = `${userLocalBin}:\${containerEnv:PATH}`;
350
+ }
351
+ else {
352
+ const parts = existingPath.split(":");
353
+ remotePath = parts.includes(userLocalBin) ? existingPath : `${userLocalBin}:${existingPath}`;
354
+ }
355
+ }
356
+ else {
357
+ remotePath = `${userLocalBin}:\${containerEnv:PATH}`;
358
+ }
359
+ devcontainer.remoteEnv = {
360
+ ...existingRemoteEnv,
361
+ PATH: remotePath,
362
+ };
363
+ specdojoTmuxScript = specdojoTmuxScript.replace('container_user="node"', `container_user="${remoteUser}"`);
223
364
  const publishedPorts = extractPublishedPorts(devcontainer);
224
365
  const sshConfigScript = generateSshConfigSample(publishedPorts);
225
366
  if (dryRun) {
@@ -228,6 +369,12 @@ fi`);
228
369
  if (emacsInitTemplate !== undefined) {
229
370
  process.stdout.write(`[dry-run] would write: .devcontainer/emacs/init.el\n`);
230
371
  }
372
+ if (vimrcTemplate !== undefined) {
373
+ process.stdout.write(`[dry-run] would write: .devcontainer/vim/vimrc\n`);
374
+ }
375
+ if (extensionsFile !== undefined) {
376
+ process.stdout.write(`[dry-run] would write: .vscode/extensions.json\n`);
377
+ }
231
378
  process.stdout.write(`[dry-run] would write: .devcontainer/remote-host/specdojo-tmux.sh.sample\n`);
232
379
  process.stdout.write(`[dry-run] would write: .devcontainer/remote-host/ssh-config.sample\n`);
233
380
  return;
@@ -239,6 +386,14 @@ fi`);
239
386
  await mkdir(path.join(devcontainerDir, "emacs"), { recursive: true });
240
387
  await writeFile(path.join(devcontainerDir, "emacs", "init.el"), emacsInitTemplate, "utf8");
241
388
  }
389
+ if (vimrcTemplate !== undefined) {
390
+ await mkdir(path.join(devcontainerDir, "vim"), { recursive: true });
391
+ await writeFile(path.join(devcontainerDir, "vim", "vimrc"), vimrcTemplate, "utf8");
392
+ }
393
+ if (extensionsFile !== undefined) {
394
+ await mkdir(path.join(repoRoot, ".vscode"), { recursive: true });
395
+ await writeFile(path.join(repoRoot, ".vscode", "extensions.json"), `${JSON.stringify(extensionsFile, null, 2)}\n`, "utf8");
396
+ }
242
397
  const remoteHostDir = path.join(devcontainerDir, "remote-host");
243
398
  await mkdir(remoteHostDir, { recursive: true });
244
399
  await writeFile(path.join(remoteHostDir, "specdojo-tmux.sh.sample"), specdojoTmuxScript, "utf8");
@@ -248,6 +403,12 @@ fi`);
248
403
  if (emacsInitTemplate !== undefined) {
249
404
  process.stdout.write(`Written: .devcontainer/emacs/init.el\n`);
250
405
  }
406
+ if (vimrcTemplate !== undefined) {
407
+ process.stdout.write(`Written: .devcontainer/vim/vimrc\n`);
408
+ }
409
+ if (extensionsFile !== undefined) {
410
+ process.stdout.write(`Written: .vscode/extensions.json\n`);
411
+ }
251
412
  process.stdout.write(`Written: .devcontainer/remote-host/specdojo-tmux.sh.sample\n`);
252
413
  process.stdout.write(`Written: .devcontainer/remote-host/ssh-config.sample\n`);
253
414
  process.stdout.write("Next steps:\n" +
@@ -1,8 +1,8 @@
1
1
  import { existsSync } from "node:fs";
2
- import { join } from "node:path";
2
+ import { isAbsolute, join, resolve } from "node:path";
3
3
  import { listFilesRecursive, readYaml } from "./shared.js";
4
4
  import { acquirePoolSlot, releaseLock } from "./slot-lock.js";
5
- import { specdojoRootDir, } from "../shared/specdojo-config.js";
5
+ import { getProjectExecutionPath, loadConfig, specdojoRootDir, } from "../shared/specdojo-config.js";
6
6
  import { resolveParentValidationConcurrency, resolveParentValidationDefinitions, } from "./parent-validation.js";
7
7
  const PLACEHOLDER_PATTERN = /\{([a-z][a-z0-9_]*)\}/g;
8
8
  const BUILTIN_VARIABLE_NAMES = new Set(["nickname", "mode", "proficiency"]);
@@ -88,6 +88,10 @@ export function resolveRateLimitDetection(config, provider) {
88
88
  const override = provider ? config.providers?.[provider]?.rate_limit_detection : undefined;
89
89
  return override ?? config.rate_limit_detection;
90
90
  }
91
+ export function resolveConnectionErrorDetection(config, provider) {
92
+ const override = provider ? config.providers?.[provider]?.connection_error_detection : undefined;
93
+ return override ?? config.connection_error_detection;
94
+ }
91
95
  export function resolveRateLimitPolicy(config, provider) {
92
96
  const override = provider ? config.providers?.[provider]?.rate_limit_policy : undefined;
93
97
  return override ?? config.rate_limit_policy;
@@ -151,6 +155,7 @@ export function providerSlotPoolPath(lockRoot, provider) {
151
155
  }
152
156
  export const DEFAULT_MAX_CONCURRENT_RUNS = 4;
153
157
  export const DEFAULT_REGISTER_EXECUTION = "in-place";
158
+ export const DEFAULT_REGISTER_POST_REVIEW = false;
154
159
  // Preserve the historical default for repositories that have not opted into worktree execution.
155
160
  // Invalid YAML-sourced values are rejected instead of silently changing where agents write.
156
161
  export function resolveRegisterExecution(config) {
@@ -162,6 +167,15 @@ export function resolveRegisterExecution(config) {
162
167
  }
163
168
  return raw;
164
169
  }
170
+ export function resolveRegisterPostReview(config) {
171
+ const raw = config.run?.register_post_review;
172
+ if (raw === undefined)
173
+ return DEFAULT_REGISTER_POST_REVIEW;
174
+ if (typeof raw !== "boolean") {
175
+ throw new Error(`run.register_post_review in exec-defaults must be true or false: ${String(raw)}`);
176
+ }
177
+ return raw;
178
+ }
165
179
  // Resolve how many `exec run` processes may run at once for one project. Invalid values fall back
166
180
  // to the default so a typo cannot silently disable the busy guard.
167
181
  export function resolveMaxConcurrentRuns(config) {
@@ -269,6 +283,37 @@ function loadLegacyRateLimitPolicy(executionPath) {
269
283
  }
270
284
  return undefined;
271
285
  }
286
+ function projectParentValidations(executionPath) {
287
+ if (!executionPath)
288
+ return [];
289
+ const { config } = loadConfig();
290
+ if (!config)
291
+ return [];
292
+ const rootDir = specdojoRootDir();
293
+ const targetExecutionPath = resolve(executionPath);
294
+ const normalizedTarget = targetExecutionPath.replaceAll("\\", "/");
295
+ for (const [projectId, project] of Object.entries(config.projects)) {
296
+ const configuredExecutionPath = getProjectExecutionPath(project);
297
+ const resolvedExecutionPath = resolve(rootDir, configuredExecutionPath);
298
+ const normalizedConfigured = configuredExecutionPath.replaceAll("\\", "/");
299
+ // Job review loads defaults before changing cwd to its worktree. In that case loadConfig()
300
+ // resolves the main checkout while executionPath already points into the worktree; the
301
+ // repository-relative project path remains the same suffix in both locations.
302
+ const isProjectWorktreePath = !isAbsolute(configuredExecutionPath) &&
303
+ normalizedTarget.endsWith(`/${normalizedConfigured.replace(/^\.\//, "")}`);
304
+ if (resolvedExecutionPath !== targetExecutionPath && !isProjectWorktreePath)
305
+ continue;
306
+ const entries = project.run
307
+ ?.parent_validations;
308
+ if (entries === undefined)
309
+ return [];
310
+ if (!Array.isArray(entries)) {
311
+ throw new Error(`Invalid .specdojo/specdojo.config.json: projects.${projectId}.run.parent_validations must be an array`);
312
+ }
313
+ return entries;
314
+ }
315
+ return [];
316
+ }
272
317
  export function loadExecDefaultsConfig(configPath, executionPath) {
273
318
  const path = configPath ?? defaultExecDefaultsPath();
274
319
  let defaults = {};
@@ -286,6 +331,19 @@ export function loadExecDefaultsConfig(configPath, executionPath) {
286
331
  if (legacyPolicy)
287
332
  defaults.rate_limit_policy = legacyPolicy;
288
333
  }
334
+ const additionalParentValidations = projectParentValidations(executionPath);
335
+ if (additionalParentValidations.length > 0) {
336
+ defaults = {
337
+ ...defaults,
338
+ pipeline: {
339
+ ...defaults.pipeline,
340
+ parent_validations: [
341
+ ...(defaults.pipeline?.parent_validations ?? []),
342
+ ...additionalParentValidations,
343
+ ],
344
+ },
345
+ };
346
+ }
289
347
  resolveParentValidationDefinitions(defaults.pipeline?.parent_validations);
290
348
  resolveParentValidationConcurrency(defaults.pipeline?.parent_validation_concurrency);
291
349
  resolveRegisterExecution(defaults);
@@ -112,17 +112,28 @@ export function buildEvent(type, o) {
112
112
  e.meta = meta;
113
113
  return e;
114
114
  }
115
- export function writeEventFile(projectPath, event) {
115
+ export function writeEventFile(projectPath, event, dependencies = {}) {
116
116
  const execDir = eventsDirForProject(projectPath);
117
117
  ensureDir(execDir);
118
118
  const tsPart = tsForFilenameUtc(event.ts);
119
119
  const byPart = safeSlug(event.by);
120
120
  const idPart = safeSlug(event.task_id);
121
- const rand = randomHex(2);
122
- const filename = `${tsPart}_${byPart}_${idPart}_${event.type}_${rand}.json`;
123
- const fullpath = join(execDir, filename);
124
- writeFileSync(fullpath, JSON.stringify(event, null, 2) + "\n", "utf8");
125
- return fullpath;
121
+ const makeRandomHex = dependencies.randomHex ?? randomHex;
122
+ const base = `${tsPart}_${byPart}_${idPart}_${event.type}_${makeRandomHex(4)}`;
123
+ const contents = JSON.stringify(event, null, 2) + "\n";
124
+ for (let sequence = 0;; sequence += 1) {
125
+ const filename = `${base}${sequence === 0 ? "" : `-${sequence}`}.json`;
126
+ const fullpath = join(execDir, filename);
127
+ try {
128
+ // `wx` preserves the append-only event contract even if another writer wins the name.
129
+ writeFileSync(fullpath, contents, { encoding: "utf8", flag: "wx" });
130
+ return fullpath;
131
+ }
132
+ catch (error) {
133
+ if (error.code !== "EEXIST")
134
+ throw error;
135
+ }
136
+ }
126
137
  }
127
138
  export function foldEventsToState(events, schedule, projectPath, initialTasks) {
128
139
  const tasks = initialTasks ? { ...initialTasks } : {};
@@ -57,6 +57,20 @@ const PARENT_VALIDATION_REGISTRY = {
57
57
  displayCommand: "npm run lint:md",
58
58
  timeoutMs: 10 * 60 * 1_000,
59
59
  },
60
+ build: {
61
+ id: "build",
62
+ command: process.platform === "win32" ? "npm.cmd" : "npm",
63
+ args: ["run", "build"],
64
+ displayCommand: "npm run build",
65
+ timeoutMs: 10 * 60 * 1_000,
66
+ },
67
+ "format-check": {
68
+ id: "format-check",
69
+ command: process.platform === "win32" ? "npm.cmd" : "npm",
70
+ args: ["run", "format:check"],
71
+ displayCommand: "npm run format:check",
72
+ timeoutMs: 10 * 60 * 1_000,
73
+ },
60
74
  };
61
75
  function truncateHead(value, limit) {
62
76
  if (value.length <= limit)
@@ -22,6 +22,7 @@ export function createPipelineState(input) {
22
22
  reporter: emptyStage(input.reporterActor),
23
23
  },
24
24
  ...(input.artifacts ? { artifacts: input.artifacts } : {}),
25
+ ...(input.integrationBranches ? { integration_branches: input.integrationBranches } : {}),
25
26
  };
26
27
  }
27
28
  function executionRelative(repoRoot, executionPath) {
@@ -47,6 +48,9 @@ function isStageState(value) {
47
48
  return false;
48
49
  const record = event;
49
50
  return ((record.action === "wait" || record.action === "fallback") &&
51
+ (record.trigger === undefined ||
52
+ record.trigger === "rate_limit" ||
53
+ record.trigger === "connection_error") &&
50
54
  typeof record.from_actor === "string" &&
51
55
  typeof record.to_actor === "string" &&
52
56
  typeof record.resumed_at === "string" &&
@@ -97,6 +101,12 @@ function isArtifactRefs(value) {
97
101
  typeof refs.result_ref === "string" &&
98
102
  !!refs.result_ref);
99
103
  }
104
+ function isIntegrationBranches(value) {
105
+ return (!!value &&
106
+ typeof value === "object" &&
107
+ !Array.isArray(value) &&
108
+ Object.entries(value).every(([repo, branch]) => /^[a-z0-9-]+$/.test(repo) && typeof branch === "string" && !!branch));
109
+ }
100
110
  export function isPipelineState(value) {
101
111
  if (!value || typeof value !== "object" || Array.isArray(value))
102
112
  return false;
@@ -114,6 +124,9 @@ export function isPipelineState(value) {
114
124
  }
115
125
  if (state.artifacts !== undefined && !isArtifactRefs(state.artifacts))
116
126
  return false;
127
+ if (state.integration_branches !== undefined &&
128
+ !isIntegrationBranches(state.integration_branches))
129
+ return false;
117
130
  const stages = state.stages;
118
131
  if (stages.integrate !== undefined && !isIntegrateStageState(stages.integrate))
119
132
  return false;
@@ -17,11 +17,22 @@ export function execDocId(projectId, prefix, localBase) {
17
17
  const localId = `${prefix}-${localBase.toLowerCase()}`;
18
18
  return projectId ? `${projectId}:${localId}` : localId;
19
19
  }
20
- // In-place plan/result share one unique stem (`<slug>-<UTC>-<rand>`) so each run keeps a
21
- // distinct file and id (no doc-index collision) and the result name is derivable from the
22
- // plan. Mirrors the done/ archive naming convention (tsForFilenameUtc + randomHex).
23
- export function buildInPlaceStem(slug) {
24
- return `${slug}-${tsForFilenameUtc(nowUtcIsoSeconds())}-${randomHex(2)}`;
20
+ const issuedInPlaceStems = new Set();
21
+ // In-place plan/result share one unique stem (`<slug>-<UTC>-<rand>[-<sequence>]`) so each
22
+ // run keeps a distinct file and id (no doc-index collision) and the result name is derivable
23
+ // from the plan. The sequence is only used if the random source repeats within this process.
24
+ export function buildInPlaceStem(slug, dependencies = {}) {
25
+ const now = dependencies.now ?? nowUtcIsoSeconds;
26
+ const makeRandomHex = dependencies.randomHex ?? randomHex;
27
+ const base = `${slug}-${tsForFilenameUtc(now())}-${makeRandomHex(4)}`;
28
+ let stem = base;
29
+ let sequence = 1;
30
+ while (issuedInPlaceStems.has(stem)) {
31
+ stem = `${base}-${sequence}`;
32
+ sequence += 1;
33
+ }
34
+ issuedInPlaceStems.add(stem);
35
+ return stem;
25
36
  }
26
37
  // Recover the shared stem from a plan path: `.../exec/plans/<stem>-plan.md` → `<stem>`.
27
38
  // Used when re-running `--plan <path>` so the tied result is overwritten in place.
@@ -5,7 +5,7 @@ import { nowUtcIsoSeconds, randomHex, tsForFilenameUtc } from "./shared.js";
5
5
  import { readSpecdojoNamespace } from "../docs/frontmatter-namespace.js";
6
6
  import { gradeFindingDisplayMessage, gradeResultPathForDocument, readGradeResultForDocument, } from "../shared/grade-result.js";
7
7
  import { lookupDocIndex } from "../docs/doc-index.js";
8
- export function archivePlan(opts) {
8
+ export function archivePlan(opts, dependencies = {}) {
9
9
  const plansDir = join(opts.executionPath, "exec", "plans");
10
10
  const from = join(plansDir, `${opts.slug}-plan.md`);
11
11
  if (!existsSync(from))
@@ -16,8 +16,16 @@ export function archivePlan(opts) {
16
16
  }
17
17
  const doneDir = join(plansDir, "done");
18
18
  mkdirSync(doneDir, { recursive: true });
19
- const stamp = tsForFilenameUtc(nowUtcIsoSeconds());
20
- const to = join(doneDir, `${opts.slug}-${stamp}-${randomHex(2)}-plan.md`);
19
+ const now = dependencies.now ?? nowUtcIsoSeconds;
20
+ const makeRandomHex = dependencies.randomHex ?? randomHex;
21
+ const stamp = tsForFilenameUtc(now());
22
+ const base = `${opts.slug}-${stamp}-${makeRandomHex(4)}`;
23
+ let sequence = 0;
24
+ let to = join(doneDir, `${base}-plan.md`);
25
+ while (existsSync(to)) {
26
+ sequence += 1;
27
+ to = join(doneDir, `${base}-${sequence}-plan.md`);
28
+ }
21
29
  renameSync(from, to);
22
30
  return { from, to, deleted: false };
23
31
  }
@@ -277,6 +277,20 @@ function registerCompletionConditions(item, ticketPath) {
277
277
  ? escapeMarkdownInline(item.description)
278
278
  : "- 個票に明示的な完了条件がないため、タイトルと概要を追加条件として扱う。";
279
279
  }
280
+ function registerAutopilotConstraints(item) {
281
+ if (item.autopilot !== "approved")
282
+ return "";
283
+ return [
284
+ "### 夜間 autopilot の制約",
285
+ "",
286
+ "この個票は人が記載済みの完了条件だけを承認した。次の操作は行わない。必要になった場合は、理由を result の申し送りへ記録して異常終了する。",
287
+ "",
288
+ "- decision の決定、保護された設定の変更、公開・tag・push。",
289
+ "- 公開済み CHANGELOG 節の変更、未承認項目の実行、完了条件や変更範囲の拡張。",
290
+ "- 別の登録項目を自分で実行すること。見つけた別問題は夜間 orchestrator が承認待ちとして起票する。",
291
+ "",
292
+ ].join("\n");
293
+ }
280
294
  function indexedDocumentPath(targetId) {
281
295
  const repoRoot = specdojoRootDir();
282
296
  const indexed = collectDocIndexEntries(join(repoRoot, "docs"), repoRoot)[targetId];
@@ -328,7 +342,12 @@ export async function generateRegisterPlan(opts) {
328
342
  targets: item.targets ?? [],
329
343
  deliverable,
330
344
  ...(refs ? { refs } : {}),
331
- additionalConditions: registerCompletionConditions(item, ticketPath),
345
+ additionalConditions: [
346
+ registerCompletionConditions(item, ticketPath),
347
+ registerAutopilotConstraints(item),
348
+ ]
349
+ .filter(Boolean)
350
+ .join("\n\n"),
332
351
  ...(opts.outPath ? { outPath: opts.outPath } : {}),
333
352
  stem: opts.stem,
334
353
  });
@@ -360,7 +379,10 @@ export async function generateRegisterPlan(opts) {
360
379
  _PJR_TICKET_REF_: ticketPath ? `\`${repoRelativePath(ticketPath)}\`` : "-",
361
380
  _RESULT_REF_: resultRef,
362
381
  _GRADE_FINDINGS_: ticketPath ? registerGradeFindingsText(opts.projectId, ticketPath) : "- なし",
382
+ _AUTOPILOT_CONSTRAINTS_: registerAutopilotConstraints(item),
363
383
  };
384
+ // 空に展開される段落(夜間の承認の印がない個票の _AUTOPILOT_CONSTRAINTS_ など)で重なる空行は
385
+ // expandTemplate がまとめる(PJR-283N)。
364
386
  const body = expandTemplate(template, values);
365
387
  // register 項目は対象成果物の schema を特定できないため、schema 検査の項目は落とす。
366
388
  const content = injectCommonConventions(body, MISSING, new Map());
@@ -248,7 +248,7 @@ export function productMergeBlockers(product) {
248
248
  const target = productIntegrationTarget(product);
249
249
  if (target === "HEAD" || !branchExists(product.repoRoot, target)) {
250
250
  blockers.push(block(`integration branch ${target === "HEAD" ? "(detached HEAD)" : target} is not a local ` +
251
- `branch; set repos[].integration_branch`));
251
+ `branch; set repos[].integration_branch or exec run --integration-branch`));
252
252
  return blockers;
253
253
  }
254
254
  if (target === product.branch) {