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
7 changes: 5 additions & 2 deletions .agents/skills/omp-sync-context/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,11 @@ folder of `ompSync.ts ompWriteFolders`: the `ompPaths` `agentDir` and the
any lock (`ompFastMode.ts requireDeployedConfig`). A missing file exits 2,
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.
(`syncDispatch.ts homeAndFolderLocks`, a scoped Effect), with the wait and
the held line of a sync. A `TierToggleError` (a refusal that leaves
`config.yml` unchanged) or `LockWaitInvalid` (before any lock) exits 2;
`KitLockHeld`, `LockAcquireError`, `ConfigWriteError`, or a failed read
exits 1.
- The locks cover the folder that the kit deploys into, not the target of a
symlinked file. A lock in the target folder would put a lock file into a
folder that the user manages, such as a dotfiles repository. Residual: two
Expand Down
15 changes: 9 additions & 6 deletions .agents/skills/sync-orchestration-context/SKILL.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
name: sync-orchestration-context
description: "Use when editing docks-kit, cli/src/main.ts, cli/src/argv.ts, cli/src/argvValidate.ts, cli/src/engine.ts, or cli/src/engine-native index.ts, engineCtx.ts, syncDispatch.ts, syncConcurrency.ts, parseArgs.ts, parseHelp.ts, or modes.ts: sync flags, the sync locks (withSyncLock, withFolderLocks, folderLockPaths, withHomeAndFolderLocks, sync-lock.db, DOCKS_KIT_SYNC_LOCK_WAIT_MS), the failure ledger, or dry-run and idempotency rules. Not for toolchain (use toolchain-context), omp (use omp-sync-context), the lock module itself (use tidy-context), or the golden harness (use engine-native-context)."
description: "Use when editing docks-kit, cli/src/main.ts, cli/src/argv.ts, cli/src/argvValidate.ts, cli/src/engine.ts, or cli/src/engine-native index.ts, engineCtx.ts, syncDispatch.ts, syncConcurrency.ts, parseArgs.ts, parseHelp.ts, or modes.ts: sync flags, the sync locks (withSyncLock, withFolderLocks, folderLockPaths, homeAndFolderLocks, sync-lock.db, DOCKS_KIT_SYNC_LOCK_WAIT_MS), the failure ledger, or dry-run and idempotency rules. Not for toolchain (use toolchain-context), omp (use omp-sync-context), the lock module itself (use tidy-context), or the golden harness (use engine-native-context)."
user-invocable: false
metadata:
pattern: tool-wrapper
Expand Down Expand Up @@ -133,7 +133,7 @@ For the doctor report and Bun managed install, use
| Invocation | Path | Notes |
|-----------|------|-------|
| `./docks-kit <args>` | Host check, then Bun-from-source | The launcher rejects a host outside the support matrix, finds or installs Bun, runs `bun install --frozen-lockfile` when `node_modules/effect` is absent, and then runs `cli/src/main.ts`. It never runs a file in `cli/dist/`, so a leftover binary cannot mask newer source. |
| `cli/src/main.ts` | Raw-channel branch, then `prepareArgv`, then the Effect CLI root command | `DOCKS_KIT_ENGINE=native-raw` skips `prepareArgv` and Effect and calls `runEngineNative` directly with `{ envGlobals: true }`. Otherwise `sync` and `toolchain` run through `engine(args)`. Some other commands call engine-native modules directly, for example: the root tier toggles in `commands/root.ts` call `syncDispatch.ts withHomeAndFolderLocks` and `ompFastMode.ts toggleDeployedOpenAiTier`, and `tidy` and `scratch` call their own modules. `main.ts` adds `argv.ts COMMANDS`, the one subcommand list that the argv surfaces also use, to `commands/root.ts rootCommand` through `Command.withSubcommands`. A new subcommand needs an entry there and a line in the hand-written root overview `root.ts SUMMARY`. A new engine mode also needs a `case` arm in `index.ts runEngineNative`. |
| `cli/src/main.ts` | Raw-channel branch, then `prepareArgv`, then the Effect CLI root command | `DOCKS_KIT_ENGINE=native-raw` skips `prepareArgv` and Effect and calls `runEngineNative` directly with `{ envGlobals: true }`. Otherwise `sync` and `toolchain` run through `engine(args)`. Some other commands call engine-native modules directly, for example: the root tier toggles in `commands/root.ts` call `syncDispatch.ts homeAndFolderLocks` and `ompFastMode.ts toggleDeployedOpenAiTier`, and `tidy` and `scratch` call their own modules. `main.ts` adds `argv.ts COMMANDS`, the one subcommand list that the argv surfaces also use, to `commands/root.ts rootCommand` through `Command.withSubcommands`. A new subcommand needs an entry there and a line in the hand-written root overview `root.ts SUMMARY`. A new engine mode also needs a `case` arm in `index.ts runEngineNative`. |
| `cli/src/argv.ts` | `prepareArgv` | Validates and normalizes argv before Effect parses it. See § Public Argv Layer. |
| `cli/src/engine.ts` | `engine` | Exits 2 on an unsupported host or `DOCKS_KIT_ENGINE=bash`, then runs EngineNative in-process with `{ envGlobals: false }`. `native-raw` is the harness-private golden channel. |
| `cli/src/engine-native/index.ts` | `runEngineNative(argv, services?, options?)` | Builds `ctx` through `engineCtx.ts makeCtx`, then dispatches `toolchain` and `sync`. Any other first word also runs sync. `options.envGlobals` defaults to false; only the `main.ts` `native-raw` branch passes `{ envGlobals: true }`. |
Expand Down Expand Up @@ -257,10 +257,13 @@ each writer of such a folder also takes `<folder>/.docks-kit-sync-lock.db`
held. The mode applies only to the folders that the call creates: it runs no
chmod, and the lock keeps the folder mode (`privateDirectory: false`). The
omp pipeline then runs `ensureDirectory` (mode 0700) under the locks.
- `withHomeAndFolderLocks(home, folders, err, body)` takes the home lock and
the folder locks outside a sync run. `docks-kit --fast` and
`docks-kit --ultrafast` use it for the omp agent folder (see
`omp-sync-context`).
- `homeAndFolderLocks(home, folders)` is a scoped Effect that takes the home
lock and the folder locks outside a sync run, one `Effect.acquireRelease`
per lock. Each try (`kitLock.ts tryAcquireKitLock`) and its release run
without interruption; only the sleep between two tries can be interrupted.
It fails with `LockWaitInvalid`, `KitLockHeld`, or `LockAcquireError`.
`docks-kit --fast` and `docks-kit --ultrafast` use it for the omp agent
folder (see `omp-sync-context`).
- A dry run (`ctx.dryRun`) takes no folder lock and creates no folder. The
held line and the wait bound are those of the home lock.

