<!-- task=m-iop-agent-cli-runtime/21+13,17,20_project_log_sink plan=0 tag=API -->

# Project Log Event Sink and S12 Closure

## For the Implementing Agent

Fill every implementation-owned section in `CODE_REVIEW-cloud-G08.md`, including actual command output. Keep active files in place and report ready for review; only the review agent finalizes. Record blockers and resume conditions in evidence fields without asking the user or creating control-plane artifacts.

## Background

The record and journal packets leave the standalone host without an `agenttask.EventSink`, deterministic WORK_LOG projection, or full S12 evidence. This closure maps events, proves retry/parallel/archive behavior, and records actual contract paths.

## Roadmap Targets

- Milestone: `agent-roadmap/phase/automation-runtime-bridge/milestones/iop-agent-cli-runtime.md`
- Milestone link: [Milestone 문서](agent-roadmap/phase/automation-runtime-bridge/milestones/iop-agent-cli-runtime.md)
- Task ids:
  - `project-logs`: project-local event/log plus WORK_LOG loop/attempt/locator and exactly-once archive lifecycle
- Completion mode: check-on-pass

## Analysis

### Files Read

- `packages/go/agenttask/ports.go`
- `packages/go/agenttask/types.go`
- `agent-contract/inner/iop-agent-cli-runtime.md`
- `agent-task/m-iop-agent-cli-runtime/17+13_project_log_records/plan_local_G08_0.log`
- `agent-task/m-iop-agent-cli-runtime/17+13_project_log_records/code_review_cloud_G08_0.log`

### SDD Criteria

S12 requires deterministic WORK_LOG loop/attempt/locator evidence, 11 retries/follow-ups for one task, an independent parallel task, separate archive ordinals, stable identities, and terminal-only exactly-once archive/cleanup. This child closes those rows over predecessors 17 and 18.

### Verification Context

Use fresh focused tests, the projectlog/agentstate race run, vet, formatting, and `git diff --check` from the original plan.

### Test Coverage Gaps

- No durable `agenttask.EventSink` or deterministic WORK_LOG projection exists.
- No integration fixture proves the complete S12 retry/parallel/archive matrix.

### Symbol References

None. The adapter implements the existing `agenttask.EventSink`.

### Split Judgment

API-3 and API-4 form the closure because the S12 matrix consumes both event projection and archive behavior. This child exclusively owns `Roadmap Targets`.

### Scope Rationale

Do not parse provider raw output, duplicate task-manager transitions, mutate `agent-task/**`, change the Python dispatcher, or add UI rendering.

### Final Routing

- evaluation_mode: `first-pass`
- finalizer: `finalize-task-policy.sh pair`
- build: `local-G08`, basis `local-fit`, filename `PLAN-local-G08.md`
- review: `cloud-G08`, basis `official-review`, filename `CODE_REVIEW-cloud-G08.md`
- large_indivisible_context: `false`
- positive loop risks: `CAS/archive crash windows`, `retry/parallel identity matrix` (count `2`)
- recovery signals: rework `0`, evidence-integrity failure `false`
- capability-gap evidence: none

## Implementation Checklist

- [ ] Implement the agenttask EventSink adapter and deterministic WORK_LOG projection without raw provider output.
- [ ] Prove the S12 11-retry, parallel-task, ordinal, crash-window, and exactly-once archive matrix under the race detector.
- [ ] Update the standalone contract with actual S12 source/test paths and verification evidence.
- [ ] Fill implementation-owned sections in CODE_REVIEW-*-G??.md with actual implementation notes and verification output.

### [API-3] Add Event Sink and WORK_LOG Projection

#### Problem

The standalone host has no durable `agenttask.EventSink` implementation or human-readable timeline.

#### Solution

Normalize manager events into journal records. Project a stable chronological WORK_LOG view with loop, attempt, role/stage, result, and locators while keeping raw streams external. Make projection a pure function of the durable journal.

#### Modified Files and Checklist

- [ ] `apps/agent/internal/projectlog/sink.go` — implement the event adapter and projection.
- [ ] `apps/agent/internal/projectlog/sink_test.go` — cover mapping and deterministic output.

#### Test Strategy

Write `TestSinkMapsEveryEventType` and `TestTimelineProjectionIsStableAndRedacted`.

#### Verification

```bash
go test -count=1 ./apps/agent/internal/projectlog -run 'TestSink|TestTimeline'
```

Expected: normalized event types are handled with stable ordering.

### [API-4] Prove the S12 Matrix

#### Problem

No Go test reproduces the required 11-attempt loop, independent parallel loop, archive ordinal separation, and terminal closure.

#### Solution

Add one integration fixture that appends 11 failed/retry/follow-up attempts for task A while task B advances independently, restarts stores between selected phases, closes both in different orders, and asserts distinct exactly-once archives plus retained locator identity. Record actual S12 source/test entries in the standalone contract.

#### Modified Files and Checklist

- [ ] `apps/agent/internal/projectlog/store_test.go` — add `TestS12LoopParallelArchiveMatrix`.
- [ ] `agent-contract/inner/iop-agent-cli-runtime.md` — add S12 actual source/test entries.

#### Test Strategy

The named fixture must use real files plus concurrent goroutines and run under race.

#### Verification

```bash
go test -count=1 -race ./apps/agent/internal/projectlog -run TestS12LoopParallelArchiveMatrix
```

Expected: one archive per terminal task, independent ordinals, 11 preserved attempts, and no duplicates.

## Dependencies and Execution Order

Predecessors `13_agent_domain`, `17+13_project_log_records`, and `20+13,17_project_log_journal` must each produce a same-group active or archived `complete.log`.

## Modified Files Summary

| File | Item |
|------|------|
| `apps/agent/internal/projectlog/sink.go` | API-3 |
| `apps/agent/internal/projectlog/sink_test.go` | API-3 |
| `apps/agent/internal/projectlog/store_test.go` | API-4 |
| `agent-contract/inner/iop-agent-cli-runtime.md` | API-4 |

## Final Verification

```bash
gofmt -w apps/agent/internal/projectlog/*.go
go test -count=1 ./apps/agent/internal/projectlog
go test -count=1 -race ./apps/agent/internal/projectlog ./packages/go/agentstate
go vet ./apps/agent/internal/projectlog
git diff --check
```

Expected: fresh and race suites, vet, formatting, and diff checks pass with stable S12 evidence. After completing all changes, fill implementation-owned sections in `CODE_REVIEW-*-G??.md`.
