specdojo 0.5.0 → 0.6.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 (93) hide show
  1. package/.github/agents/specdojo-orchestrator.md +2 -0
  2. package/CHANGELOG.md +60 -0
  3. package/dist/catalog/generate.js +144 -13
  4. package/dist/commands/init.js +1 -0
  5. package/dist/deliverable/deliverable.js +77 -4
  6. package/dist/exec/core.js +1 -0
  7. package/dist/exec/parent-validation.js +7 -0
  8. package/dist/exec/plans-core.js +46 -1
  9. package/dist/exec/plans-generation.js +39 -3
  10. package/dist/exec/plans-planning.js +1 -1
  11. package/dist/exec/plans-storage.js +1 -0
  12. package/dist/exec/product-branch-records.js +105 -0
  13. package/dist/exec/product-branches.js +52 -0
  14. package/dist/exec/register-product-message.js +50 -0
  15. package/dist/exec/register.js +6 -0
  16. package/dist/exec/repo-integration-sync.js +4 -2
  17. package/dist/exec/repo-integration.js +41 -4
  18. package/dist/exec/repo-trace.js +2 -0
  19. package/dist/exec/results.js +9 -5
  20. package/dist/exec/run/register-command.js +16 -0
  21. package/dist/exec/run/register-resume.js +11 -1
  22. package/dist/exec/run/register-worktree.js +29 -8
  23. package/dist/exec/run/schedule-prepare.js +7 -3
  24. package/dist/exec/strategy.js +2 -1
  25. package/dist/exec/task-repos.js +78 -16
  26. package/dist/exec/worktree-command.js +2 -2
  27. package/dist/exec/worktree.js +3 -3
  28. package/dist/register/core.js +5 -0
  29. package/dist/register/create-commands.js +54 -2
  30. package/dist/register/deliverable-target.js +24 -17
  31. package/dist/register/event-merge.js +4 -0
  32. package/dist/register/events.js +6 -0
  33. package/dist/register/external-project.js +2 -0
  34. package/dist/register/input.js +168 -0
  35. package/dist/register/item.js +61 -0
  36. package/dist/register/register.js +2 -2
  37. package/dist/register/renumber.js +4 -0
  38. package/dist/register/update.js +6 -0
  39. package/dist/schedule/approach.js +9 -0
  40. package/dist/schedule/strategy-profiles.js +22 -2
  41. package/dist/shared/agent-types.js +4 -1
  42. package/dist/shared/branch-template.js +26 -0
  43. package/dist/shared/commit-message-template.js +38 -0
  44. package/dist/shared/commit-types.js +15 -0
  45. package/dist/shared/specdojo-config.js +35 -4
  46. package/docs/ja/specdojo/exec-templates/xep-draft-template.md +93 -0
  47. package/docs/ja/specdojo/exec-templates/xep-fully-guided-template.md +9 -2
  48. package/docs/ja/specdojo/exec-templates/xep-register-investigate-template.md +2 -0
  49. package/docs/ja/specdojo/exec-templates/xep-register-template.md +2 -0
  50. package/docs/ja/specdojo/exec-templates/xer-human-bootstrap-finalize-template.md +2 -0
  51. package/docs/ja/specdojo/exec-templates/xer-human-draft-template.md +23 -0
  52. package/docs/ja/specdojo/exec-templates/xer-human-finalize-template.md +2 -0
  53. package/docs/ja/specdojo/exec-templates/xrp-fully-guided-template.md +7 -4
  54. package/docs/ja/specdojo/guides/exec-config-guide.md +3 -1
  55. package/docs/ja/specdojo/guides/exec-operation-guide.md +96 -2
  56. package/docs/ja/specdojo/guides/register-operation-guide.md +14 -1
  57. package/docs/ja/specdojo/guides/remote-host-development-guide.md +1 -1
  58. package/docs/ja/specdojo/guides/ryu-guide.md +114 -23
  59. package/docs/ja/specdojo/guides/schedule-design-guide.md +31 -4
  60. package/docs/ja/specdojo/recipes/exec-human-finalize-recipe.md +1 -0
  61. package/docs/ja/specdojo/recipes/tsd-recipe.md +20 -12
  62. package/docs/ja/specdojo/references/command-reference.md +44 -11
  63. package/docs/ja/specdojo/references/specdojo-config-reference.md +69 -8
  64. package/docs/ja/specdojo/rulebooks/dct-rulebook.md +8 -0
  65. package/docs/ja/specdojo/rulebooks/pjr-rulebook.md +4 -0
  66. package/docs/ja/specdojo/rulebooks/sch-rulebook.md +3 -1
  67. package/docs/ja/specdojo/samples/dct-sample.yaml +5 -1
  68. package/docs/ja/specdojo/standards/document-metadata-standard.md +16 -0
  69. package/docs/ja/specdojo/standards/exec-human-finalize-standard.md +1 -0
  70. package/docs/ja/specdojo/standards/guide-authoring-standard.md +2 -1
  71. package/docs/ja/specdojo/standards/philosophy-authoring-standard.md +1 -0
  72. package/docs/ja/specdojo/standards/recipe-authoring-standard.md +2 -1
  73. package/docs/ja/specdojo/standards/rulebook-authoring-standard.md +2 -1
  74. package/docs/ja/specdojo/standards/standard-authoring-standard.md +2 -1
  75. package/docs/ja/specdojo/templates/pjr-change-request-template.md +10 -4
  76. package/docs/ja/specdojo/templates/pjr-issue-template.md +10 -4
  77. package/docs/ja/specdojo/templates/pjr-question-template.md +11 -5
  78. package/docs/ja/specdojo/templates/pjr-risk-template.md +10 -4
  79. package/docs/ja/specdojo/templates/pjr-todo-template.md +10 -4
  80. package/docs/specdojo/schemas/v1/dct.schema.yaml +9 -0
  81. package/docs/specdojo/schemas/v1/exec-common.schema.yaml +2 -1
  82. package/docs/specdojo/schemas/v1/exec-defaults.schema.yaml +1 -0
  83. package/docs/specdojo/schemas/v1/register-events.schema.yaml +3 -0
  84. package/docs/specdojo/schemas/v1/register-item-frontmatter.schema.yaml +35 -0
  85. package/docs/specdojo/schemas/v1/sch-strategy.schema.yaml +1 -0
  86. package/docs/specdojo/schemas/v1/specdojo-config.schema.yaml +40 -2
  87. package/package.json +3 -2
  88. package/templates/antigravity/orchestrator.md +2 -0
  89. package/templates/claude/agents/specdojo-orchestrator.md +2 -0
  90. package/templates/codex/agents/specdojo-orchestrator.toml +2 -0
  91. package/templates/codex/orchestrator.md +2 -0
  92. package/templates/devcontainer/remote-host/specdojo-tmux.sh.sample +14 -8
  93. package/templates/opencode/agents/specdojo-orchestrator.md +2 -0
