specdojo 0.2.1 → 0.3.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 (168) hide show
  1. package/.github/agents/specdojo-orchestrator.md +165 -0
  2. package/CHANGELOG.md +280 -0
  3. package/README.md +92 -42
  4. package/dist/agent-response.js +20 -0
  5. package/dist/agent.js +4 -4
  6. package/dist/build-command.js +28 -8
  7. package/dist/dashboard.js +122 -1
  8. package/dist/devcontainer-command.js +43 -0
  9. package/dist/devcontainer-scaffold.js +165 -0
  10. package/dist/exec-agent-config.js +107 -9
  11. package/dist/exec-agent-git-state.js +18 -0
  12. package/dist/exec-agent-protected-config.js +46 -8
  13. package/dist/exec-evidence.js +254 -11
  14. package/dist/exec-handoff.js +336 -0
  15. package/dist/exec-parent-validation.js +317 -43
  16. package/dist/exec-pipeline-state.js +74 -9
  17. package/dist/exec-plans.js +115 -113
  18. package/dist/exec-protection-handoff.js +43 -2
  19. package/dist/exec-provider-scaffold.js +247 -15
  20. package/dist/exec-register-resume.js +65 -19
  21. package/dist/exec-register.js +9 -3
  22. package/dist/exec-repo-integration.js +811 -0
  23. package/dist/exec-repo-trace.js +182 -0
  24. package/dist/exec-reporter.js +613 -132
  25. package/dist/exec-results.js +81 -56
  26. package/dist/exec-run-lock.js +110 -107
  27. package/dist/exec-run.js +1585 -356
  28. package/dist/exec-shared.js +7 -0
  29. package/dist/exec-slot-lock.js +242 -0
  30. package/dist/exec-task-repos.js +415 -0
  31. package/dist/exec-trial.js +51 -25
  32. package/dist/exec-worktree-command.js +87 -43
  33. package/dist/exec-worktree-ops.js +502 -57
  34. package/dist/exec-worktree.js +114 -27
  35. package/dist/exec.js +13 -6
  36. package/dist/grade-result.js +128 -0
  37. package/dist/grade.js +809 -72
  38. package/dist/init-command.js +443 -0
  39. package/dist/job.js +160 -10
  40. package/dist/orchestrator.js +213 -0
  41. package/dist/register-event-merge.js +169 -0
  42. package/dist/register-item.js +7 -1
  43. package/dist/register.js +294 -86
  44. package/dist/review-grade.js +252 -0
  45. package/dist/review-plan.js +111 -1
  46. package/dist/review-types.js +40 -1
  47. package/dist/routine.js +72 -5
  48. package/dist/schedule-build.js +2 -2
  49. package/dist/schedule.js +17 -4
  50. package/dist/specdojo-config.js +465 -19
  51. package/dist/specdojo-gitignore.js +135 -0
  52. package/dist/specdojo.js +6 -0
  53. package/dist/viewpoint-document-kinds-check.js +128 -0
  54. package/docs/ja/specdojo/defaults/pm-review-viewpoints.yaml +348 -90
  55. package/docs/ja/specdojo/exec-templates/xep-common-conventions-template.md +51 -17
  56. package/docs/ja/specdojo/exec-templates/xep-fully-guided-template.md +7 -5
  57. package/docs/ja/specdojo/exec-templates/xrp-freeform-template.md +29 -31
  58. package/docs/ja/specdojo/exec-templates/xrp-fully-guided-template.md +34 -55
  59. package/docs/ja/specdojo/exec-templates/xrp-job-template.md +54 -0
  60. package/docs/ja/specdojo/exec-templates/xrp-recipe-guided-template.md +28 -37
  61. package/docs/ja/specdojo/exec-templates/xrp-recipe-maintenance-template.md +29 -34
  62. package/docs/ja/specdojo/exec-templates/xrp-retrofit-template.md +30 -30
  63. package/docs/ja/specdojo/exec-templates/xrp-rulebook-maintenance-template.md +29 -34
  64. package/docs/ja/specdojo/exec-templates/xrp-sample-maintenance-template.md +29 -34
  65. package/docs/ja/specdojo/exec-templates/xrp-template-maintenance-template.md +29 -34
  66. package/docs/ja/specdojo/exec-templates/xrp-template.md +29 -28
  67. package/docs/ja/specdojo/exec-templates/xrr-template.md +11 -9
  68. package/docs/ja/specdojo/guides/docs-editing-guide.md +20 -0
  69. package/docs/ja/specdojo/guides/docs-structure-guide.md +103 -70
  70. package/docs/ja/specdojo/guides/exec-config-guide.md +91 -47
  71. package/docs/ja/specdojo/guides/exec-operation-guide.md +124 -27
  72. package/docs/ja/specdojo/guides/exec-worktree-guide.md +40 -11
  73. package/docs/ja/specdojo/guides/kata-guide.md +4 -4
  74. package/docs/ja/specdojo/guides/orchestrator-operation-guide.md +25 -4
  75. package/docs/ja/specdojo/guides/plan-result-lifecycle-guide.md +1 -1
  76. package/docs/ja/specdojo/guides/practice-system-composition-guide.md +13 -13
  77. package/docs/ja/specdojo/guides/quick-start-guide.md +260 -30
  78. package/docs/ja/specdojo/guides/register-operation-guide.md +31 -14
  79. package/docs/ja/specdojo/guides/release-v0-3-0-migration-guide.md +264 -0
  80. package/docs/ja/specdojo/guides/remote-host-development-guide.md +22 -1
  81. package/docs/ja/specdojo/guides/review-guide.md +195 -158
  82. package/docs/ja/specdojo/guides/routine-operation-guide.md +74 -9
  83. package/docs/ja/specdojo/guides/ryu-guide.md +32 -30
  84. package/docs/ja/specdojo/guides/schedule-design-guide.md +10 -10
  85. package/docs/ja/specdojo/guides/schedule-operation-guide.md +1 -1
  86. package/docs/ja/specdojo/guides/specdojo-overview-guide.md +58 -33
  87. package/docs/ja/specdojo/guides/use-case-guide.md +3 -3
  88. package/docs/ja/specdojo/guides/waza-guide.md +15 -2
  89. package/docs/ja/specdojo/index.md +2 -2
  90. package/docs/ja/specdojo/philosophy/specdojo-philosophy.md +5 -5
  91. package/docs/ja/specdojo/recipes/bps-recipe.md +213 -0
  92. package/docs/ja/specdojo/recipes/pm-members-recipe.md +52 -117
  93. package/docs/ja/specdojo/references/command-reference.md +335 -92
  94. package/docs/ja/specdojo/references/deliverables-reference.md +1 -1
  95. package/docs/ja/specdojo/references/directory-layout-reference.md +13 -9
  96. package/docs/ja/specdojo/references/specdojo-config-reference.md +107 -24
  97. package/docs/ja/specdojo/rulebooks/bps-rulebook.md +132 -220
  98. package/docs/ja/specdojo/rulebooks/br-rulebook.md +6 -44
  99. package/docs/ja/specdojo/rulebooks/cdfd-rulebook.md +2 -0
  100. package/docs/ja/specdojo/rulebooks/dmd-rulebook.md +0 -87
  101. package/docs/ja/specdojo/rulebooks/gl-rulebook.md +61 -39
  102. package/docs/ja/specdojo/rulebooks/ifx-cmd-rulebook.md +0 -87
  103. package/docs/ja/specdojo/rulebooks/ifx-index-rulebook.md +1 -33
  104. package/docs/ja/specdojo/rulebooks/opd-rulebook.md +0 -137
  105. package/docs/ja/specdojo/rulebooks/opr-rulebook.md +0 -247
  106. package/docs/ja/specdojo/rulebooks/otp-rulebook.md +0 -83
  107. package/docs/ja/specdojo/rulebooks/pjr-rulebook.md +4 -2
  108. package/docs/ja/specdojo/rulebooks/pm-members-rulebook.md +78 -150
  109. package/docs/ja/specdojo/rulebooks/pm-roles-rulebook.md +5 -4
  110. package/docs/ja/specdojo/rulebooks/sch-rulebook.md +1 -1
  111. package/docs/ja/specdojo/rulebooks/stsd-mermaid-rulebook.md +0 -11
  112. package/docs/ja/specdojo/rulebooks/stsd-rulebook.md +0 -61
  113. package/docs/ja/specdojo/rulebooks/tml-rulebook.md +2 -47
  114. package/docs/ja/specdojo/samples/bps-sample.md +74 -21
  115. package/docs/ja/specdojo/samples/gl-sample.yaml +17 -1
  116. package/docs/ja/specdojo/samples/ifx-index-sample.yaml +28 -0
  117. package/docs/ja/specdojo/samples/pm-members-sample.yaml +2 -67
  118. package/docs/ja/specdojo/samples/pm-organization-sample.md +8 -7
  119. package/docs/ja/specdojo/samples/pm-raci-sample.md +1 -1
  120. package/docs/ja/specdojo/samples/tml-sample.yaml +40 -0
  121. package/docs/ja/specdojo/standards/document-metadata-standard.md +21 -16
  122. package/docs/ja/specdojo/standards/id-and-file-naming-standard.md +14 -14
  123. package/docs/ja/specdojo/standards/job-definition-standard.md +37 -17
  124. package/docs/ja/specdojo/standards/people-and-organization-definition-standard.md +37 -32
  125. package/docs/ja/specdojo/standards/philosophy-authoring-standard.md +1 -1
  126. package/docs/ja/specdojo/standards/rulebook-authoring-standard.md +21 -11
  127. package/docs/ja/specdojo/templates/agent-members-template.yaml +25 -0
  128. package/docs/ja/specdojo/templates/bps-template.md +91 -0
  129. package/docs/ja/specdojo/templates/pm-members-template.yaml +2 -59
  130. package/docs/specdojo/schemas/v1/agent-members.schema.yaml +76 -0
  131. package/docs/specdojo/schemas/v1/exec-common.schema.yaml +4 -2
  132. package/docs/specdojo/schemas/v1/exec-defaults.schema.yaml +55 -2
  133. package/docs/specdojo/schemas/v1/exec-evidence.schema.yaml +93 -6
  134. package/docs/specdojo/schemas/v1/exec-reporter-output.schema.yaml +27 -78
  135. package/docs/specdojo/schemas/v1/gl.schema.yaml +87 -0
  136. package/docs/specdojo/schemas/v1/grade-result.schema.yaml +33 -0
  137. package/docs/specdojo/schemas/v1/job-run.schema.yaml +27 -0
  138. package/docs/specdojo/schemas/v1/job.schema.yaml +25 -0
  139. package/docs/specdojo/schemas/v1/pipeline-state.schema.yaml +49 -1
  140. package/docs/specdojo/schemas/v1/pm-members.schema.yaml +9 -169
  141. package/docs/specdojo/schemas/v1/pm-review-viewpoints.schema.yaml +100 -10
  142. package/docs/specdojo/schemas/v1/register-item-frontmatter.schema.yaml +13 -0
  143. package/docs/specdojo/schemas/v1/routine-run.schema.yaml +3 -0
  144. package/docs/specdojo/schemas/v1/routine.schema.yaml +7 -0
  145. package/docs/specdojo/schemas/v1/specdojo-config.schema.yaml +110 -0
  146. package/package.json +15 -9
  147. package/templates/antigravity/README.md +27 -2
  148. package/templates/antigravity/{pm-members-snippet.yaml → agent-members-snippet.yaml} +8 -2
  149. package/templates/antigravity/exec-defaults-snippet.yaml +7 -6
  150. package/templates/antigravity/orchestrator.md +18 -7
  151. package/templates/antigravity/settings.global.json +55 -0
  152. package/templates/claude/agents/claude-executor.md +14 -0
  153. package/templates/claude/agents/claude-reporter.md +16 -0
  154. package/templates/claude/agents/specdojo-orchestrator.md +18 -7
  155. package/templates/claude/settings.edit.json +27 -1
  156. package/templates/codex/README.md +5 -4
  157. package/templates/codex/agents/specdojo-orchestrator.toml +18 -7
  158. package/templates/codex/orchestrator.md +18 -7
  159. package/templates/copilot/README.md +7 -5
  160. package/templates/copilot/{pm-members-snippet.yaml → agent-members-snippet.yaml} +4 -2
  161. package/templates/devcontainer/devcontainer.json +27 -0
  162. package/templates/devcontainer/emacs/init.el +88 -0
  163. package/templates/devcontainer/post-create.sh +62 -0
  164. package/templates/init-agent-members.yaml +200 -0
  165. package/templates/init-exec-defaults.yaml +72 -0
  166. package/templates/opencode/agents/specdojo-orchestrator.md +18 -7
  167. package/docs/ja/specdojo/exec-templates/xrp-viewpoint-detail-template.md +0 -7
  168. package/docs/ja/specdojo/exec-templates/xrr-viewpoint-detail-template.md +0 -7
