Skip to content

feat(project-brain): report staleness and shadowed initiatives at session start - #232

Merged
jinyeow merged 4 commits into
mainfrom
feat/project-brain-hook-followups
Sep 18, 2026
Merged

jinyeow merged 4 commits into
mainfrom
feat/project-brain-hook-followups

Conversation

@jinyeow

@jinyeow jinyeow commented Sep 18, 2026

Copy link
Copy Markdown
Owner

What

The SessionStart hook now reports two conditions it did not surface before:

  • A staleness line naming active initiatives past stale_after (first 8, oldest first, then +N more) and any STATUS.md over the size cap, emitted when a registered initiative loads.
  • A shadow notice: when an in-repo .claude/brain/ wins, it names a registered initiative that also matched the cwd but was not loaded.

Why

A 2026-09-17 brain review found three gaps. Stale STATUS.md files were invisible when no live worktree matched their glob (one was 58 days past stale_after, with two passed deadlines and no follow-up). An in-repo .claude/brain/ silently shadowed a registered initiative for at least one session and caused rework. Archived initiatives dropped out of the index because the close procedure deleted their rows. The hook and skill text close these without anyone having to remember a manual step.

Changes

  • session-start.ps1: extract registry resolution into Resolve-RegisteredInitiative; share one line-count function between the loaded-STATUS warning and the oversize scan; add Get-StaleInitiative and Format-StaleNotice; append the shadow notice (path 1) and the staleness line (path 2), each behind its own inner try/catch so a scan or resolver failure omits the line rather than dropping the loaded context.
  • Pi extension: no logic change. It shells out to the same script and forwards the context verbatim, so both lines already flow through. This adds Pester coverage that drives the real script, plus one header note.
  • Skill and contract text: the Initiative close step moves the index row into an ## Archived section with the closed date and fixes the relative paths that break when a folder moves one level deeper; new areas scaffold the section; the Loading section documents both hook lines; Codex gets a resolve-and-read shadow check; a new ADR records keeping in-repo precedence with a shadow notice, and its rejected alternatives.

Verify

  • Invoke-Pester -Path tests\project-brain-session-start.Tests.ps1, tests\pi-project-brain-autoload.Tests.ps1
  • Whole-tree Invoke-ScriptAnalyzer -Path . -Recurse -Settings .\PSScriptAnalyzerSettings.psd1 is clean.
  • Post-merge, after pulling C:\Users\jin-y\dotfiles, start a session in E:\HollardInsuranceRetail and compare the staleness line to rg -n "^stale_after:" E:\HollardInsuranceRetail\brain\initiatives\*\STATUS.md.

The hook stays fail-safe: every error path exits 0 with no output.

… SessionStart hook

Extract registry resolution into Resolve-RegisteredInitiative and share one
line-count function. When an in-repo brain wins, append a notice naming a
registered initiative that also matches the cwd but was not loaded. When a
registered initiative loads, append a line listing active initiatives past
stale_after (first 8, oldest first) and any STATUS.md over the size cap.

Both advisory paths use an inner try/catch so a scan or resolver failure can
only omit the line, never drop the loaded context. Staleness dates are injected
so tests do not depend on the clock.
…tension

The Pi before_agent_start extension shells out to session-start.ps1 and
forwards additionalContext verbatim, so the shadow and staleness lines flow
through with no logic change. Add Pester cases that drive the real script with
a fixture brain and assert both lines reach the Pi message, and note the
forwarding in the extension header.
…adow-precedence ADR

Teach the Initiative close step to move the index row into an Archived section
with the closed date and to fix the relative paths that break when a folder
moves one level deeper. New areas scaffold an empty Archived section. Document
the two new hook lines in Loading, add the Codex resolve-and-read shadow check,
and record keeping in-repo brain precedence with a shadow notice as an ADR.
The registry-resolution tests overrode only USERPROFILE to point the child at
a fixture brain. On Linux the shell derives the home dir from HOME, so the
child read the real (empty) brains.json path and the shadow and staleness
assertions failed on the Ubuntu CI job. Set both HOME and USERPROFILE at each
override site and restore both, and guard the Windows-only Volta AppData/Local
directory creation behind an IsWindows check.
@jinyeow
jinyeow merged commit 56e4e0b into main Sep 18, 2026
5 checks passed
@jinyeow
jinyeow deleted the feat/project-brain-hook-followups branch September 18, 2026 03:31
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