@infodb/p3 0.12.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 (113) hide show
  1. package/README.md +32 -35
  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-Pu6EISAM.js → quality-RFd-7k3r.js} +1 -1
  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/ui-BGK72r3u.js +1 -0
  28. package/dist/web/assets/workTarget-CySfKyfB.js +30 -0
  29. package/dist/web/index.html +4 -4
  30. package/docs/architecture.md +300 -36
  31. package/docs/development.md +60 -16
  32. package/docs/how-to-use.md +381 -28
  33. package/docs/installation.md +235 -144
  34. package/docs/publishing.md +1 -1
  35. package/lib/cli/agentsStatus.js +197 -0
  36. package/lib/cli/args.js +72 -8
  37. package/lib/cli/guide.js +27 -0
  38. package/lib/cli/guide.md +214 -0
  39. package/lib/cli/help.js +44 -6
  40. package/lib/cli/main.js +76 -20
  41. package/lib/cli/metricsCommands.js +77 -0
  42. package/lib/cli/output.js +12 -2
  43. package/lib/cli/project.js +13 -27
  44. package/lib/cli/qualityCommands.js +33 -8
  45. package/lib/cli/readOnly.js +15 -0
  46. package/lib/cli/requestCommands.js +21 -4
  47. package/lib/cli/requirementCommands.js +288 -0
  48. package/lib/cli/retroCommands.js +106 -0
  49. package/lib/cli/revisitCommands.js +73 -0
  50. package/lib/cli/showView.js +119 -6
  51. package/lib/cli/taskCommands.js +42 -16
  52. package/lib/cli/userConfig.js +47 -0
  53. package/lib/core/completionRefs.js +46 -0
  54. package/lib/core/metrics/definitions.js +434 -0
  55. package/lib/core/metrics/index.js +88 -0
  56. package/lib/core/metrics/manual.js +180 -0
  57. package/lib/core/ops.js +15 -2
  58. package/lib/core/preflight/carryover.js +5 -1
  59. package/lib/core/preflight/codexEngine.js +34 -17
  60. package/lib/core/preflight/diagnose.js +4 -9
  61. package/lib/core/preflight/engine.js +9 -0
  62. package/lib/core/preflight/hostPaths.js +260 -0
  63. package/lib/core/preflight/input.js +33 -5
  64. package/lib/core/preflight/instructions.js +18 -1
  65. package/lib/core/preflight/mockEngine.js +20 -2
  66. package/lib/core/preflight/render.js +22 -3
  67. package/lib/core/preflight/service.js +59 -9
  68. package/lib/core/preflight/uiRender.js +3 -0
  69. package/lib/core/requestOps.js +206 -14
  70. package/lib/core/retrospective.js +208 -0
  71. package/lib/core/reviewCandidates.js +56 -0
  72. package/lib/core/store/collection.js +20 -1
  73. package/lib/core/store/normalize.js +22 -4
  74. package/lib/core/store/preflightStore.js +19 -5
  75. package/lib/core/store/workspace.js +17 -1
  76. package/lib/core/taskReview/material.js +7 -0
  77. package/lib/core/taskReview/review.js +9 -2
  78. package/lib/server/api/manifest.js +51 -3
  79. package/lib/server/api/routes.js +131 -11
  80. package/lib/shared/acceptance.js +258 -18
  81. package/lib/shared/completionRecord.js +327 -0
  82. package/lib/shared/metrics.js +42 -0
  83. package/lib/shared/preflightInput.js +1 -1
  84. package/lib/shared/requirementSource.js +635 -0
  85. package/lib/shared/retrospective.js +286 -0
  86. package/lib/shared/reviewCandidate.js +308 -0
  87. package/lib/shared/reworkHistory.js +81 -0
  88. package/package.json +3 -2
  89. package/skills/p3/SKILL.md +9 -181
  90. package/dist/web/assets/ImprovementDialog-kQaVBGWH.js +0 -1
  91. package/dist/web/assets/Outputs-_nU_p3nu.js +0 -1
  92. package/dist/web/assets/RequestStatus-RG-OVQYY.js +0 -1
  93. package/dist/web/assets/Tabs-ew9i5SKX.js +0 -1
  94. package/dist/web/assets/TagInput-BtlJTF7i.js +0 -1
  95. package/dist/web/assets/TaskDrawer-DW8GyJqI.js +0 -6
  96. package/dist/web/assets/_requestId-6Nb727dD.js +0 -1
  97. package/dist/web/assets/_requestId-BykTgPax.js +0 -1
  98. package/dist/web/assets/appCtx-CxDdXABS.js +0 -1
  99. package/dist/web/assets/archive-Ckh295Xe.js +0 -1
  100. package/dist/web/assets/board-BVAIjK-Y.js +0 -1
  101. package/dist/web/assets/done-BGfA-3MA.js +0 -1
  102. package/dist/web/assets/draft-CfJeyLOl.js +0 -1
  103. package/dist/web/assets/index-CgRU744I.css +0 -2
  104. package/dist/web/assets/index-DacQ0yl4.js +0 -12
  105. package/dist/web/assets/new-DVygWvVc.js +0 -1
  106. package/dist/web/assets/outputs-B6xDsLZf.js +0 -1
  107. package/dist/web/assets/preflightInput-BAeEJYUK.js +0 -2
  108. package/dist/web/assets/preload-helper-DyCqp21K.js +0 -1
  109. package/dist/web/assets/release-notes-CCpzyiNf.js +0 -5
  110. package/dist/web/assets/requestData-D5vBnuMh.js +0 -1
  111. package/dist/web/assets/routes-Q91zvNc0.js +0 -4
  112. package/dist/web/assets/settings-BzRgcmUm.js +0 -1
  113. package/dist/web/assets/workTarget-C9c57JAO.js +0 -30
