stratagate-dsh 0.3.0 → 0.3.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/CHANGELOG.md +6 -1
- package/README.md +36 -8
- package/README.zh-CN.md +36 -9
- package/dist/client.js +1 -1
- package/dist/plugin.js +49 -6
- package/dist/plugin.js.map +1 -1
- package/package.json +1 -1
package/dist/plugin.js
CHANGED
|
@@ -4456,7 +4456,10 @@ var StrataGate = class _StrataGate {
|
|
|
4456
4456
|
}
|
|
4457
4457
|
});
|
|
4458
4458
|
}
|
|
4459
|
-
if (memory.graphProjector) await memory.commitMutation(() =>
|
|
4459
|
+
if (memory.graphProjector) await memory.commitMutation(() => {
|
|
4460
|
+
memory.recoverGraphNameProvenanceFailures();
|
|
4461
|
+
memory.queueMissingGraphProjections();
|
|
4462
|
+
});
|
|
4460
4463
|
}
|
|
4461
4464
|
return memory;
|
|
4462
4465
|
}
|
|
@@ -5379,6 +5382,7 @@ var StrataGate = class _StrataGate {
|
|
|
5379
5382
|
return event ? [event] : [];
|
|
5380
5383
|
});
|
|
5381
5384
|
if (events.length === 0) throw new Error(`Graph projection ${job.id} has no available source events`);
|
|
5385
|
+
job.nameProvenanceRecoveryVersion = 1;
|
|
5382
5386
|
job.status = "running";
|
|
5383
5387
|
job.attempts += 1;
|
|
5384
5388
|
job.lastError = null;
|
|
@@ -6269,6 +6273,7 @@ var StrataGate = class _StrataGate {
|
|
|
6269
6273
|
priority,
|
|
6270
6274
|
nodeIds: [],
|
|
6271
6275
|
edgeIds: [],
|
|
6276
|
+
nameProvenanceRecoveryVersion: 1,
|
|
6272
6277
|
reason: null,
|
|
6273
6278
|
lastError: null,
|
|
6274
6279
|
nextRetryAt: null,
|
|
@@ -6278,6 +6283,21 @@ var StrataGate = class _StrataGate {
|
|
|
6278
6283
|
this.graphProjectionJobs.set(job.id, job);
|
|
6279
6284
|
return job;
|
|
6280
6285
|
}
|
|
6286
|
+
recoverGraphNameProvenanceFailures() {
|
|
6287
|
+
const signature = /^StrataGate model did not produce a valid stratagate_project_knowledge_graph call after 2 attempts: StrataGate stratagate_project_knowledge_graph arguments were invalid: "nodes\[\d+\]\.metadataProvenance\.name\[\d+\]" must be a string(?:; "nodes\[\d+\]\.metadataProvenance\.name\[\d+\]" must be a string)*$/;
|
|
6288
|
+
for (const job of this.graphProjectionJobs.values()) {
|
|
6289
|
+
if (job.projectorVersion !== KNOWLEDGE_GRAPH_PROJECTOR_VERSION || job.nameProvenanceRecoveryVersion !== void 0 || job.status !== "failed" || job.attempts < DERIVATION_MAX_ATTEMPTS && job.nextRetryAt !== null || !signature.test((job.lastError ?? "").split("\n")[0].trim()) || job.sourceEventIds.length === 0 || !job.sourceEventIds.every((id) => {
|
|
6290
|
+
const event = this.findEvent(id);
|
|
6291
|
+
return event && (event.status === "active" || event.status === "superseded");
|
|
6292
|
+
})) continue;
|
|
6293
|
+
job.nameProvenanceRecoveryVersion = 1;
|
|
6294
|
+
job.status = "pending";
|
|
6295
|
+
job.attempts = 0;
|
|
6296
|
+
job.lastError = null;
|
|
6297
|
+
job.nextRetryAt = null;
|
|
6298
|
+
job.updatedAt = toUtc8Iso(this.now());
|
|
6299
|
+
}
|
|
6300
|
+
}
|
|
6281
6301
|
queueMissingGraphProjections() {
|
|
6282
6302
|
const candidates = this.listAllEvents().filter((event) => event.status !== "forgotten" && event.status !== "archived").sort((left, right) => {
|
|
6283
6303
|
const score = (event) => (event.status === "active" ? 1e4 : 0) + event.weight.mentionCount * 100 + (event.scope === "project" ? 500 : 0) + (Date.parse(event.temporal.happenedStart ?? event.temporal.mentionedAt ?? event.updatedAt) || 0) / 1e12;
|
|
@@ -7261,11 +7281,27 @@ var GRAPH_METADATA_PROVENANCE = {
|
|
|
7261
7281
|
type: "object",
|
|
7262
7282
|
additionalProperties: false,
|
|
7263
7283
|
properties: {
|
|
7264
|
-
name: { ...STRING_ARRAY, required: true },
|
|
7265
|
-
aliases: { type: "array", items: GRAPH_METADATA_ENTRY },
|
|
7266
|
-
tags: { type: "array", items: GRAPH_METADATA_ENTRY }
|
|
7284
|
+
name: { ...STRING_ARRAY, description: 'Exact supplied Event ID strings supporting node.name, e.g. ["evt_x"]. Unlike aliases/tags, this is NOT an array of { value, sourceEventIds } objects.', required: true },
|
|
7285
|
+
aliases: { type: "array", items: GRAPH_METADATA_ENTRY, description: 'One { value, sourceEventIds: ["evt_x"] } object per supported alias; value is the alias.' },
|
|
7286
|
+
tags: { type: "array", items: GRAPH_METADATA_ENTRY, description: 'One { value, sourceEventIds: ["evt_x"] } object per supported tag; value is the tag.' }
|
|
7267
7287
|
}
|
|
7268
7288
|
};
|
|
7289
|
+
function normalizeGraphNameProvenance(value) {
|
|
7290
|
+
const result = object(value);
|
|
7291
|
+
if (!Array.isArray(result.nodes)) return value;
|
|
7292
|
+
for (const candidate of result.nodes) {
|
|
7293
|
+
const node = object(candidate);
|
|
7294
|
+
const metadata = object(node.metadataProvenance);
|
|
7295
|
+
const entries = metadata.name;
|
|
7296
|
+
if (typeof node.name !== "string" || !Array.isArray(entries) || entries.length === 0) continue;
|
|
7297
|
+
if (!entries.every((candidateEntry) => {
|
|
7298
|
+
const entry = object(candidateEntry);
|
|
7299
|
+
return entry.value === node.name && Object.keys(entry).every((key) => key === "value" || key === "sourceEventIds") && Array.isArray(entry.sourceEventIds) && entry.sourceEventIds.length > 0 && entry.sourceEventIds.every((id) => typeof id === "string");
|
|
7300
|
+
})) continue;
|
|
7301
|
+
metadata.name = [...new Set(entries.flatMap((entry) => entry.sourceEventIds))];
|
|
7302
|
+
}
|
|
7303
|
+
return value;
|
|
7304
|
+
}
|
|
7269
7305
|
var GRAPH_NODE = {
|
|
7270
7306
|
type: "object",
|
|
7271
7307
|
additionalProperties: false,
|
|
@@ -7715,7 +7751,7 @@ Use project scope for repository decisions, user scope for stable preferences/id
|
|
|
7715
7751
|
const eventIds = new Set(context.events.map((event) => event.id));
|
|
7716
7752
|
const raw = object(await this.callStructured(
|
|
7717
7753
|
"graphProjector",
|
|
7718
|
-
`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. 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.`,
|
|
7754
|
+
`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.`,
|
|
7719
7755
|
compactGraphProjectionContext(context)
|
|
7720
7756
|
));
|
|
7721
7757
|
const nodes = (Array.isArray(raw.nodes) ? raw.nodes : []).flatMap((candidate) => {
|
|
@@ -7863,6 +7899,7 @@ Use project scope for repository decisions, user scope for stable preferences/id
|
|
|
7863
7899
|
let lastResponse = "";
|
|
7864
7900
|
let attemptsUsed = 0;
|
|
7865
7901
|
let noAdapterRetried = false;
|
|
7902
|
+
let graphRetryFeedback = "";
|
|
7866
7903
|
for (let attempt = 1; attempt <= JSON_RESPONSE_ATTEMPTS; attempt += 1) {
|
|
7867
7904
|
attemptsUsed = attempt;
|
|
7868
7905
|
const message = createUserMessage({
|
|
@@ -7876,7 +7913,7 @@ Use project scope for repository decisions, user scope for stable preferences/id
|
|
|
7876
7913
|
messages: [message],
|
|
7877
7914
|
system: attempt === 1 ? system : `${system}
|
|
7878
7915
|
|
|
7879
|
-
${JSON_RETRY_INSTRUCTION}`,
|
|
7916
|
+
${JSON_RETRY_INSTRUCTION}${graphRetryFeedback}`,
|
|
7880
7917
|
tools: [{
|
|
7881
7918
|
name: STRUCTURED_TOOLS[kind].name,
|
|
7882
7919
|
description: STRUCTURED_TOOLS[kind].description,
|
|
@@ -7953,8 +7990,14 @@ ${JSON_RETRY_INSTRUCTION}`,
|
|
|
7953
7990
|
);
|
|
7954
7991
|
}
|
|
7955
7992
|
}
|
|
7993
|
+
if (kind === "graphProjector") parsed = normalizeGraphNameProvenance(parsed);
|
|
7956
7994
|
const violations = validateArgs(STRUCTURED_TOOLS[kind].parameters, parsed);
|
|
7957
7995
|
if (violations.length > 0) {
|
|
7996
|
+
if (kind === "graphProjector") {
|
|
7997
|
+
const paths = violations.flatMap((violation) => violation.match(/nodes\[\d+\]\.metadataProvenance\.name(?:\[\d+\])?/g) ?? []);
|
|
7998
|
+
graphRetryFeedback = paths.length > 0 ? `
|
|
7999
|
+
Correct these canonical-name provenance fields: ${[...new Set(paths)].slice(0, 24).join(", ")}. metadataProvenance.name must be an array of supplied Event ID strings, e.g. ["evt_x"], supporting the actual node.name. Only aliases/tags use { value, sourceEventIds } objects. Do not substitute provenance for a different name.` : "";
|
|
8000
|
+
}
|
|
7958
8001
|
throw new ModelJsonResponseError(
|
|
7959
8002
|
`StrataGate ${expectedTool} arguments were invalid: ${kind === "topicProjector" ? "structured topic schema mismatch" : violations.join("; ")}`,
|
|
7960
8003
|
{ response: responseForError }
|