@infodb/p3 0.12.0 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. package/README.md +32 -35
  2. package/dist/web/assets/CompletionReview-gZKZrDu_.js +1 -0
  3. package/dist/web/assets/ImprovementDialog-Dno6dPnG.js +1 -0
  4. package/dist/web/assets/Outputs-BgHalMGb.js +1 -0
  5. package/dist/web/assets/RequestStatus-hZcBUUIu.js +1 -0
  6. package/dist/web/assets/Tabs-C3NmwCc3.js +1 -0
  7. package/dist/web/assets/TagInput-B2b862qn.js +1 -0
  8. package/dist/web/assets/TaskDrawer-4BQBELXa.js +6 -0
  9. package/dist/web/assets/_requestId-BMAG1t3o.js +1 -0
  10. package/dist/web/assets/_requestId-tbg2pA2S.js +1 -0
  11. package/dist/web/assets/archive-DMl6WyOe.js +1 -0
  12. package/dist/web/assets/board-BMTcHKyt.js +1 -0
  13. package/dist/web/assets/done-CL6Nlsua.js +1 -0
  14. package/dist/web/assets/draft-BvGxfD7v.js +2 -0
  15. package/dist/web/assets/index-Dp7Fc4VI.css +2 -0
  16. package/dist/web/assets/index-KdlgMitg.js +12 -0
  17. package/dist/web/assets/metrics-Cu7gJ7Rk.js +1 -0
  18. package/dist/web/assets/new-DTXWHuFO.js +1 -0
  19. package/dist/web/assets/outputs-CXqnjSqV.js +1 -0
  20. package/dist/web/assets/preflightInput-ClKwkp8R.js +2 -0
  21. package/dist/web/assets/preload-helper-oLCrNCwz.js +1 -0
  22. package/dist/web/assets/{quality-Pu6EISAM.js → quality-RFd-7k3r.js} +1 -1
  23. package/dist/web/assets/release-notes-Bpdi6RdY.js +5 -0
  24. package/dist/web/assets/requestData-CbFxwW5w.js +1 -0
  25. package/dist/web/assets/routes-BIt8bExF.js +6 -0
  26. package/dist/web/assets/settings-CsCqF_1B.js +1 -0
  27. package/dist/web/assets/ui-BGK72r3u.js +1 -0
  28. package/dist/web/assets/workTarget-CySfKyfB.js +30 -0
  29. package/dist/web/index.html +4 -4
  30. package/docs/architecture.md +300 -36
  31. package/docs/development.md +60 -16
  32. package/docs/how-to-use.md +381 -28
  33. package/docs/installation.md +235 -144
  34. package/docs/publishing.md +1 -1
  35. package/lib/cli/agentsStatus.js +197 -0
  36. package/lib/cli/args.js +72 -8
  37. package/lib/cli/guide.js +27 -0
  38. package/lib/cli/guide.md +214 -0
  39. package/lib/cli/help.js +44 -6
  40. package/lib/cli/main.js +76 -20
  41. package/lib/cli/metricsCommands.js +77 -0
  42. package/lib/cli/output.js +12 -2
  43. package/lib/cli/project.js +13 -27
  44. package/lib/cli/qualityCommands.js +33 -8
  45. package/lib/cli/readOnly.js +15 -0
  46. package/lib/cli/requestCommands.js +21 -4
  47. package/lib/cli/requirementCommands.js +288 -0
  48. package/lib/cli/retroCommands.js +106 -0
  49. package/lib/cli/revisitCommands.js +73 -0
  50. package/lib/cli/showView.js +119 -6
  51. package/lib/cli/taskCommands.js +42 -16
  52. package/lib/cli/userConfig.js +47 -0
  53. package/lib/core/completionRefs.js +46 -0
  54. package/lib/core/metrics/definitions.js +434 -0
  55. package/lib/core/metrics/index.js +88 -0
  56. package/lib/core/metrics/manual.js +180 -0
  57. package/lib/core/ops.js +15 -2
  58. package/lib/core/preflight/carryover.js +5 -1
  59. package/lib/core/preflight/codexEngine.js +34 -17
  60. package/lib/core/preflight/diagnose.js +4 -9
  61. package/lib/core/preflight/engine.js +9 -0
  62. package/lib/core/preflight/hostPaths.js +260 -0
  63. package/lib/core/preflight/input.js +33 -5
  64. package/lib/core/preflight/instructions.js +18 -1
  65. package/lib/core/preflight/mockEngine.js +20 -2
  66. package/lib/core/preflight/render.js +22 -3
  67. package/lib/core/preflight/service.js +59 -9
  68. package/lib/core/preflight/uiRender.js +3 -0
  69. package/lib/core/requestOps.js +206 -14
  70. package/lib/core/retrospective.js +208 -0
  71. package/lib/core/reviewCandidates.js +56 -0
  72. package/lib/core/store/collection.js +20 -1
  73. package/lib/core/store/normalize.js +22 -4
  74. package/lib/core/store/preflightStore.js +19 -5
  75. package/lib/core/store/workspace.js +17 -1
  76. package/lib/core/taskReview/material.js +7 -0
  77. package/lib/core/taskReview/review.js +9 -2
  78. package/lib/server/api/manifest.js +51 -3
  79. package/lib/server/api/routes.js +131 -11
  80. package/lib/shared/acceptance.js +258 -18
  81. package/lib/shared/completionRecord.js +327 -0
  82. package/lib/shared/metrics.js +42 -0
  83. package/lib/shared/preflightInput.js +1 -1
  84. package/lib/shared/requirementSource.js +635 -0
  85. package/lib/shared/retrospective.js +286 -0
  86. package/lib/shared/reviewCandidate.js +308 -0
  87. package/lib/shared/reworkHistory.js +81 -0
  88. package/package.json +3 -2
  89. package/skills/p3/SKILL.md +9 -181
  90. package/dist/web/assets/ImprovementDialog-kQaVBGWH.js +0 -1
  91. package/dist/web/assets/Outputs-_nU_p3nu.js +0 -1
  92. package/dist/web/assets/RequestStatus-RG-OVQYY.js +0 -1
  93. package/dist/web/assets/Tabs-ew9i5SKX.js +0 -1
  94. package/dist/web/assets/TagInput-BtlJTF7i.js +0 -1
  95. package/dist/web/assets/TaskDrawer-DW8GyJqI.js +0 -6
  96. package/dist/web/assets/_requestId-6Nb727dD.js +0 -1
  97. package/dist/web/assets/_requestId-BykTgPax.js +0 -1
  98. package/dist/web/assets/appCtx-CxDdXABS.js +0 -1
  99. package/dist/web/assets/archive-Ckh295Xe.js +0 -1
  100. package/dist/web/assets/board-BVAIjK-Y.js +0 -1
  101. package/dist/web/assets/done-BGfA-3MA.js +0 -1
  102. package/dist/web/assets/draft-CfJeyLOl.js +0 -1
  103. package/dist/web/assets/index-CgRU744I.css +0 -2
  104. package/dist/web/assets/index-DacQ0yl4.js +0 -12
  105. package/dist/web/assets/new-DVygWvVc.js +0 -1
  106. package/dist/web/assets/outputs-B6xDsLZf.js +0 -1
  107. package/dist/web/assets/preflightInput-BAeEJYUK.js +0 -2
  108. package/dist/web/assets/preload-helper-DyCqp21K.js +0 -1
  109. package/dist/web/assets/release-notes-CCpzyiNf.js +0 -5
  110. package/dist/web/assets/requestData-D5vBnuMh.js +0 -1
  111. package/dist/web/assets/routes-Q91zvNc0.js +0 -4
  112. package/dist/web/assets/settings-BzRgcmUm.js +0 -1
  113. package/dist/web/assets/workTarget-C9c57JAO.js +0 -30
