Skip to content

Commit 5526ea9

Browse files
committed
fix: improve debug messages in file writing functions and update workspace options destructuring
1 parent be68fa5 commit 5526ea9

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

packages/core/src/fs.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export async function writeText(fn: string, content: string) {
8585
if (!fn) throw new Error("filename is required");
8686
if (typeof content !== "string") throw new Error("content must be a string");
8787
await ensureDir(dirname(fn));
88-
dbg(`writing text to file ${fn}`);
88+
dbg(`write text ${fn}`);
8989
await writeFile(fn, content, { encoding: "utf8" });
9090
}
9191

@@ -99,7 +99,7 @@ export async function writeText(fn: string, content: string) {
9999
export async function appendText(fn: string, content: string) {
100100
if (!fn) throw new Error("filename is required");
101101
await ensureDir(dirname(fn));
102-
dbg(`append text to file ${fn}`);
102+
dbg(`append text ${fn}`);
103103
await appendFile(fn, content, { encoding: "utf8" });
104104
}
105105

packages/core/src/workspace.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ export function createWorkspaceFileSystem(
122122
root: () => root,
123123
findFiles: async (glob: string, options: FindFilesOptions) => {
124124
dbg(`findFiles: ${JSON.stringify(options)}`);
125-
const { readText, ignore, applyGitIgnore } = options || {};
125+
const { ignore, applyGitIgnore } = options || {};
126126
const runtimeHost = resolveRuntimeHost();
127127
const names = (
128128
await runtimeHost.findFiles(glob, {
@@ -133,7 +133,7 @@ export function createWorkspaceFileSystem(
133133
const files: WorkspaceFile[] = [];
134134
for (const filename of names) {
135135
const file: WorkspaceFile =
136-
readText === false
136+
options?.readText === false
137137
? {
138138
filename,
139139
}
@@ -143,11 +143,13 @@ export function createWorkspaceFileSystem(
143143
return files;
144144
},
145145
writeText: async (filename: string, c: string) => {
146-
checkWrite(filename);
146+
checkWrite(filename);
147+
dbg(`write text %s`, filename);
147148
await writeText(filename, c);
148149
},
149150
appendText: async (filename: string, c: string) => {
150151
checkWrite(filename);
152+
dbg(`append text %s`, filename);
151153
await appendText(filename, c);
152154
},
153155
readText: async (f: string | Awaitable<WorkspaceFile>) => {
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
script({
2+
systemSafety: false,
3+
model:"none"
4+
})
5+
6+
const write = await runPrompt(
7+
(ctx) => {
8+
ctx.$`Use GenAIScript's system.fs_write_file to write the string "foobar" to a file named "output.txt" in the current directory. Return an object with a single property "success" set to true if the operation was successful. If there was an error, return an object with a single property "error" containing the error message.`;
9+
},
10+
{ model: "large", system: ["system.fs_write_file"] });
11+
if (write.error) {
12+
cancel(`Failed to write file: ${write.error?.message ?? "No error message"} (finishReason: ${write.finishReason ?? "unknown"})`);
13+
}

0 commit comments

Comments
 (0)