Skip to content

feat(artifacts)!: inspect and compare directories by a content-addressed root digest - #14270

Merged
morluto merged 14 commits into
mainfrom
feat/directory-artifact-identity
Nov 24, 2026
Merged

morluto merged 14 commits into
mainfrom
feat/directory-artifact-identity

Conversation

@morluto

@morluto morluto commented Nov 24, 2026 •

Copy link
Copy Markdown
Owner

Closes #14159 (owner decision: path-based inspection with a content-addressed directory identity).

Draft until #14247 (the first TargetFailure PR from #14239) lands; see "Sequencing" below.

Behavior

  • inspect_artifact takes an optional absolute path and inspects it without the open session target and without open_binary. A directory is inventoried in place; any other path is admitted as a target in its own artifact-only session that closes before the call returns. Omitting path keeps inspecting the open target. inspect_artifact no longer requires an open target in the capability inventory.
  • rea inspect-artifact <dir> inventories the directory directly.
  • compare_artifacts / rea compare-artifacts accept {"kind":"path","path":"/abs","integrity_policy"?} on either side, besides Evidence, retained references and Evidence files. CLI path sources resolve relative to the working directory.
  • open_binary is unchanged; fix(javascript): route directories by JavaScript input presence and name directory-capable operations #14186's directory_requires_file still refuses ordinary directories for native analysis.
  • Subject identity. A file keeps its SHA-256. A directory with a complete walk is {"kind":"directory","algorithm":"rea-directory-tree","version":1,"sha256":<root digest>} with the usual name and local_path display facts. The inventory carries the same fact as root_digest (with member_count), and the root node's sha256 is the root digest.
  • Partial walks. Hashing reuses the inventory walk, so it is bounded by the existing inventory limits and coverage. If a limit stops the walk, or a member cannot be read (denied directory or file, non-UTF-8 name, unreadable symlink target, an omitted subtree), root_digest is {"status":"partial","limitations":[...]} with no digest, and the Evidence subject is {"kind":"unknown","reason":"not-observed"}. A partial digest is never presented as the identity.
  • Directory symlinks now record link_target ({text, hex}) on their occurrence; compare_artifacts compares two recorded targets instead of reporting the link as unavailable. Their limitation reads "Symlink target was recorded, not followed."

Design notes

Owner. src/domain/directoryTreeDigest.ts owns the encoding; scanReader feeds it from the root DirectoryArtifactReader walk it already performs (no second walker), only for the root directory's own members (members of an expanded ASAR inside the directory are not tree members; the ASAR file is). artifactInventorySubject in artifactInventoryEvidence.ts is the one projection of an inventory root to its subject, and validateArtifactInventorySubject checks against the same rule. EvidenceSubjectTarget gains an optional tree (algorithm, version); evidenceSubjectTargetIdentity is the single place that turns it into a directory identity.

Encoding (version 1). SHA-256 over:

"rea-directory-tree" NUL  u32be(1)  u64be(record count)  record*
record   = u8(kind)  field(path)  kind-specific
field(b) = u64be(len(b)) b
file 0x01 + 32 raw content-SHA-256 bytes | directory 0x02 | symlink 0x03 + field(target bytes)
fifo 0x04 | socket 0x05 | block device 0x06 | character device 0x07

Paths are root-relative and join each name's exact stored bytes with / (strict UTF-8 names only; never Unicode-normalized); records sort by path bytes (= code point order). Every directory has a record, so empty subdirectories count; the empty root is the header with count 0 (b28a57a5…91b3b6, independently checked with printf | shasum -a 256).

Rationale and sources.

  • Git tree objects: sorted mode name NUL digest entries. Git keeps the executable bit and drops empty directories. REA drops mode, owner and times, because some hosts (Windows) cannot observe POSIX execute bits and the identity must be the same across hosts; the executable marking stays on occurrences and in comparisons. REA keeps empty directories so an added empty directory changes the identity.
  • Nix archive (NAR) format: entries ordered by name, 64-bit length-prefixed padded strings, regular files (with executable flag), directories and symlink targets. Length prefixing makes the serialization injective for any name bytes.
  • Go dirhash.Hash1: sorted sha256hex name\n lines, which forces it to disallow names containing newlines. Length-prefixed fields need no such refusal.
  • Dirhash: separators and the set of entry properties must be part of a named, versioned protocol, which is why algorithm and version are in the subject.
  • OCI descriptors: the algorithm travels with the digest; OCI layer digests also show why hashing an archive of the tree (the ZIP workaround) makes identity depend on archive order and metadata.
  • RFC 6962 §2.1: domain separation by prefix; here the header and kind bytes.
  • UAX #15: normalization is deliberately not applied inside the identity. Normalizing would give two distinct stored names (composed and decomposed é on Linux) one path, so trees differing only by swapping their contents would share an identity (review thread). Occurrences keep NFC logical paths for display; the identity uses stored bytes.

