Files
leleka/engine/strata/apps/host/src/lib/task-handover.ts
T
Pavlo RatushnyiandClaude Sonnet 5.5 87e2633afe engine/strata: bring the Strata subtree to upstream 41cf05a0 (engine 0.1.50) with the local patches re-applied
Documented tree replacement (the history has no git-subtree metadata): 3-way merge of the old subtree
(570201a:engine/strata) against upstream 41cf05a06a25dd29103b7b27a2279a3f60c21876 (2026-10-25), merge base =
the old pin d9ab8435 (tree-identical to upstream 5b734e42; d9ab8435 is not an ancestor of upstream main).

Local patches re-applied by hand where they conflicted (15 files): STRATA_CUDA_STATIC profile, experimental KAR
experts and KAR PLE arms, keyless V-only arm (now beside upstream's K8V4 hybrid KV and fused norm+rope). Details,
conflict table and left-out files are in docs/upstream.md.

Left out (weights, captures, logs, media): new bench/results (2022 files), binary media and app assets (61),
docs/work/evidence (24), *.bin / *.gguf data files, and the 7 files the first import already left out.

scripts/build-cpu.sh: build the 11 CPU tests upstream registered since the old pin (they ran as "Not Run").
Checked: build-cpu.sh 16/16 ctest in WSL; sm_86 CUDA objects of the patched files compile, also with the KAR
macros on. No GPU run, no quality gate.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-25 12:49:15 +01:00

71 lines
4.1 KiB
TypeScript

import { tr, localeTag } from './i18n';
import type { Task } from './tasks';
import type { Session } from './types';
import { loopEndNote } from './loop';
import { sessionTitle } from './session-title';
/**
* "Continue in a new chat" on a task: the first message of the new chat. It carries what the task found, what it did and the files it made, in the
* words the person reads, so the conversation can go on from the result (a finished task, or one that stopped and needs a person).
*/
const when = (iso?: string) => (iso ? new Date(iso).toLocaleString(localeTag(), { dateStyle: 'medium', timeStyle: 'short' }) : '');
/** The task's saved answer as its parts: the answer, the list of what it did, and the note that something needed a yes ("What it did" is how the host writes it, server/task-report.mjs). */
export function splitTaskOutput(output: string): { found: string; did: string[]; attention: string } {
let text = String(output ?? '').trim();
let attention = '';
const note = /\n\n> ([\s\S]*)$/.exec(text);
if (note) { attention = note[1].replace(/\n> /g, '\n').trim(); text = text.slice(0, note.index).trim(); }
const cut = /\n\n---\n\n\*\*What it did\*\*\n\n([\s\S]*)$/.exec(text);
const did = cut ? cut[1].split('\n').map(l => l.replace(/^-\s*/, '').trim()).filter(Boolean) : [];
return { found: (cut ? text.slice(0, cut.index) : text).trim(), did, attention };
}
const MAX_STEPS = 10, MAX_STEP = 160;
export const taskHandoverTitle = (task: Task) => tr('Continuing from the task “{0}”', [task.title]);
export function taskHandoverMessage(task: Task): string {
const failed = !!task.error;
const ran = when(task.lastRunAt);
const head = `**${taskHandoverTitle(task)}**${ran ? ` ${failed ? tr('(ran {0}, did not finish).', [ran]) : tr('(ran {0}, finished).', [ran])}` : ''}`;
const parts = [head];
if (failed) parts.push(`**${tr('What went wrong')}**\n\n${String(task.error).trim()}`);
const { found, did, attention } = splitTaskOutput(task.output ?? '');
if (found) parts.push(`**${tr('What it found')}**\n\n${found}`);
if (attention) parts.push(`**${tr('Needs your attention')}**\n\n${attention}`);
if (did.length) {
// the steps of a long run are many and long: the first ones, shortened
const shown = did.slice(0, MAX_STEPS).map(l => `- ${l.length > MAX_STEP ? `${l.slice(0, MAX_STEP - 1)}…` : l}`);
if (did.length > MAX_STEPS) shown.push(`- ${tr('…and {0} more steps', [did.length - MAX_STEPS])}`);
parts.push(`**${tr('What it did')}**\n\n${shown.join('\n')}`);
}
const files = (task.files ?? []).filter(f => f && typeof f.path === 'string' && f.path);
if (files.length) parts.push(`**${tr('Files')}**\n\n${files.map(f => `- ${f.path}`).join('\n')}`);
parts.push(tr('Please help me take it from here.'));
return parts.join('\n\n');
}
export const chatHandoverTitle = (session: Pick<Session, 'title' | 'messages' | 'defaultTitle'>) => tr('Continuing from the chat “{0}”', [sessionTitle(session)]);
/**
* "Continue in a new chat" on a chat or a loop that went wrong (the board): what was asked last, what went wrong or what the last answer
* was, and, for a loop, how it ended, so the new chat can take it from there.
*/
export function chatHandoverMessage(session: Session): string {
const real = session.messages.filter(m => !m.local);
const answer = [...real].reverse().find(m => m.role === 'assistant');
const asked = [...real].reverse().find(m => m.role === 'user');
const parts = [`**${chatHandoverTitle(session)}**`];
const loop = session.loop;
if (loop) {
const ended = loop.endedWhy && loop.endedWhy !== 'stopped' && loop.endedWhy !== 'closed' ? `\n\n${loopEndNote(loop.endedWhy, loop.answers)}` : '';
parts.push(`**${tr('The loop')}**\n\n${loop.prompt}${ended}`);
} else if (asked?.content) parts.push(`**${tr('What I asked')}**\n\n${asked.content.trim().slice(0, 1500)}`);
if (answer?.error) parts.push(`**${tr('What went wrong')}**\n\n${String(answer.error).trim()}`);
const said = (answer?.content ?? '').trim() || (loop?.lastText ?? '');
if (said) parts.push(`**${tr('The last answer')}**\n\n${said.slice(0, 2000)}`);
parts.push(tr('Please help me take it from here.'));
return parts.join('\n\n');
}