@infodb/p3 0.4.0 → 0.5.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 (208) hide show
  1. package/bin/p3.mjs +11 -5
  2. package/dist/web/assets/Outputs-C83ZDXvs.js +1 -0
  3. package/dist/web/assets/RequestStatus-GmiWYEcL.js +1 -0
  4. package/dist/web/assets/Tabs-CJn0Qy7W.js +1 -0
  5. package/dist/web/assets/TagInput-CtM8HM8Z.js +1 -0
  6. package/dist/web/assets/TaskDrawer-D5v36QoF.js +3 -0
  7. package/dist/web/assets/_requestId-BHUqLO-j.js +1 -0
  8. package/dist/web/assets/_requestId-DxwxbXY2.js +30 -0
  9. package/dist/web/assets/{ui-DdOGYj9z.js → appCtx-B-VRVOyv.js} +1 -1
  10. package/dist/web/assets/board-DAaVR04x.js +1 -0
  11. package/dist/web/assets/done-CaqB_qTH.js +1 -0
  12. package/dist/web/assets/index-BF1xMdJo.css +2 -0
  13. package/dist/web/assets/index-BQYvKpjF.js +12 -0
  14. package/dist/web/assets/new-DLVnRvrB.js +1 -0
  15. package/dist/web/assets/{preflightInput-DMxqnvF8.js → preflightInput-BAeEJYUK.js} +1 -1
  16. package/dist/web/assets/preload-helper-B74h5i3O.js +1 -0
  17. package/dist/web/assets/progressTree-wp9mH4VF.js +1 -0
  18. package/dist/web/assets/release-notes-MTLcOcvZ.js +3 -0
  19. package/dist/web/assets/requestData-D-HXu-cy.js +1 -0
  20. package/dist/web/assets/routes-CI4Qfkjs.js +3 -0
  21. package/dist/web/assets/settings-CJMNgzi6.js +1 -0
  22. package/dist/web/index.html +4 -4
  23. package/docs/architecture.md +220 -3
  24. package/docs/development.md +16 -9
  25. package/docs/how-to-use.md +72 -7
  26. package/docs/installation.md +8 -6
  27. package/docs/publishing.md +4 -2
  28. package/lib/cli/args.js +172 -0
  29. package/lib/cli/chatgpt.js +70 -0
  30. package/lib/cli/codex.js +30 -0
  31. package/lib/cli/format.js +9 -0
  32. package/{src/cli/help.ts → lib/cli/help.js} +8 -8
  33. package/lib/cli/main.js +326 -0
  34. package/lib/cli/output.js +110 -0
  35. package/lib/cli/preflightCommands.js +301 -0
  36. package/lib/cli/project.js +649 -0
  37. package/lib/cli/readOnly.js +36 -0
  38. package/lib/cli/releaseNotesCommands.js +197 -0
  39. package/lib/cli/render.js +58 -0
  40. package/lib/cli/requestCommands.js +180 -0
  41. package/lib/cli/showView.js +100 -0
  42. package/lib/cli/taskCommands.js +152 -0
  43. package/lib/cli/userConfig.js +64 -0
  44. package/{src/core/chatgpt.ts → lib/core/chatgpt.js} +10 -16
  45. package/lib/core/context.js +41 -0
  46. package/lib/core/hierarchy.js +128 -0
  47. package/lib/core/machineSettings.js +146 -0
  48. package/lib/core/machineSettingsEdit.js +148 -0
  49. package/lib/core/ops.js +120 -0
  50. package/lib/core/preflight/carryover.js +105 -0
  51. package/lib/core/preflight/codexEngine.js +687 -0
  52. package/lib/core/preflight/codexImage.js +61 -0
  53. package/lib/core/preflight/diagnose.js +95 -0
  54. package/lib/core/preflight/engine.js +58 -0
  55. package/lib/core/preflight/input.js +83 -0
  56. package/lib/core/preflight/launch.js +68 -0
  57. package/lib/core/preflight/mockEngine.js +175 -0
  58. package/lib/core/preflight/render.js +304 -0
  59. package/lib/core/preflight/service.js +868 -0
  60. package/lib/core/preflight/split.js +83 -0
  61. package/lib/core/preflight/uiMaterials.js +281 -0
  62. package/lib/core/preflight/uiRender.js +89 -0
  63. package/lib/core/preflight/wireframe.js +63 -0
  64. package/lib/core/preflight/xlsx.js +324 -0
  65. package/lib/core/projectRegistry.js +207 -0
  66. package/lib/core/redact.js +28 -0
  67. package/lib/core/releaseNotes/completeRequests.js +106 -0
  68. package/lib/core/releaseNotes/generate.js +266 -0
  69. package/lib/core/releaseNotes/material.js +141 -0
  70. package/lib/core/releaseNotes/mockSummarizer.js +26 -0
  71. package/lib/core/releaseNotes/service.js +83 -0
  72. package/lib/core/releaseNotes/store.js +209 -0
  73. package/lib/core/repoAdmin.js +82 -0
  74. package/lib/core/repoRefs.js +72 -0
  75. package/lib/core/requestOps.js +154 -0
  76. package/lib/core/requestStatus.js +171 -0
  77. package/lib/core/store/attachments.js +242 -0
  78. package/lib/core/store/collection.js +254 -0
  79. package/lib/core/store/frontmatter.js +18 -0
  80. package/lib/core/store/fsutil.js +84 -0
  81. package/lib/core/store/locate.js +162 -0
  82. package/lib/core/store/normalize.js +150 -0
  83. package/lib/core/store/noteStore.js +59 -0
  84. package/lib/core/store/preflightStore.js +161 -0
  85. package/lib/core/store/projectFile.js +99 -0
  86. package/lib/core/store/workspace.js +320 -0
  87. package/lib/core/supersede.js +69 -0
  88. package/lib/core/userConfig.js +158 -0
  89. package/{src/core/userTheme.ts → lib/core/userTheme.js} +11 -13
  90. package/lib/core/workTargets.js +106 -0
  91. package/lib/server/api/chatgptRoutes.js +46 -0
  92. package/{src/server/api/local.ts → lib/server/api/local.js} +23 -22
  93. package/lib/server/api/manifest.js +140 -0
  94. package/lib/server/api/projectsRoutes.js +82 -0
  95. package/lib/server/api/releaseNoteRoutes.js +88 -0
  96. package/lib/server/api/repoRoutes.js +67 -0
  97. package/lib/server/api/routes.js +404 -0
  98. package/lib/server/api/userThemeRoutes.js +60 -0
  99. package/lib/server/server.js +85 -0
  100. package/lib/shared/dates.js +10 -0
  101. package/{src/shared/directTask.ts → lib/shared/directTask.js} +3 -11
  102. package/lib/shared/hierarchy.js +120 -0
  103. package/lib/shared/milestoneOrder.js +45 -0
  104. package/lib/shared/preflightInput.js +19 -0
  105. package/lib/shared/refs.js +44 -0
  106. package/lib/shared/repos.js +69 -0
  107. package/lib/shared/scopeView.js +39 -0
  108. package/{src/shared/tags.ts → lib/shared/tags.js} +9 -14
  109. package/lib/shared/types.js +74 -0
  110. package/lib/shared/workTarget.js +31 -0
  111. package/package.json +4 -7
  112. package/skills/p3/SKILL.md +10 -0
  113. package/dist/web/assets/Outputs-5Hby-S5Q.js +0 -1
  114. package/dist/web/assets/RequestStatus-CTkGjT02.js +0 -1
  115. package/dist/web/assets/TagInput-Rj3PNOAF.js +0 -1
  116. package/dist/web/assets/TaskDrawer-DtPhiYxP.js +0 -3
  117. package/dist/web/assets/_requestId-CGvAfIkB.js +0 -30
  118. package/dist/web/assets/_requestId-DxfYhgAq.js +0 -1
  119. package/dist/web/assets/board-wt47lfrE.js +0 -1
  120. package/dist/web/assets/done-C9Ct7ssb.js +0 -1
  121. package/dist/web/assets/index-BTFL2rpp.js +0 -12
  122. package/dist/web/assets/index-DAyBsvua.css +0 -2
  123. package/dist/web/assets/new-e4ID2vQV.js +0 -1
  124. package/dist/web/assets/preload-helper-DhIyFaOW.js +0 -1
  125. package/dist/web/assets/release-notes-CQ0d2r0k.js +0 -3
  126. package/dist/web/assets/requestData-BDZqyl35.js +0 -1
  127. package/dist/web/assets/routes-Bipv3lwJ.js +0 -2
  128. package/dist/web/assets/settings-Dwh8fj6p.js +0 -1
  129. package/src/cli/args.ts +0 -186
  130. package/src/cli/chatgpt.ts +0 -74
  131. package/src/cli/codex.ts +0 -28
  132. package/src/cli/format.ts +0 -9
  133. package/src/cli/main.ts +0 -337
  134. package/src/cli/output.ts +0 -117
  135. package/src/cli/preflightCommands.ts +0 -245
  136. package/src/cli/project.ts +0 -675
  137. package/src/cli/readOnly.ts +0 -36
  138. package/src/cli/releaseNotesCommands.ts +0 -198
  139. package/src/cli/render.ts +0 -60
  140. package/src/cli/requestCommands.ts +0 -172
  141. package/src/cli/showView.ts +0 -110
  142. package/src/cli/taskCommands.ts +0 -167
  143. package/src/cli/userConfig.ts +0 -58
  144. package/src/core/context.ts +0 -58
  145. package/src/core/machineSettings.ts +0 -207
  146. package/src/core/machineSettingsEdit.ts +0 -156
  147. package/src/core/ops.ts +0 -114
  148. package/src/core/preflight/carryover.ts +0 -133
  149. package/src/core/preflight/codexEngine.ts +0 -703
  150. package/src/core/preflight/codexImage.ts +0 -98
  151. package/src/core/preflight/diagnose.ts +0 -124
  152. package/src/core/preflight/engine.ts +0 -92
  153. package/src/core/preflight/input.ts +0 -65
  154. package/src/core/preflight/launch.ts +0 -86
  155. package/src/core/preflight/mockEngine.ts +0 -145
  156. package/src/core/preflight/render.ts +0 -339
  157. package/src/core/preflight/service.ts +0 -707
  158. package/src/core/preflight/uiMaterials.ts +0 -272
  159. package/src/core/preflight/uiRender.ts +0 -84
  160. package/src/core/preflight/wireframe.ts +0 -69
  161. package/src/core/preflight/xlsx.ts +0 -328
  162. package/src/core/projectRegistry.ts +0 -264
  163. package/src/core/redact.ts +0 -31
  164. package/src/core/releaseNotes/completeRequests.ts +0 -102
  165. package/src/core/releaseNotes/generate.ts +0 -283
  166. package/src/core/releaseNotes/material.ts +0 -114
  167. package/src/core/releaseNotes/mockSummarizer.ts +0 -28
  168. package/src/core/releaseNotes/service.ts +0 -110
  169. package/src/core/releaseNotes/store.ts +0 -216
  170. package/src/core/repoAdmin.ts +0 -81
  171. package/src/core/repoRefs.ts +0 -90
  172. package/src/core/requestOps.ts +0 -140
  173. package/src/core/requestStatus.ts +0 -58
  174. package/src/core/store/attachments.ts +0 -228
  175. package/src/core/store/collection.ts +0 -282
  176. package/src/core/store/frontmatter.ts +0 -22
  177. package/src/core/store/fsutil.ts +0 -90
  178. package/src/core/store/locate.ts +0 -181
  179. package/src/core/store/normalize.ts +0 -155
  180. package/src/core/store/noteStore.ts +0 -56
  181. package/src/core/store/preflightStore.ts +0 -136
  182. package/src/core/store/projectFile.ts +0 -101
  183. package/src/core/store/workspace.ts +0 -328
  184. package/src/core/supersede.ts +0 -74
  185. package/src/core/userConfig.ts +0 -205
  186. package/src/core/workTargets.ts +0 -120
  187. package/src/server/api/chatgptRoutes.ts +0 -49
  188. package/src/server/api/manifest.ts +0 -135
  189. package/src/server/api/projectsRoutes.ts +0 -89
  190. package/src/server/api/releaseNoteRoutes.ts +0 -89
  191. package/src/server/api/repoRoutes.ts +0 -67
  192. package/src/server/api/routes.ts +0 -382
  193. package/src/server/api/userThemeRoutes.ts +0 -62
  194. package/src/server/server.ts +0 -108
  195. package/src/shared/dates.ts +0 -12
  196. package/src/shared/milestoneOrder.ts +0 -44
  197. package/src/shared/preflightInput.ts +0 -27
  198. package/src/shared/refs.ts +0 -55
  199. package/src/shared/repos.ts +0 -113
  200. package/src/shared/scopeView.ts +0 -48
  201. package/src/shared/types.ts +0 -730
  202. package/src/shared/workTarget.ts +0 -44
  203. /package/{src → lib}/core/preflight/launcher.mjs +0 -0
  204. /package/{src → lib}/core/preflight/mock-ui.html +0 -0
  205. /package/{src → lib}/core/preflight/mock-ui.png +0 -0
  206. /package/{src → lib}/core/preflight/render-image/Dockerfile +0 -0
  207. /package/{src → lib}/core/preflight/render-image/fonts-ja.conf +0 -0
  208. /package/{src → lib}/core/preflight/render-image/render.mjs +0 -0
