# v8.3 PR21: Proactive + Policy Learning Delivery Split

## Objective

Deliver the remaining v8.3 scope after PR20 lifecycle in small, reviewable slices with strict fail-open behavior and budget controls.

## Scope Remaining After PR20

- Proactive extraction self-questioning (ProMem-inspired)
- Context compression action surface + telemetry (MemAct-inspired)
- Compression guideline learning loop (ACON-inspired)

## PR Slice Plan

### PR 21A — Foundation: Config + Schema + State Stores

Files:
- `src/types.ts`
- `src/config.ts`
- `openclaw.plugin.json`
- `src/storage.ts`
- `tests/config-proactive-policy.test.ts`
- `tests/storage-policy-state.test.ts`

Tasks:
1. Add config flags and limits (default-off, bounded):
   - `proactiveExtractionEnabled` (`false`)
   - `contextCompressionActionsEnabled` (`false`)
   - `compressionGuidelineLearningEnabled` (`false`)
   - `maxProactiveQuestionsPerExtraction` (`2`)
   - `maxCompressionTokensPerHour` (`1500`)
2. Add typed storage primitives for:
   - `state/memory-actions.jsonl`
   - `state/compression-guidelines.md`
3. Add tests for config parsing and state read/write behavior.
4. No orchestration behavior changes in this slice.

### PR 21B — Proactive Extraction Wiring

Files:
- `src/extraction.ts`
- `src/orchestrator.ts`
- tests for extraction/orchestrator proactive path

Tasks:
1. Add a bounded second-pass self-question generation path behind `proactiveExtractionEnabled`.
2. Respect `maxProactiveQuestionsPerExtraction` hard cap.
3. Fail-open: any proactive pass failure falls back to baseline extraction.
4. Add tests for gating, bounds, and fail-open behavior.

### PR 21C — Compression Action Tools + Telemetry

Files:
- `src/tools.ts`
- `src/orchestrator.ts`
- `src/storage.ts`
- tests for tool wiring + telemetry output

Tasks:
1. Add `context_checkpoint` and `memory_action_apply` tool surfaces behind `contextCompressionActionsEnabled`.
2. Log action telemetry entries to `state/memory-actions.jsonl`.
3. Ensure action writes are append-only and fail-open.
4. Add tests for action logging and disabled-mode reachability.

### PR 21D — Guideline Learning Loop + Docs

Files:
- learner wiring (orchestrator/compounding path)
- `docs/architecture/memory-lifecycle.md`
- `docs/config-reference.md`
- `docs/setup-config-tuning.md`

Tasks:
1. Add guideline update pass behind `compressionGuidelineLearningEnabled`.
2. Generate/update `state/compression-guidelines.md` from recent action outcomes.
3. Add staged rollout guidance and operator tuning playbook.
4. Run hardening playbook before merge.

## Invariants

1. All new behavior is disabled by default.
2. `0` numeric limits remain valid and are never coerced upward.
3. All new writes are fail-open and do not block extraction/recall.
4. New telemetry/state stores are namespace-safe and backward compatible.

## Verification Gate (Each PR)

1. `npm run check-types`
2. `npm test`
3. `npm run build`
4. `npm run preflight:quick`
5. PR loop must wait for terminal `Cursor Bugbot` state before claiming clean.
