@infodb/p3 0.4.0 → 0.6.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 (209) hide show
  1. package/README.md +1 -0
  2. package/bin/p3.mjs +11 -5
  3. package/dist/web/assets/Outputs-CQi0oba1.js +1 -0
  4. package/dist/web/assets/RequestStatus-grC0F_SQ.js +1 -0
  5. package/dist/web/assets/Tabs-BJRGzidj.js +1 -0
  6. package/dist/web/assets/TagInput-DkuISbfK.js +1 -0
  7. package/dist/web/assets/TaskDrawer-CysOMAjG.js +3 -0
  8. package/dist/web/assets/_requestId-BQCwOAbs.js +30 -0
  9. package/dist/web/assets/_requestId-DgSOUH78.js +1 -0
  10. package/dist/web/assets/{ui-DdOGYj9z.js → appCtx-DCiGJFAe.js} +1 -1
  11. package/dist/web/assets/board-BsntpZXP.js +1 -0
  12. package/dist/web/assets/done-Bhxqy7bH.js +1 -0
  13. package/dist/web/assets/index-BF1xMdJo.css +2 -0
  14. package/dist/web/assets/index-BTuEPzgc.js +12 -0
  15. package/dist/web/assets/new-BwknRX3V.js +1 -0
  16. package/dist/web/assets/{preflightInput-DMxqnvF8.js → preflightInput-BAeEJYUK.js} +1 -1
  17. package/dist/web/assets/preload-helper-B40dBmwL.js +1 -0
  18. package/dist/web/assets/progressTree-DgrdDFih.js +1 -0
  19. package/dist/web/assets/release-notes-AgwbykyG.js +3 -0
  20. package/dist/web/assets/requestData-w6fhCYmh.js +1 -0
  21. package/dist/web/assets/routes-Bu3bhOaC.js +3 -0
  22. package/dist/web/assets/settings-BkV8KeQk.js +1 -0
  23. package/dist/web/index.html +4 -4
  24. package/docs/architecture.md +271 -3
  25. package/docs/development.md +22 -9
  26. package/docs/how-to-use.md +83 -7
  27. package/docs/installation.md +8 -6
  28. package/docs/publishing.md +4 -2
  29. package/lib/cli/args.js +172 -0
  30. package/lib/cli/chatgpt.js +70 -0
  31. package/lib/cli/codex.js +30 -0
  32. package/lib/cli/format.js +9 -0
  33. package/{src/cli/help.ts → lib/cli/help.js} +10 -8
  34. package/lib/cli/main.js +327 -0
  35. package/lib/cli/output.js +110 -0
  36. package/lib/cli/preflightCommands.js +301 -0
  37. package/lib/cli/project.js +649 -0
  38. package/lib/cli/readOnly.js +36 -0
  39. package/lib/cli/releaseNotesCommands.js +197 -0
  40. package/lib/cli/render.js +58 -0
  41. package/lib/cli/requestCommands.js +191 -0
  42. package/lib/cli/showView.js +100 -0
  43. package/lib/cli/taskCommands.js +152 -0
  44. package/lib/cli/userConfig.js +64 -0
  45. package/{src/core/chatgpt.ts → lib/core/chatgpt.js} +10 -16
  46. package/lib/core/context.js +41 -0
  47. package/lib/core/hierarchy.js +158 -0
  48. package/lib/core/machineSettings.js +146 -0
  49. package/lib/core/machineSettingsEdit.js +148 -0
  50. package/lib/core/ops.js +120 -0
  51. package/lib/core/preflight/carryover.js +105 -0
  52. package/lib/core/preflight/codexEngine.js +687 -0
  53. package/lib/core/preflight/codexImage.js +61 -0
  54. package/lib/core/preflight/diagnose.js +95 -0
  55. package/lib/core/preflight/engine.js +58 -0
  56. package/lib/core/preflight/input.js +83 -0
  57. package/lib/core/preflight/launch.js +68 -0
  58. package/lib/core/preflight/mockEngine.js +175 -0
  59. package/lib/core/preflight/render.js +304 -0
  60. package/lib/core/preflight/service.js +883 -0
  61. package/lib/core/preflight/split.js +83 -0
  62. package/lib/core/preflight/uiMaterials.js +281 -0
  63. package/lib/core/preflight/uiRender.js +89 -0
  64. package/lib/core/preflight/wireframe.js +63 -0
  65. package/lib/core/preflight/xlsx.js +324 -0
  66. package/lib/core/projectRegistry.js +207 -0
  67. package/lib/core/redact.js +28 -0
  68. package/lib/core/releaseNotes/completeRequests.js +106 -0
  69. package/lib/core/releaseNotes/generate.js +266 -0
  70. package/lib/core/releaseNotes/material.js +141 -0
  71. package/lib/core/releaseNotes/mockSummarizer.js +26 -0
  72. package/lib/core/releaseNotes/service.js +83 -0
  73. package/lib/core/releaseNotes/store.js +209 -0
  74. package/lib/core/repoAdmin.js +82 -0
  75. package/lib/core/repoRefs.js +72 -0
  76. package/lib/core/requestOps.js +164 -0
  77. package/lib/core/requestStatus.js +171 -0
  78. package/lib/core/store/attachments.js +242 -0
  79. package/lib/core/store/collection.js +254 -0
  80. package/lib/core/store/frontmatter.js +18 -0
  81. package/lib/core/store/fsutil.js +84 -0
  82. package/lib/core/store/locate.js +162 -0
  83. package/lib/core/store/normalize.js +152 -0
  84. package/lib/core/store/noteStore.js +59 -0
  85. package/lib/core/store/preflightStore.js +161 -0
  86. package/lib/core/store/projectFile.js +99 -0
  87. package/lib/core/store/workspace.js +320 -0
  88. package/lib/core/supersede.js +69 -0
  89. package/lib/core/userConfig.js +158 -0
  90. package/{src/core/userTheme.ts → lib/core/userTheme.js} +11 -13
  91. package/lib/core/workTargets.js +106 -0
  92. package/lib/server/api/chatgptRoutes.js +46 -0
  93. package/{src/server/api/local.ts → lib/server/api/local.js} +23 -22
  94. package/lib/server/api/manifest.js +147 -0
  95. package/lib/server/api/projectsRoutes.js +82 -0
  96. package/lib/server/api/releaseNoteRoutes.js +88 -0
  97. package/lib/server/api/repoRoutes.js +67 -0
  98. package/lib/server/api/routes.js +416 -0
  99. package/lib/server/api/userThemeRoutes.js +60 -0
  100. package/lib/server/server.js +85 -0
  101. package/lib/shared/dates.js +10 -0
  102. package/{src/shared/directTask.ts → lib/shared/directTask.js} +3 -11
  103. package/lib/shared/hierarchy.js +135 -0
  104. package/lib/shared/milestoneOrder.js +45 -0
  105. package/lib/shared/preflightInput.js +19 -0
  106. package/lib/shared/refs.js +44 -0
  107. package/lib/shared/repos.js +69 -0
  108. package/lib/shared/scopeView.js +39 -0
  109. package/{src/shared/tags.ts → lib/shared/tags.js} +9 -14
  110. package/lib/shared/types.js +74 -0
  111. package/lib/shared/workTarget.js +31 -0
  112. package/package.json +4 -7
  113. package/skills/p3/SKILL.md +10 -0
  114. package/dist/web/assets/Outputs-5Hby-S5Q.js +0 -1
  115. package/dist/web/assets/RequestStatus-CTkGjT02.js +0 -1
  116. package/dist/web/assets/TagInput-Rj3PNOAF.js +0 -1
  117. package/dist/web/assets/TaskDrawer-DtPhiYxP.js +0 -3
  118. package/dist/web/assets/_requestId-CGvAfIkB.js +0 -30
  119. package/dist/web/assets/_requestId-DxfYhgAq.js +0 -1
  120. package/dist/web/assets/board-wt47lfrE.js +0 -1
  121. package/dist/web/assets/done-C9Ct7ssb.js +0 -1
  122. package/dist/web/assets/index-BTFL2rpp.js +0 -12
  123. package/dist/web/assets/index-DAyBsvua.css +0 -2
  124. package/dist/web/assets/new-e4ID2vQV.js +0 -1
  125. package/dist/web/assets/preload-helper-DhIyFaOW.js +0 -1
  126. package/dist/web/assets/release-notes-CQ0d2r0k.js +0 -3
  127. package/dist/web/assets/requestData-BDZqyl35.js +0 -1
  128. package/dist/web/assets/routes-Bipv3lwJ.js +0 -2
  129. package/dist/web/assets/settings-Dwh8fj6p.js +0 -1
  130. package/src/cli/args.ts +0 -186
  131. package/src/cli/chatgpt.ts +0 -74
  132. package/src/cli/codex.ts +0 -28
  133. package/src/cli/format.ts +0 -9
  134. package/src/cli/main.ts +0 -337
  135. package/src/cli/output.ts +0 -117
  136. package/src/cli/preflightCommands.ts +0 -245
  137. package/src/cli/project.ts +0 -675
  138. package/src/cli/readOnly.ts +0 -36
  139. package/src/cli/releaseNotesCommands.ts +0 -198
  140. package/src/cli/render.ts +0 -60
  141. package/src/cli/requestCommands.ts +0 -172
  142. package/src/cli/showView.ts +0 -110
  143. package/src/cli/taskCommands.ts +0 -167
  144. package/src/cli/userConfig.ts +0 -58
  145. package/src/core/context.ts +0 -58
  146. package/src/core/machineSettings.ts +0 -207
  147. package/src/core/machineSettingsEdit.ts +0 -156
  148. package/src/core/ops.ts +0 -114
  149. package/src/core/preflight/carryover.ts +0 -133
  150. package/src/core/preflight/codexEngine.ts +0 -703
  151. package/src/core/preflight/codexImage.ts +0 -98
  152. package/src/core/preflight/diagnose.ts +0 -124
  153. package/src/core/preflight/engine.ts +0 -92
  154. package/src/core/preflight/input.ts +0 -65
  155. package/src/core/preflight/launch.ts +0 -86
  156. package/src/core/preflight/mockEngine.ts +0 -145
  157. package/src/core/preflight/render.ts +0 -339
  158. package/src/core/preflight/service.ts +0 -707
  159. package/src/core/preflight/uiMaterials.ts +0 -272
  160. package/src/core/preflight/uiRender.ts +0 -84
  161. package/src/core/preflight/wireframe.ts +0 -69
  162. package/src/core/preflight/xlsx.ts +0 -328
  163. package/src/core/projectRegistry.ts +0 -264
  164. package/src/core/redact.ts +0 -31
  165. package/src/core/releaseNotes/completeRequests.ts +0 -102
  166. package/src/core/releaseNotes/generate.ts +0 -283
  167. package/src/core/releaseNotes/material.ts +0 -114
  168. package/src/core/releaseNotes/mockSummarizer.ts +0 -28
  169. package/src/core/releaseNotes/service.ts +0 -110
  170. package/src/core/releaseNotes/store.ts +0 -216
  171. package/src/core/repoAdmin.ts +0 -81
  172. package/src/core/repoRefs.ts +0 -90
  173. package/src/core/requestOps.ts +0 -140
  174. package/src/core/requestStatus.ts +0 -58
  175. package/src/core/store/attachments.ts +0 -228
  176. package/src/core/store/collection.ts +0 -282
  177. package/src/core/store/frontmatter.ts +0 -22
  178. package/src/core/store/fsutil.ts +0 -90
  179. package/src/core/store/locate.ts +0 -181
  180. package/src/core/store/normalize.ts +0 -155
  181. package/src/core/store/noteStore.ts +0 -56
  182. package/src/core/store/preflightStore.ts +0 -136
  183. package/src/core/store/projectFile.ts +0 -101
  184. package/src/core/store/workspace.ts +0 -328
  185. package/src/core/supersede.ts +0 -74
  186. package/src/core/userConfig.ts +0 -205
  187. package/src/core/workTargets.ts +0 -120
  188. package/src/server/api/chatgptRoutes.ts +0 -49
  189. package/src/server/api/manifest.ts +0 -135
  190. package/src/server/api/projectsRoutes.ts +0 -89
  191. package/src/server/api/releaseNoteRoutes.ts +0 -89
  192. package/src/server/api/repoRoutes.ts +0 -67
  193. package/src/server/api/routes.ts +0 -382
  194. package/src/server/api/userThemeRoutes.ts +0 -62
  195. package/src/server/server.ts +0 -108
  196. package/src/shared/dates.ts +0 -12
  197. package/src/shared/milestoneOrder.ts +0 -44
  198. package/src/shared/preflightInput.ts +0 -27
  199. package/src/shared/refs.ts +0 -55
  200. package/src/shared/repos.ts +0 -113
  201. package/src/shared/scopeView.ts +0 -48
  202. package/src/shared/types.ts +0 -730
  203. package/src/shared/workTarget.ts +0 -44
  204. /package/{src → lib}/core/preflight/launcher.mjs +0 -0
  205. /package/{src → lib}/core/preflight/mock-ui.html +0 -0
  206. /package/{src → lib}/core/preflight/mock-ui.png +0 -0
  207. /package/{src → lib}/core/preflight/render-image/Dockerfile +0 -0
  208. /package/{src → lib}/core/preflight/render-image/fonts-ja.conf +0 -0
  209. /package/{src → lib}/core/preflight/render-image/render.mjs +0 -0
