@infodb/p3 0.4.0 → 0.5.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 (208) hide show
  1. package/bin/p3.mjs +11 -5
  2. package/dist/web/assets/Outputs-C83ZDXvs.js +1 -0
  3. package/dist/web/assets/RequestStatus-GmiWYEcL.js +1 -0
  4. package/dist/web/assets/Tabs-CJn0Qy7W.js +1 -0
  5. package/dist/web/assets/TagInput-CtM8HM8Z.js +1 -0
  6. package/dist/web/assets/TaskDrawer-D5v36QoF.js +3 -0
  7. package/dist/web/assets/_requestId-BHUqLO-j.js +1 -0
  8. package/dist/web/assets/_requestId-DxwxbXY2.js +30 -0
  9. package/dist/web/assets/{ui-DdOGYj9z.js → appCtx-B-VRVOyv.js} +1 -1
  10. package/dist/web/assets/board-DAaVR04x.js +1 -0
  11. package/dist/web/assets/done-CaqB_qTH.js +1 -0
  12. package/dist/web/assets/index-BF1xMdJo.css +2 -0
  13. package/dist/web/assets/index-BQYvKpjF.js +12 -0
  14. package/dist/web/assets/new-DLVnRvrB.js +1 -0
  15. package/dist/web/assets/{preflightInput-DMxqnvF8.js → preflightInput-BAeEJYUK.js} +1 -1
  16. package/dist/web/assets/preload-helper-B74h5i3O.js +1 -0
  17. package/dist/web/assets/progressTree-wp9mH4VF.js +1 -0
  18. package/dist/web/assets/release-notes-MTLcOcvZ.js +3 -0
  19. package/dist/web/assets/requestData-D-HXu-cy.js +1 -0
  20. package/dist/web/assets/routes-CI4Qfkjs.js +3 -0
  21. package/dist/web/assets/settings-CJMNgzi6.js +1 -0
  22. package/dist/web/index.html +4 -4
  23. package/docs/architecture.md +220 -3
  24. package/docs/development.md +16 -9
  25. package/docs/how-to-use.md +72 -7
  26. package/docs/installation.md +8 -6
  27. package/docs/publishing.md +4 -2
  28. package/lib/cli/args.js +172 -0
  29. package/lib/cli/chatgpt.js +70 -0
  30. package/lib/cli/codex.js +30 -0
  31. package/lib/cli/format.js +9 -0
  32. package/{src/cli/help.ts → lib/cli/help.js} +8 -8
  33. package/lib/cli/main.js +326 -0
  34. package/lib/cli/output.js +110 -0
  35. package/lib/cli/preflightCommands.js +301 -0
  36. package/lib/cli/project.js +649 -0
  37. package/lib/cli/readOnly.js +36 -0
  38. package/lib/cli/releaseNotesCommands.js +197 -0
  39. package/lib/cli/render.js +58 -0
  40. package/lib/cli/requestCommands.js +180 -0
  41. package/lib/cli/showView.js +100 -0
  42. package/lib/cli/taskCommands.js +152 -0
  43. package/lib/cli/userConfig.js +64 -0
  44. package/{src/core/chatgpt.ts → lib/core/chatgpt.js} +10 -16
  45. package/lib/core/context.js +41 -0
  46. package/lib/core/hierarchy.js +128 -0
  47. package/lib/core/machineSettings.js +146 -0
  48. package/lib/core/machineSettingsEdit.js +148 -0
  49. package/lib/core/ops.js +120 -0
  50. package/lib/core/preflight/carryover.js +105 -0
  51. package/lib/core/preflight/codexEngine.js +687 -0
  52. package/lib/core/preflight/codexImage.js +61 -0
  53. package/lib/core/preflight/diagnose.js +95 -0
  54. package/lib/core/preflight/engine.js +58 -0
  55. package/lib/core/preflight/input.js +83 -0
  56. package/lib/core/preflight/launch.js +68 -0
  57. package/lib/core/preflight/mockEngine.js +175 -0
  58. package/lib/core/preflight/render.js +304 -0
  59. package/lib/core/preflight/service.js +868 -0
  60. package/lib/core/preflight/split.js +83 -0
  61. package/lib/core/preflight/uiMaterials.js +281 -0
  62. package/lib/core/preflight/uiRender.js +89 -0
  63. package/lib/core/preflight/wireframe.js +63 -0
  64. package/lib/core/preflight/xlsx.js +324 -0
  65. package/lib/core/projectRegistry.js +207 -0
  66. package/lib/core/redact.js +28 -0
  67. package/lib/core/releaseNotes/completeRequests.js +106 -0
  68. package/lib/core/releaseNotes/generate.js +266 -0
  69. package/lib/core/releaseNotes/material.js +141 -0
  70. package/lib/core/releaseNotes/mockSummarizer.js +26 -0
  71. package/lib/core/releaseNotes/service.js +83 -0
  72. package/lib/core/releaseNotes/store.js +209 -0
  73. package/lib/core/repoAdmin.js +82 -0
  74. package/lib/core/repoRefs.js +72 -0
  75. package/lib/core/requestOps.js +154 -0
  76. package/lib/core/requestStatus.js +171 -0
  77. package/lib/core/store/attachments.js +242 -0
  78. package/lib/core/store/collection.js +254 -0
  79. package/lib/core/store/frontmatter.js +18 -0
  80. package/lib/core/store/fsutil.js +84 -0
  81. package/lib/core/store/locate.js +162 -0
  82. package/lib/core/store/normalize.js +150 -0
  83. package/lib/core/store/noteStore.js +59 -0
  84. package/lib/core/store/preflightStore.js +161 -0
  85. package/lib/core/store/projectFile.js +99 -0
  86. package/lib/core/store/workspace.js +320 -0
  87. package/lib/core/supersede.js +69 -0
  88. package/lib/core/userConfig.js +158 -0
  89. package/{src/core/userTheme.ts → lib/core/userTheme.js} +11 -13
  90. package/lib/core/workTargets.js +106 -0
  91. package/lib/server/api/chatgptRoutes.js +46 -0
  92. package/{src/server/api/local.ts → lib/server/api/local.js} +23 -22
  93. package/lib/server/api/manifest.js +140 -0
  94. package/lib/server/api/projectsRoutes.js +82 -0
  95. package/lib/server/api/releaseNoteRoutes.js +88 -0
  96. package/lib/server/api/repoRoutes.js +67 -0
  97. package/lib/server/api/routes.js +404 -0
  98. package/lib/server/api/userThemeRoutes.js +60 -0
  99. package/lib/server/server.js +85 -0
  100. package/lib/shared/dates.js +10 -0
  101. package/{src/shared/directTask.ts → lib/shared/directTask.js} +3 -11
  102. package/lib/shared/hierarchy.js +120 -0
  103. package/lib/shared/milestoneOrder.js +45 -0
  104. package/lib/shared/preflightInput.js +19 -0
  105. package/lib/shared/refs.js +44 -0
  106. package/lib/shared/repos.js +69 -0
  107. package/lib/shared/scopeView.js +39 -0
  108. package/{src/shared/tags.ts → lib/shared/tags.js} +9 -14
  109. package/lib/shared/types.js +74 -0
  110. package/lib/shared/workTarget.js +31 -0
  111. package/package.json +4 -7
  112. package/skills/p3/SKILL.md +10 -0
  113. package/dist/web/assets/Outputs-5Hby-S5Q.js +0 -1
  114. package/dist/web/assets/RequestStatus-CTkGjT02.js +0 -1
  115. package/dist/web/assets/TagInput-Rj3PNOAF.js +0 -1
  116. package/dist/web/assets/TaskDrawer-DtPhiYxP.js +0 -3
  117. package/dist/web/assets/_requestId-CGvAfIkB.js +0 -30
  118. package/dist/web/assets/_requestId-DxfYhgAq.js +0 -1
  119. package/dist/web/assets/board-wt47lfrE.js +0 -1
  120. package/dist/web/assets/done-C9Ct7ssb.js +0 -1
  121. package/dist/web/assets/index-BTFL2rpp.js +0 -12
  122. package/dist/web/assets/index-DAyBsvua.css +0 -2
  123. package/dist/web/assets/new-e4ID2vQV.js +0 -1
  124. package/dist/web/assets/preload-helper-DhIyFaOW.js +0 -1
  125. package/dist/web/assets/release-notes-CQ0d2r0k.js +0 -3
  126. package/dist/web/assets/requestData-BDZqyl35.js +0 -1
  127. package/dist/web/assets/routes-Bipv3lwJ.js +0 -2
  128. package/dist/web/assets/settings-Dwh8fj6p.js +0 -1
  129. package/src/cli/args.ts +0 -186
  130. package/src/cli/chatgpt.ts +0 -74
  131. package/src/cli/codex.ts +0 -28
  132. package/src/cli/format.ts +0 -9
  133. package/src/cli/main.ts +0 -337
  134. package/src/cli/output.ts +0 -117
  135. package/src/cli/preflightCommands.ts +0 -245
  136. package/src/cli/project.ts +0 -675
  137. package/src/cli/readOnly.ts +0 -36
  138. package/src/cli/releaseNotesCommands.ts +0 -198
  139. package/src/cli/render.ts +0 -60
  140. package/src/cli/requestCommands.ts +0 -172
  141. package/src/cli/showView.ts +0 -110
  142. package/src/cli/taskCommands.ts +0 -167
  143. package/src/cli/userConfig.ts +0 -58
  144. package/src/core/context.ts +0 -58
  145. package/src/core/machineSettings.ts +0 -207
  146. package/src/core/machineSettingsEdit.ts +0 -156
  147. package/src/core/ops.ts +0 -114
  148. package/src/core/preflight/carryover.ts +0 -133
  149. package/src/core/preflight/codexEngine.ts +0 -703
  150. package/src/core/preflight/codexImage.ts +0 -98
  151. package/src/core/preflight/diagnose.ts +0 -124
  152. package/src/core/preflight/engine.ts +0 -92
  153. package/src/core/preflight/input.ts +0 -65
  154. package/src/core/preflight/launch.ts +0 -86
  155. package/src/core/preflight/mockEngine.ts +0 -145
  156. package/src/core/preflight/render.ts +0 -339
  157. package/src/core/preflight/service.ts +0 -707
  158. package/src/core/preflight/uiMaterials.ts +0 -272
  159. package/src/core/preflight/uiRender.ts +0 -84
  160. package/src/core/preflight/wireframe.ts +0 -69
  161. package/src/core/preflight/xlsx.ts +0 -328
  162. package/src/core/projectRegistry.ts +0 -264
  163. package/src/core/redact.ts +0 -31
  164. package/src/core/releaseNotes/completeRequests.ts +0 -102
  165. package/src/core/releaseNotes/generate.ts +0 -283
  166. package/src/core/releaseNotes/material.ts +0 -114
  167. package/src/core/releaseNotes/mockSummarizer.ts +0 -28
  168. package/src/core/releaseNotes/service.ts +0 -110
  169. package/src/core/releaseNotes/store.ts +0 -216
  170. package/src/core/repoAdmin.ts +0 -81
  171. package/src/core/repoRefs.ts +0 -90
  172. package/src/core/requestOps.ts +0 -140
  173. package/src/core/requestStatus.ts +0 -58
  174. package/src/core/store/attachments.ts +0 -228
  175. package/src/core/store/collection.ts +0 -282
  176. package/src/core/store/frontmatter.ts +0 -22
  177. package/src/core/store/fsutil.ts +0 -90
  178. package/src/core/store/locate.ts +0 -181
  179. package/src/core/store/normalize.ts +0 -155
  180. package/src/core/store/noteStore.ts +0 -56
  181. package/src/core/store/preflightStore.ts +0 -136
  182. package/src/core/store/projectFile.ts +0 -101
  183. package/src/core/store/workspace.ts +0 -328
  184. package/src/core/supersede.ts +0 -74
  185. package/src/core/userConfig.ts +0 -205
  186. package/src/core/workTargets.ts +0 -120
  187. package/src/server/api/chatgptRoutes.ts +0 -49
  188. package/src/server/api/manifest.ts +0 -135
  189. package/src/server/api/projectsRoutes.ts +0 -89
  190. package/src/server/api/releaseNoteRoutes.ts +0 -89
  191. package/src/server/api/repoRoutes.ts +0 -67
  192. package/src/server/api/routes.ts +0 -382
  193. package/src/server/api/userThemeRoutes.ts +0 -62
  194. package/src/server/server.ts +0 -108
  195. package/src/shared/dates.ts +0 -12
  196. package/src/shared/milestoneOrder.ts +0 -44
  197. package/src/shared/preflightInput.ts +0 -27
  198. package/src/shared/refs.ts +0 -55
  199. package/src/shared/repos.ts +0 -113
  200. package/src/shared/scopeView.ts +0 -48
  201. package/src/shared/types.ts +0 -730
  202. package/src/shared/workTarget.ts +0 -44
  203. /package/{src → lib}/core/preflight/launcher.mjs +0 -0
  204. /package/{src → lib}/core/preflight/mock-ui.html +0 -0
  205. /package/{src → lib}/core/preflight/mock-ui.png +0 -0
  206. /package/{src → lib}/core/preflight/render-image/Dockerfile +0 -0
  207. /package/{src → lib}/core/preflight/render-image/fonts-ja.conf +0 -0
  208. /package/{src → lib}/core/preflight/render-image/render.mjs +0 -0
