Skip to content

refactor(programs): B2a move-only — shared helpers, bindings, program run data - #1342

Merged
gewenyu99 merged 11 commits into
posthog/functional-b1-prfrom
posthog/functional-b2-move
Sep 24, 2026
Merged

gewenyu99 merged 11 commits into
posthog/functional-b1-prfrom
posthog/functional-b2-move

Conversation

@gewenyu99

@gewenyu99 gewenyu99 commented Sep 24, 2026 •

Copy link
Copy Markdown
Collaborator

Scope: Moves only. Behavior preserved.

Problem

The callable program host (#1307) mixed pure code moves with behavior changes, which made it too large to review. This PR takes the moves out so #1307 shows only the host changes.

Stack: #1306 → this PR → #1307 → #1308 → #1309.

Changes

These are pure moves and extractions. Each old site re-exports what moved, so no caller changes and no behavior changes.

  • Shared leaves:
    • shared/utils/cleanup-registry.ts (from wizard-abort.ts)
    • shared/scan-consent.ts (from wizard-session.ts)
    • shared/run-tags.ts and its test (from agent-interface.ts)
    • shared/ask-policy.ts (from bootstrap.ts and wizard-ask-bridge.ts)
  • Auth helpers:
    • shared/utils/oauth-token.ts (from oauth.ts)
    • shared/gateway-auth.ts (from agent/gateway-session.ts)
  • File watcher: lib/file-watcher.ts → shared/file-watcher.ts, as a rename. This drops two allowlist rows.
  • Other moves:
    • shared/self-driving-pricing.ts (from the TUI deck)
    • agent/tools/tool-names.ts (from tools.ts)
  • Program run data: the run data for eight programs (agent-skill, ai-observability, mcp-analytics, metrics, migration, replay-vision, revenue-analytics, web-analytics-doctor) moves out of each index.ts into run.ts, abort-cases.ts and run-definition.ts.

Test plan

  • pnpm typecheck, pnpm lint (0 errors) and pnpm vitest run (3,361 tests) pass at every commit. The architecture test passes, and the allowlist only loses rows.
  • Loaded all eight programs before and after, and compared their exports, configs, abort-case patterns and prompt output. They match exactly.

Created with PostHog Desktop

… into shared

Four stateless leaves move into src/shared with no behavior change:
the cleanup registry out of wizard-abort, the scan-consent helpers and
DiscoveredFeature out of the session, buildRunTags out of the agent
interface, and the ask policy and longer ask timeout out of the runner
bootstrap and the ask bridge. Each old module re-exports what it gave up,
so shouldDisableAsk and every other existing import keeps working. The
run-tags test moves with its function.

Generated-By: PostHog Desktop
Task-Id: d14e92bb-6ee1-49b5-8502-39cb80079589
OAuthTokenResponseSchema, getOAuthClientId and refreshAccessToken need no
UI, so they move from utils/oauth.ts into utils/oauth-token.ts with no
behavior change. oauth.ts imports what its login flow uses and re-exports
the schema, its type and refreshAccessToken for existing callers.

Generated-By: PostHog Desktop
Task-Id: d14e92bb-6ee1-49b5-8502-39cb80079589
…y-auth

GatewayAuth, isPastRefresh, isTrustedGatewayUrl and
buildWizardPropertiesBlob hold no mint state, so they move verbatim from
agent/gateway-session.ts into shared/gateway-auth.ts. The mint, its cache
and the CI credential loading stay where they are. gateway-session.ts
imports what the mint uses and re-exports all four, so no caller changes.

Generated-By: PostHog Desktop
Task-Id: d14e92bb-6ee1-49b5-8502-39cb80079589
src/lib/file-watcher.ts moves unchanged to src/shared/file-watcher.ts.
The audit ledger watcher, the event-plan watcher and the TUI hook import
it from @shared, which drops two programs-to-legacy rows from the
architecture allowlist.

Generated-By: PostHog Desktop
Task-Id: d14e92bb-6ee1-49b5-8502-39cb80079589
The pricing constants move unchanged from the self-driving deck into
shared/self-driving-pricing.ts. The deck's pricing.ts re-exports them,
so its importers keep their paths.

Generated-By: PostHog Desktop
Task-Id: d14e92bb-6ee1-49b5-8502-39cb80079589
SERVER_NAME and WIZARD_TOOL_NAMES move unchanged from tools/tools.ts into
tools/tool-names.ts, a data-only module. tools.ts re-exports both, so
every importer keeps its path.

Generated-By: PostHog Desktop
Task-Id: d14e92bb-6ee1-49b5-8502-39cb80079589
…ules

Eight programs keep their run definitions, skill options and abort cases
in their index or detect files. That data now lives in run.ts,
abort-cases.ts and agent-skill/run-definition.ts, and each index imports
it. The data is unchanged: every exported config, prompt and abort case
resolves to the same values as before. The old modules re-export
SkillProgramOptions and each abort-case list, so importers keep their
paths.

Generated-By: PostHog Desktop
Task-Id: d14e92bb-6ee1-49b5-8502-39cb80079589
Generated-By: PostHog Desktop
Task-Id: d14e92bb-6ee1-49b5-8502-39cb80079589
@github-actions

Copy link
Copy Markdown

🧙 Wizard CI

Run the Wizard CI and test your changes against wizard-workbench example apps by replying with a GitHub comment using one of the following commands:

Test all apps:

  • /wizard-ci all

Test all apps in a directory:

  • /wizard-ci ai-observability
  • /wizard-ci basic-integration
  • /wizard-ci feature-flags
  • /wizard-ci mcp-analytics
  • /wizard-ci replay-vision
  • /wizard-ci revenue
  • /wizard-ci self-driving
  • /wizard-ci warehouse
  • /wizard-ci warehouse-seeded

Test an individual app:

  • /wizard-ci ai-observability/anthropic
  • /wizard-ci ai-observability/google-adk
  • /wizard-ci ai-observability/groq
Show more apps
  • /wizard-ci ai-observability/manual-capture
  • /wizard-ci ai-observability/openai
  • /wizard-ci ai-observability/openai-agents
  • /wizard-ci ai-observability/opentelemetry
  • /wizard-ci ai-observability/vercel-ai
  • /wizard-ci basic-integration/android
  • /wizard-ci basic-integration/angular
  • /wizard-ci basic-integration/astro
  • /wizard-ci basic-integration/django
  • /wizard-ci basic-integration/fastapi
  • /wizard-ci basic-integration/flask
  • /wizard-ci basic-integration/flutter
  • /wizard-ci basic-integration/javascript-node
  • /wizard-ci basic-integration/javascript-web
  • /wizard-ci basic-integration/laravel
  • /wizard-ci basic-integration/next-js
  • /wizard-ci basic-integration/nuxt
  • /wizard-ci basic-integration/python
  • /wizard-ci basic-integration/rails
  • /wizard-ci basic-integration/react-native
  • /wizard-ci basic-integration/react-router
  • /wizard-ci basic-integration/sveltekit
  • /wizard-ci basic-integration/swift
  • /wizard-ci basic-integration/tanstack-router
  • /wizard-ci basic-integration/tanstack-start
  • /wizard-ci basic-integration/vue
  • /wizard-ci feature-flags/django
  • /wizard-ci feature-flags/next-js
  • /wizard-ci mcp-analytics/custom-dispatcher
  • /wizard-ci mcp-analytics/typescript-sdk
  • /wizard-ci replay-vision/javascript-node
  • /wizard-ci replay-vision/next-js
  • /wizard-ci replay-vision/react-vite
  • /wizard-ci revenue/stripe
  • /wizard-ci self-driving/astro
  • /wizard-ci self-driving/fastapi
  • /wizard-ci self-driving/nuxt
  • /wizard-ci self-driving/react-router
  • /wizard-ci self-driving/sveltekit
  • /wizard-ci warehouse/monorepo-env
  • /wizard-ci warehouse/multi-source-next
  • /wizard-ci warehouse/stripe-node
  • /wizard-ci warehouse/zero-source
  • /wizard-ci warehouse-seeded/next-stripe
  • /wizard-ci warehouse-seeded/next-stripe-declined

Test against a Context Mill branch:

  • /wizard-ci all context-mill:my-branch

Add context-mill:<branch> to any command above to pin the Context Mill branch. It defaults to main.

Results will be posted here when complete.

@gewenyu99 gewenyu99 changed the title refactor(programs): WIP move shared leaves and program run data (B2 code move) refactor(programs): B2a move-only — shared helpers, bindings, program run data Sep 24, 2026
Move program routing out of the agent:
- PROGRAM_BINDINGS and resolveProgramBinding go to src/programs/binding.ts.
- The flag experiments move from src/agent/runner/switchboard/flags to
  src/programs/experiments, with their tests.
- The program-axis commandments go to src/programs/commandments.ts, and
  the switchboard telemetry to src/programs/binding-telemetry.ts.
- The switchboard and variant-gating tests move to src/programs.
- DEFAULT_AGENT_BINDING, in src/agent/default-binding.ts, is the route
  standalone callers pass.

RunConfig drops switchboard. The caller passes what it already resolved:
programCommandments, stageOverrides, seededTasksEnabled and
binding.roleBindings. The orchestrator reads the role routes and the
stage and seeded-task policy from them. Pi assembles the supplied
commandments on both sequences, and Anthropic on task runs. Anthropic's
linear run looked guidance up by the run label, which names no program,
so it still gets none. The agent's resolveBinding and resolveHarness take
the base binding and the flag route as data.

Behavior is unchanged. For every program, across 22 flag and CLI cases,
in dev, production and cloud-surface builds, the resolved binding, trace,
role routes, stage overrides, seeded-task gate and commandments match the
previous code.

Generated-By: PostHog Desktop
Task-Id: d14e92bb-6ee1-49b5-8502-39cb80079589
resolveHarness and resolveRoleHarness move from switchboard/harness.ts
to switchboard/resolve-harness.ts, so harness.ts holds only the
registry. The three-step middleware chain becomes straight-line code
with the same precedence: binding, then the flag route, then the
dev-build CLI model and harness overrides. The traces and log line are
unchanged.

HARNESS_RUNS_TASKS records which backends implement runTask, and the
sequence capability clamp reads it through harnessRunsTasks instead of
asking the live registry. Both backends implement runTask, so the clamp
decides the same way. A registry test keeps the table in step with
HARNESS_OPTIONS. The DEFAULT_BINDING alias goes, and the sequence
resolver reads DEFAULT_AGENT_BINDING.

Generated-By: PostHog Desktop
Task-Id: d14e92bb-6ee1-49b5-8502-39cb80079589
resolveProgramBinding now resolves the sequence itself, so programs own
the whole binding precedence. The agent keeps the harness axis. The
middleware chain becomes straight-line code with the same order: the
composed clamp, the dev-build CLI override, the runTask capability
clamp, the flag route, the sequence experiment, then the base binding.
The traces and log lines are unchanged.

The agent's switchboard keeps the registries, resolveHarness,
resolveRoleHarness and harnessRunsTasks. It drops resolveBinding,
resolveSequence, runChain, and the flagSequence and orchestratorFlagOn
context fields, which only programs read. @agent exports harnessRunsTasks
beside resolveHarness in place of resolveBinding.

Generated-By: PostHog Desktop
Task-Id: d14e92bb-6ee1-49b5-8502-39cb80079589
@gewenyu99
gewenyu99 merged commit ef5ee43 into posthog/functional-b1-pr Sep 24, 2026
12 checks passed
@gewenyu99
gewenyu99 deleted the posthog/functional-b2-move branch September 24, 2026 20:58
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