# Runtime Prompt Boundary Audit

**Status:** Phase 2 audit complete; updated for no-child-apps clarification  
**Created:** 2026-06-27  
**Updated:** 2026-06-27  
**Repo inspected:** `/home/hex/Project/BrainDrive-Test-01`  
**Branch inspected:** `dev`  
**Code state:** after Phase 1 runtime forced-write / Finance deferral cleanup

## Purpose

This audit classifies the remaining runtime prompt/context lines in the four functions named by the brief:

- `buildProjectChatContext`
- `buildProjectConversationGuard`
- `buildProjectSpecificTurnGuard`
- `buildAppChatContextGuidance`

The classification rule is:

| Classification | Meaning | Action |
|---|---|---|
| KEEP | Runtime state, capability, active selection, file list, upload metadata, or safety/scoping context | Leave in runtime |
| DELETE | Obsolete, contradictory, duplicated, or harmful behavior | Remove |
| MOVE | Owner-visible behavior that belongs in starter-pack markdown | Move after review/approval |
| CODIFY | Hard safety guarantee currently expressed as prose | Enforce in code or keep temporarily with tracked follow-up |

## Summary

Phase 1 removed the highest-risk runtime behavior:

- forced write-as-facts-arrive instructions
- forced success-criterion artifact writes
- Finance deferral toward statements/rough estimates

The remaining largest behavior block is `buildProjectSpecificTurnGuard`. Most of that function is owner-visible, page-specific interview behavior. It should be reviewed for DELETE vs MOVE before more code changes are made.

`buildProjectChatContext` mostly provides runtime state and file context. It still contains some imperative wording, but most of it is state, path scoping, or capability context rather than interview behavior.

Product clarification after the initial audit: BrainDrive no longer has a Budget app or child apps, and app metadata was only for app prompt context. Therefore `buildAppChatContextGuidance` is obsolete and should be removed rather than retained as runtime state.

## Function Audit

### `buildProjectChatContext`

| Line(s) | Runtime text / behavior | Classification | Recommendation |
|---|---|---|---|
| 3420 | Active project identity: `You are currently in the **{projectId}** project.` | KEEP | Runtime state. |
| 3421 | Read project `AGENT.md`, optional `AGENT-user.md`, `spec.md`, `plan.md`. | KEEP | Runtime tells the model where the active project source files live. Consider rephrasing later as file priority, but this is not the harmful write-timing behavior. |
| 3422-3423 | Finance-specific project alignment file list. | KEEP for now | Runtime state/source ordering for Finance. It does not tell the model how to interview or when to write. Revisit if Finance pack can fully express this without runtime special casing. |
| 3424-3426 | Index-file handling when present or potentially present. | KEEP | Runtime file-discovery guidance. |
| 3428 | Stay focused on this domain; avoid other projects unless cross-domain is requested. | CODIFY / KEEP temporarily | This is a project-scoping safety/quality boundary. Prefer code enforcement where possible; keep as runtime context until codified. |
| 3429 | Neutral artifact state: project has `spec.md` and `plan.md`; follow project markdown for update timing. | KEEP | This is the intended Phase 1 replacement. It names state/capability and delegates behavior to pack markdown. |
| 3431-3434 | Current project files heading/list. | KEEP | Runtime state. |
| 3436 | Use current list as starting point for user file requests. | KEEP | Runtime state freshness guard. |
| 3437 | Do not rely on earlier conversation claims if current list disagrees. | KEEP | Runtime state freshness guard. |
| 3438 | For delete requests, prefer exact paths and call `memory_delete` when a matching file exists. | CODIFY / KEEP temporarily | This is tool/path behavior. Ideally enforced through tool validation and request handling; acceptable as temporary runtime guard because deletion safety matters. |
| 3439 | If list is ambiguous/incomplete, call `memory_list` before claiming missing. | KEEP | Runtime capability/context guidance tied to file list completeness. |

Recommended Phase 3 action:

- Keep the current Phase 1 replacement line.
- Do not delete file-list, active-project, or path-safety lines.
- Track line 3428 and delete/path lines as CODIFY candidates if the team wants to reduce runtime prose further.

### `buildProjectConversationGuard`

| Line(s) | Runtime text / behavior | Classification | Recommendation |
|---|---|---|---|
| 3461-3463 | Current-turn guard heading and project scope. | KEEP | Runtime state explaining the guard scope. |
| 3468 | Lists missing-context labels already asked. | KEEP | Runtime conversation state. |
| 3469 | Do not ask same missing-context label again; handle adjacent useful information. | MOVE / CODIFY | This is interview behavior and should ideally live in pack behavior or be enforced by repeated-question logic. It exists to prevent a live model failure mode, so do not delete until pack/harness coverage proves it is safe. |
| 3475 | Lists exact questions already asked. | KEEP | Runtime conversation state. |
| 3476 | Do not ask same question again; mark unknown / choose next action. | MOVE / CODIFY | Behavioral repeated-question rule. Candidate for starter-pack guidance or code-level repeated-question guard. |
| 3483 | If asking a question, ask exactly one question and use at most one question mark. | MOVE | Owner-visible interview style. Should move to starter-pack interview instructions if still needed. |

Recommended Phase 3 action:

- Keep the state lines that list already-asked labels/questions.
- Move or codify the repeated-question behavior before deleting it.
- Move the one-question rule to starter-pack interview files if the team still wants it.

