@yankeguo/dsh-command-devlead 0.1.0 → 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.
Files changed (2) hide show
  1. package/lib/index.js +70 -68
  2. package/package.json +3 -3
package/lib/index.js CHANGED
@@ -13,9 +13,9 @@ function invalid(message) {
13
13
  return { kind: "invalid", message };
14
14
  }
15
15
  function splitHead(input) {
16
- const match = /^(\S+)(?:\s+([\s\S]*))?$/u.exec(input);
17
- if (match === null) return { head: input.toLowerCase(), rest: "" };
18
- return { head: match[1].toLowerCase(), rest: (match[2] ?? "").trim() };
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
19
  }
20
20
  function unquote(text) {
21
21
  const trimmed = text.trim();
@@ -35,6 +35,11 @@ function parseSessionArgument(subcommand, text) {
35
35
  `/devlead ${subcommand} requires a Session id or a unique id prefix. Run /devlead to inspect the current watch set.`
36
36
  );
37
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
+ }
38
43
  if (/\s/u.test(session)) {
39
44
  return invalid(
40
45
  `"/devlead ${subcommand}" takes one Session reference without spaces; pass the full Session id or a unique id prefix.`
@@ -43,9 +48,7 @@ function parseSessionArgument(subcommand, text) {
43
48
  return { kind: subcommand, session };
44
49
  }
45
50
  function parseDevLeadCommand(rawInput) {
46
- const trimmed = rawInput.trim();
47
- const complete = /^\/devlead[/\s]*/iu.exec(trimmed);
48
- const input = (complete === null ? trimmed : trimmed.slice(complete[0].length)).trim();
51
+ const input = rawInput.trim();
49
52
  if (input.length === 0) return { kind: "status" };
50
53
  switch (input.toLowerCase()) {
51
54
  case "status":
@@ -80,14 +83,58 @@ import {
80
83
  notificationLine,
81
84
  transitionLabel
82
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
83
131
  var RECENT_NOTIFICATION_LIMIT = 5;
84
- var HELP_LINE = "Help: /devlead on | /devlead off | /devlead watch <session> | /devlead unwatch <session>";
132
+ var HELP_LINE = "Help: /devlead (status) | /devlead on | /devlead off | /devlead watch <session> | /devlead unwatch <session>";
85
133
  function modeLabel(enabled) {
86
134
  return enabled ? "on" : "off";
87
135
  }
88
136
  function sessionLabel(view) {
89
- const title = view.title?.trim() ?? "";
90
- return title.length === 0 ? view.sessionId : `${title} (${view.sessionId})`;
137
+ return sessionRefLabel(view.sessionId, view.title);
91
138
  }
92
139
  function sessionStateLabel(view) {
93
140
  const state = view.archived ? "archived" : view.running ? "running" : view.live ? "idle" : "cold";
@@ -141,45 +188,6 @@ function errorResult(text) {
141
188
  return { kind: "error", text };
142
189
  }
143
190
 
144
- // packages/command/src/resolve.ts
145
- function candidateOf(view) {
146
- return view.title === void 0 ? { sessionId: view.sessionId } : { sessionId: view.sessionId, title: view.title };
147
- }
148
- function mergeCandidates(listed, watchedSessionIds) {
149
- const candidates = /* @__PURE__ */ new Map();
150
- for (const view of listed) candidates.set(view.sessionId, candidateOf(view));
151
- for (const sessionId of watchedSessionIds) {
152
- if (!candidates.has(sessionId)) candidates.set(sessionId, { sessionId });
153
- }
154
- return [...candidates.values()];
155
- }
156
- function resolveSessionReference(query, candidates) {
157
- const reference = query.trim();
158
- if (reference.length === 0) return { kind: "missing" };
159
- for (const candidate of candidates) {
160
- if (candidate.sessionId !== reference) continue;
161
- return candidate.title === void 0 ? { kind: "resolved", sessionId: candidate.sessionId } : { kind: "resolved", sessionId: candidate.sessionId, title: candidate.title };
162
- }
163
- const matches = candidates.filter((candidate) => candidate.sessionId.startsWith(reference));
164
- const first = matches[0];
165
- if (first === void 0) return { kind: "missing" };
166
- if (matches.length === 1) {
167
- return first.title === void 0 ? { kind: "resolved", sessionId: first.sessionId } : { kind: "resolved", sessionId: first.sessionId, title: first.title };
168
- }
169
- return { kind: "ambiguous", candidates: matches };
170
- }
171
- var MAX_RENDERED_CANDIDATES = 10;
172
- function candidateLabel(candidate) {
173
- return candidate.title === void 0 ? candidate.sessionId : `${candidate.title} (${candidate.sessionId})`;
174
- }
175
- function formatCandidates(candidates) {
176
- const shown = candidates.slice(0, MAX_RENDERED_CANDIDATES);
177
- const lines = shown.map((candidate) => ` - ${candidateLabel(candidate)}`);
178
- const hidden = candidates.length - shown.length;
179
- if (hidden > 0) lines.push(` \u2026 and ${hidden} more`);
180
- return lines;
181
- }
182
-
183
191
  // packages/command/src/index.ts
184
192
  var name = "command-devlead";
185
193
  var inject = ["commands", "devLead"];
@@ -190,11 +198,10 @@ async function collectStatus(ctx, invocation) {
190
198
  const watched = [];
191
199
  const missingWatched = [];
192
200
  if (view.sessions.length > 0) {
193
- const sessions = await ctx.devLead.listSessions(
194
- invocation.agent,
195
- { watchedOnly: true },
196
- invocation.signal
197
- );
201
+ const sessions = await ctx.devLead.listSessions(invocation.agent, {
202
+ watchedOnly: true,
203
+ signal: invocation.signal
204
+ });
198
205
  const byId = new Map(sessions.map((session) => [session.sessionId, session]));
199
206
  for (const sessionId of view.sessions) {
200
207
  const session = byId.get(sessionId);
@@ -206,11 +213,11 @@ async function collectStatus(ctx, invocation) {
206
213
  enabled: view.enabled,
207
214
  watched,
208
215
  missingWatched,
209
- notifications: ctx.devLead.notifications(invocation.agent, { limit: RECENT_NOTIFICATION_LIMIT })
216
+ notifications: view.notifications.slice(-RECENT_NOTIFICATION_LIMIT)
210
217
  };
211
218
  }
212
219
  async function collectCandidates(ctx, invocation, watchedSessionIds) {
213
- const sessions = await ctx.devLead.listSessions(invocation.agent, {}, invocation.signal);
220
+ const sessions = await ctx.devLead.listSessions(invocation.agent, { signal: invocation.signal });
214
221
  return mergeCandidates(sessions, watchedSessionIds);
215
222
  }
216
223
  function ambiguousResult(query, candidates) {
@@ -225,9 +232,6 @@ function missingSessionResult(query) {
225
232
  `No Session matches "${query}". Check the Session id, or run /devlead to inspect the watched Sessions.`
226
233
  );
227
234
  }
228
- function referenceLabel(sessionId, title) {
229
- return title === void 0 ? sessionId : `${title} (${sessionId})`;
230
- }
231
235
  async function resolveBeyondListing(ctx, invocation, reference) {
232
236
  try {
233
237
  const view = await ctx.devLead.getSession(invocation.agent, reference, invocation.signal);
@@ -272,15 +276,15 @@ async function executeWatch(ctx, invocation, command) {
272
276
  const target = await resolveWatchTarget(ctx, invocation, command.session, view.sessions);
273
277
  if (target.kind === "failure") return target.result;
274
278
  const { sessionId } = target;
275
- const label = referenceLabel(sessionId, target.title);
279
+ const label = sessionRefLabel(sessionId, target.title);
276
280
  const watching = view.sessions.includes(sessionId);
277
281
  if (command.kind === "watch") {
278
282
  const title2 = watching ? `Already watching ${label}.` : `Now watching ${label}.`;
279
- if (!watching) await ctx.devLead.watchSession(invocation.agent, sessionId, true);
283
+ if (!watching) await ctx.devLead.watchSession(invocation.agent, sessionId, true, invocation.signal);
280
284
  return renderStatus(await collectStatus(ctx, invocation), title2);
281
285
  }
282
286
  const title = watching ? `Stopped watching ${label}.` : `Not watching ${label}.`;
283
- if (watching) await ctx.devLead.watchSession(invocation.agent, sessionId, false);
287
+ if (watching) await ctx.devLead.watchSession(invocation.agent, sessionId, false, invocation.signal);
284
288
  return renderStatus(await collectStatus(ctx, invocation), title);
285
289
  }
286
290
  function friendlyDevLeadError(error) {
@@ -288,13 +292,13 @@ function friendlyDevLeadError(error) {
288
292
  case "DEVLEAD_NOT_ENABLED":
289
293
  return NOT_ENABLED_MESSAGE;
290
294
  case "DEVLEAD_AGENT_NOT_LIVE":
291
- return "This Session is no longer live, so DevLead mode cannot be changed. Open it again from the sidebar and retry.";
295
+ return "This Session is no longer live in this Host, so the command cannot run. Open it again from the sidebar and retry.";
292
296
  case "DEVLEAD_INVALID_INPUT":
293
297
  return `The /devlead request is not usable: ${error.message}`;
294
298
  case "DEVLEAD_SESSION_NOT_FOUND":
295
299
  return `The host could not find that Session: ${error.message}`;
296
300
  case "DEVLEAD_SESSION_ARCHIVED":
297
- return "That Session is archived; unarchive it in DSH before watching or steering it.";
301
+ return "That Session is archived; restore it from the Workspace sidebar before watching it.";
298
302
  case "DEVLEAD_SESSION_UNAVAILABLE":
299
303
  return `That Session cannot be resumed right now: ${error.message}`;
300
304
  case "DEVLEAD_WATCH_LIMIT":
@@ -313,11 +317,6 @@ function friendlyDevLeadError(error) {
313
317
  }
314
318
  async function executeDevLeadCommand(ctx, invocation) {
315
319
  const command = parseDevLeadCommand(invocation.rawInput);
316
- if (invocation.attachments.length > 0) {
317
- return errorResult(
318
- "The /devlead command does not accept attachments; use the plain command text instead."
319
- );
320
- }
321
320
  if (command.kind === "invalid") return errorResult(`${command.message}
322
321
  ${USAGE}`);
323
322
  try {
@@ -341,6 +340,9 @@ function apply(ctx) {
341
340
  definitionId: CommandDefinitionId("@yankeguo/dsh-command-devlead"),
342
341
  name: DEVLEAD_COMMAND_NAME2,
343
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.
344
346
  input: { hint: COMMAND_GRAMMAR },
345
347
  handler: (invocation) => executeDevLeadCommand(ctx, invocation)
346
348
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yankeguo/dsh-command-devlead",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
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
5
  "license": "MIT",
6
6
  "type": "module",
@@ -17,8 +17,8 @@
17
17
  "@deepseek-ai/dsh-commands": "0.2.2-rc.1"
18
18
  },
19
19
  "dependencies": {
20
- "@yankeguo/dsh-devlead": "0.1.0",
21
- "@yankeguo/dsh-devlead-protocol": "0.1.0"
20
+ "@yankeguo/dsh-devlead": "0.1.1",
21
+ "@yankeguo/dsh-devlead-protocol": "0.1.1"
22
22
  },
23
23
  "engines": {
24
24
  "dsh": ">=0.2.2-rc.1 <0.3.0"