@yankeguo/dsh-command-devlead 0.0.0-stage → 0.1.1

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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Y.-K. Guo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/lib/index.js ADDED
@@ -0,0 +1,354 @@
1
+ // Built by dsh-devlead. Do not edit.
2
+
3
+ // packages/command/src/index.ts
4
+ import { CommandDefinitionId } from "@deepseek-ai/dsh-commands/brand";
5
+ import { isDevLeadError } from "@yankeguo/dsh-devlead";
6
+ import { DEVLEAD_COMMAND_NAME as DEVLEAD_COMMAND_NAME2 } from "@yankeguo/dsh-devlead-protocol";
7
+
8
+ // packages/command/src/parse.ts
9
+ import { DEVLEAD_COMMAND_NAME } from "@yankeguo/dsh-devlead-protocol";
10
+ var COMMAND_GRAMMAR = "[status|on|off|watch <session>|unwatch <session>]";
11
+ var USAGE = `Usage: /${DEVLEAD_COMMAND_NAME} ${COMMAND_GRAMMAR}`;
12
+ function invalid(message) {
13
+ return { kind: "invalid", message };
14
+ }
15
+ function splitHead(input) {
16
+ const separator = input.search(/\s/u);
17
+ if (separator === -1) return { head: input.toLowerCase(), rest: "" };
18
+ return { head: input.slice(0, separator).toLowerCase(), rest: input.slice(separator).trim() };
19
+ }
20
+ function unquote(text) {
21
+ const trimmed = text.trim();
22
+ if (trimmed.length < 2) return trimmed;
23
+ const first = trimmed[0];
24
+ const last = trimmed[trimmed.length - 1];
25
+ const pair = first === '"' && last === '"' || first === "'" && last === "'";
26
+ return pair ? trimmed.slice(1, -1).trim() : trimmed;
27
+ }
28
+ function unexpectedArgument(subcommand) {
29
+ return invalid(`The /devlead ${subcommand} subcommand does not take an argument.`);
30
+ }
31
+ function parseSessionArgument(subcommand, text) {
32
+ const session = unquote(text);
33
+ if (session.length === 0) {
34
+ return invalid(
35
+ `/devlead ${subcommand} requires a Session id or a unique id prefix. Run /devlead to inspect the current watch set.`
36
+ );
37
+ }
38
+ if (/^["']|["']$/u.test(session)) {
39
+ return invalid(
40
+ `The /devlead ${subcommand} Session reference has an unmatched quote; wrap the whole reference in one matching pair of quotes.`
41
+ );
42
+ }
43
+ if (/\s/u.test(session)) {
44
+ return invalid(
45
+ `"/devlead ${subcommand}" takes one Session reference without spaces; pass the full Session id or a unique id prefix.`
46
+ );
47
+ }
48
+ return { kind: subcommand, session };
49
+ }
50
+ function parseDevLeadCommand(rawInput) {
51
+ const input = rawInput.trim();
52
+ if (input.length === 0) return { kind: "status" };
53
+ switch (input.toLowerCase()) {
54
+ case "status":
55
+ return { kind: "status" };
56
+ case "on":
57
+ return { kind: "on" };
58
+ case "off":
59
+ return { kind: "off" };
60
+ default:
61
+ break;
62
+ }
63
+ const { head, rest } = splitHead(input);
64
+ switch (head) {
65
+ case "watch":
66
+ return parseSessionArgument("watch", rest);
67
+ case "unwatch":
68
+ return parseSessionArgument("unwatch", rest);
69
+ // A no-argument subcommand followed by stray text is a typo, not a
70
+ // Session reference; name the offending subcommand instead of guessing.
71
+ case "status":
72
+ case "on":
73
+ case "off":
74
+ return unexpectedArgument(head);
75
+ default:
76
+ return invalid(`Unknown /devlead subcommand "${head}".`);
77
+ }
78
+ }
79
+
80
+ // packages/command/src/render.ts
81
+ import {
82
+ formatInstant,
83
+ notificationLine,
84
+ transitionLabel
85
+ } from "@yankeguo/dsh-devlead-protocol";
86
+
87
+ // packages/command/src/resolve.ts
88
+ function candidateOf(view) {
89
+ return view.title === void 0 ? { sessionId: view.sessionId } : { sessionId: view.sessionId, title: view.title };
90
+ }
91
+ function mergeCandidates(listed, watchedSessionIds) {
92
+ const candidates = /* @__PURE__ */ new Map();
93
+ for (const view of listed) candidates.set(view.sessionId, candidateOf(view));
94
+ for (const sessionId of watchedSessionIds) {
95
+ if (!candidates.has(sessionId)) candidates.set(sessionId, { sessionId });
96
+ }
97
+ return [...candidates.values()];
98
+ }
99
+ function resolveSessionReference(query, candidates) {
100
+ const reference = query.trim();
101
+ if (reference.length === 0) return { kind: "missing" };
102
+ for (const candidate of candidates) {
103
+ if (candidate.sessionId !== reference) continue;
104
+ return candidate.title === void 0 ? { kind: "resolved", sessionId: candidate.sessionId } : { kind: "resolved", sessionId: candidate.sessionId, title: candidate.title };
105
+ }
106
+ const matches = candidates.filter((candidate) => candidate.sessionId.startsWith(reference));
107
+ const first = matches[0];
108
+ if (first === void 0) return { kind: "missing" };
109
+ if (matches.length === 1) {
110
+ return first.title === void 0 ? { kind: "resolved", sessionId: first.sessionId } : { kind: "resolved", sessionId: first.sessionId, title: first.title };
111
+ }
112
+ return { kind: "ambiguous", candidates: matches };
113
+ }
114
+ var MAX_RENDERED_CANDIDATES = 10;
115
+ function sessionRefLabel(sessionId, title) {
116
+ const trimmed = title?.trim() ?? "";
117
+ return trimmed.length === 0 ? sessionId : `${trimmed} (${sessionId})`;
118
+ }
119
+ function candidateLabel(candidate) {
120
+ return sessionRefLabel(candidate.sessionId, candidate.title);
121
+ }
122
+ function formatCandidates(candidates) {
123
+ const shown = candidates.slice(0, MAX_RENDERED_CANDIDATES);
124
+ const lines = shown.map((candidate) => ` - ${candidateLabel(candidate)}`);
125
+ const hidden = candidates.length - shown.length;
126
+ if (hidden > 0) lines.push(` \u2026 and ${hidden} more`);
127
+ return lines;
128
+ }
129
+
130
+ // packages/command/src/render.ts
131
+ var RECENT_NOTIFICATION_LIMIT = 5;
132
+ var HELP_LINE = "Help: /devlead (status) | /devlead on | /devlead off | /devlead watch <session> | /devlead unwatch <session>";
133
+ function modeLabel(enabled) {
134
+ return enabled ? "on" : "off";
135
+ }
136
+ function sessionLabel(view) {
137
+ return sessionRefLabel(view.sessionId, view.title);
138
+ }
139
+ function sessionStateLabel(view) {
140
+ const state = view.archived ? "archived" : view.running ? "running" : view.live ? "idle" : "cold";
141
+ const parts = [state];
142
+ if (view.running && (view.pendingInputs ?? 0) > 0) parts.push(`${view.pendingInputs} queued`);
143
+ if (view.lastTurn !== void 0) {
144
+ const outcome = view.lastTransition === void 0 ? "" : ` ${transitionLabel(view.lastTransition)}`;
145
+ parts.push(`last turn ${view.lastTurn}${outcome}`);
146
+ }
147
+ const base = parts.join(" \xB7 ");
148
+ return view.lastError === void 0 ? base : `${base}: ${view.lastError}`;
149
+ }
150
+ function watchedLines(snapshot) {
151
+ const total = snapshot.watched.length + snapshot.missingWatched.length;
152
+ if (total === 0) return ["Watched sessions: none"];
153
+ const running = snapshot.watched.filter((view) => view.running).length;
154
+ const summary = running === 0 ? `Watched sessions: ${total}` : `Watched sessions: ${total} (${running} running)`;
155
+ const lines = [summary];
156
+ for (const view of snapshot.watched) lines.push(` - ${sessionLabel(view)} \u2014 ${sessionStateLabel(view)}`);
157
+ for (const sessionId of snapshot.missingWatched) lines.push(` - ${sessionId} \u2014 not found`);
158
+ return lines;
159
+ }
160
+ function notificationLines(snapshot) {
161
+ if (snapshot.notifications.length === 0) return ["Recent notifications: none"];
162
+ const lines = ["Recent notifications:"];
163
+ for (const notification of snapshot.notifications) {
164
+ lines.push(` - ${formatInstant(notification.at)} ${notificationLine(notification)}`);
165
+ }
166
+ return lines;
167
+ }
168
+ function statusLines(snapshot) {
169
+ const lines = [
170
+ `DevLead mode: ${modeLabel(snapshot.enabled)}`,
171
+ ...watchedLines(snapshot),
172
+ ...notificationLines(snapshot)
173
+ ];
174
+ if (!snapshot.enabled) {
175
+ lines.push(
176
+ "DevLead mode is off: no notification wakes this Session until it is turned on again.",
177
+ "Turn DevLead mode on with: /devlead on"
178
+ );
179
+ }
180
+ lines.push(HELP_LINE);
181
+ return lines;
182
+ }
183
+ function renderStatus(snapshot, title) {
184
+ const lines = title === void 0 ? [] : [title, ""];
185
+ return { kind: "success", text: [...lines, ...statusLines(snapshot)].join("\n") };
186
+ }
187
+ function errorResult(text) {
188
+ return { kind: "error", text };
189
+ }
190
+
191
+ // packages/command/src/index.ts
192
+ var name = "command-devlead";
193
+ var inject = ["commands", "devLead"];
194
+ var DESCRIPTION = "Turn DevLead mode on or off for this Session, watch or unwatch another Session, and inspect the DevLead mode, watch set, and recent notification digest.";
195
+ var NOT_ENABLED_MESSAGE = "DevLead mode is off for this Session, so its watch set cannot change. Turn it on with /devlead on first.";
196
+ async function collectStatus(ctx, invocation) {
197
+ const view = ctx.devLead.view(invocation.agent);
198
+ const watched = [];
199
+ const missingWatched = [];
200
+ if (view.sessions.length > 0) {
201
+ const sessions = await ctx.devLead.listSessions(invocation.agent, {
202
+ watchedOnly: true,
203
+ signal: invocation.signal
204
+ });
205
+ const byId = new Map(sessions.map((session) => [session.sessionId, session]));
206
+ for (const sessionId of view.sessions) {
207
+ const session = byId.get(sessionId);
208
+ if (session === void 0) missingWatched.push(sessionId);
209
+ else watched.push(session);
210
+ }
211
+ }
212
+ return {
213
+ enabled: view.enabled,
214
+ watched,
215
+ missingWatched,
216
+ notifications: view.notifications.slice(-RECENT_NOTIFICATION_LIMIT)
217
+ };
218
+ }
219
+ async function collectCandidates(ctx, invocation, watchedSessionIds) {
220
+ const sessions = await ctx.devLead.listSessions(invocation.agent, { signal: invocation.signal });
221
+ return mergeCandidates(sessions, watchedSessionIds);
222
+ }
223
+ function ambiguousResult(query, candidates) {
224
+ return errorResult([
225
+ `Session reference "${query}" is ambiguous; it matches ${candidates.length} Sessions:`,
226
+ ...formatCandidates(candidates),
227
+ "Use a longer prefix or the full Session id."
228
+ ].join("\n"));
229
+ }
230
+ function missingSessionResult(query) {
231
+ return errorResult(
232
+ `No Session matches "${query}". Check the Session id, or run /devlead to inspect the watched Sessions.`
233
+ );
234
+ }
235
+ async function resolveBeyondListing(ctx, invocation, reference) {
236
+ try {
237
+ const view = await ctx.devLead.getSession(invocation.agent, reference, invocation.signal);
238
+ return view.title === void 0 ? { kind: "resolved", sessionId: view.sessionId } : { kind: "resolved", sessionId: view.sessionId, title: view.title };
239
+ } catch (error) {
240
+ if (!isDevLeadError(error)) throw error;
241
+ if (error.code === "DEVLEAD_INVALID_INPUT") return { kind: "ambiguous", message: error.message };
242
+ if (error.code === "DEVLEAD_SESSION_NOT_FOUND") return { kind: "missing" };
243
+ throw error;
244
+ }
245
+ }
246
+ async function resolveWatchTarget(ctx, invocation, reference, watchedSessionIds) {
247
+ const candidates = await collectCandidates(ctx, invocation, watchedSessionIds);
248
+ const resolution = resolveSessionReference(reference, candidates);
249
+ if (resolution.kind === "resolved") return resolution;
250
+ if (resolution.kind === "ambiguous") {
251
+ return { kind: "failure", result: ambiguousResult(reference, resolution.candidates) };
252
+ }
253
+ const fallback = await resolveBeyondListing(ctx, invocation, reference);
254
+ if (fallback.kind === "resolved") return fallback;
255
+ if (fallback.kind === "ambiguous") {
256
+ return {
257
+ kind: "failure",
258
+ result: errorResult(`${fallback.message}
259
+ Use a longer prefix or the full Session id.`)
260
+ };
261
+ }
262
+ return { kind: "failure", result: missingSessionResult(reference) };
263
+ }
264
+ async function executeMode(ctx, invocation, enabled) {
265
+ if (ctx.devLead.view(invocation.agent).enabled === enabled) {
266
+ const title2 = enabled ? "DevLead mode is already on." : "DevLead mode is already off.";
267
+ return renderStatus(await collectStatus(ctx, invocation), title2);
268
+ }
269
+ await ctx.devLead.setEnabled(invocation.agent, enabled, invocation.signal);
270
+ const title = enabled ? "DevLead mode enabled." : "DevLead mode disabled.";
271
+ return renderStatus(await collectStatus(ctx, invocation), title);
272
+ }
273
+ async function executeWatch(ctx, invocation, command) {
274
+ const view = ctx.devLead.view(invocation.agent);
275
+ if (!view.enabled) return errorResult(NOT_ENABLED_MESSAGE);
276
+ const target = await resolveWatchTarget(ctx, invocation, command.session, view.sessions);
277
+ if (target.kind === "failure") return target.result;
278
+ const { sessionId } = target;
279
+ const label = sessionRefLabel(sessionId, target.title);
280
+ const watching = view.sessions.includes(sessionId);
281
+ if (command.kind === "watch") {
282
+ const title2 = watching ? `Already watching ${label}.` : `Now watching ${label}.`;
283
+ if (!watching) await ctx.devLead.watchSession(invocation.agent, sessionId, true, invocation.signal);
284
+ return renderStatus(await collectStatus(ctx, invocation), title2);
285
+ }
286
+ const title = watching ? `Stopped watching ${label}.` : `Not watching ${label}.`;
287
+ if (watching) await ctx.devLead.watchSession(invocation.agent, sessionId, false, invocation.signal);
288
+ return renderStatus(await collectStatus(ctx, invocation), title);
289
+ }
290
+ function friendlyDevLeadError(error) {
291
+ switch (error.code) {
292
+ case "DEVLEAD_NOT_ENABLED":
293
+ return NOT_ENABLED_MESSAGE;
294
+ case "DEVLEAD_AGENT_NOT_LIVE":
295
+ return "This Session is no longer live in this Host, so the command cannot run. Open it again from the sidebar and retry.";
296
+ case "DEVLEAD_INVALID_INPUT":
297
+ return `The /devlead request is not usable: ${error.message}`;
298
+ case "DEVLEAD_SESSION_NOT_FOUND":
299
+ return `The host could not find that Session: ${error.message}`;
300
+ case "DEVLEAD_SESSION_ARCHIVED":
301
+ return "That Session is archived; restore it from the Workspace sidebar before watching it.";
302
+ case "DEVLEAD_SESSION_UNAVAILABLE":
303
+ return `That Session cannot be resumed right now: ${error.message}`;
304
+ case "DEVLEAD_WATCH_LIMIT":
305
+ return "The maximum number of watched Sessions has been reached. Stop watching one with /devlead unwatch <session> first.";
306
+ case "DEVLEAD_SELF_WATCH":
307
+ return "A DevLead Session cannot watch itself.";
308
+ case "DEVLEAD_PROJECTION_INVALID":
309
+ return `This Session's DevLead records are damaged: ${error.message}. Inspect the Session log for the offending plugin:devlead record.`;
310
+ case "DEVLEAD_WORKSPACE_NOT_FOUND":
311
+ return `The Workspace could not be resolved: ${error.message}`;
312
+ case "DEVLEAD_DIRECTORY_MISSING":
313
+ return `The target directory is missing: ${error.message}`;
314
+ default:
315
+ return `The DevLead request failed: ${error.message}`;
316
+ }
317
+ }
318
+ async function executeDevLeadCommand(ctx, invocation) {
319
+ const command = parseDevLeadCommand(invocation.rawInput);
320
+ if (command.kind === "invalid") return errorResult(`${command.message}
321
+ ${USAGE}`);
322
+ try {
323
+ switch (command.kind) {
324
+ case "status":
325
+ return renderStatus(await collectStatus(ctx, invocation));
326
+ case "on":
327
+ case "off":
328
+ return await executeMode(ctx, invocation, command.kind === "on");
329
+ case "watch":
330
+ case "unwatch":
331
+ return await executeWatch(ctx, invocation, command);
332
+ }
333
+ } catch (error) {
334
+ if (isDevLeadError(error)) return errorResult(friendlyDevLeadError(error));
335
+ throw error;
336
+ }
337
+ }
338
+ function apply(ctx) {
339
+ ctx.commands.register({
340
+ definitionId: CommandDefinitionId("@yankeguo/dsh-command-devlead"),
341
+ name: DEVLEAD_COMMAND_NAME2,
342
+ description: DESCRIPTION,
343
+ // The grammar is text-only, so the definition deliberately declares no
344
+ // `input.attachments`: the CommandRuntime then rejects composer attachments
345
+ // before this handler runs, and no handler-side guard is needed.
346
+ input: { hint: COMMAND_GRAMMAR },
347
+ handler: (invocation) => executeDevLeadCommand(ctx, invocation)
348
+ });
349
+ }
350
+ export {
351
+ apply,
352
+ inject,
353
+ name
354
+ };
package/package.json CHANGED
@@ -1,6 +1,35 @@
1
1
  {
2
2
  "name": "@yankeguo/dsh-command-devlead",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.1",
4
+ "description": "Human-facing /devlead command: enable or disable DevLead mode for the current session and inspect the lead's managed workspaces, sessions, and notifications.",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "main": "lib/index.js",
8
+ "exports": {
9
+ ".": "./lib/index.js",
10
+ "./package.json": "./package.json"
11
+ },
12
+ "files": [
13
+ "lib"
14
+ ],
15
+ "peerDependencies": {
16
+ "@deepseek-ai/cordis": "~4.1.0",
17
+ "@deepseek-ai/dsh-commands": "0.2.2-rc.1"
18
+ },
19
+ "dependencies": {
20
+ "@yankeguo/dsh-devlead": "0.1.1",
21
+ "@yankeguo/dsh-devlead-protocol": "0.1.1"
22
+ },
23
+ "engines": {
24
+ "dsh": ">=0.2.2-rc.1 <0.3.0"
25
+ },
26
+ "publishConfig": {
27
+ "access": "public"
28
+ },
29
+ "repository": {
30
+ "type": "git",
31
+ "url": "git+https://github.com/yankeguo/dsh-devlead.git",
32
+ "directory": "packages/command"
33
+ },
34
+ "homepage": "https://github.com/yankeguo/dsh-devlead#readme"
6
35
  }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.