@khorsheed/dsh-room 0.1.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 (95) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/README.i18n.yaml +6 -0
  3. package/README.md +48 -0
  4. package/README.zh.md +48 -0
  5. package/cordis.patch.yml +6 -0
  6. package/lib/client.js +11481 -0
  7. package/lib/index.js +3231 -0
  8. package/lib/invariant.js +26 -0
  9. package/lib/journal-CuRnWk66.js +435 -0
  10. package/lib/tool.js +350 -0
  11. package/lib/typert.host.d.ts +3 -0
  12. package/lib/typert.host.js +2615 -0
  13. package/lib/typert.remote-client.d.ts +55 -0
  14. package/lib/typert.remote-client.js +1711 -0
  15. package/lib/types/adapter.d.ts +42 -0
  16. package/lib/types/adapter.js +41 -0
  17. package/lib/types/agent-setup.d.ts +141 -0
  18. package/lib/types/agent-setup.js +145 -0
  19. package/lib/types/client/InviteAgentAction.d.ts +13 -0
  20. package/lib/types/client/InviteAgentAction.js +45 -0
  21. package/lib/types/client/InviteDialog.d.ts +90 -0
  22. package/lib/types/client/InviteDialog.js +216 -0
  23. package/lib/types/client/MemberCard.d.ts +33 -0
  24. package/lib/types/client/MemberCard.js +32 -0
  25. package/lib/types/client/MembersView.d.ts +5 -0
  26. package/lib/types/client/MembersView.js +168 -0
  27. package/lib/types/client/RoomComposer.d.ts +21 -0
  28. package/lib/types/client/RoomComposer.js +211 -0
  29. package/lib/types/client/RoomDockCapsules.d.ts +64 -0
  30. package/lib/types/client/RoomDockCapsules.js +277 -0
  31. package/lib/types/client/RoomEventView.d.ts +11 -0
  32. package/lib/types/client/RoomEventView.js +17 -0
  33. package/lib/types/client/RoomModelPicker.d.ts +18 -0
  34. package/lib/types/client/RoomModelPicker.js +134 -0
  35. package/lib/types/client/RoomPlanView.d.ts +17 -0
  36. package/lib/types/client/RoomPlanView.js +88 -0
  37. package/lib/types/client/RoomQueueStrip.d.ts +26 -0
  38. package/lib/types/client/RoomQueueStrip.js +28 -0
  39. package/lib/types/client/RoomRecoveryView.d.ts +11 -0
  40. package/lib/types/client/RoomRecoveryView.js +38 -0
  41. package/lib/types/client/RoomRelayView.d.ts +12 -0
  42. package/lib/types/client/RoomRelayView.js +20 -0
  43. package/lib/types/client/RoomRunView.d.ts +15 -0
  44. package/lib/types/client/RoomRunView.js +50 -0
  45. package/lib/types/client/RoomSpeechView.d.ts +18 -0
  46. package/lib/types/client/RoomSpeechView.js +62 -0
  47. package/lib/types/client/RoomStatsLine.d.ts +61 -0
  48. package/lib/types/client/RoomStatsLine.js +138 -0
  49. package/lib/types/client/RoomTaskLineView.d.ts +13 -0
  50. package/lib/types/client/RoomTaskLineView.js +21 -0
  51. package/lib/types/client/RoomTodoStrip.d.ts +24 -0
  52. package/lib/types/client/RoomTodoStrip.js +64 -0
  53. package/lib/types/client/format.d.ts +31 -0
  54. package/lib/types/client/format.js +48 -0
  55. package/lib/types/client/icons.d.ts +27 -0
  56. package/lib/types/client/icons.js +11 -0
  57. package/lib/types/client/index.d.ts +39 -0
  58. package/lib/types/client/index.js +471 -0
  59. package/lib/types/client/locales.d.ts +422 -0
  60. package/lib/types/client/locales.js +413 -0
  61. package/lib/types/client/member-color.d.ts +13 -0
  62. package/lib/types/client/member-color.js +22 -0
  63. package/lib/types/client/name-pool.d.ts +17 -0
  64. package/lib/types/client/name-pool.js +25 -0
  65. package/lib/types/client/nodes.d.ts +136 -0
  66. package/lib/types/client/nodes.js +212 -0
  67. package/lib/types/client/preset-visibility.d.ts +91 -0
  68. package/lib/types/client/preset-visibility.js +113 -0
  69. package/lib/types/client/request-ids.d.ts +7 -0
  70. package/lib/types/client/request-ids.js +21 -0
  71. package/lib/types/client/room-store.d.ts +137 -0
  72. package/lib/types/client/room-store.js +244 -0
  73. package/lib/types/client/slots.d.ts +319 -0
  74. package/lib/types/client/slots.js +1 -0
  75. package/lib/types/deliveries.d.ts +5 -0
  76. package/lib/types/deliveries.js +20 -0
  77. package/lib/types/dispatch.d.ts +105 -0
  78. package/lib/types/dispatch.js +467 -0
  79. package/lib/types/index.d.ts +301 -0
  80. package/lib/types/index.js +1200 -0
  81. package/lib/types/invariant.d.ts +16 -0
  82. package/lib/types/invariant.js +24 -0
  83. package/lib/types/journal.d.ts +117 -0
  84. package/lib/types/journal.js +434 -0
  85. package/lib/types/plan-service.d.ts +34 -0
  86. package/lib/types/plan-service.js +266 -0
  87. package/lib/types/plan.d.ts +168 -0
  88. package/lib/types/plan.js +494 -0
  89. package/lib/types/tool.d.ts +56 -0
  90. package/lib/types/tool.js +389 -0
  91. package/lib/types/types.d.ts +813 -0
  92. package/lib/types/types.js +1 -0
  93. package/locale/en.json +6 -0
  94. package/locale/zh.json +6 -0
  95. package/package.json +131 -0
