@better-fs-tools/cloudflare-shell 0.1.0 → 0.2.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/README.md +6 -6
- package/dist/index.js +1 -1
- package/dist/write.js +0 -4
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -26,15 +26,15 @@ export function workspaceReadTool(workspace: Workspace) {
|
|
|
26
26
|
}
|
|
27
27
|
```
|
|
28
28
|
|
|
29
|
-
With the write tools. `createAiSdkFsTools()` gives the read tool and the write tools one
|
|
29
|
+
With the write tools. `createAiSdkFsTools()` gives the read tool and the write tools one digest and one lock manager, and one read store when you pass `state`. Its default digest, `sha256Digest()` from `@better-fs-tools/read`, is SHA-256 in plain JavaScript, so it runs in a Worker:
|
|
30
30
|
|
|
31
31
|
```ts
|
|
32
32
|
import type { Workspace } from "@cloudflare/shell";
|
|
33
33
|
import { createAiSdkFsTools } from "@better-fs-tools/ai-sdk";
|
|
34
34
|
import { cloudflareShellFileSystem } from "@better-fs-tools/cloudflare-shell";
|
|
35
35
|
|
|
36
|
-
// read, edit,
|
|
37
|
-
//
|
|
36
|
+
// read, edit, and write with one sha256Digest() and one lock manager. Nothing
|
|
37
|
+
// here needs Node, so it runs in a Worker.
|
|
38
38
|
export function workspaceTools(workspace: Workspace) {
|
|
39
39
|
const fs = cloudflareShellFileSystem(workspace, { allowedRoots: ["/workspace"] });
|
|
40
40
|
return createAiSdkFsTools({ fs }).tools;
|
|
@@ -47,16 +47,16 @@ export function workspaceTools(workspace: Workspace) {
|
|
|
47
47
|
- `cwd` must be absolute and defaults to the first allowed root. Relative paths and relative roots resolve against it. Display paths are relative to `cwd`, and absolute outside it. `id` defaults to `"cloudflare-shell"`.
|
|
48
48
|
- `symlinks` can only be `"reject"` and `identity` only `"none"`. It walks each path with `lstat` from `/`, so a symlink above the root, a symlinked root, parent, or file is refused before any byte is read.
|
|
49
49
|
- The filesystem exposes the resolved `cwd`, `allowedRoots`, `denyRoots`, `symlinks`, `identity`, and `maxBufferedBytes`.
|
|
50
|
-
- Reads are buffered: the Workspace returns whole files. `maxBufferedBytes` defaults to 16 MiB, as in every buffering adapter. When you use converters, set it at or above `maxConvertBytes` and `maxMediaBytes`.
|
|
50
|
+
- Reads are buffered: the Workspace returns whole files. `maxBufferedBytes` defaults to 16 MiB, as in every buffering adapter. When you use converters, set it at or above `maxConvertBytes` and `maxMediaBytes`.
|
|
51
51
|
- Because reads are buffered inside `open()`, the whole file has left the Workspace before the read tool's `authorize` runs. The core still passes no byte to a classifier, a converter, or the model until `authorize` allows it. If a denied read must not reach the Workspace, deny it in the adapter with `denyRoots` or `allowedRoots`.
|
|
52
|
-
- `verify()` compares size and modification time. A same-size edit within the same millisecond is not detected.
|
|
52
|
+
- `verify()` compares size and modification time. A same-size edit within the same millisecond is not detected.
|
|
53
53
|
- `list()` lists directories, so suggestions and `directoryListing()` work. Opening a directory gives a `not-a-file` error with `kind: "directory"`.
|
|
54
54
|
|
|
55
55
|
## How it writes
|
|
56
56
|
|
|
57
57
|
- `stat()`, `write()`, and `remove()` use `lstat`, `writeFileBytes`, `mkdir`, and `rm`. They check the roots and refuse every symlink on the path before any Workspace write, as `open()` does. `writeFileBytes` would create missing parents and follow a link by itself, so the adapter checks both first.
|
|
58
58
|
- `writeFileBytes`, `mkdir`, and `rm` are optional in `CloudflareShellWorkspaceLike`. They are checked when a write runs, not when the filesystem is built. A read-only Workspace wrapper backs the read tool, and a write to it gives `unsupported`, which the tools report as `UNSUPPORTED_BACKEND`.
|
|
59
|
-
- `writeCapabilities` is `{
|
|
59
|
+
- `writeCapabilities` is `{ compareAndSwap: false }`. A large file spills to R2 in several steps, so a reader can see a partial file. Shell has no version check, so the adapter checks the precondition with a fresh `lstat` just before the write. Shell has no modes.
|
|
60
60
|
- There is no `stage()`: Shell's `mv` removes the destination first. `apply_patch` writes each file in turn, and undoes them on a failure.
|
|
61
61
|
- The version is the size and `updatedAt`. Shell stores whole seconds, so two same-size writes in one second keep the version. The write tools also compare the content hash of what the model read, so a change after the read is still `STALE`. Between the adapter's last check and the write, it is not seen.
|
|
62
62
|
- A replace passes the file's mime type back, since Shell would reset it. A new file gets Shell's default, `application/octet-stream`.
|
package/dist/index.js
CHANGED
|
@@ -48,7 +48,7 @@ export function cloudflareShellFileSystem(workspace, options) {
|
|
|
48
48
|
};
|
|
49
49
|
return Object.freeze({
|
|
50
50
|
id,
|
|
51
|
-
capabilities: Object.freeze({
|
|
51
|
+
capabilities: Object.freeze({ identity: false }),
|
|
52
52
|
paths: posixPaths,
|
|
53
53
|
cwd,
|
|
54
54
|
allowedRoots: roots.allowedRoots,
|
package/dist/write.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import { containsPosix } from "@better-fs-tools/fs";
|
|
2
2
|
import { AdapterRefusal, authorize, boundedCode, displayPath, inspect, mapBackendError, notAFile, pathsFromSlashToTarget, refuse, toFileSystemError, } from "./policy.js";
|
|
3
3
|
export const SHELL_WRITE_CAPABILITIES = Object.freeze({
|
|
4
|
-
/* Objects above the R2 threshold are written in several steps. */
|
|
5
|
-
atomic: false,
|
|
6
4
|
compareAndSwap: false,
|
|
7
|
-
preserveMode: false,
|
|
8
5
|
});
|
|
9
6
|
export function shellVersion(entry) {
|
|
10
7
|
return `shell:${entry.size}:${entry.updatedAt}`;
|
|
@@ -84,7 +81,6 @@ export function shellWrites(workspace, roots, maxBufferedBytes) {
|
|
|
84
81
|
identity: null,
|
|
85
82
|
size: entry?.size ?? null,
|
|
86
83
|
createdDirectories: created,
|
|
87
|
-
atomic: SHELL_WRITE_CAPABILITIES.atomic,
|
|
88
84
|
});
|
|
89
85
|
return {
|
|
90
86
|
async stat(requested, options = {}) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@better-fs-tools/cloudflare-shell",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "A readable and writable filesystem over a Cloudflare Shell Workspace.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -29,11 +29,11 @@
|
|
|
29
29
|
"access": "public"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@better-fs-tools/fs": "^0.
|
|
32
|
+
"@better-fs-tools/fs": "^0.2.0"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@better-fs-tools/read": "^0.
|
|
36
|
-
"@better-fs-tools/write": "^0.
|
|
35
|
+
"@better-fs-tools/read": "^0.2.0",
|
|
36
|
+
"@better-fs-tools/write": "^0.2.0",
|
|
37
37
|
"@cloudflare/shell": "0.4.3"
|
|
38
38
|
}
|
|
39
39
|
}
|