> 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_24/session_04_source_setup_and_target_configuration.md).

# Session 04: Source Setup And Target Configuration

**Session ID**: `phase24-session04-source-setup-target-configuration` **Status**: Complete **Validated**: 2026-06-08 **Estimated Tasks**: \~12-25 **Estimated Duration**: 2-4 hours

***

## Objective

Make reviewed-source setup operable from a local UI without weakening Trend Finder source compliance.

***

## Planning Source

* `PRD_phase_24.md` folded source memo, S04 coverage.
* Findings covered: 2 and 13.

***

## Active EXAMPLES References

* [EXAMPLES/outlier-lab/serve.py:46](https://github.com/moshehbenavraham/ai-os/blob/main/home/aiwithapex/projects/aios/EXAMPLES/outlier-lab/serve.py:46): local token read.
* [EXAMPLES/outlier-lab/serve.py:56](https://github.com/moshehbenavraham/ai-os/blob/main/home/aiwithapex/projects/aios/EXAMPLES/outlier-lab/serve.py:56): local token write reference; Trend Finder must preserve its existing secret boundary and never echo full secrets.
* [EXAMPLES/outlier-lab/serve.py:91](https://github.com/moshehbenavraham/ai-os/blob/main/home/aiwithapex/projects/aios/EXAMPLES/outlier-lab/serve.py:91): normalized profile/target shape.
* [EXAMPLES/outlier-lab/serve.py:156](https://github.com/moshehbenavraham/ai-os/blob/main/home/aiwithapex/projects/aios/EXAMPLES/outlier-lab/serve.py:156): setup state endpoint.
* [EXAMPLES/outlier-lab/serve.py:180](https://github.com/moshehbenavraham/ai-os/blob/main/home/aiwithapex/projects/aios/EXAMPLES/outlier-lab/serve.py:180): search endpoint.
* [EXAMPLES/outlier-lab/serve.py:241](https://github.com/moshehbenavraham/ai-os/blob/main/home/aiwithapex/projects/aios/EXAMPLES/outlier-lab/serve.py:241): token validation reference.
* [EXAMPLES/outlier-lab/serve.py:276](https://github.com/moshehbenavraham/ai-os/blob/main/home/aiwithapex/projects/aios/EXAMPLES/outlier-lab/serve.py:276): add target flow.
* [EXAMPLES/outlier-lab/serve.py:355](https://github.com/moshehbenavraham/ai-os/blob/main/home/aiwithapex/projects/aios/EXAMPLES/outlier-lab/serve.py:355): remove target flow.
* [EXAMPLES/outlier-lab/admin.html:207](https://github.com/moshehbenavraham/ai-os/blob/main/home/aiwithapex/projects/aios/EXAMPLES/outlier-lab/admin.html:207): token UI.
* [EXAMPLES/outlier-lab/admin.html:219](https://github.com/moshehbenavraham/ai-os/blob/main/home/aiwithapex/projects/aios/EXAMPLES/outlier-lab/admin.html:219): search/add UI.
* [EXAMPLES/outlier-lab/admin.html:326](https://github.com/moshehbenavraham/ai-os/blob/main/home/aiwithapex/projects/aios/EXAMPLES/outlier-lab/admin.html:326): tracked target list rendering.
* [EXAMPLES/outlier-lab/admin.html:378](https://github.com/moshehbenavraham/ai-os/blob/main/home/aiwithapex/projects/aios/EXAMPLES/outlier-lab/admin.html:378): search debounce and credential-required state.
* [EXAMPLES/outlier-lab/admin.html:428](https://github.com/moshehbenavraham/ai-os/blob/main/home/aiwithapex/projects/aios/EXAMPLES/outlier-lab/admin.html:428): add/remove event flow.
* [EXAMPLES/outlier-lab/configure.py:64](https://github.com/moshehbenavraham/ai-os/blob/main/home/aiwithapex/projects/aios/EXAMPLES/outlier-lab/configure.py:64): CLI fallback token flow.
* [EXAMPLES/outlier-lab/configure.py:98](https://github.com/moshehbenavraham/ai-os/blob/main/home/aiwithapex/projects/aios/EXAMPLES/outlier-lab/configure.py:98): target verification flow.
* [EXAMPLES/outlier-lab/configure.py:214](https://github.com/moshehbenavraham/ai-os/blob/main/home/aiwithapex/projects/aios/EXAMPLES/outlier-lab/configure.py:214): private/unavailable target rejection.

These are implementation references only. Translate creator/profile concepts into reviewed source IDs, safe target fields, and source health metadata.

***

## Source Memo Coverage

* Finding 2: provide local reviewed-source setup UI with declaration, compliance, credential, active/configured, quality, cap, warning, and last-run health state.
* Finding 13: any local bridge that reads/writes source config or serves files must remain loopback-bound, token-gated, path-contained, and root-restricted.
* Rejected direct copy: do not configure Instagram/Reels sources, arbitrary Actor inputs, private accounts, or unreviewed source IDs.

***

## Scope

### In Scope (MVP)

* Add a local-only Source Setup panel under Sources or Engine Replay.
* Show reviewed source declarations, active/configured state, compliance status, credential readiness, quality tier, caps, warnings, and last-run health.
* For source types with safe target fields, support local target/query management through a token-gated loopback bridge.
* Validate source IDs against reviewed declarations and reject unknown, placeholder, or unreviewed Actor IDs.
* Support add/remove/update flows for safe target fields such as subreddit feeds, channels, query terms, repository topics, RSS feeds, or other reviewed target fields.
* Keep credentials in existing env/private-cache conventions and never echo full secrets to the browser.
* Add source setup tests and docs for the local config path.

### Out of Scope

* Configuring unreviewed source IDs, unrestricted Actor inputs, private accounts, private feeds, or arbitrary raw JSON.
* Storing credentials in browser state.
* Replacing existing env/file-driven configuration.

***

## Primary Implementation Areas

* `scripts/extensions/trend-finder/sources/apify-source-config.ts`
* `scripts/extensions/trend-finder/sources/source-compliance.ts`
* `scripts/extensions/trend-finder/sources/types.ts`
* `scripts/lib/trend-finder-lens-bridge.ts` as a bridge pattern reference
* `scripts/lib/trend-finder-visibility-config-bridge.ts` as a file overlay pattern reference
* `src/extensions/trend-finder/views/sources-view.tsx`
* `src/extensions/trend-finder/components/runtime-readiness-panel.tsx`
* `docs/extensions/trend-finder-sources.md`
* `docs/sources/apify-source-onboarding.md`

***

## Prerequisites

* [ ] Confirm reviewed source declarations and safe target field list.
* [ ] Confirm existing source config file/env precedence.
* [ ] Confirm bridge patterns from Creator Lens and visibility config.

***

## Deliverables

1. Source Setup view or panel with reviewed-source readiness and health.
2. Token-gated loopback bridge for whitelisted source target fields.
3. Validation for unknown, unreviewed, placeholder, private, or unsafe source targets.
4. Backward-compatible source config read/write behavior.
5. Focused UI, bridge, and config tests.
6. Updated source setup and Apify onboarding docs.

***

## Success Criteria

* [ ] Source Setup can configure only reviewed source IDs and whitelisted target fields.
* [ ] Invalid source IDs, placeholder Actor IDs, private/unavailable targets, and missing credentials produce actionable warnings.
* [ ] Existing env/file-driven configuration remains backward compatible.
* [ ] Browser-visible output exposes credential presence only, never full secret values.


---

# 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_24/session_04_source_setup_and_target_configuration.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.
