Files
loki/scripts/test/session-screen.ts
CatoandClaude 85e8deac30 feat(mcp): a connected agent lists open sessions and reads what a session's terminal shows (#1653)
Over MCP an agent could send a task to a project's agent (loki_dispatch) and
was told not to poll: it had no way to see that the session was up or to
read what the agent answered. The HTTP side got both for a token in #1641.

- loki_sessions: agent sessions open on the owner's builders, each with the
  link that opens the same session in Loki's Terminal. Plain shells are
  never listed.
- loki_session_read: the end of one session's terminal output as plain text
  (escape sequences removed, redrawn and repeated lines collapsed). Queues
  the same peek_tab command as POST /api/control/peek-tab and waits up to
  twenty seconds; a builder that does not answer is an error that says so.
  A plain shell is refused before anything is queued.
- both read only, so both sit under loki.chat, as the scope rule requires.


Claude-Session: https://claude.ai/code/session_019MDtmtCjm3CvrFm3kYaTgy

Co-authored-by: Claude <noreply@anthropic.com>
2026-11-12 08:05:27 +01:00

19 lines
805 B
TypeScript

/** A session's terminal output, as text a model reads (lib/session-screen). */
import assert from "node:assert/strict";
import { plainSessionText } from "../../src/lib/session-screen";
assert.equal(plainSessionText("\x1b[1mhello\x1b[0m\r\n"), "hello", "escape sequences go");
assert.equal(
plainSessionText("thinking…\rDone.\n"),
"Done.",
"a redrawn line shows its last write",
);
assert.equal(plainSessionText("a\n\n\n\nb\nb\nc"), "a\n\nb\nc", "repeats collapse");
assert.equal(plainSessionText("\x1b]0;title\x07x"), "x", "window titles go");
assert.equal(plainSessionText(""), "");
const long = plainSessionText(`${"x".repeat(50)}END`, 10);
assert.equal(long.length, 10);
assert.ok(long.startsWith("…") && long.endsWith("END"), "the end is what is kept");
console.log("session-screen ok");