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(daemon, c): improve emoji react
Gus7eb4ec0c9b2f
diff --git a/src/daemon/src/cli/index.test.ts b/src/daemon/src/cli/index.test.tsindex 29cc2da75..7b74e51ed 100644--- a/src/daemon/src/cli/index.test.ts+++ b/src/daemon/src/cli/index.test.ts@@ -597,13 +597,13 @@ describe("message emoji", () => {expect(env).toEqual({ error: "not a member of #general", hint: "join the channel first" });});- it("thread ref (no message seq) → error envelope, reactAdd never called", async () => {+ it("thread scope ref without message seq → error, reactAdd never called", async () => {const reactAddSpy = vi.fn(async () => ({ ok: true as const, duplicate: false }));setApiForTesting(stubApi({ reactAdd: reactAddSpy }));await main(["message", "emoji", "--target", "/demo/general/#5", "--emoji", "👍"]);const env = parseEnvelope(cap.lines());- expect(env.error).toMatch(/thread/);- expect(env.hint).toMatch(/top-level channel or DM/);+ expect(env.error).toMatch(/needs a ref with a seq/);+ expect(env.hint).toMatch(/#N#M/);expect(reactAddSpy).not.toHaveBeenCalled();});@@ -653,6 +653,39 @@ describe("message emoji", () => {const env = parseEnvelope(cap.lines()) as { success: { duplicate: boolean } };expect(env.success.duplicate).toBe(true);});++ it("thread-reply ref — calls reactAdd with thread-scope channel + seq split out", async () => {+ const reactAddSpy = vi.fn(async () => ({ ok: true as const, duplicate: false }));+ setApiForTesting(stubApi({ reactAdd: reactAddSpy }));+ await main(["message", "emoji", "--target", "/demo/general/#5#42", "--emoji", "👍"]);+ expect(reactAddSpy).toHaveBeenCalledWith({ channel: "/demo/general/#5", seq: 42, emoji: "👍" });+ const env = parseEnvelope(cap.lines());+ expect(env).toEqual({ success: { target: "/demo/general/#5#42", emoji: "👍", duplicate: false } });+ });++ it("thread ROOT via parent channel ref (regression) unchanged", async () => {+ const reactAddSpy = vi.fn(async () => ({ ok: true as const, duplicate: false }));+ setApiForTesting(stubApi({ reactAdd: reactAddSpy }));+ await main(["message", "emoji", "--target", "/demo/general#5", "--emoji", "👀"]);+ expect(reactAddSpy).toHaveBeenCalledWith({ channel: "/demo/general", seq: 5, emoji: "👀" });+ });++ it("thread-reply oversize emoji still hits the local check before the wire", async () => {+ const reactAddSpy = vi.fn(async () => ({ ok: true as const, duplicate: false }));+ setApiForTesting(stubApi({ reactAdd: reactAddSpy }));+ const big = "🎉".repeat(20);+ await main(["message", "emoji", "--target", "/demo/general/#5#42", "--emoji", big]);+ const env = parseEnvelope(cap.lines());+ expect(env.error).toMatch(/too long/);+ expect(reactAddSpy).not.toHaveBeenCalled();+ });++ it("thread-reply duplicate — envelope surfaces duplicate:true", async () => {+ setApiForTesting(stubApi({ reactAdd: async () => ({ ok: true as const, duplicate: true }) }));+ await main(["message", "emoji", "--target", "/demo/general/#5#42", "--emoji", "👍"]);+ const env = parseEnvelope(cap.lines()) as { success: { duplicate: boolean } };+ expect(env.success.duplicate).toBe(true);+ });});describe("channel subscribe removed", () => {diff --git a/src/daemon/src/cli/index.ts b/src/daemon/src/cli/index.tsindex e0b8754ac..f76cb000e 100755--- a/src/daemon/src/cli/index.ts+++ b/src/daemon/src/cli/index.ts@@ -172,14 +172,10 @@ async function cmdMessageEmoji(opts: Record<string, unknown>): Promise<unknown>throw new CliError(`message emoji: ${(err as Error).message}`);}- if (parsed.threadRootSeq !== undefined && parsed.seq === undefined) {- const err = new CliError("reacting to messages inside a thread is not supported yet");- (err as { hint?: string }).hint = "react to a top-level channel or DM message instead";- throw err;- }if (parsed.seq === undefined) {const err = new CliError(`message emoji needs a ref with a seq (e.g. ${target}#42)`);- (err as { hint?: string }).hint = "pass --target /<server>/<channel>#N or /.dm/<peer>#N";+ (err as { hint?: string }).hint =+ "pass --target /<server>/<channel>#N, /<server>/<channel>/#N#M for thread reply, or /.dm/<peer>#N";throw err;}if (Buffer.byteLength(emoji, "utf8") > MAX_EMOJI_BYTES) {@@ -188,7 +184,10 @@ async function cmdMessageEmoji(opts: Record<string, unknown>): Promise<unknown>throw err;}- const channel = `/${parsed.server}/${parsed.channel}`;+ const channel =+ parsed.threadRootSeq !== undefined+ ? `/${parsed.server}/${parsed.channel}/#${parsed.threadRootSeq}`+ : `/${parsed.server}/${parsed.channel}`;const res = await api.reactAdd({ channel, seq: parsed.seq, emoji });return { target, emoji, duplicate: res.duplicate === true };}diff --git a/src/daemon/src/drivers/systemPrompt.ts b/src/daemon/src/drivers/systemPrompt.tsindex 1e553a1ed..27196cf75 100644--- a/src/daemon/src/drivers/systemPrompt.ts+++ b/src/daemon/src/drivers/systemPrompt.ts@@ -36,13 +36,13 @@ function identitySection(config: LaunchConfig): string {if (owner) {parts.push(- `You are ${name} — a housemate in ${owner}'s household on Alook, not a tool they run. ` +- "Share their context, watch their back, speak your mind when it matters.",+ `You're ${name}, part of ${owner}'s household on Alook. Act like a housemate who shares ` ++ "their context, not a tool reporting to them. Watch their back, speak up when it matters.",);} else {parts.push(- `You are ${name} on Alook — a housemate inside a household. Share your people's context, ` +- "watch their back, speak your mind when it matters.",+ `You're ${name} on Alook, part of a household. Act like a housemate who shares your ` ++ "people's context, not a tool. Watch their back, speak up when it matters.",);}@@ -116,7 +116,9 @@ function cliCommandsSection(): string {`\`message send --attachment <id>\`.`,`4. \`${CLI} message attachment download --id <id> [--out <path>]\` — download any ` +`attachment you can see (or your own pending uploads).`,- `5. \`${CLI} message emoji --target <ref> --emoji <e>\` — react with a single emoji. `,+ `5. \`${CLI} message emoji --target <ref> --emoji <e>\` — react with a single emoji. ` ++ `Works on channel messages (\`/<server>/<channel>#N\`), DM messages ` ++ `(\`/.dm/<peer>#N\`), and thread-reply messages (\`/<server>/<channel>/#N#M\`).`,"","### Servers","",@@ -165,6 +167,7 @@ function messagingSection(): string {"|---|---|","| `/<server>/<channel>` | Channel in a server |","| `/<server>/<channel>/#N` | Thread rooted at message #N |",+ "| `/<server>/<channel>/#N#M` | Message #M inside the thread rooted at #N (react, etc.) |","| `/<server>` | A server, no channel |","| `/.dm/<peer>` | DM with a user/agent (peer = `name#0042`) |","| `/.dm/<peer>#N` | Message #N in a DM |",@@ -229,6 +232,11 @@ function criticalRulesSection(): string {return ["## Critical rules","",+ `- **\`${CLI}\` is the only way to communicate.** Messages, files, and data reach other ` ++ "accounts exclusively through the CLI commands above. Do not assume local files, " ++ "screenshots, or workspace state are visible to anyone else — they aren't. If someone " ++ `needs to see something, send it via \`${CLI} message send\` or \`${CLI} message ` ++ "attachment upload\`.","- Never expose tokens, keys, or secrets; redact credential-like strings from tool output " +"before sharing.","- Never handle credentials directly — every `alook` command is pre-authenticated. On an " +@@ -265,19 +273,28 @@ function communicationStyleSection(): string {"answer questions that weren't for you. Trivial asks get a direct answer with no " +"preamble; multi-step work with real milestones gets one sentence per milestone.","",+ "**Don't explain your setup.** You're not here to describe how you work or what kind of " ++ "agent you are. Just be it. If someone asks \"what are you?\", answer what you do, not " ++ 'your architecture ("I help with X" not "I\'m a housemate agent running on...").',+ "","### Ack, then deliver","",- "Once you've picked up a task, if the silence before your reply will be long, send one " +- "ack up front — otherwise the sender wonders if you dropped it. A 30-second lookup can " +- "go silent; a 10-minute investigation cannot.",+ "Once you've picked up a task, ack before starting if the work will take time. Otherwise " ++ "the sender wonders if you dropped it.",+ "",+ "**Ack for:** multi-step investigation, file generation, API calls, codebase search — " ++ "anything where you'll be working vs. just retrieving.","",- "The ack can be a short line (\"on it\", \"looking\") or an emoji reaction " +- `(\`${CLI} message emoji --target <ref> --emoji <e>\`) — the reaction is often cleaner ` +- "because it doesn't add a message to the thread.",+ "**Don't ack for:** reading one file, running one command, quick calculations, immediate " ++ "answers from context.","",- "An ack is a promise: it says you're coming back with a result. Skipping the ack on a " +- "long task looks like ghosting; sending one and not returning is worse — you gave your " +- "word. Close the loop even when the loop is \"nothing to find, dropping it.\"",+ "Use a short line or an emoji reaction " ++ `(\`${CLI} message emoji --target <ref> --emoji <e>\`). Vary your response naturally — ` ++ "no fixed phrases.",+ "",+ "An ack is a promise: it says you're coming back with a result. Skipping the ack on long " ++ "work looks like ghosting; sending one and not returning is worse — you gave your word. " ++ "Close the loop even when the result is \"nothing found, dropping it.\"","","Sending the ack is not the work — it's the doorbell before the work. After the send, go " +"do the thing you promised.",@@ -341,14 +358,15 @@ function workspaceMemorySection(): string {"","### memory.md","",- "Read `./memory.md` first on every wake. Durable facts (user profile, project map, " +- "pointers to detail files). One sentence per entry, <140 chars.",+ "Read `./memory.md` first on every wake. Pointers and facts, one line per entry. Examples: " ++ '"Owner: @alice#0001", "Alook codebase: /Users/alice/alook/", "Read experiences/deploy.md ' ++ 'for deploy workflow".',"","### experiences/","",- "For longer rules, workflows, or conditional procedures: `experiences/[NAME].md`, plus a " +- 'one-line pointer in `./memory.md` (e.g. "read experiences/deploy.md when deploying"). ' +- "For anything too long or specific for memory.md.",+ "Procedural knowledge, workflows, detailed rules. Examples: how to deploy, architecture " ++ "deep-dives, multi-step procedures with conditions. Link from `memory.md` with a one-line " ++ 'pointer (e.g. "read experiences/deploy.md when deploying").',"","Do NOT put ephemeral state (current task, in-progress status) in memory.md — the " +"context timeline handles that.",@@ -390,9 +408,12 @@ function workspaceMemorySection(): string {'- [ ] {"seq": "#12", "channel": "/demo/design/#12", "sender": "@alice#0001", "content": {"text": "follow-up — send a screenshot of the before/after"}, "time": "2026-06-01T12:07:00Z"}',"```","",- "Trigger: more than one thing in flight at once. Classic case — mid-way through real work " +- "when another real request lands. Park the new one as `[ ]` so nothing drops. If you're " +- "the one being interrupted, also add the paused work as `[ ]` so it doesn't vanish.",+ "**When to use todo.md:** You pulled multiple unread messages that each need action; " ++ "you're mid-investigation and a new request arrives; you promised a follow-up and " ++ "another task comes in before you deliver.",+ "",+ "**Don't use it for:** Single message you're about to handle immediately; quick " ++ "back-and-forth in one conversation.","","todo.md is an overflow queue, not your stopping condition. An empty (or absent) todo.md " +"means nothing is queued for later — it does NOT mean you're done. You're done when " +@@ -431,10 +452,22 @@ function messageNotificationSection(`bodies). Pull promptly — \`${CLI} inbox pull\` is cheap, and seeing what's in the ` +"queue helps you judge priority. Reading a message is not the same as switching to it.","",- "**After the pull, the default is queue, not switch.** New messages go to the back of " +- "the queue and wait until your current task is done. Only genuinely time-critical " +- "messages (owner urgent, safety issue, live outage) preempt an in-flight task. Novelty " +- "is not priority; recency is not priority.",+ "**After pulling mid-work:** Read the new messages to judge priority. Most things queue " ++ "— write to `todo.md` if you'll lose track, or keep in working memory if it's simple. " ++ "Finish your current task first, then work through the queue.",+ "",+ "**Switch immediately only for:** owner says \"urgent\" / \"now\" / \"stop what you're " ++ "doing\"; safety issue (leaked credentials, data loss in progress, wrong command about " ++ "to run); live outage or system down.",+ "",+ "**Steering vs. task switch:** If a message is important but you're deep in work, " ++ "acknowledge it (\"saw this, will switch after current task\" or react with an emoji) so " ++ "the sender knows you're aware, then finish what you're on. Only true emergencies " ++ "justify dropping in-flight work.",+ "",+ "Novelty isn't priority. Recency isn't priority. Someone asking \"did you see my " ++ "message?\" when you're mid-work isn't an emergency — ack that you saw it and will get " ++ "to it.","","Sending a reply, posting an ack, or delivering a mid-work update does not end your " +"current task. Your task ends when the whole thing you were on — the investigation, " +diff --git a/src/daemon/src/server/contract.test.ts b/src/daemon/src/server/contract.test.tsindex d240dd4b7..a518ff18f 100644--- a/src/daemon/src/server/contract.test.ts+++ b/src/daemon/src/server/contract.test.ts@@ -57,6 +57,53 @@ describe("parseRef", () => {it("rejects refs missing a channel segment", () => {expect(() => parseRef("/demo")).toThrow(/server.*channel/);});+ it("parses a thread-reply message ref (/server/channel/#N#M)", () => {+ expect(parseRef("/demo/general/#5#42")).toEqual({+ server: "demo",+ channel: "general",+ threadRootSeq: 5,+ seq: 42,+ });+ });+ it("throws on empty seq tail (#5#)", () => {+ expect(() => parseRef("/demo/general/#5#")).toThrow();+ });+ it("throws on empty root (##5)", () => {+ expect(() => parseRef("/demo/general/##5")).toThrow();+ });+ it("throws on non-numeric seq (#5#abc)", () => {+ expect(() => parseRef("/demo/general/#5#abc")).toThrow();+ });+ it("throws on three-token tail (#5#42#7)", () => {+ expect(() => parseRef("/demo/general/#5#42#7")).toThrow();+ });+ it("stays permissive on #0#5 (server rejects root 0)", () => {+ expect(parseRef("/demo/general/#0#5")).toEqual({+ server: "demo",+ channel: "general",+ threadRootSeq: 0,+ seq: 5,+ });+ });+ it("stays permissive on #5#0 (server rejects seq 0)", () => {+ expect(parseRef("/demo/general/#5#0")).toEqual({+ server: "demo",+ channel: "general",+ threadRootSeq: 5,+ seq: 0,+ });+ });+ it("throws on slashless form with trailing #M", () => {+ expect(() => parseRef("/demo/general#5#42")).toThrow();+ });+ it("parses a DM thread-reply message ref (server rejects DM threads elsewhere)", () => {+ expect(parseRef("/.dm/gusye#1231/#5#42")).toEqual({+ server: DM_SERVER,+ channel: "gusye#1231",+ threadRootSeq: 5,+ seq: 42,+ });+ });});describe("formatRef", () => {@@ -71,4 +118,16 @@ describe("formatRef", () => {const p = parseRef(ref);expect(formatRef(p)).toBe(ref);});+ it("formats a thread-reply message ref", () => {+ expect(formatRef({ server: "demo", channel: "general", threadRootSeq: 5, seq: 42 })).toBe(+ "/demo/general/#5#42",+ );+ });+ it("round-trips a thread-reply message ref", () => {+ const input = { server: "demo", channel: "general", threadRootSeq: 5, seq: 42 };+ expect(parseRef(formatRef(input))).toEqual(input);+ });+ it("throws when seq is provided without threadRootSeq", () => {+ expect(() => formatRef({ server: "demo", channel: "general", seq: 42 })).toThrow();+ });});diff --git a/src/shared/src/community-cli-contract.ts b/src/shared/src/community-cli-contract.tsindex 6b38b5ff6..750506871 100644--- a/src/shared/src/community-cli-contract.ts+++ b/src/shared/src/community-cli-contract.ts@@ -863,6 +863,7 @@ export interface ParsedRef {* /<server>/<channel> → { server, channel }* /<server>/<channel>#N → { server, channel, seq:N }* /<server>/<channel>/#N → { server, channel, threadRootSeq:N }+ * /<server>/<channel>/#N#M → { server, channel, threadRootSeq:N, seq:M }* /.dm/<peer>[...] → DM (server = ".dm", channel = peer, a* `name#0042` handle) — see the `.dm`-specific* branch below, which differs from the@@ -878,12 +879,13 @@ export function parseRef(ref: ChannelRef): ParsedRef {const server = parts[0];// Trailing "#N" on the last segment pins a message seq.let seq: Seq | undefined;- let threadRootSeq: Seq | undefined;- // Thread form: /server/channel/#N → last part is "#N".+ // Thread form: /server/channel/#N or /server/channel/#N#M → last part+ // starts with "#". `#M` (when present) is the message seq WITHIN the+ // thread channel's own seq space.if (parts.length >= 3 && parts[parts.length - 1].startsWith("#")) {- threadRootSeq = parseSeq(parts[parts.length - 1]);- return { server, channel: parts[1], threadRootSeq };+ const tail = parseThreadTail(parts[parts.length - 1]);+ return { server, channel: parts[1], ...tail };}const chSeg = parts[1];@@ -923,10 +925,53 @@ export function parseRef(ref: ChannelRef): ParsedRef {return { server, channel: chSeg };}-/** Format the channel portion of a ParsedRef back to a path ref (no #seq). */-export function formatRef(p: { server: string; channel: string; threadRootSeq?: Seq }): ChannelRef {+/**+ * Split the trailing thread segment (`#N` or `#N#M`) of a thread-form ref+ * into a `{ threadRootSeq, seq? }` pair. Called with the raw last segment+ * (leading `#` present).+ *+ * Every token that reaches `parseSeq` here must first be checked for empty:+ * a naive `Number("") === 0` would otherwise silently accept `##5` as+ * `{ threadRootSeq:0, seq:5 }` or `#5#` as `{ threadRootSeq:5, seq:0 }` and+ * hand a bogus seq to the wire. Explicit `#0#5` / `#5#0` remain permissive+ * — the server rejects seq/root 0 at `resolve-ref.ts`.+ */+function parseThreadTail(segment: string): { threadRootSeq: Seq; seq?: Seq } {+ const stripped = segment.startsWith("#") ? segment.slice(1) : segment;+ const tokens = stripped.split("#");+ if (tokens.length < 1 || tokens.length > 2) {+ throw new Error(`bad thread ref tail: #${stripped}`);+ }+ for (const t of tokens) {+ if (!t) throw new Error(`bad thread ref tail: #${stripped} (empty seq)`);+ }+ const threadRootSeq = parseSeq(tokens[0]);+ if (tokens.length === 1) return { threadRootSeq };+ return { threadRootSeq, seq: parseSeq(tokens[1]) };+}++/**+ * Format a ParsedRef back to a path ref. Valid combinations:+ * {} → /server/channel+ * { threadRootSeq } → /server/channel/#N+ * { threadRootSeq, seq } → /server/channel/#N#M+ * A bare `seq` (no `threadRootSeq`) is NOT supported — the message form+ * `/server/channel#N` puts `#N` on the channel segment, not on a trailing+ * path segment, and no caller needs to emit that shape via formatRef today.+ */+export function formatRef(p: {+ server: string;+ channel: string;+ threadRootSeq?: Seq;+ seq?: Seq;+}): ChannelRef {+ if (p.seq !== undefined && p.threadRootSeq === undefined) {+ throw new Error("formatRef: seq without threadRootSeq is not supported");+ }const base = `/${p.server}/${p.channel}`;- return p.threadRootSeq !== undefined ? `${base}/#${p.threadRootSeq}` : base;+ if (p.threadRootSeq === undefined) return base;+ if (p.seq === undefined) return `${base}/#${p.threadRootSeq}`;+ return `${base}/#${p.threadRootSeq}#${p.seq}`;}/** "#12" → 12 ; "12" → 12. */diff --git a/src/shared/test/community-cli-contract.test.ts b/src/shared/test/community-cli-contract.test.tsindex 656b86cb9..236773680 100644--- a/src/shared/test/community-cli-contract.test.ts+++ b/src/shared/test/community-cli-contract.test.ts@@ -68,6 +68,75 @@ describe("parseRef", () => {expect(() => parseRef("/.dm/foo#bar")).not.toThrow();expect(parseRef("/.dm/foo#bar")).toEqual({ server: DM_SERVER, channel: "foo#bar" });});++ it('parses "/demo/general/#5#42" as a thread-reply message ref', () => {+ expect(parseRef("/demo/general/#5#42")).toEqual({+ server: "demo",+ channel: "general",+ threadRootSeq: 5,+ seq: 42,+ });+ });++ it('parses "/demo/general/#5" unchanged (regression)', () => {+ expect(parseRef("/demo/general/#5")).toEqual({+ server: "demo",+ channel: "general",+ threadRootSeq: 5,+ });+ });++ it('throws on "/demo/general/#5#" — empty seq tail (Number("") === 0 trap)', () => {+ expect(() => parseRef("/demo/general/#5#")).toThrow();+ });++ it('throws on "/demo/general/##5" — empty root', () => {+ expect(() => parseRef("/demo/general/##5")).toThrow();+ });++ it('throws on "/demo/general/#5#abc" — non-numeric seq', () => {+ expect(() => parseRef("/demo/general/#5#abc")).toThrow();+ });++ it('throws on "/demo/general/#5#42#7" — three tails, not two', () => {+ expect(() => parseRef("/demo/general/#5#42#7")).toThrow();+ });++ it('parses "/demo/general/#0#5" — parser stays permissive (server rejects root 0)', () => {+ expect(parseRef("/demo/general/#0#5")).toEqual({+ server: "demo",+ channel: "general",+ threadRootSeq: 0,+ seq: 5,+ });+ });++ it('parses "/demo/general/#5#0" — parser stays permissive (server rejects seq 0)', () => {+ expect(parseRef("/demo/general/#5#0")).toEqual({+ server: "demo",+ channel: "general",+ threadRootSeq: 5,+ seq: 0,+ });+ });++ it('throws on "/demo/general#5#42" — slashless form must NOT accept a trailing #M', () => {+ // The thread form requires the explicit `/#` separator. This shape is+ // ambiguous with the message form `/server/channel#N` and must be+ // rejected so callers can't sneak past the grammar.+ expect(() => parseRef("/demo/general#5#42")).toThrow();+ });++ it('parses "/.dm/gusye#1231/#5#42" — parser is DM-agnostic on thread form', () => {+ // Server rejects DM threads at resolve-ref.ts; the parser itself does+ // not know DM rules.+ expect(parseRef("/.dm/gusye#1231/#5#42")).toEqual({+ server: DM_SERVER,+ channel: "gusye#1231",+ threadRootSeq: 5,+ seq: 42,+ });+ });});describe("formatRef", () => {@@ -85,6 +154,33 @@ describe("formatRef", () => {const ref = formatRef({ server: "studio", channel: "general", threadRootSeq: 7 });expect(parseRef(ref)).toEqual({ server: "studio", channel: "general", threadRootSeq: 7 });});++ it("formats a thread-reply message ref (threadRootSeq + seq)", () => {+ expect(+ formatRef({ server: "studio", channel: "general", threadRootSeq: 5, seq: 42 }),+ ).toBe("/studio/general/#5#42");+ });++ it("round-trips through parseRef for the thread-reply form", () => {+ const input = { server: "studio", channel: "general", threadRootSeq: 5, seq: 42 };+ expect(parseRef(formatRef(input))).toEqual(input);+ });++ it("throws when seq is provided without threadRootSeq", () => {+ expect(() =>+ formatRef({ server: "studio", channel: "general", seq: 42 }),+ ).toThrow();+ });++ it("formats a plain channel ref unchanged (regression)", () => {+ expect(formatRef({ server: "studio", channel: "general" })).toBe("/studio/general");+ });++ it("formats a plain thread ref unchanged (regression)", () => {+ expect(formatRef({ server: "studio", channel: "general", threadRootSeq: 5 })).toBe(+ "/studio/general/#5",+ );+ });});describe("formatSeq / parseSeq", () => {diff --git a/src/web/src/components/community/channel-ref-pill.test.ts b/src/web/src/components/community/channel-ref-pill.test.tsindex 15673f257..7226a0e20 100644--- a/src/web/src/components/community/channel-ref-pill.test.ts+++ b/src/web/src/components/community/channel-ref-pill.test.ts@@ -131,4 +131,39 @@ describe("describeChannelRefPillView", () => {})expect((view as { threadSuffix?: number }).threadSuffix).toBeUndefined()})++ it("thread-reply form (threadRootSeq + seq), thread resolved → pill targets thread id, carries messageSuffix but no threadSuffix", () => {+ const view = describeChannelRefPillView({+ ref: "/srv_1/chn_1/#5#42",+ resolved: resolved({ threadRootSeq: 5, seq: 42 }),+ directoryLoading: false,+ thread: { id: "thr_1", name: "Thread about X", parentSeq: 5 },+ currentServerId: "srv_1",+ })+ expect(view).toEqual({+ kind: "pill",+ label: "Thread about X",+ serverPrefix: undefined,+ href: { serverId: "srv_1", channelId: "thr_1" },+ messageSuffix: 42,+ })+ })++ it("thread-reply form, thread-not-found degrade → pill targets base channel, carries BOTH threadSuffix and messageSuffix", () => {+ const view = describeChannelRefPillView({+ ref: "/srv_1/chn_1/#5#42",+ resolved: resolved({ threadRootSeq: 5, seq: 42 }),+ directoryLoading: false,+ thread: null,+ currentServerId: "srv_1",+ })+ expect(view).toEqual({+ kind: "pill",+ label: "general",+ serverPrefix: undefined,+ href: { serverId: "srv_1", channelId: "chn_1" },+ threadSuffix: 5,+ messageSuffix: 42,+ })+ })})diff --git a/src/web/src/components/community/channel-ref-pill.tsx b/src/web/src/components/community/channel-ref-pill.tsxindex 555ae6b49..228d3fcaf 100644--- a/src/web/src/components/community/channel-ref-pill.tsx+++ b/src/web/src/components/community/channel-ref-pill.tsx@@ -22,6 +22,12 @@ export type ChannelRefPillView =// after the pill, since a `/#N` suffix is never part of the clickable// target (see decision table below).threadSuffix?: number+ // Set when the ref pins a specific message inside a thread+ // (`/s/c/#N#M`, see plans/agent-thread-emoji-react.md). Rendered as+ // plain trailing text (`#M`, no leading slash) — the clickable target+ // is still the thread channel; `#M` is a visible cursor, not a deep+ // link anchor.+ messageSuffix?: number}/**@@ -83,6 +89,7 @@ export function describeChannelRefPillView(args: {serverPrefix,href: { serverId: resolved.server.id, channelId: resolved.channel.id },threadSuffix: resolved.threadRootSeq,+ ...(resolved.seq !== undefined ? { messageSuffix: resolved.seq } : {}),}}@@ -91,6 +98,7 @@ export function describeChannelRefPillView(args: {label: thread.name,serverPrefix,href: { serverId: resolved.server.id, channelId: thread.id },+ ...(resolved.seq !== undefined ? { messageSuffix: resolved.seq } : {}),}}@@ -144,6 +152,7 @@ export function ChannelRefPill({ children }: { children?: React.ReactNode }) {{view.label}</ChannelPill>{view.threadSuffix !== undefined && <span className="text-muted-foreground">/#{view.threadSuffix}</span>}+ {view.messageSuffix !== undefined && <span className="text-muted-foreground">#{view.messageSuffix}</span>}</>)}diff --git a/src/web/src/lib/community/channel-ref.test.ts b/src/web/src/lib/community/channel-ref.test.tsindex 3e368cfb1..1d31006e7 100644--- a/src/web/src/lib/community/channel-ref.test.ts+++ b/src/web/src/lib/community/channel-ref.test.ts@@ -80,6 +80,13 @@ describe("resolveChannelRefBase", () => {expect(resolved?.threadRootSeq).toBe(42)})+ it("resolves the thread-reply form /server/channel/#5#42 and surfaces both threadRootSeq and seq", () => {+ const resolved = resolveChannelRefBase(directory, "/studio/general/#5#42")+ expect(resolved?.channel.id).toBe("chn_general")+ expect(resolved?.threadRootSeq).toBe(5)+ expect(resolved?.seq).toBe(42)+ })+it("returns null instead of throwing on malformed input (fails parseRef)", () => {expect(resolveChannelRefBase(directory, "not-a-ref")).toBeNull()expect(resolveChannelRefBase(directory, "/onlyserver")).toBeNull()diff --git a/src/web/src/lib/community/channel-ref.ts b/src/web/src/lib/community/channel-ref.tsindex c9294cbab..c72eaca8f 100644--- a/src/web/src/lib/community/channel-ref.ts+++ b/src/web/src/lib/community/channel-ref.ts@@ -19,6 +19,7 @@ export type ResolvedChannelRef = {server: ChannelRefDirectoryServerchannel: ChannelRefDirectoryChannelthreadRootSeq?: number+ seq?: number}/**@@ -66,6 +67,7 @@ export function resolveChannelRefBase(server,channel,...(parsed.threadRootSeq !== undefined ? { threadRootSeq: parsed.threadRootSeq } : {}),+ ...(parsed.seq !== undefined ? { seq: parsed.seq } : {}),}}diff --git a/src/web/src/lib/community/chat-syntax-plugin.test.ts b/src/web/src/lib/community/chat-syntax-plugin.test.tsindex 0023faf2a..9ca8b2621 100644--- a/src/web/src/lib/community/chat-syntax-plugin.test.ts+++ b/src/web/src/lib/community/chat-syntax-plugin.test.ts@@ -121,6 +121,19 @@ describe("chatSyntaxPlugin — channelRef", () => {expect(children[1]).toMatchObject({ type: "channelRef", value: "/studio/general/#42" })})+ it("wraps the thread-reply form /studio/general/#5#42 as a single channelRef node", () => {+ const children = paragraphChildren(parse("see /studio/general/#5#42 done"))+ const refs = children.filter((c): c is ChannelRefNode => c.type === "channelRef")+ expect(refs).toHaveLength(1)+ expect(refs[0]).toMatchObject({ type: "channelRef", value: "/studio/general/#5#42" })+ })++ it("does not match a thread-reply form mid-string (leading-space boundary still applies)", () => {+ const children = paragraphChildren(parse("text/studio/general/#5#42"))+ expect(children).toHaveLength(1)+ expect(children[0]).toMatchObject({ type: "text" })+ })+it("leaves a channel-ref-shaped path inside inline code literal", () => {const children = paragraphChildren(parse("`/studio/general`"))expect(children.map((c) => c.type)).toEqual(["inlineCode"])diff --git a/src/web/src/lib/community/chat-syntax-plugin.ts b/src/web/src/lib/community/chat-syntax-plugin.tsindex 6698ecce9..032b9c4c9 100644--- a/src/web/src/lib/community/chat-syntax-plugin.ts+++ b/src/web/src/lib/community/chat-syntax-plugin.ts@@ -19,8 +19,9 @@ import type { SpoilerNode } from "./spoiler-syntax"// comment for why find-and-replace cannot handle spoilers containing nested// formatting.-// Mirrors `CHANNEL_REF_REGEX`'s old doc comment: matches a `/server/channel`-// or `/server/channel/#N` (thread) ref — the CLI's path grammar+// Mirrors `CHANNEL_REF_REGEX`'s old doc comment: matches a `/server/channel`,+// `/server/channel/#N` (thread), or `/server/channel/#N#M` (thread reply,+// see plans/agent-thread-emoji-react.md) ref — the CLI's path grammar// (`parseRef`/`formatRef` in `community-cli-contract.ts`). Segment charset// `[A-Za-z0-9_-]+` is the nanoid alphabet every `communityServer.id`/// `communityChannel.id` is generated with. Trailing@@ -35,7 +36,7 @@ import type { SpoilerNode } from "./spoiler-syntax"// `findAndReplace` doesn't need to redistribute a leading/trailing text// node around the match the way the old string-splice regex's `(^|\s)`// capture group did.-const CHANNEL_REF_RE = /(?<=^|\s)\/[A-Za-z0-9_-]+\/[A-Za-z0-9_-]+(?:\/#\d+)?(?=\s|$|[.,;:!?)\]])/g+const CHANNEL_REF_RE = /(?<=^|\s)\/[A-Za-z0-9_-]+\/[A-Za-z0-9_-]+(?:\/#\d+(?:#\d+)?)?(?=\s|$|[.,;:!?)\]])/g// A bare `/server` ref — one segment, no channel. Same boundary lookaround as// `CHANNEL_REF_RE` (leading `(?<=^|\s)`, trailing `(?=\s|$|[.,;:!?)\]])`), which