@@ -0,0 +1,105 @@
1
+ import { createHash, randomUUID } from "node:crypto";
2
+ import { existsSync, linkSync, mkdirSync, readdirSync, readFileSync, unlinkSync, writeFileSync, } from "node:fs";
3
+ import { join, resolve } from "node:path";
4
+ import { isValidBranchName } from "../shared/branch-template.js";
5
+ import { gitOutput, gitResult, worktreeNameFromTaskId } from "./worktree.js";
6
+ function recordDirectory(repoRoot) {
7
+ const common = gitOutput(repoRoot, ["rev-parse", "--git-common-dir"]).trim();
8
+ return resolve(repoRoot, common, "specdojo", "product-branches");
9
+ }
10
+ function recordPath(repoRoot, branch) {
11
+ return join(recordDirectory(repoRoot), `${createHash("sha256").update(branch).digest("hex")}.json`);
12
+ }
13
+ export function productBranchRecords(repoRoot) {
14
+ const directory = recordDirectory(repoRoot);
15
+ if (!existsSync(directory))
16
+ return [];
17
+ return readdirSync(directory)
18
+ .filter((name) => name.endsWith(".json"))
19
+ .map((name) => {
20
+ const record = JSON.parse(readFileSync(join(directory, name), "utf8"));
21
+ if (!record ||
22
+ typeof record !== "object" ||
23
+ !("taskId" in record) ||
24
+ !("branch" in record) ||
25
+ typeof record.taskId !== "string" ||
26
+ typeof record.branch !== "string") {
27
+ throw new Error(`Invalid runner product branch record: ${name}`);
28
+ }
29
+ return {
30
+ taskId: record.taskId,
31
+ branch: record.branch,
32
+ ...("startCommit" in record && typeof record.startCommit === "string"
33
+ ? { startCommit: record.startCommit }
34
+ : {}),
35
+ };
36
+ });
37
+ }
38
+ export function recordedProductBranch(repoRoot, taskId) {
39
+ const records = productBranchRecords(repoRoot).filter((record) => record.taskId === taskId);
40
+ if (records.length > 1)
41
+ throw new Error(`Multiple runner product branches recorded for ${taskId}`);
42
+ return records[0]?.branch;
43
+ }
44
+ export function productBranchExists(repoRoot, branch) {
45
+ return (gitResult(repoRoot, ["show-ref", "--verify", "--quiet", `refs/heads/${branch}`]).status === 0);
46
+ }
47
+ /** A legacy name is usable only when no other task has explicitly claimed it. */
48
+ export function existingProductTaskBranch(repoRoot, taskId) {
49
+ const recorded = recordedProductBranch(repoRoot, taskId);
50
+ if (recorded)
51
+ return recorded;
52
+ const legacy = `exec/${worktreeNameFromTaskId(taskId)}`;
53
+ if (productBranchRecords(repoRoot).some((record) => record.branch === legacy))
54
+ return undefined;
55
+ return productBranchExists(repoRoot, legacy) ? legacy : undefined;
56
+ }
57
+ /** Legacy runs may be adopted only under their exact conventional branch name. */
58
+ export function assertProductBranchAvailable(repoRoot, taskId, branch) {
59
+ if (!isValidBranchName(repoRoot, branch)) {
60
+ throw new Error(`Invalid product branch name: ${branch}; use --branch <repo>=<name>`);
61
+ }
62
+ const owner = productBranchRecords(repoRoot).find((record) => record.branch === branch)?.taskId;
63
+ const legacy = branch === `exec/${worktreeNameFromTaskId(taskId)}`;
64
+ if ((owner && owner !== taskId) || (!owner && !legacy && productBranchExists(repoRoot, branch))) {
65
+ throw new Error(`Product branch ${branch} already exists or is reserved for ${owner ?? "another item"}; ` +
66
+ `change topic or use exec run --branch <repo>=<name> (no automatic suffix is added)`);
67
+ }
68
+ }
69
+ /** Exclusive creation also prevents concurrent tasks from reserving the same branch. */
70
+ export function reserveProductBranch(repoRoot, taskId, branch, startPoint = "HEAD") {
71
+ assertProductBranchAvailable(repoRoot, taskId, branch);
72
+ const previous = recordedProductBranch(repoRoot, taskId);
73
+ if (previous && previous !== branch) {
74
+ throw new Error(`Product branch for ${taskId} is already recorded as ${previous}; resume that branch or discard the old lifecycle before choosing ${branch}`);
75
+ }
76
+ mkdirSync(recordDirectory(repoRoot), { recursive: true });
77
+ const path = recordPath(repoRoot, branch);
78
+ if (existsSync(path))
79
+ return;
80
+ const temporary = `${path}.${randomUUID()}.tmp`;
81
+ try {
82
+ const startCommit = gitOutput(repoRoot, [
83
+ "rev-parse",
84
+ "--verify",
85
+ `${startPoint}^{commit}`,
86
+ ]).trim();
87
+ // Publish a complete record atomically; readers never observe partial JSON.
88
+ writeFileSync(temporary, JSON.stringify({ taskId, branch, startCommit }), { flag: "wx" });
89
+ linkSync(temporary, path);
90
+ }
91
+ catch (error) {
92
+ if (error.code !== "EEXIST")
93
+ throw error;
94
+ assertProductBranchAvailable(repoRoot, taskId, branch);
95
+ }
96
+ finally {
97
+ if (existsSync(temporary))
98
+ unlinkSync(temporary);
99
+ }
100
+ }
101
+ export function forgetProductBranch(repoRoot, branch) {
102
+ const path = recordPath(repoRoot, branch);
103
+ if (existsSync(path))
104
+ unlinkSync(path);
105
+ }
@@ -0,0 +1,52 @@
1
+ import { basename } from "node:path";
2
+ import { resolveItemCommitTypeAndScope } from "../register/item.js";
3
+ import { DEFAULT_BRANCH_TEMPLATE, expandBranchTemplate } from "../shared/branch-template.js";
4
+ import { worktreeNameFromTaskId } from "./worktree.js";
5
+ import { assertProductBranchAvailable, recordedProductBranch } from "./product-branch-records.js";
6
+ import { parseIntegrationBranchOverrides } from "./task-repos.js";
7
+ export function parseProductBranchOverrides(values) {
8
+ try {
9
+ return parseIntegrationBranchOverrides(values);
10
+ }
11
+ catch (error) {
12
+ throw new Error((error instanceof Error ? error.message : String(error)).replaceAll("--integration-branch", "--branch"));
13
+ }
14
+ }
15
+ /** Resolve and preflight names before register start or stale-worktree removal. */
16
+ export function resolveProductBranches(products, params) {
17
+ const overrides = parseProductBranchOverrides(params.overrides);
18
+ for (const repo of overrides.keys()) {
19
+ if (!products.some((product) => product.name === repo)) {
20
+ throw new Error(`--branch references undeclared product repository: ${repo}`);
21
+ }
22
+ }
23
+ return products.map((product) => {
24
+ const persisted = recordedProductBranch(product.repoRoot, params.taskId);
25
+ const override = overrides.get(product.name);
26
+ const resumedBranch = persisted ?? `exec/${worktreeNameFromTaskId(params.taskId)}`;
27
+ if (params.resume && override && override !== resumedBranch) {
28
+ throw new Error(`--branch cannot change the resumed run branch for ${product.name}: ${resumedBranch}`);
29
+ }
30
+ const { type, scope } = resolveItemCommitTypeAndScope(params.item, {
31
+ projectConfig: params.projectConfig,
32
+ repoConfig: params.projectConfig?.repos?.find((repo) => repo.name === product.name),
33
+ });
34
+ const topic = params.ticketPath
35
+ ? basename(params.ticketPath)
36
+ .replace(/^pjr-[a-z0-9]{4}-/, "")
37
+ .replace(/\.md$/, "")
38
+ : params.item.id.toLowerCase();
39
+ const branch = (params.resume ? resumedBranch : undefined) ??
40
+ override ??
41
+ expandBranchTemplate(product.branchTemplate ?? DEFAULT_BRANCH_TEMPLATE, {
42
+ project: params.projectId,
43
+ id: params.item.id,
44
+ topic,
45
+ type,
46
+ scope: scope ?? "",
47
+ title: params.item.title.replace(/\s+/g, " ").trim(),
48
+ });
49
+ assertProductBranchAvailable(product.repoRoot, params.taskId, branch);
50
+ return { ...product, branch };
51
+ });
52
+ }
@@ -0,0 +1,50 @@
1
+ import { basename } from "node:path";
2
+ import { resolveItemCommitTypeAndScope } from "../register/item.js";
3
+ import { expandCommitMessageTemplate } from "../shared/commit-message-template.js";
4
+ import { commitSubject } from "./run/mode-shared.js";
5
+ import { refsTrailer } from "./repo-trace.js";
6
+ import { productIntegrationTarget } from "./task-repos.js";
7
+ /** Build only product messages; project bookkeeping keeps its existing subjects. */
8
+ export function registerProductMessage(params) {
9
+ const { item, projectId, repoConfig, product } = params;
10
+ const template = params.kind === "commit"
11
+ ? repoConfig?.commit_subject_template
12
+ : repoConfig?.merge_message_template;
13
+ const { type, scope } = resolveItemCommitTypeAndScope(item, {
14
+ projectConfig: params.projectConfig,
15
+ repoConfig,
16
+ });
17
+ const topic = params.ticketPath
18
+ ? basename(params.ticketPath)
19
+ .replace(/^pjr-[a-z0-9]{4}-/, "")
20
+ .replace(/\.md$/, "")
21
+ : item.id.toLowerCase();
22
+ const expanded = template === undefined
23
+ ? commitSubject(`exec(register ${item.id}): `, item.title)
24
+ : expandCommitMessageTemplate(template, {
25
+ id: item.id,
26
+ project: projectId,
27
+ topic,
28
+ type,
29
+ scope: scope ?? "",
30
+ title: item.title.replace(/\s+/g, " ").trim(),
31
+ branch: product.branch,
32
+ target: productIntegrationTarget(product),
33
+ });
34
+ // Commit templates are subjects; merge templates may also provide a body.
35
+ const [first = "", ...body] = expanded.replace(/\r\n?/g, "\n").trim().split("\n");
36
+ const message = params.kind === "commit"
37
+ ? commitSubject("", expanded)
38
+ : [commitSubject("", first), ...body].join("\n");
39
+ const trailer = refsTrailer(projectId, item.id);
40
+ // Keep exactly one required trailer at the end, even if the template supplied it earlier.
41
+ const withoutTrailer = message
42
+ .split("\n")
43
+ .filter((line) => line.trim() !== trailer)
44
+ .join("\n")
45
+ .trimEnd();
46
+ if (!withoutTrailer.split("\n")[0]?.trim()) {
47
+ throw new Error(`${product.name}: ${params.kind} message template expanded to an empty subject`);
48
+ }
49
+ return `${withoutTrailer}\n\n${trailer}`;
50
+ }
@@ -1,3 +1,4 @@
1
+ import { readRegisterInput, registerInputSection } from "../register/input.js";
1
2
  import { resolveRegisterDeliverableTarget, } from "../register/deliverable-target.js";
