Closes consolidated findings from wave-audit (critic + security + architect):
SECURITY HIGH:
H1 path escape — Brain::load rejects absolute mcp_server paths +
any containing '..'; canonicalize + starts_with(root) assertion;
new Error::PathEscape variant.
H2 brain name validation + clobber refuse — regex ^[a-z][a-z0-9_-]{0,63}$
enforced at Brain::load; adapters refuse to overwrite existing
mcpServers[name] with NameConflict (unless same content).
H3 symlink reject at canonicalize — std::fs::symlink_metadata()
called before canonicalize; Error::BrainIsSymlink with resolved
target path; prevents USB → $HOME pivot.
CRITIC HIGH:
#1 rusqlite dep deleted (zero uses in src/, pulls C toolchain).
#3 BrainPaths memory/artifacts/manifests now Option<String>
(only mcp_server required; schema no longer lies about contract).
CRITIC MEDIUM:
#1 _primitives/_rust/keisei/src/paths.rs (new, 23 LOC) — SSoT for
$KEISEI_HOME/$HOME resolver; config.rs and claude_code.rs
delegate instead of duplicating 7-line block.
#2 canonicalize error preserves io::Error via new Error::BrainLoad
{ path, source } with #[source] attribute.
#5 fsx::write_atomic_json rewrite via tempfile::NamedTempFile
+ persist — Windows-safe, cross-fs-fallback handling.
New module split (Constructor Pattern): brain.rs (104 → 122) now a
thin orchestrator over brain_validate.rs (108 LOC) which owns
symlink-reject / canonicalize-root / read-manifest / validate-schema
/ validate-name / check-relative-in-root / canonicalize-in-root.
Deps: regex = { workspace = true }, tempfile = "3" (runtime).
Workspace-level regex = "1.10" added.
MANIFEST.toml [primitive.keisei] deps updated.
Tests: 11 pre-existing + 5 adversarial:
- manifest_with_absolute_mcp_server_rejected — proves /usr/bin/python3
CANNOT land in settings.json (PathEscape + marker absent asserts)
- manifest_with_parent_traversal_rejected — ../../etc/passwd rejected
- manifest_with_invalid_name_rejected — 'claude-ide!' rejected
- brain_path_is_symlink_rejected — USB → $HOME pivot blocked
- attach_refuses_to_clobber_existing_mcp_entry — NameConflict on diff
All 16 pass.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
||
|---|---|---|
| .. | ||
| _rust | ||
| templates | ||
| design-scrape.sh | ||
| figma-tokens.sh | ||
| frontend-inspect.sh | ||
| harden-base.sh | ||
| kei-ci-lint.sh | ||
| kei-docs-scaffold.sh | ||
| kei-sleep-queue.sh | ||
| kei-sleep-setup.sh | ||
| kei-sleep-sync.sh | ||
| live-preview.sh | ||
| log-ship.sh | ||
| MANIFEST.toml | ||
| metrics-scrape.sh | ||
| provision-hetzner.sh | ||
| provision-vultr.sh | ||
| README.md | ||
| screenshot-decode.sh | ||
| tomd.sh | ||
_primitives — first-class building blocks
_primitives/ holds standalone utilities that agents, hooks, and skills
(including /compose-solution) depend on. Unlike _blocks/ (behavioral
markdown) or _manifests/ (agent TOML), primitives are executable shell
programs installed at $HOME/.claude/agents/_primitives/ by install.sh.
Current primitives
| Primitive | Purpose | Invocation |
|---|---|---|
tomd.sh |
Universal non-native-format → markdown converter (PDF, DOCX, XLSX, PPTX, CSV, images, code). | ~/.claude/agents/_primitives/tomd.sh <file> |
tomd.sh is ported from the KeiAgent project (user's personal CLI
predecessor) bin/keiagent-tomd — same format matrix, KeiSeiKit-style
error tags ([tomd]), configurable cache directory (KEISEI_TOMD_CACHE).
Hook integration
hooks/tomd-preread.sh is a PreToolUse(Read) hook that auto-redirects
Claude to the converted markdown when a Read targets .docx / .doc / .xlsx / .pptx / .csv. Cached under $KEISEI_TOMD_CACHE (default
/tmp/keisei-tomd-cache).
/compose-solution discovery
Phase 3 prior-art sweep greps _primitives/ alongside _blocks/,
_manifests/, skills/, _bridges/, hooks/. If a user task involves
file-format parsing, the meta-composer surfaces tomd automatically —
reuse over rewrite (RULE "No Patching").