@@ -1,7 +1,7 @@
1
1
  import { spawnSync } from "node:child_process";
2
- import { existsSync, lstatSync, mkdirSync, unlinkSync } from "node:fs";
3
- import { isAbsolute, join, relative, resolve, sep } from "node:path";
4
- import { stripTerminalControlSequences } from "./exec-shared.js";
2
+ import { appendFileSync, existsSync, lstatSync, mkdirSync, unlinkSync } from "node:fs";
3
+ import { dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
4
+ import { redactSensitiveText, stripTerminalControlSequences } from "./exec-shared.js";
5
5
  import { gitEnvironment } from "./git-environment.js";
6
6
  export { GIT_LOCAL_ENV_VARS, gitEnvironment } from "./git-environment.js";
7
7
  // git serializes index access through .git/index.lock and fails immediately (no wait) when it
@@ -11,32 +11,86 @@ export { GIT_LOCAL_ENV_VARS, gitEnvironment } from "./git-environment.js";
11
11
  // happens before git mutates anything, so retrying the same command is safe and idempotent.
12
12
  const INDEX_LOCK_RETRY_ATTEMPTS = 5;
13
13
  const INDEX_LOCK_RETRY_BASE_MS = 50;
14
+ // dubious ownership と、`.git` がある cwd での not-a-repository は一時的に起き、すぐの
15
+ // 再試行では収まらないことがある(並行実行中の統合段で確認した)。両方で上限を共有する。
16
+ const TRANSIENT_GIT_RETRY_DELAYS_MS = [2000, 5000, 10000];
14
17
  export function isGitIndexLockContention(stderr) {
15
18
  return (/Unable to create '[^']*index\.lock'/.test(stderr) ||
16
19
  /Another git process seems to be running/.test(stderr));
17
20
  }
