@foleo/cli 0.1.48 → 0.1.55
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/README.md +150 -0
- package/dist/edit-context.d.ts +15 -0
- package/dist/edit-context.d.ts.map +1 -0
- package/dist/edit-context.js +83 -0
- package/dist/edit-context.js.map +1 -0
- package/dist/index.d.ts +11 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +753 -72
- package/dist/index.js.map +1 -1
- package/dist/members.d.ts +10 -0
- package/dist/members.d.ts.map +1 -0
- package/dist/members.js +129 -0
- package/dist/members.js.map +1 -0
- package/dist/move.d.ts +11 -0
- package/dist/move.d.ts.map +1 -0
- package/dist/move.js +149 -0
- package/dist/move.js.map +1 -0
- package/dist/path-workspace.d.ts +12 -0
- package/dist/path-workspace.d.ts.map +1 -0
- package/dist/path-workspace.js +506 -0
- package/dist/path-workspace.js.map +1 -0
- package/dist/shared.d.ts +6 -0
- package/dist/shared.d.ts.map +1 -0
- package/dist/shared.js +44 -0
- package/dist/shared.js.map +1 -0
- package/dist/workspace-binding.d.ts +3 -0
- package/dist/workspace-binding.d.ts.map +1 -0
- package/dist/workspace-binding.js +37 -0
- package/dist/workspace-binding.js.map +1 -0
- package/dist/workspace-default.d.ts +4 -0
- package/dist/workspace-default.d.ts.map +1 -0
- package/dist/workspace-default.js +32 -0
- package/dist/workspace-default.js.map +1 -0
- package/dist/workspaces.d.ts +8 -1
- package/dist/workspaces.d.ts.map +1 -1
- package/dist/workspaces.js +224 -50
- package/dist/workspaces.js.map +1 -1
- package/package.json +1 -1
- package/skills/foleo/SKILL.md +440 -17
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** A non-authoritative preference; credentials and live /me still prove authority. */
|
|
2
|
+
export declare function loadDefaultWorkspace(env: NodeJS.ProcessEnv, api: string): Promise<string | null>;
|
|
3
|
+
export declare function saveDefaultWorkspace(env: NodeJS.ProcessEnv, api: string, handle: string): Promise<void>;
|
|
4
|
+
//# sourceMappingURL=workspace-default.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workspace-default.d.ts","sourceRoot":"","sources":["../src/workspace-default.ts"],"names":[],"mappings":"AAUA,sFAAsF;AACtF,wBAAsB,oBAAoB,CACxC,GAAG,EAAE,MAAM,CAAC,UAAU,EACtB,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAaxB;AACD,wBAAsB,oBAAoB,CACxC,GAAG,EAAE,MAAM,CAAC,UAAU,EACtB,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,IAAI,CAAC,CASf"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
2
|
+
import { mkdir, readFile, rename, writeFile } from "node:fs/promises";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { cliStateRoot } from "./edit-context.js";
|
|
5
|
+
function path(env, api) {
|
|
6
|
+
return join(cliStateRoot(env), createHash("sha256").update(api).digest("hex") + ".default-workspace.json");
|
|
7
|
+
}
|
|
8
|
+
/** A non-authoritative preference; credentials and live /me still prove authority. */
|
|
9
|
+
export async function loadDefaultWorkspace(env, api) {
|
|
10
|
+
try {
|
|
11
|
+
const value = JSON.parse(await readFile(path(env, api), "utf8"));
|
|
12
|
+
return typeof value.handle === "string" &&
|
|
13
|
+
/^[a-z0-9-]{1,63}$/u.test(value.handle)
|
|
14
|
+
? value.handle
|
|
15
|
+
: null;
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
if (error.code === "ENOENT")
|
|
19
|
+
return null;
|
|
20
|
+
throw error;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export async function saveDefaultWorkspace(env, api, handle) {
|
|
24
|
+
await mkdir(cliStateRoot(env), { recursive: true, mode: 0o700 });
|
|
25
|
+
const target = path(env, api), temp = target + "." + randomUUID();
|
|
26
|
+
await writeFile(temp, JSON.stringify({ handle }) + "\n", {
|
|
27
|
+
mode: 0o600,
|
|
28
|
+
flag: "wx",
|
|
29
|
+
});
|
|
30
|
+
await rename(temp, target);
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=workspace-default.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workspace-default.js","sourceRoot":"","sources":["../src/workspace-default.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACtE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,SAAS,IAAI,CAAC,GAAsB,EAAE,GAAW;IAC/C,OAAO,IAAI,CACT,YAAY,CAAC,GAAG,CAAC,EACjB,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,yBAAyB,CAC3E,CAAC;AACJ,CAAC;AACD,sFAAsF;AACtF,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,GAAsB,EACtB,GAAW;IAEX,IAAI,CAAC;QACH,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,QAAQ,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,MAAM,CAAC,CAE9D,CAAC;QACF,OAAO,OAAO,KAAK,CAAC,MAAM,KAAK,QAAQ;YACrC,oBAAoB,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC;YACvC,CAAC,CAAC,KAAK,CAAC,MAAM;YACd,CAAC,CAAC,IAAI,CAAC;IACX,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAK,KAA+B,CAAC,IAAI,KAAK,QAAQ;YAAE,OAAO,IAAI,CAAC;QACpE,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC;AACD,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,GAAsB,EACtB,GAAW,EACX,MAAc;IAEd,MAAM,KAAK,CAAC,YAAY,CAAC,GAAG,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;IACjE,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,EAC3B,IAAI,GAAG,MAAM,GAAG,GAAG,GAAG,UAAU,EAAE,CAAC;IACrC,MAAM,SAAS,CAAC,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC,GAAG,IAAI,EAAE;QACvD,IAAI,EAAE,KAAK;QACX,IAAI,EAAE,IAAI;KACX,CAAC,CAAC;IACH,MAAM,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;AAC7B,CAAC"}
|
package/dist/workspaces.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/** Keep in step with infra/publish/src/managed-workspaces/contracts.ts. */
|
|
2
2
|
export declare function secretFileName(value: string): boolean;
|
|
3
|
-
export declare const WORKSPACE_HELP = "Foleo workspace (explicit workspace grant required):\n foleo workspace list [--json]\n foleo workspace items <workspaceId> [--parent <id>] [--state live|trashed] [--cursor <cursor>] [--limit <1-100>] [--json]\n foleo workspace get <workspaceId> <itemId> [--json]\n foleo workspace read <workspaceId> <itemId> --output <path> [--revision <id>] [--json]\n foleo workspace history <workspaceId> <itemId> [--cursor <cursor>] [--limit <1-100>] [--json]\n foleo workspace search <workspaceId> <query> [--limit <1-50>] [--state live|trashed] [--json]\n foleo workspace status <workspaceId> [--json]\n foleo workspace watch <workspaceId> [--timeout <seconds>] [--json]\n foleo workspace capabilities [--json]\n foleo capabilities [--json]\n foleo workspace create <name> [--mutation-id <id>] [--json]\n foleo workspace put <workspaceId> <path> (--parent <id> [--name <name>] | --item <id> --expected-revision <revisionId>) [--mutation-id <id>] [--json]\n --expected-revision is the revisionId you read (from get/read); a newer save is refused, never overwritten.\n foleo workspace mkdir <workspaceId> --parent <id> --name <name> [--mutation-id <id>] [--json]\n foleo workspace move <workspaceId> <itemId> --parent <id> --name <name> [--mutation-id <id>] [--acknowledge-access-widening] [--json]\n foleo workspace trash <workspaceId> <itemId> [--mutation-id <id>] [--json]\n foleo workspace restore <workspaceId> <itemId> --parent <id> --name <name> [--mutation-id <id>] [--acknowledge-access-widening] [--json]\n foleo workspace commit <workspaceId> --input <json-file> [--json]\n foleo workspace commit-status <workspaceId> <mutationId> [--json]\n foleo workspace upload-status <workspaceId> <uploadId> [--json]\n foleo workspace upload-cancel <workspaceId> <uploadId> [--json]\n foleo workspace share get <workspaceId> <itemId> [--json]\n foleo workspace share set <workspaceId> <itemId> --mode private|link|password|public|inherit [--password-stdin] [--mutation-id <id>] [--acknowledge-access-widening] [--json]\n foleo approval get <approvalId> [--json]\n foleo approval commit <approvalId> --idempotency-key <key> [--json]\nWrites require workspaces:read + workspaces:write. Sharing requires workspaces:read + workspaces:share.\nNew items are Private. Narrowing applies immediately.\nBefore widening who can see a file, ask the human in chat and get a clear yes; then retry with the acknowledgement. Never acknowledge on the human's behalf.\nWith an API key, link and password widenings need --acknowledge-access-widening (otherwise acknowledgement_required); public always needs approval in Foleo, then approval commit.\nUndo a widening with share set <workspaceId> <itemId> --mode private. In commit JSON, the acknowledgement is top-level accessWideningAcknowledged: true.\nHash-first put uploads zero bytes when unchanged (32 MiB/file). Batches accept eight operations.\nOn response loss retry the exact commit payload and mutation ID, or use commit-status. Never mint a new ID just because a response was lost.\nSaves do not publish files or change sharing.\n";
|
|
3
|
+
export declare const WORKSPACE_HELP = "Foleo workspace (explicit workspace grant required):\n foleo workspace list [--json]\n foleo workspace items <workspaceId> [--parent <id>] [--state live|trashed] [--cursor <cursor>] [--limit <1-100>] [--json]\n foleo workspace get <workspaceId> <itemId> [--json]\n foleo workspace read <workspaceId> <itemId> --output <path> [--revision <id>] [--json]\n foleo workspace history <workspaceId> <itemId> [--cursor <cursor>] [--limit <1-100>] [--json]\n foleo workspace revision <workspaceId> <itemId> <revisionId> [--json]\n foleo workspace recent <workspaceId> [--all] [--limit <1-50>] [--json]\n foleo workspace restore-version <workspaceId> <itemId> <revisionId> --expected-revision <id> [--mutation-id <id>] [--json]\n foleo workspace search <workspaceId> <query> [--limit <1-50>] [--state live|trashed] [--json]\n foleo workspace status <workspaceId> [--json]\n foleo workspace watch <workspaceId> [--timeout <seconds>] [--json]\n foleo workspace capabilities [--json]\n foleo capabilities [--json]\n foleo workspace create <name> [--mutation-id <id>] [--json]\n Deprecated legacy tree creation within the bound organization. Use foleo workspaces create for a named workspace/address; MCP create_foleo_workspace creates that organization.\n foleo workspace edit <workspaceId> <itemId> --edits <json-file> --expected-revision <version> [--dry-run] [--mutation-id <id>] [--json]\n foleo workspace put <workspaceId> <path> (--parent <id> [--name <name>] | --item <id> --expected-revision <revisionId>) [--mutation-id <id>] [--json]\n --expected-revision is the revisionId you read (from get/read); a newer save is refused, never overwritten.\n foleo workspace mkdir <workspaceId> --parent <id> --name <name> [--mutation-id <id>] [--json]\n foleo workspace move <workspaceId> <itemId> --parent <id> --name <name> [--mutation-id <id>] [--acknowledge-access-widening] [--json]\n foleo workspace trash <workspaceId> <itemId> [--mutation-id <id>] [--json]\n foleo workspace restore <workspaceId> <itemId> --parent <id> --name <name> [--mutation-id <id>] [--acknowledge-access-widening] [--json]\n foleo workspace commit <workspaceId> --input <json-file> [--json]\n foleo workspace commit-status <workspaceId> <mutationId> [--json]\n foleo workspace upload-status <workspaceId> <uploadId> [--json]\n foleo workspace upload-cancel <workspaceId> <uploadId> [--json]\n foleo workspace share get <workspaceId> <itemId> [--json]\n foleo workspace share set <workspaceId> <itemId> --mode private|link|password|public|inherit [--password-stdin] [--mutation-id <id>] [--acknowledge-access-widening] [--json]\n foleo workspace address get <workspaceId> <itemId> [--json]\n foleo workspace address set <workspaceId> <itemId> --input <json-file> [--json]\n Supply action (check, pin, unpin, or promote), expectedSequence from address get, and clientMutationId.\n Pin needs versionId. Promote needs files (an array of itemId and revisionId pairs for the folder).\n Address get includes the serving version, pin, and hold reason for enrolled items.\n A null address means the item has no safe-address state. Address changes follow the sharing rules.\n foleo approval get <approvalId> [--json]\n foleo approval commit <approvalId> --idempotency-key <key> [--json]\n Approval commands also handle standalone publish candidates.\nWrites require workspaces:read + workspaces:write. Sharing requires workspaces:read + workspaces:share.\nNew items are Private. Narrowing applies immediately.\nBefore widening who can see a file, ask the human in chat and get a clear yes; then retry with the acknowledgement. Never acknowledge on the human's behalf.\nWith an API key, link and password widenings need --acknowledge-access-widening (otherwise acknowledgement_required); public always needs approval in Foleo, then approval commit.\nUndo a widening with share set <workspaceId> <itemId> --mode private. In commit JSON, the acknowledgement is top-level accessWideningAcknowledged: true.\nHash-first put uploads zero bytes when unchanged (32 MiB/file). Batches accept eight operations.\nOn response loss retry the exact commit payload and mutation ID, or use commit-status. Never mint a new ID just because a response was lost.\nSaves do not publish files or change sharing.\n";
|
|
4
4
|
type WorkspaceDeps = {
|
|
5
5
|
request(path: string, init?: RequestInit): Promise<Response>;
|
|
6
6
|
stdout(value: string): void;
|
|
@@ -9,5 +9,12 @@ type WorkspaceDeps = {
|
|
|
9
9
|
};
|
|
10
10
|
/** Read-only adapters; the server owns authorization, pagination and bytes. */
|
|
11
11
|
export declare function workspaceCommand(args: string[], deps: WorkspaceDeps): Promise<number>;
|
|
12
|
+
/** Capture one bounded, stable file before hashing; never reopen it for upload. */
|
|
13
|
+
export declare function captureFile(path: string, maxBytes?: number): Promise<{
|
|
14
|
+
bytes: Buffer<ArrayBuffer>;
|
|
15
|
+
size: number;
|
|
16
|
+
sha256: string;
|
|
17
|
+
}>;
|
|
18
|
+
export declare function readEditsFile(file: string): Promise<unknown[]>;
|
|
12
19
|
export {};
|
|
13
20
|
//# sourceMappingURL=workspaces.d.ts.map
|
package/dist/workspaces.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workspaces.d.ts","sourceRoot":"","sources":["../src/workspaces.ts"],"names":[],"mappings":"AAUA,2EAA2E;AAC3E,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAcrD;AAED,eAAO,MAAM,cAAc,
|
|
1
|
+
{"version":3,"file":"workspaces.d.ts","sourceRoot":"","sources":["../src/workspaces.ts"],"names":[],"mappings":"AAUA,2EAA2E;AAC3E,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAcrD;AAED,eAAO,MAAM,cAAc,4sIA8C1B,CAAC;AAEF,KAAK,aAAa,GAAG;IACnB,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC7D,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,SAAS,CAAC,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IAC9B,UAAU,CAAC,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;CACrC,CAAC;AAEF,+EAA+E;AAC/E,wBAAsB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,aAAa,mBAqQzE;AAWD,mFAAmF;AACnF,wBAAsB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,SAAW;;;;GAqDlE;AA2jBD,wBAAsB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,CAgBpE"}
|
package/dist/workspaces.js
CHANGED
|
@@ -27,12 +27,17 @@ export const WORKSPACE_HELP = `Foleo workspace (explicit workspace grant require
|
|
|
27
27
|
foleo workspace get <workspaceId> <itemId> [--json]
|
|
28
28
|
foleo workspace read <workspaceId> <itemId> --output <path> [--revision <id>] [--json]
|
|
29
29
|
foleo workspace history <workspaceId> <itemId> [--cursor <cursor>] [--limit <1-100>] [--json]
|
|
30
|
+
foleo workspace revision <workspaceId> <itemId> <revisionId> [--json]
|
|
31
|
+
foleo workspace recent <workspaceId> [--all] [--limit <1-50>] [--json]
|
|
32
|
+
foleo workspace restore-version <workspaceId> <itemId> <revisionId> --expected-revision <id> [--mutation-id <id>] [--json]
|
|
30
33
|
foleo workspace search <workspaceId> <query> [--limit <1-50>] [--state live|trashed] [--json]
|
|
31
34
|
foleo workspace status <workspaceId> [--json]
|
|
32
35
|
foleo workspace watch <workspaceId> [--timeout <seconds>] [--json]
|
|
33
36
|
foleo workspace capabilities [--json]
|
|
34
37
|
foleo capabilities [--json]
|
|
35
38
|
foleo workspace create <name> [--mutation-id <id>] [--json]
|
|
39
|
+
Deprecated legacy tree creation within the bound organization. Use foleo workspaces create for a named workspace/address; MCP create_foleo_workspace creates that organization.
|
|
40
|
+
foleo workspace edit <workspaceId> <itemId> --edits <json-file> --expected-revision <version> [--dry-run] [--mutation-id <id>] [--json]
|
|
36
41
|
foleo workspace put <workspaceId> <path> (--parent <id> [--name <name>] | --item <id> --expected-revision <revisionId>) [--mutation-id <id>] [--json]
|
|
37
42
|
--expected-revision is the revisionId you read (from get/read); a newer save is refused, never overwritten.
|
|
38
43
|
foleo workspace mkdir <workspaceId> --parent <id> --name <name> [--mutation-id <id>] [--json]
|
|
@@ -45,8 +50,15 @@ export const WORKSPACE_HELP = `Foleo workspace (explicit workspace grant require
|
|
|
45
50
|
foleo workspace upload-cancel <workspaceId> <uploadId> [--json]
|
|
46
51
|
foleo workspace share get <workspaceId> <itemId> [--json]
|
|
47
52
|
foleo workspace share set <workspaceId> <itemId> --mode private|link|password|public|inherit [--password-stdin] [--mutation-id <id>] [--acknowledge-access-widening] [--json]
|
|
53
|
+
foleo workspace address get <workspaceId> <itemId> [--json]
|
|
54
|
+
foleo workspace address set <workspaceId> <itemId> --input <json-file> [--json]
|
|
55
|
+
Supply action (check, pin, unpin, or promote), expectedSequence from address get, and clientMutationId.
|
|
56
|
+
Pin needs versionId. Promote needs files (an array of itemId and revisionId pairs for the folder).
|
|
57
|
+
Address get includes the serving version, pin, and hold reason for enrolled items.
|
|
58
|
+
A null address means the item has no safe-address state. Address changes follow the sharing rules.
|
|
48
59
|
foleo approval get <approvalId> [--json]
|
|
49
60
|
foleo approval commit <approvalId> --idempotency-key <key> [--json]
|
|
61
|
+
Approval commands also handle standalone publish candidates.
|
|
50
62
|
Writes require workspaces:read + workspaces:write. Sharing requires workspaces:read + workspaces:share.
|
|
51
63
|
New items are Private. Narrowing applies immediately.
|
|
52
64
|
Before widening who can see a file, ask the human in chat and get a clear yes; then retry with the acknowledgement. Never acknowledge on the human's behalf.
|
|
@@ -59,7 +71,9 @@ Saves do not publish files or change sharing.
|
|
|
59
71
|
/** Read-only adapters; the server owns authorization, pagination and bytes. */
|
|
60
72
|
export async function workspaceCommand(args, deps) {
|
|
61
73
|
const [command, ...rest] = args;
|
|
62
|
-
if (command === "
|
|
74
|
+
if (command === "edit")
|
|
75
|
+
return workspaceEdit(rest, deps);
|
|
76
|
+
if (command === "share" || command === "approval" || command === "address")
|
|
63
77
|
return workspaceSharing(command, rest, deps);
|
|
64
78
|
if (!command || command === "--help" || command === "help") {
|
|
65
79
|
deps.stdout(WORKSPACE_HELP);
|
|
@@ -82,10 +96,15 @@ export async function workspaceCommand(args, deps) {
|
|
|
82
96
|
"--mutation-id",
|
|
83
97
|
]);
|
|
84
98
|
let acknowledgeWidening = false;
|
|
99
|
+
let recentAll = false;
|
|
85
100
|
for (let i = 0; i < rest.length; i++) {
|
|
86
101
|
const value = rest[i];
|
|
87
102
|
if (value === "--json")
|
|
88
103
|
continue;
|
|
104
|
+
if (value === "--all" && command === "recent") {
|
|
105
|
+
recentAll = true;
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
89
108
|
if (value === "--acknowledge-access-widening") {
|
|
90
109
|
if (acknowledgeWidening || !["move", "restore"].includes(command))
|
|
91
110
|
throw new UsageError(WORKSPACE_HELP);
|
|
@@ -187,6 +206,7 @@ export async function workspaceCommand(args, deps) {
|
|
|
187
206
|
"move",
|
|
188
207
|
"trash",
|
|
189
208
|
"restore",
|
|
209
|
+
"restore-version",
|
|
190
210
|
"commit",
|
|
191
211
|
"commit-status",
|
|
192
212
|
"upload-status",
|
|
@@ -195,24 +215,30 @@ export async function workspaceCommand(args, deps) {
|
|
|
195
215
|
return workspaceMutation(command, positionals, flags, deps, acknowledgeWidening);
|
|
196
216
|
const count = command === "list" || command === "capabilities"
|
|
197
217
|
? 0
|
|
198
|
-
: command === "
|
|
199
|
-
?
|
|
200
|
-
:
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
218
|
+
: command === "revision"
|
|
219
|
+
? 3
|
|
220
|
+
: command === "items" || command === "status" || command === "recent"
|
|
221
|
+
? 1
|
|
222
|
+
: 2;
|
|
223
|
+
const validFlags = command === "recent"
|
|
224
|
+
? ["--limit"]
|
|
225
|
+
: command === "search"
|
|
226
|
+
? ["--limit", "--state"]
|
|
227
|
+
: command === "items"
|
|
228
|
+
? ["--parent", "--state", "--cursor", "--limit"]
|
|
229
|
+
: command === "history"
|
|
230
|
+
? ["--cursor", "--limit"]
|
|
231
|
+
: command === "read"
|
|
232
|
+
? ["--output", "--revision"]
|
|
233
|
+
: [];
|
|
210
234
|
if (![
|
|
211
235
|
"list",
|
|
212
236
|
"items",
|
|
213
237
|
"get",
|
|
214
238
|
"read",
|
|
215
239
|
"history",
|
|
240
|
+
"revision",
|
|
241
|
+
"recent",
|
|
216
242
|
"capabilities",
|
|
217
243
|
"search",
|
|
218
244
|
"status",
|
|
@@ -224,24 +250,28 @@ export async function workspaceCommand(args, deps) {
|
|
|
224
250
|
if (limit &&
|
|
225
251
|
(!/^\d+$/u.test(limit) ||
|
|
226
252
|
Number(limit) < 1 ||
|
|
227
|
-
Number(limit) > (
|
|
228
|
-
throw new UsageError(`--limit must be between 1 and ${
|
|
253
|
+
Number(limit) > (["search", "recent"].includes(command) ? 50 : 100)))
|
|
254
|
+
throw new UsageError(`--limit must be between 1 and ${["search", "recent"].includes(command) ? 50 : 100}.`);
|
|
229
255
|
if (command === "read" && !flags.has("--output"))
|
|
230
256
|
throw new UsageError("workspace read requires --output <path>.");
|
|
231
|
-
const [wid, iid] = positionals.map(encodeURIComponent);
|
|
257
|
+
const [wid, iid, rid] = positionals.map(encodeURIComponent);
|
|
232
258
|
const base = `/workspaces/${wid}/items`;
|
|
233
|
-
const path = command === "
|
|
234
|
-
?
|
|
235
|
-
: command === "
|
|
236
|
-
?
|
|
237
|
-
: command === "
|
|
238
|
-
? "/
|
|
239
|
-
: command === "
|
|
240
|
-
?
|
|
241
|
-
:
|
|
259
|
+
const path = command === "revision"
|
|
260
|
+
? `${base}/${iid}/revisions/${rid}`
|
|
261
|
+
: command === "search" || command === "status" || command === "recent"
|
|
262
|
+
? `/workspaces/${wid}/${command}`
|
|
263
|
+
: command === "capabilities"
|
|
264
|
+
? "/capabilities"
|
|
265
|
+
: command === "list"
|
|
266
|
+
? "/workspaces"
|
|
267
|
+
: command === "items"
|
|
268
|
+
? base
|
|
269
|
+
: `${base}/${iid}${command === "read" ? "/content" : command === "history" ? "/revisions" : ""}`;
|
|
242
270
|
const query = new URLSearchParams();
|
|
243
271
|
if (command === "search")
|
|
244
272
|
query.set("q", positionals[1]);
|
|
273
|
+
if (recentAll)
|
|
274
|
+
query.set("scope", "all");
|
|
245
275
|
for (const [flag, key] of [
|
|
246
276
|
["--parent", "parentId"],
|
|
247
277
|
["--state", "state"],
|
|
@@ -267,23 +297,28 @@ export async function workspaceCommand(args, deps) {
|
|
|
267
297
|
return 0;
|
|
268
298
|
}
|
|
269
299
|
/** Capture one bounded, stable file before hashing; never reopen it for upload. */
|
|
270
|
-
async function captureFile(path) {
|
|
300
|
+
export async function captureFile(path, maxBytes = 33554432) {
|
|
301
|
+
const invalidFile = () => maxBytes === 65536
|
|
302
|
+
? new UsageError("Use foleo workspace put for large/binary files.", "transport_requires_advanced")
|
|
303
|
+
: new UsageError(maxBytes === 33554432
|
|
304
|
+
? "workspace put requires a regular file of at most 32 MiB."
|
|
305
|
+
: `Use a regular input file of at most ${maxBytes} bytes.`);
|
|
271
306
|
for (let attempt = 0; attempt < 2; attempt++) {
|
|
272
307
|
const handle = await open(path, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
|
|
273
308
|
try {
|
|
274
309
|
const before = await handle.stat({ bigint: true });
|
|
275
|
-
if (!before.isFile() || before.size >
|
|
276
|
-
throw
|
|
310
|
+
if (!before.isFile() || before.size > BigInt(maxBytes))
|
|
311
|
+
throw invalidFile();
|
|
277
312
|
const chunks = [];
|
|
278
313
|
let size = 0;
|
|
279
314
|
for (;;) {
|
|
280
|
-
const buffer = Buffer.alloc(65536);
|
|
315
|
+
const buffer = Buffer.alloc(Math.min(65536, maxBytes + 1 - size));
|
|
281
316
|
const { bytesRead } = await handle.read(buffer, 0, buffer.length, null);
|
|
282
317
|
if (!bytesRead)
|
|
283
318
|
break;
|
|
284
319
|
size += bytesRead;
|
|
285
|
-
if (size >
|
|
286
|
-
throw
|
|
320
|
+
if (size > maxBytes)
|
|
321
|
+
throw invalidFile();
|
|
287
322
|
chunks.push(buffer.subarray(0, bytesRead));
|
|
288
323
|
}
|
|
289
324
|
const after = await handle.stat({ bigint: true });
|
|
@@ -306,22 +341,35 @@ async function captureFile(path) {
|
|
|
306
341
|
throw new LocalError("file_changed_during_capture", "File changed during capture; retry after it stops changing.");
|
|
307
342
|
}
|
|
308
343
|
async function workspaceMutation(command, positionals, flags, deps, acknowledgeWidening = false) {
|
|
309
|
-
const count =
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
344
|
+
const count = command === "restore-version"
|
|
345
|
+
? 3
|
|
346
|
+
: ["create", "mkdir", "commit"].includes(command)
|
|
347
|
+
? 1
|
|
348
|
+
: 2;
|
|
349
|
+
const allowed = command === "restore-version"
|
|
350
|
+
? ["--expected-revision", "--mutation-id"]
|
|
351
|
+
: command === "put"
|
|
352
|
+
? [
|
|
353
|
+
"--parent",
|
|
354
|
+
"--name",
|
|
355
|
+
"--item",
|
|
356
|
+
"--expected-revision",
|
|
357
|
+
"--mutation-id",
|
|
358
|
+
]
|
|
359
|
+
: command === "mkdir" || command === "move" || command === "restore"
|
|
360
|
+
? ["--parent", "--name", "--mutation-id"]
|
|
361
|
+
: command === "create" || command === "trash"
|
|
362
|
+
? ["--mutation-id"]
|
|
363
|
+
: command === "commit"
|
|
364
|
+
? ["--input"]
|
|
365
|
+
: [];
|
|
319
366
|
if (positionals.length !== count ||
|
|
320
367
|
[...flags.keys()].some((flag) => !allowed.includes(flag)))
|
|
321
368
|
throw new UsageError(WORKSPACE_HELP);
|
|
322
369
|
if ((["mkdir", "move", "restore"].includes(command) &&
|
|
323
370
|
(!flags.has("--parent") || !flags.has("--name"))) ||
|
|
324
371
|
(command === "commit" && !flags.has("--input")) ||
|
|
372
|
+
(command === "restore-version" && !flags.has("--expected-revision")) ||
|
|
325
373
|
(command === "put" &&
|
|
326
374
|
(flags.has("--item") === flags.has("--parent") ||
|
|
327
375
|
(flags.has("--item") && flags.has("--name")) ||
|
|
@@ -415,7 +463,15 @@ async function workspaceMutation(command, positionals, flags, deps, acknowledgeW
|
|
|
415
463
|
process.once("SIGINT", interrupt);
|
|
416
464
|
process.once("SIGTERM", interrupt);
|
|
417
465
|
try {
|
|
418
|
-
if (command === "
|
|
466
|
+
if (command === "restore-version") {
|
|
467
|
+
operations.push({
|
|
468
|
+
type: "restoreRevision",
|
|
469
|
+
itemId: positionals[1],
|
|
470
|
+
revisionId: positionals[2],
|
|
471
|
+
expectedRevisionId: flags.get("--expected-revision"),
|
|
472
|
+
});
|
|
473
|
+
}
|
|
474
|
+
else if (command === "put") {
|
|
419
475
|
const captured = await captureFile(positionals[1]);
|
|
420
476
|
const fetched = flags.has("--item")
|
|
421
477
|
? await metadata(flags.get("--item"))
|
|
@@ -608,7 +664,7 @@ async function workspaceSharing(family, args, deps) {
|
|
|
608
664
|
continue;
|
|
609
665
|
}
|
|
610
666
|
if (value.startsWith("--")) {
|
|
611
|
-
if (!["--mode", "--mutation-id", "--idempotency-key"].includes(value) ||
|
|
667
|
+
if (!["--mode", "--mutation-id", "--idempotency-key", "--input"].includes(value) ||
|
|
612
668
|
flags.has(value) ||
|
|
613
669
|
!rest[i + 1] ||
|
|
614
670
|
rest[i + 1].startsWith("--"))
|
|
@@ -626,7 +682,9 @@ async function workspaceSharing(family, args, deps) {
|
|
|
626
682
|
? []
|
|
627
683
|
: approval
|
|
628
684
|
? ["--idempotency-key"]
|
|
629
|
-
:
|
|
685
|
+
: family === "address"
|
|
686
|
+
? ["--input"]
|
|
687
|
+
: ["--mode", "--mutation-id"];
|
|
630
688
|
if ([...flags.keys()].some((flag) => !allowed.includes(flag)) ||
|
|
631
689
|
(passwordStdin &&
|
|
632
690
|
(approval || action !== "set" || flags.get("--mode") !== "password")))
|
|
@@ -642,6 +700,29 @@ async function workspaceSharing(family, args, deps) {
|
|
|
642
700
|
path += "/commit";
|
|
643
701
|
init = { method: "POST", headers: { "idempotency-key": key } };
|
|
644
702
|
}
|
|
703
|
+
else if (action === "set" && family === "address") {
|
|
704
|
+
const file = flags.get("--input");
|
|
705
|
+
if (!file)
|
|
706
|
+
throw new UsageError(WORKSPACE_HELP);
|
|
707
|
+
if (file.split(/[\\/]/u).some(secretFileName))
|
|
708
|
+
throw new UsageError("Secret filenames cannot be uploaded.", "secret_file_name");
|
|
709
|
+
const { bytes } = await captureFile(file, 256 * 1024);
|
|
710
|
+
let input;
|
|
711
|
+
try {
|
|
712
|
+
input = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(bytes));
|
|
713
|
+
}
|
|
714
|
+
catch {
|
|
715
|
+
throw new UsageError("--input must contain a JSON address request.");
|
|
716
|
+
}
|
|
717
|
+
if (typeof input !== "object" || input === null || Array.isArray(input))
|
|
718
|
+
throw new UsageError("--input must contain a JSON address request.");
|
|
719
|
+
path = `${base}/address`;
|
|
720
|
+
init = {
|
|
721
|
+
method: "POST",
|
|
722
|
+
headers: { "content-type": "application/json" },
|
|
723
|
+
body: JSON.stringify(input),
|
|
724
|
+
};
|
|
725
|
+
}
|
|
645
726
|
else if (action === "set") {
|
|
646
727
|
const mode = flags.get("--mode");
|
|
647
728
|
if (!mode ||
|
|
@@ -687,19 +768,112 @@ async function workspaceSharing(family, args, deps) {
|
|
|
687
768
|
}),
|
|
688
769
|
};
|
|
689
770
|
}
|
|
771
|
+
// A standalone publish commit advances one durable step per HTTP request.
|
|
772
|
+
// The server selects the step. Reuse the exact request after response loss.
|
|
773
|
+
let result;
|
|
774
|
+
for (let step = 0;; step++) {
|
|
775
|
+
let response;
|
|
776
|
+
try {
|
|
777
|
+
response = await deps.request(path, init);
|
|
778
|
+
}
|
|
779
|
+
catch (error) {
|
|
780
|
+
if (!init ||
|
|
781
|
+
(error instanceof FoleoError && (error.httpStatus ?? 0) < 500))
|
|
782
|
+
throw error;
|
|
783
|
+
response = await deps.request(path, init);
|
|
784
|
+
}
|
|
785
|
+
result = await response.json();
|
|
786
|
+
if (!(approval &&
|
|
787
|
+
action === "commit" &&
|
|
788
|
+
response.status === 202 &&
|
|
789
|
+
result &&
|
|
790
|
+
typeof result === "object" &&
|
|
791
|
+
"status" in result &&
|
|
792
|
+
result.status === "committing"))
|
|
793
|
+
break;
|
|
794
|
+
if (step === 11)
|
|
795
|
+
throw new LocalError("publish_in_progress", "The publish commit is still in progress.", {
|
|
796
|
+
next: "Retry foleo approval commit with the same idempotency key.",
|
|
797
|
+
retryable: true,
|
|
798
|
+
});
|
|
799
|
+
}
|
|
800
|
+
if (family === "address" && action === "get") {
|
|
801
|
+
const { sequence, shareItemId, address } = (result ?? {});
|
|
802
|
+
deps.stdout(`${JSON.stringify({ sequence, shareItemId, address: address ?? null }, null, 2)}\n`);
|
|
803
|
+
}
|
|
804
|
+
else {
|
|
805
|
+
deps.stdout(`${JSON.stringify(result, null, 2)}\n`);
|
|
806
|
+
}
|
|
807
|
+
return 0;
|
|
808
|
+
}
|
|
809
|
+
export async function readEditsFile(file) {
|
|
810
|
+
if (file.split(/[\\/]/u).some(secretFileName))
|
|
811
|
+
throw new UsageError("Secret filenames cannot be uploaded.", "secret_file_name");
|
|
812
|
+
const { bytes } = await captureFile(file, 448 * 1024);
|
|
813
|
+
let edits;
|
|
814
|
+
try {
|
|
815
|
+
edits = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(bytes));
|
|
816
|
+
}
|
|
817
|
+
catch {
|
|
818
|
+
throw new UsageError("--edits must contain a JSON array of edits.");
|
|
819
|
+
}
|
|
820
|
+
if (!Array.isArray(edits))
|
|
821
|
+
throw new UsageError("--edits must contain a JSON array of edits.");
|
|
822
|
+
return edits;
|
|
823
|
+
}
|
|
824
|
+
async function workspaceEdit(args, deps) {
|
|
825
|
+
const positionals = [], flags = new Map();
|
|
826
|
+
let dryRun = false;
|
|
827
|
+
for (let i = 0; i < args.length; i++) {
|
|
828
|
+
const a = args[i];
|
|
829
|
+
if (a === "--json")
|
|
830
|
+
continue;
|
|
831
|
+
if (a === "--dry-run") {
|
|
832
|
+
dryRun = true;
|
|
833
|
+
continue;
|
|
834
|
+
}
|
|
835
|
+
if (a.startsWith("--")) {
|
|
836
|
+
if (!["--edits", "--expected-revision", "--mutation-id"].includes(a) ||
|
|
837
|
+
!args[i + 1] ||
|
|
838
|
+
args[i + 1].startsWith("--") ||
|
|
839
|
+
flags.has(a))
|
|
840
|
+
throw new UsageError(WORKSPACE_HELP);
|
|
841
|
+
flags.set(a, args[++i]);
|
|
842
|
+
}
|
|
843
|
+
else
|
|
844
|
+
positionals.push(a);
|
|
845
|
+
}
|
|
846
|
+
if (positionals.length !== 2 ||
|
|
847
|
+
!flags.has("--edits") ||
|
|
848
|
+
!flags.has("--expected-revision"))
|
|
849
|
+
throw new UsageError(WORKSPACE_HELP);
|
|
850
|
+
const edits = await readEditsFile(flags.get("--edits"));
|
|
851
|
+
const workspaceId = encodeURIComponent(positionals[0]), itemId = positionals[1], expectedRevisionId = flags.get("--expected-revision");
|
|
852
|
+
const payload = dryRun
|
|
853
|
+
? { expectedRevisionId, edits }
|
|
854
|
+
: {
|
|
855
|
+
clientMutationId: flags.get("--mutation-id") ?? randomUUID(),
|
|
856
|
+
operations: [{ type: "edit", itemId, expectedRevisionId, edits }],
|
|
857
|
+
};
|
|
858
|
+
const path = dryRun
|
|
859
|
+
? `/workspaces/${workspaceId}/items/${encodeURIComponent(itemId)}/edits/preview`
|
|
860
|
+
: `/workspaces/${workspaceId}/commits`;
|
|
861
|
+
const init = {
|
|
862
|
+
method: "POST",
|
|
863
|
+
headers: { "content-type": "application/json" },
|
|
864
|
+
body: JSON.stringify(payload),
|
|
865
|
+
};
|
|
690
866
|
let response;
|
|
691
867
|
try {
|
|
692
868
|
response = await deps.request(path, init);
|
|
693
869
|
}
|
|
694
870
|
catch (error) {
|
|
695
|
-
if (
|
|
871
|
+
if (dryRun ||
|
|
872
|
+
(error instanceof FoleoError && (error.httpStatus ?? 0) < 500))
|
|
696
873
|
throw error;
|
|
697
|
-
// Retain the exact in-memory payload/key after response loss, including the
|
|
698
|
-
// stretched password. Never put secret-bearing recovery inputs in output.
|
|
699
874
|
response = await deps.request(path, init);
|
|
700
875
|
}
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
return 0;
|
|
876
|
+
deps.stdout(JSON.stringify(await response.json(), null, 2) + "\n");
|
|
877
|
+
return response.ok ? 0 : 1;
|
|
704
878
|
}
|
|
705
879
|
//# sourceMappingURL=workspaces.js.map
|