feat: expose daemon-owned active agent profile

This commit is contained in:
Federico Jaramillo Martinez
2026-07-13 22:50:50 +02:00
parent a1a019e7b1
commit 141cda93c8
11 changed files with 362 additions and 25 deletions
+23
View File
@@ -90,6 +90,29 @@ describe("PI WEB status", () => {
expect(runtime.capabilities).toEqual(expect.arrayContaining([PI_WEB_CAPABILITIES.piPackagesManage, PI_WEB_CAPABILITIES.selectedMachineSettings]));
});
it("carries the daemon-owned active agent profile through the web runtime response", async () => {
const activeAgentProfile = {
schemaVersion: 1 as const,
revision: `sha256:${"a".repeat(64)}`,
command: "acme-agent",
dir: "/opt/acme-agent/state",
sessionDirEnvKeys: ["PI_WEB_AGENT_SESSION_DIR"],
};
const daemon = daemonWithRuntime({
component: "sessiond",
label: "Session daemon",
runtimeVersion: "1.202605.7",
available: true,
capabilities: [],
activeAgentProfile,
});
const runtime = await getPiWebRuntime(daemon);
expect(runtime.components.sessiond.activeAgentProfile).toEqual(activeAgentProfile);
expect(runtime.components.web.activeAgentProfile).toBeUndefined();
});
it("bypasses cached npm release data for a forced check", async () => {
Reflect.deleteProperty(process.env, "PI_WEB_SKIP_VERSION_CHECK");
process.env["PI_WEB_DOCKER_RUNTIME"] = "1";
+32 -23
View File
@@ -20,11 +20,16 @@ import { TerminalService } from "./terminals/terminalService.js";
import { registerTerminalRoutes } from "./terminals/terminalRoutes.js";
import { getPiWebRuntimeComponent } from "./piWebStatus.js";
import { SESSIOND_RUNTIME_CAPABILITIES } from "../shared/capabilities.js";
import { effectiveAgentConfig, effectivePiWebConfig, maxUploadBytes, spawnSessionsEnabled, subsessionsEnabled } from "../config.js";
import { agentSessionDirEnvKeys, effectivePiWebConfig, maxUploadBytes, spawnSessionsEnabled, subsessionsEnabled } from "../config.js";
import { createActiveAgentProfileDescriptor } from "../sessiond/activeAgentProfile.js";
import { runSessionDaemonStartup } from "./sessiond/sessionDaemonStartup.js";
const { config } = effectivePiWebConfig();
const agent = effectiveAgentConfig(process.env, config);
const activeAgentProfile = createActiveAgentProfileDescriptor({
command: config.agent.command,
dir: config.agent.dir,
sessionDirEnvKeys: agentSessionDirEnvKeys(config.agent.command),
});
const app = Fastify({ logger: true, bodyLimit: maxUploadBytes(process.env, config) });
await app.register(fastifyWebsocket);
@@ -33,46 +38,50 @@ await runSessionDaemonStartup({
createRuntime() {
const eventHub = new SessionEventHub();
const workspaceActivity = new WorkspaceActivityService(eventHub);
const auth = new AuthService({ agentDir: agent.dir });
const auth = new AuthService({ agentDir: activeAgentProfile.dir });
const spawnTargets = spawnSessionsEnabled(process.env, config)
? new ProjectScopedSpawnTargetResolver({ projects: new ProjectService(new ProjectStore()), workspaces: new WorkspaceService() })
: undefined;
const sessions = new PiSessionService(eventHub, {
modelRegistry: auth.modelRegistry,
agentDir: agent.dir,
agentDir: activeAgentProfile.dir,
workspaceActivity,
logger: app.log,
...(spawnTargets === undefined ? {} : { spawnTargets }),
subsessionsEnabled: spawnTargets !== undefined && subsessionsEnabled(process.env, config),
sessionManager: createPiSessionManagerGateway({ agentDir: agent.dir, sessionDirEnvKeys: agent.sessionDirEnvKeys }),
sessionManager: createPiSessionManagerGateway({
agentDir: activeAgentProfile.dir,
sessionDirEnvKeys: activeAgentProfile.sessionDirEnvKeys,
}),
});
auth.subscribe((change) => { sessions.applyAuthChange(change); });
const terminals = new TerminalService(eventHub, workspaceActivity);
return { eventHub, workspaceActivity, auth, sessions, terminals };
const runtimeComponent = Object.freeze({
...getPiWebRuntimeComponent("sessiond", SESSIOND_RUNTIME_CAPABILITIES),
activeAgentProfile,
});
return { eventHub, workspaceActivity, auth, sessions, terminals, activeAgentProfile, runtimeComponent };
},
registerRoutes({ eventHub, workspaceActivity, auth, sessions, terminals }) {
registerRoutes({ eventHub, workspaceActivity, auth, sessions, terminals, runtimeComponent }) {
registerWorkspaceActivityRoutes(app, workspaceActivity);
registerAuthRoutes(app, auth);
registerSessionRoutes(app, sessions, eventHub);
registerTerminalRoutes(app, terminals);
app.get("/health", () => {
const runtime = getPiWebRuntimeComponent("sessiond", SESSIOND_RUNTIME_CAPABILITIES);
return {
ok: true,
activeSessions: sessions.activeCount(),
checkedAt: new Date().toISOString(),
version: {
component: runtime.component,
label: runtime.label,
...(runtime.runtimeVersion === undefined ? {} : { runtimeVersion: runtime.runtimeVersion }),
stale: false,
available: runtime.available,
},
};
});
app.get("/health", () => ({
ok: true,
activeSessions: sessions.activeCount(),
checkedAt: new Date().toISOString(),
version: {
component: runtimeComponent.component,
label: runtimeComponent.label,
...(runtimeComponent.runtimeVersion === undefined ? {} : { runtimeVersion: runtimeComponent.runtimeVersion }),
stale: false,
available: runtimeComponent.available,
},
}));
app.get("/runtime", () => getPiWebRuntimeComponent("sessiond", SESSIOND_RUNTIME_CAPABILITIES));
app.get("/runtime", () => runtimeComponent);
},
async listen({ auth, sessions, terminals }) {
let shuttingDown = false;