diff --git a/docs/plugins.md b/docs/plugins.md index d6c2228d6..61f21cd61 100644 --- a/docs/plugins.md +++ b/docs/plugins.md @@ -873,9 +873,10 @@ await paseo.agents.ref(agentId).timeline.append({ The daemon stamps the runtime `pluginId`; plugin code never supplies it. Reusing the same `id` replaces the previous row from that plugin on live clients and fresh timeline fetches. Rows live in the daemon's in-memory timeline and survive scroll, refetch, and reconnect, but not a daemon -restart. A row without an installed renderer shows an unavailable placeholder. Serialized `data` -must be at most 64 KiB; the daemon rejects a larger append instead of storing a payload that cannot -be rendered intact. The daemon advertises this RPC through +restart. A row without an installed renderer shows an unavailable placeholder. `kind` must match +`/^[a-z][a-z0-9-]*$/`, the rule `addTimelineRenderer` enforces; the daemon rejects any other kind. +Serialized `data` must be at most 64 KiB; the daemon rejects a larger append instead of storing a +payload that cannot be rendered intact. The daemon advertises this RPC through `server_info.features.pluginTimelineItems`. ## Contribute client slash commands diff --git a/packages/server/src/server/agent/agent-timeline-content.ts b/packages/server/src/server/agent/agent-timeline-content.ts index 5117073e1..4f9cc8f69 100644 --- a/packages/server/src/server/agent/agent-timeline-content.ts +++ b/packages/server/src/server/agent/agent-timeline-content.ts @@ -1,5 +1,6 @@ import type { AgentTimelineItem } from "./agent-sdk-types.js"; import type { JsonValue } from "@getpaseo/protocol/agent-types"; +import { PluginIdSchema } from "@getpaseo/protocol/plugin-config"; export const PLUGIN_TIMELINE_DATA_MAX_BYTES = 64 * 1024; @@ -14,6 +15,15 @@ const MARKER_COST = 32; const SHORT_STRING = 1024; const MAX_DEPTH = 64; +// The app registers renderer kinds under the plugin ID rule, so stored kinds must use that format. +export function assertPluginTimelineKind(kind: string): void { + if (!PluginIdSchema.safeParse(kind).success) { + throw new Error( + `Plugin timeline item kind must start with a lowercase letter and contain only lowercase letters, digits, and dashes: ${JSON.stringify(kind)}`, + ); + } +} + export function assertPluginTimelineDataSize(data: JsonValue): void { const serializedBytes = Buffer.byteLength(JSON.stringify(data), "utf8"); if (serializedBytes > PLUGIN_TIMELINE_DATA_MAX_BYTES) { diff --git a/packages/server/src/server/session.test.ts b/packages/server/src/server/session.test.ts index b2f8932b9..83ed76746 100644 --- a/packages/server/src/server/session.test.ts +++ b/packages/server/src/server/session.test.ts @@ -1660,6 +1660,37 @@ describe("plugin timeline append RPC", () => { }), ); }); + + test.each(["repro.card", "Review", "review_card", "1review", ""])( + "rejects the kind %j that no client renderer can register", + async (kind) => { + const messages: SessionOutboundMessage[] = []; + const appendTimelineItem = vi.fn(); + const session = createSessionForTest({ + clientId: "plugin:review", + messages, + agentManager: { appendTimelineItem }, + }); + + await session.handleMessage({ + type: "agent.timeline.append.request", + requestId: "append-kind", + agentId: "agent-1", + item: { type: "plugin", id: "review-1", kind, version: 1, data: {} }, + }); + + expect(appendTimelineItem).not.toHaveBeenCalled(); + expect(messages).toContainEqual({ + type: "rpc_error", + payload: { + requestId: "append-kind", + requestType: "agent.timeline.append.request", + error: `Request failed: Plugin timeline item kind must start with a lowercase letter and contain only lowercase letters, digits, and dashes: ${JSON.stringify(kind)}`, + code: "handler_error", + }, + }); + }, + ); }); describe("agent detach RPC", () => { diff --git a/packages/server/src/server/session.ts b/packages/server/src/server/session.ts index 231e98702..77f30ee0f 100644 --- a/packages/server/src/server/session.ts +++ b/packages/server/src/server/session.ts @@ -144,7 +144,10 @@ import { updateAgentCommand, } from "./agent/lifecycle-command.js"; import { buildStoredAgentPayload, toAgentPayload } from "./agent/agent-projections.js"; -import { assertPluginTimelineDataSize } from "./agent/agent-timeline-content.js"; +import { + assertPluginTimelineDataSize, + assertPluginTimelineKind, +} from "./agent/agent-timeline-content.js"; import { parsePluginClientId } from "./plugins/plugin-session-identity.js"; import { buildAgentForkContextAttachment } from "./agent/activity-curator.js"; import { buildAgentPrompt } from "./agent/prompt-attachments.js"; @@ -8504,6 +8507,7 @@ export class Session { ): Promise { const pluginId = parsePluginClientId(this.clientId); if (!pluginId) throw new Error("Only plugin sessions can append plugin timeline items"); + assertPluginTimelineKind(msg.item.kind); assertPluginTimelineDataSize(msg.item.data); const { seq, epoch } = await this.agentManager.appendTimelineItem(msg.agentId, { ...msg.item, diff --git a/public-docs/plugins/reference.md b/public-docs/plugins/reference.md index 7e9247d45..692313bc5 100644 --- a/public-docs/plugins/reference.md +++ b/public-docs/plugins/reference.md @@ -1279,9 +1279,12 @@ async function publishReview(agentId: string, { paseo }: PluginHandlerContext) { The daemon stamps `pluginId` from the calling plugin session and rejects this RPC from non-plugin sessions. The row appears live, survives timeline refetches, and keeps only the latest value for the -same plugin and `id`. If its renderer is missing, Paseo shows the existing unavailable row. Daemons -reject `data` over the limit rather than truncating it. Daemons that support this operation -advertise `server_info.features.pluginTimelineItems`. +same plugin and `id`. If its renderer is missing, Paseo shows the existing unavailable row. + +`kind` starts with a lowercase letter and contains lowercase letters, numbers, or hyphens, the same +rule `addTimelineRenderer` applies. Daemons reject any other `kind`. Daemons reject `data` over the +limit rather than truncating it. Daemons that support this operation advertise +`server_info.features.pluginTimelineItems`. ## Theme and layout diff --git a/public-docs/plugins/reference.zh-CN.md b/public-docs/plugins/reference.zh-CN.md index 05d34ac07..724ce623a 100644 --- a/public-docs/plugins/reference.zh-CN.md +++ b/public-docs/plugins/reference.zh-CN.md @@ -1060,7 +1060,9 @@ async function publishReview(agentId: string, { paseo }: PluginHandlerContext) { | `version` | 正整数 | 是 | 选择渲染器契约的版本。 | | `data` | 兼容 JSON | 是 | 渲染器负载,JSON 序列化后最多 64 KiB。 | -daemon 会根据发起调用的插件会话写入 `pluginId`,并拒绝来自非插件会话的此 RPC。该行会实时出现,在时间线重新获取后依然保留,并且对于同一插件和 `id` 只保留最新的值。如果它的渲染器缺失,Paseo 会显示现有的“不可用”行。daemon 会拒绝超过限制的 `data`,而不是截断它。支持此操作的 daemon 会声明 `server_info.features.pluginTimelineItems`。 +daemon 会根据发起调用的插件会话写入 `pluginId`,并拒绝来自非插件会话的此 RPC。该行会实时出现,在时间线重新获取后依然保留,并且对于同一插件和 `id` 只保留最新的值。如果它的渲染器缺失,Paseo 会显示现有的“不可用”行。 + +`kind` 以小写字母开头,只包含小写字母、数字或连字符,与 `addTimelineRenderer` 使用的规则相同。daemon 会拒绝其他任何 `kind`。daemon 会拒绝超过限制的 `data`,而不是截断它。支持此操作的 daemon 会声明 `server_info.features.pluginTimelineItems`。 ## 主题与布局 {#theme-and-layout}