specdojo 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +65 -0
- package/README.md +77 -18
- package/dist/catalog/build-references.js +144 -0
- package/dist/catalog/build-render.js +32 -0
- package/dist/{catalog-build.js → catalog/build.js} +18 -295
- package/dist/{catalog.js → catalog/catalog.js} +11 -11
- package/dist/{catalog-generate.js → catalog/generate.js} +13 -16
- package/dist/catalog/paths.js +1 -0
- package/dist/{catalog-plan-generate.js → catalog/plan-generate.js} +5 -5
- package/dist/{catalog-plan.js → catalog/plan.js} +9 -9
- package/dist/{catalog-scaffold.js → catalog/scaffold.js} +6 -6
- 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} +103 -37
- package/dist/{orchestrator.js → commands/orchestrator.js} +2 -2
- package/dist/{watch.js → commands/watch.js} +3 -3
- package/dist/dashboard/dashboard-timeline.js +175 -0
- package/dist/{dashboard.js → dashboard/dashboard.js} +16 -549
- package/dist/dashboard/exec-records.js +105 -0
- package/dist/dashboard/routines.js +256 -0
- package/dist/dashboard/shared.js +14 -0
- 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} +7 -7
- package/dist/{devcontainer-command.js → devcontainer/command.js} +5 -3
- package/dist/{devcontainer-scaffold.js → devcontainer/scaffold.js} +94 -2
- package/dist/{doc-index.js → docs/doc-index.js} +3 -3
- package/dist/{frontmatter-namespace.js → docs/frontmatter-namespace.js} +2 -2
- 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} +3 -3
- package/dist/{yaml-pages-command.js → docs/yaml-pages-command.js} +1 -1
- package/dist/{yaml-pages.js → docs/yaml-pages.js} +5 -5
- package/dist/{exec-agent-config.js → exec/agent-config.js} +33 -4
- package/dist/{exec-agent-git-state.js → exec/agent-git-state.js} +1 -1
- package/dist/{exec-agent-protected-config.js → exec/agent-protected-config.js} +1 -1
- package/dist/{exec.js → exec/commands.js} +22 -467
- package/dist/exec/core.js +457 -0
- package/dist/{exec-events.js → exec/events.js} +2 -2
- package/dist/{exec-evidence.js → exec/evidence.js} +11 -6
- package/dist/exec/exec.js +2 -0
- package/dist/exec/format.js +1 -0
- package/dist/{exec-handoff.js → exec/handoff.js} +13 -12
- package/dist/{exec-limit.js → exec/limit.js} +93 -12
- package/dist/{exec-parent-validation.js → exec/parent-validation.js} +4 -4
- package/dist/{exec-pipeline-state.js → exec/pipeline-state.js} +16 -2
- package/dist/{exec-plans.js → exec/plans-core.js} +97 -468
- package/dist/exec/plans-generation.js +249 -0
- package/dist/exec/plans-storage.js +131 -0
- package/dist/exec/plans.js +3 -0
- package/dist/{exec-project.js → exec/project.js} +1 -1
- package/dist/{exec-protection-handoff.js → exec/protection-handoff.js} +3 -3
- package/dist/{exec-register-resume.js → exec/register-resume.js} +2 -2
- package/dist/{exec-register.js → exec/register.js} +92 -9
- package/dist/exec/repo-integration-git.js +23 -0
- package/dist/exec/repo-integration-sync.js +264 -0
- package/dist/{exec-repo-integration.js → exec/repo-integration.js} +13 -287
- package/dist/{exec-repo-trace.js → exec/repo-trace.js} +3 -3
- package/dist/exec/reporter-output.js +206 -0
- package/dist/{exec-reporter.js → exec/reporter.js} +29 -216
- package/dist/{exec-results.js → exec/results.js} +277 -36
- package/dist/exec/run/agent-pipeline.js +276 -0
- package/dist/exec/run/agent.js +583 -0
- package/dist/exec/run/in-place.js +570 -0
- package/dist/exec/run/job.js +746 -0
- package/dist/exec/run/lifecycle-commands.js +530 -0
- package/dist/{exec-run-lock.js → exec/run/lock.js} +4 -3
- package/dist/exec/run/mode-shared.js +140 -0
- package/dist/exec/run/register-command.js +252 -0
- package/dist/exec/run/register-core.js +411 -0
- package/dist/exec/run/register-mode.js +210 -0
- package/dist/exec/run/register-resume.js +398 -0
- package/dist/exec/run/register-state.js +325 -0
- package/dist/exec/run/register-worktree.js +540 -0
- package/dist/exec/run/run.js +11 -0
- package/dist/exec/run/schedule-mode.js +294 -0
- package/dist/exec/run/schedule-prepare.js +366 -0
- package/dist/exec/run/schedule-task.js +599 -0
- package/dist/exec/run/shared.js +449 -0
- package/dist/{exec-schedule-calendar.js → exec/schedule/calendar.js} +1 -1
- package/dist/{exec-schedule-cpm.js → exec/schedule/cpm.js} +2 -2
- package/dist/{exec-schedule-gantt-chart-render.js → exec/schedule/gantt-chart-render.js} +2 -2
- package/dist/exec/schedule/gantt-chart.js +2 -0
- package/dist/{exec-schedule-hash.js → exec/schedule/hash.js} +2 -2
- package/dist/exec/schedule/index.js +1 -0
- package/dist/{exec-schedule-initial.js → exec/schedule/initial.js} +2 -2
- package/dist/{exec-schedule-progress.js → exec/schedule/progress.js} +2 -2
- package/dist/{exec-schedule-ready.js → exec/schedule/ready.js} +2 -2
- package/dist/{exec-schedule.js → exec/schedule/schedule.js} +11 -11
- package/dist/exec/shared.js +63 -0
- package/dist/exec/slot-lock.js +1 -0
- package/dist/{exec-strategy.js → exec/strategy.js} +2 -2
- package/dist/{exec-task-repos.js → exec/task-repos.js} +2 -2
- package/dist/{exec-task-view.js → exec/task-view.js} +4 -4
- package/dist/{exec-trial.js → exec/trial-commands.js} +23 -388
- package/dist/exec/trial-core.js +371 -0
- package/dist/exec/trial.js +2 -0
- package/dist/{exec-worktree-command.js → exec/worktree-command.js} +25 -23
- package/dist/exec/worktree-ops-commit.js +672 -0
- package/dist/exec/worktree-ops-lifecycle.js +297 -0
- package/dist/exec/worktree-ops-merge.js +344 -0
- package/dist/exec/worktree-ops.js +3 -0
- package/dist/exec/worktree.js +305 -0
- package/dist/grade/apply.js +734 -0
- package/dist/grade/command-apply.js +250 -0
- package/dist/grade/command-inspect.js +138 -0
- package/dist/grade/command-plan.js +101 -0
- package/dist/grade/command-shared.js +68 -0
- package/dist/grade/core.js +307 -0
- package/dist/grade/grade.js +19 -0
- package/dist/grade/markdown.js +274 -0
- package/dist/grade/pipeline-state.js +184 -0
- package/dist/grade/plan.js +507 -0
- package/dist/{grade-result.js → grade/result.js} +7 -96
- package/dist/grade/target-discovery.js +265 -0
- package/dist/grade/targets.js +435 -0
- package/dist/{job.js → job/definition.js} +32 -574
- package/dist/job/job.js +568 -0
- package/dist/{kata-command.js → kata/command.js} +4 -4
- package/dist/{kata.js → kata/kata.js} +5 -5
- package/dist/register/approach.js +134 -0
- package/dist/register/command-types.js +1 -0
- package/dist/register/core.js +369 -0
- package/dist/register/create-commands.js +352 -0
- package/dist/{register-date.js → register/date.js} +1 -1
- package/dist/register/derivation.js +163 -0
- package/dist/{register-event-merge.js → register/event-merge.js} +32 -3
- package/dist/{register-events.js → register/events.js} +12 -6
- package/dist/{register-history.js → register/history.js} +7 -6
- package/dist/{register-item.js → register/item.js} +28 -10
- package/dist/register/lifecycle-lock.js +5 -0
- package/dist/register/maintenance-commands.js +193 -0
- package/dist/{register-migrate-timestamps.js → register/migrate-timestamps.js} +3 -3
- package/dist/register/migration.js +268 -0
- package/dist/register/register.js +404 -0
- package/dist/register/renumber.js +341 -0
- package/dist/register/transition-commands.js +248 -0
- package/dist/register/update.js +230 -0
- package/dist/register/views.js +296 -0
- package/dist/{review-grade.js → review/grade.js} +2 -2
- package/dist/{review-plan.js → review/plan.js} +5 -5
- package/dist/routine/definition.js +401 -0
- package/dist/{routine.js → routine/routine.js} +50 -419
- package/dist/{schedule-approach.js → schedule/approach.js} +9 -9
- package/dist/{schedule-build.js → schedule/build.js} +7 -4
- package/dist/{schedule.js → schedule/schedule.js} +9 -9
- package/dist/schedule/strategy-generate-document.js +273 -0
- package/dist/schedule/strategy-generate-scope.js +199 -0
- package/dist/schedule/strategy-generate.js +348 -0
- 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/shared/catalog-render.js +115 -0
- 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 +316 -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} +3 -1
- package/dist/shared/random.js +4 -0
- package/dist/{exec-schedule-index.js → shared/schedule-index.js} +3 -1
- package/dist/shared/schedule-paths.js +9 -0
- package/dist/{specdojo-config.js → shared/specdojo-config.js} +96 -9
- package/dist/{exec-shared.js → shared/text.js} +0 -134
- package/dist/shared/time.js +28 -0
- package/dist/shared/yaml.js +28 -0
- package/dist/specdojo.js +22 -22
- package/docs/ja/specdojo/exec-templates/xep-common-conventions-template.md +29 -17
- package/docs/ja/specdojo/exec-templates/xep-register-investigate-template.md +1 -2
- package/docs/ja/specdojo/exec-templates/xep-register-template.md +1 -2
- package/docs/ja/specdojo/exec-templates/xer-template.md +1 -3
- package/docs/ja/specdojo/exec-templates/xrp-job-template.md +6 -4
- package/docs/ja/specdojo/guides/exec-config-guide.md +97 -22
- package/docs/ja/specdojo/guides/exec-operation-guide.md +145 -12
- package/docs/ja/specdojo/guides/exec-worktree-guide.md +2 -0
- package/docs/ja/specdojo/guides/orchestrator-operation-guide.md +51 -18
- package/docs/ja/specdojo/guides/quick-start-guide.md +81 -16
- package/docs/ja/specdojo/guides/register-operation-guide.md +2 -1
- package/docs/ja/specdojo/guides/remote-host-development-guide.md +10 -1
- package/docs/ja/specdojo/guides/review-guide.md +1 -1
- package/docs/ja/specdojo/guides/routine-operation-guide.md +6 -6
- package/docs/ja/specdojo/guides/use-case-guide.md +1 -1
- package/docs/ja/specdojo/references/command-reference.md +52 -28
- package/docs/ja/specdojo/rulebooks/pjr-rulebook.md +17 -11
- package/docs/ja/specdojo/standards/job-definition-standard.md +20 -18
- package/docs/ja/specdojo/standards/rulebook-authoring-standard.md +2 -2
- package/docs/ja/specdojo/templates/pjr-derived-items-template.md +22 -0
- package/docs/ja/specdojo/templates/pjr-index-template.md +1 -0
- package/docs/specdojo/schemas/v1/agent-members.schema.yaml +29 -2
- package/docs/specdojo/schemas/v1/exec-defaults.schema.yaml +20 -0
- package/docs/specdojo/schemas/v1/exec-evidence.schema.yaml +23 -0
- package/docs/specdojo/schemas/v1/job-run.schema.yaml +2 -2
- package/docs/specdojo/schemas/v1/job.schema.yaml +7 -0
- package/docs/specdojo/schemas/v1/pipeline-state.schema.yaml +26 -0
- package/docs/specdojo/schemas/v1/register-events.schema.yaml +3 -0
- package/docs/specdojo/schemas/v1/register-item-frontmatter.schema.yaml +70 -7
- package/docs/specdojo/schemas/v1/routine-run.schema.yaml +1 -1
- package/docs/specdojo/schemas/v1/specdojo-config.schema.yaml +1 -1
- package/package.json +4 -5
- package/templates/antigravity/README.md +7 -3
- package/templates/antigravity/agent-members-snippet.yaml +108 -12
- package/templates/antigravity/exec-defaults-snippet.yaml +10 -13
- package/templates/claude/README.md +27 -3
- package/templates/claude/agents/claude-executor.md +0 -1
- package/templates/claude/agents/claude-reporter.md +2 -1
- package/templates/claude/agents/claude-review-executor.md +0 -1
- package/templates/codex/README.md +23 -4
- package/templates/devcontainer/devcontainer.json +2 -2
- package/templates/devcontainer/remote-host/specdojo-tmux.sh.sample +69 -0
- package/templates/devcontainer/remote-host/ssh-config.sample +16 -0
- package/templates/init-agent-members.yaml +75 -25
- package/templates/init-exec-defaults.yaml +26 -8
- package/templates/opencode/README.md +17 -3
- package/templates/opencode/agents/opencode-executor.md +0 -1
- package/templates/opencode/agents/opencode-reporter.md +2 -1
- package/templates/opencode/agents/opencode-review-executor.md +0 -1
- package/dist/exec-run.js +0 -6182
- package/dist/exec-schedule-gantt-chart.js +0 -2
- package/dist/exec-worktree-ops.js +0 -1292
- package/dist/exec-worktree.js +0 -446
- package/dist/grade.js +0 -3193
- package/dist/register.js +0 -2407
- package/dist/schedule-strategy-generate.js +0 -812
- 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/{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
|
@@ -1,411 +1,17 @@
|
|
|
1
1
|
import { spawnSync } from "node:child_process";
|
|
2
2
|
import { appendFileSync, existsSync, mkdirSync, readdirSync, rmSync, statSync } from "node:fs";
|
|
3
|
-
import {
|
|
3
|
+
import { join, resolve } from "node:path";
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
|
-
import { ensureFreshDistBuildForEntry } from "
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import { jobDeclaresReview, jobRunUsesReviewedIntegration, loadJobDefinition, resolveJobPaths, resolveJobReviewAgentNominations, } from "
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
// ================================
|
|
16
|
-
// Interval / due
|
|
17
|
-
// ================================
|
|
18
|
-
const INTERVAL_UNIT_MS = {
|
|
19
|
-
m: 60_000,
|
|
20
|
-
h: 3_600_000,
|
|
21
|
-
d: 86_400_000,
|
|
22
|
-
w: 604_800_000,
|
|
23
|
-
};
|
|
24
|
-
// interval は `<正の整数><単位>` 形式(m: 分, h: 時間, d: 日, w: 週)。
|
|
25
|
-
export function parseIntervalMs(text) {
|
|
26
|
-
const match = text.trim().match(/^([1-9]\d*)(m|h|d|w)$/);
|
|
27
|
-
if (!match) {
|
|
28
|
-
throw new Error(`Invalid interval: "${text}". Use <positive integer><unit> with unit m|h|d|w (e.g. 30m, 6h, 1d, 1w)`);
|
|
29
|
-
}
|
|
30
|
-
return Number.parseInt(match[1], 10) * INTERVAL_UNIT_MS[match[2]];
|
|
31
|
-
}
|
|
32
|
-
// last_run が無い(未実行)または不正な場合は due とみなす。
|
|
33
|
-
export function isRoutineDue(doc, lastRun, now) {
|
|
34
|
-
if (!doc.interval)
|
|
35
|
-
return cronOccurrences(doc, lastRun, now).length > 0;
|
|
36
|
-
if (!lastRun)
|
|
37
|
-
return true;
|
|
38
|
-
const last = new Date(lastRun);
|
|
39
|
-
if (Number.isNaN(last.getTime()))
|
|
40
|
-
return true;
|
|
41
|
-
return now.getTime() - last.getTime() >= parseIntervalMs(doc.interval);
|
|
42
|
-
}
|
|
43
|
-
function parseCronField(text, min, max, label) {
|
|
44
|
-
const result = new Set();
|
|
45
|
-
for (const token of text.split(",")) {
|
|
46
|
-
const [base, stepText] = token.split("/");
|
|
47
|
-
const step = stepText === undefined ? 1 : Number(stepText);
|
|
48
|
-
if (!Number.isSafeInteger(step) || step < 1)
|
|
49
|
-
throw new Error(`Invalid cron ${label}: ${text}`);
|
|
50
|
-
let start;
|
|
51
|
-
let end;
|
|
52
|
-
if (base === "*") {
|
|
53
|
-
start = min;
|
|
54
|
-
end = max;
|
|
55
|
-
}
|
|
56
|
-
else if (base.includes("-")) {
|
|
57
|
-
const parts = base.split("-").map(Number);
|
|
58
|
-
if (parts.length !== 2)
|
|
59
|
-
throw new Error(`Invalid cron ${label}: ${text}`);
|
|
60
|
-
[start, end] = parts;
|
|
61
|
-
}
|
|
62
|
-
else {
|
|
63
|
-
start = Number(base);
|
|
64
|
-
end = start;
|
|
65
|
-
}
|
|
66
|
-
if (!Number.isSafeInteger(start) ||
|
|
67
|
-
!Number.isSafeInteger(end) ||
|
|
68
|
-
start < min ||
|
|
69
|
-
end > max ||
|
|
70
|
-
start > end) {
|
|
71
|
-
throw new Error(`Invalid cron ${label}: ${text}`);
|
|
72
|
-
}
|
|
73
|
-
for (let value = start; value <= end; value += step)
|
|
74
|
-
result.add(value);
|
|
75
|
-
}
|
|
76
|
-
return result;
|
|
77
|
-
}
|
|
78
|
-
export function parseCronExpression(expression) {
|
|
79
|
-
const fields = expression.trim().split(/\s+/);
|
|
80
|
-
if (fields.length !== 5)
|
|
81
|
-
throw new Error(`Invalid cron expression: "${expression}" (expected 5 fields)`);
|
|
82
|
-
return [
|
|
83
|
-
parseCronField(fields[0], 0, 59, "minute"),
|
|
84
|
-
parseCronField(fields[1], 0, 23, "hour"),
|
|
85
|
-
parseCronField(fields[2], 1, 31, "day-of-month"),
|
|
86
|
-
parseCronField(fields[3], 1, 12, "month"),
|
|
87
|
-
parseCronField(fields[4], 0, 6, "day-of-week"),
|
|
88
|
-
];
|
|
89
|
-
}
|
|
90
|
-
function zonedParts(date, timezone) {
|
|
91
|
-
const parts = new Intl.DateTimeFormat("en-US", {
|
|
92
|
-
timeZone: timezone,
|
|
93
|
-
minute: "numeric",
|
|
94
|
-
hour: "numeric",
|
|
95
|
-
day: "numeric",
|
|
96
|
-
month: "numeric",
|
|
97
|
-
weekday: "short",
|
|
98
|
-
hourCycle: "h23",
|
|
99
|
-
}).formatToParts(date);
|
|
100
|
-
const value = (type) => parts.find((part) => part.type === type)?.value ?? "";
|
|
101
|
-
const weekday = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"].indexOf(value("weekday"));
|
|
102
|
-
return [
|
|
103
|
-
Number(value("minute")),
|
|
104
|
-
Number(value("hour")),
|
|
105
|
-
Number(value("day")),
|
|
106
|
-
Number(value("month")),
|
|
107
|
-
weekday,
|
|
108
|
-
];
|
|
109
|
-
}
|
|
110
|
-
export function cronMatches(expression, timezone, date) {
|
|
111
|
-
const fields = parseCronExpression(expression);
|
|
112
|
-
const parts = zonedParts(date, timezone);
|
|
113
|
-
return fields.every((field, index) => field.has(parts[index]));
|
|
114
|
-
}
|
|
115
|
-
const MAX_CRON_LOOKBACK_MINUTES = 366 * 24 * 60;
|
|
116
|
-
export function cronOccurrences(doc, lastScheduledFor, now) {
|
|
117
|
-
if (!doc.trigger)
|
|
118
|
-
return [];
|
|
119
|
-
const nowMinute = new Date(Math.floor(now.getTime() / 60_000) * 60_000);
|
|
120
|
-
const parsedLast = lastScheduledFor ? new Date(lastScheduledFor) : null;
|
|
121
|
-
if (parsedLast && Number.isNaN(parsedLast.getTime()))
|
|
122
|
-
return cronOccurrences(doc, undefined, now);
|
|
123
|
-
if (doc.policy?.missed_run === "skip") {
|
|
124
|
-
const lastMinute = parsedLast
|
|
125
|
-
? Math.floor(parsedLast.getTime() / 60_000) * 60_000
|
|
126
|
-
: Number.NEGATIVE_INFINITY;
|
|
127
|
-
return nowMinute.getTime() > lastMinute &&
|
|
128
|
-
cronMatches(doc.trigger.cron, doc.trigger.timezone, nowMinute)
|
|
129
|
-
? [nowMinute]
|
|
130
|
-
: [];
|
|
131
|
-
}
|
|
132
|
-
if (!parsedLast) {
|
|
133
|
-
for (let offset = 0; offset <= MAX_CRON_LOOKBACK_MINUTES; offset++) {
|
|
134
|
-
const candidate = new Date(nowMinute.getTime() - offset * 60_000);
|
|
135
|
-
if (cronMatches(doc.trigger.cron, doc.trigger.timezone, candidate))
|
|
136
|
-
return [candidate];
|
|
137
|
-
}
|
|
138
|
-
return [];
|
|
139
|
-
}
|
|
140
|
-
const occurrences = [];
|
|
141
|
-
let cursor = Math.floor(parsedLast.getTime() / 60_000) * 60_000 + 60_000;
|
|
142
|
-
const maxStart = nowMinute.getTime() - MAX_CRON_LOOKBACK_MINUTES * 60_000;
|
|
143
|
-
if (cursor < maxStart)
|
|
144
|
-
cursor = maxStart;
|
|
145
|
-
for (; cursor <= nowMinute.getTime(); cursor += 60_000) {
|
|
146
|
-
const candidate = new Date(cursor);
|
|
147
|
-
if (cronMatches(doc.trigger.cron, doc.trigger.timezone, candidate))
|
|
148
|
-
occurrences.push(candidate);
|
|
149
|
-
if (occurrences.length > 1000)
|
|
150
|
-
throw new Error(`Too many missed cron occurrences for ${doc.id}`);
|
|
151
|
-
}
|
|
152
|
-
return doc.policy?.missed_run === "all" ? occurrences : occurrences.slice(-1);
|
|
153
|
-
}
|
|
154
|
-
export function isoWeek(date, timezone) {
|
|
155
|
-
const local = new Intl.DateTimeFormat("en-CA", {
|
|
156
|
-
timeZone: timezone,
|
|
157
|
-
year: "numeric",
|
|
158
|
-
month: "2-digit",
|
|
159
|
-
day: "2-digit",
|
|
160
|
-
}).format(date);
|
|
161
|
-
const [year, month, day] = local.split("-").map(Number);
|
|
162
|
-
const value = new Date(Date.UTC(year, month - 1, day));
|
|
163
|
-
const weekday = value.getUTCDay() || 7;
|
|
164
|
-
value.setUTCDate(value.getUTCDate() + 4 - weekday);
|
|
165
|
-
const weekYear = value.getUTCFullYear();
|
|
166
|
-
const first = new Date(Date.UTC(weekYear, 0, 1));
|
|
167
|
-
const week = Math.ceil(((value.getTime() - first.getTime()) / 86_400_000 + 1) / 7);
|
|
168
|
-
return `${weekYear}-W${String(week).padStart(2, "0")}`;
|
|
169
|
-
}
|
|
170
|
-
// ================================
|
|
171
|
-
// Validation
|
|
172
|
-
// ================================
|
|
173
|
-
function isRecord(value) {
|
|
174
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
175
|
-
}
|
|
176
|
-
function parseRoutineAction(value, fieldName, errors) {
|
|
177
|
-
if (!isRecord(value)) {
|
|
178
|
-
errors.push(`${fieldName} must be a mapping with kind`);
|
|
179
|
-
return undefined;
|
|
180
|
-
}
|
|
181
|
-
const kind = typeof value.kind === "string" ? value.kind : "";
|
|
182
|
-
if (kind === "specdojo") {
|
|
183
|
-
const unknownKeys = Object.keys(value).filter((key) => key !== "kind" && key !== "args");
|
|
184
|
-
if (unknownKeys.length > 0) {
|
|
185
|
-
errors.push(`${fieldName} has unknown key(s): ${unknownKeys.sort().join(", ")}`);
|
|
186
|
-
}
|
|
187
|
-
const args = value.args;
|
|
188
|
-
if (!Array.isArray(args) ||
|
|
189
|
-
args.length === 0 ||
|
|
190
|
-
args.some((item) => typeof item !== "string" || item.length === 0)) {
|
|
191
|
-
errors.push(`${fieldName}.args must be a non-empty list of strings`);
|
|
192
|
-
return undefined;
|
|
193
|
-
}
|
|
194
|
-
if (args.includes("exec") || args.includes("--project")) {
|
|
195
|
-
errors.push(`${fieldName}.args must not include exec or --project (project is appended)`);
|
|
196
|
-
return undefined;
|
|
197
|
-
}
|
|
198
|
-
return { kind: "specdojo", args: args };
|
|
199
|
-
}
|
|
200
|
-
const unknownKeys = Object.keys(value).filter((key) => key !== "kind" && key !== "job" && key !== "inputs" && key !== "commit");
|
|
201
|
-
if (unknownKeys.length > 0) {
|
|
202
|
-
errors.push(`${fieldName} has unknown key(s): ${unknownKeys.sort().join(", ")}`);
|
|
203
|
-
}
|
|
204
|
-
if (kind !== "job") {
|
|
205
|
-
errors.push(`${fieldName}.kind must be job or specdojo (got "${kind}")`);
|
|
206
|
-
}
|
|
207
|
-
if (typeof value.job !== "string" || !/^job-[a-z0-9][a-z0-9-]*$/.test(value.job)) {
|
|
208
|
-
errors.push(`${fieldName}.job must match job-<slug>`);
|
|
209
|
-
}
|
|
210
|
-
if (value.inputs !== undefined &&
|
|
211
|
-
(!isRecord(value.inputs) ||
|
|
212
|
-
Object.values(value.inputs).some((item) => typeof item !== "string"))) {
|
|
213
|
-
errors.push(`${fieldName}.inputs must be a mapping of string values`);
|
|
214
|
-
}
|
|
215
|
-
if (value.commit !== undefined && typeof value.commit !== "boolean") {
|
|
216
|
-
errors.push(`${fieldName}.commit must be a boolean`);
|
|
217
|
-
}
|
|
218
|
-
return {
|
|
219
|
-
kind: "job",
|
|
220
|
-
job: typeof value.job === "string" ? value.job : "",
|
|
221
|
-
...(isRecord(value.inputs) ? { inputs: value.inputs } : {}),
|
|
222
|
-
...(typeof value.commit === "boolean" ? { commit: value.commit } : {}),
|
|
223
|
-
};
|
|
224
|
-
}
|
|
225
|
-
// rtn-*.yaml 1 ファイルぶんを検証し、妥当なら RoutineDoc として返す。
|
|
226
|
-
// id はファイル名(拡張子なし)と一致させ、doc-index と同じ「ファイル名 = id」規約に揃える。
|
|
227
|
-
export function parseRoutineDoc(value, fileName) {
|
|
228
|
-
const errors = [];
|
|
229
|
-
if (!isRecord(value)) {
|
|
230
|
-
return { errors: [`${fileName}: routine file must be a YAML mapping`] };
|
|
231
|
-
}
|
|
232
|
-
const expectedId = fileName.replace(/\.(yaml|yml)$/, "");
|
|
233
|
-
const id = typeof value.id === "string" ? value.id.trim() : "";
|
|
234
|
-
if (!id) {
|
|
235
|
-
errors.push("id is required");
|
|
236
|
-
}
|
|
237
|
-
else {
|
|
238
|
-
if (!/^rtn-[a-z0-9][a-z0-9-]*$/.test(id)) {
|
|
239
|
-
errors.push(`id "${id}" must match rtn-<slug> (lowercase letters, digits, hyphens)`);
|
|
240
|
-
}
|
|
241
|
-
if (id !== expectedId) {
|
|
242
|
-
errors.push(`id "${id}" must match the file name base "${expectedId}"`);
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
if (value.enabled !== undefined && typeof value.enabled !== "boolean") {
|
|
246
|
-
errors.push("enabled must be a boolean");
|
|
247
|
-
}
|
|
248
|
-
const interval = typeof value.interval === "string" ? value.interval.trim() : "";
|
|
249
|
-
const trigger = isRecord(value.trigger) ? value.trigger : undefined;
|
|
250
|
-
if (!interval && !trigger) {
|
|
251
|
-
errors.push("interval or trigger is required");
|
|
252
|
-
}
|
|
253
|
-
if (interval && trigger)
|
|
254
|
-
errors.push("specify either interval or trigger, not both");
|
|
255
|
-
if (interval) {
|
|
256
|
-
try {
|
|
257
|
-
parseIntervalMs(interval);
|
|
258
|
-
}
|
|
259
|
-
catch (error) {
|
|
260
|
-
errors.push(error instanceof Error ? error.message : String(error));
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
let parsedTrigger;
|
|
264
|
-
if (trigger) {
|
|
265
|
-
const cron = typeof trigger.cron === "string" ? trigger.cron.trim() : "";
|
|
266
|
-
const timezone = typeof trigger.timezone === "string" ? trigger.timezone.trim() : "";
|
|
267
|
-
if (!cron)
|
|
268
|
-
errors.push("trigger.cron is required");
|
|
269
|
-
else {
|
|
270
|
-
try {
|
|
271
|
-
parseCronExpression(cron);
|
|
272
|
-
}
|
|
273
|
-
catch (error) {
|
|
274
|
-
errors.push(error instanceof Error ? error.message : String(error));
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
if (!timezone)
|
|
278
|
-
errors.push("trigger.timezone is required");
|
|
279
|
-
else {
|
|
280
|
-
try {
|
|
281
|
-
new Intl.DateTimeFormat("en-US", { timeZone: timezone }).format();
|
|
282
|
-
}
|
|
283
|
-
catch {
|
|
284
|
-
errors.push(`Invalid trigger.timezone: ${timezone}`);
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
if (cron && timezone)
|
|
288
|
-
parsedTrigger = { cron, timezone };
|
|
289
|
-
}
|
|
290
|
-
let policy;
|
|
291
|
-
if (value.policy !== undefined) {
|
|
292
|
-
if (!isRecord(value.policy))
|
|
293
|
-
errors.push("policy must be a mapping");
|
|
294
|
-
else {
|
|
295
|
-
const missed = value.policy.missed_run;
|
|
296
|
-
const overlap = value.policy.overlap;
|
|
297
|
-
if (missed !== undefined && missed !== "skip" && missed !== "latest" && missed !== "all") {
|
|
298
|
-
errors.push("policy.missed_run must be skip, latest, or all");
|
|
299
|
-
}
|
|
300
|
-
if (overlap !== undefined && overlap !== "skip")
|
|
301
|
-
errors.push("policy.overlap must be skip");
|
|
302
|
-
policy = {
|
|
303
|
-
...(missed === "skip" || missed === "latest" || missed === "all"
|
|
304
|
-
? { missed_run: missed }
|
|
305
|
-
: {}),
|
|
306
|
-
...(overlap === "skip" ? { overlap } : {}),
|
|
307
|
-
};
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
let action;
|
|
311
|
-
if (Array.isArray(value.action)) {
|
|
312
|
-
if (value.action.length === 0)
|
|
313
|
-
errors.push("action must contain at least one action");
|
|
314
|
-
const parsed = value.action.map((item, index) => parseRoutineAction(item, `action[${index}]`, errors));
|
|
315
|
-
if (parsed.every((item) => item !== undefined))
|
|
316
|
-
action = parsed;
|
|
317
|
-
}
|
|
318
|
-
else {
|
|
319
|
-
action = parseRoutineAction(value.action, "action", errors);
|
|
320
|
-
}
|
|
321
|
-
if (errors.length > 0 || action === undefined) {
|
|
322
|
-
return { errors: errors.map((message) => `${fileName}: ${message}`) };
|
|
323
|
-
}
|
|
324
|
-
const doc = {
|
|
325
|
-
id,
|
|
326
|
-
...(typeof value.name === "string" ? { name: value.name } : {}),
|
|
327
|
-
...(typeof value.description === "string" ? { description: value.description } : {}),
|
|
328
|
-
...(typeof value.enabled === "boolean" ? { enabled: value.enabled } : {}),
|
|
329
|
-
...(interval ? { interval } : {}),
|
|
330
|
-
...(parsedTrigger ? { trigger: parsedTrigger } : {}),
|
|
331
|
-
...(policy ? { policy } : {}),
|
|
332
|
-
action,
|
|
333
|
-
};
|
|
334
|
-
return { doc, errors: [] };
|
|
335
|
-
}
|
|
336
|
-
// ================================
|
|
337
|
-
// Path resolution / loading
|
|
338
|
-
// ================================
|
|
339
|
-
export function resolveRoutinePaths(opts) {
|
|
340
|
-
loadEnv();
|
|
341
|
-
const { config, configPath } = loadConfig();
|
|
342
|
-
const baseDir = specdojoRootDir();
|
|
343
|
-
if (!config) {
|
|
344
|
-
throw new Error(`routine commands require specdojo.config.json.\nRun: specdojo config init`);
|
|
345
|
-
}
|
|
346
|
-
const projectId = opts.project?.trim() ||
|
|
347
|
-
process.env.SPECDOJO_PROJECT?.trim() ||
|
|
348
|
-
config.current_project?.trim() ||
|
|
349
|
-
Object.keys(config.projects)[0] ||
|
|
350
|
-
"";
|
|
351
|
-
if (!projectId) {
|
|
352
|
-
throw new Error(`No project specified. Use --project <id> or SPECDOJO_PROJECT.`);
|
|
353
|
-
}
|
|
354
|
-
const project = config.projects[projectId];
|
|
355
|
-
if (!project) {
|
|
356
|
-
throw new Error(`Unknown project: ${projectId} (check ${configPath})`);
|
|
357
|
-
}
|
|
358
|
-
const routinesPath = getProjectRoutinesPath(project);
|
|
359
|
-
if (!routinesPath) {
|
|
360
|
-
throw new Error(`routines_path not set for project '${projectId}' in ${configPath}.\n` +
|
|
361
|
-
`Add "routines_path": "<path>" to the project config.`);
|
|
362
|
-
}
|
|
363
|
-
const absRoutinesPath = resolve(baseDir, routinesPath);
|
|
364
|
-
const generatedPath = join(absRoutinesPath, "generated");
|
|
365
|
-
return {
|
|
366
|
-
projectId,
|
|
367
|
-
routinesPath: absRoutinesPath,
|
|
368
|
-
generatedPath,
|
|
369
|
-
statePath: join(generatedPath, "routine-state.json"),
|
|
370
|
-
runsPath: join(generatedPath, "routine-runs.jsonl"),
|
|
371
|
-
};
|
|
372
|
-
}
|
|
373
|
-
function isRoutineYamlFile(filePath) {
|
|
374
|
-
return /^rtn-.+\.(yaml|yml)$/.test(basename(filePath));
|
|
375
|
-
}
|
|
376
|
-
// routines ディレクトリ配下の rtn-*.yaml を読み込む。ファイル列挙順に依存しないよう
|
|
377
|
-
// ソートし、パース失敗・検証エラー・id 重複はファイル名つきで集約して返す。
|
|
378
|
-
export function loadRoutines(routinesPath) {
|
|
379
|
-
const routines = [];
|
|
380
|
-
const errors = [];
|
|
381
|
-
const seenIds = new Map();
|
|
382
|
-
const files = listFilesRecursive(routinesPath).filter(isRoutineYamlFile).sort();
|
|
383
|
-
for (const filePath of files) {
|
|
384
|
-
const fileName = basename(filePath);
|
|
385
|
-
let raw;
|
|
386
|
-
try {
|
|
387
|
-
raw = readYaml(filePath);
|
|
388
|
-
}
|
|
389
|
-
catch (error) {
|
|
390
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
391
|
-
errors.push(`${fileName}: YAML parse error: ${message}`);
|
|
392
|
-
continue;
|
|
393
|
-
}
|
|
394
|
-
const parsed = parseRoutineDoc(raw, fileName);
|
|
395
|
-
if (!parsed.doc) {
|
|
396
|
-
errors.push(...parsed.errors);
|
|
397
|
-
continue;
|
|
398
|
-
}
|
|
399
|
-
const duplicatePath = seenIds.get(parsed.doc.id);
|
|
400
|
-
if (duplicatePath) {
|
|
401
|
-
errors.push(`${fileName}: duplicate routine id "${parsed.doc.id}" (also in ${duplicatePath})`);
|
|
402
|
-
continue;
|
|
403
|
-
}
|
|
404
|
-
seenIds.set(parsed.doc.id, fileName);
|
|
405
|
-
routines.push({ filePath, doc: parsed.doc });
|
|
406
|
-
}
|
|
407
|
-
return { routines, errors };
|
|
408
|
-
}
|
|
5
|
+
import { ensureFreshDistBuildForEntry } from "../shared/dist-freshness.js";
|
|
6
|
+
import { ROUTINE_BUSY_SKIP_EXIT_CODE, ROUTINE_EXEC_ENV } from "../exec/run/lock.js";
|
|
7
|
+
import { ensureDir, listFilesRecursive, readJson, writeJson } from "../shared/fs.js";
|
|
8
|
+
import { padEndDisplay } from "../shared/text.js";
|
|
9
|
+
import { nowUtcIsoSeconds } from "../shared/time.js";
|
|
10
|
+
import { jobDeclaresReview, jobRunUsesReviewedIntegration, loadJobDefinition, resolveJobPaths, resolveJobReviewAgentNominations, } from "../job/job.js";
|
|
11
|
+
import { cronOccurrences, isRecord, isRoutineDue, isRoutineYamlFile, isoWeek, loadRoutines, resolveRoutinePaths, routineActionKindLabel, } from "./definition.js";
|
|
12
|
+
import { selfRunArgs } from "../shared/spawn-self.js";
|
|
13
|
+
import { specdojoRootDir } from "../shared/specdojo-config.js";
|
|
14
|
+
export { cronMatches, cronOccurrences, isRoutineDue, isoWeek, loadRoutines, parseCronExpression, parseIntervalMs, parseRoutineDoc, resolveRoutinePaths, routineActionKindLabel, } from "./definition.js";
|
|
409
15
|
// ================================
|
|
410
16
|
// State
|
|
411
17
|
// ================================
|
|
@@ -427,6 +33,31 @@ function writeRoutineState(paths, state) {
|
|
|
427
33
|
ensureDir(paths.generatedPath);
|
|
428
34
|
writeJson(paths.statePath, state);
|
|
429
35
|
}
|
|
36
|
+
export function recordRoutineStart(current, startedAt, scheduledAt) {
|
|
37
|
+
const next = {
|
|
38
|
+
...current,
|
|
39
|
+
last_run: startedAt,
|
|
40
|
+
last_result: "running",
|
|
41
|
+
...(scheduledAt ? { last_scheduled_for: scheduledAt } : {}),
|
|
42
|
+
};
|
|
43
|
+
delete next.last_reason;
|
|
44
|
+
delete next.last_action_results;
|
|
45
|
+
return next;
|
|
46
|
+
}
|
|
47
|
+
export function recordRoutineCompletion(current, result, reason, actionResults) {
|
|
48
|
+
const next = {
|
|
49
|
+
...current,
|
|
50
|
+
last_run: current?.last_run ?? nowUtcIsoSeconds(),
|
|
51
|
+
last_result: result,
|
|
52
|
+
...(reason ? { last_reason: reason } : {}),
|
|
53
|
+
...(actionResults ? { last_action_results: actionResults } : {}),
|
|
54
|
+
};
|
|
55
|
+
if (!reason)
|
|
56
|
+
delete next.last_reason;
|
|
57
|
+
if (!actionResults)
|
|
58
|
+
delete next.last_action_results;
|
|
59
|
+
return next;
|
|
60
|
+
}
|
|
430
61
|
export function appendRoutineRunHistory(runsPath, entry) {
|
|
431
62
|
ensureDir(resolve(runsPath, ".."));
|
|
432
63
|
appendFileSync(runsPath, `${JSON.stringify(entry)}\n`, "utf8");
|
|
@@ -470,7 +101,7 @@ function releaseRoutineLock(lockDir) {
|
|
|
470
101
|
* tsx で src を直接実行している場合と配布環境では no-op になる。
|
|
471
102
|
*/
|
|
472
103
|
function ensureFreshDistForRoutineRun() {
|
|
473
|
-
const result = ensureFreshDistBuildForEntry(fileURLToPath(import.meta.url));
|
|
104
|
+
const result = ensureFreshDistBuildForEntry(fileURLToPath(new URL("../specdojo.js", import.meta.url)));
|
|
474
105
|
if (result.message) {
|
|
475
106
|
const stream = result.outcome === "rebuild-failed" ? process.stderr : process.stdout;
|
|
476
107
|
stream.write(`[routine] ${result.message}\n`);
|
|
@@ -509,6 +140,9 @@ function spawnSelf(args) {
|
|
|
509
140
|
}
|
|
510
141
|
if (result.status === ROUTINE_BUSY_SKIP_EXIT_CODE)
|
|
511
142
|
return "skipped";
|
|
143
|
+
if (result.status === 0 && marker?.match(/\bstate=([^\s]+)/)?.[1] === "partial") {
|
|
144
|
+
return "partial";
|
|
145
|
+
}
|
|
512
146
|
return result.status === 0 ? "success" : "failure";
|
|
513
147
|
}
|
|
514
148
|
function renderRoutineInput(value, scheduledAt, timezone) {
|
|
@@ -558,6 +192,8 @@ export function describeJobActionReview(action, definition) {
|
|
|
558
192
|
export function aggregateRoutineActionResults(results) {
|
|
559
193
|
if (results.includes("failure"))
|
|
560
194
|
return "failure";
|
|
195
|
+
if (results.includes("partial"))
|
|
196
|
+
return "partial";
|
|
561
197
|
if (results.includes("skipped"))
|
|
562
198
|
return "skipped";
|
|
563
199
|
return "success";
|
|
@@ -619,7 +255,7 @@ function findJobRunId(action, projectId, scheduledAt) {
|
|
|
619
255
|
return undefined;
|
|
620
256
|
}
|
|
621
257
|
// action が配列なら、前段の結果にかかわらず先頭から全段を順次実行する。
|
|
622
|
-
// 段別結果を返し、全体結果は failure > skipped > success の順に集約する。
|
|
258
|
+
// 段別結果を返し、全体結果は failure > partial > skipped > success の順に集約する。
|
|
623
259
|
function executeRoutine(routine, projectId, dryRun, scheduledAt = new Date()) {
|
|
624
260
|
const { doc } = routine;
|
|
625
261
|
const actions = Array.isArray(doc.action) ? doc.action : [doc.action];
|
|
@@ -824,35 +460,30 @@ export function registerRoutineCommands(program) {
|
|
|
824
460
|
lockDir = acquireRoutineLock(paths.routinesPath);
|
|
825
461
|
}
|
|
826
462
|
let failed = 0;
|
|
463
|
+
let partial = 0;
|
|
827
464
|
let skipped = 0;
|
|
828
465
|
for (const selectedRun of selected) {
|
|
829
466
|
const { entry, scheduledAt } = selectedRun;
|
|
830
467
|
const startedAt = nowUtcIsoSeconds();
|
|
831
468
|
// 実行の試行自体を last_run として先に記録する。失敗した routine が次の
|
|
832
469
|
// 発火まで再試行されない代わりに、失敗が高頻度で連続発火することを防ぐ。
|
|
470
|
+
// また、実行中は last_result を "running" とし、前回の結果や理由が表示されるのを防ぐ。
|
|
833
471
|
if (!dryRun) {
|
|
834
|
-
state.routines[entry.doc.id] =
|
|
835
|
-
...state.routines[entry.doc.id],
|
|
836
|
-
last_run: startedAt,
|
|
837
|
-
...(entry.doc.trigger ? { last_scheduled_for: scheduledAt.toISOString() } : {}),
|
|
838
|
-
};
|
|
472
|
+
state.routines[entry.doc.id] = recordRoutineStart(state.routines[entry.doc.id], startedAt, entry.doc.trigger ? scheduledAt.toISOString() : undefined);
|
|
839
473
|
writeRoutineState(paths, state);
|
|
840
474
|
}
|
|
841
475
|
const execution = executeRoutine(entry, paths.projectId, dryRun, scheduledAt);
|
|
842
476
|
const { result } = execution;
|
|
843
477
|
if (result === "failure")
|
|
844
478
|
failed++;
|
|
479
|
+
if (result === "partial")
|
|
480
|
+
partial++;
|
|
845
481
|
if (result === "skipped") {
|
|
846
482
|
skipped++;
|
|
847
483
|
process.stdout.write(`[routine] skipped ${entry.doc.id}: job action skipped\n`);
|
|
848
484
|
}
|
|
849
485
|
if (!dryRun) {
|
|
850
|
-
state.routines[entry.doc.id] =
|
|
851
|
-
...state.routines[entry.doc.id],
|
|
852
|
-
last_result: result,
|
|
853
|
-
...(execution.reason ? { last_reason: execution.reason } : { last_reason: undefined }),
|
|
854
|
-
last_action_results: execution.actionResults,
|
|
855
|
-
};
|
|
486
|
+
state.routines[entry.doc.id] = recordRoutineCompletion(state.routines[entry.doc.id], result, execution.reason, execution.actionResults);
|
|
856
487
|
writeRoutineState(paths, state);
|
|
857
488
|
appendRoutineRunHistory(paths.runsPath, {
|
|
858
489
|
version: 1,
|
|
@@ -866,7 +497,7 @@ export function registerRoutineCommands(program) {
|
|
|
866
497
|
});
|
|
867
498
|
}
|
|
868
499
|
}
|
|
869
|
-
process.stdout.write(`[routine] ${selected.length} routine(s) processed, ${skipped} skipped, ${failed} failed\n`);
|
|
500
|
+
process.stdout.write(`[routine] ${selected.length} routine(s) processed, ${partial} partial, ${skipped} skipped, ${failed} failed\n`);
|
|
870
501
|
if (failed > 0)
|
|
871
502
|
process.exitCode = 1;
|
|
872
503
|
}
|
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
// sch-strategy-<track>.yaml; deliverable/Kata facts and stored grades are read on every run.
|
|
3
3
|
import { existsSync, readFileSync } from "node:fs";
|
|
4
4
|
import { join, resolve } from "node:path";
|
|
5
|
-
import
|
|
6
|
-
import { collectResolvedDeliverables } from "
|
|
7
|
-
import { resolveBasePath } from "
|
|
8
|
-
import { readYaml } from "
|
|
9
|
-
import { readSpecdojoNamespace } from "
|
|
10
|
-
import { validateGradedMarkdown } from "
|
|
11
|
-
import { readGradeResultForDocument, validateGradeResult } from "
|
|
12
|
-
import { KATA_MISSING, loadRulebookRefs, resolveKataRefs } from "
|
|
5
|
+
import { load } from "../shared/yaml.js";
|
|
6
|
+
import { collectResolvedDeliverables } from "../catalog/build.js";
|
|
7
|
+
import { resolveBasePath } from "../catalog/paths.js";
|
|
8
|
+
import { readYaml } from "../shared/fs.js";
|
|
9
|
+
import { readSpecdojoNamespace } from "../docs/frontmatter-namespace.js";
|
|
10
|
+
import { validateGradedMarkdown } from "../grade/grade.js";
|
|
11
|
+
import { readGradeResultForDocument, validateGradeResult } from "../grade/result.js";
|
|
12
|
+
import { KATA_MISSING, loadRulebookRefs, resolveKataRefs } from "../kata/kata.js";
|
|
13
13
|
export const KATA_KINDS = ["rulebook", "recipe", "sample", "template"];
|
|
14
14
|
function isRecord(value) {
|
|
15
15
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -37,7 +37,7 @@ function readGrade(repoRoot, relPath, projectId) {
|
|
|
37
37
|
metadata = readSpecdojoNamespace(content);
|
|
38
38
|
}
|
|
39
39
|
else {
|
|
40
|
-
const parsed = relPath.endsWith(".json") ? JSON.parse(content) :
|
|
40
|
+
const parsed = relPath.endsWith(".json") ? JSON.parse(content) : load(content);
|
|
41
41
|
if (!isRecord(parsed))
|
|
42
42
|
return undefined;
|
|
43
43
|
metadata = isRecord(parsed.specdojo) ? parsed.specdojo : parsed;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { existsSync } from "node:fs";
|
|
2
2
|
import { resolve } from "node:path";
|
|
3
|
-
import { readYaml } from "
|
|
4
|
-
import {
|
|
3
|
+
import { readYaml } from "../shared/fs.js";
|
|
4
|
+
import { resolveAgentMember } from "../shared/specdojo-config.js";
|
|
5
|
+
import { expandPhaseSetSelection, normalizePhaseSetSelection, taskIterationSuffix, } from "./phase-sets.js";
|
|
5
6
|
// --- Helpers ---
|
|
6
7
|
function collectDeliverables(sections, includeKinds, catalogId, selectedLocalIds, catalogLocalIds, topLevelGroup, out) {
|
|
7
8
|
for (const section of sections) {
|
|
@@ -134,11 +135,13 @@ function validateAgentAssignment(label, assignment, roster, errors) {
|
|
|
134
135
|
if (!nickname)
|
|
135
136
|
continue;
|
|
136
137
|
const members = roster.members.filter((member) => member.type === "agent" && member.nickname === nickname);
|
|
137
|
-
|
|
138
|
+
// A backward-compatible alias resolves to its concrete member; validate that member's role.
|
|
139
|
+
const resolved = members.length === 0 ? resolveAgentMember(roster, nickname) : undefined;
|
|
140
|
+
if (members.length > 1 || (members.length === 0 && !resolved)) {
|
|
138
141
|
errors.push(`${label}.agent.${stageRole}: nickname '${nickname}' was not found uniquely in agent-members.yaml`);
|
|
139
142
|
continue;
|
|
140
143
|
}
|
|
141
|
-
if (members[0]
|
|
144
|
+
if ((members[0] ?? resolved)?.stage_role !== stageRole) {
|
|
142
145
|
errors.push(`${label}.agent.${stageRole}: nickname '${nickname}' must have stage_role: ${stageRole}`);
|
|
143
146
|
}
|
|
144
147
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { dirname, join, relative, resolve, sep } from "node:path";
|
|
2
2
|
import { existsSync, readdirSync, writeFileSync } from "node:fs";
|
|
3
|
-
import
|
|
4
|
-
import { getProjectCatalogPath, getProjectRolesPath, getProjectSchedulePath, getProjectTimelinePath, loadConfig, loadEnv, loadMemberRoster, specdojoRootDir, } from "
|
|
5
|
-
import { buildScheduleTrack, } from "./
|
|
6
|
-
import { readYaml } from "
|
|
7
|
-
import { resolveSpecdojoPath } from "
|
|
8
|
-
import { generateStrategy, writeStrategyFile } from "./
|
|
3
|
+
import { dump } from "../shared/yaml.js";
|
|
4
|
+
import { getProjectCatalogPath, getProjectRolesPath, getProjectSchedulePath, getProjectTimelinePath, loadConfig, loadEnv, loadMemberRoster, specdojoRootDir, } from "../shared/specdojo-config.js";
|
|
5
|
+
import { buildScheduleTrack, } from "./build.js";
|
|
6
|
+
import { readYaml } from "../shared/fs.js";
|
|
7
|
+
import { resolveSpecdojoPath } from "../docs/template-resolution.js";
|
|
8
|
+
import { generateStrategy, writeStrategyFile } from "./strategy-generate.js";
|
|
9
9
|
function resolveSchedulePath(opts) {
|
|
10
10
|
loadEnv();
|
|
11
11
|
const { config, configPath } = loadConfig();
|
|
@@ -158,7 +158,7 @@ export function updateMilestonesFile(schedulePath, projectId, newMilestones, dry
|
|
|
158
158
|
generatedById.delete(milestone.id);
|
|
159
159
|
}
|
|
160
160
|
doc.milestones = orderedMilestones.map((milestone) => ({ ...milestone }));
|
|
161
|
-
const outYaml = withSchemaModeline(filePath, MILESTONES_SCHEMA,
|
|
161
|
+
const outYaml = withSchemaModeline(filePath, MILESTONES_SCHEMA, dump(doc, { lineWidth: 120, noRefs: true }));
|
|
162
162
|
if (dryRun) {
|
|
163
163
|
const label = fileCreated ? "created" : "updated";
|
|
164
164
|
process.stdout.write(`\n# --- (dry-run) sch-milestones.yaml (${label}) ---\n`);
|
|
@@ -399,9 +399,9 @@ export function registerScheduleCommands(program) {
|
|
|
399
399
|
startDate,
|
|
400
400
|
tasks,
|
|
401
401
|
});
|
|
402
|
-
const outYaml = withSchemaModeline(outFile, TRACK_SCHEMA,
|
|
402
|
+
const outYaml = withSchemaModeline(outFile, TRACK_SCHEMA, dump(outDoc, {
|
|
403
403
|
lineWidth: 120,
|
|
404
|
-
|
|
404
|
+
quoteStyle: "double",
|
|
405
405
|
forceQuotes: false,
|
|
406
406
|
noRefs: true,
|
|
407
407
|
}));
|