Expand Down
2 changes: 1 addition & 1 deletion .agents/skills/tidy-context/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ metadata:
pattern: tool-wrapper
source_files:
- path: cli/src/engine-native/tidy.ts
lines: "1-1279"
lines: "1-1276"
- path: cli/src/engine-native/tidyReport.ts
lines: "1-509"
- path: cli/src/engine-native/kitLock.ts
Expand Down
27 changes: 27 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,32 @@
# Changelog

## 2026-12-01 - docks-kit 0.32.1: fast toggles accept an empty tier section

`docks-kit --fast` and `docks-kit --ultrafast` now accept a deployed
`config.yml` whose `tier` key omp reads as empty, such as `tier:`,
`tier: null`, `tier: ~`, or `tier: !!null` (DocksDocks/docks-kit#284). The
toggle writes a `tier` mapping with `openai` and keeps the other keys and the
comment of the old value. A `tier` value that omp reads as a string, a
number, a boolean, or a list still stops the toggle and leaves `config.yml`
unchanged.

Each toggle now reads `config.yml` as omp reads it, before and after the
rewrite. When the rewrite would change any other setting as omp reads it (a
YAML anchor, alias, or tag that the kit's YAML writer reads differently), the
toggle leaves `config.yml` unchanged and names the manual edit. It also
leaves `config.yml` unchanged when the legacy key `serviceTier` sets omp's
OpenAI tier: replace that key with the `tier` values that omp derives from
it, replace each alias of `serviceTier` with its value, then run the toggle
again. When another writer changes `config.yml` or the target of its link
during the check, the toggle leaves the file unchanged and asks you to run it
again.

A refusal of `config.yml` and an invalid `DOCKS_KIT_SYNC_LOCK_WAIT_MS` still
exit 2. A lock that cannot be opened (the message names the lock) and a
failed read or write of `config.yml` now exit 1 with their error, as a held
lock does; they exited 2 before. The success line shows a previous tier that
omp does not document as `another value`.

## 2026-12-01 - docks-kit 0.32.0: root fast tier flags replace the free-model launcher

The kit no longer starts omp sessions (DocksDocks/docks-kit#283). Run `omp`
Expand Down
2 changes: 1 addition & 1 deletion SoT/.omp/plugin/extensions/talk.js

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions cli/docs/flags.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,15 @@ over `ultrafast` selects `priority`. `--ultrafast` over `priority` selects
lock or writes a file, also when `--help` or `--version` is given. With
`--wizard`, a root tier flag exits 2 with
`--wizard cannot run a root tier toggle; run docks-kit --fast or docks-kit --ultrafast directly`.
In a `config.yml` whose root is a mapping, a `tier` that omp reads as absent,
null, or a mapping can toggle; omp reads `tier:`, `tier: null`, and
`tier: ~` as null. A refusal of `config.yml` (a missing file, invalid YAML,
a root or a `tier` of another shape, an active legacy `serviceTier`, a
rewrite that would change another setting as omp reads it, or a change by
another writer during the check) leaves `config.yml` unchanged and exits 2; so does an invalid
`DOCKS_KIT_SYNC_LOCK_WAIT_MS`, before any lock. A held lock, a lock that
cannot be opened, or a failed read or write of `config.yml` exits 1 with its
error.
The flags take no value: `docks-kit --fast false` stops with
`flag --fast does not take a value` and exit 2. The two flags belong to the
`docks-kit` root command only. A subcommand does not accept them:
Expand Down
86 changes: 42 additions & 44 deletions cli/src/commands/root.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ import { Console, Effect } from "effect";

import { bail } from "../engine";
import { p } from "../engine-native/exec";
import { errorMessage, printable } from "../engine-native/errorText";
import { engineHome } from "../engine-native/home";
import {
displayTier,
FAST_ON_TIER,
requireDeployedConfig,
toggleDeployedOpenAiTier,
ULTRAFAST_ON_TIER,
type FastToggle,
type OpenAiOnTier,
} from "../engine-native/ompFastMode";
import { ompPaths } from "../engine-native/ompPaths";
import { ExitError } from "../engine-native/parseArgs";
import { withHomeAndFolderLocks } from "../engine-native/syncDispatch";
import { homeAndFolderLocks } from "../engine-native/syncDispatch";

/** The names of the two root tier flags; parse, early validation, help, and messages use them. */
const FAST = "fast";
Expand Down Expand Up @@ -81,50 +81,33 @@ const SUMMARY: ReadonlyArray<string> = [
/**
* Toggle `tier.openai` to or from `onTier` under the sync lock of `home` and
* the folder lock of the omp agent folder, with the wait and the held line of
* a sync. A sync also merges `config.yml` there. Return 0 after the toggle, 1
* for a held lock, and 2 for a failed toggle or an invalid wait bound.
* a sync. A sync also merges `config.yml` there.
*/
async function toggleTierUnderLocks(
const toggleTierUnderLocks = Effect.fn("toggleTierUnderLocks")(function* (
home: string,
agentDir: string,
onTier: OpenAiOnTier,
): Promise<number> {
) {
const configPath = p(agentDir, "config.yml");
const err = (line: string) => console.error(line);
// Check config.yml before any lock. A missing file ends the run before the
// lock step can create the agent folder, and a folder that a sync creates
// during the home lock wait is never toggled without its folder lock.
try {
requireDeployedConfig(configPath);
} catch (error) {
err(error instanceof Error ? error.message : String(error));
return 2;
}
try {
return await withHomeAndFolderLocks(home, [agentDir], err, async () => {
let toggle: FastToggle;
try {
toggle = toggleDeployedOpenAiTier(configPath, onTier);
} catch (error) {
err(error instanceof Error ? error.message : String(error));
return 2;
}
const mode = TIER_MODES[onTier];
const state = toggle.next === onTier ? "ON" : "OFF";
console.log(
`omp ${mode.name} mode ${state} for OpenAI/Codex models: tier.openai ${toggle.previous} -> ${toggle.next} in ${configPath}`,
);
console.log(
`New omp sessions use it; in a running session, use ${mode.slash} or restart omp.`,
);
return 0;
});
} catch (error) {
// An invalid DOCKS_KIT_SYNC_LOCK_WAIT_MS prints its error line, then throws ExitError(2).
if (error instanceof ExitError) return error.code;
throw error;
}
}
yield* requireDeployedConfig(configPath);
const toggle = yield* Effect.scoped(
Effect.gen(function* () {
yield* homeAndFolderLocks(home, [agentDir]);
return yield* toggleDeployedOpenAiTier(configPath, onTier);
}),
);
const mode = TIER_MODES[onTier];
const state = toggle.next === onTier ? "ON" : "OFF";
yield* Console.log(
`omp ${mode.name} mode ${state} for OpenAI/Codex models: tier.openai ${displayTier(toggle.previous)} -> ${toggle.next} in ${printable(configPath)}`,
);
yield* Console.log(
`New omp sessions use it; in a running session, use ${mode.slash} or restart omp.`,
);
});

export const rootCommand = Command.make("docks-kit", { fast, ultrafast }, (config) =>
Effect.gen(function* () {
Expand All @@ -138,11 +121,26 @@ export const rootCommand = Command.make("docks-kit", { fast, ultrafast }, (confi
const onTier = config.ultrafast ? ULTRAFAST_ON_TIER : FAST_ON_TIER;
const home = engineHome(process.env);
const agentDir = ompPaths({ home, env: process.env, platform: process.platform }).agentDir;
const code = yield* Effect.tryPromise({
try: () => toggleTierUnderLocks(home, agentDir, onTier),
catch: (error) => (error instanceof Error ? error.message : String(error)),
}).pipe(Effect.catch((message) => bail(message)));
if (code !== 0) return yield* Effect.sync(() => process.exit(code));
// A refusal leaves config.yml unchanged and exits 2; a held lock, a lock
// that cannot be opened, or a failed read or write exits 1, as a sync does.
// Each line passes through `printable`: it can quote config.yml or a path.
const fail = (message: string, code: number) => bail(printable(message), code);
yield* toggleTierUnderLocks(home, agentDir, onTier).pipe(
Effect.catchTags({
TierToggleError: (error) => fail(error.reason.message, 2),
LockWaitInvalid: (error) => fail(error.message, 2),
KitLockHeld: (error) => fail(error.message, 1),
LockAcquireError: (error) => fail(error.message, 1),
ConfigWriteError: (error) => fail(error.message, 1),
PlatformError: (error) =>
fail(
error.cause === undefined
? error.message
: `${error.message}: ${errorMessage(error.cause)}`,
1,
),
}),
);
}),
).pipe(
Command.withDescription(
Expand Down
19 changes: 19 additions & 0 deletions cli/src/engine-native/errorText.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Predicate } from "effect";

/** The message of a caught value: the `message` of an `Error`, else its string form. */
export function errorMessage(cause: unknown): string {
return Predicate.isError(cause) ? cause.message : String(cause);
}

/**
* `text` with each control, format (bidirectional marks included), and line
* or paragraph separator character shown as `\uXXXX` (`\u{…}` above U+FFFF),
* so text from a file or a path cannot drive the terminal or reorder the
* line. Other characters, backslashes in Windows paths included, stay.
*/
export function printable(text: string): string {
return text.replace(/[\p{Cc}\p{Cf}\p{Zl}\p{Zp}]/gu, (char) => {
const code = char.codePointAt(0) ?? 0;
return code > 0xffff ? `\\u{${code.toString(16)}}` : `\\u${code.toString(16).padStart(4, "0")}`;
});
}
59 changes: 50 additions & 9 deletions cli/src/engine-native/kitLock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { DatabaseSync } from "node:sqlite";
import { setTimeout as sleepMs } from "node:timers/promises";

/** The default time between two tries. */
const POLL_MS = 50;
export const KIT_LOCK_POLL_MS = 50;
/** SQLite primary result code SQLITE_BUSY: another connection holds a conflicting lock. */
const SQLITE_BUSY = 5;

Expand Down Expand Up @@ -70,6 +70,53 @@ function tryBegin(connection: DatabaseSync): boolean {
}
}

/** Make the directory of the lock at `path` with mode 0700, and set its mode to 0700. */
export function preparePrivateLockDirectory(path: string): void {
const directory = dirname(path);
mkdirSync(directory, { recursive: true, mode: 0o700 });
chmodSync(directory, 0o700);
}

/**
* Open the lock database at `path`, with `busy_timeout` 0 so that a busy lock
* fails at once. Make its directory with mode 0700 first, unless
* `privateDirectory` is false.
*/
function openLockConnection(path: string, privateDirectory: boolean | undefined): DatabaseSync {
if (privateDirectory !== false) preparePrivateLockDirectory(path);
const connection = new DatabaseSync(path);
try {
connection.exec("PRAGMA busy_timeout = 0");
} catch (cause) {
connection.close();
throw cause;
}
return connection;
}

/**
* Try once to take the lock at `path`, with no wait. Return the lock, or
* `undefined` when another connection holds it. Any other failure closes the
* connection and throws. A caller that waits polls this between its sleeps.
*/
export function tryAcquireKitLock(
path: string,
options: Pick<KitLockOptions, "privateDirectory">,
): KitLock | undefined {
const connection = openLockConnection(path, options.privateDirectory);
try {
if (tryBegin(connection)) {
heldConnections.add(connection);
return { path, connection };
}
} catch (cause) {
connection.close();
throw cause;
}
connection.close();
return undefined;
}

/**
* Take the lock at `path`. Make its directory with mode 0700 when necessary,
* unless `privateDirectory` is false. Return `held` when another connection,
Expand All @@ -81,18 +128,12 @@ export async function acquireKitLock(
): Promise<KitLockResult> {
const now = options.now ?? Date.now;
const sleep = options.sleep ?? ((ms: number) => sleepMs(ms));
const pollMs = options.pollMs ?? POLL_MS;
const pollMs = options.pollMs ?? KIT_LOCK_POLL_MS;
const deadline = now() + options.waitMs;

if (options.privateDirectory !== false) {
const directory = dirname(path);
mkdirSync(directory, { recursive: true, mode: 0o700 });
chmodSync(directory, 0o700);
}
const connection = new DatabaseSync(path);
const connection = openLockConnection(path, options.privateDirectory);
try {
// A busy lock must fail at once; this loop does the wait.
connection.exec("PRAGMA busy_timeout = 0");
for (;;) {
if (tryBegin(connection)) {
heldConnections.add(connection);
Expand Down
Loading
Loading