Skip to content

feat(cli): add nano package check and build (#84) - #89

Merged
AetherAI3 merged 3 commits into
mainfrom
claude/nano84-package-cli
Nov 7, 2026
Merged

AetherAI3 merged 3 commits into
mainfrom
claude/nano84-package-cli

Conversation

@AetherAI3

Copy link
Copy Markdown
Owner

First slice of #84 (roadmap #67): nano package check and nano package build, a thin CLI over the shipped compile_package API. No compiler, runtime or IR file changes. The contract was frozen in docs/package-cli.md before dispatch was touched.

What changed

  • nano/cli/package.py (new): check (silent / -v / --json NanoPackageCheck 1.0.0) and build (canonical NanoPackage envelope to stdout or -o, plus --module-output). --manifest and --lock are required on every action; nothing is discovered or searched for.
  • Exit codes reuse the CLI table: 1 = rejected package, 2 = invalid invocation (including an output naming an input), 3 = I/O (a PackageError chained to an OSError).
  • JSON is canonical (sorted, compact, ASCII) plus one LF byte, written through the byte sink so Windows never emits CRLF. Documents contain no absolute paths; I/O messages keep only the OS reason.
  • Outputs are checked against the manifest, the lock and every pinned source (by realpath and normcase) before any write. All outputs are staged first; if a later replace fails, earlier outputs are restored.
  • Docs: docs/package-cli.md (frozen contract), RFC 0066 deferred-work line, docs/README.md index, example README.

Frozen inputs (commit 2a60d08): docs/package-cli.md sha256 43e460df…cab74; examples/agent-package/cases.json sha256 3c97ba80…2abd (the dev set used by PR2).

Evidence (base cb6ea884d63dcaa8cc0e7c0b952bb88784e8219f, head c8c49e5bf903cf9c729b33ae6609bb6448dfb5a7)

  • Missing behaviour at base: nano package check … → exit 2 invalid choice: 'package'.

  • RED before implementing: tests/test_package_cli.py 45 failed / 5 passed (the 5 are usage-error cases that are trivially exit 2 at base).

  • Focused + compatibility suite (test_package_cli, test_cli, test_package, test_compiler_diagnostics, test_conformance, test_acceptance_parity, test_examples, test_docs):

    Python Passed Failed Skipped
    3.13.5 293 1 1
    3.12.10 293 1 1

    The failure is pre-existing on base (see Limitations). The skip is test_docs (README advertises no count).

  • Example identity: CLI bytes == canonical(compile_package(...).to_dict()) + "\n"; packageHash sha256:b5f5a854…a099, moduleHash sha256:78031edf…200e; envelope sha256 3a1bae4e…1070. Identical from another working directory, after relocation, after reordering metadata keys, and across repeated builds.

  • Negative controls (exit code, code, path, line/column asserted): missing pin, stale pin, duplicate manifest key, duplicate symbol, wrong type, import cycle, recursion, ungranted effect, RESOURCE_LIMIT, unknown field. Rejected: absolute path, ../, symlink escape (actually run, not skipped), an unpinned sibling .nano. I/O (exit 3): missing manifest, lock or source, and a directory given as the manifest.

  • Read-only: package bytes and mtimes unchanged after check, check --json, a failing check, and build -o. A fresh interpreter with sockets disabled leaves qiskit, nano_qsearch and numpy unloaded.

  • scripts/check_contribution.py --all: 55 entries ready.

Review: an independent reviewer found a partial-write case (-o plus a --module-output that fails to commit). Fixed in c8c49e5 with RED (2 failed) then GREEN tests. A suspected symlinked-manifest overlap gap is not reachable: the compiler roots sources at Path(manifest).resolve().parent, which is what the check uses.

Iterations: 3 in total, all on the dev set.

  1. Thin adapter: GREEN.
  2. Temporary-file cleanup and naming the requested output path in write errors.
  3. The review fix above.

No assertion was weakened and no negative control was removed.

Limitations / pre-existing (not changed here)

  • tests/test_package.py::test_metadata_depth_is_positioned fails on Python ≥3.12 at base too: json.loads no longer raises RecursionError at depth 2000 (3.10 and 3.11 do). Owner: the compiler lane.
  • GitHub CI starts zero jobs on this repo ("account is locked due to a billing issue"). Per [P1][hillclimb] Add explicit hermetic package check, build and fixture-test CLI #84, that is a failure. Merge waiver for this PR and its stacked follow-up was given explicitly by the repo owner in-session: "yes merge on local evidence, waiver for these PRs". No runner, billing or security settings were changed.
  • An IRValidationError raised after lowering is not mapped (unreachable: the API re-validates through NanoModule.from_dict).
  • init and fmt remain deferred.

Refs #84, #67

🤖 Generated with Claude Code

AetherAI3 and others added 3 commits November 7, 2026 17:19
Contract for check/build/test arguments, exit codes, output framing,
diagnostic and report documents, and the strict fixture schema, frozen
before any CLI dispatch edit. Adds the agent-package example cases file
used as the frozen development set.

Refs #84, #67

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Implements the check and build operations of the frozen contract in
docs/package-cli.md as a thin adapter over the public
compile_package(manifest, lock_path=lock) API. No compiler or runtime code
changes.

- nano/cli/package.py: new module with reusable helpers for the later
  `package test` lane (canonical_bytes, compiler_identity, diagnostic_dict,
  format_diagnostic, build_package -> CompiledPackage | PackageRejection,
  write_bytes_atomic) plus the check/build commands and argparse wiring.
- --manifest and --lock are required; no discovery, no defaults.
- PackageError chained to an OSError maps to IO_ERROR/io, span null, exit 3;
  other rejections exit 1 with their own code (PACKAGE_ERROR reported as
  category "package"). The OSError rendering in I/O messages is reduced to
  its strerror so documents never carry absolute paths.
- JSON goes through the byte sink: canonical, ASCII, exactly one LF.
- build refuses outputs that resolve to the manifest, lock, any manifest
  source, or each other (exit 2, nothing written); artifacts are staged as
  sibling temporaries and os.replace'd; failures leave no files and empty
  stdout.
- tests/test_package_cli.py covers CLI==API bytes with pinned hashes, cwd /
  relocation / reordered-metadata / repeat stability, LF framing in a fresh
  interpreter, parametrized positioned negative controls, path escapes, no
  ambient discovery, I/O and usage exits, output safety, read-only inputs and
  a socket-denied fresh interpreter that loads no qiskit/nano_qsearch/numpy.
- Docs: docs/README.md index entry, RFC 0066 deferred note, CLI section in
  examples/agent-package/README.md, help epilog examples.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Review finding: with both -o and --module-output, a failing second
os.replace left the first artifact committed. Destinations are now checked
(directories refused) before staging, and any output already replaced is
restored to its previous bytes or removed, matching the contract that a
failed build leaves no partial artifact.

Refs #84

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@AetherAI3
AetherAI3 merged commit 5016260 into main Nov 7, 2026
0 of 9 checks passed
@AetherAI3
AetherAI3 deleted the claude/nano84-package-cli branch November 8, 2026 19:03
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