@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.
Files changed (138) hide show
  1. package/README.md +33 -33
  2. package/dist/web/assets/CompletionReview-gZKZrDu_.js +1 -0
  3. package/dist/web/assets/ImprovementDialog-Dno6dPnG.js +1 -0
  4. package/dist/web/assets/Outputs-BgHalMGb.js +1 -0
  5. package/dist/web/assets/RequestStatus-hZcBUUIu.js +1 -0
  6. package/dist/web/assets/Tabs-C3NmwCc3.js +1 -0
  7. package/dist/web/assets/TagInput-B2b862qn.js +1 -0
  8. package/dist/web/assets/TaskDrawer-4BQBELXa.js +6 -0
  9. package/dist/web/assets/_requestId-BMAG1t3o.js +1 -0
  10. package/dist/web/assets/_requestId-tbg2pA2S.js +1 -0
  11. package/dist/web/assets/archive-DMl6WyOe.js +1 -0
  12. package/dist/web/assets/board-BMTcHKyt.js +1 -0
  13. package/dist/web/assets/done-CL6Nlsua.js +1 -0
  14. package/dist/web/assets/draft-BvGxfD7v.js +2 -0
  15. package/dist/web/assets/index-Dp7Fc4VI.css +2 -0
  16. package/dist/web/assets/index-KdlgMitg.js +12 -0
  17. package/dist/web/assets/metrics-Cu7gJ7Rk.js +1 -0
  18. package/dist/web/assets/new-DTXWHuFO.js +1 -0
  19. package/dist/web/assets/outputs-CXqnjSqV.js +1 -0
  20. package/dist/web/assets/preflightInput-ClKwkp8R.js +2 -0
  21. package/dist/web/assets/preload-helper-oLCrNCwz.js +1 -0
  22. package/dist/web/assets/quality-RFd-7k3r.js +1 -0
  23. package/dist/web/assets/release-notes-Bpdi6RdY.js +5 -0
  24. package/dist/web/assets/requestData-CbFxwW5w.js +1 -0
  25. package/dist/web/assets/routes-BIt8bExF.js +6 -0
  26. package/dist/web/assets/settings-CsCqF_1B.js +1 -0
  27. package/dist/web/assets/taskReview-_WCgnQit.js +1 -0
  28. package/dist/web/assets/ui-BGK72r3u.js +1 -0
  29. package/dist/web/assets/workTarget-CySfKyfB.js +30 -0
  30. package/dist/web/index.html +4 -4
  31. package/docs/architecture.md +610 -33
  32. package/docs/development.md +61 -17
  33. package/docs/how-to-use.md +554 -17
  34. package/docs/installation.md +235 -144
  35. package/docs/publishing.md +1 -1
  36. package/lib/cli/agentsStatus.js +197 -0
  37. package/lib/cli/args.js +111 -2
  38. package/lib/cli/guide.js +27 -0
  39. package/lib/cli/guide.md +214 -0
  40. package/lib/cli/help.js +74 -1
  41. package/lib/cli/main.js +97 -17
  42. package/lib/cli/metricsCommands.js +77 -0
  43. package/lib/cli/output.js +19 -1
  44. package/lib/cli/preflightCommands.js +7 -1
  45. package/lib/cli/project.js +13 -24
  46. package/lib/cli/qualityCommands.js +188 -0
  47. package/lib/cli/readOnly.js +17 -0
  48. package/lib/cli/requestCommands.js +33 -4
  49. package/lib/cli/requirementCommands.js +288 -0
  50. package/lib/cli/retroCommands.js +106 -0
  51. package/lib/cli/revisitCommands.js +73 -0
  52. package/lib/cli/showView.js +183 -4
  53. package/lib/cli/taskCommands.js +341 -20
  54. package/lib/cli/taskReviewCommands.js +178 -0
  55. package/lib/cli/userConfig.js +47 -0
  56. package/lib/core/completionRefs.js +46 -0
  57. package/lib/core/context.js +4 -1
  58. package/lib/core/metrics/definitions.js +434 -0
  59. package/lib/core/metrics/index.js +88 -0
  60. package/lib/core/metrics/manual.js +180 -0
  61. package/lib/core/milestoneReview/material.js +11 -1
  62. package/lib/core/milestoneReview/mockReviewer.js +1 -0
  63. package/lib/core/milestoneReview/review.js +70 -6
  64. package/lib/core/milestoneReview/service.js +29 -93
  65. package/lib/core/milestoneReview/store.js +12 -62
  66. package/lib/core/ops.js +23 -3
  67. package/lib/core/preflight/carryover.js +6 -2
  68. package/lib/core/preflight/codexEngine.js +34 -17
  69. package/lib/core/preflight/diagnose.js +4 -9
  70. package/lib/core/preflight/engine.js +15 -0
  71. package/lib/core/preflight/hostPaths.js +260 -0
  72. package/lib/core/preflight/input.js +33 -5
  73. package/lib/core/preflight/instructions.js +36 -2
  74. package/lib/core/preflight/mockEngine.js +24 -2
  75. package/lib/core/preflight/render.js +22 -3
  76. package/lib/core/preflight/service.js +99 -8
  77. package/lib/core/preflight/uiRender.js +3 -0
  78. package/lib/core/projectRegistry.js +3 -3
  79. package/lib/core/quality.js +21 -0
  80. package/lib/core/qualityImprovement.js +221 -0
  81. package/lib/core/requestOps.js +294 -11
  82. package/lib/core/retrospective.js +208 -0
  83. package/lib/core/reviewCandidates.js +56 -0
  84. package/lib/core/reviewRuns.js +205 -0
  85. package/lib/core/store/archivedTasks.js +74 -0
  86. package/lib/core/store/collection.js +32 -3
  87. package/lib/core/store/normalize.js +35 -2
  88. package/lib/core/store/preflightStore.js +23 -1
  89. package/lib/core/store/projectFile.js +10 -0
  90. package/lib/core/store/workspace.js +49 -3
  91. package/lib/core/taskReview/material.js +459 -0
  92. package/lib/core/taskReview/mockReviewer.js +30 -0
  93. package/lib/core/taskReview/paths.js +15 -0
  94. package/lib/core/taskReview/review.js +312 -0
  95. package/lib/core/taskReview/service.js +187 -0
  96. package/lib/core/taskReview/store.js +214 -0
  97. package/lib/server/api/manifest.js +104 -5
  98. package/lib/server/api/milestoneReviewRoutes.js +4 -3
  99. package/lib/server/api/routes.js +265 -17
  100. package/lib/server/api/taskReviewRoutes.js +66 -0
  101. package/lib/server/server.js +2 -2
  102. package/lib/shared/acceptance.js +618 -0
  103. package/lib/shared/completionRecord.js +327 -0
  104. package/lib/shared/metrics.js +42 -0
  105. package/lib/shared/milestoneReview.js +2 -1
  106. package/lib/shared/preflightInput.js +1 -1
  107. package/lib/shared/quality.js +391 -0
  108. package/lib/shared/qualityImprovement.js +1 -0
  109. package/lib/shared/qualityTemplates.js +31 -0
  110. package/lib/shared/requirementSource.js +635 -0
  111. package/lib/shared/retrospective.js +286 -0
  112. package/lib/shared/reviewCandidate.js +308 -0
  113. package/lib/shared/reworkHistory.js +81 -0
  114. package/lib/shared/taskBlock.js +142 -0
  115. package/lib/shared/taskReview.js +56 -0
  116. package/package.json +3 -2
  117. package/skills/p3/SKILL.md +9 -152
  118. package/dist/web/assets/Outputs-ddwte0jj.js +0 -1
  119. package/dist/web/assets/RequestStatus-Bg1OLbRc.js +0 -1
  120. package/dist/web/assets/Tabs-DTmggzgg.js +0 -1
  121. package/dist/web/assets/TagInput-BHAgjLP7.js +0 -1
  122. package/dist/web/assets/TaskDrawer-Dz_5c2NH.js +0 -3
  123. package/dist/web/assets/_requestId-D9-gtIcG.js +0 -1
  124. package/dist/web/assets/_requestId-DzCNYvqf.js +0 -30
  125. package/dist/web/assets/appCtx-Cm24VpAf.js +0 -1
  126. package/dist/web/assets/board-MCHcZ-PU.js +0 -1
  127. package/dist/web/assets/done-zq10Bt08.js +0 -1
  128. package/dist/web/assets/draft-CfJeyLOl.js +0 -1
  129. package/dist/web/assets/index-Ce0ndpne.js +0 -12
  130. package/dist/web/assets/index-D68mkSnw.css +0 -2
  131. package/dist/web/assets/new-9TKiNT4O.js +0 -1
  132. package/dist/web/assets/preflightInput-BAeEJYUK.js +0 -2
  133. package/dist/web/assets/preload-helper-FBLw7u7x.js +0 -1
  134. package/dist/web/assets/release-notes-hK5XezLW.js +0 -5
  135. package/dist/web/assets/requestData-BnN7mctX.js +0 -1
  136. package/dist/web/assets/routes-usHwrrA0.js +0 -3
  137. package/dist/web/assets/settings-BVZDnL6O.js +0 -1
  138. package/dist/web/assets/workTarget-Cijqq4yH.js +0 -1
@@ -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 "./project.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,73 @@
1
+ import { REVIEW_CODE_LABEL, REVIEW_STATE_HINT, REVIEW_STATE_LABEL } from "../shared/reviewCandidate.js";
2
+ import { recordPremise } from "../core/requestOps.js";
3
+ import { reviewCandidates } from "../core/reviewCandidates.js";
4
+ import { UsageError } from "./project.js";
5
+ /**
6
+ * 見直しが必要(候補)と前提の変更のコマンド(規則は shared/reviewCandidate.ts)。
7
+ *
8
+ * revisit [<要望>] [--all] 見直し候補(完了したタスクと対応済・完了済の要望。完了済みも含む)
9
+ * premise [<要望>] 前提の変更の一覧
10
+ * premise [<要望>] add --target <ID>... --reason 理由 --condition 新しい条件 前提の変更を記録する(外部の規則の変更など)
11
+ * premise [<要望>] ack <P> --target <ID> --condition 確かめた条件 変更を確かめたことを記録する
12
+ */
13
+ /** 診断の行(p3 show・p3 revisit で使う) */
14
+ export function formatReview(d, { head = true } = {}) {
15
+ const lines = head ? [`見直し: ${REVIEW_STATE_LABEL[d.state]}${d.record ? `(基点 ${d.record})` : ""}`] : [];
16
+ if (d.state !== "candidate")
17
+ lines.push(` ${REVIEW_STATE_HINT[d.state]}`);
18
+ for (const r of d.reasons) {
19
+ lines.push(` - ${REVIEW_CODE_LABEL[r.code]} ${r.target}${r.related?.length ? `(関係: ${r.related.join(", ")})` : ""}`);
20
+ if (r.was !== undefined)
21
+ lines.push(` 当時: ${r.was}`);
22
+ if (r.now !== undefined)
23
+ lines.push(` 今: ${r.now}`);
24
+ }
25
+ for (const u of d.unreadable ?? [])
26
+ lines.push(` ※比べられない: ${u}`);
27
+ if (d.state === "candidate")
28
+ lines.push(" 候補を出すだけで、状態・済みは変えていません。確かめたら、もう一度済みにすると新しい記録が基点になります");
29
+ return lines;
30
+ }
31
+ const premiseLines = (c) => [
32
+ `${c.id} ${c.at} ${c.by ?? ""} 対象: ${c.targets.join(", ")}`,
33
+ ` 理由: ${c.reason}`,
34
+ ` 新しい条件: ${c.condition}`,
35
+ ...(c.acks ?? []).map((a) => ` 確認: ${a.target} ${a.condition} ${a.at} ${a.by ?? ""}`),
36
+ ];
37
+ export async function revisitCommand(cmd, env) {
38
+ const { ctx, out, args, o, actor, current, expectedRev, requestArg } = env;
39
+ if (cmd === "revisit") {
40
+ const rid = args[0] ? requestArg(args[0]) : o.all || !current ? undefined : current;
41
+ const list = reviewCandidates(ctx, rid ? { request: rid } : {});
42
+ return out.result(list, () => (list.length ? list.flatMap((d) => [d.target, ...formatReview(d, { head: false }), ""]).join("\n").trimEnd() : `見直しが必要(候補)はありません${rid ? `(${rid}。全要望は --all)` : ""}`));
43
+ }
44
+ if (cmd !== "premise" && cmd !== "premises")
45
+ return undefined;
46
+ const subs = new Set(["add", "ack", "ls"]);
47
+ const rest = subs.has(args[0] ?? "") || args.length === 0 ? args : args.slice(1);
48
+ const rid = requestArg(subs.has(args[0] ?? "") || args.length === 0 ? undefined : args[0]);
49
+ const sub = rest[0] ?? "ls";
50
+ if (sub === "ls") {
51
+ const list = ctx.ws.requests.require(rid).premiseChanges ?? [];
52
+ return out.result(list, () => (list.length ? list.flatMap(premiseLines).join("\n") : `${rid} に前提の変更の記録はありません`));
53
+ }
54
+ const condition = o.condition;
55
+ if (!condition)
56
+ throw new UsageError("--condition(新しい条件・版。ack では確かめた条件)を指定してください");
57
+ let op;
58
+ if (sub === "add") {
59
+ if (!o.target?.length || !o.reason)
60
+ throw new UsageError("--target <要望 ID・タスク ID・要望の根拠の ID>(複数可)と --reason を指定してください");
61
+ op = { op: "add", targets: o.target, reason: o.reason, condition };
62
+ }
63
+ else if (sub === "ack") {
64
+ const id = rest[1];
65
+ if (!id || o.target?.length !== 1)
66
+ throw new UsageError("p3 premise ack <P1> --target <ID> --condition <確かめた条件>");
67
+ op = { op: "ack", id, target: o.target[0], condition };
68
+ }
69
+ else
70
+ throw new UsageError("p3 premise [<要望>] [ls | add | ack <P>]");
71
+ const { change, request } = await recordPremise(ctx, rid, op, { expectedRev, actor });
72
+ return out.result({ change, rev: request.rev }, () => [`${sub === "add" ? "記録しました" : "確認を記録しました"}(rev ${request.rev})`, ...premiseLines(change)].join("\n"));
73
+ }
@@ -1,4 +1,9 @@
1
+ import { ANSWER_STATE_LABEL, criteriaSourceView, requestRequirementView, SOURCE_STATE_LABEL } from "../shared/requirementSource.js";
1
2
  import { absRef, parseRef } from "../shared/refs.js";
