<!-- task=m-iop-agent-cli-runtime/15+13_host_lifecycle plan=0 tag=API -->

# Standalone Host Lifecycle Boundary

## For the Implementing Agent

Filling implementation-owned sections in `CODE_REVIEW-cloud-G06.md` is mandatory. Run every verification command, paste actual notes/output, leave the active pair in place, and report ready for review. Finalization belongs only to the code-review skill. If blocked, record exact blocker evidence and resume conditions without asking the user, creating stop files, archiving, or writing `complete.log`.

## Background

After the application domain is registered, the standalone process needs an application-owned lifecycle around shared runtime dependencies. This packet owns ordered start, rollback, cancellation, idempotent reverse stop, and narrow application ports without composing concrete adapters.

## Analysis

### Files Read

- `agent-task/m-iop-agent-cli-runtime/13_agent_domain/plan_cloud_G09_0.log`
- `agent-task/m-iop-agent-cli-runtime/13_agent_domain/code_review_cloud_G09_0.log`
- `packages/go/agenttask/ports.go`
- `packages/go/agenttask/types.go`

### SDD Criteria

This compatibility-preserving prerequisite supplies lifecycle seams required by S10, S11, S12, and S15 without claiming their Evidence Map rows.

### Verification Context

Use fresh focused tests, a package race run, vet, formatting, and `git diff --check` from the original packet. No external runner is needed.

### Test Coverage Gaps

- No application owner coordinates runtime components.
- No test proves ordered start, partial rollback, cancellation, reverse stop, repeated stop, or retained errors.

### Symbol References

None. New application-owned symbols do not rename shared APIs.

### Split Judgment

The lifecycle boundary has a stable contract and deterministic PASS tests. It depends only on `13_agent_domain`; concrete bootstrap composition remains in child 16.

### Scope Rationale

Do not implement concrete providers, command parsing, project-log serialization, socket transport, subprocess ownership, or bootstrap adapter wiring.

### Final Routing

- evaluation_mode: `isolated-reassessment`
- finalizer: `finalize-task-policy.sh pair`
- build closures: all `true`; grade scores `1/2/1/1/1`; route `local-fit`, `local-G06`, filename `PLAN-local-G06.md`
- review closures: all `true`; grade scores `1/2/1/1/1`; route `official-review`, `cloud-G06`, filename `CODE_REVIEW-cloud-G06.md`
- large_indivisible_context: `false`
- positive loop risks: `temporal_state`, `concurrent_consistency` (count `2`)
- recovery signals: rework `0`, evidence-integrity failure `false`
- capability-gap evidence: none

## Implementation Checklist

- [x] Implement and test the standalone host lifecycle and dependency ports without duplicating shared runtime behavior.
- [x] Run fresh focused, race, vet, formatting, and diff verification.
- [x] Fill implementation-owned sections in CODE_REVIEW-*-G??.md with actual implementation notes and verification output.

### [API-2] Add the Host Lifecycle Boundary

#### Problem

Shared task ports expose host-neutral runtime behavior, but no application owner coordinates those dependencies.

#### Solution

Add an application-owned `host` package with small `Component` and runtime-control ports. Start components in declared order, cancel on failure, roll back only started components, stop in reverse order, preserve error identity, and make repeated stop safe.

#### Modified Files and Checklist

- [x] `apps/agent/internal/host/host.go` — implement lifecycle ownership.
- [x] `apps/agent/internal/host/ports.go` — define narrow application-facing runtime/status ports.
- [x] `apps/agent/internal/host/host_test.go` — cover order, rollback, cancellation, repeated stop, and error retention.

#### Test Strategy

Write `TestHostStartStopOrdering`, `TestHostStartRollback`, and `TestHostStopIsIdempotent` with deterministic fake components and an ordered trace.

#### Verification

```bash
go test -count=1 ./apps/agent/internal/host
go test -count=1 -race ./apps/agent/internal/host
```

Expected: both commands pass without races.

## Dependencies and Execution Order

Predecessor `13_agent_domain` must produce a same-group active or archived `complete.log`.

## Modified Files Summary

| File | Item |
|------|------|
| `apps/agent/internal/host/host.go` | API-2 |
| `apps/agent/internal/host/ports.go` | API-2 |
| `apps/agent/internal/host/host_test.go` | API-2 |

## Final Verification

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

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