@@ -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,6 +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";
2
- import { acceptanceStatus } from "../shared/acceptance.js";
3
+ import { acceptanceStatus, basisDetail, basisLabel, EVIDENCE_BASIS_KINDS, EVIDENCE_BASIS_LABEL, evidenceBasisOf } from "../shared/acceptance.js";
3
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";
4
7
  import { supersededWarnings } from "../core/supersede.js";
5
8
  import { table } from "./format.js";
6
9
  import { taskWork } from "../core/workTargets.js";
@@ -56,16 +59,31 @@ export function formatAcceptance(task, { emptyLine = true } = {}) {
56
59
  const acc = acceptanceStatus(task);
57
60
  if (!acc)
58
61
  return emptyLine ? ["受け入れ基準なし"] : [];
59
- const lines = [`受け入れ基準(${acc.met}/${acc.total} を満たした・作業した側の申告):`];
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
+ };
60
74
  for (const i of acc.items) {
61
- lines.push(` ${i.id} ${i.text}`, ` ${STATE_MARK[i.state]}`);
75
+ lines.push(` ${i.id} ${i.text}`, ` ${STATE_MARK[i.state]}`, ...sourceLine(i.id));
76
+ if (i.evidence)
77
+ lines.push(...basisLines(i.evidence));
62
78
  if (i.evidence?.evidence)
63
79
  lines.push(...i.evidence.evidence.split("\n").map((l) => ` ${l}`));
64
80
  if (i.state === "stale" && i.evidence)
65
81
  lines.push(` (記録したときの基準: ${i.evidence.criterionText})`);
66
82
  }
