stratagate-dsh 0.3.43 → 0.3.44
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/dist/client.js +1 -1
- package/dist/plugin.js +76 -13
- package/dist/plugin.js.map +1 -1
- package/package.json +1 -1
package/dist/plugin.js
CHANGED
|
@@ -919,7 +919,8 @@ function applyGraphProjection(options) {
|
|
|
919
919
|
warnings.push(`Dropped current edge "${relation}" because it has no active Event provenance.`);
|
|
920
920
|
continue;
|
|
921
921
|
}
|
|
922
|
-
|
|
922
|
+
const supersededIds = new Set(strings(proposal.supersedesEdgeIds, 64));
|
|
923
|
+
for (const old of options.edges.filter((edge2) => supersededIds.has(edge2.id) && edge2.status === "active" && edge2.fromNodeId === from.id && edge2.relation === relation && edge2.toNodeId !== to.id)) {
|
|
923
924
|
old.status = "superseded";
|
|
924
925
|
if (!old.validTo) old.validTo = validFrom;
|
|
925
926
|
old.updatedAt = options.now;
|
|
@@ -11405,6 +11406,7 @@ var GRAPH_EDGE = {
|
|
|
11405
11406
|
fromRef: { type: "string", required: true },
|
|
11406
11407
|
toRef: { type: "string", required: true },
|
|
11407
11408
|
relation: { type: "string", required: true },
|
|
11409
|
+
supersedesEdgeIds: STRING_ARRAY,
|
|
11408
11410
|
status: { type: "string", enum: ["active", "superseded", "disputed", "archived"] },
|
|
11409
11411
|
validFrom: { type: "string" },
|
|
11410
11412
|
validTo: { type: "string" },
|
|
@@ -11616,7 +11618,9 @@ function compactGraphProjectionContext(context) {
|
|
|
11616
11618
|
status: node.status,
|
|
11617
11619
|
sourceEventIds: node.sourceEventIds.slice(-16)
|
|
11618
11620
|
})),
|
|
11621
|
+
// id is the handle for explicit supersedesEdgeIds. Timestamps and confidence stay off the prompt.
|
|
11619
11622
|
existingEdges: context.existingEdges.slice(-60).map((edge) => ({
|
|
11623
|
+
id: edge.id,
|
|
11620
11624
|
fromNodeId: edge.fromNodeId,
|
|
11621
11625
|
toNodeId: edge.toNodeId,
|
|
11622
11626
|
relation: edge.relation,
|
|
@@ -12032,7 +12036,7 @@ Use project scope for repository decisions, user scope for stable preferences/id
|
|
|
12032
12036
|
const eventIds = new Set(context.events.map((event) => event.id));
|
|
12033
12037
|
const raw = object(await this.callStructured(
|
|
12034
12038
|
"graphProjector",
|
|
12035
|
-
`Project the supplied Events into the current Knowledge Graph, then call ${STRUCTURED_TOOLS.graphProjector.name} exactly once. Events are the sole source of truth; never use legacy Element data. Return only nodes and edges touched by the supplied Events; never echo unchanged historical graph records. Return at most 24 nodes and 32 edges. Use stable entity nodes for people, projects, organizations, tools, and places. Use aliases to merge spelling/case/separator variants. Give every returned node 1-6 concise semantic role tags such as benchmark, evaluation, memory-plugin, parser, or development-tool; tags describe the node's specific role and never replace its person/project/organization/tool/place type. Reuse stable tag wording when possible. For every node name, alias, and tag, include metadataProvenance with the exact supplied Event ids that support that individual value; never use an unrelated active Event as a substitute. The shapes are different: metadataProvenance.name is an Event ID string array, e.g. ["evt_x"], supporting node.name; it is never an array of objects. Only metadataProvenance.aliases and metadataProvenance.tags are arrays of { value, sourceEventIds: ["evt_x"] } objects for each alias/tag. Example for node.name="StrataGate": metadataProvenance={"name":["evt_x"],"aliases":[{"value":"strata_gate","sourceEventIds":["evt_x"]}],"tags":[{"value":"memory-plugin","sourceEventIds":["evt_x"]}]}. Put attributes in node facts and every relationship in a directed edge using fromRef/toRef\u2014never encode a relationship as a fact string. Prefer concise canonical Chinese relation labels such as \u4F7F\u7528\u3001\u5C5E\u4E8E\u3001\u521B\u5EFA\u3001\u53C2\u4E0E\u3001\u8D21\u732E\u3001\u4F9D\u8D56\u3001\u4F4D\u4E8E\u3001\u76F8\u5173. Every node, fact, edge, and metadata provenance id must cite only supplied Event ids. Do not return text.`,
|
|
12039
|
+
`Project the supplied Events into the current Knowledge Graph, then call ${STRUCTURED_TOOLS.graphProjector.name} exactly once. Events are the sole source of truth; never use legacy Element data. Return only nodes and edges touched by the supplied Events; never echo unchanged historical graph records. Return at most 24 nodes and 32 edges. Use stable entity nodes for people, projects, organizations, tools, and places. Use aliases to merge spelling/case/separator variants. Give every returned node 1-6 concise semantic role tags such as benchmark, evaluation, memory-plugin, parser, or development-tool; tags describe the node's specific role and never replace its person/project/organization/tool/place type. Reuse stable tag wording when possible. For every node name, alias, and tag, include metadataProvenance with the exact supplied Event ids that support that individual value; never use an unrelated active Event as a substitute. The shapes are different: metadataProvenance.name is an Event ID string array, e.g. ["evt_x"], supporting node.name; it is never an array of objects. Only metadataProvenance.aliases and metadataProvenance.tags are arrays of { value, sourceEventIds: ["evt_x"] } objects for each alias/tag. Example for node.name="StrataGate": metadataProvenance={"name":["evt_x"],"aliases":[{"value":"strata_gate","sourceEventIds":["evt_x"]}],"tags":[{"value":"memory-plugin","sourceEventIds":["evt_x"]}]}. Put attributes in node facts and every relationship in a directed edge using fromRef/toRef\u2014never encode a relationship as a fact string. Prefer concise canonical Chinese relation labels such as \u4F7F\u7528\u3001\u5C5E\u4E8E\u3001\u521B\u5EFA\u3001\u53C2\u4E0E\u3001\u8D21\u732E\u3001\u4F9D\u8D56\u3001\u4F4D\u4E8E\u3001\u76F8\u5173. Multiple targets for one relation may all be current at once. Only when supplied Events explicitly document a replacement or correction should an edge include supersedesEdgeIds copied from existingEdges.id; never supersede a same-relation edge merely because its target differs. Every node, fact, edge, and metadata provenance id must cite only supplied Event ids. Do not return text.`,
|
|
12036
12040
|
compactGraphProjectionContext(context),
|
|
12037
12041
|
void 0,
|
|
12038
12042
|
void 0,
|
|
@@ -12097,6 +12101,7 @@ Use project scope for repository decisions, user scope for stable preferences/id
|
|
|
12097
12101
|
fromRef,
|
|
12098
12102
|
toRef,
|
|
12099
12103
|
relation,
|
|
12104
|
+
...strings2(item.supersedesEdgeIds).length > 0 ? { supersedesEdgeIds: strings2(item.supersedesEdgeIds).slice(0, 32) } : {},
|
|
12100
12105
|
...typeof item.status === "string" ? { status: item.status } : {},
|
|
12101
12106
|
...text2(item.validFrom) ? { validFrom: text2(item.validFrom) } : {},
|
|
12102
12107
|
...text2(item.validTo) ? { validTo: text2(item.validTo) } : {},
|
|
@@ -14661,6 +14666,18 @@ var StrataGateRuntime = class _StrataGateRuntime {
|
|
|
14661
14666
|
if (result.sealedBlock) this.scheduleBlockDerivation(session, memory);
|
|
14662
14667
|
}
|
|
14663
14668
|
} catch (error) {
|
|
14669
|
+
if (error instanceof StorageConflictError && memory) {
|
|
14670
|
+
try {
|
|
14671
|
+
await memory.reloadFromStorage();
|
|
14672
|
+
const remaining2 = turns.slice(completed);
|
|
14673
|
+
if (remaining2.length > 0) {
|
|
14674
|
+
this.pendingTurns.set(key, [...remaining2, ...this.pendingTurns.get(key) ?? []]);
|
|
14675
|
+
}
|
|
14676
|
+
return;
|
|
14677
|
+
} catch (reloadError) {
|
|
14678
|
+
error = reloadError;
|
|
14679
|
+
}
|
|
14680
|
+
}
|
|
14664
14681
|
const remaining = turns.slice(completed);
|
|
14665
14682
|
if (remaining.length > 0) {
|
|
14666
14683
|
this.pendingTurns.set(key, [...remaining, ...this.pendingTurns.get(key) ?? []]);
|
|
@@ -15250,7 +15267,7 @@ var StrataGateRuntime = class _StrataGateRuntime {
|
|
|
15250
15267
|
if (!sourceEventSeqs) return false;
|
|
15251
15268
|
const selected = selectCompressedBlockSurface(session, sourceEventSeqs, block, context);
|
|
15252
15269
|
if (!selected) return false;
|
|
15253
|
-
appendBlockSurface(session, block
|
|
15270
|
+
appendBlockSurface(session, block, selected, sourceEventSeqs);
|
|
15254
15271
|
this.surfaceFlushPending.add(session);
|
|
15255
15272
|
levels.set(block.id, checkpointLevel(selected) ?? context.level);
|
|
15256
15273
|
return true;
|
|
@@ -15303,7 +15320,7 @@ var StrataGateRuntime = class _StrataGateRuntime {
|
|
|
15303
15320
|
);
|
|
15304
15321
|
if (!text3) continue;
|
|
15305
15322
|
if (node.text !== text3) {
|
|
15306
|
-
appendBlockSurface(session, block
|
|
15323
|
+
appendBlockSurface(session, block, text3, [node.seq]);
|
|
15307
15324
|
this.surfaceFlushPending.add(session);
|
|
15308
15325
|
changed = true;
|
|
15309
15326
|
}
|
|
@@ -15325,7 +15342,7 @@ var StrataGateRuntime = class _StrataGateRuntime {
|
|
|
15325
15342
|
const node = current.get(block.id);
|
|
15326
15343
|
const endTurn = node ? null : dshTurnAtBlockEnd(session, block);
|
|
15327
15344
|
const seqs = node ? [node.seq] : endTurn === null ? null : sealedSurfaceSeqs(session, endTurn, block);
|
|
15328
|
-
if (!seqs?.length || !safeBlockSurfaceRange(session, block
|
|
15345
|
+
if (!seqs?.length || !safeBlockSurfaceRange(session, block, seqs)) return {
|
|
15329
15346
|
status: "blocked",
|
|
15330
15347
|
reason: "source-unavailable",
|
|
15331
15348
|
message: "\u8FD9\u6BB5\u5386\u53F2\u5DF2\u88AB\u6574\u7406\uFF0C\u6216\u5939\u6709\u9700\u8981\u4FDD\u7559\u7684\u7CFB\u7EDF\u3001\u5DE5\u5177\u6216\u63D2\u4EF6\u5185\u5BB9\uFF0C\u65E0\u6CD5\u5728\u8FD9\u91CC\u5207\u6362\u5C42\u7EA7\u3002\u53EF\u4EE5\u8BA9\u52A9\u624B\u67E5\u627E\u8FD9\u6BB5\u5386\u53F2\u3002"
|
|
@@ -15411,13 +15428,15 @@ var StrataGateRuntime = class _StrataGateRuntime {
|
|
|
15411
15428
|
}
|
|
15412
15429
|
const { text: text3, seqs, relief } = plan;
|
|
15413
15430
|
for (const replacement of relief) {
|
|
15414
|
-
|
|
15431
|
+
const replacementBlock = memory.listBlocks().find((candidate) => candidate.id === replacement.id);
|
|
15432
|
+
if (!replacementBlock) continue;
|
|
15433
|
+
appendBlockSurface(session, replacementBlock, replacement.text, [replacement.seq]);
|
|
15415
15434
|
levels.set(replacement.id, replacement.level);
|
|
15416
15435
|
this.surfaceFlushPending.add(session);
|
|
15417
15436
|
}
|
|
15418
15437
|
const node = currentBlockSurfaceMessages(session).get(block.id);
|
|
15419
15438
|
if (node?.text !== text3) {
|
|
15420
|
-
appendBlockSurface(session, block
|
|
15439
|
+
appendBlockSurface(session, block, text3, seqs);
|
|
15421
15440
|
this.surfaceFlushPending.add(session);
|
|
15422
15441
|
}
|
|
15423
15442
|
levels.set(block.id, context.level);
|
|
@@ -17412,8 +17431,9 @@ function sealedSurfaceSeqs(session, endTurn, block) {
|
|
|
17412
17431
|
nodes: currentSurface.filter((seq) => {
|
|
17413
17432
|
const current = session.eventAt(seq);
|
|
17414
17433
|
if (!replaceableBlockEvent(current, block.id)) return false;
|
|
17434
|
+
if ((current?.type === "assistant/message" || current?.type === "tool/result") && !surfaceEventBelongsToTurn(session, current, open2.turn)) return false;
|
|
17415
17435
|
if (seq > open2.start && seq < event.seq) return true;
|
|
17416
|
-
return current?.type === "tool/result" && current.surfaceOp !== "append" && current.sourceEventSeqs?.some((source) => source > open2.start && source < event.seq);
|
|
17436
|
+
return (current?.type === "tool/result" || current?.type === "assistant/message") && surfaceEventBelongsToTurn(session, current, open2.turn) && current.surfaceOp !== "append" && current.sourceEventSeqs?.some((source) => source > open2.start && source < event.seq);
|
|
17417
17437
|
})
|
|
17418
17438
|
});
|
|
17419
17439
|
}
|
|
@@ -17437,19 +17457,62 @@ function sealedSurfaceSeqs(session, endTurn, block) {
|
|
|
17437
17457
|
const endIndex = currentSurface.indexOf(end);
|
|
17438
17458
|
if (startIndex < 0 || endIndex < startIndex) return null;
|
|
17439
17459
|
const range = currentSurface.slice(startIndex, endIndex + 1);
|
|
17440
|
-
return safeBlockSurfaceRange(session, block
|
|
17460
|
+
return safeBlockSurfaceRange(session, block, range) ? range : null;
|
|
17441
17461
|
}
|
|
17442
17462
|
function replaceableBlockEvent(event, blockId) {
|
|
17443
17463
|
if (event?.type === "assistant/message" || event?.type === "tool/result") return true;
|
|
17444
17464
|
return event?.type === "user/message" && (event.data.source.kind === "user" || blockSurfaceMessage(event)?.id === blockId);
|
|
17445
17465
|
}
|
|
17446
|
-
function
|
|
17466
|
+
function turnAtSurfaceSeq(session, seq) {
|
|
17467
|
+
let turn;
|
|
17468
|
+
for (const event of session.snapshotEvents()) {
|
|
17469
|
+
if (event.seq >= seq) break;
|
|
17470
|
+
if (event.type === "turn/start") turn = event.data.turn;
|
|
17471
|
+
else if (event.type === "turn/end") turn = void 0;
|
|
17472
|
+
}
|
|
17473
|
+
return turn;
|
|
17474
|
+
}
|
|
17475
|
+
function sourceTurnsForBlock(session, block) {
|
|
17476
|
+
const sourceTimes = new Set(block.l5Raw.filter((message) => message.role === "user").map((message) => Date.parse(message.createdAt)));
|
|
17477
|
+
return new Set(session.snapshotEvents().filter((event) => event.type === "turn/end" && sourceTimes.has(event.time)).map((event) => event.data.turn));
|
|
17478
|
+
}
|
|
17479
|
+
function surfaceEventTurns(session, event) {
|
|
17480
|
+
if (event.surfaceOp !== "append" && event.sourceEventSeqs?.length) {
|
|
17481
|
+
const sourceTurns = event.sourceEventSeqs.flatMap((source) => {
|
|
17482
|
+
const original = session.eventAt(source);
|
|
17483
|
+
return original?.type === "assistant/message" || original?.type === "tool/result" ? [original.data.turn] : [];
|
|
17484
|
+
});
|
|
17485
|
+
if (sourceTurns.length > 0) return new Set(sourceTurns);
|
|
17486
|
+
}
|
|
17487
|
+
return /* @__PURE__ */ new Set([event.data.turn]);
|
|
17488
|
+
}
|
|
17489
|
+
function surfaceEventBelongsToTurn(session, event, turn) {
|
|
17490
|
+
const turns = surfaceEventTurns(session, event);
|
|
17491
|
+
return turns.size === 1 && turns.has(turn);
|
|
17492
|
+
}
|
|
17493
|
+
function safeBlockSurfaceRange(session, block, seqs) {
|
|
17447
17494
|
if (seqs.length === 0) return false;
|
|
17448
17495
|
const start = session.surface.nodes.indexOf(seqs[0]);
|
|
17449
|
-
|
|
17496
|
+
if (start < 0) return false;
|
|
17497
|
+
const sourceTurns = sourceTurnsForBlock(session, block);
|
|
17498
|
+
return seqs.every((seq, index) => {
|
|
17499
|
+
if (session.surface.nodes[start + index] !== seq) return false;
|
|
17500
|
+
const event = session.eventAt(seq);
|
|
17501
|
+
if (!replaceableBlockEvent(event, block.id)) return false;
|
|
17502
|
+
const checkpoint = blockSurfaceMessage(event);
|
|
17503
|
+
if (checkpoint) return checkpoint.id === block.id;
|
|
17504
|
+
if (event?.type === "assistant/message" || event?.type === "tool/result") {
|
|
17505
|
+
const eventTurns = surfaceEventTurns(session, event);
|
|
17506
|
+
return eventTurns.size > 0 && [...eventTurns].every((turn) => sourceTurns.has(turn));
|
|
17507
|
+
}
|
|
17508
|
+
if (event?.type === "user/message" && event.data.source.kind === "user") {
|
|
17509
|
+
return sourceTurns.has(turnAtSurfaceSeq(session, seq) ?? -1);
|
|
17510
|
+
}
|
|
17511
|
+
return false;
|
|
17512
|
+
});
|
|
17450
17513
|
}
|
|
17451
|
-
function appendBlockSurface(session,
|
|
17452
|
-
if (!safeBlockSurfaceRange(session,
|
|
17514
|
+
function appendBlockSurface(session, block, text3, seqs) {
|
|
17515
|
+
if (!safeBlockSurfaceRange(session, block, seqs)) {
|
|
17453
17516
|
throw Object.assign(new Error("StrataGate surface replacement no longer owns its complete source range"), { retryable: false });
|
|
17454
17517
|
}
|
|
17455
17518
|
session.append("user/message", createUserMessage2({
|