This file is the binding governance and policy contract for the copilot repository. It records active product rules, critical interface contracts, core engineering principles, execution policy, and issue-tracking workflow. Runtime specifications, implementation constraints, current-state indexes, and service configuration live in RUNTIME.md. Keep historical delivery narrative in CHANGELOG.md, keep long operator manuals in dedicated docs, and treat old_code/ as archive-only.
Keep the remainder of this document focused on active governance rules and binding policy. Runtime facts, implementation constraints, and service configuration belong in RUNTIME.md. Dated implementation history belongs in CHANGELOG.md and docs/AGENTS_SESSION_HISTORY.md; extended tool manuals belong in dedicated docs such as docs/DESLOPPIFY_AGENT_GUIDE.md.
Term normalization for this document:
authoritative= source of truth that overrides summaries.current= as-built runtime state for this repository version.preferred= default choice when alternatives still exist.legacy-compat= incumbent compatibility behavior that must not be extended as new design.
Authority precedence (highest first):
ontology/plan/*.md,ontology/typedb/docs/*_contract_v1.md,ontology/typedb/schema/fragments/*/*.tql- This file's binding rule surfaces:
Hard Product Decisions,Critical Interfaces,Core Principles,Subagent Execution Policy,Issue Tracking with bd,Landing the Plane RUNTIME.mdcurrent-state and index surfaces: Technology Stack, Development Workflow, PM2 Services, Product Notes, Planning Artifacts, Deployment Endpoints, Portal Auth, Testing, and implementation constraints formerly inMinimal Agent Context- Historical records in
CHANGELOG.mdanddocs/AGENTS_SESSION_HISTORY.md
Note: Minimal Agent Context has moved to RUNTIME.md as implementation constraints; it is not governance content.
Modality map:
[RULE]= binding repo policy or contract.[FACT]= current runtime/product state that may change after an approved implementation/spec update.[INDEX]= pointer to a deeper runbook/spec/doc.[LEGACY-COMPAT]= active compatibility behavior preserved to avoid breaking integrations.
Use modality tags only when the whole section or bullet is intentionally homogeneous. If a section mixes descriptive runtime notes with binding instructions, leave the heading untagged and mark new binding bullets inline as [RULE] rather than pretending the whole section is purely [FACT] or [INDEX].
Historical bullets below still contain some canonical phrasing. In new edits, prefer the precise terms above (authoritative, current, preferred, legacy-compat); when reading older bullets, interpret canonical contextually rather than as a separate governance class. The same canonical interpretation rule applies when reading RUNTIME.md.
These decisions are part of the current platform contract and must be preserved unless a new approved spec replaces them.
- Voice source of truth is Copilot:
- UI:
https://copilot.stratospace.fun/voice/* - API: local
/api/voicebot/* - Legacy
voice.stratospace.funis not the implementation target for new changes.
- UI:
- Session close is REST-first:
- frontend/WebRTC closes via
POST /api/voicebot/session_done, - legacy alias
POST /api/voicebot/close_sessionmay remain server-side for compatibility, but clients must not fall back to it, - browser must not be the source of
session_donesocket emits.
- frontend/WebRTC closes via
- Voice controls contract is fixed to
New / Rec / Cut / Pause / Donewith unified behavior between page toolbar and FAB. - Full-track archive chunks are visible in monitor/runtime metadata but must not auto-upload until diarization rollout is enabled.
- ASR media handling is contract-bound:
- video inputs must be staged to extracted audio before transcription,
- transcription is single-file-first, with segmented fallback only after provider-limit checks,
- segmentation must not exceed the hard
8-chunk cap; low-bitrate re-encode is required before capped segmented fallback, - duration recovery must request
ffprobeformat_tags/stream_tagsand parse duration-like tag fallbacks before acceptingduration=0, - forensic fields
source_media_type,audio_extracted,asr_chunk_count,chunk_policy, andchunk_cap_appliedmust persist on both success and deterministic failure paths.
- Runtime isolation is mandatory for operational data:
- use deployment/database separation (dedicated DB/instance per environment),
runtime_tagis deprecated as an isolation mechanism and must not be treated as source-of-truth routing input,- legacy rows may still contain
runtime_tagduring transition, but runtime behavior must remain fail-fast and tag-agnostic.
- Production OpenAI-backed runtimes must use
backend/.env.productionas the authoritative env source for backend API, Voice workers/tgbot, and Fast-Agent PM2 agents; PM2 startup must not depend on inherited shell secrets for those services. - Realtime UX is mandatory for voice:
- upload must emit
new_message+session_update, - processing must emit
message_updatefor transcription/categorization progress. - summary notify flows for
SESSION_READY_TO_SUMMARIZEandsummary_savemust preserve stablecorrelation_id/idempotency_keyvalues through route, worker, and audit-log writes so retries dedupe against existing status rows. summary_telegram_sendaudit status is monotonic: retries may promotefailed/pending/queuedtodone, but oncedoneit must not be downgraded by later hook or webhook failures.
- upload must emit
- Retryable transcription failures must remain recoverable even for waiting sessions:
is_waitingis not a valid reason to skip message-level retry scans when rows carry canonical OpenAI recovery retry markers (for exampleinsufficient_quotaorinvalid_api_key),- after balance/key recovery, the periodic processing loop must be able to requeue those rows without manual DB repair.
- Session list behavior is contract-bound:
- quick filters:
Все,Без проекта,Активные,Мои, - deleted mode toggle (
Показывать удаленные) is part of persisted filter state, - filter state is restored after navigation/reload.
- quick filters:
- Voice/OperOps integration remains canonical:
CREATE_TASKSpayload shape isid/name/description/priority/...,CREATE_TASKSextraction is ontology-first: only bounded deliverables may materialize intotask_draft; coordination, inputs/accesses, references/ideas, and status/report statements must stay out of Draft materialization unless they are explicitly transformed into supporting context or comment enrichment,CREATE_TASKSfull recompute with no explicit chunk payload must use compact session raw transcript context (not session-id-only under-context fallback), and replay acceptance requires stable Draftrow_ididentity across consecutive recompute runs for unchanged semantics,- successful-but-empty
CREATE_TASKSMCP composites must resolve through structuredno_task_decisionoutput;create_tasks_empty_mcp_resultis an operational failure signal, not an accepted steady-state result after a successful composite, - the repo-local Codex CLI
CREATE_TASKSfallback must keep an OpenAI structured-output-compliant schema;link_existing_tasksfields that may be absent must remain required with explicit nullable unions instead of being omitted fromrequired, - raw-text
CREATE_TASKScontext builders must exclude garbage-flagged transcript rows from language sampling and replay context assembly, - garbage-detected or fully deleted voice messages are treated as deleted content for operator/analyzer surfaces: transcript projections, categorization projections, and
CREATE_TASKSraw-text assembly must exclude those rows by default, - transcript/categorization deletion is a unified exclusion contract:
deletion_reasonis mandatory, whole-garbage messages are deleted at the message level, mixed messages may delete only the affected segments, and user-driven deletes use the same exclusion semantics withdeletion_reason=user_decision, task_type_idis optional in Possible Tasks UI,- possible tasks are master records in
automation_taskswithtask_status=DRAFT_10, - Draft task editing is autosave-first across both inline row edits and the right-hand detail card; the primary manual action is
Run, notSave, andRunmust not materialize a row toREADY_10if autosave failed, process_possible_tasksnow materializes selected rows intoREADY_10,- accepted materialized rows must not be soft-deleted by possible-task cleanup,
- session
processors_data.CREATE_TASKSis legacy historical payload only and must not be used as the source of truth for Draft reads, - canonical Draft reads come from session-linked
DRAFT_10task docs and may exposediscussion_sessions[]/discussion_count;source_kindand stale refresh markers are compatibility metadata, not the semantic draft gate, - user-owned Draft fields follow a
user winscollision policy against concurrentCREATE_TASKSrecompute writes until the user explicitly releases the override, - stale
CREATE_TASKSrepair marker precedence is explicit: processor-level timestamps (job_queued_timestamp, request timestamps, finish timestamps) dominate stale-age evaluation; session_idtimestamp is fallback-only when explicit markers are absent. - transition reformulation for
CREATE_TASKSis bounded to one retry with machine-readable failures (create_tasks_transition_retries_exhausted/create_tasks_runtime_rejections_malformed); when the unresolved set is onlytask_draft_class_missing, runtime may discard those candidates and carry over persisted draft rows with explicitruntime_transition_carry_overevidence instead of silent zero-generation fallback. - the default Transcription/Categorization reading flow is operator-first: raw attachment projection/debug metadata does not belong in the normal row body; metadata signatures must render after the corresponding text block (never before it), and only actionable skip/error state may surface inline with the transcript/fallback body.
- transcript/categorization delete actions are destructive in phase 1: removing the last active speech-bearing row must mark the owning message as deleted, and delete events are not rollback-able through
rollback_event. - session task-count read surfaces are status-first and must include Draft rows in both
tasks_countandstatus_counts; a zero-task read is invalid when canonical Draft rows already exist for the session.
- Voice close:
POST /api/voicebot/session_done(and aliasPOST /api/voicebot/close_session) - Voice upload:
POST /api/voicebot/upload_audio - Voice summary save:
POST /api/voicebot/save_summary - Voice attachment upload:
POST /api/voicebot/upload_attachment(alias/api/voicebot/attachment) - Voice realtime namespace: Socket.IO
/voicebot+subscribe_on_session - Canonical voice session URL pattern:
https://copilot.stratospace.fun/voice/session/:session_id
All frontend and backend code MUST be written in TypeScript with strict type checking enabled.
Rules:
- Functions SHOULD have explicit type signatures for parameters and return values.
- Avoid
anyunless there is a clear, documented reason. - ES modules are the default in backend (
type: module).
Shared UI state MUST live in Zustand stores.
Rules:
- Shared or persistent UI state belongs in
app/src/store/*. - Components should stay focused on presentation and orchestration.
Frontend and backend MUST communicate via documented REST endpoints.
Rules:
{ data, error }is the canonical helper envelope for middleware-backed routes, but legacy Voice/CRM routes still return mixed raw payloads; callers must follow the per-route contract instead of assuming a universal envelope.- Authentication uses http-only cookies set by the Copilot backend.
- Auth is validated locally against
automation_performerswithpassword_hashand JWT.
React components MUST be functional and organized by domain.
Rules:
- Page components live in
app/src/pages/. - Reusable UI components live in
app/src/components/. - Ant Design provides the base UI system; Tailwind CSS handles custom layout/styling.
Socket.IO is the real-time layer for updates.
Rules:
- CRM/base Socket.IO event names are centralized in
backend/src/constants.ts; VoiceBot still has legacy live event literals (new_message,message_update,session_update,session_status) that remain part of the runtime contract until unified. - Clients should explicitly subscribe/unsubscribe to channels.
Preferred engineering principles for this repo:
- Favor KISS: keep solutions straightforward, remove dead fallbacks.
- Apply SOLID: explicit interfaces, dependency injection over global mutable state.
- Keep functions small and cohesive; extract utilities instead of growing branch-heavy handlers.
- Avoid hidden fallback paths that obscure control flow.
- Make failures explicit with structured errors; no silent recovery.
- Never suppress exceptions silently (
catch {}without logging is forbidden in backend paths). - Log I/O and external integration errors even when execution continues.
- Validate public API payloads with Zod at route boundaries.
- Derive TypeScript callback/input types from schemas (
z.input<typeof schema>). - Do not rely on untyped
anypayloads for voice/finops/crm route contracts.
- Follow SemVer (
MAJOR.MINOR.PATCH) for externally visible changes. MAJOR: breaking API/contract changes;MINOR: backward-compatible features;PATCH: fixes/refactors.- Keep dependencies aligned with current stable releases; avoid opportunistic downgrades unless explicitly required.
runtime_tagmay exist in historical records/logs, but new contracts must not rely on tag-family filtering for operational isolation.
- Default tracking surface is
bd; work should be represented by claimed/createdbdissues before changing repository artifacts. - Bounded execution is the default delivery mode when practical: prefer swarm/subagents with narrow, independently verifiable write surfaces.
- Parent thread remains responsible for final integration, acceptance, and required verification gates.
- Disk cleanup guardrail: do not delete or prune
/root/.codex/sessionsduring routine free-space cleanup. Treat it as retained session history unless the user gives an explicit purge instruction for that path. - Local OMX state guardrail: treat repo-root
.omx/as ephemeral agent/session state and keep it out of version control unless the user explicitly asks to persist those artifacts. - Environment backup guardrail: treat local
*.env*.bak*files as secret-bearing operator artifacts; preserve them locally when needed, but keep them out of version control and never include them in close-session pushes.
- Default execution mode for this repo: track work in
bdand prefer bounded swarm/subagent execution when practical; parent thread remains responsible for final integration and acceptance. - Default Codex subagent model for this repo is
gpt-5.3-codex; only use a different model when there is an explicit task-specific reason, and state that reason in the parent packet. - Real implementation work should be delegated to subagents when practical; the parent thread should stay focused on discovery, coordination, integration, and final acceptance.
- When a subagent is assigned a
bdissue, pass and executebd show <id> --jsonup front so the child thread reads the full unfiltered ticket payload instead of relying on a paraphrased summary or a field-filtered projection. - When implementation is governed by a spec, the parent packet must also include the literal spec path (for example
plan/<spec>.mdor an absolute path when cross-repo) and the child must read that spec before any repo reads/edits. - Parent-to-subagent issue packets must include the literal first-step command sequence, not just a prose reminder. Required pattern for spec-governed execution:
1. Run \bd show --json` and read the full unfiltered payload before any repo reads/edits.`2. Read the governing spec at \<path-to-spec.md>` before any repo reads/edits.`3. Use the ticket as the bounded execution scope and the spec as the normative contract; if the parent summary conflicts with either, ignore the parent summary.4. If the ticket and spec conflict materially, stop and report the mismatch to the parent instead of locally reinterpreting the contract.
spec_idremains the bd-native issue field for linking a governing specification document. In this repo, spec-governed execution should also duplicate the literal full path inmetadata.source_reffor machine-friendly consumption.- When
bd show <id> --jsonreturnsmetadata.source_ref, that field is the authoritative governing spec full path for the issue. - If
metadata.source_refis absent, fall back tospec_idas the governing spec reference. - If the parent packet provides a different spec path than
metadata.source_ref(orspec_idwhen no full-path duplicate exists), the child must stop and report the mismatch before any repo reads/edits beyond loading the ticket and the competing spec references. - Subagents MUST start with a clean history by default (
fork_context=false); do not spawn child agents with inherited conversation history unless there is an explicit, narrow reason to preserve prior thread state. - Parent prompts for subagents must be short, decision-complete, and scoped to one bounded write surface.
- Targeted verification can be delegated to subagents, but final integration verification and production deploy/smoke remain the responsibility of the parent thread after all patches are merged.
- Browser-based acceptance is part of the canonical verification flow for UI work; restart
mcp@chrome-devtools.servicebefore each live browser test cycle so MCP/CDP state is fresh. - Browser-based acceptance for layout work must include screenshot-level overlap checks; DOM/CSS assertions alone are not enough when footer/status widgets or task panes can visually collide.
- For ACP
/agents, do not treat the deterministic harness route as a substitute for the real host shell: acceptance must include the actual/agentssurface insideMainLayout, plus focused runtime-contract coverage for the auth-token -> ACP socket -> host-bridge lifecycle.
worker_*— bounded implementation agent for one write surface.postreview_*— independent code-review agent for implemented diffs (must not be the same thread as the worker).fix_*— focused incident/bugfix implementation worker when the issue scope is already forensics-backed.scholastic_*— spec/reasoning reviewer that runs ontology-first critique usinggreek-scholastic.
- Use this type for spec/prompt/requirements review where ontology correctness and category-mistake detection are required before implementation.
- Mandatory skill:
greek-scholastic: /root/.agents/skills/greek-scholastic/SKILL.md. - Default model remains
gpt-5.3-codexunless explicitly overridden by the parent with rationale.
- This protocol is mandatory for bug-fix waves and QA-first execution.
- Step 1: Digital forensics first (before edits):
- reproduce the bug in browser/runtime (prefer MCP Chrome tunnel for UI/console/network evidence),
- inspect related code paths and check
bdissues/changes for the previous 48h to avoid duplicate/fixed incidents, - record forensic evidence in
bd(symptoms, repro steps, logs, affected endpoints/files, candidate root-cause).
- Step 2: Implementation swarm:
- delegate bounded write-scope fixes to worker subagents (default
gpt-5.3-codex), - each worker packet must start with
bd show <id> --json, - parent thread integrates patches and resolves cross-file conflicts.
- delegate bounded write-scope fixes to worker subagents (default
- Step 3: Independent code-review swarm:
- run separate review subagents (not the same worker thread) on implemented changes,
- require severity-ordered findings with file/line references and deploy readiness verdict.
- Step 4: Verification gates:
- run isolated/targeted tests for each fixed bug first,
- then run full relevant test packs (
backendand/orapp), - for UI bugs, include screenshot-based overlap/layout validation.
- Step 5: BD synchronization:
- update each
bdissue with what was reproduced, what was changed, review verdict, and exact test commands/results, - only mark as ready/closed after all gates pass; if not reproducible, log "not reproduced" with evidence and keep decision trace.
- update each
IMPORTANT: This project uses bd (beads) for ALL issue tracking. Do NOT use markdown TODOs, task lists, or comment-based checklists.
- Dependency-aware: Track blockers and relationships between issues
- Git-friendly: Auto-syncs to JSONL for version control
- Agent-optimized: JSON output, ready work detection, discovered-from links
- Prevents duplicate tracking systems and confusion
Issue IDs in this repo look like copilot-<hash>.
Check for ready work:
bd ready --jsonCreate new issues:
bd create "Issue title" --description="Detailed context" --type task --priority 2 --json
bd create "Issue title" --description="Follow-up found while working" --type bug --priority 1 --deps discovered-from:<issue-id> --jsonClaim and update:
bd update <issue-id> --claim --json
bd update <issue-id> --priority 1 --jsonComplete work:
bd close <issue-id> --reason "Completed" --jsonbug- Something brokenfeature- New functionalitytask- Work item (tests, docs, refactoring)epic- Large feature with subtaskschore- Maintenance (dependencies, tooling)
0- Critical (security, data loss, broken builds)1- High (major features, important bugs)2- Medium (default, nice-to-have)3- Low (polish, optimization)4- Backlog (future ideas)
- Check ready work:
bd readyshows unblocked issues - Claim your task:
bd update <id> --claim - Work on it: Implement, test, document
- Discover new work? Create linked issue:
bd create "Found bug" --description="Details about what was found" --priority 1 --deps discovered-from:<parent-id>
- Complete:
bd close <id> --reason "Done"
bd keeps .beads/issues.jsonl in sync with your local DB:
- Exports to
.beads/issues.jsonlafter changes (5s debounce) - Imports from JSONL when newer (e.g., after
git pull)
Notes:
bd syncupdates JSONL but does not commit/push.- With hooks installed (
bd hooks install),pre-commitexports and stages.beads/*.jsonlautomatically. bd doctor --fixmay setskip-worktreeflags for.beads/*.jsonl, so they might not appear ingit statusuntil staged by the hook; that's expected.- Git hooks won't push for you; you still need
git push.
- ✅ Use bd for ALL task tracking
- ✅
bdis the default tracking surface for everyday work; do not rely on ad hoc side lists as primary planning - ✅ Prefer bounded swarm/subagent execution when practical, keeping scopes narrow and independently verifiable
- ✅ Before any task that changes project artifacts, ensure there is a bd issue covering that work
- ✅ Treat project artifacts broadly: code, documentation, tests, configs, scripts, migrations, generated project artifacts, and any checked-in file changes all require a bd issue
- ✅ Always use
--jsonflag for programmatic use - ✅ Link discovered work with
discovered-fromdependencies - ✅ Check
bd readybefore asking "what should I work on?" - ✅ Create only user-scoped or implementation-scoped issues; keep parser/orchestration probes in memory/logs
- ✅ Keep dated implementation history in
CHANGELOG.mdordocs/AGENTS_SESSION_HISTORY.md, not in rootAGENTS.md - ✅ Preserve recovered session-handoff notes in dedicated
plan/*-session-resume.mdartifacts or other scoped docs, not in rootAGENTS.md - ❌ Do NOT create markdown TODO lists
- ❌ Do NOT use external issue trackers
- ❌ Do NOT duplicate tracking systems
- ❌ Do NOT create synthetic temporary issues in bd (for example
tmp-*,*parse-check*), including--ephemeralprobe issues
For more details, see .beads/README.md, run bd quickstart, or use bd --help.
- If a task will modify any repository artifact, do not start from implicit context alone; create or claim the corresponding
bdissue first. - "Artifact change" includes:
- source code
- tests
- documentation
- configs/env examples
- scripts/runbooks
- schemas/migrations
- checked-in generated artifacts
- If the user asks for a direct file change and no suitable issue exists yet, create a focused
bdtask before editing.
- When sending Telegram messages through
tgbot__send_bot_messagewithparse_mode=MARKDOWNV2, do not send the first draft directly from ad hoc inline text. - First materialize the message as a fully escaped payload (prefer a local temp file or a clearly inspectable local string), then verify the final escaped text before calling the tool.
- Treat Telegram MarkdownV2 as a strict output format, not a forgiving renderer:
- escape all dynamic text,
- especially
>,_,*,[,],(,),-,.,!, and backslashes.
- Goal: avoid repeated live-send failures such as "Can\'t parse entities" caused by first-draft escaping mistakes.
When ending a work session, you MUST complete ALL steps below. Work is NOT complete until git push succeeds.
MANDATORY WORKFLOW:
- File issues for remaining work - Create issues for anything that needs follow-up
- Run quality gates (if code changed) - Tests, linters, builds
- Update issue status - Close finished work, update in-progress items
- PUSH TO REMOTE - This is MANDATORY:
git pull --rebase bd sync git push git status # MUST show "up to date with origin" - Clean up - Clear stashes, prune remote branches
- Verify - All changes committed AND pushed
- Hand off - Provide context for next session
CRITICAL RULES:
- Work is NOT complete until
git pushsucceeds - NEVER stop before pushing - that leaves work stranded locally
- NEVER say "ready to push when you are" - YOU must push
- If push fails, resolve and retry until it succeeds
Runtime specifications, implementation constraints, current-state indexes, and service configuration live in RUNTIME.md. That file covers Technology Stack, Development Workflow, PM2 Services, Product Notes, Planning Artifacts, Deployment Endpoints, Portal Auth, Testing, and the implementation constraints formerly maintained in this file under Minimal Agent Context.