@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,120 +0,0 @@
1
- import { execFileSync } from "node:child_process";
2
- import { slugify } from "./store/fsutil.ts";
3
- import type { Workspace } from "./store/workspace.ts";
4
- import type { RepoOutput, Task, Workstream } from "../shared/types.ts";
5
- import { repoTargetProblem, requestWorkstreams } from "../shared/workTarget.ts";
6
-
7
- /** 作業先にできない(参照先に無い・参照だけ)。何も変えていない */
8
- export class RepoTargetError extends Error {}
9
-
10
- /** 作業先を確かめる(作業先にできなければ RepoTargetError) */
11
- export function checkRepoTarget(ws: Workspace, repo: string | null | undefined) {
12
- const problem = repoTargetProblem(repo, ws.project);
13
- if (problem) throw new RepoTargetError(problem);
14
- }
15
-
16
- /** 要望のブランチ名(branchPattern。日本語のタイトルは slug にならないので、そのときは区切りごと落とす) */
17
- export function branchName(ws: Workspace, requestId: string, title: string): string {
18
- const slug = slugify(title);
19
- return ws.project.branchPattern.replace("{id}", requestId).replace(slug ? "{slug}" : /[-_/]?\{slug\}/, slug);
20
- }
21
-
22
- /** フォルダの git の実体(共通の .git のディレクトリ)。git でなければ undefined */
23
- function gitIdentity(path: string): string | undefined {
24
- try {
25
- return execFileSync("git", ["rev-parse", "--path-format=absolute", "--git-common-dir"], { cwd: path, encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] }).trim();
26
- } catch {
27
- return undefined;
28
- }
29
- }
30
-
31
- export interface WorkstreamPlan {
32
- /** 新しく割り当てる(参照先の名前 → ブランチと作業ツリー) */
33
- add: Record<string, Workstream>;
34
- /** git でない(書き込めるフォルダ)ので、ブランチを割り当てない */
35
- noGit: string[];
36
- }
37
-
38
- /**
39
- * 作業先の集まりに要るブランチの割当を決める(ファイルは変えない。git のブランチや作業ツリーも作らない)。
40
- * - 既に割り当てたリポジトリは上書きしない
41
- * - git でないフォルダはブランチなし(作業先は残る)
42
- * - リポジトリの中のサブフォルダは、それを含む git のリポジトリを基準にする。別の名前の参照先が同じ git の実体を指し、
43
- * どちらにも割り当てることになるなら、理由を添えて RepoTargetError(同じリポジトリに2本のブランチを作らせない)
44
- * - このマシンのパスが無い参照先は確かめられないので、名前どおりに割り当てる(作業の前にパスを登録してもらう)
45
- */
46
- export function planWorkstreams(ws: Workspace, requestId: string, repos: readonly string[]): WorkstreamPlan {
47
- const request = ws.requests.require(requestId);
48
- const existing = requestWorkstreams(request);
49
- const refs = new Map(ws.refs().map((r) => [r.name, r]));
50
- const identity = (name: string) => {
51
- const r = refs.get(name);
52
- return r?.status === "ok" && r.local ? gitIdentity(r.local) : undefined;
53
- };
54
- const plan: WorkstreamPlan = { add: {}, noGit: [] };
55
- const seen = new Map<string, string>();
56
- for (const [name] of Object.entries(existing)) {
57
- const id = identity(name);
58
- if (id) seen.set(id, name);
59
- }
60
- const branch = branchName(ws, requestId, request.title);
61
- for (const name of new Set(repos)) {
62
- if (existing[name]) continue;
63
- const ref = refs.get(name);
64
- if (ref?.status === "ok" && ref.local) {
65
- const id = identity(name);
66
- if (!id) {
67
- plan.noGit.push(name);
68
- continue;
69
- }
70
- const other = seen.get(id);
71
- if (other && other !== name) {
72
- throw new RepoTargetError(
73
- `作業先「${name}」と「${other}」は同じ git のリポジトリです。1つの要望で同じリポジトリに2本のブランチは割り当てません(作業先をどちらかにそろえてください)`,
74
- );
75
- }
76
- seen.set(id, name);
77
- }
78
- plan.add[name] = { branch };
79
- }
80
- return plan;
81
- }
82
-
83
- /** 割当を要望に書く(足すだけ。既存は消さない) */
84
- export function workstreamPatch(ws: Workspace, requestId: string, plan: WorkstreamPlan): { workstreams?: Record<string, Workstream> } {
85
- const request = ws.requests.require(requestId);
86
- return Object.keys(plan.add).length ? { workstreams: { ...request.workstreams, ...plan.add } } : {};
87
- }
88
-
89
- /** 作業先を足したタスク(手で足した・作業先を変えた)に要る割当を書く */
90
- export async function ensureWorkstreams(ws: Workspace, requestId: string, repos: (string | null | undefined)[], actor?: string) {
91
- const names = repos.filter((r): r is string => !!r);
92
- if (!names.length) return;
93
- const patch = workstreamPatch(ws, requestId, planWorkstreams(ws, requestId, names));
94
- if (Object.keys(patch).length) await ws.requests.update(requestId, patch, { actor });
95
- }
96
-
97
- /** タスクの作業先と、そのリポジトリのブランチ(CLI・画面に出す)。作業先なしは repo: null */
98
- export function taskWork(ws: Workspace, t: Task): { repo: string | null; branch?: string; registered?: boolean } {
99
- const repo = t.repo ?? null;
100
- if (!repo) return { repo: null };
101
- const w = requestWorkstreams(ws.requests.require(t.request))[repo];
102
- const ref = ws.refs().find((r) => r.name === repo);
103
- return { repo, ...(w ? { branch: w.branch } : {}), registered: ref?.status === "ok" };
104
- }
105
-
106
- /** CLI の --repo の値: none / 空 → null(作業先なし)、それ以外は名前 */
107
- export const repoArg = (v: string | undefined): string | null | undefined => (v === undefined ? undefined : v === "" || v === "none" ? null : v);
108
-
109
- /** --repo-output <名前>=<値> を読む(作業先にできる参照先だけ) */
110
- export function parseRepoOutput(ws: Workspace, raw: string): RepoOutput {
111
- const eq = raw.indexOf("=");
112
- if (eq < 1 || !raw.slice(eq + 1).trim()) throw new RepoTargetError(`--repo-output は <参照先の名前>=<成果物> で: ${raw}`);
113
- const repo = raw.slice(0, eq).trim();
114
- checkRepoTarget(ws, repo);
115
- return { repo, output: raw.slice(eq + 1).trim() };
116
- }
117
-
118
- /** 成果物を足す(同じ組は重ねない) */
119
- export const addRepoOutputs = (cur: readonly RepoOutput[], add: readonly RepoOutput[]): RepoOutput[] =>
120
- [...cur, ...add].filter((o, i, all) => all.findIndex((x) => x.repo === o.repo && x.output === o.output) === i);
@@ -1,49 +0,0 @@
1
- import { Hono } from "hono";
2
- import { z } from "zod";
3
- import type { ChatGptAccount } from "../../core/chatgpt.ts";
4
- import type { EngineStatus } from "../../core/preflight/engine.ts";
5
- import { localOnly } from "./local.ts";
6
-
7
- /**
8
- * /api/chatgpt。サインインの待ち受けは serve のプロセスが行う(同時に1つ。ページを読み直しても待っている試行を返す)。
9
- * 返すのは状態だけで、トークンは返さない。
10
- * changed: 接続が変わったことを画面へ知らせる(プロジェクトを跨ぐ serve では開いている全プロジェクトへ)。
11
- * engine: Preflight のエンジンの状態(プロジェクトごと。プロジェクトを選んでいない入口では無い)
12
- */
13
- export function chatgptRoutes(account: ChatGptAccount, opts: { changed: () => void; engine?: () => Promise<EngineStatus> }) {
14
- const app = new Hono();
15
- const changed = opts.changed;
16
- app.use("*", async (c, next) => {
17
- const why = localOnly(c, c.req.method !== "GET");
18
- if (why) return c.json({ error: why }, 403);
19
- await next();
20
- });
21
-
22
- app.get("/", async (c) => c.json({ ...(await account.status()), engine: opts.engine ? await opts.engine() : null }));
23
-
24
- app.post("/login", async (c) => {
25
- const attempt = await account.startLogin();
26
- // 終わったら(成功・失敗・取消・タイムアウト)画面へ知らせる
27
- void attempt.done.finally(changed).catch(() => {});
28
- changed();
29
- return c.json({ url: attempt.url, redirectUri: attempt.redirectUri, expiresAt: attempt.expiresAt }, 201);
30
- });
31
- app.post("/cancel", (c) => {
32
- account.pending()?.cancel();
33
- return c.json({ ok: true });
34
- });
35
- // ブラウザがコールバックに届かない環境: 「接続できません」の画面のアドレスバーの URL を貼ってもらう
36
- app.post("/paste", async (c) => {
37
- const { url } = z.object({ url: z.string() }).parse(await c.req.json());
38
- const attempt = account.pending();
39
- if (!attempt) return c.json({ error: "待っているサインインがありません。もう一度「Continue with ChatGPT」から始めてください" }, 409);
40
- return c.json(await attempt.submit(url));
41
- });
42
- app.post("/logout", async (c) => {
43
- const { forget } = z.object({ forget: z.boolean().optional() }).parse(await c.req.json().catch(() => ({})));
44
- const r = await account.logout({ forget });
45
- changed();
46
- return c.json({ ...r, status: await account.status() });
47
- });
48
- return app;
49
- }
@@ -1,135 +0,0 @@
1
- import { RELATION_TYPES } from "../../shared/types.ts";
2
-
3
- /**
4
- * 自己記述。GET /api/ai/manifest
5
- * この REST API はローカルの画面のためのもので、AI エージェントには CLI を使わせる。
6
- */
7
- export const AI_MANIFEST = {
8
- name: "p3",
9
- description:
10
- "1リポジトリ=1プロジェクトのファイルベースのタスク管理。作業の単位は要望で、要望ごとにフォルダを分ける" +
11
- "(.p3/requests/<要望ID>/request.md, tasks/T001.md, preflight/)。" +
12
- "AI エージェントは `p3` CLI(`p3 help`、`--json` 出力)を使うこと。要望の作業ツリーの中で実行すると、その要望が対象になる。",
13
- refs: {
14
- request: "<要望ID>(例: 261009-k7m3x)",
15
- task: "<要望ID>/T003。同じ要望の中なら T003",
16
- },
17
- relationTypes: RELATION_TYPES, // タスクの関係は depends_on と supersedes だけ(Preflight のタスク化が張る。手で張る API は無い)
18
- endpoints: [
19
- { method: "GET", path: "/api/mode", desc: "serve の形 {mode: single(project: 名前)| all-projects}" },
20
- {
21
- method: "GET",
22
- path: "/api/projects",
23
- desc:
24
- "(all-projects だけ)個人設定を読み直した一覧 {projects: [{name, generation(登録世代), state: ok|error, error?, open}], invalid: [{name, reason}], configError?}。" +
25
- "ここに無い API は /api/projects/:project/... の下に置く(通常の serve の /api/... と同じ)。変える操作には x-p3-project-generation が要る(無ければ 428、違えば 409 code: changed)。" +
26
- "プロジェクトを書かないデータの API は 404 code: project_required。/api/chatgpt(engine は null)・/api/user-theme・/api/events(一覧・テーマ・接続の変更)はプロジェクトを選ばずに使える",
27
- },
28
- { method: "GET", path: "/api/project", desc: "プロジェクト設定" },
29
- {
30
- method: "POST",
31
- path: "/api/reload",
32
- desc:
33
- "データのフォルダ(project.yaml・要望・タスク)を全部読み直し、関係の索引も作り直す。応答 {requests, tasks, errors, loadedAt} は読み直しを終えた後。" +
34
- "読み込み中に呼ぶと、終わってからもう1回読む。project.yaml などが読めなければ 503 で何も変えない。終えたら変更通知 kind: reload",
35
- },
36
- {
37
- method: "GET|POST|PATCH|DELETE",
38
- path: "/api/repos[/:name]",
39
- desc: "参照先(共有の定義)。GET は読めたかの状態と、ローカルの画面にだけこのマシンのパス。POST {name, role?, readFirst?, writable?, map?, path?}",
40
- },
41
- { method: "PUT|DELETE", path: "/api/repos/:name/path", desc: "参照先のこのマシンのパス(個人設定)。このマシンのローカルの画面(Origin)からだけ" },
42
- { method: "GET", path: "/api/requests", desc: "要望の一覧と進捗" },
43
- { method: "POST", path: "/api/requests", desc: "要望の作成" },
44
- { method: "GET", path: "/api/requests/:rid", desc: "要望・タスク・Preflight・置き換えられたタスクの印(superseded)・対応済なのに未完了のタスクがあるときの知らせ(issue)" },
45
- {
46
- method: "PATCH",
47
- path: "/api/requests/:rid",
48
- desc:
49
- "要望の更新(rev で楽観ロック。競合は 409 code: rev_conflict)。タイトル・本文はどの状態でも変えられる(評価のあとで変えるとその評価からはタスク化できない)。" +
50
- "status=resolved(対応済)は全タスクが完了のときだけ。done / rejected は人が決める",
51
- },
52
- { method: "GET|POST", path: "/api/requests/:rid/tasks", desc: "要望のタスク(対応済の要望に未完了のタスクを足すと進行中に戻し reopened を返す)" },
53
- { method: "GET|PATCH|DELETE", path: "/api/requests/:rid/tasks/:tid", desc: "タスク(GET は置き換えの印 superseded も返す。PATCH は rev で楽観ロック、null で項目を消す。置き換えられたタスクを作業中にすると warnings を添える)" },
54
- { method: "POST", path: "/api/requests/:rid/preflight", desc: "Preflight の実行 {engine?: codex|mock, note?: メモ}。前回の結果とまだ渡していないメモを引き継ぐ" },
55
- { method: "GET|POST", path: "/api/requests/:rid/notes", desc: "Preflight へのメモ(GET は渡し済みか・次に引き継ぐ前回の run も返す。POST {body})" },
56
- {
57
- method: "GET",
58
- path: "/api/requests/:rid/preflight/:run/ui/:material",
59
- desc: "画面資料の画像(PNG / JPEG)。資料の一覧は run の ui(items の id・対象のタスク案・説明・前提)。原稿(HTML)は返さない",
60
- },
61
- {
62
- method: "GET|POST",
63
- path: "/api/requests/:rid/attachments",
64
- desc: "要望の添付(PNG / JPEG / xlsx)。POST は multipart {file, description?, source?}。中身で形式を確かめ、件数・容量に上限。次の Preflight を始めるときに run に固定する",
65
- },
66
- { method: "GET|DELETE", path: "/api/requests/:rid/attachments/:aid", desc: "添付の原本(xlsx はダウンロード)・外す(固定済みの過去の run の資料は残る)" },
67
- { method: "GET", path: "/api/requests/:rid/preflight/:run/attachments/:aid", desc: "その run に固定した添付の原本(run の attachments に一覧)" },
68
- { method: "GET", path: "/api/requests/:rid/preflight/:run/attachments/:aid/extract", desc: "その run に固定した xlsx から取り出した内容(Markdown のテキスト)" },
69
- {
70
- method: "GET",
71
- path: "/api/requests/:rid/preflight-status[?run=PF-...]",
72
- desc:
73
- "最新の Preflight と見ている run の今の状態だけ(要望と run.json をディスクから読む。読み込んだ内容・ファイル・rev は変えない。案・ログは返さない)。" +
74
- "{requestId, state: ok|gone|broken, latest: RunPulse|null, run?: RunPulse}。RunPulse は {id, state: ready|pending|missing|broken, status?, startedAt?, finishedAt?, version?}" +
75
- "(pending は保存の途中、version が変われば run を取り直す)。latest は要望の lastPreflight(未実行なら null)。ID の形が違えば 400",
76
- },
77
- {
78
- method: "GET",
79
- path: "/api/requests/:rid/preflight[/:run]",
80
- desc: "Preflight の run。各 run に inputMatch {status: same|changed|unknown, changed?: [title|body], reason?}(評価対象と今の要望が同じか。タグ・期限・ステータスは比べない)",
81
- },
82
- {
83
- method: "PATCH",
84
- path: "/api/requests/:rid/preflight/:run/drafts/:key",
85
- desc:
86
- "タスク案を直す {title?, description?, include?, repo?, expectedTitle?}。expectedTitle(編集を始めたときの題。制御用で案には書かない)を渡すと、" +
87
- "案のファイルを読み直した今の題と比べ、違えば 409 code: rev_conflict(current に今の案)で書かない。画面から題を変えるときは必ず渡す",
88
- },
89
- { method: "GET", path: "/api/requests/:rid/preflight/:run/materialize", desc: "タスク化の確認(採用する案と、置き換えられる既存タスクの候補、inputMatch。何も変えない)" },
90
- {
91
- method: "POST",
92
- path: "/api/requests/:rid/preflight/:run/materialize",
93
- desc:
94
- "採用したタスク案をタスク化 {archive?: [{id, rev}]}(選んだ候補だけアーカイブ)。結果は {tasks, archived, kept}。" +
95
- "評価のあとで要望のタイトル・本文が変わった(か確かめられない)run は 409 code: stale_input {inputMatch} で何も書かない(再評価する)。候補の rev の競合は 409 code: rev_conflict",
96
- },
97
- { method: "GET", path: "/api/release-notes", desc: "マイルストーンごとのリリースノートの有無(ok / invalid / none)・要望の数。project.yaml に無いノートは known: false と警告" },
98
- {
99
- method: "GET",
100
- path: "/api/release-notes/:mid",
101
- desc: "保存したノート {note(本文・出典・版 version), noteError(読めない理由), material(対象の要望・収録の可否・警告・材料の hash), materialChanged(保存のあとで材料が変わった), completion(要望を一括で完了済にできるか {ready, targets, alreadyDone, skipped, blockers, basedOn})}",
102
- },
103
- {
104
- method: "POST",
105
- path: "/api/release-notes/:mid/complete-requests",
106
- desc:
107
- "対応済の要望を一括で完了済にする {basedOn: completion.basedOn}。見送り以外の全要望が全タスク完了のときだけ。タスク(済み)・ノート・マイルストーンは変えない。" +
108
- "材料が変わった・できないときは何も書かずに 409 code: material_changed / blocked {plan}。途中で止まったら 409 code: partial {result: completed, failed, notRun}",
109
- },
110
- {
111
- method: "PUT",
112
- path: "/api/release-notes/:mid",
113
- desc:
114
- "保存 {body, title?, basedOn?(元にした材料の hash), version?(更新は読んだときの版が必須)}。版が違う・既にあるは 409 code: rev_conflict {reason, current}、消えたノートの更新は 404。" +
115
- "要望・マイルストーンの状態は変えない。材料が変わっていれば warnings に material_changed",
116
- },
117
- { method: "GET", path: "/api/release-notes/:mid/export", desc: "保存した本文だけ(Markdown のダウンロード。出典・frontmatter は含めない)" },
118
- {
119
- method: "POST",
120
- path: "/api/release-notes/:mid/generate",
121
- desc: "機能の要約の生成を始める {engine?: codex|mock}(202。保存しない)。材料が無い・上限超えは 400 code: no_material / too_large(Codex は呼ばない)、実行中は 409 code: running",
122
- },
123
- { method: "GET", path: "/api/release-notes/:mid/generations", desc: "このマイルストーンの生成(新しい順。serve のメモリにだけある)" },
124
- {
125
- method: "GET|POST",
126
- path: "/api/release-generations/:id[/cancel]",
127
- desc: "生成1件 {status: running|completed|failed|cancelled, failure?, items(文と出典), markdown(本文の案), warnings, materialChanged, log} / 取り消し",
128
- },
129
- { method: "GET", path: "/api/resolve?q=&request=", desc: "参照・タイトルから対象を特定" },
130
- { method: "GET", path: "/api/chatgpt", desc: "ChatGPT プランの接続の状態(トークンは返さない)。このマシンからだけ" },
131
- { method: "POST", path: "/api/chatgpt/login|cancel|paste|logout", desc: "サインインの開始・取消・コールバックの URL の貼り付け・解除。このマシンのローカルの画面(Origin)からだけ" },
132
- { method: "GET|PUT", path: "/api/user-theme", desc: "画面のテーマ {theme: system|light|dark}(個人設定の ui.theme。このマシンのすべてのプロジェクトで共通。ほかの個人設定は返さない)。PUT はこのマシンのローカルの画面(Origin)からだけ" },
133
- { method: "GET", path: "/api/events", desc: "変更通知 (SSE)。リリースノートは changed/release-note {milestone}、生成は release-generation {id, milestone, status}" },
134
- ],
135
- };
@@ -1,89 +0,0 @@
1
- import { Hono, type Context } from "hono";
2
- import type { P3Context } from "../../core/context.ts";
3
- import { ProjectRegistry, RegistryError } from "../../core/projectRegistry.ts";
4
- import { PROJECT_NAME } from "../../core/userConfig.ts";
5
- import { chatgptRoutes } from "./chatgptRoutes.ts";
6
- import { apiRoutes, eventStream } from "./routes.ts";
7
- import { userThemeRoutes, userThemeScriptRoute } from "./userThemeRoutes.ts";
8
- import { AI_MANIFEST } from "./manifest.ts";
9
-
10
- /** 変える操作に添える登録世代のヘッダー(GET でも添えれば、違うときは断る) */
11
- export const GENERATION_HEADER = "x-p3-project-generation";
12
-
13
- const STATUS: Record<RegistryError["code"], 404 | 409 | 503> = { unknown: 404, changed: 409, duplicate: 409, unavailable: 503 };
14
-
15
- /**
16
- * プロジェクトを跨ぐ serve の API(/api の下)。個人設定に登録した名前だけを扱う。
17
- *
18
- * GET /mode { mode: "all-projects" }
19
- * GET /projects 個人設定を読み直した一覧(登録世代・開けない理由・形の違う登録・個人設定の読めない理由)
20
- * * /projects/:project/... そのプロジェクトの API(通常の serve の /api/... と同じ)。変える操作には登録世代のヘッダーが要る
21
- * GET /events 一覧・テーマ・ChatGPT の接続の変更の知らせ(プロジェクトを選んでいない画面のため)
22
- * /chatgpt・/user-theme・/user-theme.js・/ai/manifest プロジェクトを選ばなくても使える(ローカルだけの操作は今までどおり)
23
- *
24
- * プロジェクトを書かないデータの API(/api/requests など)は 404(code: project_required)で断る。
25
- */
26
- export function projectsRoutes(registry: ProjectRegistry) {
27
- const app = new Hono();
28
- /** 文脈ごとの API(文脈を閉じたら消える) */
29
- const routes = new WeakMap<P3Context, Hono>();
30
- const routesOf = (ctx: P3Context) => {
31
- let r = routes.get(ctx);
32
- if (!r) {
33
- r = new Hono();
34
- r.route("/", apiRoutes(ctx, { notify: (kind) => registry.notify(kind) }));
35
- // 無い API は 404 の JSON(画面の index.html に流さない)
36
- r.all("*", (c) => c.json({ error: `API がありません: ${c.req.method} ${new URL(c.req.url).pathname}` }, 404));
37
- routes.set(ctx, r);
38
- }
39
- return r;
40
- };
41
-
42
- app.get("/mode", (c) => c.json({ mode: "all-projects" }));
43
- app.get("/projects", async (c) => {
44
- c.header("cache-control", "no-store");
45
- return c.json(await registry.refresh());
46
- });
47
- app.get("/events", (c) => eventStream(c, (push) => registry.on((kind) => push({ type: "changed", kind }))));
48
- app.route("/chatgpt", chatgptRoutes(registry.chatgpt, { changed: () => registry.notify("chatgpt") }));
49
- app.route("/user-theme", userThemeRoutes(() => registry.notify("user")));
50
- app.route("/user-theme.js", userThemeScriptRoute());
51
- app.get("/ai/manifest", (c) => c.json(AI_MANIFEST));
52
-
53
- app.all("/projects/:project/*", async (c) => {
54
- const name = c.req.param("project");
55
- if (!PROJECT_NAME.test(name)) return c.json({ error: `プロジェクトの名前が正しくありません: ${name}`, code: "unknown" }, 404);
56
- const generation = c.req.header(GENERATION_HEADER);
57
- const mutating = c.req.method !== "GET" && c.req.method !== "HEAD";
58
- if (mutating && !generation) {
59
- return c.json({ error: `変える操作には登録世代(${GENERATION_HEADER})が要ります。一覧(GET /api/projects)を読んでから送ってください`, code: "generation_required" }, 428);
60
- }
61
- let ctx: P3Context;
62
- try {
63
- ctx = await registry.open(name, generation);
64
- } catch (e) {
65
- if (e instanceof RegistryError) return c.json({ error: e.message, code: e.code }, STATUS[e.code]);
66
- throw e;
67
- }
68
- return forward(c, routesOf(ctx), `/projects/${name}`);
69
- });
70
-
71
- // プロジェクトを書かないデータの API は、どのプロジェクトか分からないので断る
72
- app.all("*", (c) =>
73
- c.json({ error: "プロジェクトを跨ぐ serve では、/api/projects/<名前>/... で対象のプロジェクトを指定してください", code: "project_required" }, 404),
74
- );
75
- return app;
76
- }
77
-
78
- /** /api/projects/<名前> を外して、そのプロジェクトの API へ渡す(接続元の情報 c.env はそのまま。ローカルだけの操作の確かめに使う) */
79
- async function forward(c: Context, target: Hono, prefix: string) {
80
- const url = new URL(c.req.url);
81
- const at = url.pathname.indexOf(prefix);
82
- url.pathname = url.pathname.slice(at + prefix.length) || "/";
83
- const raw = c.req.raw;
84
- const body = raw.method === "GET" || raw.method === "HEAD" ? undefined : raw.body;
85
- // 本文は流れのまま渡す(Node の fetch は流れの本文に duplex: "half" が要る。型の RequestInit には無い)
86
- const init: RequestInit & { duplex?: "half" } = { method: raw.method, headers: raw.headers, body, signal: raw.signal, ...(body ? { duplex: "half" } : {}) };
87
- const req = new Request(url, init);
88
- return target.fetch(req, c.env);
89
- }
@@ -1,89 +0,0 @@
1
- import { Hono, type Context } from "hono";
2
- import { z } from "zod";
3
- import type { P3Context } from "../../core/context.ts";
4
- import { GenerationRejected } from "../../core/releaseNotes/generate.ts";
5
- import { exportReleaseNote, releaseNoteDetail, releaseOverview, saveReleaseNote, startGeneration } from "../../core/releaseNotes/service.ts";
6
- import { ReleaseNoteError } from "../../core/releaseNotes/store.ts";
7
- import { completeMilestoneRequests, CompletionRejected } from "../../core/releaseNotes/completeRequests.ts";
8
-
9
- /**
10
- * リリースノート(画面のため)。規則と保存は core/releaseNotes(CLI の p3 release-notes と同じ)。
11
- *
12
- * GET /release-notes マイルストーンごとのノートの有無
13
- * GET /release-notes/:mid 保存したノートと材料(対象の要望・警告・出典)
14
- * PUT /release-notes/:mid 保存(version 無しは新規、ありは更新。違えば 409 rev_conflict)
15
- * GET /release-notes/:mid/export 保存した本文(Markdown のダウンロード)
16
- * POST /release-notes/:mid/complete-requests 対応済の要望を一括で完了済にする(basedOn 必須。判定は詳細の completion)。
17
- * 頼めなければ何も書かずに 409(material_changed / blocked と今の判定 plan)。
18
- * 途中で止まったら 409 partial と結果(完了済にしたもの・失敗・未実行)
19
- * POST /release-notes/:mid/generate 要約の生成を始める(202。保存しない)
20
- * GET /release-notes/:mid/generations このマイルストーンの生成(新しい順)
21
- * GET /release-generations/:id 生成1件 / POST .../cancel 取り消す
22
- */
23
-
24
- const saveInput = z.object({
25
- body: z.string(),
26
- title: z.string().min(1).optional(),
27
- /** 本文の元にした材料の hash */
28
- basedOn: z.string().optional(),
29
- /** 読んだときの版(更新のときは必須)。無ければ新規 */
30
- version: z.string().optional(),
31
- });
32
-
33
- const actorOf = (c: Context) => c.req.header("x-p3-actor") ?? "human:web";
34
-
35
- export function releaseNoteRoutes(ctx: P3Context) {
36
- const app = new Hono();
37
-
38
- app.onError(async (err, c) => {
39
- if (err instanceof ReleaseNoteError) {
40
- const mid = err.milestone;
41
- if (err.code === "not_found") return c.json({ error: err.message, code: "not_found" }, 404);
42
- if (err.code === "bad_id") return c.json({ error: err.message, code: "bad_id" }, 400);
43
- if (err.code === "invalid") return c.json({ error: err.message, code: "invalid" }, 422);
44
- // 版の競合・既にある: 今のノート(読めれば)を添える。画面は入力を残したまま見比べる
45
- const current = await ctx.ws.releaseNotes.read(mid).catch(() => null);
46
- return c.json({ error: err.message, code: "rev_conflict", reason: err.code, current }, 409);
47
- }
48
- if (err instanceof CompletionRejected) return c.json({ error: err.message, code: err.code, plan: err.plan }, 409);
49
- if (err instanceof GenerationRejected) return c.json({ error: err.message, code: err.code }, err.code === "running" ? 409 : 400);
50
- if (err instanceof z.ZodError) return c.json({ error: "invalid input", issues: err.issues }, 400);
51
- console.error(err);
52
- return c.json({ error: err.message }, 400);
53
- });
54
-
55
- app.get("/release-notes", async (c) => c.json(await releaseOverview(ctx)));
56
- app.get("/release-notes/:mid", async (c) => c.json(await releaseNoteDetail(ctx, c.req.param("mid"))));
57
- app.put("/release-notes/:mid", async (c) => {
58
- const b = saveInput.parse(await c.req.json());
59
- return c.json(await saveReleaseNote(ctx, c.req.param("mid"), b, actorOf(c)));
60
- });
61
- app.get("/release-notes/:mid/export", async (c) => {
62
- const mid = c.req.param("mid");
63
- const body = await exportReleaseNote(ctx, mid);
64
- return c.body(body, 200, {
65
- "Content-Type": "text/markdown; charset=utf-8",
66
- "Content-Disposition": `attachment; filename="release-notes-${mid}.md"`,
67
- "X-Content-Type-Options": "nosniff",
68
- "Cache-Control": "no-store",
69
- });
70
- });
71
- app.post("/release-notes/:mid/complete-requests", async (c) => {
72
- const { basedOn } = z.object({ basedOn: z.string().min(1) }).parse(await c.req.json().catch(() => ({})));
73
- const r = await completeMilestoneRequests(ctx, c.req.param("mid"), basedOn, actorOf(c));
74
- if (r.failed) return c.json({ error: `${r.failed.id} で止まりました: ${r.failed.reason}`, code: "partial", result: r }, 409);
75
- return c.json(r);
76
- });
77
- app.post("/release-notes/:mid/generate", async (c) => {
78
- const { engine } = z.object({ engine: z.enum(["codex", "mock"]).optional() }).parse(await c.req.json().catch(() => ({})));
79
- return c.json(await startGeneration(ctx, c.req.param("mid"), actorOf(c), engine), 202);
80
- });
81
- app.get("/release-notes/:mid/generations", (c) => c.json(ctx.releaseGenerator.list(c.req.param("mid"))));
82
- app.get("/release-generations/:id", (c) => {
83
- const g = ctx.releaseGenerator.get(c.req.param("id"));
84
- return g ? c.json(g) : c.json({ error: `生成がありません: ${c.req.param("id")}(serve を起動し直すと消えます)`, code: "not_found" }, 404);
85
- });
86
- app.post("/release-generations/:id/cancel", (c) => c.json({ cancelled: ctx.releaseGenerator.cancel(c.req.param("id")) }));
87
-
88
- return app;
89
- }
@@ -1,67 +0,0 @@
1
- import { Hono } from "hono";
2
- import { z } from "zod";
3
- import type { P3Context } from "../../core/context.ts";
4
- import { addRepo, checkFolder, removeRepo, setLocalRepoPath, updateRepo } from "../../core/repoAdmin.ts";
5
- import { localOnly } from "./local.ts";
6
-
7
- const mapEntry = z.object({ path: z.string(), role: z.string(), entry: z.string().optional() });
8
- const repoPatch = z
9
- .object({ role: z.string(), readFirst: z.boolean(), writable: z.boolean(), map: z.array(mapEntry) })
10
- .partial();
11
-
12
- /**
13
- * /api/repos: 参照先(設定画面)。共有の定義の追加・変更・削除はプロジェクトの設定と同じく画面から行える。
14
- * このマシンのパス(個人設定)は、P3 を動かしているマシンのローカルの画面からだけ見せ・変える(ほかのマシンに個人のパスを見せない)
15
- */
16
- export function repoRoutes(ctx: P3Context) {
17
- const { ws } = ctx;
18
- const app = new Hono();
19
-
20
- app.get("/", (c) => {
21
- const local = !localOnly(c, false, "このマシンのパス");
22
- return c.json({
23
- local,
24
- registered: !!ctx.projectName,
25
- repos: ws.refs().map((r) => ({
26
- name: r.name,
27
- role: r.role,
28
- readFirst: r.readFirst,
29
- writable: r.writable,
30
- map: r.map,
31
- mount: r.mount,
32
- status: r.status,
33
- ...(local ? { local: r.local ?? null, reason: r.reason ?? null } : {}),
34
- })),
35
- });
36
- });
37
- app.post("/", async (c) => {
38
- const b = repoPatch.extend({ name: z.string(), path: z.string().optional() }).parse(await c.req.json());
39
- if (b.path) {
40
- const why = localOnly(c, true, "このマシンのパスの登録");
41
- if (why) return c.json({ error: why }, 403);
42
- }
43
- const { name, path, ...patch } = b;
44
- // パスを先に確かめる(共有の定義だけ書いて失敗しないように)
45
- if (path) checkFolder(path);
46
- const entry = await addRepo(ws, name, patch);
47
- if (path) await setLocalRepoPath(ws, ctx.projectName, name, path);
48
- return c.json(entry, 201);
49
- });
50
- app.patch("/:name", async (c) => {
51
- return c.json(await updateRepo(ws, c.req.param("name"), repoPatch.parse(await c.req.json())));
52
- });
53
- app.delete("/:name", async (c) => {
54
- await removeRepo(ws, ctx.projectName, c.req.param("name"));
55
- return c.json({ ok: true });
56
- });
57
- for (const method of ["put", "delete"] as const) {
58
- app[method]("/:name/path", async (c) => {
59
- const why = localOnly(c, true, "このマシンのパスの登録");
60
- if (why) return c.json({ error: why }, 403);
61
- const path = method === "put" ? z.object({ path: z.string().min(1) }).parse(await c.req.json()).path : null;
62
- await setLocalRepoPath(ws, ctx.projectName, c.req.param("name"), path);
63
- return c.json({ ok: true });
64
- });
65
- }
66
- return app;
67
- }