Add persistent project state scaffolding

This commit is contained in:
Meta Vens 2026-04-26 02:09:33 +01:00
commit f7763bf306
12 changed files with 982 additions and 0 deletions

View file

@ -0,0 +1,74 @@
# VoidBot Fresh Workspace Handoff
VoidBot is no longer small enough to trust chat scrollback as its only memory. Use the canonical state files first, then touch code.
## What To Trust First
For the current project shape and next move, trust these in order:
1. `state/map.yaml`
2. `notes/fresh-workspace-handoff.md`
3. `notes/voidbot-current-system-map.md`
4. `notes/voidbot-implementation-plan.md`
5. `state/evidence.jsonl`
Git history and smoke artifacts carry routine proof. `state/evidence.jsonl` should carry only belief-changing records, not every tiny triumph with a timestamp stapled to it.
## Current Shape
- Discord bot and worker are live.
- Postgres owns jobs, audit events, interaction memory, and rate-limit state.
- Qdrant owns history and source vectors.
- `.voidbot/` owns archives, artifacts, logs, status files, and backups.
- `owner_codex` and `local_llm` are the active reply lanes.
- Ops health, backup verification, offsite sync, and dashboard surfaces already exist.
- The new state/notes surfaces are now the continuity spine for future nontrivial work.
## Important Paths
- Project root: `E:\Projects\VoidBot`
- Canonical map: `E:\Projects\VoidBot\state\map.yaml`
- Scratch surface: `E:\Projects\VoidBot\state\scratch.md`
- Distilled evidence ledger: `E:\Projects\VoidBot\state\evidence.jsonl`
- Branch/hypothesis ledger: `E:\Projects\VoidBot\state\branches.json`
- Handoff summary: `E:\Projects\VoidBot\notes\fresh-workspace-handoff.md`
- System map: `E:\Projects\VoidBot\notes\voidbot-current-system-map.md`
- Implementation plan: `E:\Projects\VoidBot\notes\voidbot-implementation-plan.md`
- State CLI: `E:\Projects\VoidBot\tools\voidbot_state.ts`
- Pre-compaction helper: `E:\Projects\VoidBot\tools\voidbot_prepare_compaction.ts`
## Useful Commands
```powershell
npm run state:status
npx tsx .\tools\voidbot_state.ts add-evidence --type research --status ok --note "..."
npx tsx .\tools\voidbot_state.ts add-branch --id branch-id --hypothesis "..."
npm run state:prepare-compaction
```
## Guardrails
- Do not continue implementation automatically from a rehydrate-only request.
- Do not trust this file for the exact live HEAD.
- Do not let `state/evidence.jsonl` become an activity feed.
- Do not let `state/scratch.md` linger with stale subgoals after the bounded move is done.
## Immediate Re-entry Instruction
On fresh session load or after suspicious continuity loss:
1. read `state/map.yaml`
2. run `npm run state:status`
3. reread `notes/fresh-workspace-handoff.md`
4. read `notes/voidbot-current-system-map.md`
5. read `notes/voidbot-implementation-plan.md`
6. restate the current next action from `state/map.yaml` before editing
When context pressure is rising:
1. stop broad exploration
2. narrow the active move to one bounded organ
3. persist map or handoff changes only if understanding actually changed
4. add distilled evidence only when the lesson changes future belief
The point is to bank coals, not leave the next waking thing a pile of ash and a browser tab graveyard.

View file

