Skip to content

feat: compile-time feature flag for preview/GA consolidation#1341

Open
jesseturner21 wants to merge 12 commits into
mainfrom
feature/preview-feature-flag
Open

feat: compile-time feature flag for preview/GA consolidation#1341
jesseturner21 wants to merge 12 commits into
mainfrom
feature/preview-feature-flag

Conversation

@jesseturner21
Copy link
Copy Markdown
Contributor

@jesseturner21 jesseturner21 commented May 21, 2026

Summary

Consolidates the main and preview branches into a single branch using a compile-time feature flag. npm run bundle now produces two tarballs from the same source:

  • GA tarball — public customers, all harness features stripped via dead code elimination
  • Preview tarball — preview customers, full harness functionality enabled

This eliminates the merge-conflict-prone dual-branch workflow while ensuring GA customers never see unreleased features.

How it works

  1. src/cli/feature-flags.ts exports isPreviewEnabled() backed by a __PREVIEW__ constant
  2. esbuild's define block replaces __PREVIEW__ with true or false at bundle time
  3. When false, esbuild's minifier eliminates all dead code paths — GA bundles contain zero harness logic
  4. All harness command registrations, TUI screens, deploy paths, and invoke options are gated behind the flag

Changes

Feature flag infrastructure

  • src/cli/feature-flags.ts — wrapper function for compile-time constant
  • esbuild.config.mjsdefine: { __PREVIEW__: process.env.BUILD_PREVIEW === '1' ? 'true' : 'false' }
  • vitest.config.ts — matching define for test environments
  • scripts/bundle.mjs — produces dual tarballs (GA build, then BUILD_PREVIEW=1 rebuild)

Command gating

  • invoke/command.tsx — 13 harness options (--harness, --harness-arn, --model-id, etc.) conditionally registered
  • create/command.tsx — 8 harness options (--model-id, --api-key-arn, --truncation-strategy, etc.) conditionally registered
  • cli.tsadd tool / remove tool commands gated
  • primitives/registry.tsharnessPrimitive conditionally instantiated

TUI gating

  • useCreateFlow.ts — type selector (Harness/Agent/Skip) only shown in preview
  • useInvokeFlow.ts — harness targets only displayed in preview
  • dev/command.tsx — harness deploy + invoke flow gated

Bug fixes (found during testing)

  • Orphaned memory on harness removalremove harness now also removes the associated <name>Memory entry
  • Deploy preflight rejected harness-only projects — added hasHarnesses to the resource check
  • TUI dev mode skipped deployment — auto-deploy before harness invoke
  • Deploy-to-harness transition didn't re-render — use queueMicrotask + setMode
  • Harness teardown on stack destroy — imperative deletion before CFN stack removal
  • Invoke hint renderingisHint check after isExec to preserve magenta exec styling

Tests

  • src/cli/__tests__/preview-flag.test.ts — verifies dead code elimination in both builds
  • integ-tests/add-remove-harness.test.ts — harness lifecycle + memory cleanup + re-add after removal
  • Harness integration/e2e tests properly skip in GA builds (BUILD_PREVIEW=1 guard)

Verification

Extensively tested with parallel subagents across CLI, TUI, and AWS deployment:

Scenario Result
GA: invoke --help shows no harness options
GA: create --help shows no harness options
GA: add --help shows no harness/tool subcommands
GA: BUILD_PREVIEW=1 env var cannot bypass flag
GA: TUI create goes straight to project name (no type selector)
Preview: full harness TUI wizard (name → model → env → memory → confirm)
Preview: deploy harness-only project to AWS
Preview: invoke harness via TUI with session continuity
Preview: invoke harness via CLI --harness flag
Preview: remove harness cleans up memory
Preview: re-add harness after removal (no duplicate error)
All 4069 unit tests pass
All 16 harness integration tests pass (BUILD_PREVIEW=1)
CI: build, lint, format, typecheck, e2e, CodeQL all green

…lidation

Replace the dual-branch (main/preview) workflow with a single branch using
a compile-time __PREVIEW__ constant. esbuild's define block replaces the
constant at build time, enabling dead code elimination for GA builds while
keeping all harness/preview code in the same source tree.

