Skip to content

fix: harden agent worktree indexing and structural edit planning - #39

Merged
2233admin merged 6 commits into
mainfrom
codex/fix-linked-worktree-index
Jul 26, 2026
Merged

fix: harden agent worktree indexing and structural edit planning#39
2233admin merged 6 commits into
mainfrom
codex/fix-linked-worktree-index

Conversation

@2233admin

Copy link
Copy Markdown
Owner

What changed

  • exclude nested linked-worktree directory markers from repository snapshots
  • reuse snapshot lease exclusions in the inventory.rg capability
  • add regression coverage for linked-worktree .git pointer files and opaque directory entries
  • add the preview-only edit.ast-grep-plan capability with automatic ast-grep threading
  • document the snapshot and structured-edit artifact contracts

Why

OpenCLI Admin exposed a pipeline-level failure when an agent-created linked worktree lived under .claude/worktrees. Git reports the nested worktree as an opaque directory entry; the snapshot builder treated that entry as a regular file and failed with exit code 74. Because the same condition can occur in any repository using nested agent worktrees, the fix belongs in Code Intel rather than in the consuming project.

The structural-edit capability is included as a non-mutating planning primitive. It produces a deterministic preview and does not grant repository mutation authority.

Impact

  • Code Intel no longer fails snapshot construction on nested linked worktrees.
  • Inventory and snapshot boundaries now agree for the corrected path.
  • Consumers such as OpenCLI Admin require no application-code workaround.
  • Structural edits can be planned without changing repository files.

Validation

  • cargo test -p code-intel --test capability_exec nested_linked_worktree_is_excluded_from_inventory -- --exact
  • cargo test -p code-intel --test snapshot_identity
  • cargo fmt --check
  • real OpenCLI Admin run: code-intel D:\projects\opencli-admin --mode lite --json completed successfully in 17.883 seconds with 1,300 inventory files and no nested-worktree entries

@gemini-code-assist

Copy link
Copy Markdown

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@coderabbitai

coderabbitai Bot commented Jul 26, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: cec70ca7-b0b0-4d2f-902e-c85ebfb12b2d

📥 Commits

Reviewing files that changed from the base of the PR and between a2af63e and caf258d.

📒 Files selected for processing (11)
  • .sentrux/baseline.json
  • .sentrux/rules.toml
  • crates/code-intel-cli/src/capability_inventory.rs
  • crates/code-intel-cli/src/snapshot.rs
  • crates/code-intel-cli/src/structured_edit.rs
  • crates/code-intel-cli/tests/capability_exec.rs
  • docs/artifact-data-contract.md
  • docs/repository-snapshot-identity.md
  • orchestration/integrations.json
  • orchestration/internalization/git.json
  • orchestration/internalization/rg.json

📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Added a structured code search and rewrite preview capability using AST-based matching.
    • Preview plans report proposed replacements without modifying repository files.
    • Added validation to restrict searches to approved repository paths and prevent unsafe or generated targets.
  • Bug Fixes

    • Improved repository inventory handling for linked worktrees and nested repositories, excluding their metadata and contents appropriately.
  • Documentation

    • Documented the new structured-edit preview artifact and clarified snapshot handling for nested repositories and linked worktrees.

Walkthrough

This change adds a preview-only ast-grep structured-edit capability, strengthens snapshot exclusions for untracked linked worktrees, updates related tests and contracts, and refreshes baseline and provenance metadata.

Changes

Capability and snapshot behavior

Layer / File(s) Summary
Snapshot exclusion handling
crates/code-intel-cli/src/snapshot.rs, crates/code-intel-cli/src/capability_inventory.rs, crates/code-intel-cli/tests/capability_exec.rs, docs/repository-snapshot-identity.md
Snapshot leases collect untracked directory exclusions, inventory applies combined exclusions, and linked-worktree scenarios are covered by tests and documentation.
Structured edit execution
crates/code-intel-cli/src/structured_edit.rs
The new adapter validates scoped paths, runs ast-grep, normalizes matches, verifies snapshot consumption, and publishes a preview-only plan artifact.
Capability wiring and contract validation
crates/code-intel-cli/src/capability_inventory.rs, crates/code-intel-cli/tests/capability_exec.rs, orchestration/integrations.json, docs/artifact-data-contract.md
The adapter is registered and declared as edit.ast-grep-plan, with toolchain wiring, integration coverage, and an artifact contract for structured-edit-plan.json.
Provenance and baseline refresh
.sentrux/*, orchestration/integrations.json, orchestration/internalization/*.json
Baseline metrics, ratchet evidence, integration digests, and internalization provenance hashes are refreshed.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant CapabilityExec
  participant StructuredEdit
  participant AstGrep
  participant SnapshotLease
  participant Artifact
  Client->>CapabilityExec: Request edit.ast-grep-plan
  CapabilityExec->>StructuredEdit: Execute scoped plan
  StructuredEdit->>SnapshotLease: Begin and verify consumption
  StructuredEdit->>AstGrep: Run structural search or rewrite preview
  AstGrep-->>StructuredEdit: Return JSON matches
  StructuredEdit->>Artifact: Publish structured-edit-plan.json
  Artifact-->>Client: Return preview plan
Loading

Possibly related PRs

Poem

I’m a rabbit with plans in a burrow of code,
Ast-grep finds each twig on the snapshot road.
No files are changed, no rewrite takes flight,
Linked worktrees stay tucked out of sight.
A preview blooms softly—structured and bright!

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

… changes

snapshot.rs, capability_inventory.rs, and capability_exec.rs changed in this
branch, but git.json kept the old snapshot.rs digest, rg.json pinned
intermediate rather than final file digests, and integrations.json still
carried the pre-branch capability_inventory.rs toolchain digest in five
entries. Recomputed all pins from the checked-out tree (Get-FileHash parity
with the internalization_record gate).
Resolves orchestration digest conflicts by recomputing every pinned
source digest from the merged tree: snapshot.rs (worktree fix + main
scope changes), artifact_ref.rs, sentrux_gate.rs, hospital_diagnosis.rs,
run-code-intel.ps1, capability_inventory.rs, capability_exec.rs.
Validated with cargo fmt --check and the full code-intel suite
(1808 tests, 0 failures).
…adapter

The no-degradation gate compares against .sentrux/baseline.json, which
was snapshotted from the PR #15 tree (quality 3971, coupling 44.78).
This branch merged v0.6.0 main (audit layer, +22 files) and adds the
edit.ast-grep-plan adapter module; the honest measurement of that tree
is quality 3969 / coupling 45.07 with god files and cycles unchanged
(29 / 0). Re-baselined via the gate's own prescribed operation:
code-intel sentrux --operation save_baseline. Self-scan run execute
now exits 0 on this tree.
@2233admin
2233admin marked this pull request as ready for review July 26, 2026 13:41
@gemini-code-assist

Copy link
Copy Markdown

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@2233admin
2233admin merged commit 013c991 into main Jul 26, 2026
6 checks passed
@2233admin
2233admin deleted the codex/fix-linked-worktree-index branch July 26, 2026 13:41
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