@khorsheed/dsh-room 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/CHANGELOG.md +18 -2
  2. package/README.en.md +84 -0
  3. package/README.i18n.yaml +3 -3
  4. package/README.md +62 -26
  5. package/lib/client.js +952 -285
  6. package/lib/index.js +88 -12
  7. package/lib/{journal-CuRnWk66.js → journal-BWL3-i0s.js} +27 -0
  8. package/lib/tool.js +63 -11
  9. package/lib/typert.host.js +184 -37
  10. package/lib/typert.remote-client.d.ts +2 -0
  11. package/lib/typert.remote-client.js +151 -31
  12. package/lib/types/client/RoomActivityDock.d.ts +19 -0
  13. package/lib/types/client/RoomActivityDock.js +105 -0
  14. package/lib/types/client/RoomComposer.d.ts +1 -1
  15. package/lib/types/client/RoomComposer.js +3 -3
  16. package/lib/types/client/RoomPlanTab.d.ts +15 -0
  17. package/lib/types/client/RoomPlanTab.js +13 -0
  18. package/lib/types/client/RoomPlanView.d.ts +3 -2
  19. package/lib/types/client/RoomPlanView.js +5 -6
  20. package/lib/types/client/executions.d.ts +50 -0
  21. package/lib/types/client/executions.js +70 -0
  22. package/lib/types/client/index.d.ts +1 -1
  23. package/lib/types/client/index.js +33 -1
  24. package/lib/types/client/locales.d.ts +50 -0
  25. package/lib/types/client/locales.js +50 -0
  26. package/lib/types/client/preset-visibility.d.ts +3 -3
  27. package/lib/types/client/preset-visibility.js +2 -2
  28. package/lib/types/client/slots.d.ts +6 -1
  29. package/lib/types/dispatch.js +30 -6
  30. package/lib/types/index.d.ts +5 -0
  31. package/lib/types/index.js +42 -7
  32. package/lib/types/journal.d.ts +1 -1
  33. package/lib/types/journal.js +27 -1
  34. package/lib/types/tool-definition.d.ts +56 -0
  35. package/lib/types/tool-definition.js +393 -0
  36. package/lib/types/tool.d.ts +37 -49
  37. package/lib/types/tool.js +47 -381
  38. package/lib/types/types.d.ts +28 -0
  39. package/package.json +10 -9
  40. package/README.zh.md +0 -48
@@ -1,56 +1,44 @@
1
- import type { RoomAddTaskRequest, RoomAddTaskResult, RoomCloseTaskRequest, RoomCloseTaskResult, RoomGetStateRequest, RoomGetStateResult, RoomInviteRequest, RoomInviteResult, RoomMessageRequest, RoomMessageResult, RoomUpdateTaskRequest, RoomUpdateTaskResult } from './types.ts';
2
- /** The slice of RoomService the tool drives. */
3
- export interface RoomInviteToolBackend {
4
- /** Validate and journal an invitation (see RoomService.inviteMember). */
5
- inviteMember(request: RoomInviteRequest, invitedBy: 'human' | 'agent'): Promise<RoomInviteResult>;
6
- }
7
1
  /**
8
- * Build the room_invite tool definition bound to the room service.
9
- * @param backend - the room service.
10
- * @returns a registry-ready tool definition.
2
+ * The session-granted room model tools — this package's `./tool` composition
3
+ * entry (the canvas `./agent` pattern) for agent-preset compositions. The row
4
+ * provides NO service (the preset-mount isolate-realm rule forbids service
5
+ * rows), it only registers the model-facing `room_invite` / `room_task` /
6
+ * `room_message` tools into the host tools registry, delegating to the global
7
+ * `ctx.room` service the main row provides at the profile root — the official
8
+ * tool-row shape (the shipped `tool-bash` rows work the same way). Granting
9
+ * is therefore per-session: a preset names the row, its sessions get the
10
+ * tools; every other preset's sessions do not.
11
+ *
12
+ * This entry used to ship as the standalone companion package
13
+ * `@khorsheed/dsh-room-tool` (0.1.x); 0.2.0 folded it back into the core
14
+ * package as this subpath row (the loader mounts a package's non-default
15
+ * export fine — the canvas `./agent` precedent), and the old package name is
16
+ * deprecated on npm. An agent preset's `agent.cordis.yml` references the row
17
+ * by name: `- id: room-tool / name: '@khorsheed/dsh-room/tool'`.
18
+ * The package's own bundle patch mounts ONLY the core row — a profile-root
19
+ * tool row would grant every session, exactly what the split removed.
20
+ *
21
+ * @module @khorsheed/dsh-room/tool
11
22
  */