@@ -1,216 +0,0 @@
1
- import { createHash } from "node:crypto";
2
- import { readdir, readFile } from "node:fs/promises";
3
- import { join, resolve, sep } from "node:path";
4
- import type { ReleaseNote, ReleaseSource } from "../../shared/types.ts";
5
- import { parseFrontmatter, stringifyFrontmatter } from "../store/frontmatter.ts";
6
- import { createExclusive, nowIso, withFileLock, writeFileAtomic } from "../store/fsutil.ts";
7
-
8
- /**
9
- * <data>/release-notes/<マイルストーンID>.md リリースノート(マイルストーンごとに1件)
10
- *
11
- * frontmatter に出典(保存したときの材料: 要望・タスクの ID・タイトル・状態・変更の記録)と材料の hash、
12
- * 本文に公開する Markdown を書く。出力は本文だけ。要望やタスクが後で変わっても、保存した本文と出典は変えない。
13
- *
14
- * 編集の版はファイル全体の sha256。保存はプロセス間のロックの中で、ディスクの今のファイルの版と照らしてから原子的に書く
15
- * (rev を増やさない直接編集も見つけられる)。ロックを使わない外部のエディタとの完全な排他は保証しない。
16
- * キャッシュは持たず、問い合わせのたびにディスクを読む(再読み込みは要らない)。
17
- */
18
-
19
- export const RELEASE_NOTES_DIR = "release-notes";
20
- /** マイルストーンの ID(project.yaml と同じ。. と .. は使えない) */
21
- const MILESTONE_ID = /^[A-Za-z0-9._-]+$/;
22
-
23
- /** ノートの操作の失敗の種類。CLI は終了コード、API は応答に分ける */
24
- export class ReleaseNoteError extends Error {
25
- constructor(
26
- /** not_found: 無い / invalid: 読めない / exists: 既にある / conflict: 版が違う / bad_id: ID が使えない */
27
- readonly code: "not_found" | "invalid" | "exists" | "conflict" | "bad_id",
28
- readonly milestone: string,
29
- message: string,
30
- /** conflict のときの今の版(読めなければ無い) */
31
- readonly current?: string,
32
- ) {
33
- super(message);
34
- }
35
- }
36
-
37
- export const versionOf = (text: string) => createHash("sha256").update(text).digest("hex");
38
-
39
- export function checkMilestoneId(id: string): void {
40
- if (!MILESTONE_ID.test(id) || id === "." || id === "..") throw new ReleaseNoteError("bad_id", id, `マイルストーンの ID に使えません: ${JSON.stringify(id)}(英数字と . _ -)`);
41
- }
42
-
43
- export interface NoteWrite {
44
- title: string;
45
- body: string;
46
- sources: ReleaseSource[];
47
- materialHash?: string;
48
- }
49
-
50
- export class ReleaseNoteStore {
51
- constructor(readonly dataDir: string) {}
52
-
53
- get dir() {
54
- return join(this.dataDir, RELEASE_NOTES_DIR);
55
- }
56
-
57
- /** ノートのファイル。保存先のフォルダの外を指す ID は断る */
58
- path(milestone: string): string {
59
- checkMilestoneId(milestone);
60
- const p = resolve(this.dir, `${milestone}.md`);
61
- if (!p.startsWith(resolve(this.dir) + sep)) throw new ReleaseNoteError("bad_id", milestone, `保存先の外を指します: ${milestone}`);
62
- return p;
63
- }
64
-
65
- private lock(milestone: string) {
66
- return join(this.dir, `.${milestone}.lock`);
67
- }
68
-
69
- /** ファイルがあるマイルストーン(読めないものも含む。ID の形でないファイルは除く) */
70
- async ids(): Promise<string[]> {
71
- const files = await readdir(this.dir).catch((e: NodeJS.ErrnoException) => {
72
- if (e.code === "ENOENT") return [] as string[];
73
- throw e;
74
- });
75
- return files
76
- .filter((f) => f.endsWith(".md") && !f.startsWith("."))
77
- .map((f) => f.slice(0, -3))
78
- .filter((id) => MILESTONE_ID.test(id) && id !== "." && id !== "..")
79
- .sort();
80
- }
81
-
82
- /** 読む。無ければ not_found、読めなければ invalid(空のノートとして扱わない) */
83
- async read(milestone: string): Promise<ReleaseNote> {
84
- const path = this.path(milestone);
85
- let text: string;
86
- try {
87
- text = await readFile(path, "utf8");
88
- } catch (e) {
89
- if ((e as NodeJS.ErrnoException).code === "ENOENT") throw new ReleaseNoteError("not_found", milestone, `リリースノートがありません: ${milestone}`);
90
- throw new ReleaseNoteError("invalid", milestone, `リリースノートを読めません(${path}): ${(e as Error).message}`);
91
- }
92
- return parseNote(milestone, text, path);
93
- }
94
-
95
- /** 全部(読めないものは invalid に理由を返す) */
96
- async list(): Promise<{ notes: ReleaseNote[]; invalid: { milestone: string; error: string }[] }> {
97
- const notes: ReleaseNote[] = [];
98
- const invalid: { milestone: string; error: string }[] = [];
99
- for (const id of await this.ids()) {
100
- try {
101
- notes.push(await this.read(id));
102
- } catch (e) {
103
- if (e instanceof ReleaseNoteError && e.code === "not_found") continue; // 読む間に消えた
104
- invalid.push({ milestone: id, error: (e as Error).message });
105
- }
106
- }
107
- return { notes, invalid };
108
- }
109
-
110
- /** 新しく作る(既にあれば exists。読めないファイルがあっても上書きしない) */
111
- async create(milestone: string, input: NoteWrite, actor?: string): Promise<ReleaseNote> {
112
- const path = this.path(milestone);
113
- return withFileLock(this.lock(milestone), async () => {
114
- const now = nowIso();
115
- const text = serialize({ milestone, ...input, createdAt: now, createdBy: actor, updatedAt: now, updatedBy: actor });
116
- if (!(await createExclusive(path, text))) throw new ReleaseNoteError("exists", milestone, `リリースノートは既にあります: ${milestone}(直すときは版を付けて更新してください)`);
117
- return parseNote(milestone, text, path);
118
- });
119
- }
120
-
121
- /**
122
- * 更新する。expectedVersion は読んだときの版(必須)。ロックの中でディスクの今のファイルと照らし、違えば conflict で何も書かない。
123
- * 作成の日時と作成者は残す
124
- */
125
- async update(milestone: string, input: Partial<NoteWrite>, expectedVersion: string, actor?: string): Promise<ReleaseNote> {
126
- const path = this.path(milestone);
127
- return withFileLock(this.lock(milestone), async () => {
128
- let raw: string;
129
- try {
130
- raw = await readFile(path, "utf8");
131
- } catch (e) {
132
- if ((e as NodeJS.ErrnoException).code === "ENOENT") throw new ReleaseNoteError("not_found", milestone, `リリースノートがありません(消されました): ${milestone}`);
133
- throw e;
134
- }
135
- const version = versionOf(raw);
136
- if (version !== expectedVersion) {
137
- throw new ReleaseNoteError("conflict", milestone, `${milestone} のリリースノートは読んだ後に変わっています(版が違います)。読み直してからやり直してください`, version);
138
- }
139
- const cur = parseNote(milestone, raw, path);
140
- const text = serialize({
141
- milestone,
142
- title: input.title ?? cur.title,
143
- body: input.body ?? cur.body,
144
- sources: input.sources ?? cur.sources,
145
- materialHash: "materialHash" in input ? input.materialHash : cur.materialHash,
146
- createdAt: cur.createdAt,
147
- createdBy: cur.createdBy,
148
- updatedAt: nowIso(),
149
- updatedBy: actor,
150
- });
151
- await writeFileAtomic(path, text);
152
- return parseNote(milestone, text, path);
153
- });
154
- }
155
- }
156
-
157
- function serialize(n: Omit<ReleaseNote, "version">): string {
158
- return stringifyFrontmatter(
159
- {
160
- milestone: n.milestone,
161
- title: n.title,
162
- createdAt: n.createdAt,
163
- createdBy: n.createdBy,
164
- updatedAt: n.updatedAt,
165
- updatedBy: n.updatedBy,
166
- materialHash: n.materialHash,
167
- sources: n.sources.map((s) => ({ request: s.request, title: s.title, status: s.status, tasks: s.tasks.map((t) => ({ id: t.id, title: t.title, status: t.status, record: t.record })) })),
168
- },
169
- n.body,
170
- );
171
- }
172
-
173
- const str = (v: unknown) => (typeof v === "string" ? v : undefined);
174
-
175
- /** ファイルを読む。frontmatter が壊れている・マイルストーンが違う・日時が無いものは invalid */
176
- function parseNote(milestone: string, text: string, path: string): ReleaseNote {
177
- let data: Record<string, unknown>;
178
- let body: string;
179
- try {
180
- ({ data, body } = parseFrontmatter(text));
181
- } catch (e) {
182
- throw new ReleaseNoteError("invalid", milestone, `リリースノートの frontmatter を読めません(${path}): ${(e as Error).message}`);
183
- }
184
- const bad = (why: string) => new ReleaseNoteError("invalid", milestone, `リリースノートを読めません(${path}): ${why}`);
185
- if (data.milestone !== milestone) throw bad(`milestone が ${JSON.stringify(data.milestone)} です(ファイル名は ${milestone})`);
186
- const createdAt = str(data.createdAt);
187
- const updatedAt = str(data.updatedAt);
188
- if (!createdAt || !updatedAt) throw bad("createdAt / updatedAt がありません");
189
- if (data.sources !== undefined && !Array.isArray(data.sources)) throw bad("sources が配列ではありません");
190
- const sources: ReleaseSource[] = ((data.sources as unknown[] | undefined) ?? []).map((s, i) => {
191
- const o = (s ?? {}) as Record<string, unknown>;
192
- if (typeof o.request !== "string") throw bad(`sources[${i}].request がありません`);
193
- const tasks = Array.isArray(o.tasks) ? o.tasks : [];
194
- return {
195
- request: o.request,
196
- title: str(o.title) ?? "",
197
- status: (str(o.status) ?? "done") as ReleaseSource["status"],
198
- tasks: tasks.map((t) => {
199
- const x = (t ?? {}) as Record<string, unknown>;
200
- return { id: String(x.id ?? ""), title: str(x.title) ?? "", status: (str(x.status) ?? "done") as ReleaseSource["tasks"][number]["status"], ...(str(x.record) ? { record: str(x.record) } : {}) };
201
- }),
202
- };
203
- });
204
- return {
205
- milestone,
206
- title: str(data.title) ?? milestone,
207
- body: body.trim(),
208
- sources,
209
- materialHash: str(data.materialHash),
210
- createdAt,
211
- createdBy: str(data.createdBy),
212
- updatedAt,
213
- updatedBy: str(data.updatedBy),
214
- version: versionOf(text),
215
- };
216
- }
@@ -1,81 +0,0 @@
1
- import { existsSync, statSync } from "node:fs";
2
- import { join } from "node:path";
3
- import { repoNameProblem, type CodeMapEntry, type RepoRef } from "../shared/repos.ts";
4
- import { writeRepoEntry } from "./store/projectFile.ts";
5
- import type { Workspace } from "./store/workspace.ts";
6
- import { setProjectNode, updateUserConfig } from "./userConfig.ts";
7
-
8
- /**
9
- * 参照先の登録・変更・削除(CLI の p3 repo と設定画面で共通)。
10
- * 共有の定義は project.yaml の repos(その1件だけを書く。コメント・ほかの項目は残す)
11
- * このマシンのパスは個人設定の projects.<プロジェクト>.repos.<名前>(共有しない)
12
- */
13
- export class RepoAdminError extends Error {}
14
-
15
- /** 共有の定義のうち、変えてよい項目 */
16
- export type RepoPatch = Partial<Pick<RepoRef, "role" | "readFirst" | "writable" | "map">>;
17
-
18
- const file = (ws: Workspace) => join(ws.dataDir, "project.yaml");
19
-
20
- function cleanMap(map: CodeMapEntry[]): CodeMapEntry[] {
21
- return map
22
- .map((m) => ({ path: m.path.trim().replace(/^(\.\/)+/, "").replace(/\/+$/, ""), role: m.role.trim(), ...(m.entry?.trim() ? { entry: m.entry.trim() } : {}) }))
23
- .filter((m) => m.path);
24
- }
25
-
26
- export async function addRepo(ws: Workspace, name: string, patch: RepoPatch = {}): Promise<RepoRef> {
27
- const problem = repoNameProblem(name);
28
- if (problem) throw new RepoAdminError(`参照先の名前: ${problem}`);
29
- if (ws.project.repos.some((r) => r.name === name)) throw new RepoAdminError(`「${name}」は既にあります`);
30
- const entry: RepoRef = { name, role: patch.role?.trim() ?? "", readFirst: !!patch.readFirst, writable: !!patch.writable, map: cleanMap(patch.map ?? []) };
31
- await writeRepoEntry(file(ws), name, entry);
32
- await ws.refreshProject();
33
- return entry;
34
- }
35
-
36
- export async function updateRepo(ws: Workspace, name: string, patch: RepoPatch): Promise<RepoRef> {
37
- const cur = ws.project.repos.find((r) => r.name === name);
38
- if (!cur) throw new RepoAdminError(`「${name}」はありません`);
39
- const next: RepoRef = {
40
- ...cur,
41
- ...(patch.role !== undefined ? { role: patch.role.trim() } : {}),
42
- ...(patch.readFirst !== undefined ? { readFirst: patch.readFirst } : {}),
43
- ...(patch.writable !== undefined ? { writable: patch.writable } : {}),
44
- ...(patch.map !== undefined ? { map: cleanMap(patch.map) } : {}),
45
- };
46
- await writeRepoEntry(file(ws), name, next);
47
- await ws.refreshProject();
48
- return next;
49
- }
50
-
51
- /** 共有の定義を消す(ほかの人の Preflight でも読まなくなる。フォルダは消さない)。このマシンのパスも外す */
52
- export async function removeRepo(ws: Workspace, projectName: string | undefined, name: string) {
53
- if (!ws.project.repos.some((r) => r.name === name)) throw new RepoAdminError(`「${name}」はありません`);
54
- await writeRepoEntry(file(ws), name, null);
55
- if (projectName) await setLocalRepoPath(ws, projectName, name, null).catch(() => undefined);
56
- await ws.refreshProject();
57
- }
58
-
59
- /** このマシンのパスとして使えるか(フォルダであること。git でなくてよい) */
60
- export function checkFolder(path: string) {
61
- if (!existsSync(path)) throw new RepoAdminError(`パスがありません: ${path}`);
62
- if (!statSync(path).isDirectory()) throw new RepoAdminError(`フォルダではありません: ${path}`);
63
- }
64
-
65
- /** このマシンのパスを登録する(null で外す)。フォルダであること(git でなくてよい)。共有の定義は変えない */
66
- export async function setLocalRepoPath(ws: Workspace, projectName: string | undefined, name: string, path: string | null) {
67
- if (!projectName) throw new RepoAdminError("このプロジェクトは個人設定に登録されていません。先に p3 project add <名前> <フォルダ> で登録してください");
68
- if (path !== null) {
69
- if (!ws.project.repos.some((r) => r.name === name)) throw new RepoAdminError(`「${name}」は参照先にありません(先に共有の定義を足してください)`);
70
- checkFolder(path);
71
- }
72
- await updateUserConfig((doc, now) => {
73
- const prev = now.projects[projectName];
74
- if (!prev) throw new RepoAdminError(`プロジェクト「${projectName}」は個人設定に登録されていません`);
75
- const repos = { ...prev.repos };
76
- if (path === null) delete repos[name];
77
- else repos[name] = path;
78
- setProjectNode(doc, projectName, { dir: prev.dir, repos });
79
- });
80
- ws.setLocalRepo(name, path);
81
- }
@@ -1,90 +0,0 @@
1
- import { existsSync, readFileSync, statSync } from "node:fs";
2
- import { dirname, isAbsolute, join, relative, resolve } from "node:path";
3
- import { mountNames, type RefScope, type RepoRef } from "../shared/repos.ts";
4
- import type { ProjectConfig } from "../shared/types.ts";
5
-
6
- /**
7
- * 参照先(共有の定義)と、このマシンのパス(個人設定)を合わせたもの。
8
- *
9
- * ok 手元のパスがあり、フォルダとして読める
10
- * unregistered 手元のパスが登録されていない(p3 repo path <名前> <パス> で登録する)
11
- * missing 登録したパスが無い
12
- * notdir 登録したパスがフォルダではない
13
- *
14
- * git のリポジトリでなくてもよい(フォルダだけ・リポジトリの中のサブフォルダも可)。
15
- */
16
- export interface ResolvedRef extends RepoRef {
17
- /** コンテナの中の名前(/workspace/<mount>) */
18
- mount: string;
19
- status: "ok" | "unregistered" | "missing" | "notdir";
20
- /** このマシンのパス(共有の記録には残さない) */
21
- local?: string;
22
- /** 見られないときの理由 */
23
- reason?: string;
24
- }
25
-
26
- /** 共有の定義ごとに、個人設定の repos.<名前>(このマシンのパス)を合わせる。手元の対応が無い名前は unregistered */
27
- export function resolveRefs(project: ProjectConfig, opts: { localRepos?: Record<string, string> }): ResolvedRef[] {
28
- const local = opts.localRepos ?? {};
29
- const mounts = mountNames(project.repos.map((r) => r.name));
30
- return project.repos.map((r, i) => {
31
- const path = local[r.name];
32
- const base = { ...r, mount: mounts[i] };
33
- if (!path) return { ...base, status: "unregistered" as const, reason: "このマシンのパスが登録されていません" };
34
- try {
35
- const st = statSync(path);
36
- if (!st.isDirectory()) return { ...base, status: "notdir" as const, local: path, reason: `フォルダではありません: ${path}` };
37
- } catch {
38
- return { ...base, status: "missing" as const, local: path, reason: `登録したパスがありません: ${path}` };
39
- }
40
- return { ...base, status: "ok" as const, local: path };
41
- });
42
- }
43
-
44
- /**
45
- * 参照先のフォルダで git の履歴が使えるか。コンテナには参照先のフォルダだけを読むだけでマウントするので、
46
- * 履歴の本体(.git)がフォルダの中にあるときだけ使える。浅い clone は途中までしか無い
47
- */
48
- export function gitHistory(local: string): NonNullable<RefScope["history"]> {
49
- const dotGit = join(local, ".git");
50
- let st;
51
- try {
52
- st = statSync(dotGit);
53
- } catch {
54
- // 上に .git があれば、リポジトリの中のサブフォルダ(履歴の本体はマウントの外)
55
- for (let d = dirname(resolve(local)); d !== dirname(d); d = dirname(d)) {
56
- if (existsSync(join(d, ".git"))) return { status: "unavailable", reason: "リポジトリの中のサブフォルダなので、履歴の本体(.git)がマウントの外にあります" };
57
- }
58
- return { status: "unavailable", reason: "git のリポジトリではありません" };
59
- }
60
- if (st.isFile()) {
61
- // git の作業ツリー(worktree)・サブモジュール: .git は本体の場所を指すファイル
62
- const m = /^gitdir:\s*(.+)$/m.exec(readFileSync(dotGit, "utf8"));
63
- const gitdir = m ? resolve(local, m[1].trim()) : undefined;
64
- const inside = gitdir && !relative(local, gitdir).startsWith("..") && !isAbsolute(relative(local, gitdir));
65
- if (!inside) return { status: "unavailable", reason: "git の作業ツリーなので、履歴の本体がマウントの外にあります(メインのチェックアウトを参照先にすると使えます)" };
66
- return { status: "ok" };
67
- }
68
- if (existsSync(join(dotGit, "shallow"))) return { status: "shallow", reason: "浅い clone なので、履歴は途中までです" };
69
- return { status: "ok" };
70
- }
71
-
72
- export function refScope(r: ResolvedRef): RefScope {
73
- const reason =
74
- r.status === "unregistered"
75
- ? `このマシンのパスが登録されていません(p3 repo path ${r.name} <パス>)`
76
- : r.status === "missing"
77
- ? "登録したパスがありません"
78
- : r.status === "notdir"
79
- ? "登録したパスがフォルダではありません"
80
- : undefined;
81
- return {
82
- name: r.name,
83
- mount: r.mount,
84
- role: r.role,
85
- readFirst: r.readFirst,
86
- status: r.status,
87
- ...(reason ? { reason } : {}),
88
- ...(r.status === "ok" && r.local ? { history: gitHistory(r.local) } : {}),
89
- };
90
- }
@@ -1,140 +0,0 @@
1
- import type { Request, Task } from "../shared/types.ts";
2
- import { defaultRepo } from "../shared/workTarget.ts";
3
- import type { P3Context } from "./context.ts";
4
- import { checkStatusChange, reopenIfNeeded } from "./requestStatus.ts";
5
- import { startWarnings, type Warning } from "./supersede.ts";
6
- import { checkRepoTarget, ensureWorkstreams } from "./workTargets.ts";
7
-
8
- /**
9
- * 要望とタスクの変更の手順。CLI と API はここを呼び、引数の解釈と出力だけを持つ。
10
- * 規則(作業先・対応済・置き換えの警告・ブランチの割り当て・進行中に戻す・変更通知)を足すときは、ここだけを直す。
11
- * タスクの関係(depends_on・supersedes)は Preflight のタスク化だけが張る(手で張る操作は持たない)
12
- *
13
- * 手順はどれも「確かめる(何も書かない)→ 保存 → 後始末(ブランチの割り当て・進行中に戻す)→ 変更通知」の順。
14
- */
15
-
16
- /** 入力が規則に合わない(何も書いていない)。CLI は使い方の誤り、API は 400 */
17
- export class OpRuleError extends Error {}
18
-
19
- export interface WriteOpts {
20
- /** 楽観ロック。違えば ConflictError */
21
- expectedRev?: number;
22
- actor?: string;
23
- }
24
-
25
- /** タスクを変えた結果。reopened: 対応済から進行中に戻した要望 */
26
- export interface TaskResult {
27
- task: Task;
28
- warnings: Warning[];
29
- reopened?: string;
30
- }
31
-
32
- function changed(ctx: P3Context, kind: "task" | "request", request: string, ref?: string) {
33
- ctx.ws.emit({ type: "changed", kind, request, ref });
34
- }
35
-
36
- /** 要望のマイルストーンは project.yaml にあるものだけ */
37
- export function checkMilestone(ctx: P3Context, id: string | null | undefined) {
38
- if (id && !ctx.ws.project.milestones.some((m) => m.id === id)) {
39
- throw new OpRuleError(`マイルストーンがありません: ${id}(p3 milestone add ${id} か、画面の設定で追加してください)`);
40
- }
41
- }
42
-
43
- /**
44
- * マイルストーンを外すときの規則(CLI の milestone rm と、API の設定全体の更新で同じに効かせる)。
45
- * next: 外した後に残るマイルストーンの ID。使っている要望か、リリースノート(読めないファイルも含む)があれば断る
46
- */
47
- export async function checkMilestoneRemoval(ctx: P3Context, next: string[]): Promise<void> {
48
- const keep = new Set(next);
49
- const removed = ctx.ws.project.milestones.map((m) => m.id).filter((id) => !keep.has(id));
50
- if (!removed.length) return;
51
- const used = [...new Set(ctx.ws.requests.list().flatMap((r) => (r.milestone && removed.includes(r.milestone) ? [r.milestone] : [])))];
52
- if (used.length) {
53
- const n = (id: string) => ctx.ws.requests.list().filter((r) => r.milestone === id).length;
54
- throw new OpRuleError(`使用中のマイルストーンは消せません: ${used.map((id) => `${id}(要望 ${n(id)} 件)`).join(", ")}。要望の milestone を外してから消してください`);
55
- }
56
- const notes = (await ctx.ws.releaseNotes.ids()).filter((id) => removed.includes(id));
57
- if (notes.length) {
58
- throw new OpRuleError(`リリースノートのあるマイルストーンは消せません: ${notes.join(", ")}(release-notes/<ID>.md を残すなら消さないでください)`);
59
- }
60
- }
61
-
62
- /** タスクを変えた後: ブランチの割り当てと、対応済の要望に未完了のタスクができたら進行中に戻す */
63
- async function afterTaskWrite(ctx: P3Context, rid: string, task: Task, repo: string | null | undefined, actor?: string): Promise<string | undefined> {
64
- if (repo) await ensureWorkstreams(ctx.ws, rid, [repo], actor);
65
- const reopened = (await reopenIfNeeded(ctx.ws, rid, actor)) ? rid : undefined;
66
- changed(ctx, "task", rid, task.ref);
67
- if (reopened) changed(ctx, "request", rid);
68
- return reopened;
69
- }
70
-
71
- /**
72
- * タスクを作る。repo: 省くと作業先にできる参照先が1つならそれ(ほかは作業先なし)、null は作業先なし。
73
- * 作業先とリポジトリごとの成果物の参照先は、作業先にできるものだけ(書く前に断る)
74
- */
75
- export async function createTask(ctx: P3Context, rid: string, input: Partial<Task> & { title: string }, actor?: string): Promise<TaskResult> {
76
- ctx.ws.requests.require(rid);
77
- const repo = "repo" in input ? (input.repo ?? null) : defaultRepo(ctx.ws.project);
78
- checkRepoTarget(ctx.ws, repo);
79
- for (const o of input.repoOutputs ?? []) checkRepoTarget(ctx.ws, o.repo);
80
- const task = await ctx.ws.tasksOf(rid).create({ ...input, repo, status: input.status ?? "todo" }, actor);
81
- return { task, warnings: [], reopened: await afterTaskWrite(ctx, rid, task, repo, actor) };
82
- }
83
-
84
- /**
85
- * タスクを変える。checked: 人の「済み」を付ける / 外す(付けられるのは完了したタスクだけ)。
86
- * 置き換えられたタスクを作業中にすると warnings を返す(変更はする)
87
- */
88
- export async function updateTask(
89
- ctx: P3Context,
90
- rid: string,
91
- tid: string,
92
- patch: Partial<Task> & { checked?: boolean },
93
- opts: WriteOpts = {},
94
- ): Promise<TaskResult> {
95
- const col = ctx.ws.tasksOf(rid);
96
- const cur = col.require(tid);
97
- const { checked, ...rest } = patch;
98
- const next: Partial<Task> = { ...rest };
99
- if ("repo" in patch) {
100
- checkRepoTarget(ctx.ws, patch.repo);
101
- next.repo = patch.repo ?? null;
102
- }
103
- for (const o of patch.repoOutputs ?? []) checkRepoTarget(ctx.ws, o.repo);
104
- if (checked !== undefined) {
105
- if (checked && (next.status ?? cur.status) !== "done") throw new OpRuleError(`${cur.ref} はまだ完了していません(済みにできるのは完了したタスクだけ)`);
106
- next.checkedAt = checked ? new Date().toISOString() : undefined;
107
- }
108
- const warnings = startWarnings(ctx.ws, cur.ref, cur.status, next.status);
109
- const task = await col.update(tid, next, opts);
110
- return { task, warnings, reopened: await afterTaskWrite(ctx, rid, task, patch.repo, opts.actor) };
111
- }
112
-
113
- /** タスクをアーカイブする(.archive/ へ移す。消さない) */
114
- export async function archiveTask(ctx: P3Context, rid: string, tid: string): Promise<void> {
115
- await ctx.ws.tasksOf(rid).archive(tid);
116
- changed(ctx, "task", rid, `${rid}/${tid}`);
117
- }
118
-
119
- /** 要望を作る(下書き) */
120
- export async function createRequest(ctx: P3Context, input: Partial<Request> & { title: string }, actor?: string): Promise<Request> {
121
- checkMilestone(ctx, input.milestone);
122
- const r = await ctx.ws.requests.create({ body: "", areas: [], tags: [], ...input, status: "draft" }, actor);
123
- changed(ctx, "request", r.id);
124
- return r;
125
- }
126
-
127
- /** 要望を変える。対応済にするのは全タスクが完了のときだけ(requestStatus.ts) */
128
- export async function updateRequest(ctx: P3Context, rid: string, patch: Partial<Request>, opts: WriteOpts = {}): Promise<Request> {
129
- checkMilestone(ctx, patch.milestone);
130
- await checkStatusChange(ctx.ws, rid, patch.status);
131
- const r = await ctx.ws.requests.update(rid, patch, opts);
132
- changed(ctx, "request", r.id);
133
- return r;
134
- }
135
-
136
- /** 要望をアーカイブする(フォルダごと .archive/ へ) */
137
- export async function archiveRequest(ctx: P3Context, rid: string): Promise<void> {
138
- await ctx.ws.requests.archive(rid);
139
- changed(ctx, "request", rid);
140
- }
@@ -1,58 +0,0 @@
1
- import type { Request, RequestStatus } from "../shared/types.ts";
2
- import type { Workspace } from "./store/workspace.ts";
3
-
4
- /**
5
- * 要望の「対応済」(resolved)の規則。CLI と API のどちらから変えても同じように効くよう、ここにまとめる。
6
- *
7
- * - 対応済にできるのは、タスクが1件以上あり、全部が完了(status=done)で、読めないタスクファイルが無いときだけ。
8
- * 人の「済み」(checkedAt)・PR・マージは条件にしない。置き換えられたタスクも、残っていれば数える
9
- * - 対応済の要望に未完了のタスクができたら(足した・完了から戻した・再評価でタスク化した)進行中に戻す
10
- * - 最後のタスクを完了にしても自動では対応済にしない(作業を終えた側が明示的に設定する)
11
- */
12
-
13
- export class StatusRuleError extends Error {}
14
-
15
- /** 対応済にできないなら理由(できるなら undefined)。判定の直前にディスクから読み直す */
16
- export async function resolveBlocker(ws: Workspace, rid: string): Promise<string | undefined> {
17
- const col = ws.tasksOf(rid);
18
- await col.load();
19
- const broken = [...col.errors.keys()];
20
- if (broken.length) return `読めないタスクファイルがあります: ${broken.join(", ")}(直してから対応済にしてください)`;
21
- const tasks = col.list();
22
- if (!tasks.length) return "タスクがありません(タスクの無い要望は対応済にできません)";
23
- const open = tasks.filter((t) => t.status !== "done");
24
- if (open.length) return `完了していないタスクがあります: ${open.map((t) => `${t.id}(${t.status})`).join(", ")}(完了させるか、不要ならアーカイブしてから対応済にしてください)`;
25
- return undefined;
26
- }
27
-
28
- /** ステータスを対応済に変えるなら規則を確かめる(満たさなければ何も書かずに失敗する) */
29
- export async function checkStatusChange(ws: Workspace, rid: string, next: RequestStatus | undefined): Promise<void> {
30
- if (next !== "resolved") return;
31
- const why = await resolveBlocker(ws, rid);
32
- if (why) throw new StatusRuleError(`${rid} を対応済にできません: ${why}`);
33
- }
34
-
35
- /** 対応済なのに未完了のタスクがある(外部の直接編集など)。画面と CLI で知らせる */
36
- export function resolvedIssue(ws: Workspace, r: Request): string | undefined {
37
- if (r.status !== "resolved") return undefined;
38
- const open = ws.tasksOf(r.id).list().filter((t) => t.status !== "done");
39
- return open.length
40
- ? `対応済ですが、完了していないタスクがあります: ${open.map((t) => t.id).join(", ")}(進行中に戻すには status=active)`
41
- : undefined;
42
- }
43
-
44
- /**
45
- * タスクを変えた後に呼ぶ: 対応済の要望に未完了のタスクがあれば進行中に戻す。戻したら true。
46
- * タスクの変更は済んでいるので、要望の更新に失敗したら、そう分かるエラーにする(再試行は request set status=active)。
47
- */
48
- export async function reopenIfNeeded(ws: Workspace, rid: string, actor?: string): Promise<boolean> {
49
- const r = ws.requests.get(rid);
50
- if (!r || r.status !== "resolved") return false;
51
- if (!ws.tasksOf(rid).list().some((t) => t.status !== "done")) return false;
52
- try {
53
- await ws.requests.update(rid, { status: "active" }, { actor });
54
- return true;
55
- } catch (e) {
56
- throw new Error(`タスクは更新しましたが、要望 ${rid} を進行中に戻せませんでした: ${(e as Error).message}(p3 request set ${rid} status=active で直してください)`);
57
- }
58
- }