@@ -1,167 +0,0 @@
1
- import { relative } from "node:path";
2
- import type { Task } from "../shared/types.ts";
3
- import { listTasks, resolve, resolveRef } from "../core/ops.ts";
4
- import { archiveTask, createTask, updateTask } from "../core/requestOps.ts";
5
- import { supersededMarks } from "../core/supersede.ts";
6
- import { table } from "./format.ts";
7
- import { taskRepo } from "../shared/workTarget.ts";
8
- import { addRepoOutputs, parseRepoOutput, repoArg } from "../core/workTargets.ts";
9
- import { briefTask, formatBriefTask, taskExtras } from "./showView.ts";
10
- import { UsageError } from "./project.ts";
11
- import { parseTaskAssignments, checkStatus, readBody, type CommandEnv } from "./args.ts";
12
- import { dependentsOf, formatEntity, ambiguous, replacedBy, reopenedNote, warn, deps, workHint } from "./output.ts";
13
- import { requestCommand } from "./requestCommands.ts";
14
-
15
- /** タスクのコマンド(ls / show / find / impact / new / set / move / check / link / unlink / archive)。変更は server/requestOps.ts を通す。扱わないコマンドは undefined */
16
-
17
- const RECORD_REQUIRED =
18
- "AI が完了にするときは --record で変更の記録を残してください(何を変えたか・なぜ・入れた決まり・やめたもの。Markdown。- で標準入力)\n" +
19
- " 例: p3 move T003 done --output <成果物(変えたファイルや説明。URL は後から足せます)> --record - < record.md";
20
-
21
- export async function taskCommand(cmd: string, env: CommandEnv): Promise<number | undefined> {
22
- const { ctx, out, args, o, actor, current, expectedRev, requestArg, taskArg, split, cwd } = env;
23
- switch (cmd) {
24
- // --- タスク -------------------------------------------------------------
25
- case "ls":
26
- case "list": {
27
- if (o.repo !== undefined && o.repo !== "none" && !ctx.ws.project.repos.some((r) => r.name === o.repo)) {
28
- throw new UsageError(`参照先「${o.repo}」は登録されていません(p3 repo ls)`);
29
- }
30
- const filter = { status: o.status?.split(","), area: o.area?.[0], q: o.q, repo: o.repo };
31
- const tasks = listTasks(ctx, { ...filter, request: o.all ? undefined : requestArg(undefined) });
32
- const marks = supersededMarks(ctx.ws);
33
- const items = tasks.map((t) => (marks.has(t.ref) ? { ...t, superseded: marks.get(t.ref) } : t));
34
- // 共有の参照先があるときは作業先の列を出す
35
- const multi = ctx.ws.project.repos.length > 0;
36
- return out.result(items, () =>
37
- table(
38
- tasks.map((t) => [
39
- o.all ? t.ref : t.id,
40
- t.status,
41
- ...(multi ? [taskRepo(t) ?? "(なし)"] : []),
42
- t.title,
43
- [deps(t), replacedBy(t, marks)].filter(Boolean).join(" "),
44
- ]),
45
- ) || "タスクはありません",
46
- );
47
- }
48
-
49
- case "show": {
50
- const query = args.join(" ");
51
- const ref = resolveRef(ctx, query, current) ?? resolve(ctx, query, current).match;
52
- if (!ref) return ambiguous(out, ctx, query, current);
53
- if (!ref.includes("/")) return requestCommand(ctx, out, ["show", ref], o, actor, requestArg, expectedRev);
54
- const item = ctx.ws.requireTask(ref);
55
- const marks = supersededMarks(ctx.ws);
56
- if (o.brief) {
57
- const view = briefTask(ctx, item, marks);
58
- return out.result(view, () => formatBriefTask(view));
59
- }
60
- const file = relative(cwd, split(ref).col.path(item.id));
61
- const { superseded, dependencies, warnings } = taskExtras(ctx, item, marks);
62
- const dependents = dependentsOf(ctx, item).map((t) => ({ ref: t.ref, title: t.title, status: t.status }));
63
- return out.result({ item, file, superseded, dependencies, dependents, warnings }, () =>
64
- [superseded.length ? `※ 置き換えられています: ${superseded.map((m) => `${m.from}${m.note ? `(${m.note})` : ""}`).join(" / ")}\n` : "", formatEntity(ctx, item, file)].join(""),
65
- );
66
- }
67
-
68
- case "find":
69
- case "resolve": {
70
- const r = resolve(ctx, args.join(" "), current);
71
- return out.result(r, () => table(r.candidates.map((c) => [c.ref, c.score.toFixed(2), c.title, c.reasons.join(" / ")])) || "見つかりません");
72
- }
73
-
74
- case "new":
75
- case "add": {
76
- // 互換: new task <タイトル> / new request <タイトル>
77
- if (args[0] === "request" || args[0] === "req") return requestCommand(ctx, out, ["new", ...args.slice(1)], o, actor, requestArg, expectedRev);
78
- const title = (args[0] === "task" ? args.slice(1) : args).join(" ").trim();
79
- if (!title) throw new UsageError("タイトルを指定してください");
80
- const rid = requestArg(undefined);
81
- const status = o.status ?? "todo";
82
- checkStatus(status);
83
- // 作業先(--repo <名前>|none)。作業先にできるものだけ。書く前に確かめる
84
- const repo = repoArg(o.repo);
85
- const repoOutputs = (o["repo-output"] ?? []).map((x) => parseRepoOutput(ctx.ws, x));
86
- const r = await createTask(
87
- ctx,
88
- rid,
89
- {
90
- title,
91
- status,
92
- ...(repo !== undefined ? { repo } : {}),
93
- labels: o.label ?? [],
94
- areas: o.area ?? [],
95
- outputs: o.output ?? [],
96
- ...(repoOutputs.length ? { repoOutputs: addRepoOutputs([], repoOutputs) } : {}),
97
- body: readBody(o.body),
98
- },
99
- actor,
100
- );
101
- const t = r.task;
102
- const reopened = reopenedNote(r.reopened);
103
- return out.result(reopened ? { ...t, reopened } : t, () => [`作成: ${t.ref} ${t.title}`, workHint(ctx, t)].filter(Boolean).join("\n"));
104
- }
105
-
106
- case "set": {
107
- const ref = taskArg(args[0]);
108
- const patch = parseTaskAssignments(args.slice(1));
109
- if (o.body !== undefined) patch.body = readBody(o.body);
110
- if (o.record !== undefined) patch.record = readBody(o.record).trim() || undefined;
111
- const { col, tid } = split(ref);
112
- if (patch.status === "done" && actor.startsWith("ai:") && !patch.record && !col.require(tid).record) throw new UsageError(RECORD_REQUIRED);
113
- if (o["repo-output"]?.length) {
114
- const add = o["repo-output"].map((x) => parseRepoOutput(ctx.ws, x));
115
- patch.repoOutputs = addRepoOutputs(patch.repoOutputs ?? col.require(tid).repoOutputs ?? [], add);
116
- }
117
- if (!Object.keys(patch).length) throw new UsageError("キー=値 を指定してください");
118
- const r = await updateTask(ctx, ref.split("/")[0], tid, patch, { expectedRev, actor });
119
- const { task: next, warnings } = r;
120
- warn(warnings);
121
- const reopened = reopenedNote(r.reopened);
122
- return out.result({ ...next, ...(warnings.length ? { warnings } : {}), ...(reopened ? { reopened } : {}) }, () =>
123
- [`更新: ${next.ref} (rev ${next.rev}) ${Object.keys(patch).join(", ")}`, "repo" in patch ? workHint(ctx, next) : ""].filter(Boolean).join("\n"),
124
- );
125
- }
126
-
127
- case "move": {
128
- const ref = taskArg(args[0]);
129
- const status = args[1];
130
- if (!status) throw new UsageError("移動先のステータスを指定してください");
131
- checkStatus(status);
132
- const { col, tid } = split(ref);
133
- const cur = col.require(tid);
134
- const patch: Partial<Task> = { status };
135
- if (o.record !== undefined) patch.record = readBody(o.record).trim() || undefined;
136
- // AI が完了にするときは変更の記録を残す(後の Preflight・タスク解析・リリースノートが読む)
137
- if (status === "done" && actor.startsWith("ai:") && !patch.record && !cur.record) throw new UsageError(RECORD_REQUIRED);
138
- if (o.output?.length) patch.outputs = [...new Set([...cur.outputs, ...o.output])];
139
- // リポジトリごとの成果物(最後のタスクに、関係するリポジトリの PR を全部残せる)
140
- if (o["repo-output"]?.length) patch.repoOutputs = addRepoOutputs(cur.repoOutputs ?? [], o["repo-output"].map((x) => parseRepoOutput(ctx.ws, x)));
141
- const r = await updateTask(ctx, cur.request, tid, patch, { expectedRev, actor });
142
- const { task: next, warnings } = r;
143
- warn(warnings);
144
- const reopened = reopenedNote(r.reopened);
145
- return out.result({ ...next, ...(warnings.length ? { warnings } : {}), ...(reopened ? { reopened } : {}) }, () =>
146
- `${next.ref} → ${status}${[...(o.output ?? []), ...(o["repo-output"] ?? [])].length ? ` (${[...(o.output ?? []), ...(o["repo-output"] ?? [])].join(", ")})` : ""}`,
147
- );
148
- }
149
-
150
- case "check": {
151
- const ref = taskArg(args[0]);
152
- const { tid } = split(ref);
153
- const { task: next } = await updateTask(ctx, ref.split("/")[0], tid, { checked: !o.off }, { expectedRev, actor });
154
- return out.result(next, () => `${next.ref} ${o.off ? "の済みを外しました" : "を済みにしました"}`);
155
- }
156
-
157
- case "archive": {
158
- const ref = taskArg(args[0]);
159
- const { tid } = split(ref);
160
- await archiveTask(ctx, ref.split("/")[0], tid);
161
- return out.result({ archived: ref }, () => `アーカイブ: ${ref}`);
162
- }
163
-
164
- }
165
- return undefined;
166
- }
167
-
@@ -1,58 +0,0 @@
1
- import { THEMES } from "../shared/types.ts";
2
- import { describeSettings, parseSettingChange, SETTING_KEY_LIST, SettingsInputError, writeMachineSettings, type SettingChange } from "../core/machineSettingsEdit.ts";
3
- import { loadUserConfig, UserConfigError, userConfigPath } from "../core/userConfig.ts";
4
- import { readTheme, ThemeInputError, writeTheme } from "../core/userTheme.ts";
5
- import { UsageError } from "./project.ts";
6
-
7
- const USAGE = [
8
- "p3 user-config 個人設定の値と出どころ(環境変数 / 個人設定 / 既定)",
9
- `p3 user-config set キー=値 ... ui.theme=${THEMES.join("|")} / ${SETTING_KEY_LIST.filter((k) => k !== "codex.pathMap").join(" ")}(キー= で消す)`,
10
- "p3 user-config set codex.pathMap+=<このマシンのパス>=<Docker デーモンから見たパス> パスの対応を足す",
11
- "p3 user-config set codex.pathMap-=<このマシンのパス> パスの対応を外す(codex.pathMap= で全部)",
12
- ].join("\n");
13
-
14
- /**
15
- * p3 user-config [set ...]。個人設定(このマシン・この人)のうち、画面のテーマとマシンごとの設定(codex / preflight / serve)を
16
- * 見せ・変える。プロジェクトの登録は p3 project、プロジェクトの設定は p3 config。プロジェクトを決める前に動く。
17
- */
18
- export async function userConfigCommand(args: string[], env: Record<string, string | undefined> = process.env): Promise<{ data: unknown; text: string }> {
19
- const [sub, ...pairs] = args;
20
- const path = userConfigPath();
21
- if (sub === undefined || sub === "ls" || sub === "show") {
22
- const theme = await readTheme(path);
23
- const user = await loadUserConfig(path).catch((e) => {
24
- if (e instanceof UserConfigError) throw new UsageError(e.message);
25
- throw e;
26
- });
27
- const { rows, error } = describeSettings(user, env);
28
- const width = Math.max(...rows.map((r) => r.key.length), "ui.theme".length) + 2;
29
- const text = [
30
- `${"ui.theme".padEnd(width)}${theme}`,
31
- ...rows.map((r) => `${r.key.padEnd(width)}${r.value}${r.from === "既定" ? " (既定)" : r.from === "環境変数" ? ` (環境変数 ${r.env})` : ""}`),
32
- ...(error ? ["", `読めない値があります: ${error}`] : []),
33
- "",
34
- `ファイル: ${path}`,
35
- "変えるとき: p3 user-config set キー=値(例: p3 user-config set codex.pathMap+=/workspaces=/home/me/workspaces)",
36
- ].join("\n");
37
- return { data: { ui: { theme }, settings: rows, ...(error ? { error } : {}), path }, text };
38
- }
39
- if (sub !== "set" || !pairs.length) throw new UsageError(USAGE);
40
-
41
- let theme: string | undefined;
42
- const changes: SettingChange[] = [];
43
- try {
44
- for (const pair of pairs) {
45
- if (pair === "ui.theme" || pair.startsWith("ui.theme=")) theme = pair.slice("ui.theme=".length);
46
- else changes.push(parseSettingChange(pair));
47
- }
48
- // 読めない値があれば何も書かない(テーマも書く前に確かめる)
49
- if (theme !== undefined && !(THEMES as readonly string[]).includes(theme)) throw new ThemeInputError(`ui.theme は ${THEMES.join(" / ")} のどれか: ${theme}`);
50
- if (changes.length) await writeMachineSettings(changes, path);
51
- if (theme !== undefined) await writeTheme(theme, path);
52
- } catch (e) {
53
- if (e instanceof SettingsInputError || e instanceof ThemeInputError || e instanceof UserConfigError) throw new UsageError(e.message);
54
- throw e;
55
- }
56
- const keys = pairs.map((p) => p.replace(/^(codex\.pathMap[+-]?)=.*$/s, "$1").replace(/=.*$/s, ""));
57
- return { data: { changed: keys, path }, text: `個人設定を変えました: ${keys.join(", ")}(${path})\n効いている値は p3 user-config で確かめられます` };
58
- }
@@ -1,58 +0,0 @@
1
- import { fileURLToPath } from "node:url";
2
- import { chatgptAccount, type ChatGptAccount } from "./chatgpt.ts";
3
- import { CodexWorkspaceEngine, codexConfig } from "./preflight/codexEngine.ts";
4
- import { fixedSettings, machineSettingsSource, type MachineSettings, type SettingsSource } from "./machineSettings.ts";
5
- import type { PreflightEngine } from "./preflight/engine.ts";
6
- import { MockEngine } from "./preflight/mockEngine.ts";
7
- import { PreflightService } from "./preflight/service.ts";
8
- import { checkDataDir } from "./store/locate.ts";
9
- import { Workspace } from "./store/workspace.ts";
10
- import { ReleaseGenerator } from "./releaseNotes/generate.ts";
11
- import { MockSummarizer } from "./releaseNotes/mockSummarizer.ts";
12
-
13
- /** p3 本体(パッケージ)のルート */
14
- export const P3_ROOT = fileURLToPath(new URL("../../", import.meta.url));
15
-
16
- export interface P3Context {
17
- ws: Workspace;
18
- preflight: PreflightService;
19
- /** リリースノートの要約の生成(Codex の接続を Preflight と共有する) */
20
- releaseGenerator: ReleaseGenerator;
21
- /** ChatGPT の接続(このマシン。サインインの待ち受けを Codex エンジンと共有する) */
22
- chatgpt?: ChatGptAccount;
23
- /** 個人設定に登録したプロジェクト名(参照先のこのマシンのパスを書くため。登録していなければ無い) */
24
- projectName?: string;
25
- }
26
-
27
- /**
28
- * サーバと CLI が共有する組み立て。どちらもデータのフォルダのファイルを直接読み書きする。
29
- * repos: 参照先の名前 → このマシンのパス(個人設定)
30
- * settings: マシンごとの設定(環境変数と個人設定から。.env は読まない)。省くと個人設定から、Preflight を始めるたび・
31
- * エンジンの状態を見るたびに読み直す(serve を起動し直さずに効く)。MachineSettings を渡すとその値に決める(テストなど)。
32
- * プロジェクト(データのフォルダ)側には置かない: 認証情報をプロジェクトの git に入れないため
33
- */
34
- export async function openProject(
35
- dataDir: string,
36
- opts: { repos?: Record<string, string>; settings?: MachineSettings | SettingsSource; projectName?: string; chatgpt?: ChatGptAccount } = {},
37
- ): Promise<P3Context> {
38
- // データのフォルダと project.yaml が無ければ、空のプロジェクトとして開かずに止める(何も作らない)
39
- await checkDataDir(dataDir, opts.projectName);
40
- const source = !opts.settings ? machineSettingsSource() : "get" in opts.settings ? opts.settings : fixedSettings(opts.settings);
41
- // 初めの値(画面の表示の既定エンジン)。読めなくても開ける(Preflight を始めるときに設定のエラーとして知らせる)
42
- const initial = await source.get().catch(() => undefined);
43
- const ws = new Workspace(dataDir, opts.repos);
44
- await ws.load();
45
- // 既定は Codex(ChatGPT プランか旧来の auth.json。どちらも無ければ使えない理由と次にすることを出す)。
46
- // Mock は preflight.engine: mock(P3_PREFLIGHT_ENGINE=mock)か --engine mock で明示したときだけ(認証の失敗を Mock の成功に見せない)
47
- // プロジェクトを跨ぐ serve では、サインインの待ち受けを全プロジェクトで1つにするため外から渡す
48
- const chatgpt = opts.chatgpt ?? chatgptAccount();
49
- const codex = new CodexWorkspaceEngine({ load: async () => codexConfig(await source.get()), account: chatgpt });
50
- const engines: Partial<Record<PreflightEngine["name"], PreflightEngine>> = { codex, mock: new MockEngine() };
51
- const preflight = new PreflightService(ws, engines, {
52
- initial: initial?.preflight.engine ?? "codex",
53
- load: async () => (await source.get()).preflight.engine,
54
- });
55
- // 要約の生成も Preflight と同じ接続と既定のエンジン(preflight.engine)を使う
56
- const releaseGenerator = new ReleaseGenerator(ws, { codex, mock: new MockSummarizer() }, { engine: async () => (await source.get()).preflight.engine });
57
- return { ws, preflight, releaseGenerator, chatgpt, projectName: opts.projectName };
58
- }
@@ -1,207 +0,0 @@
1
- import { isAbsolute } from "node:path";
2
- import { loadUserSettings, userConfigPath, UserConfigError, type UserConfig } from "./userConfig.ts";
3
-
4
- /**
5
- * マシンごとの設定(Codex の認証・パスの対応・Preflight の既定エンジン・serve の待ち受け)。
6
- *
7
- * 決め方(項目ごと): CLI の明示(--port / --host / --engine)→ 環境変数(P3_*)→ 個人設定(config.yaml)→ 既定値。
8
- * - 環境変数を空(P3_CODEX_MODEL=)にすると、個人設定の値を使わずに既定値に戻す(解除)
9
- * - 読めない値は黙って捨てず、どこの何を直せばよいかをエラーにする
10
- *
11
- * 個人設定(~/.config/infodb-p3/config.yaml)の書き方:
12
- *
13
- * codex:
14
- * auth: auto # auto(ChatGPT に接続していれば ChatGPT、無ければ旧来)/ legacy(旧来の auth.json を使う)
15
- * authVolume: codex-state # 旧来: auth.json を入れた Docker ボリューム
16
- * authFile: /home/me/.codex/auth.json # 旧来: ホストの auth.json(authVolume とどちらか)
17
- * pathMap: # このマシンのパス → Docker デーモンから見たパス(DevContainer のとき)
18
- * /workspaces: /home/me/workspaces
19
- * model: gpt-5.5
20
- * effort: medium
21
- * ensureImage: true # false で、Preflight の前のイメージの作り直し(1日ごと)を止める
22
- * preflight:
23
- * engine: codex # codex / mock
24
- * serve:
25
- * host: 0.0.0.0
26
- * port: 4310
27
- *
28
- * ChatGPT のトークンはここに置かない(chatgpt.json。所有者だけが読める権限)。
29
- * P3_ACTOR・P3_REQUEST は操作ごとの指定なので、環境変数(と --actor / --req)だけで決める。
30
- */
31
- export interface MachineSettings {
32
- codex: {
33
- auth: CodexAuthChoice;
34
- authVolume?: string;
35
- authFile?: string;
36
- pathMap: [string, string][];
37
- model?: string;
38
- effort?: string;
39
- ensureImage: boolean;
40
- };
41
- preflight: { engine: EngineChoice };
42
- serve: { host: string; port: number };
43
- }
44
-
45
- export type CodexAuthChoice = "auto" | "legacy";
46
- export type EngineChoice = "codex" | "mock";
47
-
48
- /** 環境変数と個人設定の対応(docs/installation.md の「設定の決まり」の表と同じ) */
49
- export const SETTING_KEYS = {
50
- "codex.auth": "P3_CODEX_AUTH",
51
- "codex.authVolume": "P3_CODEX_AUTH_VOLUME",
52
- "codex.authFile": "P3_CODEX_AUTH_FILE",
53
- "codex.pathMap": "P3_CODEX_PATH_MAP",
54
- "codex.model": "P3_CODEX_MODEL",
55
- "codex.effort": "P3_CODEX_EFFORT",
56
- "codex.ensureImage": "P3_CODEX_ENSURE_IMAGE",
57
- "preflight.engine": "P3_PREFLIGHT_ENGINE",
58
- "serve.host": "P3_HOST",
59
- "serve.port": "P3_PORT",
60
- } as const;
61
- type Key = keyof typeof SETTING_KEYS;
62
-
63
- export const DEFAULT_SETTINGS: MachineSettings = {
64
- codex: { auth: "auto", pathMap: [], ensureImage: true },
65
- preflight: { engine: "codex" },
66
- serve: { host: "0.0.0.0", port: 4310 },
67
- };
68
-
69
- /** 設定の値が読めない(CLI は使い方の誤りと同じく終了コード 1)。configPath: 読んだ個人設定のファイル(共有の記録から外すため) */
70
- export class SettingsError extends Error {
71
- configPath?: string;
72
- }
73
-
74
- export interface SettingsOverrides {
75
- host?: string;
76
- port?: string;
77
- }
78
-
79
- type Env = Record<string, string | undefined>;
80
-
81
- /** どこから来た値か(エラーの案内に使う) */
82
- type Raw = { value: unknown; from: string } | { value: undefined; from: "default" };
83
-
84
- /**
85
- * マシンごとの設定を、呼ぶたびに読み直す(serve を起動し直さずに、個人設定の変更を次の Preflight から効かせる)。
86
- * 読めなければ SettingsError(直すファイルと項目を添える)。CLI の明示(--port / --host)は起動のときの値のまま渡す
87
- */
88
- export interface SettingsSource {
89
- get(): Promise<MachineSettings>;
90
- /** 個人設定のファイル(案内に出す) */
91
- path: string;
92
- }
93
-
94
- export function machineSettingsSource(opts: { path?: string; env?: Env; cli?: SettingsOverrides } = {}): SettingsSource {
95
- const path = opts.path ?? userConfigPath();
96
- return {
97
- path,
98
- async get() {
99
- try {
100
- return resolveMachineSettings(await loadUserSettings(path), opts.env ?? process.env, opts.cli ?? {});
101
- } catch (e) {
102
- const err =
103
- e instanceof UserConfigError
104
- ? new SettingsError(e.message)
105
- : e instanceof SettingsError && e.message.includes("個人設定")
106
- ? new SettingsError(`${e.message}(${path})`)
107
- : e;
108
- if (err instanceof SettingsError) err.configPath = path;
109
- throw err;
110
- }
111
- },
112
- };
113
- }
114
-
115
- /** 決まった設定(テストや、起動のときに一度だけ決めたいとき) */
116
- export const fixedSettings = (settings: MachineSettings, path = userConfigPath()): SettingsSource => ({ path, get: async () => settings });
117
-
118
- export function resolveMachineSettings(user: Pick<UserConfig, "settings">, env: Env = process.env, cli: SettingsOverrides = {}): MachineSettings {
119
- const pick = (key: Key, flag?: string): Raw => {
120
- if (flag !== undefined) return { value: flag, from: `--${key.split(".")[1]}` };
121
- const name = SETTING_KEYS[key];
122
- const e = env[name];
123
- if (e !== undefined) return e === "" ? { value: undefined, from: "default" } : { value: e, from: `環境変数 ${name}` };
124
- const [section, field] = key.split(".") as [keyof UserConfig["settings"], string];
125
- const v = user.settings[section]?.[field];
126
- return v === undefined || v === null || v === "" ? { value: undefined, from: "default" } : { value: v, from: `個人設定 ${key}` };
127
- };
128
- const text = (key: Key): string | undefined => {
129
- const r = pick(key);
130
- if (r.value === undefined) return undefined;
131
- if (typeof r.value !== "string" && typeof r.value !== "number") throw new SettingsError(`${r.from} は文字列で指定してください`);
132
- return String(r.value);
133
- };
134
- const oneOf = <T extends string>(key: Key, choices: readonly T[], def: T): T => {
135
- const v = text(key);
136
- if (v === undefined) return def;
137
- if (!(choices as readonly string[]).includes(v)) throw new SettingsError(`${pick(key).from} が読めません: ${v}(${choices.join(" / ")})`);
138
- return v as T;
139
- };
140
-
141
- const ensure = pick("codex.ensureImage");
142
- const port = pick("serve.port", cli.port);
143
- const host = pick("serve.host", cli.host);
144
- return {
145
- codex: {
146
- auth: oneOf("codex.auth", ["auto", "legacy"] as const, DEFAULT_SETTINGS.codex.auth),
147
- authVolume: text("codex.authVolume"),
148
- authFile: text("codex.authFile"),
149
- pathMap: parsePathMap(pick("codex.pathMap")),
150
- model: text("codex.model"),
151
- effort: text("codex.effort"),
152
- ensureImage: ensure.value === undefined ? DEFAULT_SETTINGS.codex.ensureImage : parseBool(ensure),
153
- },
154
- preflight: { engine: oneOf("preflight.engine", ["codex", "mock"] as const, DEFAULT_SETTINGS.preflight.engine) },
155
- serve: {
156
- host: host.value === undefined ? DEFAULT_SETTINGS.serve.host : String(host.value),
157
- port: port.value === undefined ? DEFAULT_SETTINGS.serve.port : parsePort(port),
158
- },
159
- };
160
- }
161
-
162
- function parseBool(r: Raw): boolean {
163
- if (typeof r.value === "boolean") return r.value;
164
- const v = String(r.value).toLowerCase();
165
- if (["1", "true", "yes", "on"].includes(v)) return true;
166
- if (["0", "false", "no", "off"].includes(v)) return false;
167
- throw new SettingsError(`${r.from} が読めません: ${String(r.value)}(true / false。環境変数なら 1 / 0 も可)`);
168
- }
169
-
170
- function parsePort(r: Raw): number {
171
- const n = Number(r.value);
172
- if (!Number.isInteger(n) || n < 1 || n > 65535) throw new SettingsError(`${r.from} が読めません: ${String(r.value)}(1〜65535 のポート番号)`);
173
- return n;
174
- }
175
-
176
- const PATH_MAP_HINT =
177
- "個人設定は p3 user-config set codex.pathMap+=<このマシンのパス>=<Docker デーモンから見たパス> で1件ずつ。環境変数は <このマシンのパス>=<Docker デーモンから見たパス> をカンマ区切りで。例: /workspaces=/home/me/workspaces";
178
-
179
- /** "ローカル=ホスト,..."(環境変数)か { ローカル: ホスト }(個人設定)。どちらも絶対パス */
180
- function parsePathMap(r: Raw): [string, string][] {
181
- if (r.value === undefined) return [];
182
- let pairs: [string, string][];
183
- if (typeof r.value === "string") {
184
- pairs = r.value
185
- .split(",")
186
- .map((s) => s.trim())
187
- .filter(Boolean)
188
- .map((s) => {
189
- const at = s.indexOf("=");
190
- if (at < 0) throw new SettingsError(`${r.from} の「${s}」が読めません(${PATH_MAP_HINT})`);
191
- return [s.slice(0, at).trim(), s.slice(at + 1).trim()];
192
- });
193
- } else if (typeof r.value === "object" && !Array.isArray(r.value)) {
194
- pairs = Object.entries(r.value as Record<string, unknown>).map(([k, v]) => {
195
- if (typeof v !== "string") throw new SettingsError(`${r.from} の「${k}」の値はパスの文字列で指定してください`);
196
- return [k, v];
197
- });
198
- } else {
199
- throw new SettingsError(`${r.from} は「このマシンのパス: Docker デーモンから見たパス」の対応で指定してください`);
200
- }
201
- for (const [local, host] of pairs) {
202
- if (!isAbsolute(local) || !host || !(isAbsolute(host) || /^[A-Za-z]:[\\/]/.test(host))) {
203
- throw new SettingsError(`${r.from} の「${local}=${host}」が読めません。どちらも絶対パスにしてください(${PATH_MAP_HINT})`);
204
- }
205
- }
206
- return pairs;
207
- }
@@ -1,156 +0,0 @@
1
- import YAML from "yaml";
2
- import { DEFAULT_SETTINGS, resolveMachineSettings, SETTING_KEYS, SettingsError, type MachineSettings } from "./machineSettings.ts";
3
- import { normalizeUserConfig, updateUserConfig, userConfigPath, type UserConfig } from "./userConfig.ts";
4
-
5
- /**
6
- * 個人設定のマシンごとの設定(codex / preflight / serve)を変える(p3 user-config set)。
7
- *
8
- * キー=値 その項目を書く(ensureImage は true / false、port は数で書く)
9
- * キー= その項目を消す(既定値に戻す)
10
- * codex.pathMap+=A=B パスの対応を1件足す(同じ A があれば置き換える)
11
- * codex.pathMap-=A パスの対応を1件外す
12
- * codex.pathMap= パスの対応を全部外す
13
- *
14
- * 書いた後の内容を読むときと同じ規則(resolveMachineSettings)で確かめ、読めなければ書かない。
15
- * コメントとほかの項目は残す。
16
- */
17
- export class SettingsInputError extends Error {}
18
-
19
- export type SettingKey = keyof typeof SETTING_KEYS;
20
- export const SETTING_KEY_LIST = Object.keys(SETTING_KEYS) as SettingKey[];
21
-
22
- export type SettingChange =
23
- | { kind: "set"; key: SettingKey; value: string }
24
- | { kind: "unset"; key: SettingKey }
25
- | { kind: "mapAdd"; local: string; host: string }
26
- | { kind: "mapRemove"; local: string };
27
-
28
- const isKey = (k: string): k is SettingKey => (SETTING_KEY_LIST as string[]).includes(k);
29
-
30
- /** 「キー=値」「codex.pathMap+=A=B」「codex.pathMap-=A」を読む */
31
- export function parseSettingChange(pair: string): SettingChange {
32
- const add = pair.match(/^codex\.pathMap\+=(.*)$/s);
33
- if (add) {
34
- const at = add[1].indexOf("=");
35
- if (at < 1) throw new SettingsInputError(`「${pair}」が読めません。codex.pathMap+=<このマシンのパス>=<Docker デーモンから見たパス>(例: codex.pathMap+=/workspaces=/home/me/workspaces)`);
36
- return { kind: "mapAdd", local: add[1].slice(0, at).trim(), host: add[1].slice(at + 1).trim() };
37
- }
38
- const remove = pair.match(/^codex\.pathMap-=(.*)$/s);
39
- if (remove) {
40
- if (!remove[1].trim()) throw new SettingsInputError("codex.pathMap-=<このマシンのパス> で外す対応を指定してください");
41
- return { kind: "mapRemove", local: remove[1].trim() };
42
- }
43
- const eq = pair.indexOf("=");
44
- const key = eq > 0 ? pair.slice(0, eq) : pair;
45
- if (!isKey(key)) throw new SettingsInputError(`変更できるキー: ui.theme ${SETTING_KEY_LIST.join(" ")}`);
46
- if (eq < 0) throw new SettingsInputError(`${key}=<値> で指定してください(${key}= で消す)`);
47
- const value = pair.slice(eq + 1).trim();
48
- if (key === "codex.pathMap" && value) {
49
- throw new SettingsInputError("パスの対応は1件ずつ codex.pathMap+=<このマシンのパス>=<Docker デーモンから見たパス> で足し、codex.pathMap-=<このマシンのパス> で外してください(codex.pathMap= で全部外す)");
50
- }
51
- return value ? { kind: "set", key, value } : { kind: "unset", key };
52
- }
53
-
54
- /** YAML に書く形(読むときと同じ型にそろえる) */
55
- function typed(key: SettingKey, value: string): unknown {
56
- if (key === "codex.ensureImage") {
57
- const v = value.toLowerCase();
58
- if (["true", "1", "yes", "on"].includes(v)) return true;
59
- if (["false", "0", "no", "off"].includes(v)) return false;
60
- throw new SettingsInputError(`codex.ensureImage は true か false: ${value}`);
61
- }
62
- if (key === "serve.port") {
63
- const n = Number(value);
64
- if (!Number.isInteger(n) || n < 1 || n > 65535) throw new SettingsInputError(`serve.port は 1〜65535 のポート番号: ${value}`);
65
- return n;
66
- }
67
- return value;
68
- }
69
-
70
- function ensureMap(doc: YAML.Document, path: string[]) {
71
- for (let i = 1; i <= path.length; i++) {
72
- const at = path.slice(0, i);
73
- if (!YAML.isMap(doc.getIn(at))) doc.setIn(at, doc.createNode({}));
74
- }
75
- }
76
-
77
- /** 空になった項目(codex: {} など)を消す */
78
- function dropEmpty(doc: YAML.Document, path: string[]) {
79
- for (let i = path.length; i >= 1; i--) {
80
- const node = doc.getIn(path.slice(0, i));
81
- if (YAML.isMap(node) && !node.items.length) doc.deleteIn(path.slice(0, i));
82
- }
83
- }
84
-
85
- export function applySettingChange(doc: YAML.Document, c: SettingChange) {
86
- if (c.kind === "mapAdd") {
87
- ensureMap(doc, ["codex", "pathMap"]);
88
- doc.setIn(["codex", "pathMap", c.local], c.host);
89
- } else if (c.kind === "mapRemove") {
90
- if (!doc.hasIn(["codex", "pathMap", c.local])) throw new SettingsInputError(`codex.pathMap に「${c.local}」の対応はありません`);
91
- doc.deleteIn(["codex", "pathMap", c.local]);
92
- dropEmpty(doc, ["codex", "pathMap"]);
93
- } else {
94
- const path = c.key.split(".");
95
- if (c.kind === "unset") {
96
- doc.deleteIn(path);
97
- dropEmpty(doc, path.slice(0, -1));
98
- } else {
99
- ensureMap(doc, path.slice(0, -1));
100
- doc.setIn(path, typed(c.key, c.value));
101
- }
102
- }
103
- }
104
-
105
- /** 変更をまとめて書く。どれか1つでも読めなければ何も書かない。書いた後の個人設定の値を返す */
106
- export async function writeMachineSettings(changes: SettingChange[], path = userConfigPath()): Promise<MachineSettings> {
107
- return updateUserConfig((doc) => {
108
- for (const c of changes) applySettingChange(doc, c);
109
- try {
110
- // 環境変数は見ずに、個人設定に書いた値だけで確かめる
111
- return resolveMachineSettings(normalizeUserConfig(doc.toJS() ?? {}), {});
112
- } catch (e) {
113
- if (e instanceof SettingsError) throw new SettingsInputError(`${e.message}(書いていません)`);
114
- throw e;
115
- }
116
- }, path);
117
- }
118
-
119
- export interface SettingRow {
120
- key: SettingKey;
121
- /** 効いている値(表示用の文字列) */
122
- value: string;
123
- /** どこから来たか */
124
- from: "環境変数" | "個人設定" | "既定";
125
- env: string;
126
- }
127
-
128
- const show = (v: unknown): string => (v === undefined ? "(なし)" : typeof v === "object" ? JSON.stringify(v) : String(v));
129
-
130
- /** 項目ごとの効いている値と出どころ。読めない値があれば error に理由(行は書かれたままの値で出す) */
131
- export function describeSettings(user: Pick<UserConfig, "settings">, env: Record<string, string | undefined>): { rows: SettingRow[]; resolved?: MachineSettings; error?: string } {
132
- let resolved: MachineSettings | undefined;
133
- let error: string | undefined;
134
- try {
135
- resolved = resolveMachineSettings(user, env);
136
- } catch (e) {
137
- error = (e as Error).message;
138
- }
139
- const rows = SETTING_KEY_LIST.map((key): SettingRow => {
140
- const name = SETTING_KEYS[key];
141
- const [section, field] = key.split(".") as [keyof UserConfig["settings"], string];
142
- const written = user.settings[section]?.[field];
143
- // 空の環境変数は個人設定を使わずに既定値に戻す(resolveMachineSettings と同じ)
144
- const from: SettingRow["from"] =
145
- env[name] !== undefined ? (env[name] === "" ? "既定" : "環境変数") : written !== undefined && written !== null && written !== "" ? "個人設定" : "既定";
146
- const effective = resolved ? (resolved as unknown as Record<string, Record<string, unknown>>)[section][field] : from === "環境変数" ? env[name] : written;
147
- const def = (DEFAULT_SETTINGS as unknown as Record<string, Record<string, unknown>>)[section][field];
148
- let value: string;
149
- if (key === "codex.pathMap") {
150
- const pairs = (Array.isArray(effective) ? effective : []) as [string, string][];
151
- value = pairs.length ? pairs.map(([l, h]) => `${l} → ${h}`).join(", ") : resolved ? "(なし)" : show(effective);
152
- } else value = show(effective ?? def);
153
- return { key, value, from, env: name };
154
- });
155
- return { rows, resolved, error };
156
- }