Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
54ba0e845d | ||
|
|
1da980e243 | ||
|
|
66bdcff208 | ||
|
|
d2d250e426 | ||
|
|
a569483456 |
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "cobble",
|
||||
"version": "0.28.19",
|
||||
"version": "0.28.21",
|
||||
"module": "index.ts",
|
||||
"type": "module",
|
||||
"private": true,
|
||||
|
||||
@@ -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>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { useState } from "react";
|
||||
import Tag from "@moduletrace/twui/elements/Tag";
|
||||
import Button from "@moduletrace/twui/layout/Button";
|
||||
import Link from "@moduletrace/twui/layout/Link";
|
||||
import Row from "@moduletrace/twui/layout/Row";
|
||||
@@ -11,7 +12,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";
|
||||
|
||||
@@ -99,12 +100,18 @@ export default function HookDetailModal({ hook, can_manage = false, onClose, onE
|
||||
{runner?.configured ? (
|
||||
<>
|
||||
<TaskFactRow label="Runner">
|
||||
{runner.running
|
||||
? `Up since ${relativeTime({ at: Number(hook.runner_started_at) || Date.now() })}`
|
||||
: "Down"}
|
||||
{runner.running ? (
|
||||
`Up since ${relativeTime({ at: Number(hook.runner_started_at) || Date.now() })}`
|
||||
) : (
|
||||
<Tag color="error" variant="outlined" className="px-1.5 py-0 text-[11px] font-bold leading-4">
|
||||
Down
|
||||
</Tag>
|
||||
)}
|
||||
</TaskFactRow>
|
||||
{runner.error ? (
|
||||
<TaskFactRow label="Check failed">{runner.error}</TaskFactRow>
|
||||
<TaskFactRow label="Check failed">
|
||||
<Span className="text-error break-words min-w-0">{runner.error}</Span>
|
||||
</TaskFactRow>
|
||||
) : null}
|
||||
<TaskFactRow label="Last checked">
|
||||
{hook.runner_checked_at
|
||||
@@ -136,9 +143,13 @@ export default function HookDetailModal({ hook, can_manage = false, onClose, onE
|
||||
<TaskFactRow label="Last called">
|
||||
{hook.last_called_at ? relativeTime({ at: Number(hook.last_called_at) }) : "Never"}
|
||||
</TaskFactRow>
|
||||
{hook.last_error ? <TaskFactRow label="Last error">{hook.last_error}</TaskFactRow> : null}
|
||||
{hook.last_error ? (
|
||||
<TaskFactRow label="Last error">
|
||||
<Span className="text-error break-words min-w-0">{hook.last_error}</Span>
|
||||
</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 ? (
|
||||
|
||||
@@ -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: "whatsapp" is looked for in your own folder in the bot's (/home/cb-<bot>/workspace/users/<you>, a run's ~) first, then in the bot's folder (/home/cb-<bot>/workspace), and the first one there is used. Empty starts in the bot's folder itself.`}
|
||||
onChange={(e) => setRunnerDir(e.target.value)}
|
||||
/>
|
||||
<Select
|
||||
|
||||
@@ -59,6 +59,7 @@ export default function HookRow({ hook, busy, onOpen, onToggle, onEdit, onCalls,
|
||||
title={title}
|
||||
onOpen={onOpen}
|
||||
badge={badge}
|
||||
badge_tone={badge == "Runner down" ? "error" : undefined}
|
||||
subtitle={hookSubtitle({ hook, show_bot: !compact, show_workspace: !compact })}
|
||||
>
|
||||
<SettingsRowMenu title={`${title} menu`} disabled={busy}>
|
||||
|
||||
+6
-6
@@ -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>");
|
||||
+21
-7
@@ -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>
|
||||
@@ -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">
|
||||
|
||||
@@ -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>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ export const HookRunnerProtocol = 1;
|
||||
* Bump with every change to `HookRunnerScript`: every runner restarts once
|
||||
* with the new script.
|
||||
*/
|
||||
export const HookRunnerVersion = "2";
|
||||
export const HookRunnerVersion = "3";
|
||||
|
||||
/**
|
||||
* The process keeper the app runs on a computer for a hook's runner
|
||||
@@ -134,14 +134,15 @@ def stop(runner_id, state, stop_ms):
|
||||
|
||||
def start(runner, env, log_max):
|
||||
runner_id = runner["id"]
|
||||
cwd = runner["cwd"]
|
||||
if not os.path.isdir(cwd):
|
||||
cwds = runner.get("cwds") or [runner["cwd"]]
|
||||
cwd = next((folder for folder in cwds if os.path.isdir(folder)), None)
|
||||
if cwd is None:
|
||||
return {
|
||||
"id": runner_id,
|
||||
"pid": None,
|
||||
"running": False,
|
||||
"started_at": None,
|
||||
"error": "Its folder isn't there: %s" % cwd,
|
||||
"error": "Its folder isn't there: %s" % " or ".join(cwds),
|
||||
}
|
||||
log = log_path(runner_id)
|
||||
try:
|
||||
|
||||
@@ -8,7 +8,7 @@ import composeComputerEnvFiles from "@/src/harness/tools/computer/compose-comput
|
||||
import type { HookRunnerSync } from "@/src/types";
|
||||
import computerNotReadyMessage from "@/src/utils/computer-not-ready-message";
|
||||
import computerRunDirs from "@/src/utils/computer-work-dirs";
|
||||
import hookRunnerDir, { hookRunnerBaseDir, hookRunnerFile } from "@/src/utils/hook-runner-paths";
|
||||
import { hookRunnerBaseDir, hookRunnerDirs, hookRunnerFile } from "@/src/utils/hook-runner-paths";
|
||||
import hookRunnerVersion from "@/src/utils/hook-runner-version";
|
||||
import type { ComputerAddress } from "../computers/grab-computer-target";
|
||||
import grabComputerTarget from "../computers/grab-computer-target";
|
||||
@@ -189,7 +189,7 @@ async function runGroup({
|
||||
workspace_id,
|
||||
});
|
||||
const base = hookRunnerBaseDir({ dirs });
|
||||
const runners: { id: number; command: string; cwd: string; version: string }[] = [];
|
||||
const runners: { id: number; command: string; cwd: string; cwds: string[]; version: string }[] = [];
|
||||
const wanted = new Set<number>();
|
||||
|
||||
for (const hook of group.hooks) {
|
||||
@@ -203,7 +203,7 @@ async function runGroup({
|
||||
user_id: hook.user_id,
|
||||
workspace_id: hook.workspace_id,
|
||||
});
|
||||
const cwd = hookRunnerDir({ dirs: hook_dirs, runner_dir: hook.runner_dir });
|
||||
const cwds = hookRunnerDirs({ dirs: hook_dirs, runner_dir: hook.runner_dir });
|
||||
const envs = await grabComputerEnvs({
|
||||
computer_id: group.computer_id,
|
||||
bot_id: hook.bot_id,
|
||||
@@ -213,7 +213,7 @@ async function runGroup({
|
||||
const version = hookRunnerVersion({
|
||||
script_version: HookRunnerVersion,
|
||||
command: hook.runner_command,
|
||||
dir: cwd,
|
||||
dir: cwds.join("\n"),
|
||||
computer_id: group.computer_id,
|
||||
workspace_id: hook.workspace_id,
|
||||
envs,
|
||||
@@ -227,7 +227,7 @@ async function runGroup({
|
||||
run_as: hook_dirs.run_as,
|
||||
});
|
||||
|
||||
runners.push({ id: Number(hook.id), command: hook.runner_command, cwd, version });
|
||||
runners.push({ id: Number(hook.id), command: hook.runner_command, cwd: cwds[0]!, cwds, version });
|
||||
wanted.add(Number(hook.id));
|
||||
} catch (error) {
|
||||
await recordRunnerFailure({
|
||||
|
||||
@@ -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,9 @@ 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,
|
||||
user_id: proposal.user_id,
|
||||
}),
|
||||
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,11 @@ 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 runner_folder = `relative: the app looks in your ~ (${dirs.cwd}) first, then in your bot folder (${dirs.bot_dir}), and starts in the first one that exists, so a folder you made at ~/whatsapp is just "whatsapp". Empty: ${dirs.bot_dir} itself`;
|
||||
const listed = computers.map((computer) => `${computer.id} (${computer.name || computer.kind})`).join(", ");
|
||||
|
||||
return {
|
||||
@@ -68,7 +77,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 +101,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,6 +5,8 @@ import Row from "@moduletrace/twui/layout/Row";
|
||||
import Span from "@moduletrace/twui/layout/Span";
|
||||
import Stack from "@moduletrace/twui/layout/Stack";
|
||||
import Checkbox from "@moduletrace/twui/form/Checkbox";
|
||||
import Tag from "@moduletrace/twui/elements/Tag";
|
||||
import { twMerge } from "tailwind-merge";
|
||||
|
||||
type Props = {
|
||||
avatar: ReactNode;
|
||||
@@ -21,6 +23,11 @@ type Props = {
|
||||
* A word beside the title, e.g. "Default" or "You".
|
||||
*/
|
||||
badge?: string;
|
||||
/**
|
||||
* `error`: the badge is a fault (a runner that is down), drawn as an
|
||||
* outlined error tag instead of a quiet word.
|
||||
*/
|
||||
badge_tone?: "error";
|
||||
/**
|
||||
* A mark right after the title, e.g. a workspace admin's shield.
|
||||
*/
|
||||
@@ -48,6 +55,7 @@ export default function SettingsListRow({
|
||||
href,
|
||||
onOpen,
|
||||
badge,
|
||||
badge_tone,
|
||||
title_icon,
|
||||
subtitle,
|
||||
selected,
|
||||
@@ -58,7 +66,17 @@ export default function SettingsListRow({
|
||||
<Span className="block text-sm font-bold leading-5 text-ink truncate w-full">
|
||||
{title}
|
||||
{title_icon ? <Span className="ml-1.5 inline-flex align-middle">{title_icon}</Span> : null}
|
||||
{badge ? <Span className="ml-2 text-[11px] font-bold leading-4 text-ink-secondary">{badge}</Span> : null}
|
||||
{badge && badge_tone == "error" ? (
|
||||
<Tag
|
||||
color="error"
|
||||
variant="outlined"
|
||||
className={twMerge("ml-2 inline-flex align-middle", "px-1.5 py-0 text-[11px] font-bold leading-4")}
|
||||
>
|
||||
{badge}
|
||||
</Tag>
|
||||
) : badge ? (
|
||||
<Span className="ml-2 text-[11px] font-bold leading-4 text-ink-secondary">{badge}</Span>
|
||||
) : null}
|
||||
</Span>
|
||||
);
|
||||
|
||||
|
||||
@@ -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,8 @@ 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,
|
||||
user_id: 1,
|
||||
});
|
||||
|
||||
expect(details).toEqual([
|
||||
@@ -15,7 +17,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 +26,8 @@ describe("describeHookProposalDetails", () => {
|
||||
action: "create",
|
||||
data: { title: "Slack", instructions: "Answer.", source: "browser_notifications", watch_computer_id: 2 },
|
||||
computers: new Map([[2, "Desk"]]),
|
||||
bot_id: 4,
|
||||
user_id: 1,
|
||||
});
|
||||
|
||||
expect(details.find((d) => d.label == "Called by")?.value).toBe("Browser notifications on Desk (#2)");
|
||||
@@ -38,6 +42,8 @@ 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,
|
||||
user_id: 1,
|
||||
});
|
||||
|
||||
expect(details.map((d) => d.label)).toEqual(["Hook", "Brief now", "New brief", "Switch on"]);
|
||||
@@ -57,6 +63,8 @@ describe("describeHookProposalDetails", () => {
|
||||
runner_computer_id: 1,
|
||||
},
|
||||
computers: new Map([[1, "Main"]]),
|
||||
bot_id: 4,
|
||||
user_id: 1,
|
||||
});
|
||||
|
||||
expect(details.map((d) => d.label)).toEqual([
|
||||
@@ -74,7 +82,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/users/1/whatsapp, else /home/cb-4/workspace/whatsapp");
|
||||
expect(details.find((d) => d.label == "Runs it on")?.value).toContain("Main (#1)");
|
||||
});
|
||||
|
||||
@@ -84,10 +92,42 @@ 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,
|
||||
user_id: 1,
|
||||
});
|
||||
|
||||
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/users/1/whatsapp, else /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: "bridge" },
|
||||
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,
|
||||
user_id: 1,
|
||||
});
|
||||
|
||||
expect(details.find((d) => d.label == "Starts in now")?.value).toBe("/home/cb-4/workspace/users/1/whatsapp, else /home/cb-4/workspace/whatsapp");
|
||||
expect(details.find((d) => d.label == "Will start in")?.value).toBe("/home/cb-4/workspace/users/1/bridge, else /home/cb-4/workspace/bridge");
|
||||
});
|
||||
|
||||
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,
|
||||
user_id: 1,
|
||||
bot_kind: "coordinator",
|
||||
});
|
||||
|
||||
expect(details.find((d) => d.label == "Will start in")?.value).toBe("/home/gem/workspace/bots/1/users/1/bridge, else /home/gem/workspace/bots/1/bridge");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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,16 @@ 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;
|
||||
/**
|
||||
* Whose hook it is: a runner looks in their folder first.
|
||||
*/
|
||||
user_id: number | string;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -32,8 +43,12 @@ export default function describeHookProposalDetails({
|
||||
current,
|
||||
workspace_name,
|
||||
computers,
|
||||
bot_id,
|
||||
bot_kind,
|
||||
user_id,
|
||||
}: Params): ExtensionProposalDetail[] {
|
||||
const computer = (id?: number | null) => (id ? `${computers.get(Number(id)) || "Computer"} (#${id})` : "");
|
||||
const folder = (dir?: string | null) => hookRunnerStartPath({ bot_id, bot_kind, user_id, runner_dir: dir }) || dir || "";
|
||||
|
||||
if (action == "create") {
|
||||
const watching = data.source == "browser_notifications";
|
||||
@@ -55,14 +70,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 +91,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 +106,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",
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ describe("describeHookRunner", () => {
|
||||
},
|
||||
});
|
||||
|
||||
expect(text).toContain("runner `./run.sh` starts in \"whatsapp\" inside the bot's folder (not your ~) on computer 1");
|
||||
expect(text).toContain("runner `./run.sh` starts in \"whatsapp\" inside your ~ or the bot's folder on computer 1");
|
||||
expect(text).toContain("NOT RUNNING, the check failed (last checked 2026-11-30T08:05:00.000Z)");
|
||||
expect(text).toContain("Its folder isn't there: /home/cb-4/workspace/whatsapp");
|
||||
expect(text).toContain("propose_hook");
|
||||
@@ -46,10 +46,18 @@ describe("describeHookRunner", () => {
|
||||
},
|
||||
}),
|
||||
).toBe(
|
||||
"runner `./run.sh` starts in the bot's folder (not your ~): running since 2026-11-30T08:00:00.000Z, last checked 2026-11-30T08:05:00.000Z",
|
||||
"runner `./run.sh` starts in the bot's folder: running since 2026-11-30T08:00:00.000Z, last checked 2026-11-30T08:05:00.000Z",
|
||||
);
|
||||
});
|
||||
|
||||
test("gives the absolute folder when it knows the bot", () => {
|
||||
const text = describeHookRunner({
|
||||
hook: { ...base, bot_id: 4, user_id: 1, bot_kind: "worker", runner_command: "./run.sh", runner_dir: "whatsapp", runner_last_error: "x" },
|
||||
});
|
||||
|
||||
expect(text).toContain('starts in /home/cb-4/workspace/users/1/whatsapp, else /home/cb-4/workspace/whatsapp (runner_dir "whatsapp": your ~ first, else the bot\'s folder)');
|
||||
});
|
||||
|
||||
test("is part of the hook a bot lists", () => {
|
||||
expect(
|
||||
describeBotHook({ hook: { ...base, runner_command: "./run.sh", runner_last_error: "It isn't running." } }),
|
||||
|
||||
@@ -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 = {
|
||||
@@ -7,8 +8,8 @@ type Params = {
|
||||
|
||||
/**
|
||||
* A hook's runner as a bot reads it, from what the last check stored
|
||||
* (`syncHookRunners`): the command, the folder it starts in (inside the
|
||||
* bot's folder, which is not a run's `~`), whether it is up, and when it
|
||||
* (`syncHookRunners`): the command, the folder it starts in (the owner's
|
||||
* `~` first, else the bot's folder), whether it is up, and when it
|
||||
* isn't, why the check failed. Empty when the hook keeps no runner.
|
||||
*
|
||||
* A failed check says the fix is the runner itself, through a proposal:
|
||||
@@ -20,8 +21,18 @@ export default function describeHookRunner({ hook }: Params) {
|
||||
|
||||
if (!state.configured) return "";
|
||||
|
||||
const folder = hook.bot_id && hook.user_id
|
||||
? hookRunnerStartPath({
|
||||
bot_id: hook.bot_id,
|
||||
bot_kind: hook.bot_kind,
|
||||
user_id: hook.user_id,
|
||||
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 || ""}": your ~ first, else the bot's folder)`
|
||||
: `starts in ${hook.runner_dir ? `"${hook.runner_dir}" inside your ~ or the bot's folder` : "the bot's folder"}`,
|
||||
hook.runner_computer_id ? `on computer ${hook.runner_computer_id}` : "",
|
||||
]
|
||||
.filter(Boolean)
|
||||
|
||||
@@ -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,
|
||||
];
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { describe, expect, test } from "bun:test";
|
||||
import { BotHookRunnerDir } from "@/src/dict/bot-hook-dict";
|
||||
import type { ComputerRunDirs } from "@/src/utils/computer-work-dirs";
|
||||
import hookRunnerDir, { hookRunnerBaseDir, hookRunnerFile } from "./hook-runner-paths";
|
||||
import hookRunnerDir, { hookRunnerBaseDir, hookRunnerDirs, hookRunnerFile } from "./hook-runner-paths";
|
||||
|
||||
const dirs = {
|
||||
bot_dir: "/home/gem/workspace/bots/3",
|
||||
@@ -69,4 +69,32 @@ describe("hookRunnerDir", () => {
|
||||
test("refuses a null byte", () => {
|
||||
expect(() => hookRunnerDir({ dirs, runner_dir: "whats\0app" })).toThrow("null byte");
|
||||
});
|
||||
});
|
||||
});
|
||||
/**
|
||||
* A runner looks in its owner's `~` first (where a bot builds a bridge it
|
||||
* was asked for), then in the bot's folder, so "whatsapp" finds
|
||||
* `~/whatsapp` and a folder given the old way still works.
|
||||
*/
|
||||
describe("hookRunnerDirs", () => {
|
||||
test("a relative folder is tried in the owner's ~, then in the bot's folder", () => {
|
||||
expect(hookRunnerDirs({ dirs, runner_dir: "whatsapp" })).toEqual([
|
||||
"/home/gem/workspace/bots/3/users/1/whatsapp",
|
||||
"/home/gem/workspace/bots/3/whatsapp",
|
||||
]);
|
||||
});
|
||||
|
||||
test("a folder given from the bot's folder still resolves there", () => {
|
||||
expect(hookRunnerDirs({ dirs, runner_dir: "users/1/whatsapp" })).toEqual([
|
||||
"/home/gem/workspace/bots/3/users/1/users/1/whatsapp",
|
||||
"/home/gem/workspace/bots/3/users/1/whatsapp",
|
||||
]);
|
||||
});
|
||||
|
||||
test("empty is the bot's folder alone", () => {
|
||||
expect(hookRunnerDirs({ dirs, runner_dir: "" })).toEqual([dirs.bot_dir]);
|
||||
});
|
||||
|
||||
test("refuses what hookRunnerDir refuses", () => {
|
||||
expect(() => hookRunnerDirs({ dirs, runner_dir: "../x" })).toThrow("has to stay inside the bot's folder");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -44,4 +44,23 @@ export default function hookRunnerDir({ dirs, runner_dir }: { dirs: ComputerRunD
|
||||
}
|
||||
|
||||
return parts.length ? path.posix.join(dirs.bot_dir, ...parts) : dirs.bot_dir;
|
||||
}
|
||||
|
||||
/**
|
||||
* The folders a runner may start in, in the order the keeper tries them
|
||||
* (it starts in the first one there): the hook owner's own folder in the
|
||||
* bot's (`users/<user>`, the run's `~`, where a bot builds what it was
|
||||
* asked for), then the bot's folder. So "whatsapp" finds a bridge a bot
|
||||
* made at `~/whatsapp`, and a folder given from the bot's folder
|
||||
* (`users/1/whatsapp`, as hooks were set before) still works. Empty is
|
||||
* the bot's folder alone. Refused the same way as `hookRunnerDir`.
|
||||
*/
|
||||
export function hookRunnerDirs({ dirs, runner_dir }: { dirs: ComputerRunDirs; runner_dir?: string | null }) {
|
||||
const in_bot = hookRunnerDir({ dirs, runner_dir });
|
||||
|
||||
if (in_bot == dirs.bot_dir || dirs.cwd == dirs.bot_dir) return [in_bot];
|
||||
|
||||
const in_home = path.posix.join(dirs.cwd, path.posix.relative(dirs.bot_dir, in_bot));
|
||||
|
||||
return [in_home, in_bot];
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
import computerRunDirs from "./computer-work-dirs";
|
||||
import { hookRunnerDirs } 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;
|
||||
/**
|
||||
* The hook's owner: the runner looks in their folder (`users/<user>`)
|
||||
* first.
|
||||
*/
|
||||
user_id: number | string;
|
||||
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 (`hookRunnerDirs`): the
|
||||
* owner's folder (the run's `~`) first, else the bot's folder, written as
|
||||
* "A, else B" so a card or a bot reading only "whatsapp" knows where it
|
||||
* looks. 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, user_id, runner_dir }: Params) {
|
||||
try {
|
||||
const dirs = computerRunDirs({ bot_id, bot_kind, user_id });
|
||||
|
||||
return hookRunnerDirs({ dirs, runner_dir }).join(", else ");
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user