Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ repository = "https://github.com/saworbit/orbit"
[dependencies]
blake3 = "1.8"
clap = { version = "4.5", features = ["derive"] }
getrandom = "0.4"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
thiserror = "2.0"
Expand All @@ -22,7 +23,7 @@ predicates = "3.1"
tempfile = "3.23"

[target.'cfg(windows)'.dependencies]
windows-sys = { version = "0.61", features = ["Win32_Globalization"] }
windows-sys = { version = "0.61", features = ["Win32_Foundation", "Win32_Globalization", "Win32_Storage_FileSystem"] }

[profile.release]
lto = true
Expand Down
24 changes: 21 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,36 @@

Orbit is being rebuilt as a small, trustworthy local data copier.

The first product contract is: provide an exact source and destination, preview a deterministic plan, copy through safe staging, resume interruption, and verify the result. The reboot currently has no supported release.
The first product contract is: provide an exact source and destination, preview a deterministic plan, copy through safe staging, and verify the result. The reboot currently has no supported release.

See [the reboot design](docs/superpowers/specs/2026-09-22-orbit-reboot-design.md) for the approved scope. Historical code and documentation are preserved at `archive/pre-reboot-2026-09-22`; see [LEGACY.md](LEGACY.md).

## Current milestone

The reboot currently provides read-only local planning:
The reboot currently provides read-only local planning and one deliberately narrow write path:

```text
orbit plan SOURCE DEST [--replace] [--verify hash|size] [--ignore-unsupported] [--json|--quiet]
orbit copy SOURCE_FILE DEST_FILE [--verify hash|size] [--json|--quiet]
```

`DEST` is the exact target path. Planning scans and hashes as required but never writes source, destination, journal, or partial data. The `copy` command will appear only when safe staging and verification are implemented.
`DEST` is always the exact target path. Planning scans and hashes as required but never writes source, destination, journal, or partial data.

`copy` currently accepts one regular local file. Orbit writes a uniquely named staging file beside the destination, flushes and verifies it, then publishes it without overwriting an existing path. An identical existing file is a successful no-op; a different existing file is refused. The destination parent must already exist. Directories, links, replacement, resume, and remote storage remain intentionally out of scope.

If Orbit cannot determine the process working directory, startup fails before planning and emits a human-readable diagnostic on stderr, including when `--json` was requested.

## End-to-end vibe harness

[`scripts/vibe-harness.ps1`](scripts/vibe-harness.ps1) is a black-box PowerShell harness that drives a built `orbit` binary and asserts the observable behaviours this milestone commits to: deterministic plans, no-op idempotence (hash and mtime preserved), concurrent publish atomicity, staging-file placement and cleanup, mid-copy source-change detection, large-file round-trip hashes, well-formed `--json` NDJSON, exit-code mapping, and more.

It is complementary to `cargo test`: the Rust tests exercise the code from inside the process, the harness exercises the shipped binary from outside with real filesystem and race conditions.

```powershell
cargo build --release
pwsh -NoProfile -File scripts/vibe-harness.ps1
# or point at a specific binary
pwsh -NoProfile -File scripts/vibe-harness.ps1 -OrbitPath path\to\orbit.exe
```

Each check prints `[PASS]` or `[FAIL]` with a one-line detail. The script exits non-zero if any check fails and leaves its temp fixtures in place for inspection.
53 changes: 53 additions & 0 deletions docs/superpowers/plans/2026-09-23-single-file-copy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Single-file copy implementation plan

> Execute in this session with strict test-first changes. Scope is only `orbit copy` for one regular local file.

**Goal:** Add a staged, verified, no-clobber single-file copy command while preserving the read-only planner.

**Architecture:** Parse `plan` and `copy` into distinct request variants. Reuse endpoint resolution, scanning, and planning for preflight. A new executor writes a sibling staging file, syncs and verifies it, then atomically publishes it with create-if-absent hard-link semantics and removes the staging name. Reporting emits a concise copy result through the existing human/JSON/quiet conventions.

**Tech stack:** Rust 2024, standard library filesystem APIs, BLAKE3, clap, serde, existing integration-test stack.

---

## Task 1: Define the command contract

**Files:** `src/request.rs`, `src/cli.rs`, `src/main.rs`, `tests/cli_contract.rs`

1. Add failing parser tests for `orbit copy SOURCE DESTINATION`, hash verification by default, `--verify size`, JSON/quiet exclusion, and rejection of plan-only flags such as `--replace`.
2. Run `cargo test --test cli_contract copy` and confirm the tests fail because `copy` is unknown.
3. Add `CopyRequest` and a top-level request enum; extend clap parsing and dispatch without changing `plan` behavior.
4. Run the focused tests and commit.