@@ -1,382 +0,0 @@
1
- import { Hono, type Context } from "hono";
2
- import { streamSSE } from "hono/streaming";
3
- import { z } from "zod";
4
- import { normalizeTaskId } from "../../shared/refs.ts";
5
- import { REQUEST_STATUSES, type Request, type ServerEvent, type Task, TASK_STATUSES, type AttachmentFormat } from "../../shared/types.ts";
6
- import type { P3Context } from "../../core/context.ts";
7
- import { listTasks, progress, resolve } from "../../core/ops.ts";
8
- import { ConflictError, NotFoundError } from "../../core/store/collection.ts";
9
- import { ATTACHMENT_LIMITS, ATTACHMENT_TYPES, AttachmentError, safeFileName } from "../../core/store/attachments.ts";
10
- import { bodyLimit } from "hono/body-limit";
11
- import { ReloadError } from "../../core/store/workspace.ts";
12
- import { resolvedIssue } from "../../core/requestStatus.ts";
13
- import { supersededMarks } from "../../core/supersede.ts";
14
- import { chatgptRoutes } from "./chatgptRoutes.ts";
15
- import { userThemeRoutes, userThemeScriptRoute } from "./userThemeRoutes.ts";
16
- import { UserConfigError } from "../../core/userConfig.ts";
17
- import { AI_MANIFEST } from "./manifest.ts";
18
- import { repoRoutes } from "./repoRoutes.ts";
19
- import { releaseNoteRoutes } from "./releaseNoteRoutes.ts";
20
- import { archiveTask, checkMilestoneRemoval, createRequest, createTask, updateRequest, updateTask } from "../../core/requestOps.ts";
21
- import { StaleInputError } from "../../core/preflight/input.ts";
22
- import { DraftConflictError, PulseInputError } from "../../core/preflight/service.ts";
23
-
24
- /**
25
- * ブラウザ用のローカル API。AI や人の操作は CLI(ファイルを直接読み書き)が主で、ここは画面のため。
26
- *
27
- * /requests 要望(進捗つき)
28
- * /requests/:rid 要望の詳細
29
- * /requests/:rid/tasks[/:tid] 要望のタスク
30
- * /requests/:rid/preflight[/:run] Preflight
31
- * /requests/:rid/notes Preflight へのメモ
32
- * /release-notes[/:mid] マイルストーンのリリースノート(releaseNoteRoutes.ts)
33
- */
34
-
35
- const date = z.string().regex(/^\d{4}-\d{2}-\d{2}$/);
36
- const taskInput = z.object({
37
- title: z.string().min(1),
38
- /** 作業先(参照先の名前)。null は作業先なし */
39
- repo: z.string().nullable().optional(),
40
- repoOutputs: z.array(z.object({ repo: z.string().min(1), output: z.string().min(1) })).optional(),
41
- status: z.enum(TASK_STATUSES).optional(),
42
- labels: z.array(z.string()).optional(),
43
- areas: z.array(z.string()).optional(),
44
- outputs: z.array(z.string()).optional(),
45
- body: z.string().optional(),
46
- /** 変更の記録(Markdown。完了にするときに書く) */
47
- record: z.string().nullable().optional(),
48
- });
49
- /** checked: 完了したタスクに人が「済み」を付ける / 外す */
50
- const taskPatch = taskInput.partial().extend({ rev: z.number().int().optional(), checked: z.boolean().optional() });
51
- const requestInput = z.object({
52
- title: z.string().min(1),
53
- body: z.string().optional(),
54
- areas: z.array(z.string()).optional(),
55
- due: date.nullish(),
56
- milestone: z.string().nullish(),
57
- tags: z.array(z.string()).optional(),
58
- });
59
- const requestPatch = requestInput
60
- .partial()
61
- .extend({ status: z.enum(REQUEST_STATUSES as [string, ...string[]]).optional(), rev: z.number().int().optional() });
62
- const projectPatch = z
63
- .object({
64
- name: z.string().min(1),
65
- description: z.string(),
66
- milestones: z.array(
67
- z.object({
68
- id: z.string().regex(/^[A-Za-z0-9._-]+$/, "マイルストーンの id は英数字と . _ -"),
69
- title: z.string().min(1),
70
- due: date.optional(),
71
- done: z.boolean().optional(),
72
- }),
73
- ),
74
- branchPattern: z.string().includes("{id}"),
75
- preflight: z.object({ instructions: z.string() }),
76
- })
77
- .partial()
78
- .superRefine((p, ctx) => {
79
- for (const [label, ids] of [["マイルストーン", p.milestones?.map((x) => x.id) ?? []]] as const) {
80
- const dup = ids.find((x, i) => ids.indexOf(x) !== i);
81
- if (dup) ctx.addIssue({ code: "custom", message: `${label}の id が重複しています: ${dup}` });
82
- }
83
- });
84
-
85
- /** null は「項目を消す」意味。frontmatter から外すため undefined に変換 */
86
- const unnull = <T extends object>(o: T) =>
87
- Object.fromEntries(Object.entries(o).map(([k, v]) => [k, v === null ? undefined : v])) as {
88
- [K in keyof T]: Exclude<T[K], null>;
89
- };
90
-
91
- /** 誰が変更したか */
92
- const actorOf = (c: Context) => c.req.header("x-p3-actor") ?? "human:web";
93
-
94
- /** 楽観ロック: body.rev か If-Match ヘッダ */
95
- const expectedRev = (c: Context, body: { rev?: number }) => body.rev ?? (c.req.header("if-match") ? Number(c.req.header("if-match")) : undefined);
96
-
97
- /** 原本を返す。xlsx は必ずダウンロードにし、画像も中身を推測させない */
98
- function download(c: Context, data: Buffer, format: AttachmentFormat, name: string) {
99
- const file = safeFileName(name, format);
100
- return c.body(new Uint8Array(data), 200, {
101
- "Content-Type": ATTACHMENT_TYPES[format],
102
- "Content-Disposition": `${format === "xlsx" ? "attachment" : "inline"}; filename="${file.replace(/[^\x20-\x7e]/g, "_")}"; filename*=UTF-8''${encodeURIComponent(file)}`,
103
- "X-Content-Type-Options": "nosniff",
104
- "Content-Security-Policy": "default-src 'none'",
105
- "Cache-Control": "private, no-cache",
106
- });
107
- }
108
-
109
- /**
110
- * notify: プロジェクトに属さない変更(ChatGPT の接続・テーマ)の知らせ方。省くとこのプロジェクトの画面へだけ流す
111
- * (プロジェクトを跨ぐ serve では開いている全プロジェクトへ)
112
- */
113
- export function apiRoutes(ctx: P3Context, opts: { notify?: (kind: "user" | "chatgpt") => void } = {}) {
114
- const { ws, preflight } = ctx;
115
- const notify = opts.notify ?? ((kind: "user" | "chatgpt") => ws.emit({ type: "changed", kind }));
116
- const app = new Hono();
117
-
118
- app.onError((err, c) => {
119
- if (err instanceof NotFoundError) return c.json({ error: err.message }, 404);
120
- // 409 は code で分ける: rev_conflict(読み直してやり直す)/ stale_input(評価のあとで要望が変わった。再評価する)
121
- if (err instanceof DraftConflictError) return c.json({ error: err.message, code: "rev_conflict", current: err.current }, 409);
122
- if (err instanceof StaleInputError) return c.json({ error: err.message, code: err.code, inputMatch: err.match }, 409);
123
- if (err instanceof ConflictError) {
124
- const current = err.id.includes("/") ? ws.task(err.id) : c.req.param("tid") ? ws.tasksOf(c.req.param("rid")!).get(err.id) : ws.requests.get(err.id);
125
- return c.json({ error: err.message, code: "rev_conflict", current }, 409);
126
- }
127
- if (err instanceof z.ZodError) return c.json({ error: "invalid input", issues: err.issues }, 400);
128
- // 個人設定のファイルが読めない・壊れている(ファイルは変えていない)
129
- if (err instanceof UserConfigError) return c.json({ error: err.message }, 500);
130
- // データのフォルダが読めない(メモリ上の状態は変えていない)
131
- if (err instanceof ReloadError) return c.json({ error: err.message }, 503);
132
- console.error(err);
133
- return c.json({ error: err.message }, 400);
134
- });
135
-
136
- /** パスの要望 ID(存在しなければ 404) */
137
- const rid = (c: Context) => ws.requests.require(c.req.param("rid")!).id;
138
- /** パスのタスク ID(T3 / 3 も可) */
139
- const tid = (c: Context) => normalizeTaskId(c.req.param("tid")!) ?? c.req.param("tid")!;
140
-
141
- // --- meta ---------------------------------------------------------------
142
- app.get("/project", (c) =>
143
- c.json({
144
- project: ws.project,
145
- dataDir: ws.dataDir,
146
- engines: preflight.availableEngines(),
147
- defaultEngine: preflight.defaultEngine,
148
- errors: ws.errors(),
149
- }),
150
- );
151
- app.put("/project", async (c) => {
152
- const patch = projectPatch.parse(await c.req.json());
153
- // 使っている要望・リリースノートのあるマイルストーンは消さない(CLI の milestone rm と同じ規則)
154
- if (patch.milestones) await checkMilestoneRemoval(ctx, patch.milestones.map((m) => m.id));
155
- return c.json(await ws.saveProject(patch));
156
- });
157
- app.get("/ai/manifest", (c) => c.json(AI_MANIFEST));
158
- /** 参照先(設定画面。このマシンのパスはローカルの画面からだけ) */
159
- app.route("/repos", repoRoutes(ctx));
160
- /** データのフォルダを全部読み直す(ファイル監視に頼らない取り込み)。終わったら変更通知 kind: "reload" */
161
- app.post("/reload", async (c) => c.json(await ws.reloadAll()));
162
- /** Preflight のエンジンが使えるか(Codex なら Docker・認証・イメージを確かめる) */
163
- app.get("/engine", async (c) => c.json(await preflight.engineStatus()));
164
- if (ctx.chatgpt) app.route("/chatgpt", chatgptRoutes(ctx.chatgpt, { changed: () => notify("chatgpt"), engine: () => preflight.engineStatus() }));
165
- /** 個人設定のテーマ(このマシンのすべてのプロジェクトで共通。ほかの個人設定は扱わない) */
166
- app.route("/user-theme", userThemeRoutes(() => notify("user")));
167
- /** 最初の描画の前に読むスクリプト(index.html の先頭)。テーマだけを埋め込み、キャッシュさせない */
168
- app.route("/user-theme.js", userThemeScriptRoute());
169
-
170
- /** マイルストーンのリリースノート(材料・保存・出力・要約の生成) */
171
- app.route("/", releaseNoteRoutes(ctx));
172
-
173
- // --- requests -------------------------------------------------------------
174
- app.get("/requests", (c) => c.json(progress(ctx)));
175
- app.post("/requests", async (c) => {
176
- const b = unnull(requestInput.parse(await c.req.json()));
177
- return c.json(await createRequest(ctx, b, actorOf(c)), 201);
178
- });
179
- app.get("/requests/:rid", async (c) => {
180
- const id = rid(c);
181
- return c.json({
182
- request: ws.requests.get(id),
183
- tasks: ws.tasksOf(id).list(),
184
- runs: await Promise.all((await preflight.list(id)).map((r) => preflight.withInputMatch(id, r))),
185
- // 対応済なのに未完了のタスクがある(外部の直接編集など)
186
- issue: resolvedIssue(ws, ws.requests.require(id)) ?? null,
187
- // 置き換えられたタスクの印(T001 → 置き換えた側)
188
- superseded: Object.fromEntries(
189
- [...supersededMarks(ws)].filter(([ref]) => ref.startsWith(`${id}/`)).map(([ref, m]) => [ref.slice(id.length + 1), m]),
190
- ),
191
- });
192
- });
193
- app.patch("/requests/:rid", async (c) => {
194
- const { rev, ...patch } = requestPatch.parse(await c.req.json());
195
- return c.json(await updateRequest(ctx, rid(c), unnull(patch) as Partial<Request>, { expectedRev: expectedRev(c, { rev }), actor: actorOf(c) }));
196
- });
197
-
198
- // --- tasks(要望の中) --------------------------------------------------------
199
- app.get("/requests/:rid/tasks", (c) => {
200
- const { status, area, q } = c.req.query();
201
- return c.json(listTasks(ctx, { request: rid(c), status: status?.split(","), area, q }));
202
- });
203
- app.post("/requests/:rid/tasks", async (c) => {
204
- const raw = taskInput.parse(await c.req.json());
205
- const { repo, ...b } = unnull(raw);
206
- // 作業先は null(作業先なし)を残す。書かなければ既定(requestOps.createTask)
207
- const input = { ...b, ...("repo" in raw ? { repo: raw.repo ?? null } : {}) } as Partial<Task> & { title: string };
208
- const { task, reopened } = await createTask(ctx, rid(c), input, actorOf(c));
209
- return c.json(reopened ? { ...task, reopened } : task, 201);
210
- });
211
- app.get("/requests/:rid/tasks/:tid", (c) => {
212
- const task = ws.tasksOf(rid(c)).require(tid(c));
213
- return c.json({ task, superseded: supersededMarks(ws).get(task.ref) ?? [] });
214
- });
215
- app.patch("/requests/:rid/tasks/:tid", async (c) => {
216
- const { rev, checked, ...patch } = taskPatch.parse(await c.req.json());
217
- const next = { ...(unnull(patch) as Partial<Task>), ...("repo" in patch ? { repo: patch.repo ?? null } : {}), ...(checked !== undefined ? { checked } : {}) };
218
- // 置き換えられたタスクを作業中にしたら警告を添える(操作は続ける)
219
- const { task, warnings, reopened } = await updateTask(ctx, rid(c), tid(c), next, { expectedRev: expectedRev(c, { rev }), actor: actorOf(c) });
220
- return c.json({ ...task, ...(warnings.length ? { warnings } : {}), ...(reopened ? { reopened } : {}) });
221
- });
222
- app.delete("/requests/:rid/tasks/:tid", async (c) => {
223
- await archiveTask(ctx, rid(c), tid(c));
224
- return c.json({ ok: true });
225
- });
226
-
227
- // --- preflight ----------------------------------------------------------
228
- app.post("/requests/:rid/preflight", async (c) => {
229
- const body = z
230
- .object({ engine: z.enum(["codex", "mock"]).optional(), note: z.string().optional() })
231
- .parse(await c.req.json().catch(() => ({})));
232
- const id = rid(c);
233
- const actor = actorOf(c);
234
- // メモを書き足してから実行する。実行を始められなくてもメモは残し、その ID を返す(再試行で書き直さない)
235
- const note = body.note?.trim() ? await preflight.addNote(id, body.note, actor) : undefined;
236
- try {
237
- return c.json(await preflight.start(id, { engine: body.engine, actor }), 202);
238
- } catch (e) {
239
- if (!note) throw e;
240
- return c.json({ error: (e as Error).message, note }, 400);
241
- }
242
- });
243
- app.get("/requests/:rid/notes", async (c) => {
244
- const id = rid(c);
245
- const [{ notes, invalid }, carry] = await Promise.all([ws.notes.list(id), preflight.carryover(id)]);
246
- const pending = new Set(carry.notes.map((n) => n.id));
247
- return c.json({
248
- notes: notes.map((n) => ({ ...n, pending: pending.has(n.id) })),
249
- invalid,
250
- previous: carry.previous?.id ?? null,
251
- previousSkipped: carry.previousSkipped ?? null,
252
- });
253
- });
254
- app.post("/requests/:rid/notes", async (c) => {
255
- const { body } = z.object({ body: z.string() }).parse(await c.req.json());
256
- return c.json(await preflight.addNote(rid(c), body, actorOf(c)), 201);
257
- });
258
- // run ごとに、評価対象と今の要望が同じか(inputMatch)を添える
259
- app.get("/requests/:rid/preflight", async (c) => {
260
- const id = rid(c);
261
- return c.json(await Promise.all((await preflight.list(id)).map((r) => preflight.withInputMatch(id, r))));
262
- });
263
- // 最新の Preflight と見ている run の今の状態(ディスクから読むだけ。開いている要望の画面が軽く確かめる)。キャッシュの要望は使わない
264
- app.get("/requests/:rid/preflight-status", async (c) => {
265
- try {
266
- return c.json(await preflight.pulse(c.req.param("rid"), c.req.query("run")));
267
- } catch (e) {
268
- if (e instanceof PulseInputError) return c.json({ error: e.message }, 400);
269
- throw e;
270
- }
271
- });
272
- app.get("/requests/:rid/preflight/:run", async (c) => {
273
- const id = rid(c);
274
- const run = await preflight.get(id, c.req.param("run"));
275
- if (!run) throw new NotFoundError(c.req.param("run"));
276
- return c.json(await preflight.withInputMatch(id, run));
277
- });
278
- // 画面資料の画像(PNG / JPEG)。要望 / run / 資料 ID で決め、パスは受け取らない。原稿(HTML)は配信しない
279
- app.get("/requests/:rid/preflight/:run/ui/:material", async (c) => {
280
- const { data, type } = await preflight.uiImage(rid(c), c.req.param("run"), c.req.param("material"));
281
- return c.body(new Uint8Array(data), 200, {
282
- "Content-Type": type,
283
- "X-Content-Type-Options": "nosniff",
284
- "Content-Security-Policy": "default-src 'none'",
285
- "Cache-Control": "private, max-age=3600",
286
- });
287
- });
288
- // 添付(画像・xlsx)。原本はダウンロードとして返す(画像も画面には ui の資料として出す)
289
- app.get("/requests/:rid/attachments", async (c) => c.json({ ...(await ws.attachments.list(rid(c))), limits: ATTACHMENT_LIMITS }));
290
- app.post("/requests/:rid/attachments", bodyLimit({ maxSize: ATTACHMENT_LIMITS.xlsxBytes + 1024 * 1024, onError: (c) => c.json({ error: "大きすぎます" }, 413) }), async (c) => {
291
- const id = rid(c);
292
- const form = await c.req.parseBody();
293
- const file = form.file;
294
- if (!(file instanceof File)) return c.json({ error: "file(ファイル)を付けてください" }, 400);
295
- const text = (v: unknown) => (typeof v === "string" ? v : undefined);
296
- try {
297
- const a = await preflight.addAttachment(id, { data: Buffer.from(await file.arrayBuffer()), name: file.name, description: text(form.description), source: text(form.source) }, actorOf(c));
298
- return c.json(a, 201);
299
- } catch (e) {
300
- if (e instanceof AttachmentError) return c.json({ error: e.message }, 400);
301
- throw e;
302
- }
303
- });
304
- app.get("/requests/:rid/attachments/:aid", async (c) => {
305
- const { meta, data } = await ws.attachments.content(rid(c), c.req.param("aid")).catch((e) => {
306
- throw e instanceof AttachmentError ? new NotFoundError(e.message) : e;
307
- });
308
- return download(c, data, meta.format, meta.name);
309
- });
310
- app.delete("/requests/:rid/attachments/:aid", async (c) => {
311
- try {
312
- await preflight.removeAttachment(rid(c), c.req.param("aid"));
313
- } catch (e) {
314
- throw e instanceof AttachmentError ? new NotFoundError(e.message) : e;
315
- }
316
- return c.json({ ok: true });
317
- });
318
- app.get("/requests/:rid/preflight/:run/attachments/:aid", async (c) => {
319
- const { meta, data } = await preflight.fixedAttachment(rid(c), c.req.param("run"), c.req.param("aid"));
320
- return download(c, data, meta.format, meta.name);
321
- });
322
- app.get("/requests/:rid/preflight/:run/attachments/:aid/extract", async (c) => {
323
- const text = await preflight.fixedExtract(rid(c), c.req.param("run"), c.req.param("aid"));
324
- return c.body(text, 200, { "Content-Type": "text/plain; charset=utf-8", "X-Content-Type-Options": "nosniff", "Content-Security-Policy": "default-src 'none'" });
325
- });
326
- app.post("/requests/:rid/preflight/:run/cancel", (c) => {
327
- preflight.cancel(c.req.param("run"));
328
- return c.json({ ok: true });
329
- });
330
- app.patch("/requests/:rid/preflight/:run/drafts/:key", async (c) => {
331
- // expectedTitle: 編集を始めたときの題(制御用。案には書かない)。今の題と違えば 409 で書かない
332
- const { expectedTitle, ...patch } = z
333
- .object({ title: z.string(), description: z.string(), include: z.boolean(), repo: z.string().nullable(), expectedTitle: z.string() })
334
- .partial()
335
- .parse(await c.req.json());
336
- return c.json(await preflight.updateDraft(rid(c), c.req.param("run"), c.req.param("key"), patch, { expectedTitle }));
337
- });
338
- app.get("/requests/:rid/preflight/:run/materialize", async (c) => c.json(await preflight.previewMaterialize(rid(c), c.req.param("run"))));
339
- app.post("/requests/:rid/preflight/:run/materialize", async (c) => {
340
- const body = z
341
- .object({ archive: z.array(z.object({ id: z.string(), rev: z.number().int().optional() })).optional() })
342
- .parse(await c.req.json().catch(() => ({})));
343
- return c.json(await preflight.materialize(rid(c), c.req.param("run"), actorOf(c), { archive: body.archive }), 201);
344
- });
345
-
346
- // --- 横断 --------------------------------------------------------------
347
- app.get("/tasks", (c) => {
348
- const { status, area, q } = c.req.query();
349
- return c.json(listTasks(ctx, { status: status?.split(","), area, q }));
350
- });
351
- /** 参照・タイトルから対象を特定する(?request= で今の要望を優先) */
352
- app.get("/resolve", (c) => c.json(resolve(ctx, c.req.query("q") ?? "", c.req.query("request"))));
353
-
354
- // --- events (SSE) ------------------------------------------------------
355
- app.get("/events", (c) => eventStream(c, (push) => ws.on(push)));
356
-
357
- return app;
358
- }
359
-
360
- /** 変更の知らせを SSE で流す(subscribe は知らせを受け取る関数を登録し、外す関数を返す)。25 秒ごとに ping */
361
- export function eventStream(c: Context, subscribe: (push: (e: ServerEvent) => void) => () => void) {
362
- return streamSSE(c, async (stream) => {
363
- const queue: ServerEvent[] = [];
364
- let wake: (() => void) | undefined;
365
- const off = subscribe((e) => {
366
- queue.push(e);
367
- wake?.();
368
- });
369
- stream.onAbort(() => {
370
- off();
371
- wake?.();
372
- });
373
- while (!stream.aborted) {
374
- if (!queue.length) {
375
- await Promise.race([new Promise<void>((r) => (wake = r)), stream.sleep(25000)]);
376
- wake = undefined;
377
- if (!queue.length) await stream.writeSSE({ event: "ping", data: "" });
378
- }
379
- while (queue.length) await stream.writeSSE({ data: JSON.stringify(queue.shift()) });
380
- }
381
- });
382
- }
@@ -1,62 +0,0 @@
1
- import { Hono } from "hono";
2
- import { z } from "zod";
3
- import { THEMES, type Theme } from "../../shared/types.ts";
4
- import { readTheme, writeTheme } from "../../core/userTheme.ts";
5
- import { localOnly } from "./local.ts";
6
-
7
- /**
8
- * /api/user-theme。個人設定のテーマだけを読み書きする(ほかの個人設定は返さない・変えない)。
9
- * GET → { theme }
10
- * PUT { theme } → { theme }。このマシンのローカルの画面からだけ(ChatGPT の接続と同じ確かめ方)
11
- */
12
- export function userThemeRoutes(onChange: () => void = () => {}) {
13
- const app = new Hono();
14
- const input = z.object({ theme: z.enum(THEMES) }).strict();
15
-
16
- app.get("/", async (c) => {
17
- c.header("cache-control", "no-store");
18
- return c.json({ theme: await readTheme() });
19
- });
20
-
21
- app.put("/", async (c) => {
22
- const why = localOnly(c, true, "画面のテーマ");
23
- if (why) return c.json({ error: why }, 403);
24
- const parsed = input.safeParse(await c.req.json().catch(() => undefined));
25
- if (!parsed.success) return c.json({ error: `{ "theme": "${THEMES.join('" | "')}" } だけを送ってください` }, 400);
26
- const theme = await writeTheme(parsed.data.theme);
27
- onChange();
28
- return c.json({ theme });
29
- });
30
- return app;
31
- }
32
-
33
- /**
34
- * 最初の描画の前に読むスクリプト(index.html の先頭。GET /api/user-theme.js)。個人設定のテーマだけを埋め込み、
35
- * html 要素に data-theme・class "dark"・color-scheme を付ける。規則は web/lib/theme.ts の applyTheme と同じ。
36
- * 個人設定が読めなくても、画面は system で起動できるようにする(エラーはスクリプトの中のコメントに残す)。
37
- */
38
- export function themeScript(theme: Theme, note?: string): string {
39
- return `${note ? `/* ${note.replace(/\*\//g, "* /")} */\n` : ""}(function (t) {
40
- var r = document.documentElement, m = false;
41
- try { m = window.matchMedia("(prefers-color-scheme: dark)").matches; } catch (e) {}
42
- var d = t === "dark" || (t === "system" && m);
43
- r.dataset.theme = t;
44
- r.classList.toggle("dark", d);
45
- r.style.colorScheme = d ? "dark" : "light";
46
- })(${JSON.stringify(theme)});
47
- `;
48
- }
49
-
50
- export function userThemeScriptRoute() {
51
- const app = new Hono();
52
- app.get("/", async (c) => {
53
- c.header("content-type", "text/javascript; charset=utf-8");
54
- c.header("cache-control", "no-store");
55
- try {
56
- return c.body(themeScript(await readTheme()));
57
- } catch (e) {
58
- return c.body(themeScript("system", `個人設定のテーマを読めませんでした: ${(e as Error).message}`));
59
- }
60
- });
61
- return app;
62
- }
@@ -1,108 +0,0 @@
1
- import { serve, type ServerType } from "@hono/node-server";
2
- import { serveStatic } from "@hono/node-server/serve-static";
3
- import { Hono } from "hono";
4
- import { existsSync } from "node:fs";
5
- import { relative } from "node:path";
6
- import { apiRoutes } from "./api/routes.ts";
7
- import { projectsRoutes } from "./api/projectsRoutes.ts";
8
- import { chatgptAccount } from "../core/chatgpt.ts";
9
- import { openProject, P3_ROOT, type P3Context } from "../core/context.ts";
10
- import { machineSettingsSource, type MachineSettings, type SettingsSource } from "../core/machineSettings.ts";
11
- import { ProjectRegistry } from "../core/projectRegistry.ts";
12
-
13
- export interface ServeOptions {
14
- /** 1つのプロジェクトのデータのフォルダ(allProjects のときは使わない) */
15
- dataDir?: string;
16
- /** 参照先の名前 → このマシンのパス(個人設定) */
17
- repos?: Record<string, string>;
18
- /** 個人設定に登録したプロジェクト名(設定画面で参照先のこのマシンのパスを書くため) */
19
- projectName?: string;
20
- /** 個人設定に登録したプロジェクトを跨いで扱う(p3 serve --all-projects) */
21
- allProjects?: boolean;
22
- port: number;
23
- host: string;
24
- /** ビルド済みの画面 (dist/web) も配信する */
25
- static: boolean;
26
- /** マシンごとの設定(省くと環境変数と個人設定から、Preflight を始めるたびに読む) */
27
- settings?: MachineSettings | SettingsSource;
28
- }
29
-
30
- export interface RunningServer {
31
- /**
32
- * 止める。新しい接続を断り、開いている接続(SSE を含む)を閉じ、実行中の Preflight・生成を取り消して終わるまで待つ
33
- * (timeoutMs まで)。監視を外す。待ちきれなかった実行の数を返す
34
- */
35
- close(opts?: { timeoutMs?: number }): Promise<{ pending: number }>;
36
- }
37
-
38
- /** 1つのプロジェクトの API(通常の serve)。/api の下 */
39
- export function singleProjectApp(ctx: P3Context) {
40
- const app = new Hono();
41
- app.get("/mode", (c) => c.json({ mode: "single", project: ctx.projectName ?? null }));
42
- app.route("/", apiRoutes(ctx));
43
- // 無い API は画面(index.html)に流さない
44
- app.all("*", (c) => c.json({ error: `API がありません: ${c.req.method} ${new URL(c.req.url).pathname}` }, 404));
45
- return app;
46
- }
47
-
48
- /** ブラウザ用のローカルサーバ。ファイルを監視して画面へ流すビューア兼エディタ */
49
- export async function startServer(opts: ServeOptions): Promise<RunningServer> {
50
- const app = new Hono();
51
- let ctx: P3Context | undefined;
52
- let registry: ProjectRegistry | undefined;
53
- if (opts.allProjects) {
54
- const settings = !opts.settings ? machineSettingsSource() : "get" in opts.settings ? opts.settings : { path: "", get: async () => opts.settings as MachineSettings };
55
- registry = new ProjectRegistry({ settings, chatgpt: chatgptAccount() });
56
- await registry.refresh();
57
- app.route("/api", projectsRoutes(registry));
58
- } else {
59
- if (!opts.dataDir) throw new Error("serve: データのフォルダが決まっていません");
60
- ctx = await openProject(opts.dataDir, { repos: opts.repos, settings: opts.settings, projectName: opts.projectName });
61
- void ctx.ws.watch();
62
- app.route("/api", singleProjectApp(ctx));
63
- }
64
- if (opts.static) {
65
- // serveStatic の root はカレントからの相対で解釈される
66
- const root = relative(process.cwd(), `${P3_ROOT}dist/web`) || ".";
67
- app.use("/*", serveStatic({ root }));
68
- app.get("*", serveStatic({ path: `${root}/index.html` }));
69
- }
70
-
71
- const server: ServerType = serve({ fetch: app.fetch, port: opts.port, hostname: opts.host }, () => {
72
- if (registry) {
73
- const l = registry.list();
74
- console.log("p3: プロジェクトを跨ぐ serve(--all-projects)");
75
- console.log(` projects ${l.projects.map((p) => p.name).join(", ") || "(登録なし。p3 init / p3 join で登録して、画面の一覧を読み直す)"}`);
76
- if (l.configError) console.log(` ⚠ ${l.configError}`);
77
- for (const i of l.invalid) console.log(` ⚠ 使えない登録 ${i.name}: ${i.reason}`);
78
- } else if (ctx) {
79
- console.log(`p3: ${ctx.ws.project.name}`);
80
- console.log(` data ${opts.dataDir}`);
81
- console.log(` repos ${ctx.ws.project.repos.map((r) => r.name).join(", ") || "(なし)"}`);
82
- console.log(` engines ${ctx.preflight.availableEngines().join(", ")} (default: ${ctx.preflight.defaultEngine})`);
83
- }
84
- console.log(` listen http://${opts.host}:${opts.port}${opts.static ? "" : " (api only)"}`);
85
- if (opts.static && !existsSync(`${P3_ROOT}dist/web/index.html`)) {
86
- console.log(` ⚠ 画面がビルドされていません。${P3_ROOT} で \`pnpm build\` を実行してください`);
87
- }
88
- });
89
-
90
- return {
91
- async close({ timeoutMs = 10_000 } = {}) {
92
- // 新しい接続を断り、開いている接続(SSE)を閉じる
93
- const closed = new Promise<void>((r) => server.close(() => r()));
94
- (server as { closeAllConnections?: () => void }).closeAllConnections?.();
95
- let pending = 0;
96
- if (registry) pending = (await registry.close({ timeoutMs })).pending;
97
- else if (ctx) {
98
- const c = ctx;
99
- const settle = Promise.all([c.preflight.settle({ cancel: true }), c.releaseGenerator.settle({ cancel: true })]).then(() => false);
100
- const timedOut = await Promise.race([settle, new Promise<boolean>((r) => setTimeout(() => r(true), timeoutMs).unref())]);
101
- c.ws.close();
102
- pending = timedOut ? c.preflight.running() + c.releaseGenerator.running() : 0;
103
- }
104
- await Promise.race([closed, new Promise<void>((r) => setTimeout(r, 1000).unref())]);
105
- return { pending };
106
- },
107
- };
108
- }
@@ -1,12 +0,0 @@
1
- /** 今日(ローカル時刻の日付 YYYY-MM-DD。UTC だと日本の朝は前日になる) */
2
- export function localToday(now = new Date()): string {
3
- const p2 = (n: number) => String(n).padStart(2, "0");
4
- return `${now.getFullYear()}-${p2(now.getMonth() + 1)}-${p2(now.getDate())}`;
5
- }
6
-
7
- export const isDate = (s: string) => /^\d{4}-\d{2}-\d{2}$/.test(s);
8
-
9
- /** 期限までの日数(過ぎていれば負) */
10
- export function daysUntil(due: string, today = localToday()): number {
11
- return Math.round((Date.parse(`${due}T00:00:00Z`) - Date.parse(`${today}T00:00:00Z`)) / 86_400_000);
12
- }
@@ -1,44 +0,0 @@
1
- /**
2
- * マイルストーンの表示の順: ID のバージョンの降順(新しいものが先)。CLI・API・画面のどの一覧・選ぶ欄でも使う。
3
- * 保存してある順(project.yaml)は変えない(表示のたびに並べる)。
4
- *
5
- * - 比べるのは ID だけ(タイトル・期限・リリース済みかは見ない)
6
- * - 先頭の v / V は比べるときだけ外す。数字の続きは数として比べる(0.10.0 > 0.9.0、v2.0 > v1.10 > v1.9)
7
- * - バージョンでない ID も同じ規則で比べる(厳密な SemVer のプレリリースの順は持たない)
8
- * - それでも同じなら、元の ID の文字列で決める(登録の順によらない)
9
- */
10
- export function compareMilestoneIds(a: string, b: string): number {
11
- const ta = tokens(a);
12
- const tb = tokens(b);
13
- for (let i = 0; i < Math.min(ta.length, tb.length); i++) {
14
- const c = compareToken(ta[i], tb[i]);
15
- if (c) return -c;
16
- }
17
- if (ta.length !== tb.length) return tb.length - ta.length;
18
- return a < b ? 1 : a > b ? -1 : 0;
19
- }
20
-
21
- /** ID の降順に並べた新しい配列(元の配列は変えない) */
22
- export function sortMilestones<T extends { id: string }>(list: readonly T[]): T[] {
23
- return [...list].sort((x, y) => compareMilestoneIds(x.id, y.id));
24
- }
25
-
26
- /** 数字の続きと、それ以外の続きに分ける(先頭の v / V は外す) */
27
- function tokens(id: string): string[] {
28
- return id.replace(/^[vV]/, "").match(/\d+|\D+/g) ?? [];
29
- }
30
-
31
- /** 昇順の比較。数字どうしは数として(桁の多いほうが大きい。先頭の 0 は除く)、それ以外は文字列として */
32
- function compareToken(a: string, b: string): number {
33
- const da = /^\d/.test(a);
34
- const db = /^\d/.test(b);
35
- if (da && db) {
36
- const na = a.replace(/^0+(?=\d)/, "");
37
- const nb = b.replace(/^0+(?=\d)/, "");
38
- if (na.length !== nb.length) return na.length - nb.length;
39
- return na < nb ? -1 : na > nb ? 1 : 0;
40
- }
41
- // 数字の続きと文字の続きでは、数字を小さいとする(どちらかに決めて順を一意にする)
42
- if (da !== db) return da ? -1 : 1;
43
- return a < b ? -1 : a > b ? 1 : 0;
44
- }
@@ -1,27 +0,0 @@
1
- import type { PreflightInput, PreflightRun } from "./types.ts";
2
-
3
- /**
4
- * Preflight の評価対象(要望のタイトルと本文)の規則。サーバ(固定・比較・タスク化の判定)と画面(下書き)で同じものを使う。
5
- *
6
- * 正規化: 改行を LF にそろえ、前後の空白・空行を除く。要望のファイルは保存するときに本文の前後を除くので
7
- * (core/store/frontmatter.ts)、保存の形の違いだけで変わったことにしない。行末の空白(Markdown の改行)や途中の空行は残して比べる。
8
- */
9
- export function normalizeText(s: string): string {
10
- return s.replace(/\r\n?/g, "\n").trim();
11
- }
12
-
13
- export function normalizeInput(r: { title: string; body: string }): PreflightInput {
14
- return { title: normalizeText(r.title), body: normalizeText(r.body) };
15
- }
16
-
17
- /** 保存すると同じになる本文か */
18
- export const sameText = (a: string, b: string) => normalizeText(a) === normalizeText(b);
19
-
20
- const FIELD_LABEL = { title: "タイトル", body: "本文" } as const;
21
-
22
- /** 変わった項目の表示(「タイトルと本文」) */
23
- export const changedLabel = (fields: readonly (keyof PreflightInput)[] | undefined) => (fields ?? []).map((k) => FIELD_LABEL[k]).join("と");
24
-
25
- /** この run からのタスク化が終わっている(途中で止まったものは含めない) */
26
- export const isMaterialized = (run: Pick<PreflightRun, "materialized" | "materialization">) =>
27
- !!run.materialized?.length && run.materialization?.done !== false;