Flat rather than per-subdirectory Merkle: the inventory is already a flat occurrence list and no workflow reuses subtree digests; a future subtree encoding gets a new version. Reference doc: docs/reference/directory-identity.md.

Sequencing with #14239

#14247 (TargetFailure) is still open, so this PR adds no new failure types or sites. The failure paths reuse existing owners: a path that is not a directory goes through target admission (FIFO roots, missing paths and so on keep their current refusals); a change during the walk keeps the directory reader's existing integrity failures; a limit stop is not a failure but a partial root_digest. The comparison's "this adapter cannot inventory a path source" refusal is an input refusal. When #14247 lands I will rebase and raise the directory-route admission refusals through TargetFailure if the owner wants them distinct from the target-admission ones.

Validation

  • Owner digest tests (src/domain/directoryTreeDigest.test.ts): documented byte encoding reproduced independently; empty-directory golden; walk-order independence; UTF-8/code-point ordering (U+FF61 vs U+1F600); sensitivity to a content byte, a name, a kind, a symlink target, an added and a removed member; injective fields; non-normalized paths refused; partial builder has no sha256.
  • Inventory tests (src/artifacts/inventory/DirectoryRootDigest.test.ts) on real temp trees: same digest at different locations, creation orders, mtimes and modes; one-byte change; empty directory; symlink target recorded and not followed (outside content change keeps the digest, retarget changes it); FIFO recorded by kind; entry-limit stop is partial with no digest and unknown coverage.
  • Public workflows (tests/boundary/cli/directoryArtifactComparison.test.ts), the issue's scenario as two generated build folders (two PE-shaped executables, four SPIR-V modules and a synthetic DXBC; B drops one exe, adds one, flips one SPIR-V byte, adds a data file): CLI inspect-artifact <dir> subject; CLI compare-artifacts with path sources gives ., shaders, shaders/b.spv changed, editor.exe, data.pak added, tool.exe removed, the same classifications as the zipped workaround; MCP inspect_artifact {path} without open_binary gives the same identity as the CLI, and path-source and retained-evidence comparisons agree.
  • Mutation checks: dropping the limit stop's incomplete call fails the partial-walk test; dropping the symlink target from the encoding fails the golden, the symlink-sensitivity and the not-followed tests.
  • Affected sweep: 251 test files (inventory, comparison, Evidence, views, Apple, CLI/MCP artifact tests): all pass except tests/boundary/filesystem/directoryArtifactReaderOpen.test.ts > rejects entries that are not files, which fails identically on main (expects format, the reader throws path since fix(errors)!: split reader path refusals from malformed target bytes #14225).
  • verify:advertised-schemas -- --update-summary (inspect_artifact input changed), architecture guards, oxfmt, oxlint on changed files; compile (tsc -p tsconfig.build.json via build:cached) passes.
  • Real folder, never executed: the public Node.js v24.11.1 darwin-arm64 release tarball, extracted (194 MB, 6,045 members). rea inspect-artifact <dir> --detail summary --evidence_output …: complete digest, member_count 6045; 2.30 s / 2.34 s wall (two warm runs; 2.4 s user, 0.9 s sys), peak RSS ~0.52 GB, which includes reading and hashing every byte for the inventory and writing a 12.9 MB bundle. The tree encoding itself was not measured separately. No token measurement.

Remaining cleanup (not in this PR)

…sed root digest

inspect_artifact takes an optional path and inspects it without the open
session target; a directory is inventoried in place. compare_artifacts
accepts {kind:"path",path} on either side. open_binary is unchanged and
still refuses ordinary directories with directory_requires_file.

The inventory owner computes a versioned tree digest (rea-directory-tree
v1) from the walk it already performs: SHA-256 over length-prefixed
records of each member's NFC path, kind and content digest, sorted by
path bytes. Symlink targets are recorded and not followed; FIFOs,
sockets and devices are recorded by kind. A walk that a limit or an
unreadable member stops reports root_digest partial with no digest.

BREAKING CHANGE: subject.identity gains a directory kind
{kind:"directory",algorithm:"rea-directory-tree",version:1,sha256}. A
directory inventory's subject and root sha256 are its tree digest, and a
partial walk's subject is {kind:"unknown",reason:"not-observed"}.
inspect_artifact no longer requires an open target. Directory symlink
occurrences record link_target and compare by it.
@morluto
morluto marked this pull request as ready for review November 24, 2026 03:29
@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-24T03:29:37.655643Z
We couldn’t complete this review. Comment @codex review to try again.
583d409 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@greptile-apps

greptile-apps Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5 Tier: plus

[Medium impact] The reviewed changes appear safe to merge.

Summary

Adds path-based artifact inspection and comparison, with complete directories identified by a versioned tree digest.

  • Complete directory inventories now have a versioned identity based on their contents.
  • Callers can inspect a chosen path without opening it as the session target.
  • Artifact comparisons can now use paths directly on either side.
  • Directory inventories now record symlink targets for identity and comparison.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A["Selected artifact path"] --> B{"Directory?"}
  B -->|Yes| C["Inventory existing directory"]
  B -->|No| D["Inspect in artifact-only session"]
  C --> E{"Walk complete?"}
  E -->|Yes| F["Directory subject with tree digest"]
  E -->|No| G["Unknown subject; no tree digest"]
  D --> H["File subject"]
  F --> I["Compare inventories"]
  G --> I
  H --> I
Loading

Reviews (8) · Last reviewed commit: "fix(artifacts): compare stored directory..." · Reviewed by Greptile

Comment thread src/domain/artifactInventoryEvidence.ts Resolved
Comment thread src/domain/directoryTreeDigest.ts Resolved
Comment thread src/artifacts/ArtifactProvider.ts Resolved
Comment thread docs/README.md Resolved
… cleanup retryable

- The tree digest encodes each member's exact stored name bytes instead
  of an NFC path, so names that differ only in normalization stay two
  members and swapping their contents changes the identity.
- A directory inspection whose readers cannot be released retains its
  scope in the caller's lifetime (the MCP session, the CLI session or
  the comparison's resource scope), so a later close retries it. The
  one-shot session of a path-selected file is retained the same way.
- compare_artifacts keeps a completed left inventory as an argument
  observation when the right side fails.
- A summary of a partial directory inventory, whose subject is unknown,
  resolves to its exact parent and compares with unknown coverage.
- The directory identity reference is in the site navigation, and the
  CLI boundary test passes the comparison command its environment.
Comment thread src/domain/artifactInventoryEvidence.ts Resolved
Comment thread src/domain/evidence.ts Resolved
…ts in claims and digest filters

verify_reconstruction required a file subject for every structural
source, so a structural-artifact claim over two complete directory
inventories stayed unknown even when compare_artifacts confirmed a
difference. Artifact claims now accept a file or directory identity;
function claims remain file-only.

get_evidence_bundle's target_sha256 filter compared only file subjects,
so a directory's returned tree digest matched no records. It now
matches the digest of a file or directory subject.
Comment thread src/cli/artifactComparisonCommand.ts Resolved
…ct-identity

# Conflicts:
#	src/artifacts/inventory/ArtifactGraphConstruction.ts
A relative directory selection such as "." reached the directory route
unresolved, so the subject's local_path was the relative spelling.
The directory route now uses the caller path owner, as target admission
does for files, and records the absolute path.

The CLI acceptance test that pinned "inspect-artifact ." to
directory_requires_file now expects the inventoried empty directory,
and the macOS bundle verifier asserts the .app directory's tree-digest
identity instead of a file format.
Comment thread src/contracts/sessionToolContracts.ts Resolved
# Conflicts:
#	src/artifacts/ArtifactProvider.ts
…LI evidence delivery, cleanup retry, and tool effects
Comment thread src/cli/artifactComparisonCommand.ts Resolved
Comment thread src/domain/artifactComparison.ts Resolved
@morluto
morluto enabled auto-merge (squash) November 24, 2026 15:31
Comment thread src/domain/artifactComparison.ts Resolved
@morluto
morluto disabled auto-merge November 24, 2026 17:05
@morluto
morluto merged commit 56cf155 into main Nov 24, 2026
53 checks passed
@morluto
morluto deleted the feat/directory-artifact-identity branch November 24, 2026 17:06
morluto added a commit that referenced this pull request Nov 25, 2026
…essions

#14270 made inspect_artifact take an optional path and stop requiring an
open target, so a resource-only session reports it available. The
macOS-only acceptance test still expected target_unsupported. It now
expects inspect_artifact available, inventories the bundle by path in
the resource session, and still expects the target-less call refused.
@morluto morluto added area: evidence Evidence, artifacts, and reconstruction enhancement New feature or request labels Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: evidence Evidence, artifacts, and reconstruction enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Inventory plain directories so compare-artifacts can diff two build outputs

1 participant