onionskin-cli 0.0.2 → 0.0.5
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 +111 -0
- package/INSTALL.md +5 -1
- package/NOTICE +34 -0
- package/README.md +101 -33
- package/docs/contracts/batch.schema.json +27 -4
- package/docs/contracts/ops.schema.json +117 -5
- package/package.json +4 -2
- package/skills/onionskin/SKILL.md +9 -6
- package/skills/onionskin/reference/batch.md +5 -3
- package/skills/onionskin/reference/formats.md +5 -1
- package/skills/onionskin/reference/ops.md +47 -3
- 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 +77 -19
- 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/cli.js +91 -25
- package/src/constants.js +34 -1
- package/src/diff.js +3 -1
- package/src/docx.js +368 -58
- package/src/edit-hash.js +19 -0
- package/src/fsutil.js +1 -1
- package/src/history-worker.js +8 -8
- package/src/history.js +135 -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 +880 -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 +1257 -0
- package/src/local.js +68 -4
- package/src/merge-package.js +1110 -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 +400 -1
- package/src/open-worker.js +27 -0
- package/src/ops/common.js +2 -1
- package/src/ops/docx.js +58 -29
- package/src/ops/html.js +394 -0
- package/src/ops/pptx.js +74 -21
- 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 +12 -7
- package/src/ops-worker.js +17 -0
- package/src/package.js +26 -2
- package/src/person.js +8 -1
- package/src/pptx.js +85 -21
- package/src/quick-plan.js +13 -6
- 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/sanitize.js +16 -3
- package/src/server.js +88 -37
- package/src/session.js +1143 -208
- 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 +288 -0
- package/src/voice-guide.js +4 -3
- package/src/voice-learn.js +4 -3
- package/src/voice-sample-worker.js +7 -6
- package/src/voice-worker.js +4 -6
- package/src/watch.js +188 -0
- package/src/worker-host.js +23 -0
- package/src/xlsx.js +355 -94
- package/src/xml-tree.js +6 -3
- package/src/xml.js +82 -34
- package/src/zip-write.js +2 -1
- package/src/zip.js +9 -5
- 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-DkNx0LSH.css +1 -0
- package/web/dist/assets/{index-BUtofdtr.js → index-DytKkMdi.js} +117 -107
- package/web/dist/index.html +2 -2
- package/web/dist/assets/index-Dfizlg0i.css +0 -1
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// The answer of GET /api/html-view (docs/contracts/routes.md): one binary body the page reads without parsing a large JSON. Pure, no
|
|
2
|
+
// imports: the server encodes it (src/server.js) and the page decodes it (web/src/HtmlHost.jsx), from this same file.
|
|
3
|
+
//
|
|
4
|
+
// Layout (little-endian):
|
|
5
|
+
// 0 4 bytes "OSKV"
|
|
6
|
+
// 4 u32 length of the header JSON in bytes (H)
|
|
7
|
+
// 8 H bytes header JSON (UTF-8): {version, plain, reason, stats, texts: n, editable: m, ident: k}
|
|
8
|
+
// padding to a multiple of 4
|
|
9
|
+
// n x i32 texts: the copy's n-th text node is source text node texts[n], or -1 (src/html-render.js)
|
|
10
|
+
// m x i32 editable: the source text nodes the person may type in (src/html.js editableTextIds)
|
|
11
|
+
// k x i32 ident: their identities, 6 per editable node in the same order (src/html.js editIdentities), or none (k = 0)
|
|
12
|
+
// rest the copy (UTF-8): set once as the frame's srcdoc
|
|
13
|
+
// `texts` and `editable` hold one entry per text node (200,000 at the limits), so they travel as Int32Arrays: the page takes views on the
|
|
14
|
+
// one ArrayBuffer it received, nothing is copied or parsed.
|
|
15
|
+
|
|
16
|
+
const MAGIC = [0x4f, 0x53, 0x4b, 0x56]; // "OSKV"
|
|
17
|
+
|
|
18
|
+
/** The parts of the body: [prefix (magic, header, padding, both arrays), copy]. The server writes them in turn (no 40 MB concatenation). */
|
|
19
|
+
export function encodeHtmlView({ version, plain, reason, stats, texts, editable, ident = [], copy }) {
|
|
20
|
+
const head = new TextEncoder().encode(JSON.stringify({ version, plain: !!plain, reason: reason ?? null, stats: stats ?? null, texts: texts.length, editable: editable.length, ident: ident.length }));
|
|
21
|
+
const at = (8 + head.length + 3) & ~3;
|
|
22
|
+
const count = texts.length + editable.length + ident.length;
|
|
23
|
+
const prefix = new Uint8Array(at + 4 * count);
|
|
24
|
+
prefix.set(MAGIC, 0);
|
|
25
|
+
new DataView(prefix.buffer).setUint32(4, head.length, true);
|
|
26
|
+
prefix.set(head, 8);
|
|
27
|
+
const ints = new Int32Array(prefix.buffer, at, count);
|
|
28
|
+
ints.set(texts, 0);
|
|
29
|
+
ints.set(editable, texts.length);
|
|
30
|
+
ints.set(ident, texts.length + editable.length);
|
|
31
|
+
return [prefix, copy];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** The page's side: {version, plain, reason, stats, texts, editable, ident (Int32Arrays), copy (Uint8Array)}; throws on a bad body. */
|
|
35
|
+
export function decodeHtmlView(buf) {
|
|
36
|
+
const u8 = buf instanceof Uint8Array ? buf : new Uint8Array(buf);
|
|
37
|
+
if (u8.length < 8 || MAGIC.some((b, i) => u8[i] !== b)) throw new Error("not an HTML view");
|
|
38
|
+
const dv = new DataView(u8.buffer, u8.byteOffset, u8.byteLength);
|
|
39
|
+
const len = dv.getUint32(4, true);
|
|
40
|
+
if (8 + len > u8.length) throw new Error("a cut HTML view");
|
|
41
|
+
const head = JSON.parse(new TextDecoder().decode(u8.subarray(8, 8 + len)));
|
|
42
|
+
const at = (8 + len + 3) & ~3;
|
|
43
|
+
const n = head.texts;
|
|
44
|
+
const m = head.editable;
|
|
45
|
+
const k = head.ident ?? 0;
|
|
46
|
+
const end = at + 4 * (n + m + k);
|
|
47
|
+
if (!Number.isInteger(n) || !Number.isInteger(m) || !Number.isInteger(k) || end > u8.length) throw new Error("a cut HTML view");
|
|
48
|
+
// an Int32Array view needs an aligned offset in its buffer: copied only when the body's own offset is not (it is for a fetched body)
|
|
49
|
+
const ints = (u8.byteOffset + at) % 4 === 0 ? new Int32Array(u8.buffer, u8.byteOffset + at, n + m + k) : new Int32Array(u8.slice(at, end).buffer);
|
|
50
|
+
return { version: head.version, plain: head.plain, reason: head.reason, stats: head.stats, texts: ints.subarray(0, n), editable: ints.subarray(n, n + m), ident: ints.subarray(n + m), copy: u8.subarray(end) };
|
|
51
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// The one module that imports the vendored HTML parser (vendor/parse5/parse5.mjs, pinned by vendor/parse5.lock.json) and installs it
|
|
2
|
+
// in src/html.js. Only modules that run in worker threads import this one (src/anchor-worker.js), so the server's own thread never
|
|
3
|
+
// parses a page: test/html-parser-thread.test.js fails if src/server.js or src/session.js reach it.
|
|
4
|
+
import * as P5 from "../vendor/parse5/parse5.mjs";
|
|
5
|
+
import { installParser } from "./html.js";
|
|
6
|
+
|
|
7
|
+
installParser(P5);
|
|
8
|
+
export { P5 };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import "./html-parser.js"; // this worker reads HTML files: the parser lives here, never on the server's thread
|
|
2
|
+
import { editableTextIds, editIdentities, readHtml } from "./html.js";
|
|
3
|
+
import { makeAssetReader, plainCopy, renderCopy } from "./html-render.js";
|
|
4
|
+
|
|
5
|
+
// The render copy of one version of an HTML file (src/offload.js renderOffThread, PLAN-html R12), run by src/worker-host.js within a
|
|
6
|
+
// time and memory limit: the file read again, the copy built (local images and stylesheets read here, src/html-render.js), and when the
|
|
7
|
+
// copy does not survive its own re-parse (R2), the plain text view instead. `job` = {bytes, fileDir}. Answers {ok: true, plain, reason,
|
|
8
|
+
// bytes, texts, stats, editable, ident} or {ok: false, error, code, copyable}. `bytes` is the copy (UTF-8), for the page to set as `srcdoc` once;
|
|
9
|
+
// `editable` the source text nodes the person may type in (src/html.js editableTextIds), `ident` their identities (editIdentities).
|
|
10
|
+
// `plain: true` in the job: the plain copy only (the page asks for it after its view stopped responding, R6).
|
|
11
|
+
export function work({ bytes, fileDir, plain = false }) {
|
|
12
|
+
try {
|
|
13
|
+
const read = readHtml(Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength));
|
|
14
|
+
let r = plain ? null : renderCopy(read, { fileDir, readAsset: makeAssetReader(), editable: true });
|
|
15
|
+
let reason = plain ? "asked" : null;
|
|
16
|
+
if (!r || r.plain) {
|
|
17
|
+
reason = r ? r.reason : reason;
|
|
18
|
+
r = plainCopy(read);
|
|
19
|
+
}
|
|
20
|
+
const editable = editableTextIds(read);
|
|
21
|
+
return { ok: true, plain: reason !== null, reason, bytes: new Uint8Array(r.bytes.buffer, r.bytes.byteOffset, r.bytes.byteLength), texts: r.texts, stats: r.stats, editable, ident: editIdentities(read, editable) };
|
|
22
|
+
} catch (err) {
|
|
23
|
+
return { ok: false, code: typeof err?.code === "string" ? err.code : null, copyable: err?.copyable === true, error: String(err?.message || err).slice(0, 200) };
|
|
24
|
+
}
|
|
25
|
+
}
|