3
+ import { acceptanceStatus, basisDetail, basisLabel, EVIDENCE_BASIS_KINDS, EVIDENCE_BASIS_LABEL, evidenceBasisOf } from "../shared/acceptance.js";
4
+ import { blockWarnings } from "../shared/taskBlock.js";
5
+ import { REWORK_CAUSE_LABEL, reworkLine } from "../shared/reworkHistory.js";
6
+ import { COMPLETION_TRIGGER_LABEL, REF_CAPTURE_LABEL } from "../shared/completionRecord.js";
2
7
  import { supersededWarnings } from "../core/supersede.js";
3
8
  import { table } from "./format.js";
4
9
  import { taskWork } from "../core/workTargets.js";
@@ -20,6 +25,69 @@ export function taskExtras(ctx, task, marks) {
20
25
  return { superseded, dependencies: dependencyStates(ctx, task), warnings };
21
26
  }
22
27
  const BRIEF_TASK_KEYS = ["id", "ref", "request", "title", "status", "body", "rev", "outputs", "relations"];
28
+ const STATE_MARK = { met: "✓ 満たした", unmet: "✗ 満たせなかった", unverified: "? 未検証", missing: "・ 証拠なし", stale: "! 再確認が必要(基準を変えた後)" };
29
+ /** 停止の行(show・brief・アーカイブで共通。履歴は通常の show だけ)。停止も履歴も問題も無ければ空 */
30
+ export function formatBlock(task, { history = false } = {}) {
31
+ const lines = [];
32
+ const b = task.block;
33
+ if (b) {
34
+ lines.push(`⏸ 止まっています(${b.since} から${b.updatedBy ? `・${b.updatedBy}` : ""})`, ...b.reason.split("\n").map((l) => ` ${l}`));
35
+ if (b.decision)
36
+ lines.push(" 決めてほしいこと:", ...b.decision.split("\n").map((l) => ` ${l}`));
37
+ }
38
+ for (const w of blockWarnings(task))
39
+ lines.push(`※ ${w}`);
40
+ if (history && task.blockHistory?.length) {
41
+ lines.push("停止の履歴:");
42
+ const label = { set: "付けた", update: "直した", clear: "解除した" };
43
+ for (const h of task.blockHistory) {
44
+ lines.push(` ${h.at} ${label[h.action]}${h.by ? ` ${h.by}` : ""}`);
45
+ const shown = h.after ?? h.before;
46
+ if (shown)
47
+ lines.push(` 理由: ${shown.reason.split("\n")[0]}`);
48
+ if (h.resolution)
49
+ lines.push(` 回答・解決: ${h.resolution.split("\n").join(" / ")}`);
50
+ }
51
+ }
52
+ return lines;
53
+ }
54
+ /**
55
+ * 受け入れ基準と証拠・不足の行(show・criteria で共通)。基準が無いタスクは「受け入れ基準なし」の1行(emptyLine: false なら出さない)。
56
+ * 証拠は作業した側の申告で、人が「済み」にする前に読むもの
57
+ */
58
+ export function formatAcceptance(task, { emptyLine = true } = {}) {
59
+ const acc = acceptanceStatus(task);
60
+ if (!acc)
61
+ return emptyLine ? ["受け入れ基準なし"] : [];
62
+ const kinds = EVIDENCE_BASIS_KINDS.filter((k) => acc.metByBasis[k] > 0).map((k) => `${EVIDENCE_BASIS_LABEL[k]} ${acc.metByBasis[k]}`);
63
+ const lines = [`受け入れ基準(${acc.met}/${acc.total} を満たしたと申告${kinds.length ? `。根拠: ${kinds.join("・")}` : ""}):`];
64
+ // 根拠の行: 結果と別に、種類(古い証拠は「種類未記録」)と、読んだもの・検査のコマンド・結果・対象
65
+ const basisLines = (e) => [` 根拠: ${basisLabel(e)}`, ...basisDetail(evidenceBasisOf(e).basis).map((d) => ` ${d.label}: ${d.value.split("\n").join("\n ")}`)];
66
+ // 要求の出典と確認(実装後の証拠とは別。要望者の申告の記録)
67
+ const sv = task.acceptanceSources?.length ? criteriaSourceView(task.acceptanceCriteria, task.acceptanceSources) : undefined;
68
+ const sourceLine = (id) => {
69
+ const it = sv?.items.find((x) => x.id === id);
70
+ if (!it || !it.sources.length)
71
+ return [];
72
+ return [` 出典と確認: ${SOURCE_STATE_LABEL[it.state]}(${it.sources.map((x) => `${x.id}${x.source ? ` ${x.source}` : ""}${x.confirmed ? ` ${x.confirmed.by}・${x.confirmed.on}` : ""}`).join(" / ")})`];
73
+ };
74
+ for (const i of acc.items) {
75
+ lines.push(` ${i.id} ${i.text}`, ` ${STATE_MARK[i.state]}`, ...sourceLine(i.id));
76
+ if (i.evidence)
77
+ lines.push(...basisLines(i.evidence));
78
+ if (i.evidence?.evidence)
79
+ lines.push(...i.evidence.evidence.split("\n").map((l) => ` ${l}`));
80
+ if (i.state === "stale" && i.evidence)
81
+ lines.push(` (記録したときの基準: ${i.evidence.criterionText})`);
82
+ }
83
+ for (const e of acc.orphans)
84
+ lines.push(` ${e.criterionId} (基準は消されています: ${e.criterionText})`, ` ${STATE_MARK[e.result]}`, ...basisLines(e), ...(e.evidence ? e.evidence.split("\n").map((l) => ` ${l}`) : []));
85
+ for (const x of sv?.orphans ?? [])
86
+ lines.push(` ${x.criterionId} (基準が無い出典と確認の記録 ${x.id}: 対応先不明)`);
87
+ if (acc.shortfalls.length)
88
+ lines.push("不足:", ...acc.shortfalls.map((s) => ` - ${s}`));
89
+ return lines;
90
+ }
23
91
  export function briefTask(ctx, task, marks) {
24
92
  const item = Object.fromEntries(BRIEF_TASK_KEYS.map((k) => [k, task[k]]));
25
93
  item.relations = task.relations.filter((r) => r.type === "depends_on");
@@ -28,13 +96,89 @@ export function briefTask(ctx, task, marks) {
28
96
  // 変更の記録(完了したタスク)。経緯を知るために読む
29
97
  if (task.record)
30
98
  item.record = task.record;
99
+ // 受け入れ基準と証拠(着手時に読み、完了時に項目ごとの証拠を残す)
100
+ if (task.acceptanceCriteria?.length)
101
+ item.acceptanceCriteria = task.acceptanceCriteria;
102
+ if (task.acceptanceEvidence?.length)
103
+ item.acceptanceEvidence = task.acceptanceEvidence;
104
+ // 基準ごとの要求の出典と確認(あるときだけ)
105
+ if (task.acceptanceSources?.length)
106
+ item.acceptanceSources = task.acceptanceSources;
107
+ if (task.acceptanceProblems?.length)
108
+ item.acceptanceProblems = task.acceptanceProblems;
109
+ // 停止の今の値と読み取りの問題(履歴は省く)
110
+ if (task.block)
111
+ item.block = task.block;
112
+ if (task.blockProblems?.length)
113
+ item.blockProblems = task.blockProblems;
31
114
  // 着手先: 作業先のリポジトリとそのブランチ(作業先なしは repo: null)
32
- return { item, work: taskWork(ctx.ws, task), ...taskExtras(ctx, task, marks) };
115
+ // 基準・証拠の状態(基準なしのタスクでは省く)
116
+ const acceptance = acceptanceStatus(task);
117
+ const completion = completionBrief(task);
118
+ return { item, work: taskWork(ctx.ws, task), ...taskExtras(ctx, task, marks), ...(acceptance ? { acceptance } : {}), ...(completion ? { completion } : {}) };
119
+ }
120
+ /** 完了の記録の概要(契機・日時・主体・rev。条件の写しは p3 show(--brief でない)か API の詳細で読む)。記録も問題も無ければ省く */
121
+ export function completionBrief(x) {
122
+ if (!x.completionRecords?.length && !x.completionProblems?.length)
123
+ return undefined;
124
+ return {
125
+ records: (x.completionRecords ?? []).map((r) => ({ id: r.id, trigger: r.trigger, at: r.at, ...(r.by ? { by: r.by } : {}), rev: r.rev, status: r.status })),
126
+ ...(x.completionProblems?.length ? { problems: x.completionProblems } : {}),
127
+ };
128
+ }
129
+ const refLine = (r) => r.state === "ok"
130
+ ? `${r.name}: ${r.commit?.slice(0, 12) ?? ""}${r.dirty === true ? "(未コミットの変更あり)" : r.dirty === false ? "" : `(未コミットの変更は不明${r.reason ? `: ${r.reason}` : ""})`}`
131
+ : `${r.name}: ${r.reason ?? REF_CAPTURE_LABEL[r.state]}`;
132
+ /** 完了の記録の詳細(p3 show。そのときの条件の写しで、今の値とは別) */
133
+ export function formatCompletionDetail(x) {
134
+ const lines = ["完了の記録(そのときの条件の写し。今の値とは別):"];
135
+ for (const r of x.completionRecords ?? []) {
136
+ lines.push(` ${r.id} ${COMPLETION_TRIGGER_LABEL[r.trigger]} ${r.at} ${r.by ?? "(主体なし)"} rev ${r.rev} ${r.status}${r.checked ? " 済み" : ""}`);
137
+ const q = r.quality;
138
+ lines.push(` 品質: ${q.state === "set" ? "設定済" : q.state === "unset" ? "未設定" : "読めない"} 版 ${q.version}${q.standards ? ` 項目 ${q.standards.map((s) => `${s.id}${s.exempt ? "(除外)" : ""}`).join(", ") || "なし"}` : ""}`);
139
+ if (r.acceptance?.problems)
140
+ lines.push(` 受け入れ基準: 読めない(${r.acceptance.problems.join(" / ")})`);
141
+ for (const c of r.acceptance?.criteria ?? []) {
142
+ const e = r.acceptance?.evidence?.find((v) => v.criterionId === c.id);
143
+ lines.push(` ${c.id} ${c.text}${e ? ` → ${e.result}・${basisLabel(e)}` : " → 証拠なし"}`);
144
+ }
145
+ if (r.title !== undefined)
146
+ lines.push(` 題: ${r.title}`);
147
+ if (r.requirement?.problems)
148
+ lines.push(` 要求の根拠: 読めない(${r.requirement.problems.join(" / ")})`);
149
+ else if (r.requirement?.sources?.length)
150
+ lines.push(` 要求の根拠: ${r.requirement.sources.map((s) => s.id).join(", ")}`);
151
+ if (r.tasks)
152
+ lines.push(` タスク: ${r.tasks.map((t) => `${t.id} rev ${t.rev} ${t.status}${t.record ? ` ${t.record}` : "(記録なし)"}`).join(" / ") || "なし"}`);
153
+ if (r.children?.length)
154
+ lines.push(` 子の要望: ${r.children.map((t) => `${t.id} rev ${t.rev} ${t.status}${t.record ? ` ${t.record}` : "(記録なし)"}`).join(" / ")}`);
155
+ lines.push(` 参照先: ${r.refs ? r.refs.map(refLine).join(" / ") || "登録なし" : "取得していません"}`);
156
+ }
157
+ for (const p of x.completionProblems ?? [])
158
+ lines.push(` ※読めない: ${p}(ファイルの completionRecords を直すまで新しい記録は足しません)`);
159
+ return lines;
160
+ }
161
+ /** 手戻りの履歴(済みの解除・完了からの再開)の行 */
162
+ export function formatRework(t) {
163
+ return [
164
+ "手戻りの履歴(済みの解除・完了からの再開):",
165
+ ...(t.reworkHistory ?? []).map((e) => ` ${reworkLine(e)} ${REWORK_CAUSE_LABEL[e.cause]} ${e.at} ${e.by ?? "(主体なし)"} rev ${e.rev}`),
166
+ ...(t.reworkProblems ?? []).map((p) => ` ※読めない: ${p}(ファイルの reworkHistory を直すまで新しい履歴は足しません)`),
167
+ ];
168
+ }
169
+ /** 完了の記録の行(今の値とは別の、そのときの記録) */
170
+ export function formatCompletion(c) {
171
+ return [
172
+ "完了の記録(そのときの条件の写し。今の値とは別):",
173
+ ...c.records.map((r) => ` ${r.id} ${COMPLETION_TRIGGER_LABEL[r.trigger]} ${r.at} ${r.by ?? "(主体なし)"} rev ${r.rev}`),
174
+ ...(c.problems ?? []).map((p) => ` ※読めない: ${p}(ファイルの completionRecords を直すまで新しい記録は足しません)`),
175
+ ];
33
176
  }
34
177
  export function formatBriefTask(view) {
35
178
  const { item, work, dependencies, warnings } = view;
36
179
  const short = (ref) => (ref.startsWith(`${item.request}/`) ? ref.slice(item.request.length + 1) : ref);
37
180
  const lines = [`${item.ref} ${item.title}`, ` status ${item.status} rev ${item.rev}`];
181
+ lines.push(...formatBlock(item));
38
182
  lines.push(` 作業先 ${work.repo ? `${work.repo}${work.branch ? ` branch ${work.branch}` : "(ブランチなし)"}${work.registered ? "" : ` ※このマシンのパスが未登録(p3 repo path ${work.repo} <パス>)`}` : "なし"}`);
39
183
  if (dependencies.length) {
40
184
  lines.push(` 依存 ${dependencies.map((d) => `${short(d.ref)} ${d.status ?? "(状態不明)"}`).join(" / ")}`);
@@ -49,6 +193,9 @@ export function formatBriefTask(view) {
49
193
  lines.push("", item.body.trim());
50
194
  if (item.record)
51
195
  lines.push("", "## 変更の記録", item.record);
196
+ lines.push("", ...formatAcceptance(item));
197
+ if (view.completion)
198
+ lines.push("", ...formatCompletion(view.completion));
52
199
  return lines.join("\n");
53
200
  }
54
201
  export function briefRequest(ctx, r, issue) {
@@ -65,8 +212,38 @@ export function briefRequest(ctx, r, issue) {
65
212
  const tasks = ctx.ws
66
213
  .tasksOf(r.id)
67
214
  .list()
68
- .map((t) => ({ id: t.id, ref: t.ref, title: t.title, status: t.status, repo: t.repo }));
69
- return { item, branches, tasks, ...(issue ? { issue } : {}) };
215
+ .map((t) => ({ id: t.id, ref: t.ref, title: t.title, status: t.status, repo: t.repo, ...(t.block ? { blocked: true } : {}) }));
216
+ // 要求の出典と確認(記録・回答・読めない値があるときだけ)
217
+ const req = requestRequirementView(r);
218
+ const requirement = req.sources.length || req.answers.length || req.problems.length ? req : undefined;
219
+ const completion = completionBrief(r);
220
+ return { item, branches, tasks, ...(issue ? { issue } : {}), ...(requirement ? { requirement } : {}), ...(completion ? { completion } : {}) };
221
+ }
222
+ const confirmLine = (c) => `${c.by}・${c.on}`;
223
+ export function sourceLines(s, pad = " ") {
224
+ return [
225
+ `${pad}${s.id} [${SOURCE_STATE_LABEL[s.state]}${s.confirmed ? `: ${confirmLine(s.confirmed)}` : ""}]${s.from ? ` (要望の ${s.from} を写したもの)` : ""}`,
226
+ ...(s.target ? [`${pad} 対象: ${s.target}`] : []),
227
+ ...(s.source ? [`${pad} 出典: ${s.source}`] : []),
228
+ ...(s.basis ? [`${pad} 根拠: ${s.basis.split("\n").join(`\n${pad} `)}`] : []),
229
+ ...(s.history?.length ? [`${pad} 前の確認: ${s.history.map((h) => `${confirmLine(h)}${h.lapsedAt ? `(${h.lapsedAt.slice(0, 10)} に効かなくなった)` : ""}`).join(" / ")}`] : []),
230
+ ];
231
+ }
232
+ /** 要望の根拠と回答(p3 source・p3 show で使う) */
233
+ export function formatRequirement(v) {
234
+ const lines = [`要求の出典と確認: ${SOURCE_STATE_LABEL[v.state]}(申告の記録。P3 の保証ではありません)`];
235
+ if (!v.sources.length)
236
+ lines.push(" 記録なし(任意。p3 source add --source <出典> --grounds <根拠> で残せます)");
237
+ for (const s of v.sources)
238
+ lines.push(...sourceLines(s));
239
+ if (v.answers.length) {
240
+ lines.push("確認事項への回答:");
241
+ for (const a of v.answers)
242
+ lines.push(` ${a.run}/${a.question} [${ANSWER_STATE_LABEL[a.state]}] ${a.copy.question}`, ` 回答${a.by || a.on ? `(${[a.by, a.on].filter(Boolean).join("・")})` : ""}: ${a.answer.split("\n").join("\n ")}`);
243
+ }
244
+ for (const p of v.problems)
245
+ lines.push(` ※読めない: ${p}(request.md を直してください)`);
246
+ return lines;
70
247
  }
71
248
  /** 親子の行(祖先と直下の子。無ければ何も出さない) */
72
249
  export function formatFamily(f) {
@@ -91,9 +268,11 @@ export function formatBriefRequest(view) {
91
268
  ...(branchLine ? [] : names.map((n) => ` branch ${n}: ${branches[n].branch}`)),
92
269
  ...(family ? formatFamily(family) : []),
93
270
  item.body.trim() ? `\n${item.body.trim()}` : "",
271
+ ...(view.requirement ? ["", ...formatRequirement(view.requirement)] : []),
272
+ ...(view.completion ? ["", ...formatCompletion(view.completion)] : []),
94
273
  "",
95
274
  `タスク (${tasks.length}):`,
96
- table(tasks.map((t) => [` ${t.id}`, t.status, t.repo ?? "(作業先なし)", t.title])) || " (なし)",
275
+ table(tasks.map((t) => [` ${t.id}`, t.status, t.repo ?? "(作業先なし)", `${t.title}${t.blocked ? " ⏸停止" : ""}`])) || " (なし)",
97
276
  ]
98
277
  .filter((l, i) => l !== "" || i > 1)
99
278
  .join("\n");