okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge f-clean-7 (045843071): the app loads screens, languages, Prism and Time-skip on first use; main chunk 3,123,528 -> 755,418 B, start screen 248.5 -> 143.4 ms (p2006 Chrome, median of 10); nothing users see changes (cleanup step 7)1631a9fde

main
5.4 KiB69 linesraw
1/** "Continue in a new chat" on a task: the first message of the new chat carries what the task found, did, and the files it made. */
2import test from 'node:test';
3import assert from 'node:assert/strict';
4import { build } from 'esbuild';
5import { createAgentTaskRunner } from '../server/agent/task-run.mjs';
6import { createTaskService } from '../server/tasks.mjs';
7
8const compiled = await build({ stdin: { contents: "export * from './src/lib/task-handover'; export * from './src/lib/i18n';", resolveDir: process.cwd() }, bundle: true, write: false, format: 'esm', platform: 'node', loader: { '.json': 'json' } });
9const { splitTaskOutput, taskHandoverMessage, taskHandoverTitle, setTranslationLanguage, loadCatalog } = await import(`data:text/javascript;base64,${Buffer.from(compiled.outputFiles[0].text).toString('base64')}`);
10for (const l of ['zh', 'ja', 'de', 'es', 'ru', 'pt', 'ko', 'fr']) await loadCatalog(l);  // the non-English catalogs load on first use (src/lib/i18n.ts loadCatalog); load them before the first tr()
11
12const OUTPUT = 'Two things need your attention.\n\n- Disk space is low.\n- The card ran hot twice.\n\n---\n\n**What it did**\n\n- Read the temperature log\n- Checked free space on C: and D:\n\n> This task wanted to change something and needed a yes. Nothing was changed.';
13const task = { id: 't', title: 'Hardware check', prompt: 'Check it', frequency: 'daily', at: '08:00', weekday: 1, timeZone: 'UTC', enabled: true, lastRunAt: '2026-10-18T06:00:00.000Z', output: OUTPUT,
14  files: [{ name: 'report.md', path: 'C:\\Users\\you\\Documents\\Strata\\Workspace\\report.md' }] };
15
16test('the saved answer is split into what it found, what it did, and the note that needed a yes', () => {
17  const parts = splitTaskOutput(OUTPUT);
18  assert.equal(parts.found, 'Two things need your attention.\n\n- Disk space is low.\n- The card ran hot twice.');
19  assert.deepEqual(parts.did, ['Read the temperature log', 'Checked free space on C: and D:']);
20  assert.match(parts.attention, /needed a yes/);
21  assert.deepEqual(splitTaskOutput('Just an answer.'), { found: 'Just an answer.', did: [], attention: '' });
22  assert.deepEqual(splitTaskOutput(''), { found: '', did: [], attention: '' });
23});
24
25test('the first message names the task and carries the findings, the steps, the files and a next step', () => {
26  setTranslationLanguage('en');
27  const text = taskHandoverMessage(task);
28  assert.match(text, /^\*\*Continuing from the task “Hardware check”\*\* \(ran .*, finished\)\./);
29  for (const part of ['**What it found**', 'Disk space is low.', '**Needs your attention**', 'needed a yes', '**What it did**', '- Read the temperature log', '**Files**', '- C:\\Users\\you\\Documents\\Strata\\Workspace\\report.md', 'Please help me take it from here.']) assert.ok(text.includes(part), part);
30  assert.ok(text.indexOf('What it found') < text.indexOf('What it did') && text.indexOf('What it did') < text.indexOf('Files'), 'in reading order');
31  assert.equal(taskHandoverTitle(task), 'Continuing from the task “Hardware check”');
32});
33
34test('a task that did not finish says what went wrong; a task with no files has no Files part', () => {
35  setTranslationLanguage('en');
36  const failed = taskHandoverMessage({ ...task, error: 'The model is not reachable.', output: '', files: [] });
37  assert.match(failed, /did not finish/); assert.match(failed, /\*\*What went wrong\*\*\n\nThe model is not reachable\./);
38  assert.ok(!failed.includes('**Files**') && !failed.includes('**What it found**'));
39});
40
41test('the labels follow the language of the app', () => {
42  setTranslationLanguage('de');
43  const text = taskHandoverMessage(task);
44  assert.match(text, /Weiter mit der Aufgabe „Hardware check“/); assert.match(text, /\*\*Was sie gefunden hat\*\*/); assert.match(text, /Dateien/);
45  setTranslationLanguage('en');
46});
47
48test('a scheduled run keeps the files the agent made, and a later failed run does not keep the old ones', async () => {
49  const frames = [{ type: 'delta', text: 'Done.' }, { type: 'deliverable', abs: '/w/report.md', name: 'report.md', path: 'report.md' }, { type: 'deliverable', abs: '/w/report.md', name: 'report.md', path: 'report.md' }];
50  const agent = { runTurn: async ({ onFrame }) => { for (const f of frames) onFrame(f); }, stop: async () => {}, forget() {}, approve: async () => {} };
51  const run = createAgentTaskRunner({ agent, choice: () => ({ instanceId: 'i' }), workspace: '/w' });
52  let store = [];
53  const service = createTaskService({ read: () => store, write: v => { store = v; }, run });
54  const saved = service.put({ title: 'T', prompt: 'p', frequency: 'daily', at: '08:00', timeZone: 'UTC' });
55  await service.execute(saved.id);
56  assert.deepEqual(service.list()[0].files, [{ name: 'report.md', path: '/w/report.md' }]);
57  frames.length = 0; frames.push({ type: 'error', message: 'boom' });
58  await service.execute(saved.id);
59  assert.equal(service.list()[0].status, 'error'); assert.deepEqual(service.list()[0].files, []);
60});
61
62test('a long run keeps the first steps, shortened, and says how many more', () => {
63  setTranslationLanguage('en');
64  const steps = Array.from({ length: 14 }, (_, i) => `Step ${i + 1} ${'x'.repeat(300)}`);
65  const text = taskHandoverMessage({ ...task, output: `Done.\n\n---\n\n**What it did**\n\n${steps.map(s => `- ${s}`).join('\n')}`, files: [] });
66  const lines = text.split('\n').filter(l => l.startsWith('- '));
67  assert.equal(lines.length, 11); assert.ok(lines.slice(0, 10).every(l => l.length <= 162 && l.endsWith('…')));
68  assert.equal(lines[10], '- …and 4 more steps');
69});