Compare commits

...
3 Commits
Author SHA1 Message Date
tbenandClaude Opus 5.5 66bdcff208 Bump version to 0.28.20
CI / check (push) Waiting to run
Release image / image (release) Waiting to run
Release image / computer-image (release) Waiting to run
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-30 10:26:12 +01:00
tbenandClaude Opus 5.5 d2d250e426 Render bot- and user-written markdown everywhere instead of raw text
TaskMarkdown becomes the shared MarkdownText (with a boxed, scrolling
variant). Proposal briefs, runbooks and prompts, card reasons and
research, plan goals and steps, questions, a hook's brief and the bot
panel's instructions and memory now render through it; code-like values
stay word for word.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-30 10:26:06 +01:00
tbenandClaude Opus 5.5 a569483456 Show the absolute folder a hook's runner starts in
runner_dir is relative to the bot's folder, not a run's ~, and a bare
"whatsapp" led a bot to point its runner at a folder that never
existed. The proposal card, list_hooks and propose_hook now give the
full path (hookRunnerStartPath, resolved like syncHookRunners), and the
form's help text explains the difference.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-30 10:26:06 +01:00
31 changed files with 248 additions and 111 deletions
+3 -2
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "cobble",
"version": "0.28.19",
"version": "0.28.20",
"module": "index.ts",
"type": "module",
"private": true,
+9 -18
View File
@@ -1,34 +1,25 @@
import Markdown from "react-markdown";
import remarkGfm from "remark-gfm";
import Span from "@moduletrace/twui/layout/Span";
import Stack from "@moduletrace/twui/layout/Stack";
import { MessageMarkdownComponents } from "@/src/pages/admin/bots/[bot_id]/(data)/message-markdown-components";
import linkComputerRefs from "@/src/utils/link-computer-refs";
/**
* Kept module-level: a new array on every render makes `react-markdown`
* parse the message again.
*/
const RemarkPlugins = [remarkGfm];
import MarkdownText from "./markdown-text";
type Props = {
label: string;
text: string;
/**
* Long text (a hook's brief): kept to a box that scrolls.
*/
boxed?: boolean;
};
/**
* What a hook call's run answered, rendered like a chat message (raw HTML
* never).
* Markdown about a hook under its label (what a call's run answered, the
* hook's brief), rendered like a chat message (raw HTML never).
*/
export default function HookCallAnswer({ label, text }: Props) {
export default function HookCallAnswer({ label, text, boxed }: Props) {
return (
<Stack className="w-full gap-0.5! items-stretch">
<Span className="text-[11px] leading-4 text-ink-secondary">{label}</Span>
<Stack className="w-full gap-2.5! items-start break-words">
<Markdown remarkPlugins={RemarkPlugins} components={MessageMarkdownComponents}>
{linkComputerRefs({ text })}
</Markdown>
</Stack>
<MarkdownText text={text} boxed={boxed} />
</Stack>
);
}
+2 -2
View File
@@ -11,7 +11,7 @@ import type { BotHookWithNames } from "@/src/types";
import conversationHref from "@/src/utils/conversation-href";
import hookRunnerState from "@/src/utils/hook-runner-state";
import relativeTime from "@/src/utils/relative-time";
import HookCallText from "./hook-call-text";
import HookCallAnswer from "./hook-call-answer";
import HookCalls from "./hook-calls";
import TaskFactRow from "./task-fact-row";
@@ -138,7 +138,7 @@ export default function HookDetailModal({ hook, can_manage = false, onClose, onE
</TaskFactRow>
{hook.last_error ? <TaskFactRow label="Last error">{hook.last_error}</TaskFactRow> : null}
</Stack>
{hook.instructions ? <HookCallText label="Brief" text={hook.instructions} full /> : null}
{hook.instructions ? <HookCallAnswer label="Brief" text={hook.instructions} boxed /> : null}
{status ? <SettingsStatus status={status} /> : null}
<Row className="w-full gap-2! justify-end">
{can_manage && runner?.configured ? (
+1 -1
View File
@@ -289,7 +289,7 @@ export default function HookForm({
autoComplete="off"
placeholder="whatsapp"
defaultValue={hook?.runner_dir || ""}
info={`Where it starts, inside the bot's folder: "whatsapp" is the bot's whatsapp folder. Empty starts in the bot's folder itself.`}
info={`Where it starts, relative to the bot's folder (/home/cb-<bot>/workspace), not to a run's ~: "whatsapp" is /home/cb-<bot>/workspace/whatsapp, while a folder a bot made at ~/whatsapp is "users/<user>/whatsapp". Empty starts in the bot's folder itself.`}
onChange={(e) => setRunnerDir(e.target.value)}
/>
<Select
@@ -1,10 +1,10 @@
import { describe, expect, test } from "bun:test";
import { renderToString } from "react-dom/server";
import TaskMarkdown from "./task-markdown";
import MarkdownText from "./markdown-text";
describe("TaskMarkdown", () => {
describe("MarkdownText", () => {
test("renders the markdown, not as written", () => {
const html = renderToString(<TaskMarkdown text={"## Steps\n\n- **Check** the [docs](https://example.com)"} />);
const html = renderToString(<MarkdownText text={"## Steps\n\n- **Check** the [docs](https://example.com)"} />);
expect(html).not.toContain("## Steps");
expect(html).not.toContain("**Check**");
@@ -13,7 +13,7 @@ describe("TaskMarkdown", () => {
});
test("opens links in a new tab, bare ones too", () => {
const html = renderToString(<TaskMarkdown text={"See [the docs](https://example.com) or https://example.org"} />);
const html = renderToString(<MarkdownText text={"See [the docs](https://example.com) or https://example.org"} />);
expect(html).toContain('href="https://example.com"');
expect(html).toContain('href="https://example.org"');
@@ -22,7 +22,7 @@ describe("TaskMarkdown", () => {
});
test("shows refs as chips", () => {
const html = renderToString(<TaskMarkdown text={"Ask [bot:2] about [task:20]."} />);
const html = renderToString(<MarkdownText text={"Ask [bot:2] about [task:20]."} />);
expect(html).not.toContain("[bot:2]");
expect(html).toContain("bot 2");
@@ -30,7 +30,7 @@ describe("TaskMarkdown", () => {
});
test("never renders raw HTML", () => {
const html = renderToString(<TaskMarkdown text={"<script>alert(1)</script> <b>hi</b>"} />);
const html = renderToString(<MarkdownText text={"<script>alert(1)</script> <b>hi</b>"} />);
expect(html).not.toContain("<script>");
expect(html).not.toContain("<b>");
@@ -17,17 +17,25 @@ const RemarkPlugins = [remarkGfm];
type Props = {
text: string;
/**
* Long text (a brief, a runbook, a memory): kept to a sunken box that
* scrolls, so it never pushes the rest of a card out of sight.
*/
boxed?: boolean;
className?: string;
};
/**
* A task's description or a note on it, rendered like a bot's message
* (raw HTML never rendered, links in a new tab, refs as their chips). The
* crew the chips link to is the page's own when no conversation around it
* gives one. The message elements reach this file again through the task
* chip, so they're read when it renders, never at load.
* Bot- or user-written markdown anywhere outside a message (a task's
* description and notes, a hook's or routine's brief, a skill's runbook,
* a card's reason, a bot's instructions and memory), rendered like a bot's
* message: raw HTML never rendered, links in a new tab, refs as their
* chips. Never show such text raw. The crew the chips link to is the
* page's own when no conversation around it gives one. The message
* elements reach this file again through the chips and cards, so they're
* read when it renders, never at load.
*/
export default function TaskMarkdown({ text, className }: Props) {
export default function MarkdownText({ text, boxed, className }: Props) {
const { pageProps } = useContext(AppContext);
const crew_bots = useContext(CrewBotsContext);
const crew_workspaces = useContext(CrewWorkspacesContext);
@@ -37,7 +45,13 @@ export default function TaskMarkdown({ text, className }: Props) {
return (
<CrewBotsContext.Provider value={bots}>
<CrewWorkspacesContext.Provider value={workspaces}>
<Stack className={twMerge("w-full min-w-0 gap-2! items-stretch", className)}>
<Stack
className={twMerge(
"w-full min-w-0 gap-2! items-stretch break-words",
boxed && "max-h-80 overflow-y-auto rounded-default-xs bg-sunken px-3 py-2",
className,
)}
>
<Markdown remarkPlugins={RemarkPlugins} components={MessageMarkdownComponents}>
{linkComputerRefs({ text })}
</Markdown>
+2 -2
View File
@@ -17,7 +17,7 @@ import TaskNoteRow from "@/src/components/general/task-note-row";
import TaskSubtaskRow from "@/src/components/general/task-subtask-row";
import TaskSubtasksModal from "@/src/components/general/task-subtasks-modal";
import SubtaskLinkForm from "@/src/components/general/subtask-link-form";
import TaskMarkdown from "@/src/components/general/task-markdown";
import MarkdownText from "@/src/components/general/markdown-text";
import type { BotFace } from "@/src/dict/bot-dict";
import { AppContext } from "@/src/pages/__root";
import { AppData } from "@/src/data/app-data";
@@ -474,7 +474,7 @@ export default function TaskDetailPanel({
<Span className="text-[13px] leading-[18px] text-ink">{`Waiting on you: ${task.blocked_reason}`}</Span>
) : null}
{task.description ? <TaskMarkdown text={task.description} /> : null}
{task.description ? <MarkdownText text={task.description} /> : null}
{task.workspace_id && !task.bot_id ? (
<Stack className="w-full gap-1! items-stretch">
+2 -2
View File
@@ -3,7 +3,7 @@ import Span from "@moduletrace/twui/layout/Span";
import Stack from "@moduletrace/twui/layout/Stack";
import type { TaskNote } from "@/src/types";
import relativeTime from "@/src/utils/relative-time";
import TaskMarkdown from "./task-markdown";
import MarkdownText from "./markdown-text";
type Props = {
note: TaskNote;
@@ -26,7 +26,7 @@ export default function TaskNoteRow({ note }: Props) {
</Span>
) : null}
</Row>
{note.text ? <TaskMarkdown text={note.text} /> : null}
{note.text ? <MarkdownText text={note.text} /> : null}
</Stack>
);
}
@@ -25,7 +25,7 @@ export default async function grabHookProposalView({ proposal_id, user_id }: Par
) as number[];
const [bot, workspace, computers] = await Promise.all([
BunSQLite.sql<{ name: string }>({ sql: `SELECT name FROM bots WHERE id = ?`, values: [proposal.bot_id] }),
BunSQLite.sql<{ name: string; kind: string | null }>({ sql: `SELECT name, kind FROM bots WHERE id = ?`, values: [proposal.bot_id] }),
proposal.workspace_id
? BunSQLite.sql<{ name: string }>({ sql: `SELECT name FROM workspaces WHERE id = ?`, values: [proposal.workspace_id] })
: null,
@@ -56,6 +56,8 @@ export default async function grabHookProposalView({ proposal_id, user_id }: Par
current,
workspace_name: workspace?.payload?.[0]?.name || null,
computers: new Map((computers?.payload || []).map((c) => [Number(c.id), c.name || ""])),
bot_id: proposal.bot_id,
bot_kind: bot.payload?.[0]?.kind || null,
}),
reason: proposal.reason,
};
@@ -56,7 +56,7 @@ export default function grabBotHookTools({
pauseHookTool({ user_id, bot_id, is_coordinator, workspace_id }),
deleteHookTool({ user_id, bot_id, is_coordinator, workspace_id }),
...(session_id && onPropose
? [proposeHookTool({ user_id, bot_id, session_id, workspace_id, computers, onPropose })]
? [proposeHookTool({ user_id, bot_id, session_id, workspace_id, computers, is_coordinator, onPropose })]
: []),
];
}
@@ -4,6 +4,7 @@ import { AppData } from "@/src/data/app-data";
import { BotHookSources, type BotHookSource } from "@/src/dict/bot-hook-dict";
import createHookProposal from "@/src/functions/backend/db/hook-proposals/create-hook-proposal";
import grabHookProposalView from "@/src/functions/backend/db/hook-proposals/grab-hook-proposal-view";
import computerRunDirs from "@/src/utils/computer-work-dirs";
import hookProposalRef from "@/src/utils/hook-proposal-ref";
import type { HarnessTool } from "../../../types";
import describeHookProposalForBot from "./describe-hook-proposal-for-bot";
@@ -23,6 +24,11 @@ type Params = {
* The bot's computers where it runs, the current one first.
*/
computers: BUN_SQLITE_COBBLE_COMPUTERS[];
/**
* The coordinator's folder is in the computer's workspace, a worker's
* in its own home: the runner folder is explained with the real paths.
*/
is_coordinator?: boolean;
/**
* Called with the proposal's ref, so the reply always carries its card.
*/
@@ -58,8 +64,12 @@ export default function proposeHookTool({
session_id,
workspace_id,
computers,
is_coordinator,
onPropose,
}: Params): HarnessTool<Args> {
const dirs = computerRunDirs({ bot_id, bot_kind: is_coordinator ? "coordinator" : null, user_id, workspace_id });
const home_relative = dirs.cwd.slice(dirs.bot_dir.length + 1);
const runner_folder = `relative to your bot folder ${dirs.bot_dir}, NOT to your ~ (${dirs.cwd}): a folder you made at ~/whatsapp is "${home_relative}/whatsapp", and "whatsapp" alone is ${dirs.bot_dir}/whatsapp. Empty: ${dirs.bot_dir} itself`;
const listed = computers.map((computer) => `${computer.id} (${computer.name || computer.kind})`).join(", ");
return {
@@ -68,7 +78,7 @@ export default function proposeHookTool({
workspace_id ? "in this workspace" : "in your own chat"
}, with what the caller sent attached as data, in the hook's own thread: results never come back to this chat, the user reads them by opening the hook. Runs carry the brief out without asking the user, so write it as a full brief for a future you with no memory of this chat, saying exactly what to do with each call, and lay it out as the plan the run follows: the steps in order, each naming what it produces. ${
computers.length ? `Your computers here: ${listed}.` : `You have no computer here, so it can't watch one.`
} To change one of your hooks (ids from list_hooks), give hook_id and only what changes: title, instructions, watch_filter, enabled true to switch a paused one back on, or its runner; what calls it and where it runs can't change. A hook whose caller is a process on your computer (a bridge started there) can keep it running: give runner_command, the command the app runs for it, runner_dir (a folder inside the bot's folder, such as whatsapp) and, if not the bot's own, runner_computer_id. The app starts it again by itself within five minutes of it dying, and when the computer restarts, so it must stay in the foreground and not go into the background with &. It runs as the bot's account, and the card shows the command word for word: only a crew manager can confirm a runner, so if the user isn't one, tell them an admin has to. Nothing is saved until the user presses Confirm on the card. A new hook's URL is shown to the user on the card, once: you never see it, never ask for it, and never set a signing secret (the user adds one from the Hooks menu). Check list_hooks first: if a hook already does the job, propose a change to it instead. When the user tells you to handle a hook's calls differently (often in reply to a run's report), tell them the hook's brief has to change for that and propose the new brief. Runs follow the brief over your memory, so don't save it to your memory or promise to do it from now on instead: neither changes what the next call does.`,
} To change one of your hooks (ids from list_hooks), give hook_id and only what changes: title, instructions, watch_filter, enabled true to switch a paused one back on, or its runner; what calls it and where it runs can't change. A hook whose caller is a process on your computer (a bridge started there) can keep it running: give runner_command, the command the app runs for it, runner_dir (the folder it starts in, ${runner_folder}; the card shows the full path) and, if not the bot's own, runner_computer_id. The app starts it again by itself within five minutes of it dying, and when the computer restarts, so it must stay in the foreground and not go into the background with &. It runs as the bot's account, and the card shows the command word for word: only a crew manager can confirm a runner, so if the user isn't one, tell them an admin has to. Nothing is saved until the user presses Confirm on the card. A new hook's URL is shown to the user on the card, once: you never see it, never ask for it, and never set a signing secret (the user adds one from the Hooks menu). Check list_hooks first: if a hook already does the job, propose a change to it instead. When the user tells you to handle a hook's calls differently (often in reply to a run's report), tell them the hook's brief has to change for that and propose the new brief. Runs follow the brief over your memory, so don't save it to your memory or promise to do it from now on instead: neither changes what the next call does.`,
schema: z.object({
hook_id: z.number().int().positive().optional().describe("The hook to change; leave out for a new one"),
title: z.string().trim().min(1).max(80).optional().describe(`A short name, e.g. "GitHub pushes"`),
@@ -92,7 +102,7 @@ export default function proposeHookTool({
.trim()
.max(AppData.BotHookRunnerDirMaxLength)
.optional()
.describe(`The folder it starts in, inside the bot's folder, e.g. "whatsapp". Empty: the bot's folder`),
.describe(`The folder it starts in, ${runner_folder}`),
runner_computer_id: z
.number()
.int()
@@ -251,13 +251,13 @@ export default function BotPanel({
<BotReadOnlyBlock
title="Instructions"
content={system_prompt || ""}
className="h-52"
className="max-h-52"
/>
<Divider className="my-2 border-hairline dark:border-hairline" />
<BotReadOnlyBlock
title="Memory"
content={memory || ""}
className="h-52"
className="max-h-52"
/>
{workspace_id ? (
<>
@@ -269,7 +269,7 @@ export default function BotPanel({
.instructions
?.memory || ""
}
className="h-40"
className="max-h-40"
/>
</>
) : null}
@@ -1,4 +1,5 @@
import { useState } from "react";
import MarkdownText from "@/src/components/general/markdown-text";
import { twMerge } from "tailwind-merge";
import Button from "@moduletrace/twui/layout/Button";
import Span from "@moduletrace/twui/layout/Span";
@@ -93,7 +94,7 @@ export default function BotPlanCard({ plan_id }: Props) {
<Span className="text-[12px] leading-4 text-ink-secondary">{botPlanStatusLine({ view })}</Span>
{view.goal ? (
<Span className="text-[13px] leading-5 text-ink-secondary">{view.goal}</Span>
<MarkdownText text={view.goal} className="text-ink-secondary" />
) : null}
<Span className="flex w-full flex-col gap-1.5 pt-0.5">
@@ -1,4 +1,5 @@
import Span from "@moduletrace/twui/layout/Span";
import MarkdownText from "@/src/components/general/markdown-text";
import { twMerge } from "tailwind-merge";
import { Circle, CircleCheck, CircleSlash, CircleDot } from "lucide-react";
import type { BotPlanStep } from "@/src/types";
@@ -40,11 +41,11 @@ export default function BotPlanStepRow({ step, current }: Props) {
(done || skipped) && "text-ink-secondary",
)}
>
{step.text}
<MarkdownText text={step.text} />
</Span>
{step.note ? (
<Span className="text-[12px] leading-4 text-ink-secondary">{step.note}</Span>
<MarkdownText text={step.note} className="text-ink-secondary" />
) : current ? (
<Span className="text-[12px] leading-4 text-ink-secondary">Working on this now.</Span>
) : null}
@@ -1,4 +1,5 @@
import Input from "@moduletrace/twui/form/Input";
import MarkdownText from "@/src/components/general/markdown-text";
import Radios from "@moduletrace/twui/form/Radios";
import Span from "@moduletrace/twui/layout/Span";
import Stack from "@moduletrace/twui/layout/Stack";
@@ -54,9 +55,7 @@ export default function BotQuestionField({
return (
<Stack className="w-full gap-0! items-stretch">
<MessageDetailsHeading>{`${index + 1}. ${single ? "Pick one" : "Pick any"}`}</MessageDetailsHeading>
<Span className="whitespace-pre-wrap text-[13px] leading-5 font-bold text-ink break-words">
{item.question}
</Span>
<MarkdownText text={item.question} className="font-bold" />
{open ? (
<Stack className="mt-2 w-full gap-2! items-stretch">
@@ -1,25 +1,29 @@
import CodeEditor from "@/src/components/general/code-editor";
import Span from "@moduletrace/twui/layout/Span";
import Stack from "@moduletrace/twui/layout/Stack";
import MarkdownText from "@/src/components/general/markdown-text";
type BotReadOnlyBlockProps = {
title: string;
content: string;
/**
* The box's height cap (a `max-h-*`), so a long memory scrolls.
*/
className?: string;
};
/** A block of a bot's own text its panel shows a user read-only. */
export default function BotReadOnlyBlock({
title,
content,
className,
}: BotReadOnlyBlockProps) {
/**
* A block of a bot's own text (its instructions, a memory) its panel shows
* a user read-only: markdown, rendered, never the raw text.
*/
export default function BotReadOnlyBlock({ title, content, className }: BotReadOnlyBlockProps) {
return (
<CodeEditor
title={title}
content={content || "Nothing yet."}
mode="markdown"
className={className}
readOnly
onChange={() => {}}
/>
<Stack className="w-full gap-1! items-stretch">
<Span className="text-[12px] leading-4 text-ink-secondary">{title}</Span>
{content.trim() ? (
<MarkdownText text={content} boxed className={className} />
) : (
<Span className="text-[13px] leading-5 text-ink-secondary">Nothing yet.</Span>
)}
</Stack>
);
}
}
@@ -74,7 +74,7 @@ export default function BotUserMemory({
<BotReadOnlyBlock
title="About you"
content={memory}
className="h-32"
className="max-h-32"
/>
</>
);
@@ -91,7 +91,7 @@ export default function BotUserMemory({
mode="markdown"
placeholder="What it should keep in mind about you..."
info="Markdown, replaced whole. Only this bot, and only when it works with you."
className="h-32"
className="max-h-32"
onChange={(value) => {
setText(value);
setSaved(false);
@@ -1,4 +1,5 @@
import { useContext, useState } from "react";
import MarkdownText from "@/src/components/general/markdown-text";
import Button from "@moduletrace/twui/layout/Button";
import Row from "@moduletrace/twui/layout/Row";
import Span from "@moduletrace/twui/layout/Span";
@@ -89,7 +90,7 @@ export default function HookProposalCard({ view, onDecided, onDone }: Props) {
) : null}
<MessageDetailsHeading>Why (written by the bot)</MessageDetailsHeading>
<Span className="whitespace-pre-wrap text-[13px] leading-5 text-ink break-words">{view.reason}</Span>
<MarkdownText text={view.reason || ""} />
{view.outcome ? <Span className="mt-4 text-[13px] leading-5 text-ink">{view.outcome}</Span> : null}
@@ -1,4 +1,5 @@
import { useContext, useState } from "react";
import MarkdownText from "@/src/components/general/markdown-text";
import Button from "@moduletrace/twui/layout/Button";
import Row from "@moduletrace/twui/layout/Row";
import Span from "@moduletrace/twui/layout/Span";
@@ -84,7 +85,7 @@ export default function ProposalCard({ view, onDecided }: Props) {
<MessageDetailsHeading>
{is_skill ? "Review (written by the bot)" : "Background check (written by the bot)"}
</MessageDetailsHeading>
<Span className="whitespace-pre-wrap text-[13px] leading-5 text-ink break-words">{view.research}</Span>
<MarkdownText text={view.research || ""} />
<Stack className="mt-1 w-full gap-0! items-stretch">
{view.sources.length ? (
view.sources.map((url) => <ProposalSourceRow key={url} url={url} />)
@@ -0,0 +1,21 @@
import { describe, expect, test } from "bun:test";
import { renderToString } from "react-dom/server";
import ProposalDetailRow from "./proposal-detail-row";
describe("ProposalDetailRow", () => {
test("renders a markdown brief instead of showing it raw", () => {
const html = renderToString(
<ProposalDetailRow label="Brief" value={"## Steps\n\n1. **Read** the call"} block markdown />,
);
expect(html).toContain("<li");
expect(html).not.toContain("## Steps");
expect(html).not.toContain("**Read**");
});
test("keeps a code-like value word for word", () => {
const html = renderToString(<ProposalDetailRow label="Keeps running" value="./run.sh --flag **x**" block />);
expect(html).toContain("./run.sh --flag **x**");
});
});
@@ -1,24 +1,30 @@
import Row from "@moduletrace/twui/layout/Row";
import Span from "@moduletrace/twui/layout/Span";
import { twMerge } from "tailwind-merge";
import MarkdownText from "@/src/components/general/markdown-text";
import type { ExtensionProposalDetail } from "@/src/types";
/**
* One line of what a proposed server or tool would do, as the app read it
* from the config: a label, and its value, code-like ones as a block.
* from the config: a label, and its value, code-like ones as a block and
* markdown ones (a brief, a runbook) rendered.
*/
export default function ProposalDetailRow({ label, value, block }: ExtensionProposalDetail) {
export default function ProposalDetailRow({ label, value, block, markdown }: ExtensionProposalDetail) {
return (
<Row className="w-full py-2 gap-3! flex-nowrap items-baseline border-0 border-b border-solid border-hairline last:border-b-0">
<Span className="w-28 shrink-0 text-[12px] leading-4 text-ink-secondary">{label}</Span>
<Span
className={twMerge(
"grow min-w-0 text-[13px] leading-5 text-ink break-words",
block && "max-h-48 overflow-auto whitespace-pre-wrap rounded-default-xs bg-sunken px-2 py-1 font-mono text-[12px]",
)}
>
{value}
</Span>
{markdown ? (
<MarkdownText text={value} boxed={block} className="grow text-[13px] leading-5" />
) : (
<Span
className={twMerge(
"grow min-w-0 text-[13px] leading-5 text-ink break-words",
block && "max-h-48 overflow-auto whitespace-pre-wrap rounded-default-xs bg-sunken px-2 py-1 font-mono text-[12px]",
)}
>
{value}
</Span>
)}
</Row>
);
}
@@ -1,4 +1,5 @@
import { useContext, useState } from "react";
import MarkdownText from "@/src/components/general/markdown-text";
import Input from "@moduletrace/twui/form/Input";
import Button from "@moduletrace/twui/layout/Button";
import Row from "@moduletrace/twui/layout/Row";
@@ -113,11 +114,11 @@ export default function SecretRequestCard({ view, onDecided, onDone }: Props) {
return (
<Stack className="w-full gap-0! items-stretch">
<MessageDetailsHeading>What it is</MessageDetailsHeading>
<Span className="text-[13px] leading-5 text-ink break-words">{view.description}</Span>
<MarkdownText text={view.description || ""} />
<Span className="mt-1 text-[12px] leading-4 text-ink-secondary">{`Saved as ${view.key}, for your runs of ${view.bot_name} only.`}</Span>
<MessageDetailsHeading>Why (written by the bot)</MessageDetailsHeading>
<Span className="whitespace-pre-wrap text-[13px] leading-5 text-ink break-words">{view.reason}</Span>
<MarkdownText text={view.reason || ""} />
{open ? (
<Stack className="mt-5 w-full gap-2! items-stretch">
+5
View File
@@ -1617,6 +1617,11 @@ export type ExtensionProposalDetail = {
* Long or code-like: shown as a block.
*/
block?: boolean;
/**
* Written in markdown (a brief, a runbook, a prompt): rendered, never
* shown raw.
*/
markdown?: boolean;
};
/**
@@ -8,6 +8,7 @@ describe("describeHookProposalDetails", () => {
data: { title: "GitHub pushes", instructions: "Summarise each push.", source: "url", computer_id: 3 },
workspace_name: "Launch",
computers: new Map([[3, "Main"]]),
bot_id: 4,
});
expect(details).toEqual([
@@ -15,7 +16,7 @@ describe("describeHookProposalDetails", () => {
{ label: "Called by", value: "Anyone with its URL (shown to you once, when you confirm)" },
{ label: "Runs in", value: "The workspace Launch" },
{ label: "Runs on", value: "Main (#3)" },
{ label: "Brief", value: "Summarise each push.", block: true },
{ label: "Brief", value: "Summarise each push.", block: true, markdown: true },
]);
});
@@ -24,6 +25,7 @@ describe("describeHookProposalDetails", () => {
action: "create",
data: { title: "Slack", instructions: "Answer.", source: "browser_notifications", watch_computer_id: 2 },
computers: new Map([[2, "Desk"]]),
bot_id: 4,
});
expect(details.find((d) => d.label == "Called by")?.value).toBe("Browser notifications on Desk (#2)");
@@ -38,6 +40,7 @@ describe("describeHookProposalDetails", () => {
data: { instructions: "New brief.", enabled: true },
current: { id: 7, title: "GitHub pushes", instructions: "Old brief.", enabled: 0 },
computers: new Map(),
bot_id: 4,
});
expect(details.map((d) => d.label)).toEqual(["Hook", "Brief now", "New brief", "Switch on"]);
@@ -57,6 +60,7 @@ describe("describeHookProposalDetails", () => {
runner_computer_id: 1,
},
computers: new Map([[1, "Main"]]),
bot_id: 4,
});
expect(details.map((d) => d.label)).toEqual([
@@ -74,7 +78,7 @@ describe("describeHookProposalDetails", () => {
value: "python3 bridge.py",
block: true,
});
expect(details.find((d) => d.label == "Starts in")?.value).toBe("The bot's whatsapp folder");
expect(details.find((d) => d.label == "Starts in")?.value).toBe("/home/cb-4/workspace/whatsapp");
expect(details.find((d) => d.label == "Runs it on")?.value).toContain("Main (#1)");
});
@@ -84,10 +88,39 @@ describe("describeHookProposalDetails", () => {
data: { runner_command: "python3 bridge.py", runner_dir: "whatsapp", runner_computer_id: 1 },
current: { id: 7, title: "WhatsApp", instructions: "Answer.", enabled: 1 },
computers: new Map([[1, "Main"]]),
bot_id: 4,
});
expect(details.map((d) => d.label)).toEqual(["Hook", "Runner now", "New runner"]);
expect(details.map((d) => d.label)).toEqual(["Hook", "Runner now", "New runner", "Will start in", "Runs it on"]);
expect(details[1]?.value).toBe("None");
expect(details[2]?.value).toBe("python3 bridge.py in whatsapp, on Main (#1)");
expect(details[2]?.value).toBe("python3 bridge.py");
expect(details[3]?.value).toBe("/home/cb-4/workspace/whatsapp");
expect(details[4]?.value).toBe("Main (#1)");
});
test("a runner moved to another folder shows both absolute paths", () => {
const details = describeHookProposalDetails({
action: "change",
data: { runner_command: "./run.sh", runner_dir: "users/1/whatsapp" },
current: { id: 2, title: "WhatsApp", enabled: 1, runner_command: "./run.sh", runner_dir: "whatsapp", runner_computer_id: 1 },
computers: new Map([[1, "Main"]]),
bot_id: 4,
});
expect(details.find((d) => d.label == "Starts in now")?.value).toBe("/home/cb-4/workspace/whatsapp");
expect(details.find((d) => d.label == "Will start in")?.value).toBe("/home/cb-4/workspace/users/1/whatsapp");
});
test("the coordinator's runner starts in its folder in the computer's workspace", () => {
const details = describeHookProposalDetails({
action: "change",
data: { runner_command: "./run.sh", runner_dir: "bridge" },
current: { id: 2, title: "Bridge", enabled: 1 },
computers: new Map(),
bot_id: 1,
bot_kind: "coordinator",
});
expect(details.find((d) => d.label == "Will start in")?.value).toBe("/home/gem/workspace/bots/1/bridge");
});
});
+20 -18
View File
@@ -1,6 +1,7 @@
import type { HookProposalAction } from "@/src/dict/bot-hook-dict";
import type { HookProposalData } from "@/src/schemas/bot-hook-schema";
import type { BotHookWithNames, ExtensionProposalDetail } from "@/src/types";
import hookRunnerStartPath from "./hook-runner-start-path";
type Params = {
action: HookProposalAction;
@@ -18,6 +19,12 @@ type Params = {
* Computer names by id.
*/
computers: Map<number, string>;
/**
* The bot that runs it, so a runner's folder shows as the absolute
* path it starts in.
*/
bot_id: number | string;
bot_kind?: string | null;
};
/**
@@ -32,8 +39,11 @@ export default function describeHookProposalDetails({
current,
workspace_name,
computers,
bot_id,
bot_kind,
}: Params): ExtensionProposalDetail[] {
const computer = (id?: number | null) => (id ? `${computers.get(Number(id)) || "Computer"} (#${id})` : "");
const folder = (dir?: string | null) => hookRunnerStartPath({ bot_id, bot_kind, runner_dir: dir }) || dir || "";
if (action == "create") {
const watching = data.source == "browser_notifications";
@@ -55,14 +65,14 @@ export default function describeHookProposalDetails({
...(data.runner_command
? [
{ label: "Keeps running", value: data.runner_command, block: true },
{ label: "Starts in", value: data.runner_dir ? `The bot's ${data.runner_dir} folder` : "The bot's folder" },
{ label: "Starts in", value: folder(data.runner_dir) },
{
label: "Runs it on",
value: `${computer(data.runner_computer_id) || "The bot's computer"}, as the bot's account, in its own process`,
},
]
: []),
{ label: "Brief", value: data.instructions || "", block: true },
{ label: "Brief", value: data.instructions || "", block: true, markdown: true },
];
}
@@ -76,8 +86,8 @@ export default function describeHookProposalDetails({
if (data.instructions !== undefined) {
lines.push(
{ label: "Brief now", value: current?.instructions || "", block: true },
{ label: "New brief", value: data.instructions, block: true },
{ label: "Brief now", value: current?.instructions || "", block: true, markdown: true },
{ label: "New brief", value: data.instructions, block: true, markdown: true },
);
}
@@ -91,22 +101,14 @@ export default function describeHookProposalDetails({
if (data.enabled) lines.push({ label: "Switch on", value: "It's paused now; calls would run again" });
if (data.runner_command !== undefined) {
const shown = ({ command, dir }: { command: string; dir?: string | null }) =>
`${command}${dir ? ` in ${dir}` : ""}`;
lines.push(
{ label: "Runner now", value: current?.runner_command || "None", block: Boolean(current?.runner_command) },
...(current?.runner_command ? [{ label: "Starts in now", value: folder(current.runner_dir) }] : []),
{ label: "New runner", value: data.runner_command ?? "", block: true },
{ label: "Will start in", value: folder(data.runner_dir) },
{
label: "Runner now",
value: current?.runner_command ? shown({ command: current.runner_command, dir: current.runner_dir }) : "None",
},
{
label: "New runner",
value: `${shown({ command: data.runner_command ?? "", dir: data.runner_dir })}, on ${
computer(data.runner_computer_id) ||
computer(current?.runner_computer_id || null) ||
"the bot's computer"
}`,
block: true,
label: "Runs it on",
value: computer(data.runner_computer_id) || computer(current?.runner_computer_id || null) || "The bot's computer",
},
);
}
+8
View File
@@ -50,6 +50,14 @@ describe("describeHookRunner", () => {
);
});
test("gives the absolute folder when it knows the bot", () => {
const text = describeHookRunner({
hook: { ...base, bot_id: 4, bot_kind: "worker", runner_command: "./run.sh", runner_dir: "whatsapp", runner_last_error: "x" },
});
expect(text).toContain('starts in /home/cb-4/workspace/whatsapp (runner_dir "whatsapp", relative to the bot\'s folder, not your ~)');
});
test("is part of the hook a bot lists", () => {
expect(
describeBotHook({ hook: { ...base, runner_command: "./run.sh", runner_last_error: "It isn't running." } }),
+7 -1
View File
@@ -1,4 +1,5 @@
import type { BotHookWithNames } from "@/src/types";
import hookRunnerStartPath from "./hook-runner-start-path";
import hookRunnerState from "./hook-runner-state";
type Params = {
@@ -20,8 +21,13 @@ export default function describeHookRunner({ hook }: Params) {
if (!state.configured) return "";
const folder = hook.bot_id
? hookRunnerStartPath({ bot_id: hook.bot_id, bot_kind: hook.bot_kind, runner_dir: hook.runner_dir })
: null;
const where = [
`starts in ${hook.runner_dir ? `"${hook.runner_dir}" inside the bot's folder` : "the bot's folder"} (not your ~)`,
folder
? `starts in ${folder} (runner_dir "${hook.runner_dir || ""}", relative to the bot's folder, not your ~)`
: `starts in ${hook.runner_dir ? `"${hook.runner_dir}" inside the bot's folder` : "the bot's folder"} (not your ~)`,
hook.runner_computer_id ? `on computer ${hook.runner_computer_id}` : "",
]
.filter(Boolean)
+1 -1
View File
@@ -75,7 +75,7 @@ export default function describeProposalDetails(params: Params): ExtensionPropos
return [
...common,
{ label: "Kind", value: "Prompt, one turn with the bot's models" },
{ label: "Prompt", value: tool.config.prompt, block: true },
{ label: "Prompt", value: tool.config.prompt, block: true, markdown: true },
parameters,
...reach,
];
+1 -1
View File
@@ -38,7 +38,7 @@ export default function describeSkillProposal({ data, current }: Params): Extens
},
]
: []),
{ label: "Runbook", value: data.body, block: true },
{ label: "Runbook", value: data.body, block: true, markdown: true },
{ label: "Starts", value: data.enabled ? "On" : "Off" },
{
label: "Who gets it",
+30
View File
@@ -0,0 +1,30 @@
import computerRunDirs from "./computer-work-dirs";
import hookRunnerDir from "./hook-runner-paths";
type Params = {
bot_id: number | string;
/**
* `coordinator`: its folder is `bots/<id>` in the computer's workspace,
* a worker's is `/home/cb-<id>/workspace`.
*/
bot_kind?: string | null;
runner_dir?: string | null;
};
/**
* The absolute folder a hook's runner starts in, as the bot's account sees
* it, the same way `syncHookRunners` works it out: `runner_dir` is relative
* to the bot's folder, which is not a run's `~` (that is `users/<user>`
* inside it), so a card or a bot reading only "whatsapp" can't tell which
* folder it means. Null when the folder would be refused (absolute, `~`,
* climbing out), so the caller shows what was given instead.
*/
export default function hookRunnerStartPath({ bot_id, bot_kind, runner_dir }: Params) {
try {
const dirs = computerRunDirs({ bot_id, bot_kind, user_id: 0 });
return hookRunnerDir({ dirs, runner_dir });
} catch {
return null;
}
}