67
83
  for (const e of acc.orphans)
68
- lines.push(` ${e.criterionId} (基準は消されています: ${e.criterionText})`, ` ${STATE_MARK[e.result]}`, ...(e.evidence ? e.evidence.split("\n").map((l) => ` ${l}`) : []));
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}: 対応先不明)`);
69
87
  if (acc.shortfalls.length)
70
88
  lines.push("不足:", ...acc.shortfalls.map((s) => ` - ${s}`));
71
89
  return lines;
@@ -83,6 +101,9 @@ export function briefTask(ctx, task, marks) {
83
101
  item.acceptanceCriteria = task.acceptanceCriteria;
84
102
  if (task.acceptanceEvidence?.length)
85
103
  item.acceptanceEvidence = task.acceptanceEvidence;
104
+ // 基準ごとの要求の出典と確認(あるときだけ)
105
+ if (task.acceptanceSources?.length)
106
+ item.acceptanceSources = task.acceptanceSources;
86
107
  if (task.acceptanceProblems?.length)
87
108
  item.acceptanceProblems = task.acceptanceProblems;
88
109
  // 停止の今の値と読み取りの問題(履歴は省く)
@@ -93,7 +114,65 @@ export function briefTask(ctx, task, marks) {
93
114
  // 着手先: 作業先のリポジトリとそのブランチ(作業先なしは repo: null)
94
115
  // 基準・証拠の状態(基準なしのタスクでは省く)
95
116
  const acceptance = acceptanceStatus(task);
96
- return { item, work: taskWork(ctx.ws, task), ...taskExtras(ctx, task, marks), ...(acceptance ? { acceptance } : {}) };
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
+ ];
97
176
  }
98
177
  export function formatBriefTask(view) {
99
178
  const { item, work, dependencies, warnings } = view;
@@ -115,6 +194,8 @@ export function formatBriefTask(view) {
115
194
  if (item.record)
116
195
  lines.push("", "## 変更の記録", item.record);
117
196
  lines.push("", ...formatAcceptance(item));
197
+ if (view.completion)
198
+ lines.push("", ...formatCompletion(view.completion));
118
199
  return lines.join("\n");
119
200
  }
120
201
  export function briefRequest(ctx, r, issue) {
@@ -132,7 +213,37 @@ export function briefRequest(ctx, r, issue) {
132
213
  .tasksOf(r.id)
133
214
  .list()
134
215
  .map((t) => ({ id: t.id, ref: t.ref, title: t.title, status: t.status, repo: t.repo, ...(t.block ? { blocked: true } : {}) }));
135
- return { item, branches, tasks, ...(issue ? { issue } : {}) };
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;
136
247
  }
137
248
  /** 親子の行(祖先と直下の子。無ければ何も出さない) */
138
249
  export function formatFamily(f) {
@@ -157,6 +268,8 @@ export function formatBriefRequest(view) {
157
268
  ...(branchLine ? [] : names.map((n) => ` branch ${n}: ${branches[n].branch}`)),
158
269
  ...(family ? formatFamily(family) : []),
159
270
  item.body.trim() ? `\n${item.body.trim()}` : "",
271
+ ...(view.requirement ? ["", ...formatRequirement(view.requirement)] : []),
272
+ ...(view.completion ? ["", ...formatCompletion(view.completion)] : []),
160
273
  "",
161
274
  `タスク (${tasks.length}):`,
162
275
  table(tasks.map((t) => [` ${t.id}`, t.status, t.repo ?? "(作業先なし)", `${t.title}${t.blocked ? " ⏸停止" : ""}`])) || " (なし)",
@@ -11,9 +11,12 @@ import { table } from "./format.js";
11
11
  import { taskRepo } from "../shared/workTarget.js";
12
12
  import { addRepoOutputs, parseRepoOutput, repoArg } from "../core/workTargets.js";
13
13
  import { briefTask, formatAcceptance, formatBlock, formatBriefTask, taskExtras } from "./showView.js";
14
+ import { formatReview } from "./revisitCommands.js";
15
+ import { taskReview } from "../core/reviewCandidates.js";
16
+ import { reviewSummary } from "../shared/reviewCandidate.js";
14
17
  import { UsageError } from "./project.js";
15
18
  import { NotFoundError } from "../core/store/collection.js";
16
- import { parseTaskAssignments, checkStatus, evidenceOps, readBody } from "./args.js";
19
+ import { basisFromOptions, parseTaskAssignments, checkStatus, evidenceOps, readBody } from "./args.js";
17
20
  import { ACCEPTANCE_RESULTS, acceptanceStatus, applyAcceptanceOps, isAcceptanceResult } from "../shared/acceptance.js";
18
21
  import { dependentsOf, formatEntity, indent, ambiguous, replacedBy, reopenedNote, warn, deps, workHint } from "./output.js";
19
22
  import { requestCommand } from "./requestCommands.js";
@@ -32,7 +35,7 @@ export async function taskCommand(cmd, env) {
32
35
  if (o.repo !== undefined && o.repo !== "none" && !ctx.ws.project.repos.some((r) => r.name === o.repo)) {
33
36
  throw new UsageError(`参照先「${o.repo}」は登録されていません(p3 repo ls)`);
34
37
  }
35
- const filter = { status: o.status?.split(","), area: o.area?.[0], q: o.q, repo: o.repo, blocked: o.blocked };
38
+ const filter = { status: o.status?.split(","), area: o.area?.[0], q: o.q, repo: o.repo, blocked: o.blocked, review: o.review };
36
39
  const tasks = listTasks(ctx, { ...filter, request: o.all ? undefined : requestArg(undefined) });
37
40
  const marks = supersededMarks(ctx.ws);
38
41
  const items = tasks.map((t) => (marks.has(t.ref) ? { ...t, superseded: marks.get(t.ref) } : t));
@@ -43,8 +46,8 @@ export async function taskCommand(cmd, env) {
43
46
  t.status,
44
47
  ...(multi ? [taskRepo(t) ?? "(なし)"] : []),
45
48
  t.title,
46
- [t.block ? `⏸停止 ${t.block.since.slice(0, 10)}: ${t.block.reason.split("\n")[0]}` : "", deps(t), replacedBy(t, marks)].filter(Boolean).join(" "),
47
- ])) || (o.blocked ? "止まっているタスクはありません" : "タスクはありません"));
49
+ [t.block ? `⏸停止 ${t.block.since.slice(0, 10)}: ${t.block.reason.split("\n")[0]}` : "", deps(t), replacedBy(t, marks), taskReview(ctx, t)?.state === "candidate" ? "※見直し候補" : ""].filter(Boolean).join(" "),
50
+ ])) || (o.blocked ? "止まっているタスクはありません" : o.review ? "見直しが必要(候補)のタスクはありません" : "タスクはありません"));
48
51
  }
49
52
  case "show": {
50
53
  if (o.archived)
@@ -57,15 +60,21 @@ export async function taskCommand(cmd, env) {
57
60
  return requestCommand(ctx, out, ["show", ref], o, actor, requestArg, expectedRev);
58
61
  const item = ctx.ws.requireTask(ref);
59
62
  const marks = supersededMarks(ctx.ws);
63
+ const review = taskReview(ctx, item);
60
64
  if (o.brief) {
61
- const view = briefTask(ctx, item, marks);
62
- return out.result(view, () => formatBriefTask(view));
65
+ // 見直しの概要は候補のときだけ(記録なし・差分なしは短い出力に出さない)
66
+ const view = { ...briefTask(ctx, item, marks), ...(review?.state === "candidate" ? { review: reviewSummary(review) } : {}) };
67
+ return out.result(view, () => [formatBriefTask(view), ...(review?.state === "candidate" ? ["", ...formatReview(review)] : [])].join("\n"));
63
68
  }
64
69
  const file = relative(cwd, split(ref).col.path(item.id));
65
70
  const { superseded, dependencies, warnings } = taskExtras(ctx, item, marks);
66
71
  const dependents = dependentsOf(ctx, item).map((t) => ({ ref: t.ref, title: t.title, status: t.status }));
67
72
  const acceptance = acceptanceStatus(item) ?? null;
68
- return out.result({ item, file, superseded, dependencies, dependents, warnings, acceptance }, () => [superseded.length ? `※ 置き換えられています: ${superseded.map((m) => `${m.from}${m.note ? `(${m.note})` : ""}`).join(" / ")}\n` : "", formatEntity(ctx, item, file)].join(""));
73
+ return out.result({ item, file, superseded, dependencies, dependents, warnings, acceptance, review: review ?? null }, () => [
74
+ superseded.length ? `※ 置き換えられています: ${superseded.map((m) => `${m.from}${m.note ? `(${m.note})` : ""}`).join(" / ")}\n` : "",
75
+ formatEntity(ctx, item, file),
76
+ review ? `\n\n${formatReview(review).join("\n")}` : "",
77
+ ].join(""));
69
78
  }
70
79
  case "find":
71
80
  case "resolve": {
@@ -118,14 +127,16 @@ export async function taskCommand(cmd, env) {
118
127
  const add = o["repo-output"].map((x) => parseRepoOutput(ctx.ws, x));
119
128
  patch.repoOutputs = addRepoOutputs(patch.repoOutputs ?? col.require(tid).repoOutputs ?? [], add);
120
129
  }
121
- // 受け入れ基準を足す(--criterion)・証拠を残す(--evidence / --evidence-file)
130
+ // 受け入れ基準を足す(--criterion)・証拠を残す(--evidence / --evidence-file / --evidence-json)
122
131
  const acceptance = [...(o.criterion ?? []).map((text) => ({ op: "add", text })), ...evidenceOps(o)];
123
132
  if (!Object.keys(patch).length && !acceptance.length)
124
- throw new UsageError("キー=値 を指定してください(受け入れ基準は --criterion、証拠は --evidence / --evidence-file)");
133
+ throw new UsageError("キー=値 を指定してください(受け入れ基準は --criterion、証拠は --evidence / --evidence-file / --evidence-json)");
125
134
  const r = await updateTask(ctx, ref.split("/")[0], tid, { ...patch, ...(acceptance.length ? { acceptance } : {}) }, { expectedRev, actor });
126
135
  const { task: next, warnings } = r;
127
136
  warn(warnings);
128
137
  checkClearedNote(r.checkCleared);
138
+ completionSkippedNote(r.completionSkipped);
139
+ completionSkippedNote(r.reworkSkipped);
129
140
  const reopened = reopenedNote(r.reopened, r.reopenedAncestors);
130
141
  const keys = [...Object.keys(patch), ...(acceptance.length ? ["acceptance"] : [])];
131
142
  return out.result({ ...next, ...(warnings.length ? { warnings } : {}), ...(reopened ? { reopened } : {}), ...(r.reopenedAncestors ? { reopenedAncestors: r.reopenedAncestors } : {}), ...(r.checkCleared ? { checkCleared: r.checkCleared } : {}) }, () => [`更新: ${next.ref} (rev ${next.rev}) ${keys.join(", ")}`, "repo" in patch ? workHint(ctx, next) : ""].filter(Boolean).join("\n"));
@@ -149,12 +160,14 @@ export async function taskCommand(cmd, env) {
149
160
  // リポジトリごとの成果物(最後のタスクに、関係するリポジトリの PR を全部残せる)
150
161
  if (o["repo-output"]?.length)
151
162
  patch.repoOutputs = addRepoOutputs(cur.repoOutputs ?? [], o["repo-output"].map((x) => parseRepoOutput(ctx.ws, x)));
152
- // 完了と同時に項目ごとの証拠を残す(--evidence / --evidence-file。不足があっても完了は拒まない)
163
+ // 完了と同時に項目ごとの証拠を残す(--evidence / --evidence-file / --evidence-json。不足があっても完了は拒まない)
153
164
  const acceptance = evidenceOps(o);
154
165
  const r = await updateTask(ctx, cur.request, tid, { ...patch, ...(acceptance.length ? { acceptance } : {}) }, { expectedRev, actor });
155
166
  const { task: next, warnings } = r;
156
167
  warn(warnings);
157
168
  checkClearedNote(r.checkCleared);
169
+ completionSkippedNote(r.completionSkipped);
170
+ completionSkippedNote(r.reworkSkipped);
158
171
  const reopened = reopenedNote(r.reopened, r.reopenedAncestors);
159
172
  const short = status === "done" ? acceptanceStatus(next)?.shortfalls : undefined;
160
173
  if (short?.length)
@@ -164,7 +177,9 @@ export async function taskCommand(cmd, env) {
164
177
  case "check": {
165
178
  const ref = taskArg(args[0]);
166
179
  const { tid } = split(ref);
167
- const { task: next } = await updateTask(ctx, ref.split("/")[0], tid, { checked: !o.off }, { expectedRev, actor });
180
+ const { task: next, completionSkipped, reworkSkipped } = await updateTask(ctx, ref.split("/")[0], tid, { checked: !o.off }, { expectedRev, actor });
181
+ completionSkippedNote(completionSkipped);
182
+ completionSkippedNote(reworkSkipped);
168
183
  return out.result(next, () => `${next.ref} ${o.off ? "の済みを外しました" : "を済みにしました"}`);
169
184
  }
170
185
  case "block":
@@ -223,6 +238,11 @@ function checkClearedNote(msg) {
223
238
  if (msg)
224
239
  process.stderr.write(`${msg}\n`);
225
240
  }
241
+ /** 完了の記録・手戻りの履歴を足せなかった(壊れた記録)ことを知らせる */
242
+ export function completionSkippedNote(msg) {
243
+ if (msg)
244
+ process.stderr.write(`${msg}\n`);
245
+ }
226
246
  /** 基準・証拠の操作を当てて、今の基準と不足を出す */
227
247
  async function applyAcceptance({ ctx, out, actor, expectedRev, split }, ref, acceptance) {
228
248
  const { tid } = split(ref);
@@ -341,8 +361,9 @@ async function draftCriteriaCommand({ ctx, out, args, o, requestArg }, head, key
341
361
  return out.result({ request: rid, run: run.id, key, criteria: saved.acceptanceCriteria ?? [], problems: [] }, () => show(saved));
342
362
  }
343
363
  /**
344
- * evidence <タスク> <ID> <結果> [--body 本文|- | --file 本文.md] 1項目の証拠を残す(再記録は置き換え)
364
+ * evidence <タスク> <ID> <結果> [--body 本文|- | --file 本文.md] [--basis 種類 ...] 1項目の証拠を残す(再記録は置き換え)
345
365
  * evidence <タスク> --file 証拠.md|- 見出し「## <ID> <結果>」ごとにまとめて残す
366
+ * evidence <タスク> --evidence-json 証拠.json|- 根拠つきでまとめて残す
346
367
  * evidence <タスク> rm <ID> [...] 証拠を消す
347
368
  */
348
369
  async function evidenceCommand(env) {
@@ -355,10 +376,14 @@ async function evidenceCommand(env) {
355
376
  return applyAcceptance(env, ref, rest.map((id) => ({ op: "unrecord", id })));
356
377
  }
357
378
  if (first === undefined) {
358
- if (o.file === undefined)
359
- throw new UsageError("使い方: p3 evidence <タスク> <ID> <結果> [--body 本文|- | --file 本文.md](まとめてなら --file 証拠.md)");
360
- return applyAcceptance(env, ref, evidenceOps({ "evidence-file": o.file }));
379
+ if (o.file === undefined && o["evidence-json"] === undefined)
380
+ throw new UsageError("使い方: p3 evidence <タスク> <ID> <結果> [--body 本文|- | --file 本文.md] [--basis 種類](まとめてなら --file 証拠.md か --evidence-json 証拠.json)");
381
+ if (o.basis !== undefined)
382
+ throw new UsageError("まとめて残すときの根拠は、--evidence-json の各項目の basis に書いてください(--basis は1項目のときだけ)");
383
+ return applyAcceptance(env, ref, evidenceOps({ "evidence-file": o.file, "evidence-json": o["evidence-json"] }));
361
384
  }
385
+ if (o["evidence-json"] !== undefined)
386
+ throw new UsageError("--evidence-json はまとめて残すときだけ使えます(p3 evidence <タスク> --evidence-json 証拠.json)");
362
387
  const result = rest[0];
363
388
  if (!isAcceptanceResult(result))
364
389
  throw new UsageError(`結果は ${ACCEPTANCE_RESULTS.join(" / ")} のどれかです: p3 evidence <タスク> ${first} <結果>`);
@@ -375,7 +400,8 @@ async function evidenceCommand(env) {
375
400
  throw new UsageError(`証拠のファイルが読めません: ${o.file}`);
376
401
  }
377
402
  }
378
- return applyAcceptance(env, ref, [{ op: "record", id: first, result, evidence }]);
403
+ const basis = basisFromOptions(o);
404
+ return applyAcceptance(env, ref, [{ op: "record", id: first, result, evidence, ...(basis ? { basis } : {}) }]);
379
405
  }
380
406
  // --- アーカイブしたタスク(--archived を付けたときだけ。読むだけ) ------------------------------------
381
407
  /** ls --archived: 今の要望(--req)のアーカイブの一覧。通常の絞り込み・--all とは混ぜない */
@@ -1,4 +1,7 @@
1
+ import { resolve } from "node:path";
1
2
  import { THEMES } from "../shared/types.js";
3
+ import { resolveMachineSettings } from "../core/machineSettings.js";
4
+ import { originText, resolveHostPaths } from "../core/preflight/hostPaths.js";
2
5
  import { describeSettings, parseSettingChange, SETTING_KEY_LIST, SettingsInputError, writeMachineSettings } from "../core/machineSettingsEdit.js";
3
6
  import { loadUserConfig, UserConfigError, userConfigPath } from "../core/userConfig.js";
4
7
  import { readTheme, ThemeInputError, writeTheme } from "../core/userTheme.js";
@@ -8,7 +11,49 @@ const USAGE = [
8
11
  `p3 user-config set キー=値 ... ui.theme=${THEMES.join("|")} / ${SETTING_KEY_LIST.filter((k) => k !== "codex.pathMap").join(" ")}(キー= で消す)`,
9
12
  "p3 user-config set codex.pathMap+=<このマシンのパス>=<Docker デーモンから見たパス> パスの対応を足す",
10
13
  "p3 user-config set codex.pathMap-=<このマシンのパス> パスの対応を外す(codex.pathMap= で全部)",
14
+ "p3 user-config paths <このマシンのパス> ... Docker にマウントするときのホストのパスと決め方(変えない)",
11
15
  ].join("\n");
16
+ /** 動いている場所の説明(このマシンの CLI の出力だけ。共有の記録には残さない) */
17
+ function environmentText(r) {
18
+ const e = r.environment;
19
+ if (e.kind === "direct")
20
+ return "コンテナの外(パスはそのまま渡します。手で書いた対応があればそれを使います)";
21
+ if (e.kind === "container")
22
+ return `コンテナの中(自分のコンテナ ${e.containerId.slice(0, 12)} を Docker で確かめました。マウントから決めます)`;
23
+ return `コンテナの中(自分のコンテナを確かめられません: ${e.detail})`;
24
+ }
25
+ /**
26
+ * p3 user-config paths: Preflight・描画と同じ設定と決め方で、このマシンのパスが Docker のホストのどこに当たるかを見せる。
27
+ * 読むだけで、個人設定とデータは変えない。実際のパスはこの出力だけに出す
28
+ */
29
+ async function pathsCommand(paths, env, path) {
30
+ if (!paths.length)
31
+ throw new UsageError("p3 user-config paths <このマシンのパス> ...(例: p3 user-config paths . ~/p3-data/myapp)");
32
+ const user = await loadUserConfig(path).catch((e) => {
33
+ if (e instanceof UserConfigError)
34
+ throw new UsageError(e.message);
35
+ throw e;
36
+ });
37
+ let pathMap;
38
+ try {
39
+ pathMap = resolveMachineSettings(user, env).codex.pathMap;
40
+ }
41
+ catch (e) {
42
+ throw new UsageError(e.message);
43
+ }
44
+ const locals = paths.map((p) => resolve(p));
45
+ const r = await resolveHostPaths(locals, { pathMap });
46
+ const lines = [`p3 が動いている場所: ${environmentText(r)}`, ""];
47
+ for (const p of r.paths) {
48
+ lines.push(p.local);
49
+ if (p.ok)
50
+ lines.push(` → ${p.host} ${originText(p, pathMap.length)}${p.origin === "auto" && p.destination ? `(マウント ${p.destination})` : ""}`);
51
+ else
52
+ lines.push(` × 決められません: ${p.detail}`, ` 次にすること: ${p.next}`);
53
+ }
54
+ lines.push("", r.ok ? "全部決まりました(Preflight と描画でこのとおりにマウントします)" : "決まらないものがあります。Preflight と描画は、このフォルダを使うときコンテナを起こさずに止まります");
55
+ return { data: r, text: lines.join("\n") };
56
+ }
12
57
  /**
13
58
  * p3 user-config [set ...]。個人設定(このマシン・この人)のうち、画面のテーマとマシンごとの設定(codex / preflight / serve)を
14
59
  * 見せ・変える。プロジェクトの登録は p3 project、プロジェクトの設定は p3 config。プロジェクトを決める前に動く。
@@ -35,6 +80,8 @@ export async function userConfigCommand(args, env = process.env) {
35
80
  ].join("\n");
36
81
  return { data: { ui: { theme }, settings: rows, ...(error ? { error } : {}), path }, text };
37
82
  }
83
+ if (sub === "paths")
84
+ return pathsCommand(pairs, env, path);
38
85
  if (sub !== "set" || !pairs.length)
39
86
  throw new UsageError(USAGE);
40
87
  let theme;
@@ -0,0 +1,46 @@
1
+ import { execFile } from "node:child_process";
2
+ /**
3
+ * 完了の記録に残す参照先の取得(shared/completionRecord.ts の RefCapture)。登録された参照先ごとに、このマシンのパスで
4
+ * HEAD のコミットと未コミットの変更の有無を取る。取れなければ理由を残す(推測で埋めない)。このマシンのパスは残さない。
5
+ * 書く前(ロックの外)に取るので、取得時刻を参照先ごとに残す
6
+ */
7
+ const UNAVAILABLE = {
8
+ unregistered: "このマシンのパスが登録されていません",
9
+ missing: "登録したパスがありません",
10
+ notdir: "登録したパスがフォルダではありません",
11
+ };
12
+ function git(local, args) {
13
+ return new Promise((resolve) => {
14
+ execFile("git", ["-C", local, ...args], { encoding: "utf8", timeout: 15_000, maxBuffer: 16 * 1024 * 1024 }, (err, stdout, stderr) => resolve(err ? { ok: false, err: `${stderr || err.message}` } : { ok: true, out: stdout }));
15
+ });
16
+ }
17
+ /** git の失敗の理由(このマシンのパスを伏せて1行に) */
18
+ const reasonOf = (err, local) => (err.split("\n").find((l) => l.trim()) ?? "git の実行に失敗しました").split(local).join("<参照先>").trim().slice(0, 300);
19
+ export async function captureRef(r, now = () => new Date().toISOString()) {
20
+ if (r.status !== "ok" || !r.local) {
21
+ const state = r.status === "ok" ? "unregistered" : r.status;
22
+ return { name: r.name, state, at: now(), reason: UNAVAILABLE[state] };
23
+ }
24
+ const local = r.local;
25
+ const inside = await git(local, ["rev-parse", "--is-inside-work-tree"]);
26
+ if (!inside.ok) {
27
+ if (/not a git repository/i.test(inside.err))
28
+ return { name: r.name, state: "not_git", at: now(), reason: "git のリポジトリではありません" };
29
+ return { name: r.name, state: "failed", at: now(), reason: reasonOf(inside.err, local) };
30
+ }
31
+ const head = await git(local, ["rev-parse", "HEAD"]);
32
+ if (!head.ok)
33
+ return { name: r.name, state: "failed", at: now(), reason: /unknown revision|ambiguous argument/i.test(head.err) ? "コミットがありません" : reasonOf(head.err, local) };
34
+ const status = await git(local, ["status", "--porcelain", "--", "."]);
35
+ return {
36
+ name: r.name,
37
+ state: "ok",
38
+ commit: head.out.trim(),
39
+ ...(status.ok ? { dirty: status.out.trim() !== "" } : { reason: `未コミットの変更を確かめられません: ${reasonOf(status.err, local)}` }),
40
+ at: now(),
41
+ };
42
+ }
43
+ /** 登録された参照先を全部取る(並べて実行) */
44
+ export function captureRefs(refs) {
45
+ return Promise.all(refs.map((r) => captureRef(r)));
46
+ }