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 — fix(core): register a new ChatGPT client when adding an account · anomalyco/opencode@46df5d6

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • packages
    • core
      • src
        • automation.ts
        • automation
          • code.ts
          • shell.ts
        • environment
          • environment.ts
          • environments.ts
          • index.ts
          • path.ts
        • file-access.ts
        • filesystem.ts
        • filesystem
          • search.ts
        • formatter.ts
        • machine
          • driver.ts
          • path.ts
        • mcp
          • index.ts
        • model-lookup.ts
        • model.ts
        • models-dev.ts
        • plugin.ts
        • plugin
          • host.ts
          • provider
            • chatgpt.ts
            • claude-agent
              • index.ts
            • local.ts
          • service.ts
        • ripgrep.ts
        • session
          • runner
            • model.ts
          • to-session-error.ts
        • shell.ts
        • tool
          • plugin
            • cd.ts
          • search.ts
        • worktree.ts
        • worktree
          • strategies.ts
      • test
        • environment.test.ts
        • environments.test.ts
        • fixture
          • target-environment.ts
        • machine-path.test.ts
        • mcp-stdio.test.ts
        • mcp.test.ts
        • models.test.ts
        • plugin
          • automation.test.ts
          • fixture.ts
          • provider-chatgpt.test.ts
          • provider-ollama.test.ts
          • provider/claude-agent
            • plugin.test.ts
        • session-cwd-instructions.test.ts
        • shell-retention.test.ts
        • tool-read.test.ts
        • tool-search-target-environment.test.ts
        • tool-shell-target-environment.test.ts
        • worktree.test.ts
    • data
      • app/src/routes
        • index.tsx
      • core/src/domain
        • home.test.ts
        • home.ts
    • plugin/src/promise
      • adapter.ts
    • sdk
      • src/internal
        • instances.ts
      • test
        • instances.test.ts
    • server/test
      • workerd.test.ts
    • session-ui/src
      • components
        • message-part.css
      • message
        • user-message-quotes.tsx
    • tui
      • src/context
        • local.tsx
      • test/component
        • dialog-speed.test.tsx

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Dismiss banner
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎packages/core/src/automation.ts‎

Copy file name to clipboardExpand all lines: packages/core/src/automation.ts
+14-3Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,14 +254,25 @@ const layer = Layer.effect(
254254
const doorbell = yield* Latch.make()
255255
const watches = yield* FiberMap.make<ID>()
256256

257+
/**
258+
* Runs `effect` with `owner`'s Session capabilities. A plugin provides its instance's selector, which can serve the
259+
* instance while it is still booting.
260+
*/
261+
const inSession =
262+
(owner: SessionSchema.Info) =>
263+
<A, E, R>(effect: Effect.Effect<A, E, R>) =>
264+
Effect.flatMap(Effect.serviceOption(Instance.Service), (selector) =>
265+
Option.getOrElse(selector, () => instances).provide(owner)(effect),
266+
)
267+
257268
/**
258269
* The agent a run's child Session starts with, if `owner` could start it with the subagent tool: not hidden, not
259270
* primary-only, within the depth limit and already allowed in the owner's current Location. The code/tools
260271
* authorized when the automation was created do not grant permission to start a child.
261272
*/
262273
const subagent = (owner: SessionSchema.Info, id: Agent.ID, invocation?: Invocation) =>
263274
Effect.gen(function* () {
264-
yield* Plugin.awaitActivation
275+
yield* AutomationCode.awaitPlugins.pipe(Effect.mapError((reason) => new InvalidError({ reason })))
265276
const location = yield* Location.Service
266277
if (location.project.id !== owner.projectID)
267278
return yield* new InvalidError({ reason: "The creating session's location is no longer in its project" })
@@ -296,7 +307,7 @@ const layer = Layer.effect(
296307
),
297308
)
298309
return agent
299-
}).pipe(instances.provide(owner))
310+
}).pipe(inSession(owner))
300311

