Multi-Agent Collaboration for Team and Friends
TypeScript agent-automationagent-orchestrationagent-workflowai-agentsai-collaborationai-memoryai-workforceautonomous-agentsclaude-codeclaude-code-skillscodexcoding-agentmulti-agentmultiple-agentone-person-businessone-person-companyone-person-teamopencodesolopreneur
feat: store markdown instead of HTML for agent link instructions and calendar descriptions
Gus7fde50a8828e
diff --git a/src/cli/daemon/execenv/context.test.ts b/src/cli/daemon/execenv/context.test.tsindex 75ea03d87..956bcd82f 100644--- a/src/cli/daemon/execenv/context.test.ts+++ b/src/cli/daemon/execenv/context.test.ts@@ -1,5 +1,5 @@import { describe, it, expect } from "vitest";-import { buildInstructionContent } from "./context.js";+import { buildInstructionContent, resolveInstruction } from "./context.js";import { tempDir } from "../../lib/platform.js";import type { Task } from "../types.js";@@ -137,7 +137,7 @@ describe("buildInstructionContent email tool injection", () => {name: "test",instructions: "",colleagues: [- { name: "Scout", email: "[email protected]", description: "A researcher agent", instruction: "Share findings via email" },+ { name: "Scout", email: "[email protected]", description: "A researcher agent", instruction: 'Share findings with [@ id="agent-123" label="test"]' },{ name: "Writer", email: "[email protected]", description: "", instruction: "Draft blog posts" },],},@@ -147,9 +147,9 @@ describe("buildInstructionContent email tool injection", () => {expect(content).toContain("## Your Colleagues");expect(content).toContain("### Scout ([email protected])");expect(content).toContain("A researcher agent");- expect(content).toContain("**Relationship:** Share findings via email");+ expect(content).toContain("**When to involve:** Share findings with YOU");expect(content).toContain("### Writer ([email protected])");- expect(content).toContain("**Relationship:** Draft blog posts");+ expect(content).toContain("**When to involve:** Draft blog posts");});it("omits colleagues section when no colleagues", () => {@@ -183,9 +183,39 @@ describe("buildInstructionContent email tool injection", () => {const content = buildInstructionContent(task);expect(content).toContain("### Scout ([email protected])");- expect(content).toContain("**Relationship:** Share data");+ expect(content).toContain("**When to involve:** Share data");// Only the header + relationship, no blank description lineconst scoutSection = content.split("### Scout")[1].split("##")[0];expect(scoutSection).not.toMatch(/\n\n\n/);});});++describe("resolveInstruction", () => {+ it("converts self-mentions to YOU", () => {+ const md = 'when [@ id="ag_abc" label="gus"] is asked to implement';+ expect(resolveInstruction(md, "ag_abc")).toBe("when YOU is asked to implement");+ });++ it("preserves other agent mentions as @name", () => {+ const md = 'share with [@ id="ag_other" label="planner"]';+ expect(resolveInstruction(md, "ag_abc")).toBe("share with @planner");+ });++ it("handles both self and other mentions in the same instruction", () => {+ const md = '[@ id="ag_abc" label="gus"] should report to [@ id="ag_other" label="planner"]';+ expect(resolveInstruction(md, "ag_abc")).toBe("YOU should report to @planner");+ });++ it("returns empty string for empty input", () => {+ expect(resolveInstruction("", "ag_abc")).toBe("");+ });++ it("passes through plain text unchanged", () => {+ expect(resolveInstruction("just plain text", "ag_abc")).toBe("just plain text");+ });++ it("handles legacy HTML mentions as fallback", () => {+ const html = '<p>when <span class="mention-highlight" data-type="mention" data-id="ag_abc" data-label="gus">@gus</span> asks YOU to help</p>';+ expect(resolveInstruction(html, "ag_abc")).toBe("when YOU asks YOU to help");+ });+});diff --git a/src/cli/daemon/execenv/context.ts b/src/cli/daemon/execenv/context.tsindex 6e4a47e12..833042f3a 100644--- a/src/cli/daemon/execenv/context.ts+++ b/src/cli/daemon/execenv/context.ts@@ -68,6 +68,23 @@ those json are sorted by datetime in asc order.- When access other local projects, make sure you read the CLAUDE.md/AGENTS.md file under the project root dir to understand the requirements.`;+export function resolveInstruction(text: string, selfAgentId: string): string {+ let result = text;+ result = result.replace(+ /\[@ id="([^"]*)" label="([^"]*)"\]/g,+ (_, id, label) => (id === selfAgentId ? "YOU" : `@${label}`),+ );+ // Fallback: handle legacy HTML mentions (pre-markdown-switch data)+ result = result.replace(+ /<span[^>]*data-id="([^"]*)"[^>]*data-label="([^"]*)"[^>]*>[^<]*<\/span>/gi,+ (_, id, label) => (id === selfAgentId ? "YOU" : `@${label ?? "unknown"}`),+ );+ result = result.replace(/<\/p>\s*<p[^>]*>/gi, "\n");+ result = result.replace(/<[^>]+>/g, "");+ result = result.replace(/\n{3,}/g, "\n\n").trim();+ return result;+}+export function buildInstructionContent(task: Task): string {const displayName = task.agent?.name || "Alook Agent";const alookAddr = task.agent?.emailHandle ? toAlookAddress(task.agent.emailHandle) : null;@@ -101,7 +118,7 @@ Below are your direct colleagues. You can reach them via email.const c = task.agent.colleagues[i];content += `### ${c.name}${c.email ? ` (${c.email})` : ""}\n`;if (c.description) content += `${c.description}\n`;- if (c.instruction) content += `**Relationship:** ${c.instruction}\n`;+ if (c.instruction) content += `**When to involve:** ${resolveInstruction(c.instruction, task.agentId)}\n`;if (i < task.agent.colleagues.length - 1) content += "\n";}}diff --git a/src/web/src/app/api/calendar/[id]/route.ts b/src/web/src/app/api/calendar/[id]/route.tsindex 7f2463c65..daa7627d2 100644--- a/src/web/src/app/api/calendar/[id]/route.ts+++ b/src/web/src/app/api/calendar/[id]/route.ts@@ -3,7 +3,6 @@ import {queries,UpdateCalendarEventRequestSchema,DeleteCalendarEventRequestSchema,- isEmptyHtml,computeNextScheduledAt,} from "@alook/shared";import { getDb } from "@/lib/db";@@ -74,7 +73,7 @@ export const PATCH = withAuth(async (req, ctx) => {if (body.title !== undefined) patch.title = body.title;if (body.description !== undefined) {patch.description =- body.description && !isEmptyHtml(body.description) ? body.description : null;+ body.description?.trim() || null;}if (body.agent_id !== undefined) patch.agentId = body.agent_id;if (body.scheduled_at !== undefined) {diff --git a/src/web/src/app/api/calendar/route.ts b/src/web/src/app/api/calendar/route.tsindex 991ac5d58..9ea80ca47 100644--- a/src/web/src/app/api/calendar/route.ts+++ b/src/web/src/app/api/calendar/route.ts@@ -4,7 +4,6 @@ import {queries,CreateCalendarEventRequestSchema,expandOccurrences,- isEmptyHtml,} from "@alook/shared";import { getDb } from "@/lib/db";import { withAuth } from "@/lib/middleware/auth";@@ -124,10 +123,7 @@ export const POST = withAuth(async (req: NextRequest, ctx) => {}}- const description =- body.description && !isEmptyHtml(body.description)- ? body.description- : null;+ const description = body.description?.trim() || null;const created = await queries.calendarEvent.createCalendarEvent(db, {agentId: body.agent_id,diff --git a/src/web/src/components/calendar/calendar-event-sheet.tsx b/src/web/src/components/calendar/calendar-event-sheet.tsxindex 7f4fdea17..4df44114e 100644--- a/src/web/src/components/calendar/calendar-event-sheet.tsx+++ b/src/web/src/components/calendar/calendar-event-sheet.tsx@@ -18,7 +18,7 @@ import {DialogTitle,} from "@/components/ui/dialog";import { Button } from "@/components/ui/button";-import { MarkdownEditor, isEmptyHtml } from "@/components/ui/markdown-editor";+import { MarkdownEditor } from "@/components/ui/markdown-editor";import {CalendarDays,CalendarOff,@@ -105,9 +105,8 @@ function parseTime(d: Date): string {return `${pad(d.getHours())}:${pad(d.getMinutes())}`;}-function normalizedDescription(html: string | null | undefined): string {- if (!html) return "";- return isEmptyHtml(html) ? "" : html;+function normalizedDescription(value: string | null | undefined): string {+ return value?.trim() || "";}const GHOST_CONTROL =@@ -359,11 +358,11 @@ export function CalendarEventSheet({const err = validate();if (err) return toast.error(err);const scheduled = combineDateTime(dateValue, timeValue);- const descHtml = isEmptyHtml(description) ? undefined : description;+ const desc = description?.trim() || undefined;await onCreate?.({agent_id: agentId,title: title.trim(),- description: descHtml,+ description: desc,scheduled_at: scheduled.toISOString(),repeat_interval: repeat || undefined,repeat_stop_date: stopDate ? toYYYYMMDD(stopDate) : undefined,@@ -687,6 +686,7 @@ export function CalendarEventSheet({<div ref={descriptionRef}><MarkdownEditorkey={event?.id ?? "new"}+ contentType="markdown"value={description}onChange={setDescription}placeholder="Add a description…"diff --git a/src/web/src/components/canvas/link-sidecar.tsx b/src/web/src/components/canvas/link-sidecar.tsxindex 7db7368dd..684350c79 100644--- a/src/web/src/components/canvas/link-sidecar.tsx+++ b/src/web/src/components/canvas/link-sidecar.tsx@@ -112,6 +112,7 @@ export function LinkSidecar({<div className="flex-1 overflow-y-auto thin-scrollbar px-5 py-4"><MarkdownEditorvariant="seamless"+ contentType="markdown"placeholder="Describe how these agents should collaborate. This instruction is shared with both agents when they receive tasks."value={instruction}onChange={setInstruction}