@@ -1,3 +1,4 @@
1
+ import { applySourceOps, criterionSubject, readCriterionSources, RequirementInputError, settleSources, sourcesKey } from "./requirementSource.js";
1
2
  /**
2
3
  * タスクの受け入れ基準(acceptanceCriteria)と、作業した側が項目ごとに残す証拠(acceptanceEvidence)の規則。
3
4
  * CLI・API・画面で同じものを使う(保存は core/requestOps.ts の createTask / updateTask がこれで確かめる)。
@@ -8,6 +9,10 @@
8
9
  * 変えたら、その証拠は「再確認が必要」(stale)として達成に数えない。基準を消しても証拠は「対応する基準のない証拠」(orphan)として残す
9
10
  * - 結果は met(満たした)/ unmet(満たせなかった)/ unverified(確かめていない)。met は証拠の本文が要る
10
11
  * - 証拠は作業した側の申告で、レビューの判定ではない。不足があっても完了・済みを拒まない(不足は読めるようにするだけ)
12
+ * - 根拠の種類(basis)は結果と別に持つ: 未確認 / 申告のみ / 読んで確認(参照先)/ 検査結果あり(コマンド・結果・対象)。
13
+ * どれも作業した側の申告で、P3 は検査を実行しない。読んで確認と検査結果ありは方法の違いで、正しさの上下は付けない。
14
+ * 人の「済み」はタスクごとの確認(checkedAt)で、根拠の種類には入れない。根拠の無い古い証拠は書き換えず、読むときだけ
15
+ * unverified は未確認、ほかは「申告のみ(種類未記録)」として扱う(本文から推し量って格上げしない)
11
16
  * - 直接編集で壊れた項目は黙って消さず、problems として知らせる。problems があるタスクの基準・証拠は操作で変えず、
12
17
  * 関係のない更新ではファイルの元の値をそのまま書き戻す(core/store/collection.ts の keepRaw)
13
18
  */
@@ -26,8 +31,25 @@ export const ACCEPTANCE_LIMITS = {
26
31
  /** 証拠1件の文字数 */
27
32
  evidence: 20000,
28
33
  };
34
+ /** 証拠の根拠の種類 */
35
+ export const EVIDENCE_BASIS_KINDS = ["unverified", "declaration", "read", "machine"];
36
+ export const isEvidenceBasisKind = (v) => typeof v === "string" && EVIDENCE_BASIS_KINDS.includes(v);
37
+ export const EVIDENCE_BASIS_LABEL = {
38
+ unverified: "未確認",
39
+ declaration: "申告のみ",
40
+ read: "読んで確認",
41
+ machine: "検査結果あり",
42
+ };
43
+ /** 根拠の説明(画面の凡例・CLI の案内で使う) */
44
+ export const EVIDENCE_BASIS_HINT = {
45
+ unverified: "まだ確かめていない",
46
+ declaration: "満たしたと作業した側が申告しただけ(確かめた方法の記録なし)",
47
+ read: "作業した側(AI を含む)がコード・資料・画面を読んで確かめた",
48
+ machine: "作業した側が記録した検査の結果(P3 は実行していない)",
49
+ };
50
+ export const BASIS_LIMITS = { reference: 1000, command: 1000, result: 2000, target: 300 };
29
51
  /** ファイルに書く基準・証拠の項目(壊れていたら元の値のまま書き戻す) */
