Files
Jarvis/scripts/check-embedding-dim-literal.sh
james.maes 6f4f2fb6c2 feat(07-06): four cross-plan grep gates + AppDelegate install-order test (Task 3)
- scripts/check-single-memory-mutated-emit.sh — MEM-06 single-emission-site
  for ReplayEvent.memoryMutation (allowlist: MemoryStore.swift,
  Replay/ReplayEvent.swift, Replay/Schema.swift; tests + comments excluded).
- scripts/check-single-memory-used-emit.sh — D-05 single-emission-site for
  ReplayEvent.memoryRetrieval (same allowlist shape, MemoryStore.recordRetrieval
  is the sole emit site).
- scripts/check-presence-vision-isolation.sh — VISION-03 three-layer guard:
  Layer 1 (Vision/Package.swift declares no Voice or AgentOrchestrator dep),
  Layer 2 (no `import Voice` / `import AgentOrchestrator` and no TTSEngine /
  AgentOrchestrator.runTurn / cancelAndSubmit token references in
  packages/Vision/Sources/), Layer 3 (no App/ file co-locates a
  PresenceSignalBus reference with a forbidden TTS / runTurn token).
- scripts/check-embedding-dim-literal.sh — MEM-02 invariant: no literal 768
  in packages/Memory/Sources/Memory/ outside Constants.swift; comment-only
  lines tolerated.
- All four scripts wired as Jarvis pre-build phases in project.yml; the
  generated project.pbxproj reflects the updates.
- packages/Memory/Tests/MemoryTests/PhaseSevenGrepGateTests.swift mirrors
  the four shell gates as XCTest assertions plus a fifth assertion
  (testAppDelegateInstallOrder) verifying the call order in
  applicationWillFinishLaunching: installMemory before installVoice
  before installVision.
- App/Voice/NullVoiceAdapters.swift extracted from AppDelegate.swift to
  honor the Layer 3 boundary cleanly. NullOrchestratorAdapter and
  NullTTSAdapter are placeholder no-ops mirroring the prior structure;
  Phase 7 future wiring replaces them with real bridges.
- Negative-case demonstration completed: introducing a stray
  `.memoryMutation(...)` literal in App/AppDelegate.swift made
  check-single-memory-mutated-emit.sh exit non-zero; the violation was
  reverted before commit. Documented as evidence of gate sensitivity.
2026-04-29 18:58:11 -05:00

30 lines
1.1 KiB
Bash
Executable File

#!/usr/bin/env bash
# MEM-02 invariant guard.
#
# EMBEDDING_DIM = 768 is defined exactly once at MemoryConstants.embeddingDim.
# Any other literal 768 in the Memory module is a shadow that drifts on a
# model swap and silently returns garbage from vector queries (RESEARCH P2).
#
# Strips comment-only lines (after the file:lineno: prefix is stripped)
# before counting so prose mentioning 768 in docstrings does not fail the
# gate. The companion EmbeddingDimSymbolTests covers the parallel symbol
# case with a stricter "EMBEDDING_DIM = 768" definition pattern; this gate
# covers the bare-literal-shadow case.
set -euo pipefail
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$REPO_ROOT"
HITS=$(grep -rnE '\b768\b' packages/Memory/Sources/Memory/ --include='*.swift' 2>/dev/null \
| grep -v 'Constants.swift:' \
| sed -E 's|^[^:]+:[0-9]+:||' \
| grep -vE '^[[:space:]]*(//|\*|/\*)' \
| grep -E '\b768\b' || true)
if [[ -n "$HITS" ]]; then
echo "MEM-02 violation: literal 768 outside MemoryConstants.embeddingDim:" >&2
echo "$HITS" >&2
exit 1
fi
exit 0