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
2 changes: 1 addition & 1 deletion .agents/skills/engine-native-context/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ metadata:
- path: cli/src/engine.ts
lines: "1-53"
- path: cli/src/main.ts
lines: "1-89"
lines: "1-60"
- path: cli/src/engine-native/exec.ts
lines: "1-346"
- path: cli/src/engine-native/jq.ts
Expand Down
31 changes: 14 additions & 17 deletions .agents/skills/omp-sync-context/SKILL.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
name: omp-sync-context
description: "Use when changing the docks-kit omp harness: the omp sync pipeline (ompSync.ts, syncDispatch.ts engineSync), omp paths (ompPaths.ts), deploy, YAML merge, and retired-key prune of config.yml and models.yml (ompFileDeploy.ts, ompYaml.ts, ompRemovals.ts), the plugin pass and the docks marketplace retirement (ompPlugins.ts, ompKitPlugin.ts, ompChild.ts), the session model in kit.db (ompSession.ts, kitDb.ts), or the docks-kit omp free-session launcher (commands/omp.ts, ompOverlay.ts). Covers the dry-run boundary, the pi-intercom notice, the omp folder locks and the omp child environment (ompWriteFolders, spawnOmp, omp --fast), and private file modes. Not for cross-cutting sync flags (use sync-orchestration-context) or tool pins (use toolchain-context)."
description: "Use when changing the omp harness of docks-kit: the omp sync pipeline (ompSync.ts, syncDispatch.ts engineSync), omp paths (ompPaths.ts), deploy, YAML merge, and retired-key prune of config.yml and models.yml (ompFileDeploy.ts, ompYaml.ts, ompRemovals.ts), the plugin pass and the docks marketplace retirement (ompPlugins.ts, ompKitPlugin.ts, ompChild.ts), the kit store kit.db (kitDb.ts), or the root tier toggles docks-kit --fast and --ultrafast (commands/root.ts, ompFastMode.ts). Covers the dry-run boundary, the pi-intercom notice, the omp folder locks and the omp child environment (ompWriteFolders, spawnOmp, toggleTierUnderLocks), and private file modes. Not for cross-cutting sync flags (use sync-orchestration-context) or tool pins (use toolchain-context)."
user-invocable: false
metadata:
pattern: tool-wrapper
Expand All @@ -21,14 +21,12 @@ metadata:
lines: "1-123"
- path: cli/src/engine-native/ompYaml.ts
lines: "1-213"
- path: cli/src/engine-native/ompSession.ts
lines: "1-67"
- path: cli/src/engine-native/home.ts
lines: "1-15"
- path: cli/src/engine-native/kitDb.ts
lines: "1-240"
- path: cli/src/engine-native/ompOverlay.ts
lines: "1-264"
- path: cli/src/commands/omp.ts
lines: "1-426"
lines: "1-177"
- path: cli/src/commands/root.ts
lines: "1-133"
- path: cli/src/engine-native/syncDispatch.ts
lines: "1-215"
- path: cli/src/engine-native/atomicWrite.ts
Expand All @@ -42,7 +40,7 @@ metadata:

# omp Sync Context

EngineNative owns omp configuration deployment, plugin reconciliation, and the omp session model.
EngineNative owns omp configuration deployment, plugin reconciliation, the kit store, and the root tier toggles.
Use this context for omp-specific behavior only.

