Skip to content

Add -S/--session-or-attach and 'session attach --create' flags#116

Open
yochum wants to merge 7 commits into
rockorager:mainfrom
yochum:feature/attach-or-create-session
Open

Add -S/--session-or-attach and 'session attach --create' flags#116
yochum wants to merge 7 commits into
rockorager:mainfrom
yochum:feature/attach-or-create-session

Conversation

@yochum

@yochum yochum commented Apr 20, 2026

Copy link
Copy Markdown

Summary

  • Adds -S, --session-or-attach <name> — attach to an existing session, create one if missing.
  • Adds --create / -c to prise session attach — same behavior via the subcommand surface.
  • Extracts a shared resolveSessionTarget helper; -s, session attach, and both new flags all funnel through it (eliminates two parallel implementations of validate + existence-check).
  • Tightens session attach to validate session names. Malformed names now error with the existing validation message instead of "Session not found" — small behavior change, strictly more informative.
  • Updates prise --help and prise session --help to document the new flags.
  • Adds 7 unit tests for resolveSessionTarget covering the full mode × existence matrix plus validation failures (first tests in main.zig).

Motivation

Today prise session attach <name> errors if missing and prise -s <name> errors if existing — so users have to shell-wrap the two to get a "attach or create" command. -S and --create close that gap.

Test plan

  • zig build succeeds
  • zig build test — 246/246 passing (baseline 239 + 7 new)
  • Manual smoke of all positive and negative paths:
    • -s <new> / -s <existing> / -s <invalid>
    • session attach <existing> / <missing> / <invalid> / no-arg falls back to most recent
    • -S <existing> / -S <missing> / -S <invalid> / -S with no arg
    • session attach --create <existing> / <missing> / -c alias
    • Conflict: -S foo session attach bar errors

Notes

  • Uses a test-only sessions_dir_override global so tests can point sessionExists at std.testing.tmpDir() instead of the real ~/.local/state/prise/sessions.
  • rename / delete still skip name validation (latent gap, out of scope).

yochum added 7 commits April 19, 2026 20:52
Adds a ResolveMode enum and a shared helper that validates a session
name, checks whether the session exists on disk, and populates either
attach_session or new_session_name on ParseResult based on mode. No
callers yet; existing -s and 'session attach' paths will be migrated
in follow-up commits.
Replaces the inline validation/existence/SessionAlreadyExists logic in
the -s/--session branch of parseArgs with a single call to
resolveSessionTarget(.create_only). Error messages are preserved
byte-for-byte. Also widens the errdefer to cover attach_session now that
the helper may populate either field.
Replaces the inline sessionExists check in the 'session attach <name>'
branch with resolveSessionTarget(.attach_only). Adds name validation
to attach (malformed names now error with the validation message
instead of the less helpful 'Session not found'). The no-name path
continues to use findMostRecentSession unchanged.
New top-level flag that attaches to an existing session with the given
name or creates a new one if missing. Routes through resolveSessionTarget
with .attach_or_create. Extends the -s/session conflict check to cover
-S, and forwards new_session_name from session subcommand results so
P2.2 (--create) can populate it.
When present on 'session attach', routes through resolveSessionTarget
with .attach_or_create so the named session is attached if it exists
and created otherwise. Accepted before or after the name argument.
Without a name, errors with a dedicated MissingArgument message
(distinct from the no-arg 'attach' which falls back to findMostRecentSession).
Adds -S/--session-or-attach to the top-level options list and
mentions --create/-c on the 'session attach' usage line. Column
widths adjusted so everything lines up.
Adds 7 test cases covering the full matrix:
- create_only x {missing, existing}
- attach_only x {existing, missing}
- attach_or_create x {existing, missing}
- invalid name (empty, too long, contains space, contains slash)

Splits sessionExists into sessionExistsInDir(dir, name) plus a public
wrapper that resolves the real sessions dir from HOME, and introduces
a test-only sessions_dir_override so tests can point the resolver at
std.testing.tmpDir() without touching the user's state dir.
@yochum

yochum commented Apr 20, 2026

Copy link
Copy Markdown
Author

Note: rename / delete skip session name validation. I can follow up with a PR to tighten those up.

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