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
7 changes: 7 additions & 0 deletions .claude/skills/sc-cli-reference/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,13 @@ cargo run --bin sc -- transcript show <ref> [--identity <key>] # decrypt + pri
cargo run --bin sc -- transcript list [<ref>] [--json] # list transcripts (never decrypts)
cargo run --bin sc -- transcript sign <ref> [--identity <key>] # retroactively sign a tip's
# transcript(s) (P30)
cargo run --bin sc -- transcript drop <id> [--identity <key>] # drop a transcript by id/hex prefix (see `list`): writes
# a tombstone that travels with fetch/clone so a peer
# that still has it cannot restore it; gc reclaims the
# body (loose: after the grace window; already packed: next gc). Not erasure. --identity
# signs the tombstone; peers honor it only if that key
# is under [signers] trusted (unsigned = local-only).
# Propagates on the peer's next fetch (ADR-0038 addendum)
cargo run --bin sc -- ws harvest --transcript <path> [--sign] [--identity <key>] # attach the
# file to each harvested workspace's landed snapshot
# (P30; landing status prints before the attach)
Expand Down
2 changes: 1 addition & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ the code, those win.
| P27 | Partial clone: `sc clone --filter <prefix…>`, `.sc/promisor`, `sc backfill [--all]`; wire `PROTOCOL_VERSION` 3 | [0037](docs/adr/0037-partial-clone.md) |
| P28 | Security hardening: `MAX_OBJECT_SIZE` (256 MiB) caps on every untrusted transfer length; strict ref-name validation | [0039](docs/adr/0039-security-hardening-sweep.md) |
| P29 | `sc serve --http` access control: bearer tokens (`sc serve token`), `--read-only`, fail-closed non-loopback bind gate | [0040](docs/adr/0040-sc-http-access-control.md) |
| P30 | Sealed agent-session transcripts: `sc transcript attach/show/list/sign`, always-encrypted body, gc-coupled index | [0038](docs/adr/0038-agent-session-transcripts.md) |
| P30 | Sealed agent-session transcripts: `sc transcript attach/show/list/sign/drop`, always-encrypted body, gc-coupled index; drop = grow-only tombstone (a bare `Transcript` object, no wire change), kept by gc, hides the body from fetch/reindex | [0038](docs/adr/0038-agent-session-transcripts.md) |
| P31 | Listener resource limits: `--max-connections`, `--timeout`, `--max-pack-size` (both transports), capped read-only drain, accept backoff | [0041](docs/adr/0041-listener-resource-limits.md) |
| P32 | In-binary TLS: `sc+https://` via leaf crate `tlsio`; accept-new TOFU pinning; public plaintext bind no longer justified by tokens alone | [0042](docs/adr/0042-in-binary-tls-sc-https.md) |
| P33 | Randomized protected sealing (fresh DEK + nonce; `RANDOMIZED` perms bit); dual-read of pre-P33 convergent ciphertext; per-checkout keyed stat cache; `sc rewrap` upgrades convergent blobs at the tip | [0043](docs/adr/0043-randomized-protected-encryption.md) |
Expand Down
12 changes: 6 additions & 6 deletions ROADMAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,12 @@ across every phase.
failing closed on ciphertext while the right identity decrypts the exact
body bytes, the `sc log` marker, and `sc gc` pruning a deleted branch's
transcript while the still-reachable one survives — run twice, zero
residue. No new dependency. (ADR-0038.)
residue. No new dependency. Issue #212 added `sc transcript drop <id>`: a
grow-only drop tombstone (a bare `Transcript` object, so no wire change)
hides the body from `list`/`show`, travels with fetch/clone, blocks
resurrection in either arrival order, and is kept by gc while the dropped
body is swept at gc (after the grace window if loose). (ADR-0038 addendum;
delivery gaps tracked in #230.)

- **Phase 32 — In-binary TLS (`sc+https://`).** Closes the audit's High #1
(plaintext bearer tokens/traffic on `sc+http://`) and ADR-0036's "no TLS"
Expand Down Expand Up @@ -868,11 +873,6 @@ scale-&-reach horizon):
<path>` requires an explicit path today; auto-discovering a
conventional transcript location (e.g. an agent-runner-written temp
file) per workspace is deferred.
- **`sc transcript drop` + resurrection tombstone (P30).** There is no
command to remove an attached transcript short of gc-by-unreachability;
a first-class drop with a tombstone (so a later merge of a pre-drop
branch can't silently resurrect it, mirroring P16's revocation
tombstones) is deferred.
- **Transcript access lifecycle (P30).** Transcripts have no
rewrap/grant/revoke surface — sealed once, to the recipient set at
attach time, permanently. Extending P17's rewrap and P16's
Expand Down
25 changes: 25 additions & 0 deletions crates/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,22 @@ enum TranscriptOp {
#[arg(long)]
json: bool,
},
/// Drop a transcript by id (or unique id prefix) from `sc transcript
/// list`. Records a tombstone that travels with fetch/push, so a peer
/// that still has the transcript cannot bring it back; `sc gc` reclaims
/// the body (a loose one after `--prune-expire`, but one already packed
/// by an earlier gc at the next gc). Not erasure: peers that never
/// receive the tombstone keep the sealed body. Without `--identity` the
/// drop is local-only: peers honor a tombstone only when it is signed by
/// a key in their `[signers] trusted` list.
Drop {
/// Transcript id as shown by `sc transcript list` (hex prefix).
id: String,
/// Sign the tombstone with this v2 identity so trusting peers honor
/// it (default: unsigned, local-only).
#[arg(long)]
identity: Option<PathBuf>,
},
/// Sign every transcript attached to a ref's tip snapshot.
Sign {
/// Branch or remote-tracking ref whose tip snapshot's transcripts
Expand Down Expand Up @@ -3016,6 +3032,15 @@ fn run_transcript(op: TranscriptOp) -> Result<()> {
}
Ok(())
}
TranscriptOp::Drop { id, identity } => {
let signer = identity.map(|p| load_identity_full(Some(p))).transpose()?;
let tid = repo.drop_transcript(&id, signer.as_ref())?;
println!("dropped transcript {}", tid.short());
if signer.is_none() {
eprintln!("note: unsigned drop is local-only; pass --identity to let trusting peers honor it");
}
Ok(())
}
TranscriptOp::Sign { r#ref, identity } => {
let tip = resolve_ref_tip(&repo, &r#ref)?;
let ident = load_identity_full(identity)?;
Expand Down
65 changes: 65 additions & 0 deletions crates/cli/tests/transcripts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,3 +288,68 @@ fn ws_harvest_transcript_prints_landing_before_reporting_attach_failure() {

std::fs::remove_dir_all(&root).unwrap();
}

#[test]
fn drop_removes_transcript_from_list_and_show() {
let root = tmp("drop");
let repo = root.join("work");
std::fs::create_dir_all(&repo).unwrap();
let keys = root.join("keys");
std::fs::create_dir_all(&keys).unwrap();
let (id, enc_pk, _sig_pk) = keygen(&keys, "alice");
assert!(sc(&repo, &["init"]).status.success());
std::fs::write(
repo.join(".sc/recipients.toml"),
format!("[recipients]\nalice = \"{enc_pk}\"\n"),
)
.unwrap();
std::fs::write(repo.join("a.txt"), "hello\n").unwrap();
assert!(sc(&repo, &["commit", "-m", "c1"]).status.success());
let body = keys.join("session.txt");
std::fs::write(&body, "USER: hi\n").unwrap();
assert!(sc(
&repo,
&["transcript", "attach", "main", body.to_str().unwrap()]
)
.status
.success());

let list = stdout(&sc(&repo, &["transcript", "list", "--json"]));
let tid = serde_json::from_str::<serde_json::Value>(&list).unwrap()[0]["transcript"]
.as_str()
.unwrap()
.to_string();

let drop = sc(
&repo,
&[
"transcript",
"drop",
&tid[..12],
"--identity",
id.to_str().unwrap(),
],
);
assert!(
drop.status.success(),
"{}",
String::from_utf8_lossy(&drop.stderr)
);
assert!(stdout(&sc(&repo, &["transcript", "list"])).contains("no transcripts"));
let show = stdout(&sc(
&repo,
&[
"transcript",
"show",
"main",
"--identity",
id.to_str().unwrap(),
],
));
assert!(show.contains("no transcripts attached"), "{show}");
assert!(
!sc(&repo, &["transcript", "drop", &tid]).status.success(),
"dropping twice is an error"
);
std::fs::remove_dir_all(&root).unwrap();
}
46 changes: 46 additions & 0 deletions crates/core/src/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,36 @@ pub struct Transcript {
pub wrapped_keys: Vec<WrappedKey>,
}

impl Transcript {
/// `agent` marker of a drop tombstone (ADR-0038 addendum).
pub const DROP_AGENT: &'static str = "sc-transcript-drop-v1";

/// The tombstone for transcript `dropped` on `snapshot`: a transcript-shaped
/// object with no envelope, so it rides existing packs with no wire change.
pub fn drop_tombstone(snapshot: ObjectId, dropped: &ObjectId) -> Self {
Transcript {
snapshot,
agent: Self::DROP_AGENT.to_string(),
session: dropped.to_hex(),
nonce: Vec::new(),
ciphertext: Vec::new(),
wrapped_keys: Vec::new(),
}
}

/// The transcript id this object drops, or `None` for a real transcript
/// (a sealed one always has a ciphertext and at least one wrap).
pub fn dropped_id(&self) -> Option<ObjectId> {
let bare =
self.nonce.is_empty() && self.ciphertext.is_empty() && self.wrapped_keys.is_empty();
if bare && self.agent == Self::DROP_AGENT {
self.session.parse().ok()
} else {
None
}
}
}

/// A sealed private-branch object (P34, ADR-0044): the canonical encoding of
/// some inner object (snapshot, tree, or blob) encrypted under a fresh random
/// per-object DEK — payload is `nonce(24) ‖ AEAD ciphertext`. Which inner kind
Expand Down Expand Up @@ -1135,6 +1165,22 @@ mod tests {
);
}

#[test]
fn drop_tombstone_round_trips_and_is_distinct_from_a_real_transcript() {
let snap = ObjectId::of(b"snap");
let dropped = ObjectId::of(b"dropped");
let tomb = Transcript::drop_tombstone(snap, &dropped);
let back = Object::decode(&Object::Transcript(tomb.clone()).encode()).unwrap();
assert_eq!(back, Object::Transcript(tomb.clone()));
assert_eq!(tomb.dropped_id(), Some(dropped));
// Same agent marker but a real envelope is not a tombstone.
let real = Transcript {
ciphertext: vec![1],
..tomb
};
assert_eq!(real.dropped_id(), None);
}

#[test]
fn transcript_decode_rejects_fabricated_wrap_count() {
// TAG_TRANSCRIPT(6) + snapshot(32) + agent str(0) + session str(0)
Expand Down
2 changes: 1 addition & 1 deletion crates/gitio/src/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ fn count_transcripts(
let mut count = 0;
for id in store.all_ids()? {
if let Object::Transcript(t) = store.get(&id)? {
if seen_snaps.contains(&t.snapshot) {
if seen_snaps.contains(&t.snapshot) && t.dropped_id().is_none() {
count += 1;
}
}
Expand Down
53 changes: 52 additions & 1 deletion crates/repo/src/gc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ pub struct GcStats {
/// to the ordinary loose-object prune, not counted here.
pub signatures_pruned: usize,
/// Transcript index entries dropped (P30) because their snapshot fell
/// out of the reachable set this pass; their transcript objects fall
/// out of the reachable set this pass, or because a drop tombstone hides
/// them; their transcript objects fall
/// through to the ordinary loose-object prune, not counted here.
pub transcripts_pruned: usize,
}
Expand Down Expand Up @@ -787,6 +788,56 @@ mod tests {
std::fs::remove_dir_all(&root).unwrap();
}

#[test]
fn gc_reclaims_a_dropped_transcript_and_keeps_its_tombstone() {
let root = tmp_root("transcript-drop");
let repo = crate::repo::Repo::init(&root).unwrap();
std::fs::write(root.join("a.txt"), b"base").unwrap();
let base = repo.commit("t", "base").unwrap();
let (_s, identity) = scl_crypto::generate_identity_v2();
let keep = repo
.attach_transcript(base, "a", "keep", b"keep", &[identity.enc.public()])
.unwrap();
let gone = repo
.attach_transcript(base, "a", "gone", b"gone", &[identity.enc.public()])
.unwrap();
repo.sign_transcript(gone, &identity).unwrap();
repo.drop_transcript(&gone.to_hex(), Some(&identity))
.unwrap();

let stats = repo.gc(Duration::from_secs(0)).unwrap();
assert_eq!(
stats.transcripts_pruned, 1,
"the dropped entry purged from the index is counted"
);

let tomb = {
let drops = std::fs::read_to_string(repo.layout().transcript_drops_path()).unwrap();
let line = drops.lines().next().expect("tombstone line survives gc");
line.split_whitespace()
.nth(1)
.unwrap()
.parse::<ObjectId>()
.unwrap()
};
let arc = repo.vfs().store();
let s = arc.lock().unwrap();
assert!(!s.contains(&gone), "dropped body is reclaimed");
assert!(s.contains(&keep), "other transcripts survive");
assert!(s.contains(&tomb), "tombstone is rooted");
drop(s);
assert!(repo.signatures_for(&gone).unwrap().is_empty());
assert_eq!(
repo.signatures_for(&tomb).unwrap().len(),
1,
"the tombstone's signature is kept with it"
);
assert_eq!(transcripts::load(repo.layout()).unwrap().len(), 1);

drop(repo);
std::fs::remove_dir_all(&root).unwrap();
}

/// Build a repo at `root` with `src/a.txt` and `docs/b.txt` in separate
/// subtrees, one commit. Returns `(repo, src blob id, docs blob id)`.
fn tmp_repo_with_src_and_docs(
Expand Down
6 changes: 6 additions & 0 deletions crates/repo/src/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ impl Layout {
pub fn transcripts_path(&self) -> PathBuf {
self.dot_sc.join("transcripts")
}
/// `.sc/transcript-drops` — the transcript drop-tombstone index (ADR-0038
/// addendum): one `<snapshot-hex> <tombstone-hex> <dropped-hex>` line per
/// dropped transcript. Never pruned by gc.
pub fn transcript_drops_path(&self) -> PathBuf {
self.dot_sc.join("transcript-drops")
}
/// `.sc/tmp` — scratch space for transient files (P25 streaming pack
/// transfer: spilled sender/receiver pack bodies). Never durable state —
/// safe to delete at any time; callers that write here are responsible
Expand Down
12 changes: 12 additions & 0 deletions crates/repo/src/signatures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,18 @@ pub(crate) fn reindex(layout: &Layout, store: &mut scl_core::Store) -> Result<us
Ok(count)
}

/// The whole signature index as `signed target -> signature object ids`, read
/// once so a caller checking many targets does not rescan the file per target.
pub(crate) fn index_by_target(
layout: &Layout,
) -> Result<std::collections::HashMap<ObjectId, Vec<ObjectId>>> {
let mut out: std::collections::HashMap<ObjectId, Vec<ObjectId>> = Default::default();
for (target, sig_id) in read_index(layout)? {
out.entry(target).or_default().push(sig_id);
}
Ok(out)
}

/// Sender-side seam (Task 3): the indexed signature object ids covering any
/// of `snapshots`, deduped and sorted — the set a push/export needs to
/// carry alongside the snapshots themselves so the receiving repo's index
Expand Down
Loading
Loading