Key changes:
- Add src/cli/feature-flags.ts with isPreviewEnabled() wrapper
- Configure esbuild define block and vitest define for __PREVIEW__
- Gate harness commands (add tool, remove tool/harness) behind isPreviewEnabled()
- Gate harness UI screens and create flow behind the flag
- Add globalThis shim in index.ts for tsx dev mode
- Update bundle.mjs to produce dual tarballs (GA + preview)
- Support ESBUILD_OUTFILE env var for isolated test builds
- Port all harness-related source files from preview branch
- Add preview-flag.test.ts verifying dead code elimination
@jesseturner21 jesseturner21 requested a review from a team May 21, 2026 13:24
@github-actions github-actions Bot added the size/xl PR size: XL label May 21, 2026
@agentcore-devx-automation agentcore-devx-automation Bot added the claude-security-reviewing Claude Code /security-review in progress label May 21, 2026
@github-actions github-actions Bot added the agentcore-harness-reviewing AgentCore Harness review in progress label May 21, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Package Tarball

aws-agentcore-0.14.1.tgz

How to install

gh release download pr-1341-tarball --repo aws/agentcore-cli --pattern "*.tgz" --dir /tmp/pr-tarball
npm install -g /tmp/pr-tarball/aws-agentcore-0.14.1.tgz

@agentcore-devx-automation
Copy link
Copy Markdown
Contributor

Claude Security Review: the review run failed before completing. See the run for details.

@agentcore-devx-automation agentcore-devx-automation Bot removed the claude-security-reviewing Claude Code /security-review in progress label May 21, 2026
Prettier requires unquoted object keys when valid identifiers.
@github-actions github-actions Bot added size/xl PR size: XL and removed size/xl PR size: XL labels May 21, 2026
@agentcore-devx-automation agentcore-devx-automation Bot added the claude-security-reviewing Claude Code /security-review in progress label May 21, 2026
@github-actions github-actions Bot removed the agentcore-harness-reviewing AgentCore Harness review in progress label May 21, 2026
@agentcore-devx-automation
Copy link
Copy Markdown
Contributor

Claude Security Review: the review run failed before completing. See the run for details.

@agentcore-devx-automation agentcore-devx-automation Bot removed the claude-security-reviewing Claude Code /security-review in progress label May 21, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 21, 2026

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 42.17% 9777 / 23182
🔵 Statements 41.42% 10383 / 25062
🔵 Functions 39.62% 1691 / 4268
🔵 Branches 38.68% 6313 / 16317
Generated in workflow #3205 for commit dad4319 by the Vitest Coverage Report Action

Harness features are gated behind BUILD_PREVIEW=1 and eliminated from
GA bundles. Integration and e2e tests that exercise harness commands
must skip when running against the default (GA) build.
@github-actions github-actions Bot removed the size/xl PR size: XL label May 21, 2026
@github-actions github-actions Bot added the size/xl PR size: XL label May 21, 2026
@agentcore-devx-automation agentcore-devx-automation Bot added the claude-security-reviewing Claude Code /security-review in progress label May 21, 2026
@agentcore-devx-automation
Copy link
Copy Markdown
Contributor

Claude Security Review: the review run failed before completing. See the run for details.

@agentcore-devx-automation agentcore-devx-automation Bot removed the claude-security-reviewing Claude Code /security-review in progress label May 21, 2026
…mory cleanup

- Wrap harness-related CLI options in invoke command behind isPreviewEnabled()
  so they don't leak into GA build's --help output
- Wrap harness-related CLI options in create command behind isPreviewEnabled()
- Fix remove harness leaving orphaned memory entries in agentcore.json
- Fix deploy preflight rejecting harness-only projects
- Add integration test for harness re-add after removal
@github-actions github-actions Bot added size/xl PR size: XL and removed size/xl PR size: XL labels May 21, 2026
@agentcore-devx-automation agentcore-devx-automation Bot added the claude-security-reviewing Claude Code /security-review in progress label May 21, 2026
@agentcore-devx-automation
Copy link
Copy Markdown
Contributor

Claude Security Review: the review run failed before completing. See the run for details.

