@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,148 @@
1
+ import YAML from "yaml";
2
+ import { DEFAULT_SETTINGS, resolveMachineSettings, SETTING_KEYS, SettingsError } from "./machineSettings.js";
3
+ import { normalizeUserConfig, updateUserConfig, userConfigPath } from "./userConfig.js";
4
+ /**
5
+ * 個人設定のマシンごとの設定(codex / preflight / serve)を変える(p3 user-config set)。
6
+ *
7
+ * キー=値 その項目を書く(ensureImage は true / false、port は数で書く)
8
+ * キー= その項目を消す(既定値に戻す)
9
+ * codex.pathMap+=A=B パスの対応を1件足す(同じ A があれば置き換える)
10
+ * codex.pathMap-=A パスの対応を1件外す
11
+ * codex.pathMap= パスの対応を全部外す
12
+ *
13
+ * 書いた後の内容を読むときと同じ規則(resolveMachineSettings)で確かめ、読めなければ書かない。
14
+ * コメントとほかの項目は残す。
15
+ */
16
+ export class SettingsInputError extends Error {
17
+ }
18
+ export const SETTING_KEY_LIST = Object.keys(SETTING_KEYS);
19
+ const isKey = (k) => SETTING_KEY_LIST.includes(k);
20
+ /** 「キー=値」「codex.pathMap+=A=B」「codex.pathMap-=A」を読む */
21
+ export function parseSettingChange(pair) {
22
+ const add = pair.match(/^codex\.pathMap\+=(.*)$/s);
23
+ if (add) {
24
+ const at = add[1].indexOf("=");
25
+ if (at < 1)
26
+ throw new SettingsInputError(`「${pair}」が読めません。codex.pathMap+=<このマシンのパス>=<Docker デーモンから見たパス>(例: codex.pathMap+=/workspaces=/home/me/workspaces)`);
27
+ return { kind: "mapAdd", local: add[1].slice(0, at).trim(), host: add[1].slice(at + 1).trim() };
28
+ }
29
+ const remove = pair.match(/^codex\.pathMap-=(.*)$/s);
30
+ if (remove) {
31
+ if (!remove[1].trim())
32
+ throw new SettingsInputError("codex.pathMap-=<このマシンのパス> で外す対応を指定してください");
33
+ return { kind: "mapRemove", local: remove[1].trim() };
34
+ }
35
+ const eq = pair.indexOf("=");
36
+ const key = eq > 0 ? pair.slice(0, eq) : pair;
37
+ if (!isKey(key))
38
+ throw new SettingsInputError(`変更できるキー: ui.theme ${SETTING_KEY_LIST.join(" ")}`);
39
+ if (eq < 0)
40
+ throw new SettingsInputError(`${key}=<値> で指定してください(${key}= で消す)`);
41
+ const value = pair.slice(eq + 1).trim();
42
+ if (key === "codex.pathMap" && value) {
43
+ throw new SettingsInputError("パスの対応は1件ずつ codex.pathMap+=<このマシンのパス>=<Docker デーモンから見たパス> で足し、codex.pathMap-=<このマシンのパス> で外してください(codex.pathMap= で全部外す)");
44
+ }
45
+ return value ? { kind: "set", key, value } : { kind: "unset", key };
46
+ }
47
+ /** YAML に書く形(読むときと同じ型にそろえる) */
48
+ function typed(key, value) {
49
+ if (key === "codex.ensureImage") {
50
+ const v = value.toLowerCase();
51
+ if (["true", "1", "yes", "on"].includes(v))
52
+ return true;
53
+ if (["false", "0", "no", "off"].includes(v))
54
+ return false;
55
+ throw new SettingsInputError(`codex.ensureImage は true か false: ${value}`);
56
+ }
57
+ if (key === "serve.port") {
58
+ const n = Number(value);
59
+ if (!Number.isInteger(n) || n < 1 || n > 65535)
60
+ throw new SettingsInputError(`serve.port は 1〜65535 のポート番号: ${value}`);
61
+ return n;
62
+ }
63
+ return value;
64
+ }
65
+ function ensureMap(doc, path) {
66
+ for (let i = 1; i <= path.length; i++) {
67
+ const at = path.slice(0, i);
68
+ if (!YAML.isMap(doc.getIn(at)))
69
+ doc.setIn(at, doc.createNode({}));
70
+ }
71
+ }
72
+ /** 空になった項目(codex: {} など)を消す */
73
+ function dropEmpty(doc, path) {
74
+ for (let i = path.length; i >= 1; i--) {
75
+ const node = doc.getIn(path.slice(0, i));
76
+ if (YAML.isMap(node) && !node.items.length)
77
+ doc.deleteIn(path.slice(0, i));
78
+ }
79
+ }
80
+ export function applySettingChange(doc, c) {
81
+ if (c.kind === "mapAdd") {
82
+ ensureMap(doc, ["codex", "pathMap"]);
83
+ doc.setIn(["codex", "pathMap", c.local], c.host);
84
+ }
85
+ else if (c.kind === "mapRemove") {
86
+ if (!doc.hasIn(["codex", "pathMap", c.local]))
87
+ throw new SettingsInputError(`codex.pathMap に「${c.local}」の対応はありません`);
88
+ doc.deleteIn(["codex", "pathMap", c.local]);
89
+ dropEmpty(doc, ["codex", "pathMap"]);
90
+ }
91
+ else {
92
+ const path = c.key.split(".");
93
+ if (c.kind === "unset") {
94
+ doc.deleteIn(path);
95
+ dropEmpty(doc, path.slice(0, -1));
96
+ }
97
+ else {
98
+ ensureMap(doc, path.slice(0, -1));
99
+ doc.setIn(path, typed(c.key, c.value));
100
+ }
101
+ }
102
+ }
103
+ /** 変更をまとめて書く。どれか1つでも読めなければ何も書かない。書いた後の個人設定の値を返す */
104
+ export async function writeMachineSettings(changes, path = userConfigPath()) {
105
+ return updateUserConfig((doc) => {
106
+ for (const c of changes)
107
+ applySettingChange(doc, c);
108
+ try {
109
+ // 環境変数は見ずに、個人設定に書いた値だけで確かめる
110
+ return resolveMachineSettings(normalizeUserConfig(doc.toJS() ?? {}), {});
111
+ }
112
+ catch (e) {
113
+ if (e instanceof SettingsError)
114
+ throw new SettingsInputError(`${e.message}(書いていません)`);
115
+ throw e;
116
+ }
117
+ }, path);
118
+ }
119
+ const show = (v) => (v === undefined ? "(なし)" : typeof v === "object" ? JSON.stringify(v) : String(v));
120
+ /** 項目ごとの効いている値と出どころ。読めない値があれば error に理由(行は書かれたままの値で出す) */
121
+ export function describeSettings(user, env) {
122
+ let resolved;
123
+ let error;
124
+ try {
125
+ resolved = resolveMachineSettings(user, env);
126
+ }
127
+ catch (e) {
128
+ error = e.message;
129
+ }
130
+ const rows = SETTING_KEY_LIST.map((key) => {
131
+ const name = SETTING_KEYS[key];
132
+ const [section, field] = key.split(".");
133
+ const written = user.settings[section]?.[field];
134
+ // 空の環境変数は個人設定を使わずに既定値に戻す(resolveMachineSettings と同じ)
135
+ const from = env[name] !== undefined ? (env[name] === "" ? "既定" : "環境変数") : written !== undefined && written !== null && written !== "" ? "個人設定" : "既定";
136
+ const effective = resolved ? resolved[section][field] : from === "環境変数" ? env[name] : written;
137
+ const def = DEFAULT_SETTINGS[section][field];
138
+ let value;
139
+ if (key === "codex.pathMap") {
140
+ const pairs = (Array.isArray(effective) ? effective : []);
141
+ value = pairs.length ? pairs.map(([l, h]) => `${l} → ${h}`).join(", ") : resolved ? "(なし)" : show(effective);
142
+ }
143
+ else
144
+ value = show(effective ?? def);
145
+ return { key, value, from, env: name };
146
+ });
147
+ return { rows, resolved, error };
148
+ }
@@ -0,0 +1,120 @@
1
+ import { normalizeTaskId } from "../shared/refs.js";
2
+ import { REQUEST_STATUSES, TASK_STATUSES } from "../shared/types.js";
3
+ import { hierarchyNow } from "./requestStatus.js";
4
+ export function listTasks({ ws }, f = {}) {
5
+ let tasks = f.request ? ws.tasksOf(f.request).list() : ws.allTasks();
6
+ if (f.status?.length)
7
+ tasks = tasks.filter((t) => f.status.includes(t.status));
8
+ if (f.area)
9
+ tasks = tasks.filter((t) => t.areas.some((a) => a.startsWith(f.area)));
10
+ // 作業先で絞る(none は作業先なし)
11
+ if (f.repo !== undefined)
12
+ tasks = tasks.filter((t) => (t.repo ?? null) === (f.repo === "none" ? null : f.repo));
13
+ if (f.q) {
14
+ const q = f.q.toLowerCase();
15
+ tasks = tasks.filter((t) => `${t.ref} ${t.title} ${t.body}`.toLowerCase().includes(q));
16
+ }
17
+ return tasks;
18
+ }
19
+ /**
20
+ * 要望の ID を短い書き方からも解く: 完全な ID、乱数部分(k7m3x)、ID の先頭・末尾の一部(一意なときだけ)。
21
+ */
22
+ export function resolveRequestId({ ws }, raw) {
23
+ const s = raw.trim().toLowerCase();
24
+ if (!s)
25
+ return undefined;
26
+ if (ws.requests.get(s))
27
+ return s;
28
+ if (s.length < 3)
29
+ return undefined;
30
+ const hits = ws.requests.list().filter((r) => r.id.startsWith(s) || r.id.endsWith(s));
31
+ return hits.length === 1 ? hits[0].id : undefined;
32
+ }
33
+ /**
34
+ * 参照を絶対参照に解く。存在しなければ undefined。
35
+ * "<要望>/T3" "<要望>" — 要望は短い書き方でもよい
36
+ * "T3" / "3" — current(今の要望)の中のタスク
37
+ */
38
+ export function resolveRef(ctx, raw, current) {
39
+ const s = raw.trim();
40
+ const [head, tail] = s.split("/", 2);
41
+ if (tail !== undefined) {
42
+ const rid = resolveRequestId(ctx, head);
43
+ const tid = normalizeTaskId(tail);
44
+ return rid && tid && ctx.ws.tasksOf(rid).get(tid) ? `${rid}/${tid}` : undefined;
45
+ }
46
+ const tid = normalizeTaskId(s);
47
+ if (tid && current)
48
+ return ctx.ws.tasksOf(current).get(tid) ? `${current}/${tid}` : undefined;
49
+ return resolveRequestId(ctx, s);
50
+ }
51
+ /** 参照・タイトル・自然文から対象を特定する。参照の一致 → タイトル部分一致 → 内容類似 */
52
+ export function resolve(ctx, q, current) {
53
+ const query = q.trim();
54
+ const exact = query ? resolveRef(ctx, query, current) : undefined;
55
+ if (exact)
56
+ return { match: exact, candidates: [{ ref: exact, title: titleOf(ctx, exact), score: 1, reasons: ["参照が一致"] }] };
57
+ const items = [
58
+ ...ctx.ws.requests.list().map((r) => ({ ref: r.id, title: r.title, request: r.id })),
59
+ ...ctx.ws.allTasks().map((t) => ({ ref: t.ref, title: t.title, request: t.request })),
60
+ ];
61
+ const byTitle = items
62
+ .filter((t) => query && t.title.toLowerCase().includes(query.toLowerCase()))
63
+ // 今の要望の中のものを先に
64
+ .sort((a, b) => Number(b.request === current) - Number(a.request === current))
65
+ .map((t) => ({ ref: t.ref, title: t.title, score: 0.9, reasons: ["タイトルに含む"] }));
66
+ const candidates = byTitle.slice(0, 8);
67
+ return { match: candidates.length === 1 ? candidates[0].ref : null, candidates };
68
+ }
69
+ export function titleOf({ ws }, ref) {
70
+ return ws.task(ref)?.title ?? ws.requests.get(ref)?.title ?? "?";
71
+ }
72
+ /**
73
+ * 要望ごとの進捗。進捗の画面と `p3 progress` で使う。
74
+ * 並び: 最終更新(要望自身と、アーカイブしていないタスクの updatedAt の最大)の新しい順。同じ日時なら要望 ID の順。
75
+ */
76
+ export function progress(ctx) {
77
+ const h = hierarchyNow(ctx.ws);
78
+ const zero = () => Object.fromEntries(TASK_STATUSES.map((s) => [s, 0]));
79
+ return ctx.ws.requests
80
+ .list()
81
+ .map((request) => {
82
+ const tasks = ctx.ws.tasksOf(request.id).list();
83
+ const counts = zero();
84
+ for (const t of tasks)
85
+ counts[t.status]++;
86
+ const done = tasks.filter((t) => t.status === "done");
87
+ // 配下: 自分と子孫(循環しても1回ずつ)
88
+ const below = h.descendants(request.id);
89
+ const sub = { counts: zero(), total: 0, done: 0, requests: Object.fromEntries(REQUEST_STATUSES.map((s) => [s, 0])) };
90
+ const stamps = [request.updatedAt, ...tasks.map((t) => t.updatedAt)];
91
+ for (const r of [request, ...below]) {
92
+ if (r !== request) {
93
+ sub.requests[r.status]++;
94
+ stamps.push(r.updatedAt);
95
+ }
96
+ for (const t of ctx.ws.tasksOf(r.id).list()) {
97
+ sub.counts[t.status]++;
98
+ sub.total++;
99
+ if (t.status === "done")
100
+ sub.done++;
101
+ if (r !== request)
102
+ stamps.push(t.updatedAt);
103
+ }
104
+ }
105
+ return {
106
+ request,
107
+ tasks: tasks.map(({ id, ref, title, status, createdAt, startedAt, doneAt, checkedAt }) => ({ id, ref, title, status, createdAt, startedAt, doneAt, checkedAt })),
108
+ counts,
109
+ total: tasks.length,
110
+ done: done.length,
111
+ updatedAt: stamps.sort().at(-1),
112
+ children: h.children(request.id).map((c) => c.id),
113
+ subtree: sub,
114
+ hierarchyIssues: h.issuesAround(request.id),
115
+ };
116
+ })
117
+ .sort((a, b) => b.updatedAt.localeCompare(a.updatedAt) || byId(a.request.id, b.request.id));
118
+ }
119
+ /** ID の順(数を含む部分は数として比べる: T2 < T10) */
120
+ const byId = (a, b) => a.localeCompare(b, undefined, { numeric: true });
@@ -0,0 +1,105 @@
1
+ import { compareInput, runInput } from "./input.js";
2
+ import { changedLabel } from "../../shared/preflightInput.js";
3
+ /**
4
+ * 引き継ぐものを選ぶ。
5
+ * - 前回: 直近の run が completed で評価を読めるときだけ。失敗・欠損なら、古い成功 run に戻らず「前回なし」
6
+ * - メモ: 前回を引き継ぐなら、前回までの引き継ぎの経路(previous を辿った run)で渡し済みのものを除く。
7
+ * 失敗した run に渡しただけのメモは渡し済みにしない。前回を引き継がないなら全部渡す
8
+ */
9
+ export async function selectCarryover(ws, requestId) {
10
+ const runs = await ws.preflight.list(requestId);
11
+ const latest = runs[0];
12
+ const { notes, invalid } = await ws.notes.list(requestId);
13
+ let previous;
14
+ let previousSkipped;
15
+ if (latest) {
16
+ if (latest.status !== "completed")
17
+ previousSkipped = `直近の ${latest.id} が${latest.status === "failed" ? "失敗" : "実行中"}のため`;
18
+ else if (!latest.assessment)
19
+ previousSkipped = `直近の ${latest.id} に評価がないため`;
20
+ else
21
+ previous = latest;
22
+ }
23
+ const used = new Set();
24
+ const seen = new Set();
25
+ for (let r = previous; r && !seen.has(r.id); r = r.previous ? runs.find((x) => x.id === r.previous) : undefined) {
26
+ seen.add(r.id);
27
+ for (const n of r.notes ?? [])
28
+ used.add(n);
29
+ }
30
+ let requestChange;
31
+ if (previous) {
32
+ const before = await runInput(previous, ws.preflight.runDir(requestId, previous.id));
33
+ const match = compareInput(before, ws.requests.require(requestId));
34
+ if (match.status !== "same")
35
+ requestChange = { match, ...("error" in before ? {} : { before }) };
36
+ }
37
+ return { previous, previousSkipped, notes: notes.filter((n) => !used.has(n.id)), invalidNotes: invalid, ...(requestChange ? { requestChange } : {}) };
38
+ }
39
+ /** 前回の評価のあとの要望の変更。今の要望を基準にし、前回の評価・案・メモとの食い違いは確認事項にさせる */
40
+ function requestChangeSection(c, previousId) {
41
+ const quote = (s) => (s ? s.split("\n").map((l) => `> ${l}`).join("\n") : "> (空)");
42
+ const head = "## 前回の評価のあとで変わった要望(評価の基準は今の要望。前回の評価・タスク案・メモと食い違う点は確認事項に)";
43
+ if (c.match.status === "unknown" || !c.before) {
44
+ return `${head}\n前回 ${previousId} が何を評価したか確かめられません(${c.match.reason ?? "不明"})。前回の評価は今の要望に合っていないものとして扱ってください。`;
45
+ }
46
+ const parts = [head, `前回 ${previousId} の後で、要望の${changedLabel(c.match.changed)}が書き換えられました。前回が評価した内容:`];
47
+ if (c.match.changed?.includes("title"))
48
+ parts.push(`### 前回の時点のタイトル\n${quote(c.before.title)}`);
49
+ if (c.match.changed?.includes("body"))
50
+ parts.push(`### 前回の時点の本文\n${quote(c.before.body)}`);
51
+ return parts.join("\n\n");
52
+ }
53
+ /**
54
+ * 前回の画面イメージ(固定した参照)。前回の提案であり、今の画面の証拠ではない。パスはデータのフォルダからの相対
55
+ * (コンテナの中では /data/ の下)。作り直すときは今回の run の ui/ に書く
56
+ */
57
+ function uiCarryover(p) {
58
+ const ui = p.ui;
59
+ const head = "## 前回の画面イメージ(前回の提案。今の画面の証拠ではありません。案を変えたら今回の ui/ に原稿を書き直す)";
60
+ if (!ui)
61
+ return `${head}
62
+ (記録なし)`;
63
+ if (ui.status === "not_needed")
64
+ return `${head}
65
+ 不要としていました(${ui.reason ?? "理由なし"})`;
66
+ const dir = `requests/${p.requestId}/preflight/${p.id}/ui`;
67
+ const items = ui.items.map((m) => `- ${m.id} ${m.title}(対象 ${m.drafts.join(", ")}${m.viewport ? ` / 幅 ${m.viewport}` : ""}): 画像 ${dir}/${m.file}${m.html ? ` / 原稿 ${dir}/${m.html}` : ""}${m.assumptions.length ? ` / 前提: ${m.assumptions.join("・")}` : ""}`);
68
+ return [head, ...(items.length ? items : ["(なし)"]), ...(ui.status === "missing" ? [`足りなかったもの: ${ui.reason ?? "不明"}`] : [])].join("\n");
69
+ }
70
+ /**
71
+ * 引き継ぐものを Markdown にする。run ディレクトリの carryover.md に固定して残し、そのままエンジンに渡す
72
+ * (前回のタスク案やメモが後から直されても、この run が何を根拠にしたかは変わらない)。
73
+ * 引き継ぐものが無ければ undefined。
74
+ */
75
+ export function renderCarryover(c) {
76
+ if (!c.previous && !c.notes.length)
77
+ return undefined;
78
+ const out = ["# 引き継ぎ"];
79
+ const p = c.previous;
80
+ if (p?.assessment) {
81
+ const a = p.assessment;
82
+ const list = (xs) => (xs.length ? xs.map((x) => `- ${x}`).join("\n") : "(なし)");
83
+ if (c.requestChange)
84
+ out.push(requestChangeSection(c.requestChange, p.id));
85
+ out.push(`## 前回の評価(${p.id})`, `判定: ${a.verdict} / 妥当性 ${a.validity.score} / 実現可能性 ${a.feasibility.score}`, a.summary, `### 確認事項\n${list(a.questions)}`, `### リスク\n${list(a.risks)}`,
86
+ // 前回の根拠は前回の時点のもの。今回の確かめた根拠としてそのまま写させない
87
+ `### 前回の根拠(前回の時点のもの。使うなら今回あらためて確かめ、確かめていなければ assumed にする)\n${a.evidence === undefined
88
+ ? "(記録なし)"
89
+ : list(a.evidence.map((e) => `${e.kind === "verified" ? "確かめた" : "推測"}: ${e.claim}${e.repo && e.file ? `(${e.repo}:${e.file}${e.location ? ` ${e.location}` : ""})` : ""}`))}`, `## 前回のタスク案(人の編集と採否を含む)`, ...(p.drafts.length
90
+ ? p.drafts.map((d) => `### ${d.key} ${d.title}(${d.include ? "採用" : "不採用"}${d.dependsOn.length ? ` / 依存: ${d.dependsOn.join(", ")}` : ""}${d.repo !== undefined ? ` / 作業先: ${d.repo ?? "なし"}` : ""})\n${d.description}`)
91
+ : [p.children ? "(なし。前回は子の要望に分ける案でした)" : "(なし)"]), ...(p.children
92
+ ? [
93
+ `## 前回の子の要望の案(人の編集と採否を含む)${p.adoption?.done ? `。採用済み: ${Object.values(p.adoption.reserved).join(", ")}` : ""}`,
94
+ ...p.children.map((c) => `### ${c.key} ${c.title}(${c.include ? "採用" : "不採用"}${c.estimatedTasks !== undefined ? ` / 想定 ${c.estimatedTasks} 件` : ""})\n${c.description}`),
95
+ ]
96
+ : []), uiCarryover(p));
97
+ }
98
+ else if (c.previousSkipped) {
99
+ out.push(`## 前回の評価\n引き継ぎません(${c.previousSkipped})。`);
100
+ }
101
+ if (c.notes.length) {
102
+ out.push("## その後のメモ(確認事項への回答・方針の変更。古い順)", ...c.notes.map((n) => `### ${n.id}(${n.createdBy ?? "不明"}, ${n.createdAt})\n${n.body}`));
103
+ }
104
+ return `${out.join("\n\n")}\n`;
105
+ }