Skip to content

Latest commit

 

History

History
429 lines (373 loc) · 24.8 KB

AGENTS.md

File metadata and controls

429 lines (373 loc) · 24.8 KB

smart_ssh — AGENTS.md

Cross-platform SSH client (Tauri 2 + Rust core + React frontend) with an AI copilot that suggests commands, which run through a policy/filter engine before anything touches a real server. The project's core promise is full transparency and control over every command that reaches a server — the AI is a copilot, never an autonomous actor. Code quality rules here exist to protect that promise, not as bureaucracy.

This file holds the project facts and conventions that apply to every contributor and every coding agent. Issues and this file define the work. The agent and skill definitions under .claude/ are optional helpers for interactive Claude Code sessions; on conflict, this file and the issue win.

Product principles

Use these to decide edge cases an issue leaves open:

  • Core promise: full transparency and control over every command that reaches a server. The AI is a copilot, never an autonomous actor.
  • Safety before convenience — but no patronising of manual actions (the file browser and the terminal are trusted user actions).
  • Honest notices instead of playing things down.
  • When a command is refused by a permission (e.g. rm), offer it to the user to run themselves; never work around the refusal.

Before every commit

Run the full gate and make sure it's green — this mirrors CI (.github/workflows/community.yml). The test job (matrix: Ubuntu, Windows, macOS) runs cargo fmt --check/clippy/test/build plus, in the frontend, npm run lint, npm test, and npm run build (Spec 0090, A5) — a lint or test failure there fails the job. The separate dependency-audit job (ubuntu-latest only) runs cargo deny check licenses sources bans and cargo audit as blocking steps (Spec 0090, A2): a license/origin/ban violation or a non-exempted vulnerability fails the job; unmaintained/ unsound advisories and yanked crates stay visible warnings. A third step there checks that every exemption in .cargo/audit.toml still matches a current finding (Spec 0090, A4) — a stale exemption (e.g. for a withdrawn advisory) fails the job too.

scripts/gate.sh                  # all stages, in order
scripts/gate.sh rust             # fmt --check, clippy, test, build
scripts/gate.sh boundary         # app-logic stays free of Tauri (Spec 0084, A3)
scripts/gate.sh frontend         # tsc -b, npm run lint, vitest, npm run build
scripts/gate.sh --ci rust        # as CI: cargo-nextest (profile ci), clipboard test required, under xvfb-run on Linux

CI runs the Rust tests with cargo nextest run --profile ci (retries, JUnit report, a step that fails the job on tests that pass only on retry, Spec 0090 A9) plus cargo test --doc; locally scripts/gate.sh uses nextest if installed and otherwise falls back to cargo test, and developers may keep using cargo test.

scripts/gate.sh is the single definition of the gate; CI calls it too (Windows keeps its Cargo steps inline with the same commands, see the comment in .github/workflows/community.yml). Every Cargo build/test/clippy/tree call uses --locked, so the checked-in Cargo.lock is what gets tested and a stale lockfile fails instead of being re-resolved silently (guarded by src/cargoLockedCheck.test.ts).

The rust stage's last step builds without the test-support feature, which cargo test/clippy --all-targets both enable — it is the only one of the four that catches a production-code call into a test-only access point (e.g. parts_mut_for_tests, gated on cfg(any(test, feature = "test-support"))), since that call compiles fine as long as test-support is on.

