<!-- task=m-command-first-operator-workflow/03+02_market_status_scenario plan=0 tag=CLI -->

# Plan - Market Status Scenario

## 이 파일을 읽는 구현 에이전트에게

이 plan은 구현 지시서이며, 구현 완료 전 active `CODE_REVIEW-*-G??.md`의 구현 에이전트 소유 섹션을 실제 내용과 검증 출력으로 채운다. 이 task는 `02+01_import_cli_scenario` 완료 뒤 구현한다. 최종 판정, archive 이동, `complete.log` 작성은 code-review-skill 전용이다. 사용자-only blocker가 있으면 review stub의 `사용자 리뷰 요청`을 채우고 멈춘다.

## 배경

현재 `market_data_status_query`는 저장된 market data를 조회하지만, 같은 scenario 안에서 import가 먼저 되었는지는 보장하지 않는다. 이 작업은 import action 후 instruments/bars를 조회하는 command-first status scenario로 바꾼다. PASS 시 `market-status-scenario` 기능 Task를 완료 대상으로 삼는다.

## 사용자 리뷰 요청 흐름

구현 중 사용자-only blocker는 active review stub의 `사용자 리뷰 요청` 섹션에 기록한다. code-review가 이를 검증하고 실제 `USER_REVIEW.md` 작성 여부를 결정한다.

## Roadmap Targets

- Milestone: `agent-roadmap/phase/operator-surface/milestones/command-first-operator-workflow.md`
- Task ids:
  - `market-status-scenario`: imported market data를 CLI/YAML로 조회할 수 있다.
- Completion mode: check-on-pass

## 분석 결과

### 읽은 파일

- `agent-test/local/rules.md`
- `agent-test/local/operations-smoke.md`
- `agent-test/local/api-smoke.md`
- `agent-test/local/worker-smoke.md`
- `agent-ops/rules/project/domain/operations/rules.md`
- `agent-roadmap/current.md`
- `agent-roadmap/phase/operator-surface/PHASE.md`
- `agent-roadmap/phase/operator-surface/milestones/command-first-operator-workflow.md`
- `apps/cli/internal/operator/scenario.go`
- `apps/cli/internal/operator/runner.go`
- `apps/cli/internal/operator/runner_market_test.go`
- `apps/cli/internal/operator/runner_error_test.go`
- `apps/cli/internal/operator/client_test.go`
- `apps/cli/internal/operator/output.go`
- `apps/cli/internal/operator/handoff_test.go`
- `apps/cli/testdata/operator/market_data_status_query.yaml`
- `apps/cli/testdata/operator/expected/market_data_status_query.jsonl`
- `apps/cli/testdata/operator/headless_validation.md`
- `bin/dev`

### 테스트 환경 규칙

- test_env: `local`.
- Matched profile: `operations-smoke` for CLI fixtures; `api-smoke`/`worker-smoke` are covered by predecessor rail and not changed here unless implementation touches API/worker.
- Applied commands: `go test ./apps/cli/...`, `go run ./apps/cli/cmd/alt operator scenario validate ...`, `git diff --check`.

### 테스트 커버리지 공백

- Existing `TestRunScenarioMarketDataStatus` covers list instruments/bars but not import-before-read.
- Handoff tests validate expected JSONL shape but do not require `instrument_count`/`bar_count` until the fixture is updated.
- Typed unavailable/error key is covered generically by runner tests; add explicit status scenario test with `ErrorInfo{Code:"unavailable"}` for import or list.

### 심볼 참조

- Renamed/removed symbols: none.

### 분할 판단

- Shared task group: `agent-task/m-command-first-operator-workflow/`.
- This subtask directory is `03+02_market_status_scenario`; predecessor index `02` is `02+01_import_cli_scenario`.
- Predecessor completion status at plan creation: missing active/archive `complete.log`; implementation waits for predecessor completion.

### 범위 결정 근거

- Excludes implementing `import_daily_bars`; predecessor owns it.
- Excludes backtest start/poll/result; `04+02_backtest_runtime_flow` owns it.
- Excludes UI layout and wireframes; handoff stays command evidence only.

### 빌드 등급

- build=`cloud-G07`, review=`cloud-G07`: command workflow and machine-readable terminal output are the success surface.

## 의존 관계 및 구현 순서

- Wait for `02+01_import_cli_scenario` complete.log.
- Update status fixture and fake API tests after import action is available.

## 구현 체크리스트

- [ ] [CLI-1] Update `market_data_status_query.yaml` to run import before instrument/bar status reads.
- [ ] [CLI-2] Update expected JSONL and tests to require import counts, instrument count, bar count, and typed unavailable/error keys. 검증: `alt operator scenario validate/run` 또는 동등한 command가 instrument/bar count와 typed unavailable/error key를 출력한다.
- [ ] [CLI-3] Update handoff matrix and CLI dev hints so the command-first status scenario is discoverable.
- [ ] [CLI-4] Run CLI verification and `git diff --check`.
- [ ] CODE_REVIEW-*-G??.md의 구현 에이전트 소유 섹션을 실제 구현 내용과 검증 출력으로 채운다. 이 항목이 완료되기 전에는 구현이 완료된 것이 아니다.

## [CLI-1] Import Before Status Reads

### 문제