@agentcore-devx-automation agentcore-devx-automation Bot removed the claude-security-reviewing Claude Code /security-review in progress label May 21, 2026
- isHint check now comes after isExec (matching preview branch) so
  exec messages always render as magenta, not gray
- When a project has both runtimes and harnesses and no flag is given,
  show a clear error listing both --runtime and --harness options
@github-actions github-actions Bot removed the size/xl PR size: XL label May 21, 2026
@github-actions github-actions Bot added the size/xl PR size: XL label May 21, 2026
@agentcore-devx-automation agentcore-devx-automation Bot added the claude-security-reviewing Claude Code /security-review in progress label May 21, 2026
@agentcore-devx-automation
Copy link
Copy Markdown
Contributor

Claude Security Review: the review run failed before completing. See the run for details.

@agentcore-devx-automation agentcore-devx-automation Bot removed the claude-security-reviewing Claude Code /security-review in progress label May 21, 2026
The browser in `agentcore dev` could not invoke harnesses because the
/invocations POST handler never checked for harnessName in the request
body. Add early routing to handleHarnessInvocation when present.

The deploy progress box was missing because useDevDeploy did not pass
verbose: true or onResourceEvent to handleDeploy, so the switchableIoHost
was never created and CloudFormation messages never reached the TUI.

Constraint: handleHarnessInvocation handler already existed but was unreachable
Rejected: Adding a separate /harness-invocations endpoint | breaks frontend contract
Confidence: high
Scope-risk: narrow
@github-actions github-actions Bot removed the size/xl PR size: XL label May 22, 2026
@github-actions github-actions Bot added the size/xl PR size: XL label May 22, 2026
@agentcore-devx-automation agentcore-devx-automation Bot added the claude-security-reviewing Claude Code /security-review in progress label May 22, 2026
@agentcore-devx-automation
Copy link
Copy Markdown
Contributor

Claude Security Review: no high-confidence findings. (run)

@agentcore-devx-automation agentcore-devx-automation Bot removed the claude-security-reviewing Claude Code /security-review in progress label May 22, 2026
The browser frontend could not discover harnesses because /api/status
did not include harness data or selectedHarness in its response.

The deploy box was still not showing because switchableIoHost was only
created with verbose:true, but preview also creates it when
onDeployMessage is provided. Also wire onDeployMessage into the
setOnMessage callback so both callbacks receive deploy events.

Constraint: frontend polls /api/status to discover available targets
Rejected: Separate /api/harnesses endpoint | adds complexity for no benefit
Confidence: high
Scope-risk: narrow
@github-actions github-actions Bot removed the size/xl PR size: XL label May 22, 2026
@github-actions github-actions Bot added the size/xl PR size: XL label May 22, 2026
@agentcore-devx-automation agentcore-devx-automation Bot added the claude-security-reviewing Claude Code /security-review in progress label May 22, 2026
@agentcore-devx-automation
Copy link
Copy Markdown
Contributor

Claude Security Review: no high-confidence findings. (run)

@agentcore-devx-automation agentcore-devx-automation Bot removed the claude-security-reviewing Claude Code /security-review in progress label May 22, 2026
The frontend Agent Inspector crashes with "Cannot read properties of
undefined (reading 'find')" when switching to a harness because the
/api/resources endpoint was missing the harnesses array entirely.

Constraint: Frontend expects harnesses array with deploymentStatus and deployed fields
Confidence: high
Scope-risk: narrow
@github-actions github-actions Bot removed the size/xl PR size: XL label May 22, 2026
@jesseturner21 jesseturner21 deployed to e2e-testing May 22, 2026 21:16 — with GitHub Actions Active
@github-actions github-actions Bot added the size/xl PR size: XL label May 22, 2026
@agentcore-devx-automation agentcore-devx-automation Bot added the claude-security-reviewing Claude Code /security-review in progress label May 22, 2026
@agentcore-devx-automation
Copy link
Copy Markdown
Contributor

Claude Security Review: no high-confidence findings. (run)

@agentcore-devx-automation agentcore-devx-automation Bot removed the claude-security-reviewing Claude Code /security-review in progress label May 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/xl PR size: XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant