Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
147 changes: 110 additions & 37 deletions README.md

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion bench/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
Git0 vs last-write-wins vs text-git across scripted multi-agent scenarios.
Plan, scenario format and metrics: [docs/team/person-c-bench-concurrency.md](../docs/team/person-c-bench-concurrency.md).

**Status (2026-10-18): skeleton only.** There is no runner (`bench/run.py`) and no scenarios or results yet, so `make bench` fails. The concurrency proof that does exist is `tests/core/test_repo.py::test_concurrent_writers_lose_nothing` (20 writers, 0 lost), which runs in CI.

```bash
make bench # -> bench/results/<backend>/<scenario>.json
make bench # planned: -> bench/results/<backend>/<scenario>.json
```
26 changes: 23 additions & 3 deletions docs/ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,26 @@ Invariants (tests enforce these; do not break them):

Checkout, commit (CAS), log, merge-base, conflict detection, dependents/revert cascade, why-path, "not in memory" proofs, tenant isolation and the scorecard all run as Cypher. Agents hold no state between turns. Stop the container and agents know nothing. Demo this.

## 5b. Git0 Relay: code-context graph (IDE demo, `/ide/`)

Same rules (one query per write, Cypher in `cypher/code_*.cypher`), different graph: one per IDE session, `ide_<sid>`.

```
(:File {path})-[:DEFINES]->(:Symbol {id: "<path>::<qualname>", signature, body_hash, line, end_line})
(:Symbol)-[:CALLS]->(:Symbol) // rebuilt for a file on every recorded write
(:Agent {id: 'A'|'B'})-[:MADE]->(:Change {kind, old_signature, new_signature})-[:TOUCHED]->(:Symbol)
(:Agent)-[:INTENDS]->(:Intent {task, active})-[:TARGETS]->(:Symbol)
(:Agent)-[:ACKED]->(:Change) // seen/absorbed: pulled, or the human said override
```

