Skip to content

refactor(hub-zero): T5c-ii move agent-run machinery out of packages/chat (CL-8173) - #770

Merged
TheGreatAxios merged 5 commits into
mainfrom
cl-8173-t5c-ii
Sep 17, 2026
Merged

TheGreatAxios merged 5 commits into
mainfrom
cl-8173-t5c-ii

Conversation

@TheGreatAxios

Copy link
Copy Markdown
Contributor

Summary

Continues T5c: relocating agent-run machinery out of packages/chat.

  • Grant-conditions registry → apps/hub/src/grant-conditions.ts
  • Turn machinery (agent-turns, chat-orchestrator, client-ids, turn-claims, turn-mail-correlation, turn-queue, write-claims) → packages/agent-runtime
  • Artifact delivery → packages/agent-runtime (beside the turn loop)
  • No-op inference stub → the hub's own e2e wiring

These moved modules still write to the chat.* tables (chat_settings, chat_room_messages/timeline events, etc.) via the ChatStore/room-message deps injected into them — the tables stayed put; only the code moved.

Skipped (scope note)

Two moves from the original T5c-ii ask are not in this PR — both turned out to be more than a pure relocation:

  • settleConnectedService (packages/chat/src/connect-pending.ts, not platform-adapter.ts as filed) settles pending connector cards by calling into postRoomMessage, dispatchTurn, ChatStore, workbench-settings, blocks, mentions, and agent-address — all packages/chat internals. packages/connections is a dependency of packages/chat today (chat depends on connections, not the reverse); moving this function there as-is would require connections to import chat, introducing a package cycle. Doing it properly needs either a smaller structural interface this function can depend on, or moving it somewhere both packages can reach — a design decision, not a relocation.
  • Workflow-participant routes + idle-sleep lifecycle (packages/chat/src/workflow-participant-routes.ts, and the idle-sleep wiring in packages/chat/src/platform-adapter.ts) are saturated with chat internals (ChatStore, workbench-service's launchAndJoinAgent/sendWorkbenchMessage, parts, blocks, connect-pending, mail-headers, room-messages). Moving this into packages/agent-runtime with zero @corbits/chat import means either moving most of packages/chat along with it, or redesigning these routes against a narrower structural dependency shape — real design work, not a same-day relocation.

Filing these as follow-up scope rather than forcing an incomplete/behavior-risking move under this PR.

Test plan

  • bun run typecheck
  • bun run lint
  • bun run check:structural
  • Rebased onto origin/main

@linear-code

linear-code Bot commented Sep 17, 2026

Copy link
Copy Markdown

CL-8173

The hub built its `ConditionRegistry` inline beside chat's grant store
and threaded it through ~20 mounts under a chat-flavoured name, though
nothing in it is chat-specific: `time_window` is `@intx/authz`'s own
evaluator, the same default `mountHubRoutes` builds when no registry is
supplied.

It now lives in `apps/hub/src/grant-conditions.ts` as
`grantConditionRegistry`, with every mount updated. No behavior change.

Claude-Session: https://claude.ai/code/session_01RweuMUskU2nvcFhdckc7EG
Turn intake, the turn queue and its claims, the finalized-turn write
claims, the client-id ledger and the turn/mail correlation store are the
agent run loop, not the chat surface. They now live in
`@corbits/agent-runtime` alongside the run definition builder that
already lived there; `packages/chat` and `apps/hub` consume them from
there.

Relocation only: each module keeps its behavior and, for now, the
`chat.*` tables it already wrote (`chat.agent_turns`,
`chat.finalized_turn_write_claim`, `chat.message_client_ids`,
`chat.turn_mail_correlation`), reached through the new
`@corbits/chat/schema` subpath. Replacing those with native
`session_mail`/run state is the next slice.

Claude-Session: https://claude.ai/code/session_01RweuMUskU2nvcFhdckc7EG
`artifact-delivery.ts` maps a finalized turn's persisted-artifact facts
onto the file-part wire shape. Its only consumer is the turn
orchestrator, which now lives in `@corbits/agent-runtime`, so the module
follows it there. Recognition stays in `@corbits/turn-artifacts` as
before.

Claude-Session: https://claude.ai/code/session_01RweuMUskU2nvcFhdckc7EG
The stub inference routes exist for the `E2E_PROVIDER`-unset path, which
the hub mounts and nothing else consumes. They now sit with the hub, at
`apps/hub/src/e2e/noop-inference.ts`, rather than shipping as part of the
chat package's public surface.

Claude-Session: https://claude.ai/code/session_01RweuMUskU2nvcFhdckc7EG
A rebase conflict with origin/main's removal of CreateWorkflowAuthorRegistryDeps's deployer field left a stray deployer: workflowDeployer line; drop it, and take origin/main's bun.lock refreshed via bun install.
@TheGreatAxios
TheGreatAxios merged commit 11dffc4 into main Sep 17, 2026
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant