lingshu-skill 5.60.0 → 5.62.0
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 +29 -0
- package/README.md +1 -1
- package/SKILL-lite.md +1 -1
- package/SKILL-tiny.md +1 -1
- package/SKILL.md +1 -1
- package/manifest.json +461 -0
- package/package.json +8 -2
- package/scripts/astrbot_plugin_lingshu/CHECKSUMS.json +10 -10
- package/scripts/astrbot_plugin_lingshu/engine/CHANGELOG.md +29 -0
- package/scripts/astrbot_plugin_lingshu/engine/README.md +1 -1
- package/scripts/astrbot_plugin_lingshu/engine/SKILL-lite.md +1 -1
- package/scripts/astrbot_plugin_lingshu/engine/SKILL-tiny.md +1 -1
- package/scripts/astrbot_plugin_lingshu/engine/SKILL.md +1 -1
- package/scripts/astrbot_plugin_lingshu/engine/scripts/core.py +58 -39
- package/scripts/astrbot_plugin_lingshu/engine/scripts/growth.py +3 -4
- package/scripts/astrbot_plugin_lingshu/engine/scripts/make_dsh_tgz.py +20 -3
- package/scripts/astrbot_plugin_lingshu/engine/scripts/memory.py +11 -2
- package/scripts/astrbot_plugin_lingshu/engine/scripts/panel_build.py +13 -0
- package/scripts/core.py +58 -39
- package/scripts/growth.py +3 -4
- package/scripts/make_dsh_tgz.py +20 -3
- package/scripts/make_manifest.py +15 -10
- package/scripts/make_plugin_zip.py +7 -3
- package/scripts/memory.py +11 -2
- package/scripts/panel_build.py +13 -0
- package/scripts/_ci_env_probe.py +0 -81
- package/scripts/_panel_smoke_v299.py +0 -27
- package/scripts/_scratch/_tmp_backup_race.py +0 -70
- package/scripts/_scratch/_tmp_cleanup_move.py +0 -34
- package/scripts/_scratch/_tmp_count_kinds.py +0 -25
- package/scripts/_scratch/_tmp_diag_paths.py +0 -48
- package/scripts/_scratch/_tmp_facts.py +0 -63
- package/scripts/_scratch/_tmp_find_copies.py +0 -31
- package/scripts/_scratch/_tmp_find_pin.py +0 -29
- package/scripts/_scratch/_tmp_fix_pin.py +0 -36
- package/scripts/_scratch/_tmp_fold_fixture.py +0 -55
- package/scripts/_scratch/_tmp_fold_test.mjs +0 -81
- package/scripts/_scratch/_tmp_inject_secs.py +0 -30
- package/scripts/_scratch/_tmp_kb_balance.py +0 -159
- package/scripts/_scratch/_tmp_lines.py +0 -15
- package/scripts/_scratch/_tmp_market_probe.py +0 -13
- package/scripts/_scratch/_tmp_move_partial.py +0 -16
- package/scripts/_scratch/_tmp_patch_b3.py +0 -41
- package/scripts/_scratch/_tmp_patch_b5.py +0 -62
- package/scripts/_scratch/_tmp_patch_crash_excl.py +0 -24
- package/scripts/_scratch/_tmp_patch_handoff.py +0 -21
- package/scripts/_scratch/_tmp_patch_ps1.py +0 -25
- package/scripts/_scratch/_tmp_patch_stat.py +0 -27
- package/scripts/_scratch/_tmp_patch_todo.py +0 -25
- package/scripts/_scratch/_tmp_patch_todo2.py +0 -64
- package/scripts/_scratch/_tmp_probe_session.py +0 -51
- package/scripts/_scratch/_tmp_style_probe.py +0 -40
- package/scripts/_scratch/_tmp_write_note.py +0 -139
- package/scripts/_scratch/_/346/235/245/346/272/220/350/256/260/345/275/225.txt +0 -1
- package/scripts/_scratch/asar_compaction/dsh-compaction-basic__lib__index.js +0 -1044
- package/scripts/_scratch/asar_compaction/dsh-compaction-tool-result-pruner__lib__index.js +0 -194
- package/scripts/_scratch/asar_compaction/dsh-compaction__lib__index.js +0 -175
- package/scripts/_scratch/asar_compaction/dsh-compaction__lib__types__tool-pairing.js +0 -97
- package/scripts/_scratch/asar_compaction/dsh__node_modules__@deepseek-ai__dsh-compaction-image-offload__lib__types__image-offload.js +0 -47
- package/scripts/_scratch/asar_compaction/dsh__node_modules__@deepseek-ai__dsh-compaction-image-offload__lib__types__index.js +0 -40
- package/scripts/_scratch/asar_compaction/dsh__node_modules__@deepseek-ai__dsh-compaction-image-offload__lib__types__project-message.js +0 -37
- package/scripts/_scratch/asar_compaction/dsh__node_modules__@deepseek-ai__dsh-compaction__lib__types__brand.js +0 -9
- package/scripts/_scratch/asar_compaction/dsh__node_modules__@deepseek-ai__dsh-compaction__lib__types__checkpoint.js +0 -36
- package/scripts/_scratch/asar_compaction/dsh__node_modules__@deepseek-ai__dsh-compaction__lib__types__types.js +0 -10
- package/scripts/_scratch/commit_msg_occ.txt +0 -16
- package/scripts/_scratch/commit_msg_struct.txt +0 -16
- package/scripts/_scratch/v5.34_changelog.txt +0 -36
- package/scripts/_smoke_v299.py +0 -31
- package/scripts/_sync_trae_cn.py +0 -102
- package/scripts/_tmp_add_s10.py +0 -54
- package/scripts/_tmp_add_s11.py +0 -61
- package/scripts/_tmp_add_s12.py +0 -66
- package/scripts/_tmp_add_s13.py +0 -69
- package/scripts/_tmp_add_s14.py +0 -80
- package/scripts/_tmp_add_s9.py +0 -68
- package/scripts/_tmp_cache_load.py +0 -82
- package/scripts/_tmp_clean_market.py +0 -40
- package/scripts/_tmp_clean_pruned.py +0 -81
- package/scripts/_tmp_cleanup_docs.py +0 -39
- package/scripts/_tmp_cmp_ranker.py +0 -17
- package/scripts/_tmp_dolater_note.py +0 -35
- package/scripts/_tmp_dust_why.py +0 -27
- package/scripts/_tmp_explicit_import.py +0 -40
- package/scripts/_tmp_extract_compaction.py +0 -35
- package/scripts/_tmp_extract_compaction2.py +0 -63
- package/scripts/_tmp_extract_compaction3.py +0 -51
- package/scripts/_tmp_extract_compaction4.py +0 -54
- package/scripts/_tmp_finalize_s14.py +0 -39
- package/scripts/_tmp_find_compaction.py +0 -43
- package/scripts/_tmp_fix_b4.py +0 -22
- package/scripts/_tmp_fix_cli76.py +0 -26
- package/scripts/_tmp_fix_docs.py +0 -38
- package/scripts/_tmp_fix_docs_b.py +0 -46
- package/scripts/_tmp_fix_docs_b2.py +0 -22
- package/scripts/_tmp_fix_i3.py +0 -23
- package/scripts/_tmp_fix_s10.py +0 -83
- package/scripts/_tmp_fix_s11.py +0 -14
- package/scripts/_tmp_fix_s9_status.py +0 -19
- package/scripts/_tmp_fix_shadow_sim.py +0 -37
- package/scripts/_tmp_fix_traits_value.py +0 -41
- package/scripts/_tmp_import_idem.py +0 -106
- package/scripts/_tmp_log_ack.py +0 -45
- package/scripts/_tmp_mark_batch.py +0 -28
- package/scripts/_tmp_mark_batch2.py +0 -32
- package/scripts/_tmp_mark_dolater.py +0 -26
- package/scripts/_tmp_mark_dolater2.py +0 -31
- package/scripts/_tmp_move_self.py +0 -16
- package/scripts/_tmp_occ_cli.py +0 -22
- package/scripts/_tmp_occ_link.py +0 -108
- package/scripts/_tmp_optimize_recall.py +0 -54
- package/scripts/_tmp_panel_audit.py +0 -26
- package/scripts/_tmp_patch_batch3.py +0 -65
- package/scripts/_tmp_patch_rrf.py +0 -46
- package/scripts/_tmp_patch_s2s3.py +0 -80
- package/scripts/_tmp_patch_s4.py +0 -39
- package/scripts/_tmp_patch_s7.py +0 -43
- package/scripts/_tmp_patch_s8.py +0 -91
- package/scripts/_tmp_patch_skill.py +0 -17
- package/scripts/_tmp_release_guard.py +0 -57
- package/scripts/_tmp_rerank_breaker.py +0 -62
- package/scripts/_tmp_s16.py +0 -41
- package/scripts/_tmp_scan_asar.py +0 -41
- package/scripts/_tmp_scan_asar2.py +0 -37
- package/scripts/_tmp_speed_survey.py +0 -49
- package/scripts/_tmp_struct_docs.py +0 -49
- package/scripts/_tmp_sum_fallback.py +0 -42
- package/scripts/_tmp_sweep.py +0 -81
- package/scripts/_tmp_sync_check.py +0 -69
- package/scripts/_tmp_sync_tail.py +0 -39
- package/scripts/_tmp_todo_clean.py +0 -67
- package/scripts/_tmp_verify_copy.py +0 -17
- package/scripts/_tmp_wire_extras.py +0 -93
- package/scripts/_tmp_wire_hsum.py +0 -34
- package/scripts/_tmp_wire_occ_b5.py +0 -40
- package/scripts/_tmp_wire_ranker.py +0 -13
- package/scripts/_tmp_wire_shadow_timeline.py +0 -45
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_ci_env_probe.py +0 -81
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_panel_smoke_v299.py +0 -27
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_smoke_v299.py +0 -31
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_sync_trae_cn.py +0 -102
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_add_s10.py +0 -54
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_add_s11.py +0 -61
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_add_s12.py +0 -66
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_add_s13.py +0 -69
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_add_s14.py +0 -80
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_add_s9.py +0 -68
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_cache_load.py +0 -82
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_clean_market.py +0 -40
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_clean_pruned.py +0 -81
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_cleanup_docs.py +0 -39
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_cmp_ranker.py +0 -17
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_dolater_note.py +0 -35
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_dust_why.py +0 -27
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_explicit_import.py +0 -40
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_extract_compaction.py +0 -35
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_extract_compaction2.py +0 -63
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_extract_compaction3.py +0 -51
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_extract_compaction4.py +0 -54
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_finalize_s14.py +0 -39
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_find_compaction.py +0 -43
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_fix_b4.py +0 -22
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_fix_cli76.py +0 -26
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_fix_docs.py +0 -38
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_fix_docs_b.py +0 -46
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_fix_docs_b2.py +0 -22
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_fix_i3.py +0 -23
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_fix_s10.py +0 -83
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_fix_s11.py +0 -14
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_fix_s9_status.py +0 -19
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_fix_shadow_sim.py +0 -37
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_fix_traits_value.py +0 -41
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_import_idem.py +0 -106
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_log_ack.py +0 -45
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_mark_batch.py +0 -28
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_mark_batch2.py +0 -32
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_mark_dolater.py +0 -26
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_mark_dolater2.py +0 -31
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_move_self.py +0 -16
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_occ_cli.py +0 -22
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_occ_link.py +0 -108
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_optimize_recall.py +0 -54
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_panel_audit.py +0 -26
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_patch_batch3.py +0 -65
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_patch_rrf.py +0 -46
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_patch_s2s3.py +0 -80
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_patch_s4.py +0 -39
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_patch_s7.py +0 -43
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_patch_s8.py +0 -91
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_patch_skill.py +0 -17
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_release_guard.py +0 -57
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_rerank_breaker.py +0 -62
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_s16.py +0 -41
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_scan_asar.py +0 -41
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_scan_asar2.py +0 -37
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_speed_survey.py +0 -49
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_struct_docs.py +0 -49
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_sum_fallback.py +0 -42
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_sweep.py +0 -81
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_sync_check.py +0 -69
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_sync_tail.py +0 -39
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_todo_clean.py +0 -67
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_verify_copy.py +0 -17
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_wire_extras.py +0 -93
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_wire_hsum.py +0 -34
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_wire_occ_b5.py +0 -40
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_wire_ranker.py +0 -13
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_wire_shadow_timeline.py +0 -45
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
import { Service } from "@deepseek-ai/cordis";
|
|
2
|
-
import z from "@deepseek-ai/schemastery";
|
|
3
|
-
import { freezeMessage } from "@deepseek-ai/dsh-llm";
|
|
4
|
-
import { deepFreeze } from "@deepseek-ai/dsh-util-values";
|
|
5
|
-
//#region lib/types/config.js
|
|
6
|
-
/** Configuration resolution for deterministic tool-result pruning. */
|
|
7
|
-
/** Fixed marker substituted for every removed middle span. */
|
|
8
|
-
const PRUNE_MARKER = "\n\n[... tool result middle pruned ...]\n\n";
|
|
9
|
-
/** Low-friction defaults for coding-agent tool output. */
|
|
10
|
-
const DEFAULTS = deepFreeze({
|
|
11
|
-
thresholdChars: 8192,
|
|
12
|
-
headChars: 4096,
|
|
13
|
-
tailChars: 1024
|
|
14
|
-
});
|
|
15
|
-
const CONFIG_KEYS = new Set([
|
|
16
|
-
"thresholdChars",
|
|
17
|
-
"headChars",
|
|
18
|
-
"tailChars"
|
|
19
|
-
]);
|
|
20
|
-
/**
|
|
21
|
-
* Count Unicode code points without splitting surrogate pairs.
|
|
22
|
-
* @param text - text to measure.
|
|
23
|
-
* @returns the Unicode code-point count.
|
|
24
|
-
*/
|
|
25
|
-
function codePointLength(text) {
|
|
26
|
-
return Array.from(text).length;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Resolve and validate pruning budgets.
|
|
30
|
-
* @param config - raw plugin configuration.
|
|
31
|
-
* @returns a detached deeply immutable configuration.
|
|
32
|
-
*/
|
|
33
|
-
function resolveConfig(config = {}) {
|
|
34
|
-
for (const key of Object.keys(config)) if (!CONFIG_KEYS.has(key)) throw new Error(`ToolResultPruneConfig: unknown key "${key}" (allowed: thresholdChars, headChars, tailChars)`);
|
|
35
|
-
const resolved = {
|
|
36
|
-
thresholdChars: config.thresholdChars ?? DEFAULTS.thresholdChars,
|
|
37
|
-
headChars: config.headChars ?? DEFAULTS.headChars,
|
|
38
|
-
tailChars: config.tailChars ?? DEFAULTS.tailChars
|
|
39
|
-
};
|
|
40
|
-
assertPositiveInteger("thresholdChars", resolved.thresholdChars);
|
|
41
|
-
assertNonNegativeInteger("headChars", resolved.headChars);
|
|
42
|
-
assertNonNegativeInteger("tailChars", resolved.tailChars);
|
|
43
|
-
const emittedChars = resolved.headChars + codePointLength(PRUNE_MARKER) + resolved.tailChars;
|
|
44
|
-
if (emittedChars > resolved.thresholdChars) throw new Error(`ToolResultPruneConfig: headChars + marker + tailChars (${emittedChars}) must be at most thresholdChars (${resolved.thresholdChars})`);
|
|
45
|
-
return deepFreeze(structuredClone(resolved));
|
|
46
|
-
}
|
|
47
|
-
function assertPositiveInteger(name, value) {
|
|
48
|
-
if (!Number.isInteger(value) || value <= 0) throw new Error(`ToolResultPruneConfig: ${name} (${value}) must be a positive integer`);
|
|
49
|
-
}
|
|
50
|
-
function assertNonNegativeInteger(name, value) {
|
|
51
|
-
if (!Number.isInteger(value) || value < 0) throw new Error(`ToolResultPruneConfig: ${name} (${value}) must be a non-negative integer`);
|
|
52
|
-
}
|
|
53
|
-
//#endregion
|
|
54
|
-
//#region lib/types/index.js
|
|
55
|
-
/**
|
|
56
|
-
* Replay-safe, model-free tool-result pruning service.
|
|
57
|
-
*
|
|
58
|
-
* @module @deepseek-ai/dsh-compaction-tool-result-pruner
|
|
59
|
-
*/
|
|
60
|
-
/** Deterministic head/middle/tail pruning for current tool-result surface nodes. */
|
|
61
|
-
var ToolResultPruner = class extends Service {
|
|
62
|
-
static inject = ["tokenMeter"];
|
|
63
|
-
static Config = z.object({
|
|
64
|
-
thresholdChars: z.number().step(1).min(1).default(DEFAULTS.thresholdChars),
|
|
65
|
-
headChars: z.number().step(1).min(0).default(DEFAULTS.headChars),
|
|
66
|
-
tailChars: z.number().step(1).min(0).default(DEFAULTS.tailChars)
|
|
67
|
-
});
|
|
68
|
-
/** Resolved and immutable character budgets. */
|
|
69
|
-
config;
|
|
70
|
-
constructor(ctx, config = {}) {
|
|
71
|
-
super(ctx, "toolResultPruner");
|
|
72
|
-
this.config = resolveConfig(config);
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Measure text content in Unicode code points; non-text blocks cost zero.
|
|
76
|
-
* @param blocks - tool-result content to measure.
|
|
77
|
-
* @returns total Unicode code points across text blocks.
|
|
78
|
-
*/
|
|
79
|
-
measureContent(blocks) {
|
|
80
|
-
let chars = 0;
|
|
81
|
-
for (const block of blocks) if (block.type === "text") chars += codePointLength(block.text);
|
|
82
|
-
return chars;
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Replace an over-budget text middle while retaining rich-block order.
|
|
86
|
-
* Text slicing is by Unicode code point, not UTF-16 code unit, so a retained
|
|
87
|
-
* boundary cannot split a surrogate pair. Grapheme clusters may still split.
|
|
88
|
-
* @param blocks - original tool-result content.
|
|
89
|
-
* @returns pruned content, or `null` when the text is within budget.
|
|
90
|
-
*/
|
|
91
|
-
pruneContent(blocks) {
|
|
92
|
-
const totalChars = this.measureContent(blocks);
|
|
93
|
-
if (totalChars <= this.config.thresholdChars) return null;
|
|
94
|
-
const removedStart = this.config.headChars;
|
|
95
|
-
const removedEnd = totalChars - this.config.tailChars;
|
|
96
|
-
const pruned = [];
|
|
97
|
-
let consumed = 0;
|
|
98
|
-
let markerInserted = false;
|
|
99
|
-
for (const block of blocks) {
|
|
100
|
-
if (block.type !== "text") {
|
|
101
|
-
pruned.push(block);
|
|
102
|
-
continue;
|
|
103
|
-
}
|
|
104
|
-
const points = Array.from(block.text);
|
|
105
|
-
const blockStart = consumed;
|
|
106
|
-
const blockEnd = blockStart + points.length;
|
|
107
|
-
const headEnd = Math.min(points.length, Math.max(0, removedStart - blockStart));
|
|
108
|
-
const tailStart = Math.min(points.length, Math.max(0, removedEnd - blockStart));
|
|
109
|
-
const marker = blockStart < removedEnd && blockEnd > removedStart && !markerInserted ? PRUNE_MARKER : "";
|
|
110
|
-
if (marker.length > 0) markerInserted = true;
|
|
111
|
-
const text = points.slice(0, headEnd).join("") + marker + points.slice(tailStart).join("");
|
|
112
|
-
if (text.length > 0) pruned.push({
|
|
113
|
-
...block,
|
|
114
|
-
text
|
|
115
|
-
});
|
|
116
|
-
consumed = blockEnd;
|
|
117
|
-
}
|
|
118
|
-
/* v8 ignore next -- totalChars > threshold and valid budgets guarantee a removed text span. */
|
|
119
|
-
if (!markerInserted) throw new Error("tool-result prune: failed to locate the removed text span");
|
|
120
|
-
const charsAfter = this.measureContent(pruned);
|
|
121
|
-
/* v8 ignore next -- config validation fixes the emitted head + marker + tail budget. */
|
|
122
|
-
if (charsAfter > this.config.thresholdChars || charsAfter >= totalChars) throw new Error("tool-result prune: replacement must be smaller and within threshold");
|
|
123
|
-
return pruned;
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* Prune every over-budget tool result from one stable current-surface snapshot.
|
|
127
|
-
* Each replacement preserves the complete event data except for `content`,
|
|
128
|
-
* cites the shadowed node so replay can recover the replacement input, and is
|
|
129
|
-
* immediately preceded by a `compaction/prune` shadow-price event pricing the
|
|
130
|
-
* shadowed node through the injected token meter, so pure consumers can
|
|
131
|
-
* subtract it without per-node state.
|
|
132
|
-
* @param session - session whose current surface is rewritten.
|
|
133
|
-
* @returns landed replacements and aggregate Unicode-code-point savings.
|
|
134
|
-
* @throws when the session rejects a replacement; replacements committed
|
|
135
|
-
* earlier in the pass remain durable.
|
|
136
|
-
*/
|
|
137
|
-
pruneSession(session) {
|
|
138
|
-
const candidates = [];
|
|
139
|
-
for (const seq of [...session.surface.nodes]) {
|
|
140
|
-
const event = session.eventAt(seq);
|
|
141
|
-
/* v8 ignore next -- surface seqs are validated contiguous log references. */
|
|
142
|
-
if (event?.type === "tool/result") candidates.push({
|
|
143
|
-
seq,
|
|
144
|
-
event
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
const pruned = [];
|
|
148
|
-
let charsRemoved = 0;
|
|
149
|
-
for (const { seq, event } of candidates) {
|
|
150
|
-
const original = session.deriveEventMessage(event);
|
|
151
|
-
const content = this.pruneContent(original.content);
|
|
152
|
-
if (content === null) continue;
|
|
153
|
-
const charsBefore = this.measureContent(original.content);
|
|
154
|
-
const charsAfter = this.measureContent(content);
|
|
155
|
-
const message = freezeMessage({
|
|
156
|
-
...original,
|
|
157
|
-
content
|
|
158
|
-
});
|
|
159
|
-
session.append("compaction/prune", {
|
|
160
|
-
shadowedRange: {
|
|
161
|
-
start: seq,
|
|
162
|
-
end: seq
|
|
163
|
-
},
|
|
164
|
-
shadowedSeqs: [seq],
|
|
165
|
-
shadowedTokenCount: this.ctx.tokenMeter.estimateMessage(original)
|
|
166
|
-
});
|
|
167
|
-
const replacement = session.append("tool/result", {
|
|
168
|
-
...event.data,
|
|
169
|
-
message
|
|
170
|
-
}, {
|
|
171
|
-
surfaceOp: {
|
|
172
|
-
op: "replace",
|
|
173
|
-
startSeq: seq,
|
|
174
|
-
endSeq: seq
|
|
175
|
-
},
|
|
176
|
-
sourceEventSeqs: [seq]
|
|
177
|
-
});
|
|
178
|
-
pruned.push({
|
|
179
|
-
originalSeq: seq,
|
|
180
|
-
replacementSeq: replacement.seq,
|
|
181
|
-
callId: event.data.message.source.callId,
|
|
182
|
-
charsBefore,
|
|
183
|
-
charsAfter
|
|
184
|
-
});
|
|
185
|
-
charsRemoved += charsBefore - charsAfter;
|
|
186
|
-
}
|
|
187
|
-
return {
|
|
188
|
-
pruned,
|
|
189
|
-
charsRemoved
|
|
190
|
-
};
|
|
191
|
-
}
|
|
192
|
-
};
|
|
193
|
-
//#endregion
|
|
194
|
-
export { DEFAULTS, PRUNE_MARKER, ToolResultPruner, ToolResultPruner as default, codePointLength, resolveConfig };
|
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
import { Service } from "@deepseek-ai/cordis";
|
|
2
|
-
//#region lib/types/brand.js
|
|
3
|
-
/**
|
|
4
|
-
* Brand an implementation-minted compaction identity.
|
|
5
|
-
* @param id - opaque transaction identity.
|
|
6
|
-
* @returns the same string, branded; no validation is performed.
|
|
7
|
-
*/
|
|
8
|
-
function CompactionId(id) {
|
|
9
|
-
return id;
|
|
10
|
-
}
|
|
11
|
-
//#endregion
|
|
12
|
-
//#region lib/types/tool-pairing.js
|
|
13
|
-
/**
|
|
14
|
-
* Tool-pairing balance over a session surface. Compaction changes surface
|
|
15
|
-
* positions, so safe cuts are derived from tool-call/result content in current
|
|
16
|
-
* surface order rather than step markers.
|
|
17
|
-
* @module @deepseek-ai/dsh-compaction/tool-pairing
|
|
18
|
-
*/
|
|
19
|
-
const balanceCacheBySession = /* @__PURE__ */ new WeakMap();
|
|
20
|
-
/** Return how one surface event changes the in-progress tool-call count. */
|
|
21
|
-
function eventDelta(event) {
|
|
22
|
-
switch (event.type) {
|
|
23
|
-
case "assistant/message": return event.data.message.content.filter((block) => block.type === "tool-call").length;
|
|
24
|
-
case "tool/result": return -1;
|
|
25
|
-
default: return 0;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
/** Fold surface sequences not yet in the cache into its balance state. */
|
|
29
|
-
function extendCache(session, cache, seqs) {
|
|
30
|
-
const processed = cache.cutBalanced.length - 1;
|
|
31
|
-
const tail = seqs.slice(processed);
|
|
32
|
-
const pendingCuts = [];
|
|
33
|
-
let inProgressToolCalls = cache.inProgressToolCalls;
|
|
34
|
-
for (const seq of tail) {
|
|
35
|
-
const event = session.eventAt(seq);
|
|
36
|
-
if (event === void 0 || event.seq !== seq) throw new Error(`tool-pairing balance: surface seq ${seq} has no matching session event (corrupt surface)`);
|
|
37
|
-
inProgressToolCalls += eventDelta(event);
|
|
38
|
-
if (inProgressToolCalls < 0) throw new Error(`tool-pairing balance: tool/result at surface seq ${seq} has no matching tool-call (corrupt surface)`);
|
|
39
|
-
pendingCuts.push(inProgressToolCalls === 0);
|
|
40
|
-
}
|
|
41
|
-
tail.forEach((seq, offset) => cache.indexBySeq.set(seq, processed + offset));
|
|
42
|
-
cache.cutBalanced = cache.cutBalanced.concat(pendingCuts);
|
|
43
|
-
cache.inProgressToolCalls = inProgressToolCalls;
|
|
44
|
-
return cache;
|
|
45
|
-
}
|
|
46
|
-
/** Return balance state synchronized with the current session surface. */
|
|
47
|
-
function balanceCache(session) {
|
|
48
|
-
const surface = session.surface;
|
|
49
|
-
const seqs = surface.nodes;
|
|
50
|
-
const generation = surface.replaceGeneration;
|
|
51
|
-
const cached = balanceCacheBySession.get(session);
|
|
52
|
-
if (cached === void 0 || cached.generation !== generation || cached.cutBalanced.length - 1 > seqs.length) {
|
|
53
|
-
const rebuilt = extendCache(session, {
|
|
54
|
-
generation,
|
|
55
|
-
cutBalanced: [true],
|
|
56
|
-
indexBySeq: /* @__PURE__ */ new Map(),
|
|
57
|
-
inProgressToolCalls: 0
|
|
58
|
-
}, seqs);
|
|
59
|
-
balanceCacheBySession.set(session, rebuilt);
|
|
60
|
-
return rebuilt;
|
|
61
|
-
}
|
|
62
|
-
if (cached.cutBalanced.length - 1 < seqs.length) return extendCache(session, cached, seqs);
|
|
63
|
-
return cached;
|
|
64
|
-
}
|
|
65
|
-
/** Balance of the cut at a sequence's position plus offset, rejecting seqs outside current membership. */
|
|
66
|
-
function cutBalance(cache, seq, offset) {
|
|
67
|
-
const index = cache.indexBySeq.get(seq);
|
|
68
|
-
const balanced = index === void 0 ? void 0 : cache.cutBalanced[index + offset];
|
|
69
|
-
if (balanced === void 0) throw new Error(`tool-pairing balance: surface seq ${seq} not found`);
|
|
70
|
-
return balanced;
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Whether the cut immediately before a current surface sequence is tool-pairing balanced.
|
|
74
|
-
* @param session - session whose surface is checked.
|
|
75
|
-
* @param seq - event sequence whose leading cut is checked.
|
|
76
|
-
* @returns true when no unanswered tool call crosses the cut.
|
|
77
|
-
* @throws when the seq is absent from the current surface, a surface sequence has no
|
|
78
|
-
* matching log event, or a tool result has no preceding open call.
|
|
79
|
-
*/
|
|
80
|
-
function toolPairingBalancedBefore(session, seq) {
|
|
81
|
-
return cutBalance(balanceCache(session), seq, 0);
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Whether the cut immediately after a current surface sequence is tool-pairing balanced.
|
|
85
|
-
* @param session - session whose surface is checked.
|
|
86
|
-
* @param seq - event sequence whose trailing cut is checked.
|
|
87
|
-
* @returns true when no unanswered tool call crosses the cut.
|
|
88
|
-
* @throws when the seq is absent from the current surface, a surface sequence has no
|
|
89
|
-
* matching log event, or a tool result has no preceding open call.
|
|
90
|
-
*/
|
|
91
|
-
function toolPairingBalancedAfter(session, seq) {
|
|
92
|
-
return cutBalance(balanceCache(session), seq, 1);
|
|
93
|
-
}
|
|
94
|
-
//#endregion
|
|
95
|
-
//#region lib/types/checkpoint.js
|
|
96
|
-
/**
|
|
97
|
-
* Compaction checkpoint source: the correlated constructor and type
|
|
98
|
-
* every backend uses for its replacement user message, plus the predicate that
|
|
99
|
-
* recognizes persisted checkpoints.
|
|
100
|
-
*
|
|
101
|
-
* The seam itself lives in `@deepseek-ai/dsh-compaction`, which re-exports these
|
|
102
|
-
* contracts; this module is a pure type/value/predicate outlet (no cordis
|
|
103
|
-
* imports, no module augmentation) so client and wire programs can name the
|
|
104
|
-
* checkpoint source without loading the host plugin's Context merges — the
|
|
105
|
-
* `dsh-commands/brand` shape.
|
|
106
|
-
*
|
|
107
|
-
* @module @deepseek-ai/dsh-compaction/checkpoint
|
|
108
|
-
*/
|
|
109
|
-
const COMPACT_CHECKPOINT_MARKER = Object.freeze({ kind: "compact-checkpoint" });
|
|
110
|
-
/**
|
|
111
|
-
* Create a checkpoint source correlated with one compaction transaction.
|
|
112
|
-
* @param compactionId - owning compaction identity.
|
|
113
|
-
* @param sourceCommandId - initiating manual command, when present.
|
|
114
|
-
* @returns immutable checkpoint source.
|
|
115
|
-
*/
|
|
116
|
-
function compactCheckpointSource(compactionId, sourceCommandId) {
|
|
117
|
-
return Object.freeze({
|
|
118
|
-
...COMPACT_CHECKPOINT_MARKER,
|
|
119
|
-
compactionId,
|
|
120
|
-
...sourceCommandId === void 0 ? {} : { sourceCommandId }
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
/**
|
|
124
|
-
* Test whether a persisted message source identifies a compaction checkpoint.
|
|
125
|
-
* @param source - source restored from a surface user message.
|
|
126
|
-
* @returns whether the source carries the backend-independent checkpoint marker.
|
|
127
|
-
*/
|
|
128
|
-
function isCompactCheckpointSource(source) {
|
|
129
|
-
return source.kind === "compact-checkpoint";
|
|
130
|
-
}
|
|
131
|
-
//#endregion
|
|
132
|
-
//#region lib/types/index.js
|
|
133
|
-
/**
|
|
134
|
-
* Compaction Service Definition (`ctx.compaction`): providers decide when to
|
|
135
|
-
* compact and replace a history range with one summary node by subclassing
|
|
136
|
-
* {@link CompactionEngine}. This interface necessarily depends on session and LLM
|
|
137
|
-
* vocabulary; the dependency rule is documented in the
|
|
138
|
-
* [compaction reference](../README.md#understand-the-implementation).
|
|
139
|
-
* @module @deepseek-ai/dsh-compaction
|
|
140
|
-
*/
|
|
141
|
-
/**
|
|
142
|
-
* Expected manual-compaction failure suitable for a direct human-command result.
|
|
143
|
-
* Shared durable-lock entry assertions may also throw the `busy` subtype from
|
|
144
|
-
* automatic compaction paths.
|
|
145
|
-
*/
|
|
146
|
-
var ManualCompactionError = class extends Error {
|
|
147
|
-
code;
|
|
148
|
-
name = "ManualCompactionError";
|
|
149
|
-
/**
|
|
150
|
-
* Create one classified compaction failure.
|
|
151
|
-
* @param code - stable failure class; `busy` may originate from any compaction entry path.
|
|
152
|
-
* @param message - backend diagnostic retained as the Error message.
|
|
153
|
-
* @param options - optional original failure.
|
|
154
|
-
*/
|
|
155
|
-
constructor(code, message, options) {
|
|
156
|
-
super(message, options);
|
|
157
|
-
this.code = code;
|
|
158
|
-
}
|
|
159
|
-
};
|
|
160
|
-
/**
|
|
161
|
-
* Abstract compaction service. Implementations own trigger policy, retention,
|
|
162
|
-
* and summarization, and may consume a separate measurement service. A
|
|
163
|
-
* successful run replaces the selected surface span with one summary node and
|
|
164
|
-
* prevents concurrent compaction of the same session. The replacement user
|
|
165
|
-
* message uses {@link compactCheckpointSource} with the transaction identity
|
|
166
|
-
* so consumers recognize and correlate it independently of the backend. Load
|
|
167
|
-
* one implementation per context as `ctx.compaction`.
|
|
168
|
-
*/
|
|
169
|
-
var CompactionEngine = class extends Service {
|
|
170
|
-
constructor(ctx) {
|
|
171
|
-
super(ctx, "compaction");
|
|
172
|
-
}
|
|
173
|
-
};
|
|
174
|
-
//#endregion
|
|
175
|
-
export { CompactionEngine, CompactionEngine as default, CompactionId, ManualCompactionError, compactCheckpointSource, isCompactCheckpointSource, toolPairingBalancedAfter, toolPairingBalancedBefore };
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tool-pairing balance over a session surface. Compaction changes surface
|
|
3
|
-
* positions, so safe cuts are derived from tool-call/result content in current
|
|
4
|
-
* surface order rather than step markers.
|
|
5
|
-
* @module @deepseek-ai/dsh-compaction/tool-pairing
|
|
6
|
-
*/
|
|
7
|
-
const balanceCacheBySession = new WeakMap();
|
|
8
|
-
/** Return how one surface event changes the in-progress tool-call count. */
|
|
9
|
-
function eventDelta(event) {
|
|
10
|
-
switch (event.type) {
|
|
11
|
-
case 'assistant/message':
|
|
12
|
-
return event.data.message.content.filter(block => block.type === 'tool-call').length;
|
|
13
|
-
case 'tool/result':
|
|
14
|
-
return -1;
|
|
15
|
-
default:
|
|
16
|
-
return 0;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
/** Fold surface sequences not yet in the cache into its balance state. */
|
|
20
|
-
function extendCache(session, cache, seqs) {
|
|
21
|
-
const processed = cache.cutBalanced.length - 1;
|
|
22
|
-
const tail = seqs.slice(processed);
|
|
23
|
-
// Validate the unseen tail before mutating the live cache, so a corrupt
|
|
24
|
-
// append cannot leave a partially advanced state behind.
|
|
25
|
-
const pendingCuts = [];
|
|
26
|
-
let inProgressToolCalls = cache.inProgressToolCalls;
|
|
27
|
-
for (const seq of tail) {
|
|
28
|
-
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
|
|
29
|
-
const event = session.eventAt(seq);
|
|
30
|
-
if (event === undefined || event.seq !== seq) {
|
|
31
|
-
throw new Error(`tool-pairing balance: surface seq ${seq} has no matching session event (corrupt surface)`);
|
|
32
|
-
}
|
|
33
|
-
inProgressToolCalls += eventDelta(event);
|
|
34
|
-
if (inProgressToolCalls < 0) {
|
|
35
|
-
throw new Error(`tool-pairing balance: tool/result at surface seq ${seq} has no matching tool-call (corrupt surface)`);
|
|
36
|
-
}
|
|
37
|
-
pendingCuts.push(inProgressToolCalls === 0);
|
|
38
|
-
}
|
|
39
|
-
tail.forEach((seq, offset) => cache.indexBySeq.set(seq, processed + offset));
|
|
40
|
-
cache.cutBalanced = cache.cutBalanced.concat(pendingCuts);
|
|
41
|
-
cache.inProgressToolCalls = inProgressToolCalls;
|
|
42
|
-
return cache;
|
|
43
|
-
}
|
|
44
|
-
/** Return balance state synchronized with the current session surface. */
|
|
45
|
-
function balanceCache(session) {
|
|
46
|
-
const surface = session.surface;
|
|
47
|
-
const seqs = surface.nodes;
|
|
48
|
-
const generation = surface.replaceGeneration;
|
|
49
|
-
const cached = balanceCacheBySession.get(session);
|
|
50
|
-
if (cached === undefined || cached.generation !== generation || cached.cutBalanced.length - 1 > seqs.length) {
|
|
51
|
-
// A rebuild is the same fold started from the empty-surface state, whose
|
|
52
|
-
// single leading cut is trivially balanced.
|
|
53
|
-
const rebuilt = extendCache(session, {
|
|
54
|
-
generation,
|
|
55
|
-
cutBalanced: [true],
|
|
56
|
-
indexBySeq: new Map(),
|
|
57
|
-
inProgressToolCalls: 0,
|
|
58
|
-
}, seqs);
|
|
59
|
-
balanceCacheBySession.set(session, rebuilt);
|
|
60
|
-
return rebuilt;
|
|
61
|
-
}
|
|
62
|
-
if (cached.cutBalanced.length - 1 < seqs.length)
|
|
63
|
-
return extendCache(session, cached, seqs);
|
|
64
|
-
return cached;
|
|
65
|
-
}
|
|
66
|
-
/** Balance of the cut at a sequence's position plus offset, rejecting seqs outside current membership. */
|
|
67
|
-
function cutBalance(cache, seq, offset) {
|
|
68
|
-
const index = cache.indexBySeq.get(seq);
|
|
69
|
-
const balanced = index === undefined ? undefined : cache.cutBalanced[index + offset];
|
|
70
|
-
if (balanced === undefined) {
|
|
71
|
-
throw new Error(`tool-pairing balance: surface seq ${seq} not found`);
|
|
72
|
-
}
|
|
73
|
-
return balanced;
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Whether the cut immediately before a current surface sequence is tool-pairing balanced.
|
|
77
|
-
* @param session - session whose surface is checked.
|
|
78
|
-
* @param seq - event sequence whose leading cut is checked.
|
|
79
|
-
* @returns true when no unanswered tool call crosses the cut.
|
|
80
|
-
* @throws when the seq is absent from the current surface, a surface sequence has no
|
|
81
|
-
* matching log event, or a tool result has no preceding open call.
|
|
82
|
-
*/
|
|
83
|
-
export function toolPairingBalancedBefore(session, seq) {
|
|
84
|
-
return cutBalance(balanceCache(session), seq, 0);
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Whether the cut immediately after a current surface sequence is tool-pairing balanced.
|
|
88
|
-
* @param session - session whose surface is checked.
|
|
89
|
-
* @param seq - event sequence whose trailing cut is checked.
|
|
90
|
-
* @returns true when no unanswered tool call crosses the cut.
|
|
91
|
-
* @throws when the seq is absent from the current surface, a surface sequence has no
|
|
92
|
-
* matching log event, or a tool result has no preceding open call.
|
|
93
|
-
*/
|
|
94
|
-
export function toolPairingBalancedAfter(session, seq) {
|
|
95
|
-
return cutBalance(balanceCache(session), seq, 1);
|
|
96
|
-
}
|
|
97
|
-
//# sourceMappingURL=tool-pairing.js.map
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
/** Select and log permanent image omissions in current model-request order. */
|
|
2
|
-
/**
|
|
3
|
-
* Record one decision omitting the oldest retained input-image occurrences.
|
|
4
|
-
* Assistant nodes carry model output and are excluded. Image indexes count
|
|
5
|
-
* every occurrence, including previously offloaded ones, within each message.
|
|
6
|
-
* @param session - session whose next request applies the decision.
|
|
7
|
-
* @param sourceEventSeqs - input message events in the failed request's order.
|
|
8
|
-
* @param count - additional retained occurrences the adapter needs omitted.
|
|
9
|
-
* @returns whether any occurrence remained to offload.
|
|
10
|
-
*/
|
|
11
|
-
export function offloadOldestImages(session, sourceEventSeqs, count) {
|
|
12
|
-
const targets = [];
|
|
13
|
-
for (const seq of sourceEventSeqs) {
|
|
14
|
-
if (count === 0)
|
|
15
|
-
break;
|
|
16
|
-
// Existing Session history read; migration deferred. Current surface nodes index the durable log.
|
|
17
|
-
// oxlint-disable-next-line typescript/no-non-null-assertion, typescript/no-deprecated
|
|
18
|
-
const event = session.eventAt(seq);
|
|
19
|
-
if (event.type !== 'user/message' && event.type !== 'tool/result')
|
|
20
|
-
continue;
|
|
21
|
-
// oxlint-disable-next-line typescript/no-non-null-assertion -- both input node types produce a message
|
|
22
|
-
const message = session.deriveEventMessage(event);
|
|
23
|
-
const imageIndexes = [];
|
|
24
|
-
let imageIndex = 0;
|
|
25
|
-
const visit = (blocks) => {
|
|
26
|
-
for (const block of blocks) {
|
|
27
|
-
if (count === 0)
|
|
28
|
-
break;
|
|
29
|
-
if (block.type === 'image') {
|
|
30
|
-
if (block.offloaded !== true) {
|
|
31
|
-
imageIndexes.push(imageIndex);
|
|
32
|
-
count -= 1;
|
|
33
|
-
}
|
|
34
|
-
imageIndex += 1;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
visit(message.content);
|
|
39
|
-
if (imageIndexes.length > 0)
|
|
40
|
-
targets.push({ seq, imageIndexes });
|
|
41
|
-
}
|
|
42
|
-
if (targets.length === 0)
|
|
43
|
-
return false;
|
|
44
|
-
session.append('image/offload', { targets });
|
|
45
|
-
return true;
|
|
46
|
-
}
|
|
47
|
-
//# sourceMappingURL=image-offload.js.map
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Image offload executor for the compaction seam. When an image-capable route
|
|
3
|
-
* fails a request with `IMAGE_OFFLOAD_REQUIRED`, the plugin records one
|
|
4
|
-
* `image/offload` decision selecting the oldest retained input occurrences
|
|
5
|
-
* and retries through the agent or compaction summary error waterfall. Every route
|
|
6
|
-
* sends placeholder text for those occurrences in subsequent requests.
|
|
7
|
-
*
|
|
8
|
-
* @module @deepseek-ai/dsh-compaction-image-offload
|
|
9
|
-
*/
|
|
10
|
-
import { IMAGE_OFFLOAD_REQUIRED_CODE, LlmError } from '@deepseek-ai/dsh-llm';
|
|
11
|
-
import { offloadOldestImages } from "./image-offload.js";
|
|
12
|
-
import { imageOffloadProjection } from "./projection.js";
|
|
13
|
-
export const name = 'compaction-image-offload';
|
|
14
|
-
export const inject = ['agents', 'sessions'];
|
|
15
|
-
/**
|
|
16
|
-
* Mount agent and summary recovery listeners without configuration.
|
|
17
|
-
* @param ctx - the plugin context.
|
|
18
|
-
*/
|
|
19
|
-
export function apply(ctx) {
|
|
20
|
-
ctx.sessions.registerMessageProjection(imageOffloadProjection);
|
|
21
|
-
ctx.on('agent/request-error', ({ agent, failure, signal }, next) => {
|
|
22
|
-
if (failure.code !== IMAGE_OFFLOAD_REQUIRED_CODE || failure.offloadImages === undefined || signal.aborted)
|
|
23
|
-
return next();
|
|
24
|
-
// A durable surface repair, not a provider retry: it spends no retry budget and logs no retry event.
|
|
25
|
-
if (!offloadOldestImages(agent.session, agent.session.surface.nodes, failure.offloadImages))
|
|
26
|
-
return next();
|
|
27
|
-
return Promise.resolve({ kind: 'retry' });
|
|
28
|
-
});
|
|
29
|
-
ctx.on('compaction/summary-error', ({ session, sourceEventSeqs, error, signal }, next) => {
|
|
30
|
-
if (!(error instanceof LlmError)
|
|
31
|
-
|| error.code !== IMAGE_OFFLOAD_REQUIRED_CODE
|
|
32
|
-
|| error.failure.offloadImages === undefined)
|
|
33
|
-
return next();
|
|
34
|
-
signal?.throwIfAborted();
|
|
35
|
-
if (!offloadOldestImages(session, sourceEventSeqs, error.failure.offloadImages))
|
|
36
|
-
return next();
|
|
37
|
-
return true;
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
/** Immutable application of the image occurrences recorded by image/offload. */
|
|
2
|
-
import { deepFreeze } from '@deepseek-ai/dsh-util-values';
|
|
3
|
-
/**
|
|
4
|
-
* Project selected image occurrences to immutable offloaded blocks.
|
|
5
|
-
* @param message - message projected before this decision.
|
|
6
|
-
* @param indexes - nonempty, strictly increasing depth-first image indexes.
|
|
7
|
-
* @returns an immutable message with the same identity and selected images marked.
|
|
8
|
-
* @throws when a selected occurrence is missing or already offloaded.
|
|
9
|
-
*/
|
|
10
|
-
export function offloadMessageImages(message, indexes) {
|
|
11
|
-
let imageIndex = 0;
|
|
12
|
-
let selected = 0;
|
|
13
|
-
const visit = (blocks) => {
|
|
14
|
-
let next;
|
|
15
|
-
for (const [index, block] of blocks.entries()) {
|
|
16
|
-
let projected = block;
|
|
17
|
-
if (block.type === 'image') {
|
|
18
|
-
if (imageIndex === indexes[selected]) {
|
|
19
|
-
if (block.offloaded === true)
|
|
20
|
-
throw new Error(`image/offload: image index ${imageIndex} is already offloaded`);
|
|
21
|
-
projected = { ...block, offloaded: true };
|
|
22
|
-
selected += 1;
|
|
23
|
-
}
|
|
24
|
-
imageIndex += 1;
|
|
25
|
-
}
|
|
26
|
-
if (projected !== block)
|
|
27
|
-
next ??= blocks.slice(0, index);
|
|
28
|
-
next?.push(projected);
|
|
29
|
-
}
|
|
30
|
-
return next ?? blocks;
|
|
31
|
-
};
|
|
32
|
-
const content = visit(message.content);
|
|
33
|
-
if (selected !== indexes.length)
|
|
34
|
-
throw new Error(`image/offload: image index ${indexes[selected]} does not exist`);
|
|
35
|
-
return deepFreeze({ ...message, content });
|
|
36
|
-
}
|
|
37
|
-
//# sourceMappingURL=project-message.js.map
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Brand an implementation-minted compaction identity.
|
|
3
|
-
* @param id - opaque transaction identity.
|
|
4
|
-
* @returns the same string, branded; no validation is performed.
|
|
5
|
-
*/
|
|
6
|
-
export function CompactionId(id) {
|
|
7
|
-
return id;
|
|
8
|
-
}
|
|
9
|
-
//# sourceMappingURL=brand.js.map
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Compaction checkpoint source: the correlated constructor and type
|
|
3
|
-
* every backend uses for its replacement user message, plus the predicate that
|
|
4
|
-
* recognizes persisted checkpoints.
|
|
5
|
-
*
|
|
6
|
-
* The seam itself lives in `@deepseek-ai/dsh-compaction`, which re-exports these
|
|
7
|
-
* contracts; this module is a pure type/value/predicate outlet (no cordis
|
|
8
|
-
* imports, no module augmentation) so client and wire programs can name the
|
|
9
|
-
* checkpoint source without loading the host plugin's Context merges — the
|
|
10
|
-
* `dsh-commands/brand` shape.
|
|
11
|
-
*
|
|
12
|
-
* @module @deepseek-ai/dsh-compaction/checkpoint
|
|
13
|
-
*/
|
|
14
|
-
const COMPACT_CHECKPOINT_MARKER = Object.freeze({ kind: 'compact-checkpoint' });
|
|
15
|
-
/**
|
|
16
|
-
* Create a checkpoint source correlated with one compaction transaction.
|
|
17
|
-
* @param compactionId - owning compaction identity.
|
|
18
|
-
* @param sourceCommandId - initiating manual command, when present.
|
|
19
|
-
* @returns immutable checkpoint source.
|
|
20
|
-
*/
|
|
21
|
-
export function compactCheckpointSource(compactionId, sourceCommandId) {
|
|
22
|
-
return Object.freeze({
|
|
23
|
-
...COMPACT_CHECKPOINT_MARKER,
|
|
24
|
-
compactionId,
|
|
25
|
-
...sourceCommandId === undefined ? {} : { sourceCommandId },
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Test whether a persisted message source identifies a compaction checkpoint.
|
|
30
|
-
* @param source - source restored from a surface user message.
|
|
31
|
-
* @returns whether the source carries the backend-independent checkpoint marker.
|
|
32
|
-
*/
|
|
33
|
-
export function isCompactCheckpointSource(source) {
|
|
34
|
-
return source.kind === 'compact-checkpoint';
|
|
35
|
-
}
|
|
36
|
-
//# sourceMappingURL=checkpoint.js.map
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Compaction vocabulary: the result type and the `compaction/*` session events.
|
|
3
|
-
* Those declaration-merged events record the lock and summary inputs without entering the surface, so they are not
|
|
4
|
-
* surface events; a separate replacement `user/message` carries the summary.
|
|
5
|
-
* Backend packages own configuration and retention policy; see the
|
|
6
|
-
* [compaction reference](../README.md#understand-the-implementation).
|
|
7
|
-
* @module @deepseek-ai/dsh-compaction/types
|
|
8
|
-
*/
|
|
9
|
-
export {};
|
|
10
|
-
//# sourceMappingURL=types.js.map
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
feat: OCC 联动七情六欲 + 离线摘要兜底补段(清理过期待办)
|
|
2
|
-
|
|
3
|
-
OCC 到七情六欲的联动:
|
|
4
|
-
- occ.apply_emotion():6 类映射到七情(组+具体情绪)与六欲增减,走既有
|
|
5
|
-
emotion_evaluate(polarity, why=OCC:...) + desire_nudge(...)
|
|
6
|
-
- brain.py occ apply 文本 [--dry-run];识别不出时不动任何状态
|
|
7
|
-
- 修映射:静组只有 平静/疲惫/无聊,没有安心,释然改为 静·平静
|
|
8
|
-
|
|
9
|
-
离线摘要兜底(残余风险):
|
|
10
|
-
- 未决空 -> 用最后一条用户消息(待确认:...);原话空 -> 最近一句原话;
|
|
11
|
-
约束空 -> 再扫线索词(不要/必须/预算/期限)
|
|
12
|
-
- 空段文案改诚实表述(本轮没有明显约束),不再统一写未提取到
|
|
13
|
-
- 同句不跨段重复的既有约束有测试锁
|
|
14
|
-
|
|
15
|
-
待办清理:RSS / BM25 两处过期标记已改(早已完成);统计刷新
|
|
16
|
-
测试 119/119(新增 test_summary_fallback 3 条)
|