@infodb/p3 0.4.0 → 0.6.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 (209) hide show
  1. package/README.md +1 -0
  2. package/bin/p3.mjs +11 -5
  3. package/dist/web/assets/Outputs-CQi0oba1.js +1 -0
  4. package/dist/web/assets/RequestStatus-grC0F_SQ.js +1 -0
  5. package/dist/web/assets/Tabs-BJRGzidj.js +1 -0
  6. package/dist/web/assets/TagInput-DkuISbfK.js +1 -0
  7. package/dist/web/assets/TaskDrawer-CysOMAjG.js +3 -0
  8. package/dist/web/assets/_requestId-BQCwOAbs.js +30 -0
  9. package/dist/web/assets/_requestId-DgSOUH78.js +1 -0
  10. package/dist/web/assets/{ui-DdOGYj9z.js → appCtx-DCiGJFAe.js} +1 -1
  11. package/dist/web/assets/board-BsntpZXP.js +1 -0
  12. package/dist/web/assets/done-Bhxqy7bH.js +1 -0
  13. package/dist/web/assets/index-BF1xMdJo.css +2 -0
  14. package/dist/web/assets/index-BTuEPzgc.js +12 -0
  15. package/dist/web/assets/new-BwknRX3V.js +1 -0
  16. package/dist/web/assets/{preflightInput-DMxqnvF8.js → preflightInput-BAeEJYUK.js} +1 -1
  17. package/dist/web/assets/preload-helper-B40dBmwL.js +1 -0
  18. package/dist/web/assets/progressTree-DgrdDFih.js +1 -0
  19. package/dist/web/assets/release-notes-AgwbykyG.js +3 -0
  20. package/dist/web/assets/requestData-w6fhCYmh.js +1 -0
  21. package/dist/web/assets/routes-Bu3bhOaC.js +3 -0
  22. package/dist/web/assets/settings-BkV8KeQk.js +1 -0
  23. package/dist/web/index.html +4 -4
  24. package/docs/architecture.md +271 -3
  25. package/docs/development.md +22 -9
  26. package/docs/how-to-use.md +83 -7
  27. package/docs/installation.md +8 -6
  28. package/docs/publishing.md +4 -2
  29. package/lib/cli/args.js +172 -0
  30. package/lib/cli/chatgpt.js +70 -0
  31. package/lib/cli/codex.js +30 -0
  32. package/lib/cli/format.js +9 -0
  33. package/{src/cli/help.ts → lib/cli/help.js} +10 -8
  34. package/lib/cli/main.js +327 -0
  35. package/lib/cli/output.js +110 -0
  36. package/lib/cli/preflightCommands.js +301 -0
  37. package/lib/cli/project.js +649 -0
  38. package/lib/cli/readOnly.js +36 -0
  39. package/lib/cli/releaseNotesCommands.js +197 -0
  40. package/lib/cli/render.js +58 -0
  41. package/lib/cli/requestCommands.js +191 -0
  42. package/lib/cli/showView.js +100 -0
  43. package/lib/cli/taskCommands.js +152 -0
  44. package/lib/cli/userConfig.js +64 -0
  45. package/{src/core/chatgpt.ts → lib/core/chatgpt.js} +10 -16
  46. package/lib/core/context.js +41 -0
  47. package/lib/core/hierarchy.js +158 -0
  48. package/lib/core/machineSettings.js +146 -0
  49. package/lib/core/machineSettingsEdit.js +148 -0
  50. package/lib/core/ops.js +120 -0
  51. package/lib/core/preflight/carryover.js +105 -0
  52. package/lib/core/preflight/codexEngine.js +687 -0
  53. package/lib/core/preflight/codexImage.js +61 -0
  54. package/lib/core/preflight/diagnose.js +95 -0
  55. package/lib/core/preflight/engine.js +58 -0
  56. package/lib/core/preflight/input.js +83 -0
  57. package/lib/core/preflight/launch.js +68 -0
  58. package/lib/core/preflight/mockEngine.js +175 -0
  59. package/lib/core/preflight/render.js +304 -0
  60. package/lib/core/preflight/service.js +883 -0
  61. package/lib/core/preflight/split.js +83 -0
  62. package/lib/core/preflight/uiMaterials.js +281 -0
  63. package/lib/core/preflight/uiRender.js +89 -0
  64. package/lib/core/preflight/wireframe.js +63 -0
  65. package/lib/core/preflight/xlsx.js +324 -0
  66. package/lib/core/projectRegistry.js +207 -0
  67. package/lib/core/redact.js +28 -0
  68. package/lib/core/releaseNotes/completeRequests.js +106 -0
  69. package/lib/core/releaseNotes/generate.js +266 -0
  70. package/lib/core/releaseNotes/material.js +141 -0
  71. package/lib/core/releaseNotes/mockSummarizer.js +26 -0
  72. package/lib/core/releaseNotes/service.js +83 -0
  73. package/lib/core/releaseNotes/store.js +209 -0
  74. package/lib/core/repoAdmin.js +82 -0
  75. package/lib/core/repoRefs.js +72 -0
  76. package/lib/core/requestOps.js +164 -0
  77. package/lib/core/requestStatus.js +171 -0
  78. package/lib/core/store/attachments.js +242 -0
  79. package/lib/core/store/collection.js +254 -0
  80. package/lib/core/store/frontmatter.js +18 -0
  81. package/lib/core/store/fsutil.js +84 -0
  82. package/lib/core/store/locate.js +162 -0
  83. package/lib/core/store/normalize.js +152 -0
  84. package/lib/core/store/noteStore.js +59 -0
  85. package/lib/core/store/preflightStore.js +161 -0
  86. package/lib/core/store/projectFile.js +99 -0
  87. package/lib/core/store/workspace.js +320 -0
  88. package/lib/core/supersede.js +69 -0
  89. package/lib/core/userConfig.js +158 -0
  90. package/{src/core/userTheme.ts → lib/core/userTheme.js} +11 -13
  91. package/lib/core/workTargets.js +106 -0
  92. package/lib/server/api/chatgptRoutes.js +46 -0
  93. package/{src/server/api/local.ts → lib/server/api/local.js} +23 -22
  94. package/lib/server/api/manifest.js +147 -0
  95. package/lib/server/api/projectsRoutes.js +82 -0
  96. package/lib/server/api/releaseNoteRoutes.js +88 -0
  97. package/lib/server/api/repoRoutes.js +67 -0
  98. package/lib/server/api/routes.js +416 -0
  99. package/lib/server/api/userThemeRoutes.js +60 -0
  100. package/lib/server/server.js +85 -0
  101. package/lib/shared/dates.js +10 -0
  102. package/{src/shared/directTask.ts → lib/shared/directTask.js} +3 -11
  103. package/lib/shared/hierarchy.js +135 -0
  104. package/lib/shared/milestoneOrder.js +45 -0
  105. package/lib/shared/preflightInput.js +19 -0
  106. package/lib/shared/refs.js +44 -0
  107. package/lib/shared/repos.js +69 -0
  108. package/lib/shared/scopeView.js +39 -0
  109. package/{src/shared/tags.ts → lib/shared/tags.js} +9 -14
  110. package/lib/shared/types.js +74 -0
  111. package/lib/shared/workTarget.js +31 -0
  112. package/package.json +4 -7
  113. package/skills/p3/SKILL.md +10 -0
  114. package/dist/web/assets/Outputs-5Hby-S5Q.js +0 -1
  115. package/dist/web/assets/RequestStatus-CTkGjT02.js +0 -1
  116. package/dist/web/assets/TagInput-Rj3PNOAF.js +0 -1
  117. package/dist/web/assets/TaskDrawer-DtPhiYxP.js +0 -3
  118. package/dist/web/assets/_requestId-CGvAfIkB.js +0 -30
  119. package/dist/web/assets/_requestId-DxfYhgAq.js +0 -1
  120. package/dist/web/assets/board-wt47lfrE.js +0 -1
  121. package/dist/web/assets/done-C9Ct7ssb.js +0 -1
  122. package/dist/web/assets/index-BTFL2rpp.js +0 -12
  123. package/dist/web/assets/index-DAyBsvua.css +0 -2
  124. package/dist/web/assets/new-e4ID2vQV.js +0 -1
  125. package/dist/web/assets/preload-helper-DhIyFaOW.js +0 -1
  126. package/dist/web/assets/release-notes-CQ0d2r0k.js +0 -3
  127. package/dist/web/assets/requestData-BDZqyl35.js +0 -1
  128. package/dist/web/assets/routes-Bipv3lwJ.js +0 -2
  129. package/dist/web/assets/settings-Dwh8fj6p.js +0 -1
  130. package/src/cli/args.ts +0 -186
  131. package/src/cli/chatgpt.ts +0 -74
  132. package/src/cli/codex.ts +0 -28
  133. package/src/cli/format.ts +0 -9
  134. package/src/cli/main.ts +0 -337
  135. package/src/cli/output.ts +0 -117
  136. package/src/cli/preflightCommands.ts +0 -245
  137. package/src/cli/project.ts +0 -675
  138. package/src/cli/readOnly.ts +0 -36
  139. package/src/cli/releaseNotesCommands.ts +0 -198
  140. package/src/cli/render.ts +0 -60
  141. package/src/cli/requestCommands.ts +0 -172
  142. package/src/cli/showView.ts +0 -110
  143. package/src/cli/taskCommands.ts +0 -167
  144. package/src/cli/userConfig.ts +0 -58
  145. package/src/core/context.ts +0 -58
  146. package/src/core/machineSettings.ts +0 -207
  147. package/src/core/machineSettingsEdit.ts +0 -156
  148. package/src/core/ops.ts +0 -114
  149. package/src/core/preflight/carryover.ts +0 -133
  150. package/src/core/preflight/codexEngine.ts +0 -703
  151. package/src/core/preflight/codexImage.ts +0 -98
  152. package/src/core/preflight/diagnose.ts +0 -124
  153. package/src/core/preflight/engine.ts +0 -92
  154. package/src/core/preflight/input.ts +0 -65
  155. package/src/core/preflight/launch.ts +0 -86
  156. package/src/core/preflight/mockEngine.ts +0 -145
  157. package/src/core/preflight/render.ts +0 -339
  158. package/src/core/preflight/service.ts +0 -707
  159. package/src/core/preflight/uiMaterials.ts +0 -272
  160. package/src/core/preflight/uiRender.ts +0 -84
  161. package/src/core/preflight/wireframe.ts +0 -69
  162. package/src/core/preflight/xlsx.ts +0 -328
  163. package/src/core/projectRegistry.ts +0 -264
  164. package/src/core/redact.ts +0 -31
  165. package/src/core/releaseNotes/completeRequests.ts +0 -102
  166. package/src/core/releaseNotes/generate.ts +0 -283
  167. package/src/core/releaseNotes/material.ts +0 -114
  168. package/src/core/releaseNotes/mockSummarizer.ts +0 -28
  169. package/src/core/releaseNotes/service.ts +0 -110
  170. package/src/core/releaseNotes/store.ts +0 -216
  171. package/src/core/repoAdmin.ts +0 -81
  172. package/src/core/repoRefs.ts +0 -90
  173. package/src/core/requestOps.ts +0 -140
  174. package/src/core/requestStatus.ts +0 -58
  175. package/src/core/store/attachments.ts +0 -228
  176. package/src/core/store/collection.ts +0 -282
  177. package/src/core/store/frontmatter.ts +0 -22
  178. package/src/core/store/fsutil.ts +0 -90
  179. package/src/core/store/locate.ts +0 -181
  180. package/src/core/store/normalize.ts +0 -155
  181. package/src/core/store/noteStore.ts +0 -56
  182. package/src/core/store/preflightStore.ts +0 -136
  183. package/src/core/store/projectFile.ts +0 -101
  184. package/src/core/store/workspace.ts +0 -328
  185. package/src/core/supersede.ts +0 -74
  186. package/src/core/userConfig.ts +0 -205
  187. package/src/core/workTargets.ts +0 -120
  188. package/src/server/api/chatgptRoutes.ts +0 -49
  189. package/src/server/api/manifest.ts +0 -135
  190. package/src/server/api/projectsRoutes.ts +0 -89
  191. package/src/server/api/releaseNoteRoutes.ts +0 -89
  192. package/src/server/api/repoRoutes.ts +0 -67
  193. package/src/server/api/routes.ts +0 -382
  194. package/src/server/api/userThemeRoutes.ts +0 -62
  195. package/src/server/server.ts +0 -108
  196. package/src/shared/dates.ts +0 -12
  197. package/src/shared/milestoneOrder.ts +0 -44
  198. package/src/shared/preflightInput.ts +0 -27
  199. package/src/shared/refs.ts +0 -55
  200. package/src/shared/repos.ts +0 -113
  201. package/src/shared/scopeView.ts +0 -48
  202. package/src/shared/types.ts +0 -730
  203. package/src/shared/workTarget.ts +0 -44
  204. /package/{src → lib}/core/preflight/launcher.mjs +0 -0
  205. /package/{src → lib}/core/preflight/mock-ui.html +0 -0
  206. /package/{src → lib}/core/preflight/mock-ui.png +0 -0
  207. /package/{src → lib}/core/preflight/render-image/Dockerfile +0 -0
  208. /package/{src → lib}/core/preflight/render-image/fonts-ja.conf +0 -0
  209. /package/{src → lib}/core/preflight/render-image/render.mjs +0 -0