301312
/** Runs `effect` in the Location of `directory`; fails with DirectoryNotFoundError when the folder is gone. */
302313
const inDirectory =
@@ -1096,7 +1107,7 @@ const layer = Layer.effect(
10961107
if (action.type === "shell") {
10971108
if (!owner) return yield* new InvalidError({ reason: "A shell action needs a session" })
10981109
yield* AutomationShell.authorize(owner, input.name, trigger, action, invocation).pipe(
1099-
instances.provide(owner),
1110+
inSession(owner),
11001111
Effect.mapError((error) => (typeof error === "string" ? new InvalidError({ reason: error }) : error)),
11011112
)
11021113
return action
Collapse file

‎packages/core/src/automation/code.ts‎

Copy file name to clipboardExpand all lines: packages/core/src/automation/code.ts
+20-2Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ export * as AutomationCode from "./code.js"
22

33
import { CodeMode } from "@opencode/codemode"
44
import { Automation } from "@opencode/schema/automation"
5-
import { Array, Effect, Option, Result, Schema } from "effect"
5+
import { Array, Context, Effect, Option, Result, Schema } from "effect"
66
import { Agent } from "../agent.js"
77
import { CodeModeTool } from "../codemode/tool.js"
88
import { Permission } from "../permission.js"
@@ -83,6 +83,24 @@ function scanProgram(code: string): Result.Result<ProgramScan, string> {
8383
return Result.succeed({ tools: scanned.success.tools, actions: extensionActions(scanned.success) })
8484
}
8585

86+
/** The calling plugin's registry. SDK instances and the host can have separate registries at the same Location. */
87+
export const FromPlugin = Context.Reference<Plugin.Interface | undefined>("@opencode/AutomationCode/FromPlugin", {
88+
defaultValue: () => undefined,
89+
})
90+
91+
/**
92+
* Waits for this registry's plugins. A create from a plugin in this same registry is refused instead while it activates:
93+
* its activation may be waiting on that plugin's setup, and configured permissions are applied by plugins that load later.
94+
*/
95+
export const awaitPlugins = Effect.gen(function* () {
96+
const plugins = yield* Plugin.Service
97+
if ((yield* FromPlugin) !== plugins) return yield* plugins.awaitActivation
98+
if (yield* plugins.activated) return
99+
return yield* Effect.fail(
100+
"Plugins in this location are still loading, so configured permissions are not applied yet. Create this automation after plugin setup, for example from an event handler.",
101+
)
102+
})
103+
86104
/**
87105
* Runs in the creating Session's Location while the user is present: asks once for tool and extension permissions (and for
88106
* `execute` if none of those needed approval), without saving, so every run can be allowed unattended.
@@ -95,7 +113,7 @@ export const authorize = Effect.fnUntraced(function* (
95113
invocation?: Invocation,
96114
) {
97115
const scanned = yield* Effect.fromResult(scan(action.code))
98-
yield* Plugin.awaitActivation
116+
yield* awaitPlugins
99117
const permission = yield* Permission.Service
100118
const agents = yield* Agent.Service
101119
const agent = yield* agents.select(session.agent)
Collapse file

‎packages/core/src/automation/shell.ts‎

Copy file name to clipboardExpand all lines: packages/core/src/automation/shell.ts
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { Shell } from "../shell.js"
1212
import { ShellPermissions } from "../shell/permissions.js"
1313
import { ShellSelect } from "../shell/select.js"
1414
import { type Invocation, matchesAuthor } from "./author.js"
15+
import { AutomationCode } from "./code.js"
1516

1617
export const authorize = Effect.fnUntraced(function* (
1718
owner: SessionSchema.Info,
@@ -20,7 +21,7 @@ export const authorize = Effect.fnUntraced(function* (
2021
action: Automation.ShellAction,
2122
invocation?: Invocation,
2223
) {
23-
if (invocation) yield* Plugin.awaitActivation
24+
if (invocation || (yield* AutomationCode.FromPlugin)) yield* AutomationCode.awaitPlugins
2425
const agents = yield* Agent.Service
2526
const agent = yield* agents.select(owner.agent)
2627
if (invocation && !matchesAuthor(owner, agent.info, invocation))
Collapse file

‎packages/core/src/environment/environment.ts‎

Copy file name to clipboardExpand all lines: packages/core/src/environment/environment.ts
+13-23Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { CrossSpawnSpawner } from "@opencode/util/cross-spawn-spawner"
22
import { makeLocationNode } from "@opencode/util/effect/app-node"
3-
import { Global } from "@opencode/util/global"
43
import { Context, Effect, Layer, PlatformError, Schema } from "effect"
54
import { ChildProcessSpawner } from "effect/process"
65
import { posix, type PlatformPath } from "node:path"
@@ -27,40 +26,33 @@ export const Place = Schema.Struct({
2726
})
2827
export type Place = typeof Place.Type
2928

30-
/** Target properties supplied by whoever constructs an Environment. */
31-
export interface Options {
32-
/**
33-
* True only when commands and files live on the server's own OS process (false on workerd and all remotes):
34-
* commands start from the server's variables, cwds resolve here, the process daemon can hold them, and host
35-
* formatters and worktree strategies reach its files.
36-
*/
37-
readonly local?: boolean
29+
/** What an environment says about itself, set by whoever makes it. Absent means no, or the server's own. */
30+
export interface Facts {
3831
/** The path rules of its files, when they are not the server's. */
3932
readonly path?: PlatformPath
4033
/** The shell every command there runs under, when it is not the configured one. */
4134
readonly shell?: string
42-
/** Resolves `~` in this environment when available (host homedir locally, `hello.home` on paired machines). */
43-
readonly home?: Effect.Effect<string, unknown>
4435
/**
45-
* Ripgrep command to spawn in this environment (`undefined` means search is unavailable).
46-
* Local environments (`local: true`) use the bundled `RipgrepBinary` when `rg` is set.
36+
* Whether this is the computer the server itself runs on, so a command there is the server's own child: it starts
37+
* from the server's variables, its cwd is made absolute here, the server's process daemon can hold it, and the
38+
* server's formatters reach its files.
4739
*/
48-
readonly rg?: Effect.Effect<string, unknown>
40+
readonly hostsServer?: boolean
41+
/** Whether a search can run over its files. It goes when the search tools no longer need a ripgrep binary there. */
42+
readonly searchable?: boolean
4943
}
5044

51-
export interface Interface extends Options {
45+
export interface Interface extends Facts {
5246
readonly id: ID
53-
readonly local: boolean
5447
readonly files: Files
5548
readonly spawner: ChildProcessSpawner.ChildProcessSpawner["Service"]
5649
}
5750

5851
export class Service extends Context.Service<Service, Interface>()("@opencode/Environment") {}
5952

60-
export const make = (id: ID, driver: Driver, options?: Options): Interface => ({
61-
...options,
53+
export const make = (id: ID, driver: Driver, facts?: Facts): Interface => ({
54+
...facts,
6255
id,
63-
local: options?.local === true,
6456
files: makeFiles(driver),
6557
spawner: driver.spawner,
6658
})
@@ -71,14 +63,12 @@ export const local = (spawner: ChildProcessSpawner.ChildProcessSpawner["Service"
7163
localID,
7264
makeLocalDriver(spawner),
7365
// Runtimes without local process execution (such as workerd) cannot host local commands or search.
74-
spawner === EnvironmentUnavailable.spawner
75-
? {}
76-
: { local: true, home: Effect.sync(() => Global.Path.home), rg: Effect.succeed("rg") },
66+
spawner === EnvironmentUnavailable.spawner ? {} : { hostsServer: true, searchable: true },
7767
)
7868

7969
/** A workspace sandbox environment; runs ripgrep through its own spawner and uses POSIX path rules. */
8070
export const workspace = (id: Workspace.ID, driver: Driver) =>
81-
make(ID.make(id), driver, { path: posix, rg: Effect.succeed("rg") })
71+
make(ID.make(id), driver, { path: posix, searchable: true })
8272

8373
/**
8474
* A total environment handle that fails every file and command operation loudly with `cause` instead of
Collapse file

‎packages/core/src/environment/environments.ts‎

Copy file name to clipboardExpand all lines: packages/core/src/environment/environments.ts
-6Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ export interface Interface {
2020
* Fails immediately with NotFound when a machine or workspace does not exist, without waking lazy sandboxes.
2121
*/
2222
readonly lookup: (id: Environment.ID) => Effect.Effect<Environment.Interface, Machines.NotFound | Workspace.NotFound>
23-
/** Whether an environment prefix is known (local, any workspace ID, or a registered paired machine). */
24-
readonly has: (id: Environment.ID) => Effect.Effect<boolean>
2523
/** Whether an environment is currently reachable in memory without waking a cold/lazy sandbox. */
2624
readonly ready: (id: Environment.ID) => Effect.Effect<boolean>
2725
}
@@ -58,10 +56,6 @@ const layer = Layer.effect(
5856
}
5957
return yield* machines.get(id)
6058
}),
61-
has: Effect.fn("Environments.has")(function* (id: Environment.ID) {
62-
if (id === Environment.localID || Workspace.isID(id)) return true
63-
return (yield* machines.list()).some((info) => info.id === id)
64-
}),
6559
ready: Effect.fn("Environments.ready")(function* (id: Environment.ID) {
6660
if (id === Environment.localID) return true
6761
if (Workspace.isID(id)) return yield* workspaces.connected(id)
Collapse file

‎packages/core/src/environment/index.ts‎

Copy file name to clipboardExpand all lines: packages/core/src/environment/index.ts
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ export {
2424
localID,
2525
make,
2626
node,
27-
type Options,
2827
Place,
2928
Service,
3029
unavailable,
Collapse file

‎packages/core/src/environment/path.ts‎

Copy file name to clipboardExpand all lines: packages/core/src/environment/path.ts
+7-2Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,17 @@ export const parse = (text: string): Parsed | undefined => {
5353
* Non-rooted `name:relative` text is refused for reserved environment prefixes (`local:`, `wrk_...:`) and
5454
* known paired machines so typos never silently misroute to another environment's relative path.
5555
*/
56-
export const typed = Effect.fnUntraced(function* (text: string, has: (id: Environment.ID) => Effect.Effect<boolean>) {
56+
export const typed = Effect.fnUntraced(function* (text: string, machines: Machines.Interface) {
5757
const parsed = parse(text)
5858
if (parsed) return parsed
5959
const named = split(text)
6060
if (!named || rooted(named)) return
61-
if (yield* has(named.environment)) return yield* new NotAbsolute({ machine: named.environment })
61+
if (
62+
named.environment === Environment.localID ||
63+
Workspace.isID(named.environment) ||
64+
(yield* machines.list()).some((info) => info.id === named.environment)
65+
)
66+
return yield* new NotAbsolute({ machine: named.environment })
6267
})
6368

6469
/** An environment path's text: what `parse` reads back. */
Collapse file

‎packages/core/src/file-access.ts‎

Copy file name to clipboardExpand all lines: packages/core/src/file-access.ts
+16-14Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ import { Environment } from "./environment/index.js"
1010
import { EnvironmentPath } from "./environment/path.js"
1111
import { Flag } from "./flag.js"
1212
import { Location } from "./location.js"
13+
import { Machines } from "./machine/machines.js"
1314
import { Permission } from "./permission.js"
1415
import { Project } from "./project.js"
1516
import { AbsolutePath } from "./schema.js"
1617
import type { SessionErrors } from "./session/error.js"
1718
import type { Tool } from "./tool.js"
19+
import { Workspace } from "./workspace.js"
1820

1921
export const Kind = Schema.Literals(["file", "directory"])
2022
export type Kind = typeof Kind.Type
@@ -132,6 +134,7 @@ const layer = Layer.effect(
132134
const permission = yield* Permission.Service
133135
const flags = yield* Flag.Service
134136
const environments = yield* Environments.Service
137+
const machines = yield* Machines.Service
135138

136139
// The flag and the working directory are read once per operation by `locate` and `resolve`, which both call this.
137140
const place = Effect.fnUntraced(function* (
@@ -146,7 +149,7 @@ const layer = Layer.effect(
146149
const crossEnvironment = enabled && environment.id === Environment.localID
147150
const parsed =
148151
!base && crossEnvironment
149-
? yield* EnvironmentPath.typed(text, environments.has).pipe(
152+
? yield* EnvironmentPath.typed(text, machines).pipe(
150153
Effect.mapError((cause) => new Environment.Failed({ path: text, cause })),
151154
)
152155
: undefined
@@ -161,24 +164,23 @@ const layer = Layer.effect(
161164
} satisfies Environment.Place
162165
}
163166
// Another environment's paths follow its own path rules (falling back to POSIX when unknown). Only `~` and `~/`
164-
// are expanded when the target environment exposes `home` (e.g. a paired machine's hello or a sandbox with home).
167+
// are expanded: paired machines report their home in hello, while sandboxes do not expose a home directory.
165168
// With the flag off no home is asked for, so a base on another machine refuses every `~`.
166-
const written = parsed?.path ?? text
167-
const isHome = written === "~" || written.startsWith("~/")
168169
const target = crossEnvironment
169-
? yield* environments
170-
.lookup(id)
171-
.pipe(
172-
Effect.catch((cause) =>
173-
isHome ? Effect.fail(new Environment.Failed({ path: text, cause })) : Effect.undefined,
174-
),
175-
)
170+
? yield* environments.lookup(id).pipe(
171+
Effect.catchTags({
172+
"Machines.NotFound": () => Effect.undefined,
173+
"Workspace.NotFound": () => Effect.undefined,
174+
}),
175+
)
176176
: undefined
177177
const rules = target ? (target.path ?? path) : path.posix
178+
const written = parsed?.path ?? text
179+
const isHome = written === "~" || written.startsWith("~/")
178180
const rooted =
179-
crossEnvironment && isHome && target?.home
181+
crossEnvironment && isHome && !Workspace.isID(id)
180182
? rules.join(
181-
yield* target.home.pipe(Effect.mapError((cause) => new Environment.Failed({ path: text, cause }))),
183+
yield* machines.home(id).pipe(Effect.mapError((cause) => new Environment.Failed({ path: text, cause }))),
182184
written.slice(1),
183185
)
184186
: written
@@ -348,5 +350,5 @@ const layer = Layer.effect(
348350
export const node = makeLocationNode({
349351
service: Service,
350352
layer,
351-
deps: [Environment.node, Environments.node, Flag.node, Location.node, Permission.node],
353+
deps: [Environment.node, Environments.node, Flag.node, Location.node, Machines.node, Permission.node],
352354
})
Collapse file

‎packages/core/src/filesystem.ts‎

Copy file name to clipboardExpand all lines: packages/core/src/filesystem.ts
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ const baseLayer = Layer.effect(
119119
// configured directory as canonical; host placements keep symlink
120120
// canonicalization. This skip is boot-only: resolve/read/list below still
121121
// access the host filesystem per operation (tracked in #44568).
122-
const root = environment.local
122+
const root = environment.hostsServer
123123
? yield* fs.realPath(location.directory).pipe(
124124
// Linux realpath succeeds on an unreadable directory, so probe readability explicitly.
125125
Effect.tap((real) => fs.access(real, { readable: true })),
Collapse file

‎packages/core/src/filesystem/search.ts‎

Copy file name to clipboardExpand all lines: packages/core/src/filesystem/search.ts
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ const layer = (options?: Options) =>
231231
const environment = yield* Environment.Service
232232
// fff indexes a directory on the server's own disk in-process, so only the server's own environment can use it.
233233
// Ripgrep routes through the Location environment spawner.
234-
if (!environment.local) return ripgrepLayer
234+
if (!environment.hostsServer) return ripgrepLayer
235235
if (options?.fff === false || (options?.fff === undefined && process.platform === "win32") || !Fff.available())
236236
return ripgrepLayer
237237
// Non-VCS locations can contain many repositories, so avoid eagerly content-indexing the entire aggregate tree.

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.