@infodb/p3 0.3.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.
- package/bin/p3.mjs +11 -5
- package/dist/web/assets/Outputs-C83ZDXvs.js +1 -0
- package/dist/web/assets/RequestStatus-GmiWYEcL.js +1 -0
- package/dist/web/assets/Tabs-CJn0Qy7W.js +1 -0
- package/dist/web/assets/TagInput-CtM8HM8Z.js +1 -0
- package/dist/web/assets/TaskDrawer-D5v36QoF.js +3 -0
- package/dist/web/assets/_requestId-BHUqLO-j.js +1 -0
- package/dist/web/assets/_requestId-DxwxbXY2.js +30 -0
- package/dist/web/assets/{ui-Sz7y5_TS.js → appCtx-B-VRVOyv.js} +1 -1
- package/dist/web/assets/board-DAaVR04x.js +1 -0
- package/dist/web/assets/copy-CKsXEjMi.js +1 -0
- package/dist/web/assets/done-CaqB_qTH.js +1 -0
- package/dist/web/assets/index-BF1xMdJo.css +2 -0
- package/dist/web/assets/index-BQYvKpjF.js +12 -0
- package/dist/web/assets/milestoneOrder-N7b5XFJP.js +1 -0
- package/dist/web/assets/new-DLVnRvrB.js +1 -0
- package/dist/web/assets/preflightInput-BAeEJYUK.js +2 -0
- package/dist/web/assets/preload-helper-B74h5i3O.js +1 -0
- package/dist/web/assets/progressTree-wp9mH4VF.js +1 -0
- package/dist/web/assets/release-notes-MTLcOcvZ.js +3 -0
- package/dist/web/assets/requestData-D-HXu-cy.js +1 -0
- package/dist/web/assets/routes-CI4Qfkjs.js +3 -0
- package/dist/web/assets/settings-CJMNgzi6.js +1 -0
- package/dist/web/index.html +4 -4
- package/docs/architecture.md +238 -9
- package/docs/development.md +16 -9
- package/docs/how-to-use.md +128 -12
- package/docs/installation.md +8 -6
- package/docs/publishing.md +4 -2
- package/lib/cli/args.js +172 -0
- package/lib/cli/chatgpt.js +70 -0
- package/lib/cli/codex.js +30 -0
- package/lib/cli/format.js +9 -0
- package/{src/cli/help.ts → lib/cli/help.js} +11 -8
- package/lib/cli/main.js +326 -0
- package/lib/cli/output.js +110 -0
- package/lib/cli/preflightCommands.js +301 -0
- package/lib/cli/project.js +649 -0
- package/lib/cli/readOnly.js +36 -0
- package/lib/cli/releaseNotesCommands.js +197 -0
- package/lib/cli/render.js +58 -0
- package/lib/cli/requestCommands.js +180 -0
- package/lib/cli/showView.js +100 -0
- package/lib/cli/taskCommands.js +152 -0
- package/lib/cli/userConfig.js +64 -0
- package/{src/core/chatgpt.ts → lib/core/chatgpt.js} +10 -16
- package/lib/core/context.js +41 -0
- package/lib/core/hierarchy.js +128 -0
- package/lib/core/machineSettings.js +146 -0
- package/lib/core/machineSettingsEdit.js +148 -0
- package/lib/core/ops.js +120 -0
- package/lib/core/preflight/carryover.js +105 -0
- package/lib/core/preflight/codexEngine.js +687 -0
- package/lib/core/preflight/codexImage.js +61 -0
- package/lib/core/preflight/diagnose.js +95 -0
- package/lib/core/preflight/engine.js +58 -0
- package/lib/core/preflight/input.js +83 -0
- package/lib/core/preflight/launch.js +68 -0
- package/lib/core/preflight/mockEngine.js +175 -0
- package/lib/core/preflight/render.js +304 -0
- package/lib/core/preflight/service.js +868 -0
- package/lib/core/preflight/split.js +83 -0
- package/lib/core/preflight/uiMaterials.js +281 -0
- package/lib/core/preflight/uiRender.js +89 -0
- package/lib/core/preflight/wireframe.js +63 -0
- package/lib/core/preflight/xlsx.js +324 -0
- package/lib/core/projectRegistry.js +207 -0
- package/lib/core/redact.js +28 -0
- package/lib/core/releaseNotes/completeRequests.js +106 -0
- package/lib/core/releaseNotes/generate.js +266 -0
- package/lib/core/releaseNotes/material.js +141 -0
- package/lib/core/releaseNotes/mockSummarizer.js +26 -0
- package/lib/core/releaseNotes/service.js +83 -0
- package/lib/core/releaseNotes/store.js +209 -0
- package/lib/core/repoAdmin.js +82 -0
- package/lib/core/repoRefs.js +72 -0
- package/lib/core/requestOps.js +154 -0
- package/lib/core/requestStatus.js +171 -0
- package/lib/core/store/attachments.js +242 -0
- package/lib/core/store/collection.js +254 -0
- package/lib/core/store/frontmatter.js +18 -0
- package/lib/core/store/fsutil.js +84 -0
- package/lib/core/store/locate.js +162 -0
- package/lib/core/store/normalize.js +150 -0
- package/lib/core/store/noteStore.js +59 -0
- package/lib/core/store/preflightStore.js +161 -0
- package/lib/core/store/projectFile.js +99 -0
- package/lib/core/store/workspace.js +320 -0
- package/lib/core/supersede.js +69 -0
- package/lib/core/userConfig.js +158 -0
- package/{src/core/userTheme.ts → lib/core/userTheme.js} +11 -13
- package/lib/core/workTargets.js +106 -0
- package/lib/server/api/chatgptRoutes.js +46 -0
- package/{src/server/api/local.ts → lib/server/api/local.js} +23 -22
- package/lib/server/api/manifest.js +140 -0
- package/lib/server/api/projectsRoutes.js +82 -0
- package/lib/server/api/releaseNoteRoutes.js +88 -0
- package/lib/server/api/repoRoutes.js +67 -0
- package/lib/server/api/routes.js +404 -0
- package/lib/server/api/userThemeRoutes.js +60 -0
- package/lib/server/server.js +85 -0
- package/lib/shared/dates.js +10 -0
- package/{src/shared/directTask.ts → lib/shared/directTask.js} +3 -11
- package/lib/shared/hierarchy.js +120 -0
- package/lib/shared/milestoneOrder.js +45 -0
- package/lib/shared/preflightInput.js +19 -0
- package/lib/shared/refs.js +44 -0
- package/lib/shared/repos.js +69 -0
- package/lib/shared/scopeView.js +39 -0
- package/{src/shared/tags.ts → lib/shared/tags.js} +9 -14
- package/lib/shared/types.js +74 -0
- package/lib/shared/workTarget.js +31 -0
- package/package.json +4 -7
- package/skills/p3/SKILL.md +29 -8
- package/dist/web/assets/Outputs-DqJdybkd.js +0 -1
- package/dist/web/assets/RequestStatus-DN-2iAM0.js +0 -1
- package/dist/web/assets/TagInput-D-1ILLDX.js +0 -1
- package/dist/web/assets/TaskDrawer-CHD7T-Su.js +0 -3
- package/dist/web/assets/_requestId-BzSepQIV.js +0 -30
- package/dist/web/assets/_requestId-pIds2tFU.js +0 -1
- package/dist/web/assets/board-BIkOpuC4.js +0 -1
- package/dist/web/assets/copy-B1ZbihKL.js +0 -2
- package/dist/web/assets/done-BUAUhIRr.js +0 -1
- package/dist/web/assets/index-Byv9j77D.js +0 -12
- package/dist/web/assets/index-DTfUhuQw.css +0 -2
- package/dist/web/assets/new-6kly4-PX.js +0 -1
- package/dist/web/assets/preload-helper-DlN0ouRj.js +0 -1
- package/dist/web/assets/release-notes-iwQWmfX6.js +0 -3
- package/dist/web/assets/requestData-DJ1Rlx-u.js +0 -1
- package/dist/web/assets/routes-Ciot9p4x.js +0 -2
- package/dist/web/assets/settings-DBCi6lAY.js +0 -1
- package/src/cli/args.ts +0 -186
- package/src/cli/chatgpt.ts +0 -74
- package/src/cli/codex.ts +0 -28
- package/src/cli/format.ts +0 -9
- package/src/cli/main.ts +0 -336
- package/src/cli/output.ts +0 -117
- package/src/cli/preflightCommands.ts +0 -245
- package/src/cli/project.ts +0 -672
- package/src/cli/readOnly.ts +0 -36
- package/src/cli/releaseNotesCommands.ts +0 -159
- package/src/cli/render.ts +0 -60
- package/src/cli/requestCommands.ts +0 -170
- package/src/cli/showView.ts +0 -110
- package/src/cli/taskCommands.ts +0 -167
- package/src/cli/userConfig.ts +0 -58
- package/src/core/context.ts +0 -58
- package/src/core/machineSettings.ts +0 -207
- package/src/core/machineSettingsEdit.ts +0 -156
- package/src/core/ops.ts +0 -114
- package/src/core/preflight/carryover.ts +0 -133
- package/src/core/preflight/codexEngine.ts +0 -703
- package/src/core/preflight/codexImage.ts +0 -98
- package/src/core/preflight/diagnose.ts +0 -124
- package/src/core/preflight/engine.ts +0 -92
- package/src/core/preflight/input.ts +0 -65
- package/src/core/preflight/launch.ts +0 -86
- package/src/core/preflight/mockEngine.ts +0 -145
- package/src/core/preflight/render.ts +0 -339
- package/src/core/preflight/service.ts +0 -707
- package/src/core/preflight/uiMaterials.ts +0 -272
- package/src/core/preflight/uiRender.ts +0 -84
- package/src/core/preflight/wireframe.ts +0 -69
- package/src/core/preflight/xlsx.ts +0 -328
- package/src/core/projectRegistry.ts +0 -264
- package/src/core/redact.ts +0 -31
- package/src/core/releaseNotes/generate.ts +0 -283
- package/src/core/releaseNotes/material.ts +0 -114
- package/src/core/releaseNotes/mockSummarizer.ts +0 -28
- package/src/core/releaseNotes/service.ts +0 -106
- package/src/core/releaseNotes/store.ts +0 -216
- package/src/core/repoAdmin.ts +0 -81
- package/src/core/repoRefs.ts +0 -90
- package/src/core/requestOps.ts +0 -140
- package/src/core/requestStatus.ts +0 -58
- package/src/core/store/attachments.ts +0 -228
- package/src/core/store/collection.ts +0 -282
- package/src/core/store/frontmatter.ts +0 -22
- package/src/core/store/fsutil.ts +0 -90
- package/src/core/store/locate.ts +0 -181
- package/src/core/store/normalize.ts +0 -155
- package/src/core/store/noteStore.ts +0 -56
- package/src/core/store/preflightStore.ts +0 -136
- package/src/core/store/projectFile.ts +0 -101
- package/src/core/store/workspace.ts +0 -328
- package/src/core/supersede.ts +0 -74
- package/src/core/userConfig.ts +0 -205
- package/src/core/workTargets.ts +0 -120
- package/src/server/api/chatgptRoutes.ts +0 -49
- package/src/server/api/manifest.ts +0 -128
- package/src/server/api/projectsRoutes.ts +0 -89
- package/src/server/api/releaseNoteRoutes.ts +0 -78
- package/src/server/api/repoRoutes.ts +0 -67
- package/src/server/api/routes.ts +0 -382
- package/src/server/api/userThemeRoutes.ts +0 -62
- package/src/server/server.ts +0 -108
- package/src/shared/dates.ts +0 -12
- package/src/shared/preflightInput.ts +0 -27
- package/src/shared/refs.ts +0 -55
- package/src/shared/repos.ts +0 -113
- package/src/shared/scopeView.ts +0 -48
- package/src/shared/types.ts +0 -700
- package/src/shared/workTarget.ts +0 -44
- /package/{src → lib}/core/preflight/launcher.mjs +0 -0
- /package/{src → lib}/core/preflight/mock-ui.html +0 -0
- /package/{src → lib}/core/preflight/mock-ui.png +0 -0
- /package/{src → lib}/core/preflight/render-image/Dockerfile +0 -0
- /package/{src → lib}/core/preflight/render-image/fonts-ja.conf +0 -0
- /package/{src → lib}/core/preflight/render-image/render.mjs +0 -0
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { normalizeTaskId } from "../../shared/refs.js";
|
|
3
|
+
/**
|
|
4
|
+
* 分割の run(子の要望の案)の規則(docs/architecture.md の「Preflight の分割の案」)。読み込みの検証・子の本文・採用の版。
|
|
5
|
+
* 採用の手順(予約・作成・やり直し)は service.ts の adopt
|
|
6
|
+
*/
|
|
7
|
+
/** 子の案のキー(C1, C2, ...) */
|
|
8
|
+
const CHILD_KEY = /^C\d+$/;
|
|
9
|
+
/** 見出しの下の本文(無ければ空) */
|
|
10
|
+
function section(md, heading) {
|
|
11
|
+
const m = new RegExp(`^##\\s*${heading}\\s*$([\\s\\S]*?)(?=^##\\s|(?![\\s\\S]))`, "m").exec(md);
|
|
12
|
+
return m?.[1]?.trim() ?? "";
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* 案の読み込みの問題。あれば採用しない(直すか、再評価する)。
|
|
16
|
+
* タスク案と子の案の混在・キーの形と重なり・題・目的・完了条件の欠け・無い案を指す requires・親に無いタスクを指す overlaps
|
|
17
|
+
*/
|
|
18
|
+
export function draftProblems(run, parentTasks) {
|
|
19
|
+
const children = run.children;
|
|
20
|
+
if (!children)
|
|
21
|
+
return [];
|
|
22
|
+
const problems = [];
|
|
23
|
+
if (children.length && run.drafts.length)
|
|
24
|
+
problems.push("タスク案(drafts/)と子の案(children/)が両方あります。1つの run はどちらか一方だけにしてください");
|
|
25
|
+
const keys = children.map((c) => c.key);
|
|
26
|
+
for (const k of new Set(keys.filter((k, i) => keys.indexOf(k) !== i)))
|
|
27
|
+
problems.push(`子の案のキーが重なっています: ${k}`);
|
|
28
|
+
for (const c of children) {
|
|
29
|
+
if (!CHILD_KEY.test(c.key))
|
|
30
|
+
problems.push(`子の案のキーの形が違います: ${c.key}(C1, C2, ...)`);
|
|
31
|
+
if (!c.title.trim())
|
|
32
|
+
problems.push(`${c.key}: 題がありません`);
|
|
33
|
+
if (!section(c.description, "目的"))
|
|
34
|
+
problems.push(`${c.key}: 「## 目的」がありません`);
|
|
35
|
+
if (!section(c.description, "完了条件"))
|
|
36
|
+
problems.push(`${c.key}: 「## 完了条件」がありません`);
|
|
37
|
+
for (const r of c.requires) {
|
|
38
|
+
if (r === c.key)
|
|
39
|
+
problems.push(`${c.key}: 自分を前提にしています`);
|
|
40
|
+
else if (!keys.includes(r))
|
|
41
|
+
problems.push(`${c.key}: 前提の ${r} という子の案はありません`);
|
|
42
|
+
}
|
|
43
|
+
for (const t of c.overlaps) {
|
|
44
|
+
const id = normalizeTaskId(t) ?? t;
|
|
45
|
+
if (!parentTasks.includes(id))
|
|
46
|
+
problems.push(`${c.key}: 重なるとした ${t} は親のタスクにありません`);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return problems;
|
|
50
|
+
}
|
|
51
|
+
/** 評価の split を取り込む(形が揺れても弾かず、読めなければ無し) */
|
|
52
|
+
export function parseSplit(v) {
|
|
53
|
+
if (!v || typeof v !== "object")
|
|
54
|
+
return undefined;
|
|
55
|
+
const s = v;
|
|
56
|
+
if (s.decision !== "split" && s.decision !== "keep")
|
|
57
|
+
return undefined;
|
|
58
|
+
const n = Number(s.estimatedTasks);
|
|
59
|
+
return {
|
|
60
|
+
decision: s.decision,
|
|
61
|
+
...(s.estimatedTasks !== undefined && Number.isFinite(n) ? { estimatedTasks: Math.max(0, Math.round(n)) } : {}),
|
|
62
|
+
reasons: Array.isArray(s.reasons) ? s.reasons.map(String) : [],
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
/** 採用する案の版(題・本文・前提・重なり・採否)。確認のときと採用のときで比べる */
|
|
66
|
+
export function childrenVersion(children) {
|
|
67
|
+
const key = children.map((c) => [c.key, c.title, c.description, c.estimatedTasks ?? null, c.requires, c.overlaps, c.include]);
|
|
68
|
+
return createHash("sha256").update(JSON.stringify(key)).digest("hex").slice(0, 16);
|
|
69
|
+
}
|
|
70
|
+
/** 子の要望の本文: 出典・親の目的(採用のときの題と本文)・案の範囲・前提にする子 */
|
|
71
|
+
export function childBody(parent, c, runId, ids) {
|
|
72
|
+
const quote = (s) => (s.trim() ? s.trim().split("\n").map((l) => `> ${l}`).join("\n") : "> (本文なし)");
|
|
73
|
+
const requires = c.requires.map((k) => `- ${k} → ${ids[k] ?? "(採用していない案)"}`);
|
|
74
|
+
return [
|
|
75
|
+
`> 親の要望 ${parent.id} を分割した子の要望(${runId} / ${c.key})。添付は親の要望にあります`,
|
|
76
|
+
"## 親の目的(採用のときの親の題と本文)",
|
|
77
|
+
`> **${parent.title}**\n>\n${quote(parent.body)}`,
|
|
78
|
+
c.description.trim(),
|
|
79
|
+
...(requires.length ? ["## 前提にする子の要望", requires.join("\n")] : []),
|
|
80
|
+
].join("\n\n");
|
|
81
|
+
}
|
|
82
|
+
/** 子の採用元の印(request.md の splitFrom) */
|
|
83
|
+
export const splitMarker = (runId, key) => `${runId}/${key}`;
|
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
import { lstat, readFile } from "node:fs/promises";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
/**
|
|
4
|
+
* Preflight の画面資料(run の ui/)。エンジンは画像と一覧を書き、P3 が確かめてから run に取り込む:
|
|
5
|
+
*
|
|
6
|
+
* <runDir>/ui/index.json 資料の一覧(UI_INDEX_SPEC)
|
|
7
|
+
* <runDir>/ui/U1.png ... 画像(PNG / JPEG)
|
|
8
|
+
* <runDir>/ui/src/U1.html 原稿(HTML / CSS。画面には配信しない)
|
|
9
|
+
*
|
|
10
|
+
* パスはすべて ui/ からの相対。絶対パス・..・シンボリックリンク・拡張子と中身が合わない画像・上限を超える画像は取り込まない。
|
|
11
|
+
* 資料が不正でも評価は消さず、取り込めなかった理由を残す。必要な画面イメージが足りなければ go を clarify にする(no_go は変えない)。
|
|
12
|
+
*/
|
|
13
|
+
export const UI_DIR = "ui";
|
|
14
|
+
export const UI_INDEX = "index.json";
|
|
15
|
+
/** 上限(1つの run あたり) */
|
|
16
|
+
export const UI_LIMITS = {
|
|
17
|
+
items: 20,
|
|
18
|
+
/** 1枚の大きさ */
|
|
19
|
+
bytes: 5 * 1024 * 1024,
|
|
20
|
+
/** 全部の大きさ */
|
|
21
|
+
totalBytes: 30 * 1024 * 1024,
|
|
22
|
+
width: 4096,
|
|
23
|
+
height: 16384,
|
|
24
|
+
pixels: 40_000_000,
|
|
25
|
+
};
|
|
26
|
+
export const UI_INDEX_SPEC = `{
|
|
27
|
+
"needed": true | false,
|
|
28
|
+
"reason": "不要の理由(needed が false のとき必須。例: CLI と API だけの変更で画面は変わらない)",
|
|
29
|
+
"targets": ["D1"],
|
|
30
|
+
"items": [
|
|
31
|
+
{ "id": "U1", "html": "src/U1.html", "title": "何の画面のどの状態か",
|
|
32
|
+
"drafts": ["D1", "D2"], "viewport": 1280, "assumptions": ["仮のデータで描いた", "省いたもの"] }
|
|
33
|
+
]
|
|
34
|
+
}
|
|
35
|
+
needed: 画面(UI)を伴うタスク案があるか / targets: 画面イメージが要るタスク案の key(省くと items の drafts を合わせたもの)/
|
|
36
|
+
items: 原稿1つにつき1件。id は U1, U2 ...、html は ui/ からの相対パス、drafts は対象のタスク案の key(1枚に複数をまとめてよい)、
|
|
37
|
+
viewport は想定する画面の幅(px。320〜2560)。画像(file)は書かないでください(P3 が原稿から描いて書き足します)`;
|
|
38
|
+
export class UiMaterialError extends Error {
|
|
39
|
+
}
|
|
40
|
+
/** 画像の形式と大きさを中身から読む(PNG / JPEG だけ。ほかは undefined) */
|
|
41
|
+
export function imageInfo(buf) {
|
|
42
|
+
if (buf.length >= 24 && buf.subarray(0, 8).equals(Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a])) && buf.toString("latin1", 12, 16) === "IHDR") {
|
|
43
|
+
return { format: "png", width: buf.readUInt32BE(16), height: buf.readUInt32BE(20) };
|
|
44
|
+
}
|
|
45
|
+
if (buf.length >= 4 && buf[0] === 0xff && buf[1] === 0xd8 && buf[2] === 0xff) {
|
|
46
|
+
// SOF(フレームの始まり)を探して大きさを読む
|
|
47
|
+
let i = 2;
|
|
48
|
+
while (i + 9 < buf.length) {
|
|
49
|
+
if (buf[i] !== 0xff)
|
|
50
|
+
return undefined;
|
|
51
|
+
const marker = buf[i + 1];
|
|
52
|
+
if (marker === 0xff) {
|
|
53
|
+
i++;
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
if (marker === 0xd8 || marker === 0x01 || (marker >= 0xd0 && marker <= 0xd7)) {
|
|
57
|
+
i += 2;
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
const len = buf.readUInt16BE(i + 2);
|
|
61
|
+
if (len < 2)
|
|
62
|
+
return undefined;
|
|
63
|
+
if (marker >= 0xc0 && marker <= 0xcf && marker !== 0xc4 && marker !== 0xc8 && marker !== 0xcc) {
|
|
64
|
+
return { format: "jpeg", width: buf.readUInt16BE(i + 7), height: buf.readUInt16BE(i + 5) };
|
|
65
|
+
}
|
|
66
|
+
i += 2 + len;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return undefined;
|
|
70
|
+
}
|
|
71
|
+
const EXT = { ".png": "png", ".jpg": "jpeg", ".jpeg": "jpeg" };
|
|
72
|
+
export const IMAGE_TYPES = { png: "image/png", jpeg: "image/jpeg" };
|
|
73
|
+
/** base の中の相対パスか(絶対パス・..・空の部分・\ を断る)。正規化した相対パスを返す */
|
|
74
|
+
export function safeRelative(rel) {
|
|
75
|
+
if (typeof rel !== "string" || !rel.trim())
|
|
76
|
+
return undefined;
|
|
77
|
+
const p = rel.trim().replace(/^(\.\/)+/, "");
|
|
78
|
+
if (p.startsWith("/") || p.includes("\\") || /^[A-Za-z]:/.test(p))
|
|
79
|
+
return undefined;
|
|
80
|
+
const parts = p.split("/");
|
|
81
|
+
if (parts.some((s) => !s || s === "." || s === ".."))
|
|
82
|
+
return undefined;
|
|
83
|
+
return parts.join("/");
|
|
84
|
+
}
|
|
85
|
+
/** base(それ自身も含む)から rel までのどこにもシンボリックリンクが無い、ふつうのファイルか。違えば理由 */
|
|
86
|
+
async function plainFileProblem(base, rel, dir = false) {
|
|
87
|
+
const parts = rel.split("/");
|
|
88
|
+
let cur = base;
|
|
89
|
+
for (let i = -1; i < parts.length; i++) {
|
|
90
|
+
if (i >= 0)
|
|
91
|
+
cur = join(cur, parts[i]);
|
|
92
|
+
const st = await lstat(cur).catch(() => undefined);
|
|
93
|
+
if (!st)
|
|
94
|
+
return "ファイルがありません";
|
|
95
|
+
if (st.isSymbolicLink())
|
|
96
|
+
return "シンボリックリンクは使えません";
|
|
97
|
+
if (i < parts.length - 1 || dir ? !st.isDirectory() : !st.isFile())
|
|
98
|
+
return i < parts.length - 1 || dir ? "フォルダではありません" : "ふつうのファイルではありません";
|
|
99
|
+
}
|
|
100
|
+
return undefined;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* ui/ の中の画像を確かめて読む(取り込みと配信で同じ確かめ方をする)。
|
|
104
|
+
* 返すのは中身と形式。だめなら UiMaterialError(理由)
|
|
105
|
+
*/
|
|
106
|
+
export async function readUiImage(uiDir, file) {
|
|
107
|
+
const rel = safeRelative(file);
|
|
108
|
+
if (!rel)
|
|
109
|
+
throw new UiMaterialError(`ui/ の中の相対パスではありません: ${String(file)}`);
|
|
110
|
+
const ext = EXT[rel.slice(rel.lastIndexOf(".")).toLowerCase()];
|
|
111
|
+
if (!ext)
|
|
112
|
+
throw new UiMaterialError(`画像は PNG か JPEG(.png / .jpg / .jpeg)にしてください: ${rel}`);
|
|
113
|
+
const problem = await plainFileProblem(uiDir, rel);
|
|
114
|
+
if (problem)
|
|
115
|
+
throw new UiMaterialError(`${rel}: ${problem}`);
|
|
116
|
+
const full = join(uiDir, rel);
|
|
117
|
+
const st = await lstat(full);
|
|
118
|
+
if (st.size > UI_LIMITS.bytes)
|
|
119
|
+
throw new UiMaterialError(`${rel}: 大きすぎます(${st.size} バイト。上限 ${UI_LIMITS.bytes})`);
|
|
120
|
+
const data = await readFile(full);
|
|
121
|
+
const info = imageInfo(data);
|
|
122
|
+
if (!info)
|
|
123
|
+
throw new UiMaterialError(`${rel}: PNG / JPEG として読めません`);
|
|
124
|
+
if (info.format !== ext)
|
|
125
|
+
throw new UiMaterialError(`${rel}: 拡張子と中身の形式が合いません(中身は ${info.format})`);
|
|
126
|
+
if (!info.width || !info.height || info.width > UI_LIMITS.width || info.height > UI_LIMITS.height || info.width * info.height > UI_LIMITS.pixels) {
|
|
127
|
+
throw new UiMaterialError(`${rel}: 画像の大きさが上限を超えています(${info.width}x${info.height}。幅 ${UI_LIMITS.width}・高さ ${UI_LIMITS.height} まで)`);
|
|
128
|
+
}
|
|
129
|
+
return { data, info };
|
|
130
|
+
}
|
|
131
|
+
const isRendered = (v) => !!v && typeof v === "object" && v.by === "p3";
|
|
132
|
+
const text = (v) => (typeof v === "string" && v.trim() ? v.trim() : undefined);
|
|
133
|
+
const strs = (v) => (Array.isArray(v) ? v.filter((x) => typeof x === "string" && !!x.trim()).map((x) => x.trim()) : []);
|
|
134
|
+
const ID = /^[A-Za-z0-9][A-Za-z0-9_-]{0,31}$/;
|
|
135
|
+
/**
|
|
136
|
+
* エンジンが書いた ui/ を確かめて取り込む。draftKeys: この run のタスク案の D キー。
|
|
137
|
+
* 一覧が無い・読めない・資料が不正でも例外にせず、状態と理由で返す
|
|
138
|
+
*/
|
|
139
|
+
export async function loadUiMaterials(runDir, runId, draftKeys) {
|
|
140
|
+
const uiDir = join(runDir, UI_DIR);
|
|
141
|
+
const problems = [];
|
|
142
|
+
const missing = (reason, extra = {}) => ({ status: "missing", reason, targets: [], items: [], problems, ...extra });
|
|
143
|
+
const dirProblem = await plainFileProblem(runDir, UI_DIR, true);
|
|
144
|
+
if (dirProblem === "ファイルがありません")
|
|
145
|
+
return missing("画面資料の一覧(ui/index.json)がありません");
|
|
146
|
+
if (dirProblem)
|
|
147
|
+
return missing(`ui/ が使えません(${dirProblem})`);
|
|
148
|
+
const indexProblem = await plainFileProblem(uiDir, UI_INDEX);
|
|
149
|
+
if (indexProblem)
|
|
150
|
+
return missing(`画面資料の一覧(ui/index.json)が読めません(${indexProblem})`, { needed: indexProblem === "ファイルがありません" ? undefined : true });
|
|
151
|
+
let index;
|
|
152
|
+
try {
|
|
153
|
+
const raw = JSON.parse(await readFile(join(uiDir, UI_INDEX), "utf8"));
|
|
154
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw))
|
|
155
|
+
throw new Error("オブジェクトではありません");
|
|
156
|
+
index = raw;
|
|
157
|
+
}
|
|
158
|
+
catch (e) {
|
|
159
|
+
// 一覧を書こうとしたが壊れている: 画面イメージが要る案だった可能性があるので、要るものとして足りない扱いにする
|
|
160
|
+
return missing(`画面資料の一覧(ui/index.json)が JSON として読めません: ${e.message}`, { needed: true });
|
|
161
|
+
}
|
|
162
|
+
if (index.needed === false) {
|
|
163
|
+
const reason = text(index.reason);
|
|
164
|
+
if (!reason)
|
|
165
|
+
problems.push("不要の理由が書かれていません");
|
|
166
|
+
return { status: "not_needed", needed: false, reason: reason ?? "(理由が書かれていません)", targets: [], items: [], problems };
|
|
167
|
+
}
|
|
168
|
+
const keys = new Set(draftKeys);
|
|
169
|
+
const rawItems = Array.isArray(index.items) ? index.items : [];
|
|
170
|
+
if (!Array.isArray(index.items) && index.items !== undefined)
|
|
171
|
+
problems.push("items が配列ではありません");
|
|
172
|
+
if (rawItems.length > UI_LIMITS.items)
|
|
173
|
+
problems.push(`資料が多すぎます(${rawItems.length} 件。先頭の ${UI_LIMITS.items} 件だけ取り込みます)`);
|
|
174
|
+
const items = [];
|
|
175
|
+
let total = 0;
|
|
176
|
+
for (const [i, raw] of rawItems.slice(0, UI_LIMITS.items).entries()) {
|
|
177
|
+
const label = `items[${i}]`;
|
|
178
|
+
if (!raw || typeof raw !== "object") {
|
|
179
|
+
problems.push(`${label}: 読めません`);
|
|
180
|
+
continue;
|
|
181
|
+
}
|
|
182
|
+
const r = raw;
|
|
183
|
+
const id = text(r.id);
|
|
184
|
+
if (!id || !ID.test(id)) {
|
|
185
|
+
problems.push(`${label}: id は英数字・_・- で書いてください(${String(r.id)})`);
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
188
|
+
if (items.some((x) => x.id === id)) {
|
|
189
|
+
problems.push(`${id}: id が重なっています`);
|
|
190
|
+
continue;
|
|
191
|
+
}
|
|
192
|
+
if (r.kind !== undefined && r.kind !== "proposal") {
|
|
193
|
+
problems.push(`${id}: エンジンが書けるのは提案(proposal)の画面イメージだけです(${String(r.kind)})`);
|
|
194
|
+
continue;
|
|
195
|
+
}
|
|
196
|
+
if (r.run !== undefined && r.run !== runId) {
|
|
197
|
+
problems.push(`${id}: ほかの run(${String(r.run)})の資料は取り込みません`);
|
|
198
|
+
continue;
|
|
199
|
+
}
|
|
200
|
+
const drafts = strs(r.drafts);
|
|
201
|
+
const unknown = drafts.filter((k) => !keys.has(k));
|
|
202
|
+
if (unknown.length)
|
|
203
|
+
problems.push(`${id}: 無いタスク案 ${unknown.join(", ")} を外しました`);
|
|
204
|
+
const known = drafts.filter((k) => keys.has(k));
|
|
205
|
+
if (!known.length) {
|
|
206
|
+
problems.push(`${id}: 対象のタスク案(drafts)がありません`);
|
|
207
|
+
continue;
|
|
208
|
+
}
|
|
209
|
+
if (r.file === undefined) {
|
|
210
|
+
problems.push(`${id}: 画像がありません${typeof r.renderError === "string" ? `(描画できませんでした: ${r.renderError})` : r.html === undefined ? "(原稿もありません)" : ""}`);
|
|
211
|
+
continue;
|
|
212
|
+
}
|
|
213
|
+
let image;
|
|
214
|
+
try {
|
|
215
|
+
image = await readUiImage(uiDir, r.file);
|
|
216
|
+
}
|
|
217
|
+
catch (e) {
|
|
218
|
+
if (!(e instanceof UiMaterialError))
|
|
219
|
+
throw e;
|
|
220
|
+
problems.push(`${id}: ${e.message}`);
|
|
221
|
+
continue;
|
|
222
|
+
}
|
|
223
|
+
if (total + image.data.length > UI_LIMITS.totalBytes) {
|
|
224
|
+
problems.push(`${id}: 資料の合計が上限(${UI_LIMITS.totalBytes} バイト)を超えるので取り込みません`);
|
|
225
|
+
continue;
|
|
226
|
+
}
|
|
227
|
+
total += image.data.length;
|
|
228
|
+
let html;
|
|
229
|
+
if (r.html !== undefined) {
|
|
230
|
+
const h = safeRelative(r.html);
|
|
231
|
+
const p = h && /\.html?$/i.test(h) ? await plainFileProblem(uiDir, h) : "ui/ の中の HTML ではありません";
|
|
232
|
+
if (h && !p)
|
|
233
|
+
html = h;
|
|
234
|
+
else
|
|
235
|
+
problems.push(`${id}: 原稿 ${String(r.html)} を記録しません(${p})`);
|
|
236
|
+
}
|
|
237
|
+
const viewport = Number(r.viewport);
|
|
238
|
+
items.push({
|
|
239
|
+
id,
|
|
240
|
+
kind: "proposal",
|
|
241
|
+
file: safeRelative(r.file),
|
|
242
|
+
format: image.info.format,
|
|
243
|
+
width: image.info.width,
|
|
244
|
+
height: image.info.height,
|
|
245
|
+
bytes: image.data.length,
|
|
246
|
+
title: text(r.title) ?? id,
|
|
247
|
+
...(text(r.source) ? { source: text(r.source) } : {}),
|
|
248
|
+
...(html ? { html, source: text(r.source) ?? `ui/${html}` } : {}),
|
|
249
|
+
drafts: known,
|
|
250
|
+
...(Number.isInteger(viewport) && viewport > 0 ? { viewport } : {}),
|
|
251
|
+
assumptions: strs(r.assumptions),
|
|
252
|
+
run: runId,
|
|
253
|
+
...(isRendered(r.rendered) ? { rendered: { by: "p3", clipped: !!r.rendered.clipped, blocked: Number(r.rendered.blocked) || 0 } } : {}),
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
const declared = strs(index.targets);
|
|
257
|
+
const unknownTargets = declared.filter((k) => !keys.has(k));
|
|
258
|
+
if (unknownTargets.length)
|
|
259
|
+
problems.push(`targets: 無いタスク案 ${unknownTargets.join(", ")} を外しました`);
|
|
260
|
+
const targets = declared.length ? declared.filter((k) => keys.has(k)) : [...new Set(strs(rawItems.flatMap((r) => (r && typeof r === "object" ? r.drafts : []))).filter((k) => keys.has(k)))];
|
|
261
|
+
const covered = new Set(items.flatMap((x) => x.drafts));
|
|
262
|
+
const lacking = targets.filter((k) => !covered.has(k));
|
|
263
|
+
if (lacking.length)
|
|
264
|
+
return { status: "missing", needed: true, reason: `画面イメージが足りないタスク案: ${lacking.join(", ")}`, targets, items, problems };
|
|
265
|
+
if (!items.length)
|
|
266
|
+
return { status: "missing", needed: true, reason: problems.length ? "取り込める画面イメージがありません" : "画面イメージがありません", targets, items, problems };
|
|
267
|
+
return { status: "ready", needed: true, targets, items, problems };
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* 必要な画面イメージが足りないとき、評価に反映する(go → clarify と確認事項)。no_go・clarify は変えない。
|
|
271
|
+
* 一覧が無い(エンジンが画面資料を扱っていない)だけのときは変えない
|
|
272
|
+
*/
|
|
273
|
+
export function applyUiShortage(assessment, ui) {
|
|
274
|
+
if (ui.status !== "missing" || ui.needed !== true)
|
|
275
|
+
return ui;
|
|
276
|
+
assessment.questions = [...assessment.questions, `画面イメージが足りません(${ui.reason})。画面の内容を確かめてから進めるか、メモで再評価してください`];
|
|
277
|
+
if (assessment.verdict !== "go")
|
|
278
|
+
return ui;
|
|
279
|
+
assessment.verdict = "clarify";
|
|
280
|
+
return { ...ui, verdictAdjusted: { from: "go", to: "clarify" } };
|
|
281
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { lstat, readFile } from "node:fs/promises";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { writeFileAtomic } from "../store/fsutil.js";
|
|
4
|
+
import { RENDER_LIMITS, RenderError, renderHtml } from "./render.js";
|
|
5
|
+
import { safeRelative, UI_DIR, UI_INDEX } from "./uiMaterials.js";
|
|
6
|
+
/**
|
|
7
|
+
* エンジンが書いた原稿(ui/index.json の items の html)を P3 が PNG にし、一覧に結果を書き足す:
|
|
8
|
+
* 描けた: file(ui/ からの相対)と rendered(P3 が描いた。エンジンは画像を見ていない)
|
|
9
|
+
* 描けない: renderError(理由)。取り込むときに「画像がありません」として不足に数える
|
|
10
|
+
* 既に file があるもの・原稿の無いものは触らない。一覧が無い・読めないときは何もしない(取り込みで理由を残す)。
|
|
11
|
+
* 描画の失敗・取消は例外にしない(評価は残す)
|
|
12
|
+
*/
|
|
13
|
+
export async function renderManuscripts(runDir, opts) {
|
|
14
|
+
const uiDir = join(runDir, UI_DIR);
|
|
15
|
+
const indexFile = join(uiDir, UI_INDEX);
|
|
16
|
+
let index;
|
|
17
|
+
try {
|
|
18
|
+
if ((await lstat(uiDir)).isSymbolicLink() || (await lstat(indexFile)).isSymbolicLink())
|
|
19
|
+
return;
|
|
20
|
+
index = JSON.parse(await readFile(indexFile, "utf8"));
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
if (!index || typeof index !== "object" || !Array.isArray(index.items))
|
|
26
|
+
return;
|
|
27
|
+
const items = index.items.filter((x) => !!x && typeof x === "object");
|
|
28
|
+
// 「P3 が描いた」は P3 だけが書く(エンジンが書いたものは消す)
|
|
29
|
+
let forged = false;
|
|
30
|
+
for (const item of items) {
|
|
31
|
+
if (!("rendered" in item))
|
|
32
|
+
continue;
|
|
33
|
+
forged = true;
|
|
34
|
+
delete item.rendered;
|
|
35
|
+
}
|
|
36
|
+
const jobs = [];
|
|
37
|
+
const byId = new Map();
|
|
38
|
+
for (const item of items) {
|
|
39
|
+
if (item.file !== undefined || item.html === undefined)
|
|
40
|
+
continue;
|
|
41
|
+
const id = String(item.id ?? "");
|
|
42
|
+
const html = safeRelative(item.html);
|
|
43
|
+
if (!html || !/\.html?$/i.test(html)) {
|
|
44
|
+
item.renderError = `原稿が ui/ の中の HTML ではありません: ${String(item.html)}`;
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
const st = await lstat(join(uiDir, html)).catch(() => undefined);
|
|
48
|
+
if (!st?.isFile() || st.size > RENDER_LIMITS.htmlBytes) {
|
|
49
|
+
item.renderError = !st ? `原稿がありません: ${html}` : st.isSymbolicLink() ? "原稿がシンボリックリンクです" : `原稿が読めません: ${html}`;
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
if (byId.has(id) || jobs.length >= RENDER_LIMITS.pages) {
|
|
53
|
+
item.renderError = byId.has(id) ? "id が重なっています" : `描画できるのは ${RENDER_LIMITS.pages} 枚までです`;
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
const viewport = Number(item.viewport);
|
|
57
|
+
jobs.push({ id, html: await readFile(join(uiDir, html), "utf8"), width: Number.isInteger(viewport) ? viewport : 1280 });
|
|
58
|
+
byId.set(id, item);
|
|
59
|
+
}
|
|
60
|
+
if (jobs.length) {
|
|
61
|
+
opts.log({ kind: "info", text: `画面イメージを描画します(${jobs.length} 枚。Codex の後に P3 が描きます)` });
|
|
62
|
+
try {
|
|
63
|
+
const results = await (opts.render ?? renderHtml)(jobs, uiDir, uiDir, opts);
|
|
64
|
+
for (const r of results) {
|
|
65
|
+
const item = byId.get(r.id);
|
|
66
|
+
if (r.ok) {
|
|
67
|
+
item.file = `${r.id}.png`;
|
|
68
|
+
item.rendered = { by: "p3", clipped: !!r.clipped, blocked: r.blocked.length };
|
|
69
|
+
delete item.renderError;
|
|
70
|
+
if (r.blocked.length)
|
|
71
|
+
opts.log({ kind: "info", text: `${r.id}: 読み込みを ${r.blocked.length} 件止めました` });
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
const error = r.error ?? "描画できませんでした";
|
|
75
|
+
item.renderError = error;
|
|
76
|
+
opts.log({ kind: "error", text: `${r.id} を描画できません: ${error}` });
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
catch (e) {
|
|
81
|
+
const message = e instanceof RenderError ? e.message : `描画できません: ${e.message}`;
|
|
82
|
+
opts.log({ kind: "error", text: `画面イメージを描画できません: ${message}` });
|
|
83
|
+
for (const item of byId.values())
|
|
84
|
+
item.renderError = message;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
if (forged || jobs.length || items.some((x) => x.renderError))
|
|
88
|
+
await writeFileAtomic(indexFile, JSON.stringify(index, null, 2) + "\n");
|
|
89
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { deflateSync } from "node:zlib";
|
|
2
|
+
export function wireframePng(width, height, boxes, background = 0xffffff) {
|
|
3
|
+
const row = width * 3 + 1;
|
|
4
|
+
const raw = Buffer.alloc(row * height);
|
|
5
|
+
const fill = (x0, y0, w, h, c) => {
|
|
6
|
+
for (let y = Math.max(0, y0); y < Math.min(height, y0 + h); y++) {
|
|
7
|
+
for (let x = Math.max(0, x0); x < Math.min(width, x0 + w); x++) {
|
|
8
|
+
const o = y * row + 1 + x * 3;
|
|
9
|
+
raw[o] = (c >> 16) & 0xff;
|
|
10
|
+
raw[o + 1] = (c >> 8) & 0xff;
|
|
11
|
+
raw[o + 2] = c & 0xff;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
fill(0, 0, width, height, background);
|
|
16
|
+
for (const [x, y, w, h, c] of boxes)
|
|
17
|
+
fill(x, y, w, h, c);
|
|
18
|
+
const chunk = (type, data) => {
|
|
19
|
+
const len = Buffer.alloc(4);
|
|
20
|
+
len.writeUInt32BE(data.length);
|
|
21
|
+
const body = Buffer.concat([Buffer.from(type, "latin1"), data]);
|
|
22
|
+
const crc = Buffer.alloc(4);
|
|
23
|
+
crc.writeUInt32BE(crc32(body));
|
|
24
|
+
return Buffer.concat([len, body, crc]);
|
|
25
|
+
};
|
|
26
|
+
const ihdr = Buffer.alloc(13);
|
|
27
|
+
ihdr.writeUInt32BE(width, 0);
|
|
28
|
+
ihdr.writeUInt32BE(height, 4);
|
|
29
|
+
ihdr[8] = 8; // ビットの深さ
|
|
30
|
+
ihdr[9] = 2; // RGB
|
|
31
|
+
return Buffer.concat([
|
|
32
|
+
Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]),
|
|
33
|
+
chunk("IHDR", ihdr),
|
|
34
|
+
chunk("IDAT", deflateSync(raw)),
|
|
35
|
+
chunk("IEND", Buffer.alloc(0)),
|
|
36
|
+
]);
|
|
37
|
+
}
|
|
38
|
+
const TABLE = Array.from({ length: 256 }, (_, n) => {
|
|
39
|
+
let c = n;
|
|
40
|
+
for (let k = 0; k < 8; k++)
|
|
41
|
+
c = c & 1 ? 0xedb88320 ^ (c >>> 1) : c >>> 1;
|
|
42
|
+
return c >>> 0;
|
|
43
|
+
});
|
|
44
|
+
function crc32(buf) {
|
|
45
|
+
let c = 0xffffffff;
|
|
46
|
+
for (const b of buf)
|
|
47
|
+
c = TABLE[(c ^ b) & 0xff] ^ (c >>> 8);
|
|
48
|
+
return (c ^ 0xffffffff) >>> 0;
|
|
49
|
+
}
|
|
50
|
+
/** 一覧画面のワイヤーフレーム(見出し・絞り込み欄・ボタン・表の行) */
|
|
51
|
+
export function listScreenPng(rows = 5) {
|
|
52
|
+
const line = 0xcbd5e1;
|
|
53
|
+
const boxes = [
|
|
54
|
+
[24, 24, 320, 28, 0x1e293b],
|
|
55
|
+
[24, 72, 240, 32, line],
|
|
56
|
+
[276, 72, 160, 32, line],
|
|
57
|
+
[448, 72, 96, 32, 0x4f46e5],
|
|
58
|
+
[24, 124, 976, 36, 0xe2e8f0],
|
|
59
|
+
];
|
|
60
|
+
for (let i = 0; i < rows; i++)
|
|
61
|
+
boxes.push([24, 164 + i * 40, 976, 1, line], [40, 176 + i * 40, 200 + ((i * 53) % 160), 14, 0x94a3b8]);
|
|
62
|
+
return wireframePng(1024, 200 + rows * 40, boxes);
|
|
63
|
+
}
|