@infodb/p3 0.12.0 → 0.14.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 -35
- package/bin/p3.mjs +3 -2
- package/dist/web/assets/CompletionReview-BD7d6Yzt.js +1 -0
- package/dist/web/assets/ImprovementDialog-BoAZN1KR.js +1 -0
- package/dist/web/assets/Outputs-D-ZouoxF.js +1 -0
- package/dist/web/assets/RequestStatus-Bl3fdSbM.js +1 -0
- package/dist/web/assets/Tabs-CxeceOL-.js +1 -0
- package/dist/web/assets/TagInput-CeAbmGRR.js +1 -0
- package/dist/web/assets/TaskDrawer-BCriSnhe.js +6 -0
- package/dist/web/assets/_requestId-CZKMe_mC.js +1 -0
- package/dist/web/assets/_requestId-Fx4lLkFo.js +1 -0
- package/dist/web/assets/appCtx-BdxbkSZa.js +1 -0
- package/dist/web/assets/archive-D5IIxcSV.js +1 -0
- package/dist/web/assets/board-p6R9KMqd.js +1 -0
- package/dist/web/assets/done-BTOF188x.js +1 -0
- package/dist/web/assets/draft-BWYpm3PD.js +2 -0
- package/dist/web/assets/index-DFbY8NAR.css +2 -0
- package/dist/web/assets/index-Dpqi2dcC.js +12 -0
- package/dist/web/assets/link-D481whDt.js +1 -0
- package/dist/web/assets/metrics-CAzP6V8I.js +1 -0
- package/dist/web/assets/new-C65IJJg3.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-_dAYMct_.js +1 -0
- package/dist/web/assets/{quality-Pu6EISAM.js → quality-RFd-7k3r.js} +1 -1
- package/dist/web/assets/release-notes-Dtif8xsQ.js +5 -0
- package/dist/web/assets/requestData-SPc36t8Q.js +1 -0
- package/dist/web/assets/routes-DJj8CWuk.js +6 -0
- package/dist/web/assets/settings-DKJd7CLe.js +1 -0
- package/dist/web/assets/ui-CbEOnPnF.js +1 -0
- package/dist/web/assets/workTarget-DavxMs-c.js +30 -0
- package/dist/web/index.html +6 -4
- package/docs/architecture.md +430 -72
- package/docs/chatgpt-sign-in.md +2 -2
- package/docs/development.md +141 -64
- package/docs/feature-inventory.md +139 -0
- package/docs/how-to-use.md +389 -31
- package/docs/installation.md +261 -147
- package/docs/publishing.md +33 -14
- package/docs/refactoring.md +332 -0
- package/lib/cli/agentsStatus.js +198 -0
- package/lib/cli/guide.js +27 -0
- package/lib/cli/guide.md +217 -0
- package/lib/cli/help.js +45 -7
- package/lib/cli/main.js +58 -207
- package/lib/cli/project.js +34 -294
- package/lib/core/projectRegistry.js +2 -2
- package/lib/kit/appInfo.js +13 -0
- package/lib/kit/usage.js +27 -0
- package/lib/server/api/projectsRoutes.js +5 -5
- package/lib/server/server.js +7 -4
- package/lib/{cli → tasks/cli}/args.js +73 -9
- package/lib/{cli → tasks/cli}/chatgpt.js +1 -1
- package/lib/{cli → tasks/cli}/codex.js +1 -1
- package/lib/{cli → tasks/cli}/output.js +12 -2
- package/lib/{cli → tasks/cli}/preflightCommands.js +1 -1
- package/lib/tasks/cli/readOnly.js +75 -0
- package/lib/{cli → tasks/cli}/render.js +1 -1
- package/lib/{cli → tasks/cli}/requestCommands.js +24 -7
- package/lib/tasks/cli/showView.js +279 -0
- package/lib/{cli → tasks/cli}/taskCommands.js +55 -21
- package/lib/tasks/cli/tasksCli.js +149 -0
- package/lib/{core → tasks/core}/context.js +6 -9
- package/lib/tasks/core/errorOutcome.js +125 -0
- package/lib/{core → tasks/core}/hierarchy.js +1 -1
- package/lib/{core → tasks/core}/ops.js +17 -2
- package/lib/{core → tasks/core}/preflight/carryover.js +5 -1
- package/lib/{core → tasks/core}/preflight/codexEngine.js +36 -28
- package/lib/{core → tasks/core}/preflight/diagnose.js +4 -9
- package/lib/{core → tasks/core}/preflight/engine.js +9 -0
- package/lib/tasks/core/preflight/hostPaths.js +299 -0
- package/lib/{core → tasks/core}/preflight/input.js +33 -5
- package/lib/{core → tasks/core}/preflight/instructions.js +19 -2
- package/lib/{core → tasks/core}/preflight/mockEngine.js +27 -8
- package/lib/{core → tasks/core}/preflight/render.js +22 -3
- package/lib/{core → tasks/core}/preflight/service.js +86 -11
- package/lib/{core → tasks/core}/preflight/uiRender.js +5 -2
- package/lib/{core → tasks/core}/requestOps.js +214 -17
- package/lib/{core → tasks/core}/reviewRuns.js +127 -22
- package/lib/{core → tasks/core}/store/attachments.js +3 -2
- package/lib/{core → tasks/core}/store/collection.js +21 -2
- package/lib/tasks/core/store/fieldGroups.js +30 -0
- package/lib/tasks/core/store/jsonRecord.js +30 -0
- package/lib/{core → tasks/core}/store/normalize.js +15 -10
- package/lib/{core → tasks/core}/store/noteStore.js +2 -2
- package/lib/{core → tasks/core}/store/preflightStore.js +59 -22
- package/lib/{core → tasks/core}/store/projectFile.js +1 -1
- package/lib/{core → tasks/core}/store/workspace.js +28 -6
- package/lib/{core → tasks/core}/userConfig.js +1 -1
- package/lib/{core → tasks/core}/workTargets.js +1 -1
- package/lib/tasks/features/metrics/cli/metricsCommands.js +77 -0
- package/lib/tasks/features/metrics/core/definitions.js +445 -0
- package/lib/tasks/features/metrics/core/index.js +112 -0
- package/lib/tasks/features/metrics/core/manual.js +179 -0
- package/lib/tasks/features/metrics/server/metricsRoutes.js +8 -0
- package/lib/tasks/features/metrics/shared/metrics.js +42 -0
- package/lib/{core/milestoneReview → tasks/features/milestoneReview/core}/code.js +2 -11
- package/lib/{core/milestoneReview → tasks/features/milestoneReview/core}/material.js +5 -6
- package/lib/{core/milestoneReview → tasks/features/milestoneReview/core}/review.js +2 -2
- package/lib/{core/milestoneReview → tasks/features/milestoneReview/core}/service.js +38 -100
- package/lib/{core/milestoneReview → tasks/features/milestoneReview/core}/store.js +3 -3
- package/lib/{server/api → tasks/features/milestoneReview/server}/milestoneReviewRoutes.js +7 -13
- package/lib/{cli → tasks/features/quality/cli}/qualityCommands.js +36 -11
- package/lib/{core → tasks/features/quality/core}/qualityImprovement.js +16 -15
- package/lib/tasks/features/records/cli/revisitCommands.js +73 -0
- package/lib/tasks/features/records/core/completionRefs.js +46 -0
- package/lib/tasks/features/records/core/reviewCandidates.js +76 -0
- package/lib/tasks/features/records/shared/completionRecord.js +329 -0
- package/lib/tasks/features/records/shared/reviewCandidate.js +313 -0
- package/lib/tasks/features/records/shared/reworkHistory.js +86 -0
- package/lib/{cli → tasks/features/releaseNotes/cli}/releaseNotesCommands.js +7 -7
- package/lib/{core/releaseNotes → tasks/features/releaseNotes/core}/completeRequests.js +5 -6
- package/lib/{core/releaseNotes → tasks/features/releaseNotes/core}/generate.js +3 -14
- package/lib/{core/releaseNotes → tasks/features/releaseNotes/core}/material.js +3 -4
- package/lib/{core/releaseNotes → tasks/features/releaseNotes/core}/service.js +1 -1
- package/lib/{core/releaseNotes → tasks/features/releaseNotes/core}/store.js +2 -2
- package/lib/{server/api → tasks/features/releaseNotes/server}/releaseNoteRoutes.js +11 -20
- package/lib/tasks/features/requirements/cli/requirementCommands.js +289 -0
- package/lib/{shared → tasks/features/requirements/shared}/acceptance.js +292 -18
- package/lib/tasks/features/requirements/shared/requirementSource.js +635 -0
- package/lib/tasks/features/retro/cli/retroCommands.js +106 -0
- package/lib/tasks/features/retro/core/retrospective.js +197 -0
- package/lib/tasks/features/retro/shared/retrospective.js +286 -0
- package/lib/tasks/features/settings/cli/projectSettings.js +245 -0
- package/lib/{cli → tasks/features/settings/cli}/userConfig.js +50 -3
- package/lib/{core → tasks/features/settings/core}/machineSettingsEdit.js +2 -2
- package/lib/{core → tasks/features/settings/core}/repoAdmin.js +3 -3
- package/lib/{core → tasks/features/settings/core}/userTheme.js +2 -2
- package/lib/{server/api → tasks/features/settings/server}/repoRoutes.js +2 -2
- package/lib/{server/api → tasks/features/settings/server}/userThemeRoutes.js +3 -3
- package/lib/{cli → tasks/features/taskReview/cli}/taskReviewCommands.js +5 -5
- package/lib/{core/taskReview → tasks/features/taskReview/core}/material.js +13 -7
- package/lib/{core/taskReview → tasks/features/taskReview/core}/review.js +10 -3
- package/lib/{core/taskReview → tasks/features/taskReview/core}/service.js +24 -85
- package/lib/{core/taskReview → tasks/features/taskReview/core}/store.js +4 -4
- package/lib/{server/api → tasks/features/taskReview/server}/taskReviewRoutes.js +7 -14
- package/lib/{server → tasks/server}/api/manifest.js +51 -3
- package/lib/{server → tasks/server}/api/routes.js +134 -65
- package/lib/tasks/shared/commitRefs.js +10 -0
- package/lib/{shared → tasks/shared}/preflightInput.js +1 -1
- package/package.json +1 -43
- package/skills/p3/SKILL.md +9 -181
- package/dist/web/assets/ImprovementDialog-kQaVBGWH.js +0 -1
- package/dist/web/assets/Outputs-_nU_p3nu.js +0 -1
- package/dist/web/assets/RequestStatus-RG-OVQYY.js +0 -1
- package/dist/web/assets/Tabs-ew9i5SKX.js +0 -1
- package/dist/web/assets/TagInput-BtlJTF7i.js +0 -1
- package/dist/web/assets/TaskDrawer-DW8GyJqI.js +0 -6
- package/dist/web/assets/_requestId-6Nb727dD.js +0 -1
- package/dist/web/assets/_requestId-BykTgPax.js +0 -1
- package/dist/web/assets/appCtx-CxDdXABS.js +0 -1
- package/dist/web/assets/archive-Ckh295Xe.js +0 -1
- package/dist/web/assets/board-BVAIjK-Y.js +0 -1
- package/dist/web/assets/done-BGfA-3MA.js +0 -1
- package/dist/web/assets/draft-CfJeyLOl.js +0 -1
- package/dist/web/assets/index-CgRU744I.css +0 -2
- package/dist/web/assets/index-DacQ0yl4.js +0 -12
- package/dist/web/assets/new-DVygWvVc.js +0 -1
- package/dist/web/assets/outputs-B6xDsLZf.js +0 -1
- package/dist/web/assets/preflightInput-BAeEJYUK.js +0 -2
- package/dist/web/assets/preload-helper-DyCqp21K.js +0 -1
- package/dist/web/assets/release-notes-CCpzyiNf.js +0 -5
- package/dist/web/assets/requestData-D5vBnuMh.js +0 -1
- package/dist/web/assets/routes-Q91zvNc0.js +0 -4
- package/dist/web/assets/settings-BzRgcmUm.js +0 -1
- package/dist/web/assets/workTarget-C9c57JAO.js +0 -30
- package/lib/cli/readOnly.js +0 -38
- package/lib/cli/showView.js +0 -166
- /package/lib/{core/store → kit}/frontmatter.js +0 -0
- /package/lib/{core/store → kit}/fsutil.js +0 -0
- /package/lib/{cli → tasks/cli}/format.js +0 -0
- /package/lib/{core → tasks/core}/chatgpt.js +0 -0
- /package/lib/{core → tasks/core}/machineSettings.js +0 -0
- /package/lib/{core → tasks/core}/preflight/codexImage.js +0 -0
- /package/lib/{core → tasks/core}/preflight/docker.js +0 -0
- /package/lib/{core → tasks/core}/preflight/launch.js +0 -0
- /package/lib/{core → tasks/core}/preflight/launcher.mjs +0 -0
- /package/lib/{core → tasks/core}/preflight/mock-ui.html +0 -0
- /package/lib/{core → tasks/core}/preflight/mock-ui.png +0 -0
- /package/lib/{core → tasks/core}/preflight/owner.js +0 -0
- /package/lib/{core → tasks/core}/preflight/render-image/Dockerfile +0 -0
- /package/lib/{core → tasks/core}/preflight/render-image/fonts-ja.conf +0 -0
- /package/lib/{core → tasks/core}/preflight/render-image/render.mjs +0 -0
- /package/lib/{core → tasks/core}/preflight/split.js +0 -0
- /package/lib/{core → tasks/core}/preflight/uiMaterials.js +0 -0
- /package/lib/{core → tasks/core}/preflight/wireframe.js +0 -0
- /package/lib/{core → tasks/core}/preflight/xlsx.js +0 -0
- /package/lib/{core → tasks/core}/redact.js +0 -0
- /package/lib/{core → tasks/core}/repoRefs.js +0 -0
- /package/lib/{core → tasks/core}/requestStatus.js +0 -0
- /package/lib/{core → tasks/core}/store/archivedTasks.js +0 -0
- /package/lib/{core → tasks/core}/store/dataWatcher.js +0 -0
- /package/lib/{core → tasks/core}/store/locate.js +0 -0
- /package/lib/{core → tasks/core}/supersede.js +0 -0
- /package/lib/{core/milestoneReview → tasks/features/milestoneReview/core}/mockReviewer.js +0 -0
- /package/lib/{shared → tasks/features/milestoneReview/shared}/milestoneReview.js +0 -0
- /package/lib/{core → tasks/features/quality/core}/quality.js +0 -0
- /package/lib/{shared → tasks/features/quality/shared}/quality.js +0 -0
- /package/lib/{shared → tasks/features/quality/shared}/qualityImprovement.js +0 -0
- /package/lib/{shared → tasks/features/quality/shared}/qualityTemplates.js +0 -0
- /package/lib/{core/releaseNotes → tasks/features/releaseNotes/core}/mockSummarizer.js +0 -0
- /package/lib/{core/taskReview → tasks/features/taskReview/core}/mockReviewer.js +0 -0
- /package/lib/{core/taskReview → tasks/features/taskReview/core}/paths.js +0 -0
- /package/lib/{shared → tasks/features/taskReview/shared}/taskReview.js +0 -0
- /package/lib/{server → tasks/server}/api/chatgptRoutes.js +0 -0
- /package/lib/{server → tasks/server}/api/local.js +0 -0
- /package/lib/{shared → tasks/shared}/dates.js +0 -0
- /package/lib/{shared → tasks/shared}/directTask.js +0 -0
- /package/lib/{shared → tasks/shared}/hierarchy.js +0 -0
- /package/lib/{shared → tasks/shared}/milestoneGoals.js +0 -0
- /package/lib/{shared → tasks/shared}/milestoneOrder.js +0 -0
- /package/lib/{shared → tasks/shared}/preflightRunner.js +0 -0
- /package/lib/{shared → tasks/shared}/refs.js +0 -0
- /package/lib/{shared → tasks/shared}/repos.js +0 -0
- /package/lib/{shared → tasks/shared}/scopeView.js +0 -0
- /package/lib/{shared → tasks/shared}/tags.js +0 -0
- /package/lib/{shared → tasks/shared}/taskBlock.js +0 -0
- /package/lib/{shared → tasks/shared}/types.js +0 -0
- /package/lib/{shared → tasks/shared}/workTarget.js +0 -0
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { ADOPTION_KIND_LABEL, EVIDENCE_CHECK_LABEL, isRiskState, RETRO_EVIDENCE_LABEL, RISK_STATE_LABEL, RISK_STATES, } from "../shared/retrospective.js";
|
|
3
|
+
import { confirmRetrospectiveTarget, judgeRisk, retrospectiveView } from "../core/retrospective.js";
|
|
4
|
+
import { UsageError } from "../../../../kit/usage.js";
|
|
5
|
+
/**
|
|
6
|
+
* 要望の振り返り(Preflight で心配したリスクが実装の後に起きたか)のコマンド(規則は shared/retrospective.ts)。
|
|
7
|
+
*
|
|
8
|
+
* retro [<要望>] 振り返りの対象(確定した run・リスク)と候補(採用済みの run と根拠)
|
|
9
|
+
* retro [<要望>] confirm <run> [--reason 理由] 対象を確定する(2回目からは訂正で理由が要る。--rev で版を照らす)
|
|
10
|
+
* retro [<要望>] judge <リスクの番号> --state occurred|not_occurred|unchecked [--facts 事実] [--scope 範囲] [--reason 理由]
|
|
11
|
+
* --evidence review:T001:<run>:<項目>[:<位置>] | milestone:<ID>:<run>:<項目>[:<位置>][:<結び付く理由>] | rework:T001:R1 | manual:<参照>
|
|
12
|
+
* (繰り返し可)/ --evidence-json 根拠.json|- リスクの確認を記録する(人の判断。根拠だけなら unchecked のまま結び付ける)
|
|
13
|
+
*/
|
|
14
|
+
/** 根拠の指定の文字列を読む */
|
|
15
|
+
export function parseEvidenceSpec(spec) {
|
|
16
|
+
const [kind, ...rest] = spec.split(":");
|
|
17
|
+
const num = (v) => (v === undefined || v === "" ? undefined : Number.isInteger(Number(v)) ? Number(v) : NaN);
|
|
18
|
+
if (kind === "manual" && rest.join(":").trim())
|
|
19
|
+
return { kind: "manual", reference: rest.join(":").trim() };
|
|
20
|
+
if (kind === "rework" && rest.length === 2)
|
|
21
|
+
return { kind: "rework", task: rest[0], history: rest[1] };
|
|
22
|
+
if (kind === "review" && rest.length >= 3 && !Number.isNaN(num(rest[3])))
|
|
23
|
+
return { kind: "task_review", task: rest[0], run: rest[1], section: rest[2], index: num(rest[3]) };
|
|
24
|
+
if (kind === "milestone" && rest.length >= 3 && !Number.isNaN(num(rest[3])))
|
|
25
|
+
return { kind: "milestone_review", milestone: rest[0], run: rest[1], section: rest[2], index: num(rest[3]), ...(rest.length > 4 ? { reason: rest.slice(4).join(":") } : {}) };
|
|
26
|
+
throw new UsageError(`根拠の指定が読めません: ${spec}(review:T001:<run>:<項目>[:<位置>] / milestone:<ID>:<run>:<項目>[:<位置>][:<理由>] / rework:T001:R1 / manual:<参照>)`);
|
|
27
|
+
}
|
|
28
|
+
const evidenceLine = (e, check) => {
|
|
29
|
+
const where = e.kind === "task_review" ? `${e.request}/${e.task} ${e.run} ${e.section}[${e.index}]` : e.kind === "milestone_review" ? `${e.milestone} ${e.run} ${e.section}[${e.index}]${e.inputChanged ? "(実行中に材料が変わった)" : ""}` : e.kind === "rework" ? `${e.request}/${e.task} ${e.history}` : e.reference;
|
|
30
|
+
const text = e.kind === "manual" ? (e.note ?? "") : e.excerpt;
|
|
31
|
+
return `${RETRO_EVIDENCE_LABEL[e.kind]} ${where}${check ? ` [${EVIDENCE_CHECK_LABEL[check]}]` : ""}${text ? `\n 当時の抜粋: ${text}` : ""}${e.kind === "milestone_review" && e.reason ? `\n 結び付く理由: ${e.reason}` : ""}`;
|
|
32
|
+
};
|
|
33
|
+
const judgmentLines = (j, checks) => [
|
|
34
|
+
` ${j.id} ${RISK_STATE_LABEL[j.state]} ${j.at} ${j.by ?? ""}${j.reason ? ` 理由: ${j.reason}` : ""}`,
|
|
35
|
+
...(j.facts ? [` 事実: ${j.facts}`] : []),
|
|
36
|
+
...(j.scope ? [` 範囲: ${j.scope}`] : []),
|
|
37
|
+
...j.evidence.map((e, i) => ` 根拠: ${evidenceLine(e, checks?.[i])}`),
|
|
38
|
+
];
|
|
39
|
+
const basisLine = (b) => `${b.key ? `${b.key}→` : ""}${b.target}${b.state === "present" ? "" : `(${{ archived: "アーカイブ済み", missing: "見つからない", mismatch: "採用元が合わない" }[b.state]})`}`;
|
|
40
|
+
export function formatTarget(t) {
|
|
41
|
+
return [
|
|
42
|
+
`${t.id} ${t.run} ${ADOPTION_KIND_LABEL[t.kind]} ${t.at} ${t.by ?? ""}${t.replaces ? ` (${t.replaces} を訂正: ${t.reason ?? ""})` : ""}`,
|
|
43
|
+
` 評価の版 ${t.assessmentVersion} 根拠: ${t.basis.map(basisLine).join(", ")}`,
|
|
44
|
+
...(t.risks.length ? t.risks.map((r) => ` リスク ${r.index + 1}: ${r.text}`) : [" リスクなし"]),
|
|
45
|
+
];
|
|
46
|
+
}
|
|
47
|
+
export function formatRetro(v) {
|
|
48
|
+
const lines = [v.target ? "振り返りの対象:" : "振り返りの対象: 未確定(p3 retro confirm <run> で確定する)"];
|
|
49
|
+
if (v.target) {
|
|
50
|
+
lines.push(` ${formatTarget(v.target)[0]}`, ` 評価の版 ${v.target.assessmentVersion}`);
|
|
51
|
+
lines.push("", `リスクの確認(人の判断。起きた ${v.counts.occurred}・起きなかった ${v.counts.not_occurred}・未確認 ${v.counts.unchecked}):`);
|
|
52
|
+
if (!v.risks.length)
|
|
53
|
+
lines.push(" リスクなし(評価にリスクがありませんでした)");
|
|
54
|
+
for (const r of v.risks) {
|
|
55
|
+
lines.push(` ${r.index + 1}. [${RISK_STATE_LABEL[r.state]}] ${r.text}`);
|
|
56
|
+
for (const j of r.history)
|
|
57
|
+
lines.push(...judgmentLines(j, v.checks[j.id]));
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
if (v.targets.length > 1)
|
|
61
|
+
lines.push("", "前の対象(訂正の履歴):", ...v.targets.slice(0, -1).flatMap((t) => formatTarget(t).slice(0, 1).map((l) => ` ${l}`)));
|
|
62
|
+
lines.push("", "候補(採用を終えた Preflight。新しい順):");
|
|
63
|
+
if (!v.candidates.length)
|
|
64
|
+
lines.push(` なし: ${v.none ?? ""}`);
|
|
65
|
+
for (const c of v.candidates)
|
|
66
|
+
lines.push(` ${c.run} ${ADOPTION_KIND_LABEL[c.kind]}${c.latest ? " 最新" : ""}${v.target?.run === c.run ? " ← 対象" : ""} リスク ${c.risks} 根拠: ${c.basis.map(basisLine).join(", ")}`);
|
|
67
|
+
return lines.join("\n");
|
|
68
|
+
}
|
|
69
|
+
export async function retroCommand(cmd, env) {
|
|
70
|
+
if (cmd !== "retro" && cmd !== "retrospective")
|
|
71
|
+
return undefined;
|
|
72
|
+
const { ctx, out, args, o, actor, expectedRev, requestArg } = env;
|
|
73
|
+
const subs = new Set(["show", "confirm", "judge"]);
|
|
74
|
+
const explicit = args[0] && !subs.has(args[0]) ? args[0] : undefined;
|
|
75
|
+
const rid = requestArg(explicit);
|
|
76
|
+
const rest = explicit ? args.slice(1) : args;
|
|
77
|
+
const sub = rest[0] ?? "show";
|
|
78
|
+
if (sub === "show") {
|
|
79
|
+
const v = await retrospectiveView(ctx, rid);
|
|
80
|
+
return out.result(v, () => formatRetro(v));
|
|
81
|
+
}
|
|
82
|
+
if (sub === "confirm") {
|
|
83
|
+
const run = rest[1];
|
|
84
|
+
if (!run)
|
|
85
|
+
throw new UsageError("p3 retro [<要望>] confirm <run> [--reason 理由](run は p3 retro の候補から)");
|
|
86
|
+
const v = await confirmRetrospectiveTarget(ctx, rid, { run, reason: o.reason }, { expectedVersion: expectedRev, actor });
|
|
87
|
+
return out.result(v, () => `確定しました(版 ${v.version})\n${formatRetro(v)}`);
|
|
88
|
+
}
|
|
89
|
+
if (sub === "judge") {
|
|
90
|
+
const no = Number(rest[1]);
|
|
91
|
+
if (!Number.isInteger(no) || no < 1)
|
|
92
|
+
throw new UsageError("p3 retro [<要望>] judge <リスクの番号(1 から)> --state occurred|not_occurred|unchecked ...");
|
|
93
|
+
if (!isRiskState(o.state))
|
|
94
|
+
throw new UsageError(`--state は ${RISK_STATES.join(" / ")} です`);
|
|
95
|
+
const evidence = (o.evidence ?? []).map(parseEvidenceSpec);
|
|
96
|
+
if (o["evidence-json"]) {
|
|
97
|
+
const raw = JSON.parse(readFileSync(o["evidence-json"] === "-" ? 0 : o["evidence-json"], "utf8"));
|
|
98
|
+
if (!Array.isArray(raw))
|
|
99
|
+
throw new UsageError("--evidence-json は根拠の並び([{kind: task_review|milestone_review|rework|manual, ...}])にしてください");
|
|
100
|
+
evidence.push(...raw);
|
|
101
|
+
}
|
|
102
|
+
const v = await judgeRisk(ctx, rid, { risk: no - 1, state: o.state, facts: o.facts, scope: o.scope, reason: o.reason, evidence }, { expectedVersion: expectedRev, actor });
|
|
103
|
+
return out.result(v, () => `記録しました(版 ${v.version})\n${formatRetro(v)}`);
|
|
104
|
+
}
|
|
105
|
+
throw new UsageError("p3 retro [<要望>] [show | confirm <run> | judge <番号>]");
|
|
106
|
+
}
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { join } from "node:path";
|
|
2
|
+
import { reworkLine } from "../../records/shared/reworkHistory.js";
|
|
3
|
+
/** タスク(今かアーカイブ)の手戻りの履歴の 1 件(根拠を保存するときと、保存した根拠を照らすときで同じ引き方) */
|
|
4
|
+
const reworkEntry = (t, id) => t?.reworkHistory?.find((e) => e.id === id);
|
|
5
|
+
import { addJudgment, assessmentVersion, JUDGMENT_LIMITS, latestJudgment, MILESTONE_REVIEW_SECTIONS, riskCounts, TASK_REVIEW_SECTIONS, confirmTarget, currentTarget, readRetrospective, retroCandidates, RetrospectiveError, } from "../shared/retrospective.js";
|
|
6
|
+
import { getArchivedTask, listArchivedTasks } from "../../../core/store/archivedTasks.js";
|
|
7
|
+
import { NotFoundError } from "../../../core/store/collection.js";
|
|
8
|
+
import { withFileLock } from "../../../../kit/fsutil.js";
|
|
9
|
+
import { readJsonRecord, writeJsonRecord } from "../../../core/store/jsonRecord.js";
|
|
10
|
+
/**
|
|
11
|
+
* 要望の振り返りの保存と読み取り(規則は shared/retrospective.ts)。記録は requests/<要望ID>/retrospective.json で、要望のロック
|
|
12
|
+
* (requestLock。要望・タスクの保存と同じ)の中で、読み直してから版を照らして書く。読み取りはファイルを書かない
|
|
13
|
+
*/
|
|
14
|
+
export const RETRO_FILE = "retrospective.json";
|
|
15
|
+
const pathOf = (ctx, rid) => join(ctx.ws.requestsDir, rid, RETRO_FILE);
|
|
16
|
+
/** 記録を読む(無ければ空。JSON として読めなければ retro_unreadable、ほかの読めない理由はそのまま投げる) */
|
|
17
|
+
export function loadRetrospective(ctx, rid) {
|
|
18
|
+
return readJsonRecord(pathOf(ctx, rid), {
|
|
19
|
+
missing: () => ({ version: 0, targets: [] }),
|
|
20
|
+
invalidJson: (m) => {
|
|
21
|
+
throw new RetrospectiveError("retro_unreadable", `retrospective.json が JSON として読めません: ${m}(ファイルを直してください)`);
|
|
22
|
+
},
|
|
23
|
+
shape: readRetrospective,
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* 記録を変える(確定・訂正・リスクの確認で共通)。要望のロックの中で、要望があること(アーカイブで移した後のフォルダに書き戻さない)を確かめ、
|
|
28
|
+
* 読み直して版を照らし(違えば retro_conflict)、change が返した記録を置き換えで書く。書いた後に変更を知らせ、今の表示を返す
|
|
29
|
+
*/
|
|
30
|
+
async function changeRetrospective(ctx, rid, expectedVersion, change) {
|
|
31
|
+
ctx.ws.requests.require(rid);
|
|
32
|
+
await withFileLock(ctx.ws.requestLock(rid), async () => {
|
|
33
|
+
if ("missing" in (await ctx.ws.requests.peek(rid)))
|
|
34
|
+
throw new NotFoundError(rid);
|
|
35
|
+
const file = await loadRetrospective(ctx, rid);
|
|
36
|
+
if (expectedVersion !== undefined && expectedVersion !== file.version) {
|
|
37
|
+
throw new RetrospectiveError("retro_conflict", `振り返りの記録が他で変わりました(版 ${expectedVersion} → ${file.version})。読み直してからやり直してください`);
|
|
38
|
+
}
|
|
39
|
+
await writeJsonRecord(pathOf(ctx, rid), await change(file));
|
|
40
|
+
}, { busyMessage: "別のプロセスがこの要望を保存中です。少し待ってやり直してください" });
|
|
41
|
+
ctx.ws.emit({ type: "changed", kind: "request", request: rid });
|
|
42
|
+
return retrospectiveView(ctx, rid);
|
|
43
|
+
}
|
|
44
|
+
/** 候補(新しい順)。runs と照らすタスク・子の要望はディスクと読み込んだ値から */
|
|
45
|
+
export async function retrospectiveCandidates(ctx, rid) {
|
|
46
|
+
const request = ctx.ws.requests.require(rid);
|
|
47
|
+
const runs = await ctx.preflight.list(rid);
|
|
48
|
+
const archived = new Set((await listArchivedTasks(ctx.ws, rid)).tasks.map((t) => t.id));
|
|
49
|
+
const tasks = ctx.ws.tasksOf(rid);
|
|
50
|
+
const lookup = {
|
|
51
|
+
task: (tid) => (tasks.get(tid) ? "present" : archived.has(tid) ? "archived" : "missing"),
|
|
52
|
+
child: (id) => {
|
|
53
|
+
const c = ctx.ws.requests.get(id);
|
|
54
|
+
return c ? { splitFrom: c.splitFrom, parent: c.parent } : undefined;
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
return { ...retroCandidates(rid, request.status, runs, lookup), runs };
|
|
58
|
+
}
|
|
59
|
+
export async function retrospectiveView(ctx, rid) {
|
|
60
|
+
const file = await loadRetrospective(ctx, rid);
|
|
61
|
+
const { candidates, none } = await retrospectiveCandidates(ctx, rid);
|
|
62
|
+
const target = currentTarget(file);
|
|
63
|
+
const judgments = file.judgments ?? [];
|
|
64
|
+
const risks = (target?.risks ?? []).map((r) => {
|
|
65
|
+
const j = latestJudgment(file, target.id, r.index);
|
|
66
|
+
return { index: r.index, text: r.text, state: j?.state ?? "unchecked", ...(j ? { judgment: j } : {}), history: judgments.filter((x) => x.target === target.id && x.risk === r.index) };
|
|
67
|
+
});
|
|
68
|
+
const checks = {};
|
|
69
|
+
for (const j of judgments)
|
|
70
|
+
checks[j.id] = await Promise.all(j.evidence.map((e) => checkEvidence(ctx, e)));
|
|
71
|
+
return { version: file.version, ...(target ? { target } : {}), targets: file.targets, candidates, ...(none ? { none } : {}), risks, counts: riskCounts(file), judgments, checks };
|
|
72
|
+
}
|
|
73
|
+
// --- リスクの確認の根拠 -----------------------------------------------------------
|
|
74
|
+
const bad = (m) => new RetrospectiveError("retro_invalid", m);
|
|
75
|
+
const clip = (s) => (s.length > JUDGMENT_LIMITS.excerpt ? `${s.slice(0, JUDGMENT_LIMITS.excerpt)}…` : s);
|
|
76
|
+
/** 結果の項目と位置から所見の文を取り出す(無ければ undefined) */
|
|
77
|
+
function findingOf(result, section, index) {
|
|
78
|
+
if (section === "overall")
|
|
79
|
+
return index === 0 && typeof result.overall === "string" ? result.overall : undefined;
|
|
80
|
+
const list = result[section];
|
|
81
|
+
if (!Array.isArray(list) || index < 0 || index >= list.length)
|
|
82
|
+
return undefined;
|
|
83
|
+
const x = list[index];
|
|
84
|
+
if (typeof x === "string")
|
|
85
|
+
return x;
|
|
86
|
+
const head = [x.item ?? x.unit ?? x.standard, x.verdict].filter((v) => typeof v === "string").join(": ");
|
|
87
|
+
return [head, typeof x.reason === "string" ? x.reason : typeof x.text === "string" ? x.text : ""].filter(Boolean).join(" ");
|
|
88
|
+
}
|
|
89
|
+
/** 所見がこの要望を根拠に挙げているか(マイルストーンレビューの所見の evidence に要望 ID かそのタスクの参照がある) */
|
|
90
|
+
function citesRequest(result, section, index, rid) {
|
|
91
|
+
const list = result[section];
|
|
92
|
+
const x = Array.isArray(list) ? list[index] : undefined;
|
|
93
|
+
const ev = x && Array.isArray(x.evidence) ? x.evidence : [];
|
|
94
|
+
return ev.some((e) => typeof e === "string" && (e === rid || e.startsWith(`${rid}/`)));
|
|
95
|
+
}
|
|
96
|
+
/** タスクを今の・アーカイブから引く(無ければ undefined) */
|
|
97
|
+
async function taskOf(ctx, rid, tid) {
|
|
98
|
+
return ctx.ws.tasksOf(rid).get(tid) ?? (await getArchivedTask(ctx.ws, rid, tid).catch(() => undefined));
|
|
99
|
+
}
|
|
100
|
+
/** 根拠の指定を今の記録と照らして、保存する根拠にする(範囲外・見つからない・所見が無いなどは retro_invalid) */
|
|
101
|
+
export async function resolveEvidence(ctx, rid, ref) {
|
|
102
|
+
if (ref.kind === "manual") {
|
|
103
|
+
const reference = ref.reference?.trim();
|
|
104
|
+
if (!reference)
|
|
105
|
+
throw bad("人が書く参照(reference)が空です");
|
|
106
|
+
return { kind: "manual", reference: clip(reference), ...(ref.note?.trim() ? { note: clip(ref.note.trim()) } : {}) };
|
|
107
|
+
}
|
|
108
|
+
if (ref.kind === "rework") {
|
|
109
|
+
const t = await taskOf(ctx, rid, ref.task);
|
|
110
|
+
if (!t)
|
|
111
|
+
throw bad(`${rid}/${ref.task} はこの要望のタスクにありません`);
|
|
112
|
+
const h = reworkEntry(t, ref.history);
|
|
113
|
+
if (!h)
|
|
114
|
+
throw bad(`${t.id} の手戻りの履歴に ${ref.history} はありません`);
|
|
115
|
+
return { kind: "rework", request: rid, task: t.id, history: h.id, excerpt: clip(reworkLine(h)) };
|
|
116
|
+
}
|
|
117
|
+
const index = ref.index ?? 0;
|
|
118
|
+
if (ref.kind === "task_review") {
|
|
119
|
+
if (!TASK_REVIEW_SECTIONS.includes(ref.section))
|
|
120
|
+
throw bad(`タスクレビューの所見の項目は ${TASK_REVIEW_SECTIONS.join(" / ")} です`);
|
|
121
|
+
if (!(await taskOf(ctx, rid, ref.task)))
|
|
122
|
+
throw bad(`${rid}/${ref.task} はこの要望のタスクにありません(ほかの要望のレビューは結び付けられません)`);
|
|
123
|
+
const rec = await ctx.ws.taskReviews.get(`${rid}/${ref.task}`, ref.run).catch(() => undefined);
|
|
124
|
+
if (!rec?.result)
|
|
125
|
+
throw bad(`${rid}/${ref.task} のレビュー ${ref.run} の結果がありません`);
|
|
126
|
+
const text = findingOf(rec.result, ref.section, index);
|
|
127
|
+
if (text === undefined)
|
|
128
|
+
throw bad(`レビュー ${ref.run} の ${ref.section}[${index}] に所見がありません`);
|
|
129
|
+
return { kind: "task_review", request: rid, task: ref.task, run: ref.run, section: ref.section, index, resultVersion: assessmentVersion(rec.result), excerpt: clip(text) };
|
|
130
|
+
}
|
|
131
|
+
if (!MILESTONE_REVIEW_SECTIONS.includes(ref.section))
|
|
132
|
+
throw bad(`マイルストーンレビューの所見の項目は ${MILESTONE_REVIEW_SECTIONS.join(" / ")} です`);
|
|
133
|
+
const rec = await ctx.ws.milestoneReviews.get(ref.milestone, ref.run).catch(() => undefined);
|
|
134
|
+
if (!rec?.result || !rec.input)
|
|
135
|
+
throw bad(`マイルストーン ${ref.milestone} のレビュー ${ref.run} の結果がありません`);
|
|
136
|
+
if (!rec.input.requests.some((r) => r.id === rid))
|
|
137
|
+
throw bad(`レビュー ${ref.run} の材料で、${rid} は直接の対象ではありません(範囲外の所見は結び付けられません)`);
|
|
138
|
+
const result = rec.result;
|
|
139
|
+
const text = findingOf(result, ref.section, index);
|
|
140
|
+
if (text === undefined)
|
|
141
|
+
throw bad(`レビュー ${ref.run} の ${ref.section}[${index}] に所見がありません`);
|
|
142
|
+
const reason = ref.reason?.trim();
|
|
143
|
+
if (!citesRequest(result, ref.section, index, rid) && !reason)
|
|
144
|
+
throw bad(`この所見は ${rid} を根拠に挙げていません。全体に関わる所見を結び付けるには、この要望と結び付く理由(reason)を書いてください`);
|
|
145
|
+
return {
|
|
146
|
+
kind: "milestone_review",
|
|
147
|
+
milestone: ref.milestone,
|
|
148
|
+
run: ref.run,
|
|
149
|
+
section: ref.section,
|
|
150
|
+
index,
|
|
151
|
+
resultVersion: assessmentVersion(rec.result),
|
|
152
|
+
excerpt: clip(text),
|
|
153
|
+
...(rec.run.inputChanged ? { inputChanged: true } : {}),
|
|
154
|
+
...(reason ? { reason: clip(reason) } : {}),
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
/** 保存した根拠を今の記録と照らす(ファイルは書かない) */
|
|
158
|
+
export async function checkEvidence(ctx, e) {
|
|
159
|
+
if (e.kind === "manual")
|
|
160
|
+
return "manual";
|
|
161
|
+
if (e.kind === "rework")
|
|
162
|
+
return reworkEntry(await taskOf(ctx, e.request, e.task), e.history) ? "ok" : "missing";
|
|
163
|
+
const rec = e.kind === "task_review" ? await ctx.ws.taskReviews.get(`${e.request}/${e.task}`, e.run).catch(() => undefined) : await ctx.ws.milestoneReviews.get(e.milestone, e.run).catch(() => undefined);
|
|
164
|
+
if (!rec?.result)
|
|
165
|
+
return "missing";
|
|
166
|
+
return assessmentVersion(rec.result) === e.resultVersion ? "ok" : "changed";
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* リスクの確認を記録する(追記。今の確定した対象のリスクだけ)。根拠は保存するときに照らして抜粋と版を写す。
|
|
170
|
+
* expectedVersion が違えば retro_conflict、規則に合わない・範囲外の根拠は retro_invalid(どちらも何も書かない)
|
|
171
|
+
*/
|
|
172
|
+
export async function judgeRisk(ctx, rid, input, opts = {}) {
|
|
173
|
+
return changeRetrospective(ctx, rid, opts.expectedVersion, async (file) => {
|
|
174
|
+
const evidence = [];
|
|
175
|
+
for (const ref of input.evidence)
|
|
176
|
+
evidence.push(await resolveEvidence(ctx, rid, ref));
|
|
177
|
+
return addJudgment(file, { ...input, evidence }, { now: new Date().toISOString(), actor: opts.actor });
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* 振り返りの対象を確定する(訂正は理由つきで追記)。expectedVersion が今の版と違えば retro_conflict、候補でない・評価が無いなどは
|
|
182
|
+
* retro_invalid(どちらも何も書かない)
|
|
183
|
+
*/
|
|
184
|
+
export async function confirmRetrospectiveTarget(ctx, rid, input, opts = {}) {
|
|
185
|
+
return changeRetrospective(ctx, rid, opts.expectedVersion, async (file) => {
|
|
186
|
+
const { candidates, none, runs } = await retrospectiveCandidates(ctx, rid);
|
|
187
|
+
const runOf = (id) => runs.find((r) => r.id === id);
|
|
188
|
+
return confirmTarget(file, input, {
|
|
189
|
+
candidates,
|
|
190
|
+
none,
|
|
191
|
+
risksOf: (id) => runOf(id)?.assessment?.risks,
|
|
192
|
+
assessmentOf: (id) => runOf(id)?.assessment,
|
|
193
|
+
now: new Date().toISOString(),
|
|
194
|
+
actor: opts.actor,
|
|
195
|
+
});
|
|
196
|
+
});
|
|
197
|
+
}
|
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
export const ADOPTION_KIND_LABEL = {
|
|
2
|
+
tasks: "タスク化",
|
|
3
|
+
split: "分割の採用",
|
|
4
|
+
legacy: "タスク化(旧記録)",
|
|
5
|
+
};
|
|
6
|
+
// --- リスクの確認 ---------------------------------------------------------------
|
|
7
|
+
/** 確認の状態。occurred: 起きた / not_occurred: 起きなかった / unchecked: 確かめていない */
|
|
8
|
+
export const RISK_STATES = ["occurred", "not_occurred", "unchecked"];
|
|
9
|
+
export const isRiskState = (v) => typeof v === "string" && RISK_STATES.includes(v);
|
|
10
|
+
export const RISK_STATE_LABEL = { occurred: "起きた", not_occurred: "起きなかった", unchecked: "未確認" };
|
|
11
|
+
/** タスクレビューの所見の場所(結果の項目と位置) */
|
|
12
|
+
export const TASK_REVIEW_SECTIONS = ["overall", "items", "quality", "unplanned", "checks"];
|
|
13
|
+
/** マイルストーンレビューの所見の場所 */
|
|
14
|
+
export const MILESTONE_REVIEW_SECTIONS = ["overall", "units", "quality", "unplanned"];
|
|
15
|
+
export const RETRO_EVIDENCE_LABEL = {
|
|
16
|
+
task_review: "タスクの AI レビュー",
|
|
17
|
+
milestone_review: "マイルストーンレビュー",
|
|
18
|
+
rework: "手戻り",
|
|
19
|
+
manual: "人が書いた参照",
|
|
20
|
+
};
|
|
21
|
+
export const EVIDENCE_CHECK_LABEL = { ok: "照合済み", changed: "記録が差し替わった", missing: "今は見つからない", manual: "人の参照(照合しない)" };
|
|
22
|
+
export const JUDGMENT_LIMITS = { text: 4000, evidence: 30, excerpt: 1000 };
|
|
23
|
+
/** 対象とリスクの今の確認(無ければ undefined = 未確認) */
|
|
24
|
+
export const latestJudgment = (f, target, risk) => [...(f.judgments ?? [])].reverse().find((j) => j.target === target && j.risk === risk);
|
|
25
|
+
/** 今の対象の三状態の件数(確認の無いリスクは未確認) */
|
|
26
|
+
export function riskCounts(f) {
|
|
27
|
+
const counts = { occurred: 0, not_occurred: 0, unchecked: 0 };
|
|
28
|
+
const t = currentTarget(f);
|
|
29
|
+
for (const r of t?.risks ?? [])
|
|
30
|
+
counts[latestJudgment(f, t.id, r.index)?.state ?? "unchecked"]++;
|
|
31
|
+
return counts;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* リスクの確認を足す(足した値を返す)。対象は今の確定した対象だけ。起きた → 確認した事実と根拠、起きなかった → 確認した範囲と根拠が要る。
|
|
35
|
+
* 根拠を結び付けるだけなら未確認のまま。決めた確認を変える・未確認に戻すには理由が要る。規則に合わなければ RetrospectiveError(何も当てない)
|
|
36
|
+
*/
|
|
37
|
+
export function addJudgment(file, input, ctx) {
|
|
38
|
+
const t = currentTarget(file);
|
|
39
|
+
if (!t)
|
|
40
|
+
throw new RetrospectiveError("retro_invalid", "振り返りの対象が確定していません(先に p3 retro confirm <run>)");
|
|
41
|
+
const risk = t.risks.find((r) => r.index === input.risk);
|
|
42
|
+
if (!risk)
|
|
43
|
+
throw new RetrospectiveError("retro_invalid", `対象 ${t.id}(${t.run})にリスク ${input.risk + 1} はありません(リスクは ${t.risks.length} 件)`);
|
|
44
|
+
if (!isRiskState(input.state))
|
|
45
|
+
throw new RetrospectiveError("retro_invalid", `状態は ${RISK_STATES.join(" / ")} です`);
|
|
46
|
+
const facts = input.facts?.trim() || undefined;
|
|
47
|
+
const scope = input.scope?.trim() || undefined;
|
|
48
|
+
const reason = input.reason?.trim() || undefined;
|
|
49
|
+
for (const [k, v] of [["事実", facts], ["範囲", scope], ["理由", reason]])
|
|
50
|
+
if (v && v.length > JUDGMENT_LIMITS.text)
|
|
51
|
+
throw new RetrospectiveError("retro_invalid", `${k}は ${JUDGMENT_LIMITS.text} 文字までです`);
|
|
52
|
+
if (input.evidence.length > JUDGMENT_LIMITS.evidence)
|
|
53
|
+
throw new RetrospectiveError("retro_invalid", `根拠は ${JUDGMENT_LIMITS.evidence} 件までです`);
|
|
54
|
+
if (input.state === "occurred" && (!facts || !input.evidence.length))
|
|
55
|
+
throw new RetrospectiveError("retro_invalid", "「起きた」には確認した事実(facts)と根拠(evidence)が要ります");
|
|
56
|
+
if (input.state === "not_occurred" && (!scope || !input.evidence.length))
|
|
57
|
+
throw new RetrospectiveError("retro_invalid", "「起きなかった」には確認した範囲(scope)と根拠(evidence)が要ります");
|
|
58
|
+
const prev = latestJudgment(file, t.id, input.risk);
|
|
59
|
+
if (prev && prev.state !== "unchecked" && !reason)
|
|
60
|
+
throw new RetrospectiveError("retro_invalid", `リスク ${input.risk + 1} は「${RISK_STATE_LABEL[prev.state]}」と確認済みです。変える・未確認に戻すには理由(reason)を書いてください`);
|
|
61
|
+
if (input.state === "unchecked" && !input.evidence.length && !prev)
|
|
62
|
+
throw new RetrospectiveError("retro_invalid", "未確認のままにするなら、結び付ける根拠を1つ以上指定してください");
|
|
63
|
+
const n = Math.max(0, ...(file.judgments ?? []).map((j) => Number(j.id.slice(1)))) + 1;
|
|
64
|
+
const j = {
|
|
65
|
+
id: `J${n}`,
|
|
66
|
+
target: t.id,
|
|
67
|
+
risk: input.risk,
|
|
68
|
+
riskText: risk.text,
|
|
69
|
+
state: input.state,
|
|
70
|
+
...(facts ? { facts } : {}),
|
|
71
|
+
...(scope ? { scope } : {}),
|
|
72
|
+
evidence: input.evidence,
|
|
73
|
+
...(reason ? { reason } : {}),
|
|
74
|
+
at: ctx.now,
|
|
75
|
+
...(ctx.actor ? { by: ctx.actor } : {}),
|
|
76
|
+
};
|
|
77
|
+
return { ...file, version: file.version + 1, judgments: [...(file.judgments ?? []), j] };
|
|
78
|
+
}
|
|
79
|
+
export class RetrospectiveError extends Error {
|
|
80
|
+
code;
|
|
81
|
+
constructor(code, message) {
|
|
82
|
+
super(message);
|
|
83
|
+
this.code = code;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
export const RETRO_LIMITS = { reason: 2000 };
|
|
87
|
+
/** 評価の版(評価の内容の hash。依存を足さない) */
|
|
88
|
+
export function assessmentVersion(assessment) {
|
|
89
|
+
const s = JSON.stringify(assessment ?? null);
|
|
90
|
+
let h1 = 0x811c9dc5;
|
|
91
|
+
let h2 = 0x01000193;
|
|
92
|
+
for (let i = 0; i < s.length; i++) {
|
|
93
|
+
const c = s.charCodeAt(i);
|
|
94
|
+
h1 = Math.imul(h1 ^ c, 0x01000193) >>> 0;
|
|
95
|
+
h2 = Math.imul(h2 ^ c, 0x85ebca6b) >>> 0;
|
|
96
|
+
}
|
|
97
|
+
return `${h1.toString(16).padStart(8, "0")}${h2.toString(16).padStart(8, "0")}`;
|
|
98
|
+
}
|
|
99
|
+
/** 1つの run の採用(候補にならなければ undefined) */
|
|
100
|
+
function adoptionOf(requestId, run, lookup) {
|
|
101
|
+
if (run.status !== "completed" || !run.assessment)
|
|
102
|
+
return undefined;
|
|
103
|
+
const base = { run: run.id, ...(run.finishedAt ? { finishedAt: run.finishedAt } : {}), risks: run.assessment.risks?.length ?? 0, verdict: run.assessment.verdict };
|
|
104
|
+
if (run.materialization) {
|
|
105
|
+
if (!run.materialization.done)
|
|
106
|
+
return undefined;
|
|
107
|
+
const basis = Object.entries(run.materialization.created).map(([key, tid]) => ({ key, target: tid, state: lookup.task(tid) }));
|
|
108
|
+
return basis.length ? { ...base, kind: "tasks", basis } : undefined;
|
|
109
|
+
}
|
|
110
|
+
if (run.adoption) {
|
|
111
|
+
if (!run.adoption.done)
|
|
112
|
+
return undefined;
|
|
113
|
+
const basis = run.adoption.created.map((key) => {
|
|
114
|
+
const id = run.adoption.reserved[key];
|
|
115
|
+
const c = id ? lookup.child(id) : undefined;
|
|
116
|
+
return { key, target: id ?? key, state: !c ? "missing" : c.splitFrom === `${run.id}/${key}` && c.parent === requestId ? "present" : "mismatch" };
|
|
117
|
+
});
|
|
118
|
+
return basis.length ? { ...base, kind: "split", basis } : undefined;
|
|
119
|
+
}
|
|
120
|
+
if (run.materialized?.length)
|
|
121
|
+
return { ...base, kind: "legacy", basis: run.materialized.map((tid) => ({ target: tid, state: lookup.task(tid) })) };
|
|
122
|
+
return undefined;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* 要望の候補(新しい順。runs は新しい順で渡す)。見送りの要望は候補なし(none に理由)。
|
|
126
|
+
*/
|
|
127
|
+
export function retroCandidates(requestId, status, runs, lookup) {
|
|
128
|
+
if (status === "rejected")
|
|
129
|
+
return { candidates: [], none: "見送りの要望は振り返りの対象にしません" };
|
|
130
|
+
const list = runs.flatMap((r) => {
|
|
131
|
+
const a = adoptionOf(requestId, r, lookup);
|
|
132
|
+
return a ? [a] : [];
|
|
133
|
+
});
|
|
134
|
+
if (!list.length)
|
|
135
|
+
return { candidates: [], none: "採用を終えた Preflight がありません(直接作ったタスクだけ・採用の前・評価の途中など)" };
|
|
136
|
+
return { candidates: list.map((c, i) => ({ ...c, latest: i === 0 })) };
|
|
137
|
+
}
|
|
138
|
+
/** 今の対象(無ければ undefined) */
|
|
139
|
+
export const currentTarget = (f) => f.targets.at(-1);
|
|
140
|
+
/**
|
|
141
|
+
* 対象を確定する(足した値を返す)。run は候補の中の1つで、評価があること。2件目からは訂正の理由が要る。
|
|
142
|
+
* 規則に合わなければ RetrospectiveError(何も当てない)
|
|
143
|
+
*/
|
|
144
|
+
export function confirmTarget(file, input, ctx) {
|
|
145
|
+
const cand = ctx.candidates.find((c) => c.run === input.run);
|
|
146
|
+
if (!cand)
|
|
147
|
+
throw new RetrospectiveError("retro_invalid", `${input.run} は振り返りの対象の候補ではありません(${ctx.none ?? `候補: ${ctx.candidates.map((c) => c.run).join(", ")}`})`);
|
|
148
|
+
const risks = ctx.risksOf(input.run);
|
|
149
|
+
const assessment = ctx.assessmentOf(input.run);
|
|
150
|
+
if (!risks || assessment === undefined)
|
|
151
|
+
throw new RetrospectiveError("retro_invalid", `${input.run} の評価が読めないため確定できません`);
|
|
152
|
+
const prev = currentTarget(file);
|
|
153
|
+
const reason = input.reason?.trim();
|
|
154
|
+
if (prev && prev.run === input.run && prev.assessmentVersion === assessmentVersion(assessment))
|
|
155
|
+
throw new RetrospectiveError("retro_invalid", `${input.run} は既に振り返りの対象です`);
|
|
156
|
+
if (prev && !reason)
|
|
157
|
+
throw new RetrospectiveError("retro_invalid", `対象を訂正するには理由(reason)を書いてください(今の対象: ${prev.run})`);
|
|
158
|
+
if (reason && reason.length > RETRO_LIMITS.reason)
|
|
159
|
+
throw new RetrospectiveError("retro_invalid", `理由は ${RETRO_LIMITS.reason} 文字までです`);
|
|
160
|
+
const n = Math.max(0, ...file.targets.map((t) => Number(t.id.slice(1)))) + 1;
|
|
161
|
+
const target = {
|
|
162
|
+
id: `V${n}`,
|
|
163
|
+
run: input.run,
|
|
164
|
+
kind: cand.kind,
|
|
165
|
+
assessmentVersion: assessmentVersion(assessment),
|
|
166
|
+
risks: risks.map((text, index) => ({ index, text })),
|
|
167
|
+
basis: cand.basis,
|
|
168
|
+
at: ctx.now,
|
|
169
|
+
...(ctx.actor ? { by: ctx.actor } : {}),
|
|
170
|
+
...(reason ? { reason } : {}),
|
|
171
|
+
...(prev ? { replaces: prev.id } : {}),
|
|
172
|
+
};
|
|
173
|
+
return { ...file, version: file.version + 1, targets: [...file.targets, target] };
|
|
174
|
+
}
|
|
175
|
+
// --- 読む ---------------------------------------------------------------------
|
|
176
|
+
const str = (v) => (typeof v === "string" && v ? v : undefined);
|
|
177
|
+
function readBasis(v) {
|
|
178
|
+
if (!Array.isArray(v))
|
|
179
|
+
return undefined;
|
|
180
|
+
const out = [];
|
|
181
|
+
for (const x of v) {
|
|
182
|
+
const o = x && typeof x === "object" ? x : {};
|
|
183
|
+
if (!str(o.target) || !["present", "archived", "missing", "mismatch"].includes(String(o.state)))
|
|
184
|
+
return undefined;
|
|
185
|
+
out.push({ ...(str(o.key) ? { key: str(o.key) } : {}), target: str(o.target), state: o.state });
|
|
186
|
+
}
|
|
187
|
+
return out;
|
|
188
|
+
}
|
|
189
|
+
function readTarget(v, at) {
|
|
190
|
+
const o = v && typeof v === "object" ? v : {};
|
|
191
|
+
const id = str(o.id) ?? "";
|
|
192
|
+
if (!/^V\d+$/.test(id))
|
|
193
|
+
return `${at} の id が読めません(V1, V2, ...)`;
|
|
194
|
+
const kind = o.kind;
|
|
195
|
+
if (kind !== "tasks" && kind !== "split" && kind !== "legacy")
|
|
196
|
+
return `${at}(${id})の kind が読めません`;
|
|
197
|
+
const risks = Array.isArray(o.risks) ? o.risks : undefined;
|
|
198
|
+
if (!risks || risks.some((r) => !r || typeof r !== "object" || !Number.isInteger(r.index) || typeof r.text !== "string"))
|
|
199
|
+
return `${at}(${id})の risks が読めません`;
|
|
200
|
+
const basis = readBasis(o.basis);
|
|
201
|
+
if (!str(o.run) || !str(o.assessmentVersion) || !str(o.at) || !basis)
|
|
202
|
+
return `${at}(${id})には run・assessmentVersion・basis・at が要ります`;
|
|
203
|
+
return {
|
|
204
|
+
id,
|
|
205
|
+
run: str(o.run),
|
|
206
|
+
kind,
|
|
207
|
+
assessmentVersion: str(o.assessmentVersion),
|
|
208
|
+
risks: risks.map((r) => ({ index: r.index, text: r.text })),
|
|
209
|
+
basis,
|
|
210
|
+
at: str(o.at),
|
|
211
|
+
...(str(o.by) ? { by: str(o.by) } : {}),
|
|
212
|
+
...(str(o.reason) ? { reason: str(o.reason) } : {}),
|
|
213
|
+
...(str(o.replaces) ? { replaces: str(o.replaces) } : {}),
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
/** retrospective.json を読む(壊れていれば RetrospectiveError retro_unreadable。黙って空にしない) */
|
|
217
|
+
export function readRetrospective(raw) {
|
|
218
|
+
const o = raw && typeof raw === "object" && !Array.isArray(raw) ? raw : undefined;
|
|
219
|
+
if (!o)
|
|
220
|
+
throw new RetrospectiveError("retro_unreadable", "retrospective.json が読めません(オブジェクトではありません)");
|
|
221
|
+
const version = Number.isInteger(o.version) && o.version >= 0 ? o.version : undefined;
|
|
222
|
+
if (version === undefined)
|
|
223
|
+
throw new RetrospectiveError("retro_unreadable", "retrospective.json の version が読めません");
|
|
224
|
+
const targets = [];
|
|
225
|
+
for (const [i, t] of (Array.isArray(o.targets) ? o.targets : []).entries()) {
|
|
226
|
+
const r = readTarget(t, `振り返りの対象 ${i + 1} 件目`);
|
|
227
|
+
if (typeof r === "string")
|
|
228
|
+
throw new RetrospectiveError("retro_unreadable", `retrospective.json: ${r}`);
|
|
229
|
+
targets.push(r);
|
|
230
|
+
}
|
|
231
|
+
const judgments = [];
|
|
232
|
+
for (const [i, j] of (Array.isArray(o.judgments) ? o.judgments : []).entries()) {
|
|
233
|
+
const r = readJudgment(j, `リスクの確認 ${i + 1} 件目`);
|
|
234
|
+
if (typeof r === "string")
|
|
235
|
+
throw new RetrospectiveError("retro_unreadable", `retrospective.json: ${r}`);
|
|
236
|
+
judgments.push(r);
|
|
237
|
+
}
|
|
238
|
+
return { ...o, version, targets, ...(judgments.length ? { judgments } : {}) };
|
|
239
|
+
}
|
|
240
|
+
function readEvidence(v) {
|
|
241
|
+
const o = v && typeof v === "object" ? v : {};
|
|
242
|
+
const idx = Number.isInteger(o.index) ? o.index : undefined;
|
|
243
|
+
if (o.kind === "task_review" && str(o.request) && str(o.task) && str(o.run) && TASK_REVIEW_SECTIONS.includes(o.section) && idx !== undefined && str(o.resultVersion) && typeof o.excerpt === "string")
|
|
244
|
+
return { kind: "task_review", request: str(o.request), task: str(o.task), run: str(o.run), section: o.section, index: idx, resultVersion: str(o.resultVersion), excerpt: o.excerpt };
|
|
245
|
+
if (o.kind === "milestone_review" && str(o.milestone) && str(o.run) && MILESTONE_REVIEW_SECTIONS.includes(o.section) && idx !== undefined && str(o.resultVersion) && typeof o.excerpt === "string")
|
|
246
|
+
return {
|
|
247
|
+
kind: "milestone_review",
|
|
248
|
+
milestone: str(o.milestone),
|
|
249
|
+
run: str(o.run),
|
|
250
|
+
section: o.section,
|
|
251
|
+
index: idx,
|
|
252
|
+
resultVersion: str(o.resultVersion),
|
|
253
|
+
excerpt: o.excerpt,
|
|
254
|
+
...(o.inputChanged === true ? { inputChanged: true } : {}),
|
|
255
|
+
...(str(o.reason) ? { reason: str(o.reason) } : {}),
|
|
256
|
+
};
|
|
257
|
+
if (o.kind === "rework" && str(o.request) && str(o.task) && str(o.history) && typeof o.excerpt === "string")
|
|
258
|
+
return { kind: "rework", request: str(o.request), task: str(o.task), history: str(o.history), excerpt: o.excerpt };
|
|
259
|
+
if (o.kind === "manual" && str(o.reference))
|
|
260
|
+
return { kind: "manual", reference: str(o.reference), ...(str(o.note) ? { note: str(o.note) } : {}) };
|
|
261
|
+
return undefined;
|
|
262
|
+
}
|
|
263
|
+
function readJudgment(v, at) {
|
|
264
|
+
const o = v && typeof v === "object" ? v : {};
|
|
265
|
+
const id = str(o.id) ?? "";
|
|
266
|
+
if (!/^J\d+$/.test(id))
|
|
267
|
+
return `${at} の id が読めません(J1, J2, ...)`;
|
|
268
|
+
const evidence = Array.isArray(o.evidence) ? o.evidence.map(readEvidence) : undefined;
|
|
269
|
+
if (!evidence || evidence.some((e) => !e))
|
|
270
|
+
return `${at}(${id})の evidence が読めません`;
|
|
271
|
+
if (!str(o.target) || !Number.isInteger(o.risk) || typeof o.riskText !== "string" || !isRiskState(o.state) || !str(o.at))
|
|
272
|
+
return `${at}(${id})には target・risk・riskText・state・at が要ります`;
|
|
273
|
+
return {
|
|
274
|
+
id,
|
|
275
|
+
target: str(o.target),
|
|
276
|
+
risk: o.risk,
|
|
277
|
+
riskText: o.riskText,
|
|
278
|
+
state: o.state,
|
|
279
|
+
...(str(o.facts) ? { facts: str(o.facts) } : {}),
|
|
280
|
+
...(str(o.scope) ? { scope: str(o.scope) } : {}),
|
|
281
|
+
evidence: evidence,
|
|
282
|
+
...(str(o.reason) ? { reason: str(o.reason) } : {}),
|
|
283
|
+
at: str(o.at),
|
|
284
|
+
...(str(o.by) ? { by: str(o.by) } : {}),
|
|
285
|
+
};
|
|
286
|
+
}
|