mirror of
https://github.com/wu736139669/hapi.git
synced 2026-11-25 05:07:05 +00:00
feat(codex): share sessions across terminal and web
Use one native app-server for terminal, Web and phone clients while retaining the existing CLI and Runner lifecycle. Synchronize native queues, permissions, question history and steering state; preserve explicit permission precedence and per-turn usage models. Resume inactive clear commands through Runner and reject independent child cold resumes. Add shared-runtime regression tests, generated protocol fixtures and lifecycle documentation.
This commit is contained in:
@@ -21,6 +21,9 @@ export { HAPI_SESSION_ID_ENV, exportHapiSessionEnv, exportHapiHubAuthEnv } from
|
||||
export type SessionStartedBy = 'runner' | 'terminal'
|
||||
|
||||
export type SessionBootstrapOptions = {
|
||||
reportStarted?: boolean
|
||||
/** Multi-session workers inject session identity into each child, never process.env. */
|
||||
exportSessionEnv?: boolean
|
||||
flavor: string
|
||||
startedBy?: SessionStartedBy
|
||||
workingDirectory?: string
|
||||
@@ -229,9 +232,9 @@ export async function bootstrapSession(options: SessionBootstrapOptions): Promis
|
||||
|
||||
const session = api.sessionSyncClient(sessionInfo)
|
||||
|
||||
exportHapiSessionEnv(sessionInfo.id)
|
||||
if (options.exportSessionEnv !== false) exportHapiSessionEnv(sessionInfo.id)
|
||||
|
||||
await reportSessionStarted(sessionInfo.id, metadata)
|
||||
if (options.reportStarted !== false) await reportSessionStarted(sessionInfo.id, metadata)
|
||||
|
||||
return {
|
||||
api,
|
||||
@@ -314,7 +317,7 @@ export async function bootstrapLazySession(options: SessionBootstrapOptions): Pr
|
||||
// Export only after the hub row exists. Exporting the provisional id at
|
||||
// bootstrap lets agents inherit HAPI_SESSION_ID before GET /api/sessions/:id
|
||||
// can resolve (and before hapiMcpUrl is persisted) — #1119 / PR #1121 Major.
|
||||
exportHapiSessionEnv(materialized.id)
|
||||
if (options.exportSessionEnv !== false) exportHapiSessionEnv(materialized.id)
|
||||
void reportSessionStarted(materialized.id, snapshot.metadata ?? metadata)
|
||||
}
|
||||
})
|
||||
@@ -331,6 +334,8 @@ export async function bootstrapLazySession(options: SessionBootstrapOptions): Pr
|
||||
}
|
||||
|
||||
export async function bootstrapExistingSession(options: {
|
||||
reportStarted?: boolean
|
||||
exportSessionEnv?: boolean
|
||||
sessionId: string
|
||||
flavor: string
|
||||
startedBy?: SessionStartedBy
|
||||
@@ -371,9 +376,9 @@ export async function bootstrapExistingSession(options: {
|
||||
const session = api.sessionSyncClient(sessionInfo)
|
||||
session.updateMetadata(buildUpdatedMetadata)
|
||||
|
||||
exportHapiSessionEnv(sessionInfo.id)
|
||||
if (options.exportSessionEnv !== false) exportHapiSessionEnv(sessionInfo.id)
|
||||
|
||||
await reportSessionStarted(sessionInfo.id, metadata)
|
||||
if (options.reportStarted !== false) await reportSessionStarted(sessionInfo.id, metadata)
|
||||
|
||||
return {
|
||||
api,
|
||||
|
||||
Reference in New Issue
Block a user