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,230 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import { basename, join } from "node:path";
|
|
3
|
+
import { atomicWriteFile, prepareRegisterEventFile } from "./register-core.js";
|
|
4
|
+
import { buildRegisterEvent } from "./register-events.js";
|
|
5
|
+
import { parseSpecdojoDocument } from "./frontmatter-namespace.js";
|
|
6
|
+
import { applyRegisterItemFields, formatRegisterItemFields, PJR_ID_RE, registerItemFieldsFromItem, REMOVE_REGISTER_ITEM_FIELD, setRegisterItemDescription, setRegisterItemTitle, TERMINAL_STATUSES_SET, } from "./register-item.js";
|
|
7
|
+
import { findRegisterItem, loadRegisterItems, writeDerivedViews } from "./register-views.js";
|
|
8
|
+
// 更新対象の登録項目を解決する。個票ファイルが無い項目は、書き込み先(正本)が無いため
|
|
9
|
+
// 更新できない。移行が済んでいない旧項目に当たった場合は、個票化を促して中断する。
|
|
10
|
+
export function loadItemForUpdate(paths, id, guard) {
|
|
11
|
+
if (!PJR_ID_RE.test(id)) {
|
|
12
|
+
throw new Error(`Invalid ID: "${id}". Must match PJR-XXXX (e.g., PJR-0001)`);
|
|
13
|
+
}
|
|
14
|
+
const view = findRegisterItem(loadRegisterItems(paths), id);
|
|
15
|
+
if (!view) {
|
|
16
|
+
throw new Error(`Item not found: ${id} (searched ${paths.projectRegisterPath})`);
|
|
17
|
+
}
|
|
18
|
+
if (!view.ticketPath) {
|
|
19
|
+
throw new Error(`Item ${id} has no ticket file under ${paths.projectRegisterPath}.\n` +
|
|
20
|
+
`The register item frontmatter is the source of truth; create the ticket file ` +
|
|
21
|
+
`(pjr-${id.slice("PJR-".length).toLowerCase()}-<topic>.md) before updating the item.`);
|
|
22
|
+
}
|
|
23
|
+
if (guard === "require-active" && TERMINAL_STATUSES_SET.has(view.item.status)) {
|
|
24
|
+
throw new Error(`Cannot change ${id}: status is "${view.item.status}" (terminal). Use "register reopen" first.`);
|
|
25
|
+
}
|
|
26
|
+
if (guard === "require-terminal" && !TERMINAL_STATUSES_SET.has(view.item.status)) {
|
|
27
|
+
throw new Error(`Cannot reopen ${id}: status is "${view.item.status}" (already active).`);
|
|
28
|
+
}
|
|
29
|
+
return view;
|
|
30
|
+
}
|
|
31
|
+
// note は未対応項目ではなく、open のまま更新し続ける記録である。終端操作による書き込みを
|
|
32
|
+
// 始める前に共通ガードを通し、対応・回答・判断が必要な場合は別項目の起票へ誘導する。
|
|
33
|
+
export function assertTerminalOperationAllowed(item, command) {
|
|
34
|
+
if (item.type !== "note")
|
|
35
|
+
return;
|
|
36
|
+
throw new Error(`Cannot ${command} ${item.id}: item type "note" is non-terminal and must remain open. ` +
|
|
37
|
+
`Create a todo, question, decision, or another appropriate item type when action, ` +
|
|
38
|
+
`an answer, or a decision is required.`);
|
|
39
|
+
}
|
|
40
|
+
// 更新後の項目値を個票 frontmatter へ書き戻す。未移行(source: index)の項目は、
|
|
41
|
+
// 行から読んだ値も含めて全フィールドを書き込み、その場で個票正本へ移行する。
|
|
42
|
+
// タイトル・説明は frontmatter に持たないため、H1 と概要段落を書き換える。
|
|
43
|
+
export function applyItemUpdate(opts) {
|
|
44
|
+
const ticketPath = opts.view.ticketPath;
|
|
45
|
+
if (!ticketPath) {
|
|
46
|
+
throw new Error(`Item ${opts.view.id} has no ticket file to update`);
|
|
47
|
+
}
|
|
48
|
+
const label = opts.action ?? `→ ${opts.updated.status}`;
|
|
49
|
+
const updates = {
|
|
50
|
+
...registerItemFieldsFromItem(opts.updated),
|
|
51
|
+
// block_reason は waiting の現在値にだけ属する。waiting 以外への遷移や、
|
|
52
|
+
// stale な個票に対する更新では削除し、削除前の値は event の差分へ残す。
|
|
53
|
+
...(opts.updated.status === "waiting" ? {} : { block_reason: REMOVE_REGISTER_ITEM_FIELD }),
|
|
54
|
+
...opts.fieldUpdates,
|
|
55
|
+
};
|
|
56
|
+
if (opts.dryRun) {
|
|
57
|
+
const lines = [`Would update ${ticketPath} (${opts.updated.id} ${label}):`];
|
|
58
|
+
if (opts.title !== undefined)
|
|
59
|
+
lines.push(` title: ${opts.title}`);
|
|
60
|
+
if (opts.description !== undefined)
|
|
61
|
+
lines.push(` description: ${opts.description}`);
|
|
62
|
+
lines.push(formatRegisterItemFields(updates));
|
|
63
|
+
process.stdout.write(`${lines.join("\n")}\n`);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const beforeContent = readFileSync(ticketPath, "utf8");
|
|
67
|
+
let content = beforeContent;
|
|
68
|
+
if (opts.title !== undefined)
|
|
69
|
+
content = setRegisterItemTitle(content, opts.title);
|
|
70
|
+
if (opts.description !== undefined) {
|
|
71
|
+
content = setRegisterItemDescription(content, opts.description);
|
|
72
|
+
}
|
|
73
|
+
content = applyRegisterItemFields(content, updates);
|
|
74
|
+
const event = buildRegisterEvent({
|
|
75
|
+
beforeContent,
|
|
76
|
+
afterContent: content,
|
|
77
|
+
filename: basename(ticketPath),
|
|
78
|
+
timeZone: opts.paths.registerDateTimeZone,
|
|
79
|
+
action: opts.eventAction,
|
|
80
|
+
actor: opts.eventActor,
|
|
81
|
+
reason: opts.eventReason,
|
|
82
|
+
});
|
|
83
|
+
if (!event) {
|
|
84
|
+
process.stdout.write(`Unchanged: ${ticketPath} (${opts.updated.id})\n`);
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
const eventWrite = prepareRegisterEventFile(opts.paths.projectRegisterPath, opts.updated.id, event);
|
|
88
|
+
atomicWriteFile(ticketPath, content);
|
|
89
|
+
atomicWriteFile(eventWrite.path, eventWrite.content);
|
|
90
|
+
process.stdout.write(`Updated: ${ticketPath} (${opts.updated.id} ${label})\n`);
|
|
91
|
+
process.stdout.write(`Updated: ${eventWrite.path}\n`);
|
|
92
|
+
for (const view of writeDerivedViews(opts.paths, "all")) {
|
|
93
|
+
process.stdout.write(`Generated: ${view.path}\n`);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
// ================================
|
|
97
|
+
// Ticket Frontmatter Status
|
|
98
|
+
// ================================
|
|
99
|
+
const FRONTMATTER_BLOCK_RE = /^---\r?\n([\s\S]*?)\r?\n---/;
|
|
100
|
+
// pjr-index の「個票」セル(例: `[pjr-0001-topic](./pjr-0001-topic.md)`)から
|
|
101
|
+
// project-register ディレクトリ相対のファイル名を取り出す。個票なし(`-`)は undefined。
|
|
102
|
+
export function parseTicketFilename(ticketCell) {
|
|
103
|
+
if (ticketCell === "-" || ticketCell.trim() === "")
|
|
104
|
+
return undefined;
|
|
105
|
+
const match = ticketCell.match(/\]\(\.\/([^)]+\.md)\)/);
|
|
106
|
+
return match ? match[1] : undefined;
|
|
107
|
+
}
|
|
108
|
+
function stripFencedCode(markdown) {
|
|
109
|
+
let fence;
|
|
110
|
+
return markdown
|
|
111
|
+
.split(/(?<=\n)/)
|
|
112
|
+
.map((lineWithEnding) => {
|
|
113
|
+
const line = lineWithEnding.replace(/\r?\n$/, "");
|
|
114
|
+
const lineEnding = lineWithEnding.slice(line.length);
|
|
115
|
+
if (fence) {
|
|
116
|
+
const closing = line.match(/^ {0,3}(`+|~+)[ \t]*$/);
|
|
117
|
+
if (closing && closing[1][0] === fence.marker && closing[1].length >= fence.length) {
|
|
118
|
+
fence = undefined;
|
|
119
|
+
}
|
|
120
|
+
return lineEnding;
|
|
121
|
+
}
|
|
122
|
+
const opening = line.match(/^ {0,3}(`{3,}|~{3,})(.*)$/);
|
|
123
|
+
if (opening && !(opening[1][0] === "`" && opening[2].includes("`"))) {
|
|
124
|
+
fence = { marker: opening[1][0], length: opening[1].length };
|
|
125
|
+
return lineEnding;
|
|
126
|
+
}
|
|
127
|
+
return lineWithEnding;
|
|
128
|
+
})
|
|
129
|
+
.join("");
|
|
130
|
+
}
|
|
131
|
+
function isEscapedMarkdownCharacter(markdown, index) {
|
|
132
|
+
let backslashes = 0;
|
|
133
|
+
for (let cursor = index - 1; cursor >= 0 && markdown[cursor] === "\\"; cursor--) {
|
|
134
|
+
backslashes++;
|
|
135
|
+
}
|
|
136
|
+
return backslashes % 2 === 1;
|
|
137
|
+
}
|
|
138
|
+
function findClosingBacktickRun(markdown, start, length) {
|
|
139
|
+
for (let cursor = start; cursor < markdown.length;) {
|
|
140
|
+
if (markdown[cursor] !== "`") {
|
|
141
|
+
cursor++;
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
const runStart = cursor;
|
|
145
|
+
while (markdown[cursor] === "`")
|
|
146
|
+
cursor++;
|
|
147
|
+
if (cursor - runStart === length && !isEscapedMarkdownCharacter(markdown, runStart)) {
|
|
148
|
+
return runStart;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return -1;
|
|
152
|
+
}
|
|
153
|
+
function stripInlineCode(markdown) {
|
|
154
|
+
let result = "";
|
|
155
|
+
for (let cursor = 0; cursor < markdown.length;) {
|
|
156
|
+
if (markdown[cursor] !== "`" || isEscapedMarkdownCharacter(markdown, cursor)) {
|
|
157
|
+
result += markdown[cursor];
|
|
158
|
+
cursor++;
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
const runStart = cursor;
|
|
162
|
+
while (markdown[cursor] === "`")
|
|
163
|
+
cursor++;
|
|
164
|
+
const runLength = cursor - runStart;
|
|
165
|
+
const closing = findClosingBacktickRun(markdown, cursor, runLength);
|
|
166
|
+
if (closing === -1) {
|
|
167
|
+
result += markdown.slice(runStart, cursor);
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
cursor = closing + runLength;
|
|
171
|
+
}
|
|
172
|
+
return result;
|
|
173
|
+
}
|
|
174
|
+
// type 固有の必須節が固まっているかの判定。見出し文言(言語依存)に依存せず、
|
|
175
|
+
// Markdown のコード範囲を除く本文に記入プレースホルダ `_TODO_` が残っていれば
|
|
176
|
+
// 「未確定」とみなす。コード範囲は記法の説明や例示に使えるため判定対象外とする。
|
|
177
|
+
function ticketBodyHasTodo(content) {
|
|
178
|
+
const { body } = parseSpecdojoDocument(content);
|
|
179
|
+
return stripInlineCode(stripFencedCode(body)).includes("_TODO_");
|
|
180
|
+
}
|
|
181
|
+
// 個票 Frontmatter(specdojo 名前空間)内の `status:` 行を targetStatus へ書き換える。
|
|
182
|
+
// 既に目的の値なら changed=false を返し、内容を変えない(冪等)。
|
|
183
|
+
export function updateTicketFrontmatterStatus(content, targetStatus) {
|
|
184
|
+
const block = content.match(FRONTMATTER_BLOCK_RE);
|
|
185
|
+
if (!block) {
|
|
186
|
+
throw new Error("frontmatter not found in ticket file");
|
|
187
|
+
}
|
|
188
|
+
const statusLineRe = /^(\s*status:[ \t]*)(\S+)(.*)$/m;
|
|
189
|
+
const statusLine = block[1].match(statusLineRe);
|
|
190
|
+
if (!statusLine) {
|
|
191
|
+
throw new Error("status field not found in ticket frontmatter");
|
|
192
|
+
}
|
|
193
|
+
if (statusLine[2] === targetStatus) {
|
|
194
|
+
return { content, changed: false };
|
|
195
|
+
}
|
|
196
|
+
const newFrontmatter = block[1].replace(statusLineRe, (_m, prefix, _old, suffix) => `${prefix}${targetStatus}${suffix}`);
|
|
197
|
+
const newContent = content.replace(block[1], () => newFrontmatter);
|
|
198
|
+
return { content: newContent, changed: true };
|
|
199
|
+
}
|
|
200
|
+
// close / reject に伴い、対象個票の Frontmatter `status` を昇格・廃止する。
|
|
201
|
+
// - 個票なし(個票列が `-`)や個票ファイル不在は、エラーにせず処理状態のみで完了する。
|
|
202
|
+
// - `ready` への昇格は必須節に `_TODO_` が残っていないことを条件とし、残る場合は警告して据え置く。
|
|
203
|
+
export function updateTicketStatusForItem(opts) {
|
|
204
|
+
const filename = parseTicketFilename(opts.item.ticket);
|
|
205
|
+
if (!filename)
|
|
206
|
+
return;
|
|
207
|
+
const ticketPath = join(opts.paths.projectRegisterPath, filename);
|
|
208
|
+
if (!existsSync(ticketPath)) {
|
|
209
|
+
process.stdout.write(`Warning: ticket file not found; skipped status update for ${opts.item.id}: ${ticketPath}\n`);
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
const content = readFileSync(ticketPath, "utf8");
|
|
213
|
+
if (opts.targetStatus === "ready" && ticketBodyHasTodo(content)) {
|
|
214
|
+
process.stdout.write(`Warning: ${opts.item.id} ticket has unresolved _TODO_; kept as draft (not promoted to ready): ${ticketPath}\n`);
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
const { content: updated, changed } = updateTicketFrontmatterStatus(content, opts.targetStatus);
|
|
218
|
+
if (!changed) {
|
|
219
|
+
if (opts.dryRun) {
|
|
220
|
+
process.stdout.write(`Ticket already ${opts.targetStatus}: ${ticketPath}\n`);
|
|
221
|
+
}
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
if (opts.dryRun) {
|
|
225
|
+
process.stdout.write(`Would update ticket status → ${opts.targetStatus}: ${ticketPath}\n`);
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
atomicWriteFile(ticketPath, updated);
|
|
229
|
+
process.stdout.write(`Updated ticket status → ${opts.targetStatus}: ${ticketPath}\n`);
|
|
230
|
+
}
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { basename, dirname, join } from "node:path";
|
|
3
|
+
import { extractTableHeading, formatTableRow, injectRegisterRows, parsePjrIndex, REGISTER_INDEX_TEMPLATE, } from "./register-core.js";
|
|
4
|
+
import { readRegisterEventsFromContent, registerEventFilePath } from "./register-events.js";
|
|
5
|
+
import { compareRegisterItemIds, loadRegisterItemDocs, ticketRefCell, toDisplayItem, VALID_PRIORITIES, VALID_STATUSES, } from "./register-item.js";
|
|
6
|
+
import { flattenTemplateFrontmatter } from "./template-frontmatter.js";
|
|
7
|
+
import { resolveSpecdojoTemplatePath } from "./template-resolution.js";
|
|
8
|
+
// ================================
|
|
9
|
+
// Derived View Generation
|
|
10
|
+
// ================================
|
|
11
|
+
function adjustTicketLink(ticket, prefix) {
|
|
12
|
+
if (ticket === "-")
|
|
13
|
+
return ticket;
|
|
14
|
+
return ticket.replace(/\]\(\.\//g, `](${prefix}`);
|
|
15
|
+
}
|
|
16
|
+
function rebaseItems(items, prefix) {
|
|
17
|
+
return items.map((it) => ({ ...it, ticket: adjustTicketLink(it.ticket, prefix) }));
|
|
18
|
+
}
|
|
19
|
+
function makeTable(items, heading) {
|
|
20
|
+
const rows = items.map(formatTableRow);
|
|
21
|
+
return [heading.header, heading.separator, ...rows].join("\n");
|
|
22
|
+
}
|
|
23
|
+
// 派生ビューの外枠(H1・note・章見出し・frontmatter)は template が所有する。
|
|
24
|
+
// template をロードして生成物形へ平坦化し、`_PROJECT_ID_` を実プロジェクト ID へ置換する。
|
|
25
|
+
function loadViewTemplate(templateFileName, projectId) {
|
|
26
|
+
const templatePath = resolveSpecdojoTemplatePath(templateFileName);
|
|
27
|
+
const raw = readFileSync(templatePath, "utf8");
|
|
28
|
+
return flattenTemplateFrontmatter(raw).replace(/_PROJECT_ID_/g, projectId);
|
|
29
|
+
}
|
|
30
|
+
// template 本文中の `<!-- specdojo:view-slot=<key> -->` 行を生成テーブルへ置換する。
|
|
31
|
+
// slot と提供テーブルは相互に過不足がないことを検証し、template の不整合を早期に検出する。
|
|
32
|
+
export function injectViewSlots(content, slots) {
|
|
33
|
+
const used = new Set();
|
|
34
|
+
const injected = content.replace(/^<!-- specdojo:view-slot=([a-z-]+) -->$/gm, (_match, key) => {
|
|
35
|
+
if (!(key in slots)) {
|
|
36
|
+
throw new Error(`Unknown view-slot in template: ${key}`);
|
|
37
|
+
}
|
|
38
|
+
used.add(key);
|
|
39
|
+
return slots[key];
|
|
40
|
+
});
|
|
41
|
+
const missing = Object.keys(slots).filter((key) => !used.has(key));
|
|
42
|
+
if (missing.length > 0) {
|
|
43
|
+
throw new Error(`View-slot not found in template: ${missing.join(", ")}`);
|
|
44
|
+
}
|
|
45
|
+
return injected;
|
|
46
|
+
}
|
|
47
|
+
// グループ(状態別・優先度別・担当者別など)を `### <chapter>.<n>. <label>` 見出し付きの
|
|
48
|
+
// テーブル群へ整形する。章見出しラベルは template 側が持つため、ここでは番号と値のみ扱う。
|
|
49
|
+
function renderGroupedTables(groups, chapter, heading) {
|
|
50
|
+
return groups
|
|
51
|
+
.map((group, index) => [
|
|
52
|
+
`### ${chapter}.${index + 1}. ${group.label}`,
|
|
53
|
+
"",
|
|
54
|
+
"<!-- prettier-ignore -->",
|
|
55
|
+
makeTable(group.items, heading),
|
|
56
|
+
].join("\n"))
|
|
57
|
+
.join("\n\n");
|
|
58
|
+
}
|
|
59
|
+
// ビューの行順に使う起票時刻を解決する。`registered` は移行前の項目で `_TODO_` になるため、
|
|
60
|
+
// 追記型イベントの `add` の `ts` で補う。表示 ID はランダムな 4 文字で、ID 順には時系列の意味が
|
|
61
|
+
// ないため、並びの根拠は時刻に置く。
|
|
62
|
+
function resolveRegisteredOrder(item, paths, cache) {
|
|
63
|
+
const cached = cache.get(item.id);
|
|
64
|
+
if (cached !== undefined)
|
|
65
|
+
return cached;
|
|
66
|
+
let value = "";
|
|
67
|
+
if (item.registered && item.registered !== "_TODO_" && item.registered !== "-") {
|
|
68
|
+
value = item.registered;
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
const eventPath = registerEventFilePath(paths.projectRegisterPath, item.id);
|
|
72
|
+
if (existsSync(eventPath)) {
|
|
73
|
+
const events = readRegisterEventsFromContent(readFileSync(eventPath, "utf8"), eventPath);
|
|
74
|
+
const added = events.find((event) => event.action === "add");
|
|
75
|
+
if (added?.ts)
|
|
76
|
+
value = added.ts;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
cache.set(item.id, value);
|
|
80
|
+
return value;
|
|
81
|
+
}
|
|
82
|
+
// 新しい起票を先頭へ置く。時刻が並ぶ場合と時刻を解決できない場合は ID で安定させる。
|
|
83
|
+
// 時刻を解決できない項目は末尾へ送り、解決できた項目の並びを乱さない。
|
|
84
|
+
export function sortByRegisteredDesc(items, paths) {
|
|
85
|
+
const cache = new Map();
|
|
86
|
+
return [...items].sort((a, b) => {
|
|
87
|
+
const left = resolveRegisteredOrder(a, paths, cache);
|
|
88
|
+
const right = resolveRegisteredOrder(b, paths, cache);
|
|
89
|
+
if (left !== right) {
|
|
90
|
+
if (!left)
|
|
91
|
+
return 1;
|
|
92
|
+
if (!right)
|
|
93
|
+
return -1;
|
|
94
|
+
return left < right ? 1 : -1;
|
|
95
|
+
}
|
|
96
|
+
return compareRegisterItemIds(a.id, b.id);
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
function groupByOwner(items) {
|
|
100
|
+
const grouped = new Map();
|
|
101
|
+
for (const item of items) {
|
|
102
|
+
const key = item.owner || "-";
|
|
103
|
+
if (!grouped.has(key))
|
|
104
|
+
grouped.set(key, []);
|
|
105
|
+
grouped.get(key).push(item);
|
|
106
|
+
}
|
|
107
|
+
return [...grouped.keys()].sort().map((owner) => ({ label: owner, items: grouped.get(owner) }));
|
|
108
|
+
}
|
|
109
|
+
// 登録項目一覧(pjr-index)本体を生成する。行は ID 昇順で、列見出しと外枠は template が持つ。
|
|
110
|
+
function generateIndexView(items, projectId) {
|
|
111
|
+
const template = loadViewTemplate(REGISTER_INDEX_TEMPLATE, projectId);
|
|
112
|
+
return injectRegisterRows(template, items.map(formatTableRow));
|
|
113
|
+
}
|
|
114
|
+
// 状態別・優先度別・担当者別のビューは、非追跡の生成物になったことで単一ファイルへ
|
|
115
|
+
// まとめる理由(共有編集時の git 差分・マージ競合の回避)が無くなったため、
|
|
116
|
+
// 軸ごとに別ファイルへ分割する(見やすさを優先する)。
|
|
117
|
+
function generateViewsByStatusFile(items, projectId, heading) {
|
|
118
|
+
const statusGroups = VALID_STATUSES.map((status) => ({
|
|
119
|
+
label: status,
|
|
120
|
+
items: items.filter((it) => it.status === status),
|
|
121
|
+
})).filter((group) => group.items.length > 0);
|
|
122
|
+
const template = loadViewTemplate("pjr-views-by-status-template.md", projectId);
|
|
123
|
+
return injectViewSlots(template, {
|
|
124
|
+
"by-status": renderGroupedTables(statusGroups, 1, heading),
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
function generateViewsByPriorityFile(items, projectId, heading) {
|
|
128
|
+
const priorityGroups = VALID_PRIORITIES.map((priority) => ({
|
|
129
|
+
label: priority,
|
|
130
|
+
items: items.filter((it) => it.priority === priority),
|
|
131
|
+
}));
|
|
132
|
+
const template = loadViewTemplate("pjr-views-by-priority-template.md", projectId);
|
|
133
|
+
return injectViewSlots(template, {
|
|
134
|
+
"by-priority": renderGroupedTables(priorityGroups, 1, heading),
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
function generateViewsByOwnerFile(items, projectId, heading) {
|
|
138
|
+
const template = loadViewTemplate("pjr-views-by-owner-template.md", projectId);
|
|
139
|
+
return injectViewSlots(template, {
|
|
140
|
+
"by-owner": renderGroupedTables(groupByOwner(items), 1, heading),
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
function generateTypeFilterView(items, type, templateFileName, projectId, heading) {
|
|
144
|
+
const filtered = items.filter((it) => it.type === type);
|
|
145
|
+
const template = loadViewTemplate(templateFileName, projectId);
|
|
146
|
+
return injectViewSlots(template, {
|
|
147
|
+
table: ["<!-- prettier-ignore -->", makeTable(filtered, heading)].join("\n"),
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
export const VALID_BUILD_SCOPES = ["register", "controls", "all"];
|
|
151
|
+
export function generateDerivedViewFiles(paths, scope) {
|
|
152
|
+
// 項目の値は個票 frontmatter(正本)から集める。列見出しは template から採用するため、
|
|
153
|
+
// 生成処理は作業ツリーの pjr-index.md を入力にしない。
|
|
154
|
+
// 「登録日」「完了日」は保存された日時をプロジェクトの登録日タイムゾーンへ変換して導出する。
|
|
155
|
+
const items = loadRegisterItems(paths).map((view) => toDisplayItem(view.item, paths.registerDateTimeZone));
|
|
156
|
+
const heading = extractTableHeading(loadViewTemplate(REGISTER_INDEX_TEMPLATE, paths.projectId));
|
|
157
|
+
// 個票セルのリンクは project-register/ 起点の `./` 表記で作られる。
|
|
158
|
+
// 各 generated/ ディレクトリから辿れるよう相対パスを付け替える。
|
|
159
|
+
const pjrDirName = basename(paths.projectRegisterPath);
|
|
160
|
+
const regItems = rebaseItems(items, "../");
|
|
161
|
+
const ctrlItems = rebaseItems(items, `../${pjrDirName}/`);
|
|
162
|
+
const registerViews = [];
|
|
163
|
+
const controlsViews = [];
|
|
164
|
+
if (scope === "register" || scope === "all") {
|
|
165
|
+
// 本体(pjr-index)は ID で引く用途があるため ID 昇順を保つ。軸別ビューは状況の把握が目的で、
|
|
166
|
+
// 新しい起票を先頭へ置く。
|
|
167
|
+
const viewItems = sortByRegisteredDesc(regItems, paths);
|
|
168
|
+
registerViews.push({
|
|
169
|
+
path: join(paths.generatedPath, "pjr-index.md"),
|
|
170
|
+
content: generateIndexView(regItems, paths.projectId),
|
|
171
|
+
}, {
|
|
172
|
+
path: join(paths.generatedPath, "pjr-views-by-status.md"),
|
|
173
|
+
content: generateViewsByStatusFile(viewItems, paths.projectId, heading),
|
|
174
|
+
}, {
|
|
175
|
+
path: join(paths.generatedPath, "pjr-views-by-priority.md"),
|
|
176
|
+
content: generateViewsByPriorityFile(viewItems, paths.projectId, heading),
|
|
177
|
+
}, {
|
|
178
|
+
path: join(paths.generatedPath, "pjr-views-by-owner.md"),
|
|
179
|
+
content: generateViewsByOwnerFile(viewItems, paths.projectId, heading),
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
if (scope === "controls" || scope === "all") {
|
|
183
|
+
controlsViews.push({
|
|
184
|
+
path: join(paths.controlsGeneratedPath, "pm-risk-register.md"),
|
|
185
|
+
content: generateTypeFilterView(ctrlItems, "risk", "pm-risk-register-template.md", paths.projectId, heading),
|
|
186
|
+
}, {
|
|
187
|
+
path: join(paths.controlsGeneratedPath, "pm-issue-log.md"),
|
|
188
|
+
content: generateTypeFilterView(ctrlItems, "issue", "pm-issue-log-template.md", paths.projectId, heading),
|
|
189
|
+
}, {
|
|
190
|
+
path: join(paths.controlsGeneratedPath, "pm-change-request-log.md"),
|
|
191
|
+
content: generateTypeFilterView(ctrlItems, "change-request", "pm-change-request-log-template.md", paths.projectId, heading),
|
|
192
|
+
}, {
|
|
193
|
+
path: join(paths.controlsGeneratedPath, "pm-decision-log.md"),
|
|
194
|
+
content: generateTypeFilterView(ctrlItems, "decision", "pm-decision-log-template.md", paths.projectId, heading),
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
return [...registerViews, ...controlsViews];
|
|
198
|
+
}
|
|
199
|
+
export function writeDerivedViews(paths, scope) {
|
|
200
|
+
const views = generateDerivedViewFiles(paths, scope);
|
|
201
|
+
const hasRegisterViews = views.some((view) => dirname(view.path) === paths.generatedPath);
|
|
202
|
+
const hasControlsViews = views.some((view) => dirname(view.path) === paths.controlsGeneratedPath);
|
|
203
|
+
if (hasRegisterViews) {
|
|
204
|
+
mkdirSync(paths.generatedPath, { recursive: true });
|
|
205
|
+
}
|
|
206
|
+
if (hasControlsViews) {
|
|
207
|
+
mkdirSync(paths.controlsGeneratedPath, { recursive: true });
|
|
208
|
+
}
|
|
209
|
+
for (const view of views) {
|
|
210
|
+
writeFileSync(view.path, view.content, "utf8");
|
|
211
|
+
}
|
|
212
|
+
return views;
|
|
213
|
+
}
|
|
214
|
+
// ================================
|
|
215
|
+
// Item Update Helpers
|
|
216
|
+
// ================================
|
|
217
|
+
export function findItemById(items, id) {
|
|
218
|
+
return items.find((it) => it.id === id);
|
|
219
|
+
}
|
|
220
|
+
// 登録項目を全件解決する。正本は個票 frontmatter で、登録項目フィールドを持つ個票を
|
|
221
|
+
// 最優先で採用する。まだ個票へ移行していない項目は pjr-index の行から読み取り(互換)、
|
|
222
|
+
// 個票ファイルがある場合はそのパスを保持して、次回の更新時に frontmatter へ移す。
|
|
223
|
+
export function loadRegisterItems(paths) {
|
|
224
|
+
const docs = loadRegisterItemDocs(paths.projectRegisterPath);
|
|
225
|
+
const docById = new Map(docs.map((doc) => [doc.id, doc]));
|
|
226
|
+
const views = new Map();
|
|
227
|
+
for (const doc of docs) {
|
|
228
|
+
if (!doc.hasRegisterFields)
|
|
229
|
+
continue;
|
|
230
|
+
views.set(doc.id, {
|
|
231
|
+
id: doc.id,
|
|
232
|
+
item: doc.item,
|
|
233
|
+
ticketPath: doc.path,
|
|
234
|
+
ticketFilename: doc.filename,
|
|
235
|
+
source: "ticket",
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
if (existsSync(paths.pjrIndexPath)) {
|
|
239
|
+
for (const item of parsePjrIndex(readFileSync(paths.pjrIndexPath, "utf8"), paths.registerDateTimeZone)) {
|
|
240
|
+
if (views.has(item.id))
|
|
241
|
+
continue;
|
|
242
|
+
const doc = docById.get(item.id);
|
|
243
|
+
views.set(item.id, {
|
|
244
|
+
id: item.id,
|
|
245
|
+
item: doc ? { ...item, ticket: ticketRefCell(doc.filename) } : item,
|
|
246
|
+
ticketPath: doc?.path,
|
|
247
|
+
ticketFilename: doc?.filename,
|
|
248
|
+
source: "index",
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
return [...views.values()].sort((a, b) => compareRegisterItemIds(a.id, b.id));
|
|
253
|
+
}
|
|
254
|
+
export function findRegisterItem(views, id) {
|
|
255
|
+
return views.find((view) => view.id === id);
|
|
256
|
+
}
|