fix(coding-agent): reuse initial resource loader on startup closes #2766

This commit is contained in:
Mario Zechner
2026-04-02 11:05:41 +02:00
parent 8ccd3c55c1
commit 617f1870f8
3 changed files with 10 additions and 3 deletions

View File

@@ -79,6 +79,7 @@ After runtime replacement, use `runtimeHost.session` as the new live session and
### Fixed ### Fixed
- Fixed startup resource loading to reuse the initial `ResourceLoader` for the first runtime, so extensions are not loaded twice before session startup and `session_start` handlers still fire for singleton-style extensions ([#2766](https://github.com/badlogic/pi-mono/issues/2766))
- Fixed theme `export` colors to resolve theme variables the same way as `colors`, so `/export` HTML backgrounds now honor entries like `pageBg: "base"` instead of requiring inline hex values ([#2707](https://github.com/badlogic/pi-mono/issues/2707)) - Fixed theme `export` colors to resolve theme variables the same way as `colors`, so `/export` HTML backgrounds now honor entries like `pageBg: "base"` instead of requiring inline hex values ([#2707](https://github.com/badlogic/pi-mono/issues/2707))
## [0.64.0] - 2026-03-29 ## [0.64.0] - 2026-03-29

View File

@@ -53,6 +53,8 @@ export interface CreateAgentSessionRuntimeOptions {
cwd: string; cwd: string;
/** Optional preselected session manager. If omitted, normal session resolution applies. */ /** Optional preselected session manager. If omitted, normal session resolution applies. */
sessionManager?: SessionManager; sessionManager?: SessionManager;
/** Optional preloaded resource loader to reuse instead of creating and reloading one. */
resourceLoader?: ResourceLoader;
/** Optional session_start metadata to emit when the runtime binds extensions. */ /** Optional session_start metadata to emit when the runtime binds extensions. */
sessionStartEvent?: SessionStartEvent; sessionStartEvent?: SessionStartEvent;
} }
@@ -86,15 +88,18 @@ export async function createAgentSessionRuntime(
const settingsManager = SettingsManager.create(cwd, agentDir); const settingsManager = SettingsManager.create(cwd, agentDir);
const modelRegistry = ModelRegistry.create(authStorage, join(agentDir, "models.json")); const modelRegistry = ModelRegistry.create(authStorage, join(agentDir, "models.json"));
const resourceLoader = const resourceLoader =
typeof bootstrap.resourceLoader === "function" options.resourceLoader ??
(typeof bootstrap.resourceLoader === "function"
? await bootstrap.resourceLoader(cwd, agentDir) ? await bootstrap.resourceLoader(cwd, agentDir)
: new DefaultResourceLoader({ : new DefaultResourceLoader({
...(bootstrap.resourceLoader ?? {}), ...(bootstrap.resourceLoader ?? {}),
cwd, cwd,
agentDir, agentDir,
settingsManager, settingsManager,
}); }));
await resourceLoader.reload(); if (!options.resourceLoader) {
await resourceLoader.reload();
}
const extensionsResult = resourceLoader.getExtensions(); const extensionsResult = resourceLoader.getExtensions();
for (const { name, config } of extensionsResult.runtime.pendingProviderRegistrations) { for (const { name, config } of extensionsResult.runtime.pendingProviderRegistrations) {

View File

@@ -873,6 +873,7 @@ export async function main(args: string[]) {
const runtime = await createAgentSessionRuntime(runtimeBootstrap, { const runtime = await createAgentSessionRuntime(runtimeBootstrap, {
cwd: sessionManager?.getCwd() ?? cwd, cwd: sessionManager?.getCwd() ?? cwd,
sessionManager, sessionManager,
resourceLoader,
}); });
if (process.cwd() !== runtime.cwd) { if (process.cwd() !== runtime.cwd) {
process.chdir(runtime.cwd); process.chdir(runtime.cwd);