Skip to content

feat: restore TaskCreate captain-misuse enforcement via admiral session marker#119

Merged
harrymunro merged 2 commits into
mainfrom
feat/issue-1o9-admiral-session-marker
May 8, 2026
Merged

feat: restore TaskCreate captain-misuse enforcement via admiral session marker#119
harrymunro merged 2 commits into
mainfrom
feat/issue-1o9-admiral-session-marker

Conversation

@harrymunro
Copy link
Copy Markdown
Collaborator

Summary

Restores the captain-TaskCreate enforcement that PR #116 removed, this time without false-positive rejections of the admiral's own Ctrl+T visibility tracking. Discriminates admiral from captain subagents via the hook payload's transcript_path (each subagent spawn gets a fresh transcript; admiral keeps its own).

  • session-init (SessionStart): records admiral transcript_path to .nelson/admiral.session.
  • session-check (PreToolUse on TaskCreate): rejects with wrong-ensign only in subagents / single-session mode when the payload transcript_path does not match the recorded admiral marker.
  • preflight: opportunistically backfills the marker if init ran after SessionStart fired (admiral always spawns Agents, so this is the safe fallback).
  • stand-down: best-effort marker cleanup.
  • Every uncertainty path fails open (no mission, missing marker, missing/empty transcript_path), so non-Nelson projects and edge cases stay untouched.

Depends on #116 — this branch is based off fix/issue-112-taskcreate-hook-removal. The new hook reuses the PreToolUse:TaskCreate matcher slot that #116 frees up; otherwise both mode-check and session-check would fire and the buggy mode-check would still block the admiral. If #116 lands first, retarget this PR to main (no overlap on changed lines).

Tracks nelson-1o9.

Test plan

  • pytest hooks/test_nelson_hooks.py -q → 60/60 pass (was 48; +4 TestSessionInit, +8 TestSessionCheck).
  • pytest skills/nelson/scripts -q → 280/280 pass (was 278; +2 stand-down marker-cleanup tests).
  • bash scripts/check-references.sh → all cross-references valid.
  • python3 hooks/nelson_hooks.py --help → both new subcommands listed.
  • Manual stdin smoke tests for session-init: writes marker when .nelson/ exists, no-op when it doesn't.
  • Discriminator spike (verification, not yet run): start a subagents-mode Nelson mission, spawn a captain via Agent, log payloads from a throwaway PreToolUse:TaskCreate hook, confirm captain transcript_path differs from admiral. Plan called for this before committing — flagging for reviewer because it requires a real mission run.
  • Real-mission smoke test: admiral TaskCreate allowed without wrong-ensign feedback; captain TaskCreate rejected; .nelson/admiral.session removed at stand-down; SessionStart is a no-op in non-Nelson projects.

Notes

  • Marker location: .nelson/admiral.session, project-scoped (not mission-scoped). Stand-down resolves it via mission_dir.parent.parent.
  • README enforcement-hooks table re-adds the TaskCreate row plus a new SessionStart row.
  • No changes to references/tool-mapping.md or references/standing-orders/wrong-ensign.md — existing admiral-exception language remains accurate.

harrymunro added a commit that referenced this pull request May 8, 2026
Address PR #119 review feedback on cmd_session_check:

- Mode gate now uses an explicit CAPTAIN_GATED_MODES allow-list
  (subagents, single-session). Previously any non-agent-team mode
  would reject on transcript mismatch, contradicting the docstring
  and pre-emptively gating future modes.
- Empty admiral.session marker now fails open. Previously a partially
  written or interrupted marker would mismatch every payload and
  reject everything — including the admiral.
- Share ADMIRAL_SESSION_MARKER constant via nelson_data_utils so
  hooks/ and skills/scripts/ reference one filename, not two.
- Add regression tests for both fail-open paths and two unit tests
  for the preflight backfill path (previously untested).

Tests: 64/64 hook tests, 280/280 lifecycle tests, references green.
@harrymunro harrymunro changed the base branch from fix/issue-112-taskcreate-hook-removal to main May 8, 2026 17:57
harrymunro added 2 commits May 8, 2026 14:58
…on marker

PR #116 removed the PreToolUse:TaskCreate mode-check hook because it
blanket-rejected the admiral's own Ctrl+T visibility tracking. This
reinstates enforcement properly by discriminating admiral from captain
via the hook payload's transcript_path (each subagent gets its own).

- session-init (SessionStart): records admiral transcript_path to
  .nelson/admiral.session
- session-check (PreToolUse:TaskCreate): rejects with wrong-ensign only
  when mode is subagents/single-session and the payload transcript_path
  does not match the recorded admiral marker
- preflight: opportunistically backfills the marker if init ran after
  SessionStart fired
- stand-down: best-effort marker cleanup
- All paths fail-open on uncertainty (missing marker, empty transcript,
  no mission), so non-Nelson projects and edge cases are unaffected
Address PR #119 review feedback on cmd_session_check:

- Mode gate now uses an explicit CAPTAIN_GATED_MODES allow-list
  (subagents, single-session). Previously any non-agent-team mode
  would reject on transcript mismatch, contradicting the docstring
  and pre-emptively gating future modes.
- Empty admiral.session marker now fails open. Previously a partially
  written or interrupted marker would mismatch every payload and
  reject everything — including the admiral.
- Share ADMIRAL_SESSION_MARKER constant via nelson_data_utils so
  hooks/ and skills/scripts/ reference one filename, not two.
- Add regression tests for both fail-open paths and two unit tests
  for the preflight backfill path (previously untested).

Tests: 64/64 hook tests, 280/280 lifecycle tests, references green.
@harrymunro harrymunro force-pushed the feat/issue-1o9-admiral-session-marker branch from 8a03dd9 to 7a1117c Compare May 8, 2026 18:00
@harrymunro harrymunro merged commit 5d24a69 into main May 8, 2026
6 checks passed
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