@yankeguo/dsh-devlead 0.2.0 → 0.2.2

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/lib/index.js CHANGED
@@ -15849,17 +15849,32 @@ async function resolveExactSession(deps, reference) {
15849
15849
  return void 0;
15850
15850
  }
15851
15851
  }
15852
+ var SESSION_ID_PREFIX = "session-";
15853
+ function matchSessionIds(candidates, reference) {
15854
+ const mayOmitPrefix = !reference.startsWith(SESSION_ID_PREFIX);
15855
+ const matched = /* @__PURE__ */ new Set();
15856
+ for (const id of candidates) {
15857
+ if (id.startsWith(reference)) {
15858
+ matched.add(id);
15859
+ continue;
15860
+ }
15861
+ if (mayOmitPrefix && id.startsWith(SESSION_ID_PREFIX) && id.slice(SESSION_ID_PREFIX.length).startsWith(reference)) {
15862
+ matched.add(id);
15863
+ }
15864
+ }
15865
+ return [...matched];
15866
+ }
15852
15867
  async function resolveSessionReference(deps, reference) {
15853
15868
  const trimmed = reference.trim();
15854
15869
  if (trimmed.length === 0) throw new DevLeadError("a Session id is required", "DEVLEAD_INVALID_INPUT");
15855
15870
  const exact = await resolveExactSession(deps, trimmed);
15856
15871
  if (exact !== void 0) return exact;
15857
15872
  const candidates = await collectSessionIds(deps, void 0, true);
15858
- const matched = candidates.filter((id) => id.startsWith(trimmed));
15873
+ const matched = matchSessionIds(candidates, trimmed);
15859
15874
  const resolvedId = matched.find((id) => id === trimmed) ?? (matched.length === 1 ? matched[0] : void 0);
15860
15875
  if (resolvedId === void 0 && matched.length === 0) {
15861
15876
  throw new DevLeadError(
15862
- `no Session matches "${reference}"; list the addressable Sessions with devlead_list_sessions`,
15877
+ `no Session matches "${reference}"; the id may be incomplete or truncated, so look up the full id with devlead_list_sessions and retry`,
15863
15878
  "DEVLEAD_SESSION_NOT_FOUND"
15864
15879
  );
15865
15880
  }
@@ -15941,6 +15956,27 @@ function workspacePathFailure(error51, path) {
15941
15956
  "DEVLEAD_INVALID_INPUT"
15942
15957
  );
15943
15958
  }
15959
+ var MAX_REPORTED_ACTIVITY_ITEMS = 3;
15960
+ function isActiveSessionFailure(error51) {
15961
+ if (typeof error51 !== "object" || error51 === null) return false;
15962
+ const candidate = error51;
15963
+ return candidate.name === "WorkspaceActiveSessionError" && Array.isArray(candidate.activity);
15964
+ }
15965
+ function isUnknownSessionFailure(error51) {
15966
+ if (typeof error51 !== "object" || error51 === null) return false;
15967
+ return error51.name === "WorkspaceUnknownSessionError";
15968
+ }
15969
+ function describeSessionActivity(activity) {
15970
+ if (activity.length === 0) return "unspecified activity";
15971
+ return activity.map((entry) => {
15972
+ const kind = String(entry.kind);
15973
+ const items = entry.items ?? [];
15974
+ if (items.length === 0) return kind;
15975
+ const labels = items.slice(0, MAX_REPORTED_ACTIVITY_ITEMS).map((item) => item.label ?? item.id);
15976
+ const omitted = items.length - labels.length;
15977
+ return `${kind} (${labels.join(", ")}${omitted > 0 ? `, +${String(omitted)} more` : ""})`;
15978
+ }).join("; ");
15979
+ }
15944
15980
  var DevLeadService = class extends Service {
15945
15981
  static inject = ["agents", "sessions", "sessionProjections"];
15946
15982
  /** Loader schema, applied by the Loader before construction. */
@@ -16369,6 +16405,36 @@ var DevLeadService = class extends Service {
16369
16405
  }
16370
16406
  return await devLeadWorkspaceView(workspace);
16371
16407
  }
