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
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
|
-
import {
|
|
2
|
+
import { unknownFormat } from "./constants.js";
|
|
3
3
|
import { readDocxParagraphs } from "./docx.js";
|
|
4
4
|
import { validatePackage } from "./package.js";
|
|
5
5
|
import { parseDeck } from "./pptx.js";
|
|
@@ -35,8 +35,9 @@ function office(bytes, format, index) {
|
|
|
35
35
|
if (zip.names.some((n) => MACRO_PART.test(n))) throw new SampleError(index, "macro");
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
const textsOf = (format, bytes) => {
|
|
38
|
+
export const textsOf = (format, bytes) => {
|
|
39
39
|
if (format === "docx") return readDocxParagraphs(bytes).map((p) => p.text);
|
|
40
|
+
if (format !== "pptx") return unknownFormat(format, "textsOf");
|
|
40
41
|
const deck = parseDeck(bytes);
|
|
41
42
|
deck.ensure();
|
|
42
43
|
return deck.slides.flatMap((s) => [s.title, ...(s.shapes || []).map((sh) => sh.text)]);
|
|
@@ -84,12 +85,12 @@ export function sampleSources({ open = null, files = [], texts = [], shares = 0
|
|
|
84
85
|
return { sources };
|
|
85
86
|
}
|
|
86
87
|
|
|
87
|
-
// Run in a worker thread
|
|
88
|
+
// Run in a worker thread by src/worker-host.js, with a timeout in the caller. One message back: {ok: true, sources} or
|
|
88
89
|
// {ok: false, index, code}. Anything else that goes wrong is {ok: false, index: -1, code: "unreadable"}.
|
|
89
|
-
|
|
90
|
+
export function work(data) {
|
|
90
91
|
try {
|
|
91
|
-
|
|
92
|
+
return { ok: true, ...sampleSources(data) };
|
|
92
93
|
} catch (err) {
|
|
93
|
-
|
|
94
|
+
return err instanceof SampleError ? { ok: false, index: err.index, code: err.code } : { ok: false, index: -1, code: "unreadable" };
|
|
94
95
|
}
|
|
95
96
|
}
|
package/src/voice-store.js
CHANGED
|
@@ -96,12 +96,15 @@ export function readEvidence() {
|
|
|
96
96
|
const raw = readObject(evidenceFile());
|
|
97
97
|
if (raw === "missing") return emptyEvidence();
|
|
98
98
|
if (!raw || typeof raw.learning !== "boolean") return { ...emptyEvidence(), learning: false };
|
|
99
|
+
const pairs = list(raw.pairs, cleanPair, MAX_PAIRS);
|
|
99
100
|
const examples = list(raw.examples, cleanExample, Infinity);
|
|
100
101
|
const unique = examples.filter((e, i) => examples.findLastIndex((x) => x.id === e.id) === i).slice(-MAX_EXAMPLES);
|
|
102
|
+
const totalPairs = Number.isSafeInteger(raw.totalPairs) && raw.totalPairs >= pairs.length ? raw.totalPairs : undefined;
|
|
101
103
|
return {
|
|
102
104
|
v: 1,
|
|
103
105
|
learning: raw.learning,
|
|
104
|
-
pairs
|
|
106
|
+
pairs,
|
|
107
|
+
...(totalPairs !== undefined ? { totalPairs } : {}),
|
|
105
108
|
hits: list(raw.hits, cleanHit, MAX_HITS),
|
|
106
109
|
examples: unique,
|
|
107
110
|
answers: cleanAnswers(raw.answers),
|
|
@@ -123,10 +126,13 @@ export function appendRecords({ pairs = [], hits = [], examples = [] } = {}, now
|
|
|
123
126
|
const ev = readEvidence();
|
|
124
127
|
if (!ev.learning) return ev;
|
|
125
128
|
const add = (items, clean) => (Array.isArray(items) ? items.map((x) => clean(plain(x) ? { ...x, at: now } : x)).filter(Boolean) : []);
|
|
129
|
+
const newPairs = add(pairs, cleanPair);
|
|
126
130
|
const newHits = add((Array.isArray(hits) ? hits : []).map((trait) => ({ trait })), cleanHit);
|
|
131
|
+
const prevTotal = Number.isSafeInteger(ev.totalPairs) && ev.totalPairs >= ev.pairs.length ? ev.totalPairs : ev.pairs.length;
|
|
127
132
|
const next = {
|
|
128
133
|
...ev,
|
|
129
|
-
pairs: [...ev.pairs, ...
|
|
134
|
+
pairs: [...ev.pairs, ...newPairs].slice(-MAX_PAIRS),
|
|
135
|
+
totalPairs: prevTotal + newPairs.length,
|
|
130
136
|
hits: [...ev.hits, ...newHits].slice(-MAX_HITS),
|
|
131
137
|
examples: [...ev.examples, ...add(examples, cleanExample)],
|
|
132
138
|
};
|
|
@@ -134,12 +140,13 @@ export function appendRecords({ pairs = [], hits = [], examples = [] } = {}, now
|
|
|
134
140
|
return save(next);
|
|
135
141
|
}
|
|
136
142
|
|
|
137
|
-
/** "Not now" ({later: pairs
|
|
143
|
+
/** "Not now" ({later: total pairs seen so far}) or "Don't suggest this" ({never}) for one trait. An unknown trait or action is a 400, nothing written. */
|
|
138
144
|
export function setAnswer(trait, action) {
|
|
139
145
|
if (typeof trait !== "string" || !TRAIT_IDS.includes(trait)) throw new VoiceError(`trait must be one of: ${TRAIT_IDS.join(", ")}`);
|
|
140
146
|
if (typeof action !== "string" || !ANSWERS.includes(action)) throw new VoiceError(`action must be one of: ${ANSWERS.join(", ")}`);
|
|
141
147
|
const ev = readEvidence();
|
|
142
|
-
|
|
148
|
+
const total = Number.isSafeInteger(ev.totalPairs) && ev.totalPairs >= ev.pairs.length ? ev.totalPairs : ev.pairs.length;
|
|
149
|
+
return save({ ...ev, answers: { ...ev.answers, [trait]: action === "never" ? { never: true } : { later: total } } });
|
|
143
150
|
}
|
|
144
151
|
|
|
145
152
|
/** Forget the kept edits, comment hits and examples. The learning switch stays; "never" answers stay (a choice, not evidence); "later" goes (it counted kept pairs). */
|
package/src/voice-worker.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
|
-
import { parentPort, workerData } from "node:worker_threads";
|
|
3
2
|
import { readDocxParagraphs } from "./docx.js";
|
|
4
3
|
import { documentRuns, editPairs, exampleOf, pairSignals } from "./voice.js";
|
|
5
4
|
|
|
@@ -16,13 +15,12 @@ export function analyzeVoice(preBytes, postBytes, mineBytes) {
|
|
|
16
15
|
return { pairs: found.map(pairSignals), examples: found.map((p) => exampleOf(p, runs)).filter(Boolean) };
|
|
17
16
|
}
|
|
18
17
|
|
|
19
|
-
// Run in a worker thread
|
|
18
|
+
// Run in a worker thread by src/worker-host.js: data = {pre, post, mine}, three snapshot blob paths. One message back,
|
|
20
19
|
// {ok: true, pairs, examples} or {ok: false, error}. A version that cannot be read or parsed fails the whole job and learns nothing.
|
|
21
|
-
|
|
20
|
+
export function work({ pre, post, mine }) {
|
|
22
21
|
try {
|
|
23
|
-
|
|
24
|
-
parentPort.postMessage({ ok: true, ...analyzeVoice(fs.readFileSync(pre), fs.readFileSync(post), fs.readFileSync(mine)) });
|
|
22
|
+
return { ok: true, ...analyzeVoice(fs.readFileSync(pre), fs.readFileSync(post), fs.readFileSync(mine)) };
|
|
25
23
|
} catch (err) {
|
|
26
|
-
|
|
24
|
+
return { ok: false, error: String(err?.message || err) };
|
|
27
25
|
}
|
|
28
26
|
}
|
package/src/voice.js
CHANGED
|
@@ -271,11 +271,12 @@ export function suggestions(evidence, style) {
|
|
|
271
271
|
const hits = Array.isArray(ev.hits) ? ev.hits.filter((h) => h && typeof h === "object" && COMMENT_TRAITS.includes(h.trait)) : [];
|
|
272
272
|
const answers = ev.answers && typeof ev.answers === "object" && !Array.isArray(ev.answers) ? ev.answers : {};
|
|
273
273
|
const on = new Set(Array.isArray(style?.traits) ? style.traits : []);
|
|
274
|
+
const totalPairs = Number.isInteger(ev.totalPairs) ? ev.totalPairs : pairs.length;
|
|
274
275
|
const held = (trait) => {
|
|
275
276
|
const a = Object.hasOwn(answers, trait) ? answers[trait] : null;
|
|
276
277
|
if (!a || typeof a !== "object") return false;
|
|
277
278
|
if (a.never === true) return true;
|
|
278
|
-
return Number.isInteger(a.later) &&
|
|
279
|
+
return Number.isInteger(a.later) && totalPairs - a.later < LATER_AFTER;
|
|
279
280
|
};
|
|
280
281
|
const found = [];
|
|
281
282
|
const win = pairs.slice(-WINDOW);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// The entry of every worker thread the server starts (src/offload.js startWorker). It imports node builtins only, so its own evaluation is
|
|
2
|
+
// synchronous; it then loads the named worker module dynamically, marks `loaded`, runs the module's work(data) and posts what it returns.
|
|
3
|
+
// Why: the worker modules import src/docx.js, which awaits at its top level. Terminating a worker while a module is still being evaluated
|
|
4
|
+
// asynchronously aborts the whole server process on Node 26 ("Check failed: !is_null()", exit 133), and a worker whose job ran inside its
|
|
5
|
+
// module's evaluation was in that state for the whole job. startWorker's terminate() waits for `loaded` (the imports took tens of ms),
|
|
6
|
+
// so a worker is only ever stopped while it runs plain code. It also hands the zlib gate its word (src/stop-gate.js): stopping a worker
|
|
7
|
+
// inside zlib aborts the process too. test/worker-terminate.test.js stops each worker at many points.
|
|
8
|
+
import { parentPort, workerData } from "node:worker_threads";
|
|
9
|
+
import { setStopGate } from "./stop-gate.js";
|
|
10
|
+
|
|
11
|
+
const WORKERS = new Set(["check-worker.js", "history-worker.js", "redline-worker.js", "voice-worker.js", "voice-sample-worker.js", "open-worker.js", "merge-worker.js", "ops-worker.js", "anchor-worker.js", "html-write-worker.js", "html-render-worker.js"]);
|
|
12
|
+
const name = process.argv[2];
|
|
13
|
+
if (!WORKERS.has(name)) throw new Error(`unknown worker ${JSON.stringify(String(name)).slice(0, 60)}`);
|
|
14
|
+
const { data, loaded } = workerData;
|
|
15
|
+
setStopGate(new Int32Array(loaded)); // index 0: loaded, index 1: the zlib gate
|
|
16
|
+
// No top-level await here, in it or in src/stop-gate.js (that would make this module's evaluation asynchronous again). A failed import or a throw from work() is an
|
|
17
|
+
// unhandled rejection, which ends the worker with an "error" event its caller already handles; so is a rejected promise from work().
|
|
18
|
+
// A module that exports serve(port) is kept warm instead (src/anchor-worker.js): it answers each message it is sent, itself.
|
|
19
|
+
import(new URL(`./${name}`, import.meta.url).href).then((m) => {
|
|
20
|
+
Atomics.store(new Int32Array(loaded), 0, 1);
|
|
21
|
+
if (typeof m.serve === "function") return m.serve(parentPort, data);
|
|
22
|
+
return Promise.resolve(m.work(data)).then((r) => parentPort.postMessage(r)); // a value, or a promise of one (the merge worker's engine is asynchronous)
|
|
23
|
+
});
|