summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorDax Raad <[email protected]>2025-06-02 20:24:32 -0400
committerDax Raad <[email protected]>2025-06-02 20:24:32 -0400
commit54b99cd88a56095422c88003c7814ddfef513c87 (patch)
treef64748fc2e3407e77dc287f9e5036aa350cc40ce
parent786db364d26f5fe4b723ad528d90da47ba7c7157 (diff)
downloadopencode-54b99cd88a56095422c88003c7814ddfef513c87.tar.gz
opencode-54b99cd88a56095422c88003c7814ddfef513c87.zip
scope filetimes to session
-rw-r--r--packages/opencode/src/tool/edit.ts5
-rw-r--r--packages/opencode/src/tool/patch.ts10
-rw-r--r--packages/opencode/src/tool/util/file-times.ts28
-rw-r--r--packages/opencode/src/tool/view.ts4
4 files changed, 24 insertions, 23 deletions
diff --git a/packages/opencode/src/tool/edit.ts b/packages/opencode/src/tool/edit.ts
index 3dd332aee..856400a97 100644
--- a/packages/opencode/src/tool/edit.ts
+++ b/packages/opencode/src/tool/edit.ts
@@ -92,7 +92,7 @@ export const EditTool = Tool.define({
return
}
- const read = FileTimes.get(filePath)
+ const read = FileTimes.get(ctx.sessionID, filePath)
if (!read)
throw new Error(
`You must read the file ${filePath} before editing it. Use the View tool first`,
@@ -129,8 +129,7 @@ export const EditTool = Tool.define({
const changes = diffLines(contentOld, contentNew)
- FileTimes.write(filePath)
- FileTimes.read(filePath)
+ FileTimes.read(ctx.sessionID, filePath)
let output = ""
await LSP.file(filePath)
diff --git a/packages/opencode/src/tool/patch.ts b/packages/opencode/src/tool/patch.ts
index 68d2cfeed..aa733ddba 100644
--- a/packages/opencode/src/tool/patch.ts
+++ b/packages/opencode/src/tool/patch.ts
@@ -269,7 +269,7 @@ export const PatchTool = Tool.define({
id: "opencode.patch",
description: DESCRIPTION,
parameters: PatchParams,
- execute: async (params) => {
+ execute: async (params, ctx) => {
if (!params.patchText) {
throw new Error("patchText is required")
}
@@ -282,7 +282,7 @@ export const PatchTool = Tool.define({
absPath = path.resolve(process.cwd(), absPath)
}
- if (!FileTimes.get(absPath)) {
+ if (!FileTimes.get(ctx.sessionID, absPath)) {
throw new Error(
`you must read the file ${filePath} before patching it. Use the FileRead tool first`,
)
@@ -294,7 +294,7 @@ export const PatchTool = Tool.define({
throw new Error(`path is a directory, not a file: ${absPath}`)
}
- const lastRead = FileTimes.get(absPath)
+ const lastRead = FileTimes.get(ctx.sessionID, absPath)
if (lastRead && stats.mtime > lastRead) {
throw new Error(
`file ${absPath} has been modified since it was last read (mod time: ${stats.mtime.toISOString()}, last read: ${lastRead.toISOString()})`,
@@ -400,9 +400,7 @@ export const PatchTool = Tool.define({
totalAdditions += additions
totalRemovals += removals
- // Record file operations
- FileTimes.write(absPath)
- FileTimes.read(absPath)
+ FileTimes.read(ctx.sessionID, absPath)
}
const result = `Patch applied successfully. ${changedFiles.length} files changed, ${totalAdditions} additions, ${totalRemovals} removals`
diff --git a/packages/opencode/src/tool/util/file-times.ts b/packages/opencode/src/tool/util/file-times.ts
index 3eac09aab..19589d549 100644
--- a/packages/opencode/src/tool/util/file-times.ts
+++ b/packages/opencode/src/tool/util/file-times.ts
@@ -1,20 +1,24 @@
import { App } from "../../app/app"
export namespace FileTimes {
- export const state = App.state("tool.filetimes", () => ({
- read: new Map<string, Date>(),
- write: new Map<string, Date>(),
- }))
+ export const state = App.state("tool.filetimes", () => {
+ const read: {
+ [sessionID: string]: {
+ [path: string]: Date | undefined
+ }
+ } = {}
+ return {
+ read,
+ }
+ })
- export function read(filePath: string) {
- state().read.set(filePath, new Date())
+ export function read(sessionID: string, file: string) {
+ const { read } = state()
+ read[sessionID] = read[sessionID] || {}
+ read[sessionID][file] = new Date()
}
- export function write(filePath: string) {
- state().write.set(filePath, new Date())
- }
-
- export function get(filePath: string): Date | null {
- return state().read.get(filePath) || null
+ export function get(sessionID: string, file: string) {
+ return state().read[sessionID]?.[file]
}
}
diff --git a/packages/opencode/src/tool/view.ts b/packages/opencode/src/tool/view.ts
index c17aa1d22..6e29eb450 100644
--- a/packages/opencode/src/tool/view.ts
+++ b/packages/opencode/src/tool/view.ts
@@ -54,7 +54,7 @@ export const ViewTool = Tool.define({
.describe("The number of lines to read (defaults to 2000)")
.optional(),
}),
- async execute(params) {
+ async execute(params, ctx) {
let filePath = params.filePath
if (!path.isAbsolute(filePath)) {
filePath = path.join(process.cwd(), filePath)
@@ -119,7 +119,7 @@ export const ViewTool = Tool.define({
// just warms the lsp client
LSP.file(filePath)
- FileTimes.read(filePath)
+ FileTimes.read(ctx.sessionID, filePath)
return {
output,