GeezerVison is showing github.com — sync · matleh/opencode@e97ed73
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: .gitignore +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -2,4 +2,4 @@ node_modules | 2 | 2 | .opencode | 3 | 3 | .sst | 4 | 4 | app.log | 5 | | - | | 5 | +.env |
Collapse file Copy file name to clipboardExpand all lines: bun.lock +1Lines changed: 1 addition & 0 deletions Collapse file Copy file name to clipboardExpand all lines: packages/function/sst-env.d.ts +8-8Lines changed: 8 additions & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 6 | 6 | import "sst" | 7 | 7 | declare module "sst" { | 8 | 8 | export interface Resource { | 9 | | - Web: { | 10 | | - type: "sst.cloudflare.StaticSite" | 11 | | - url: string | | 9 | + "Web": { | | 10 | + "type": "sst.cloudflare.StaticSite" | | 11 | + "url": string | 12 | 12 | } | 13 | 13 | } | 14 | 14 | } | 15 | | -// cloudflare | 16 | | -import * as cloudflare from "@cloudflare/workers-types" | | 15 | +// cloudflare | | 16 | +import * as cloudflare from "@cloudflare/workers-types"; | 17 | 17 | declare module "sst" { | 18 | 18 | export interface Resource { | 19 | | - Api: cloudflare.Service | 20 | | - Bucket: cloudflare.R2Bucket | | 19 | + "Api": cloudflare.Service | | 20 | + "Bucket": cloudflare.R2Bucket | 21 | 21 | } | 22 | 22 | } | 23 | 23 |
| 24 | 24 | import "sst" | 25 | | -export {} | | 25 | +export {} |
Collapse file Copy file name to clipboardExpand all lines: packages/opencode/package.json +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 25 | 25 | "ai": "catalog:", | 26 | 26 | "cac": "6.7.14", | 27 | 27 | "decimal.js": "10.5.0", | | 28 | + "diff": "8.0.2", | 28 | 29 | "env-paths": "3.0.0", | 29 | 30 | "hono": "4.7.10", | 30 | 31 | "hono-openapi": "0.4.8", | |
Collapse file Copy file name to clipboardExpand all lines: packages/opencode/src/tool/edit.ts +14-7Lines changed: 14 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -3,6 +3,7 @@ import * as path from "path" | 3 | 3 | import { Tool } from "./tool" | 4 | 4 | import { FileTimes } from "./util/file-times" | 5 | 5 | import { LSP } from "../lsp" | | 6 | +import { diffLines } from "diff" | 6 | 7 |
| 7 | 8 | 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. | 8 | 9 |
| @@ -70,8 +71,11 @@ export const EditTool = Tool.define({ | 70 | 71 | filePath = path.join(process.cwd(), filePath) | 71 | 72 | } | 72 | 73 |
| | 74 | + let contentOld = "" | | 75 | + let contentNew = "" | 73 | 76 | await (async () => { | 74 | 77 | if (params.oldString === "") { | | 78 | + contentNew = params.newString | 75 | 79 | await Bun.write(filePath, params.newString) | 76 | 80 | return | 77 | 81 | } | @@ -91,26 +95,28 @@ export const EditTool = Tool.define({ | 91 | 95 | `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.`, | 92 | 96 | ) | 93 | 97 |
| 94 | | - const content = await file.text() | 95 | | - const index = content.indexOf(params.oldString) | | 98 | + contentOld = await file.text() | | 99 | + const index = contentOld.indexOf(params.oldString) | 96 | 100 | if (index === -1) | 97 | 101 | throw new Error( | 98 | 102 | `oldString not found in file. Make sure it matches exactly, including whitespace and line breaks`, | 99 | 103 | ) | 100 | | - const lastIndex = content.lastIndexOf(params.oldString) | | 104 | + const lastIndex = contentOld.lastIndexOf(params.oldString) | 101 | 105 | if (index !== lastIndex) | 102 | 106 | throw new Error( | 103 | 107 | `oldString appears multiple times in the file. Please provide more context to ensure a unique match`, | 104 | 108 | ) | 105 | 109 |
| 106 | | - const newContent = | 107 | | - content.substring(0, index) + | | 110 | + contentNew = | | 111 | + contentOld.substring(0, index) + | 108 | 112 | params.newString + | 109 | | - content.substring(index + params.oldString.length) | | 113 | + contentOld.substring(index + params.oldString.length) | 110 | 114 |
| 111 | | - await file.write(newContent) | | 115 | + await file.write(contentNew) | 112 | 116 | })() | 113 | 117 |
| | 118 | + const changes = diffLines(contentOld, contentNew) | | 119 | + | 114 | 120 | FileTimes.write(filePath) | 115 | 121 | FileTimes.read(filePath) | 116 | 122 |
| @@ -129,6 +135,7 @@ export const EditTool = Tool.define({ | 129 | 135 | return { | 130 | 136 | metadata: { | 131 | 137 | diagnostics, | | 138 | + changes, | 132 | 139 | }, | 133 | 140 | output, | 134 | 141 | } | |
Collapse file Copy file name to clipboardExpand all lines: packages/opencode/src/util/event.ts Collapse file Copy file name to clipboardExpand all lines: packages/opencode/src/util/log.ts +3Lines changed: 3 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -53,6 +53,9 @@ export namespace Log { | 53 | 53 | error(message?: any, extra?: Record<string, any>) { | 54 | 54 | write.err(build(message, extra)) | 55 | 55 | }, | | 56 | + warn(message?: any, extra?: Record<string, any>) { | | 57 | + write.err(build(message, extra)) | | 58 | + }, | 56 | 59 | tag(key: string, value: string) { | 57 | 60 | if (tags) tags[key] = value | 58 | 61 | return result | |
Collapse file Copy file name to clipboard +5Lines changed: 5 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | export const foo: string = "42" | | 2 | +export const bar: number = 123 | 2 | 3 |
| 3 | 4 | export function dummyFunction(): void { | 4 | 5 | console.log("This is a dummy function") | 5 | 6 | } | | 7 | + | | 8 | +export function randomHelper(): boolean { | | 9 | + return Math.random() > 0.5 | | 10 | +} |
Collapse file Copy file name to clipboardExpand all lines: packages/web/src/components/DiffView.tsx +10-14Lines changed: 10 additions & 14 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | | -import { type Component, createSignal, onMount } from "solid-js" | 2 | | -import { diffLines } from "diff" | | 1 | +import { type Component, createMemo, createSignal, onMount } from "solid-js" | | 2 | +import { diffLines, type ChangeObject } from "diff" | 3 | 3 | import CodeBlock from "./CodeBlock" | 4 | 4 | import styles from "./diffview.module.css" | 5 | 5 |
| @@ -10,33 +10,29 @@ type DiffRow = { | 10 | 10 | } | 11 | 11 |
| 12 | 12 | interface DiffViewProps { | 13 | | - oldCode: string | 14 | | - newCode: string | | 13 | + changes: ChangeObject<string>[] | 15 | 14 | lang?: string | 16 | 15 | class?: string | 17 | 16 | } | 18 | 17 |
| 19 | 18 | const DiffView: Component<DiffViewProps> = (props) => { | 20 | | - const [rows, setRows] = createSignal<DiffRow[]>([]) | 21 | | - | 22 | | - onMount(() => { | 23 | | - const chunks = diffLines(props.oldCode, props.newCode) | | 19 | + const rows = createMemo(() => { | 24 | 20 | const diffRows: DiffRow[] = [] | 25 | 21 |
| 26 | | - for (const chunk of chunks) { | 27 | | - const lines = chunk.value.split(/\r?\n/) | | 22 | + for (const item of props.changes) { | | 23 | + const lines = item.value.split(/\r?\n/) | 28 | 24 | if (lines.at(-1) === "") lines.pop() | 29 | 25 |
| 30 | 26 | for (const line of lines) { | 31 | 27 | diffRows.push({ | 32 | | - left: chunk.removed ? line : chunk.added ? "" : line, | 33 | | - right: chunk.added ? line : chunk.removed ? "" : line, | 34 | | - type: chunk.added ? "added" : chunk.removed ? "removed" : "unchanged", | | 28 | + left: item.removed ? line : item.added ? "" : line, | | 29 | + right: item.added ? line : item.removed ? "" : line, | | 30 | + type: item.added ? "added" : item.removed ? "removed" : "unchanged", | 35 | 31 | }) | 36 | 32 | } | 37 | 33 | } | 38 | 34 |
| 39 | | - setRows(diffRows) | | 35 | + return diffRows | 40 | 36 | }) | 41 | 37 |
| 42 | 38 | return ( | |
Collapse file Copy file name to clipboardExpand all lines: packages/web/src/components/Share.tsx +5-5Lines changed: 5 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -53,7 +53,7 @@ type SessionMessage = UIMessage<{ | 53 | 53 | tool: Record< | 54 | 54 | string, | 55 | 55 | { | 56 | | - properties: Record<string, any> | | 56 | + [key: string]: any | 57 | 57 | time: { | 58 | 58 | start: number | 59 | 59 | end: number | @@ -596,11 +596,12 @@ export default function Share(props: { api: string }) { | 596 | 596 | when={ | 597 | 597 | msg.role === "assistant" && | 598 | 598 | part.type === "tool-invocation" && | 599 | | - part.toolInvocation.toolName === "edit" && | | 599 | + part.toolInvocation.toolName === "opencode_edit" && | 600 | 600 | part | 601 | 601 | } | 602 | 602 | > | 603 | 603 | {(part) => { | | 604 | + const metadata = createMemo(() => msg.metadata?.tool[part().toolInvocation.toolCallId]) | 604 | 605 | const args = part().toolInvocation.args | 605 | 606 | const filePath = args.filePath | 606 | 607 | return ( | @@ -622,8 +623,7 @@ export default function Share(props: { api: string }) { | 622 | 623 | <div data-part-tool-edit> | 623 | 624 | <DiffView | 624 | 625 | class={styles["code-block"]} | 625 | | - oldCode={args.oldString} | 626 | | - newCode={args.newString} | | 626 | + changes={metadata()?.changes || []} | 627 | 627 | lang={getFileType(filePath)} | 628 | 628 | /> | 629 | 629 | </div> | @@ -680,7 +680,7 @@ export default function Share(props: { api: string }) { | 680 | 680 | <Match | 681 | 681 | when={ | 682 | 682 | part().toolInvocation.state === | 683 | | - "result" && | | 683 | + "result" && | 684 | 684 | part().toolInvocation.result | 685 | 685 | } | 686 | 686 | > | |
|