@infodb/p3 0.0.0-stage → 0.2.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.
- package/LICENSE +21 -0
- package/README.md +56 -2
- package/bin/p3.mjs +18 -0
- package/dist/web/apple-touch-icon.png +0 -0
- package/dist/web/assets/Outputs-Ni3pNuGU.js +1 -0
- package/dist/web/assets/RequestStatus-K8TZwpur.js +1 -0
- package/dist/web/assets/TagInput-BICKVH2x.js +1 -0
- package/dist/web/assets/TaskDrawer-BkDIstIN.js +3 -0
- package/dist/web/assets/_requestId-B5O_ytaq.js +1 -0
- package/dist/web/assets/_requestId-C66puEMO.js +30 -0
- package/dist/web/assets/action-CMjATXqv.js +1 -0
- package/dist/web/assets/board-CbfDjkls.js +1 -0
- package/dist/web/assets/copy-B1ZbihKL.js +2 -0
- package/dist/web/assets/done-CPQbCFHg.js +1 -0
- package/dist/web/assets/draft-dT3gLDIt.js +1 -0
- package/dist/web/assets/format-DuK6P1hb.js +1 -0
- package/dist/web/assets/index-BUcs2J6N.js +12 -0
- package/dist/web/assets/index-C3DkqwJ9.css +2 -0
- package/dist/web/assets/link-_s8ndNKS.js +1 -0
- package/dist/web/assets/new-T60RB7de.js +1 -0
- package/dist/web/assets/preload-helper-dXqN7N-I.js +1 -0
- package/dist/web/assets/release-notes-DxrPhDbt.js +3 -0
- package/dist/web/assets/requestData-D8ZiSZss.js +1 -0
- package/dist/web/assets/rolldown-runtime-hePW80VL.js +1 -0
- package/dist/web/assets/routes-D9ZxXoLk.js +2 -0
- package/dist/web/assets/search-CJ8MBKTz.js +1 -0
- package/dist/web/assets/settings-DsHVyqzJ.js +1 -0
- package/dist/web/assets/supersede-CLXlhCq0.js +1 -0
- package/dist/web/assets/ui-Cvke4y4X.js +1 -0
- package/dist/web/favicon.ico +0 -0
- package/dist/web/favicon.svg +12 -0
- package/dist/web/index.html +23 -0
- package/docs/architecture.md +591 -0
- package/docs/chatgpt-sign-in.md +163 -0
- package/docs/development.md +194 -0
- package/docs/how-to-use.md +524 -0
- package/docs/installation.md +284 -0
- package/docs/publishing.md +65 -0
- package/package.json +86 -3
- package/skills/p3/SKILL.md +95 -0
- package/src/cli/args.ts +179 -0
- package/src/cli/chatgpt.ts +74 -0
- package/src/cli/codex.ts +28 -0
- package/src/cli/format.ts +9 -0
- package/src/cli/help.ts +99 -0
- package/src/cli/main.ts +267 -0
- package/src/cli/output.ts +99 -0
- package/src/cli/preflightCommands.ts +237 -0
- package/src/cli/project.ts +508 -0
- package/src/cli/readOnly.ts +36 -0
- package/src/cli/releaseNotesCommands.ts +139 -0
- package/src/cli/render.ts +60 -0
- package/src/cli/requestCommands.ts +170 -0
- package/src/cli/showView.ts +110 -0
- package/src/cli/taskCommands.ts +167 -0
- package/src/cli/userConfig.ts +58 -0
- package/src/core/chatgpt.ts +33 -0
- package/src/core/context.ts +57 -0
- package/src/core/machineSettings.ts +207 -0
- package/src/core/machineSettingsEdit.ts +156 -0
- package/src/core/ops.ts +114 -0
- package/src/core/preflight/carryover.ts +133 -0
- package/src/core/preflight/codexEngine.ts +702 -0
- package/src/core/preflight/codexImage.ts +98 -0
- package/src/core/preflight/diagnose.ts +124 -0
- package/src/core/preflight/engine.ts +92 -0
- package/src/core/preflight/input.ts +65 -0
- package/src/core/preflight/launch.ts +86 -0
- package/src/core/preflight/launcher.mjs +75 -0
- package/src/core/preflight/mock-ui.html +24 -0
- package/src/core/preflight/mock-ui.png +0 -0
- package/src/core/preflight/mockEngine.ts +145 -0
- package/src/core/preflight/render-image/Dockerfile +23 -0
- package/src/core/preflight/render-image/render.mjs +53 -0
- package/src/core/preflight/render.ts +336 -0
- package/src/core/preflight/service.ts +690 -0
- package/src/core/preflight/uiMaterials.ts +272 -0
- package/src/core/preflight/uiRender.ts +84 -0
- package/src/core/preflight/wireframe.ts +69 -0
- package/src/core/preflight/xlsx.ts +328 -0
- package/src/core/redact.ts +31 -0
- package/src/core/releaseNotes/generate.ts +271 -0
- package/src/core/releaseNotes/material.ts +114 -0
- package/src/core/releaseNotes/mockSummarizer.ts +28 -0
- package/src/core/releaseNotes/service.ts +106 -0
- package/src/core/releaseNotes/store.ts +216 -0
- package/src/core/repoAdmin.ts +81 -0
- package/src/core/repoRefs.ts +90 -0
- package/src/core/requestOps.ts +140 -0
- package/src/core/requestStatus.ts +58 -0
- package/src/core/store/attachments.ts +228 -0
- package/src/core/store/collection.ts +282 -0
- package/src/core/store/frontmatter.ts +22 -0
- package/src/core/store/fsutil.ts +90 -0
- package/src/core/store/locate.ts +181 -0
- package/src/core/store/normalize.ts +155 -0
- package/src/core/store/noteStore.ts +56 -0
- package/src/core/store/preflightStore.ts +136 -0
- package/src/core/store/projectFile.ts +101 -0
- package/src/core/store/workspace.ts +328 -0
- package/src/core/supersede.ts +74 -0
- package/src/core/userConfig.ts +180 -0
- package/src/core/userTheme.ts +22 -0
- package/src/core/workTargets.ts +120 -0
- package/src/server/api/chatgptRoutes.ts +48 -0
- package/src/server/api/local.ts +33 -0
- package/src/server/api/manifest.ts +119 -0
- package/src/server/api/releaseNoteRoutes.ts +78 -0
- package/src/server/api/repoRoutes.ts +67 -0
- package/src/server/api/routes.ts +374 -0
- package/src/server/api/userThemeRoutes.ts +62 -0
- package/src/server/server.ts +49 -0
- package/src/shared/dates.ts +12 -0
- package/src/shared/preflightInput.ts +27 -0
- package/src/shared/refs.ts +55 -0
- package/src/shared/repos.ts +113 -0
- package/src/shared/scopeView.ts +48 -0
- package/src/shared/tags.ts +27 -0
- package/src/shared/types.ts +700 -0
- package/src/shared/workTarget.ts +44 -0
|
@@ -0,0 +1,120 @@
|
|
|
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);
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Hono } from "hono";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import type { ChatGptAccount } from "../../core/chatgpt.ts";
|
|
4
|
+
import type { PreflightService } from "../../core/preflight/service.ts";
|
|
5
|
+
import type { Workspace } from "../../core/store/workspace.ts";
|
|
6
|
+
import { localOnly } from "./local.ts";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* /api/chatgpt。サインインの待ち受けは serve のプロセスが行う(同時に1つ。ページを読み直しても待っている試行を返す)。
|
|
10
|
+
* 返すのは状態だけで、トークンは返さない。
|
|
11
|
+
*/
|
|
12
|
+
export function chatgptRoutes(account: ChatGptAccount, ws: Workspace, preflight: PreflightService) {
|
|
13
|
+
const app = new Hono();
|
|
14
|
+
const changed = () => ws.emit({ type: "changed", kind: "chatgpt" });
|
|
15
|
+
app.use("*", async (c, next) => {
|
|
16
|
+
const why = localOnly(c, c.req.method !== "GET");
|
|
17
|
+
if (why) return c.json({ error: why }, 403);
|
|
18
|
+
await next();
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
app.get("/", async (c) => c.json({ ...(await account.status()), engine: await preflight.engineStatus() }));
|
|
22
|
+
|
|
23
|
+
app.post("/login", async (c) => {
|
|
24
|
+
const attempt = await account.startLogin();
|
|
25
|
+
// 終わったら(成功・失敗・取消・タイムアウト)画面へ知らせる
|
|
26
|
+
void attempt.done.finally(changed).catch(() => {});
|
|
27
|
+
changed();
|
|
28
|
+
return c.json({ url: attempt.url, redirectUri: attempt.redirectUri, expiresAt: attempt.expiresAt }, 201);
|
|
29
|
+
});
|
|
30
|
+
app.post("/cancel", (c) => {
|
|
31
|
+
account.pending()?.cancel();
|
|
32
|
+
return c.json({ ok: true });
|
|
33
|
+
});
|
|
34
|
+
// ブラウザがコールバックに届かない環境: 「接続できません」の画面のアドレスバーの URL を貼ってもらう
|
|
35
|
+
app.post("/paste", async (c) => {
|
|
36
|
+
const { url } = z.object({ url: z.string() }).parse(await c.req.json());
|
|
37
|
+
const attempt = account.pending();
|
|
38
|
+
if (!attempt) return c.json({ error: "待っているサインインがありません。もう一度「Continue with ChatGPT」から始めてください" }, 409);
|
|
39
|
+
return c.json(await attempt.submit(url));
|
|
40
|
+
});
|
|
41
|
+
app.post("/logout", async (c) => {
|
|
42
|
+
const { forget } = z.object({ forget: z.boolean().optional() }).parse(await c.req.json().catch(() => ({})));
|
|
43
|
+
const r = await account.logout({ forget });
|
|
44
|
+
changed();
|
|
45
|
+
return c.json({ ...r, status: await account.status() });
|
|
46
|
+
});
|
|
47
|
+
return app;
|
|
48
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { getConnInfo } from "@hono/node-server/conninfo";
|
|
2
|
+
import type { Context } from "hono";
|
|
3
|
+
|
|
4
|
+
const LOOPBACK_ADDR = new Set(["127.0.0.1", "::1", "::ffff:127.0.0.1"]);
|
|
5
|
+
const LOOPBACK_HOST = new Set(["localhost", "127.0.0.1", "[::1]"]);
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* ローカルだけの API(ChatGPT の接続・個人設定のテーマ)を受けてよいか。serve は既定で 0.0.0.0 で待つので、LAN の別のマシンから
|
|
9
|
+
* サインインの開始・解除をされたり、アカウントを読まれたりしないようにする(P3 自体に本人認証は無い)。
|
|
10
|
+
* - 接続元が自分のマシン(127.0.0.1 / ::1。DevContainer の VS Code の転送もこれになる)
|
|
11
|
+
* - 変更は Origin が必須で、ローカルのページ(localhost / 127.0.0.1 / [::1])から。Origin が無いだけでは通さない
|
|
12
|
+
* (別のサイトのページや DNS rebinding からの要求を断る。Vite の開発用の proxy は Host を書き換えるので Host とは比べない)
|
|
13
|
+
*/
|
|
14
|
+
export function localOnly(c: Context, mutating: boolean, what = "ChatGPT の接続"): string | undefined {
|
|
15
|
+
let addr: string | undefined;
|
|
16
|
+
try {
|
|
17
|
+
addr = getConnInfo(c).remote.address;
|
|
18
|
+
} catch {
|
|
19
|
+
addr = undefined;
|
|
20
|
+
}
|
|
21
|
+
if (!addr || !LOOPBACK_ADDR.has(addr)) return `${what}は、P3 を動かしているマシンからだけ操作できます`;
|
|
22
|
+
if (!mutating) return undefined;
|
|
23
|
+
const origin = c.req.header("origin");
|
|
24
|
+
let host: string | undefined;
|
|
25
|
+
try {
|
|
26
|
+
host = origin ? new URL(origin).hostname : undefined;
|
|
27
|
+
} catch {
|
|
28
|
+
host = undefined;
|
|
29
|
+
}
|
|
30
|
+
if (!host || !LOOPBACK_HOST.has(host === "::1" ? "[::1]" : host)) return "この操作はローカルの P3 の画面からだけ行えます";
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
|
|
@@ -0,0 +1,119 @@
|
|
|
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/project", desc: "プロジェクト設定" },
|
|
20
|
+
{
|
|
21
|
+
method: "POST",
|
|
22
|
+
path: "/api/reload",
|
|
23
|
+
desc:
|
|
24
|
+
"データのフォルダ(project.yaml・要望・タスク)を全部読み直し、関係の索引も作り直す。応答 {requests, tasks, errors, loadedAt} は読み直しを終えた後。" +
|
|
25
|
+
"読み込み中に呼ぶと、終わってからもう1回読む。project.yaml などが読めなければ 503 で何も変えない。終えたら変更通知 kind: reload",
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
method: "GET|POST|PATCH|DELETE",
|
|
29
|
+
path: "/api/repos[/:name]",
|
|
30
|
+
desc: "参照先(共有の定義)。GET は読めたかの状態と、ローカルの画面にだけこのマシンのパス。POST {name, role?, readFirst?, writable?, map?, path?}",
|
|
31
|
+
},
|
|
32
|
+
{ method: "PUT|DELETE", path: "/api/repos/:name/path", desc: "参照先のこのマシンのパス(個人設定)。このマシンのローカルの画面(Origin)からだけ" },
|
|
33
|
+
{ method: "GET", path: "/api/requests", desc: "要望の一覧と進捗" },
|
|
34
|
+
{ method: "POST", path: "/api/requests", desc: "要望の作成" },
|
|
35
|
+
{ method: "GET", path: "/api/requests/:rid", desc: "要望・タスク・Preflight・置き換えられたタスクの印(superseded)・対応済なのに未完了のタスクがあるときの知らせ(issue)" },
|
|
36
|
+
{
|
|
37
|
+
method: "PATCH",
|
|
38
|
+
path: "/api/requests/:rid",
|
|
39
|
+
desc:
|
|
40
|
+
"要望の更新(rev で楽観ロック。競合は 409 code: rev_conflict)。タイトル・本文はどの状態でも変えられる(評価のあとで変えるとその評価からはタスク化できない)。" +
|
|
41
|
+
"status=resolved(対応済)は全タスクが完了のときだけ。done / rejected は人が決める",
|
|
42
|
+
},
|
|
43
|
+
{ method: "GET|POST", path: "/api/requests/:rid/tasks", desc: "要望のタスク(対応済の要望に未完了のタスクを足すと進行中に戻し reopened を返す)" },
|
|
44
|
+
{ method: "GET|PATCH|DELETE", path: "/api/requests/:rid/tasks/:tid", desc: "タスク(GET は置き換えの印 superseded も返す。PATCH は rev で楽観ロック、null で項目を消す。置き換えられたタスクを作業中にすると warnings を添える)" },
|
|
45
|
+
{ method: "POST", path: "/api/requests/:rid/preflight", desc: "Preflight の実行 {engine?: codex|mock, note?: メモ}。前回の結果とまだ渡していないメモを引き継ぐ" },
|
|
46
|
+
{ method: "GET|POST", path: "/api/requests/:rid/notes", desc: "Preflight へのメモ(GET は渡し済みか・次に引き継ぐ前回の run も返す。POST {body})" },
|
|
47
|
+
{
|
|
48
|
+
method: "GET",
|
|
49
|
+
path: "/api/requests/:rid/preflight/:run/ui/:material",
|
|
50
|
+
desc: "画面資料の画像(PNG / JPEG)。資料の一覧は run の ui(items の id・対象のタスク案・説明・前提)。原稿(HTML)は返さない",
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
method: "GET|POST",
|
|
54
|
+
path: "/api/requests/:rid/attachments",
|
|
55
|
+
desc: "要望の添付(PNG / JPEG / xlsx)。POST は multipart {file, description?, source?}。中身で形式を確かめ、件数・容量に上限。次の Preflight を始めるときに run に固定する",
|
|
56
|
+
},
|
|
57
|
+
{ method: "GET|DELETE", path: "/api/requests/:rid/attachments/:aid", desc: "添付の原本(xlsx はダウンロード)・外す(固定済みの過去の run の資料は残る)" },
|
|
58
|
+
{ method: "GET", path: "/api/requests/:rid/preflight/:run/attachments/:aid", desc: "その run に固定した添付の原本(run の attachments に一覧)" },
|
|
59
|
+
{ method: "GET", path: "/api/requests/:rid/preflight/:run/attachments/:aid/extract", desc: "その run に固定した xlsx から取り出した内容(Markdown のテキスト)" },
|
|
60
|
+
{
|
|
61
|
+
method: "GET",
|
|
62
|
+
path: "/api/requests/:rid/preflight-status[?run=PF-...]",
|
|
63
|
+
desc:
|
|
64
|
+
"最新の Preflight と見ている run の今の状態だけ(要望と run.json をディスクから読む。読み込んだ内容・ファイル・rev は変えない。案・ログは返さない)。" +
|
|
65
|
+
"{requestId, state: ok|gone|broken, latest: RunPulse|null, run?: RunPulse}。RunPulse は {id, state: ready|pending|missing|broken, status?, startedAt?, finishedAt?, version?}" +
|
|
66
|
+
"(pending は保存の途中、version が変われば run を取り直す)。latest は要望の lastPreflight(未実行なら null)。ID の形が違えば 400",
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
method: "GET",
|
|
70
|
+
path: "/api/requests/:rid/preflight[/:run]",
|
|
71
|
+
desc: "Preflight の run。各 run に inputMatch {status: same|changed|unknown, changed?: [title|body], reason?}(評価対象と今の要望が同じか。タグ・期限・ステータスは比べない)",
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
method: "PATCH",
|
|
75
|
+
path: "/api/requests/:rid/preflight/:run/drafts/:key",
|
|
76
|
+
desc:
|
|
77
|
+
"タスク案を直す {title?, description?, include?, repo?, expectedTitle?}。expectedTitle(編集を始めたときの題。制御用で案には書かない)を渡すと、" +
|
|
78
|
+
"案のファイルを読み直した今の題と比べ、違えば 409 code: rev_conflict(current に今の案)で書かない。画面から題を変えるときは必ず渡す",
|
|
79
|
+
},
|
|
80
|
+
{ method: "GET", path: "/api/requests/:rid/preflight/:run/materialize", desc: "タスク化の確認(採用する案と、置き換えられる既存タスクの候補、inputMatch。何も変えない)" },
|
|
81
|
+
{
|
|
82
|
+
method: "POST",
|
|
83
|
+
path: "/api/requests/:rid/preflight/:run/materialize",
|
|
84
|
+
desc:
|
|
85
|
+
"採用したタスク案をタスク化 {archive?: [{id, rev}]}(選んだ候補だけアーカイブ)。結果は {tasks, archived, kept}。" +
|
|
86
|
+
"評価のあとで要望のタイトル・本文が変わった(か確かめられない)run は 409 code: stale_input {inputMatch} で何も書かない(再評価する)。候補の rev の競合は 409 code: rev_conflict",
|
|
87
|
+
},
|
|
88
|
+
{ method: "GET", path: "/api/release-notes", desc: "マイルストーンごとのリリースノートの有無(ok / invalid / none)・要望の数。project.yaml に無いノートは known: false と警告" },
|
|
89
|
+
{
|
|
90
|
+
method: "GET",
|
|
91
|
+
path: "/api/release-notes/:mid",
|
|
92
|
+
desc: "保存したノート {note(本文・出典・版 version), noteError(読めない理由), material(対象の要望・収録の可否・警告・材料の hash), materialChanged(保存のあとで材料が変わった)}",
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
method: "PUT",
|
|
96
|
+
path: "/api/release-notes/:mid",
|
|
97
|
+
desc:
|
|
98
|
+
"保存 {body, title?, basedOn?(元にした材料の hash), version?(更新は読んだときの版が必須)}。版が違う・既にあるは 409 code: rev_conflict {reason, current}、消えたノートの更新は 404。" +
|
|
99
|
+
"要望・マイルストーンの状態は変えない。材料が変わっていれば warnings に material_changed",
|
|
100
|
+
},
|
|
101
|
+
{ method: "GET", path: "/api/release-notes/:mid/export", desc: "保存した本文だけ(Markdown のダウンロード。出典・frontmatter は含めない)" },
|
|
102
|
+
{
|
|
103
|
+
method: "POST",
|
|
104
|
+
path: "/api/release-notes/:mid/generate",
|
|
105
|
+
desc: "機能の要約の生成を始める {engine?: codex|mock}(202。保存しない)。材料が無い・上限超えは 400 code: no_material / too_large(Codex は呼ばない)、実行中は 409 code: running",
|
|
106
|
+
},
|
|
107
|
+
{ method: "GET", path: "/api/release-notes/:mid/generations", desc: "このマイルストーンの生成(新しい順。serve のメモリにだけある)" },
|
|
108
|
+
{
|
|
109
|
+
method: "GET|POST",
|
|
110
|
+
path: "/api/release-generations/:id[/cancel]",
|
|
111
|
+
desc: "生成1件 {status: running|completed|failed|cancelled, failure?, items(文と出典), markdown(本文の案), warnings, materialChanged, log} / 取り消し",
|
|
112
|
+
},
|
|
113
|
+
{ method: "GET", path: "/api/resolve?q=&request=", desc: "参照・タイトルから対象を特定" },
|
|
114
|
+
{ method: "GET", path: "/api/chatgpt", desc: "ChatGPT プランの接続の状態(トークンは返さない)。このマシンからだけ" },
|
|
115
|
+
{ method: "POST", path: "/api/chatgpt/login|cancel|paste|logout", desc: "サインインの開始・取消・コールバックの URL の貼り付け・解除。このマシンのローカルの画面(Origin)からだけ" },
|
|
116
|
+
{ method: "GET|PUT", path: "/api/user-theme", desc: "画面のテーマ {theme: system|light|dark}(個人設定の ui.theme。このマシンのすべてのプロジェクトで共通。ほかの個人設定は返さない)。PUT はこのマシンのローカルの画面(Origin)からだけ" },
|
|
117
|
+
{ method: "GET", path: "/api/events", desc: "変更通知 (SSE)。リリースノートは changed/release-note {milestone}、生成は release-generation {id, milestone, status}" },
|
|
118
|
+
],
|
|
119
|
+
};
|
|
@@ -0,0 +1,78 @@
|
|
|
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
|
+
|
|
8
|
+
/**
|
|
9
|
+
* リリースノート(画面のため)。規則と保存は core/releaseNotes(CLI の p3 release-notes と同じ)。
|
|
10
|
+
*
|
|
11
|
+
* GET /release-notes マイルストーンごとのノートの有無
|
|
12
|
+
* GET /release-notes/:mid 保存したノートと材料(対象の要望・警告・出典)
|
|
13
|
+
* PUT /release-notes/:mid 保存(version 無しは新規、ありは更新。違えば 409 rev_conflict)
|
|
14
|
+
* GET /release-notes/:mid/export 保存した本文(Markdown のダウンロード)
|
|
15
|
+
* POST /release-notes/:mid/generate 要約の生成を始める(202。保存しない)
|
|
16
|
+
* GET /release-notes/:mid/generations このマイルストーンの生成(新しい順)
|
|
17
|
+
* GET /release-generations/:id 生成1件 / POST .../cancel 取り消す
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
const saveInput = z.object({
|
|
21
|
+
body: z.string(),
|
|
22
|
+
title: z.string().min(1).optional(),
|
|
23
|
+
/** 本文の元にした材料の hash */
|
|
24
|
+
basedOn: z.string().optional(),
|
|
25
|
+
/** 読んだときの版(更新のときは必須)。無ければ新規 */
|
|
26
|
+
version: z.string().optional(),
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
const actorOf = (c: Context) => c.req.header("x-p3-actor") ?? "human:web";
|
|
30
|
+
|
|
31
|
+
export function releaseNoteRoutes(ctx: P3Context) {
|
|
32
|
+
const app = new Hono();
|
|
33
|
+
|
|
34
|
+
app.onError(async (err, c) => {
|
|
35
|
+
if (err instanceof ReleaseNoteError) {
|
|
36
|
+
const mid = err.milestone;
|
|
37
|
+
if (err.code === "not_found") return c.json({ error: err.message, code: "not_found" }, 404);
|
|
38
|
+
if (err.code === "bad_id") return c.json({ error: err.message, code: "bad_id" }, 400);
|
|
39
|
+
if (err.code === "invalid") return c.json({ error: err.message, code: "invalid" }, 422);
|
|
40
|
+
// 版の競合・既にある: 今のノート(読めれば)を添える。画面は入力を残したまま見比べる
|
|
41
|
+
const current = await ctx.ws.releaseNotes.read(mid).catch(() => null);
|
|
42
|
+
return c.json({ error: err.message, code: "rev_conflict", reason: err.code, current }, 409);
|
|
43
|
+
}
|
|
44
|
+
if (err instanceof GenerationRejected) return c.json({ error: err.message, code: err.code }, err.code === "running" ? 409 : 400);
|
|
45
|
+
if (err instanceof z.ZodError) return c.json({ error: "invalid input", issues: err.issues }, 400);
|
|
46
|
+
console.error(err);
|
|
47
|
+
return c.json({ error: err.message }, 400);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
app.get("/release-notes", async (c) => c.json(await releaseOverview(ctx)));
|
|
51
|
+
app.get("/release-notes/:mid", async (c) => c.json(await releaseNoteDetail(ctx, c.req.param("mid"))));
|
|
52
|
+
app.put("/release-notes/:mid", async (c) => {
|
|
53
|
+
const b = saveInput.parse(await c.req.json());
|
|
54
|
+
return c.json(await saveReleaseNote(ctx, c.req.param("mid"), b, actorOf(c)));
|
|
55
|
+
});
|
|
56
|
+
app.get("/release-notes/:mid/export", async (c) => {
|
|
57
|
+
const mid = c.req.param("mid");
|
|
58
|
+
const body = await exportReleaseNote(ctx, mid);
|
|
59
|
+
return c.body(body, 200, {
|
|
60
|
+
"Content-Type": "text/markdown; charset=utf-8",
|
|
61
|
+
"Content-Disposition": `attachment; filename="release-notes-${mid}.md"`,
|
|
62
|
+
"X-Content-Type-Options": "nosniff",
|
|
63
|
+
"Cache-Control": "no-store",
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
app.post("/release-notes/:mid/generate", async (c) => {
|
|
67
|
+
const { engine } = z.object({ engine: z.enum(["codex", "mock"]).optional() }).parse(await c.req.json().catch(() => ({})));
|
|
68
|
+
return c.json(await startGeneration(ctx, c.req.param("mid"), actorOf(c), engine), 202);
|
|
69
|
+
});
|
|
70
|
+
app.get("/release-notes/:mid/generations", (c) => c.json(ctx.releaseGenerator.list(c.req.param("mid"))));
|
|
71
|
+
app.get("/release-generations/:id", (c) => {
|
|
72
|
+
const g = ctx.releaseGenerator.get(c.req.param("id"));
|
|
73
|
+
return g ? c.json(g) : c.json({ error: `生成がありません: ${c.req.param("id")}(serve を起動し直すと消えます)`, code: "not_found" }, 404);
|
|
74
|
+
});
|
|
75
|
+
app.post("/release-generations/:id/cancel", (c) => c.json({ cancelled: ctx.releaseGenerator.cancel(c.req.param("id")) }));
|
|
76
|
+
|
|
77
|
+
return app;
|
|
78
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
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
|
+
}
|