mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 12:54:20 +01:00
- Sandbox new root sessions by default with a per-session composer toggle; child sessions inherit their root session's mode (OM-82) - Run each sandboxed root session in its own microVM that mounts only the session's repository, with per-session CPU/memory overrides, Settings defaults, idle stop, and a cap on running VMs (OM-89) - Arbitrate shell sandboxing with other plugins (opencode-forge) through the shared opencode.sandbox-arbiter.v1 registry so exactly one provider sandboxes each call regardless of load order; fail closed on claim errors - Throw when another plugin rewrites a pinned sandbox shell setting - Tag sandboxed tool results with the owning provider and show it in the badge - Hint the agent to start Docker inside the VM only when OCM owns the session
43 lines
1.2 KiB
TypeScript
43 lines
1.2 KiB
TypeScript
import type { OpenCodeClient } from './opencode/client'
|
|
|
|
const MAX_PARENT_HOPS = 10
|
|
|
|
export class SessionAncestry {
|
|
private readonly parentBySession = new Map<string, string | null>()
|
|
|
|
constructor(private readonly openCodeClient: OpenCodeClient) {}
|
|
|
|
rememberParent(sessionId: string, parentId: string | null | undefined): void {
|
|
this.parentBySession.set(sessionId, parentId ?? null)
|
|
}
|
|
|
|
forget(sessionId: string): void {
|
|
this.parentBySession.delete(sessionId)
|
|
}
|
|
|
|
async resolveRootSessionId(sessionId: string): Promise<string> {
|
|
let current = sessionId
|
|
|
|
for (let hops = 0; hops < MAX_PARENT_HOPS; hops += 1) {
|
|
const parentId = await this.getParentId(current)
|
|
if (!parentId) {
|
|
return current
|
|
}
|
|
current = parentId
|
|
}
|
|
|
|
return current
|
|
}
|
|
|
|
private async getParentId(sessionId: string): Promise<string | null> {
|
|
if (this.parentBySession.has(sessionId)) {
|
|
return this.parentBySession.get(sessionId) ?? null
|
|
}
|
|
|
|
const session = await this.openCodeClient.api.session.get({ sessionID: sessionId })
|
|
const parentId = session.parentID ?? null
|
|
this.parentBySession.set(sessionId, parentId)
|
|
return parentId
|
|
}
|
|
}
|