{"version":3,"file":"hub.cjs","names":[],"sources":["../../src/types/hub.ts"],"sourcesContent":["import type { BridgeState, SessionFrame } from './session';\n\n/**\n * Wire vocabulary between the hub and its pages.\n *\n * One WebSocket carries every session: hub-level frames describe the set of\n * sessions, and session-scoped traffic travels enveloped with the session id.\n * Field naming follows @earendil-works/pi-protocol so a future swap to the\n * upstream session server stays a transport change, not a rename.\n */\nexport const HUB_PROTOCOL_VERSION = 2;\n\n/** Role marker in the health payload; po-server probes for it before binding the port. */\nexport const HUB_ROLE = 'hub';\n\n/** REST endpoint for admitting and listing durable workspaces. */\nexport const WORKSPACES_API_ROUTE = '/api/workspaces';\n\n/** REST endpoint for creating sessions and browsing resumable Pi history. */\nexport const SESSIONS_API_ROUTE = '/api/workspaces/:workspaceId/sessions';\n\n/** One durable repository workspace shown in the rail, even while it has no sessions. */\nexport interface WorkspaceSummary {\n  /** Server-owned backing scope for sessions shown without a workspace. */\n  kind?: 'session';\n  /** HTTP-only metadata, not sent on the v1 hub wire. */\n  instructions?: string;\n  id: string;\n  root: string;\n  /** Display name chosen when the workspace was added; the folder basename stands in when absent. */\n  name?: string;\n  /** A remembered workspace whose root could not be mounted on this server start. */\n  available?: boolean;\n  /** The sandbox provider id that runs this workspace; absent means it runs on this host. */\n  sandbox?: string;\n  /**\n   * The container's lifecycle as the host reports it. On a workspace that is not sandboxed,\n   * `unavailable` means the container provider cannot run here, with the cause in `sandboxReason`.\n   */\n  sandboxState?: WorkspaceSandboxState;\n  /** Plain-language cause for an unavailable or failed container. */\n  sandboxReason?: string;\n  error?: string;\n}\n\nexport const WORKSPACE_SANDBOX_STATES = ['starting', 'running', 'stopping', 'unavailable', 'failed'] as const;\nexport type WorkspaceSandboxState = (typeof WORKSPACE_SANDBOX_STATES)[number];\n\n/** One inactive Pi thread available to resume in a live session's workspace. */\nexport interface PiSessionHistoryItem {\n  id: string;\n  name?: string;\n  firstMessage: string;\n  createdAt: string;\n  updatedAt: string;\n}\n\n/** A session removed from History that can still be restored until `purgeAt` (both ISO 8601). */\nexport interface RemovedSessionItem extends PiSessionHistoryItem {\n  removedAt: string;\n  purgeAt: string;\n}\n\n/**\n * REST endpoint behind the new-session directory picker; the page sends the\n * typed path as ?q= and receives {directories}: the children of the parent\n * directory whose names match the trailing segment as a regular expression.\n */\nexport const DIRECTORIES_API_ROUTE = '/api/directories';\n\n/** Lists the visible child folders of ?path= (home when absent) for the workspace folder browser. */\nexport const DIRECTORY_CHILDREN_API_ROUTE = '/api/directories/children';\n\n/** Folders under home that already hold a `.po` folder, offered as workspaces during onboarding. */\nexport const PO_FOLDERS_API_ROUTE = '/api/directories/po';\n\n/** One folder's visible child directories, as absolute paths. */\nexport interface DirectoryListing {\n  path: string;\n  parent?: string;\n  directories: string[];\n}\n\n/**\n * Query parameter that routes a package API request to one session's server.\n * Without it the request is answered by a hub-scoped API in this process.\n */\nexport const API_SESSION_QUERY_PARAM = 'session';\n\n/** What the agent is doing right now, derived from its frame stream. */\nexport type SessionPhase = 'idle' | 'turn' | 'compaction' | 'retry';\n\nexport interface SessionProfile {\n  name: string;\n  displayName?: string;\n  /** Changes whenever the icon does; absent when the profile has no icon. */\n  iconVersion?: string;\n}\n\nexport interface SessionGitStatus {\n  branch: string;\n  /** True when the working tree has uncommitted changes; rendered as a star. */\n  dirty: boolean;\n}\n\n/** One immutable, signed client composition resolved for a session. */\nexport interface SessionWebComposition {\n  /** Stable identity of the synchronized root and generation. */\n  id: string;\n  /** Monotonic signing revision advertised by the manifest. */\n  revision: number;\n  /** Same-origin signed-manifest route read by the trusted service worker. */\n  manifestUrl: string;\n  /** Same-origin prefix for the untrusted source bytes verified by the worker. */\n  rawAssetBaseUrl: string;\n  /** Worker-owned prefix from which the page may execute verified bytes. */\n  verifiedAssetBaseUrl: string;\n  /** `[slot, entry]` per plugin copy this mount runs, each entry an absolute path below both asset prefixes. */\n  pluginEntries: [string, string][];\n  /** Absolute paths below both asset prefixes of every file this mount's slots can load. */\n  assetPaths: string[];\n  /** Absolute paths below both asset prefixes, replaced when this session is focused. */\n  stylePaths: string[];\n  /** Frame types owned by the matching session-local hub composition. */\n  channels: string[];\n  /**\n   * The slots this mount runs out of a shared build. Absent means the composition\n   * holds only this mount's plugins, as in-memory test hosts publish it.\n   */\n  plugins?: string[];\n}\n\n/** One immutable, signed native composition resolved for a session; read by po-native, ignored by the web. */\nexport interface SessionNativeComposition {\n  /** Stable identity of the synchronized root and generation. */\n  id: string;\n  scope: 'host' | 'workspace' | 'session';\n  /** Monotonic signing revision advertised by the manifest. */\n  revision: number;\n  manifestUrl: string;\n  rawAssetBaseUrl: string;\n  /** `[pluginId, modulePath]` for each plugin of this mount that built; the shell loads each on its own. */\n  pluginEntries: [string, string][];\n  /** Shared host UI entry in the same signed generation; absent on legacy hosts. */\n  uiEntry?: string;\n  channels: string[];\n  /** The `poNative.pluginId` values resolved for this mount; the shell installs only these. */\n  plugins: string[];\n}\n\n/**\n * Everything the rail needs to render one session without subscribing to it.\n */\nexport interface SessionSummary {\n  workspaceId?: string;\n  id: string;\n  name: string;\n  cwd: string;\n  /** ISO 8601, from the session's registry record. */\n  createdAt: string;\n  /** ISO 8601, bumped whenever the session's frame stream moves. */\n  updatedAt: string;\n  phase: SessionPhase;\n  /** ISO 8601 timestamp of the last phase change; drives \"running · 12m\". */\n  phaseSince: string;\n  /** The hub's own attachment to the session socket. */\n  attach: BridgeState;\n  /** Human-readable cause, present when attach is refused or closed. */\n  attachReason?: string;\n  pendingMessageCount: number;\n  /** True once prior work is observed; false may also mean unavailable history. */\n  everPrompted: boolean;\n  /** True while the agent waits on a dialog answer; \"waiting for your input\". */\n  awaitingInput: boolean;\n  /** ISO 8601 of the last settled run, once one finished. */\n  lastSettledAt?: string;\n  /** Authoritative owned work; null is unknown, absent is a legacy host. */\n  backgroundWorkActive?: boolean | null;\n  /** Omitted when the cwd is not a git repository or git is unavailable. */\n  git?: SessionGitStatus;\n  /** Selected profile; the icon itself is served by the session avatar route. */\n  profile?: SessionProfile;\n  /** Signed plugin composition independently resolved for this session. */\n  webComposition?: SessionWebComposition;\n  /** Signed native composition for this session, when native targets were built. */\n  nativeComposition?: SessionNativeComposition;\n  /**\n   * The session this one was spawned from, recorded by the hub when it opened the session.\n   * The rail nests a session under its parent; absent means a top-level row.\n   */\n  parentSessionId?: string;\n  /**\n   * The spawning package's own label for the relationship, such as \"worktree\".\n   * The hub does not interpret it; the rail uses it to pick an affordance.\n   */\n  sessionProvenance?: string;\n  /** User-assigned groups; sessions sharing one may message each other. Absent means none. */\n  groups?: string[];\n  /** Host reservations awaiting a durable child runtime, not live sessions. */\n  pendingSetups?: Array<{\n    id: string;\n    name: string;\n    createdAt: string;\n    cwd?: string;\n    status?: 'provisioning' | 'failed' | 'interrupted';\n    setupKind?: 'managed-worktree' | 'existing-directory';\n    errorCode?: 'SESSION_WORKTREE_PROVISION_FAILED' | 'SESSION_UNAVAILABLE';\n  }>;\n  /**\n   * One line an extension published about background work it runs for this\n   * session, such as a workflow; the rail shows it in place of the idle copy.\n   */\n  activity?: { label: string; attention?: boolean; since?: string };\n  /** Tool calls waiting for the person's approval in the Activity rail. */\n  pendingApprovalCount?: number;\n  /**\n   * The hub recorded this session but has not reopened it since its last\n   * restart. Its journal is on disk; nothing is running behind the card until\n   * the page asks for it.\n   */\n  dormant?: boolean;\n}\n\nexport const HUB_HELLO_TYPE = 'hub_hello';\n/** Hub-synthesized close for an answered dialog; Pi itself never announces one. */\nexport const DIALOG_ANSWERED_TYPE = 'extension_ui_answered';\n\n/**\n * The custom session entry the Po runtime journals with its mode\n * catalog projection; it arrives inside Pi's entry_appended frames. The shape\n * mirrors ModeProjection in po-mode.\n */\nexport const MODE_ENTRY_TYPE = 'po-modes';\n\n/**\n * The custom session entry the Po runtime journals when the agent's model\n * changes without a client having asked for it. The shape mirrors\n * AgentModelProjection in po-core.\n *\n * Pi reports a thinking-level switch on the wire, so that field follows from\n * the frame alone. It has no wire event for the model, so plan mode applying\n * its configured planning model would otherwise leave the chip naming the\n * model the session left behind.\n */\nexport const AGENT_MODEL_ENTRY_TYPE = 'po-agent-model';\n/**\n * The custom session entry Po journals describing what the session is\n * composed of: which mode admitted each tool and skill, and what each costs.\n *\n * Schemas are deliberately absent. Only names, kinds, owners and integer token\n * counts travel, so republishing the whole composition stays cheap.\n */\nexport const CONTEXT_ENTRY_TYPE = 'po-context';\n\n/**\n * The custom session entry po-profile journals naming the persona the\n * session speaks as. The shape mirrors ProfileIdentityProjection in\n * po-core.\n *\n * Unlike the entries above, this one is transcript rather than projection: it\n * stays in journal order and is never collapsed to the latest record, because a\n * message keeps the persona it was written under. Adding it to\n * PROJECTION_ENTRY_TYPES would repaint the whole transcript on every switch.\n */\nexport const PROFILE_IDENTITY_ENTRY_TYPE = 'po-profile-identity';\n/**\n * The custom session entry po-domain journals once Pi has rebuilt its\n * resource catalog for a reload; it mirrors PO_RESOURCE_CATALOG_ENTRY_TYPE in\n * po-core.\n *\n * A reload is what changes the skills the composer offers under `$`, and Pi\n * reports nothing else for one, so this entry is the cockpit's only notice that\n * the command list it cached belongs to the previous selection.\n */\nexport const RESOURCE_CATALOG_ENTRY_TYPE = 'po-resource-catalog';\nexport interface ModeActionProjection {\n  id: string;\n  label: string;\n  description: string;\n  enabled: boolean;\n  disabledReason?: string;\n  needsInput: boolean;\n}\n\nexport interface ModeRecordProjection {\n  id: string;\n  label: string;\n  description: string;\n  order: number;\n  activation: 'inactive' | 'activating' | 'active' | 'deactivating';\n  condition: string;\n  detail?: string;\n  actions: ModeActionProjection[];\n}\n\nexport interface ModeProjection {\n  version: 1;\n  revision: number;\n  modes: ModeRecordProjection[];\n}\n\nexport type ContextGroupKind = 'preset' | 'mode' | 'domain' | 'shared' | 'core';\nexport type ContextItemSource = 'extension' | 'mcp' | 'plugin' | 'core';\n\nexport interface ContextItemProjection {\n  name: string;\n  itemKind: 'tool' | 'skill';\n  source: ContextItemSource;\n  owner: string;\n  tokens: number;\n  active: boolean;\n}\n\nexport interface ContextGroupProjection {\n  id: string;\n  label: string;\n  kind: ContextGroupKind;\n  items: ContextItemProjection[];\n  /** What the group costs now: active items only. */\n  tokens: number;\n  /** What its gated items would add if switched on. */\n  inactiveTokens: number;\n}\n\nexport interface ContextProjection {\n  version: 1;\n  revision: number;\n  selection?: { preset: string; domains: string[]; profile?: string };\n  groups: ContextGroupProjection[];\n  totalTokens: number;\n  inactiveTokens: number;\n  /**\n   * What the assembled system prompt costs, deliberately outside the groups.\n   *\n   * Every tool's prose and every skill's listing already count inside\n   * `totalTokens`, and those are slices of this same text, so the two figures\n   * overlap and must not be added. `stage` is `base` when the session has sent\n   * nothing yet and the prompt shown is the one before packages patch it.\n   */\n  systemPrompt?: { tokens: number; stage: 'base' | 'effective' };\n  /** Names the tokenizer, because the figures are indicative, not billed. */\n  estimator: string;\n}\nexport const SESSION_COMMAND_TYPE = 'session_command';\n/** A page asks for the transcript before what it already holds. */\nexport const HISTORY_REQUEST_TYPE = 'history_request';\n/** One older window, oldest first, answering a history_request. */\nexport const HISTORY_PAGE_TYPE = 'history_page';\n\n/**\n * How many journalled messages one page carries. Small enough that prepending\n * a window never blocks the reader's scroll, large enough that a flick through\n * a long transcript does not turn into a hundred round trips.\n */\nexport const HISTORY_PAGE_SIZE = 100;\n\nexport interface HistoryRequestFrame {\n  type: typeof HISTORY_REQUEST_TYPE;\n  sessionId: string;\n  /** Journal id of the oldest entry the page holds; absent asks for the newest window. */\n  before?: string;\n  limit?: number;\n}\n\nexport interface HistoryPageFrame {\n  type: typeof HISTORY_PAGE_TYPE;\n  sessionId: string;\n  /** Entry frames, oldest first, to prepend above what the page holds. */\n  frames: Record<string, unknown>[];\n  /** The cursor for the next older window; null when the transcript starts here. */\n  cursor: string | null;\n  /** Whether anything older than this window exists. */\n  hasMore: boolean;\n  /** Echoed so a page can drop an answer to a question it has since abandoned. */\n  before?: string;\n}\n\n/** First frame on every page socket, before the snapshot. */\nexport interface HubHelloFrame {\n  type: typeof HUB_HELLO_TYPE;\n  protocol: number;\n  /** Frame types of the hub's loaded data channels; lets a panel tell \"plugin server not installed\" from \"no data\". */\n  channels: string[];\n}\n\n/** One command frame from the page, addressed to a session's agent. */\nexport interface SessionCommandFrame {\n  type: typeof SESSION_COMMAND_TYPE;\n  sessionId: string;\n  frame: SessionFrame;\n}\n\nexport function hubHello(channels: string[]): HubHelloFrame {\n  return { type: HUB_HELLO_TYPE, protocol: HUB_PROTOCOL_VERSION, channels };\n}\n\nexport function sessionCommand(sessionId: string, frame: SessionFrame): SessionCommandFrame {\n  return { type: SESSION_COMMAND_TYPE, sessionId, frame };\n}\n"],"mappings":";;;;;;;;;AAUA,MAAa,uBAAuB;;AAGpC,MAAa,WAAW;;AAGxB,MAAa,uBAAuB;;AAGpC,MAAa,qBAAqB;AA0BlC,MAAa,2BAA2B;CAAC;CAAY;CAAW;CAAY;CAAe;AAAQ;;;;;;AAuBnG,MAAa,wBAAwB;;AAGrC,MAAa,+BAA+B;;AAG5C,MAAa,uBAAuB;;;;;AAapC,MAAa,0BAA0B;AAwIvC,MAAa,iBAAiB;;AAE9B,MAAa,uBAAuB;;;;;;AAOpC,MAAa,kBAAkB;;;;;;;;;;;AAY/B,MAAa,yBAAyB;;;;;;;;AAQtC,MAAa,qBAAqB;;;;;;;;;;;AAYlC,MAAa,8BAA8B;;;;;;;;;;AAU3C,MAAa,8BAA8B;AAqE3C,MAAa,uBAAuB;;AAEpC,MAAa,uBAAuB;;AAEpC,MAAa,oBAAoB;;;;;;AAOjC,MAAa,oBAAoB;AAsCjC,SAAgB,SAAS,UAAmC;CAC1D,OAAO;EAAE,MAAM;EAAgB,UAAA;EAAgC;CAAS;AAC1E;AAEA,SAAgB,eAAe,WAAmB,OAA0C;CAC1F,OAAO;EAAE,MAAM;EAAsB;EAAW;CAAM;AACxD"}