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 — rename bus · kasbah/opencode@1e3bdcc

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • packages/opencode/src
    • bus
      • bus-event.ts
      • index.ts
    • cli/cmd/tui
      • event.ts
    • command
      • index.ts
    • file
      • index.ts
      • watcher.ts
    • ide
      • index.ts
    • installation
      • index.ts
    • lsp
      • client.ts
      • index.ts
    • permission
      • index.ts
    • project
      • project.ts
      • vcs.ts
    • pty
      • index.ts
    • server
      • server.ts
    • session
      • compaction.ts
      • index.ts
      • message-v2.ts
      • status.ts
      • todo.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎packages/opencode/src/bus/bus-event.ts‎

Copy file name to clipboard
+43Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import z from "zod"
2+
import type { ZodType } from "zod"
3+
import { Log } from "../util/log"
4+
5+
export namespace BusEvent {
6+
const log = Log.create({ service: "event" })
7+
8+
export type Definition = ReturnType<typeof define>
9+
10+
const registry = new Map<string, Definition>()
11+
12+
export function define<Type extends string, Properties extends ZodType>(type: Type, properties: Properties) {
13+
const result = {
14+
type,
15+
properties,
16+
}
17+
registry.set(type, result)
18+
return result
19+
}
20+
21+
export function payloads() {
22+
return z
23+
.discriminatedUnion(
24+
"type",
25+
registry
26+
.entries()
27+
.map(([type, def]) => {
28+
return z
29+
.object({
30+
type: z.literal(type),
31+
properties: def.properties,
32+
})
33+
.meta({
34+
ref: "Event" + "." + def.type,
35+
})
36+
})
37+
.toArray() as any,
38+
)
39+
.meta({
40+
ref: "Event",
41+
})
42+
}
43+
}
Collapse file

‎packages/opencode/src/bus/index.ts‎

Copy file name to clipboardExpand all lines: packages/opencode/src/bus/index.ts
+5-41Lines changed: 5 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
import z from "zod"
2-
import type { ZodType } from "zod"
32
import { Log } from "../util/log"
43
import { Instance } from "../project/instance"
4+
import { BusEvent } from "./bus-event"
55
import { GlobalBus } from "./global"
66