package/lib/tool.js ADDED
@@ -0,0 +1,350 @@
1
+ import { i as isRoomLog, r as coordinatorMember } from "./journal-CuRnWk66.js";
2
+ import { defineTool } from "@deepseek-ai/dsh-tools";
3
+ //#region lib/types/tool.js
4
+ /**
5
+ * The room's model-facing tool DEFINITIONS, `room_invite`, `room_task`, and
6
+ * `room_message`: the main
7
+ * agent's paths into the room it belongs to. `room_invite` and
8
+ * `room_message` PROMOTE: calling them in a plain session turns it into a
9
+ * room (ensureRoom) instead of rejecting. `room_task` stays gated at execute
10
+ * time — the calling agent's session must be a room (the journal carries
11
+ * `room/created`); anywhere else the tool answers with readable error text
12
+ * instead of throwing, so the model can see the rejection and self-correct.
13
+ * `room_invite` lands in the same invite path as the human dialog
14
+ * (`invitedBy: 'agent'`), producing an identical member record; `room_task`
15
+ * writes the SHARED task board through the very host functions the capsule UI
16
+ * uses (addTask/closeTask, plus the tool-only updateTask), so an agent-written
17
+ * task is indistinguishable from a human-added one; `room_message` dispatches
18
+ * a message to a member through the same engine path as the human's
19
+ * `@member text`, minus the user bubble (the caller is the room's own agent).
20
+ *
21
+ * Since the tool-row split (M4') the core no longer REGISTERS these tools:
22
+ * the factories are consumed by the companion `@khorsheed/dsh-room-tool`,
23
+ * which mounts the tool row inside agent-preset compositions (session-granted,
24
+ * never at the profile root). The definitions are therefore returned
25
+ * UNTAGGED — the registering package applies its own tool-origin tag
26
+ * (AGENTS.md § Tool origin tagging — the owner is whichever package mounts
27
+ * the row).
28
+ * @module @khorsheed/dsh-room/tool
29
+ */
30
+ /**
31
+ * Build the room_invite tool definition bound to the room service.
32
+ * @param backend - the room service.
33
+ * @returns a registry-ready tool definition.
34
+ */
35
+ function roomInviteTool(backend) {
36
+ return defineTool({
37
+ name: "room_invite",
38
+ description: "Invite a CLI agent member into the current session (any session works — inviting promotes it into a room: the multi-agent group conversation surface wakes up on it). The member becomes @-addressable by the human and by other members: pick a short unique name (no whitespace, no \"@\", e.g. ada/bill/cathy) — it is the addressing name, decoupled from the provider so two instances of one provider can coexist; prefer a function-style name (e.g. design-review / restart-test) when the member has a standing role, so the human and the other members can tell what it is for. The instructions are the member's role briefing, prepended to its first dispatch and persisted in its own CLI session from then on. Give a firstTask to put the member to work immediately, or omit it to have the member join idle. A member keeps its own CLI session and accumulates context across rounds, so prefer inviting over a one-shot subagent_* delegation whenever the work expects follow-ups with the same agent — reserve one-shot delegations for self-contained tasks with no continuation. The provider must be a registered delegation provider id — an unknown one is rejected with the list of available ids, so retry with one of those.",
39
+ parameters: {
40
+ provider: {
41
+ type: "string",
42
+ required: true,
43
+ description: "The local-agent delegation provider id (e.g. kimi-cli / codex-cli / claude-code) — the delegation id the family registered, which may differ from the harness's display name. When unsure, call without firstTask first: an unknown id is rejected with the list of available providers to retry with."
44
+ },
45
+ name: {
46
+ type: "string",
47
+ required: true,
48
+ description: "The member's @-addressing name: unique in this room, no whitespace, no \"@\"."
49
+ },
50
+ instructions: {
51
+ type: "string",
52
+ required: true,
53
+ description: "The member's role instructions (responsibilities, constraints, output expectations)."
54
+ },
55
+ firstTask: {
56
+ type: "string",
57
+ description: "Optional first task, dispatched to the member as soon as it joins."
58
+ },
59
+ cwd: {
60
+ type: "string",
61
+ description: "Optional working directory for the member (empty: inherits the room session's cwd)."
62
+ }
63
+ },
64
+ output: {
65
+ schema: {
66
+ type: "object",
67
+ additionalProperties: false,
68
+ properties: { text: {
69
+ type: "string",
70
+ required: true
71
+ } }
72
+ },
73
+ render: (_args, value) => [{
74
+ type: "text",
75
+ text: value.text
76
+ }]
77
+ },
78
+ isConcurrencySafe: () => true,
79
+ async execute(args, exec) {
80
+ const agent = exec.agent;
81
+ if (agent === void 0) return { text: "room_invite requires a calling agent (exec.agent was undefined)." };
82
+ const result = await backend.inviteMember({
83
+ sessionId: agent.session.id,
84
+ provider: args.provider,
85
+ name: args.name,
86
+ instructions: args.instructions,
87
+ ...args.firstTask === void 0 ? {} : { firstTask: args.firstTask },
88
+ ...args.cwd === void 0 ? {} : { cwd: args.cwd }
89
+ }, "agent");
90
+ if (!result.ok) {
91
+ const hint = result.error.code === "duplicate-name" ? " Pick a different name and retry." : result.error.code === "invalid-name" ? " Names must be non-empty and free of whitespace and \"@\"; retry with a valid name." : result.error.code === "local-agent-unavailable" ? " The local-agent delegation facade is not mounted; CLI members cannot join right now." : result.error.code === "unknown-provider" ? ` 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 ? "none (no harness with a delegation provider is registered)" : result.error.available.join(", ")}. Retry with one of the available providers.` : "";
92
+ return { text: `Could not invite "${args.name}": ${result.error.code}.${hint}` };
93
+ }
94
+ return { text: result.value.pendingFirstTask ? `Member ${result.value.name} joined the room and its first task was dispatched.` : `Member ${result.value.name} joined the room (idle; @-address it to dispatch work).` };
95
+ }
96
+ });
97
+ }
98
+ /**
99
+ * Build the room_task tool definition bound to the room service. Every write
100
+ * goes through the same host functions as the capsule UI, so a task the agent
101
+ * opens is a public commitment indistinguishable from a human-added one.
102
+ * @param backend - the room service.
103
+ * @returns a registry-ready tool definition.
104
+ */
105
+ function roomTaskTool(backend) {
106
+ return defineTool({
107
+ name: "room_task",
108
+ description: "Manage the current room's SHARED task board (only usable inside a room session). This board is public — every room member and the human sees these tasks, so writing here is a public commitment the room coordinates around; for your private work plan use your own todo tool instead. Actions: \"add\" (title + member — the roster name owning the task, use room_read to find your own or another member's name; optional blockedBy names the member the task waits on, display only) opens a pending task and returns its id; \"close\" (taskId) marks an open task done; \"update\" (taskId + a new title and/or blockedBy — null clears the wait) edits an open task. Errors answer with the roster or the open-task list so you can retry with a valid member name or task id.",
109
+ parameters: {
110
+ action: {
111
+ type: "string",
112
+ enum: [
113
+ "add",
114
+ "close",
115
+ "update"
116
+ ],
117
+ required: true,
118
+ description: "add: open a task (title + member). close: mark a task done (taskId). update: edit title/blockedBy (taskId)."
119
+ },
120
+ title: {
121
+ type: "string",
122
+ description: "Task title. Required for add; optional new title for update."
123
+ },
124
+ member: {
125
+ type: "string",
126
+ description: "The roster name owning the task (required for add; read room_read for current names)."
127
+ },
128
+ taskId: {
129
+ type: "string",
130
+ description: "The task id (required for close/update; add's success text returns the new id)."
131
+ },
132
+ blockedBy: {
133
+ oneOf: [{ type: "string" }, { type: "null" }],
134
+ description: "The member this task waits on (must be on the roster; display only, never an automatic dispatch). Optional on add; on update, a string re-targets the wait and null clears it."
135
+ }
136
+ },
137
+ output: {
138
+ schema: {
139
+ type: "object",
140
+ additionalProperties: false,
141
+ properties: { text: {
142
+ type: "string",
143
+ required: true
144
+ } }
145
+ },
146
+ render: (_args, value) => [{
147
+ type: "text",
148
+ text: value.text
149
+ }]
150
+ },
151
+ isConcurrencySafe: () => true,
152
+ async execute(args, exec) {
153
+ const agent = exec.agent;
154
+ if (agent === void 0) return { text: "room_task requires a calling agent (exec.agent was undefined)." };
155
+ if (!isRoomLog(agent.session.snapshotEvents())) return { text: "The current session is not a room; room_task is only usable inside a room session." };
156
+ const sessionId = agent.session.id;
157
+ const ownership = await backend.getState({ sessionId });
158
+ if (ownership.ok && coordinatorMember(ownership.value)?.kind !== "main-agent") return { text: "Only the current coordinator may manage the shared room task board." };
159
+ /** The self-correcting roster suffix: the legal member names, for member-not-found. */
160
+ const rosterHint = async () => {
161
+ const state = await backend.getState({ sessionId });
162
+ if (!state.ok) return "";
163
+ const names = state.value.members.map((member) => member.name);
164
+ return names.length === 0 ? "" : ` The room roster is: ${names.join(", ")}. Retry with one of these names.`;
165
+ };
166
+ /** The self-correcting board suffix: the open tasks (id — title), for task-not-found. */
167
+ const openTasksHint = async () => {
168
+ const state = await backend.getState({ sessionId });
169
+ if (!state.ok) return "";
170
+ const open = state.value.tasks.filter((task) => task.status === "pending" || task.status === "in_progress");
171
+ if (open.length === 0) return " The board has no open tasks right now.";
172
+ return ` Open tasks: ${open.map((task) => `${task.id} — "${task.title}" (${task.member}, ${task.status})`).join("; ")}. Retry with one of these ids.`;
173
+ };
174
+ const failureText = async (code) => {
175
+ switch (code) {
176
+ case "member-not-found": return `Unknown member.${await rosterHint()}`;
177
+ case "empty-text": return "The title must be non-blank; retry with a real title.";
178
+ case "task-not-found": return `No task with that id.${await openTasksHint()}`;
179
+ case "task-closed": return "That task is already closed (done/cancelled); closed tasks take no further changes.";
180
+ case "nothing-to-update": return "update needs at least one field to change: a new title and/or blockedBy (null clears the wait).";
181
+ default: return `The room rejected the write (${code}).`;
182
+ }
183
+ };
184
+ switch (args.action) {
185
+ case "add": {
186
+ if (args.title === void 0 || args.member === void 0) return { text: "room_task add requires both title and member (the roster name owning the task; read room_read for current names)." };
187
+ if (args.blockedBy === null) return { text: "add takes no null blockedBy — simply omit blockedBy for an unblocked task." };
188
+ const result = await backend.addTask({
189
+ sessionId,
190
+ member: args.member,
191
+ title: args.title,
192
+ ...args.blockedBy === void 0 ? {} : { blockedBy: args.blockedBy }
193
+ });
194
+ if (!result.ok) return { text: `Could not add the task: ${result.error.code}. ${await failureText(result.error.code)}` };
195
+ return { text: `Task "${args.title}" is now on ${args.member}'s lane of the shared room board (id: ${result.value.id}) — visible to every member and the human. Keep the id to update or close the task later.` };
196
+ }
197
+ case "close": {
198
+ if (args.taskId === void 0) return { text: `room_task close requires taskId.${await openTasksHint()}` };
199
+ const result = await backend.closeTask({
200
+ sessionId,
201
+ taskId: args.taskId
202
+ });
203
+ if (!result.ok) return { text: `Could not close the task: ${result.error.code}. ${await failureText(result.error.code)}` };
204
+ return { text: `Task ${result.value.id} is done — the shared board shows it closed.` };
205
+ }
206
+ case "update": {
207
+ if (args.taskId === void 0) return { text: `room_task update requires taskId.${await openTasksHint()}` };
208
+ const result = await backend.updateTask({
209
+ sessionId,
210
+ taskId: args.taskId,
211
+ ...args.title === void 0 ? {} : { title: args.title },
212
+ ...args.blockedBy === void 0 ? {} : { blockedBy: args.blockedBy }
213
+ });
214
+ if (!result.ok) return { text: `Could not update the task: ${result.error.code}. ${await failureText(result.error.code)}` };
215
+ return { text: `Task ${result.value.id} updated on the shared room board.` };
216
+ }
217
+ }
218
+ }
219
+ });
220
+ }
221
+ /**
222
+ * Build the room_message tool definition bound to the room service: the main
223
+ * agent's way to hand a member a message/task — the model-facing equivalent
224
+ * of the human's `@member text`, minus the user bubble (the caller is the
225
+ * room's own agent, not the human).
226
+ * @param backend - the room service.
227
+ * @returns a registry-ready tool definition.
228
+ */
229
+ function roomMessageTool(backend) {
230
+ return defineTool({
231
+ name: "room_message",
232
+ description: "Dispatch a message to a member of the current room (works in any session — it promotes the session into a room if it is not one yet). A member is an independent CLI session: the message runs asynchronously, and the member's reply appears in the room as member speech (the human sees it; you read it through the room's flow). Use this to ask a member something or hand it work — the equivalent of the human typing \"@member <text>\" in the room composer. The member argument is a roster name (read room_read for current names); an unknown name is rejected with the live roster, so retry with one of those.",
233
+ parameters: {
234
+ member: {
235
+ type: "string",
236
+ required: true,
237
+ description: "The addressee's roster name (read room_read for current names; new rooms name the native member \"dsh\")."
238
+ },
239
+ text: {
240
+ type: "string",
241
+ required: true,
242
+ description: "The message text the member receives as its task."
243
+ }
244
+ },
245
+ output: {
246
+ schema: {
247
+ type: "object",
248
+ additionalProperties: false,
249
+ properties: { text: {
250
+ type: "string",
251
+ required: true
252
+ } }
253
+ },
254
+ render: (_args, value) => [{
255
+ type: "text",
256
+ text: value.text
257
+ }]
258
+ },
259
+ isConcurrencySafe: () => true,
260
+ async execute(args, exec) {
261
+ const agent = exec.agent;
262
+ if (agent === void 0) return { text: "room_message requires a calling agent (exec.agent was undefined)." };
263
+ const sessionId = agent.session.id;
264
+ const result = await backend.messageMember({
265
+ sessionId,
266
+ member: args.member,
267
+ text: args.text
268
+ });
269
+ if (!result.ok) {
270
+ if (result.error.code === "member-not-found") {
271
+ const state = await backend.getState({ sessionId });
272
+ const names = state.ok ? state.value.members.map((member) => member.name) : [];
273
+ const hint = names.length === 0 ? "" : ` The room roster is: ${names.join(", ")}. Retry with one of these names.`;
274
+ return { text: `Could not message "${args.member}": unknown member.${hint}` };
275
+ }
276
+ if (result.error.code === "empty-text") return { text: "The message text must be non-blank; retry with real content." };
277
+ return { text: `Could not message "${args.member}": ${result.error.code}.` };
278
+ }
279
+ return { text: `Dispatched to ${result.value.member} — the member runs it asynchronously and its reply appears in the room as member speech. Do not wait on it; the human watches the room.` };
280
+ }
281
+ });
282
+ }
283
+ /** Native room tools use the same bounded context reader as the external MCP bridge. */
284
+ function roomReadTool(backend) {
285
+ return defineTool({
286
+ name: "room_read",
287
+ description: "Read the current room roster, coordinator, deliveries, recent outcomes and available harness providers. Reading does not wake any member.",
288
+ parameters: {},
289
+ output: {
290
+ schema: {
291
+ type: "object",
292
+ additionalProperties: false,
293
+ properties: { text: {
294
+ type: "string",
295
+ required: true
296
+ } }
297
+ },
298
+ render: (_args, value) => [{
299
+ type: "text",
300
+ text: value.text
301
+ }]
302
+ },
303
+ isConcurrencySafe: () => true,
304
+ async execute(_args, exec) {
305
+ if (exec.agent === void 0) return { text: "room_read requires a calling agent." };
306
+ try {
307
+ return { text: await backend.readRoomContext(exec.agent.session.id) };
308
+ } catch (error) {
309
+ return { text: String(error) };
310
+ }
311
+ }
312
+ });
313
+ }
314
+ /** Formal planning uses the same strict command grammar exposed by room_read. */
315
+ function roomPlanTool(backend) {
316
+ return defineTool({
317
+ name: "room_plan",
318
+ 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.",
319
+ parameters: { command: {
320
+ type: "string",
321
+ required: true,
322
+ 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."
323
+ } },
324
+ output: {
325
+ schema: {
326
+ type: "object",
327
+ additionalProperties: false,
328
+ properties: { text: {
329
+ type: "string",
330
+ required: true
331
+ } }
332
+ },
333
+ render: (_args, value) => [{
334
+ type: "text",
335
+ text: value.text
336
+ }]
337
+ },
338
+ isConcurrencySafe: () => true,
339
+ async execute(args, exec) {
340
+ if (exec.agent === void 0) return { text: "room_plan requires a calling agent." };
341
+ try {
342
+ return { text: await backend.commandPlan(exec.agent.session.id, args.command) };
343
+ } catch (error) {
344
+ return { text: String(error) };
345
+ }
346
+ }
347
+ });
348
+ }
349
+ //#endregion
350
+ export { roomInviteTool, roomMessageTool, roomPlanTool, roomReadTool, roomTaskTool };
@@ -0,0 +1,3 @@
1
+ /* Generated by @deepseek-ai/dsh-typert-generator from FaceModel — do not edit. */
2
+
3
+ export declare const TYPERT: unknown