[apps/cli/testdata/operator/market_data_status_query.yaml](/config/workspace/alt/apps/cli/testdata/operator/market_data_status_query.yaml:1) reads instruments/bars but does not import first. That makes the scenario a generic status query rather than an imported market data status workflow.

### 해결 방법

Prepend an `import_daily_bars` step after `hello`, using the same KIS symbol/date range as the import smoke. Keep the existing `list_instruments` and `list_bars` steps so status still reports counts.

Before (`market_data_status_query.yaml:9`):

```yaml
  - id: hello
    action: hello
```

After:

```yaml
  - id: hello
    action: hello
  - id: import_kr_daily_bars
    action: import_daily_bars
    request:
      provider: kis
      selector_kind: watchlist
      market: kr
      venue: krx
      symbols: ["005930"]
      from_yyyymmdd: "20240527"
      to_yyyymmdd: "20240528"
```

### 수정 파일 및 체크리스트

- [ ] `apps/cli/testdata/operator/market_data_status_query.yaml`: add import step.
- [ ] `apps/cli/testdata/operator/expected/market_data_status_query.jsonl`: add import output line and step count.

### 테스트 작성

Existing handoff JSONL parser test should catch malformed fixture. Add a runner test that loads this fixture and asserts fake API call order: import, list instruments, list bars.

### 중간 검증

```bash
go run ./apps/cli/cmd/alt operator scenario validate --file apps/cli/testdata/operator/market_data_status_query.yaml
```

Expected: `scenario=market_data_status_query status=valid`.

## [CLI-2] Status Evidence Tests

### 문제

[apps/cli/internal/operator/runner_market_test.go](/config/workspace/alt/apps/cli/internal/operator/runner_market_test.go:34) verifies status count output for list/read only. It does not prove `import_daily_bars` counts and typed unavailable keys survive the scenario run.

### 해결 방법

Update fake API support from predecessor if needed, then adjust `TestRunScenarioMarketDataStatus` to expect import, list, and bars output. Add a second test where import or list returns `ErrorInfo{Code:"unavailable"}` and the step expects `status: error`, proving the JSON/text output includes `error_code`.

### 수정 파일 및 체크리스트

- [ ] `apps/cli/internal/operator/runner_market_test.go`: update happy path and add unavailable typed error case.
- [ ] `apps/cli/internal/operator/client_test.go`: expose last import request if not already available.
- [ ] `apps/cli/internal/operator/handoff_test.go`: assert expected JSONL step lines include import count keys for status scenario.

### 테스트 작성

Write focused runner tests:

- `TestRunScenarioMarketDataStatusImportsBeforeReads`
- `TestRunScenarioMarketStatusTypedUnavailable`

### 중간 검증

```bash
go test ./apps/cli/internal/operator -run 'MarketDataStatus|MarketStatusTypedUnavailable|Handoff' -count=1
```

Expected: tests pass and output key assertions are covered.

## [CLI-3] Handoff Discoverability

### 문제

[apps/cli/testdata/operator/headless_validation.md](/config/workspace/alt/apps/cli/testdata/operator/headless_validation.md:29) describes `market_data_status_query` as list-only. [bin/dev](/config/workspace/alt/bin/dev:20) points to this scenario, so the developer hint should match the new import-before-read behavior.

### 해결 방법

Update matrix text for `market_data_status_query` to mention `ImportDailyBarsResponse.instrument_count`, `ImportDailyBarsResponse.bar_count`, `ListInstrumentsResponse.instruments`, and `ListBarsResponse.bars`. Keep UI dependency deferred.

### 수정 파일 및 체크리스트

- [ ] `apps/cli/testdata/operator/headless_validation.md`: update checked fields and scenario description.
- [ ] `bin/dev`: no path change expected; update text only if it says read-only.

### 테스트 작성

No new test beyond handoff coverage; existing doc/fixture tests validate referenced paths.

### 중간 검증

```bash
go test ./apps/cli/internal/operator -run Handoff -count=1
```

Expected: handoff tests pass.

## [CLI-4] Verification

### 문제

Fixture drift can make the scenario validate but leave expected JSONL stale.

### 해결 방법

Run CLI tests, validate the scenario, and diff check.

### 수정 파일 및 체크리스트

- [ ] No extra files.

### 테스트 작성

No additional tests.

### 중간 검증

```bash
git diff --check
```

Expected: no warnings.

## 수정 파일 요약

| 파일 | 항목 |
|------|------|
| `apps/cli/testdata/operator/market_data_status_query.yaml` | CLI-1 |
| `apps/cli/testdata/operator/expected/market_data_status_query.jsonl` | CLI-1 |
| `apps/cli/internal/operator/runner_market_test.go` | CLI-2 |
| `apps/cli/internal/operator/client_test.go` | CLI-2 |
| `apps/cli/internal/operator/handoff_test.go` | CLI-2 |
| `apps/cli/testdata/operator/headless_validation.md` | CLI-3 |
| `bin/dev` | CLI-3 |

## 최종 검증

```bash
go test ./apps/cli/... -count=1
go run ./apps/cli/cmd/alt operator scenario validate --file apps/cli/testdata/operator/market_data_status_query.yaml
git diff --check
```

Expected: all commands exit 0.

모든 코드 변경 완료 후 반드시 `CODE_REVIEW-*-G??.md`의 구현 에이전트 소유 섹션을 채운다. 이 파일 작성이 구현의 마지막 단계다.
