@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.
- package/README.md +33 -33
- package/dist/web/assets/CompletionReview-gZKZrDu_.js +1 -0
- package/dist/web/assets/ImprovementDialog-Dno6dPnG.js +1 -0
- package/dist/web/assets/Outputs-BgHalMGb.js +1 -0
- package/dist/web/assets/RequestStatus-hZcBUUIu.js +1 -0
- package/dist/web/assets/Tabs-C3NmwCc3.js +1 -0
- package/dist/web/assets/TagInput-B2b862qn.js +1 -0
- package/dist/web/assets/TaskDrawer-4BQBELXa.js +6 -0
- package/dist/web/assets/_requestId-BMAG1t3o.js +1 -0
- package/dist/web/assets/_requestId-tbg2pA2S.js +1 -0
- package/dist/web/assets/archive-DMl6WyOe.js +1 -0
- package/dist/web/assets/board-BMTcHKyt.js +1 -0
- package/dist/web/assets/done-CL6Nlsua.js +1 -0
- package/dist/web/assets/draft-BvGxfD7v.js +2 -0
- package/dist/web/assets/index-Dp7Fc4VI.css +2 -0
- package/dist/web/assets/index-KdlgMitg.js +12 -0
- package/dist/web/assets/metrics-Cu7gJ7Rk.js +1 -0
- package/dist/web/assets/new-DTXWHuFO.js +1 -0
- package/dist/web/assets/outputs-CXqnjSqV.js +1 -0
- package/dist/web/assets/preflightInput-ClKwkp8R.js +2 -0
- package/dist/web/assets/preload-helper-oLCrNCwz.js +1 -0
- package/dist/web/assets/quality-RFd-7k3r.js +1 -0
- package/dist/web/assets/release-notes-Bpdi6RdY.js +5 -0
- package/dist/web/assets/requestData-CbFxwW5w.js +1 -0
- package/dist/web/assets/routes-BIt8bExF.js +6 -0
- package/dist/web/assets/settings-CsCqF_1B.js +1 -0
- package/dist/web/assets/taskReview-_WCgnQit.js +1 -0
- package/dist/web/assets/ui-BGK72r3u.js +1 -0
- package/dist/web/assets/workTarget-CySfKyfB.js +30 -0
- package/dist/web/index.html +4 -4
- package/docs/architecture.md +610 -33
- package/docs/development.md +61 -17
- package/docs/how-to-use.md +554 -17
- package/docs/installation.md +235 -144
- package/docs/publishing.md +1 -1
- package/lib/cli/agentsStatus.js +197 -0
- package/lib/cli/args.js +111 -2
- package/lib/cli/guide.js +27 -0
- package/lib/cli/guide.md +214 -0
- package/lib/cli/help.js +74 -1
- package/lib/cli/main.js +97 -17
- package/lib/cli/metricsCommands.js +77 -0
- package/lib/cli/output.js +19 -1
- package/lib/cli/preflightCommands.js +7 -1
- package/lib/cli/project.js +13 -24
- package/lib/cli/qualityCommands.js +188 -0
- package/lib/cli/readOnly.js +17 -0
- package/lib/cli/requestCommands.js +33 -4
- package/lib/cli/requirementCommands.js +288 -0
- package/lib/cli/retroCommands.js +106 -0
- package/lib/cli/revisitCommands.js +73 -0
- package/lib/cli/showView.js +183 -4
- package/lib/cli/taskCommands.js +341 -20
- package/lib/cli/taskReviewCommands.js +178 -0
- package/lib/cli/userConfig.js +47 -0
- package/lib/core/completionRefs.js +46 -0
- package/lib/core/context.js +4 -1
- package/lib/core/metrics/definitions.js +434 -0
- package/lib/core/metrics/index.js +88 -0
- package/lib/core/metrics/manual.js +180 -0
- package/lib/core/milestoneReview/material.js +11 -1
- package/lib/core/milestoneReview/mockReviewer.js +1 -0
- package/lib/core/milestoneReview/review.js +70 -6
- package/lib/core/milestoneReview/service.js +29 -93
- package/lib/core/milestoneReview/store.js +12 -62
- package/lib/core/ops.js +23 -3
- package/lib/core/preflight/carryover.js +6 -2
- package/lib/core/preflight/codexEngine.js +34 -17
- package/lib/core/preflight/diagnose.js +4 -9
- package/lib/core/preflight/engine.js +15 -0
- package/lib/core/preflight/hostPaths.js +260 -0
- package/lib/core/preflight/input.js +33 -5
- package/lib/core/preflight/instructions.js +36 -2
- package/lib/core/preflight/mockEngine.js +24 -2
- package/lib/core/preflight/render.js +22 -3
- package/lib/core/preflight/service.js +99 -8
- package/lib/core/preflight/uiRender.js +3 -0
- package/lib/core/projectRegistry.js +3 -3
- package/lib/core/quality.js +21 -0
- package/lib/core/qualityImprovement.js +221 -0
- package/lib/core/requestOps.js +294 -11
- package/lib/core/retrospective.js +208 -0
- package/lib/core/reviewCandidates.js +56 -0
- package/lib/core/reviewRuns.js +205 -0
- package/lib/core/store/archivedTasks.js +74 -0
- package/lib/core/store/collection.js +32 -3
- package/lib/core/store/normalize.js +35 -2
- package/lib/core/store/preflightStore.js +23 -1
- package/lib/core/store/projectFile.js +10 -0
- package/lib/core/store/workspace.js +49 -3
- package/lib/core/taskReview/material.js +459 -0
- package/lib/core/taskReview/mockReviewer.js +30 -0
- package/lib/core/taskReview/paths.js +15 -0
- package/lib/core/taskReview/review.js +312 -0
- package/lib/core/taskReview/service.js +187 -0
- package/lib/core/taskReview/store.js +214 -0
- package/lib/server/api/manifest.js +104 -5
- package/lib/server/api/milestoneReviewRoutes.js +4 -3
- package/lib/server/api/routes.js +265 -17
- package/lib/server/api/taskReviewRoutes.js +66 -0
- package/lib/server/server.js +2 -2
- package/lib/shared/acceptance.js +618 -0
- package/lib/shared/completionRecord.js +327 -0
- package/lib/shared/metrics.js +42 -0
- package/lib/shared/milestoneReview.js +2 -1
- package/lib/shared/preflightInput.js +1 -1
- package/lib/shared/quality.js +391 -0
- package/lib/shared/qualityImprovement.js +1 -0
- package/lib/shared/qualityTemplates.js +31 -0
- package/lib/shared/requirementSource.js +635 -0
- package/lib/shared/retrospective.js +286 -0
- package/lib/shared/reviewCandidate.js +308 -0
- package/lib/shared/reworkHistory.js +81 -0
- package/lib/shared/taskBlock.js +142 -0
- package/lib/shared/taskReview.js +56 -0
- package/package.json +3 -2
- package/skills/p3/SKILL.md +9 -152
- package/dist/web/assets/Outputs-ddwte0jj.js +0 -1
- package/dist/web/assets/RequestStatus-Bg1OLbRc.js +0 -1
- package/dist/web/assets/Tabs-DTmggzgg.js +0 -1
- package/dist/web/assets/TagInput-BHAgjLP7.js +0 -1
- package/dist/web/assets/TaskDrawer-Dz_5c2NH.js +0 -3
- package/dist/web/assets/_requestId-D9-gtIcG.js +0 -1
- package/dist/web/assets/_requestId-DzCNYvqf.js +0 -30
- package/dist/web/assets/appCtx-Cm24VpAf.js +0 -1
- package/dist/web/assets/board-MCHcZ-PU.js +0 -1
- package/dist/web/assets/done-zq10Bt08.js +0 -1
- package/dist/web/assets/draft-CfJeyLOl.js +0 -1
- package/dist/web/assets/index-Ce0ndpne.js +0 -12
- package/dist/web/assets/index-D68mkSnw.css +0 -2
- package/dist/web/assets/new-9TKiNT4O.js +0 -1
- package/dist/web/assets/preflightInput-BAeEJYUK.js +0 -2
- package/dist/web/assets/preload-helper-FBLw7u7x.js +0 -1
- package/dist/web/assets/release-notes-hK5XezLW.js +0 -5
- package/dist/web/assets/requestData-BnN7mctX.js +0 -1
- package/dist/web/assets/routes-usHwrrA0.js +0 -3
- package/dist/web/assets/settings-BVZDnL6O.js +0 -1
- package/dist/web/assets/workTarget-Cijqq4yH.js +0 -1
|
@@ -0,0 +1,618 @@
|
|
|
1
|
+
import { applySourceOps, criterionSubject, readCriterionSources, RequirementInputError, settleSources, sourcesKey } from "./requirementSource.js";
|
|
2
|
+
/**
|
|
3
|
+
* タスクの受け入れ基準(acceptanceCriteria)と、作業した側が項目ごとに残す証拠(acceptanceEvidence)の規則。
|
|
4
|
+
* CLI・API・画面で同じものを使う(保存は core/requestOps.ts の createTask / updateTask がこれで確かめる)。
|
|
5
|
+
*
|
|
6
|
+
* - 基準は { id, text } の並び。id は追加のときに振り(A1, A2, ...)、並べ替え・文言の変更で振り直さず、消した id も使い直さない
|
|
7
|
+
* (acceptanceSeq に振った最後の番号を残す)
|
|
8
|
+
* - 証拠は基準の id ごとに1件(再記録は置き換え)。記録したときの基準の文言(criterionText)を写して持つ。後で基準の文言を
|
|
9
|
+
* 変えたら、その証拠は「再確認が必要」(stale)として達成に数えない。基準を消しても証拠は「対応する基準のない証拠」(orphan)として残す
|
|
10
|
+
* - 結果は met(満たした)/ unmet(満たせなかった)/ unverified(確かめていない)。met は証拠の本文が要る
|
|
11
|
+
* - 証拠は作業した側の申告で、レビューの判定ではない。不足があっても完了・済みを拒まない(不足は読めるようにするだけ)
|
|
12
|
+
* - 根拠の種類(basis)は結果と別に持つ: 未確認 / 申告のみ / 読んで確認(参照先)/ 検査結果あり(コマンド・結果・対象)。
|
|
13
|
+
* どれも作業した側の申告で、P3 は検査を実行しない。読んで確認と検査結果ありは方法の違いで、正しさの上下は付けない。
|
|
14
|
+
* 人の「済み」はタスクごとの確認(checkedAt)で、根拠の種類には入れない。根拠の無い古い証拠は書き換えず、読むときだけ
|
|
15
|
+
* unverified は未確認、ほかは「申告のみ(種類未記録)」として扱う(本文から推し量って格上げしない)
|
|
16
|
+
* - 直接編集で壊れた項目は黙って消さず、problems として知らせる。problems があるタスクの基準・証拠は操作で変えず、
|
|
17
|
+
* 関係のない更新ではファイルの元の値をそのまま書き戻す(core/store/collection.ts の keepRaw)
|
|
18
|
+
*/
|
|
19
|
+
export const ACCEPTANCE_RESULTS = ["met", "unmet", "unverified"];
|
|
20
|
+
export const isAcceptanceResult = (v) => typeof v === "string" && ACCEPTANCE_RESULTS.includes(v);
|
|
21
|
+
export const ACCEPTANCE_RESULT_LABEL = {
|
|
22
|
+
met: "満たした",
|
|
23
|
+
unmet: "満たせなかった",
|
|
24
|
+
unverified: "未検証",
|
|
25
|
+
};
|
|
26
|
+
export const ACCEPTANCE_LIMITS = {
|
|
27
|
+
/** 基準の件数 */
|
|
28
|
+
criteria: 50,
|
|
29
|
+
/** 基準1件の文字数 */
|
|
30
|
+
text: 1000,
|
|
31
|
+
/** 証拠1件の文字数 */
|
|
32
|
+
evidence: 20000,
|
|
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 };
|
|
51
|
+
/** ファイルに書く基準・証拠の項目(壊れていたら元の値のまま書き戻す) */
|
|
52
|
+
export const ACCEPTANCE_KEYS = ["acceptanceCriteria", "acceptanceEvidence", "acceptanceSeq", "acceptanceSources"];
|
|
53
|
+
/** 直接編集で書いたものも読めるよう、A<番号> 以外の英数字の id も受け付ける。新しく振るのは A<番号> だけ */
|
|
54
|
+
export const CRITERION_ID_RE = /^[A-Za-z0-9._-]{1,32}$/;
|
|
55
|
+
/** 入力が規則に合わない(何も書いていない)。CLI は使い方の誤り、API は 400 */
|
|
56
|
+
export class AcceptanceInputError extends Error {
|
|
57
|
+
code = "acceptance_invalid";
|
|
58
|
+
}
|
|
59
|
+
// --- 読む ---------------------------------------------------------------------
|
|
60
|
+
const text = (v) => (typeof v === "string" ? v : typeof v === "number" ? String(v) : undefined);
|
|
61
|
+
const iso = (v) => (v instanceof Date ? v.toISOString() : typeof v === "string" && v ? v : undefined);
|
|
62
|
+
/**
|
|
63
|
+
* frontmatter の値を読む。読めない項目は除いて problems に理由を足す(ファイルは書き換えない)。
|
|
64
|
+
* どちらの項目も無ければ何も足さない(基準のない古いタスクはそのまま)
|
|
65
|
+
*/
|
|
66
|
+
export function readAcceptance(d) {
|
|
67
|
+
const problems = [];
|
|
68
|
+
const out = {};
|
|
69
|
+
if (d.acceptanceCriteria !== undefined && d.acceptanceCriteria !== null) {
|
|
70
|
+
const criteria = [];
|
|
71
|
+
if (!Array.isArray(d.acceptanceCriteria))
|
|
72
|
+
problems.push("acceptanceCriteria が並びになっていません");
|
|
73
|
+
else
|
|
74
|
+
for (const [i, raw] of d.acceptanceCriteria.entries()) {
|
|
75
|
+
const o = raw && typeof raw === "object" ? raw : {};
|
|
76
|
+
const id = text(o.id)?.trim() ?? "";
|
|
77
|
+
const t = text(o.text)?.trim() ?? "";
|
|
78
|
+
const at = `受け入れ基準 ${i + 1} 件目${id ? `(${id})` : ""}`;
|
|
79
|
+
if (!CRITERION_ID_RE.test(id))
|
|
80
|
+
problems.push(`${at} の id が読めません`);
|
|
81
|
+
else if (criteria.some((c) => c.id === id))
|
|
82
|
+
problems.push(`受け入れ基準の id が重複しています: ${id}`);
|
|
83
|
+
else if (!t)
|
|
84
|
+
problems.push(`${at} の文が空です`);
|
|
85
|
+
else if (o.quality !== undefined && !qualitySourceOf(o.quality))
|
|
86
|
+
problems.push(`${at} の品質基準の出典(quality)が読めません(id・hash・version が要ります)`);
|
|
87
|
+
else
|
|
88
|
+
criteria.push({ id, text: t, ...(o.quality !== undefined ? { quality: qualitySourceOf(o.quality) } : {}) });
|
|
89
|
+
}
|
|
90
|
+
out.acceptanceCriteria = criteria;
|
|
91
|
+
}
|
|
92
|
+
if (d.acceptanceEvidence !== undefined && d.acceptanceEvidence !== null) {
|
|
93
|
+
const evidence = [];
|
|
94
|
+
if (!Array.isArray(d.acceptanceEvidence))
|
|
95
|
+
problems.push("acceptanceEvidence が並びになっていません");
|
|
96
|
+
else
|
|
97
|
+
for (const [i, raw] of d.acceptanceEvidence.entries()) {
|
|
98
|
+
const o = raw && typeof raw === "object" ? raw : {};
|
|
99
|
+
const id = text(o.criterionId)?.trim() ?? "";
|
|
100
|
+
const at = `証拠 ${i + 1} 件目${id ? `(${id})` : ""}`;
|
|
101
|
+
const body = text(o.evidence) ?? "";
|
|
102
|
+
if (!CRITERION_ID_RE.test(id))
|
|
103
|
+
problems.push(`${at} の criterionId が読めません`);
|
|
104
|
+
else if (evidence.some((e) => e.criterionId === id))
|
|
105
|
+
problems.push(`${id} の証拠が重複しています`);
|
|
106
|
+
else if (!isAcceptanceResult(o.result))
|
|
107
|
+
problems.push(`${at} の result が読めません(${ACCEPTANCE_RESULTS.join(" / ")})`);
|
|
108
|
+
else if (o.result === "met" && !body.trim())
|
|
109
|
+
problems.push(`${at} は met ですが証拠が空です`);
|
|
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
|
+
}
|
|
127
|
+
}
|
|
128
|
+
out.acceptanceEvidence = evidence;
|
|
129
|
+
}
|
|
130
|
+
if (d.acceptanceSeq !== undefined && d.acceptanceSeq !== null) {
|
|
131
|
+
const n = Number(d.acceptanceSeq);
|
|
132
|
+
if (Number.isInteger(n) && n >= 0)
|
|
133
|
+
out.acceptanceSeq = n;
|
|
134
|
+
else
|
|
135
|
+
problems.push("acceptanceSeq が読めません");
|
|
136
|
+
}
|
|
137
|
+
// 基準ごとの要求の根拠(shared/requirementSource.ts)
|
|
138
|
+
const sources = readCriterionSources(d.acceptanceSources, problems);
|
|
139
|
+
if (sources)
|
|
140
|
+
out.acceptanceSources = sources;
|
|
141
|
+
if (problems.length)
|
|
142
|
+
out.acceptanceProblems = problems;
|
|
143
|
+
return out;
|
|
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
|
+
}
|
|
215
|
+
function qualitySourceOf(v) {
|
|
216
|
+
if (!v || typeof v !== "object")
|
|
217
|
+
return undefined;
|
|
218
|
+
const o = v;
|
|
219
|
+
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;
|
|
220
|
+
}
|
|
221
|
+
function cleanText(raw, label) {
|
|
222
|
+
const t = raw.trim();
|
|
223
|
+
if (!t)
|
|
224
|
+
throw new AcceptanceInputError(`${label}の文が空です`);
|
|
225
|
+
if (t.length > ACCEPTANCE_LIMITS.text)
|
|
226
|
+
throw new AcceptanceInputError(`${label}は ${ACCEPTANCE_LIMITS.text} 文字までです(${t.length} 文字)`);
|
|
227
|
+
return t;
|
|
228
|
+
}
|
|
229
|
+
/** 振った最後の番号(acceptanceSeq と、今ある A<番号> の大きい方。消した id を使い直さない) */
|
|
230
|
+
function lastSeq(s) {
|
|
231
|
+
const ids = [...(s.acceptanceCriteria ?? []).map((c) => c.id), ...(s.acceptanceEvidence ?? []).map((e) => e.criterionId)];
|
|
232
|
+
return ids.reduce((n, id) => Math.max(n, /^A(\d+)$/.exec(id) ? Number(id.slice(1)) : 0), s.acceptanceSeq ?? 0);
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* 操作を順に当てた後の基準・証拠(何も書かない。規則に合わなければ AcceptanceInputError で、1件も当てない)。
|
|
236
|
+
* 同じ値の再記録は元の証拠(記録した日時も)をそのまま残す
|
|
237
|
+
*/
|
|
238
|
+
export function applyAcceptanceOps(state, ops, at) {
|
|
239
|
+
if (state.acceptanceProblems?.length) {
|
|
240
|
+
throw new AcceptanceInputError(`受け入れ基準・証拠のファイルの値が読めないため変えられません。ファイルを直してください: ${state.acceptanceProblems.join(" / ")}`);
|
|
241
|
+
}
|
|
242
|
+
let criteria = [...(state.acceptanceCriteria ?? [])];
|
|
243
|
+
let evidence = [...(state.acceptanceEvidence ?? [])];
|
|
244
|
+
let sources = [...(state.acceptanceSources ?? [])];
|
|
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
|
+
};
|
|
250
|
+
const find = (id) => {
|
|
251
|
+
const c = criteria.find((x) => x.id === id);
|
|
252
|
+
if (!c)
|
|
253
|
+
throw new AcceptanceInputError(`受け入れ基準 ${id} はありません${criteria.length ? `(${criteria.map((x) => x.id).join(", ")})` : "(基準がありません)"}`);
|
|
254
|
+
return c;
|
|
255
|
+
};
|
|
256
|
+
for (const op of ops) {
|
|
257
|
+
switch (op.op) {
|
|
258
|
+
case "add": {
|
|
259
|
+
if (criteria.length >= ACCEPTANCE_LIMITS.criteria)
|
|
260
|
+
throw new AcceptanceInputError(`受け入れ基準は ${ACCEPTANCE_LIMITS.criteria} 件までです`);
|
|
261
|
+
if (op.quality && criteria.some((c) => c.quality?.id === op.quality.id))
|
|
262
|
+
throw new AcceptanceInputError(`品質基準 ${op.quality.id} は取り込み済みです`);
|
|
263
|
+
seq += 1;
|
|
264
|
+
criteria.push({ id: `A${seq}`, text: cleanText(op.text, "受け入れ基準"), ...(op.quality ? { quality: { ...op.quality } } : {}) });
|
|
265
|
+
break;
|
|
266
|
+
}
|
|
267
|
+
case "edit": {
|
|
268
|
+
const c = find(op.id);
|
|
269
|
+
const t = cleanText(op.text, `受け入れ基準 ${op.id} `);
|
|
270
|
+
criteria = criteria.map((x) => (x.id === c.id ? { ...x, text: t, ...(op.quality ? { quality: { ...op.quality } } : {}) } : x));
|
|
271
|
+
break;
|
|
272
|
+
}
|
|
273
|
+
case "remove": {
|
|
274
|
+
find(op.id);
|
|
275
|
+
// 証拠は残す(対応する基準のない証拠として読める)
|
|
276
|
+
criteria = criteria.filter((x) => x.id !== op.id);
|
|
277
|
+
break;
|
|
278
|
+
}
|
|
279
|
+
case "order": {
|
|
280
|
+
const now = criteria.map((x) => x.id);
|
|
281
|
+
const same = op.ids.length === now.length && new Set(op.ids).size === op.ids.length && op.ids.every((id) => now.includes(id));
|
|
282
|
+
if (!same)
|
|
283
|
+
throw new AcceptanceInputError(`並べ替えは今の基準の id を全部、1回ずつ指定してください(今: ${now.join(", ") || "なし"})`);
|
|
284
|
+
criteria = op.ids.map((id) => criteria.find((x) => x.id === id));
|
|
285
|
+
break;
|
|
286
|
+
}
|
|
287
|
+
case "record": {
|
|
288
|
+
const c = find(op.id);
|
|
289
|
+
if (!isAcceptanceResult(op.result))
|
|
290
|
+
throw new AcceptanceInputError(`結果は ${ACCEPTANCE_RESULTS.join(" / ")} のどれかです: ${String(op.result)}`);
|
|
291
|
+
const body = (op.evidence ?? "").trim();
|
|
292
|
+
if (op.result === "met" && !body)
|
|
293
|
+
throw new AcceptanceInputError(`${op.id} を met にするには証拠を書いてください(通したテスト・コマンドと結果・画面の確認・リンクなど)`);
|
|
294
|
+
if (body.length > ACCEPTANCE_LIMITS.evidence)
|
|
295
|
+
throw new AcceptanceInputError(`${op.id} の証拠は ${ACCEPTANCE_LIMITS.evidence} 文字までです(${body.length} 文字)`);
|
|
296
|
+
const prev = evidence.find((e) => e.criterionId === c.id);
|
|
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))
|
|
304
|
+
break;
|
|
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
|
+
};
|
|
314
|
+
evidence = prev ? evidence.map((e) => (e === prev ? entry : e)) : [...evidence, entry];
|
|
315
|
+
break;
|
|
316
|
+
}
|
|
317
|
+
case "unrecord": {
|
|
318
|
+
if (!evidence.some((e) => e.criterionId === op.id))
|
|
319
|
+
throw new AcceptanceInputError(`${op.id} の証拠はありません`);
|
|
320
|
+
evidence = evidence.filter((e) => e.criterionId !== op.id);
|
|
321
|
+
break;
|
|
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
|
+
}
|
|
339
|
+
default:
|
|
340
|
+
throw new AcceptanceInputError(`知らない操作です: ${String(op.op)}`);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
// 基準の文を変えた・消した記録の確認は効かなくなる(履歴へ移す。消した基準の記録は対応先不明として残す)
|
|
344
|
+
sources = settleSources(sources, subjectOf, at.now);
|
|
345
|
+
return {
|
|
346
|
+
acceptanceCriteria: criteria.length ? criteria : undefined,
|
|
347
|
+
acceptanceEvidence: evidence.length ? evidence : undefined,
|
|
348
|
+
acceptanceSeq: seq > 0 ? seq : undefined,
|
|
349
|
+
acceptanceSources: sources.length ? sources : undefined,
|
|
350
|
+
};
|
|
351
|
+
}
|
|
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
|
+
/** 基準・証拠の中身が変わったか(並び・文言・結果・証拠・根拠・要求の根拠の記録。記録の日時と変更者・採番は見ない)。人の「済み」を外す判断に使う */
|
|
356
|
+
export function acceptanceChanged(a, b) {
|
|
357
|
+
const key = (s) => JSON.stringify([
|
|
358
|
+
(s.acceptanceCriteria ?? []).map((c) => [c.id, c.text]),
|
|
359
|
+
(s.acceptanceEvidence ?? []).map((e) => [e.criterionId, e.criterionText, e.result, e.evidence, basisKey(e.basis)]),
|
|
360
|
+
sourcesKey(s.acceptanceSources),
|
|
361
|
+
]);
|
|
362
|
+
return key(a) !== key(b);
|
|
363
|
+
}
|
|
364
|
+
/** 基準・証拠の状態。基準も証拠も問題も無いタスクは undefined(「受け入れ基準なし」) */
|
|
365
|
+
export function acceptanceStatus(t) {
|
|
366
|
+
const criteria = t.acceptanceCriteria ?? [];
|
|
367
|
+
const evidence = t.acceptanceEvidence ?? [];
|
|
368
|
+
const problems = t.acceptanceProblems ?? [];
|
|
369
|
+
if (!criteria.length && !evidence.length && !problems.length)
|
|
370
|
+
return undefined;
|
|
371
|
+
const items = criteria.map((c) => {
|
|
372
|
+
const e = evidence.find((x) => x.criterionId === c.id);
|
|
373
|
+
const state = !e ? "missing" : e.criterionText !== c.text ? "stale" : e.result;
|
|
374
|
+
return { id: c.id, text: c.text, state, ...(e ? { evidence: e } : {}) };
|
|
375
|
+
});
|
|
376
|
+
const orphans = evidence.filter((e) => !criteria.some((c) => c.id === e.criterionId));
|
|
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
|
+
}
|
|
388
|
+
const shortfalls = [
|
|
389
|
+
...(ids("missing").length ? [`証拠なし: ${ids("missing").join(", ")}`] : []),
|
|
390
|
+
...(ids("unmet").length ? [`満たせなかった: ${ids("unmet").join(", ")}`] : []),
|
|
391
|
+
...(ids("unverified").length ? [`未検証: ${ids("unverified").join(", ")}`] : []),
|
|
392
|
+
...(ids("stale").length ? [`基準を変えた後の再確認が必要: ${ids("stale").join(", ")}`] : []),
|
|
393
|
+
// 注意(完了・済みは拒まない): 満たしたと申告しただけで、確かめた方法の記録が無い
|
|
394
|
+
...(declarationOnly.length ? [`申告のみの met(確かめた方法の記録なし): ${declarationOnly.join(", ")}`] : []),
|
|
395
|
+
...(orphans.length ? [`対応する基準のない証拠: ${orphans.map((e) => e.criterionId).join(", ")}`] : []),
|
|
396
|
+
...problems.map((p) => `読めない: ${p}`),
|
|
397
|
+
];
|
|
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 };
|
|
405
|
+
}
|
|
406
|
+
// --- CLI の証拠の入力 -----------------------------------------------------------
|
|
407
|
+
/** `A1=met:本文` / `A1=unverified`(本文は省ける。met は本文が要る) */
|
|
408
|
+
export function parseEvidenceArg(arg) {
|
|
409
|
+
const m = /^([A-Za-z0-9._-]+)=([a-z]+)(?::([\s\S]*))?$/.exec(arg.trim());
|
|
410
|
+
if (!m || !isAcceptanceResult(m[2]))
|
|
411
|
+
throw new AcceptanceInputError(`証拠は <基準の ID>=<${ACCEPTANCE_RESULTS.join("|")}>[:本文] の形で指定してください: ${arg}`);
|
|
412
|
+
return { op: "record", id: m[1], result: m[2], evidence: m[3] ?? "" };
|
|
413
|
+
}
|
|
414
|
+
/**
|
|
415
|
+
* 証拠のファイル(Markdown)。見出し `## <基準の ID> <結果>` ごとに、次の見出しまでを証拠の本文として読む。
|
|
416
|
+
* 最初の見出しの前に文があれば断る(取りこぼさない)
|
|
417
|
+
*/
|
|
418
|
+
export function parseEvidenceFile(src) {
|
|
419
|
+
const out = [];
|
|
420
|
+
let cur;
|
|
421
|
+
const lines = [];
|
|
422
|
+
const flush = () => {
|
|
423
|
+
if (cur)
|
|
424
|
+
out.push({ ...cur, evidence: lines.join("\n").trim() });
|
|
425
|
+
lines.length = 0;
|
|
426
|
+
};
|
|
427
|
+
for (const line of src.replace(/\r\n/g, "\n").split("\n")) {
|
|
428
|
+
const h = /^##\s+([A-Za-z0-9._-]+)\s*[::]?\s*([a-z]+)\s*$/.exec(line);
|
|
429
|
+
if (h) {
|
|
430
|
+
if (!isAcceptanceResult(h[2]))
|
|
431
|
+
throw new AcceptanceInputError(`証拠のファイルの見出しの結果は ${ACCEPTANCE_RESULTS.join(" / ")} のどれかです: ${line}`);
|
|
432
|
+
flush();
|
|
433
|
+
cur = { op: "record", id: h[1], result: h[2], evidence: "" };
|
|
434
|
+
continue;
|
|
435
|
+
}
|
|
436
|
+
if (!cur && line.trim())
|
|
437
|
+
throw new AcceptanceInputError(`証拠のファイルは「## <基準の ID> <結果>」の見出しから始めてください: ${line}`);
|
|
438
|
+
lines.push(line);
|
|
439
|
+
}
|
|
440
|
+
flush();
|
|
441
|
+
if (!out.length)
|
|
442
|
+
throw new AcceptanceInputError("証拠のファイルに「## <基準の ID> <結果>」の見出しがありません");
|
|
443
|
+
const dup = out.map((e) => e.id).find((id, i, a) => a.indexOf(id) !== i);
|
|
444
|
+
if (dup)
|
|
445
|
+
throw new AcceptanceInputError(`証拠のファイルに ${dup} が2回あります`);
|
|
446
|
+
return out;
|
|
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
|
+
}
|
|
484
|
+
// --- Preflight のタスク案の基準 ----------------------------------------------------
|
|
485
|
+
/**
|
|
486
|
+
* タスク案の基準(drafts/D1.md の acceptanceCriteria)を読む。Codex・手元のエージェントが書いた文の並び(["…"])も、
|
|
487
|
+
* { id, text } の並びも受け付け、id の無い項目には A<番号> を振る。読めない項目は除いて problems に理由を足す(無いのは基準なし)
|
|
488
|
+
*/
|
|
489
|
+
export function readDraftCriteria(raw) {
|
|
490
|
+
if (raw === undefined || raw === null)
|
|
491
|
+
return {};
|
|
492
|
+
if (!Array.isArray(raw))
|
|
493
|
+
return { criteria: [], problems: ["acceptanceCriteria が並びになっていません(文の並びで書いてください)"] };
|
|
494
|
+
const problems = [];
|
|
495
|
+
const items = [];
|
|
496
|
+
for (const [i, x] of raw.entries()) {
|
|
497
|
+
const at = `受け入れ基準 ${i + 1} 件目`;
|
|
498
|
+
const o = typeof x === "string" ? { text: x } : x && typeof x === "object" ? x : undefined;
|
|
499
|
+
const t = o && (typeof o.text === "string" || typeof o.text === "number") ? String(o.text).trim() : "";
|
|
500
|
+
const id = o && (typeof o.id === "string" || typeof o.id === "number") ? String(o.id).trim() : undefined;
|
|
501
|
+
if (!o)
|
|
502
|
+
problems.push(`${at} が文になっていません`);
|
|
503
|
+
else if (!t)
|
|
504
|
+
problems.push(`${at} が空です`);
|
|
505
|
+
else if (t.length > ACCEPTANCE_LIMITS.text)
|
|
506
|
+
problems.push(`${at} は ${ACCEPTANCE_LIMITS.text} 文字までです(${t.length} 文字)`);
|
|
507
|
+
else if (id !== undefined && !CRITERION_ID_RE.test(id))
|
|
508
|
+
problems.push(`${at} の id が使えません: ${id}`);
|
|
509
|
+
else if (id !== undefined && items.some((c) => c.id === id))
|
|
510
|
+
problems.push(`受け入れ基準の id が重複しています: ${id}`);
|
|
511
|
+
else
|
|
512
|
+
items.push({ ...(id !== undefined ? { id } : {}), text: t });
|
|
513
|
+
}
|
|
514
|
+
if (items.length > ACCEPTANCE_LIMITS.criteria)
|
|
515
|
+
problems.push(`受け入れ基準は ${ACCEPTANCE_LIMITS.criteria} 件までです(${items.length} 件)`);
|
|
516
|
+
return { criteria: withIds(items), ...(problems.length ? { problems } : {}) };
|
|
517
|
+
}
|
|
518
|
+
/** id の無い項目に、今ある A<番号> の次から振る */
|
|
519
|
+
function withIds(items) {
|
|
520
|
+
let n = items.reduce((m, c) => Math.max(m, c.id && /^A(\d+)$/.exec(c.id) ? Number(c.id.slice(1)) : 0), 0);
|
|
521
|
+
return items.map((c) => ({ id: c.id ?? `A${++n}`, text: c.text }));
|
|
522
|
+
}
|
|
523
|
+
/**
|
|
524
|
+
* 人が直したタスク案の基準(並び全体の置き換え)を確かめて保存する形にする。id は残し、無い項目に振る。
|
|
525
|
+
* 空・長すぎる・件数・重複した id は AcceptanceInputError(何も書かない)
|
|
526
|
+
*/
|
|
527
|
+
export function tidyDraftCriteria(items) {
|
|
528
|
+
if (items.length > ACCEPTANCE_LIMITS.criteria)
|
|
529
|
+
throw new AcceptanceInputError(`受け入れ基準は ${ACCEPTANCE_LIMITS.criteria} 件までです(${items.length} 件)`);
|
|
530
|
+
const seen = new Set();
|
|
531
|
+
const out = items.map((c, i) => {
|
|
532
|
+
const id = c.id?.trim() || undefined;
|
|
533
|
+
if (id !== undefined && !CRITERION_ID_RE.test(id))
|
|
534
|
+
throw new AcceptanceInputError(`受け入れ基準 ${i + 1} 件目の id が使えません: ${id}`);
|
|
535
|
+
if (id !== undefined && seen.has(id))
|
|
536
|
+
throw new AcceptanceInputError(`受け入れ基準の id が重複しています: ${id}`);
|
|
537
|
+
if (id !== undefined)
|
|
538
|
+
seen.add(id);
|
|
539
|
+
return { ...(id !== undefined ? { id } : {}), text: cleanText(c.text, `受け入れ基準 ${i + 1} 件目`) };
|
|
540
|
+
});
|
|
541
|
+
return withIds(out);
|
|
542
|
+
}
|
|
543
|
+
/** 基準の並びが同じか(id と文。タスク案の編集の競合を見る) */
|
|
544
|
+
export const sameCriteria = (a, b) => JSON.stringify((a ?? []).map((c) => [c.id, c.text])) === JSON.stringify((b ?? []).map((c) => [c.id, c.text]));
|
|
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()) {
|
|
552
|
+
if (!criteria?.length)
|
|
553
|
+
return {};
|
|
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);
|
|
590
|
+
}
|
|
591
|
+
// --- 画面の基準の編集 ---------------------------------------------------------------
|
|
592
|
+
/**
|
|
593
|
+
* 画面で並び全体を直した結果(rows。id の無い行は新しい基準)を、今の基準(state)への操作にする:
|
|
594
|
+
* 消す → 文を変える → 足す → 並べる(足した基準の id は今の採番の続きになる。rev を添えて送れば、他で変わっていれば 409 で当たらない)。
|
|
595
|
+
* 変わっていなければ空。id が今の基準に無い行は新しい基準として足す
|
|
596
|
+
*/
|
|
597
|
+
export function criteriaEditOps(state, rows) {
|
|
598
|
+
const cur = state.acceptanceCriteria ?? [];
|
|
599
|
+
const known = new Set(cur.map((c) => c.id));
|
|
600
|
+
const kept = rows.filter((r) => r.id !== undefined && known.has(r.id));
|
|
601
|
+
const keptIds = new Set(kept.map((r) => r.id));
|
|
602
|
+
const ops = [];
|
|
603
|
+
for (const c of cur)
|
|
604
|
+
if (!keptIds.has(c.id))
|
|
605
|
+
ops.push({ op: "remove", id: c.id });
|
|
606
|
+
for (const r of kept)
|
|
607
|
+
if (cur.find((c) => c.id === r.id).text !== r.text.trim())
|
|
608
|
+
ops.push({ op: "edit", id: r.id, text: r.text });
|
|
609
|
+
let seq = lastSeq(state);
|
|
610
|
+
const finalIds = rows.map((r) => (r.id !== undefined && keptIds.has(r.id) ? r.id : `A${++seq}`));
|
|
611
|
+
for (const r of rows)
|
|
612
|
+
if (!(r.id !== undefined && keptIds.has(r.id)))
|
|
613
|
+
ops.push({ op: "add", text: r.text });
|
|
614
|
+
const afterIds = [...cur.filter((c) => keptIds.has(c.id)).map((c) => c.id), ...finalIds.filter((id) => !keptIds.has(id))];
|
|
615
|
+
if (afterIds.join(",") !== finalIds.join(","))
|
|
616
|
+
ops.push({ op: "order", ids: finalIds });
|
|
617
|
+
return ops;
|
|
618
|
+
}
|