### `buildProjectSpecificTurnGuard`

This is the main remaining runtime behavior block.

The previous Fitness-specific rows were deleted from this audit and removed from runtime code on 2026-06-27.

| Line(s) | Runtime text / behavior | Classification | Recommendation |
|---|---|---|---|
| 3499-3503 | Career: mirror career constraints and preserve exact money/time/current-role phrases. | MOVE | Career interview behavior. |
| 3506-3512 | Career: record unanswered setup details unknown; do not repeat broad setup question. | MOVE / CODIFY | Behavior plus repeated-question guard. |
| 3516-3520 | Finance: mirror money/account-boundary phrases. | MOVE | Finance interview behavior. |
| 3523-3527 | Finance: mirror every amount when multiple money amounts are present. | MOVE | Finance behavior. Could also be tested in Finance pack harness. |
| 3530-3536 | Finance: adjacent finance information; do not repeat same finance intake question. | MOVE / CODIFY | Behavior plus repeated-question guard. |
| 3540-3544 | Relationships: mirror relationship area/feeling/boundary/safety phrase; avoid flattening. | MOVE | Relationships interview behavior. |
| 3547-3553 | Relationships: record relationship area unknown if unconfirmed; do not repeat broad question. | MOVE / CODIFY | Behavior plus repeated-question guard. |
| 3557-3561 | New Project: mirror project scope/constraints; preserve project names/crops/budget/output/success. | MOVE | New Project interview behavior. |
| 3564-3570 | New Project: adjacent project information; do not repeat setup question. | MOVE / CODIFY | Behavior plus repeated-question guard. |
| 3574-3578 | Your Agent: mirror trust/privacy/approval/routing/control language. | MOVE | Your Agent interview behavior. |
| 3581-3587 | Your Agent: operating boundary; record unanswered capability details unknown; do not repeat setup question. | MOVE / CODIFY | Behavior plus repeated-question guard. |

Recommended Phase 3 action:

- Treat this function as the primary migration target.
- Do not delete the whole function until each page pack is checked for equivalent behavior or the team agrees the behavior is no longer needed.
- Best next step: create page-by-page pack deltas or confirm Dave W's harness already proves these are unnecessary.
- After pack coverage is confirmed, delete the migrated/deprecated runtime blocks and update tests accordingly.

### `buildAppChatContextGuidance`

Product clarification: BrainDrive no longer has Budget app or child apps. This function only existed to inject child-app prompt context and was removed from runtime code on 2026-06-27.

| Line(s) | Runtime text / behavior | Classification | Recommendation |
|---|---|---|---|
| Removed | Active app scope heading and focused app folder. | DELETE | Removed from runtime code. |
| Removed | App `AGENT.md` / overlay presence or absence. | DELETE | Removed from runtime code. |
| Removed | App state file presence or absence. | DELETE | Removed from runtime code. |
| Removed | App rules file presence or absence. | DELETE | Removed from runtime code. |
| Removed | `statements/` folder as app source evidence when present. | DELETE | Removed from runtime code; Finance Budget app must not reappear. |
| Removed | `reports/` folder as app-generated report location when present. | DELETE | Removed from runtime code. |
| Removed | Stay inside app folder unless owner asks for project-level work or app instructions point elsewhere. | DELETE | Removed from runtime code. Preserve project-level path safety elsewhere if needed. |

Recommended Phase 3 action:

- Removed the call to `buildAppChatContextGuidance`.
- Removed `buildAppChatContextGuidance`.
- Removed `metadata.app` handling from gateway prompt assembly and prompt audit metadata.
- Updated regressions that fail on `### Active App Scope`, `focused on the app folder`, app state-file, app statements, and app reports prompt text.

## Recommended Next Implementation Pass

### Safe to do next after review

1. Move/remove remaining `buildProjectSpecificTurnGuard` page-specific mirror/narrowing language after confirming each page pack covers the intended behavior.
2. Move the one-question rule from `buildProjectConversationGuard` into starter-pack interview files if still desired.
3. Decide whether repeated-question prevention should be:
   - pack behavior,
   - code-level guard,
   - or retained temporarily as runtime prose.

### Do not do mechanically

- Do not delete active project/file-list context.
- Do not delete path/delete safety guidance until code enforcement exists.
- Do not delete all repeated-question guards without confirming the pack-only and live-runtime harnesses still pass.

## Proposed Phase 3 Work Items

1. Review page packs for equivalent mirror/repeat-question behavior:
   - Fitness
   - Career
   - Finance
   - Relationships
   - New Project
   - Your Agent
2. For each page-specific runtime guard, choose:
   - DELETE because pack already handles it
   - MOVE because pack needs it
   - CODIFY because it should be enforced outside prompts
3. Add runtime-sim tests that fail if page-specific interview behavior remains in gateway prompt assembly after migration.
4. Keep child-app/app-scope runtime prompt injection removed and fail tests on app-scope prompt phrases.

## Completion Status

- Phase 2 audit is complete as a documentation artifact.
- No new code changes were made during the audit step itself.
- Selected audit recommendations have now been implemented: Fitness-specific runtime guards were removed, and obsolete child-app/app-scope prompt handling was removed.
- Remaining page-specific runtime behavior still needs review before additional move/delete decisions.
- App-scope prompt removal has been implemented.
