UNPKG

@code-yeongyu/senpi

Version:

Coding agent CLI with read, bash, edit, write tools and session management

63 lines • 3.78 kB
const THINKING_LEVELS = [ "off", "minimal", "low", "medium", "high", "xhigh", "max", ]; const thinkingLevelOf = (value) => THINKING_LEVELS.find((level) => level === value); /** * The park record of a retained session. `hostContextKeys` are the context keys THIS host merged * in on open: they describe this generation and are stripped, so the successor merges its own. */ export function parkedEntryFromProfile(session, profile, hostContextKeys) { const clientContext = profile?.sessionContext === undefined ? undefined : Object.fromEntries(Object.entries(profile.sessionContext).filter(([key]) => !hostContextKeys.includes(key))); return { sessionPath: session.sessionPath, ...(session.durableSessionId !== undefined ? { durableSessionId: session.durableSessionId } : {}), retainOnDisconnect: true, ...(session.contextOverlay !== undefined ? { contextOverlay: session.contextOverlay } : {}), ...(profile?.cwd !== undefined ? { cwd: profile.cwd } : {}), ...(profile?.creationModel !== undefined ? { model: profile.creationModel } : {}), ...(profile?.initialThinkingLevel !== undefined ? { thinkingLevel: profile.initialThinkingLevel } : {}), ...(profile?.permissionPreset !== undefined ? { permissionPreset: profile.permissionPreset } : {}), ...(profile?.promptSurface !== undefined ? { promptSurface: profile.promptSurface } : {}), ...(profile?.browserEngine !== undefined ? { browserEngine: profile.browserEngine } : {}), ...(profile?.sessionKind !== undefined ? { sessionKind: profile.sessionKind } : {}), ...(clientContext !== undefined && Object.keys(clientContext).length > 0 ? { sessionContext: clientContext } : {}), ...(profile?.autoTitle !== undefined ? { autoTitle: profile.autoTitle } : {}), ...(profile?.retryFallback !== undefined ? { retryFallback: profile.retryFallback } : {}), ...(profile?.sessionEnv !== undefined ? { sessionEnv: profile.sessionEnv } : {}), }; } /** The `open_session` a parked entry replays on the successor. */ export function parkedOpenCommand(entry) { const thinkingLevel = thinkingLevelOf(entry.thinkingLevel); if (entry.thinkingLevel !== undefined && thinkingLevel === undefined) process.stderr.write(`senpi rpc successor reopens ${entry.sessionPath} without its unknown thinking level "${entry.thinkingLevel}"\n`); const command = { type: "open_session", sessionPath: entry.sessionPath, ...(entry.cwd !== undefined ? { cwd: entry.cwd } : {}), ...(entry.durableSessionId !== undefined ? { durableSessionId: entry.durableSessionId } : {}), ...(entry.model !== undefined ? { provider: entry.model.provider, modelId: entry.model.modelId } : {}), ...(thinkingLevel !== undefined ? { thinkingLevel } : {}), ...(entry.permissionPreset !== undefined ? { permissionPreset: entry.permissionPreset } : {}), ...(entry.promptSurface !== undefined ? { promptSurface: entry.promptSurface } : {}), ...(entry.browserEngine !== undefined ? { browserEngine: entry.browserEngine } : {}), ...(entry.sessionKind !== undefined ? { kind: entry.sessionKind } : {}), ...(entry.sessionContext !== undefined ? { context: entry.sessionContext } : {}), ...(entry.autoTitle !== undefined ? { auto_title: entry.autoTitle } : {}), ...(entry.retryFallback !== undefined ? { retryFallback: entry.retryFallback } : {}), ...(entry.sessionEnv !== undefined ? { env: { ...entry.sessionEnv } } : {}), retain_on_disconnect: entry.retainOnDisconnect, }; return command; } //# sourceMappingURL=host-handover-parked-open.js.map