A local-first multi-agent app development platform, built on PenguinHarness
fix(company): 工位忙时错过的 @ 合并成一个工作轮送达,重启也不丢
lmliheng2821578f2e21
diff --git a/FORK-PROGRESS.md b/FORK-PROGRESS.mdindex f1f96ccd..8b70ab58 100644--- a/FORK-PROGRESS.md+++ b/FORK-PROGRESS.md@@ -195,6 +195,31 @@流水线仍属 4.x)。- [ ] 4.3 **旧的四件产物要更新**(用户 2026-10-05 定:按新基座重发新版,不是下架)。+### 5. 跟上游学(2026-10-06 查上游现状后定的顺序)++判据是「对着我们的待办与生意」,不是「上游有什么」。上游 `main` 停在 `d56d9ced`(2026-10-04T18:02Z),+我们比它少 31 个提交(`18d7c137` 基座 → 今天),另有 221 个分支在推(今天 09:17Z 一波约 180 条)。++- [x] **5.1 工位 @ 合并成一个工作轮**(上游 `feat/org-trigger-coalesce` / `c41fa086`)——本轮做完,见下。+ 这是四处里唯一一条直接压公司模式那笔钱的:会话数才是费用变量,而忙工位过去会攒下几十个各带一份+ 频道上下文的工作轮。+- [ ] 5.2 **插件库「自带 demo」+ 商店条目模型**(上游 `c6a7b6ee` `#726`、`feat/plugin-store`)——+ 正对插件市场 v1 的货架、一键安装与更新提示;上游把索引条目、桶、demo 快速开始都试过了。+- [ ] 5.3 **跨机 agents**(`feat/agents-across-machines`、`feat/machine-*`、`feat/port-forwarding`、+ `feat/company-remote-machines`、`feat/agent-state-handover`)——**先调研再投资**。价值最大:+ 公司跑在 Windows(RTX 5060)那台,现在两台机器之间靠人搬。+- [ ] 5.4 **沙箱体系**(上游已进 main:Landlock 让默认 Ubuntu 可用 `234183f5`、权限菜单命名预设+ `9b170c61`、`sandbox-dsh` 在 Windows 走 pwsh `c03e58c4`、建沙箱前先建 scratchpad `cba091e3`、+ 后端拆成 npm 包 `1ba104c9`)。我们有四个后端,缺的是「体系」:公司模式下一群 agent 在跑命令。+- [ ] 5.5 **长会话与 Trace 的加载性能**(`b8862716` `#958`:窗口化消息 + Trace 行索引 + Trace 图片)。+- [ ] 5.6 **用量成本「记账时就定价」**(`feat/usage-cost-at-record-time`)——公司审计里 `unpriced = false`+ 那个口径就靠它。+- [x] **5.7 一个功能提交带一条 `changelog/unreleased/<日期>-<slug>.md`(中英双份)** ——本轮照做;+ 此前我们自己的改动基本只写本台账,发版说明全靠临时凑。+- **不学**:阿里云 OSS 分发(`feat/aliyun-oss-release-distribution`)、模型库「官方推荐」与 TokenDance+ 推荐分组(`FORK.md` 已写明不搬)、`web-mod-1…12` 那类大模块化重构(与我们改过的 77 个文件重叠,+ 现在合进来是净亏)。+## 发布 v0.2.0(2026-10-05)用户要求「先发布最新版本到 GitHub,说明是基于 penguin harness 做的」。这一版是**源码版**:@@ -1877,3 +1902,50 @@ README 的环境表跟上了。这一轮没碰它,它属 2.2c 的文档尾巴无人值守的定时轮次(本文件这些自主轮次、组织的工位会话)靠的就是「不问就干」,而每轮会话自己还能在输入区改档。- `packages/web/README.md` 末尾那行来源链接仍写着上游的 `github.com/Prism-Shadow/penguin-harness`(我们的仓库是 `lmliheng/Adelie`);属品牌那一类,这轮没动。++## 跟上游学之一:工位 @ 合并(2026-10-06)++用户让「按你的思路进化应用」,第一件做的是清单里的 5.1 —— 公司模式里最直接压钱的那条。++### 为什么要做++上一轮算公司模式的开销时得到的结论是「**会话数量才是费用变量**」:每一次巡检、每一次重跑、每一次重剪+都是一次会话,而每个会话第一条消息都要冷读手册、规范与工单。频道 @ 是这条账上最不值的一笔 ——+工位忙时,过去每被 @ 一次就在工位会话的内存队列里压一个 Task,一个长 Task 回来面对几十个工作轮,+每个都带着同一段频道上下文、其中大多数说的是它已经办完的事;而服务重启或热更新会**静默清空**这个队列,+频道扫描早已越过那些消息,它们再也不会送达(丢了还没人知道)。++上游在 `feat/org-trigger-coalesce` 上解决了它(提交 `c41fa086`,2026-09-29),那条分支没进 `main`,+我们的基座里也没有。++### 做了什么(照上游的设计移植,不是合分支)++- **排队取代压队列**:@ 先写进公司模式新表 `org_desk_mentions`(我们这边是迁移 **13**+ `company-mode-desk-mentions`,`swapSafe: true`),与推进频道扫描游标在同一次对账里落库,+ 按(员工、频道、消息)去重 —— 一次死在游标移动之前的对账不会重复排队。+- **一次对账 = 每个空闲工位一个工作轮**:`deliverDeskMentions` 把待送达的 @ 合并送达,每轮至多 20 条+ (`MENTIONS_PER_RUN`),**发起成功才出队**:发起被拒或开不出工位时它们留到下一次;忙着的工位跳过、+ 继续累积。合并轮的 hop 取各条的最大值,连锁上限不因合并而重置。+- **正文只在多条时才变**:一条与过去逐字相同;多条合成清单 —— 逐条列出完整点名、按频道分组、+ 「今天早些时候」的上下文每个频道只附一次,点名之间未 @ 它的消息不重复(留给 `channel tail`)。+- **旧的队列语义改了**:`dispatchToDesk` 的 `queueIfBusy` 仍在(日历事件还用它),但它的注释写清了+ 它只在本进程存活期间有效 —— 所以 @ 不走它。+- 员工离任时把待送达的 @ 一并清空(`service.leave`);组织暂停或公司模式关闭期间保留,不丢弃。+- `company-employee` Skill 补上合并送达的说明:每条点名回各自的频道答复,已处理过的跳过;+ `agent-company` 版本 `2026.09.18.1` → `2026.10.06.1`。+- 变更日志照 5.7 的习惯写了中英双份:`changelog/unreleased/2026-10-06-org-desk-mentions{,zh}.md`。++### 验证(都实跑过)++- `packages/server`:**181 个文件 / 2613 通过 · 2 跳过 · 0 失败**(新增 5 条运行时用例 + 2 条迁移用例)。+ 新增的 5 条是上游那 5 条的对应物:忙工位把两条 @ 攒起来、空闲后一个轮送达且上下文只附一次、+ 中间未点名的那条不被复述、已在办的不重复办;待送达的 @ 活过进程重启且 hop 取最大;+ 发起被拒则留到下一轮且单独一条读起来与过去一致;每轮上限 20 条并说明还有更多;+ 离任员工把待送达的 @ 带走。+- `packages/server/test/db-migrations.test.ts`:迁移 13 的两条(新库与声明一致、重复扫描不重复入队、+ 回滚到 12 只剩空表),并修了三处写死到 12 的断言与七个按「当前声明减去某迁移」构造的旧库夹具。+- `packages/docs` 62 通过(含 `skills-sync.test.ts`,插件技能与文档站同步);`packages/core` 的+ `plugins.test.ts` 21 + `plugin-store.test.ts` 8 通过。+- `pnpm lint` 0 警告 0 错误(2052 文件);`pnpm format:check` 干净;`packages/server` 的+ `tsc --noEmit` 过,`ifaces.json` 重新生成(它是生成物、`.gitignore` 里,不进提交)。+- 没有起的服务、没有动的端口;`/root/adelie-fork` 工作树在本轮开始与结束时都只有本轮的文件。diff --git a/changelog/unreleased/2026-10-06-org-desk-mentions.md b/changelog/unreleased/2026-10-06-org-desk-mentions.mdnew file mode 100644index 00000000..92226c27--- /dev/null+++ b/changelog/unreleased/2026-10-06-org-desk-mentions.md@@ -0,0 +1,38 @@+# A busy desk gets one run for all the mentions it missed, and keeps them across a restart++- **Date:** 2026-10-06+- **Type:** fix+- **Scope:** `server`++[中文版](2026-10-06-org-desk-mentions.zh.md)++Every channel mention of an employee started a Task of its own at the employee's desk, queued+in the session's memory when the desk was busy. A desk working one long Task could return to+dozens of queued runs, each carrying the same channel context, most of them about work it had+already done; a restart or a hot update emptied that queue silently, and the scan had already+moved past the messages, so they were never delivered. Ported from upstream PenguinHarness+(`feat/org-trigger-coalesce`, commit `c41fa086`), which the fork did not carry.++## Details++- Mentions now wait in a new company-mode table, `org_desk_mentions` (migration 13,+ `company-mode-desk-mentions`, swap-safe), written in the same pass that moves the channel's+ scan offset and deduplicated by (employee, channel, message). The desk's session follow-up+ queue no longer holds them.+- Each reconcile pass carries the waiting mentions to every desk that is idle as one+ `kind: mention` run: up to `MENTIONS_PER_RUN` (20) per run, removed only once the run has+ started, so a refused start or a desk that cannot be opened leaves them for the next pass. A+ busy desk is passed over and its mentions keep accumulating.+- A single mention reads exactly as before. Several read as one list: every mention in full,+ grouped by channel, with the earlier-today context once per channel rather than once per+ mention; lines between them that named someone else are left to `penguin org channel tail`.+ The trigger's `message` names the first mention and how many more follow; `channel` is+ omitted when the mentions span channels.+- The run carries the highest hop among its mentions, so batching never resets the mention+ chain limit. Waiting mentions are held while the organization is paused or company mode is+ switched off, and an employee who leaves takes theirs along.+- The `company-employee` skill describes the batched `mention` run: answer each mention in its+ own channel and skip the ones already handled. `agent-company` is `2026.10.06.1`.+- A queue is cheaper than a run: this is what keeps a long Task from coming back to a dozen+ runs that re-read the same channel and the same handbook. `penguin cost --by session` is+ where the difference shows.diff --git a/changelog/unreleased/2026-10-06-org-desk-mentions.zh.md b/changelog/unreleased/2026-10-06-org-desk-mentions.zh.mdnew file mode 100644index 00000000..2a04ba51--- /dev/null+++ b/changelog/unreleased/2026-10-06-org-desk-mentions.zh.md@@ -0,0 +1,28 @@+# 工位忙时错过的 @ 合并成一个工作轮送达,重启也不丢++- **Date:** 2026-10-06+- **Type:** fix+- **Scope:** `server`++[English](2026-10-06-org-desk-mentions.md)++过去员工在频道里每被 @ 一次,就在其工位上单独发起一个 Task;工位忙时这些 Task 排在会话的内存队列里。+工位跑完一个长 Task 回来,可能面对几十个排队的工作轮,每个都带着同一段频道上下文,而其中大多数说的是+它已经办完的事;服务重启或热更新会静默清空这个队列,而频道扫描早已越过这些消息,它们再也不会送达。+本次从上游 PenguinHarness 移植(`feat/org-trigger-coalesce`,提交 `c41fa086`),此前本 fork 没有这一条。++## Details++- @ 现在先记入公司模式新增的表 `org_desk_mentions`(迁移 13,`company-mode-desk-mentions`,swap-safe),+ 与推进频道扫描游标在同一次对账里落库,按(员工、频道、消息)去重;工位会话的 follow-up 队列不再承载它们。+- 每次对账把待送达的 @ 合并成一个 `kind: mention` 工作轮送给空闲的工位:每轮至多 `MENTIONS_PER_RUN`(20)条,+ 发起成功才出队,因此发起被拒或开不出工位时它们留待下一次对账;忙着的工位被跳过,它的 @ 继续累积。+- 只有一条时正文与过去完全相同;多条时合成一份清单:逐条列出完整的点名,按频道分组,今天早些时候的+ 上下文每个频道只附一次、不再每条附一次;点名之间未 @ 它的消息留给 `penguin org channel tail` 去读。+ 触发块的 `message` 写首条点名并注明后面还有几条;点名跨频道时省略 `channel`。+- 合并轮的 hop 取其中各条的最大值,连锁上限不因合并而重置。组织暂停或公司模式关闭期间待送达的 @+ 保留;员工离任时一并清空。+- `company-employee` Skill 说明了合并送达的 `mention` 工作轮:每条点名回到各自的频道答复,已处理过的+ 跳过。`agent-company` 版本为 `2026.10.06.1`。+- 排队比跑一轮便宜:这正是让一个长 Task 回来时不再面对十几个重复读同一份频道与同一份手册的工作轮的原因,+ 差别在 `penguin cost --by session` 上看得到。diff --git a/packages/server/src/db/migrations.ts b/packages/server/src/db/migrations.tsindex 1f43b497..33c921e9 100644--- a/packages/server/src/db/migrations.ts+++ b/packages/server/src/db/migrations.ts@@ -524,6 +524,36 @@ export const MIGRATIONS: readonly Migration[] = [// was never this migration's to take away.down() {},},+ {+ version: 13,+ name: "company-mode-desk-mentions",+ // Additive: one new table. A channel mention no longer starts a work run of its own+ // (queued in the desk session's memory when the desk was busy, and lost on a restart);+ // it waits here until the desk is idle and is delivered with the others in one run.+ // A predecessor build never reads the table, so a rollback survives it — with whatever+ // rows are in it left undelivered.+ swapSafe: true,+ up(db) {+ db.exec(`+ CREATE TABLE IF NOT EXISTS org_desk_mentions ( -- DERIVED CACHE (company mode): channel mentions waiting for an employee's desk to be idle; dropping it loses only the mentions not delivered yet (the messages stay in the channel files)+ seq INTEGER PRIMARY KEY AUTOINCREMENT,+ project_id TEXT NOT NULL,+ org_id TEXT NOT NULL,+ agent_id TEXT NOT NULL,+ channel_id TEXT NOT NULL,+ date TEXT NOT NULL,+ message_id TEXT NOT NULL,+ hop INTEGER NOT NULL,+ UNIQUE (project_id, org_id, agent_id, channel_id, message_id)+ );+ `);+ },+ // LOSES every mention not delivered yet: the message stays in its channel file, but no+ // desk run will name it.+ down(db) {+ db.exec(`DROP TABLE IF EXISTS org_desk_mentions;`);+ },+ },];/** The highest version this build knows how to reach. */diff --git a/packages/server/src/db/repos/organizations.ts b/packages/server/src/db/repos/organizations.tsindex dfa19143..01cbd698 100644--- a/packages/server/src/db/repos/organizations.ts+++ b/packages/server/src/db/repos/organizations.ts@@ -3,10 +3,11 @@* desk session an employee has, which sessions contribute to a ticket, how far a calendar* event or a channel scan has got, what a ticket looked like when it was last notified) or a* user's own read cursor. The service rebuilds the projections every reconcile pass, so a- * dropped table costs one pass of silence, never a wrong answer. `org_desk_notices` is the- * one queue in the family: the ticket changes an employee has not been told about yet, held- * until its next calendar sweep carries them, so dropping it loses those digests and nothing- * else — the changes themselves live in the ticket files and the all-hands channel.+ * dropped table costs one pass of silence, never a wrong answer. Two queues are the+ * exception: `org_desk_notices` holds the ticket changes an employee has not been told about+ * yet until its next calendar sweep carries them, and `org_desk_mentions` holds the channel+ * mentions until its desk is idle, so dropping either loses only what it has not delivered —+ * the changes live in the ticket files, the messages in the channel files.*/import { Component, Use } from "@lmliheng/penguin-core/kernel";import type { Db } from "../../hmr/capabilities.js";@@ -81,6 +82,22 @@ export interface OrgDeskNoticeRow {at: string;}+/**+ * One channel mention waiting for an employee's desk to be idle. `seq` is the delivery order+ * and `hop` the chain hop it arrived with; `date` names the channel day file the message sits+ * in, so delivery reads it back from the file (the truth) instead of a copy here.+ */+export interface OrgDeskMentionRow {+ seq: number;+ projectId: string;+ orgId: string;+ agentId: string;+ channelId: string;+ date: string;+ messageId: string;+ hop: number;+}+/** Where a session belongs, when it belongs to an organization at all. */export interface OrgSessionOwner {projectId: string;@@ -620,6 +637,77 @@ export class OrgCacheRepo implements OrgCache {.run(projectId, orgId, agentId);}+ // ---- desk mentions (the queue delivered once the desk is idle) ----++ /**+ * Records a mention for an employee's desk. A message already queued for that employee is+ * left as it is: a pass that dies after this write but before the channel offset moves reads+ * the same lines again, and must not queue them twice.+ */+ queueDeskMention(row: Omit<OrgDeskMentionRow, "seq">): void {+ this.db+ .prepare(+ `INSERT OR IGNORE INTO org_desk_mentions (project_id, org_id, agent_id, channel_id, date, message_id, hop)+ VALUES (?, ?, ?, ?, ?, ?, ?)`,+ )+ .run(row.projectId, row.orgId, row.agentId, row.channelId, row.date, row.messageId, row.hop);+ }++ /** The employees with at least one mention waiting, in the order their oldest one arrived. */+ agentsWithDeskMentions(projectId: string, orgId: string): string[] {+ const rows = this.db+ .prepare(+ `SELECT agent_id FROM org_desk_mentions WHERE project_id = ? AND org_id = ?+ GROUP BY agent_id ORDER BY MIN(seq)`,+ )+ .all(projectId, orgId) as Array<{ agent_id: string }>;+ return rows.map((r) => r.agent_id);+ }++ /**+ * Up to `limit` of an employee's waiting mentions in delivery order, left in place: they are+ * removed with {@link dropDeskMentions} only once the run carrying them has started.+ */+ peekDeskMentions(+ projectId: string,+ orgId: string,+ agentId: string,+ limit: number,+ ): OrgDeskMentionRow[] {+ const rows = this.db+ .prepare(+ `SELECT * FROM org_desk_mentions+ WHERE project_id = ? AND org_id = ? AND agent_id = ? ORDER BY seq LIMIT ?`,+ )+ .all(projectId, orgId, agentId, limit) as Record<string, unknown>[];+ return rows.map((r) => ({+ seq: Number(r.seq),+ projectId: r.project_id as string,+ orgId: r.org_id as string,+ agentId: r.agent_id as string,+ channelId: r.channel_id as string,+ date: r.date as string,+ messageId: r.message_id as string,+ hop: Number(r.hop),+ }));+ }++ /** Removes an employee's mentions up to and including `throughSeq` — the ones a run just carried. */+ dropDeskMentions(projectId: string, orgId: string, agentId: string, throughSeq: number): void {+ this.db+ .prepare(+ "DELETE FROM org_desk_mentions WHERE project_id = ? AND org_id = ? AND agent_id = ? AND seq <= ?",+ )+ .run(projectId, orgId, agentId, throughSeq);+ }++ /** An employee that left takes its undelivered mentions with it: no desk of its will run them. */+ deleteDeskMentions(projectId: string, orgId: string, agentId: string): void {+ this.db+ .prepare("DELETE FROM org_desk_mentions WHERE project_id = ? AND org_id = ? AND agent_id = ?")+ .run(projectId, orgId, agentId);+ }+// ---- lifecycle ----deleteOrg(projectId: string, orgId: string): void {@@ -632,6 +720,7 @@ export class OrgCacheRepo implements OrgCache {"org_channel_reads","org_budget_state","org_desk_notices",+ "org_desk_mentions",]) {this.db.prepare(`DELETE FROM ${table} WHERE project_id = ? AND org_id = ?`)@@ -649,6 +738,7 @@ export class OrgCacheRepo implements OrgCache {"org_channel_reads","org_budget_state","org_desk_notices",+ "org_desk_mentions",]) {this.db.prepare(`DELETE FROM ${table} WHERE project_id = ?`).run(projectId);}diff --git a/packages/server/src/db/schema.ts b/packages/server/src/db/schema.tsindex 77a23bb3..7566eba7 100644--- a/packages/server/src/db/schema.ts+++ b/packages/server/src/db/schema.ts@@ -287,4 +287,15 @@ CREATE TABLE IF NOT EXISTS org_desk_notices ( -- DERIVED CACHE (company mode):at TEXT NOT NULL);CREATE INDEX IF NOT EXISTS idx_org_desk_notices_agent ON org_desk_notices(project_id, org_id, agent_id);+CREATE TABLE IF NOT EXISTS org_desk_mentions ( -- DERIVED CACHE (company mode): channel mentions waiting for an employee's desk to be idle; dropping it loses only the mentions not delivered yet (the messages stay in the channel files)+ seq INTEGER PRIMARY KEY AUTOINCREMENT,+ project_id TEXT NOT NULL,+ org_id TEXT NOT NULL,+ agent_id TEXT NOT NULL,+ channel_id TEXT NOT NULL,+ date TEXT NOT NULL,+ message_id TEXT NOT NULL,+ hop INTEGER NOT NULL,+ UNIQUE (project_id, org_id, agent_id, channel_id, message_id)+);`;diff --git a/packages/server/src/runtime/organization/reconcile.ts b/packages/server/src/runtime/organization/reconcile.tsindex 0eb24e02..e7632080 100644--- a/packages/server/src/runtime/organization/reconcile.ts+++ b/packages/server/src/runtime/organization/reconcile.ts@@ -3,15 +3,16 @@* or a route's write asks for it. Files in, decisions out: caches are projected from the* ledger and the tickets, missing desks are opened and desks renewed where the chart moved* them, due calendar events fire (carrying the ticket changes queued since the employee's- * last sweep), ticket changes are recorded and queued, new channel mentions are delivered,- * budgets are checked, and every employee's company plugins are brought up to the library's- * version.+ * last sweep), ticket changes are recorded and queued, new channel mentions are queued and+ * carried to the desks that are idle, budgets are checked, and every employee's company+ * plugins are brought up to the library's version.* Missed work is never backfilled: a slot that passed while the server was down, the* organization paused or the switch off is consumed and skipped, like a schedule.*/import { createHash } from "node:crypto";import { comparePluginVersions } from "@lmliheng/penguin-core";import type { OrgCalendarOutcome, OrgChannelMessage, OrgTicketChange } from "../../api/types.js";+import type { OrgDeskMentionRow } from "../../db/repos/organizations.js";import type { SessionRow } from "../../db/repos/sessions.js";import type { ChannelConfig, TicketDoc } from "../../organization/files.js";import { parseChannelMessageLine, serializeChannelMessageLine } from "../../organization/files.js";@@ -553,16 +554,87 @@ export async function appendSystemMessage(});}+/** How many earlier messages of the channel's day a mention carries as context. */+const MENTION_CONTEXT = 20;++/** How many waiting mentions one desk run carries; the rest wait for the desk's next idle moment. */+export const MENTIONS_PER_RUN = 20;++const quoteLine = (m: OrgChannelMessage): string =>+ `> ${m.time} ${m.sender}: ${m.text.replace(/\n/g, "\n> ")}`;++const mentionHead = (msg: OrgChannelMessage): string =>+ `Message ${msg.id} from ${msg.sender}${msg.refs?.ticket !== undefined ? ` (ticket ${msg.refs.ticket})` : ""}:\n${msg.text}`;++/** Up to {@link MENTION_CONTEXT} messages of the day before `msg`, minus the ones in `skip`. */+function earlierLines(+ all: readonly OrgChannelMessage[],+ msg: OrgChannelMessage,+ skip: ReadonlySet<string> = new Set(),+): string[] {+ const idx = all.findIndex((m) => m.id === msg.id);+ return (idx > 0 ? all.slice(Math.max(0, idx - MENTION_CONTEXT), idx) : [])+ .filter((m) => !skip.has(m.id))+ .map(quoteLine);+}+/** The body of a mention trigger: the message, then up to 20 earlier messages of that channel's day as context. */function mentionBody(all: readonly OrgChannelMessage[], msg: OrgChannelMessage): string {- const idx = all.findIndex((m) => m.id === msg.id);- const earlier = (idx > 0 ? all.slice(Math.max(0, idx - 20), idx) : []).map(- (m) => `> ${m.time} ${m.sender}: ${m.text.replace(/\n/g, "\n> ")}`,- );- const head = `Message ${msg.id} from ${msg.sender}${msg.refs?.ticket !== undefined ? ` (ticket ${msg.refs.ticket})` : ""}:\n${msg.text}`;+ const earlier = earlierLines(all, msg);+ const head = mentionHead(msg);return earlier.length === 0 ? head : `${head}\n\nEarlier today:\n${earlier.join("\n")}`;}+/** A waiting mention, read back from its channel file (null: the line is no longer there). */+interface WaitingMention {+ row: OrgDeskMentionRow;+ msg: OrgChannelMessage | null;+ day: readonly OrgChannelMessage[];+}++/**+ * The body of a run carrying several mentions: each mention in full, grouped by channel in+ * the order the first of each arrived, and the context once per channel — the messages before+ * that channel's first mention — rather than once per mention. Lines between two mentions that+ * named someone else are not repeated; the desk reads them with `channel tail` if it needs to.+ */+function batchBody(waiting: readonly WaitingMention[], more: boolean): string {+ const groups = new Map<string, WaitingMention[]>();+ for (const w of waiting) {+ const list = groups.get(w.row.channelId);+ if (list) list.push(w);+ else groups.set(w.row.channelId, [w]);+ }+ const parts = [+ `${waiting.length} channel mentions are waiting for you, oldest first. Answer each in the channel it came from; one you have already handled needs no second answer.`,+ ];+ for (const [channelId, list] of groups) {+ const lines = [`## Channel ${channelId}`];+ const first = list.find((w) => w.msg !== null);+ if (first) {+ const earlier = earlierLines(+ first.day,+ first.msg!,+ new Set(list.map((w) => w.row.messageId)),+ );+ if (earlier.length > 0) lines.push(`Earlier today:\n${earlier.join("\n")}`);+ }+ for (const w of list) {+ lines.push(+ w.msg !== null+ ? mentionHead(w.msg)+ : `Message ${w.row.messageId}: no longer in ${channelId}/${w.row.date}.jsonl.`,+ );+ }+ lines.push(+ `Messages between these that did not mention you are not repeated here: \`penguin org channel tail --channel ${channelId}\` reads them.`,+ );+ parts.push(lines.join("\n\n"));+ }+ if (more) parts.push("More mentions are still waiting; they follow in your next run.");+ return parts.join("\n\n");+}+/*** The employees a channel delivers to: every employee for the all-hands channel, the* `agent:` members for any other. An `agent:` member who has since left the organization is@@ -579,14 +651,17 @@ function channelAgents(org: LoadedOrg, channel: ChannelConfig): Set<string> {}/**- * Tail-scans each channel's recent day files, publishes every new message and delivers its- * mentions inside that channel's membership. Archived channels take no posts, so there is- * nothing new to find in them; an invalid `channel.toml` is reported and the channel skipped.+ * Tail-scans each channel's recent day files, publishes every new message and queues its+ * mentions inside that channel's membership in `org_desk_mentions`; a message that names+ * nobody goes to the channel's default recipients (`notify`) instead, the same way — unless a+ * plugin claims the channel, which then handles its messages itself. Nothing is sent here: the+ * queue is written before the channel's offset moves, and {@link deliverDeskMentions} carries+ * it to the desks that are idle. Archived channels take no posts, so there is nothing new to+ * find in them; an invalid `channel.toml` is reported and the channel skipped.*/export async function scanChannels(deps: OrgDeps,org: LoadedOrg,- spend: OrgSpend,triggers: boolean,): Promise<void> {for (const file of await deps.store.listChannels(org.dir)) {@@ -617,7 +692,6 @@ export async function scanChannels(deps.cache.setChannelOffset(org.projectId, org.orgId, channelId, date, nextOffset);continue;}- const all = (await deps.store.readMessageDay(org.dir, channelId, date)).messages;for (const line of lines) {const parsed = parseChannelMessageLine(line);if (!parsed.ok) {@@ -654,18 +728,15 @@ export async function scanChannels(if (senderAgent !== null) targets.delete(senderAgent);for (const agentId of targets) {if (!org.byId.has(agentId)) continue;- await dispatchToDesk(- deps,- org,+ deps.cache.queueDeskMention({+ projectId: org.projectId,+ orgId: org.orgId,agentId,- {- kind: "mention",- message: `${msg.id} from ${msg.sender}`,- channel: channelId,- },- mentionBody(all, msg),- { hop: msg.hop, budget: budgetLine(org, spend, agentId) },- );+ channelId,+ date,+ messageId: msg.id,+ hop: msg.hop,+ });}}deps.cache.setChannelOffset(org.projectId, org.orgId, channelId, date, nextOffset);@@ -673,6 +744,75 @@ export async function scanChannels(}}+/**+ * Carries the waiting mentions to every desk that is idle: one run per desk however many wait+ * (up to {@link MENTIONS_PER_RUN}), removed from the queue only once the run has started — a+ * desk that cannot be opened or a runner that refuses leaves them for the next pass. A busy+ * desk is passed over: its mentions keep accumulating here, durable across a restart or a hot+ * update, instead of one queued Task each in the session's memory. A single mention reads+ * exactly as it always did; several read as one list (see {@link batchBody}). The run's hop is+ * the highest of the mentions it carries, so batching never resets a chain. Held, not dropped,+ * while the organization is paused or the master switch is off.+ */+export async function deliverDeskMentions(+ deps: OrgDeps,+ org: LoadedOrg,+ spend: OrgSpend,+ triggers: boolean,+): Promise<void> {+ if (!triggers || org.config.status === "paused") return;+ for (const agentId of deps.cache.agentsWithDeskMentions(org.projectId, org.orgId)) {+ if (!org.byId.has(agentId)) {+ // Taken off the chart by hand: nobody will ever work these.+ deps.cache.deleteDeskMentions(org.projectId, org.orgId, agentId);+ continue;+ }+ const desk = org.desks[agentId];+ if (desk !== undefined && deps.runner.statusOf(desk.sessionId) !== "idle") continue;+ const rows = deps.cache.peekDeskMentions(+ org.projectId,+ org.orgId,+ agentId,+ MENTIONS_PER_RUN + 1,+ );+ const more = rows.length > MENTIONS_PER_RUN;+ const batch = rows.slice(0, MENTIONS_PER_RUN);+ if (batch.length === 0) continue;+ const days = new Map<string, readonly OrgChannelMessage[]>();+ const waiting: WaitingMention[] = [];+ for (const row of batch) {+ const key = `${row.channelId}/${row.date}`;+ let day = days.get(key);+ if (day === undefined) {+ day = (await deps.store.readMessageDay(org.dir, row.channelId, row.date)).messages;+ days.set(key, day);+ }+ waiting.push({ row, day, msg: day.find((m) => m.id === row.messageId) ?? null });+ }+ const first = waiting[0]!;+ const sender = first.msg?.sender;+ const channels = new Set(batch.map((r) => r.channelId));+ const single = waiting.length === 1 && first.msg !== null;+ const outcome = await dispatchToDesk(+ deps,+ org,+ agentId,+ {+ kind: "mention",+ message: `${first.row.messageId}${sender !== undefined ? ` from ${sender}` : ""}${waiting.length > 1 ? ` (+${waiting.length - 1} more)` : ""}`,+ ...(channels.size === 1 ? { channel: first.row.channelId } : {}),+ },+ single ? mentionBody(first.day, first.msg!) : batchBody(waiting, more),+ {+ hop: Math.max(...batch.map((r) => r.hop)),+ budget: budgetLine(org, spend, agentId),+ },+ );+ if (outcome === "skipped") continue;+ deps.cache.dropDeskMentions(org.projectId, org.orgId, agentId, batch.at(-1)!.seq);+ }+}+// ---------------------------------------------------------------------------// Budgets// ---------------------------------------------------------------------------@@ -784,6 +924,7 @@ export async function reconcileOrg(const paused = pausedEmployees(deps, org, spend.period);await reconcileCalendar(deps, org, tickets, spend, paused, triggers);await reconcileTickets(deps, org, tickets);- await scanChannels(deps, org, spend, triggers);+ await scanChannels(deps, org, triggers);+ await deliverDeskMentions(deps, org, spend, triggers);return { org, tickets, spend };}diff --git a/packages/server/src/runtime/organization/service.ts b/packages/server/src/runtime/organization/service.tsindex ee82e79c..2a5601a2 100644--- a/packages/server/src/runtime/organization/service.ts+++ b/packages/server/src/runtime/organization/service.ts@@ -1016,8 +1016,10 @@ export class OrganizationService {delete org.desks[agentId];await this.deps.store.writeDesks(org.dir, org.desks);}- // Nothing will sweep for this employee again, so its queued ticket changes go with it.+ // Nothing will sweep for this employee again, so its queued ticket changes and its+ // waiting mentions go with it.this.deps.cache.deleteDeskNotices(projectId, orgId, agentId);+ this.deps.cache.deleteDeskMentions(projectId, orgId, agentId);for (const f of await this.deps.store.listCalendar(org.dir)) {if (f.agentId === agentId)await this.deps.store.deleteCalendarEvent(org.dir, agentId, f.name);diff --git a/packages/server/src/runtime/organization/triggers.ts b/packages/server/src/runtime/organization/triggers.tsindex f771c42a..aceac91c 100644--- a/packages/server/src/runtime/organization/triggers.ts+++ b/packages/server/src/runtime/organization/triggers.ts@@ -152,8 +152,9 @@ export type DispatchOutcome = "sent" | "queued" | "skipped";/*** Sends one work run to an employee's desk: opens the desk if needed, prefixes the block,- * queues behind a running Task (`queueIfBusy`: a busy desk never loses a trigger, it works- * it next), records the chain hop and notifies the Project's users.+ * queues behind a running Task (`queueIfBusy`: a busy desk works it next — for as long as this+ * process lives; mentions therefore wait in `org_desk_mentions` and come here only for an idle+ * desk), records the chain hop and notifies the Project's users.*/export async function dispatchToDesk(deps: OrgDeps,diff --git a/packages/server/test/db-migrations.test.ts b/packages/server/test/db-migrations.test.tsindex 87e923ae..40404990 100644--- a/packages/server/test/db-migrations.test.ts+++ b/packages/server/test/db-migrations.test.ts@@ -56,6 +56,7 @@ function dropCompanyModeTables(db: DatabaseSync): void {"org_channel_reads","org_budget_state","org_desk_notices",+ "org_desk_mentions",]) {db.exec(`DROP TABLE IF EXISTS ${table}`);}@@ -114,8 +115,9 @@ function open6(): DatabaseSync {db.exec("DROP TABLE IF EXISTS model_provider_auth_tokens");db.exec("DROP TABLE IF EXISTS model_promotions");db.exec(PRE_CHANNEL_CHAT_DDL);- // SCHEMA_SQL declares the CURRENT shape; migration 8's queue came after 6.+ // SCHEMA_SQL declares the CURRENT shape; migration 8's queue and migration 13's came after 6.db.exec("DROP TABLE IF EXISTS org_desk_notices");+ db.exec("DROP TABLE IF EXISTS org_desk_mentions");db.exec("PRAGMA user_version = 6");return db;}@@ -125,6 +127,7 @@ function open7(): DatabaseSync {const db = new sqlite.DatabaseSync(":memory:");db.exec(SCHEMA_SQL);db.exec("DROP TABLE IF EXISTS org_desk_notices");+ db.exec("DROP TABLE IF EXISTS org_desk_mentions");db.exec("DROP TABLE IF EXISTS model_provider_auth_tokens");db.exec("DROP TABLE IF EXISTS model_promotions");db.exec("PRAGMA user_version = 7");@@ -137,6 +140,7 @@ function open8(): DatabaseSync {db.exec(SCHEMA_SQL);db.exec("DROP TABLE IF EXISTS model_provider_auth_tokens");db.exec("DROP TABLE IF EXISTS model_promotions");+ db.exec("DROP TABLE IF EXISTS org_desk_mentions");db.exec("PRAGMA user_version = 8");return db;}@@ -146,10 +150,20 @@ function open9(): DatabaseSync {const db = new sqlite.DatabaseSync(":memory:");db.exec(SCHEMA_SQL);db.exec("DROP TABLE IF EXISTS model_provider_auth_tokens");+ db.exec("DROP TABLE IF EXISTS org_desk_mentions");db.exec("PRAGMA user_version = 9");return db;}+/** A database stamped at migration 12: everything the current declaration has but the desk-mention queue. */+function open12(): DatabaseSync {+ const db = new sqlite.DatabaseSync(":memory:");+ db.exec(SCHEMA_SQL);+ db.exec("DROP TABLE IF EXISTS org_desk_mentions");+ db.exec("PRAGMA user_version = 12");+ return db;+}+/** A 0.2.9 database: everything 0.2.4 had plus what versions 1 and 2 added, and still goal_state. */function open029(): DatabaseSync {const db = new sqlite.DatabaseSync(":memory:");@@ -185,13 +199,14 @@ function openPreProfile(): DatabaseSync {return db;}-/** Takes everything migrations 6–8 create off a database built from the current declaration. */+/** Takes everything migrations 6–8 and 13 create off a database built from the current declaration. */function dropCompanyTables(db: DatabaseSync): void {db.exec(`DROP INDEX IF EXISTS idx_org_desk_notices_agent;DROP INDEX IF EXISTS idx_org_ticket_sessions_session;DROP INDEX IF EXISTS idx_org_sessions_org;DROP TABLE IF EXISTS org_desk_notices;+ DROP TABLE IF EXISTS org_desk_mentions;DROP TABLE IF EXISTS org_budget_state;DROP TABLE IF EXISTS org_channel_reads;DROP TABLE IF EXISTS org_channel_state;@@ -574,8 +589,9 @@ describe("migration 8 → current: model-promotions", () => {"model-provider-auth-tokens","sessions-sandbox","machines-columns",+ "company-mode-desk-mentions",]);- expect(schemaVersion(db)).toBe(12);+ expect(schemaVersion(db)).toBe(13);expect(promotionsTableExists()).toEqual({ "1": 1 });expect(authTokensTableExists()).toEqual({ "1": 1 });@@ -596,8 +612,9 @@ describe("migration 8 → current: model-promotions", () => {"model-provider-auth-tokens","sessions-sandbox","machines-columns",+ "company-mode-desk-mentions",]);- expect(schemaVersion(db)).toBe(12);+ expect(schemaVersion(db)).toBe(13);} finally {db.close();}@@ -618,8 +635,9 @@ describe("migration 9 → current: model-provider-auth-tokens", () => {"model-provider-auth-tokens","sessions-sandbox","machines-columns",+ "company-mode-desk-mentions",]);- expect(schemaVersion(db)).toBe(12);+ expect(schemaVersion(db)).toBe(13);expect(tableExists()).toEqual({ "1": 1 });db.exec("INSERT INTO users (user_id, password_hash, is_admin, created_at)" +@@ -646,6 +664,58 @@ describe("migration 9 → current: model-provider-auth-tokens", () => {});});+describe("migration 12 → current: company-mode-desk-mentions", () => {+ /** A mention an employee's desk has not been handed yet, as the scan writes it. */+ const queue = (db: DatabaseSync, messageId: string, agentId = "acme_hr") =>+ db+ .prepare(+ "INSERT OR IGNORE INTO org_desk_mentions (project_id, org_id, agent_id, channel_id, date, message_id, hop)" ++ " VALUES ('p1', 'acme', ?, 'default_channel', '2026-10-06', ?, 0)",+ )+ .run(agentId, messageId);++ it("adds the queue a mention waits in, and the same message queues once per employee", () => {+ const db = open12();+ const fresh = new sqlite.DatabaseSync(":memory:");+ try {+ fresh.exec(SCHEMA_SQL);+ expect(shape(db)).not.toBe(shape(fresh));+ expect(migrate(db).applied).toEqual(["company-mode-desk-mentions"]);+ expect(schemaVersion(db)).toBe(LATEST_VERSION);+ expect(shape(db)).toBe(shape(fresh));+ queue(db, "msg-1");+ // A pass that dies before its offset moves reads the same line again: it must not queue twice.+ queue(db, "msg-1");+ queue(db, "msg-2");+ // A different employee waiting on the same message is a row of its own.+ queue(db, "msg-2", "acme_ceo");+ expect(db.prepare("SELECT message_id FROM org_desk_mentions ORDER BY seq").all()).toEqual([+ { message_id: "msg-1" },+ { message_id: "msg-2" },+ { message_id: "msg-2" },+ ]);+ } finally {+ db.close();+ fresh.close();+ }+ });++ it("down drops the queue with the mentions not delivered yet", () => {+ const db = open12();+ const at12 = open12();+ try {+ migrate(db);+ queue(db, "msg-1");+ rollbackTo(db, 12);+ expect(schemaVersion(db)).toBe(12);+ expect(shape(db)).toBe(shape(at12));+ } finally {+ db.close();+ at12.close();+ }+ });+});+describe("0.2.4 → current", () => {/** The whole point: an older runtime's database becomes what a current build creates. */it("brings a 0.2.4 database to the shape a fresh one is created with", () => {diff --git a/packages/server/test/organization-runtime.test.ts b/packages/server/test/organization-runtime.test.tsindex 1c9b48b7..00fac4b5 100644--- a/packages/server/test/organization-runtime.test.ts+++ b/packages/server/test/organization-runtime.test.ts@@ -30,6 +30,7 @@ import { zonedDate } from "../src/organization/zoned.js";import type { ErrorRecordArgs } from "../src/runtime/error-recorder.js";import { DEFAULT_EMPLOYEE_PLUGINS } from "../src/runtime/organization/deps.js";import type { OrgDeps } from "../src/runtime/organization/deps.js";+import { MENTIONS_PER_RUN } from "../src/runtime/organization/reconcile.js";import { OrganizationScheduler } from "../src/runtime/organization/scheduler.js";import { OrganizationService } from "../src/runtime/organization/service.js";import { ProjectConfigService } from "../src/services/project-config-service.js";@@ -2112,6 +2113,132 @@ describe("organization runtime", () => {});expect(started).toHaveLength(0);});++ const deskOf = (agentId: string): string =>+ cache.deskSessions(P, ORG).find((r) => r.agentId === agentId && r.current)!.sessionId;++ it("a busy desk collects its mentions and works them in one run once idle, the context once", async () => {+ const hrDesk = deskOf(HR);+ busy.add(hrDesk);+ const m1 = await service.sendChannelMessage(P, ORG, "alice", DEFAULT_CHANNEL_ID, {+ text: `@${HR} apply for a slot`,+ });+ await service.sendChannelMessage(P, ORG, "alice", DEFAULT_CHANNEL_ID, {+ text: "unrelated chatter",+ });+ const m3 = await service.sendChannelMessage(P, ORG, "alice", DEFAULT_CHANNEL_ID, {+ text: `@${HR} the field I forgot`,+ });+ // A busy desk gets nothing while it works, and the same message scanned again is not queued twice.+ await scheduler.tickOnce();+ expect(started).toHaveLength(0);+ expect(cache.agentsWithDeskMentions(P, ORG)).toEqual([HR]);++ busy.delete(hrDesk);+ await scheduler.tickOnce();+ expect(started).toHaveLength(1);+ expect(started[0]!.sessionId).toBe(hrDesk);+ const run = parseOrgTriggerMessage(started[0]!.text);+ expect(run?.origin).toMatchObject({+ kind: "mention",+ message: `${m1.id} from user:alice (+1 more)`,+ channel: DEFAULT_CHANNEL_ID,+ });+ expect(run?.rest).toContain("2 channel mentions are waiting for you");+ expect(run?.rest).toContain(`Message ${m1.id} from user:alice:\n@${HR} apply for a slot`);+ expect(run?.rest).toContain(`Message ${m3.id} from user:alice:\n@${HR} the field I forgot`);+ // A line between the two that named nobody is left to `channel tail`.+ expect(run?.rest).not.toContain("unrelated chatter");+ expect(run?.rest).toContain(`penguin org channel tail --channel ${DEFAULT_CHANNEL_ID}`);++ // Delivered is delivered: the next pass has nothing for the desk.+ await scheduler.tickOnce();+ expect(started).toHaveLength(1);+ });++ it("waiting mentions outlive the process, and the run carries the highest hop", async () => {+ const hrDesk = deskOf(HR);+ const ceoDesk = deskOf(CEO);+ busy.add(hrDesk);+ await service.sendChannelMessage(P, ORG, "alice", DEFAULT_CHANNEL_ID, {+ text: `@${HR} from a person`,+ });+ const fromCeo = await service.sendChannelMessage(P, ORG, "alice", DEFAULT_CHANNEL_ID, {+ text: `@${HR} from the CEO's desk`,+ sessionId: ceoDesk,+ });+ expect(fromCeo.hop).toBe(1);+ expect(started).toHaveLength(0);++ // A restart (or a hot update replacing the session manager) forgets every in-memory+ // follow-up; a fresh scheduler over the same database still has both mentions.+ const restarted = new OrganizationScheduler(deps, { intervalMs: 1_000_000 });+ busy.delete(hrDesk);+ await restarted.tickOnce();+ expect(started).toHaveLength(1);+ expect(parseOrgTriggerMessage(started[0]!.text)?.rest).toContain("from the CEO's desk");+ expect(cache.ownerOfSession(hrDesk)?.triggerHop).toBe(1);+ });++ it("a runner that refuses the run leaves the mentions waiting for the next pass", async () => {+ startFails = true;+ const m = await service.sendChannelMessage(P, ORG, "alice", DEFAULT_CHANNEL_ID, {+ text: `@${HR} are you there`,+ });+ expect(started).toHaveLength(0);+ expect(errors.some((e) => e.code === "org_dispatch_failed")).toBe(true);+ expect(cache.agentsWithDeskMentions(P, ORG)).toEqual([HR]);++ startFails = false;+ await scheduler.tickOnce();+ expect(started).toHaveLength(1);+ // Alone, it reads exactly as a mention always has.+ expect(parseOrgTriggerMessage(started[0]!.text)?.origin).toMatchObject({+ kind: "mention",+ message: `${m.id} from user:alice`,+ channel: DEFAULT_CHANNEL_ID,+ });+ });++ it("carries at most MENTIONS_PER_RUN per run and says more are waiting", async () => {+ const hrDesk = deskOf(HR);+ busy.add(hrDesk);+ const sent: string[] = [];+ for (let i = 0; i < MENTIONS_PER_RUN + 1; i++) {+ sent.push(+ (+ await service.sendChannelMessage(P, ORG, "alice", DEFAULT_CHANNEL_ID, {+ text: `@${HR} item ${i}`,+ })+ ).id,+ );+ }+ busy.delete(hrDesk);+ await scheduler.tickOnce();+ expect(started).toHaveLength(1);+ const first = parseOrgTriggerMessage(started[0]!.text);+ expect(first?.origin.message).toBe(+ `${sent[0]} from user:alice (+${MENTIONS_PER_RUN - 1} more)`,+ );+ expect(first?.rest).toContain("More mentions are still waiting");+ expect(first?.rest).not.toContain(`item ${MENTIONS_PER_RUN}`);++ await scheduler.tickOnce();+ expect(started).toHaveLength(2);+ expect(parseOrgTriggerMessage(started[1]!.text)?.origin.message).toBe(+ `${sent[MENTIONS_PER_RUN]} from user:alice`,+ );+ });++ it("an employee who leaves takes its waiting mentions along", async () => {+ busy.add(deskOf(HR));+ await service.sendChannelMessage(P, ORG, "alice", DEFAULT_CHANNEL_ID, {+ text: `@${HR} one last thing`,+ });+ expect(cache.agentsWithDeskMentions(P, ORG)).toEqual([HR]);+ await service.leave(P, ORG, HR);+ expect(cache.agentsWithDeskMentions(P, ORG)).toEqual([]);+ });});describe("channels", () => {diff --git a/plugins/agent-company/plugin.json b/plugins/agent-company/plugin.jsonindex 6f93cd0f..cddd2470 100644--- a/plugins/agent-company/plugin.json+++ b/plugins/agent-company/plugin.json@@ -3,7 +3,7 @@"description_zh": "把 Project 里的 Agent 组织成一家公司:先与用户一问一答地创建组织,再是每个工位会话与工单会话都遵循的员工协议(触发块、工单看板、频道礼仪、预算、重负载或不可逆的事先向董事会请示),以及 CEO、人事与财务的操作手册——使命拆解为工单、招募与日程、预算与成本巡检——还有科研协议(在董事会批准的资源额度内跑 autoresearch 式实验循环、作者与审稿人对抗评审),以及让数字分身在真人之间传话的镜像协议。","short_description": "Company setup plus the employee, CEO, HR, finance, research and mirror playbooks.","short_description_zh": "创建组织,以及员工、CEO、人事、财务、科研、镜像公司的操作手册。",- "version": "2026.09.18.1",+ "version": "2026.10.06.1","category": "agent-company","preinstall": false}diff --git a/plugins/agent-company/skills/company-employee/SKILL.md b/plugins/agent-company/skills/company-employee/SKILL.mdindex feb0a2c6..25cbae47 100644--- a/plugins/agent-company/skills/company-employee/SKILL.md+++ b/plugins/agent-company/skills/company-employee/SKILL.md@@ -51,7 +51,7 @@ budget: 12.40 / 30.00 USD (41%) # this period's spend (you + subordinates)- `init` — the first run of a new organization's CEO: the mission and the initialization tasks (see `company-ceo`).- `event` — a calendar event fired; the body is the event's `prompt`, followed by `## Since your last sweep` when ticket changes are waiting for you.-- `mention` — someone @-mentioned you in a channel; the body is that message plus up to 20 earlier messages of the same day **in that channel**, quoted. Answer where you were addressed — the `channel:` line names it: `penguin org channel send --channel <channel_id> -m "…"`.+- `mention` — someone @-mentioned you in a channel; the body is that message plus up to 20 earlier messages of the same day **in that channel**, quoted. Answer where you were addressed — the `channel:` line names it: `penguin org channel send --channel <channel_id> -m "…"`. Mentions that arrive while your desk is busy wait and reach you together in one `mention` run once it is idle: the body lists each one under its channel (`message:` names the first and how many more follow), so answer each in its own channel, and skip the ones you already handled during the run that kept you busy.- `ticket_work` — the first message of a ticket session: the ticket file in full (frontmatter and prose) plus the starter's note. Do the work.The first three arrive at your desk session; `ticket_work` opens a ticket session. A message with no block is a human talking to you directly — answer as in any conversation.