Browser tests (issue #166, ADR 0120) run the real frontend in Chromium and WebKit, at 1280×800 and 800×560, against a fake backend that replaces the Tauri IPC layer (e2e/harness/). Unknown commands fail the test, so a new screen or command needs a handler in e2e/harness/fakeBackend.ts or a per-test override. Layout checks (inside the viewport, not covered, reachable by Tab, only the content scrolls) live in e2e/support/layout.ts; known axe findings are listed with a reason in e2e/support/axe.ts. CI runs the suite in the separate browser-tests job (ubuntu-24.04 only, pinned for Playwright's WebKit); on failure it uploads traces and the HTML report as the playwright-traces artifact.

cd apps/smart-ssh-community/frontend
npx playwright install chromium webkit   # once, downloads the browsers
npm run test:e2e      # whole suite, headless
npm run test:e2e:ui   # Playwright UI mode, for local debugging

npm run lint first runs npm run check-commands: it fails when a #[tauri::command] is not in generate_handler!, a generate_handler! entry has no definition, a non-test frontend file invokes an unregistered name, or a name in the startup gate's allow list is not registered (issue #101). Then npm run check-events (scripts/check-event-names.mjs, issue #918) fails when the event name constants in crates/app-logic/src/event_names.rs and src/api/eventNames.ts drift apart or a listen(/once( call uses a string literal. Then it runs npm run check-a11y-rules (scripts/check-a11y-lint-rules.mjs, issue #146): it fails when a jsx-a11y rule that the installed oxlint enables is not listed with error in .oxlintrc.json (Spec 0100 A6.1, ADR 0116) — after an oxlint upgrade that adds a rule, add it there. Finally npm run check-conventions (scripts/check-conventions.mjs, issue #858) fails on a new *_tests.rs file (see "Testing conventions"), on a stale entry in its list of the existing ones, and on LOCAL_SERVER_ID / local_server anywhere under crates/core/src/filter/ or crates/core/src/risk/ (see "No special-casing the local pseudo-server"). npm run check-doc-paths (scripts/check-doc-paths.mjs, issue #874) fails on a backticked path or a quoted section reference in these guidance documents that does not exist; intentional non-paths go into scripts/doc-paths-allowlist.json with a reason. CI runs all of them through the same npm run lint step.

npm run lint also runs npm run check-file-size (scripts/check-file-size.mjs, issue #841): tracked *.rs, *.ts, *.tsx, *.mjs and *.kt files may have at most 1,200 lines (test files: 2,000). Files above their limit are listed in scripts/file-size-allowlist.json with their maximum size; such a file may not grow past its entry, and an entry for a file that is now within the limit or deleted fails as stale. node scripts/check-file-size.mjs --update lowers or removes entries (never raises or adds). On pull requests CI also compares with the base branch (--base), so entries can only go down: split the file instead of raising an entry.

Order matters: cargo fmt --all --check runs before clippy/test in CI — if formatting is off, clippy and test never even execute, so a red CI run that only shows a fmt failure tells you nothing about whether the actual code is correct. Run cargo fmt --all locally before committing, not just --check.

For UI-affecting changes, also start the dev app and click through the golden path once — type-checking and unit tests verify code correctness, not feature correctness. On macOS use ./scripts/tauri-dev.sh, not plain cargo tauri dev (a code-signing/keychain quirk, see docs/adr/0022-stable-dev-code-signature.md). Don't relaunch it repeatedly while iterating — build/test/lint don't need a running window; start it once, when a change is actually ready to look at.

Toolchain

The Rust version comes from rust-toolchain.toml (exact x.y.z); CI reads the channel from that file, and [workspace.package] rust-version carries the same minor. A bump is its own pull request that also fixes any new clippy findings. Projects embedding the core can reuse the same file.

Git staging — never blanket-add

Never git add -A or git add .. Several files are deliberately untracked (local .claude/ caches, signing credentials outside the repo, in-progress work), and a blanket add has already once swept untracked files into a commit whose message claimed otherwise. Always stage the exact paths that belong in the commit, and run git status before committing to confirm nothing unintended is staged (no secrets, no local caches, no unrelated in-progress edits).

Architecture rules

crates/
├── core/               # pure logic — NO Tauri, NO UI framework dependency
│   ├── ssh/              # connection handling, trait-based
│   ├── filter/            # policy/filter engine (security-critical)
│   ├── risk/               # command risk classification
│   ├── ai/                  # AI provider abstraction + output redaction
│   ├── profiles/              # server/group/credential domain types
│   └── entitlements.rs         # `Feature` enum and `EntitlementProvider` trait
├── ssh-transport/       # concrete SshTransport impl (russh + local pseudo-server)
├── persistence-sqlite/  # concrete ProfileStore/PolicyStore impl
├── credentials-keyring/ # concrete CredentialStore impl (OS keychain)
├── ai-providers/        # concrete AiProvider impls (Anthropic, OpenAI-compatible, ...)
├── mcp-server/           # MCP server exposing sessions to external clients
├── speech/               # speech-to-text
├── app-logic/            # Tauri-free application logic: chat-turn orchestration,
│                         # compaction, confirmation registry, connection test,
│                         # server/group/credential management, DTOs, AppState
│                         # (Spec 0084; see docs/architecture.md for the app-logic/
│                         # app-shell boundary and its one deliberate exception)
├── app-shell/            # Tauri layer: commands, events, wiring (`Wiring`, Spec 0038);
│                         # depends on `app-logic` and directly on the adapter crates
└── real-app-tests/       # starts the real app in CI
apps/
└── smart-ssh-community/  # thin binary: app_shell::run(Wiring::community())
    └── frontend/           # React, talks only to app-shell via invoke()

Extension points:

  • app_shell::Wiring — crates/app-shell/src/wiring.rs
  • Frontend extension registry — apps/smart-ssh-community/frontend/src/extensions/registry.ts
  • Namespaced extension tables — extension_db in crates/persistence-sqlite (crates/persistence-sqlite/src/extension_db.rs)

core never depends on Tauri or a UI framework. All domain logic belongs there; app-shell only translates between Tauri commands/events and core APIs. This is what lets a future TUI reuse the same logic without duplication — don't put business logic in app-shell because it was faster to reach AppHandle/State from there.

Every external boundary is a trait, defined before its concrete implementation. SshTransport, SftpSession, InteractiveShell, AiProvider, PolicyStore, ProfileStore, CredentialStore — each has an in-memory/mock implementation used in tests, so core's logic (above all the filter engine) is fully testable without a real SSH connection or API call. When adding a new external dependency, add the trait first.

No special-casing the local pseudo-server (or any other server) in the core loop. The local pseudo-server (ssh-transport::LocalTransport, app_shell::local_server) exists specifically to prove this: it implements the same traits as a real server, so the filter engine, risk classifier, and confirmation flow apply to it identically, with zero branching on server identity anywhere in that path. If you find yourself writing if server_id == LOCAL_SERVER_ID inside filter/risk/confirmation code, that's a sign something is architecturally wrong — the special casing belongs at the transport/session-construction boundary, never inside the security logic itself.

Where to look

  • docs/codemap.md — read this first when you look for the file, symbol or extension point for a change (checked by npm run check-codemap).
  • docs/recipes/README.md — read this before a change that always touches the same files (new Tauri command, new UI text, new database migration).
  • docs/architecture.md — read this when you need the crate boundaries, in particular app-logic vs. app-shell.
  • THREAT-MODEL.md — read this when a change touches what the AI sees, redaction, where data lives, network connections or trust boundaries.
  • .claude/skills/smart-ssh-coder/references/security-invariants.md — read this before changing anything security-critical.
  • docs/ui-guidelines.md — read this when you build or change UI.
  • docs/i18n-glossary.md — read this when you add or change translated texts.
  • docs/glossary.md — read this when you meet a project or domain term (Wiring, fencing, ledger, …) you do not know.
  • docs/datenpfade.md — read this when you need to know where the app stores data on disk.
  • docs/netzwerkverbindungen.md — read this when you add or change an outgoing network connection.
  • docs/android-build.md — read this when you build for or debug on Android.
  • docs/dev-environment.md — read this when you set up a development environment.
  • README_DEV.md — read this for developer-facing build and run instructions.
  • docs/specs/INDEX.md — read this to find the spec for an area (generated, node scripts/check-spec-index.mjs --write-index).
  • docs/specs/README.md — read this when you change user-visible behaviour or write a spec.
  • docs/adr/README.md — read this when you make or look up an architecture decision.
  • changelog.d/README.md — read this when you add a changelog fragment.

Security-critical modules — extra care

crates/core/src/filter/ (policy engine), crates/core/src/risk/ (risk classifier), crates/core/src/ai/ output redaction, and credential handling (credentials-keyring, crates/core/src/profiles/credentials.rs) are the modules standing between an AI suggestion and something irreversible happening on a real server. For changes here:

  • Never loosen an existing check to make a test pass or a feature work — find out why the check exists (usually a numbered spec test case, see crates/core/src/filter/tests.rs's test_t*/named cases) before touching it.

  • Escalation only goes one direction: a rule-based Deny/risk-Red must never be downgraded by an AI opinion or a new code path (see docs/adr/0024-risk-indicator-second-opinion-design.md for the pattern: "only escalation, never softening").

  • Add adversarial test cases, not just happy-path ones — evasion via command chaining, substitution, encoding, or a sufficiently long input are the standard categories already covered in crates/core/src/filter/tests.rs; extend from there rather than starting over.

  • Redaction (crates/core/src/ai/) must run before content is persisted or sent anywhere — verify with a test that plants a redaction-worthy secret and asserts it never appears in plaintext in the output/DB.

  • Types that carry plaintext secrets (input DTOs with keys, passwords, passphrases, tokens) have a redacting Debug that prints [REDACTED], never a derived one — add a test that plants a secret and checks the {:?} output.

  • Keep THREAT-MODEL.md current. A pull request that changes the filter engine, risk classifier, redaction or fencing, credential handling, the command execution/confirmation path, a network boundary (new outgoing connection, listener, MCP), an IPC command with side effects, a stored secret, an external process, or a trust boundary updates THREAT-MODEL.md in the same pull request. This applies to crates/core/src/filter/, crates/core/src/risk/, crates/core/src/ai/, crates/core/src/profiles/credentials.rs, crates/credentials-keyring/, crates/app-logic/src/orchestration/, crates/mcp-server/, crates/ssh-transport/ and crates/app-shell/src/elevated_sftp.rs. If it does not need to change, the pull request description says Threat model: no change – <reason>. CI enforces this (job threat-model-note, scripts/check-threat-model-note.mjs); the authoritative list of security-critical path prefixes is .github/security-paths.txt (test-only changes do not count).

Spec workflow

A spec describes behaviour. Each numbered spec in docs/specs/ (NNNN-slug.md) describes what a user sees and can do in one area of the product: rules, edge cases, error behaviour, security guarantees. It does not reference code locations, function names or file paths, and it is not a task list. Rationale for implementation choices belongs in an ADR, not in the spec. Before changing an area, read its spec and at least the specs it explicitly references.

Every change has a spec impact — one of:

  • new — behaviour in an area no spec covers yet; the new spec takes the next free number in docs/specs/.
  • update NNNN — behaviour of an existing spec changes or is added. Preferred over a new spec whenever an existing one covers the area.
  • none — a fix of already specified behaviour, refactoring, tests, CI.

The issue forms carry an optional "Spec impact" field for this. If a change alters visible behaviour that no spec describes, or that a spec describes differently, the spec change belongs to it even if the issue said none.

The spec change ships in the same pull request as the code and is reviewed with it. After merge, the spec describes the state of main, not a plan.

A bug fix touches a spec only when the spec was wrong or incomplete, and then only the affected statement.

ADRs. docs/adr/ holds architecture decisions that cut across a single spec, or non-obvious implementation choices (numbered independently, see docs/adr/README.md); write one whenever you make a call the spec or issue left open, especially a scope reduction (e.g. "X works but without history/feature Y, because Z") — say so explicitly rather than silently narrowing what was asked for. An ADR ships in the same pull request as the change it documents.

Versioning & changelog (Spec 0048)

This repo is the single source of truth for the product version — the places Tauri and the build actually read it: apps/smart-ssh-community/ tauri.conf.json (version), the workspace Cargo.toml ([workspace.package].version, inherited by every crate via version.workspace = true), the internal path-dependency version pins in the root Cargo.toml [workspace.dependencies] entries for the internal crates (e.g. ssh-manager-core = { version = "0.7.0", path = "crates/core" } — these must match the workspace version or the workspace fails to build, since Cargo's default caret requirement on a 0.x version only matches that patch range), and the frontend package.json/package-lock.json (bump both together via npm version X.Y.Z --no-git-tag-version from apps/smart-ssh-community/frontend/, not by hand-editing, so the lockfile stays consistent).

  • The version is bumped deliberately, never automatically by the coder and never per-feature. SemVer: a feature bump is minor, a fix bump is patch.
  • At a bump: change the version everywhere it's pinned (see above), move CHANGELOG.md's [Unreleased] section to [X.Y.Z] — <date>, merge all fragments from changelog.d/ into that new version section and delete the fragment files, write a ### Highlights section as the first heading of the new version section (required: 3–6 bullet items, exactly one line each, user-facing, no internals; it feeds the download page and release notes; [Unreleased] has none), open a fresh empty [Unreleased] above it, tag the release.
  • Release notes file at a bump: also write release-notes/X.Y.Z.json with the Highlights in English, German, French and Spanish (format in Spec 0048 §2; en identical to the changelog Highlights). scripts/check-release-notes.mjs (run by npm run lint) enforces it for every version after 0.5.2.
  • The changelog and the fragments are written in English.
  • Fragment rules (details in changelog.d/README.md): at most two lines per item; describe the user-visible effect, not the mechanism; nothing internal. scripts/check-changelog-highlights.mjs (run by npm run lint) fails a released section after 0.5.2 without valid Highlights.
  • CHANGELOG.md (repo root, Keep a Changelog format) holds user-relevant changes only — internal refactors, tests, CI and documentation-only changes stay out of it (that's what git history is for).
  • Normal work never edits CHANGELOG.md directly. Every user-relevant change (new or changed behaviour, fix, security) adds one fragment in changelog.d/ in the same pull request, whatever its spec impact — a bug fix with spec impact none gets one too. Naming, language, categories and the **(Pro)** marking for paid-edition-only entries are defined in changelog.d/README.md.

Testing conventions

  • Rust: small test modules stay inline (#[cfg(test)] mod tests { … }). Larger ones go in <module>/tests.rs or <module>/tests_<topic>.rs next to <module>.rs, declared with #[cfg(test)] mod tests;. Cross-crate or real-connection tests live in the crate's tests/ directory (crates/ssh-transport/tests/integration.rs is the one place real test-fixture SSH connections are exercised). Shared helpers live in test_support.rs behind cfg(any(test, feature = "test-support")). Tests use trait mocks (MockAiProvider in crates/core/src/ai/tests.rs, the in-memory ProfileStore/CredentialStore in crates/app-logic/src/test_support.rs) — no real network/SSH/keychain access in unit tests. No new *_tests.rs files: seven exist (listed in scripts/check-conventions.mjs) and stay until they are touched anyway; when one is renamed or removed, drop it from that list. Note that crates/app-logic/src/test_connection.rs is production code (the "test connection" feature), not a test file.
  • Frontend: pure logic (lib/groupTree.ts, lib/remotePath.ts, api/errorCodes.ts, …) gets its own *.test.ts via Vitest; component tests exist for the trickier interactive pieces, not for every component. Async frontend tests follow ADR 0122 R6–R15 (docs/adr/0122-plattform-und-zeitunabhaengige-tests.md): wait for the final DOM state, re-query after transitions, send events in act.
  • When a bug is fixed, add the regression test that would have caught it, not just the fix — see crates/app-logic/src/dto/tests.rs's rename_all_fields regression tests for the pattern.
  • Prove a regression test is real: it must fail against the un-fixed code. Before accepting a regression test as green, verify it actually catches the bug — revert the fix locally (or run the test against the pre-fix state) and confirm the test fails, then restore the fix. A test that passes both before and after the fix tests nothing; this is the single most effective guard against the tautological tests that a past audit found across the codebase.

Workspace dependencies

A third-party crate used by two or more workspace crates is pinned once in the root Cargo.toml under [workspace.dependencies]; crates inherit it with name = { workspace = true } and add only their own features/optional. default-features = false belongs in the workspace entry. New shared dependencies go there too. scripts/check-workspace-deps.mjs (run by npm run lint) fails on a crate that pins its own version of such a dependency. Remaining duplicate versions in the lockfile come from upstream crates and are listed with a reason under [bans] skip in deny.toml (multiple-versions stays warn); add an entry there when an upstream update introduces a new one.

Code comments

Comments in new code are written in English; existing German comments stay as they are (translate only when the surrounding function is substantially rewritten, never in bulk). Spec references (Spec NNNN, A<n>) stay as they are. See docs/adr/0152-code-comment-language.md.

Locks and poisoning

Production code locks std::sync primitives (Mutex, RwLock) only through ssh_manager_core::sync::{lock,read,write}_tolerating_poison — never lock().unwrap(), lock().expect(..) or the read/write equivalents. Where a poisoned value could be half-updated and continuing would be wrong, the call site resets the value to a safe default after recovering and says so in a comment; it never panics, and never skips a revocation or turns a pending decision into an approval (Spec 0088, A5). A guard test (crates/core/tests/lock_poison_guard.rs) enforces it; tests may keep unwrap. tokio::sync locks are not poisoned and are out of scope.

Commits

Conventional Commits, scoped to the crate/area, referencing the spec if any: feat(app-shell): add X per spec 0032, fix(ci): ..., docs(adr): propose design decisions for X (spec 0032). Keep the ADR as a separate commit after the feature commit it documents. Commit on your own once a step is done; run the full gate above first. Stage exact paths, never git add -A (see "Git staging" above).