@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.
- 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-DdOGYj9z.js → appCtx-B-VRVOyv.js} +1 -1
- package/dist/web/assets/board-DAaVR04x.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/new-DLVnRvrB.js +1 -0
- package/dist/web/assets/{preflightInput-DMxqnvF8.js → preflightInput-BAeEJYUK.js} +1 -1
- 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 +220 -3
- package/docs/development.md +16 -9
- package/docs/how-to-use.md +72 -7
- 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} +8 -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 +10 -0
- package/dist/web/assets/Outputs-5Hby-S5Q.js +0 -1
- package/dist/web/assets/RequestStatus-CTkGjT02.js +0 -1
- package/dist/web/assets/TagInput-Rj3PNOAF.js +0 -1
- package/dist/web/assets/TaskDrawer-DtPhiYxP.js +0 -3
- package/dist/web/assets/_requestId-CGvAfIkB.js +0 -30
- package/dist/web/assets/_requestId-DxfYhgAq.js +0 -1
- package/dist/web/assets/board-wt47lfrE.js +0 -1
- package/dist/web/assets/done-C9Ct7ssb.js +0 -1
- package/dist/web/assets/index-BTFL2rpp.js +0 -12
- package/dist/web/assets/index-DAyBsvua.css +0 -2
- package/dist/web/assets/new-e4ID2vQV.js +0 -1
- package/dist/web/assets/preload-helper-DhIyFaOW.js +0 -1
- package/dist/web/assets/release-notes-CQ0d2r0k.js +0 -3
- package/dist/web/assets/requestData-BDZqyl35.js +0 -1
- package/dist/web/assets/routes-Bipv3lwJ.js +0 -2
- package/dist/web/assets/settings-Dwh8fj6p.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 -337
- package/src/cli/output.ts +0 -117
- package/src/cli/preflightCommands.ts +0 -245
- package/src/cli/project.ts +0 -675
- package/src/cli/readOnly.ts +0 -36
- package/src/cli/releaseNotesCommands.ts +0 -198
- package/src/cli/render.ts +0 -60
- package/src/cli/requestCommands.ts +0 -172
- 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/completeRequests.ts +0 -102
- 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 -110
- 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 -135
- package/src/server/api/projectsRoutes.ts +0 -89
- package/src/server/api/releaseNoteRoutes.ts +0 -89
- 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/milestoneOrder.ts +0 -44
- 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 -730
- 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,324 @@
|
|
|
1
|
+
import { inflateRawSync } from "node:zlib";
|
|
2
|
+
import { posix } from "node:path";
|
|
3
|
+
import { imageInfo, UI_LIMITS } from "./uiMaterials.js";
|
|
4
|
+
/**
|
|
5
|
+
* xlsx から、セルの文字・保存済みの値と、標準の埋め込み画像(PNG / JPEG)を取り出す(補助の仕様書として Preflight に渡す)。
|
|
6
|
+
*
|
|
7
|
+
* - 数式は計算しない。保存済みの値があればそれを、無ければ「未確認」とする
|
|
8
|
+
* - 外部のブックや URL は取りに行かない。マクロ・OLE は動かさない(見つけたら未対応として記録する)
|
|
9
|
+
* - XML の DOCTYPE(外部実体)は断る。実体は XML の決まった5つと数値の参照だけを戻す
|
|
10
|
+
* - 図形・グラフ・リンクの画像・EMF などは描かない(見つけたら未対応として記録する)。Excel の見た目は再現しない
|
|
11
|
+
* - ZIP の展開後の大きさ・項目数・セル数・画像の数と大きさ・処理時間に上限があり、超えたら打ち切りを記録する
|
|
12
|
+
*/
|
|
13
|
+
export const XLSX_LIMITS = {
|
|
14
|
+
entries: 10_000,
|
|
15
|
+
/** 1つの項目の展開後の大きさ */
|
|
16
|
+
entryBytes: 30 * 1024 * 1024,
|
|
17
|
+
/** 展開した合計 */
|
|
18
|
+
totalBytes: 200 * 1024 * 1024,
|
|
19
|
+
cells: 50_000,
|
|
20
|
+
/** 取り出した文字の合計 */
|
|
21
|
+
textChars: 1_000_000,
|
|
22
|
+
images: 20,
|
|
23
|
+
timeMs: 10_000,
|
|
24
|
+
};
|
|
25
|
+
export class XlsxError extends Error {
|
|
26
|
+
}
|
|
27
|
+
function readEntries(buf) {
|
|
28
|
+
let eocd = -1;
|
|
29
|
+
for (let i = buf.length - 22; i >= Math.max(0, buf.length - 65_557); i--) {
|
|
30
|
+
if (buf.readUInt32LE(i) === 0x06054b50) {
|
|
31
|
+
eocd = i;
|
|
32
|
+
break;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if (eocd < 0)
|
|
36
|
+
throw new XlsxError("ZIP の終わりが見つかりません");
|
|
37
|
+
const count = buf.readUInt16LE(eocd + 10);
|
|
38
|
+
if (count > XLSX_LIMITS.entries)
|
|
39
|
+
throw new XlsxError(`中のファイルが多すぎます(${count})`);
|
|
40
|
+
let at = buf.readUInt32LE(eocd + 16);
|
|
41
|
+
const map = new Map();
|
|
42
|
+
for (let i = 0; i < count; i++) {
|
|
43
|
+
if (at + 46 > buf.length || buf.readUInt32LE(at) !== 0x02014b50)
|
|
44
|
+
throw new XlsxError("ZIP の一覧が壊れています");
|
|
45
|
+
const nameLen = buf.readUInt16LE(at + 28);
|
|
46
|
+
const name = buf.toString("utf8", at + 46, at + 46 + nameLen);
|
|
47
|
+
map.set(name, {
|
|
48
|
+
name,
|
|
49
|
+
method: buf.readUInt16LE(at + 10),
|
|
50
|
+
compressed: buf.readUInt32LE(at + 20),
|
|
51
|
+
uncompressed: buf.readUInt32LE(at + 24),
|
|
52
|
+
offset: buf.readUInt32LE(at + 42),
|
|
53
|
+
});
|
|
54
|
+
at += 46 + nameLen + buf.readUInt16LE(at + 30) + buf.readUInt16LE(at + 32);
|
|
55
|
+
}
|
|
56
|
+
return map;
|
|
57
|
+
}
|
|
58
|
+
class Zip {
|
|
59
|
+
buf;
|
|
60
|
+
entries;
|
|
61
|
+
used = 0;
|
|
62
|
+
constructor(buf) {
|
|
63
|
+
this.buf = buf;
|
|
64
|
+
this.entries = readEntries(buf);
|
|
65
|
+
}
|
|
66
|
+
has(name) {
|
|
67
|
+
return this.entries.has(name);
|
|
68
|
+
}
|
|
69
|
+
names() {
|
|
70
|
+
return [...this.entries.keys()];
|
|
71
|
+
}
|
|
72
|
+
read(name) {
|
|
73
|
+
const e = this.entries.get(name);
|
|
74
|
+
if (!e)
|
|
75
|
+
return undefined;
|
|
76
|
+
const at = e.offset;
|
|
77
|
+
if (at + 30 > this.buf.length || this.buf.readUInt32LE(at) !== 0x04034b50)
|
|
78
|
+
throw new XlsxError(`${name}: ZIP の項目が壊れています`);
|
|
79
|
+
const start = at + 30 + this.buf.readUInt16LE(at + 26) + this.buf.readUInt16LE(at + 28);
|
|
80
|
+
const raw = this.buf.subarray(start, start + e.compressed);
|
|
81
|
+
const limit = Math.min(XLSX_LIMITS.entryBytes, XLSX_LIMITS.totalBytes - this.used);
|
|
82
|
+
let out;
|
|
83
|
+
if (e.method === 0)
|
|
84
|
+
out = Buffer.from(raw);
|
|
85
|
+
else if (e.method === 8) {
|
|
86
|
+
try {
|
|
87
|
+
out = inflateRawSync(raw, { maxOutputLength: limit + 1 });
|
|
88
|
+
}
|
|
89
|
+
catch (err) {
|
|
90
|
+
if (err.code === "ERR_BUFFER_TOO_LARGE" || /too large|maxOutputLength/i.test(err.message)) {
|
|
91
|
+
throw new XlsxError(`${name}: 展開すると大きすぎます`);
|
|
92
|
+
}
|
|
93
|
+
throw new XlsxError(`${name}: 展開できません`);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
else
|
|
97
|
+
throw new XlsxError(`${name}: 対応していない圧縮方式です(${e.method})`);
|
|
98
|
+
if (out.length > limit)
|
|
99
|
+
throw new XlsxError(`${name}: 展開すると大きすぎます`);
|
|
100
|
+
this.used += out.length;
|
|
101
|
+
return out;
|
|
102
|
+
}
|
|
103
|
+
text(name) {
|
|
104
|
+
const b = this.read(name);
|
|
105
|
+
if (!b)
|
|
106
|
+
return undefined;
|
|
107
|
+
const s = b.toString("utf8");
|
|
108
|
+
// 外部実体を使わせない(DOCTYPE があれば読まない)
|
|
109
|
+
if (/<!DOCTYPE/i.test(s))
|
|
110
|
+
throw new XlsxError(`${name}: DOCTYPE を含む XML は読みません`);
|
|
111
|
+
// 要素の名前空間の接頭辞(xdr: a: x: など。書いたソフトで違う)を外す。属性(r:id など)はそのまま
|
|
112
|
+
return s.replace(/<(\/?)[A-Za-z_][\w.-]*:(?=[A-Za-z_])/g, "<$1");
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
/** XML の文字を戻す(決まった5つと数値の参照だけ) */
|
|
116
|
+
export function unescapeXml(s) {
|
|
117
|
+
return s.replace(/&(#x[0-9a-f]+|#\d+|lt|gt|amp|quot|apos);/gi, (_, e) => {
|
|
118
|
+
const k = e.toLowerCase();
|
|
119
|
+
if (k === "lt")
|
|
120
|
+
return "<";
|
|
121
|
+
if (k === "gt")
|
|
122
|
+
return ">";
|
|
123
|
+
if (k === "amp")
|
|
124
|
+
return "&";
|
|
125
|
+
if (k === "quot")
|
|
126
|
+
return '"';
|
|
127
|
+
if (k === "apos")
|
|
128
|
+
return "'";
|
|
129
|
+
const n = k.startsWith("#x") ? parseInt(k.slice(2), 16) : parseInt(k.slice(1), 10);
|
|
130
|
+
return Number.isFinite(n) && n > 0 && n <= 0x10ffff ? String.fromCodePoint(n) : "";
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
const attr = (tag, name) => {
|
|
134
|
+
const m = new RegExp(`\\s${name.replace(":", "\\:")}\\s*=\\s*("([^"]*)"|'([^']*)')`).exec(tag);
|
|
135
|
+
return m ? unescapeXml(m[2] ?? m[3] ?? "") : undefined;
|
|
136
|
+
};
|
|
137
|
+
/** <t> の文字を全部つなぐ(リッチテキストの断片を含む。ふりがな rPh は除く) */
|
|
138
|
+
const texts = (xml) => [...xml.replace(/<rPh\b[\s\S]*?<\/rPh>/g, "").matchAll(/<t(?:\s[^>]*)?>([\s\S]*?)<\/t>|<t(?:\s[^>]*)?\/>/g)].map((m) => unescapeXml(m[1] ?? "")).join("");
|
|
139
|
+
/** 関係(rels): Id → { target(ZIP の中のパス), type, external } */
|
|
140
|
+
function rels(zip, base) {
|
|
141
|
+
const file = posix.join(posix.dirname(base), "_rels", `${posix.basename(base)}.rels`);
|
|
142
|
+
const xml = zip.text(file);
|
|
143
|
+
const map = new Map();
|
|
144
|
+
if (!xml)
|
|
145
|
+
return map;
|
|
146
|
+
for (const m of xml.matchAll(/<Relationship\b[^>]*>/g)) {
|
|
147
|
+
const id = attr(m[0], "Id");
|
|
148
|
+
const target = attr(m[0], "Target") ?? "";
|
|
149
|
+
const external = attr(m[0], "TargetMode") === "External";
|
|
150
|
+
if (!id)
|
|
151
|
+
continue;
|
|
152
|
+
const resolved = external ? target : target.startsWith("/") ? target.slice(1) : posix.normalize(posix.join(posix.dirname(base), target));
|
|
153
|
+
map.set(id, { target: resolved, type: attr(m[0], "Type") ?? "", external });
|
|
154
|
+
}
|
|
155
|
+
return map;
|
|
156
|
+
}
|
|
157
|
+
const colName = (n) => {
|
|
158
|
+
let s = "";
|
|
159
|
+
for (let x = n + 1; x > 0; x = Math.floor((x - 1) / 26))
|
|
160
|
+
s = String.fromCharCode(65 + ((x - 1) % 26)) + s;
|
|
161
|
+
return s;
|
|
162
|
+
};
|
|
163
|
+
const md = (s) => s.replace(/\r\n?/g, "\n").replace(/\n/g, " ⏎ ").trim();
|
|
164
|
+
/** xlsx(固定した原本)から取り出す。ブックとして読めなければ XlsxError */
|
|
165
|
+
export function extractXlsx(data, title, now = Date.now) {
|
|
166
|
+
const started = now();
|
|
167
|
+
const zip = new Zip(data);
|
|
168
|
+
if (!zip.has("xl/workbook.xml"))
|
|
169
|
+
throw new XlsxError("xl/workbook.xml がありません(xlsx のブックではありません)");
|
|
170
|
+
const truncated = [];
|
|
171
|
+
const unsupported = new Set();
|
|
172
|
+
const out = [];
|
|
173
|
+
const images = [];
|
|
174
|
+
let cells = 0;
|
|
175
|
+
let unknownCells = 0;
|
|
176
|
+
let chars = 0;
|
|
177
|
+
const timeUp = () => now() - started > XLSX_LIMITS.timeMs;
|
|
178
|
+
if (zip.names().some((n) => /vbaProject\.bin$/i.test(n)))
|
|
179
|
+
unsupported.add("マクロ(実行しません)");
|
|
180
|
+
if (zip.names().some((n) => n.startsWith("xl/embeddings/")))
|
|
181
|
+
unsupported.add("埋め込みのオブジェクト(OLE。開きません)");
|
|
182
|
+
if (zip.names().some((n) => n.startsWith("xl/externalLinks/")))
|
|
183
|
+
unsupported.add("外部のブックへの参照(取りに行きません)");
|
|
184
|
+
if (zip.names().some((n) => n.startsWith("xl/charts/")))
|
|
185
|
+
unsupported.add("グラフ(描きません)");
|
|
186
|
+
const shared = [];
|
|
187
|
+
const ss = zip.text("xl/sharedStrings.xml");
|
|
188
|
+
if (ss)
|
|
189
|
+
for (const m of ss.matchAll(/<si>([\s\S]*?)<\/si>|<si\/>/g))
|
|
190
|
+
shared.push(texts(m[1] ?? ""));
|
|
191
|
+
const wbXml = zip.text("xl/workbook.xml");
|
|
192
|
+
const wbRels = rels(zip, "xl/workbook.xml");
|
|
193
|
+
const sheets = [...wbXml.matchAll(/<sheet\b[^>]*>/g)].map((m) => ({ name: attr(m[0], "name") ?? "?", rid: attr(m[0], "r:id") ?? "", state: attr(m[0], "state") }));
|
|
194
|
+
let done = 0;
|
|
195
|
+
for (const sheet of sheets) {
|
|
196
|
+
if (timeUp()) {
|
|
197
|
+
truncated.push(`時間の上限(${XLSX_LIMITS.timeMs / 1000} 秒)で、シート「${sheet.name}」から先を読んでいません`);
|
|
198
|
+
break;
|
|
199
|
+
}
|
|
200
|
+
const rel = wbRels.get(sheet.rid);
|
|
201
|
+
if (!rel || rel.external || !rel.target.startsWith("xl/")) {
|
|
202
|
+
out.push(`## シート「${sheet.name}」\n(読めません: シートの場所が分かりません)`);
|
|
203
|
+
continue;
|
|
204
|
+
}
|
|
205
|
+
const xml = zip.text(rel.target);
|
|
206
|
+
if (!xml) {
|
|
207
|
+
out.push(`## シート「${sheet.name}」\n(読めません: ${rel.target} がありません)`);
|
|
208
|
+
continue;
|
|
209
|
+
}
|
|
210
|
+
done++;
|
|
211
|
+
const lines = [`## シート「${sheet.name}」${sheet.state === "hidden" || sheet.state === "veryHidden" ? "(非表示のシート)" : ""}`];
|
|
212
|
+
const merges = [...xml.matchAll(/<mergeCell\b[^>]*>/g)].map((m) => attr(m[0], "ref")).filter(Boolean);
|
|
213
|
+
if (merges.length)
|
|
214
|
+
lines.push(`結合セル: ${merges.slice(0, 200).join(", ")}${merges.length > 200 ? ` ほか ${merges.length - 200}` : ""}`);
|
|
215
|
+
let stopped = false;
|
|
216
|
+
for (const m of xml.matchAll(/<c\b([^>]*?)(?:\/>|>([\s\S]*?)<\/c>)/g)) {
|
|
217
|
+
if (cells >= XLSX_LIMITS.cells || chars >= XLSX_LIMITS.textChars || timeUp()) {
|
|
218
|
+
truncated.push(`${cells >= XLSX_LIMITS.cells ? `セル数の上限(${XLSX_LIMITS.cells})` : chars >= XLSX_LIMITS.textChars ? "文字数の上限" : "時間の上限"}で、シート「${sheet.name}」の途中から先を読んでいません`);
|
|
219
|
+
stopped = true;
|
|
220
|
+
break;
|
|
221
|
+
}
|
|
222
|
+
const head = `<c${m[1]}>`;
|
|
223
|
+
const body = m[2] ?? "";
|
|
224
|
+
const ref = attr(head, "r") ?? "?";
|
|
225
|
+
const t = attr(head, "t");
|
|
226
|
+
const f = /<f\b[^>]*>([\s\S]*?)<\/f>|<f\b[^>]*\/>/.exec(body);
|
|
227
|
+
const v = /<v>([\s\S]*?)<\/v>/.exec(body)?.[1];
|
|
228
|
+
let value;
|
|
229
|
+
if (t === "s")
|
|
230
|
+
value = v !== undefined ? shared[Number(v)] : undefined;
|
|
231
|
+
else if (t === "inlineStr")
|
|
232
|
+
value = texts(/<is>([\s\S]*?)<\/is>/.exec(body)?.[1] ?? "");
|
|
233
|
+
else if (t === "b")
|
|
234
|
+
value = v === undefined ? undefined : v === "1" ? "TRUE" : "FALSE";
|
|
235
|
+
else if (t === "e")
|
|
236
|
+
value = v === undefined ? undefined : `エラー ${unescapeXml(v)}`;
|
|
237
|
+
else
|
|
238
|
+
value = v === undefined ? undefined : unescapeXml(v);
|
|
239
|
+
if (f) {
|
|
240
|
+
const formula = f[1] ? unescapeXml(f[1]) : "(共有の数式)";
|
|
241
|
+
if (value === undefined || value === "") {
|
|
242
|
+
unknownCells++;
|
|
243
|
+
lines.push(`- ${ref}: =${md(formula)} → (値が保存されていません。未確認)`);
|
|
244
|
+
}
|
|
245
|
+
else
|
|
246
|
+
lines.push(`- ${ref}: =${md(formula)} → ${md(value)}(保存済みの値)`);
|
|
247
|
+
}
|
|
248
|
+
else if (value !== undefined && value !== "")
|
|
249
|
+
lines.push(`- ${ref}: ${md(value)}`);
|
|
250
|
+
else
|
|
251
|
+
continue;
|
|
252
|
+
cells++;
|
|
253
|
+
chars += lines.at(-1).length;
|
|
254
|
+
}
|
|
255
|
+
// 標準の図(drawing)の画像
|
|
256
|
+
const sheetRels = rels(zip, rel.target);
|
|
257
|
+
for (const r of sheetRels.values()) {
|
|
258
|
+
if (r.external)
|
|
259
|
+
unsupported.add(`シート「${sheet.name}」の外部への参照(取りに行きません)`);
|
|
260
|
+
if (r.type.endsWith("/oleObject"))
|
|
261
|
+
unsupported.add(`シート「${sheet.name}」の埋め込みのオブジェクト(OLE)`);
|
|
262
|
+
}
|
|
263
|
+
const drawing = [...sheetRels.values()].find((r) => r.type.endsWith("/drawing") && !r.external);
|
|
264
|
+
if (drawing && !stopped)
|
|
265
|
+
lines.push(...readDrawing(zip, drawing.target, sheet.name, images, truncated, unsupported));
|
|
266
|
+
out.push(lines.join("\n"));
|
|
267
|
+
}
|
|
268
|
+
const head = [
|
|
269
|
+
`# ${title} から取り出した内容`,
|
|
270
|
+
`範囲: シート ${done}/${sheets.length}・セル ${cells}・画像 ${images.length}${unknownCells ? `・値が保存されていない数式 ${unknownCells}(未確認)` : ""}`,
|
|
271
|
+
"セルの文字と保存済みの値だけです。数式は計算していません。書式・図形・グラフなど見た目は再現していません。",
|
|
272
|
+
...(truncated.length ? ["打ち切り:", ...truncated.map((x) => `- ${x}`)] : []),
|
|
273
|
+
...(unsupported.size ? ["扱っていないもの(中身は未確認):", ...[...unsupported].map((x) => `- ${x}`)] : []),
|
|
274
|
+
];
|
|
275
|
+
return { text: `${[head.join("\n"), ...out].join("\n\n")}\n`, sheets: done, cells, images, unknownCells, truncated, unsupported: [...unsupported] };
|
|
276
|
+
}
|
|
277
|
+
function readDrawing(zip, path, sheet, images, truncated, unsupported) {
|
|
278
|
+
const xml = zip.text(path);
|
|
279
|
+
if (!xml)
|
|
280
|
+
return [];
|
|
281
|
+
const dRels = rels(zip, path);
|
|
282
|
+
const lines = [];
|
|
283
|
+
for (const m of xml.matchAll(/<(twoCellAnchor|oneCellAnchor|absoluteAnchor)\b[\s\S]*?<\/\1>/g)) {
|
|
284
|
+
const a = m[0];
|
|
285
|
+
const col = /<from>[\s\S]*?<col>(\d+)<\/col>[\s\S]*?<row>(\d+)<\/row>/.exec(a);
|
|
286
|
+
const anchor = col ? `${colName(Number(col[1]))}${Number(col[2]) + 1}` : "(位置不明)";
|
|
287
|
+
if (/<pic\b/.test(a)) {
|
|
288
|
+
const embed = /<blip\b[^>]*r:embed\s*=\s*"([^"]+)"/.exec(a)?.[1];
|
|
289
|
+
const link = /<blip\b[^>]*r:link\s*=\s*"([^"]+)"/.exec(a)?.[1];
|
|
290
|
+
if (link && !embed) {
|
|
291
|
+
unsupported.add(`シート「${sheet}」${anchor} のリンクの画像(取りに行きません)`);
|
|
292
|
+
continue;
|
|
293
|
+
}
|
|
294
|
+
const r = embed ? dRels.get(embed) : undefined;
|
|
295
|
+
if (!r || r.external) {
|
|
296
|
+
unsupported.add(`シート「${sheet}」${anchor} の画像(場所が分かりません)`);
|
|
297
|
+
continue;
|
|
298
|
+
}
|
|
299
|
+
if (images.length >= XLSX_LIMITS.images) {
|
|
300
|
+
truncated.push(`画像の数の上限(${XLSX_LIMITS.images})で、シート「${sheet}」${anchor} から先の画像を取り出していません`);
|
|
301
|
+
break;
|
|
302
|
+
}
|
|
303
|
+
const data = zip.read(r.target);
|
|
304
|
+
const info = data && imageInfo(data);
|
|
305
|
+
if (!data || !info) {
|
|
306
|
+
unsupported.add(`シート「${sheet}」${anchor} の画像(${posix.extname(r.target).slice(1) || "形式不明"}。PNG / JPEG ではありません)`);
|
|
307
|
+
continue;
|
|
308
|
+
}
|
|
309
|
+
if (data.length > UI_LIMITS.bytes || info.width > UI_LIMITS.width || info.height > UI_LIMITS.height) {
|
|
310
|
+
unsupported.add(`シート「${sheet}」${anchor} の画像(大きすぎます)`);
|
|
311
|
+
continue;
|
|
312
|
+
}
|
|
313
|
+
images.push({ sheet, anchor, ...info, data });
|
|
314
|
+
lines.push(`- 画像 ${images.length}: ${anchor} に置かれた ${info.format.toUpperCase()}(${info.width}x${info.height})`);
|
|
315
|
+
}
|
|
316
|
+
else if (/<graphicFrame\b/.test(a))
|
|
317
|
+
unsupported.add(`シート「${sheet}」${anchor} のグラフ・図表(描きません)`);
|
|
318
|
+
else if (/<(sp|grpSp|cxnSp)\b/.test(a)) {
|
|
319
|
+
const label = texts(a);
|
|
320
|
+
unsupported.add(`シート「${sheet}」${anchor} の図形(描きません${label ? `。中の文字: ${md(label).slice(0, 80)}` : ""})`);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
return lines;
|
|
324
|
+
}
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { realpath } from "node:fs/promises";
|
|
3
|
+
import { openProject } from "./context.js";
|
|
4
|
+
import { inspectUserProjects, PROJECT_NAME, userConfigPath } from "./userConfig.js";
|
|
5
|
+
/** 開けない(unknown: 登録に無い / changed: 登録世代が違う / duplicate: 同じデータを複数の名前で登録 / unavailable: 開けない) */
|
|
6
|
+
export class RegistryError extends Error {
|
|
7
|
+
code;
|
|
8
|
+
constructor(code, message) {
|
|
9
|
+
super(message);
|
|
10
|
+
this.code = code;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export class ProjectRegistry {
|
|
14
|
+
opts;
|
|
15
|
+
entries = new Map();
|
|
16
|
+
invalid = [];
|
|
17
|
+
configError;
|
|
18
|
+
counter = 0;
|
|
19
|
+
refreshing = Promise.resolve({ projects: [], invalid: [] });
|
|
20
|
+
/** 登録から外れて、実行中の処理が終わるのを待っている文脈 */
|
|
21
|
+
retiring = new Set();
|
|
22
|
+
listeners = new Set();
|
|
23
|
+
closed = false;
|
|
24
|
+
constructor(opts) {
|
|
25
|
+
this.opts = opts;
|
|
26
|
+
}
|
|
27
|
+
get chatgpt() {
|
|
28
|
+
return this.opts.chatgpt;
|
|
29
|
+
}
|
|
30
|
+
/** 個人設定から一覧を読み直す(同時に呼ばれたら順に) */
|
|
31
|
+
refresh() {
|
|
32
|
+
this.refreshing = this.refreshing.then(() => this.load(), () => this.load());
|
|
33
|
+
return this.refreshing;
|
|
34
|
+
}
|
|
35
|
+
list() {
|
|
36
|
+
const projects = [...this.entries.values()]
|
|
37
|
+
.sort((a, b) => a.name.localeCompare(b.name))
|
|
38
|
+
.map((e) => {
|
|
39
|
+
const error = e.duplicate ?? e.error;
|
|
40
|
+
return { name: e.name, generation: e.generation, state: error ? "error" : "ok", ...(error ? { error } : {}), open: !!e.ctx };
|
|
41
|
+
});
|
|
42
|
+
return { projects, invalid: this.invalid, ...(this.configError ? { configError: this.configError } : {}) };
|
|
43
|
+
}
|
|
44
|
+
/** 登録した名前の文脈(必要なら開く)。generation を渡したら、今の登録世代と同じときだけ */
|
|
45
|
+
async open(name, generation) {
|
|
46
|
+
if (this.closed)
|
|
47
|
+
throw new RegistryError("unavailable", "serve を止めています");
|
|
48
|
+
const e = PROJECT_NAME.test(name) ? this.entries.get(name) : undefined;
|
|
49
|
+
if (!e)
|
|
50
|
+
throw new RegistryError("unknown", `プロジェクト「${name}」は個人設定に登録されていません(p3 project ls で確かめ、画面の一覧を読み直してください)`);
|
|
51
|
+
if (generation !== undefined && generation !== e.generation) {
|
|
52
|
+
throw new RegistryError("changed", `プロジェクト「${name}」の登録が変わりました(外した・付け直した・データのフォルダを変えた)。一覧を読み直して選び直してください(入力は送っていません)`);
|
|
53
|
+
}
|
|
54
|
+
if (e.duplicate)
|
|
55
|
+
throw new RegistryError("duplicate", e.duplicate);
|
|
56
|
+
if (!e.ctx) {
|
|
57
|
+
e.ctx = (this.opts.open ?? openProject)(e.dir, { repos: e.repos, settings: this.opts.settings, projectName: e.name, chatgpt: this.opts.chatgpt });
|
|
58
|
+
e.ctx.then((ctx) => {
|
|
59
|
+
e.error = undefined;
|
|
60
|
+
void ctx.ws.watch();
|
|
61
|
+
// 開いている間に登録から外れた・変わった: 新しい要求には使わせず閉じる
|
|
62
|
+
if (this.entries.get(name) !== e || this.closed)
|
|
63
|
+
this.retire(ctx);
|
|
64
|
+
}, (err) => {
|
|
65
|
+
// 覚えずに次の open でやり直す(フォルダを戻した・共有ドライブをつないだら使える)
|
|
66
|
+
if (this.entries.get(name) === e) {
|
|
67
|
+
e.ctx = undefined;
|
|
68
|
+
e.error = err.message;
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
try {
|
|
73
|
+
const ctx = await e.ctx;
|
|
74
|
+
if (this.entries.get(name) !== e)
|
|
75
|
+
throw new RegistryError("changed", `プロジェクト「${name}」の登録が変わりました。一覧を読み直して選び直してください`);
|
|
76
|
+
return ctx;
|
|
77
|
+
}
|
|
78
|
+
catch (err) {
|
|
79
|
+
if (err instanceof RegistryError)
|
|
80
|
+
throw err;
|
|
81
|
+
throw new RegistryError("unavailable", `プロジェクト「${name}」を開けません: ${err.message}`);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/** 開いている文脈(変更の知らせを全部へ流すため) */
|
|
85
|
+
async openContexts() {
|
|
86
|
+
const opened = await Promise.allSettled([...this.entries.values()].flatMap((e) => (e.ctx ? [e.ctx] : [])));
|
|
87
|
+
return opened.flatMap((r) => (r.status === "fulfilled" ? [r.value] : []));
|
|
88
|
+
}
|
|
89
|
+
/** プロジェクトに属さない変更(一覧・テーマ・ChatGPT の接続)を知らせる。開いている全プロジェクトの画面にも流す */
|
|
90
|
+
notify(kind) {
|
|
91
|
+
for (const l of this.listeners)
|
|
92
|
+
l(kind);
|
|
93
|
+
if (kind === "projects")
|
|
94
|
+
return;
|
|
95
|
+
void this.openContexts().then((all) => all.forEach((ctx) => ctx.ws.emit({ type: "changed", kind })));
|
|
96
|
+
}
|
|
97
|
+
on(listener) {
|
|
98
|
+
this.listeners.add(listener);
|
|
99
|
+
return () => this.listeners.delete(listener);
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* 止める。新しい要求は断り、実行中の Preflight・生成を取り消して終わるまで待つ(timeoutMs まで)。監視を外す。
|
|
103
|
+
* 待ちきれなかった数を返す
|
|
104
|
+
*/
|
|
105
|
+
async close(opts = {}) {
|
|
106
|
+
this.closed = true;
|
|
107
|
+
const all = await this.openContexts();
|
|
108
|
+
for (const e of this.entries.values())
|
|
109
|
+
e.ctx = undefined;
|
|
110
|
+
const settle = Promise.all([
|
|
111
|
+
...all.map(async (ctx) => {
|
|
112
|
+
await Promise.all([ctx.preflight.settle({ cancel: true }), ctx.releaseGenerator.settle({ cancel: true })]);
|
|
113
|
+
ctx.ws.close();
|
|
114
|
+
}),
|
|
115
|
+
...this.retiring,
|
|
116
|
+
]).then(() => false);
|
|
117
|
+
const timedOut = await Promise.race([settle, new Promise((r) => setTimeout(() => r(true), opts.timeoutMs ?? 10_000).unref())]);
|
|
118
|
+
for (const ctx of all)
|
|
119
|
+
ctx.ws.close();
|
|
120
|
+
return { pending: timedOut ? all.reduce((n, c) => n + c.preflight.running() + c.releaseGenerator.running(), 0) : 0 };
|
|
121
|
+
}
|
|
122
|
+
async load() {
|
|
123
|
+
let projects;
|
|
124
|
+
try {
|
|
125
|
+
const r = await inspectUserProjects(this.opts.configPath ?? userConfigPath());
|
|
126
|
+
projects = r.projects;
|
|
127
|
+
this.invalid = r.invalid;
|
|
128
|
+
this.configError = undefined;
|
|
129
|
+
}
|
|
130
|
+
catch (e) {
|
|
131
|
+
// 読めない・壊れている: 今の一覧と開いている文脈はそのまま(直して読み直せば戻る)
|
|
132
|
+
this.configError = e.message;
|
|
133
|
+
return this.list();
|
|
134
|
+
}
|
|
135
|
+
const before = this.list();
|
|
136
|
+
for (const [name, e] of this.entries) {
|
|
137
|
+
const next = projects[name];
|
|
138
|
+
if (!next || next.dir !== e.dir)
|
|
139
|
+
this.drop(name, e);
|
|
140
|
+
}
|
|
141
|
+
for (const [name, p] of Object.entries(projects)) {
|
|
142
|
+
const cur = this.entries.get(name);
|
|
143
|
+
if (cur) {
|
|
144
|
+
// 参照先のパスだけの変更は今の文脈に反映する(次の Preflight から使う)
|
|
145
|
+
if (JSON.stringify(cur.repos) !== JSON.stringify(p.repos)) {
|
|
146
|
+
const old = cur.repos;
|
|
147
|
+
cur.repos = { ...p.repos };
|
|
148
|
+
void cur.ctx?.then((ctx) => {
|
|
149
|
+
for (const k of Object.keys(old))
|
|
150
|
+
if (!(k in p.repos))
|
|
151
|
+
ctx.ws.setLocalRepo(k, null);
|
|
152
|
+
for (const [k, v] of Object.entries(p.repos))
|
|
153
|
+
if (old[k] !== v)
|
|
154
|
+
ctx.ws.setLocalRepo(k, v);
|
|
155
|
+
}, () => undefined);
|
|
156
|
+
}
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
this.entries.set(name, { name, dir: p.dir, repos: { ...p.repos }, generation: this.nextGeneration(p.dir) });
|
|
160
|
+
}
|
|
161
|
+
await this.markDuplicates();
|
|
162
|
+
const after = this.list();
|
|
163
|
+
if (JSON.stringify(before) !== JSON.stringify(after))
|
|
164
|
+
this.notify("projects");
|
|
165
|
+
return after;
|
|
166
|
+
}
|
|
167
|
+
/** 登録から外す。新しい要求には使わせず、実行中の処理が終わってから閉じる */
|
|
168
|
+
drop(name, e) {
|
|
169
|
+
this.entries.delete(name);
|
|
170
|
+
void e.ctx?.then((ctx) => this.retire(ctx), () => undefined);
|
|
171
|
+
}
|
|
172
|
+
retire(ctx) {
|
|
173
|
+
const p = Promise.all([ctx.preflight.settle(), ctx.releaseGenerator.settle()]).then(() => ctx.ws.close());
|
|
174
|
+
this.retiring.add(p);
|
|
175
|
+
void p.finally(() => this.retiring.delete(p));
|
|
176
|
+
}
|
|
177
|
+
/** 同じ実体のフォルダを指す登録は、どれも開かない(どれを使うかは人が個人設定で決める) */
|
|
178
|
+
async markDuplicates() {
|
|
179
|
+
const real = new Map();
|
|
180
|
+
for (const e of this.entries.values()) {
|
|
181
|
+
const key = await realpath(e.dir).catch(() => e.dir);
|
|
182
|
+
real.set(key, [...(real.get(key) ?? []), e.name]);
|
|
183
|
+
}
|
|
184
|
+
for (const names of real.values()) {
|
|
185
|
+
for (const name of names) {
|
|
186
|
+
const e = this.entries.get(name);
|
|
187
|
+
const was = e.duplicate;
|
|
188
|
+
e.duplicate =
|
|
189
|
+
names.length > 1
|
|
190
|
+
? `同じデータのフォルダを複数の名前で登録しています: ${names.join(", ")}(二重に動かさないため、どれも開きません。p3 project rm <名前> で1つにしてください)`
|
|
191
|
+
: undefined;
|
|
192
|
+
// 重なりを外して開けるようになったら、別の登録として世代を変える
|
|
193
|
+
if (was && !e.duplicate)
|
|
194
|
+
e.generation = this.nextGeneration(e.dir);
|
|
195
|
+
if (!was && e.duplicate && e.ctx) {
|
|
196
|
+
const ctx = e.ctx;
|
|
197
|
+
e.ctx = undefined;
|
|
198
|
+
void ctx.then((c) => this.retire(c), () => undefined);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
nextGeneration(dir) {
|
|
204
|
+
this.counter += 1;
|
|
205
|
+
return `${createHash("sha256").update(dir).digest("hex").slice(0, 8)}-${this.counter}`;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Preflight のログ・エラーに残す前に、トークンらしいものを伏せる。
|
|
3
|
+
* - Codex がエラーで一部だけ見せるキー(例: `Incorrect API key provided: eyJhbGci***xyz`)
|
|
4
|
+
* - JWT(ChatGPT の access token / ID トークンの形)
|
|
5
|
+
* - Authorization: Bearer の値
|
|
6
|
+
* 本物の値を知っている呼び出し側は、secrets に渡せばそれも伏せる。
|
|
7
|
+
*/
|
|
8
|
+
export const REDACTED = "[伏せました]";
|
|
9
|
+
const PATTERNS = [
|
|
10
|
+
// 一部を *** で隠した値(前後の残りも消す)
|
|
11
|
+
/[A-Za-z0-9._~+/=-]*\*{3,}[A-Za-z0-9._~+/=-]*/g,
|
|
12
|
+
// JWT
|
|
13
|
+
/eyJ[A-Za-z0-9_-]{4,}\.[A-Za-z0-9_-]{4,}\.[A-Za-z0-9_-]*/g,
|
|
14
|
+
// Bearer の値
|
|
15
|
+
/(Bearer\s+)[A-Za-z0-9._~+/=-]+/gi,
|
|
16
|
+
];
|
|
17
|
+
export function redact(text, secrets = []) {
|
|
18
|
+
let out = text;
|
|
19
|
+
for (const s of secrets)
|
|
20
|
+
if (s && s.length >= 8)
|
|
21
|
+
out = out.split(s).join(REDACTED);
|
|
22
|
+
return PATTERNS.reduce((t, re) => t.replace(re, (m, bearer) => {
|
|
23
|
+
if (typeof bearer === "string" && /^Bearer/i.test(m))
|
|
24
|
+
return `${bearer}${REDACTED}`;
|
|
25
|
+
// 文の終わりの「.」は値の一部ではないので残す
|
|
26
|
+
return `${REDACTED}${/\.+$/.exec(m)?.[0] ?? ""}`;
|
|
27
|
+
}), out);
|
|
28
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { updateRequest } from "../requestOps.js";
|
|
2
|
+
import { hierarchyNow, resolveBlocker } from "../requestStatus.js";
|
|
3
|
+
import { ConflictError } from "../store/collection.js";
|
|
4
|
+
import { Workspace } from "../store/workspace.js";
|
|
5
|
+
import { materialOf } from "./material.js";
|
|
6
|
+
import { checkMilestoneId, ReleaseNoteError } from "./store.js";
|
|
7
|
+
/**
|
|
8
|
+
* マイルストーンの要望を一括で完了済にする。規則はここだけに置く(CLI・API・画面は判定を見せて、表示したときの材料の hash で頼むだけ)。
|
|
9
|
+
*
|
|
10
|
+
* - 判定は材料(material.ts の収録の条件)と同じ: 見送りを除く全要望が収録できる(対応済か完了済・タスクが1件以上で全部完了・
|
|
11
|
+
* 読めないタスクなし)ときだけできる。マイルストーンが project.yaml に無い・所属の分からない読めない要望があればできない
|
|
12
|
+
* - 変えるのは対応済(resolved)の要望のステータスだけ(→ done)。完了済・見送り・アーカイブした要望、タスク(状態・済み)、
|
|
13
|
+
* マイルストーン、ノートは変えない。変更の記録が無い・ノートを保存していない・済みが無いことは条件にしない
|
|
14
|
+
* - 実行はディスクから読み直した材料で判定し直し、表示したときの hash と違えば何も書かない(material_changed)。できなければ
|
|
15
|
+
* 何も書かない(blocked)
|
|
16
|
+
* - 子のある要望は配下が終わっているときだけ(material.ts)。子から親の順に書く
|
|
17
|
+
* - 複数のファイルをまとめて書く仕組みは無いので、1件ずつ書く。書く直前に、タスクを読み直して確かめ、要望は判定したときの rev で
|
|
18
|
+
* 書く(違えば競合)。途中で失敗したら止め、完了済にしたもの・失敗した1件・まだ変えていないものを返す(戻さない。外の変更を
|
|
19
|
+
* 上書きしないため)。やり直しは、取り直した判定でもう一度頼む(完了済にしたものは対象から外れ、書き直さない)
|
|
20
|
+
*/
|
|
21
|
+
/** 材料から判定する(書かない) */
|
|
22
|
+
export function completionPlanOf(material) {
|
|
23
|
+
const plan = { milestone: material.milestone.id, basedOn: material.hash, ready: false, targets: [], alreadyDone: [], skipped: [], blockers: [] };
|
|
24
|
+
if (!material.milestone.known)
|
|
25
|
+
plan.blockers.push({ target: material.milestone.id, reason: `マイルストーン ${material.milestone.id} は project.yaml にありません` });
|
|
26
|
+
for (const w of material.warnings.filter((x) => x.code === "broken_request"))
|
|
27
|
+
plan.blockers.push({ target: w.target, reason: w.message });
|
|
28
|
+
for (const r of material.requests) {
|
|
29
|
+
if (r.status === "rejected")
|
|
30
|
+
plan.skipped.push(r.id);
|
|
31
|
+
else if (!r.included) {
|
|
32
|
+
const open = r.tasks.filter((t) => t.status !== "done").map((t) => `${t.id}(${t.status})`);
|
|
33
|
+
const detail = r.reason === "完了していないタスクがある" && open.length ? `: ${open.join(", ")}` : "";
|
|
34
|
+
plan.blockers.push({ target: r.id, reason: `${r.title}(${r.id}): ${r.reason ?? "収録できません"}${detail}` });
|
|
35
|
+
}
|
|
36
|
+
else if (r.status === "resolved")
|
|
37
|
+
plan.targets.push({ id: r.id, title: r.title });
|
|
38
|
+
else
|
|
39
|
+
plan.alreadyDone.push(r.id);
|
|
40
|
+
}
|
|
41
|
+
plan.ready = plan.blockers.length === 0;
|
|
42
|
+
return plan;
|
|
43
|
+
}
|
|
44
|
+
/** 頼めない(何も書いていない)。material_changed: 表示したときの材料と違う / blocked: 未完了などがある。plan は今の判定 */
|
|
45
|
+
export class CompletionRejected extends Error {
|
|
46
|
+
code;
|
|
47
|
+
plan;
|
|
48
|
+
constructor(code, message, plan) {
|
|
49
|
+
super(message);
|
|
50
|
+
this.code = code;
|
|
51
|
+
this.plan = plan;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/** 今の判定(ディスクから読み直す) */
|
|
55
|
+
export async function completionPlan(ctx, mid) {
|
|
56
|
+
return (await snapshot(ctx, mid)).plan;
|
|
57
|
+
}
|
|
58
|
+
/** 一括で完了済にする。basedOn は判定を見せたときの材料の hash(必須) */
|
|
59
|
+
export async function completeMilestoneRequests(ctx, mid, basedOn, actor) {
|
|
60
|
+
const { snap, plan } = await snapshot(ctx, mid);
|
|
61
|
+
if (plan.basedOn !== basedOn) {
|
|
62
|
+
throw new CompletionRejected("material_changed", "表示したあとで、このマイルストーンの要望・タスクが変わりました。何も変えていません。読み直して確かめてから、もう一度実行してください", plan);
|
|
63
|
+
}
|
|
64
|
+
if (!plan.ready) {
|
|
65
|
+
throw new CompletionRejected("blocked", `完了済にできません(何も変えていません): ${plan.blockers.map((b) => b.reason).join(" / ")}`, plan);
|
|
66
|
+
}
|
|
67
|
+
const result = { milestone: mid, completed: [], notRun: [], alreadyDone: plan.alreadyDone };
|
|
68
|
+
// 子から親の順(深いものから)。親を完了済にする判定が、先に完了済にした子を見る
|
|
69
|
+
const h = hierarchyNow(snap);
|
|
70
|
+
const depth = (id) => h.ancestors(id).length;
|
|
71
|
+
const targets = [...plan.targets].sort((a, b) => depth(b.id) - depth(a.id));
|
|
72
|
+
for (const [i, t] of targets.entries()) {
|
|
73
|
+
try {
|
|
74
|
+
// タスクの変更は要望の rev に出ないので、書く直前に読み直して確かめる。要望(所属・状態)は判定したときの rev で確かめる
|
|
75
|
+
const why = await resolveBlocker(ctx.ws, t.id);
|
|
76
|
+
if (why) {
|
|
77
|
+
result.failed = { id: t.id, reason: why, code: "changed" };
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
await updateRequest(ctx, t.id, { status: "done" }, { expectedRev: snap.requests.require(t.id).rev, actor });
|
|
81
|
+
result.completed.push(t);
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
catch (e) {
|
|
86
|
+
result.failed =
|
|
87
|
+
e instanceof ConflictError
|
|
88
|
+
? { id: t.id, reason: `判定したあとで要望が変わりました(${e.message})`, code: "conflict" }
|
|
89
|
+
: { id: t.id, reason: e.message, code: "error" };
|
|
90
|
+
}
|
|
91
|
+
result.notRun = targets.slice(i + 1).map((x) => x.id);
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
return result;
|
|
95
|
+
}
|
|
96
|
+
/** ディスクから読み直した状態で、材料と判定を作る。project.yaml に無く、ノートも無いマイルストーンは not_found */
|
|
97
|
+
async function snapshot(ctx, mid) {
|
|
98
|
+
checkMilestoneId(mid);
|
|
99
|
+
const snap = new Workspace(ctx.ws.dataDir);
|
|
100
|
+
await snap.load();
|
|
101
|
+
const material = materialOf(snap, mid);
|
|
102
|
+
if (!material.milestone.known && !(await ctx.ws.releaseNotes.ids()).includes(mid)) {
|
|
103
|
+
throw new ReleaseNoteError("not_found", mid, `マイルストーンがありません: ${mid}`);
|
|
104
|
+
}
|
|
105
|
+
return { snap, material, plan: completionPlanOf(material) };
|
|
106
|
+
}
|