12
- export declare function roomInviteTool(backend: RoomInviteToolBackend): import("@deepseek-ai/dsh-tools").ToolDefinition;
13
- /** The slice of RoomService the room_task tool drives. */
14
- export interface RoomTaskToolBackend {
15
- /** Open a pending task on a member's lane (see RoomService.addTask). */
16
- addTask(request: RoomAddTaskRequest): Promise<RoomAddTaskResult>;
17
- /** Close an open task (see RoomService.closeTask). */
18
- closeTask(request: RoomCloseTaskRequest): Promise<RoomCloseTaskResult>;
19
- /** Edit an open task's title/blockedBy (see RoomService.updateTask). */
20
- updateTask(request: RoomUpdateTaskRequest): Promise<RoomUpdateTaskResult>;
21
- /** Replay the room state (the error texts read the roster/open tasks from it). */
22
- getState(request: RoomGetStateRequest): Promise<RoomGetStateResult>;
23
- }
23
+ import type { Context } from '@deepseek-ai/cordis';
24
+ /** Cordis plugin name used by loader diagnostics. */
25
+ export declare const name = "room-tool";
24
26
  /**
25
- * Build the room_task tool definition bound to the room service. Every write
26
- * goes through the same host functions as the capsule UI, so a task the agent
27
- * opens is a public commitment indistinguishable from a human-added one.
28
- * @param backend - the room service.
29
- * @returns a registry-ready tool definition.
27
+ * The `room` core is a declared inject (the owning-family companion
28
+ * exception to the community-service probe rule): a preset's standing scope
29
+ * mounts at registry-activation time, BEFORE the profile's later bundle rows
30
+ * provide the core, so a one-shot ctx.get probe at apply saw ABSENT there and
31
+ * nothing re-ran the row (rc.1 boot order; 3080 production 2026-09-27). The
32
+ * declared inject pends the row until the core provides, then the body
33
+ * applies. The tools registry still joins through deferred injection so its
34
+ * mount order cannot strand the registrations.
30
35
  */
31
- export declare function roomTaskTool(backend: RoomTaskToolBackend): import("@deepseek-ai/dsh-tools").ToolDefinition;
32
- /** The slice of RoomService the room_message tool drives. */
33
- export interface RoomMessageToolBackend {
34
- /** Dispatch one message to one member (see RoomService.messageMember). */
35
- messageMember(request: RoomMessageRequest): Promise<RoomMessageResult>;
36
- /** Replay the room state (the error text reads the live roster from it). */
37
- getState(request: RoomGetStateRequest): Promise<RoomGetStateResult>;
38
- }
36
+ export declare const inject: string[];
39
37
  /**
40
- * Build the room_message tool definition bound to the room service: the main
41
- * agent's way to hand a member a message/task — the model-facing equivalent
42
- * of the human's `@member text`, minus the user bubble (the caller is the
43
- * room's own agent, not the human).
44
- * @param backend - the room service.
45
- * @returns a registry-ready tool definition.
38
+ * Plugin body: register the room tools. The declared `room` inject pends the
39
+ * row until the core provides, so mount order can no longer strand it; the
40
+ * in-body guard stays as the defensive direct-call path.
41
+ * @param ctx - Cordis context (the preset's agent-plane mount).
46
42
  */
47
- export declare function roomMessageTool(backend: RoomMessageToolBackend): import("@deepseek-ai/dsh-tools").ToolDefinition;
48
- /** Native room tools use the same bounded context reader as the external MCP bridge. */
49
- export declare function roomReadTool(backend: {
50
- readRoomContext(sessionId: string): Promise<string>;
51
- }): import("@deepseek-ai/dsh-tools").ToolDefinition;
52
- /** Formal planning uses the same strict command grammar exposed by room_read. */
53
- export declare function roomPlanTool(backend: {
54
- commandPlan(sessionId: string, command: string): Promise<string>;
55
- }): import("@deepseek-ai/dsh-tools").ToolDefinition;
43
+ export declare function apply(ctx: Context): void;
56
44
  //# sourceMappingURL=tool.d.ts.map
