Session 197 Handoff

Documentation for Plans

Session 197 Handoff — Make Vitto Actually Generate Modules

Critical Context

Session 196 built the infrastructure for Vitto's memory + job mastery system. The schemas, services, APIs, frontend lib, chat plugin, prompt templates, and pipeline wiring are ALL committed and building clean. But the system doesn't work end-to-end yet. When a user asks Vitto to "create a module to manage a sports team club" in the web panel chat, the agent loop stalls after iteration 1 — it writes text but never calls start_module_generation.

What's Built (S196 — all committed, all building)

Backend (backend-vitto-api)

Frontend

What's BROKEN (Must Fix in S197)

Problem 1: Agent Loop Stalls on Module Generation Requests

Symptoms: User sends "Create a module to manage a sports team club" → SSE shows agent.iteration with iteration 1, agent.text with "Starting on the soccer club management modu..." → Then ONLY heartbeat events, no tool calls, no completion.

Root cause: The agent loop in agent-loop.service.ts is not progressing past iteration 1. The LLM responds with text but doesn't call start_module_generation. This could be:

  1. The tool definitions aren't being sent correctly to the Anthropic API
  2. The system prompt is too long (context overflow) causing the model to skip tool use
  3. The agent loop's tool-call parsing fails silently
  4. The LLM model being used doesn't support tool use (unlikely but check)

Files to investigate:

How to debug:

  1. Add logging in agent-loop.service.ts at the point where it sends tools to the LLM
  2. Log the exact Anthropic API response to see if tool_use blocks are present
  3. Check if the system prompt exceeds the model's context window
  4. Check the maxIterations setting (currently 40 — should be fine)

Problem 2: No Visual Pipeline Editor

The orchestration schema exists (PlaybookOrchestration with steps, dependencies, parallel/sequential modes) but there's no UI to:

Problem 3: Frontend Components Are Stubs

The 6 components in @libs-ai/vitto-intelligence render but:

Key Files Map

Backend — Generation Pipeline

APIs/backend-vitto-api/src/app/
├── engine/
│   ├── agent-loop.service.ts          ← INVESTIGATE: Why does it stall?
│   ├── vitto-engine.service.ts        ← Orchestrates agent loop
│   ├── context-assembly.service.ts    ← System prompt (S196: dossier + mastery injected)
│   └── autonomy.service.ts            ← OBSERVE/SUGGEST/DIRECT/AUTONOMOUS levels
├── module-generation/
│   ├── phases/
│   │   ├── module-gen-phase.executor.ts  ← S196: mastery outcome recording + dossier updates
│   │   ├── enhance.phase.ts
│   │   ├── analyze.phase.ts           ← S196: playbookStrategy + masteryContext in prompt
│   │   ├── decompose.phase.ts         ← S196: same
│   │   ├── plan.phase.ts              ← S196: same (added contextHints param)
│   │   └── execute.phase.ts           ← S196: same
│   ├── context/
│   │   └── generation-context.service.ts  ← S196: fetches mastery + strategy
│   └── module-generation.module.ts    ← S196: imports UsersModule
├── tools/
│   └── tool-registry.service.ts       ← Line 1302: start_module_generation definition
├── users/                             ← NEW in S196
│   ├── schemas/
│   │   ├── user-dossier.schema.ts
│   │   └── job-playbook.schema.ts
│   ├── user-dossier.service.ts
│   ├── job-mastery.service.ts
│   ├── users.controller.ts
│   └── users.module.ts
├── mind/
│   ├── mind.service.ts                ← S196: dossierService injected, auto-populates
│   └── mind.module.ts                 ← S196: imports UsersModule
└── prompts/module-gen/
    ├── system-analyze.prompt.md       ← S196: {{playbookStrategy}} + {{masteryContext}}
    ├── system-decompose.prompt.md     ← S196: same
    ├── system-plan.prompt.md          ← S196: same
    ├── implement-visual.prompt.md     ← S196: same
    └── implement.prompt.md            ← S196: same

