Skip to main content

Module bundle_import

Module bundle_import 

Source
Expand description

Armory Bundle Format (ABF) importer — Phase 2 of docs/specs/SPEC_ABF_V0_1_SINGLE_FILE_AND_IMPORTER_2026_08_01.md. Inverse of bundle_export.rs: takes a bundle’s files (either a raw [{path, content}] list or an unpacked .abf zip archive) and validates + parses them into data ready for the bundle.import RPC handler to write to the Store.

Pure functions only — no I/O, no Store access, no account resolution (account resolution needs db_accounts, which only the RPC handler has access to; see the spec’s §4.5). Mirrors bundle_export.rs’s shape and quality bar deliberately: the same “warn, don’t silently drop” and “reject the whole thing on structural failure, but never partially import on a per-entry problem” philosophy, since the two modules are meant to round-trip against each other.

Modules§

parse_steps
The steps of parse_bundle_import_with_budget, one function each, in the order they ran: the manifest, then each component category (instructions, skills, MCP servers, account requirements, the memory note, project instructions). Moved out of it without a change in behaviour, so every warning is still pushed in the same order. A child module of bundle_import.rs, whose private helpers and caps these use.

Structs§

AccountRequirement
One accounts/requirements.json entry — mirrors the shape bundle_export.rs writes (research report §5.3).
BundleImportFile
One file read from an import source (zip or raw list), path relative to the bundle root. Mirrors bundle_export::BundleExportFile.
ImportedContextFile
One instructions/context/* file, in the [{path, content}] shape db_bundles.context_files stores.
ImportedProjectInstruction
One components.projectInstructions entry, read back out of the bundle.
ParsedBundleImport
Parsed, validated bundle content ready for the RPC handler to resolve accounts against and write to the Store. mcp_servers still contains whatever ${VAR}-style placeholders the exporter’s redaction left in place — account resolution (§4.5, RPC-handler-side) substitutes real account bindings where exactly one match is found and leaves the rest untouched.
ParsedMcpServer
An MCP server parsed out of a components.mcpServers reference — Phase 3 spec §3.0. source_path is the stable, always-unique selection key (the manifest path reference, distinct from whatever "name" field happens to appear inside config’s arbitrary JSON, which has no uniqueness guarantee and isn’t even required to be present).
ParsedSkill
A skill parsed out of a skills/<slug>/SKILL.md file — the inverse of agent_config::render_skill_md.
WarningBudget
Bounds how many warnings a parse call accumulates, and how long each individual warning string may be — Phase 3 spec (SPEC_ABF_IMPORT_UI_PHASE3_2026_08_02.md) §3.1, round 11: the cap must live at the point warnings are actually PRODUCED, not only at a later RPC-response-serialization boundary, or a hostile archive can still force the parser itself to build an unbounded Vec<String> in memory before any cap ever runs. unbounded() preserves today’s existing bundle.import route’s real, already-shipped behavior exactly — this is a capability the parser gains, not a behavior change forced onto Phase 2’s existing caller.

Enums§

ImportInputMode
Which of the three bundle.import.preview/.commit input fields produced a given payload — mixed into the content-digest hash domain itself (Phase 3 spec §3.0.5, round 7) so a file_path preview can never be satisfied by a zip_base64 commit of the identical underlying bytes (both canonicalize to the same raw zip bytes and would otherwise hash identically), closing the gap a bare byte-digest comparison left open.

Constants§

LEGACY_MANIFEST_FILE
The manifest of ABF v0.1 and v0.2 archives, read forever.
MANIFEST_FILE
The manifest an ABF v0.3 archive carries (SPEC_AGENT_BUNDLE_FORMAT_V0_3_2026_10_05.md §2.1).
MAX_BUNDLE_NAME_CHARS
Maximum character length of a bundle’s manifest name, enforced at parse time (Phase 3 spec §3.1, round 13) rather than at a later display boundary — name is re-submitted verbatim as bundle_name when a user doesn’t edit the preview’s suggested value, so the canonical, bounded value must be what both preview and commit converge on from the moment parsing completes. Generous for any real bundle name.
MAX_DISPLAY_FIELD_CHARS
Fixed-character display cap shared by every “meant to be short” bounded field this spec defines: skill description/slug (rounds 10/12), requirement id/provider/env (round 11), context-file display_path (round 13), and bundle description (round 12 self-audit).
MAX_IMPORTED_PROJECT_INSTRUCTIONS
Cap on how many components.projectInstructions entries are read back.
MAX_IMPORTED_SKILLS
Maximum number of skills actually imported (i.e. written to the Store) from a single bundle. MAX_ENTRY_COUNT/capped_component_array bound how many components.skills entries are even LOOKED AT, but codex P1 (PR #2379 round 7) points out that’s still far too high a ceiling for the RPC handler’s write side: importing up to that many skills means up to that many separate synchronous Store transactions, each creating a permanent, globally-visible skill row — a compact malicious archive (well within the size caps) could otherwise monopolize the handler and pollute the installation’s skill catalog. A real bundle needs a handful to a few dozen skills at most.
MAX_INSTRUCTIONS_PREVIEW_CHARS
Cap on instructions_preview (Phase 3 spec §3.1, round 5) — generous for a glance-and-decide preview; bounds worst-case JSON-escaped response size to roughly 300 KB rather than the ~300 MB a maximally-adversarial, unbounded instructions string could otherwise force.
MAX_MCP_DISPLAY_FIELD_CHARS
Fixed-character display cap for an MCP server’s projected name/ command (Phase 3 spec §3.1, round 7) — smaller than MAX_DISPLAY_FIELD_CHARS since these are meant to be short identifiers/executable names, not free-form text.
MEMORY_COMPONENT_IGNORED_WARNING
SCHEMA_V0_3
The $schema an ABF v0.3 manifest names.

Functions§

abf_format_version
The ABF format version a manifest declares through its $schema, or None when it names none this importer knows. The version field is the bundle’s own content version, not this.
bound_bundle_name
Bounds a bundle name to MAX_BUNDLE_NAME_CHARS via plain truncation (no ellipsis, unlike truncate_display) — this IS the canonical value, not a display abbreviation of a longer “real” one. Shared by parse_bundle_import’s own manifest-name bounding and the Phase 3 bundle.import.commit RPC’s bundle_name override (round 3), so a client-supplied override can’t bypass the same bound parsed.name is already held to.
bounded_instructions_preview
Bounds instructions_preview for the RPC response — returns (preview, truncated, total_chars). The full, untruncated instructions value is unaffected; this only bounds what’s echoed back for display (Phase 3 spec §3.1, rounds 5 and 8).
classify_skill_collision
"none" / "name_conflict" / "duplicate_in_bundle" — Phase 3 spec §3.1’s two-pass skill collision classification. global_slugs is whatever the caller already fetched from skill.catalog.list’s underlying skill_list_global() (Store access lives in the RPC handler, not here — this stays a pure function so it’s testable with a seeded fake global-skill list, per the spec’s own §6 testing notes). Pass 1 (global catalog) takes priority over pass 2 (intra-bundle duplicate) when both apply, matching §3.1’s stated precedence.
content_digest_files
SHA-256 content digest for files-mode input (§3.0.5, round 6) — hashes parse_bundle_import’s own effective, order-resolved representation ([dedup_files_by_path]’s normalize-then-first-wins reduction, sorted by normalized key), not the raw input array. This makes the digest order-independent for genuinely equivalent inputs while remaining sensitive to any reordering that would actually change which entry the parser’s first-wins rule keeps.
content_digest_raw_bytes
SHA-256 content digest for file_path/zip_base64 input — both canonicalize to the same thing (raw zip bytes), differentiated only by the mode tag mixed into the hash domain (§3.0.5, round 7).
duplicate_in_bundle_slugs
Every parsed skill slug that appears more than once across the WHOLE bundle — the "duplicate_in_bundle" collision pass (Phase 3 spec §3.1, codex P1 round 2), computed independently of any external global-catalog state so it’s pure and directly testable.
enforce_raw_files_caps
Applies [check_entry_size]’s caps (plus [MAX_ENTRY_COUNT]) to the raw files RPC intake path — the path unzip_bundle_import never covers (reagent P1, PR #2379 round 5). Unlike zip entries, a raw file’s content is already fully materialized (no separate declared-vs-actual distinction, no incremental decompression to bound), so this only needs the shared per-entry/aggregate check, no backstop-read machinery.
enforce_raw_files_caps_with_budget
Same as enforce_raw_files_caps, but with an explicit WarningBudget (Phase 3 spec §3.1, round 11).
manifest_file_name
Which manifest file a set of archive paths carries: bundle.json, else the legacy armory.json.
mcp_server_display
Bounded {name, command} projection of an MCP server’s full config (Phase 3 spec §3.1, round 7) — the full config is never returned in preview/commit responses, only this small, defensively-extracted projection. Falls back to null for either field when absent or not a string, since MCP JSON has no required shape (§3.0).
newer_abf_refusal
The plain refusal for a manifest whose $schema names an ABF format newer than this build reads, or None (a format this build reads, or a $schema that names no ABF format: those keep the warning in warn_on_schema). It names the format and, when the bundle says which AgentMux made it (metadata.agentmuxVersion), that version. Such a bundle is refused whole: a newer format can change what a component means, and importing what this build can make sense of would be a half import.
parse_bundle_import
Parse and validate a bundle’s files into ParsedBundleImport. Structural failures (no manifest, bundle.json or armory.json, or a malformed one) reject the whole import — Err — since there is nothing safe to partially write. Per-entry problems (a missing referenced file, an unsafe path, a malformed SKILL.md) degrade to a warning and that entry is skipped — matches bundle_export.rs’s own philosophy, and lets a lossy import still produce a usable bundle rather than an all-or-nothing failure on e.g. one corrupt skill among five good ones.
parse_bundle_import_with_budget
Same as parse_bundle_import, but with an explicit WarningBudget enforced at every warning-push site inside this function (Phase 3 spec §3.1, round 11) — the new bundle.import.preview/.commit RPC handlers call this directly with a tight budget; parse_bundle_import passes WarningBudget::unbounded, preserving today’s existing bundle.import route’s behavior exactly.
truncate_display
Fixed-character truncation shared by every bounded-display projection this module (and its RPC callers, Phase 3 spec §3.1/§3.2) define — stated once so preview and commit always apply IDENTICAL bounds to the equivalent field, rather than independent per-endpoint copies drifting apart (the exact class of gap codex found and re-found across rounds 9 and 12).
unzip_bundle_import
Unpack a .abf zip archive into a flat file list, applying the same path-safety check as everywhere else in this module to every entry name before it’s trusted (§4.3.4) — a zip’s own internal paths are exactly as untrusted as any other part of the archive’s content. Directory entries are skipped; anything that fails the safety check is dropped with a warning rather than surfaced as a file.
unzip_bundle_import_with_budget
Same as unzip_bundle_import, but with an explicit WarningBudget (Phase 3 spec §3.1, round 11).