@ -0,0 +1,89 @@
# VoidBot Current System Map
This note is the source-grounded description of how the live VoidBot stack is shaped right now. It is not a prose replacement for the code, and it is not a second canonical map. Its job is to explain the major organs and their data flow in plain language with concrete path anchors.
## Main Organs
- `apps/bot/src/discord-bot.ts`
- Discord gateway, commands, mention handling, permissions, provider selection, rate-limit gating, and context assembly entrypoint.
- `apps/worker/src/index.ts`
- owner-job poller, provider execution, handoff packaging, and MCP wiring for the worker-side lane.
- `apps/worker/src/mcp-server.ts`
- read-only retrieval tools and resource surfaces for archived history, indexed repos, lore, and owner notifications.
- `packages/core/src/state-storage.ts`
- Postgres-backed durable state for jobs, audit events, interaction memory, and Void usage rate-limit counters.
- `packages/core/src/context-builder.ts`
- request context assembly, including interaction-memory/profile attachment.
- `packages/providers/src/owner-codex-provider.ts`
- Discord-safe `codex exec` lane, read-only tool policy, source-grounding enforcement, traces, handoff behavior.
- `packages/providers/src/local-llm-provider.ts`
- Ollama chat lane with a bounded host-managed read-only tool loop.
- `packages/rag/src/retrieval-service.ts`
- high-level history/source retrieval API used by bot, worker, and provider tool loops.
- `packages/rag/src/qdrant-vector-store.ts`
- Qdrant vector persistence for history and source collections.
- `packages/rag/src/message-archive.ts`
- archived Discord message store under `.voidbot/rag/messages.json`.
- `packages/rag/src/source-document-archive.ts`
- archived source/lore document store under `.voidbot/rag/source-documents.json`.
## Flow 1: Discord Request To Provider
1. `apps/bot/src/discord-bot.ts` receives a slash command or mention-driven request.
2. Permission checks run through `packages/core/src/permission-engine.ts`.
3. Void usage limits are applied through `packages/core/src/void-usage-rate-limiter.ts` backed by `packages/core/src/state-storage.ts`.
4. `packages/core/src/context-builder.ts` assembles request context, including recent interaction profile and any retrieval hints.
5. Provider selection goes through `packages/providers/src/index.ts`.
6. The bot either:
- answers directly through `local_llm`, or
- queues an owner job for the worker / `owner_codex` path.
## Flow 2: Owner Job Execution
1. `apps/worker/src/index.ts` polls approved jobs from durable state.
2. The worker claims a job and dispatches it to the configured provider.
3. `packages/providers/src/owner-codex-provider.ts` runs `codex exec` in the bounded lane, exposes the VoidBot MCP server, records traces, and enforces source grounding for repo/lore/project questions.
4. If the answer fits the Discord-safe lane, the worker posts it back.
5. If the task needs deeper work, the worker writes a handoff bundle under `.voidbot/artifacts/<job-id>/` and posts the handoff response.
## Flow 3: Retrieval And Indexing
1. `packages/rag/src/message-archive.ts` and `packages/rag/src/source-document-archive.ts` keep the raw corpora.
2. `packages/rag/src/retrieval-service.ts` translates history/source queries into vector lookups plus metadata filters.
3. `packages/rag/src/qdrant-vector-store.ts` executes the live vector lookups against separate history and source collections.
4. `scripts/index-source-repos.ts` and `scripts/git-post-push-index.mjs` drive detached source/lore reindex work.
5. `apps/worker/src/mcp-server.ts` exposes retrieval to Codex and other sessions through `search_history`, `get_message_context`, `search_sources`, `get_source_context`, and `list_indexed_repos`.
## Flow 4: Ops And Recovery
- `scripts/start-voidbot-stack.ps1`
- stack bootstrap, health checks, fresh build, stale-process cleanup, bot/worker restart, runtime status emission.
- `scripts/check-voidbot-operations.ps1`
- watchdog for process liveness, Qdrant, Postgres, Ollama, Discord auth, backup freshness, and offsite sync freshness.
- `scripts/backup-voidbot-state.ps1`
- local backup of Postgres, Qdrant snapshots, and RAG archives.
- `scripts/restore-voidbot-state.ps1`
- local restore path.
- `scripts/sync-voidbot-backup-offsite.ps1`
- verified offsite backup sync to the Qwen box.
- `scripts/voidbot-operations-dashboard-lib.ps1`
- dashboard rendering for the local ops surface.
## Storage Boundaries
- Postgres:
- jobs
- audit events
- interaction-memory events
- provider run records
- usage rate-limit state
- Qdrant:
- Discord history vectors
- source/lore vectors
- `.voidbot/`:
- archived raw corpora
- job artifacts and traces
- logs and status files
- backups and snapshots
The important scar is that these stores are split on purpose. Do not casually weld them back into one convenient blob and act surprised when it becomes a moon.

View file

@ -0,0 +1,38 @@
# VoidBot Implementation Plan
This is the current forward plan for the next larger organs. It is not a changelog and it is not allowed to become a duplicate brain for the canonical map.
## Current Aim
Use the new persistent project-state surfaces to keep future work source-grounded and rehydratable while the stack keeps getting more interconnected.
## Near-Term Organs
### 1. Public-Lane Hardening
- tighten moderation and abuse handling for non-owner traffic
- make budgets and rate-limit policy easier to inspect/administer
- preserve the current owner/public provider boundaries instead of letting them blur
### 2. Recovery That Is More Adult Than Hope
- add a real restore-drill cadence instead of stopping at backup verification
- reduce dependence on interactive workstation logon where practical
- keep watchdog signals and dashboard diagnostics honest when dependencies are degraded
### 3. Admin And Forensics Surfaces
- richer inspection around jobs, provider runs, tool usage, interaction memory, and rate-limit denials
- better “what happened?” answers without spelunking raw artifacts by candlelight
### 4. The Still-Scaffolded Paths
- replace the remaining scaffolded provider paths with funded or production-grade implementations
- move sandbox execution from policy theater to real constrained runners when the policy story is ready
## Rules For Editing This Plan
- update this note when the larger sequence of work changes
- do not dump volatile minute-by-minute status here
- if a lesson changes future belief, record it in `state/evidence.jsonl`
- if the current next action changes, update `state/map.yaml` and `notes/fresh-workspace-handoff.md`