Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/computer-workspace-file-tools.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@cloudflare/computer": minor
---

Add bounded `find` and `grep` tools, a read-only-aware `delete` tool, and shared locking for file mutations.
12 changes: 12 additions & 0 deletions packages/computer/src/stub.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,18 @@ describe("WorkspaceStub", () => {
});
});

it("fs.find forwards bounded search options", async () => {
await withStub(async (ws) => {
const stub = ws.stub();
await ws.fs.writeFile("/a.ts", "");
await ws.fs.writeFile("/b.ts", "");
await ws.fs.writeFile("/c.ts", "");
expect(await stub.fs.find("/", "*.ts", { limit: 1, offset: 1 })).toEqual([
{ path: "/b.ts", type: "file" },
]);
});
});

it("fs.stat propagates ENOENT for missing paths", async () => {
await withStub(async (ws) => {
const stub = ws.stub();
Expand Down
9 changes: 7 additions & 2 deletions packages/computer/src/stub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@

import { trackStub, untrackStub } from "@cloudflare/computer-rpc/debug";
import type {
FindOptions,
GrepOptions,
MkdirOptions,
ReaddirOptions,
Expand Down Expand Up @@ -190,12 +191,16 @@ export class WorkspaceFilesystemStub extends RpcTarget {
);
}

find(directory: string, pattern?: string): Promise<WorkspaceFoundEntry[]> {
find(
directory: string,
pattern?: string,
options: FindOptions = {},
): Promise<WorkspaceFoundEntry[]> {
return withSpan(
this.#ws.observer,
"workspace.fs.find",
{ "workspace.fs.path": directory, "workspace.fs.pattern": pattern },
() => this.#ws.fs.find(directory, pattern),
() => this.#ws.fs.find(directory, pattern, options),
(span, outcome) => {
if (outcome.ok) span.setAttribute("workspace.fs.matches", outcome.value.length);
},
Expand Down
Loading
Loading