specdojo 0.3.1 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +47 -0
- package/README.md +77 -18
- package/dist/{catalog-build-references.js → catalog/build-references.js} +4 -4
- package/dist/catalog/build-render.js +32 -0
- package/dist/{catalog-build.js → catalog/build.js} +9 -9
- package/dist/{catalog.js → catalog/catalog.js} +10 -10
- package/dist/{catalog-generate.js → catalog/generate.js} +8 -8
- package/dist/catalog/paths.js +1 -0
- package/dist/{catalog-plan-generate.js → catalog/plan-generate.js} +4 -4
- package/dist/{catalog-plan.js → catalog/plan.js} +4 -4
- package/dist/{catalog-scaffold.js → catalog/scaffold.js} +3 -3
- package/dist/{agent.js → commands/agent.js} +11 -11
- package/dist/{build-command.js → commands/build.js} +2 -2
- package/dist/{init-command.js → commands/init.js} +98 -32
- package/dist/{orchestrator.js → commands/orchestrator.js} +2 -2
- package/dist/{watch.js → commands/watch.js} +3 -3
- package/dist/{dashboard-timeline.js → dashboard/dashboard-timeline.js} +2 -2
- package/dist/{dashboard.js → dashboard/dashboard.js} +11 -10
- package/dist/{dashboard-exec-records.js → dashboard/exec-records.js} +2 -2
- package/dist/{dashboard-routines.js → dashboard/routines.js} +6 -5
- package/dist/{dashboard-shared.js → dashboard/shared.js} +1 -1
- package/dist/{timeline-build.js → dashboard/timeline-build.js} +2 -1
- package/dist/{timeline.js → dashboard/timeline.js} +1 -1
- package/dist/{deliverable.js → deliverable/deliverable.js} +5 -5
- package/dist/{deliverable-trash.js → deliverable/trash.js} +5 -5
- package/dist/{devcontainer-command.js → devcontainer/command.js} +5 -3
- package/dist/{devcontainer-scaffold.js → devcontainer/scaffold.js} +94 -2
- package/dist/{doc-index.js → docs/doc-index.js} +1 -1
- package/dist/{frontmatter-namespace.js → docs/frontmatter-namespace.js} +1 -1
- package/dist/{index-command.js → docs/index-command.js} +1 -1
- package/dist/docs/template-resolution.js +1 -0
- package/dist/{viewpoint-document-kinds-check.js → docs/viewpoint-document-kinds-check.js} +1 -1
- package/dist/{yaml-pages-command.js → docs/yaml-pages-command.js} +1 -1
- package/dist/{yaml-pages.js → docs/yaml-pages.js} +2 -2
- package/dist/{exec-agent-config.js → exec/agent-config.js} +33 -4
- package/dist/{exec-agent-git-state.js → exec/agent-git-state.js} +1 -1
- package/dist/{exec-agent-protected-config.js → exec/agent-protected-config.js} +1 -1
- package/dist/{exec-commands.js → exec/commands.js} +22 -18
- package/dist/{exec-core.js → exec/core.js} +11 -11
- package/dist/{exec-events.js → exec/events.js} +2 -2
- package/dist/{exec-evidence.js → exec/evidence.js} +11 -6
- package/dist/exec/exec.js +2 -0
- package/dist/exec/format.js +1 -0
- package/dist/{exec-handoff.js → exec/handoff.js} +13 -12
- package/dist/{exec-limit.js → exec/limit.js} +93 -12
- package/dist/{exec-parent-validation.js → exec/parent-validation.js} +4 -4
- package/dist/{exec-pipeline-state.js → exec/pipeline-state.js} +16 -2
- package/dist/{exec-plans-core.js → exec/plans-core.js} +68 -114
- package/dist/{exec-plans-generation.js → exec/plans-generation.js} +53 -10
- package/dist/{exec-plans-storage.js → exec/plans-storage.js} +5 -5
- package/dist/{exec-plans.js → exec/plans.js} +3 -3
- package/dist/{exec-project.js → exec/project.js} +1 -1
- package/dist/{exec-protection-handoff.js → exec/protection-handoff.js} +3 -3
- package/dist/{exec-register-resume.js → exec/register-resume.js} +2 -2
- package/dist/{exec-register.js → exec/register.js} +92 -9
- package/dist/{exec-repo-integration-git.js → exec/repo-integration-git.js} +2 -2
- package/dist/{exec-repo-integration-sync.js → exec/repo-integration-sync.js} +4 -4
- package/dist/{exec-repo-integration.js → exec/repo-integration.js} +13 -10
- package/dist/{exec-repo-trace.js → exec/repo-trace.js} +3 -3
- package/dist/{exec-reporter-output.js → exec/reporter-output.js} +2 -2
- package/dist/{exec-reporter.js → exec/reporter.js} +29 -12
- package/dist/{exec-results.js → exec/results.js} +256 -22
- package/dist/{exec-run-agent-pipeline.js → exec/run/agent-pipeline.js} +32 -12
- package/dist/{exec-run-agent.js → exec/run/agent.js} +79 -27
- package/dist/{exec-run-in-place.js → exec/run/in-place.js} +56 -27
- package/dist/{exec-run-job.js → exec/run/job.js} +64 -35
- package/dist/{exec-run-lifecycle-commands.js → exec/run/lifecycle-commands.js} +30 -22
- package/dist/{exec-run-lock.js → exec/run/lock.js} +4 -3
- package/dist/{exec-run-mode-shared.js → exec/run/mode-shared.js} +3 -3
- package/dist/{exec-run-register-command.js → exec/run/register-command.js} +18 -10
- package/dist/{exec-run-register-core.js → exec/run/register-core.js} +46 -21
- package/dist/{exec-run-register-mode.js → exec/run/register-mode.js} +20 -16
- package/dist/{exec-run-register-resume.js → exec/run/register-resume.js} +22 -17
- package/dist/{exec-run-register-state.js → exec/run/register-state.js} +13 -10
- package/dist/{exec-run-register-worktree.js → exec/run/register-worktree.js} +54 -23
- package/dist/{exec-run.js → exec/run/run.js} +11 -11
- package/dist/{exec-run-schedule-mode.js → exec/run/schedule-mode.js} +17 -17
- package/dist/{exec-run-schedule-prepare.js → exec/run/schedule-prepare.js} +31 -18
- package/dist/{exec-run-schedule-task.js → exec/run/schedule-task.js} +45 -18
- package/dist/{exec-run-shared.js → exec/run/shared.js} +61 -11
- package/dist/{exec-schedule-calendar.js → exec/schedule/calendar.js} +1 -1
- package/dist/{exec-schedule-cpm.js → exec/schedule/cpm.js} +2 -2
- package/dist/{exec-schedule-gantt-chart-render.js → exec/schedule/gantt-chart-render.js} +2 -2
- package/dist/exec/schedule/gantt-chart.js +2 -0
- package/dist/{exec-schedule-hash.js → exec/schedule/hash.js} +2 -2
- package/dist/exec/schedule/index.js +1 -0
- package/dist/{exec-schedule-initial.js → exec/schedule/initial.js} +2 -2
- package/dist/{exec-schedule-progress.js → exec/schedule/progress.js} +2 -2
- package/dist/{exec-schedule-ready.js → exec/schedule/ready.js} +2 -2
- package/dist/{exec-schedule.js → exec/schedule/schedule.js} +11 -11
- package/dist/exec/shared.js +63 -0
- package/dist/exec/slot-lock.js +1 -0
- package/dist/{exec-strategy.js → exec/strategy.js} +2 -2
- package/dist/{exec-task-repos.js → exec/task-repos.js} +2 -2
- package/dist/{exec-task-view.js → exec/task-view.js} +4 -4
- package/dist/{exec-trial-commands.js → exec/trial-commands.js} +20 -22
- package/dist/{exec-trial-core.js → exec/trial-core.js} +6 -6
- package/dist/{exec-trial.js → exec/trial.js} +2 -2
- package/dist/{exec-worktree-command.js → exec/worktree-command.js} +25 -23
- package/dist/{exec-worktree-ops-commit.js → exec/worktree-ops-commit.js} +25 -60
- package/dist/{exec-worktree-ops-lifecycle.js → exec/worktree-ops-lifecycle.js} +13 -8
- package/dist/{exec-worktree-ops-merge.js → exec/worktree-ops-merge.js} +48 -7
- package/dist/{exec-worktree-ops.js → exec/worktree-ops.js} +3 -3
- package/dist/exec/worktree.js +305 -0
- package/dist/{grade-apply.js → grade/apply.js} +9 -9
- package/dist/{grade-command-apply.js → grade/command-apply.js} +7 -7
- package/dist/{grade-command-inspect.js → grade/command-inspect.js} +6 -6
- package/dist/{grade-command-plan.js → grade/command-plan.js} +5 -5
- package/dist/{grade-core.js → grade/core.js} +3 -3
- package/dist/grade/grade.js +19 -0
- package/dist/{grade-markdown.js → grade/markdown.js} +6 -6
- package/dist/{grade-pipeline-state.js → grade/pipeline-state.js} +4 -4
- package/dist/{grade-plan.js → grade/plan.js} +5 -5
- package/dist/{grade-result.js → grade/result.js} +5 -94
- package/dist/{grade-target-discovery.js → grade/target-discovery.js} +7 -7
- package/dist/{grade-targets.js → grade/targets.js} +11 -8
- package/dist/{job-definition.js → job/definition.js} +25 -6
- package/dist/{job.js → job/job.js} +12 -11
- package/dist/{kata-command.js → kata/command.js} +3 -3
- package/dist/{kata.js → kata/kata.js} +5 -5
- package/dist/register/approach.js +134 -0
- package/dist/{register-core.js → register/core.js} +13 -7
- package/dist/{register-create-commands.js → register/create-commands.js} +115 -8
- package/dist/{register-date.js → register/date.js} +1 -1
- package/dist/register/derivation.js +163 -0
- package/dist/{register-event-merge.js → register/event-merge.js} +32 -3
- package/dist/{register-events.js → register/events.js} +9 -3
- package/dist/{register-history.js → register/history.js} +7 -6
- package/dist/{register-item.js → register/item.js} +23 -5
- package/dist/register/lifecycle-lock.js +5 -0
- package/dist/{register-maintenance-commands.js → register/maintenance-commands.js} +13 -7
- package/dist/{register-migrate-timestamps.js → register/migrate-timestamps.js} +3 -3
- package/dist/{register-migration.js → register/migration.js} +4 -4
- package/dist/{register.js → register/register.js} +32 -27
- package/dist/{register-renumber.js → register/renumber.js} +38 -11
- package/dist/{register-transition-commands.js → register/transition-commands.js} +3 -3
- package/dist/{register-update.js → register/update.js} +5 -5
- package/dist/{register-views.js → register/views.js} +47 -7
- package/dist/{review-grade.js → review/grade.js} +2 -2
- package/dist/{review-plan.js → review/plan.js} +3 -3
- package/dist/{routine-definition.js → routine/definition.js} +2 -2
- package/dist/{routine.js → routine/routine.js} +49 -22
- package/dist/{schedule-approach.js → schedule/approach.js} +8 -8
- package/dist/{schedule-build.js → schedule/build.js} +7 -4
- package/dist/{schedule.js → schedule/schedule.js} +6 -6
- package/dist/{schedule-strategy-generate-document.js → schedule/strategy-generate-document.js} +2 -2
- package/dist/{schedule-strategy-generate-scope.js → schedule/strategy-generate-scope.js} +4 -4
- package/dist/{schedule-strategy-generate.js → schedule/strategy-generate.js} +10 -10
- package/dist/shared/agent-types.js +23 -0
- package/dist/shared/artifact-path.js +9 -0
- package/dist/{build-if-stale.js → shared/build-if-stale.js} +1 -1
- package/dist/{catalog-build-render.js → shared/catalog-render.js} +3 -32
- package/dist/{exec-slot-lock.js → shared/cross-process-lock.js} +3 -1
- package/dist/shared/fs.js +30 -0
- package/dist/{exec-worktree.js → shared/git.js} +83 -241
- package/dist/shared/grade-result.js +94 -0
- package/dist/{package-paths.js → shared/package-paths.js} +3 -3
- package/dist/shared/plan-templates.js +114 -0
- package/dist/{exec-provider-scaffold.js → shared/provider-scaffold.js} +3 -1
- package/dist/shared/random.js +4 -0
- package/dist/{exec-schedule-index.js → shared/schedule-index.js} +3 -1
- package/dist/shared/schedule-paths.js +9 -0
- package/dist/{specdojo-config.js → shared/specdojo-config.js} +93 -5
- package/dist/{exec-shared.js → shared/text.js} +0 -134
- package/dist/shared/time.js +28 -0
- package/dist/specdojo.js +22 -22
- package/docs/ja/specdojo/exec-templates/xep-common-conventions-template.md +29 -17
- package/docs/ja/specdojo/exec-templates/xep-register-investigate-template.md +1 -2
- package/docs/ja/specdojo/exec-templates/xep-register-template.md +1 -2
- package/docs/ja/specdojo/exec-templates/xer-template.md +1 -3
- package/docs/ja/specdojo/exec-templates/xrp-job-template.md +6 -4
- package/docs/ja/specdojo/guides/exec-config-guide.md +91 -16
- package/docs/ja/specdojo/guides/exec-operation-guide.md +145 -12
- package/docs/ja/specdojo/guides/exec-worktree-guide.md +2 -0
- package/docs/ja/specdojo/guides/orchestrator-operation-guide.md +31 -0
- package/docs/ja/specdojo/guides/quick-start-guide.md +81 -16
- package/docs/ja/specdojo/guides/register-operation-guide.md +2 -1
- package/docs/ja/specdojo/guides/remote-host-development-guide.md +10 -1
- package/docs/ja/specdojo/guides/review-guide.md +1 -1
- package/docs/ja/specdojo/guides/routine-operation-guide.md +5 -5
- package/docs/ja/specdojo/guides/use-case-guide.md +1 -1
- package/docs/ja/specdojo/references/command-reference.md +52 -28
- package/docs/ja/specdojo/rulebooks/pjr-rulebook.md +17 -11
- package/docs/ja/specdojo/standards/job-definition-standard.md +20 -18
- package/docs/ja/specdojo/standards/rulebook-authoring-standard.md +2 -2
- package/docs/ja/specdojo/templates/pjr-derived-items-template.md +22 -0
- package/docs/ja/specdojo/templates/pjr-index-template.md +1 -0
- package/docs/specdojo/schemas/v1/agent-members.schema.yaml +29 -2
- package/docs/specdojo/schemas/v1/exec-defaults.schema.yaml +20 -0
- package/docs/specdojo/schemas/v1/exec-evidence.schema.yaml +23 -0
- package/docs/specdojo/schemas/v1/job-run.schema.yaml +2 -2
- package/docs/specdojo/schemas/v1/job.schema.yaml +7 -0
- package/docs/specdojo/schemas/v1/pipeline-state.schema.yaml +26 -0
- package/docs/specdojo/schemas/v1/register-events.schema.yaml +3 -0
- package/docs/specdojo/schemas/v1/register-item-frontmatter.schema.yaml +70 -7
- package/docs/specdojo/schemas/v1/routine-run.schema.yaml +1 -1
- package/docs/specdojo/schemas/v1/specdojo-config.schema.yaml +1 -1
- package/package.json +1 -1
- package/templates/antigravity/README.md +5 -1
- package/templates/antigravity/agent-members-snippet.yaml +108 -12
- package/templates/antigravity/exec-defaults-snippet.yaml +8 -13
- package/templates/claude/README.md +27 -3
- package/templates/claude/agents/claude-executor.md +0 -1
- package/templates/claude/agents/claude-reporter.md +2 -1
- package/templates/claude/agents/claude-review-executor.md +0 -1
- package/templates/codex/README.md +23 -4
- package/templates/devcontainer/devcontainer.json +2 -2
- package/templates/devcontainer/remote-host/specdojo-tmux.sh.sample +69 -0
- package/templates/devcontainer/remote-host/ssh-config.sample +16 -0
- package/templates/init-agent-members.yaml +75 -25
- package/templates/init-exec-defaults.yaml +24 -8
- package/templates/opencode/README.md +17 -3
- package/templates/opencode/agents/opencode-executor.md +0 -1
- package/templates/opencode/agents/opencode-reporter.md +2 -1
- package/templates/opencode/agents/opencode-review-executor.md +0 -1
- package/dist/exec-schedule-gantt-chart.js +0 -2
- package/dist/exec.js +0 -2
- package/dist/grade.js +0 -19
- package/templates/claude/agents/claude-expert-review-executor.md +0 -14
- /package/dist/{catalog-plan-prompt.js → catalog/plan-prompt.js} +0 -0
- /package/dist/{catalog-types.js → catalog/types.js} +0 -0
- /package/dist/{template-frontmatter.js → docs/template-frontmatter.js} +0 -0
- /package/dist/{role-types.js → exec/role-types.js} +0 -0
- /package/dist/{exec-schedule-gantt-chart-scope.js → exec/schedule/gantt-chart-scope.js} +0 -0
- /package/dist/{exec-types.js → exec/types.js} +0 -0
- /package/dist/{grade-command-shared.js → grade/command-shared.js} +0 -0
- /package/dist/{register-command-types.js → register/command-types.js} +0 -0
- /package/dist/{review-types.js → review/types.js} +0 -0
- /package/dist/{schedule-phase-sets.js → schedule/phase-sets.js} +0 -0
- /package/dist/{schedule-strategy-profiles.js → schedule/strategy-profiles.js} +0 -0
- /package/dist/{agent-response.js → shared/agent-response.js} +0 -0
- /package/dist/{catalog-paths.js → shared/catalog-paths.js} +0 -0
- /package/dist/{dist-freshness.js → shared/dist-freshness.js} +0 -0
- /package/dist/{git-environment.js → shared/git-environment.js} +0 -0
- /package/dist/{exec-format.js → shared/markdown-format.js} +0 -0
- /package/dist/{practice-id.js → shared/practice-id.js} +0 -0
- /package/dist/{spawn-self.js → shared/spawn-self.js} +0 -0
- /package/dist/{specdojo-gitignore.js → shared/specdojo-gitignore.js} +0 -0
- /package/dist/{template-resolution.js → shared/template-resolution.js} +0 -0
- /package/dist/{yaml-schema-modeline.js → shared/yaml-schema-modeline.js} +0 -0
- /package/dist/{yaml.js → shared/yaml.js} +0 -0
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { spawnSync } from "node:child_process";
|
|
2
|
-
import { appendFileSync,
|
|
3
|
-
import { dirname,
|
|
4
|
-
import { redactSensitiveText, stripTerminalControlSequences } from "./exec-shared.js";
|
|
2
|
+
import { appendFileSync, lstatSync, mkdirSync } from "node:fs";
|
|
3
|
+
import { dirname, join, relative, resolve, sep } from "node:path";
|
|
5
4
|
import { gitEnvironment } from "./git-environment.js";
|
|
5
|
+
import { redactSensitiveText, stripTerminalControlSequences } from "./text.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
|
|
8
8
|
// cannot acquire it. Under `exec run --parallel`, the parent's root-index operations and the
|
|
@@ -45,26 +45,33 @@ export function transientGitFailureReason(stderr, repoRoot) {
|
|
|
45
45
|
}
|
|
46
46
|
return undefined;
|
|
47
47
|
}
|
|
48
|
-
export function runGitWithTransientRetry(run, onTransientFailureRetry = () => undefined, sleep = sleepSync, repoRoot) {
|
|
48
|
+
export function runGitWithTransientRetry(run, onTransientFailureRetry = () => undefined, sleep = sleepSync, repoRoot, recoverFromTransientFailure) {
|
|
49
49
|
let indexLockRetries = 0;
|
|
50
50
|
let transientFailureRetries = 0;
|
|
51
51
|
let result = run();
|
|
52
52
|
while (result.status !== 0) {
|
|
53
53
|
const stderr = typeof result.stderr === "string" ? result.stderr : "";
|
|
54
54
|
const transientFailure = transientGitFailureReason(stderr, repoRoot);
|
|
55
|
-
if (
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
55
|
+
if (transientFailure !== undefined) {
|
|
56
|
+
// Some multi-step Git commands can finish their mutation before a later ownership check
|
|
57
|
+
// reports a transient failure. Give those commands a chance to verify/reconcile their
|
|
58
|
+
// postcondition before blindly repeating a non-idempotent operation.
|
|
59
|
+
if (recoverFromTransientFailure?.(transientFailure)) {
|
|
60
|
+
return { ...result, status: 0, stderr: "" };
|
|
61
|
+
}
|
|
62
|
+
if (transientFailureRetries < TRANSIENT_GIT_RETRY_DELAYS_MS.length) {
|
|
63
|
+
const waitMilliseconds = TRANSIENT_GIT_RETRY_DELAYS_MS[transientFailureRetries];
|
|
64
|
+
transientFailureRetries += 1;
|
|
65
|
+
onTransientFailureRetry({
|
|
66
|
+
attempt: transientFailureRetries,
|
|
67
|
+
maxAttempts: TRANSIENT_GIT_RETRY_DELAYS_MS.length,
|
|
68
|
+
waitMilliseconds,
|
|
69
|
+
reason: transientFailure,
|
|
70
|
+
});
|
|
71
|
+
sleep(waitMilliseconds);
|
|
72
|
+
result = run();
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
68
75
|
}
|
|
69
76
|
if (indexLockRetries < INDEX_LOCK_RETRY_ATTEMPTS && isGitIndexLockContention(stderr)) {
|
|
70
77
|
indexLockRetries += 1;
|
|
@@ -79,7 +86,7 @@ export function runGitWithTransientRetry(run, onTransientFailureRetry = () => un
|
|
|
79
86
|
// spawnSync の既定の maxBuffer(1 MiB)では、未追跡のファイルが多い作業場所の
|
|
80
87
|
// `git status --porcelain` などが打ち切られ、子プロセスが SIGTERM で止められる。
|
|
81
88
|
export const GIT_OUTPUT_MAX_BUFFER = 256 * 1024 * 1024;
|
|
82
|
-
export function gitResult(repoRoot, args) {
|
|
89
|
+
export function gitResult(repoRoot, args, recoverFromTransientFailure) {
|
|
83
90
|
const cwd = resolve(repoRoot);
|
|
84
91
|
const run = () => spawnSync("git", ["-C", cwd, ...args], {
|
|
85
92
|
// `-C` だけに依存せず、子プロセス自体も対象 repository から起動する。linked worktree の
|
|
@@ -94,7 +101,7 @@ export function gitResult(repoRoot, args) {
|
|
|
94
101
|
const summary = summarizeGitArguments(args);
|
|
95
102
|
process.stderr.write(`warning: git command failed with ${reason}; retrying in ${waitMilliseconds / 1000}s` +
|
|
96
103
|
` (attempt ${attempt}/${maxAttempts}, cwd: ${repoRoot}${summary ? `, args: ${summary}` : ""})\n`);
|
|
97
|
-
}, sleepSync, cwd);
|
|
104
|
+
}, sleepSync, cwd, recoverFromTransientFailure);
|
|
98
105
|
}
|
|
99
106
|
// git 失敗メッセージは register イベントの reason、result の block_reason、実行ログの一覧行の
|
|
100
107
|
// いずれでも長さ上限で切り詰められて記録される。commit のように pathspec が全件並ぶコマンドでは、
|
|
@@ -173,6 +180,15 @@ export function formatGitCommandFailure(args, stderr, processFailure = "") {
|
|
|
173
180
|
.join(" / ");
|
|
174
181
|
return cause ? `${label} failed: ${cause}${detail}` : `${label} failed${detail}`;
|
|
175
182
|
}
|
|
183
|
+
// gitResult を直接扱う呼び出し元でも、gitOutput と同じ stderr 要約に加えて終了コードを
|
|
184
|
+
// 必ず残す。status が null の起動失敗・signal 終了では describeGitProcessFailure が原因を補う。
|
|
185
|
+
export function formatGitResultFailure(args, result) {
|
|
186
|
+
const stderr = typeof result.stderr === "string" ? result.stderr : "";
|
|
187
|
+
const processFailure = [`exit ${result.status ?? "unknown"}`, describeGitProcessFailure(result)]
|
|
188
|
+
.filter(Boolean)
|
|
189
|
+
.join("; ");
|
|
190
|
+
return formatGitCommandFailure(args, stderr, processFailure);
|
|
191
|
+
}
|
|
176
192
|
// lefthook などの hook 出力から、block reason に載せる失敗ステップ名と最初のエラー行を
|
|
177
193
|
// 取り出し、Vitest の失敗テスト名・集計があれば末尾から補う。罫線や ANSI 制御は監査ログには
|
|
178
194
|
// 残す一方、短い理由には混ぜない。
|
|
@@ -227,6 +243,20 @@ export function appendGitFailureLog(path, lines) {
|
|
|
227
243
|
mkdirSync(dirname(path), { recursive: true });
|
|
228
244
|
appendFileSync(path, redactSensitiveText(`${lines.join("\n")}\n`), "utf8");
|
|
229
245
|
}
|
|
246
|
+
/** Appends a complete gitResult failure record while keeping the caller's operation label. */
|
|
247
|
+
export function appendGitResultFailureLog(path, label, result) {
|
|
248
|
+
appendGitFailureLog(path, [
|
|
249
|
+
`=== ${new Date().toISOString()} ${label} ===`,
|
|
250
|
+
`exit: ${result.status ?? "unknown"}`,
|
|
251
|
+
`signal: ${result.signal ?? "none"}`,
|
|
252
|
+
`error: ${result.error?.message ?? "none"}`,
|
|
253
|
+
"--- stdout ---",
|
|
254
|
+
typeof result.stdout === "string" ? result.stdout : "",
|
|
255
|
+
"--- stderr ---",
|
|
256
|
+
typeof result.stderr === "string" ? result.stderr : "",
|
|
257
|
+
"",
|
|
258
|
+
]);
|
|
259
|
+
}
|
|
230
260
|
// message は block reason 向けに要約する一方、調査に必要な stderr 全文は失わない。
|
|
231
261
|
export class GitCommandError extends Error {
|
|
232
262
|
args;
|
|
@@ -238,237 +268,49 @@ export class GitCommandError extends Error {
|
|
|
238
268
|
this.name = "GitCommandError";
|
|
239
269
|
}
|
|
240
270
|
}
|
|
241
|
-
export function gitOutput(repoRoot, args) {
|
|
242
|
-
const result = gitResult(repoRoot, args);
|
|
271
|
+
export function gitOutput(repoRoot, args, recoverFromTransientFailure) {
|
|
272
|
+
const result = gitResult(repoRoot, args, recoverFromTransientFailure);
|
|
243
273
|
if (result.status !== 0 || result.error) {
|
|
244
274
|
const stderr = typeof result.stderr === "string" ? result.stderr : "";
|
|
245
275
|
throw new GitCommandError(formatGitCommandFailure(args, stderr, describeGitProcessFailure(result)), args, stderr);
|
|
246
276
|
}
|
|
247
277
|
return typeof result.stdout === "string" ? result.stdout : "";
|
|
248
278
|
}
|
|
249
|
-
export function
|
|
250
|
-
const
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
.replace(/-+/g, "-")
|
|
254
|
-
.replace(/^-+|-+$/g, "");
|
|
255
|
-
if (!slug)
|
|
256
|
-
throw new Error(`Task ID cannot be used as a worktree name: ${value}`);
|
|
257
|
-
return slug;
|
|
258
|
-
}
|
|
259
|
-
export function resolveWorktreeBase(repoRoot, override, configured) {
|
|
260
|
-
const value = override?.trim() || configured?.trim() || "../worktrees";
|
|
261
|
-
return isAbsolute(value) ? resolve(value) : resolve(repoRoot, value);
|
|
262
|
-
}
|
|
263
|
-
export function listRegisteredWorktrees(repoRoot) {
|
|
264
|
-
const output = gitOutput(repoRoot, ["worktree", "list", "--porcelain"]);
|
|
265
|
-
const result = [];
|
|
266
|
-
let currentPath;
|
|
267
|
-
let currentBranch;
|
|
268
|
-
function pushCurrent() {
|
|
269
|
-
if (currentPath)
|
|
270
|
-
result.push({ path: currentPath, branch: currentBranch });
|
|
271
|
-
currentPath = undefined;
|
|
272
|
-
currentBranch = undefined;
|
|
273
|
-
}
|
|
274
|
-
for (const line of output.split(/\r?\n/)) {
|
|
275
|
-
if (line.startsWith("worktree ")) {
|
|
276
|
-
pushCurrent();
|
|
277
|
-
currentPath = resolve(line.slice("worktree ".length));
|
|
278
|
-
}
|
|
279
|
-
else if (currentPath && line.startsWith("branch refs/heads/")) {
|
|
280
|
-
currentBranch = line.slice("branch refs/heads/".length);
|
|
281
|
-
}
|
|
282
|
-
else if (line === "") {
|
|
283
|
-
pushCurrent();
|
|
284
|
-
}
|
|
279
|
+
export function repoRelative(repoRoot, path) {
|
|
280
|
+
const value = relative(repoRoot, path);
|
|
281
|
+
if (!value || value === ".." || value.startsWith(`..${sep}`)) {
|
|
282
|
+
throw new Error(`Path is outside repository root: ${path}`);
|
|
285
283
|
}
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
const
|
|
291
|
-
const
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
return { path: registered.path, branch, name, created: false };
|
|
296
|
-
}
|
|
297
|
-
export function execBranchExists(repoRoot, taskId) {
|
|
298
|
-
const branch = `exec/${worktreeNameFromTaskId(taskId)}`;
|
|
299
|
-
return (gitResult(repoRoot, ["show-ref", "--verify", "--quiet", `refs/heads/${branch}`]).status === 0);
|
|
300
|
-
}
|
|
301
|
-
function pathEntryExists(target) {
|
|
302
|
-
try {
|
|
303
|
-
lstatSync(target);
|
|
304
|
-
return true;
|
|
305
|
-
}
|
|
306
|
-
catch {
|
|
307
|
-
return false;
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
function trackedPackageLockDirs(worktreePath) {
|
|
311
|
-
const output = gitOutput(worktreePath, [
|
|
312
|
-
"ls-files",
|
|
313
|
-
"-z",
|
|
314
|
-
"--",
|
|
315
|
-
"package-lock.json",
|
|
316
|
-
"*/package-lock.json",
|
|
317
|
-
]);
|
|
318
|
-
const dirs = new Set();
|
|
319
|
-
for (const entry of output.split("\0")) {
|
|
320
|
-
if (!entry)
|
|
284
|
+
return value.split(sep).join("/");
|
|
285
|
+
}
|
|
286
|
+
export function worktreeStatusPaths(repoRoot) {
|
|
287
|
+
const output = gitOutput(repoRoot, ["status", "--porcelain=v1", "-z", "--untracked-files=all"]);
|
|
288
|
+
const records = output.split("\0").filter(Boolean);
|
|
289
|
+
const paths = [];
|
|
290
|
+
for (let index = 0; index < records.length; index++) {
|
|
291
|
+
const record = records[index];
|
|
292
|
+
if (record.length < 4)
|
|
321
293
|
continue;
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
function runNpmCi(packageDir) {
|
|
327
|
-
const command = process.platform === "win32" ? "npm.cmd" : "npm";
|
|
328
|
-
const result = spawnSync(command, ["ci", "--include=dev"], {
|
|
329
|
-
cwd: packageDir,
|
|
330
|
-
env: { ...gitEnvironment(), CI: "true", LEFTHOOK: "0" },
|
|
331
|
-
stdio: "inherit",
|
|
332
|
-
});
|
|
333
|
-
if (result.error) {
|
|
334
|
-
throw new Error(`npm ci could not start in ${packageDir}: ${result.error.message}`);
|
|
335
|
-
}
|
|
336
|
-
if (result.status !== 0) {
|
|
337
|
-
throw new Error(`npm ci failed in ${packageDir} (exit ${result.status ?? "unknown"})`);
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
function removeLegacyNodeModulesLink(packageDir) {
|
|
341
|
-
const target = join(packageDir, "node_modules");
|
|
342
|
-
if (!pathEntryExists(target) || !lstatSync(target).isSymbolicLink())
|
|
343
|
-
return;
|
|
344
|
-
unlinkSync(target);
|
|
345
|
-
}
|
|
346
|
-
// Git worktree は独自の作業ツリーを持つだけで node_modules は引き継がないため、
|
|
347
|
-
// tracked package-lock.json ごとに npm ci を実行し、worktree 内へ独立して依存を配置する。
|
|
348
|
-
// 旧方式の共有 symlink は npm に辿らせず、先に link 自体だけを削除する。
|
|
349
|
-
// lock が無い worktree は導入しない。依存が無いまま検証が失敗したときに原因を追えるよう、
|
|
350
|
-
// 導入しなかったことをログに残す(PJR-86Q5)。
|
|
351
|
-
export function installWorktreeDependencies(worktreePath, npmCi = runNpmCi) {
|
|
352
|
-
const packageDirs = trackedPackageLockDirs(resolve(worktreePath));
|
|
353
|
-
if (packageDirs.length === 0) {
|
|
354
|
-
process.stdout.write(`Skipping worktree dependencies: no tracked package-lock.json in ${worktreePath}\n`);
|
|
355
|
-
return;
|
|
356
|
-
}
|
|
357
|
-
for (const packageDir of packageDirs) {
|
|
358
|
-
if (!existsSync(join(packageDir, "package.json"))) {
|
|
359
|
-
throw new Error(`package.json is missing next to package-lock.json: ${packageDir}`);
|
|
294
|
+
const status = record.slice(0, 2);
|
|
295
|
+
paths.push(record.slice(3));
|
|
296
|
+
if ((status.includes("R") || status.includes("C")) && records[index + 1]) {
|
|
297
|
+
paths.push(records[++index]);
|
|
360
298
|
}
|
|
361
|
-
removeLegacyNodeModulesLink(packageDir);
|
|
362
|
-
process.stdout.write(`Installing worktree dependencies: ${relative(worktreePath, packageDir) || "."}\n`);
|
|
363
|
-
npmCi(packageDir);
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
const SPECDOJO_CONFIG_REL = join(".specdojo", "specdojo.config.json");
|
|
367
|
-
// 生成物の失敗は成果物の失敗と混同されやすい。準備段階であることと、生成物が worktree ごとに
|
|
368
|
-
// 作り直しになる理由をメッセージ本体へ含める。
|
|
369
|
-
export function formatWorktreeBuildFailure(worktreePath, detail) {
|
|
370
|
-
return (`Worktree preparation failed: specdojo build ${detail} in ${worktreePath}. ` +
|
|
371
|
-
`Generated docs are gitignored and must be rebuilt per worktree, so this is a ` +
|
|
372
|
-
`preparation failure, not a task deliverable failure.`);
|
|
373
|
-
}
|
|
374
|
-
// build は worktree 内で完結させる。依存と同じく、worktree の checkout にある CLI を使うため、
|
|
375
|
-
// 実行元プロセスの entry(テストランナー等)へは依存しない。SpecDojo 自身のリポジトリでは
|
|
376
|
-
// src の entry を worktree の tsx で、CLI を依存として使うリポジトリでは
|
|
377
|
-
// node_modules/.bin/specdojo を使う。
|
|
378
|
-
export function resolveWorktreeBuildCommand(worktreePath) {
|
|
379
|
-
const root = resolve(worktreePath);
|
|
380
|
-
const sourceEntry = join(root, "src", "specdojo.ts");
|
|
381
|
-
const localTsx = join(root, "node_modules", ".bin", "tsx");
|
|
382
|
-
if (existsSync(sourceEntry) && existsSync(localTsx)) {
|
|
383
|
-
return { command: process.execPath, args: [localTsx, sourceEntry, "build"] };
|
|
384
299
|
}
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
300
|
+
return paths;
|
|
301
|
+
}
|
|
302
|
+
export function selectStageablePaths(repoRoot, paths) {
|
|
303
|
+
if (paths.length === 0)
|
|
304
|
+
return [];
|
|
305
|
+
const indexed = new Set(gitOutput(repoRoot, ["ls-files", "--full-name", "-z", "--", ...paths])
|
|
306
|
+
.split("\0")
|
|
307
|
+
.filter(Boolean));
|
|
308
|
+
const existsInWorktree = (path) => lstatSync(resolve(repoRoot, path), { throwIfNoEntry: false }) !== undefined;
|
|
309
|
+
return paths.filter((path) => indexed.has(path) || existsInWorktree(path));
|
|
310
|
+
}
|
|
311
|
+
export function stageCommitTargets(repoRoot, paths) {
|
|
312
|
+
const stageable = selectStageablePaths(repoRoot, paths);
|
|
313
|
+
if (stageable.length === 0)
|
|
399
314
|
return;
|
|
400
|
-
|
|
401
|
-
process.stdout.write("Generating worktree artifacts: specdojo build\n");
|
|
402
|
-
const result = spawnSync(resolved.command, resolved.args, {
|
|
403
|
-
cwd: worktreePath,
|
|
404
|
-
env: { ...gitEnvironment(), CI: "true", LEFTHOOK: "0" },
|
|
405
|
-
stdio: "inherit",
|
|
406
|
-
});
|
|
407
|
-
if (result.error) {
|
|
408
|
-
throw new Error(formatWorktreeBuildFailure(worktreePath, `could not start: ${result.error.message}`));
|
|
409
|
-
}
|
|
410
|
-
if (result.status !== 0) {
|
|
411
|
-
throw new Error(formatWorktreeBuildFailure(worktreePath, `exited with ${result.status ?? "unknown"}`));
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
// 生成物(docs/**/generated と .specdojo/doc-index.json)は .gitignore 済みで worktree へ
|
|
415
|
-
// 複製されない。生成物の存在を前提とする検証は、成果物と無関係に失敗するため、依存の install
|
|
416
|
-
// 直後にまとめて生成する。生成対象が増えても追従が要らないよう、scope を絞らず build を通しで
|
|
417
|
-
// 実行する(全 scope で数秒。npm ci に対して無視できる)。
|
|
418
|
-
export function generateWorktreeArtifacts(worktreePath, build = runWorktreeBuild) {
|
|
419
|
-
const root = resolve(worktreePath);
|
|
420
|
-
// SpecDojo の設定を持たないリポジトリには生成物が無い。build は失敗するだけなので実行しない。
|
|
421
|
-
if (!existsSync(join(root, SPECDOJO_CONFIG_REL)))
|
|
422
|
-
return;
|
|
423
|
-
build(root);
|
|
424
|
-
}
|
|
425
|
-
/**
|
|
426
|
-
* Path of a task worktree. Without `repoDirName` (projects without `repos`) the worktree is
|
|
427
|
-
* `<base>/<task-name>/`; with it, each repository gets `<base>/<task-name>/<repoDirName>/`.
|
|
428
|
-
*/
|
|
429
|
-
export function execWorktreePath(worktreeBase, taskId, repoDirName) {
|
|
430
|
-
const name = worktreeNameFromTaskId(taskId);
|
|
431
|
-
return resolve(repoDirName ? join(worktreeBase, name, repoDirName) : join(worktreeBase, name));
|
|
432
|
-
}
|
|
433
|
-
export function ensureExecWorktree(opts) {
|
|
434
|
-
const repoRoot = resolve(opts.repoRoot);
|
|
435
|
-
const baseRelative = relative(repoRoot, resolve(opts.worktreeBase));
|
|
436
|
-
if (baseRelative === "" || (!baseRelative.startsWith(`..${sep}`) && baseRelative !== "..")) {
|
|
437
|
-
throw new Error(`Worktree base must be outside the repository: ${opts.worktreeBase}`);
|
|
438
|
-
}
|
|
439
|
-
const name = worktreeNameFromTaskId(opts.taskId);
|
|
440
|
-
const branch = `exec/${name}`;
|
|
441
|
-
const worktreePath = execWorktreePath(opts.worktreeBase, opts.taskId, opts.repoDirName);
|
|
442
|
-
const registered = listRegisteredWorktrees(repoRoot);
|
|
443
|
-
const registeredAtPath = registered.find((item) => item.path === worktreePath);
|
|
444
|
-
if (registeredAtPath) {
|
|
445
|
-
if (!existsSync(worktreePath)) {
|
|
446
|
-
throw new Error(`Registered worktree path does not exist: ${worktreePath}`);
|
|
447
|
-
}
|
|
448
|
-
if (registeredAtPath.branch !== branch) {
|
|
449
|
-
throw new Error(`Worktree ${worktreePath} uses branch ${registeredAtPath.branch ?? "(detached)"}; expected ${branch}`);
|
|
450
|
-
}
|
|
451
|
-
(opts.installDependencies ?? installWorktreeDependencies)(worktreePath);
|
|
452
|
-
(opts.generateArtifacts ?? generateWorktreeArtifacts)(worktreePath);
|
|
453
|
-
return { path: worktreePath, branch, name, created: false };
|
|
454
|
-
}
|
|
455
|
-
if (existsSync(worktreePath)) {
|
|
456
|
-
throw new Error(`Worktree path already exists but is not registered: ${worktreePath}`);
|
|
457
|
-
}
|
|
458
|
-
mkdirSync(dirname(worktreePath), { recursive: true });
|
|
459
|
-
const branchExists = gitResult(repoRoot, ["show-ref", "--verify", "--quiet", `refs/heads/${branch}`]).status === 0;
|
|
460
|
-
const args = branchExists
|
|
461
|
-
? ["worktree", "add", worktreePath, branch]
|
|
462
|
-
: [
|
|
463
|
-
"worktree",
|
|
464
|
-
"add",
|
|
465
|
-
worktreePath,
|
|
466
|
-
"-b",
|
|
467
|
-
branch,
|
|
468
|
-
...(opts.startPoint ? [opts.startPoint] : []),
|
|
469
|
-
];
|
|
470
|
-
gitOutput(repoRoot, args);
|
|
471
|
-
(opts.installDependencies ?? installWorktreeDependencies)(worktreePath);
|
|
472
|
-
(opts.generateArtifacts ?? generateWorktreeArtifacts)(worktreePath);
|
|
473
|
-
return { path: worktreePath, branch, name, created: true };
|
|
315
|
+
gitOutput(repoRoot, ["add", "-A", "--", ...stageable]);
|
|
474
316
|
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
3
|
+
import { join, resolve } from "node:path";
|
|
4
|
+
import { load } from "./yaml.js";
|
|
5
|
+
import { getProjectExecutionPath, loadConfig, specdojoRootDir } from "./specdojo-config.js";
|
|
6
|
+
const DOCUMENT_ID_RE = /^[a-z0-9][a-z0-9-:]*$/;
|
|
7
|
+
export const SEVERITIES = ["blocker", "major", "minor", "note"];
|
|
8
|
+
function isRecord(value) {
|
|
9
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
10
|
+
}
|
|
11
|
+
export function gradeContentHash(content) {
|
|
12
|
+
return createHash("sha256").update(content).digest("hex");
|
|
13
|
+
}
|
|
14
|
+
export function markdownDocumentId(content, path) {
|
|
15
|
+
const match = content.match(/^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/);
|
|
16
|
+
if (!match)
|
|
17
|
+
throw new Error(`${path}: Markdown frontmatter is required`);
|
|
18
|
+
const parsed = load(match[1]);
|
|
19
|
+
const specdojo = isRecord(parsed) && isRecord(parsed.specdojo) ? parsed.specdojo : undefined;
|
|
20
|
+
const id = specdojo?.id;
|
|
21
|
+
if (typeof id !== "string" || !DOCUMENT_ID_RE.test(id)) {
|
|
22
|
+
throw new Error(`${path}: specdojo.id is required to store a grade result`);
|
|
23
|
+
}
|
|
24
|
+
return id;
|
|
25
|
+
}
|
|
26
|
+
export function resolveGradeResultsDirectory(projectOption, rootDir = specdojoRootDir()) {
|
|
27
|
+
const { config } = loadConfig();
|
|
28
|
+
if (!config)
|
|
29
|
+
throw new Error("grade commands require .specdojo/specdojo.config.json");
|
|
30
|
+
const projectId = projectOption?.trim() || config.current_project || Object.keys(config.projects)[0] || "";
|
|
31
|
+
const project = config.projects[projectId];
|
|
32
|
+
if (!project)
|
|
33
|
+
throw new Error(`Unknown project: ${projectId}`);
|
|
34
|
+
return resolve(rootDir, getProjectExecutionPath(project), "grade", "results");
|
|
35
|
+
}
|
|
36
|
+
// ファイル名では名前空間区切りの ":" を "." に置き換える(Windows で ":" は使えない)。
|
|
37
|
+
// DOCUMENT_ID_RE は "." を許さないため、置換後も元の id と一対一に対応する。
|
|
38
|
+
export function gradeResultFileName(documentId) {
|
|
39
|
+
if (!DOCUMENT_ID_RE.test(documentId)) {
|
|
40
|
+
throw new Error(`Invalid grade result document id: ${documentId}`);
|
|
41
|
+
}
|
|
42
|
+
return `${documentId.replace(/:/g, ".")}.yaml`;
|
|
43
|
+
}
|
|
44
|
+
export function gradeResultPath(resultsDirectory, documentId) {
|
|
45
|
+
return join(resultsDirectory, gradeResultFileName(documentId));
|
|
46
|
+
}
|
|
47
|
+
export function gradeResultPathForDocument(opts) {
|
|
48
|
+
const rootDir = opts.rootDir ?? specdojoRootDir();
|
|
49
|
+
const absolute = resolve(rootDir, opts.documentPath);
|
|
50
|
+
const content = readFileSync(absolute, "utf8");
|
|
51
|
+
return gradeResultPath(resolveGradeResultsDirectory(opts.project, rootDir), markdownDocumentId(content, opts.documentPath));
|
|
52
|
+
}
|
|
53
|
+
export function parseGradeResult(content, path) {
|
|
54
|
+
const parsed = load(content);
|
|
55
|
+
if (!isRecord(parsed))
|
|
56
|
+
throw new Error(`${path}: grade result must be a mapping`);
|
|
57
|
+
const result = parsed;
|
|
58
|
+
if (result.version !== 1 ||
|
|
59
|
+
typeof result.document !== "string" ||
|
|
60
|
+
typeof result.path !== "string" ||
|
|
61
|
+
(result.target !== "kata" && result.target !== "deliverable") ||
|
|
62
|
+
typeof result.rubric !== "string" ||
|
|
63
|
+
(result.verdict !== "pass" && result.verdict !== "needs-work" && result.verdict !== "fail") ||
|
|
64
|
+
!Number.isSafeInteger(result.score) ||
|
|
65
|
+
typeof result.graded_at !== "string" ||
|
|
66
|
+
typeof result.graded_by !== "string" ||
|
|
67
|
+
typeof result.content_hash !== "string" ||
|
|
68
|
+
!isRecord(result.categories) ||
|
|
69
|
+
!isRecord(result.viewpoints) ||
|
|
70
|
+
!isRecord(result.finding_counts) ||
|
|
71
|
+
!Array.isArray(result.findings)) {
|
|
72
|
+
throw new Error(`${path}: invalid grade result`);
|
|
73
|
+
}
|
|
74
|
+
if (result.source_hashes !== undefined &&
|
|
75
|
+
(!isRecord(result.source_hashes) ||
|
|
76
|
+
Object.values(result.source_hashes).some((hash) => typeof hash !== "string" || !/^[a-f0-9]{64}$/.test(hash)))) {
|
|
77
|
+
throw new Error(`${path}: source_hashes must map sources to SHA-256 hex digests`);
|
|
78
|
+
}
|
|
79
|
+
return result;
|
|
80
|
+
}
|
|
81
|
+
export function gradeFindingDisplayMessage(finding) {
|
|
82
|
+
return finding.message_ja?.trim() || finding.message;
|
|
83
|
+
}
|
|
84
|
+
export function readGradeResult(path) {
|
|
85
|
+
if (!existsSync(path))
|
|
86
|
+
return undefined;
|
|
87
|
+
return parseGradeResult(readFileSync(path, "utf8"), path);
|
|
88
|
+
}
|
|
89
|
+
export function readGradeResultForDocument(opts) {
|
|
90
|
+
return readGradeResult(gradeResultPathForDocument(opts));
|
|
91
|
+
}
|
|
92
|
+
export function gradeFindingCount(result) {
|
|
93
|
+
return SEVERITIES.reduce((sum, severity) => sum + result.finding_counts[severity], 0);
|
|
94
|
+
}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { readFileSync } from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { fileURLToPath } from "node:url";
|
|
4
|
-
// このモジュールは開発時は src/、npm 配布時は dist/
|
|
5
|
-
//
|
|
4
|
+
// このモジュールは開発時は src/shared/、npm 配布時は dist/shared/ にある。
|
|
5
|
+
// どちらの場合もモジュール位置から 2 階層上が SpecDojo package のルートになる。
|
|
6
6
|
//
|
|
7
7
|
// SPECDOJO_PACKAGE_ROOT は参照先の package を明示的に差し替える。利用リポジトリに kata を
|
|
8
8
|
// 持たない構成では、モジュール位置から求めた package が自動で参照されるため、単体テストの
|
|
9
9
|
// 一時ディレクトリが開発リポジトリの kata へ解決されてしまう。テストと検証では、この変数へ
|
|
10
10
|
// 一時ディレクトリを指定して解決範囲を閉じる。
|
|
11
11
|
function moduleRelativePackageRoot() {
|
|
12
|
-
return path.resolve(path.dirname(fileURLToPath(import.meta.url)), "
|
|
12
|
+
return path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../..");
|
|
13
13
|
}
|
|
14
14
|
export function specdojoPackageRootDir() {
|
|
15
15
|
const override = process.env.SPECDOJO_PACKAGE_ROOT;
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import { resolveSpecdojoPath, resolveSpecdojoPathIfExists, specdojoReferencePath, } from "./template-resolution.js";
|
|
3
|
+
export const MISSING = "_MISSING_";
|
|
4
|
+
const COMMON_CONVENTIONS_TEMPLATE = "xep-common-conventions-template.md";
|
|
5
|
+
const COMMON_CONVENTIONS_PLACEHOLDER = "_COMMON_CONVENTIONS_";
|
|
6
|
+
const REVIEW_ONLY_START = "<!-- review-only:start -->";
|
|
7
|
+
const REVIEW_ONLY_END = "<!-- review-only:end -->";
|
|
8
|
+
const PLAN_ESSENTIALS_START = "<!-- plan-essentials:start -->";
|
|
9
|
+
const PLAN_ESSENTIALS_END = "<!-- plan-essentials:end -->";
|
|
10
|
+
const DEFAULT_CONVENTIONS_HEADING = "## 共通: 記法・成果物規約";
|
|
11
|
+
const SCHEMA_REF_PLACEHOLDER = "_SCHEMA_REF_";
|
|
12
|
+
export function execTemplatesDir() {
|
|
13
|
+
return resolveSpecdojoPath("docs/ja/specdojo/exec-templates");
|
|
14
|
+
}
|
|
15
|
+
export function execTemplatePath(fileName) {
|
|
16
|
+
return resolveSpecdojoPath(`docs/ja/specdojo/exec-templates/${fileName}`);
|
|
17
|
+
}
|
|
18
|
+
function templatePrefix(mode) {
|
|
19
|
+
return mode === "review" ? "xrp" : "xep";
|
|
20
|
+
}
|
|
21
|
+
function standardTemplateFileName(mode) {
|
|
22
|
+
return `${templatePrefix(mode)}-template.md`;
|
|
23
|
+
}
|
|
24
|
+
function approachTemplateFileName(mode, approach) {
|
|
25
|
+
return `${templatePrefix(mode)}-${approach}-template.md`;
|
|
26
|
+
}
|
|
27
|
+
function resolvePlanTemplatePath(mode, approach) {
|
|
28
|
+
if (approach) {
|
|
29
|
+
const candidatePath = resolveSpecdojoPathIfExists(`docs/ja/specdojo/exec-templates/${approachTemplateFileName(mode, approach)}`);
|
|
30
|
+
if (candidatePath)
|
|
31
|
+
return candidatePath;
|
|
32
|
+
}
|
|
33
|
+
return execTemplatePath(standardTemplateFileName(mode));
|
|
34
|
+
}
|
|
35
|
+
function readTemplate(templatePath, cache) {
|
|
36
|
+
const cached = cache.get(templatePath);
|
|
37
|
+
if (cached !== undefined)
|
|
38
|
+
return cached;
|
|
39
|
+
if (!existsSync(templatePath)) {
|
|
40
|
+
throw new Error(`Template not found: ${templatePath}`);
|
|
41
|
+
}
|
|
42
|
+
const content = readFileSync(templatePath, "utf8");
|
|
43
|
+
cache.set(templatePath, content);
|
|
44
|
+
return content;
|
|
45
|
+
}
|
|
46
|
+
export function loadPlanTemplate(mode, approach, cache) {
|
|
47
|
+
return readTemplate(resolvePlanTemplatePath(mode, approach), cache);
|
|
48
|
+
}
|
|
49
|
+
function extractMarkedBlock(text, start, end) {
|
|
50
|
+
const lines = text.split("\n");
|
|
51
|
+
const startIndex = lines.findIndex((line) => line.trim() === start);
|
|
52
|
+
if (startIndex < 0)
|
|
53
|
+
return null;
|
|
54
|
+
const endOffset = lines.slice(startIndex + 1).findIndex((line) => line.trim() === end);
|
|
55
|
+
if (endOffset < 0)
|
|
56
|
+
return null;
|
|
57
|
+
return lines
|
|
58
|
+
.slice(startIndex + 1, startIndex + 1 + endOffset)
|
|
59
|
+
.join("\n")
|
|
60
|
+
.trim();
|
|
61
|
+
}
|
|
62
|
+
function conventionsReferenceSentence(referencePath) {
|
|
63
|
+
return (`作業を始める前に、共通の規約の詳細 \`${referencePath}\` を読み、その内容に従う。` +
|
|
64
|
+
"次の箇条書きは、そのうち守らないと失敗に直結する要点である。");
|
|
65
|
+
}
|
|
66
|
+
function selectReviewOnlyBlock(conventions, isReview) {
|
|
67
|
+
const kept = [];
|
|
68
|
+
let inside = false;
|
|
69
|
+
for (const line of conventions.split("\n")) {
|
|
70
|
+
const marker = line.trim();
|
|
71
|
+
if (marker === REVIEW_ONLY_START) {
|
|
72
|
+
inside = true;
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
if (marker === REVIEW_ONLY_END) {
|
|
76
|
+
inside = false;
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
if (!inside || isReview)
|
|
80
|
+
kept.push(line);
|
|
81
|
+
}
|
|
82
|
+
return kept
|
|
83
|
+
.join("\n")
|
|
84
|
+
.replace(/\n{3,}/g, "\n\n")
|
|
85
|
+
.trimEnd();
|
|
86
|
+
}
|
|
87
|
+
function planConventionsText(fragment, referencePath, isReview) {
|
|
88
|
+
const essentials = extractMarkedBlock(fragment, PLAN_ESSENTIALS_START, PLAN_ESSENTIALS_END);
|
|
89
|
+
if (essentials === null)
|
|
90
|
+
return selectReviewOnlyBlock(fragment, isReview);
|
|
91
|
+
const heading = fragment.split("\n").find((line) => line.startsWith("## ")) ?? DEFAULT_CONVENTIONS_HEADING;
|
|
92
|
+
const sections = [heading, conventionsReferenceSentence(referencePath), essentials];
|
|
93
|
+
if (isReview) {
|
|
94
|
+
const reviewOnly = extractMarkedBlock(fragment, REVIEW_ONLY_START, REVIEW_ONLY_END);
|
|
95
|
+
if (reviewOnly)
|
|
96
|
+
sections.push(reviewOnly);
|
|
97
|
+
}
|
|
98
|
+
return sections.join("\n\n");
|
|
99
|
+
}
|
|
100
|
+
export function injectCommonConventions(body, schemaRef, cache, mode = "edit") {
|
|
101
|
+
const fragmentPath = execTemplatePath(COMMON_CONVENTIONS_TEMPLATE);
|
|
102
|
+
let conventions = planConventionsText(readTemplate(fragmentPath, cache), specdojoReferencePath(fragmentPath), mode === "review");
|
|
103
|
+
conventions =
|
|
104
|
+
schemaRef === MISSING
|
|
105
|
+
? conventions
|
|
106
|
+
.split("\n")
|
|
107
|
+
.filter((line) => !line.includes(SCHEMA_REF_PLACEHOLDER))
|
|
108
|
+
.join("\n")
|
|
109
|
+
: conventions.split(SCHEMA_REF_PLACEHOLDER).join(schemaRef);
|
|
110
|
+
if (body.includes(COMMON_CONVENTIONS_PLACEHOLDER)) {
|
|
111
|
+
return body.split(COMMON_CONVENTIONS_PLACEHOLDER).join(conventions);
|
|
112
|
+
}
|
|
113
|
+
return `${body.trimEnd()}\n\n${conventions}\n`;
|
|
114
|
+
}
|
|
@@ -2,7 +2,9 @@ import { existsSync } from "node:fs";
|
|
|
2
2
|
import { copyFile, mkdir, readdir, readFile, writeFile } from "node:fs/promises";
|
|
3
3
|
import { homedir } from "node:os";
|
|
4
4
|
import path from "node:path";
|
|
5
|
-
|
|
5
|
+
function isRecord(value) {
|
|
6
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
7
|
+
}
|
|
6
8
|
export { specdojoPackageRootDir } from "./package-paths.js";
|
|
7
9
|
export const ORCHESTRATOR_NPM_SCRIPTS = {
|
|
8
10
|
claude: {
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { existsSync } from "node:fs";
|
|
2
2
|
import { dirname, join, resolve } from "node:path";
|
|
3
|
-
import {
|
|
3
|
+
import { listFilesRecursive, readYaml } from "./fs.js";
|
|
4
|
+
import { isSchYamlFilename, toScheduleFilePath } from "./schedule-paths.js";
|
|
4
5
|
import { specdojoRootDir } from "./specdojo-config.js";
|
|
6
|
+
import { normalizeDateOnly } from "./time.js";
|
|
5
7
|
export function defaultScheduleCalendar() {
|
|
6
8
|
return {
|
|
7
9
|
timezone: "UTC",
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { basename, relative } from "node:path";
|
|
2
|
+
import { toPortablePath } from "./artifact-path.js";
|
|
3
|
+
export function isSchYamlFilename(path) {
|
|
4
|
+
const name = basename(path);
|
|
5
|
+
return /^sch-.*\.(yaml|yml)$/.test(name);
|
|
6
|
+
}
|
|
7
|
+
export function toScheduleFilePath(schedulePath, filePath) {
|
|
8
|
+
return toPortablePath(relative(schedulePath, filePath) || ".");
|
|
9
|
+
}
|