30
- export const ACCEPTANCE_KEYS = ["acceptanceCriteria", "acceptanceEvidence", "acceptanceSeq"];
52
+ export const ACCEPTANCE_KEYS = ["acceptanceCriteria", "acceptanceEvidence", "acceptanceSeq", "acceptanceSources"];
31
53
  /** 直接編集で書いたものも読めるよう、A<番号> 以外の英数字の id も受け付ける。新しく振るのは A<番号> だけ */
32
54
  export const CRITERION_ID_RE = /^[A-Za-z0-9._-]{1,32}$/;
33
55
  /** 入力が規則に合わない(何も書いていない)。CLI は使い方の誤り、API は 400 */
@@ -85,15 +107,23 @@ export function readAcceptance(d) {
85
107
  problems.push(`${at} の result が読めません(${ACCEPTANCE_RESULTS.join(" / ")})`);
86
108
  else if (o.result === "met" && !body.trim())
87
109
  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
- });
110
+ else {
111
+ const basis = o.basis === undefined || o.basis === null ? undefined : readBasis(o.basis);
112
+ if (typeof basis === "string")
113
+ problems.push(`${at} の根拠(basis)が読めません: ${basis}`);
114
+ else if (basis && basisMismatch(o.result, basis))
115
+ problems.push(`${at} の根拠(basis)が結果と合いません: ${basisMismatch(o.result, basis)}`);
116
+ else
117
+ evidence.push({
118
+ criterionId: id,
119
+ criterionText: text(o.criterionText)?.trim() ?? "",
120
+ result: o.result,
121
+ evidence: body.trim(),
122
+ ...(basis ? { basis } : {}),
123
+ recordedAt: iso(o.recordedAt) ?? new Date(0).toISOString(),
124
+ ...(text(o.recordedBy) ? { recordedBy: text(o.recordedBy) } : {}),
125
+ });
126
+ }
97
127
  }
98
128
  out.acceptanceEvidence = evidence;
99
129
  }
@@ -104,10 +134,84 @@ export function readAcceptance(d) {
104
134
  else
105
135
  problems.push("acceptanceSeq が読めません");
106
136
  }
137
+ // 基準ごとの要求の根拠(shared/requirementSource.ts)
138
+ const sources = readCriterionSources(d.acceptanceSources, problems);
139
+ if (sources)
140
+ out.acceptanceSources = sources;
107
141
  if (problems.length)
108
142
  out.acceptanceProblems = problems;
109
143
  return out;
110
144
  }
