Files
kebab/tasks/p9/p9-fb-18-cli-ask-session-repl.md
altair823 4f96b1b01d feat(kebab-app + kebab-cli): p9-fb-18 CLI ask --session multi-turn
도그푸딩 item 14 — CLI 에서도 multi-turn 가능하도록 `kebab ask
--session <id>` 추가. p9-fb-17 의 ChatSessionRepo 위에 build, 첫 호출
세션 자동 생성, 이후 호출이 prior turns 를 history 로 받아 follow-up.
external AI integration (Claude Code skill / MCP) 도 같은 facade 로
stateful 대화 가능.

## 핵심 변경

- **`App::ask_with_session(session_id, query, opts) -> Answer`** —
  load session header → list_turns 로 prior history → 빌드 retriever
  stack (lexical / vector / hybrid 같은 분기) → `RagPipeline::ask_
  with_history` 호출 → 첫 호출이면 `chat_sessions` row 자동 생성
  (title = first_question_title) → `chat_turns` 새 row append.
- **`App::first_question_title(question)`** helper — `trim() + nfc()
  + 40 chars cap`, fallback `"untitled"`. unicode-normalization
  workspace dep 재사용.
- **`App::blake3_truncate(input)`** helper — `blake3(session_id ||
  ":" || turn_index)` 의 첫 16 byte 를 u128 으로, format!{:032x} 로
  32-hex `turn_id`.
- **`ask_with_session_with_config`** facade — CLI 진입점.
- **CLI `--session <id>` flag** — `Cmd::Ask` 의 `session: Option<
  String>` field, handler 가 None 이면 `ask_with_config` (기존
  단발), Some(id) 면 `ask_with_session_with_config` 호출.
- **에러 정책**: session create / turn append 실패 시 warn 로그
  남기고 answer 는 그대로 반환 — 사용자가 답변 받은 컴퓨트를 잃지
  않음. 영속성 실패가 답변 응답을 가로막지 않는 conservative shape.

## 테스트

- `App::first_question_title` 3 unit (trim + cap, empty → untitled,
  korean NFD → NFC)
- `App::blake3_truncate` 1 unit (deterministic + distinct across
  varying session/index)
- 워크스페이스 전체 `cargo test --workspace --no-fail-fast -j 1` exit 0
- `cargo clippy --workspace --all-targets -- -D warnings` clean

## 문서

- README `kebab ask` 행: `--session` 안내 + chat_sessions 자동 생성
  + `kebab reset --data-only` wipe 안내
- README **외부 AI 통합** 절: Claude Code skill 이 `--session` 으로
  multi-turn 가능하다는 한 문장 추가
- HANDOFF entry
- spec status planned → in_progress

## Out of scope (spec deviation)

- `--repl` (stdin loop) — spec 명시되어 있으나 stdin fixture 부담
  으로 deferral. 별도 후속 task 또는 `--session` 사용자 경험 회신
  후 결정.
- session list / show / delete 관리 명령 (spec 의 Out of scope).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-03 06:20:16 +00:00

61 lines
2.1 KiB
Markdown

---
phase: P9
component: kebab-cli + kebab-app
task_id: p9-fb-18
title: "CLI ask --session / --repl"
status: in_progress
depends_on: [p9-fb-15, p9-fb-17]
unblocks: []
contract_source: ../../docs/superpowers/specs/2026-04-27-kebab-final-form-design.md
contract_sections: [§7 RAG, §externalAI]
source_feedback: p9-dogfooding-feedback.md item 14
---
# p9-fb-18 — CLI ask multi-turn
## Goal
CLI 에서도 conversation history 사용. `--session <id>` (영속) + `--repl` (in-memory loop).
## Allowed dependencies
- 기존 kebab-cli deps + p9-fb-17 의 ChatSessionRepo.
## Public surface
CLI:
```
kebab ask "Q" [--session <id>] [--repl]
```
- 둘 다 없음: 단발 (현 동작 유지).
- `--session foo`: SQLite chat_sessions 에 `foo` 가 있으면 history 로 사용 + 새 turn append. 없으면 새 session 생성.
- `--repl`: stdin loop. 각 question 후 답변 출력. `:q` 또는 EOF 종료. `--session` 결합 시 영속, 아니면 in-memory.
- `--repl` 에서 빈 줄 + `:` 명령: `:q` (quit), `:new` (session reset, in-memory), `:save <id>` (현 in-memory → session 저장 + 이후 영속).
`--json` 모드: line-delimited 답변 JSON. 각 줄 `answer.v1` (이미 정의), `conversation_id` + `turn_index` 필드 추가 (p9-fb-15 의 schema bump 와 함께).
## Behavior contract
- session 없이 단발 호출은 wire schema `answer.v1``conversation_id` 필드 = null. 호환.
- `--repl` 에서 Ctrl-C → graceful exit. session 저장된 상태면 finalized.
## Test plan
| kind | description |
|------|-------------|
| unit | `--session foo` 첫 호출 → 새 session 생성 |
| unit | `--session foo` 두번째 호출 → 이전 turn history 로 prompt 빌드 |
| integration | `--repl` stdin "Q1\nQ2\n:q\n" → 2 답변 + clean exit |
## DoD
- [ ] `cargo test -p kebab-cli` 통과
- [ ] `answer.v1` schema 갱신 (conversation_id / turn_index 추가, optional)
- [ ] README **명령** 표 + **외부 AI 통합** 절 — `--session` 으로 Claude Code skill / MCP 가 multi-turn 가능
## Out of scope
- session list / show / delete CLI 명령 (P+)
- session export (markdown / JSON dump)