The open source coding agent.
TypeScript
sync
Dax Raade97ed735d9b2
diff --git a/.gitignore b/.gitignoreindex 5f0f3842165..7a87ec706da 100644--- a/.gitignore+++ b/.gitignore@@ -2,4 +2,4 @@ node_modules.opencode.sstapp.log-+.envdiff --git a/bun.lock b/bun.lockindex e33d04cc475..7b56e631fb7 100644--- a/bun.lock+++ b/bun.lock@@ -28,6 +28,7 @@"ai": "catalog:","cac": "6.7.14","decimal.js": "10.5.0",+ "diff": "8.0.2","env-paths": "3.0.0","hono": "4.7.10","hono-openapi": "0.4.8",diff --git a/packages/function/sst-env.d.ts b/packages/function/sst-env.d.tsindex a123afeb985..41727ee9ddd 100644--- a/packages/function/sst-env.d.ts+++ b/packages/function/sst-env.d.ts@@ -6,20 +6,20 @@import "sst"declare module "sst" {export interface Resource {- Web: {- type: "sst.cloudflare.StaticSite"- url: string+ "Web": {+ "type": "sst.cloudflare.StaticSite"+ "url": string}}}-// cloudflare-import * as cloudflare from "@cloudflare/workers-types"+// cloudflare+import * as cloudflare from "@cloudflare/workers-types";declare module "sst" {export interface Resource {- Api: cloudflare.Service- Bucket: cloudflare.R2Bucket+ "Api": cloudflare.Service+ "Bucket": cloudflare.R2Bucket}}import "sst"-export {}+export {}\ No newline at end of filediff --git a/packages/opencode/package.json b/packages/opencode/package.jsonindex 61cccb89a79..25ee16a65d6 100644--- a/packages/opencode/package.json+++ b/packages/opencode/package.json@@ -25,6 +25,7 @@"ai": "catalog:","cac": "6.7.14","decimal.js": "10.5.0",+ "diff": "8.0.2","env-paths": "3.0.0","hono": "4.7.10","hono-openapi": "0.4.8",diff --git a/packages/opencode/src/tool/edit.ts b/packages/opencode/src/tool/edit.tsindex c8e31f522fd..7f06df9e3aa 100644--- a/packages/opencode/src/tool/edit.ts+++ b/packages/opencode/src/tool/edit.ts@@ -3,6 +3,7 @@ import * as path from "path"import { Tool } from "./tool"import { FileTimes } from "./util/file-times"import { LSP } from "../lsp"+import { diffLines } from "diff"const DESCRIPTION = `Edits files by replacing text, creating new files, or deleting content. For moving or renaming files, use the Bash tool with the 'mv' command instead. For larger file edits, use the FileWrite tool to overwrite files.@@ -70,8 +71,11 @@ export const EditTool = Tool.define({filePath = path.join(process.cwd(), filePath)}+ let contentOld = ""+ let contentNew = ""await (async () => {if (params.oldString === "") {+ contentNew = params.newStringawait Bun.write(filePath, params.newString)return}@@ -91,26 +95,28 @@ export const EditTool = Tool.define({`File ${filePath} has been modified since it was last read.\nLast modification: ${read.toISOString()}\nLast read: ${stats.mtime.toISOString()}\n\nPlease read the file again before modifying it.`,)- const content = await file.text()- const index = content.indexOf(params.oldString)+ contentOld = await file.text()+ const index = contentOld.indexOf(params.oldString)if (index === -1)throw new Error(`oldString not found in file. Make sure it matches exactly, including whitespace and line breaks`,)- const lastIndex = content.lastIndexOf(params.oldString)+ const lastIndex = contentOld.lastIndexOf(params.oldString)if (index !== lastIndex)throw new Error(`oldString appears multiple times in the file. Please provide more context to ensure a unique match`,)- const newContent =- content.substring(0, index) ++ contentNew =+ contentOld.substring(0, index) +params.newString +- content.substring(index + params.oldString.length)+ contentOld.substring(index + params.oldString.length)- await file.write(newContent)+ await file.write(contentNew)})()+ const changes = diffLines(contentOld, contentNew)+FileTimes.write(filePath)FileTimes.read(filePath)@@ -129,6 +135,7 @@ export const EditTool = Tool.define({return {metadata: {diagnostics,+ changes,},output,}diff --git a/packages/opencode/src/util/event.ts b/packages/opencode/src/util/event.tsdeleted file mode 100644index e69de29bb2d..00000000000diff --git a/packages/opencode/src/util/log.ts b/packages/opencode/src/util/log.tsindex bf0a7258c52..003ebb77acd 100644--- a/packages/opencode/src/util/log.ts+++ b/packages/opencode/src/util/log.ts@@ -53,6 +53,9 @@ export namespace Log {error(message?: any, extra?: Record<string, any>) {write.err(build(message, extra))},+ warn(message?: any, extra?: Record<string, any>) {+ write.err(build(message, extra))+ },tag(key: string, value: string) {if (tags) tags[key] = valuereturn resultdiff --git a/packages/opencode/src/util/scrap.ts b/packages/opencode/src/util/scrap.tsindex 519f8326181..554dba1c54a 100644--- a/packages/opencode/src/util/scrap.ts+++ b/packages/opencode/src/util/scrap.ts@@ -1,5 +1,10 @@export const foo: string = "42"+export const bar: number = 123export function dummyFunction(): void {console.log("This is a dummy function")}++export function randomHelper(): boolean {+ return Math.random() > 0.5+}diff --git a/packages/web/src/components/DiffView.tsx b/packages/web/src/components/DiffView.tsxindex 4e864e06b57..6f89d6a977b 100644--- a/packages/web/src/components/DiffView.tsx+++ b/packages/web/src/components/DiffView.tsx@@ -1,5 +1,5 @@-import { type Component, createSignal, onMount } from "solid-js"-import { diffLines } from "diff"+import { type Component, createMemo, createSignal, onMount } from "solid-js"+import { diffLines, type ChangeObject } from "diff"import CodeBlock from "./CodeBlock"import styles from "./diffview.module.css"@@ -10,33 +10,29 @@ type DiffRow = {}interface DiffViewProps {- oldCode: string- newCode: string+ changes: ChangeObject<string>[]lang?: stringclass?: string}const DiffView: Component<DiffViewProps> = (props) => {- const [rows, setRows] = createSignal<DiffRow[]>([])-- onMount(() => {- const chunks = diffLines(props.oldCode, props.newCode)+ const rows = createMemo(() => {const diffRows: DiffRow[] = []- for (const chunk of chunks) {- const lines = chunk.value.split(/\r?\n/)+ for (const item of props.changes) {+ const lines = item.value.split(/\r?\n/)if (lines.at(-1) === "") lines.pop()for (const line of lines) {diffRows.push({- left: chunk.removed ? line : chunk.added ? "" : line,- right: chunk.added ? line : chunk.removed ? "" : line,- type: chunk.added ? "added" : chunk.removed ? "removed" : "unchanged",+ left: item.removed ? line : item.added ? "" : line,+ right: item.added ? line : item.removed ? "" : line,+ type: item.added ? "added" : item.removed ? "removed" : "unchanged",})}}- setRows(diffRows)+ return diffRows})return (diff --git a/packages/web/src/components/Share.tsx b/packages/web/src/components/Share.tsxindex f4b89e1f536..6d418b82ddf 100644--- a/packages/web/src/components/Share.tsx+++ b/packages/web/src/components/Share.tsx@@ -53,7 +53,7 @@ type SessionMessage = UIMessage<{tool: Record<string,{- properties: Record<string, any>+ [key: string]: anytime: {start: numberend: number@@ -596,11 +596,12 @@ export default function Share(props: { api: string }) {when={msg.role === "assistant" &&part.type === "tool-invocation" &&- part.toolInvocation.toolName === "edit" &&+ part.toolInvocation.toolName === "opencode_edit" &&part}>{(part) => {+ const metadata = createMemo(() => msg.metadata?.tool[part().toolInvocation.toolCallId])const args = part().toolInvocation.argsconst filePath = args.filePathreturn (@@ -622,8 +623,7 @@ export default function Share(props: { api: string }) {<div data-part-tool-edit><DiffViewclass={styles["code-block"]}- oldCode={args.oldString}- newCode={args.newString}+ changes={metadata()?.changes || []}lang={getFileType(filePath)}/></div>@@ -680,7 +680,7 @@ export default function Share(props: { api: string }) {<Matchwhen={part().toolInvocation.state ===- "result" &&+ "result" &&part().toolInvocation.result}>diff --git a/packages/web/sst-env.d.ts b/packages/web/sst-env.d.tsindex 0397645b50f..b6a7e9066ef 100644--- a/packages/web/sst-env.d.ts+++ b/packages/web/sst-env.d.ts@@ -6,4 +6,4 @@/// <reference path="../../sst-env.d.ts" />import "sst"-export {}+export {}\ No newline at end of filediff --git a/sst-env.d.ts b/sst-env.d.tsindex 51e6de573fd..7ca38b723ba 100644--- a/sst-env.d.ts+++ b/sst-env.d.ts@@ -5,20 +5,20 @@declare module "sst" {export interface Resource {- Api: {- type: "sst.cloudflare.Worker"- url: string+ "Api": {+ "type": "sst.cloudflare.Worker"+ "url": string}- Bucket: {- type: "sst.cloudflare.Bucket"+ "Bucket": {+ "type": "sst.cloudflare.Bucket"}- Web: {- type: "sst.cloudflare.StaticSite"- url: string+ "Web": {+ "type": "sst.cloudflare.StaticSite"+ "url": string}}}/// <reference path="sst-env.d.ts" />import "sst"-export {}+export {}\ No newline at end of file