> For the complete documentation index, see [llms.txt](https://faction-os.gitbook.io/faction-os-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://faction-os.gitbook.io/faction-os-docs/.spec_system/archive/sessions/phase19-session11-templates-and-planning-context/code-review.md).

# Code Review and Repair Report

**Session ID**: `phase19-session11-templates-and-planning-context` **Package**: null **Reviewed**: 2026-06-26 **Scope**: All uncommitted changes in the working tree **Result**: RESOLVED

## Review Surface

**Files reviewed** (all uncommitted changes before this report was generated):

* `.spec_system/PRD/phase_19/session_11_templates_and_planning_context.md` - tracked-modified
* `.spec_system/specs/phase19-session11-templates-and-planning-context/implementation-notes.md` - untracked
* `.spec_system/specs/phase19-session11-templates-and-planning-context/spec.md` - untracked
* `.spec_system/specs/phase19-session11-templates-and-planning-context/tasks.md` - untracked
* `.spec_system/state.json` - tracked-modified
* `apps/server/src/lib/commandCenterValidation.ts` - tracked-modified
* `apps/server/src/lib/orchestrationValidation.ts` - tracked-modified
* `apps/server/src/lib/templatePlanningContext.ts` - untracked
* `apps/server/src/managers/agentTemplates.ts` - tracked-modified
* `apps/server/src/managers/orchestrationCommandCenter.ts` - tracked-modified
* `apps/server/src/managers/planCampaignManager.ts` - tracked-modified
* `apps/server/src/managers/taskQueue.ts` - tracked-modified
* `apps/server/src/routes/orchestration.ts` - tracked-modified
* `apps/server/src/server.ts` - tracked-modified
* `apps/server/tests/commandCenterManager.test.ts` - tracked-modified
* `apps/server/tests/commandCenterRoutes.test.ts` - tracked-modified
* `apps/server/tests/orchestration.test.ts` - tracked-modified
* `apps/server/tests/orchestrationDiagnostics.test.ts` - tracked-modified
* `apps/server/tests/planCampaignManager.test.ts` - tracked-modified
* `apps/server/tests/templatePlanningContext.test.ts` - untracked
* `apps/server/tests/websocket.test.ts` - tracked-modified by validation repair
* `apps/web/src/components/orchestration/CampaignWorkbench.tsx` - tracked-modified
* `apps/web/src/components/orchestration/CommandCenterPanes.tsx` - tracked-modified
* `apps/web/src/components/orchestration/OrchestrationCurrentState.tsx` - tracked-modified
* `apps/web/src/components/orchestration/OrchestrationDrawer.tsx` - tracked-modified
* `apps/web/src/components/orchestration/OrchestrationShell.tsx` - tracked-modified
* `apps/web/src/components/orchestration/OrchestrationTabs.tsx` - tracked-modified
* `apps/web/src/components/orchestration/TemplateWorkbench.tsx` - untracked
* `apps/web/src/components/orchestration/index.ts` - tracked-modified
* `apps/web/src/lib/orchestrationApi.ts` - tracked-modified
* `apps/web/src/lib/orchestrationUi.ts` - tracked-modified
* `apps/web/src/lib/templatePlanningContext.ts` - untracked
* `apps/web/src/store/useGameStore.ts` - tracked-modified
* `apps/web/tests/OrchestrationPanel.test.tsx` - tracked-modified
* `apps/web/tests/TemplateWorkbench.test.tsx` - untracked
* `apps/web/tests/orchestrationApi.test.ts` - tracked-modified
* `apps/web/tests/orchestrationStore.test.ts` - tracked-modified
* `packages/protocol/src/agentTemplates.ts` - tracked-modified
* `packages/protocol/src/orchestrationCommandCenter.ts` - tracked-modified
* `packages/protocol/src/taskQueue.ts` - tracked-modified
* `packages/protocol/tests/orchestration.test.ts` - tracked-modified
* `.spec_system/specs/phase19-session11-templates-and-planning-context/code-review.md` - untracked report generated by `creview`

**Inventory commands**: `git status --short`, `git diff HEAD`, `git diff --cached --name-status`, `git ls-files --others --exclude-standard`

## Findings by Severity

### Critical

* None.

### High

* None.

### Medium

* `apps/server/src/managers/taskQueue.ts:78` - Queue `sourceAttribution` accepted bounded but unredacted strings, then stored, returned through REST list/get/mutation responses, and emitted through websocket event entries. A user-supplied label or summary could expose tokens, bearer values, or broad local paths through broad orchestration surfaces. Fix: normalize source attribution on create, update, clone, and event entry generation, redact source labels/summaries/categories, dedupe/sort source task ids, and cap source refs. Status: FIXED. Tests: `apps/server/tests/orchestration.test.ts` now asserts create/list output does not contain sensitive tokens or broad paths.
* `apps/server/src/lib/orchestrationValidation.ts:79` - New queue/template planning routes did not consistently reject blocked raw payload fields before parsing, so top-level or nested keys such as `prompt` and `token` could be silently ignored instead of rejected at the trust boundary. Fix: added `rejectBlockedPayload` checks for task queue create/update, nested `sourceAttribution`, and template queue preview/create bodies. Status: FIXED. Tests: `apps/server/tests/orchestration.test.ts` covers blocked nested attribution and blocked template preview payloads without echoing raw values.
* `apps/server/src/lib/templatePlanningContext.ts:420` - Planning source labels/summaries and transcript-mined memory content were bounded but not redacted before being placed into planning context, template suggestions, queue previews, and auto-improvement attention records. Fix: route all bounded labels/text through `redactSensitiveText` before whitespace normalization/truncation. Status: FIXED. Tests: `apps/server/tests/templatePlanningContext.test.ts` verifies sensitive source and memory text is redacted.
* `packages/protocol/src/taskQueue.ts:240` - The exported task queue source attribution parsers accepted nested blocked raw fields and dropped unknown keys, leaving other consumers of the shared protocol parser with weaker behavior than the server route. Fix: reject command-center blocked payload fields in `parseTaskQueueSourceRef` and `parseTaskQueueSourceAttribution` before normalization. Status: FIXED. Tests: `packages/protocol/tests/orchestration.test.ts` now verifies nested `prompt` and `token` keys are rejected.

### Low

* None.

## Assumptions and Deliberate Non-Fixes

* The Template Workbench currently passes memory filters through the UI by default, while explicit mission, queue, Quest Board, analysis, project-scan, follow-up, and auto-improvement source refs are supported by the server/API contracts and typed client tests. I left broader source-selection UX unchanged because no existing uncommitted state contract owns selected Quest/analysis/project-scan refs, and inventing that cross-surface selection model during `creview` would exceed a surgical repair. The source path remains covered through route/API tests and can be expanded in a follow-up UI session.

## Behavior Changes

* Queue source attribution labels, summaries, source ref labels/summaries, and source ref categories are now redacted before storage or broad REST/websocket exposure.
* Queue create/update and template queue preview/create now reject blocked raw payload keys such as `prompt`, `token`, raw transcript, raw logs, file content, diffs, terminal output, and broad path fields instead of ignoring them.
* Planning context builder output now redacts sensitive text in source and memory-derived fields before creating template suggestions, queue previews, and auto-improvement attention.
* Shared task queue source attribution parsers now reject blocked raw fields for all protocol consumers.

## Verification

* Tests: `source /home/aiwithapex/.nvm/nvm.sh && nvm use --silent 26.2.0 && npm test -- orchestration templatePlanningContext planCampaignManager commandCenterRoutes orchestrationApi commandCenterStore TemplateWorkbench OrchestrationPanel` - PASS - 15 test files, 124 tests.
* Formatter write: `source /home/aiwithapex/.nvm/nvm.sh && nvm use --silent 26.2.0 && npx biome format --write packages/protocol/src/taskQueue.ts packages/protocol/tests/orchestration.test.ts apps/server/src/lib/orchestrationValidation.ts apps/server/src/lib/templatePlanningContext.ts apps/server/src/managers/taskQueue.ts apps/server/tests/templatePlanningContext.test.ts apps/server/tests/orchestration.test.ts` - PASS - 7 files checked, no fixes applied.
* Type checker: `source /home/aiwithapex/.nvm/nvm.sh && nvm use --silent 26.2.0 && npm run typecheck --workspaces --if-present` - PASS - all configured workspaces.
* Formatter: `source /home/aiwithapex/.nvm/nvm.sh && nvm use --silent 26.2.0 && npm run format:check` - PASS - 704 files checked.
* Linter: `source /home/aiwithapex/.nvm/nvm.sh && nvm use --silent 26.2.0 && npm run lint` - PASS - 706 files checked.
* Whitespace: `git diff --check HEAD` - PASS.
* ASCII/LF: modified and untracked file scan with `grep` for non-ASCII and CRLF - PASS.
* Final diff re-read: no remaining repo-fixable findings found in the uncommitted review surface.

## Validation Repair Addendum

* `apps/server/tests/websocket.test.ts` - During validation, full `npm test` failed two websocket tests because their queue-create fixtures still posted blocked top-level raw fields (`path`, `token`, `command`) to `/task-queue`. The current route behavior correctly rejects those fields. Fix: moved sensitive-looking fixture text into accepted `sourceAttribution` label/summary fields so the tests still verify websocket redaction without relying on invalid request shapes. Status: FIXED.
* Verification: `source /home/aiwithapex/.nvm/nvm.sh && nvm use --silent 26.2.0 && npm test -- apps/server/tests/websocket.test.ts` - PASS - 1 test file, 13 tests.
* Verification: `source /home/aiwithapex/.nvm/nvm.sh && nvm use --silent 26.2.0 && npm test` - PASS - 239 test files, 2857 tests, 1 skipped.

## Summary

1. Reviewed 41 implementation/spec/test files plus this generated report across protocol, server, web, and session metadata.
2. Resolved 4 medium findings: source attribution redaction, blocked raw payload rejection for queue/template routes, planning context redaction, and protocol-level source attribution parser hardening.
3. No critical, high, or low findings remain. The only deliberate non-fix is the broader source-selection UX gap, documented above with supporting evidence.
4. Focused tests, workspace typecheck, formatter, linter, whitespace, and ASCII/LF checks all pass.


---

# 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://faction-os.gitbook.io/faction-os-docs/.spec_system/archive/sessions/phase19-session11-templates-and-planning-context/code-review.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.
