stratagate-dsh 0.2.76 → 0.2.78

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/plugin.js CHANGED
@@ -98,6 +98,11 @@ var FILLER_ONLY = /* @__PURE__ */ new Set([
98
98
  ]);
99
99
  var REPEATED_PASTE_MIN_CHARS = 80;
100
100
  var REPEATED_PASTE_MARKER = "[repeated paste omitted; original remains in L5]";
101
+ var DERIVATION_SOURCE_FIELD_MIN_CHARS = 240;
102
+ var DERIVATION_ARGUMENT_MAX_CHARS = 1200;
103
+ var DERIVATION_RESULT_MAX_CHARS = 2400;
104
+ var DERIVATION_TOOL_MESSAGE_MAX_CHARS = 2400;
105
+ var DERIVATION_SOURCE_FIELD = /^(?:code|command|program|script|source|sourcecode)$/u;
101
106
  function asBlockLevel(value) {
102
107
  return Math.max(0, Math.min(BLOCK_MAX_LEVEL, Math.round(value)));
103
108
  }
@@ -161,6 +166,73 @@ function resultSummary(value) {
161
166
  if (record2.ok === false) return "not completed";
162
167
  return "structured result returned";
163
168
  }
169
+ function serializedValue(value) {
170
+ if (typeof value === "string") return value;
171
+ try {
172
+ return JSON.stringify(value) ?? String(value);
173
+ } catch {
174
+ return String(value);
175
+ }
176
+ }
177
+ function sourceFieldName(value) {
178
+ return DERIVATION_SOURCE_FIELD.test(value.replace(/[\s_-]+/gu, "").toLocaleLowerCase());
179
+ }
180
+ function omitLargeSourceFields(value, key = "", seen = /* @__PURE__ */ new WeakSet()) {
181
+ if (typeof value === "string") {
182
+ if (!sourceFieldName(key) || value.length <= DERIVATION_SOURCE_FIELD_MIN_CHARS) return value;
183
+ return `[${key || "source"} omitted: ${value.length} chars; full value remains in L5]`;
184
+ }
185
+ if (!value || typeof value !== "object") return value;
186
+ if (seen.has(value)) return "[circular value omitted; full value remains in L5]";
187
+ seen.add(value);
188
+ if (Array.isArray(value)) return value.map((item) => omitLargeSourceFields(item, key, seen));
189
+ return Object.fromEntries(Object.entries(value).map(([nestedKey, nestedValue]) => [nestedKey, omitLargeSourceFields(nestedValue, nestedKey, seen)]));
190
+ }
191
+ function compactDerivationValue(value, maxChars, label) {
192
+ const rendered = serializedValue(value);
193
+ if (rendered.length <= maxChars) return value;
194
+ const summary = resultSummary(value);
195
+ const headChars = Math.max(160, Math.floor(maxChars * 0.48));
196
+ const tailChars = Math.max(80, Math.floor(maxChars * 0.2));
197
+ const omittedChars = Math.max(0, rendered.length - headChars - tailChars);
198
+ return {
199
+ _stratagate: `${label} compacted; full value remains in L5`,
200
+ originalChars: rendered.length,
201
+ ...summary ? { summary } : {},
202
+ head: rendered.slice(0, headChars),
203
+ tail: rendered.slice(-tailChars),
204
+ omittedChars
205
+ };
206
+ }
207
+ function compactDerivationText(value, maxChars, label) {
208
+ if (value.length <= maxChars) return value;
209
+ const headChars = Math.max(160, Math.floor(maxChars * 0.6));
210
+ const tailChars = Math.max(80, Math.floor(maxChars * 0.2));
211
+ const omittedChars = Math.max(0, value.length - headChars - tailChars);
212
+ return `${value.slice(0, headChars)}
213
+ [${label} compacted: ${omittedChars} chars omitted; full value remains in L5]
214
+ ${value.slice(-tailChars)}`;
215
+ }
216
+ function buildMemoryDerivationMessages(messages) {
217
+ return messages.map((message) => ({
218
+ ...message,
219
+ content: message.role === "tool" ? compactDerivationText(message.content, DERIVATION_TOOL_MESSAGE_MAX_CHARS, "tool message content") : message.content,
220
+ ...message.toolCalls ? {
221
+ toolCalls: message.toolCalls.map((trace) => {
222
+ const argumentsValue = trace.arguments === void 0 ? void 0 : compactDerivationValue(
223
+ omitLargeSourceFields(trace.arguments),
224
+ DERIVATION_ARGUMENT_MAX_CHARS,
225
+ "tool arguments"
226
+ );
227
+ return {
228
+ name: trace.name,
229
+ ...argumentsValue === void 0 ? {} : { arguments: argumentsValue },
230
+ ...trace.result === void 0 ? {} : { result: compactDerivationValue(trace.result, DERIVATION_RESULT_MAX_CHARS, "tool result") }
231
+ };
232
+ })
233
+ } : {}
234
+ }));
235
+ }
164
236
  function summarizeToolTrace(trace) {
165
237
  const summary = resultSummary(trace.result);
166
238
  return `Tool call: ${trace.name}${summary ? ` (${summary})` : ""}`;
@@ -5426,7 +5498,14 @@ function l2Neighbor(block) {
5426
5498
  }
5427
5499
  function extractorPayload(context) {
5428
5500
  return {
5429
- target: context.target,
5501
+ target: {
5502
+ blockId: context.target.id,
5503
+ sequence: context.target.sequence,
5504
+ startTurn: context.target.startTurn,
5505
+ endTurn: context.target.endTurn,
5506
+ createdAt: context.target.createdAt,
5507
+ messages: buildMemoryDerivationMessages(context.target.l5Raw)
5508
+ },
5430
5509
  neighbors: {
5431
5510
  previous: l2Neighbor(context.previous),
5432
5511
  next: l2Neighbor(context.next)
@@ -5697,8 +5776,8 @@ var DshModelBridge = class {
5697
5776
  summarizer = async (messages) => {
5698
5777
  const raw = object(await this.callStructured(
5699
5778
  "summarizer",
5700
- `You compress agent conversations into durable memory blocks. Read the supplied messages and call ${STRUCTURED_TOOLS.summarizer.name} exactly once with l0Title, l0Tags, l1Summary, l2Keypoints, and shouldExtract. Preserve decisions, constraints, preferences, outcomes, and unresolved work. shouldExtract is true only when durable events or facts exist. Do not return the summary as text.`,
5701
- { messages }
5779
+ `You compress agent conversations into durable memory blocks. Read the supplied provenance-preserving derivation messages and call ${STRUCTURED_TOOLS.summarizer.name} exactly once with l0Title, l0Tags, l1Summary, l2Keypoints, and shouldExtract. Preserve decisions, constraints, preferences, outcomes, and unresolved work. Tool code and oversized tool payloads may be marked compacted; use the retained tool names, evidence summaries, and excerpts without inventing omitted details. shouldExtract is true only when durable events or facts exist. Do not return the summary as text.`,
5780
+ { messages: buildMemoryDerivationMessages(messages) }
5702
5781
  ));
5703
5782
  return {
5704
5783
  l0Title: text2(raw.l0Title).slice(0, 120),
@@ -5712,7 +5791,7 @@ var DshModelBridge = class {
5712
5791
  const validMessageIds = new Set(context.target.l5Raw.map((message) => message.id));
5713
5792
  const raw = object(await this.callStructured(
5714
5793
  "extractor",
5715
- `Extract only durable, evidence-backed events from target.l5Raw, then call ${STRUCTURED_TOOLS.extractor.name} exactly once. The target block is the only legal source of new facts, quotations, and sourceMessageIds. neighbors.previous and neighbors.next are context-only L2 summaries; never extract from them. Every sourceMessageIds entry must exactly match allowedSourceMessageIds. If a fact appears only in a neighbor, do not extract it in this call. Events must be understandable later without the original chat. Use project scope for repository decisions, user scope for stable preferences/identity, and session scope for temporary task state. temporal.eventType must use exactly one stable value: decision, release, task_completed, plan, change, cancellation, incident, meeting, collaboration, migration, or other. temporal.participants contains canonical entity names. Use ISO-8601 timestamps with the explicit +08:00 offset in temporal fields. Keep happened time separate from mentionedAt; when happened time is unknown omit it and set precision/basis to unknown. Do not turn an assistant statement that merely recalls older memory into a new event; require new human input or a new observable task/tool outcome from target.l5Raw. Do not return the result as text.`,
5794
+ `Extract only durable, evidence-backed events from target.messages, then call ${STRUCTURED_TOOLS.extractor.name} exactly once. target.messages is a provenance-preserving derivation view of the target block: message ids and conversational text are retained, while tool code and oversized tool payloads may be marked compacted. Use the retained tool names, evidence summaries, and excerpts without inventing omitted details. The target block is the only legal source of new facts, quotations, and sourceMessageIds. neighbors.previous and neighbors.next are context-only L2 summaries; never extract from them. Every sourceMessageIds entry must exactly match allowedSourceMessageIds. If a fact appears only in a neighbor, do not extract it in this call. Events must be understandable later without the original chat. Use project scope for repository decisions, user scope for stable preferences/identity, and session scope for temporary task state. temporal.eventType must use exactly one stable value: decision, release, task_completed, plan, change, cancellation, incident, meeting, collaboration, migration, or other. temporal.participants contains canonical entity names. Use ISO-8601 timestamps with the explicit +08:00 offset in temporal fields. Keep happened time separate from mentionedAt; when happened time is unknown omit it and set precision/basis to unknown. Do not turn an assistant statement that merely recalls older memory into a new event; require new human input or a new observable task/tool outcome from target.messages. Do not return the result as text.`,
5716
5795
  extractorPayload(context)
5717
5796
  ));
5718
5797
  const events = (Array.isArray(raw.events) ? raw.events : []).map((candidate) => {