Skip to content

feat: interactive screen for gateway policy generate - #2173

Merged
tejaskash merged 5 commits into
refactorfrom
feat/gateway-policy-generate-tui
Sep 3, 2026
Merged

feat: interactive screen for gateway policy generate#2173
tejaskash merged 5 commits into
refactorfrom
feat/gateway-policy-generate-tui

Conversation

@tejaskash

Copy link
Copy Markdown
Contributor

What

  • Interactive screen for agentcore gateway policy generate: pick a Gateway, see its attached Policy Engine, type a prompt, watch the generation steps, read the Cedar and findings. e edits the prompt and runs again.
  • policy appears in the agentcore gateway menu. A bare gateway policy generate opens the picker, --gateway-id X without --prompt opens the form on that Gateway. --json and any run with --prompt stay headless.
  • A Gateway with no Policy Engine attached gets an explanation instead of a prompt.
  • ErrorPanel and EventLog promoted from private copies to src/components and reused.

Testing

  • bun test src: 2794 pass. Four screen tests through renderScreen (picker to form, no engine, happy path with exact Core input and rendered Cedar plus the e retry, error phase back to the form), the gateway menu test lists policy, one deep-link handler test with an injected renderer.
  • Live drive in us-west-2 through the tui-harness against a deployed project with an attached and a bare Gateway: menu, picker, no-engine message, real generation with a DENY_ALL finding, e retry, esc while running, deep link, headless --json still errors on the missing prompt. Screenshot below.

@github-actions github-actions Bot added the size/m PR size: M label Sep 2, 2026
@agentcore-devx-automation agentcore-devx-automation Bot added agentcore-harness-reviewing AgentCore Harness review in progress claude-security-reviewing Claude Code /security-review in progress labels Sep 2, 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 Sep 2, 2026

@agentcore-devx-automation agentcore-devx-automation Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AgentCore Harness Review

Verdict: Looks good

Nice PR. The deep-link fall-through in src/handlers/gateway/policy/generate.tsx mirrors the pattern already established in harness/exec/index.tsx, and the fall-through gate (only when --prompt, --policy-engine-id, and --name are all unspecified and not JSON mode) is a sensible design that keeps the headless path predictable.

A few things I checked and liked:

  • Testing seams over mocks. createGeneratePolicyHandler takes an injectable renderGenerateTui, so the deep-link test in gateway.test.tsx verifies the path/core wiring without stubbing I/O. The screen tests drive real React trees through renderScreen and the existing TestPolicyClient seam — no filesystem/network mocking added.
  • Telemetry. Command-path telemetry is emitted automatically by the router (recordCommandPath in router.tsx), so the new gateway policy generate subroute is already instrumented without extra work.
  • Cleanup. aliveRef in GeneratePolicyForm correctly guards the async generator loop against state updates after unmount.
  • Component extraction. Pulling ErrorPanel out of HarnessWizard.tsx and EventLog out of project/create/screen.tsx into src/components/ is a clean dedup; no leftover unused imports in the source files.

No blocking issues from me — LGTM to merge.

@agentcore-devx-automation agentcore-devx-automation Bot removed the agentcore-harness-reviewing AgentCore Harness review in progress label Sep 2, 2026
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 99.07834% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 97.12%. Comparing base (d403f5d) to head (0006f61).

Files with missing lines Patch % Lines
src/handlers/gateway/policy/screen.tsx 98.67% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           refactor    #2173    +/-   ##
==========================================
  Coverage     97.12%   97.12%            
==========================================
  Files           535      538     +3     
  Lines         36844    37035   +191     
==========================================
+ Hits          35783    35972   +189     
- Misses         1061     1063     +2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread src/handlers/gateway/policy/screen.tsx Outdated
useInput(
(input, key) => {
if (key.escape) {
navigate(-1);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a no-op when launched directly through --gateway-id, because the MemoryRouter contains no previous history entry. Please navigate explicitly to /agentcore/gateway/policy/generate.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 9e3946e: esc now navigates to /agentcore/gateway/policy/generate explicitly, verified live from a --gateway-id deep link.

Comment thread src/handlers/gateway/policy/screen.tsx Outdated
);
let next = await generation.next();
while (!next.done) {
if (!aliveRef.current) return;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this prevents state updates but does not cancel or close the generator. The AWS waiter may continue polling after the user leaves. can we abort the operation on Esc/unmount and close the iterator, threading an AbortSignal through generatePolicy?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 9e3946e: generatePolicy takes an optional AbortSignal, passed to every send and to the waiter's abortSignal. The screen aborts the controller and calls return() on the iterator on esc and on unmount. A screen test asserts the signal is aborted on esc while running, and a Core test asserts an aborted signal rejects with UserCancellationError.

Comment thread src/components/EventLog.tsx Outdated
<Box flexDirection="column">
{events.map((message, index) => (
<Text key={`${index}-${message}`} color={theme.colors.muted}>
✓ {message}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A yielded progress step is the currently running step, not a completed one. This can display ✓ Waiting for generation to complete while it is still waiting.

Also, can we reuse the existing TaskList task-state model instead?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed and done in 9e3946e: the screen now uses TaskList with running/done/failed states, the same model runWithProgress uses. EventLog is no longer promoted, the create screen keeps its private copy untouched.

@github-actions github-actions Bot added size/l PR size: L and removed size/m PR size: M labels Sep 3, 2026
@agentcore-devx-automation agentcore-devx-automation Bot added the claude-security-reviewing Claude Code /security-review in progress label Sep 3, 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 Sep 3, 2026
@tejaskash
tejaskash merged commit 522f8e5 into refactor Sep 3, 2026
23 of 24 checks passed
@tejaskash
tejaskash deleted the feat/gateway-policy-generate-tui branch September 3, 2026 17:05
This was referenced Sep 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/l PR size: L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants