KeiSeiKit-1.0/install
KeiSei84 72bf31ba7a refactor(installer): v0.49 — extract kei-prompt cube as interactivity SSoT
Constructor Pattern fix replacing v0.47-v0.48 patch series. The "is the
user interactive?" logic was previously duplicated across 15+ places:

  bootstrap.sh        x4  ([ -t 0 ] gates on profile/onboard/launch/etc)
  install.sh          x1  (PATH wiring decision)
  install/lib-hooks.sh        (activate-hooks prompt)
  install/lib-plan.sh         (auto-confirm gate)
  install/lib-menu.sh         (skip-menu gate)
  install/lib-wizard.sh       (sleep-wizard gate)
  install/lib-onboarding.sh  x2  (onboarding_should_run + preflight retry)
  install/lib-preflight.sh    (install-tool prompt)

Every duplicated check was a chance to get curl|bash semantics wrong.
v0.47 used `[ -t 1 ]` (broke under tee'd stdout). v0.48 used `[ -t 0 ]`
(broke under curl pipe stdin). Each fix was a patch on top of the same
architectural defect: scattered truth.

ARCHITECTURAL FIX (Rule Zero — 1 cube = 1 responsibility):

  scripts/kei-prompt.sh  (NEW, ~110 LOC, public API):
    kei_is_interactive          → 0 if user is at a terminal, 1 if headless
    kei_prompt    Q [DEFAULT]   → answer or default to stdout
    kei_prompt_yn Q [Y|N]       → exit 0=yes, 1=no, with [Y/n] hint
    kei_prompt_secret Q         → no-echo input (tokens, keys)

  Truth signal: /dev/tty accessibility, with [ -t 0 ] as second-choice
  fallback. KEI_NONINTERACTIVE=1 for CI override. Same contract as the
  inline rules — now in ONE place.

  bootstrap.sh + install.sh: source the cube at the top, with self-
  contained inline fallback (mirrors the kei_is_interactive contract
  only) so they remain self-bootable even if scripts/ is missing.

  All 15+ inline gates replaced with `kei_is_interactive` calls.
  All 3 `read -r -p` prompts in installer cubes replaced with
  `kei_prompt` / `kei_prompt_yn`.

  Existing copy_pet_scripts() in lib-scaffold.sh installs scripts/*.sh
  into ~/.claude/scripts/ automatically — no install logic change needed.

WHAT THIS PREVENTS:

- Next time someone writes a prompt in installer code, the only path
  is `kei_prompt`. They CANNOT accidentally type `[ -t 0 ]` because
  there is no `[ -t 0 ]` to copy-paste anymore (except inside the
  cube itself).

- The v2 tty-interactivity-gate-guard.sh hook (added 2026-05-27)
  becomes a regression net rather than the first line of defence.

- Two real install incidents this month (May 2026, 7 prompts each)
  do not happen a third time.

VERIFIED:
- Syntax check passes on all 9 modified files + new cube.
- Primitive functions smoke-tested across 8 cases: headless,
  KEI_NONINTERACTIVE override, default fallback, yn convenience,
  re-source guard, /dev/tty available, /dev/tty open() fails.
- 2 remaining [ -t 0 ] in tree: BOTH inside kei_is_interactive
  fallback in bootstrap.sh + install.sh (single-source contract,
  not patches).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-27 16:05:44 +08:00
..
i18n feat: opt-in hook packs + stack profiles + public-prep repoint (#44) 2026-05-26 13:26:09 +07:00
launchd-templates KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
preflight fix(install,router): close 5 HIGH audit findings 2026-05-17 16:28:33 +08:00
sql fix(audit-batch-2): regressions from prev batch + 2nd-wave audit findings 2026-05-03 20:30:51 +08:00
lib-agents.sh feat: opt-in hook packs + stack profiles + public-prep repoint (#44) 2026-05-26 13:26:09 +07:00
lib-args.sh fix(install): make fresh install actually complete + ship tamagotchi (#26) 2026-05-21 01:40:50 +08:00
lib-backup.sh fix(install): backup_file mv→cp -a, install --activate-hooks больше не падает 2026-05-18 14:33:22 +08:00
lib-bin.sh KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
lib-bridges.sh KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
lib-dev-hub-datasette.sh KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
lib-dev-hub-daytona.sh KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
lib-dev-hub-forgejo-runner.sh feat(v0.45): onboarding wizard + 5 prod-install bugs (mirror of keigit 4bc40e8e) 2026-05-26 23:20:24 +08:00
lib-dev-hub-forgejo.sh feat(v0.45): onboarding wizard + 5 prod-install bugs (mirror of keigit 4bc40e8e) 2026-05-26 23:20:24 +08:00
lib-dev-hub-gdrive-import.sh KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
lib-dev-hub-mdbook.sh KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
lib-dev-hub-restic.sh KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
lib-dev-hub-zoekt.sh feat(v0.45): onboarding wizard + 5 prod-install bugs (mirror of keigit 4bc40e8e) 2026-05-26 23:20:24 +08:00
lib-frustration-bootstrap.sh KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
lib-hooks.sh refactor(installer): v0.49 — extract kei-prompt cube as interactivity SSoT 2026-05-27 16:05:44 +08:00
lib-i18n.sh feat(i18n): расширил язык-набор с 2 до 16 2026-05-17 16:51:44 +08:00
lib-launchd.sh KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
lib-log.sh style(install): KeiSei brand colors + ASCII banner in installer output (#37) 2026-05-22 16:06:17 +08:00
lib-menu.sh refactor(installer): v0.49 — extract kei-prompt cube as interactivity SSoT 2026-05-27 16:05:44 +08:00
lib-onboarding-registry.sh fix(onboarding): no crash on text input, Claude Code default, explanations (#34) 2026-05-22 13:00:59 +08:00
lib-onboarding-state.sh feat: opt-in hook packs + stack profiles + public-prep repoint (#44) 2026-05-26 13:26:09 +07:00
lib-onboarding-ui.sh feat: opt-in hook packs + stack profiles + public-prep repoint (#44) 2026-05-26 13:26:09 +07:00
lib-onboarding.sh refactor(installer): v0.49 — extract kei-prompt cube as interactivity SSoT 2026-05-27 16:05:44 +08:00
lib-packs.sh feat: opt-in hook packs + stack profiles + public-prep repoint (#44) 2026-05-26 13:26:09 +07:00
lib-pathway.sh KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
lib-plan.sh refactor(installer): v0.49 — extract kei-prompt cube as interactivity SSoT 2026-05-27 16:05:44 +08:00
lib-preflight.sh refactor(installer): v0.49 — extract kei-prompt cube as interactivity SSoT 2026-05-27 16:05:44 +08:00
lib-prereqs.sh fix(install): make fresh install actually complete + ship tamagotchi (#26) 2026-05-21 01:40:50 +08:00
lib-primitives.sh style(install): KeiSei brand colors + ASCII banner in installer output (#37) 2026-05-22 16:06:17 +08:00
lib-profile-outcome-only.sh fix(release+slices): v0.14.4 publish auth fallback + 4 fix-implementer slices 2026-05-04 00:16:48 +08:00
lib-profile.sh feat: opt-in hook packs + stack profiles + public-prep repoint (#44) 2026-05-26 13:26:09 +07:00
lib-rust-mirror.sh KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
lib-rust-prebuild.sh fix(install): make fresh install actually complete + ship tamagotchi (#26) 2026-05-21 01:40:50 +08:00
lib-rust.sh Revert "feat(mcp-server): production-ready publish path via GitHub Packages" 2026-05-03 18:04:00 +08:00
lib-scaffold.sh feat(kei message): persistent inter-session mailbox + pull-inbox hook (#40) 2026-05-23 14:06:27 +07:00
lib-skills.sh KeiSeiKit-public — clean state 2026-05-01 12:09:03 +08:00
lib-substrate.sh chore(kit): wire kei-db-contract into installer + drop final #[path] hack 2026-05-01 17:55:52 +08:00
lib-summary.sh feat(install): first-run /onboard nudge + normalize null hook matchers (#38) 2026-05-22 19:38:22 +08:00
lib-wizard.sh refactor(installer): v0.49 — extract kei-prompt cube as interactivity SSoT 2026-05-27 16:05:44 +08:00