145
+ /** ファイルの根拠を読む(読めなければ理由の文) */
146
+ function readBasis(v) {
147
+ try {
148
+ return cleanBasis(v);
149
+ }
150
+ catch (e) {
151
+ return e instanceof Error ? e.message : String(e);
152
+ }
153
+ }
154
+ /**
155
+ * 入力の根拠を確かめて保存する形にする(前後の空白を除く)。知らない種類・要る項目の欠け・長すぎるは AcceptanceInputError
156
+ */
157
+ export function cleanBasis(v) {
158
+ if (!v || typeof v !== "object")
159
+ throw new AcceptanceInputError("根拠は { kind, ... } の形で指定してください");
160
+ const o = v;
161
+ if (!isEvidenceBasisKind(o.kind))
162
+ throw new AcceptanceInputError(`根拠の種類は ${EVIDENCE_BASIS_KINDS.join(" / ")} のどれかです: ${String(o.kind)}`);
163
+ const field = (key, label) => {
164
+ const t = (text(o[key]) ?? "").trim();
165
+ if (!t)
166
+ throw new AcceptanceInputError(`根拠「${EVIDENCE_BASIS_LABEL[o.kind]}」には${label}(${key})が要ります`);
167
+ if (t.length > BASIS_LIMITS[key])
168
+ throw new AcceptanceInputError(`根拠の${label}(${key})は ${BASIS_LIMITS[key]} 文字までです(${t.length} 文字)`);
169
+ return t;
170
+ };
171
+ switch (o.kind) {
172
+ case "unverified":
173
+ case "declaration":
174
+ return { kind: o.kind };
175
+ case "read":
176
+ return { kind: "read", reference: field("reference", "読んだもの") };
177
+ case "machine":
178
+ return { kind: "machine", command: field("command", "検査のコマンド"), result: field("result", "検査の結果"), target: field("target", "対象(参照先とコミット)") };
179
+ }
180
+ }
181
+ /** 結果と根拠の組み合わせが合わなければ理由。met / unmet に未確認は付けない、unverified は未確認だけ */
182
+ export function basisMismatch(result, basis) {
183
+ if (result === "unverified" && basis.kind !== "unverified")
184
+ return `unverified(未検証)の根拠は「未確認」だけです(${EVIDENCE_BASIS_LABEL[basis.kind]} は付けられません)`;
185
+ if (result !== "unverified" && basis.kind === "unverified")
186
+ return `${result}(${ACCEPTANCE_RESULT_LABEL[result]})に根拠「未確認」は付けられません(確かめていないなら結果を unverified にします)`;
187
+ return undefined;
188
+ }
189
+ /** 根拠を省いた新しい入力の既定(unverified は未確認、ほかは申告のみ) */
190
+ export const defaultBasis = (result) => (result === "unverified" ? { kind: "unverified" } : { kind: "declaration" });
191
+ /** 読むときの根拠。古い証拠(basis なし)は recorded: false で、unverified は未確認・ほかは申告のみと解釈する */
192
+ export function evidenceBasisOf(e) {
193
+ return e.basis ? { basis: e.basis, recorded: true } : { basis: defaultBasis(e.result), recorded: false };
194
+ }
195
+ /** 根拠の短い表示(例: 「検査結果あり」「申告のみ(種類未記録)」) */
196
+ export function basisLabel(e) {
197
+ const { basis, recorded } = evidenceBasisOf(e);
198
+ return `${EVIDENCE_BASIS_LABEL[basis.kind]}${recorded ? "" : "(種類未記録)"}`;
199
+ }
200
+ /** 根拠の詳しい行(参照先・コマンド・結果・対象。CLI の show と画面で同じ並び) */
201
+ export function basisDetail(basis) {
202
+ switch (basis.kind) {
203
+ case "read":
204
+ return [{ label: "読んだもの", value: basis.reference }];
205
+ case "machine":
206
+ return [
207
+ { label: "コマンド", value: basis.command },
208
+ { label: "検査の結果", value: basis.result },
209
+ { label: "対象", value: basis.target },
210
+ ];
211
+ default:
212
+ return [];
213
+ }
214
+ }
111
215
  function qualitySourceOf(v) {
112
216
  if (!v || typeof v !== "object")
113
217
  return undefined;
@@ -137,7 +241,12 @@ export function applyAcceptanceOps(state, ops, at) {
137
241
  }
138
242
  let criteria = [...(state.acceptanceCriteria ?? [])];
139
243
  let evidence = [...(state.acceptanceEvidence ?? [])];
244
+ let sources = [...(state.acceptanceSources ?? [])];
140
245
  let seq = lastSeq(state);
246
+ const subjectOf = (s) => {
247
+ const c = criteria.find((x) => x.id === s.criterionId);
248
+ return c ? criterionSubject(c.text) : undefined;
249
+ };
141
250
  const find = (id) => {
142
251
  const c = criteria.find((x) => x.id === id);
143
252
  if (!c)
@@ -185,9 +294,23 @@ export function applyAcceptanceOps(state, ops, at) {
185
294
  if (body.length > ACCEPTANCE_LIMITS.evidence)
186
295
  throw new AcceptanceInputError(`${op.id} の証拠は ${ACCEPTANCE_LIMITS.evidence} 文字までです(${body.length} 文字)`);
187
296
  const prev = evidence.find((e) => e.criterionId === c.id);
188
- if (prev && prev.result === op.result && prev.evidence === body && prev.criterionText === c.text)
297
+ // 根拠を省いた入力(古い CLI・画面)は、同じ結果の前の証拠の根拠をそのまま使う(無ければ既定)。古い証拠を開いて同じ値で
298
+ // 保存し直しても、根拠を足したことにはならない
299
+ const basis = op.basis !== undefined ? cleanBasis(op.basis) : prev && prev.result === op.result ? prev.basis : defaultBasis(op.result);
300
+ const mismatch = basis && basisMismatch(op.result, basis);
301
+ if (mismatch)
302
+ throw new AcceptanceInputError(`${op.id}: ${mismatch}`);
303
+ if (prev && prev.result === op.result && prev.evidence === body && prev.criterionText === c.text && sameBasis(prev.basis, basis))
189
304
  break;
190
- const entry = { criterionId: c.id, criterionText: c.text, result: op.result, evidence: body, recordedAt: at.now, ...(at.actor ? { recordedBy: at.actor } : {}) };
305
+ const entry = {
306
+ criterionId: c.id,
307
+ criterionText: c.text,
308
+ result: op.result,
309
+ evidence: body,
310
+ ...(basis ? { basis } : {}),
311
+ recordedAt: at.now,
312
+ ...(at.actor ? { recordedBy: at.actor } : {}),
313
+ };
191
314
  evidence = prev ? evidence.map((e) => (e === prev ? entry : e)) : [...evidence, entry];
192
315
  break;
193
316
  }
@@ -197,21 +320,44 @@ export function applyAcceptanceOps(state, ops, at) {
197
320
  evidence = evidence.filter((e) => e.criterionId !== op.id);
198
321
  break;
199
322
  }
323
+ case "source": {
324
+ const c = find(op.id);
325
+ const target = op.source.id;
326
+ if (target !== undefined && !sources.some((x) => x.id === target && x.criterionId === c.id)) {
327
+ throw new AcceptanceInputError(`${c.id} に根拠の記録 ${target} はありません${sources.some((x) => x.criterionId === c.id) ? `(${sources.filter((x) => x.criterionId === c.id).map((x) => x.id).join(", ")})` : ""}`);
328
+ }
329
+ try {
330
+ sources = applySourceOps(sources, [op.source], { now: at.now, actor: at.actor, subjectOf, requestSources: at.requestSources ?? [], criterionId: c.id }).list;
331
+ }
332
+ catch (e) {
333
+ if (e instanceof RequirementInputError)
334
+ throw new AcceptanceInputError(`${c.id}: ${e.message}`);
335
+ throw e;
336
+ }
337
+ break;
338
+ }
200
339
  default:
201
340
  throw new AcceptanceInputError(`知らない操作です: ${String(op.op)}`);
202
341
  }
203
342
  }
