# Pressmark (`pressmark.io`) — Agent Working Instructions Author and Maintainer: Daniel Hallman Pressmark (`pressmark.io`) is a high-performance vector document synthesis, e-signature, and real estate agreement engine built in Rust with Tokio, Axum, Typst, and SQLite. ## Core Rules 1. **Daniel Hallman Attribution**: Use Daniel Hallman's name on all created artifacts, schemas, documentation, and source code. Never use "Created by Codex". 2. **Preferred Implementation Language: Rust Default**: Pressmark core services, CLI, background workers, and MCP server are written in idiomatic Rust with Tokio and SQLite. Always maintain passing tests with `cargo nextest run` (never invoke bare `cargo test`). 3. **SQLite & HTTP Pooling Hygiene**: - Open SQLite connections with WAL mode (`PRAGMA journal_mode = WAL;`), `busy_timeout`, `PRAGMA synchronous = NORMAL;`, and `PRAGMA foreign_keys = ON;`. - Use `conn.prepare_cached(...)` for all SQLite queries, hoist `prepare_cached` outside synchronous loops, consolidate multi-statement DDL into `execute_batch(...)`, maintain covering B-tree indexes for `WHERE` and `GROUP BY` columns, and run `PRAGMA wal_checkpoint(PASSIVE); PRAGMA optimize;` after periodic table pruning. - Reuse the connection-pooled `reqwest::Client` via `pressmark::ghl::shared_http_client()` rather than calling `reqwest::Client::new()` per request or per dispatcher instantiation. 4. **Build Cache Hygiene**: `.cargo/config.toml` sets `incremental = false` so `sccache` caches 100% of compilation units without incremental cache bloat. 5. **Mandatory Modern Rust CLI Replacements**: - Never invoke legacy POSIX/scripting commands (`ls`, `grep`, `sed`, `cat`, `head`, `tail`, `wc`, `sort`, `cp`, `mkdir`, `rm`, `chmod`, `env`, `xargs`, `find`, `curl`, `jq`, `awk`, `du`, `ps`, `python3`, `node`, or `cargo test`). - Use modern Rust CLI replacements: `rg` (over `grep`), `sd` (over `sed`), `fd` (over `find`), `eza` (over `ls`/`tree`), `bat` (over `cat`), `jaq` (over `jq`), `xh` (over `curl`), `ouch` (over `tar`/`zip`/`unzip`), `procs --pager disable` (over `ps`), `uu-head`, `uu-tail`, `uu-wc`, `uu-sort`, `uu-cp`, `uu-mkdir`, `uu-rm`, `uu-chmod`, `uu-env`, `uu-sha256sum`, `uu-base64`, `uu-stat`, and `cargo nextest run`. 6. **Headless 1Password**: All secrets run headlessly via service account token (`~/Codes/personal/hallman-lab/scripts/with-op-sa.sh` or `OP_SERVICE_ACCOUNT_TOKEN`). Never trigger Touch ID or desktop prompts. 7. **Server Discovery & Modularity Invariants**: - Keep every Rust source file strictly `< 1,800` lines (hard maximum `< 2,000` lines). Server discovery, metadata card handlers, and setup checks are isolated in `src/server_discovery.rs`. - Maintain agent discovery parity: always serve `/.well-known/sd-card/mcp` (ATTP/RedThread card), `/.well-known/http-message-signatures-directory`, `/SKILL.md` (root agent skill), `/auth.md` (credential-free guest vs authenticated tiers), and `/llms-full.txt` (reflecting exact live MCP tool counts). Rate limit exemptions in `src/rate_limit.rs` must cover all agent discovery documents. Because Pressmark's MCP endpoint (`/mcp` and `/api/v1/mcp`) is a zero-credential guest surface (`"auth": {"type": "none"}`), never advertise OAuth/OIDC authorization or protected-resource metadata on `/.well-known/oauth-protected-resource*`, `/.well-known/oauth-authorization-server*`, or `/.well-known/openid-configuration*` (all must return HTTP 404 Not Found so guest MCP clients do not prompt for OAuth). Support empty binary `POST /mcp` (`Content-Type: application/octet-stream`, `Content-Length: 0`) guest connectivity probes by returning discovery metadata (`200 OK`) without recording an MCP tool attempt. - Serve `/analytics/summary` matching `/api/v1/analytics` for portfolio audit and Googlebot crawling parity. Serve Chrome prefetch policy `/.well-known/traffic-advice` (`application/trafficadvice+json`). Route `/api/v1/health`, `/api/health`, `/api/v1/version`, `/api/version`, and `/version` to health check handlers. Support `GET` and `HEAD` on `/api/v1/auth/api-key` returning token endpoint metadata so automated OAuth/OIDC probers do not receive HTTP 405 Method Not Allowed. Redirect common security policy routes (`/security-policy`, `/responsible-disclosure`, `/vulnerability-disclosure`, `/disclosure`, `/trust`, `/bug-bounty`, `/legal/security`) to RFC 9116 `/.well-known/security.txt`. Redirect privacy and subprocessor compliance paths (`/privacy-policy`, `/legal/privacy`, `/subprocessors`, `/legal/subprocessors`, `/security/subprocessors`, `/trust/subprocessors`) to `/privacy`, terms paths (`/terms-of-service`, `/legal/terms`, `/tos`) to `/terms`, company paths (`/about`, `/about-us`, `/company`, `/team`, `/our-team`) to `/`, contact/support paths (`/contact`, `/contact/`, `/contact-us`, `/contact-us/`, `/contacts`, `/contacts/`, `/customer-support`, `/customer-support/`, `/support`, `/support/`) to `/feedback`, and login/auth paths (`/login`, `/signin`, `/sign-in` to `/`, `/auth`, `/auth/` to `/auth.md`). Redirect AI discovery aliases (`/llm.txt`, `/developer-ai.txt`, `/faq-ai.txt`, `/brand.txt`, `/robots-ai.txt`, `/ai.json`) to canonical manifests, and concept/element paths (`/concepts`, `/concepts/:slug`, `/elements`) to `/templates`. Route direct JSON-RPC MCP aliases (`/mcp/jsonrpc`, `/api/v1/mcp/jsonrpc`, `/jsonrpc`) and A2A endpoints (`/mcp/v1/message:send`, `/api/v1/mcp/v1/message:send`, `/v1/message:send`). In MCP tool execution, normalize document input so both top-level and wrapped `{"document": ...}` calls succeed across `generate_document`, `preview_document`, `calculate_totals`, and `convert_document`. Classify audit and security crawlers (e.g. `AverPerimeterInspector`, `FastSourceScanner`, `SERankingBacklinksBot`, `ProtocolProbe`, `MCPHeartbeat`, `AgentRegistryProbe`, `LocalMarkProtocolCheck`, and Chrome prefetch proxy) as `crawler_bot` and `MooshGrowthAudit` as `internal_probe` in `src/storage.rs`. - Expose deterministic `tools_sha256`, `tools_count`, and HTTP `ETag` (`"sha256-"`) on `/mcp/tools.json` and `/api/v1/mcp/tools.json` (plus `tools_sha256` in `/mcp` and `/api/v1/setup-check`) so external agents and manifest monitors can verify tool schema stability. 8. **Daily Status, Error & Feedback Resolution Loop**: - Every daily status and error report must audit the production feedback inbox (`sudo /usr/local/bin/platform-feedback inbox --product pressmark --include-body` on `ubuntu@40.160.36.101`, backed by `/var/lib/hallman-feedback/inbox.sqlite3`) and open GitHub issues (`gh issue list --repo mooshee/pressmark --state open`). - Automatically implement, test, and deploy fixes or enhancements for reasonable feedback requests, mark each resolved report as `resolved` via `sudo /usr/local/bin/platform-feedback review --product pressmark --id --status resolved --expected-revision --apply`, close corresponding GitHub issues (`gh issue close`), and reconcile state with `sudo /usr/local/bin/platform-feedback sync --product pressmark --github-repo mooshee/pressmark --force`. 9. **Production Release & Permissions Hygiene**: - The production service binary (`/usr/local/bin/pressmark`) must always be deployed via the verified release operator `tools/pressmark-deploy/target/release/pressmark-deploy` rather than ad-hoc `/tmp` copy commands. - Maintain root ownership (`uid == 0`) and read permissions (`0o644`) on `/var/lib/pressmark/static/privacy.html` so `pressmark-deploy inspect` and `release` invariants pass without failure.