forked from anomalyco/opencode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrefresh.ts
More file actions
36 lines (32 loc) · 1.1 KB
/
refresh.ts
File metadata and controls
36 lines (32 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import * as path from "path"
import { z } from "zod"
import { Tool } from "openagent-ai"
export const refresh = (filePath: string) =>
Tool.define({
id: "refresh",
description: `Refreshes and reads the current content of the target file
- Marks the file as read to ensure it's not stale
- Returns the complete file content
Use this tool when you need to refresh a file that may have been modified externally`,
parameters: z.object({}),
async execute(_params, { services }) {
const projectPath = services.appInfo.path.cwd
const filePathAbs = path.isAbsolute(filePath)
? filePath
: path.join(projectPath, filePath)
const file = Bun.file(filePathAbs)
const content = await file.text()
await services.markFileAsRead(filePathAbs)
const lines = content.split("\n")
return {
metadata: {
filePath: filePathAbs,
title: path.relative(projectPath, filePathAbs),
size: content.length,
preview: lines.slice(0, 20).join("\n"),
lines: lines.length,
},
output: content,
}
},
})