Skip to content

feat: ai session attach + ai_agent template overrides for start-session - #279

Closed
maximelb wants to merge 3 commits into
cli-v2from
cli-v2-ai-attach
Closed

maximelb wants to merge 3 commits into
cli-v2from
cli-v2-ai-attach

Conversation

@maximelb

Copy link
Copy Markdown
Contributor

Summary

  • Add limacharlie ai session attach for live WebSocket streaming with optional interactive chat, read-only fallback, and pretty/raw rendering.
  • Rework ai start-session so the ai_agent hive record is a starting template: every ProfileContent field (model, budgets, TTL, permission mode, allowed/denied tools, plugins, env, credentials) can be overridden per run, with hive://secret/<name> resolution for sensitive values.
  • New SDK helpers: AI.attach_session() and SessionAttachment async wrapper around the ai-sessions WebSocket protocol; AI.start_session gains keyword-only override params.
  • Adds websockets>=13.0 runtime dep and ~70 new unit tests covering WS plumbing, override merge/replace semantics, env secret resolution, CSV/KEY=VALUE parsing, and CLI registration.

Test plan

  • ./run_local_test.sh (or equivalent) passes
  • limacharlie ai session attach --id <sid> streams messages live (owner endpoint)
  • Same command as non-owner falls back to org read-only endpoint
  • --interactive surfaces tool approval + ask_user_question prompts
  • limacharlie ai start-session with --model, --env KEY=VAL, --anthropic-key hive://secret/... applies overrides on top of the hive template
  • Omitted flags leave the template untouched

🤖 Generated with Claude Code

maximelb and others added 3 commits April 18, 2026 11:15
…ive chat

Adds a new CLI subcommand that attaches to a running AI session over
WebSocket and streams messages in real time, with an optional
interactive mode that turns the terminal into a chat with the agent.

- new `limacharlie.sdk.ai_session.SessionAttachment` async helper
  wrapping the ai-sessions WebSocket protocol (prompt, interrupt,
  tool_approval_response, ask_user_question_response, heartbeat)
- `AI.attach_session()` factory on the SDK, selecting the
  owner-interactive or org-scoped read-only endpoint
- `limacharlie ai session attach --id <sid> [--interactive]
  [--read-only] [--raw] [--no-history]` command with colour-coded
  pretty printing and transparent 403 fallback to the read-only
  org endpoint when the caller is not the session owner
- interactive loop surfaces tool approval requests and
  `ask_user_question` messages as live prompts
- `websockets>=13.0` added as a runtime dependency
- 39 unit tests covering URL derivation, send/receive plumbing,
  read-only enforcement, message rendering, and CLI registration

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Reworks `limacharlie ai start-session` so the ai_agent hive record is a
starting template and every profile field can be overridden from the
CLI for a single run.

Adds override flags matching the full server ProfileContent schema:

  * --model, --max-turns, --max-budget-usd, --task-budget-tokens,
    --ttl-seconds, --one-shot/--no-one-shot, --permission-mode,
    --allowed-tools, --denied-tools, --plugin (repeatable)
  * --env KEY=VALUE (repeatable) - merged with the template's
    environment; override wins on key collisions
  * --anthropic-key, --lc-api-key, --lc-uid - credential overrides
    that accept literal values or "hive://secret/<name>" refs

Scalars and lists REPLACE the template value when passed.  Environment
MERGES.  Omitted flags leave the template untouched.  Override values
that start with hive://secret/ are resolved before sending, so secrets
never appear in argv.

SDK: AI.start_session grows keyword-only override parameters.

Adds 30 new unit tests covering every override path: scalar replace,
list replace, env merge with collision, env secret resolution on
overrides, credential literal vs secret-ref overrides, CSV parsing
edge cases (empty list vs None), --env KEY=VALUE parsing validation,
and a help-text assertion that every flag is documented.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
# Conflicts:
#	limacharlie/commands/_ai_attach.py
#	limacharlie/commands/ai.py
#	limacharlie/sdk/ai_session.py
#	tests/unit/test_ai_session_attach.py
#	tests/unit/test_sdk_ai_sessions.py
@maximelb

Copy link
Copy Markdown
Contributor Author

Superseded — cli-v2 already contains both commits from this branch (tree is byte-identical after merging cli-v2). Closing as redundant.

@maximelb maximelb closed this Apr 21, 2026
@maximelb
maximelb deleted the cli-v2-ai-attach branch April 21, 2026 01:32
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