Integrate canonical architecture: two-process backend + LiveKit agent

Promote all 12 staged canonical files from docs/generated/files/ to their
live paths, creating the full PodMan architecture:

Backend:
- server.ts: HTTP service (token mint, sync-PR, outcome recording, /health, WS relay)
- agent.ts: worker joining LiveKit room, grabbing screenshare frames at ~1fps
- agent/podman.ts: orchestrator loop (vision -> collision detection -> intervention)
- env.ts: flat env var accessors replacing nested stub
- vision/gemini.ts: JPEG -> Gemini vision -> EngineerContext (real implementation)
- collision/detector.ts: fused vision+GitHub collision detection (the moat)
- github/client.ts: Octokit wrapper with caching + sync PR creation
- memory/store.ts: extended with recordObservation/recordCollision/recordIntervention/recordOutcome helpers
- memory/vectors.ts: stub for Voyage+Atlas vector recall (Loop A)
- memory/policy.ts: stub for intervention policy gate (Loop B)
- voice/live.ts: stub for Gemini Live TTS voice output

Shared:
- messages.ts: LiveKit data-channel wire protocol (DataMessage, InterventionOutcome, TeamModel, LocalGitReport)
- index.ts: re-exports messages module

Frontend:
- livekit/useScreenPublish.ts: hook for joining pod and publishing screenshare
- livekit/useInterventions.ts: hook for receiving collision cards and responding
- lib/api.ts: fetchToken + postOutcome HTTP helpers

Database:
- database/init.ts: MongoDB Atlas collections + indexes + vector search index

Infra:
- infra/.do/app.yaml: DO App Platform spec (static_site + service + worker)

Retire stubs superseded by canonical decomposition:
- backend/src/index.ts (replaced by server.ts)
- backend/src/intervention/engine.ts (logic now in agent/podman.ts)
- backend/src/livekit/token.ts (token minting now in server.ts)

Install missing dependencies: @livekit/rtc-node, sharp, mongodb, ws, @types/ws

Type error fixes:
- vision/gemini.ts: use MediaResolution.MEDIA_RESOLUTION_LOW enum value (not string literal)
- agent/podman.ts: wrap SuggestedActionKind into { kind: action } SuggestedAction object

All packages pass pnpm -r typecheck and pnpm -r build.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Kartikeya
2026-06-27 14:27:14 -07:00
parent 253c7438fb
commit da5b2622b2
23 changed files with 1369 additions and 190 deletions
+39 -18
View File
@@ -1,25 +1,46 @@
import { Octokit } from 'octokit';
import type { GithubStateSnapshot } from '@podman/shared';
import { env } from '../env.js';
import { env, repoParts } from '../env.js';
export const octokit: Octokit = new Octokit({ auth: env.github.token });
const gh = new Octokit({ auth: env.GITHUB_TOKEN });
let cache: { at: number; state: GithubStateSnapshot } | null = null;
const TTL_MS = 5000;
/**
* Pull the GitHub state relevant to a file in the pod's repo: open branches
* and PRs touching it. Fused with vision contexts by the collision detector.
*
* TODO(github): list branches/PRs, diff files, map commits -> engineer logins.
*/
export async function getStateForFile(_file: string): Promise<GithubStateSnapshot> {
return { branches: {}, openPrs: [], unpushed: false };
export async function getGithubState(): Promise<GithubStateSnapshot> {
if (cache && Date.now() - cache.at < TTL_MS) return cache.state;
const { owner, repo } = repoParts();
const [{ data: branches }] = await Promise.all([
gh.rest.repos.listBranches({ owner, repo, per_page: 50 }),
]);
const state: GithubStateSnapshot = {
branches: Object.fromEntries(branches.map((b) => [b.name, b.commit.sha])),
openPrs: [],
unpushed: undefined, // vision/Tier-2 fills this; API cannot know
};
cache = { at: Date.now(), state };
return state;
}
/** Open a draft "sync PR" between two engineers' branches — the suggested action. */
export async function openSyncPr(_params: {
base: string;
head: string;
title: string;
}): Promise<{ number: number; url: string } | null> {
// TODO(github): octokit.rest.pulls.create({ ...env.github.repo, draft: true })
return null;
export async function remoteHasFile(path: string, ref = 'main'): Promise<boolean> {
const { owner, repo } = repoParts();
return gh.rest.repos
.getContent({ owner, repo, path, ref })
.then(() => true)
.catch(() => false);
}
export async function createSyncPr(input: { headBranch: string; file: string; summary: string }) {
const { owner, repo } = repoParts();
const { data: mainRef } = await gh.rest.git.getRef({ owner, repo, ref: 'heads/main' });
const branch = `podman-sync-${Date.now()}`;
await gh.rest.git.createRef({ owner, repo, ref: `refs/heads/${branch}`, sha: mainRef.object.sha });
const { data: pr } = await gh.rest.pulls.create({
owner,
repo,
title: `PodMan: sync ${input.file} before collision`,
head: branch,
base: 'main',
body: input.summary,
});
return pr;
}