Skip to content

Soul-driven AI agent with permission-hardened tools, token budgets, and multi-channel access. Runs 24/7 from CLI, Telegram or More.

docs: improvement roadmap, security policy, 1.3.1 changelog, security backlog closure drafts

Salman Qureshi3c16f4e0b3d0
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 2bb258fe..65bf927b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,16 @@
# Changelog
+## Unreleased — 1.3.1
+
+### Security
+
+- **Git helpers run argv, not a shell string** — `git_status`, `git_log` and `git_diff` built a command string from a model-chosen `path` and ran it through `execSync` with no permission check. They now pass the path to `execFileSync('git', [...])` as a single argv element after `--` (or `-C <resolved>`), and refuse any path that fails the same read-scope check `read_file` uses. `git_push` rejects option-looking `remote`/`branch` values (`--receive-pack=…`, `--exec=…`) and also uses argv. Regression tests: `src/capabilities/git/git-helpers.test.ts`.
+- **Safe-read bypass fixes, now closed with regression tests** — the read-only auto-approval lane in Ask Me mode denies: `find` action flags (`-exec`/`-execdir`/`-ok`/`-okdir`/`-delete`, since 1.2.2; `-fprint`/`-fprintf`/`-files0-from` since 1.3.0 — #71, #77, #101, #110); shell redirection (`>`, `>>`, `2>`, `<`, `&>`, since 1.2.2 — #72, #82, #109); and shell expansion (`$VAR`, `${VAR}`, `$(…)`, backticks, `$'…'`, `~`, since 1.3.0 / PR #128 — #76, #80, #95). An explicit `find -exec` case was added to `src/capabilities/permissions.test.ts`.
+- **Sub-agent approval routing** — `delegate_task` workers no longer switch the shared permission manager into allow-all with a `/` write scope; their shell and filesystem calls go through the same Ask Me prompts as the parent (since 1.2.2 — #75, #99). `allowedTools` is enforced at runtime, not just in the prompt (since 1.3.0 — #74, #97, #98). Still open: a sibling-ownership check for `stop_agent`, and an immutable per-agent permission context so a concurrent internal-channel turn cannot widen a worker's approvals (ROADMAP P1.12 / P2.2).
+- **Symlink write canonicalisation** — `create_file`/`write_file`/`edit_file` check the resolved target of a symlink against the writable scopes, not only the lexical path (since 1.3.0 — #105).
+- **SSRF guard** — unchanged; see the 1.2.3 entry below (hardened in 1.3.0 by #121 and #124; response record in `docs/security/ssrf-108-response.md`).
+- **Disclosure process** — `SECURITY.md` added (private reporting, response targets, scope); issue-closure and advisory drafts in `docs/security/2026-10-backlog-closure.md`.
+
## 1.3.0 — Mercury Bots
Persistent, persona-scoped agents that run **outside your conversation** — each with its own persona, workspace, skills, permissions, and durable queue. Onboard specialists, chain them into multi-level fleets, and let them work 24/7 while you keep talking to Mercury.
diff --git a/ROADMAP.md b/ROADMAP.md
new file mode 100644
index 00000000..ea7595d3
--- /dev/null
+++ b/ROADMAP.md
@@ -0,0 +1,282 @@
+# Mercury — Improvement Plan (October 2026)
+
+Scope: make Mercury a top-tier personal agent harness across macOS, Linux, Windows and
+Termux, with the TUI as the flagship surface. Derived from a read-only audit of
+v1.3.0 (`5aae3fb`) covering the agent loop, TUI, channels, Mercury Code, Bots,
+security backlog, and the build/deploy pipeline. All `file:line` references are
+against that commit.
+
+---
+
+## 0. Executive summary — five root causes
+
+Most user-visible pain traces back to five things. Fix these and the product changes
+character; everything else is polish.
+
+| # | Root cause | Symptom users report | Where |
+|---|---|---|---|
+| 1 | **Mercury Code's guards run in plain chat.** The narration guard and verification gate fire whenever `programmingMode` is `off` and the message matches an implementation-intent regex (`mak|add|test|cod|creat|continu|proceed|do it`). | "Make me a workout plan" → up to 10 forced tool-only rounds, "getting started on the real build now…", then "I couldn't get started on this one yet." **This is the "not helpful at all" bug.** | `src/core/agent.ts:4459-4476`, `:4745-4747`; `src/core/execute-guard.ts:70` |
+| 2 | **"Done" is not evidence-gated in practice.** A failed or timed-out `npm test` satisfies the verification gate (string match, not exit code); remote channels never receive the verification line; pause banners are truncated to 80 chars and deleted on Telegram. | Green "✓ Verified" over a broken build; bot "goes silent" on Telegram; permission prompts silently auto-deny after 120 s. | `execute-guard.ts:216`; `agent.ts:4707/4800/4829/5097`; `channels/telegram.ts:361-378, 680, 716` |
+| 3 | **The TUI loses input and can't be interrupted.** Multi-line paste strips `\n`; no bracketed paste; Ctrl+C hard-exits, Esc does nothing; chat mode re-parses the whole streaming message as markdown every 60 ms; the Ink patch can silently fail, after which new messages stop rendering past 100. | Mangled code pastes, "it feels laggy", no way to stop a turn except `/stop`, CJK input broken (#41). | `src/ui/input-composer.tsx:250-259`; `src/ui/App.tsx:292, 681, 1705`; `package.json:23,66`; `tsup.config.ts:45` |
+| 4 | **Standalone binaries ship without a working SQLite on any OS**, and Termux is mis-detected (`android` ≠ `linux`). | Second Brain silently off for every binary user (not just Linux #96); bots fall back to JSON; Termux exits after the wizard with "Unsupported platform". | `src/memory/second-brain-db.ts:15-34`, `src/bots/queue.ts:15-31`; `src/utils/platform.ts:8`; `src/cli/service.ts:495-499` |
+| 5 | **Security backlog is mostly fixed but publicly "unpatched".** 8 of 13 open security issues are fixed in code and not closed; 5 CVEs + 4 GHSAs list "Patched versions: None"; no `SECURITY.md`. One **unreported** shell injection remains in `git_status/git_log/git_diff`. | Reputation risk any investor or enterprise buyer finds in minutes. | `src/capabilities/git/git-status.ts:13`, `git-log.ts:16`, `git-diff.ts:16`; `permissions.ts:477-498` |
+
+Cross-cutting: `src/core/agent.ts` is 8,362 lines with a single 2,400-line `handleMessage`
+and `onStepFinish` copy-pasted four times; 699 `any` casts; 981 `console.log`; no ESLint; no
+end-to-end eval harness; 154 of 174 commits in 90 days by one person.
+
+---
+
+## 1. Scorecard
+
+| Area | State | One-line verdict |
+|---|---|---|
+| Conversation quality | 🔴 | Guards misfire in chat; history = last 10 texts, tool results never persisted; memory injected as fake dialogue |
+| Latency | 🟠 | ~10K-token uncached prefix per step; blocking channel edits per step; 3 full session-JSON reads + ~9 SQLite queries before first token |
+| TUI | 🟠 | Architecture is sound (Static scrollback, diff-render); input/interrupt/paste are below par; patch shipping fragile |
+| Feedback (all channels) | 🔴 | No consistent started/step/waiting/done/failed contract; evidence lost on remote channels |
+| Mercury Code | 🟠 | Good ideas (completion contract, watchdog) undermined by string-match verification and a watchdog that kills long builds |
+| Bots (new) | 🟠 | Solid queue design; duplicate-execution race; lead synthesis never delivered; `needsYou` volatile |
+| Security | 🔴 (process) 🟠 (code) | Code mostly patched; disclosure process absent; one unreported injection; safe-read classifier is a losing regex race |
+| macOS | 🟢 | Reference platform |
+| Linux | 🟠 | Fine via npm; binary lacks SQLite; arm64 untested in CI |
+| Windows | 🔴 | Service install broken (#13), wizard can exit silently (#64), kill = TerminateProcess, upgrade race, update check dead |
+| Termux | 🔴 | Mis-detected platform; npm-only; no service |
+| Engineering foundations | 🟠 | Good docs/ADRs and OS matrix in CI; no lint, no eval harness, no binary smoke tests, monolith files |
+
+---
+
+## 2. Priorities
+
+### P0 — this week (release as 1.3.1 hotfix)
+
+| # | Change | Evidence | Size | Acceptance |
+|---|---|---|---|---|
+| P0.1 | Gate narration guard and verification gate to `programmingMode.isExecute()` only | `agent.ts:4459-4476`, `:4745-4747` | S | "Make me a workout plan" and "write my notes to notes.md" produce a direct answer with zero forced rounds; regression test in `execute-guard.test.ts` |
+| P0.2 | Verification must be `ok === true` and after the last mutation; timeout = ✗; failed verification → pause banner, never "complete" | `execute-guard.ts:216`, `agent.ts:4707/4800`, `run-command.ts:113` | S | Test: `npm test` exit 1 → no completion banner; timed-out test → ✗ |
+| P0.3 | `endTask()` before terminal sends; flush deferred text; never truncate pause/failure banners | `agent.ts:4829`, `telegram.ts:361-378`, `discord.ts:445`, slack | S | Telegram test: step-budget pause arrives as a full persistent message |
+| P0.4 | Fix `git_status/git_log/git_diff` shell injection: `execFileSync('git', ['-C', path, …])` + `checkFsAccess(path,'read')` | `git-status.ts:13`, `git-log.ts:16`, `git-diff.ts:16` (pattern already correct in `git-add.ts:16`) | S | Test with a path containing `"; echo pwned` |
+| P0.5 | Close the 8 fixed-but-open security issues with commit refs; add `SECURITY.md`; publish advisories for the 5 CVEs / 4 GHSAs with fixed versions; CHANGELOG security entry | issues #101/#71/#77, #82/#72, #80/#76, #99/#75 (residual race noted) | S (admin) | GitHub shows a security policy and advisories with patched versions |
+| P0.6 | Termux detection: `platform === 'linux' \|\| 'android'`; assert in Termux CI job | `platform.ts:8`, `index.ts:2249-2275` | S | Termux job asserts `process.platform` and that `autoDaemonize` doesn't exit |
+| P0.7 | Bots: `running.has(job.id)` guard in retry/pause timers; deliver lead `mailbox` turns; make `needsYou` durable (journal row) | `bot-manager.ts:521-548, 565, 154` | S | Test: retry + due-sweep never runs a job twice; lead synthesis reaches the thread |
+| P0.8 | Permission/choice prompt timeouts write the outcome back ("⏱ no answer → denied") and keep the card; `editMessageReplyMarkup` after approvals (#23) | `telegram.ts:262-275, 680, 716, 760` | S | Manual + unit |
+| P0.9 | Ink patch: pin `"ink": "5.2.1"` exactly; ship `scripts/apply-ink-patch.cjs` in `files`; assert patch markers at boot and abort with a clear message | `package.json:23,66`, `tsup.config.ts:45`, `cli.ts:604` | S | Fresh `npm i --ignore-scripts` → clear error, not a silent 100-message cap |
+| P0.10 | Drop minute-resolution time/budget from the system prompt (append at the end at day resolution); add Anthropic `cache_control`; log `cachedInputTokens` | `agent.ts:5201-5215` | S | Cached-token ratio visible in `completionMeta` |
+
+### P1 — next 2–3 weeks (1.3.2 / 1.4)
+
+| # | Change | Evidence | Size |
+|---|---|---|---|
+| P1.1 | **Feedback contract** implemented behind one `TaskSurface` interface used by CLI, web, Telegram, Discord, Slack, Signal (see §3C) | four divergent status-card implementations in `src/channels/*` | M |
+| P1.2 | **Context builder v2**: persist compact tool-step records (tool, args head, result head) in the session; token-budgeted window with rolling summary; memory moved from fake dialogue into a system section with a score threshold | `agent.ts:3063-3065, 3110-3118, 4917-4934`; `user-memory.ts:255-266` | M |
+| P1.3 | Per-step channel updates fire-and-forget + coalesced; `Promise.all` cloud pool search with memory retrieval; cache session reads per turn; batch SQLite writes | `agent.ts:3130, 3678-3739`; `sessions/repository.ts:132→458` | M |
+| P1.4 | Mode-aware `activeTools`: no Spotify/GitHub/scheduler schemas in a plain chat turn (~6.5K tokens of tool schema per step today) | `capabilities/registry.ts:277` | S |
+| P1.5 | TUI input: keep `\n\t`, enable bracketed paste (`?2004h`), strip `ESC[200~/201~`, Shift+Enter multi-line; grapheme-aware cursor (`Intl.Segmenter` + `string-width`); persistent history | `input-composer.tsx:250-259, 284`; `App.tsx:368, 700` | M |
+| P1.6 | TUI interrupt semantics: Esc = interrupt turn, Ctrl+C = clear input / double-tap quit; prompt resolver map keyed by prompt id | `App.tsx:292, 681`; `cli.ts:1757-1845` | S |
+| P1.7 | TUI perf: reuse Mercury Code's fence-aligned tail renderer in chat/coding; one shared 100 ms tick store replacing five tickers; async `readGitStateQuick`; reset log-update baseline on resize | `App.tsx:1705, 1834, 1749, 1925, 2296`; `cli.ts:2183`; patch `log-update` | M |
+| P1.8 | Tool progress + abort plumbing: `run_command` streams stdout to `markProgress`, honours `abortSignal`, stall clock suspended while a tool with explicit timeout runs | `run-command.ts`, `agent.ts:397, 2278, 4345` | M |
+| P1.9 | Standalone SQLite: `bun:sqlite` backend when `process.versions.bun`; `node:sqlite` fallback for toolchain-less npm installs; `mercury doctor --storage` | `second-brain-db.ts:15-34`, `queue.ts:15-31, 475`, `board-db.ts:135`, `pool-search.ts:10-12` | M |
+| P1.10 | Windows: fix `installWindows` quoting + `getDistPath` via `realpathSync(argv[1])`; HKCU Run fallback for non-elevated; graceful shutdown over local HTTP instead of `process.kill`; installer waits on parent PID; `execFile('npm')` with `shell:true`; `os.homedir()` for `~` | `service.ts:59-64, 495-499`, `daemon.ts:219-223`, `index.ts:4740-4757`, `update-notice.ts:96`, `agent.ts:7168,7817` | M |
+| P1.11 | Wizard robustness (#64): single readline, reject on `close`, global error handlers before `configure()` | `index.ts:152-160, 2325-2350` | S |
+| P1.12 | Read-side path canonicalisation + `nlink>1` prompt + `fstat` dev/ino (#104 and symlink reads); strip `list_agents/stop_agent/delegate_task` from children by default + lineage check (#74) | `permissions.ts:477-498`; `stop-agent.ts:14-22`, `supervisor.ts:338` | S/M |
+| P1.13 | `/new` on every channel (fresh session, memory kept) (#38); `/trace <id>` per-turn trace; daemon log level `info`; `mercury doctor --health` | `agent.ts:7582`, `telegram.ts:313-329`, `utils/logger.ts:5`, `index.ts:3852` | M |
+| P1.14 | Provider layer: DeepSeek thinking by prefix (`deepseek-v4*`, `reasoner`), pass stored reasoning back (#24); capability tiers so fallback never silently downgrades; remove sticky `markSuccess` override; sane `maxOutputTokens` per provider; set `temperature` | `providers/deepseek.ts:14`, `providers/registry.ts:166-176`, `agent.ts:4409`, `config.ts:295/328` | M |
+
+### P2 — this quarter (1.5)
+
+| # | Change | Why |
+|---|---|---|
+| P2.1 | Split `handleMessage` into `prepareContext → generate → guards → deliver` with one shared `onStepFinish`; break `agent.ts`, `index.ts`, `App.tsx`, `cli.ts` into modules | Velocity and bus factor; every P1 item is harder inside an 8K-line file |
+| P2.2 | Auto-approval **argv lane**: POSIX-tokenise, allowlisted `argv[0]`, per-command flag policy, `execFile(absBinary, argv, {env: minimal})` from a PATH pinned at startup; shell only in the approval lane. Immutable per-agent permission context (capability tokens, child ⊆ parent) | Closes the whole safe-read bypass class (#103, residual `find -fprint0`, `rg --pre`, `git --output`, `--ext-diff`) and the #99/#75 race |
+| P2.3 | Replay-based eval harness: fixtures (history, message, recorded tool outputs) → mocked provider; assert no forced guard in chat, non-empty answer, verification correctness, per-phase timings; run in CI | Today nothing drives `handleMessage`; quality regressions are invisible |
+| P2.4 | Vendor the patched Ink (`noExternal` + alias to `vendor/ink`), drop postinstall; upstream Yoga hygiene (`facebook/yoga#1818`) and `Static.itemKey`; real hardware-cursor positioning for IME (#41) | Deterministic TUI on every install path incl. Termux |
+| P2.5 | Declarative keymap table driving `App.tsx`, `/help` and attach TUI; attach consumes `TuiState` diffs over SSE instead of reconstructing from events | Removes ~135 lines of drifting duplicate key handling |
+| P2.6 | CI: Bun job per OS building the host binary and running `--version`, `doctor --platform`, `doctor --storage`; Node 24/25; linux-arm64; installer scripts against a local release dir; shellcheck/PSScriptAnalyzer; unit tests for plist/unit/schtasks generation | No binary or service path is tested today |
+| P2.7 | ESLint (strict), `any` budget with a ratchet, `console.log` → logger, `files`/tarball verification test | Hygiene that compounds |
+| P2.8 | Termux first-class: `~/.termux/boot/start-mercury` from `mercury service install`, `node:sqlite` path, narrow-width TUI rules (`cols`-based instead of fixed 60/50/34+56/26) | Makes the fourth platform real |
+
+---
+
+## 3. Workstreams (detail)
+
+### A. Conversation quality and latency
+
+Architecture: `enqueueMessage` (661) → `processQueue` (2383) → `handleMessage` (2805-5179) →
+`buildSystemPrompt` (5181); AI SDK `streamText` with `stepCountIs(75)`, `maxOutputTokens: 32768`,
+all 53 tools every step; history = last 10 `message` entries from JSON sessions; memory via FTS.
+
+Problems and fixes, ranked:
+1. Guards in chat (P0.1). Also `isTextDeliverableRequest` should short-circuit the verification gate.
+2. Cross-turn amnesia: only `finalText` is stored; the `[Using: …]` loop-detector regex at 3072 scans a marker never written. Persist tool-step summaries; budget by tokens (P1.2).
+3. Memory as fake dialogue, injected even with zero matches (profile fallback). System section + threshold (P1.2).
+4. Uncached ~10K prefix (system ~3.8K + tool schemas ~6.5K) re-sent on up to 75 steps; prompt changes every minute. P0.10 + P1.4.
+5. Blocking per-step channel edits serialise the loop (P1.3).
+6. Hot path before first token: awaited cloud pool search (800 ms timeout) in series; `presentChoice` modal for ambiguous skills; Mercury Code handoff modal (45 s) on coding-looking CLI messages; 3 full session reads; ~9 SQLite queries. P1.3.
+7. Non-answer endings: loop-detector aborts end with a banner and no synthesis; empty text becomes "(no text response)" and is delivered; intermediate narration is concatenated with the final answer. Fix: on abort, run one final no-tools round to summarise; never deliver "(no text response)"; separate narration stream from answer stream.
+8. Provider layer (P1.14).
+
+Metrics to add to `completionMeta` and `/trace`: prompt-build ms, memory ms, first-token ms, per-step ms, cached/uncached input tokens, guard decisions, provider switches.
+
+### B. TUI
+
+Architecture is right (single Ink root, `TuiState` via `useSyncExternalStore`, `<Static>` scrollback,
+diff-rendered live region). The gaps are input, interrupt, perf and patch shipping.
+
+Order: P0.9 (patch safety) → P1.6 (interrupt) → P1.5 (paste/IME/history) → P1.7 (perf) →
+narrow-width rules (P2.8) → P2.4/P2.5.
+
+UX features, in priority order once the above lands: permission prompts showing the diff/command
+inline with "always for this tool"; `?` keybinding overlay and rotating status hints; Ctrl+R history
+search; `/copy` via OSC 52 and OSC 8 links; real LCS diff with intra-line highlight (`tool-block.ts:133`
+is prefix/suffix only); OSC 11 theme query (today `COLORFGBG` only, mis-detects Windows Terminal /
+VS Code / tmux); bell when a prompt needs you; Ctrl+O expand in place.
+
+Known-bad specifics to fix along the way: Delete acts as backspace (`App.tsx:750`); `setSlashSelIdx(0)`
+effects add two commits per keystroke (`App.tsx:128,150`); 120 ms tail memo has no trailing flush
+(`App.tsx:2652`); attach `streaming` only clears on `text_done`/`error` so tool-only turns show
+"working…" forever (`attach-tui.tsx:207-213`).
+
+### C. Feedback contract (every surface, every turn)
+
+1. **started** — one line within 2 s: intent restatement + mode (chat/code/bot), edited in place.
+2. **step** — `n/N · tool target · ok|err · Δt` in one live region; never a new message per step.
+3. **waiting-on-you** — explicit card with options and a visible timeout; the timeout outcome is
+ written back ("no answer → denied").
+4. **done-with-evidence** — files changed, verification command + exit code + 1-line output tail,
+ tokens/cost/time. **No "complete" without `verified.ok === true` or an explicit
+ "unverified because: …".**
+5. **failed/paused-with-reason** — which guard/provider/limit fired, what was preserved, the one
+ command to resume; delivered as a persistent message, never a status-card notice.
+6. **trace handle** — every terminal message carries an id resolvable by `/trace <id>` and the web
+ cockpit.
+
+Implement once behind `TaskSurface`; channels render, they do not decide.
+
+### D. Mercury Code and Bots
+
+Mercury Code: P0.2 (verification semantics), P1.8 (progress/abort so a 10-minute build isn't killed at
+4 minutes with "stalled provider"), plan checklist reconciled against actual tool success instead of
+model self-report (`cli.ts:1437`), `update_plan` on all channels (today CLI-only, `agent.ts:2534`),
+checkpoint/undo beyond `/code diff`.
+
+Bots: P0.7 (duplicate run race, lead delivery, durable `needsYou`), sub-agent results not sliced to
+500 chars (`supervisor.ts:315`), "needs you" sends retried, retention caps verified under load.
+
+### E. Security
+
+Code order: P0.4 (git helpers) → P1.12 (reads, lineage) → P2.2 (argv lane + capability tokens) →
+PATH pinning in service files (`service.ts:297, 398`). Windows blocklist additions: `pwsh`,
+`Remove-Item`, `Set-ExecutionPolicy` (`blocklist.ts`). `.env` written with `mode: 0o600`
+(`index.ts:723-734`).
+
+Process (P0.5): `SECURITY.md` with private reporting via GitHub advisories and an SLA; advisories
+published for CVE-2026-22169, -32010, -30741, -28463, -26322 and GHSA-796m-2973-wc5q,
+-jccr-rrw2-vc8h, -943q-mwmv-hhvh, -qrp5-gfw2-gxv4 with fixed versions; close #101/#71/#77,
+#82/#72, #80/#76, #99/#75 with commit refs; add regression tests for `find -exec`, #99/#75, #100,
+#74 lineage. Until P2.2 ships, describe safe-read auto-approval as best-effort, and do not claim
+"asks before it acts" for `git_status/git_log/git_diff` until P0.4 is released.
+
+### F. Cross-platform
+
+| | macOS | Linux | Windows | Termux |
+|---|---|---|---|---|
+| Install | OK | OK (glibc) | OK x64; arm64 refused | npm only |
+| Service | OK | OK | P1.10 | P2.8 |
+| TUI | OK | OK | P1.5/P1.6 (Ctrl+C hard-kill in `arrow-select.ts:117`) | P2.8 narrow widths |
+| SQLite (binary) | P1.9 | P1.9 (#96) | P1.9 | n/a |
+| Upgrade | OK | OK | P1.10 | npm |
+| Channels | Signal needs Java 17+ | all | no Signal | no Signal |
+
+Also: `install.sh:49` calls `err` before it is defined; no post-install `--version` smoke or rollback.
+CI additions in P2.6. Release workflow is manual (`publish.sh`, CI publish job disabled,
+`ci.yml:138-163`); binaries are built on one Mac with Bun and never executed in CI.
+
+### G. Engineering foundations
+
+P2.1 split, P2.3 eval harness, P2.6 CI, P2.7 lint. Keep ADRs current: add ADR-015 (feedback
+contract / `TaskSurface`), ADR-016 (argv-lane auto-approval and capability tokens), ADR-017
+(vendored Ink), ADR-018 (SQLite backend selection: better-sqlite3 → bun:sqlite → node:sqlite → JSON).
+
+---
+
+## 4. Targets
+
+| Metric | Today (estimated) | Target |
+|---|---|---|
+| Forced tool rounds in plain chat | up to 10 | 0 |
+| "Complete" banners with failed/absent verification | possible | 0 (test-enforced) |
+| Fixed prefix tokens per step | ~10K, uncached | ≤6K, ≥80% cached on Anthropic/OpenAI |
+| Time to first token (local, warm) | prompt build + 3 session reads + ~9 queries + serial pool search | < 400 ms before provider latency; measured in `/trace` |
+| Pause/failure messages lost on Telegram | yes | 0 |
+| Standalone binary with working Second Brain | 0 of 4 targets | 4 of 4 |
+| Windows `mercury service install` | broken | works for standard users |
+| Termux `mercury` after wizard | exits | runs; boot script optional |
+| Open security issues already fixed | 8 | 0; advisories published |
+| Tests driving `handleMessage` / `TuiApp.useInput` | 0 / 0 | eval harness + key-handling tests in CI |
+
+---
+
+## 5. Sequencing
+
+- **Week 1 — 1.3.1 hotfix.** P0.1–P0.10. Mostly one-line conditions, admin, and small guards.
+ Publish advisories the same day the git-helper fix ships.
+- **Weeks 2–4 — 1.3.2 then 1.4.** P1.1 (feedback contract) and P1.2 (context v2) first because
+ everything else renders through them; then TUI P1.5–P1.7, Windows P1.10–P1.11, SQLite P1.9,
+ provider P1.14, security P1.12, `/new` + `/trace` P1.13.
+- **Weeks 5–12 — 1.5.** P2.1 split (do it early in this window; later work gets cheaper), P2.2 argv
+ lane, P2.3 eval harness in CI, P2.4 vendored Ink + IME, P2.6 binary CI, P2.7 lint, P2.8 Termux.
+
+Hiring/ownership note: with one author on 90% of commits, the P2.1 split and the eval harness are
+what let a second engineer contribute safely. Prioritise them over new features.
+
+---
+
+## Appendix — condensed findings by area
+
+### Agent loop (`src/core/agent.ts`, `execute-guard.ts`, `providers/*`, `sessions/*`, `memory/*`)
+- `handleMessage` 2805–5179; `onStepFinish` duplicated at 3473, 3917, 4563, 2430.
+- Narration guard 4459–4476 (chat mode), verification gate 4745–4747; `FORCED_ACTION_TOOLS` 4545; `WORK_NOT_STARTED_BANNER`; second-wind rounds 4619.
+- History 3063–3065 (10 messages, 4 in Saver); only `finalText` stored 4917–4934; dead `[Using: …]` detector 3072.
+- Memory injection 3110–3118, 3161–3168; profile fallback `user-memory.ts:255-266`.
+- Prompt: time/budget 5201–5215; soul+guardrails+persona ~5.8 KB; 25 skill summaries ~5.5 KB; 53 tool schemas ~25 KB incl. 14 Spotify tools always present.
+- Blocking step I/O 3678 (Telegram), 3692 (Signal), 3720 (Discord), 3734 (Slack), 3739 (`[Using…]`).
+- Hot path: pool search 3130; skill choice modal 3240; Mercury Code handoff 766; research prompt 752; `sessions.get` re-reads 132→458.
+- Loop-detector aborts 3552–3582, 4289–4295; "(no text response)" 4445, 4882; narration concatenation `stepAwareTextStream` 103–140; auto-continue only in execute 3831.
+- Providers: default `deepseek-chat` (`config.ts:295/328`); thinking only for exact `deepseek-reasoner` (`deepseek.ts:14`); sticky `markSuccess` (`registry.ts:166-176`); chain doubled 4409; `maxOutputTokens: 32768` 393; no temperature.
+- Tests: 20 `core/*.test.ts`, pure helpers only.
+
+### TUI (`src/ui/*`, `src/channels/cli.ts`, `patches/ink+5.2.1.patch`)
+- Root `cli.ts:1067`; `TuiState` coalescing 712–741; token throttle 1640–1680; Mercury Code tail 32 KB / 120 ms memo `App.tsx:2645`.
+- Hook census `App.tsx`: 25 `useState`, 15 `useEffect`, 6 `setInterval`; `useInput` closure 485 lines (281–766).
+- Paste: `cleanPrintableInput` `input-composer.tsx:250-259`; no `?2004h`.
+- IME: hidden cursor `log-update.js:9`; fake cursor `App.tsx:2130, 2430`; UTF-16 editing `input-composer.tsx:284`, `App.tsx:368, 700`.
+- Patch: `tsup.config.ts:45` external; `package.json:23` postinstall `|| echo`; `scripts/` not in `files` (66); caret range; 100-message window `App.tsx:914, 1052, 2691` + ignored `itemKey` on stock Ink.
+- Markdown per frame `App.tsx:1705`; tickers 1834, 1749, 1925, 2296, `use-terminal-size.ts:21`.
+- Interrupt: `App.tsx:292` → `index.ts:2711`; Esc 681; resolver slot `cli.ts:1757-1845`.
+- Resize vs diff-render `ink.js:91`; `readGitStateQuick` `cli.ts:2183`; fixed widths `App.tsx:2110, 938, 772-786, 1101, 2259`; attach `attach-tui.tsx:207-213, 323-457`.
+
+### Bots / Mercury Code / channels
+- Verification: `execute-guard.ts:216`; `vOk` regex `agent.ts:4707/4800`; timeout text `run-command.ts:113`; CLI-only note 5097; channel completions 4985–5065.
+- Pause swallowed: `agent.ts:4829` → `telegram.ts:361-378` → `finalizeChannelTask` 2796; `discord.ts:445`.
+- Watchdog: `MAX_STALL_MS` `agent.ts:397, 2278`; ambiguous end 4345; `run-command` ignores `abortSignal`.
+- Bots: retry race `bot-manager.ts:521-548` vs `resumeDueJobs` 261; lead delivery 565 / `sendToBot` 370; `needsYou` 154; sub-agent slice `supervisor.ts:315`.
+- Prompts: `telegram.ts:680, 716, 760`; keyboards 262–275; `statusNotices` 372 unbounded.
+- `/reset` `agent.ts:7582`; Telegram commands `telegram.ts:313-329`; logger `utils/logger.ts:5`; `doctor` `index.ts:3852`; plan progress `agent.ts:2534`, `cli.ts:1437`.
+
+### Security
+- Fixed-not-closed: `permissions.ts:681` (redirection), `:686` (find flags), `:696-697` (`$`, backticks, `~`); tests `permissions.test.ts:181-262` (no explicit `-exec` case).
+- Sub-agent approvals `sub-agent.ts:172-175`; shared mutable `PermissionManager` `supervisor.ts:183`; internal auto-approve window `agent.ts:2929-2933 → 5174`; `isGlobalAutoApproveActive` `permissions.ts:386-390`; "full permissions" prompt `sub-agent.ts:504`.
+- Lineage: `stop-agent.ts:14-22`, `supervisor.ts:338`; `tool-filter.ts:5`.
+- Reads lexical only `permissions.ts:477-498`; realpath for writes 484–492; `read-file.ts:21-38`.
+- Unchecked exec: `git-status.ts:13`, `git-log.ts:16`, `git-diff.ts:16`, `git-push`; `registry.ts:244-246`; `run-command.ts:32-36` `shell:true`; PATH in `service.ts:297, 398`.
+- Residual auto-approved primitives: `find -fprint0`, `find -fls`, `tree -o`, `git log --output`, `rg --pre`, `--ext-diff`.
+- Process: no `SECURITY.md`; advisories unpublished; CHANGELOG security section incomplete; only `docs/security/ssrf-108-response.md`.
+
+### Cross-platform
+- Build: `tsup.config.ts:40-62` externals; `post-build.cjs`; `build-bin.cjs:75-81, 138-146, 173-207`; `verify-standalone-release.cjs` never runs a binary; `ci.yml:138-163` publish disabled; `files` `package.json:67-71`.
+- SQLite in binaries: `better-sqlite3/lib/database.js:48` via `bindings`; probes `second-brain-db.ts:15-34`, `queue.ts:15-31`, `board-db.ts:135`, `pool-search.ts:10-12`; warn only `index.ts:2460-2463`.
+- Windows service: `service.ts:495-499, 59-64, 95`; stop `daemon.ts:219-223`; shutdown `index.ts:3632-3666`; upgrade `index.ts:4740-4757`, `install.ps1:204-206`; update check `update-notice.ts:96`; `~` via `HOME` `agent.ts:7168, 7817`, `cli.ts:2047, 2203`, `bot-manager.ts:1387`.
+- Termux: `platform.ts:8`; `autoDaemonize` `index.ts:2249-2275`; binary refused `install.sh:198`; Signal `binary.ts:32`.
+- Wizard: `index.ts:152-160`, handlers 2325–2350; `.env` mode `index.ts:723-734` vs `config.ts:657`, `web/auth.ts:22`.
+- `install.sh:49` `err` before definition; `install.ps1:147` arm64 refused.
+- Tests: 109 files; `it.skipIf(!sqliteAvailable)` ×17; `live-region-guard.test.tsx:68`; none for `service.ts`, daemon, installers, binaries.
diff --git a/SECURITY.md b/SECURITY.md
new file mode 100644
index 00000000..71ad27dc
--- /dev/null
+++ b/SECURITY.md
@@ -0,0 +1,70 @@
+# Security Policy
+
+Mercury is a local-first agent that can run shell commands, edit files and talk to
+chat channels on your behalf. We take reports about its permission model seriously.
+
+## Supported versions
+
+| Version | Supported |
+|---------|-----------|
+| 1.3.x (latest) | Yes — security fixes land here |
+| 1.2.x and older | No — please upgrade (`mercury upgrade` or `npm i -g @cosmicstack/mercury-agent@latest`) |
+
+Fixes ship as patch releases on the current minor line only.
+
+## Reporting a vulnerability
+
+Please do **not** open a public issue for anything exploitable.
+
+1. Preferred: GitHub private vulnerability reporting —
+ https://github.com/cosmicstack-labs/mercury-agent/security/advisories/new
+2. Fallback: email **[email protected]** with "Mercury security" in the subject.
+
+Include the version (`mercury --version`), the channel or surface involved, steps to
+reproduce (a deterministic harness or stub provider is ideal), and your assessment
+of impact. Tell us how you would like to be credited.
+
+## What to expect
+
+- Acknowledgement within **3 business days**.
+- For High/Critical reports: a fix or a concrete mitigation plan within **14 days**,
+ and a patch release as soon as it is verified.
+- For Medium/Low reports: a fix in the next regular release, normally within 60 days.
+- We will keep you updated, credit you in the advisory and changelog unless you
+ prefer otherwise, and coordinate publication timing with you.
+
+## Scope
+
+In scope:
+
+- The agent runtime in this repository (`src/`): tool loop, permission manager,
+ shell/filesystem/git tools, sub-agents and Mercury Bots.
+- Channels shipped here: CLI/TUI, local web dashboard, Telegram, Discord, Slack, Signal.
+- The web dashboard and its HTTP/SSE API.
+- Skills: `install_skill`, registry fetches and how installed skills are loaded.
+- Mercury Cloud client code that lives in this repository.
+
+Out of scope:
+
+- Third-party model providers and their APIs (report to the provider).
+- The content and behaviour of skills you install yourself.
+- Attacks that require an already-compromised host account or the Mercury
+ config directory (`~/.mercury`), or a dashboard deliberately exposed beyond
+ `127.0.0.1` without a reverse proxy and authentication.
+- A model being persuaded to *ask* for something that you then approve.
+
+## A note on the permission model
+
+Mercury's "Ask Me" mode is the real security boundary: risky commands and
+out-of-scope file access prompt you before they run. On top of that, a small
+allowlist of read-only commands (`ls`, `cat`, `grep`, `find`, ...) is auto-approved
+for usability. That classifier is a **best-effort** pattern check on the command
+string. Several bypasses of it have been reported and fixed (find action flags,
+shell redirection, variable expansion), and we expect the class to keep producing
+reports until the auto-approval lane is rebuilt around a tokenised argv allowlist
+with per-command flag policy (tracked in `ROADMAP.md`, P2.2). Until then, treat
+auto-approval as a convenience, not a guarantee, and keep Ask Me on for any
+instance reachable by people you do not fully trust.
+
+Known-fixed issues and the regression tests that cover them are listed in
+`docs/security/`.
diff --git a/docs/security/2026-10-backlog-closure.md b/docs/security/2026-10-backlog-closure.md
new file mode 100644
index 00000000..58d2bcf9
--- /dev/null
+++ b/docs/security/2026-10-backlog-closure.md
@@ -0,0 +1,291 @@
+# Security backlog closure — October 2026 (ROADMAP P0.5)
+
+Status: **DRAFT — nothing below has been posted.** The maintainer reviews, edits and
+posts. Issue comments are ready to paste; advisory text is ready to paste into
+"New draft security advisory" on GitHub.
+
+Prepared 2026-10-09 against branch `fix/p0-hotfix-1.3.1`. All reports are by
+[@YLChen-007](https://github.com/YLChen-007); the fixes are by @SeashoreShi and
+@salmanqureshi. Evidence for every claim is a commit hash you can `git show`.
+
+## 0. Two things to know before posting anything
+
+**1. The nine identifiers in ROADMAP are not ours.** The GitHub Advisory Database
+resolves every one of them to an **OpenClaw** advisory (checked 2026-10-09 via
+`gh api /advisories?cve_id=…` and `/advisories/<ghsa>`):
+
+| Identifier | Appears in Mercury issue | Actually assigned to |
+|---|---|---|
+| CVE-2026-22169 | #71 (find -exec) | OpenClaw — safeBins `sort` allowlist bypass (GHSA-vmqr-rc7x-3446) |
+| CVE-2026-32010 | #77 (find -exec) | OpenClaw — `sort --compress-program` bypass (GHSA-4gc7-qcvf-38wg) |
+| CVE-2026-30741 | #99 (delegate_task) | OpenClaw Agent Platform RCE (GHSA-rvp5-mqmc-q4g6, unreviewed) |
+| CVE-2026-28463 | #95 (`$HOME` expansion, closed) | OpenClaw — safeBins shell-expansion bypass (GHSA-xvhf-x56f-2hpp) |
+| CVE-2026-26322 | #81 (`github_api` token leak, closed) | OpenClaw — Gateway `gatewayUrl` override (GHSA-g6q9-8fvw-f7rf) |
+| GHSA-796m-2973-wc5q | #101 (find -exec) | OpenClaw — `env -S` wrapper policy mismatch |
+| GHSA-jccr-rrw2-vc8h | #76 **and** #80 (`echo $VAR`) | OpenClaw — jq `$ENV` env disclosure |
+| GHSA-943q-mwmv-hhvh | #75 (delegate_task) | OpenClaw — `/tools/invoke` escalation + ACP auto-approval |
+| GHSA-qrp5-gfw2-gxv4 | #98 (allowedTools bypass, closed) | OpenClaw — bundled MCP/LSP tool-policy bypass |
+| — (none cited) | #72, #82 (redirection), #74 (sibling halt), #109 | — |
+
+The reporter's PoC paths (`llm-enhance/cve-finding/similar/…/Advisory-GHSA-…-exp`)
+show these were the *pattern* advisories the Mercury bugs were modelled on; the
+IDs were reused as canary strings. **Do not publish Mercury advisories under these
+identifiers and do not "update patched versions" on them.** Instead create new
+repository advisories (GitHub assigns a fresh GHSA; tick "request CVE" if you
+want one from GitHub's CNA) using the drafts in §3.
+
+**2. Private vulnerability reporting is currently off.** `gh api
+repos/cosmicstack-labs/mercury-agent/private-vulnerability-reporting` returns
+`{"enabled": false}`. `SECURITY.md` points reporters at it, so enable it first:
+Settings → Code security and analysis → Private vulnerability reporting → Enable.
+
+## 1. Closure table
+
+Release lines: v1.1.13 = `0de8955` (2026-06-18, last vulnerable for the 1.2.2
+fixes). npm 1.2.1 (`63bda36`, 2026-08-05, no git tag) already carries the
+`isSafeReadSegment` and sub-agent changes; the first tagged release with them is
+**v1.2.2** (`e5dc012`, PR #111, 2026-08-10). v1.2.7 = `31013b0` (2026-09-14) is
+the last release without the 1.3.0 fixes. v1.3.0 = `2222670` (2026-10-06).
+
+| Issues | Class | Fixed in | Commit / PR | Regression test | Action |
+|---|---|---|---|---|---|
+| #71, #77, #101 (+#110 closed) | `find` action flags auto-approved | 1.2.2 (`-exec/-execdir/-ok/-okdir/-delete`); 1.3.0 (`-fprint/-fprintf/-files0-from`) | `e5dc012` (PR #111); `f465e6f`; `6a6c6bd` (#102, generic `--files0-from`) | `src/capabilities/permissions.test.ts` — "does not classify redirection or mutating read-command flags" (explicit `-exec`/`-execdir` cases added in this hotfix) and "find -fprint/-fprintf/-files0-from…" | Close all three |
+| #72, #82 (+#109 closed) | Redirection turns safe reads into writes | 1.2.2 | `e5dc012` (PR #111) | `src/capabilities/permissions.test.ts` — `echo poisoned > AGENTS.md`, `echo poisoned>AGENTS.md` | Close both |
+| #76, #80 (+#95 closed) | `$VAR` expansion discloses env / escapes scope | 1.3.0 | `00108b9` + `6651188` (PR #128) | `src/capabilities/permissions.test.ts` — "requires approval for safe-read commands that rely on shell expansion" (`echo $TOKEN`, `head $HOME/…`, `~`, `$'…'`) | Close both |
+| #75, #99 | `delegate_task` worker ran with allow-all + `/` scope | 1.2.2 | `e5dc012` (PR #111) removed `setAutoApproveAll(true)` / `addTempScope('/')` from `SubAgent.run()` | None end-to-end yet (ROADMAP asks for one); the absence of the calls is the fix — `grep setAutoApproveAll src/core/sub-agent.ts` returns nothing | Close, with the residual race stated openly and tracked in P2.2 |
+| #74 (+#97, #98 closed) | `allowedTools` not enforced; child can halt siblings | 1.3.0 (allowedTools); lineage **pending** | `0f5fe78` | `src/utils/tool-filter.test.ts` — "drops orchestration tools that are not allowlisted" | Keep open (or close and open a narrower lineage issue); post status |
+
+Residual for #75/#99, in plain terms: sub-agents still share the parent's single
+mutable `PermissionManager` (`supervisor.ts:183`). When the main loop handles an
+`internal`-channel message it calls `setAutoApproveAll(true)` for the duration of
+that turn (`agent.ts:2929-2933` → `:5225`). A worker whose tool call lands inside
+that window is auto-approved. It needs an internal turn to be running at the same
+time, so it is not reachable from chat input alone, but it is a real gap. The fix
+is an immutable per-agent permission context (ROADMAP P2.2). The sub-agent system
+prompt also still says "You have full permissions for this task"
+(`sub-agent.ts:504`); that is prompt text only and should be reworded in P1.12.
+
+## 2. Issue comments (ready to paste)
+
+### #71, #77, #101 — `find -exec` (post the same text on each; adjust the "see also" line)
+
+> Fixed — closing. Thanks @YLChen-007 for the clear report and the deterministic
+> stub-provider harness; it made this easy to replay.
+>
+> **Fix:** `isSafeReadSegment` in `src/capabilities/permissions.ts` refuses to
+> auto-approve any `find` segment carrying `-exec`, `-execdir`, `-ok`, `-okdir`
+> or `-delete`; those fall through to the normal Ask Me prompt. Shipped in
+> **v1.2.2** (commit `e5dc012`, PR #111). The same gate was widened in
+> **v1.3.0** to `-fprint`/`-fprintf` (attacker-chosen write path) and
+> `-files0-from` (path list dereferenced at exec time), plus a generic
+> `--files0-from` deny for every safe-read command (`f465e6f`, `6a6c6bd`).
+>
+> **Verified:** your exact payload
+> `find . -maxdepth 0 -exec sh -c 'printf … > canary.txt' ';'` now produces a
+> permission prompt; plain `find . -maxdepth 1` stays auto-approved.
+>
+> **Regression tests:** `src/capabilities/permissions.test.ts` — an explicit
+> `find -exec` / `-execdir` case is in 1.3.1 alongside the existing `-delete`,
+> `-fprint`, `-fprintf`, `-files0-from` cases.
+>
+> **Affected:** ≤ 1.1.13. **Patched:** ≥ 1.2.2 (full flag set ≥ 1.3.0).
+> Same root cause as #71 / #77 / #101 / #110. A GitHub advisory for this class
+> is being published from this repository and will credit you.
+>
+> Honest caveat: the safe-read lane is a pattern check on the command string.
+> It is best-effort until the argv-allowlist lane lands (ROADMAP P2.2), and
+> `SECURITY.md` now says so.
+
+### #72, #82 — shell redirection
+
+> Fixed — closing. Thanks @YLChen-007; the control-path design in your harness
+> (direct `sh -c` prompts, redirected `cat` did not) was exactly the right test.
+>
+> **Fix:** `isSafeReadSegment` rejects any safe-read segment containing a
+> redirection operator (`>`, `>>`, `<`, `<<`, `2>`, `&>`, with or without
+> spaces) before the allowlist match, so `cat README.md > variant.txt` and
+> `echo X>f` go to the Ask Me prompt. Shipped in **v1.2.2** (commit `e5dc012`,
+> PR #111). This is the same fix recorded on #109.
+>
+> **Regression tests:** `src/capabilities/permissions.test.ts` — "does not
+> classify redirection or mutating read-command flags as safe reads"
+> (`echo poisoned > AGENTS.md`, `echo poisoned>AGENTS.md`).
+>
+> **Affected:** ≤ 1.1.13. **Patched:** ≥ 1.2.2. Duplicate of #72 / #82 / #109;
+> one advisory covers the class and will credit you.
+
+### #76, #80 — `echo $VAR` environment disclosure
+
+> Fixed — closing. Thanks @YLChen-007, and thanks @SeashoreShi for the PR.
+>
+> **Fix:** PR #128 (`00108b9`, follow-up `6651188`) makes `isSafeReadSegment`
+> require approval for any segment that relies on shell expansion — `$VAR`,
+> `${VAR}`, `$(…)`, backticks, ANSI-C `$'…'`, and `~`/`~user` — because the
+> literal-path gate runs before the shell expands them. `echo $TOKEN`,
+> `printenv`-style disclosure through `echo`, and `head $HOME/secret` (#95) all
+> prompt now. Shipped in **v1.3.0**.
+>
+> **Regression tests:** `src/capabilities/permissions.test.ts` — "requires
+> approval for safe-read commands that rely on shell expansion" (includes
+> `echo $TOKEN` with a reference to this issue).
+>
+> **Affected:** ≤ 1.2.7. **Patched:** ≥ 1.3.0. Same root cause as #76 / #80 /
+> #95; one advisory covers the class and will credit you.
+
+### #75, #99 — `delegate_task` approval bypass
+
+> Fixed — closing, with one residual noted below so it is not lost. Thanks
+> @YLChen-007 for the end-to-end differential harness.
+>
+> **Fix:** `SubAgent.run()` no longer calls
+> `permissions.setAutoApproveAll(true)` or `addTempScope('/', true, true)`.
+> A delegated worker runs under the same `PermissionManager` state and channel
+> context as the parent, so its `run_command` calls hit the same Ask Me prompt
+> as the direct path (your control case). Shipped in **v1.2.2** (commit
+> `e5dc012`, PR #111). In **v1.3.0**, `allowedTools` also became a real runtime
+> filter on the tools a worker receives (`0f5fe78`, #97/#98).
+>
+> **Verified:** your exploit payload now yields `permissionRequestCount: 1` on
+> the delegated path, matching the control.
+>
+> **Residual (tracked, not closed):** workers still share the parent's single
+> mutable permission manager. When the main agent processes an
+> `internal`-channel turn (scheduled/background work) it enables allow-all for
+> that turn; a worker whose tool call lands inside that window inherits it.
+> This needs a concurrent internal turn, so it is not reachable from chat
+> input alone, but it is real. The fix is an immutable per-agent permission
+> context (ROADMAP P2.2); an end-to-end regression test for this issue is on
+> the same list. If you want to keep poking at it, that window is the place.
+>
+> **Affected:** ≤ 1.1.13. **Patched:** ≥ 1.2.2. One advisory covers #75 / #99
+> and will credit you.
+
+### #74 — restricted sub-agent halts siblings (status comment; keep open)
+
+> Status update, thanks @YLChen-007. This is **partially fixed** and we are
+> keeping it open for the remainder.
+>
+> **Fixed in v1.3.0** (`0f5fe78`, closes #97/#98): `allowedTools` is now
+> enforced at runtime. A child spawned with `allowedTools: ['read_file']` is
+> handed only `read_file`; it never sees `list_agents` or `stop_agent`. Test:
+> `src/utils/tool-filter.test.ts` ("drops orchestration tools that are not
+> allowlisted").
+>
+> **Still open:** (1) `stop_agent` has no ownership/lineage check —
+> `supervisor.halt(agentId)` will halt any agent id, so a child spawned
+> *without* an `allowedTools` list can still halt a sibling; (2) children with
+> no `allowedTools` receive the orchestration tools by default. Plan (ROADMAP
+> P1.12): strip `delegate_task`/`list_agents`/`stop_agent` from children unless
+> explicitly allowed, and restrict `stop_agent` to the caller's own descendants,
+> with a lineage test. We will update here when that lands.
+
+## 3. Advisory drafts (new repository advisories — do not reuse the OpenClaw IDs)
+
+Common fields: Ecosystem **npm**, package **`@cosmicstack/mercury-agent`**,
+credit **@YLChen-007 (reporter)**, fix credit @SeashoreShi / @salmanqureshi.
+CVSS vectors below are the reporter's; adjust if you disagree. Severity is as
+reported.
+
+### A. Safe-read auto-approval bypass via `find` action flags
+
+- **Summary:** In Ask Me mode, Mercury auto-approved any `run_command` whose
+ segments matched the read-only allowlist, including `find *`. `find`'s
+ `-exec`/`-execdir`/`-ok`/`-okdir`/`-delete` (and `-fprint`/`-fprintf`/
+ `-files0-from`) are side-effectful, so an authenticated chat/dashboard user
+ who could steer the model into `run_command` could run an arbitrary
+ subprocess or write files without the approval prompt.
+- **Affected:** ≤ 1.1.13 (full flag coverage: ≤ 1.2.7).
+- **Patched:** 1.2.2 (`e5dc012`); 1.3.0 (`f465e6f`, `6a6c6bd`).
+- **References:** #71, #77, #101, #110, #102. CWE-285. High,
+ `CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H`.
+- **Workaround for unpatched versions:** none short of disabling the shell
+ capability; upgrade.
+
+### B. Safe-read auto-approval bypass via shell redirection
+
+- **Summary:** Auto-approved read-only commands (`cat`, `echo`, `grep`, …)
+ were executed through `shell: true` with redirection operators intact, so
+ `cat README.md > out.txt` or `echo X >> file` wrote files in the workspace
+ without a prompt.
+- **Affected:** ≤ 1.1.13. **Patched:** 1.2.2 (`e5dc012`).
+- **References:** #72, #82, #109. CWE-863 / CWE-266. High,
+ `CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:N/I:H/A:L` (#82; #72 gives `C:N/I:H/A:N`).
+
+### C. Safe-read auto-approval bypass via shell expansion (env disclosure, scope escape)
+
+- **Summary:** The safe-read check ran on the literal command string before
+ the shell expanded it, so `echo $SECRET` disclosed environment variables and
+ `head $HOME/…` / `cat ~/…` / `$'…'` read files outside the approved scopes
+ without a prompt.
+- **Affected:** ≤ 1.2.7. **Patched:** 1.3.0 (PR #128: `00108b9`, `6651188`).
+- **References:** #76, #80, #95. CWE-200 / CWE-266. High
+ (`CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:N/A:N`; reporter rated #80 High,
+ #76 and #95 Medium on the same vector).
+
+### D. Delegated sub-agents bypassed shell/filesystem approvals
+
+- **Summary:** `SubAgent.run()` unconditionally enabled allow-all on the shared
+ permission manager and granted a read/write temp scope at `/`, so a prompt
+ routed through `delegate_task` executed `run_command` and file writes without
+ the approval prompt the direct path shows.
+- **Affected:** ≤ 1.1.13. **Patched:** 1.2.2 (`e5dc012`).
+- **Known limitation after the patch:** workers share the parent's permission
+ manager; a worker tool call that coincides with an internal-channel turn of
+ the main agent (which enables allow-all for that turn) is auto-approved.
+ Tracked in ROADMAP P2.2 (immutable per-agent permission context).
+- **References:** #75, #99. CWE-285. High,
+ `CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H`.
+
+### E. Sub-agent `allowedTools` not enforced at runtime
+
+- **Summary:** `delegate_task` accepted an `allowedTools` list but
+ `SubAgent.run()` handed the model the full tool registry, so a child
+ restricted to `read_file` could still call `run_command`, file-mutation
+ tools, `list_agents` and `stop_agent` (and halt sibling agents).
+- **Affected:** ≤ 1.2.7. **Patched:** 1.3.0 (`0f5fe78`).
+- **Known limitation after the patch:** no ownership check on `stop_agent`;
+ orchestration tools still exposed to children that set no `allowedTools`
+ (ROADMAP P1.12).
+- **References:** #74, #97, #98. CWE-285. Reporter rated #74 Medium
+ (`CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:L/I:H/A:H`) but #97/#98 High
+ (`AV:N … C:H/I:H/A:H`); High is the defensible choice for the class because
+ it exposed `run_command` and file mutation, not only sibling halts.
+
+### F. `github_api` forwarded `GITHUB_TOKEN` to attacker-chosen hosts
+
+- **Summary:** `githubRequest()` treated any `path` beginning with `http` as a
+ full URL and still attached the bearer token, so a model-driven
+ `github_api` call could send the host's GitHub token to an arbitrary server.
+- **Affected:** ≤ 1.2.7. **Patched:** 1.3.0 (`cc5b879` PR #129 confines
+ requests to `api.github.com`; `71a662f` PR #130 requires https).
+- **References:** #81 (closed 2026-09-22). CWE-918 / CWE-200. High,
+ `CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:C/C:H/I:H/A:N`.
+- The reporter referenced CVE-2026-26322, which is OpenClaw's; request a new
+ CVE if wanted.
+
+### Also eligible for advisories (no identifier was cited by the reporter)
+
+| Issue | Class | Patched | Commit |
+|---|---|---|---|
+| #105 | Writes followed in-scope symlinks outside approved scopes | 1.3.0 | `757cdd8` |
+| #73 | `/bg <command>` skipped `checkShellCommand` | 1.3.0 | `efb8a45` |
+| #100 | Telegram members could reach `install_skill` → shell | 1.3.0 | `8160bff` |
+| #106 | Skill names could escape the skills root | 1.3.0 | `8806b29` |
+| #107, #108 | `fetch_url` SSRF | 1.2.3 (guard), 1.3.0 (`599450a` #121, `337e0a7` #124) | see `ssrf-108-response.md` |
+
+## 4. Still open after this pass (not "fixed-but-open")
+
+- #103 — auto-approved helpers resolve executables from a mutable `PATH`
+ (ROADMAP P2.2 PATH pinning + argv lane).
+- #104 — hardlink alias read bypass (ROADMAP P1.12 `nlink>1` prompt).
+
+## 5. Checklist for the maintainer
+
+1. Enable private vulnerability reporting (see §0.2).
+2. Merge/release 1.3.1 so the `find -exec` test and the git-helper fix are on a tag.
+3. Post the §2 comments; close #71 #77 #101 #72 #82 #76 #80 #75 #99; leave #74 open.
+4. Create advisories A–F from §3 (GitHub assigns GHSA IDs; optionally request CVEs);
+ add the issue links as references and credit @YLChen-007. Do not touch the
+ OpenClaw advisories.
+5. Optionally reply on #81, #95, #97, #98, #102, #105, #109, #110 pointing at the
+ published advisory so the reporter can update their own records.