From 564b3e182ece87aa1c598c426e4e130058665e37 Mon Sep 17 00:00:00 2001 From: Ray Tien Date: Tue, 25 Aug 2026 16:32:18 +0800 Subject: [PATCH] fix: enable continual learning trial mode by default --- continual-learning/README.md | 2 +- .../hooks/continual-learning-stop.test.ts | 64 +++++++++++++++++++ .../hooks/continual-learning-stop.ts | 5 +- 3 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 continual-learning/hooks/continual-learning-stop.test.ts diff --git a/continual-learning/README.md b/continual-learning/README.md index 410fe925..60db47f1 100644 --- a/continual-learning/README.md +++ b/continual-learning/README.md @@ -42,7 +42,7 @@ Default cadence: - minimum 120 minutes since the last run - transcript mtime must advance since the previous run -Trial mode defaults (enabled in this plugin hook config): +Trial mode defaults (enabled by default in this plugin): - minimum 3 completed turns - minimum 15 minutes diff --git a/continual-learning/hooks/continual-learning-stop.test.ts b/continual-learning/hooks/continual-learning-stop.test.ts new file mode 100644 index 00000000..59acbfd1 --- /dev/null +++ b/continual-learning/hooks/continual-learning-stop.test.ts @@ -0,0 +1,64 @@ +import { expect, test } from "bun:test"; +import { mkdtempSync, rmSync, writeFileSync } from "node:fs"; +import { tmpdir } from "node:os"; +import { join } from "node:path"; + +const path_hook = join(import.meta.dir, "continual-learning-stop.ts"); + +test("uses trial cadence by default", async () => { + const dir_workspace = mkdtempSync(join(tmpdir(), "continual-learning-")); + const path_transcript = join(dir_workspace, "transcript.jsonl"); + writeFileSync(path_transcript, "{}\n"); + + try { + const outputs_hook = []; + + for (let count_turn = 1; count_turn <= 3; count_turn += 1) { + outputs_hook.push( + await runHook(dir_workspace, path_transcript, count_turn) + ); + } + + expect(outputs_hook.slice(0, 2)).toEqual([{}, {}]); + expect(outputs_hook[2]).toHaveProperty("followup_message"); + } finally { + rmSync(dir_workspace, { recursive: true, force: true }); + } +}); + +async function runHook( + dir_workspace: string, + path_transcript: string, + count_turn: number +): Promise> { + const env_hook = { ...process.env }; + delete env_hook.CONTINUAL_LEARNING_TRIAL_MODE; + delete env_hook.CONTINUOUS_LEARNING_TRIAL_MODE; + + const process_hook = Bun.spawn(["bun", "run", path_hook], { + cwd: dir_workspace, + env: env_hook, + stdin: "pipe", + stdout: "pipe", + stderr: "pipe", + }); + const input_hook = { + conversation_id: "trial-default-test", + generation_id: `generation-${count_turn}`, + status: "completed", + loop_count: 0, + transcript_path: path_transcript, + }; + + process_hook.stdin.write(JSON.stringify(input_hook)); + process_hook.stdin.end(); + + const [status_exit, text_stdout, text_stderr] = await Promise.all([ + process_hook.exited, + new Response(process_hook.stdout).text(), + new Response(process_hook.stderr).text(), + ]); + expect(status_exit, text_stderr).toBe(0); + + return JSON.parse(text_stdout) as Record; +} diff --git a/continual-learning/hooks/continual-learning-stop.ts b/continual-learning/hooks/continual-learning-stop.ts index fa6f5d95..957c58a8 100644 --- a/continual-learning/hooks/continual-learning-stop.ts +++ b/continual-learning/hooks/continual-learning-stop.ts @@ -160,7 +160,10 @@ async function main(): Promise { const now = Date.now(); const trialEnabled = parseBoolean( - readEnvValue("CONTINUAL_LEARNING_TRIAL_MODE", "CONTINUOUS_LEARNING_TRIAL_MODE") + readEnvValue( + "CONTINUAL_LEARNING_TRIAL_MODE", + "CONTINUOUS_LEARNING_TRIAL_MODE" + ) ?? "true" ); if (trialEnabled && countedTurn && state.trialStartedAtMs === null) { state.trialStartedAtMs = now;