@infodb/p3 0.10.0 → 0.12.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 (104) hide show
  1. package/README.md +6 -1
  2. package/dist/web/assets/ImprovementDialog-kQaVBGWH.js +1 -0
  3. package/dist/web/assets/Outputs-_nU_p3nu.js +1 -0
  4. package/dist/web/assets/{RequestStatus-DGaoQoIa.js → RequestStatus-RG-OVQYY.js} +1 -1
  5. package/dist/web/assets/{Tabs-D16MqQxu.js → Tabs-ew9i5SKX.js} +1 -1
  6. package/dist/web/assets/TagInput-BtlJTF7i.js +1 -0
  7. package/dist/web/assets/TaskDrawer-DW8GyJqI.js +6 -0
  8. package/dist/web/assets/_requestId-6Nb727dD.js +1 -0
  9. package/dist/web/assets/_requestId-BykTgPax.js +1 -0
  10. package/dist/web/assets/appCtx-CxDdXABS.js +1 -0
  11. package/dist/web/assets/archive-Ckh295Xe.js +1 -0
  12. package/dist/web/assets/board-BVAIjK-Y.js +1 -0
  13. package/dist/web/assets/done-BGfA-3MA.js +1 -0
  14. package/dist/web/assets/index-CgRU744I.css +2 -0
  15. package/dist/web/assets/index-DacQ0yl4.js +12 -0
  16. package/dist/web/assets/{new-ChFzBoL2.js → new-DVygWvVc.js} +1 -1
  17. package/dist/web/assets/outputs-B6xDsLZf.js +1 -0
  18. package/dist/web/assets/preload-helper-DyCqp21K.js +1 -0
  19. package/dist/web/assets/quality-Pu6EISAM.js +1 -0
  20. package/dist/web/assets/release-notes-CCpzyiNf.js +5 -0
  21. package/dist/web/assets/requestData-D5vBnuMh.js +1 -0
  22. package/dist/web/assets/routes-Q91zvNc0.js +4 -0
  23. package/dist/web/assets/settings-BzRgcmUm.js +1 -0
  24. package/dist/web/assets/taskReview-_WCgnQit.js +1 -0
  25. package/dist/web/assets/workTarget-C9c57JAO.js +30 -0
  26. package/dist/web/index.html +4 -4
  27. package/docs/architecture.md +392 -3
  28. package/docs/development.md +1 -1
  29. package/docs/how-to-use.md +261 -5
  30. package/docs/installation.md +5 -5
  31. package/lib/cli/args.js +45 -0
  32. package/lib/cli/help.js +43 -1
  33. package/lib/cli/main.js +42 -4
  34. package/lib/cli/output.js +9 -1
  35. package/lib/cli/preflightCommands.js +7 -1
  36. package/lib/cli/project.js +3 -0
  37. package/lib/cli/qualityCommands.js +163 -0
  38. package/lib/cli/readOnly.js +2 -0
  39. package/lib/cli/requestCommands.js +219 -14
  40. package/lib/cli/showView.js +69 -3
  41. package/lib/cli/taskCommands.js +312 -17
  42. package/lib/cli/taskReviewCommands.js +178 -0
  43. package/lib/core/context.js +7 -1
  44. package/lib/core/milestoneReview/code.js +129 -0
  45. package/lib/core/milestoneReview/material.js +148 -0
  46. package/lib/core/milestoneReview/mockReviewer.js +28 -0
  47. package/lib/core/milestoneReview/review.js +325 -0
  48. package/lib/core/milestoneReview/service.js +214 -0
  49. package/lib/core/milestoneReview/store.js +176 -0
  50. package/lib/core/ops.js +9 -2
  51. package/lib/core/preflight/carryover.js +1 -1
  52. package/lib/core/preflight/codexEngine.js +20 -6
  53. package/lib/core/preflight/engine.js +6 -0
  54. package/lib/core/preflight/instructions.js +18 -1
  55. package/lib/core/preflight/mockEngine.js +4 -0
  56. package/lib/core/preflight/service.js +45 -4
  57. package/lib/core/projectRegistry.js +3 -3
  58. package/lib/core/quality.js +21 -0
  59. package/lib/core/qualityImprovement.js +221 -0
  60. package/lib/core/requestOps.js +101 -6
  61. package/lib/core/reviewRuns.js +205 -0
  62. package/lib/core/store/archivedTasks.js +74 -0
  63. package/lib/core/store/collection.js +12 -2
  64. package/lib/core/store/normalize.js +43 -2
  65. package/lib/core/store/preflightStore.js +9 -1
  66. package/lib/core/store/projectFile.js +18 -1
  67. package/lib/core/store/workspace.js +122 -14
  68. package/lib/core/taskReview/material.js +452 -0
  69. package/lib/core/taskReview/mockReviewer.js +30 -0
  70. package/lib/core/taskReview/paths.js +15 -0
  71. package/lib/core/taskReview/review.js +305 -0
  72. package/lib/core/taskReview/service.js +187 -0
  73. package/lib/core/taskReview/store.js +214 -0
  74. package/lib/server/api/manifest.js +74 -5
  75. package/lib/server/api/milestoneReviewRoutes.js +70 -0
  76. package/lib/server/api/routes.js +164 -20
  77. package/lib/server/api/taskReviewRoutes.js +66 -0
  78. package/lib/server/server.js +2 -2
  79. package/lib/shared/acceptance.js +378 -0
  80. package/lib/shared/milestoneGoals.js +57 -0
  81. package/lib/shared/milestoneReview.js +27 -0
  82. package/lib/shared/quality.js +391 -0
  83. package/lib/shared/qualityImprovement.js +1 -0
  84. package/lib/shared/qualityTemplates.js +31 -0
  85. package/lib/shared/taskBlock.js +142 -0
  86. package/lib/shared/taskReview.js +56 -0
  87. package/package.json +1 -1
  88. package/skills/p3/SKILL.md +31 -2
  89. package/dist/web/assets/Outputs-B4Tr7JzU.js +0 -1
  90. package/dist/web/assets/TagInput-pSYxm4bz.js +0 -1
  91. package/dist/web/assets/TaskDrawer-1Ev3RpRV.js +0 -3
  92. package/dist/web/assets/_requestId-BKhn019m.js +0 -1
  93. package/dist/web/assets/_requestId-Btpvuu7-.js +0 -30
  94. package/dist/web/assets/appCtx-D_Iaoh2e.js +0 -1
  95. package/dist/web/assets/board-DeHdxbN4.js +0 -1
  96. package/dist/web/assets/done-BFaHGt03.js +0 -1
  97. package/dist/web/assets/index-BF1xMdJo.css +0 -2
  98. package/dist/web/assets/index-CDWcKy1L.js +0 -12
  99. package/dist/web/assets/preload-helper-hSId95YD.js +0 -1
  100. package/dist/web/assets/release-notes-BWNDFDkH.js +0 -3
  101. package/dist/web/assets/requestData-B_320uxL.js +0 -1
  102. package/dist/web/assets/routes-BBD464IS.js +0 -3
  103. package/dist/web/assets/settings-D7PPrGjT.js +0 -1
  104. package/dist/web/assets/workTarget-Cijqq4yH.js +0 -1
@@ -100,6 +100,9 @@ export class MarkdownCollection {
100
100
  const item = this.opts.normalize(data, body, id);
101
101
  const known = new Set(["body", ...this.opts.keyOrder, ...(this.opts.derived ?? []), ...Object.keys(item)]);
102
102
  const extra = Object.fromEntries(Object.entries(data).filter(([k]) => !known.has(k)));
103
+ for (const k of this.opts.keepRaw?.(item) ?? [])
104
+ if (k in data)
105
+ extra[k] = data[k];
103
106
  return { item, extra };
104
107
  }
105
108
  catch (e) {
@@ -151,9 +154,10 @@ export class MarkdownCollection {
151
154
  const { body, ...rest } = item;
152
155
  const skip = new Set(["body", ...(this.opts.derived ?? [])]);
153
156
  const ordered = {};
157
+ // extra に知っているキーがあるのは keepRaw のとき(元の値のまま書く)
154
158
  for (const k of this.opts.keyOrder)
155
159
  if (!skip.has(k))
156
- ordered[k] = rest[k];
160
+ ordered[k] = k in extra ? extra[k] : rest[k];
157
161
  for (const [k, v] of Object.entries(rest))
158
162
  if (!(k in ordered) && !skip.has(k))
159
163
  ordered[k] = v;
@@ -196,17 +200,23 @@ export class MarkdownCollection {
196
200
  }
197
201
  /**
198
202
  * 部分更新。expectedRev を渡すと楽観ロック(AI が古い状態を元に上書きするのを防ぐ)。
203
+ * patch に関数を渡すと、直前に読み直した今の値から patch を作る(基準の操作のように、今の値に当てる変更)。関数が投げたら書かない
199
204
  */
200
205
  async update(id, patch, opts = {}) {
201
206
  // 外部での編集を取りこぼさないよう、更新の直前にディスクから読み直す。
202
207
  // この版が知らない項目(新しい版の p3 が書いた項目)は消さずに書き戻す(古い版の更新で親子などが消えないように)
203
208
  const r = await this.read(id);
204
209
  this.apply(id, r);
205
- const extra = "item" in r ? r.extra : {};
210
+ const extra = "item" in r ? { ...r.extra } : {};
206
211
  const cur = this.require(id);
207
212
  if (opts.expectedRev !== undefined && opts.expectedRev !== cur.rev) {
208
213
  throw new ConflictError(id, opts.expectedRev, cur.rev);
209
214
  }
215
+ if (typeof patch === "function")
216
+ patch = patch(cur);
217
+ // patch で書き換えるキーは、元の値を残す対象(keepRaw・知らない項目)から外す
218
+ for (const k of Object.keys(patch))
219
+ delete extra[k];
210
220
  const merged = {
211
221
  ...cur,
212
222
  ...patch,
@@ -1,3 +1,6 @@
1
+ import { ACCEPTANCE_KEYS, readAcceptance } from "../../shared/acceptance.js";
2
+ import { BLOCK_KEYS, readBlock } from "../../shared/taskBlock.js";
3
+ import { qualityVersion, readQuality } from "../../shared/quality.js";
1
4
  import { repoNameProblem } from "../../shared/repos.js";
2
5
  import { isPreflightRunner } from "../../shared/preflightRunner.js";
3
6
  import { isTaskStatus, RELATION_TYPES, REQUEST_STATUSES } from "../../shared/types.js";
@@ -38,6 +41,8 @@ export const normalizeTaskIn = (requestId) => (d, body, id) => ({
38
41
  doneAt: d.doneAt ? iso(d.doneAt) : undefined,
39
42
  checkedAt: d.checkedAt ? iso(d.checkedAt) : undefined,
40
43
  record: str(d.record)?.trim() || undefined,
44
+ ...readAcceptance(d),
45
+ ...readBlock(d),
41
46
  relations: normalizeRelations(d.relations),
42
47
  rev: num(d.rev) ?? 1,
43
48
  createdAt: iso(d.createdAt),
@@ -45,9 +50,13 @@ export const normalizeTaskIn = (requestId) => (d, body, id) => ({
45
50
  updatedBy: str(d.updatedBy),
46
51
  body,
47
52
  });
53
+ /** タスクのうちファイルに書かないキー(場所から決まるもの・読んだときの問題) */
54
+ export const TASK_DERIVED = ["request", "ref", "acceptanceProblems", "blockProblems"];
55
+ /** 基準・証拠が壊れていたら、関係のない更新ではファイルの元の値のまま書き戻す(shared/acceptance.ts) */
56
+ export const taskKeepRaw = (t) => [...(t.acceptanceProblems?.length ? ACCEPTANCE_KEYS : []), ...(t.blockProblems?.length ? BLOCK_KEYS : [])];
48
57
  export const TASK_KEY_ORDER = [
49
58
  "id", "title", "status", "repo", "labels", "areas", "outputs", "repoOutputs", "record",
50
- "relations", "rev", "createdAt", "startedAt", "doneAt", "checkedAt", "updatedAt", "updatedBy",
59
+ "acceptanceCriteria", "acceptanceEvidence", "acceptanceSeq", "block", "blockHistory", "relations", "rev", "createdAt", "startedAt", "doneAt", "checkedAt", "updatedAt", "updatedBy",
51
60
  ];
52
61
  export function normalizeRequest(d, body, id) {
53
62
  const status = str(d.status);
@@ -84,6 +93,26 @@ function runnerOf(v) {
84
93
  return {};
85
94
  return isPreflightRunner(raw) ? { runner: raw } : { invalidRunner: raw };
86
95
  }
96
+ /**
97
+ * マイルストーンの目的と予定機能(無い古いファイルは空として読む)。予定機能は id と text のある項目だけを読み、重複した id は
98
+ * 最初のものを残す(読めない項目は画面・CLI に出ず、次の保存で消える)
99
+ */
100
+ function milestoneGoalsOf(m) {
101
+ const purpose = typeof m.purpose === "string" && m.purpose.trim() ? m.purpose.replace(/\s+$/, "") : undefined;
102
+ const goals = [];
103
+ if (Array.isArray(m.goals)) {
104
+ for (const g of m.goals) {
105
+ if (!g || typeof g !== "object")
106
+ continue;
107
+ const { id, text } = g;
108
+ const gid = typeof id === "string" || typeof id === "number" ? String(id).trim() : "";
109
+ if (!gid || typeof text !== "string" || !text.trim() || goals.some((x) => x.id === gid))
110
+ continue;
111
+ goals.push({ id: gid, text: text.trim() });
112
+ }
113
+ }
114
+ return { ...(purpose ? { purpose } : {}), ...(goals.length ? { goals } : {}) };
115
+ }
87
116
  export function normalizeProject(d) {
88
117
  const preflight = (d.preflight ?? {});
89
118
  return {
@@ -93,12 +122,24 @@ export function normalizeProject(d) {
93
122
  milestones: Array.isArray(d.milestones)
94
123
  ? d.milestones
95
124
  .filter((m) => !!m && typeof m === "object" && !!m.id)
96
- .map((m) => ({ id: String(m.id), title: str(m.title) ?? String(m.id), due: date(m.due), done: m.done === true ? true : undefined }))
125
+ .map((m) => ({
126
+ id: String(m.id),
127
+ title: str(m.title) ?? String(m.id),
128
+ due: date(m.due),
129
+ done: m.done === true ? true : undefined,
130
+ ...milestoneGoalsOf(m),
131
+ }))
97
132
  : [],
98
133
  branchPattern: str(d.branchPattern) ?? "req/{id}-{slug}",
99
134
  preflight: { instructions: str(preflight.instructions) ?? "", ...runnerOf(preflight.runner) },
135
+ ...qualityOf(d.quality, normalizeRepos(d.repos).map((r) => r.name)),
100
136
  };
101
137
  }
138
+ /** 品質基準(無い・読めない・読めるを分ける。読めない値もそのまま版に入れ、書き換えない) */
139
+ function qualityOf(raw, repoNames) {
140
+ const quality = readQuality(raw, repoNames);
141
+ return { quality, qualityVersion: qualityVersion(quality, raw) };
142
+ }
102
143
  /**
103
144
  * project.yaml の repos。名前をキーにした対応(推奨)か、name を持つ項目の並び。名前が使えない項目・重複は読まない
104
145
  * (書き戻すときも p3 repo で変えた項目のほかは触らないので、ファイルからは消えない)。
@@ -1,6 +1,12 @@
1
1
  import { readdir, readFile, mkdir, rm, stat } from "node:fs/promises";
2
2
  import { join } from "node:path";
3
+ import { readDraftCriteria } from "../../shared/acceptance.js";
3
4
  import { parseFrontmatter, stringifyFrontmatter } from "./frontmatter.js";
5
+ /** 案の受け入れ基準(無い古い案は何も足さない。読めない項目は acceptanceProblems に理由) */
6
+ function draftCriteriaOf(raw) {
7
+ const { criteria, problems } = readDraftCriteria(raw);
8
+ return { ...(criteria ? { acceptanceCriteria: criteria } : {}), ...(problems ? { acceptanceProblems: problems } : {}) };
9
+ }
4
10
  import { writeFileAtomic } from "./fsutil.js";
5
11
  /**
6
12
  * requests/<要望ID>/preflight/<RUN-ID>/
@@ -32,7 +38,8 @@ export class PreflightStore {
32
38
  await this.saveDraft(requestId, runId, d);
33
39
  }
34
40
  async saveDraft(requestId, runId, d) {
35
- const { description, ...meta } = d;
41
+ // 基準が読めない理由は書かない(読むたびに決まる)
42
+ const { description, acceptanceProblems: _p, ...meta } = d;
36
43
  await writeFileAtomic(join(this.runDir(requestId, runId), "drafts", `${d.key}.md`), stringifyFrontmatter({ ...meta, include: d.include }, description));
37
44
  }
38
45
  async loadDrafts(requestId, runId) {
@@ -50,6 +57,7 @@ export class PreflightStore {
50
57
  supersedes: Array.isArray(data.supersedes) ? data.supersedes.map(String) : [],
51
58
  include: data.include !== false,
52
59
  ...("repo" in data ? { repo: data.repo === null || data.repo === "" || data.repo === "none" ? null : String(data.repo) } : {}),
60
+ ...draftCriteriaOf(data.acceptanceCriteria),
53
61
  });
54
62
  }
55
63
  return drafts.sort((a, b) => a.key.localeCompare(b.key, undefined, { numeric: true }));
@@ -11,7 +11,14 @@ function toPlain(cfg) {
11
11
  name: cfg.name,
12
12
  description: cfg.description || undefined,
13
13
  milestones: cfg.milestones.length
14
- ? cfg.milestones.map((m) => Object.fromEntries(Object.entries({ id: m.id, title: m.title, due: m.due, done: m.done || undefined }).filter(([, v]) => v !== undefined)))
14
+ ? cfg.milestones.map((m) => Object.fromEntries(Object.entries({
15
+ id: m.id,
16
+ title: m.title,
17
+ due: m.due,
18
+ done: m.done || undefined,
19
+ purpose: m.purpose || undefined,
20
+ goals: m.goals?.length ? m.goals.map((g) => ({ id: g.id, text: g.text })) : undefined,
21
+ }).filter(([, v]) => v !== undefined)))
15
22
  : undefined,
16
23
  branchPattern: cfg.branchPattern,
17
24
  preflight: preflightPlain(cfg.preflight),
@@ -102,3 +109,13 @@ export async function writeRepoEntry(path, name, entry) {
102
109
  sortKeys(doc);
103
110
  await writeFileAtomic(path, doc.toString({ lineWidth: 0 }));
104
111
  }
112
+ /**
113
+ * project.yaml の quality だけを書き換える(ほかの項目・コメントは残す)。plain は qualityPlain の形。
114
+ * ロックと版の照合は呼ぶ側(Workspace.writeQuality)
115
+ */
116
+ export async function writeQualityFile(path, plain) {
117
+ const text = await readFile(path, "utf8").catch(() => "");
118
+ const doc = text.trim() ? YAML.parseDocument(text) : new YAML.Document({});
119
+ doc.set("quality", doc.createNode(plain));
120
+ await writeFileAtomic(path, doc.toString({ lineWidth: 0 }));
121
+ }
@@ -1,17 +1,31 @@
1
+ import { createHash } from "node:crypto";
1
2
  import { readdir, readFile } from "node:fs/promises";
2
3
  import { join } from "node:path";
3
4
  import YAML from "yaml";
4
5
  import { parseRef, REQUEST_ID, TASK_ID, taskId } from "../../shared/refs.js";
6
+ import { milestoneGoalProblems, tidyMilestoneGoals } from "../../shared/milestoneGoals.js";
7
+ import { QualityInputError, qualityPlain } from "../../shared/quality.js";
5
8
  import { fileLayout, folderLayout, MarkdownCollection, NotFoundError } from "./collection.js";
6
- import { newRequestId } from "./fsutil.js";
7
- import { normalizeProject, normalizeRequest, normalizeTaskIn, REQUEST_KEY_ORDER, TASK_KEY_ORDER } from "./normalize.js";
9
+ import { newRequestId, withFileLock } from "./fsutil.js";
10
+ import { normalizeProject, normalizeRequest, normalizeTaskIn, REQUEST_KEY_ORDER, TASK_DERIVED, TASK_KEY_ORDER, taskKeepRaw } from "./normalize.js";
8
11
  import { AttachmentStore } from "./attachments.js";
9
12
  import { DataWatcher } from "./dataWatcher.js";
10
13
  import { NoteStore } from "./noteStore.js";
11
14
  import { PreflightStore } from "./preflightStore.js";
12
- import { writeProjectFile } from "./projectFile.js";
15
+ import { writeProjectFile, writeQualityFile } from "./projectFile.js";
13
16
  import { resolveRefs } from "../repoRefs.js";
14
17
  import { RELEASE_NOTES_DIR, ReleaseNoteStore } from "../releaseNotes/store.js";
18
+ import { MILESTONE_REVIEWS_DIR, MilestoneReviewStore } from "../milestoneReview/store.js";
19
+ import { TASK_REVIEWS_DIR, TaskReviewStore } from "../taskReview/store.js";
20
+ /** 保存する並びの各項目で、purpose / goals のキーが無ければ同じ ID の今の値を残す */
21
+ function keepGoals(next, cur) {
22
+ return next.map((m) => {
23
+ const was = cur.find((c) => c.id === m.id);
24
+ if (!was)
25
+ return m;
26
+ return { ...m, ...(!("purpose" in m) ? { purpose: was.purpose } : {}), ...(!("goals" in m) ? { goals: was.goals } : {}) };
27
+ });
28
+ }
15
29
  /** 全件の読み直しができなかった(project.yaml やデータのフォルダが読めない)。メモリ上の状態は変えていない */
16
30
  export class ReloadError extends Error {
17
31
  }
@@ -33,6 +47,28 @@ export function stampStatus(prev, next) {
33
47
  checkedAt: done ? next.checkedAt : undefined,
34
48
  };
35
49
  }
50
+ /** 編集を始めた後に、マイルストーンが他(CLI・ほかの画面・エディタ)で変わった。何も書いていない */
51
+ export class MilestonesConflictError extends Error {
52
+ expected;
53
+ current;
54
+ code = "milestones_conflict";
55
+ constructor(expected, current) {
56
+ super(`マイルストーンが他で変わりました(版 ${expected} → ${current})。最新を読み直してからやり直してください`);
57
+ this.expected = expected;
58
+ this.current = current;
59
+ }
60
+ }
61
+ /** プロジェクトの設定として保存できない値(何も書いていない) */
62
+ export class ProjectInputError extends Error {
63
+ }
64
+ /**
65
+ * マイルストーンの版: 中身(ID・名前・期限・リリース済み・目的・予定機能と並び)のハッシュ。ファイルの書き方(コメント・空白)
66
+ * やほかの設定の項目は含めない
67
+ */
68
+ export function milestonesVersion(ms) {
69
+ const plain = ms.map((m) => [m.id, m.title, m.due ?? null, !!m.done, m.purpose ?? null, (m.goals ?? []).map((g) => [g.id, g.text])]);
70
+ return createHash("sha256").update(JSON.stringify(plain)).digest("hex").slice(0, 16);
71
+ }
36
72
  export class Workspace {
37
73
  dataDir;
38
74
  localRepos;
@@ -42,6 +78,10 @@ export class Workspace {
42
78
  notes;
43
79
  attachments;
44
80
  releaseNotes;
81
+ /** マイルストーンレビューの履歴(milestoneReview/store.ts) */
82
+ milestoneReviews;
83
+ /** タスクの AI レビューの履歴(requests/<要望ID>/task-reviews/) */
84
+ taskReviews;
45
85
  taskCollections = new Map();
46
86
  listeners = new Set();
47
87
  watcher;
@@ -59,6 +99,8 @@ export class Workspace {
59
99
  this.notes = new NoteStore(this.requestsDir);
60
100
  this.attachments = new AttachmentStore(this.requestsDir);
61
101
  this.releaseNotes = new ReleaseNoteStore(dataDir);
102
+ this.milestoneReviews = new MilestoneReviewStore(dataDir);
103
+ this.taskReviews = new TaskReviewStore(this.requestsDir);
62
104
  }
63
105
  get requestsDir() {
64
106
  return join(this.dataDir, "requests");
@@ -167,7 +209,8 @@ export class Workspace {
167
209
  layout: fileLayout(join(this.requestsDir, requestId, "tasks"), TASK_ID, taskId),
168
210
  normalize: normalizeTaskIn(requestId),
169
211
  keyOrder: TASK_KEY_ORDER,
170
- derived: ["request", "ref"],
212
+ derived: TASK_DERIVED,
213
+ keepRaw: taskKeepRaw,
171
214
  beforeWrite: (prev, next) => stampStatus(prev, next),
172
215
  });
173
216
  this.taskCollections.set(requestId, col);
@@ -206,16 +249,69 @@ export class Workspace {
206
249
  out[`requests/${rid}/tasks/${id}.md`] = e;
207
250
  return out;
208
251
  }
209
- /** プロジェクト設定を更新して project.yaml に書く(コメントは残す) */
210
- async saveProject(patch) {
211
- await this.loadProject();
212
- // preflight は項目ごとに重ねる(観点だけ・担当だけの更新で、もう片方を消さない。以前の API の形 { instructions } も同じ)。
213
- // 担当を設定したら、読めなかった値は消す
214
- const pf = patch.preflight;
215
- const preflight = pf ? { ...this.project.preflight, ...pf, ...(pf.runner ? { invalidRunner: undefined } : {}) } : this.project.preflight;
216
- const next = { ...this.project, ...patch, preflight };
217
- await writeProjectFile(join(this.dataDir, "project.yaml"), next);
218
- await this.loadProject();
252
+ /** 今のマイルストーンの版(milestonesVersion) */
253
+ get milestonesVersion() {
254
+ return milestonesVersion(this.project.milestones);
255
+ }
256
+ /**
257
+ * プロジェクト設定を更新して project.yaml に書く(コメントは残す)。別のプロセス(CLI・serve)の保存とはロックで1つずつにし、
258
+ * ロックの中で最新のファイルを読んでから、patch の項目だけを重ねる。
259
+ *
260
+ * - preflight は項目ごとに重ねる
261
+ * - milestones の各項目で purpose / goals のキーが無ければ、同じ ID の今の値を残す(目的を知らない古い画面・API の保存で落とさない)。
262
+ * 消すなら空(purpose: "" / goals: [])を渡す
263
+ * - opts.milestonesVersion を渡すと、最新の版と照らして違えば MilestonesConflictError(何も書かない)
264
+ */
265
+ async saveProject(patch, opts = {}) {
266
+ return this.writeProject((cur) => {
267
+ // preflight は項目ごとに重ねる(観点だけ・担当だけの更新で、もう片方を消さない。以前の API の形 { instructions } も同じ)。
268
+ // 担当を設定したら、読めなかった値は消す
269
+ const pf = patch.preflight;
270
+ const preflight = pf ? { ...cur.preflight, ...pf, ...(pf.runner ? { invalidRunner: undefined } : {}) } : cur.preflight;
271
+ const milestones = patch.milestones ? keepGoals(patch.milestones, cur.milestones) : cur.milestones;
272
+ return { ...cur, ...patch, milestones, preflight };
273
+ }, opts);
274
+ }
275
+ /**
276
+ * 品質基準を、ロックの中で読み直した最新の値から作り直して書く(project.yaml の quality だけ)。expectedVersion が今の版と違えば
277
+ * QualityInputError(quality_conflict)で何も書かない。make が投げたら何も書かない
278
+ */
279
+ async writeQuality(make, opts = {}) {
280
+ const path = join(this.dataDir, "project.yaml");
281
+ await withFileLock(join(this.dataDir, ".project.yaml.lock"), async () => {
282
+ await this.loadProject();
283
+ const now = this.project.qualityVersion;
284
+ if (opts.expectedVersion !== undefined && opts.expectedVersion !== now) {
285
+ throw new QualityInputError("quality_conflict", `品質基準が他で変わりました(版 ${opts.expectedVersion} → ${now})。最新を読み直してからやり直してください`);
286
+ }
287
+ await writeQualityFile(path, qualityPlain(make(this.project)));
288
+ await this.loadProject();
289
+ });
290
+ this.emit({ type: "changed", kind: "project" });
291
+ return this.project;
292
+ }
293
+ /**
294
+ * マイルストーンを、ロックの中で読んだ最新の並びから作り直して書く(CLI の milestone の操作。指定した項目のほかを巻き戻さない)。
295
+ * fn が投げたら何も書かない
296
+ */
297
+ async updateMilestones(fn, opts = {}) {
298
+ return this.writeProject((cur) => ({ ...cur, milestones: fn(cur.milestones) }), opts);
299
+ }
300
+ async writeProject(make, opts) {
301
+ const path = join(this.dataDir, "project.yaml");
302
+ await withFileLock(join(this.dataDir, ".project.yaml.lock"), async () => {
303
+ await this.loadProject();
304
+ const now = milestonesVersion(this.project.milestones);
305
+ if (opts.milestonesVersion !== undefined && opts.milestonesVersion !== now)
306
+ throw new MilestonesConflictError(opts.milestonesVersion, now);
307
+ const next = make(this.project);
308
+ next.milestones = next.milestones.map((m) => tidyMilestoneGoals(m));
309
+ const problems = next.milestones.flatMap((m) => milestoneGoalProblems(m));
310
+ if (problems.length)
311
+ throw new ProjectInputError(problems.join(" / "));
312
+ await writeProjectFile(path, next);
313
+ await this.loadProject();
314
+ }, { busyMessage: "project.yaml を保存できませんでした(別のプロセスが保存中です。少し待ってやり直してください)" });
219
315
  this.emit({ type: "changed", kind: "project" });
220
316
  return this.project;
221
317
  }
@@ -258,6 +354,12 @@ export class Workspace {
258
354
  }
259
355
  async onFileChanged(rel) {
260
356
  const [top, rid, kind, file] = rel.split(/[\\/]/);
357
+ if (top === MILESTONE_REVIEWS_DIR) {
358
+ // レビューの履歴(ほかのプロセスの実行・取消)。ロックのフォルダ .locks は除く
359
+ if (rid && !rid.startsWith("."))
360
+ this.emit({ type: "milestone-review", milestone: rid });
361
+ return;
362
+ }
261
363
  if (top === RELEASE_NOTES_DIR) {
262
364
  // リリースノートの作成・更新・削除(ロックのファイル .<ID>.lock は除く)
263
365
  if (rid?.endsWith(".md") && !rid.startsWith(".") && kind === undefined)
@@ -271,6 +373,12 @@ export class Workspace {
271
373
  }
272
374
  if (top !== "requests" || !rid || !REQUEST_ID.test(rid))
273
375
  return;
376
+ if (kind === TASK_REVIEWS_DIR) {
377
+ // タスクのレビューの履歴(ほかのプロセスの実行・取消)。ロックのフォルダ .locks は除く
378
+ if (file && !file.startsWith("."))
379
+ this.emit({ type: "task-review", request: rid, task: file });
380
+ return;
381
+ }
274
382
  if (kind === undefined || kind === "request.md") {
275
383
  // 要望の作成・削除(git pull でフォルダごと増減することもある)
276
384
  const known = !!this.requests.get(rid);