dsh-compaction-weave 0.0.0-stage → 0.3.3

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.
Files changed (92) hide show
  1. package/CHANGELOG.md +97 -0
  2. package/LICENSE +21 -0
  3. package/README.en.md +136 -0
  4. package/README.md +139 -2
  5. package/cordis.patch.yml +19 -0
  6. package/docs/architecture.md +84 -0
  7. package/docs/benchmarks/published-0.3.2-rc.1-tests.json +576 -0
  8. package/docs/benchmarks/rc2-documentation.json +41 -0
  9. package/docs/benchmarks/rc2-linux-tests.json +590 -0
  10. package/docs/benchmarks/rc2-live-and-cost.json +746 -0
  11. package/docs/benchmarks/rc3-host-compatibility.json +2314 -0
  12. package/docs/benchmarks/rc4-tests.json +617 -0
  13. package/docs/benchmarks/review35-compression.json +117 -0
  14. package/docs/benchmarks/v0.3.2-live-four-way.json +3495 -0
  15. package/docs/benchmarks/v0.3.2-tests.json +590 -0
  16. package/docs/configuration.md +131 -0
  17. package/docs/development.md +88 -0
  18. package/docs/en/architecture.md +75 -0
  19. package/docs/en/configuration.md +131 -0
  20. package/docs/en/development.md +86 -0
  21. package/docs/en/feedback.md +47 -0
  22. package/docs/en/principles.md +235 -0
  23. package/docs/en/testing.md +368 -0
  24. package/docs/en/troubleshooting.md +59 -0
  25. package/docs/feedback.md +47 -0
  26. package/docs/images/principles-context.en.svg +77 -0
  27. package/docs/images/principles-context.zh.svg +77 -0
  28. package/docs/images/principles-pipeline.en.svg +93 -0
  29. package/docs/images/principles-pipeline.zh.svg +93 -0
  30. package/docs/images/principles-recovery.en.svg +46 -0
  31. package/docs/images/principles-recovery.zh.svg +46 -0
  32. package/docs/principles.md +235 -0
  33. package/docs/test-results.json +634 -0
  34. package/docs/testing.md +358 -0
  35. package/docs/troubleshooting.md +59 -0
  36. package/lib/abort.js +13 -0
  37. package/lib/action-state.js +60 -0
  38. package/lib/atomic-replace.js +18 -0
  39. package/lib/attachments.js +76 -0
  40. package/lib/audit-reject.js +161 -0
  41. package/lib/audit.js +939 -0
  42. package/lib/cache-policy.js +71 -0
  43. package/lib/client.js +696 -0
  44. package/lib/command-compact.js +38 -0
  45. package/lib/command-heartbeat.js +61 -0
  46. package/lib/config.js +596 -0
  47. package/lib/constraint-scope.js +37 -0
  48. package/lib/continuation-budget.js +69 -0
  49. package/lib/continuation-pending.js +57 -0
  50. package/lib/continuation-progress.js +46 -0
  51. package/lib/continuation.js +287 -0
  52. package/lib/engine-entry.js +103 -0
  53. package/lib/engine.js +2485 -0
  54. package/lib/failure-diagnostics.js +220 -0
  55. package/lib/history-source.js +74 -0
  56. package/lib/history.js +712 -0
  57. package/lib/idle-compaction.js +64 -0
  58. package/lib/index.js +611 -0
  59. package/lib/instruction-source.js +163 -0
  60. package/lib/journal.js +164 -0
  61. package/lib/manual-error.js +179 -0
  62. package/lib/memory-policy.js +383 -0
  63. package/lib/meter.js +387 -0
  64. package/lib/observation-mask.js +390 -0
  65. package/lib/proactive.js +108 -0
  66. package/lib/progress-facts.js +347 -0
  67. package/lib/progress-state.js +30 -0
  68. package/lib/prompt.js +194 -0
  69. package/lib/reconstruct.js +72 -0
  70. package/lib/reference-input.js +107 -0
  71. package/lib/region.js +972 -0
  72. package/lib/source-provenance.js +58 -0
  73. package/lib/source-recovery.js +22 -0
  74. package/lib/source-refs.js +137 -0
  75. package/lib/state.js +46 -0
  76. package/lib/storage-path.js +42 -0
  77. package/lib/summary-budget.js +187 -0
  78. package/lib/summary-config.js +308 -0
  79. package/lib/summary-progress.js +56 -0
  80. package/lib/summary-retry.js +27 -0
  81. package/lib/summary-timeout.js +68 -0
  82. package/lib/summary.js +476 -0
  83. package/lib/tools.js +341 -0
  84. package/lib/transaction-host.js +252 -0
  85. package/lib/transaction.js +285 -0
  86. package/lib/validate.js +503 -0
  87. package/lib/version.js +3 -0
  88. package/lib/window.js +120 -0
  89. package/lib/work-report.js +55 -0
  90. package/locale/en.json +6 -0
  91. package/locale/zh.json +6 -0
  92. package/package.json +71 -4
