@wrongstack/core 0.109.1 → 0.141.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/dist/{agent-bridge-mOxbpFcg.d.ts → agent-bridge-r9y6gdn4.d.ts} +1 -1
- package/dist/{agent-subagent-runner-DukQLUcS.d.ts → agent-subagent-runner-1GeQE_L0.d.ts} +7 -8
- package/dist/{brain-Dfv4Y82E.d.ts → brain-Cp_3GIS2.d.ts} +14 -3
- package/dist/{compactor-DXLxLcmU.d.ts → compactor-BueGt7LG.d.ts} +9 -1
- package/dist/{config-BSU-6vah.d.ts → config-BaVThgnT.d.ts} +104 -3
- package/dist/{context-CNRYfhUv.d.ts → context-C7G_MtLV.d.ts} +38 -1
- package/dist/coordination/index.d.ts +12 -13
- package/dist/coordination/index.js +229 -17
- package/dist/coordination/index.js.map +1 -1
- package/dist/defaults/index.d.ts +26 -27
- package/dist/defaults/index.js +886 -721
- package/dist/defaults/index.js.map +1 -1
- package/dist/execution/index.d.ts +15 -16
- package/dist/execution/index.js +535 -322
- package/dist/execution/index.js.map +1 -1
- package/dist/extension/index.d.ts +6 -7
- package/dist/{goal-preamble-CI8lxeY1.d.ts → goal-preamble-iuIUTQwk.d.ts} +48 -18
- package/dist/{index-BWRN6wOb.d.ts → index-BZdezm3g.d.ts} +9 -10
- package/dist/{index-DIKEcfgC.d.ts → index-CPweVoFM.d.ts} +7 -6
- package/dist/index.d.ts +51 -52
- package/dist/index.js +752 -545
- package/dist/index.js.map +1 -1
- package/dist/infrastructure/index.d.ts +6 -7
- package/dist/infrastructure/index.js +64 -19
- package/dist/infrastructure/index.js.map +1 -1
- package/dist/kernel/index.d.ts +10 -11
- package/dist/kernel/index.js.map +1 -1
- package/dist/llm-selector-CP72f1lC.d.ts +58 -0
- package/dist/{mcp-servers-CXCsANdY.d.ts → mcp-servers-Bl5LTvQg.d.ts} +3 -3
- package/dist/{mode-ARA3HrkY.d.ts → mode-CZlO9iU1.d.ts} +1 -1
- package/dist/models/index.d.ts +157 -53
- package/dist/models/index.js +475 -20
- package/dist/models/index.js.map +1 -1
- package/dist/{models-registry-DU64QxQa.d.ts → models-registry-D90K9UnM.d.ts} +1 -1
- package/dist/{multi-agent-coordinator-51LvnXkD.d.ts → multi-agent-coordinator-QWEzJDlm.d.ts} +1 -1
- package/dist/{null-fleet-bus-D09hMzFQ.d.ts → null-fleet-bus-BUyfqh23.d.ts} +13 -10
- package/dist/observability/index.d.ts +2 -2
- package/dist/{parallel-eternal-engine-B2CbsKpc.d.ts → parallel-eternal-engine-Dj2SYzha.d.ts} +24 -11
- package/dist/{path-resolver-DDJiMAtX.d.ts → path-resolver-DRjQBkoO.d.ts} +3 -3
- package/dist/{permission-BDv7z0mk.d.ts → permission-B7nKnEvQ.d.ts} +1 -1
- package/dist/{permission-policy-dF74EpDp.d.ts → permission-policy-8-6zBmfA.d.ts} +2 -13
- package/dist/{pipeline-BqiA_UMr.d.ts → pipeline-BG7UgbDc.d.ts} +2 -2
- package/dist/{plan-templates-BdDxl9cI.d.ts → plan-templates-CkKNPU3I.d.ts} +6 -6
- package/dist/{provider-runner-BUunikwY.d.ts → provider-runner-BNpuIyOL.d.ts} +3 -3
- package/dist/{retry-policy-BcmuT_V0.d.ts → retry-policy-rutAfVeR.d.ts} +1 -1
- package/dist/sdd/index.d.ts +8 -9
- package/dist/sdd/index.js +208 -1
- package/dist/sdd/index.js.map +1 -1
- package/dist/{secret-vault-DrOhc2i5.d.ts → secret-vault-BTcC_T5v.d.ts} +3 -2
- package/dist/security/index.d.ts +5 -7
- package/dist/security/index.js +4 -35
- package/dist/security/index.js.map +1 -1
- package/dist/{selector-C7wcdqMA.d.ts → selector-4vDFZKt3.d.ts} +1 -1
- package/dist/{session-event-bridge-BpJ5trO9.d.ts → session-event-bridge-DWlvglC2.d.ts} +2 -2
- package/dist/{session-reader-DDz1Ek4V.d.ts → session-reader-BAtCxdaw.d.ts} +1 -1
- package/dist/storage/index.d.ts +14 -15
- package/dist/storage/index.js +140 -134
- package/dist/storage/index.js.map +1 -1
- package/dist/types/index.d.ts +19 -20
- package/dist/types/index.js +186 -102
- package/dist/types/index.js.map +1 -1
- package/dist/utils/index.d.ts +38 -15
- package/dist/utils/index.js +62 -33
- package/dist/utils/index.js.map +1 -1
- package/dist/{wstack-paths-_lqjzErq.d.ts → wstack-paths-DD50Omgn.d.ts} +3 -0
- package/package.json +2 -2
- package/dist/models-registry-B6_KfS65.d.ts +0 -95
package/dist/types/index.d.ts
CHANGED
|
@@ -1,35 +1,34 @@
|
|
|
1
|
-
export { A as AgentError, k as Capabilities, u as ConfigError, g as ContentBlock, E as ERROR_CODES, w as ErrorCode, x as ErrorSeverity, y as ErrorSubsystem, F as FileSnapshot, z as FsError, I as ImageBlock, J as JSONSchema, M as Message, B as MessageRole, f as Permission, D as PluginError, P as Provider, e as ProviderError, G as ProviderErrorBody, R as Request, b as Response, p as ResumedSession, K as RiskTier, q as SessionData, N as SessionError, S as SessionEvent, h as SessionMetadata, i as SessionStore, r as SessionSummary, a as SessionWriter, V as StopReason, W as StreamEvent, l as TextBlock,
|
|
2
|
-
export { P as ProviderRunner, R as RunProviderOptions } from '../provider-runner-
|
|
3
|
-
export { A as AutonomyConfig,
|
|
4
|
-
export { a as CompactReport, C as Compactor } from '../compactor-
|
|
5
|
-
export { a as PermissionDecision, P as PermissionPolicy, T as TrustPolicy } from '../permission-
|
|
1
|
+
export { A as AgentError, k as Capabilities, u as ConfigError, g as ContentBlock, E as ERROR_CODES, w as ErrorCode, x as ErrorSeverity, y as ErrorSubsystem, F as FileSnapshot, z as FsError, I as ImageBlock, J as JSONSchema, M as Message, B as MessageRole, f as Permission, D as PluginError, P as Provider, e as ProviderError, G as ProviderErrorBody, R as Request, b as Response, p as ResumedSession, K as RiskTier, q as SessionData, N as SessionError, S as SessionEvent, h as SessionMetadata, i as SessionStore, r as SessionSummary, a as SessionWriter, V as StopReason, W as StreamEvent, X as StreamHangError, l as TextBlock, Y as ThinkingBlock, T as Tool, Z as ToolCallContext, _ as ToolError, $ as ToolFinalEvent, j as ToolProgressEvent, n as ToolResultBlock, a0 as ToolStreamEvent, m as ToolUseBlock, U as Usage, a1 as WrongStackError, a2 as asBlocks, a3 as asText, a5 as isAgentError, a6 as isConfigError, a7 as isFsError, a8 as isImageBlock, a9 as isPluginError, aa as isSessionError, ab as isTextBlock, ac as isThinkingBlock, ad as isToolError, ae as isToolResultBlock, af as isToolUseBlock, ag as isWrongStackError, ah as toWrongStackError } from '../context-C7G_MtLV.js';
|
|
2
|
+
export { P as ProviderRunner, R as RunProviderOptions } from '../provider-runner-BNpuIyOL.js';
|
|
3
|
+
export { A as AutonomyConfig, n as CONTEXT_WINDOW_MODES, h as Config, j as ConfigLoader, i as ConfigStore, o as ContextConfig, C as ContextWindowAggressiveOn, p as ContextWindowConfigLike, q as ContextWindowMode, r as ContextWindowModeId, g as ContextWindowPolicy, s as ContextWindowThresholds, t as CustomModelDefinition, D as DEFAULT_CONTEXT_WINDOW_MODE_ID, F as FeaturesConfig, f as HookEntry, H as HookEvent, l as HookInput, e as HookMatcher, m as HookOutcome, I as InProcessHook, u as IndexingConfig, L as LaunchConfig, v as LogConfig, c as MCPServerConfig, d as ModelMatrixEntry, x as PluginConfig, y as ProviderApiKey, P as ProviderConfig, z as SessionLoggingConfig, S as ShellHook, B as SyncCategory, k as SyncConfig, T as ToolsConfig, E as formatContextWindowModeList, G as getContextWindowMode, J as isContextWindowModeId, K as listContextWindowModes, N as resolveContextWindowPolicy } from '../config-BaVThgnT.js';
|
|
4
|
+
export { a as CompactReport, C as Compactor } from '../compactor-BueGt7LG.js';
|
|
5
|
+
export { a as PermissionDecision, P as PermissionPolicy, T as TrustPolicy } from '../permission-B7nKnEvQ.js';
|
|
6
6
|
export { C as CheckpointInfo, R as RewindResult, a as RewindResultExtended, S as SessionRewinder } from '../session-rewinder-C9HnMkhP.js';
|
|
7
|
-
export { a as AddAttachmentInput, c as Attachment, d as AttachmentKind, e as AttachmentMeta, b as AttachmentRef, A as AttachmentStore, D as DefaultSessionReader } from '../session-reader-
|
|
7
|
+
export { a as AddAttachmentInput, c as Attachment, d as AttachmentKind, e as AttachmentMeta, b as AttachmentRef, A as AttachmentStore, D as DefaultSessionReader } from '../session-reader-BAtCxdaw.js';
|
|
8
8
|
export { D as DEFAULT_AUTONOMY_CONFIG, a as DEFAULT_CONTEXT_CONFIG, b as DEFAULT_SESSION_LOGGING_CONFIG, c as DEFAULT_SESSION_PRUNE_DAYS, d as DEFAULT_TOOLS_CONFIG } from '../default-config-CXsDvOmP.js';
|
|
9
|
-
export { D as DefaultSecretScrubber, a as DefaultSecretVault, S as SecretVaultOptions, d as decryptConfigSecrets, e as encryptConfigSecrets, m as migratePlaintextSecrets, r as rewriteConfigEncrypted } from '../secret-vault-
|
|
9
|
+
export { D as DefaultSecretScrubber, a as DefaultSecretVault, S as SecretVaultOptions, d as decryptConfigSecrets, e as encryptConfigSecrets, i as isSecretField, m as migratePlaintextSecrets, r as rewriteConfigEncrypted } from '../secret-vault-BTcC_T5v.js';
|
|
10
10
|
export { D as DefaultLogger, a as DefaultLoggerOptions } from '../logger-B9J5puGM.js';
|
|
11
|
-
export { D as DefaultPathResolver, a as DefaultTokenCounter } from '../path-resolver-
|
|
12
|
-
export { p as MEMORY_TYPE_LABELS, q as MemoryClearedPayload, r as MemoryConsolidatedPayload, k as MemoryEntry, s as MemoryForgottenPayload, t as MemoryPriority, m as MemoryRelevanceContext, u as MemoryRememberedPayload, M as MemoryScope, l as MemoryStore, v as MemoryType, S as ScoredEntry } from '../brain-
|
|
13
|
-
import { I as IterationStage, f as ParallelIterationStage } from '../parallel-eternal-engine-
|
|
14
|
-
export { C as CompactorOptions, g as DEFAULT_RECOVERY_STRATEGIES, D as DefaultErrorHandler, a as DefaultRetryPolicy, H as HybridCompactor, R as RecoveryStrategy, T as ToolExecutor, h as buildRecoveryStrategies } from '../parallel-eternal-engine-
|
|
11
|
+
export { D as DefaultPathResolver, a as DefaultTokenCounter } from '../path-resolver-DRjQBkoO.js';
|
|
12
|
+
export { p as MEMORY_TYPE_LABELS, q as MemoryClearedPayload, r as MemoryConsolidatedPayload, k as MemoryEntry, s as MemoryForgottenPayload, t as MemoryPriority, m as MemoryRelevanceContext, u as MemoryRememberedPayload, M as MemoryScope, l as MemoryStore, v as MemoryType, S as ScoredEntry } from '../brain-Cp_3GIS2.js';
|
|
13
|
+
import { I as IterationStage, f as ParallelIterationStage } from '../parallel-eternal-engine-Dj2SYzha.js';
|
|
14
|
+
export { C as CompactorOptions, g as DEFAULT_RECOVERY_STRATEGIES, D as DefaultErrorHandler, a as DefaultRetryPolicy, H as HybridCompactor, R as RecoveryStrategy, T as ToolExecutor, h as buildRecoveryStrategies } from '../parallel-eternal-engine-Dj2SYzha.js';
|
|
15
15
|
export { b as SkillEntry, S as SkillLoader, a as SkillManifest } from '../skill-Bj6Ezqb8.js';
|
|
16
|
-
export { B as BuildContext, b as ModelCapabilities, a as Renderer, S as SystemPromptBuilder } from '../pipeline-
|
|
16
|
+
export { B as BuildContext, b as ModelCapabilities, a as Renderer, S as SystemPromptBuilder } from '../pipeline-BG7UgbDc.js';
|
|
17
17
|
export { I as InputReader, P as PromptOption } from '../input-reader-E-ffP2ee.js';
|
|
18
|
-
export { O as CoordinatorEvents, C as CoordinatorStatus, D as DoneCondition, I as MCPRegistryView, L as MetricsSinkView, c as MultiAgentConfig, M as MultiAgentCoordinator, N as Plugin, P as PluginAPI, Q as PluginCapabilities, R as PluginDependency, E as PluginPipelines, _ as ProviderFactory, H as ProviderRegistryView, K as SessionWriterView, z as SlashCommand, J as SlashCommandRegistryView, e as SpawnResult, S as SubagentConfig, U as SubagentContext, V as SubagentError, W as SubagentErrorKind, X as SubagentRunContext, Y as SubagentRunOutcome, d as SubagentRunner, Z as TaskDelegation, f as TaskResult, T as TaskSpec, G as ToolRegistryView } from '../agent-subagent-runner-
|
|
19
|
-
export { D as DefaultModelsRegistry, a as DefaultModelsRegistryOptions, c as classifyFamily } from '../models-registry-
|
|
20
|
-
export { D as DEFAULT_MODES,
|
|
21
|
-
export { I as InMemoryAgentBridge, a as InMemoryBridgeTransport, c as createMessage } from '../agent-bridge-
|
|
18
|
+
export { O as CoordinatorEvents, C as CoordinatorStatus, D as DoneCondition, I as MCPRegistryView, L as MetricsSinkView, c as MultiAgentConfig, M as MultiAgentCoordinator, N as Plugin, P as PluginAPI, Q as PluginCapabilities, R as PluginDependency, E as PluginPipelines, _ as ProviderFactory, H as ProviderRegistryView, K as SessionWriterView, z as SlashCommand, J as SlashCommandRegistryView, e as SpawnResult, S as SubagentConfig, U as SubagentContext, V as SubagentError, W as SubagentErrorKind, X as SubagentRunContext, Y as SubagentRunOutcome, d as SubagentRunner, Z as TaskDelegation, f as TaskResult, T as TaskSpec, G as ToolRegistryView } from '../agent-subagent-runner-1GeQE_L0.js';
|
|
19
|
+
export { D as DefaultModelsRegistry, a as DefaultModelsRegistryOptions, c as classifyFamily } from '../models-registry-D90K9UnM.js';
|
|
20
|
+
export { D as DEFAULT_MODES, b as Mode, a as ModeConfig, c as ModeManifest, M as ModeStore } from '../mode-CZlO9iU1.js';
|
|
21
|
+
export { I as InMemoryAgentBridge, a as InMemoryBridgeTransport, c as createMessage } from '../agent-bridge-r9y6gdn4.js';
|
|
22
22
|
export { D as DEFAULT_SPEC_TEMPLATE, S as SpecAnalysis, a as SpecApiEndpoint, b as SpecRequirement, c as SpecSection, d as SpecSectionType, e as SpecStatus, f as SpecTemplate, g as SpecValidationResult, h as Specification } from '../spec-TBi3Jr6T.js';
|
|
23
23
|
export { C as CriticalPathResult, f as TaskAssignment, g as TaskDependency, h as TaskEdge, i as TaskFilter, d as TaskGraph, e as TaskNode, a as TaskPriority, c as TaskProgress, j as TaskSort, b as TaskStatus, T as TaskType, k as computeTaskProgress, l as findCriticalPath, t as topologicalSort } from '../task-graph-u1q9Jkyk.js';
|
|
24
24
|
export { A as AggregateHealth, a as HealthCheck, b as HealthCheckResult, H as HealthRegistry, c as HealthStatus, d as MetricLabels, e as MetricSeries, M as MetricsSink, f as MetricsSnapshot, S as Span, T as Tracer } from '../observability-D-HZN_mF.js';
|
|
25
|
-
export { S as SystemPromptContributor } from '../index-
|
|
25
|
+
export { S as SystemPromptContributor } from '../index-CPweVoFM.js';
|
|
26
26
|
import '../logger-B63L5bTg.js';
|
|
27
|
-
import '../retry-policy-
|
|
28
|
-
import '../models-registry-B6_KfS65.js';
|
|
27
|
+
import '../retry-policy-rutAfVeR.js';
|
|
29
28
|
import '../secret-vault-DoISxaKO.js';
|
|
30
29
|
import '../path-resolver-CPRj4bFY.js';
|
|
31
30
|
import '../goal-store-CV9Yz2X_.js';
|
|
32
|
-
import '../multi-agent-coordinator-
|
|
31
|
+
import '../multi-agent-coordinator-QWEzJDlm.js';
|
|
33
32
|
import 'node:events';
|
|
34
33
|
|
|
35
34
|
/** Union of serial and parallel autonomy engine stage types (from EternalAutonomyEngine / ParallelEternalEngine). */
|
package/dist/types/index.js
CHANGED
|
@@ -291,6 +291,39 @@ function describeStatus(status, type) {
|
|
|
291
291
|
function truncate(s, n) {
|
|
292
292
|
return s.length <= n ? s : `${s.slice(0, n - 1)}\u2026`;
|
|
293
293
|
}
|
|
294
|
+
var StreamHangError = class extends ProviderError {
|
|
295
|
+
/** Name of the provider that hung, e.g. "zai", "anthropic". */
|
|
296
|
+
hungProviderId;
|
|
297
|
+
/** Model that was being called when the hang occurred. */
|
|
298
|
+
hungModel;
|
|
299
|
+
/** How long (ms) we waited for the next chunk before declaring a hang. */
|
|
300
|
+
hangTimeoutMs;
|
|
301
|
+
/** How many bytes were received before the hang. */
|
|
302
|
+
bytesReceived;
|
|
303
|
+
/** Elapsed time (ms) from the start of the stream until the hang. */
|
|
304
|
+
elapsedMs;
|
|
305
|
+
constructor(opts) {
|
|
306
|
+
super(
|
|
307
|
+
`Stream hang: ${opts.providerId}/${opts.model} \u2014 no data for ${opts.hangTimeoutMs}ms after ${opts.bytesReceived} bytes (${opts.elapsedMs}ms elapsed)`,
|
|
308
|
+
599,
|
|
309
|
+
true,
|
|
310
|
+
// always retryable
|
|
311
|
+
opts.providerId,
|
|
312
|
+
{
|
|
313
|
+
body: {
|
|
314
|
+
message: `Stream stalled after ${opts.elapsedMs}ms, ${opts.bytesReceived} bytes received`
|
|
315
|
+
},
|
|
316
|
+
cause: opts.cause
|
|
317
|
+
}
|
|
318
|
+
);
|
|
319
|
+
this.name = "StreamHangError";
|
|
320
|
+
this.hungProviderId = opts.providerId;
|
|
321
|
+
this.hungModel = opts.model;
|
|
322
|
+
this.hangTimeoutMs = opts.hangTimeoutMs;
|
|
323
|
+
this.bytesReceived = opts.bytesReceived;
|
|
324
|
+
this.elapsedMs = opts.elapsedMs;
|
|
325
|
+
}
|
|
326
|
+
};
|
|
294
327
|
function providerStatusToCode(status, type) {
|
|
295
328
|
if (status === 0) return ERROR_CODES.PROVIDER_NETWORK_ERROR;
|
|
296
329
|
if (type === "rate_limit_error" || status === 429) return ERROR_CODES.PROVIDER_RATE_LIMITED;
|
|
@@ -912,6 +945,16 @@ function expectDefined(value, label) {
|
|
|
912
945
|
|
|
913
946
|
// src/utils/token-estimate.ts
|
|
914
947
|
var RoughTokenEstimate = (text, charsPerToken = 3.5) => Math.max(1, Math.ceil(text.length / charsPerToken));
|
|
948
|
+
var CALIBRATION_GLOBAL_KEY = "__global__";
|
|
949
|
+
var _cals = /* @__PURE__ */ new Map();
|
|
950
|
+
function calState(key) {
|
|
951
|
+
let state = _cals.get(key);
|
|
952
|
+
if (!state) {
|
|
953
|
+
state = { ratio: 1, count: 0, prevEst: 0 };
|
|
954
|
+
_cals.set(key, state);
|
|
955
|
+
}
|
|
956
|
+
return state;
|
|
957
|
+
}
|
|
915
958
|
var ESTIMATE_CACHE = /* @__PURE__ */ new Map();
|
|
916
959
|
var ESTIMATE_CACHE_MAX_SIZE = 1e4;
|
|
917
960
|
function getCachedEstimate(key, compute) {
|
|
@@ -943,10 +986,25 @@ function estimateToolResultTokens(content) {
|
|
|
943
986
|
function estimateTextTokens(text) {
|
|
944
987
|
return RoughTokenEstimate(text);
|
|
945
988
|
}
|
|
989
|
+
function estimateMessageTokens(messages) {
|
|
990
|
+
let total = 0;
|
|
991
|
+
for (const m of messages) {
|
|
992
|
+
if (typeof m.content === "string") {
|
|
993
|
+
total += estimateTextTokens(m.content);
|
|
994
|
+
} else {
|
|
995
|
+
for (const b of m.content) {
|
|
996
|
+
if (b.type === "text") total += estimateTextTokens(b.text);
|
|
997
|
+
else if (b.type === "tool_use") total += estimateToolInputTokens(b.input);
|
|
998
|
+
else if (b.type === "tool_result") total += estimateToolResultTokens(b.content);
|
|
999
|
+
}
|
|
1000
|
+
}
|
|
1001
|
+
}
|
|
1002
|
+
return total;
|
|
1003
|
+
}
|
|
946
1004
|
function estimateToolDefTokens(tool) {
|
|
947
1005
|
return RoughTokenEstimate(tool.name) + RoughTokenEstimate(tool.description ?? "") + RoughTokenEstimate(JSON.stringify(tool.inputSchema));
|
|
948
1006
|
}
|
|
949
|
-
function estimateRequestTokens(messages, systemPrompt, tools) {
|
|
1007
|
+
function estimateRequestTokens(messages, systemPrompt, tools, calibrationKey = CALIBRATION_GLOBAL_KEY) {
|
|
950
1008
|
let messagesTokens = 0;
|
|
951
1009
|
if (typeof messages === "string") {
|
|
952
1010
|
messagesTokens = RoughTokenEstimate(messages);
|
|
@@ -985,6 +1043,7 @@ function estimateRequestTokens(messages, systemPrompt, tools) {
|
|
|
985
1043
|
toolsTokens += estimateToolDefTokens(t);
|
|
986
1044
|
}
|
|
987
1045
|
const total = messagesTokens + systemTokens + toolsTokens;
|
|
1046
|
+
calState(calibrationKey).prevEst = total;
|
|
988
1047
|
return {
|
|
989
1048
|
messages: messagesTokens,
|
|
990
1049
|
systemPrompt: systemTokens,
|
|
@@ -1085,34 +1144,121 @@ function isEmptyMessage(msg) {
|
|
|
1085
1144
|
return msg.content.length === 0;
|
|
1086
1145
|
}
|
|
1087
1146
|
|
|
1147
|
+
// src/execution/compaction-core.ts
|
|
1148
|
+
var estimateMessages = estimateMessageTokens;
|
|
1149
|
+
function hasTextContent(m) {
|
|
1150
|
+
if (typeof m.content === "string") return m.content.trim().length > 0;
|
|
1151
|
+
return m.content.some((b) => b.type === "text" && b.text.trim().length > 0);
|
|
1152
|
+
}
|
|
1153
|
+
function findPreserveStart(messages, preserveK) {
|
|
1154
|
+
let pairCount = 0;
|
|
1155
|
+
let preserveStart = messages.length;
|
|
1156
|
+
for (let i = messages.length - 1; i >= 0 && pairCount < preserveK; i--) {
|
|
1157
|
+
const m = messages[i];
|
|
1158
|
+
if (!m) continue;
|
|
1159
|
+
if (m.role === "user" || m.role === "assistant") {
|
|
1160
|
+
pairCount++;
|
|
1161
|
+
preserveStart = i;
|
|
1162
|
+
}
|
|
1163
|
+
}
|
|
1164
|
+
for (let i = preserveStart; i < messages.length; i++) {
|
|
1165
|
+
const m = messages[i];
|
|
1166
|
+
if (!m || typeof m.content === "string" || !Array.isArray(m.content)) continue;
|
|
1167
|
+
const hasToolUse2 = m.content.some((b) => b.type === "tool_use");
|
|
1168
|
+
if (hasToolUse2 && i + 1 < messages.length) {
|
|
1169
|
+
const next = messages[i + 1];
|
|
1170
|
+
if (next && next.role === "user" && typeof next.content !== "string" && Array.isArray(next.content) && next.content.some((b) => b.type === "tool_result")) {
|
|
1171
|
+
preserveStart = i + 1;
|
|
1172
|
+
}
|
|
1173
|
+
}
|
|
1174
|
+
}
|
|
1175
|
+
return preserveStart;
|
|
1176
|
+
}
|
|
1177
|
+
function eliseOldToolResults(messages, opts) {
|
|
1178
|
+
const preserveStart = findPreserveStart(messages, opts.preserveK);
|
|
1179
|
+
let saved = 0;
|
|
1180
|
+
let changed = false;
|
|
1181
|
+
const next = new Array(messages.length);
|
|
1182
|
+
for (let i = 0; i < messages.length; i++) {
|
|
1183
|
+
const msg = messages[i];
|
|
1184
|
+
if (i >= preserveStart || !msg || !Array.isArray(msg.content)) {
|
|
1185
|
+
next[i] = msg;
|
|
1186
|
+
continue;
|
|
1187
|
+
}
|
|
1188
|
+
const original = msg.content;
|
|
1189
|
+
const newContent = original.map((b) => {
|
|
1190
|
+
if (b.type !== "tool_result") return b;
|
|
1191
|
+
const tokens = estimateToolResultTokens(b.content);
|
|
1192
|
+
if (tokens < opts.eliseThreshold) return b;
|
|
1193
|
+
saved += tokens;
|
|
1194
|
+
const elided = {
|
|
1195
|
+
type: "tool_result",
|
|
1196
|
+
tool_use_id: b.tool_use_id,
|
|
1197
|
+
content: `[elided: ~${tokens} tokens]`,
|
|
1198
|
+
is_error: b.is_error
|
|
1199
|
+
};
|
|
1200
|
+
return elided;
|
|
1201
|
+
});
|
|
1202
|
+
if (newContent.every((b, idx) => b === original[idx])) {
|
|
1203
|
+
next[i] = msg;
|
|
1204
|
+
} else {
|
|
1205
|
+
next[i] = { ...msg, content: newContent };
|
|
1206
|
+
changed = true;
|
|
1207
|
+
}
|
|
1208
|
+
}
|
|
1209
|
+
return { messages: changed ? next : messages, saved, changed };
|
|
1210
|
+
}
|
|
1211
|
+
function buildLosslessDigest(messages) {
|
|
1212
|
+
const lines = [];
|
|
1213
|
+
for (const m of messages) {
|
|
1214
|
+
let text;
|
|
1215
|
+
let omitted = 0;
|
|
1216
|
+
if (typeof m.content === "string") {
|
|
1217
|
+
text = m.content;
|
|
1218
|
+
} else {
|
|
1219
|
+
const parts = [];
|
|
1220
|
+
for (const b of m.content) {
|
|
1221
|
+
if (isTextBlock(b)) parts.push(b.text);
|
|
1222
|
+
else if (b.type === "tool_use" || b.type === "tool_result") omitted++;
|
|
1223
|
+
}
|
|
1224
|
+
text = parts.join(" ");
|
|
1225
|
+
}
|
|
1226
|
+
if (text.trim().length === 0 && omitted === 0) continue;
|
|
1227
|
+
const marker = omitted > 0 ? ` [${omitted} tool call(s) omitted \u2014 see session log]` : "";
|
|
1228
|
+
lines.push(`[${m.role}]: ${text}${marker}`);
|
|
1229
|
+
}
|
|
1230
|
+
return lines.join("\n");
|
|
1231
|
+
}
|
|
1232
|
+
|
|
1088
1233
|
// src/execution/compactor.ts
|
|
1089
1234
|
var HybridCompactor = class {
|
|
1090
1235
|
preserveK;
|
|
1091
1236
|
eliseThreshold;
|
|
1092
|
-
estimator;
|
|
1093
1237
|
constructor(opts = {}) {
|
|
1094
1238
|
this.preserveK = opts.preserveK ?? 5;
|
|
1095
1239
|
this.eliseThreshold = opts.eliseThreshold ?? 2e3;
|
|
1096
|
-
this.estimator = opts.estimator ?? estimateTextTokens;
|
|
1097
1240
|
}
|
|
1098
1241
|
async compact(ctx, opts = {}) {
|
|
1099
|
-
const beforeTokens =
|
|
1242
|
+
const beforeTokens = estimateMessages(ctx.messages);
|
|
1100
1243
|
const beforeFull = this.estimateFullRequest(ctx);
|
|
1101
1244
|
const reductions = [];
|
|
1102
1245
|
const policy = readContextWindowPolicy(ctx);
|
|
1103
1246
|
const preserveK = policy?.preserveK ?? this.preserveK;
|
|
1104
1247
|
const eliseThreshold = policy?.eliseThreshold ?? this.eliseThreshold;
|
|
1105
|
-
const
|
|
1106
|
-
if (
|
|
1248
|
+
const elide = eliseOldToolResults(ctx.messages, { preserveK, eliseThreshold });
|
|
1249
|
+
if (elide.changed) ctx.state.replaceMessages(elide.messages);
|
|
1250
|
+
if (elide.saved > 0) reductions.push({ phase: "elision", saved: elide.saved });
|
|
1251
|
+
let collapsedDigest;
|
|
1107
1252
|
if (opts.aggressive) {
|
|
1108
|
-
const
|
|
1109
|
-
if (
|
|
1253
|
+
const phase2 = this.collapseAncientTurns(ctx, preserveK);
|
|
1254
|
+
if (phase2.saved > 0) reductions.push({ phase: "summary", saved: phase2.saved });
|
|
1255
|
+
collapsedDigest = phase2.digest;
|
|
1110
1256
|
}
|
|
1111
1257
|
const repaired = repairToolUseAdjacency(ctx.messages);
|
|
1112
1258
|
if (repaired.report.changed) {
|
|
1113
1259
|
ctx.state.replaceMessages(repaired.messages);
|
|
1114
1260
|
}
|
|
1115
|
-
const afterTokens =
|
|
1261
|
+
const afterTokens = estimateMessages(ctx.messages);
|
|
1116
1262
|
const afterFull = this.estimateFullRequest(ctx);
|
|
1117
1263
|
return {
|
|
1118
1264
|
before: beforeTokens,
|
|
@@ -1120,6 +1266,7 @@ var HybridCompactor = class {
|
|
|
1120
1266
|
fullRequestTokensBefore: beforeFull,
|
|
1121
1267
|
fullRequestTokensAfter: afterFull,
|
|
1122
1268
|
reductions,
|
|
1269
|
+
collapsedDigest,
|
|
1123
1270
|
repaired: repaired.report.changed ? {
|
|
1124
1271
|
removedToolUses: repaired.report.removedToolUses,
|
|
1125
1272
|
removedToolResults: repaired.report.removedToolResults,
|
|
@@ -1132,72 +1279,23 @@ var HybridCompactor = class {
|
|
|
1132
1279
|
* This is the accurate figure for context-window pressure monitoring.
|
|
1133
1280
|
*/
|
|
1134
1281
|
estimateFullRequest(ctx) {
|
|
1135
|
-
|
|
1136
|
-
return breakdown.total;
|
|
1137
|
-
}
|
|
1138
|
-
eliseOldToolResults(ctx, preserveK = this.preserveK, eliseThreshold = this.eliseThreshold) {
|
|
1139
|
-
const messages = ctx.messages;
|
|
1140
|
-
let pairCount = 0;
|
|
1141
|
-
let preserveStart = messages.length;
|
|
1142
|
-
for (let i = messages.length - 1; i >= 0 && pairCount < preserveK; i--) {
|
|
1143
|
-
const m = messages[i];
|
|
1144
|
-
if (!m) continue;
|
|
1145
|
-
if (m.role === "user" || m.role === "assistant") {
|
|
1146
|
-
pairCount++;
|
|
1147
|
-
preserveStart = i;
|
|
1148
|
-
}
|
|
1149
|
-
}
|
|
1150
|
-
for (let i = preserveStart; i < messages.length; i++) {
|
|
1151
|
-
const m = messages[i];
|
|
1152
|
-
if (!m || typeof m.content === "string" || !Array.isArray(m.content)) continue;
|
|
1153
|
-
const hasToolUse2 = m.content.some((b) => b.type === "tool_use");
|
|
1154
|
-
if (hasToolUse2 && i + 1 < messages.length) {
|
|
1155
|
-
const next = messages[i + 1];
|
|
1156
|
-
if (next && next.role === "user" && typeof next.content !== "string" && Array.isArray(next.content) && next.content.some((b) => b.type === "tool_result")) {
|
|
1157
|
-
preserveStart = i + 1;
|
|
1158
|
-
}
|
|
1159
|
-
}
|
|
1160
|
-
}
|
|
1161
|
-
let saved = 0;
|
|
1162
|
-
let changed = false;
|
|
1163
|
-
const nextMessages = new Array(messages.length);
|
|
1164
|
-
for (let i = 0; i < messages.length; i++) {
|
|
1165
|
-
const msg = messages[i];
|
|
1166
|
-
if (i >= preserveStart) {
|
|
1167
|
-
nextMessages[i] = msg;
|
|
1168
|
-
continue;
|
|
1169
|
-
}
|
|
1170
|
-
if (!msg || !Array.isArray(msg.content)) {
|
|
1171
|
-
nextMessages[i] = msg;
|
|
1172
|
-
continue;
|
|
1173
|
-
}
|
|
1174
|
-
const newContent = msg.content.map((b) => {
|
|
1175
|
-
if (b.type !== "tool_result") return b;
|
|
1176
|
-
const tokens = estimateToolResultTokens(b.content);
|
|
1177
|
-
if (tokens < eliseThreshold) return b;
|
|
1178
|
-
saved += tokens;
|
|
1179
|
-
const elided = {
|
|
1180
|
-
type: "tool_result",
|
|
1181
|
-
tool_use_id: b.tool_use_id,
|
|
1182
|
-
content: `[elided: ~${tokens} tokens]`,
|
|
1183
|
-
is_error: b.is_error
|
|
1184
|
-
};
|
|
1185
|
-
return elided;
|
|
1186
|
-
});
|
|
1187
|
-
if (newContent.length === msg.content.length && newContent.every((b, idx) => b === msg.content[idx])) {
|
|
1188
|
-
nextMessages[i] = msg;
|
|
1189
|
-
} else {
|
|
1190
|
-
nextMessages[i] = { ...msg, content: newContent };
|
|
1191
|
-
changed = true;
|
|
1192
|
-
}
|
|
1193
|
-
}
|
|
1194
|
-
if (changed) ctx.state.replaceMessages(nextMessages);
|
|
1195
|
-
return saved;
|
|
1282
|
+
return estimateRequestTokens(ctx.messages, ctx.systemPrompt, ctx.tools ?? []).total;
|
|
1196
1283
|
}
|
|
1284
|
+
/**
|
|
1285
|
+
* Lossless rule-based collapse of ancient turns into a single digest message.
|
|
1286
|
+
*
|
|
1287
|
+
* Preserves ALL textual content of the collapsed range — user instructions,
|
|
1288
|
+
* assistant decisions/conclusions, and any prior digests (chained forward so
|
|
1289
|
+
* the digest stays lossless across repeated compactions). Only `tool_use` /
|
|
1290
|
+
* `tool_result` protocol blocks are dropped and replaced with a count marker;
|
|
1291
|
+
* their full payload already lives in the session log. No sub-LLM call.
|
|
1292
|
+
*
|
|
1293
|
+
* Returns the token savings and the digest text (for audit logging).
|
|
1294
|
+
*/
|
|
1197
1295
|
collapseAncientTurns(ctx, preserveK = this.preserveK) {
|
|
1198
1296
|
const messages = ctx.messages;
|
|
1199
1297
|
const cutTarget = Math.max(0, messages.length - preserveK * 2);
|
|
1200
|
-
if (cutTarget <= 0) return 0;
|
|
1298
|
+
if (cutTarget <= 0) return { saved: 0 };
|
|
1201
1299
|
let boundary = -1;
|
|
1202
1300
|
for (let i = cutTarget; i < messages.length; i++) {
|
|
1203
1301
|
const m = messages[i];
|
|
@@ -1207,34 +1305,20 @@ var HybridCompactor = class {
|
|
|
1207
1305
|
break;
|
|
1208
1306
|
}
|
|
1209
1307
|
}
|
|
1210
|
-
if (boundary <= 0) return 0;
|
|
1308
|
+
if (boundary <= 0) return { saved: 0 };
|
|
1211
1309
|
const removed = messages.slice(0, boundary);
|
|
1212
|
-
const removedTokens =
|
|
1213
|
-
const
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
{ role: "assistant", content: "Continuing from compacted context." }
|
|
1219
|
-
];
|
|
1310
|
+
const removedTokens = estimateMessages(removed);
|
|
1311
|
+
const digest = buildLosslessDigest(removed) || `${removed.length} earlier turns (no textual content; tool I/O omitted \u2014 see session log)`;
|
|
1312
|
+
const summaryMsg = {
|
|
1313
|
+
role: "system",
|
|
1314
|
+
content: `[prior_turns_digest: ${digest}]`
|
|
1315
|
+
};
|
|
1220
1316
|
const tail = ctx.messages.slice(boundary);
|
|
1221
|
-
ctx.state.replaceMessages([
|
|
1222
|
-
return
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
for (const m of messages) {
|
|
1227
|
-
if (typeof m.content === "string") {
|
|
1228
|
-
total += this.estimator(m.content);
|
|
1229
|
-
} else {
|
|
1230
|
-
for (const b of m.content) {
|
|
1231
|
-
if (b.type === "text") total += this.estimator(b.text);
|
|
1232
|
-
else if (b.type === "tool_use") total += estimateToolInputTokens(b.input);
|
|
1233
|
-
else if (b.type === "tool_result") total += estimateToolResultTokens(b.content);
|
|
1234
|
-
}
|
|
1235
|
-
}
|
|
1236
|
-
}
|
|
1237
|
-
return total;
|
|
1317
|
+
ctx.state.replaceMessages([summaryMsg, ...tail]);
|
|
1318
|
+
return {
|
|
1319
|
+
saved: Math.max(0, removedTokens - estimateMessages([summaryMsg])),
|
|
1320
|
+
digest
|
|
1321
|
+
};
|
|
1238
1322
|
}
|
|
1239
1323
|
};
|
|
1240
1324
|
function readContextWindowPolicy(ctx) {
|
|
@@ -1246,10 +1330,6 @@ function readContextWindowPolicy(ctx) {
|
|
|
1246
1330
|
}
|
|
1247
1331
|
return candidate;
|
|
1248
1332
|
}
|
|
1249
|
-
function hasTextContent(m) {
|
|
1250
|
-
if (typeof m.content === "string") return m.content.trim().length > 0;
|
|
1251
|
-
return m.content.some((b) => b.type === "text" && b.text.trim().length > 0);
|
|
1252
|
-
}
|
|
1253
1333
|
var PROJECT_MARKERS = [
|
|
1254
1334
|
".git",
|
|
1255
1335
|
"package.json",
|
|
@@ -1456,6 +1536,7 @@ var DefaultRetryPolicy = class {
|
|
|
1456
1536
|
if (err instanceof ProviderError) {
|
|
1457
1537
|
if (err.status === 429) return 5;
|
|
1458
1538
|
if (err.status === 529) return 3;
|
|
1539
|
+
if (err.status === 599) return 5;
|
|
1459
1540
|
if (err.status >= 500) return 3;
|
|
1460
1541
|
return 0;
|
|
1461
1542
|
}
|
|
@@ -2493,6 +2574,8 @@ function topologicalSort(graph) {
|
|
|
2493
2574
|
var ToolCapabilities = {
|
|
2494
2575
|
/** Can execute arbitrary commands in the user's shell (the `bash` tool). */
|
|
2495
2576
|
SHELL_ARBITRARY: "shell.arbitrary",
|
|
2577
|
+
/** Can execute a restricted set of commands (the `exec` tool). */
|
|
2578
|
+
SHELL_RESTRICTED: "shell.restricted",
|
|
2496
2579
|
/** Can write / modify / delete files inside the project. */
|
|
2497
2580
|
FS_WRITE: "fs.write",
|
|
2498
2581
|
/** Can write files outside the current project root (very high risk). */
|
|
@@ -2508,6 +2591,7 @@ var ToolCapabilities = {
|
|
|
2508
2591
|
};
|
|
2509
2592
|
var DANGEROUS_FOR_SUBAGENTS = [
|
|
2510
2593
|
ToolCapabilities.SHELL_ARBITRARY,
|
|
2594
|
+
ToolCapabilities.SHELL_RESTRICTED,
|
|
2511
2595
|
ToolCapabilities.FS_WRITE,
|
|
2512
2596
|
ToolCapabilities.FS_WRITE_OUTSIDE_PROJECT,
|
|
2513
2597
|
ToolCapabilities.MCP_PROXY,
|
|
@@ -3397,6 +3481,6 @@ function renderPlainText(meta, events) {
|
|
|
3397
3481
|
return lines.join("\n");
|
|
3398
3482
|
}
|
|
3399
3483
|
|
|
3400
|
-
export { AgentError, CONTEXT_WINDOW_MODES, ConfigError, DEFAULT_AUTONOMY_CONFIG, DEFAULT_CONTEXT_CONFIG, DEFAULT_CONTEXT_WINDOW_MODE_ID, DEFAULT_MODES, DEFAULT_RECOVERY_STRATEGIES, DEFAULT_SESSION_LOGGING_CONFIG, DEFAULT_SESSION_PRUNE_DAYS, DEFAULT_SPEC_TEMPLATE, DEFAULT_TOOLS_CONFIG, DefaultErrorHandler, DefaultLogger, DefaultModelsRegistry, DefaultPathResolver, DefaultRetryPolicy, DefaultSecretScrubber, DefaultSecretVault, DefaultSessionReader, DefaultTokenCounter, ERROR_CODES, FsError, HybridCompactor, InMemoryAgentBridge, InMemoryBridgeTransport, MEMORY_TYPE_LABELS, PluginError, ProviderError, SessionError, ToolError, ToolExecutor, WrongStackError, asBlocks, asText, buildRecoveryStrategies, classifyFamily, computeTaskProgress, createMessage, decryptConfigSecrets, encryptConfigSecrets, findCriticalPath, formatContextWindowModeList, getContextWindowMode, isAgentError, isConfigError, isContextWindowModeId, isFsError, isImageBlock, isPluginError, isSessionError, isTextBlock, isThinkingBlock, isToolError, isToolResultBlock, isToolUseBlock, isWrongStackError, listContextWindowModes, migratePlaintextSecrets, resolveContextWindowPolicy, rewriteConfigEncrypted, toWrongStackError, topologicalSort };
|
|
3484
|
+
export { AgentError, CONTEXT_WINDOW_MODES, ConfigError, DEFAULT_AUTONOMY_CONFIG, DEFAULT_CONTEXT_CONFIG, DEFAULT_CONTEXT_WINDOW_MODE_ID, DEFAULT_MODES, DEFAULT_RECOVERY_STRATEGIES, DEFAULT_SESSION_LOGGING_CONFIG, DEFAULT_SESSION_PRUNE_DAYS, DEFAULT_SPEC_TEMPLATE, DEFAULT_TOOLS_CONFIG, DefaultErrorHandler, DefaultLogger, DefaultModelsRegistry, DefaultPathResolver, DefaultRetryPolicy, DefaultSecretScrubber, DefaultSecretVault, DefaultSessionReader, DefaultTokenCounter, ERROR_CODES, FsError, HybridCompactor, InMemoryAgentBridge, InMemoryBridgeTransport, MEMORY_TYPE_LABELS, PluginError, ProviderError, SessionError, StreamHangError, ToolError, ToolExecutor, WrongStackError, asBlocks, asText, buildRecoveryStrategies, classifyFamily, computeTaskProgress, createMessage, decryptConfigSecrets, encryptConfigSecrets, findCriticalPath, formatContextWindowModeList, getContextWindowMode, isAgentError, isConfigError, isContextWindowModeId, isFsError, isImageBlock, isPluginError, isSecretField, isSessionError, isTextBlock, isThinkingBlock, isToolError, isToolResultBlock, isToolUseBlock, isWrongStackError, listContextWindowModes, migratePlaintextSecrets, resolveContextWindowPolicy, rewriteConfigEncrypted, toWrongStackError, topologicalSort };
|
|
3401
3485
|
//# sourceMappingURL=index.js.map
|
|
3402
3486
|
//# sourceMappingURL=index.js.map
|