Skip to content

Extract misfiled code out of packages/folded-runs - #294

Merged
TheGreatAxios merged 3 commits into
mainfrom
cl-folded-runs-extract
Aug 22, 2026
Merged

Extract misfiled code out of packages/folded-runs#294
TheGreatAxios merged 3 commits into
mainfrom
cl-folded-runs-extract

Conversation

@TheGreatAxios

Copy link
Copy Markdown
Contributor

Summary

Two independent reviews found that packages/folded-runs is not the ~1,000
line "renders source from a stored projection" package its description
suggests — it's 2,806 source LOC across 13 files, of which only
definition.ts (~342 LOC) actually reads the folded projection. The rest is
real domain logic that has nothing to do with folded runs and was simply
misfiled. This PR moves the three misfiled slices out, as a pure refactor
with zero behavior change. It does not touch definition.ts itself — a
later epic wants to delete the foldedBody-reading slice, and that's blocked
and out of scope here.

  • @corbits/agent-eventsconnectorReplyContent, inferenceDoneBlocks,
    toolDoneResult, messageRunStarted, messageRunEnded: recognizers for
    sidecar agent.event frames. Zero dependencies (didn't import anything
    before the move either), so trivially browser-safe. Actual importers,
    verified by reading the import graph rather than trusting grep-for-mentions:
    packages/chat/src/chat-orchestrator.ts and
    packages/tasks/src/orchestrator.ts. (chat-ui, slack-tag, github-tools, and
    workflows/workbench-digest only mention these functions in comments — they
    don't import them. slack-tag even carries its own mirrored copy of
    connectorReplyContent rather than importing the real one.)
  • @corbits/folded-run-one-shotrunOneShotFoldedPrompt, a synchronous
    request/reply runner over one folded run's opening turn with teardown on
    every exit path. Depends on @corbits/folded-runs' public exports
    (readDefinitionProjection, readFoldedBody, launchFoldedRun,
    sendFoldedMailWithRetry, CryptoProviderCache, FoldedRunsDeps) and on
    the new @corbits/agent-events. Consumed by @corbits/routines and
    @corbits/task-planner directly; apps/hub/src/index.ts's 4 call sites
    already went through @corbits/task-planner's re-export barrel (not
    @corbits/folded-runs directly), so hub's import of the function itself
    needed no change.
  • @corbits/run-scopecreateTopLevelRunRoutes, listTopLevelRuns,
    listTopLevelRunFires: the HTTP route answering "which of this tenant's
    workflow runs are genuine top-level deployments," mounted once in
    apps/hub/src/index.ts. Its only folded-run-specific coupling is a
    NOT EXISTS/LEFT JOIN against folded_run, now read through
    @corbits/folded-runs' public foldedRun export.

All 18 external importer files and 8 package.json workspace deps are
repointed at the new packages. No re-export shim is left in folded-runs.
folded-runs' own package.json drops hono, @corbits/agent-lifecycle,
and @intx/log — each was only used by one of the three moved slices — and
gains a "./migrations" export subpath so the relocated
run-scope/test/scope-routes.drizzle.test.tscan reachapplyFoldedRunsMigrationsthrough the package boundary instead of a relativesrc` import.

Before/after LOC (packages/folded-runs/src, non-test):
2,806 → 1,986. Split out: agent-events 173, folded-run-one-shot 278,
run-scope 338 (small deltas from header-comment path updates, index.ts
barrels).

Known wart, not touched: scripts/db-setup.ts:32-34 imports
applyFoldedRunsMigrations/backfillFoldedRunMarkers from
packages/folded-runs/src/migrations by relative path, bypassing the
package's own exports map. migrations.ts never moved, so this import is
unaffected by this PR — flagging per the review, not fixing here.

Bug spotted, deliberately not fixed: none found in the moved code itself
— this was a pure location change with no logic edits.

Test plan

  • bun run check (typecheck, lint, tests, all repo checks incl.
    check:licenses and check:browser-safe-subpaths) passes clean from
    the repo root.
  • bunx prettier --write over every changed file (no-op — already
    formatted).
  • Verified no stale imports of the moved symbols remain anywhere under
    apps/, packages/, workflows/, scripts/.

…from folded-runs

packages/folded-runs was 2,806 source LOC across 13 files, but only
definition.ts (~342 LOC) reads the folded projection its name promises;
the rest is unrelated domain logic that happened to land there. Move
the three misfiled slices to their own packages, pure refactor, no
behavior change:

- @corbits/agent-events: the sidecar agent.event parsers
  (connectorReplyContent, inferenceDoneBlocks, toolDoneResult,
  messageRunStarted, messageRunEnded). Zero dependencies, so trivially
  browser-safe.
- @corbits/folded-run-one-shot: runOneShotFoldedPrompt, the
  synchronous request/reply runner over one folded run's opening turn.
- @corbits/run-scope: createTopLevelRunRoutes and the top-level-run
  queries, an HTTP route with nothing to do with folded-run lifecycle
  beyond excluding folded rows.

All 18 external importer files and 8 package.json workspace deps are
repointed at the new packages; no re-export shim is left behind in
folded-runs. folded-runs gains a "./migrations" export subpath so
run-scope's own drizzle test can reach applyFoldedRunsMigrations
through the package boundary instead of a relative src import.
runOneShotFoldedPrompt, scope-routes.ts, and agent-events.ts moved to
@corbits/folded-run-one-shot, @corbits/run-scope, and
@corbits/agent-events respectively.
@TheGreatAxios
TheGreatAxios force-pushed the cl-folded-runs-extract branch from a6dd7bb to fa24973 Compare August 22, 2026 04:09
scripts/e2e/folded-run-backfill.test.ts reached listTopLevelRuns through
a relative path into folded-runs' src, bypassing the package's exports
map, so repointing the package importers did not move it and the
walking-skeleton run failed to resolve the module.

scripts/db-setup.ts reaches applyFoldedRunsMigrations the same way and
is left alone here: folded-runs still owns migrations, and that import
is called out separately in this PR.
@TheGreatAxios
TheGreatAxios merged commit a823376 into main Aug 22, 2026
5 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