@@ -0,0 +1,107 @@
1
+ // Request-only projections with explicit XML provenance channels.
2
+ // Durable events and verified archives keep every original byte untouched.
3
+ import { isReferenceContextKind, sourceKindOf } from './source-provenance.js';
4
+ import { summaryProse } from './validate.js';
5
+
6
+ const READ_KEYS = {
7
+ skill: ['name'],
8
+ read: ['file_path'],
9
+ read_file: ['path'],
10
+ ops_read_files: ['files'],
11
+ memory_get: ['id'],
12
+ read_page: ['url'],
13
+ };
14
+
15
+ const PROJECTED_MESSAGES = new WeakSet();
16
+
17
+ export function isProjectedSummaryMessage(message) {
18
+ return Boolean(message && typeof message === 'object' && PROJECTED_MESSAGES.has(message));
19
+ }
20
+
21
+ export function sanitizeReferenceBody(text) {
22
+ return String(text ?? '').replace(
23
+ /<(\/?\s*(?:untrusted[-_]?reference|verified[-_]?user[-_]?message|channel[-_]?provenance)\b)/gi,
24
+ '&lt;$1',
25
+ );
26
+ }
27
+
28
+ function markProjected(wrapped) {
29
+ if (wrapped && typeof wrapped === 'object') PROJECTED_MESSAGES.add(wrapped);
30
+ return wrapped;
31
+ }
32
+
33
+ function wrapMessageText(message, openTag, closeTag) {
34
+ if (isProjectedSummaryMessage(message)) return message;
35
+ const content = message?.content;
36
+ if (typeof content === 'string') {
37
+ const combined = sanitizeReferenceBody(content);
38
+ return markProjected({
39
+ ...message,
40
+ content: [{ type: 'text', text: `${openTag}\n${combined}\n${closeTag}` }],
41
+ });
42
+ }
43
+ if (!Array.isArray(content)) return message;
44
+ const textBlocks = content.filter((b) => b?.type === 'text' && typeof b.text === 'string');
45
+ if (textBlocks.length === 0) return message;
46
+ const nonText = content.filter((b) => !(b?.type === 'text' && typeof b.text === 'string'));
47
+ const combined = sanitizeReferenceBody(textBlocks.map((b) => b.text).join('\n'));
48
+ return markProjected({
49
+ ...message,
50
+ content: [{ type: 'text', text: `${openTag}\n${combined}\n${closeTag}` }, ...nonText],
51
+ });
52
+ }
53
+
54
+ export function projectSummaryMessage(session, event, message) {
55
+ if (!message) return message;
56
+ const seq = event?.seq;
57
+ const kind = sourceKindOf(session, seq);
58
+ const replace = (text) => markProjected({ ...message, content: [{ type: 'text', text }] });
59
+
60
+ if (isReferenceContextKind(kind)) {
61
+ if (['runtime-context', 'session-reference', 'skill-catalog', 'time-context', 'msg-state'].includes(kind)) {
62
+ const source = event.data.source;
63
+ const names = kind === 'skill-catalog' ? (source.entries ?? []).map((e) => sanitizeReferenceBody(e.name)).filter(Boolean) : undefined;
64
+ const note = sanitizeReferenceBody(`[External ${kind} reference at source seq ${seq}; original archived. Reload the current host context or use history_read for the historical version.${names?.length ? ' Skills: ' + names.join(', ') + '. Load a named skill when needed.' : ''}]`);
65
+ return replace(`<untrusted_reference seq="${seq}" kind="${kind}">\n${note}\n</untrusted_reference>`);
66
+ }
67
+ return wrapMessageText(message, `<untrusted_reference seq="${seq}" kind="${kind}">`, '</untrusted_reference>');
68
+ }
69
+
70
+ if (kind === 'compact-checkpoint' && Array.isArray(event.data?.source?.preserved) && !event.data.source.continuation) {
71
+ const blocks = message.content;
72
+ const close = Array.isArray(blocks) ? blocks.findIndex((b) => b.type === 'text' && b.text === '</compacted-summary>') : -1;
73
+ if (close > 0 && blocks[0]?.text?.endsWith('<compacted-summary>')) {
74
+ const text = blocks.slice(1, close).filter((b) => b.type === 'text').map((b) => b.text).join('\n');
75
+ return replace('[Prior checkpoint. Original requests are selected independently from structured sources.]\n' + summaryProse(text));
76
+ }
77
+ return message;
78
+ }
79
+
80
+ if (event?.type === 'tool/result') {
81
+ if (message.isError) return message;
82
+ const callId = message.toolCallId ?? message.source?.callId;
83
+ const call = (event.sourceEventSeqs ?? [])
84
+ .map((n) => session.eventAt(n))
85
+ .find((e) => e?.type === 'tool/call' && e.data?.callId === callId);
86
+ if (call && Object.hasOwn(READ_KEYS, call.data.name)) {
87
+ let args;
88
+ try {
89
+ args = typeof call.data.arguments === 'string' ? JSON.parse(call.data.arguments) : call.data.arguments;
90
+ } catch {
91
+ args = undefined;
92
+ }
93
+ const keys = READ_KEYS[call.data.name];
94
+ if (args && keys.every((k) => args[k] !== undefined)) {
95
+ const locatorKeys = [
96
+ ...new Set([...keys, ...(['read', 'read_file'].includes(call.data.name) ? ['offset', 'limit', 'startLine', 'endLine'] : [])]),
97
+ ];
98
+ const locator = Object.fromEntries(locatorKeys.filter((k) => args[k] !== undefined).map((k) => [k, args[k]]));
99
+ const omitted = sanitizeReferenceBody(`[External content omitted from working memory. Reload with ${call.data.name} ${JSON.stringify(locator)}. Source seq ${seq} is archived for exact historical bytes; current external content may have changed.]`);
100
+ return replace(`<untrusted_reference seq="${seq}" kind="tool-result">\n${omitted}\n</untrusted_reference>`);
101
+ }
102
+ }
103
+ return wrapMessageText(message, `<untrusted_reference seq="${seq}" kind="tool-result">`, '</untrusted_reference>');
104
+ }
105
+
106
+ return message;
107
+ }