@wrongstack/core 0.2.0 → 0.3.2
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-DmBiCipY.d.ts → agent-bridge-C3DUGjSb.d.ts} +1 -1
- package/dist/{compactor-DSl2FK7a.d.ts → compactor-DpJBI1YH.d.ts} +8 -2
- package/dist/{config-DXrqb41m.d.ts → config-D2qvAxVd.d.ts} +39 -2
- package/dist/{context-u0bryklF.d.ts → context-IovtuTf8.d.ts} +2 -0
- package/dist/coordination/index.d.ts +11 -11
- package/dist/coordination/index.js +307 -245
- package/dist/coordination/index.js.map +1 -1
- package/dist/defaults/index.d.ts +30 -15
- package/dist/defaults/index.js +1077 -479
- package/dist/defaults/index.js.map +1 -1
- package/dist/{events-B6Q03pTu.d.ts → events-BHIQs4o1.d.ts} +34 -1
- package/dist/execution/index.d.ts +17 -14
- package/dist/execution/index.js +166 -18
- package/dist/execution/index.js.map +1 -1
- package/dist/extension/index.d.ts +9 -0
- package/dist/extension/index.js +241 -0
- package/dist/extension/index.js.map +1 -0
- package/dist/{plugin-CoYYZKdn.d.ts → index-hWNybrNZ.d.ts} +368 -11
- package/dist/index.d.ts +76 -26
- package/dist/index.js +1595 -748
- package/dist/index.js.map +1 -1
- package/dist/infrastructure/index.d.ts +6 -6
- package/dist/infrastructure/index.js +191 -20
- package/dist/infrastructure/index.js.map +1 -1
- package/dist/kernel/index.d.ts +12 -9
- package/dist/kernel/index.js +73 -7
- package/dist/kernel/index.js.map +1 -1
- package/dist/{mcp-servers-BA1Ofmfj.d.ts → mcp-servers-C2OopXOn.d.ts} +21 -5
- package/dist/models/index.d.ts +2 -2
- package/dist/models/index.js +24 -1
- package/dist/models/index.js.map +1 -1
- package/dist/{multi-agent-BDfkxL5C.d.ts → multi-agent-B9a6sflH.d.ts} +2 -2
- package/dist/observability/index.d.ts +2 -2
- package/dist/{path-resolver-Crkt8wTQ.d.ts → path-resolver--59rCou3.d.ts} +2 -2
- package/dist/provider-runner-B39miKRw.d.ts +36 -0
- package/dist/sdd/index.d.ts +3 -3
- package/dist/{secret-scrubber-3TLUkiCV.d.ts → secret-scrubber-CgG2tV2B.d.ts} +1 -1
- package/dist/{secret-scrubber-CwYliRWd.d.ts → secret-scrubber-Cuy5afaQ.d.ts} +1 -1
- package/dist/security/index.d.ts +3 -3
- package/dist/security/index.js +24 -1
- package/dist/security/index.js.map +1 -1
- package/dist/{selector-BRqzvugb.d.ts → selector-wT2fv9Fg.d.ts} +1 -1
- package/dist/{session-reader-C3x96CDR.d.ts → session-reader-CcPi4BQ8.d.ts} +1 -1
- package/dist/{skill-Bx8jxznf.d.ts → skill-C_7znCIC.d.ts} +2 -2
- package/dist/storage/index.d.ts +7 -6
- package/dist/storage/index.js +204 -14
- package/dist/storage/index.js.map +1 -1
- package/dist/{renderer-0A2ZEtca.d.ts → system-prompt-Dk1qm8ey.d.ts} +30 -2
- package/dist/{tool-executor-CYdZdtno.d.ts → tool-executor-HsBLGRaA.d.ts} +5 -5
- package/dist/types/index.d.ts +16 -16
- package/dist/types/index.js +230 -10
- package/dist/types/index.js.map +1 -1
- package/dist/utils/index.d.ts +23 -2
- package/dist/utils/index.js +117 -2
- package/dist/utils/index.js.map +1 -1
- package/package.json +5 -1
- package/dist/system-prompt-CG9jU5-5.d.ts +0 -31
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { T as TextBlock, b as ContentBlock } from './context-
|
|
1
|
+
import { T as TextBlock, b as ContentBlock, u as Tool } from './context-IovtuTf8.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Container — dependency injection with explicit bind / override / decorate.
|
|
@@ -155,4 +155,32 @@ interface Renderer {
|
|
|
155
155
|
clear(): void;
|
|
156
156
|
}
|
|
157
157
|
|
|
158
|
-
|
|
158
|
+
/** Model capabilities relevant to prompt composition. */
|
|
159
|
+
interface ModelCapabilities {
|
|
160
|
+
maxContextTokens: number;
|
|
161
|
+
supportsTools: boolean;
|
|
162
|
+
supportsVision: boolean;
|
|
163
|
+
supportsReasoning: boolean;
|
|
164
|
+
}
|
|
165
|
+
interface BuildContext {
|
|
166
|
+
cwd: string;
|
|
167
|
+
projectRoot: string;
|
|
168
|
+
tools: Tool[];
|
|
169
|
+
/** Provider id (e.g. "anthropic", "minimax-coding-plan"). */
|
|
170
|
+
provider?: string;
|
|
171
|
+
/** Model id (e.g. "claude-sonnet-4-6", "MiniMax-M2.7"). */
|
|
172
|
+
model?: string;
|
|
173
|
+
/**
|
|
174
|
+
* True when the prompt is being built for a SUBAGENT, not the host
|
|
175
|
+
* agent. Subagents are scoped to a single task — they should NOT see
|
|
176
|
+
* the host's strategic plan board (which is anchoring the host across
|
|
177
|
+
* turns, not steering individual subtasks). The plan-injection
|
|
178
|
+
* layer short-circuits when this flag is set.
|
|
179
|
+
*/
|
|
180
|
+
subagent?: boolean;
|
|
181
|
+
}
|
|
182
|
+
interface SystemPromptBuilder {
|
|
183
|
+
build(ctx: BuildContext): Promise<TextBlock[]>;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
export { type BuildContext as B, Container as C, type Decorator as D, type Factory as F, type ModelCapabilities as M, type NextFn as N, Pipeline as P, type Renderer as R, type SystemPromptBuilder as S, type Token as T, type BindOptions as a, type Middleware as b, type MiddlewareHandler as c, type PipelineOptions as d, type ReadonlyPipeline as e };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { a0 as Context, h as ProviderError, u as Tool, D as ToolUseBlock, z as ToolResultBlock } from './context-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { a0 as Context, h as ProviderError, u as Tool, D as ToolUseBlock, z as ToolResultBlock } from './context-IovtuTf8.js';
|
|
2
|
+
import { a as Compactor, C as CompactReport } from './compactor-DpJBI1YH.js';
|
|
3
|
+
import { c as RecoveryDecision, E as ErrorHandler, R as RetryPolicy } from './skill-C_7znCIC.js';
|
|
4
4
|
import { M as ModelsRegistry } from './models-registry-Y2xbog0E.js';
|
|
5
|
-
import {
|
|
5
|
+
import { k as ToolExecutorOptions, l as ToolExecutorStrategy, m as ToolBatchResult } from './index-hWNybrNZ.js';
|
|
6
6
|
|
|
7
7
|
interface CompactorOptions {
|
|
8
8
|
preserveK?: number;
|
|
@@ -94,4 +94,4 @@ declare class ToolExecutor {
|
|
|
94
94
|
private subjectFor;
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
-
export { type CompactorOptions as C,
|
|
97
|
+
export { type CompactorOptions as C, DEFAULT_RECOVERY_STRATEGIES as D, HybridCompactor as H, type RecoveryStrategy as R, ToolExecutor as T, DefaultErrorHandler as a, DefaultRetryPolicy as b, buildRecoveryStrategies as c };
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
export { A as AgentError, C as Capabilities, a as ConfigError, b as ContentBlock, E as ErrorCode, c as ErrorSeverity, d as ErrorSubsystem, I as ImageBlock, J as JSONSchema, M as Message, e as MessageRole, P as Permission, f as PluginError, g as Provider, h as ProviderError, i as ProviderErrorBody, R as Request, j as Response, k as ResumedSession, S as SessionData, l as SessionError, m as SessionEvent, n as SessionMetadata, o as SessionStore, p as SessionSummary, q as SessionWriter, r as StopReason, s as StreamEvent, T as TextBlock, t as ThinkingBlock, u as Tool, v as ToolCallContext, w as ToolError, x as ToolFinalEvent, y as ToolProgressEvent, z as ToolResultBlock, B as ToolStreamEvent, D as ToolUseBlock, U as Usage, W as WrongStackError, F as asBlocks, G as asText, H as isAgentError, K as isConfigError, L as isImageBlock, N as isPluginError, O as isSessionError, Q as isTextBlock, V as isThinkingBlock, X as isToolError, Y as isToolResultBlock, Z as isToolUseBlock, _ as isWrongStackError, $ as toWrongStackError } from '../context-
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
5
|
-
export {
|
|
1
|
+
export { A as AgentError, C as Capabilities, a as ConfigError, b as ContentBlock, E as ErrorCode, c as ErrorSeverity, d as ErrorSubsystem, I as ImageBlock, J as JSONSchema, M as Message, e as MessageRole, P as Permission, f as PluginError, g as Provider, h as ProviderError, i as ProviderErrorBody, R as Request, j as Response, k as ResumedSession, S as SessionData, l as SessionError, m as SessionEvent, n as SessionMetadata, o as SessionStore, p as SessionSummary, q as SessionWriter, r as StopReason, s as StreamEvent, T as TextBlock, t as ThinkingBlock, u as Tool, v as ToolCallContext, w as ToolError, x as ToolFinalEvent, y as ToolProgressEvent, z as ToolResultBlock, B as ToolStreamEvent, D as ToolUseBlock, U as Usage, W as WrongStackError, F as asBlocks, G as asText, H as isAgentError, K as isConfigError, L as isImageBlock, N as isPluginError, O as isSessionError, Q as isTextBlock, V as isThinkingBlock, X as isToolError, Y as isToolResultBlock, Z as isToolUseBlock, _ as isWrongStackError, $ as toWrongStackError } from '../context-IovtuTf8.js';
|
|
2
|
+
export { P as ProviderRunner, R as RunProviderOptions } from '../provider-runner-B39miKRw.js';
|
|
3
|
+
export { C as CONTEXT_WINDOW_MODES, a as Config, b as ConfigLoader, c as ConfigStore, d as ContextConfig, e as ContextWindowAggressiveOn, f as ContextWindowConfigLike, g as ContextWindowMode, h as ContextWindowModeId, i as ContextWindowPolicy, j as ContextWindowThresholds, D as DEFAULT_CONTEXT_WINDOW_MODE_ID, F as FeaturesConfig, L as LogConfig, M as MCPServerConfig, P as PluginConfig, k as ProviderApiKey, l as ProviderConfig, T as ToolsConfig, m as formatContextWindowModeList, n as getContextWindowMode, o as isContextWindowModeId, p as listContextWindowModes, r as resolveContextWindowPolicy } from '../config-D2qvAxVd.js';
|
|
4
|
+
export { C as CompactReport, a as Compactor } from '../compactor-DpJBI1YH.js';
|
|
5
|
+
export { P as PermissionDecision, a as PermissionPolicy, T as TrustPolicy } from '../secret-scrubber-CgG2tV2B.js';
|
|
6
|
+
export { A as AddAttachmentInput, a as Attachment, b as AttachmentKind, c as AttachmentMeta, d as AttachmentRef, e as AttachmentStore, D as DefaultSessionReader } from '../session-reader-CcPi4BQ8.js';
|
|
7
|
+
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-Cuy5afaQ.js';
|
|
6
8
|
export { D as DefaultLogger, a as DefaultLoggerOptions } from '../logger-BH6AE0W9.js';
|
|
7
|
-
export { D as DefaultPathResolver, a as DefaultTokenCounter } from '../path-resolver
|
|
9
|
+
export { D as DefaultPathResolver, a as DefaultTokenCounter } from '../path-resolver--59rCou3.js';
|
|
8
10
|
export { M as MemoryEntry, a as MemoryScope, b as MemoryStore } from '../memory-CEXuo7sz.js';
|
|
9
|
-
export { C as CompactorOptions,
|
|
10
|
-
export { S as SkillEntry, a as SkillLoader, b as SkillManifest } from '../skill-
|
|
11
|
-
export { B as BuildContext, M as ModelCapabilities, S as SystemPromptBuilder } from '../system-prompt-
|
|
12
|
-
export { R as Renderer } from '../renderer-0A2ZEtca.js';
|
|
11
|
+
export { C as CompactorOptions, D as DEFAULT_RECOVERY_STRATEGIES, a as DefaultErrorHandler, b as DefaultRetryPolicy, H as HybridCompactor, R as RecoveryStrategy, T as ToolExecutor, c as buildRecoveryStrategies } from '../tool-executor-HsBLGRaA.js';
|
|
12
|
+
export { S as SkillEntry, a as SkillLoader, b as SkillManifest } from '../skill-C_7znCIC.js';
|
|
13
|
+
export { B as BuildContext, M as ModelCapabilities, R as Renderer, S as SystemPromptBuilder } from '../system-prompt-Dk1qm8ey.js';
|
|
13
14
|
export { I as InputReader, P as PromptOption } from '../input-reader-E-ffP2ee.js';
|
|
14
|
-
export { M as MCPRegistryView, P as Plugin,
|
|
15
|
+
export { M as MCPRegistryView, a as MetricsSinkView, P as Plugin, b as PluginAPI, c as PluginCapabilities, d as PluginDependency, e as PluginPipelines, f as ProviderFactory, g as ProviderRegistryView, S as SessionWriterView, h as SlashCommand, i as SlashCommandRegistryView, j as SystemPromptContributor, T as ToolRegistryView } from '../index-hWNybrNZ.js';
|
|
15
16
|
export { D as DefaultModelsRegistry, a as DefaultModelsRegistryOptions, c as classifyFamily } from '../models-registry-DqzwpBQy.js';
|
|
16
17
|
export { D as DEFAULT_MODES, M as Mode, a as ModeConfig, b as ModeManifest, c as ModeStore } from '../mode-CV077NjV.js';
|
|
17
|
-
export { I as InMemoryAgentBridge, a as InMemoryBridgeTransport, c as createMessage } from '../agent-bridge-
|
|
18
|
-
export { C as CoordinatorEvents,
|
|
18
|
+
export { I as InMemoryAgentBridge, a as InMemoryBridgeTransport, c as createMessage } from '../agent-bridge-C3DUGjSb.js';
|
|
19
|
+
export { C as CoordinatorEvents, a as CoordinatorStatus, D as DoneCondition, M as MultiAgentConfig, b as MultiAgentCoordinator, S as SpawnResult, c as SubagentConfig, d as SubagentContext, e as SubagentError, f as SubagentErrorKind, g as SubagentRunContext, h as SubagentRunOutcome, i as SubagentRunner, T as TaskDelegation, j as TaskResult, k as TaskSpec } from '../multi-agent-B9a6sflH.js';
|
|
19
20
|
export { C as CriticalPathResult, 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, T as TaskAssignment, i as TaskDependency, j as TaskEdge, k as TaskFilter, l as TaskGraph, m as TaskNode, n as TaskPriority, o as TaskProgress, p as TaskSort, q as TaskStatus, r as TaskType, s as computeTaskProgress, t as findCriticalPath, u as topologicalSort } from '../task-graph-BITvWt4t.js';
|
|
20
21
|
export { A as AggregateHealth, H as HealthCheck, a as HealthCheckResult, b as HealthRegistry, c as HealthStatus, M as MetricLabels, d as MetricSeries, e as MetricsSink, f as MetricsSnapshot, S as Span, T as Tracer } from '../observability-BhnVLBLS.js';
|
|
22
|
+
import '../events-BHIQs4o1.js';
|
|
23
|
+
import '../logger-BMQgxvdy.js';
|
|
21
24
|
import '../models-registry-Y2xbog0E.js';
|
|
22
25
|
import '../secret-vault-DoISxaKO.js';
|
|
23
|
-
import '../logger-BMQgxvdy.js';
|
|
24
|
-
import '../events-B6Q03pTu.js';
|
|
25
26
|
import '../path-resolver-CPRj4bFY.js';
|
|
26
|
-
import '../compactor-DSl2FK7a.js';
|
package/dist/types/index.js
CHANGED
|
@@ -682,6 +682,98 @@ function estimateTextTokens(text) {
|
|
|
682
682
|
return RoughTokenEstimate(text);
|
|
683
683
|
}
|
|
684
684
|
|
|
685
|
+
// src/utils/message-invariants.ts
|
|
686
|
+
function repairToolUseAdjacency(messages) {
|
|
687
|
+
const removedToolUses = [];
|
|
688
|
+
const removedToolResults = [];
|
|
689
|
+
let removedMessages = 0;
|
|
690
|
+
let changed = false;
|
|
691
|
+
const out = [];
|
|
692
|
+
for (let i = 0; i < messages.length; i++) {
|
|
693
|
+
const original = messages[i];
|
|
694
|
+
let msg = original;
|
|
695
|
+
if (hasToolUse(msg)) {
|
|
696
|
+
const nextIds = toolResultIds(messages[i + 1]);
|
|
697
|
+
const filtered = mapContent(msg, (blocks) => {
|
|
698
|
+
const next = [];
|
|
699
|
+
for (const block of blocks) {
|
|
700
|
+
if (block.type === "tool_use" && !nextIds.has(block.id)) {
|
|
701
|
+
removedToolUses.push(block.id);
|
|
702
|
+
changed = true;
|
|
703
|
+
continue;
|
|
704
|
+
}
|
|
705
|
+
next.push(block);
|
|
706
|
+
}
|
|
707
|
+
return next;
|
|
708
|
+
});
|
|
709
|
+
msg = filtered ?? msg;
|
|
710
|
+
}
|
|
711
|
+
if (hasToolResult(msg)) {
|
|
712
|
+
const allowed = toolUseIds(out[out.length - 1]);
|
|
713
|
+
const filtered = mapContent(msg, (blocks) => {
|
|
714
|
+
const next = [];
|
|
715
|
+
for (const block of blocks) {
|
|
716
|
+
if (block.type === "tool_result" && !allowed.has(block.tool_use_id)) {
|
|
717
|
+
removedToolResults.push(block.tool_use_id);
|
|
718
|
+
changed = true;
|
|
719
|
+
continue;
|
|
720
|
+
}
|
|
721
|
+
next.push(block);
|
|
722
|
+
}
|
|
723
|
+
return next;
|
|
724
|
+
});
|
|
725
|
+
msg = filtered ?? msg;
|
|
726
|
+
}
|
|
727
|
+
if (isEmptyMessage(msg)) {
|
|
728
|
+
removedMessages++;
|
|
729
|
+
changed = true;
|
|
730
|
+
continue;
|
|
731
|
+
}
|
|
732
|
+
out.push(msg);
|
|
733
|
+
}
|
|
734
|
+
return {
|
|
735
|
+
messages: changed ? out : messages,
|
|
736
|
+
report: { changed, removedToolUses, removedToolResults, removedMessages }
|
|
737
|
+
};
|
|
738
|
+
}
|
|
739
|
+
function hasToolUse(msg) {
|
|
740
|
+
return contentBlocks(msg).some((b) => b.type === "tool_use");
|
|
741
|
+
}
|
|
742
|
+
function hasToolResult(msg) {
|
|
743
|
+
return contentBlocks(msg).some((b) => b.type === "tool_result");
|
|
744
|
+
}
|
|
745
|
+
function toolUseIds(msg) {
|
|
746
|
+
const ids = /* @__PURE__ */ new Set();
|
|
747
|
+
if (!msg || msg.role !== "assistant") return ids;
|
|
748
|
+
for (const block of contentBlocks(msg)) {
|
|
749
|
+
if (block.type === "tool_use") ids.add(block.id);
|
|
750
|
+
}
|
|
751
|
+
return ids;
|
|
752
|
+
}
|
|
753
|
+
function toolResultIds(msg) {
|
|
754
|
+
const ids = /* @__PURE__ */ new Set();
|
|
755
|
+
if (!msg || msg.role !== "user") return ids;
|
|
756
|
+
for (const block of contentBlocks(msg)) {
|
|
757
|
+
if (block.type === "tool_result") ids.add(block.tool_use_id);
|
|
758
|
+
}
|
|
759
|
+
return ids;
|
|
760
|
+
}
|
|
761
|
+
function contentBlocks(msg) {
|
|
762
|
+
return msg && Array.isArray(msg.content) ? msg.content : [];
|
|
763
|
+
}
|
|
764
|
+
function mapContent(msg, fn) {
|
|
765
|
+
if (!Array.isArray(msg.content)) return msg;
|
|
766
|
+
const next = fn(msg.content);
|
|
767
|
+
if (next.length === msg.content.length && next.every((b, idx) => b === msg.content[idx])) {
|
|
768
|
+
return msg;
|
|
769
|
+
}
|
|
770
|
+
return { ...msg, content: next };
|
|
771
|
+
}
|
|
772
|
+
function isEmptyMessage(msg) {
|
|
773
|
+
if (typeof msg.content === "string") return msg.content.trim().length === 0;
|
|
774
|
+
return msg.content.length === 0;
|
|
775
|
+
}
|
|
776
|
+
|
|
685
777
|
// src/execution/compactor.ts
|
|
686
778
|
var HybridCompactor = class {
|
|
687
779
|
preserveK;
|
|
@@ -695,20 +787,36 @@ var HybridCompactor = class {
|
|
|
695
787
|
async compact(ctx, opts = {}) {
|
|
696
788
|
const beforeTokens = this.estimateMessages(ctx.messages);
|
|
697
789
|
const reductions = [];
|
|
698
|
-
const
|
|
790
|
+
const policy = readContextWindowPolicy(ctx);
|
|
791
|
+
const preserveK = policy?.preserveK ?? this.preserveK;
|
|
792
|
+
const eliseThreshold = policy?.eliseThreshold ?? this.eliseThreshold;
|
|
793
|
+
const phase1Saved = this.eliseOldToolResults(ctx, preserveK, eliseThreshold);
|
|
699
794
|
if (phase1Saved > 0) reductions.push({ phase: "elision", saved: phase1Saved });
|
|
700
795
|
if (opts.aggressive) {
|
|
701
|
-
const phase2Saved = this.collapseAncientTurns(ctx);
|
|
796
|
+
const phase2Saved = this.collapseAncientTurns(ctx, preserveK);
|
|
702
797
|
if (phase2Saved > 0) reductions.push({ phase: "summary", saved: phase2Saved });
|
|
703
798
|
}
|
|
799
|
+
const repaired = repairToolUseAdjacency(ctx.messages);
|
|
800
|
+
if (repaired.report.changed) {
|
|
801
|
+
ctx.state.replaceMessages(repaired.messages);
|
|
802
|
+
}
|
|
704
803
|
const afterTokens = this.estimateMessages(ctx.messages);
|
|
705
|
-
return {
|
|
804
|
+
return {
|
|
805
|
+
before: beforeTokens,
|
|
806
|
+
after: afterTokens,
|
|
807
|
+
reductions,
|
|
808
|
+
repaired: repaired.report.changed ? {
|
|
809
|
+
removedToolUses: repaired.report.removedToolUses,
|
|
810
|
+
removedToolResults: repaired.report.removedToolResults,
|
|
811
|
+
removedMessages: repaired.report.removedMessages
|
|
812
|
+
} : void 0
|
|
813
|
+
};
|
|
706
814
|
}
|
|
707
|
-
eliseOldToolResults(ctx) {
|
|
815
|
+
eliseOldToolResults(ctx, preserveK = this.preserveK, eliseThreshold = this.eliseThreshold) {
|
|
708
816
|
const messages = ctx.messages;
|
|
709
817
|
let pairCount = 0;
|
|
710
818
|
let preserveStart = messages.length;
|
|
711
|
-
for (let i = messages.length - 1; i >= 0 && pairCount <
|
|
819
|
+
for (let i = messages.length - 1; i >= 0 && pairCount < preserveK; i--) {
|
|
712
820
|
const m = messages[i];
|
|
713
821
|
if (!m) continue;
|
|
714
822
|
if (m.role === "user" || m.role === "assistant") {
|
|
@@ -732,7 +840,7 @@ var HybridCompactor = class {
|
|
|
732
840
|
const newContent = msg.content.map((b) => {
|
|
733
841
|
if (b.type !== "tool_result") return b;
|
|
734
842
|
const tokens = estimateToolResultTokens(b.content);
|
|
735
|
-
if (tokens <
|
|
843
|
+
if (tokens < eliseThreshold) return b;
|
|
736
844
|
saved += tokens;
|
|
737
845
|
const elided = {
|
|
738
846
|
type: "tool_result",
|
|
@@ -752,9 +860,9 @@ var HybridCompactor = class {
|
|
|
752
860
|
if (changed) ctx.state.replaceMessages(nextMessages);
|
|
753
861
|
return saved;
|
|
754
862
|
}
|
|
755
|
-
collapseAncientTurns(ctx) {
|
|
863
|
+
collapseAncientTurns(ctx, preserveK = this.preserveK) {
|
|
756
864
|
const messages = ctx.messages;
|
|
757
|
-
const cutTarget = Math.max(0, messages.length -
|
|
865
|
+
const cutTarget = Math.max(0, messages.length - preserveK * 2);
|
|
758
866
|
if (cutTarget <= 0) return 0;
|
|
759
867
|
let boundary = -1;
|
|
760
868
|
for (let i = cutTarget; i < messages.length; i++) {
|
|
@@ -795,6 +903,15 @@ var HybridCompactor = class {
|
|
|
795
903
|
return total;
|
|
796
904
|
}
|
|
797
905
|
};
|
|
906
|
+
function readContextWindowPolicy(ctx) {
|
|
907
|
+
const policy = ctx.meta?.["contextWindowPolicy"];
|
|
908
|
+
if (!policy || typeof policy !== "object") return null;
|
|
909
|
+
const candidate = policy;
|
|
910
|
+
if (typeof candidate.preserveK !== "number" || typeof candidate.eliseThreshold !== "number") {
|
|
911
|
+
return null;
|
|
912
|
+
}
|
|
913
|
+
return candidate;
|
|
914
|
+
}
|
|
798
915
|
function hasTextContent(m) {
|
|
799
916
|
if (typeof m.content === "string") return m.content.trim().length > 0;
|
|
800
917
|
return m.content.some((b) => b.type === "text" && b.text.trim().length > 0);
|
|
@@ -1121,7 +1238,7 @@ async function atomicWrite(targetPath, content, opts = {}) {
|
|
|
1121
1238
|
if (mode !== void 0) {
|
|
1122
1239
|
await fs4.chmod(tmp, mode);
|
|
1123
1240
|
}
|
|
1124
|
-
await
|
|
1241
|
+
await renameWithRetry(tmp, targetPath);
|
|
1125
1242
|
} catch (err) {
|
|
1126
1243
|
try {
|
|
1127
1244
|
await fs4.unlink(tmp);
|
|
@@ -1130,6 +1247,29 @@ async function atomicWrite(targetPath, content, opts = {}) {
|
|
|
1130
1247
|
throw err;
|
|
1131
1248
|
}
|
|
1132
1249
|
}
|
|
1250
|
+
var TRANSIENT_RENAME_CODES = /* @__PURE__ */ new Set(["EPERM", "EBUSY", "EACCES", "ENOTEMPTY"]);
|
|
1251
|
+
async function renameWithRetry(from, to) {
|
|
1252
|
+
if (process.platform !== "win32") {
|
|
1253
|
+
await fs4.rename(from, to);
|
|
1254
|
+
return;
|
|
1255
|
+
}
|
|
1256
|
+
const delays = [10, 25, 60, 120, 250];
|
|
1257
|
+
let lastErr;
|
|
1258
|
+
for (let i = 0; i <= delays.length; i++) {
|
|
1259
|
+
try {
|
|
1260
|
+
await fs4.rename(from, to);
|
|
1261
|
+
return;
|
|
1262
|
+
} catch (err) {
|
|
1263
|
+
lastErr = err;
|
|
1264
|
+
const code = err?.code;
|
|
1265
|
+
if (!code || !TRANSIENT_RENAME_CODES.has(code) || i === delays.length) {
|
|
1266
|
+
throw err;
|
|
1267
|
+
}
|
|
1268
|
+
await new Promise((resolve3) => setTimeout(resolve3, delays[i]));
|
|
1269
|
+
}
|
|
1270
|
+
}
|
|
1271
|
+
throw lastErr;
|
|
1272
|
+
}
|
|
1133
1273
|
|
|
1134
1274
|
// src/models/models-registry.ts
|
|
1135
1275
|
var DEFAULT_URL = "https://models.dev/api.json";
|
|
@@ -1434,6 +1574,85 @@ When refactoring code:
|
|
|
1434
1574
|
}
|
|
1435
1575
|
];
|
|
1436
1576
|
|
|
1577
|
+
// src/types/context-window.ts
|
|
1578
|
+
var DEFAULT_CONTEXT_WINDOW_MODE_ID = "balanced";
|
|
1579
|
+
var CONTEXT_WINDOW_MODES = Object.freeze([
|
|
1580
|
+
{
|
|
1581
|
+
id: "balanced",
|
|
1582
|
+
name: "Balanced",
|
|
1583
|
+
description: "Default rolling compaction: recent work stays verbatim, old tool output is trimmed.",
|
|
1584
|
+
thresholds: { warn: 0.6, soft: 0.75, hard: 0.9 },
|
|
1585
|
+
aggressiveOn: "soft",
|
|
1586
|
+
preserveK: 10,
|
|
1587
|
+
eliseThreshold: 2e3,
|
|
1588
|
+
targetLoad: 0.65
|
|
1589
|
+
},
|
|
1590
|
+
{
|
|
1591
|
+
id: "frugal",
|
|
1592
|
+
name: "Frugal",
|
|
1593
|
+
description: "Token-saver mode: compacts early and keeps a tighter verbatim tail.",
|
|
1594
|
+
thresholds: { warn: 0.45, soft: 0.6, hard: 0.75 },
|
|
1595
|
+
aggressiveOn: "warn",
|
|
1596
|
+
preserveK: 6,
|
|
1597
|
+
eliseThreshold: 700,
|
|
1598
|
+
targetLoad: 0.5
|
|
1599
|
+
},
|
|
1600
|
+
{
|
|
1601
|
+
id: "deep",
|
|
1602
|
+
name: "Deep",
|
|
1603
|
+
description: "Long-reasoning mode: delays compaction and keeps more recent turns intact.",
|
|
1604
|
+
thresholds: { warn: 0.72, soft: 0.86, hard: 0.96 },
|
|
1605
|
+
aggressiveOn: "hard",
|
|
1606
|
+
preserveK: 18,
|
|
1607
|
+
eliseThreshold: 5e3,
|
|
1608
|
+
targetLoad: 0.78
|
|
1609
|
+
},
|
|
1610
|
+
{
|
|
1611
|
+
id: "archival",
|
|
1612
|
+
name: "Archival",
|
|
1613
|
+
description: "Decision-preserving mode: compacts steadily while keeping summaries prominent.",
|
|
1614
|
+
thresholds: { warn: 0.55, soft: 0.7, hard: 0.84 },
|
|
1615
|
+
aggressiveOn: "soft",
|
|
1616
|
+
preserveK: 8,
|
|
1617
|
+
eliseThreshold: 1200,
|
|
1618
|
+
targetLoad: 0.58
|
|
1619
|
+
}
|
|
1620
|
+
]);
|
|
1621
|
+
function listContextWindowModes() {
|
|
1622
|
+
return CONTEXT_WINDOW_MODES.map((m) => ({ ...m, thresholds: { ...m.thresholds } }));
|
|
1623
|
+
}
|
|
1624
|
+
function getContextWindowMode(id) {
|
|
1625
|
+
if (!id) return null;
|
|
1626
|
+
const mode = CONTEXT_WINDOW_MODES.find((m) => m.id === id);
|
|
1627
|
+
return mode ? { ...mode, thresholds: { ...mode.thresholds } } : null;
|
|
1628
|
+
}
|
|
1629
|
+
function isContextWindowModeId(id) {
|
|
1630
|
+
return CONTEXT_WINDOW_MODES.some((m) => m.id === id);
|
|
1631
|
+
}
|
|
1632
|
+
function resolveContextWindowPolicy(config = {}, overrideMode) {
|
|
1633
|
+
const requested = overrideMode ?? config.mode ?? DEFAULT_CONTEXT_WINDOW_MODE_ID;
|
|
1634
|
+
const mode = getContextWindowMode(requested) ?? getContextWindowMode(DEFAULT_CONTEXT_WINDOW_MODE_ID);
|
|
1635
|
+
if (mode.id !== DEFAULT_CONTEXT_WINDOW_MODE_ID) {
|
|
1636
|
+
return mode;
|
|
1637
|
+
}
|
|
1638
|
+
return {
|
|
1639
|
+
...mode,
|
|
1640
|
+
thresholds: {
|
|
1641
|
+
warn: config.warnThreshold ?? mode.thresholds.warn,
|
|
1642
|
+
soft: config.softThreshold ?? mode.thresholds.soft,
|
|
1643
|
+
hard: config.hardThreshold ?? mode.thresholds.hard
|
|
1644
|
+
},
|
|
1645
|
+
preserveK: config.preserveK ?? mode.preserveK,
|
|
1646
|
+
eliseThreshold: config.eliseThreshold ?? mode.eliseThreshold
|
|
1647
|
+
};
|
|
1648
|
+
}
|
|
1649
|
+
function formatContextWindowModeList(activeId) {
|
|
1650
|
+
return CONTEXT_WINDOW_MODES.map((m) => {
|
|
1651
|
+
const marker = m.id === activeId ? "*" : " ";
|
|
1652
|
+
return `${marker} ${m.id.padEnd(9)} ${m.name} - ${m.description}`;
|
|
1653
|
+
}).join("\n");
|
|
1654
|
+
}
|
|
1655
|
+
|
|
1437
1656
|
// src/coordination/in-memory-transport.ts
|
|
1438
1657
|
var InMemoryBridgeTransport = class {
|
|
1439
1658
|
subs = /* @__PURE__ */ new Map();
|
|
@@ -1553,6 +1772,7 @@ var InMemoryAgentBridge = class {
|
|
|
1553
1772
|
this.stopped = true;
|
|
1554
1773
|
for (const [, p] of this.pendingRequests) {
|
|
1555
1774
|
clearTimeout(p.timer);
|
|
1775
|
+
p.reject(new Error("Bridge stopped"));
|
|
1556
1776
|
}
|
|
1557
1777
|
this.pendingRequests.clear();
|
|
1558
1778
|
this.inflightGuards.clear();
|
|
@@ -2241,6 +2461,6 @@ function renderPlainText(meta, events) {
|
|
|
2241
2461
|
return lines.join("\n");
|
|
2242
2462
|
}
|
|
2243
2463
|
|
|
2244
|
-
export { AgentError, ConfigError, DEFAULT_MODES, DEFAULT_RECOVERY_STRATEGIES, DEFAULT_SPEC_TEMPLATE, DefaultErrorHandler, DefaultLogger, DefaultModelsRegistry, DefaultPathResolver, DefaultRetryPolicy, DefaultSecretScrubber, DefaultSecretVault, DefaultSessionReader, DefaultTokenCounter, HybridCompactor, InMemoryAgentBridge, InMemoryBridgeTransport, PluginError, ProviderError, SessionError, ToolError, ToolExecutor, WrongStackError, asBlocks, asText, buildRecoveryStrategies, classifyFamily, computeTaskProgress, createMessage, decryptConfigSecrets, encryptConfigSecrets, findCriticalPath, isAgentError, isConfigError, isImageBlock, isPluginError, isSessionError, isTextBlock, isThinkingBlock, isToolError, isToolResultBlock, isToolUseBlock, isWrongStackError, migratePlaintextSecrets, rewriteConfigEncrypted, toWrongStackError, topologicalSort };
|
|
2464
|
+
export { AgentError, CONTEXT_WINDOW_MODES, ConfigError, DEFAULT_CONTEXT_WINDOW_MODE_ID, DEFAULT_MODES, DEFAULT_RECOVERY_STRATEGIES, DEFAULT_SPEC_TEMPLATE, DefaultErrorHandler, DefaultLogger, DefaultModelsRegistry, DefaultPathResolver, DefaultRetryPolicy, DefaultSecretScrubber, DefaultSecretVault, DefaultSessionReader, DefaultTokenCounter, HybridCompactor, InMemoryAgentBridge, InMemoryBridgeTransport, PluginError, ProviderError, SessionError, ToolError, ToolExecutor, WrongStackError, asBlocks, asText, buildRecoveryStrategies, classifyFamily, computeTaskProgress, createMessage, decryptConfigSecrets, encryptConfigSecrets, findCriticalPath, formatContextWindowModeList, getContextWindowMode, isAgentError, isConfigError, isContextWindowModeId, isImageBlock, isPluginError, isSessionError, isTextBlock, isThinkingBlock, isToolError, isToolResultBlock, isToolUseBlock, isWrongStackError, listContextWindowModes, migratePlaintextSecrets, resolveContextWindowPolicy, rewriteConfigEncrypted, toWrongStackError, topologicalSort };
|
|
2245
2465
|
//# sourceMappingURL=index.js.map
|
|
2246
2466
|
//# sourceMappingURL=index.js.map
|