## Task 2: Build the staged executor

**Files:** `src/copy.rs`, `src/lib.rs`, `src/error.rs`

1. Add failing unit tests for copying to a missing destination, hash/size verification, identical destination no-op, differing destination refusal, directory/symlink refusal, missing parent, destination race, and staging cleanup.
2. Run `cargo test copy::tests` and confirm failures before implementation.
3. Implement preflight through the existing resolver/scanner/planner, require exactly one regular-file entry, create a unique sibling stage with `create_new`, stream and `sync_all`, verify against the planned digest or size, publish with `hard_link(stage, destination)`, and remove the staging link.
4. Fail closed on unsupported publication or races. Add stable domain errors for non-file sources, existing different destinations, verification mismatch, missing destination parent, and incomplete staging cleanup.
5. Run the focused unit tests and commit.

## Task 3: Add copy reporting and application flow

**Files:** `src/app.rs`, `src/report.rs`, `src/main.rs`, `tests/cli_contract.rs`

1. Add failing CLI tests for human success, JSON result, quiet success, visible quiet errors, and identical no-op.
2. Run those tests and confirm failure.
3. Add `run_copy` and `CopyResult` reporting. Human output identifies copied/no-op status; JSON emits one `copy_result` event with schema version 1; quiet emits nothing on success. Preserve exit code 3 for domain refusal and 1 for report/internal failures.
4. Run focused CLI tests and commit.

## Task 4: Prove safety boundaries

**Files:** `tests/copy_integration.rs`, `README.md`

1. Add integration tests proving a different existing destination is byte-for-byte unchanged, a racing destination is never overwritten, no partial destination appears after injected/observable failure paths, directory and link sources are rejected, and no `.orbit-*.partial` files remain after ordinary failures.
2. Run `cargo test --test copy_integration` and confirm each new assertion exercises the implementation.
3. Document the exact copy boundary and deferred replacement behavior in the README.
4. Run formatting, linting, the full suite, and an optimized build:
`cargo fmt --check`
`cargo clippy --all-targets --all-features -- -D warnings`
`cargo test --all-targets --all-features`
`cargo build --release`
5. Review the final diff for scope and commit.
42 changes: 42 additions & 0 deletions docs/superpowers/specs/2026-09-23-single-file-copy-design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Orbit single-file copy design

## Goal

Add the first write operation to Orbit: safely copy one regular local file to a new local destination. This is deliberately smaller than a general-purpose copy engine so its safety properties can be established before adding replacement, directories, resume, or remote storage.

## User contract

`orbit copy SOURCE DESTINATION` accepts one regular file as its source.

- The destination's parent directory must already exist.
- A missing destination is eligible for copying.
- An existing destination with identical content is a successful no-op.
- An existing destination with different content is refused without modification.
- Symbolic links, directories, special files, and remote endpoints remain unsupported.
- Hash verification is the default; size verification remains available explicitly.
- Failures use Orbit's existing diagnostics, JSON/human/quiet output conventions, and non-zero exit codes.

## Execution model

Orbit first reuses the existing planner and refuses to execute any blocked or unsupported plan. For an eligible file it then:

1. Creates a uniquely named staging file beside the destination using create-new semantics.
2. Streams the source into the staging file without modifying the source.
3. Flushes the staging file to stable storage.
4. Verifies the staged content against the source using the selected verification mode.
5. Publishes the staged file with an atomic no-replace operation.
6. Removes staging material on failure and reports its exact path if cleanup cannot be completed.

Publishing must never overwrite a path that appears after planning. Platform-specific code is acceptable for the final atomic no-replace step; unsupported filesystems fail closed rather than falling back to a partial or overwriting copy.

## Boundaries

This milestone does not add replacement, backup/rollback, recursive directory copy, resumability, parallel transfer, metadata preservation beyond ordinary file creation, cloud protocols, a daemon, or a language split. Rust remains the right implementation language for this small filesystem core; the broader full-stack question remains open for later user interfaces and services.

## Recovery and observability

The destination is either absent or complete and verified. A failed operation never exposes a partial destination under the requested name. Reports identify whether the result was copied, already identical, refused, or failed, and include stable machine-readable error codes in JSON mode. Temporary names use an Orbit-reserved pattern and are never silently treated as completed files.

## Verification

Tests cover successful copy, byte-for-byte equality, identical-destination no-op, differing-destination refusal, destination-creation races, source mutation detection, unsupported source types, missing parent directories, staging cleanup, reporting modes, and injected I/O failures. Existing planner behavior remains unchanged.
Loading
Loading