onionskin-cli 0.0.3 → 0.0.6
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/CHANGELOG.md +198 -0
- package/INSTALL.md +5 -1
- package/NOTICE +34 -0
- package/README.md +102 -34
- package/docs/contracts/batch.schema.json +27 -4
- package/docs/contracts/ops.schema.json +117 -5
- package/package.json +4 -2
- package/scripts/checker/check.py +24 -5
- package/scripts/checker/requirements.txt +482 -5
- package/scripts/requirements.txt +482 -5
- package/scripts/rewriter/apple/main.swift +1 -1
- package/scripts/rewriter/apple/onionskin-fm +0 -0
- package/scripts/rewriter/apple/onionskin-fm.json +1 -1
- package/skills/onionskin/SKILL.md +12 -9
- package/skills/onionskin/reference/batch.md +5 -3
- package/skills/onionskin/reference/formats.md +5 -1
- package/skills/onionskin/reference/ops.md +48 -4
- package/skills/onionskin/reference/troubleshooting.md +31 -0
- package/src/agent-detect.js +28 -2
- package/src/agent-prompt.js +12 -1
- package/src/agent-runner.js +110 -20
- package/src/anchor-work.js +154 -0
- package/src/anchor-worker.js +38 -0
- package/src/anchors.js +61 -11
- package/src/apply.js +119 -47
- package/src/batch.js +32 -8
- package/src/check-worker.js +8 -5
- package/src/checker.js +238 -33
- package/src/cli.js +248 -42
- package/src/constants.js +34 -1
- package/src/diff.js +3 -1
- package/src/doctor.js +12 -3
- package/src/docx.js +464 -87
- package/src/edit-hash.js +19 -0
- package/src/fsutil.js +14 -6
- package/src/history-worker.js +8 -8
- package/src/history.js +144 -31
- package/src/html-active.js +384 -0
- package/src/html-envelope.js +51 -0
- package/src/html-parser.js +8 -0
- package/src/html-render-worker.js +25 -0
- package/src/html-render.js +939 -0
- package/src/html-utf8.js +65 -0
- package/src/html-write-worker.js +14 -0
- package/src/html-write.js +380 -0
- package/src/html.js +1259 -0
- package/src/local.js +68 -4
- package/src/merge-package.js +1166 -0
- package/src/merge-pptx.js +98 -38
- package/src/merge-proof.js +1019 -0
- package/src/merge-worker.js +60 -0
- package/src/merge-xlsx.js +84 -29
- package/src/merge.js +286 -83
- package/src/nfc.js +46 -0
- package/src/notes.js +122 -0
- package/src/offload.js +419 -1
- package/src/open-worker.js +27 -0
- package/src/ops/common.js +2 -1
- package/src/ops/docx-table.js +5 -3
- package/src/ops/docx.js +58 -29
- package/src/ops/html.js +394 -0
- package/src/ops/pptx.js +82 -23
- package/src/ops/run.js +23 -3
- package/src/ops/runs.js +215 -13
- package/src/ops/schema.js +8 -1
- package/src/ops/xlsx.js +121 -10
- package/src/ops-worker.js +17 -0
- package/src/package.js +43 -4
- package/src/person.js +2 -1
- package/src/pptx.js +323 -23
- package/src/question.js +10 -3
- package/src/quick-plan.js +13 -6
- package/src/quick.js +1 -1
- package/src/redline-check.js +12 -2
- package/src/redline-worker.js +10 -14
- package/src/reply.js +46 -19
- package/src/retain.js +223 -0
- package/src/review.js +32 -18
- package/src/rewrite-check.js +2 -2
- package/src/rewriter.js +38 -8
- package/src/sanitize.js +16 -3
- package/src/server-entry.js +4 -3
- package/src/server.js +175 -62
- package/src/session.js +1151 -210
- package/src/setup.js +20 -2
- package/src/stop-gate.js +34 -0
- package/src/suggest-reply.js +42 -7
- package/src/suggest.js +14 -29
- package/src/text.js +161 -11
- package/src/update.js +517 -0
- package/src/voice-guide.js +15 -9
- package/src/voice-learn.js +15 -4
- package/src/voice-sample-worker.js +7 -6
- package/src/voice-store.js +11 -4
- package/src/voice-worker.js +4 -6
- package/src/voice.js +2 -1
- package/src/worker-host.js +23 -0
- package/src/xlsx.js +378 -97
- package/src/xml-tree.js +6 -3
- package/src/xml.js +82 -34
- package/src/zip-write.js +10 -5
- package/src/zip.js +73 -18
- package/vendor/parse5/LICENSE.txt +32 -0
- package/vendor/parse5/parse5.mjs +7822 -0
- package/vendor/parse5.lock.json +23 -0
- package/web/dist/assets/{index-DS-WST1E.js → index-CjsTf5gj.js} +58 -52
- package/web/dist/assets/index-DnbLtHhG.css +1 -0
- package/web/dist/index.html +2 -2
- package/web/dist/assets/index-BCAEKiOG.css +0 -1
package/src/ops/xlsx.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { checkExpect, colIndex, colLetters, engineFailure, fail, parseA1, refused } from "./common.js";
|
|
2
2
|
import { openEngine } from "./engine.js";
|
|
3
|
-
import {
|
|
3
|
+
import { countMatches, findRanges } from "./runs.js";
|
|
4
4
|
import { a1Range, parseWorkbook } from "../xlsx.js";
|
|
5
|
+
import { openZip } from "../zip.js";
|
|
6
|
+
import { walkXml } from "../xml.js";
|
|
5
7
|
|
|
6
8
|
/**
|
|
7
9
|
* XLSX driver (headless Engine: xlsx.set, xlsx.format, xlsx.sheetOp, xlsx.bookOp, xlsx.replace). Cell text for `expect` is what a
|
|
@@ -90,22 +92,110 @@ async function colText(st, sh, c) {
|
|
|
90
92
|
|
|
91
93
|
const input = (v) => (v === null ? "" : typeof v === "boolean" ? (v ? "TRUE" : "FALSE") : String(v));
|
|
92
94
|
|
|
95
|
+
// Give equal decimal spellings the same signed coefficient and power of ten.
|
|
96
|
+
function normalizedDecimal(text) {
|
|
97
|
+
const [mantissa, exponent = "0"] = text.split(/e/i);
|
|
98
|
+
const [whole, fraction = ""] = mantissa.replace(/^[-+]/, "").split(".");
|
|
99
|
+
const digits = (whole + fraction).replace(/^0+/, "");
|
|
100
|
+
if (!digits) return "0";
|
|
101
|
+
const coefficient = digits.replace(/0+$/, "");
|
|
102
|
+
const power = BigInt(exponent) - BigInt(fraction.length) + BigInt(digits.length - coefficient.length);
|
|
103
|
+
return `${mantissa.startsWith("-") ? "-" : ""}${coefficient}e${power}`;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// The numeric and percent patterns mirror parseInput in vendor/engine-node/engine-node.mjs.
|
|
107
|
+
export function numberWriteRefusal(value, r, c) {
|
|
108
|
+
if (typeof value !== "string") return null;
|
|
109
|
+
const text = value.trim();
|
|
110
|
+
const match = /^[-+]?(\d+\.?\d*|\.\d+)(?:e[-+]?\d+|%)?$/i.exec(text);
|
|
111
|
+
if (!match) return null;
|
|
112
|
+
const percent = text.endsWith("%");
|
|
113
|
+
const body = percent ? text.slice(0, -1) : text;
|
|
114
|
+
const number = Number(body);
|
|
115
|
+
let reason;
|
|
116
|
+
if (/^0\d/.test(match[1])) reason = "leading zeros are not kept in this version";
|
|
117
|
+
else if (!Number.isFinite(number) || normalizedDecimal(body) !== normalizedDecimal(String(number))) reason = "the number cannot be stored exactly";
|
|
118
|
+
else return null;
|
|
119
|
+
return refused("number_would_change", `${colLetters(c)}${r + 1} would be saved as the number ${percent ? number / 100 : number} instead of the text ${JSON.stringify(value)}: ${reason}`);
|
|
120
|
+
}
|
|
121
|
+
|
|
93
122
|
const STRUCTURAL = new Set(["insert_rows", "delete_rows", "insert_columns", "delete_columns"]);
|
|
94
123
|
|
|
124
|
+
// Mirror the two dateSerial2 patterns in vendor/engine-node/engine-node.mjs.
|
|
125
|
+
function invalidDatePart(value) {
|
|
126
|
+
const text = value.trim();
|
|
127
|
+
const iso = /^(\d{4})-(\d{1,2})-(\d{1,2})(?:[ T](\d{1,2}):(\d{2})(?::(\d{2}))?)?$/.exec(text);
|
|
128
|
+
const m = iso ?? /^(\d{1,2})\/(\d{1,2})\/(\d{4})(?: (\d{1,2}):(\d{2})(?::(\d{2}))?)?$/.exec(text);
|
|
129
|
+
if (!m) return null;
|
|
130
|
+
const month = Number(m[2]), day = Number(m[iso ? 3 : 1]), year = Number(m[iso ? 1 : 3]);
|
|
131
|
+
const leap = year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);
|
|
132
|
+
if (month < 1 || month > 12 || day < 1 || day > [31, leap ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month - 1]) return "day";
|
|
133
|
+
return Number(m[4]) > 23 || Number(m[5]) > 59 || Number(m[6]) > 59 ? "time" : null;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
async function setCells(st, sh, cells) {
|
|
137
|
+
await st.h.engine.call("xlsx.set", [sh, cells]);
|
|
138
|
+
// The live format decides whether the engine parses a date. Discard this in-memory edit if it converted an impossible date or time.
|
|
139
|
+
for (const { r, c, input } of cells) {
|
|
140
|
+
const invalid = invalidDatePart(input);
|
|
141
|
+
if (invalid && await cellText(st, sh, r, c) !== input)
|
|
142
|
+
return { ...refused("invalid_date", `${colLetters(c)}${r + 1} has a date format and ${JSON.stringify(input)} names a ${invalid} that does not exist`), dirty: true };
|
|
143
|
+
}
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function addressRefusal(st, sh) {
|
|
148
|
+
const sheet = st.sheets[sh];
|
|
149
|
+
if (sheet.implicitCells === undefined) {
|
|
150
|
+
const xml = (st.zip ??= openZip(st.bytes)).readText(sheet.path);
|
|
151
|
+
if (xml == null) return refused("sheet_unreadable", "the worksheet could not be checked for cell addresses");
|
|
152
|
+
let implicit = false;
|
|
153
|
+
const stack = [];
|
|
154
|
+
walkXml(xml, {
|
|
155
|
+
onOpen(name, attrs) {
|
|
156
|
+
const tag = name.slice(name.indexOf(":") + 1);
|
|
157
|
+
if (tag === "c" && stack.at(-1) === "row" && stack.at(-2) === "sheetData" && !attrs.r) implicit = true;
|
|
158
|
+
stack.push(tag);
|
|
159
|
+
},
|
|
160
|
+
onClose() { stack.pop(); },
|
|
161
|
+
});
|
|
162
|
+
sheet.implicitCells = implicit;
|
|
163
|
+
}
|
|
164
|
+
return sheet.implicitCells ? refused("cells_without_address", `sheet "${sheet.name}" stores cells without their addresses. Edits to it are not supported in this version.`) : null;
|
|
165
|
+
}
|
|
166
|
+
|
|
95
167
|
/** Phase 1 (before any op ran): sheet and range exist, `expect` holds. Async because it reads cells through the engine. */
|
|
96
168
|
export async function bind(st, op) {
|
|
97
169
|
const b = bindShape(st, op);
|
|
98
170
|
if (!b.ok) return b;
|
|
171
|
+
// Moving addresses or renaming a sheet can also rewrite formulas on other sheets.
|
|
172
|
+
const sheets = STRUCTURAL.has(op.op) || op.op === "rename_sheet" ? st.sheets.keys() : b.sh === undefined ? [] : [b.sh];
|
|
173
|
+
for (const sh of sheets) {
|
|
174
|
+
const bad = addressRefusal(st, sh);
|
|
175
|
+
if (bad) return bad;
|
|
176
|
+
}
|
|
99
177
|
// Addresses and `expect` are about the file as it is now. After rows or columns moved they would mean something else.
|
|
100
178
|
if (b.sh !== undefined && st.shifted?.has(b.sh)) return refused("after_structural_edit", "an earlier op of this file inserted or deleted rows/columns on this sheet; send this op in a separate apply call");
|
|
179
|
+
if (op.op === "replace_all_text" && st.shifted?.size > 0) return refused("after_structural_edit", "an earlier op of this file inserted or deleted rows/columns on a sheet; send this op in a separate apply call");
|
|
101
180
|
const bad = await checkRegion(st, b);
|
|
102
181
|
if (bad) return bad;
|
|
103
182
|
if (STRUCTURAL.has(op.op)) (st.shifted ??= new Set()).add(b.sh);
|
|
104
183
|
if (op.op === "replace_all_text") {
|
|
105
184
|
const hits = await allMatches(st, op);
|
|
185
|
+
for (const sh of new Set(hits.map((x) => x.sh))) {
|
|
186
|
+
const bad = addressRefusal(st, sh);
|
|
187
|
+
if (bad) return bad;
|
|
188
|
+
}
|
|
106
189
|
const total = hits.reduce((n, x) => n + x.n, 0);
|
|
190
|
+
// The read-only preview binds with count zero. At execution an earlier op may have changed the cell text.
|
|
191
|
+
if (op.expect.count === 0) {
|
|
192
|
+
for (const x of hits) {
|
|
193
|
+
const cell = replacementCell(x, x.t, op);
|
|
194
|
+
if (cell.code) return cell;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
107
197
|
// `t` is the formula when a cell has one, so a hit whose text starts with "=" would rewrite a formula
|
|
108
|
-
const extra = { partial_words: hits.reduce((n, x) => n +
|
|
198
|
+
const extra = { partial_words: hits.reduce((n, x) => n + x.partial, 0), in_formulas: hits.reduce((n, x) => n + (x.t.startsWith("=") ? x.n : 0), 0) };
|
|
109
199
|
if (total !== op.expect.count) return fail("expect_mismatch", `found ${total} occurrence(s), expected ${op.expect.count}`, { found: total, ...extra });
|
|
110
200
|
Object.assign(b, extra);
|
|
111
201
|
b.hits = hits;
|
|
@@ -135,10 +225,16 @@ function bindShape(st, op) {
|
|
|
135
225
|
if (op.op === "set_cells") {
|
|
136
226
|
// a merged range shows only its top-left cell: a value in any other cell of it is hidden from the person (an empty write is harmless)
|
|
137
227
|
const flat = Array.isArray(op.values) ? op.values : [[op.values]];
|
|
228
|
+
const written = flat.flatMap((row, i) => row.map((v, j) => ({ r: rect.r0 + i, c: rect.c0 + j, v }))).filter((x) => input(x.v) !== ""); // once, not per range
|
|
138
229
|
for (const m of mergesOf(st, target.sheet)) {
|
|
139
|
-
|
|
230
|
+
if (m.r1 < rect.r0 || m.r0 > rect.r1 || m.c1 < rect.c0 || m.c0 > rect.c1) continue; // a range outside the write: nothing of it is hit
|
|
231
|
+
const hit = written.find((x) => x.r >= m.r0 && x.r <= m.r1 && x.c >= m.c0 && x.c <= m.c1 && !(x.r === m.r0 && x.c === m.c0));
|
|
140
232
|
if (hit) return refused("merged_cell", `${colLetters(hit.c)}${hit.r + 1} is inside the merged range ${a1Range(m)}, which shows only its top-left cell ${colLetters(m.c0)}${m.r0 + 1}: write there, or pick a cell outside the range`);
|
|
141
233
|
}
|
|
234
|
+
for (const { v, r, c } of written) {
|
|
235
|
+
const bad = numberWriteRefusal(v, r, c);
|
|
236
|
+
if (bad) return bad;
|
|
237
|
+
}
|
|
142
238
|
}
|
|
143
239
|
return { ok: true, op, sh, rect, phase: "region" };
|
|
144
240
|
}
|
|
@@ -199,14 +295,24 @@ async function allMatches(st, op) {
|
|
|
199
295
|
for (const row of b.rows)
|
|
200
296
|
for (const c of row.cells) {
|
|
201
297
|
const t = await cellText(st, sh, row.r, c[0]);
|
|
202
|
-
const n =
|
|
203
|
-
if (n) out.push({ sh, r: row.r, c: c[0], n, t });
|
|
298
|
+
const { n, partial } = countMatches(t, op.find, op.match_case !== false);
|
|
299
|
+
if (n) out.push({ sh, r: row.r, c: c[0], n, partial, t });
|
|
204
300
|
}
|
|
205
301
|
}
|
|
206
302
|
}
|
|
207
303
|
return out;
|
|
208
304
|
}
|
|
209
305
|
|
|
306
|
+
function replacementCell(x, text, op) {
|
|
307
|
+
const ranges = findRanges(text, op.find, op.match_case !== false);
|
|
308
|
+
if (ranges.length !== x.n) return { ...refused("incomplete_replace", `cell ${colLetters(x.c)}${x.r + 1} changed before replace_all_text ran`), dirty: true };
|
|
309
|
+
let next = "";
|
|
310
|
+
let cur = 0;
|
|
311
|
+
for (const { start, end } of ranges) (next += text.slice(cur, start) + op.replace), (cur = end);
|
|
312
|
+
next += text.slice(cur);
|
|
313
|
+
return numberWriteRefusal(next, x.r, x.c) ?? { sh: x.sh, r: x.r, c: x.c, input: next };
|
|
314
|
+
}
|
|
315
|
+
|
|
210
316
|
export async function exec(st, b) {
|
|
211
317
|
const { op } = b;
|
|
212
318
|
try {
|
|
@@ -215,11 +321,15 @@ export async function exec(st, b) {
|
|
|
215
321
|
const total = b.hits.reduce((n, x) => n + x.n, 0);
|
|
216
322
|
const byFormula = [];
|
|
217
323
|
for (const x of b.hits) {
|
|
218
|
-
const
|
|
219
|
-
const
|
|
220
|
-
|
|
324
|
+
const live = await cellText(st, x.sh, x.r, x.c);
|
|
325
|
+
const cell = replacementCell(x, live, op);
|
|
326
|
+
if (cell.code) return cell;
|
|
327
|
+
byFormula.push(cell);
|
|
328
|
+
}
|
|
329
|
+
for (const sh of new Set(byFormula.map((x) => x.sh))) {
|
|
330
|
+
const bad = await setCells(st, sh, byFormula.filter((x) => x.sh === sh));
|
|
331
|
+
if (bad) return bad;
|
|
221
332
|
}
|
|
222
|
-
for (const sh of new Set(byFormula.map((x) => x.sh))) await st.h.engine.call("xlsx.set", [sh, byFormula.filter((x) => x.sh === sh).map(({ r, c, input }) => ({ r, c, input }))]);
|
|
223
333
|
if (byFormula.length !== b.hits.length) return { ...refused("incomplete_replace", "not every matching cell was rewritten"), dirty: true };
|
|
224
334
|
return { status: "applied", detail: { replaced: total, cells: byFormula.length } };
|
|
225
335
|
}
|
|
@@ -228,7 +338,8 @@ export async function exec(st, b) {
|
|
|
228
338
|
const flat = Array.isArray(op.values) ? op.values : [[op.values]];
|
|
229
339
|
const cells = [];
|
|
230
340
|
flat.forEach((row, i) => row.forEach((v, j) => cells.push({ r: b.rect.r0 + i, c: b.rect.c0 + j, input: input(v) })));
|
|
231
|
-
await st
|
|
341
|
+
const bad = await setCells(st, b.sh, cells);
|
|
342
|
+
if (bad) return bad;
|
|
232
343
|
return { status: "applied", detail: { cells: cells.length } };
|
|
233
344
|
}
|
|
234
345
|
case "format_cells": {
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { env } from "./constants.js";
|
|
2
|
+
import "./html-parser.js"; // an HTML file's ops run here, never on the server's or the CLI's thread (test/html-parser-thread.test.js)
|
|
3
|
+
import { previewAll, runOps } from "./ops/run.js";
|
|
4
|
+
|
|
5
|
+
// The engine's work for a quick change, off the server's thread (src/offload.js opsOffThread), run by src/worker-host.js within a time
|
|
6
|
+
// and memory limit: the count a quick preview and a quick plan show (`preview`: previewAll) and the change itself made on this Mac
|
|
7
|
+
// (`run`: runOps, which the local runner's apply calls through src/local.js). An outside review: a 12,538-byte document of one
|
|
8
|
+
// paragraph of 8 million characters held the server's thread for 4 s while its matches were counted. One message back: {ok: true, p} |
|
|
9
|
+
// {ok: true, r: runOps' answer}. ONIONSKIN_TEST_OPS_DELAY_MS (tests only) blocks this thread for that long first, the way a slow count
|
|
10
|
+
// would.
|
|
11
|
+
export async function work({ kind, bytes, format, op, ops, name, partial, anchors }) {
|
|
12
|
+
const delay = Number(env("TEST_OPS_DELAY_MS", 0));
|
|
13
|
+
if (delay > 0) Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, delay);
|
|
14
|
+
const b = Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
15
|
+
if (kind === "preview") return { ok: true, p: await previewAll(b, format, op, { name }) };
|
|
16
|
+
return { ok: true, r: await runOps({ bytes: b, format, name, ops, partial, anchors: new Map(anchors || []) }) };
|
|
17
|
+
}
|
package/src/package.js
CHANGED
|
@@ -4,6 +4,7 @@ import { openZip, ZipError } from "./zip.js";
|
|
|
4
4
|
import { walkXml } from "./xml.js";
|
|
5
5
|
import { runDeepCheck } from "./checker.js";
|
|
6
6
|
import { cleanFlag } from "./sanitize.js";
|
|
7
|
+
import { decodeHtml, HtmlEncodingError, readHtml } from "./html.js";
|
|
7
8
|
|
|
8
9
|
const MAX_TYPES_BYTES = 4 * 1024 * 1024; // [Content_Types].xml of a real document is a few KB
|
|
9
10
|
// Cumulative work of the relationship scan: a hostile archive can hold thousands of individually allowed .rels parts.
|
|
@@ -14,6 +15,13 @@ const MAX_RELS_BYTES = 64 * 1024 * 1024;
|
|
|
14
15
|
export function validatePackage(bytes, format) {
|
|
15
16
|
const want = FORMATS[format];
|
|
16
17
|
if (!want) throw new ZipError(`unsupported format: ${format}`);
|
|
18
|
+
// an HTML file is no package: its encoding is checked here (no parse; the parser lives in worker threads only, src/html-parser.js).
|
|
19
|
+
// Returns null; the open worker reads it whole (src/open-worker.js), a write goes through src/html-write.js
|
|
20
|
+
if (format === "html") {
|
|
21
|
+
const d = decodeHtml(bytes);
|
|
22
|
+
if (!d.ok) throw new HtmlEncodingError(d);
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
17
25
|
const zip = openZip(bytes);
|
|
18
26
|
const ct = zip.readText("[Content_Types].xml", MAX_TYPES_BYTES);
|
|
19
27
|
if (ct == null) throw new ZipError("missing [Content_Types].xml");
|
|
@@ -30,17 +38,26 @@ export function validatePackage(bytes, format) {
|
|
|
30
38
|
return zip;
|
|
31
39
|
}
|
|
32
40
|
|
|
41
|
+
function hasZipEntry(zip, clean) {
|
|
42
|
+
if (zip.entries.has(clean)) return true;
|
|
43
|
+
try {
|
|
44
|
+
return zip.entries.has(decodeURIComponent(clean));
|
|
45
|
+
} catch {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
33
50
|
function relTargets(zip) {
|
|
34
51
|
const missing = [];
|
|
35
52
|
let parts = 0;
|
|
36
53
|
let bytes = 0;
|
|
37
54
|
for (const name of zip.names) {
|
|
38
55
|
if (!name.endsWith(".rels")) continue;
|
|
39
|
-
if (++parts > MAX_RELS_PARTS) throw new ZipError(`
|
|
56
|
+
if (++parts > MAX_RELS_PARTS) throw new ZipError(`this file has more than ${MAX_RELS_PARTS.toLocaleString("en-US")} relationship parts, more than Onionskin can read. Save it again in Word, Excel or PowerPoint, or split it, and open that`);
|
|
40
57
|
const xml = zip.readText(name);
|
|
41
58
|
if (xml == null) continue;
|
|
42
59
|
bytes += xml.length;
|
|
43
|
-
if (bytes > MAX_RELS_BYTES) throw new ZipError(
|
|
60
|
+
if (bytes > MAX_RELS_BYTES) throw new ZipError(`the relationship parts of this file are larger than ${MAX_RELS_BYTES / 1024 / 1024} MB in all, more than Onionskin can read. Save it again in Word, Excel or PowerPoint, or split it, and open that`);
|
|
44
61
|
const srcDir = path.posix.dirname(path.posix.dirname(name)); // word/_rels/x.rels -> word
|
|
45
62
|
const base = srcDir === "." ? "" : srcDir;
|
|
46
63
|
walkXml(xml, {
|
|
@@ -48,7 +65,7 @@ function relTargets(zip) {
|
|
|
48
65
|
if (tag !== "Relationship" || attrs.TargetMode === "External" || !attrs.Target) return;
|
|
49
66
|
const target = attrs.Target.startsWith("/") ? attrs.Target.slice(1) : path.posix.normalize(path.posix.join(base, attrs.Target));
|
|
50
67
|
const clean = target.split("#")[0];
|
|
51
|
-
if (clean && !zip
|
|
68
|
+
if (clean && !hasZipEntry(zip, clean)) missing.push({ rels: name, target: clean });
|
|
52
69
|
},
|
|
53
70
|
});
|
|
54
71
|
}
|
|
@@ -79,7 +96,13 @@ export function partRels(zip, part) {
|
|
|
79
96
|
onOpen(tag, a) {
|
|
80
97
|
if (tag !== "Relationship" || !a.Type || !a.Target) return;
|
|
81
98
|
const external = a.TargetMode === "External";
|
|
82
|
-
|
|
99
|
+
let target = external ? a.Target : a.Target.startsWith("/") ? a.Target.slice(1) : path.posix.normalize(path.posix.join(base === "." ? "" : base, a.Target.split("#")[0]));
|
|
100
|
+
if (!external && !zip.entries.has(target)) {
|
|
101
|
+
try {
|
|
102
|
+
const dec = decodeURIComponent(target);
|
|
103
|
+
if (zip.entries.has(dec)) target = dec;
|
|
104
|
+
} catch {}
|
|
105
|
+
}
|
|
83
106
|
out.push({ id: a.Id, type: a.Type.split("/").pop(), target, external });
|
|
84
107
|
},
|
|
85
108
|
});
|
|
@@ -157,6 +180,21 @@ export function nodeChecks(preBytes, postBytes, format) {
|
|
|
157
180
|
return rawNodeChecks(preBytes, postBytes, format).map(cleanFlag);
|
|
158
181
|
}
|
|
159
182
|
|
|
183
|
+
/**
|
|
184
|
+
* The check of an HTML file at `done` (no package, no deeper check, PLAN-html D9): the version the agent left still reads as HTML within
|
|
185
|
+
* Onionskin's limits (every write through Onionskin was checked whole before it was written, src/html-write.js; a direct save was not).
|
|
186
|
+
* Needs the parser: runs in the check worker (src/check-worker.js).
|
|
187
|
+
*/
|
|
188
|
+
function htmlChecks(postBytes) {
|
|
189
|
+
const skipped = { status: "skipped", reason: "the deeper checks are for Word, Excel and PowerPoint files", code: "not_for_html" };
|
|
190
|
+
try {
|
|
191
|
+
readHtml(postBytes);
|
|
192
|
+
return { flags: [], checks: { node: "ran", deep: skipped, notice: "Checked that the page still reads as HTML within Onionskin's limits. The deeper checks are for Word, Excel and PowerPoint files." } };
|
|
193
|
+
} catch (err) {
|
|
194
|
+
return { flags: [cleanFlag({ code: "html_unreadable", severity: "error", detail: String(err?.message || err).slice(0, 200) })], checks: { node: "ran", deep: skipped, notice: "The page the agent left cannot be read as HTML by Onionskin. Revert restores the version before the run." } };
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
160
198
|
/** The one sentence about the deeper check. A LibreOffice check still running is "pending", never "passed". */
|
|
161
199
|
export const deepNotice = (skipped = [], pending = false) =>
|
|
162
200
|
`Deeper check ran${skipped.length ? `; skipped: ${skipped.map((x) => `${x.check} (${x.reason})`).join(", ")}` : ""}${pending ? "; the LibreOffice conversion check is still running (pending), the Activity list updates when it finishes" : ""}.`;
|
|
@@ -168,6 +206,7 @@ const flagKey = (f) => JSON.stringify([f.code, f.part, f.element, f.rels, f.targ
|
|
|
168
206
|
* Returns {flags, checks}: `flags` are findings (severity info/warn/error); `checks` says what ran, so a skipped deep check is never silent.
|
|
169
207
|
*/
|
|
170
208
|
export function checkPackages(preBytes, postBytes, format, opts = {}) {
|
|
209
|
+
if (format === "html") return htmlChecks(postBytes);
|
|
171
210
|
const node = rawNodeChecks(preBytes, postBytes, format);
|
|
172
211
|
if (node.some((f) => f.code === "invalid_package")) return { flags: node.map(cleanFlag), checks: { node: "ran", deep: { status: "skipped", reason: "the package is invalid" } } };
|
|
173
212
|
const deep = runDeepCheck(preBytes, postBytes, format, { deferSoffice: !!opts.deferSoffice });
|
package/src/person.js
CHANGED
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
import { PRODUCT } from "./constants.js";
|
|
4
4
|
|
|
5
5
|
const BIN = PRODUCT.bin;
|
|
6
|
-
|
|
6
|
+
// the formats Onionskin opens, and the web files it refuses with a sentence (src/constants.js REFUSED_PAGES): `onionskin page.mhtml` says why
|
|
7
|
+
const DOC_EXT = /\.(docx|xlsx|pptx|html|htm|mhtml|mht|webarchive|xhtml|svg)$/i;
|
|
7
8
|
export const GET_CLAUDE_CODE = "https://claude.com/product/claude-code";
|
|
8
9
|
|
|
9
10
|
/**
|