343
+ // 基準の文を変えた・消した記録の確認は効かなくなる(履歴へ移す。消した基準の記録は対応先不明として残す)
344
+ sources = settleSources(sources, subjectOf, at.now);
204
345
  return {
205
346
  acceptanceCriteria: criteria.length ? criteria : undefined,
206
347
  acceptanceEvidence: evidence.length ? evidence : undefined,
207
348
  acceptanceSeq: seq > 0 ? seq : undefined,
349
+ acceptanceSources: sources.length ? sources : undefined,
208
350
  };
209
351
  }
210
- /** 基準・証拠の中身が変わったか(並び・文言・結果・証拠。記録の日時と変更者・採番は見ない)。人の「済み」を外す判断に使う */
352
+ /** 保存した根拠の比較の鍵(項目の順によらない) */
353
+ const basisKey = (b) => (b ? JSON.stringify(Object.entries(b).sort(([x], [y]) => x.localeCompare(y))) : "");
354
+ const sameBasis = (a, b) => basisKey(a) === basisKey(b);
355
+ /** 基準・証拠の中身が変わったか(並び・文言・結果・証拠・根拠・要求の根拠の記録。記録の日時と変更者・採番は見ない)。人の「済み」を外す判断に使う */
211
356
  export function acceptanceChanged(a, b) {
212
357
  const key = (s) => JSON.stringify([
213
358
  (s.acceptanceCriteria ?? []).map((c) => [c.id, c.text]),
214
- (s.acceptanceEvidence ?? []).map((e) => [e.criterionId, e.criterionText, e.result, e.evidence]),
359
+ (s.acceptanceEvidence ?? []).map((e) => [e.criterionId, e.criterionText, e.result, e.evidence, basisKey(e.basis)]),
360
+ sourcesKey(s.acceptanceSources),
215
361
  ]);
216
362
  return key(a) !== key(b);
217
363
  }
@@ -229,15 +375,33 @@ export function acceptanceStatus(t) {
229
375
  });
230
376
  const orphans = evidence.filter((e) => !criteria.some((c) => c.id === e.criterionId));
231
377
  const ids = (s) => items.filter((i) => i.state === s).map((i) => i.id);
