fix(plugin-host): persist session cwd and explicitly assign default

This commit is contained in:
Makito
2026-02-28 03:10:41 +07:00
parent ebf1bac222
commit bc4387e2de
+5 -3
View File
@@ -422,6 +422,7 @@ export interface PluginHostSession {
plugin: Plugin plugin: Plugin
id: string id: string
index: number index: number
cwd: string
identity: ModuleIdentity identity: ModuleIdentity
phase: PluginSessionPhase phase: PluginSessionPhase
lifecycle: ActorRefFrom<typeof pluginLifecycleMachine> lifecycle: ActorRefFrom<typeof pluginLifecycleMachine>
@@ -482,6 +483,7 @@ export class PluginHost {
async load(manifest: ManifestV1, options: PluginLoadOptions = {}): Promise<PluginHostSession> { async load(manifest: ManifestV1, options: PluginLoadOptions = {}): Promise<PluginHostSession> {
// Step 0 (channel gateway preparation): resolve runtime and transport for this plugin. // Step 0 (channel gateway preparation): resolve runtime and transport for this plugin.
const runtime = options.runtime ?? this.runtime const runtime = options.runtime ?? this.runtime
const sessionCwd = options.cwd ?? cwd() // Explicitly assign the default CWD.
const transport = this.transport const transport = this.transport
// TODO: implement other transports and runtime bindings. // TODO: implement other transports and runtime bindings.
@@ -519,6 +521,7 @@ export class PluginHost {
plugin: {}, plugin: {},
id, id,
index: sessionIndex, index: sessionIndex,
cwd: sessionCwd,
identity, identity,
phase: lifecycle.getSnapshot().value as PluginSessionPhase, phase: lifecycle.getSnapshot().value as PluginSessionPhase,
lifecycle, lifecycle,
@@ -537,7 +540,7 @@ export class PluginHost {
// Load plugin module from manifest-selected runtime entrypoint. // Load plugin module from manifest-selected runtime entrypoint.
// This is where malformed entrypoints or import errors surface. // This is where malformed entrypoints or import errors surface.
session.plugin = await this.loader.loadPluginFor(manifest, { session.plugin = await this.loader.loadPluginFor(manifest, {
cwd: options.cwd, cwd: sessionCwd,
runtime, runtime,
}) })
@@ -906,11 +909,10 @@ export class PluginHost {
} }
const manifest = previous.manifest const manifest = previous.manifest
const cwdValue = options.cwd
this.stop(sessionId) this.stop(sessionId)
return this.start(manifest, { return this.start(manifest, {
...options, ...options,
cwd: cwdValue, cwd: options.cwd ?? previous.cwd,
runtime: options.runtime ?? previous.runtime, runtime: options.runtime ?? previous.runtime,
}) })
} }