@yankeguo/dsh-devlead 0.3.0-rc.1 → 0.3.0-rc.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 +204 -48
- package/package.json +3 -2
package/lib/index.js
CHANGED
|
@@ -15330,8 +15330,15 @@ import {
|
|
|
15330
15330
|
devLeadReportId as devLeadReportId3,
|
|
15331
15331
|
notificationId as notificationId2
|
|
15332
15332
|
} from "@yankeguo/dsh-devlead-protocol";
|
|
15333
|
-
function emptyDevLeadProjectionState() {
|
|
15334
|
-
return {
|
|
15333
|
+
function emptyDevLeadProjectionState(inheritedEventCount = 0) {
|
|
15334
|
+
return {
|
|
15335
|
+
enabled: false,
|
|
15336
|
+
sessions: [],
|
|
15337
|
+
notifications: [],
|
|
15338
|
+
reports: [],
|
|
15339
|
+
failure: null,
|
|
15340
|
+
inheritedEventCount
|
|
15341
|
+
};
|
|
15335
15342
|
}
|
|
15336
15343
|
var excerptSchema = external_exports.string().min(1).refine(
|
|
15337
15344
|
(value) => value.length <= DEVLEAD_ERROR_EXCERPT_MAX3 * 2 && Array.from(value).length <= DEVLEAD_ERROR_EXCERPT_MAX3,
|
|
@@ -15406,7 +15413,8 @@ var devLeadProjectionStateSchema = external_exports.object({
|
|
|
15406
15413
|
(reports) => new Set(reports.map((report) => report.id)).size === reports.length,
|
|
15407
15414
|
{ message: "report ids must be unique" }
|
|
15408
15415
|
),
|
|
15409
|
-
failure: external_exports.string().min(1).nullable()
|
|
15416
|
+
failure: external_exports.string().min(1).nullable(),
|
|
15417
|
+
inheritedEventCount: external_exports.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER)
|
|
15410
15418
|
}).strict();
|
|
15411
15419
|
var devLeadProjectionSchema = external_exports.object({
|
|
15412
15420
|
enabled: external_exports.boolean(),
|
|
@@ -15434,12 +15442,13 @@ function devLeadProjectionView(state) {
|
|
|
15434
15442
|
return view;
|
|
15435
15443
|
}
|
|
15436
15444
|
function applyDevLeadProjection(state, event) {
|
|
15445
|
+
if (event.seq < state.inheritedEventCount) return state;
|
|
15437
15446
|
const record2 = pluginRecordOf(event);
|
|
15438
15447
|
if (record2 === void 0) return state;
|
|
15439
15448
|
if (record2.type === DEVLEAD_RESET_RECORD_TYPE2) {
|
|
15440
15449
|
try {
|
|
15441
15450
|
decodeResetRecord(record2.data);
|
|
15442
|
-
return emptyDevLeadProjectionState();
|
|
15451
|
+
return emptyDevLeadProjectionState(state.inheritedEventCount);
|
|
15443
15452
|
} catch (error51) {
|
|
15444
15453
|
if (state.failure !== null) return state;
|
|
15445
15454
|
return freezeProjection(state, event, record2.type, error51);
|
|
@@ -15485,9 +15494,10 @@ function freezeProjection(state, event, type, error51) {
|
|
|
15485
15494
|
var devLeadProjectionDefinition = {
|
|
15486
15495
|
key: DEVLEAD_PROJECTION_KEY,
|
|
15487
15496
|
stateSchema: devLeadProjectionStateSchema,
|
|
15488
|
-
// The unit owns no Session-metadata-derived state
|
|
15489
|
-
//
|
|
15490
|
-
|
|
15497
|
+
// The unit owns no Session-metadata-derived state (the header is unused), but
|
|
15498
|
+
// it must remember the fork-inherited prefix length so inherited mode/watch
|
|
15499
|
+
// records never describe the forked Session.
|
|
15500
|
+
init: (_header, inheritedEventCount = 0) => emptyDevLeadProjectionState(inheritedEventCount),
|
|
15491
15501
|
apply: applyDevLeadProjection,
|
|
15492
15502
|
wire: {
|
|
15493
15503
|
viewSchema: devLeadProjectionSchema,
|
|
@@ -15496,19 +15506,20 @@ var devLeadProjectionDefinition = {
|
|
|
15496
15506
|
// conversation reads it: keep it out of every Session summary/list row.
|
|
15497
15507
|
summary: false
|
|
15498
15508
|
},
|
|
15499
|
-
//
|
|
15500
|
-
// are discarded and refolded from the durable log.
|
|
15501
|
-
stateVersion:
|
|
15509
|
+
// 3: adds the fork-inherited prefix length (version 2 added reports); older
|
|
15510
|
+
// cache rows are discarded and refolded from the durable log.
|
|
15511
|
+
stateVersion: 3
|
|
15502
15512
|
};
|
|
15503
|
-
function emptyDevLeadWatchProjectionState() {
|
|
15504
|
-
return { sessions: [], failure: null };
|
|
15513
|
+
function emptyDevLeadWatchProjectionState(inheritedEventCount = 0) {
|
|
15514
|
+
return { sessions: [], failure: null, inheritedEventCount };
|
|
15505
15515
|
}
|
|
15506
15516
|
var devLeadWatchProjectionStateSchema = external_exports.object({
|
|
15507
15517
|
sessions: external_exports.array(external_exports.string().min(1)).refine(
|
|
15508
15518
|
(sessions) => new Set(sessions).size === sessions.length,
|
|
15509
15519
|
{ message: "watch sessions must be unique" }
|
|
15510
15520
|
),
|
|
15511
|
-
failure: external_exports.string().min(1).nullable()
|
|
15521
|
+
failure: external_exports.string().min(1).nullable(),
|
|
15522
|
+
inheritedEventCount: external_exports.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER)
|
|
15512
15523
|
}).strict();
|
|
15513
15524
|
var devLeadWatchProjectionSchema = external_exports.object({
|
|
15514
15525
|
sessions: external_exports.array(external_exports.string().min(1)).refine(
|
|
@@ -15520,12 +15531,13 @@ function devLeadWatchProjectionView(state) {
|
|
|
15520
15531
|
return { sessions: state.sessions };
|
|
15521
15532
|
}
|
|
15522
15533
|
function applyDevLeadWatchProjection(state, event) {
|
|
15534
|
+
if (event.seq < state.inheritedEventCount) return state;
|
|
15523
15535
|
const record2 = pluginRecordOf(event);
|
|
15524
15536
|
if (record2 === void 0) return state;
|
|
15525
15537
|
if (record2.type === DEVLEAD_RESET_RECORD_TYPE2) {
|
|
15526
15538
|
try {
|
|
15527
15539
|
decodeResetRecord(record2.data);
|
|
15528
|
-
return emptyDevLeadWatchProjectionState();
|
|
15540
|
+
return emptyDevLeadWatchProjectionState(state.inheritedEventCount);
|
|
15529
15541
|
} catch (error51) {
|
|
15530
15542
|
if (state.failure !== null) return state;
|
|
15531
15543
|
const message = error51 instanceof Error ? error51.message : String(error51);
|
|
@@ -15540,7 +15552,7 @@ function applyDevLeadWatchProjection(state, event) {
|
|
|
15540
15552
|
switch (record2.type) {
|
|
15541
15553
|
case DEVLEAD_WATCH_RECORD_TYPE2: {
|
|
15542
15554
|
const watch = decodeWatchRecord(record2.data);
|
|
15543
|
-
return sameSessionIds(state.sessions, watch.sessions) ? state : { sessions: watch.sessions, failure: null };
|
|
15555
|
+
return sameSessionIds(state.sessions, watch.sessions) ? state : { sessions: watch.sessions, failure: null, inheritedEventCount: state.inheritedEventCount };
|
|
15544
15556
|
}
|
|
15545
15557
|
case DEVLEAD_MODE_RECORD_TYPE2:
|
|
15546
15558
|
decodeModeRecord(record2.data);
|
|
@@ -15565,21 +15577,23 @@ function applyDevLeadWatchProjection(state, event) {
|
|
|
15565
15577
|
var devLeadWatchProjectionDefinition = {
|
|
15566
15578
|
key: DEVLEAD_WATCH_PROJECTION_KEY,
|
|
15567
15579
|
stateSchema: devLeadWatchProjectionStateSchema,
|
|
15568
|
-
init: emptyDevLeadWatchProjectionState,
|
|
15580
|
+
init: (_header, inheritedEventCount = 0) => emptyDevLeadWatchProjectionState(inheritedEventCount),
|
|
15569
15581
|
apply: applyDevLeadWatchProjection,
|
|
15570
15582
|
wire: {
|
|
15571
15583
|
viewSchema: devLeadWatchProjectionSchema,
|
|
15572
15584
|
view: devLeadWatchProjectionView
|
|
15573
15585
|
},
|
|
15574
|
-
//
|
|
15575
|
-
|
|
15586
|
+
// 2: adds the fork-inherited prefix length; version 1 was the initial
|
|
15587
|
+
// summary representation.
|
|
15588
|
+
stateVersion: 2
|
|
15576
15589
|
};
|
|
15577
|
-
function emptyDevLeadModeProjectionState() {
|
|
15578
|
-
return { enabled: false, failure: null };
|
|
15590
|
+
function emptyDevLeadModeProjectionState(inheritedEventCount = 0) {
|
|
15591
|
+
return { enabled: false, failure: null, inheritedEventCount };
|
|
15579
15592
|
}
|
|
15580
15593
|
var devLeadModeProjectionStateSchema = external_exports.object({
|
|
15581
15594
|
enabled: external_exports.boolean(),
|
|
15582
|
-
failure: external_exports.string().min(1).nullable()
|
|
15595
|
+
failure: external_exports.string().min(1).nullable(),
|
|
15596
|
+
inheritedEventCount: external_exports.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER)
|
|
15583
15597
|
}).strict();
|
|
15584
15598
|
var devLeadModeProjectionSchema = external_exports.object({
|
|
15585
15599
|
enabled: external_exports.boolean()
|
|
@@ -15590,12 +15604,13 @@ function devLeadModeProjectionView(state) {
|
|
|
15590
15604
|
return state.enabled ? MODE_ENABLED_VIEW : MODE_DISABLED_VIEW;
|
|
15591
15605
|
}
|
|
15592
15606
|
function applyDevLeadModeProjection(state, event) {
|
|
15607
|
+
if (event.seq < state.inheritedEventCount) return state;
|
|
15593
15608
|
const record2 = pluginRecordOf(event);
|
|
15594
15609
|
if (record2 === void 0) return state;
|
|
15595
15610
|
if (record2.type === DEVLEAD_RESET_RECORD_TYPE2) {
|
|
15596
15611
|
try {
|
|
15597
15612
|
decodeResetRecord(record2.data);
|
|
15598
|
-
return emptyDevLeadModeProjectionState();
|
|
15613
|
+
return emptyDevLeadModeProjectionState(state.inheritedEventCount);
|
|
15599
15614
|
} catch (error51) {
|
|
15600
15615
|
if (state.failure !== null) return state;
|
|
15601
15616
|
const message = error51 instanceof Error ? error51.message : String(error51);
|
|
@@ -15610,7 +15625,7 @@ function applyDevLeadModeProjection(state, event) {
|
|
|
15610
15625
|
switch (record2.type) {
|
|
15611
15626
|
case DEVLEAD_MODE_RECORD_TYPE2: {
|
|
15612
15627
|
const mode = decodeModeRecord(record2.data);
|
|
15613
|
-
return mode.enabled === state.enabled ? state : { enabled: mode.enabled, failure: null };
|
|
15628
|
+
return mode.enabled === state.enabled ? state : { enabled: mode.enabled, failure: null, inheritedEventCount: state.inheritedEventCount };
|
|
15614
15629
|
}
|
|
15615
15630
|
case DEVLEAD_WATCH_RECORD_TYPE2:
|
|
15616
15631
|
decodeWatchRecord(record2.data);
|
|
@@ -15635,23 +15650,23 @@ function applyDevLeadModeProjection(state, event) {
|
|
|
15635
15650
|
var devLeadModeProjectionDefinition = {
|
|
15636
15651
|
key: DEVLEAD_MODE_PROJECTION_KEY,
|
|
15637
15652
|
stateSchema: devLeadModeProjectionStateSchema,
|
|
15638
|
-
|
|
15639
|
-
// and inherited-prefix arguments the registry passes.
|
|
15640
|
-
init: emptyDevLeadModeProjectionState,
|
|
15653
|
+
init: (_header, inheritedEventCount = 0) => emptyDevLeadModeProjectionState(inheritedEventCount),
|
|
15641
15654
|
apply: applyDevLeadModeProjection,
|
|
15642
15655
|
wire: {
|
|
15643
15656
|
viewSchema: devLeadModeProjectionSchema,
|
|
15644
15657
|
view: devLeadModeProjectionView
|
|
15645
15658
|
},
|
|
15646
|
-
//
|
|
15647
|
-
|
|
15659
|
+
// 2: adds the fork-inherited prefix length; version 1 was the initial durable
|
|
15660
|
+
// representation of the compact mode selection.
|
|
15661
|
+
stateVersion: 2
|
|
15648
15662
|
};
|
|
15649
15663
|
|
|
15650
15664
|
// packages/devlead/src/active.ts
|
|
15651
15665
|
import { pluginRecordOf as pluginRecordOf2 } from "@deepseek-ai/dsh-session";
|
|
15652
15666
|
import {
|
|
15653
15667
|
DEVLEAD_MODE_RECORD_TYPE as DEVLEAD_MODE_RECORD_TYPE3,
|
|
15654
|
-
DEVLEAD_RESET_RECORD_TYPE as DEVLEAD_RESET_RECORD_TYPE3
|
|
15668
|
+
DEVLEAD_RESET_RECORD_TYPE as DEVLEAD_RESET_RECORD_TYPE3,
|
|
15669
|
+
sessionRefLabel
|
|
15655
15670
|
} from "@yankeguo/dsh-devlead-protocol";
|
|
15656
15671
|
function lastEnabledAt(events) {
|
|
15657
15672
|
let at;
|
|
@@ -15678,8 +15693,7 @@ function rankActiveSessions(occupants, preferredSessionId) {
|
|
|
15678
15693
|
});
|
|
15679
15694
|
}
|
|
15680
15695
|
function activeSessionLabel(occupant) {
|
|
15681
|
-
|
|
15682
|
-
return title.length === 0 ? occupant.sessionId : `${title} (${occupant.sessionId})`;
|
|
15696
|
+
return sessionRefLabel(occupant.sessionId, occupant.title);
|
|
15683
15697
|
}
|
|
15684
15698
|
function alreadyActiveMessage(occupant) {
|
|
15685
15699
|
const label = activeSessionLabel(occupant);
|
|
@@ -16007,9 +16021,27 @@ var DevLeadNotificationHub = class {
|
|
|
16007
16021
|
* @param agent - live Agent that may lead.
|
|
16008
16022
|
*/
|
|
16009
16023
|
syncLead(agent) {
|
|
16024
|
+
this.syncSession(agent.session);
|
|
16025
|
+
}
|
|
16026
|
+
/**
|
|
16027
|
+
* Reconcile one Session's durable DevLead state with the hub index, with or
|
|
16028
|
+
* without a live Agent.
|
|
16029
|
+
*
|
|
16030
|
+
* Owned mode/watch/reset records can be appended to a Session that is
|
|
16031
|
+
* attached to the store but has no Agent (for example an archived attach-only
|
|
16032
|
+
* holder whose mode-off the admission path just wrote). Such a Session must
|
|
16033
|
+
* still leave the watch index, or it keeps receiving notifications and can
|
|
16034
|
+
* still be selected as a report target. Subagent Sessions are never indexed.
|
|
16035
|
+
* @param session - Session whose owned record was appended.
|
|
16036
|
+
*/
|
|
16037
|
+
syncSession(session) {
|
|
16010
16038
|
if (this.stopping) return;
|
|
16011
|
-
const sessionId = String(
|
|
16012
|
-
|
|
16039
|
+
const sessionId = String(session.id);
|
|
16040
|
+
if (session.header.origin === "subagent") {
|
|
16041
|
+
this.removeLead(sessionId);
|
|
16042
|
+
return;
|
|
16043
|
+
}
|
|
16044
|
+
const state = this.stateOf(session);
|
|
16013
16045
|
if (state === void 0 || !state.enabled) {
|
|
16014
16046
|
this.removeLead(sessionId);
|
|
16015
16047
|
return;
|
|
@@ -16143,6 +16175,22 @@ var DevLeadNotificationHub = class {
|
|
|
16143
16175
|
if (record2 !== void 0 && (record2.type === DEVLEAD_MODE_RECORD_TYPE4 || record2.type === DEVLEAD_WATCH_RECORD_TYPE3 || record2.type === DEVLEAD_RESET_RECORD_TYPE)) {
|
|
16144
16176
|
const agent = this.ctx.agents.get(session.id);
|
|
16145
16177
|
if (agent !== void 0) this.syncLead(agent);
|
|
16178
|
+
else if (session.header.origin === "subagent") this.removeLead(sessionId);
|
|
16179
|
+
else {
|
|
16180
|
+
const state = this.stateOf(session);
|
|
16181
|
+
if (state === void 0 || !state.enabled) {
|
|
16182
|
+
this.removeLead(sessionId);
|
|
16183
|
+
} else {
|
|
16184
|
+
queueMicrotask(() => {
|
|
16185
|
+
if (this.stopping) return;
|
|
16186
|
+
try {
|
|
16187
|
+
this.syncSession(session);
|
|
16188
|
+
} catch (error51) {
|
|
16189
|
+
this.ctx.logger.warn(`devlead: could not reconcile a DevLead record after append: ${thrownMessage(error51)}`);
|
|
16190
|
+
}
|
|
16191
|
+
});
|
|
16192
|
+
}
|
|
16193
|
+
}
|
|
16146
16194
|
}
|
|
16147
16195
|
if (event.type === "assistant/message") {
|
|
16148
16196
|
if (this.watchers.has(sessionId)) this.rememberAssistant(sessionId, event.data.message.content);
|
|
@@ -16445,6 +16493,19 @@ var DevLeadNotificationHub = class {
|
|
|
16445
16493
|
return source?.kind === DEVLEAD_MESSAGE_KIND3 && source?.form === "notice";
|
|
16446
16494
|
});
|
|
16447
16495
|
}
|
|
16496
|
+
/**
|
|
16497
|
+
* Drop one lead runtime and its watch index without touching durable state.
|
|
16498
|
+
*
|
|
16499
|
+
* Admission uses this when a tombstoned occupant is ignored: an archived (or
|
|
16500
|
+
* otherwise unreleasable) holder must not keep receiving notifications or be
|
|
16501
|
+
* selected as a report target. A later live index (`agent/created` after the
|
|
16502
|
+
* human opens it) re-registers the durable state and reconciles it.
|
|
16503
|
+
* @param leadId - lead Session identity to forget.
|
|
16504
|
+
*/
|
|
16505
|
+
forgetLead(leadId) {
|
|
16506
|
+
if (this.stopping) return;
|
|
16507
|
+
this.removeLead(leadId);
|
|
16508
|
+
}
|
|
16448
16509
|
/**
|
|
16449
16510
|
* Resume one cold lead Session so it can receive its queued digest.
|
|
16450
16511
|
* @param runtime - lead runtime row.
|
|
@@ -16909,6 +16970,7 @@ async function resolveSessionReference(deps, reference) {
|
|
|
16909
16970
|
var MAX_TIMER_DELAY_MS = 2147483647;
|
|
16910
16971
|
var MAX_COLD_LEAD_LOG_READS = 64;
|
|
16911
16972
|
var MAX_ACTIVE_SCAN_UNKNOWN_READS = 64;
|
|
16973
|
+
var REPORT_OUTBOX_PRUNE_INTERVAL_MS = 60 * 60 * 1e3;
|
|
16912
16974
|
var REHYDRATION_READINESS_TIMEOUT_MS = 2e3;
|
|
16913
16975
|
var REHYDRATION_READINESS_POLL_MS = 100;
|
|
16914
16976
|
var DevLeadInterruptedAdmissionError = class extends DevLeadError {
|
|
@@ -17065,6 +17127,8 @@ var DevLeadService = class extends Service {
|
|
|
17065
17127
|
outboxInjection;
|
|
17066
17128
|
/** Guard against overlapping outbox replay passes. */
|
|
17067
17129
|
outboxReplaying = false;
|
|
17130
|
+
/** Last outbox retention sweep (open or opportunistic report-write prune). */
|
|
17131
|
+
outboxPrunedAt = 0;
|
|
17068
17132
|
/**
|
|
17069
17133
|
* Archived holders whose mode-off could not be written. The durable
|
|
17070
17134
|
* tombstones live in the outbox domain; this set is the in-process mirror
|
|
@@ -17101,7 +17165,11 @@ var DevLeadService = class extends Service {
|
|
|
17101
17165
|
this.disposeRehydrationRetry();
|
|
17102
17166
|
this.outboxInjection?.dispose();
|
|
17103
17167
|
this.outboxInjection = void 0;
|
|
17104
|
-
|
|
17168
|
+
const opening = this.outboxOpening;
|
|
17169
|
+
return (async () => {
|
|
17170
|
+
await opening?.catch(() => void 0);
|
|
17171
|
+
await this.outbox?.close();
|
|
17172
|
+
})();
|
|
17105
17173
|
};
|
|
17106
17174
|
}.bind(this), "devlead: cold rehydration");
|
|
17107
17175
|
this.ctx.effect(function* () {
|
|
@@ -17440,11 +17508,14 @@ var DevLeadService = class extends Service {
|
|
|
17440
17508
|
// Mode
|
|
17441
17509
|
// ---------------------------------------------------------------------------
|
|
17442
17510
|
/**
|
|
17443
|
-
* Whether DevLead mode is selected for one exact live Agent.
|
|
17511
|
+
* Whether DevLead mode is selected for one exact live Agent. A subagent
|
|
17512
|
+
* Session never qualifies, even when a durable mode record was inherited or
|
|
17513
|
+
* hand-edited into its log.
|
|
17444
17514
|
* @param agent - candidate lead Agent.
|
|
17445
17515
|
* @returns whether the durable mode is enabled for that Agent's Session.
|
|
17446
17516
|
*/
|
|
17447
17517
|
isEnabled(agent) {
|
|
17518
|
+
if (agent.session.header.origin === "subagent") return false;
|
|
17448
17519
|
if (this.ctx.agents.get(agent.id) !== agent) return false;
|
|
17449
17520
|
const state = this.projectionHandle.stateOf(agent.session);
|
|
17450
17521
|
return state.failure === null && state.enabled;
|
|
@@ -17472,6 +17543,12 @@ var DevLeadService = class extends Service {
|
|
|
17472
17543
|
async setEnabled(agent, enabled, signal) {
|
|
17473
17544
|
await this.withAdmission(async () => {
|
|
17474
17545
|
this.assertLive(agent);
|
|
17546
|
+
if (agent.session.header.origin === "subagent") {
|
|
17547
|
+
throw new DevLeadError(
|
|
17548
|
+
"a subagent Session cannot hold DevLead mode; use a top-level Session",
|
|
17549
|
+
"DEVLEAD_INVALID_INPUT"
|
|
17550
|
+
);
|
|
17551
|
+
}
|
|
17475
17552
|
signal?.throwIfAborted();
|
|
17476
17553
|
const current = this.projectionHandle.stateOf(agent.session);
|
|
17477
17554
|
if (current.failure !== null) {
|
|
@@ -17484,6 +17561,7 @@ var DevLeadService = class extends Service {
|
|
|
17484
17561
|
this.appendResetRecord(agent.session);
|
|
17485
17562
|
await this.flushDurably(agent.session, `DevLead reset for Session "${agent.id}"`);
|
|
17486
17563
|
await this.checkpointProjectionCache(agent.session, `DevLead reset for Session "${agent.id}"`);
|
|
17564
|
+
await this.discardLeadReportState(String(agent.id));
|
|
17487
17565
|
if (this.activeSessionId === String(agent.id)) this.activeSessionId = void 0;
|
|
17488
17566
|
return;
|
|
17489
17567
|
}
|
|
@@ -17528,8 +17606,7 @@ var DevLeadService = class extends Service {
|
|
|
17528
17606
|
this.appendResetRecord(agent.session);
|
|
17529
17607
|
await this.flushDurably(agent.session, `DevLead reset for Session "${agent.id}"`);
|
|
17530
17608
|
await this.checkpointProjectionCache(agent.session, `DevLead reset for Session "${agent.id}"`);
|
|
17531
|
-
await this.
|
|
17532
|
-
this.ignoredArchived.delete(String(agent.id));
|
|
17609
|
+
await this.discardLeadReportState(String(agent.id));
|
|
17533
17610
|
if (this.activeSessionId === String(agent.id)) this.activeSessionId = void 0;
|
|
17534
17611
|
});
|
|
17535
17612
|
}
|
|
@@ -17540,6 +17617,17 @@ var DevLeadService = class extends Service {
|
|
|
17540
17617
|
appendResetRecord(session) {
|
|
17541
17618
|
appendPluginRecord2(session, DEVLEAD_RESET_RECORD_TYPE, resetRecord(Date.now()));
|
|
17542
17619
|
}
|
|
17620
|
+
/**
|
|
17621
|
+
* Discard the queue-side state of one lead's DevLead epoch after a reset
|
|
17622
|
+
* marker: undelivered outbox reports and the in-process archived-holder
|
|
17623
|
+
* tombstone mirror. Both `reset()` and the frozen-fold `setEnabled(false)`
|
|
17624
|
+
* recovery are resets semantically, so they must drop the same rows.
|
|
17625
|
+
* @param sessionId - lead Session identity whose queued reports are discarded.
|
|
17626
|
+
*/
|
|
17627
|
+
async discardLeadReportState(sessionId) {
|
|
17628
|
+
await this.outbox?.dropForLead(sessionId);
|
|
17629
|
+
this.ignoredArchived.delete(sessionId);
|
|
17630
|
+
}
|
|
17543
17631
|
// ---------------------------------------------------------------------------
|
|
17544
17632
|
// Workspaces
|
|
17545
17633
|
// ---------------------------------------------------------------------------
|
|
@@ -18168,8 +18256,10 @@ var DevLeadService = class extends Service {
|
|
|
18168
18256
|
}
|
|
18169
18257
|
/** Open the optional durable outbox once and load its archived-holder tombstones. */
|
|
18170
18258
|
async openOutbox() {
|
|
18259
|
+
if (this.disposed) return;
|
|
18171
18260
|
if (this.outbox !== void 0 || this.outboxOpening !== void 0) return;
|
|
18172
18261
|
const run = (async () => {
|
|
18262
|
+
if (this.disposed) return;
|
|
18173
18263
|
const outbox = await DevLeadReportOutbox.open(this.ctx);
|
|
18174
18264
|
if (outbox === void 0) {
|
|
18175
18265
|
this.ctx.logger.debug(
|
|
@@ -18177,9 +18267,14 @@ var DevLeadService = class extends Service {
|
|
|
18177
18267
|
);
|
|
18178
18268
|
return;
|
|
18179
18269
|
}
|
|
18270
|
+
if (this.disposed) {
|
|
18271
|
+
await outbox.close();
|
|
18272
|
+
return;
|
|
18273
|
+
}
|
|
18180
18274
|
this.outbox = outbox;
|
|
18181
18275
|
for (const sessionId of outbox.ignoredIds()) this.ignoredArchived.add(sessionId);
|
|
18182
18276
|
await outbox.prune();
|
|
18277
|
+
this.outboxPrunedAt = Date.now();
|
|
18183
18278
|
})();
|
|
18184
18279
|
this.outboxOpening = run;
|
|
18185
18280
|
try {
|
|
@@ -18188,6 +18283,20 @@ var DevLeadService = class extends Service {
|
|
|
18188
18283
|
this.outboxOpening = void 0;
|
|
18189
18284
|
}
|
|
18190
18285
|
}
|
|
18286
|
+
/**
|
|
18287
|
+
* Run one throttled outbox retention sweep before a report write. Replay
|
|
18288
|
+
* already prunes on every pass; this keeps the seven-day horizon enforced on
|
|
18289
|
+
* a Host whose only outbox traffic is report writes (for example a cold lead
|
|
18290
|
+
* with `wakeColdSession: false`).
|
|
18291
|
+
*/
|
|
18292
|
+
async pruneOutboxOpportunistically() {
|
|
18293
|
+
const outbox = this.outbox;
|
|
18294
|
+
if (outbox === void 0) return;
|
|
18295
|
+
const now = Date.now();
|
|
18296
|
+
if (this.outboxPrunedAt !== 0 && now - this.outboxPrunedAt < REPORT_OUTBOX_PRUNE_INTERVAL_MS) return;
|
|
18297
|
+
this.outboxPrunedAt = now;
|
|
18298
|
+
await outbox.prune(now);
|
|
18299
|
+
}
|
|
18191
18300
|
/**
|
|
18192
18301
|
* Replay durable outbox rows whose lead is now attachable, then clear each
|
|
18193
18302
|
* row only after its Session-log receipt was flushed.
|
|
@@ -18197,6 +18306,7 @@ var DevLeadService = class extends Service {
|
|
|
18197
18306
|
this.outboxReplaying = true;
|
|
18198
18307
|
try {
|
|
18199
18308
|
await this.outbox.prune();
|
|
18309
|
+
this.outboxPrunedAt = Date.now();
|
|
18200
18310
|
const archived = new Set(
|
|
18201
18311
|
(this.ctx.get("workspaceRegistry")?.archivedSessionIds ?? []).map((id) => String(id))
|
|
18202
18312
|
);
|
|
@@ -18236,6 +18346,7 @@ var DevLeadService = class extends Service {
|
|
|
18236
18346
|
* @returns the child-facing receipt with durability status.
|
|
18237
18347
|
*/
|
|
18238
18348
|
async deliverReport(report) {
|
|
18349
|
+
await this.pruneOutboxOpportunistically();
|
|
18239
18350
|
const outboxed = this.outbox === void 0 ? false : await this.outbox.put(report);
|
|
18240
18351
|
if (outboxed && this.outbox !== void 0) {
|
|
18241
18352
|
let delivered = false;
|
|
@@ -18556,13 +18667,17 @@ var DevLeadService = class extends Service {
|
|
|
18556
18667
|
}
|
|
18557
18668
|
/**
|
|
18558
18669
|
* Find an enabled Session other than `agent`, releasing archived holders
|
|
18559
|
-
* first. This is the admission check under the global mutex
|
|
18670
|
+
* first. This is the admission check under the global mutex: it runs the
|
|
18671
|
+
* strict occupancy scan, so an unverifiable persisted corpus refuses the
|
|
18672
|
+
* enable instead of admitting a possible second lead.
|
|
18560
18673
|
* @param agent - Session requesting the mode.
|
|
18561
18674
|
* @param signal - caller cancellation checked around the scan and releases.
|
|
18562
18675
|
* @returns the blocking occupant, or undefined when the mode is free.
|
|
18676
|
+
* @throws {@link DevLeadError} `DEVLEAD_SESSION_UNAVAILABLE` when occupancy
|
|
18677
|
+
* cannot be verified.
|
|
18563
18678
|
*/
|
|
18564
18679
|
async blockingOccupant(agent, signal) {
|
|
18565
|
-
const active = await this.scanActiveSessions(signal);
|
|
18680
|
+
const active = await this.scanActiveSessions(signal, true, true);
|
|
18566
18681
|
const blockers = [];
|
|
18567
18682
|
for (const occupant of active) {
|
|
18568
18683
|
if (occupant.sessionId === String(agent.id)) continue;
|
|
@@ -18581,6 +18696,8 @@ var DevLeadService = class extends Service {
|
|
|
18581
18696
|
if (this.ignoredArchived.has(occupant.sessionId)) {
|
|
18582
18697
|
if (await this.releaseActiveOccupant(occupant, "duplicate")) {
|
|
18583
18698
|
await this.rememberReleased(occupant.sessionId);
|
|
18699
|
+
} else {
|
|
18700
|
+
await this.rememberIgnored(occupant.sessionId);
|
|
18584
18701
|
}
|
|
18585
18702
|
continue;
|
|
18586
18703
|
}
|
|
@@ -18597,11 +18714,21 @@ var DevLeadService = class extends Service {
|
|
|
18597
18714
|
* are folded exactly, `inactive` rows are skipped, and rows the cache cannot
|
|
18598
18715
|
* classify (including a Host with no cache) are folded up to a bounded read
|
|
18599
18716
|
* budget. The budget only limits an arbitrarily large unknown history and is
|
|
18600
|
-
* reported
|
|
18717
|
+
* reported.
|
|
18718
|
+
*
|
|
18719
|
+
* `strict` makes the scan safe for admission: a corpus listing failure, or a
|
|
18720
|
+
* log read failure for a row the cache positively classified as active, is a
|
|
18721
|
+
* hard `DEVLEAD_SESSION_UNAVAILABLE` instead of a best-effort skip, because
|
|
18722
|
+
* admitting on an unverifiable corpus could create a second active lead.
|
|
18723
|
+
* Reconciliation and status remain best-effort.
|
|
18601
18724
|
* @param signal - caller cancellation threaded through query reads.
|
|
18725
|
+
* @param includePersisted - whether the persisted corpus is scanned.
|
|
18726
|
+
* @param strict - whether unknown occupancy is a hard error (admission only).
|
|
18602
18727
|
* @returns every enabled Session, deduplicated by id.
|
|
18728
|
+
* @throws {@link DevLeadError} `DEVLEAD_SESSION_UNAVAILABLE` when `strict` is
|
|
18729
|
+
* set and a cache-positive candidate or the corpus listing cannot be read.
|
|
18603
18730
|
*/
|
|
18604
|
-
async scanActiveSessions(signal, includePersisted = true) {
|
|
18731
|
+
async scanActiveSessions(signal, includePersisted = true, strict = false) {
|
|
18605
18732
|
const active = /* @__PURE__ */ new Map();
|
|
18606
18733
|
const seen = /* @__PURE__ */ new Set();
|
|
18607
18734
|
const archived = new Set(
|
|
@@ -18637,7 +18764,9 @@ var DevLeadService = class extends Service {
|
|
|
18637
18764
|
records = await query.listSessions(signal);
|
|
18638
18765
|
} catch (error51) {
|
|
18639
18766
|
if (signal?.aborted === true) throw error51;
|
|
18640
|
-
|
|
18767
|
+
const detail = `could not verify global DevLead occupancy: listing persisted Sessions failed: ${thrownMessage(error51)}`;
|
|
18768
|
+
if (strict) throw new DevLeadError(detail, "DEVLEAD_SESSION_UNAVAILABLE");
|
|
18769
|
+
this.ctx.logger.warn(`devlead: ${detail}`);
|
|
18641
18770
|
return [...active.values()];
|
|
18642
18771
|
}
|
|
18643
18772
|
const cache = projectionCacheOf(this.ctx);
|
|
@@ -18648,6 +18777,10 @@ var DevLeadService = class extends Service {
|
|
|
18648
18777
|
signal?.throwIfAborted();
|
|
18649
18778
|
const sessionId = String(record2.header.id);
|
|
18650
18779
|
if (seen.has(sessionId)) continue;
|
|
18780
|
+
if (record2.header.origin === "subagent") {
|
|
18781
|
+
seen.add(sessionId);
|
|
18782
|
+
continue;
|
|
18783
|
+
}
|
|
18651
18784
|
const prefilter = cache === void 0 ? "unknown" : devLeadActivePrefilterOf(cache, record2.header);
|
|
18652
18785
|
if (prefilter === "inactive") {
|
|
18653
18786
|
seen.add(sessionId);
|
|
@@ -18662,17 +18795,26 @@ var DevLeadService = class extends Service {
|
|
|
18662
18795
|
}
|
|
18663
18796
|
seen.add(sessionId);
|
|
18664
18797
|
let events;
|
|
18798
|
+
let inheritedEventCount = 0;
|
|
18665
18799
|
try {
|
|
18666
|
-
|
|
18800
|
+
const snapshot = await query.readSession(record2.header.id);
|
|
18801
|
+
events = snapshot.events;
|
|
18802
|
+
inheritedEventCount = snapshot.inheritedEventCount;
|
|
18667
18803
|
} catch (error51) {
|
|
18668
18804
|
if (signal?.aborted === true) throw error51;
|
|
18805
|
+
if (strict && prefilter === "active") {
|
|
18806
|
+
throw new DevLeadError(
|
|
18807
|
+
`could not verify global DevLead occupancy: persisted Session "${sessionId}" is cached as an active DevLead but its log could not be read: ${thrownMessage(error51)}`,
|
|
18808
|
+
"DEVLEAD_SESSION_UNAVAILABLE"
|
|
18809
|
+
);
|
|
18810
|
+
}
|
|
18669
18811
|
if (!warnedRead) {
|
|
18670
18812
|
warnedRead = true;
|
|
18671
18813
|
this.ctx.logger.warn(`devlead: could not read a persisted Session log for global DevLead admission: ${thrownMessage(error51)}`);
|
|
18672
18814
|
}
|
|
18673
18815
|
continue;
|
|
18674
18816
|
}
|
|
18675
|
-
let state = emptyDevLeadProjectionState();
|
|
18817
|
+
let state = emptyDevLeadProjectionState(inheritedEventCount);
|
|
18676
18818
|
for (const event of events) {
|
|
18677
18819
|
state = applyDevLeadProjection(state, event);
|
|
18678
18820
|
if (state.failure !== null) break;
|
|
@@ -18760,6 +18902,7 @@ var DevLeadService = class extends Service {
|
|
|
18760
18902
|
/** Remember one ignored archived holder in memory and, when available, durably. */
|
|
18761
18903
|
async rememberIgnored(sessionId) {
|
|
18762
18904
|
this.ignoredArchived.add(sessionId);
|
|
18905
|
+
this.hub?.forgetLead(sessionId);
|
|
18763
18906
|
await this.outbox?.rememberIgnored(sessionId);
|
|
18764
18907
|
}
|
|
18765
18908
|
/** Forget one ignored-holder tombstone after a successful release. */
|
|
@@ -18812,6 +18955,8 @@ var DevLeadService = class extends Service {
|
|
|
18812
18955
|
if (this.ignoredArchived.has(occupant.sessionId)) {
|
|
18813
18956
|
if (await this.releaseActiveOccupant(occupant, "duplicate")) {
|
|
18814
18957
|
await this.rememberReleased(occupant.sessionId);
|
|
18958
|
+
} else {
|
|
18959
|
+
await this.rememberIgnored(occupant.sessionId);
|
|
18815
18960
|
}
|
|
18816
18961
|
continue;
|
|
18817
18962
|
}
|
|
@@ -18952,8 +19097,11 @@ var DevLeadService = class extends Service {
|
|
|
18952
19097
|
unknownReads += 1;
|
|
18953
19098
|
}
|
|
18954
19099
|
let events;
|
|
19100
|
+
let inheritedEventCount = 0;
|
|
18955
19101
|
try {
|
|
18956
|
-
|
|
19102
|
+
const snapshot = await query.readSession(record2.header.id);
|
|
19103
|
+
events = snapshot.events;
|
|
19104
|
+
inheritedEventCount = snapshot.inheritedEventCount;
|
|
18957
19105
|
} catch (error51) {
|
|
18958
19106
|
if (!warnedRead) {
|
|
18959
19107
|
warnedRead = true;
|
|
@@ -18961,7 +19109,7 @@ var DevLeadService = class extends Service {
|
|
|
18961
19109
|
}
|
|
18962
19110
|
continue;
|
|
18963
19111
|
}
|
|
18964
|
-
let state = emptyDevLeadProjectionState();
|
|
19112
|
+
let state = emptyDevLeadProjectionState(inheritedEventCount);
|
|
18965
19113
|
for (const event of events) {
|
|
18966
19114
|
state = applyDevLeadProjection(state, event);
|
|
18967
19115
|
if (state.failure !== null) break;
|
|
@@ -19277,7 +19425,9 @@ var DevLeadService = class extends Service {
|
|
|
19277
19425
|
* admitted immediately afterwards, and the Agent reclassifies a wake after
|
|
19278
19426
|
* an aborted phase to the next turn and latches it until the aborted
|
|
19279
19427
|
* activity converges, so the prompt cannot enter the cancelling turn. No
|
|
19280
|
-
* settlement wait is needed.
|
|
19428
|
+
* settlement wait is needed. The inbox retention restore is best-effort: a
|
|
19429
|
+
* failed restore is a warning, and the replacement prompt is admitted anyway
|
|
19430
|
+
* because the stop cannot be rolled back.
|
|
19281
19431
|
* @param leadAgent - exact live lead Agent.
|
|
19282
19432
|
* @param sessionId - target Session identity.
|
|
19283
19433
|
* @param text - non-empty prompt text.
|
|
@@ -19330,7 +19480,13 @@ var DevLeadService = class extends Service {
|
|
|
19330
19480
|
const kept = keptInputsOf(target, String(leadAgent.id), options.interruptInbox);
|
|
19331
19481
|
await this.stopSessionActivity(sessionId);
|
|
19332
19482
|
if (options.interruptInbox !== "clear-all") {
|
|
19333
|
-
|
|
19483
|
+
try {
|
|
19484
|
+
retainedInputs = restoreInputs(target, kept);
|
|
19485
|
+
} catch (error51) {
|
|
19486
|
+
this.ctx.logger.warn(
|
|
19487
|
+
`devlead: could not restore queued input for Session "${sessionId}" after the interrupt: ` + thrownMessage(error51)
|
|
19488
|
+
);
|
|
19489
|
+
}
|
|
19334
19490
|
}
|
|
19335
19491
|
}
|
|
19336
19492
|
try {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yankeguo/dsh-devlead",
|
|
3
|
-
"version": "0.3.0-rc.
|
|
3
|
+
"version": "0.3.0-rc.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",
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
"./package.json": "./package.json"
|
|
12
12
|
},
|
|
13
13
|
"files": [
|
|
14
|
+
"LICENSE",
|
|
14
15
|
"lib",
|
|
15
16
|
"locale/*.json",
|
|
16
17
|
"README.md"
|
|
@@ -43,7 +44,7 @@
|
|
|
43
44
|
}
|
|
44
45
|
},
|
|
45
46
|
"dependencies": {
|
|
46
|
-
"@yankeguo/dsh-devlead-protocol": "0.3.0-rc.
|
|
47
|
+
"@yankeguo/dsh-devlead-protocol": "0.3.0-rc.2"
|
|
47
48
|
},
|
|
48
49
|
"engines": {
|
|
49
50
|
"dsh": ">=0.2.2-rc.1 <0.3.0"
|