Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

Skill resolver logs: one file per day, kept 14 days

garrytaneb5120b6661f
diff --git a/docs/architecture/key-files/skills.md b/docs/architecture/key-files/skills.md
index 871a85288b..a6e199801e 100644
--- a/docs/architecture/key-files/skills.md
+++ b/docs/architecture/key-files/skills.md
@@ -46,7 +46,7 @@ Contract schemas: `docs/schemas/skill-resolver.v1.*.json`. Every module under
`skill-catalog.ts` import, static or dynamic (`test/skill-resolver-module-graph.test.ts`).
- `src/core/skills/resolver/index.ts` — the library entry (`gbrain/skill-resolver` export, and the entry of the Node bundle `gbrain-skill-resolver.mjs`). Re-exports build, status, remove, resolve, `ResolverError`, `resolverHome`; `resetSkillSession` deletes one session's state.
-- `src/core/skills/resolver/resolve.ts` — one turn: `normalizeTurnInput` (the turn-input schema, unknown fields refused, message capped at 8 KB), catalog loading (receipt and ranker identity, index size, gbrain version, the sliced stat freshness check: at most `STAT_CHECK_SLICE` entries per turn, a full sweep at most once per `STAT_CHECK_INTERVAL_MS`, cursor in `stat-check`), ack and no_match, explicit mentions first, merged-catalog interleave, the session rules (k 5/3/1 at 50%/80% of the budget, strong-match pacing, no-repeat, one re-suggestion after 10 turns), the block, `explain`, `failOpen`, `deadlineMs`. Returns `commit()`; session state changes only through it. Pinned by `test/skill-resolver.test.ts` and `test/skill-resolver-contract.test.ts`.
+- `src/core/skills/resolver/resolve.ts` — one turn: `normalizeTurnInput` (the turn-input schema, unknown fields refused, message capped at 8 KB), catalog loading (receipt and ranker identity, index size, gbrain version, the sliced stat freshness check: at most `STAT_CHECK_SLICE` entries per turn, a full sweep at most once per `STAT_CHECK_INTERVAL_MS`, cursor in `stat-check`), ack and no_match, explicit mentions first, merged-catalog interleave, the `min_match_strength` floor before the cut to k, `previous_user_message` as the no-match fallback, the session rules (k 5/3/1 at 50%/80% of the budget, strong-match pacing, no-repeat, one re-suggestion after 10 turns, a named skill past a spent budget), the block, `explain`, `failOpen`, `deadlineMs`. Returns `commit()`; session state changes only through it. Pinned by `test/skill-resolver.test.ts` and `test/skill-resolver-contract.test.ts`.
- `src/core/skills/resolver/rank.ts` — the A5 BM25F ranker over an `IndexReader` (scores summed in the prototype's order, ranked by score over summed idf, ties by name then id), the multilingual acknowledgement list, `mentionsSkill` (a `/name` counts only as a leading slash command) and `reasonText`. `test/skill-resolver-reproduction.test.ts` pins top-5 equality with the Step 1 prototype.
- `src/core/skills/resolver/tokenize.ts` — `splitWords` (shared with `scoreSkillMatch` in `skill-catalog.ts`) and `lexTerms`, the frozen Step 1 term rule (stopwords, light stemming); CJK runs become overlapping bigrams. Vectors: `test/fixtures/skill-resolver/tokenizer-vectors.json`.
- `src/core/skills/resolver/index-format.ts` — `index.bin` (magic `GBSKIDX1`, JSON header, field-length averages, per-skill lengths, sorted term dictionary, flat postings with per-field tf, per-skill meta), byte-identical for identical records; `VARIANT_PARAMS` (D and T constants), `fieldText`, `summaryOf` (the description cut at 120 characters), `IndexReader` (lazy postings and meta reads).
@@ -62,7 +62,7 @@ Contract schemas: `docs/schemas/skill-resolver.v1.*.json`. Every module under
- `src/core/skills/resolver/errors.ts` — `ResolverError` codes (rows in `src/core/error-registry.ts`), `USAGE_CODES` (exit 2).
- `src/core/skills/resolver/fsutil.ts` — temp-file, fsync and rename writes; bounded reads.
- `src/core/skill-description.ts` — `oneLineDescription` (frontmatter description, block scalars folded, else the first body paragraph), shared by `skill-catalog.ts`, `bundled.ts` and the bundled source.
-- `src/core/skills/resolver/hook-lane.ts` + `hook-worker.ts` — the hook lane (`GBRAIN_HOOK_LANE=skill-resolver`, dispatched first in `src/commands/hook.ts` after the `GBRAIN_HOOKS=0` check): async config/stdin/carrier reads on the main thread, ranking in a worker (source: `hook-worker.ts` beside it; compiled binary: the second build entrypoint at `WORKER_SRC_PATH`, so every `bun build --compile` that ships a binary lists it), a 50 ms deadline that exits the process with no output and no commit, the commit (`commitSessionAsync`) on the main thread after delivery, the payload budget (`skills.resolver.lane_payload_chars`, dropped whole as `payload_dropped`), the one-owner rule (first carrier entry whose home has the lane on), the SessionStart compaction reset, the Claude Code project catalog (`claude-code-project-<root hash>`, built by a detached `skills index build`, stamp-limited to once a minute) and `skill-index/logs/lane.jsonl`. Test seams: `GBRAIN_TEST_SKILL_LANE_STALL`, `GBRAIN_TEST_SKILL_LANE_DEADLINE_MS`. Pinned by `test/skill-resolver-hook-lane.test.ts`.
+- `src/core/skills/resolver/hook-lane.ts` + `hook-worker.ts` — the hook lane (`GBRAIN_HOOK_LANE=skill-resolver`, dispatched first in `src/commands/hook.ts` after the `GBRAIN_HOOKS=0` check): async config/stdin/carrier reads on the main thread, ranking in a worker (source: `hook-worker.ts` beside it; compiled binary: the second build entrypoint at `WORKER_SRC_PATH`, so every `bun build --compile` that ships a binary lists it), a 50 ms deadline that exits the process with no output and no commit, the commit (`commitSessionAsync`) on the main thread after delivery, the payload budget (`skills.resolver.lane_payload_chars`, dropped whole as `payload_dropped`), the one-owner rule (first carrier entry whose home has the lane on), the SessionStart compaction reset, the Claude Code project catalog (`claude-code-project-<root hash>`, built by a detached `skills index build`, stamp-limited to once a minute) and the daily lane log (`daily-log.ts`: `skill-index/logs/lane-<date>.jsonl`, kept 14 days). Test seams: `GBRAIN_TEST_SKILL_LANE_STALL`, `GBRAIN_TEST_SKILL_LANE_DEADLINE_MS`. Pinned by `test/skill-resolver-hook-lane.test.ts`.
- `src/core/setup/skill-resolver-{lane,hook,config,setup}.ts` — `setup <claude-code|codex> --skill-loading resolve|off` and `--remove`: the lane identity leaf (marker `skill-resolver-v1`, which every other lane's ownership and yield test excludes), the Claude Code entries and the Codex group plus its `config.toml` trust, the file-plane keys (`skills.resolver.*`, engine-free in `gbrain config`; an unreadable file is never rewritten), and the build-then-write order (≥1 skill or `skill_resolver_setup_incomplete`). Pinned by `test/setup-skill-resolver.test.ts`.
- `src/commands/doctor/checks/skill-resolver.ts` — doctor `skill_resolver` (emitted by the `harness_wiring` entry, whose details carry the same view): hook state, each catalog's content-tier freshness, recent lane outcomes and error codes; silent when nothing of the resolver exists.
- `src/commands/skill-resolver.ts` — the CLI (`src/cli/commands/skill-resolver.ts` dispatches; `src/cli/command-route.ts` routes only `skills index`, `skills resolve` and `skills library` here, so plain `gbrain skills` stays `list_skills`). Exit 0, 1 (runtime error), 0 with `--fail-open`, 2 (usage); commits a session turn only after stdout is written. Pinned by `test/skill-resolver-cli.test.ts` and `test/skill-resolver-guide.test.ts`.
diff --git a/docs/guides/skill-resolver.md b/docs/guides/skill-resolver.md
index ec29026545..3fe06fd8e9 100644
--- a/docs/guides/skill-resolver.md
+++ b/docs/guides/skill-resolver.md
@@ -115,8 +115,9 @@ The lane always exits 0 and prints nothing when it cannot deliver:
0.165 and later) resets the session, so skills can be offered again. A Codex
install from before gets the SessionStart group on its next setup run.
-Each turn appends one line (outcome, error code, duration; never turn text)
-to `skill-index/logs/lane.jsonl`. `gbrain doctor` (`skill_resolver`, and
+Each turn appends one line (outcome, error code, duration, catalogs; never
+turn text) to `skill-index/logs/lane-<UTC date>.jsonl`, one file per day,
+kept 14 days and capped at 2 MB a day. `gbrain doctor` (`skill_resolver`, and
`harness_wiring`'s details) reports the hook, each catalog's freshness and
the recent error codes; it says nothing while the resolver is off.
@@ -225,7 +226,7 @@ Nothing leaves the machine. Everything lives under `$GBRAIN_HOME/.gbrain/skill-i
| `<catalog>/source.json` | the `--from-json` snapshot |
| `<catalog>/fingerprint.json`, `stat-check`, `stale.stamp`, `lock`, `build.log` | freshness, lease and the last build error |
| `sessions/<key>.json` | skill ids and turn counters; never turn text |
-| `logs/resolver.log` | scrubbed stack traces of unexpected failures; never turn text |
+| `logs/lane-<date>.jsonl`, `logs/resolver-<date>.log` | one line per lane turn, and scrubbed stack traces of unexpected failures; never turn text; one file per day, kept 14 days |
The block never echoes the user's text. Summaries (each skill's description
cut at 120 characters, the `summary` field) are catalog text, so they are
@@ -357,7 +358,7 @@ written (an empty catalog is removed). Add a skill there, or pass
### skill_resolver_internal
An unexpected failure; a scrubbed trace was written to
-`skill-index/logs/resolver.log`. Run `gbrain skills index status` and report it
+`skill-index/logs/resolver-<UTC date>.log`. Run `gbrain skills index status` and report it
if it repeats.
### skill_catalog_unknown
diff --git a/src/commands/doctor/checks/skill-resolver.ts b/src/commands/doctor/checks/skill-resolver.ts
index 7707dc7ed9..77f9d49373 100644
--- a/src/commands/doctor/checks/skill-resolver.ts
+++ b/src/commands/doctor/checks/skill-resolver.ts
@@ -10,14 +10,14 @@
*
* Read-only apart from catalogStatus's session sweep; warns, never fails.
*/
-import { existsSync, readFileSync, statSync } from 'node:fs';
import { join } from 'node:path';
import type { Check } from '../../doctor.ts';
import { doctorVerify } from '../check-fix.ts';
import { configDir } from '../../../core/config.ts';
import { catalogStatus, listCatalogs } from '../../../core/skills/resolver/build.ts';
import { logsDir } from '../../../core/skills/resolver/paths.ts';
-import { LANE_LOG_FILE, projectCatalogPrefix, userCatalogName, type LaneHarness } from '../../../core/skills/resolver/hook-lane.ts';
+import { LANE_LOG, readRecentDailyLog } from '../../../core/skills/resolver/daily-log.ts';
+import { projectCatalogPrefix, userCatalogName, type LaneHarness } from '../../../core/skills/resolver/hook-lane.ts';
import { readResolverConfig, resolverHarnesses } from '../../../core/setup/skill-resolver-config.ts';
import { inspectSkillResolverHook } from '../../../core/setup/skill-resolver-hook.ts';
@@ -36,14 +36,8 @@ export interface SkillResolverView {
}
function recentLane(home: string): SkillResolverView['recent'] | null {
- const p = join(logsDir(home), LANE_LOG_FILE);
- if (!existsSync(p)) return null;
- let text = '';
- try {
- const size = statSync(p).size;
- text = readFileSync(p, 'utf8');
- if (size > LOG_TAIL_BYTES) text = text.slice(-LOG_TAIL_BYTES);
- } catch { return null; }
+ const text = readRecentDailyLog(logsDir(home), LANE_LOG, LOG_TAIL_BYTES);
+ if (text === null) return null;
const outcomes: Record<string, number> = {};
const errors: Record<string, number> = {};
const lines = text.split('\n').filter(Boolean).slice(-RECENT_LINES);
diff --git a/src/core/skills/resolver/daily-log.ts b/src/core/skills/resolver/daily-log.ts
new file mode 100644
index 0000000000..38c3d586f8
--- /dev/null
+++ b/src/core/skills/resolver/daily-log.ts
@@ -0,0 +1,61 @@
+/**
+ * The resolver's logs under skill-index/logs/: one file per UTC day
+ * (`lane-2026-11-10.jsonl`, `resolver-2026-11-10.log`), kept 14 days. The
+ * first write of a day deletes that log's files older than that, and the
+ * undated file earlier releases wrote. A day stops growing at 2 MB. Lines
+ * carry what the callers write (outcomes, codes, durations, scrubbed stack
+ * frames), never turn text. Leaf module.
+ */
+import { appendFileSync, readdirSync, readFileSync, statSync, unlinkSync } from 'node:fs';
+import { appendFile, readdir, stat, unlink } from 'node:fs/promises';
+import { join } from 'node:path';
+
+export const DAILY_LOG_KEEP_DAYS = 14;
+export const DAILY_LOG_DAY_CAP_BYTES = 2 * 1024 * 1024;
+
+export interface DailyLog { prefix: string; ext: string }
+export const LANE_LOG: DailyLog = { prefix: 'lane', ext: '.jsonl' };
+export const RESOLVER_LOG: DailyLog = { prefix: 'resolver', ext: '.log' };
+
+const day = (ms: number) => new Date(ms).toISOString().slice(0, 10);
+export const dailyLogFile = (log: DailyLog, ms: number) => `${log.prefix}-${day(ms)}${log.ext}`;
+
+/** The log's files in `names` that fall out of the window on day `ms`, plus the undated legacy file. */
+function expired(log: DailyLog, names: string[], ms: number): string[] {
+ const oldest = day(ms - (DAILY_LOG_KEEP_DAYS - 1) * 86_400_000);
+ const re = new RegExp(`^${log.prefix}-(\\d{4}-\\d{2}-\\d{2})${log.ext.replace('.', '\\.')}$`);
+ return names.filter(n => n === `${log.prefix}${log.ext}` || (re.exec(n)?.[1] ?? '9999') < oldest);
+}
+
+export async function appendDailyLog(dir: string, log: DailyLog, line: string, now = Date.now()): Promise<void> {
+ const p = join(dir, dailyLogFile(log, now));
+ let size = -1;
+ try { size = (await stat(p)).size; } catch { /* first write today */ }
+ if (size >= DAILY_LOG_DAY_CAP_BYTES) return;
+ if (size < 0) for (const n of expired(log, await readdir(dir).catch(() => []), now)) await unlink(join(dir, n)).catch(() => {});
+ await appendFile(p, line, { mode: 0o600 });
+}
+
+export function appendDailyLogSync(dir: string, log: DailyLog, line: string, now = Date.now()): void {
+ const p = join(dir, dailyLogFile(log, now));
+ let size = -1;
+ try { size = statSync(p).size; } catch { /* first write today */ }
+ if (size >= DAILY_LOG_DAY_CAP_BYTES) return;
+ if (size < 0) {
+ let names: string[] = [];
+ try { names = readdirSync(dir); } catch { /* none */ }
+ for (const n of expired(log, names, now)) { try { unlinkSync(join(dir, n)); } catch { /* gone */ } }
+ }
+ appendFileSync(p, line, { mode: 0o600 });
+}
+
+/** The last `maxBytes` of today's and yesterday's files, oldest first ('' when there are none). */
+export function readRecentDailyLog(dir: string, log: DailyLog, maxBytes: number, now = Date.now()): string | null {
+ const parts: string[] = [];
+ for (const ms of [now - 86_400_000, now]) {
+ try { parts.push(readFileSync(join(dir, dailyLogFile(log, ms)), 'utf8')); } catch { /* none that day */ }
+ }
+ if (!parts.length) return null;
+ const text = parts.join('');
+ return text.length > maxBytes ? text.slice(-maxBytes) : text;
+}
diff --git a/src/core/skills/resolver/hook-lane.ts b/src/core/skills/resolver/hook-lane.ts
index 74ffdd4a0e..b39cd8f9f4 100644
--- a/src/core/skills/resolver/hook-lane.ts
+++ b/src/core/skills/resolver/hook-lane.ts
@@ -44,13 +44,14 @@
* 4000 characters of hook JSON); a block that does not fit is dropped whole
* and counted (outcome payload_dropped in the lane log).
*
- * Lane log: <home>/skill-index/logs/lane.jsonl, one line per turn that got
- * past the on/off check (outcome, error code, duration; never turn text),
- * capped at 256 KB; doctor's skill_resolver check reads it.
+ * Lane log: <home>/skill-index/logs/lane-<UTC day>.jsonl (daily-log.ts, kept
+ * 14 days), one line per turn that got past the on/off check (outcome, error
+ * code, duration, catalogs; never turn text); doctor's skill_resolver check
+ * reads the last day of it.
*/
import { createHash } from 'node:crypto';
import { unlinkSync } from 'node:fs';
-import { appendFile, mkdir, readFile, realpath, stat, truncate, unlink, writeFile } from 'node:fs/promises';
+import { mkdir, readFile, realpath, stat, unlink, writeFile } from 'node:fs/promises';
import { homedir } from 'node:os';
import { join } from 'node:path';
import type { Worker } from 'node:worker_threads';
@@ -59,6 +60,7 @@ import { claudeManagedSettingsPaths, claudeUserSettingsPath, codexHooksPath } fr
import { shellWords } from '../../setup/hook-launcher.ts';
import { isSkillResolverCommand, isSkillResolverEntry } from '../../setup/skill-resolver-lane.ts';
import { laneTurnSettings, type LaneTurnSettings } from './config.ts';
+import { appendDailyLog, LANE_LOG } from './daily-log.ts';
import { assertCatalogName, catalogFile, logsDir, resolverHome } from './paths.ts';
import { type CommitHold, commitSessionAsync, sessionKey, type TurnDelta } from './session.ts';
import type { TurnOutput } from './resolve.ts';
@@ -73,8 +75,6 @@ export const LANE_STDIN_CAP_BYTES = 256 * 1024;
export const LANE_PAYLOAD_CHARS_DEFAULT = 4000;
export const LANE_PAYLOAD_CHARS_MIN = 500;
export const LANE_PAYLOAD_CHARS_MAX = 10_000;
-export const LANE_LOG_FILE = 'lane.jsonl';
-const LANE_LOG_CAP_BYTES = 256 * 1024;
const CONFIG_CAP_BYTES = 1024 * 1024;
const SPAWN_INTERVAL_MS = 60_000;
/** Time kept back from the worker's own deadline for delivery and the commit. */
@@ -157,9 +157,7 @@ async function appendLaneLog(home: string, line: LaneLogLine): Promise<void> {
try {
const dir = logsDir(home);
await mkdir(dir, { recursive: true, mode: 0o700 });
- const p = join(dir, LANE_LOG_FILE);
- try { if ((await stat(p)).size > LANE_LOG_CAP_BYTES) await truncate(p, 0); } catch { /* new */ }
- await appendFile(p, `${JSON.stringify(line)}\n`, { mode: 0o600 });
+ await appendDailyLog(dir, LANE_LOG, `${JSON.stringify(line)}\n`);
} catch { /* logging never fails a turn */ }
}
diff --git a/src/core/skills/resolver/resolve.ts b/src/core/skills/resolver/resolve.ts
index 8b96a97b55..ee79efce6d 100644
--- a/src/core/skills/resolver/resolve.ts
+++ b/src/core/skills/resolver/resolve.ts
@@ -23,7 +23,7 @@
* never shrinks the block below what the stronger matches fill. A message
* that matches no catalog word falls back to previous_user_message.
*/
-import { appendFileSync, existsSync, readFileSync, statSync, truncateSync } from 'node:fs';
+import { existsSync, readFileSync, statSync } from 'node:fs';
import { createHash } from 'node:crypto';
import { join } from 'node:path';
import { VERSION } from '../../../version.ts';
@@ -32,6 +32,7 @@ import type { BuildReceipt } from './build.ts';
import { dirFingerprintSlice, listCatalogs, readReceipt } from './catalog-files.ts';
import { readResolverSettings, validateSessionTokenBudget } from './config.ts';
import { ResolverError } from './errors.ts';
+import { appendDailyLogSync, RESOLVER_LOG } from './daily-log.ts';
import { ensureDir, writeFileAtomic, writeFileDurable } from './fsutil.ts';
import { EXCLUDE_MAX, MATCH_STRENGTHS, type MatchStrength, STRENGTH_FIELDS, TOP_K_DEFAULT, TOP_K_MAX } from './limits.ts';
import { IndexReader, RANKER_ID, RANKER_VERSION } from './index-format.ts';
@@ -227,10 +228,8 @@ function logUnexpected(home: string, e: unknown): void {
try {
const dir = logsDir(home);
ensureDir(dir);
- const p = join(dir, 'resolver.log');
- try { if (statSync(p).size > 256 * 1024) truncateSync(p, 0); } catch { /* new */ }
const err = e as Error;
- appendFileSync(p, `${JSON.stringify({ at: new Date().toISOString(), version: VERSION, name: err?.name ?? typeof e, stack: String(err?.stack ?? '').split('\n').slice(1, 6).map(l => l.trim()) })}\n`, { mode: 0o600 });
+ appendDailyLogSync(dir, RESOLVER_LOG, `${JSON.stringify({ at: new Date().toISOString(), version: VERSION, name: err?.name ?? typeof e, stack: String(err?.stack ?? '').split('\n').slice(1, 6).map(l => l.trim()) })}\n`);
} catch { /* logging never fails a turn */ }
}
diff --git a/test/skill-resolver-hook-lane.test.ts b/test/skill-resolver-hook-lane.test.ts
index 65ab2247eb..60e3aa6cf2 100644
--- a/test/skill-resolver-hook-lane.test.ts
+++ b/test/skill-resolver-hook-lane.test.ts
@@ -19,6 +19,7 @@ import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { runCli } from './helpers/cli-spawn.ts';
import { LANE_DEADLINE_MS, projectCatalogPrefix, WORKER_SRC_PATH } from '../src/core/skills/resolver/hook-lane.ts';
+import { dailyLogFile, LANE_LOG } from '../src/core/skills/resolver/daily-log.ts';
setDefaultTimeout(60_000);
const CLI = join(import.meta.dir, '..', 'src', 'cli.ts');
@@ -83,7 +84,7 @@ async function hook(b: Box, command: string, payload: Record<string, unknown>, e
}
const WIDE = { GBRAIN_TEST_SKILL_LANE_DEADLINE_MS: '10000' };
const laneLog = (b: Box): any[] => {
- const p = join(b.home, '.gbrain', 'skill-index', 'logs', 'lane.jsonl');
+ const p = join(b.home, '.gbrain', 'skill-index', 'logs', dailyLogFile(LANE_LOG, Date.now()));
return existsSync(p) ? readFileSync(p, 'utf8').trim().split('\n').filter(Boolean).map((l) => JSON.parse(l)) : [];
};
const sessions = (b: Box) => { const d = join(b.home, '.gbrain', 'skill-index', 'sessions'); return existsSync(d) ? readdirSync(d) : []; };
diff --git a/test/skill-resolver.test.ts b/test/skill-resolver.test.ts
index 5358871d84..77588a4f36 100644
--- a/test/skill-resolver.test.ts
+++ b/test/skill-resolver.test.ts
@@ -28,6 +28,7 @@ import { estimateTokens } from '../src/core/skills/resolver/block.ts';
import { acquireLease, holdsLease, releaseLease, tryAcquireLease } from '../src/core/skills/resolver/lock.ts';
import { commitSession, commitSessionAsync, gcSessions, loadSession, sessionKey } from '../src/core/skills/resolver/session.ts';
import { catalogFile } from '../src/core/skills/resolver/paths.ts';
+import { appendDailyLog, appendDailyLogSync, DAILY_LOG_DAY_CAP_BYTES, dailyLogFile, LANE_LOG, readRecentDailyLog, RESOLVER_LOG } from '../src/core/skills/resolver/daily-log.ts';
import { EXCLUDE_MAX, STAT_CHECK_SLICE } from '../src/core/skills/resolver/resolve.ts';
import { RACY_MTIME_MS } from '../src/core/skills/resolver/build.ts';
@@ -835,3 +836,25 @@ describe('freshness and errors', () => {
expect(existsSync(join(home, 'missing'))).toBe(false);
});
});
+
+describe('daily logs', () => {
+ test('one file per UTC day; the first write of a day drops files older than 14 days and the undated file; a day stops at its cap', async () => {
+ const dir = tmp('skres-logs-');
+ const day = 86_400_000;
+ const now = Date.parse('2026-11-20T12:00:00Z');
+ for (const d of [0, 12, 13, 30]) writeFileSync(join(dir, dailyLogFile(LANE_LOG, now - d * day)), 'old\n');
+ writeFileSync(join(dir, 'lane.jsonl'), 'legacy\n');
+ writeFileSync(join(dir, dailyLogFile(RESOLVER_LOG, now - 30 * day)), 'other log\n');
+ await appendDailyLog(dir, LANE_LOG, 'x\n', now + day);
+ expect(readdirSync(dir).sort()).toEqual(['lane-2026-11-08.jsonl', 'lane-2026-11-20.jsonl', 'lane-2026-11-21.jsonl', 'resolver-2026-10-21.log']);
+ appendDailyLogSync(dir, RESOLVER_LOG, 'trace\n', now + day);
+ expect(readdirSync(dir).filter(n => n.startsWith('resolver-'))).toEqual(['resolver-2026-11-21.log']);
+ expect(readRecentDailyLog(dir, LANE_LOG, 1024, now + day)).toBe('old\nx\n');
+ expect(readRecentDailyLog(dir, LANE_LOG, 2, now + day)).toBe('x\n');
+ expect(readRecentDailyLog(dir, LANE_LOG, 1024, now + 9 * day)).toBeNull();
+ const full = join(dir, dailyLogFile(LANE_LOG, now + day));
+ writeFileSync(full, 'y'.repeat(DAILY_LOG_DAY_CAP_BYTES));
+ await appendDailyLog(dir, LANE_LOG, 'z\n', now + day);
+ expect(readFileSync(full, 'utf8').endsWith('z\n')).toBe(false);
+ });
+});