@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,635 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 要求そのものの根拠(出典・確かめた人・確かめた日・根拠)と、Preflight の確認事項(clarify)への回答の規則。
|
|
3
|
+
* CLI・API・画面・Preflight で同じものを使う(保存は core/requestOps.ts と core/preflight/service.ts がこれで確かめる)。
|
|
4
|
+
*
|
|
5
|
+
* - 実装後の達成の証拠(shared/acceptance.ts の AcceptanceEvidence.basis)や、AI の調べた箇所(PreflightAssessment.evidence)とは別のもの。
|
|
6
|
+
* 「何が正しい要求か」の根拠で、業務の担当が承認した計算例・規則や契約の該当箇所などを書く
|
|
7
|
+
* - 根拠記録は要望(request.md の requirementSources)と、受け入れ基準ごと(タスク・タスク案の acceptanceSources。criterionId で対応付ける)に持てる。
|
|
8
|
+
* どれも任意で、無いのは「未記録」。要望の記録を基準が参照すると、そのときの内容を写して参照元の ID(from)を残す。
|
|
9
|
+
* 要望全体の確認を基準に自動で引き継がない(写した記録は未確認から始まる)
|
|
10
|
+
* - 確かめた人(by)は役割名かアクター名の文字列。氏名・連絡先は求めない。保存した人(recordedBy)とは別に持つ。確かめた日(on)は
|
|
11
|
+
* 利用者が書く YYYY-MM-DD で、保存した日で補わない
|
|
12
|
+
* - 確認の記録には出典・根拠・確かめた人・確かめた日がそろうことが要る(下書きは出典だけ・対象だけでも保存できる)。
|
|
13
|
+
* 確認したときの対象(要望の題と本文、または基準の文)と記録の対象文・出典・根拠を固定して残し、どれかが変わったら「再確認が必要」。
|
|
14
|
+
* 変わった確認は保存するときに履歴(history)へ移すので、文を元に戻しただけでは確認記録ありに戻らない(もう一度確認を記録する)
|
|
15
|
+
* - 「確認記録あり」は、申告された確認が今の対象に対応するという意味で、P3 の認証・保証ではない。AI の評価・実装の met・人の済みでは変わらない
|
|
16
|
+
* - 回答は要望の clarifyAnswers に残す(過去の run と評価は書き換えない)。元の run と確認事項の ID・質問の写しを持つ。回答しただけでは
|
|
17
|
+
* 根拠記録を確認記録ありにしない。次の run の同じ質問へ文字の一致で移さず、元の組のまま資料として渡す
|
|
18
|
+
* - 直接編集で壊れた値は黙って消さず problems にし、関係のない更新ではファイルの元の値のまま書き戻す(keepRaw)
|
|
19
|
+
*/
|
|
20
|
+
export const REQUIREMENT_LIMITS = {
|
|
21
|
+
/** 1つの要望・1つのタスクの記録の件数 */
|
|
22
|
+
records: 50,
|
|
23
|
+
/** 対象の要求・前提の文 */
|
|
24
|
+
target: 1000,
|
|
25
|
+
/** 出典(要求元の役割・資料名・版・節) */
|
|
26
|
+
source: 1000,
|
|
27
|
+
/** 根拠の本文(承認された計算例など) */
|
|
28
|
+
basis: 20000,
|
|
29
|
+
/** 確かめた人・回答した人(役割名・アクター名) */
|
|
30
|
+
by: 100,
|
|
31
|
+
/** 回答の件数 */
|
|
32
|
+
answers: 200,
|
|
33
|
+
/** 回答の本文 */
|
|
34
|
+
answer: 20000,
|
|
35
|
+
/** 確認事項の件数(1つの評価) */
|
|
36
|
+
clarifications: 30,
|
|
37
|
+
/** 確認事項の各項目 */
|
|
38
|
+
clarificationText: 2000,
|
|
39
|
+
};
|
|
40
|
+
export const SOURCE_STATE_LABEL = {
|
|
41
|
+
unrecorded: "未記録",
|
|
42
|
+
unconfirmed: "未確認",
|
|
43
|
+
confirmed: "確認記録あり",
|
|
44
|
+
reconfirm: "再確認が必要",
|
|
45
|
+
unlinked: "対応先不明",
|
|
46
|
+
};
|
|
47
|
+
export const SOURCE_STATE_HINT = {
|
|
48
|
+
unrecorded: "出典・根拠の記録がありません",
|
|
49
|
+
unconfirmed: "出典や根拠はあるが、確かめた記録がありません",
|
|
50
|
+
confirmed: "記録した確認が今の内容に対応しています(申告。P3 の保証ではありません)",
|
|
51
|
+
reconfirm: "確認した後で対象か根拠が変わりました。もう一度確かめて記録してください",
|
|
52
|
+
unlinked: "対応する基準・参照元の記録がありません",
|
|
53
|
+
};
|
|
54
|
+
/** 確認先が分からないときの確認先 */
|
|
55
|
+
export const ASK_UNKNOWN = "要望者に確認先を特定してもらう";
|
|
56
|
+
export const ANSWER_STATE_LABEL = {
|
|
57
|
+
answered: "回答済み",
|
|
58
|
+
unanswered: "未回答",
|
|
59
|
+
reconfirm: "再確認が必要",
|
|
60
|
+
unlinked: "参照元不明",
|
|
61
|
+
};
|
|
62
|
+
/** ファイルに書く要望の項目(壊れていたら元の値のまま書き戻す) */
|
|
63
|
+
export const REQUIREMENT_KEYS = ["requirementSources", "requirementSeq", "clarifyAnswers"];
|
|
64
|
+
/** 入力が規則に合わない(何も書いていない)。CLI は使い方の誤り、API は 400 */
|
|
65
|
+
export class RequirementInputError extends Error {
|
|
66
|
+
code = "requirement_invalid";
|
|
67
|
+
}
|
|
68
|
+
export const SOURCE_ID_RE = /^[A-Za-z0-9._-]{1,32}$/;
|
|
69
|
+
export const DATE_RE = /^\d{4}-\d{2}-\d{2}$/;
|
|
70
|
+
/** 実在する日付か(YYYY-MM-DD) */
|
|
71
|
+
export function isDate(v) {
|
|
72
|
+
if (!DATE_RE.test(v))
|
|
73
|
+
return false;
|
|
74
|
+
const d = new Date(`${v}T00:00:00Z`);
|
|
75
|
+
return !Number.isNaN(d.getTime()) && d.toISOString().slice(0, 10) === v;
|
|
76
|
+
}
|
|
77
|
+
// --- hash ----------------------------------------------------------------------
|
|
78
|
+
/** 依存を足さない短い hash(変わったかを比べるだけ。画面でも同じ値になる) */
|
|
79
|
+
export function textHash(s) {
|
|
80
|
+
let h1 = 0x811c9dc5;
|
|
81
|
+
let h2 = 0x01000193;
|
|
82
|
+
for (let i = 0; i < s.length; i++) {
|
|
83
|
+
const c = s.charCodeAt(i);
|
|
84
|
+
h1 = Math.imul(h1 ^ c, 0x01000193) >>> 0;
|
|
85
|
+
h2 = Math.imul(h2 ^ c, 0x85ebca6b) >>> 0;
|
|
86
|
+
}
|
|
87
|
+
return `${h1.toString(16).padStart(8, "0")}${h2.toString(16).padStart(8, "0")}`;
|
|
88
|
+
}
|
|
89
|
+
const nl = (s) => s.replace(/\r\n?/g, "\n").trim();
|
|
90
|
+
/** 要望の記録の対象(題と本文)の hash */
|
|
91
|
+
export const requestSubject = (r) => textHash(`request\n${nl(r.title)}\n${nl(r.body)}`);
|
|
92
|
+
/** 基準の記録の対象(基準の文)の hash */
|
|
93
|
+
export const criterionSubject = (text) => textHash(`criterion\n${nl(text)}`);
|
|
94
|
+
/** 記録の内容(対象文・出典・根拠)の hash(回答の対応の変化を見る) */
|
|
95
|
+
export const sourceContentHash = (s) => textHash(JSON.stringify([s.target ?? "", s.source ?? "", s.basis ?? ""]));
|
|
96
|
+
// --- 読む ----------------------------------------------------------------------
|
|
97
|
+
const str = (v) => (typeof v === "string" ? v : typeof v === "number" ? String(v) : undefined);
|
|
98
|
+
const opt = (v) => {
|
|
99
|
+
const s = str(v)?.trim();
|
|
100
|
+
return s ? s : undefined;
|
|
101
|
+
};
|
|
102
|
+
const iso = (v) => (v instanceof Date ? v.toISOString() : typeof v === "string" && v ? v : undefined);
|
|
103
|
+
/** YAML は日付を Date にしてしまうので YYYY-MM-DD に戻す */
|
|
104
|
+
const day = (v) => (v instanceof Date ? v.toISOString().slice(0, 10) : opt(v));
|
|
105
|
+
function readConfirmation(v, at) {
|
|
106
|
+
if (!v || typeof v !== "object" || Array.isArray(v))
|
|
107
|
+
return `${at} の確認(confirmed)が読めません`;
|
|
108
|
+
const o = v;
|
|
109
|
+
const by = opt(o.by);
|
|
110
|
+
const on = day(o.on);
|
|
111
|
+
const subject = opt(o.subject);
|
|
112
|
+
if (!by)
|
|
113
|
+
return `${at} の確認に確かめた人(by)がありません`;
|
|
114
|
+
if (!on || !isDate(on))
|
|
115
|
+
return `${at} の確認の日(on)が YYYY-MM-DD ではありません`;
|
|
116
|
+
if (!subject)
|
|
117
|
+
return `${at} の確認に対象の記録(subject)がありません`;
|
|
118
|
+
return {
|
|
119
|
+
by,
|
|
120
|
+
on,
|
|
121
|
+
target: str(o.target) ?? "",
|
|
122
|
+
source: str(o.source) ?? "",
|
|
123
|
+
basis: str(o.basis) ?? "",
|
|
124
|
+
subject,
|
|
125
|
+
recordedAt: iso(o.recordedAt) ?? new Date(0).toISOString(),
|
|
126
|
+
...(opt(o.recordedBy) ? { recordedBy: opt(o.recordedBy) } : {}),
|
|
127
|
+
...(iso(o.lapsedAt) ? { lapsedAt: iso(o.lapsedAt) } : {}),
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
function readSource(raw, at, withCriterion) {
|
|
131
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw))
|
|
132
|
+
return `${at} が項目になっていません`;
|
|
133
|
+
const o = raw;
|
|
134
|
+
const id = opt(o.id) ?? "";
|
|
135
|
+
const label = `${at}${id ? `(${id})` : ""}`;
|
|
136
|
+
if (!SOURCE_ID_RE.test(id))
|
|
137
|
+
return `${label} の id が読めません`;
|
|
138
|
+
const criterionId = opt(o.criterionId);
|
|
139
|
+
if (withCriterion && !criterionId)
|
|
140
|
+
return `${label} の criterionId がありません`;
|
|
141
|
+
const out = { id, ...(withCriterion ? { criterionId } : {}) };
|
|
142
|
+
for (const k of ["target", "source", "basis", "from"]) {
|
|
143
|
+
const v = o[k];
|
|
144
|
+
if (v === undefined || v === null)
|
|
145
|
+
continue;
|
|
146
|
+
if (typeof v !== "string" && typeof v !== "number")
|
|
147
|
+
return `${label} の ${k} が文ではありません`;
|
|
148
|
+
const s = String(v).trim();
|
|
149
|
+
if (s)
|
|
150
|
+
out[k] = s;
|
|
151
|
+
}
|
|
152
|
+
const tooLong = lengthProblem(out);
|
|
153
|
+
if (tooLong)
|
|
154
|
+
return `${label}: ${tooLong}`;
|
|
155
|
+
if (o.confirmed !== undefined && o.confirmed !== null) {
|
|
156
|
+
const c = readConfirmation(o.confirmed, label);
|
|
157
|
+
if (typeof c === "string")
|
|
158
|
+
return c;
|
|
159
|
+
out.confirmed = c;
|
|
160
|
+
}
|
|
161
|
+
if (o.history !== undefined && o.history !== null) {
|
|
162
|
+
if (!Array.isArray(o.history))
|
|
163
|
+
return `${label} の history が並びになっていません`;
|
|
164
|
+
const history = [];
|
|
165
|
+
for (const h of o.history) {
|
|
166
|
+
const c = readConfirmation(h, `${label} の履歴`);
|
|
167
|
+
if (typeof c === "string")
|
|
168
|
+
return c;
|
|
169
|
+
history.push(c);
|
|
170
|
+
}
|
|
171
|
+
if (history.length)
|
|
172
|
+
out.history = history;
|
|
173
|
+
}
|
|
174
|
+
if (iso(o.recordedAt))
|
|
175
|
+
out.recordedAt = iso(o.recordedAt);
|
|
176
|
+
if (opt(o.recordedBy))
|
|
177
|
+
out.recordedBy = opt(o.recordedBy);
|
|
178
|
+
return out;
|
|
179
|
+
}
|
|
180
|
+
/** 記録の並びを読む(読めない項目は除いて problems に理由を足す) */
|
|
181
|
+
function readSourceList(v, key, withCriterion, problems) {
|
|
182
|
+
if (!Array.isArray(v)) {
|
|
183
|
+
problems.push(`${key} が並びになっていません`);
|
|
184
|
+
return [];
|
|
185
|
+
}
|
|
186
|
+
const out = [];
|
|
187
|
+
for (const [i, raw] of v.entries()) {
|
|
188
|
+
const r = readSource(raw, `根拠の記録 ${i + 1} 件目`, withCriterion);
|
|
189
|
+
if (typeof r === "string")
|
|
190
|
+
problems.push(r);
|
|
191
|
+
else if (out.some((x) => x.id === r.id))
|
|
192
|
+
problems.push(`根拠の記録の id が重複しています: ${r.id}`);
|
|
193
|
+
else
|
|
194
|
+
out.push(r);
|
|
195
|
+
}
|
|
196
|
+
if (out.length > REQUIREMENT_LIMITS.records)
|
|
197
|
+
problems.push(`根拠の記録は ${REQUIREMENT_LIMITS.records} 件までです(${out.length} 件)`);
|
|
198
|
+
return out;
|
|
199
|
+
}
|
|
200
|
+
function readAnswer(raw, at) {
|
|
201
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw))
|
|
202
|
+
return `${at} が項目になっていません`;
|
|
203
|
+
const o = raw;
|
|
204
|
+
const run = opt(o.run);
|
|
205
|
+
const question = opt(o.question);
|
|
206
|
+
if (!run || !question)
|
|
207
|
+
return `${at} に元の run と確認事項の ID(run・question)がありません`;
|
|
208
|
+
const label = `${at}(${run}/${question})`;
|
|
209
|
+
const answer = opt(o.answer);
|
|
210
|
+
if (!answer)
|
|
211
|
+
return `${label} の回答(answer)が空です`;
|
|
212
|
+
const copy = o.copy && typeof o.copy === "object" ? o.copy : {};
|
|
213
|
+
const on = day(o.on);
|
|
214
|
+
if (on !== undefined && !isDate(on))
|
|
215
|
+
return `${label} の日(on)が YYYY-MM-DD ではありません`;
|
|
216
|
+
let links;
|
|
217
|
+
if (o.links !== undefined && o.links !== null) {
|
|
218
|
+
if (!Array.isArray(o.links))
|
|
219
|
+
return `${label} の links が並びになっていません`;
|
|
220
|
+
links = [];
|
|
221
|
+
for (const l of o.links) {
|
|
222
|
+
const lo = l && typeof l === "object" ? l : {};
|
|
223
|
+
const id = opt(lo.id);
|
|
224
|
+
const hash = opt(lo.hash);
|
|
225
|
+
if (!id || !hash)
|
|
226
|
+
return `${label} の links の項目が読めません(id・hash が要ります)`;
|
|
227
|
+
links.push({ id, hash });
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
return {
|
|
231
|
+
run,
|
|
232
|
+
question,
|
|
233
|
+
copy: { question: str(copy.question) ?? "", ask: str(copy.ask) ?? "", target: str(copy.target) ?? "" },
|
|
234
|
+
answer,
|
|
235
|
+
...(opt(o.by) ? { by: opt(o.by) } : {}),
|
|
236
|
+
...(on ? { on } : {}),
|
|
237
|
+
...(opt(o.source) ? { source: opt(o.source) } : {}),
|
|
238
|
+
...(opt(o.basis) ? { basis: opt(o.basis) } : {}),
|
|
239
|
+
...(links?.length ? { links } : {}),
|
|
240
|
+
recordedAt: iso(o.recordedAt) ?? new Date(0).toISOString(),
|
|
241
|
+
...(opt(o.recordedBy) ? { recordedBy: opt(o.recordedBy) } : {}),
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
/** 要望の frontmatter の値を読む。どれも無ければ何も足さない(古い要望はそのまま) */
|
|
245
|
+
export function readRequirement(d) {
|
|
246
|
+
const problems = [];
|
|
247
|
+
const out = {};
|
|
248
|
+
if (d.requirementSources !== undefined && d.requirementSources !== null) {
|
|
249
|
+
const list = readSourceList(d.requirementSources, "requirementSources", false, problems);
|
|
250
|
+
if (list.length)
|
|
251
|
+
out.requirementSources = list;
|
|
252
|
+
}
|
|
253
|
+
if (d.requirementSeq !== undefined && d.requirementSeq !== null) {
|
|
254
|
+
const n = Number(d.requirementSeq);
|
|
255
|
+
if (Number.isInteger(n) && n >= 0)
|
|
256
|
+
out.requirementSeq = n;
|
|
257
|
+
else
|
|
258
|
+
problems.push("requirementSeq が読めません");
|
|
259
|
+
}
|
|
260
|
+
if (d.clarifyAnswers !== undefined && d.clarifyAnswers !== null) {
|
|
261
|
+
if (!Array.isArray(d.clarifyAnswers))
|
|
262
|
+
problems.push("clarifyAnswers が並びになっていません");
|
|
263
|
+
else {
|
|
264
|
+
const answers = [];
|
|
265
|
+
for (const [i, raw] of d.clarifyAnswers.entries()) {
|
|
266
|
+
const a = readAnswer(raw, `回答 ${i + 1} 件目`);
|
|
267
|
+
if (typeof a === "string")
|
|
268
|
+
problems.push(a);
|
|
269
|
+
else if (answers.some((x) => x.run === a.run && x.question === a.question))
|
|
270
|
+
problems.push(`同じ確認事項への回答が重複しています: ${a.run}/${a.question}`);
|
|
271
|
+
else
|
|
272
|
+
answers.push(a);
|
|
273
|
+
}
|
|
274
|
+
if (answers.length)
|
|
275
|
+
out.clarifyAnswers = answers;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
if (problems.length)
|
|
279
|
+
out.requirementProblems = problems;
|
|
280
|
+
return out;
|
|
281
|
+
}
|
|
282
|
+
/** タスク・タスク案の基準の根拠の記録を読む(acceptanceSources) */
|
|
283
|
+
export function readCriterionSources(v, problems) {
|
|
284
|
+
if (v === undefined || v === null)
|
|
285
|
+
return undefined;
|
|
286
|
+
const list = readSourceList(v, "acceptanceSources", true, problems);
|
|
287
|
+
return list.length ? list : undefined;
|
|
288
|
+
}
|
|
289
|
+
// --- 状態 ----------------------------------------------------------------------
|
|
290
|
+
/** 確認したときの内容と今が同じか */
|
|
291
|
+
function confirmationHolds(c, s, subject) {
|
|
292
|
+
return c.subject === subject && c.target === (s.target ?? "") && c.source === (s.source ?? "") && c.basis === (s.basis ?? "");
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* 記録1件の確認の状態。subject: 今の対象の hash(対応する基準が無ければ undefined で対応先不明)。
|
|
296
|
+
* known: 要望の記録の ID(基準の記録の参照元を確かめる。省くと確かめない)
|
|
297
|
+
*/
|
|
298
|
+
export function sourceState(s, subject, known) {
|
|
299
|
+
if (subject === undefined)
|
|
300
|
+
return "unlinked";
|
|
301
|
+
if (s.from && known && !known.includes(s.from))
|
|
302
|
+
return "unlinked";
|
|
303
|
+
if (s.confirmed)
|
|
304
|
+
return confirmationHolds(s.confirmed, s, subject) ? "confirmed" : "reconfirm";
|
|
305
|
+
return s.history?.length ? "reconfirm" : "unconfirmed";
|
|
306
|
+
}
|
|
307
|
+
/** 対象の記録の並び(無ければ未記録)の状態をまとめる: どれか再確認・対応先不明 → それ、全部確認記録あり → 確認記録あり、ほかは未確認 */
|
|
308
|
+
export function overallState(states) {
|
|
309
|
+
if (!states.length)
|
|
310
|
+
return "unrecorded";
|
|
311
|
+
for (const s of ["unlinked", "reconfirm", "unconfirmed"])
|
|
312
|
+
if (states.includes(s))
|
|
313
|
+
return s;
|
|
314
|
+
return "confirmed";
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* 保存の前に、効かなくなった確認を履歴へ移す(対象か内容が確認したときと違う)。文を元に戻しても確認記録ありに戻らないようにする
|
|
318
|
+
*/
|
|
319
|
+
export function settleSources(list, subjectOf, now) {
|
|
320
|
+
return list.map((s) => {
|
|
321
|
+
const subject = subjectOf(s);
|
|
322
|
+
if (!s.confirmed || subject === undefined || confirmationHolds(s.confirmed, s, subject))
|
|
323
|
+
return s;
|
|
324
|
+
const { confirmed, ...rest } = s;
|
|
325
|
+
return { ...rest, history: [...(s.history ?? []), { ...confirmed, lapsedAt: now }] };
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
/** 回答の状態(runs: 今ある run の確認事項。省くと参照元を確かめない) */
|
|
329
|
+
export function answerState(a, sources, runs) {
|
|
330
|
+
if (runs && !runs.get(a.run)?.some((q) => q.id === a.question))
|
|
331
|
+
return "unlinked";
|
|
332
|
+
for (const l of a.links ?? []) {
|
|
333
|
+
const s = sources.find((x) => x.id === l.id);
|
|
334
|
+
if (!s)
|
|
335
|
+
return "unlinked";
|
|
336
|
+
if (sourceContentHash(s) !== l.hash)
|
|
337
|
+
return "reconfirm";
|
|
338
|
+
}
|
|
339
|
+
return "answered";
|
|
340
|
+
}
|
|
341
|
+
/** 確認事項ごとの回答の状態(未回答を含む)。run の確認事項の順 */
|
|
342
|
+
export function clarificationStates(runId, clarifications, answers, sources) {
|
|
343
|
+
return clarifications.map((q) => {
|
|
344
|
+
const a = (answers ?? []).find((x) => x.run === runId && x.question === q.id);
|
|
345
|
+
return { clarification: q, state: a ? answerState(a, sources ?? []) : "unanswered", ...(a ? { answer: a } : {}) };
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
const FIELD_LABEL = { target: "対象の文", source: "出典", basis: "根拠" };
|
|
349
|
+
function lengthProblem(s) {
|
|
350
|
+
for (const k of ["target", "source", "basis"]) {
|
|
351
|
+
const v = s[k];
|
|
352
|
+
if (v && v.length > REQUIREMENT_LIMITS[k])
|
|
353
|
+
return `${FIELD_LABEL[k]}は ${REQUIREMENT_LIMITS[k]} 文字までです(${v.length} 文字)`;
|
|
354
|
+
}
|
|
355
|
+
return undefined;
|
|
356
|
+
}
|
|
357
|
+
function cleanField(v, label) {
|
|
358
|
+
if (v === undefined || v === null)
|
|
359
|
+
return undefined;
|
|
360
|
+
if (typeof v !== "string")
|
|
361
|
+
throw new RequirementInputError(`${label}は文で書いてください`);
|
|
362
|
+
return v.trim();
|
|
363
|
+
}
|
|
364
|
+
/** 確かめた人・日を確かめる */
|
|
365
|
+
export function cleanConfirm(c, label) {
|
|
366
|
+
const by = typeof c.by === "string" ? c.by.trim() : "";
|
|
367
|
+
const on = typeof c.on === "string" ? c.on.trim() : "";
|
|
368
|
+
if (!by)
|
|
369
|
+
throw new RequirementInputError(`${label}: 確かめた人(役割名かアクター名)を書いてください`);
|
|
370
|
+
if (by.length > REQUIREMENT_LIMITS.by)
|
|
371
|
+
throw new RequirementInputError(`${label}: 確かめた人は ${REQUIREMENT_LIMITS.by} 文字までです`);
|
|
372
|
+
if (!isDate(on))
|
|
373
|
+
throw new RequirementInputError(`${label}: 確かめた日は YYYY-MM-DD で書いてください: ${on || "(空)"}`);
|
|
374
|
+
return { by, on };
|
|
375
|
+
}
|
|
376
|
+
/** 振った最後の番号 */
|
|
377
|
+
export function sourceSeq(list, seq = 0) {
|
|
378
|
+
return list.reduce((n, s) => Math.max(n, /^S(\d+)$/.exec(s.id) ? Number(s.id.slice(1)) : 0), seq);
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* 操作を順に当てた後の記録(何も書かない。規則に合わなければ RequirementInputError で、1件も当てない)。
|
|
382
|
+
* 当てた後に、効かなくなった確認を履歴へ移す(settleSources)。同じ値の再保存は元の記録をそのまま残す
|
|
383
|
+
*/
|
|
384
|
+
export function applySourceOps(list, ops, ctx) {
|
|
385
|
+
let out = [...list];
|
|
386
|
+
let seq = sourceSeq(list, ctx.seq ?? 0);
|
|
387
|
+
const find = (id) => {
|
|
388
|
+
const s = out.find((x) => x.id === id);
|
|
389
|
+
if (!s)
|
|
390
|
+
throw new RequirementInputError(`根拠の記録 ${id} はありません${out.length ? `(${out.map((x) => x.id).join(", ")})` : "(記録がありません)"}`);
|
|
391
|
+
return s;
|
|
392
|
+
};
|
|
393
|
+
const confirmOf = (s, c) => {
|
|
394
|
+
const { by, on } = cleanConfirm(c, `根拠の記録 ${s.id}`);
|
|
395
|
+
const missing = ["source", "basis"].filter((k) => !s[k]);
|
|
396
|
+
if (missing.length)
|
|
397
|
+
throw new RequirementInputError(`根拠の記録 ${s.id} の確認を記録するには${missing.map((k) => FIELD_LABEL[k]).join("と")}が要ります(下書きは確認なしで保存できます)`);
|
|
398
|
+
const subject = ctx.subjectOf(s);
|
|
399
|
+
if (subject === undefined)
|
|
400
|
+
throw new RequirementInputError(`根拠の記録 ${s.id} は対応する基準が無いので確認を記録できません`);
|
|
401
|
+
return { by, on, target: s.target ?? "", source: s.source ?? "", basis: s.basis ?? "", subject, recordedAt: ctx.now, ...(ctx.actor ? { recordedBy: ctx.actor } : {}) };
|
|
402
|
+
};
|
|
403
|
+
const withFields = (s, f) => {
|
|
404
|
+
const next = { ...s };
|
|
405
|
+
for (const k of ["target", "source", "basis"]) {
|
|
406
|
+
const v = cleanField(f[k], FIELD_LABEL[k]);
|
|
407
|
+
if (v === undefined)
|
|
408
|
+
continue;
|
|
409
|
+
if (v)
|
|
410
|
+
next[k] = v;
|
|
411
|
+
else
|
|
412
|
+
delete next[k];
|
|
413
|
+
}
|
|
414
|
+
const tooLong = lengthProblem(next);
|
|
415
|
+
if (tooLong)
|
|
416
|
+
throw new RequirementInputError(`根拠の記録 ${s.id}: ${tooLong}`);
|
|
417
|
+
return next;
|
|
418
|
+
};
|
|
419
|
+
const stamp = (s) => ({ ...s, recordedAt: ctx.now, ...(ctx.actor ? { recordedBy: ctx.actor } : {}) });
|
|
420
|
+
const same = (a, b) => JSON.stringify([a.target, a.source, a.basis, a.from]) === JSON.stringify([b.target, b.source, b.basis, b.from]);
|
|
421
|
+
for (const op of ops) {
|
|
422
|
+
switch (op.op) {
|
|
423
|
+
case "add": {
|
|
424
|
+
if (out.length >= REQUIREMENT_LIMITS.records)
|
|
425
|
+
throw new RequirementInputError(`根拠の記録は ${REQUIREMENT_LIMITS.records} 件までです`);
|
|
426
|
+
seq += 1;
|
|
427
|
+
let s = { id: `S${seq}`, ...(ctx.criterionId ? { criterionId: ctx.criterionId } : {}) };
|
|
428
|
+
if (op.from !== undefined) {
|
|
429
|
+
if (!ctx.requestSources)
|
|
430
|
+
throw new RequirementInputError("要望の記録を写せるのは受け入れ基準の記録だけです");
|
|
431
|
+
const src = ctx.requestSources.find((x) => x.id === op.from);
|
|
432
|
+
if (!src)
|
|
433
|
+
throw new RequirementInputError(`要望の根拠の記録 ${op.from} はありません`);
|
|
434
|
+
// 写すのは内容だけ(確認は引き継がない)
|
|
435
|
+
s = { ...s, from: src.id, ...(src.target ? { target: src.target } : {}), ...(src.source ? { source: src.source } : {}), ...(src.basis ? { basis: src.basis } : {}) };
|
|
436
|
+
}
|
|
437
|
+
s = withFields(s, op);
|
|
438
|
+
if (!s.target && !s.source && !s.basis)
|
|
439
|
+
throw new RequirementInputError("根拠の記録には対象の文・出典・根拠のどれかを書いてください");
|
|
440
|
+
s = stamp(s);
|
|
441
|
+
if (op.confirm)
|
|
442
|
+
s = { ...s, confirmed: confirmOf(s, op.confirm) };
|
|
443
|
+
out.push(s);
|
|
444
|
+
break;
|
|
445
|
+
}
|
|
446
|
+
case "edit": {
|
|
447
|
+
const cur = find(op.id);
|
|
448
|
+
let s = withFields(cur, op);
|
|
449
|
+
if (!s.target && !s.source && !s.basis)
|
|
450
|
+
throw new RequirementInputError(`根拠の記録 ${op.id} を空にはできません(消すなら remove)`);
|
|
451
|
+
if (!same(cur, s))
|
|
452
|
+
s = stamp(s);
|
|
453
|
+
if (op.confirm) {
|
|
454
|
+
// 効かなくなった前の確認は履歴へ
|
|
455
|
+
const settled = settleSources([s], ctx.subjectOf, ctx.now)[0];
|
|
456
|
+
s = { ...settled, confirmed: confirmOf(settled, op.confirm) };
|
|
457
|
+
}
|
|
458
|
+
out = out.map((x) => (x === cur ? s : x));
|
|
459
|
+
break;
|
|
460
|
+
}
|
|
461
|
+
case "confirm": {
|
|
462
|
+
const cur = find(op.id);
|
|
463
|
+
const settled = settleSources([cur], ctx.subjectOf, ctx.now)[0];
|
|
464
|
+
const c = confirmOf(settled, op);
|
|
465
|
+
// 同じ人・日で今も効いている確認の付け直しは何もしない
|
|
466
|
+
if (cur.confirmed && cur.confirmed.by === c.by && cur.confirmed.on === c.on && confirmationHolds(cur.confirmed, cur, c.subject))
|
|
467
|
+
break;
|
|
468
|
+
const next = { ...settled, confirmed: c };
|
|
469
|
+
// 効いている確認の付け直し(人・日の訂正)は前の確認を履歴に残す
|
|
470
|
+
if (settled.confirmed)
|
|
471
|
+
next.history = [...(settled.history ?? []), { ...settled.confirmed, lapsedAt: ctx.now }];
|
|
472
|
+
out = out.map((x) => (x === cur ? next : x));
|
|
473
|
+
break;
|
|
474
|
+
}
|
|
475
|
+
case "remove": {
|
|
476
|
+
const cur = find(op.id);
|
|
477
|
+
out = out.filter((x) => x !== cur);
|
|
478
|
+
break;
|
|
479
|
+
}
|
|
480
|
+
default:
|
|
481
|
+
throw new RequirementInputError(`知らない操作です: ${String(op.op)}`);
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
return { list: settleSources(out, ctx.subjectOf, ctx.now), seq };
|
|
485
|
+
}
|
|
486
|
+
/** 保存した記録の比較の鍵(記録の日時・保存者は見ない。確認は人・日・固定した内容を見る) */
|
|
487
|
+
export function sourcesKey(list) {
|
|
488
|
+
const c = (x) => (x ? [x.by, x.on, x.target, x.source, x.basis, x.subject, x.lapsedAt ?? ""] : null);
|
|
489
|
+
return JSON.stringify((list ?? []).map((s) => [s.criterionId ?? "", s.id, s.target ?? "", s.source ?? "", s.basis ?? "", s.from ?? "", c(s.confirmed), (s.history ?? []).map(c)]));
|
|
490
|
+
}
|
|
491
|
+
/** 回答の比較の鍵(記録の日時・保存者は見ない) */
|
|
492
|
+
export function answersKey(list) {
|
|
493
|
+
return JSON.stringify((list ?? []).map((a) => [a.run, a.question, a.copy.question, a.copy.ask, a.copy.target, a.answer, a.by ?? "", a.on ?? "", a.source ?? "", a.basis ?? "", (a.links ?? []).map((l) => `${l.id}:${l.hash}`)]));
|
|
494
|
+
}
|
|
495
|
+
/**
|
|
496
|
+
* 回答を確かめて保存する形にする(clarification は元の run の確認事項。写しを持つ)。規則に合わなければ RequirementInputError
|
|
497
|
+
*/
|
|
498
|
+
export function makeAnswer(runId, q, input, sources, at) {
|
|
499
|
+
const answer = typeof input.answer === "string" ? input.answer.trim() : "";
|
|
500
|
+
if (!answer)
|
|
501
|
+
throw new RequirementInputError(`${q.id} の回答が空です`);
|
|
502
|
+
if (answer.length > REQUIREMENT_LIMITS.answer)
|
|
503
|
+
throw new RequirementInputError(`${q.id} の回答は ${REQUIREMENT_LIMITS.answer} 文字までです(${answer.length} 文字)`);
|
|
504
|
+
const by = input.by?.trim();
|
|
505
|
+
if (by && by.length > REQUIREMENT_LIMITS.by)
|
|
506
|
+
throw new RequirementInputError(`回答した人は ${REQUIREMENT_LIMITS.by} 文字までです`);
|
|
507
|
+
const on = input.on?.trim();
|
|
508
|
+
if (on && !isDate(on))
|
|
509
|
+
throw new RequirementInputError(`回答の日は YYYY-MM-DD で書いてください: ${on}`);
|
|
510
|
+
const source = input.source?.trim();
|
|
511
|
+
if (source && source.length > REQUIREMENT_LIMITS.source)
|
|
512
|
+
throw new RequirementInputError(`出典は ${REQUIREMENT_LIMITS.source} 文字までです`);
|
|
513
|
+
const basis = input.basis?.trim();
|
|
514
|
+
if (basis && basis.length > REQUIREMENT_LIMITS.basis)
|
|
515
|
+
throw new RequirementInputError(`根拠は ${REQUIREMENT_LIMITS.basis} 文字までです`);
|
|
516
|
+
const links = [...new Set(input.links ?? [])].map((id) => {
|
|
517
|
+
const s = sources.find((x) => x.id === id);
|
|
518
|
+
if (!s)
|
|
519
|
+
throw new RequirementInputError(`要望の根拠の記録 ${id} はありません${sources.length ? `(${sources.map((x) => x.id).join(", ")})` : ""}`);
|
|
520
|
+
return { id, hash: sourceContentHash(s) };
|
|
521
|
+
});
|
|
522
|
+
return {
|
|
523
|
+
run: runId,
|
|
524
|
+
question: q.id,
|
|
525
|
+
copy: { question: q.question, ask: q.ask, target: q.target },
|
|
526
|
+
answer,
|
|
527
|
+
...(by ? { by } : {}),
|
|
528
|
+
...(on ? { on } : {}),
|
|
529
|
+
...(source ? { source } : {}),
|
|
530
|
+
...(basis ? { basis } : {}),
|
|
531
|
+
...(links.length ? { links } : {}),
|
|
532
|
+
recordedAt: at.now,
|
|
533
|
+
...(at.actor ? { recordedBy: at.actor } : {}),
|
|
534
|
+
};
|
|
535
|
+
}
|
|
536
|
+
/** 回答を足す・置き換える(同じ内容なら元の回答をそのまま残す) */
|
|
537
|
+
export function putAnswer(list, a) {
|
|
538
|
+
const cur = list ?? [];
|
|
539
|
+
const prev = cur.find((x) => x.run === a.run && x.question === a.question);
|
|
540
|
+
if (prev && answersKey([prev]) === answersKey([a]))
|
|
541
|
+
return [...cur];
|
|
542
|
+
if (!prev && cur.length >= REQUIREMENT_LIMITS.answers)
|
|
543
|
+
throw new RequirementInputError(`回答は ${REQUIREMENT_LIMITS.answers} 件までです`);
|
|
544
|
+
return prev ? cur.map((x) => (x === prev ? a : x)) : [...cur, a];
|
|
545
|
+
}
|
|
546
|
+
// --- Preflight の確認事項 ----------------------------------------------------------
|
|
547
|
+
/**
|
|
548
|
+
* 評価の clarifications を読む(Codex・手元のエージェントで同じ)。壊れた項目は黙って捨てず problems に理由を返す
|
|
549
|
+
*/
|
|
550
|
+
export function readClarifications(v) {
|
|
551
|
+
if (v === undefined || v === null)
|
|
552
|
+
return {};
|
|
553
|
+
if (!Array.isArray(v))
|
|
554
|
+
return { problems: ["clarifications が並びになっていません"] };
|
|
555
|
+
const problems = [];
|
|
556
|
+
const out = [];
|
|
557
|
+
for (const [i, raw] of v.entries()) {
|
|
558
|
+
const at = `確認事項 ${i + 1} 件目`;
|
|
559
|
+
const o = raw && typeof raw === "object" && !Array.isArray(raw) ? raw : undefined;
|
|
560
|
+
if (!o) {
|
|
561
|
+
problems.push(`${at} が項目になっていません`);
|
|
562
|
+
continue;
|
|
563
|
+
}
|
|
564
|
+
const id = opt(o.id) ?? `Q${i + 1}`;
|
|
565
|
+
const question = opt(o.question);
|
|
566
|
+
const target = opt(o.target);
|
|
567
|
+
const fields = { target: target ?? "", ask: opt(o.ask) ?? ASK_UNKNOWN, question: question ?? "", needed: opt(o.needed) ?? "", impact: opt(o.impact) ?? "" };
|
|
568
|
+
if (!SOURCE_ID_RE.test(id))
|
|
569
|
+
problems.push(`${at} の id が使えません: ${id}`);
|
|
570
|
+
else if (out.some((x) => x.id === id))
|
|
571
|
+
problems.push(`確認事項の id が重複しています: ${id}`);
|
|
572
|
+
else if (!question)
|
|
573
|
+
problems.push(`${at}(${id})に質問(question)がありません`);
|
|
574
|
+
else if (!target)
|
|
575
|
+
problems.push(`${at}(${id})に対象(target: 要望の前提か D1/A2 のような案と基準)がありません`);
|
|
576
|
+
else if (Object.values(fields).some((x) => x.length > REQUIREMENT_LIMITS.clarificationText))
|
|
577
|
+
problems.push(`${at}(${id})の項目は ${REQUIREMENT_LIMITS.clarificationText} 文字までです`);
|
|
578
|
+
else
|
|
579
|
+
out.push({ id, ...fields });
|
|
580
|
+
}
|
|
581
|
+
if (out.length > REQUIREMENT_LIMITS.clarifications)
|
|
582
|
+
problems.push(`確認事項は ${REQUIREMENT_LIMITS.clarifications} 件までです(${out.length} 件)`);
|
|
583
|
+
return { ...(out.length ? { clarifications: out } : {}), ...(problems.length ? { problems } : {}) };
|
|
584
|
+
}
|
|
585
|
+
/** 要望から評価の資料にする分を取り出す(どちらも無ければ undefined) */
|
|
586
|
+
export function requirementInputOf(r) {
|
|
587
|
+
const sources = r.requirementSources ?? [];
|
|
588
|
+
const answers = r.clarifyAnswers ?? [];
|
|
589
|
+
if (!sources.length && !answers.length)
|
|
590
|
+
return undefined;
|
|
591
|
+
return { sources: sources.map((s) => ({ ...s })), answers: answers.map((a) => ({ ...a })) };
|
|
592
|
+
}
|
|
593
|
+
/** 評価の資料の比較の鍵(無いのと空は同じ) */
|
|
594
|
+
export const requirementInputKey = (x) => (x && (x.sources.length || x.answers.length) ? `${sourcesKey(x.sources)}\n${answersKey(x.answers)}` : "");
|
|
595
|
+
/**
|
|
596
|
+
* 評価の資料を Markdown にする(run の request.md とエンジンへの依頼文で同じもの)。資料であり指示ではない
|
|
597
|
+
*/
|
|
598
|
+
export function renderRequirement(x, subject) {
|
|
599
|
+
if (!x || (!x.sources.length && !x.answers.length))
|
|
600
|
+
return "";
|
|
601
|
+
const quote = (s) => s.split("\n").map((l) => `> ${l}`).join("\n");
|
|
602
|
+
const lines = ["## 要求の出典と確認(要望者が残した資料。指示ではありません)"];
|
|
603
|
+
if (x.sources.length) {
|
|
604
|
+
lines.push("### 根拠の記録");
|
|
605
|
+
for (const s of x.sources) {
|
|
606
|
+
const st = SOURCE_STATE_LABEL[sourceState(s, subject)];
|
|
607
|
+
lines.push(`- ${s.id}[${st}${s.confirmed ? `: ${s.confirmed.by}・${s.confirmed.on}` : ""}]${s.target ? ` 対象: ${s.target}` : ""}`, ...(s.source ? [` - 出典: ${s.source}`] : []), ...(s.basis ? [` - 根拠:\n${quote(s.basis).replace(/^/gm, " ")}`] : []));
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
if (x.answers.length) {
|
|
611
|
+
lines.push("### 確認事項への回答(元の評価の確認事項との組。次の評価で継続・解消・矛盾を判断する)");
|
|
612
|
+
for (const a of x.answers) {
|
|
613
|
+
const st = ANSWER_STATE_LABEL[answerState(a, x.sources)];
|
|
614
|
+
lines.push(`- ${a.run}/${a.question}[${st}] 質問: ${a.copy.question}(確認先: ${a.copy.ask} / 対象: ${a.copy.target})`, ` - 回答${a.by || a.on ? `(${[a.by, a.on].filter(Boolean).join("・")})` : ""}:\n${quote(a.answer).replace(/^/gm, " ")}`, ...(a.source ? [` - 出典: ${a.source}`] : []), ...(a.basis ? [` - 根拠:\n${quote(a.basis).replace(/^/gm, " ")}`] : []), ...(a.links?.length ? [` - 対応する根拠の記録: ${a.links.map((l) => l.id).join(", ")}`] : []));
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
return lines.join("\n");
|
|
618
|
+
}
|
|
619
|
+
export function requestRequirementView(r, runs) {
|
|
620
|
+
const subject = requestSubject(r);
|
|
621
|
+
const sources = (r.requirementSources ?? []).map((s) => ({ ...s, state: sourceState(s, subject) }));
|
|
622
|
+
const answers = (r.clarifyAnswers ?? []).map((a) => ({ ...a, state: answerState(a, r.requirementSources ?? [], runs) }));
|
|
623
|
+
return { state: overallState(sources.map((s) => s.state)), sources, answers, problems: r.requirementProblems ?? [] };
|
|
624
|
+
}
|
|
625
|
+
export function criteriaSourceView(criteria, sources, requestSourceIds) {
|
|
626
|
+
const list = sources ?? [];
|
|
627
|
+
const items = (criteria ?? []).map((c) => {
|
|
628
|
+
const subject = criterionSubject(c.text);
|
|
629
|
+
const mine = list.filter((s) => s.criterionId === c.id).map((s) => ({ ...s, state: sourceState(s, subject, requestSourceIds) }));
|
|
630
|
+
return { id: c.id, text: c.text, state: overallState(mine.map((s) => s.state)), sources: mine };
|
|
631
|
+
});
|
|
632
|
+
const ids = new Set((criteria ?? []).map((c) => c.id));
|
|
633
|
+
const orphans = list.filter((s) => !ids.has(s.criterionId)).map((s) => ({ ...s, state: "unlinked" }));
|
|
634
|
+
return { items, orphans };
|
|
635
|
+
}
|