16408
+ /**
16409
+ * Close one Workspace by removing its DSH registration.
16410
+ *
16411
+ * This is the registry's own `remove` action, not a deletion: the directory,
16412
+ * its files, and every Session log stay untouched. The Workspace's Sessions
16413
+ * become ungrouped — still openable and continuable — and re-registering the
16414
+ * same directory creates a new registration that does not adopt them.
16415
+ *
16416
+ * The returned view is the pre-removal snapshot, so the caller can report
16417
+ * what it closed and which Sessions it accounted to.
16418
+ * @param agent - exact live lead Agent making the removal.
16419
+ * @param workspace - Workspace id or canonical/registered path.
16420
+ * @param signal - cancellation checked before the registry write.
16421
+ * @returns the pre-removal Workspace view and whether a registration was
16422
+ * removed (`false` when another actor removed it first).
16423
+ * @throws {@link DevLeadError} `DEVLEAD_NOT_ENABLED`/`DEVLEAD_AGENT_NOT_LIVE`
16424
+ * for a disallowed caller, `DEVLEAD_WORKSPACE_NOT_FOUND` when the Host
16425
+ * composes no registry or nothing matches the reference.
16426
+ */
16427
+ async removeWorkspace(agent, workspace, signal) {
16428
+ this.assertReady(agent);
16429
+ signal?.throwIfAborted();
16430
+ const registry2 = this.requireWorkspaceRegistry();
16431
+ const resolved = await resolveWorkspaceReference(this.ctx, workspace, signal);
16432
+ signal?.throwIfAborted();
16433
+ const view = await devLeadWorkspaceView(resolved);
16434
+ signal?.throwIfAborted();
16435
+ const removed = await registry2.delete(resolved.id);
16436
+ return { workspace: view, removed };
16437
+ }
16372
16438
  // ---------------------------------------------------------------------------
16373
16439
  // Sessions
16374
16440
  // ---------------------------------------------------------------------------
@@ -16572,6 +16638,88 @@ var DevLeadService = class extends Service {
16572
16638
  resumed
16573
16639
  };
16574
16640
  }
