specdojo 0.8.0 → 0.9.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/.github/agents/specdojo-orchestrator.md +4 -1
- package/CHANGELOG.md +64 -0
- package/dist/catalog/catalog.js +16 -14
- package/dist/commands/agent.js +5 -3
- package/dist/commands/build.js +69 -10
- package/dist/commands/git.js +206 -0
- package/dist/commands/init.js +4 -2
- package/dist/commands/where.js +25 -0
- package/dist/dashboard/dashboard.js +5 -3
- package/dist/dashboard/routines.js +4 -7
- package/dist/dashboard/timeline.js +14 -14
- package/dist/docs/index-command.js +2 -2
- package/dist/docs/yaml-business-tables.js +243 -0
- package/dist/docs/yaml-interface-tables.js +106 -0
- package/dist/docs/yaml-pages-command.js +5 -3
- package/dist/docs/yaml-pages.js +146 -3
- package/dist/docs/yaml-table-shared.js +70 -0
- package/dist/docs/yaml-tables.js +39 -0
- package/dist/exec/agent-config.js +9 -0
- package/dist/exec/agent-protected-config.js +2 -0
- package/dist/exec/commands.js +31 -18
- package/dist/exec/events.js +34 -14
- package/dist/exec/evidence.js +13 -3
- package/dist/exec/parent-validation.js +56 -3
- package/dist/exec/plans-core.js +21 -2
- package/dist/exec/plans-generation.js +6 -7
- package/dist/exec/post-integration.js +162 -0
- package/dist/exec/queue-command.js +166 -0
- package/dist/exec/queue.js +285 -0
- package/dist/exec/register-foreign-wait.js +84 -0
- package/dist/exec/repo-integration-sync.js +17 -5
- package/dist/exec/reporter.js +2 -2
- package/dist/exec/results.js +24 -4
- package/dist/exec/review-kata.js +4 -1
- package/dist/exec/run/agent-pipeline.js +3 -2
- package/dist/exec/run/agent.js +12 -6
- package/dist/exec/run/change-scope.js +365 -0
- package/dist/exec/run/deferred-cleanup.js +31 -0
- package/dist/exec/run/in-place.js +4 -1
- package/dist/exec/run/job-lock.js +66 -0
- package/dist/exec/run/job-sequence.js +137 -0
- package/dist/exec/run/job.js +56 -19
- package/dist/exec/run/lifecycle-commands.js +1 -1
- package/dist/exec/run/lock.js +22 -1
- package/dist/exec/run/register-command.js +8 -5
- package/dist/exec/run/register-mode.js +68 -8
- package/dist/exec/run/register-resume.js +68 -14
- package/dist/exec/run/register-state.js +13 -8
- package/dist/exec/run/register-worktree.js +140 -125
- package/dist/exec/run/schedule-mode.js +75 -14
- package/dist/exec/run/schedule-prepare.js +3 -0
- package/dist/exec/run/schedule-task.js +88 -38
- package/dist/exec/run/shared.js +5 -0
- package/dist/exec/schedule/schedule.js +116 -4
- package/dist/exec/shared.js +1 -1
- package/dist/exec/smoke.js +190 -0
- package/dist/exec/strategy.js +13 -3
- package/dist/exec/task-view.js +6 -4
- package/dist/exec/trial-commands.js +5 -2
- package/dist/exec/trial-core.js +6 -1
- package/dist/exec/validation-metrics.js +181 -0
- package/dist/exec/worktree-cleanup-lock.js +26 -0
- package/dist/exec/worktree-command.js +9 -1
- package/dist/exec/worktree-ops-commit.js +2 -2
- package/dist/exec/worktree.js +13 -2
- package/dist/grade/command-apply.js +3 -3
- package/dist/grade/command-inspect.js +5 -3
- package/dist/grade/command-plan.js +1 -1
- package/dist/grade/command-run.js +5 -1
- package/dist/grade/run.js +64 -8
- package/dist/job/definition.js +84 -8
- package/dist/job/job.js +79 -23
- package/dist/register/authoring-sources.js +22 -16
- package/dist/register/maintenance-commands.js +2 -2
- package/dist/register/register.js +31 -7
- package/dist/routine/definition.js +9 -0
- package/dist/routine/routine.js +137 -43
- package/dist/routine/status.js +62 -0
- package/dist/schedule/schedule.js +38 -39
- package/dist/shared/agent-types.js +5 -0
- package/dist/shared/cross-process-lock.js +9 -1
- package/dist/shared/dist-freshness.js +8 -2
- package/dist/shared/git-environment.js +2 -1
- package/dist/shared/git.js +44 -1
- package/dist/shared/lefthook-scaffold.js +3 -0
- package/dist/shared/local-config.js +244 -0
- package/dist/shared/specdojo-config.js +34 -20
- package/dist/shared/specdojo-gitignore.js +1 -0
- package/dist/shared/text.js +9 -1
- package/dist/shared/where-alias.js +13 -0
- package/dist/specdojo.js +4 -0
- package/docs/ja/specdojo/defaults/pm-review-viewpoints.yaml +2 -0
- package/docs/ja/specdojo/guides/exec-config-guide.md +23 -4
- package/docs/ja/specdojo/guides/exec-operation-guide.md +44 -1
- package/docs/ja/specdojo/guides/job-sequence-guide.md +77 -0
- package/docs/ja/specdojo/guides/quick-start-guide.md +3 -3
- package/docs/ja/specdojo/guides/register-operation-guide.md +1 -1
- package/docs/ja/specdojo/guides/routine-operation-guide.md +11 -6
- package/docs/ja/specdojo/guides/schedule-design-guide.md +20 -17
- package/docs/ja/specdojo/guides/waza-guide.md +12 -8
- package/docs/ja/specdojo/recipes/bac-recipe.md +66 -49
- package/docs/ja/specdojo/recipes/bes-recipe.md +90 -54
- package/docs/ja/specdojo/recipes/bps-recipe.md +88 -139
- package/docs/ja/specdojo/recipes/br-recipe.md +40 -47
- package/docs/ja/specdojo/recipes/cdfd-overview-recipe.md +97 -109
- package/docs/ja/specdojo/recipes/cdfd-recipe.md +85 -146
- package/docs/ja/specdojo/recipes/cdfd-uc-recipe.md +91 -110
- package/docs/ja/specdojo/recipes/cnd-recipe.md +79 -69
- package/docs/ja/specdojo/recipes/cpd-recipe.md +78 -64
- package/docs/ja/specdojo/recipes/cxd-recipe.md +92 -75
- package/docs/ja/specdojo/recipes/ifd-recipe.md +79 -68
- package/docs/ja/specdojo/recipes/ifx-cmd-recipe.md +78 -105
- package/docs/ja/specdojo/recipes/ifx-index-recipe.md +105 -71
- package/docs/ja/specdojo/recipes/pm-communication-plan-recipe.md +60 -49
- package/docs/ja/specdojo/recipes/pm-members-recipe.md +50 -51
- package/docs/ja/specdojo/recipes/pm-organization-recipe.md +59 -51
- package/docs/ja/specdojo/recipes/pm-plan-recipe.md +69 -56
- package/docs/ja/specdojo/recipes/pm-quality-management-plan-recipe.md +37 -56
- package/docs/ja/specdojo/recipes/pm-raci-recipe.md +39 -53
- package/docs/ja/specdojo/recipes/pm-roles-recipe.md +52 -79
- package/docs/ja/specdojo/recipes/prj-assumptions-constraints-dependencies-recipe.md +64 -93
- package/docs/ja/specdojo/recipes/prj-charter-recipe.md +71 -106
- package/docs/ja/specdojo/recipes/prj-comparison-of-alternatives-recipe.md +78 -157
- package/docs/ja/specdojo/recipes/prj-issues-and-approach-recipe.md +62 -111
- package/docs/ja/specdojo/recipes/prj-scope-recipe.md +67 -123
- package/docs/ja/specdojo/recipes/prj-stakeholder-register-recipe.md +60 -96
- package/docs/ja/specdojo/recipes/prj-success-criteria-and-acceptance-criteria-recipe.md +61 -105
- package/docs/ja/specdojo/recipes/stsd-recipe.md +79 -109
- package/docs/ja/specdojo/recipes/sysd-critical-flows-recipe.md +78 -55
- package/docs/ja/specdojo/recipes/sysd-cross-cutting-policy-recipe.md +82 -73
- package/docs/ja/specdojo/recipes/sysd-index-recipe.md +78 -59
- package/docs/ja/specdojo/recipes/tsd-recipe.md +149 -129
- package/docs/ja/specdojo/references/command-reference.md +257 -117
- package/docs/ja/specdojo/references/deliverables-reference.md +21 -12
- package/docs/ja/specdojo/references/specdojo-config-reference.md +37 -2
- package/docs/ja/specdojo/rulebooks/atc-index-rulebook.md +101 -257
- package/docs/ja/specdojo/rulebooks/atc-rulebook.md +102 -228
- package/docs/ja/specdojo/rulebooks/bac-rulebook.md +19 -28
- package/docs/ja/specdojo/rulebooks/bdd-rulebook.md +16 -67
- package/docs/ja/specdojo/rulebooks/bds-rulebook.md +30 -51
- package/docs/ja/specdojo/rulebooks/bes-index-rulebook.md +41 -61
- package/docs/ja/specdojo/rulebooks/bes-rulebook.md +22 -50
- package/docs/ja/specdojo/rulebooks/bps-rulebook.md +24 -56
- package/docs/ja/specdojo/rulebooks/br-rulebook.md +13 -38
- package/docs/ja/specdojo/rulebooks/ccd-mermaid-rulebook.md +41 -76
- package/docs/ja/specdojo/rulebooks/cdfd-d2-rulebook.md +18 -93
- package/docs/ja/specdojo/rulebooks/cdfd-mermaid-rulebook.md +18 -52
- package/docs/ja/specdojo/rulebooks/cdfd-overview-rulebook.md +109 -147
- package/docs/ja/specdojo/rulebooks/cdfd-rulebook.md +80 -108
- package/docs/ja/specdojo/rulebooks/cdfd-uc-rulebook.md +21 -46
- package/docs/ja/specdojo/rulebooks/cdr-rulebook.md +144 -0
- package/docs/ja/specdojo/rulebooks/cdsd-rulebook.md +27 -48
- package/docs/ja/specdojo/rulebooks/cdt-rulebook.md +37 -50
- package/docs/ja/specdojo/rulebooks/clis-rulebook.md +52 -69
- package/docs/ja/specdojo/rulebooks/cnd-mermaid-rulebook.md +33 -86
- package/docs/ja/specdojo/rulebooks/cnd-rulebook.md +16 -32
- package/docs/ja/specdojo/rulebooks/cop-index-rulebook.md +45 -131
- package/docs/ja/specdojo/rulebooks/cop-rulebook.md +69 -275
- package/docs/ja/specdojo/rulebooks/cpd-mermaid-rulebook.md +20 -112
- package/docs/ja/specdojo/rulebooks/cpd-rulebook.md +23 -56
- package/docs/ja/specdojo/rulebooks/cxd-mermaid-rulebook.md +12 -145
- package/docs/ja/specdojo/rulebooks/cxd-rulebook.md +39 -47
- package/docs/ja/specdojo/rulebooks/dct-index-rulebook.md +37 -56
- package/docs/ja/specdojo/rulebooks/dct-rulebook.md +118 -175
- package/docs/ja/specdojo/rulebooks/dec-rulebook.md +5 -14
- package/docs/ja/specdojo/rulebooks/dmd-index-rulebook.md +22 -66
- package/docs/ja/specdojo/rulebooks/dmd-rulebook.md +36 -94
- package/docs/ja/specdojo/rulebooks/dss-rulebook.md +59 -81
- package/docs/ja/specdojo/rulebooks/etc-index-rulebook.md +31 -131
- package/docs/ja/specdojo/rulebooks/etc-rulebook.md +50 -104
- package/docs/ja/specdojo/rulebooks/gl-rulebook.md +51 -61
- package/docs/ja/specdojo/rulebooks/ifd-mermaid-rulebook.md +38 -45
- package/docs/ja/specdojo/rulebooks/ifx-api-rulebook.md +14 -20
- package/docs/ja/specdojo/rulebooks/ifx-cmd-rulebook.md +26 -38
- package/docs/ja/specdojo/rulebooks/ifx-file-rulebook.md +26 -107
- package/docs/ja/specdojo/rulebooks/ifx-index-rulebook.md +42 -49
- package/docs/ja/specdojo/rulebooks/ifx-msg-rulebook.md +14 -22
- package/docs/ja/specdojo/rulebooks/imp-business-rulebook.md +21 -44
- package/docs/ja/specdojo/rulebooks/imp-data-rulebook.md +41 -64
- package/docs/ja/specdojo/rulebooks/imp-interface-rulebook.md +14 -38
- package/docs/ja/specdojo/rulebooks/imp-operations-rulebook.md +34 -61
- package/docs/ja/specdojo/rulebooks/imp-test-rulebook.md +27 -50
- package/docs/ja/specdojo/rulebooks/itc-index-rulebook.md +70 -199
- package/docs/ja/specdojo/rulebooks/itc-rulebook.md +65 -153
- package/docs/ja/specdojo/rulebooks/mip-index-rulebook.md +74 -150
- package/docs/ja/specdojo/rulebooks/mm-rulebook.md +11 -23
- package/docs/ja/specdojo/rulebooks/mtp-rulebook.md +99 -176
- package/docs/ja/specdojo/rulebooks/nfr-availability-rulebook.md +35 -61
- package/docs/ja/specdojo/rulebooks/nfr-index-rulebook.md +75 -117
- package/docs/ja/specdojo/rulebooks/nfr-integrity-rulebook.md +31 -60
- package/docs/ja/specdojo/rulebooks/nfr-maintainability-rulebook.md +26 -81
- package/docs/ja/specdojo/rulebooks/nfr-operations-rulebook.md +32 -70
- package/docs/ja/specdojo/rulebooks/nfr-performance-rulebook.md +45 -87
- package/docs/ja/specdojo/rulebooks/nfr-reliability-rulebook.md +48 -101
- package/docs/ja/specdojo/rulebooks/nfr-security-safety-rulebook.md +44 -80
- package/docs/ja/specdojo/rulebooks/nfr-usability-rulebook.md +59 -127
- package/docs/ja/specdojo/rulebooks/opd-index-rulebook.md +31 -50
- package/docs/ja/specdojo/rulebooks/opd-rulebook.md +42 -109
- package/docs/ja/specdojo/rulebooks/opr-index-rulebook.md +29 -42
- package/docs/ja/specdojo/rulebooks/opr-rulebook.md +29 -87
- package/docs/ja/specdojo/rulebooks/otp-index-rulebook.md +62 -84
- package/docs/ja/specdojo/rulebooks/otp-rulebook.md +11 -61
- package/docs/ja/specdojo/rulebooks/pjr-rulebook.md +91 -106
- package/docs/ja/specdojo/rulebooks/pm-change-request-log-rulebook.md +25 -34
- package/docs/ja/specdojo/rulebooks/pm-communication-plan-rulebook.md +30 -53
- package/docs/ja/specdojo/rulebooks/pm-issue-log-rulebook.md +23 -35
- package/docs/ja/specdojo/rulebooks/pm-members-rulebook.md +27 -45
- package/docs/ja/specdojo/rulebooks/pm-organization-rulebook.md +37 -45
- package/docs/ja/specdojo/rulebooks/pm-plan-rulebook.md +45 -46
- package/docs/ja/specdojo/rulebooks/pm-quality-management-plan-rulebook.md +37 -48
- package/docs/ja/specdojo/rulebooks/pm-raci-rulebook.md +25 -29
- package/docs/ja/specdojo/rulebooks/pm-risk-register-rulebook.md +28 -35
- package/docs/ja/specdojo/rulebooks/pm-roles-rulebook.md +36 -41
- package/docs/ja/specdojo/rulebooks/pr-rulebook.md +5 -18
- package/docs/ja/specdojo/rulebooks/prj-assumptions-constraints-dependencies-rulebook.md +16 -37
- package/docs/ja/specdojo/rulebooks/prj-charter-rulebook.md +23 -97
- package/docs/ja/specdojo/rulebooks/prj-comparison-of-alternatives-rulebook.md +39 -57
- package/docs/ja/specdojo/rulebooks/prj-issues-and-approach-rulebook.md +43 -116
- package/docs/ja/specdojo/rulebooks/prj-scope-rulebook.md +16 -51
- package/docs/ja/specdojo/rulebooks/prj-stakeholder-register-rulebook.md +47 -92
- package/docs/ja/specdojo/rulebooks/prj-success-criteria-and-acceptance-criteria-rulebook.md +25 -84
- package/docs/ja/specdojo/rulebooks/sac-rulebook.md +44 -107
- package/docs/ja/specdojo/rulebooks/sf-index-rulebook.md +39 -49
- package/docs/ja/specdojo/rulebooks/sf-rulebook.md +42 -49
- package/docs/ja/specdojo/rulebooks/sld-rulebook.md +64 -89
- package/docs/ja/specdojo/rulebooks/stc-index-rulebook.md +90 -189
- package/docs/ja/specdojo/rulebooks/stc-rulebook.md +45 -105
- package/docs/ja/specdojo/rulebooks/stsd-mermaid-rulebook.md +6 -12
- package/docs/ja/specdojo/rulebooks/stsd-rulebook.md +49 -68
- package/docs/ja/specdojo/rulebooks/sysd-critical-flows-rulebook.md +51 -60
- package/docs/ja/specdojo/rulebooks/sysd-cross-cutting-policy-rulebook.md +46 -50
- package/docs/ja/specdojo/rulebooks/sysd-index-rulebook.md +39 -64
- package/docs/ja/specdojo/rulebooks/sysd-rulebook.md +47 -60
- package/docs/ja/specdojo/rulebooks/trc-requirements-to-specs-rulebook.md +69 -70
- package/docs/ja/specdojo/rulebooks/trc-requirements-to-tests-rulebook.md +65 -72
- package/docs/ja/specdojo/rulebooks/tsd-index-rulebook.md +35 -46
- package/docs/ja/specdojo/rulebooks/tsd-rulebook.md +49 -66
- package/docs/ja/specdojo/rulebooks/tsp-index-rulebook.md +64 -139
- package/docs/ja/specdojo/rulebooks/uis-rulebook.md +41 -108
- package/docs/ja/specdojo/rulebooks/utc-index-rulebook.md +49 -144
- package/docs/ja/specdojo/rulebooks/utc-rulebook.md +67 -155
- package/docs/ja/specdojo/samples/bds-sample.md +58 -71
- package/docs/ja/specdojo/samples/bes-index-sample.md +20 -37
- package/docs/ja/specdojo/samples/bes-sample.md +43 -53
- package/docs/ja/specdojo/samples/bps-sample.md +42 -54
- package/docs/ja/specdojo/samples/br-sample.md +40 -52
- package/docs/ja/specdojo/samples/ccd-sample.md +0 -1
- package/docs/ja/specdojo/samples/cdr-sample.md +78 -0
- package/docs/ja/specdojo/samples/cdsd-sample.md +47 -63
- package/docs/ja/specdojo/samples/clis-sample.md +70 -77
- package/docs/ja/specdojo/samples/dec-sample.md +2 -3
- package/docs/ja/specdojo/samples/ifx-api-sample.yaml +0 -2
- package/docs/ja/specdojo/samples/ifx-msg-sample.yaml +0 -2
- package/docs/ja/specdojo/samples/job-sequence.yaml +67 -0
- package/docs/ja/specdojo/samples/mip-index-sample.md +98 -20
- package/docs/ja/specdojo/samples/pm-communication-plan-sample.md +26 -19
- package/docs/ja/specdojo/samples/pm-organization-sample.md +39 -50
- package/docs/ja/specdojo/samples/pm-plan-sample.md +61 -67
- package/docs/ja/specdojo/samples/pm-quality-management-plan-sample.md +31 -45
- package/docs/ja/specdojo/samples/pm-raci-sample.md +31 -37
- package/docs/ja/specdojo/samples/prj-assumptions-constraints-dependencies-sample.md +32 -48
- package/docs/ja/specdojo/samples/prj-charter-sample.md +42 -59
- package/docs/ja/specdojo/samples/prj-comparison-of-alternatives-sample.md +55 -61
- package/docs/ja/specdojo/samples/prj-success-criteria-and-acceptance-criteria-sample.md +30 -33
- package/docs/ja/specdojo/samples/sf-index-sample.md +13 -55
- package/docs/ja/specdojo/samples/sf-sample.md +73 -85
- package/docs/ja/specdojo/samples/sld-sample.md +60 -79
- package/docs/ja/specdojo/samples/uis-sample.md +98 -121
- package/docs/ja/specdojo/standards/job-definition-standard.md +24 -9
- package/docs/ja/specdojo/templates/cdr-template.md +58 -0
- package/docs/specdojo/schemas/v1/exec-common.schema.yaml +2 -1
- package/docs/specdojo/schemas/v1/exec-defaults.schema.yaml +42 -5
- package/docs/specdojo/schemas/v1/exec-evidence.schema.yaml +35 -0
- package/docs/specdojo/schemas/v1/job-run.schema.yaml +23 -0
- package/docs/specdojo/schemas/v1/job.schema.yaml +63 -2
- package/docs/specdojo/schemas/v1/sch-strategy.schema.yaml +2 -2
- package/package.json +9 -6
- package/templates/antigravity/orchestrator.md +4 -1
- package/templates/claude/agents/specdojo-orchestrator.md +4 -1
- package/templates/codex/agents/specdojo-orchestrator.toml +4 -1
- package/templates/codex/orchestrator.md +4 -1
- package/templates/init-exec-defaults.yaml +13 -0
- package/templates/lefthook/tools/specdojo-pre-commit.mjs +8 -0
- package/templates/opencode/agents/specdojo-orchestrator.md +5 -2
package/dist/routine/routine.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { registerDeprecatedWhereAlias } from "../shared/where-alias.js";
|
|
1
2
|
import { spawnSync } from "node:child_process";
|
|
2
3
|
import { appendFileSync, existsSync, mkdirSync, readdirSync, rmSync, statSync } from "node:fs";
|
|
3
4
|
import { join, resolve } from "node:path";
|
|
@@ -8,12 +9,13 @@ import { ensureDir, listFilesRecursive, readJson, writeJson } from "../shared/fs
|
|
|
8
9
|
import { padEndDisplay } from "../shared/text.js";
|
|
9
10
|
import { nowUtcIsoSeconds } from "../shared/time.js";
|
|
10
11
|
import { jobDeclaresReview, jobRunUsesReviewedIntegration, loadJobDefinition, resolveJobPaths, resolveJobReviewAgentNominations, } from "../job/job.js";
|
|
11
|
-
import { cronOccurrences, isRecord,
|
|
12
|
+
import { cronOccurrences, isRecord, isRoutineEntryDue, isRoutineYamlFile, isoWeek, loadRoutines, resolveRoutinePaths, routineActionKindLabel, } from "./definition.js";
|
|
12
13
|
import { selfRunArgs } from "../shared/spawn-self.js";
|
|
13
14
|
import { specdojoRootDir } from "../shared/specdojo-config.js";
|
|
14
15
|
import { migrateRoutineStorage } from "./storage.js";
|
|
15
16
|
import { recordRoutineFailure } from "./failure.js";
|
|
16
|
-
|
|
17
|
+
import { formatRoutineStatus, readRoutineHistoryLenient } from "./status.js";
|
|
18
|
+
export { cronMatches, cronOccurrences, isRoutineDue, isRoutineEntryDue, isoWeek, loadRoutines, parseCronExpression, parseIntervalMs, parseRoutineDoc, resolveRoutinePaths, routineActionKindLabel, } from "./definition.js";
|
|
17
19
|
// ================================
|
|
18
20
|
// State
|
|
19
21
|
// ================================
|
|
@@ -60,6 +62,46 @@ export function recordRoutineCompletion(current, result, reason, actionResults)
|
|
|
60
62
|
delete next.last_action_results;
|
|
61
63
|
return next;
|
|
62
64
|
}
|
|
65
|
+
// busy skip の回を流し直す上限(同じ routine で続いた回数)。毎時の `routine run --due` で
|
|
66
|
+
// おおよそ 1 日ぶん試し、超えたらその回を済んだ回として扱い、理由を last_reason と履歴に残す。
|
|
67
|
+
export const ROUTINE_BUSY_RETRY_LIMIT = 24;
|
|
68
|
+
/**
|
|
69
|
+
* 完了を記録した state を、skip の内訳に合わせて確定する。別の run の lock による skip(busy)は
|
|
70
|
+
* 済んだ回として扱わず、cron は last_scheduled_for を開始前の値へ戻し、interval は
|
|
71
|
+
* busy_skip_count を正にして次の `routine run --due` で due にする。missed_run が skip の cron、
|
|
72
|
+
* Job の前提条件による skip、skipped 以外の結果は従来どおり済んだ回として扱う。
|
|
73
|
+
*/
|
|
74
|
+
export function settleRoutineSkip(doc, previous, completed, result, busySkipped) {
|
|
75
|
+
const entry = { ...completed };
|
|
76
|
+
delete entry.busy_skip_count;
|
|
77
|
+
delete entry.last_skip_reason;
|
|
78
|
+
if (result !== "skipped")
|
|
79
|
+
return { entry, retryPending: false };
|
|
80
|
+
const skipReason = busySkipped ? "busy" : "precondition";
|
|
81
|
+
entry.last_skip_reason = skipReason;
|
|
82
|
+
if (!busySkipped || (doc.trigger && doc.policy?.missed_run === "skip")) {
|
|
83
|
+
return { entry, skipReason, retryPending: false };
|
|
84
|
+
}
|
|
85
|
+
const count = (previous?.busy_skip_count ?? 0) + 1;
|
|
86
|
+
if (count > ROUTINE_BUSY_RETRY_LIMIT) {
|
|
87
|
+
const note = `busy skip retry limit (${ROUTINE_BUSY_RETRY_LIMIT}) reached; occurrence not retried`;
|
|
88
|
+
entry.last_reason = entry.last_reason ? `${entry.last_reason}; ${note}` : note;
|
|
89
|
+
return { entry, skipReason, retryPending: false };
|
|
90
|
+
}
|
|
91
|
+
entry.busy_skip_count = count;
|
|
92
|
+
if (doc.trigger) {
|
|
93
|
+
if (previous?.last_scheduled_for)
|
|
94
|
+
entry.last_scheduled_for = previous.last_scheduled_for;
|
|
95
|
+
else
|
|
96
|
+
delete entry.last_scheduled_for;
|
|
97
|
+
}
|
|
98
|
+
return { entry, skipReason, retryPending: true };
|
|
99
|
+
}
|
|
100
|
+
// exec run / resume が別の run の lock で skip したときの出力(src/exec/run/shared.ts)。
|
|
101
|
+
// Job の前提条件による skip も同じ終了コードを返すため、出力で区別する。
|
|
102
|
+
export function isExecBusySkipOutput(output) {
|
|
103
|
+
return /^\[[a-z-]+\] skipped: exec busy$/m.test(output);
|
|
104
|
+
}
|
|
63
105
|
export function appendRoutineRunHistory(runsPath, entry) {
|
|
64
106
|
ensureDir(resolve(runsPath, ".."));
|
|
65
107
|
appendFileSync(runsPath, `${JSON.stringify(entry)}\n`, "utf8");
|
|
@@ -112,10 +154,15 @@ function ensureFreshDistForRoutineRun() {
|
|
|
112
154
|
let lastRoutineSpawnReason;
|
|
113
155
|
let lastRoutineSpawnRunId;
|
|
114
156
|
let lastRoutineSpawnNoop = false;
|
|
115
|
-
|
|
157
|
+
let lastRoutineSpawnBusy = false;
|
|
158
|
+
function resetRoutineSpawnMarkers() {
|
|
116
159
|
lastRoutineSpawnReason = undefined;
|
|
117
160
|
lastRoutineSpawnRunId = undefined;
|
|
118
161
|
lastRoutineSpawnNoop = false;
|
|
162
|
+
lastRoutineSpawnBusy = false;
|
|
163
|
+
}
|
|
164
|
+
function spawnSelf(args) {
|
|
165
|
+
resetRoutineSpawnMarkers();
|
|
119
166
|
const [exe, fullArgs] = selfRunArgs(args);
|
|
120
167
|
const result = spawnSync(exe, fullArgs, {
|
|
121
168
|
encoding: "utf8",
|
|
@@ -142,8 +189,10 @@ function spawnSelf(args) {
|
|
|
142
189
|
.filter(Boolean)
|
|
143
190
|
.at(-1);
|
|
144
191
|
}
|
|
145
|
-
if (result.status === ROUTINE_BUSY_SKIP_EXIT_CODE)
|
|
192
|
+
if (result.status === ROUTINE_BUSY_SKIP_EXIT_CODE) {
|
|
193
|
+
lastRoutineSpawnBusy = isExecBusySkipOutput(output);
|
|
146
194
|
return "skipped";
|
|
195
|
+
}
|
|
147
196
|
if (result.status === 0 && marker?.match(/\bstate=([^\s]+)/)?.[1] === "partial") {
|
|
148
197
|
return "partial";
|
|
149
198
|
}
|
|
@@ -214,9 +263,7 @@ function executeRoutineAction(doc, action, projectId, dryRun, scheduledAt = new
|
|
|
214
263
|
? buildSpecdojoActionArgs(action, projectId)
|
|
215
264
|
: buildJobRunArgs(action, projectId, scheduledAt, doc.trigger?.timezone ?? "UTC");
|
|
216
265
|
if (dryRun) {
|
|
217
|
-
|
|
218
|
-
lastRoutineSpawnRunId = undefined;
|
|
219
|
-
lastRoutineSpawnNoop = false;
|
|
266
|
+
resetRoutineSpawnMarkers();
|
|
220
267
|
process.stdout.write(` [dry-run] specdojo ${args.join(" ")}\n`);
|
|
221
268
|
if (action.kind === "job") {
|
|
222
269
|
try {
|
|
@@ -269,12 +316,11 @@ function executeRoutine(routine, projectId, dryRun, scheduledAt = new Date()) {
|
|
|
269
316
|
const multiple = Array.isArray(doc.action);
|
|
270
317
|
const jobRunIds = [];
|
|
271
318
|
const reasons = [];
|
|
319
|
+
let busySkipped = false;
|
|
272
320
|
const actionResults = executeRoutineActions(actions, (action, index) => {
|
|
273
321
|
if (multiple)
|
|
274
322
|
process.stdout.write(` action ${index}/${actions.length}: ${action.kind}\n`);
|
|
275
|
-
|
|
276
|
-
lastRoutineSpawnRunId = undefined;
|
|
277
|
-
lastRoutineSpawnNoop = false;
|
|
323
|
+
resetRoutineSpawnMarkers();
|
|
278
324
|
let result;
|
|
279
325
|
try {
|
|
280
326
|
result = executeRoutineAction(doc, action, projectId, dryRun, scheduledAt);
|
|
@@ -288,6 +334,8 @@ function executeRoutine(routine, projectId, dryRun, scheduledAt = new Date()) {
|
|
|
288
334
|
jobRunIds.push(runId);
|
|
289
335
|
if (lastRoutineSpawnReason)
|
|
290
336
|
reasons.push(lastRoutineSpawnReason);
|
|
337
|
+
if (result === "skipped" && lastRoutineSpawnBusy)
|
|
338
|
+
busySkipped = true;
|
|
291
339
|
if (multiple)
|
|
292
340
|
process.stdout.write(` action ${index}/${actions.length}: ${result}\n`);
|
|
293
341
|
return result;
|
|
@@ -300,6 +348,7 @@ function executeRoutine(routine, projectId, dryRun, scheduledAt = new Date()) {
|
|
|
300
348
|
...(multiple ? { actionResults } : {}),
|
|
301
349
|
jobRunIds: [...new Set(jobRunIds)],
|
|
302
350
|
...(reasons.length ? { reason: reasons.join("; ") } : {}),
|
|
351
|
+
busySkipped,
|
|
303
352
|
};
|
|
304
353
|
}
|
|
305
354
|
// ================================
|
|
@@ -318,29 +367,27 @@ export function formatRoutineLastRun(entry) {
|
|
|
318
367
|
return "-";
|
|
319
368
|
return entry.last_result ? `${entry.last_run} (${entry.last_result})` : entry.last_run;
|
|
320
369
|
}
|
|
370
|
+
export function printRoutinePaths(opts) {
|
|
371
|
+
try {
|
|
372
|
+
const paths = resolveRoutinePaths(opts);
|
|
373
|
+
process.stdout.write(`project: ${paths.projectId}\n`);
|
|
374
|
+
process.stdout.write(`routines: ${paths.routinesPath}\n`);
|
|
375
|
+
process.stdout.write(`state: ${paths.statePath}\n`);
|
|
376
|
+
process.stdout.write(`runs: ${paths.runsPath}\n`);
|
|
377
|
+
const files = listFilesRecursive(paths.routinesPath).filter(isRoutineYamlFile).sort();
|
|
378
|
+
for (const filePath of files) {
|
|
379
|
+
process.stdout.write(` ${filePath}\n`);
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
catch (error) {
|
|
383
|
+
printCommandError(error);
|
|
384
|
+
}
|
|
385
|
+
}
|
|
321
386
|
export function registerRoutineCommands(program) {
|
|
322
387
|
const routine = program
|
|
323
388
|
.command("routine")
|
|
324
389
|
.description("Periodic task execution from rtn-*.yaml definitions");
|
|
325
|
-
|
|
326
|
-
const whereCmd = routine.command("where").description("Print resolved routine paths and files");
|
|
327
|
-
addProjectOption(whereCmd);
|
|
328
|
-
whereCmd.action((opts) => {
|
|
329
|
-
try {
|
|
330
|
-
const paths = resolveRoutinePaths(opts);
|
|
331
|
-
process.stdout.write(`project: ${paths.projectId}\n`);
|
|
332
|
-
process.stdout.write(`routines: ${paths.routinesPath}\n`);
|
|
333
|
-
process.stdout.write(`state: ${paths.statePath}\n`);
|
|
334
|
-
process.stdout.write(`runs: ${paths.runsPath}\n`);
|
|
335
|
-
const files = listFilesRecursive(paths.routinesPath).filter(isRoutineYamlFile).sort();
|
|
336
|
-
for (const filePath of files) {
|
|
337
|
-
process.stdout.write(` ${filePath}\n`);
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
catch (error) {
|
|
341
|
-
printCommandError(error);
|
|
342
|
-
}
|
|
343
|
-
});
|
|
390
|
+
registerDeprecatedWhereAlias(routine, printRoutinePaths);
|
|
344
391
|
// --- validate ---
|
|
345
392
|
const validateCmd = routine.command("validate").description("Validate rtn-*.yaml definitions");
|
|
346
393
|
addProjectOption(validateCmd);
|
|
@@ -386,15 +433,9 @@ export function registerRoutineCommands(program) {
|
|
|
386
433
|
interval: doc.interval ?? doc.trigger?.cron ?? "-",
|
|
387
434
|
kind: routineActionKindLabel(doc.action),
|
|
388
435
|
lastRun: formatRoutineLastRun(state.routines[doc.id]),
|
|
389
|
-
due: doc.enabled
|
|
390
|
-
? "
|
|
391
|
-
:
|
|
392
|
-
? cronOccurrences(doc, state.routines[doc.id]?.last_scheduled_for, now).length > 0
|
|
393
|
-
? "due"
|
|
394
|
-
: "-"
|
|
395
|
-
: isRoutineDue(doc, state.routines[doc.id]?.last_run, now)
|
|
396
|
-
? "due"
|
|
397
|
-
: "-",
|
|
436
|
+
due: doc.enabled !== false && isRoutineEntryDue(doc, state.routines[doc.id], now)
|
|
437
|
+
? "due"
|
|
438
|
+
: "-",
|
|
398
439
|
}));
|
|
399
440
|
const idWidth = Math.max(2, ...rows.map((row) => row.id.length));
|
|
400
441
|
for (const row of rows) {
|
|
@@ -409,6 +450,44 @@ export function registerRoutineCommands(program) {
|
|
|
409
450
|
printCommandError(error);
|
|
410
451
|
}
|
|
411
452
|
});
|
|
453
|
+
// --- status ---
|
|
454
|
+
const statusCmd = routine
|
|
455
|
+
.command("status")
|
|
456
|
+
.description("Show each routine's state, busy-skip retries, and recent runs");
|
|
457
|
+
addProjectOption(statusCmd);
|
|
458
|
+
statusCmd.option("--id <routineId>", "Show only this routine");
|
|
459
|
+
statusCmd.option("--limit <count>", "Number of recent runs to show per routine", "5");
|
|
460
|
+
statusCmd.action((opts) => {
|
|
461
|
+
try {
|
|
462
|
+
const limit = Number(opts.limit);
|
|
463
|
+
if (!Number.isSafeInteger(limit) || limit < 0) {
|
|
464
|
+
throw new Error(`--limit must be a non-negative integer (got "${String(opts.limit)}")`);
|
|
465
|
+
}
|
|
466
|
+
const paths = resolveRoutinePaths(opts);
|
|
467
|
+
const { routines, errors } = loadRoutines(paths.routinesPath);
|
|
468
|
+
for (const message of errors) {
|
|
469
|
+
process.stderr.write(`ERROR: ${message}\n`);
|
|
470
|
+
}
|
|
471
|
+
if (errors.length > 0)
|
|
472
|
+
process.exitCode = 1;
|
|
473
|
+
const routineId = typeof opts.id === "string" ? opts.id.trim() : "";
|
|
474
|
+
const targets = routineId ? routines.filter((entry) => entry.doc.id === routineId) : routines;
|
|
475
|
+
if (routineId && targets.length === 0) {
|
|
476
|
+
throw new Error(`Routine not found: ${routineId} (in ${paths.routinesPath})`);
|
|
477
|
+
}
|
|
478
|
+
migrateRoutineStorage(paths.routinesPath);
|
|
479
|
+
const state = readRoutineState(paths.statePath);
|
|
480
|
+
const history = readRoutineHistoryLenient(paths.runsPath);
|
|
481
|
+
const now = new Date();
|
|
482
|
+
for (const { doc } of targets) {
|
|
483
|
+
const lines = formatRoutineStatus(doc, state.routines[doc.id], history, now, limit);
|
|
484
|
+
process.stdout.write(`${lines.join("\n")}\n`);
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
catch (error) {
|
|
488
|
+
printCommandError(error);
|
|
489
|
+
}
|
|
490
|
+
});
|
|
412
491
|
// --- run ---
|
|
413
492
|
const runCmd = routine
|
|
414
493
|
.command("run")
|
|
@@ -454,9 +533,7 @@ export function registerRoutineCommands(program) {
|
|
|
454
533
|
if (entry.doc.trigger) {
|
|
455
534
|
return cronOccurrences(entry.doc, stateEntry?.last_scheduled_for, now).map((scheduledAt) => ({ entry, scheduledAt }));
|
|
456
535
|
}
|
|
457
|
-
return
|
|
458
|
-
? [{ entry, scheduledAt: now }]
|
|
459
|
-
: [];
|
|
536
|
+
return isRoutineEntryDue(entry.doc, stateEntry, now) ? [{ entry, scheduledAt: now }] : [];
|
|
460
537
|
});
|
|
461
538
|
}
|
|
462
539
|
if (selected.length === 0) {
|
|
@@ -474,8 +551,16 @@ export function registerRoutineCommands(program) {
|
|
|
474
551
|
let failed = 0;
|
|
475
552
|
let partial = 0;
|
|
476
553
|
let skipped = 0;
|
|
554
|
+
// busy skip した routine の残りの回(missed_run: all)は、この実行では流さない。
|
|
555
|
+
// 後の回だけ進めると last_scheduled_for が skip した回を越え、その回が流し直されなくなる。
|
|
556
|
+
const busyRoutineIds = new Set();
|
|
477
557
|
for (const selectedRun of selected) {
|
|
478
558
|
const { entry, scheduledAt } = selectedRun;
|
|
559
|
+
if (busyRoutineIds.has(entry.doc.id)) {
|
|
560
|
+
process.stdout.write(`[routine] deferred ${entry.doc.id} ${scheduledAt.toISOString()}: earlier occurrence skipped as busy\n`);
|
|
561
|
+
continue;
|
|
562
|
+
}
|
|
563
|
+
const previousEntry = state.routines[entry.doc.id];
|
|
479
564
|
const startedAt = nowUtcIsoSeconds();
|
|
480
565
|
// 実行の試行自体を last_run として先に記録する。失敗した routine が次の
|
|
481
566
|
// 発火まで再試行されない代わりに、失敗が高頻度で連続発火することを防ぐ。
|
|
@@ -493,6 +578,7 @@ export function registerRoutineCommands(program) {
|
|
|
493
578
|
result: "failure",
|
|
494
579
|
jobRunIds: [],
|
|
495
580
|
reason: error instanceof Error ? error.message : String(error),
|
|
581
|
+
busySkipped: false,
|
|
496
582
|
};
|
|
497
583
|
}
|
|
498
584
|
const { result } = execution;
|
|
@@ -505,8 +591,14 @@ export function registerRoutineCommands(program) {
|
|
|
505
591
|
process.stdout.write(`[routine] skipped ${entry.doc.id}: job action skipped\n`);
|
|
506
592
|
}
|
|
507
593
|
if (!dryRun) {
|
|
508
|
-
|
|
594
|
+
const settlement = settleRoutineSkip(entry.doc, previousEntry, recordRoutineCompletion(state.routines[entry.doc.id], result, execution.reason, execution.actionResults), result, execution.busySkipped);
|
|
595
|
+
state.routines[entry.doc.id] = settlement.entry;
|
|
509
596
|
writeRoutineState(paths, state);
|
|
597
|
+
if (settlement.retryPending) {
|
|
598
|
+
busyRoutineIds.add(entry.doc.id);
|
|
599
|
+
process.stdout.write(`[routine] ${entry.doc.id}: busy skip ${settlement.entry.busy_skip_count}/${ROUTINE_BUSY_RETRY_LIMIT}, retried on the next routine run --due\n`);
|
|
600
|
+
}
|
|
601
|
+
const historyReason = settlement.entry.last_reason;
|
|
510
602
|
const history = {
|
|
511
603
|
version: 1,
|
|
512
604
|
routine_id: entry.doc.id,
|
|
@@ -515,7 +607,9 @@ export function registerRoutineCommands(program) {
|
|
|
515
607
|
completed_at: nowUtcIsoSeconds(),
|
|
516
608
|
result,
|
|
517
609
|
job_run_ids: execution.jobRunIds,
|
|
518
|
-
...(
|
|
610
|
+
...(historyReason ? { reason: historyReason } : {}),
|
|
611
|
+
...(settlement.skipReason ? { skip_reason: settlement.skipReason } : {}),
|
|
612
|
+
...(settlement.retryPending ? { retry_pending: true } : {}),
|
|
519
613
|
};
|
|
520
614
|
appendRoutineRunHistory(paths.runsPath, history);
|
|
521
615
|
recordRoutineFailure(specdojoRootDir(), paths.failuresPath, history);
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import { isRecord, isRoutineEntryDue, } from "./definition.js";
|
|
3
|
+
// routine status が読む履歴。壊れた行は読み飛ばし、状態の表示を止めない(検証は dashboard 側)。
|
|
4
|
+
export function readRoutineHistoryLenient(runsPath) {
|
|
5
|
+
if (!existsSync(runsPath))
|
|
6
|
+
return [];
|
|
7
|
+
const entries = [];
|
|
8
|
+
for (const line of readFileSync(runsPath, "utf8").split(/\r?\n/)) {
|
|
9
|
+
if (!line.trim())
|
|
10
|
+
continue;
|
|
11
|
+
let value;
|
|
12
|
+
try {
|
|
13
|
+
value = JSON.parse(line);
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
18
|
+
if (isRecord(value) &&
|
|
19
|
+
typeof value.routine_id === "string" &&
|
|
20
|
+
typeof value.scheduled_for === "string" &&
|
|
21
|
+
typeof value.started_at === "string" &&
|
|
22
|
+
typeof value.result === "string") {
|
|
23
|
+
entries.push(value);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return entries;
|
|
27
|
+
}
|
|
28
|
+
function formatHistoryEntry(entry) {
|
|
29
|
+
const details = [
|
|
30
|
+
entry.skip_reason,
|
|
31
|
+
entry.retry_pending ? "retry pending" : undefined,
|
|
32
|
+
entry.reason,
|
|
33
|
+
].filter((item) => typeof item === "string" && item.length > 0);
|
|
34
|
+
const suffix = details.length ? ` (${details.join(", ")})` : "";
|
|
35
|
+
return ` ${entry.started_at} scheduled_for=${entry.scheduled_for} ${entry.result}${suffix}`;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* 1 routine ぶんの状態を行の配列で返す。busy skip の流し直し待ちは `busy skips` 行で示し、
|
|
39
|
+
* 直近の履歴には skip の内訳(busy / precondition)と流し直し待ちを添える。
|
|
40
|
+
*/
|
|
41
|
+
export function formatRoutineStatus(doc, entry, history, now, limit) {
|
|
42
|
+
const enabled = doc.enabled !== false;
|
|
43
|
+
const lines = [
|
|
44
|
+
`${doc.id}${doc.name ? ` ${doc.name}` : ""}`,
|
|
45
|
+
` schedule: ${doc.interval ?? (doc.trigger ? `cron ${doc.trigger.cron} (${doc.trigger.timezone})` : "-")}${doc.policy?.missed_run ? ` missed_run=${doc.policy.missed_run}` : ""}`,
|
|
46
|
+
` enabled: ${enabled ? "yes" : "no"}`,
|
|
47
|
+
` due: ${enabled && isRoutineEntryDue(doc, entry, now) ? "due" : "-"}`,
|
|
48
|
+
` last run: ${entry?.last_run ? `${entry.last_run} (${entry.last_result ?? "-"}${entry.last_skip_reason ? `, ${entry.last_skip_reason}` : ""})` : "-"}`,
|
|
49
|
+
];
|
|
50
|
+
if (doc.trigger)
|
|
51
|
+
lines.push(` scheduled to: ${entry?.last_scheduled_for ?? "-"}`);
|
|
52
|
+
if (entry?.last_reason)
|
|
53
|
+
lines.push(` last reason: ${entry.last_reason}`);
|
|
54
|
+
if ((entry?.busy_skip_count ?? 0) > 0) {
|
|
55
|
+
lines.push(` busy skips: ${entry?.busy_skip_count} (retried on the next routine run --due)`);
|
|
56
|
+
}
|
|
57
|
+
const recent = history.filter((item) => item.routine_id === doc.id).slice(-limit);
|
|
58
|
+
lines.push(` recent runs:${recent.length ? "" : " -"}`);
|
|
59
|
+
for (const item of recent)
|
|
60
|
+
lines.push(formatHistoryEntry(item));
|
|
61
|
+
return lines;
|
|
62
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { registerDeprecatedWhereAlias } from "../shared/where-alias.js";
|
|
1
2
|
import { dirname, join, relative, resolve, sep } from "node:path";
|
|
2
3
|
import { existsSync, readdirSync, writeFileSync } from "node:fs";
|
|
3
4
|
import { dump } from "../shared/yaml.js";
|
|
@@ -316,48 +317,46 @@ function registerScheduleStrategyCommands(sch) {
|
|
|
316
317
|
}
|
|
317
318
|
});
|
|
318
319
|
}
|
|
319
|
-
export function
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
const { schedulePath } = resolveSchedulePath(opts);
|
|
327
|
-
process.stdout.write(`schedule-path: ${schedulePath}\n`);
|
|
328
|
-
if (!existsSync(schedulePath)) {
|
|
329
|
-
process.stdout.write(`(path does not exist)\n`);
|
|
330
|
-
return;
|
|
331
|
-
}
|
|
332
|
-
const files = readdirSync(schedulePath)
|
|
333
|
-
.filter((f) => /^sch-.+\.yaml$/.test(f))
|
|
334
|
-
.sort();
|
|
335
|
-
const strategyFiles = files.filter((f) => f.startsWith("sch-strategy-"));
|
|
336
|
-
const trackFiles = files.filter((f) => f.startsWith("sch-track-"));
|
|
337
|
-
process.stdout.write(`strategy-files:\n`);
|
|
338
|
-
if (strategyFiles.length === 0) {
|
|
339
|
-
process.stdout.write(` (none)\n`);
|
|
340
|
-
}
|
|
341
|
-
else {
|
|
342
|
-
for (const f of strategyFiles)
|
|
343
|
-
process.stdout.write(` - ${f}\n`);
|
|
344
|
-
}
|
|
345
|
-
process.stdout.write(`track-files:\n`);
|
|
346
|
-
if (trackFiles.length === 0) {
|
|
347
|
-
process.stdout.write(` (none)\n`);
|
|
348
|
-
}
|
|
349
|
-
else {
|
|
350
|
-
for (const f of trackFiles)
|
|
351
|
-
process.stdout.write(` - ${f}\n`);
|
|
352
|
-
}
|
|
320
|
+
export function printSchedulePaths(opts) {
|
|
321
|
+
try {
|
|
322
|
+
const { schedulePath } = resolveSchedulePath(opts);
|
|
323
|
+
process.stdout.write(`schedule-path: ${schedulePath}\n`);
|
|
324
|
+
if (!existsSync(schedulePath)) {
|
|
325
|
+
process.stdout.write(`(path does not exist)\n`);
|
|
326
|
+
return;
|
|
353
327
|
}
|
|
354
|
-
|
|
355
|
-
|
|
328
|
+
const files = readdirSync(schedulePath)
|
|
329
|
+
.filter((f) => /^sch-.+\.yaml$/.test(f))
|
|
330
|
+
.sort();
|
|
331
|
+
const strategyFiles = files.filter((f) => f.startsWith("sch-strategy-"));
|
|
332
|
+
const trackFiles = files.filter((f) => f.startsWith("sch-track-"));
|
|
333
|
+
process.stdout.write(`strategy-files:\n`);
|
|
334
|
+
if (strategyFiles.length === 0) {
|
|
335
|
+
process.stdout.write(` (none)\n`);
|
|
356
336
|
}
|
|
357
|
-
|
|
337
|
+
else {
|
|
338
|
+
for (const f of strategyFiles)
|
|
339
|
+
process.stdout.write(` - ${f}\n`);
|
|
340
|
+
}
|
|
341
|
+
process.stdout.write(`track-files:\n`);
|
|
342
|
+
if (trackFiles.length === 0) {
|
|
343
|
+
process.stdout.write(` (none)\n`);
|
|
344
|
+
}
|
|
345
|
+
else {
|
|
346
|
+
for (const f of trackFiles)
|
|
347
|
+
process.stdout.write(` - ${f}\n`);
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
catch (error) {
|
|
351
|
+
printCommandError(error);
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
export function registerScheduleCommands(program) {
|
|
355
|
+
const sch = program.command("schedule").description("Schedule build commands");
|
|
356
|
+
registerDeprecatedWhereAlias(sch, printSchedulePaths);
|
|
358
357
|
const bcmd = sch
|
|
359
|
-
.command("build")
|
|
360
|
-
.description("
|
|
358
|
+
.command("build", { hidden: true })
|
|
359
|
+
.description("Internal compatibility entry for build --only schedule");
|
|
361
360
|
addProjectOption(bcmd);
|
|
362
361
|
bcmd.requiredOption("--track <track>", "Track name (e.g. launch)");
|
|
363
362
|
bcmd.option("--force", "Overwrite existing sch-track-<track>.yaml", false);
|
|
@@ -33,3 +33,8 @@ export const APPROACHES = [
|
|
|
33
33
|
"finalize",
|
|
34
34
|
"bootstrap-finalize",
|
|
35
35
|
];
|
|
36
|
+
// Frontier is above expert and requires an explicit tier request or a named agent.
|
|
37
|
+
export const PROFICIENCIES = ["low", "normal", "high", "expert", "frontier"];
|
|
38
|
+
export function isProficiency(value) {
|
|
39
|
+
return PROFICIENCIES.some((proficiency) => proficiency === value);
|
|
40
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { existsSync, mkdirSync, readdirSync, readFileSync, renameSync, rmSync, statSync, utimesSync, } from "node:fs";
|
|
2
2
|
import { spawn } from "node:child_process";
|
|
3
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
3
4
|
import { join } from "node:path";
|
|
4
5
|
import { ensureDir, writeJson } from "./fs.js";
|
|
5
6
|
import { randomHex } from "./random.js";
|
|
@@ -11,6 +12,13 @@ import { nowUtcIsoSeconds } from "./time.js";
|
|
|
11
12
|
export const LOCK_HEARTBEAT_MS = 5_000;
|
|
12
13
|
export const LOCK_STALE_MS = 30_000;
|
|
13
14
|
export const LOCK_POLL_MS = 200;
|
|
15
|
+
// Propagate only locks held by this async operation to Git hooks, without changing process.env.
|
|
16
|
+
export const GIT_LOCK_TOKENS_ENV = "SPECDOJO_GIT_LOCK_TOKENS";
|
|
17
|
+
const heldLocks = new AsyncLocalStorage();
|
|
18
|
+
export function gitLockEnvironment() {
|
|
19
|
+
const locks = heldLocks.getStore();
|
|
20
|
+
return locks?.length ? { [GIT_LOCK_TOKENS_ENV]: locks.map((lock) => lock.token).join(",") } : {};
|
|
21
|
+
}
|
|
14
22
|
// The lock directory of the project whose exec-run lock this process holds. Gates that are
|
|
15
23
|
// reached through many call paths (parent validations) read it instead of having the directory
|
|
16
24
|
// threaded through every caller. One `exec run` process serves one project.
|
|
@@ -231,7 +239,7 @@ export class CrossProcessMutex {
|
|
|
231
239
|
try {
|
|
232
240
|
const handle = await acquirePoolSlot(this.poolDir, 1, this.owner, this.options);
|
|
233
241
|
try {
|
|
234
|
-
return await
|
|
242
|
+
return await heldLocks.run([...(heldLocks.getStore() ?? []), handle], fn);
|
|
235
243
|
}
|
|
236
244
|
finally {
|
|
237
245
|
releaseLock(handle);
|
|
@@ -4,6 +4,8 @@ import path from "node:path";
|
|
|
4
4
|
const SKIP_ENV_NAME = "SPECDOJO_SKIP_DIST_FRESHNESS_CHECK";
|
|
5
5
|
const SKIP_ENV_VALUES = new Set(["1", "true", "yes"]);
|
|
6
6
|
const IGNORED_DIRECTORY_NAMES = new Set(["node_modules", ".git"]);
|
|
7
|
+
// A failed tsc may still emit newer JS. A successful clean build removes this marker with dist/.
|
|
8
|
+
export const DIST_BUILD_FAILURE_MARKER = ".specdojo-build-failed";
|
|
7
9
|
/** 検証の沈黙した省略を避けるため、exec 系だけは警告ではなく中断する。 */
|
|
8
10
|
const BLOCKING_COMMANDS = new Set(["exec"]);
|
|
9
11
|
function findNewestFile(rootDir, extension) {
|
|
@@ -44,11 +46,13 @@ export function inspectBuildFreshness(packageRoot) {
|
|
|
44
46
|
if (!newestDist) {
|
|
45
47
|
return { status: "no-dist-output", packageRoot, newestSourcePath: newestSource.filePath };
|
|
46
48
|
}
|
|
49
|
+
const buildFailed = existsSync(path.join(packageRoot, "dist", DIST_BUILD_FAILURE_MARKER));
|
|
47
50
|
return {
|
|
48
|
-
status: newestSource.mtimeMs > newestDist.mtimeMs ? "stale" : "up-to-date",
|
|
51
|
+
status: buildFailed || newestSource.mtimeMs > newestDist.mtimeMs ? "stale" : "up-to-date",
|
|
49
52
|
packageRoot,
|
|
50
53
|
newestSourcePath: newestSource.filePath,
|
|
51
54
|
newestDistPath: newestDist.filePath,
|
|
55
|
+
...(buildFailed ? { buildFailed: true } : {}),
|
|
52
56
|
};
|
|
53
57
|
}
|
|
54
58
|
/**
|
|
@@ -77,7 +81,9 @@ function toDisplayPath(packageRoot, filePath) {
|
|
|
77
81
|
function buildMessage(result, isBlocking) {
|
|
78
82
|
const detail = result.status === "no-dist-output"
|
|
79
83
|
? "dist/ が存在しない"
|
|
80
|
-
:
|
|
84
|
+
: result.buildFailed
|
|
85
|
+
? "直前の統合後ビルドが失敗した"
|
|
86
|
+
: `src が dist より新しい (src: ${toDisplayPath(result.packageRoot, result.newestSourcePath)}, dist: ${toDisplayPath(result.packageRoot, result.newestDistPath)})`;
|
|
81
87
|
const head = isBlocking
|
|
82
88
|
? `specdojo: 中断: dist ビルドが古い: ${detail}`
|
|
83
89
|
: `specdojo: 警告: dist ビルドが古い: ${detail}`;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { gitLockEnvironment } from "./cross-process-lock.js";
|
|
1
2
|
export const GIT_LOCAL_ENV_VARS = [
|
|
2
3
|
"GIT_ALTERNATE_OBJECT_DIRECTORIES",
|
|
3
4
|
"GIT_COMMON_DIR",
|
|
@@ -17,7 +18,7 @@ export function removeGitLocalEnvironment(environment) {
|
|
|
17
18
|
delete environment[name];
|
|
18
19
|
}
|
|
19
20
|
export function gitEnvironment() {
|
|
20
|
-
const environment = { ...process.env };
|
|
21
|
+
const environment = { ...process.env, ...gitLockEnvironment() };
|
|
21
22
|
removeGitLocalEnvironment(environment);
|
|
22
23
|
return environment;
|
|
23
24
|
}
|
package/dist/shared/git.js
CHANGED
|
@@ -243,7 +243,9 @@ function abbreviate(value, limit) {
|
|
|
243
243
|
export function summarizeGitArguments(args) {
|
|
244
244
|
const separatorIndex = args.indexOf("--");
|
|
245
245
|
const head = separatorIndex === -1 ? args : args.slice(0, separatorIndex);
|
|
246
|
-
|
|
246
|
+
// 複数行の commit message などは 1 行へ畳む。改行が残ると要約が失敗理由の行から離れ、
|
|
247
|
+
// 出力の最後の行が引数の断片だけになって失敗に気づきにくい(PJR-Y3XS)。
|
|
248
|
+
const parts = head.map((arg) => abbreviate(arg.replace(/\s+/g, " ").trim(), MAX_GIT_ARGUMENT_LENGTH));
|
|
247
249
|
if (separatorIndex !== -1) {
|
|
248
250
|
const pathCount = args.length - separatorIndex - 1;
|
|
249
251
|
parts.push(`-- ${pathCount} ${pathCount === 1 ? "path" : "paths"}`);
|
|
@@ -467,6 +469,47 @@ export function unstageCommitTargets(repoRoot, paths) {
|
|
|
467
469
|
return;
|
|
468
470
|
gitOutput(repoRoot, ["reset", "--quiet", "--", ...unique]);
|
|
469
471
|
}
|
|
472
|
+
// `git commit -- <pathspec>`(--only)は一時 index で commit する。pre-commit hook の整形と
|
|
473
|
+
// `git add`(lefthook の stage_fixed)は一時 index にだけ入り、本来の index には hook 前の内容が
|
|
474
|
+
// 残る。HEAD と作業ツリーは整形後で一致するのに、index だけが整形前を staged として持ち、次の統合を
|
|
475
|
+
// stagedMergeBlocker で止める(PJR-Y3XS)。commit 対象のうち作業ツリーが HEAD と一致するパスだけを
|
|
476
|
+
// HEAD へ戻す。作業ツリーが HEAD と異なるパスは、利用者の作業の可能性があるため触らない。
|
|
477
|
+
// 戻したパス(リポジトリルート起点)を返す。
|
|
478
|
+
export function restoreIndexAfterPathspecCommit(cwd, pathspecs, globals = []) {
|
|
479
|
+
if (pathspecs.length === 0)
|
|
480
|
+
return [];
|
|
481
|
+
const zeroSeparated = (output) => output.split("\0").filter(Boolean);
|
|
482
|
+
const staged = zeroSeparated(gitOutput(cwd, [
|
|
483
|
+
...globals,
|
|
484
|
+
"diff",
|
|
485
|
+
"--cached",
|
|
486
|
+
"--no-renames",
|
|
487
|
+
"--no-relative",
|
|
488
|
+
"--name-only",
|
|
489
|
+
"-z",
|
|
490
|
+
"--",
|
|
491
|
+
...pathspecs,
|
|
492
|
+
]));
|
|
493
|
+
if (staged.length === 0)
|
|
494
|
+
return [];
|
|
495
|
+
const topLiteral = (path) => `:(top,literal)${path}`;
|
|
496
|
+
const differsFromHead = new Set(zeroSeparated(gitOutput(cwd, [
|
|
497
|
+
...globals,
|
|
498
|
+
"diff",
|
|
499
|
+
"--no-renames",
|
|
500
|
+
"--no-relative",
|
|
501
|
+
"--name-only",
|
|
502
|
+
"-z",
|
|
503
|
+
"HEAD",
|
|
504
|
+
"--",
|
|
505
|
+
...staged.map(topLiteral),
|
|
506
|
+
])));
|
|
507
|
+
const restorable = staged.filter((path) => !differsFromHead.has(path));
|
|
508
|
+
if (restorable.length === 0)
|
|
509
|
+
return [];
|
|
510
|
+
gitOutput(cwd, [...globals, "reset", "--quiet", "--", ...restorable.map(topLiteral)]);
|
|
511
|
+
return restorable;
|
|
512
|
+
}
|
|
470
513
|
// A non-fast-forward merge requires a clean index even when staged paths do not overlap the
|
|
471
514
|
// incoming diff. Never reset or commit another operation's staged work on its behalf.
|
|
472
515
|
export function stagedMergeBlocker(repoRoot) {
|
|
@@ -16,6 +16,9 @@ function hasConfiguredPath(config, key) {
|
|
|
16
16
|
}
|
|
17
17
|
export function renderLefthookConfig(config) {
|
|
18
18
|
const commands = [
|
|
19
|
+
" git-lock-warning:",
|
|
20
|
+
" run: node tools/specdojo-pre-commit.mjs git-lock-warning",
|
|
21
|
+
"",
|
|
19
22
|
" prettier:",
|
|
20
23
|
' glob: "*.{md,yaml,yml}"',
|
|
21
24
|
" run: node tools/specdojo-pre-commit.mjs prettier {staged_files}",
|