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
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Tag scope: local-only vs shared claims (#1793)

## 2026-11-08T06-25-00Z Design: tag scopes for pkgs/id

### Request

Issue #1793 bullet 2: tags (and petnames) can be scoped local-only or
shared, chosen at create/edit time, honoured by replication, and
existing tags can be reviewed and organised by scope. Bullet 1 (file
origin in listings) landed separately in PR #5191; this record covers
only the scope work, implemented in PR #7344.

### Design approach

- `TagScope` (`shared` | `local`) is carried on every live `Claim`,
defaulting to `shared`, so already-landed claims decode and behave
exactly as before. No migration reclassifies an existing claim.
- The signed `tag.set` wire form is untouched: no field is added, so
v1 event IDs and encodings are unchanged and a shared claim is
replicated exactly as it was before scopes existed.

### Persistence boundary

- Shared claims live in the signed event store, as before.
- Local claims live in a separate store beside the event store
(`local-claims.jsonl`, rewritten atomically). A local claim is never
signed and never enters the event store, so it never enters the
range-sync set and cannot reach another node. A test pins the sync
set unchanged across a local set/clear.

### Publication behaviour

- `tags_on`, `search` and the review listing merge shared and local
claims; every row carries its scope, so the two kinds are never
silently conflated.
- CLI: `id claim set --scope local|shared` selects scope at create
time; `id claim scope SUBJECT NAME SCOPE` moves a claim between
scopes; `id claim review` lists every visible claim with its scope.

### Scope-conversion trade-offs

- Moving shared → local copies the claim into the local store and
then clears only this node's own shared claims, by claim ID, so
another author's same-named claims are untouched.
- Moving local → shared publishes only this node's own local claims
(filtered by author) under its signing key, and then removes only
its own local originals. Publishing another identity's local claims
— possible when two identities share one `--event-store` with
different data directories — would leak claims their owner chose to
keep private; the author filter is the guard, and it matches the
shared → local direction.
- A move changes where a claim lives, never its name or value.

### Petnames

Petnames were already viewer-private by construction (local journal,
shown only to the owning account, never replicated). No scope choice
was added for them; existing tests pin the private behaviour.

---

## 2026-11-08T06-25-00Z Update: record created during review

This record was written when PR #7344's Codex review flagged its
absence (pkgs/id/AGENTS.md requires the record for new commands, a
new persistent store, and scope-conversion semantics). It documents
the design as implemented in that PR, plus the author-filter guard
for local → shared conversion added in the same review round.
1 change: 1 addition & 0 deletions pkgs/id/src/aliases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ mod tests {
subject,
name: name.to_owned(),
value: value.map(str::to_owned),
scope: crate::tag_claims::TagScope::Shared,
}
}

Expand Down
25 changes: 25 additions & 0 deletions pkgs/id/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2646,6 +2646,9 @@ pub enum ClaimCommand {
name: String,
/// The tag value. Without one, the tag is bare.
value: Option<String>,
/// Whether the claim is shared with peers or stays on this node.
#[arg(long, value_enum, default_value = "shared")]
scope: ClaimScope,
},
/// Clear the live claims with this name on a subject, whoever set them.
Clear {
Expand All @@ -2661,13 +2664,35 @@ pub enum ClaimCommand {
/// The tag value to match as a whole. Without one, any value and a bare tag match.
value: Option<String>,
},
/// Change the scope of this node's claims with this name on a subject.
Scope {
/// The subject's event ID.
subject: String,
/// The tag name.
name: String,
/// The target scope.
#[arg(value_enum)]
scope: ClaimScope,
},
/// Review every live claim visible to this node, with its scope.
Review,
/// List the live claims on a subject.
List {
/// The subject's event ID.
subject: String,
},
}

/// Where a tag claim lives: shared with peers, or on this node only (#1793).
#[derive(ValueEnum, Clone, Copy, Debug, Default, PartialEq, Eq)]
pub enum ClaimScope {
/// Published to the shared claim set and replicated, the v1 default.
#[default]
Shared,
/// Kept on this node only; never published or synced.
Local,
}

/// Subcommands for `id tag`.
///
/// Manage metadata tags (key/value pairs) attached to files.
Expand Down
53 changes: 49 additions & 4 deletions pkgs/id/src/commands/claim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ use anyhow::Result;
use p2panda_core::Hash;
use serde_json::{Value, json};

use crate::cli::ClaimCommand;
use crate::cli::{ClaimCommand, ClaimScope};
use crate::commands::doc::{open_events, print_action, print_rows};
use crate::commands::group::hex;
use crate::groups::log::hash_from_hex;
use crate::tag_claims::Claim;
use crate::tag_claims::{Claim, TagScope};

/// Prints a `set` line for a claim just recorded.
pub(super) fn print_set(json: bool, subject: Hash, name: &str, value: Option<&str>, event: Hash) {
Expand All @@ -42,6 +42,7 @@ fn claim_fields(claim: &Claim) -> Vec<(&'static str, Value)> {
fields.push(("value", json!(value)));
}
fields.push(("author", json!(hex(&claim.author))));
fields.push(("scope", json!(claim.scope.as_str())));
fields.push(("event", json!(claim.id.to_hex())));
fields
}
Expand All @@ -59,10 +60,24 @@ pub async fn cmd_claim(path: Option<PathBuf>, json: bool, command: ClaimCommand)
subject,
name,
value,
scope,
} => {
let subject = hash_from_hex(&subject)?;
let event = events.set_tag(subject, &name, value.as_deref())?;
print_set(json, subject, &name, value.as_deref(), event);
let scope = match scope {
ClaimScope::Shared => TagScope::Shared,
ClaimScope::Local => TagScope::Local,
};
let claim = events.set_tag_scoped(subject, &name, value.as_deref(), scope)?;
let mut fields = vec![
("subject", json!(subject.to_hex())),
("name", json!(name)),
("scope", json!(scope.as_str())),
("event", json!(claim.to_hex())),
];
if let Some(value) = value {
fields.push(("value", json!(value)));
}
print_action(json, "set", fields);
}
ClaimCommand::Clear { subject, name } => {
let subject = hash_from_hex(&subject)?;
Expand All @@ -87,6 +102,36 @@ pub async fn cmd_claim(path: Option<PathBuf>, json: bool, command: ClaimCommand)
.collect();
print_rows(json, &rows);
}
ClaimCommand::Scope {
subject,
name,
scope,
} => {
let subject = hash_from_hex(&subject)?;
let scope = match scope {
ClaimScope::Shared => TagScope::Shared,
ClaimScope::Local => TagScope::Local,
};
let moved = events.set_tag_scope(subject, &name, scope)?;
print_action(
json,
"scope",
vec![
("subject", json!(subject.to_hex())),
("name", json!(name)),
("scope", json!(scope.as_str())),
("moved", json!(moved)),
],
);
}
ClaimCommand::Review => {
let rows: Vec<Vec<(&str, Value)>> = events
.review_tags()?
.iter()
.map(claim_fields)
.collect();
print_rows(json, &rows);
}
ClaimCommand::List { subject } => {
let subject = hash_from_hex(&subject)?;
let rows: Vec<Vec<(&str, Value)>> =
Expand Down
1 change: 1 addition & 0 deletions pkgs/id/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ pub mod invites;
pub mod issuer_rotation;
pub(crate) mod key_envelope;
pub mod local;
pub mod local_claims;
pub mod local_events;
pub mod log_sync;
mod peer_announcement;
Expand Down
Loading
Loading