package/lib/types/tool.js CHANGED
@@ -1,389 +1,55 @@
1
+ import { roomInviteTool, roomMessageTool, roomTaskTool, roomReadTool, roomPlanTool } from './tool-definition.js';
2
+ const PACKAGE_NAME = '@khorsheed/dsh-room';
1
3
  /**
2
- * The room's model-facing tool DEFINITIONS, `room_invite`, `room_task`, and
3
- * `room_message`: the main
4
- * agent's paths into the room it belongs to. `room_invite` and
5
- * `room_message` PROMOTE: calling them in a plain session turns it into a
6
- * room (ensureRoom) instead of rejecting. `room_task` stays gated at execute
7
- * time — the calling agent's session must be a room (the journal carries
8
- * `room/created`); anywhere else the tool answers with readable error text
9
- * instead of throwing, so the model can see the rejection and self-correct.
10
- * `room_invite` lands in the same invite path as the human dialog
11
- * (`invitedBy: 'agent'`), producing an identical member record; `room_task`
12
- * writes the SHARED task board through the very host functions the capsule UI
13
- * uses (addTask/closeTask, plus the tool-only updateTask), so an agent-written
14
- * task is indistinguishable from a human-added one; `room_message` dispatches
15
- * a message to a member through the same engine path as the human's
16
- * `@member text`, minus the user bubble (the caller is the room's own agent).
17
- *
18
- * Since the tool-row split (M4') the core no longer REGISTERS these tools:
19
- * the factories are consumed by the companion `@khorsheed/dsh-room-tool`,
20
- * which mounts the tool row inside agent-preset compositions (session-granted,
21
- * never at the profile root). The definitions are therefore returned
22
- * UNTAGGED — the registering package applies its own tool-origin tag
23
- * (AGENTS.md § Tool origin tagging — the owner is whichever package mounts
24
- * the row).
25
- * @module @khorsheed/dsh-room/tool
4
+ * Tag the model-visible tools with their origin (AGENTS.md § Tool origin
5
+ * tagging; seam S12): the capability catalog reads this `Symbol.for`-keyed
6
+ * tag back through `ctx.tools.get()`, so the room tools attribute to THIS
7
+ * package (the row the preset mounts), not to the service core. The tag is
8
+ * host-side only and never travels on the model wire. Generic form (not
9
+ * `typeof defineTool`, which trips typert TS2321).
26
10
  */
27
- import { defineTool } from '@deepseek-ai/dsh-tools';
28
- import { coordinatorMember, isRoomLog } from './journal.js';
11
+ const definePluginTool = (def) => Object.assign(def, {
12
+ [Symbol.for('dsh.tool.origin')]: { channel: 'plugin', owner: PACKAGE_NAME },
13
+ });
14
+ /** Cordis plugin name used by loader diagnostics. */
15
+ export const name = 'room-tool';
29
16
  /**
30
- * Build the room_invite tool definition bound to the room service.
31
- * @param backend - the room service.
32
- * @returns a registry-ready tool definition.
17
+ * The `room` core is a declared inject (the owning-family companion
18
+ * exception to the community-service probe rule): a preset's standing scope
19
+ * mounts at registry-activation time, BEFORE the profile's later bundle rows
20
+ * provide the core, so a one-shot ctx.get probe at apply saw ABSENT there and
21
+ * nothing re-ran the row (rc.1 boot order; 3080 production 2026-09-27). The
22
+ * declared inject pends the row until the core provides, then the body
23
+ * applies. The tools registry still joins through deferred injection so its
24
+ * mount order cannot strand the registrations.
33
25
  */
