Skip to content
Closed
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
2 changes: 1 addition & 1 deletion .github/workflows/id-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,4 @@ jobs:
sudo udevadm trigger --name-match=kvm

- name: Run nix flake check
run: nix flake check ./pkgs/id/ -L
run: nix flake check ./pkgs/id/ -L --keep-going
5 changes: 4 additions & 1 deletion .opencode/plans/phase-9-portable-platform.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ The immediate slice (P9.1) is a backwards-compatible, validated cell-grid presen
- **P9.3b in PR #225:** source builds attach server-observed compiler/platform/source digests, target, and stable arguments to the install event; raw artifact installs are labeled as artifacts. Metadata survives restart/checkpoint and is available through the additive module-info field. This is not a trust attestation. The latest full Nix check failed in Firefox E2E, tracked in issue #229; Rust build/lint checks passed. Human-readable compiler version remains open; server/per-world capability ceilings are tracked in issue #230.
- **P9.3c complete:** define optional per-world resource requests that inherit server limits when absent and clamp to the stricter server hard ceiling when present. Capability ceilings remain separate.
- **P9.3d in PR #228:** persist profiles per durable world and apply them only when a new instance is installed or restored. Runtime changes are not applied to an existing guest; the admin API communicates that boundary. Focused Rust tests and the PR run check passed; rollback compatibility is tracked in issue #227.
- **P9.3e in progress (issue #230):** server and per-world capability ceilings bound which granted host capabilities authority reaches. The server ceiling is `serve --world-allowed-caps` (runtime configuration); the world ceiling is durable and applies immediately, and it never rewrites grants. Record: [world capability ceilings](../../doc/2026-10-16T11-00-00Z_feature_world_capability_ceilings/2026-10-16T11-00-00Z_feature_world_capability_ceilings.md).
- **P9.3e in PR #231:** server and per-world capability ceilings bound which granted host capabilities authority reaches. The server ceiling is `serve --world-allowed-caps` (runtime configuration); the world ceiling is durable and applies immediately, and it never rewrites grants. Record: [world capability ceilings](../../doc/2026-10-16T11-00-00Z_feature_world_capability_ceilings/2026-10-16T11-00-00Z_feature_world_capability_ceilings.md).
- **P9.3f complete in this worktree:** operator CLI commands for capability ceilings (`id world caps --ceiling`) and execution profiles (`id world profile`). Record: [world CLI controls](../../doc/2026-10-16T12-00-00Z_feature_world_cli_controls/2026-10-16T12-00-00Z_feature_world_cli_controls.md).
- **P9.2a complete in this worktree:** focusable browser surfaces encode common keys with terminal-compatible bytes and send them through the existing durable input event. SSH already forwards PTY bytes through that same event.
- **P9.2b complete in PR #219:** bounded paste is an explicit input event; browser ResizeObserver and SSH PTY/window-change events set connection-local viewport context. Structured screens are cropped per connection without entering the journal. Roc apps still render at their declared dimensions; guest-aware reflow remains a future ABI follow-up.
- **P9.4 first slice complete in this worktree:** pure-Roc `RocJson.roc` decode/encode and typed accessors are exported by the Roc world platform; lounge now decodes host events and encodes requests/records. Broader data/game/communication helpers remain planned.
Expand Down Expand Up @@ -57,6 +58,8 @@ P9.3d record: [durable per-world resource profiles](../../doc/2026-10-16T10-30-0

P9.3e record: [world capability ceilings](../../doc/2026-10-16T11-00-00Z_feature_world_capability_ceilings/2026-10-16T11-00-00Z_feature_world_capability_ceilings.md).

P9.3f record: [world operator CLI controls](../../doc/2026-10-16T12-00-00Z_feature_world_cli_controls/2026-10-16T12-00-00Z_feature_world_cli_controls.md).

## P9.3a acceptance

- Source-only is an explicit server option, off by default, and requires an enabled world plus a configured server-side Roc compiler/platform.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# World Operator CLI Controls for Capability Ceilings and Resource Profiles

See the [Phase 9 plan](../../.opencode/plans/phase-9-portable-platform.md), the [resource profile record](../2026-10-16T10-30-00Z_feature_durable_world_resource_profiles/2026-10-16T10-30-00Z_feature_durable_world_resource_profiles.md), and the [capability ceilings record](../2026-10-16T11-00-00Z_feature_world_capability_ceilings/2026-10-16T11-00-00Z_feature_world_capability_ceilings.md).

## Intent

Expose client-side operator CLI commands under `id world` for managing world capability ceilings and execution profiles over Iroh:

1. `id world caps <NODE> [--grant <G>] [--revoke <R>] [--ceiling <C1,C2,...>]`: configure capability ceilings alongside grants.
2. `id world profile <NODE> [--admin-token <T>] [--wasm-fuel <N>] [--wasm-memory <BYTES>] [--wasm-message <BYTES>] [--native-cpu <SECS>] [--native-memory <BYTES>] [--native-deadline <MS>]`: inspect or update the persisted resource execution profile.

## Decisions

- **Caps ceiling flag:** Added `--ceiling` to `id world caps`. Setting a ceiling requires `--admin-token`. When combined with `--grant` or `--revoke`, the ceiling is applied and then grants/revocations are updated, returning the authoritative `CapsReport`.
- **Profile command:** Added `id world profile` subcommand. When any resource bound is passed, `--admin-token` is required to persist the new profile, returning an `ExecutionProfileUpdate` notice with `applies_on_next_program_install_or_process_restart: true`. When no limit flag is passed, queries and prints the current persisted profile (authorized by `--admin-token` or guest `--capability`).
- **Wire protocol:** Added `ClientFrame::ExecutionProfileInfo` to query execution profile state without mutating it. Handled in both pre-join (authorized by admin token or guest capability) and post-join session phases.
- **CLI memory efficiency:** Boxed `Command::World(Box<WorldCommand>)` in `Cli` to reduce stack allocation pressure in clap parsers.

## Acceptance

- `id world caps NODE --ceiling time.now,chat.say --admin-token ADMIN` sets the ceiling over Iroh and prints the updated report.
- `id world profile NODE --admin-token ADMIN --wasm-fuel 500000` updates the profile and reports deferred activation.
- `id world profile NODE --capability CAP` reads the current profile.
- Unauthenticated queries are rejected with access denied.
- 106 CLI parser tests and 245 world tests pass.
3 changes: 3 additions & 0 deletions pkgs/id/.cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ coverage = "llvm-cov --html --open"

# Quick test - just lib tests (no integration tests)
test-lib = "test --lib"

[env]
RUST_MIN_STACK = "8388608"
7 changes: 7 additions & 0 deletions pkgs/id/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,13 @@
name: justCmd:
pkgs.stdenv.mkDerivation {
name = "id-${name}";
# Every check builds its own debug test binaries in parallel on a
# runner with limited disk. Full debuginfo and the incremental cache
# filled the disk (ENOSPC, then a linker bus error). Line tables keep
# file:line in panics and backtraces.
CARGO_INCREMENTAL = "0";
CARGO_PROFILE_TEST_DEBUG = "line-tables-only";
CARGO_PROFILE_DEV_DEBUG = "line-tables-only";
src = ./.;
inherit buildInputs;
nativeBuildInputs = nativeBuildInputs ++ [
Expand Down
215 changes: 181 additions & 34 deletions pkgs/id/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1040,7 +1040,7 @@ pub enum Command {
/// ID_WORLD_CAPABILITY=... id world join NODE_ID
/// ```
#[command(subcommand)]
World(WorldCommand),
World(Box<WorldCommand>),
/// Groups: create, show the policy, add, remove, set roles, list, and join (P6.7a).
///
/// Each action records one event in the group log and prints one line, or one JSON object with
Expand Down Expand Up @@ -1558,9 +1558,9 @@ pub enum WorldCommand {
#[arg(long)]
no_relay: bool,
},
/// Show (and, with `--grant`/`--revoke`, change) a world's capabilities.
/// Show (and, with `--grant`/`--revoke`/`--ceiling`, change) a world's capabilities.
///
/// Without `--grant`/`--revoke` this needs only a guest capability and
/// Without `--grant`/`--revoke`/`--ceiling` this needs only a guest capability and
/// prints what the world has granted, what its program wants, and what it
/// has used. With them it needs the admin token.
Caps {
Expand All @@ -1578,6 +1578,52 @@ pub enum WorldCommand {
/// Capability to revoke (repeatable).
#[arg(long)]
revoke: Vec<String>,
/// Capability ceiling to set (comma-separated or repeatable; only known capabilities, no `*`).
#[arg(long, value_delimiter = ',')]
ceiling: Option<Vec<String>>,
/// World on the host to use (default: the host's default world).
#[arg(long, env = "ID_WORLD")]
world: Option<String>,
/// Direct socket address of the host (repeatable); skips discovery.
#[arg(long = "addr")]
addrs: Vec<SocketAddr>,
/// Disable relay servers (direct connection only).
#[arg(long)]
no_relay: bool,
},
/// View or configure a world's requested execution profile bounds.
///
/// When any limit option (`--fuel`, `--wasm-memory`, etc.) is specified,
/// `--admin-token` is required to persist the new profile. When no limits
/// are specified, prints the current persisted profile (requires either
/// `--admin-token` or a guest `--capability`).
Profile {
/// The host's node ID (64 hex characters).
node: String,
/// Admin secret configured with `serve --world-admin-token`.
#[arg(long, env = "ID_WORLD_ADMIN_TOKEN", hide_env_values = true)]
admin_token: Option<String>,
/// Guest capability from `id world invite` (sufficient to inspect the profile).
#[arg(long, env = "ID_WORLD_CAPABILITY", hide_env_values = true)]
capability: Option<String>,
/// Requested Wasm fuel limit per transaction/event.
#[arg(long, visible_alias = "fuel")]
wasm_fuel: Option<u64>,
/// Requested Wasm linear memory in bytes.
#[arg(long, visible_alias = "wasm-memory")]
wasm_memory_bytes: Option<u64>,
/// Requested Wasm message payload limit in bytes.
#[arg(long, visible_alias = "wasm-message")]
wasm_message_bytes: Option<u64>,
/// Requested native address-space cap in bytes.
#[arg(long, visible_alias = "native-memory")]
native_memory_bytes: Option<u64>,
/// Requested native CPU cap in seconds.
#[arg(long, visible_alias = "native-cpu")]
native_cpu_seconds: Option<u64>,
/// Requested native call deadline in milliseconds.
#[arg(long, visible_alias = "native-deadline")]
native_call_deadline_ms: Option<u64>,
/// World on the host to use (default: the host's default world).
#[arg(long, env = "ID_WORLD")]
world: Option<String>,
Expand Down Expand Up @@ -3521,9 +3567,12 @@ mod tests {
"t",
]);
match cli.command {
Some(Command::World(WorldCommand::CrossWorldWrite { mode, .. })) => {
assert_eq!(mode, "on");
}
Some(Command::World(cmd)) => match *cmd {
WorldCommand::CrossWorldWrite { mode, .. } => {
assert_eq!(mode, "on");
}
other => panic!("unexpected: {other:?}"),
},
other => panic!("unexpected: {other:?}"),
}
let cli = Cli::parse_from([
Expand All @@ -3536,7 +3585,7 @@ mod tests {
]);
assert!(matches!(
cli.command,
Some(Command::World(WorldCommand::ForceCrossWorldWrite { .. }))
Some(Command::World(cmd)) if matches!(*cmd, WorldCommand::ForceCrossWorldWrite { .. })
));
let cli = Cli::parse_from([
"id",
Expand All @@ -3550,14 +3599,17 @@ mod tests {
"t",
]);
match cli.command {
Some(Command::World(WorldCommand::FileScope {
scope,
write_override,
..
})) => {
assert_eq!(scope, "unrestricted");
assert_eq!(write_override.as_deref(), Some("on"));
}
Some(Command::World(cmd)) => match *cmd {
WorldCommand::FileScope {
scope,
write_override,
..
} => {
assert_eq!(scope, "unrestricted");
assert_eq!(write_override.as_deref(), Some("on"));
}
other => panic!("unexpected: {other:?}"),
},
other => panic!("unexpected: {other:?}"),
}
assert!(
Expand Down Expand Up @@ -3603,18 +3655,21 @@ mod tests {
"--no-relay",
]);
match cli.command {
Some(Command::World(WorldCommand::Invite {
admin_token,
name,
addrs,
no_relay,
..
})) => {
assert_eq!(admin_token, "t");
assert_eq!(name, "ann");
assert_eq!(addrs.len(), 1);
assert!(no_relay);
}
Some(Command::World(cmd)) => match *cmd {
WorldCommand::Invite {
admin_token,
name,
addrs,
no_relay,
..
} => {
assert_eq!(admin_token, "t");
assert_eq!(name, "ann");
assert_eq!(addrs.len(), 1);
assert!(no_relay);
}
other => panic!("unexpected: {other:?}"),
},
other => panic!("unexpected: {other:?}"),
}
let cli = Cli::parse_from([
Expand All @@ -3632,12 +3687,15 @@ mod tests {
"2",
]);
match cli.command {
Some(Command::World(WorldCommand::Invite {
expires_in, uses, ..
})) => {
assert_eq!(expires_in, Some(259_200));
assert_eq!(uses, Some(2));
}
Some(Command::World(cmd)) => match *cmd {
WorldCommand::Invite {
expires_in, uses, ..
} => {
assert_eq!(expires_in, Some(259_200));
assert_eq!(uses, Some(2));
}
other => panic!("unexpected: {other:?}"),
},
other => panic!("unexpected: {other:?}"),
}
assert!(
Expand Down Expand Up @@ -3667,7 +3725,96 @@ mod tests {
]);
assert!(matches!(
cli.command,
Some(Command::World(WorldCommand::Join { after: Some(7), .. }))
Some(Command::World(cmd)) if matches!(*cmd, WorldCommand::Join { after: Some(7), .. })
));
}

#[test]
fn test_cli_parse_world_caps_ceiling() {
let node = "a".repeat(64);
let cli = Cli::parse_from([
"id",
"world",
"caps",
&node,
"--admin-token",
"adm",
"--ceiling",
"time.now,chat.say",
]);
match cli.command {
Some(Command::World(cmd)) => match *cmd {
WorldCommand::Caps {
admin_token,
ceiling,
..
} => {
assert_eq!(admin_token, Some("adm".to_owned()));
assert_eq!(
ceiling,
Some(vec!["time.now".to_owned(), "chat.say".to_owned()])
);
}
other => panic!("unexpected: {other:?}"),
},
other => panic!("unexpected: {other:?}"),
}
}

#[test]
fn test_cli_parse_world_profile() {
let node = "a".repeat(64);
let cli = Cli::parse_from([
"id",
"world",
"profile",
&node,
"--admin-token",
"adm",
"--wasm-fuel",
"500000",
"--wasm-memory",
"16777216",
"--native-cpu",
"10",
]);
match cli.command {
Some(Command::World(cmd)) => match *cmd {
WorldCommand::Profile {
admin_token,
wasm_fuel,
wasm_memory_bytes,
native_cpu_seconds,
capability,
..
} => {
assert_eq!(admin_token, Some("adm".to_owned()));
assert_eq!(wasm_fuel, Some(500000));
assert_eq!(wasm_memory_bytes, Some(16777216));
assert_eq!(native_cpu_seconds, Some(10));
assert!(capability.is_none());
}
other => panic!("unexpected: {other:?}"),
},
other => panic!("unexpected: {other:?}"),
}

let cli = Cli::parse_from(["id", "world", "profile", &node, "--capability", "cap123"]);
match cli.command {
Some(Command::World(cmd)) => match *cmd {
WorldCommand::Profile {
admin_token,
capability,
wasm_fuel,
..
} => {
assert_eq!(admin_token, None);
assert_eq!(capability, Some("cap123".to_owned()));
assert!(wasm_fuel.is_none());
}
other => panic!("unexpected: {other:?}"),
},
other => panic!("unexpected: {other:?}"),
}
}
}
Loading
Loading