GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — sync · matleh/opencode@e97ed73

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • .gitignore
  • bun.lock
  • packages
    • function
      • sst-env.d.ts
    • opencode
      • package.json
      • src
        • tool
          • edit.ts
        • util
          • event.ts
          • log.ts
          • scrap.ts
    • web
      • src/components
        • DiffView.tsx
        • Share.tsx
      • sst-env.d.ts
  • sst-env.d.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎.gitignore‎

Copy file name to clipboardExpand all lines: .gitignore
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ node_modules
22
.opencode
33
.sst
44
app.log
5-
5+
.env
Collapse file

‎bun.lock‎

Copy file name to clipboardExpand all lines: bun.lock
+1Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Collapse file

‎packages/function/sst-env.d.ts‎

Copy file name to clipboardExpand all lines: packages/function/sst-env.d.ts
+8-8Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,20 @@
66
import "sst"
77
declare module "sst" {
88
export interface Resource {
9-
Web: {
10-
type: "sst.cloudflare.StaticSite"
11-
url: string
9+
"Web": {
10+
"type": "sst.cloudflare.StaticSite"
11+
"url": string
1212
}
1313
}
1414
}
15-
// cloudflare
16-
import * as cloudflare from "@cloudflare/workers-types"
15+
// cloudflare
16+
import * as cloudflare from "@cloudflare/workers-types";
1717
declare module "sst" {
1818
export interface Resource {
19-
Api: cloudflare.Service
20-
Bucket: cloudflare.R2Bucket
19+
"Api": cloudflare.Service
20+
"Bucket": cloudflare.R2Bucket
2121
}
2222
}
2323

2424
import "sst"
25-
export {}
25+
export {}
Collapse file

‎packages/opencode/package.json‎

Copy file name to clipboardExpand all lines: packages/opencode/package.json
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"ai": "catalog:",
2626
"cac": "6.7.14",
2727
"decimal.js": "10.5.0",
28+
"diff": "8.0.2",
2829
"env-paths": "3.0.0",
2930
"hono": "4.7.10",
3031
"hono-openapi": "0.4.8",
Collapse file

‎packages/opencode/src/tool/edit.ts‎

Copy file name to clipboardExpand all lines: packages/opencode/src/tool/edit.ts
+14-7Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as path from "path"
33
import { Tool } from "./tool"
44
import { FileTimes } from "./util/file-times"
55
import { LSP } from "../lsp"
6+
import { diffLines } from "diff"
67

78
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.
89
@@ -70,8 +71,11 @@ export const EditTool = Tool.define({
7071
filePath = path.join(process.cwd(), filePath)
7172
}
7273

74+
let contentOld = ""
75+
let contentNew = ""
7376
await (async () => {
7477
if (params.oldString === "") {
78+
contentNew = params.newString
7579
await Bun.write(filePath, params.newString)
7680
return
7781
}
@@ -91,26 +95,28 @@ export const EditTool = Tool.define({
9195
`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.`,
9296
)
9397

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)
96100
if (index === -1)
97101
throw new Error(
98102
`oldString not found in file. Make sure it matches exactly, including whitespace and line breaks`,
99103
)
100-
const lastIndex = content.lastIndexOf(params.oldString)
104+
const lastIndex = contentOld.lastIndexOf(params.oldString)
101105
if (index !== lastIndex)
102106
throw new Error(
103107
`oldString appears multiple times in the file. Please provide more context to ensure a unique match`,
104108
)
105109

106-
const newContent =
107-
content.substring(0, index) +
110+
contentNew =
111+
contentOld.substring(0, index) +
108112
params.newString +
109-
content.substring(index + params.oldString.length)
113+
contentOld.substring(index + params.oldString.length)
110114

111-
await file.write(newContent)
115+
await file.write(contentNew)
112116
})()
113117

118+
const changes = diffLines(contentOld, contentNew)
119+
114120
FileTimes.write(filePath)
115121
FileTimes.read(filePath)
116122

@@ -129,6 +135,7 @@ export const EditTool = Tool.define({
129135
return {
130136
metadata: {
131137
diagnostics,
138+
changes,
132139
},
133140
output,
134141
}
Collapse file

‎packages/opencode/src/util/event.ts‎

Copy file name to clipboardExpand all lines: packages/opencode/src/util/event.ts
Whitespace-only changes.
Collapse file

‎packages/opencode/src/util/log.ts‎

Copy file name to clipboardExpand all lines: packages/opencode/src/util/log.ts
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ export namespace Log {
5353
error(message?: any, extra?: Record<string, any>) {
5454
write.err(build(message, extra))
5555
},
56+
warn(message?: any, extra?: Record<string, any>) {
57+
write.err(build(message, extra))
58+
},
5659
tag(key: string, value: string) {
5760
if (tags) tags[key] = value
5861
return result
Collapse file

‎packages/opencode/src/util/scrap.ts‎

Copy file name to clipboard
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
export const foo: string = "42"
2+
export const bar: number = 123
23

34
export function dummyFunction(): void {
45
console.log("This is a dummy function")
56
}
7+
8+
export function randomHelper(): boolean {
9+
return Math.random() > 0.5
10+
}
Collapse file

‎packages/web/src/components/DiffView.tsx‎

Copy file name to clipboardExpand all lines: packages/web/src/components/DiffView.tsx
+10-14Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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"
33
import CodeBlock from "./CodeBlock"
44
import styles from "./diffview.module.css"
55

@@ -10,33 +10,29 @@ type DiffRow = {
1010
}
1111

1212
interface DiffViewProps {
13-
oldCode: string
14-
newCode: string
13+
changes: ChangeObject<string>[]
1514
lang?: string
1615
class?: string
1716
}
1817

1918
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(() => {
2420
const diffRows: DiffRow[] = []
2521

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/)
2824
if (lines.at(-1) === "") lines.pop()
2925

3026
for (const line of lines) {
3127
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",
3531
})
3632
}
3733
}
3834

39-
setRows(diffRows)
35+
return diffRows
4036
})
4137

4238
return (
Collapse file

‎packages/web/src/components/Share.tsx‎

Copy file name to clipboardExpand all lines: packages/web/src/components/Share.tsx
+5-5Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ type SessionMessage = UIMessage<{
5353
tool: Record<
5454
string,
5555
{
56-
properties: Record<string, any>
56+
[key: string]: any
5757
time: {
5858
start: number
5959
end: number
@@ -596,11 +596,12 @@ export default function Share(props: { api: string }) {
596596
when={
597597
msg.role === "assistant" &&
598598
part.type === "tool-invocation" &&
599-
part.toolInvocation.toolName === "edit" &&
599+
part.toolInvocation.toolName === "opencode_edit" &&
600600
part
601601
}
602602
>
603603
{(part) => {
604+
const metadata = createMemo(() => msg.metadata?.tool[part().toolInvocation.toolCallId])
604605
const args = part().toolInvocation.args
605606
const filePath = args.filePath
606607
return (
@@ -622,8 +623,7 @@ export default function Share(props: { api: string }) {
622623
<div data-part-tool-edit>
623624
<DiffView
624625
class={styles["code-block"]}
625-
oldCode={args.oldString}
626-
newCode={args.newString}
626+
changes={metadata()?.changes || []}
627627
lang={getFileType(filePath)}
628628
/>
629629
</div>
@@ -680,7 +680,7 @@ export default function Share(props: { api: string }) {
680680
<Match
681681
when={
682682
part().toolInvocation.state ===
683-
"result" &&
683+
"result" &&
684684
part().toolInvocation.result
685685
}
686686
>

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.