Skip to content

armgit / qm

Public Imported from GitHub
0

Multiplayer agent harness for work.

Fix chat formatting guidance and delivery surface labels

Regan Belld1bcb80884c4
diff --git a/docs/screenshots/delivery-surface-after.png b/docs/screenshots/delivery-surface-after.png
new file mode 100644
index 000000000..dd71df7e0
Binary files /dev/null and b/docs/screenshots/delivery-surface-after.png differ
diff --git a/docs/screenshots/delivery-surface-before.png b/docs/screenshots/delivery-surface-before.png
new file mode 100644
index 000000000..dc0c815b6
Binary files /dev/null and b/docs/screenshots/delivery-surface-before.png differ
diff --git a/plugins/admin/public/index.html b/plugins/admin/public/index.html
index a72c7dc15..0294be09e 100644
--- a/plugins/admin/public/index.html
+++ b/plugins/admin/public/index.html
@@ -14577,7 +14577,7 @@
drow.className = "who";
const dlabel = document.createElement("span");
dlabel.className = "entry-label important";
- dlabel.textContent = delivery.shadow ? "Shadow delivery" : "Slack delivery";
+ dlabel.textContent = deliveryLabel(delivery);
drow.appendChild(dlabel);
if (delivery.shadow) {
const sb = document.createElement("span");
@@ -14586,7 +14586,7 @@
sb.textContent = "not sent";
drow.appendChild(sb);
}
- drow.appendChild(badge(delivery.destination?.type === "principal" ? "Slack DM" : "Slack", "info"));
+ drow.appendChild(badge(deliverySurfaceLabel(delivery), "info"));
const mirror = slackMirrorRef(delivery);
if (mirror) {
const ml = navLink("View in Slack mirror ↗", { view: "slack", container: mirror.container, ts: mirror.ts });
@@ -16136,6 +16136,19 @@
}
}
+ function deliverySurfaceLabel(event) {
+ const type = event?.destination?.type;
+ if (type === "principal") return "Slack DM";
+ if (type === "slack") return "Slack";
+ if (type === "web") return "Web";
+ return type || "Unknown surface";
+ }
+
+ function deliveryLabel(event) {
+ if (event.shadow) return "Shadow delivery";
+ return `${deliverySurfaceLabel(event)} delivery`;
+ }
+
function slackMirrorRef(event) {
const d = event?.destination || {};
if (d.type !== "slack" || !d.editRef || typeof d.target !== "string" || !d.target) return null;
@@ -17027,19 +17040,16 @@
const who = document.createElement("div");
who.className = "who";
const outbound = event.type === "outbound_delivery";
- const slackDelivery = outbound || event.type === "principal_delivery";
+ const isDelivery = outbound || event.type === "principal_delivery";
const label = document.createElement("span");
label.className = "entry-label important";
- let deliveryLabel = "Delivery event";
- if (event.shadow) deliveryLabel = "Shadow delivery";
- else if (slackDelivery) deliveryLabel = "Slack delivery";
- label.textContent = deliveryLabel;
+ label.textContent = event.shadow || isDelivery ? deliveryLabel(event) : "Delivery event";
const when = document.createElement("span");
when.className = "when";
let deliveryState = "delivery";
if (event.shadow) deliveryState = "shadow";
else if (event.expiredAt) deliveryState = "dropped";
- else if (slackDelivery) deliveryState = "delivered";
+ else if (isDelivery) deliveryState = "delivered";
when.textContent = `${deliveryState} · ${fmtTime(event.createdAt)}`;
const text = event.text || "";
who.append(label);
@@ -17056,8 +17066,7 @@
xb.textContent = "never sent";
who.append(xb);
}
- if (slackDelivery)
- who.appendChild(badge(event.destination?.type === "principal" ? "Slack DM" : "Slack", "info"));
+ if (isDelivery) who.appendChild(badge(deliverySurfaceLabel(event), "info"));
const provenanceLink = originNodeForDeliveryEvent(event);
if (!outbound && provenanceLink) who.appendChild(provenanceLink);
const originLink = cronLinkForDeliveryEvent(event);
diff --git a/plugins/admin/test/delivery-labels.test.ts b/plugins/admin/test/delivery-labels.test.ts
new file mode 100644
index 000000000..87819224e
--- /dev/null
+++ b/plugins/admin/test/delivery-labels.test.ts
@@ -0,0 +1,37 @@
+import assert from "node:assert/strict";
+import { readFileSync } from "node:fs";
+import test from "node:test";
+
+const html = readFileSync(new URL("../public/index.html", import.meta.url), "utf8");
+const source = ["deliverySurfaceLabel", "deliveryLabel"]
+ .map((name) => {
+ const match = html.match(new RegExp(`function ${name}\\([^)]*\\) \\{[\\s\\S]*?\\n {6}\\}`));
+ assert.ok(match, `${name} exists`);
+ return match[0];
+ })
+ .join("\n");
+const labels = new Function(`${source}; return { deliverySurfaceLabel, deliveryLabel };`)();
+
+for (const [type, surface] of [
+ ["web", "Web"],
+ ["slack", "Slack"],
+ ["principal", "Slack DM"],
+ ["telegram", "telegram"],
+ [undefined, "Unknown surface"],
+]) {
+ test(`delivery labels describe ${type ?? "missing"} destinations independently of origin`, () => {
+ const event = { destination: { type }, provenance: { surface: "slack" } };
+ assert.equal(labels.deliverySurfaceLabel(event), surface);
+ assert.equal(labels.deliveryLabel(event), `${surface} delivery`);
+ assert.equal(labels.deliveryLabel({ ...event, shadow: true }), "Shadow delivery");
+ assert.equal(labels.deliverySurfaceLabel({ ...event, shadow: true }), surface);
+ });
+}
+
+test("tool-associated and standalone deliveries use the same surface labels", () => {
+ assert.match(html, /dlabel.textContent = deliveryLabel\(delivery\)/);
+ assert.match(html, /badge\(deliverySurfaceLabel\(delivery\), "info"\)/);
+ assert.match(html, /label.textContent = event.shadow \|\| isDelivery \? deliveryLabel\(event\)/);
+ assert.match(html, /badge\(deliverySurfaceLabel\(event\), "info"\)/);
+ assert.doesNotMatch(html, /"Slack delivery"|const slackDelivery/);
+});
diff --git a/src/core/orchestrator.ts b/src/core/orchestrator.ts
index 2da468296..328304dec 100644
--- a/src/core/orchestrator.ts
+++ b/src/core/orchestrator.ts
@@ -978,7 +978,6 @@ export function createOrchestrator(deps: OrchestratorDeps): Orchestrator {
userEmail: actor.id.includes("@") ? actor.id : undefined,
surfaceLabel: isWeb ? `the ${botName} web app` : "Slack",
slack: isSlack,
- web: isWeb,
};
}
let modeFrame = applyPromptVars(frameMd, frameVars);
diff --git a/src/harness/agent-tools.ts b/src/harness/agent-tools.ts
index 5fb10ed10..7fad31911 100644
--- a/src/harness/agent-tools.ts
+++ b/src/harness/agent-tools.ts
@@ -2693,7 +2693,10 @@ export function createAgentTools(ref: ToolContextRef, opts?: AgentToolsOptions):
text: Type.Optional(
Type.String({
description:
- "post/reach: the message to send (the surface renders it). To @-mention, use real Slack syntax — `<@U…>` for a person, `<!subteam^S…>` for a user group (both ids appear in People here / read / search results). A typed `@name` is plain text and pings no one; @here/@channel/@everyone never ping. edit: the new message content.",
+ "post/reach: the message to send. edit: the new message content. Use Markdown, including [label](url) links; the surface renders it." +
+ (surfaceName === "slack"
+ ? " To @-mention on Slack, use `<@U…>` for a person or `<!subteam^S…>` for a user group (ids appear in People here / read / search results). A typed `@name` is plain text and pings no one; @here/@channel/@everyone never ping."
+ : ""),
}),
),
channel: Type.Optional(
diff --git a/src/resolution/protocols/mode-conversation.md b/src/resolution/protocols/mode-conversation.md
index 0eaf4c6a3..35c4ff706 100644
--- a/src/resolution/protocols/mode-conversation.md
+++ b/src/resolution/protocols/mode-conversation.md
@@ -7,6 +7,5 @@ Work like a capable coworker, not a system:
- Your last message must stand alone. Everything they need — answers, links, codes, file names — goes in it, restated if it first appeared mid-turn. Never point at tool output as if they can see it.
- Describe work in human terms ("here's the report"), never machinery — no tool names, scopes, spools, or raw error strings.
{{#if slack}}- This is Slack: keep each reply to a couple of sentences unless they ask for more.{{/if}}
-{{#if web}}- Replies render as markdown.{{/if}}
Your reply reaches only this conversation. To message anyone else — a teammate's DM, a channel — send exact words now via `POST $AGENT_API_URL/v1/reach` with `{"text":"…","recipient":"<name>"}` (or `"channel":"<name>"`), or schedule it with the `cron` tool. Core resolves names; the response confirms who it matched.
diff --git a/src/resolution/protocols/shared-core.md b/src/resolution/protocols/shared-core.md
index 4f529c25f..41325d982 100644
--- a/src/resolution/protocols/shared-core.md
+++ b/src/resolution/protocols/shared-core.md
@@ -1,6 +1,8 @@
# {{botName}}
-You are {{botName}}{{#if botHandle}} (@{{botHandle}} in Slack){{/if}} — the shared assistant platform for {{orgName}}. One core serves the whole org, but each conversation is isolated: you see and act only on what the people in this conversation are entitled to. Everything you do is audited.
+You are {{botName}}{{#if botHandle}} (@{{botHandle}} in Slack){{/if}} — the shared assistant platform for {{orgName}}. Each conversation is isolated: you see and act only on what the people in this conversation are entitled to. Everything you do is audited.
+
+Chat uses Markdown: `[label](url)`, never `<url|label>`.
## Runtime
`runtime` discovers/changes models/harnesses and resumes; lifetime `scope` changes defaults.
diff --git a/test/agent-tools.test.ts b/test/agent-tools.test.ts
index c535d6135..1017a49eb 100644
--- a/test/agent-tools.test.ts
+++ b/test/agent-tools.test.ts
@@ -3196,3 +3196,14 @@ test("a queued runtime change cannot mutate after cancellation while draining to
assert.equal(selected, false);
assert.equal(ref.runtimeHandoff, undefined);
});
+
+test("surface messages use Markdown and only Slack tools teach Slack mentions", () => {
+ const ref: ToolContextRef = { current: fakeToolContext(), scopeLabel: "channel:C1" };
+ for (const name of ["web", "slack", "telegram"]) {
+ const tool = surfaceTool(ref, name);
+ const text = (tool.parameters as { properties: { text: { description: string } } }).properties.text.description;
+ assert.match(text, /Use Markdown, including \[label\]\(url\) links/);
+ if (name === "slack") assert.match(text, /<@U…>/);
+ else assert.doesNotMatch(text, /Slack|<@U…>|<!subteam/);
+ }
+});
diff --git a/test/prompt-modes.test.ts b/test/prompt-modes.test.ts
index 267314d77..22f576c99 100644
--- a/test/prompt-modes.test.ts
+++ b/test/prompt-modes.test.ts
@@ -421,3 +421,22 @@ test("Mode 2 (spine channel): static prose stays within the word-count ceiling (
"This is expected to fail until the menu deletions in CONTRACT.md S5 land.",
);
});
+
+for (const surface of ["web", "slack"]) {
+ for (const mode of ["conversation", "autonomous", "fallback"]) {
+ test(`${surface} ${mode} turns share the Markdown chat contract`, async () => {
+ const prompt = await sysprompt(buildOrchestrator(), {
+ surface,
+ actor,
+ conversation: mode === "conversation" ? dmConversation : channelConversation,
+ surfaceTools: mode === "autonomous",
+ text: "",
+ origin: mode === "fallback" ? { kind: "automation" } : { kind: "direct" },
+ });
+ assert.match(prompt, /Chat uses Markdown/);
+ assert.match(prompt, /\[label\]\(url\)/);
+ assert.equal(countOccurrences(prompt, "Chat uses Markdown"), 1);
+ assertNoTemplateTokens(prompt, `${surface} ${mode}`);
+ });
+ }
+}