specdojo 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/dist/catalog-build-references.js +144 -0
- package/dist/catalog-build-render.js +144 -0
- package/dist/catalog-build.js +13 -290
- package/dist/catalog-generate.js +6 -9
- package/dist/catalog-plan-generate.js +2 -2
- package/dist/catalog-plan.js +6 -6
- package/dist/catalog-scaffold.js +4 -4
- package/dist/catalog.js +2 -2
- package/dist/dashboard-exec-records.js +105 -0
- package/dist/dashboard-routines.js +255 -0
- package/dist/dashboard-shared.js +14 -0
- package/dist/dashboard-timeline.js +175 -0
- package/dist/dashboard.js +10 -544
- package/dist/deliverable-trash.js +3 -3
- package/dist/doc-index.js +3 -3
- package/dist/exec-commands.js +557 -0
- package/dist/exec-core.js +457 -0
- package/dist/exec-plans-core.js +693 -0
- package/dist/exec-plans-generation.js +206 -0
- package/dist/exec-plans-storage.js +131 -0
- package/dist/exec-plans.js +3 -1018
- package/dist/exec-repo-integration-git.js +23 -0
- package/dist/exec-repo-integration-sync.js +264 -0
- package/dist/exec-repo-integration.js +4 -281
- package/dist/exec-reporter-output.js +206 -0
- package/dist/exec-reporter.js +2 -206
- package/dist/exec-results.js +22 -15
- package/dist/exec-run-agent-pipeline.js +256 -0
- package/dist/exec-run-agent.js +531 -0
- package/dist/exec-run-in-place.js +541 -0
- package/dist/exec-run-job.js +717 -0
- package/dist/exec-run-lifecycle-commands.js +522 -0
- package/dist/exec-run-mode-shared.js +140 -0
- package/dist/exec-run-register-command.js +244 -0
- package/dist/exec-run-register-core.js +386 -0
- package/dist/exec-run-register-mode.js +206 -0
- package/dist/exec-run-register-resume.js +393 -0
- package/dist/exec-run-register-state.js +322 -0
- package/dist/exec-run-register-worktree.js +509 -0
- package/dist/exec-run-schedule-mode.js +294 -0
- package/dist/exec-run-schedule-prepare.js +353 -0
- package/dist/exec-run-schedule-task.js +572 -0
- package/dist/exec-run-shared.js +399 -0
- package/dist/exec-run.js +11 -6182
- package/dist/exec-shared.js +2 -2
- package/dist/exec-trial-commands.js +558 -0
- package/dist/exec-trial-core.js +371 -0
- package/dist/exec-trial.js +2 -921
- package/dist/exec-worktree-ops-commit.js +707 -0
- package/dist/exec-worktree-ops-lifecycle.js +292 -0
- package/dist/exec-worktree-ops-merge.js +303 -0
- package/dist/exec-worktree-ops.js +3 -1292
- package/dist/exec-worktree.js +32 -4
- package/dist/exec.js +2 -1006
- package/dist/frontmatter-namespace.js +2 -2
- 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-markdown.js +274 -0
- package/dist/grade-pipeline-state.js +184 -0
- package/dist/grade-plan.js +507 -0
- package/dist/grade-result.js +5 -5
- package/dist/grade-target-discovery.js +265 -0
- package/dist/grade-targets.js +432 -0
- package/dist/grade.js +14 -3188
- package/dist/init-command.js +7 -7
- package/dist/job-definition.js +670 -0
- package/dist/job.js +9 -673
- package/dist/kata-command.js +2 -2
- package/dist/register-command-types.js +1 -0
- package/dist/register-core.js +363 -0
- package/dist/register-create-commands.js +245 -0
- package/dist/register-events.js +4 -4
- package/dist/register-item.js +6 -6
- package/dist/register-maintenance-commands.js +187 -0
- package/dist/register-migration.js +268 -0
- package/dist/register-renumber.js +314 -0
- package/dist/register-transition-commands.js +248 -0
- package/dist/register-update.js +230 -0
- package/dist/register-views.js +256 -0
- package/dist/register.js +61 -2069
- package/dist/review-plan.js +3 -3
- package/dist/routine-definition.js +401 -0
- package/dist/routine.js +6 -402
- package/dist/schedule-approach.js +2 -2
- package/dist/schedule-strategy-generate-document.js +273 -0
- package/dist/schedule-strategy-generate-scope.js +199 -0
- package/dist/schedule-strategy-generate.js +9 -473
- package/dist/schedule.js +4 -4
- package/dist/specdojo-config.js +3 -4
- package/dist/viewpoint-document-kinds-check.js +3 -3
- package/dist/yaml-pages.js +4 -4
- package/dist/yaml.js +28 -0
- package/docs/ja/specdojo/guides/exec-config-guide.md +6 -6
- package/docs/ja/specdojo/guides/orchestrator-operation-guide.md +20 -18
- package/docs/ja/specdojo/guides/routine-operation-guide.md +1 -1
- package/package.json +4 -5
- package/templates/antigravity/README.md +3 -3
- package/templates/antigravity/exec-defaults-snippet.yaml +6 -4
- package/templates/init-exec-defaults.yaml +3 -1
package/dist/routine.js
CHANGED
|
@@ -1,411 +1,15 @@
|
|
|
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
5
|
import { ensureFreshDistBuildForEntry } from "./dist-freshness.js";
|
|
6
|
-
import { selfRunArgs } from "./spawn-self.js";
|
|
7
|
-
import { getProjectRoutinesPath, loadConfig, loadEnv, specdojoRootDir } from "./specdojo-config.js";
|
|
8
|
-
import { ensureDir, listFilesRecursive, nowUtcIsoSeconds, padEndDisplay, readJson, readYaml, writeJson, } from "./exec-shared.js";
|
|
9
6
|
import { ROUTINE_BUSY_SKIP_EXIT_CODE, ROUTINE_EXEC_ENV } from "./exec-run-lock.js";
|
|
7
|
+
import { ensureDir, listFilesRecursive, nowUtcIsoSeconds, padEndDisplay, readJson, writeJson, } from "./exec-shared.js";
|
|
10
8
|
import { jobDeclaresReview, jobRunUsesReviewedIntegration, loadJobDefinition, resolveJobPaths, resolveJobReviewAgentNominations, } from "./job.js";
|
|
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
|
-
}
|
|
9
|
+
import { cronOccurrences, isRecord, isRoutineDue, isRoutineYamlFile, isoWeek, loadRoutines, resolveRoutinePaths, routineActionKindLabel, } from "./routine-definition.js";
|
|
10
|
+
import { selfRunArgs } from "./spawn-self.js";
|
|
11
|
+
import { specdojoRootDir } from "./specdojo-config.js";
|
|
12
|
+
export { cronMatches, cronOccurrences, isRoutineDue, isoWeek, loadRoutines, parseCronExpression, parseIntervalMs, parseRoutineDoc, resolveRoutinePaths, routineActionKindLabel, } from "./routine-definition.js";
|
|
409
13
|
// ================================
|
|
410
14
|
// State
|
|
411
15
|
// ================================
|
|
@@ -2,7 +2,7 @@
|
|
|
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
|
|
5
|
+
import { load } from "./yaml.js";
|
|
6
6
|
import { collectResolvedDeliverables } from "./catalog-build.js";
|
|
7
7
|
import { resolveBasePath } from "./catalog-paths.js";
|
|
8
8
|
import { readYaml } from "./exec-shared.js";
|
|
@@ -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;
|