mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-11-13 18:29:32 +01:00
Claude Code lets a subscription's one-hour prompt cache expire after an hour idle, and the first turn back re-writes the whole conversation at the cache-write rate; nearly every gap over an hour goes cold, while the saving is concentrated in gaps of one to four hours. Codeman now sends one short keep-alive turn five minutes before the expiry Claude Code reports on its statusline, so the next real prompt still reads the conversation from cache, and stops two hours (configurable) after the last real prompt. Codeman owns the idle policy for these sessions, as agreed in Discussion #554: a launch with keep-warm on also carries idleCompaction: false in its one --settings JSON, so Claude Code's own idle compaction cannot replace the conversation with a summary a minute before the nudge. It is decided once per launch (keep-warm on, the statusLine exporter injected, Claude Code 2.1.290 or newer, an unknown version fails closed like --name), recorded on the mux record, and picked up by any relaunch; a launch with keep-warm off is byte-identical. A session switched on after launch is kept warm best-effort and the readout says so. Every guard lives in one pure rulebook: the opt-in (an agent-spawned session does not inherit the app default), a launch that reports cache state, a warm 1h cache with enough tokens at stake and no compaction this gap, a live pane, no usage-limit pause, no respawn, Ralph, task or waiting agent, idle, no open dialog, an empty composer and no recent keystroke. The nudge is a submit and moves lastSubmitAt, which the response viewer's conversation correlation needs; the cap counts from its own persisted lastRealPromptAt instead. Read My Mind drops the exact nudge text, and the turn's stop hook and idle prompt open pre-acknowledged so nothing alerts. The last cache report and the clock survive a restart, so the timer re-arms.
69 lines
2.9 KiB
TypeScript
69 lines
2.9 KiB
TypeScript
/**
|
|
* @fileoverview The prompt-cache keep-warm rows (Session Options → Respawn switch, App Settings
|
|
* → Automation default and cap) in Chinese (zh-CN): each label and description runs through
|
|
* the real translator over the real index.html in JSDOM and reads in Chinese with no English
|
|
* left beyond the product names, and every new key, the toggle toasts included, is in the
|
|
* dictionary exactly once (a repeated key in the object literal silently replaces the first).
|
|
*
|
|
* Port: N/A.
|
|
*/
|
|
import { readFileSync } from 'node:fs';
|
|
import { resolve } from 'node:path';
|
|
import vm from 'node:vm';
|
|
import { JSDOM } from 'jsdom';
|
|
import { afterAll, describe, expect, it } from 'vitest';
|
|
|
|
const PUBLIC = resolve(import.meta.dirname, '../src/web/public');
|
|
const I18N = readFileSync(resolve(PUBLIC, 'i18n.js'), 'utf8');
|
|
const INDEX = readFileSync(resolve(PUBLIC, 'index.html'), 'utf8');
|
|
|
|
type Api = { configure(o: Record<string, string>): void; start(): void };
|
|
|
|
const IDS = ['modalKeepWarmEnabled', 'appSettingsPromptCacheKeepWarm', 'appSettingsPromptCacheKeepWarmMaxHours'];
|
|
|
|
/** What may stay Latin: the product names. */
|
|
const leftover = (text: string) =>
|
|
text.replace(/\b(Claude Code|Claude|Codeman|Ralph)\b/g, '').match(/[A-Za-z]+/g) ?? [];
|
|
|
|
function rowStrings(doc: Document, id: string): { label: string; description: string } {
|
|
const row = doc.getElementById(id)!.closest('.set-row')!;
|
|
return {
|
|
label: row.querySelector('.set-row-label')!.textContent!.trim(),
|
|
description: row.querySelector('.set-row-desc')!.textContent!.trim(),
|
|
};
|
|
}
|
|
|
|
const source = new JSDOM(INDEX);
|
|
const dom = new JSDOM(INDEX, { runScripts: 'outside-only', url: 'http://localhost/' });
|
|
vm.runInContext(I18N, dom.getInternalVMContext(), { filename: 'i18n.js' });
|
|
const api = (dom.window as unknown as { CodemanI18n: Api }).CodemanI18n;
|
|
api.start();
|
|
api.configure({ language: 'zh-CN' });
|
|
|
|
afterAll(() => {
|
|
source.window.close();
|
|
dom.window.close();
|
|
});
|
|
|
|
describe('the keep-warm rows in zh-CN', () => {
|
|
it.each(IDS)('translates the %s row, with no English left', (id) => {
|
|
const english = rowStrings(source.window.document, id);
|
|
const chinese = rowStrings(dom.window.document, id);
|
|
expect(english.label.length).toBeGreaterThan(0);
|
|
for (const key of ['label', 'description'] as const) {
|
|
expect(chinese[key]).not.toBe(english[key]);
|
|
expect(leftover(chinese[key])).toEqual([]);
|
|
}
|
|
});
|
|
|
|
it('adds each key to the dictionary once, the toasts included', () => {
|
|
const texts = IDS.flatMap((id) => Object.values(rowStrings(source.window.document, id)));
|
|
texts.push('hours', 'Prompt-cache keep-warm enabled', 'Prompt-cache keep-warm disabled');
|
|
for (const text of texts) {
|
|
const quoted = I18N.split(`'${text}'`).length + I18N.split(`"${text}"`).length - 2;
|
|
const bare = /^\w+$/.test(text) ? I18N.split(`\n ${text}: `).length - 1 : 0;
|
|
expect(quoted + bare, text).toBe(1);
|
|
}
|
|
});
|
|
});
|