21
+ export function isGitDubiousOwnership(stderr) {
22
+ return /fatal:\s+detected dubious ownership in repository\b/i.test(stderr);
23
+ }
24
+ export function isGitNotRepositoryWithGitMetadata(stderr, repoRoot) {
25
+ if (!/\bnot a git repository\b/i.test(stderr))
26
+ return false;
27
+ try {
28
+ const metadata = lstatSync(join(resolve(repoRoot), ".git"));
29
+ return metadata.isFile() || metadata.isDirectory();
30
+ }
31
+ catch {
32
+ return false;
33
+ }
34
+ }
18
35
  // Synchronously block the thread. gitResult is intentionally spawnSync-based (blocking), and we
19
36
  // want to wait for a contended index.lock to be released before retrying rather than busy-loop.
20
37
  function sleepSync(milliseconds) {
21
38
  Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, milliseconds);
22
39
  }
40
+ export function transientGitFailureReason(stderr, repoRoot) {
41
+ if (isGitDubiousOwnership(stderr))
42
+ return "dubious ownership";
43
+ if (repoRoot !== undefined && isGitNotRepositoryWithGitMetadata(stderr, repoRoot)) {
44
+ return "not a git repository";
45
+ }
46
+ return undefined;
47
+ }
48
+ export function runGitWithTransientRetry(run, onTransientFailureRetry = () => undefined, sleep = sleepSync, repoRoot) {
49
+ let indexLockRetries = 0;
50
+ let transientFailureRetries = 0;
51
+ let result = run();
52
+ while (result.status !== 0) {
53
+ const stderr = typeof result.stderr === "string" ? result.stderr : "";
54
+ const transientFailure = transientGitFailureReason(stderr, repoRoot);
55
+ if (transientFailureRetries < TRANSIENT_GIT_RETRY_DELAYS_MS.length &&
56
+ transientFailure !== undefined) {
57
+ const waitMilliseconds = TRANSIENT_GIT_RETRY_DELAYS_MS[transientFailureRetries];
58
+ transientFailureRetries += 1;
59
+ onTransientFailureRetry({
60
+ attempt: transientFailureRetries,
61
+ maxAttempts: TRANSIENT_GIT_RETRY_DELAYS_MS.length,
62
+ waitMilliseconds,
63
+ reason: transientFailure,
64
+ });
65
+ sleep(waitMilliseconds);
66
+ result = run();
67
+ continue;
68
+ }
69
+ if (indexLockRetries < INDEX_LOCK_RETRY_ATTEMPTS && isGitIndexLockContention(stderr)) {
70
+ indexLockRetries += 1;
71
+ sleep(INDEX_LOCK_RETRY_BASE_MS * indexLockRetries); // 50, 100, 150, 200, 250 ms
72
+ result = run();
73
+ continue;
74
+ }
75
+ break;
76
+ }
77
+ return result;
78
+ }
23
79
  export function gitResult(repoRoot, args) {
24
- const run = () => spawnSync("git", ["-C", repoRoot, ...args], {
80
+ const cwd = resolve(repoRoot);
81
+ const run = () => spawnSync("git", ["-C", cwd, ...args], {
82
+ // `-C` だけに依存せず、子プロセス自体も対象 repository から起動する。linked worktree の
83
+ // `.git` が相対 gitdir の場合も、resume 中の diff を runner の cwd から切り離す。
84
+ cwd,
25
85
  encoding: "utf8",
26
86
  env: gitEnvironment(),
27
87
  stdio: ["ignore", "pipe", "pipe"],
28
88
  });
29
- let result = run();
30
- for (let attempt = 1; attempt <= INDEX_LOCK_RETRY_ATTEMPTS; attempt++) {
31
- if (result.status === 0)
32
- break;
33
- const stderr = typeof result.stderr === "string" ? result.stderr : "";
34
- if (!isGitIndexLockContention(stderr))
35
- break;
36
- sleepSync(INDEX_LOCK_RETRY_BASE_MS * attempt); // 50, 100, 150, 200, 250 ms
37
- result = run();
38
- }
39
- return result;
89
+ return runGitWithTransientRetry(run, ({ attempt, maxAttempts, waitMilliseconds, reason }) => {
90
+ const summary = summarizeGitArguments(args);
91
+ process.stderr.write(`warning: git command failed with ${reason}; retrying in ${waitMilliseconds / 1000}s` +
92
+ ` (attempt ${attempt}/${maxAttempts}, cwd: ${repoRoot}${summary ? `, args: ${summary}` : ""})\n`);
93
+ }, sleepSync, cwd);
40
94
  }
41
95
  // git 失敗メッセージは register イベントの reason、result の block_reason、実行ログの一覧行の
42
96
  // いずれでも長さ上限で切り詰められて記録される。commit のように pathspec が全件並ぶコマンドでは、
@@ -91,8 +145,9 @@ export function formatGitCommandFailure(args, stderr) {
91
145
  const cause = summarizeGitStderr(stderr);
92
146
  return cause ? `${label} failed: ${cause}${detail}` : `${label} failed${detail}`;
93
147
  }
94
- // lefthook などの hook 出力から、block reason に載せる「失敗ステップ名 + 最初のエラー行」
95
- // を取り出す。罫線や ANSI 制御は監査ログには残す一方、短い理由には混ぜない。
148
+ // lefthook などの hook 出力から、block reason に載せる失敗ステップ名と最初のエラー行を
149
+ // 取り出し、Vitest の失敗テスト名・集計があれば末尾から補う。罫線や ANSI 制御は監査ログには
150
+ // 残す一方、短い理由には混ぜない。
96
151
  export function summarizeGitHookFailure(output) {
97
152
  const lines = stripTerminalControlSequences(output)
98
153
  .split(/\r?\n/)
@@ -119,13 +174,30 @@ export function summarizeGitHookFailure(output) {
119
174
  const errorLine = lines
120
175
  .slice(stepIndex >= 0 ? stepIndex + 1 : 0)
121
176
  .find((line) => line !== step && !isDecoration(line) && !/[❯▶]\s*$/u.test(line));
122
- if (step && errorLine)
123
- return `${step}: ${errorLine}`;
124
- if (step)
125
- return step;
126
- return (lines.find((line) => /(?:\bCONFLICT\b|\bfatal:|\berror:|\bfailed\b)/i.test(line)) ??
127
- lines.find((line) => !isDecoration(line)) ??
128
- lines[0]);
177
+ const primary = step && errorLine
178
+ ? `${step}: ${errorLine}`
179
+ : step ||
180
+ (lines.find((line) => /(?:\bCONFLICT\b|\bfatal:|\berror:|\bfailed\b)/i.test(line)) ??
181
+ lines.find((line) => !isDecoration(line)) ??
182
+ lines[0]);
183
+ const tail = lines
184
+ .filter((line) => /^(?:FAIL\b|Test Files\b|Tests\b)/iu.test(line))
185
+ .filter((line) => line !== errorLine && !primary.includes(line))
186
+ .slice(-3);
187
+ const summary = [primary, ...tail].join("; ");
188
+ const limit = 400;
189
+ if (summary.length <= limit)
190
+ return summary;
191
+ const marker = " … ";
192
+ const retained = limit - marker.length;
193
+ return `${summary.slice(0, Math.ceil(retained / 2))}${marker}${summary.slice(-Math.floor(retained / 2))}`;
194
+ }
195
+ /** Appends redacted Git/hook diagnostics to a run-scoped evidence log. */
196
+ export function appendGitFailureLog(path, lines) {
197
+ if (!path)
198
+ return;
199
+ mkdirSync(dirname(path), { recursive: true });
200
+ appendFileSync(path, redactSensitiveText(`${lines.join("\n")}\n`), "utf8");
129
201
  }
130
202
  // message は block reason 向けに要約する一方、調査に必要な stderr 全文は失わない。
131
203
  export class GitCommandError extends Error {
@@ -246,8 +318,15 @@ function removeLegacyNodeModulesLink(packageDir) {
246
318
  // Git worktree は独自の作業ツリーを持つだけで node_modules は引き継がないため、
247
319
  // tracked package-lock.json ごとに npm ci を実行し、worktree 内へ独立して依存を配置する。
248
320
  // 旧方式の共有 symlink は npm に辿らせず、先に link 自体だけを削除する。
321
+ // lock が無い worktree は導入しない。依存が無いまま検証が失敗したときに原因を追えるよう、
322
+ // 導入しなかったことをログに残す(PJR-86Q5)。
249
323
  export function installWorktreeDependencies(worktreePath, npmCi = runNpmCi) {
250
- for (const packageDir of trackedPackageLockDirs(resolve(worktreePath))) {
324
+ const packageDirs = trackedPackageLockDirs(resolve(worktreePath));
325
+ if (packageDirs.length === 0) {
326
+ process.stdout.write(`Skipping worktree dependencies: no tracked package-lock.json in ${worktreePath}\n`);
327
+ return;
328
+ }
329
+ for (const packageDir of packageDirs) {
251
330
  if (!existsSync(join(packageDir, "package.json"))) {
252
331
  throw new Error(`package.json is missing next to package-lock.json: ${packageDir}`);
253
332
  }
@@ -315,6 +394,14 @@ export function generateWorktreeArtifacts(worktreePath, build = runWorktreeBuild
315
394
  return;
316
395
  build(root);
317
396
  }
397
+ /**
398
+ * Path of a task worktree. Without `repoDirName` (projects without `repos`) the worktree is
399
+ * `<base>/<task-name>/`; with it, each repository gets `<base>/<task-name>/<repoDirName>/`.
400
+ */
401
+ export function execWorktreePath(worktreeBase, taskId, repoDirName) {
402
+ const name = worktreeNameFromTaskId(taskId);
403
+ return resolve(repoDirName ? join(worktreeBase, name, repoDirName) : join(worktreeBase, name));
404
+ }
318
405
  export function ensureExecWorktree(opts) {
319
406
  const repoRoot = resolve(opts.repoRoot);
320
407
  const baseRelative = relative(repoRoot, resolve(opts.worktreeBase));
@@ -323,7 +410,7 @@ export function ensureExecWorktree(opts) {
323
410
  }
324
411
  const name = worktreeNameFromTaskId(opts.taskId);
325
412
  const branch = `exec/${name}`;
326
- const worktreePath = resolve(join(opts.worktreeBase, name));
413
+ const worktreePath = execWorktreePath(opts.worktreeBase, opts.taskId, opts.repoDirName);
327
414
  const registered = listRegisteredWorktrees(repoRoot);
328
415
  const registeredAtPath = registered.find((item) => item.path === worktreePath);
329
416
  if (registeredAtPath) {
@@ -340,7 +427,7 @@ export function ensureExecWorktree(opts) {
340
427
  if (existsSync(worktreePath)) {
341
428
  throw new Error(`Worktree path already exists but is not registered: ${worktreePath}`);
342
429
  }
343
- mkdirSync(opts.worktreeBase, { recursive: true });
430
+ mkdirSync(dirname(worktreePath), { recursive: true });
344
431
  const branchExists = gitResult(repoRoot, ["show-ref", "--verify", "--quiet", `refs/heads/${branch}`]).status === 0;
345
432
  const args = branchExists
346
433
  ? ["worktree", "add", worktreePath, branch]
package/dist/exec.js CHANGED
@@ -7,16 +7,18 @@ import { assertValidActor, getProjectViewpointsPath, loadConfig, loadMemberRoste
7
7
  import { buildScheduleIndex, computeCpm, exitWithCode, printValidateResult, selectNextTask, validateAll, writeCpmFiles, writeGeneratedCore, writeScheduleHashAndDiff, } from "./exec-schedule.js";
8
8
  import { readReadySnapshot } from "./exec-schedule-ready.js";
9
9
  import { displayWidth, nowUtcIsoSeconds, padEndDisplay, qualifyTaskId, requireNonEmpty, } from "./exec-shared.js";
10
- import { archivePlan, buildInPlaceStem, generateDeliverablePlan, generateSinglePlan, resolveDeliverableTarget, finalizeResultSectionsForDeliverable, reviewResultSectionsForDeliverable, targetDocIdsForScheduledTask, stemFromPlanPath, } from "./exec-plans.js";
10
+ import { archivePlan, buildInPlaceStem, generateDeliverablePlan, generateSinglePlan, resolveDeliverableTarget, finalizeResultSectionsForDeliverable, targetDocIdsForScheduledTask, stemFromPlanPath, } from "./exec-plans.js";
11
11
  import { resetResultForClaim, scaffoldResult } from "./exec-results.js";
12
12
  import { runProviderScaffold, specdojoPackageRootDir } from "./exec-provider-scaffold.js";
13
13
  import { generateRegisterPlan, normalizePjrId, resolveRegisterRunTarget } from "./exec-register.js";
14
14
  import { scaffoldViewpoints } from "./review-plan.js";
15
- import { registerCycleCommand, registerResumeCommand, registerRunCommand } from "./exec-run.js";
15
+ import { registerCycleCommand, registerResumeCommand, registerRunCommand, registerSlotsCommand, } from "./exec-run.js";
16
16
  import { buildTaskView } from "./exec-task-view.js";
17
17
  import { registerExecWorktreeCommands } from "./exec-worktree-command.js";
18
18
  import { registerExecTrialCommands } from "./exec-trial.js";
19
+ import { registerExecHandoffCommands } from "./exec-handoff.js";
19
20
  import { discardStaleExecWorktree } from "./exec-worktree-ops.js";
21
+ import { configuredProductRepos } from "./exec-task-repos.js";
20
22
  import { buildInitialStateFromStrategy } from "./exec-schedule-initial.js";
21
23
  import { buildPhaseModeIndex, resolveApproach, resolveOwnerForLocalId, resolveTaskExecution, resolveTaskMode, } from "./exec-strategy.js";
22
24
  const KNOWN_OWNER_LABELS = ["PO", "PM", "BA", "ARC", "DEV", "QE", "UX", "OPS"];
@@ -206,9 +208,6 @@ async function scaffoldClaimResult(opts) {
206
208
  const mode = resolveTaskMode(localId, opts.taskId, phaseModeIndex, scheduleNode?.phase_suffix, scheduleNode?.phase_set);
207
209
  const approach = resolveApproach(localId, opts.taskId, phaseModeIndex, scheduleNode?.phase_suffix, scheduleNode?.phase_set);
208
210
  const execution = resolveTaskExecution(localId, opts.taskId, phaseModeIndex, scheduleNode?.phase_suffix, scheduleNode?.phase_set);
209
- const reviewSections = mode === "review"
210
- ? reviewResultSectionsForDeliverable(opts.catalogPath ?? "", localId)
211
- : undefined;
212
211
  const finalizeSections = approach === "finalize" || approach === "bootstrap-finalize"
213
212
  ? finalizeResultSectionsForDeliverable(opts.catalogPath ?? "", localId, approach)
214
213
  : undefined;
@@ -228,7 +227,6 @@ async function scaffoldClaimResult(opts) {
228
227
  execution,
229
228
  ...(approach ? { approach } : {}),
230
229
  ...(targets ? { targets } : {}),
231
- ...(reviewSections ? { reviewSections } : {}),
232
230
  ...(finalizeSections ? { finalizeSections } : {}),
233
231
  });
234
232
  if (!result.created) {
@@ -380,6 +378,8 @@ function resetExecWorktreeForTask(args) {
380
378
  executionPath: args.executionPath,
381
379
  },
382
380
  worktreeTaskId,
381
+ // PJR-98G4: repos を宣言した project では、プロダクト側の worktree と exec branch も破棄する。
382
+ products: configuredProductRepos(args.schedulePath),
383
383
  });
384
384
  process.stdout.write(discarded
385
385
  ? `reset worktree: discarded ${discarded}\n`
@@ -469,6 +469,7 @@ async function runReleaseAllBlocked(opts) {
469
469
  }
470
470
  export function registerExecCommands(program) {
471
471
  const exec = program.command("exec").description("Execution helpers");
472
+ registerExecHandoffCommands(exec);
472
473
  const lockedActions = {
473
474
  claim: {
474
475
  type: "claim",
@@ -869,6 +870,7 @@ export function registerExecCommands(program) {
869
870
  registerRunCommand(exec);
870
871
  registerResumeCommand(exec);
871
872
  registerCycleCommand(exec);
873
+ registerSlotsCommand(exec);
872
874
  registerExecWorktreeCommands(exec);
873
875
  registerExecTrialCommands(exec);
874
876
  // exec scaffold: creates project setup files (viewpoints etc.) or provider templates
@@ -879,14 +881,19 @@ export function registerExecCommands(program) {
879
881
  scaffoldCmd.option("--force", "Overwrite existing files", false);
880
882
  scaffoldCmd.option("--provider <name>", "Copy the provider's agent/settings templates (templates/<name>) into the repository");
881
883
  scaffoldCmd.option("--dry-run", "Show planned files without writing", false);
884
+ scaffoldCmd.option("--global", "Merge provider permissions into user-level settings (currently antigravity only)", false);
882
885
  scaffoldCmd.action(async (opts) => {
883
886
  try {
887
+ if (opts.global && !opts.provider) {
888
+ throw new Error("--global requires --provider <name>");
889
+ }
884
890
  if (opts.provider) {
885
891
  await runProviderScaffold(String(opts.provider), {
886
892
  packageRoot: specdojoPackageRootDir(),
887
893
  repoRoot: specdojoRootDir(),
888
894
  force: !!opts.force,
889
895
  dryRun: !!opts.dryRun,
896
+ global: !!opts.global,
890
897
  });
891
898
  return;
892
899
  }
@@ -73,6 +73,11 @@ export function parseGradeResult(content, path) {
73
73
  !Array.isArray(result.findings)) {
74
74
  throw new Error(`${path}: invalid grade result`);
75
75
  }
76
+ if (result.source_hashes !== undefined &&
77
+ (!isRecord(result.source_hashes) ||
78
+ Object.values(result.source_hashes).some((hash) => typeof hash !== "string" || !/^[a-f0-9]{64}$/.test(hash)))) {
79
+ throw new Error(`${path}: source_hashes must map sources to SHA-256 hex digests`);
80
+ }
76
81
  return result;
77
82
  }
78
83
  export function readGradeResult(path) {
@@ -106,6 +111,129 @@ export function writeGradeResult(path, result, dryRun = false) {
106
111
  export function gradeFindingCount(result) {
107
112
  return SEVERITIES.reduce((sum, severity) => sum + result.finding_counts[severity], 0);
108
113
  }
114
+ export function gradeFindingDisplayMessage(finding) {
115
+ return finding.message_ja?.trim() || finding.message;
116
+ }
117
+ function isJapaneseFindingMessage(message) {
118
+ // 英語の finding は対象文書の日本語を inline code で引用できるため、その引用は
119
+ // 言語判定から外す。引用以外に仮名がある文、または漢字だけの短文を日本語と扱う。
120
+ const prose = message.replace(/`[^`]*`/gu, "");
121
+ if (/[\p{Script=Hiragana}\p{Script=Katakana}]/u.test(prose))
122
+ return true;
123
+ return /\p{Script=Han}/u.test(prose) && !/[A-Za-z]/u.test(prose);
124
+ }
125
+ function translatableGradeFindings(result) {
126
+ return result.findings
127
+ .map((finding, findingIndex) => ({ finding, findingIndex }))
128
+ .filter(({ finding }) => !isJapaneseFindingMessage(finding.message));
129
+ }
130
+ function selectTranslationTargets(result, translationIndex) {
131
+ const targets = translatableGradeFindings(result).map((target, index) => ({
132
+ ...target,
133
+ translationIndex: index,
134
+ }));
135
+ if (translationIndex === undefined)
136
+ return targets;
137
+ const selected = targets[translationIndex];
138
+ if (!selected) {
139
+ throw new Error(`translation index out of range: index=${translationIndex}, count=${targets.length}`);
140
+ }
141
+ return [selected];
142
+ }
143
+ export function gradeFindingTranslationInput(result, translationIndex) {
144
+ return selectTranslationTargets(result, translationIndex).map(({ finding }) => finding.message);
145
+ }
146
+ export function applyGradeFindingTranslations(result, translations, translationIndex) {
147
+ const targets = selectTranslationTargets(result, translationIndex);
148
+ const targetFindingIndexes = new Set(targets.map(({ findingIndex }) => findingIndex));
149
+ const localizedFindings = result.findings.map((finding, findingIndex) => {
150
+ if (translationIndex === undefined || targetFindingIndexes.has(findingIndex)) {
151
+ return { ...finding, message_ja: finding.message };
152
+ }
153
+ return { ...finding };
154
+ });
155
+ const fallback = () => ({ ...result, findings: localizedFindings });
156
+ const rejectAll = (reason, detail) => targets.map(({ finding, translationIndex: index }) => ({
157
+ translation_index: index,
158
+ finding_id: finding.id,
159
+ reason,
160
+ ...(detail ? { detail } : {}),
161
+ }));
162
+ if (!Array.isArray(translations)) {
163
+ return {
164
+ result: fallback(),
165
+ accepted: false,
166
+ reason: "translation output must be a string array",
167
+ rejections: rejectAll("invalid-output", "translation output must be a string array"),
168
+ };
169
+ }
170
+ if (translations.length !== targets.length) {
171
+ const reason = `translation count mismatch: expected=${targets.length}, actual=${translations.length}`;
172
+ return {
173
+ result: fallback(),
174
+ accepted: false,
175
+ reason,
176
+ rejections: rejectAll("count-mismatch", reason),
177
+ };
178
+ }
179
+ const rejections = [];
180
+ for (const [arrayIndex, value] of translations.entries()) {
181
+ const target = targets[arrayIndex];
182
+ let reason;
183
+ let detail;
184
+ if (typeof value !== "string") {
185
+ reason = "not-string";
186
+ }
187
+ else if (!value.trim()) {
188
+ reason = "empty";
189
+ }
190
+ else if (!/[\p{Script=Hiragana}\p{Script=Katakana}]/u.test(value)) {
191
+ reason = "missing-kana";
192
+ }
193
+ else {
194
+ const sourceInlineCode = target.finding.message.match(/`[^`\r\n]*`/gu) ?? [];
195
+ const translatedInlineCode = value.match(/`[^`\r\n]*`/gu) ?? [];
196
+ const unmatchedTranslatedInlineCode = [...translatedInlineCode];
197
+ const missingInlineCode = sourceInlineCode.find((code) => {
198
+ const matchedIndex = unmatchedTranslatedInlineCode.indexOf(code);
199
+ if (matchedIndex === -1)
200
+ return true;
201
+ unmatchedTranslatedInlineCode.splice(matchedIndex, 1);
202
+ return false;
203
+ });
204
+ if (missingInlineCode) {
205
+ reason = "missing-inline-code";
206
+ detail = missingInlineCode;
207
+ }
208
+ else if (unmatchedTranslatedInlineCode.length > 0) {
209
+ reason = "extra-inline-code";
210
+ detail = unmatchedTranslatedInlineCode[0];
211
+ }
212
+ }
213
+ if (reason) {
214
+ rejections.push({
215
+ translation_index: target.translationIndex,
216
+ finding_id: target.finding.id,
217
+ reason,
218
+ ...(detail ? { detail } : {}),
219
+ });
220
+ }
221
+ else {
222
+ localizedFindings[target.findingIndex] = {
223
+ ...localizedFindings[target.findingIndex],
224
+ message_ja: value.trim(),
225
+ };
226
+ }
227
+ }
228
+ return {
229
+ accepted: rejections.length === 0,
230
+ ...(rejections.length > 0
231
+ ? { reason: `rejected ${rejections.length} of ${targets.length} translations` }
232
+ : {}),
233
+ rejections,
234
+ result: { ...result, findings: localizedFindings },
235
+ };
236
+ }
109
237
  export function validateGradeResult(result, documentContent, documentPath, expectedTarget) {
110
238
  const errors = [];
111
239
  let documentId;