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
8 changes: 4 additions & 4 deletions .agents/skills/engine-native-context/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ metadata:
pattern: tool-wrapper
source_files:
- path: cli/src/engine-native/index.ts
lines: "1-82"
lines: "1-98"
- path: cli/src/engine.ts
lines: "1-103"
lines: "1-92"
- path: cli/src/main.ts
lines: "1-78"
lines: "1-84"
- path: cli/src/engine-native/exec.ts
lines: "1-346"
- path: cli/src/engine-native/jq.ts
Expand Down Expand Up @@ -39,7 +39,7 @@ metadata:
lines: "1-18"
- path: cli/test/lib/goldenProveRed.ts
lines: "1-63"
updated: "2026-12-01"
updated: "2026-12-02"
---

# EngineNative Golden Contract
Expand Down
94 changes: 73 additions & 21 deletions .agents/skills/omp-sync-context/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,38 @@ metadata:
pattern: tool-wrapper
source_files:
- path: cli/src/engine-native/ompSync.ts
lines: "1-122"
lines: "1-151"
- path: cli/src/engine-native/ompFileDeploy.ts
lines: "1-116"
lines: "1-131"
- path: cli/src/engine-native/ompPlugins.ts
lines: "1-374"
lines: "1-436"
- path: cli/src/engine-native/ompKitPlugin.ts
lines: "1-99"
lines: "1-164"
- path: cli/src/engine-native/ompRemovals.ts
lines: "1-385"
lines: "1-466"
- path: cli/src/engine-native/failures.ts
lines: "1-16"
- path: cli/src/engine-native/ompPaths.ts
lines: "1-123"
lines: "1-128"
- path: cli/src/engine-native/ompYaml.ts
lines: "1-213"
lines: "1-255"
- path: cli/src/engine-native/home.ts
lines: "1-15"
- path: cli/src/engine-native/kitDb.ts
lines: "1-177"
- path: cli/src/commands/root.ts
lines: "1-133"
lines: "1-150"
- path: cli/src/engine-native/syncDispatch.ts
lines: "1-215"
- path: cli/src/engine-native/atomicWrite.ts
lines: "1-123"
- path: cli/src/engine-native/ompFastMode.ts
lines: "1-63"
- path: cli/src/engine-native/ompChild.ts
lines: "1-26"
updated: "2026-12-01"
lines: "1-32"
- path: cli/src/engine-native/fileText.ts
lines: "1-65"
updated: "2026-12-02"
---

# omp Sync Context
Expand All @@ -56,9 +58,47 @@ Preserve the two deployment roots and all private modes.
Create directories with mode `0700`.
Write files with mode `0600`.
Run `chmod` after each creation or write.
`mkdirSync` and `writeFileSync` apply `mode` only when they create a path.
`FileSystem.makeDirectory` and `writeFileString` apply `mode` only when they
create a path.
Run each write or copy with its chmod, each directory creation with its
chmod, each removal, and each `replaceFile` call as one started mutation
(`signalGuard.ts mutationRegion`), so neither an interrupt nor a handled signal
ends the run between the write and its chmod.
</constraint>

The omp passes (`ompFileDeploy.ts`, `ompKitPlugin.ts`, `ompPlugins.ts`,
`ompRemovals.ts`, `ompChild.ts`, `ompPaths.ts`) are Effect code on the
`FileSystem` service, with typed failures. A failed `FileSystem` read, write,
copy, chmod, directory creation, listing, or `lstat` of a pass fails the run
with its `PlatformError`, and a YAML merge or prune fails with
`OmpYamlInvalid`. These failures do not fail the run:

- An existence probe counts every failure as absent.
- A failed read of the marketplace registry: `ENOENT` and `ENOTDIR` mean that
the registry is missing, and any other error only warns.
- A failed removal of the retired upgrade log, or a failure of its status
line, only warns (`ompPlugins.ts removeUpgradeLog`).

The kit plugin prune removes a stale file with `unlinkSync` and an empty
folder with `rmdirSync`, each inside `Effect.try`. A failed file removal fails
the run with `PluginFileRemoveFailed`, and a failed folder removal with
`PluginFolderRemoveFailed`; each keeps the Node error and its message.
`FileSystem` has no removal of an empty folder alone, and the
`FileSystem.remove` adapter of Bun 1.4.5 reports `EPERM` as `EFAULT`.

The calls of the passes into `atomicWrite.ts`, `exec.ts` (through
`ompChild.ts spawnOmp`), the dependency probes, and the logger (also through
`recordFailure` and `deps.warnMissing`) stay behind `bridge.ts bridgeSync` or
`bridgePromise` until #297 and #298.
Every text read that a comparison or a parser uses goes through
`fileText.ts readTextKeepingBom`, which keeps a leading byte order mark, as
`readFileSync(path, "utf8")` did; `FileSystem.readFileString` drops it.
Every existence probe goes through `fileText.ts pathExists`, which follows a
symlink on every platform (`FileSystem.stat`), so a link to a missing target
is absent, and counts every failure as absent, as the synchronous `node:fs`
probe did. Do not use `FileSystem.exists`: on Windows it sees the link and
not its target.

