Compare commits

...
3 Commits
Author SHA1 Message Date
tben 3209828723 Bump version to 0.19.1
CI / check (push) Canceled after 0s
Release image / image (release) Canceled after 0s
Release image / computer-image (release) Canceled after 0s
2026-11-13 12:56:37 +01:00
tben 0d38268fef Let a hand-over only move a task, and ask before work starts
Handing a task to another bot started it by default: it went to doing and
queued a run, so handing three tasks over "to wait for the go-ahead" ran
three jobs that each only reported they were waiting.

handOverTask now only moves the task, as to do, with no job; `start: true`
(the user asked for the work to begin now) is what sets it doing and queues
the run. hand_over_task and delegate_task pass that only when the user asked
and are told to ask first with one ask_user card for every task they named,
since a worker can't start a task once it has left its list. The UI's hand
over form gains a "Start it now" toggle, unchecked by default, and the
coordinator and workspace-admin prompts say the same.
2026-11-13 12:52:01 +01:00
tben 41be1b6fb1 Make a release mean the whole chain, watched to the end
CI / check (push) Canceled after 0s
2026-11-13 12:15:40 +01:00
15 changed files with 204 additions and 46 deletions
+3 -2
View File
@@ -36,7 +36,7 @@ For the current UI read `src/layouts/bots/` (rail, workspace rail, user popover)
| DB schema sync / admin UI / backup | `bun run db:schema` / `db:admin` / `db:backup` |
| Seed super admin / sample crew | `bun run seed` (needs `SEED_SUPER_ADMIN_PASSWORD`) / `bun run seed:bots [email]` (idempotent) |
| Query DB (read-only, JSON envelope) | `bun llm-code-assistant/query-db.ts "<sql>"` |
| Publish a release | `bun run publish:github` / `publish:gitea`; `bun run mirror:gitea` afterwards |
| Publish a release | `bun run publish:github` / `publish:gitea`; `bun run mirror:gitea` afterwards (`gh run watch` in between until the image build ends) |
No linter or formatter. `bun run typecheck` and `bun run test` are the verification steps. Use `query-db.ts` to see what is actually in the database instead of reading ORM code.
@@ -165,7 +165,7 @@ A secret URL, `POST /api/hooks/<token>` (`src/pages/api/hooks/[token].ts`, publi
### Tasks (the to-do tracker)
`tasks` (**a task belongs to a bot by default**, the coordinator included: a bot's own list is `bot_id` alone, a workspace's task has `workspace_id` plus the `bot_id` that has it there; the one exception is a **workspace-wide** task (`workspace_id`, `bot_id` null), only when asked for (`workspace_wide`, enforced by `taskScopeValues`), which every bot working there sees and works on; a worker reaches its own plus the workspace-wide ones in its workspaces, a workspace admin all of that workspace's, the coordinator all, `botTaskScopesSql`; on a workspace-wide task `update_task` logs each call's status move and filed files as a note under the bot (`task_notes.bot_id`), and `list_tasks` with `task_id` reads the whole log with who and when; the coordinator and a workspace's admin bot (`update_task` `workspace_wide`) or a crew manager (Make workspace-wide, `api/admin/tasks/make-workspace-wide`) turn a bot's open workspace task workspace-wide (`makeTaskWorkspaceWide`, noted in its log; never a bot's own list), and hand-over gives one back to a single bot; a bot removed from a workspace or deleted passes its own tasks there to the workspace's admin bot, else the coordinator (`passOnBotTasks`), workspace-wide ones stay), `task_notes`, `task_media` (deliverable|reference). Not the same as `bot_tasks`/`bots_queue` (those record jobs). Visibility SQL in `src/utils/task-access/`. Helpers in `src/functions/backend/db/tasks/`; tools `list_tasks`/`create_task`/`update_task` (which also renames a task and rewrites its brief, refusing an open twin's title, and unlinks bot files with `unlink_file_ids`: a task holds `AppData.TaskMediaMaxPerTask` files; `list_tasks` with `task_id` lists them) and, in chat replies the user follows only (never routines, hook calls or rooms), `delete_task`; API `api/admin/tasks/` (`userAuth` -> `isReadOnlyUser` -> `assertUserReachesTask` -> `safeErrorMessage`). UI in the workspace dashboard and the header's Tasks modal (shared components in `src/components/general/`); a card's title opens `TaskDetailModal` with everything about the task and its status moves (a modal over the list, never swapped in place). **Hand-over:** `handOverTask` (bot: `delegate_task` with `task_id` when it directs work, else `hand_over_task` for a task of its own; UI: Hand over, crew managers) moves an open task to the new bot (a workspace's stays in the workspace, now the new bot's, and is worked there), sets it doing and queues a job with `params.tracker_task_id` (with `start: false` it only moves it, as to do, no job: for "take it and wait for the go-ahead"); `noteTrackerTask` notes the job's end on it, blocks it on failure, and blocks it too when the run used every step it had without finishing (`trackerTaskEnding`, so a run measured to its last step no longer leaves the task silently open). **Not built yet:** task steps, `server:task-changed` pushes, a `/admin/tasks` page.
`tasks` (**a task belongs to a bot by default**, the coordinator included: a bot's own list is `bot_id` alone, a workspace's task has `workspace_id` plus the `bot_id` that has it there; the one exception is a **workspace-wide** task (`workspace_id`, `bot_id` null), only when asked for (`workspace_wide`, enforced by `taskScopeValues`), which every bot working there sees and works on; a worker reaches its own plus the workspace-wide ones in its workspaces, a workspace admin all of that workspace's, the coordinator all, `botTaskScopesSql`; on a workspace-wide task `update_task` logs each call's status move and filed files as a note under the bot (`task_notes.bot_id`), and `list_tasks` with `task_id` reads the whole log with who and when; the coordinator and a workspace's admin bot (`update_task` `workspace_wide`) or a crew manager (Make workspace-wide, `api/admin/tasks/make-workspace-wide`) turn a bot's open workspace task workspace-wide (`makeTaskWorkspaceWide`, noted in its log; never a bot's own list), and hand-over gives one back to a single bot; a bot removed from a workspace or deleted passes its own tasks there to the workspace's admin bot, else the coordinator (`passOnBotTasks`), workspace-wide ones stay), `task_notes`, `task_media` (deliverable|reference). Not the same as `bot_tasks`/`bots_queue` (those record jobs). Visibility SQL in `src/utils/task-access/`. Helpers in `src/functions/backend/db/tasks/`; tools `list_tasks`/`create_task`/`update_task` (which also renames a task and rewrites its brief, refusing an open twin's title, and unlinks bot files with `unlink_file_ids`: a task holds `AppData.TaskMediaMaxPerTask` files; `list_tasks` with `task_id` lists them) and, in chat replies the user follows only (never routines, hook calls or rooms), `delete_task`; API `api/admin/tasks/` (`userAuth` -> `isReadOnlyUser` -> `assertUserReachesTask` -> `safeErrorMessage`). UI in the workspace dashboard and the header's Tasks modal (shared components in `src/components/general/`); a card's title opens `TaskDetailModal` with everything about the task and its status moves (a modal over the list, never swapped in place). **Hand-over:** `handOverTask` (bot: `delegate_task` with `task_id` when it directs work, else `hand_over_task` for a task of its own; UI: Hand over, crew managers) moves an open task to the new bot (a workspace's stays in the workspace, now the new bot's, and is worked there) as to do, with no job: a hand-over never starts the work. Only `start: true` (the UI's "Start it now" toggle, or a bot passing it after the user said so) sets it doing and queues a job with `params.tracker_task_id`; when the user asked for the move but not for the work to start, bots ask first with one `ask_user` card for every task they named, since a worker can't start a task once it has left its list; `noteTrackerTask` notes the job's end on it, blocks it on failure, and blocks it too when the run used every step it had without finishing (`trackerTaskEnding`, so a run measured to its last step no longer leaves the task silently open). **Not built yet:** task steps, `server:task-changed` pushes, a `/admin/tasks` page.
### Envs
@@ -241,6 +241,7 @@ Read-only browser of every volume (`src/utils/storage-volumes.ts`: bots, workspa
- **App networks:** extra docker networks for the app's own container (never computers) are the app setting `app_extra_networks` (Settings > General, super admin, picked from the networks docker lists, `listJoinableNetworks`), joined by the app itself over the docker socket (`syncAppNetworks`) at boot, on save and every 5 minutes, so they outlast `install.sh` recreating the container; the installer's `--extra-network` still works beside it.
- Plain HTTP only; TLS is the proxy's job. Container: `--network cobble`, `.env` read-only at `/app/.env`, docker socket, `MAIN_SERVER=1`, `--init`, `--cpus 1 --memory 2048m` by default.
- Publishing: `scripts/publish-github.sh` / `publish-gitea.sh` sharing `scripts/lib/publish-*.sh` (tested by `scripts/publish-tools.test.ts`). A GitHub release triggers `.github/workflows/release.yml` (amd64 + arm64 to `ghcr.io/moduletrace/cobble`); `mirror-gitea.sh` copies to `git.tben.me/moduletrace/cobble` (CI can't reach the VPN). **Bump `package.json`'s `version` with a release.** CI (`ci.yml`) runs typecheck and tests. Dockerfile pins Bun 1.4.3.
- **A release is done when every artifact exists, not when the tag is pushed.** Publishing (`publish`/`release`/`ship`, any of them) means the whole chain, run by you and watched to the end: `publish:github`, `publish:gitea`, then `gh run watch` until the image build succeeds, then `mirror:gitea` (it has nothing to copy until that build finishes). Report each artifact with its link, and say plainly (with the reason) if one fails or is still building: never hand back a tag and leave the rest as a note for the user.
## Admin routes
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "cobble",
"version": "0.19.0",
"version": "0.19.1",
"module": "index.ts",
"type": "module",
"private": true,
+26 -2
View File
@@ -1,4 +1,5 @@
import { useEffect, useState } from "react";
import Checkbox from "@moduletrace/twui/form/Checkbox";
import Form from "@moduletrace/twui/form/Form";
import Select from "@moduletrace/twui/form/Select";
import Textarea from "@moduletrace/twui/form/Textarea";
@@ -24,6 +25,12 @@ type Props<T> = {
* Offer a note added to the brief (a task's hand-over).
*/
with_note?: boolean;
/**
* Offer to start the work now (a task's hand-over). Off by default:
* handing a task over only moves it, it never starts the work unless
* the user asks for that here.
*/
with_start?: boolean;
onHandedOver: (params: { saved: T; msg: string }) => void;
onCancel: () => void;
};
@@ -39,12 +46,14 @@ export default function HandOverForm<T extends { [k: string]: any }>({
submit_path,
body,
with_note,
with_start,
onHandedOver,
onCancel,
}: Props<T>) {
const [targets, setTargets] = useState<HandOverTarget[]>();
const [bot_id, setBotId] = useState<number>();
const [note, setNote] = useState("");
const [start, setStart] = useState(false);
const [loading, setLoading] = useState(false);
const [error, setError] = useState<string>();
@@ -73,14 +82,19 @@ export default function HandOverForm<T extends { [k: string]: any }>({
return;
}
if (!window.confirm(`Hand ${what} over to ${target.name}?`)) return;
if (!window.confirm(`Hand ${what} over to ${target.name}${with_start && start ? " and start it now" : ""}?`)) return;
setLoading(true);
setError(undefined);
const res = await postAdminApi<T>({
path: submit_path,
body: { ...body, bot_id: target.id, instructions: with_note && note.trim() ? note : undefined },
body: {
...body,
bot_id: target.id,
instructions: with_note && note.trim() ? note : undefined,
...(with_start ? { start } : {}),
},
});
setLoading(false);
@@ -121,6 +135,16 @@ export default function HandOverForm<T extends { [k: string]: any }>({
disabled={loading}
/>
) : null}
{with_start && targets?.length ? (
<Checkbox
title="Start it now"
label="Start it now"
info="Left off, the task only moves: it lands on their list as to do, and nothing runs until they're told to start."
checked={start}
clickDispatchHandler={setStart}
wrap
/>
) : null}
<AddFormActions submit_label="Hand over" loading={loading} error={error} onCancel={onCancel} />
</Stack>
</Form>
@@ -131,6 +131,7 @@ export default function TaskDetailPanel({ task, can_manage, onChanged, onDeleted
submit_path="tasks/hand-over-task"
body={{ task_id: Number(task.id) }}
with_note
with_start
onCancel={() => setHandingOver(false)}
onHandedOver={({ saved, msg }) => {
setHandingOver(false);
+1 -1
View File
@@ -34,7 +34,7 @@ Permission to draft is not permission to send, permission to analyze is not perm
- Delegating into a workspace the worker isn't in adds it to that workspace as a side effect. Say that in your reply when it happens; don't add members silently for a one-off.
- Give a full brief: objective, inputs, deliverable, acceptance criteria, constraints.
- Check \`list_tasks\` first. Never give two bots the same job, and don't restart work an open task already covers.
- When the work is already a task on a list, hand that task over: \`delegate_task\` with its \`task_id\`. It moves to the worker (a workspace's task stays on that workspace's list and is worked there), goes to doing, and the worker moves that same task along. Never copy it into a new one.
- When the work is already a task on a list, hand that task over: \`delegate_task\` with its \`task_id\`. It moves to the worker (a workspace's task stays on that workspace's list and is worked there) and the worker moves that same task along. Never copy it into a new one. A hand-over lands on their list as to do and starts nothing: pass \`start: true\` only when the user asked for the work to begin now, and when they asked for the move but not whether to start it, ask first (one \`ask_user\` card with every task they named) and hand over once they've answered.
- A routine of yours that belongs with a worker goes to them with \`hand_over_schedule\`, not by deleting it and asking for a new one. A routine in a workspace keeps running there.
- Track what comes back, judge it against the request, and integrate it. Don't pass a worker's unchecked claim on as fact.
- If the user talks to a worker directly, read the shared state before repeating or reassigning its work.
+2
View File
@@ -113,6 +113,7 @@ describe("RequestScopeNote", () => {
expect(note).toContain("a standing preference is not a standing instruction");
expect(note).toContain("the same ask_user card");
expect(note).toContain("delegating a task");
expect(note).toContain("ask before it leaves: one ask_user card with every task they named");
expect(note).toContain("don't offer it again in this conversation");
expect(note).not.toContain("the brief is what you may do");
expect(note).not.toContain("\u2014");
@@ -123,6 +124,7 @@ describe("RequestScopeNote", () => {
expect(note).toContain("the brief is what you may do");
expect(note).toContain("Say in your report what you would propose");
expect(note).toContain("move it as to do and say in your report that it waits for the user to start it");
expect(note).not.toContain("ask_user");
expect(note).not.toContain("\u2014");
});
+11 -4
View File
@@ -229,6 +229,11 @@ The user's request sets the scope. Do what they asked, in the scope they gave, a
: `the brief is what you may do. Say in your report what you would propose, and why.`
}
- When you can't tell whether something was asked for, it wasn't: ask. Once the user has chosen, do exactly that, nothing bundled with it.
- Handing a task over moves it; starting the work is a separate thing the user asks for. When they asked for the move but not for it to start, ${
can_ask
? `ask before it leaves: one ask_user card with every task they named.`
: `move it as to do and say in your report that it waits for the user to start it.`
}
- If the user declines, or doesn't pick it, drop it: don't do it anyway, don't do a smaller version of it, and don't offer it again in this conversation.`;
/**
@@ -258,7 +263,7 @@ When a concept, comparison, process, timeline or set of numbers is easier to see
* `bot_id` is the coordinator itself, so the ref example it copies is its
* own rather than a worker's.
*/
export const coordinatorReplyNote = ({ bot_id }: { bot_id: number | string }) => `As the coordinator, hand work that fits a crew member's role to them with delegate_task. Work that is already a task on a list goes over as that task (delegate_task with its task_id), never as a copy; a routine of yours that belongs with a worker goes with hand_over_schedule. They post the result in their own conversation, and it's reported back here when they finish or fail, so tell the user who is on it and where: a task with no workspace_id runs in that bot's own chat, on its own memory, files and directly assigned computers; one with workspace_id runs in the workspace, on the workspace's context, files and computers as well as the bot's, and lands in that project's conversation. Never swap one for the other without saying so. When a report comes back, pass on what matters to the user, follow up on anything left, and propose what comes next with ask_user: the next piece of work, which bot would take it, or the question that settles the direction, as options for the user to pick. Once the user agrees, you can also grow the crew with create_bot, put a worker in a workspace with add_bot_to_workspace, and create or change a workspace with create_workspace and update_workspace. When you name a crew member, write its ref instead of its name, e.g. ${botRef({ id: bot_id })} for yourself: the user sees it as the bot's name, linked to its conversation.`;
export const coordinatorReplyNote = ({ bot_id }: { bot_id: number | string }) => `As the coordinator, hand work that fits a crew member's role to them with delegate_task. Work that is already a task on a list goes over as that task (delegate_task with its task_id), never as a copy; a routine of yours that belongs with a worker goes with hand_over_schedule. A task handed over lands there as to do and nothing runs: pass start: true only when the user asked for the work to begin now, and when they haven't said, ask before it moves (one ask_user card with every task they named). They post the result in their own conversation, and it's reported back here when they finish or fail, so tell the user who is on it and where: a task with no workspace_id runs in that bot's own chat, on its own memory, files and directly assigned computers; one with workspace_id runs in the workspace, on the workspace's context, files and computers as well as the bot's, and lands in that project's conversation. Never swap one for the other without saying so. When a report comes back, pass on what matters to the user, follow up on anything left, and propose what comes next with ask_user: the next piece of work, which bot would take it, or the question that settles the direction, as options for the user to pick. Once the user agrees, you can also grow the crew with create_bot, put a worker in a workspace with add_bot_to_workspace, and create or change a workspace with create_workspace and update_workspace. When you name a crew member, write its ref instead of its name, e.g. ${botRef({ id: bot_id })} for yourself: the user sees it as the bot's name, linked to its conversation.`;
/**
* Added to the coordinator's chat prompt instead while it has no workers,
@@ -279,7 +284,7 @@ export const workspaceAdminNote = ({
members: { id?: number | "" }[];
}) => `# Leading ${workspace_name}
You are this workspace's admin: you lead the bots working here (${members.map((m) => botRef({ id: m.id || 0 })).join(", ")}). Hand work that fits a member's role to them with delegate_task rather than doing all of it yourself (a task already on a list goes over with its task_id, and one of your routines here with hand_over_schedule); they post the result in their conversation here, and it's reported back to you when they finish or fail, so tell the user who is on it. When a report comes back, pass on what matters, follow up on anything left and propose what comes next. Set how a member should work here with set_bot_workspace_instructions, keep the workspace's task list honest (create_task with a member's bot_id gives them a task here), and keep the workspace's shared context current with update_workspace when you have it. When you name a member, write its ref, so the user sees its name linked to its conversation.`;
You are this workspace's admin: you lead the bots working here (${members.map((m) => botRef({ id: m.id || 0 })).join(", ")}). Hand work that fits a member's role to them with delegate_task rather than doing all of it yourself (a task already on a list goes over with its task_id, and one of your routines here with hand_over_schedule; a hand-over lands as to do and starts nothing, so pass start: true only when the user asked for the work to begin now, and ask first when they haven't said); they post the result in their conversation here, and it's reported back to you when they finish or fail, so tell the user who is on it. When a report comes back, pass on what matters, follow up on anything left and propose what comes next. Set how a member should work here with set_bot_workspace_instructions, keep the workspace's task list honest (create_task with a member's bot_id gives them a task here), and keep the workspace's shared context current with update_workspace when you have it. When you name a member, write its ref, so the user sees its name linked to its conversation.`;
/**
* Added to a workspace member's prompt while the workspace has an admin,
@@ -426,10 +431,12 @@ You have tasks of your own to keep up with. When the message is an opening ("hel
*/
export const HandOverTaskNote = `# Passing a task on
A task on your own list can go to another bot with hand_over_task: it moves to their list, they work that same task, and their result comes back to this conversation. Do it only when the user asked for that task to go to that bot; the list is theirs and the work costs them a run.
A task on your own list can go to another bot with hand_over_task: it moves to their list, and their result comes back to this conversation. Do it only when the user asked for that task to go to that bot; the list is theirs.
- A hand-over moves the task as to do; it never starts the work. Pass start: true only when the user asked for the work to begin now.
- When they asked for the move but not whether to start it, ask first: put one ask_user card with every task they named ("hand over and start", "hand over to wait", "leave it") and hand over only once they've answered. Once a task has left your list you can't start it any more.
- The task_id comes from list_tasks, and it has to be your own open task. You can't create work for another bot, and you can't move a workspace-wide task.
- Say where it went with the run id the tool returned. Never say a task was handed over, or that someone picked work up, without it.
- Say where it went the way the tool returned it: the run id when it started, or that it's on their list as to do. Never say a task was handed over, or that someone picked work up, without it.
- Handing over is not asking: when you only need an answer from another bot, use ask_crew.`;
/**
@@ -47,10 +47,12 @@ type Params = {
requested_by_bot_id?: number | string | null;
requested_by_session_id?: number | string | null;
/**
* False to only move it: the task goes to the new bot's list as to do
* and no job is queued, for when the user hasn't asked for the work to
* begin. Handing three tasks over "to wait for the go-ahead" once ran
* three jobs that each only reported they were waiting.
* True only when the user asked for the work to begin now: the task
* goes to doing and a job is queued. Left out (the default) it only
* moves: the task goes to the new bot's list as to do and no job is
* queued, since handing a task over is not asking for it to be worked.
* Handing three tasks over "to wait for the go-ahead" once ran three
* jobs that each only reported they were waiting.
*/
start?: boolean;
};
@@ -70,13 +72,15 @@ export type HandedOverTask = {
};
/**
* Hands an open task to another bot and starts the work: a task in a
* workspace stays there and becomes the new bot's there (the work runs in
* that workspace), one on a bot's own list moves to the new bot's. The task goes to doing, its log
* says who handed it over, and a job is queued in the new bot's
* conversation with the task's brief and `params.tracker_task_id`, so the
* bot moves this same task along and the job's end is noted on it. With
* `start` false it only moves: to do, no job, the notice says so.
* Hands an open task to another bot: a task in a workspace stays there and
* becomes the new bot's there (the work runs in that workspace), one on a
* bot's own list moves to the new bot's. Handing it over is not asking for
* it to be worked, so by default it only moves: the task goes to the new
* bot's list as to do, no job is queued and the notice says so. With
* `start` true (the user asked for the work to begin now) the task goes to
* doing, its log says who handed it over, and a job is queued in the new
* bot's conversation with the task's brief and `params.tracker_task_id`, so
* the bot moves this same task along and the job's end is noted on it.
*/
export default async function handOverTask({
user_id,
@@ -87,7 +91,7 @@ export default async function handOverTask({
handed_by,
requested_by_bot_id,
requested_by_session_id,
start = true,
start = false,
}: Params): Promise<HandedOverTask> {
const task = await grabTaskRow({ task_id });
@@ -0,0 +1,87 @@
import { afterAll, beforeEach, describe, expect, mock, test } from "bun:test";
import type { BUN_SQLITE_COBBLE_BOTS, BUN_SQLITE_COBBLE_TASKS } from "@/db/types/db";
/**
* The task being handed over, and what `handOverTask` answered with it:
* what a hand-over passes on is the whole point of these tests, so the
* helper is mocked and its arguments recorded.
*/
let task = {
id: 27,
title: "Rewrite the pricing page",
bot_id: 4,
workspace_id: 3,
status: "todo",
} as BUN_SQLITE_COBBLE_TASKS;
let handedArgs: Record<string, unknown> | null = null;
let handed: Record<string, unknown> = {};
mock.module("@/src/functions/backend/db/tasks/grab-run-task", () => ({
default: async () => task,
}));
mock.module("@/src/functions/backend/db/tasks/hand-over-task", () => ({
default: async (args: Record<string, unknown>) => {
handedArgs = args;
return handed;
},
}));
const delegateTaskTool = (await import("./delegate-task-tool")).default;
afterAll(() => {
mock.restore();
});
const worker = { id: 5, name: "Researcher", role: "research", kind: "worker" } as BUN_SQLITE_COBBLE_BOTS;
const signal = new AbortController().signal;
function tool() {
return delegateTaskTool({
user_id: 1,
requester_id: 1,
session_id: 10,
requester_name: "Coordinator",
workers: [worker],
workspaces: [],
grabTargets: async () => [worker],
});
}
beforeEach(() => {
task = {
id: 27,
title: "Rewrite the pricing page",
bot_id: 4,
workspace_id: 3,
status: "todo",
} as BUN_SQLITE_COBBLE_TASKS;
handedArgs = null;
handed = { task, job_id: null, bot_name: "Researcher", workspace_id: 3, joined: "" };
});
describe("delegateTaskTool, handing over a task on a list", () => {
test("moves it as to do by default: no run is queued", async () => {
const answer = await tool().run({ args: { bot_id: 5, task_id: 27 }, signal });
expect(handedArgs?.start).toBe(false);
expect(handedArgs?.task_id).toBe(27);
expect(String(answer)).toContain("as to do");
expect(String(answer)).toContain("Nothing is running");
});
test("starts it only with start: true, when the user asked for that", async () => {
handed = { task, job_id: 318, bot_name: "Researcher", workspace_id: 3, joined: "" };
const answer = await tool().run({ args: { bot_id: 5, task_id: 27, start: true }, signal });
expect(handedArgs?.start).toBe(true);
expect(String(answer)).toContain("is with Researcher now (job #318)");
expect(String(answer)).toContain("marked doing");
});
test("says a hand-over starts nothing, and to ask before it moves", () => {
expect(tool().description).toContain("Handing a task over never starts it");
expect(tool().description).toContain("ask first with ask_user");
});
});
@@ -96,11 +96,11 @@ describe("delegateTaskTool", () => {
expect(tool.description).toContain("task_id");
});
test("can hand a task over without starting it", () => {
test("hands a task over as to do unless told to start it", () => {
const tool = coordinatorTool();
expect(tool.schema?.safeParse({ bot_id: 5, task_id: 27, start: false }).success).toBe(true);
expect(tool.description).toContain("start: false");
expect(tool.schema?.safeParse({ bot_id: 5, task_id: 27, start: true }).success).toBe(true);
expect(tool.description).toContain("start: true");
});
test("without a task_id, still needs a title and instructions", async () => {
+5 -4
View File
@@ -69,7 +69,8 @@ type Args = {
*/
task_id?: number;
/**
* With `task_id`: false to only move the task, nothing started.
* The user asked for that task's work to begin now (with `task_id`):
* left out it only moves, to do, and no run is spent.
*/
start?: boolean;
title?: string;
@@ -114,7 +115,7 @@ export default function delegateTaskTool({
return {
name: "delegate_task",
description: `Hand a task to a crew member. They run it in the background and post the result in their own conversation; it's also reported back here when they finish or fail. Write the instructions as a full brief: what to do, where, and how they'll know it's done. To hand over a task already on a list (list_tasks), pass its task_id instead of writing a new one: it moves to the crew member's list (a workspace's task stays on the workspace's list and runs there), goes to doing, and they work that same task; title and instructions are then optional, the task's brief is used and yours is added to it. When the user hasn't asked for that task's work to begin yet (they want it moved, or to decide first), add start: false: it only moves to their list as to do, and no run is spent on reporting that they're waiting. Crew: ${crew}.${
description: `Hand a task to a crew member. They run it in the background and post the result in their own conversation; it's also reported back here when they finish or fail. Write the instructions as a full brief: what to do, where, and how they'll know it's done. To hand over a task already on a list (list_tasks), pass its task_id instead of writing a new one: it moves to the crew member's list (a workspace's task stays on the workspace's list and runs there) and they work that same task; title and instructions are then optional, the task's brief is used and yours is added to it. Handing a task over never starts it: it lands there as to do, and only start: true (when the user asked for the work to begin now) marks it doing and queues the run. When the user asked for the move but not for it to start, ask first with ask_user (one card, every task they named: hand over and start, hand over to wait, leave it) and hand over only once they've answered. A new brief with no task_id always runs at once. Crew: ${crew}.${
workspace_id
? ` You are working in a workspace, so the task runs there: in this workspace's context.`
: ` Leave workspace_id out to run it in the crew member's own chat: only its own memory, files and directly assigned computers apply there, and the user finds the result by talking to it on its own. Add workspace_id to run it in one of the user's workspaces instead: the workspace's shared context, the member's instructions and memory there, its files and its computers (the workspace's own and the member's) all apply, and the result lands in its conversation in that workspace, beside the project it belongs to. Pick a workspace when the work belongs to that project; the member is added to it when it isn't in it yet. Workspaces: ${places || "none"}.`
@@ -125,7 +126,7 @@ export default function delegateTaskTool({
start: z
.boolean()
.optional()
.describe("With task_id: false to only move the task (to do, nothing runs) until the user says to start"),
.describe("With task_id: true to start the work at once, only when the user asked for it; left out it only moves (to do, nothing runs)"),
title: z.string().min(1).max(80).optional(),
instructions: z.string().min(1).max(8000).optional(),
workspace_id: z
@@ -198,7 +199,7 @@ export default function delegateTaskTool({
handed_by: requester_name,
requested_by_bot_id: requester_id,
requested_by_session_id: session_id,
start: args.start !== false,
start: args.start === true,
});
onTask?.({ task_id: Number(task.id) });
@@ -75,6 +75,7 @@ describe("handOverTaskTool", () => {
expect(tool.name).toBe("hand_over_task");
expect(tool.schema?.safeParse({ task_id: 43, bot_id: 6 }).success).toBe(true);
expect(tool.schema?.safeParse({ task_id: 43, bot_id: 6, start: false }).success).toBe(true);
expect(tool.schema?.safeParse({ task_id: 43, bot_id: 6, start: true }).success).toBe(true);
expect(tool.schema?.safeParse({ bot_id: 6 }).success).toBe(false);
});
@@ -84,8 +85,15 @@ describe("handOverTaskTool", () => {
expect(tool.description).toContain("6: Software Engineer; 3: Graphic Designer");
});
test("tells the bot to ask before the task leaves its list, and that a hand-over starts nothing", () => {
const tool = build();
expect(tool.description).toContain("Handing it over never starts it");
expect(tool.description).toContain("ask first with ask_user");
});
test("hands the task over with the bot and session to report back to", async () => {
const answer = await build().run({ args: { task_id: 43, bot_id: 6 }, signal: new AbortController().signal });
const answer = await build().run({ args: { task_id: 43, bot_id: 6, start: true }, signal: new AbortController().signal });
expect(handedArgs?.task_id).toBe(43);
expect(handedArgs?.to_bot_id).toBe(6);
@@ -107,7 +115,17 @@ describe("handOverTaskTool", () => {
expect(String(answer)).toContain("It joined the workspace.");
});
test("start: false only moves it, and says nothing is running", async () => {
test("moves it as to do unless the user asked to start it", async () => {
handed = { task, job_id: null, bot_name: "Software Engineer", workspace_id: 2, joined: "" };
const answer = await build().run({ args: { task_id: 43, bot_id: 6 }, signal: new AbortController().signal });
expect(handedArgs?.start).toBe(false);
expect(String(answer)).toContain("as to do");
expect(String(answer)).toContain("Nothing is running");
});
test("an explicit start: false asks for the same move", async () => {
handed = { task, job_id: null, bot_name: "Software Engineer", workspace_id: 2, joined: "" };
const answer = await build().run({ args: { task_id: 43, bot_id: 6, start: false }, signal: new AbortController().signal });
+10 -8
View File
@@ -42,9 +42,9 @@ type Args = {
task_id: number;
bot_id: number;
/**
* False to only move it: the task goes to the other bot's list as to do
* and no job is queued, for when the user hasn't asked for the work to
* begin.
* True only when the user asked for the work to begin now. Left out the
* task only moves: it goes to the other bot's list as to do and no job
* is queued.
*/
start?: boolean;
};
@@ -55,7 +55,9 @@ type Args = {
* to hand out work. It only ever moves a task the run already has, only an
* open one, and only to a bot it could ask for the same user, so it can't
* create a task for someone else or widen a run's reach. The task keeps its
* place (a workspace's stays there), the other bot works that same task, and
* place (a workspace's stays there) and moves as to do: it never starts the
* work unless the user asked for that (`start`), and when they only asked
* for the move the bot asks first. The other bot works that same task, and
* the result is reported back in this session.
*/
export default function handOverTaskTool({ user_id, bot, session_id, powers, workers, grabTargets, onTask }: Params): HarnessTool<Args> {
@@ -64,14 +66,14 @@ export default function handOverTaskTool({ user_id, bot, session_id, powers, wor
return {
name: "hand_over_task",
description: `Hand over a task on your own list to another bot, when the user asked for that task to go to them. Pass its task_id (list_tasks) and the bot: the task moves to their list and they work that same task there, and their result is reported back here. Only a task of your own, and only an open one. To ask a bot something without giving it a task, use ask_crew; to have work made for another bot, ask the user. Crew you can hand to: ${crew || "none"}.`,
description: `Hand over a task on your own list to another bot, when the user asked for that task to go to them. Pass its task_id (list_tasks) and the bot: the task moves to their list as to do, and their result is reported back here. Handing it over never starts it: pass start: true only when the user asked for the work to begin now. When they asked for the move but not for it to start, ask first with ask_user (one card, every task they named: hand over and start, hand over to wait, leave it), and hand over only once they've answered: a task that has left your list can't be started by you any more. Only a task of your own, and only an open one. To ask a bot something without giving it a task, use ask_crew; to have work made for another bot, ask the user. Crew you can hand to: ${crew || "none"}.`,
schema: z.object({
task_id: z.number().int().describe("An open task on your own list (list_tasks)"),
bot_id: z.number().int(),
start: z
.boolean()
.optional()
.describe("false to only move the task (to do, nothing runs) until the user says to start"),
.describe("true to start the work at once, only when the user asked for it; left out it only moves (to do, nothing runs)"),
}),
run: async ({ args }) => {
const task = await grabRunTask({
@@ -111,7 +113,7 @@ export default function handOverTaskTool({ user_id, bot, session_id, powers, wor
handed_by: bot.name || "The bot that had it",
requested_by_bot_id: bot_id,
requested_by_session_id: session_id,
start: args.start !== false,
start: args.start === true,
});
onTask?.({ task_id: Number(task.id) });
@@ -119,7 +121,7 @@ export default function handOverTaskTool({ user_id, bot, session_id, powers, wor
const where = handed.workspace_id ? ` in workspace ${handed.workspace_id}` : " in its own chat";
if (!handed.job_id) {
return `Task #${task.id} "${task.title}" is on ${handed.bot_name}'s list now${where}, as to do. Nothing is running: they start when the user tells them to.`;
return `Task #${task.id} "${task.title}" is on ${handed.bot_name}'s list now${where}, as to do. Nothing is running: they start when the user tells them to.${handed.joined ? ` ${handed.joined}` : ""}`;
}
return `Task #${task.id} "${task.title}" is with ${handed.bot_name} now (job #${handed.job_id})${where}, marked doing, and it's off your list.${handed.joined} They work that same task; their result is reported back here.`;
+13 -7
View File
@@ -13,10 +13,11 @@ import safeErrorMessage from "@/src/utils/safe-error-message";
import type { APIResponseObject, BunextAPIRouteHandler } from "@moduletrace/bunext/types";
/**
* Hands an open task to another bot and starts the work (`handOverTask`):
* the bot works that same task, and its result lands in its conversation.
* Crew managers only, like every other change to a task by hand. Returns
* the task as it is now.
* Hands an open task to another bot (`handOverTask`): the bot has that same
* task on its list, and its result lands in its conversation. It only moves
* the task by default, as to do; it starts the work only when the user
* ticked that in the form (`start`). Crew managers only, like every other
* change to a task by hand. Returns the task as it is now.
*/
export const handler: BunextAPIRouteHandler<APIResponseObject<TaskDetail>> = async ({ req, body }) => {
try {
@@ -38,7 +39,7 @@ export const handler: BunextAPIRouteHandler<APIResponseObject<TaskDetail>> = asy
throw new AppError(`Only an admin can hand a task over.`);
}
const { task_id, bot_id, instructions } = parseWithSchema({ schema: HandOverTaskRequestSchema, data: body });
const { task_id, bot_id, instructions, start } = parseWithSchema({ schema: HandOverTaskRequestSchema, data: body });
await assertUserReachesTask({ user_id: user.id, task_id });
@@ -48,14 +49,19 @@ export const handler: BunextAPIRouteHandler<APIResponseObject<TaskDetail>> = asy
to_bot_id: bot_id,
instructions,
handed_by: user.first_name || user.username || "The user",
start: start === true,
});
wakeBotsQueue();
if (handed.job_id) {
wakeBotsQueue();
}
return {
success: true,
singleRes: await grabTask({ user_id: user.id, task_id }),
msg: `${handed.bot_name} has it now and is starting on it.`,
msg: handed.job_id
? `${handed.bot_name} has it now and is starting on it.`
: `${handed.bot_name} has it now, as to do on their list.`,
};
} catch (error: unknown) {
return { success: false, msg: safeErrorMessage({ error }) };
+5
View File
@@ -81,6 +81,11 @@ export const HandOverTaskRequestSchema = z.object({
task_id: z.number().int().positive(),
bot_id: z.number().int().positive("Pick a bot"),
instructions: z.string().max(AppData.TaskDescriptionMaxLength).optional(),
/**
* True to start the work now (the user ticked "Start it now"): left out
* the task only moves, as to do.
*/
start: z.boolean().optional(),
});
export const TaskIdRequestSchema = z.object({