@@ -6,13 +6,18 @@ import { createOpencodeClient } from "@opencode-ai/sdk"
66import { Server } from "../server/server"
77import { BunProc } from "../bun"
88import { Instance } from "../project/instance"
9+ import { Flag } from "../flag/flag"
910import { CodexAuthPlugin } from "./codex"
11+ import { Session } from "../session"
12+ import { NamedError } from "@opencode-ai/util/error"
1013import { CopilotAuthPlugin } from "./copilot"
1114import { gitlabAuthPlugin as GitlabAuthPlugin } from "@gitlab/opencode-gitlab-auth"
1215
1316export namespace Plugin {
1417 const log = Log . create ( { service : "plugin" } )
1518
19+ const BUILTIN = [ "opencode-anthropic-auth@0.0.13" ]
20+
1621 // Built-in plugins that are directly imported (not installed from npm)
1722 const INTERNAL_PLUGINS : PluginInstance [ ] = [ CodexAuthPlugin , CopilotAuthPlugin , GitlabAuthPlugin ]
1823
@@ -41,6 +46,9 @@ export namespace Plugin {
4146
4247 const plugins = [ ...( config . plugin ?? [ ] ) ]
4348 if ( plugins . length ) await Config . waitForDependencies ( )
49+ if ( ! Flag . OPENCODE_DISABLE_DEFAULT_PLUGINS ) {
50+ plugins . push ( ...BUILTIN )
51+ }
4452
4553 for ( let plugin of plugins ) {
4654 // ignore old codex plugin since it is supported first party now
@@ -50,7 +58,24 @@ export namespace Plugin {
5058 const lastAtIndex = plugin . lastIndexOf ( "@" )
5159 const pkg = lastAtIndex > 0 ? plugin . substring ( 0 , lastAtIndex ) : plugin
5260 const version = lastAtIndex > 0 ? plugin . substring ( lastAtIndex + 1 ) : "latest"
53- plugin = await BunProc . install ( pkg , version )
61+ const builtin = BUILTIN . some ( ( x ) => x . startsWith ( pkg + "@" ) )
62+ plugin = await BunProc . install ( pkg , version ) . catch ( ( err ) => {
63+ if ( ! builtin ) throw err
64+
65+ const message = err instanceof Error ? err . message : String ( err )
66+ log . error ( "failed to install builtin plugin" , {
67+ pkg,
68+ version,
69+ error : message ,
70+ } )
71+ Bus . publish ( Session . Event . Error , {
72+ error : new NamedError . Unknown ( {
73+ message : `Failed to install built-in plugin ${ pkg } @${ version } : ${ message } ` ,
74+ } ) . toObject ( ) ,
75+ } )
76+
77+ return ""
78+ } )
5479 if ( ! plugin ) continue
5580 }
5681 const mod = await import ( plugin )
0 commit comments