@infodb/p3 0.11.0 → 0.13.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.
Files changed (138) hide show
  1. package/README.md +33 -33
  2. package/dist/web/assets/CompletionReview-gZKZrDu_.js +1 -0
  3. package/dist/web/assets/ImprovementDialog-Dno6dPnG.js +1 -0
  4. package/dist/web/assets/Outputs-BgHalMGb.js +1 -0
  5. package/dist/web/assets/RequestStatus-hZcBUUIu.js +1 -0
  6. package/dist/web/assets/Tabs-C3NmwCc3.js +1 -0
  7. package/dist/web/assets/TagInput-B2b862qn.js +1 -0
  8. package/dist/web/assets/TaskDrawer-4BQBELXa.js +6 -0
  9. package/dist/web/assets/_requestId-BMAG1t3o.js +1 -0
  10. package/dist/web/assets/_requestId-tbg2pA2S.js +1 -0
  11. package/dist/web/assets/archive-DMl6WyOe.js +1 -0
  12. package/dist/web/assets/board-BMTcHKyt.js +1 -0
  13. package/dist/web/assets/done-CL6Nlsua.js +1 -0
  14. package/dist/web/assets/draft-BvGxfD7v.js +2 -0
  15. package/dist/web/assets/index-Dp7Fc4VI.css +2 -0
  16. package/dist/web/assets/index-KdlgMitg.js +12 -0
  17. package/dist/web/assets/metrics-Cu7gJ7Rk.js +1 -0
  18. package/dist/web/assets/new-DTXWHuFO.js +1 -0
  19. package/dist/web/assets/outputs-CXqnjSqV.js +1 -0
  20. package/dist/web/assets/preflightInput-ClKwkp8R.js +2 -0
  21. package/dist/web/assets/preload-helper-oLCrNCwz.js +1 -0
  22. package/dist/web/assets/quality-RFd-7k3r.js +1 -0
  23. package/dist/web/assets/release-notes-Bpdi6RdY.js +5 -0
  24. package/dist/web/assets/requestData-CbFxwW5w.js +1 -0
  25. package/dist/web/assets/routes-BIt8bExF.js +6 -0
  26. package/dist/web/assets/settings-CsCqF_1B.js +1 -0
  27. package/dist/web/assets/taskReview-_WCgnQit.js +1 -0
  28. package/dist/web/assets/ui-BGK72r3u.js +1 -0
  29. package/dist/web/assets/workTarget-CySfKyfB.js +30 -0
  30. package/dist/web/index.html +4 -4
  31. package/docs/architecture.md +610 -33
  32. package/docs/development.md +61 -17
  33. package/docs/how-to-use.md +554 -17
  34. package/docs/installation.md +235 -144
  35. package/docs/publishing.md +1 -1
  36. package/lib/cli/agentsStatus.js +197 -0
  37. package/lib/cli/args.js +111 -2
  38. package/lib/cli/guide.js +27 -0
  39. package/lib/cli/guide.md +214 -0
  40. package/lib/cli/help.js +74 -1
  41. package/lib/cli/main.js +97 -17
  42. package/lib/cli/metricsCommands.js +77 -0
  43. package/lib/cli/output.js +19 -1
  44. package/lib/cli/preflightCommands.js +7 -1
  45. package/lib/cli/project.js +13 -24
  46. package/lib/cli/qualityCommands.js +188 -0
  47. package/lib/cli/readOnly.js +17 -0
  48. package/lib/cli/requestCommands.js +33 -4
  49. package/lib/cli/requirementCommands.js +288 -0
  50. package/lib/cli/retroCommands.js +106 -0
  51. package/lib/cli/revisitCommands.js +73 -0
  52. package/lib/cli/showView.js +183 -4
  53. package/lib/cli/taskCommands.js +341 -20
  54. package/lib/cli/taskReviewCommands.js +178 -0
  55. package/lib/cli/userConfig.js +47 -0
  56. package/lib/core/completionRefs.js +46 -0
  57. package/lib/core/context.js +4 -1
  58. package/lib/core/metrics/definitions.js +434 -0
  59. package/lib/core/metrics/index.js +88 -0
  60. package/lib/core/metrics/manual.js +180 -0
  61. package/lib/core/milestoneReview/material.js +11 -1
  62. package/lib/core/milestoneReview/mockReviewer.js +1 -0
  63. package/lib/core/milestoneReview/review.js +70 -6
  64. package/lib/core/milestoneReview/service.js +29 -93
  65. package/lib/core/milestoneReview/store.js +12 -62
  66. package/lib/core/ops.js +23 -3
  67. package/lib/core/preflight/carryover.js +6 -2
  68. package/lib/core/preflight/codexEngine.js +34 -17
  69. package/lib/core/preflight/diagnose.js +4 -9
  70. package/lib/core/preflight/engine.js +15 -0
  71. package/lib/core/preflight/hostPaths.js +260 -0
  72. package/lib/core/preflight/input.js +33 -5
  73. package/lib/core/preflight/instructions.js +36 -2
  74. package/lib/core/preflight/mockEngine.js +24 -2
  75. package/lib/core/preflight/render.js +22 -3
  76. package/lib/core/preflight/service.js +99 -8
  77. package/lib/core/preflight/uiRender.js +3 -0
  78. package/lib/core/projectRegistry.js +3 -3
  79. package/lib/core/quality.js +21 -0
  80. package/lib/core/qualityImprovement.js +221 -0
  81. package/lib/core/requestOps.js +294 -11
  82. package/lib/core/retrospective.js +208 -0
  83. package/lib/core/reviewCandidates.js +56 -0
  84. package/lib/core/reviewRuns.js +205 -0
  85. package/lib/core/store/archivedTasks.js +74 -0
  86. package/lib/core/store/collection.js +32 -3
  87. package/lib/core/store/normalize.js +35 -2
  88. package/lib/core/store/preflightStore.js +23 -1
  89. package/lib/core/store/projectFile.js +10 -0
  90. package/lib/core/store/workspace.js +49 -3
  91. package/lib/core/taskReview/material.js +459 -0
  92. package/lib/core/taskReview/mockReviewer.js +30 -0
  93. package/lib/core/taskReview/paths.js +15 -0
  94. package/lib/core/taskReview/review.js +312 -0
  95. package/lib/core/taskReview/service.js +187 -0
  96. package/lib/core/taskReview/store.js +214 -0
  97. package/lib/server/api/manifest.js +104 -5
  98. package/lib/server/api/milestoneReviewRoutes.js +4 -3
  99. package/lib/server/api/routes.js +265 -17
  100. package/lib/server/api/taskReviewRoutes.js +66 -0
  101. package/lib/server/server.js +2 -2
  102. package/lib/shared/acceptance.js +618 -0
  103. package/lib/shared/completionRecord.js +327 -0
  104. package/lib/shared/metrics.js +42 -0
  105. package/lib/shared/milestoneReview.js +2 -1
  106. package/lib/shared/preflightInput.js +1 -1
  107. package/lib/shared/quality.js +391 -0
  108. package/lib/shared/qualityImprovement.js +1 -0
  109. package/lib/shared/qualityTemplates.js +31 -0
  110. package/lib/shared/requirementSource.js +635 -0
  111. package/lib/shared/retrospective.js +286 -0
  112. package/lib/shared/reviewCandidate.js +308 -0
  113. package/lib/shared/reworkHistory.js +81 -0
  114. package/lib/shared/taskBlock.js +142 -0
  115. package/lib/shared/taskReview.js +56 -0
  116. package/package.json +3 -2
  117. package/skills/p3/SKILL.md +9 -152
  118. package/dist/web/assets/Outputs-ddwte0jj.js +0 -1
  119. package/dist/web/assets/RequestStatus-Bg1OLbRc.js +0 -1
  120. package/dist/web/assets/Tabs-DTmggzgg.js +0 -1
  121. package/dist/web/assets/TagInput-BHAgjLP7.js +0 -1
  122. package/dist/web/assets/TaskDrawer-Dz_5c2NH.js +0 -3
  123. package/dist/web/assets/_requestId-D9-gtIcG.js +0 -1
  124. package/dist/web/assets/_requestId-DzCNYvqf.js +0 -30
  125. package/dist/web/assets/appCtx-Cm24VpAf.js +0 -1
  126. package/dist/web/assets/board-MCHcZ-PU.js +0 -1
  127. package/dist/web/assets/done-zq10Bt08.js +0 -1
  128. package/dist/web/assets/draft-CfJeyLOl.js +0 -1
  129. package/dist/web/assets/index-Ce0ndpne.js +0 -12
  130. package/dist/web/assets/index-D68mkSnw.css +0 -2
  131. package/dist/web/assets/new-9TKiNT4O.js +0 -1
  132. package/dist/web/assets/preflightInput-BAeEJYUK.js +0 -2
  133. package/dist/web/assets/preload-helper-FBLw7u7x.js +0 -1
  134. package/dist/web/assets/release-notes-hK5XezLW.js +0 -5
  135. package/dist/web/assets/requestData-BnN7mctX.js +0 -1
  136. package/dist/web/assets/routes-usHwrrA0.js +0 -3
  137. package/dist/web/assets/settings-BVZDnL6O.js +0 -1
  138. package/dist/web/assets/workTarget-Cijqq4yH.js +0 -1
@@ -0,0 +1,391 @@
1
+ /**
2
+ * プロジェクトの品質基準(project.yaml の quality)。プロジェクトとして守る最低限の水準(規約・構成・検証・文書など)を、
3
+ * 安定した ID の項目として持つ。CLI・API・画面で同じ規則を使う(保存は core/quality.ts)。
4
+ *
5
+ * - 状態: unset(quality が無い。初めて作るときの状態に任せている)/ set(設定済み。意図して空でもよい)/ invalid(読めない値がある)
6
+ * - 項目: { id: Q1.., text, repos?(無い・空は全部の参照先), check(machine: コマンドと成功の条件 / manual: 人が確かめる方法・参照の資料),
7
+ * exempt?(適用の除外。理由が要る), source?(採用したテンプレートの項目) }
8
+ * - ID は追加のときに振り、消した ID を別の内容に使い直さない(seq に振った最後の番号を残す)
9
+ * - P3 はコマンドを実行しない・依存を入れない。確認の方法は CI・手元の作業・外の自動化のどれでもよい(特定の製品・フォルダを必須にしない)
10
+ * - テンプレートは同梱の版つきの例で、業界の標準への認証ではない。採用すると編集できる実体に写す。テンプレートが改版しても採用済みの
11
+ * 内容は変わらない(差分を見て明示して当てる)
12
+ */
13
+ export const QUALITY_LIMITS = {
14
+ standards: 100,
15
+ text: 1000,
16
+ command: 500,
17
+ success: 500,
18
+ reference: 1000,
19
+ reason: 500,
20
+ };
21
+ export function qualitySnapshot(state, version) {
22
+ const st = state ?? { state: "unset" };
23
+ if (st.state === "set")
24
+ return { state: "set", version: version ?? "", standards: structuredClone(st.config.standards) };
25
+ if (st.state === "invalid")
26
+ return { state: "invalid", version: version ?? "", problems: [...st.problems] };
27
+ return { state: "unset", version: version ?? "" };
28
+ }
29
+ export class QualityInputError extends Error {
30
+ code;
31
+ constructor(code, message) {
32
+ super(message);
33
+ this.code = code;
34
+ }
35
+ }
36
+ export const QUALITY_ID_RE = /^Q\d+$/;
37
+ // --- 読む ---------------------------------------------------------------------
38
+ const str = (v) => (typeof v === "string" ? v.trim() : undefined);
39
+ function readCheck(v) {
40
+ if (!v || typeof v !== "object")
41
+ return "check がありません(kind: machine / manual)";
42
+ const o = v;
43
+ if (o.kind === "machine") {
44
+ const command = str(o.command);
45
+ const success = str(o.success);
46
+ if (!command || !success)
47
+ return "machine の check には command と success が要ります";
48
+ return { kind: "machine", command, success };
49
+ }
50
+ if (o.kind === "manual") {
51
+ const reference = str(o.reference);
52
+ if (!reference)
53
+ return "manual の check には reference(確かめ方・参照の資料)が要ります";
54
+ return { kind: "manual", reference };
55
+ }
56
+ return "check の kind は machine か manual です";
57
+ }
58
+ /**
59
+ * project.yaml の quality を読む。無ければ unset、読めない値があれば invalid(理由つき。ファイルは書き換えない)。
60
+ * repoNames: 今の参照先(知らない参照先は警告にする。読める)
61
+ */
62
+ export function readQuality(raw, repoNames = []) {
63
+ if (raw === undefined)
64
+ return { state: "unset" };
65
+ if (raw === null || typeof raw !== "object" || Array.isArray(raw))
66
+ return { state: "invalid", problems: ["quality は standards を持つ対応(マップ)にしてください"] };
67
+ const o = raw;
68
+ const problems = [];
69
+ const warnings = [];
70
+ const list = o.standards ?? [];
71
+ if (!Array.isArray(list))
72
+ return { state: "invalid", problems: ["quality.standards が並びになっていません"] };
73
+ const standards = [];
74
+ for (const [i, x] of list.entries()) {
75
+ const s = x && typeof x === "object" ? x : {};
76
+ const id = str(s.id) ?? "";
77
+ const at = `品質基準 ${i + 1} 件目${id ? `(${id})` : ""}`;
78
+ if (!QUALITY_ID_RE.test(id)) {
79
+ problems.push(`${at} の id が読めません(Q1, Q2, ...)`);
80
+ continue;
81
+ }
82
+ if (standards.some((x) => x.id === id)) {
83
+ problems.push(`品質基準の id が重複しています: ${id}`);
84
+ continue;
85
+ }
86
+ const text = str(s.text);
87
+ if (!text) {
88
+ problems.push(`${at} の text が空です`);
89
+ continue;
90
+ }
91
+ const check = readCheck(s.check);
92
+ if (typeof check === "string") {
93
+ problems.push(`${at}: ${check}`);
94
+ continue;
95
+ }
96
+ const repos = Array.isArray(s.repos) ? s.repos.map((r) => String(r).trim()).filter(Boolean) : undefined;
97
+ for (const r of repos ?? [])
98
+ if (repoNames.length && !repoNames.includes(r))
99
+ warnings.push(`${id} の対象の参照先 ${r} は登録されていません`);
100
+ let exempt;
101
+ if (s.exempt !== undefined && s.exempt !== null) {
102
+ const reason = s.exempt && typeof s.exempt === "object" ? str(s.exempt.reason) : undefined;
103
+ if (!reason) {
104
+ problems.push(`${at} の適用の除外に理由がありません(exempt.reason)`);
105
+ continue;
106
+ }
107
+ exempt = { reason };
108
+ }
109
+ const src = s.source && typeof s.source === "object" ? s.source : undefined;
110
+ const source = src && str(src.template) && str(src.key) && Number.isInteger(src.version) ? { template: str(src.template), version: src.version, key: str(src.key) } : undefined;
111
+ standards.push({ id, text, ...(repos?.length ? { repos } : {}), check, ...(exempt ? { exempt } : {}), ...(source ? { source } : {}) });
112
+ }
113
+ if (standards.length > QUALITY_LIMITS.standards)
114
+ problems.push(`品質基準は ${QUALITY_LIMITS.standards} 件までです`);
115
+ const templates = Array.isArray(o.templates)
116
+ ? o.templates.flatMap((t) => {
117
+ const x = t && typeof t === "object" ? t : {};
118
+ return str(x.id) && Number.isInteger(x.version) ? [{ id: str(x.id), version: x.version }] : [];
119
+ })
120
+ : undefined;
121
+ const seq = Number.isInteger(o.seq) && o.seq >= 0 ? o.seq : undefined;
122
+ if (problems.length)
123
+ return { state: "invalid", problems };
124
+ return { state: "set", config: { ...(templates?.length ? { templates } : {}), standards, ...(seq !== undefined ? { seq } : {}) }, ...(warnings.length ? { warnings } : {}) };
125
+ }
126
+ /** 書く形(読み直すと同じになる) */
127
+ export function qualityPlain(c) {
128
+ return {
129
+ ...(c.templates?.length ? { templates: c.templates.map((t) => ({ id: t.id, version: t.version })) } : {}),
130
+ standards: c.standards.map((s) => ({
131
+ id: s.id,
132
+ text: s.text,
133
+ ...(s.repos?.length ? { repos: [...s.repos] } : {}),
134
+ check: s.check.kind === "machine" ? { kind: "machine", command: s.check.command, success: s.check.success } : { kind: "manual", reference: s.check.reference },
135
+ ...(s.exempt ? { exempt: { reason: s.exempt.reason } } : {}),
136
+ ...(s.source ? { source: { ...s.source } } : {}),
137
+ })),
138
+ ...(c.seq ? { seq: c.seq } : {}),
139
+ };
140
+ }
141
+ /** 品質の設定の版(中身の hash。無い・読めないは別の値)。保存の前に比べる */
142
+ export function qualityVersion(state, raw) {
143
+ const key = state.state === "set" ? JSON.stringify(qualityPlain(state.config)) : state.state === "unset" ? "unset" : `invalid:${JSON.stringify(raw ?? null)}`;
144
+ return fnv(key);
145
+ }
146
+ /** 依存を足さない短い hash(版の比較だけに使う) */
147
+ function fnv(s) {
148
+ let h1 = 0x811c9dc5;
149
+ let h2 = 0x01000193;
150
+ for (let i = 0; i < s.length; i++) {
151
+ const c = s.charCodeAt(i);
152
+ h1 = Math.imul(h1 ^ c, 0x01000193) >>> 0;
153
+ h2 = Math.imul(h2 ^ c, 0x85ebca6b) >>> 0;
154
+ }
155
+ return `${h1.toString(16).padStart(8, "0")}${h2.toString(16).padStart(8, "0")}`;
156
+ }
157
+ function clean(raw, label, max) {
158
+ const t = (raw ?? "").trim();
159
+ if (!t)
160
+ throw new QualityInputError("quality_invalid", `${label}を書いてください`);
161
+ if (t.length > max)
162
+ throw new QualityInputError("quality_invalid", `${label}は ${max} 文字までです(${t.length} 文字)`);
163
+ return t;
164
+ }
165
+ function cleanCheck(c) {
166
+ if (!c)
167
+ throw new QualityInputError("quality_invalid", "確認の方法(機械の検査か人の確認)を選んでください");
168
+ if (c.kind === "machine")
169
+ return { kind: "machine", command: clean(c.command, "検査のコマンド", QUALITY_LIMITS.command), success: clean(c.success, "成功の条件", QUALITY_LIMITS.success) };
170
+ if (c.kind === "manual")
171
+ return { kind: "manual", reference: clean(c.reference, "確かめ方・参照の資料", QUALITY_LIMITS.reference) };
172
+ throw new QualityInputError("quality_invalid", "確認の方法は machine か manual です");
173
+ }
174
+ function cleanRepos(repos, repoNames) {
175
+ const list = [...new Set((repos ?? []).map((r) => r.trim()).filter(Boolean))];
176
+ for (const r of list)
177
+ if (!repoNames.includes(r))
178
+ throw new QualityInputError("quality_invalid", `参照先 ${r} は登録されていません(${repoNames.join(", ") || "参照先なし"})`);
179
+ return list.length ? list : undefined;
180
+ }
181
+ function checkSource(src, templates) {
182
+ const t = templates.find((x) => x.id === src.template && x.version === src.version);
183
+ if (!t?.items.some((i) => i.key === src.key))
184
+ throw new QualityInputError("quality_invalid", `テンプレートの項目 ${src.template}@${src.version}:${src.key} はありません`);
185
+ return { template: src.template, version: src.version, key: src.key };
186
+ }
187
+ const lastSeq = (c) => c.standards.reduce((n, s) => Math.max(n, Number(s.id.slice(1))), c.seq ?? 0);
188
+ /** 操作を順に当てた後の設定(何も書かない。合わなければ QualityInputError で1件も当てない) */
189
+ export function applyQualityOps(state, ops, ctx) {
190
+ if (state.state === "invalid")
191
+ throw new QualityInputError("quality_unreadable", `project.yaml の quality が読めないため変えられません。ファイルを直してください: ${state.problems.join(" / ")}`);
192
+ let c = state.state === "set" ? structuredClone(state.config) : { standards: [] };
193
+ let seq = lastSeq(c);
194
+ const find = (id) => {
195
+ const s = c.standards.find((x) => x.id === id);
196
+ if (!s)
197
+ throw new QualityInputError("quality_invalid", `品質基準 ${id} はありません`);
198
+ return s;
199
+ };
200
+ for (const op of ops) {
201
+ switch (op.op) {
202
+ case "init":
203
+ break;
204
+ case "adopt": {
205
+ const t = ctx.templates.find((x) => x.id === op.template && (op.version === undefined || x.version === op.version));
206
+ if (!t)
207
+ throw new QualityInputError("quality_invalid", `テンプレート ${op.template}${op.version ? `@${op.version}` : ""} はありません(${ctx.templates.map((x) => `${x.id}@${x.version}`).join(", ")})`);
208
+ if (c.templates?.some((x) => x.id === t.id))
209
+ throw new QualityInputError("quality_invalid", `テンプレート ${t.id} は採用済みです(更新は差分を見て当ててください)`);
210
+ for (const item of t.items) {
211
+ seq += 1;
212
+ c.standards.push({ id: `Q${seq}`, text: item.text, check: structuredClone(item.check), source: { template: t.id, version: t.version, key: item.key } });
213
+ }
214
+ c.templates = [...(c.templates ?? []), { id: t.id, version: t.version }];
215
+ break;
216
+ }
217
+ case "upgrade": {
218
+ const d = templateDiffs(c, ctx.templates).find((x) => x.template === op.template);
219
+ if (!d)
220
+ throw new QualityInputError("quality_invalid", `テンプレート ${op.template} に当てる差分はありません`);
221
+ const latest = ctx.templates.find((t) => t.id === d.template && t.version === d.to);
222
+ const at = (key) => latest.items.find((i) => i.key === key);
223
+ c = {
224
+ ...c,
225
+ standards: c.standards.map((x) => {
226
+ if (x.source?.template !== d.template)
227
+ return x;
228
+ if (d.changed.some((ch) => ch.key === x.source.key))
229
+ return { ...x, text: at(x.source.key).text, check: structuredClone(at(x.source.key).check), source: { ...x.source, version: d.to } };
230
+ if (d.removed.some((r) => r.key === x.source.key))
231
+ return (({ source: _s, ...rest }) => rest)(x);
232
+ return { ...x, source: { ...x.source, version: d.to } };
233
+ }),
234
+ };
235
+ for (const a of d.added) {
236
+ seq += 1;
237
+ c.standards.push({ id: `Q${seq}`, text: a.text, check: structuredClone(at(a.key).check), source: { template: d.template, version: d.to, key: a.key } });
238
+ }
239
+ c.templates = (c.templates ?? []).map((t) => (t.id === d.template ? { id: t.id, version: d.to } : t));
240
+ break;
241
+ }
242
+ case "replace": {
243
+ const seen = new Set();
244
+ const next = op.standards.map((row) => {
245
+ const cur = row.id ? find(row.id) : undefined;
246
+ if (row.id && seen.has(row.id))
247
+ throw new QualityInputError("quality_invalid", `品質基準 ${row.id} が2回あります`);
248
+ if (row.id)
249
+ seen.add(row.id);
250
+ const repos = cleanRepos(row.repos, ctx.repoNames);
251
+ const reason = row.exemptReason?.trim();
252
+ if (reason !== undefined && reason.length > QUALITY_LIMITS.reason)
253
+ throw new QualityInputError("quality_invalid", `適用の除外の理由は ${QUALITY_LIMITS.reason} 文字までです`);
254
+ const id = cur?.id ?? `Q${++seq}`;
255
+ return {
256
+ id,
257
+ text: clean(row.text, `品質基準 ${id} の文`, QUALITY_LIMITS.text),
258
+ ...(repos ? { repos } : {}),
259
+ check: cleanCheck(row.check),
260
+ ...(reason ? { exempt: { reason } } : {}),
261
+ ...(cur?.source ? { source: cur.source } : row.source ? { source: checkSource(row.source, ctx.templates) } : {}),
262
+ };
263
+ });
264
+ const adopted = [...(c.templates ?? [])];
265
+ for (const t of op.templates ?? []) {
266
+ if (!ctx.templates.some((x) => x.id === t.id && x.version === t.version))
267
+ throw new QualityInputError("quality_invalid", `テンプレート ${t.id}@${t.version} はありません`);
268
+ if (!adopted.some((x) => x.id === t.id))
269
+ adopted.push({ id: t.id, version: t.version });
270
+ }
271
+ c = { ...c, standards: next, ...(adopted.length ? { templates: adopted } : {}) };
272
+ break;
273
+ }
274
+ case "add": {
275
+ seq += 1;
276
+ c.standards.push({ id: `Q${seq}`, text: clean(op.standard.text, "品質基準の文", QUALITY_LIMITS.text), ...(cleanRepos(op.standard.repos, ctx.repoNames) ? { repos: cleanRepos(op.standard.repos, ctx.repoNames) } : {}), check: cleanCheck(op.standard.check) });
277
+ break;
278
+ }
279
+ case "edit": {
280
+ const s = find(op.id);
281
+ const next = {
282
+ ...s,
283
+ ...(op.standard.text !== undefined ? { text: clean(op.standard.text, "品質基準の文", QUALITY_LIMITS.text) } : {}),
284
+ ...(op.standard.check !== undefined ? { check: cleanCheck(op.standard.check) } : {}),
285
+ };
286
+ if (op.standard.repos !== undefined) {
287
+ const r = cleanRepos(op.standard.repos, ctx.repoNames);
288
+ if (r)
289
+ next.repos = r;
290
+ else
291
+ delete next.repos;
292
+ }
293
+ c = { ...c, standards: c.standards.map((x) => (x.id === s.id ? next : x)) };
294
+ break;
295
+ }
296
+ case "remove":
297
+ find(op.id);
298
+ c = { ...c, standards: c.standards.filter((x) => x.id !== op.id) };
299
+ break;
300
+ case "exempt": {
301
+ const s = find(op.id);
302
+ const reason = clean(op.reason, "適用の除外の理由", QUALITY_LIMITS.reason);
303
+ c = { ...c, standards: c.standards.map((x) => (x.id === s.id ? { ...x, exempt: { reason } } : x)) };
304
+ break;
305
+ }
306
+ case "unexempt": {
307
+ const s = find(op.id);
308
+ c = { ...c, standards: c.standards.map((x) => (x.id === s.id ? (({ exempt: _e, ...rest }) => rest)(x) : x)) };
309
+ break;
310
+ }
311
+ default:
312
+ throw new QualityInputError("quality_invalid", `知らない操作です: ${String(op.op)}`);
313
+ }
314
+ }
315
+ if (c.standards.length > QUALITY_LIMITS.standards)
316
+ throw new QualityInputError("quality_invalid", `品質基準は ${QUALITY_LIMITS.standards} 件までです`);
317
+ return { ...c, ...(seq > 0 ? { seq } : {}) };
318
+ }
319
+ /** 参照先に当てはまる品質基準(除外したものは別に返す)。repo が null(作業先なし)なら全体の基準だけ */
320
+ export function standardsFor(config, repo) {
321
+ const hit = config.standards.filter((s) => !s.repos?.length || (repo ? s.repos.includes(repo) : false));
322
+ return { applies: hit.filter((s) => !s.exempt), exempt: hit.filter((s) => s.exempt) };
323
+ }
324
+ /** 確認の方法の一行 */
325
+ export const checkLine = (c) => (c.kind === "machine" ? `検査: ${c.command}(成功: ${c.success})` : `人の確認: ${c.reference}`);
326
+ export function templateDiffs(config, templates) {
327
+ const out = [];
328
+ for (const used of config.templates ?? []) {
329
+ const latest = templates.filter((t) => t.id === used.id).sort((a, b) => b.version - a.version)[0];
330
+ if (!latest || latest.version <= used.version)
331
+ continue;
332
+ const old = templates.find((t) => t.id === used.id && t.version === used.version);
333
+ const mine = config.standards.filter((s) => s.source?.template === used.id);
334
+ const idsOf = (key) => mine.filter((s) => s.source?.key === key).map((s) => s.id);
335
+ const added = latest.items.filter((i) => !old?.items.some((o) => o.key === i.key)).map((i) => ({ key: i.key, text: i.text }));
336
+ const changed = latest.items
337
+ .filter((i) => {
338
+ const o = old?.items.find((x) => x.key === i.key);
339
+ return o && JSON.stringify([o.text, o.check]) !== JSON.stringify([i.text, i.check]);
340
+ })
341
+ .map((i) => ({ key: i.key, ids: idsOf(i.key), text: i.text }));
342
+ const removed = (old?.items ?? []).filter((o) => !latest.items.some((i) => i.key === o.key)).map((o) => ({ key: o.key, ids: idsOf(o.key) }));
343
+ out.push({ template: used.id, from: used.version, to: latest.version, added, changed, removed });
344
+ }
345
+ return out;
346
+ }
347
+ // --- タスクの受け入れ基準への取り込み -----------------------------------------------
348
+ /** 項目の中身の hash(文・確認の方法・対象。取り込んだ後に変わったかを見る) */
349
+ export const standardHash = (s) => fnv(JSON.stringify([s.text, s.check, s.repos ?? []]));
350
+ /** 受け入れ基準に取り込むときの文(品質 ID と確認の方法を添える) */
351
+ export const qualityCriterionText = (s) => `[${s.id}] ${s.text}(${checkLine(s.check)})`;
352
+ /** 取り込む受け入れ基準(作業先に当てはまり、除外していない品質基準) */
353
+ export function qualityCriteria(config, version, opts) {
354
+ const list = opts.ids ? config.standards.filter((s) => opts.ids.includes(s.id) && !s.exempt) : standardsFor(config, opts.repo).applies;
355
+ if (opts.ids) {
356
+ const missing = opts.ids.filter((id) => !config.standards.some((s) => s.id === id));
357
+ if (missing.length)
358
+ throw new QualityInputError("quality_invalid", `品質基準 ${missing.join(", ")} はありません`);
359
+ }
360
+ return list.map((s) => ({ text: qualityCriterionText(s), quality: { id: s.id, hash: standardHash(s), version } }));
361
+ }
362
+ /**
363
+ * タスクの受け入れ基準と今の品質基準の差分(読むだけ。タスクは書き換えない)。作業先が無いタスクには、取り込み済みのもの以外を足す案を出さない
364
+ */
365
+ export function taskQualityDiff(criteria, state, repo) {
366
+ if (!state || state.state !== "set")
367
+ return [];
368
+ const config = state.config;
369
+ const out = [];
370
+ const { applies, exempt } = standardsFor(config, repo);
371
+ for (const c of criteria) {
372
+ if (!c.quality)
373
+ continue;
374
+ const s = config.standards.find((x) => x.id === c.quality.id);
375
+ if (!s)
376
+ out.push({ kind: "remove", quality: c.quality.id, criterion: c.id, reason: "品質基準が消えました" });
377
+ else if (exempt.some((x) => x.id === s.id))
378
+ out.push({ kind: "exempt", quality: s.id, criterion: c.id, reason: `除外になりました: ${s.exempt.reason}` });
379
+ else if (!applies.some((x) => x.id === s.id))
380
+ out.push({ kind: "remove", quality: s.id, criterion: c.id, reason: "作業先に当てはまらなくなりました" });
381
+ else if (standardHash(s) !== c.quality.hash)
382
+ out.push({ kind: "change", quality: s.id, criterion: c.id, text: qualityCriterionText(s) });
383
+ else if (c.text !== qualityCriterionText(s))
384
+ out.push({ kind: "edited", quality: s.id, criterion: c.id, text: qualityCriterionText(s), reason: "タスクで文を直しています" });
385
+ }
386
+ if (repo)
387
+ for (const s of applies)
388
+ if (!criteria.some((c) => c.quality?.id === s.id))
389
+ out.push({ kind: "add", quality: s.id, text: qualityCriterionText(s) });
390
+ return out;
391
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,31 @@
1
+ /**
2
+ * 同梱の品質基準のテンプレート(版つきの例)。業界の標準への認証ではない。採用すると project.yaml に編集できる実体として写す。
3
+ * 中身を変えるときは版を上げて新しい項目として足す(採用済みのプロジェクトの内容は変わらず、差分を見て明示して当てる)。
4
+ * コマンドは例で、P3 は実行しない。CI・特定の製品・フォルダ名を必須にしない
5
+ */
6
+ export const QUALITY_TEMPLATES = [
7
+ {
8
+ id: "basic",
9
+ version: 1,
10
+ title: "共通の基本",
11
+ description: "どの言語でも使える最低限の水準(規約・構成と依存の向き・検証・文書の更新)",
12
+ items: [
13
+ { key: "conventions", text: "プロジェクトのコーディング規約(命名・書式・エラーの扱い)に従う", check: { kind: "manual", reference: "規約の文書(例: docs/development.md)と照らして確かめる" } },
14
+ { key: "structure", text: "決めたフォルダの構成と依存の向きを崩さない(下の層から上の層を参照しない)", check: { kind: "manual", reference: "構成・依存の向きの文書と、変えたファイルの import を確かめる" } },
15
+ { key: "verification", text: "変更に見合う自動テストを足し、プロジェクトの検証をすべて通してから完了にする", check: { kind: "manual", reference: "検証の手順(例: README・docs の「テスト」)を実行した結果を証拠に残す" } },
16
+ { key: "docs", text: "使い方・設計が変わったら、同じ変更で文書を直す", check: { kind: "manual", reference: "変えた振る舞いを説明している文書の箇所を確かめる" } },
17
+ ],
18
+ },
19
+ {
20
+ id: "typescript",
21
+ version: 1,
22
+ title: "TypeScript の例",
23
+ description: "TypeScript のプロジェクトでよく使う機械の検査(コマンドはプロジェクトに合わせて直す)",
24
+ items: [
25
+ { key: "typecheck", text: "型検査が通る", check: { kind: "machine", command: "npm run typecheck(例: tsc --noEmit)", success: "終了コード 0・エラーなし" } },
26
+ { key: "lint", text: "lint が警告なしで通る", check: { kind: "machine", command: "npm run lint", success: "終了コード 0・警告なし" } },
27
+ { key: "test", text: "自動テストが通る", check: { kind: "machine", command: "npm test", success: "終了コード 0・失敗なし" } },
28
+ { key: "build", text: "ビルドが通る", check: { kind: "machine", command: "npm run build", success: "終了コード 0" } },
29
+ ],
30
+ },
31
+ ];