Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

docs: require agents to fix or track discovered problems (#7804)

[._.]/3e17113cc855
diff --git a/AGENTS.md b/AGENTS.md
index 3070bbcf05..cec78d99fe 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -4,6 +4,15 @@ Guidance for every AI coding agent working in this repository — Claude Code, C
`AGENTS.md` is the canonical file. The `CLAUDE.md` beside it is a one-line `@AGENTS.md` import (Claude Code hardcodes that filename) — an import rather than a symlink so it survives a Windows checkout and a CLI that reads both names doesn't ingest the body twice. Both files exist at the root and at each nested location below. **Edit `AGENTS.md`; never put content in a `CLAUDE.md`.**
+## Don't leave trash on the floor
+
+Every agent must leave discovered problems either fixed and verified or captured in the owning project's issue tracker before finishing. This includes product bugs, broken expectations or assumptions, workflow/process defects, flaky tests, and concrete inefficiencies encountered during the task. “Pre-existing,” “unrelated,” and “out of scope” are reasons to file a follow-up, not reasons to lose the finding. Stay alert while doing the requested work; this does not require an unrelated full-repository audit.
+
+- **Fix now when bounded and safe; otherwise file.** Preserve the requested scope and unrelated work. Do not weaken assertions, skip tests, or retry until green to hide a failure. If the expectation is wrong, correct the contract and its test together.
+- **Route to the owner.** Shared slashdo command, renderer, or workflow defects belong in [atomantic/slashdo](https://github.com/atomantic/slashdo/issues); PortOS behavior, integration, configuration, and repository instructions belong in this repository's tracker. Use the configured repository remote for forks or managed apps. Cross-link issues only when both projects need changes. Use only the `atomantic` GitHub account for repositories owned by `atomantic`.
+- **Search before filing.** Reuse an existing issue that covers the finding; add new evidence when useful. For a new issue, include redacted evidence or reproduction steps, expected versus actual behavior, affected files, a chosen next step, and acceptance criteria. Distinguish a suspected flake from a reproduced cause. Follow the owning project's issue conventions; for PortOS, read [portos-file-issue](.claude/skills/portos-file-issue/SKILL.md) and the canonical label guidance in `server/lib/dispatchLabels.js`.
+- **Close the loop.** Report fixes and issue links in the handoff. Chat-only notes and TODO comments do not replace a filed issue. If tracker access fails, report the exact blocker and provide a ready-to-file issue body; never claim it was filed.
+
## Commands
Non-obvious invocations only — everything else is in `package.json` scripts.
@@ -20,12 +29,12 @@ cd client && npm test # Vitest (happy-dom) — component/unit tests
# inherits it aims at the real Postgres.
npm run test:db # DB-backed suites → portos_test ONLY (see Security Model)
-npm run pregate # BEFORE EVERY PUSH — runs what CI will run on this branch
+npm run pregate # BEFORE EVERY PUSH — local CI-plan checks; limits below
```
-**`npm run pregate` is the pre-push gate.** It asks CI's own planner (`scripts/ci-test-plan.js`) what this branch's diff selects, then runs that plan through CI's own runners — so a green pregate means the Linux lint and test jobs are green for the same reasons, not a second opinion that can drift. It takes seconds on a scoped diff, and it is the only local command that reaches the tree-wide guards nothing imports: the import budget (`server/lib/importScoping.test.js`), server→client import purity, union-merged catalog rows, generated-manifest drift. Those are the failures that otherwise cost a push and a CI round to discover — and the ones that reproduce only *after* a rebase, so **run it again after every rebase onto a moved `main`**, not just once before the first push.
+**Run `npm run pregate` on committed work before every push and again after rebasing onto a moved base.** It uses CI's planner and runners, including tree-wide guards for import boundaries, catalog merges, and generated manifests. It does not validate uncommitted changes.
-It plans from **committed** work only and says so when the tree is dirty; commit, then re-run. A diff big enough to force CI's full suite runs the always-run guards here instead (`--full` opts into everything). It never runs the DB suites, the Windows job, the client build, or the boot smoke — it names the ones your diff implicated and leaves them to CI, which is the only honest answer for a check this machine cannot perform.
+A full-suite plan runs only the always-run guards unless `--full` is supplied. DB suites, Windows, client build, and boot smoke are reported but not run by pregate. A green pregate proves only the stages it ran; required CI checks still apply.
## Test Strategy: Value Over Assertion Count
@@ -37,11 +46,11 @@ It plans from **committed** work only and says so when the tree is dirty; commit
## Security Model
-**Trust model (within one install).** Each install serves exactly one human, on a private network behind Tailscale VPN, never exposed to the public internet — one server process, one user. Concurrent *request* races, mutex locking on file I/O, and atomic-write patterns as defenses against competing actors are unnecessary; do not add or flag them. Simple re-entrancy guards (per-account sync locks against duplicate in-flight operations; serializing two write paths that mutate the same record) are fine and expected. PortOS intentionally omits CORS restrictions, rate limiting, and full concurrency controls — non-issues here. **"Single-user" means: do not defend against multiple competing humans inside one install. It does NOT mean "assume only one install exists."**
+**Trust model (within one install).** Each install serves exactly one human, on a private network behind Tailscale VPN, never exposed to the public internet — one server process, one user. Do not add multi-tenant defenses or locking solely for hypothetical competing users. One human can still trigger overlapping requests and background jobs: preserve crash-safe persistence and serialize operations that can overwrite the same record. Simple re-entrancy guards (such as per-account sync locks) are expected when duplicate in-flight work is possible. PortOS intentionally omits CORS restrictions, rate limiting, and full concurrency controls — non-issues here. **"Single-user" means: do not defend against multiple competing humans inside one install. It does NOT mean "assume only one install exists."**
**Authentication and HTTPS exist, but are OPT-IN and OFF by default.** Do not assume they are absent:
-- **Auth** — an optional instance password (`server/services/auth.js`, enforced by `server/services/authGate.js`) gates all of `/api/*` and `/data/*` when set, with a small always-public set (`/api/auth/status`, `/api/system/health`). Peers reach a password-gated instance via a per-peer Basic credential on the peer record, attached to every outbound hop by `peerFetch` (`server/lib/peerHttpClient.js`). **A PortOS-spawned agent authenticates with `PORTOS_API_TOKEN`** — a loopback session token the server mints and injects into the agent's environment (`server/services/agentApiAuth.js`). Any `curl` you write against this install's own API carries `-H "Authorization: Bearer ${PORTOS_API_TOKEN:-}"`; a bare `401 AUTH_REQUIRED` means the header was dropped, not that the endpoint is down. The variable is empty when no password is set (the gate ignores it) and is never given to a public-content review stage.
+- **Auth** — an optional instance password (`server/services/auth.js`, enforced by `server/services/authGate.js`) gates all of `/api/*` and `/data/*` when set, with a small always-public set (`/api/auth/status`, `/api/system/health`). Peers reach a password-gated instance via a per-peer Basic credential on the peer record, attached to every outbound hop by `peerFetch` (`server/lib/peerHttpClient.js`). **A PortOS-spawned agent authenticates with `PORTOS_API_TOKEN`** — a loopback session token the server mints and injects into the agent's environment (`server/services/agentApiAuth.js`). Any `curl` you write against this install's own API carries `-H "Authorization: Bearer ${PORTOS_API_TOKEN:-}"`; `401 AUTH_REQUIRED` means authentication was rejected; check for a missing, expired, or invalid token before diagnosing availability. The variable is empty when no password is set (the gate ignores it) and is never given to a public-content review stage.
- **HTTPS** — provisioned by `npm run setup:cert`; `:5555` flips to TLS with a loopback-only HTTP mirror on `:5553`. Peer hops set `rejectUnauthorized: false` ("Tailnet is the trust boundary"): between two tailnet nodes WireGuard supplies mutual auth, but a non-tailnet peer (plain LAN IP / non-`.ts.net` host, see `peerRequiresTailscale()`) gets no server authentication.
Because both are off by default, **never treat "the password is set" as an available guarantee** — gate on it explicitly, or design for the default posture.
@@ -87,7 +96,7 @@ The server is always user-facing on `:5555` (HTTP or HTTPS). The client runs on
### Per-directory conventions
-Client- and server-specific conventions live in nested memory files that load when you work in those trees (each an `AGENTS.md` with a bridge `CLAUDE.md`):
+Read the applicable nested instruction files before editing those trees (each an `AGENTS.md` with a bridge `CLAUDE.md`):
- `client/src/AGENTS.md` — UI conventions, routing/deep-linking, API error/save gating, the shared `Drawer` convention
- `client/src/components/dashboard/AGENTS.md` — widget registration, grid/arrange mechanics, ⌘K layout wiring
@@ -98,7 +107,7 @@ Client- and server-specific conventions live in nested memory files that load wh
### Command Palette & Voice Nav — shared backbone
-`server/lib/navManifest.js` is the single source of truth for navigation: `NAV_COMMANDS` + `resolveNavCommand()`, consumed by both the `⌘K` palette and the voice agent's `ui_navigate` tool. **Adding a `<Route>` without a `NAV_COMMANDS` entry leaves the page unreachable from `⌘K` and un-navigable by voice.** Invoke the `portos-add-page` skill for the entry shape, palette-action wiring, and the fail-fast guards.
+`server/lib/navManifest.js` is the single source of truth for navigation: `NAV_COMMANDS` + `resolveNavCommand()`, consumed by both the `⌘K` palette and the voice agent's `ui_navigate` tool. **Adding a `<Route>` without a `NAV_COMMANDS` entry leaves the page unreachable from `⌘K` and un-navigable by voice.** Read [.claude/skills/portos-add-page/SKILL.md](.claude/skills/portos-add-page/SKILL.md) for the entry shape, palette-action wiring, and fail-fast guards.
**Optional features gate navigation, not routes.** `server/lib/instanceFeatureRegistry.js` declares the optional per-install features (**Settings > Features**); a nav entry tagged `feature: '<id>'` (or in a `SECTION_FEATURE` section) drops out of `⌘K` and the sidebar while the feature is off, but its `<Route>` keeps working. The gate is applied CLIENT-side (`useInstanceFeatures` + `client/src/lib/navFeatures.js`), never by filtering the HTTP-cached manifest response, and a sidebar row still needs its own `NAV_PRESENTATION` entry in `client/src/lib/navPresentation.js`. **A feature toggle that arms background work must reconcile that work at toggle time, not only at boot** — one idempotent `reconcile…()` called from every path that moves the gate (`server/services/beeperArming.js` is the worked example). Feature groups, the resolution order, and the full contract: `docs/INSTANCE_FEATURES.md`.
@@ -110,7 +119,7 @@ In that source, `!read lib/<name>.md` means read `lib/slashdo/lib/<name>.md` whe
## Module Organization
-PortOS is large enough that re-implementing a helper is cheaper to *start* than finding what exists. Every directory holding reusable code carries a catalog `README.md` and an enumerable `index.js` barrel. **Before writing a helper, grep the catalog.**
+PortOS is large enough that re-implementing a helper is cheaper to *start* than finding what exists. Every directory holding reusable code carries a catalog `README.md` and an enumerable `index.js` barrel. **Before writing a helper, search the catalog.**
### Where new code lives
@@ -126,25 +135,9 @@ One concern per file. Tests live next to their source as `<name>.test.js`. Namin
### Discovery rule (BEFORE writing a helper)
-```bash
-grep -i "what you want to do" server/lib/README.md
-grep -i "what you want to do" client/src/lib/README.md
-grep -i "what you want to do" client/src/hooks/README.md
-grep -i "what you want to do" client/src/services/README.md
-```
-
-If a close match exists, **extend it or use it**. Only add a new module when none fits. Easy-to-miss helpers:
+Search the relevant `README.md` in `server/lib/`, `client/src/lib/`, `client/src/hooks/`, `client/src/utils/`, or `client/src/services/` with `rg -i`. Extend or reuse a close match before adding a module. The catalogs document APIs and examples; do not duplicate that inventory here.
-- `tryReadFile` (`server/lib/fileUtils.js`) — collapses `readFile(path).catch(() => null)`.
-- `atomicWrite` (`server/lib/fileUtils.js`) — `ensureDir + writeFile + JSON.stringify` in one call.
-- `createCollectionStore` (`server/lib/collectionStore.js`) — when a service outgrows its single-JSON-file shape (large per-record payload, frequent mutations), use this instead of another `readJSONFile` + `atomicWrite` + `createFileWriteQueue`. Lays out `data/{type}/{id}/index.json` under a type-level index stamping the storage-layout `schemaVersion`, with a per-id write queue and a `verifySchemaVersion` hook for the boot-time verifier. Full API in `server/lib/README.md`; worked example `server/services/universeBuilder.js` (migration 034).
-- `optionalBooleanMap(keys)` (`server/lib/validation.js`) — collapses `z.object(Object.fromEntries(KEYS.map(k => [k, z.boolean().optional()])))`.
-- `flattenCanonDescriptorFragments` / `mapCanonDescriptorFragments` (`server/lib/canonPrompt.js`, mirrored to client) — render `[{ prefix?, value }]` fragments to a sentence or array.
-- `copyToClipboard` / `writeClipboardSilently` / `readClipboard` (`client/src/lib/clipboard.js`) — safe on insecure-origin contexts. Never use `navigator.clipboard.writeText` inline.
-- `useLockToggle` (`client/src/hooks/useLockToggle.js`) — optimistic-PATCH lock toggle for any new lock button.
-- `useSseProgress` (`client/src/hooks/useSseProgress.js`) — generic JSON-frame EventSource subscriber; build new progress hooks on it.
-- `formatBytes` / `formatTimecode` / `formatDateShort` / `formatDurationMs` / `timeAgo` (`client/src/utils/formatters.js`) — never re-define formatters inside components.
-- `formatCount` / `formatUsd` (`client/src/utils/formatters.js`) — thousands-grouped, en-US-pinned (`2,762`, `$4,610.09`) for every user-facing count or amount. Never a raw integer or a bare `.toLocaleString()`; `client/src/numberFormattingConventions.test.js` fails CI on one. Full rule (including when to pass `{ fallback: '0' }`) in `client/src/AGENTS.md`.
+Required shared boundaries: use the clipboard helpers for insecure-origin support, `useSseProgress` for SSE subscriptions, and the shared formatters for user-facing numbers and amounts (see `client/src/AGENTS.md`). For file-backed storage, choose the backend under `docs/STORAGE.md` first, then consult `fileUtils.js` / `collectionStore.js`; a growing collection is not a reason to bypass the database policy.
### Maintenance rule (WHEN adding a public module)
@@ -189,34 +182,33 @@ This complements the Security Model (the deployed product) — this section gove
## Code Conventions
-- **No try/catch** — errors bubble to centralized middleware. **Exception:** PTY/child-process/`setTimeout`/`setInterval` callbacks and any code running *outside* the Express request lifecycle, where an uncaught throw crashes the Node process. At those boundaries, wrap hook invocation in try/catch and log via the emoji-prefixed `console.error` style. Async event handlers that mutate shared module-level state (e.g. the TUI spawner's `handleData`) must also be serialized — chain them onto a per-session/per-actor `Promise.resolve()` queue rather than firing concurrently.
+- **Error handling** — in Express request handlers, let errors bubble to centralized middleware instead of wrapping each handler in try/catch. Client code uses the shared error/save boundaries in `client/src/AGENTS.md`. **Process-boundary exception:** PTY/child-process/`setTimeout`/`setInterval` callbacks and any code running *outside* the Express request lifecycle, where an uncaught throw crashes the Node process. At those boundaries, wrap hook invocation in try/catch and log via the emoji-prefixed `console.error` style. Async event handlers that mutate shared module-level state (e.g. the TUI spawner's `handleData`) must also be serialized — chain them onto a per-session/per-actor `Promise.resolve()` queue rather than firing concurrently.
- **Functional programming** — no classes; use hooks in React.
- **Zod validation** — all route inputs validated via `lib/validation.js`.
-- **Command allowlist** — shell execution restricted to approved commands only.
-- **Every new page registers in the nav manifest** — a `<Route>` + sidebar link also means a `NAV_COMMANDS` entry in `server/lib/navManifest.js`. Invoke the `portos-add-page` skill.
+- **Command allowlists** — preserve the operator and unattended execution policies in `server/lib/commandSecurity.js` and the agent guard. These govern PortOS runtime execution; development-agent tool permissions are supplied by the host.
- **Selection lives in the URL, never in local state** — any view that opens/selects a specific record encodes it as a route param, so it's shareable, bookmarkable, and reachable from ⌘K and voice. Full contract in `client/src/AGENTS.md`.
- **Client UI conventions** (`client/src/AGENTS.md`) — no `alert`/`confirm`, `htmlFor`/`id` label pairing, mobile responsive, above the fold, no hardcoded localhost, alphabetical nav, user-facing number formatting, reactive local-state updates after mutations, silent-vs-toasting API errors, save gating for "Run Now" actions, and the shared tabbed `Drawer` convention.
- **Server conventions** (`server/AGENTS.md`) — schema parity when adding fields, serializing async PATCH races on shared records, batching high-frequency state writes, peer fan-out in record-creating tests, backup exclude anchoring, and stage-prompt template migrations.
-- **Socket-driven UI** — invoke the `portos-socket-ui` skill before wiring or debugging a socket-driven view.
+- **Socket-driven UI** — read [.claude/skills/portos-socket-ui/SKILL.md](.claude/skills/portos-socket-ui/SKILL.md) before wiring or debugging a socket-driven view.
- **Single-line logging** — emoji prefixes and string interpolation; never log full JSON blobs or arrays.
```js
console.log(`🚀 Server started on port ${PORT}`);
console.error(`❌ Failed to connect: ${err.message}`);
```
-- **LLM response merging — distinguish absent vs intentionally empty.** "Key absent" preserves the original; "key present with empty value" applies the clear. Don't use `.length` truthiness as the signal. Strings: `null`/`undefined` = absent, `""` = a clear (server helpers like `universeBuilderExpand.trimField` return `null` for non-strings). Arrays/objects: gate on `Array.isArray(parsed?.field)` / `typeof parsed?.field === 'object'` before falling back. Keep server-side merges and the client's `pick` helpers mirrored.
+- **LLM response merging — distinguish absent vs intentionally empty.** "Key absent" preserves the original; "key present with empty value" applies the clear. Don't use `.length` truthiness as the signal. Strings: `null`/`undefined` = absent, `""` = a clear (server helpers like `universeBuilderExpand.trimField` return `null` for non-strings). Arrays/objects: gate on `Array.isArray(parsed?.field)` / `parsed?.field !== null && typeof parsed?.field === 'object' && !Array.isArray(parsed.field)` before falling back. Keep server-side merges and the client's `pick` helpers mirrored.
- **Sentinel + validate to distinguish "not set / failed" from "present-but-empty / valid".** Never let *absent*, *failed-to-fetch*, or *invalid* collapse into the same value as *fetched-and-legitimately-empty* or *valid*; use an explicit sentinel and validate before falling through, not `x.length` or `x || fallback`. Canonical examples in the local-LLM backends: model-list caches use `null = not fetched` vs `[] = cached-empty` (`ollamaManager.js` `installedModels`, `lmStudioManager.js` `availableModels`); `getBackend()` validates the `.env` marker before falling back to `process.env` (`server/services/localLlm.js`); a reachable-but-list-failed backend surfaces an explicit `modelsError` rather than `0 models` (`lmStudioManager.js` `getLastListError`).
## Git Workflow
- **main**: active development. **release**: push `main` to `release` to trigger the GitHub Release workflow.
-- **Push pattern**: `npm run pregate && git pull --rebase --autostash && npm run pregate && git push` — the gate runs CI's own plan locally (see Commands). Run it **again after the rebase**: the import budget and the tree-wide guards are properties of your branch *merged with* the new `main`, so a rebase is exactly when a clean branch starts failing, and the first run cannot have seen it.
+- **Before pushing**: inspect branch/upstream and working-tree state, preserve unrelated changes, and commit the intended work. Fetch and integrate the workflow's intended base explicitly; a feature branch's tracking branch is not necessarily the default branch. Run `npm run pregate` on the resulting commits, then push. Re-run it after any subsequent rebase; do not blindly pull with autostash.
- **No per-branch changelog entries.** PRs do not write a changelog file or fragment — commit messages are the record, and `/do:release` synthesizes the release notes from the commit log since the last tag into `.changelog/v{version}.md`. **Write commit subjects/bodies for a human release-note reader** (see "Git commits and PRs" in the global instructions). Rationale: `.changelog/README.md`.
- **Release quality snapshot**: before a release, run `npm run quality:snapshot` on the install holding PortOS audit evidence. It publishes numeric local assessments only (no provider calls, no private run prose) into the repo-root `.quality.json`; with no local evidence it commits nothing and says so.
- **Versioning**: `package.json` reflects the last release. Do not bump during development — `/do:release` handles it.
-- After each feature or bug fix, run `/simplify`, then commit and push.
-- **Capture deferred work, and decide rather than park it.** Deferred refactors/cleanups go into a filed GitHub issue labeled `plan`, specific enough to pick up cold — never left only in chat. When the sole obstacle is an undecided design choice, **make the call yourself** and file it ready-to-work; `future` / `needs-input` are last resorts. Invoke the `portos-file-issue` skill before filing. The label vocabulary (dispatch axes, contributor labels, `planner:<model>`, colors, read-back) has exactly one source of truth — `MANDATORY_DISPATCH_HINT_GUIDANCE` in `server/lib/dispatchLabels.js` — so take it from there and never restate it in a doc, skill, or prompt that can drift from it.
+- After each feature or bug fix, review the diff for unnecessary complexity and duplication; use `/simplify` when available, otherwise perform the review directly. Follow the active task's delivery workflow for commit/push; a review-only request does not authorize shipping changes.
+- **Deferred work follows “Don't leave trash on the floor” above.** Make routine design decisions rather than parking an issue for input. PortOS issue labels come only from `MANDATORY_DISPATCH_HINT_GUIDANCE` in `server/lib/dispatchLabels.js`; do not duplicate the vocabulary in instructions.
- **Never link to AI conversation sessions.** No `claude.ai`, `chatgpt.com`, or other AI chat/session share URL (or "view this conversation" link) in a PR description, commit message, issue, or review comment. Reference durable artifacts instead: issue/PR numbers, commit SHAs, file paths.
-- If enough commits have accumulated to warrant a production release, pull the latest `main` and `release`, then run `/do:release` from `main`.
+- Release only as part of an authorized release workflow; commit count alone is not a release trigger. Follow `/do:release` and verify the current `main` and `release` state.
- **Archive approved design plans.** When a plan is approved out of plan mode, copy it from `~/.claude/plans/` to `./docs/plans/YYYY-MM-DD-<slug>.md` (date of approval) before implementing. See `docs/plans/README.md`.
## Documentation