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
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
import { existsSync, readFileSync, readdirSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { load } from "./yaml.js";
|
|
4
|
+
import { readJson } from "./exec-shared.js";
|
|
5
|
+
import { cronMatches, cronOccurrences, isRoutineDue, routineActionKindLabel, } from "./routine.js";
|
|
6
|
+
// routine ファイル(rtn-*.yaml)を読み、状態ファイル generated/routine-state.json と突き合わせて
|
|
7
|
+
// 最終実行・実行結果・due 状況を得る。CLI 出力(routine list)の転記に依存しない。
|
|
8
|
+
export function aggregateRoutines(routinesPath) {
|
|
9
|
+
if (!routinesPath || !existsSync(routinesPath))
|
|
10
|
+
return { rows: [], docs: [], history: [] };
|
|
11
|
+
const result = {
|
|
12
|
+
rows: [],
|
|
13
|
+
docs: [],
|
|
14
|
+
history: readRoutineRunHistory(join(routinesPath, "generated", "routine-runs.jsonl")),
|
|
15
|
+
error: undefined,
|
|
16
|
+
};
|
|
17
|
+
const stateEntries = readRoutineStateEntries(join(routinesPath, "generated", "routine-state.json"));
|
|
18
|
+
const now = new Date();
|
|
19
|
+
const files = readdirSync(routinesPath)
|
|
20
|
+
.filter((name) => /^rtn-.*\.(ya?ml)$/.test(name))
|
|
21
|
+
.sort();
|
|
22
|
+
for (const file of files) {
|
|
23
|
+
try {
|
|
24
|
+
const doc = parseRoutineFileSafe(join(routinesPath, file));
|
|
25
|
+
if (!doc?.id || typeof doc.id !== "string")
|
|
26
|
+
continue;
|
|
27
|
+
result.docs.push(doc);
|
|
28
|
+
buildRoutineRow(result, doc, stateEntries, now);
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
result.error = `routine file parse failed: ${file}`;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
result.rows.sort((a, b) => a.id.localeCompare(b.id));
|
|
35
|
+
return result;
|
|
36
|
+
}
|
|
37
|
+
export function readRoutineRunHistory(historyPath) {
|
|
38
|
+
if (!existsSync(historyPath))
|
|
39
|
+
return [];
|
|
40
|
+
const entries = [];
|
|
41
|
+
for (const [index, line] of readFileSync(historyPath, "utf8").split(/\r?\n/).entries()) {
|
|
42
|
+
if (!line.trim())
|
|
43
|
+
continue;
|
|
44
|
+
try {
|
|
45
|
+
const value = JSON.parse(line);
|
|
46
|
+
if (value.version === 1 &&
|
|
47
|
+
typeof value.routine_id === "string" &&
|
|
48
|
+
typeof value.scheduled_for === "string" &&
|
|
49
|
+
typeof value.started_at === "string" &&
|
|
50
|
+
typeof value.completed_at === "string" &&
|
|
51
|
+
["success", "failure", "skipped"].includes(value.result) &&
|
|
52
|
+
Array.isArray(value.job_run_ids)) {
|
|
53
|
+
entries.push(value);
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
throw new Error("invalid routine history entry");
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
throw new Error(`routine history parse failed at line ${index + 1}`);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return entries;
|
|
64
|
+
}
|
|
65
|
+
// 毎時の dashboard 更新のように 1 日に何度も動く routine は、日ごとに 1 行へまとめる。
|
|
66
|
+
export const ROUTINE_ROW_COLLAPSE_THRESHOLD = 3;
|
|
67
|
+
export function formatZonedDateTime(iso, timeZone) {
|
|
68
|
+
const date = new Date(iso);
|
|
69
|
+
if (Number.isNaN(date.getTime()))
|
|
70
|
+
return iso;
|
|
71
|
+
const parts = new Intl.DateTimeFormat("en-CA", {
|
|
72
|
+
timeZone,
|
|
73
|
+
month: "2-digit",
|
|
74
|
+
day: "2-digit",
|
|
75
|
+
hour: "2-digit",
|
|
76
|
+
minute: "2-digit",
|
|
77
|
+
hour12: false,
|
|
78
|
+
}).formatToParts(date);
|
|
79
|
+
const get = (type) => parts.find((part) => part.type === type)?.value ?? "";
|
|
80
|
+
return `${get("month")}-${get("day")} ${get("hour")}:${get("minute")}`;
|
|
81
|
+
}
|
|
82
|
+
export function zonedDateKey(date, timeZone) {
|
|
83
|
+
return new Intl.DateTimeFormat("en-CA", {
|
|
84
|
+
timeZone,
|
|
85
|
+
year: "numeric",
|
|
86
|
+
month: "2-digit",
|
|
87
|
+
day: "2-digit",
|
|
88
|
+
}).format(date);
|
|
89
|
+
}
|
|
90
|
+
function previousDateKey(dateKey) {
|
|
91
|
+
const [year, month, day] = dateKey.split("-").map(Number);
|
|
92
|
+
const previous = new Date(Date.UTC(year, month - 1, day - 1));
|
|
93
|
+
return previous.toISOString().slice(0, 10);
|
|
94
|
+
}
|
|
95
|
+
function scheduledToday(doc, today, now, timeZone) {
|
|
96
|
+
if (!doc.trigger || doc.enabled === false)
|
|
97
|
+
return [];
|
|
98
|
+
const start = Math.floor((now.getTime() - 36 * 60 * 60 * 1000) / 60_000) * 60_000;
|
|
99
|
+
const end = Math.floor((now.getTime() + 36 * 60 * 60 * 1000) / 60_000) * 60_000;
|
|
100
|
+
const matches = [];
|
|
101
|
+
for (let cursor = start; cursor <= end; cursor += 60_000) {
|
|
102
|
+
const candidate = new Date(cursor);
|
|
103
|
+
if (zonedDateKey(candidate, timeZone) === today &&
|
|
104
|
+
cronMatches(doc.trigger.cron, doc.trigger.timezone, candidate)) {
|
|
105
|
+
matches.push(candidate);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return matches;
|
|
109
|
+
}
|
|
110
|
+
export function buildDailyRoutineRows(docs, history, now, timeZone = "Asia/Tokyo") {
|
|
111
|
+
const today = zonedDateKey(now, timeZone);
|
|
112
|
+
const yesterday = previousDateKey(today);
|
|
113
|
+
const rows = history
|
|
114
|
+
.filter((entry) => {
|
|
115
|
+
const key = zonedDateKey(new Date(entry.scheduled_for), timeZone);
|
|
116
|
+
return key === yesterday || key === today;
|
|
117
|
+
})
|
|
118
|
+
.map((entry) => ({
|
|
119
|
+
day: zonedDateKey(new Date(entry.scheduled_for), timeZone) === yesterday ? "昨日" : "本日",
|
|
120
|
+
routineId: entry.routine_id,
|
|
121
|
+
scheduledFor: entry.scheduled_for,
|
|
122
|
+
startedAt: entry.started_at,
|
|
123
|
+
completedAt: entry.completed_at,
|
|
124
|
+
result: entry.result,
|
|
125
|
+
jobRunIds: entry.job_run_ids,
|
|
126
|
+
runCount: 1,
|
|
127
|
+
}));
|
|
128
|
+
const completedKeys = new Set(history.map((entry) => `${entry.routine_id}:${new Date(entry.scheduled_for).toISOString().slice(0, 16)}`));
|
|
129
|
+
for (const doc of docs) {
|
|
130
|
+
for (const scheduledFor of scheduledToday(doc, today, now, timeZone)) {
|
|
131
|
+
const key = `${doc.id}:${scheduledFor.toISOString().slice(0, 16)}`;
|
|
132
|
+
if (completedKeys.has(key))
|
|
133
|
+
continue;
|
|
134
|
+
rows.push({
|
|
135
|
+
day: "本日",
|
|
136
|
+
routineId: doc.id,
|
|
137
|
+
scheduledFor: scheduledFor.toISOString(),
|
|
138
|
+
startedAt: "-",
|
|
139
|
+
completedAt: "-",
|
|
140
|
+
// 予定時刻を過ぎても履歴がなければ、skip や cron 停止で動かなかったことを示す。
|
|
141
|
+
result: scheduledFor.getTime() <= now.getTime() ? "未実行" : "予定",
|
|
142
|
+
jobRunIds: [],
|
|
143
|
+
runCount: 1,
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return collapseFrequentRoutineRows(rows).sort((a, b) => a.scheduledFor.localeCompare(b.scheduledFor) || a.routineId.localeCompare(b.routineId));
|
|
148
|
+
}
|
|
149
|
+
// 同じ routine・同じ日の行が閾値以上あれば、最新の実行 1 行に件数をまとめる。
|
|
150
|
+
export function collapseFrequentRoutineRows(rows) {
|
|
151
|
+
const groups = new Map();
|
|
152
|
+
for (const row of rows) {
|
|
153
|
+
const key = `${row.day}:${row.routineId}`;
|
|
154
|
+
groups.set(key, [...(groups.get(key) ?? []), row]);
|
|
155
|
+
}
|
|
156
|
+
const collapsed = [];
|
|
157
|
+
for (const group of groups.values()) {
|
|
158
|
+
if (group.length < ROUTINE_ROW_COLLAPSE_THRESHOLD) {
|
|
159
|
+
collapsed.push(...group);
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
const executed = group.filter((row) => row.result !== "予定" && row.result !== "未実行");
|
|
163
|
+
const latest = [...(executed.length > 0 ? executed : group)].sort((a, b) => b.scheduledFor.localeCompare(a.scheduledFor))[0];
|
|
164
|
+
const failures = executed.filter((row) => row.result === "failure").length;
|
|
165
|
+
collapsed.push({
|
|
166
|
+
...latest,
|
|
167
|
+
runCount: executed.length > 0 ? executed.length : group.length,
|
|
168
|
+
jobRunIds: [],
|
|
169
|
+
result: failures > 0 ? "failure" : latest.result,
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
return collapsed;
|
|
173
|
+
}
|
|
174
|
+
// generated/routine-state.json の routines.<id> が状態の正本。破損時は空。
|
|
175
|
+
function readRoutineStateEntries(statePath) {
|
|
176
|
+
const entries = {};
|
|
177
|
+
if (!existsSync(statePath))
|
|
178
|
+
return entries;
|
|
179
|
+
try {
|
|
180
|
+
const parsed = readJson(statePath);
|
|
181
|
+
const routines = parsed?.routines;
|
|
182
|
+
if (routines && typeof routines === "object") {
|
|
183
|
+
for (const [id, value] of Object.entries(routines)) {
|
|
184
|
+
if (value && typeof value === "object") {
|
|
185
|
+
const entry = value;
|
|
186
|
+
entries[id] = {
|
|
187
|
+
last_run: typeof entry.last_run === "string" ? entry.last_run : undefined,
|
|
188
|
+
last_result: typeof entry.last_result === "string" ? entry.last_result : undefined,
|
|
189
|
+
last_scheduled_for: typeof entry.last_scheduled_for === "string" ? entry.last_scheduled_for : undefined,
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
catch {
|
|
196
|
+
return {};
|
|
197
|
+
}
|
|
198
|
+
return entries;
|
|
199
|
+
}
|
|
200
|
+
function parseRoutineFileSafe(filePath) {
|
|
201
|
+
let parsed;
|
|
202
|
+
try {
|
|
203
|
+
parsed = load(readFileSync(filePath, "utf8"));
|
|
204
|
+
}
|
|
205
|
+
catch {
|
|
206
|
+
return undefined;
|
|
207
|
+
}
|
|
208
|
+
if (!parsed || typeof parsed !== "object")
|
|
209
|
+
return undefined;
|
|
210
|
+
return parsed;
|
|
211
|
+
}
|
|
212
|
+
// routine 1 行を機械可読な正本から集計し、due は now と状態から判定する。
|
|
213
|
+
function buildRoutineRow(result, doc, stateEntries, now) {
|
|
214
|
+
const id = String(doc.id);
|
|
215
|
+
const enabled = doc.enabled === undefined ? true : doc.enabled;
|
|
216
|
+
const kind = doc.action ? routineActionKindLabel(doc.action) : "-";
|
|
217
|
+
const stateEntry = stateEntries[id];
|
|
218
|
+
let lastRun = "-";
|
|
219
|
+
if (stateEntry?.last_run) {
|
|
220
|
+
lastRun = stateEntry.last_result
|
|
221
|
+
? `${stateEntry.last_run} (${stateEntry.last_result})`
|
|
222
|
+
: stateEntry.last_run;
|
|
223
|
+
}
|
|
224
|
+
result.rows.push({
|
|
225
|
+
id,
|
|
226
|
+
name: typeof doc.name === "string" ? doc.name : undefined,
|
|
227
|
+
enabled,
|
|
228
|
+
schedule: routineScheduleLabel(doc),
|
|
229
|
+
kind,
|
|
230
|
+
lastRun,
|
|
231
|
+
due: computeRoutineDue(doc, stateEntry, enabled, now),
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
// interval / trigger + 現在時刻 + 状態(last_run / last_scheduled_for)から due を機械的に判定する。
|
|
235
|
+
export function computeRoutineDue(doc, stateEntry, enabled, now) {
|
|
236
|
+
if (!enabled)
|
|
237
|
+
return "disabled";
|
|
238
|
+
if (doc.trigger) {
|
|
239
|
+
const occurrences = cronOccurrences(doc, stateEntry?.last_scheduled_for, now);
|
|
240
|
+
return occurrences.length > 0 ? "due" : "-";
|
|
241
|
+
}
|
|
242
|
+
if (doc.interval) {
|
|
243
|
+
return isRoutineDue(doc, stateEntry?.last_run, now) ? "due" : "-";
|
|
244
|
+
}
|
|
245
|
+
return "-";
|
|
246
|
+
}
|
|
247
|
+
// interval / trigger を表すラベル。interval 優先、なければ trigger.cron。
|
|
248
|
+
function routineScheduleLabel(doc) {
|
|
249
|
+
if (typeof doc.interval === "string")
|
|
250
|
+
return doc.interval;
|
|
251
|
+
const trigger = doc.trigger;
|
|
252
|
+
if (trigger && typeof trigger.cron === "string")
|
|
253
|
+
return `cron: ${trigger.cron}`;
|
|
254
|
+
return "-";
|
|
255
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { stripTerminalControlSequences } from "./exec-shared.js";
|
|
2
|
+
const MAX_DASHBOARD_CELL_LENGTH = 200;
|
|
3
|
+
// dashboard の表へは event や subprocess 由来の文字列も入る。表へ埋める直前に
|
|
4
|
+
// ターミナル制御シーケンスと改行類を除き、列区切りをエスケープして長さを制限する。
|
|
5
|
+
export function sanitizeDashboardCell(text) {
|
|
6
|
+
const singleLine = stripTerminalControlSequences(text)
|
|
7
|
+
.replace(/[\t\r\n]+/g, " ")
|
|
8
|
+
.replace(/ +/g, " ")
|
|
9
|
+
.trim();
|
|
10
|
+
const truncated = singleLine.length <= MAX_DASHBOARD_CELL_LENGTH
|
|
11
|
+
? singleLine
|
|
12
|
+
: `${singleLine.slice(0, MAX_DASHBOARD_CELL_LENGTH)}…`;
|
|
13
|
+
return truncated.replace(/\|/g, "\\|");
|
|
14
|
+
}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { addWorkingDaysToDate } from "./exec-schedule-calendar.js";
|
|
2
|
+
import { buildScheduleIndex, defaultScheduleCalendar } from "./exec-schedule-index.js";
|
|
3
|
+
import { buildTimelineWaves } from "./timeline-build.js";
|
|
4
|
+
// tml-index の tracks を order → wave に集約し、planned_start_date と稼働日カレンダーで各トラックの
|
|
5
|
+
// 予定開始日・終了日を算出する。横軸は日付であり、wave 番号ではない。
|
|
6
|
+
export function computeTimelineTrackSchedules(index, calendar) {
|
|
7
|
+
const waves = buildTimelineWaves(index.tracks);
|
|
8
|
+
const waveNumberByOrder = new Map();
|
|
9
|
+
for (const wave of waves) {
|
|
10
|
+
for (const tk of wave.tracks)
|
|
11
|
+
waveNumberByOrder.set(tk.order, wave.wave);
|
|
12
|
+
}
|
|
13
|
+
const startByTrack = new Map();
|
|
14
|
+
const endByTrack = new Map();
|
|
15
|
+
let cursor = index.planned_start_date;
|
|
16
|
+
for (const wave of waves) {
|
|
17
|
+
const waveStart = cursor;
|
|
18
|
+
let waveEnd;
|
|
19
|
+
for (const tk of wave.tracks) {
|
|
20
|
+
startByTrack.set(tk.track, waveStart);
|
|
21
|
+
if (tk.catalog_duration_estimate_days && waveStart) {
|
|
22
|
+
const end = addWorkingDaysToDate(waveStart, tk.catalog_duration_estimate_days, calendar);
|
|
23
|
+
endByTrack.set(tk.track, end);
|
|
24
|
+
if (!waveEnd || end > waveEnd)
|
|
25
|
+
waveEnd = end;
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
endByTrack.set(tk.track, undefined);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
// 次 wave の手始め。本 wave に推定日数のあるトラックがあれば最遅完了日の翌稼働日で、
|
|
32
|
+
// 未定のトラックだけなら直前の手始め日をそのまま受け継ぐ(後続波まで日付が伝播する)。
|
|
33
|
+
cursor = waveEnd ? addWorkingDaysToDate(waveEnd, 1, calendar) : cursor;
|
|
34
|
+
}
|
|
35
|
+
const schedule = index.tracks.map((tk) => ({
|
|
36
|
+
track: tk.track,
|
|
37
|
+
order: tk.order,
|
|
38
|
+
domains: tk.domains,
|
|
39
|
+
status: tk.catalog_status,
|
|
40
|
+
estimateDays: tk.catalog_duration_estimate_days,
|
|
41
|
+
parallel_group: tk.parallel_group,
|
|
42
|
+
depends_on: tk.depends_on,
|
|
43
|
+
startDate: startByTrack.get(tk.track),
|
|
44
|
+
endDate: endByTrack.get(tk.track),
|
|
45
|
+
wave: waveNumberByOrder.get(tk.order) ?? 0,
|
|
46
|
+
}));
|
|
47
|
+
return { schedule, plannedStartDate: index.planned_start_date };
|
|
48
|
+
}
|
|
49
|
+
// 稼働日カレンダーの機械可読正本:tml-index.planned_start_date を起点にし、Schedule 側
|
|
50
|
+
// (sch-defaults.yaml と各 sch-*.yaml)の calendar を buildScheduleIndex から復用する。
|
|
51
|
+
// 両方とも YAML 正本から機械的に読み取り、表示文言の解析に依存しない。
|
|
52
|
+
export function resolveDashboardCalendar(schedulePath) {
|
|
53
|
+
try {
|
|
54
|
+
return buildScheduleIndex(schedulePath).calendar;
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
return defaultScheduleCalendar();
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
// ================================
|
|
61
|
+
// Timeline Gantt SVG (x-axis = date)
|
|
62
|
+
// ================================
|
|
63
|
+
function xmlEscape(text) {
|
|
64
|
+
return text
|
|
65
|
+
.replace(/&/g, "&")
|
|
66
|
+
.replace(/</g, "<")
|
|
67
|
+
.replace(/>/g, ">")
|
|
68
|
+
.replace(/"/g, """);
|
|
69
|
+
}
|
|
70
|
+
function statusColor(status) {
|
|
71
|
+
if (status === "primary")
|
|
72
|
+
return "#16a34a";
|
|
73
|
+
if (status === "draft")
|
|
74
|
+
return "#2563eb";
|
|
75
|
+
return "#d1d5db";
|
|
76
|
+
}
|
|
77
|
+
// 予定日付の無いトラックはバーを持たずラベルのみ表示する(手始め日 or 推定稼働日が未設定)。
|
|
78
|
+
export function buildTimelineGanttSvg(schedule, plannedStartDate, title = "トラック計画ガントチャート") {
|
|
79
|
+
const dayWidth = 30;
|
|
80
|
+
const rowHeight = 26;
|
|
81
|
+
const leftPad = 240;
|
|
82
|
+
const topPad = 56;
|
|
83
|
+
const bottomPad = 20;
|
|
84
|
+
// バーは startDate かつ endDate 両方を持つトラックへ。開始日のみのトラックは着手順の着手点として
|
|
85
|
+
// 四角(diamond)で表示する。軸の範囲は endDate が無いトラックも startDate を含めて算出する。
|
|
86
|
+
const fullRows = schedule.filter((row) => row.startDate);
|
|
87
|
+
if (fullRows.length === 0 || !plannedStartDate) {
|
|
88
|
+
return noDataTimelineSvg(title, plannedStartDate
|
|
89
|
+
? "トラックの予定開始日・終了日を算出できませんでした。"
|
|
90
|
+
: "計画開始日(tml-index.yaml の planned_start_date)が未設定です。");
|
|
91
|
+
}
|
|
92
|
+
const parseMs = (dateOnly) => {
|
|
93
|
+
const [year, month, day] = dateOnly.split("-").map(Number);
|
|
94
|
+
return Date.UTC(year, month - 1, day, 0, 0, 0, 0);
|
|
95
|
+
};
|
|
96
|
+
const startMs = parseMs(plannedStartDate);
|
|
97
|
+
let endMs = startMs;
|
|
98
|
+
for (const row of fullRows) {
|
|
99
|
+
const last = row.endDate ?? row.startDate;
|
|
100
|
+
if (parseMs(last) > endMs)
|
|
101
|
+
endMs = parseMs(last);
|
|
102
|
+
}
|
|
103
|
+
const totalDays = Math.max(1, Math.ceil((endMs - startMs) / 86_400_000) + 1);
|
|
104
|
+
const width = leftPad + totalDays * dayWidth + 24;
|
|
105
|
+
const height = topPad + schedule.length * rowHeight + bottomPad;
|
|
106
|
+
const xForDate = (dateOnly) => {
|
|
107
|
+
const daysDiff = Math.floor((parseMs(dateOnly) - startMs) / 86_400_000);
|
|
108
|
+
return leftPad + daysDiff * dayWidth;
|
|
109
|
+
};
|
|
110
|
+
const parts = [];
|
|
111
|
+
parts.push(`<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${height}" viewBox="0 0 ${width} ${height}" role="img" aria-label="${xmlEscape(title)}">`);
|
|
112
|
+
parts.push(`<style>
|
|
113
|
+
text { font-family: ui-sans-serif, system-ui, -apple-system, sans-serif; fill: #1f2937; }
|
|
114
|
+
.tl-title { font-size: 16px; font-weight: 700; fill: #0f172a; }
|
|
115
|
+
.tl-caption { font-size: 11px; fill: #64748b; }
|
|
116
|
+
.tl-label { font-size: 11px; font-weight: 600; fill: #1f2937; }
|
|
117
|
+
.tl-axis { font-size: 10px; fill: #475569; }
|
|
118
|
+
.tl-grid { stroke: #e2e8f0; stroke-width: 1; }
|
|
119
|
+
.tl-month-grid { stroke: #94a3b8; stroke-width: 1.5; }
|
|
120
|
+
.tl-note { font-size: 10px; fill: #9ca3af; }
|
|
121
|
+
</style>`);
|
|
122
|
+
parts.push(`<rect x="0" y="0" width="${width}" height="${height}" fill="#fffdf8" />`);
|
|
123
|
+
parts.push(`<text class="tl-title" x="16" y="24">${xmlEscape(title)}</text>`);
|
|
124
|
+
parts.push(`<text class="tl-caption" x="16" y="42">横軸は日付。予定開始日・予定終了日は tml-index.yaml の planned_start_date と catalog_duration_estimate_days(推定稼働日数)から算出。</text>`);
|
|
125
|
+
for (let offset = 0; offset < totalDays; offset++) {
|
|
126
|
+
const dayMs = startMs + offset * 86_400_000;
|
|
127
|
+
if (new Date(dayMs).getUTCDate() !== 1)
|
|
128
|
+
continue;
|
|
129
|
+
const x = leftPad + offset * dayWidth;
|
|
130
|
+
parts.push(`<line class="tl-month-grid" x1="${x}" y1="${topPad - 22}" x2="${x}" y2="${height - bottomPad}" />`);
|
|
131
|
+
parts.push(`<text class="tl-axis" x="${x + 4}" y="${topPad - 8}">${xmlEscape(new Date(dayMs).toISOString().slice(0, 7))}</text>`);
|
|
132
|
+
}
|
|
133
|
+
parts.push(`<line class="tl-grid" x1="${leftPad}" y1="${topPad - 22}" x2="${leftPad}" y2="${height - bottomPad}" />`);
|
|
134
|
+
let currentY = topPad;
|
|
135
|
+
for (const row of schedule) {
|
|
136
|
+
parts.push(`<text class="tl-label" x="8" y="${currentY + 14}">${xmlEscape(row.track)}</text>`);
|
|
137
|
+
if (row.startDate && row.endDate) {
|
|
138
|
+
const x1 = xForDate(row.startDate);
|
|
139
|
+
const x2 = xForDate(row.endDate);
|
|
140
|
+
const barWidth = Math.max(4, x2 - x1);
|
|
141
|
+
parts.push(`<rect x="${x1}" y="${currentY + 6}" width="${barWidth}" height="12" rx="3" fill="${statusColor(row.status)}" opacity="0.9" />`);
|
|
142
|
+
}
|
|
143
|
+
else if (row.startDate) {
|
|
144
|
+
// 開始日のみ(推定稼働日数未定): 着手点の diamond マーカーで表示。
|
|
145
|
+
const cx = xForDate(row.startDate);
|
|
146
|
+
parts.push(`<polygon points="${cx},${currentY + 2} ${cx + 6},${currentY + 8} ${cx},${currentY + 14} ${cx - 6},${currentY + 8}" fill="${statusColor(row.status)}" opacity="0.85" />`);
|
|
147
|
+
parts.push(`<text class="tl-note" x="${xForDate(row.startDate) + 8}" y="${currentY + 14}">${xmlEscape(datePlanNote(row))}</text>`);
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
parts.push(`<text class="tl-note" x="${leftPad + 4}" y="${currentY + 14}">${xmlEscape(datePlanNote(row))}</text>`);
|
|
151
|
+
}
|
|
152
|
+
parts.push(`<line class="tl-grid" x1="0" y1="${currentY + rowHeight}" x2="${width}" y2="${currentY + rowHeight}" />`);
|
|
153
|
+
currentY += rowHeight;
|
|
154
|
+
}
|
|
155
|
+
parts.push(`</svg>`);
|
|
156
|
+
return parts.join("\n");
|
|
157
|
+
}
|
|
158
|
+
function datePlanNote(row) {
|
|
159
|
+
if (!row.startDate)
|
|
160
|
+
return "手始め日未定";
|
|
161
|
+
if (row.endDate === undefined || !row.estimateDays)
|
|
162
|
+
return `着手順 ${row.order}(推定稼働日数未定)`;
|
|
163
|
+
return `${row.startDate} ~ ${row.endDate}`;
|
|
164
|
+
}
|
|
165
|
+
function noDataTimelineSvg(title, message) {
|
|
166
|
+
const width = 560;
|
|
167
|
+
const height = 120;
|
|
168
|
+
return [
|
|
169
|
+
`<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${height}" viewBox="0 0 ${width} ${height}" role="img" aria-label="${xmlEscape(title)}">`,
|
|
170
|
+
`<rect x="0" y="0" width="${width}" height="${height}" fill="#fffdf8" />`,
|
|
171
|
+
`<text class="tl-title" x="16" y="24">${xmlEscape(title)}</text>`,
|
|
172
|
+
`<text x="16" y="72" font-size="13" fill="#64748b">${xmlEscape(message)}</text>`,
|
|
173
|
+
`</svg>`,
|
|
174
|
+
].join("\n");
|
|
175
|
+
}
|