Pointers here name concepts, not coordinates — if a path or symbol moved, trust the stated purpose and re-locate it (grep the symbol) before acting.
Expand Down Expand Up @@ -95,8 +93,8 @@ and `bunx vitest run cli/test/unit/ompPaths.test.ts -t "prefers OMP_PROFILE even
- Change omp deployment file modes, backups, or restart triggers.
- Change the retired-entry prune in `ompRemovals.ts` — `syncOmpRemovals` or `syncOmpModelRemovals`.
- Change omp plugin reconciliation or the retirement of the former `docks` marketplace plugins.
- Change `readOmpSessionModel` or `writeOmpSessionModel` in `ompSession.ts`.
- Change the free-session run overlay in `ompOverlay.ts` or the launcher in `cli/src/commands/omp.ts`.
- Change the kit store in `kitDb.ts` — `withKitDb`, `MIGRATIONS`, `readCache`, or `writeCache`.
- Change the root tier toggles in `cli/src/commands/root.ts` — `toggleTierUnderLocks` — or in `ompFastMode.ts`.
- Change the omp pipeline call in `syncDispatch.ts` — `engineSync`.

Use `sync-orchestration-context` for a sync flag.
Expand Down Expand Up @@ -232,11 +230,10 @@ folder of `ompSync.ts ompWriteFolders`: the `ompPaths` `agentDir` and the
`agentDir`, an empty `<home>/<PI_CONFIG_DIR|.omp>` folder can appear.
- `~/.docks-kit/omp-plugin` and the retired upgrade-log folder that each sync
removes stay under the home, so the home lock covers them.
- `commands/omp.ts toggleFastUnderLocks` checks `<agentDir>/config.yml` before
- `commands/root.ts toggleTierUnderLocks` checks `<agentDir>/config.yml` before
any lock (`ompFastMode.ts requireDeployedConfig`). A missing file exits 2,
and the run creates no omp folder. Otherwise it runs `docks-kit omp --fast`
or `--ultrafast`
under the home sync lock and always the `agentDir` lock
and the run creates no omp folder. Otherwise it runs `docks-kit --fast` or
`--ultrafast` under the home sync lock and always the `agentDir` lock
(`syncDispatch.ts withHomeAndFolderLocks`), with the wait and the held line
of a sync.
- The locks cover the folder that the kit deploys into, not the target of a
Expand All @@ -250,7 +247,7 @@ folder of `ompSync.ts ompWriteFolders`: the `ompPaths` `agentDir` and the
Verify: `bunx vitest run cli/test/unit/syncLock.test.ts -t "shared omp agent folder"`,
`bunx vitest run cli/test/unit/syncLock.test.ts -t "shared omp data root"`,
`bunx vitest run cli/test/unit/syncLock.test.ts -t "keeps each omp child on the locked config root"`,
and `bunx vitest run cli/test/unit/ompFastMode.test.ts -t "omp --fast under the folder lock"`.
and `bunx vitest run cli/test/unit/ompFastMode.test.ts -t "--fast under the folder lock"`.

### Private Mode Pattern

Expand All @@ -274,7 +271,7 @@ and `bunx vitest run cli/test/unit/ompKitPlugin.test.ts -t "removes stale files

- `references/yaml-merge.md` - YAML merge contract and the retired-entry prune.
- `references/plugins-and-marketplace.md` - plugin constraints, the retirement of the former marketplace plugins, inventory contract, dry-run rules, and the pi-intercom notice.
- `references/state-and-launcher.md` - kit.db state store, session model, and the free-session launcher.
- `references/state-and-launcher.md` - kit.db store (schema, migrations, unused tables, too-new refusal, cache) and the root tier toggles.

## Change Checklist

Expand Down
113 changes: 50 additions & 63 deletions .agents/skills/omp-sync-context/references/state-and-launcher.md
Original file line number Diff line number Diff line change
@@ -1,74 +1,61 @@
# omp State Store And Launcher
# Kit Store And Root Tier Toggles

Part of `omp-sync-context`. Read the SKILL.md constraints first.

## Local State Store
## Kit Store

Store the omp session model in the SQLite store `~/.docks-kit/kit.db`, table
`omp_session`. The `harness_selection` table has had no use since 0.24.0 and
stays in `kitDb.ts MIGRATIONS[0]` only to keep schema 1; a `DROP` migration
would raise the schema and make older kits refuse the store.
Resolve that path from the engine home with `kitDb.ts kitDbFile`.
The SQLite store `~/.docks-kit/kit.db` holds the TTL cache `cache_entry`,
which `toolchain outdated` uses through `kitDb.ts readCache` and `writeCache`.
Schema 1 also keeps the tables `omp_session` and `harness_selection`. No code
reads or writes them. They stay in `kitDb.ts MIGRATIONS[0]` only to keep
schema 1, so older kits still open the store; a `DROP` migration would raise
the schema and make older kits refuse the store.
Resolve the store path from the engine home (`home.ts engineHome`) with
`kitDb.ts kitDbFile`.
Open the store only through `kitDb.ts withKitDb`, which applies the migrations.
Append a new migration to `kitDb.ts MIGRATIONS`; never edit a shipped entry.
A migration may drop and recreate `cache_entry`, because every row can be
fetched again (`kitDb.ts MIGRATIONS` comment).
Write the state directory with mode `0700`.
Chmod the database file to mode `0600`.
Never create the store on a read when neither `kit.db` nor `state.json` exists.

`withKitDb` imports the session model of a legacy `~/.docks-kit/state.json`
once, when `omp_session` is empty, and renames the file to
`state.json.migrated`. It imports no harness selection.
Each table has one writer.

`ompSession.ts readOmpSessionModel` treats a missing, corrupt, or too-new
store as no stored session model.
Never create the store on a read when `kit.db` does not exist.
A read of an existing store changes no permissions. SQLite still opens the
store read-write and in WAL mode, so a read can need write access to the
state directory and the database file; `readCache` treats a failed read as a
cache miss.

`withKitDb` refuses a store whose `user_version` is above
`KIT_DB_SCHEMA_VERSION` with `KitDbTooNewError`, which tells the user to run
`docks-kit update`. The check runs again under the migration lock, so a
newer kit that migrates in parallel is never downgraded.
`readCache` treats a missing, corrupt, or too-new store as a cache miss, and
`writeCache` ignores a failed write, because the cache is an optimization.
Cache rows carry the kit version as fingerprint, so a new release fetches
them again.
`sync` never opens `kit.db`.

Every `docks-kit omp` launch writes a run overlay under `kitCacheDir`;
only `--model` or `--pick` writes the `omp_session` table.
`docks-kit omp --fast` and `--ultrafast` write only `tier.openai` in the
deployed `config.yml`, through `ompFastMode.ts toggleDeployedOpenAiTier`.
The session model entry stores a required free model selector and an optional session thinking level.
Every overlay role, `advisor` included, runs that one level.
Compute the level once at set time from the catalog row of the chosen model.
Derive the level from that model's own ladder, never from the global ladder
constant: free-model ladders differ per model, and some publish no `medium`
or no ladder (`cli/docs/omp-models.md`; verify: `omp models --json`).
Store no level for a model without a ladder, and render a bare selector for it.
An invented level makes omp fail when the session starts, not when the user
chooses the model.
Treat a missing, blank, or malformed entry as no stored model, and resolve it
to `DEFAULT_OMP_SESSION_MODEL`.
Never throw on a corrupt entry, because a launcher that refuses to start is
worse than one that starts on the default free model.
Drop the level field when it is blank, so a stale level never
survives a switch to a level-free model.

Anchor storage at `ompSession.ts` — `readOmpSessionModel` and `writeOmpSessionModel` — the `omp_session` table opened through `kitDb.ts withKitDb`.
Anchor rendering at `ompOverlay.ts` — `ladderCeiling`, `planEffortChoice`, and `renderFreeOverlay` — per-model ladder derivation, the picker question set, and empty fallback chains, including the chains keyed by the free model at every level.

The launcher enforces the free model before omp starts.
Reject each forwarded flag that can select a model, in both forms and also after a `--`, because omp can read that `--` as a flag value.
Start omp with `launch` first, so a forwarded subcommand name becomes message text.
Pass the session model as an explicit `--model`, so a restored session model cannot replace it.
Set the three model variables in the child environment instead of removing them, because omp refills an unset variable from its `.env` files.
Check the session model against the free catalog of every candidate profile.
Do not claim that the launcher controls these paths, which can still select a paid model: model selection inside a running session, the `web` role and its chain, the model-kind roles, and extensions and hooks.
`cli/docs/omp-models.md` `### Model selection outside the launcher` owns the list.
Anchor input checks at `cli/src/commands/omp.ts` — `rejectedForwardedFlag` and `forwardedProfile` — the rejected model flags and the candidate profiles, scanned past `--`.
Anchor the launch at `ompOverlay.ts` — `buildOmpArgs` and `ompChildEnvironment` — `launch` first, the explicit `--model`, the model variables, and the `PI_CONFIG_FILES` append.

Verify the store:
`bunx vitest run cli/test/unit/ompSession.test.ts -t "creates no store when a read finds neither file"`,
`bunx vitest run cli/test/unit/ompSession.test.ts -t "imports no harness selection from a legacy state.json"`,
`bunx vitest run cli/test/unit/ompSession.test.ts -t "treats a corrupt SQLite store as a missing session model"`,
`bunx vitest run cli/test/unit/ompSession.test.ts -t "refuses a store from a newer schema"`,
and `bunx vitest run cli/test/unit/ompSession.test.ts -t "leaves no stale level behind when a level-free model overwrites a levelled one"`.

Verify the launcher and the overlay:
`bunx vitest run cli/test/unit/ompCommand.test.ts -t "rejects a model flag after a forwarded"`,
`bunx vitest run cli/test/unit/ompCommand.test.ts -t "refuses a launch whose model is free in the environment profile but not in a forwarded profile"`,
`bunx vitest run cli/test/unit/ompOverlay.test.ts -t "starts omp with launch, the overlay, and the session model at its level"`,
`bunx vitest run cli/test/unit/ompOverlay.test.ts -t "lists replaced variables in smol, slow, plan order"`,
`bunx vitest run cli/test/unit/ompOverlay.test.ts -t "renders a level-free model with bare chat selectors and no thinking keys"`,
and `bunx vitest run cli/test/unit/ompFastMode.test.ts -t "turns fast on and changes only tier.openai"`.
`bunx vitest run cli/test/unit/kitDb.test.ts -t "creates no store when a read finds no kit.db"`,
`bunx vitest run cli/test/unit/kitDb.test.ts -t "treats a corrupt SQLite store as a cache miss"`,
`bunx vitest run cli/test/unit/kitDb.test.ts -t "refuses a store from a newer schema and keeps its rows"`,
and `bunx vitest run cli/test/unit/kitDb.test.ts -t "keeps schema 1 with its unused tables, so an older kit still opens the store"`.

## Root Tier Toggles

`docks-kit --fast` and `docks-kit --ultrafast` are flags of the `docks-kit`
root command (`cli/src/commands/root.ts`). A subcommand does not accept them.
They write only `tier.openai` in the deployed `config.yml`, through
`ompFastMode.ts toggleDeployedOpenAiTier`, and they never open `kit.db`.
`--fast` toggles between `priority` and `none`; `--ultrafast` toggles between
`ultrafast` and `none`. Any value other than the ON tier of the flag switches
to that ON tier.
Both flags together exit 2 with `Pass either --fast or --ultrafast, not both`
before any lock or write.
`root.ts toggleTierUnderLocks` owns the config check and the locks (see
SKILL.md `### Folder Locks`).

Verify the toggles:
`bunx vitest run cli/test/unit/ompFastMode.test.ts -t "turns fast on and changes only tier.openai"`,
`bunx vitest run cli/test/unit/rootFlags.test.ts -t "turns fast mode on and off and changes only tier.openai"`,
`bunx vitest run cli/test/unit/rootFlags.test.ts -t "turns ultrafast mode on and off and changes only tier.openai"`,
and `bunx vitest run cli/test/unit/rootFlags.test.ts -t "with exit 2 before any lock or write"`.
Loading
Loading