Skip to content

Stop paying the multimodal tax. Your AI agent keeps every image it has seen but only sends the ones it needs: lighter chats, no endless reconnecting, no starting over. Works with Codex, Claude Code, Cline, Gemini CLI, OpenCode, WorkBuddy and more. Install once, forget it.

test(selftest): 自测测完把自己建的任务归档;加一个归档遗留测试任务的脚本

chipfighter9fb2ec3160fe
diff --git a/spike/scripts/archive-test-threads.ts b/spike/scripts/archive-test-threads.ts
new file mode 100644
index 0000000..2d5f7ca
--- /dev/null
+++ b/spike/scripts/archive-test-threads.ts
@@ -0,0 +1,39 @@
+// Purpose: archive the tasks the self-tests left in the user's Codex — tasks named "[CAM测试] …" or "[CAM test] …" that
+// are not archived yet, e.g. from runs before the self-tests archived their own tasks (user 2026-09-28). No other task
+// is touched; archived tasks stay readable under Codex's archived tasks. Codex may show them until it restarts.
+// Input: `node spike/scripts/archive-test-threads.ts [--dry-run]`; CODEX_HOME. Output: the names of the tasks archived.
+
+import { existsSync, readFileSync } from "node:fs";
+import { join } from "node:path";
+import { codexHome } from "../../plugin/src/codexconfig.ts";
+import { hasRollout } from "../../plugin/src/thread-index.ts";
+import { AppServer, findBundledCodex } from "../src/appserver.ts";
+import { archiveThreads } from "../src/testkit.ts";
+
+// Only the names the test scripts give their tasks; a task that merely starts with "[CAM测试]" is left alone.
+const TEST_NAME = /^\[CAM测试\] (P\d|v0\.1 占位符自测 |截图编号自测 )|^\[CAM test\] (v0\.1 placeholder self-test |screenshot id self-test )/;
+const dryRun = process.argv.includes("--dry-run");
+const home = codexHome();
+const indexFile = join(home, "session_index.jsonl");
+if (!existsSync(indexFile)) throw new Error(`no ${indexFile}`);
+
+// A task's name is the last one written for it.
+const names = new Map<string, string>();
+for (const line of readFileSync(indexFile, "utf8").split(/\r?\n/)) {
+ try { const entry = JSON.parse(line); if (entry?.id) names.set(entry.id, String(entry.thread_name ?? "")); } catch { /* skip */ }
+}
+const sessionsDir = join(home, "sessions");
+const targets = [...names].filter(([id, name]) => TEST_NAME.test(name) && hasRollout(sessionsDir, id));
+for (const [, name] of targets) console.log(name);
+console.log(`${targets.length} test task(s) ${dryRun ? "would be archived" : "to archive"}`);
+
+if (!dryRun && targets.length) {
+ const server = new AppServer(findBundledCodex(), ["-c", "notify=[]"], {}, join(process.env.TEMP ?? home, "cam-archive-appserver.log"));
+ try {
+ await server.initialize();
+ const failed = await archiveThreads(server, targets.map(([id]) => id));
+ console.log(`archived ${targets.length - failed.length}${failed.length ? `, failed ${failed.length}: ${failed.join(", ")}` : ""}`);
+ } finally {
+ await server.stop();
+ }
+}
diff --git a/spike/src/testkit.ts b/spike/src/testkit.ts
index a9c17cc..ce342e0 100644
--- a/spike/src/testkit.ts
+++ b/spike/src/testkit.ts
@@ -56,6 +56,16 @@ export const TEST_EFFORT = process.env.CAM_TEST_EFFORT?.trim() || "low";
export const text = (value: string) => ({ type: "text", text: value, text_elements: [] });
+// The self-tests' tasks show up in the user's Codex; once a test is done they are archived (user 2026-09-28), and stay
+// readable under Codex's archived tasks. Returns the ids that could not be archived.
+export async function archiveThreads(server: AppServer, threadIds: string[]): Promise<string[]> {
+ const failed: string[] = [];
+ for (const threadId of threadIds) {
+ try { await server.request("thread/archive", { threadId }, 30_000); } catch { failed.push(threadId); }
+ }
+ return failed;
+}
+
export async function runTurn(server: AppServer, threadId: string, input: Json[], timeoutMs = 20 * 60_000): Promise<Json> {
const started = Date.now();
const before = server.notifications.length;
diff --git a/spike/src/v01-needs-selftest.ts b/spike/src/v01-needs-selftest.ts
index 28528ee..3b6aff8 100644
--- a/spike/src/v01-needs-selftest.ts
+++ b/spike/src/v01-needs-selftest.ts
@@ -24,7 +24,7 @@ import { selectionDirOf } from "../../plugin/src/paths.ts";
import { readRequestStats } from "../../plugin/src/request-stats.ts";
import { writeSelection } from "../../plugin/src/selection.ts";
import { loadThreadIndex } from "../../plugin/src/thread-index.ts";
-import { png, runTurn, TEST_EFFORT, TEST_MODEL, text } from "./testkit.ts";
+import { archiveThreads, png, runTurn, TEST_EFFORT, TEST_MODEL, text } from "./testkit.ts";
type Json = Record<string, any>;
const here = dirname(fileURLToPath(import.meta.url));
@@ -118,6 +118,7 @@ async function main(): Promise<void> {
const server = new AppServer(findBundledCodex(), ["-c", `openai_base_url="http://localhost:${port}/backend-api/codex"`, "-c", "features.respect_system_proxy=true", "-c", "notify=[]", "-c", "mcp_servers.node_repl.enabled=false", ...off], { NO_PROXY: undefined, no_proxy: undefined }, join(root, `needs-appserver-${label}.log`));
const result: Json = { createdAt: new Date().toISOString(), label, lang, model: TEST_MODEL, effort: TEST_EFFORT, threads: [] };
const sessionsDir = join(codexHome(), "sessions");
+ const created: string[] = [];
try {
// thread/resume takes a history only from a client that opts into the experimental API.
await server.initialize({ experimentalApi: true, requestAttestation: false });
@@ -125,6 +126,7 @@ async function main(): Promise<void> {
const run = async (n: number, questions: Array<[string, string]>) => {
const { thread } = await server.request<{ thread: Json }>("thread/resume", { threadId: randomUUID(), history: history(words), model: TEST_MODEL, cwd: work, approvalPolicy: "never", sandbox: "read-only" });
const threadId: string = thread.id;
+ created.push(threadId);
await server.request("thread/name/set", { threadId, name: words.name(label, n) });
const entry: Json = { threadId, turns: {} };
// The index comes from the thread's record; if Codex has not written it yet, one short turn (images still in) does.
@@ -153,6 +155,7 @@ async function main(): Promise<void> {
await run(1, [["lookNow", words.lookNow], ["whichImages", words.whichImages], ["detail", words.detail]]);
await run(2, [["detail", words.detail]]);
} finally {
+ result.notArchived = await archiveThreads(server, created);
await server.stop();
engine.kill();
}
diff --git a/spike/src/v01-placeholder-selftest.ts b/spike/src/v01-placeholder-selftest.ts
index 170d545..30bd499 100644
--- a/spike/src/v01-placeholder-selftest.ts
+++ b/spike/src/v01-placeholder-selftest.ts
@@ -19,7 +19,7 @@ import { languageFileOf, rememberLang } from "../../plugin/src/language.ts";
import { selectionDirOf } from "../../plugin/src/paths.ts";
import { readRequestStats } from "../../plugin/src/request-stats.ts";
import { writeSelection } from "../../plugin/src/selection.ts";
-import { runTurn, TEST_EFFORT, TEST_MODEL, testImages, text } from "./testkit.ts";
+import { archiveThreads, runTurn, TEST_EFFORT, TEST_MODEL, testImages, text } from "./testkit.ts";
import { loadThreadIndex } from "../../plugin/src/thread-index.ts";
type Json = Record<string, any>;
@@ -99,6 +99,7 @@ async function main(): Promise<void> {
await turn("newDetail", words.newDetail);
result.lastRequest = readRequestStats(threadId, join(data, "state", "requests"))?.lastHttp?.rewrite ?? null;
} finally {
+ if (result.threadId) result.notArchived = await archiveThreads(server, [result.threadId]);
await server.stop();
engine.kill();
}