@infodb/p3 0.2.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/README.md +6 -1
  2. package/dist/web/assets/{Outputs-Ni3pNuGU.js → Outputs-5Hby-S5Q.js} +1 -1
  3. package/dist/web/assets/{RequestStatus-K8TZwpur.js → RequestStatus-CTkGjT02.js} +1 -1
  4. package/dist/web/assets/TagInput-Rj3PNOAF.js +1 -0
  5. package/dist/web/assets/TaskDrawer-DtPhiYxP.js +3 -0
  6. package/dist/web/assets/_requestId-CGvAfIkB.js +30 -0
  7. package/dist/web/assets/_requestId-DxfYhgAq.js +1 -0
  8. package/dist/web/assets/board-wt47lfrE.js +1 -0
  9. package/dist/web/assets/copy-CKsXEjMi.js +1 -0
  10. package/dist/web/assets/directTask-Dk3H5Q2B.js +1 -0
  11. package/dist/web/assets/done-C9Ct7ssb.js +1 -0
  12. package/dist/web/assets/draft-CfJeyLOl.js +1 -0
  13. package/dist/web/assets/index-BTFL2rpp.js +12 -0
  14. package/dist/web/assets/index-DAyBsvua.css +2 -0
  15. package/dist/web/assets/milestoneOrder-N7b5XFJP.js +1 -0
  16. package/dist/web/assets/new-e4ID2vQV.js +1 -0
  17. package/dist/web/assets/preflightInput-DMxqnvF8.js +2 -0
  18. package/dist/web/assets/preload-helper-DhIyFaOW.js +1 -0
  19. package/dist/web/assets/release-notes-CQ0d2r0k.js +3 -0
  20. package/dist/web/assets/requestData-BDZqyl35.js +1 -0
  21. package/dist/web/assets/routes-Bipv3lwJ.js +2 -0
  22. package/dist/web/assets/settings-Dwh8fj6p.js +1 -0
  23. package/dist/web/assets/ui-DdOGYj9z.js +1 -0
  24. package/dist/web/assets/workTarget-Cijqq4yH.js +1 -0
  25. package/dist/web/index.html +4 -5
  26. package/docs/architecture.md +80 -15
  27. package/docs/development.md +83 -7
  28. package/docs/how-to-use.md +159 -15
  29. package/docs/installation.md +142 -5
  30. package/docs/publishing.md +27 -3
  31. package/package.json +8 -5
  32. package/skills/p3/SKILL.md +21 -8
  33. package/src/cli/args.ts +9 -2
  34. package/src/cli/help.ts +12 -3
  35. package/src/cli/main.ts +75 -5
  36. package/src/cli/output.ts +18 -0
  37. package/src/cli/preflightCommands.ts +10 -2
  38. package/src/cli/project.ts +268 -101
  39. package/src/cli/releaseNotesCommands.ts +63 -4
  40. package/src/cli/requestCommands.ts +4 -2
  41. package/src/cli/taskCommands.ts +1 -1
  42. package/src/core/context.ts +3 -2
  43. package/src/core/preflight/codexEngine.ts +2 -1
  44. package/src/core/preflight/render-image/Dockerfile +3 -0
  45. package/src/core/preflight/render-image/fonts-ja.conf +28 -0
  46. package/src/core/preflight/render-image/render.mjs +10 -1
  47. package/src/core/preflight/render.ts +5 -2
  48. package/src/core/preflight/service.ts +19 -2
  49. package/src/core/projectRegistry.ts +264 -0
  50. package/src/core/releaseNotes/completeRequests.ts +102 -0
  51. package/src/core/releaseNotes/generate.ts +12 -0
  52. package/src/core/releaseNotes/service.ts +9 -5
  53. package/src/core/store/locate.ts +3 -3
  54. package/src/core/userConfig.ts +25 -0
  55. package/src/server/api/chatgptRoutes.ts +6 -5
  56. package/src/server/api/manifest.ts +17 -1
  57. package/src/server/api/projectsRoutes.ts +89 -0
  58. package/src/server/api/releaseNoteRoutes.ts +11 -0
  59. package/src/server/api/routes.ts +33 -25
  60. package/src/server/server.ts +74 -15
  61. package/src/shared/directTask.ts +20 -0
  62. package/src/shared/milestoneOrder.ts +44 -0
  63. package/src/shared/types.ts +31 -1
  64. package/dist/web/assets/TagInput-BICKVH2x.js +0 -1
  65. package/dist/web/assets/TaskDrawer-BkDIstIN.js +0 -3
  66. package/dist/web/assets/_requestId-B5O_ytaq.js +0 -1
  67. package/dist/web/assets/_requestId-C66puEMO.js +0 -30
  68. package/dist/web/assets/board-CbfDjkls.js +0 -1
  69. package/dist/web/assets/copy-B1ZbihKL.js +0 -2
  70. package/dist/web/assets/done-CPQbCFHg.js +0 -1
  71. package/dist/web/assets/draft-dT3gLDIt.js +0 -1
  72. package/dist/web/assets/index-BUcs2J6N.js +0 -12
  73. package/dist/web/assets/index-C3DkqwJ9.css +0 -2
  74. package/dist/web/assets/link-_s8ndNKS.js +0 -1
  75. package/dist/web/assets/new-T60RB7de.js +0 -1
  76. package/dist/web/assets/preload-helper-dXqN7N-I.js +0 -1
  77. package/dist/web/assets/release-notes-DxrPhDbt.js +0 -3
  78. package/dist/web/assets/requestData-D8ZiSZss.js +0 -1
  79. package/dist/web/assets/routes-D9ZxXoLk.js +0 -2
  80. package/dist/web/assets/settings-DsHVyqzJ.js +0 -1
  81. package/dist/web/assets/supersede-CLXlhCq0.js +0 -1
  82. package/dist/web/assets/ui-Cvke4y4X.js +0 -1
