Skip to content

feat(server): let the operator select a playbook at session start - #84

Merged
sourcehawk merged 4 commits into
mainfrom
feat/session-playbook-select
Aug 25, 2026
Merged

feat(server): let the operator select a playbook at session start#84
sourcehawk merged 4 commits into
mainfrom
feat/session-playbook-select

Conversation

@sourcehawk

@sourcehawk sourcehawk commented Aug 25, 2026

Copy link
Copy Markdown
Owner

Description

Closes #83

Operators can now start a session against a specific playbook (a release-verification runbook, say) instead of the guided investigation flow, which was the only entrypoint and dragged every non-triage session through routing and capture_offer. The new-investigation form gains an optional Playbook picker; the chosen id flows preflight → Investigationmetadata.jsonsessions.Optionsprompts.Env, and the opening prompt points the agent at that playbook with no closing playbook. Sessions started this way skip wiki capture entirely; that's deliberate, since the closing offer only makes sense for investigations.

Changes

  • Optional Playbook dropdown on the new-investigation form, fed by GET /api/playbooks with locked launcher metas and disabled entries filtered out (frontend/lib/playbook-select.ts).
  • POST /api/preflight accepts playbook, rejects unknown, disabled, or locked (launcher meta) ids with 400, and records it on the investigation; InvestigationDTO and metadata.json carry playbook so it survives restarts.
  • prompts.Build honours Env.Playbook: it becomes suggested-entrypoint-playbook, suggested-closing-playbook is omitted, and the strategies tool bullet tells the agent the operator chose it and there is no closing playbook.
  • Session header shows playbook: <id> for such sessions.
  • Signal-watch and auto-mode spawns are untouched and keep the default flow.

Testing

TDD throughout: prompts tests for both prompt shapes; server tests for accept / unknown / disabled / locked / unset on preflight and a metadata.json round-trip; a sessions test that Options.promptEnv() forwards the id; vitest for the catalog filter and for the form submitting with and without a selection. make test, make lint, and cd frontend && npm run typecheck all pass. Worth poking at manually: start a session with a user playbook selected and confirm the agent's first call is walk_playbook on that id and that no capture_offer walk follows summarize.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Sh4mHX8JUzvrdpWg56iZth

The new-investigation form gains an optional Playbook picker fed by GET /api/playbooks (locked launcher metas and disabled entries filtered out). When set, the id flows preflight → Investigation → metadata.json → sessions.Options → prompts.Env, and the opening prompt points the agent at that playbook instead of the profile's guided investigation flow, skipping the closing playbook as well. Preflight rejects unknown or disabled ids with 400. The session header shows the selected playbook, and it survives launcher restarts via persisted metadata.

Signal-watch spawns are unchanged and keep the default flow.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Sh4mHX8JUzvrdpWg56iZth
Copilot AI lite review requested due to automatic review settings August 25, 2026 23:17

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Server-side preflight validation currently allows locked (system/meta) playbook ids to be explicitly selected, which can unintentionally bypass the intended guided/default flow semantics.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Adds an optional “start session on a specific playbook” entrypoint that bypasses the default guided investigation flow (and its closing capture_offer) when an operator explicitly selects a playbook at session start. This threads the chosen playbook id from the UI → preflight validation → investigation persistence/DTOs → session options → prompt construction, so sessions can reliably resume with the intended entrypoint.

Changes:

  • Extend prompt generation to honor Env.Playbook by setting only suggested-entrypoint-playbook and omitting the closing playbook guidance when a playbook is explicitly selected.
  • Carry playbook through server preflight, investigation snapshot/restore (metadata.json), and session option → prompt env projection.
  • Add frontend playbook picker + catalog filtering/sorting utilities, with vitest coverage.
File summaries
File Description
prompts/prompts.go Adds Env.Playbook and adjusts prompt output/tool guidance when set.
prompts/prompts_test.go Adds tests for prompt shape with and without a selected playbook.
internal/sessions/session.go Adds Options.Playbook and centralizes prompt env building via promptEnv().
internal/sessions/session_test.go Tests that Options.promptEnv() forwards the selected playbook (and cluster id).
internal/server/persist.go Persists playbook in metadata.json and restores it on load.
internal/server/manager.go Adds Playbook to investigation state, DTO, snapshot, and session start options.
internal/server/manager_test.go Tests playbook round-trips via persisted metadata restore.
internal/server/handlers.go Validates optional playbook on preflight and records it on the investigation.
internal/server/handlers_start_test.go Adds preflight tests for accept/unknown/disabled/unset playbook behavior.
frontend/lib/playbook-select.ts Filters/sorts playbooks for the picker (drops locked/disabled/broken).
frontend/lib/playbook-select.test.ts Tests picker filtering and ordering.
frontend/lib/api.ts Adds playbook to preflight request type and investigation DTO type.
frontend/components/investigations/SessionView.header.tsx Displays selected playbook id in the session header when present.
frontend/components/investigations/InvestigationForm.tsx Fetches playbook catalog, renders optional picker, submits selected id.
frontend/components/investigations/InvestigationForm.test.tsx Adds tests for playbook picker visibility/filtering and submission behavior.
frontend/app/(main)/investigations/new/page.tsx Forwards optional playbook field into api.preflight call.
docs/content/investigations.md Documents the new optional playbook picker behavior.
Review details
  • Files reviewed: 17/17 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread internal/server/handlers.go
The UI already hides launcher metas from the picker, but the server accepted them, so a crafted request could start a session on capture_offer or select investigation with the closing playbook suppressed. Enforce the same contract server-side.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Sh4mHX8JUzvrdpWg56iZth
Copilot AI review requested due to automatic review settings August 25, 2026 23:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The change is consistently plumbed end-to-end (UI → preflight validation → persistence → session/prompt) with targeted tests covering default and override behaviors.

Review details
  • Files reviewed: 17/17 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

…-select

# Conflicts:
#	prompts/prompts.go
#	prompts/prompts_test.go
Copilot AI review requested due to automatic review settings August 25, 2026 23:40

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The end-to-end plumbing (UI → preflight validation → persistence → prompt behavior) is implemented coherently and is backed by targeted server/frontend/prompt tests, with only a minor comment/doc mismatch noted.

Review details
  • Files reviewed: 17/17 changed files
  • Comments generated: 1
  • Review effort level: Lite

Comment on lines +7 to +8
// can't be walked. Investigation-typed playbooks sort first, then
// other types, each group by id.
…-select

# Conflicts:
#	internal/sessions/session.go
#	internal/sessions/session_test.go
Copilot AI review requested due to automatic review settings August 25, 2026 23:50

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The change is end-to-end (UI → API validation → persistence → prompt shaping) with targeted Go and frontend tests covering the new behavior and edge cases.

Review details
  • Files reviewed: 17/17 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

@sourcehawk
sourcehawk merged commit 8623cc4 into main Aug 25, 2026
6 checks passed
@sourcehawk
sourcehawk deleted the feat/session-playbook-select branch August 25, 2026 23:55
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.

Let the operator pick a playbook when starting an investigation session

2 participants