Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(ci): move wakeshift env-key into src/core so pglite-snapshot cache keys cover it

garrytand22eb30a38aa
diff --git a/docs/architecture/key-files/wakeshift.md b/docs/architecture/key-files/wakeshift.md
index d2cfdc8651..9176ffaf90 100644
--- a/docs/architecture/key-files/wakeshift.md
+++ b/docs/architecture/key-files/wakeshift.md
@@ -3,4 +3,4 @@
[Subsystem index](../KEY_FILES.md). Read only the entries relevant to your change.
Current behavior and load-bearing invariants; history belongs in Git and CHANGELOG.
-- `src/core/ops/wakeshift.ts` + `src/core/wakeshift/{client,config,env-key,events,drain}.ts` + `src/commands/wakeshift.ts` + `src/commands/doctor/checks/wakeshift.ts` — report back to agent conversations through Wakeshift (docs/guides/wakeshift.md), off by default. `client.ts` is the in-repo HTTP client (no SDK): key parsing (`wst_` + 50 base58 with a CRC32; legacy formats refused), a fresh EdDSA `app+jwt` assertion per request, one `fetch` with a 10 s timeout and no retry, loopback-only http. `config.ts` holds the host-only state: `wakeshift.enabled`/`url` in the file plane, the key (WAKESHIFT_API_KEY, which `env-key.ts` moves out of the environment on every config load so children never inherit it, the first value seen winning; else a 0600 `~/.gbrain/wakeshift.key`), the 0600 HMAC secret and the opaque Wakeshift user (HMAC over brain and principal); `wakeshiftPublished` is publish gate `mcp.publish_wakeshift`, which `mcp/publish-gates.ts` resolves from the file plane and key presence only (never the DB plane; not in `PUBLISH_GATE_KEYS`). `watch_job` runs the get_job owner fence (exported from `ops/jobs.ts`), subscribes the conversation (`once`, 7 d), stores a `wake_subscriptions` row (migration v290), rolls the subscription back when the insert fails, and hands Wakeshift's addition to dispatch through `ctx.emitToolTail` (the result's last text block plus `_meta` keys); `ctx.mcpCaller` (client name, User-Agent, request `_meta`) is set by the stdio and both HTTP transports. `drain.ts` is pull reconciliation: `gbrain serve` and `MinionWorker.start` run a 5 s unref'd timer, `gbrain jobs work` (PGLite) a final pass; at most 20 leased rows a tick, the emit id `<event>:<target>:<finished_us>:<status>:<row>:<namespace>` (12 hex of the watch's user and creation time, so brains on one key never collide), the claim re-checking backoff and attempts, a settle only under the claim's lease, the principal re-checked before each emit, 5 attempts on 30 s/2 m/8 m/30 m (429 honours Retry-After, other 4xx final), dead/revoked/expired rows ended at Wakeshift once. The payload (`events.ts`) is a pointer: job id, kind, status, times, next call; never page text. The CLI (`enable` with consent, the owner-only member check, GET /app and the manifest merge; `disable`, `status`, `test`) is the only writer of the enabled flag. Tests: `test/wakeshift-client.test.ts`, `test/wakeshift.serial.test.ts` (repo-less PGLite against `test/helpers/fake-wakeshift.ts`), `test/e2e/wakeshift-postgres.test.ts`.
+- `src/core/ops/wakeshift.ts` + `src/core/wakeshift/{client,config,events,drain}.ts` + `src/core/wakeshift-env-key.ts` + `src/commands/wakeshift.ts` + `src/commands/doctor/checks/wakeshift.ts` — report back to agent conversations through Wakeshift (docs/guides/wakeshift.md), off by default. `client.ts` is the in-repo HTTP client (no SDK): key parsing (`wst_` + 50 base58 with a CRC32; legacy formats refused), a fresh EdDSA `app+jwt` assertion per request, one `fetch` with a 10 s timeout and no retry, loopback-only http. `config.ts` holds the host-only state: `wakeshift.enabled`/`url` in the file plane, the key (WAKESHIFT_API_KEY, which `env-key.ts` moves out of the environment on every config load so children never inherit it, the first value seen winning; else a 0600 `~/.gbrain/wakeshift.key`), the 0600 HMAC secret and the opaque Wakeshift user (HMAC over brain and principal); `wakeshiftPublished` is publish gate `mcp.publish_wakeshift`, which `mcp/publish-gates.ts` resolves from the file plane and key presence only (never the DB plane; not in `PUBLISH_GATE_KEYS`). `watch_job` runs the get_job owner fence (exported from `ops/jobs.ts`), subscribes the conversation (`once`, 7 d), stores a `wake_subscriptions` row (migration v290), rolls the subscription back when the insert fails, and hands Wakeshift's addition to dispatch through `ctx.emitToolTail` (the result's last text block plus `_meta` keys); `ctx.mcpCaller` (client name, User-Agent, request `_meta`) is set by the stdio and both HTTP transports. `drain.ts` is pull reconciliation: `gbrain serve` and `MinionWorker.start` run a 5 s unref'd timer, `gbrain jobs work` (PGLite) a final pass; at most 20 leased rows a tick, the emit id `<event>:<target>:<finished_us>:<status>:<row>:<namespace>` (12 hex of the watch's user and creation time, so brains on one key never collide), the claim re-checking backoff and attempts, a settle only under the claim's lease, the principal re-checked before each emit, 5 attempts on 30 s/2 m/8 m/30 m (429 honours Retry-After, other 4xx final), dead/revoked/expired rows ended at Wakeshift once. The payload (`events.ts`) is a pointer: job id, kind, status, times, next call; never page text. The CLI (`enable` with consent, the owner-only member check, GET /app and the manifest merge; `disable`, `status`, `test`) is the only writer of the enabled flag. Tests: `test/wakeshift-client.test.ts`, `test/wakeshift.serial.test.ts` (repo-less PGLite against `test/helpers/fake-wakeshift.ts`), `test/e2e/wakeshift-postgres.test.ts`.
diff --git a/scripts/core-world-reads-baseline.tsv b/scripts/core-world-reads-baseline.tsv
index 446ea31887..b2882d6517 100644
--- a/scripts/core-world-reads-baseline.tsv
+++ b/scripts/core-world-reads-baseline.tsv
@@ -1146,7 +1146,7 @@ src/core/verbs/usage-log.ts fs_import 1 W7: filesystem boundary moves to the loc
src/core/wakeshift/config.ts fs_import 1 stays: the Wakeshift key and HMAC secret are host files (0600) by design, never engine settings (docs/guides/wakeshift.md#the-key)
src/core/wakeshift/config.ts load_config 1 stays: wakeshift.enabled is read from the host file plane only, so no DB-plane or remote writer can turn reporting back on
src/core/wakeshift/config.ts process_env 2 stays: an explicit env argument is compared with process.env to decide whether the key moves into env-key.ts
-src/core/wakeshift/env-key.ts process_env 2 stays: WAKESHIFT_API_KEY is taken out of the process environment whenever config loads, so child processes do not inherit the signing key
+src/core/wakeshift-env-key.ts process_env 2 stays: WAKESHIFT_API_KEY is taken out of the process environment whenever config loads, so child processes do not inherit the signing key
src/core/workspace-push.ts fs_import 1 W7: filesystem boundary moves to the local app
src/core/workspace-push.ts process_env 2 W6: settings plane out of the core
src/core/workspace-push.ts spawn_import 1 W7: process-wide effects move to src/cli
diff --git a/src/core/gbrain-env-file.ts b/src/core/gbrain-env-file.ts
index 3ed0a779f8..19ea3d9bc6 100644
--- a/src/core/gbrain-env-file.ts
+++ b/src/core/gbrain-env-file.ts
@@ -13,7 +13,7 @@
import { existsSync, readFileSync } from 'fs';
import { join } from 'path';
import { splitDotenvLines } from './env-trust.ts';
-import { takeWakeshiftEnvKey } from './wakeshift/env-key.ts';
+import { takeWakeshiftEnvKey } from './wakeshift-env-key.ts';
// KEY=VALUE with a POSIX-shaped name. `export KEY=...` is deliberately not
// accepted: this is an env FILE, not a shell script (same stance as Bun's
diff --git a/src/core/wakeshift/env-key.ts b/src/core/wakeshift-env-key.ts
similarity index 100%
rename from src/core/wakeshift/env-key.ts
rename to src/core/wakeshift-env-key.ts
diff --git a/src/core/wakeshift/config.ts b/src/core/wakeshift/config.ts
index 80c13c8a2e..dbf3e9ba65 100644
--- a/src/core/wakeshift/config.ts
+++ b/src/core/wakeshift/config.ts
@@ -4,7 +4,7 @@
*
* - `wakeshift.enabled` / `wakeshift.url` in the file plane (~/.gbrain/config.json), written only by the
* trusted local `gbrain wakeshift enable|disable`, so a remote caller can never turn reporting back on;
- * - the key: WAKESHIFT_API_KEY (moved out of this process's environment whenever config loads, env-key.ts, so
+ * - the key: WAKESHIFT_API_KEY (moved out of this process's environment whenever config loads, wakeshift-env-key.ts, so
* child processes do not inherit it), else ~/.gbrain/wakeshift.key, which must be 0600 (a looser file is ignored and doctor says so);
* - the HMAC secret ~/.gbrain/wakeshift.secret (0600, random): the Wakeshift `user` is the first 32 hex of
* HMAC-SHA256 over (brain, principal), never an email, name or token.
@@ -15,9 +15,9 @@ import { createHash, createHmac, randomBytes } from 'node:crypto';
import { readFileSync, statSync, writeFileSync } from 'node:fs';
import { gbrainPath, loadConfig, type GBrainConfig } from '../config.ts';
import { normalizeWakeshiftUrl, parseWakeshiftKey, wakeshiftClient, type WakeshiftApi, type WakeshiftKey } from './client.ts';
-import { WAKESHIFT_KEY_ENV, takeWakeshiftEnvKey } from './env-key.ts';
+import { WAKESHIFT_KEY_ENV, takeWakeshiftEnvKey } from '../wakeshift-env-key.ts';
-export { WAKESHIFT_KEY_ENV, resetWakeshiftEnvKeyForTests } from './env-key.ts';
+export { WAKESHIFT_KEY_ENV, resetWakeshiftEnvKeyForTests } from '../wakeshift-env-key.ts';
export const wakeshiftKeyFile = () => gbrainPath('wakeshift.key');
export const wakeshiftSecretFile = () => gbrainPath('wakeshift.secret');
@@ -27,7 +27,7 @@ export type KeyRead =
| { source: 'none' }
| { source: 'file_too_open'; mode: string };
-/** Where the key comes from, without parsing it. The process's env value moves out of process.env when first seen (env-key.ts). */
+/** Where the key comes from, without parsing it. The process's env value moves out of process.env when first seen (wakeshift-env-key.ts). */
export function readWakeshiftKey(env: NodeJS.ProcessEnv = process.env): KeyRead {
if (env === process.env) {
const taken = takeWakeshiftEnvKey();