Skip to content

feat(init): install SessionStart auto-bootstrap hook (self-arming agents)#33

Merged
ThinkOffApp merged 2 commits into
mainfrom
feat/session-bootstrap-init
Jul 14, 2026
Merged

feat(init): install SessionStart auto-bootstrap hook (self-arming agents)#33
ThinkOffApp merged 2 commits into
mainfrom
feat/session-bootstrap-init

Conversation

@ThinkOffApp

Copy link
Copy Markdown
Owner

Problem

After every IDE/CLI restart the room agent sat idle until Petrus manually typed /loop check rooms into the session. The 07-12 ask: "codewatchy should make that happen automatically" — restarts should leave the agent self-armed, for every IAK user, not just this machine.

Lineage

This productizes the prototype that has been running in production on the Mac mini since 2026-07-12 (~/.claude/scripts/session-bootstrap.sh + a hand-edited SessionStart entry in ~/.claude/settings.json). Same mechanism, de-petrus-ified.

Design

scripts/session-bootstrap.sh — a SessionStart hook script. It reads the hook stdin JSON (source: startup|resume|compact), counts backlog lines in the poller's notification file, and emits {"suppressOutput": true, "hookSpecificOutput": {"hookEventName": "SessionStart", "additionalContext": ...}} instructing the agent to:

  1. arm a persistent Monitor on the notification file if TaskList lacks one (instant wake, never a duplicate),
  2. read + act on + clear any backlog that arrived while no session was running,
  3. run the self-paced room loop with a fallback ScheduleWakeup (~1500s),
  4. on compact, verify via TaskList instead of re-arming blindly.

Parameterization follows the existing script conventions (check-rooms-hook.sh, claudemb-poll.sh): IAK_NEW_FILE env, else config poller.notification_file, else /tmp/iak-new-messages.txt (the poller default / NOTIFY_FILE_DEFAULT); IAK_HANDLE env, else poller.handle; IAK_CONFIG_JSON env, else ide-agent-kit.json found relative to the script (repo root, or project root when installed into .claude/scripts/). Any failure degrades to no output + exit 0 — it can never block session start.

Wiring, both existing install paths:

  • ide-agent-kit init --ide claude-code (and antigravity): copies the script into .claude/scripts/ and merges the hook into .claude/settings.json via the new src/claude-settings.mjs helper. Note: "Config already exists" no longer aborts init — every downstream step is individually guarded, so re-running init upgrades an existing install (that's how current users get this hook).
  • scripts/install.sh: registers SessionStart alongside the existing UserPromptSubmit + Stop hooks in the same python ensure_hook merger.

Idempotency & safety

  • Dedup by exact command string across all entries for the event (same semantics as install.sh's ensure_hook) — running init or the installer twice adds nothing.
  • Unrelated hooks, permissions, and unknown settings keys are never touched; merge is additive only.
  • settings.json.bak backup taken before the first mutating write (repo .bak convention); no backup churn on no-op runs.

Test coverage (test/session-bootstrap.test.mjs, 14 tests)

  • hook emits valid SessionStart JSON for startup, compact, empty stdin, and non-JSON stdin
  • backlog count reflects notification-file contents; missing file → 0
  • config-file values (poller.notification_file, poller.handle) are honored; env overrides beat config
  • settings merge: preserves unrelated hooks/permissions, idempotent, keeps pre-existing SessionStart entries, .bak backup on change, creates file when missing (temp-dir fixtures)
  • end to end: iak init --ide claude-code twice in a temp cwd → exactly one hook entry

npm test: 134 pass, 0 fail. bash -n clean on both shell scripts; install.sh's python merger exercised standalone against a fixture (install → idempotent re-run → unrelated keys preserved → backup present).

Review

@codexmb — adversarial review requested per the cross-model PR review rule, before merge.

🤖 Generated with Claude Code

…nts)

After an IDE/CLI restart the agent sat idle until someone typed
"/loop check rooms" by hand. Ship the proven 07-12 prototype as a
product feature: a SessionStart hook that makes every fresh session
self-arm the room loop.

- scripts/session-bootstrap.sh: generic hook script. Reads the hook
  stdin JSON (source: startup|resume|compact), counts backlog in the
  poller notification file, and emits suppressed additionalContext
  telling the agent to arm a persistent Monitor on the file, read and
  clear the backlog, and keep a fallback ScheduleWakeup armed. Config
  via IAK_NEW_FILE / poller.notification_file, IAK_HANDLE /
  poller.handle, IAK_CONFIG_JSON, IAK_BOOTSTRAP_FALLBACK_SEC — same
  conventions as check-rooms-hook.sh and claudemb-poll.sh. Never blocks
  session start.
- src/claude-settings.mjs: careful settings.json hook merge (dedup by
  command, .bak backup before first write, unrelated hooks untouched),
  mirroring install.sh's ensure_hook semantics.
- bin/cli.mjs init: copies the script into .claude/scripts/ and merges
  the hook into .claude/settings.json for claude-code/antigravity.
  "Config already exists" no longer aborts init, so re-running upgrades
  existing installs; every step is guarded and idempotent.
- scripts/install.sh: registers the SessionStart hook alongside
  UserPromptSubmit + Stop, now with a settings.json.bak backup.
- test/session-bootstrap.test.mjs: hook JSON for startup/compact/empty
  and garbage stdin, backlog counting, env-over-config precedence,
  merge idempotency and preservation, and an end-to-end double-init run.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3510facf10

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread scripts/session-bootstrap.sh Outdated
Comment thread scripts/install.sh
P1 (codex, #33): the bootstrap told agents to truncate the whole
notification file - recreating the exact read-vs-append race #32 just
fixed. Instructions now direct agents to the consumed-only room_ack MCP
tool, with raw-clear only as a no-MCP fallback plus an immediate re-check.
P2: install.sh skipped hook wiring entirely when ~/.claude/settings.json
did not exist yet - fresh one-shot installs now get a minimal file created
so self-arming works on day one.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@ThinkOffApp ThinkOffApp merged commit d2e716e into main Jul 14, 2026
3 checks passed
ThinkOffApp pushed a commit that referenced this pull request Jul 14, 2026
Ships the two responsiveness features (SessionStart self-arm #33, peer-wake
watchdog #34) and refreshes the README What's-new to address all three
multi-agent pain points: unresponsive IDEs, prompting-vs-buttons, typing-over.
142 tests.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant