@infodb/p3 0.2.0 → 0.3.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/README.md +6 -1
- package/dist/web/assets/{Outputs-Ni3pNuGU.js → Outputs-DqJdybkd.js} +1 -1
- package/dist/web/assets/{RequestStatus-K8TZwpur.js → RequestStatus-DN-2iAM0.js} +1 -1
- package/dist/web/assets/TagInput-D-1ILLDX.js +1 -0
- package/dist/web/assets/TaskDrawer-CHD7T-Su.js +3 -0
- package/dist/web/assets/_requestId-BzSepQIV.js +30 -0
- package/dist/web/assets/_requestId-pIds2tFU.js +1 -0
- package/dist/web/assets/board-BIkOpuC4.js +1 -0
- package/dist/web/assets/directTask-Dk3H5Q2B.js +1 -0
- package/dist/web/assets/done-BUAUhIRr.js +1 -0
- package/dist/web/assets/draft-CfJeyLOl.js +1 -0
- package/dist/web/assets/index-Byv9j77D.js +12 -0
- package/dist/web/assets/index-DTfUhuQw.css +2 -0
- package/dist/web/assets/new-6kly4-PX.js +1 -0
- package/dist/web/assets/preload-helper-DlN0ouRj.js +1 -0
- package/dist/web/assets/release-notes-iwQWmfX6.js +3 -0
- package/dist/web/assets/requestData-DJ1Rlx-u.js +1 -0
- package/dist/web/assets/routes-Ciot9p4x.js +2 -0
- package/dist/web/assets/settings-DBCi6lAY.js +1 -0
- package/dist/web/assets/ui-Sz7y5_TS.js +1 -0
- package/dist/web/assets/workTarget-Cijqq4yH.js +1 -0
- package/dist/web/index.html +4 -5
- package/docs/architecture.md +62 -9
- package/docs/development.md +83 -7
- package/docs/how-to-use.md +103 -10
- package/docs/installation.md +142 -5
- package/docs/publishing.md +27 -3
- package/package.json +8 -5
- package/skills/p3/SKILL.md +2 -0
- package/src/cli/args.ts +9 -2
- package/src/cli/help.ts +9 -3
- package/src/cli/main.ts +73 -4
- package/src/cli/output.ts +18 -0
- package/src/cli/preflightCommands.ts +10 -2
- package/src/cli/project.ts +262 -98
- package/src/cli/releaseNotesCommands.ts +21 -1
- package/src/core/context.ts +3 -2
- package/src/core/preflight/codexEngine.ts +2 -1
- package/src/core/preflight/render-image/Dockerfile +3 -0
- package/src/core/preflight/render-image/fonts-ja.conf +28 -0
- package/src/core/preflight/render-image/render.mjs +10 -1
- package/src/core/preflight/render.ts +5 -2
- package/src/core/preflight/service.ts +19 -2
- package/src/core/projectRegistry.ts +264 -0
- package/src/core/releaseNotes/generate.ts +12 -0
- package/src/core/store/locate.ts +3 -3
- package/src/core/userConfig.ts +25 -0
- package/src/server/api/chatgptRoutes.ts +6 -5
- package/src/server/api/manifest.ts +9 -0
- package/src/server/api/projectsRoutes.ts +89 -0
- package/src/server/api/routes.ts +33 -25
- package/src/server/server.ts +74 -15
- package/src/shared/directTask.ts +20 -0
- package/src/shared/types.ts +1 -1
- package/dist/web/assets/TagInput-BICKVH2x.js +0 -1
- package/dist/web/assets/TaskDrawer-BkDIstIN.js +0 -3
- package/dist/web/assets/_requestId-B5O_ytaq.js +0 -1
- package/dist/web/assets/_requestId-C66puEMO.js +0 -30
- package/dist/web/assets/board-CbfDjkls.js +0 -1
- package/dist/web/assets/done-CPQbCFHg.js +0 -1
- package/dist/web/assets/draft-dT3gLDIt.js +0 -1
- package/dist/web/assets/index-BUcs2J6N.js +0 -12
- package/dist/web/assets/index-C3DkqwJ9.css +0 -2
- package/dist/web/assets/link-_s8ndNKS.js +0 -1
- package/dist/web/assets/new-T60RB7de.js +0 -1
- package/dist/web/assets/preload-helper-dXqN7N-I.js +0 -1
- package/dist/web/assets/release-notes-DxrPhDbt.js +0 -3
- package/dist/web/assets/requestData-D8ZiSZss.js +0 -1
- package/dist/web/assets/routes-D9ZxXoLk.js +0 -2
- package/dist/web/assets/settings-DsHVyqzJ.js +0 -1
- package/dist/web/assets/supersede-CLXlhCq0.js +0 -1
- package/dist/web/assets/ui-Cvke4y4X.js +0 -1
package/src/cli/project.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { execFileSync } from "node:child_process";
|
|
2
2
|
import { existsSync, readFileSync } from "node:fs";
|
|
3
|
-
import { appendFile, copyFile, mkdir } from "node:fs/promises";
|
|
3
|
+
import { appendFile, copyFile, mkdir, readFile, stat, writeFile } from "node:fs/promises";
|
|
4
4
|
import { homedir, userInfo } from "node:os";
|
|
5
5
|
import { basename, dirname, join, relative, resolve } from "node:path";
|
|
6
6
|
import { createInterface } from "node:readline/promises";
|
|
7
7
|
import { fileURLToPath } from "node:url";
|
|
8
|
+
import YAML from "yaml";
|
|
8
9
|
import { REQUEST_ID } from "../shared/refs.ts";
|
|
9
10
|
import type { ProjectConfig } from "../shared/types.ts";
|
|
10
11
|
import type { P3Context } from "../core/context.ts";
|
|
@@ -12,7 +13,7 @@ import { resolveRequestId } from "../core/ops.ts";
|
|
|
12
13
|
import { writeProjectFile, writeRepoEntry } from "../core/store/projectFile.ts";
|
|
13
14
|
import { repoNameProblem } from "../shared/repos.ts";
|
|
14
15
|
import { addRepo, checkFolder, RepoAdminError, removeRepo, setLocalRepoPath, updateRepo, type RepoPatch } from "../core/repoAdmin.ts";
|
|
15
|
-
import {
|
|
16
|
+
import { normalizeProject } from "../core/store/normalize.ts";
|
|
16
17
|
import { requestWorkstreams } from "../shared/workTarget.ts";
|
|
17
18
|
import type { Workspace } from "../core/store/workspace.ts";
|
|
18
19
|
import { DATA_DIR_NAME } from "../core/store/locate.ts";
|
|
@@ -109,18 +110,34 @@ const DOC_ENTRIES = ["README.md", "index.md"];
|
|
|
109
110
|
|
|
110
111
|
const AGENTS_MARK = "タスク管理(infodb p3)";
|
|
111
112
|
|
|
113
|
+
/** AI 向けの使い方を置く先(リポジトリのルートからの相対パス。どれも同じ原本 skills/p3/SKILL.md を写す) */
|
|
114
|
+
export const AGENT_TARGETS = {
|
|
115
|
+
claude: { path: ".claude/skills/p3/SKILL.md", agent: "Claude Code" },
|
|
116
|
+
codex: { path: ".agents/skills/p3/SKILL.md", agent: "Codex" },
|
|
117
|
+
} as const;
|
|
118
|
+
export type AgentKind = keyof typeof AGENT_TARGETS;
|
|
119
|
+
/** --agents / p3 agents の選び方(値なしの --agents は both) */
|
|
120
|
+
export const AGENT_CHOICES = { claude: ["claude"], codex: ["codex"], both: ["claude", "codex"] } as const satisfies Record<string, readonly AgentKind[]>;
|
|
121
|
+
export type AgentChoice = keyof typeof AGENT_CHOICES;
|
|
122
|
+
export const isAgentChoice = (v: unknown): v is AgentChoice => typeof v === "string" && Object.hasOwn(AGENT_CHOICES, v);
|
|
123
|
+
const KINDS = Object.keys(AGENT_TARGETS) as AgentKind[];
|
|
124
|
+
|
|
112
125
|
/**
|
|
113
|
-
*
|
|
114
|
-
*
|
|
126
|
+
* AGENTS.md / CLAUDE.md に書く指示(節)。スキルの参照は、置いた先(と既にある先)だけを書く。手順の詳しい版は同梱のスキル
|
|
127
|
+
* (skills/p3/SKILL.md)で、役割と終わり方はそちらとそろえる(test/agents.test.ts が確かめる)
|
|
115
128
|
*/
|
|
116
|
-
export
|
|
129
|
+
export function agentsSnippet(kinds: readonly AgentKind[]): string {
|
|
130
|
+
const list = KINDS.filter((k) => kinds.includes(k));
|
|
131
|
+
const skills = list.map((k) => `\`${AGENT_TARGETS[k].path}\`(${AGENT_TARGETS[k].agent})`).join("・") + (list.length > 1 ? "。中身は同じ" : "");
|
|
132
|
+
return `
|
|
117
133
|
## ${AGENTS_MARK}
|
|
118
134
|
|
|
119
135
|
- 作業の単位は要望。タスクは \`p3\` CLI(入っていなければ \`pnpx @infodb/p3\`)で操作し、\`--json\` で結果を読むこと(データのフォルダを直接編集しない)。
|
|
120
|
-
詳しい手順はスキル
|
|
136
|
+
詳しい手順はスキル ${skills}
|
|
121
137
|
- 変更するときは環境変数 \`P3_ACTOR=ai:<エージェント名>\` を付ける
|
|
122
138
|
- 操作する要望は \`--req <要望ID>\` で指定する(要望の作業ツリーの中なら省ける)。まず \`p3 whoami --json\` で確かめる
|
|
123
139
|
- \`whoami\` の \`via\`(プロジェクトの決まり方)が \`cwd\` でなければ(\`dir\` / \`project\` / \`legacy\` / \`only\`)、それ以上 p3 を操作せず、対象のプロジェクトでよいか人に確かめる(推測した \`--project\` / \`--dir\` で避けない。人が指定・確認した後はその対象のまま続ける)
|
|
140
|
+
- プロジェクトが無い・未登録のときは \`p3 init\` / \`p3 join\` を自分から実行せず、新しく作る(\`init\`)のか共有されたものに参加する(\`join\`)のかを人に確かめる
|
|
124
141
|
- 新しい作業を頼まれたら \`p3 request new "<タイトル>" --body "..."\` で要望を登録し、ID を伝えて終える。
|
|
125
142
|
Preflight(\`preflight\`)とタスク化(\`accept\`)は人が行う(AI は実行しない。結果を \`p3 drafts\` で読むのと、頼まれたメモの保存 \`--note-only\` はよい)
|
|
126
143
|
- 着手する前に \`p3 show T003 --brief --json\` で本文・依存とその状態(\`dependencies\`)・置き換えの注意(\`warnings\`)を読む
|
|
@@ -130,44 +147,101 @@ export const AGENTS_SNIPPET = `
|
|
|
130
147
|
- 置き換えられたタスク(\`p3 ls\` の \`※置換\`、\`--json\` の \`superseded\`)からは始めない。\`move\` が \`warnings\` を返したら止めて人に確かめる
|
|
131
148
|
- 作業中に新しく必要になった作業は \`p3 new "<タイトル>" --body "..."\` でタスクにする(人への質問はタスクにしない)
|
|
132
149
|
`;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/** 両方に置いたときの節(docs/architecture.md に載せる例。test/agents.test.ts が同じことを確かめる) */
|
|
153
|
+
export const AGENTS_SNIPPET = agentsSnippet(KINDS);
|
|
133
154
|
|
|
134
155
|
/**
|
|
135
|
-
*
|
|
136
|
-
* 置くのはプロジェクトの中だけ(個人のスキルの場所に置くと、p3 を使わないプロジェクトでも読まれる)
|
|
156
|
+
* 同梱のスキルの原本。置くのはプロジェクトの中だけ(個人のスキルの場所に置くと、p3 を使わないプロジェクトでも読まれる)
|
|
137
157
|
*/
|
|
138
158
|
export const SKILL_SOURCE = fileURLToPath(new URL("../../skills/p3/SKILL.md", import.meta.url));
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
159
|
+
|
|
160
|
+
/** 2つの文の最初に違う行(1 から) */
|
|
161
|
+
function firstDiffLine(a: string, b: string): number {
|
|
162
|
+
const x = a.split("\n");
|
|
163
|
+
const y = b.split("\n");
|
|
164
|
+
let i = 0;
|
|
165
|
+
while (i < x.length && i < y.length && x[i] === y[i]) i++;
|
|
166
|
+
return i + 1;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/** 指示の節(見出し「タスク管理(infodb p3)」からその見出しと同じか上の段の次の見出しの前まで。コードの囲みの中は見出しに数えない) */
|
|
170
|
+
function findSections(text: string): { start: number; end: number; level: number }[] {
|
|
171
|
+
const lines = text.split("\n");
|
|
172
|
+
const heads: { line: number; level: number; mark: boolean }[] = [];
|
|
173
|
+
let fence = false;
|
|
174
|
+
lines.forEach((l, i) => {
|
|
175
|
+
if (/^\s*(```|~~~)/.test(l)) fence = !fence;
|
|
176
|
+
const m = fence ? null : /^(#{1,6})\s+(.*?)\s*#*\s*$/.exec(l);
|
|
177
|
+
if (m) heads.push({ line: i, level: m[1].length, mark: m[2] === AGENTS_MARK });
|
|
178
|
+
});
|
|
179
|
+
return heads
|
|
180
|
+
.filter((h) => h.mark)
|
|
181
|
+
.map((h) => ({ start: h.line, level: h.level, end: heads.find((n) => n.line > h.line && n.level <= h.level)?.line ?? lines.length }));
|
|
182
|
+
}
|
|
143
183
|
|
|
144
184
|
/**
|
|
145
|
-
* --agents
|
|
146
|
-
*
|
|
147
|
-
*
|
|
185
|
+
* AI 向けの使い方を置く(init --agents と p3 agents)。kinds の先だけを扱い、ほかの先は作らず・変えず・消さない。
|
|
186
|
+
* - スキル: 無ければ置く・同じなら何もしない・違えば上書きせず違う行と最新にする方法を出す(force なら同梱の版にする)
|
|
187
|
+
* - 指示: AGENTS.md(無ければ CLAUDE.md、どちらも無ければ AGENTS.md を作る)の節。スキルの参照は kinds と既にある先。
|
|
188
|
+
* 節が無ければ足す・同じなら何もしない・違えば変えずに知らせる(force なら節だけを置き換え、前後の文は残す)。
|
|
189
|
+
* 節が複数・見出しの形が分からないときは force でも変えず、手で整理するよう知らせる
|
|
148
190
|
*/
|
|
149
|
-
async function placeAgents(root: string, cwd: string): Promise<string[]> {
|
|
191
|
+
export async function placeAgents(root: string, cwd: string, choice: AgentChoice, force = false): Promise<string[]> {
|
|
192
|
+
const kinds: readonly AgentKind[] = AGENT_CHOICES[choice];
|
|
150
193
|
const lines: string[] = [];
|
|
151
|
-
const
|
|
152
|
-
const target = join(root, agentsFile ?? "AGENTS.md");
|
|
153
|
-
if (existsSync(target) && readFileSync(target, "utf8").includes(AGENTS_MARK)) {
|
|
154
|
-
lines.push(` AI 向けの使い方は ${relative(cwd, target) || target} に書いてあります(追記しません)`);
|
|
155
|
-
} else {
|
|
156
|
-
await appendFile(target, AGENTS_SNIPPET);
|
|
157
|
-
lines.push(` AI 向けの使い方を ${relative(cwd, target) || target} に追記しました`);
|
|
158
|
-
}
|
|
194
|
+
const update = `p3 agents ${choice} --force`;
|
|
159
195
|
const source = readFileSync(SKILL_SOURCE, "utf8");
|
|
160
|
-
for (const
|
|
196
|
+
for (const k of kinds) {
|
|
197
|
+
const t = AGENT_TARGETS[k];
|
|
161
198
|
const skill = join(root, t.path);
|
|
162
|
-
const shown = relative(cwd, skill);
|
|
199
|
+
const shown = relative(cwd, skill) || skill;
|
|
163
200
|
if (!existsSync(skill)) {
|
|
164
201
|
await mkdir(dirname(skill), { recursive: true });
|
|
165
202
|
await copyFile(SKILL_SOURCE, skill);
|
|
166
|
-
lines.push(` AI 向けのスキル(${t.agent})を ${shown} に置きました`);
|
|
167
|
-
|
|
168
|
-
|
|
203
|
+
lines.push(` 作成 AI 向けのスキル(${t.agent})を ${shown} に置きました`);
|
|
204
|
+
continue;
|
|
205
|
+
}
|
|
206
|
+
const now = readFileSync(skill, "utf8");
|
|
207
|
+
if (now === source) lines.push(` 同一 AI 向けのスキル(${t.agent})${shown} は最新です`);
|
|
208
|
+
else if (force) {
|
|
209
|
+
await copyFile(SKILL_SOURCE, skill);
|
|
210
|
+
lines.push(` 更新 AI 向けのスキル(${t.agent})${shown} を同梱の版にしました`);
|
|
169
211
|
} else {
|
|
170
|
-
lines.push(` ※ ${shown}(${t.agent}
|
|
212
|
+
lines.push(` 保護 ※ ${shown}(${t.agent})は既にあり、同梱の版と違うので上書きしません(${firstDiffLine(now, source)} 行目から違います)。最新にするなら ${update}(原本: ${SKILL_SOURCE})`);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// 指示の節のスキルの参照: 置いた先と、既にある先(後から片方を足したとき、もう片方も指す。無い先は書かない)
|
|
217
|
+
const refs = KINDS.filter((k) => kinds.includes(k) || existsSync(join(root, AGENT_TARGETS[k].path)));
|
|
218
|
+
const snippet = agentsSnippet(refs);
|
|
219
|
+
const file = ["AGENTS.md", "CLAUDE.md"].find((f) => existsSync(join(root, f))) ?? "AGENTS.md";
|
|
220
|
+
const target = join(root, file);
|
|
221
|
+
const shown = relative(cwd, target) || target;
|
|
222
|
+
const text = existsSync(target) ? readFileSync(target, "utf8") : "";
|
|
223
|
+
const sections = findSections(text);
|
|
224
|
+
if (!sections.length && !text.includes(AGENTS_MARK)) {
|
|
225
|
+
await appendFile(target, text ? snippet : snippet.replace(/^\n/, ""));
|
|
226
|
+
lines.push(` 作成 AI 向けの使い方を ${shown} に${text ? "追記しました" : "書きました"}`);
|
|
227
|
+
} else if (sections.length !== 1) {
|
|
228
|
+
lines.push(
|
|
229
|
+
` 保護 ※ ${shown} の「${AGENTS_MARK}」の節が${sections.length ? `${sections.length} つあります` : "見出しとして見つかりません"}。どこまでが p3 の節か決められないので変えません。手で1つの節(見出し「## ${AGENTS_MARK}」)に整理してから、もう一度実行してください`,
|
|
230
|
+
);
|
|
231
|
+
} else {
|
|
232
|
+
const all = text.split("\n");
|
|
233
|
+
const { start, end, level } = sections[0];
|
|
234
|
+
// 見出しの段は今のもの(### などで書かれていればそのまま)
|
|
235
|
+
const body = snippet.replace(/^\n/, "").replace(/^## /, `${"#".repeat(level)} `);
|
|
236
|
+
const current = all.slice(start, end).join("\n");
|
|
237
|
+
if (current.trim() === body.trim()) lines.push(` 同一 AI 向けの使い方(${shown} の節)は最新です`);
|
|
238
|
+
else if (force) {
|
|
239
|
+
const before = all.slice(0, start).join("\n");
|
|
240
|
+
const after = all.slice(end).join("\n");
|
|
241
|
+
await writeFile(target, `${before}${before ? "\n" : ""}${body.trimEnd()}\n${after ? `\n${after.replace(/^\n+/, "")}` : ""}`);
|
|
242
|
+
lines.push(` 更新 AI 向けの使い方(${shown} の「${AGENTS_MARK}」の節)を置き換えました(前後の文はそのまま)`);
|
|
243
|
+
} else {
|
|
244
|
+
lines.push(` 保護 ※ ${shown} の「${AGENTS_MARK}」の節は同梱の版と違うので変えません。最新にするなら ${update}(節だけを置き換えます)`);
|
|
171
245
|
}
|
|
172
246
|
}
|
|
173
247
|
return lines;
|
|
@@ -182,7 +256,8 @@ export interface InitOptions {
|
|
|
182
256
|
name?: string;
|
|
183
257
|
description?: string;
|
|
184
258
|
instructions?: string;
|
|
185
|
-
|
|
259
|
+
/** AI 向けの使い方を置く先(未指定なら、対話では聞き(Enter は置かない)、非対話では置かない) */
|
|
260
|
+
agents?: AgentChoice;
|
|
186
261
|
yes?: boolean;
|
|
187
262
|
/** このリポジトリの参照先の名前(既定はフォルダ名) */
|
|
188
263
|
repoName?: string;
|
|
@@ -190,79 +265,64 @@ export interface InitOptions {
|
|
|
190
265
|
prompt?: (question: string) => Promise<string>;
|
|
191
266
|
}
|
|
192
267
|
|
|
268
|
+
/** 対話の問い(--yes・非対話なら既定値のまま)。使い終えたら close */
|
|
269
|
+
function prompter(o: { yes?: boolean; prompt?: (q: string) => Promise<string> }) {
|
|
270
|
+
const interactive = !o.yes && (!!o.prompt || (process.stdin.isTTY && process.stdout.isTTY));
|
|
271
|
+
const rl = interactive && !o.prompt ? createInterface({ input: process.stdin, output: process.stdout }) : undefined;
|
|
272
|
+
const question = o.prompt ?? (rl ? (q: string) => rl.question(q) : undefined);
|
|
273
|
+
const ask = async (q: string, def: string) => {
|
|
274
|
+
if (!question) return def;
|
|
275
|
+
const a = (await question(`${q}${def ? ` [${def}]` : ""}: `)).trim();
|
|
276
|
+
return a || def;
|
|
277
|
+
};
|
|
278
|
+
return { interactive: !!question, ask, close: () => rl?.close() };
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/** プロジェクト名とデータのフォルダ(init・join で同じ決め方。未指定はルートの .p3、指定は相対なら実行した場所から・~・絶対) */
|
|
282
|
+
async function projectAndDir(o: { cwd: string; project?: string; dir?: string }, root: string, ask: (q: string, def: string) => Promise<string>, dirQuestion: string) {
|
|
283
|
+
const key = await ask("プロジェクト名(切り替えに使う短い名前)", o.project ?? slugifyName(basename(root)) ?? "project");
|
|
284
|
+
if (!PROJECT_NAME.test(key)) throw new UsageError(`プロジェクト名は英数字と . _ - で: ${key}`);
|
|
285
|
+
// 明示した空のパスは未指定と分けて断る
|
|
286
|
+
if (o.dir !== undefined && !o.dir.trim()) throw new UsageError("--dir が空です。既定(リポジトリのルートの .p3)にするなら --dir を付けずに実行してください");
|
|
287
|
+
const dir = resolvePath(o.cwd, o.dir ?? (await ask(dirQuestion, join(root, DATA_DIR_NAME))));
|
|
288
|
+
return { key, dir };
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/** --dir の案内(既定の場所なら付けない) */
|
|
292
|
+
const dirHint = (dir: string, root: string) => (dir === join(root, DATA_DIR_NAME) ? "" : ` --dir ${dir}`);
|
|
293
|
+
|
|
193
294
|
/**
|
|
194
|
-
* p3 init
|
|
295
|
+
* p3 init。管理したいリポジトリの中で実行し、新しくプロジェクトを作る(作るだけ。既にあるプロジェクトへの参加は p3 join)。
|
|
195
296
|
* - データを置くフォルダに project.yaml と requests/ を作る。既定はリポジトリのルート(git のメインの作業ツリー。
|
|
196
297
|
* git 管理外なら実行した場所)の .p3。サブフォルダや追加の作業ツリーから実行してもルートの .p3 にする。
|
|
197
298
|
* 公開できないデータや、リポジトリと別に管理したいときは --dir でリポジトリの外を指せる
|
|
198
|
-
* -
|
|
199
|
-
* -
|
|
299
|
+
* - そのフォルダに既に project.yaml があれば、何も書かずに断って p3 join を案内する(--agents を付けても置かない)
|
|
300
|
+
* - 個人設定に「プロジェクト名 → フォルダ・手元のリポジトリ」を登録する。以後はリポジトリの中なら指定が要らない
|
|
200
301
|
* 端末から実行すると対話式で聞き、--yes か非対話(AI・スクリプト)なら引数と推測した既定値で作る。
|
|
201
302
|
*/
|
|
202
303
|
export async function init(o: InitOptions): Promise<string> {
|
|
203
304
|
const root = repoRoot(o.cwd);
|
|
204
305
|
const user = await loadUserConfig();
|
|
205
|
-
|
|
206
|
-
const interactive = !o.yes && (!!o.prompt || (process.stdin.isTTY && process.stdout.isTTY));
|
|
207
|
-
const rl = interactive && !o.prompt ? createInterface({ input: process.stdin, output: process.stdout }) : undefined;
|
|
208
|
-
const question = o.prompt ?? (rl ? (q: string) => rl.question(q) : undefined);
|
|
209
|
-
const ask = async (q: string, def: string) => {
|
|
210
|
-
if (!question) return def;
|
|
211
|
-
const a = (await question(`${q}${def ? ` [${def}]` : ""}: `)).trim();
|
|
212
|
-
return a || def;
|
|
213
|
-
};
|
|
306
|
+
const { interactive, ask, close } = prompter(o);
|
|
214
307
|
|
|
215
308
|
try {
|
|
216
|
-
if (
|
|
217
|
-
const key = await
|
|
218
|
-
|
|
219
|
-
//
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
309
|
+
if (interactive) console.log(`p3 のプロジェクトを作ります(リポジトリ: ${root})\n(Enter で [ ] 内の既定値)\n`);
|
|
310
|
+
const { key, dir } = await projectAndDir(o, root, ask, "データを置くフォルダ(相対パスは今いる場所から。リポジトリの外も指定できます)");
|
|
311
|
+
|
|
312
|
+
// 既にあるプロジェクト: 作らず、何も書かない(参加は join、AI 向けの使い方は agents)
|
|
313
|
+
if (existsSync(join(dir, "project.yaml"))) {
|
|
314
|
+
throw new UsageError(
|
|
315
|
+
[
|
|
316
|
+
`${dir} には既にプロジェクトがあります(init は新しく作るだけです。何も変えていません)`,
|
|
317
|
+
` 参加するなら: p3 join --project ${key}${dirHint(dir, root)}`,
|
|
318
|
+
...(o.agents ? [" AI 向けの使い方を置く・最新にするなら: p3 agents claude|codex|both"] : []),
|
|
319
|
+
].join("\n"),
|
|
320
|
+
);
|
|
321
|
+
}
|
|
224
322
|
const registered = user.projects[key];
|
|
225
323
|
if (registered && registered.dir !== dir) throw new UsageError(`プロジェクト名「${key}」は別のフォルダで登録済みです: ${registered.dir}`);
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
const joining = existsSync(join(dir, "project.yaml"));
|
|
229
|
-
const shared = joining ? (await (async () => { const ws = new WorkspaceStore(dir); await ws.load(); return ws.project.repos; })()) : [];
|
|
230
|
-
const derived = o.repoName ?? slugifyName(basename(root)) ?? "app";
|
|
231
|
-
const refName = joining ? (shared.find((r) => r.name === derived) ?? (shared.length === 1 ? shared[0] : undefined))?.name : derived;
|
|
232
|
-
if (!joining && repoNameProblem(refName!)) throw new UsageError(`参照先の名前: ${repoNameProblem(refName!)}(--repo-name で指定してください)`);
|
|
233
|
-
// 最新の個人設定の上で、このプロジェクトの登録だけを書く(聞いている間にほかで変わっていても消さない)
|
|
234
|
-
const register = () =>
|
|
235
|
-
updateUserConfig((doc, now) => {
|
|
236
|
-
const prev = now.projects[key];
|
|
237
|
-
if (prev && prev.dir !== dir) throw new UsageError(`プロジェクト名「${key}」は別のフォルダで登録済みです: ${prev.dir}`);
|
|
238
|
-
setProjectNode(doc, key, { dir, repos: refName ? { ...prev?.repos, [refName]: root } : (prev?.repos ?? {}) });
|
|
239
|
-
});
|
|
240
|
-
|
|
241
|
-
const agentsFile = ["AGENTS.md", "CLAUDE.md"].find((f) => existsSync(join(root, f)));
|
|
242
|
-
const askAgents = async () =>
|
|
243
|
-
o.agents ??
|
|
244
|
-
(rl ? /^y/i.test(await ask(`${agentsFile ?? "AGENTS.md"} と .claude/skills/・.agents/skills/ に AI 向けの p3 の使い方を置きますか (y/n)`, agentsFile ? "y" : "n")) : false);
|
|
245
|
-
|
|
246
|
-
// 既に作られたフォルダなら参加だけ
|
|
247
|
-
if (joining) {
|
|
248
|
-
// 登録済みのリポジトリでも --agents なら、登録とデータはそのままで AI 向けの使い方だけを置く(あとから置き場所が増えたとき)
|
|
249
|
-
const already = !!registered && (!refName || registered.repos[refName] === root);
|
|
250
|
-
if (already && !o.agents) throw new UsageError(`${key}(${dir})は登録済みです(設定の変更は p3 config。AI 向けの使い方を置くなら --agents)`);
|
|
251
|
-
if (already) return [`登録済みです: ${key} → ${dir}`, ...(await placeAgents(root, o.cwd))].join("\n");
|
|
252
|
-
const addAgents = await askAgents();
|
|
253
|
-
await register();
|
|
254
|
-
return [
|
|
255
|
-
`参加しました: ${key} → ${dir}`,
|
|
256
|
-
refName
|
|
257
|
-
? ` 参照先 ${refName} ${root}`
|
|
258
|
-
: ` このリポジトリを参照先として登録していません。p3 repo ls で名前を確かめ、p3 repo path <名前> ${root} で登録してください`,
|
|
259
|
-
...(addAgents ? await placeAgents(root, o.cwd) : []),
|
|
260
|
-
"",
|
|
261
|
-
"次に: p3 request ls / p3 serve",
|
|
262
|
-
]
|
|
263
|
-
.filter((l, i) => l || i > 1)
|
|
264
|
-
.join("\n");
|
|
265
|
-
}
|
|
324
|
+
const refName = o.repoName ?? slugifyName(basename(root)) ?? "app";
|
|
325
|
+
if (repoNameProblem(refName)) throw new UsageError(`参照先の名前: ${repoNameProblem(refName)}(--repo-name で指定してください)`);
|
|
266
326
|
|
|
267
327
|
// 既定値: git とリポジトリの中身から推測する
|
|
268
328
|
const docsFound = DOC_CANDIDATES.filter((d) => existsSync(join(root, d)));
|
|
@@ -276,23 +336,31 @@ export async function init(o: InitOptions): Promise<string> {
|
|
|
276
336
|
return { path: d, role: "ドキュメント", ...(entry ? { entry } : {}) };
|
|
277
337
|
});
|
|
278
338
|
const instructions = await ask("Preflight で重視する観点・制約(任意)", o.instructions ?? "");
|
|
279
|
-
|
|
339
|
+
// 既にある AGENTS.md / CLAUDE.md からは推測しない(Enter は置かない)
|
|
340
|
+
let agents = o.agents;
|
|
341
|
+
if (agents === undefined && interactive) {
|
|
342
|
+
const a = await ask("AI 向けの p3 の使い方(スキルと AGENTS.md / CLAUDE.md の節)を置く先(置かない / claude / codex / both)", "置かない");
|
|
343
|
+
if (!["置かない", "none", "n", "no"].includes(a)) {
|
|
344
|
+
if (!isAgentChoice(a)) throw new UsageError(`置く先は 置かない / claude / codex / both のどれか: ${a}`);
|
|
345
|
+
agents = a;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
280
348
|
|
|
281
349
|
const cfg: ProjectConfig = {
|
|
282
350
|
name,
|
|
283
351
|
description,
|
|
284
352
|
// このリポジトリを本体の参照先にする(このマシンのパスは個人設定に持ち、共有するデータには書かない)
|
|
285
|
-
repos: [{ name: refName
|
|
353
|
+
repos: [{ name: refName, role: "本体", readFirst: true, writable: true, map }],
|
|
286
354
|
milestones: [],
|
|
287
355
|
branchPattern: "req/{id}-{slug}",
|
|
288
356
|
preflight: { instructions },
|
|
289
357
|
};
|
|
290
358
|
await mkdir(join(dir, "requests"), { recursive: true });
|
|
291
359
|
await writeProjectFile(join(dir, "project.yaml"), cfg);
|
|
292
|
-
await writeRepoEntry(join(dir, "project.yaml"), refName
|
|
293
|
-
await register();
|
|
360
|
+
await writeRepoEntry(join(dir, "project.yaml"), refName, cfg.repos[0]);
|
|
361
|
+
await register(key, dir, refName, root);
|
|
294
362
|
|
|
295
|
-
const agentLines =
|
|
363
|
+
const agentLines = agents ? await placeAgents(root, o.cwd, agents) : [];
|
|
296
364
|
return [
|
|
297
365
|
`作りました: ${key} → ${dir}`,
|
|
298
366
|
` 参照先 ${refName}(本体) → ${root}`,
|
|
@@ -307,7 +375,103 @@ export async function init(o: InitOptions): Promise<string> {
|
|
|
307
375
|
.join("\n")
|
|
308
376
|
.trimEnd();
|
|
309
377
|
} finally {
|
|
310
|
-
|
|
378
|
+
close();
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
/** 最新の個人設定の上で、このプロジェクトの登録だけを書く(聞いている間にほかで変わっていても、ほかの登録・項目は消さない) */
|
|
383
|
+
function register(key: string, dir: string, refName: string | undefined, root: string) {
|
|
384
|
+
return updateUserConfig((doc, now) => {
|
|
385
|
+
const prev = now.projects[key];
|
|
386
|
+
if (prev && prev.dir !== dir) throw new UsageError(`プロジェクト名「${key}」は別のフォルダで登録済みです: ${prev.dir}`);
|
|
387
|
+
setProjectNode(doc, key, { dir, repos: refName ? { ...prev?.repos, [refName]: root } : (prev?.repos ?? {}) });
|
|
388
|
+
});
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
/** 参加する前に、データのフォルダが読める p3 のプロジェクトかを確かめ、共有の定義(読むだけ)を返す */
|
|
392
|
+
async function readSharedProject(dir: string): Promise<ProjectConfig> {
|
|
393
|
+
const create = "新しく作るなら p3 init";
|
|
394
|
+
const st = await stat(dir).catch((e: NodeJS.ErrnoException) => e);
|
|
395
|
+
if (st instanceof Error) {
|
|
396
|
+
throw new UsageError(
|
|
397
|
+
st.code === "ENOENT"
|
|
398
|
+
? `データのフォルダがありません: ${dir}(パスと、共有のフォルダがつながっているかを確かめてください。${create})`
|
|
399
|
+
: `データのフォルダを読めません: ${dir}(${st.code ?? st.message})`,
|
|
400
|
+
);
|
|
401
|
+
}
|
|
402
|
+
if (!st.isDirectory()) throw new UsageError(`データのフォルダがフォルダではありません: ${dir}`);
|
|
403
|
+
const file = join(dir, "project.yaml");
|
|
404
|
+
let text: string;
|
|
405
|
+
try {
|
|
406
|
+
text = await readFile(file, "utf8");
|
|
407
|
+
} catch (e) {
|
|
408
|
+
const code = (e as NodeJS.ErrnoException).code;
|
|
409
|
+
throw new UsageError(
|
|
410
|
+
code === "ENOENT"
|
|
411
|
+
? `${dir} は p3 のプロジェクトではありません(project.yaml がありません)。指したフォルダと中身を確かめてください(参加では作りません。${create})`
|
|
412
|
+
: `project.yaml を読めません: ${file}(${code ?? (e as Error).message})`,
|
|
413
|
+
);
|
|
414
|
+
}
|
|
415
|
+
let data: unknown;
|
|
416
|
+
try {
|
|
417
|
+
data = YAML.parse(text);
|
|
418
|
+
} catch (e) {
|
|
419
|
+
throw new UsageError(`project.yaml を読めません(YAML として壊れています): ${file}: ${(e as Error).message.split("\n")[0]}`);
|
|
420
|
+
}
|
|
421
|
+
if (!data || typeof data !== "object" || Array.isArray(data)) throw new UsageError(`project.yaml の中身が p3 の設定ではありません: ${file}`);
|
|
422
|
+
return normalizeProject(data as Record<string, unknown>);
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
export interface JoinOptions {
|
|
426
|
+
cwd: string;
|
|
427
|
+
project?: string;
|
|
428
|
+
dir?: string;
|
|
429
|
+
repoName?: string;
|
|
430
|
+
yes?: boolean;
|
|
431
|
+
prompt?: (question: string) => Promise<string>;
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
/**
|
|
435
|
+
* p3 join。既にあるプロジェクト(ほかの人が作って共有したデータのフォルダ)に参加する。個人設定に
|
|
436
|
+
* 「プロジェクト名 → フォルダ・このリポジトリのこのマシンのパス」を登録するだけで、共有の定義・データ・
|
|
437
|
+
* AI 向けのファイル(スキル・AGENTS.md / CLAUDE.md)は書かない。データのフォルダの既定と指定の仕方は init と同じ。
|
|
438
|
+
* - このリポジトリを登録する参照先: --repo-name(共有の定義にある名前)→ フォルダ名と同じ名前 → 参照先が1つならそれ。
|
|
439
|
+
* 決まらなければ登録せず p3 repo path を案内する
|
|
440
|
+
* - 同じ名前で別のフォルダは断る。同じ名前・同じフォルダ・同じパスなら何もしない(成功)
|
|
441
|
+
*/
|
|
442
|
+
export async function joinProject(o: JoinOptions): Promise<string> {
|
|
443
|
+
const root = repoRoot(o.cwd);
|
|
444
|
+
const { interactive, ask, close } = prompter(o);
|
|
445
|
+
try {
|
|
446
|
+
if (interactive) console.log(`p3 のプロジェクトに参加します(リポジトリ: ${root})\n(Enter で [ ] 内の既定値)\n`);
|
|
447
|
+
const { key, dir } = await projectAndDir(o, root, ask, "参加するデータのフォルダ(相対パスは今いる場所から)");
|
|
448
|
+
const shared = (await readSharedProject(dir)).repos;
|
|
449
|
+
let refName: string | undefined;
|
|
450
|
+
if (o.repoName !== undefined) {
|
|
451
|
+
if (!shared.some((r) => r.name === o.repoName)) {
|
|
452
|
+
throw new UsageError(`参照先「${o.repoName}」は共有の定義にありません(あるもの: ${shared.map((r) => r.name).join(", ") || "なし"})`);
|
|
453
|
+
}
|
|
454
|
+
refName = o.repoName;
|
|
455
|
+
} else {
|
|
456
|
+
const derived = slugifyName(basename(root));
|
|
457
|
+
refName = (shared.find((r) => r.name === derived) ?? (shared.length === 1 ? shared[0] : undefined))?.name;
|
|
458
|
+
}
|
|
459
|
+
const user = await loadUserConfig();
|
|
460
|
+
const prev = user.projects[key];
|
|
461
|
+
if (prev && prev.dir !== dir) throw new UsageError(`プロジェクト名「${key}」は別のフォルダで登録済みです: ${prev.dir}`);
|
|
462
|
+
if (prev && (!refName || prev.repos[refName] === root)) return `登録済みです: ${key} → ${dir}(変えていません)`;
|
|
463
|
+
await register(key, dir, refName, root);
|
|
464
|
+
return [
|
|
465
|
+
`参加しました: ${key} → ${dir}`,
|
|
466
|
+
refName
|
|
467
|
+
? ` 参照先 ${refName} ${root}`
|
|
468
|
+
: ` このリポジトリを参照先として登録していません。p3 repo ls で名前を確かめ、p3 repo path <名前> ${root} で登録してください`,
|
|
469
|
+
` 個人設定 ${userConfigPath()} に登録しました(データ・リポジトリのファイルは変えていません)`,
|
|
470
|
+
"",
|
|
471
|
+
"次に: p3 request ls / p3 serve",
|
|
472
|
+
].join("\n");
|
|
473
|
+
} finally {
|
|
474
|
+
close();
|
|
311
475
|
}
|
|
312
476
|
}
|
|
313
477
|
|
|
@@ -327,7 +491,7 @@ export async function projectCommand(
|
|
|
327
491
|
data: rows,
|
|
328
492
|
text: rows.length
|
|
329
493
|
? rows.map((r) => `${r.current ? "*" : " "} ${r.name.padEnd(w)} ${r.dir}${Object.keys(r.repos).length ? ` (参照先 ${Object.keys(r.repos).join(", ")})` : ""}`).join("\n")
|
|
330
|
-
: "登録済みのプロジェクトはありません。管理したいリポジトリの中で p3 init --project
|
|
494
|
+
: "登録済みのプロジェクトはありません。管理したいリポジトリの中で p3 init --project <名前>(新しく作る)か p3 join --project <名前>(参加する)",
|
|
331
495
|
};
|
|
332
496
|
}
|
|
333
497
|
if (sub === "add") {
|
|
@@ -5,6 +5,8 @@ import { exportReleaseNote, releaseNoteDetail, releaseOverview, saveReleaseNote,
|
|
|
5
5
|
import { readBody, type CommandEnv } from "./args.ts";
|
|
6
6
|
import { table } from "./format.ts";
|
|
7
7
|
import { UsageError } from "./project.ts";
|
|
8
|
+
import { shellArg } from "./output.ts";
|
|
9
|
+
import { GenerationRejected } from "../core/releaseNotes/generate.ts";
|
|
8
10
|
|
|
9
11
|
/**
|
|
10
12
|
* p3 release-notes ... マイルストーンごとのリリースノート(規則と保存は core/releaseNotes)
|
|
@@ -56,7 +58,12 @@ export async function releaseNotesCommand(env: CommandEnv): Promise<number> {
|
|
|
56
58
|
|
|
57
59
|
case "generate": {
|
|
58
60
|
if (o.engine !== undefined && o.engine !== "codex" && o.engine !== "mock") throw new UsageError("--engine は codex か mock");
|
|
59
|
-
const
|
|
61
|
+
const id = need();
|
|
62
|
+
const g = await startGeneration(ctx, id, actor, o.engine).catch((e: Error) => {
|
|
63
|
+
// 始められなければ手で書く道を添える(実行中は別の理由なので添えない。終了コードは変えない)
|
|
64
|
+
if (e instanceof GenerationRejected && e.code !== "running") e.message += `\n${manualSaveHint(id)}`;
|
|
65
|
+
throw e;
|
|
66
|
+
});
|
|
60
67
|
const gen = ctx.releaseGenerator;
|
|
61
68
|
// 進み具合は stderr(stdout は本文の案か JSON だけにする)
|
|
62
69
|
let shown = 0;
|
|
@@ -71,6 +78,8 @@ export async function releaseNotesCommand(env: CommandEnv): Promise<number> {
|
|
|
71
78
|
if (done.status !== "completed") {
|
|
72
79
|
if (out.json) out.result(done, () => "");
|
|
73
80
|
else process.stderr.write(`${failureLine(done)}\n`);
|
|
81
|
+
// 失敗したら手で書く道を stderr に出す(--json の stdout は変えない。取消は失敗と扱わない)
|
|
82
|
+
if (done.status === "failed") process.stderr.write(`${manualSaveHint(done.milestone)}\n`);
|
|
74
83
|
return 1;
|
|
75
84
|
}
|
|
76
85
|
if (!out.json) {
|
|
@@ -123,6 +132,17 @@ function flushLog(g: ReleaseGeneration, from: number): number {
|
|
|
123
132
|
return g.log.length;
|
|
124
133
|
}
|
|
125
134
|
|
|
135
|
+
/** 要約を生成できないときの、本文を手で書いて保存する道(Codex・Docker・ChatGPT は要らない) */
|
|
136
|
+
function manualSaveHint(mid: string): string {
|
|
137
|
+
const m = shellArg(mid);
|
|
138
|
+
return [
|
|
139
|
+
"生成せずに、本文を手で書いて保存できます(Docker や ChatGPT の接続は要りません):",
|
|
140
|
+
` p3 release-notes show ${m} # 材料(収録する要望と変更の記録)を確かめる`,
|
|
141
|
+
` p3 release-notes save ${m} --file <本文.md> # 新しく保存する`,
|
|
142
|
+
` 既にノートがあるときは、show で読んだ版を付けて更新します: p3 release-notes save ${m} --file <本文.md> --version <版>`,
|
|
143
|
+
].join("\n");
|
|
144
|
+
}
|
|
145
|
+
|
|
126
146
|
function failureLine(g: ReleaseGeneration): string {
|
|
127
147
|
if (g.status === "cancelled") return "取り消しました(保存したノートは変えていません)";
|
|
128
148
|
return `生成できませんでした(${g.failure}): ${g.error}(保存したノートは変えていません)`;
|
package/src/core/context.ts
CHANGED
|
@@ -33,7 +33,7 @@ export interface P3Context {
|
|
|
33
33
|
*/
|
|
34
34
|
export async function openProject(
|
|
35
35
|
dataDir: string,
|
|
36
|
-
opts: { repos?: Record<string, string>; settings?: MachineSettings | SettingsSource; projectName?: string } = {},
|
|
36
|
+
opts: { repos?: Record<string, string>; settings?: MachineSettings | SettingsSource; projectName?: string; chatgpt?: ChatGptAccount } = {},
|
|
37
37
|
): Promise<P3Context> {
|
|
38
38
|
// データのフォルダと project.yaml が無ければ、空のプロジェクトとして開かずに止める(何も作らない)
|
|
39
39
|
await checkDataDir(dataDir, opts.projectName);
|
|
@@ -44,7 +44,8 @@ export async function openProject(
|
|
|
44
44
|
await ws.load();
|
|
45
45
|
// 既定は Codex(ChatGPT プランか旧来の auth.json。どちらも無ければ使えない理由と次にすることを出す)。
|
|
46
46
|
// Mock は preflight.engine: mock(P3_PREFLIGHT_ENGINE=mock)か --engine mock で明示したときだけ(認証の失敗を Mock の成功に見せない)
|
|
47
|
-
|
|
47
|
+
// プロジェクトを跨ぐ serve では、サインインの待ち受けを全プロジェクトで1つにするため外から渡す
|
|
48
|
+
const chatgpt = opts.chatgpt ?? chatgptAccount();
|
|
48
49
|
const codex = new CodexWorkspaceEngine({ load: async () => codexConfig(await source.get()), account: chatgpt });
|
|
49
50
|
const engines: Partial<Record<PreflightEngine["name"], PreflightEngine>> = { codex, mock: new MockEngine() };
|
|
50
51
|
const preflight = new PreflightService(ws, engines, {
|
|
@@ -629,7 +629,8 @@ function uiSection(paths: ContainerPaths) {
|
|
|
629
629
|
日本語のラベル・項目・配置・主な操作(ボタン・リンク)・前提(仮のデータなど)が読めるように書いてください。
|
|
630
630
|
見た目の作り込みより、何がどこにあるかが分かることを優先します。複数のタスク案を1画面にまとめてもよいが、drafts で対応を示してください。
|
|
631
631
|
- 自己完結した HTML と <style> の CSS だけで書いてください。スクリプト・onclick などの属性・外のファイルや URL の参照(画像・CSS・フォント・
|
|
632
|
-
@import・相対パス)は使えません(P3 が断ります)。画像が要るなら data: の PNG / JPEG / SVG
|
|
632
|
+
@import・相対パス)は使えません(P3 が断ります)。画像が要るなら data: の PNG / JPEG / SVG にしてください。フォントは指定しなくても日本語のゴシック体(sans-serif)で描きます。
|
|
633
|
+
明朝体・等幅が要るところだけ serif(明朝体にするなら "Noto Serif JP" などの名前)・monospace を指定してください。
|
|
633
634
|
- PNG は Codex の終了後に P3 が原稿から描いて ui/index.json に書き足します。あなたは PNG を作らず、画像を見たとも書かないでください。
|
|
634
635
|
- 再評価で前回の画面イメージがあれば(引き継ぎに書いてあります)、それは前回の提案で、今の画面の証拠ではありません。
|
|
635
636
|
変えた案に合わせて、今回の run の ui/ に原稿を書き直してください(前回のファイルは書き換えない)。
|
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
# Codex のコンテナとは別のイメージ。P3(ホストのプロセス)が docker run で動かし、
|
|
4
4
|
# ネットワークなし・認証情報なし・リポジトリなしで、確かめた原稿(読むだけ)と出力のフォルダだけをマウントする。
|
|
5
5
|
# Playwright と Chromium(headless shell)の版は固定し、日本語のフォント(Noto CJK, SIL Open Font License 1.1)を入れる。
|
|
6
|
+
# 日本語の既定と、イメージに無い日本語のフォント名は fonts-ja.conf で Noto CJK JP にする(Playwright の依存で入る
|
|
7
|
+
# 中国語の字形のフォントが先に選ばれないように)。
|
|
6
8
|
FROM node:22-bookworm-slim
|
|
7
9
|
|
|
8
10
|
ENV PLAYWRIGHT_BROWSERS_PATH=/ms-playwright \
|
|
@@ -16,6 +18,7 @@ RUN npm install --no-save --no-audit --no-fund --no-package-lock playwright@1.63
|
|
|
16
18
|
&& rm -rf /var/lib/apt/lists/* /root/.npm /tmp/* \
|
|
17
19
|
&& useradd --create-home --uid 10001 render
|
|
18
20
|
|
|
21
|
+
COPY fonts-ja.conf /etc/fonts/conf.d/99-p3-ja.conf
|
|
19
22
|
COPY render.mjs /render/render.mjs
|
|
20
23
|
|
|
21
24
|
USER render
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
<?xml version="1.0"?>
|
|
2
|
+
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
|
|
3
|
+
<!--
|
|
4
|
+
画面イメージの描画で、日本語を Noto CJK JP で描く(Dockerfile が /etc/fonts/conf.d/ に置く)。
|
|
5
|
+
Playwright の依存で入る WenQuanYi Zen Hei(中国語の字形)が総称の既定に先に来るので、総称と、イメージに無い日本語の
|
|
6
|
+
フォント名を Noto CJK JP に寄せる。原稿が明示したほかのフォント(Noto Sans CJK SC など)と埋め込みのフォントには触れない。
|
|
7
|
+
-->
|
|
8
|
+
<fontconfig>
|
|
9
|
+
<!-- 総称 -->
|
|
10
|
+
<alias binding="strong"><family>sans-serif</family><prefer><family>Noto Sans CJK JP</family></prefer></alias>
|
|
11
|
+
<alias binding="strong"><family>system-ui</family><prefer><family>Noto Sans CJK JP</family></prefer></alias>
|
|
12
|
+
<alias binding="strong"><family>serif</family><prefer><family>Noto Serif CJK JP</family></prefer></alias>
|
|
13
|
+
<alias binding="strong"><family>monospace</family><prefer><family>Noto Sans Mono CJK JP</family></prefer></alias>
|
|
14
|
+
|
|
15
|
+
<!-- イメージに無い日本語のゴシック体 -->
|
|
16
|
+
<alias binding="strong"><family>Noto Sans JP</family><prefer><family>Noto Sans CJK JP</family></prefer></alias>
|
|
17
|
+
<alias binding="strong"><family>Hiragino Sans</family><prefer><family>Noto Sans CJK JP</family></prefer></alias>
|
|
18
|
+
<alias binding="strong"><family>Hiragino Kaku Gothic ProN</family><prefer><family>Noto Sans CJK JP</family></prefer></alias>
|
|
19
|
+
<alias binding="strong"><family>ヒラギノ角ゴ ProN</family><prefer><family>Noto Sans CJK JP</family></prefer></alias>
|
|
20
|
+
<alias binding="strong"><family>Yu Gothic</family><prefer><family>Noto Sans CJK JP</family></prefer></alias>
|
|
21
|
+
<alias binding="strong"><family>游ゴシック</family><prefer><family>Noto Sans CJK JP</family></prefer></alias>
|
|
22
|
+
|
|
23
|
+
<!-- イメージに無い日本語の明朝体 -->
|
|
24
|
+
<alias binding="strong"><family>Noto Serif JP</family><prefer><family>Noto Serif CJK JP</family></prefer></alias>
|
|
25
|
+
<alias binding="strong"><family>Hiragino Mincho ProN</family><prefer><family>Noto Serif CJK JP</family></prefer></alias>
|
|
26
|
+
<alias binding="strong"><family>Yu Mincho</family><prefer><family>Noto Serif CJK JP</family></prefer></alias>
|
|
27
|
+
<alias binding="strong"><family>游明朝</family><prefer><family>Noto Serif CJK JP</family></prefer></alias>
|
|
28
|
+
</fontconfig>
|
|
@@ -5,6 +5,15 @@
|
|
|
5
5
|
import { readFile } from "node:fs/promises";
|
|
6
6
|
import { chromium } from "playwright";
|
|
7
7
|
|
|
8
|
+
// フォントを指定していない原稿も、ゴシック体(sans-serif)で描く(Chromium の既定は Times New Roman で、欧文が明朝系になる)。
|
|
9
|
+
// 原稿の先頭(doctype の後)に置き、詳細度 0 にするので、原稿のどの指定よりも弱い
|
|
10
|
+
const BASE_STYLE = "<style>:where(html){font-family:sans-serif}</style>";
|
|
11
|
+
const DOCTYPE = /^\uFEFF?\s*(?:<!--[\s\S]*?-->\s*)*<!doctype[^>]*>/i;
|
|
12
|
+
const withBaseStyle = (html) => {
|
|
13
|
+
const m = DOCTYPE.exec(html);
|
|
14
|
+
return m ? m[0] + BASE_STYLE + html.slice(m[0].length) : BASE_STYLE + html;
|
|
15
|
+
};
|
|
16
|
+
|
|
8
17
|
const MAX_HEIGHT = Number(process.env.P3_RENDER_MAX_HEIGHT ?? 16384);
|
|
9
18
|
const PAGE_TIMEOUT = Number(process.env.P3_RENDER_PAGE_TIMEOUT ?? 20000);
|
|
10
19
|
|
|
@@ -31,7 +40,7 @@ try {
|
|
|
31
40
|
});
|
|
32
41
|
const page = await context.newPage();
|
|
33
42
|
page.setDefaultTimeout(PAGE_TIMEOUT);
|
|
34
|
-
await page.setContent(await readFile(`/in/${job.file}`, "utf8"), { waitUntil: "load", timeout: PAGE_TIMEOUT });
|
|
43
|
+
await page.setContent(withBaseStyle(await readFile(`/in/${job.file}`, "utf8")), { waitUntil: "load", timeout: PAGE_TIMEOUT });
|
|
35
44
|
const path = `/out/${job.id}.png`;
|
|
36
45
|
await page.screenshot({ path, fullPage: true, animations: "disabled", timeout: PAGE_TIMEOUT });
|
|
37
46
|
// 縦に長すぎるときは上から切る
|