MCPcopy Index your code
hub / github.com/anomalyco/opencode / resolve

Function resolve

packages/opencode/src/plugin/loader.ts:86–133  ·  view source on GitHub ↗
(
    plan: Plan,
    kind: PluginKind,
  )

Source from the content-addressed store, hash-verified

84 // The stages here intentionally separate install/target resolution, entrypoint detection,
85 // and compatibility checks so callers can report the exact reason a plugin was skipped.
86 export async function resolve(
87 plan: Plan,
88 kind: PluginKind,
89 ): Promise<
90 | { ok: true; value: Resolved }
91 | { ok: false; stage: "missing"; value: Missing }
92 | { ok: false; stage: "install" | "entry" | "compatibility"; error: unknown }
93 > {
94 // First make sure the plugin exists locally, installing npm plugins on demand.
95 let target = ""
96 try {
97 target = await resolvePluginTarget(plan.spec)
98 } catch (error) {
99 return { ok: false, stage: "install", error }
100 }
101 if (!target) return { ok: false, stage: "install", error: new Error(`Plugin ${plan.spec} target is empty`) }
102
103 // Then inspect the target for the requested server/tui entrypoint.
104 let base
105 try {
106 base = await createPluginEntry(plan.spec, target, kind)
107 } catch (error) {
108 return { ok: false, stage: "entry", error }
109 }
110 if (!base.entry)
111 return {
112 ok: false,
113 stage: "missing",
114 value: {
115 ...plan,
116 source: base.source,
117 target: base.target,
118 pkg: base.pkg,
119 message: `Plugin ${plan.spec} does not expose a ${kind} entrypoint`,
120 },
121 }
122
123 // npm plugins can declare which opencode versions they support; file plugins are treated
124 // as local development code and skip this compatibility gate.
125 if (base.source === "npm") {
126 try {
127 await checkPluginCompatibility(base.target, InstallationVersion, base.pkg)
128 } catch (error) {
129 return { ok: false, stage: "compatibility", error }
130 }
131 }
132 return { ok: true, value: { ...plan, source: base.source, target: base.target, entry: base.entry, pkg: base.pkg } }
133 }
134
135 // Import the resolved module only after all earlier validation has succeeded.
136 export async function load(row: Resolved): Promise<{ ok: true; value: Loaded } | { ok: false; error: unknown }> {

Callers 15

startOAuthServerFunction · 0.70
waitForOAuthCallbackFunction · 0.70
startOAuthServerFunction · 0.70
waitForOAuthCallbackFunction · 0.70
startOAuthServerFunction · 0.70
waitForOAuthCallbackFunction · 0.70
attemptFunction · 0.70
closeHttpServerFunction · 0.50
onAbortFunction · 0.50
getFreeLoopbackPortFunction · 0.50

Calls 3

resolvePluginTargetFunction · 0.90
createPluginEntryFunction · 0.90
checkPluginCompatibilityFunction · 0.90

Tested by 11

closeHttpServerFunction · 0.40
onAbortFunction · 0.40
getFreeLoopbackPortFunction · 0.40
doneFunction · 0.40
openSocketFunction · 0.40
expectSocketRejectedFunction · 0.40
waitForMessageFunction · 0.40
openPtySocketFunction · 0.40
isPortFreeFunction · 0.40
occupyPortFunction · 0.40
createEventStreamFunction · 0.40