@@ -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,10 +13,11 @@ 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 { Workspace as WorkspaceStore } from "../core/store/workspace.ts";
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";
20
+ import { sortMilestones } from "../shared/milestoneOrder.ts";
19
21
  import { loadUserConfig, PROJECT_NAME, setProjectNode, updateUserConfig, userConfigPath } from "../core/userConfig.ts";
20
22
 
21
23
  /** プロジェクトの初期設定・設定変更、変更者と「今の要望」の判定(CLI) */
@@ -109,65 +111,140 @@ const DOC_ENTRIES = ["README.md", "index.md"];
109
111
 
110
112
  const AGENTS_MARK = "タスク管理(infodb p3)";
111
113
 
114
+ /** AI 向けの使い方を置く先(リポジトリのルートからの相対パス。どれも同じ原本 skills/p3/SKILL.md を写す) */
115
+ export const AGENT_TARGETS = {
116
+ claude: { path: ".claude/skills/p3/SKILL.md", agent: "Claude Code" },
117
+ codex: { path: ".agents/skills/p3/SKILL.md", agent: "Codex" },
118
+ } as const;
119
+ export type AgentKind = keyof typeof AGENT_TARGETS;
120
+ /** --agents / p3 agents の選び方(値なしの --agents は both) */
121
+ export const AGENT_CHOICES = { claude: ["claude"], codex: ["codex"], both: ["claude", "codex"] } as const satisfies Record<string, readonly AgentKind[]>;
122
+ export type AgentChoice = keyof typeof AGENT_CHOICES;
123
+ export const isAgentChoice = (v: unknown): v is AgentChoice => typeof v === "string" && Object.hasOwn(AGENT_CHOICES, v);
124
+ const KINDS = Object.keys(AGENT_TARGETS) as AgentKind[];
125
+
112
126
  /**
113
- * p3 init --agents で AGENTS.md / CLAUDE.md に追記する指示。手順の詳しい版は同梱のスキル(skills/p3/SKILL.md)で、
114
- * 役割と終わり方はそちらとそろえる(test/agents.test.ts が確かめる)
127
+ * AGENTS.md / CLAUDE.md に書く指示(節)。スキルの参照は、置いた先(と既にある先)だけを書く。手順の詳しい版は同梱のスキル
128
+ * (skills/p3/SKILL.md)で、役割と終わり方はそちらとそろえる(test/agents.test.ts が確かめる)
115
129
  */
116
- export const AGENTS_SNIPPET = `
130
+ export function agentsSnippet(kinds: readonly AgentKind[]): string {
131
+ const list = KINDS.filter((k) => kinds.includes(k));
132
+ const skills = list.map((k) => `\`${AGENT_TARGETS[k].path}\`(${AGENT_TARGETS[k].agent})`).join("・") + (list.length > 1 ? "。中身は同じ" : "");
133
+ return `
117
134
  ## ${AGENTS_MARK}
118
135
 
119
136
  - 作業の単位は要望。タスクは \`p3\` CLI(入っていなければ \`pnpx @infodb/p3\`)で操作し、\`--json\` で結果を読むこと(データのフォルダを直接編集しない)。
120
- 詳しい手順はスキル \`.claude/skills/p3/SKILL.md\`(Claude Code)・\`.agents/skills/p3/SKILL.md\`(Codex)。中身は同じ
137
+ 詳しい手順はスキル ${skills}
121
138
  - 変更するときは環境変数 \`P3_ACTOR=ai:<エージェント名>\` を付ける
122
139
  - 操作する要望は \`--req <要望ID>\` で指定する(要望の作業ツリーの中なら省ける)。まず \`p3 whoami --json\` で確かめる
123
140
  - \`whoami\` の \`via\`(プロジェクトの決まり方)が \`cwd\` でなければ(\`dir\` / \`project\` / \`legacy\` / \`only\`)、それ以上 p3 を操作せず、対象のプロジェクトでよいか人に確かめる(推測した \`--project\` / \`--dir\` で避けない。人が指定・確認した後はその対象のまま続ける)
141
+ - プロジェクトが無い・未登録のときは \`p3 init\` / \`p3 join\` を自分から実行せず、新しく作る(\`init\`)のか共有されたものに参加する(\`join\`)のかを人に確かめる
124
142
  - 新しい作業を頼まれたら \`p3 request new "<タイトル>" --body "..."\` で要望を登録し、ID を伝えて終える。
125
143
  Preflight(\`preflight\`)とタスク化(\`accept\`)は人が行う(AI は実行しない。結果を \`p3 drafts\` で読むのと、頼まれたメモの保存 \`--note-only\` はよい)
126
144
  - 着手する前に \`p3 show T003 --brief --json\` で本文・依存とその状態(\`dependencies\`)・置き換えの注意(\`warnings\`)を読む
127
145
  - 着手する前に、\`--brief --json\` の \`work\`(作業先のリポジトリとブランチ)を見て、そのリポジトリでブランチに入る(作業先なしなら移動しない)
128
- - 着手するときは \`p3 move T003 doing\`、終えたら \`p3 move T003 done --output <PR の URL など> --record -\`(変更の記録は必須: 何を変えたか・なぜ・入れた決まり・やめたもの を標準入力から Markdown で)。複数のリポジトリにまたがるときは最後のタスクに \`--repo-output <参照先>=<PR の URL>\` で全部の PR を残す
129
- - 要望のタスクを全部終えたら \`p3 request set <要望ID> status=resolved\`(対応済)にする。完了済(done)・見送り(rejected)とタスクの済み(check)は人が決める
146
+ - 着手するときは \`p3 move T003 doing\`。テストを通したら、コミットする前に \`p3 move T003 done --output <今ある成果物(変えたファイルや説明)> --record -\` で完了にする(変更の記録は必須: 何を変えたか・なぜ・入れた決まり・やめたもの を標準入力から Markdown で。まだ無い URL は書かない)
147
+ - 要望のタスクを全部終えたら、コミットする前に \`p3 request set <要望ID> status=resolved\`(対応済)にする。完了済(done)・見送り(rejected)とタスクの済み(check)は人が決める
148
+ - データのフォルダがこの作業ツリーの中で git 管理されているなら、要望のフォルダ(\`requests/<要望ID>/\`)の変更も実装と同じコミットに入れる(ほかの要望・関係ない変更は入れない。外・無視・worktree のときは入らないので、移動や \`git add -f\` はしない)。push に失敗したら完了の記録は残し、公開できていないことを伝える
149
+ - コミットや PR の URL は後から \`p3 move T003 done --output <URL>\` で足す(完了・記録はそのまま。データをコミットしているなら追記もコミットして push)。複数のリポジトリにまたがるときは最後のタスクに \`--repo-output <参照先>=<PR の URL>\` で全部の PR を残す
130
150
  - 置き換えられたタスク(\`p3 ls\` の \`※置換\`、\`--json\` の \`superseded\`)からは始めない。\`move\` が \`warnings\` を返したら止めて人に確かめる
131
151
  - 作業中に新しく必要になった作業は \`p3 new "<タイトル>" --body "..."\` でタスクにする(人への質問はタスクにしない)
132
152
  `;
153
+ }
154
+
155
+ /** 両方に置いたときの節(docs/architecture.md に載せる例。test/agents.test.ts が同じことを確かめる) */
156
+ export const AGENTS_SNIPPET = agentsSnippet(KINDS);
133
157
 
134
158
  /**
135
- * 同梱のスキルの原本と、プロジェクトに置く場所(リポジトリのルートからの相対パス。同じ原本を写す)。
136
- * 置くのはプロジェクトの中だけ(個人のスキルの場所に置くと、p3 を使わないプロジェクトでも読まれる)
159
+ * 同梱のスキルの原本。置くのはプロジェクトの中だけ(個人のスキルの場所に置くと、p3 を使わないプロジェクトでも読まれる)
137
160
  */
138
161
  export const SKILL_SOURCE = fileURLToPath(new URL("../../skills/p3/SKILL.md", import.meta.url));
139
- export const SKILL_TARGETS = [
140
- { path: ".claude/skills/p3/SKILL.md", agent: "Claude Code" },
141
- { path: ".agents/skills/p3/SKILL.md", agent: "Codex" },
142
- ] as const;
162
+
163
+ /** 2つの文の最初に違う行(1 から) */
164
+ function firstDiffLine(a: string, b: string): number {
165
+ const x = a.split("\n");
166
+ const y = b.split("\n");
167
+ let i = 0;
168
+ while (i < x.length && i < y.length && x[i] === y[i]) i++;
169
+ return i + 1;
170
+ }
171
+
172
+ /** 指示の節(見出し「タスク管理(infodb p3)」からその見出しと同じか上の段の次の見出しの前まで。コードの囲みの中は見出しに数えない) */
173
+ function findSections(text: string): { start: number; end: number; level: number }[] {
174
+ const lines = text.split("\n");
175
+ const heads: { line: number; level: number; mark: boolean }[] = [];
176
+ let fence = false;
177
+ lines.forEach((l, i) => {
178
+ if (/^\s*(```|~~~)/.test(l)) fence = !fence;
179
+ const m = fence ? null : /^(#{1,6})\s+(.*?)\s*#*\s*$/.exec(l);
180
+ if (m) heads.push({ line: i, level: m[1].length, mark: m[2] === AGENTS_MARK });
181
+ });
182
+ return heads
183
+ .filter((h) => h.mark)
184
+ .map((h) => ({ start: h.line, level: h.level, end: heads.find((n) => n.line > h.line && n.level <= h.level)?.line ?? lines.length }));
185
+ }
143
186
 
144
187
  /**
145
- * --agents: AGENTS.md(無ければ CLAUDE.md、どちらも無ければ AGENTS.md を作る)に指示を追記し、スキルを置く。
146
- * 指示は見出しがあれば足さない。スキルは置く場所ごとに、無ければ置き、同じ内容なら何もせず、違えば上書きしない
147
- * (手で直したものを消さない。片方が違っても、もう片方は置く)。
188
+ * AI 向けの使い方を置く(init --agents と p3 agents)。kinds の先だけを扱い、ほかの先は作らず・変えず・消さない。
189
+ * - スキル: 無ければ置く・同じなら何もしない・違えば上書きせず違う行と最新にする方法を出す(force なら同梱の版にする)
190
+ * - 指示: AGENTS.md(無ければ CLAUDE.md、どちらも無ければ AGENTS.md を作る)の節。スキルの参照は kinds と既にある先。
191
+ * 節が無ければ足す・同じなら何もしない・違えば変えずに知らせる(force なら節だけを置き換え、前後の文は残す)。
192
+ * 節が複数・見出しの形が分からないときは force でも変えず、手で整理するよう知らせる
148
193
  */
149
- async function placeAgents(root: string, cwd: string): Promise<string[]> {
194
+ export async function placeAgents(root: string, cwd: string, choice: AgentChoice, force = false): Promise<string[]> {
195
+ const kinds: readonly AgentKind[] = AGENT_CHOICES[choice];
150
196
  const lines: string[] = [];
151
- const agentsFile = ["AGENTS.md", "CLAUDE.md"].find((f) => existsSync(join(root, f)));
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
- }
197
+ const update = `p3 agents ${choice} --force`;
159
198
  const source = readFileSync(SKILL_SOURCE, "utf8");
160
- for (const t of SKILL_TARGETS) {
199
+ for (const k of kinds) {
200
+ const t = AGENT_TARGETS[k];
161
201
  const skill = join(root, t.path);
162
- const shown = relative(cwd, skill);
202
+ const shown = relative(cwd, skill) || skill;
163
203
  if (!existsSync(skill)) {
164
204
  await mkdir(dirname(skill), { recursive: true });
165
205
  await copyFile(SKILL_SOURCE, skill);
166
- lines.push(` AI 向けのスキル(${t.agent})を ${shown} に置きました`);
167
- } else if (readFileSync(skill, "utf8") === source) {
168
- lines.push(` AI 向けのスキル(${t.agent})${shown} は最新です`);
206
+ lines.push(` 作成 AI 向けのスキル(${t.agent})を ${shown} に置きました`);
207
+ continue;
208
+ }
209
+ const now = readFileSync(skill, "utf8");
210
+ if (now === source) lines.push(` 同一 AI 向けのスキル(${t.agent})${shown} は最新です`);
211
+ else if (force) {
212
+ await copyFile(SKILL_SOURCE, skill);
213
+ lines.push(` 更新 AI 向けのスキル(${t.agent})${shown} を同梱の版にしました`);
169
214
  } else {
170
- lines.push(` ※ ${shown}(${t.agent})は既にあり、同梱の版と違うので上書きしません。手で見比べて更新してください: ${SKILL_SOURCE}`);
215
+ lines.push(` 保護 ※ ${shown}(${t.agent})は既にあり、同梱の版と違うので上書きしません(${firstDiffLine(now, source)} 行目から違います)。最新にするなら ${update}(原本: ${SKILL_SOURCE})`);
216
+ }
217
+ }
218
+
219
+ // 指示の節のスキルの参照: 置いた先と、既にある先(後から片方を足したとき、もう片方も指す。無い先は書かない)
220
+ const refs = KINDS.filter((k) => kinds.includes(k) || existsSync(join(root, AGENT_TARGETS[k].path)));
221
+ const snippet = agentsSnippet(refs);
222
+ const file = ["AGENTS.md", "CLAUDE.md"].find((f) => existsSync(join(root, f))) ?? "AGENTS.md";
223
+ const target = join(root, file);
224
+ const shown = relative(cwd, target) || target;
225
+ const text = existsSync(target) ? readFileSync(target, "utf8") : "";
226
+ const sections = findSections(text);
227
+ if (!sections.length && !text.includes(AGENTS_MARK)) {
228
+ await appendFile(target, text ? snippet : snippet.replace(/^\n/, ""));
229
+ lines.push(` 作成 AI 向けの使い方を ${shown} に${text ? "追記しました" : "書きました"}`);
230
+ } else if (sections.length !== 1) {
231
+ lines.push(
232
+ ` 保護 ※ ${shown} の「${AGENTS_MARK}」の節が${sections.length ? `${sections.length} つあります` : "見出しとして見つかりません"}。どこまでが p3 の節か決められないので変えません。手で1つの節(見出し「## ${AGENTS_MARK}」)に整理してから、もう一度実行してください`,
233
+ );
234
+ } else {
235
+ const all = text.split("\n");
236
+ const { start, end, level } = sections[0];
237
+ // 見出しの段は今のもの(### などで書かれていればそのまま)
238
+ const body = snippet.replace(/^\n/, "").replace(/^## /, `${"#".repeat(level)} `);
239
+ const current = all.slice(start, end).join("\n");
240
+ if (current.trim() === body.trim()) lines.push(` 同一 AI 向けの使い方(${shown} の節)は最新です`);
241
+ else if (force) {
242
+ const before = all.slice(0, start).join("\n");
243
+ const after = all.slice(end).join("\n");
244
+ await writeFile(target, `${before}${before ? "\n" : ""}${body.trimEnd()}\n${after ? `\n${after.replace(/^\n+/, "")}` : ""}`);
245
+ lines.push(` 更新 AI 向けの使い方(${shown} の「${AGENTS_MARK}」の節)を置き換えました(前後の文はそのまま)`);
246
+ } else {
247
+ lines.push(` 保護 ※ ${shown} の「${AGENTS_MARK}」の節は同梱の版と違うので変えません。最新にするなら ${update}(節だけを置き換えます)`);
171
248
  }
172
249
  }
173
250
  return lines;
@@ -182,7 +259,8 @@ export interface InitOptions {
182
259
  name?: string;
183
260
  description?: string;
184
261
  instructions?: string;
185
- agents?: boolean;
262
+ /** AI 向けの使い方を置く先(未指定なら、対話では聞き(Enter は置かない)、非対話では置かない) */
263
+ agents?: AgentChoice;
186
264
  yes?: boolean;
187
265
  /** このリポジトリの参照先の名前(既定はフォルダ名) */
188
266
  repoName?: string;
@@ -190,79 +268,64 @@ export interface InitOptions {
190
268
  prompt?: (question: string) => Promise<string>;
191
269
  }
192
270
 
271
+ /** 対話の問い(--yes・非対話なら既定値のまま)。使い終えたら close */
272
+ function prompter(o: { yes?: boolean; prompt?: (q: string) => Promise<string> }) {
273
+ const interactive = !o.yes && (!!o.prompt || (process.stdin.isTTY && process.stdout.isTTY));
274
+ const rl = interactive && !o.prompt ? createInterface({ input: process.stdin, output: process.stdout }) : undefined;
275
+ const question = o.prompt ?? (rl ? (q: string) => rl.question(q) : undefined);
276
+ const ask = async (q: string, def: string) => {
277
+ if (!question) return def;
278
+ const a = (await question(`${q}${def ? ` [${def}]` : ""}: `)).trim();
279
+ return a || def;
280
+ };
281
+ return { interactive: !!question, ask, close: () => rl?.close() };
282
+ }
283
+
284
+ /** プロジェクト名とデータのフォルダ(init・join で同じ決め方。未指定はルートの .p3、指定は相対なら実行した場所から・~・絶対) */
285
+ async function projectAndDir(o: { cwd: string; project?: string; dir?: string }, root: string, ask: (q: string, def: string) => Promise<string>, dirQuestion: string) {
286
+ const key = await ask("プロジェクト名(切り替えに使う短い名前)", o.project ?? slugifyName(basename(root)) ?? "project");
287
+ if (!PROJECT_NAME.test(key)) throw new UsageError(`プロジェクト名は英数字と . _ - で: ${key}`);
288
+ // 明示した空のパスは未指定と分けて断る
289
+ if (o.dir !== undefined && !o.dir.trim()) throw new UsageError("--dir が空です。既定(リポジトリのルートの .p3)にするなら --dir を付けずに実行してください");
290
+ const dir = resolvePath(o.cwd, o.dir ?? (await ask(dirQuestion, join(root, DATA_DIR_NAME))));
291
+ return { key, dir };
292
+ }
293
+
294
+ /** --dir の案内(既定の場所なら付けない) */
295
+ const dirHint = (dir: string, root: string) => (dir === join(root, DATA_DIR_NAME) ? "" : ` --dir ${dir}`);
296
+
193
297
  /**
194
- * p3 init。管理したいリポジトリの中で実行する。
298
+ * p3 init。管理したいリポジトリの中で実行し、新しくプロジェクトを作る(作るだけ。既にあるプロジェクトへの参加は p3 join)。
195
299
  * - データを置くフォルダに project.yaml と requests/ を作る。既定はリポジトリのルート(git のメインの作業ツリー。
196
300
  * git 管理外なら実行した場所)の .p3。サブフォルダや追加の作業ツリーから実行してもルートの .p3 にする。
197
301
  * 公開できないデータや、リポジトリと別に管理したいときは --dir でリポジトリの外を指せる
198
- * - 既に作られたフォルダ(他の人が作って共有したもの)を指したら、作らずに参加だけする
199
- * - どちらの場合も個人設定に「プロジェクト名 → フォルダ・手元のリポジトリ」を登録する。以後はリポジトリの中なら指定が要らない
302
+ * - そのフォルダに既に project.yaml があれば、何も書かずに断って p3 join を案内する(--agents を付けても置かない)
303
+ * - 個人設定に「プロジェクト名 → フォルダ・手元のリポジトリ」を登録する。以後はリポジトリの中なら指定が要らない
200
304
  * 端末から実行すると対話式で聞き、--yes か非対話(AI・スクリプト)なら引数と推測した既定値で作る。
201
305
  */
202
306
  export async function init(o: InitOptions): Promise<string> {
203
307
  const root = repoRoot(o.cwd);
204
308
  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
- };
309
+ const { interactive, ask, close } = prompter(o);
214
310
 
215
311
  try {
216
- if (question) console.log(`p3 のプロジェクトを作ります(リポジトリ: ${root})\n(Enter で [ ] 内の既定値)\n`);
217
- const key = await ask("プロジェクト名(切り替えに使う短い名前)", o.project ?? slugifyName(basename(root)) ?? "project");
218
- if (!PROJECT_NAME.test(key)) throw new UsageError(`プロジェクト名は英数字と . _ - で: ${key}`);
219
- // 未指定ならルートの .p3(既定値は絶対パスで見せる)。指定したパス(相対は実行した場所から)はそのまま使い、外にも置ける。
220
- // 明示した空のパスは未指定と分けて断る
221
- if (o.dir !== undefined && !o.dir.trim()) throw new UsageError("--dir が空です。既定(リポジトリのルートの .p3)にするなら --dir を付けずに実行してください");
222
- const dir = resolvePath(o.cwd, o.dir ?? (await ask("データを置くフォルダ(相対パスは今いる場所から。リポジトリの外も指定できます)", join(root, DATA_DIR_NAME))));
223
-
312
+ if (interactive) console.log(`p3 のプロジェクトを作ります(リポジトリ: ${root})\n(Enter で [ ] 内の既定値)\n`);
313
+ const { key, dir } = await projectAndDir(o, root, ask, "データを置くフォルダ(相対パスは今いる場所から。リポジトリの外も指定できます)");
314
+
315
+ // 既にあるプロジェクト: 作らず、何も書かない(参加は join、AI 向けの使い方は agents)
316
+ if (existsSync(join(dir, "project.yaml"))) {
317
+ throw new UsageError(
318
+ [
319
+ `${dir} には既にプロジェクトがあります(init は新しく作るだけです。何も変えていません)`,
320
+ ` 参加するなら: p3 join --project ${key}${dirHint(dir, root)}`,
321
+ ...(o.agents ? [" AI 向けの使い方を置く・最新にするなら: p3 agents claude|codex|both"] : []),
322
+ ].join("\n"),
323
+ );
324
+ }
224
325
  const registered = user.projects[key];
225
326
  if (registered && registered.dir !== dir) throw new UsageError(`プロジェクト名「${key}」は別のフォルダで登録済みです: ${registered.dir}`);
226
- // このリポジトリを参照先として登録する名前(新しく作るときは本体として共有の定義も書く。参加するときは同じ名前の参照先か、
227
- // 参照先が1つならそれ。決まらなければ登録せず p3 repo path を案内する)
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
- }
327
+ const refName = o.repoName ?? slugifyName(basename(root)) ?? "app";
328
+ if (repoNameProblem(refName)) throw new UsageError(`参照先の名前: ${repoNameProblem(refName)}(--repo-name で指定してください)`);
266
329
 
267
330
  // 既定値: git とリポジトリの中身から推測する
268
331
  const docsFound = DOC_CANDIDATES.filter((d) => existsSync(join(root, d)));
@@ -276,23 +339,31 @@ export async function init(o: InitOptions): Promise<string> {
276
339
  return { path: d, role: "ドキュメント", ...(entry ? { entry } : {}) };
277
340
  });
278
341
  const instructions = await ask("Preflight で重視する観点・制約(任意)", o.instructions ?? "");
279
- const addAgents = await askAgents();
342
+ // 既にある AGENTS.md / CLAUDE.md からは推測しない(Enter は置かない)
343
+ let agents = o.agents;
344
+ if (agents === undefined && interactive) {
345
+ const a = await ask("AI 向けの p3 の使い方(スキルと AGENTS.md / CLAUDE.md の節)を置く先(置かない / claude / codex / both)", "置かない");
346
+ if (!["置かない", "none", "n", "no"].includes(a)) {
347
+ if (!isAgentChoice(a)) throw new UsageError(`置く先は 置かない / claude / codex / both のどれか: ${a}`);
348
+ agents = a;
349
+ }
350
+ }
280
351
 
281
352
  const cfg: ProjectConfig = {
282
353
  name,
283
354
  description,
284
355
  // このリポジトリを本体の参照先にする(このマシンのパスは個人設定に持ち、共有するデータには書かない)
285
- repos: [{ name: refName!, role: "本体", readFirst: true, writable: true, map }],
356
+ repos: [{ name: refName, role: "本体", readFirst: true, writable: true, map }],
286
357
  milestones: [],
287
358
  branchPattern: "req/{id}-{slug}",
288
359
  preflight: { instructions },
289
360
  };
290
361
  await mkdir(join(dir, "requests"), { recursive: true });
291
362
  await writeProjectFile(join(dir, "project.yaml"), cfg);
292
- await writeRepoEntry(join(dir, "project.yaml"), refName!, cfg.repos[0]);
293
- await register();
363
+ await writeRepoEntry(join(dir, "project.yaml"), refName, cfg.repos[0]);
364
+ await register(key, dir, refName, root);
294
365
 
295
- const agentLines = addAgents ? await placeAgents(root, o.cwd) : [];
366
+ const agentLines = agents ? await placeAgents(root, o.cwd, agents) : [];
296
367
  return [
297
368
  `作りました: ${key} → ${dir}`,
298
369
  ` 参照先 ${refName}(本体) → ${root}`,
@@ -307,7 +378,103 @@ export async function init(o: InitOptions): Promise<string> {
307
378
  .join("\n")
308
379
  .trimEnd();
309
380
  } finally {
310
- rl?.close();
381
+ close();
382
+ }
383
+ }
384
+
385
+ /** 最新の個人設定の上で、このプロジェクトの登録だけを書く(聞いている間にほかで変わっていても、ほかの登録・項目は消さない) */
386
+ function register(key: string, dir: string, refName: string | undefined, root: string) {
387
+ return updateUserConfig((doc, now) => {
388
+ const prev = now.projects[key];
389
+ if (prev && prev.dir !== dir) throw new UsageError(`プロジェクト名「${key}」は別のフォルダで登録済みです: ${prev.dir}`);
390
+ setProjectNode(doc, key, { dir, repos: refName ? { ...prev?.repos, [refName]: root } : (prev?.repos ?? {}) });
391
+ });
392
+ }
393
+
394
+ /** 参加する前に、データのフォルダが読める p3 のプロジェクトかを確かめ、共有の定義(読むだけ)を返す */
395
+ async function readSharedProject(dir: string): Promise<ProjectConfig> {
396
+ const create = "新しく作るなら p3 init";
397
+ const st = await stat(dir).catch((e: NodeJS.ErrnoException) => e);
398
+ if (st instanceof Error) {
399
+ throw new UsageError(
400
+ st.code === "ENOENT"
401
+ ? `データのフォルダがありません: ${dir}(パスと、共有のフォルダがつながっているかを確かめてください。${create})`
402
+ : `データのフォルダを読めません: ${dir}(${st.code ?? st.message})`,
403
+ );
404
+ }
405
+ if (!st.isDirectory()) throw new UsageError(`データのフォルダがフォルダではありません: ${dir}`);
406
+ const file = join(dir, "project.yaml");
407
+ let text: string;
408
+ try {
409
+ text = await readFile(file, "utf8");
410
+ } catch (e) {
411
+ const code = (e as NodeJS.ErrnoException).code;
412
+ throw new UsageError(
413
+ code === "ENOENT"
414
+ ? `${dir} は p3 のプロジェクトではありません(project.yaml がありません)。指したフォルダと中身を確かめてください(参加では作りません。${create})`
415
+ : `project.yaml を読めません: ${file}(${code ?? (e as Error).message})`,
416
+ );
417
+ }
418
+ let data: unknown;
419
+ try {
420
+ data = YAML.parse(text);
421
+ } catch (e) {
422
+ throw new UsageError(`project.yaml を読めません(YAML として壊れています): ${file}: ${(e as Error).message.split("\n")[0]}`);
423
+ }
424
+ if (!data || typeof data !== "object" || Array.isArray(data)) throw new UsageError(`project.yaml の中身が p3 の設定ではありません: ${file}`);
425
+ return normalizeProject(data as Record<string, unknown>);
426
+ }
427
+
428
+ export interface JoinOptions {
429
+ cwd: string;
430
+ project?: string;
431
+ dir?: string;
432
+ repoName?: string;
433
+ yes?: boolean;
434
+ prompt?: (question: string) => Promise<string>;
435
+ }
436
+
437
+ /**
438
+ * p3 join。既にあるプロジェクト(ほかの人が作って共有したデータのフォルダ)に参加する。個人設定に
439
+ * 「プロジェクト名 → フォルダ・このリポジトリのこのマシンのパス」を登録するだけで、共有の定義・データ・
440
+ * AI 向けのファイル(スキル・AGENTS.md / CLAUDE.md)は書かない。データのフォルダの既定と指定の仕方は init と同じ。
441
+ * - このリポジトリを登録する参照先: --repo-name(共有の定義にある名前)→ フォルダ名と同じ名前 → 参照先が1つならそれ。
442
+ * 決まらなければ登録せず p3 repo path を案内する
443
+ * - 同じ名前で別のフォルダは断る。同じ名前・同じフォルダ・同じパスなら何もしない(成功)
444
+ */
445
+ export async function joinProject(o: JoinOptions): Promise<string> {
446
+ const root = repoRoot(o.cwd);
447
+ const { interactive, ask, close } = prompter(o);
448
+ try {
449
+ if (interactive) console.log(`p3 のプロジェクトに参加します(リポジトリ: ${root})\n(Enter で [ ] 内の既定値)\n`);
450
+ const { key, dir } = await projectAndDir(o, root, ask, "参加するデータのフォルダ(相対パスは今いる場所から)");
451
+ const shared = (await readSharedProject(dir)).repos;
452
+ let refName: string | undefined;
453
+ if (o.repoName !== undefined) {
454
+ if (!shared.some((r) => r.name === o.repoName)) {
455
+ throw new UsageError(`参照先「${o.repoName}」は共有の定義にありません(あるもの: ${shared.map((r) => r.name).join(", ") || "なし"})`);
456
+ }
457
+ refName = o.repoName;
458
+ } else {
459
+ const derived = slugifyName(basename(root));
460
+ refName = (shared.find((r) => r.name === derived) ?? (shared.length === 1 ? shared[0] : undefined))?.name;
461
+ }
462
+ const user = await loadUserConfig();
463
+ const prev = user.projects[key];
464
+ if (prev && prev.dir !== dir) throw new UsageError(`プロジェクト名「${key}」は別のフォルダで登録済みです: ${prev.dir}`);
465
+ if (prev && (!refName || prev.repos[refName] === root)) return `登録済みです: ${key} → ${dir}(変えていません)`;
466
+ await register(key, dir, refName, root);
467
+ return [
468
+ `参加しました: ${key} → ${dir}`,
469
+ refName
470
+ ? ` 参照先 ${refName} ${root}`
471
+ : ` このリポジトリを参照先として登録していません。p3 repo ls で名前を確かめ、p3 repo path <名前> ${root} で登録してください`,
472
+ ` 個人設定 ${userConfigPath()} に登録しました(データ・リポジトリのファイルは変えていません)`,
473
+ "",
474
+ "次に: p3 request ls / p3 serve",
475
+ ].join("\n");
476
+ } finally {
477
+ close();
311
478
  }
312
479
  }
313
480
 
@@ -327,7 +494,7 @@ export async function projectCommand(
327
494
  data: rows,
328
495
  text: rows.length
329
496
  ? 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 <名前> --dir <フォルダ>",
497
+ : "登録済みのプロジェクトはありません。管理したいリポジトリの中で p3 init --project <名前>(新しく作る)か p3 join --project <名前>(参加する)",
331
498
  };
332
499
  }
333
500
  if (sub === "add") {
@@ -390,7 +557,7 @@ export async function config(ws: Workspace, args: string[]): Promise<{ data: unk
390
557
  `name ${p.name}`,
391
558
  `description ${p.description || "(なし)"}`,
392
559
  `repos ${p.repos.map((r) => r.name).join(", ") || "(なし)"} (p3 repo ls)`,
393
- `milestones ${p.milestones.map((m) => `${m.id}${m.due ? `(${m.due})` : ""}${m.done ? "[済]" : ""}`).join(", ") || "(なし)"}`,
560
+ `milestones ${sortMilestones(p.milestones).map((m) => `${m.id}${m.due ? `(${m.due})` : ""}${m.done ? "[済]" : ""}`).join(", ") || "(なし)"}`,
394
561
  `branchPattern ${p.branchPattern}`,
395
562
  `instructions ${p.preflight.instructions || "(なし)"}`,
396
563
  "",
@@ -1,10 +1,13 @@
1
1
  import { readFile } from "node:fs/promises";
2
2
  import { resolve as resolvePath } from "node:path";
3
- import type { ReleaseGeneration, ReleaseMaterial, ReleaseWarning } from "../shared/types.ts";
3
+ import type { ReleaseGeneration, ReleaseMaterial, ReleaseWarning, RequestCompletionPlan } from "../shared/types.ts";
4
4
  import { exportReleaseNote, releaseNoteDetail, releaseOverview, saveReleaseNote, startGeneration } from "../core/releaseNotes/service.ts";
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";
10
+ import { completeMilestoneRequests, CompletionRejected } from "../core/releaseNotes/completeRequests.ts";
8
11
 
9
12
  /**
10
13
  * p3 release-notes ... マイルストーンごとのリリースノート(規則と保存は core/releaseNotes)
@@ -14,6 +17,7 @@ import { UsageError } from "./project.ts";
14
17
  * generate <id> 機能の要約を生成して案を出す(保存しない。進み具合は stderr)
15
18
  * save <id> 本文を保存する(--body 本文|- か --file。更新は --version 必須)
16
19
  * export <id> 保存した本文だけを stdout に出す
20
+ * complete-requests <id> --based-on <hash> 対応済の要望を一括で完了済にする(判定と hash は show。頼めない・途中で止まったら非ゼロ)
17
21
  */
18
22
  export async function releaseNotesCommand(env: CommandEnv): Promise<number> {
19
23
  const { ctx, out, args, o, actor } = env;
@@ -42,7 +46,7 @@ export async function releaseNotesCommand(env: CommandEnv): Promise<number> {
42
46
  const d = await releaseNoteDetail(ctx, need());
43
47
  return out.result(d, () => {
44
48
  const lines = [`${d.material.milestone.id} ${d.material.milestone.title}${d.material.milestone.done ? "(リリース済み)" : ""}`, ""];
45
- lines.push(...materialLines(d.material), "");
49
+ lines.push(...materialLines(d.material), "", ...completionLines(d.completion), "");
46
50
  if (d.noteError) lines.push(`ノート: 読めません(${d.noteError})`, " 直すまで新しく保存できません。frontmatter を直すか、本文を退避してファイルを消してください");
47
51
  else if (!d.note) lines.push("ノート: まだありません(p3 release-notes generate → save)");
48
52
  else {
@@ -56,7 +60,12 @@ export async function releaseNotesCommand(env: CommandEnv): Promise<number> {
56
60
 
57
61
  case "generate": {
58
62
  if (o.engine !== undefined && o.engine !== "codex" && o.engine !== "mock") throw new UsageError("--engine は codex か mock");
59
- const g = await startGeneration(ctx, need(), actor, o.engine);
63
+ const id = need();
64
+ const g = await startGeneration(ctx, id, actor, o.engine).catch((e: Error) => {
65
+ // 始められなければ手で書く道を添える(実行中は別の理由なので添えない。終了コードは変えない)
66
+ if (e instanceof GenerationRejected && e.code !== "running") e.message += `\n${manualSaveHint(id)}`;
67
+ throw e;
68
+ });
60
69
  const gen = ctx.releaseGenerator;
61
70
  // 進み具合は stderr(stdout は本文の案か JSON だけにする)
62
71
  let shown = 0;
@@ -71,6 +80,8 @@ export async function releaseNotesCommand(env: CommandEnv): Promise<number> {
71
80
  if (done.status !== "completed") {
72
81
  if (out.json) out.result(done, () => "");
73
82
  else process.stderr.write(`${failureLine(done)}\n`);
83
+ // 失敗したら手で書く道を stderr に出す(--json の stdout は変えない。取消は失敗と扱わない)
84
+ if (done.status === "failed") process.stderr.write(`${manualSaveHint(done.milestone)}\n`);
74
85
  return 1;
75
86
  }
76
87
  if (!out.json) {
@@ -95,8 +106,30 @@ export async function releaseNotesCommand(env: CommandEnv): Promise<number> {
95
106
  return 0;
96
107
  }
97
108
 
109
+ case "complete-requests": {
110
+ const id = need();
111
+ const basedOn = o["based-on"];
112
+ if (!basedOn) throw new UsageError(`判定を確かめた材料の hash を --based-on で指定してください(p3 release-notes show ${shellArg(id)} --json の completion.basedOn)`);
113
+ try {
114
+ const r = await completeMilestoneRequests(ctx, id, basedOn, actor);
115
+ out.result(r, () =>
116
+ [
117
+ r.completed.length ? `完了済にしました(${r.completed.length} 件):` : r.failed ? "完了済にした要望はありません" : "完了済にする要望はありません(変えていません)",
118
+ ...r.completed.map((t) => ` ${t.id} ${t.title}`),
119
+ ...(r.failed ? [`止まりました: ${r.failed.id}(${r.failed.reason})`, ...(r.notRun.length ? [`まだ変えていません: ${r.notRun.join(", ")}`] : []), `やり直すには show で読み直してから、表示された --based-on で実行してください`] : []),
120
+ ].join("\n"),
121
+ );
122
+ return r.failed ? (r.failed.code === "error" ? 1 : 3) : 0;
123
+ } catch (e) {
124
+ if (!(e instanceof CompletionRejected)) throw e;
125
+ if (out.json) out.result({ error: e.message, code: e.code, plan: e.plan }, () => "");
126
+ else process.stderr.write(`${[e.message, ...completionLines(e.plan)].join("\n")}\n`);
127
+ return e.code === "material_changed" ? 3 : 1;
128
+ }
129
+ }
130
+
98
131
  default:
99
- throw new UsageError("p3 release-notes [ls | show <id> | generate <id> | save <id> | export <id>]");
132
+ throw new UsageError("p3 release-notes [ls | show <id> | generate <id> | save <id> | export <id> | complete-requests <id> --based-on <hash>]");
100
133
  }
101
134
  }
102
135
 
@@ -118,11 +151,37 @@ function materialLines(m: ReleaseMaterial): string[] {
118
151
  ];
119
152
  }
120
153
 
154
+ /** 要望を一括で完了済にできるか(show と、頼めなかったとき) */
155
+ function completionLines(p: RequestCompletionPlan): string[] {
156
+ const head = !p.ready
157
+ ? "要望の一括完了: できません(見送り以外の全要望が、全タスク完了の対応済か完了済になってから)"
158
+ : p.targets.length
159
+ ? `要望の一括完了: 対応済 ${p.targets.length} 件を完了済にできます(タスクの済みは変えません)`
160
+ : "要望の一括完了: 完了済にする要望はありません";
161
+ return [
162
+ head,
163
+ ...p.blockers.map((b) => ` ✕ ${b.target}: ${b.reason}`),
164
+ ...p.targets.map((t) => ` → ${t.id} ${t.title}`),
165
+ ...(p.ready && p.targets.length ? [` 実行: p3 release-notes complete-requests ${shellArg(p.milestone)} --based-on ${p.basedOn}`] : []),
166
+ ];
167
+ }
168
+
121
169
  function flushLog(g: ReleaseGeneration, from: number): number {
122
170
  for (const e of g.log.slice(from)) process.stderr.write(`[${e.kind}] ${e.text}\n`);
123
171
  return g.log.length;
124
172
  }
125
173
 
174
+ /** 要約を生成できないときの、本文を手で書いて保存する道(Codex・Docker・ChatGPT は要らない) */
175
+ function manualSaveHint(mid: string): string {
176
+ const m = shellArg(mid);
177
+ return [
178
+ "生成せずに、本文を手で書いて保存できます(Docker や ChatGPT の接続は要りません):",
179
+ ` p3 release-notes show ${m} # 材料(収録する要望と変更の記録)を確かめる`,
180
+ ` p3 release-notes save ${m} --file <本文.md> # 新しく保存する`,
181
+ ` 既にノートがあるときは、show で読んだ版を付けて更新します: p3 release-notes save ${m} --file <本文.md> --version <版>`,
182
+ ].join("\n");
183
+ }
184
+
126
185
  function failureLine(g: ReleaseGeneration): string {
127
186
  if (g.status === "cancelled") return "取り消しました(保存したノートは変えていません)";
128
187
  return `生成できませんでした(${g.failure}): ${g.error}(保存したノートは変えていません)`;