34
- export function roomInviteTool(backend) {
35
- return defineTool({
36
- name: 'room_invite',
37
- description: 'Invite a CLI agent member into the current session (any session works — inviting promotes it '
38
- + 'into a room: the multi-agent group conversation surface wakes up on it). '
39
- + 'The member becomes @-addressable by the human and by other members: pick a short unique '
40
- + 'name (no whitespace, no "@", e.g. ada/bill/cathy) — it is the addressing name, decoupled '
41
- + 'from the provider so two instances of one provider can coexist; prefer a function-style '
42
- + 'name (e.g. design-review / restart-test) when the member has a standing role, so the human '
43
- + 'and the other members can tell what it is for. The instructions are the '
44
- + 'member\'s role briefing, prepended to its first dispatch and persisted in its own CLI '
45
- + 'session from then on. Give a firstTask to put the member to work immediately, or omit it '
46
- + 'to have the member join idle. A member keeps its own CLI session and accumulates context '
47
- + 'across rounds, so prefer inviting over a one-shot subagent_* delegation whenever the work '
48
- + 'expects follow-ups with the same agent — reserve one-shot delegations for self-contained '
49
- + 'tasks with no continuation. The provider must be a registered delegation provider id — '
50
- + 'an unknown one is rejected with the list of available ids, so retry with one of those.',
51
- parameters: {
52
- provider: {
53
- type: 'string',
54
- required: true,
55
- description: 'The local-agent delegation provider id (e.g. kimi-cli / codex-cli / claude-code) — the '
56
- + 'delegation id the family registered, which may differ from the harness\'s display '
57
- + 'name. When unsure, call without firstTask first: an unknown id is rejected with the '
58
- + 'list of available providers to retry with.',
59
- },
60
- name: {
61
- type: 'string',
62
- required: true,
63
- description: 'The member\'s @-addressing name: unique in this room, no whitespace, no "@".',
64
- },
65
- instructions: {
66
- type: 'string',
67
- required: true,
68
- description: 'The member\'s role instructions (responsibilities, constraints, output expectations).',
69
- },
70
- firstTask: {
71
- type: 'string',
72
- description: 'Optional first task, dispatched to the member as soon as it joins.',
73
- },
74
- cwd: {
75
- type: 'string',
76
- description: 'Optional working directory for the member (empty: inherits the room session\'s cwd).',
77
- },
78
- },
79
- output: {
80
- schema: {
81
- type: 'object',
82
- additionalProperties: false,
83
- properties: {
84
- text: { type: 'string', required: true },
85
- },
86
- },
87
- render: (_args, value) => [{ type: 'text', text: value.text }],
88
- },
89
- // Invitations mutate only the room journal; two invites never conflict
90
- // beyond a duplicate name, which the result text reports back.
91
- isConcurrencySafe: () => true,
92
- async execute(args, exec) {
93
- const agent = exec.agent;
94
- if (agent === undefined)
95
- return { text: 'room_invite requires a calling agent (exec.agent was undefined).' };
96
- // No room gate: inviteMember PROMOTES the calling session into a room.
97
- const result = await backend.inviteMember({
98
- sessionId: agent.session.id,
99
- provider: args.provider,
100
- name: args.name,
101
- instructions: args.instructions,
102
- ...args.firstTask === undefined ? {} : { firstTask: args.firstTask },
103
- ...args.cwd === undefined ? {} : { cwd: args.cwd },
104
- }, 'agent');
105
- if (!result.ok) {
106
- const hint = result.error.code === 'duplicate-name'
107
- ? ' Pick a different name and retry.'
108
- : result.error.code === 'invalid-name'
109
- ? ' Names must be non-empty and free of whitespace and "@"; retry with a valid name.'
110
- : result.error.code === 'local-agent-unavailable'
111
- ? ' The local-agent delegation facade is not mounted; CLI members cannot join right now.'
112
- : result.error.code === 'unknown-provider'
113
- ? ` Unknown delegation provider "${result.error.provider}" (it must be the family's delegation provider id, not the harness's display name). Available: ${result.error.available.length === 0
114
- ? 'none (no harness with a delegation provider is registered)'
115
- : result.error.available.join(', ')}. Retry with one of the available providers.`
116
- : '';
117
- return { text: `Could not invite "${args.name}": ${result.error.code}.${hint}` };
118
- }
119
- return {
120
- text: result.value.pendingFirstTask
121
- ? `Member ${result.value.name} joined the room and its first task was dispatched.`
122
- : `Member ${result.value.name} joined the room (idle; @-address it to dispatch work).`,
123
- };
124
- },
125
- });
126
- }
127
- /**
128
- * Build the room_task tool definition bound to the room service. Every write
129
- * goes through the same host functions as the capsule UI, so a task the agent
130
- * opens is a public commitment indistinguishable from a human-added one.
131
- * @param backend - the room service.
132
- * @returns a registry-ready tool definition.
133
- */
134
- export function roomTaskTool(backend) {
135
- return defineTool({
136
- name: 'room_task',
137
- description: 'Manage the current room\'s SHARED task board (only usable inside a room session). This '
138
- + 'board is public — every room member and the human sees these tasks, so writing here is '
139
- + 'a public commitment the room coordinates around; for your private work plan use your own '
140
- + 'todo tool instead. Actions: "add" (title + member — the roster name owning the task, '
141
- + 'use room_read to find your own or another member\'s name; optional blockedBy names the member the task waits '
142
- + 'on, display only) opens a pending task and returns its id; "close" (taskId) marks an '
143
- + 'open task done; "update" (taskId + a new title and/or blockedBy — null clears the wait) '
144
- + 'edits an open task. Errors answer with the roster or the open-task list so you can retry '
145
- + 'with a valid member name or task id.',
146
- parameters: {
147
- action: {
148
- type: 'string',
149
- enum: ['add', 'close', 'update'],
150
- required: true,
151
- description: 'add: open a task (title + member). close: mark a task done (taskId). update: edit title/blockedBy (taskId).',
152
- },
153
- title: {
154
- type: 'string',
155
- description: 'Task title. Required for add; optional new title for update.',
156
- },
157
- member: {
158
- type: 'string',
159
- description: 'The roster name owning the task (required for add; read room_read for current names).',
160
- },
161
- taskId: {
162
- type: 'string',
163
- description: 'The task id (required for close/update; add\'s success text returns the new id).',
164
- },
165
- blockedBy: {
166
- oneOf: [{ type: 'string' }, { type: 'null' }],
167
- description: 'The member this task waits on (must be on the roster; display only, never an automatic '
168
- + 'dispatch). Optional on add; on update, a string re-targets the wait and null clears it.',
169
- },
170
- },
171
- output: {
172
- schema: {
173
- type: 'object',
174
- additionalProperties: false,
175
- properties: {
176
- text: { type: 'string', required: true },
177
- },
178
- },
179
- render: (_args, value) => [{ type: 'text', text: value.text }],
180
- },
181
- // Board writes mutate only the room journal; two writes never conflict
182
- // beyond the validations the result text reports back.
183
- isConcurrencySafe: () => true,
184
- async execute(args, exec) {
185
- const agent = exec.agent;
186
- if (agent === undefined)
187
- return { text: 'room_task requires a calling agent (exec.agent was undefined).' };
188
- if (!isRoomLog(agent.session.snapshotEvents())) {
189
- return { text: 'The current session is not a room; room_task is only usable inside a room session.' };
190
- }
191
- const sessionId = agent.session.id;
192
- const ownership = await backend.getState({ sessionId });
193
- if (ownership.ok && coordinatorMember(ownership.value)?.kind !== 'main-agent')
194
- return { text: 'Only the current coordinator may manage the shared room task board.' };
195
- /** The self-correcting roster suffix: the legal member names, for member-not-found. */
196
- const rosterHint = async () => {
197
- const state = await backend.getState({ sessionId });
198
- if (!state.ok)
199
- return '';
200
- const names = state.value.members.map(member => member.name);
201
- return names.length === 0 ? '' : ` The room roster is: ${names.join(', ')}. Retry with one of these names.`;
202
- };
203
- /** The self-correcting board suffix: the open tasks (id — title), for task-not-found. */
204
- const openTasksHint = async () => {
205
- const state = await backend.getState({ sessionId });
206
- if (!state.ok)
207
- return '';
208
- const open = state.value.tasks.filter(task => task.status === 'pending' || task.status === 'in_progress');
209
- if (open.length === 0)
210
- return ' The board has no open tasks right now.';
211
- return ` Open tasks: ${open.map(task => `${task.id} — "${task.title}" (${task.member}, ${task.status})`).join('; ')}. Retry with one of these ids.`;
212
- };
213
- const failureText = async (code) => {
214
- switch (code) {
215
- case 'member-not-found':
216
- return `Unknown member.${await rosterHint()}`;
217
- case 'empty-text':
218
- return 'The title must be non-blank; retry with a real title.';
219
- case 'task-not-found':
220
- return `No task with that id.${await openTasksHint()}`;
221
- case 'task-closed':
222
- return 'That task is already closed (done/cancelled); closed tasks take no further changes.';
223
- case 'nothing-to-update':
224
- return 'update needs at least one field to change: a new title and/or blockedBy (null clears the wait).';
225
- default:
226
- return `The room rejected the write (${code}).`;
227
- }
228
- };
229
- switch (args.action) {
230
- case 'add': {
231
- if (args.title === undefined || args.member === undefined) {
232
- return { text: 'room_task add requires both title and member (the roster name owning the task; read room_read for current names).' };
233
- }
234
- if (args.blockedBy === null) {
235
- return { text: 'add takes no null blockedBy — simply omit blockedBy for an unblocked task.' };
236
- }
237
- const result = await backend.addTask({
238
- sessionId,
239
- member: args.member,
240
- title: args.title,
241
- ...args.blockedBy === undefined ? {} : { blockedBy: args.blockedBy },
242
- });
243
- if (!result.ok)
244
- return { text: `Could not add the task: ${result.error.code}. ${await failureText(result.error.code)}` };
245
- return {
246
- text: `Task "${args.title}" is now on ${args.member}'s lane of the shared room board `
247
- + `(id: ${result.value.id}) — visible to every member and the human. `
248
- + 'Keep the id to update or close the task later.',
249
- };
250
- }
251
- case 'close': {
252
- if (args.taskId === undefined) {
253
- return { text: `room_task close requires taskId.${await openTasksHint()}` };
254
- }
255
- const result = await backend.closeTask({ sessionId, taskId: args.taskId });
256
- if (!result.ok)
257
- return { text: `Could not close the task: ${result.error.code}. ${await failureText(result.error.code)}` };
258
- return { text: `Task ${result.value.id} is done — the shared board shows it closed.` };
259
- }
260
- case 'update': {
261
- if (args.taskId === undefined) {
262
- return { text: `room_task update requires taskId.${await openTasksHint()}` };
263
- }
264
- const result = await backend.updateTask({
265
- sessionId,
266
- taskId: args.taskId,
267
- ...args.title === undefined ? {} : { title: args.title },
268
- ...args.blockedBy === undefined ? {} : { blockedBy: args.blockedBy },
269
- });
270
- if (!result.ok)
271
- return { text: `Could not update the task: ${result.error.code}. ${await failureText(result.error.code)}` };
272
- return { text: `Task ${result.value.id} updated on the shared room board.` };
273
- }
274
- }
275
- },
276
- });
277
- }
26
+ export const inject = ['room'];
278
27
  /**
279
- * Build the room_message tool definition bound to the room service: the main
280
- * agent's way to hand a member a message/task — the model-facing equivalent
281
- * of the human's `@member text`, minus the user bubble (the caller is the
282
- * room's own agent, not the human).
283
- * @param backend - the room service.
284
- * @returns a registry-ready tool definition.
28
+ * Plugin body: register the room tools. The declared `room` inject pends the
29
+ * row until the core provides, so mount order can no longer strand it; the
30
+ * in-body guard stays as the defensive direct-call path.
31
+ * @param ctx - Cordis context (the preset's agent-plane mount).
285
32
  */
