This file is loaded by qcode on every session and injected into the system prompt. Keep it short (<2k tokens). Model-agnostic by design.
qcode is a local coding agent that runs on the user's Mac via @qvac/sdk (Tether's official SDK, v0.8.3). Controlled from iPhone via a PWA served by an Express daemon. Multi-modal: voice input (Whisper), vision (Qwen3-VL), and delegated inference (P2P) are all opt-in features.
Stack: TypeScript + Node 22+, ESM strict, @qvac/sdk for inference, Express for HTTP,
vanilla JS PWA (no build step). Design system matches qvac.tether.io (Inconsolata mono +
#16E3C1 mint accent).
Primary model: Qwen3 1.7B Q4 via SDK registry. Native tool calling via
completion({ tools }) with Zod schemas. The SDK handles chat template formatting.
Architecture: a capability router dispatches each request to the best backend:
local (full agent loop with Qwen3 1.7B) or delegated peer (via @qvac/sdk P2P over
Hyperswarm). Add a new backend by implementing AgentBackend and calling
router.register().
- ES modules only. 2-space indent. Prettier defaults.
- No
anyin TypeScript (strict mode). Useunknown+ narrowing. - No abbreviations (
userName, notusrNm). No narrative comments. - Small, targeted changes. Never rewrite working code.
- Every new backend file goes in
src/agent/backends/. - Every new frontend logic goes in
public/app.js(vanilla JS, no framework).
src/agent/- agent loop, executor, models (SDK wrapper), prompt, tool-schemas, router, memory, condensesrc/agent/backends/- local-llm.ts (tier 1), delegated-peer.ts (tier 2)src/server/- Express routes, SSE, auth, sessions, features, voice, vision, model-providersrc/tools/- tools the agent can call (read/write/list/grep/bash/diff/propose_plan)src/state/- disk persistencesrc/utils/- paths, loggerpublic/- PWA (index.html, app.js, style.css)docs/- PROJECT-STATUS.md, PEER-SETUP.md, DEMO-SCRIPT.mdscripts/- peer-provider.mjs, smoke-test.sh, multi-turn-test.sh.qcode-state/- runtime state (auth-key, features.json, sessions.json), gitignored
src/agent/loop.ts- ReAct loop. SDK native tool calling + fallback text parser. Context window management (sliding window, token budget). Reflection nudge after 2 consecutive failures. Strips Qwen3<think>blocks.src/agent/tool-schemas.ts- Zod schemas for 8 tools, passed asToolInput[].src/agent/models.ts-QvacSdkBackendwraps @qvac/sdk. Loads from registry constants, file paths, or delegate config. Consumes tokenStream + toolCallStream.src/agent/prompt.ts- compact system prompt (~500 tokens). No tool catalog prose.src/agent/backends/delegated-peer.ts- routes heavy tasks to peer backend via P2P.src/server/index.ts- daemon entry. Boots SDK, loads model, optional fire-and-forget peer load via mutablepeerBackendRefholder.src/server/features.ts- opt-in features (voice, vision, delegated). SDK downloads on demand.public/app.js- PWA with SSE streaming, lastEventId tracking, voice, model picker.
qcode.md(this file) - project memory for the agent.models/- external assets (gitignored)..qcode-state/- runtime state.
- 8 GB M3 Mac target. Context window budget is ~8192 tokens total. System prompt + docs must stay under 3k combined. Sliding window + token budget in loop.ts enforces this.
- Local models, not Claude. Qwen3 1.7B via @qvac/sdk. Enforce behavior programmatically.
- All features are opt-in. Whisper/vision/delegated downloads happen only on explicit
user enable. Respect
isFeatureEnabled(id)in gates. - Permission modes matter: writes and bash are gated except in
auto-writesandyolo.