Frontend — Intelligence UI

libs/libs-ai/vitto-intelligence/src/lib/
├── components/
│   ├── job-mastery-dashboard/         ← Grid of all playbooks
│   ├── job-mastery-detail/            ← Single playbook deep dive
│   ├── playbook-editor/               ← Edit playbook (executive only)
│   ├── playbook-creator/              ← Create new job type (needs LLM wiring)
│   ├── user-dossier-view/             ← Tabbed dossier display
│   └── executive-instructions/        ← Directive management
├── services/
│   └── vitto-intelligence-api.service.ts  ← HTTP client (/users/* endpoints)
└── types/
    └── intelligence.types.ts

Chat Plugin

libs/libs-ai/vitto-chat/src/lib/plugins/
├── mastery.plugin.ts                  ← /mastery, /teach, /dossier, /new-job
├── plugin-presets.ts                  ← S196: mastery plugin in standard set
└── index.ts                           ← S196: exports createMasteryPlugin

Schemas Reference

UserDossier (collection: 'dossiers' in vitto-users)

userId (unique), identity, personality, expertise, workPatterns,
spaces (per-space map), relationships, timeline (cap 50),
jobMastery (per-job-type mastery overlay), brief, briefGeneratedAt,
lastInteraction, expiresAt (GDPR TTL)

JobPlaybook (collection: 'job-playbooks' in vitto-users)

jobType (unique), displayName, category, description, brief,
skills[] (composable, with embeddings), strategyVersions[] (self-optimizing),
graduationCriteria (5-tier: intern→principal), globalStats,
orchestration (steps[], maxConcurrency, pipelineTimeoutMs, failFast),
phases, origin (seeded|emergent), status, version

Seeded Playbook: code-platform-generation

7 skills: analyze-space-profile, select-template, plan-architecture,
          generate-backend, generate-frontend, verify-build, validate-output
4 orchestration steps: analyze → plan → generate (parallel) → verify (parallel)
Strategy v1: "Template-first approach..."

REST API Endpoints

GET    /users/dossier/me              ← Own dossier (any user)
GET    /users/dossier/:userId         ← Other user (executive/admin/developer)
POST   /users/dossier/me/facts        ← Learn fact (own)
POST   /users/dossier/me/corrections  ← Record correction (own)
POST   /users/dossier/me/expertise    ← Update expertise (own)
POST   /users/dossier/me/events       ← Record event (own)
POST   /users/dossier/me/brief/rebuild ← Rebuild brief (own)
DELETE /users/dossier/:userId         ← Delete (executive/admin)
GET    /users/playbooks               ← List all (any user)
GET    /users/playbooks/:jobType      ← Get one (any user)
POST   /users/playbooks               ← Create (executive/admin)
PUT    /users/playbooks/:jobType      ← Update (executive/admin)
POST   /users/mastery/:userId/:jobType/outcome ← Record outcome (system/admin)
GET    /users/mastery/:userId/:jobType ← Get mastery (own or executive)

Build Commands

npx nx build backend-vitto-api --skip-nx-cache   # Backend
npx nx build gograb-ai --skip-nx-cache            # Frontend (includes vitto-intelligence)
npx nx test backend-vitto-api --testFile="session-196"  # 39 tests
npx nx test backend-vitto-api --testFile="session-195"  # 21 tests (regression)
npx nx lint vitto-intelligence                    # Frontend lint

Priority Order for S197

  1. Fix agent loop stalling — This unblocks EVERYTHING. Without it, nothing works.
  2. Pipeline visualization component — Real-time generation monitoring
  3. Polish frontend components — Make them production-ready
  4. Wire "Let Vitto Help" in PlaybookCreator — LLM-assisted form filling
  5. Live SSE events in mastery dashboard — Real-time skill score updates during generation