286
- export function roomMessageTool(backend) {
287
- return defineTool({
288
- name: 'room_message',
289
- description: 'Dispatch a message to a member of the current room (works in any session — it promotes the '
290
- + 'session into a room if it is not one yet). '
291
- + 'A member is an independent CLI session: the message runs asynchronously, and the member\'s '
292
- + 'reply appears in the room as member speech (the human sees it; you read it through the '
293
- + 'room\'s flow). Use this to ask a member something or hand it work — the equivalent of the '
294
- + 'human typing "@member <text>" in the room composer. The member argument is a roster name '
295
- + '(read room_read for current names); an unknown name is rejected with the live roster, so retry with one '
296
- + 'of those.',
297
- parameters: {
298
- member: {
299
- type: 'string',
300
- required: true,
301
- description: 'The addressee\'s roster name (read room_read for current names; new rooms name the native member "dsh").',
302
- },
303
- text: {
304
- type: 'string',
305
- required: true,
306
- description: 'The message text the member receives as its task.',
307
- },
308
- },
309
- output: {
310
- schema: {
311
- type: 'object',
312
- additionalProperties: false,
313
- properties: {
314
- text: { type: 'string', required: true },
315
- },
316
- },
317
- render: (_args, value) => [{ type: 'text', text: value.text }],
318
- },
319
- // A dispatch mutates only the room journal; two messages never conflict
320
- // beyond the roster validation the result text reports back.
321
- isConcurrencySafe: () => true,
322
- async execute(args, exec) {
323
- const agent = exec.agent;
324
- if (agent === undefined)
325
- return { text: 'room_message requires a calling agent (exec.agent was undefined).' };
326
- // No room gate: messageMember PROMOTES the calling session into a room.
327
- const sessionId = agent.session.id;
328
- const result = await backend.messageMember({ sessionId, member: args.member, text: args.text });
329
- if (!result.ok) {
330
- if (result.error.code === 'member-not-found') {
331
- const state = await backend.getState({ sessionId });
332
- const names = state.ok ? state.value.members.map(member => member.name) : [];
333
- const hint = names.length === 0 ? '' : ` The room roster is: ${names.join(', ')}. Retry with one of these names.`;
334
- return { text: `Could not message "${args.member}": unknown member.${hint}` };
335
- }
336
- if (result.error.code === 'empty-text') {
337
- return { text: 'The message text must be non-blank; retry with real content.' };
338
- }
339
- return { text: `Could not message "${args.member}": ${result.error.code}.` };
340
- }
341
- return {
342
- text: `Dispatched to ${result.value.member} — the member runs it asynchronously and its reply `
343
- + 'appears in the room as member speech. Do not wait on it; the human watches the room.',
344
- };
345
- },
346
- });
347
- }
348
- /** Native room tools use the same bounded context reader as the external MCP bridge. */
349
- export function roomReadTool(backend) {
350
- return defineTool({
351
- name: 'room_read',
352
- description: 'Read the current room roster, coordinator, deliveries, recent outcomes and available harness providers. Reading does not wake any member.',
353
- parameters: {},
354
- output: { schema: { type: 'object', additionalProperties: false, properties: { text: { type: 'string', required: true } } },
355
- render: (_args, value) => [{ type: 'text', text: value.text }] },
356
- isConcurrencySafe: () => true,
357
- async execute(_args, exec) {
358
- if (exec.agent === undefined)
359
- return { text: 'room_read requires a calling agent.' };
360
- try {
361
- return { text: await backend.readRoomContext(exec.agent.session.id) };
362
- }
363
- catch (error) {
364
- return { text: String(error) };
365
- }
366
- },
367
- });
368
- }
369
- /** Formal planning uses the same strict command grammar exposed by room_read. */
370
- export function roomPlanTool(backend) {
371
- return defineTool({
372
- name: 'room_plan',
373
- description: 'Organize a requested goal into stages and dependent tasks, submit evidence, review/rework results, and pause/resume. Read room_read for current plan and planCommands JSON schema. Ordinary small tasks use room_message without a formal goal. A native run finishing only submits a result; acceptance requires evidence review.',
374
- parameters: { command: { type: 'string', required: true, description: 'JSON command matching room_read planCommands: action, requestId, expectedRevision and action fields. Create mode execute is for authorized execution; draft saves a proposal without dispatch.' } },
375
- output: { schema: { type: 'object', additionalProperties: false, properties: { text: { type: 'string', required: true } } },
376
- render: (_args, value) => [{ type: 'text', text: value.text }] },
377
- isConcurrencySafe: () => true,
378
- async execute(args, exec) {
379
- if (exec.agent === undefined)
380
- return { text: 'room_plan requires a calling agent.' };
381
- try {
382
- return { text: await backend.commandPlan(exec.agent.session.id, args.command) };
383
- }
384
- catch (error) {
385
- return { text: String(error) };
386
- }
387
- },
33
+ export function apply(ctx) {
34
+ const service = ctx.get('room');
35
+ if (service === undefined) {
36
+ // Degrade, don't explode: the core plugin is not mounted in this
37
+ // profile, so there is nothing to delegate to. The room UI is the
38
+ // core's own concern and unaffected; only the model tools stay absent.
39
+ ctx.logger.info(`${name}: the global room service is absent — the room tools are not registered`);
40
+ return;
41
+ }
42
+ // Deferred injection, NOT an apply-time probe: `ctx.get('tools')` races the
43
+ // tools registry's own mount order on the real composition tree and loses,
44
+ // silently never registering the tools. `ctx.inject` fires when the
45
+ // registry appears and never fires in a composition without one.
46
+ ctx.inject(['tools'], (toolsCtx) => {
47
+ if (typeof service.commandPlan === 'function')
48
+ toolsCtx.effect(() => toolsCtx.tools.register(definePluginTool(roomPlanTool(service))), 'room-tool: room_plan tool');
49
+ if (typeof service.readRoomContext === 'function')
50
+ toolsCtx.effect(() => toolsCtx.tools.register(definePluginTool(roomReadTool(service))), 'room-tool: room_read tool');
51
+ toolsCtx.effect(() => toolsCtx.tools.register(definePluginTool(roomInviteTool(service))), 'room-tool: room_invite tool');
52
+ toolsCtx.effect(() => toolsCtx.tools.register(definePluginTool(roomTaskTool(service))), 'room-tool: room_task tool');
53
+ toolsCtx.effect(() => toolsCtx.tools.register(definePluginTool(roomMessageTool(service))), 'room-tool: room_message tool');
388
54
  });
389
55
  }
@@ -137,8 +137,20 @@ export interface RoomSpeechEvent {
137
137
  /** Native admission→settle milliseconds, excluding queue time. */
138
138
  readonly durationMs?: number;
139
139
  }
140
+ /** Observed execution metadata; separate from lifecycle edges to avoid restarting chat nodes. */
141
+ export interface RoomExecutionMetadataEvent {
142
+ readonly runId: string;
143
+ readonly model?: string;
144
+ readonly effort?: string;
145
+ readonly tokens?: number;
146
+ }
140
147
  /** A member run's lifecycle edge. */
141
148
  export interface RoomRunStateEvent {
149
+ readonly childSessionId?: SessionId;
150
+ /** Observed round metadata, never a requested-model guess or session total. */
151
+ readonly model?: string;
152
+ readonly effort?: string;
153
+ readonly tokens?: number;
142
154
  /** Stable execution identity; legacy journals use startedAt. */
143
155
  readonly runId?: string;
144
156
  readonly member: string;
@@ -244,6 +256,8 @@ declare module '@deepseek-ai/dsh-session/types' {
244
256
  'room/speech': RoomSpeechEvent;
245
257
  /** Member run lifecycle. */
246
258
  'room/run-state': RoomRunStateEvent;
259
+ /** Log-only observed metadata for a single execution. */
260
+ 'room/execution-metadata': RoomExecutionMetadataEvent;
247
261
  /** Notification gate: a member-to-member relay arrived (pending). */
248
262
  'room/relay': RoomRelayEvent;
249
263
  /** Notification gate: a relay was confirmed, dismissed, or delivered. */
@@ -308,6 +322,16 @@ export interface RoomMemberRun {
308
322
  /** Why the run failed (failed edges only), when the edge carried one. */
309
323
  readonly error?: string;
310
324
  }
325
+ /** Durable per-execution history; unlike runs this retains earlier member rounds. */
326
+ export interface RoomExecution extends RoomMemberRun {
327
+ readonly id: string;
328
+ readonly memberId?: string;
329
+ readonly childSessionId?: SessionId;
330
+ readonly provider?: string;
331
+ readonly model?: string;
332
+ readonly effort?: string;
333
+ readonly tokens?: number;
334
+ }
311
335
  /**
312
336
  * The replayed room state: roster, notification relays, the task board, run
313
337
  * states, and the current goal. There is deliberately NO blackboard/log
@@ -315,6 +339,7 @@ export interface RoomMemberRun {
315
339
  * design note).
316
340
  */
317
341
  export interface RoomState {
342
+ readonly executions?: readonly RoomExecution[];
318
343
  readonly plan?: Omit<RoomPlan, 'requests'>;
319
344
  readonly deliveries?: readonly RoomDelivery[];
320
345
  readonly coordinator?: RoomCoordinatorEvent;
@@ -596,6 +621,9 @@ export type RoomPostMessageResult = {
596
621
  };
597
622
  /** cancel request: interrupt a member's in-flight run. */
598
623
  export interface RoomCancelRequest {
624
+ /** Optional fencing for an execution card; a stale card must never stop a successor. */
625
+ readonly expectedRunId?: string;
626
+ readonly expectedStartedAt?: number;
599
627
  /** Room session. */
600
628
  readonly sessionId: SessionId;
601
629
  /** Member whose run should be cancelled. */