77
export namespace Bus {
88
const log = Log.create({ service: "bus" })
99
type Subscription = (event: any) => void
1010
const disposedEventType = "server.instance.disposed"
1111

12-
export type EventDefinition = ReturnType<typeof event>
13-
14-
const registry = new Map<string, EventDefinition>()
15-
1612
const state = Instance.state(
1713
() => {
1814
const subscriptions = new Map<any, Subscription[]>()
@@ -36,46 +32,14 @@ export namespace Bus {
3632
},
3733
)
3834

39-
export function event<Type extends string, Properties extends ZodType>(type: Type, properties: Properties) {
40-
const result = {
41-
type,
42-
properties,
43-
}
44-
registry.set(type, result)
45-
return result
46-
}
47-
48-
export const InstanceDisposed = event(
35+
export const InstanceDisposed = BusEvent.define(
4936
disposedEventType,
5037
z.object({
5138
directory: z.string(),
5239
}),
5340
)
5441

55-
export function payloads() {
56-
return z
57-
.discriminatedUnion(
58-
"type",
59-
registry
60-
.entries()
61-
.map(([type, def]) => {
62-
return z
63-
.object({
64-
type: z.literal(type),
65-
properties: def.properties,
66-
})
67-
.meta({
68-
ref: "Event" + "." + def.type,
69-
})
70-
})
71-
.toArray() as any,
72-
)
73-
.meta({
74-
ref: "Event",
75-
})
76-
}
77-
78-
export async function publish<Definition extends EventDefinition>(
42+
export async function publish<Definition extends BusEvent.Definition>(
7943
def: Definition,
8044
properties: z.output<Definition["properties"]>,
8145
) {
@@ -100,14 +64,14 @@ export namespace Bus {
10064
return Promise.all(pending)
10165
}
10266

103-
export function subscribe<Definition extends EventDefinition>(
67+
export function subscribe<Definition extends BusEvent.Definition>(
10468
def: Definition,
10569
callback: (event: { type: Definition["type"]; properties: z.infer<Definition["properties"]> }) => void,
10670
) {
10771
return raw(def.type, callback)
10872
}
10973

110-
export function once<Definition extends EventDefinition>(
74+
export function once<Definition extends BusEvent.Definition>(
11175
def: Definition,
11276
callback: (event: {
11377
type: Definition["type"]
Collapse file

‎packages/opencode/src/cli/cmd/tui/event.ts‎

Copy file name to clipboardExpand all lines: packages/opencode/src/cli/cmd/tui/event.ts
+4-3Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
import { BusEvent } from "@/bus/bus-event"
12
import { Bus } from "@/bus"
23
import z from "zod"
34

45
export const TuiEvent = {
5-
PromptAppend: Bus.event("tui.prompt.append", z.object({ text: z.string() })),
6-
CommandExecute: Bus.event(
6+
PromptAppend: BusEvent.define("tui.prompt.append", z.object({ text: z.string() })),
7+
CommandExecute: BusEvent.define(
78
"tui.command.execute",
89
z.object({
910
command: z.union([
@@ -27,7 +28,7 @@ export const TuiEvent = {
2728
]),
2829
}),
2930
),
30-
ToastShow: Bus.event(
31+
ToastShow: BusEvent.define(
3132
"tui.toast.show",
3233
z.object({
3334
title: z.string().optional(),
Collapse file

‎packages/opencode/src/command/index.ts‎

Copy file name to clipboardExpand all lines: packages/opencode/src/command/index.ts
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1+
import { Bus } from "@/bus"
2+
import { BusEvent } from "@/bus/bus-event"
13
import z from "zod"
24
import { Config } from "../config/config"
35
import { Instance } from "../project/instance"
4-
import { Bus } from "../bus"
56
import { Identifier } from "../id/id"
67
import PROMPT_INITIALIZE from "./template/initialize.txt"
78
import PROMPT_REVIEW from "./template/review.txt"
89

910
export namespace Command {
1011
export const Event = {
11-
Executed: Bus.event(
12+
Executed: BusEvent.define(
1213
"command.executed",
1314
z.object({
1415
name: z.string(),
Collapse file

‎packages/opencode/src/file/index.ts‎

Copy file name to clipboardExpand all lines: packages/opencode/src/file/index.ts
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
import { BusEvent } from "@/bus/bus-event"
2+
import { Bus } from "@/bus"
13
import z from "zod"
2-
import { Bus } from "../bus"
34
import { $ } from "bun"
45
import type { BunFile } from "bun"
56
import { formatPatch, structuredPatch } from "diff"
@@ -111,7 +112,7 @@ export namespace File {
111112
}
112113

113114
export const Event = {
114-
Edited: Bus.event(
115+
Edited: BusEvent.define(
115116
"file.edited",
116117
z.object({
117118
file: z.string(),
Collapse file

‎packages/opencode/src/file/watcher.ts‎

Copy file name to clipboardExpand all lines: packages/opencode/src/file/watcher.ts
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
import { BusEvent } from "@/bus/bus-event"
2+
import { Bus } from "@/bus"
13
import z from "zod"
2-
import { Bus } from "../bus"
34
import { Instance } from "../project/instance"
45
import { Log } from "../util/log"
56
import { FileIgnore } from "./ignore"
@@ -16,7 +17,7 @@ export namespace FileWatcher {
1617
const log = Log.create({ service: "file.watcher" })
1718

1819
export const Event = {
19-
Updated: Bus.event(
20+
Updated: BusEvent.define(
2021
"file.watcher.updated",
2122
z.object({
2223
file: z.string(),
Collapse file

‎packages/opencode/src/ide/index.ts‎

Copy file name to clipboardExpand all lines: packages/opencode/src/ide/index.ts
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
import { BusEvent } from "@/bus/bus-event"
2+
import { Bus } from "@/bus"
13
import { spawn } from "bun"
24
import z from "zod"
35
import { NamedError } from "@opencode-ai/util/error"
46
import { Log } from "../util/log"
5-
import { Bus } from "../bus"
67

78
const SUPPORTED_IDES = [
89
{ name: "Windsurf" as const, cmd: "windsurf" },
@@ -16,7 +17,7 @@ export namespace Ide {
1617
const log = Log.create({ service: "ide" })
1718

1819
export const Event = {
19-
Installed: Bus.event(
20+
Installed: BusEvent.define(
2021
"ide.installed",
2122
z.object({
2223
ide: z.string(),
Collapse file

‎packages/opencode/src/installation/index.ts‎

Copy file name to clipboardExpand all lines: packages/opencode/src/installation/index.ts
+4-3Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
import { BusEvent } from "@/bus/bus-event"
2+
import { Bus } from "@/bus"
13
import path from "path"
24
import { $ } from "bun"
35
import z from "zod"
46
import { NamedError } from "@opencode-ai/util/error"
5-
import { Bus } from "../bus"
67
import { Log } from "../util/log"
78
import { iife } from "@/util/iife"
89

@@ -17,13 +18,13 @@ export namespace Installation {
1718
export type Method = Awaited<ReturnType<typeof method>>
1819

1920
export const Event = {
20-
Updated: Bus.event(
21+
Updated: BusEvent.define(
2122
"installation.updated",
2223
z.object({
2324
version: z.string(),
2425
}),
2526
),
26-
UpdateAvailable: Bus.event(
27+
UpdateAvailable: BusEvent.define(
2728
"installation.update-available",
2829
z.object({
2930
version: z.string(),
Collapse file

‎packages/opencode/src/lsp/client.ts‎

Copy file name to clipboardExpand all lines: packages/opencode/src/lsp/client.ts
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
import { BusEvent } from "@/bus/bus-event"
2+
import { Bus } from "@/bus"
13
import path from "path"
24
import { createMessageConnection, StreamMessageReader, StreamMessageWriter } from "vscode-jsonrpc/node"
35
import type { Diagnostic as VSCodeDiagnostic } from "vscode-languageserver-types"
46
import { Log } from "../util/log"
57
import { LANGUAGE_EXTENSIONS } from "./language"
6-
import { Bus } from "../bus"
78
import z from "zod"
89
import type { LSPServer } from "./server"
910
import { NamedError } from "@opencode-ai/util/error"
@@ -25,7 +26,7 @@ export namespace LSPClient {
2526
)
2627

2728
export const Event = {
28-
Diagnostics: Bus.event(
29+
Diagnostics: BusEvent.define(
2930
"lsp.client.diagnostics",
3031
z.object({
3132
serverID: z.string(),
Collapse file

‎packages/opencode/src/lsp/index.ts‎

Copy file name to clipboardExpand all lines: packages/opencode/src/lsp/index.ts
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { BusEvent } from "@/bus/bus-event"
2+
import { Bus } from "@/bus"
13
import { Log } from "../util/log"
24
import { LSPClient } from "./client"
35
import path from "path"
@@ -6,13 +8,12 @@ import z from "zod"
68
import { Config } from "../config/config"
79
import { spawn } from "child_process"
810
import { Instance } from "../project/instance"
9-
import { Bus } from "../bus"
1011

1112
export namespace LSP {
1213
const log = Log.create({ service: "lsp" })
1314

1415
export const Event = {
15-
Updated: Bus.event("lsp.updated", z.object({})),
16+
Updated: BusEvent.define("lsp.updated", z.object({})),
1617
}
1718

1819
export const Range = z

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.