@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,114 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import type { ReleaseMaterial, ReleaseRequestItem, ReleaseSource, ReleaseWarning, Request, Task } from "../../shared/types.ts";
|
|
3
|
+
import { Workspace } from "../store/workspace.ts";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* マイルストーンのリリースノートの材料を取り出す。規則はここだけに置く(CLI・API・画面は結果を見せるだけ)。
|
|
7
|
+
*
|
|
8
|
+
* - マイルストーンに属する要望を全部返す(アーカイブしたものは含まない)。並びは作成日時 → ID
|
|
9
|
+
* - 収録するのは、要望が対応済(resolved)か完了済(done)で、タスクが1件以上あり、全部が完了で、読めないタスクが無いもの。
|
|
10
|
+
* 完了済でもタスクの実態を確かめる(直接編集で状態が食い違うことがある)
|
|
11
|
+
* - 見送り(rejected)は理由を付けて対象外。それ以外の状態は未完了として警告して対象外
|
|
12
|
+
* - 要約の材料は、収録する要望の、変更の記録(record)のある完了したタスクだけ。記録の無いものは警告し、
|
|
13
|
+
* 要望の本文やタイトルで補わない
|
|
14
|
+
* - 読めない要望は所属が分からないので全体の警告に残す
|
|
15
|
+
*
|
|
16
|
+
* 抽出のたびにディスクから読み直した別の Workspace を使い、その時点の状態を固定して返す(画面・CLI のキャッシュに左右されない)。
|
|
17
|
+
*/
|
|
18
|
+
export async function extractMaterial(dataDir: string, milestone: string): Promise<ReleaseMaterial> {
|
|
19
|
+
const snap = new Workspace(dataDir);
|
|
20
|
+
await snap.load();
|
|
21
|
+
return materialOf(snap, milestone);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const byId = (a: string, b: string) => a.localeCompare(b, undefined, { numeric: true });
|
|
25
|
+
|
|
26
|
+
export function materialOf(ws: Workspace, mid: string): ReleaseMaterial {
|
|
27
|
+
const m = ws.project.milestones.find((x) => x.id === mid);
|
|
28
|
+
const warnings: ReleaseWarning[] = [];
|
|
29
|
+
if (!m) warnings.push({ code: "unknown_milestone", target: mid, message: `マイルストーン ${mid} は project.yaml にありません(直接編集で消えた可能性があります)` });
|
|
30
|
+
for (const [id, e] of ws.requests.errors) {
|
|
31
|
+
warnings.push({ code: "broken_request", target: `requests/${id}/request.md`, message: `要望のファイルを読めないため、このマイルストーンに属するか分かりません: ${e}` });
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const members = ws.requests
|
|
35
|
+
.list()
|
|
36
|
+
.filter((r) => r.milestone === mid)
|
|
37
|
+
.sort((a, b) => a.createdAt.localeCompare(b.createdAt) || byId(a.id, b.id));
|
|
38
|
+
const requests: ReleaseRequestItem[] = [];
|
|
39
|
+
const sources: ReleaseSource[] = [];
|
|
40
|
+
for (const r of members) {
|
|
41
|
+
const col = ws.tasksOf(r.id);
|
|
42
|
+
const item = classify(r, col.list(), [...col.errors.keys()]);
|
|
43
|
+
requests.push(item.view);
|
|
44
|
+
if (item.source) sources.push(item.source);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const included = requests.filter((r) => r.included);
|
|
48
|
+
if (!included.length) warnings.push({ code: "no_candidates", target: mid, message: "収録する要望がありません(対応済か完了済で、全タスクが完了した要望が無い)" });
|
|
49
|
+
else if (!sources.some((s) => s.tasks.length)) warnings.push({ code: "no_sources", target: mid, message: "要約の材料(変更の記録のある完了したタスク)がありません。生成はできず、本文は手で書きます" });
|
|
50
|
+
|
|
51
|
+
const material = {
|
|
52
|
+
milestone: { id: mid, title: m?.title ?? mid, due: m?.due, done: m?.done, known: !!m },
|
|
53
|
+
requests,
|
|
54
|
+
sources,
|
|
55
|
+
warnings,
|
|
56
|
+
};
|
|
57
|
+
return { ...material, hash: materialHash(material), extractedAt: new Date().toISOString() };
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function classify(r: Request, all: Task[], broken: string[]): { view: ReleaseRequestItem; source?: ReleaseSource } {
|
|
61
|
+
const tasks = [...all].sort((a, b) => byId(a.id, b.id));
|
|
62
|
+
const warnings: ReleaseWarning[] = [];
|
|
63
|
+
const view: ReleaseRequestItem = {
|
|
64
|
+
id: r.id,
|
|
65
|
+
title: r.title,
|
|
66
|
+
status: r.status,
|
|
67
|
+
createdAt: r.createdAt,
|
|
68
|
+
included: false,
|
|
69
|
+
tasks: tasks.map((t) => ({ id: t.id, title: t.title, status: t.status, hasRecord: !!t.record?.trim() })),
|
|
70
|
+
warnings,
|
|
71
|
+
};
|
|
72
|
+
const exclude = (reason: string, warn?: ReleaseWarning) => {
|
|
73
|
+
view.reason = reason;
|
|
74
|
+
if (warn) warnings.push(warn);
|
|
75
|
+
return { view };
|
|
76
|
+
};
|
|
77
|
+
if (r.status === "rejected") return exclude("見送り");
|
|
78
|
+
if (r.status !== "resolved" && r.status !== "done") {
|
|
79
|
+
return exclude(`未完了(${r.status})`, { code: "not_finished", target: r.id, message: `${r.id} はまだ終わっていません(${r.status})。収録しません` });
|
|
80
|
+
}
|
|
81
|
+
if (broken.length) {
|
|
82
|
+
return exclude("読めないタスクがある", { code: "broken_task", target: r.id, message: `${r.id} に読めないタスクのファイルがあります: ${broken.sort(byId).join(", ")}(直すまで収録しません)` });
|
|
83
|
+
}
|
|
84
|
+
if (!tasks.length) return exclude("タスクが無い", { code: "no_tasks", target: r.id, message: `${r.id} にタスクがありません(収録しません)` });
|
|
85
|
+
const open = tasks.filter((t) => t.status !== "done");
|
|
86
|
+
if (open.length) {
|
|
87
|
+
return exclude("完了していないタスクがある", {
|
|
88
|
+
code: "open_tasks",
|
|
89
|
+
target: r.id,
|
|
90
|
+
message: `${r.id} は ${r.status} ですが、完了していないタスクがあります: ${open.map((t) => `${t.id}(${t.status})`).join(", ")}(収録しません)`,
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
view.included = true;
|
|
94
|
+
const withRecord = tasks.filter((t) => t.record?.trim());
|
|
95
|
+
for (const t of tasks) {
|
|
96
|
+
if (!t.record?.trim()) warnings.push({ code: "missing_record", target: t.ref, message: `${t.ref} に変更の記録がありません(要約の材料にしません)` });
|
|
97
|
+
}
|
|
98
|
+
if (!withRecord.length) warnings.push({ code: "no_material", target: r.id, message: `${r.id} には変更の記録が1つもありません(要約に入りません)` });
|
|
99
|
+
return {
|
|
100
|
+
view,
|
|
101
|
+
source: { request: r.id, title: r.title, status: r.status, tasks: withRecord.map((t) => ({ id: t.id, title: t.title, status: t.status, record: t.record!.trim() })) },
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** 材料の識別子: 所属する要望の状態・タイトル・収録の可否と、要約の材料(記録まで)。抽出した日時と警告の文言は含めない */
|
|
106
|
+
function materialHash(m: Omit<ReleaseMaterial, "hash" | "extractedAt">): string {
|
|
107
|
+
const key = {
|
|
108
|
+
milestone: m.milestone.id,
|
|
109
|
+
requests: m.requests.map((r) => ({ id: r.id, title: r.title, status: r.status, included: r.included, tasks: r.tasks.map((t) => [t.id, t.status, t.hasRecord]) })),
|
|
110
|
+
sources: m.sources,
|
|
111
|
+
broken: m.warnings.filter((w) => w.code === "broken_request").map((w) => w.target),
|
|
112
|
+
};
|
|
113
|
+
return createHash("sha256").update(JSON.stringify(key)).digest("hex");
|
|
114
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { PreflightLogEntry } from "../../shared/types.ts";
|
|
2
|
+
import type { AskResult } from "../preflight/codexEngine.ts";
|
|
3
|
+
import type { Summarizer } from "./generate.ts";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Codex を使わずに要約の契約(最後の応答の JSON)を再現する(オフライン開発・デモ・テスト用)。
|
|
7
|
+
* 依頼文の材料から、要望ごとに1項目「(Mock)タイトル: 最初の記録の1行目」を作るだけで、要約はしない。
|
|
8
|
+
* --engine mock か個人設定の preflight.engine: mock で明示したときだけ使う(Preflight と同じ)
|
|
9
|
+
*/
|
|
10
|
+
export class MockSummarizer implements Summarizer {
|
|
11
|
+
/** 待ち時間(ms。画面で生成中が見えるように少し待つ。テストでは 0) */
|
|
12
|
+
constructor(private opts: { delayMs?: number } = {}) {}
|
|
13
|
+
|
|
14
|
+
async ask(input: { prompt: string }, log: (e: Omit<PreflightLogEntry, "at">) => void, signal: AbortSignal): Promise<AskResult> {
|
|
15
|
+
log({ kind: "info", text: "Mock で要約します(要約はせず、記録の1行目を並べます)" });
|
|
16
|
+
await new Promise<void>((res, rej) => {
|
|
17
|
+
const t = setTimeout(res, this.opts.delayMs ?? 1500);
|
|
18
|
+
signal.addEventListener("abort", () => (clearTimeout(t), rej(new Error("aborted"))), { once: true });
|
|
19
|
+
});
|
|
20
|
+
const json = /<material>\n([\s\S]*?)\n<\/material>/.exec(input.prompt)?.[1];
|
|
21
|
+
const material = JSON.parse(json ?? "{}") as { requests?: { id: string; title: string; tasks: { ref: string; record?: string }[] }[] };
|
|
22
|
+
const items = (material.requests ?? []).map((r) => ({
|
|
23
|
+
text: `(Mock)${r.title}: ${(r.tasks[0]?.record ?? "").split("\n").find((l) => l.trim() && !l.startsWith("#"))?.replace(/^[-*]\s*/, "").trim() ?? ""}`,
|
|
24
|
+
sources: [r.id, ...r.tasks.map((t) => t.ref)],
|
|
25
|
+
}));
|
|
26
|
+
return { message: JSON.stringify({ items }), seconds: 0 };
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import type { ReleaseGeneration, ReleaseMaterial, ReleaseNote, ReleaseNoteSummary, ReleaseWarning } from "../../shared/types.ts";
|
|
2
|
+
import type { P3Context } from "../context.ts";
|
|
3
|
+
import { extractMaterial } from "./material.ts";
|
|
4
|
+
import type { SummaryEngine } from "./generate.ts";
|
|
5
|
+
import { checkMilestoneId, ReleaseNoteError } from "./store.ts";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* リリースノートの操作(CLI と API はここを呼ぶ)。材料の規則は material.ts、保存の形は store.ts。
|
|
9
|
+
*
|
|
10
|
+
* ノートを作る・変えるのは明示的に保存したときだけ。要望・タスク・マイルストーンの状態は変えない。
|
|
11
|
+
* 保存では、そのときディスクにある材料を出典として固定する(本文の元にした材料が古ければ material_changed で知らせる)。
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/** マイルストーンごとのノートの有無。並びは project.yaml の順、その後ろに project.yaml に無いノート(ID の順) */
|
|
15
|
+
export async function releaseOverview(ctx: P3Context): Promise<{ milestones: ReleaseNoteSummary[]; warnings: ReleaseWarning[] }> {
|
|
16
|
+
const { ws } = ctx;
|
|
17
|
+
const count = (mid: string) => ws.requests.list().filter((r) => r.milestone === mid).length;
|
|
18
|
+
const ids = await ws.releaseNotes.ids();
|
|
19
|
+
const noteState = async (mid: string): Promise<ReleaseNoteSummary["note"]> => {
|
|
20
|
+
if (!ids.includes(mid)) return { state: "none" };
|
|
21
|
+
try {
|
|
22
|
+
const n = await ws.releaseNotes.read(mid);
|
|
23
|
+
return { state: "ok", version: n.version, updatedAt: n.updatedAt, updatedBy: n.updatedBy };
|
|
24
|
+
} catch (e) {
|
|
25
|
+
if (e instanceof ReleaseNoteError && e.code === "not_found") return { state: "none" };
|
|
26
|
+
return { state: "invalid", error: (e as Error).message };
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
const known = ws.project.milestones;
|
|
30
|
+
const orphans = ids.filter((id) => !known.some((m) => m.id === id));
|
|
31
|
+
const milestones: ReleaseNoteSummary[] = [
|
|
32
|
+
...(await Promise.all(known.map(async (m) => ({ milestone: m.id, title: m.title, due: m.due, done: m.done, known: true, requests: count(m.id), note: await noteState(m.id) })))),
|
|
33
|
+
...(await Promise.all(orphans.map(async (id) => ({ milestone: id, title: id, known: false, requests: count(id), note: await noteState(id) })))),
|
|
34
|
+
];
|
|
35
|
+
const warnings: ReleaseWarning[] = orphans.map((id) => ({
|
|
36
|
+
code: "unknown_milestone",
|
|
37
|
+
target: id,
|
|
38
|
+
message: `リリースノート ${id} のマイルストーンが project.yaml にありません(読めます。マイルストーンを足し直すか、不要ならファイルを消してください)`,
|
|
39
|
+
}));
|
|
40
|
+
return { milestones, warnings };
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** 材料。project.yaml に無く、ノートも無いマイルストーンは not_found */
|
|
44
|
+
export async function releaseMaterial(ctx: P3Context, mid: string): Promise<ReleaseMaterial> {
|
|
45
|
+
checkMilestoneId(mid);
|
|
46
|
+
const material = await extractMaterial(ctx.ws.dataDir, mid);
|
|
47
|
+
if (!material.milestone.known && !(await ctx.ws.releaseNotes.ids()).includes(mid)) {
|
|
48
|
+
throw new ReleaseNoteError("not_found", mid, `マイルストーンがありません: ${mid}`);
|
|
49
|
+
}
|
|
50
|
+
return material;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export interface ReleaseNoteDetail {
|
|
54
|
+
/** 保存したノート(無ければ null) */
|
|
55
|
+
note: ReleaseNote | null;
|
|
56
|
+
/** ノートのファイルが読めない理由(このときは note が null でも「無い」ではない) */
|
|
57
|
+
noteError: string | null;
|
|
58
|
+
material: ReleaseMaterial;
|
|
59
|
+
/** 保存のあとで材料が変わった(ノートが無ければ false) */
|
|
60
|
+
materialChanged: boolean;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export async function releaseNoteDetail(ctx: P3Context, mid: string): Promise<ReleaseNoteDetail> {
|
|
64
|
+
const material = await releaseMaterial(ctx, mid);
|
|
65
|
+
let note: ReleaseNote | null = null;
|
|
66
|
+
let noteError: string | null = null;
|
|
67
|
+
try {
|
|
68
|
+
note = await ctx.ws.releaseNotes.read(mid);
|
|
69
|
+
} catch (e) {
|
|
70
|
+
if (!(e instanceof ReleaseNoteError && e.code === "not_found")) noteError = (e as Error).message;
|
|
71
|
+
}
|
|
72
|
+
return { note, noteError, material, materialChanged: !!note && note.materialHash !== material.hash };
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export interface SaveInput {
|
|
76
|
+
body: string;
|
|
77
|
+
title?: string;
|
|
78
|
+
/** 本文の元にした材料の hash(生成のプレビューや詳細で受け取ったもの)。今の材料と違えば material_changed を返す */
|
|
79
|
+
basedOn?: string;
|
|
80
|
+
/** 更新のときは読んだときの版(必須)。無ければ新しく作る(既にあれば exists) */
|
|
81
|
+
version?: string;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** 保存する(新規か、版を付けた更新)。出典は保存のときの材料。材料が無くても本文は保存できる(手で書く) */
|
|
85
|
+
export async function saveReleaseNote(ctx: P3Context, mid: string, input: SaveInput, actor?: string): Promise<{ note: ReleaseNote; warnings: ReleaseWarning[] }> {
|
|
86
|
+
const material = await releaseMaterial(ctx, mid);
|
|
87
|
+
const write = { title: input.title ?? material.milestone.title, body: input.body, sources: material.sources, materialHash: material.hash };
|
|
88
|
+
const note = input.version === undefined ? await ctx.ws.releaseNotes.create(mid, write, actor) : await ctx.ws.releaseNotes.update(mid, write, input.version, actor);
|
|
89
|
+
ctx.ws.emit({ type: "changed", kind: "release-note", milestone: mid });
|
|
90
|
+
const warnings: ReleaseWarning[] =
|
|
91
|
+
input.basedOn && input.basedOn !== material.hash
|
|
92
|
+
? [{ code: "material_changed", target: mid, message: "本文の元にした材料のあとで、要望・タスクが変わっています。保存はしました(出典は今の材料)。内容を確かめてください" }]
|
|
93
|
+
: [];
|
|
94
|
+
return { note, warnings };
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** 公開する本文だけ(frontmatter・出典は含めない) */
|
|
98
|
+
export async function exportReleaseNote(ctx: P3Context, mid: string): Promise<string> {
|
|
99
|
+
const note = await ctx.ws.releaseNotes.read(mid);
|
|
100
|
+
return note.body ? `${note.body}\n` : "";
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** 要約の生成を始める(材料はここで固定する。保存はしない)。材料が無ければ Codex を呼ばずに GenerationRejected */
|
|
104
|
+
export async function startGeneration(ctx: P3Context, mid: string, actor?: string, engine?: SummaryEngine): Promise<ReleaseGeneration> {
|
|
105
|
+
return ctx.releaseGenerator.start(await releaseMaterial(ctx, mid), actor, engine);
|
|
106
|
+
}
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { readdir, readFile } from "node:fs/promises";
|
|
3
|
+
import { join, resolve, sep } from "node:path";
|
|
4
|
+
import type { ReleaseNote, ReleaseSource } from "../../shared/types.ts";
|
|
5
|
+
import { parseFrontmatter, stringifyFrontmatter } from "../store/frontmatter.ts";
|
|
6
|
+
import { createExclusive, nowIso, withFileLock, writeFileAtomic } from "../store/fsutil.ts";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* <data>/release-notes/<マイルストーンID>.md リリースノート(マイルストーンごとに1件)
|
|
10
|
+
*
|
|
11
|
+
* frontmatter に出典(保存したときの材料: 要望・タスクの ID・タイトル・状態・変更の記録)と材料の hash、
|
|
12
|
+
* 本文に公開する Markdown を書く。出力は本文だけ。要望やタスクが後で変わっても、保存した本文と出典は変えない。
|
|
13
|
+
*
|
|
14
|
+
* 編集の版はファイル全体の sha256。保存はプロセス間のロックの中で、ディスクの今のファイルの版と照らしてから原子的に書く
|
|
15
|
+
* (rev を増やさない直接編集も見つけられる)。ロックを使わない外部のエディタとの完全な排他は保証しない。
|
|
16
|
+
* キャッシュは持たず、問い合わせのたびにディスクを読む(再読み込みは要らない)。
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
export const RELEASE_NOTES_DIR = "release-notes";
|
|
20
|
+
/** マイルストーンの ID(project.yaml と同じ。. と .. は使えない) */
|
|
21
|
+
const MILESTONE_ID = /^[A-Za-z0-9._-]+$/;
|
|
22
|
+
|
|
23
|
+
/** ノートの操作の失敗の種類。CLI は終了コード、API は応答に分ける */
|
|
24
|
+
export class ReleaseNoteError extends Error {
|
|
25
|
+
constructor(
|
|
26
|
+
/** not_found: 無い / invalid: 読めない / exists: 既にある / conflict: 版が違う / bad_id: ID が使えない */
|
|
27
|
+
readonly code: "not_found" | "invalid" | "exists" | "conflict" | "bad_id",
|
|
28
|
+
readonly milestone: string,
|
|
29
|
+
message: string,
|
|
30
|
+
/** conflict のときの今の版(読めなければ無い) */
|
|
31
|
+
readonly current?: string,
|
|
32
|
+
) {
|
|
33
|
+
super(message);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export const versionOf = (text: string) => createHash("sha256").update(text).digest("hex");
|
|
38
|
+
|
|
39
|
+
export function checkMilestoneId(id: string): void {
|
|
40
|
+
if (!MILESTONE_ID.test(id) || id === "." || id === "..") throw new ReleaseNoteError("bad_id", id, `マイルストーンの ID に使えません: ${JSON.stringify(id)}(英数字と . _ -)`);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface NoteWrite {
|
|
44
|
+
title: string;
|
|
45
|
+
body: string;
|
|
46
|
+
sources: ReleaseSource[];
|
|
47
|
+
materialHash?: string;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export class ReleaseNoteStore {
|
|
51
|
+
constructor(readonly dataDir: string) {}
|
|
52
|
+
|
|
53
|
+
get dir() {
|
|
54
|
+
return join(this.dataDir, RELEASE_NOTES_DIR);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** ノートのファイル。保存先のフォルダの外を指す ID は断る */
|
|
58
|
+
path(milestone: string): string {
|
|
59
|
+
checkMilestoneId(milestone);
|
|
60
|
+
const p = resolve(this.dir, `${milestone}.md`);
|
|
61
|
+
if (!p.startsWith(resolve(this.dir) + sep)) throw new ReleaseNoteError("bad_id", milestone, `保存先の外を指します: ${milestone}`);
|
|
62
|
+
return p;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
private lock(milestone: string) {
|
|
66
|
+
return join(this.dir, `.${milestone}.lock`);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** ファイルがあるマイルストーン(読めないものも含む。ID の形でないファイルは除く) */
|
|
70
|
+
async ids(): Promise<string[]> {
|
|
71
|
+
const files = await readdir(this.dir).catch((e: NodeJS.ErrnoException) => {
|
|
72
|
+
if (e.code === "ENOENT") return [] as string[];
|
|
73
|
+
throw e;
|
|
74
|
+
});
|
|
75
|
+
return files
|
|
76
|
+
.filter((f) => f.endsWith(".md") && !f.startsWith("."))
|
|
77
|
+
.map((f) => f.slice(0, -3))
|
|
78
|
+
.filter((id) => MILESTONE_ID.test(id) && id !== "." && id !== "..")
|
|
79
|
+
.sort();
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** 読む。無ければ not_found、読めなければ invalid(空のノートとして扱わない) */
|
|
83
|
+
async read(milestone: string): Promise<ReleaseNote> {
|
|
84
|
+
const path = this.path(milestone);
|
|
85
|
+
let text: string;
|
|
86
|
+
try {
|
|
87
|
+
text = await readFile(path, "utf8");
|
|
88
|
+
} catch (e) {
|
|
89
|
+
if ((e as NodeJS.ErrnoException).code === "ENOENT") throw new ReleaseNoteError("not_found", milestone, `リリースノートがありません: ${milestone}`);
|
|
90
|
+
throw new ReleaseNoteError("invalid", milestone, `リリースノートを読めません(${path}): ${(e as Error).message}`);
|
|
91
|
+
}
|
|
92
|
+
return parseNote(milestone, text, path);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** 全部(読めないものは invalid に理由を返す) */
|
|
96
|
+
async list(): Promise<{ notes: ReleaseNote[]; invalid: { milestone: string; error: string }[] }> {
|
|
97
|
+
const notes: ReleaseNote[] = [];
|
|
98
|
+
const invalid: { milestone: string; error: string }[] = [];
|
|
99
|
+
for (const id of await this.ids()) {
|
|
100
|
+
try {
|
|
101
|
+
notes.push(await this.read(id));
|
|
102
|
+
} catch (e) {
|
|
103
|
+
if (e instanceof ReleaseNoteError && e.code === "not_found") continue; // 読む間に消えた
|
|
104
|
+
invalid.push({ milestone: id, error: (e as Error).message });
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return { notes, invalid };
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** 新しく作る(既にあれば exists。読めないファイルがあっても上書きしない) */
|
|
111
|
+
async create(milestone: string, input: NoteWrite, actor?: string): Promise<ReleaseNote> {
|
|
112
|
+
const path = this.path(milestone);
|
|
113
|
+
return withFileLock(this.lock(milestone), async () => {
|
|
114
|
+
const now = nowIso();
|
|
115
|
+
const text = serialize({ milestone, ...input, createdAt: now, createdBy: actor, updatedAt: now, updatedBy: actor });
|
|
116
|
+
if (!(await createExclusive(path, text))) throw new ReleaseNoteError("exists", milestone, `リリースノートは既にあります: ${milestone}(直すときは版を付けて更新してください)`);
|
|
117
|
+
return parseNote(milestone, text, path);
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* 更新する。expectedVersion は読んだときの版(必須)。ロックの中でディスクの今のファイルと照らし、違えば conflict で何も書かない。
|
|
123
|
+
* 作成の日時と作成者は残す
|
|
124
|
+
*/
|
|
125
|
+
async update(milestone: string, input: Partial<NoteWrite>, expectedVersion: string, actor?: string): Promise<ReleaseNote> {
|
|
126
|
+
const path = this.path(milestone);
|
|
127
|
+
return withFileLock(this.lock(milestone), async () => {
|
|
128
|
+
let raw: string;
|
|
129
|
+
try {
|
|
130
|
+
raw = await readFile(path, "utf8");
|
|
131
|
+
} catch (e) {
|
|
132
|
+
if ((e as NodeJS.ErrnoException).code === "ENOENT") throw new ReleaseNoteError("not_found", milestone, `リリースノートがありません(消されました): ${milestone}`);
|
|
133
|
+
throw e;
|
|
134
|
+
}
|
|
135
|
+
const version = versionOf(raw);
|
|
136
|
+
if (version !== expectedVersion) {
|
|
137
|
+
throw new ReleaseNoteError("conflict", milestone, `${milestone} のリリースノートは読んだ後に変わっています(版が違います)。読み直してからやり直してください`, version);
|
|
138
|
+
}
|
|
139
|
+
const cur = parseNote(milestone, raw, path);
|
|
140
|
+
const text = serialize({
|
|
141
|
+
milestone,
|
|
142
|
+
title: input.title ?? cur.title,
|
|
143
|
+
body: input.body ?? cur.body,
|
|
144
|
+
sources: input.sources ?? cur.sources,
|
|
145
|
+
materialHash: "materialHash" in input ? input.materialHash : cur.materialHash,
|
|
146
|
+
createdAt: cur.createdAt,
|
|
147
|
+
createdBy: cur.createdBy,
|
|
148
|
+
updatedAt: nowIso(),
|
|
149
|
+
updatedBy: actor,
|
|
150
|
+
});
|
|
151
|
+
await writeFileAtomic(path, text);
|
|
152
|
+
return parseNote(milestone, text, path);
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function serialize(n: Omit<ReleaseNote, "version">): string {
|
|
158
|
+
return stringifyFrontmatter(
|
|
159
|
+
{
|
|
160
|
+
milestone: n.milestone,
|
|
161
|
+
title: n.title,
|
|
162
|
+
createdAt: n.createdAt,
|
|
163
|
+
createdBy: n.createdBy,
|
|
164
|
+
updatedAt: n.updatedAt,
|
|
165
|
+
updatedBy: n.updatedBy,
|
|
166
|
+
materialHash: n.materialHash,
|
|
167
|
+
sources: n.sources.map((s) => ({ request: s.request, title: s.title, status: s.status, tasks: s.tasks.map((t) => ({ id: t.id, title: t.title, status: t.status, record: t.record })) })),
|
|
168
|
+
},
|
|
169
|
+
n.body,
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const str = (v: unknown) => (typeof v === "string" ? v : undefined);
|
|
174
|
+
|
|
175
|
+
/** ファイルを読む。frontmatter が壊れている・マイルストーンが違う・日時が無いものは invalid */
|
|
176
|
+
function parseNote(milestone: string, text: string, path: string): ReleaseNote {
|
|
177
|
+
let data: Record<string, unknown>;
|
|
178
|
+
let body: string;
|
|
179
|
+
try {
|
|
180
|
+
({ data, body } = parseFrontmatter(text));
|
|
181
|
+
} catch (e) {
|
|
182
|
+
throw new ReleaseNoteError("invalid", milestone, `リリースノートの frontmatter を読めません(${path}): ${(e as Error).message}`);
|
|
183
|
+
}
|
|
184
|
+
const bad = (why: string) => new ReleaseNoteError("invalid", milestone, `リリースノートを読めません(${path}): ${why}`);
|
|
185
|
+
if (data.milestone !== milestone) throw bad(`milestone が ${JSON.stringify(data.milestone)} です(ファイル名は ${milestone})`);
|
|
186
|
+
const createdAt = str(data.createdAt);
|
|
187
|
+
const updatedAt = str(data.updatedAt);
|
|
188
|
+
if (!createdAt || !updatedAt) throw bad("createdAt / updatedAt がありません");
|
|
189
|
+
if (data.sources !== undefined && !Array.isArray(data.sources)) throw bad("sources が配列ではありません");
|
|
190
|
+
const sources: ReleaseSource[] = ((data.sources as unknown[] | undefined) ?? []).map((s, i) => {
|
|
191
|
+
const o = (s ?? {}) as Record<string, unknown>;
|
|
192
|
+
if (typeof o.request !== "string") throw bad(`sources[${i}].request がありません`);
|
|
193
|
+
const tasks = Array.isArray(o.tasks) ? o.tasks : [];
|
|
194
|
+
return {
|
|
195
|
+
request: o.request,
|
|
196
|
+
title: str(o.title) ?? "",
|
|
197
|
+
status: (str(o.status) ?? "done") as ReleaseSource["status"],
|
|
198
|
+
tasks: tasks.map((t) => {
|
|
199
|
+
const x = (t ?? {}) as Record<string, unknown>;
|
|
200
|
+
return { id: String(x.id ?? ""), title: str(x.title) ?? "", status: (str(x.status) ?? "done") as ReleaseSource["tasks"][number]["status"], ...(str(x.record) ? { record: str(x.record) } : {}) };
|
|
201
|
+
}),
|
|
202
|
+
};
|
|
203
|
+
});
|
|
204
|
+
return {
|
|
205
|
+
milestone,
|
|
206
|
+
title: str(data.title) ?? milestone,
|
|
207
|
+
body: body.trim(),
|
|
208
|
+
sources,
|
|
209
|
+
materialHash: str(data.materialHash),
|
|
210
|
+
createdAt,
|
|
211
|
+
createdBy: str(data.createdBy),
|
|
212
|
+
updatedAt,
|
|
213
|
+
updatedBy: str(data.updatedBy),
|
|
214
|
+
version: versionOf(text),
|
|
215
|
+
};
|
|
216
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { existsSync, statSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { repoNameProblem, type CodeMapEntry, type RepoRef } from "../shared/repos.ts";
|
|
4
|
+
import { writeRepoEntry } from "./store/projectFile.ts";
|
|
5
|
+
import type { Workspace } from "./store/workspace.ts";
|
|
6
|
+
import { setProjectNode, updateUserConfig } from "./userConfig.ts";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* 参照先の登録・変更・削除(CLI の p3 repo と設定画面で共通)。
|
|
10
|
+
* 共有の定義は project.yaml の repos(その1件だけを書く。コメント・ほかの項目は残す)
|
|
11
|
+
* このマシンのパスは個人設定の projects.<プロジェクト>.repos.<名前>(共有しない)
|
|
12
|
+
*/
|
|
13
|
+
export class RepoAdminError extends Error {}
|
|
14
|
+
|
|
15
|
+
/** 共有の定義のうち、変えてよい項目 */
|
|
16
|
+
export type RepoPatch = Partial<Pick<RepoRef, "role" | "readFirst" | "writable" | "map">>;
|
|
17
|
+
|
|
18
|
+
const file = (ws: Workspace) => join(ws.dataDir, "project.yaml");
|
|
19
|
+
|
|
20
|
+
function cleanMap(map: CodeMapEntry[]): CodeMapEntry[] {
|
|
21
|
+
return map
|
|
22
|
+
.map((m) => ({ path: m.path.trim().replace(/^(\.\/)+/, "").replace(/\/+$/, ""), role: m.role.trim(), ...(m.entry?.trim() ? { entry: m.entry.trim() } : {}) }))
|
|
23
|
+
.filter((m) => m.path);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export async function addRepo(ws: Workspace, name: string, patch: RepoPatch = {}): Promise<RepoRef> {
|
|
27
|
+
const problem = repoNameProblem(name);
|
|
28
|
+
if (problem) throw new RepoAdminError(`参照先の名前: ${problem}`);
|
|
29
|
+
if (ws.project.repos.some((r) => r.name === name)) throw new RepoAdminError(`「${name}」は既にあります`);
|
|
30
|
+
const entry: RepoRef = { name, role: patch.role?.trim() ?? "", readFirst: !!patch.readFirst, writable: !!patch.writable, map: cleanMap(patch.map ?? []) };
|
|
31
|
+
await writeRepoEntry(file(ws), name, entry);
|
|
32
|
+
await ws.refreshProject();
|
|
33
|
+
return entry;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export async function updateRepo(ws: Workspace, name: string, patch: RepoPatch): Promise<RepoRef> {
|
|
37
|
+
const cur = ws.project.repos.find((r) => r.name === name);
|
|
38
|
+
if (!cur) throw new RepoAdminError(`「${name}」はありません`);
|
|
39
|
+
const next: RepoRef = {
|
|
40
|
+
...cur,
|
|
41
|
+
...(patch.role !== undefined ? { role: patch.role.trim() } : {}),
|
|
42
|
+
...(patch.readFirst !== undefined ? { readFirst: patch.readFirst } : {}),
|
|
43
|
+
...(patch.writable !== undefined ? { writable: patch.writable } : {}),
|
|
44
|
+
...(patch.map !== undefined ? { map: cleanMap(patch.map) } : {}),
|
|
45
|
+
};
|
|
46
|
+
await writeRepoEntry(file(ws), name, next);
|
|
47
|
+
await ws.refreshProject();
|
|
48
|
+
return next;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** 共有の定義を消す(ほかの人の Preflight でも読まなくなる。フォルダは消さない)。このマシンのパスも外す */
|
|
52
|
+
export async function removeRepo(ws: Workspace, projectName: string | undefined, name: string) {
|
|
53
|
+
if (!ws.project.repos.some((r) => r.name === name)) throw new RepoAdminError(`「${name}」はありません`);
|
|
54
|
+
await writeRepoEntry(file(ws), name, null);
|
|
55
|
+
if (projectName) await setLocalRepoPath(ws, projectName, name, null).catch(() => undefined);
|
|
56
|
+
await ws.refreshProject();
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** このマシンのパスとして使えるか(フォルダであること。git でなくてよい) */
|
|
60
|
+
export function checkFolder(path: string) {
|
|
61
|
+
if (!existsSync(path)) throw new RepoAdminError(`パスがありません: ${path}`);
|
|
62
|
+
if (!statSync(path).isDirectory()) throw new RepoAdminError(`フォルダではありません: ${path}`);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** このマシンのパスを登録する(null で外す)。フォルダであること(git でなくてよい)。共有の定義は変えない */
|
|
66
|
+
export async function setLocalRepoPath(ws: Workspace, projectName: string | undefined, name: string, path: string | null) {
|
|
67
|
+
if (!projectName) throw new RepoAdminError("このプロジェクトは個人設定に登録されていません。先に p3 project add <名前> <フォルダ> で登録してください");
|
|
68
|
+
if (path !== null) {
|
|
69
|
+
if (!ws.project.repos.some((r) => r.name === name)) throw new RepoAdminError(`「${name}」は参照先にありません(先に共有の定義を足してください)`);
|
|
70
|
+
checkFolder(path);
|
|
71
|
+
}
|
|
72
|
+
await updateUserConfig((doc, now) => {
|
|
73
|
+
const prev = now.projects[projectName];
|
|
74
|
+
if (!prev) throw new RepoAdminError(`プロジェクト「${projectName}」は個人設定に登録されていません`);
|
|
75
|
+
const repos = { ...prev.repos };
|
|
76
|
+
if (path === null) delete repos[name];
|
|
77
|
+
else repos[name] = path;
|
|
78
|
+
setProjectNode(doc, projectName, { dir: prev.dir, repos });
|
|
79
|
+
});
|
|
80
|
+
ws.setLocalRepo(name, path);
|
|
81
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { existsSync, readFileSync, statSync } from "node:fs";
|
|
2
|
+
import { dirname, isAbsolute, join, relative, resolve } from "node:path";
|
|
3
|
+
import { mountNames, type RefScope, type RepoRef } from "../shared/repos.ts";
|
|
4
|
+
import type { ProjectConfig } from "../shared/types.ts";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* 参照先(共有の定義)と、このマシンのパス(個人設定)を合わせたもの。
|
|
8
|
+
*
|
|
9
|
+
* ok 手元のパスがあり、フォルダとして読める
|
|
10
|
+
* unregistered 手元のパスが登録されていない(p3 repo path <名前> <パス> で登録する)
|
|
11
|
+
* missing 登録したパスが無い
|
|
12
|
+
* notdir 登録したパスがフォルダではない
|
|
13
|
+
*
|
|
14
|
+
* git のリポジトリでなくてもよい(フォルダだけ・リポジトリの中のサブフォルダも可)。
|
|
15
|
+
*/
|
|
16
|
+
export interface ResolvedRef extends RepoRef {
|
|
17
|
+
/** コンテナの中の名前(/workspace/<mount>) */
|
|
18
|
+
mount: string;
|
|
19
|
+
status: "ok" | "unregistered" | "missing" | "notdir";
|
|
20
|
+
/** このマシンのパス(共有の記録には残さない) */
|
|
21
|
+
local?: string;
|
|
22
|
+
/** 見られないときの理由 */
|
|
23
|
+
reason?: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** 共有の定義ごとに、個人設定の repos.<名前>(このマシンのパス)を合わせる。手元の対応が無い名前は unregistered */
|
|
27
|
+
export function resolveRefs(project: ProjectConfig, opts: { localRepos?: Record<string, string> }): ResolvedRef[] {
|
|
28
|
+
const local = opts.localRepos ?? {};
|
|
29
|
+
const mounts = mountNames(project.repos.map((r) => r.name));
|
|
30
|
+
return project.repos.map((r, i) => {
|
|
31
|
+
const path = local[r.name];
|
|
32
|
+
const base = { ...r, mount: mounts[i] };
|
|
33
|
+
if (!path) return { ...base, status: "unregistered" as const, reason: "このマシンのパスが登録されていません" };
|
|
34
|
+
try {
|
|
35
|
+
const st = statSync(path);
|
|
36
|
+
if (!st.isDirectory()) return { ...base, status: "notdir" as const, local: path, reason: `フォルダではありません: ${path}` };
|
|
37
|
+
} catch {
|
|
38
|
+
return { ...base, status: "missing" as const, local: path, reason: `登録したパスがありません: ${path}` };
|
|
39
|
+
}
|
|
40
|
+
return { ...base, status: "ok" as const, local: path };
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* 参照先のフォルダで git の履歴が使えるか。コンテナには参照先のフォルダだけを読むだけでマウントするので、
|
|
46
|
+
* 履歴の本体(.git)がフォルダの中にあるときだけ使える。浅い clone は途中までしか無い
|
|
47
|
+
*/
|
|
48
|
+
export function gitHistory(local: string): NonNullable<RefScope["history"]> {
|
|
49
|
+
const dotGit = join(local, ".git");
|
|
50
|
+
let st;
|
|
51
|
+
try {
|
|
52
|
+
st = statSync(dotGit);
|
|
53
|
+
} catch {
|
|
54
|
+
// 上に .git があれば、リポジトリの中のサブフォルダ(履歴の本体はマウントの外)
|
|
55
|
+
for (let d = dirname(resolve(local)); d !== dirname(d); d = dirname(d)) {
|
|
56
|
+
if (existsSync(join(d, ".git"))) return { status: "unavailable", reason: "リポジトリの中のサブフォルダなので、履歴の本体(.git)がマウントの外にあります" };
|
|
57
|
+
}
|
|
58
|
+
return { status: "unavailable", reason: "git のリポジトリではありません" };
|
|
59
|
+
}
|
|
60
|
+
if (st.isFile()) {
|
|
61
|
+
// git の作業ツリー(worktree)・サブモジュール: .git は本体の場所を指すファイル
|
|
62
|
+
const m = /^gitdir:\s*(.+)$/m.exec(readFileSync(dotGit, "utf8"));
|
|
63
|
+
const gitdir = m ? resolve(local, m[1].trim()) : undefined;
|
|
64
|
+
const inside = gitdir && !relative(local, gitdir).startsWith("..") && !isAbsolute(relative(local, gitdir));
|
|
65
|
+
if (!inside) return { status: "unavailable", reason: "git の作業ツリーなので、履歴の本体がマウントの外にあります(メインのチェックアウトを参照先にすると使えます)" };
|
|
66
|
+
return { status: "ok" };
|
|
67
|
+
}
|
|
68
|
+
if (existsSync(join(dotGit, "shallow"))) return { status: "shallow", reason: "浅い clone なので、履歴は途中までです" };
|
|
69
|
+
return { status: "ok" };
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function refScope(r: ResolvedRef): RefScope {
|
|
73
|
+
const reason =
|
|
74
|
+
r.status === "unregistered"
|
|
75
|
+
? `このマシンのパスが登録されていません(p3 repo path ${r.name} <パス>)`
|
|
76
|
+
: r.status === "missing"
|
|
77
|
+
? "登録したパスがありません"
|
|
78
|
+
: r.status === "notdir"
|
|
79
|
+
? "登録したパスがフォルダではありません"
|
|
80
|
+
: undefined;
|
|
81
|
+
return {
|
|
82
|
+
name: r.name,
|
|
83
|
+
mount: r.mount,
|
|
84
|
+
role: r.role,
|
|
85
|
+
readFirst: r.readFirst,
|
|
86
|
+
status: r.status,
|
|
87
|
+
...(reason ? { reason } : {}),
|
|
88
|
+
...(r.status === "ok" && r.local ? { history: gitHistory(r.local) } : {}),
|
|
89
|
+
};
|
|
90
|
+
}
|