KeiSeiKit-1.0/install/lib-agents.sh
KeiSei84 98b6f9ab64
Some checks failed
CI (Forgejo Actions — self-hosted runner on Mac, host mode) / preflight (pull_request) Has been cancelled
CI (Forgejo Actions — self-hosted runner on Mac, host mode) / vps-smoke (pull_request) Has been cancelled
CI (Forgejo Actions — self-hosted runner on Mac, host mode) / rust-primitives (map[crates:frustration-matrix,kei-frustration-loop,kei-skill-importer,kei-projects-index,kei-projects-watcher,kei-gdrive-import,kei-leak-matrix,kei-skills,kei-gateway,kei-cron-scheduler,kei-export-trajectories,kei-backend-daytona,kei-d… (pull_request) Has been cancelled
CI (Forgejo Actions — self-hosted runner on Mac, host mode) / rust-primitives (map[crates:kei-compute-baremetal,kei-compute-vultr,kei-compute-linode,kei-compute-digitalocean,kei-svc-systemd,kei-llm-bridge-mlx name:hosted-sleep-compute]) (pull_request) Has been cancelled
CI (Forgejo Actions — self-hosted runner on Mac, host mode) / rust-primitives (map[crates:kei-diff,kei-scheduler,kei-watch,kei-prune,kei-discover,kei-brain-view,kei-hibernate,kei-ledger-sign,kei-fork name:wave13-15]) (pull_request) Has been cancelled
CI (Forgejo Actions — self-hosted runner on Mac, host mode) / rust-primitives (map[crates:kei-git-gitea,kei-git-forgejo,kei-git-gitlab,kei-git-bitbucket,kei-memory-sled,kei-memory-redis,kei-memory-postgres,kei-memory-sqlite,kei-auth-google,kei-auth-apple,kei-auth-magiclink,kei-auth-webauthn,kei-notify-slack,kei-n… (pull_request) Has been cancelled
CI (Forgejo Actions — self-hosted runner on Mac, host mode) / rust-primitives (map[crates:kei-ledger,kei-migrate,kei-changelog,kei-memory,kei-store,kei-conflict-scan,kei-refactor-engine,kei-graph-check,kei-shared,kei-dna-index,kei-pet name:core]) (pull_request) Has been cancelled
CI (Forgejo Actions — self-hosted runner on Mac, host mode) / rust-primitives (map[crates:kei-machine-probe,kei-llm-ollama,kei-llm-llamacpp,kei-llm-mlx,kei-llm-router,kei-model name:llm-stack]) (pull_request) Has been cancelled
CI (Forgejo Actions — self-hosted runner on Mac, host mode) / rust-primitives (map[crates:kei-router,kei-sage,kei-task,kei-chat-store,kei-crossdomain,kei-search-core,kei-content-store,kei-social-store,kei-curator,kei-auth,kei-artifact name:mcp-lbm]) (pull_request) Has been cancelled
CI (Forgejo Actions — self-hosted runner on Mac, host mode) / rust-primitives (map[crates:keisei,kei-forge,kei-runtime,kei-runtime-core,kei-atom-discovery,kei-agent-runtime,kei-capability,kei-provision,kei-entity-store,kei-pipe,kei-cache,kei-spawn,kei-replay name:atom-substrate]) (pull_request) Has been cancelled
fix(install): make fresh install actually complete + ship tamagotchi
Root causes found by reproducing a clean install from keigit:

1. PROFILE_PRIMS resolved only inside check_prereqs → unbound for
   --no-execute (plan showed 0 prims for every profile) and silently
   empty for --skip-prereqs. Now resolved unconditionally in install.sh
   before any reader (SSoT).

2. Every profile (even minimal, advertised "no Rust compile") fell back
   to a 5-15 min `cargo build --workspace` because no prebuilt release
   binaries exist. Auto-set KEI_SKIP_RUST for profiles with no rust
   primitives → minimal installs in ~18s (assembler only). cargo stays a
   hard prereq because the agent assembler always compiles.

3. The assembler aborted the WHOLE install on any single bad manifest
   (set -e). generate_agents is now tolerant: bad manifests print FAIL
   but hooks/skills/settings still land. Commit-time validate stays strict.

4. Data bugs that broke the assembler:
   - duplicate [taxonomy] table in _roles/{auditor,merger}.toml
   - fal-ai-runner handoff → keimd-expert (not shipped in kit)
   - infra-implementer-cicd forbidden_domain literal `${{ secrets.NAME }}`
     collided with assembler ${{ }} placeholder detection

5. Metadata: KeiSei84 (nonexistent GitHub org) → KeiSeiLab/KeiSeiKit-1.0
   across plugin manifests, bootstrap, README, docs, Cargo/npm metadata.
   .claude-plugin/{plugin,marketplace}.json 0.16.0 → 0.38.0. SECURITY.md
   supported version 0.14.x → 0.38.x.

feat: ship KeiSei tamagotchi statusline into the kit
   - scripts/keisei-pet{,-update}.sh (portable, state under ~/.claude/pet/)
   - install copies them to ~/.claude/scripts/
   - settings-snippet adds statusLine (set-if-absent, never clobbers an
     existing one) + 4 pet-update hooks (prompt/rust_write/github_block/sleep)

Verified: clean minimal install RC=0, zero FAIL, 38 agents + 52 hooks +
68 skills, settings valid, statusLine wired, pet renders, idempotent re-run.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-21 00:14:17 +08:00

112 lines
4.5 KiB
Bash

# shellcheck shell=bash
# lib-agents.sh — manifest copy + assembler build + .md agent generation.
#
# Generic manifests: overwrite-skip policy (never stomp user's existing
# manifests). Assembler source: always refreshed. Build: offline-first with
# online fallback. Agents: written in-place by the built assemble binary.
#
# Requires: say / err from lib-log.sh.
# Requires: backup_dir from lib-backup.sh.
# Reads globals: $KIT_DIR, $AGENTS_DIR.
# Copy _manifests/*.toml from the kit; skip any target file that already
# exists (user manifests are sacred). Also copies _templates/*.template
# when present.
install_manifests() {
say "copying generic manifests -> $AGENTS_DIR/_manifests/ (skip if exists)"
local copied=0 skipped=0 f name t has_templates=0
for f in "$KIT_DIR/_manifests/"*.toml; do
name="$(basename "$f")"
if [[ -f "$AGENTS_DIR/_manifests/$name" ]]; then
skipped=$((skipped+1))
else
cp "$f" "$AGENTS_DIR/_manifests/$name"
copied=$((copied+1))
fi
done
say " copied $copied, skipped $skipped (already present)"
for t in "$KIT_DIR/_templates/"*.template; do
[ -f "$t" ] && { has_templates=1; break; }
done
if [ "$has_templates" = "1" ]; then
say "copying specialist template"
backup_dir "$AGENTS_DIR/_templates"
cp -f "$KIT_DIR/_templates/"*.template "$AGENTS_DIR/_templates/"
fi
}
# Refresh _blocks/*.md — SSoT is the kit, always overwritten after backup.
install_blocks() {
say "copying shared blocks -> $AGENTS_DIR/_blocks/"
backup_dir "$AGENTS_DIR/_blocks"
cp -f "$KIT_DIR/_blocks/"*.md "$AGENTS_DIR/_blocks/"
}
# Refresh _roles/*.toml — SSoT is the kit, always overwritten after backup.
# Manifests reference these via tool_role/agent_role keys; without them the
# assembler fails with "read role .../<name>.toml: No such file".
install_roles() {
if ! compgen -G "$KIT_DIR/_roles/"*.toml > /dev/null; then
return 0
fi
say "copying agent roles -> $AGENTS_DIR/_roles/"
mkdir -p "$AGENTS_DIR/_roles"
backup_dir "$AGENTS_DIR/_roles"
cp -f "$KIT_DIR/_roles/"*.toml "$AGENTS_DIR/_roles/"
}
# Refresh _capabilities/<bucket>/<name>/text.md — capability snippets
# referenced by manifests' capabilities[] list. SSoT is the kit; full tree
# copy after backup. Without this the assembler fails with "read capability
# X::Y at .../_capabilities/X/Y/text.md: No such file".
install_capabilities() {
if [ ! -d "$KIT_DIR/_capabilities" ]; then
return 0
fi
say "copying capability snippets -> $AGENTS_DIR/_capabilities/"
mkdir -p "$AGENTS_DIR/_capabilities"
backup_dir "$AGENTS_DIR/_capabilities"
cp -Rf "$KIT_DIR/_capabilities/"* "$AGENTS_DIR/_capabilities/"
}
# Copy the Rust assembler source (Cargo.toml + src/*.rs + .gitignore if any).
# Caller should run build_assembler afterwards.
copy_assembler_source() {
say "copying assembler source"
backup_dir "$AGENTS_DIR/_assembler"
cp -f "$KIT_DIR/_assembler/Cargo.toml" "$AGENTS_DIR/_assembler/"
cp -f "$KIT_DIR/_assembler/src/"*.rs "$AGENTS_DIR/_assembler/src/"
if [[ -f "$KIT_DIR/_assembler/.gitignore" ]]; then
cp -f "$KIT_DIR/_assembler/.gitignore" "$AGENTS_DIR/_assembler/"
fi
}
# Build the assembler (release, offline-first, online fallback).
# Exits 2 if the binary is missing after a reported success (disk failure).
build_assembler() {
copy_assembler_source
say "building Rust assembler (cargo build --release, offline first)"
if ! ( cd "$AGENTS_DIR/_assembler" && cargo build --release --offline ) 2>/tmp/keiseikit-cargo-offline.log; then
say "offline build failed — fetching deps from crates.io"
( cd "$AGENTS_DIR/_assembler" && cargo build --release )
fi
if [[ ! -x "$AGENTS_DIR/_assembler/target/release/assemble" ]]; then
err "build succeeded but binary not found at $AGENTS_DIR/_assembler/target/release/assemble"
exit 2
fi
}
# Run the built assembler in --in-place mode to write the agent .md files.
# Tolerant by design: a handful of stale/broken manifests (e.g. a handoff to
# an agent not shipped in this profile, or an un-substituted template field)
# must NOT abort the whole install — hooks, skills, settings still need to
# land. The assembler prints per-manifest FAIL lines for visibility, and the
# commit-time assembler-validate gate stays strict, so genuine breakage is
# still caught at authoring time.
generate_agents() {
say "generating agent .md files (--in-place)"
if ! AGENT_ROOT="$AGENTS_DIR" "$AGENTS_DIR/_assembler/target/release/assemble" --in-place; then
warn "some agent manifests failed to assemble (see FAIL lines above) — continuing install"
fi
}