@wirecat/cli-core 0.709.0 → 0.711.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/CHANGELOG.md +70 -0
- package/dist/cli/bot/api-http.js +23 -2
- package/dist/cli/effects.d.ts +1 -1
- package/dist/cli/effects.js +6 -1
- package/dist/content/manifest/manifest.d.ts +10 -3
- package/dist/content/manifest/manifest.js +8 -0
- package/dist/content/manifest/source.js +32 -17
- package/dist/content/sync.js +11 -2
- package/dist/content/testing/manifest-fake.d.ts +9 -0
- package/dist/content/testing/manifest-fake.js +24 -6
- package/dist/documents/file-mirror-model.d.ts +9 -1
- package/dist/documents/index.d.ts +2 -1
- package/dist/documents/index.js +2 -1
- package/dist/errors/reasons.js +7 -0
- package/dist/http/listen.js +3 -3
- package/dist/mount/index.d.ts +3 -0
- package/dist/mount/index.js +2 -0
- package/dist/mount/serve.d.ts +28 -0
- package/dist/mount/serve.js +31 -0
- package/dist/mount/source.d.ts +31 -0
- package/dist/mount/source.js +1 -0
- package/dist/mount/webdav.d.ts +18 -0
- package/dist/mount/webdav.js +241 -0
- package/dist/ports/wirecat-tools.js +7 -0
- package/dist/services/documents/mirrors.d.ts +2 -0
- package/dist/services/documents/push.d.ts +1 -1
- package/dist/services/documents/push.js +3 -1
- package/dist/services/files/exclusions.d.ts +8 -0
- package/dist/services/files/exclusions.js +39 -0
- package/dist/services/files/mirror.d.ts +43 -7
- package/dist/services/files/mirror.js +176 -31
- package/dist/services/files/versions.d.ts +2 -0
- package/dist/services/files/versions.js +1 -0
- package/package.json +5 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,76 @@ Notable changes to `@wirecat/cli-core` (`@wirecat/cli-messaging` up to 0.261.0,
|
|
|
5
5
|
minor version may break callers, and says how under "Changed — may break callers". `pnpm docs:check` checks the
|
|
6
6
|
shape of this file.
|
|
7
7
|
|
|
8
|
+
## 0.711.0 — 19.11.2026
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- **Mirror exclusions.** `Mirror.exclude` (and `FileMirrorOptions.exclude`) takes globs, read by `excludedBy` and
|
|
13
|
+
checked by `exclusionPattern`. An excluded path is skipped on both sides and is never deleted: adding an exclusion
|
|
14
|
+
trashes nothing, and removing one syncs the path as a new folder. `fileMirrorStatus` leaves excluded paths out.
|
|
15
|
+
- **A file mirror checks free space before it writes.** A run that would leave less free than a tenth of what it
|
|
16
|
+
writes (at least 100 MB, at most 1 GB) on the drive it downloads into, or on the version store's drive, stops with
|
|
17
|
+
`mirror.no-space` and the bytes it needs. The local
|
|
18
|
+
scan takes up to 100,000 files, and a big state is saved less often.
|
|
19
|
+
- **linear joins `WIRECAT_TOOLS`.** Linear (`linear`, `@wirecat/linear-cli`) is on npm since 0.1.0, so every CLI's
|
|
20
|
+
first screen ("Works with") and first-run list of other WireCat tools now name it, and an upload refuses a file from
|
|
21
|
+
its folders (`linear-cli`, `WCLINEAR_`) as it does for the other tools.
|
|
22
|
+
- **A read-only scheduled agent may stage project and meeting findings.** `projects actions add` and
|
|
23
|
+
`meetings actions add` join `messages acknowledge` and `mail findings add` in the propose tier, when the host marks
|
|
24
|
+
them `proposesOnly`. Like mail findings, each stages a cited batch the owner confirms or rejects; nothing becomes a
|
|
25
|
+
fact or a task until he does. memo's task agent needs it to propose tasks from messengers and meetings.
|
|
26
|
+
- **`@wirecat/cli-core/mount`: show a service's folder as a read-only folder on this computer.** `serveMount` serves a
|
|
27
|
+
`MountSource` (`stat`, `list`, `read` of a byte range; it has no write) over WebDAV on 127.0.0.1, which the system's
|
|
28
|
+
own client mounts: `gio mount` on Linux, Finder on macOS, `net use` on Windows. Every request must carry a random
|
|
29
|
+
per-run secret in its path and this machine's `Host`, so another site's page cannot reach it. Only OPTIONS,
|
|
30
|
+
PROPFIND, GET and HEAD are answered; every write method is refused (405, MKCOL 403), and a file is served sandboxed
|
|
31
|
+
so an HTML file on the mount cannot script it. Listings are kept 10 seconds, so a file manager's
|
|
32
|
+
probes do not spend the service's rate limit ([mount](docs/mount.md)).
|
|
33
|
+
|
|
34
|
+
### Changed — may break callers
|
|
35
|
+
|
|
36
|
+
- **A file mirror asks before more than 10 deletions or 50 replacements, whatever its size.** The deletion guard no
|
|
37
|
+
longer lets a share of a big mirror through (40 deletions out of 1,000 files used to pass): more than 10 deletions
|
|
38
|
+
stop the run. More than 50 replacements of existing files, on either side, stop it too, as an editor rewriting
|
|
39
|
+
every file or ransomware encrypting the folder would. `allowReplacements` allows them like `allowDeletions`. The
|
|
40
|
+
stop is no longer thrown: the mirror's result carries one `confirmation_required` error at path `.`
|
|
41
|
+
(`mirror.too-many-deletions` or `mirror.too-many-replacements`), so the other mirrors still sync and a watch reports
|
|
42
|
+
it at every cycle that syncs the mirror. Its message names the counts and the one command that allows them;
|
|
43
|
+
`MirrorHints` gains `sync`, `allowReplacements` and `exclude`, and fills `<id>` and `<count>`. See
|
|
44
|
+
[DOCUMENTS.md](docs/dev/DOCUMENTS.md#plain-files-both-ways).
|
|
45
|
+
- **`FileTarget` needs `exists(path)`.** A file missing from a complete listing is deleted locally only once a
|
|
46
|
+
direct read after the listing finds nothing there, so a page that shifted while it was read, or a lagging flat
|
|
47
|
+
listing, never deletes a file. A remote that changes all the time still has its deletions proven: no listing has to
|
|
48
|
+
stand still.
|
|
49
|
+
|
|
50
|
+
### Fixed
|
|
51
|
+
|
|
52
|
+
- **A local server's answer ends when its body fails part-way.** `listen` left the connection open, and the client
|
|
53
|
+
waited for bytes that never came.
|
|
54
|
+
|
|
55
|
+
## 0.710.0 — 19.11.2026
|
|
56
|
+
|
|
57
|
+
### Added
|
|
58
|
+
|
|
59
|
+
- **A refusal keeps the status its details name, as `inner_status`.** A read refused with an answer that names
|
|
60
|
+
another status under `details` (WordPress's 400 with 403 inside) keeps that number in the error's details; the
|
|
61
|
+
service's text stays out.
|
|
62
|
+
- **`contentManifestFake` takes `lacks` and `denied`:** the rights a sign-in lacks (its rights reads answer false,
|
|
63
|
+
and a call whose `needs` is lacked is refused as WordPress refuses it) and the operations refused with 403.
|
|
64
|
+
|
|
65
|
+
### Fixed
|
|
66
|
+
|
|
67
|
+
- **A content kind read by several calls syncs for a role refused one of them.** A WordPress author or
|
|
68
|
+
contributor may not list pages with a private status: WordPress answers HTTP 400 with 403 in its details, and the
|
|
69
|
+
whole `post` kind failed, so even their own posts stopped syncing. A call's `optional.needs` names a rights read
|
|
70
|
+
and a `check`; unless it is true the call is never sent, and the sync reports a gap with its own text. The kind's
|
|
71
|
+
other calls sync as before, and the gap holds deletions, so no stored row is marked deleted for a skipped call.
|
|
72
|
+
Each rights read is sent once per source, whatever it checks. A content source takes a 400 with 403 inside as a
|
|
73
|
+
refusal, so `optional` reports a gap for it.
|
|
74
|
+
- **A scheduled post the sign-in may not read is a gap, not a failed sync.** Past its time, such a post (a page an
|
|
75
|
+
editor's sign-in stored, read later by an author) is read again; a refusal failed the whole `post` kind on every
|
|
76
|
+
run. It now stays as it was, and the gap holds deletions.
|
|
77
|
+
|
|
8
78
|
## 0.709.0 — 19.11.2026
|
|
9
79
|
|
|
10
80
|
### Added
|
package/dist/cli/bot/api-http.js
CHANGED
|
@@ -171,7 +171,8 @@ export const httpApiExchange = (options) => async (command, operation, request)
|
|
|
171
171
|
if (!response.ok) {
|
|
172
172
|
const failed = status >= 500 && writes
|
|
173
173
|
? refusal(options.service, operation, response, writes)
|
|
174
|
-
: (options.failure?.(status, answer, operation) ??
|
|
174
|
+
: (options.failure?.(status, answer, operation) ??
|
|
175
|
+
refusal(options.service, operation, response, writes, innerStatus(answer)));
|
|
175
176
|
end({ status, error: failed });
|
|
176
177
|
throw failed;
|
|
177
178
|
}
|
|
@@ -224,7 +225,26 @@ const unreadable = (service, writes, status) => writes
|
|
|
224
225
|
retryable: false,
|
|
225
226
|
})
|
|
226
227
|
: new CliError("invalid_response", `${service} sent an answer that could not be read`, { status, retryable: true });
|
|
227
|
-
|
|
228
|
+
/**
|
|
229
|
+
* The status a refusal's `details` name, as WordPress answers a role a status it may not read: HTTP 400 with 403 in
|
|
230
|
+
* `data.details`. Only the number is kept, never the service's text (WC-SECR-6).
|
|
231
|
+
*/
|
|
232
|
+
const innerStatus = (answer) => {
|
|
233
|
+
const find = (value, depth, inDetails) => {
|
|
234
|
+
if (depth > 5 || typeof value !== "object" || value === null || Array.isArray(value))
|
|
235
|
+
return undefined;
|
|
236
|
+
for (const [key, one] of Object.entries(value)) {
|
|
237
|
+
if (inDetails && key === "status" && typeof one === "number" && one >= 400 && one < 600)
|
|
238
|
+
return one;
|
|
239
|
+
const found = find(one, depth + 1, inDetails || key === "details");
|
|
240
|
+
if (found !== undefined)
|
|
241
|
+
return found;
|
|
242
|
+
}
|
|
243
|
+
return undefined;
|
|
244
|
+
};
|
|
245
|
+
return find(answer, 0, false);
|
|
246
|
+
};
|
|
247
|
+
const refusal = (service, operation, response, writes, inner) => {
|
|
228
248
|
const { status } = response;
|
|
229
249
|
if (status === 429) {
|
|
230
250
|
const wait = providerWaitMs(response.headers, wallClock);
|
|
@@ -262,5 +282,6 @@ const refusal = (service, operation, response, writes) => {
|
|
|
262
282
|
return new CliError(statusToCode(status), `${service} refused ${operation.command} (HTTP ${status})`, {
|
|
263
283
|
status,
|
|
264
284
|
retryable: status >= 500,
|
|
285
|
+
...(inner === undefined || inner === status ? {} : { inner_status: inner }),
|
|
265
286
|
});
|
|
266
287
|
};
|
package/dist/cli/effects.d.ts
CHANGED
|
@@ -45,7 +45,7 @@ export declare const destroysNothing: <T extends Command>(command: T) => T;
|
|
|
45
45
|
* be marked `proposesOnly` **and** end with one of these paths; adding a path widens what a read-only agent can
|
|
46
46
|
* write, so it needs its own review.
|
|
47
47
|
*/
|
|
48
|
-
export declare const PROPOSE_COMMANDS: readonly ["messages acknowledge", "mail findings add"];
|
|
48
|
+
export declare const PROPOSE_COMMANDS: readonly ["messages acknowledge", "mail findings add", "projects actions add", "meetings actions add"];
|
|
49
49
|
/** Marks a command of the `propose` tier; the lock lets it through only when its path is in `PROPOSE_COMMANDS`. */
|
|
50
50
|
export declare const proposesOnly: <T extends Command>(command: T) => T;
|
|
51
51
|
export declare const isProposal: (command: Command) => boolean;
|
package/dist/cli/effects.js
CHANGED
|
@@ -66,7 +66,12 @@ export const destroysNothing = (command) => {
|
|
|
66
66
|
* be marked `proposesOnly` **and** end with one of these paths; adding a path widens what a read-only agent can
|
|
67
67
|
* write, so it needs its own review.
|
|
68
68
|
*/
|
|
69
|
-
export const PROPOSE_COMMANDS = [
|
|
69
|
+
export const PROPOSE_COMMANDS = [
|
|
70
|
+
"messages acknowledge",
|
|
71
|
+
"mail findings add",
|
|
72
|
+
"projects actions add",
|
|
73
|
+
"meetings actions add",
|
|
74
|
+
];
|
|
70
75
|
const PROPOSES = new WeakSet();
|
|
71
76
|
/** Marks a command of the `propose` tier; the lock lets it through only when its path is in `PROPOSE_COMMANDS`. */
|
|
72
77
|
export const proposesOnly = (command) => {
|
|
@@ -39,16 +39,23 @@ export interface ContentManifestEntity {
|
|
|
39
39
|
/**
|
|
40
40
|
* The sign-in may be refused this call (a role without the right): a gap with this text, and the rest syncs. A
|
|
41
41
|
* source that leaves rows out without an error names `requires`: a read whose value at `check` is true when the
|
|
42
|
-
* sign-in sees every row; false or missing is the same gap.
|
|
42
|
+
* sign-in sees every row; false or missing is the same gap. A source that refuses the call outright to a role names
|
|
43
|
+
* `needs`: unless its `check` is true the call is never sent, and the gap says its own `message`.
|
|
43
44
|
*/
|
|
44
45
|
optional?: {
|
|
45
46
|
message: string;
|
|
46
47
|
scope?: string;
|
|
47
|
-
requires?:
|
|
48
|
-
|
|
48
|
+
requires?: ContentRightsCall;
|
|
49
|
+
needs?: ContentRightsCall & {
|
|
50
|
+
message: string;
|
|
51
|
+
scope?: string;
|
|
49
52
|
};
|
|
50
53
|
};
|
|
51
54
|
}
|
|
55
|
+
/** A read of the sign-in's rights, true at `check` when it has the right (WordPress: `users/me`'s capabilities). */
|
|
56
|
+
export type ContentRightsCall = CrmOperationCall & {
|
|
57
|
+
check: string;
|
|
58
|
+
};
|
|
52
59
|
/** A post's writes, as calls and values over the update call. `"{id}"` and `"{at}"` are filled by the engine. */
|
|
53
60
|
export interface ContentManifestWrites {
|
|
54
61
|
create: CrmOperationCall;
|
|
@@ -30,6 +30,12 @@ const entity = v.strictObject({
|
|
|
30
30
|
message: v.pipe(v.string(), v.minLength(1)),
|
|
31
31
|
scope: v.optional(v.string()),
|
|
32
32
|
requires: v.optional(v.strictObject({ ...call.entries, check: path })),
|
|
33
|
+
needs: v.optional(v.strictObject({
|
|
34
|
+
...call.entries,
|
|
35
|
+
check: path,
|
|
36
|
+
message: v.pipe(v.string(), v.minLength(1)),
|
|
37
|
+
scope: v.optional(v.string()),
|
|
38
|
+
})),
|
|
33
39
|
})),
|
|
34
40
|
});
|
|
35
41
|
const schema = v.strictObject({
|
|
@@ -101,6 +107,8 @@ export const parseContentManifest = (input, api) => {
|
|
|
101
107
|
checkCall(`${where}.ids`, one.ids, true);
|
|
102
108
|
if (one.optional?.requires)
|
|
103
109
|
checkCall(`${where}.optional.requires`, one.optional.requires, true);
|
|
110
|
+
if (one.optional?.needs)
|
|
111
|
+
checkCall(`${where}.optional.needs`, one.optional.needs, true);
|
|
104
112
|
if (one.get) {
|
|
105
113
|
checkCall(`${where}.get`, one.get, true);
|
|
106
114
|
if (!holds([one.get.path, one.get.query], "{id}"))
|
|
@@ -3,7 +3,7 @@ import { nextPage, parameterValue, withValue } from "../../cli/service-api-manif
|
|
|
3
3
|
import { crmValues } from "../../crm/index.js";
|
|
4
4
|
import { at, evaluate, MISSING } from "../../crm/manifest/map.js";
|
|
5
5
|
import { GET_UNSUPPORTED, } from "../source.js";
|
|
6
|
-
import { parseContentManifest } from "./manifest.js";
|
|
6
|
+
import { parseContentManifest, } from "./manifest.js";
|
|
7
7
|
import { mapContentRecord, postBodyOf, utcEpoch } from "./map.js";
|
|
8
8
|
/**
|
|
9
9
|
* The one channel's id, the same whatever the site's address: a profile pointed at another address is then a moved
|
|
@@ -66,7 +66,9 @@ const pageOf = (page, now) => {
|
|
|
66
66
|
return Number.isSafeInteger(call) && call >= 0 ? { call, token, started } : { call: -1, token: undefined, started };
|
|
67
67
|
};
|
|
68
68
|
const gone = (error) => isCliError(error) && error.code === "not_found";
|
|
69
|
-
|
|
69
|
+
// A service may refuse a role with a 400 whose details say 403 (WordPress, for a status the role may not read).
|
|
70
|
+
const refused = (error) => isCliError(error) &&
|
|
71
|
+
(error.code === "permission_error" || error.code === "not_found" || error.details.inner_status === 403);
|
|
70
72
|
/**
|
|
71
73
|
* A `ContentSource` read from a manifest: each kind by the calls it names, paged by each operation's own
|
|
72
74
|
* `pagination`, each row mapped onto the content domain, a post's text turned into Markdown.
|
|
@@ -136,23 +138,35 @@ export const contentSourceFromManifest = (input, options) => {
|
|
|
136
138
|
return records;
|
|
137
139
|
};
|
|
138
140
|
const rights = new Map();
|
|
139
|
-
/** Whether the sign-in
|
|
141
|
+
/** Whether the sign-in has the right `check` names; each rights read is sent once per source, whatever it checks. */
|
|
142
|
+
const has = async (read, send) => {
|
|
143
|
+
const request = inputOf(read, {});
|
|
144
|
+
const key = JSON.stringify([read.operation, request]);
|
|
145
|
+
let answer = rights.get(key);
|
|
146
|
+
if (answer === undefined) {
|
|
147
|
+
answer = send(read.operation, request);
|
|
148
|
+
rights.set(key, answer);
|
|
149
|
+
answer.catch(() => rights.delete(key));
|
|
150
|
+
}
|
|
151
|
+
return at(await answer, read.check) === true;
|
|
152
|
+
};
|
|
153
|
+
/**
|
|
154
|
+
* Whether the call may be sent: a role its `needs` read refuses is a gap, and the call is skipped. Else a sign-in
|
|
155
|
+
* its `requires` read says sees only part is a gap, and the call is sent.
|
|
156
|
+
*/
|
|
140
157
|
const checkRights = async (kind, entity, send, context) => {
|
|
141
|
-
const requires = entity.optional
|
|
142
|
-
if (!
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
let seen = rights.get(key);
|
|
146
|
-
if (seen === undefined) {
|
|
147
|
-
seen = at(await send(requires.operation, inputOf(requires, {})), requires.check) === true;
|
|
148
|
-
rights.set(key, seen);
|
|
158
|
+
const { needs, requires } = entity.optional ?? {};
|
|
159
|
+
if (needs && !(await has(needs, send))) {
|
|
160
|
+
context?.gap({ kind, message: needs.message, ...(needs.scope ? { scope: needs.scope } : {}) });
|
|
161
|
+
return false;
|
|
149
162
|
}
|
|
150
|
-
if (!
|
|
163
|
+
if (requires && !(await has(requires, send)))
|
|
151
164
|
context?.gap({
|
|
152
165
|
kind,
|
|
153
166
|
message: entity.optional?.message ?? "",
|
|
154
167
|
...(entity.optional?.scope ? { scope: entity.optional.scope } : {}),
|
|
155
168
|
});
|
|
169
|
+
return true;
|
|
156
170
|
};
|
|
157
171
|
const gapOf = (kind, entity, error, context) => {
|
|
158
172
|
if (!entity.optional || !refused(error))
|
|
@@ -189,9 +203,9 @@ export const contentSourceFromManifest = (input, options) => {
|
|
|
189
203
|
const changes = since === null ? undefined : entity.changes;
|
|
190
204
|
let read;
|
|
191
205
|
try {
|
|
192
|
-
await checkRights(kind, entity, send, context)
|
|
193
|
-
|
|
194
|
-
changes?.keyset && since !== null
|
|
206
|
+
read = !(await checkRights(kind, entity, send, context))
|
|
207
|
+
? { rows: [], next: undefined }
|
|
208
|
+
: changes?.keyset && since !== null
|
|
195
209
|
? await keysetPage({ ...changes, keyset: changes.keyset }, spot.token === undefined ? since - overlap : Number(spot.token), send)
|
|
196
210
|
: await readPage(changes ?? entity.list, changes && since !== null ? { since: SINCE[changes.since](since - overlap) } : {}, spot.token, send);
|
|
197
211
|
}
|
|
@@ -218,8 +232,9 @@ export const contentSourceFromManifest = (input, options) => {
|
|
|
218
232
|
let read;
|
|
219
233
|
const send = metered(context);
|
|
220
234
|
try {
|
|
221
|
-
await checkRights(kind, entity, send, context)
|
|
222
|
-
|
|
235
|
+
read = (await checkRights(kind, entity, send, context))
|
|
236
|
+
? await readPage(entity.ids ?? entity.list, {}, spot.token, send)
|
|
237
|
+
: { rows: [], next: undefined };
|
|
223
238
|
}
|
|
224
239
|
catch (error) {
|
|
225
240
|
// Refused, the ids read so far would mark every unread row deleted: the gap holds the pass.
|
package/dist/content/sync.js
CHANGED
|
@@ -8,6 +8,8 @@ const MOST_UNLISTED = 0.5;
|
|
|
8
8
|
const GUARDED_FROM = 10;
|
|
9
9
|
/** Scheduled posts past their time read one by one per run; more wait for the next. */
|
|
10
10
|
const MOST_DUE = 50;
|
|
11
|
+
/** The sign-in may not read it, which proves nothing about the row; WordPress also refuses with 400 and 403 inside. */
|
|
12
|
+
const refusedRead = (error) => isCliError(error) && (error.code === "permission_error" || error.details.inner_status === 403);
|
|
11
13
|
const fresh = () => ({ v: 1, token: null, round: null, passAt: 0 });
|
|
12
14
|
const parsed = (value) => {
|
|
13
15
|
try {
|
|
@@ -170,7 +172,14 @@ const readDue = async (run, result) => {
|
|
|
170
172
|
catch (error) {
|
|
171
173
|
if (isCliError(error) && error.details.reason === GET_UNSUPPORTED)
|
|
172
174
|
return null;
|
|
173
|
-
|
|
175
|
+
// An author's scheduled page, stored by an editor's sign-in: a refusal holds it, and the other posts go on.
|
|
176
|
+
if (!refusedRead(error))
|
|
177
|
+
throw error;
|
|
178
|
+
run.context.gap({
|
|
179
|
+
kind: "post",
|
|
180
|
+
message: `${source.provider} would not give this sign-in every post: ${error.message}`,
|
|
181
|
+
});
|
|
182
|
+
continue;
|
|
174
183
|
}
|
|
175
184
|
if (post)
|
|
176
185
|
result.saved += await store.content.save(account, "post", [post], run.now);
|
|
@@ -213,7 +222,7 @@ const confirmGone = async (run, kind, missing, result) => {
|
|
|
213
222
|
catch (error) {
|
|
214
223
|
// WordPress leaves others' drafts out of a contributor's list and refuses to read them, and a row of a status we
|
|
215
224
|
// do not know reads as nothing: neither proves it gone.
|
|
216
|
-
if (
|
|
225
|
+
if (refusedRead(error) || (isCliError(error) && error.code === "invalid_response")) {
|
|
217
226
|
run.context.gap({
|
|
218
227
|
kind,
|
|
219
228
|
message: `${source.provider} would not give this sign-in every ${kind}: ${error.message}`,
|
|
@@ -12,6 +12,15 @@ export interface ContentManifestFakeOptions {
|
|
|
12
12
|
pageSize?: number;
|
|
13
13
|
/** The service's clock, for the change time a write stamps. */
|
|
14
14
|
clock?: () => number;
|
|
15
|
+
/**
|
|
16
|
+
* The rights the sign-in lacks, as the `check` paths of the manifest's `requires` and `needs` reads
|
|
17
|
+
* (`capabilities.edit_pages`): they answer false. A call whose `needs` is lacked is refused, as WordPress refuses an
|
|
18
|
+
* author pages with a private status: a list with HTTP 400 and 403 in its details, one row with 403. It lands in
|
|
19
|
+
* `refusals`.
|
|
20
|
+
*/
|
|
21
|
+
lacks?: readonly string[];
|
|
22
|
+
/** Operations refused with 403 to this sign-in, as WordPress refuses an author the users list. */
|
|
23
|
+
denied?: readonly string[];
|
|
15
24
|
}
|
|
16
25
|
export interface ContentManifestFake {
|
|
17
26
|
/** Reads as `serviceApiCall` sends them, with the answer's headers through `withHeaders`. */
|
|
@@ -169,10 +169,10 @@ export const contentManifestFake = (input, options) => {
|
|
|
169
169
|
...(entity.get ? [{ kind, index, role: "get", call: entity.get }] : []),
|
|
170
170
|
{ kind, index, role: "list", call: entity.list },
|
|
171
171
|
...(entity.ids ? [{ kind, index, role: "list", call: entity.ids }] : []),
|
|
172
|
-
...
|
|
173
|
-
? [{ kind, index, role: "requires", call: entity.optional.requires }]
|
|
174
|
-
: []),
|
|
172
|
+
...[entity.optional?.requires, entity.optional?.needs].flatMap((call) => call ? [{ kind, index, role: "rights", call }] : []),
|
|
175
173
|
]));
|
|
174
|
+
const lacks = new Set(options.lacks ?? []);
|
|
175
|
+
const checks = manifest.kinds.flatMap((kind) => entities(kind).flatMap((entity) => [entity.optional?.requires, entity.optional?.needs].flatMap((call) => (call ? [call] : []))));
|
|
176
176
|
const carries = (route, request) => {
|
|
177
177
|
const fixed = fixedOf({ path: route.call.path ?? {}, query: route.call.query ?? {} });
|
|
178
178
|
const own = { path: request.path, query: request.query };
|
|
@@ -241,13 +241,28 @@ export const contentManifestFake = (input, options) => {
|
|
|
241
241
|
refusals.push(operation);
|
|
242
242
|
throw new CliError("configuration_error", `the content fake answers no ${operation} call like this`);
|
|
243
243
|
}
|
|
244
|
+
if (options.denied?.includes(operation))
|
|
245
|
+
throw new CliError("permission_error", `the content fake denies ${operation} to this sign-in`);
|
|
244
246
|
const entity = entities(route.kind)[route.index];
|
|
245
247
|
const held = rows[route.kind]?.[route.index] ?? [];
|
|
246
|
-
|
|
248
|
+
// One rights read answers every right the manifest checks with it.
|
|
249
|
+
if (route.role === "rights") {
|
|
247
250
|
const body = {};
|
|
248
|
-
|
|
251
|
+
for (const one of checks)
|
|
252
|
+
if (one.operation === operation && carries({ ...route, call: one }, request))
|
|
253
|
+
put(body, one.check, !lacks.has(one.check));
|
|
249
254
|
return { body, headers: new Headers() };
|
|
250
255
|
}
|
|
256
|
+
const needs = entity.optional?.needs;
|
|
257
|
+
if (needs && lacks.has(needs.check)) {
|
|
258
|
+
refusals.push(operation);
|
|
259
|
+
if (route.role === "get")
|
|
260
|
+
throw new CliError("permission_error", `the content fake denies ${operation} to this sign-in`);
|
|
261
|
+
throw new CliError("validation_error", `the content fake refuses ${operation} to this sign-in`, {
|
|
262
|
+
status: 400,
|
|
263
|
+
inner_status: 403,
|
|
264
|
+
});
|
|
265
|
+
}
|
|
251
266
|
if (route.role === "get") {
|
|
252
267
|
const place = placeOf(route.call, "{id}");
|
|
253
268
|
const id = place ? request[place.in][place.name] : undefined;
|
|
@@ -375,7 +390,10 @@ export const contentManifestFake = (input, options) => {
|
|
|
375
390
|
catch (error) {
|
|
376
391
|
if (!(error instanceof CliError) || error.code === "outcome_unknown")
|
|
377
392
|
throw error;
|
|
378
|
-
|
|
393
|
+
const inner = error.details.inner_status;
|
|
394
|
+
return Response.json(inner === undefined
|
|
395
|
+
? { message: error.message }
|
|
396
|
+
: { message: error.message, data: { status: 400, details: { status: { data: { status: inner } } } } }, { status: statusOf(error) });
|
|
379
397
|
}
|
|
380
398
|
};
|
|
381
399
|
const call = Object.assign(async (operation, request) => (await read(operation, request)).body, {
|
|
@@ -29,12 +29,20 @@ export interface FileTarget {
|
|
|
29
29
|
/**
|
|
30
30
|
* Every file under `root`, with the root folder's own id; undefined when the folder does not exist. `complete` is
|
|
31
31
|
* false when any page was skipped or a cap was hit: a file missing from such a listing is not taken as deleted.
|
|
32
|
+
* Files at paths `excluded` names are listed too, so a file moved there is found by its id, but count toward no cap.
|
|
32
33
|
*/
|
|
33
|
-
list(root: string, signal?: AbortSignal
|
|
34
|
+
list(root: string, signal?: AbortSignal, options?: {
|
|
35
|
+
excluded?(path: string): boolean;
|
|
36
|
+
}): Promise<{
|
|
34
37
|
rootId: string;
|
|
35
38
|
files: RemoteFile[];
|
|
36
39
|
complete: boolean;
|
|
37
40
|
} | undefined>;
|
|
41
|
+
/**
|
|
42
|
+
* Whether anything is at `path` now, read directly rather than from a listing; false only when the provider says
|
|
43
|
+
* nothing is there. A file missing from a listing is deleted only once this says so.
|
|
44
|
+
*/
|
|
45
|
+
exists(path: string, signal?: AbortSignal): Promise<boolean>;
|
|
38
46
|
/** Streams the file into `into`, a new local file. */
|
|
39
47
|
download(path: string, into: string, signal?: AbortSignal): Promise<void>;
|
|
40
48
|
/** Streams the local file `from` to `path` and returns the file as the remote now has it. */
|
|
@@ -10,7 +10,8 @@ export type { SyncOptions } from "../services/documents/ports.js";
|
|
|
10
10
|
export { extractDocumentMemories, type ImportedSource, type ProposalOptions } from "../services/documents/proposals.js";
|
|
11
11
|
export { type MirrorAction, type PushConflict, type PushOptions, type PushResult, planPush, pushDocuments, scanLocal, skippedName, } from "../services/documents/push.js";
|
|
12
12
|
export { type SyncResult, syncDocuments } from "../services/documents/sync.js";
|
|
13
|
-
export {
|
|
13
|
+
export { excludedBy, exclusionPattern } from "../services/files/exclusions.js";
|
|
14
|
+
export { type FileMirrorOptions, type FileMirrorResult, type FileMirrorSyncOptions, type FileStep, fileMirrorStatus, fileRemoteChanges, fileSyncState, MAX_DELETIONS, MAX_REPLACEMENTS, type MirrorHints, syncFileMirror, syncFileMirrors, } from "../services/files/mirror.js";
|
|
14
15
|
export { type FileVersion, type FileVersions, fileVersions, restoreFileVersion, type VersionDirection, type VersionEvent, } from "../services/files/versions.js";
|
|
15
16
|
export { type Block, blockKey, blockShape, type Inline, type ListKind, normalizeInlines } from "./blocks.js";
|
|
16
17
|
export { catalogFiles } from "./catalog.js";
|
package/dist/documents/index.js
CHANGED
|
@@ -9,7 +9,8 @@ export { conflictReport, fileMirrorState, mirrorId, mirrorStatus, syncMirrors, }
|
|
|
9
9
|
export { extractDocumentMemories } from "../services/documents/proposals.js";
|
|
10
10
|
export { planPush, pushDocuments, scanLocal, skippedName, } from "../services/documents/push.js";
|
|
11
11
|
export { syncDocuments } from "../services/documents/sync.js";
|
|
12
|
-
export {
|
|
12
|
+
export { excludedBy, exclusionPattern } from "../services/files/exclusions.js";
|
|
13
|
+
export { fileMirrorStatus, fileRemoteChanges, fileSyncState, MAX_DELETIONS, MAX_REPLACEMENTS, syncFileMirror, syncFileMirrors, } from "../services/files/mirror.js";
|
|
13
14
|
export { fileVersions, restoreFileVersion, } from "../services/files/versions.js";
|
|
14
15
|
export { blockKey, blockShape, normalizeInlines } from "./blocks.js";
|
|
15
16
|
export { catalogFiles } from "./catalog.js";
|
package/dist/errors/reasons.js
CHANGED
|
@@ -228,6 +228,13 @@ const OTHERS = [
|
|
|
228
228
|
"confirmation_required",
|
|
229
229
|
"the sync would delete more files than the guard allows; check them with --dry-run and allow them explicitly",
|
|
230
230
|
],
|
|
231
|
+
[
|
|
232
|
+
"mirror.too-many-replacements",
|
|
233
|
+
"confirmation_required",
|
|
234
|
+
"the sync would replace more files than the guard allows; check them with --dry-run and allow them explicitly",
|
|
235
|
+
],
|
|
236
|
+
validation("mirror.no-space", "the sync needs more free space than the local drive has"),
|
|
237
|
+
validation("mirror.bad-exclusion", "the exclusion is not a path pattern inside the mirror"),
|
|
231
238
|
[
|
|
232
239
|
"mirror.version-not-kept",
|
|
233
240
|
"provider_error",
|
package/dist/http/listen.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createServer } from "node:http";
|
|
2
|
-
import { Readable } from "node:stream";
|
|
2
|
+
import { pipeline, Readable } from "node:stream";
|
|
3
3
|
/** Larger bodies are refused unread: the port faces the internet. MCP requests are small JSON. */
|
|
4
4
|
export const MAX_BODY = 4 * 1024 * 1024;
|
|
5
5
|
class TooLarge extends Error {
|
|
@@ -41,8 +41,8 @@ const send = async (response, outgoing) => {
|
|
|
41
41
|
if (!response.body)
|
|
42
42
|
return void outgoing.end();
|
|
43
43
|
const body = Readable.fromWeb(response.body);
|
|
44
|
-
|
|
45
|
-
body
|
|
44
|
+
// pipe() leaves the answer open when the body fails mid-way, and the client waits for bytes that never come.
|
|
45
|
+
pipeline(body, outgoing, () => undefined);
|
|
46
46
|
};
|
|
47
47
|
/**
|
|
48
48
|
* Binds `host` only — never every interface: the public address is the owner's tunnel.
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { MountSource } from "./source.js";
|
|
2
|
+
export interface MountOptions {
|
|
3
|
+
/** 0 picks a free port. */
|
|
4
|
+
port?: number;
|
|
5
|
+
/** A new random one each run when left out. */
|
|
6
|
+
secret?: string;
|
|
7
|
+
cacheMs?: number;
|
|
8
|
+
now?: () => number;
|
|
9
|
+
onError?: (error: unknown) => void;
|
|
10
|
+
}
|
|
11
|
+
export interface Mounted {
|
|
12
|
+
/** Holds the per-run secret and nothing else: no token, no account. */
|
|
13
|
+
url: string;
|
|
14
|
+
/** The command or the steps that mount `url` on each system. */
|
|
15
|
+
how: {
|
|
16
|
+
linux: string;
|
|
17
|
+
macos: string;
|
|
18
|
+
windows: string;
|
|
19
|
+
};
|
|
20
|
+
close(): Promise<void>;
|
|
21
|
+
}
|
|
22
|
+
/** The ways to mount a URL the system's own WebDAV client understands, so no driver is installed. */
|
|
23
|
+
export declare const mountSteps: (url: string) => Mounted["how"];
|
|
24
|
+
/**
|
|
25
|
+
* Serves `source` read-only over WebDAV on 127.0.0.1, behind a random secret in the path. Only this machine can
|
|
26
|
+
* reach it, and only a client that was given the URL.
|
|
27
|
+
*/
|
|
28
|
+
export declare const serveMount: (source: MountSource, options?: MountOptions) => Promise<Mounted>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { randomBytes } from "node:crypto";
|
|
2
|
+
import { listen } from "../http/listen.js";
|
|
3
|
+
import { webdavHandler } from "./webdav.js";
|
|
4
|
+
const HOST = "127.0.0.1";
|
|
5
|
+
/** A PROPFIND body is a few hundred bytes; a larger body, such as a file a client tries to upload, is refused unread. */
|
|
6
|
+
const MOST_BODY = 64 * 1024;
|
|
7
|
+
/** The ways to mount a URL the system's own WebDAV client understands, so no driver is installed. */
|
|
8
|
+
export const mountSteps = (url) => ({
|
|
9
|
+
linux: `gio mount ${url.replace(/^http:/u, "dav:")}`,
|
|
10
|
+
macos: `Finder > Go > Connect to Server (Cmd+K), then ${url}`,
|
|
11
|
+
windows: `net use * ${url}`,
|
|
12
|
+
});
|
|
13
|
+
/**
|
|
14
|
+
* Serves `source` read-only over WebDAV on 127.0.0.1, behind a random secret in the path. Only this machine can
|
|
15
|
+
* reach it, and only a client that was given the URL.
|
|
16
|
+
*/
|
|
17
|
+
export const serveMount = async (source, options = {}) => {
|
|
18
|
+
const secret = options.secret ?? randomBytes(24).toString("base64url");
|
|
19
|
+
let port = options.port ?? 0;
|
|
20
|
+
const handle = webdavHandler(source, {
|
|
21
|
+
secret,
|
|
22
|
+
hosts: () => [`${HOST}:${port}`, `localhost:${port}`],
|
|
23
|
+
...(options.cacheMs === undefined ? {} : { cacheMs: options.cacheMs }),
|
|
24
|
+
...(options.now ? { now: options.now } : {}),
|
|
25
|
+
...(options.onError ? { onError: options.onError } : {}),
|
|
26
|
+
});
|
|
27
|
+
const listening = await listen(handle, { host: HOST, port, maxBody: MOST_BODY });
|
|
28
|
+
port = Number(listening.url.port);
|
|
29
|
+
const url = `http://${HOST}:${port}/${secret}/`;
|
|
30
|
+
return { url, how: mountSteps(url), close: listening.close };
|
|
31
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/** One file or folder as a mount shows it. */
|
|
2
|
+
export interface MountEntry {
|
|
3
|
+
name: string;
|
|
4
|
+
folder: boolean;
|
|
5
|
+
size?: number;
|
|
6
|
+
/** ISO 8601. */
|
|
7
|
+
modifiedAt?: string;
|
|
8
|
+
createdAt?: string;
|
|
9
|
+
mime?: string;
|
|
10
|
+
/** Changes when the content does, such as an md5; it becomes the ETag. */
|
|
11
|
+
version?: string;
|
|
12
|
+
}
|
|
13
|
+
/** Inclusive, as HTTP's `Range: bytes=start-end`. */
|
|
14
|
+
export interface ByteRange {
|
|
15
|
+
start: number;
|
|
16
|
+
end: number;
|
|
17
|
+
}
|
|
18
|
+
export interface MountRead {
|
|
19
|
+
body: ReadableStream<Uint8Array>;
|
|
20
|
+
/** True when `body` holds only the range asked for; false when the service sent the whole file. */
|
|
21
|
+
ranged: boolean;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* What a service hands a mount. It has no method that changes anything, so a mount cannot write, whatever a client
|
|
25
|
+
* asks. Paths are `/` or `/a/b`, under the folder the owner mounted; a missing item throws `not_found`.
|
|
26
|
+
*/
|
|
27
|
+
export interface MountSource {
|
|
28
|
+
stat(path: string): Promise<MountEntry>;
|
|
29
|
+
list(path: string): Promise<MountEntry[]>;
|
|
30
|
+
read(path: string, entry: MountEntry, range?: ByteRange): Promise<MountRead>;
|
|
31
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { MountSource } from "./source.js";
|
|
2
|
+
export interface WebdavOptions {
|
|
3
|
+
/** The first path segment every request must carry; the URL the owner mounts holds it. */
|
|
4
|
+
secret: string;
|
|
5
|
+
/** The `Host` values a request may carry, such as `127.0.0.1:8080`; any other is a page on another site. */
|
|
6
|
+
hosts: () => readonly string[];
|
|
7
|
+
/** How long a listing or a stat answers from memory. */
|
|
8
|
+
cacheMs?: number;
|
|
9
|
+
now?: () => number;
|
|
10
|
+
/** A failure other than `not_found`, for the command to report; never the request, whose path holds the secret. */
|
|
11
|
+
onError?: (error: unknown) => void;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* A read-only WebDAV server over a `MountSource`, as a web-standard handler. Every request must name an allowed
|
|
15
|
+
* `Host` (a page on another site that rebinds its name to 127.0.0.1 cannot), carry no foreign `Origin`, and start
|
|
16
|
+
* with the secret; it may only read. Answers carry no CORS header, so no page can read them.
|
|
17
|
+
*/
|
|
18
|
+
export declare const webdavHandler: (source: MountSource, options: WebdavOptions) => (request: Request) => Promise<Response>;
|