diff --git a/backend/src/agent/podman.ts b/backend/src/agent/podman.ts index 6d87270..d42cd70 100644 --- a/backend/src/agent/podman.ts +++ b/backend/src/agent/podman.ts @@ -5,6 +5,7 @@ import { analyzeFrame } from '../vision/gemini.js'; import { detectCollisions } from '../collision/detector.js'; import { getGithubState } from '../github/client.js'; import { recordObservation, recordCollision, recordIntervention } from '../memory/store.js'; +import { getGitStates } from '../memory/db.js'; import { recallSimilar } from '../memory/vectors.js'; import { shouldIntervene, preferredAction } from '../memory/policy.js'; import { speak } from '../voice/live.js'; @@ -36,6 +37,14 @@ export class PodMan { this.contexts.set(engineerId, ctx); await recordObservation(ctx); + // Fuse git ground truth: engineer_states written by scripts/podman-agent.mjs. + // Keyed by name (matches --name arg), same as LiveKit participant identity. + const gitStates = await getGitStates(this.podId); + for (const [id, c] of this.contexts) { + const git = gitStates.get(id); + if (git && git.changedFiles.length > 0) c.hasUnpushedChanges = true; + } + const github = await getGithubState(); // cached const collisions = detectCollisions([...this.contexts.values()], github); for (const collision of collisions) await this.handle(collision); diff --git a/backend/src/memory/db.ts b/backend/src/memory/db.ts index 629d08c..1902fb0 100644 --- a/backend/src/memory/db.ts +++ b/backend/src/memory/db.ts @@ -43,6 +43,38 @@ export async function collections(): Promise { }; } +export interface GitState { + changedFiles: string[]; + branch: string | null; + recentCommit: string | null; + gitUpdatedAt: Date | null; +} + +/** Fetch latest git state per engineer for a pod from the engineer_states collection. + * Returns a map keyed by engineer name (matches --name arg used in podman-agent.mjs). */ +export async function getGitStates(podId: string): Promise> { + const db = await getDb(); + const col = db.collection<{ + _id: string; + name: string; + changedFiles?: string[]; + branch?: string | null; + recentCommit?: string | null; + gitUpdatedAt?: Date; + }>('engineer_states'); + const docs = await col.find({ podId }).toArray(); + const map = new Map(); + for (const doc of docs) { + map.set(doc.name, { + changedFiles: doc.changedFiles ?? [], + branch: doc.branch ?? null, + recentCommit: doc.recentCommit ?? null, + gitUpdatedAt: doc.gitUpdatedAt ?? null, + }); + } + return map; +} + /** Connect, verify reachability, and create helpful indexes. Call once on startup. */ export async function initMemory(): Promise { const db = await getDb();