@yankeguo/dsh-command-devlead 0.1.1 → 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.
- package/README.md +48 -0
- package/lib/index.js +67 -20
- package/package.json +5 -4
package/README.md
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# @yankeguo/dsh-command-devlead
|
|
2
|
+
|
|
3
|
+
The human-facing `/devlead` command behind the UI mode switch; it also owns watch-set changes,
|
|
4
|
+
damage recovery, and the human-readable status view. The status output includes
|
|
5
|
+
`Worktree isolation: available|unavailable` so a human can see whether the optional
|
|
6
|
+
checkout-isolation capability is composed.
|
|
7
|
+
|
|
8
|
+
```text
|
|
9
|
+
/devlead # status: mode, worktree capability, watched sessions, recent notifications
|
|
10
|
+
/devlead on # enable DevLead mode for this Session (human-only)
|
|
11
|
+
/devlead off # disable it; on a frozen fold it recovers by resetting the damaged state
|
|
12
|
+
/devlead reset # human-only recovery: discard this Session's DevLead state (mode/watch/digest)
|
|
13
|
+
/devlead watch <session> # watch a Session by full id or unique prefix
|
|
14
|
+
/devlead unwatch <session> # stop watching it
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
The command parses the DSH `CommandInvocation.rawInput` contract (text after the command name),
|
|
18
|
+
does not accept composer attachments, and renders domain failures as friendly text instead of
|
|
19
|
+
throwing. Prefix references are confirmed with the core's exhaustive resolver before a watch
|
|
20
|
+
mutation, so a bounded listing cannot silently shadow another matching Session. Outcome titles are
|
|
21
|
+
derived from a post-mutation snapshot, so a concurrent command cannot leave the title describing a
|
|
22
|
+
different state than the rendered body.
|
|
23
|
+
|
|
24
|
+
`/devlead reset` appends a `plugin:devlead/reset` durable record: replay applies it before the
|
|
25
|
+
corruption freeze check, so a Session whose earlier `plugin:devlead/*` record is corrupt becomes
|
|
26
|
+
usable again (both projections restart from the default disabled state). `/devlead off` runs the
|
|
27
|
+
same recovery when the fold is frozen; `/devlead on` refuses and asks for the explicit reset.
|
|
28
|
+
|
|
29
|
+
## Install
|
|
30
|
+
|
|
31
|
+
Normally installed as part of the bundle:
|
|
32
|
+
|
|
33
|
+
```sh
|
|
34
|
+
dsh plugin --profile desktop add @yankeguo/dsh-devlead-bundle
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Related docs
|
|
38
|
+
|
|
39
|
+
- [Repository README (English)](https://github.com/yankeguo/dsh-devlead/blob/main/README.md) / [中文](https://github.com/yankeguo/dsh-devlead/blob/main/README.zh.md)
|
|
40
|
+
- [Design notes: command contract and error mapping](https://github.com/yankeguo/dsh-devlead/blob/main/docs/DESIGN.md)
|
|
41
|
+
|
|
42
|
+
## 中文
|
|
43
|
+
|
|
44
|
+
`@yankeguo/dsh-command-devlead` 提供人类 `/devlead` 命令:状态、开关、reset、watch/unwatch。
|
|
45
|
+
0.2.0 起 `/devlead reset`(以及冻结时 `/devlead off`)追加 `plugin:devlead/reset` 记录并解冻
|
|
46
|
+
损坏的 fold;reset 会丢弃该会话的 watch 集合与通知 digest。命令按 DSH `rawInput` 契约解析,
|
|
47
|
+
不接受附件,前缀引用在变更前由 core 穷尽验证,变更后的标题与正文来自同一 post-mutation 快照。完整中文文档见
|
|
48
|
+
[根 README.zh.md](https://github.com/yankeguo/dsh-devlead/blob/main/README.zh.md)与[设计说明](https://github.com/yankeguo/dsh-devlead/blob/main/docs/DESIGN.md)。
|
package/lib/index.js
CHANGED
|
@@ -7,7 +7,7 @@ import { DEVLEAD_COMMAND_NAME as DEVLEAD_COMMAND_NAME2 } from "@yankeguo/dsh-dev
|
|
|
7
7
|
|
|
8
8
|
// packages/command/src/parse.ts
|
|
9
9
|
import { DEVLEAD_COMMAND_NAME } from "@yankeguo/dsh-devlead-protocol";
|
|
10
|
-
var COMMAND_GRAMMAR = "[status|on|off|watch <session>|unwatch <session>]";
|
|
10
|
+
var COMMAND_GRAMMAR = "[status|on|off|reset|watch <session>|unwatch <session>]";
|
|
11
11
|
var USAGE = `Usage: /${DEVLEAD_COMMAND_NAME} ${COMMAND_GRAMMAR}`;
|
|
12
12
|
function invalid(message) {
|
|
13
13
|
return { kind: "invalid", message };
|
|
@@ -57,6 +57,8 @@ function parseDevLeadCommand(rawInput) {
|
|
|
57
57
|
return { kind: "on" };
|
|
58
58
|
case "off":
|
|
59
59
|
return { kind: "off" };
|
|
60
|
+
case "reset":
|
|
61
|
+
return { kind: "reset" };
|
|
60
62
|
default:
|
|
61
63
|
break;
|
|
62
64
|
}
|
|
@@ -71,6 +73,7 @@ function parseDevLeadCommand(rawInput) {
|
|
|
71
73
|
case "status":
|
|
72
74
|
case "on":
|
|
73
75
|
case "off":
|
|
76
|
+
case "reset":
|
|
74
77
|
return unexpectedArgument(head);
|
|
75
78
|
default:
|
|
76
79
|
return invalid(`Unknown /devlead subcommand "${head}".`);
|
|
@@ -85,6 +88,10 @@ import {
|
|
|
85
88
|
} from "@yankeguo/dsh-devlead-protocol";
|
|
86
89
|
|
|
87
90
|
// packages/command/src/resolve.ts
|
|
91
|
+
import {
|
|
92
|
+
DEVLEAD_ERROR_EXCERPT_MAX,
|
|
93
|
+
excerptLine
|
|
94
|
+
} from "@yankeguo/dsh-devlead-protocol";
|
|
88
95
|
function candidateOf(view) {
|
|
89
96
|
return view.title === void 0 ? { sessionId: view.sessionId } : { sessionId: view.sessionId, title: view.title };
|
|
90
97
|
}
|
|
@@ -113,8 +120,8 @@ function resolveSessionReference(query, candidates) {
|
|
|
113
120
|
}
|
|
114
121
|
var MAX_RENDERED_CANDIDATES = 10;
|
|
115
122
|
function sessionRefLabel(sessionId, title) {
|
|
116
|
-
const
|
|
117
|
-
return
|
|
123
|
+
const line = title === void 0 ? void 0 : excerptLine(title, DEVLEAD_ERROR_EXCERPT_MAX);
|
|
124
|
+
return line === void 0 ? sessionId : `${line} (${sessionId})`;
|
|
118
125
|
}
|
|
119
126
|
function candidateLabel(candidate) {
|
|
120
127
|
return sessionRefLabel(candidate.sessionId, candidate.title);
|
|
@@ -129,7 +136,7 @@ function formatCandidates(candidates) {
|
|
|
129
136
|
|
|
130
137
|
// packages/command/src/render.ts
|
|
131
138
|
var RECENT_NOTIFICATION_LIMIT = 5;
|
|
132
|
-
var HELP_LINE = "Help: /devlead (status) | /devlead on | /devlead off | /devlead watch <session> | /devlead unwatch <session>";
|
|
139
|
+
var HELP_LINE = "Help: /devlead (status) | /devlead on | /devlead off | /devlead reset | /devlead watch <session> | /devlead unwatch <session>";
|
|
133
140
|
function modeLabel(enabled) {
|
|
134
141
|
return enabled ? "on" : "off";
|
|
135
142
|
}
|
|
@@ -168,6 +175,7 @@ function notificationLines(snapshot) {
|
|
|
168
175
|
function statusLines(snapshot) {
|
|
169
176
|
const lines = [
|
|
170
177
|
`DevLead mode: ${modeLabel(snapshot.enabled)}`,
|
|
178
|
+
`Worktree isolation: ${snapshot.worktreeIsolation ? "available" : "unavailable"}`,
|
|
171
179
|
...watchedLines(snapshot),
|
|
172
180
|
...notificationLines(snapshot)
|
|
173
181
|
];
|
|
@@ -191,7 +199,7 @@ function errorResult(text) {
|
|
|
191
199
|
// packages/command/src/index.ts
|
|
192
200
|
var name = "command-devlead";
|
|
193
201
|
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.";
|
|
202
|
+
var DESCRIPTION = "Turn DevLead mode on or off for this Session, reset damaged DevLead state, watch or unwatch another Session, and inspect the DevLead mode, watch set, and recent notification digest.";
|
|
195
203
|
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
204
|
async function collectStatus(ctx, invocation) {
|
|
197
205
|
const view = ctx.devLead.view(invocation.agent);
|
|
@@ -211,6 +219,7 @@ async function collectStatus(ctx, invocation) {
|
|
|
211
219
|
}
|
|
212
220
|
return {
|
|
213
221
|
enabled: view.enabled,
|
|
222
|
+
worktreeIsolation: ctx.devLead.worktreeIsolationAvailable,
|
|
214
223
|
watched,
|
|
215
224
|
missingWatched,
|
|
216
225
|
notifications: view.notifications.slice(-RECENT_NOTIFICATION_LIMIT)
|
|
@@ -246,10 +255,10 @@ async function resolveBeyondListing(ctx, invocation, reference) {
|
|
|
246
255
|
async function resolveWatchTarget(ctx, invocation, reference, watchedSessionIds) {
|
|
247
256
|
const candidates = await collectCandidates(ctx, invocation, watchedSessionIds);
|
|
248
257
|
const resolution = resolveSessionReference(reference, candidates);
|
|
249
|
-
if (resolution.kind === "resolved") return resolution;
|
|
250
258
|
if (resolution.kind === "ambiguous") {
|
|
251
259
|
return { kind: "failure", result: ambiguousResult(reference, resolution.candidates) };
|
|
252
260
|
}
|
|
261
|
+
if (resolution.kind === "resolved" && reference === resolution.sessionId) return resolution;
|
|
253
262
|
const fallback = await resolveBeyondListing(ctx, invocation, reference);
|
|
254
263
|
if (fallback.kind === "resolved") return fallback;
|
|
255
264
|
if (fallback.kind === "ambiguous") {
|
|
@@ -261,14 +270,41 @@ Use a longer prefix or the full Session id.`)
|
|
|
261
270
|
}
|
|
262
271
|
return { kind: "failure", result: missingSessionResult(reference) };
|
|
263
272
|
}
|
|
273
|
+
function snapshotWatches(snapshot, sessionId) {
|
|
274
|
+
return snapshot.watched.some((view) => view.sessionId === sessionId) || snapshot.missingWatched.includes(sessionId);
|
|
275
|
+
}
|
|
276
|
+
function modeTitle(requested, previous, actual) {
|
|
277
|
+
if (actual !== requested) {
|
|
278
|
+
return `DevLead mode is ${actual ? "on" : "off"} (another command changed it).`;
|
|
279
|
+
}
|
|
280
|
+
if (previous !== requested) return requested ? "DevLead mode enabled." : "DevLead mode disabled.";
|
|
281
|
+
return requested ? "DevLead mode is already on." : "DevLead mode is already off.";
|
|
282
|
+
}
|
|
283
|
+
function watchTitle(command, label, previous, actual) {
|
|
284
|
+
const requested = command === "watch";
|
|
285
|
+
if (actual !== requested) {
|
|
286
|
+
return requested ? `Not watching ${label} (another command changed it).` : `Still watching ${label} (another command changed it).`;
|
|
287
|
+
}
|
|
288
|
+
if (requested) return previous ? `Already watching ${label}.` : `Now watching ${label}.`;
|
|
289
|
+
return previous ? `Stopped watching ${label}.` : `Not watching ${label}.`;
|
|
290
|
+
}
|
|
264
291
|
async function executeMode(ctx, invocation, enabled) {
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
292
|
+
let previous;
|
|
293
|
+
try {
|
|
294
|
+
previous = ctx.devLead.view(invocation.agent).enabled;
|
|
295
|
+
} catch (error) {
|
|
296
|
+
if (!isDevLeadError(error) || error.code !== "DEVLEAD_PROJECTION_INVALID") throw error;
|
|
297
|
+
if (enabled) throw error;
|
|
298
|
+
await ctx.devLead.setEnabled(invocation.agent, false, invocation.signal);
|
|
299
|
+
const snapshot2 = await collectStatus(ctx, invocation);
|
|
300
|
+
const title = snapshot2.enabled ? "DevLead mode is on (another command changed it)." : "DevLead mode disabled; the damaged DevLead records were reset.";
|
|
301
|
+
return renderStatus(snapshot2, title);
|
|
268
302
|
}
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
303
|
+
if (previous !== enabled) {
|
|
304
|
+
await ctx.devLead.setEnabled(invocation.agent, enabled, invocation.signal);
|
|
305
|
+
}
|
|
306
|
+
const snapshot = await collectStatus(ctx, invocation);
|
|
307
|
+
return renderStatus(snapshot, modeTitle(enabled, previous, snapshot.enabled));
|
|
272
308
|
}
|
|
273
309
|
async function executeWatch(ctx, invocation, command) {
|
|
274
310
|
const view = ctx.devLead.view(invocation.agent);
|
|
@@ -279,13 +315,20 @@ async function executeWatch(ctx, invocation, command) {
|
|
|
279
315
|
const label = sessionRefLabel(sessionId, target.title);
|
|
280
316
|
const watching = view.sessions.includes(sessionId);
|
|
281
317
|
if (command.kind === "watch") {
|
|
282
|
-
const title2 = watching ? `Already watching ${label}.` : `Now watching ${label}.`;
|
|
283
318
|
if (!watching) await ctx.devLead.watchSession(invocation.agent, sessionId, true, invocation.signal);
|
|
284
|
-
|
|
319
|
+
} else if (watching) {
|
|
320
|
+
await ctx.devLead.watchSession(invocation.agent, sessionId, false, invocation.signal);
|
|
285
321
|
}
|
|
286
|
-
const
|
|
287
|
-
|
|
288
|
-
|
|
322
|
+
const snapshot = await collectStatus(ctx, invocation);
|
|
323
|
+
return renderStatus(
|
|
324
|
+
snapshot,
|
|
325
|
+
watchTitle(command.kind, label, watching, snapshotWatches(snapshot, sessionId))
|
|
326
|
+
);
|
|
327
|
+
}
|
|
328
|
+
async function executeReset(ctx, invocation) {
|
|
329
|
+
await ctx.devLead.reset(invocation.agent, invocation.signal);
|
|
330
|
+
const snapshot = await collectStatus(ctx, invocation);
|
|
331
|
+
return renderStatus(snapshot, "DevLead state reset.");
|
|
289
332
|
}
|
|
290
333
|
function friendlyDevLeadError(error) {
|
|
291
334
|
switch (error.code) {
|
|
@@ -306,13 +349,15 @@ function friendlyDevLeadError(error) {
|
|
|
306
349
|
case "DEVLEAD_SELF_WATCH":
|
|
307
350
|
return "A DevLead Session cannot watch itself.";
|
|
308
351
|
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.`;
|
|
352
|
+
return `This Session's DevLead records are damaged, so its DevLead state cannot be read: ${error.message}. Run /devlead reset to discard the damaged state and start over (that also discards the watched-Session set and the notification digest). Inspect the Session log for the offending plugin:devlead record.`;
|
|
310
353
|
case "DEVLEAD_WORKSPACE_NOT_FOUND":
|
|
311
354
|
return `The Workspace could not be resolved: ${error.message}`;
|
|
312
355
|
case "DEVLEAD_DIRECTORY_MISSING":
|
|
313
356
|
return `The target directory is missing: ${error.message}`;
|
|
314
|
-
default:
|
|
315
|
-
|
|
357
|
+
default: {
|
|
358
|
+
const unknownCode = error.code;
|
|
359
|
+
return `The DevLead request failed (${String(unknownCode)}): ${error.message}`;
|
|
360
|
+
}
|
|
316
361
|
}
|
|
317
362
|
}
|
|
318
363
|
async function executeDevLeadCommand(ctx, invocation) {
|
|
@@ -326,6 +371,8 @@ ${USAGE}`);
|
|
|
326
371
|
case "on":
|
|
327
372
|
case "off":
|
|
328
373
|
return await executeMode(ctx, invocation, command.kind === "on");
|
|
374
|
+
case "reset":
|
|
375
|
+
return await executeReset(ctx, invocation);
|
|
329
376
|
case "watch":
|
|
330
377
|
case "unwatch":
|
|
331
378
|
return await executeWatch(ctx, invocation, command);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yankeguo/dsh-command-devlead",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
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",
|
|
@@ -10,15 +10,16 @@
|
|
|
10
10
|
"./package.json": "./package.json"
|
|
11
11
|
},
|
|
12
12
|
"files": [
|
|
13
|
-
"lib"
|
|
13
|
+
"lib",
|
|
14
|
+
"README.md"
|
|
14
15
|
],
|
|
15
16
|
"peerDependencies": {
|
|
16
17
|
"@deepseek-ai/cordis": "~4.1.0",
|
|
17
18
|
"@deepseek-ai/dsh-commands": "0.2.2-rc.1"
|
|
18
19
|
},
|
|
19
20
|
"dependencies": {
|
|
20
|
-
"@yankeguo/dsh-devlead": "0.
|
|
21
|
-
"@yankeguo/dsh-devlead-protocol": "0.
|
|
21
|
+
"@yankeguo/dsh-devlead": "0.2.0",
|
|
22
|
+
"@yankeguo/dsh-devlead-protocol": "0.2.0"
|
|
22
23
|
},
|
|
23
24
|
"engines": {
|
|
24
25
|
"dsh": ">=0.2.2-rc.1 <0.3.0"
|