Skip to content

feat: guard playground CLI command (T7)#30

Merged
kaicianflone merged 5 commits into
mainfrom
feat/guard-playground
Mar 28, 2026
Merged

feat: guard playground CLI command (T7)#30
kaicianflone merged 5 commits into
mainfrom
feat/guard-playground

Conversation

@kaicianflone
Copy link
Copy Markdown
Collaborator

Summary

Guard Playground (T7) — an interactive CLI tool that makes guard decisions transparent and explorable. The EXPLAIN ANALYZE for consensus governance.

consensus-tools playground runs 4 evaluators against any input and shows a colored vote breakdown:

  • 3 cross-cutting guard templates (security, compliance, user-impact) from the facade's regex path
  • 1 domain-specific evaluator (code-merge, send-email, deployment, etc.)

Ships with 15 canned scenarios across all 7 guard domains for zero-config first-run experience.

Commits:

  • Scenario fixtures — 15 JSON files covering safe/risky for all 7 domains + edge case for code-merge
  • Evaluation engine — playground.ts with fail-closed error handling, path traversal protection, scenario schema validation
  • Colored renderer — chalk-based vote table, decision banner, hard-block flag display
  • CLI wiring — top-level playground command with --domain, --scenario, --input, --list, --json
  • Tests — 23 tests (16 evaluation + 7 renderer)
  • TODOS — T18 added for util.styleText evaluation as chalk replacement

Pre-Landing Review

4-pass adversarial review completed (Claude structured + Claude adversarial + Codex structured + Codex adversarial). 10 findings across all passes, all fixed:

  • Fail-open error handling → fail-closed (NO votes on error)
  • Non-deterministic default scenario → sorted file list
  • Scenario name mislabeled → derive from sorted list
  • Path traversal in --scenario → containment check
  • Type confusion on domain → String() coercion
  • Payload falsy value confusion → ?? instead of ||
  • No schema validation → domain/payload field checks
  • parseInput fallthrough → clear error message
  • JSON.stringify circular ref → try/catch
  • TODOS.md updated with T18

Test Coverage

43 tests pass (23 new + 20 existing). Coverage: 87% of code paths tested.

Test plan

  • All CLI tests pass (43 tests, 0 failures)
  • TypeScript clean (tsc --noEmit passes)
  • Zero-config consensus-tools playground produces colored output
  • All 7 domains have canned scenarios
  • Custom input via --input works with JSON strings and file paths
  • --list shows all available scenarios

🤖 Generated with Claude Code

kaicianflone and others added 5 commits March 28, 2026 01:06
15 scenarios across all 7 guard domains (safe + risky for each,
plus edge case for code-merge). Designed to trigger both cross-cutting
guard template rules and domain-specific evaluator checks.
Adds `consensus-tools playground` command infrastructure:
- playground.ts: 4-vote evaluation (3 cross-cutting guard templates +
  1 domain-specific evaluator), hard-block detection, fail-closed error
  handling, scenario loading with path traversal protection, schema
  validation on loaded scenarios
- playground-renderer.ts: colored vote breakdown table with chalk,
  truncation, decision banner
- Adds @consensus-tools/guards and chalk as CLI dependencies
Top-level `consensus-tools playground` command with flags:
--domain, --scenario, --input, --list, --json.
Supports canned scenarios, custom JSON input, and file paths.
Domain normalization (dash to underscore) for custom input mode.
23 tests covering: scenario loading (valid/invalid/default), input
parsing (JSON/file/malformed/missing), evaluation flow (4 votes,
ALLOW/BLOCK/REWRITE, hard-block flags, unknown domain, null payload),
and renderer output (domain/scenario labels, vote rows, decision
banner, flag display, reason truncation).
Track potential chalk replacement with Node 20.12+ built-in
util.styleText for reduced CLI dependency footprint.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@kaicianflone kaicianflone force-pushed the feat/guard-playground branch from 4fb5d69 to b4989ec Compare March 28, 2026 05:06
@kaicianflone kaicianflone merged commit df7f7bc into main Mar 28, 2026
3 checks passed
@kaicianflone kaicianflone deleted the feat/guard-playground branch March 28, 2026 18:38
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.

1 participant