@yankeguo/dsh-devlead 0.2.5 → 0.3.0-rc.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/README.md +18 -7
- package/lib/index.js +422 -71
- package/locale/zh.json +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Core Host service of the DevLead suite (`ctx.devLead`): the durable mode switch, damage-recovery
|
|
4
4
|
`reset()`, Workspace and Session orchestration (including `useWorkspace(agent, request, signal?)`
|
|
5
5
|
with directory creation opt-in), the watched-session notification hub with cold-lead rehydration, the mid-turn report channel for watched Sessions,
|
|
6
|
-
and the `devLead` / `devLeadMode` Session projections.
|
|
6
|
+
and the `devLead` / `devLeadMode` / `devLeadWatch` Session projections.
|
|
7
7
|
|
|
8
8
|
DevLead mode is **globally single-active**: at most one Session (across every Workspace) may be
|
|
9
9
|
enabled. `setEnabled(agent, true)` throws `DEVLEAD_ALREADY_ACTIVE` naming the occupant when another
|
|
@@ -11,11 +11,22 @@ Session holds it; `off`/`reset` release immediately, archiving or deleting the h
|
|
|
11
11
|
releasable, and a restart/rehydration reconciles historical duplicates and keeps one Session.
|
|
12
12
|
Admission is serialized in-process and scans live projections plus the durable corpus.
|
|
13
13
|
|
|
14
|
+
`sessionQueuedInputs(agent, sessionId, signal?)` projects a live Session's pending inbox inputs
|
|
15
|
+
(id, boundary, source kind/form/sender, bounded text excerpt, enqueue instant from the durable
|
|
16
|
+
`agent/inbox/spliced` log); a cold target reports undefined. `retractQueuedInput(agent, sessionId,
|
|
17
|
+
inputId, signal?)` withdraws one queued input this lead authored (devlead relay with its own
|
|
18
|
+
sender id) through the Host's per-message `inbox.remove`; other producers' inputs are refused,
|
|
19
|
+
an already-gone input is idempotent (`retracted: false`), and the target must be live and not the
|
|
20
|
+
lead itself. `promptSession` accepts `interruptInbox: 'clear-all' | 'keep' | 'clear-own'`
|
|
21
|
+
(default `clear-all`): because the Host stop providers always clear the inbox, retention is a
|
|
22
|
+
snapshot before the stop and a restore of the same identified messages after it, ahead of the
|
|
23
|
+
replacement prompt; the result reports `retainedInputs` when a retention policy ran.
|
|
24
|
+
|
|
14
25
|
`reportProgress(agent, { message, kind?, summary? }, signal?)` lets a watched, non-DevLead Session
|
|
15
|
-
send a one-way report to its unique active lead. It resolves the
|
|
16
|
-
reverse index, validates size/kind, deduplicates identical
|
|
17
|
-
distinct reports per turn (`DEVLEAD_REPORT_RATE_LIMITED`
|
|
18
|
-
`DEVLEAD_NOT_SUPERVISED`. The receipt is `{ report, durable, queued, warning? }`.
|
|
26
|
+
send a one-way report to its unique active lead. It resolves the active lead that watches it through
|
|
27
|
+
the hub's reverse index, validates size/kind, deduplicates identical kind+message pairs within a turn, enforces four
|
|
28
|
+
distinct non-question reports per turn (`DEVLEAD_REPORT_RATE_LIMITED`; `question` reports are exempt
|
|
29
|
+
from that budget), and otherwise refuses with `DEVLEAD_NOT_SUPERVISED`. The receipt is `{ report, durable, queued, warning? }`.
|
|
19
30
|
|
|
20
31
|
The report is first written to a durable outbox (`devlead_report_outbox` over the optional
|
|
21
32
|
`storageDomain` KV facility), then a `plugin:devlead/report` receipt is appended to the lead's
|
|
@@ -37,7 +48,7 @@ dsh plugin --profile desktop add @yankeguo/dsh-devlead-bundle
|
|
|
37
48
|
|
|
38
49
|
## Requirements
|
|
39
50
|
|
|
40
|
-
- DSH `0.2.2-rc.1`–`0.2.2-rc.
|
|
51
|
+
- DSH `0.2.2-rc.1`–`0.2.2-rc.5` (the package declares `engines.dsh: >=0.2.2-rc.1 <0.3.0`; this checkout's devDependencies pin rc.1 for the oldest-API typecheck).
|
|
41
52
|
- Peer services `agents`, `sessions`, `sessionProjections` (provided by the default `dsh-base`
|
|
42
53
|
composition).
|
|
43
54
|
- Optional, probed at call time: `workspaceRegistry`, `sessionController`, `sessionTitle`,
|
|
@@ -70,7 +81,7 @@ validated at both the Loader and direct-construction boundaries.
|
|
|
70
81
|
|
|
71
82
|
`@yankeguo/dsh-devlead` 是套件的 Host 核心服务 `ctx.devLead`:模式开关、损坏状态恢复
|
|
72
83
|
`reset()`、Workspace/Session 编排(`useWorkspace(agent, request, signal?)`,目录创建 opt-in)、
|
|
73
|
-
带冷 lead
|
|
84
|
+
带冷 lead 索引重建的关注关系索引与通知投递,以及 `devLead` / `devLeadMode` / `devLeadWatch` projection。
|
|
74
85
|
`agents`、`sessions`、`sessionProjections` 为必需 peer;Workspace registry、Session controller、
|
|
75
86
|
标题/查询服务、projection cache、`sessionPersistence`(冷重建就绪屏障)与实验性 worktree 能力
|
|
76
87
|
均为可选探测。完整中文文档见[根 README.zh.md](https://github.com/yankeguo/dsh-devlead/blob/main/README.zh.md)与
|
package/lib/index.js
CHANGED
|
@@ -9,7 +9,7 @@ var __export = (target, all) => {
|
|
|
9
9
|
import { mkdir } from "node:fs/promises";
|
|
10
10
|
import { Service } from "@deepseek-ai/cordis";
|
|
11
11
|
import z2 from "@deepseek-ai/schemastery";
|
|
12
|
-
import { ReasoningEffortId } from "@deepseek-ai/dsh-llm";
|
|
12
|
+
import { MessageId, ReasoningEffortId } from "@deepseek-ai/dsh-llm";
|
|
13
13
|
import { appendPluginRecord as appendPluginRecord2 } from "@deepseek-ai/dsh-session";
|
|
14
14
|
import { SessionId as toSessionId3 } from "@deepseek-ai/dsh-session";
|
|
15
15
|
import {
|
|
@@ -114,8 +114,9 @@ function devLeadReport(input) {
|
|
|
114
114
|
const title = input.senderSessionTitle === void 0 ? void 0 : excerptLine(input.senderSessionTitle, DEVLEAD_ERROR_EXCERPT_MAX);
|
|
115
115
|
const summary = input.summary === void 0 ? void 0 : excerptLine(input.summary, DEVLEAD_REPORT_SUMMARY_MAX);
|
|
116
116
|
const workspaceTitle = input.senderWorkspaceTitle === void 0 ? void 0 : excerptLine(input.senderWorkspaceTitle, DEVLEAD_ERROR_EXCERPT_MAX);
|
|
117
|
+
const turn = Number.isSafeInteger(input.turn) && input.turn >= 0 ? input.turn : 0;
|
|
117
118
|
return {
|
|
118
|
-
id: devLeadReportId(input.senderSessionId,
|
|
119
|
+
id: devLeadReportId(input.senderSessionId, turn, input.kind, message),
|
|
119
120
|
kind: input.kind,
|
|
120
121
|
message,
|
|
121
122
|
...summary === void 0 ? {} : { summary },
|
|
@@ -124,7 +125,7 @@ function devLeadReport(input) {
|
|
|
124
125
|
...input.senderWorkspaceId === void 0 ? {} : { senderWorkspaceId: input.senderWorkspaceId },
|
|
125
126
|
...workspaceTitle === void 0 ? {} : { senderWorkspaceTitle: workspaceTitle },
|
|
126
127
|
leadSessionId: input.leadSessionId,
|
|
127
|
-
turn
|
|
128
|
+
turn,
|
|
128
129
|
at: representableInstant(input.at, Date.now())
|
|
129
130
|
};
|
|
130
131
|
}
|
|
@@ -343,7 +344,7 @@ function assistantExcerpt(blocks) {
|
|
|
343
344
|
return excerptLine(text, DEVLEAD_ERROR_EXCERPT_MAX);
|
|
344
345
|
}
|
|
345
346
|
|
|
346
|
-
// packages/devlead/src/
|
|
347
|
+
// packages/devlead/src/normalize.ts
|
|
347
348
|
function stringField(value) {
|
|
348
349
|
return typeof value === "string" ? value : "";
|
|
349
350
|
}
|
|
@@ -353,6 +354,8 @@ function recordOf(value) {
|
|
|
353
354
|
function itemsOf(value) {
|
|
354
355
|
return Array.isArray(value) ? value : [];
|
|
355
356
|
}
|
|
357
|
+
|
|
358
|
+
// packages/devlead/src/dispatch.ts
|
|
356
359
|
function modelViewOf(value) {
|
|
357
360
|
const record2 = recordOf(value);
|
|
358
361
|
if (record2 === void 0) return void 0;
|
|
@@ -475,6 +478,89 @@ function agentTeamsCapabilityOf(ctx) {
|
|
|
475
478
|
return candidate;
|
|
476
479
|
}
|
|
477
480
|
|
|
481
|
+
// packages/devlead/src/inbox.ts
|
|
482
|
+
import { DEVLEAD_ERROR_EXCERPT_MAX as DEVLEAD_ERROR_EXCERPT_MAX2, DEVLEAD_MESSAGE_KIND as DEVLEAD_MESSAGE_KIND2, excerptLine as excerptLine2 } from "@yankeguo/dsh-devlead-protocol";
|
|
483
|
+
function sourceString(source, key) {
|
|
484
|
+
const value = source[key];
|
|
485
|
+
return typeof value === "string" && value.length > 0 ? value : void 0;
|
|
486
|
+
}
|
|
487
|
+
function sourceOf(message) {
|
|
488
|
+
const source = message.source;
|
|
489
|
+
return typeof source === "object" && source !== null && !Array.isArray(source) ? source : {};
|
|
490
|
+
}
|
|
491
|
+
function isOwnRelay(message, leadSessionId) {
|
|
492
|
+
const source = sourceOf(message);
|
|
493
|
+
return source.kind === DEVLEAD_MESSAGE_KIND2 && source.form === "relay" && source.senderSessionId === leadSessionId;
|
|
494
|
+
}
|
|
495
|
+
function locatedInputs(agent) {
|
|
496
|
+
return [
|
|
497
|
+
...agent.inbox.nextTurn.map((message) => ({ boundary: "next-turn", message })),
|
|
498
|
+
...agent.inbox.nextStep.map((message) => ({ boundary: "next-step", message }))
|
|
499
|
+
];
|
|
500
|
+
}
|
|
501
|
+
function enqueuedTimes(session, ids) {
|
|
502
|
+
const times = /* @__PURE__ */ new Map();
|
|
503
|
+
if (ids.size === 0) return times;
|
|
504
|
+
const events = session.snapshotEvents();
|
|
505
|
+
for (let index = events.length - 1; index >= 0 && times.size < ids.size; index -= 1) {
|
|
506
|
+
const event = events[index];
|
|
507
|
+
if (event?.type !== "agent/inbox/spliced") continue;
|
|
508
|
+
const inserted = event.data.inserted;
|
|
509
|
+
if (!Array.isArray(inserted)) continue;
|
|
510
|
+
for (const candidate of inserted) {
|
|
511
|
+
const id = candidate?.id;
|
|
512
|
+
if (typeof id === "string" && ids.has(id) && !times.has(id)) times.set(id, event.time);
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
return times;
|
|
516
|
+
}
|
|
517
|
+
function textExcerpt(message) {
|
|
518
|
+
const blocks = message.content;
|
|
519
|
+
if (!Array.isArray(blocks)) return void 0;
|
|
520
|
+
const text = blocks.filter((block) => typeof block === "object" && block !== null && block.type === "text" && typeof block.text === "string").map((block) => block.text).join(" ");
|
|
521
|
+
return excerptLine2(text, DEVLEAD_ERROR_EXCERPT_MAX2);
|
|
522
|
+
}
|
|
523
|
+
function queuedInputsOf(agent) {
|
|
524
|
+
const located = locatedInputs(agent);
|
|
525
|
+
const times = enqueuedTimes(agent.session, new Set(located.map((entry) => String(entry.message.id))));
|
|
526
|
+
return located.map(({ boundary, message }) => {
|
|
527
|
+
const source = sourceOf(message);
|
|
528
|
+
const id = String(message.id);
|
|
529
|
+
const excerpt = textExcerpt(message);
|
|
530
|
+
const enqueuedAt = times.get(id);
|
|
531
|
+
const sourceForm = sourceString(source, "form");
|
|
532
|
+
const senderSessionId = sourceString(source, "senderSessionId");
|
|
533
|
+
return {
|
|
534
|
+
id,
|
|
535
|
+
boundary,
|
|
536
|
+
sourceKind: sourceString(source, "kind") ?? "unknown",
|
|
537
|
+
...sourceForm === void 0 ? {} : { sourceForm },
|
|
538
|
+
...senderSessionId === void 0 ? {} : { senderSessionId },
|
|
539
|
+
...excerpt === void 0 ? {} : { excerpt },
|
|
540
|
+
...enqueuedAt === void 0 ? {} : { enqueuedAt }
|
|
541
|
+
};
|
|
542
|
+
});
|
|
543
|
+
}
|
|
544
|
+
function restoreInputs(agent, kept) {
|
|
545
|
+
const pending = new Set(locatedInputs(agent).map((entry) => String(entry.message.id)));
|
|
546
|
+
let restored = 0;
|
|
547
|
+
for (let index = kept.length - 1; index >= 0; index -= 1) {
|
|
548
|
+
const entry = kept[index];
|
|
549
|
+
if (entry === void 0) continue;
|
|
550
|
+
const id = String(entry.message.id);
|
|
551
|
+
if (pending.has(id)) continue;
|
|
552
|
+
agent.inbox.prepend(entry.boundary, entry.message);
|
|
553
|
+
pending.add(id);
|
|
554
|
+
restored += 1;
|
|
555
|
+
}
|
|
556
|
+
return restored;
|
|
557
|
+
}
|
|
558
|
+
function keptInputsOf(agent, leadSessionId, policy) {
|
|
559
|
+
if (policy === "clear-all") return [];
|
|
560
|
+
const located = locatedInputs(agent);
|
|
561
|
+
return policy === "keep" ? located : located.filter((entry) => !isOwnRelay(entry.message, leadSessionId));
|
|
562
|
+
}
|
|
563
|
+
|
|
478
564
|
// node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/classic/external.js
|
|
479
565
|
var external_exports = {};
|
|
480
566
|
__export(external_exports, {
|
|
@@ -15226,7 +15312,7 @@ var DevLeadReportOutbox = class _DevLeadReportOutbox {
|
|
|
15226
15312
|
import { pluginRecordOf } from "@deepseek-ai/dsh-session";
|
|
15227
15313
|
import {
|
|
15228
15314
|
DEVLEAD_DEFAULT_NOTIFICATION_RETENTION as DEVLEAD_DEFAULT_NOTIFICATION_RETENTION2,
|
|
15229
|
-
DEVLEAD_ERROR_EXCERPT_MAX as
|
|
15315
|
+
DEVLEAD_ERROR_EXCERPT_MAX as DEVLEAD_ERROR_EXCERPT_MAX3,
|
|
15230
15316
|
DEVLEAD_MAX_INSTANT as DEVLEAD_MAX_INSTANT3,
|
|
15231
15317
|
DEVLEAD_MODE_PROJECTION_KEY,
|
|
15232
15318
|
DEVLEAD_MODE_RECORD_TYPE as DEVLEAD_MODE_RECORD_TYPE2,
|
|
@@ -15239,6 +15325,7 @@ import {
|
|
|
15239
15325
|
DEVLEAD_REPORT_SUMMARY_MAX as DEVLEAD_REPORT_SUMMARY_MAX3,
|
|
15240
15326
|
DEVLEAD_RESET_RECORD_TYPE as DEVLEAD_RESET_RECORD_TYPE2,
|
|
15241
15327
|
DEVLEAD_TRANSITIONS,
|
|
15328
|
+
DEVLEAD_WATCH_PROJECTION_KEY,
|
|
15242
15329
|
DEVLEAD_WATCH_RECORD_TYPE as DEVLEAD_WATCH_RECORD_TYPE2,
|
|
15243
15330
|
devLeadReportId as devLeadReportId3,
|
|
15244
15331
|
notificationId as notificationId2
|
|
@@ -15247,8 +15334,8 @@ function emptyDevLeadProjectionState() {
|
|
|
15247
15334
|
return { enabled: false, sessions: [], notifications: [], reports: [], failure: null };
|
|
15248
15335
|
}
|
|
15249
15336
|
var excerptSchema = external_exports.string().min(1).refine(
|
|
15250
|
-
(value) => value.length <=
|
|
15251
|
-
{ message: `excerpt must be at most ${
|
|
15337
|
+
(value) => value.length <= DEVLEAD_ERROR_EXCERPT_MAX3 * 2 && Array.from(value).length <= DEVLEAD_ERROR_EXCERPT_MAX3,
|
|
15338
|
+
{ message: `excerpt must be at most ${DEVLEAD_ERROR_EXCERPT_MAX3} code points` }
|
|
15252
15339
|
);
|
|
15253
15340
|
var notificationSchema = external_exports.object({
|
|
15254
15341
|
id: external_exports.string().min(1),
|
|
@@ -15413,6 +15500,80 @@ var devLeadProjectionDefinition = {
|
|
|
15413
15500
|
// are discarded and refolded from the durable log.
|
|
15414
15501
|
stateVersion: 2
|
|
15415
15502
|
};
|
|
15503
|
+
function emptyDevLeadWatchProjectionState() {
|
|
15504
|
+
return { sessions: [], failure: null };
|
|
15505
|
+
}
|
|
15506
|
+
var devLeadWatchProjectionStateSchema = external_exports.object({
|
|
15507
|
+
sessions: external_exports.array(external_exports.string().min(1)).refine(
|
|
15508
|
+
(sessions) => new Set(sessions).size === sessions.length,
|
|
15509
|
+
{ message: "watch sessions must be unique" }
|
|
15510
|
+
),
|
|
15511
|
+
failure: external_exports.string().min(1).nullable()
|
|
15512
|
+
}).strict();
|
|
15513
|
+
var devLeadWatchProjectionSchema = external_exports.object({
|
|
15514
|
+
sessions: external_exports.array(external_exports.string().min(1)).refine(
|
|
15515
|
+
(sessions) => new Set(sessions).size === sessions.length,
|
|
15516
|
+
{ message: "watch sessions must be unique" }
|
|
15517
|
+
)
|
|
15518
|
+
}).strict();
|
|
15519
|
+
function devLeadWatchProjectionView(state) {
|
|
15520
|
+
return { sessions: state.sessions };
|
|
15521
|
+
}
|
|
15522
|
+
function applyDevLeadWatchProjection(state, event) {
|
|
15523
|
+
const record2 = pluginRecordOf(event);
|
|
15524
|
+
if (record2 === void 0) return state;
|
|
15525
|
+
if (record2.type === DEVLEAD_RESET_RECORD_TYPE2) {
|
|
15526
|
+
try {
|
|
15527
|
+
decodeResetRecord(record2.data);
|
|
15528
|
+
return emptyDevLeadWatchProjectionState();
|
|
15529
|
+
} catch (error51) {
|
|
15530
|
+
if (state.failure !== null) return state;
|
|
15531
|
+
const message = error51 instanceof Error ? error51.message : String(error51);
|
|
15532
|
+
return {
|
|
15533
|
+
...state,
|
|
15534
|
+
failure: `devlead watch replay failed at session event ${event.seq} (${record2.type}): ${message}`
|
|
15535
|
+
};
|
|
15536
|
+
}
|
|
15537
|
+
}
|
|
15538
|
+
if (state.failure !== null) return state;
|
|
15539
|
+
try {
|
|
15540
|
+
switch (record2.type) {
|
|
15541
|
+
case DEVLEAD_WATCH_RECORD_TYPE2: {
|
|
15542
|
+
const watch = decodeWatchRecord(record2.data);
|
|
15543
|
+
return sameSessionIds(state.sessions, watch.sessions) ? state : { sessions: watch.sessions, failure: null };
|
|
15544
|
+
}
|
|
15545
|
+
case DEVLEAD_MODE_RECORD_TYPE2:
|
|
15546
|
+
decodeModeRecord(record2.data);
|
|
15547
|
+
return state;
|
|
15548
|
+
case DEVLEAD_NOTIFICATION_RECORD_TYPE2:
|
|
15549
|
+
decodeNotificationRecord(record2.data);
|
|
15550
|
+
return state;
|
|
15551
|
+
case DEVLEAD_REPORT_RECORD_TYPE2:
|
|
15552
|
+
decodeReportRecord(record2.data);
|
|
15553
|
+
return state;
|
|
15554
|
+
default:
|
|
15555
|
+
return state;
|
|
15556
|
+
}
|
|
15557
|
+
} catch (error51) {
|
|
15558
|
+
const message = error51 instanceof Error ? error51.message : String(error51);
|
|
15559
|
+
return {
|
|
15560
|
+
...state,
|
|
15561
|
+
failure: `devlead watch replay failed at session event ${event.seq} (${record2.type}): ${message}`
|
|
15562
|
+
};
|
|
15563
|
+
}
|
|
15564
|
+
}
|
|
15565
|
+
var devLeadWatchProjectionDefinition = {
|
|
15566
|
+
key: DEVLEAD_WATCH_PROJECTION_KEY,
|
|
15567
|
+
stateSchema: devLeadWatchProjectionStateSchema,
|
|
15568
|
+
init: emptyDevLeadWatchProjectionState,
|
|
15569
|
+
apply: applyDevLeadWatchProjection,
|
|
15570
|
+
wire: {
|
|
15571
|
+
viewSchema: devLeadWatchProjectionSchema,
|
|
15572
|
+
view: devLeadWatchProjectionView
|
|
15573
|
+
},
|
|
15574
|
+
// 1: the initial summary representation of the watch set.
|
|
15575
|
+
stateVersion: 1
|
|
15576
|
+
};
|
|
15416
15577
|
function emptyDevLeadModeProjectionState() {
|
|
15417
15578
|
return { enabled: false, failure: null };
|
|
15418
15579
|
}
|
|
@@ -15550,7 +15711,7 @@ import { appendPluginRecord, pluginRecordOf as pluginRecordOf3 } from "@deepseek
|
|
|
15550
15711
|
import { SessionId as toSessionId } from "@deepseek-ai/dsh-session";
|
|
15551
15712
|
import {
|
|
15552
15713
|
DEVLEAD_DEFAULT_NOTIFICATION_RETENTION as DEVLEAD_DEFAULT_NOTIFICATION_RETENTION3,
|
|
15553
|
-
DEVLEAD_MESSAGE_KIND as
|
|
15714
|
+
DEVLEAD_MESSAGE_KIND as DEVLEAD_MESSAGE_KIND3,
|
|
15554
15715
|
DEVLEAD_MODE_RECORD_TYPE as DEVLEAD_MODE_RECORD_TYPE4,
|
|
15555
15716
|
DEVLEAD_NOTIFICATION_RECORD_TYPE as DEVLEAD_NOTIFICATION_RECORD_TYPE3,
|
|
15556
15717
|
DEVLEAD_REPORT_RECORD_TYPE as DEVLEAD_REPORT_RECORD_TYPE3,
|
|
@@ -15701,9 +15862,8 @@ var DevLeadNotificationHub = class {
|
|
|
15701
15862
|
* @returns whether the report belongs to an indexed watch relationship.
|
|
15702
15863
|
*/
|
|
15703
15864
|
report(report) {
|
|
15704
|
-
|
|
15705
|
-
|
|
15706
|
-
if (runtime === void 0 || !runtime.watched.has(report.senderSessionId)) return false;
|
|
15865
|
+
const runtime = this.reportRuntime(report);
|
|
15866
|
+
if (runtime === void 0) return false;
|
|
15707
15867
|
if (runtime.pendingReports.some((existing) => existing.id === report.id) || runtime.unsavedReports.some((existing) => existing.id === report.id)) return true;
|
|
15708
15868
|
const session = this.ctx.sessions.get(toSessionId(report.leadSessionId));
|
|
15709
15869
|
if (session !== void 0) {
|
|
@@ -15733,12 +15893,8 @@ var DevLeadNotificationHub = class {
|
|
|
15733
15893
|
* @returns whether the lead Session log now carries a flushed receipt.
|
|
15734
15894
|
*/
|
|
15735
15895
|
async persistReport(report) {
|
|
15736
|
-
|
|
15737
|
-
|
|
15738
|
-
if (runtime === void 0 || !runtime.watched.has(report.senderSessionId)) return false;
|
|
15739
|
-
if (this.ctx.get("workspaceRegistry")?.archivedSessionIds.some((id) => String(id) === report.leadSessionId) ?? false) {
|
|
15740
|
-
return false;
|
|
15741
|
-
}
|
|
15896
|
+
const runtime = this.reportRuntime(report);
|
|
15897
|
+
if (runtime === void 0) return false;
|
|
15742
15898
|
const session = this.ctx.sessions.get(toSessionId(report.leadSessionId));
|
|
15743
15899
|
if (session === void 0) {
|
|
15744
15900
|
runtime.unsavedReports = [...runtime.unsavedReports, report].slice(-DEVLEAD_REPORT_RETENTION2);
|
|
@@ -15772,6 +15928,23 @@ var DevLeadNotificationHub = class {
|
|
|
15772
15928
|
this.scheduleFlush(runtime);
|
|
15773
15929
|
return true;
|
|
15774
15930
|
}
|
|
15931
|
+
/**
|
|
15932
|
+
* Resolve the lead runtime one report may be queued for: the hub must be
|
|
15933
|
+
* running, the lead indexed and still watching the sender, and the lead not
|
|
15934
|
+
* archived. Shared by the sync queue path and the durable receipt path so
|
|
15935
|
+
* both reject the same relationships.
|
|
15936
|
+
* @param report - report addressed to one lead.
|
|
15937
|
+
* @returns the lead runtime, or undefined when the report must be refused.
|
|
15938
|
+
*/
|
|
15939
|
+
reportRuntime(report) {
|
|
15940
|
+
if (this.stopping) return void 0;
|
|
15941
|
+
const runtime = this.leads.get(report.leadSessionId);
|
|
15942
|
+
if (runtime === void 0 || !runtime.watched.has(report.senderSessionId)) return void 0;
|
|
15943
|
+
if (this.ctx.get("workspaceRegistry")?.archivedSessionIds.some((id) => String(id) === report.leadSessionId) ?? false) {
|
|
15944
|
+
return void 0;
|
|
15945
|
+
}
|
|
15946
|
+
return runtime;
|
|
15947
|
+
}
|
|
15775
15948
|
/**
|
|
15776
15949
|
* Append one report receipt and fire-and-forget its durability checkpoint.
|
|
15777
15950
|
* @param session - attached lead Session log receiving the record.
|
|
@@ -16183,7 +16356,15 @@ var DevLeadNotificationHub = class {
|
|
|
16183
16356
|
}
|
|
16184
16357
|
this.persistUnsaved(agent.session, runtime);
|
|
16185
16358
|
if (runtime.pending.length === 0 && runtime.pendingReports.length === 0) return;
|
|
16186
|
-
|
|
16359
|
+
let queuedNotice = false;
|
|
16360
|
+
try {
|
|
16361
|
+
queuedNotice = this.hasQueuedNotice(agent);
|
|
16362
|
+
} catch (error51) {
|
|
16363
|
+
this.ctx.logger.warn(
|
|
16364
|
+
`devlead: could not inspect the inbox of lead "${runtime.sessionId}" for a queued notice: ${thrownMessage(error51)}`
|
|
16365
|
+
);
|
|
16366
|
+
}
|
|
16367
|
+
if (queuedNotice) {
|
|
16187
16368
|
this.scheduleRetry(runtime);
|
|
16188
16369
|
return;
|
|
16189
16370
|
}
|
|
@@ -16261,7 +16442,7 @@ var DevLeadNotificationHub = class {
|
|
|
16261
16442
|
hasQueuedNotice(agent) {
|
|
16262
16443
|
return [...agent.inbox.nextTurn, ...agent.inbox.nextStep].some((message) => {
|
|
16263
16444
|
const source = message.source;
|
|
16264
|
-
return source
|
|
16445
|
+
return source?.kind === DEVLEAD_MESSAGE_KIND3 && source?.form === "notice";
|
|
16265
16446
|
});
|
|
16266
16447
|
}
|
|
16267
16448
|
/**
|
|
@@ -16326,12 +16507,6 @@ async function persistedSessionsOf(ctx, signal) {
|
|
|
16326
16507
|
}
|
|
16327
16508
|
|
|
16328
16509
|
// packages/devlead/src/presets.ts
|
|
16329
|
-
function recordOf2(value) {
|
|
16330
|
-
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
16331
|
-
}
|
|
16332
|
-
function stringField2(value) {
|
|
16333
|
-
return typeof value === "string" ? value : "";
|
|
16334
|
-
}
|
|
16335
16510
|
function agentPresetRosterCapabilityOf(ctx) {
|
|
16336
16511
|
const candidate = ctx.get("agentPresets");
|
|
16337
16512
|
if (typeof candidate !== "object" || candidate === null) return void 0;
|
|
@@ -16343,13 +16518,13 @@ function agentPresetRosterCapabilityOf(ctx) {
|
|
|
16343
16518
|
function devLeadAgentPresetsOf(rows, defaultId) {
|
|
16344
16519
|
const presets = [];
|
|
16345
16520
|
for (const row of rows) {
|
|
16346
|
-
const record2 =
|
|
16521
|
+
const record2 = recordOf(row);
|
|
16347
16522
|
if (record2 === void 0) continue;
|
|
16348
|
-
const id =
|
|
16523
|
+
const id = stringField(record2.id).trim();
|
|
16349
16524
|
if (id.length === 0) continue;
|
|
16350
|
-
const name =
|
|
16351
|
-
const description =
|
|
16352
|
-
const broken =
|
|
16525
|
+
const name = stringField(record2.name).trim();
|
|
16526
|
+
const description = stringField(record2.description).trim();
|
|
16527
|
+
const broken = stringField(record2.broken).trim();
|
|
16353
16528
|
presets.push({
|
|
16354
16529
|
id,
|
|
16355
16530
|
default: id === defaultId,
|
|
@@ -16635,13 +16810,20 @@ async function devLeadSessionViews(deps, ids, withLog, facts) {
|
|
|
16635
16810
|
}
|
|
16636
16811
|
return views;
|
|
16637
16812
|
}
|
|
16813
|
+
function workspaceCandidateLabel(workspace) {
|
|
16814
|
+
return `${workspace.id} (${workspace.path})`;
|
|
16815
|
+
}
|
|
16638
16816
|
async function resolveWorkspaceReference(ctx, reference, signal) {
|
|
16639
16817
|
const registry2 = ctx.get("workspaceRegistry");
|
|
16640
16818
|
if (registry2 === void 0) {
|
|
16641
16819
|
throw new DevLeadError("this Host composes no Workspace registry", "DEVLEAD_WORKSPACE_NOT_FOUND");
|
|
16642
16820
|
}
|
|
16643
16821
|
const trimmed = reference.trim();
|
|
16644
|
-
|
|
16822
|
+
if (trimmed.length === 0) {
|
|
16823
|
+
throw new DevLeadError("a Workspace reference is required", "DEVLEAD_INVALID_INPUT");
|
|
16824
|
+
}
|
|
16825
|
+
const workspaces = registry2.list();
|
|
16826
|
+
const byId = workspaces.find((workspace) => workspace.id === trimmed);
|
|
16645
16827
|
if (byId !== void 0) return byId;
|
|
16646
16828
|
try {
|
|
16647
16829
|
signal?.throwIfAborted();
|
|
@@ -16651,8 +16833,17 @@ async function resolveWorkspaceReference(ctx, reference, signal) {
|
|
|
16651
16833
|
rethrowIfAborted(error51, signal);
|
|
16652
16834
|
}
|
|
16653
16835
|
signal?.throwIfAborted();
|
|
16836
|
+
const byTitle = workspaces.filter((workspace) => workspace.title.trim() === trimmed);
|
|
16837
|
+
const only = byTitle[0];
|
|
16838
|
+
if (only !== void 0 && byTitle.length === 1) return only;
|
|
16839
|
+
if (byTitle.length > 1) {
|
|
16840
|
+
throw new DevLeadError(
|
|
16841
|
+
`Workspace title "${trimmed}" is ambiguous: ${byTitle.length} Workspaces share it: ${byTitle.map(workspaceCandidateLabel).join(", ")}; pass a Workspace id or registered path instead`,
|
|
16842
|
+
"DEVLEAD_WORKSPACE_AMBIGUOUS"
|
|
16843
|
+
);
|
|
16844
|
+
}
|
|
16654
16845
|
throw new DevLeadError(
|
|
16655
|
-
`no Workspace matches "${reference}";
|
|
16846
|
+
`no Workspace matches "${reference}"; pass a Workspace id, a registered directory path, or an exact title from devlead_list_workspaces. If the repository is not registered yet, add it with devlead_use_workspace.`,
|
|
16656
16847
|
"DEVLEAD_WORKSPACE_NOT_FOUND"
|
|
16657
16848
|
);
|
|
16658
16849
|
}
|
|
@@ -16660,12 +16851,10 @@ async function resolveExactSession(deps, reference) {
|
|
|
16660
16851
|
const { ctx } = deps;
|
|
16661
16852
|
const sessionId = toSessionId2(reference);
|
|
16662
16853
|
const live = ctx.agents.get(sessionId) !== void 0;
|
|
16663
|
-
if (deps.watchedSessions.includes(reference)) return { sessionId, live };
|
|
16664
16854
|
const session = ctx.sessions.get(sessionId) ?? ctx.agents.get(sessionId)?.session;
|
|
16665
|
-
if (session !== void 0)
|
|
16666
|
-
|
|
16667
|
-
|
|
16668
|
-
}
|
|
16855
|
+
if (session !== void 0 && session.header.origin === "subagent") return void 0;
|
|
16856
|
+
if (deps.watchedSessions.includes(reference)) return { sessionId, live };
|
|
16857
|
+
if (session !== void 0) return { sessionId, live };
|
|
16669
16858
|
const query = ctx.get("sessionQuery");
|
|
16670
16859
|
if (query === void 0) return void 0;
|
|
16671
16860
|
try {
|
|
@@ -16722,6 +16911,16 @@ var MAX_COLD_LEAD_LOG_READS = 64;
|
|
|
16722
16911
|
var MAX_ACTIVE_SCAN_UNKNOWN_READS = 64;
|
|
16723
16912
|
var REHYDRATION_READINESS_TIMEOUT_MS = 2e3;
|
|
16724
16913
|
var REHYDRATION_READINESS_POLL_MS = 100;
|
|
16914
|
+
var DevLeadInterruptedAdmissionError = class extends DevLeadError {
|
|
16915
|
+
/**
|
|
16916
|
+
* @param message - failure text naming both the admission failure and the
|
|
16917
|
+
* already-committed stop.
|
|
16918
|
+
*/
|
|
16919
|
+
constructor(message) {
|
|
16920
|
+
super(message, "DEVLEAD_SESSION_UNAVAILABLE");
|
|
16921
|
+
this.name = "DevLeadInterruptedAdmissionError";
|
|
16922
|
+
}
|
|
16923
|
+
};
|
|
16725
16924
|
var Config = z2.object({
|
|
16726
16925
|
notificationBatchMs: z2.number().step(1).min(0).max(MAX_TIMER_DELAY_MS).default(400),
|
|
16727
16926
|
maxWatchedSessions: z2.number().step(1).min(1).default(DEVLEAD_DEFAULT_MAX_WATCHED2),
|
|
@@ -16888,6 +17087,7 @@ var DevLeadService = class extends Service {
|
|
|
16888
17087
|
async [Service.init]() {
|
|
16889
17088
|
this.projectionHandle = await this.ctx.sessionProjections.register(devLeadProjectionDefinition);
|
|
16890
17089
|
await this.ctx.sessionProjections.register(devLeadModeProjectionDefinition);
|
|
17090
|
+
await this.ctx.sessionProjections.register(devLeadWatchProjectionDefinition);
|
|
16891
17091
|
this.hub = new DevLeadNotificationHub(
|
|
16892
17092
|
this.ctx,
|
|
16893
17093
|
(session) => this.projectionHandle.stateOf(session),
|
|
@@ -16901,7 +17101,7 @@ var DevLeadService = class extends Service {
|
|
|
16901
17101
|
this.disposeRehydrationRetry();
|
|
16902
17102
|
this.outboxInjection?.dispose();
|
|
16903
17103
|
this.outboxInjection = void 0;
|
|
16904
|
-
|
|
17104
|
+
return this.outbox?.close();
|
|
16905
17105
|
};
|
|
16906
17106
|
}.bind(this), "devlead: cold rehydration");
|
|
16907
17107
|
this.ctx.effect(function* () {
|
|
@@ -17430,7 +17630,7 @@ var DevLeadService = class extends Service {
|
|
|
17430
17630
|
* The returned view is the pre-removal snapshot, so the caller can report
|
|
17431
17631
|
* what it closed and which Sessions it accounted to.
|
|
17432
17632
|
* @param agent - exact live lead Agent making the removal.
|
|
17433
|
-
* @param workspace - Workspace id or
|
|
17633
|
+
* @param workspace - Workspace id, registered path, or exact display title.
|
|
17434
17634
|
* @param signal - cancellation checked before the registry write.
|
|
17435
17635
|
* @returns the pre-removal Workspace view and whether a registration was
|
|
17436
17636
|
* removed (`false` when another actor removed it first).
|
|
@@ -17592,6 +17792,74 @@ var DevLeadService = class extends Service {
|
|
|
17592
17792
|
signal?.throwIfAborted();
|
|
17593
17793
|
return await devLeadSessionView(deps, String(resolved.sessionId), true);
|
|
17594
17794
|
}
|
|
17795
|
+
/**
|
|
17796
|
+
* Read the pending inbox inputs of one Session for the detail tool.
|
|
17797
|
+
*
|
|
17798
|
+
* The inbox is driver-owned: only a live Agent has one, so a cold Session
|
|
17799
|
+
* reports undefined (the caller omits the field) rather than an empty list
|
|
17800
|
+
* that would claim "nothing queued" about a log the Host has not folded.
|
|
17801
|
+
* @param agent - exact live lead Agent.
|
|
17802
|
+
* @param sessionId - exact Session identity (already resolved by the caller).
|
|
17803
|
+
* @param signal - cancellation checked before the read.
|
|
17804
|
+
* @returns queued inputs in queue order, or undefined when the target is not live.
|
|
17805
|
+
* @throws {@link DevLeadError} when the caller is not live.
|
|
17806
|
+
*/
|
|
17807
|
+
sessionQueuedInputs(agent, sessionId, signal) {
|
|
17808
|
+
this.assertLive(agent);
|
|
17809
|
+
signal?.throwIfAborted();
|
|
17810
|
+
const target = this.ctx.agents.get(toSessionId3(sessionId));
|
|
17811
|
+
return target === void 0 ? void 0 : queuedInputsOf(target);
|
|
17812
|
+
}
|
|
17813
|
+
/**
|
|
17814
|
+
* Withdraw one queued inbox input this lead Session authored.
|
|
17815
|
+
*
|
|
17816
|
+
* Only the lead's own relay prompts are retractable: a human's queued
|
|
17817
|
+
* instruction is the human's intent, a scheduled wake belongs to the
|
|
17818
|
+
* schedule plugin, and another lead's relay belongs to that lead. The call
|
|
17819
|
+
* is idempotent — an input already consumed or withdrawn reports
|
|
17820
|
+
* `retracted: false`. The target must be live (the inbox is driver-owned)
|
|
17821
|
+
* and cannot be the lead itself.
|
|
17822
|
+
* @param agent - exact live lead Agent.
|
|
17823
|
+
* @param sessionId - target Session reference (id or unique prefix).
|
|
17824
|
+
* @param inputId - Host message identity reported by queuedInputs.
|
|
17825
|
+
* @param signal - cancellation checked before each stage.
|
|
17826
|
+
* @returns the retraction outcome.
|
|
17827
|
+
* @throws {@link DevLeadError} `DEVLEAD_INVALID_INPUT` for a self-addressed
|
|
17828
|
+
* call or an input this lead did not author, `DEVLEAD_SESSION_UNAVAILABLE`
|
|
17829
|
+
* for a cold target, and the usual resolution failures.
|
|
17830
|
+
*/
|
|
17831
|
+
async retractQueuedInput(agent, sessionId, inputId, signal) {
|
|
17832
|
+
this.assertReady(agent);
|
|
17833
|
+
signal?.throwIfAborted();
|
|
17834
|
+
const deps = this.viewDeps(agent, signal);
|
|
17835
|
+
const resolved = await resolveSessionReference(deps, sessionId);
|
|
17836
|
+
signal?.throwIfAborted();
|
|
17837
|
+
const targetId = String(resolved.sessionId);
|
|
17838
|
+
if (targetId === String(agent.id)) {
|
|
17839
|
+
throw new DevLeadError(
|
|
17840
|
+
"a DevLead Session cannot retract inputs from its own inbox; ask the human to manage this Session",
|
|
17841
|
+
"DEVLEAD_INVALID_INPUT"
|
|
17842
|
+
);
|
|
17843
|
+
}
|
|
17844
|
+
const target = this.ctx.agents.get(resolved.sessionId);
|
|
17845
|
+
if (target === void 0) {
|
|
17846
|
+
throw new DevLeadError(
|
|
17847
|
+
`Session "${targetId}" is not live, so its inbox cannot be inspected or retracted; open it first`,
|
|
17848
|
+
"DEVLEAD_SESSION_UNAVAILABLE"
|
|
17849
|
+
);
|
|
17850
|
+
}
|
|
17851
|
+
const pending = [...target.inbox.nextTurn, ...target.inbox.nextStep].find((message) => String(message.id) === inputId);
|
|
17852
|
+
if (pending === void 0) return { sessionId: targetId, inputId, retracted: false };
|
|
17853
|
+
if (!isOwnRelay(pending, String(agent.id))) {
|
|
17854
|
+
throw new DevLeadError(
|
|
17855
|
+
`queued input "${inputId}" was not authored by this DevLead Session; only your own relay prompts can be retracted \u2014 human, scheduled, and other producers' inputs are not yours to remove`,
|
|
17856
|
+
"DEVLEAD_INVALID_INPUT"
|
|
17857
|
+
);
|
|
17858
|
+
}
|
|
17859
|
+
const retracted = target.inbox.remove(MessageId(inputId));
|
|
17860
|
+
if (retracted) await this.flushDurably(target.session, `retraction of input "${inputId}"`);
|
|
17861
|
+
return { sessionId: targetId, inputId, retracted };
|
|
17862
|
+
}
|
|
17595
17863
|
/**
|
|
17596
17864
|
* Create one ordinary Session in a Workspace and optionally prompt it.
|
|
17597
17865
|
*
|
|
@@ -17687,7 +17955,12 @@ var DevLeadService = class extends Service {
|
|
|
17687
17955
|
const prompt = request.prompt?.trim() ?? "";
|
|
17688
17956
|
const prompted = prompt.length > 0;
|
|
17689
17957
|
if (prompted) {
|
|
17690
|
-
await this.admitPrompt(agent, created.sessionId, prompt,
|
|
17958
|
+
await this.admitPrompt(agent, created.sessionId, prompt, {
|
|
17959
|
+
allowResume: false,
|
|
17960
|
+
interrupt: false,
|
|
17961
|
+
interruptInbox: "clear-all",
|
|
17962
|
+
signal
|
|
17963
|
+
});
|
|
17691
17964
|
}
|
|
17692
17965
|
const deps = this.viewDeps(agent, signal);
|
|
17693
17966
|
return {
|
|
@@ -17705,11 +17978,20 @@ var DevLeadService = class extends Service {
|
|
|
17705
17978
|
/**
|
|
17706
17979
|
* Admit one prompt into an existing Session, resuming a cold Session and
|
|
17707
17980
|
* watching it by default.
|
|
17981
|
+
*
|
|
17982
|
+
* `interrupt: true` explicitly replaces the Session's current work: when its
|
|
17983
|
+
* Agent is running, the Host's `workspace/session-stop` providers are asked
|
|
17984
|
+
* to stop the turn (and the subagent/job/schedule work they report) before
|
|
17985
|
+
* the prompt is admitted. The stop is fire-and-forget; the replacement
|
|
17986
|
+
* prompt is queued for the next turn and starts once the aborted turn
|
|
17987
|
+
* converges, so it can never join the cancelling turn. An idle or cold
|
|
17988
|
+
* Session skips the stop entirely.
|
|
17708
17989
|
* @param agent - exact live lead Agent.
|
|
17709
17990
|
* @param sessionId - Session id or unique prefix.
|
|
17710
17991
|
* @param prompt - non-empty prompt text.
|
|
17711
|
-
* @param options -
|
|
17712
|
-
*
|
|
17992
|
+
* @param options - watch policy, interrupt policy, and cancellation checked
|
|
17993
|
+
* between stages. Cancellation after an interrupt was requested does not
|
|
17994
|
+
* roll the stop back; the replacement prompt is admitted with it.
|
|
17713
17995
|
* @returns the admitted prompt receipt.
|
|
17714
17996
|
* @throws {@link DevLeadError} when the Session is missing, archived, or cannot be resumed.
|
|
17715
17997
|
*/
|
|
@@ -17739,11 +18021,16 @@ var DevLeadService = class extends Service {
|
|
|
17739
18021
|
const alreadyWatched = this.strictStateOf(agent.session).sessions.includes(String(resolved.sessionId));
|
|
17740
18022
|
const added = watch && !alreadyWatched;
|
|
17741
18023
|
if (added) await this.setWatching(agent, resolved.sessionId, true, signal);
|
|
17742
|
-
let
|
|
18024
|
+
let admission;
|
|
17743
18025
|
try {
|
|
17744
|
-
|
|
18026
|
+
admission = await this.admitPrompt(agent, resolved.sessionId, text, {
|
|
18027
|
+
allowResume: true,
|
|
18028
|
+
interrupt: options.interrupt ?? false,
|
|
18029
|
+
interruptInbox: options.interruptInbox ?? "clear-all",
|
|
18030
|
+
signal
|
|
18031
|
+
});
|
|
17745
18032
|
} catch (error51) {
|
|
17746
|
-
if (added) {
|
|
18033
|
+
if (added && !(error51 instanceof DevLeadInterruptedAdmissionError)) {
|
|
17747
18034
|
try {
|
|
17748
18035
|
await this.setWatching(agent, resolved.sessionId, false);
|
|
17749
18036
|
} catch (compensateError) {
|
|
@@ -17757,7 +18044,9 @@ var DevLeadService = class extends Service {
|
|
|
17757
18044
|
return {
|
|
17758
18045
|
sessionId: String(resolved.sessionId),
|
|
17759
18046
|
watched: this.strictStateOf(agent.session).sessions.includes(String(resolved.sessionId)),
|
|
17760
|
-
resumed
|
|
18047
|
+
resumed: admission.resumed,
|
|
18048
|
+
interrupted: admission.interrupted,
|
|
18049
|
+
...admission.retainedInputs === void 0 ? {} : { retainedInputs: admission.retainedInputs }
|
|
17761
18050
|
};
|
|
17762
18051
|
}
|
|
17763
18052
|
/**
|
|
@@ -17979,15 +18268,15 @@ var DevLeadService = class extends Service {
|
|
|
17979
18268
|
};
|
|
17980
18269
|
}
|
|
17981
18270
|
/**
|
|
17982
|
-
* Resolve the unique active DevLead Session
|
|
18271
|
+
* Resolve the unique active DevLead Session that watches one reporter.
|
|
17983
18272
|
*
|
|
17984
18273
|
* The hub's reverse index already reflects durable watch/mode state (live and
|
|
17985
18274
|
* cold rehydrated leads). Archived leads are excluded, and when historical
|
|
17986
18275
|
* state leaves more than one watcher the current global incumbent wins; with
|
|
17987
|
-
* no unique answer the reporter is treated as
|
|
18276
|
+
* no unique answer the reporter is treated as unwatched instead of
|
|
17988
18277
|
* broadcasting to an arbitrary lead.
|
|
17989
18278
|
* @param agent - candidate watched Session Agent.
|
|
17990
|
-
* @returns the
|
|
18279
|
+
* @returns the watching lead Session id, or undefined.
|
|
17991
18280
|
*/
|
|
17992
18281
|
supervisorOf(agent) {
|
|
17993
18282
|
if (this.hub === void 0) return void 0;
|
|
@@ -18022,7 +18311,7 @@ var DevLeadService = class extends Service {
|
|
|
18022
18311
|
/**
|
|
18023
18312
|
* Whether one Session may send mid-turn reports to an active DevLead.
|
|
18024
18313
|
* @param agent - candidate reporter Agent.
|
|
18025
|
-
* @returns whether the reporter has exactly one
|
|
18314
|
+
* @returns whether the reporter has exactly one active lead watching it.
|
|
18026
18315
|
*/
|
|
18027
18316
|
isSupervised(agent) {
|
|
18028
18317
|
return this.supervisorOf(agent) !== void 0;
|
|
@@ -18034,9 +18323,12 @@ var DevLeadService = class extends Service {
|
|
|
18034
18323
|
* for a cold lead by the hub), then the lead is woken through the same
|
|
18035
18324
|
* coalesced notice path as turn notifications. This method returns after the
|
|
18036
18325
|
* receipt/queue decision and never waits for the lead's next turn, so the
|
|
18037
|
-
* reporter is not blocked. Same-message reports in one turn are
|
|
18038
|
-
*
|
|
18039
|
-
*
|
|
18326
|
+
* reporter is not blocked. Same-kind same-message reports in one turn are
|
|
18327
|
+
* idempotent (the same text under a different kind is a new report);
|
|
18328
|
+
* more than {@link DEVLEAD_REPORT_MAX_PER_TURN} distinct non-question reports
|
|
18329
|
+
* in one turn are refused. `question` reports are the answer-seeking channel
|
|
18330
|
+
* used by the watched-Session question router, so they are exempt from that
|
|
18331
|
+
* progress budget.
|
|
18040
18332
|
* @param agent - exact live reporter Agent.
|
|
18041
18333
|
* @param request - report text, kind, and optional summary.
|
|
18042
18334
|
* @param signal - cancellation checked before durable work.
|
|
@@ -18074,7 +18366,7 @@ var DevLeadService = class extends Service {
|
|
|
18074
18366
|
const kind = request.kind ?? "progress";
|
|
18075
18367
|
if (!isDevLeadReportKind2(kind)) {
|
|
18076
18368
|
throw new DevLeadError(
|
|
18077
|
-
`report kind ${JSON.stringify(kind)} is not recognized; use progress, blocked, decision, or fyi`,
|
|
18369
|
+
`report kind ${JSON.stringify(kind)} is not recognized; use progress, blocked, decision, question, or fyi`,
|
|
18078
18370
|
"DEVLEAD_INVALID_INPUT"
|
|
18079
18371
|
);
|
|
18080
18372
|
}
|
|
@@ -18092,11 +18384,13 @@ var DevLeadService = class extends Service {
|
|
|
18092
18384
|
if (previous === void 0 || previous.turn !== turn || previous.leadSessionId !== leadSessionId) {
|
|
18093
18385
|
this.reportState.set(reporterId, state);
|
|
18094
18386
|
}
|
|
18095
|
-
const
|
|
18387
|
+
const dedupKey = `${kind}\0${message}`;
|
|
18388
|
+
const duplicate = state.messages.get(dedupKey);
|
|
18096
18389
|
if (duplicate !== void 0) return duplicate;
|
|
18097
|
-
|
|
18390
|
+
const progressCount = [...state.messages.values()].filter((entry) => entry.report.kind !== "question").length;
|
|
18391
|
+
if (kind !== "question" && progressCount >= DEVLEAD_REPORT_MAX_PER_TURN) {
|
|
18098
18392
|
throw new DevLeadError(
|
|
18099
|
-
`this Session already sent ${DEVLEAD_REPORT_MAX_PER_TURN} reports in turn ${turn}; wait for the next turn or let the DevLead continue`,
|
|
18393
|
+
`this Session already sent ${DEVLEAD_REPORT_MAX_PER_TURN} non-question reports in turn ${turn}; wait for the next turn or let the DevLead continue`,
|
|
18100
18394
|
"DEVLEAD_REPORT_RATE_LIMITED"
|
|
18101
18395
|
);
|
|
18102
18396
|
}
|
|
@@ -18123,7 +18417,7 @@ var DevLeadService = class extends Service {
|
|
|
18123
18417
|
});
|
|
18124
18418
|
signal?.throwIfAborted();
|
|
18125
18419
|
const receipt = await this.deliverReport(report);
|
|
18126
|
-
state.messages.set(
|
|
18420
|
+
state.messages.set(dedupKey, receipt);
|
|
18127
18421
|
if (this.reportState.size > 512) {
|
|
18128
18422
|
const oldest = this.reportState.keys().next().value;
|
|
18129
18423
|
if (oldest !== void 0) this.reportState.delete(oldest);
|
|
@@ -18131,13 +18425,15 @@ var DevLeadService = class extends Service {
|
|
|
18131
18425
|
return receipt;
|
|
18132
18426
|
}
|
|
18133
18427
|
/**
|
|
18134
|
-
* Read the retained mid-turn report digest of one live lead.
|
|
18428
|
+
* Read the retained mid-turn report digest of one live lead. Like
|
|
18429
|
+
* {@link notifications}, this is an audit read: a disabled lead may still
|
|
18430
|
+
* inspect what it retained while the mode was on.
|
|
18135
18431
|
* @param agent - exact live lead Agent.
|
|
18136
18432
|
* @param options - optional newest-row limit, defaulting to 20.
|
|
18137
18433
|
* @returns detached reports, oldest first.
|
|
18138
18434
|
*/
|
|
18139
18435
|
reports(agent, options = {}) {
|
|
18140
|
-
this.
|
|
18436
|
+
this.assertLive(agent);
|
|
18141
18437
|
const state = this.strictStateOf(agent.session);
|
|
18142
18438
|
const limit = options.limit ?? 20;
|
|
18143
18439
|
const effective = Number.isSafeInteger(limit) && limit > 0 ? limit : 20;
|
|
@@ -18315,6 +18611,7 @@ var DevLeadService = class extends Service {
|
|
|
18315
18611
|
const sessionId = String(session.id);
|
|
18316
18612
|
if (seen.has(sessionId)) return;
|
|
18317
18613
|
seen.add(sessionId);
|
|
18614
|
+
if (session.header.origin === "subagent") return;
|
|
18318
18615
|
const state = this.projectionHandle.stateOf(session);
|
|
18319
18616
|
if (state.failure !== null || !state.enabled) return;
|
|
18320
18617
|
const title = this.ctx.get("sessionTitle")?.get(session)?.title;
|
|
@@ -18828,7 +19125,7 @@ var DevLeadService = class extends Service {
|
|
|
18828
19125
|
* Resolve the Workspace one created Session should join: the requested
|
|
18829
19126
|
* reference, or the lead's own directory registered on demand.
|
|
18830
19127
|
* @param agent - exact live lead Agent.
|
|
18831
|
-
* @param reference - requested Workspace id or
|
|
19128
|
+
* @param reference - requested Workspace id, registered path, or exact title.
|
|
18832
19129
|
* @returns the target Workspace.
|
|
18833
19130
|
*/
|
|
18834
19131
|
async createTargetWorkspace(agent, reference) {
|
|
@@ -18972,19 +19269,31 @@ var DevLeadService = class extends Service {
|
|
|
18972
19269
|
}
|
|
18973
19270
|
/**
|
|
18974
19271
|
* Admit one lead-authored prompt into a Session, resuming a cold Session.
|
|
19272
|
+
*
|
|
19273
|
+
* `interrupt` is evaluated only against a live running Agent. The Host's
|
|
19274
|
+
* `workspace/session-stop` providers are the same fan-out archive
|
|
19275
|
+
* `stopActivity` uses; they cancel the turn and stop the Session's reported
|
|
19276
|
+
* subagent/job/schedule work. The stop is fire-and-forget: `followup` is
|
|
19277
|
+
* admitted immediately afterwards, and the Agent reclassifies a wake after
|
|
19278
|
+
* an aborted phase to the next turn and latches it until the aborted
|
|
19279
|
+
* activity converges, so the prompt cannot enter the cancelling turn. No
|
|
19280
|
+
* settlement wait is needed.
|
|
18975
19281
|
* @param leadAgent - exact live lead Agent.
|
|
18976
19282
|
* @param sessionId - target Session identity.
|
|
18977
19283
|
* @param text - non-empty prompt text.
|
|
18978
|
-
* @param
|
|
18979
|
-
*
|
|
18980
|
-
*
|
|
19284
|
+
* @param options - resume policy, interrupt policy, and cancellation checked
|
|
19285
|
+
* before each stage. Once an interrupt is requested, cancellation does not
|
|
19286
|
+
* roll it back; the replacement prompt is admitted with the stop.
|
|
19287
|
+
* @returns whether the Host resumed a cold Session and whether it was asked
|
|
19288
|
+
* to interrupt a running turn.
|
|
18981
19289
|
*/
|
|
18982
|
-
async admitPrompt(leadAgent, sessionId, text,
|
|
19290
|
+
async admitPrompt(leadAgent, sessionId, text, options) {
|
|
19291
|
+
const signal = options.signal;
|
|
18983
19292
|
signal?.throwIfAborted();
|
|
18984
19293
|
let target = this.ctx.agents.get(sessionId);
|
|
18985
19294
|
let resumed = false;
|
|
18986
19295
|
if (target === void 0) {
|
|
18987
|
-
if (!allowResume) {
|
|
19296
|
+
if (!options.allowResume) {
|
|
18988
19297
|
throw new DevLeadError(`Session "${sessionId}" is not live`, "DEVLEAD_SESSION_UNAVAILABLE");
|
|
18989
19298
|
}
|
|
18990
19299
|
const controller = this.ctx.get("sessionController");
|
|
@@ -19014,16 +19323,52 @@ var DevLeadService = class extends Service {
|
|
|
19014
19323
|
signal?.throwIfAborted();
|
|
19015
19324
|
}
|
|
19016
19325
|
signal?.throwIfAborted();
|
|
19326
|
+
let interrupted = false;
|
|
19327
|
+
let retainedInputs;
|
|
19328
|
+
if (options.interrupt && target.status === "running") {
|
|
19329
|
+
interrupted = true;
|
|
19330
|
+
const kept = keptInputsOf(target, String(leadAgent.id), options.interruptInbox);
|
|
19331
|
+
await this.stopSessionActivity(sessionId);
|
|
19332
|
+
if (options.interruptInbox !== "clear-all") {
|
|
19333
|
+
retainedInputs = restoreInputs(target, kept);
|
|
19334
|
+
}
|
|
19335
|
+
}
|
|
19017
19336
|
try {
|
|
19018
19337
|
target.followup(createDevLeadPromptMessage(text, leadAgent));
|
|
19019
19338
|
} catch (error51) {
|
|
19020
|
-
|
|
19021
|
-
|
|
19022
|
-
|
|
19023
|
-
|
|
19339
|
+
const detail = `could not admit a prompt into Session "${sessionId}": ${thrownMessage(error51)}`;
|
|
19340
|
+
if (interrupted) {
|
|
19341
|
+
throw new DevLeadInterruptedAdmissionError(
|
|
19342
|
+
`${detail}; the running work was already asked to stop, so the Session keeps its watch \u2014 retry the prompt`
|
|
19343
|
+
);
|
|
19344
|
+
}
|
|
19345
|
+
throw new DevLeadError(detail, "DEVLEAD_SESSION_UNAVAILABLE");
|
|
19024
19346
|
}
|
|
19025
19347
|
await this.flushDurably(target.session, `prompt into Session "${sessionId}"`);
|
|
19026
|
-
return resumed;
|
|
19348
|
+
return { resumed, interrupted, ...retainedInputs === void 0 ? {} : { retainedInputs } };
|
|
19349
|
+
}
|
|
19350
|
+
/**
|
|
19351
|
+
* Ask every composed `workspace/session-stop` provider to stop one Session's
|
|
19352
|
+
* running work. This is the same fan-out archive `stopActivity` uses, without
|
|
19353
|
+
* the archive write: the Agent registry cancels the running turn, the job
|
|
19354
|
+
* registry kills owned jobs, the subagent runtime cancels running
|
|
19355
|
+
* descendants, and the schedule plugin removes active schedule rows.
|
|
19356
|
+
* Provider failures are logged and never block the replacement prompt; the
|
|
19357
|
+
* cancellation itself is fire-and-forget, so this method does not wait for
|
|
19358
|
+
* the stopped work to settle.
|
|
19359
|
+
* @param sessionId - Session whose running work should stop.
|
|
19360
|
+
*/
|
|
19361
|
+
async stopSessionActivity(sessionId) {
|
|
19362
|
+
try {
|
|
19363
|
+
await this.ctx.parallel("workspace/session-stop", { sessionId });
|
|
19364
|
+
} catch (error51) {
|
|
19365
|
+
const failures = error51 instanceof AggregateError ? error51.errors : [error51];
|
|
19366
|
+
for (const failure of failures) {
|
|
19367
|
+
this.ctx.logger.warn(
|
|
19368
|
+
`devlead: stopping Session "${String(sessionId)}" for prompt interrupt failed: ${thrownMessage(failure)}`
|
|
19369
|
+
);
|
|
19370
|
+
}
|
|
19371
|
+
}
|
|
19027
19372
|
}
|
|
19028
19373
|
/**
|
|
19029
19374
|
* Replace one lead's watch set with one Session added or removed.
|
|
@@ -19075,6 +19420,7 @@ export {
|
|
|
19075
19420
|
DevLeadService,
|
|
19076
19421
|
applyDevLeadModeProjection,
|
|
19077
19422
|
applyDevLeadProjection,
|
|
19423
|
+
applyDevLeadWatchProjection,
|
|
19078
19424
|
assistantExcerpt,
|
|
19079
19425
|
createDevLeadNoticeMessage,
|
|
19080
19426
|
createDevLeadPromptMessage,
|
|
@@ -19096,8 +19442,13 @@ export {
|
|
|
19096
19442
|
devLeadProjectionStateSchema,
|
|
19097
19443
|
devLeadProjectionView,
|
|
19098
19444
|
devLeadReport,
|
|
19445
|
+
devLeadWatchProjectionDefinition,
|
|
19446
|
+
devLeadWatchProjectionSchema,
|
|
19447
|
+
devLeadWatchProjectionStateSchema,
|
|
19448
|
+
devLeadWatchProjectionView,
|
|
19099
19449
|
emptyDevLeadModeProjectionState,
|
|
19100
19450
|
emptyDevLeadProjectionState,
|
|
19451
|
+
emptyDevLeadWatchProjectionState,
|
|
19101
19452
|
failureExcerpt,
|
|
19102
19453
|
isDevLeadError,
|
|
19103
19454
|
modeRecord,
|
package/locale/zh.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yankeguo/dsh-devlead",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0-rc.1",
|
|
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",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
}
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@yankeguo/dsh-devlead-protocol": "0.
|
|
46
|
+
"@yankeguo/dsh-devlead-protocol": "0.3.0-rc.1"
|
|
47
47
|
},
|
|
48
48
|
"engines": {
|
|
49
49
|
"dsh": ">=0.2.2-rc.1 <0.3.0"
|