<constraint>
Resolve every omp path through `ompPaths.ts ompPaths`, which mirrors upstream
`dirs.ts` `DirResolver`. Never join `ctx.home` with `.omp`.
Expand All @@ -74,7 +114,12 @@ The agent directory never moves under XDG; only `dataRoot` does, on Linux and
macOS, and only when the probed omp directory already exists.
Deploy `AGENTS.md`, `config.yml`, `models.yml`, and `mcp.json` to `agentDir`, and read
the active `marketplaces.json` from `dataRoot`.
Resolution stays env plus `existsSync` so a dry run runs no omp subcommand.
Resolution stays env plus an existence probe of the final candidate
(`fileText.ts pathExists`), so a dry run runs no omp subcommand. The probe
checks existence only, not the type: when a folder above the candidate is a
file, the candidate is absent and `dataRoot` falls back to the config root,
but when the candidate itself is a file, `dataRoot` is that path.
`ompPaths` is an Effect; the path math stays plain.
</constraint>

Plugin identity, the marketplace registry states of the retirement, the probe
Expand Down Expand Up @@ -256,20 +301,27 @@ and `bunx vitest run cli/test/unit/ompFastMode.test.ts -t "--fast under the fold
### Private Mode Pattern

```ts
// BAD — mode does not repair an existing permissive path.
mkdirSync(directory, { recursive: true, mode: 0o700 })
writeFileSync(target, content, { mode: 0o600 })

// GOOD — chmod enforces the private mode after each operation.
mkdirSync(directory, { recursive: true, mode: 0o700 })
chmodSync(directory, 0o700)
writeFileSync(target, content, { mode: 0o600 })
chmodSync(target, 0o600)
// BAD — mode does not repair an existing permissive path, and an interrupt
// or a signal can end the run between the write and the chmod.
yield* fs.makeDirectory(directory, { recursive: true, mode: 0o700 })
yield* fs.writeFileString(target, content, { mode: 0o600 })
yield* fs.chmod(target, 0o600)

// GOOD — chmod enforces the private mode, and each pair is one started mutation.
yield* mutationRegion(
Effect.andThen(fs.makeDirectory(directory, { recursive: true, mode: 0o700 }), fs.chmod(directory, 0o700)),
)
yield* mutationRegion(
Effect.andThen(fs.writeFileString(target, content, { mode: 0o600 }), fs.chmod(target, 0o600)),
)
```

Verify the private modes and the kit plugin rules:
`bunx vitest run cli/test/unit/ompKitPlugin.test.ts -t "writes the plugin package with the kit version and private modes"`
and `bunx vitest run cli/test/unit/ompKitPlugin.test.ts -t "removes stale files and empty directories from the plugin directory"`.
Verify the mutation region:
`bunx vitest run cli/test/unit/syncLock.test.ts -t "finishes a started deploy write with its chmod"`
and `bunx vitest run cli/test/unit/syncSignals.test.ts -t "between a deploy write and its chmod"`.

## References

Expand Down
14 changes: 13 additions & 1 deletion .agents/skills/omp-sync-context/references/yaml-merge.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ Validate both YAML roots as mappings when the deployed document is non-empty.
Return Source of Truth text when the deployed document is empty.
Reject invalid deployed YAML without writing the target.

`mergeOmpConfig` and `mergeOmpModels` stay plain functions and return an
`effect/Result`: the merged text, or an `OmpYamlInvalid` failure that keeps
the message of each refusal (`Invalid deployed omp <file> YAML: ...`,
`Deployed omp <file> YAML root must be a mapping`, and the SoT forms). A
merged document that the `yaml` library cannot write, such as an alias that
comes before its anchor, is also `OmpYamlInvalid`, with the message of the
library (`ompYaml.ts yamlText`). `syncMergedYaml` yields the `Result`
through `Effect.fromResult`, so the run fails with that message.

| Node relationship | Result |
|---|---|
| Both nodes are mappings | Merge recursively. |
Expand All @@ -51,7 +60,8 @@ Do not replace this parser with a line-based YAML merge.
Verify the merge:
`bunx vitest run cli/test/unit/ompYamlMerge.test.ts -t "drops deployed-only slash keys under retry.fallbackChains while keeping role siblings"`,
`bunx vitest run cli/test/unit/ompYamlMerge.test.ts -t "keeps a deployed-only slash key outside retry.fallbackChains"`,
`bunx vitest run cli/test/unit/ompYamlMerge.test.ts -t "throws for invalid deployed YAML"`,
`bunx vitest run cli/test/unit/ompYamlMerge.test.ts -t "fails with OmpYamlInvalid for invalid deployed YAML"`,
`bunx vitest run cli/test/unit/contract-omp-yaml.test.ts -t "alias before its anchor"`,
and `bunx vitest run cli/test/unit/ompBashPatterns.test.ts -t "puts user denies and prompts ahead of every kit allow"`.

## Retired-Entry Prune
Expand All @@ -75,6 +85,8 @@ It keeps a section-header comment above the deleted key. The header moves onto
the next key, or becomes the mapping's trailing comment when no key follows.
A dry run prints `[dry-run] prune` with the entry names and writes nothing.
An unparseable file gets a warning and stays untouched.
A pruned document that the `yaml` library cannot write fails the run with
`OmpYamlInvalid` and the message of the library, after the backup.

`ompRemovals.ts pruneRetired` follows the deployment rules in SKILL.md. It
writes through `atomicWrite.ts replaceFile` with mode `0600`, so a symlinked
Expand Down
51 changes: 35 additions & 16 deletions .agents/skills/sync-orchestration-context/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,19 @@ metadata:
- path: docks-kit
lines: "1-100"
- path: cli/src/main.ts
lines: "1-78"
lines: "1-84"
- path: cli/src/commands/root.ts
lines: "1-133"
lines: "1-150"
- path: cli/src/argv.ts
lines: "1-59"
- path: cli/src/argvValidate.ts
lines: "1-57"
- path: cli/src/argvSurface.ts
lines: "1-351"
- path: cli/src/engine.ts
lines: "1-103"
lines: "1-92"
- path: cli/src/engine-native/signalGuard.ts
lines: "1-113"
- path: cli/src/kitHome.ts
lines: "1-99"
- path: cli/src/payload.ts
Expand All @@ -30,7 +32,7 @@ metadata:
- path: cli/src/commands/update.ts
lines: "1-282"
- path: cli/src/engine-native/index.ts
lines: "1-82"
lines: "1-98"
- path: cli/src/engine-native/engineCtx.ts
lines: "1-86"
- path: cli/src/engine-native/syncDispatch.ts
Expand All @@ -50,14 +52,14 @@ metadata:
- path: cli/src/engine-native/modes.ts
lines: "1-69"
- path: cli/src/engine-native/ompSync.ts
lines: "1-155"
lines: "1-151"
- path: cli/src/engine-native/ompPlugins.ts
lines: "1-374"
lines: "1-436"
- path: cli/src/engine-native/bun.ts
lines: "1-120"
- path: cli/src/engine-native/toolchain.ts
lines: "1-237"
updated: "2026-12-01"
updated: "2026-12-02"
---

# Sync Engine Orchestration
Expand Down Expand Up @@ -138,7 +140,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` bypasses `prepareArgv` and the Effect CLI: it runs the `runEngineNative` Effect with `{ envGlobals: true }`, the live engine layers, and `BunServices.layer`, and exits with its code; a SIGINT exits 130 and a SIGTERM 143 at once. 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 branch in the mode selection of `index.ts runEngineNative`, which picks `modeToolchain` for `toolchain` and `engineSync` otherwise. |
| `cli/src/main.ts` | Raw-channel branch, then `prepareArgv`, then the Effect CLI root command | `DOCKS_KIT_ENGINE=native-raw` bypasses `prepareArgv` and the Effect CLI: it runs the `runEngineNative` Effect with `{ envGlobals: true }`, the live engine layers, and `BunServices.layer` inside `signalGuard.ts exitOnSignal(RAW_SIGNAL_EXIT_CODES)`, and exits with its code; a SIGINT exits 130 and a SIGTERM 143 at once, except inside a started mutation, which `deferSignalExit` lets settle first. 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 branch in the mode selection of `index.ts runEngineNative`, which picks `modeToolchain` for `toolchain` and `engineSync` otherwise. |
| `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 yields EngineNative in-process with `{ envGlobals: false }`, and maps a failed run or a defect to `engine operation '<args>' failed: <message>` (`engineFailureDetail`). `native-raw` is the harness-private golden channel. |
| `cli/src/engine-native/index.ts` | `runEngineNative(argv, options?)` | An Effect that reads `LoggerService`, `DependencyManagerService`, `PlatformService`, and `FileSystem` from its layers, builds `ctx` through `engineCtx.ts makeCtx`, provides it as `EngineContext`, then dispatches `toolchain` and `sync`. Any other first word also runs sync. It succeeds with the exit code and fails with `EngineFailure`. `options.envGlobals` defaults to false; only the `main.ts` `native-raw` branch passes `{ envGlobals: true }`. |
Expand Down Expand Up @@ -219,16 +221,31 @@ writing sync runs `lockedSync` in one lock scope (see § Sync Lock):

Each call into a module that a later child of plan #290 moves runs through
`bridge.ts bridgeSync` or `bridgePromise`, so an interrupt waits until that
step settles (`references/dispatch-flow.md`). The bridge text of a failure is
step settles (`references/dispatch-flow.md`). The omp passes are Effect code
(#296): only their calls into the logger, `atomicWrite.ts`, `exec.ts`, and
the dependency probes are bridged. The bridge text of a failure is
`bridge.ts failureText`, which never coerces the thrown value. `kitHome()`
(`cli/src/kitHome.ts`, #297) is bridged the same way, and `makeCtx` maps its
`LegacyStepFailed` to `KitHomeInvalid` with the original message and cause.
A failed `FileSystem` operation of a pass fails the run with its
`PlatformError`, a YAML merge or prune with `OmpYamlInvalid`, and a removal of
the kit plugin prune with `PluginFileRemoveFailed` or
`PluginFolderRemoveFailed`; `engine.ts engineFailureDetail` prints the
message of the Node error or of the YAML failure, as the bridge did. An
existence probe, the marketplace registry read, and the removal of the retired
upgrade log do not fail the run (`omp-sync-context`).

While an engine run is active, a SIGINT or SIGTERM ends the process at once,
as before the Effect seam, because a bridged pass cannot stop its `omp` or
installer child until #297: exit 130 on the public channel (`engine.ts
exitOnSignal`, installed only for the run) and 130 or 143 on the raw channel
(`main.ts`). The OS releases the locks with the process.
installer child until #297: exit 130 on the public channel (`signalGuard.ts
exitOnSignal(PUBLIC_SIGNAL_EXIT_CODES)` in `engine.ts`, installed only for the
run) and 130 or 143 on the raw channel (`exitOnSignal(RAW_SIGNAL_EXIT_CODES)`
in `main.ts`). The exception is a started mutation of a pass (a write or copy
with its chmod, a directory creation with its chmod, a removal, or a
`replaceFile` call): it runs in `signalGuard.ts mutationRegion`, which is
uninterruptible and inside `deferSignalExit`, so a signal during it is
recorded and the process exits with that code once the mutation settled. The
OS releases the locks with the process.
(verify: `bunx vitest run cli/test/unit/syncSignals.test.ts`)

The omp pipeline reads SoT from the embedded payload.
Expand Down Expand Up @@ -265,10 +282,12 @@ lock module).
returns 1 before the pipeline.
- Every lock of a sync is an `Effect.acquireRelease` in one scope, so it goes
when the scope closes: after the run, a failure, or an interrupt. An
in-process interrupt during a bridged pass waits until the pass settles, and
the locks stay held until then. A SIGINT or SIGTERM ends the process at once
(see § Dispatch Order), and the OS releases the locks with it.
(verify: `bunx vitest run cli/test/unit/syncLock.test.ts -t "keeps the sync lock and the omp folder locks until an interrupted bridged pass settles"` and `bunx vitest run cli/test/unit/syncLock.test.ts -t "lock wait deadline"`)
in-process interrupt during a bridged pass or a started mutation waits until
it settles, and the locks stay held until then. A SIGINT or SIGTERM ends the
process at once, except inside a started mutation, which `deferSignalExit`
lets settle first (see § Dispatch Order), and the OS releases the locks with
it.
(verify: `bunx vitest run cli/test/unit/syncLock.test.ts -t "keeps the sync lock and the omp folder locks until an interrupted bridged pass settles"`, `bunx vitest run cli/test/unit/syncLock.test.ts -t "finishes a started deploy write with its chmod"`, and `bunx vitest run cli/test/unit/syncLock.test.ts -t "lock wait deadline"`)

(verify: `bunx vitest run cli/test/unit/syncLock.test.ts -t "exits 1 with the held line and leaves HOME unchanged"`, `bunx vitest run cli/test/unit/syncLock.test.ts -t "takes no lock in a dry run"`, `bunx vitest run cli/test/unit/syncLock.test.ts -t "rejects an unknown argument with exit 2 before it takes the lock"`, `bunx vitest run cli/test/unit/engine-di.test.ts -t "with exit 2 before it takes a lock or writes an omp file"`, `bunx vitest run cli/test/unit/syncLock.test.ts -t "exits 2 when the lock wait is not a non-negative safe integer"`, `bunx vitest run cli/test/unit/syncLock.test.ts -t "DRY_RUN env global"`, and `bunx vitest run cli/test/unit/syncLock.test.ts -t "prints the help with -h and --help while another sync holds the lock"`)

Expand Down
Loading
Loading