2
3
  import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
3
4
  import { basename, extname, join, relative, resolve } from "node:path";
@@ -376,6 +377,9 @@ export async function generateRegisterPlan(opts) {
376
377
  const { item } = opts;
377
378
  const category = requireRunnableRegisterItem(item);
378
379
  const ticketPath = ticketPathFromItem(item, opts.registerPaths.projectRegisterPath);
380
+ const inputs = ticketPath && existsSync(ticketPath)
381
+ ? readRegisterInput(readFileSync(ticketPath, "utf8"))
382
+ : item.inputs;
379
383
  if (item.approach) {
380
384
  validateRegisterApproachTargets({
381
385
  repoRoot: specdojoRootDir(),
@@ -508,6 +512,7 @@ export async function generateRegisterPlan(opts) {
508
512
  deliverable,
509
513
  ...(refs ? { refs } : {}),
510
514
  ...(authoring ? { authoring } : {}),
515
+ registerInput: inputs,
511
516
  additionalConditions: [
512
517
  cataloglessConditions,
513
518
  registerCompletionConditions(item, ticketPath),
@@ -545,6 +550,7 @@ export async function generateRegisterPlan(opts) {
545
550
  _PJR_DUE_: item.due,
546
551
  _PJR_TICKET_REF_: ticketPath ? `\`${repoRelativePath(ticketPath)}\`` : "-",
547
552
  _RESULT_REF_: resultRef,
553
+ _REGISTER_INPUT_: registerInputSection(inputs),
548
554
  _GRADE_FINDINGS_: ticketPath ? registerGradeFindingsText(opts.projectId, ticketPath) : "- なし",
549
555
  _AUTOPILOT_CONSTRAINTS_: registerAutopilotConstraints(item),
550
556
  };
@@ -229,12 +229,14 @@ export function syncTaskWorktreesWithIntegrationTargets(params) {
229
229
  const synced = [];
230
230
  for (const product of params.worktree.repos ?? []) {
231
231
  const target = productIntegrationTarget(product);
232
- if (product.integrationStrategy === "branch-only") {
232
+ if (product.integrationStrategy === "branch-only" || product.integrationStrategy === "ff") {
233
233
  synced.push({
234
234
  repo: product.name,
235
235
  target,
236
236
  status: "skipped",
237
- detail: "product-side review (branch-only)",
237
+ detail: product.integrationStrategy === "ff"
238
+ ? "fast-forward only (ff)"
239
+ : "product-side review (branch-only)",
238
240
  });
239
241
  continue;
240
242
  }
@@ -1,3 +1,4 @@
1
+ import { productBranchRecords } from "./product-branch-records.js";
1
2
  import { appendFileSync, existsSync, mkdirSync } from "node:fs";
2
3
  import { dirname, resolve } from "node:path";
3
4
  import { acquireSchedulerLock, releaseSchedulerLock } from "./events.js";
@@ -148,7 +149,7 @@ export function commitProductWorktrees(params) {
148
149
  if (!existsSync(product.path))
149
150
  continue;
150
151
  const outcome = commitProductWorktree(product, {
151
- message: params.message,
152
+ message: typeof params.message === "function" ? params.message(product) : params.message,
152
153
  targetPaths: targetPaths.get(product.name),
153
154
  failureLogPath: params.failureLogPath,
154
155
  });
@@ -198,6 +199,11 @@ export function productMergeState(product) {
198
199
  ]);
199
200
  if (ancestor.status !== 0)
200
201
  return "pending";
202
+ if (product.integrationStrategy === "ff") {
203
+ const record = productBranchRecords(product.repoRoot).find((entry) => entry.branch === product.branch);
204
+ if (record?.startCommit)
205
+ return record.startCommit === gitText(tip.stdout).trim() ? "unchanged" : "merged";
206
+ }
201
207
  const firstParent = gitOutput(product.repoRoot, ["rev-list", "--first-parent", target])
202
208
  .split("\n")
203
209
  .map((line) => line.trim());
@@ -261,6 +267,12 @@ export function productMergeBlockers(product) {
261
267
  }
262
268
  if (productMergeState(product) !== "pending")
263
269
  return blockers;
270
+ if (product.integrationStrategy === "ff" &&
271
+ gitResult(product.repoRoot, ["merge-base", "--is-ancestor", target, product.branch]).status !==
272
+ 0) {
273
+ blockers.push(block(`cannot fast-forward ${target} to ${product.branch}: histories have diverged; no rebase or merge is performed`));
274
+ return blockers;
275
+ }
264
276
  const merged = mergeTree(product.repoRoot, target, product.branch);
265
277
  if (merged.kind === "conflicts") {
266
278
  blockers.push(block(`merge conflicts with ${target}: ${merged.paths.join(", ")}`));
@@ -329,8 +341,8 @@ export function projectMergeBlockers(params) {
329
341
  }
330
342
  // ── プロダクトの merge ─────────────────────────────────────────────────────
331
343
  /**
332
- * Merge the product exec branch into its integration target with a merge commit and return the
333
- * merge commit. When the target is checked out (normally the product's main checkout), a regular
344
+ * Integrate the product branch and return the resulting tip. The ff strategy only advances the
345
+ * target to the product tip, without creating a commit. For merge, when the target is checked out,
334
346
  * `git merge --no-ff` updates that working tree; a failed merge is aborted. Otherwise the merge
335
347
  * commit is written with `merge-tree` / `commit-tree` and the branch is moved with a
336
348
  * compare-and-swap `update-ref`, so a concurrent update of the target is never overwritten.
@@ -340,6 +352,29 @@ export function mergeProductIntoTarget(params) {
340
352
  const target = productIntegrationTarget(product);
341
353
  const checkout = checkoutOfBranch(product.repoRoot, target);
342
354
  const header = `=== ${new Date().toISOString()} ${product.name}: merge ${product.branch} into ${target} ===`;
355
+ if (product.integrationStrategy === "ff") {
356
+ const parent = gitOutput(product.repoRoot, ["rev-parse", `refs/heads/${target}`]).trim();
357
+ const tip = gitOutput(product.repoRoot, ["rev-parse", `${product.branch}^{commit}`]).trim();
358
+ if (gitResult(product.repoRoot, ["merge-base", "--is-ancestor", parent, tip]).status !== 0) {
359
+ throw new Error(`cannot fast-forward ${target} to ${product.branch}: histories have diverged; no rebase or merge is performed`);
360
+ }
361
+ const result = checkout
362
+ ? gitResult(checkout, ["merge", "--ff-only", tip])
363
+ : gitResult(product.repoRoot, [
364
+ "update-ref",
365
+ "-m",
366
+ `exec: fast-forward ${product.branch}`,
367
+ `refs/heads/${target}`,
368
+ tip,
369
+ parent,
370
+ ]);
371
+ if (result.status !== 0) {
372
+ const detail = gitText(result.stderr).trim() || gitText(result.stdout).trim();
373
+ appendGitFailureLog(params.failureLogPath, [header, `fast-forward failed: ${detail}`, ""]);
374
+ throw new Error(`cannot fast-forward ${target} to ${product.branch}: ${detail}`);
375
+ }
376
+ return tip;
377
+ }
343
378
  if (checkout) {
344
379
  const result = gitResult(checkout, ["merge", "--no-ff", "-m", message, product.branch]);
345
380
  if (result.status === 0)
@@ -519,7 +554,9 @@ export function integrateTaskRepositories(params) {
519
554
  }
520
555
  commit = mergeProductIntoTarget({
521
556
  product,
522
- message: params.productMergeMessage ?? params.mergeMessage,
557
+ message: typeof params.productMergeMessage === "function"
558
+ ? params.productMergeMessage(product)
559
+ : (params.productMergeMessage ?? params.mergeMessage),
523
560
  failureLogPath: params.failureLogPath,
524
561
  });
525
562
  }
@@ -46,6 +46,8 @@ function integrationCommitOf(product, target) {
46
46
  if (tip.status !== 0)
47
47
  return null;
48
48
  const tipSha = String(tip.stdout).trim();
49
+ if (product.integrationStrategy === "ff")
50
+ return tipSha;
49
51
  const lines = gitOutput(product.repoRoot, [
50
52
  "rev-list",
51
53
  "--first-parent",
@@ -105,9 +105,12 @@ function execResultDocId(projectId, mode, localBase) {
105
105
  const localId = `${prefix}-${localBase.toLowerCase()}`;
106
106
  return projectId ? `${projectId}:${localId}` : localId;
107
107
  }
108
- // approach が finalize 系なら xer-human-<approach>-template.md を優先し、無ければ
109
- // mode 別の標準テンプレートへフォールバックする(plan 側の human × approach 解決と対称)。
110
- function loadResultTemplate(mode, approach) {
108
+ // Human draft results guide scaffold/context entry; finalize results guide confirmation.
109
+ // Other approaches use their specialized result or the standard mode template.
110
+ function loadResultTemplate(mode, approach, execution) {
111
+ if (mode === "edit" && execution === "human" && approach === "draft") {
112
+ return readFileSync(resolveSpecdojoPath("docs/ja/specdojo/exec-templates/xer-human-draft-template.md"), "utf8");
113
+ }
111
114
  if (mode === "edit" && approach === "cross-deliverable-dedup") {
112
115
  const crossDeliverablePath = resolveSpecdojoPathIfExists("docs/ja/specdojo/exec-templates/xer-cross-deliverable-dedup-template.md");
113
116
  if (crossDeliverablePath)
@@ -160,7 +163,7 @@ async function supersedePriorResults(resultsDir, taskId, nextResultPath, superse
160
163
  const APPROACH_SECTION_WITH_APPROACH = [
161
164
  "## 4. 進め方と実践の型の適用",
162
165
  "",
163
- "_TODO_: `approach` に従ってどう進めたか、その進め方の中で実践の型(rulebook / recipe / sample / template)をどう適用したかを記入する(`fully-guided` で rulebook / recipe / sample / template をどう使い分けたか、`recipe-guided` で recipe のみを基準にした内容、`freeform` で実践の型より優先した実例やプロジェクト文脈、`retrofit` で実際に参照した実装パス・抽出した現在動作・反映/新設判断・未反映の乖離・未確認範囲、`rulebook-authoring` などの authoring 系で手本から一般化した内容・変更しなかった手本・参照の付け替えまたは見送り、`rulebook-maintenance` などの maintenance 系で見直した実践の型とその根拠、など)。実践の型を基準にしなかった場合は、その判断と代わりに根拠にした内容も記入する。複数文書間に矛盾があり rulebook を正として判断した箇所、参照範囲から外れていた文書とその代わりに根拠にした内容があれば、あわせて記録する。",
166
+ "_TODO_: `approach` に従ってどう進めたか、その進め方の中で実践の型(rulebook / recipe / sample / template)をどう適用したかを記入する(`draft` で任された範囲・提案値ごとの出典と選定理由・反映した元の指示、`fully-guided` で rulebook / recipe / sample に沿って既存成果物をどう磨き込んだか、`recipe-guided` で recipe のみを基準にした内容、`freeform` で実践の型より優先した実例やプロジェクト文脈、`retrofit` で実際に参照した実装パス・抽出した現在動作・反映/新設判断・未反映の乖離・未確認範囲、`rulebook-authoring` などの authoring 系で手本から一般化した内容・変更しなかった手本・参照の付け替えまたは見送り、`rulebook-maintenance` などの maintenance 系で見直した実践の型とその根拠、など)。実践の型を基準にしなかった場合は、その判断と代わりに根拠にした内容も記入する。複数文書間に矛盾があり rulebook を正として判断した箇所、参照範囲から外れていた文書とその代わりに根拠にした内容があれば、あわせて記録する。",
164
167
  ].join("\n");
165
168
  const APPROACH_SECTION_WITHOUT_APPROACH = [
166
169
  "## 4. 進め方",
@@ -178,7 +181,7 @@ export async function scaffoldResult(opts) {
178
181
  const resultsDir = join(executionPath, "exec", "results");
179
182
  if (!existsSync(resultsDir))
180
183
  mkdirSync(resultsDir, { recursive: true });
181
- const template = loadResultTemplate(mode, approach);
184
+ const template = loadResultTemplate(mode, approach, opts.execution);
182
185
  const meta = {
183
186
  id: execResultDocId(projectId, mode, stem),
184
187
  type: "exec-result",
@@ -770,6 +773,7 @@ export function parseResultTaskIdentity(resultContent) {
770
773
  const execution = meta.execution === "human" || meta.execution === "agent" ? meta.execution : undefined;
771
774
  const approach = meta.approach &&
772
775
  [
776
+ "draft",
773
777
  "fully-guided",
774
778
  "recipe-guided",
775
779
  "freeform",
@@ -1,3 +1,4 @@
1
+ import { parseProductBranchOverrides } from "../product-branches.js";
1
2
  import { loadExecDefaultsConfig, resolveRegisterPostReview } from "../agent-config.js";
2
3
  import { resolveProjectPaths } from "../project.js";
3
4
  import { isRegisterFailureMode } from "../register.js";
@@ -40,6 +41,7 @@ export function registerRunCommand(exec) {
40
41
  rcmd.option("--track-state", "Record claim/complete events (requires --task; --by optional, actor auto-derived from the resolved agent)", false);
41
42
  rcmd.option("--archive-on-success", "Archive the generated plan to exec/plans/done/ after a successful in-place run", false);
42
43
  rcmd.option("--integration-branch <repo=branch>", "With register worktree mode: integrate the declared product repository <repo> into the local branch <branch> for this run (repeatable; overrides repos[].integration_branch; resume reuses the value recorded at the start)", (value, previous = []) => [...previous, value]);
44
+ rcmd.option("--branch <repo=name>", "With register worktree mode: override a declared product work branch (repeatable; resume keeps the recorded branch)", (value, previous = []) => [...previous, value]);
43
45
  rcmd.option("--parallel <n>", "Number of worktree instances to run in parallel", "1");
44
46
  rcmd.option("--worktree-base <path>", "Override worktree base directory");
45
47
  rcmd.option("--strategy <s>", "Task selection strategy: critical-first|fifo (default: critical-first)");
@@ -124,6 +126,20 @@ export function registerRunCommand(exec) {
124
126
  process.exitCode = 1;
125
127
  return;
126
128
  }
129
+ const branches = parseProductBranchOverrides(opts.branch);
130
+ if (branches.size > 0) {
131
+ if (!(hasRegister && opts.worktree)) {
132
+ process.stdout.write("--branch requires --register (or --register-filter) in worktree mode.\n");
133
+ process.exitCode = 1;
134
+ return;
135
+ }
136
+ const products = configuredProductRepos(resolveProjectPaths({ project: opts.project }).schedulePath);
137
+ for (const repo of branches.keys()) {
138
+ if (!products.some((product) => product.name === repo)) {
139
+ throw new Error(`--branch references undeclared product repository: ${repo}`);
140
+ }
141
+ }
142
+ }
127
143
  const integrationBranches = opts.integrationBranch ?? [];
128
144
  if (integrationBranches.length > 0) {
129
145
  if (!(hasRegister && opts.worktree)) {
@@ -1,3 +1,5 @@
1
+ import { loadConfig } from "../../shared/specdojo-config.js";
2
+ import { resolveProductBranches } from "../product-branches.js";
1
3
  import { registerDependencyBlockReason } from "../../register/dependency.js";
2
4
  import { existsSync, readFileSync } from "node:fs";
3
5
  import { resolve } from "node:path";
@@ -193,7 +195,15 @@ export async function resumeSingleRegisterItemWorktree(context, opts, pjrId, lif
193
195
  let integrationBranchOverrides;
194
196
  try {
195
197
  const overrides = resumeIntegrationBranches(target.state.integration_branches, opts.integrationBranch);
196
- products = configuredProductRepos(schedulePath, overrides);
198
+ products = resolveProductBranches(configuredProductRepos(schedulePath, overrides), {
199
+ projectId,
200
+ taskId: worktreeTaskId,
201
+ item,
202
+ ticketPath,
203
+ projectConfig: loadConfig().config?.projects[projectId],
204
+ overrides: opts.branch,
205
+ resume: true,
206
+ });
197
207
  integrationBranchOverrides = overrides.size > 0 ? Object.fromEntries(overrides) : undefined;
198
208
  }
199
209
  catch (error) {
@@ -3,15 +3,17 @@ import { gradeCheckpointPaths } from "../grade-checkpoint.js";
3
3
  import { existsSync, readFileSync } from "node:fs";
4
4
  import { resolve } from "node:path";
5
5
  import { qualifyTaskId, randomHex } from "../shared.js";
6
- import { resolveAgentMember } from "../../shared/specdojo-config.js";
6
+ import { loadConfig, resolveAgentMember, } from "../../shared/specdojo-config.js";
7
+ import { resolveProductBranches } from "../product-branches.js";
8
+ import { registerProductMessage } from "../register-product-message.js";
7
9
  import { buildInPlaceStem } from "../plans.js";
8
10
  import { generateRegisterPlan, requireRunnableRegisterItem, resolveRegisterRunTarget, sanitizeRegisterConclusion, ticketPathFromItem, } from "../register.js";
9
11
  import { readResultFrontmatterSnapshot, scaffoldResult, updateResultStatus } from "../results.js";
10
- import { findExecWorktree, gitOutput } from "../worktree.js";
11
- import { configuredProductRepos, integrationBranchOverrideRecord, withProductRepoPrompt, } from "../task-repos.js";
12
+ import { findExecWorktree, gitOutput, } from "../worktree.js";
13
+ import { configuredProductRepos, integrationBranchOverrideRecord, reserveProductBranches, withProductRepoPrompt, } from "../task-repos.js";
12
14
  import { checkpointAndEnsureWorktree, commitTargetPaths, commitWorktreeChanges, discardStaleExecWorktree, isExecBranchMergedIntoCurrent, mergeWorktreeIntoCurrent, removeWorktree, taskTargetsAtHead, WorktreeRemovedBranchDeletionError, worktreeStatusPaths, } from "../worktree-ops.js";
13
15
  import { commitProductWorktrees, integrateTaskRepositories, projectMergeBlockers, PROJECT_REPO_NAME, RepoIntegrationError, } from "../repo-integration.js";
14
- import { productIntegrationTrace, recordResultTrace, refsTrailer, registerProjectMergeMessage, traceKey, withCommitTrailers, } from "../repo-trace.js";
16
+ import { productIntegrationTrace, recordResultTrace, registerProjectMergeMessage, traceKey, } from "../repo-trace.js";
15
17
  import { pipelineStateLocation, readPipelineState } from "../pipeline-state.js";
16
18
  import { findResumableRegisterRun } from "../register-resume.js";
17
19
  import { isAuthoringApproach } from "../../kata/authoring.js";
@@ -199,7 +201,18 @@ export async function finalizeRegisterWorktreeRun(params) {
199
201
  // PJR-30SW: プロダクト側の commit と merge commit、プロジェクト側の merge commit に
200
202
  // `Refs: <project-id>:<item-id>` を付ける(PJR-1SXK)。
201
203
  const itemTraceKey = traceKey(projectId, item.id);
202
- const productMessage = withCommitTrailers(subject, [refsTrailer(projectId, item.id)]);
204
+ const projectConfig = (worktree.repos?.length ?? 0) > 0
205
+ ? loadConfig(repoRoot).config?.projects[projectId]
206
+ : undefined;
207
+ const productMessage = (product, kind) => registerProductMessage({
208
+ projectId,
209
+ item,
210
+ ticketPath,
211
+ projectConfig,
212
+ product,
213
+ kind,
214
+ repoConfig: projectConfig?.repos?.find((repo) => repo.name === product.name),
215
+ });
203
216
  const integrateStartedAt = new Date().toISOString();
204
217
  recordIntegrateStage(params.pipelineStatePath, integrateStartedAt, (current) => ({
205
218
  status: "running",
@@ -213,7 +226,7 @@ export async function finalizeRegisterWorktreeRun(params) {
213
226
  try {
214
227
  const productOutcomes = commitProductWorktrees({
215
228
  worktree,
216
- message: productMessage,
229
+ message: (product) => productMessage(product, "commit"),
217
230
  targets: taskTargetsAtHead(wtContext, worktree, stem),
218
231
  scopeLogPath: integrateLogPath(params.pipelineStatePath),
219
232
  failureLogPath: integrateLogPath(params.pipelineStatePath),
@@ -262,7 +275,7 @@ export async function finalizeRegisterWorktreeRun(params) {
262
275
  integrateTaskRepositories({
263
276
  worktree,
264
277
  mergeMessage,
265
- productMergeMessage: productMessage,
278
+ productMergeMessage: (product) => productMessage(product, "merge"),
266
279
  checkProject: () => projectMergeBlockers({
267
280
  context: wtContext,
268
281
  worktree,
@@ -432,7 +445,14 @@ export async function runSingleRegisterItemWorktree(context, opts, pjrId, lifecy
432
445
  : undefined;
433
446
  // PJR-98G4: repos を宣言した project では、プロダクトの worktree も同じタスクの下に作る。
434
447
  // PJR-XRAB: --integration-branch は設定の integration_branch より優先する。
435
- const products = configuredProductRepos(schedulePath, opts.integrationBranch);
448
+ const products = resolveProductBranches(configuredProductRepos(schedulePath, opts.integrationBranch), {
449
+ projectId,
450
+ taskId: worktreeTaskId,
451
+ item,
452
+ ticketPath,
453
+ projectConfig: loadConfig().config?.projects[projectId],
454
+ overrides: opts.branch,
455
+ });
436
456
  const integrationBranchOverrides = integrationBranchOverrideRecord(opts.integrationBranch);
437
457
  // Phase 1: plan/result 生成 → register start → checkpoint → worktree 作成(root で直列化)。
438
458
  const setup = async () => {
@@ -466,6 +486,7 @@ export async function runSingleRegisterItemWorktree(context, opts, pjrId, lifecy
466
486
  const discarded = discardStaleExecWorktree({ context: wtContext, worktreeTaskId, products });
467
487
  if (discarded)
468
488
  process.stdout.write(` [run] discarded stale worktree/branch: ${discarded}\n`);
489
+ reserveProductBranches(products, worktreeTaskId);
469
490
  const { planPath } = await generateRegisterPlan({
470
491
  executionPath,
471
492
  projectId,
@@ -9,7 +9,7 @@ import { ensureReviewGrade } from "../../review/grade.js";
9
9
  import { gradeCheckpointPaths } from "../grade-checkpoint.js";
10
10
  import { isResultUnfilled, readResultFrontmatterSnapshot, scaffoldResult } from "../results.js";
11
11
  import { worktreeNameFromTaskId } from "../worktree.js";
12
- import { configuredProductRepos, plannedProjectWorktreePath } from "../task-repos.js";
12
+ import { configuredProductRepos, plannedProjectWorktreePath, preflightProductBranches, productBranchForTask, } from "../task-repos.js";
13
13
  import { checkpointAndEnsureWorktree, discardStaleExecWorktree } from "../worktree-ops.js";
14
14
  import { pipelineStateLocation } from "../pipeline-state.js";
15
15
  import { collectBusyActors, pinnedExecutor, pinnedReporter, resolveAgentOverride, resolveExecDefaultsPath, resolvePinnedRateLimitRunOptions, resolveTaskPhaseContext, selectCandidates, } from "./shared.js";
@@ -196,7 +196,11 @@ export async function prepareSingleTask(task, projectId, repoRoot, schedulePath,
196
196
  const worktreeTaskId = qualifyTaskId(projectId, task.id);
197
197
  const worktreeName = worktreeNameFromTaskId(worktreeTaskId);
198
198
  // PJR-98G4: repos を宣言した project では <base>/<task>/project/ と <base>/<task>/<repo>/ を作る。
199
- const products = configuredProductRepos(schedulePath);
199
+ const products = configuredProductRepos(schedulePath).map((product) => ({
200
+ ...product,
201
+ branch: productBranchForTask(product, worktreeTaskId, skipClaim),
202
+ }));
203
+ preflightProductBranches(products, worktreeTaskId);
200
204
  if (dryRun) {
201
205
  const worktree = {
202
206
  path: plannedProjectWorktreePath(worktreeBase, worktreeTaskId, products),
@@ -207,7 +211,7 @@ export async function prepareSingleTask(task, projectId, repoRoot, schedulePath,
207
211
  process.stdout.write(` [run] would setup: worktree ${worktree.path} (${worktree.branch})\n`);
208
212
  for (const product of products) {
209
213
  process.stdout.write(` [run] would setup: worktree ${join(worktreeBase, worktreeName, product.name)} ` +
210
- `(${worktree.branch} in ${product.repoRoot})\n`);
214
+ `(${productBranchForTask(product, worktreeTaskId)} in ${product.repoRoot})\n`);
211
215
  }
212
216
  const claimMsg = skipClaim
213
217
  ? ` [dry-run] already claimed: ${task.id} as ${actor} (skip claim)`
@@ -4,7 +4,8 @@ function isTaskMode(value) {
4
4
  return value === "edit" || value === "review";
5
5
  }
6
6
  function isApproach(value) {
7
- return (value === "fully-guided" ||
7
+ return (value === "draft" ||
8
+ value === "fully-guided" ||
8
9
  value === "recipe-guided" ||
9
10
  value === "freeform" ||
10
11
  value === "bootstrap" ||