> 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/phases/phase_15/session_03_aggregate_orchestration_refactor.md).

# Session 03: Aggregate Orchestration Refactor

**Session ID**: `phase15-session03-aggregate-orchestration-refactor` **Status**: Complete **Estimated Tasks**: \~16 **Estimated Duration**: 2-4 hours

***

## Objective

Expose reusable host/local and extension aggregate orchestration without changing `bun run aggregate` output or public behavior.

This is the extraction half of the agent aggregate work. Do not register scoped scheduler jobs in this session; Session 04 wires the `agent-aggregate` scheduler job after compatibility is proven.

***

## Scope

### In Scope (MVP)

* Extract reusable aggregate orchestration pieces from `scripts/aggregate.ts`
* Add a host/local aggregate path that can skip extension collectors
* Preserve Dream projection loading in the host/local refresh path
* Preserve local agent/session/config/memory/integration assembly
* Keep the full compatibility aggregate command behavior unchanged
* Focused tests for helper behavior and compatibility output

### Out of Scope

* Registering scoped scheduler jobs
* Adding package scheduler scripts for scoped jobs
* Timer unit rendering
* SQLite observation store writes

***

## Detailed Tasks

1. Refactor `scripts/aggregate.ts` into reusable orchestration pieces without changing `bun run aggregate`.
2. Add an aggregate mode or helper that skips extension collectors.
3. Preserve Dream projection loading in the host/local refresh path.
4. Preserve local agent, session, config, memory, and integration assembly.
5. Keep `bun run aggregate` as the full compatibility command with unchanged output and public behavior.
6. Keep existing generated-data validation on all writes.
7. Make the host/local helper usable by the later `agent-aggregate` scheduler handler.
8. Make extension orchestration separable so the later Trend Finder job can run only its owned collector branch.
9. Add focused tests for reusable helper behavior.
10. Add compatibility tests or fixtures proving full aggregate output is unchanged.
11. Verify the host/local path can run without Trend Finder collectors.
12. Run focused scheduler and aggregate tests needed by the refactor.

***

## Prerequisites

* [x] Session 02 complete.
* [x] Shared live-data merge and lock helpers are available for scoped writes.

***

## Deliverables

1. Reusable aggregate orchestration helpers.
2. Compatibility-preserving full aggregate path.
3. Tests proving extension collectors can be skipped in host/local mode.

***

## Handoff Gate

* [x] `scripts/aggregate.ts` exposes reusable host/local and extension orchestration.
* [x] `bun run aggregate` output and public behavior are unchanged.
* [x] The future `agent-aggregate` job can refresh host/local data without running Trend Finder collectors.

***

## Success Criteria

* [x] Full `bun run aggregate` remains behavior-compatible.
* [x] Host/local orchestration can run without Trend Finder collectors.
* [x] Existing generated-data validation still gates writes.


---

# 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/phases/phase_15/session_03_aggregate_orchestration_refactor.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.
