mirror of
https://github.com/aljazceru/opencode.git
synced 2025-12-21 09:44:21 +01:00
chore: cleanup versioned zod imports (#3460)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com> Co-authored-by: opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com> Co-authored-by: rekram1-node <rekram1-node@users.noreply.github.com>
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/env bun
|
#!/usr/bin/env bun
|
||||||
|
|
||||||
import { z } from "zod/v4"
|
import { z } from "zod"
|
||||||
import { Config } from "../src/config/config"
|
import { Config } from "../src/config/config"
|
||||||
|
|
||||||
const file = process.argv[2]
|
const file = process.argv[2]
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { Config } from "../config/config"
|
import { Config } from "../config/config"
|
||||||
import z from "zod/v4"
|
import z from "zod"
|
||||||
import { Provider } from "../provider/provider"
|
import { Provider } from "../provider/provider"
|
||||||
import { generateObject, type ModelMessage } from "ai"
|
import { generateObject, type ModelMessage } from "ai"
|
||||||
import PROMPT_GENERATE from "./generate.txt"
|
import PROMPT_GENERATE from "./generate.txt"
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import z from "zod/v4"
|
import z from "zod"
|
||||||
import { Auth } from "./index"
|
import { Auth } from "./index"
|
||||||
import { NamedError } from "../util/error"
|
import { NamedError } from "../util/error"
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import path from "path"
|
import path from "path"
|
||||||
import { Global } from "../global"
|
import { Global } from "../global"
|
||||||
import fs from "fs/promises"
|
import fs from "fs/promises"
|
||||||
import z from "zod/v4"
|
import z from "zod"
|
||||||
|
|
||||||
export namespace Auth {
|
export namespace Auth {
|
||||||
export const Oauth = z
|
export const Oauth = z
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import z from "zod/v4"
|
import z from "zod"
|
||||||
import { Global } from "../global"
|
import { Global } from "../global"
|
||||||
import { Log } from "../util/log"
|
import { Log } from "../util/log"
|
||||||
import path from "path"
|
import path from "path"
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import z from "zod/v4"
|
import z from "zod"
|
||||||
import type { ZodType } from "zod/v4"
|
import type { ZodType } from "zod"
|
||||||
import { Log } from "../util/log"
|
import { Log } from "../util/log"
|
||||||
import { Instance } from "../project/instance"
|
import { Instance } from "../project/instance"
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import z from "zod/v4"
|
import z from "zod"
|
||||||
import { EOL } from "os"
|
import { EOL } from "os"
|
||||||
import { NamedError } from "../util/error"
|
import { NamedError } from "../util/error"
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import z from "zod/v4"
|
import z from "zod"
|
||||||
import { Config } from "../config/config"
|
import { Config } from "../config/config"
|
||||||
import { Instance } from "../project/instance"
|
import { Instance } from "../project/instance"
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { Log } from "../util/log"
|
import { Log } from "../util/log"
|
||||||
import path from "path"
|
import path from "path"
|
||||||
import os from "os"
|
import os from "os"
|
||||||
import z from "zod/v4"
|
import z from "zod"
|
||||||
import { Filesystem } from "../util/filesystem"
|
import { Filesystem } from "../util/filesystem"
|
||||||
import { ModelsDev } from "../provider/models"
|
import { ModelsDev } from "../provider/models"
|
||||||
import { mergeDeep, pipe } from "remeda"
|
import { mergeDeep, pipe } from "remeda"
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import path from "path"
|
import path from "path"
|
||||||
import { Global } from "../global"
|
import { Global } from "../global"
|
||||||
import fs from "fs/promises"
|
import fs from "fs/promises"
|
||||||
import z from "zod/v4"
|
import z from "zod"
|
||||||
import { NamedError } from "../util/error"
|
import { NamedError } from "../util/error"
|
||||||
import { lazy } from "../util/lazy"
|
import { lazy } from "../util/lazy"
|
||||||
import { Log } from "../util/log"
|
import { Log } from "../util/log"
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import z from "zod/v4"
|
import z from "zod"
|
||||||
import { Bus } from "../bus"
|
import { Bus } from "../bus"
|
||||||
import { $ } from "bun"
|
import { $ } from "bun"
|
||||||
import type { BunFile } from "bun"
|
import type { BunFile } from "bun"
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
import path from "path"
|
import path from "path"
|
||||||
import { Global } from "../global"
|
import { Global } from "../global"
|
||||||
import fs from "fs/promises"
|
import fs from "fs/promises"
|
||||||
import z from "zod/v4"
|
import z from "zod"
|
||||||
import { NamedError } from "../util/error"
|
import { NamedError } from "../util/error"
|
||||||
import { lazy } from "../util/lazy"
|
import { lazy } from "../util/lazy"
|
||||||
import { $ } from "bun"
|
import { $ } from "bun"
|
||||||
@@ -218,7 +218,7 @@ export namespace Ripgrep {
|
|||||||
code: "ENOENT",
|
code: "ENOENT",
|
||||||
errno: -2,
|
errno: -2,
|
||||||
path: input.cwd,
|
path: input.cwd,
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const proc = Bun.spawn(args, {
|
const proc = Bun.spawn(args, {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import z from "zod/v4"
|
import z from "zod"
|
||||||
import { Bus } from "../bus"
|
import { Bus } from "../bus"
|
||||||
import { Flag } from "../flag/flag"
|
import { Flag } from "../flag/flag"
|
||||||
import { Instance } from "../project/instance"
|
import { Instance } from "../project/instance"
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import z from "zod/v4"
|
import z from "zod"
|
||||||
import { randomBytes } from "crypto"
|
import { randomBytes } from "crypto"
|
||||||
|
|
||||||
export namespace Identifier {
|
export namespace Identifier {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { spawn } from "bun"
|
import { spawn } from "bun"
|
||||||
import z from "zod/v4"
|
import z from "zod"
|
||||||
import { NamedError } from "../util/error"
|
import { NamedError } from "../util/error"
|
||||||
import { Log } from "../util/log"
|
import { Log } from "../util/log"
|
||||||
import { Bus } from "../bus"
|
import { Bus } from "../bus"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import path from "path"
|
import path from "path"
|
||||||
import { $ } from "bun"
|
import { $ } from "bun"
|
||||||
import z from "zod/v4"
|
import z from "zod"
|
||||||
import { NamedError } from "../util/error"
|
import { NamedError } from "../util/error"
|
||||||
import { Bus } from "../bus"
|
import { Bus } from "../bus"
|
||||||
import { Log } from "../util/log"
|
import { Log } from "../util/log"
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import type { Diagnostic as VSCodeDiagnostic } from "vscode-languageserver-types
|
|||||||
import { Log } from "../util/log"
|
import { Log } from "../util/log"
|
||||||
import { LANGUAGE_EXTENSIONS } from "./language"
|
import { LANGUAGE_EXTENSIONS } from "./language"
|
||||||
import { Bus } from "../bus"
|
import { Bus } from "../bus"
|
||||||
import z from "zod/v4"
|
import z from "zod"
|
||||||
import type { LSPServer } from "./server"
|
import type { LSPServer } from "./server"
|
||||||
import { NamedError } from "../util/error"
|
import { NamedError } from "../util/error"
|
||||||
import { withTimeout } from "../util/timeout"
|
import { withTimeout } from "../util/timeout"
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { Log } from "../util/log"
|
|||||||
import { LSPClient } from "./client"
|
import { LSPClient } from "./client"
|
||||||
import path from "path"
|
import path from "path"
|
||||||
import { LSPServer } from "./server"
|
import { LSPServer } from "./server"
|
||||||
import z from "zod/v4"
|
import z from "zod"
|
||||||
import { Config } from "../config/config"
|
import { Config } from "../config/config"
|
||||||
import { spawn } from "child_process"
|
import { spawn } from "child_process"
|
||||||
import { Instance } from "../project/instance"
|
import { Instance } from "../project/instance"
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js"
|
|||||||
import { Config } from "../config/config"
|
import { Config } from "../config/config"
|
||||||
import { Log } from "../util/log"
|
import { Log } from "../util/log"
|
||||||
import { NamedError } from "../util/error"
|
import { NamedError } from "../util/error"
|
||||||
import z from "zod/v4"
|
import z from "zod"
|
||||||
import { Session } from "../session"
|
import { Session } from "../session"
|
||||||
import { Bus } from "../bus"
|
import { Bus } from "../bus"
|
||||||
import { Instance } from "../project/instance"
|
import { Instance } from "../project/instance"
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import z from "zod/v4"
|
import z from "zod"
|
||||||
import { Bus } from "../bus"
|
import { Bus } from "../bus"
|
||||||
import { Log } from "../util/log"
|
import { Log } from "../util/log"
|
||||||
import { Identifier } from "../id/id"
|
import { Identifier } from "../id/id"
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import z from "zod/v4"
|
import z from "zod"
|
||||||
import { Filesystem } from "../util/filesystem"
|
import { Filesystem } from "../util/filesystem"
|
||||||
import path from "path"
|
import path from "path"
|
||||||
import { $ } from "bun"
|
import { $ } from "bun"
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { Global } from "../global"
|
import { Global } from "../global"
|
||||||
import { Log } from "../util/log"
|
import { Log } from "../util/log"
|
||||||
import path from "path"
|
import path from "path"
|
||||||
import z from "zod/v4"
|
import z from "zod"
|
||||||
import { data } from "./models-macro" with { type: "macro" }
|
import { data } from "./models-macro" with { type: "macro" }
|
||||||
import { Installation } from "../installation"
|
import { Installation } from "../installation"
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import z from "zod/v4"
|
import z from "zod"
|
||||||
import path from "path"
|
import path from "path"
|
||||||
import { Config } from "../config/config"
|
import { Config } from "../config/config"
|
||||||
import { mergeDeep, sortBy } from "remeda"
|
import { mergeDeep, sortBy } from "remeda"
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { Hono } from "hono"
|
|||||||
import { cors } from "hono/cors"
|
import { cors } from "hono/cors"
|
||||||
import { stream, streamSSE } from "hono/streaming"
|
import { stream, streamSSE } from "hono/streaming"
|
||||||
import { Session } from "../session"
|
import { Session } from "../session"
|
||||||
import z from "zod/v4"
|
import z from "zod"
|
||||||
import { Provider } from "../provider/provider"
|
import { Provider } from "../provider/provider"
|
||||||
import { mapValues } from "remeda"
|
import { mapValues } from "remeda"
|
||||||
import { NamedError } from "../util/error"
|
import { NamedError } from "../util/error"
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import { defer } from "../util/defer"
|
|||||||
import { MessageV2 } from "./message-v2"
|
import { MessageV2 } from "./message-v2"
|
||||||
import { SystemPrompt } from "./system"
|
import { SystemPrompt } from "./system"
|
||||||
import { Bus } from "../bus"
|
import { Bus } from "../bus"
|
||||||
import z from "zod/v4"
|
import z from "zod"
|
||||||
import type { ModelsDev } from "../provider/models"
|
import type { ModelsDev } from "../provider/models"
|
||||||
import { SessionPrompt } from "./prompt"
|
import { SessionPrompt } from "./prompt"
|
||||||
import { Flag } from "../flag/flag"
|
import { Flag } from "../flag/flag"
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { Decimal } from "decimal.js"
|
import { Decimal } from "decimal.js"
|
||||||
import z from "zod/v4"
|
import z from "zod"
|
||||||
import { type LanguageModelUsage, type ProviderMetadata } from "ai"
|
import { type LanguageModelUsage, type ProviderMetadata } from "ai"
|
||||||
|
|
||||||
import PROMPT_INITIALIZE from "../session/prompt/initialize.txt"
|
import PROMPT_INITIALIZE from "../session/prompt/initialize.txt"
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import z from "zod/v4"
|
import z from "zod"
|
||||||
import { Instance } from "../project/instance"
|
import { Instance } from "../project/instance"
|
||||||
import { Log } from "../util/log"
|
import { Log } from "../util/log"
|
||||||
import { NamedError } from "../util/error"
|
import { NamedError } from "../util/error"
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import z from "zod/v4"
|
import z from "zod"
|
||||||
import { Bus } from "../bus"
|
import { Bus } from "../bus"
|
||||||
import { NamedError } from "../util/error"
|
import { NamedError } from "../util/error"
|
||||||
import { Message } from "./message"
|
import { Message } from "./message"
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import z from "zod/v4"
|
import z from "zod"
|
||||||
import { NamedError } from "../util/error"
|
import { NamedError } from "../util/error"
|
||||||
|
|
||||||
export namespace Message {
|
export namespace Message {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import path from "path"
|
import path from "path"
|
||||||
import os from "os"
|
import os from "os"
|
||||||
import fs from "fs/promises"
|
import fs from "fs/promises"
|
||||||
import z from "zod/v4"
|
import z from "zod"
|
||||||
import { Identifier } from "../id/id"
|
import { Identifier } from "../id/id"
|
||||||
import { MessageV2 } from "./message-v2"
|
import { MessageV2 } from "./message-v2"
|
||||||
import { Log } from "../util/log"
|
import { Log } from "../util/log"
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import z from "zod/v4"
|
import z from "zod"
|
||||||
import { Identifier } from "../id/id"
|
import { Identifier } from "../id/id"
|
||||||
import { Snapshot } from "../snapshot"
|
import { Snapshot } from "../snapshot"
|
||||||
import { MessageV2 } from "./message-v2"
|
import { MessageV2 } from "./message-v2"
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import z from "zod/v4"
|
import z from "zod"
|
||||||
import { Bus } from "../bus"
|
import { Bus } from "../bus"
|
||||||
import { Storage } from "../storage/storage"
|
import { Storage } from "../storage/storage"
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import path from "path"
|
|||||||
import fs from "fs/promises"
|
import fs from "fs/promises"
|
||||||
import { Log } from "../util/log"
|
import { Log } from "../util/log"
|
||||||
import { Global } from "../global"
|
import { Global } from "../global"
|
||||||
import z from "zod/v4"
|
import z from "zod"
|
||||||
import { Config } from "../config/config"
|
import { Config } from "../config/config"
|
||||||
import { Instance } from "../project/instance"
|
import { Instance } from "../project/instance"
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import z from "zod/v4"
|
import z from "zod"
|
||||||
import { spawn } from "child_process"
|
import { spawn } from "child_process"
|
||||||
import { Tool } from "./tool"
|
import { Tool } from "./tool"
|
||||||
import DESCRIPTION from "./bash.txt"
|
import DESCRIPTION from "./bash.txt"
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
// https://github.com/google-gemini/gemini-cli/blob/main/packages/core/src/utils/editCorrector.ts
|
// https://github.com/google-gemini/gemini-cli/blob/main/packages/core/src/utils/editCorrector.ts
|
||||||
// https://github.com/cline/cline/blob/main/evals/diff-edits/diff-apply/diff-06-26-25.ts
|
// https://github.com/cline/cline/blob/main/evals/diff-edits/diff-apply/diff-06-26-25.ts
|
||||||
|
|
||||||
import z from "zod/v4"
|
import z from "zod"
|
||||||
import * as path from "path"
|
import * as path from "path"
|
||||||
import { Tool } from "./tool"
|
import { Tool } from "./tool"
|
||||||
import { LSP } from "../lsp"
|
import { LSP } from "../lsp"
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import z from "zod/v4"
|
import z from "zod"
|
||||||
import path from "path"
|
import path from "path"
|
||||||
import { Tool } from "./tool"
|
import { Tool } from "./tool"
|
||||||
import DESCRIPTION from "./glob.txt"
|
import DESCRIPTION from "./glob.txt"
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import z from "zod/v4"
|
import z from "zod"
|
||||||
import { Tool } from "./tool"
|
import { Tool } from "./tool"
|
||||||
import { Ripgrep } from "../file/ripgrep"
|
import { Ripgrep } from "../file/ripgrep"
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import z from "zod/v4"
|
import z from "zod"
|
||||||
import { Tool } from "./tool"
|
import { Tool } from "./tool"
|
||||||
|
|
||||||
export const InvalidTool = Tool.define("invalid", {
|
export const InvalidTool = Tool.define("invalid", {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import z from "zod/v4"
|
import z from "zod"
|
||||||
import { Tool } from "./tool"
|
import { Tool } from "./tool"
|
||||||
import * as path from "path"
|
import * as path from "path"
|
||||||
import DESCRIPTION from "./ls.txt"
|
import DESCRIPTION from "./ls.txt"
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import z from "zod/v4"
|
import z from "zod"
|
||||||
import { Tool } from "./tool"
|
import { Tool } from "./tool"
|
||||||
import path from "path"
|
import path from "path"
|
||||||
import { LSP } from "../lsp"
|
import { LSP } from "../lsp"
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import z from "zod/v4"
|
import z from "zod"
|
||||||
import { Tool } from "./tool"
|
import { Tool } from "./tool"
|
||||||
import path from "path"
|
import path from "path"
|
||||||
import { LSP } from "../lsp"
|
import { LSP } from "../lsp"
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import z from "zod/v4"
|
import z from "zod"
|
||||||
import { Tool } from "./tool"
|
import { Tool } from "./tool"
|
||||||
import { EditTool } from "./edit"
|
import { EditTool } from "./edit"
|
||||||
import DESCRIPTION from "./multiedit.txt"
|
import DESCRIPTION from "./multiedit.txt"
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import z from "zod/v4"
|
import z from "zod"
|
||||||
import * as path from "path"
|
import * as path from "path"
|
||||||
import * as fs from "fs/promises"
|
import * as fs from "fs/promises"
|
||||||
import { Tool } from "./tool"
|
import { Tool } from "./tool"
|
||||||
@@ -17,7 +17,8 @@ const PatchParams = z.object({
|
|||||||
})
|
})
|
||||||
|
|
||||||
export const PatchTool = Tool.define("patch", {
|
export const PatchTool = Tool.define("patch", {
|
||||||
description: "Apply a patch to modify multiple files. Supports adding, updating, and deleting files with context-aware changes.",
|
description:
|
||||||
|
"Apply a patch to modify multiple files. Supports adding, updating, and deleting files with context-aware changes.",
|
||||||
parameters: PatchParams,
|
parameters: PatchParams,
|
||||||
async execute(params, ctx) {
|
async execute(params, ctx) {
|
||||||
if (!params.patchText) {
|
if (!params.patchText) {
|
||||||
@@ -46,12 +47,12 @@ export const PatchTool = Tool.define("patch", {
|
|||||||
type: "add" | "update" | "delete" | "move"
|
type: "add" | "update" | "delete" | "move"
|
||||||
movePath?: string
|
movePath?: string
|
||||||
}> = []
|
}> = []
|
||||||
|
|
||||||
let totalDiff = ""
|
let totalDiff = ""
|
||||||
|
|
||||||
for (const hunk of hunks) {
|
for (const hunk of hunks) {
|
||||||
const filePath = path.resolve(Instance.directory, hunk.path)
|
const filePath = path.resolve(Instance.directory, hunk.path)
|
||||||
|
|
||||||
if (!Filesystem.contains(Instance.directory, filePath)) {
|
if (!Filesystem.contains(Instance.directory, filePath)) {
|
||||||
throw new Error(`File ${filePath} is not in the current working directory`)
|
throw new Error(`File ${filePath} is not in the current working directory`)
|
||||||
}
|
}
|
||||||
@@ -62,30 +63,30 @@ export const PatchTool = Tool.define("patch", {
|
|||||||
const oldContent = ""
|
const oldContent = ""
|
||||||
const newContent = hunk.contents
|
const newContent = hunk.contents
|
||||||
const diff = createTwoFilesPatch(filePath, filePath, oldContent, newContent)
|
const diff = createTwoFilesPatch(filePath, filePath, oldContent, newContent)
|
||||||
|
|
||||||
fileChanges.push({
|
fileChanges.push({
|
||||||
filePath,
|
filePath,
|
||||||
oldContent,
|
oldContent,
|
||||||
newContent,
|
newContent,
|
||||||
type: "add",
|
type: "add",
|
||||||
})
|
})
|
||||||
|
|
||||||
totalDiff += diff + "\n"
|
totalDiff += diff + "\n"
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
|
|
||||||
case "update":
|
case "update":
|
||||||
// Check if file exists for update
|
// Check if file exists for update
|
||||||
const stats = await fs.stat(filePath).catch(() => null)
|
const stats = await fs.stat(filePath).catch(() => null)
|
||||||
if (!stats || stats.isDirectory()) {
|
if (!stats || stats.isDirectory()) {
|
||||||
throw new Error(`File not found or is directory: ${filePath}`)
|
throw new Error(`File not found or is directory: ${filePath}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read file and update time tracking (like edit tool does)
|
// Read file and update time tracking (like edit tool does)
|
||||||
await FileTime.assert(ctx.sessionID, filePath)
|
await FileTime.assert(ctx.sessionID, filePath)
|
||||||
const oldContent = await fs.readFile(filePath, "utf-8")
|
const oldContent = await fs.readFile(filePath, "utf-8")
|
||||||
let newContent = oldContent
|
let newContent = oldContent
|
||||||
|
|
||||||
// Apply the update chunks to get new content
|
// Apply the update chunks to get new content
|
||||||
try {
|
try {
|
||||||
const fileUpdate = Patch.deriveNewContentsFromChunks(filePath, hunk.chunks)
|
const fileUpdate = Patch.deriveNewContentsFromChunks(filePath, hunk.chunks)
|
||||||
@@ -93,9 +94,9 @@ export const PatchTool = Tool.define("patch", {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new Error(`Failed to apply update to ${filePath}: ${error}`)
|
throw new Error(`Failed to apply update to ${filePath}: ${error}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
const diff = createTwoFilesPatch(filePath, filePath, oldContent, newContent)
|
const diff = createTwoFilesPatch(filePath, filePath, oldContent, newContent)
|
||||||
|
|
||||||
fileChanges.push({
|
fileChanges.push({
|
||||||
filePath,
|
filePath,
|
||||||
oldContent,
|
oldContent,
|
||||||
@@ -103,23 +104,23 @@ export const PatchTool = Tool.define("patch", {
|
|||||||
type: hunk.move_path ? "move" : "update",
|
type: hunk.move_path ? "move" : "update",
|
||||||
movePath: hunk.move_path ? path.resolve(Instance.directory, hunk.move_path) : undefined,
|
movePath: hunk.move_path ? path.resolve(Instance.directory, hunk.move_path) : undefined,
|
||||||
})
|
})
|
||||||
|
|
||||||
totalDiff += diff + "\n"
|
totalDiff += diff + "\n"
|
||||||
break
|
break
|
||||||
|
|
||||||
case "delete":
|
case "delete":
|
||||||
// Check if file exists for deletion
|
// Check if file exists for deletion
|
||||||
await FileTime.assert(ctx.sessionID, filePath)
|
await FileTime.assert(ctx.sessionID, filePath)
|
||||||
const contentToDelete = await fs.readFile(filePath, "utf-8")
|
const contentToDelete = await fs.readFile(filePath, "utf-8")
|
||||||
const deleteDiff = createTwoFilesPatch(filePath, filePath, contentToDelete, "")
|
const deleteDiff = createTwoFilesPatch(filePath, filePath, contentToDelete, "")
|
||||||
|
|
||||||
fileChanges.push({
|
fileChanges.push({
|
||||||
filePath,
|
filePath,
|
||||||
oldContent: contentToDelete,
|
oldContent: contentToDelete,
|
||||||
newContent: "",
|
newContent: "",
|
||||||
type: "delete",
|
type: "delete",
|
||||||
})
|
})
|
||||||
|
|
||||||
totalDiff += deleteDiff + "\n"
|
totalDiff += deleteDiff + "\n"
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@@ -141,7 +142,7 @@ export const PatchTool = Tool.define("patch", {
|
|||||||
|
|
||||||
// Apply the changes
|
// Apply the changes
|
||||||
const changedFiles: string[] = []
|
const changedFiles: string[] = []
|
||||||
|
|
||||||
for (const change of fileChanges) {
|
for (const change of fileChanges) {
|
||||||
switch (change.type) {
|
switch (change.type) {
|
||||||
case "add":
|
case "add":
|
||||||
@@ -153,12 +154,12 @@ export const PatchTool = Tool.define("patch", {
|
|||||||
await fs.writeFile(change.filePath, change.newContent, "utf-8")
|
await fs.writeFile(change.filePath, change.newContent, "utf-8")
|
||||||
changedFiles.push(change.filePath)
|
changedFiles.push(change.filePath)
|
||||||
break
|
break
|
||||||
|
|
||||||
case "update":
|
case "update":
|
||||||
await fs.writeFile(change.filePath, change.newContent, "utf-8")
|
await fs.writeFile(change.filePath, change.newContent, "utf-8")
|
||||||
changedFiles.push(change.filePath)
|
changedFiles.push(change.filePath)
|
||||||
break
|
break
|
||||||
|
|
||||||
case "move":
|
case "move":
|
||||||
if (change.movePath) {
|
if (change.movePath) {
|
||||||
// Create parent directories for destination
|
// Create parent directories for destination
|
||||||
@@ -173,13 +174,13 @@ export const PatchTool = Tool.define("patch", {
|
|||||||
changedFiles.push(change.movePath)
|
changedFiles.push(change.movePath)
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
|
|
||||||
case "delete":
|
case "delete":
|
||||||
await fs.unlink(change.filePath)
|
await fs.unlink(change.filePath)
|
||||||
changedFiles.push(change.filePath)
|
changedFiles.push(change.filePath)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update file time tracking
|
// Update file time tracking
|
||||||
FileTime.read(ctx.sessionID, change.filePath)
|
FileTime.read(ctx.sessionID, change.filePath)
|
||||||
if (change.movePath) {
|
if (change.movePath) {
|
||||||
@@ -193,7 +194,7 @@ export const PatchTool = Tool.define("patch", {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Generate output summary
|
// Generate output summary
|
||||||
const relativePaths = changedFiles.map(filePath => path.relative(Instance.worktree, filePath))
|
const relativePaths = changedFiles.map((filePath) => path.relative(Instance.worktree, filePath))
|
||||||
const summary = `${fileChanges.length} files changed`
|
const summary = `${fileChanges.length} files changed`
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -201,7 +202,7 @@ export const PatchTool = Tool.define("patch", {
|
|||||||
metadata: {
|
metadata: {
|
||||||
diff: totalDiff,
|
diff: totalDiff,
|
||||||
},
|
},
|
||||||
output: `Patch applied successfully. ${summary}:\n${relativePaths.map(p => ` ${p}`).join("\n")}`,
|
output: `Patch applied successfully. ${summary}:\n${relativePaths.map((p) => ` ${p}`).join("\n")}`,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import z from "zod/v4"
|
import z from "zod"
|
||||||
import * as fs from "fs"
|
import * as fs from "fs"
|
||||||
import * as path from "path"
|
import * as path from "path"
|
||||||
import { Tool } from "./tool"
|
import { Tool } from "./tool"
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ import { Instance } from "../project/instance"
|
|||||||
import { Config } from "../config/config"
|
import { Config } from "../config/config"
|
||||||
import path from "path"
|
import path from "path"
|
||||||
import { type ToolDefinition } from "@opencode-ai/plugin"
|
import { type ToolDefinition } from "@opencode-ai/plugin"
|
||||||
import z from "zod/v4"
|
import z from "zod"
|
||||||
import { Plugin } from "../plugin"
|
import { Plugin } from "../plugin"
|
||||||
|
|
||||||
export namespace ToolRegistry {
|
export namespace ToolRegistry {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { Tool } from "./tool"
|
import { Tool } from "./tool"
|
||||||
import DESCRIPTION from "./task.txt"
|
import DESCRIPTION from "./task.txt"
|
||||||
import z from "zod/v4"
|
import z from "zod"
|
||||||
import { Session } from "../session"
|
import { Session } from "../session"
|
||||||
import { Bus } from "../bus"
|
import { Bus } from "../bus"
|
||||||
import { MessageV2 } from "../session/message-v2"
|
import { MessageV2 } from "../session/message-v2"
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import z from "zod/v4"
|
import z from "zod"
|
||||||
import { Tool } from "./tool"
|
import { Tool } from "./tool"
|
||||||
import DESCRIPTION_WRITE from "./todowrite.txt"
|
import DESCRIPTION_WRITE from "./todowrite.txt"
|
||||||
import { Todo } from "../session/todo"
|
import { Todo } from "../session/todo"
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import z from "zod/v4"
|
import z from "zod"
|
||||||
import type { MessageV2 } from "../session/message-v2"
|
import type { MessageV2 } from "../session/message-v2"
|
||||||
|
|
||||||
export namespace Tool {
|
export namespace Tool {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import z from "zod/v4"
|
import z from "zod"
|
||||||
import { Tool } from "./tool"
|
import { Tool } from "./tool"
|
||||||
import TurndownService from "turndown"
|
import TurndownService from "turndown"
|
||||||
import DESCRIPTION from "./webfetch.txt"
|
import DESCRIPTION from "./webfetch.txt"
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import z from "zod/v4"
|
import z from "zod"
|
||||||
import * as path from "path"
|
import * as path from "path"
|
||||||
import { Tool } from "./tool"
|
import { Tool } from "./tool"
|
||||||
import { LSP } from "../lsp"
|
import { LSP } from "../lsp"
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import z from "zod/v4"
|
import z from "zod"
|
||||||
|
|
||||||
export abstract class NamedError extends Error {
|
export abstract class NamedError extends Error {
|
||||||
abstract schema(): z.core.$ZodType
|
abstract schema(): z.core.$ZodType
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import path from "path"
|
import path from "path"
|
||||||
import fs from "fs/promises"
|
import fs from "fs/promises"
|
||||||
import { Global } from "../global"
|
import { Global } from "../global"
|
||||||
import z from "zod/v4"
|
import z from "zod"
|
||||||
|
|
||||||
export namespace Log {
|
export namespace Log {
|
||||||
export const Level = z.enum(["DEBUG", "INFO", "WARN", "ERROR"]).meta({ ref: "LogLevel", description: "Log level" })
|
export const Level = z.enum(["DEBUG", "INFO", "WARN", "ERROR"]).meta({ ref: "LogLevel", description: "Log level" })
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { z } from "zod/v4"
|
import { z } from "zod"
|
||||||
|
|
||||||
export type ToolContext = {
|
export type ToolContext = {
|
||||||
sessionID: string
|
sessionID: string
|
||||||
|
|||||||
Reference in New Issue
Block a user