378
+ const metByBasis = Object.fromEntries(EVIDENCE_BASIS_KINDS.map((k) => [k, 0]));
379
+ const declarationOnly = [];
380
+ for (const i of items) {
381
+ if (i.state !== "met" || !i.evidence)
382
+ continue;
383
+ const kind = evidenceBasisOf(i.evidence).basis.kind;
384
+ metByBasis[kind] += 1;
385
+ if (kind === "declaration")
386
+ declarationOnly.push(i.id);
387
+ }
232
388
  const shortfalls = [
233
389
  ...(ids("missing").length ? [`証拠なし: ${ids("missing").join(", ")}`] : []),
234
390
  ...(ids("unmet").length ? [`満たせなかった: ${ids("unmet").join(", ")}`] : []),
235
391
  ...(ids("unverified").length ? [`未検証: ${ids("unverified").join(", ")}`] : []),
236
392
  ...(ids("stale").length ? [`基準を変えた後の再確認が必要: ${ids("stale").join(", ")}`] : []),
393
+ // 注意(完了・済みは拒まない): 満たしたと申告しただけで、確かめた方法の記録が無い
394
+ ...(declarationOnly.length ? [`申告のみの met(確かめた方法の記録なし): ${declarationOnly.join(", ")}`] : []),
237
395
  ...(orphans.length ? [`対応する基準のない証拠: ${orphans.map((e) => e.criterionId).join(", ")}`] : []),
238
396
  ...problems.map((p) => `読めない: ${p}`),
239
397
  ];
240
- return { total: criteria.length, met: ids("met").length, items, orphans, problems, shortfalls };
398
+ return { total: criteria.length, met: ids("met").length, metByBasis, declarationOnly, items, orphans, problems, shortfalls };
399
+ }
400
+ export function evidenceSummary(t) {
401
+ const s = acceptanceStatus(t);
402
+ if (!s)
403
+ return undefined;
404
+ return { met: s.met, total: s.total, declarationOnly: s.declarationOnly.length, metByBasis: s.metByBasis, problems: s.problems.length > 0 };
241
405
  }
242
406
  // --- CLI の証拠の入力 -----------------------------------------------------------
243
407
  /** `A1=met:本文` / `A1=unverified`(本文は省ける。met は本文が要る) */
@@ -281,6 +445,42 @@ export function parseEvidenceFile(src) {
281
445
  throw new AcceptanceInputError(`証拠のファイルに ${dup} が2回あります`);
282
446
  return out;
283
447
  }
448
+ /**
449
+ * 証拠の JSON(構造化)。[{ id, result, evidence?, basis? }] の並びで、record と同じ規則で読む。
450
+ * 例: [{"id":"A1","result":"met","evidence":"対象のテストが通った","basis":{"kind":"machine","command":"pnpm vitest run test/x.test.ts","result":"終了コード 0","target":"p3:abc1234"}}]
451
+ */
452
+ export function parseEvidenceJson(src) {
453
+ let raw;
454
+ try {
455
+ raw = JSON.parse(src);
456
+ }
457
+ catch (e) {
458
+ throw new AcceptanceInputError(`証拠の JSON が読めません: ${e instanceof Error ? e.message : String(e)}`);
459
+ }
460
+ if (!Array.isArray(raw) || !raw.length)
461
+ throw new AcceptanceInputError("証拠の JSON は [{ id, result, evidence?, basis? }] の並び(1件以上)にしてください");
462
+ const out = raw.map((x, i) => {
463
+ const at = `証拠の JSON の ${i + 1} 件目`;
464
+ if (!x || typeof x !== "object" || Array.isArray(x))
465
+ throw new AcceptanceInputError(`${at} が { id, result, ... } になっていません`);
466
+ const o = x;
467
+ const unknownKeys = Object.keys(o).filter((k) => !["id", "result", "evidence", "basis"].includes(k));
468
+ if (unknownKeys.length)
469
+ throw new AcceptanceInputError(`${at} に知らない項目があります: ${unknownKeys.join(", ")}(id・result・evidence・basis)`);
470
+ const id = typeof o.id === "string" ? o.id.trim() : "";
471
+ if (!CRITERION_ID_RE.test(id))
472
+ throw new AcceptanceInputError(`${at} の id が読めません`);
473
+ if (!isAcceptanceResult(o.result))
474
+ throw new AcceptanceInputError(`${at}(${id})の result は ${ACCEPTANCE_RESULTS.join(" / ")} のどれかです`);
475
+ if (o.evidence !== undefined && typeof o.evidence !== "string")
476
+ throw new AcceptanceInputError(`${at}(${id})の evidence は文字列です`);
477
+ return { op: "record", id, result: o.result, evidence: o.evidence ?? "", ...(o.basis !== undefined ? { basis: cleanBasis(o.basis) } : {}) };
478
+ });
479
+ const dup = out.map((e) => e.id).find((id, i, a) => a.indexOf(id) !== i);
480
+ if (dup)
481
+ throw new AcceptanceInputError(`証拠の JSON に ${dup} が2回あります`);
482
+ return out;
483
+ }
284
484
  // --- Preflight のタスク案の基準 ----------------------------------------------------
