fix(#102): make nelson-data.py init own mission-directory creation#103
Merged
Conversation
SKILL.md previously told Claude to manually create
.nelson/missions/{stamp}_{SESSION_ID}/, the two subdirectories, and the
.active-{SESSION_ID} sidecar before running nelson-data.py init. But
cmd_init/_do_init created its *own* timestamped directory (no
SESSION_ID) and ignored Claude's. Claude saw the mismatch and abandoned
its own directory, breaking the SESSION_ID linkage and leaving an empty
orphan dir behind.
Collapse the two actors into one. The script now:
- generates an 8-char hex SESSION_ID (or accepts --session-id for
deterministic tests / known-id resumes)
- creates .nelson/missions/{stamp}_{session_id}/ with damage-reports/
and turnover-briefs/
- writes sailing-orders.json, mission-log.json, fleet-status.json
- writes .nelson/.active-{session_id} as the session marker (already
consumed by hooks/_find_mission_dir and lifecycle/_find_active_mission)
- prints the mission dir path as before (relative path, unchanged
stdout contract — session_id is the segment after the last underscore)
cmd_headless inherits this for free since it delegates to _do_init.
SKILL.md, session-hygiene.md, and structured-data.md updated to defer
to the script. Four new TestInit tests cover auto-generation, explicit
--session-id, sidecar contents, and rejection of invalid session ids
(8 lowercase hex enforced to prevent path injection via the marker
filename). All 274 tests pass (222 scripts + 52 hooks).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #102.
Problem
SKILL.mdtold Claude to manually create.nelson/missions/{stamp}_{SESSION_ID}/, the two subdirectories, and the.active-{SESSION_ID}sidecar before runningnelson-data.py init. Butcmd_init/_do_initcreated its own timestamped directory (no SESSION_ID) and ignored Claude's.Claude saw the mismatch and rationally abandoned its own dir ("The script is creating a new timestamped directory rather than using mine. I'll work with the one it created."). Result: the
.active-{SESSION_ID}sidecar pointed at an empty orphan directory, SESSION_ID-based recovery broke, and every fresh mission left a stray dir in.nelson/missions/.Approach
Collapse the two actors into one: give the script full ownership of the mission-directory contract. SKILL.md no longer does any manual mkdir work.
nelson-data.py initnow:--session-idfor deterministic tests / known-id resumes).nelson/missions/{stamp}_{session_id}/withdamage-reports/andturnover-briefs/sailing-orders.json,mission-log.json,fleet-status.json.nelson/.active-{session_id}as the session marker (already consumed byhooks/_find_mission_dirandlifecycle/_find_active_mission)session_idis the segment after the last underscorecmd_headlesspicks this up for free since it already delegates to_do_init.Why option 2 over adding
--mission-dirtoinit_do_initis already the well-tested path used bycmd_headless; interactive now takes the same route.uuidgen | cut -d- -f1, timestamp formatting, ormkdir -pdance in prose. Deterministic Python instead.damage-reports/) touch one function.Changes
Code:
nelson_data_utils.py—_generate_session_id()(8-hex viasecrets.token_hex),_is_valid_session_id()(enforces 8 lowercase hex chars; prevents path injection via the.active-<id>filename)nelson_data_lifecycle.py::_do_init— acceptssession_id=None, new dir format, writes sidecarnelson-data.py— adds--session-idoptional arg to theinitsubparserTests (all new in
test_nelson_data.py::TestInit):test_auto_generates_session_id_in_dirnametest_accepts_explicit_session_idtest_writes_active_sidecartest_rejects_invalid_session_idDocs:
SKILL.md§"Establish Mission Directory" — removed manualuuidgen/mkdir/sidecar-write instructionsreferences/damage-control/session-hygiene.md— new-session procedure now verifiesinitran instead of describing separate creationreferences/structured-data.md—initdescription updated to reflect full ownershipTest plan
skills/nelson/scripts/tests pass (71 existing + new init tests)hooks/tests pass (mission-dir discovery still works against the new sidecar)scripts/check-references.shgreen (no broken doc cross-refs)nelson-data.py initin a fresh dir produces.nelson/missions/{stamp}_{session_id}/+.nelson/.active-{session_id}with matching pathsession-resumption.mdprose still reads correctly — its existing "read.nelson/.active-{SESSION_ID}" fallback continues to work unchanged since the script now writes that file