@@ -0,0 +1,301 @@
1
+ import { readFile, writeFile } from "node:fs/promises";
2
+ import { basename, join, relative, resolve as resolvePath } from "node:path";
3
+ import { AttachmentError, safeFileName } from "../core/store/attachments.js";
4
+ import { UI_MATERIAL_KINDS, ATTACHMENT_FORMATS } from "../shared/types.js";
5
+ import {} from "../core/context.js";
6
+ import { NotFoundError } from "../core/store/collection.js";
7
+ import { table } from "./format.js";
8
+ import { evidenceLines, scopeLines } from "../shared/scopeView.js";
9
+ import { UsageError } from "./project.js";
10
+ import { StaleInputError, staleMessage } from "../core/preflight/input.js";
11
+ import { changedLabel, isMaterialized } from "../shared/preflightInput.js";
12
+ import { readBody } from "./args.js";
13
+ import { deps, directTaskHint, indent } from "./output.js";
14
+ import { PreflightBusyError } from "../core/preflight/service.js";
15
+ import { preflightFailed } from "../shared/directTask.js";
16
+ /** Preflight のコマンド(preflight / attach / notes / drafts / accept)。扱わないコマンドは undefined */
17
+ export async function preflightCommand(cmd, env) {
18
+ const { ctx, out, args, o, actor, requestArg, cwd } = env;
19
+ switch (cmd) {
20
+ // --- Preflight ----------------------------------------------------------
21
+ case "preflight": {
22
+ const rid = requestArg(args[0]);
23
+ const engine = o.engine;
24
+ if (o["note-only"] && o.note === undefined)
25
+ throw new UsageError("--note-only には --note でメモを渡してください");
26
+ if (o["note-only"] && engine)
27
+ throw new UsageError("--note-only は実行しないので --engine は使えません");
28
+ const note = o.note === undefined ? undefined : await ctx.preflight.addNote(rid, readBody(o.note), actor);
29
+ if (o["note-only"])
30
+ return out.result(note, () => `メモ ${note.id} を書き足しました(次の Preflight に渡します)`);
31
+ if (note && !out.json)
32
+ process.stderr.write(`メモ ${note.id} を書き足しました\n`);
33
+ const off = ctx.ws.on((e) => {
34
+ if (e.type === "preflight-log" && !out.json)
35
+ process.stderr.write(`${e.entry.at.slice(11, 19)} ${e.entry.text}\n`);
36
+ });
37
+ const hint = () => directTaskHint(rid, { project: o.project, dir: o.dir });
38
+ const started = await ctx.preflight.start(rid, { engine, actor }).catch((e) => {
39
+ off();
40
+ // メモは残っているので、書き直さずに p3 preflight だけで再実行できる
41
+ const err = note ? new Error(`${e.message}(メモ ${note.id} は保存済みです。p3 preflight ${rid} で再実行できます)`) : e;
42
+ // 始められなかったら直接作る道を添える(実行中・要望が無いときは別の理由なので添えない。終了コードは変えない)
43
+ if (!(e instanceof PreflightBusyError) && !(e instanceof NotFoundError))
44
+ err.message += `\n${hint()}`;
45
+ throw err;
46
+ });
47
+ if (!out.json)
48
+ process.stderr.write(`preflight ${started.id} (${started.engine})\n`);
49
+ const run = await ctx.preflight.wait(rid, started.id);
50
+ off();
51
+ if (!run)
52
+ throw new Error("preflight の結果が読めません");
53
+ out.result(run, () => formatRun(ctx, rid, run));
54
+ // 失敗したら直接作る道を stderr に出す(--json の stdout は変えない。取消は失敗と扱わない)
55
+ if (preflightFailed(run))
56
+ process.stderr.write(`${hint()}\n`);
57
+ return run.status === "completed" ? 0 : 1;
58
+ }
59
+ case "attach": {
60
+ // 要望は --req(か今の要望)。serve なしでファイルを直接扱う(API と同じ確かめ方)
61
+ const rid = requestArg(undefined);
62
+ const [sub = "ls", target] = args;
63
+ const fmt = (a) => [a.id, ATTACHMENT_FORMATS[a.format], `${Math.ceil(a.bytes / 1024)}KB`, a.name, a.description ?? "", a.source ? `出典: ${a.source}` : ""];
64
+ if (sub === "ls") {
65
+ const { items, invalid } = await ctx.ws.attachments.list(rid);
66
+ return out.result({ items, invalid }, () => [
67
+ items.length ? table(items.map(fmt)) : "添付はありません",
68
+ ...invalid.map((i) => `[読めない] ${i.id}: ${i.error}`),
69
+ "",
70
+ "次の Preflight を始めるときに、この添付を run に固定して渡します(後で足し・消ししても過去の run の資料は変わりません)",
71
+ ].join("\n"));
72
+ }
73
+ if (sub === "add") {
74
+ if (!target)
75
+ throw new UsageError("p3 attach add <ファイル> [--description 説明] [--source 出典] --req <要望>");
76
+ const data = await readFile(resolvePath(cwd, target)).catch(() => {
77
+ throw new UsageError(`ファイルが読めません: ${target}`);
78
+ });
79
+ try {
80
+ const a = await ctx.preflight.addAttachment(rid, { data, name: basename(target), description: o.description, source: o.source }, actor);
81
+ return out.result(a, () => `添付しました: ${table([fmt(a)])}\n次の Preflight に渡します`);
82
+ }
83
+ catch (e) {
84
+ throw e instanceof AttachmentError ? new UsageError(e.message) : e;
85
+ }
86
+ }
87
+ if (sub === "get") {
88
+ if (!target)
89
+ throw new UsageError("p3 attach get <A-ID> [--out ファイル] [--run PF-...](--run でその run に固定した原本)");
90
+ const got = o.run ? await ctx.preflight.fixedAttachment(rid, o.run, target) : await ctx.ws.attachments.content(rid, target).catch((e) => {
91
+ throw e instanceof AttachmentError ? new NotFoundError(e.message) : e;
92
+ });
93
+ const file = resolvePath(cwd, o.out ?? safeFileName(got.meta.name, got.meta.format));
94
+ await writeFile(file, got.data, { flag: "wx" }).catch((e) => {
95
+ throw e.code === "EEXIST" ? new UsageError(`${file} は既にあります(--out で別の名前に)`) : e;
96
+ });
97
+ return out.result({ ...got.meta, file }, () => `書き出しました: ${file}`);
98
+ }
99
+ if (sub === "rm") {
100
+ if (!target)
101
+ throw new UsageError("p3 attach rm <A-ID>");
102
+ await ctx.preflight.removeAttachment(rid, target).catch((e) => {
103
+ throw e instanceof AttachmentError ? new NotFoundError(target) : e;
104
+ });
105
+ return out.result({ removed: target }, () => `添付を外しました: ${target}(固定済みの過去の run の資料は残ります)`);
106
+ }
107
+ throw new UsageError("p3 attach [ls | add <ファイル> | get <A-ID> | rm <A-ID>] --req <要望>");
108
+ }
109
+ case "notes": {
110
+ const rid = requestArg(args[0]);
111
+ const { notes, invalid } = await ctx.ws.notes.list(rid);
112
+ const carry = await ctx.preflight.carryover(rid);
113
+ const pending = new Set(carry.notes.map((n) => n.id));
114
+ const items = notes.map((n) => ({ ...n, pending: pending.has(n.id) }));
115
+ return out.result({ notes: items, invalid, previous: carry.previous?.id ?? null, previousSkipped: carry.previousSkipped ?? null }, () => [
116
+ `次の Preflight: ${carry.previous ? `前回 ${carry.previous.id} を引き継ぐ` : carry.previousSkipped ? `前回を引き継がない(${carry.previousSkipped})` : "前回なし"}・メモ ${carry.notes.length} 件を渡す`,
117
+ ...items.map((n) => `\n${n.pending ? "[未]" : "[済]"} ${n.id} ${n.createdBy ?? ""} ${n.createdAt.slice(0, 16).replace("T", " ")}\n${indent(n.body)}`),
118
+ ...invalid.map((i) => `\n[読めない] ${i.file}: ${i.error}`),
119
+ ].join("\n"));
120
+ }
121
+ case "drafts": {
122
+ const rid = requestArg(args[0]);
123
+ const run = await pickRun(ctx, rid, o.run);
124
+ // タスク化の前なら、置き換えられる既存タスクも見せる(分割の run には無い)
125
+ const supersedes = run.materialized?.length || run.children ? [] : (await ctx.preflight.previewMaterialize(rid, run.id)).candidates;
126
+ const inputMatch = await ctx.preflight.inputMatch(rid, run);
127
+ return out.result({ ...run, inputMatch, supersedes }, () => [
128
+ formatRun(ctx, rid, run),
129
+ inputMatchLine(rid, run, inputMatch),
130
+ supersedes.length
131
+ ? `\n置き換えられる既存タスク(accept では残す。--archive-superseded でアーカイブ):\n${table(supersedes.map((c) => [c.id, c.status, c.title]))}`
132
+ : "",
133
+ ].join("\n"));
134
+ }
135
+ case "accept": {
136
+ const rid = requestArg(args[0]);
137
+ const run = await pickRun(ctx, rid, o.run);
138
+ const keys = (s) => s?.split(",").map((x) => x.trim().toUpperCase());
139
+ const only = keys(o.only);
140
+ const skip = keys(o.skip) ?? [];
141
+ if (run.children)
142
+ return adoptChildren(ctx, out, rid, run, only, skip, actor, !!o.json);
143
+ for (const d of run.drafts) {
144
+ const include = (only ? only.includes(d.key) : d.include) && !skip.includes(d.key);
145
+ if (include !== d.include)
146
+ await ctx.preflight.updateDraft(rid, run.id, d.key, { include });
147
+ }
148
+ // 置き換えられるタスクは --archive-superseded のときだけ、確定時点の候補(プレビューと同じ rev)をアーカイブする
149
+ const { candidates } = await ctx.preflight.previewMaterialize(rid, run.id);
150
+ const archive = o["archive-superseded"] ? candidates.map((c) => ({ id: c.id, rev: c.rev })) : [];
151
+ let r;
152
+ try {
153
+ r = await ctx.preflight.materialize(rid, run.id, actor, { archive });
154
+ }
155
+ catch (e) {
156
+ if (!(e instanceof StaleInputError) || !o.json)
157
+ throw e;
158
+ // --json では理由を機械可読で返す(終了コードは 1)
159
+ out.result({ error: e.message, code: e.code, request: rid, run: run.id, inputMatch: e.match }, () => "");
160
+ return 1;
161
+ }
162
+ return out.result(r, () => [
163
+ `タスク化 (${rid} / ${run.id}):\n${table(r.tasks.map((t) => [t.id, t.title, deps(t)]))}`,
164
+ r.archived.length ? `\n置き換えられたタスクをアーカイブしました: ${r.archived.join(", ")}` : "",
165
+ r.kept.length
166
+ ? `\n置き換えられるタスクを残しました(着手前に確かめ、不要なら p3 archive <T> か accept --archive-superseded):\n${table(r.kept.map((c) => [c.id, c.status, c.title, c.reasons.map((x) => `案 ${x.draft}`).join(",")]))}`
167
+ : "",
168
+ ].join("\n"));
169
+ }
170
+ }
171
+ return undefined;
172
+ }
173
+ /**
174
+ * 分割の run の採用: 選んだ子の案から子の要望を作る(子のタスク化・Preflight はしない)。途中で失敗したら作った・失敗・未実行を出し、
175
+ * 同じ accept でやり直せる(作った子は作り直さない)。終了コード: 全部作れたら 0、失敗があれば 1
176
+ */
177
+ async function adoptChildren(ctx, out, rid, run, only, skip, actor, json) {
178
+ if (!run.adoption) {
179
+ for (const c of run.children ?? []) {
180
+ const include = (only ? only.includes(c.key) : c.include) && !skip.includes(c.key);
181
+ if (include !== c.include)
182
+ await ctx.preflight.updateChild(rid, run.id, c.key, { include });
183
+ }
184
+ }
185
+ else if (only || skip.length) {
186
+ throw new UsageError(`${run.id} は採用を始めています(選んだ案: ${run.adoption.keys.join(", ")})。--only / --skip を外して、同じ採用を続けてください`);
187
+ }
188
+ let r;
189
+ try {
190
+ r = await ctx.preflight.adopt(rid, run.id, actor);
191
+ }
192
+ catch (e) {
193
+ if (!(e instanceof StaleInputError) || !json)
194
+ throw e;
195
+ out.result({ error: e.message, code: e.code, request: rid, run: run.id, inputMatch: e.match }, () => "");
196
+ return 1;
197
+ }
198
+ const title = (id) => ctx.ws.requests.get(id)?.title ?? "";
199
+ out.result(r, () => [
200
+ `子の要望を作りました (${rid} / ${run.id}):`,
201
+ table(r.created.map((c) => [` ${c.key}`, c.id, title(c.id)])) || " (なし)",
202
+ ...r.failed.map((f) => `\n作れませんでした: ${f.key}(${f.error})`),
203
+ r.pending.length ? `まだ作っていない案: ${r.pending.join(", ")}(直してから p3 accept ${rid} --run ${run.id} で続けます。作った子は作り直しません)` : "",
204
+ r.failed.length ? "" : `\n親 ${rid} は残します。子ごとに Preflight を実行してください(例: p3 preflight ${r.created[0]?.id ?? "<子>"})`,
205
+ ]
206
+ .filter(Boolean)
207
+ .join("\n"));
208
+ return r.failed.length ? 1 : 0;
209
+ }
210
+ /** 評価対象と今の要望の比較(drafts の表示) */
211
+ function inputMatchLine(rid, run, m) {
212
+ if (m.status === "same")
213
+ return "";
214
+ if (isMaterialized(run)) {
215
+ return `\n※ この評価のあとで要望が変わっています(${m.status === "changed" ? changedLabel(m.changed) : m.reason})。タスク化は済んでいます。作り直すなら p3 preflight ${rid}`;
216
+ }
217
+ return `\n※ ${staleMessage(rid, run.id, m)}`;
218
+ }
219
+ async function pickRun(ctx, rid, runId) {
220
+ const runs = await ctx.preflight.list(rid);
221
+ const run = runId ? runs.find((r) => r.id === runId) : runs[0];
222
+ if (!run)
223
+ throw new NotFoundError(runId ?? `${rid} の preflight`);
224
+ return run;
225
+ }
226
+ function formatRun(ctx, rid, run) {
227
+ const lines = [`${rid} / ${run.id} ${run.engine} ${run.status}${run.startedBy ? ` ${run.startedBy}` : ""}`];
228
+ if (run.previous || run.notes?.length) {
229
+ lines.push(`引き継ぎ: ${run.previous ? `前回 ${run.previous}` : "前回なし"}${run.notes?.length ? ` / メモ ${run.notes.join(", ")}` : ""}`);
230
+ }
231
+ if (run.error)
232
+ lines.push(`エラー: ${run.error}`);
233
+ const a = run.assessment;
234
+ if (a) {
235
+ lines.push("", `判定: ${a.verdict} 妥当性 ${a.validity.score} / 実現可能性 ${a.feasibility.score}`, indent(a.summary));
236
+ if (a.risks.length)
237
+ lines.push("", "リスク:", ...a.risks.map((x) => ` - ${x}`));
238
+ if (a.questions.length)
239
+ lines.push("", "確認事項:", ...a.questions.map((x) => ` - ${x}`));
240
+ }
241
+ lines.push("", ...scopeLines(run.scope));
242
+ if (a)
243
+ lines.push("", ...evidenceLines(a.evidence));
244
+ if (run.scope?.some((s) => s.status === "unregistered"))
245
+ lines.push(" → このマシンのパスは p3 repo path <名前> <パス> で登録します");
246
+ if (run.drafts.length) {
247
+ lines.push("", `タスク案 (${run.drafts.filter((d) => d.include).length}/${run.drafts.length} 件を採用):`);
248
+ const multi = ctx.ws.project.repos.length > 0;
249
+ lines.push(table(run.drafts.map((d) => [
250
+ d.include ? "[x]" : "[ ]",
251
+ d.key,
252
+ ...(multi ? [d.repo ?? "(作業先なし)"] : []),
253
+ d.title,
254
+ d.dependsOn.length ? `← ${d.dependsOn.join(",")}` : "",
255
+ ])));
256
+ lines.push("", `ファイル: ${relative(process.cwd(), join(ctx.ws.preflight.runDir(rid, run.id), "drafts"))}/`);
257
+ }
258
+ if (a?.split) {
259
+ lines.push("", `分割: ${a.split.decision === "split" ? "子の要望に分ける" : "分けない"}${a.split.estimatedTasks !== undefined ? `(想定 ${a.split.estimatedTasks} 件)` : ""}`, ...a.split.reasons.map((x) => ` - ${x}`));
260
+ }
261
+ if (run.children) {
262
+ lines.push("", `子の要望の案 (${run.children.filter((c) => c.include).length}/${run.children.length} 件を採用):`);
263
+ lines.push(table(run.children.map((c) => [
264
+ c.include ? "[x]" : "[ ]",
265
+ c.key,
266
+ c.title,
267
+ c.estimatedTasks !== undefined ? `想定 ${c.estimatedTasks} 件` : "",
268
+ c.requires.length ? `前提 ${c.requires.join(",")}` : "",
269
+ c.overlaps.length ? `重なり ${c.overlaps.join(",")}` : "",
270
+ run.adoption?.reserved[c.key] ? `→ ${run.adoption.reserved[c.key]}${run.adoption.created.includes(c.key) ? "" : "(予約)"}` : "",
271
+ ])));
272
+ for (const p of run.draftProblems ?? [])
273
+ lines.push(` [問題] ${p}`);
274
+ lines.push("", `ファイル: ${relative(process.cwd(), join(ctx.ws.preflight.runDir(rid, run.id), "children"))}/`);
275
+ lines.push(run.adoption?.done ? "子の要望を作成済み(子ごとに Preflight を実行します)" : `採用: p3 accept ${rid} --run ${run.id}(親は残し、子の要望だけを作ります。子の Preflight はまだ)`);
276
+ }
277
+ lines.push("", ...uiLines(run.ui, relative(process.cwd(), join(ctx.ws.preflight.runDir(rid, run.id), "ui"))));
278
+ if (run.materialized?.length)
279
+ lines.push("", `タスク化済み: ${run.materialized.join(", ")}`);
280
+ return lines.join("\n");
281
+ }
282
+ const UI_STATUS = { generating: "評価中", ready: "そろっています", not_needed: "不要", missing: "足りません" };
283
+ /** 画面資料(ui/)。資料 ID は画面・API(/api/requests/<要望>/preflight/<run>/ui/<ID>)と同じ */
284
+ function uiLines(ui, dir) {
285
+ if (!ui)
286
+ return ["画面資料: 記録なし(以前の run)"];
287
+ const lines = [`画面資料: ${UI_STATUS[ui.status]}${ui.reason ? `(${ui.reason})` : ""}`];
288
+ if (ui.verdictAdjusted)
289
+ lines.push(" → 必要な画面イメージが足りないので、判定を go から clarify にしました");
290
+ if (ui.items.length) {
291
+ lines.push(table(ui.items.map((m) => [` ${m.id}`, UI_MATERIAL_KINDS[m.kind], m.drafts.join(","), `${m.width}x${m.height}`, m.title, `ui/${m.file}`])));
292
+ for (const m of ui.items.filter((x) => x.assumptions.length))
293
+ lines.push(` ${m.id} の前提: ${m.assumptions.join(" / ")}`);
294
+ if (ui.items.some((m) => m.rendered))
295
+ lines.push(" P3 が原稿から描いた画像です(Codex は画像を見ていません。読めるかは画像で確かめてください)");
296
+ lines.push(` ファイル: ${dir}/`);
297
+ }
298
+ for (const p of ui.problems)
299
+ lines.push(` [取り込めない] ${p}`);
300
+ return lines;
301
+ }