Skip to content

feat(cli): operator terms display + acceptance at registration (#1077) - #1079

Merged
alpergundogdu merged 3 commits into
mainfrom
claude/cli-terms-acceptance
Jul 7, 2026
Merged

alpergundogdu merged 3 commits into
mainfrom
claude/cli-terms-acceptance

Conversation

@alpergundogdu

@alpergundogdu alpergundogdu commented Jul 7, 2026 •

Copy link
Copy Markdown
Contributor

Closes #1077. Implements the operator-facing half of ADR 019 § Terms Acceptance — the on-chain enforcement + governor-swappable currentTermsHash shipped in #1078.

Behaviour

decdn node register / decdn setup read the network's currentTermsHash, then gate registration on acceptance:

Context Behaviour
Terminal Print the terms + version + hash, prompt Accept these operator terms? [y/N] (default no)
Headless / automation Require --accept-terms; error clearly without it — scripted provisioning keeps working, consent stays explicit
Stale client If the embedded terms hash ≠ the network's currentTermsHash, refuse — never sign terms the operator wasn't shown (ADR 019 §281)
  • New commands::terms: embeds the canonical TERMS.md via include_str!, so the displayed text is the exact preimage of the recorded hash (no external document to fetch/substitute). decide is the pure policy; ensure_accepted is the thin IO wrapper.
  • --accept-terms added to both commands. In setup it's separate from --yes (which only skips the bond-amount confirmation) — terms acceptance is always its own explicit act.
  • Terms display + prompt go to stderr, so --json stdout stays machine-parseable.

Design choice

Prompt-with-flag-fallback (chosen over interactive-only / flag-only): interactive operators get your y/N flow; headless operator provisioning (decdn setup in CI/scripts) uses --accept-terms instead of hanging on a prompt.

Tests

  • Pure decide matrix (stale precedence, flag, TTY, headless).
  • Real ensure_accepted branches (the test harness has no TTY, so headless/flag/stale run for real against the actual embedded hash).
  • Hash lock: keccak256(TERMS.md) pinned to 0x7da33feb… (== cast keccak of the raw file), so a terms edit is a deliberate, test-gated event that must be paired with a governance setCurrentTermsHash bump + new CURRENT_TERMS_HASH deploy value.

Local: cargo fmt/clippy clean, 622 cli/common tests pass, binary --help shows the flag in both commands.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Added --accept-terms option for setup and node registration.
    • Node registration now fetches the network’s current terms hash and requires acceptance that matches it.
    • When needed, interactive confirmation prompts are shown; headless runs require --accept-terms.
  • Bug Fixes
    • Registration now commits to and enforces the caller’s network terms hash, preventing stale or mismatched approvals (dry-run behavior remains non-submitting).
  • Tests
    • Added automated coverage for terms-hash validation and acceptance decision behavior.

Implements the operator-facing half of ADR 019 § Terms Acceptance (the on-chain
enforcement shipped in #1078).

- New `commands::terms`: embeds the canonical TERMS.md (`include_str!`), so the
  displayed text is the exact preimage of the recorded hash. `decide` is the
  pure acceptance policy; `ensure_accepted` is the IO wrapper.
- `decdn node register` / `decdn setup` read the network's `currentTermsHash`,
  then gate registration on acceptance:
  - Terminal: print the terms + version + hash, prompt `[y/N]` (default no).
  - Headless/automation: require `--accept-terms` (errors clearly without it) —
    keeps scripted provisioning working while keeping consent explicit.
  - Stale client: if the embedded terms hash != the network's currentTermsHash,
    refuse — never sign terms the operator wasn't shown (ADR 019 § 281).
- `--accept-terms` added to both commands (setup keeps it separate from `--yes`,
  which only skips the bond confirmation).
- Terms display + prompt go to stderr so `--json` stdout stays clean.

Tests: pure `decide` matrix, real `ensure_accepted` branches (headless/flag/
stale), and a lock on `keccak256(TERMS.md)` so a terms edit is a gated event
paired with a governance setCurrentTermsHash bump.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Copilot AI review requested due to automatic review settings July 7, 2026 16:46
@coderabbitai

coderabbitai Bot commented Jul 7, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: fc3b7b11-5e2a-4da4-92c6-9b13d9e9883e

📥 Commits

Reviewing files that changed from the base of the PR and between 13e9851 and f88ae55.

📒 Files selected for processing (3)
  • crates/cli/src/commands/register.rs
  • crates/cli/src/commands/setup.rs
  • crates/cli/src/commands/terms.rs
🚧 Files skipped from review as they are similar to previous changes (3)
  • crates/cli/src/commands/register.rs
  • crates/cli/src/commands/setup.rs
  • crates/cli/src/commands/terms.rs

Walkthrough

Adds a terms module that embeds canonical operator terms, computes their hash, and enforces acceptance. Adds --accept-terms flags to register/setup CLI args, and wires terms-hash fetching and acceptance checks into registration before passing terms_hash into submission.

Changes

Operator terms acceptance for node registration

Layer / File(s) Summary
Terms module and acceptance policy
crates/cli/src/commands/terms.rs
Embeds TERMS.md, adds terms_hash() and terms_version(), defines Decision and decide(), implements ensure_accepted() and ensure_accepted_async(), adds IO helpers, and includes unit tests.
CLI flags and registration wiring
crates/common/src/cli/node.rs, crates/common/src/cli/setup.rs, crates/cli/src/commands/mod.rs, crates/cli/src/commands/register.rs, crates/cli/src/commands/setup.rs
Adds --accept-terms to RegisterArgs and SetupArgs, exports the new terms module, reads currentTermsHash(), enforces acceptance, and threads terms_hash into submit_registration.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Possibly related issues

Possibly related PRs

  • decdn/decdn#1044: Provides the canonical TERMS.md text whose preimage is embedded and hashed by this PR.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and accurately summarizes the CLI terms display and acceptance work.
Linked Issues check ✅ Passed The changes implement operator terms display, explicit acceptance, stale-hash checks, and termsHash signing for register/setup as required by #1077.
Out of Scope Changes check ✅ Passed The added terms module, CLI flags, and registration/setup flow changes are all in scope for ADR 019 terms acceptance.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/cli-terms-acceptance

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

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request implements operator-terms acceptance at registration (ADR 019) by embedding the canonical terms in the binary, verifying their hash against the network's current terms, and prompting the operator for acceptance (or accepting via a new --accept-terms CLI flag). Feedback on the changes suggests checking both stdin and stderr terminal status to prevent potential silent hangs when stderr is redirected.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread crates/cli/src/commands/terms.rs Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR implements the CLI-side operator terms acceptance flow required by ADR 019 during node registration, ensuring the registration signature commits to the network’s currentTermsHash and that operators explicitly accept the displayed terms (or pass --accept-terms in headless automation).

Changes:

  • Add a new commands::terms module that embeds TERMS.md, computes keccak256 hash, and enforces acceptance via a prompt/flag policy with tests.
  • Add --accept-terms to both decdn setup and decdn node register, and gate registration on acceptance + on-chain currentTermsHash.
  • Thread terms_hash into the registration submission/signature path.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
crates/common/src/cli/setup.rs Adds --accept-terms flag to setup CLI args.
crates/common/src/cli/node.rs Adds --accept-terms flag to node registration CLI args.
crates/cli/src/commands/terms.rs New module embedding terms text, hashing, acceptance policy, prompting, and tests.
crates/cli/src/commands/setup.rs Reads currentTermsHash and enforces acceptance before registration in setup flow.
crates/cli/src/commands/register.rs Reads currentTermsHash, enforces acceptance (but currently skipped on --dry-run), and passes terms_hash into signing/submission.
crates/cli/src/commands/mod.rs Exposes the new terms command module.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread crates/cli/src/commands/register.rs Resolved
Comment thread crates/cli/src/commands/terms.rs Resolved
…for terms

Gemini review on #1079: if stderr is redirected but stdin is a TTY, the terms
+ prompt print to the invisible stderr and the process blocks on stdin — a
silent hang. Gate the interactive path on both streams being terminals;
otherwise fall back to requiring --accept-terms.

Co-Authored-By: Claude Opus 4.8 <[email protected]>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@crates/cli/src/commands/setup.rs`:
- Around line 335-345: The terms acceptance check in setup happens too late,
allowing bond::execute to commit before refusal or stale terms can abort the
flow. Move the currentTermsHash/ensure_accepted logic in setup.rs to run before
calling bond::execute, and gate it on !already_registered so registration/bond
submission only proceeds after acceptance. Use the existing setup path around
bond::execute, currentTermsHash, and terms::ensure_accepted to keep the
acceptance gate ahead of any transaction side effects.

In `@crates/cli/src/commands/terms.rs`:
- Around line 81-125: The interactive prompt path in ensure_accepted blocks a
tokio worker thread because it performs synchronous stderr/stdin I/O when called
from async handlers like setup::run and register::run. Move only the prompt
branch off the runtime thread by wrapping the print_terms and prompt_yes_no flow
in spawn_blocking, or convert the prompt to async stdin handling, while keeping
the non-interactive Decision branches unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 81d63f3f-34a9-408a-9c8a-31ac64c98507

📥 Commits

Reviewing files that changed from the base of the PR and between 0d73fe3 and e70a89f.

📒 Files selected for processing (6)
  • crates/cli/src/commands/mod.rs
  • crates/cli/src/commands/register.rs
  • crates/cli/src/commands/setup.rs
  • crates/cli/src/commands/terms.rs
  • crates/common/src/cli/node.rs
  • crates/common/src/cli/setup.rs

Comment thread crates/cli/src/commands/setup.rs Resolved
Comment thread crates/cli/src/commands/terms.rs Resolved
Review round on #1079 (Copilot + CodeRabbit):

- register --dry-run now also enforces terms acceptance: a dry run still emits a
  real, submit-able signature committing to termsHash, so it must not be produced
  over unseen/stale terms. (Copilot)
- setup accepts terms BEFORE bond::execute (gated on !already_registered) so a
  refusal / stale-client aborts before the bond is spent, not after. Extracted
  `accept_terms_if_registering` helper (keeps setup::run under the cognitive-
  complexity limit). (CodeRabbit)
- New `terms::ensure_accepted_async` runs the blocking prompt via spawn_blocking
  so it never parks a tokio worker; call sites use it. (CodeRabbit)
- (stderr-redirect interactive check already landed in the prior commit.)

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown

Coverage report

Total: 81.99% (was 82.06%, ▼ 0.07%) — 42468/51797 lines

File Coverage Lines Δ
crates/cli/src/commands/register.rs 27.66% 52/188 ▼ 1.07%
crates/cli/src/commands/setup.rs 47.66% 336/705 ▼ 2.12%
crates/cli/src/commands/terms.rs 76.42% 81/106 new
History
Commit Total Δ vs base
f88ae55 (HEAD) 81.99% ▼ 0.07%

@alpergundogdu
alpergundogdu merged commit ae78222 into main Jul 7, 2026
22 checks passed
@alpergundogdu
alpergundogdu deleted the claude/cli-terms-acceptance branch July 7, 2026 17:28
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.

cli: decdn register/setup — display operator terms + carry termsHash acceptance in the registration signature (ADR 019 §241)

2 participants