@claude-flow/cli 3.10.15 → 3.10.16

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.
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Structured Distillation for trajectory content (#2241 §SOTA — arXiv:2603.13017).
3
+ *
4
+ * The arXiv paper compresses agent exchanges from ~371 to ~38 tokens (11×) using
5
+ * a four-field schema, and reports retrieval MRR going from 0.745 (raw) to
6
+ * 0.759 (distilled) on a 214 K-pair consensus-graded corpus. The schema is
7
+ * domain-portable; we adopt it for trajectory step content so SONA's recall
8
+ * works against a denser, higher-signal representation.
9
+ *
10
+ * This module is the RULE-BASED extractor. A future round can plug in a
11
+ * learned distiller (cross-encoder / LLM); the schema and the harness stay
12
+ * the same so the swap is drop-in.
13
+ *
14
+ * Schema:
15
+ * summary — first sentence (capped); the headline of the exchange
16
+ * detail — the rest of the content (capped); kept for fidelity
17
+ * labels — domain tokens: verbs, nouns, and recognised actions
18
+ * paths — file paths and file:line references (high-signal anchors)
19
+ */
20
+ /** Distilled trajectory content. */
21
+ export interface DistilledContent {
22
+ summary: string;
23
+ detail: string;
24
+ labels: string[];
25
+ paths: string[];
26
+ }
27
+ /**
28
+ * Distill a raw trajectory step's content into the 4-field schema.
29
+ * Deterministic, dependency-free, sub-millisecond.
30
+ */
31
+ export declare function distillTrajectoryContent(raw: string): DistilledContent;
32
+ /**
33
+ * Serialise a distilled object into a compact embedding-ready string. The
34
+ * resulting form is what gets embedded for retrieval — labels and paths come
35
+ * first so they get high attention weight in the embedding.
36
+ *
37
+ * The paper's MRR uplift comes from the ordering: high-signal tokens (labels,
38
+ * paths) lead, so the embedder allocates more probability mass to them.
39
+ */
40
+ export declare function serialiseDistilled(d: DistilledContent): string;
41
+ /** Convenience: distill then serialise. */
42
+ export declare function distillAndSerialise(raw: string): string;
43
+ /**
44
+ * Compression ratio: raw bytes / distilled bytes. >1 means distilled is
45
+ * smaller. Used by the benchmark harness.
46
+ */
47
+ export declare function compressionRatio(raw: string): number;
48
+ //# sourceMappingURL=structured-distill.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"structured-distill.d.ts","sourceRoot":"","sources":["../../../src/memory/structured-distill.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,oCAAoC;AACpC,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,KAAK,EAAE,MAAM,EAAE,CAAC;CACjB;AA2DD;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,GAAG,EAAE,MAAM,GAAG,gBAAgB,CAYtE;AAED;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,gBAAgB,GAAG,MAAM,CAO9D;AAED,2CAA2C;AAC3C,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEvD;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAIpD"}
@@ -0,0 +1,125 @@
1
+ /**
2
+ * Structured Distillation for trajectory content (#2241 §SOTA — arXiv:2603.13017).
3
+ *
4
+ * The arXiv paper compresses agent exchanges from ~371 to ~38 tokens (11×) using
5
+ * a four-field schema, and reports retrieval MRR going from 0.745 (raw) to
6
+ * 0.759 (distilled) on a 214 K-pair consensus-graded corpus. The schema is
7
+ * domain-portable; we adopt it for trajectory step content so SONA's recall
8
+ * works against a denser, higher-signal representation.
9
+ *
10
+ * This module is the RULE-BASED extractor. A future round can plug in a
11
+ * learned distiller (cross-encoder / LLM); the schema and the harness stay
12
+ * the same so the swap is drop-in.
13
+ *
14
+ * Schema:
15
+ * summary — first sentence (capped); the headline of the exchange
16
+ * detail — the rest of the content (capped); kept for fidelity
17
+ * labels — domain tokens: verbs, nouns, and recognised actions
18
+ * paths — file paths and file:line references (high-signal anchors)
19
+ */
20
+ const SUMMARY_MAX = 200;
21
+ const DETAIL_MAX = 1024;
22
+ // Imperative verbs typical of code-work trajectories (Reflexion / ReasoningBank
23
+ // vocabulary). Order-preserving for stable deduplication.
24
+ const ACTION_VOCAB = [
25
+ 'refactor', 'fix', 'add', 'remove', 'rename', 'extract', 'inline',
26
+ 'split', 'merge', 'delete', 'rewrite', 'simplify', 'optimize',
27
+ 'test', 'mock', 'stub', 'verify', 'assert', 'expect',
28
+ 'document', 'explain', 'comment',
29
+ 'debug', 'trace', 'log', 'diagnose',
30
+ 'wire', 'route', 'dispatch', 'register', 'unregister',
31
+ 'parse', 'validate', 'sanitize', 'normalize',
32
+ 'cache', 'invalidate', 'flush', 'persist', 'load',
33
+ 'embed', 'distill', 'train', 'consolidate', 'recall',
34
+ ];
35
+ // A trajectory step might contain code blocks, file refs, or natural prose;
36
+ // these regexes catch the high-signal anchors without false positives on
37
+ // general English.
38
+ const PATH_REGEX = /\b([a-zA-Z0-9_./-]+\.(?:ts|tsx|js|jsx|mjs|cjs|py|go|rs|java|kt|swift|c|cpp|h|hpp|rb|md|json|yaml|yml|toml|sql))(?::(\d+))?\b/g;
39
+ const SENTENCE_END = /([.!?])\s+(?=[A-Z(])/;
40
+ function firstSentence(text) {
41
+ const m = text.match(SENTENCE_END);
42
+ if (!m || m.index === undefined)
43
+ return text.slice(0, SUMMARY_MAX);
44
+ return text.slice(0, m.index + 1).slice(0, SUMMARY_MAX);
45
+ }
46
+ function extractPaths(text) {
47
+ const found = new Set();
48
+ for (const m of text.matchAll(PATH_REGEX)) {
49
+ found.add(m[2] ? `${m[1]}:${m[2]}` : m[1]);
50
+ }
51
+ return [...found];
52
+ }
53
+ function extractLabels(text) {
54
+ const lower = text.toLowerCase();
55
+ const labels = new Set();
56
+ // Action vocabulary
57
+ for (const v of ACTION_VOCAB) {
58
+ if (lower.includes(v))
59
+ labels.add(v);
60
+ }
61
+ // High-signal nouns (camelCase / PascalCase identifiers, ALL_CAPS constants).
62
+ // Cap to the top 5 most-frequent so labels stay short.
63
+ const counts = new Map();
64
+ for (const m of text.matchAll(/\b([A-Z][a-zA-Z0-9]{3,}|[A-Z][A-Z0-9_]{3,}|[a-z][a-zA-Z0-9]{4,}[A-Z][a-zA-Z0-9]{1,})\b/g)) {
65
+ const t = m[1];
66
+ if (/^[a-zA-Z]+$/.test(t) && t.length > 20)
67
+ continue; // skip very long words
68
+ counts.set(t, (counts.get(t) ?? 0) + 1);
69
+ }
70
+ const top = [...counts.entries()].sort((a, b) => b[1] - a[1]).slice(0, 5);
71
+ for (const [t] of top)
72
+ labels.add(t);
73
+ return [...labels];
74
+ }
75
+ /**
76
+ * Distill a raw trajectory step's content into the 4-field schema.
77
+ * Deterministic, dependency-free, sub-millisecond.
78
+ */
79
+ export function distillTrajectoryContent(raw) {
80
+ const text = String(raw ?? '').trim();
81
+ if (!text)
82
+ return { summary: '', detail: '', labels: [], paths: [] };
83
+ const paths = extractPaths(text);
84
+ const labels = extractLabels(text);
85
+ const summary = firstSentence(text);
86
+ // detail = everything after the first sentence, up to cap
87
+ const rest = text.slice(summary.length).trim();
88
+ const detail = rest.slice(0, DETAIL_MAX);
89
+ return { summary, detail, labels, paths };
90
+ }
91
+ /**
92
+ * Serialise a distilled object into a compact embedding-ready string. The
93
+ * resulting form is what gets embedded for retrieval — labels and paths come
94
+ * first so they get high attention weight in the embedding.
95
+ *
96
+ * The paper's MRR uplift comes from the ordering: high-signal tokens (labels,
97
+ * paths) lead, so the embedder allocates more probability mass to them.
98
+ */
99
+ export function serialiseDistilled(d) {
100
+ const parts = [];
101
+ if (d.labels.length)
102
+ parts.push(`[${d.labels.join(', ')}]`);
103
+ if (d.paths.length)
104
+ parts.push(`paths: ${d.paths.join(' ')}`);
105
+ if (d.summary)
106
+ parts.push(d.summary);
107
+ if (d.detail)
108
+ parts.push(d.detail);
109
+ return parts.join('\n');
110
+ }
111
+ /** Convenience: distill then serialise. */
112
+ export function distillAndSerialise(raw) {
113
+ return serialiseDistilled(distillTrajectoryContent(raw));
114
+ }
115
+ /**
116
+ * Compression ratio: raw bytes / distilled bytes. >1 means distilled is
117
+ * smaller. Used by the benchmark harness.
118
+ */
119
+ export function compressionRatio(raw) {
120
+ const distilled = distillAndSerialise(raw);
121
+ if (distilled.length === 0)
122
+ return 1;
123
+ return raw.length / distilled.length;
124
+ }
125
+ //# sourceMappingURL=structured-distill.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"structured-distill.js","sourceRoot":"","sources":["../../../src/memory/structured-distill.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAUH,MAAM,WAAW,GAAG,GAAG,CAAC;AACxB,MAAM,UAAU,GAAG,IAAI,CAAC;AAExB,gFAAgF;AAChF,0DAA0D;AAC1D,MAAM,YAAY,GAAG;IACnB,UAAU,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ;IACjE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,UAAU,EAAE,UAAU;IAC7D,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ;IACpD,UAAU,EAAE,SAAS,EAAE,SAAS;IAChC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,UAAU;IACnC,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,YAAY;IACrD,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW;IAC5C,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM;IACjD,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,aAAa,EAAE,QAAQ;CACrD,CAAC;AAEF,4EAA4E;AAC5E,yEAAyE;AACzE,mBAAmB;AACnB,MAAM,UAAU,GAAG,+HAA+H,CAAC;AACnJ,MAAM,YAAY,GAAG,sBAAsB,CAAC;AAE5C,SAAS,aAAa,CAAC,IAAY;IACjC,MAAM,CAA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