onionskin-cli 0.0.3 → 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 +100 -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 +16 -5
- 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 +2 -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 +80 -36
- package/src/session.js +1138 -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/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-DS-WST1E.js → index-DytKkMdi.js} +112 -108
- package/web/dist/index.html +2 -2
- package/web/dist/assets/index-BCAEKiOG.css +0 -1
package/src/local.js
CHANGED
|
@@ -13,6 +13,10 @@
|
|
|
13
13
|
// Upgrade path: run applyCommand in a worker with the same in-process port.
|
|
14
14
|
|
|
15
15
|
import { quickPlanner } from "./quick-plan.js";
|
|
16
|
+
import { NOT_YOUR_FILE, agentMayUse, isAgentHolder } from "./agent-detect.js";
|
|
17
|
+
import { HttpError, readChecked } from "./session.js";
|
|
18
|
+
import { runOpsOffThread } from "./offload.js";
|
|
19
|
+
import { LIMITS } from "./agent-runner.js";
|
|
16
20
|
|
|
17
21
|
export const LOCAL_HOLDER = "onionskin-local";
|
|
18
22
|
|
|
@@ -37,6 +41,41 @@ export function leaseOf(body) {
|
|
|
37
41
|
return { holder: str(body.holder), token: str(body.lease_token), batchId: str(body.batch_id), strict: true };
|
|
38
42
|
}
|
|
39
43
|
|
|
44
|
+
/**
|
|
45
|
+
* The binding of an agent Onionskin started to its one file, checked before a /cli/* route looks the file up: another file, open or not,
|
|
46
|
+
* gets the same 403 `not_your_file`, so the refusal says nothing about it. Every other holder passes (its lease is checked where it acts).
|
|
47
|
+
*/
|
|
48
|
+
export function checkBinding(file, holder) {
|
|
49
|
+
if (!agentMayUse(holder, file)) throw new HttpError(403, NOT_YOUR_FILE, { code: "not_your_file" });
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** The session a CLI call names, after the holder's binding is checked. */
|
|
53
|
+
export function sessionFor(sessions, file, holder) {
|
|
54
|
+
checkBinding(file, holder);
|
|
55
|
+
return sessions.byFile(String(file || ""));
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* `GET /cli/batch`: the delivered batch. With a claim (any of holder-with-token, batch_id, lease_token), and always for an agent Onionskin
|
|
60
|
+
* started, only for the lease holder (Sessions.deliveredBatch), checked before anything of it is returned. A call with no claim and no
|
|
61
|
+
* agent holder (a person's own tools, `apply --dry-run` without a ticket) gets it as before: such a caller can read the file and the state
|
|
62
|
+
* folder anyway; the restricted agent can only run the CLI, which always sends its holder.
|
|
63
|
+
*/
|
|
64
|
+
export function cliBatch(sessions, s, { holder, token, batchId }) {
|
|
65
|
+
if (token || batchId || isAgentHolder(holder)) return { state: sessions.state(s), batch: sessions.deliveredBatch(s.key, { holder, token, batchId }) };
|
|
66
|
+
return { state: sessions.state(s), batch: s.delivered?.batch || null };
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** `GET /cli/batch-file`: the file of the delivery named by a full ticket (batch id and token) for this holder, or null. Never a file for a wrong token. */
|
|
70
|
+
export function batchFile(sessions, { holder, token, batchId }) {
|
|
71
|
+
if (!batchId || !token) return null;
|
|
72
|
+
const s = [...sessions.map.values()].find((x) => x.delivered?.batch.batch_id === batchId && x.delivered.lease.token === token);
|
|
73
|
+
return s && agentMayUse(holder, s.file) ? s.file : null;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** The claim of a GET route's query (holder, lease_token, batch_id). */
|
|
77
|
+
export const claimOfQuery = (q) => leaseOf({ holder: q.get("holder"), lease_token: q.get("lease_token"), batch_id: q.get("batch_id") });
|
|
78
|
+
|
|
40
79
|
/** `GET /cli/status`: what `apply`, `commit` and `done` read about a file's session. One function for the socket and the in-process port. */
|
|
41
80
|
export function cliStatus(sessions, s) {
|
|
42
81
|
const v = sessions.view(s);
|
|
@@ -47,6 +86,29 @@ export function cliStatus(sessions, s) {
|
|
|
47
86
|
};
|
|
48
87
|
}
|
|
49
88
|
|
|
89
|
+
// A tab gone this long no longer holds the update back: the same 20 minutes after which the background agent of a file with no tab stops
|
|
90
|
+
// (src/agent-runner.js LIMITS.idleMs). A forgotten session does not block updates forever.
|
|
91
|
+
export const TAB_RECENT_MS = LIMITS.idleMs;
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* `GET /cli/open-work`: the sum of cliStatus over every session (what `onionskin update` would cut off). Counts only, never file names.
|
|
95
|
+
* `open_sessions`: sessions not closed with a tab open now (`tabs(key)`) or seen less than TAB_RECENT_MS ago (`seen(key)`, a time). The
|
|
96
|
+
* page keeps typed edits to itself until Send, so `unsent_edits` cannot see them: an open tab is the only sign of them.
|
|
97
|
+
*/
|
|
98
|
+
export function openWork(sessions, { tabs = () => 0, seen = () => null, now = Date.now() } = {}) {
|
|
99
|
+
const w = { sessions: 0, open_sessions: 0, unsent_edits: 0, draft_comments: 0, batches: 0 };
|
|
100
|
+
for (const s of sessions.map.values()) {
|
|
101
|
+
const st = cliStatus(sessions, s);
|
|
102
|
+
w.sessions++;
|
|
103
|
+
const t = seen(s.key);
|
|
104
|
+
if (!s.closed && (tabs(s.key) > 0 || (Number.isFinite(t) && now - t < TAB_RECENT_MS))) w.open_sessions++;
|
|
105
|
+
w.unsent_edits += st.unsent_edits;
|
|
106
|
+
w.draft_comments += st.comments.draft;
|
|
107
|
+
if (st.pending_batch || st.delivered_batch) w.batches++;
|
|
108
|
+
}
|
|
109
|
+
return w;
|
|
110
|
+
}
|
|
111
|
+
|
|
50
112
|
/** The person reverted a local run of these words: they go to the agent. True when any comment of the batch, or its whole note, is marked. */
|
|
51
113
|
export function skipsLocal(s, batch) {
|
|
52
114
|
const ids = new Set((batch.instructions?.comments || []).map((c) => c.id));
|
|
@@ -60,9 +122,9 @@ export function skipsLocal(s, batch) {
|
|
|
60
122
|
* An HttpError becomes {status, text} exactly as the socket's fail() writes it, so `apply` takes the same refusal paths.
|
|
61
123
|
*/
|
|
62
124
|
function inProcessPort(sessions, key) {
|
|
63
|
-
const answer = (fn) => {
|
|
125
|
+
const answer = async (fn) => {
|
|
64
126
|
try {
|
|
65
|
-
return { status: 200, text: JSON.stringify(fn()) };
|
|
127
|
+
return { status: 200, text: JSON.stringify(await fn()) };
|
|
66
128
|
} catch (err) {
|
|
67
129
|
if (Number.isInteger(err?.status)) return { status: err.status, text: JSON.stringify({ error: err.message, ...(err.extra || {}) }) };
|
|
68
130
|
return { status: 500, text: JSON.stringify({ error: "internal error" }) };
|
|
@@ -76,16 +138,18 @@ function inProcessPort(sessions, key) {
|
|
|
76
138
|
return {
|
|
77
139
|
healthy: async () => true,
|
|
78
140
|
json: (t) => JSON.parse(t),
|
|
141
|
+
checkBytes: (bytes, format) => readChecked(format, bytes), // apply reads the file again: within the readers' caps before the engine
|
|
142
|
+
runOps: runOpsOffThread, // and the engine's work happens in a worker thread with a time limit, never on the server's thread
|
|
79
143
|
async req({ method, path: p }, body = {}) {
|
|
80
144
|
const u = new URL(p, "http://x");
|
|
81
145
|
const route = `${method} ${u.pathname}`;
|
|
82
146
|
if (route === "GET /cli/status") return answer(() => cliStatus(sessions, mine(u.searchParams.get("file"))));
|
|
83
|
-
if (route === "GET /cli/batch") return answer(() =>
|
|
147
|
+
if (route === "GET /cli/batch") return answer(() => cliBatch(sessions, mine(u.searchParams.get("file")), claimOfQuery(u.searchParams)));
|
|
84
148
|
if (route === "POST /cli/agent-write") {
|
|
85
149
|
return answer(() => {
|
|
86
150
|
const s = mine(body.file);
|
|
87
151
|
const bytes = typeof body.bytes_b64 === "string" ? Buffer.from(body.bytes_b64, "base64") : null;
|
|
88
|
-
return sessions.
|
|
152
|
+
return sessions.agentWriteChecked(s.key, { baseSha: String(body.base_sha256 || ""), bytes, route: "apply", ops: Array.isArray(body.ops) ? body.ops : null, partial: body.partial === true, ...leaseOf(body) });
|
|
89
153
|
});
|
|
90
154
|
}
|
|
91
155
|
if (route === "POST /cli/apply-report") {
|