/** * Producer-owned message sources for durable DeepSeek Harness writes. * * DSH 0.1.7 upgraded the durable session log to format V4. On every * message-producing event that reaches disk, `dsh-session-format-v3-to-v4`'s * admission validator now requires a producer-owned `source.kind`: a * non-empty string that is never the retired V3 wrapper value `"plugin"`. * The old wrapper shape `{ kind: "plugin", plugin: "graph-memory" }` is * rejected with `format v4 message requires a producer-owned source kind`, * which fails the whole turn once rolling compaction or tool-trace * projection triggers (https://github.com/adoresever/graph-memory/issues/113). * * The canonical producer kind for a third-party plugin is `plugin:`, * exactly what DSH's own V3-to-V4 migration (`producerKind()`) rewrites * historical graph-memory wrappers to when an old session is read. Older V3 * hosts never validate `kind`, so the same shape is safe everywhere and no * host-version branch is needed. Every durable Graph Memory surface write — * the rolling-compaction archive marker, the completed-turn trace marker, and * the recall snapshot carried through `agent/pre-step` — must build its source * here, so the V4 rule cannot be reintroduced by a future `session.append`. */ const PLUGIN_NAME = "graph-memory"; /** The V4 producer-owned source kind that owns Graph Memory surface writes. */ export const GRAPH_MEMORY_SOURCE_KIND = `plugin:${PLUGIN_NAME}`; /** * Build the producer-owned source for one Graph Memory-attributed message. * * @param extra - optional attribution fields (for example the recall * snapshot's `form` and `sections`); the V4 admission validator only * constrains `kind`, and V3→V4 migration preserves non-identity fields. */ export function ownPluginSource(extra: Record = {}): Record { return { kind: GRAPH_MEMORY_SOURCE_KIND, ...extra }; } /** * Whether a message source belongs to Graph Memory. * * Matches the V4 producer kind that current writes and migrated V4 logs carry, * plus the retired V3 wrapper that still appears in un-migrated in-memory * logs on hosts older than 0.1.7. */ export function isOwnPluginSource(source: unknown): boolean { if (!source || typeof source !== "object") return false; const record = source as Record; return record.kind === GRAPH_MEMORY_SOURCE_KIND || (record.kind === "plugin" && record.plugin === PLUGIN_NAME); }