Flow (`src/git0/ide/`): two Pydantic AI agents on Gemini (`harness.py`), each in its own copy of `demo_project/`. Every tool call passes `RelayHooks` (`hooks.py`), which call the MCP server mounted at `/mcp/` in the same FastAPI process:
- **PostToolUse** (after a write): `code_record_edit` parses the file (`code/parse.py`, stdlib `ast`) and records changed symbols and signature changes.
- **PreToolUse** (before a write): `code_check_edit` runs `code_conflicts_same_symbol`, `code_conflicts_dependency` (calls a function whose signature the peer changed), `code_conflicts_reverse` (the peer's new code reaches the target through `CALLS*1..3`) and `code_conflicts_intent`. A blocking hit denies the write and asks the human: pull the peer's change, keep mine, or pause.
- **PreToolUse** (before a read): `code_peer_activity` adds heads-ups about teammate changes to the agent's context.
- **Merge check** (`mergecheck.py`): `git merge-file` (line-based) vs the symbol/call analysis, so the UI shows git calling a broken merge clean.

Sessions (`session.py`): at most `IDE_MAX_SESSIONS` (8); graph and workspaces are deleted on End session, on tab close (sendBeacon), after 15 min idle, and orphans on process start. The room sweeper only touches `team_*`.

## 6. Integration contracts (who depends on whom)

| Contract | Owner | Consumers | File |
Expand All @@ -119,17 +139,17 @@ Checkout, commit (CAS), log, merge-base, conflict detection, dependents/revert c
| `POST /api/{t}/commits` | `CommitRequest` → `{commit, retries}` | A | done |
| `GET /api/{t}/facts/{id}/why` | → why-path rows | A | done |
| `GET /api/{t}/branches/{name}/procedures` | → `Procedure[]` | A | done |
| `POST /api/{t}/agents/{agent}/messages` | `{message, session_id}` → `AgentReply` (plain JSON; unknown agent 404). SSE streaming (`token`, `commit`, `error`, `: ping` every 15 s) is issue #10 | B `agents.step` | done (JSON) |
| `POST /api/{t}/agents/{agent}/messages` | `{text, session_id?}` → SSE stream: `token` (reply text), `commit` (`commit_id`, `cited_fact_ids`, `branch`, `usage`), `error` (LLM failure). Unknown agent 404 | B `agents.step` | done (SSE) |
| `POST /api/{t}/merge/preview` | `{source, target}` → `MergeResult` | A `plan_merge` | done |
| `POST /api/{t}/merge/resolve` | `{source, target, choices, agent_id?, target_head?, source_head?}` → `MergeApplied` (`invalidated` = facts for the Arbiter to re-derive). Send the previewed heads back: if either branch moved since, 409 "preview again" | A `apply_merge` | done |
| `POST /api/{t}/revert` | `{branch, commit_id, agent_id?}` → `RevertResult` | A `revert` | done |
| `GET /api/{t}/graph?branch=main&limit=200&episodes=true` | → `GraphView` (`branch`, `nodes: {id, label, kind, ...}[]`, `links: {source, target, type}[]`, `truncated`); 404 unknown branch | D (canvas) + A query | done |
| `POST /api/{t}/merge/explain` | `{source, target}` → `ConflictExplanation[]` (`{key, text}`, one per conflict; one LLM call, cached) | B `arbiter.explain` | done |
| `POST /api/{t}/arbiter/rederive` | `{target, fact_ids, session_id?}` → `RederiveResult` (`replies`, `tokens` spent, `owners`, `skipped`). Send `MergeApplied.invalidated[].id` as `fact_ids` | B `arbiter.rederive` | done |
| `POST /api/{t}/agents/{agent}/kill` | → `HandoffResult` (`successor`, `branch`, `inherited: Fact[]`, `commits`, `commit_id`, `summary`). Unknown agent or branch is 404 | B `handoff` | done |
| `POST /api/{t}/load-test` | `{writers}` → `{commits, lost, retries, p50_ms, p95_ms}` | C `run_load` | P2 |
| `POST /api/{t}/load-test` | `{writers}` → `{commits, lost, retries, p50_ms, p95_ms}` | C `run_load` | not built (the 20-writer proof is `test_concurrent_writers_lose_nothing`) |
| `GET /api/{t}/scorecard` | → live Track 02 counts | A `scorecard.cypher` | done |
| `POST /api/{t}/fork` | → `{graph, ms}` (GRAPH.COPY) | A | P3 |
| `POST /api/{t}/fork` | → `{graph, ms}` (GRAPH.COPY) | A | not built |

Any `LLMError` (provider failure, offline cache miss, tenant rate limit) comes back as **502 `{detail}`**, never 429 and never fabricated output (M12); the UI shows `detail` in a red banner. An SSE stream that has already started cannot use the 502: it sends an `error` event instead.

Expand Down
10 changes: 6 additions & 4 deletions docs/STACK.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ Versions are what `uv sync` / `pnpm install` resolved today. Full research with
|-|-|-|-|
| Language | Python | 3.12 (`.python-version`) | Every FalkorDB/LLM SDK is first-class. Matches the Docker image |
| Package mgr | uv | 0.12+ | Lockfile, fast CI, `uv sync --frozen` in Docker |
| Graph DB | FalkorDB | `falkordb/falkordb:latest` | Track sponsor. Multigraph per tenant, Cypher, algorithms, GRAPH.COPY |
| Graph DB | FalkorDB | `falkordb/falkordb:v4.22.1` (pinned in compose, CI and the AWS host) | Track sponsor. Multigraph per tenant, Cypher, algorithms, GRAPH.COPY |
| DB client | `falkordb` (asyncio) | 1.8.0 | `FalkorDB.from_url`, `select_graph`, `query`/`ro_query` with params |
| API | FastAPI + uvicorn | 0.143 | Native SSE (`fastapi.sse`, ≥0.135), OpenAPI → typed TS client |
| Models | Pydantic v2 + pydantic-settings | 2.14 | Shared contracts. LLM output validation |
| LLM primary | `groq` SDK, `openai/gpt-oss-20b` | 1.7 | Strict `json_schema` structured outputs (gpt-oss only). Fast |
| LLM fallback | `google-genai`, Gemini Flash | 2.31 | Free tier, response schema. Check the model name in AI Studio |
| MCP | `mcp` SDK | 2.3 | Should-have: Git0 as memory for Claude Code/Cursor |
| LLM fallback | `google-genai`, Gemini (`gemini-3.1-flash-lite`, then the `GEMINI_FALLBACK_MODELS` chain) | 2.31 | Free tier, response schema |
| MCP | `mcp` SDK | 2.3 | Streamable HTTP, mounted at `/mcp/` in the API: memory tools + `code_*` relay tools for Claude Code, Cursor, Gemini CLI |
| IDE agents | `pydantic-ai-slim[google,mcp]` + Gemini | 2.x | The two coding agents in `/ide/`; hooks call the MCP server |
| Tests | pytest + pytest-asyncio | 9.1 / 1.4 | Run against a **real** FalkorDB, never mocks |
| Lint | ruff | 0.17 | Lint + format in CI |

Expand All @@ -25,7 +26,8 @@ Versions are what `uv sync` / `pnpm install` resolved today. Full research with
| Commit DAG | `@xyflow/react` + `@dagrejs/dagre` | Clickable nodes, path highlight. gitgraph.js is unmaintained |
| Memory graph | `@falkordb/canvas` (web component, v0.3.x) | Same renderer as the FalkorDB Browser. Fallback: `force-graph` |
| Data | TanStack Query + `openapi-fetch` (types from `/openapi.json`) | One source of truth for the API shape |
| Realtime | SSE (`EventSource`) | One-way stream of agent replies + scorecard. Simpler than WS |
| Realtime | SSE over `fetch` + `ReadableStream` (agent replies are a POST, which `EventSource` can't send); the scorecard and logs poll | Simpler than WS |
| IDE editor | `@monaco-editor/react` | VS Code-like view of both clones in `/ide/` |
| Tests | Vitest + Testing Library | |

## Infra
Expand Down
28 changes: 9 additions & 19 deletions docs/context.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Person D — Implementation Context & Demo Guide

> Updated 2026-10-18 to match the code. The judge flow and the IDE demo are summarised in the [README](../README.md#try-it-in-60-seconds).

**Issues:** #10 (SSE route + 3-column shell + CommitDag) · #15 (ChatPanel, ConflictCard, WhyPath, Scorecard)

---
Expand All @@ -18,14 +20,8 @@ Streams agent replies as Server-Sent Events:

Uses `StreamingResponse(media_type="text/event-stream")` with `X-Accel-Buffering: no` to prevent Caddy buffering.

#### Gemini Fallback Chain (`src/git0/config.py`, `src/git0/llm/client.py`)
Primary model: `gemini-3.6-flash`. On 503/overload, retries in order:
1. `gemini-3.8-flash`
2. `gemini-3.5-flash-lite`
3. `gemini-3.1-flash-lite`
4. `gemini-2.5-flash-lite`

First success wins. Only raises `LLMError` if all five fail simultaneously.
#### LLM provider chain (`src/git0/config.py`, `src/git0/llm/client.py`)
Providers are tried in order; the first valid answer wins: **Groq** `openai/gpt-oss-20b` (strict JSON schema, when `GROQ_API_KEY` is set), then **Gemini** `GEMINI_MODEL` (default `gemini-3.1-flash-lite`) and each model in `GEMINI_FALLBACK_MODELS` (default `gemini-3.5-flash-lite`, `gemini-3.5-flash`). Every output is validated with Pydantic. Only when all providers fail does it raise `LLMError` (API: 502, UI: red banner).

#### Agent Update Rule (`src/git0/agents/specs.py`)
Added to `_RULES` shared across all agents: when asked to UPDATE or CHANGE an existing fact, the agent must add the new value to `facts` AND put the old key in `removed_keys` so the old value is retracted. Without this, agents answered update requests conversationally without writing to the graph.
Expand All @@ -47,7 +43,7 @@ SSE via `fetch` + `ReadableStream` (not `EventSource` — that's GET-only):
`onAgentChange(agentId)` tells App which branch is active (drives ConflictCard source).

#### CommitDag (`web/src/components/CommitDag.tsx`)
Fetches `/branches/{name}/log` for planner / scheduler / notes / main every 4s. Infers parent edges from `seq` ordering within each branch (the API `Commit` schema has no explicit `parents` field). Uses `@dagrejs/dagre` with `rankdir: TB` for layout. Branch color coding: planner=purple, scheduler=blue, notes=green, main=pink.
Fetches `/branches/{name}/log` for planner / scheduler / notes / main every 4s and draws edges from each commit's `parents` (exposed in PR #33, so merge commits show both parents). Uses `@dagrejs/dagre` with `rankdir: LR` (left to right) for layout. Branch color coding: planner=purple, scheduler=blue, notes=green, main=pink.

#### ConflictCard (`web/src/components/ConflictCard.tsx`)
"Merge `{branch}` → main" button at the bottom of the left column. Flow:
Expand All @@ -63,23 +59,17 @@ Branch label updates when user switches agent tabs.
On "why?" click: calls `GET /api/{tenant}/facts/{fact_id}/why`. The route returns provenance rows with `fact_id`, `commit_id`, `agent_id`, `episode_id`. All four are graph node IDs — WhyPath collects them all and passes to App's `highlight` state. MemoryCanvas dims everything not in the set.

#### Scorecard (`web/src/components/Scorecard.tsx`)
Polls `GET /api/{tenant}/scorecard` every 3s. Maps 7 Track 02 counters: facts on main, episodes, procedures, sessions resumed, handoffs, total commits, tenants live.
Polls `GET /api/{tenant}/scorecard` every 3s. Shows 12 live counters (facts, chat turns, procedures, sessions, agents, memory updates, merges, disagreements settled, past decisions reused, undos, handoffs, live team rooms), all from one Cypher query.

---

## Demo Flow (Full Pipeline)

### Setup
```bash
# Terminal 1 — FalkorDB
docker run -p 6380:6379 falkordb/falkordb

# Terminal 2 — API (from git0/)
set -a && source .env && set +a
uv run uvicorn git0.api.app:app --reload --port 8000

# Terminal 3 — Frontend (from git0/web/)
pnpm run dev
make db-up # FalkorDB v4.22.1 on :6379 (browser UI on :3000)
make api # FastAPI on :8000 (reads .env)
make web # Vite on :5173, proxies /api and /mcp to :8000
```
Open `http://localhost:5173`. The seed endpoint runs automatically on first room visit.

Expand Down
Binary file added docs/img/pipeline.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 16 additions & 16 deletions docs/team/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,25 @@ D.deploy (P0) ────────────────────► ev
```
Nobody waits: code against the contract (`core/models.py` + stub signatures). The stub raises `NotImplementedError`, so use a local fake in your tests until the real one merges.

## Must-have tracker (tick at each gate, on `main` + deployed)
## Must-have tracker (status checked against the code on 2026-10-18)
| # | Must-have | Owner | P | Status |
|-|-|-|-|-|
| M1 | Semantic 3-way merge with dependents + Arbiter | A (+B) | 2 | ☐ |
| M2 | Graph is the only channel between agents | B | 1 | ☐ |
| M3 | All Track 02 focus items live on the scorecard | D (+A counts) | 2-3 | ☐ |
| M4 | Deterministic merge authority (Cypher rules, LLM explains only) | A | 2 | ☐ |
| M5 | Why-path on every answer | A + D | 2 | ☐ |
| M6 | Concurrency proof (20 writers, 0 lost, p95) | C (+A) | 2-3 | ☐ baseline test exists |
| M7 | Tenant isolation by graph | D (+A) | 3 | ☐ |
| M8 | Benchmark vs 2 baselines, JSON in repo | C | 2-3 | ☐ |
| M9 | Precedent reuse | A | 2-3 | ☐ |
| M10 | "Not in memory" no-path proof | A + B | 2 | ☐ query exists |
| M11 | Live 60 s judge flow | D | 2 | ☐ |
| M12 | Fail loudly (no canned output) | B + D | 3 | ☐ |
| M13 | Submission basics (repo, README, Cypher list, video, URL, disclosure) | C + D | 4 | ☐ |
| M14 | Everyone explains model + queries | All | 4 | ☐ |
| M1 | Semantic 3-way merge with dependents + Arbiter | A (+B) | 2 | ☑ `core/merge.py` + `agents/arbiter.py` |
| M2 | Graph is the only channel between agents | B | 1 | ☑ agents read only `checkout` |
| M3 | All Track 02 focus items live on the scorecard | D (+A counts) | 2-3 | ☑ `scorecard.cypher` + `Scorecard.tsx` |
| M4 | Deterministic merge authority (Cypher rules, LLM explains only) | A | 2 | ☑ `(:Rule)` + human; LLM explains |
| M5 | Why-path on every answer | A + D | 2 | ☑ `why_path.cypher` + `WhyPath.tsx` |
| M6 | Concurrency proof (20 writers, 0 lost, p95) | C (+A) | 2-3 | ◐ 20-writer CAS test in CI; no load button or p95 |
| M7 | Tenant isolation by graph | D (+A) | 3 | ☑ graph per room + TTL sweep |
| M8 | Benchmark vs 2 baselines, JSON in repo | C | 2-3 | ☐ `bench/` skeleton only, no results |
| M9 | Precedent reuse | A | 2-3 | ☑ `(:Precedent)` on the conflict card |
| M10 | "Not in memory" no-path proof | A + B | 2 | ☑ "Not in team memory (no path)" |
| M11 | Live 60 s judge flow | D | 2 | ☑ live, "Try the demo" bar |
| M12 | Fail loudly (no canned output) | B + D | 3 | ☑ `LLMError` → 502 / red banner |
| M13 | Submission basics (repo, README, Cypher list, video, URL, disclosure) | C + D | 4 | ◐ repo, README, Cypher list, URL, disclosure done; video pending |
| M14 | Everyone explains model + queries | All | 4 | ☐ team walkthrough |
| M15 | Every commit is one atomic Cypher query | A | 0 | ☑ `commit_cas.cypher` |
| M16 | Entity reuse + strict JSON extraction | B | 1 | ☐ |
| M16 | Entity reuse + strict JSON extraction | B | 1 | ☑ entity list in prompt + strict schema |

## Rituals (short, fixed)
- **Stand-ups (10 min):** 09:00, 14:00, 21:00 IST. Each person answers: done since last, next, blocked on whom.
Expand Down
24 changes: 12 additions & 12 deletions web/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,25 @@ React + TypeScript + Vite frontend for the Git0 hackathon app.

## Folder map

Two pages from one build (`vite.config.ts` has two Rollup inputs): the team room at `/` and the relay IDE at `/ide/`.

```
src/
main.tsx entry: StrictMode + TanStack QueryClientProvider
App.tsx 3-column shell: ChatPanel | CommitDag/MemoryCanvas tabs | Scorecard
index.css Tailwind v4 (`@import "tailwindcss"`)
api/
client.ts openapi-fetch client typed by schema.d.ts (baseUrl "")
schema.d.ts generated by `pnpm gen:api`; placeholder `paths {}` until then
sse.ts subscribe(url, onEvent) wrapper around EventSource
components/ placeholders owned by Person D (see docs/team/person-d-ui.md)
ChatPanel.tsx, CommitDag.tsx (React Flow + dagre demo), MemoryCanvas.tsx (<falkordb-canvas>),
ConflictCard.tsx, Scorecard.tsx, WhyPath.tsx
index.html, src/main.tsx team room entry
src/App.tsx shell: chat + merge bar | commit DAG / memory graph tabs | scorecard
src/components/ ChatPanel (SSE over fetch), MergeBar + ConflictCard (preview -> explain -> resolve -> rederive),
CommitDag (xyflow + dagre), MemoryCanvas (@falkordb/canvas), WhyPath, Scorecard,
DemoGuide ("Try the demo" bar), BranchPicker, TenantGate (per-visitor room), ErrorBanner
src/api/ openapi-fetch client + generated schema.d.ts
src/lib/ shared hooks (branch logs, tenant)
ide/index.html, src/ide/ relay IDE: App, useIdeSession (SSE events), tour + coach marks,
components/ (AgentPanel, Workspace (Monaco), GraphCanvas/GraphOverlay, BottomPanel)
```

`@/` is an alias for `src/` (Vite and tsconfig).

## How the API proxy works

In dev, `vite.config.ts` forwards any request whose path starts with `/api` to
In dev, `vite.config.ts` forwards any request whose path starts with `/api` or `/mcp` to
`http://localhost:8000`. The browser only talks to the Vite origin, so there is no CORS
setup and `EventSource` streams (SSE) pass straight through.

Expand Down
Loading