feat(install): copy _primitives/ + build Rust workspace; register agent-fork-logger + site-wysiwyd hooks

This commit is contained in:
Parfii-bot 2026-04-21 21:33:11 +08:00
parent 1b382b7fca
commit 7acacc8fb7
2 changed files with 88 additions and 6 deletions

View file

@ -203,6 +203,16 @@ fi
if ! command -v pandoc >/dev/null 2>&1; then
warn "pandoc not found — tomd primitive will fail on .docx/.pptx. Install: brew install pandoc"
fi
# Soft-warn on playwright — frontend primitives (design-scrape, live-preview,
# mock-render) need the Playwright browser driver. Not used by the core fleet.
if ! command -v playwright >/dev/null 2>&1 && ! command -v npx >/dev/null 2>&1; then
warn "playwright/npx not found — frontend primitives (design-scrape, live-preview, mock-render) will fail. Install: npm i -g playwright && playwright install chromium"
fi
# Soft-warn on sqlite3 CLI — kei-ledger / kei-migrate embed rusqlite, so the
# CLI is optional. Only surfaced so users can manually inspect the ledger DB.
if ! command -v sqlite3 >/dev/null 2>&1; then
warn "sqlite3 CLI not found — kei-ledger/kei-migrate work without it (rusqlite embedded). Install if you want manual DB inspection: brew install sqlite"
fi
# --- create target dirs -----------------------------------------------------
say "creating directories"
@ -237,12 +247,40 @@ backup_dir "$AGENTS_DIR/_blocks"
cp -f "$KIT_DIR/_blocks/"*.md "$AGENTS_DIR/_blocks/"
# --- copy primitives (overwrite; primitives are SSoT from kit) -------------
# Shell primitives live at _primitives/*.sh, Rust primitives under
# _primitives/_rust/ (Cargo workspace). The Rust workspace is copied wholesale
# but the compile artefacts (target/) are excluded — we rebuild locally.
if [[ -d "$KIT_DIR/_primitives" ]]; then
say "copying primitives -> $AGENTS_DIR/_primitives/"
backup_dir "$AGENTS_DIR/_primitives"
cp -f "$KIT_DIR/_primitives/"*.sh "$AGENTS_DIR/_primitives/" 2>/dev/null || true
cp -f "$KIT_DIR/_primitives/README.md" "$AGENTS_DIR/_primitives/" 2>/dev/null || true
chmod +x "$AGENTS_DIR/_primitives/"*.sh 2>/dev/null || true
if [[ -d "$KIT_DIR/_primitives/_rust" ]]; then
say " copying Rust primitive workspace (excluding target/)"
mkdir -p "$AGENTS_DIR/_primitives/_rust"
# Copy workspace manifest + each crate source, skip target/
cp -f "$KIT_DIR/_primitives/_rust/Cargo.toml" "$AGENTS_DIR/_primitives/_rust/"
if [[ -f "$KIT_DIR/_primitives/_rust/Cargo.lock" ]]; then
cp -f "$KIT_DIR/_primitives/_rust/Cargo.lock" "$AGENTS_DIR/_primitives/_rust/"
fi
for crate_dir in "$KIT_DIR/_primitives/_rust/"*/; do
[ -d "$crate_dir" ] || continue
crate_name="$(basename "$crate_dir")"
[ "$crate_name" = "target" ] && continue
mkdir -p "$AGENTS_DIR/_primitives/_rust/$crate_name"
# Copy Cargo.toml + src/ + tests/ (if present)
cp -f "$crate_dir/Cargo.toml" "$AGENTS_DIR/_primitives/_rust/$crate_name/" 2>/dev/null || true
if [[ -d "$crate_dir/src" ]]; then
mkdir -p "$AGENTS_DIR/_primitives/_rust/$crate_name/src"
cp -rf "$crate_dir/src/"* "$AGENTS_DIR/_primitives/_rust/$crate_name/src/" 2>/dev/null || true
fi
if [[ -d "$crate_dir/tests" ]]; then
mkdir -p "$AGENTS_DIR/_primitives/_rust/$crate_name/tests"
cp -rf "$crate_dir/tests/"* "$AGENTS_DIR/_primitives/_rust/$crate_name/tests/" 2>/dev/null || true
fi
done
fi
fi
# --- copy bridges (overwrite; templates are SSoT from kit) -----------------
@ -295,13 +333,19 @@ fi
# $HOOKS_DIR is shared with other kits — back up each KeiSeiKit-owned hook
# individually rather than the whole directory, so foreign hooks are not
# dragged into .bak-TIMESTAMP snapshots on every re-run.
# Discover hooks dynamically from $KIT_DIR/hooks/*.sh so new hooks land
# automatically without editing install.sh.
say "copying hooks -> $HOOKS_DIR/"
for h in assemble-agents.sh assemble-validate.sh no-hand-edit-agents.sh tomd-preread.sh; do
[ -f "$KIT_DIR/hooks/$h" ] || continue
hook_count=0
for hook_src in "$KIT_DIR/hooks/"*.sh; do
[ -f "$hook_src" ] || continue
h="$(basename "$hook_src")"
backup_file "$HOOKS_DIR/$h"
cp -f "$KIT_DIR/hooks/$h" "$HOOKS_DIR/$h"
cp -f "$hook_src" "$HOOKS_DIR/$h"
chmod +x "$HOOKS_DIR/$h"
hook_count=$((hook_count+1))
done
say " installed $hook_count hook(s)"
# --- copy skills -----------------------------------------------------------
if [[ -d "$KIT_DIR/skills" ]]; then
@ -329,6 +373,28 @@ if [[ ! -x "$AGENTS_DIR/_assembler/target/release/assemble" ]]; then
exit 2
fi
# --- build Rust primitives workspace (8 crates) ----------------------------
# Offline-first like the assembler. Failure here is non-fatal: the fleet and
# shell primitives still work without the 8 Rust binaries.
if [[ -d "$AGENTS_DIR/_primitives/_rust" && -f "$AGENTS_DIR/_primitives/_rust/Cargo.toml" ]]; then
say "building Rust primitive workspace (8 crates, cargo build --release)"
if ! ( cd "$AGENTS_DIR/_primitives/_rust" && cargo build --workspace --release --offline ) 2>/tmp/keiseikit-primitives-offline.log; then
say " offline build failed — fetching deps from crates.io"
if ! ( cd "$AGENTS_DIR/_primitives/_rust" && cargo build --workspace --release ); then
warn "Rust primitive workspace build failed; fleet still functional without binaries"
warn " see log: /tmp/keiseikit-primitives-offline.log"
fi
fi
# Report which binaries built successfully.
built=0
for bin in kei-ledger kei-migrate kei-changelog ssh-check firewall-diff mock-render visual-diff tokens-sync; do
if [[ -x "$AGENTS_DIR/_primitives/_rust/target/release/$bin" ]]; then
built=$((built+1))
fi
done
say " $built / 8 Rust primitive binaries available"
fi
# --- generate .md agents in-place ------------------------------------------
say "generating agent .md files (--in-place)"
AGENT_ROOT="$AGENTS_DIR" "$AGENTS_DIR/_assembler/target/release/assemble" --in-place
@ -397,8 +463,9 @@ else
NEXT STEP: merge settings-snippet.json into ~/.claude/settings.json
==========================================================================
KeiSeiKit ships 4 hooks (assemble-agents, assemble-validate, no-hand-edit, tomd-preread).
To activate them, merge entries from:
KeiSeiKit ships 6 hooks (assemble-agents, assemble-validate, no-hand-edit,
tomd-preread, agent-fork-logger, site-wysiwyd-check). To activate them,
merge entries from:
$KIT_DIR/settings-snippet.json
into your:
$SETTINGS_FILE

View file

@ -1,5 +1,5 @@
{
"_comment": "Merge these entries into your ~/.claude/settings.json under the matching keys. If you already have PostToolUse/PreToolUse arrays, append the objects below to them instead of overwriting.",
"_comment": "Merge these entries into your ~/.claude/settings.json under the matching keys. If you already have PostToolUse/PreToolUse arrays, append the objects below to them instead of overwriting. install.sh --activate-hooks automates the merge and de-dupes by hooks[].command.",
"hooks": {
"PostToolUse": [
{
@ -8,6 +8,11 @@
{
"type": "command",
"command": "~/.claude/hooks/assemble-agents.sh"
},
{
"type": "command",
"command": "~/.claude/hooks/site-wysiwyd-check.sh",
"statusMessage": "site-wysiwyd drift check..."
}
]
}
@ -40,6 +45,16 @@
"statusMessage": "tomd pre-read auto-convert check..."
}
]
},
{
"matcher": "Agent",
"hooks": [
{
"type": "command",
"command": "~/.claude/hooks/agent-fork-logger.sh",
"statusMessage": "agent-fork-logger (RULE 0.12)..."
}
]
}
]
}