import type { Shell, ShellConfig } from '@astrale-os/shell' import type { SelfNode } from '../session.context.js' export function isShellConfig(config: ShellConfig | Shell): config is ShellConfig { return 'mode' in config } let prebuiltCounter = 0 const prebuiltIds = new WeakMap() function prebuiltId(shell: object): string { let id = prebuiltIds.get(shell) if (id === undefined) { id = `prebuilt#${++prebuiltCounter}` prebuiltIds.set(shell, id) } return id } /** Stable ownership key. Capability objects intentionally use reference identity. */ export function configIdentity(config: ShellConfig | Shell): string { if (!isShellConfig(config)) return prebuiltId(config) if (config.mode === 'sandboxed') return prebuiltId(config) if (config.client !== undefined) return `standalone-client|${prebuiltId(config.client)}` return `standalone-session|${prebuiltId(config.session)}` } export async function resolveSelf(shell: Shell): Promise { const auth = shell.kernel.auth return typeof auth.whoami === 'function' ? auth.whoami() : null }