@wrongstack/core 0.8.0 → 0.8.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.
- package/dist/{agent-subagent-runner-Bzeueq2J.d.ts → agent-subagent-runner-Cav3yEJM.d.ts} +1 -1
- package/dist/coordination/index.d.ts +6 -6
- package/dist/defaults/index.d.ts +8 -8
- package/dist/defaults/index.js +82 -14
- package/dist/defaults/index.js.map +1 -1
- package/dist/execution/index.d.ts +32 -9
- package/dist/execution/index.js +53 -11
- package/dist/execution/index.js.map +1 -1
- package/dist/extension/index.d.ts +2 -2
- package/dist/{index-BciJeH8g.d.ts → index-oYZeWsuJ.d.ts} +1 -1
- package/dist/index.d.ts +425 -11
- package/dist/index.js +967 -42
- package/dist/index.js.map +1 -1
- package/dist/kernel/index.d.ts +1 -1
- package/dist/{multi-agent-coordinator-tlSWD4cE.d.ts → multi-agent-coordinator-IQKrMfXz.d.ts} +1 -1
- package/dist/{null-fleet-bus-DXEvZKHW.d.ts → null-fleet-bus-sKnVwEd8.d.ts} +2 -2
- package/dist/{permission-policy-D5Gj1o2K.d.ts → permission-policy-BBa1M1xc.d.ts} +10 -1
- package/dist/sdd/index.d.ts +3 -3
- package/dist/{secret-scrubber-DXkhwuka.d.ts → secret-scrubber-C0n1EqrC.d.ts} +1 -1
- package/dist/{secret-scrubber-nI8qjaqW.d.ts → secret-scrubber-CyE1-EMG.d.ts} +1 -1
- package/dist/security/index.d.ts +3 -3
- package/dist/security/index.js +29 -3
- package/dist/security/index.js.map +1 -1
- package/dist/{tool-executor-Cx2ndr0L.d.ts → tool-executor-QwfWnQZ8.d.ts} +1 -1
- package/dist/types/index.d.ts +4 -4
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { c as Agent, f as AgentInput } from './index-
|
|
1
|
+
import { c as Agent, f as AgentInput } from './index-oYZeWsuJ.js';
|
|
2
2
|
import { E as EventBus } from './events-DyhxkstG.js';
|
|
3
3
|
import { n as SubagentConfig, v as TaskSpec, t as SubagentRunner } from './multi-agent-CRMznZmf.js';
|
|
4
4
|
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
export { A as ACP_AGENTS, a as AGENTS_BY_PHASE, b as AGENT_CATALOG, c as ALL_AGENT_DEFINITIONS, d as ALL_FLEET_AGENTS, e as AUDIT_LOG_AGENT, f as AutoExtendCeiling, g as AutoExtendPolicy, B as BUG_HUNTER_AGENT, C as CreateDelegateToolOptions, D as DEFAULT_DIRECTOR_PREAMBLE, h as DEFAULT_SUBAGENT_BASELINE, i as DelegateHost, j as Director, k as DirectorPromptParts, l as DirectorSessionFactory, m as DirectorSessionFactoryOptions, F as FLEET_ROSTER, n as FLEET_ROSTER_BUDGETS, o as FLEET_ROSTER_WITHACP, p as FleetCostCapError, q as FleetManager, r as FleetManagerOptions, s as FleetRosterBudget, t as FleetSpawnBudgetError, I as ICoordinator, u as IFleetManager, N as NULL_FLEET_BUS, R as REFACTOR_PLANNER_AGENT, S as SECURITY_SCANNER_AGENT, v as SubagentPromptParts, w as applyRosterBudget, x as attachAutoExtend, y as composeDirectorPrompt, z as composeSubagentPrompt, E as createDelegateTool, G as getAgentDefinition, H as makeDirectorSessionFactory, J as rosterSummaryFromConfigs } from '../null-fleet-bus-
|
|
2
|
-
import { b as AgentDefinition } from '../multi-agent-coordinator-
|
|
3
|
-
export { T as AGENT_TOOL_PRESETS, A as AgentBudgetTier, a as AgentCapability, c as AgentPhase, D as DEFAULT_DISPATCH_ROLE, d as DefaultMultiAgentCoordinator, e as DispatchCandidate, f as DispatchClassifier, g as DispatchMethod, h as DispatchOptions, i as DispatchResult, H as HEAVY_BUDGET, L as LIGHT_BUDGET, M as MEDIUM_BUDGET, j as MultiAgentCoordinatorOptions, k as dispatchAgent, m as makeLLMClassifier, s as scoreAgents } from '../multi-agent-coordinator-
|
|
1
|
+
export { A as ACP_AGENTS, a as AGENTS_BY_PHASE, b as AGENT_CATALOG, c as ALL_AGENT_DEFINITIONS, d as ALL_FLEET_AGENTS, e as AUDIT_LOG_AGENT, f as AutoExtendCeiling, g as AutoExtendPolicy, B as BUG_HUNTER_AGENT, C as CreateDelegateToolOptions, D as DEFAULT_DIRECTOR_PREAMBLE, h as DEFAULT_SUBAGENT_BASELINE, i as DelegateHost, j as Director, k as DirectorPromptParts, l as DirectorSessionFactory, m as DirectorSessionFactoryOptions, F as FLEET_ROSTER, n as FLEET_ROSTER_BUDGETS, o as FLEET_ROSTER_WITHACP, p as FleetCostCapError, q as FleetManager, r as FleetManagerOptions, s as FleetRosterBudget, t as FleetSpawnBudgetError, I as ICoordinator, u as IFleetManager, N as NULL_FLEET_BUS, R as REFACTOR_PLANNER_AGENT, S as SECURITY_SCANNER_AGENT, v as SubagentPromptParts, w as applyRosterBudget, x as attachAutoExtend, y as composeDirectorPrompt, z as composeSubagentPrompt, E as createDelegateTool, G as getAgentDefinition, H as makeDirectorSessionFactory, J as rosterSummaryFromConfigs } from '../null-fleet-bus-sKnVwEd8.js';
|
|
2
|
+
import { b as AgentDefinition } from '../multi-agent-coordinator-IQKrMfXz.js';
|
|
3
|
+
export { T as AGENT_TOOL_PRESETS, A as AgentBudgetTier, a as AgentCapability, c as AgentPhase, D as DEFAULT_DISPATCH_ROLE, d as DefaultMultiAgentCoordinator, e as DispatchCandidate, f as DispatchClassifier, g as DispatchMethod, h as DispatchOptions, i as DispatchResult, H as HEAVY_BUDGET, L as LIGHT_BUDGET, M as MEDIUM_BUDGET, j as MultiAgentCoordinatorOptions, k as dispatchAgent, m as makeLLMClassifier, s as scoreAgents } from '../multi-agent-coordinator-IQKrMfXz.js';
|
|
4
4
|
export { c as BudgetExceededError, d as BudgetKind, e as BudgetLimits, f as BudgetNegotiationMode, g as BudgetThresholdDecision, h as BudgetThresholdHandler, i as BudgetThresholdSignal, j as BudgetUsage, m as SubagentBudget } from '../multi-agent-CRMznZmf.js';
|
|
5
|
-
export { A as AgentFactory, a as AgentFactoryResult, b as AgentRunnerOptions, F as FleetBus, c as FleetEvent, d as FleetHandler, e as FleetUsage, f as FleetUsageAggregator, S as SubagentUsageSnapshot, m as makeAgentSubagentRunner } from '../agent-subagent-runner-
|
|
5
|
+
export { A as AgentFactory, a as AgentFactoryResult, b as AgentRunnerOptions, F as FleetBus, c as FleetEvent, d as FleetHandler, e as FleetUsage, f as FleetUsageAggregator, S as SubagentUsageSnapshot, m as makeAgentSubagentRunner } from '../agent-subagent-runner-Cav3yEJM.js';
|
|
6
6
|
export { I as InMemoryAgentBridge, a as InMemoryBridgeTransport, c as createMessage } from '../agent-bridge-DPxcUVkn.js';
|
|
7
7
|
import '../context-z2x5gv_V.js';
|
|
8
8
|
import '../director-state-BmYi3DGA.js';
|
|
9
9
|
import '../events-DyhxkstG.js';
|
|
10
10
|
import 'node:events';
|
|
11
|
-
import '../index-
|
|
11
|
+
import '../index-oYZeWsuJ.js';
|
|
12
12
|
import '../logger-DDd5C--Z.js';
|
|
13
13
|
import '../system-prompt-CWA6ml-d.js';
|
|
14
14
|
import '../observability-BhnVLBLS.js';
|
|
15
|
-
import '../secret-scrubber-
|
|
15
|
+
import '../secret-scrubber-CyE1-EMG.js';
|
|
16
16
|
import '../config-Bi4Q0fnz.js';
|
|
17
17
|
import '../models-registry-BcYJDKLm.js';
|
|
18
18
|
|
package/dist/defaults/index.d.ts
CHANGED
|
@@ -2,16 +2,16 @@ export { D as DefaultLogger, a as DefaultLoggerOptions } from '../logger-bOzkF5L
|
|
|
2
2
|
export { A as AbandonedSession, a as AttachmentStoreOptions, C as ConfigLoaderOptions, b as ConfigMigration, c as ConfigMigrationError, d as ConfigSource, D as DEFAULT_CONFIG_MIGRATIONS, e as DefaultAttachmentStore, f as DefaultConfigLoader, g as DefaultConfigStore, h as DefaultMemoryStore, i as DefaultSessionStore, M as MemoryStoreOptions, j as MigrationContext, k as MigrationResult, P as PersistedQueueItem, l as PlanFile, m as PlanItem, n as PlanTemplate, Q as QueueStore, R as RecoveryLock, o as RecoveryLockOptions, S as SessionAnalyzer, p as SessionStoreOptions, T as TodosCheckpointFile, q as addPlanItem, r as attachPlanCheckpoint, s as attachTodosCheckpoint, t as clearPlan, u as deriveTodosFromPlanItem, v as emptyPlan, w as formatPlan, x as formatPlanTemplates, y as getPlanTemplate, z as listPlanTemplates, B as loadPlan, E as loadTodosCheckpoint, F as removePlanItem, G as runConfigMigrations, H as savePlan, I as saveTodosCheckpoint, J as setPlanItemStatus } from '../plan-templates-BnlpEkX8.js';
|
|
3
3
|
export { D as DefaultSessionReader } from '../session-reader-DsadjyF9.js';
|
|
4
4
|
export { D as DirectorStateCheckpoint, a as DirectorStateSnapshot, b as DirectorSubagentState, c as DirectorTaskState, l as loadDirectorState } from '../director-state-BmYi3DGA.js';
|
|
5
|
-
export { D as DefaultSecretScrubber, a as DefaultSecretVault, S as SecretVaultOptions, d as decryptConfigSecrets, e as encryptConfigSecrets, m as migratePlaintextSecrets, r as rewriteConfigEncrypted } from '../secret-scrubber-
|
|
6
|
-
export { A as AutoApprovePermissionPolicy, D as DefaultPermissionPolicy, P as PermissionPolicyOptions } from '../permission-policy-
|
|
7
|
-
export { C as CompactorOptions, a as DefaultErrorHandler, b as DefaultRetryPolicy, H as HybridCompactor, T as ToolExecutor } from '../tool-executor-
|
|
5
|
+
export { D as DefaultSecretScrubber, a as DefaultSecretVault, S as SecretVaultOptions, d as decryptConfigSecrets, e as encryptConfigSecrets, m as migratePlaintextSecrets, r as rewriteConfigEncrypted } from '../secret-scrubber-C0n1EqrC.js';
|
|
6
|
+
export { A as AutoApprovePermissionPolicy, D as DefaultPermissionPolicy, P as PermissionPolicyOptions } from '../permission-policy-BBa1M1xc.js';
|
|
7
|
+
export { C as CompactorOptions, a as DefaultErrorHandler, b as DefaultRetryPolicy, H as HybridCompactor, T as ToolExecutor } from '../tool-executor-QwfWnQZ8.js';
|
|
8
8
|
export { AutoCompactionMiddleware, AutonomousRunner, AutonomousRunnerOptions, AutonomyPromptContributorOptions, DefaultSkillLoader, DoneCheckResult, DoneConditionChecker, EternalAutonomyEngine, EternalAutonomyOptions, EternalEngineState, IntelligentCompactor, IntelligentCompactorOptions, ParallelEngineState, ParallelEternalEngine, ParallelEternalOptions, SelectiveCompactor, SelectiveCompactorOptions, SkillLoaderOptions, buildGoalPreamble, makeAutonomyPromptContributor } from '../execution/index.js';
|
|
9
9
|
import { P as ProviderRunner, R as RunProviderOptions } from '../provider-runner-BrA0XR-l.js';
|
|
10
10
|
import { q as Response } from '../context-z2x5gv_V.js';
|
|
11
|
-
export { a as AGENTS_BY_PHASE, b as AGENT_CATALOG, c as ALL_AGENT_DEFINITIONS, d as ALL_FLEET_AGENTS, e as AUDIT_LOG_AGENT, f as AutoExtendCeiling, g as AutoExtendPolicy, B as BUG_HUNTER_AGENT, C as CreateDelegateToolOptions, D as DEFAULT_DIRECTOR_PREAMBLE, h as DEFAULT_SUBAGENT_BASELINE, i as DelegateHost, j as Director, k as DirectorPromptParts, l as DirectorSessionFactory, m as DirectorSessionFactoryOptions, F as FLEET_ROSTER, n as FLEET_ROSTER_BUDGETS, s as FleetRosterBudget, t as FleetSpawnBudgetError, I as ICoordinator, u as IFleetManager, N as NULL_FLEET_BUS, R as REFACTOR_PLANNER_AGENT, S as SECURITY_SCANNER_AGENT, v as SubagentPromptParts, w as applyRosterBudget, x as attachAutoExtend, y as composeDirectorPrompt, z as composeSubagentPrompt, E as createDelegateTool, G as getAgentDefinition, H as makeDirectorSessionFactory, J as rosterSummaryFromConfigs } from '../null-fleet-bus-
|
|
12
|
-
export { A as AgentBudgetTier, a as AgentCapability, b as AgentDefinition, c as AgentPhase, D as DEFAULT_DISPATCH_ROLE, d as DefaultMultiAgentCoordinator, e as DispatchCandidate, f as DispatchClassifier, g as DispatchMethod, h as DispatchOptions, i as DispatchResult, j as MultiAgentCoordinatorOptions, k as dispatchAgent, m as makeLLMClassifier, s as scoreAgents } from '../multi-agent-coordinator-
|
|
11
|
+
export { a as AGENTS_BY_PHASE, b as AGENT_CATALOG, c as ALL_AGENT_DEFINITIONS, d as ALL_FLEET_AGENTS, e as AUDIT_LOG_AGENT, f as AutoExtendCeiling, g as AutoExtendPolicy, B as BUG_HUNTER_AGENT, C as CreateDelegateToolOptions, D as DEFAULT_DIRECTOR_PREAMBLE, h as DEFAULT_SUBAGENT_BASELINE, i as DelegateHost, j as Director, k as DirectorPromptParts, l as DirectorSessionFactory, m as DirectorSessionFactoryOptions, F as FLEET_ROSTER, n as FLEET_ROSTER_BUDGETS, s as FleetRosterBudget, t as FleetSpawnBudgetError, I as ICoordinator, u as IFleetManager, N as NULL_FLEET_BUS, R as REFACTOR_PLANNER_AGENT, S as SECURITY_SCANNER_AGENT, v as SubagentPromptParts, w as applyRosterBudget, x as attachAutoExtend, y as composeDirectorPrompt, z as composeSubagentPrompt, E as createDelegateTool, G as getAgentDefinition, H as makeDirectorSessionFactory, J as rosterSummaryFromConfigs } from '../null-fleet-bus-sKnVwEd8.js';
|
|
12
|
+
export { A as AgentBudgetTier, a as AgentCapability, b as AgentDefinition, c as AgentPhase, D as DEFAULT_DISPATCH_ROLE, d as DefaultMultiAgentCoordinator, e as DispatchCandidate, f as DispatchClassifier, g as DispatchMethod, h as DispatchOptions, i as DispatchResult, j as MultiAgentCoordinatorOptions, k as dispatchAgent, m as makeLLMClassifier, s as scoreAgents } from '../multi-agent-coordinator-IQKrMfXz.js';
|
|
13
13
|
export { c as BudgetExceededError, d as BudgetKind, e as BudgetLimits, j as BudgetUsage, m as SubagentBudget } from '../multi-agent-CRMznZmf.js';
|
|
14
|
-
export { A as AgentFactory, a as AgentFactoryResult, b as AgentRunnerOptions, F as FleetBus, c as FleetEvent, d as FleetHandler, e as FleetUsage, f as FleetUsageAggregator, S as SubagentUsageSnapshot, m as makeAgentSubagentRunner } from '../agent-subagent-runner-
|
|
14
|
+
export { A as AgentFactory, a as AgentFactoryResult, b as AgentRunnerOptions, F as FleetBus, c as FleetEvent, d as FleetHandler, e as FleetUsage, f as FleetUsageAggregator, S as SubagentUsageSnapshot, m as makeAgentSubagentRunner } from '../agent-subagent-runner-Cav3yEJM.js';
|
|
15
15
|
export { I as InMemoryAgentBridge, a as InMemoryBridgeTransport, c as createMessage } from '../agent-bridge-DPxcUVkn.js';
|
|
16
16
|
export { D as DefaultModelsRegistry, a as DefaultModelsRegistryOptions, c as classifyFamily } from '../models-registry-OG_30xqZ.js';
|
|
17
17
|
export { DefaultModeStore, LLMSelector, LLMSelectorOptions, ModeLoaderOptions, loadProjectModes, loadUserModes } from '../models/index.js';
|
|
@@ -26,11 +26,11 @@ import '../wstack-paths-gCrJ631C.js';
|
|
|
26
26
|
import '../config-Bi4Q0fnz.js';
|
|
27
27
|
import '../models-registry-BcYJDKLm.js';
|
|
28
28
|
import '../secret-vault-DoISxaKO.js';
|
|
29
|
-
import '../secret-scrubber-
|
|
29
|
+
import '../secret-scrubber-CyE1-EMG.js';
|
|
30
30
|
import '../input-reader-E-ffP2ee.js';
|
|
31
31
|
import '../compactor-Mw7-rNyb.js';
|
|
32
32
|
import '../retry-policy-OwtKNxo8.js';
|
|
33
|
-
import '../index-
|
|
33
|
+
import '../index-oYZeWsuJ.js';
|
|
34
34
|
import '../system-prompt-CWA6ml-d.js';
|
|
35
35
|
import '../observability-BhnVLBLS.js';
|
|
36
36
|
import '../selector-DkvgYVS4.js';
|
package/dist/defaults/index.js
CHANGED
|
@@ -3213,10 +3213,36 @@ var DefaultPermissionPolicy = class {
|
|
|
3213
3213
|
return void 0;
|
|
3214
3214
|
}
|
|
3215
3215
|
};
|
|
3216
|
-
var AutoApprovePermissionPolicy = class {
|
|
3216
|
+
var AutoApprovePermissionPolicy = class _AutoApprovePermissionPolicy {
|
|
3217
|
+
/**
|
|
3218
|
+
* Tools that are too dangerous to auto-approve even in a delegated
|
|
3219
|
+
* subagent context. Subagents run non-interactively under a director
|
|
3220
|
+
* and cannot answer prompts, but inherited authorization does not
|
|
3221
|
+
* imply blanket permission for destructive or privilege-escalating
|
|
3222
|
+
* operations. These tools remain at their declared `permission`
|
|
3223
|
+
* level so the leader must explicitly allow them per-spawn.
|
|
3224
|
+
*/
|
|
3225
|
+
static DENY = /* @__PURE__ */ new Set([
|
|
3226
|
+
"bash",
|
|
3227
|
+
// arbitrary shell — use exec for constrained shell
|
|
3228
|
+
"write",
|
|
3229
|
+
// arbitrary file write
|
|
3230
|
+
"scaffold",
|
|
3231
|
+
// arbitrary file generation outside project root
|
|
3232
|
+
"patch",
|
|
3233
|
+
// arbitrary diff application
|
|
3234
|
+
"install",
|
|
3235
|
+
// installs from arbitrary package sources
|
|
3236
|
+
"exec"
|
|
3237
|
+
// restricted shell but with arbitrary command args
|
|
3238
|
+
]);
|
|
3217
3239
|
async evaluate(tool) {
|
|
3218
|
-
if (tool.permission === "deny") {
|
|
3219
|
-
return {
|
|
3240
|
+
if (tool.permission === "deny" || _AutoApprovePermissionPolicy.DENY.has(tool.name)) {
|
|
3241
|
+
return {
|
|
3242
|
+
permission: "deny",
|
|
3243
|
+
source: "subagent_guard",
|
|
3244
|
+
reason: _AutoApprovePermissionPolicy.DENY.has(tool.name) ? `tool ${tool.name} is not auto-approved for subagents \u2014 ask the leader to allow it explicitly` : "tool default deny"
|
|
3245
|
+
};
|
|
3220
3246
|
}
|
|
3221
3247
|
return { permission: "auto", source: "yolo" };
|
|
3222
3248
|
}
|
|
@@ -4801,6 +4827,7 @@ Summarize the following message range:`;
|
|
|
4801
4827
|
};
|
|
4802
4828
|
|
|
4803
4829
|
// src/execution/auto-compaction-middleware.ts
|
|
4830
|
+
var LEVEL_RANK2 = { warn: 0, soft: 1, hard: 2 };
|
|
4804
4831
|
var AutoCompactionMiddleware = class _AutoCompactionMiddleware {
|
|
4805
4832
|
name = "AutoCompaction";
|
|
4806
4833
|
compactor;
|
|
@@ -4815,12 +4842,28 @@ var AutoCompactionMiddleware = class _AutoCompactionMiddleware {
|
|
|
4815
4842
|
failureMode;
|
|
4816
4843
|
policyProvider;
|
|
4817
4844
|
/**
|
|
4818
|
-
*
|
|
4819
|
-
*
|
|
4820
|
-
*
|
|
4821
|
-
*
|
|
4845
|
+
* Calibration factor applied to the estimator output. The estimator is now
|
|
4846
|
+
* expected to already include messages + system prompt + tool definitions
|
|
4847
|
+
* (see `estimateRequestTokens.total`), so no overhead boost is needed. Kept
|
|
4848
|
+
* as a constant so a future calibration against real provider tokenization
|
|
4849
|
+
* (BPE vs the chars/3.5 rough estimator) can dial this without touching the
|
|
4850
|
+
* threshold-check math.
|
|
4851
|
+
*
|
|
4852
|
+
* Historical note: was 1.3 when the estimator only counted messages — that
|
|
4853
|
+
* double-counted system+tools once the estimator was upgraded, firing
|
|
4854
|
+
* compaction ~30% earlier than intended (e.g. real 56% load showed as 73%).
|
|
4855
|
+
*/
|
|
4856
|
+
static OVERHEAD_FACTOR = 1;
|
|
4857
|
+
/**
|
|
4858
|
+
* Once a compaction attempt reduces nothing (preserveK protects everything,
|
|
4859
|
+
* no oversized tool_results remain to elide), retrying on every iteration
|
|
4860
|
+
* just spams `compaction.fired` events without making progress. We remember
|
|
4861
|
+
* the no-op and skip until either the pressure level escalates or context
|
|
4862
|
+
* has grown by at least this many tokens since the failed attempt.
|
|
4822
4863
|
*/
|
|
4823
|
-
static
|
|
4864
|
+
static NOOP_RETRY_DELTA_TOKENS = 2e3;
|
|
4865
|
+
/** Tracks the most recent no-op attempt so we can avoid re-firing per turn. */
|
|
4866
|
+
lastNoopAttempt = null;
|
|
4824
4867
|
/**
|
|
4825
4868
|
* @param compactor Compactor to use for compaction.
|
|
4826
4869
|
* @param maxContext Provider's max context window in tokens.
|
|
@@ -4862,19 +4905,44 @@ var AutoCompactionMiddleware = class _AutoCompactionMiddleware {
|
|
|
4862
4905
|
hard: this.hardThreshold
|
|
4863
4906
|
};
|
|
4864
4907
|
const aggressiveOn = policy?.aggressiveOn ?? this.aggressiveOn;
|
|
4865
|
-
|
|
4866
|
-
|
|
4867
|
-
|
|
4868
|
-
|
|
4869
|
-
} else if (load >= thresholds.warn) {
|
|
4870
|
-
await this.compact(ctx, aggressiveOn === "warn", { level: "warn", tokens, load });
|
|
4908
|
+
const level = load >= thresholds.hard ? "hard" : load >= thresholds.soft ? "soft" : load >= thresholds.warn ? "warn" : null;
|
|
4909
|
+
if (!level) {
|
|
4910
|
+
this.lastNoopAttempt = null;
|
|
4911
|
+
return next(ctx);
|
|
4871
4912
|
}
|
|
4913
|
+
if (this.shouldSkipNoopRetry(level, tokens)) {
|
|
4914
|
+
return next(ctx);
|
|
4915
|
+
}
|
|
4916
|
+
const aggressive = level === "hard" ? true : level === "soft" ? aggressiveOn !== "hard" : aggressiveOn === "warn";
|
|
4917
|
+
await this.compact(ctx, aggressive, { level, tokens, load });
|
|
4872
4918
|
return next(ctx);
|
|
4873
4919
|
};
|
|
4874
4920
|
}
|
|
4921
|
+
/**
|
|
4922
|
+
* Returns true when the previous compaction at the same or higher pressure
|
|
4923
|
+
* level reduced nothing and context has not grown materially since. Prevents
|
|
4924
|
+
* a stuck preserveK window from spamming compaction events every iteration.
|
|
4925
|
+
*/
|
|
4926
|
+
shouldSkipNoopRetry(level, tokens) {
|
|
4927
|
+
const stuck = this.lastNoopAttempt;
|
|
4928
|
+
if (!stuck) return false;
|
|
4929
|
+
if (LEVEL_RANK2[level] > LEVEL_RANK2[stuck.level]) return false;
|
|
4930
|
+
const delta = tokens - stuck.tokens;
|
|
4931
|
+
return delta < _AutoCompactionMiddleware.NOOP_RETRY_DELTA_TOKENS;
|
|
4932
|
+
}
|
|
4933
|
+
recordAttempt(level, tokens, report) {
|
|
4934
|
+
const reduced = report.before > report.after;
|
|
4935
|
+
const repaired = !!report.repaired;
|
|
4936
|
+
if (reduced || repaired) {
|
|
4937
|
+
this.lastNoopAttempt = null;
|
|
4938
|
+
} else {
|
|
4939
|
+
this.lastNoopAttempt = { level, tokens };
|
|
4940
|
+
}
|
|
4941
|
+
}
|
|
4875
4942
|
async compact(ctx, aggressive, pressure) {
|
|
4876
4943
|
try {
|
|
4877
4944
|
const report = await this.compactor.compact(ctx, { aggressive });
|
|
4945
|
+
this.recordAttempt(pressure.level, pressure.tokens, report);
|
|
4878
4946
|
this.events?.emit("compaction.fired", {
|
|
4879
4947
|
level: pressure.level,
|
|
4880
4948
|
tokens: pressure.tokens,
|