> For the complete documentation index, see [llms.txt](https://ai-os-and-trend-finder.gitbook.io/ai-os-and-trend-finder-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ai-os-and-trend-finder.gitbook.io/ai-os-and-trend-finder-docs/.spec_system/archive/sessions/phase24-session02-delta-aware-enrichment-spend-accounting/tasks.md).

# Task Checklist

**Session ID**: `phase24-session02-delta-aware-enrichment-spend-accounting` **Total Tasks**: 25 **Estimated Duration**: 3.5-4 hours **Created**: 2026-06-07

***

## Legend

* `[x]` = Completed
* `[ ]` = Pending
* `[P]` = Parallelizable (can run with other \[P] tasks)
* `[SNNMM]` = Session reference (NN=phase number, MM=session number)
* `TNNN` = Task ID

***

## Progress Summary

| Category       | Total  | Done   | Remaining |
| -------------- | ------ | ------ | --------- |
| Setup          | 3      | 3      | 0         |
| Foundation     | 6      | 6      | 0         |
| Implementation | 12     | 12     | 0         |
| Testing        | 4      | 4      | 0         |
| **Total**      | **25** | **25** | **0**     |

***

## Setup (3 tasks)

Initial verification and environment preparation.

* [x] T001 \[S2402] Verify stable evidence ID, source-local, and Trend Finder schema semantics (`src/extensions/trend-finder/schema.ts`)
* [x] T002 \[S2402] Confirm private cache root and ignored artifact conventions (`.gitignore`)
* [x] T003 \[S2402] Confirm current Apify and Google Trends charge cap metadata (`scripts/lib/apify/types.ts`)

***

## Foundation (6 tasks)

Core contracts and base implementations.

* [x] T004 \[S2402] \[P] Create private enrichment cache helper with schema-validated entries, path containment, atomic writes, and idempotency protection (`scripts/extensions/trend-finder/enrichment-cache.ts`)
* [x] T005 \[S2402] \[P] Create spend accounting helper with bounded currency math, exact/estimated states, cadence-unavailable fallback, and raw billing redaction (`scripts/extensions/trend-finder/spend-accounting.ts`)
* [x] T006 \[S2402] Extend source adapter contracts for enrichment cache and spend summaries with types matching declared contract and exhaustive enum handling (`scripts/extensions/trend-finder/sources/types.ts`)
* [x] T007 \[S2402] Extend browser Trend Finder schema with additive cache and spend summaries with safe defaults for legacy payloads (`src/extensions/trend-finder/schema.ts`)
* [x] T008 \[S2402] Extend Engine Trace browser contract with bounded cache and spend summaries with deterministic ordering (`src/extensions/trend-finder/engine-trace.ts`)
* [x] T009 \[S2402] Extend Apify run result types for safe usage and charge cap summaries with raw provenance excluded from browser contracts (`scripts/lib/apify/types.ts`)

***

## Implementation (12 tasks)

Main feature implementation.

* [x] T010 \[S2402] Capture Apify `usageTotalUsd` and configured charge caps in run results with explicit failure-path handling (`scripts/lib/apify/actors.ts`)
* [x] T011 \[S2402] Emit per-source Apify spend summaries with timeout, retry/backoff, and failure-path handling preserved (`scripts/extensions/trend-finder/sources/apify-adapter.ts`)
* [x] T012 \[S2402] Emit Google Trends demand spend summaries with exact/estimated labels, max charge caps, and missing-token fallback behavior (`scripts/extensions/trend-finder/sources/google-trends-demand.ts`)
* [x] T013 \[S2402] Implement cheap-first enrichment cache selection and merge flow with idempotency protection, transaction boundaries, and compensation on failure (`scripts/extensions/trend-finder/collector.ts`)
* [x] T014 \[S2402] Implement enrichment cache pruning from the active evidence keep set with cleanup on scope exit for all acquired resources (`scripts/extensions/trend-finder/collector.ts`)
* [x] T015 \[S2402] Emit sanitized cache and spend trace events with schema-validated input and explicit error mapping (`scripts/extensions/trend-finder/engine-trace.ts`)
* [x] T016 \[S2402] Project cache and spend summaries into Engine Replay metrics with explicit loading, empty, error, and offline states (`src/extensions/trend-finder/engine-replay-model.ts`)
* [x] T017 \[S2402] Add source spend and enrichment cache state to Sources view with platform-appropriate accessibility labels, focus management, and input support (`src/extensions/trend-finder/views/sources-view.tsx`)
* [x] T018 \[S2402] Update Trend Finder fixtures and fallback data for cache hits, skipped enrichment, pruned entries, and spend estimates (`src/extensions/trend-finder/fixtures.ts`)
* [x] T019 \[S2402] Update committed live-data fallback shape for additive cache and spend fields (`src/data/live-data.example.json`)
* [x] T020 \[S2402] \[P] Update pipeline docs for enrichment cache, retention, pruning, and spend accounting (`docs/extensions/trend-finder-pipeline.md`)
* [x] T021 \[S2402] \[P] Update source and runtime provenance docs for source spend, cache state, exact/estimated labels, and cadence-unavailable state (`docs/extensions/trend-finder-sources.md`, `docs/extensions/trend-finder-runtime-and-provenance.md`)

***

## Testing (4 tasks)

Verification and quality assurance.

* [x] T022 \[S2402] \[P] Write enrichment cache unit tests for keys, validation, hits, misses, stale fingerprints, atomic writes, and pruning (`scripts/extensions/trend-finder/__tests__/enrichment-cache.test.ts`)
* [x] T023 \[S2402] \[P] Write spend accounting tests for actual usage, estimates, caps, cadence-unavailable state, and redaction (`scripts/extensions/trend-finder/__tests__/spend-accounting.test.ts`)
* [x] T024 \[S2402] Extend adapter, collector, schema, and Engine Replay tests for cache/spend summaries and legacy payload defaults (`scripts/extensions/trend-finder/__tests__/collector.test.ts`)
* [x] T025 \[S2402] Run focused Trend Finder tests and ASCII checks (`package.json`)

***

## Completion Checklist

Before marking session complete:

* [x] All tasks marked `[x]`
* [x] All tests passing
* [x] All files ASCII-encoded
* [x] implementation-notes.md updated
* [x] Ready for the validate workflow step

***

## Next Steps

Run the implement workflow step to begin AI-led implementation.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://ai-os-and-trend-finder.gitbook.io/ai-os-and-trend-finder-docs/.spec_system/archive/sessions/phase24-session02-delta-aware-enrichment-spend-accounting/tasks.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