285
485
  /**
286
486
  * タスク案の基準(drafts/D1.md の acceptanceCriteria)を読む。Codex・手元のエージェントが書いた文の並び(["…"])も、
@@ -342,11 +542,51 @@ export function tidyDraftCriteria(items) {
342
542
  }
343
543
  /** 基準の並びが同じか(id と文。タスク案の編集の競合を見る) */
344
544
  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) {
545
+ /** タスク案の要求の根拠の記録が同じか(案の編集の競合を見る) */
546
+ export const sameSources = (a, b) => sourcesKey(a) === sourcesKey(b);
547
+ /**
548
+ * タスク案の基準からタスクの基準を作る(案の ID を残し、振った最後の番号を引き継ぐ)。要求の根拠の記録も写す: 要望の記録を参照した
549
+ * 記録(from)は、採用するときの要望の記録の内容を写し直す(内容が変われば確認は再確認が必要になる。要望の確認は引き継がない)
550
+ */
551
+ export function criteriaForTask(criteria, sources, requestSources, now = new Date().toISOString()) {
347
552
  if (!criteria?.length)
348
553
  return {};
349
- return { acceptanceCriteria: criteria.map((c) => ({ ...c })), acceptanceSeq: lastSeq({ acceptanceCriteria: [...criteria] }) || undefined };
554
+ const ids = new Set(criteria.map((c) => c.id));
555
+ const copied = (sources ?? [])
556
+ .filter((x) => ids.has(x.criterionId))
557
+ .map((x) => {
558
+ const src = x.from ? requestSources?.find((r) => r.id === x.from) : undefined;
559
+ if (!src)
560
+ return { ...x };
561
+ const { target: _t, source: _s, basis: _b, ...rest } = x;
562
+ return { ...rest, ...(src.target ? { target: src.target } : {}), ...(src.source ? { source: src.source } : {}), ...(src.basis ? { basis: src.basis } : {}) };
563
+ });
564
+ const subjectOf = (x) => {
565
+ const c = criteria.find((y) => y.id === x.criterionId);
566
+ return c ? criterionSubject(c.text) : undefined;
567
+ };
568
+ const settled = settleSources(copied, subjectOf, now);
569
+ return {
570
+ acceptanceCriteria: criteria.map((c) => ({ ...c })),
571
+ acceptanceSeq: lastSeq({ acceptanceCriteria: [...criteria] }) || undefined,
572
+ ...(settled.length ? { acceptanceSources: settled } : {}),
573
+ };
574
+ }
575
+ /**
576
+ * タスク案の基準ごとの要求の根拠への操作を当てる(案の基準の文を対象にする)。規則に合わなければ AcceptanceInputError
577
+ */
578
+ export function applyDraftSourceOps(criteria, sources, ops, at) {
579
+ const next = applyAcceptanceOps({ acceptanceCriteria: [...(criteria ?? [])], acceptanceSources: [...(sources ?? [])] }, ops.map((o) => ({ op: "source", ...o })), at);
580
+ return next.acceptanceSources ?? [];
581
+ }
582
+ /** タスク案の基準を直した後の根拠の記録(文を変えた基準の確認は効かなくなる。消した基準の記録は対応先不明として残す) */
583
+ export function settleDraftSources(criteria, sources, now) {
584
+ if (!sources?.length)
585
+ return undefined;
586
+ return settleSources(sources, (x) => {
587
+ const c = (criteria ?? []).find((y) => y.id === x.criterionId);
588
+ return c ? criterionSubject(c.text) : undefined;
589
+ }, now);
350
590
  }
351
591
  // --- 画面の基準の編集 ---------------------------------------------------------------
352
592
  /**