dsh-agent-enhancer 0.3.2 → 0.3.4

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.
@@ -1 +1 @@
1
- {"version":3,"file":"session-hook.d.ts","sourceRoot":"","sources":["../../../src/host/auto-route/session-hook.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAKlD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AA2OvD,wBAAgB,uBAAuB,CACrC,GAAG,EAAE,OAAO,EACZ,OAAO,EAAE;IAAE,QAAQ,CAAC,QAAQ,EAAE,MAAM,gBAAgB,CAAA;CAAE,GACrD,IAAI,CAsEN"}
1
+ {"version":3,"file":"session-hook.d.ts","sourceRoot":"","sources":["../../../src/host/auto-route/session-hook.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAKlD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AA4PvD,wBAAgB,uBAAuB,CACrC,GAAG,EAAE,OAAO,EACZ,OAAO,EAAE;IAAE,QAAQ,CAAC,QAAQ,EAAE,MAAM,gBAAgB,CAAA;CAAE,GACrD,IAAI,CAwHN"}
@@ -5,6 +5,10 @@ export interface SessionModelPick {
5
5
  readonly model: string;
6
6
  readonly reasoningEffort?: string;
7
7
  }
8
- /** Same priority as the main Auto session hook: pending selection, then last used, then host default. */
8
+ /**
9
+ * Prefer `agent.model.current()` (0.2.2 domain API) over deprecated
10
+ * `sessionProjections.stateOf(session, 'modelSelection')`.
11
+ * Same priority as AgentModel: pending → lastUsed → live options → host default.
12
+ */
9
13
  export declare function projectedSessionModel(ctx: Context, session: Session): SessionModelPick;
10
14
  //# sourceMappingURL=session-selection.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"session-selection.d.ts","sourceRoot":"","sources":["../../../src/host/auto-route/session-selection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAA;AAEvD,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,CAAA;CAClC;AAOD,yGAAyG;AACzG,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,GAAG,gBAAgB,CAoBtF"}
1
+ {"version":3,"file":"session-selection.d.ts","sourceRoot":"","sources":["../../../src/host/auto-route/session-selection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAA;AAGvD,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,CAAA;CAClC;AAYD;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,GAAG,gBAAgB,CA0CtF"}
@@ -1 +1 @@
1
- {"version":3,"file":"dsh.d.ts","sourceRoot":"","sources":["../../../src/host/checkpoint/dsh.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAIlD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gCAAgC,CAAA;AAC/D,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAA;AAsC5D,qBAAa,qBAAqB;IAGpB,OAAO,CAAC,QAAQ,CAAC,GAAG;IAFhC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAgF;gBAE5E,GAAG,EAAE,OAAO;IAEzC,cAAc,GAAI,WAAW,SAAS,KAAG,wBAAwB,GAAG,SAAS,CAuC5E;CACF"}
1
+ {"version":3,"file":"dsh.d.ts","sourceRoot":"","sources":["../../../src/host/checkpoint/dsh.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAIlD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gCAAgC,CAAA;AAC/D,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAA;AAkC5D,qBAAa,qBAAqB;IAGpB,OAAO,CAAC,QAAQ,CAAC,GAAG;IAFhC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAgF;gBAE5E,GAAG,EAAE,OAAO;IAEzC,cAAc,GAAI,WAAW,SAAS,KAAG,wBAAwB,GAAG,SAAS,CAuC5E;CACF"}
@@ -1,4 +1,5 @@
1
1
  import type { Context } from '@deepseek-ai/cordis';
2
+ import type { CompactionResult } from '@deepseek-ai/dsh-compaction';
2
3
  import type { Session } from '@deepseek-ai/dsh-session';
3
4
  import type { SessionId } from '@deepseek-ai/dsh-session/types';
4
5
  import type { EnhancerSettings } from '../config.ts';
@@ -7,7 +8,7 @@ export interface ContextCompactRequest {
7
8
  }
8
9
  export interface ContextCompactResult {
9
10
  readonly sessionId: SessionId;
10
- /** Official `/compact` returned a replacement summary. */
11
+ /** Official manual compaction returned a replacement summary. */
11
12
  readonly status: 'compacted' | 'noop';
12
13
  readonly shadowedCount: number;
13
14
  readonly shadowedTokens: number;
@@ -16,7 +17,7 @@ export interface CompactRouteOverride {
16
17
  readonly provider: string;
17
18
  readonly model: string;
18
19
  }
19
- /** Minimal face of `@deepseek-ai/dsh-commands` used for `/compact`. */
20
+ /** Minimal face of `@deepseek-ai/dsh-commands` used as `/compact` fallback. */
20
21
  export interface CompactCommandRuntime {
21
22
  execute(agent: unknown, line: string, attachments: readonly unknown[], signal: AbortSignal): Promise<{
22
23
  readonly result: {
@@ -25,18 +26,36 @@ export interface CompactCommandRuntime {
25
26
  };
26
27
  } | undefined>;
27
28
  }
28
- /** Resolve the temporary agent route used while official `/compact` runs. */
29
+ /** Official `ctx.compaction.compactNow` — same seam chat `/compact` calls. */
30
+ export interface CompactEngineRuntime {
31
+ compactNow(agent: CompactManualAgent, signal: AbortSignal, sourceCommandId?: string): Promise<CompactionResult | null>;
32
+ }
33
+ /** Agent shape required by manual compaction (`runMaintenance` + idle gate). */
34
+ export interface CompactManualAgent {
35
+ readonly status?: unknown;
36
+ readonly options?: {
37
+ provider?: string;
38
+ model?: string;
39
+ };
40
+ readonly session?: unknown;
41
+ runMaintenance?<T>(task: (signal: AbortSignal) => Promise<T>): Promise<T>;
42
+ }
43
+ /**
44
+ * Kept for settings / Auto mapping tests. Live compact follows the official
45
+ * summarizer route (requestHeader / agent.options) — do not force a plugin seat.
46
+ */
29
47
  export declare function resolveCompactRouteOverride(ctx: Context, settings: EnhancerSettings, session: Session, signal: AbortSignal): Promise<CompactRouteOverride | undefined>;
30
48
  /**
31
- * Trigger official idle `/compact` through the command registry — same path as
32
- * typing `/compact` in chat. Avoids requiring `ctx.compaction` inject (which is
33
- * not visible in this plugin's Cordis scope on Desktop).
49
+ * Same backend as chat `/compact`: prefer `ctx.compaction.compactNow`, fall back
50
+ * to `commands.execute('/compact')`. Do not mutate agent.options or wrap
51
+ * purpose=compaction streams with a plugin-forced route — Auto remapping in
52
+ * session-hook is enough for the sentinel seat.
34
53
  */
35
54
  export declare function compactContextNow(options: {
55
+ readonly compaction: CompactEngineRuntime | undefined;
36
56
  readonly commands: CompactCommandRuntime | undefined;
37
- readonly agent: unknown;
57
+ readonly agent: CompactManualAgent;
38
58
  readonly sessionId: SessionId;
39
59
  readonly signal: AbortSignal;
40
- readonly route?: CompactRouteOverride;
41
60
  }): Promise<ContextCompactResult>;
42
61
  //# sourceMappingURL=context-compact.d.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AG,SAAS,CAAA;IACrD,QAAQ,CAAC,QAAQ,EAAE,qBAAqB,GAAG,SAAS,CAAA;IACpD,QAAQ,CAAC,KAAK,EAAE,kBAAkB,CAAA;IAClC,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAA;IAC7B,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAA;CAC7B,GAAG,OAAO,CAAC,oBAAoB,CAAC,CA6ChC"}
@@ -4,15 +4,13 @@ import type { ModelCatalog } from '@deepseek-ai/dsh-api-session-controller/types
4
4
  import { TypertRemoteService } from '@deepseek-ai/dsh-typert-protocol';
5
5
  import { CheckpointRollbackService } from './checkpoint/service.ts';
6
6
  import type { CheckpointCutRequest, CheckpointRollbackRequest, CheckpointSummariesRequest } from './checkpoint/service.ts';
7
- import type { Session } from '@deepseek-ai/dsh-session';
8
- import type { CompactRouteOverride, ContextCompactRequest, ContextCompactResult } from './context-compact.ts';
7
+ import type { CompactCommandRuntime, ContextCompactRequest, ContextCompactResult } from './context-compact.ts';
9
8
  import type { ContextInspectRequest, ContextInspectResult } from './context-inspect.ts';
10
9
  import { AuxiliaryModels } from './model.ts';
11
10
  import type { ProviderBalances, ProviderBalancesRequest, UsageRange, UsageSummary, UsageSummaryReader } from './usage/types.ts';
12
11
  import type { RpcPayload } from './rpc.ts';
13
12
  import type { AuxiliaryResult } from './types.ts';
14
13
  import type { ApplyUpdateResult, UpdateCheckResult } from './update/types.ts';
15
- import type { CompactCommandRuntime } from './context-compact.ts';
16
14
  export declare const name = "agent-enhancer";
17
15
  export declare const inject: string[];
18
16
  export declare const Config: z<Schemastery.ObjectS<NoInfer<{
@@ -87,10 +85,9 @@ export declare const hostContribution: {
87
85
  };
88
86
  export declare class AgentEnhancerService extends TypertRemoteService {
89
87
  private readonly models;
90
- private readonly compactRoute;
91
88
  private readonly usage;
92
89
  private readonly balances;
93
- constructor(ctx: Context, models: AuxiliaryModels, compactRoute: (session: Session, signal: AbortSignal) => Promise<CompactRouteOverride | undefined>, usage?: UsageSummaryReader, balances?: {
90
+ constructor(ctx: Context, models: AuxiliaryModels, usage?: UsageSummaryReader, balances?: {
94
91
  get(force?: boolean, locale?: string): Promise<ProviderBalances>;
95
92
  });
96
93
  private assertOwner;
@@ -98,7 +95,7 @@ export declare class AgentEnhancerService extends TypertRemoteService {
98
95
  /** Same Desktop catalog the official model selector uses (`llm` registry). */
99
96
  listCatalog(): Promise<ModelCatalog>;
100
97
  inspectContext(request: ContextInspectRequest, signal: AbortSignal): Promise<ContextInspectResult>;
101
- /** Trigger the official idle `/compact` command (same path as chat `/compact`). */
98
+ /** Trigger official idle compaction (same seam as chat `/compact`). */
102
99
  compactContext(request: ContextCompactRequest, signal: AbortSignal): Promise<ContextCompactResult>;
103
100
  /** Read-only version probe — same gate policy as `listCatalog` (settings-safe). */
104
101
  checkUpdate(): Promise<UpdateCheckResult>;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/host/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,CAAC,MAAM,0BAA0B,CAAA;AACxC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+CAA+C,CAAA;AACjF,OAAO,EAAe,mBAAmB,EAAE,MAAM,kCAAkC,CAAA;AAcnF,OAAO,EAA2B,yBAAyB,EAAE,MAAM,yBAAyB,CAAA;AAC5F,OAAO,KAAK,EACV,oBAAoB,EACpB,yBAAyB,EACzB,0BAA0B,EAC3B,MAAM,yBAAyB,CAAA;AAMhC,OAAO,KAAK,EAAE,OAAO,EAAgB,MAAM,0BAA0B,CAAA;AAErE,OAAO,KAAK,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAA;AAE7G,OAAO,KAAK,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAA;AAEvF,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AA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tE,gBAAgB,CAAC,OAAO,GAAE,uBAA4B,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAKlF,WAAW,IAAI,OAAO,CAAC,iBAAiB,CAAC;CAUhD;AAoBD,OAAO,QAAQ,qBAAqB,CAAC;IACnC,UAAU,OAAO;QACf,aAAa,EAAE,oBAAoB,CAAA;QACnC,0EAA0E;QAC1E,QAAQ,EAAE,qBAAqB,CAAA;KAChC;CACF;AAmED,wBAAgB,KAAK,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAwFxD;AAED,0FAA0F;AAC1F,eAAO,MAAM,0BAA0B;;;;;;;;;;CAM7B,CAAA;AAEV,qBAAa,+BAAgC,SAAQ,mBAAmB;IAC5C,OAAO,CAAC,QAAQ,CAAC,QAAQ;gBAAvC,GAAG,EAAE,OAAO,EAAmB,QAAQ,EAAE,yBAAyB;IAIxE,OAAO,CAAC,OAAO,EAAE,yBAAyB,EAAE,MAAM,EAAE,WAAW;IAS/D,OAAO,CAAC,OAAO,EAAE,yBAAyB,EAAE,MAAM,EAAE,WAAW;IAS/D,SAAS,CAAC,OAAO,EAAE,0BAA0B,EAAE,MAAM,EAAE,WAAW;IASlE,MAAM,CAAC,OAAO,EAAE,oBAAoB,EAAE,MAAM,EAAE,WAAW;IAS/D,OAAO,CAAC,WAAW;IAMnB,OAAO,CAAC,WAAW;CAKpB;AAED,OAAO,QAAQ,qBAAqB,CAAC;IACnC,UAAU,OAAO;QACf,kBAAkB,EAAE,+BAA+B,CAAA;KACpD;CACF;AAED,wBAAgB,uBAAuB,CAAC,GAAG,EAAE,OAAO,EAAE,QAAQ,EAAE,yBAAyB,GAAG,IAAI,CAG/F"}
package/lib/identity.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /** Canonical package / plugin identity after the Composer → Agent rename. */
2
2
  export declare const PACKAGE_NAME = "dsh-agent-enhancer";
3
3
  export declare const PLUGIN_ID = "agent-enhancer";
4
- export declare const PACKAGE_VERSION = "0.3.2";
4
+ export declare const PACKAGE_VERSION = "0.3.4";
5
5
  /** Pre-0.2.0 identity — keep reading markers and plugin-data written under these names. */
6
6
  export declare const LEGACY_PACKAGE_NAME = "dsh-composer-enhancer";
7
7
  export declare const LEGACY_PLUGIN_ID = "composer-enhancer";
package/lib/index.js CHANGED
@@ -160,7 +160,7 @@ var AuxiliaryError = class extends Error {
160
160
  // src/identity.ts
161
161
  var PACKAGE_NAME = "dsh-agent-enhancer";
162
162
  var PLUGIN_ID = "agent-enhancer";
163
- var PACKAGE_VERSION = "0.3.2";
163
+ var PACKAGE_VERSION = "0.3.4";
164
164
  var LEGACY_PACKAGE_NAME = "dsh-composer-enhancer";
165
165
  var ROLLBACK_PREFIX = `${PACKAGE_NAME}:rollback:`;
166
166
  var UNDO_PREFIX = `${PACKAGE_NAME}:undo:`;
@@ -247,9 +247,7 @@ async function buildAuxiliaryModelCatalog(ctx) {
247
247
  function syncIdleLastTurnFromProjection(ctx, agent) {
248
248
  if (agent.status !== "idle") return;
249
249
  const agents = ctx.agents;
250
- const fromAgents = agents.turnBoundaryOf?.(agent.session);
251
- const fromProjection = ctx.sessionProjections.stateOf(agent.session, "turnBoundary");
252
- const lastTurn = fromAgents?.lastTurn ?? fromProjection?.lastTurn;
250
+ const lastTurn = agents.turnBoundaryOf?.(agent.session)?.lastTurn;
253
251
  if (typeof lastTurn !== "number") return;
254
252
  const live = agent;
255
253
  if (live.phase?.kind !== "idle" || live.phase.lastTurn === lastTurn) return;
@@ -2763,6 +2761,9 @@ var CheckpointStore = class {
2763
2761
  }
2764
2762
  };
2765
2763
 
2764
+ // src/host/context-compact.ts
2765
+ import { ManualCompactionError } from "@deepseek-ai/dsh-compaction";
2766
+
2766
2767
  // src/host/auto-route/classifier.ts
2767
2768
  import { BlockAssembler } from "@deepseek-ai/dsh-llm";
2768
2769
 
@@ -2923,10 +2924,24 @@ function clearSessionResolvedRoute(agent) {
2923
2924
  // src/host/auto-route/session-selection.ts
2924
2925
  function projectedSessionModel(ctx, session) {
2925
2926
  try {
2926
- const projections = ctx.get("sessionProjections");
2927
- const state = projections?.stateOf?.(session, "modelSelection");
2928
- if (state?.pending !== void 0 && state.pending !== null) return state.pending;
2929
- if (state?.lastUsed !== void 0 && state.lastUsed !== null) return state.lastUsed;
2927
+ const agents = ctx.get("agents");
2928
+ const agent = agents?.get?.(session.id);
2929
+ const fromModel = agent?.model?.current?.();
2930
+ if (fromModel !== void 0 && typeof fromModel.provider === "string" && fromModel.provider !== "" && typeof fromModel.model === "string" && fromModel.model !== "") {
2931
+ return {
2932
+ provider: fromModel.provider,
2933
+ model: fromModel.model,
2934
+ ...typeof fromModel.reasoningEffort === "string" ? { reasoningEffort: fromModel.reasoningEffort } : {}
2935
+ };
2936
+ }
2937
+ const options = agent?.options;
2938
+ if (typeof options?.provider === "string" && options.provider !== "" && typeof options.model === "string" && options.model !== "") {
2939
+ return {
2940
+ provider: options.provider,
2941
+ model: options.model,
2942
+ ...typeof options.reasoningEffort === "string" ? { reasoningEffort: options.reasoningEffort } : {}
2943
+ };
2944
+ }
2930
2945
  } catch {
2931
2946
  }
2932
2947
  try {
@@ -3131,88 +3146,35 @@ async function resolveAutoRoute(options) {
3131
3146
  }
3132
3147
 
3133
3148
  // src/host/context-compact.ts
3134
- function modelExists(provider, model) {
3135
- return provider !== "" && model !== "";
3136
- }
3137
- function sessionModelSelection(ctx, session) {
3138
- return projectedSessionModel(ctx, session);
3139
- }
3140
- function tierRouteFromSelection(selection, effortFallback) {
3141
- return {
3142
- provider: selection.provider,
3143
- model: selection.model,
3144
- reasoningEffort: typeof selection.reasoningEffort === "string" ? selection.reasoningEffort : effortFallback
3145
- };
3146
- }
3147
- function fallbackFromSession(ctx, session, override) {
3148
- const selection = sessionModelSelection(ctx, session);
3149
- if (!isAutoModel(selection) && modelExists(selection.provider, selection.model)) {
3150
- return tierRouteFromSelection(selection, override.reasoningEffort);
3151
- }
3152
- const fallback = ctx.agentDefaultModel.currentSelection();
3153
- if (isAutoModel(fallback) || !modelExists(fallback.provider, fallback.model)) return void 0;
3154
- return tierRouteFromSelection(fallback, override.reasoningEffort);
3155
- }
3156
- async function resolveAutoRouteForCompact(ctx, settings, session, feature, signal) {
3157
- const override = auxiliaryModelOf(settings, "compact");
3158
- const map = autoRouteMapOf(settings);
3159
- const classify = settings.autoClassifierEnabled ? createClassifier(ctx.llm, map.classifier) : void 0;
3160
- const hint = sessionTurnHint(session);
3161
- const mapped = await resolveAutoRoute({
3162
- text: hint?.text ?? "",
3163
- feature,
3164
- toolHeavy: hint?.toolHeavy,
3165
- map,
3166
- classifierEnabled: settings.autoClassifierEnabled,
3167
- classify,
3168
- isAvailable: modelExists,
3169
- fallback: fallbackFromSession(ctx, session, override),
3170
- signal
3171
- });
3172
- if (feature === "session") {
3173
- setSessionResolvedRouteForSession(session, {
3174
- provider: mapped.provider,
3175
- model: mapped.model,
3176
- reasoningEffort: mapped.reasoningEffort
3177
- });
3178
- }
3179
- return { provider: mapped.provider, model: mapped.model };
3180
- }
3181
- async function resolveCompactRouteOverride(ctx, settings, session, signal) {
3182
- signal.throwIfAborted();
3183
- const override = auxiliaryModelOf(settings, "compact");
3184
- if (isAutoModel(override)) {
3185
- return resolveAutoRouteForCompact(ctx, settings, session, "compact", signal);
3186
- }
3187
- if (!isFollowSessionModel(override)) {
3188
- return { provider: override.provider, model: override.model };
3189
- }
3190
- const selection = sessionModelSelection(ctx, session);
3191
- if (isAutoModel(selection)) {
3192
- const cached = getSessionResolvedRouteForSession(session);
3193
- if (cached !== void 0) {
3194
- return { provider: cached.provider, model: cached.model };
3149
+ function mapManualCompactionCode(code) {
3150
+ switch (code) {
3151
+ case "busy":
3152
+ return "COMPACT_BUSY";
3153
+ case "cancelled":
3154
+ return "COMPACT_FAILED";
3155
+ case "changed":
3156
+ return "COMPACT_CHANGED";
3157
+ case "summary":
3158
+ return "COMPACT_SUMMARY";
3159
+ case "commit":
3160
+ return "COMPACT_FAILED";
3161
+ case "persistence":
3162
+ return "COMPACT_FAILED";
3163
+ default: {
3164
+ const _exhaustive = code;
3165
+ return _exhaustive;
3195
3166
  }
3196
- return resolveAutoRouteForCompact(ctx, settings, session, "session", signal);
3197
3167
  }
3198
- return void 0;
3199
3168
  }
3200
- function applyCompactRoute(agent, route) {
3201
- if (route === void 0 || route.provider === "" || route.model === "") return void 0;
3202
- const options = agent.options;
3203
- if (options === void 0 || typeof options !== "object") return void 0;
3204
- const previous = { provider: options.provider, model: options.model };
3205
- options.provider = route.provider;
3206
- options.model = route.model;
3207
- return () => {
3208
- ;
3209
- options.provider = previous.provider;
3210
- options.model = previous.model;
3211
- };
3169
+ function isManualCompactionError(error) {
3170
+ if (error instanceof ManualCompactionError) return true;
3171
+ if (typeof error !== "object" || error === null) return false;
3172
+ const candidate = error;
3173
+ return candidate.name === "ManualCompactionError" && typeof candidate.code === "string";
3212
3174
  }
3213
3175
  function mapCompactErrorText(text3) {
3214
3176
  const lower = text3.toLowerCase();
3215
- if (lower.includes("busy") || lower.includes("active") || text3.includes("\u5FD9\u788C")) {
3177
+ if (lower.includes("busy") || lower.includes("active") || text3.includes("\u5FD9\u788C") || text3.includes("\u4E0D\u53EF\u7528\u56E0\u4E3A")) {
3216
3178
  return "COMPACT_BUSY";
3217
3179
  }
3218
3180
  if (lower.includes("summary") || text3.includes("\u6458\u8981")) {
@@ -3224,6 +3186,9 @@ function mapCompactErrorText(text3) {
3224
3186
  if (lower.includes("not available") || text3.includes("\u672A\u63D0\u4F9B") || text3.includes("\u4E0D\u53EF\u7528")) {
3225
3187
  return "COMPACT_UNAVAILABLE";
3226
3188
  }
3189
+ if (lower.includes("cancelled") || text3.includes("\u5DF2\u53D6\u6D88")) {
3190
+ return "COMPACT_FAILED";
3191
+ }
3227
3192
  return "COMPACT_FAILED";
3228
3193
  }
3229
3194
  function parseCompactSuccess(sessionId, text3) {
@@ -3245,20 +3210,48 @@ function parseCompactSuccess(sessionId, text3) {
3245
3210
  shadowedTokens: tokenMatch ? Number(tokenMatch[1]) : 0
3246
3211
  };
3247
3212
  }
3213
+ function resultFromEngine(sessionId, result) {
3214
+ if (result === null) {
3215
+ return {
3216
+ sessionId,
3217
+ status: "noop",
3218
+ shadowedCount: 0,
3219
+ shadowedTokens: 0
3220
+ };
3221
+ }
3222
+ return {
3223
+ sessionId,
3224
+ status: "compacted",
3225
+ shadowedCount: result.shadowedSeqs.length,
3226
+ shadowedTokens: result.shadowedTokenCount
3227
+ };
3228
+ }
3248
3229
  async function compactContextNow(options) {
3249
3230
  options.signal.throwIfAborted();
3250
- if (options.commands === void 0 || typeof options.commands.execute !== "function") {
3251
- throw new AuxiliaryError("COMPACT_UNAVAILABLE");
3252
- }
3253
- if (options.agent === null || typeof options.agent !== "object") {
3231
+ const agent = options.agent;
3232
+ if (agent === null || typeof agent !== "object") {
3254
3233
  throw new AuxiliaryError("SESSION_CHANGED");
3255
3234
  }
3256
- const agent = options.agent;
3257
3235
  if (agent.status !== void 0 && agent.status !== "idle") {
3258
3236
  throw new AuxiliaryError("COMPACT_BUSY");
3259
3237
  }
3260
- const restore = applyCompactRoute(agent, options.route);
3238
+ const canCompactNow = options.compaction !== void 0 && typeof options.compaction.compactNow === "function" && typeof agent.runMaintenance === "function";
3261
3239
  try {
3240
+ if (canCompactNow && options.compaction !== void 0) {
3241
+ try {
3242
+ const result = await options.compaction.compactNow(agent, options.signal);
3243
+ return resultFromEngine(options.sessionId, result);
3244
+ } catch (error) {
3245
+ if (options.signal.aborted) throw error;
3246
+ if (isManualCompactionError(error)) {
3247
+ throw new AuxiliaryError(mapManualCompactionCode(error.code));
3248
+ }
3249
+ throw error;
3250
+ }
3251
+ }
3252
+ if (options.commands === void 0 || typeof options.commands.execute !== "function") {
3253
+ throw new AuxiliaryError("COMPACT_UNAVAILABLE");
3254
+ }
3262
3255
  const execution = await options.commands.execute(agent, "/compact", [], options.signal);
3263
3256
  if (execution === void 0) throw new AuxiliaryError("COMPACT_UNAVAILABLE");
3264
3257
  if (execution.result.kind === "error") {
@@ -3268,9 +3261,10 @@ async function compactContextNow(options) {
3268
3261
  } catch (error) {
3269
3262
  if (options.signal.aborted) throw error;
3270
3263
  if (error instanceof AuxiliaryError) throw error;
3264
+ if (isManualCompactionError(error)) {
3265
+ throw new AuxiliaryError(mapManualCompactionCode(error.code));
3266
+ }
3271
3267
  throw new AuxiliaryError("COMPACT_FAILED");
3272
- } finally {
3273
- restore?.();
3274
3268
  }
3275
3269
  }
3276
3270
 
@@ -3623,6 +3617,13 @@ function concreteRoute(selection) {
3623
3617
  };
3624
3618
  }
3625
3619
  function projectedSelection(ctx, agent) {
3620
+ try {
3621
+ const fromModel = agent?.model?.current?.();
3622
+ if (fromModel !== void 0 && typeof fromModel.provider === "string" && fromModel.provider !== "" && typeof fromModel.model === "string" && fromModel.model !== "") {
3623
+ return fromModel;
3624
+ }
3625
+ } catch {
3626
+ }
3626
3627
  const session = agent?.session;
3627
3628
  if (session === void 0) return void 0;
3628
3629
  try {
@@ -3633,17 +3634,26 @@ function projectedSelection(ctx, agent) {
3633
3634
  }
3634
3635
  function fallbackRoute(ctx, agent) {
3635
3636
  try {
3637
+ const projected = concreteRoute(projectedSelection(ctx, agent));
3638
+ if (projected !== void 0) return projected;
3636
3639
  const options = agent?.options;
3637
3640
  const fromOptions = typeof options?.provider === "string" && typeof options.model === "string" ? concreteRoute({ provider: options.provider, model: options.model }) : void 0;
3638
3641
  if (fromOptions !== void 0) return fromOptions;
3639
- const projected = concreteRoute(projectedSelection(ctx, agent));
3640
- if (projected !== void 0) return projected;
3641
3642
  const defaults = softService(ctx, "agentDefaultModel");
3642
3643
  return concreteRoute(defaults?.currentSelection?.());
3643
3644
  } catch {
3644
3645
  return void 0;
3645
3646
  }
3646
3647
  }
3648
+ function shouldRemapAuto(config, agent) {
3649
+ if (isAutoModel(config)) return true;
3650
+ try {
3651
+ const seat = agent?.model?.current?.();
3652
+ return seat !== void 0 && isAutoModel(seat);
3653
+ } catch {
3654
+ return false;
3655
+ }
3656
+ }
3647
3657
  function routeConfig(config, mapped) {
3648
3658
  const { reasoningEffort: _effort, ...rest } = config;
3649
3659
  void _effort;
@@ -3698,41 +3708,77 @@ function installAutoSessionRoute(ctx, options) {
3698
3708
  });
3699
3709
  ctx.effect(() => {
3700
3710
  const llm = ctx.llm;
3701
- const inner = llm.prepareCall.bind(llm);
3702
- const wrapped = async (config, signal, configure) => {
3703
- const keyProbe = activeAgent(ctx) ?? config;
3704
- const depth = resolving.get(keyProbe) ?? 0;
3705
- if (depth > 0 || !isAutoModel(config)) return inner(config, signal, configure);
3711
+ if (typeof llm.prepareCall !== "function") return () => {
3712
+ };
3713
+ const innerPrepare = llm.prepareCall.bind(llm);
3714
+ const innerStream = typeof llm.stream === "function" ? llm.stream.bind(llm) : void 0;
3715
+ const remapAuto = async (config, signal, agent, feature = "session") => {
3716
+ const settings = options.settings();
3717
+ const map = autoRouteMapOf(settings);
3718
+ const note = (agent === void 0 ? void 0 : notes.get(agent)) ?? loggedTurn(asAgent(agent));
3719
+ const classify = settings.autoClassifierEnabled ? createClassifier({ prepareCall: innerPrepare }, map.classifier) : void 0;
3720
+ const mapped = await resolveAutoRoute({
3721
+ text: note?.text ?? "",
3722
+ feature,
3723
+ toolHeavy: note?.toolHeavy ?? false,
3724
+ map,
3725
+ classifierEnabled: settings.autoClassifierEnabled,
3726
+ classify,
3727
+ isAvailable: (provider, model) => provider !== "" && model !== "" && !isAutoModel({ provider, model }),
3728
+ signal,
3729
+ fallback: fallbackRoute(ctx, asAgent(agent))
3730
+ });
3731
+ if (agent !== void 0 && feature === "session") setSessionResolvedRoute(agent, mapped);
3732
+ return mapped;
3733
+ };
3734
+ const wrappedPrepare = async (config, signal, configure) => {
3706
3735
  const agent = activeAgent(ctx);
3736
+ const keyProbe = agent ?? config;
3737
+ const depth = resolving.get(keyProbe) ?? 0;
3738
+ if (depth > 0 || !shouldRemapAuto(config, asAgent(agent))) {
3739
+ return innerPrepare(config, signal, configure);
3740
+ }
3707
3741
  const key = agent ?? config;
3708
3742
  resolving.set(key, (resolving.get(key) ?? 0) + 1);
3709
3743
  try {
3710
- const settings = options.settings();
3711
- const map = autoRouteMapOf(settings);
3712
- const note = (agent === void 0 ? void 0 : notes.get(agent)) ?? loggedTurn(asAgent(agent));
3713
- const classify = settings.autoClassifierEnabled ? createClassifier({ prepareCall: inner }, map.classifier) : void 0;
3714
- const mapped = await resolveAutoRoute({
3715
- text: note?.text ?? "",
3716
- feature: "session",
3717
- toolHeavy: note?.toolHeavy ?? false,
3718
- map,
3719
- classifierEnabled: settings.autoClassifierEnabled,
3720
- classify,
3721
- isAvailable: (provider, model) => provider !== "" && model !== "" && !isAutoModel({ provider, model }),
3722
- signal,
3723
- fallback: fallbackRoute(ctx, asAgent(agent))
3724
- });
3725
- if (agent !== void 0) setSessionResolvedRoute(agent, mapped);
3726
- return await inner(routeConfig(config, mapped), signal, configure);
3744
+ const mapped = await remapAuto(config, signal, agent);
3745
+ return await innerPrepare(routeConfig(config, mapped), signal, configure);
3727
3746
  } finally {
3728
- const next = (resolving.get(key) ?? 1) - 1;
3729
- if (next <= 0) resolving.delete(key);
3730
- else resolving.set(key, next);
3747
+ const nextDepth = (resolving.get(key) ?? 1) - 1;
3748
+ if (nextDepth <= 0) resolving.delete(key);
3749
+ else resolving.set(key, nextDepth);
3731
3750
  }
3732
3751
  };
3733
- llm.prepareCall = wrapped;
3752
+ llm.prepareCall = wrappedPrepare;
3753
+ let wrappedStream;
3754
+ if (innerStream !== void 0) {
3755
+ wrappedStream = (options2) => {
3756
+ const agent = activeAgent(ctx);
3757
+ if (!shouldRemapAuto(options2, asAgent(agent))) return innerStream(options2);
3758
+ const keyProbe = agent ?? options2;
3759
+ const depth = resolving.get(keyProbe) ?? 0;
3760
+ if (depth > 0) return innerStream(options2);
3761
+ return (async function* remappedAutoStream() {
3762
+ const key = agent ?? options2;
3763
+ resolving.set(key, (resolving.get(key) ?? 0) + 1);
3764
+ try {
3765
+ const mapped = await remapAuto(options2, options2.signal, agent, "session");
3766
+ const routed = routeConfig(options2, mapped);
3767
+ yield* innerStream({ ...options2, ...routed });
3768
+ } finally {
3769
+ const nextDepth = (resolving.get(key) ?? 1) - 1;
3770
+ if (nextDepth <= 0) resolving.delete(key);
3771
+ else resolving.set(key, nextDepth);
3772
+ }
3773
+ })();
3774
+ };
3775
+ llm.stream = wrappedStream;
3776
+ }
3734
3777
  return () => {
3735
- if (llm.prepareCall === wrapped) llm.prepareCall = inner;
3778
+ if (llm.prepareCall === wrappedPrepare) llm.prepareCall = innerPrepare;
3779
+ if (wrappedStream !== void 0 && llm.stream === wrappedStream && innerStream !== void 0) {
3780
+ llm.stream = innerStream;
3781
+ }
3736
3782
  };
3737
3783
  });
3738
3784
  }
@@ -5851,7 +5897,7 @@ var inject = [
5851
5897
  "tokenMeter",
5852
5898
  "typert",
5853
5899
  "typertGateway",
5854
- // Official `/compact` runs through the command registry (not ctx.compaction).
5900
+ // Chat `/compact` → compaction.compactNow; commands kept as fallback.
5855
5901
  "commands"
5856
5902
  ];
5857
5903
  var Config = z5.object({
@@ -5892,7 +5938,7 @@ var hostContribution = {
5892
5938
  invocations: [...remoteInfo.descriptors, ...checkpointRemoteInfo.descriptors]
5893
5939
  };
5894
5940
  var AgentEnhancerService = class extends TypertRemoteService {
5895
- constructor(ctx, models, compactRoute, usage = {
5941
+ constructor(ctx, models, usage = {
5896
5942
  async summarize(range) {
5897
5943
  return summarizeUsage([], range, Date.now());
5898
5944
  }
@@ -5906,12 +5952,10 @@ var AgentEnhancerService = class extends TypertRemoteService {
5906
5952
  }) {
5907
5953
  super(ctx, "agentEnhancer");
5908
5954
  this.models = models;
5909
- this.compactRoute = compactRoute;
5910
5955
  this.usage = usage;
5911
5956
  this.balances = balances;
5912
5957
  }
5913
5958
  models;
5914
- compactRoute;
5915
5959
  usage;
5916
5960
  balances;
5917
5961
  assertOwner() {
@@ -5961,7 +6005,7 @@ var AgentEnhancerService = class extends TypertRemoteService {
5961
6005
  throw new RemoteError("agent-enhancer/failed", "Context inspect failed", { code: "MODEL_FAILED" });
5962
6006
  }
5963
6007
  }
5964
- /** Trigger the official idle `/compact` command (same path as chat `/compact`). */
6008
+ /** Trigger official idle compaction (same seam as chat `/compact`). */
5965
6009
  async compactContext(request, signal) {
5966
6010
  this.assertOwner();
5967
6011
  signal.throwIfAborted();
@@ -5973,16 +6017,18 @@ var AgentEnhancerService = class extends TypertRemoteService {
5973
6017
  }
5974
6018
  try {
5975
6019
  return await withUsageSource("compact", async () => compactContextNow({
5976
- commands: this.ctx.commands,
6020
+ compaction: softService2(this.ctx, "compaction", "compactNow"),
6021
+ commands: softService2(this.ctx, "commands", "execute") ?? this.ctx.commands,
5977
6022
  agent,
5978
6023
  sessionId: request.sessionId,
5979
- signal,
5980
- route: await this.compactRoute(agent.session, signal)
6024
+ signal
5981
6025
  }));
5982
6026
  } catch (error) {
5983
6027
  if (signal.aborted) throw error;
5984
6028
  const code = error instanceof AuxiliaryError ? error.code : "COMPACT_FAILED";
5985
- throw new RemoteError("agent-enhancer/failed", "Context compaction failed", { code });
6029
+ const detail = error instanceof Error ? error.message : String(error);
6030
+ this.ctx.logger.warn(`agent-enhancer compact failed (${code}): ${detail}`);
6031
+ throw new RemoteError("agent-enhancer/failed", detail || "Context compaction failed", { code });
5986
6032
  }
5987
6033
  }
5988
6034
  /** Read-only version probe — same gate policy as `listCatalog` (settings-safe). */
@@ -6116,7 +6162,6 @@ function apply(ctx, config) {
6116
6162
  new AgentEnhancerService(
6117
6163
  ctx,
6118
6164
  models,
6119
- (session, signal) => resolveCompactRouteOverride(ctx, settings(), session, signal),
6120
6165
  {
6121
6166
  async summarize(range) {
6122
6167
  const stored = await usage.listCalls();