feat(import): add runtime and memory import subcommands with TUI wizard#763
Merged
jesseturner21 merged 33 commits intoaws:mainfrom Apr 2, 2026
Merged
feat(import): add runtime and memory import subcommands with TUI wizard#763jesseturner21 merged 33 commits intoaws:mainfrom
jesseturner21 merged 33 commits intoaws:mainfrom
Conversation
Contributor
Package TarballHow to installnpm install https://github.com/aws/agentcore-cli/releases/download/pr-763-tarball/aws-agentcore-0.5.1.tgz |
Hweinstock
reviewed
Apr 2, 2026
Contributor
Hweinstock
left a comment
There was a problem hiding this comment.
Mostly nits and some questions about existing patterns. Only comments worth addressing today:
- could we build more reusable utilities to make future import work easier? Feels like memory/runtime are pretty duplicated. This could also be picked up when adding new resources, if we're trying to get this out today.
- Should we log when non-critical parts of import fail, or when we attempt to rollback?
Fetch tags via ListTagsForResource API and include them in the imported memory config. Tags already flow through the CLI schema and CDK construct, they just weren't being read from the API during import.
Add encryptionKeyArn to CLI schema, MemoryDetail, and toMemorySpec so imported memories preserve their KMS encryption key configuration. Also update CDK L3 construct to pass encryptionKeyArn through to CfnMemory.
Map the API field memoryExecutionRoleArn to executionRoleArn in CLI schema to match the runtime convention. Also update CDK L3 construct to use an imported role via Role.fromRoleArn when executionRoleArn is provided instead of always creating a new one.
…ities actions.ts reimplemented 5 utilities that already exist in import-utils.ts. Replace local definitions with imports and use updateDeployedState() instead of inline state manipulation. Removed: sanitize(), toStackName(), fixPyprojectForSetuptools(), COPY_EXCLUDE_DIRS, copyDirRecursive() — all duplicates of import-utils.ts.
…ve runtime config Three import bugs fixed: 1. listAgentRuntimes/listMemories only fetched one page (max 100). Added listAllAgentRuntimes/listAllMemories that paginate via nextToken. 2. Single-result listing incorrectly showed "Multiple found" error. Now auto-selects when exactly one runtime/memory exists. 3. toAgentEnvSpec dropped env vars, tags, lifecycle config, and request header allowlist. Extended AgentRuntimeDetail and getAgentRuntimeDetail to extract these fields (including ListTagsForResource call for tags), and mapped them in toAgentEnvSpec. Confidence: high Scope-risk: moderate Not-tested: pagination with >100 real resources (no integration test account available)
…, and env var mapping Tests cover: - listAllAgentRuntimes/listAllMemories pagination across multiple pages - getAgentRuntimeDetail extraction of environmentVariables, tags (via ListTagsForResource), lifecycleConfiguration, requestHeaderAllowlist - toAgentEnvSpec mapping of env vars Record to envVars array, plus direct mapping of tags, lifecycle config, and header allowlist - Single-result auto-select when listing returns exactly 1 runtime - Error cases: empty listings, multiple results, absent fields
When no deployment targets are configured, import runtime/memory now parses the --arn to extract region and account, then creates a default target automatically instead of requiring `agentcore deploy` first.
Container runtimes have no runtimeVersion from the API, but toAgentEnvSpec was hardcoding PYTHON_3_12 as a fallback. Now runtimeVersion is optional in the schema and only set for non-Container builds.
Memory strategies like SUMMARIZATION and USER_PREFERENCE include
auto-generated namespace patterns (e.g. /strategies/{memoryStrategyId}/...)
that are API-internal and should not be written to local agentcore.json.
Constraint: Only filters namespaces containing {memoryStrategyId} template var
Rejected: Strip all namespaces for non-SEMANTIC strategies | would lose user-defined namespaces
Confidence: high
Scope-risk: narrow
Commander's requiredOption() for --code runs before the action handler, so users outside a project see "required option not specified" instead of "no agentcore project found". Change to option() so the handler's project context check (step 1) runs first. The --code validation at step 5 still catches missing values after project context is confirmed. Constraint: Commander validates requiredOption before action handlers execute Rejected: Moving project check into a Commander hook | adds complexity for one flag Confidence: high Scope-risk: narrow
- Invalid ARN now returns "Not a valid ARN" before target resolution - Failed imports roll back agentcore.json and clean up copied app/ dirs - Discovery listings show ARNs (not just IDs) so users can copy them - Remove --target flag from import runtime/memory subcommands - Add description field to AgentEnvSpec schema and wire through import Constraint: Commander validates requiredOption before action handlers Constraint: Rollback is best-effort to avoid masking the original error Rejected: Keep --target on subcommands | silently falls back to default, confusing UX Confidence: high Scope-risk: moderate
Adds a multi-screen TUI flow for importing runtimes, memories, and starter toolkit configs, replacing the silent fall-through that previously occurred when selecting "import" in the TUI. Constraint: onProgress must be injectable so TUI can display step progress Rejected: Single text-input screen for all flows | each import type has different required fields Confidence: high Scope-risk: narrow
Bug 5: Validate --name against the AgentNameSchema regex before any file I/O operations. Previously, a malicious --name like '../../../etc/pwned' would copy files outside the project directory and set up a Python venv there before schema validation rejected it. Now invalid names are caught immediately with a clear error message. Applied to both import-runtime and import-memory. Bug 6: Allow re-importing the same cloud resource under a different local name when --name is provided. Previously, the deployed-state duplicate check blocked all re-imports by resource ID regardless of --name. Now it only blocks when --name is not provided, and suggests using --name in the error message. When --name is provided, it warns and proceeds. Applied to both import-runtime and import-memory.
Bug 6 is not a bug — blocking re-imports of the same cloud resource ARN is correct because allowing it would create duplicate CFN logical resources referencing the same physical resource, causing deploy failures. Reverts the --name re-import allowance while keeping the Bug 5 early name validation fix.
…le picker Two TUI fixes for the import flow: 1. ImportFlow now accepts onNavigate prop so selecting "Deploy" from next steps navigates to the deploy screen instead of going back. 2. PathInput gains a showHidden prop; YamlPathScreen uses it so .bedrock_agentcore.yaml is visible in the file picker.
…lication The three import handlers (import-runtime, import-memory, actions) all repeated the same CDK build/synth/bootstrap/publish/phase1/phase2/state-update pipeline (~120 lines each). Extract this into executeCdkImportPipeline() in a new import-pipeline.ts module. Also add resolveImportContext() and failResult() helpers to import-utils.ts for shared setup and error handling. Net effect: -335 lines, zero behavior change, all 260 tests pass. Constraint: Must not change any observable behavior — pure structural refactor Rejected: Full strategy-pattern abstraction | over-engineering for 2 concrete cases Confidence: high Scope-risk: moderate Not-tested: actions.ts YAML import path with real AWS (infra limitation)
…args Previously `agentcore import` with no --source flag showed help text. Now it launches the interactive ImportFlow TUI, matching the pattern used by `agentcore add` and other commands.
When running `agentcore import` from CLI (not full TUI), selecting "deploy" or "status" from the next-steps menu now renders the corresponding screen instead of silently exiting.
…ulnerabilities npm audit fix resolves CVE for code injection via _.template and prototype pollution via _.unset/_.omit in lodash <=4.17.23.
…nstantiation Each function in agentcore-control.ts was creating a new BedrockAgentCoreControlClient on every call, wasting HTTP connections and credential resolution. Extracted a shared createControlClient() factory and reuse a single client across paginated listAll* calls.
…ing errors Tag fetch failures in agentcore-control.ts and rollback failures in import-runtime.ts and import-memory.ts were silently swallowed. Users had no indication when config could be left in a broken state. Added console.warn calls matching the existing pattern in bedrock-import.ts.
Hweinstock
approved these changes
Apr 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds
agentcore import runtimeandagentcore import memorysubcommands that import existing AWS BedrockAgentCore resources into a local CLI project via CloudFormation IMPORT change sets. Also adds an interactive TUI wizard for the import flow.Key changes
New import subcommands:
agentcore import runtime --arn <arn> --code <path>— imports an existing AgentCore Runtime, copies agent source code, and brings the resource under CloudFormation managementagentcore import memory --arn <arn>— imports an existing AgentCore Memory with full strategy/namespace/tag preservation--namefor local name override,--targetfor multi-target projects, and-yfor auto-confirmInteractive TUI wizard:
agentcore importwith no args launches a guided wizard (resource type selection → ARN input → code path → progress → next steps)Shared CDK import pipeline (
import-pipeline.ts):actions.ts,import-runtime.ts, andimport-memory.tsinto a singleexecuteCdkImportPipeline()functionbuildResourcesToImportcallbackAWS control plane helpers (
agentcore-control.ts):getAgentRuntimeDetail/getMemoryDetail— fetch full resource details with field validationlistAllAgentRuntimes/listAllMemories— paginated listing with auto-select for single resultsImport utilities (
import-utils.ts):resolveImportContext()— shared setup (logger, project context, target resolution)parseAndValidateArn()— validates format, resource type, region, and account matchfailResult()— standardized error return buildercopyAgentSource()— copies agent code with exclusion filters, pyproject.toml fixup, Dockerfile generationfindResourceInDeployedState()— duplicate detection against deployed-state.jsonValidation and error handling:
AgentNameSchemaregex before any file I/O (prevents path traversal via--name)Schema changes:
runtimeVersionmade optional (Container builds don't need it)descriptionandencryptionKeyArnto Memory schemaexecutionRoleArnto Memory schemaRelated Issue
Closes #
Documentation PR
Type of Change
Testing
How have you tested the change?
npm run test:unitandnpm run test:integnpm run typechecknpm run lintsrc/assets/, I rannpm run test:update-snapshotsand committed the updated snapshotsUnit tests added:
import-runtime-handler.test.ts— 200+ tests covering entrypoint detection, field mapping, validation, duplicate detection, rollback, error pathsimport-runtime-entrypoint.test.ts— extractEntrypoint edge cases (OTel wrappers, missing extensions, path prefixes)agentcore-control.test.ts— AWS API helper tests (pagination, field extraction, auto-select, env var mapping)End-to-end bugbash testing:
Checklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the
terms of your choice.