@infodb/p3 0.10.0 → 0.12.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 (104) hide show
  1. package/README.md +6 -1
  2. package/dist/web/assets/ImprovementDialog-kQaVBGWH.js +1 -0
  3. package/dist/web/assets/Outputs-_nU_p3nu.js +1 -0
  4. package/dist/web/assets/{RequestStatus-DGaoQoIa.js → RequestStatus-RG-OVQYY.js} +1 -1
  5. package/dist/web/assets/{Tabs-D16MqQxu.js → Tabs-ew9i5SKX.js} +1 -1
  6. package/dist/web/assets/TagInput-BtlJTF7i.js +1 -0
  7. package/dist/web/assets/TaskDrawer-DW8GyJqI.js +6 -0
  8. package/dist/web/assets/_requestId-6Nb727dD.js +1 -0
  9. package/dist/web/assets/_requestId-BykTgPax.js +1 -0
  10. package/dist/web/assets/appCtx-CxDdXABS.js +1 -0
  11. package/dist/web/assets/archive-Ckh295Xe.js +1 -0
  12. package/dist/web/assets/board-BVAIjK-Y.js +1 -0
  13. package/dist/web/assets/done-BGfA-3MA.js +1 -0
  14. package/dist/web/assets/index-CgRU744I.css +2 -0
  15. package/dist/web/assets/index-DacQ0yl4.js +12 -0
  16. package/dist/web/assets/{new-ChFzBoL2.js → new-DVygWvVc.js} +1 -1
  17. package/dist/web/assets/outputs-B6xDsLZf.js +1 -0
  18. package/dist/web/assets/preload-helper-DyCqp21K.js +1 -0
  19. package/dist/web/assets/quality-Pu6EISAM.js +1 -0
  20. package/dist/web/assets/release-notes-CCpzyiNf.js +5 -0
  21. package/dist/web/assets/requestData-D5vBnuMh.js +1 -0
  22. package/dist/web/assets/routes-Q91zvNc0.js +4 -0
  23. package/dist/web/assets/settings-BzRgcmUm.js +1 -0
  24. package/dist/web/assets/taskReview-_WCgnQit.js +1 -0
  25. package/dist/web/assets/workTarget-C9c57JAO.js +30 -0
  26. package/dist/web/index.html +4 -4
  27. package/docs/architecture.md +392 -3
  28. package/docs/development.md +1 -1
  29. package/docs/how-to-use.md +261 -5
  30. package/docs/installation.md +5 -5
  31. package/lib/cli/args.js +45 -0
  32. package/lib/cli/help.js +43 -1
  33. package/lib/cli/main.js +42 -4
  34. package/lib/cli/output.js +9 -1
  35. package/lib/cli/preflightCommands.js +7 -1
  36. package/lib/cli/project.js +3 -0
  37. package/lib/cli/qualityCommands.js +163 -0
  38. package/lib/cli/readOnly.js +2 -0
  39. package/lib/cli/requestCommands.js +219 -14
  40. package/lib/cli/showView.js +69 -3
  41. package/lib/cli/taskCommands.js +312 -17
  42. package/lib/cli/taskReviewCommands.js +178 -0
  43. package/lib/core/context.js +7 -1
  44. package/lib/core/milestoneReview/code.js +129 -0
  45. package/lib/core/milestoneReview/material.js +148 -0
  46. package/lib/core/milestoneReview/mockReviewer.js +28 -0
  47. package/lib/core/milestoneReview/review.js +325 -0
  48. package/lib/core/milestoneReview/service.js +214 -0
  49. package/lib/core/milestoneReview/store.js +176 -0
  50. package/lib/core/ops.js +9 -2
  51. package/lib/core/preflight/carryover.js +1 -1
  52. package/lib/core/preflight/codexEngine.js +20 -6
  53. package/lib/core/preflight/engine.js +6 -0
  54. package/lib/core/preflight/instructions.js +18 -1
  55. package/lib/core/preflight/mockEngine.js +4 -0
  56. package/lib/core/preflight/service.js +45 -4
  57. package/lib/core/projectRegistry.js +3 -3
  58. package/lib/core/quality.js +21 -0
  59. package/lib/core/qualityImprovement.js +221 -0
  60. package/lib/core/requestOps.js +101 -6
  61. package/lib/core/reviewRuns.js +205 -0
  62. package/lib/core/store/archivedTasks.js +74 -0
  63. package/lib/core/store/collection.js +12 -2
  64. package/lib/core/store/normalize.js +43 -2
  65. package/lib/core/store/preflightStore.js +9 -1
  66. package/lib/core/store/projectFile.js +18 -1
  67. package/lib/core/store/workspace.js +122 -14
  68. package/lib/core/taskReview/material.js +452 -0
  69. package/lib/core/taskReview/mockReviewer.js +30 -0
  70. package/lib/core/taskReview/paths.js +15 -0
  71. package/lib/core/taskReview/review.js +305 -0
  72. package/lib/core/taskReview/service.js +187 -0
  73. package/lib/core/taskReview/store.js +214 -0
  74. package/lib/server/api/manifest.js +74 -5
  75. package/lib/server/api/milestoneReviewRoutes.js +70 -0
  76. package/lib/server/api/routes.js +164 -20
  77. package/lib/server/api/taskReviewRoutes.js +66 -0
  78. package/lib/server/server.js +2 -2
  79. package/lib/shared/acceptance.js +378 -0
  80. package/lib/shared/milestoneGoals.js +57 -0
  81. package/lib/shared/milestoneReview.js +27 -0
  82. package/lib/shared/quality.js +391 -0
  83. package/lib/shared/qualityImprovement.js +1 -0
  84. package/lib/shared/qualityTemplates.js +31 -0
  85. package/lib/shared/taskBlock.js +142 -0
  86. package/lib/shared/taskReview.js +56 -0
  87. package/package.json +1 -1
  88. package/skills/p3/SKILL.md +31 -2
  89. package/dist/web/assets/Outputs-B4Tr7JzU.js +0 -1
  90. package/dist/web/assets/TagInput-pSYxm4bz.js +0 -1
  91. package/dist/web/assets/TaskDrawer-1Ev3RpRV.js +0 -3
  92. package/dist/web/assets/_requestId-BKhn019m.js +0 -1
  93. package/dist/web/assets/_requestId-Btpvuu7-.js +0 -30
  94. package/dist/web/assets/appCtx-D_Iaoh2e.js +0 -1
  95. package/dist/web/assets/board-DeHdxbN4.js +0 -1
  96. package/dist/web/assets/done-BFaHGt03.js +0 -1
  97. package/dist/web/assets/index-BF1xMdJo.css +0 -2
  98. package/dist/web/assets/index-CDWcKy1L.js +0 -12
  99. package/dist/web/assets/preload-helper-hSId95YD.js +0 -1
  100. package/dist/web/assets/release-notes-BWNDFDkH.js +0 -3
  101. package/dist/web/assets/requestData-B_320uxL.js +0 -1
  102. package/dist/web/assets/routes-BBD464IS.js +0 -3
  103. package/dist/web/assets/settings-D7PPrGjT.js +0 -1
  104. package/dist/web/assets/workTarget-Cijqq4yH.js +0 -1
@@ -0,0 +1,378 @@
1
+ /**
2
+ * タスクの受け入れ基準(acceptanceCriteria)と、作業した側が項目ごとに残す証拠(acceptanceEvidence)の規則。
3
+ * CLI・API・画面で同じものを使う(保存は core/requestOps.ts の createTask / updateTask がこれで確かめる)。
4
+ *
5
+ * - 基準は { id, text } の並び。id は追加のときに振り(A1, A2, ...)、並べ替え・文言の変更で振り直さず、消した id も使い直さない
6
+ * (acceptanceSeq に振った最後の番号を残す)
7
+ * - 証拠は基準の id ごとに1件(再記録は置き換え)。記録したときの基準の文言(criterionText)を写して持つ。後で基準の文言を
8
+ * 変えたら、その証拠は「再確認が必要」(stale)として達成に数えない。基準を消しても証拠は「対応する基準のない証拠」(orphan)として残す
9
+ * - 結果は met(満たした)/ unmet(満たせなかった)/ unverified(確かめていない)。met は証拠の本文が要る
10
+ * - 証拠は作業した側の申告で、レビューの判定ではない。不足があっても完了・済みを拒まない(不足は読めるようにするだけ)
11
+ * - 直接編集で壊れた項目は黙って消さず、problems として知らせる。problems があるタスクの基準・証拠は操作で変えず、
12
+ * 関係のない更新ではファイルの元の値をそのまま書き戻す(core/store/collection.ts の keepRaw)
13
+ */
14
+ export const ACCEPTANCE_RESULTS = ["met", "unmet", "unverified"];
15
+ export const isAcceptanceResult = (v) => typeof v === "string" && ACCEPTANCE_RESULTS.includes(v);
16
+ export const ACCEPTANCE_RESULT_LABEL = {
17
+ met: "満たした",
18
+ unmet: "満たせなかった",
19
+ unverified: "未検証",
20
+ };
21
+ export const ACCEPTANCE_LIMITS = {
22
+ /** 基準の件数 */
23
+ criteria: 50,
24
+ /** 基準1件の文字数 */
25
+ text: 1000,
26
+ /** 証拠1件の文字数 */
27
+ evidence: 20000,
28
+ };
29
+ /** ファイルに書く基準・証拠の項目(壊れていたら元の値のまま書き戻す) */
30
+ export const ACCEPTANCE_KEYS = ["acceptanceCriteria", "acceptanceEvidence", "acceptanceSeq"];
31
+ /** 直接編集で書いたものも読めるよう、A<番号> 以外の英数字の id も受け付ける。新しく振るのは A<番号> だけ */
32
+ export const CRITERION_ID_RE = /^[A-Za-z0-9._-]{1,32}$/;
33
+ /** 入力が規則に合わない(何も書いていない)。CLI は使い方の誤り、API は 400 */
34
+ export class AcceptanceInputError extends Error {
35
+ code = "acceptance_invalid";
36
+ }
37
+ // --- 読む ---------------------------------------------------------------------
38
+ const text = (v) => (typeof v === "string" ? v : typeof v === "number" ? String(v) : undefined);
39
+ const iso = (v) => (v instanceof Date ? v.toISOString() : typeof v === "string" && v ? v : undefined);
40
+ /**
41
+ * frontmatter の値を読む。読めない項目は除いて problems に理由を足す(ファイルは書き換えない)。
42
+ * どちらの項目も無ければ何も足さない(基準のない古いタスクはそのまま)
43
+ */
44
+ export function readAcceptance(d) {
45
+ const problems = [];
46
+ const out = {};
47
+ if (d.acceptanceCriteria !== undefined && d.acceptanceCriteria !== null) {
48
+ const criteria = [];
49
+ if (!Array.isArray(d.acceptanceCriteria))
50
+ problems.push("acceptanceCriteria が並びになっていません");
51
+ else
52
+ for (const [i, raw] of d.acceptanceCriteria.entries()) {
53
+ const o = raw && typeof raw === "object" ? raw : {};
54
+ const id = text(o.id)?.trim() ?? "";
55
+ const t = text(o.text)?.trim() ?? "";
56
+ const at = `受け入れ基準 ${i + 1} 件目${id ? `(${id})` : ""}`;
57
+ if (!CRITERION_ID_RE.test(id))
58
+ problems.push(`${at} の id が読めません`);
59
+ else if (criteria.some((c) => c.id === id))
60
+ problems.push(`受け入れ基準の id が重複しています: ${id}`);
61
+ else if (!t)
62
+ problems.push(`${at} の文が空です`);
63
+ else if (o.quality !== undefined && !qualitySourceOf(o.quality))
64
+ problems.push(`${at} の品質基準の出典(quality)が読めません(id・hash・version が要ります)`);
65
+ else
66
+ criteria.push({ id, text: t, ...(o.quality !== undefined ? { quality: qualitySourceOf(o.quality) } : {}) });
67
+ }
68
+ out.acceptanceCriteria = criteria;
69
+ }
70
+ if (d.acceptanceEvidence !== undefined && d.acceptanceEvidence !== null) {
71
+ const evidence = [];
72
+ if (!Array.isArray(d.acceptanceEvidence))
73
+ problems.push("acceptanceEvidence が並びになっていません");
74
+ else
75
+ for (const [i, raw] of d.acceptanceEvidence.entries()) {
76
+ const o = raw && typeof raw === "object" ? raw : {};
77
+ const id = text(o.criterionId)?.trim() ?? "";
78
+ const at = `証拠 ${i + 1} 件目${id ? `(${id})` : ""}`;
79
+ const body = text(o.evidence) ?? "";
80
+ if (!CRITERION_ID_RE.test(id))
81
+ problems.push(`${at} の criterionId が読めません`);
82
+ else if (evidence.some((e) => e.criterionId === id))
83
+ problems.push(`${id} の証拠が重複しています`);
84
+ else if (!isAcceptanceResult(o.result))
85
+ problems.push(`${at} の result が読めません(${ACCEPTANCE_RESULTS.join(" / ")})`);
86
+ else if (o.result === "met" && !body.trim())
87
+ problems.push(`${at} は met ですが証拠が空です`);
88
+ else
89
+ evidence.push({
90
+ criterionId: id,
91
+ criterionText: text(o.criterionText)?.trim() ?? "",
92
+ result: o.result,
93
+ evidence: body.trim(),
94
+ recordedAt: iso(o.recordedAt) ?? new Date(0).toISOString(),
95
+ ...(text(o.recordedBy) ? { recordedBy: text(o.recordedBy) } : {}),
96
+ });
97
+ }
98
+ out.acceptanceEvidence = evidence;
99
+ }
100
+ if (d.acceptanceSeq !== undefined && d.acceptanceSeq !== null) {
101
+ const n = Number(d.acceptanceSeq);
102
+ if (Number.isInteger(n) && n >= 0)
103
+ out.acceptanceSeq = n;
104
+ else
105
+ problems.push("acceptanceSeq が読めません");
106
+ }
107
+ if (problems.length)
108
+ out.acceptanceProblems = problems;
109
+ return out;
110
+ }
111
+ function qualitySourceOf(v) {
112
+ if (!v || typeof v !== "object")
113
+ return undefined;
114
+ const o = v;
115
+ return typeof o.id === "string" && typeof o.hash === "string" && typeof o.version === "string" && o.id && o.hash ? { id: o.id, hash: o.hash, version: o.version } : undefined;
116
+ }
117
+ function cleanText(raw, label) {
118
+ const t = raw.trim();
119
+ if (!t)
120
+ throw new AcceptanceInputError(`${label}の文が空です`);
121
+ if (t.length > ACCEPTANCE_LIMITS.text)
122
+ throw new AcceptanceInputError(`${label}は ${ACCEPTANCE_LIMITS.text} 文字までです(${t.length} 文字)`);
123
+ return t;
124
+ }
125
+ /** 振った最後の番号(acceptanceSeq と、今ある A<番号> の大きい方。消した id を使い直さない) */
126
+ function lastSeq(s) {
127
+ const ids = [...(s.acceptanceCriteria ?? []).map((c) => c.id), ...(s.acceptanceEvidence ?? []).map((e) => e.criterionId)];
128
+ return ids.reduce((n, id) => Math.max(n, /^A(\d+)$/.exec(id) ? Number(id.slice(1)) : 0), s.acceptanceSeq ?? 0);
129
+ }
130
+ /**
131
+ * 操作を順に当てた後の基準・証拠(何も書かない。規則に合わなければ AcceptanceInputError で、1件も当てない)。
132
+ * 同じ値の再記録は元の証拠(記録した日時も)をそのまま残す
133
+ */
134
+ export function applyAcceptanceOps(state, ops, at) {
135
+ if (state.acceptanceProblems?.length) {
136
+ throw new AcceptanceInputError(`受け入れ基準・証拠のファイルの値が読めないため変えられません。ファイルを直してください: ${state.acceptanceProblems.join(" / ")}`);
137
+ }
138
+ let criteria = [...(state.acceptanceCriteria ?? [])];
139
+ let evidence = [...(state.acceptanceEvidence ?? [])];
140
+ let seq = lastSeq(state);
141
+ const find = (id) => {
142
+ const c = criteria.find((x) => x.id === id);
143
+ if (!c)
144
+ throw new AcceptanceInputError(`受け入れ基準 ${id} はありません${criteria.length ? `(${criteria.map((x) => x.id).join(", ")})` : "(基準がありません)"}`);
145
+ return c;
146
+ };
147
+ for (const op of ops) {
148
+ switch (op.op) {
149
+ case "add": {
150
+ if (criteria.length >= ACCEPTANCE_LIMITS.criteria)
151
+ throw new AcceptanceInputError(`受け入れ基準は ${ACCEPTANCE_LIMITS.criteria} 件までです`);
152
+ if (op.quality && criteria.some((c) => c.quality?.id === op.quality.id))
153
+ throw new AcceptanceInputError(`品質基準 ${op.quality.id} は取り込み済みです`);
154
+ seq += 1;
155
+ criteria.push({ id: `A${seq}`, text: cleanText(op.text, "受け入れ基準"), ...(op.quality ? { quality: { ...op.quality } } : {}) });
156
+ break;
157
+ }
158
+ case "edit": {
159
+ const c = find(op.id);
160
+ const t = cleanText(op.text, `受け入れ基準 ${op.id} `);
161
+ criteria = criteria.map((x) => (x.id === c.id ? { ...x, text: t, ...(op.quality ? { quality: { ...op.quality } } : {}) } : x));
162
+ break;
163
+ }
164
+ case "remove": {
165
+ find(op.id);
166
+ // 証拠は残す(対応する基準のない証拠として読める)
167
+ criteria = criteria.filter((x) => x.id !== op.id);
168
+ break;
169
+ }
170
+ case "order": {
171
+ const now = criteria.map((x) => x.id);
172
+ const same = op.ids.length === now.length && new Set(op.ids).size === op.ids.length && op.ids.every((id) => now.includes(id));
173
+ if (!same)
174
+ throw new AcceptanceInputError(`並べ替えは今の基準の id を全部、1回ずつ指定してください(今: ${now.join(", ") || "なし"})`);
175
+ criteria = op.ids.map((id) => criteria.find((x) => x.id === id));
176
+ break;
177
+ }
178
+ case "record": {
179
+ const c = find(op.id);
180
+ if (!isAcceptanceResult(op.result))
181
+ throw new AcceptanceInputError(`結果は ${ACCEPTANCE_RESULTS.join(" / ")} のどれかです: ${String(op.result)}`);
182
+ const body = (op.evidence ?? "").trim();
183
+ if (op.result === "met" && !body)
184
+ throw new AcceptanceInputError(`${op.id} を met にするには証拠を書いてください(通したテスト・コマンドと結果・画面の確認・リンクなど)`);
185
+ if (body.length > ACCEPTANCE_LIMITS.evidence)
186
+ throw new AcceptanceInputError(`${op.id} の証拠は ${ACCEPTANCE_LIMITS.evidence} 文字までです(${body.length} 文字)`);
187
+ const prev = evidence.find((e) => e.criterionId === c.id);
188
+ if (prev && prev.result === op.result && prev.evidence === body && prev.criterionText === c.text)
189
+ break;
190
+ const entry = { criterionId: c.id, criterionText: c.text, result: op.result, evidence: body, recordedAt: at.now, ...(at.actor ? { recordedBy: at.actor } : {}) };
191
+ evidence = prev ? evidence.map((e) => (e === prev ? entry : e)) : [...evidence, entry];
192
+ break;
193
+ }
194
+ case "unrecord": {
195
+ if (!evidence.some((e) => e.criterionId === op.id))
196
+ throw new AcceptanceInputError(`${op.id} の証拠はありません`);
197
+ evidence = evidence.filter((e) => e.criterionId !== op.id);
198
+ break;
199
+ }
200
+ default:
201
+ throw new AcceptanceInputError(`知らない操作です: ${String(op.op)}`);
202
+ }
203
+ }
204
+ return {
205
+ acceptanceCriteria: criteria.length ? criteria : undefined,
206
+ acceptanceEvidence: evidence.length ? evidence : undefined,
207
+ acceptanceSeq: seq > 0 ? seq : undefined,
208
+ };
209
+ }
210
+ /** 基準・証拠の中身が変わったか(並び・文言・結果・証拠。記録の日時と変更者・採番は見ない)。人の「済み」を外す判断に使う */
211
+ export function acceptanceChanged(a, b) {
212
+ const key = (s) => JSON.stringify([
213
+ (s.acceptanceCriteria ?? []).map((c) => [c.id, c.text]),
214
+ (s.acceptanceEvidence ?? []).map((e) => [e.criterionId, e.criterionText, e.result, e.evidence]),
215
+ ]);
216
+ return key(a) !== key(b);
217
+ }
218
+ /** 基準・証拠の状態。基準も証拠も問題も無いタスクは undefined(「受け入れ基準なし」) */
219
+ export function acceptanceStatus(t) {
220
+ const criteria = t.acceptanceCriteria ?? [];
221
+ const evidence = t.acceptanceEvidence ?? [];
222
+ const problems = t.acceptanceProblems ?? [];
223
+ if (!criteria.length && !evidence.length && !problems.length)
224
+ return undefined;
225
+ const items = criteria.map((c) => {
226
+ const e = evidence.find((x) => x.criterionId === c.id);
227
+ const state = !e ? "missing" : e.criterionText !== c.text ? "stale" : e.result;
228
+ return { id: c.id, text: c.text, state, ...(e ? { evidence: e } : {}) };
229
+ });
230
+ const orphans = evidence.filter((e) => !criteria.some((c) => c.id === e.criterionId));
231
+ const ids = (s) => items.filter((i) => i.state === s).map((i) => i.id);
232
+ const shortfalls = [
233
+ ...(ids("missing").length ? [`証拠なし: ${ids("missing").join(", ")}`] : []),
234
+ ...(ids("unmet").length ? [`満たせなかった: ${ids("unmet").join(", ")}`] : []),
235
+ ...(ids("unverified").length ? [`未検証: ${ids("unverified").join(", ")}`] : []),
236
+ ...(ids("stale").length ? [`基準を変えた後の再確認が必要: ${ids("stale").join(", ")}`] : []),
237
+ ...(orphans.length ? [`対応する基準のない証拠: ${orphans.map((e) => e.criterionId).join(", ")}`] : []),
238
+ ...problems.map((p) => `読めない: ${p}`),
239
+ ];
240
+ return { total: criteria.length, met: ids("met").length, items, orphans, problems, shortfalls };
241
+ }
242
+ // --- CLI の証拠の入力 -----------------------------------------------------------
243
+ /** `A1=met:本文` / `A1=unverified`(本文は省ける。met は本文が要る) */
244
+ export function parseEvidenceArg(arg) {
245
+ const m = /^([A-Za-z0-9._-]+)=([a-z]+)(?::([\s\S]*))?$/.exec(arg.trim());
246
+ if (!m || !isAcceptanceResult(m[2]))
247
+ throw new AcceptanceInputError(`証拠は <基準の ID>=<${ACCEPTANCE_RESULTS.join("|")}>[:本文] の形で指定してください: ${arg}`);
248
+ return { op: "record", id: m[1], result: m[2], evidence: m[3] ?? "" };
249
+ }
250
+ /**
251
+ * 証拠のファイル(Markdown)。見出し `## <基準の ID> <結果>` ごとに、次の見出しまでを証拠の本文として読む。
252
+ * 最初の見出しの前に文があれば断る(取りこぼさない)
253
+ */
254
+ export function parseEvidenceFile(src) {
255
+ const out = [];
256
+ let cur;
257
+ const lines = [];
258
+ const flush = () => {
259
+ if (cur)
260
+ out.push({ ...cur, evidence: lines.join("\n").trim() });
261
+ lines.length = 0;
262
+ };
263
+ for (const line of src.replace(/\r\n/g, "\n").split("\n")) {
264
+ const h = /^##\s+([A-Za-z0-9._-]+)\s*[::]?\s*([a-z]+)\s*$/.exec(line);
265
+ if (h) {
266
+ if (!isAcceptanceResult(h[2]))
267
+ throw new AcceptanceInputError(`証拠のファイルの見出しの結果は ${ACCEPTANCE_RESULTS.join(" / ")} のどれかです: ${line}`);
268
+ flush();
269
+ cur = { op: "record", id: h[1], result: h[2], evidence: "" };
270
+ continue;
271
+ }
272
+ if (!cur && line.trim())
273
+ throw new AcceptanceInputError(`証拠のファイルは「## <基準の ID> <結果>」の見出しから始めてください: ${line}`);
274
+ lines.push(line);
275
+ }
276
+ flush();
277
+ if (!out.length)
278
+ throw new AcceptanceInputError("証拠のファイルに「## <基準の ID> <結果>」の見出しがありません");
279
+ const dup = out.map((e) => e.id).find((id, i, a) => a.indexOf(id) !== i);
280
+ if (dup)
281
+ throw new AcceptanceInputError(`証拠のファイルに ${dup} が2回あります`);
282
+ return out;
283
+ }
284
+ // --- Preflight のタスク案の基準 ----------------------------------------------------
285
+ /**
286
+ * タスク案の基準(drafts/D1.md の acceptanceCriteria)を読む。Codex・手元のエージェントが書いた文の並び(["…"])も、
287
+ * { id, text } の並びも受け付け、id の無い項目には A<番号> を振る。読めない項目は除いて problems に理由を足す(無いのは基準なし)
288
+ */
289
+ export function readDraftCriteria(raw) {
290
+ if (raw === undefined || raw === null)
291
+ return {};
292
+ if (!Array.isArray(raw))
293
+ return { criteria: [], problems: ["acceptanceCriteria が並びになっていません(文の並びで書いてください)"] };
294
+ const problems = [];
295
+ const items = [];
296
+ for (const [i, x] of raw.entries()) {
297
+ const at = `受け入れ基準 ${i + 1} 件目`;
298
+ const o = typeof x === "string" ? { text: x } : x && typeof x === "object" ? x : undefined;
299
+ const t = o && (typeof o.text === "string" || typeof o.text === "number") ? String(o.text).trim() : "";
300
+ const id = o && (typeof o.id === "string" || typeof o.id === "number") ? String(o.id).trim() : undefined;
301
+ if (!o)
302
+ problems.push(`${at} が文になっていません`);
303
+ else if (!t)
304
+ problems.push(`${at} が空です`);
305
+ else if (t.length > ACCEPTANCE_LIMITS.text)
306
+ problems.push(`${at} は ${ACCEPTANCE_LIMITS.text} 文字までです(${t.length} 文字)`);
307
+ else if (id !== undefined && !CRITERION_ID_RE.test(id))
308
+ problems.push(`${at} の id が使えません: ${id}`);
309
+ else if (id !== undefined && items.some((c) => c.id === id))
310
+ problems.push(`受け入れ基準の id が重複しています: ${id}`);
311
+ else
312
+ items.push({ ...(id !== undefined ? { id } : {}), text: t });
313
+ }
314
+ if (items.length > ACCEPTANCE_LIMITS.criteria)
315
+ problems.push(`受け入れ基準は ${ACCEPTANCE_LIMITS.criteria} 件までです(${items.length} 件)`);
316
+ return { criteria: withIds(items), ...(problems.length ? { problems } : {}) };
317
+ }
318
+ /** id の無い項目に、今ある A<番号> の次から振る */
319
+ function withIds(items) {
320
+ let n = items.reduce((m, c) => Math.max(m, c.id && /^A(\d+)$/.exec(c.id) ? Number(c.id.slice(1)) : 0), 0);
321
+ return items.map((c) => ({ id: c.id ?? `A${++n}`, text: c.text }));
322
+ }
323
+ /**
324
+ * 人が直したタスク案の基準(並び全体の置き換え)を確かめて保存する形にする。id は残し、無い項目に振る。
325
+ * 空・長すぎる・件数・重複した id は AcceptanceInputError(何も書かない)
326
+ */
327
+ export function tidyDraftCriteria(items) {
328
+ if (items.length > ACCEPTANCE_LIMITS.criteria)
329
+ throw new AcceptanceInputError(`受け入れ基準は ${ACCEPTANCE_LIMITS.criteria} 件までです(${items.length} 件)`);
330
+ const seen = new Set();
331
+ const out = items.map((c, i) => {
332
+ const id = c.id?.trim() || undefined;
333
+ if (id !== undefined && !CRITERION_ID_RE.test(id))
334
+ throw new AcceptanceInputError(`受け入れ基準 ${i + 1} 件目の id が使えません: ${id}`);
335
+ if (id !== undefined && seen.has(id))
336
+ throw new AcceptanceInputError(`受け入れ基準の id が重複しています: ${id}`);
337
+ if (id !== undefined)
338
+ seen.add(id);
339
+ return { ...(id !== undefined ? { id } : {}), text: cleanText(c.text, `受け入れ基準 ${i + 1} 件目`) };
340
+ });
341
+ return withIds(out);
342
+ }
343
+ /** 基準の並びが同じか(id と文。タスク案の編集の競合を見る) */
344
+ export const sameCriteria = (a, b) => JSON.stringify((a ?? []).map((c) => [c.id, c.text])) === JSON.stringify((b ?? []).map((c) => [c.id, c.text]));
345
+ /** タスク案の基準からタスクの基準を作る(案の ID を残し、振った最後の番号を引き継ぐ) */
346
+ export function criteriaForTask(criteria) {
347
+ if (!criteria?.length)
348
+ return {};
349
+ return { acceptanceCriteria: criteria.map((c) => ({ ...c })), acceptanceSeq: lastSeq({ acceptanceCriteria: [...criteria] }) || undefined };
350
+ }
351
+ // --- 画面の基準の編集 ---------------------------------------------------------------
352
+ /**
353
+ * 画面で並び全体を直した結果(rows。id の無い行は新しい基準)を、今の基準(state)への操作にする:
354
+ * 消す → 文を変える → 足す → 並べる(足した基準の id は今の採番の続きになる。rev を添えて送れば、他で変わっていれば 409 で当たらない)。
355
+ * 変わっていなければ空。id が今の基準に無い行は新しい基準として足す
356
+ */
357
+ export function criteriaEditOps(state, rows) {
358
+ const cur = state.acceptanceCriteria ?? [];
359
+ const known = new Set(cur.map((c) => c.id));
360
+ const kept = rows.filter((r) => r.id !== undefined && known.has(r.id));
361
+ const keptIds = new Set(kept.map((r) => r.id));
362
+ const ops = [];
363
+ for (const c of cur)
364
+ if (!keptIds.has(c.id))
365
+ ops.push({ op: "remove", id: c.id });
366
+ for (const r of kept)
367
+ if (cur.find((c) => c.id === r.id).text !== r.text.trim())
368
+ ops.push({ op: "edit", id: r.id, text: r.text });
369
+ let seq = lastSeq(state);
370
+ const finalIds = rows.map((r) => (r.id !== undefined && keptIds.has(r.id) ? r.id : `A${++seq}`));
371
+ for (const r of rows)
372
+ if (!(r.id !== undefined && keptIds.has(r.id)))
373
+ ops.push({ op: "add", text: r.text });
374
+ const afterIds = [...cur.filter((c) => keptIds.has(c.id)).map((c) => c.id), ...finalIds.filter((id) => !keptIds.has(id))];
375
+ if (afterIds.join(",") !== finalIds.join(","))
376
+ ops.push({ op: "order", ids: finalIds });
377
+ return ops;
378
+ }
@@ -0,0 +1,57 @@
1
+ /**
2
+ * マイルストーンの目的(purpose)と予定している機能・目標(goals)の規則。CLI・API・画面で同じものを使う(保存は
3
+ * core/store/workspace.ts の saveProject がこれで確かめる)。
4
+ *
5
+ * - 目的は複数行の自由文。空は「目的なし」(project.yaml に書かない)
6
+ * - 予定機能は { id, text } の並び。id は追加のときに振り(G1, G2, ...。今ある最大の番号の次)、並べ替え・文言の変更で振り直さない
7
+ * - 目的だけ・予定機能だけでも保存できる。どちらも任意
8
+ */
9
+ export const MILESTONE_GOAL_LIMITS = {
10
+ /** 目的の文字数 */
11
+ purpose: 4000,
12
+ /** 予定機能の件数 */
13
+ goals: 50,
14
+ /** 予定機能1件の文字数 */
15
+ goalText: 500,
16
+ };
17
+ /** 予定機能の id(手で書いた project.yaml も読めるよう、G<番号> 以外の英数字も受け付ける) */
18
+ export const GOAL_ID_RE = /^[A-Za-z0-9._-]{1,32}$/;
19
+ /** 目的・予定機能の問題(保存を断る理由。無ければ空) */
20
+ export function milestoneGoalProblems(m) {
21
+ const out = [];
22
+ const at = `マイルストーン ${m.id}`;
23
+ if (m.purpose !== undefined && m.purpose.length > MILESTONE_GOAL_LIMITS.purpose) {
24
+ out.push(`${at} の目的は ${MILESTONE_GOAL_LIMITS.purpose} 文字までです(${m.purpose.length} 文字)`);
25
+ }
26
+ const goals = m.goals ?? [];
27
+ if (goals.length > MILESTONE_GOAL_LIMITS.goals)
28
+ out.push(`${at} の予定機能は ${MILESTONE_GOAL_LIMITS.goals} 件までです(${goals.length} 件)`);
29
+ const seen = new Set();
30
+ for (const [i, g] of goals.entries()) {
31
+ const label = `${at} の予定機能 ${i + 1} 件目${g.id ? `(${g.id})` : ""}`;
32
+ if (!GOAL_ID_RE.test(g.id))
33
+ out.push(`${label} の id が使えません(英数字と . _ -、32 文字まで)`);
34
+ else if (seen.has(g.id))
35
+ out.push(`${at} の予定機能の id が重複しています: ${g.id}`);
36
+ seen.add(g.id);
37
+ if (!g.text.trim())
38
+ out.push(`${label} が空です`);
39
+ else if (g.text.length > MILESTONE_GOAL_LIMITS.goalText)
40
+ out.push(`${label} は ${MILESTONE_GOAL_LIMITS.goalText} 文字までです(${g.text.length} 文字)`);
41
+ }
42
+ return out;
43
+ }
44
+ /** 次に足す予定機能の id(G<今ある最大の番号 + 1>。消した番号も、残っている最大より小さければ使わない) */
45
+ export function nextGoalId(goals) {
46
+ const max = goals.reduce((n, g) => Math.max(n, /^G(\d+)$/.exec(g.id) ? Number(g.id.slice(1)) : 0), 0);
47
+ return `G${max + 1}`;
48
+ }
49
+ /**
50
+ * 保存する形にそろえる: 目的は末尾の空白を落とし、空なら無し。予定機能は前後の空白を落とし、0 件なら無し。
51
+ * 空の項目は消さない(問題として断る)
52
+ */
53
+ export function tidyMilestoneGoals(m) {
54
+ const purpose = m.purpose?.replace(/\s+$/, "");
55
+ const goals = m.goals?.map((g) => ({ id: g.id.trim(), text: g.text.trim() }));
56
+ return { ...m, purpose: purpose ? purpose : undefined, goals: goals?.length ? goals : undefined };
57
+ }
@@ -0,0 +1,27 @@
1
+ /**
2
+ * マイルストーンレビューの形(CLI・API・画面で共有する)。保存の規則は core/milestoneReview/。
3
+ *
4
+ * レビューは、保存してあるマイルストーンの目的・予定機能に対して、参照先のリポジトリのコードと git の履歴を Codex が読み、
5
+ * 実装が目的を果たしているか・目的に無い変更(意図しない変更)が無いかを確かめる参考の記録。所属する要望・タスクの記録は
6
+ * 実装した人(AI)の自己申告として、どこを見るかの手がかりにする(それだけを達成の根拠にしない)。
7
+ * テストやアプリを実際に動かしてはいない。要望の状態・リリースノート・リリース済みは変えず、完了やリリースの条件にもしない。
8
+ */
9
+ /** 比較単位ごとの判定 */
10
+ export const REVIEW_VERDICTS = ["achieved", "partial", "not_achieved", "insufficient"];
11
+ export const REVIEW_VERDICT_LABELS = {
12
+ achieved: "達成",
13
+ partial: "一部達成",
14
+ not_achieved: "未達成",
15
+ insufficient: "判断材料不足",
16
+ };
17
+ /** 評価の範囲(結果と一緒に保存し、画面・CLI に出す) */
18
+ export const REVIEW_SCOPE = "保存してあるマイルストーンの目的・予定機能に対して、参照先のリポジトリのコードと git の履歴(抽出のときの作業ツリー・タスクに残したコミット)を読み、" +
19
+ "このマイルストーンに直接属する要望・タスクの記録を手がかりに確かめた結果です。品質基準が設定してあれば、目的の達成とは別に品質基準への適合も確かめています(検査のコマンドは実行していません)。" +
20
+ "テストやアプリを実際に動かしてはいません。公開されたかは確かめていません。" +
21
+ "成果物の URL や添付の中身は読んでいません。アーカイブした要望は含みません。";
22
+ /** 読める参照先が無いときの評価の範囲(記録だけの点検で、実装は確かめていない) */
23
+ export const REVIEW_SCOPE_RECORDS_ONLY = "読める参照先(リポジトリ)が無かったため、保存してあるマイルストーンの目的・予定機能と、直接属する要望・タスクの記録だけを比べた結果です。" +
24
+ "記録は実装した人の自己申告で、実装・実際の動作・公開されたかは確かめていません。成果物の URL や添付の中身は読んでいません。アーカイブした要望は含みません。";
25
+ export const PURPOSE_UNIT_ID = "purpose";
26
+ export const REVIEW_STATUSES = ["running", "completed", "failed", "cancelled"];
27
+ export const REVIEW_STATUS_LABELS = { running: "実行中", completed: "完了", failed: "失敗", cancelled: "取消" };