Add computer switching, crew reporting, job steps and markdown chat
- Bots have a current computer (bots.computer_id), switched from the chat header beside the model button or by clicking a computer the bot names ([computer:ID]); tasks run on it by default - search_computers runs one read-only command on all of a bot's computers; chat replies know their computers (compose-computers-note) - The coordinator can use every computer and grants or revokes crew access with assign_computer - Delegated jobs record requested_by_bot_id; the worker's result or failure is reported back in the coordinator's conversation - bots_queue_updates records each model turn of a job, pushed live and shown in the working-on panel - Live relay: every process pushes new messages, job steps and bot changes from the database to its own sockets, so work done elsewhere shows live - Bot messages render as markdown (react-markdown + remark-gfm, no raw HTML) with twui components; rail previews are plain text - Fix header button overflow in the model and computer selects - Bump @moduletrace/twui to 0.1.2 Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
/**
|
||||
* How a bot names one of its computers in a message: `[computer:3]`. The
|
||||
* chat shows it as a button that switches the bot to that computer.
|
||||
*/
|
||||
export default function computerRef({ id }: { id: number | string }) {
|
||||
return `[computer:${id}]`;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import { describe, expect, test } from "bun:test";
|
||||
import computerRef from "./computer-ref";
|
||||
import linkComputerRefs from "./link-computer-refs";
|
||||
|
||||
describe("linkComputerRefs", () => {
|
||||
test("links every computer a message names", () => {
|
||||
expect(
|
||||
linkComputerRefs({
|
||||
text: `Your GitHub session is on ${computerRef({ id: 3 })}, not ${computerRef({ id: 12 })}.`,
|
||||
}),
|
||||
).toBe("Your GitHub session is on [computer 3](#computer-3), not [computer 12](#computer-12).");
|
||||
});
|
||||
|
||||
test("leaves look-alikes and existing links alone", () => {
|
||||
const text = "See [computer:x], [link](url) and [computer:4](https://example.com)";
|
||||
|
||||
expect(linkComputerRefs({ text })).toBe(text);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,18 @@
|
||||
/**
|
||||
* The link target a computer ref (`computerRef`) becomes, e.g.
|
||||
* `#computer-3`. The chat's markdown renders these links as buttons that
|
||||
* switch the bot to that computer.
|
||||
*/
|
||||
export const ComputerRefHrefPrefix = "#computer-";
|
||||
|
||||
/**
|
||||
* Turns every computer ref in a message into a markdown link to
|
||||
* `#computer-<id>`, so it survives markdown rendering as a link the chat
|
||||
* can swap for a switch button.
|
||||
*/
|
||||
export default function linkComputerRefs({ text }: { text: string }) {
|
||||
return text.replace(
|
||||
/\[computer:(\d+)\](?!\()/g,
|
||||
(_, id: string) => `[computer ${id}](${ComputerRefHrefPrefix}${id})`,
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import { describe, expect, test } from "bun:test";
|
||||
import messagePreview from "./message-preview";
|
||||
|
||||
describe("messagePreview", () => {
|
||||
test("strips markdown and names computers plainly", () => {
|
||||
expect(
|
||||
messagePreview({
|
||||
text: "## Found it\n\nYour **GitHub** session is on [computer:3]. See [the docs](https://x.y) and `search_computers`.\n\n- *one*\n- two",
|
||||
}),
|
||||
).toBe("Found it Your GitHub session is on a computer. See the docs and search_computers. one two");
|
||||
});
|
||||
|
||||
test("keeps code text without its fences", () => {
|
||||
expect(messagePreview({ text: "Run:\n```bash\nls ~\n```" })).toBe("Run: ls ~");
|
||||
});
|
||||
|
||||
test("leaves plain text alone", () => {
|
||||
expect(messagePreview({ text: "All done, 3 files_moved." })).toBe("All done, 3 files_moved.");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
* A bot message as one line of plain text, for the rail's preview: no
|
||||
* markdown syntax, links as their text, computer refs (`computerRef`) as
|
||||
* "a computer", whitespace collapsed.
|
||||
*/
|
||||
export default function messagePreview({ text }: { text: string }) {
|
||||
return text
|
||||
.replace(/```[^\n]*\n?/g, "")
|
||||
.replace(/\[computer:\d+\](?!\()/g, "a computer")
|
||||
.replace(/!?\[([^\]]*)\]\([^)]*\)/g, "$1")
|
||||
.replace(/^\s{0,3}(#{1,6}\s+|>\s?|[-*+]\s+|\d+\.\s+)/gm, "")
|
||||
.replace(/(\*\*|__|~~|`)/g, "")
|
||||
.replace(/(^|\s)[*_](\S[^*_]*\S|\S)[*_](?=\s|$|[.,;:!?])/g, "$1$2")
|
||||
.replace(/\|/g, " ")
|
||||
.replace(/\s+/g, " ")
|
||||
.trim();
|
||||
}
|
||||
Reference in New Issue
Block a user