16641
+ /**
16642
+ * Close one Session by archiving it in the Workspace registry.
16643
+ *
16644
+ * Archiving is the DSH `archive` action: the Session disappears from grouping
16645
+ * surfaces but its log is kept, and {@link unarchiveSession} restores it to
16646
+ * its recorded Workspace position. It is idempotent: an already archived
16647
+ * Session resolves without writing, asking, or stopping anything, and
16648
+ * `stopped` is then `false` even when `stopRunning` is true.
16649
+ *
16650
+ * With `stopRunning` unset the Host refuses a Session whose running work was
16651
+ * reported by a `workspace/session-activity` provider; that refusal is mapped
16652
+ * to `DEVLEAD_SESSION_ACTIVE` with the activity families in the message.
16653
+ * With `stopRunning: true` the archive is written first and the Host is then
16654
+ * asked to stop that work through the same providers the human's own stop
16655
+ * action uses; running work is never awaited to settlement, so the result
16656
+ * reports `stopped: true` as soon as the requests were issued.
16657
+ *
16658
+ * A lead Session can never archive itself: that would pause its own
16659
+ * notification delivery, and `stopRunning` would cancel the very turn making
16660
+ * the call. The rejection is a domain error that points the human at the
16661
+ * Workspace sidebar.
16662
+ * @param agent - exact live lead Agent making the archival.
16663
+ * @param sessionId - Session id, unique prefix, or bare uuid prefix.
16664
+ * @param options - stop-running policy (default `false`) and cancellation
16665
+ * checked before the registry write.
16666
+ * @returns the archived Session identity and whether the Host was asked to
16667
+ * stop the Session's running work (`false` when it was already archived).
16668
+ * @throws {@link DevLeadError} `DEVLEAD_NOT_ENABLED`/`DEVLEAD_AGENT_NOT_LIVE`
16669
+ * for a disallowed caller, `DEVLEAD_INVALID_INPUT` for the lead's own
16670
+ * Session, `DEVLEAD_SESSION_NOT_FOUND` for an unknown Session,
16671
+ * `DEVLEAD_SESSION_ACTIVE` for running work without `stopRunning`, and
16672
+ * `DEVLEAD_WORKSPACE_NOT_FOUND` when the Host composes no registry.
16673
+ */
16674
+ async archiveSession(agent, sessionId, options = {}) {
16675
+ this.assertReady(agent);
16676
+ const signal = options.signal;
16677
+ signal?.throwIfAborted();
16678
+ const deps = this.viewDeps(agent, signal);
16679
+ const resolved = await resolveSessionReference(deps, sessionId);
16680
+ const id = String(resolved.sessionId);
16681
+ signal?.throwIfAborted();
16682
+ if (id === String(agent.id)) {
16683
+ throw new DevLeadError(
16684
+ "a DevLead Session cannot archive itself; ask the human to close this Session from the Workspace sidebar",
16685
+ "DEVLEAD_INVALID_INPUT"
16686
+ );
16687
+ }
16688
+ const registry2 = this.requireWorkspaceRegistry();
16689
+ if (registry2.archivedSessionIds.includes(resolved.sessionId)) {
16690
+ return { sessionId: id, archived: true, stopped: false };
16691
+ }
16692
+ const stopRunning = options.stopRunning ?? false;
16693
+ try {
16694
+ await registry2.archiveSession(resolved.sessionId, { stopActivity: stopRunning });
16695
+ } catch (error51) {
16696
+ throw this.archiveFailure(id, error51) ?? error51;
16697
+ }
16698
+ return { sessionId: id, archived: true, stopped: stopRunning };
16699
+ }
16700
+ /**
16701
+ * Restore one archived Session to its recorded Workspace position.
16702
+ *
16703
+ * Unarchiving is idempotent: an id that is not archived resolves without
16704
+ * writing. The Session log was never touched by the archive.
16705
+ * @param agent - exact live lead Agent making the restore.
16706
+ * @param sessionId - Session id, unique prefix, or bare uuid prefix.
16707
+ * @param signal - cancellation checked before the registry write.
16708
+ * @returns the restored Session identity.
16709
+ * @throws {@link DevLeadError} `DEVLEAD_SESSION_NOT_FOUND` when nothing
16710
+ * matches the reference, `DEVLEAD_WORKSPACE_NOT_FOUND` when the Host
16711
+ * composes no registry, and the caller errors of {@link assertReady}.
16712
+ */
16713
+ async unarchiveSession(agent, sessionId, signal) {
16714
+ this.assertReady(agent);
16715
+ signal?.throwIfAborted();
16716
+ const deps = this.viewDeps(agent, signal);
16717
+ const resolved = await resolveSessionReference(deps, sessionId);
16718
+ signal?.throwIfAborted();
16719
+ const registry2 = this.requireWorkspaceRegistry();
16720
+ await registry2.unarchiveSession(resolved.sessionId);
16721
+ return { sessionId: String(resolved.sessionId), archived: false };
16722
+ }
16575
16723
  /**
16576
16724
  * Add or remove one Session from this lead's watch set.
16577
16725
  * @param agent - exact live lead Agent.
@@ -16811,12 +16959,12 @@ var DevLeadService = class extends Service {
16811
16959
  }
16812
16960
  return [...leads].map(([sessionId, watched]) => ({ sessionId, watched }));
16813
16961
  }
16814
- /** Require the Workspace registry capability. */
16962
+ /** Require the Workspace registry capability (Workspaces and Session archive state). */
16815
16963
  requireWorkspaceRegistry() {
16816
16964
  const registry2 = this.ctx.get("workspaceRegistry");
16817
16965
  if (registry2 === void 0) {
16818
16966
  throw new DevLeadError(
16819
- "this Host composes no Workspace registry, so Workspaces cannot be managed",
16967
+ "this Host composes no Workspace registry, so Workspaces and archived Sessions cannot be managed",
16820
16968
  "DEVLEAD_WORKSPACE_NOT_FOUND"
16821
16969
  );
16822
16970
  }
@@ -16962,6 +17110,29 @@ var DevLeadService = class extends Service {
16962
17110
  if (code === "session/not-found") return new DevLeadError(message, "DEVLEAD_SESSION_NOT_FOUND");
16963
17111
  return new DevLeadError(message, "DEVLEAD_SESSION_UNAVAILABLE");
16964
17112
  }
17113
+ /**
17114
+ * Map one Workspace-registry archive failure to the stable DevLead
17115
+ * vocabulary.
17116
+ * @param sessionId - Session identity the archive addressed.
17117
+ * @param error - failure thrown by `workspaceRegistry.archiveSession`.
17118
+ * @returns the mapped domain failure, or undefined for an infrastructure
17119
+ * failure the caller rethrows unchanged.
17120
+ */
17121
+ archiveFailure(sessionId, error51) {
17122
+ if (isActiveSessionFailure(error51)) {
17123
+ return new DevLeadError(
17124
+ `Session "${sessionId}" is still active (${describeSessionActivity(error51.activity)}); stop that work first, or retry with stop_running: true to archive it and ask the Host to stop it now`,
17125
+ "DEVLEAD_SESSION_ACTIVE"
17126
+ );
17127
+ }
17128
+ if (isUnknownSessionFailure(error51)) {
17129
+ return new DevLeadError(
17130
+ `no Session matches "${sessionId}"; it may have disappeared since it was resolved`,
17131
+ "DEVLEAD_SESSION_NOT_FOUND"
17132
+ );
17133
+ }
17134
+ return void 0;
17135
+ }
16965
17136
  /**
16966
17137
  * Admit one lead-authored prompt into a Session, resuming a cold Session.
16967
17138
  * @param leadAgent - exact live lead Agent.
package/locale/en.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "DevLead",
4
+ "description": "Host core of DevLead mode: the per-Session mode switch, Workspace and Session orchestration for the lead, watched-Session notifications, and the devLead Session projections."
5
+ }
6
+ }
package/locale/zh.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "DevLead",
4
+ "description": "DevLead 模式的 Host 核心:每个会话的模式开关、lead 的 Workspace 与会话编排、被监督会话的通知,以及 devLead 会话投影。"
5
+ }
6
+ }
package/package.json CHANGED
@@ -1,16 +1,18 @@
1
1
  {
2
2
  "name": "@yankeguo/dsh-devlead",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "DevLead mode core service for the DeepSeek Harness: durable per-session mode, Workspace and Session orchestration, watched-session notifications, and the `devLead` Session projection.",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
7
  "main": "lib/index.js",
8
8
  "exports": {
9
9
  ".": "./lib/index.js",
10
+ "./locale/*.json": "./locale/*.json",
10
11
  "./package.json": "./package.json"
11
12
  },
12
13
  "files": [
13
14
  "lib",
15
+ "locale/*.json",
14
16
  "README.md"
15
17
  ],
16
18
  "peerDependencies": {
@@ -41,7 +43,7 @@
41
43
  }
42
44
  },
43
45
  "dependencies": {
44
- "@yankeguo/dsh-devlead-protocol": "0.2.0"
46
+ "@yankeguo/dsh-devlead-protocol": "0.2.2"
45
47
  },
46
48
  "engines": {
47
49
  "dsh": ">=0.2.2-rc.1 <0.3.0"