diff --git a/skills-stub/README.md b/.agents/skills/README.md similarity index 51% rename from skills-stub/README.md rename to .agents/skills/README.md index 8523f9d..0102492 100644 --- a/skills-stub/README.md +++ b/.agents/skills/README.md @@ -1,15 +1,17 @@ -# Bezel skills-stub +# Bezel skills -This directory is the skills input for the Bezel flake until you point -`inputs.skills` at your own skills repo. The flake uses this path: +This directory is the canonical skills tree and the flake input: ```nix -inputs.skills.url = "path:./skills-stub"; +inputs.skills.url = "path:./.agents/skills"; ``` When you have a skills repo, change only that URL (and lock). Do **not** add -a second repo-root `skills/` tree — the Home Manager module only symlinks -`${inputs.skills}`. +a repo-root `skills/` tree, `.omp/skills/`, or `.codex/skills/`. + +`scripts/sync-skills` rewrites the regular-file copies in `.claude/skills/`, +`.grok/skills/`, and `.cursor/skills/` from this tree. Edit here, then sync. +Those copies are not a second source. Shipped skills: @@ -28,8 +30,18 @@ prints the same JSON envelope: `{ ok, command, exit, data, error }`. The Nushell that runs them is the one pinned by this flake's nixpkgs lock. MCP servers for those tools stay supported; this tree does not turn them off. -Copy or link one directory into another harness's skills folder -(`~/.agents/skills/` or `~/.claude/skills/`). With Home Manager, the whole -input is already linked at `~/.config/omp/agent/skills`. +`programs.bezel.enable` copies each skill directory, as regular files, into: + +- `~/.agents/skills` +- `~/.claude/skills` +- `~/.grok/skills` +- `~/.cursor/skills` + +A second run leaves a file alone when its bytes already match, and it keeps +that file's mode. If a managed file already exists with different bytes, or +the path is a symlink, `scripts/install-user-skills.sh` prints a drift report +and writes nothing. `--force` replaces the bytes and keeps the existing mode. +`--check` reports drift and writes nothing. Unrelated skill directories +already in those folders are left in place. -See [docs/SPIKE-stanley.md](../docs/SPIKE-stanley.md). +See [docs/SPIKE-stanley.md](../../docs/SPIKE-stanley.md). diff --git a/.agents/skills/bootstrap/SKILL.md b/.agents/skills/bootstrap/SKILL.md new file mode 100644 index 0000000..359840e --- /dev/null +++ b/.agents/skills/bootstrap/SKILL.md @@ -0,0 +1,13 @@ +--- +name: bootstrap +description: Placeholder skill shipped with the Bezel skills tree until a skills repository is published. Replace the flake skills input. Harness copies are generated from .agents/skills. +--- + +# bootstrap + +This skill exists so the skills flake input is a valid skills directory +(`*/SKILL.md`) until you point the flake skills input at a skills repository. + +Home Manager copies each skill directory as regular files into the user +directories the harnesses read: `~/.agents/skills`, `~/.claude/skills`, +`~/.grok/skills`, and `~/.cursor/skills`. diff --git a/skills-stub/check/SKILL.md b/.agents/skills/check/SKILL.md similarity index 100% rename from skills-stub/check/SKILL.md rename to .agents/skills/check/SKILL.md diff --git a/skills-stub/facet/SKILL.md b/.agents/skills/facet/SKILL.md similarity index 100% rename from skills-stub/facet/SKILL.md rename to .agents/skills/facet/SKILL.md diff --git a/skills-stub/facet/facet.nu b/.agents/skills/facet/facet.nu similarity index 100% rename from skills-stub/facet/facet.nu rename to .agents/skills/facet/facet.nu diff --git a/skills-stub/geode/SKILL.md b/.agents/skills/geode/SKILL.md similarity index 100% rename from skills-stub/geode/SKILL.md rename to .agents/skills/geode/SKILL.md diff --git a/skills-stub/geode/geode.nu b/.agents/skills/geode/geode.nu similarity index 100% rename from skills-stub/geode/geode.nu rename to .agents/skills/geode/geode.nu diff --git a/skills-stub/lapis/SKILL.md b/.agents/skills/lapis/SKILL.md similarity index 100% rename from skills-stub/lapis/SKILL.md rename to .agents/skills/lapis/SKILL.md diff --git a/skills-stub/lapis/lapis.nu b/.agents/skills/lapis/lapis.nu similarity index 100% rename from skills-stub/lapis/lapis.nu rename to .agents/skills/lapis/lapis.nu diff --git a/skills-stub/laws/LAWS.bend b/.agents/skills/laws/LAWS.bend similarity index 100% rename from skills-stub/laws/LAWS.bend rename to .agents/skills/laws/LAWS.bend diff --git a/skills-stub/laws/PROOF.bend b/.agents/skills/laws/PROOF.bend similarity index 100% rename from skills-stub/laws/PROOF.bend rename to .agents/skills/laws/PROOF.bend diff --git a/skills-stub/laws/SKILL.md b/.agents/skills/laws/SKILL.md similarity index 100% rename from skills-stub/laws/SKILL.md rename to .agents/skills/laws/SKILL.md diff --git a/.claude/skills/bootstrap/SKILL.md b/.claude/skills/bootstrap/SKILL.md new file mode 100644 index 0000000..359840e --- /dev/null +++ b/.claude/skills/bootstrap/SKILL.md @@ -0,0 +1,13 @@ +--- +name: bootstrap +description: Placeholder skill shipped with the Bezel skills tree until a skills repository is published. Replace the flake skills input. Harness copies are generated from .agents/skills. +--- + +# bootstrap + +This skill exists so the skills flake input is a valid skills directory +(`*/SKILL.md`) until you point the flake skills input at a skills repository. + +Home Manager copies each skill directory as regular files into the user +directories the harnesses read: `~/.agents/skills`, `~/.claude/skills`, +`~/.grok/skills`, and `~/.cursor/skills`. diff --git a/.claude/skills/check/SKILL.md b/.claude/skills/check/SKILL.md new file mode 100644 index 0000000..2e6dd7a --- /dev/null +++ b/.claude/skills/check/SKILL.md @@ -0,0 +1,50 @@ +--- +name: check +description: Bounded Jev-first check of a git diff. Code gathers evidence, Jev classifies, code applies thresholds. Empty findings are not approval. +--- + +# check + +Thin overlay skill for a bounded diff check. Prefer this +workflow when the user asks to check a diff against a task. + +## Run (shadow default) + +```sh +# Key from the environment only — never flags or files. +export TYPESAFE_API_KEY # host card store / your shell; omit to smoke without live Jev + +# Worktree + staged, or inject a unified diff: +jev-router --check --intent "" +jev-router --check --intent "" --base origin/main +jev-router --check --intent "" --diff-file path/to.diff +``` + +`JEV_MODE` defaults to `shadow`: Choice is logged; **shadow never blocks**. +Missing `TYPESAFE_API_KEY` in shadow continues — hunks land in `notChecked`. + +## Result contract + +Stdout is one JSON object: + +| Field | Meaning | +| --- | --- | +| `findings` | Deterministic or Jev-threshold hits | +| `parked` | Unclear; a human should look | +| `notChecked` | Skipped, unjudged, or out of scope | +| `approval` | Always `false` on this path | +| `emptyFindingsAreNotApproval` | Always `true` | + +**Empty `findings` is not approval.** Do not tell the user the change is +approved, LGTM, or safe to merge because the list is empty. + +## Available-gate + +`check` (and the `review` routing stub) require a git diff. No diff → +`status: "no_diff"` and `cannot_tell` — do not invent a pass. + +## Do not + +- Invoke a `stanley` binary, another agent binary, improve-worker, or promote loop +- Pass `TYPESAFE_API_KEY` as a flag or write it to a file +- Auto-activate agent-drafted skills diff --git a/.claude/skills/facet/SKILL.md b/.claude/skills/facet/SKILL.md new file mode 100644 index 0000000..6932a0b --- /dev/null +++ b/.claude/skills/facet/SKILL.md @@ -0,0 +1,44 @@ +--- +name: facet +description: > + Inspect Facet HTTP request history, sessions, pins, and stored-value + metadata through the facet CLI. Use when a task needs to know what requests + ran, their status and timing, or to compare two runs. Prefer this skill over + the facet MCP server: it adds no tool schemas to context. The MCP server + remains available. +--- + +# facet — request history skill + +Read-only. The body is the fixed script `facet.nu` next to this file. Every +wrapped command appends `--json` (facet expects it after the subcommand). +Do not reimplement the calls. + +## Commands + +```bash +nu facet.nu history [path] [--limit 20] [--request sel] [--status 200] [--session id] +nu facet.nu last [path] [--request sel] +nu facet.nu sessions [--open] +nu facet.nu session +nu facet.nu pins [path] +nu facet.nu env [path] [--environment e] # names only, never values +nu facet.nu diff [path] # hashes only +nu facet.nu doctor +``` + +Each command prints one JSON envelope: `{ ok, command, exit, data, error }`. +`diff` uses `exit` 1 to mean the runs differ (`data.same` is false); that is +still `ok: true`. + +## Not wrapped, on purpose + +`facet.nu` refuses these and does not call facet: + +- `history --bodies`, `history --id`, `blob`, `diff --bodies`: these can print + recorded request or response bodies and headers, which may carry tokens. +- `request run`, including `request run --dry-run`: a preview resolves + variables, so it can show a hydrated secret. +- `replay`, `env set`, `env delete`, `pin`, `gc --yes`, + `session start/end`: these change state or send traffic. Run them only when + a human has explicitly asked, and never pass a secret value on the command line. diff --git a/.claude/skills/facet/facet.nu b/.claude/skills/facet/facet.nu new file mode 100755 index 0000000..9f48255 --- /dev/null +++ b/.claude/skills/facet/facet.nu @@ -0,0 +1,246 @@ +#!/usr/bin/env nu +# Fixed read-only body for the facet skill. Wraps `facet` with `--json` +# after the subcommand. +# stdout is one JSON envelope: {ok, command, exit, data, error} +# Never calls history --bodies, history --id, blob, diff --bodies, or request run. + +const BLOCKED = ["--bodies" "--id" "blob" "--dry-run"] +const OWN_FLAGS = ["--limit" "--request" "--status" "--session" "--open" "--environment"] + +def clip-error [stderr: string, stdout: string] { + let joined = ([$stderr $stdout] | str join " " | str trim) + if ($joined | is-empty) { + "command failed" + } else { + ($joined | lines | first | str substring 0..399) + } +} + +def ok-row [command: string, exit: int, data: any] { + { ok: true, command: $command, exit: $exit, data: $data, error: null } +} + +def err-row [command: string, exit: int, error: string] { + { ok: false, command: $command, exit: $exit, data: null, error: ($error | str substring 0..399) } +} + +def as-text [raw: any] { + let d = ($raw | describe) + if $d == "string" { + $raw + } else { + try { $raw | decode utf-8 } catch { "" } + } +} + +def parse-json [text: string] { + let t = ($text | str trim) + if ($t | is-empty) { + error make { msg: "empty json" } + } + $t | from json --strict +} + +def opt [flag: string, v: string] { + if $v == "" { [] } else { [$flag $v] } +} + +def pos [v: string] { + if $v == "" { [] } else { [$v] } +} + +def blocked-argv [args: list] { + let joined = ($args | str join " ") + ($args | any {|a| $a in $BLOCKED }) or ($joined | str contains "request run") or ($joined | str contains "request --dry-run") +} + +def ascii-lower [text: string] { + let pairs = [ + [A a] [B b] [C c] [D d] [E e] [F f] [G g] [H h] [I i] [J j] + [K k] [L l] [M m] [N n] [O o] [P p] [Q q] [R r] [S s] [T t] + [U u] [V v] [W w] [X x] [Y y] [Z z] + ] + $pairs | reduce --fold $text {|p, acc| + $acc | str replace --all ($p | get 0) ($p | get 1) + } +} + +def secret-key [name: string] { + let lowered = (ascii-lower $name) + $lowered in [ + value values secret token password authorization + header headers body bodies raw content cookie cookies + request_body response_body + ] +} + +def env-name-key [name: string] { + let chars = ($name | split chars) + if ($chars | is-empty) { + false + } else { + $chars | all {|c| $c =~ "[A-Z0-9_]" } + } +} + +def redact [v: any] { + let d = ($v | describe) + if ($d | str starts-with "list") or ($d | str starts-with "table") { + $v | each {|item| redact $item } + } else if ($d | str starts-with "record") { + let cols = ($v | columns | where {|c| not (secret-key $c) }) + if ($cols | is-empty) { + {} + } else { + $cols | reduce --fold {} {|c, acc| + let val = ($v | get $c) + let vd = ($val | describe) + if (env-name-key $c) and $vd == "string" { + $acc | upsert $c null + } else { + $acc | upsert $c (redact $val) + } + } + } + } else { + $v + } +} + +def with-same [parsed: any, same: bool] { + let d = ($parsed | describe) + if ($d | str starts-with "record") { + $parsed | merge { same: $same } + } else { + { same: $same, report: $parsed } + } +} + +def run-facet [command: string, args: list, ok_codes: list = [0], redact_values: bool = false, embed_same: bool = false] { + let stray = ($args | where {|a| ($a | str starts-with "-") and (not ($a in $OWN_FLAGS)) }) + if (blocked-argv $args) or (not ($stray | is-empty)) { + err-row $command 2 "refused: history bodies, blob, diff --bodies, and request run are not available from this skill" + } else { + let r = (try { + ^facet ...$args --json | complete + } catch {|e| + { stdout: "", stderr: $"facet: ($e.msg)", exit_code: 127 } + }) + let stdout = (as-text $r.stdout) + let stderr = (as-text $r.stderr) + if not ($r.exit_code in $ok_codes) { + err-row $command $r.exit_code (clip-error $stderr $stdout) + } else { + let parsed = (try { { ok: true, value: (parse-json $stdout) } } catch {|e| { ok: false, value: $e.msg } }) + if not $parsed.ok { + err-row $command 1 $"invalid json: ($parsed.value)" + } else { + let data = if $redact_values { redact $parsed.value } else { $parsed.value } + let out = if $embed_same { with-same $data ($r.exit_code == 0) } else { $data } + ok-row $command $r.exit_code $out + } + } + } +} + +def "main history" [ + path: string = "", + --limit: int = 20, + --request: string = "", + --status: string = "", + --session: string = "", + --bodies, + --id: string = "", + ...rest: string, +] { + if $bodies or $id != "" or not ($rest | is-empty) or (blocked-argv (pos $path)) { + err-row "history" 2 "refused: history bodies are not available from this skill" | to json --raw + } else if $limit < 1 { + err-row "history" 2 "limit must be >= 1" | to json --raw + } else { + let args = ( + ["history"] + ++ (pos $path) + ++ ["--limit" ($limit | into string)] + ++ (opt "--request" $request) + ++ (opt "--status" $status) + ++ (opt "--session" $session) + ) + run-facet "history" $args | to json --raw + } +} + +def "main last" [path: string = "", --request: string = "", --bodies, ...rest: string] { + if $bodies or not ($rest | is-empty) or (blocked-argv (pos $path)) { + err-row "last" 2 "refused: history bodies are not available from this skill" | to json --raw + } else { + run-facet "last" (["last"] ++ (pos $path) ++ (opt "--request" $request)) | to json --raw + } +} + +def "main sessions" [--open, ...rest: string] { + if not ($rest | is-empty) { + err-row "sessions" 2 "refused: facet skill is read-only" | to json --raw + } else { + let args = (["session" "list"] ++ (if $open { ["--open"] } else { [] })) + run-facet "sessions" $args | to json --raw + } +} + +def "main session" [id: string, ...rest: string] { + if not ($rest | is-empty) or ($id in ["start" "end" "delete" "rm"]) { + err-row "session" 2 "refused: session start/end is not available from this skill" | to json --raw + } else { + run-facet "session" ["session" "show" $id] | to json --raw + } +} + +def "main pins" [path: string = "", ...rest: string] { + if not ($rest | is-empty) or (blocked-argv (pos $path)) { + err-row "pins" 2 "refused: facet skill is read-only" | to json --raw + } else { + run-facet "pins" (["pin" "list"] ++ (pos $path)) | to json --raw + } +} + +def "main env" [path: string = "", --environment: string = "", ...rest: string] { + if not ($rest | is-empty) or ($path in ["set" "delete" "unset" "get" "add" "rm"]) { + err-row "env" 2 "refused: env values and env writes are not available from this skill" | to json --raw + } else { + run-facet "env" (["env" "list"] ++ (pos $path) ++ (opt "--environment" $environment)) [0] true | to json --raw + } +} + +def "main diff" [a: string, b: string, path: string = "", --bodies, ...rest: string] { + if $bodies or not ($rest | is-empty) or (blocked-argv [$a $b $path]) { + err-row "diff" 2 "refused: diff --bodies is not available from this skill" | to json --raw + } else { + # exit 1 means the runs differ; that is a result, not a failure + run-facet "diff" (["diff" $a $b] ++ (pos $path)) [0 1] false true | to json --raw + } +} + +def "main doctor" [...rest: string] { + if not ($rest | is-empty) { + err-row "doctor" 2 "refused: facet skill is read-only" | to json --raw + } else { + run-facet "doctor" ["doctor"] | to json --raw + } +} + +def "main blob" [...args: string] { + err-row "blob" 2 "refused: blob is not available from this skill" | to json --raw +} + +def "main request" [--dry-run, ...args: string] { + err-row "request" 2 "refused: request run is not available from this skill" | to json --raw +} + +def "main replay" [...args: string] { + err-row "replay" 2 "refused: replay is not available from this skill" | to json --raw +} + +def main [...args: string] { + let command = ($args | first | default "") + err-row $command 2 "refused: facet skill is read-only" | to json --raw +} diff --git a/.claude/skills/geode/SKILL.md b/.claude/skills/geode/SKILL.md new file mode 100644 index 0000000..7046b48 --- /dev/null +++ b/.claude/skills/geode/SKILL.md @@ -0,0 +1,46 @@ +--- +name: geode +description: > + Check Geode vault health and metadata through the geode CLI: entry names, + integrity, recipients, snapshots, policy, audit chain, custody status. Use + when a task asks whether a vault is intact, who can open it, or what it + holds by name. This skill never reads or prints secret values. Prefer it + over the geode MCP server. The MCP server remains available. +--- + +# geode — custody status skill (metadata only) + +The body is the fixed script `geode.nu` next to this file. Every wrapped +command uses `geode --output json`. The vault path comes from the argument or +`$GEODE_VAULT`; the identity key from `$GEODE_KEY_FILE` as usual. The script +never puts the key on the command line. Do not reimplement the calls. + +## Commands + +```bash +nu geode.nu list [vault] [prefix] # entry names and sizes, no contents +nu geode.nu verify [vault] [--sample 0.05] # default --cheap +nu geode.nu recipients [vault] # recipient types and key ids (public) +nu geode.nu snapshots [vault] +nu geode.nu policy [vault] +nu geode.nu can [vault] # dry run; deny is exit 3 +nu geode.nu audit +nu geode.nu custody +nu geode.nu keyring +``` + +Each command prints one JSON envelope: `{ ok, command, exit, data, error }`. +`can` keeps `ok: true` when geode exits 3 (deny). `audit` keeps `ok: true` +when geode exits 2 (chain failed). + +## Never run from this skill + +`geode.nu` refuses anything that is not in the list above, including `cat`, +`open`, `mount`, `run`, `agent`, `keygen`, `seal`, `sign`, `vault init`, +`vault add-recipient`, `vault rotate`, `policy set`, `keyring add`, +`custody unlock/lock`, `gc`, and `git unlock`. Those read secret bytes, put +them in an environment or on disk, or change custody. They need a human, and +their output must never be pasted into notes, logs, or chat. + +Entry names can themselves be sensitive. Quote them only where the reader is +allowed to know the vault holds them. diff --git a/.claude/skills/geode/geode.nu b/.claude/skills/geode/geode.nu new file mode 100755 index 0000000..5f722d5 --- /dev/null +++ b/.claude/skills/geode/geode.nu @@ -0,0 +1,224 @@ +#!/usr/bin/env nu +# Fixed metadata-only body for the geode skill. Wraps `geode --output json`. +# stdout is one JSON envelope: {ok, command, exit, data, error} +# Only the allowlist is passed to geode. Anything else is refused. + +const ALLOWED = [ + "list" + "verify" + "vault recipients" + "snapshot ls" + "policy show" + "policy check" + "audit verify" + "custody status" + "keyring list" +] + +def clip-error [stderr: string, stdout: string] { + let joined = ([$stderr $stdout] | str join " " | str trim) + if ($joined | is-empty) { + "command failed" + } else { + ($joined | lines | first | str substring 0..399) + } +} + +def ok-row [command: string, exit: int, data: any] { + { ok: true, command: $command, exit: $exit, data: $data, error: null } +} + +def err-row [command: string, exit: int, error: string] { + { ok: false, command: $command, exit: $exit, data: null, error: ($error | str substring 0..399) } +} + +def refused [command: string, detail: string] { + err-row $command 2 $"refused: geode skill is metadata-only ($detail)" +} + +def as-text [raw: any] { + let d = ($raw | describe) + if $d == "string" { + $raw + } else { + try { $raw | decode utf-8 } catch { "" } + } +} + +def parse-json [text: string] { + let t = ($text | str trim) + if ($t | is-empty) { + error make { msg: "empty json" } + } + $t | from json --strict +} + +def vault-path [v: string] { + if $v != "" { $v } else { $env.GEODE_VAULT? | default "" } +} + +def run-geode [ + command: string, + sub: list, + rest: list, + ok_codes: list = [0], + permit_flags: list = [], +] { + let key = ($sub | str join " ") + let flagged = ($rest | where {|a| ($a | str starts-with "-") and (not ($a in $permit_flags)) }) + if not ($key in $ALLOWED) { + refused $command $"not on the allowlist: ($key)" + } else if not ($flagged | is-empty) { + refused $command "flags are not accepted" + } else { + let argv = (["--output" "json"] ++ $sub ++ $rest) + let r = (try { + ^geode ...$argv | complete + } catch {|e| + { stdout: "", stderr: $"geode: ($e.msg)", exit_code: 127 } + }) + let stdout = (as-text $r.stdout) + let stderr = (as-text $r.stderr) + if not ($r.exit_code in $ok_codes) { + err-row $command $r.exit_code (clip-error $stderr $stdout) + } else { + let parsed = (try { { ok: true, value: (parse-json $stdout) } } catch {|e| { ok: false, value: $e.msg } }) + if not $parsed.ok { + err-row $command 1 $"invalid json: ($parsed.value)" + } else { + ok-row $command $r.exit_code $parsed.value + } + } + } +} + +def path-verb [p: string] { + $p in [ + set init add-recipient rotate add unlock lock delete rm + start end get unset cat open mount run agent keygen seal sign gc + ] +} + +def need-vault [command: string, vault: string] { + let p = (vault-path $vault) + if (path-verb $vault) { + refused $command $"($vault) is not available from this skill" + } else if $p == "" { + err-row $command 2 "no vault: pass one or set GEODE_VAULT" + } else if ($p | str starts-with "-") { + refused $command "vault path must not be a flag" + } else { + { ok: true, path: $p } + } +} + +def "main list" [vault: string = "", prefix: string = "", ...rest: string] { + if not ($rest | is-empty) { + refused "list" "extra arguments" | to json --raw + } else { + let got = (need-vault "list" $vault) + if not $got.ok { + $got | to json --raw + } else { + let rest_args = ([$got.path] ++ (if $prefix == "" { [] } else { [$prefix] })) + run-geode "list" [list] $rest_args | to json --raw + } + } +} + +def "main verify" [vault: string = "", --sample: string = "", ...rest: string] { + if not ($rest | is-empty) { + refused "verify" "extra arguments" | to json --raw + } else { + let got = (need-vault "verify" $vault) + if not $got.ok { + $got | to json --raw + } else if $sample == "" { + run-geode "verify" [verify] [$got.path "--cheap"] [0] ["--cheap"] | to json --raw + } else { + let numeric = (try { $sample | into float; true } catch {|_| false }) + if not $numeric or ($sample | str starts-with "-") { + refused "verify" "sample must be a non-negative number" | to json --raw + } else { + run-geode "verify" [verify] [$got.path "--sample" $sample] [0] ["--sample"] | to json --raw + } + } + } +} + +def "main recipients" [vault: string = "", ...rest: string] { + if not ($rest | is-empty) { + refused "recipients" "extra arguments" | to json --raw + } else { + let got = (need-vault "recipients" $vault) + if not $got.ok { $got | to json --raw } else { + run-geode "recipients" [vault recipients] [$got.path] | to json --raw + } + } +} + +def "main snapshots" [vault: string = "", ...rest: string] { + if not ($rest | is-empty) { + refused "snapshots" "extra arguments" | to json --raw + } else { + let got = (need-vault "snapshots" $vault) + if not $got.ok { $got | to json --raw } else { + run-geode "snapshots" [snapshot ls] [$got.path] | to json --raw + } + } +} + +def "main policy" [vault: string = "", ...rest: string] { + if not ($rest | is-empty) { + refused "policy" "policy set is not available from this skill" | to json --raw + } else { + let got = (need-vault "policy" $vault) + if not $got.ok { $got | to json --raw } else { + run-geode "policy" [policy show] [$got.path] | to json --raw + } + } +} + +def "main can" [principal: string, op: string, path: string, vault: string = "", ...rest: string] { + if not ($rest | is-empty) { + refused "can" "extra arguments" | to json --raw + } else if ([$principal $op $path] | any {|a| $a | str starts-with "-" }) { + refused "can" "flags are not accepted" | to json --raw + } else { + let got = (need-vault "can" $vault) + if not $got.ok { $got | to json --raw } else { + # deny exits 3; that is a result, not a failure + run-geode "can" [policy check] [$got.path $principal $op $path] [0 3] | to json --raw + } + } +} + +def "main audit" [...rest: string] { + if not ($rest | is-empty) { + refused "audit" "extra arguments" | to json --raw + } else { + # a broken chain exits 2; that is a result, not a failure + run-geode "audit" [audit verify] [] [0 2] | to json --raw + } +} + +def "main custody" [...rest: string] { + if not ($rest | is-empty) { + refused "custody" "unlock/lock is not available from this skill" | to json --raw + } else { + run-geode "custody" [custody status] [] | to json --raw + } +} + +def "main keyring" [...rest: string] { + if not ($rest | is-empty) { + refused "keyring" "keyring add is not available from this skill" | to json --raw + } else { + run-geode "keyring" [keyring list] [] | to json --raw + } +} + +def main [...args: string] { + let command = ($args | first | default "") + refused $command ($args | str join " ") | to json --raw +} diff --git a/.claude/skills/lapis/SKILL.md b/.claude/skills/lapis/SKILL.md new file mode 100644 index 0000000..9e8b3b2 --- /dev/null +++ b/.claude/skills/lapis/SKILL.md @@ -0,0 +1,52 @@ +--- +name: lapis +description: > + Search and read a Lapis notes vault through the lapis CLI. Use when a task + needs notes, doctrine, project context, wikilink neighbors, or recent notes + from the vault. Prefer this skill over the lapis MCP server: it adds no tool + schemas to context and its body is deterministic. The MCP server remains + available. +--- + +# lapis — vault read skill + +`lapis` owns the vault and its index. This skill only reads, through the +fixed script `lapis.nu` next to this file. Never open `.lapis/` index files +directly, and do not reimplement the calls. + +## Configuration + +The vault path is resolved in this order: + +1. `--vault ` passed to any command +2. `$LAPIS_VAULT` +3. the path recorded by `lapis init` in the lapis config + +## Commands + +```bash +nu lapis.nu search "phrase" --limit 5 [--domain d] +nu lapis.nu read path/to/note.md +nu lapis.nu list [--prefix projects/] +nu lapis.nu neighbors path/to/note.md +nu lapis.nu resolve "[[Note Name]]" +nu lapis.nu recent [--limit 10] +nu lapis.nu status +nu lapis.nu doctor +``` + +Each command prints one JSON envelope: `{ ok, command, exit, data, error }`. + +- `search`: BM25 over chunks (vectors only if an embedder is configured); one hit per note. `data` is `path` and `title` only. +- `read`: frontmatter (`hal`) plus body. +- `list`: index metadata only; never walks the vault. +- `neighbors`: hop-1 wikilink edges. +- `recent`: newest first. Each row is read by name: `path`, `title`, and `mtime_iso` (Lapis 0.4.2) or `mtime` (older builds). `mtime_iso` wins when both are present. +- `status` / `doctor`: vault root and index health (`exit` 2 when the index is down). + +## Rules + +- Read before you cite: give the note path and quote the passage. +- Writes (`create`, `append`, `task`, `trash`) are refused by `lapis.nu`. + Run them only when a human has explicitly asked, and not through this skill. +- If a path is missing, start `neighbors` from a hub note rather than guessing. diff --git a/.claude/skills/lapis/lapis.nu b/.claude/skills/lapis/lapis.nu new file mode 100755 index 0000000..a54633c --- /dev/null +++ b/.claude/skills/lapis/lapis.nu @@ -0,0 +1,203 @@ +#!/usr/bin/env nu +# Fixed read-only body for the lapis skill. Wraps `lapis --json`. +# stdout is one JSON envelope: {ok, command, exit, data, error} +# Vault: --vault, else $LAPIS_VAULT, else the lapis config default. + +def clip-error [stderr: string, stdout: string] { + let joined = ([$stderr $stdout] | str join " " | str trim) + if ($joined | is-empty) { + "command failed" + } else { + ($joined | lines | first | str substring 0..399) + } +} + +def ok-row [command: string, exit: int, data: any] { + { ok: true, command: $command, exit: $exit, data: $data, error: null } +} + +def err-row [command: string, exit: int, error: string] { + { ok: false, command: $command, exit: $exit, data: null, error: ($error | str substring 0..399) } +} + +def as-text [raw: any] { + let d = ($raw | describe) + if $d == "string" { + $raw + } else { + try { $raw | decode utf-8 } catch { "" } + } +} + +def parse-json [text: string] { + let t = ($text | str trim) + if ($t | is-empty) { + error make { msg: "empty json" } + } + $t | from json --strict +} + +def vault-args [vault: string] { + let v = if $vault != "" { $vault } else { $env.LAPIS_VAULT? | default "" } + if ($v | str starts-with "-") { + error make { msg: "vault path must not be a flag" } + } + if $v == "" { [] } else { ["--vault" $v] } +} + +def lapis-data [value: any] { + let d = ($value | describe) + if ($d | str starts-with "record") and ("data" in ($value | columns)) { + $value | get data + } else { + $value + } +} + +def run-lapis [command: string, args: list, vault: string] { + let vault_part = (try { vault-args $vault } catch {|e| $e.msg }) + if ($vault_part | describe) == "string" { + err-row $command 2 $vault_part + } else { + let argv = (["--json"] ++ $vault_part ++ $args) + let r = (try { + ^lapis ...$argv | complete + } catch {|e| + { stdout: "", stderr: $"lapis: ($e.msg)", exit_code: 127 } + }) + let stdout = (as-text $r.stdout) + let stderr = (as-text $r.stderr) + if $r.exit_code != 0 { + err-row $command $r.exit_code (clip-error $stderr $stdout) + } else { + let parsed = (try { { ok: true, value: (parse-json $stdout) } } catch {|e| { ok: false, value: $e.msg } }) + if not $parsed.ok { + err-row $command 1 $"invalid json: ($parsed.value)" + } else { + ok-row $command 0 (lapis-data $parsed.value) + } + } + } +} + +def flagish [s: string] { $s | str starts-with "-" } + +def "main search" [query: string, --limit (-n): int = 5, --domain: string = "", --vault: string = ""] { + if $limit < 1 { + err-row "search" 2 "limit must be >= 1" | to json --raw + } else if (flagish $query) or (flagish $domain) { + err-row "search" 2 "refused: lapis skill is read-only" | to json --raw + } else { + mut args = ["search" $query "-n" ($limit | into string)] + if $domain != "" { $args = ($args ++ ["--domain" $domain]) } + let row = (run-lapis "search" $args $vault) + if not $row.ok { + $row | to json --raw + } else { + let hits = (try { $row.data | get hits } catch {|err| null }) + let kind = ($hits | describe) + if not (($kind | str starts-with "list") or ($kind | str starts-with "table")) { + err-row "search" 1 "search data has no hits" | to json --raw + } else { + let slim = (try { $hits | select path title } catch {|err| null }) + if ($slim | describe) == "nothing" { + err-row "search" 1 "search hits missing path or title" | to json --raw + } else { + ok-row "search" $row.exit $slim | to json --raw + } + } + } + } +} + +def "main read" [path: string, --vault: string = ""] { + if (flagish $path) { + err-row "read" 2 "refused: lapis skill is read-only" | to json --raw + } else { + run-lapis "read" ["read" $path] $vault | to json --raw + } +} + +def "main list" [--prefix: string = "", --vault: string = ""] { + let row = (run-lapis "list" ["list"] $vault) + if not $row.ok or $prefix == "" { + $row | to json --raw + } else { + let kind = ($row.data | describe) + if not (($kind | str starts-with "list") or ($kind | str starts-with "table")) { + err-row "list" 1 "list data is not a list" | to json --raw + } else { + let filtered = ($row.data | where path starts-with $prefix) + ok-row "list" $row.exit $filtered | to json --raw + } + } +} + +def "main neighbors" [path: string, --vault: string = ""] { + if (flagish $path) { + err-row "neighbors" 2 "refused: lapis skill is read-only" | to json --raw + } else { + run-lapis "neighbors" ["neighbors" $path] $vault | to json --raw + } +} + +def "main resolve" [link: string, --vault: string = ""] { + if (flagish $link) { + err-row "resolve" 2 "refused: lapis skill is read-only" | to json --raw + } else { + run-lapis "resolve" ["resolve" $link] $vault | to json --raw + } +} + +# Lapis 0.4.2 rows are path, title, domain, priority, mtime_iso. +# Older builds are path, title, mtime. Read those fields by name. +def recent-mtime [row: record] { + let cols = ($row | columns) + if "mtime_iso" in $cols { + $row | get mtime_iso + } else if "mtime" in $cols { + $row | get mtime + } else { + error make { msg: "recent row missing mtime" } + } +} + +def "main recent" [--limit (-n): int = 10, --vault: string = ""] { + if $limit < 1 { + err-row "recent" 2 "limit must be >= 1" | to json --raw + } else { + let row = (run-lapis "recent" ["analytics" "recent"] $vault) + if not $row.ok { + $row | to json --raw + } else { + let rows = (try { $row.data | get rows } catch {|err| null }) + let shaped = (try { + $rows | first $limit | each {|r| + { + path: ($r | get path) + title: ($r | get title) + mtime: (recent-mtime $r) + } + } + } catch {|err| null }) + if ($shaped | describe) == "nothing" { + err-row "recent" 1 "recent data has no rows" | to json --raw + } else { + ok-row "recent" $row.exit $shaped | to json --raw + } + } + } +} + +def "main status" [--vault: string = ""] { + run-lapis "status" ["vault" "info"] $vault | to json --raw +} + +def "main doctor" [--vault: string = ""] { + run-lapis "doctor" ["doctor"] $vault | to json --raw +} + +def main [...args: string] { + let command = ($args | first | default "") + err-row $command 2 "refused: lapis skill is read-only" | to json --raw +} diff --git a/.claude/skills/laws/LAWS.bend b/.claude/skills/laws/LAWS.bend new file mode 100644 index 0000000..17ef699 --- /dev/null +++ b/.claude/skills/laws/LAWS.bend @@ -0,0 +1,85 @@ +import Base + +type Mode is Data: + Shadow{} + Active{} + +type Auto is Data: + Hold{} + Allow{} + +type Call is Data: + Denied{} + Open{} + +type Transport is Data: + Silent{} + Called{} + +type Findings is Data: + Empty{} + Present{} + +type Approval is Data: + No{} + Yes{} + +type Key is Data: + Public{} + Secret{} + +type State is Data: + Rejected{} + Seated{} + +def verdict_auto(mode: Mode) -> Auto: + match mode: + case Shadow{}: + Hold{} + case Active{}: + Hold{} + +def transport(call: Call) -> Transport: + match call: + case Denied{}: + Silent{} + case Open{}: + Called{} + +def approval(findings: Findings) -> Approval: + match findings: + case Empty{}: + No{} + case Present{}: + Yes{} + +def state(key: Key) -> State: + match key: + case Secret{}: + Rejected{} + case Public{}: + Seated{} + +law shadow_cannot_set_auto_allow: + {verdict_auto(Shadow{}) == Hold{} : Auto} + +def shadow_cannot_set_auto_allow(): + {==} + +law code_deny_never_calls_transport: + {transport(Denied{}) == Silent{} : Transport} + +def code_deny_never_calls_transport(): + {==} + +law empty_findings_are_not_approval: + {approval(Empty{}) == No{} : Approval} + +def empty_findings_are_not_approval(): + {==} + +law state_rejects_secret_key: + {state(Secret{}) == Rejected{} : State} + +def state_rejects_secret_key(): + {==} diff --git a/.claude/skills/laws/PROOF.bend b/.claude/skills/laws/PROOF.bend new file mode 100644 index 0000000..94e95aa --- /dev/null +++ b/.claude/skills/laws/PROOF.bend @@ -0,0 +1,13 @@ +import ./LAWS.bend as Laws + +def main() -> {Laws.verdict_auto(Laws.Shadow{}) == Laws.Hold{} : Laws.Auto} & {Laws.transport(Laws.Denied{}) == Laws.Silent{} : Laws.Transport} & {Laws.approval(Laws.Empty{}) == Laws.No{} : Laws.Approval} & {Laws.state(Laws.Secret{}) == Laws.Rejected{} : Laws.State}: + ( + Laws.shadow_cannot_set_auto_allow(), + ( + Laws.code_deny_never_calls_transport(), + ( + Laws.empty_findings_are_not_approval(), + Laws.state_rejects_secret_key() + ) + ) + ) diff --git a/.claude/skills/laws/SKILL.md b/.claude/skills/laws/SKILL.md new file mode 100644 index 0000000..e3d4bbf --- /dev/null +++ b/.claude/skills/laws/SKILL.md @@ -0,0 +1,31 @@ +--- +name: laws +description: Bend2 LAWS.bend for the Bezel bridle. The harness stays the harness. This skill carries the laws the bridle checks. +--- + +# laws + +Bezel is not a harness. It is the bridle on one: the piece that sits on Grok, omp, or Cursor and decides what that harness may do. This skill is how that bridle travels inside the Bezel skill pack. + +## What you are holding + +`LAWS.bend` states invariants. `PROOF.bend` checks them once the Rust modules exist. The JavaScript prototype at `v0.1.0` is the oracle, not the thing Bend proves. + +Draft these four laws. Do not invent a second runtime. + +- A shadow verdict cannot set `auto_allow`. +- A code deny never calls transport. +- Empty findings are not approval. +- A `state` constructor rejects a secret-shaped key. + +## Where it sits + +The harness loads this skill from the Bezel pack. Bezel does not replace the harness, and it does not exec the agent. `initiated` stays false. The publish name, if `bezel` is taken, is `bezel-bridle`. + +## Do not + +- Treat this skill as permission to delete the JavaScript before parity +- Link `@typesafe-ai/sdk` from Rust +- Publish the crate `bezel` +- Flip the live PreToolUse matcher +- Run `cargo` on castle diff --git a/.cursor/skills/bootstrap/SKILL.md b/.cursor/skills/bootstrap/SKILL.md new file mode 100644 index 0000000..359840e --- /dev/null +++ b/.cursor/skills/bootstrap/SKILL.md @@ -0,0 +1,13 @@ +--- +name: bootstrap +description: Placeholder skill shipped with the Bezel skills tree until a skills repository is published. Replace the flake skills input. Harness copies are generated from .agents/skills. +--- + +# bootstrap + +This skill exists so the skills flake input is a valid skills directory +(`*/SKILL.md`) until you point the flake skills input at a skills repository. + +Home Manager copies each skill directory as regular files into the user +directories the harnesses read: `~/.agents/skills`, `~/.claude/skills`, +`~/.grok/skills`, and `~/.cursor/skills`. diff --git a/.cursor/skills/check/SKILL.md b/.cursor/skills/check/SKILL.md new file mode 100644 index 0000000..2e6dd7a --- /dev/null +++ b/.cursor/skills/check/SKILL.md @@ -0,0 +1,50 @@ +--- +name: check +description: Bounded Jev-first check of a git diff. Code gathers evidence, Jev classifies, code applies thresholds. Empty findings are not approval. +--- + +# check + +Thin overlay skill for a bounded diff check. Prefer this +workflow when the user asks to check a diff against a task. + +## Run (shadow default) + +```sh +# Key from the environment only — never flags or files. +export TYPESAFE_API_KEY # host card store / your shell; omit to smoke without live Jev + +# Worktree + staged, or inject a unified diff: +jev-router --check --intent "" +jev-router --check --intent "" --base origin/main +jev-router --check --intent "" --diff-file path/to.diff +``` + +`JEV_MODE` defaults to `shadow`: Choice is logged; **shadow never blocks**. +Missing `TYPESAFE_API_KEY` in shadow continues — hunks land in `notChecked`. + +## Result contract + +Stdout is one JSON object: + +| Field | Meaning | +| --- | --- | +| `findings` | Deterministic or Jev-threshold hits | +| `parked` | Unclear; a human should look | +| `notChecked` | Skipped, unjudged, or out of scope | +| `approval` | Always `false` on this path | +| `emptyFindingsAreNotApproval` | Always `true` | + +**Empty `findings` is not approval.** Do not tell the user the change is +approved, LGTM, or safe to merge because the list is empty. + +## Available-gate + +`check` (and the `review` routing stub) require a git diff. No diff → +`status: "no_diff"` and `cannot_tell` — do not invent a pass. + +## Do not + +- Invoke a `stanley` binary, another agent binary, improve-worker, or promote loop +- Pass `TYPESAFE_API_KEY` as a flag or write it to a file +- Auto-activate agent-drafted skills diff --git a/.cursor/skills/facet/SKILL.md b/.cursor/skills/facet/SKILL.md new file mode 100644 index 0000000..6932a0b --- /dev/null +++ b/.cursor/skills/facet/SKILL.md @@ -0,0 +1,44 @@ +--- +name: facet +description: > + Inspect Facet HTTP request history, sessions, pins, and stored-value + metadata through the facet CLI. Use when a task needs to know what requests + ran, their status and timing, or to compare two runs. Prefer this skill over + the facet MCP server: it adds no tool schemas to context. The MCP server + remains available. +--- + +# facet — request history skill + +Read-only. The body is the fixed script `facet.nu` next to this file. Every +wrapped command appends `--json` (facet expects it after the subcommand). +Do not reimplement the calls. + +## Commands + +```bash +nu facet.nu history [path] [--limit 20] [--request sel] [--status 200] [--session id] +nu facet.nu last [path] [--request sel] +nu facet.nu sessions [--open] +nu facet.nu session +nu facet.nu pins [path] +nu facet.nu env [path] [--environment e] # names only, never values +nu facet.nu diff [path] # hashes only +nu facet.nu doctor +``` + +Each command prints one JSON envelope: `{ ok, command, exit, data, error }`. +`diff` uses `exit` 1 to mean the runs differ (`data.same` is false); that is +still `ok: true`. + +## Not wrapped, on purpose + +`facet.nu` refuses these and does not call facet: + +- `history --bodies`, `history --id`, `blob`, `diff --bodies`: these can print + recorded request or response bodies and headers, which may carry tokens. +- `request run`, including `request run --dry-run`: a preview resolves + variables, so it can show a hydrated secret. +- `replay`, `env set`, `env delete`, `pin`, `gc --yes`, + `session start/end`: these change state or send traffic. Run them only when + a human has explicitly asked, and never pass a secret value on the command line. diff --git a/.cursor/skills/facet/facet.nu b/.cursor/skills/facet/facet.nu new file mode 100755 index 0000000..9f48255 --- /dev/null +++ b/.cursor/skills/facet/facet.nu @@ -0,0 +1,246 @@ +#!/usr/bin/env nu +# Fixed read-only body for the facet skill. Wraps `facet` with `--json` +# after the subcommand. +# stdout is one JSON envelope: {ok, command, exit, data, error} +# Never calls history --bodies, history --id, blob, diff --bodies, or request run. + +const BLOCKED = ["--bodies" "--id" "blob" "--dry-run"] +const OWN_FLAGS = ["--limit" "--request" "--status" "--session" "--open" "--environment"] + +def clip-error [stderr: string, stdout: string] { + let joined = ([$stderr $stdout] | str join " " | str trim) + if ($joined | is-empty) { + "command failed" + } else { + ($joined | lines | first | str substring 0..399) + } +} + +def ok-row [command: string, exit: int, data: any] { + { ok: true, command: $command, exit: $exit, data: $data, error: null } +} + +def err-row [command: string, exit: int, error: string] { + { ok: false, command: $command, exit: $exit, data: null, error: ($error | str substring 0..399) } +} + +def as-text [raw: any] { + let d = ($raw | describe) + if $d == "string" { + $raw + } else { + try { $raw | decode utf-8 } catch { "" } + } +} + +def parse-json [text: string] { + let t = ($text | str trim) + if ($t | is-empty) { + error make { msg: "empty json" } + } + $t | from json --strict +} + +def opt [flag: string, v: string] { + if $v == "" { [] } else { [$flag $v] } +} + +def pos [v: string] { + if $v == "" { [] } else { [$v] } +} + +def blocked-argv [args: list] { + let joined = ($args | str join " ") + ($args | any {|a| $a in $BLOCKED }) or ($joined | str contains "request run") or ($joined | str contains "request --dry-run") +} + +def ascii-lower [text: string] { + let pairs = [ + [A a] [B b] [C c] [D d] [E e] [F f] [G g] [H h] [I i] [J j] + [K k] [L l] [M m] [N n] [O o] [P p] [Q q] [R r] [S s] [T t] + [U u] [V v] [W w] [X x] [Y y] [Z z] + ] + $pairs | reduce --fold $text {|p, acc| + $acc | str replace --all ($p | get 0) ($p | get 1) + } +} + +def secret-key [name: string] { + let lowered = (ascii-lower $name) + $lowered in [ + value values secret token password authorization + header headers body bodies raw content cookie cookies + request_body response_body + ] +} + +def env-name-key [name: string] { + let chars = ($name | split chars) + if ($chars | is-empty) { + false + } else { + $chars | all {|c| $c =~ "[A-Z0-9_]" } + } +} + +def redact [v: any] { + let d = ($v | describe) + if ($d | str starts-with "list") or ($d | str starts-with "table") { + $v | each {|item| redact $item } + } else if ($d | str starts-with "record") { + let cols = ($v | columns | where {|c| not (secret-key $c) }) + if ($cols | is-empty) { + {} + } else { + $cols | reduce --fold {} {|c, acc| + let val = ($v | get $c) + let vd = ($val | describe) + if (env-name-key $c) and $vd == "string" { + $acc | upsert $c null + } else { + $acc | upsert $c (redact $val) + } + } + } + } else { + $v + } +} + +def with-same [parsed: any, same: bool] { + let d = ($parsed | describe) + if ($d | str starts-with "record") { + $parsed | merge { same: $same } + } else { + { same: $same, report: $parsed } + } +} + +def run-facet [command: string, args: list, ok_codes: list = [0], redact_values: bool = false, embed_same: bool = false] { + let stray = ($args | where {|a| ($a | str starts-with "-") and (not ($a in $OWN_FLAGS)) }) + if (blocked-argv $args) or (not ($stray | is-empty)) { + err-row $command 2 "refused: history bodies, blob, diff --bodies, and request run are not available from this skill" + } else { + let r = (try { + ^facet ...$args --json | complete + } catch {|e| + { stdout: "", stderr: $"facet: ($e.msg)", exit_code: 127 } + }) + let stdout = (as-text $r.stdout) + let stderr = (as-text $r.stderr) + if not ($r.exit_code in $ok_codes) { + err-row $command $r.exit_code (clip-error $stderr $stdout) + } else { + let parsed = (try { { ok: true, value: (parse-json $stdout) } } catch {|e| { ok: false, value: $e.msg } }) + if not $parsed.ok { + err-row $command 1 $"invalid json: ($parsed.value)" + } else { + let data = if $redact_values { redact $parsed.value } else { $parsed.value } + let out = if $embed_same { with-same $data ($r.exit_code == 0) } else { $data } + ok-row $command $r.exit_code $out + } + } + } +} + +def "main history" [ + path: string = "", + --limit: int = 20, + --request: string = "", + --status: string = "", + --session: string = "", + --bodies, + --id: string = "", + ...rest: string, +] { + if $bodies or $id != "" or not ($rest | is-empty) or (blocked-argv (pos $path)) { + err-row "history" 2 "refused: history bodies are not available from this skill" | to json --raw + } else if $limit < 1 { + err-row "history" 2 "limit must be >= 1" | to json --raw + } else { + let args = ( + ["history"] + ++ (pos $path) + ++ ["--limit" ($limit | into string)] + ++ (opt "--request" $request) + ++ (opt "--status" $status) + ++ (opt "--session" $session) + ) + run-facet "history" $args | to json --raw + } +} + +def "main last" [path: string = "", --request: string = "", --bodies, ...rest: string] { + if $bodies or not ($rest | is-empty) or (blocked-argv (pos $path)) { + err-row "last" 2 "refused: history bodies are not available from this skill" | to json --raw + } else { + run-facet "last" (["last"] ++ (pos $path) ++ (opt "--request" $request)) | to json --raw + } +} + +def "main sessions" [--open, ...rest: string] { + if not ($rest | is-empty) { + err-row "sessions" 2 "refused: facet skill is read-only" | to json --raw + } else { + let args = (["session" "list"] ++ (if $open { ["--open"] } else { [] })) + run-facet "sessions" $args | to json --raw + } +} + +def "main session" [id: string, ...rest: string] { + if not ($rest | is-empty) or ($id in ["start" "end" "delete" "rm"]) { + err-row "session" 2 "refused: session start/end is not available from this skill" | to json --raw + } else { + run-facet "session" ["session" "show" $id] | to json --raw + } +} + +def "main pins" [path: string = "", ...rest: string] { + if not ($rest | is-empty) or (blocked-argv (pos $path)) { + err-row "pins" 2 "refused: facet skill is read-only" | to json --raw + } else { + run-facet "pins" (["pin" "list"] ++ (pos $path)) | to json --raw + } +} + +def "main env" [path: string = "", --environment: string = "", ...rest: string] { + if not ($rest | is-empty) or ($path in ["set" "delete" "unset" "get" "add" "rm"]) { + err-row "env" 2 "refused: env values and env writes are not available from this skill" | to json --raw + } else { + run-facet "env" (["env" "list"] ++ (pos $path) ++ (opt "--environment" $environment)) [0] true | to json --raw + } +} + +def "main diff" [a: string, b: string, path: string = "", --bodies, ...rest: string] { + if $bodies or not ($rest | is-empty) or (blocked-argv [$a $b $path]) { + err-row "diff" 2 "refused: diff --bodies is not available from this skill" | to json --raw + } else { + # exit 1 means the runs differ; that is a result, not a failure + run-facet "diff" (["diff" $a $b] ++ (pos $path)) [0 1] false true | to json --raw + } +} + +def "main doctor" [...rest: string] { + if not ($rest | is-empty) { + err-row "doctor" 2 "refused: facet skill is read-only" | to json --raw + } else { + run-facet "doctor" ["doctor"] | to json --raw + } +} + +def "main blob" [...args: string] { + err-row "blob" 2 "refused: blob is not available from this skill" | to json --raw +} + +def "main request" [--dry-run, ...args: string] { + err-row "request" 2 "refused: request run is not available from this skill" | to json --raw +} + +def "main replay" [...args: string] { + err-row "replay" 2 "refused: replay is not available from this skill" | to json --raw +} + +def main [...args: string] { + let command = ($args | first | default "") + err-row $command 2 "refused: facet skill is read-only" | to json --raw +} diff --git a/.cursor/skills/geode/SKILL.md b/.cursor/skills/geode/SKILL.md new file mode 100644 index 0000000..7046b48 --- /dev/null +++ b/.cursor/skills/geode/SKILL.md @@ -0,0 +1,46 @@ +--- +name: geode +description: > + Check Geode vault health and metadata through the geode CLI: entry names, + integrity, recipients, snapshots, policy, audit chain, custody status. Use + when a task asks whether a vault is intact, who can open it, or what it + holds by name. This skill never reads or prints secret values. Prefer it + over the geode MCP server. The MCP server remains available. +--- + +# geode — custody status skill (metadata only) + +The body is the fixed script `geode.nu` next to this file. Every wrapped +command uses `geode --output json`. The vault path comes from the argument or +`$GEODE_VAULT`; the identity key from `$GEODE_KEY_FILE` as usual. The script +never puts the key on the command line. Do not reimplement the calls. + +## Commands + +```bash +nu geode.nu list [vault] [prefix] # entry names and sizes, no contents +nu geode.nu verify [vault] [--sample 0.05] # default --cheap +nu geode.nu recipients [vault] # recipient types and key ids (public) +nu geode.nu snapshots [vault] +nu geode.nu policy [vault] +nu geode.nu can [vault] # dry run; deny is exit 3 +nu geode.nu audit +nu geode.nu custody +nu geode.nu keyring +``` + +Each command prints one JSON envelope: `{ ok, command, exit, data, error }`. +`can` keeps `ok: true` when geode exits 3 (deny). `audit` keeps `ok: true` +when geode exits 2 (chain failed). + +## Never run from this skill + +`geode.nu` refuses anything that is not in the list above, including `cat`, +`open`, `mount`, `run`, `agent`, `keygen`, `seal`, `sign`, `vault init`, +`vault add-recipient`, `vault rotate`, `policy set`, `keyring add`, +`custody unlock/lock`, `gc`, and `git unlock`. Those read secret bytes, put +them in an environment or on disk, or change custody. They need a human, and +their output must never be pasted into notes, logs, or chat. + +Entry names can themselves be sensitive. Quote them only where the reader is +allowed to know the vault holds them. diff --git a/.cursor/skills/geode/geode.nu b/.cursor/skills/geode/geode.nu new file mode 100755 index 0000000..5f722d5 --- /dev/null +++ b/.cursor/skills/geode/geode.nu @@ -0,0 +1,224 @@ +#!/usr/bin/env nu +# Fixed metadata-only body for the geode skill. Wraps `geode --output json`. +# stdout is one JSON envelope: {ok, command, exit, data, error} +# Only the allowlist is passed to geode. Anything else is refused. + +const ALLOWED = [ + "list" + "verify" + "vault recipients" + "snapshot ls" + "policy show" + "policy check" + "audit verify" + "custody status" + "keyring list" +] + +def clip-error [stderr: string, stdout: string] { + let joined = ([$stderr $stdout] | str join " " | str trim) + if ($joined | is-empty) { + "command failed" + } else { + ($joined | lines | first | str substring 0..399) + } +} + +def ok-row [command: string, exit: int, data: any] { + { ok: true, command: $command, exit: $exit, data: $data, error: null } +} + +def err-row [command: string, exit: int, error: string] { + { ok: false, command: $command, exit: $exit, data: null, error: ($error | str substring 0..399) } +} + +def refused [command: string, detail: string] { + err-row $command 2 $"refused: geode skill is metadata-only ($detail)" +} + +def as-text [raw: any] { + let d = ($raw | describe) + if $d == "string" { + $raw + } else { + try { $raw | decode utf-8 } catch { "" } + } +} + +def parse-json [text: string] { + let t = ($text | str trim) + if ($t | is-empty) { + error make { msg: "empty json" } + } + $t | from json --strict +} + +def vault-path [v: string] { + if $v != "" { $v } else { $env.GEODE_VAULT? | default "" } +} + +def run-geode [ + command: string, + sub: list, + rest: list, + ok_codes: list = [0], + permit_flags: list = [], +] { + let key = ($sub | str join " ") + let flagged = ($rest | where {|a| ($a | str starts-with "-") and (not ($a in $permit_flags)) }) + if not ($key in $ALLOWED) { + refused $command $"not on the allowlist: ($key)" + } else if not ($flagged | is-empty) { + refused $command "flags are not accepted" + } else { + let argv = (["--output" "json"] ++ $sub ++ $rest) + let r = (try { + ^geode ...$argv | complete + } catch {|e| + { stdout: "", stderr: $"geode: ($e.msg)", exit_code: 127 } + }) + let stdout = (as-text $r.stdout) + let stderr = (as-text $r.stderr) + if not ($r.exit_code in $ok_codes) { + err-row $command $r.exit_code (clip-error $stderr $stdout) + } else { + let parsed = (try { { ok: true, value: (parse-json $stdout) } } catch {|e| { ok: false, value: $e.msg } }) + if not $parsed.ok { + err-row $command 1 $"invalid json: ($parsed.value)" + } else { + ok-row $command $r.exit_code $parsed.value + } + } + } +} + +def path-verb [p: string] { + $p in [ + set init add-recipient rotate add unlock lock delete rm + start end get unset cat open mount run agent keygen seal sign gc + ] +} + +def need-vault [command: string, vault: string] { + let p = (vault-path $vault) + if (path-verb $vault) { + refused $command $"($vault) is not available from this skill" + } else if $p == "" { + err-row $command 2 "no vault: pass one or set GEODE_VAULT" + } else if ($p | str starts-with "-") { + refused $command "vault path must not be a flag" + } else { + { ok: true, path: $p } + } +} + +def "main list" [vault: string = "", prefix: string = "", ...rest: string] { + if not ($rest | is-empty) { + refused "list" "extra arguments" | to json --raw + } else { + let got = (need-vault "list" $vault) + if not $got.ok { + $got | to json --raw + } else { + let rest_args = ([$got.path] ++ (if $prefix == "" { [] } else { [$prefix] })) + run-geode "list" [list] $rest_args | to json --raw + } + } +} + +def "main verify" [vault: string = "", --sample: string = "", ...rest: string] { + if not ($rest | is-empty) { + refused "verify" "extra arguments" | to json --raw + } else { + let got = (need-vault "verify" $vault) + if not $got.ok { + $got | to json --raw + } else if $sample == "" { + run-geode "verify" [verify] [$got.path "--cheap"] [0] ["--cheap"] | to json --raw + } else { + let numeric = (try { $sample | into float; true } catch {|_| false }) + if not $numeric or ($sample | str starts-with "-") { + refused "verify" "sample must be a non-negative number" | to json --raw + } else { + run-geode "verify" [verify] [$got.path "--sample" $sample] [0] ["--sample"] | to json --raw + } + } + } +} + +def "main recipients" [vault: string = "", ...rest: string] { + if not ($rest | is-empty) { + refused "recipients" "extra arguments" | to json --raw + } else { + let got = (need-vault "recipients" $vault) + if not $got.ok { $got | to json --raw } else { + run-geode "recipients" [vault recipients] [$got.path] | to json --raw + } + } +} + +def "main snapshots" [vault: string = "", ...rest: string] { + if not ($rest | is-empty) { + refused "snapshots" "extra arguments" | to json --raw + } else { + let got = (need-vault "snapshots" $vault) + if not $got.ok { $got | to json --raw } else { + run-geode "snapshots" [snapshot ls] [$got.path] | to json --raw + } + } +} + +def "main policy" [vault: string = "", ...rest: string] { + if not ($rest | is-empty) { + refused "policy" "policy set is not available from this skill" | to json --raw + } else { + let got = (need-vault "policy" $vault) + if not $got.ok { $got | to json --raw } else { + run-geode "policy" [policy show] [$got.path] | to json --raw + } + } +} + +def "main can" [principal: string, op: string, path: string, vault: string = "", ...rest: string] { + if not ($rest | is-empty) { + refused "can" "extra arguments" | to json --raw + } else if ([$principal $op $path] | any {|a| $a | str starts-with "-" }) { + refused "can" "flags are not accepted" | to json --raw + } else { + let got = (need-vault "can" $vault) + if not $got.ok { $got | to json --raw } else { + # deny exits 3; that is a result, not a failure + run-geode "can" [policy check] [$got.path $principal $op $path] [0 3] | to json --raw + } + } +} + +def "main audit" [...rest: string] { + if not ($rest | is-empty) { + refused "audit" "extra arguments" | to json --raw + } else { + # a broken chain exits 2; that is a result, not a failure + run-geode "audit" [audit verify] [] [0 2] | to json --raw + } +} + +def "main custody" [...rest: string] { + if not ($rest | is-empty) { + refused "custody" "unlock/lock is not available from this skill" | to json --raw + } else { + run-geode "custody" [custody status] [] | to json --raw + } +} + +def "main keyring" [...rest: string] { + if not ($rest | is-empty) { + refused "keyring" "keyring add is not available from this skill" | to json --raw + } else { + run-geode "keyring" [keyring list] [] | to json --raw + } +} + +def main [...args: string] { + let command = ($args | first | default "") + refused $command ($args | str join " ") | to json --raw +} diff --git a/.cursor/skills/lapis/SKILL.md b/.cursor/skills/lapis/SKILL.md new file mode 100644 index 0000000..9e8b3b2 --- /dev/null +++ b/.cursor/skills/lapis/SKILL.md @@ -0,0 +1,52 @@ +--- +name: lapis +description: > + Search and read a Lapis notes vault through the lapis CLI. Use when a task + needs notes, doctrine, project context, wikilink neighbors, or recent notes + from the vault. Prefer this skill over the lapis MCP server: it adds no tool + schemas to context and its body is deterministic. The MCP server remains + available. +--- + +# lapis — vault read skill + +`lapis` owns the vault and its index. This skill only reads, through the +fixed script `lapis.nu` next to this file. Never open `.lapis/` index files +directly, and do not reimplement the calls. + +## Configuration + +The vault path is resolved in this order: + +1. `--vault ` passed to any command +2. `$LAPIS_VAULT` +3. the path recorded by `lapis init` in the lapis config + +## Commands + +```bash +nu lapis.nu search "phrase" --limit 5 [--domain d] +nu lapis.nu read path/to/note.md +nu lapis.nu list [--prefix projects/] +nu lapis.nu neighbors path/to/note.md +nu lapis.nu resolve "[[Note Name]]" +nu lapis.nu recent [--limit 10] +nu lapis.nu status +nu lapis.nu doctor +``` + +Each command prints one JSON envelope: `{ ok, command, exit, data, error }`. + +- `search`: BM25 over chunks (vectors only if an embedder is configured); one hit per note. `data` is `path` and `title` only. +- `read`: frontmatter (`hal`) plus body. +- `list`: index metadata only; never walks the vault. +- `neighbors`: hop-1 wikilink edges. +- `recent`: newest first. Each row is read by name: `path`, `title`, and `mtime_iso` (Lapis 0.4.2) or `mtime` (older builds). `mtime_iso` wins when both are present. +- `status` / `doctor`: vault root and index health (`exit` 2 when the index is down). + +## Rules + +- Read before you cite: give the note path and quote the passage. +- Writes (`create`, `append`, `task`, `trash`) are refused by `lapis.nu`. + Run them only when a human has explicitly asked, and not through this skill. +- If a path is missing, start `neighbors` from a hub note rather than guessing. diff --git a/.cursor/skills/lapis/lapis.nu b/.cursor/skills/lapis/lapis.nu new file mode 100755 index 0000000..a54633c --- /dev/null +++ b/.cursor/skills/lapis/lapis.nu @@ -0,0 +1,203 @@ +#!/usr/bin/env nu +# Fixed read-only body for the lapis skill. Wraps `lapis --json`. +# stdout is one JSON envelope: {ok, command, exit, data, error} +# Vault: --vault, else $LAPIS_VAULT, else the lapis config default. + +def clip-error [stderr: string, stdout: string] { + let joined = ([$stderr $stdout] | str join " " | str trim) + if ($joined | is-empty) { + "command failed" + } else { + ($joined | lines | first | str substring 0..399) + } +} + +def ok-row [command: string, exit: int, data: any] { + { ok: true, command: $command, exit: $exit, data: $data, error: null } +} + +def err-row [command: string, exit: int, error: string] { + { ok: false, command: $command, exit: $exit, data: null, error: ($error | str substring 0..399) } +} + +def as-text [raw: any] { + let d = ($raw | describe) + if $d == "string" { + $raw + } else { + try { $raw | decode utf-8 } catch { "" } + } +} + +def parse-json [text: string] { + let t = ($text | str trim) + if ($t | is-empty) { + error make { msg: "empty json" } + } + $t | from json --strict +} + +def vault-args [vault: string] { + let v = if $vault != "" { $vault } else { $env.LAPIS_VAULT? | default "" } + if ($v | str starts-with "-") { + error make { msg: "vault path must not be a flag" } + } + if $v == "" { [] } else { ["--vault" $v] } +} + +def lapis-data [value: any] { + let d = ($value | describe) + if ($d | str starts-with "record") and ("data" in ($value | columns)) { + $value | get data + } else { + $value + } +} + +def run-lapis [command: string, args: list, vault: string] { + let vault_part = (try { vault-args $vault } catch {|e| $e.msg }) + if ($vault_part | describe) == "string" { + err-row $command 2 $vault_part + } else { + let argv = (["--json"] ++ $vault_part ++ $args) + let r = (try { + ^lapis ...$argv | complete + } catch {|e| + { stdout: "", stderr: $"lapis: ($e.msg)", exit_code: 127 } + }) + let stdout = (as-text $r.stdout) + let stderr = (as-text $r.stderr) + if $r.exit_code != 0 { + err-row $command $r.exit_code (clip-error $stderr $stdout) + } else { + let parsed = (try { { ok: true, value: (parse-json $stdout) } } catch {|e| { ok: false, value: $e.msg } }) + if not $parsed.ok { + err-row $command 1 $"invalid json: ($parsed.value)" + } else { + ok-row $command 0 (lapis-data $parsed.value) + } + } + } +} + +def flagish [s: string] { $s | str starts-with "-" } + +def "main search" [query: string, --limit (-n): int = 5, --domain: string = "", --vault: string = ""] { + if $limit < 1 { + err-row "search" 2 "limit must be >= 1" | to json --raw + } else if (flagish $query) or (flagish $domain) { + err-row "search" 2 "refused: lapis skill is read-only" | to json --raw + } else { + mut args = ["search" $query "-n" ($limit | into string)] + if $domain != "" { $args = ($args ++ ["--domain" $domain]) } + let row = (run-lapis "search" $args $vault) + if not $row.ok { + $row | to json --raw + } else { + let hits = (try { $row.data | get hits } catch {|err| null }) + let kind = ($hits | describe) + if not (($kind | str starts-with "list") or ($kind | str starts-with "table")) { + err-row "search" 1 "search data has no hits" | to json --raw + } else { + let slim = (try { $hits | select path title } catch {|err| null }) + if ($slim | describe) == "nothing" { + err-row "search" 1 "search hits missing path or title" | to json --raw + } else { + ok-row "search" $row.exit $slim | to json --raw + } + } + } + } +} + +def "main read" [path: string, --vault: string = ""] { + if (flagish $path) { + err-row "read" 2 "refused: lapis skill is read-only" | to json --raw + } else { + run-lapis "read" ["read" $path] $vault | to json --raw + } +} + +def "main list" [--prefix: string = "", --vault: string = ""] { + let row = (run-lapis "list" ["list"] $vault) + if not $row.ok or $prefix == "" { + $row | to json --raw + } else { + let kind = ($row.data | describe) + if not (($kind | str starts-with "list") or ($kind | str starts-with "table")) { + err-row "list" 1 "list data is not a list" | to json --raw + } else { + let filtered = ($row.data | where path starts-with $prefix) + ok-row "list" $row.exit $filtered | to json --raw + } + } +} + +def "main neighbors" [path: string, --vault: string = ""] { + if (flagish $path) { + err-row "neighbors" 2 "refused: lapis skill is read-only" | to json --raw + } else { + run-lapis "neighbors" ["neighbors" $path] $vault | to json --raw + } +} + +def "main resolve" [link: string, --vault: string = ""] { + if (flagish $link) { + err-row "resolve" 2 "refused: lapis skill is read-only" | to json --raw + } else { + run-lapis "resolve" ["resolve" $link] $vault | to json --raw + } +} + +# Lapis 0.4.2 rows are path, title, domain, priority, mtime_iso. +# Older builds are path, title, mtime. Read those fields by name. +def recent-mtime [row: record] { + let cols = ($row | columns) + if "mtime_iso" in $cols { + $row | get mtime_iso + } else if "mtime" in $cols { + $row | get mtime + } else { + error make { msg: "recent row missing mtime" } + } +} + +def "main recent" [--limit (-n): int = 10, --vault: string = ""] { + if $limit < 1 { + err-row "recent" 2 "limit must be >= 1" | to json --raw + } else { + let row = (run-lapis "recent" ["analytics" "recent"] $vault) + if not $row.ok { + $row | to json --raw + } else { + let rows = (try { $row.data | get rows } catch {|err| null }) + let shaped = (try { + $rows | first $limit | each {|r| + { + path: ($r | get path) + title: ($r | get title) + mtime: (recent-mtime $r) + } + } + } catch {|err| null }) + if ($shaped | describe) == "nothing" { + err-row "recent" 1 "recent data has no rows" | to json --raw + } else { + ok-row "recent" $row.exit $shaped | to json --raw + } + } + } +} + +def "main status" [--vault: string = ""] { + run-lapis "status" ["vault" "info"] $vault | to json --raw +} + +def "main doctor" [--vault: string = ""] { + run-lapis "doctor" ["doctor"] $vault | to json --raw +} + +def main [...args: string] { + let command = ($args | first | default "") + err-row $command 2 "refused: lapis skill is read-only" | to json --raw +} diff --git a/.cursor/skills/laws/LAWS.bend b/.cursor/skills/laws/LAWS.bend new file mode 100644 index 0000000..17ef699 --- /dev/null +++ b/.cursor/skills/laws/LAWS.bend @@ -0,0 +1,85 @@ +import Base + +type Mode is Data: + Shadow{} + Active{} + +type Auto is Data: + Hold{} + Allow{} + +type Call is Data: + Denied{} + Open{} + +type Transport is Data: + Silent{} + Called{} + +type Findings is Data: + Empty{} + Present{} + +type Approval is Data: + No{} + Yes{} + +type Key is Data: + Public{} + Secret{} + +type State is Data: + Rejected{} + Seated{} + +def verdict_auto(mode: Mode) -> Auto: + match mode: + case Shadow{}: + Hold{} + case Active{}: + Hold{} + +def transport(call: Call) -> Transport: + match call: + case Denied{}: + Silent{} + case Open{}: + Called{} + +def approval(findings: Findings) -> Approval: + match findings: + case Empty{}: + No{} + case Present{}: + Yes{} + +def state(key: Key) -> State: + match key: + case Secret{}: + Rejected{} + case Public{}: + Seated{} + +law shadow_cannot_set_auto_allow: + {verdict_auto(Shadow{}) == Hold{} : Auto} + +def shadow_cannot_set_auto_allow(): + {==} + +law code_deny_never_calls_transport: + {transport(Denied{}) == Silent{} : Transport} + +def code_deny_never_calls_transport(): + {==} + +law empty_findings_are_not_approval: + {approval(Empty{}) == No{} : Approval} + +def empty_findings_are_not_approval(): + {==} + +law state_rejects_secret_key: + {state(Secret{}) == Rejected{} : State} + +def state_rejects_secret_key(): + {==} diff --git a/.cursor/skills/laws/PROOF.bend b/.cursor/skills/laws/PROOF.bend new file mode 100644 index 0000000..94e95aa --- /dev/null +++ b/.cursor/skills/laws/PROOF.bend @@ -0,0 +1,13 @@ +import ./LAWS.bend as Laws + +def main() -> {Laws.verdict_auto(Laws.Shadow{}) == Laws.Hold{} : Laws.Auto} & {Laws.transport(Laws.Denied{}) == Laws.Silent{} : Laws.Transport} & {Laws.approval(Laws.Empty{}) == Laws.No{} : Laws.Approval} & {Laws.state(Laws.Secret{}) == Laws.Rejected{} : Laws.State}: + ( + Laws.shadow_cannot_set_auto_allow(), + ( + Laws.code_deny_never_calls_transport(), + ( + Laws.empty_findings_are_not_approval(), + Laws.state_rejects_secret_key() + ) + ) + ) diff --git a/.cursor/skills/laws/SKILL.md b/.cursor/skills/laws/SKILL.md new file mode 100644 index 0000000..e3d4bbf --- /dev/null +++ b/.cursor/skills/laws/SKILL.md @@ -0,0 +1,31 @@ +--- +name: laws +description: Bend2 LAWS.bend for the Bezel bridle. The harness stays the harness. This skill carries the laws the bridle checks. +--- + +# laws + +Bezel is not a harness. It is the bridle on one: the piece that sits on Grok, omp, or Cursor and decides what that harness may do. This skill is how that bridle travels inside the Bezel skill pack. + +## What you are holding + +`LAWS.bend` states invariants. `PROOF.bend` checks them once the Rust modules exist. The JavaScript prototype at `v0.1.0` is the oracle, not the thing Bend proves. + +Draft these four laws. Do not invent a second runtime. + +- A shadow verdict cannot set `auto_allow`. +- A code deny never calls transport. +- Empty findings are not approval. +- A `state` constructor rejects a secret-shaped key. + +## Where it sits + +The harness loads this skill from the Bezel pack. Bezel does not replace the harness, and it does not exec the agent. `initiated` stays false. The publish name, if `bezel` is taken, is `bezel-bridle`. + +## Do not + +- Treat this skill as permission to delete the JavaScript before parity +- Link `@typesafe-ai/sdk` from Rust +- Publish the crate `bezel` +- Flip the live PreToolUse matcher +- Run `cargo` on castle diff --git a/.grok/skills/bootstrap/SKILL.md b/.grok/skills/bootstrap/SKILL.md new file mode 100644 index 0000000..359840e --- /dev/null +++ b/.grok/skills/bootstrap/SKILL.md @@ -0,0 +1,13 @@ +--- +name: bootstrap +description: Placeholder skill shipped with the Bezel skills tree until a skills repository is published. Replace the flake skills input. Harness copies are generated from .agents/skills. +--- + +# bootstrap + +This skill exists so the skills flake input is a valid skills directory +(`*/SKILL.md`) until you point the flake skills input at a skills repository. + +Home Manager copies each skill directory as regular files into the user +directories the harnesses read: `~/.agents/skills`, `~/.claude/skills`, +`~/.grok/skills`, and `~/.cursor/skills`. diff --git a/.grok/skills/check/SKILL.md b/.grok/skills/check/SKILL.md new file mode 100644 index 0000000..2e6dd7a --- /dev/null +++ b/.grok/skills/check/SKILL.md @@ -0,0 +1,50 @@ +--- +name: check +description: Bounded Jev-first check of a git diff. Code gathers evidence, Jev classifies, code applies thresholds. Empty findings are not approval. +--- + +# check + +Thin overlay skill for a bounded diff check. Prefer this +workflow when the user asks to check a diff against a task. + +## Run (shadow default) + +```sh +# Key from the environment only — never flags or files. +export TYPESAFE_API_KEY # host card store / your shell; omit to smoke without live Jev + +# Worktree + staged, or inject a unified diff: +jev-router --check --intent "" +jev-router --check --intent "" --base origin/main +jev-router --check --intent "" --diff-file path/to.diff +``` + +`JEV_MODE` defaults to `shadow`: Choice is logged; **shadow never blocks**. +Missing `TYPESAFE_API_KEY` in shadow continues — hunks land in `notChecked`. + +## Result contract + +Stdout is one JSON object: + +| Field | Meaning | +| --- | --- | +| `findings` | Deterministic or Jev-threshold hits | +| `parked` | Unclear; a human should look | +| `notChecked` | Skipped, unjudged, or out of scope | +| `approval` | Always `false` on this path | +| `emptyFindingsAreNotApproval` | Always `true` | + +**Empty `findings` is not approval.** Do not tell the user the change is +approved, LGTM, or safe to merge because the list is empty. + +## Available-gate + +`check` (and the `review` routing stub) require a git diff. No diff → +`status: "no_diff"` and `cannot_tell` — do not invent a pass. + +## Do not + +- Invoke a `stanley` binary, another agent binary, improve-worker, or promote loop +- Pass `TYPESAFE_API_KEY` as a flag or write it to a file +- Auto-activate agent-drafted skills diff --git a/.grok/skills/facet/SKILL.md b/.grok/skills/facet/SKILL.md new file mode 100644 index 0000000..6932a0b --- /dev/null +++ b/.grok/skills/facet/SKILL.md @@ -0,0 +1,44 @@ +--- +name: facet +description: > + Inspect Facet HTTP request history, sessions, pins, and stored-value + metadata through the facet CLI. Use when a task needs to know what requests + ran, their status and timing, or to compare two runs. Prefer this skill over + the facet MCP server: it adds no tool schemas to context. The MCP server + remains available. +--- + +# facet — request history skill + +Read-only. The body is the fixed script `facet.nu` next to this file. Every +wrapped command appends `--json` (facet expects it after the subcommand). +Do not reimplement the calls. + +## Commands + +```bash +nu facet.nu history [path] [--limit 20] [--request sel] [--status 200] [--session id] +nu facet.nu last [path] [--request sel] +nu facet.nu sessions [--open] +nu facet.nu session +nu facet.nu pins [path] +nu facet.nu env [path] [--environment e] # names only, never values +nu facet.nu diff [path] # hashes only +nu facet.nu doctor +``` + +Each command prints one JSON envelope: `{ ok, command, exit, data, error }`. +`diff` uses `exit` 1 to mean the runs differ (`data.same` is false); that is +still `ok: true`. + +## Not wrapped, on purpose + +`facet.nu` refuses these and does not call facet: + +- `history --bodies`, `history --id`, `blob`, `diff --bodies`: these can print + recorded request or response bodies and headers, which may carry tokens. +- `request run`, including `request run --dry-run`: a preview resolves + variables, so it can show a hydrated secret. +- `replay`, `env set`, `env delete`, `pin`, `gc --yes`, + `session start/end`: these change state or send traffic. Run them only when + a human has explicitly asked, and never pass a secret value on the command line. diff --git a/.grok/skills/facet/facet.nu b/.grok/skills/facet/facet.nu new file mode 100755 index 0000000..9f48255 --- /dev/null +++ b/.grok/skills/facet/facet.nu @@ -0,0 +1,246 @@ +#!/usr/bin/env nu +# Fixed read-only body for the facet skill. Wraps `facet` with `--json` +# after the subcommand. +# stdout is one JSON envelope: {ok, command, exit, data, error} +# Never calls history --bodies, history --id, blob, diff --bodies, or request run. + +const BLOCKED = ["--bodies" "--id" "blob" "--dry-run"] +const OWN_FLAGS = ["--limit" "--request" "--status" "--session" "--open" "--environment"] + +def clip-error [stderr: string, stdout: string] { + let joined = ([$stderr $stdout] | str join " " | str trim) + if ($joined | is-empty) { + "command failed" + } else { + ($joined | lines | first | str substring 0..399) + } +} + +def ok-row [command: string, exit: int, data: any] { + { ok: true, command: $command, exit: $exit, data: $data, error: null } +} + +def err-row [command: string, exit: int, error: string] { + { ok: false, command: $command, exit: $exit, data: null, error: ($error | str substring 0..399) } +} + +def as-text [raw: any] { + let d = ($raw | describe) + if $d == "string" { + $raw + } else { + try { $raw | decode utf-8 } catch { "" } + } +} + +def parse-json [text: string] { + let t = ($text | str trim) + if ($t | is-empty) { + error make { msg: "empty json" } + } + $t | from json --strict +} + +def opt [flag: string, v: string] { + if $v == "" { [] } else { [$flag $v] } +} + +def pos [v: string] { + if $v == "" { [] } else { [$v] } +} + +def blocked-argv [args: list] { + let joined = ($args | str join " ") + ($args | any {|a| $a in $BLOCKED }) or ($joined | str contains "request run") or ($joined | str contains "request --dry-run") +} + +def ascii-lower [text: string] { + let pairs = [ + [A a] [B b] [C c] [D d] [E e] [F f] [G g] [H h] [I i] [J j] + [K k] [L l] [M m] [N n] [O o] [P p] [Q q] [R r] [S s] [T t] + [U u] [V v] [W w] [X x] [Y y] [Z z] + ] + $pairs | reduce --fold $text {|p, acc| + $acc | str replace --all ($p | get 0) ($p | get 1) + } +} + +def secret-key [name: string] { + let lowered = (ascii-lower $name) + $lowered in [ + value values secret token password authorization + header headers body bodies raw content cookie cookies + request_body response_body + ] +} + +def env-name-key [name: string] { + let chars = ($name | split chars) + if ($chars | is-empty) { + false + } else { + $chars | all {|c| $c =~ "[A-Z0-9_]" } + } +} + +def redact [v: any] { + let d = ($v | describe) + if ($d | str starts-with "list") or ($d | str starts-with "table") { + $v | each {|item| redact $item } + } else if ($d | str starts-with "record") { + let cols = ($v | columns | where {|c| not (secret-key $c) }) + if ($cols | is-empty) { + {} + } else { + $cols | reduce --fold {} {|c, acc| + let val = ($v | get $c) + let vd = ($val | describe) + if (env-name-key $c) and $vd == "string" { + $acc | upsert $c null + } else { + $acc | upsert $c (redact $val) + } + } + } + } else { + $v + } +} + +def with-same [parsed: any, same: bool] { + let d = ($parsed | describe) + if ($d | str starts-with "record") { + $parsed | merge { same: $same } + } else { + { same: $same, report: $parsed } + } +} + +def run-facet [command: string, args: list, ok_codes: list = [0], redact_values: bool = false, embed_same: bool = false] { + let stray = ($args | where {|a| ($a | str starts-with "-") and (not ($a in $OWN_FLAGS)) }) + if (blocked-argv $args) or (not ($stray | is-empty)) { + err-row $command 2 "refused: history bodies, blob, diff --bodies, and request run are not available from this skill" + } else { + let r = (try { + ^facet ...$args --json | complete + } catch {|e| + { stdout: "", stderr: $"facet: ($e.msg)", exit_code: 127 } + }) + let stdout = (as-text $r.stdout) + let stderr = (as-text $r.stderr) + if not ($r.exit_code in $ok_codes) { + err-row $command $r.exit_code (clip-error $stderr $stdout) + } else { + let parsed = (try { { ok: true, value: (parse-json $stdout) } } catch {|e| { ok: false, value: $e.msg } }) + if not $parsed.ok { + err-row $command 1 $"invalid json: ($parsed.value)" + } else { + let data = if $redact_values { redact $parsed.value } else { $parsed.value } + let out = if $embed_same { with-same $data ($r.exit_code == 0) } else { $data } + ok-row $command $r.exit_code $out + } + } + } +} + +def "main history" [ + path: string = "", + --limit: int = 20, + --request: string = "", + --status: string = "", + --session: string = "", + --bodies, + --id: string = "", + ...rest: string, +] { + if $bodies or $id != "" or not ($rest | is-empty) or (blocked-argv (pos $path)) { + err-row "history" 2 "refused: history bodies are not available from this skill" | to json --raw + } else if $limit < 1 { + err-row "history" 2 "limit must be >= 1" | to json --raw + } else { + let args = ( + ["history"] + ++ (pos $path) + ++ ["--limit" ($limit | into string)] + ++ (opt "--request" $request) + ++ (opt "--status" $status) + ++ (opt "--session" $session) + ) + run-facet "history" $args | to json --raw + } +} + +def "main last" [path: string = "", --request: string = "", --bodies, ...rest: string] { + if $bodies or not ($rest | is-empty) or (blocked-argv (pos $path)) { + err-row "last" 2 "refused: history bodies are not available from this skill" | to json --raw + } else { + run-facet "last" (["last"] ++ (pos $path) ++ (opt "--request" $request)) | to json --raw + } +} + +def "main sessions" [--open, ...rest: string] { + if not ($rest | is-empty) { + err-row "sessions" 2 "refused: facet skill is read-only" | to json --raw + } else { + let args = (["session" "list"] ++ (if $open { ["--open"] } else { [] })) + run-facet "sessions" $args | to json --raw + } +} + +def "main session" [id: string, ...rest: string] { + if not ($rest | is-empty) or ($id in ["start" "end" "delete" "rm"]) { + err-row "session" 2 "refused: session start/end is not available from this skill" | to json --raw + } else { + run-facet "session" ["session" "show" $id] | to json --raw + } +} + +def "main pins" [path: string = "", ...rest: string] { + if not ($rest | is-empty) or (blocked-argv (pos $path)) { + err-row "pins" 2 "refused: facet skill is read-only" | to json --raw + } else { + run-facet "pins" (["pin" "list"] ++ (pos $path)) | to json --raw + } +} + +def "main env" [path: string = "", --environment: string = "", ...rest: string] { + if not ($rest | is-empty) or ($path in ["set" "delete" "unset" "get" "add" "rm"]) { + err-row "env" 2 "refused: env values and env writes are not available from this skill" | to json --raw + } else { + run-facet "env" (["env" "list"] ++ (pos $path) ++ (opt "--environment" $environment)) [0] true | to json --raw + } +} + +def "main diff" [a: string, b: string, path: string = "", --bodies, ...rest: string] { + if $bodies or not ($rest | is-empty) or (blocked-argv [$a $b $path]) { + err-row "diff" 2 "refused: diff --bodies is not available from this skill" | to json --raw + } else { + # exit 1 means the runs differ; that is a result, not a failure + run-facet "diff" (["diff" $a $b] ++ (pos $path)) [0 1] false true | to json --raw + } +} + +def "main doctor" [...rest: string] { + if not ($rest | is-empty) { + err-row "doctor" 2 "refused: facet skill is read-only" | to json --raw + } else { + run-facet "doctor" ["doctor"] | to json --raw + } +} + +def "main blob" [...args: string] { + err-row "blob" 2 "refused: blob is not available from this skill" | to json --raw +} + +def "main request" [--dry-run, ...args: string] { + err-row "request" 2 "refused: request run is not available from this skill" | to json --raw +} + +def "main replay" [...args: string] { + err-row "replay" 2 "refused: replay is not available from this skill" | to json --raw +} + +def main [...args: string] { + let command = ($args | first | default "") + err-row $command 2 "refused: facet skill is read-only" | to json --raw +} diff --git a/.grok/skills/geode/SKILL.md b/.grok/skills/geode/SKILL.md new file mode 100644 index 0000000..7046b48 --- /dev/null +++ b/.grok/skills/geode/SKILL.md @@ -0,0 +1,46 @@ +--- +name: geode +description: > + Check Geode vault health and metadata through the geode CLI: entry names, + integrity, recipients, snapshots, policy, audit chain, custody status. Use + when a task asks whether a vault is intact, who can open it, or what it + holds by name. This skill never reads or prints secret values. Prefer it + over the geode MCP server. The MCP server remains available. +--- + +# geode — custody status skill (metadata only) + +The body is the fixed script `geode.nu` next to this file. Every wrapped +command uses `geode --output json`. The vault path comes from the argument or +`$GEODE_VAULT`; the identity key from `$GEODE_KEY_FILE` as usual. The script +never puts the key on the command line. Do not reimplement the calls. + +## Commands + +```bash +nu geode.nu list [vault] [prefix] # entry names and sizes, no contents +nu geode.nu verify [vault] [--sample 0.05] # default --cheap +nu geode.nu recipients [vault] # recipient types and key ids (public) +nu geode.nu snapshots [vault] +nu geode.nu policy [vault] +nu geode.nu can [vault] # dry run; deny is exit 3 +nu geode.nu audit +nu geode.nu custody +nu geode.nu keyring +``` + +Each command prints one JSON envelope: `{ ok, command, exit, data, error }`. +`can` keeps `ok: true` when geode exits 3 (deny). `audit` keeps `ok: true` +when geode exits 2 (chain failed). + +## Never run from this skill + +`geode.nu` refuses anything that is not in the list above, including `cat`, +`open`, `mount`, `run`, `agent`, `keygen`, `seal`, `sign`, `vault init`, +`vault add-recipient`, `vault rotate`, `policy set`, `keyring add`, +`custody unlock/lock`, `gc`, and `git unlock`. Those read secret bytes, put +them in an environment or on disk, or change custody. They need a human, and +their output must never be pasted into notes, logs, or chat. + +Entry names can themselves be sensitive. Quote them only where the reader is +allowed to know the vault holds them. diff --git a/.grok/skills/geode/geode.nu b/.grok/skills/geode/geode.nu new file mode 100755 index 0000000..5f722d5 --- /dev/null +++ b/.grok/skills/geode/geode.nu @@ -0,0 +1,224 @@ +#!/usr/bin/env nu +# Fixed metadata-only body for the geode skill. Wraps `geode --output json`. +# stdout is one JSON envelope: {ok, command, exit, data, error} +# Only the allowlist is passed to geode. Anything else is refused. + +const ALLOWED = [ + "list" + "verify" + "vault recipients" + "snapshot ls" + "policy show" + "policy check" + "audit verify" + "custody status" + "keyring list" +] + +def clip-error [stderr: string, stdout: string] { + let joined = ([$stderr $stdout] | str join " " | str trim) + if ($joined | is-empty) { + "command failed" + } else { + ($joined | lines | first | str substring 0..399) + } +} + +def ok-row [command: string, exit: int, data: any] { + { ok: true, command: $command, exit: $exit, data: $data, error: null } +} + +def err-row [command: string, exit: int, error: string] { + { ok: false, command: $command, exit: $exit, data: null, error: ($error | str substring 0..399) } +} + +def refused [command: string, detail: string] { + err-row $command 2 $"refused: geode skill is metadata-only ($detail)" +} + +def as-text [raw: any] { + let d = ($raw | describe) + if $d == "string" { + $raw + } else { + try { $raw | decode utf-8 } catch { "" } + } +} + +def parse-json [text: string] { + let t = ($text | str trim) + if ($t | is-empty) { + error make { msg: "empty json" } + } + $t | from json --strict +} + +def vault-path [v: string] { + if $v != "" { $v } else { $env.GEODE_VAULT? | default "" } +} + +def run-geode [ + command: string, + sub: list, + rest: list, + ok_codes: list = [0], + permit_flags: list = [], +] { + let key = ($sub | str join " ") + let flagged = ($rest | where {|a| ($a | str starts-with "-") and (not ($a in $permit_flags)) }) + if not ($key in $ALLOWED) { + refused $command $"not on the allowlist: ($key)" + } else if not ($flagged | is-empty) { + refused $command "flags are not accepted" + } else { + let argv = (["--output" "json"] ++ $sub ++ $rest) + let r = (try { + ^geode ...$argv | complete + } catch {|e| + { stdout: "", stderr: $"geode: ($e.msg)", exit_code: 127 } + }) + let stdout = (as-text $r.stdout) + let stderr = (as-text $r.stderr) + if not ($r.exit_code in $ok_codes) { + err-row $command $r.exit_code (clip-error $stderr $stdout) + } else { + let parsed = (try { { ok: true, value: (parse-json $stdout) } } catch {|e| { ok: false, value: $e.msg } }) + if not $parsed.ok { + err-row $command 1 $"invalid json: ($parsed.value)" + } else { + ok-row $command $r.exit_code $parsed.value + } + } + } +} + +def path-verb [p: string] { + $p in [ + set init add-recipient rotate add unlock lock delete rm + start end get unset cat open mount run agent keygen seal sign gc + ] +} + +def need-vault [command: string, vault: string] { + let p = (vault-path $vault) + if (path-verb $vault) { + refused $command $"($vault) is not available from this skill" + } else if $p == "" { + err-row $command 2 "no vault: pass one or set GEODE_VAULT" + } else if ($p | str starts-with "-") { + refused $command "vault path must not be a flag" + } else { + { ok: true, path: $p } + } +} + +def "main list" [vault: string = "", prefix: string = "", ...rest: string] { + if not ($rest | is-empty) { + refused "list" "extra arguments" | to json --raw + } else { + let got = (need-vault "list" $vault) + if not $got.ok { + $got | to json --raw + } else { + let rest_args = ([$got.path] ++ (if $prefix == "" { [] } else { [$prefix] })) + run-geode "list" [list] $rest_args | to json --raw + } + } +} + +def "main verify" [vault: string = "", --sample: string = "", ...rest: string] { + if not ($rest | is-empty) { + refused "verify" "extra arguments" | to json --raw + } else { + let got = (need-vault "verify" $vault) + if not $got.ok { + $got | to json --raw + } else if $sample == "" { + run-geode "verify" [verify] [$got.path "--cheap"] [0] ["--cheap"] | to json --raw + } else { + let numeric = (try { $sample | into float; true } catch {|_| false }) + if not $numeric or ($sample | str starts-with "-") { + refused "verify" "sample must be a non-negative number" | to json --raw + } else { + run-geode "verify" [verify] [$got.path "--sample" $sample] [0] ["--sample"] | to json --raw + } + } + } +} + +def "main recipients" [vault: string = "", ...rest: string] { + if not ($rest | is-empty) { + refused "recipients" "extra arguments" | to json --raw + } else { + let got = (need-vault "recipients" $vault) + if not $got.ok { $got | to json --raw } else { + run-geode "recipients" [vault recipients] [$got.path] | to json --raw + } + } +} + +def "main snapshots" [vault: string = "", ...rest: string] { + if not ($rest | is-empty) { + refused "snapshots" "extra arguments" | to json --raw + } else { + let got = (need-vault "snapshots" $vault) + if not $got.ok { $got | to json --raw } else { + run-geode "snapshots" [snapshot ls] [$got.path] | to json --raw + } + } +} + +def "main policy" [vault: string = "", ...rest: string] { + if not ($rest | is-empty) { + refused "policy" "policy set is not available from this skill" | to json --raw + } else { + let got = (need-vault "policy" $vault) + if not $got.ok { $got | to json --raw } else { + run-geode "policy" [policy show] [$got.path] | to json --raw + } + } +} + +def "main can" [principal: string, op: string, path: string, vault: string = "", ...rest: string] { + if not ($rest | is-empty) { + refused "can" "extra arguments" | to json --raw + } else if ([$principal $op $path] | any {|a| $a | str starts-with "-" }) { + refused "can" "flags are not accepted" | to json --raw + } else { + let got = (need-vault "can" $vault) + if not $got.ok { $got | to json --raw } else { + # deny exits 3; that is a result, not a failure + run-geode "can" [policy check] [$got.path $principal $op $path] [0 3] | to json --raw + } + } +} + +def "main audit" [...rest: string] { + if not ($rest | is-empty) { + refused "audit" "extra arguments" | to json --raw + } else { + # a broken chain exits 2; that is a result, not a failure + run-geode "audit" [audit verify] [] [0 2] | to json --raw + } +} + +def "main custody" [...rest: string] { + if not ($rest | is-empty) { + refused "custody" "unlock/lock is not available from this skill" | to json --raw + } else { + run-geode "custody" [custody status] [] | to json --raw + } +} + +def "main keyring" [...rest: string] { + if not ($rest | is-empty) { + refused "keyring" "keyring add is not available from this skill" | to json --raw + } else { + run-geode "keyring" [keyring list] [] | to json --raw + } +} + +def main [...args: string] { + let command = ($args | first | default "") + refused $command ($args | str join " ") | to json --raw +} diff --git a/.grok/skills/lapis/SKILL.md b/.grok/skills/lapis/SKILL.md new file mode 100644 index 0000000..9e8b3b2 --- /dev/null +++ b/.grok/skills/lapis/SKILL.md @@ -0,0 +1,52 @@ +--- +name: lapis +description: > + Search and read a Lapis notes vault through the lapis CLI. Use when a task + needs notes, doctrine, project context, wikilink neighbors, or recent notes + from the vault. Prefer this skill over the lapis MCP server: it adds no tool + schemas to context and its body is deterministic. The MCP server remains + available. +--- + +# lapis — vault read skill + +`lapis` owns the vault and its index. This skill only reads, through the +fixed script `lapis.nu` next to this file. Never open `.lapis/` index files +directly, and do not reimplement the calls. + +## Configuration + +The vault path is resolved in this order: + +1. `--vault ` passed to any command +2. `$LAPIS_VAULT` +3. the path recorded by `lapis init` in the lapis config + +## Commands + +```bash +nu lapis.nu search "phrase" --limit 5 [--domain d] +nu lapis.nu read path/to/note.md +nu lapis.nu list [--prefix projects/] +nu lapis.nu neighbors path/to/note.md +nu lapis.nu resolve "[[Note Name]]" +nu lapis.nu recent [--limit 10] +nu lapis.nu status +nu lapis.nu doctor +``` + +Each command prints one JSON envelope: `{ ok, command, exit, data, error }`. + +- `search`: BM25 over chunks (vectors only if an embedder is configured); one hit per note. `data` is `path` and `title` only. +- `read`: frontmatter (`hal`) plus body. +- `list`: index metadata only; never walks the vault. +- `neighbors`: hop-1 wikilink edges. +- `recent`: newest first. Each row is read by name: `path`, `title`, and `mtime_iso` (Lapis 0.4.2) or `mtime` (older builds). `mtime_iso` wins when both are present. +- `status` / `doctor`: vault root and index health (`exit` 2 when the index is down). + +## Rules + +- Read before you cite: give the note path and quote the passage. +- Writes (`create`, `append`, `task`, `trash`) are refused by `lapis.nu`. + Run them only when a human has explicitly asked, and not through this skill. +- If a path is missing, start `neighbors` from a hub note rather than guessing. diff --git a/.grok/skills/lapis/lapis.nu b/.grok/skills/lapis/lapis.nu new file mode 100755 index 0000000..a54633c --- /dev/null +++ b/.grok/skills/lapis/lapis.nu @@ -0,0 +1,203 @@ +#!/usr/bin/env nu +# Fixed read-only body for the lapis skill. Wraps `lapis --json`. +# stdout is one JSON envelope: {ok, command, exit, data, error} +# Vault: --vault, else $LAPIS_VAULT, else the lapis config default. + +def clip-error [stderr: string, stdout: string] { + let joined = ([$stderr $stdout] | str join " " | str trim) + if ($joined | is-empty) { + "command failed" + } else { + ($joined | lines | first | str substring 0..399) + } +} + +def ok-row [command: string, exit: int, data: any] { + { ok: true, command: $command, exit: $exit, data: $data, error: null } +} + +def err-row [command: string, exit: int, error: string] { + { ok: false, command: $command, exit: $exit, data: null, error: ($error | str substring 0..399) } +} + +def as-text [raw: any] { + let d = ($raw | describe) + if $d == "string" { + $raw + } else { + try { $raw | decode utf-8 } catch { "" } + } +} + +def parse-json [text: string] { + let t = ($text | str trim) + if ($t | is-empty) { + error make { msg: "empty json" } + } + $t | from json --strict +} + +def vault-args [vault: string] { + let v = if $vault != "" { $vault } else { $env.LAPIS_VAULT? | default "" } + if ($v | str starts-with "-") { + error make { msg: "vault path must not be a flag" } + } + if $v == "" { [] } else { ["--vault" $v] } +} + +def lapis-data [value: any] { + let d = ($value | describe) + if ($d | str starts-with "record") and ("data" in ($value | columns)) { + $value | get data + } else { + $value + } +} + +def run-lapis [command: string, args: list, vault: string] { + let vault_part = (try { vault-args $vault } catch {|e| $e.msg }) + if ($vault_part | describe) == "string" { + err-row $command 2 $vault_part + } else { + let argv = (["--json"] ++ $vault_part ++ $args) + let r = (try { + ^lapis ...$argv | complete + } catch {|e| + { stdout: "", stderr: $"lapis: ($e.msg)", exit_code: 127 } + }) + let stdout = (as-text $r.stdout) + let stderr = (as-text $r.stderr) + if $r.exit_code != 0 { + err-row $command $r.exit_code (clip-error $stderr $stdout) + } else { + let parsed = (try { { ok: true, value: (parse-json $stdout) } } catch {|e| { ok: false, value: $e.msg } }) + if not $parsed.ok { + err-row $command 1 $"invalid json: ($parsed.value)" + } else { + ok-row $command 0 (lapis-data $parsed.value) + } + } + } +} + +def flagish [s: string] { $s | str starts-with "-" } + +def "main search" [query: string, --limit (-n): int = 5, --domain: string = "", --vault: string = ""] { + if $limit < 1 { + err-row "search" 2 "limit must be >= 1" | to json --raw + } else if (flagish $query) or (flagish $domain) { + err-row "search" 2 "refused: lapis skill is read-only" | to json --raw + } else { + mut args = ["search" $query "-n" ($limit | into string)] + if $domain != "" { $args = ($args ++ ["--domain" $domain]) } + let row = (run-lapis "search" $args $vault) + if not $row.ok { + $row | to json --raw + } else { + let hits = (try { $row.data | get hits } catch {|err| null }) + let kind = ($hits | describe) + if not (($kind | str starts-with "list") or ($kind | str starts-with "table")) { + err-row "search" 1 "search data has no hits" | to json --raw + } else { + let slim = (try { $hits | select path title } catch {|err| null }) + if ($slim | describe) == "nothing" { + err-row "search" 1 "search hits missing path or title" | to json --raw + } else { + ok-row "search" $row.exit $slim | to json --raw + } + } + } + } +} + +def "main read" [path: string, --vault: string = ""] { + if (flagish $path) { + err-row "read" 2 "refused: lapis skill is read-only" | to json --raw + } else { + run-lapis "read" ["read" $path] $vault | to json --raw + } +} + +def "main list" [--prefix: string = "", --vault: string = ""] { + let row = (run-lapis "list" ["list"] $vault) + if not $row.ok or $prefix == "" { + $row | to json --raw + } else { + let kind = ($row.data | describe) + if not (($kind | str starts-with "list") or ($kind | str starts-with "table")) { + err-row "list" 1 "list data is not a list" | to json --raw + } else { + let filtered = ($row.data | where path starts-with $prefix) + ok-row "list" $row.exit $filtered | to json --raw + } + } +} + +def "main neighbors" [path: string, --vault: string = ""] { + if (flagish $path) { + err-row "neighbors" 2 "refused: lapis skill is read-only" | to json --raw + } else { + run-lapis "neighbors" ["neighbors" $path] $vault | to json --raw + } +} + +def "main resolve" [link: string, --vault: string = ""] { + if (flagish $link) { + err-row "resolve" 2 "refused: lapis skill is read-only" | to json --raw + } else { + run-lapis "resolve" ["resolve" $link] $vault | to json --raw + } +} + +# Lapis 0.4.2 rows are path, title, domain, priority, mtime_iso. +# Older builds are path, title, mtime. Read those fields by name. +def recent-mtime [row: record] { + let cols = ($row | columns) + if "mtime_iso" in $cols { + $row | get mtime_iso + } else if "mtime" in $cols { + $row | get mtime + } else { + error make { msg: "recent row missing mtime" } + } +} + +def "main recent" [--limit (-n): int = 10, --vault: string = ""] { + if $limit < 1 { + err-row "recent" 2 "limit must be >= 1" | to json --raw + } else { + let row = (run-lapis "recent" ["analytics" "recent"] $vault) + if not $row.ok { + $row | to json --raw + } else { + let rows = (try { $row.data | get rows } catch {|err| null }) + let shaped = (try { + $rows | first $limit | each {|r| + { + path: ($r | get path) + title: ($r | get title) + mtime: (recent-mtime $r) + } + } + } catch {|err| null }) + if ($shaped | describe) == "nothing" { + err-row "recent" 1 "recent data has no rows" | to json --raw + } else { + ok-row "recent" $row.exit $shaped | to json --raw + } + } + } +} + +def "main status" [--vault: string = ""] { + run-lapis "status" ["vault" "info"] $vault | to json --raw +} + +def "main doctor" [--vault: string = ""] { + run-lapis "doctor" ["doctor"] $vault | to json --raw +} + +def main [...args: string] { + let command = ($args | first | default "") + err-row $command 2 "refused: lapis skill is read-only" | to json --raw +} diff --git a/.grok/skills/laws/LAWS.bend b/.grok/skills/laws/LAWS.bend new file mode 100644 index 0000000..17ef699 --- /dev/null +++ b/.grok/skills/laws/LAWS.bend @@ -0,0 +1,85 @@ +import Base + +type Mode is Data: + Shadow{} + Active{} + +type Auto is Data: + Hold{} + Allow{} + +type Call is Data: + Denied{} + Open{} + +type Transport is Data: + Silent{} + Called{} + +type Findings is Data: + Empty{} + Present{} + +type Approval is Data: + No{} + Yes{} + +type Key is Data: + Public{} + Secret{} + +type State is Data: + Rejected{} + Seated{} + +def verdict_auto(mode: Mode) -> Auto: + match mode: + case Shadow{}: + Hold{} + case Active{}: + Hold{} + +def transport(call: Call) -> Transport: + match call: + case Denied{}: + Silent{} + case Open{}: + Called{} + +def approval(findings: Findings) -> Approval: + match findings: + case Empty{}: + No{} + case Present{}: + Yes{} + +def state(key: Key) -> State: + match key: + case Secret{}: + Rejected{} + case Public{}: + Seated{} + +law shadow_cannot_set_auto_allow: + {verdict_auto(Shadow{}) == Hold{} : Auto} + +def shadow_cannot_set_auto_allow(): + {==} + +law code_deny_never_calls_transport: + {transport(Denied{}) == Silent{} : Transport} + +def code_deny_never_calls_transport(): + {==} + +law empty_findings_are_not_approval: + {approval(Empty{}) == No{} : Approval} + +def empty_findings_are_not_approval(): + {==} + +law state_rejects_secret_key: + {state(Secret{}) == Rejected{} : State} + +def state_rejects_secret_key(): + {==} diff --git a/.grok/skills/laws/PROOF.bend b/.grok/skills/laws/PROOF.bend new file mode 100644 index 0000000..94e95aa --- /dev/null +++ b/.grok/skills/laws/PROOF.bend @@ -0,0 +1,13 @@ +import ./LAWS.bend as Laws + +def main() -> {Laws.verdict_auto(Laws.Shadow{}) == Laws.Hold{} : Laws.Auto} & {Laws.transport(Laws.Denied{}) == Laws.Silent{} : Laws.Transport} & {Laws.approval(Laws.Empty{}) == Laws.No{} : Laws.Approval} & {Laws.state(Laws.Secret{}) == Laws.Rejected{} : Laws.State}: + ( + Laws.shadow_cannot_set_auto_allow(), + ( + Laws.code_deny_never_calls_transport(), + ( + Laws.empty_findings_are_not_approval(), + Laws.state_rejects_secret_key() + ) + ) + ) diff --git a/.grok/skills/laws/SKILL.md b/.grok/skills/laws/SKILL.md new file mode 100644 index 0000000..e3d4bbf --- /dev/null +++ b/.grok/skills/laws/SKILL.md @@ -0,0 +1,31 @@ +--- +name: laws +description: Bend2 LAWS.bend for the Bezel bridle. The harness stays the harness. This skill carries the laws the bridle checks. +--- + +# laws + +Bezel is not a harness. It is the bridle on one: the piece that sits on Grok, omp, or Cursor and decides what that harness may do. This skill is how that bridle travels inside the Bezel skill pack. + +## What you are holding + +`LAWS.bend` states invariants. `PROOF.bend` checks them once the Rust modules exist. The JavaScript prototype at `v0.1.0` is the oracle, not the thing Bend proves. + +Draft these four laws. Do not invent a second runtime. + +- A shadow verdict cannot set `auto_allow`. +- A code deny never calls transport. +- Empty findings are not approval. +- A `state` constructor rejects a secret-shaped key. + +## Where it sits + +The harness loads this skill from the Bezel pack. Bezel does not replace the harness, and it does not exec the agent. `initiated` stays false. The publish name, if `bezel` is taken, is `bezel-bridle`. + +## Do not + +- Treat this skill as permission to delete the JavaScript before parity +- Link `@typesafe-ai/sdk` from Rust +- Publish the crate `bezel` +- Flip the live PreToolUse matcher +- Run `cargo` on castle diff --git a/CLAUDE.md b/CLAUDE.md new file mode 100644 index 0000000..43c994c --- /dev/null +++ b/CLAUDE.md @@ -0,0 +1 @@ +@AGENTS.md diff --git a/README.md b/README.md index 248db98..f619ad5 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ Bezel is the supplement, not the harness. It ships the suite in one Nix flake: s | Piece | What you get | | --- | --- | -| Skills | Flake input `inputs.skills` (`skills-stub/`). Each skill is a directory with `SKILL.md`. Lapis, Facet, and Geode default to that skill plus the CLI. Home Manager symlinks the store path to the directory the harness already reads. | +| Skills | Flake input `inputs.skills` (`.agents/skills/`). Each skill is a directory with `SKILL.md`. Lapis, Facet, and Geode default to that skill plus the CLI. Home Manager copies each skill directory as regular files into the user directory each harness reads. | | Jev | `jev-router` asks Typesafe for one policy decision and prints one JSON verdict. Shadow, the default, logs the verdict and does not block. | | Toolkit | `jev-router --catalog` prints a small tool index. `--schema NAME` prints one JSON Schema. Reading a schema does not allow the tool. `--check` is a shadow diff check. | | Cursor | `cursor-agent-jev` runs the gate, then execs `cursor-agent`. | @@ -88,7 +88,7 @@ The product name is Bezel. The repository is [VirtualMachinist/bezel](https://gi } ``` -`programs.bezel.enable` installs `bezel` (`bezel-omp`), `jev-router`, `cursor-agent-jev`, and `grok-build-jev`. It symlinks the skills input to `~/.config/omp/agent/skills`, the directory the omp harness loads. `programs.omapi` is deprecated; it renames to `programs.bezel`. +`programs.bezel.enable` installs `bezel` (`bezel-omp`), `jev-router`, `cursor-agent-jev`, and `grok-build-jev`. It copies each skill directory as regular files into `~/.agents/skills`, `~/.claude/skills`, `~/.grok/skills`, and `~/.cursor/skills`. `programs.omapi` is deprecated; it renames to `programs.bezel`. ## Packages @@ -116,7 +116,7 @@ The flake input and the primary package attribute are `bezel`. `packages.default | Same package attrs | `.#omapi` is `bezel`. `.#omapi-pinned` is `bezel-pinned`. | | Jev commands | `jev-router`, `cursor-agent-jev`, `grok-build-jev` | | Home Manager | `programs.bezel`. `programs.omapi` is deprecated and renames to `programs.bezel`. | -| Skills path | `~/.config/omp/agent/skills` (the omp harness path) | +| Skills paths | `~/.agents/skills`, `~/.claude/skills`, `~/.grok/skills`, `~/.cursor/skills` | | Env | `BEZEL_*`. Legacy `OMAPI_*` is still read. The wrap sets both `BEZEL_OVERLAY` and `OMAPI_OVERLAY`. | Gate version strings stay `omapi-loop-stop-policy@1`, `omapi-check-policy@1`, and `omapi-route-workflow-policy@1`. Those ids are the policy contract. The typed-call host profile id stays `omapi-jev-router`. Changing either would change verdicts, not the product name. `omp-pin` and `omp-runtime` stay those attribute names. @@ -155,7 +155,7 @@ JEV_MODE=shadow jev-router --check --intent "" # or: --diff-file packages/jev-router/testdata/skip-marker.diff ``` -Skill: `skills-stub/check`. How to run: [docs/SPIKE-stanley.md](docs/SPIKE-stanley.md). +Skill: `.agents/skills/check`. How to run: [docs/SPIKE-stanley.md](docs/SPIKE-stanley.md). Grok `PreToolUse` uses the same three policy ids and the same `JEV_BYPASS` predicate. The tool-class map, matcher (shell, write, and MCP), and the hook checklist are in [docs/POLICY-MAP.md](docs/POLICY-MAP.md). The hook calls `jev-router`. It is not a second TypeSafe client. Default mode stays shadow. @@ -186,13 +186,13 @@ How to run: [docs/GROK-BUILD.md](docs/GROK-BUILD.md). ## Skills -Skills are a flake input, and that input is the only skills tree Bezel installs. This repo ships them in `skills-stub/` (`inputs.skills`). Home Manager symlinks that store path to `~/.config/omp/agent/skills`. There is no second repo-root `skills/` tree. When you have a skills repo, change `inputs.skills.url` and the lock. +Skills are a flake input, and that input is the only skills tree Bezel installs. This repo ships them in `.agents/skills/` (`inputs.skills`). `scripts/sync-skills` writes regular-file copies to `.claude/skills/`, `.grok/skills/`, and `.cursor/skills/`. There is no repo-root `skills/` tree, no `.omp/skills/`, and no `.codex/skills/`. When you have a skills repo, change `inputs.skills.url` and the lock. The tree includes `bootstrap`, the shadow `check` skill (`jev-router --check`), and `laws`. It also includes shared read-only skills for Lapis, Facet, and Geode. ### Agent use: skills + CLI first, MCP still shipped -The default way for an agent to use Lapis, Facet, or Geode is the bundled skill. In this repo that directory is `skills-stub//`. After install it is `~/.config/omp/agent/skills//`. A short `SKILL.md` is what the harness reads to decide when to use it, plus a Nushell body (`nu .nu`) that calls the CLI with JSON output. Every command prints the same envelope: `{ ok, command, exit, data, error }`. +The default way for an agent to use Lapis, Facet, or Geode is the bundled skill. In this repo that directory is `.agents/skills//`. After install, the same directory is at `~/.agents/skills//`, `~/.claude/skills//`, `~/.grok/skills//`, and `~/.cursor/skills//`. A short `SKILL.md` is what the harness reads to decide when to use it, plus a Nushell body (`nu .nu`) that calls the CLI with JSON output. Every command prints the same envelope: `{ ok, command, exit, data, error }`. The MCP server for each tool (`lapis mcp`, `facet mcp`, `geode mcp`) stays supported and works the same as that tool ships it. Bezel does not disable MCP. @@ -204,11 +204,11 @@ Why the skill is the default: Use the MCP server when your harness defers or filters MCP tool schemas (loading them only on demand, or letting you enable single tools), or when the client has no shell. -`programs.bezel.enable` puts the pinned Nushell on `PATH` and links the whole tree for omp. Install one skill into another harness by copying or linking `skills-stub//` into that harness's skills directory (for example `~/.agents/skills/` or `~/.claude/skills/`). +`programs.bezel.enable` puts the pinned Nushell on `PATH` and copies each skill directory into the four user directories above. The copies are regular files. A second activation leaves a file alone when its bytes already match, and it keeps that file's mode. If a managed file already exists with different bytes, or the path is a symlink, the activation prints a drift report and writes nothing, so a live `~/.agents/skills/lapis/lapis.nu` stays in place for `~/.local/bin/lapisq`. Repair with `scripts/install-user-skills.sh --force .agents/skills "$HOME"`, which replaces the bytes and keeps the mode the file already had. `--check` reports drift and writes nothing. ```sh nix build .#nushell -nu skills-stub/lapis/lapis.nu status +nu .agents/skills/lapis/lapis.nu status ``` These three scripts are read-only. Facet never requests history bodies, blobs, `diff --bodies`, or `request run`. Geode is metadata only and refuses every other command. @@ -236,7 +236,7 @@ If a later release drops a platform build, `packages/omp-pin.nix` **throws** for - Jev defaults to shadow. `jev-router --check` is the shadow diff check. Empty findings are not approval. Loop-stop is shadow-first. Active `stop` and `escalate` do not exec. - The tool catalog is a small always-on index of the existing policy ids. Full schema is `jev-router --schema NAME` and is not an allow. Permission catalogs stay shadow. - `grok-build-jev` adapts those controls for Grok Build. Default modes stay shadow. The harness does not install a host hook. -- Skills ship as `skills-stub`, the flake's only skills tree. Lapis, Facet, and Geode are read-only skills there: skill plus CLI is the default, and MCP remains supported. Nushell is pinned by the nixpkgs lock. +- Skills ship as `.agents/skills`, the flake's only skills tree. Lapis, Facet, and Geode are read-only skills there: skill plus CLI is the default, and MCP remains supported. Nushell is pinned by the nixpkgs lock. - Nix packaging stays. The router stays JavaScript. ## Contributing diff --git a/crates/bezel-bridle/src/lib.rs b/crates/bezel-bridle/src/lib.rs index 726791e..bf9d61a 100644 --- a/crates/bezel-bridle/src/lib.rs +++ b/crates/bezel-bridle/src/lib.rs @@ -67,7 +67,7 @@ mod tests { } fn laws_sentence() -> String { - let path = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../../skills-stub/laws/LAWS.bend"); + let path = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../../.agents/skills/laws/LAWS.bend"); std::fs::read_to_string(&path).unwrap_or_else(|err| panic!("read {}: {err}", path.display())) } diff --git a/docs/SPIKE-stanley.md b/docs/SPIKE-stanley.md index a3cee26..6749977 100644 --- a/docs/SPIKE-stanley.md +++ b/docs/SPIKE-stanley.md @@ -31,7 +31,7 @@ nix build .#jev-router --diff-file packages/jev-router/testdata/skip-marker.diff ``` -Skill (Home Manager skills input): `skills-stub/check/SKILL.md`. +Skill (Home Manager skills input): `.agents/skills/check/SKILL.md`. ## What you get diff --git a/flake.lock b/flake.lock index 0d2218a..74276fa 100644 --- a/flake.lock +++ b/flake.lock @@ -42,11 +42,11 @@ "skills": { "flake": false, "locked": { - "path": "./skills-stub", + "path": "./.agents/skills", "type": "path" }, "original": { - "path": "./skills-stub", + "path": "./.agents/skills", "type": "path" }, "parent": [] diff --git a/flake.nix b/flake.nix index 546d1e9..d84c733 100644 --- a/flake.nix +++ b/flake.nix @@ -10,7 +10,7 @@ # Sole skills input. Lapis, Facet, and Geode live in this tree with the # Bezel stub skills. Do not add a second repo-root skills/ product tree. skills = { - url = "path:./skills-stub"; + url = "path:./.agents/skills"; flake = false; }; }; @@ -34,12 +34,17 @@ ]; # Evaluated by the skills-cli check. A repo-root skills/ directory would - # be a second product tree next to inputs.skills (skills-stub). + # be a second product tree next to inputs.skills (.agents/skills). + # .omp/skills would shadow the other copies. Codex reads .agents/skills. skillsTreeOk = if builtins.pathExists ./skills then - throw "Do not add a repo-root skills/ tree. Ship Lapis, Facet, and Geode through inputs.skills (skills-stub)." + throw "Do not add a repo-root skills/ tree. Ship Lapis, Facet, and Geode through inputs.skills (.agents/skills)." + else if builtins.pathExists ./.omp/skills then + throw "Do not add .omp/skills. It shadows the other harness copies." + else if builtins.pathExists ./.codex/skills then + throw "Do not add .codex/skills. Codex reads .agents/skills." else - "skills-stub"; + "agents-skills"; forAllSystems = f: lib.genAttrs systems (system: f system); @@ -360,14 +365,14 @@ export HOME=$TMPDIR/home mkdir -p "$CARGO_HOME" "$HOME" "$CARGO_TARGET_DIR" work=$TMPDIR/bridle - mkdir -p "$work/crates/bezel-bridle" "$work/packages" "$work/docs" "$work/skills-stub" + mkdir -p "$work/crates/bezel-bridle" "$work/packages" "$work/docs" "$work/.agents/skills" cp ${./crates/bezel-bridle}/Cargo.toml ${./crates/bezel-bridle}/Cargo.lock "$work/crates/bezel-bridle/" cp -r ${./crates/bezel-bridle}/src "$work/crates/bezel-bridle/src" cp -r ${./packages/jev-router} "$work/packages/jev-router" cp ${./docs/POLICY-MAP.md} "$work/docs/POLICY-MAP.md" cp ${./packages/cursor-agent-jev.nix} "$work/packages/cursor-agent-jev.nix" cp ${./packages/bezel-planes-shim.sh} "$work/packages/bezel-planes-shim.sh" - cp -r ${./skills-stub}/laws "$work/skills-stub/laws" + cp -r ${./.agents/skills}/laws "$work/.agents/skills/laws" chmod -R u+w "$work" test -f "$work/crates/bezel-bridle/src/oracle.rs" cargo test --offline --manifest-path "$work/crates/bezel-bridle/Cargo.toml" @@ -687,8 +692,10 @@ ]; } '' set -eu - test "${skillsTreeOk}" = skills-stub - bash ${./scripts/check-skill-cli.sh} ${./skills-stub} + test "${skillsTreeOk}" = agents-skills + bash ${./scripts}/check-skill-copies.sh ${./.agents/skills} ${./.claude/skills} ${./.grok/skills} ${./.cursor/skills} + bash ${./scripts}/check-user-skills.sh ${./.agents/skills} + bash ${./scripts}/check-skill-cli.sh ${./.agents/skills} echo ok >"$out" ''; } diff --git a/modules/home-manager.nix b/modules/home-manager.nix index c2ecad1..3eef3f6 100644 --- a/modules/home-manager.nix +++ b/modules/home-manager.nix @@ -6,9 +6,10 @@ ... }: -# Skills flake input is the sole SoT. This module only symlinks that store -# path. Do not vendor a second skills/ tree in Bezel. Nushell is on PATH so -# the Lapis, Facet, and Geode skill bodies can run. +# Skills flake input is the sole SoT. This module copies that tree into each +# harness's user directory as regular files. Do not vendor a second skills/ +# tree in Bezel. Nushell is on PATH so the Lapis, Facet, and Geode skill +# bodies can run. # `programs.omapi` is deprecated. It renames to `programs.bezel`. { @@ -43,9 +44,10 @@ defaultText = lib.literalExpression "inputs.skills"; description = '' Sole skills source of truth: the flake `inputs.skills` store path. - Home Manager only symlinks this path to ~/.config/omp/agent/skills, - the directory the omp harness reads. Bezel does not invent a second tree. - Do not point this at a second in-repo skills/ copy. + Home Manager copies each skill directory as regular files into + ~/.agents/skills, ~/.claude/skills, ~/.grok/skills, and ~/.cursor/skills. + Bezel does not invent a second tree. Do not point this at a second + in-repo skills/ copy. ''; }; }; @@ -53,6 +55,18 @@ config = lib.mkIf config.programs.bezel.enable { home.packages = [ config.programs.bezel.package ] ++ config.programs.bezel.extraPackages; - xdg.configFile."omp/agent/skills".source = config.programs.bezel.skillsSource; + # Regular files, one tree per harness. Matching bytes stay in place, + # including their mode. Different bytes or a symlinked managed file fail + # this activation: it does not pass --force, and the existing file is left + # unchanged. lib.hm is Home Manager's module library. + home.activation.bezelUserSkills = + let + dag = lib.hm.dag or (throw "programs.bezel needs Home Manager (lib.hm.dag)"); + in + dag.entryAfter [ "writeBoundary" ] '' + ${pkgs.bash}/bin/bash ${../scripts}/install-user-skills.sh ${ + lib.escapeShellArg (toString config.programs.bezel.skillsSource) + } ${lib.escapeShellArg config.home.homeDirectory} + ''; }; } diff --git a/packages/jev-router/default.nix b/packages/jev-router/default.nix index c3656c3..b614c09 100644 --- a/packages/jev-router/default.nix +++ b/packages/jev-router/default.nix @@ -32,14 +32,14 @@ stdenv.mkDerivation { export HOME=$TMPDIR/home mkdir -p "$CARGO_HOME" "$HOME" work=$TMPDIR/bridle - mkdir -p "$work/crates/bezel-bridle" "$work/packages/jev-router" "$work/docs" "$work/skills-stub" + mkdir -p "$work/crates/bezel-bridle" "$work/packages/jev-router" "$work/docs" "$work/.agents/skills" cp ${repoRoot}/crates/bezel-bridle/Cargo.toml ${repoRoot}/crates/bezel-bridle/Cargo.lock "$work/crates/bezel-bridle/" cp -r ${repoRoot}/crates/bezel-bridle/src "$work/crates/bezel-bridle/src" cp -r ${repoRoot}/packages/jev-router/testdata "$work/packages/jev-router/testdata" cp ${repoRoot}/docs/POLICY-MAP.md "$work/docs/POLICY-MAP.md" cp ${repoRoot}/packages/cursor-agent-jev.nix "$work/packages/cursor-agent-jev.nix" cp ${repoRoot}/packages/bezel-planes-shim.sh "$work/packages/bezel-planes-shim.sh" - cp -r ${repoRoot}/skills-stub/laws "$work/skills-stub/laws" + cp -r ${repoRoot}/.agents/skills/laws "$work/.agents/skills/laws" chmod -R u+w "$work" echo "bezel-bridle oracle fixtures" export CARGO_TARGET_DIR=$work/target diff --git a/scripts/bend-gate.sh b/scripts/bend-gate.sh index d5670b2..90eac8c 100755 --- a/scripts/bend-gate.sh +++ b/scripts/bend-gate.sh @@ -6,7 +6,7 @@ set -eu export BEND_NO_TELEMETRY="${BEND_NO_TELEMETRY:-1}" root=$(CDPATH= cd -- "$(dirname "$0")/.." && pwd) -proof=${1:-"$root/skills-stub/laws/PROOF.bend"} +proof=${1:-"$root/.agents/skills/laws/PROOF.bend"} if [ ! -f "$proof" ]; then printf 'bend-gate: no proof at %s\n' "$proof" >&2 diff --git a/scripts/check-skill-cli.sh b/scripts/check-skill-cli.sh index 26e6ca2..5c486b2 100755 --- a/scripts/check-skill-cli.sh +++ b/scripts/check-skill-cli.sh @@ -5,7 +5,7 @@ set -euo pipefail script_dir=$(CDPATH= cd -- "$(dirname "$0")" && pwd) root=$(CDPATH= cd -- "$script_dir/.." && pwd) -skills=${1:-$root/skills-stub} +skills=${1:-$root/.agents/skills} nu=${NU:-nu} fail() { @@ -14,7 +14,7 @@ fail() { } if [[ -f "$root/flake.nix" && -d "$root/skills" ]]; then - fail "repo-root skills/ is a second product tree; ship skills through skills-stub/" + fail "repo-root skills/ is a second product tree; ship skills through .agents/skills/" fi command -v "$nu" >/dev/null || fail "nushell (nu) is not on PATH" diff --git a/scripts/check-skill-copies.sh b/scripts/check-skill-copies.sh new file mode 100755 index 0000000..4f837c4 --- /dev/null +++ b/scripts/check-skill-copies.sh @@ -0,0 +1,42 @@ +#!/usr/bin/env bash +# Fail when a harness skill copy differs by a byte or is a symlink. +# No args: this repo. Four args: canonical, claude, grok, and cursor skill roots. + +set -euo pipefail + +script_dir=$(CDPATH= cd -- "$(dirname "$0")" && pwd) +# shellcheck source=skill-mirror.sh +source "$script_dir/skill-mirror.sh" + +if [[ $# -eq 0 ]]; then + root=$(CDPATH= cd -- "$script_dir/.." && pwd) + canonical=$root/.agents/skills + copies=( + "$root/.claude/skills" + "$root/.grok/skills" + "$root/.cursor/skills" + ) +elif [[ $# -eq 4 ]]; then + canonical=$1 + copies=("$2" "$3" "$4") +else + printf 'usage: check-skill-copies.sh [canonical claude grok cursor]\n' >&2 + exit 2 +fi + +repo_root=$(CDPATH= cd -- "$script_dir/.." && pwd) +if [[ -f $repo_root/flake.nix ]]; then + if [[ -d $repo_root/skills ]]; then + skill_fail "repo-root skills/ is a second product tree" + fi + if [[ -d $repo_root/.omp/skills ]]; then + skill_fail ".omp/skills shadows the other harness copies" + fi + if [[ -d $repo_root/.codex/skills ]]; then + skill_fail ".codex/skills is not used; Codex reads .agents/skills" + fi +fi + +for dest in "${copies[@]}"; do + skill_sync_root "$canonical" "$dest" check +done diff --git a/scripts/check-user-skills.sh b/scripts/check-user-skills.sh new file mode 100755 index 0000000..b4eb05e --- /dev/null +++ b/scripts/check-user-skills.sh @@ -0,0 +1,180 @@ +#!/usr/bin/env bash +# Install the skills into a temp home twice and require the second run to +# leave bytes and mtimes alone. A file whose bytes differ, or a symlinked +# file, makes a plain install exit 1 with a drift report and write nothing. +# --force replaces those bytes and keeps the mode the regular file already +# had. --check must fail on a byte change or a symlink without repairing it, +# and the installer must not write through a symlinked destination. + +set -euo pipefail + +script_dir=$(CDPATH= cd -- "$(dirname "$0")" && pwd) +install=$script_dir/install-user-skills.sh + +if [[ $# -ne 1 ]]; then + printf 'usage: check-user-skills.sh CANONICAL\n' >&2 + exit 2 +fi + +canonical=$1 +if [[ ! -d $canonical/lapis || ! -f $canonical/lapis/lapis.nu ]]; then + printf 'check-user-skills: %s is not the Bezel skills tree\n' "$canonical" >&2 + exit 1 +fi + +fail() { + printf 'check-user-skills: %s\n' "$*" >&2 + exit 1 +} + +mtime() { + python3 -c 'import os, sys; print(os.stat(sys.argv[1]).st_mtime_ns)' "$1" +} + +file_mode() { + if stat -c %a "$1" >/dev/null 2>&1; then + stat -c %a "$1" + else + stat -f %OLp "$1" + fi +} + +work=$(mktemp -d) +trap 'rm -rf "$work"' EXIT +home=$work/home +mkdir -p "$home" + +# A skill the installer does not own stays put. +mkdir -p "$home/.claude/skills/other" +printf 'other\n' >"$home/.claude/skills/other/SKILL.md" + +bash "$install" "$canonical" "$home" + +for dest in .agents/skills .claude/skills .grok/skills .cursor/skills; do + [[ -d $home/$dest/lapis ]] || fail "missing $dest/lapis" + [[ ! -L $home/$dest ]] || fail "$dest is a symlink" + [[ ! -L $home/$dest/lapis ]] || fail "$dest/lapis is a symlink" + [[ ! -L $home/$dest/lapis/lapis.nu ]] || fail "$dest/lapis/lapis.nu is a symlink" + cmp -s "$canonical/lapis/lapis.nu" "$home/$dest/lapis/lapis.nu" || fail "$dest lapis.nu bytes differ" + cmp -s "$canonical/lapis/SKILL.md" "$home/$dest/lapis/SKILL.md" || fail "$dest SKILL.md bytes differ" +done + +[[ -f $home/.claude/skills/other/SKILL.md ]] || fail "unrelated skill was removed" +cmp -s <(printf 'other\n') "$home/.claude/skills/other/SKILL.md" || fail "unrelated skill changed" + +if find "$home/.agents" "$home/.claude" "$home/.grok" "$home/.cursor" -type l | grep -q .; then + fail "install left a symlink" +fi + +stamp=$home/.cursor/skills/lapis/lapis.nu +touch -t 200001010000 "$stamp" +before=$(mtime "$stamp") +bash "$install" "$canonical" "$home" +after=$(mtime "$stamp") +[[ $before == "$after" ]] || fail "second install rewrote a matching file" + +# A matching file keeps a mode that is not the normalized 755/644. +live=$home/.agents/skills/lapis/lapis.nu +chmod 700 "$live" +live_stamp=$(mtime "$live") +bash "$install" "$canonical" "$home" +[[ $(file_mode "$live") == 700 ]] || fail "install normalized a matching file's mode" +[[ $(mtime "$live") == "$live_stamp" ]] || fail "install rewrote a mode-only difference" +bash "$install" --check "$canonical" "$home" + +printf 'extra\n' >"$home/.agents/skills/lapis/extra.txt" +if bash "$install" --check "$canonical" "$home"; then + fail "--check passed with an extra file" +fi +[[ -f $home/.agents/skills/lapis/extra.txt ]] || fail "--check removed the extra file" +bash "$install" "$canonical" "$home" +[[ ! -e $home/.agents/skills/lapis/extra.txt ]] || fail "install left an extra file" +[[ -f $home/.claude/skills/other/SKILL.md ]] || fail "repair removed an unrelated skill" + +# Drift check reports and does not repair. A plain install refuses. +err=$work/err +printf 'drift\n' >>"$home/.grok/skills/lapis/SKILL.md" +chmod 640 "$home/.grok/skills/lapis/SKILL.md" +printf 'extra\n' >"$home/.agents/skills/lapis/extra-during-drift.txt" +clean=$(mtime "$home/.agents/skills/lapis/lapis.nu") +if bash "$install" --check "$canonical" "$home"; then + fail "--check passed after a byte change" +fi +grep -q drift "$home/.grok/skills/lapis/SKILL.md" || fail "--check rewrote the drifted file" +status=0 +bash "$install" "$canonical" "$home" 2>"$err" || status=$? +[[ $status -eq 1 ]] || fail "install exit on byte drift was $status" +grep -F -q "byte drift: $home/.grok/skills/lapis/SKILL.md" "$err" || fail "drift report missed the file" +grep -F -q "re-run with --force" "$err" || fail "drift report did not require --force" +grep -q drift "$home/.grok/skills/lapis/SKILL.md" || fail "install overwrote drifted bytes" +[[ $(file_mode "$home/.grok/skills/lapis/SKILL.md") == 640 ]] || fail "refusing install changed the file mode" +[[ -f $home/.agents/skills/lapis/extra-during-drift.txt ]] || fail "refusing install removed an extra file" +[[ $(mtime "$home/.agents/skills/lapis/lapis.nu") == "$clean" ]] || fail "refusing install wrote another tree" +[[ $(file_mode "$live") == 700 ]] || fail "refusing install changed lapis.nu's mode" + +# The four copies are independent files. +cmp -s "$home/.agents/skills/lapis/SKILL.md" "$home/.grok/skills/lapis/SKILL.md" && fail "harness copies were the same file after one drifted" + +status=0 +bash "$install" --check --force "$canonical" "$home" 2>"$err" || status=$? +[[ $status -eq 2 ]] || fail "--check --force exit was $status" +grep -q drift "$home/.grok/skills/lapis/SKILL.md" || fail "--check --force rewrote the drifted file" + +bash "$install" --force "$canonical" "$home" +cmp -s "$canonical/lapis/SKILL.md" "$home/.grok/skills/lapis/SKILL.md" || fail "--force did not repair drift" +[[ $(file_mode "$home/.grok/skills/lapis/SKILL.md") == 640 ]] || fail "--force changed the file mode" +[[ ! -e $home/.agents/skills/lapis/extra-during-drift.txt ]] || fail "--force left an extra file" +[[ $(file_mode "$live") == 700 ]] || fail "--force changed a matching file's mode" +bash "$install" --check "$canonical" "$home" + +# castle: ~/.local/bin/lapisq points at the live lapis.nu. Refuse leaves the +# symlink, the bytes, and the mode. --force updates the bytes only. +printf '\n# castle\n' >>"$live" +mkdir -p "$home/.local/bin" +ln -s "$live" "$home/.local/bin/lapisq" +castle=$(cat "$live") +status=0 +bash "$install" "$canonical" "$home" 2>"$err" || status=$? +[[ $status -eq 1 ]] || fail "install exit on live lapis.nu was $status" +grep -F -q "byte drift: $live" "$err" || fail "drift report missed lapis.nu" +[[ $(readlink "$home/.local/bin/lapisq") == "$live" ]] || fail "refusing install changed lapisq" +[[ $(cat "$live") == "$castle" ]] || fail "refusing install changed live lapis.nu" +[[ $(file_mode "$live") == 700 ]] || fail "refusing install changed live lapis.nu mode" +[[ -x $home/.local/bin/lapisq ]] || fail "lapisq was not executable after refuse" +bash "$install" --force "$canonical" "$home" +cmp -s "$canonical/lapis/lapis.nu" "$live" || fail "--force did not update live lapis.nu" +cmp -s "$canonical/lapis/lapis.nu" "$home/.local/bin/lapisq" || fail "lapisq does not read the updated file" +[[ -L $home/.local/bin/lapisq ]] || fail "--force replaced the lapisq symlink" +[[ $(readlink "$home/.local/bin/lapisq") == "$live" ]] || fail "--force retargeted lapisq" +[[ $(file_mode "$live") == 700 ]] || fail "--force changed live lapis.nu mode" +[[ -x $home/.local/bin/lapisq ]] || fail "lapisq was not executable after --force" +bash "$install" --check "$canonical" "$home" + +# A symlink, even to matching bytes, is drift. Check and a plain install +# leave it. --force replaces it with a regular file. +rm -f "$home/.claude/skills/facet/SKILL.md" +ln -s "$canonical/facet/SKILL.md" "$home/.claude/skills/facet/SKILL.md" +if bash "$install" --check "$canonical" "$home"; then + fail "--check passed while a skill file was a symlink" +fi +[[ -L $home/.claude/skills/facet/SKILL.md ]] || fail "--check replaced a symlink" +status=0 +bash "$install" "$canonical" "$home" 2>"$err" || status=$? +[[ $status -eq 1 ]] || fail "install exit on a symlinked file was $status" +grep -F -q "symlink: $home/.claude/skills/facet/SKILL.md" "$err" || fail "drift report missed the symlink" +[[ -L $home/.claude/skills/facet/SKILL.md ]] || fail "install replaced a symlink without --force" +bash "$install" --force "$canonical" "$home" +[[ ! -L $home/.claude/skills/facet/SKILL.md ]] || fail "--force left the skill file as a symlink" +cmp -s "$canonical/facet/SKILL.md" "$home/.claude/skills/facet/SKILL.md" || fail "--force did not replace the symlink" +bash "$install" --check "$canonical" "$home" + +# Replacing a symlinked skills directory must not write through the link. +holder=$work/holder +mkdir -p "$holder" +rm -rf "$home/.cursor/skills" +ln -s "$holder" "$home/.cursor/skills" +bash "$install" "$canonical" "$home" +[[ ! -L $home/.cursor/skills ]] || fail "install left the skills directory as a symlink" +[[ -d $home/.cursor/skills/lapis ]] || fail "install did not create a real cursor skills tree" +[[ ! -e $holder/lapis ]] || fail "install wrote through the skills symlink" +bash "$install" --check "$canonical" "$home" diff --git a/scripts/install-user-skills.sh b/scripts/install-user-skills.sh new file mode 100755 index 0000000..ae5bda3 --- /dev/null +++ b/scripts/install-user-skills.sh @@ -0,0 +1,94 @@ +#!/usr/bin/env bash +# Copy Bezel skills into each harness's user directory as regular files. +# +# ~/.agents/skills omp (compatible user path) and Codex +# ~/.claude/skills Claude Code personal skills +# ~/.grok/skills Grok user skills +# ~/.cursor/skills Cursor user skills +# +# A second run does not rewrite a file whose bytes already match, and it +# leaves that file's mode alone. When a managed file already exists with +# different bytes, is a symlink, or is not a regular file, the run prints a +# drift report and writes nothing. --force replaces those bytes and keeps the +# mode the regular file already had. --check reports drift and writes nothing. +# Unrelated skill directories already in those folders are left in place. A +# symlinked skills directory is replaced so the copy is not written through +# the link. + +set -euo pipefail + +script_dir=$(CDPATH= cd -- "$(dirname "$0")" && pwd) +# shellcheck source=skill-mirror.sh +source "$script_dir/skill-mirror.sh" + +usage() { + printf 'usage: install-user-skills.sh [--check | --force] SOURCE_DIR HOME\n' >&2 +} + +mode=apply +force=0 +while [[ $# -gt 0 ]]; do + case $1 in + --check) + mode=check + shift + ;; + --force) + force=1 + shift + ;; + --) + shift + break + ;; + -*) + usage + exit 2 + ;; + *) + break + ;; + esac +done + +if [[ $mode == check && $force -eq 1 ]]; then + printf 'install-user-skills: --check and --force cannot be combined\n' >&2 + exit 2 +fi + +if [[ $# -ne 2 ]]; then + usage + exit 2 +fi + +source_dir=$1 +home=$2 + +if [[ -L $source_dir || ! -d $source_dir ]]; then + skill_fail "skills source is not a real directory: $source_dir" +fi +if [[ -L $home || ! -d $home ]]; then + skill_fail "home is not a real directory: $home" +fi + +destinations=( + "$home/.agents/skills" + "$home/.claude/skills" + "$home/.grok/skills" + "$home/.cursor/skills" +) + +if [[ $mode == apply && $force -eq 0 ]]; then + conflict=0 + for dest in "${destinations[@]}"; do + skill_user_conflicts "$source_dir" "$dest" || conflict=1 + done + if [[ $conflict -eq 1 ]]; then + printf 'install-user-skills: refusing to overwrite drifted files; re-run with --force\n' >&2 + exit 1 + fi +fi + +for dest in "${destinations[@]}"; do + skill_sync_user_root "$source_dir" "$dest" "$mode" +done diff --git a/scripts/skill-mirror.sh b/scripts/skill-mirror.sh new file mode 100755 index 0000000..a1ab2ce --- /dev/null +++ b/scripts/skill-mirror.sh @@ -0,0 +1,338 @@ +# Shared regular-file skill tree copy. Source this file; do not execute it. +# A destination matches when every path is a real file or directory and the +# bytes match. Symlinks are drift, including when the target bytes match. + +if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then + printf 'skill-mirror.sh is sourced by the skill scripts\n' >&2 + exit 2 +fi + +skill_fail() { + printf 'skill-mirror: %s\n' "$*" >&2 + exit 1 +} + +# Immediate child directories of a skills root. Each one must contain SKILL.md. +skill_dir_names() { + local root=$1 + local path name + local -a names=() + if [[ -L $root || ! -d $root ]]; then + skill_fail "skills root is not a real directory: $root" + fi + shopt -s nullglob + for path in "$root"/*/; do + name=$(basename "${path%/}") + if [[ -L $root/$name ]]; then + skill_fail "skill directory is a symlink: $root/$name" + fi + if [[ ! -f $root/$name/SKILL.md || -L $root/$name/SKILL.md ]]; then + skill_fail "skill is missing a regular SKILL.md: $root/$name" + fi + names+=("$name") + done + shopt -u nullglob + if [[ ${#names[@]} -eq 0 ]]; then + skill_fail "no skills in $root" + fi + printf '%s\n' "${names[@]}" | sort +} + +skill_file_mode() { + if stat -c %a "$1" >/dev/null 2>&1; then + stat -c %a "$1" + else + stat -f %OLp "$1" + fi +} + +# Directories are 755. A file keeps the executable bit and is otherwise 644. +# Nix store paths drop the owner-write bit (755 -> 555, 644 -> 444); the +# installed tree has to stay writable or the next run cannot repair it. +skill_dest_mode() { + local path=$1 + local mode + if [[ -d $path && ! -L $path ]]; then + printf '755\n' + return + fi + mode=$(skill_file_mode "$path") + if [[ $((8#$mode & 0111)) -ne 0 ]]; then + printf '755\n' + else + printf '644\n' + fi +} + +skill_mode_ok() { + [[ $(skill_file_mode "$2") == "$(skill_dest_mode "$1")" ]] +} + +skill_apply_mode() { + chmod "$(skill_dest_mode "$1")" "$2" +} + +# Nix drops the owner-write bit, so 755 and 555 are the same executable file. +skill_is_exec() { + local mode + mode=$(skill_file_mode "$1") + [[ $((8#$mode & 0111)) -ne 0 ]] +} + +skill_exec_ok() { + local src_exec=1 dest_exec=1 + if [[ -d $1 && ! -L $1 ]]; then + return 0 + fi + skill_is_exec "$1" || src_exec=0 + skill_is_exec "$2" || dest_exec=0 + [[ $src_exec -eq $dest_exec ]] +} + +skill_assert_source_file() { + local path=$1 + if [[ -L $path ]]; then + skill_fail "source symlink: $path" + fi + if [[ -d $path || -f $path ]]; then + return 0 + fi + skill_fail "unsupported source file: $path" +} + +# mode is apply or check. apply rewrites dest until it matches src. +# keep_mode=1 leaves an existing directory or file mode alone. A file that +# already exists keeps that mode after a byte rewrite. New paths still get +# the normalized mode. +skill_sync_tree() { + local src=$1 dest=$2 mode=$3 keep_mode=${4:-0} + local rel parent tmp preserved dest_ready nested_ready + if [[ $mode != apply && $mode != check ]]; then + skill_fail "unknown sync mode: $mode" + fi + skill_assert_source_file "$src" + if [[ ! -d $src ]]; then + skill_fail "source skill is not a directory: $src" + fi + + dest_ready=0 + if [[ -d $dest && ! -L $dest ]]; then + dest_ready=1 + fi + if [[ -L $dest ]]; then + if [[ $mode == check ]]; then + skill_fail "symlink: $dest" + fi + rm -f -- "$dest" + elif [[ -e $dest && ! -d $dest ]]; then + if [[ $mode == check ]]; then + skill_fail "not a directory: $dest" + fi + rm -f -- "$dest" + fi + if [[ ! -d $dest ]]; then + if [[ $mode == check ]]; then + skill_fail "missing directory: $dest" + fi + mkdir -p -- "$dest" + fi + if [[ $mode == apply && ( $keep_mode == 0 || $dest_ready == 0 ) ]] && ! skill_mode_ok "$src" "$dest"; then + skill_apply_mode "$src" "$dest" + fi + + while IFS= read -r -d '' rel; do + rel=${rel#./} + skill_assert_source_file "$src/$rel" + if [[ -d $src/$rel ]]; then + nested_ready=0 + if [[ -d $dest/$rel && ! -L $dest/$rel ]]; then + nested_ready=1 + fi + if [[ -L $dest/$rel ]]; then + if [[ $mode == check ]]; then + skill_fail "symlink: $dest/$rel" + fi + rm -f -- "$dest/$rel" + elif [[ -e $dest/$rel && ! -d $dest/$rel ]]; then + if [[ $mode == check ]]; then + skill_fail "not a directory: $dest/$rel" + fi + rm -f -- "$dest/$rel" + fi + if [[ ! -d $dest/$rel ]]; then + if [[ $mode == check ]]; then + skill_fail "missing directory: $dest/$rel" + fi + mkdir -p -- "$dest/$rel" + fi + if [[ $mode == apply && ( $keep_mode == 0 || $nested_ready == 0 ) ]] && ! skill_mode_ok "$src/$rel" "$dest/$rel"; then + skill_apply_mode "$src/$rel" "$dest/$rel" + fi + else + if [[ -L $dest/$rel ]]; then + if [[ $mode == check ]]; then + skill_fail "symlink: $dest/$rel" + fi + elif [[ ! -f $dest/$rel ]]; then + if [[ $mode == check ]]; then + skill_fail "missing file: $dest/$rel" + fi + elif ! cmp -s -- "$src/$rel" "$dest/$rel"; then + if [[ $mode == check ]]; then + skill_fail "byte drift: $dest/$rel" + fi + elif [[ $keep_mode == 0 ]] && ! skill_exec_ok "$src/$rel" "$dest/$rel"; then + if [[ $mode == check ]]; then + skill_fail "mode drift: $dest/$rel" + fi + skill_apply_mode "$src/$rel" "$dest/$rel" + continue + elif [[ $mode == apply && $keep_mode == 0 ]] && ! skill_mode_ok "$src/$rel" "$dest/$rel"; then + skill_apply_mode "$src/$rel" "$dest/$rel" + continue + else + continue + fi + preserved="" + if [[ $keep_mode == 1 && -f $dest/$rel && ! -L $dest/$rel ]]; then + preserved=$(skill_file_mode "$dest/$rel") + fi + parent=$(dirname -- "$dest/$rel") + mkdir -p -- "$parent" + rm -f -- "$dest/$rel" + tmp=$(mktemp "$parent/.bezel-skill.XXXXXX") + cat -- "$src/$rel" >"$tmp" + mv -f -- "$tmp" "$dest/$rel" + if [[ -n $preserved ]]; then + chmod "$preserved" "$dest/$rel" + else + skill_apply_mode "$src/$rel" "$dest/$rel" + fi + fi + done < <(cd -- "$src" && find . -mindepth 1 -print0) + + local -a extras=() + while IFS= read -r -d '' rel; do + rel=${rel#./} + if [[ ! -e $src/$rel && ! -L $src/$rel ]]; then + extras+=("$dest/$rel") + fi + done < <(cd -- "$dest" && find . -depth -mindepth 1 -print0) + if [[ ${#extras[@]} -gt 0 ]]; then + if [[ $mode == check ]]; then + skill_fail "extra path: ${extras[0]}" + fi + for rel in "${extras[@]}"; do + [[ -e $rel || -L $rel ]] && rm -rf -- "$rel" + done + fi +} + +# A skills root that must contain exactly the canonical skill directories. +skill_sync_root() { + local src=$1 dest=$2 mode=$3 + local name + local -a names=() + mapfile -t names < <(skill_dir_names "$src") + if [[ -L $dest ]]; then + if [[ $mode == check ]]; then + skill_fail "skills directory is a symlink: $dest" + fi + rm -f -- "$dest" + elif [[ -e $dest && ! -d $dest ]]; then + if [[ $mode == check ]]; then + skill_fail "skills path is not a directory: $dest" + fi + rm -f -- "$dest" + fi + if [[ ! -d $dest ]]; then + if [[ $mode == check ]]; then + skill_fail "missing skills directory: $dest" + fi + mkdir -p -- "$dest" + fi + for name in "${names[@]}"; do + skill_sync_tree "$src/$name" "$dest/$name" "$mode" + done + local base found have + while IFS= read -r -d '' base; do + base=$(basename -- "$base") + found=0 + for have in "${names[@]}"; do + if [[ $have == "$base" ]]; then + found=1 + break + fi + done + if [[ $found -eq 0 ]]; then + if [[ $mode == check ]]; then + skill_fail "extra path: $dest/$base" + fi + rm -rf -- "$dest/$base" + fi + done < <(find "$dest" -mindepth 1 -maxdepth 1 -print0) +} + +# User install: write each canonical skill, and leave unrelated skill names in place. +skill_sync_user_root() { + local src=$1 dest=$2 mode=$3 + local name + local -a names=() + mapfile -t names < <(skill_dir_names "$src") + if [[ -L $dest ]]; then + if [[ $mode == check ]]; then + skill_fail "skills directory is a symlink: $dest" + fi + rm -f -- "$dest" + elif [[ -e $dest && ! -d $dest ]]; then + if [[ $mode == check ]]; then + skill_fail "skills path is not a directory: $dest" + fi + rm -f -- "$dest" + fi + if [[ ! -d $dest ]]; then + if [[ $mode == check ]]; then + skill_fail "missing skills directory: $dest" + fi + mkdir -p -- "$dest" + fi + for name in "${names[@]}"; do + skill_sync_tree "$src/$name" "$dest/$name" "$mode" 1 + done +} + +# User install must not overwrite a regular file whose bytes differ, or replace +# a symlink, unless the caller passes --force. Prints every conflict. +# Returns 1 when any exist. A missing file is not a conflict. +skill_user_conflicts() { + local src=$1 dest=$2 + local name rel path status=0 + local -a names=() + if [[ ! -e $dest || -L $dest || ! -d $dest ]]; then + return 0 + fi + mapfile -t names < <(skill_dir_names "$src") + for name in "${names[@]}"; do + if [[ ! -d $dest/$name || -L $dest/$name ]]; then + continue + fi + while IFS= read -r -d '' rel; do + rel=${rel#./} + [[ -f $src/$name/$rel && ! -L $src/$name/$rel ]] || continue + path=$dest/$name/$rel + if [[ -L $path ]]; then + printf 'install-user-skills: symlink: %s\n' "$path" >&2 + status=1 + elif [[ -f $path ]]; then + if ! cmp -s -- "$src/$name/$rel" "$path"; then + printf 'install-user-skills: byte drift: %s\n' "$path" >&2 + status=1 + fi + elif [[ -e $path ]]; then + printf 'install-user-skills: not a regular file: %s\n' "$path" >&2 + status=1 + fi + done < <(cd -- "$src/$name" && find . -mindepth 1 -type f -print0) + done + return "$status" +} diff --git a/scripts/sync-skills b/scripts/sync-skills new file mode 100755 index 0000000..388c25b --- /dev/null +++ b/scripts/sync-skills @@ -0,0 +1,21 @@ +#!/usr/bin/env bash +# Rewrite .claude/skills, .grok/skills, and .cursor/skills from .agents/skills. +# Copies are regular files. The canonical tree is the only one to edit. + +set -euo pipefail + +script_dir=$(CDPATH= cd -- "$(dirname "$0")" && pwd) +root=$(CDPATH= cd -- "$script_dir/.." && pwd) +# shellcheck source=skill-mirror.sh +source "$script_dir/skill-mirror.sh" + +canonical=$root/.agents/skills +harnesses=( + "$root/.claude/skills" + "$root/.grok/skills" + "$root/.cursor/skills" +) + +for dest in "${harnesses[@]}"; do + skill_sync_root "$canonical" "$dest" apply +done diff --git a/skills-stub/bootstrap/SKILL.md b/skills-stub/bootstrap/SKILL.md deleted file mode 100644 index 92f57a7..0000000 --- a/skills-stub/bootstrap/SKILL.md +++ /dev/null @@ -1,12 +0,0 @@ ---- -name: bootstrap -description: Placeholder skill shipped with the Bezel skills-stub until a skills repository is published. Replace the flake skills input; do not copy a second skills tree into this repo. ---- - -# bootstrap - -This skill exists so the skills flake input is a valid skills directory -(`*/SKILL.md`) until you point the flake skills input at a skills repository. - -Home Manager installs the input at `~/.config/omp/agent/skills`, the directory -the wrapped harness loads.