dsh-context-compression-improved 0.8.0-beta.7 → 0.9.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/.gitattributes +2 -2
- package/.githooks/pre-push +37 -37
- package/.github/workflows/ci.yml +39 -39
- package/CHANGELOG.de.md +41 -0
- package/CHANGELOG.es.md +41 -0
- package/CHANGELOG.fr.md +42 -0
- package/CHANGELOG.it.md +41 -0
- package/CHANGELOG.ja.md +35 -0
- package/CHANGELOG.ko.md +34 -0
- package/CHANGELOG.md +47 -0
- package/CHANGELOG.ru.md +37 -0
- package/CHANGELOG.zh.md +32 -0
- package/CONTRIBUTING.md +22 -22
- package/LICENSE +21 -21
- package/README.de.md +7 -9
- package/README.es.md +7 -9
- package/README.fr.md +7 -9
- package/README.it.md +7 -9
- package/README.ja.md +6 -2
- package/README.ko.md +6 -2
- package/README.md +96 -98
- package/README.ru.md +7 -9
- package/README.zh.md +89 -85
- package/SECURITY.md +18 -18
- package/THIRD_PARTY_NOTICES.md +14 -14
- package/docs/compat-0.1.5-report.md +77 -77
- package/docs/installation.de.md +5 -5
- package/docs/installation.es.md +5 -5
- package/docs/installation.fr.md +5 -5
- package/docs/installation.it.md +5 -5
- package/docs/installation.ja.md +5 -5
- package/docs/installation.ko.md +5 -5
- package/docs/installation.md +5 -5
- package/docs/installation.ru.md +5 -5
- package/docs/installation.zh.md +5 -5
- package/docs/repair-log.md +657 -657
- package/package.json +163 -163
- package/packages/selector/LICENSE +21 -21
- package/packages/selector/README.md +26 -26
- package/packages/selector/README.zh.md +24 -24
- package/packages/selector/THIRD_PARTY_NOTICES.md +32 -32
- package/packages/selector/cordis.patch.yml +27 -27
- package/packages/selector/docs/history-tool-call-working-set-spec.md +112 -112
- package/packages/selector/docs/native-tool-result-selector-spec.md +34 -34
- package/packages/selector/docs/subagent-cache-reuse-spec.md +46 -46
- package/packages/selector/dsh.plugin.json +16 -16
- package/packages/selector/lib/client.js +178 -21
- package/packages/selector/lib/host-generation.js +62 -0
- package/packages/selector/lib/index.js +208 -1
- package/packages/selector/lib/invariant.js +1 -1
- package/packages/selector/lib/pruner.js +41 -43
- package/packages/selector/lib/style.css +53 -53
- package/packages/selector/lib/tail-trim.js +73 -4
- package/packages/selector/package.json +80 -21
- package/packages/selector/screenshots.json +3 -3
- package/packages/selector/src/client/CustomPolicyEditor.tsx +216 -216
- package/packages/selector/src/client/EstimatorControls.tsx +277 -277
- package/packages/selector/src/client/bridge-scope.ts +125 -0
- package/packages/selector/src/client/index.ts +109 -31
- package/packages/selector/src/client/monitor-fab.ts +0 -2
- package/packages/selector/src/client/preset-options.ts +88 -88
- package/packages/selector/src/client/scope-face.ts +24 -24
- package/packages/selector/src/compat/host-generation.ts +96 -0
- package/packages/selector/src/compat/settings-lease.ts +108 -0
- package/packages/selector/src/compat/tool-result.ts +91 -0
- package/packages/selector/src/css-modules.d.ts +6 -6
- package/packages/selector/src/deepseek-v4-tokenizer.ts +205 -205
- package/packages/selector/src/estimator-catalog.ts +104 -104
- package/packages/selector/src/index.ts +8 -0
- package/packages/selector/src/invariant.ts +113 -113
- package/packages/selector/src/preset-overlay.ts +626 -626
- package/packages/selector/src/pruner/content.ts +198 -198
- package/packages/selector/src/pruner/session.ts +97 -96
- package/packages/selector/src/pruner/tuning.ts +23 -23
- package/packages/selector/src/pruner/types.ts +78 -78
- package/packages/selector/src/pruner.ts +45 -40
- package/packages/selector/src/runtime/adaptive-cost.ts +205 -205
- package/packages/selector/src/runtime/custom-policy.ts +278 -278
- package/packages/selector/src/runtime/deepseek-official-pricing.ts +298 -298
- package/packages/selector/src/runtime/deepseek-v4-vision-tokens.ts +254 -254
- package/packages/selector/src/runtime/measurement.ts +431 -431
- package/packages/selector/src/runtime/reducers.ts +1674 -1674
- package/packages/selector/src/runtime/retrieve.ts +7 -3
- package/packages/selector/src/runtime/session-events.ts +30 -30
- package/packages/selector/src/runtime/tail-trim.ts +175 -165
- package/packages/selector/src/runtime/token-count.ts +72 -72
- package/packages/selector/src/runtime/tokenpilot/advisor.ts +419 -419
- package/packages/selector/src/runtime/tokenpilot/benefit.ts +200 -200
- package/packages/selector/src/runtime/tokenpilot/dedup.ts +81 -81
- package/packages/selector/src/runtime/tokenpilot/estimator.ts +151 -151
- package/packages/selector/src/runtime/tokenpilot/locator.ts +128 -128
- package/packages/selector/src/runtime/tokenpilot/read-state.ts +98 -98
- package/packages/selector/src/runtime/tokenpilot/sidechannel.ts +303 -303
- package/packages/selector/src/runtime/toolclass.ts +103 -103
- package/packages/selector/src/runtime/value.ts +48 -48
- package/packages/selector/src/settings-bridge.ts +175 -0
- package/packages/selector/tests/advisor-report.host.spec.ts +223 -223
- package/packages/selector/tests/built/client-artifact.spec.ts +6 -9
- package/packages/selector/tests/cache-prefix-audit.spec.ts +123 -123
- package/packages/selector/tests/code-skeleton.client.spec.ts +98 -94
- package/packages/selector/tests/compat/compat-narrow-waist.spec.ts +150 -0
- package/packages/selector/tests/custom-contract.client.spec.ts +226 -223
- package/packages/selector/tests/estimator-catalog.spec.ts +70 -70
- package/packages/selector/tests/estimator-route-registration.host.spec.ts +199 -194
- package/packages/selector/tests/helpers/legacy-namespace.ts +35 -35
- package/packages/selector/tests/helpers/legacy-settings/index.ts +15 -15
- package/packages/selector/tests/helpers/legacy-settings/legacy/provider.d.ts +41 -41
- package/packages/selector/tests/helpers/legacy-settings/legacy/provider.js +647 -647
- package/packages/selector/tests/helpers/legacy-settings/legacy/redact.js +78 -78
- package/packages/selector/tests/helpers/legacy-settings/legacy/util-values.js +234 -234
- package/packages/selector/tests/host-preset-overlay.host.spec.ts +204 -204
- package/packages/selector/tests/preset-options-write.client.spec.ts +192 -188
- package/packages/selector/tests/preset-overlay-loader.e2e.host.spec.ts +200 -200
- package/packages/selector/tests/preset-overlay.host.spec.ts +246 -246
- package/packages/selector/tests/public/package-contract.client.spec.ts +11 -3
- package/packages/selector/tests/runtime/adaptive-cost.spec.ts +167 -167
- package/packages/selector/tests/runtime/advice-never-withholds.host.spec.ts +230 -230
- package/packages/selector/tests/runtime/advisor-invariant.spec.ts +272 -272
- package/packages/selector/tests/runtime/advisor.spec.ts +226 -226
- package/packages/selector/tests/runtime/auto-compact-config.spec.ts +523 -523
- package/packages/selector/tests/runtime/char-basis.spec.ts +30 -30
- package/packages/selector/tests/runtime/code-skeleton.spec.ts +152 -152
- package/packages/selector/tests/runtime/deepseek-official-pricing.spec.ts +186 -186
- package/packages/selector/tests/runtime/deepseek-v4-tokenizer.spec.ts +122 -122
- package/packages/selector/tests/runtime/deepseek-v4-vision-tokens.spec.ts +122 -122
- package/packages/selector/tests/runtime/deprecated-preset-options.spec.ts +96 -96
- package/packages/selector/tests/runtime/fixtures/profile-baseline.json +273 -273
- package/packages/selector/tests/runtime/fixtures/tokenizer-golden.json +106 -106
- package/packages/selector/tests/runtime/fixtures/vision-golden.json +459 -459
- package/packages/selector/tests/runtime/frequency-longstrings.spec.ts +74 -74
- package/packages/selector/tests/runtime/html-reducer.spec.ts +212 -212
- package/packages/selector/tests/runtime/line-mapping.spec.ts +153 -153
- package/packages/selector/tests/runtime/prose-reducers.spec.ts +133 -133
- package/packages/selector/tests/runtime/public/public-runtime.spec.ts +3 -3
- package/packages/selector/tests/runtime/read-input-cap.spec.ts +33 -33
- package/packages/selector/tests/runtime/search-reducer.spec.ts +110 -110
- package/packages/selector/tests/runtime/session-events.spec.ts +27 -27
- package/packages/selector/tests/runtime/sidechannel.spec.ts +241 -241
- package/packages/selector/tests/runtime/toc-and-bundled.spec.ts +159 -159
- package/packages/selector/tests/runtime/tokenizer-golden.spec.ts +53 -53
- package/packages/selector/tests/runtime/tokenpilot/benefit.spec.ts +217 -217
- package/packages/selector/tests/runtime/tokenpilot/dedup.spec.ts +52 -52
- package/packages/selector/tests/runtime/tokenpilot/estimator.spec.ts +79 -79
- package/packages/selector/tests/runtime/tokenpilot/locator.spec.ts +76 -76
- package/packages/selector/tests/runtime/tokenpilot/profile-baseline.spec.ts +116 -116
- package/packages/selector/tests/runtime/tokenpilot/read-state.spec.ts +82 -82
- package/packages/selector/tests/runtime/toolclass.spec.ts +156 -156
- package/packages/selector/tests/runtime/value.spec.ts +23 -23
- package/packages/selector/tests/settings-seat.client.spec.ts +45 -7
- package/packages/selector/tests/standing-generation.host.spec.ts +724 -724
- package/packages/selector/tests/subagent-cache-reuse.host.spec.ts +269 -269
- package/packages/selector/tests/support/cache-prefix-audit.ts +105 -105
- package/packages/selector/tests/support/mock-adapter.ts +37 -37
- package/packages/selector/tests/support/ui-primitives.tsx +34 -34
- package/packages/selector/tsconfig.json +11 -11
- package/packages/selector/tsdown.client.config.ts +102 -102
- package/packages/selector/tsdown.config.ts +20 -20
- package/scripts/capture-profile-baseline.mjs +42 -42
- package/scripts/generate-tokenizer-fixtures.py +81 -81
- package/scripts/generate-vision-fixtures.py +208 -208
- package/scripts/hosts.mjs +74 -0
- package/scripts/packed-components-smoke.mjs +763 -732
- package/scripts/packed-install-e2e.mjs +1330 -1273
- package/scripts/sync-hosts.mjs +174 -0
- package/scripts/toolclass-corpus-replay.mjs +281 -281
- package/scripts/verify-release.mjs +335 -318
- package/tsconfig.base.json +18 -18
- package/tsconfig.json +7 -7
- package/tsconfig.tests.json +15 -15
- package/vitest.built.config.ts +9 -9
- package/vitest.config.ts +46 -43
|
@@ -4,8 +4,8 @@ window.__ModuleLoader__.load({
|
|
|
4
4
|
var module = { exports: {} };
|
|
5
5
|
var exports = module.exports;
|
|
6
6
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
7
|
-
let react_jsx_runtime = require("react/jsx-runtime");
|
|
8
7
|
let react = require("react");
|
|
8
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
9
9
|
require("@deepseek-ai/dsh-client-ui-primitives");
|
|
10
10
|
//#region src/profiles.ts
|
|
11
11
|
/** Public context-compression choices shared by the Host schema and browser selector. */
|
|
@@ -3093,12 +3093,120 @@ window.__ModuleLoader__.load({
|
|
|
3093
3093
|
});
|
|
3094
3094
|
}
|
|
3095
3095
|
//#endregion
|
|
3096
|
+
//#region src/client/bridge-scope.ts
|
|
3097
|
+
const SETTINGS_ROUTE = "/api/dsh-context-compression-improved/settings";
|
|
3098
|
+
const POLL_MS = 4e3;
|
|
3099
|
+
function createBridgeScope() {
|
|
3100
|
+
let snapshot = {
|
|
3101
|
+
status: "loading",
|
|
3102
|
+
value: void 0,
|
|
3103
|
+
revision: void 0,
|
|
3104
|
+
writable: true,
|
|
3105
|
+
base: void 0,
|
|
3106
|
+
user: void 0,
|
|
3107
|
+
mode: "host"
|
|
3108
|
+
};
|
|
3109
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
3110
|
+
let pollTimer;
|
|
3111
|
+
const emit = () => {
|
|
3112
|
+
for (const listener of listeners) listener();
|
|
3113
|
+
};
|
|
3114
|
+
const applyDoc = (doc, revision) => {
|
|
3115
|
+
const value = decodeSettings(doc);
|
|
3116
|
+
const next = {
|
|
3117
|
+
status: value === void 0 ? "unavailable" : "ready",
|
|
3118
|
+
value,
|
|
3119
|
+
revision,
|
|
3120
|
+
writable: true,
|
|
3121
|
+
base: void 0,
|
|
3122
|
+
user: void 0,
|
|
3123
|
+
mode: "host"
|
|
3124
|
+
};
|
|
3125
|
+
if (JSON.stringify(next) !== JSON.stringify(snapshot)) {
|
|
3126
|
+
snapshot = next;
|
|
3127
|
+
emit();
|
|
3128
|
+
}
|
|
3129
|
+
};
|
|
3130
|
+
async function refresh() {
|
|
3131
|
+
try {
|
|
3132
|
+
const response = await fetch(SETTINGS_ROUTE, { headers: { "cache-control": "no-cache" } });
|
|
3133
|
+
if (!response.ok) throw new Error(`settings bridge ${response.status}`);
|
|
3134
|
+
const body = await response.json();
|
|
3135
|
+
applyDoc(body.doc, body.revision ?? void 0);
|
|
3136
|
+
} catch {
|
|
3137
|
+
if (snapshot.status !== "unavailable") {
|
|
3138
|
+
snapshot = {
|
|
3139
|
+
...snapshot,
|
|
3140
|
+
status: "unavailable"
|
|
3141
|
+
};
|
|
3142
|
+
emit();
|
|
3143
|
+
}
|
|
3144
|
+
}
|
|
3145
|
+
}
|
|
3146
|
+
async function writeDoc(next) {
|
|
3147
|
+
const response = await fetch(SETTINGS_ROUTE, {
|
|
3148
|
+
method: "POST",
|
|
3149
|
+
headers: { "content-type": "application/json" },
|
|
3150
|
+
body: JSON.stringify({ doc: next })
|
|
3151
|
+
});
|
|
3152
|
+
if (!response.ok) return false;
|
|
3153
|
+
const body = await response.json();
|
|
3154
|
+
if (body.ok !== true) return false;
|
|
3155
|
+
applyDoc(body.doc ?? next, (snapshot.revision ?? 0) + 1);
|
|
3156
|
+
return true;
|
|
3157
|
+
}
|
|
3158
|
+
const cloneDoc = () => {
|
|
3159
|
+
const value = snapshot.value;
|
|
3160
|
+
return value === void 0 ? {} : structuredClone(value);
|
|
3161
|
+
};
|
|
3162
|
+
return {
|
|
3163
|
+
getSnapshot: () => snapshot,
|
|
3164
|
+
subscribe: (listener) => {
|
|
3165
|
+
listeners.add(listener);
|
|
3166
|
+
if (listeners.size === 1) {
|
|
3167
|
+
refresh();
|
|
3168
|
+
pollTimer = setInterval(() => {
|
|
3169
|
+
refresh();
|
|
3170
|
+
}, POLL_MS);
|
|
3171
|
+
}
|
|
3172
|
+
return () => {
|
|
3173
|
+
listeners.delete(listener);
|
|
3174
|
+
if (listeners.size === 0 && pollTimer !== void 0) {
|
|
3175
|
+
clearInterval(pollTimer);
|
|
3176
|
+
pollTimer = void 0;
|
|
3177
|
+
}
|
|
3178
|
+
};
|
|
3179
|
+
},
|
|
3180
|
+
set: async (field, value) => {
|
|
3181
|
+
const next = cloneDoc();
|
|
3182
|
+
next[field] = value;
|
|
3183
|
+
return writeDoc(next);
|
|
3184
|
+
},
|
|
3185
|
+
unset: async (field) => {
|
|
3186
|
+
const next = cloneDoc();
|
|
3187
|
+
delete next[field];
|
|
3188
|
+
return writeDoc(next);
|
|
3189
|
+
},
|
|
3190
|
+
mutate: async (ops) => {
|
|
3191
|
+
const doc = cloneDoc();
|
|
3192
|
+
for (const op of ops) {
|
|
3193
|
+
const [head, key] = op.path;
|
|
3194
|
+
if (head !== "presetOptions") return false;
|
|
3195
|
+
const section = { ...doc.presetOptions ?? {} };
|
|
3196
|
+
if (op.op === "unset") delete section[key];
|
|
3197
|
+
else section[key] = op.value;
|
|
3198
|
+
doc.presetOptions = section;
|
|
3199
|
+
}
|
|
3200
|
+
return writeDoc(doc);
|
|
3201
|
+
},
|
|
3202
|
+
refresh: () => {
|
|
3203
|
+
refresh();
|
|
3204
|
+
}
|
|
3205
|
+
};
|
|
3206
|
+
}
|
|
3207
|
+
//#endregion
|
|
3096
3208
|
//#region src/client/index.ts
|
|
3097
|
-
const inject = [
|
|
3098
|
-
"slots",
|
|
3099
|
-
"locale",
|
|
3100
|
-
"configForms"
|
|
3101
|
-
];
|
|
3209
|
+
const inject = ["slots", "locale"];
|
|
3102
3210
|
const NS = "context-compression";
|
|
3103
3211
|
/** 0.1.7: the profile entry whose config carries the compression settings doc. */
|
|
3104
3212
|
const ENTRY_ID = "context-compression-improved-bundle";
|
|
@@ -3159,13 +3267,11 @@ window.__ModuleLoader__.load({
|
|
|
3159
3267
|
console.warn(`[dsh-context-compression-improved] locale "${language.id}" registration failed:`, error);
|
|
3160
3268
|
}
|
|
3161
3269
|
const tNav = ctx.locale?.bind?.(NS) ?? ((key) => key);
|
|
3162
|
-
let
|
|
3163
|
-
|
|
3164
|
-
|
|
3165
|
-
|
|
3166
|
-
|
|
3167
|
-
}
|
|
3168
|
-
};
|
|
3270
|
+
let configFormsHandle;
|
|
3271
|
+
/** Last monitorPanel.enabled seen through whichever scope is current (FAB 读数缓存). */
|
|
3272
|
+
let monitorPanelEnabledCache = false;
|
|
3273
|
+
/** 浮动监控面板(FAB): body 级幂等单例。enabled 读数走双臂 scope 的投影缓存。 */
|
|
3274
|
+
let readMonitorPanelEnabled = () => monitorPanelEnabledCache;
|
|
3169
3275
|
let latestSessionId;
|
|
3170
3276
|
try {
|
|
3171
3277
|
initMonitorFab({
|
|
@@ -3190,10 +3296,23 @@ window.__ModuleLoader__.load({
|
|
|
3190
3296
|
} catch (error) {
|
|
3191
3297
|
console.warn("[dsh-context-compression-improved] 监控浮动球挂载失败(不影响设置分节):", error);
|
|
3192
3298
|
}
|
|
3193
|
-
const
|
|
3194
|
-
|
|
3299
|
+
const bridgeScope = createBridgeScope();
|
|
3300
|
+
bridgeScope.refresh();
|
|
3301
|
+
const bridgeReadEnabled = () => decodeSettings(bridgeScope.getSnapshot().value)?.monitorPanel?.enabled ?? false;
|
|
3302
|
+
readMonitorPanelEnabled = () => configFormsHandle === void 0 ? bridgeReadEnabled() : monitorPanelEnabledCache;
|
|
3303
|
+
try {
|
|
3304
|
+
ctx.inject(["configForms"], (configFormsArg) => {
|
|
3305
|
+
const svc = configFormsArg?.configForms;
|
|
3306
|
+
const face = svc !== void 0 && svc !== null ? svc : configFormsArg;
|
|
3307
|
+
configFormsHandle = typeof face?.get === "function" ? face : void 0;
|
|
3308
|
+
});
|
|
3309
|
+
} catch (error) {
|
|
3310
|
+
console.warn("[dsh-context-compression-improved] configForms 臂挂载失败(桥面继续服务):", error);
|
|
3311
|
+
}
|
|
3312
|
+
/** configForms 原生 scope(0.1.7+):volatile entry 字段权威写路径。 */
|
|
3313
|
+
const scopeFromConfigForms = (service) => {
|
|
3314
|
+
const form = service.get(ENTRY_ID);
|
|
3195
3315
|
const readDoc = () => decodeSettings(form.getSnapshot().value?.settings);
|
|
3196
|
-
readMonitorPanelEnabled = () => decodeSettings(form.getSnapshot().value?.settings)?.monitorPanel?.enabled ?? false;
|
|
3197
3316
|
let projectedSource;
|
|
3198
3317
|
let projected = {
|
|
3199
3318
|
status: "loading",
|
|
@@ -3204,21 +3323,22 @@ window.__ModuleLoader__.load({
|
|
|
3204
3323
|
user: void 0,
|
|
3205
3324
|
mode: "host"
|
|
3206
3325
|
};
|
|
3207
|
-
|
|
3326
|
+
return {
|
|
3208
3327
|
getSnapshot() {
|
|
3209
3328
|
const snap = form.getSnapshot();
|
|
3210
3329
|
if (snap !== projectedSource) {
|
|
3211
3330
|
projectedSource = snap;
|
|
3212
3331
|
projected = {
|
|
3213
|
-
status: snap.status,
|
|
3332
|
+
status: snap.status ?? "loading",
|
|
3214
3333
|
value: decodeSettings(snap.value?.settings),
|
|
3215
|
-
revision: snap.revision,
|
|
3216
|
-
writable: snap.writable,
|
|
3334
|
+
revision: snap.revision ?? void 0,
|
|
3335
|
+
writable: snap.writable ?? false,
|
|
3217
3336
|
base: snap.base,
|
|
3218
3337
|
user: snap.user,
|
|
3219
|
-
mode: snap.mode
|
|
3338
|
+
mode: snap.mode ?? "host"
|
|
3220
3339
|
};
|
|
3221
3340
|
}
|
|
3341
|
+
monitorPanelEnabledCache = projected.value?.monitorPanel?.enabled ?? false;
|
|
3222
3342
|
return projected;
|
|
3223
3343
|
},
|
|
3224
3344
|
subscribe: (listener) => form.subscribe(listener),
|
|
@@ -3245,6 +3365,14 @@ window.__ModuleLoader__.load({
|
|
|
3245
3365
|
return form.set("settings", doc);
|
|
3246
3366
|
}
|
|
3247
3367
|
};
|
|
3368
|
+
};
|
|
3369
|
+
const injected = () => {
|
|
3370
|
+
let scope = bridgeScope;
|
|
3371
|
+
if (configFormsHandle !== void 0) try {
|
|
3372
|
+
scope = scopeFromConfigForms(configFormsHandle);
|
|
3373
|
+
} catch (error) {
|
|
3374
|
+
console.warn("[dsh-context-compression-improved] configForms scope 构建失败(回落桥面):", error);
|
|
3375
|
+
}
|
|
3248
3376
|
const writeAndConfirm = async (write, accepts) => {
|
|
3249
3377
|
const beforeRevision = scope.getSnapshot().revision;
|
|
3250
3378
|
await write();
|
|
@@ -3292,6 +3420,35 @@ window.__ModuleLoader__.load({
|
|
|
3292
3420
|
} catch (error) {
|
|
3293
3421
|
console.warn("[dsh-context-compression-improved] conversation.input.left 注册失败(旧宿主无该槽,浮动面板保持聚合口径):", error);
|
|
3294
3422
|
}
|
|
3423
|
+
try {
|
|
3424
|
+
ctx.slots.inject("plugins.bundle.config", () => ctx.slots.register({
|
|
3425
|
+
name: "plugins.bundle.config",
|
|
3426
|
+
key: "dsh-context-compression-improved",
|
|
3427
|
+
locale: NS
|
|
3428
|
+
}, (props) => {
|
|
3429
|
+
const inj = injected();
|
|
3430
|
+
const scope = inj.hooks?.compression;
|
|
3431
|
+
const useCompression = (selector) => {
|
|
3432
|
+
if (!scope) return selector({
|
|
3433
|
+
status: "loading",
|
|
3434
|
+
value: void 0,
|
|
3435
|
+
revision: void 0,
|
|
3436
|
+
writable: false,
|
|
3437
|
+
base: void 0,
|
|
3438
|
+
user: void 0,
|
|
3439
|
+
mode: "memory"
|
|
3440
|
+
});
|
|
3441
|
+
return (0, react.useSyncExternalStore)(scope.subscribe, () => selector(scope.getSnapshot()));
|
|
3442
|
+
};
|
|
3443
|
+
return (0, react.createElement)(ContextCompressionSettingsSection, {
|
|
3444
|
+
...inj,
|
|
3445
|
+
...props,
|
|
3446
|
+
useCompression
|
|
3447
|
+
});
|
|
3448
|
+
}));
|
|
3449
|
+
} catch (error) {
|
|
3450
|
+
console.warn("[dsh-context-compression-improved] plugins.bundle.config 注册失败(旧宿主无该槽,静默缺席):", error);
|
|
3451
|
+
}
|
|
3295
3452
|
}
|
|
3296
3453
|
//#endregion
|
|
3297
3454
|
exports.apply = apply;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
//#region src/compat/host-generation.ts
|
|
2
|
+
let cached;
|
|
3
|
+
/**
|
|
4
|
+
* Pure classifier from a RESOLVED settings service face. A service that still
|
|
5
|
+
* exposes `register` is a pre-0.1.7 host (0.1.0–0.1.5 lines, dsh-settings pack
|
|
6
|
+
* evidence — verified on the real 0.1.0-rc.2 host: `register(ns, schema,
|
|
7
|
+
* options)` at dsh-settings/lib/index.js:311); from 0.1.7-rc.1 the service
|
|
8
|
+
* drops register entirely and settings live in the loader-managed entry
|
|
9
|
+
* config.
|
|
10
|
+
*/
|
|
11
|
+
function classifySettingsFace(settings) {
|
|
12
|
+
return typeof settings?.register === "function" ? "legacy" : "modern";
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Probe the host generation from the settings service face.
|
|
16
|
+
*
|
|
17
|
+
* A verdict is only CACHED from a resolved service object. Rows compose
|
|
18
|
+
* before host services on every line (measured: the wire-time probe on a real
|
|
19
|
+
* 0.1.0-rc.2 cell saw no settings service yet and the old code cached
|
|
20
|
+
* 'modern' forever — the legacy lease arm went dead on the exact line it was
|
|
21
|
+
* built for). While the service is absent the answer is a provisional
|
|
22
|
+
* 'modern' and deliberately uncached, so the definitive
|
|
23
|
+
* `noteResolvedSettingsService` evidence can still flip it.
|
|
24
|
+
*/
|
|
25
|
+
function detectHostGeneration(ctx) {
|
|
26
|
+
if (cached !== void 0) return cached;
|
|
27
|
+
let settings;
|
|
28
|
+
try {
|
|
29
|
+
settings = ctx.get("settings");
|
|
30
|
+
} catch {
|
|
31
|
+
return "modern";
|
|
32
|
+
}
|
|
33
|
+
if (settings === null || typeof settings !== "object") return "modern";
|
|
34
|
+
cached = classifySettingsFace(settings);
|
|
35
|
+
return cached;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Definitive verdict from the resolved service (evidence observed, not
|
|
39
|
+
* guessed): the settings inject callback calls this once the service has
|
|
40
|
+
* actually composed. Always (re)writes the cache — a provisional earlier
|
|
41
|
+
* verdict must not survive real evidence.
|
|
42
|
+
*/
|
|
43
|
+
function noteResolvedSettingsService(settings) {
|
|
44
|
+
cached = classifySettingsFace(settings);
|
|
45
|
+
return cached;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Server-plane snapshot for code paths that hold no ctx (the tool-result
|
|
49
|
+
* adapters). The bridge's inject callback has already noted the resolved
|
|
50
|
+
* service by the time any session message flows, so this reads real evidence
|
|
51
|
+
* on every line; without it the only safe answer is the provisional default.
|
|
52
|
+
*/
|
|
53
|
+
function hostGenerationSnapshot() {
|
|
54
|
+
return cached ?? "modern";
|
|
55
|
+
}
|
|
56
|
+
function compatLog(ctx, level = "info") {
|
|
57
|
+
if (detectHostGeneration(ctx) === "legacy") return (message, ...rest) => console[level](`[dsh-context-compression-improved] ${message}`, ...rest);
|
|
58
|
+
const sink = ctx.logger?.[level]?.bind(ctx.logger) ?? ((...rest) => console[level](...rest));
|
|
59
|
+
return (message, ...rest) => sink(`[dsh-context-compression-improved] ${message}`, ...rest);
|
|
60
|
+
}
|
|
61
|
+
//#endregion
|
|
62
|
+
export { noteResolvedSettingsService as i, detectHostGeneration as n, hostGenerationSnapshot as r, compatLog as t };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { A as getLastIntentFold, C as estimateSavingsPricing, D as INTENT_GATE_GROWTH_TOKENS, E as INTENT_GATE_FLOOR_FRACTION, M as getSummaryOverride, R as setSummaryOverride, S as buildMonitorSnapshot, U as getSavingsLedger, a as DEFAULT_CONTEXT_COMPRESSION_SETTINGS, j as getObservedIntentEnabled, k as getAdvisorState, w as isSessionOverrideAction, x as applySessionOverride } from "./config.js";
|
|
1
|
+
import { A as getLastIntentFold, C as estimateSavingsPricing, D as INTENT_GATE_GROWTH_TOKENS, E as INTENT_GATE_FLOOR_FRACTION, M as getSummaryOverride, R as setSummaryOverride, S as buildMonitorSnapshot, U as getSavingsLedger, a as DEFAULT_CONTEXT_COMPRESSION_SETTINGS, j as getObservedIntentEnabled, k as getAdvisorState, n as CONTEXT_COMPRESSION_SETTINGS_NAMESPACE, r as ContextCompressionSettingsSchema, w as isSessionOverrideAction, x as applySessionOverride } from "./config.js";
|
|
2
|
+
import { i as noteResolvedSettingsService, n as detectHostGeneration, t as compatLog } from "./host-generation.js";
|
|
2
3
|
import z from "@deepseek-ai/schemastery";
|
|
3
4
|
import { createHash } from "node:crypto";
|
|
4
5
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
@@ -165,6 +166,211 @@ function registerSummaryCommand(ctx) {
|
|
|
165
166
|
});
|
|
166
167
|
}
|
|
167
168
|
//#endregion
|
|
169
|
+
//#region src/compat/settings-lease.ts
|
|
170
|
+
const SHARED_LEASE = Symbol.for("dsh-context-compression-improved/settings-lease");
|
|
171
|
+
/**
|
|
172
|
+
* Lease the namespace. No-op on modern hosts (register absent). Returns a
|
|
173
|
+
* read/update face; both are undefined-safe on modern hosts so callers can
|
|
174
|
+
* hold the face unconditionally and stay on the entry-config path there.
|
|
175
|
+
*/
|
|
176
|
+
function acquireSettingsLease(ctx, namespace, schema) {
|
|
177
|
+
const settings = ctx.settings;
|
|
178
|
+
if (settings === void 0 || typeof settings.register !== "function") return {
|
|
179
|
+
get: () => void 0,
|
|
180
|
+
update: async () => false
|
|
181
|
+
};
|
|
182
|
+
const owner = { settings };
|
|
183
|
+
let shared = settings[SHARED_LEASE];
|
|
184
|
+
if (shared === void 0) {
|
|
185
|
+
shared = {
|
|
186
|
+
owners: /* @__PURE__ */ new Set(),
|
|
187
|
+
registrationOwner: owner
|
|
188
|
+
};
|
|
189
|
+
Object.defineProperty(settings, SHARED_LEASE, {
|
|
190
|
+
configurable: true,
|
|
191
|
+
enumerable: false,
|
|
192
|
+
writable: false,
|
|
193
|
+
value: shared
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
shared.owners.add(owner);
|
|
197
|
+
const state = shared;
|
|
198
|
+
ctx.effect(() => () => {
|
|
199
|
+
state.owners.delete(owner);
|
|
200
|
+
if (state.registrationOwner === owner && state.owners.size > 0) {
|
|
201
|
+
const next = state.owners.values().next().value;
|
|
202
|
+
state.registrationOwner = next;
|
|
203
|
+
next.settings.register(namespace, schema);
|
|
204
|
+
}
|
|
205
|
+
if (state.owners.size === 0 && settings[SHARED_LEASE] === state) Reflect.deleteProperty(settings, SHARED_LEASE);
|
|
206
|
+
}, "contextCompressionSelector.settingsLease()");
|
|
207
|
+
if (state.owners.size === 1) settings.register(namespace, schema);
|
|
208
|
+
return {
|
|
209
|
+
get: () => {
|
|
210
|
+
try {
|
|
211
|
+
return settings.get?.(namespace);
|
|
212
|
+
} catch {
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
},
|
|
216
|
+
update: async (patch) => {
|
|
217
|
+
try {
|
|
218
|
+
await settings.update?.(namespace, patch);
|
|
219
|
+
return true;
|
|
220
|
+
} catch {
|
|
221
|
+
return false;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
//#endregion
|
|
227
|
+
//#region src/settings-bridge.ts
|
|
228
|
+
const ENTRY_ID = "context-compression-improved-bundle";
|
|
229
|
+
/** Hand back the service itself — the host reads route tables off `this`. */
|
|
230
|
+
function asWebServer$1(value) {
|
|
231
|
+
if (typeof value !== "object" || value === null) return void 0;
|
|
232
|
+
return typeof value.register === "function" ? value : void 0;
|
|
233
|
+
}
|
|
234
|
+
function jsonResponse$1(res, status, body) {
|
|
235
|
+
const typed = res;
|
|
236
|
+
if (typeof typed?.writeHead !== "function" || typeof typed?.end !== "function") return;
|
|
237
|
+
typed.writeHead(status, {
|
|
238
|
+
"content-type": "application/json; charset=utf-8",
|
|
239
|
+
"cache-control": "no-cache"
|
|
240
|
+
});
|
|
241
|
+
typed.end(JSON.stringify(body));
|
|
242
|
+
}
|
|
243
|
+
/** Modern-host read: the entry config descriptor's resolved value (pruner parity). */
|
|
244
|
+
function readEntryDoc(settings) {
|
|
245
|
+
const host = settings;
|
|
246
|
+
try {
|
|
247
|
+
const described = host?.describe?.().find((d) => String(d.ns) === ENTRY_ID)?.value;
|
|
248
|
+
if (described !== void 0) {
|
|
249
|
+
const record = described;
|
|
250
|
+
return record !== null && typeof record === "object" && "settings" in record ? record.settings : described;
|
|
251
|
+
}
|
|
252
|
+
} catch {}
|
|
253
|
+
}
|
|
254
|
+
function wireSettingsBridge(ctx) {
|
|
255
|
+
const log = compatLog(ctx, "warn");
|
|
256
|
+
let generation = detectHostGeneration(ctx);
|
|
257
|
+
let lease;
|
|
258
|
+
try {
|
|
259
|
+
ctx.inject(["settings"], (settingsCtx) => {
|
|
260
|
+
lease = acquireSettingsLease(settingsCtx, CONTEXT_COMPRESSION_SETTINGS_NAMESPACE, ContextCompressionSettingsSchema);
|
|
261
|
+
const svc = settingsCtx.settings;
|
|
262
|
+
generation = noteResolvedSettingsService(svc);
|
|
263
|
+
compatLog(ctx, "info")(`settings service resolved, generation=${generation}`);
|
|
264
|
+
});
|
|
265
|
+
} catch (error) {
|
|
266
|
+
log("settings lease wiring failed:", error);
|
|
267
|
+
}
|
|
268
|
+
const readDoc = () => {
|
|
269
|
+
const settings = (() => {
|
|
270
|
+
try {
|
|
271
|
+
return ctx.get("settings");
|
|
272
|
+
} catch {
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
})();
|
|
276
|
+
if (generation === "legacy") return lease?.get() ?? settings?.get?.("context-compression");
|
|
277
|
+
return readEntryDoc(settings) ?? settings?.get?.("context-compression");
|
|
278
|
+
};
|
|
279
|
+
const handleGet = (_req, res) => {
|
|
280
|
+
jsonResponse$1(res, 200, {
|
|
281
|
+
ok: true,
|
|
282
|
+
doc: readDoc() ?? null,
|
|
283
|
+
generation
|
|
284
|
+
});
|
|
285
|
+
};
|
|
286
|
+
const handlePost = (req, res) => {
|
|
287
|
+
if (generation !== "legacy" || lease === void 0) {
|
|
288
|
+
jsonResponse$1(res, 409, {
|
|
289
|
+
ok: false,
|
|
290
|
+
error: "modern-host: configForms is authoritative"
|
|
291
|
+
});
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
const chunks = [];
|
|
295
|
+
const typed = req;
|
|
296
|
+
if (typeof typed?.on !== "function") {
|
|
297
|
+
jsonResponse$1(res, 400, {
|
|
298
|
+
ok: false,
|
|
299
|
+
error: "unreadable request body"
|
|
300
|
+
});
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
typed.on("data", (chunk) => {
|
|
304
|
+
if (chunk) chunks.push(chunk);
|
|
305
|
+
});
|
|
306
|
+
typed.on("end", async () => {
|
|
307
|
+
try {
|
|
308
|
+
const parsed = JSON.parse(Buffer.concat(chunks).toString("utf8"));
|
|
309
|
+
if (parsed.doc === void 0 || parsed.doc === null || typeof parsed.doc !== "object") {
|
|
310
|
+
jsonResponse$1(res, 400, {
|
|
311
|
+
ok: false,
|
|
312
|
+
error: "doc must be an object"
|
|
313
|
+
});
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
if (!await lease.update(parsed.doc)) {
|
|
317
|
+
jsonResponse$1(res, 502, {
|
|
318
|
+
ok: false,
|
|
319
|
+
error: "settings update rejected by host"
|
|
320
|
+
});
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
323
|
+
jsonResponse$1(res, 200, {
|
|
324
|
+
ok: true,
|
|
325
|
+
doc: parsed.doc
|
|
326
|
+
});
|
|
327
|
+
} catch (error) {
|
|
328
|
+
jsonResponse$1(res, 500, {
|
|
329
|
+
ok: false,
|
|
330
|
+
error: String(error?.message ?? error)
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
});
|
|
334
|
+
};
|
|
335
|
+
let registered = false;
|
|
336
|
+
const register = (webServer, channel) => {
|
|
337
|
+
if (registered) return;
|
|
338
|
+
try {
|
|
339
|
+
const disposers = [`/endpoint/dsh-context-compression-improved/settings`, `/api/dsh-context-compression-improved/settings`].map((path) => webServer.register({
|
|
340
|
+
kind: "exact",
|
|
341
|
+
path,
|
|
342
|
+
handler: (req, res) => {
|
|
343
|
+
if (String(req?.method ?? "GET").toUpperCase() === "POST") return handlePost(req, res);
|
|
344
|
+
return handleGet(req, res);
|
|
345
|
+
}
|
|
346
|
+
})).filter((off) => typeof off === "function");
|
|
347
|
+
registered = true;
|
|
348
|
+
ctx.effect(() => () => {
|
|
349
|
+
for (const off of disposers) off();
|
|
350
|
+
}, "contextCompressionSelector.settings bridge route");
|
|
351
|
+
compatLog(ctx, "info")(`settings bridge registered (${channel}), generation=${generation}`);
|
|
352
|
+
} catch (error) {
|
|
353
|
+
log("settings bridge registration failed:", error);
|
|
354
|
+
}
|
|
355
|
+
};
|
|
356
|
+
const active = asWebServer$1((() => {
|
|
357
|
+
try {
|
|
358
|
+
return ctx.get("webServer");
|
|
359
|
+
} catch {
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
})());
|
|
363
|
+
if (active !== void 0) {
|
|
364
|
+
register(active, "direct");
|
|
365
|
+
if (registered) return;
|
|
366
|
+
}
|
|
367
|
+
ctx.inject(["webServer"], (injected) => {
|
|
368
|
+
const webServer = asWebServer$1(injected.webServer);
|
|
369
|
+
if (webServer === void 0) return;
|
|
370
|
+
register(webServer, "inject");
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
//#endregion
|
|
168
374
|
//#region src/preset-overlay.ts
|
|
169
375
|
/** Plugin-owned, reversible compression overlays for native agent presets. */
|
|
170
376
|
/**
|
|
@@ -1032,6 +1238,7 @@ function apply(ctx, config = {}) {
|
|
|
1032
1238
|
if (config.estimatorCatalogRoute === true) registerEstimatorCatalogRoute(ctx);
|
|
1033
1239
|
registerSavingsRoute(ctx);
|
|
1034
1240
|
registerMonitorRoute(ctx);
|
|
1241
|
+
wireSettingsBridge(ctx);
|
|
1035
1242
|
if (config.advisorReportRoute === true) registerAdvisorReportRoute(ctx);
|
|
1036
1243
|
registerSummaryCommand(ctx);
|
|
1037
1244
|
if (config.presetOverlay !== true) return;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as validatePublishedTailTrim,
|
|
1
|
+
import { a as validatePublishedTailTrim, l as sessionEvents } from "./tail-trim.js";
|
|
2
2
|
//#region src/invariant.ts
|
|
3
3
|
const PACKAGE_NAME = "dsh-context-compression-improved-runtime";
|
|
4
4
|
/** Cordis companion plugin name. */
|