specdojo 0.3.1 → 0.4.1
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/.github/agents/specdojo-orchestrator.md +61 -2
- package/CHANGELOG.md +90 -0
- package/README.md +85 -25
- 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} +168 -45
- package/dist/commands/night-orchestrator.js +287 -0
- package/dist/{orchestrator.js → commands/orchestrator.js} +12 -5
- 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} +8 -4
- package/dist/devcontainer/scaffold.js +418 -0
- 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} +92 -5
- 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} +18 -4
- package/dist/{exec-pipeline-state.js → exec/pipeline-state.js} +29 -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} +114 -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} +14 -11
- 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} +142 -25
- package/dist/{exec-results.js → exec/results.js} +287 -31
- package/dist/{exec-run-agent-pipeline.js → exec/run/agent-pipeline.js} +35 -12
- package/dist/{exec-run-agent.js → exec/run/agent.js} +115 -28
- package/dist/{exec-run-in-place.js → exec/run/in-place.js} +56 -27
- package/dist/{exec-run-job.js → exec/run/job.js} +65 -36
- 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} +38 -11
- package/dist/{exec-run-register-core.js → exec/run/register-core.js} +63 -21
- package/dist/{exec-run-register-mode.js → exec/run/register-mode.js} +58 -31
- package/dist/exec/run/register-post-review.js +420 -0
- package/dist/{exec-run-register-resume.js → exec/run/register-resume.js} +48 -27
- 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} +119 -24
- 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} +78 -30
- 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} +104 -17
- 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} +26 -8
- package/dist/{register-create-commands.js → register/create-commands.js} +171 -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} +44 -3
- package/dist/{register-events.js → register/events.js} +13 -3
- package/dist/{register-history.js → register/history.js} +7 -6
- package/dist/{register-item.js → register/item.js} +32 -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} +5 -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/shared/git.js +346 -0
- 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} +6 -3
- 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} +162 -21
- package/dist/{exec-shared.js → shared/text.js} +4 -135
- package/dist/shared/time.js +28 -0
- package/dist/shared/workspace-scaffold.js +69 -0
- package/dist/specdojo.js +22 -22
- package/docs/ja/specdojo/exec-templates/xep-common-conventions-template.md +31 -18
- package/docs/ja/specdojo/exec-templates/xep-register-investigate-template.md +1 -2
- package/docs/ja/specdojo/exec-templates/xep-register-template.md +3 -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/exec-templates/xrp-register-post-run-template.md +46 -0
- package/docs/ja/specdojo/guides/branch-workflow-guide.md +34 -1
- package/docs/ja/specdojo/guides/docs-structure-guide.md +2 -0
- package/docs/ja/specdojo/guides/exec-config-guide.md +169 -26
- package/docs/ja/specdojo/guides/exec-operation-guide.md +184 -13
- package/docs/ja/specdojo/guides/exec-worktree-guide.md +2 -0
- package/docs/ja/specdojo/guides/orchestrator-operation-guide.md +40 -3
- package/docs/ja/specdojo/guides/quick-start-guide.md +89 -21
- package/docs/ja/specdojo/guides/register-operation-guide.md +44 -1
- package/docs/ja/specdojo/guides/remote-host-development-guide.md +61 -6
- 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/specdojo-overview-guide.md +1 -1
- package/docs/ja/specdojo/guides/use-case-guide.md +1 -1
- package/docs/ja/specdojo/guides/waza-guide.md +1 -1
- package/docs/ja/specdojo/references/command-reference.md +124 -55
- package/docs/ja/specdojo/references/specdojo-config-reference.md +33 -7
- package/docs/ja/specdojo/rulebooks/pjr-rulebook.md +22 -13
- 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 +111 -17
- package/docs/specdojo/schemas/v1/exec-evidence.schema.yaml +28 -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 +38 -0
- package/docs/specdojo/schemas/v1/register-events.schema.yaml +5 -0
- package/docs/specdojo/schemas/v1/register-item-frontmatter.schema.yaml +91 -7
- package/docs/specdojo/schemas/v1/routine-run.schema.yaml +1 -1
- package/docs/specdojo/schemas/v1/specdojo-config.schema.yaml +36 -1
- package/package.json +17 -17
- package/templates/antigravity/README.md +6 -2
- package/templates/antigravity/agent-members-snippet.yaml +108 -12
- package/templates/antigravity/exec-defaults-snippet.yaml +8 -13
- package/templates/antigravity/orchestrator.md +61 -2
- 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/claude/agents/specdojo-orchestrator.md +61 -2
- package/templates/codex/README.md +40 -4
- package/templates/codex/agents/specdojo-orchestrator.toml +61 -2
- package/templates/codex/orchestrator.md +61 -2
- package/templates/devcontainer/devcontainer.json +5 -2
- package/templates/devcontainer/post-create.sh +15 -7
- package/templates/devcontainer/remote-host/specdojo-tmux.sh.sample +102 -0
- package/templates/devcontainer/remote-host/ssh-config.sample +19 -0
- package/templates/devcontainer/vim/vimrc +37 -0
- package/templates/init-agent-members.yaml +75 -25
- package/templates/init-exec-defaults.yaml +44 -9
- 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/templates/opencode/agents/specdojo-orchestrator.md +61 -2
- package/dist/devcontainer-scaffold.js +0 -165
- package/dist/exec-schedule-gantt-chart.js +0 -2
- package/dist/exec-worktree.js +0 -474
- 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
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
|
+
import { appendFileSync, lstatSync, mkdirSync } from "node:fs";
|
|
3
|
+
import { dirname, join, relative, resolve, sep } from "node:path";
|
|
4
|
+
import { gitEnvironment } from "./git-environment.js";
|
|
5
|
+
import { redactSensitiveText, stripTerminalControlSequences } from "./text.js";
|
|
6
|
+
export { GIT_LOCAL_ENV_VARS, gitEnvironment } from "./git-environment.js";
|
|
7
|
+
// git serializes index access through .git/index.lock and fails immediately (no wait) when it
|
|
8
|
+
// cannot acquire it. Under `exec run --parallel`, the parent's root-index operations and the
|
|
9
|
+
// concurrent worktree commits (each firing lefthook pre-commit hooks that invoke git) contend
|
|
10
|
+
// for that lock, surfacing as "Unable to create '.../index.lock'". A failed lock acquisition
|
|
11
|
+
// happens before git mutates anything, so retrying the same command is safe and idempotent.
|
|
12
|
+
// 並行の run の統合や記帳と重なると、ロックは数百ミリ秒より長く保持される(PJR-G90K)。
|
|
13
|
+
// 1.5 秒間隔で 10 回までやり直し、ロックのファイルは消さない(実際に動いている git がありうる)。
|
|
14
|
+
export const INDEX_LOCK_RETRY_ATTEMPTS = 10;
|
|
15
|
+
export const INDEX_LOCK_RETRY_WAIT_MS = 1500;
|
|
16
|
+
// dubious ownership と、`.git` がある cwd での not-a-repository は一時的に起き、すぐの
|
|
17
|
+
// 再試行では収まらないことがある(並行実行中の統合段で確認した)。両方で上限を共有する。
|
|
18
|
+
const TRANSIENT_GIT_RETRY_DELAYS_MS = [2000, 5000, 10000];
|
|
19
|
+
// 英語の `Unable to create '<path>/index.lock': File exists.` に加え、翻訳された git の
|
|
20
|
+
// メッセージ(日本語など)でも引用符で囲まれた index.lock のパスが出るため、それも拾う。
|
|
21
|
+
const INDEX_LOCK_QUOTED_PATH = /['"‘’“「]([^'"‘’“”「」\r\n]*index\.lock)['"’”」]/u;
|
|
22
|
+
export function gitIndexLockPath(stderr) {
|
|
23
|
+
return INDEX_LOCK_QUOTED_PATH.exec(stderr)?.[1];
|
|
24
|
+
}
|
|
25
|
+
export function isGitIndexLockContention(stderr) {
|
|
26
|
+
return (/Unable to create '[^']*index\.lock'/.test(stderr) ||
|
|
27
|
+
/Another git process seems to be running/.test(stderr) ||
|
|
28
|
+
/別の\s*git\s*プロセス/iu.test(stderr) ||
|
|
29
|
+
gitIndexLockPath(stderr) !== undefined);
|
|
30
|
+
}
|
|
31
|
+
export function isGitDubiousOwnership(stderr) {
|
|
32
|
+
return /fatal:\s+detected dubious ownership in repository\b/i.test(stderr);
|
|
33
|
+
}
|
|
34
|
+
export function isGitNotRepositoryWithGitMetadata(stderr, repoRoot) {
|
|
35
|
+
if (!/\bnot a git repository\b/i.test(stderr))
|
|
36
|
+
return false;
|
|
37
|
+
try {
|
|
38
|
+
const metadata = lstatSync(join(resolve(repoRoot), ".git"));
|
|
39
|
+
return metadata.isFile() || metadata.isDirectory();
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
// Synchronously block the thread. gitResult is intentionally spawnSync-based (blocking), and we
|
|
46
|
+
// want to wait for a contended index.lock to be released before retrying rather than busy-loop.
|
|
47
|
+
function sleepSync(milliseconds) {
|
|
48
|
+
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, milliseconds);
|
|
49
|
+
}
|
|
50
|
+
export function transientGitFailureReason(stderr, repoRoot) {
|
|
51
|
+
if (isGitDubiousOwnership(stderr))
|
|
52
|
+
return "dubious ownership";
|
|
53
|
+
if (repoRoot !== undefined && isGitNotRepositoryWithGitMetadata(stderr, repoRoot)) {
|
|
54
|
+
return "not a git repository";
|
|
55
|
+
}
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
export function runGitWithTransientRetry(run, onTransientFailureRetry = () => undefined, sleep = sleepSync, repoRoot, recoverFromTransientFailure) {
|
|
59
|
+
let indexLockRetries = 0;
|
|
60
|
+
let transientFailureRetries = 0;
|
|
61
|
+
let result = run();
|
|
62
|
+
while (result.status !== 0) {
|
|
63
|
+
const stderr = typeof result.stderr === "string" ? result.stderr : "";
|
|
64
|
+
const transientFailure = transientGitFailureReason(stderr, repoRoot);
|
|
65
|
+
if (transientFailure !== undefined) {
|
|
66
|
+
// Some multi-step Git commands can finish their mutation before a later ownership check
|
|
67
|
+
// reports a transient failure. Give those commands a chance to verify/reconcile their
|
|
68
|
+
// postcondition before blindly repeating a non-idempotent operation.
|
|
69
|
+
if (recoverFromTransientFailure?.(transientFailure)) {
|
|
70
|
+
return { ...result, status: 0, stderr: "" };
|
|
71
|
+
}
|
|
72
|
+
if (transientFailureRetries < TRANSIENT_GIT_RETRY_DELAYS_MS.length) {
|
|
73
|
+
const waitMilliseconds = TRANSIENT_GIT_RETRY_DELAYS_MS[transientFailureRetries];
|
|
74
|
+
transientFailureRetries += 1;
|
|
75
|
+
onTransientFailureRetry({
|
|
76
|
+
attempt: transientFailureRetries,
|
|
77
|
+
maxAttempts: TRANSIENT_GIT_RETRY_DELAYS_MS.length,
|
|
78
|
+
waitMilliseconds,
|
|
79
|
+
reason: transientFailure,
|
|
80
|
+
});
|
|
81
|
+
sleep(waitMilliseconds);
|
|
82
|
+
result = run();
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
if (indexLockRetries < INDEX_LOCK_RETRY_ATTEMPTS && isGitIndexLockContention(stderr)) {
|
|
87
|
+
indexLockRetries += 1;
|
|
88
|
+
onTransientFailureRetry({
|
|
89
|
+
attempt: indexLockRetries,
|
|
90
|
+
maxAttempts: INDEX_LOCK_RETRY_ATTEMPTS,
|
|
91
|
+
waitMilliseconds: INDEX_LOCK_RETRY_WAIT_MS,
|
|
92
|
+
reason: "index.lock contention",
|
|
93
|
+
});
|
|
94
|
+
sleep(INDEX_LOCK_RETRY_WAIT_MS);
|
|
95
|
+
result = run();
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
return result;
|
|
101
|
+
}
|
|
102
|
+
// spawnSync の既定の maxBuffer(1 MiB)では、未追跡のファイルが多い作業場所の
|
|
103
|
+
// `git status --porcelain` などが打ち切られ、子プロセスが SIGTERM で止められる。
|
|
104
|
+
export const GIT_OUTPUT_MAX_BUFFER = 256 * 1024 * 1024;
|
|
105
|
+
export function gitResult(repoRoot, args, recoverFromTransientFailure) {
|
|
106
|
+
const cwd = resolve(repoRoot);
|
|
107
|
+
const run = () => spawnSync("git", ["-C", cwd, ...args], {
|
|
108
|
+
// `-C` だけに依存せず、子プロセス自体も対象 repository から起動する。linked worktree の
|
|
109
|
+
// `.git` が相対 gitdir の場合も、resume 中の diff を runner の cwd から切り離す。
|
|
110
|
+
cwd,
|
|
111
|
+
encoding: "utf8",
|
|
112
|
+
env: gitEnvironment(),
|
|
113
|
+
maxBuffer: GIT_OUTPUT_MAX_BUFFER,
|
|
114
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
115
|
+
});
|
|
116
|
+
return runGitWithTransientRetry(run, ({ attempt, maxAttempts, waitMilliseconds, reason }) => {
|
|
117
|
+
const summary = summarizeGitArguments(args);
|
|
118
|
+
process.stderr.write(`warning: git command failed with ${reason}; retrying in ${waitMilliseconds / 1000}s` +
|
|
119
|
+
` (attempt ${attempt}/${maxAttempts}, cwd: ${repoRoot}${summary ? `, args: ${summary}` : ""})\n`);
|
|
120
|
+
}, sleepSync, cwd, recoverFromTransientFailure);
|
|
121
|
+
}
|
|
122
|
+
// git 失敗メッセージは register イベントの reason、result の block_reason、実行ログの一覧行の
|
|
123
|
+
// いずれでも長さ上限で切り詰められて記録される。commit のように pathspec が全件並ぶコマンドでは、
|
|
124
|
+
// 引数をそのまま連ねると失敗原因(stderr)が上限の外へ押し出されて残らない。原因を先頭付近へ置き、
|
|
125
|
+
// 引数は pathspec を件数へ要約したうえで末尾に添える。
|
|
126
|
+
const MAX_GIT_ARGUMENT_LENGTH = 40;
|
|
127
|
+
const MAX_GIT_ARGUMENT_SUMMARY_LENGTH = 120;
|
|
128
|
+
function abbreviate(value, limit) {
|
|
129
|
+
return value.length <= limit ? value : `${value.slice(0, Math.max(0, limit - 1))}…`;
|
|
130
|
+
}
|
|
131
|
+
// `--` 以降の pathspec は件数へ、それ以外の引数は 1 件ずつ長さを制限して要約する。
|
|
132
|
+
export function summarizeGitArguments(args) {
|
|
133
|
+
const separatorIndex = args.indexOf("--");
|
|
134
|
+
const head = separatorIndex === -1 ? args : args.slice(0, separatorIndex);
|
|
135
|
+
const parts = head.map((arg) => abbreviate(arg, MAX_GIT_ARGUMENT_LENGTH));
|
|
136
|
+
if (separatorIndex !== -1) {
|
|
137
|
+
const pathCount = args.length - separatorIndex - 1;
|
|
138
|
+
parts.push(`-- ${pathCount} ${pathCount === 1 ? "path" : "paths"}`);
|
|
139
|
+
}
|
|
140
|
+
return abbreviate(parts.join(" "), MAX_GIT_ARGUMENT_SUMMARY_LENGTH);
|
|
141
|
+
}
|
|
142
|
+
// git は進捗を `\r` で上書きしながら stderr へ書く(`Updating files: 52% (2412/4638)` など)。
|
|
143
|
+
// 失敗理由へ stderr 全文を載せると進捗が文字数を占有し、register の block_reason が
|
|
144
|
+
// 切り詰められた際に、進捗の後ろへ出る原因行が失われる。行ごとに `\r` の最終表示だけを
|
|
145
|
+
// 残し、進捗だけの行を落としたうえで、原因が書かれる側から行を採る。
|
|
146
|
+
const GIT_PROGRESS_LINE = /^(?:remote: )?(?:Updating files|Receiving objects|Resolving deltas|Counting objects|Compressing objects|Writing objects|Enumerating objects|Checking out files|Unpacking objects|Filtering content)\b.*?\d+%/u;
|
|
147
|
+
const GIT_CAUSE_LINE = /(?:\bfatal\b|\berror\b|\bwarning\b|\bCONFLICT\b|\bdenied\b|\bNo space left\b)/i;
|
|
148
|
+
const GIT_FAILURE_REASON_MAX_LENGTH = 400;
|
|
149
|
+
export function summarizeGitStderr(stderr, maxLength = GIT_FAILURE_REASON_MAX_LENGTH) {
|
|
150
|
+
const lines = stripTerminalControlSequences(stderr)
|
|
151
|
+
.split("\n")
|
|
152
|
+
// `\r` は同じ行の上書きを表すため、最後に表示された内容だけを残す。
|
|
153
|
+
.map((line) => line.split("\r").at(-1) ?? "")
|
|
154
|
+
.map((line) => line.trim())
|
|
155
|
+
.filter((line) => line !== "" && !GIT_PROGRESS_LINE.test(line));
|
|
156
|
+
if (lines.length === 0)
|
|
157
|
+
return "";
|
|
158
|
+
const causes = lines.filter((line) => GIT_CAUSE_LINE.test(line));
|
|
159
|
+
// 原因を示す行が無い場合は、進捗の後ろに残った末尾側の行を採る。先頭は
|
|
160
|
+
// `Preparing worktree ...` のような手順の告知で、失敗の原因を含まない。
|
|
161
|
+
const selected = causes.length > 0 ? causes : lines.slice(-2);
|
|
162
|
+
const joined = selected.join(" / ");
|
|
163
|
+
return joined.length <= maxLength ? joined : `${joined.slice(0, maxLength - 1)}…`;
|
|
164
|
+
}
|
|
165
|
+
// 起動の失敗や出力の上限超過(ENOBUFS)では stderr が空になるため、spawnSync の
|
|
166
|
+
// error と signal から原因を組み立てる。git 自身が終了コードを返した場合は空文字を返す。
|
|
167
|
+
export function describeGitProcessFailure(outcome) {
|
|
168
|
+
const parts = [];
|
|
169
|
+
const error = outcome.error;
|
|
170
|
+
if (error) {
|
|
171
|
+
const code = "code" in error && typeof error.code === "string" ? error.code : undefined;
|
|
172
|
+
const message = error.message.trim();
|
|
173
|
+
if (code === "ENOBUFS") {
|
|
174
|
+
parts.push(`output exceeded maxBuffer (ENOBUFS): ${message}`);
|
|
175
|
+
}
|
|
176
|
+
else if (code && !message.includes(code)) {
|
|
177
|
+
parts.push(`${code}: ${message}`);
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
parts.push(message || "spawn error");
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
if (outcome.signal)
|
|
184
|
+
parts.push(`terminated by signal ${outcome.signal}`);
|
|
185
|
+
return parts.join("; ");
|
|
186
|
+
}
|
|
187
|
+
export function formatGitCommandFailure(args, stderr, processFailure = "") {
|
|
188
|
+
const subcommandIndex = args.findIndex((arg) => !arg.startsWith("-"));
|
|
189
|
+
const label = subcommandIndex === -1 ? "git" : `git ${args[subcommandIndex]}`;
|
|
190
|
+
const summary = summarizeGitArguments(subcommandIndex === -1
|
|
191
|
+
? args
|
|
192
|
+
: [...args.slice(0, subcommandIndex), ...args.slice(subcommandIndex + 1)]);
|
|
193
|
+
const detail = summary ? ` (args: ${summary})` : "";
|
|
194
|
+
// gitResult は index.lock の取り合いをやり直したうえで失敗を返す。どのロックが残っていたかを
|
|
195
|
+
// 要約の切り詰めに左右されず先頭に残す(ロックは runner が消さないため、人が確かめる手掛かり)。
|
|
196
|
+
const lockPath = isGitIndexLockContention(stderr) ? gitIndexLockPath(stderr) : undefined;
|
|
197
|
+
const lockNotice = lockPath ? `index.lock is still held (lock: ${lockPath})` : "";
|
|
198
|
+
const cause = [processFailure.trim(), lockNotice, summarizeGitStderr(stderr)]
|
|
199
|
+
.filter((part) => part !== "")
|
|
200
|
+
.join(" / ");
|
|
201
|
+
return cause ? `${label} failed: ${cause}${detail}` : `${label} failed${detail}`;
|
|
202
|
+
}
|
|
203
|
+
// gitResult を直接扱う呼び出し元でも、gitOutput と同じ stderr 要約に加えて終了コードを
|
|
204
|
+
// 必ず残す。status が null の起動失敗・signal 終了では describeGitProcessFailure が原因を補う。
|
|
205
|
+
export function formatGitResultFailure(args, result) {
|
|
206
|
+
const stderr = typeof result.stderr === "string" ? result.stderr : "";
|
|
207
|
+
const processFailure = [`exit ${result.status ?? "unknown"}`, describeGitProcessFailure(result)]
|
|
208
|
+
.filter(Boolean)
|
|
209
|
+
.join("; ");
|
|
210
|
+
return formatGitCommandFailure(args, stderr, processFailure);
|
|
211
|
+
}
|
|
212
|
+
// lefthook などの hook 出力から、block reason に載せる失敗ステップ名と最初のエラー行を
|
|
213
|
+
// 取り出し、Vitest の失敗テスト名・集計があれば末尾から補う。罫線や ANSI 制御は監査ログには
|
|
214
|
+
// 残す一方、短い理由には混ぜない。
|
|
215
|
+
export function summarizeGitHookFailure(output) {
|
|
216
|
+
const lines = stripTerminalControlSequences(output)
|
|
217
|
+
.split(/\r?\n/)
|
|
218
|
+
.map((line) => line
|
|
219
|
+
.trim()
|
|
220
|
+
.replace(/^[│┃║╎┆┊┋┇┌┐└┘├┤┬┴┼╭╮╰╯┏┓┗┛─━═\s]+/u, "")
|
|
221
|
+
.replace(/[│┃║╎┆┊┋┇┌┐└┘├┤┬┴┼╭╮╰╯┏┓┗┛─━═\s]+$/u, "")
|
|
222
|
+
.trim())
|
|
223
|
+
.filter(Boolean);
|
|
224
|
+
if (lines.length === 0)
|
|
225
|
+
return "unknown hook failure";
|
|
226
|
+
const stepHeaders = [];
|
|
227
|
+
for (const [index, line] of lines.entries()) {
|
|
228
|
+
const match = line.match(/^(.+?)\s*[❯▶]\s*$/u);
|
|
229
|
+
if (match)
|
|
230
|
+
stepHeaders.push({ step: match[1].trim(), index });
|
|
231
|
+
}
|
|
232
|
+
// parallel: true の lefthook は成功した step の出力も並べるため、最初の step 見出しが
|
|
233
|
+
// 失敗した step とは限らない。末尾の summary で失敗印(🥊 など)が付いた step を優先する。
|
|
234
|
+
const failedSteps = lines
|
|
235
|
+
.map((line) => line.match(/^(?:🥊|✗|✘|✕|❌)️?\s*([^\s(]+)/u)?.[1])
|
|
236
|
+
.filter((name) => name !== undefined && name !== "lefthook");
|
|
237
|
+
const selected = stepHeaders.find((header) => failedSteps.includes(header.step)) ?? stepHeaders[0];
|
|
238
|
+
const step = selected?.step ?? failedSteps[0] ?? "";
|
|
239
|
+
const stepIndex = selected?.index ?? -1;
|
|
240
|
+
const sectionEnd = selected === undefined
|
|
241
|
+
? lines.length
|
|
242
|
+
: (stepHeaders.find((header) => header.index > selected.index)?.index ?? lines.length);
|
|
243
|
+
const isDecoration = (line) => /^(?:hook output|summary:|exit status\b|failed steps?:|skip(?:ped)?\b)/i.test(line) ||
|
|
244
|
+
/^[✓✔✗✘✕❯▶]+$/u.test(line);
|
|
245
|
+
const isCandidate = (line) => line !== step && !isDecoration(line) && !/[❯▶]\s*$/u.test(line);
|
|
246
|
+
const sectionLines = lines.slice(stepIndex + 1, sectionEnd).filter(isCandidate);
|
|
247
|
+
// 整形ツールが出す "(unchanged)" などの進捗行より、error を含む行を最初のエラーとして選ぶ。
|
|
248
|
+
const errorLine = sectionLines.find((line) => /\berror\b/i.test(line)) ??
|
|
249
|
+
sectionLines[0] ??
|
|
250
|
+
lines.slice(stepIndex + 1).find(isCandidate);
|
|
251
|
+
const primary = step && errorLine
|
|
252
|
+
? `${step}: ${errorLine}`
|
|
253
|
+
: step ||
|
|
254
|
+
(lines.find((line) => /(?:\bCONFLICT\b|\bfatal:|\berror:|\bfailed\b)/i.test(line)) ??
|
|
255
|
+
lines.find((line) => !isDecoration(line)) ??
|
|
256
|
+
lines[0]);
|
|
257
|
+
const tail = lines
|
|
258
|
+
.filter((line) => /^(?:FAIL\b|Test Files\b|Tests\b)/iu.test(line))
|
|
259
|
+
.filter((line) => line !== errorLine && !primary.includes(line))
|
|
260
|
+
.slice(-3);
|
|
261
|
+
const summary = [primary, ...tail].join("; ");
|
|
262
|
+
const limit = 400;
|
|
263
|
+
if (summary.length <= limit)
|
|
264
|
+
return summary;
|
|
265
|
+
const marker = " … ";
|
|
266
|
+
const retained = limit - marker.length;
|
|
267
|
+
return `${summary.slice(0, Math.ceil(retained / 2))}${marker}${summary.slice(-Math.floor(retained / 2))}`;
|
|
268
|
+
}
|
|
269
|
+
/** Appends redacted Git/hook diagnostics to a run-scoped evidence log. */
|
|
270
|
+
export function appendGitFailureLog(path, lines) {
|
|
271
|
+
if (!path)
|
|
272
|
+
return;
|
|
273
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
274
|
+
appendFileSync(path, redactSensitiveText(`${lines.join("\n")}\n`), "utf8");
|
|
275
|
+
}
|
|
276
|
+
/** Appends a complete gitResult failure record while keeping the caller's operation label. */
|
|
277
|
+
export function appendGitResultFailureLog(path, label, result) {
|
|
278
|
+
appendGitFailureLog(path, [
|
|
279
|
+
`=== ${new Date().toISOString()} ${label} ===`,
|
|
280
|
+
`exit: ${result.status ?? "unknown"}`,
|
|
281
|
+
`signal: ${result.signal ?? "none"}`,
|
|
282
|
+
`error: ${result.error?.message ?? "none"}`,
|
|
283
|
+
"--- stdout ---",
|
|
284
|
+
typeof result.stdout === "string" ? result.stdout : "",
|
|
285
|
+
"--- stderr ---",
|
|
286
|
+
typeof result.stderr === "string" ? result.stderr : "",
|
|
287
|
+
"",
|
|
288
|
+
]);
|
|
289
|
+
}
|
|
290
|
+
// message は block reason 向けに要約する一方、調査に必要な stderr 全文は失わない。
|
|
291
|
+
export class GitCommandError extends Error {
|
|
292
|
+
args;
|
|
293
|
+
stderr;
|
|
294
|
+
constructor(message, args, stderr) {
|
|
295
|
+
super(message);
|
|
296
|
+
this.args = args;
|
|
297
|
+
this.stderr = stderr;
|
|
298
|
+
this.name = "GitCommandError";
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
export function gitOutput(repoRoot, args, recoverFromTransientFailure) {
|
|
302
|
+
const result = gitResult(repoRoot, args, recoverFromTransientFailure);
|
|
303
|
+
if (result.status !== 0 || result.error) {
|
|
304
|
+
const stderr = typeof result.stderr === "string" ? result.stderr : "";
|
|
305
|
+
throw new GitCommandError(formatGitCommandFailure(args, stderr, describeGitProcessFailure(result)), args, stderr);
|
|
306
|
+
}
|
|
307
|
+
return typeof result.stdout === "string" ? result.stdout : "";
|
|
308
|
+
}
|
|
309
|
+
export function repoRelative(repoRoot, path) {
|
|
310
|
+
const value = relative(repoRoot, path);
|
|
311
|
+
if (!value || value === ".." || value.startsWith(`..${sep}`)) {
|
|
312
|
+
throw new Error(`Path is outside repository root: ${path}`);
|
|
313
|
+
}
|
|
314
|
+
return value.split(sep).join("/");
|
|
315
|
+
}
|
|
316
|
+
export function worktreeStatusPaths(repoRoot) {
|
|
317
|
+
const output = gitOutput(repoRoot, ["status", "--porcelain=v1", "-z", "--untracked-files=all"]);
|
|
318
|
+
const records = output.split("\0").filter(Boolean);
|
|
319
|
+
const paths = [];
|
|
320
|
+
for (let index = 0; index < records.length; index++) {
|
|
321
|
+
const record = records[index];
|
|
322
|
+
if (record.length < 4)
|
|
323
|
+
continue;
|
|
324
|
+
const status = record.slice(0, 2);
|
|
325
|
+
paths.push(record.slice(3));
|
|
326
|
+
if ((status.includes("R") || status.includes("C")) && records[index + 1]) {
|
|
327
|
+
paths.push(records[++index]);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
return paths;
|
|
331
|
+
}
|
|
332
|
+
export function selectStageablePaths(repoRoot, paths) {
|
|
333
|
+
if (paths.length === 0)
|
|
334
|
+
return [];
|
|
335
|
+
const indexed = new Set(gitOutput(repoRoot, ["ls-files", "--full-name", "-z", "--", ...paths])
|
|
336
|
+
.split("\0")
|
|
337
|
+
.filter(Boolean));
|
|
338
|
+
const existsInWorktree = (path) => lstatSync(resolve(repoRoot, path), { throwIfNoEntry: false }) !== undefined;
|
|
339
|
+
return paths.filter((path) => indexed.has(path) || existsInWorktree(path));
|
|
340
|
+
}
|
|
341
|
+
export function stageCommitTargets(repoRoot, paths) {
|
|
342
|
+
const stageable = selectStageablePaths(repoRoot, paths);
|
|
343
|
+
if (stageable.length === 0)
|
|
344
|
+
return;
|
|
345
|
+
gitOutput(repoRoot, ["add", "-A", "--", ...stageable]);
|
|
346
|
+
}
|
|
@@ -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: {
|
|
@@ -10,10 +12,11 @@ export const ORCHESTRATOR_NPM_SCRIPTS = {
|
|
|
10
12
|
"orch:sonnet": "specdojo orchestrator launch --provider claude -- --agent specdojo-orchestrator --model sonnet",
|
|
11
13
|
},
|
|
12
14
|
codex: {
|
|
13
|
-
"orch:
|
|
15
|
+
"orch:sol": 'specdojo orchestrator launch --provider codex -- -m gpt-5.6-sol "$(cat .specdojo/codex/orchestrator.md)"',
|
|
16
|
+
"orch:terra": 'specdojo orchestrator launch --provider codex -- -m gpt-5.6-terra "$(cat .specdojo/codex/orchestrator.md)"',
|
|
14
17
|
},
|
|
15
18
|
antigravity: {
|
|
16
|
-
"orch:
|
|
19
|
+
"orch:flash": 'specdojo orchestrator launch --provider antigravity -- --add-dir "$(pwd)" --model gemini-3.8-flash-high -i "$(cat .specdojo/antigravity/orchestrator.md)"',
|
|
17
20
|
},
|
|
18
21
|
opencode: {
|
|
19
22
|
"orch:opencode": "specdojo orchestrator launch --provider opencode -- --agent specdojo-orchestrator",
|
|
@@ -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
|
+
}
|