@wrongstack/core 0.1.9 → 0.1.10

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.
Files changed (69) hide show
  1. package/dist/agent-bridge-6KPqsFx6.d.ts +33 -0
  2. package/dist/compactor-B4mQZXf2.d.ts +17 -0
  3. package/dist/config-BU9f_5yH.d.ts +193 -0
  4. package/dist/{provider-txgB0Oq9.d.ts → context-BmM2xGUZ.d.ts} +532 -472
  5. package/dist/coordination/index.d.ts +694 -0
  6. package/dist/coordination/index.js +1995 -0
  7. package/dist/coordination/index.js.map +1 -0
  8. package/dist/defaults/index.d.ts +34 -2309
  9. package/dist/defaults/index.js +3893 -3803
  10. package/dist/defaults/index.js.map +1 -1
  11. package/dist/events-BMNaEFZl.d.ts +218 -0
  12. package/dist/execution/index.d.ts +260 -0
  13. package/dist/execution/index.js +1625 -0
  14. package/dist/execution/index.js.map +1 -0
  15. package/dist/index.d.ts +47 -10
  16. package/dist/index.js +6617 -6093
  17. package/dist/index.js.map +1 -1
  18. package/dist/infrastructure/index.d.ts +10 -0
  19. package/dist/infrastructure/index.js +575 -0
  20. package/dist/infrastructure/index.js.map +1 -0
  21. package/dist/input-reader-E-ffP2ee.d.ts +12 -0
  22. package/dist/kernel/index.d.ts +15 -4
  23. package/dist/kernel/index.js.map +1 -1
  24. package/dist/logger-BH6AE0W9.d.ts +24 -0
  25. package/dist/logger-BMQgxvdy.d.ts +12 -0
  26. package/dist/mcp-servers-Dzgg4x1w.d.ts +100 -0
  27. package/dist/memory-CEXuo7sz.d.ts +16 -0
  28. package/dist/mode-CV077NjV.d.ts +27 -0
  29. package/dist/models/index.d.ts +60 -0
  30. package/dist/models/index.js +621 -0
  31. package/dist/models/index.js.map +1 -0
  32. package/dist/models-registry-DqzwpBQy.d.ts +46 -0
  33. package/dist/models-registry-Y2xbog0E.d.ts +95 -0
  34. package/dist/multi-agent-fmkRHtof.d.ts +283 -0
  35. package/dist/observability/index.d.ts +353 -0
  36. package/dist/observability/index.js +691 -0
  37. package/dist/observability/index.js.map +1 -0
  38. package/dist/observability-BhnVLBLS.d.ts +67 -0
  39. package/dist/path-resolver-CPRj4bFY.d.ts +10 -0
  40. package/dist/path-resolver-DBjaoXFq.d.ts +54 -0
  41. package/dist/plugin-DJk6LL8B.d.ts +434 -0
  42. package/dist/renderer-rk_1Swwc.d.ts +158 -0
  43. package/dist/sdd/index.d.ts +206 -0
  44. package/dist/sdd/index.js +864 -0
  45. package/dist/sdd/index.js.map +1 -0
  46. package/dist/secret-scrubber-CicHLN4G.d.ts +31 -0
  47. package/dist/secret-scrubber-DF88luOe.d.ts +54 -0
  48. package/dist/secret-vault-DoISxaKO.d.ts +19 -0
  49. package/dist/security/index.d.ts +30 -0
  50. package/dist/security/index.js +524 -0
  51. package/dist/security/index.js.map +1 -0
  52. package/dist/selector-BbJqiEP4.d.ts +51 -0
  53. package/dist/session-reader-Drq8RvJu.d.ts +150 -0
  54. package/dist/skill-DhfSizKv.d.ts +72 -0
  55. package/dist/storage/index.d.ts +382 -0
  56. package/dist/storage/index.js +1530 -0
  57. package/dist/storage/index.js.map +1 -0
  58. package/dist/{system-prompt-vAB0F54-.d.ts → system-prompt-BC_8ypCG.d.ts} +1 -1
  59. package/dist/task-graph-BITvWt4t.d.ts +160 -0
  60. package/dist/tool-executor-CpuJPYm9.d.ts +97 -0
  61. package/dist/types/index.d.ts +26 -4
  62. package/dist/types/index.js +1787 -4
  63. package/dist/types/index.js.map +1 -1
  64. package/dist/utils/index.d.ts +49 -2
  65. package/dist/utils/index.js +100 -2
  66. package/dist/utils/index.js.map +1 -1
  67. package/package.json +34 -2
  68. package/dist/mode-Pjt5vMS6.d.ts +0 -815
  69. package/dist/session-reader-9sOTgmeC.d.ts +0 -1087
@@ -0,0 +1,218 @@
1
+ import { U as Usage, a0 as Context, y as ToolProgressEvent, u as Tool } from './context-BmM2xGUZ.js';
2
+
3
+ /**
4
+ * EventBus — observe-only typed event bus.
5
+ * Subscribers cannot modify or cancel. Subscriber exceptions are caught.
6
+ */
7
+
8
+ interface EventMap {
9
+ 'session.started': {
10
+ id: string;
11
+ };
12
+ 'session.ended': {
13
+ id: string;
14
+ usage: Usage;
15
+ };
16
+ 'session.damaged': {
17
+ sessionId: string;
18
+ detail: string;
19
+ };
20
+ 'iteration.started': {
21
+ ctx: Context;
22
+ index: number;
23
+ };
24
+ 'iteration.completed': {
25
+ ctx: Context;
26
+ index: number;
27
+ };
28
+ /**
29
+ * Fired when the agent hits its iteration limit. Listeners (CLI/TUI) can
30
+ * call `grant(extra)` to allow more iterations, or `deny()` to stop.
31
+ * If no listener responds within 30s the run ends with 'max_iterations'.
32
+ */
33
+ 'iteration.limit_reached': {
34
+ currentIterations: number;
35
+ currentLimit: number;
36
+ grant: (extraIterations: number) => void;
37
+ deny: () => void;
38
+ };
39
+ 'provider.response': {
40
+ ctx: Context;
41
+ usage: Usage;
42
+ stopReason: string;
43
+ };
44
+ 'provider.text_delta': {
45
+ ctx: Context;
46
+ text: string;
47
+ };
48
+ 'provider.thinking_delta': {
49
+ ctx: Context;
50
+ text: string;
51
+ };
52
+ 'provider.tool_use_start': {
53
+ ctx: Context;
54
+ id: string;
55
+ name: string;
56
+ };
57
+ 'provider.tool_use_stop': {
58
+ ctx: Context;
59
+ id: string;
60
+ };
61
+ /**
62
+ * Fired before each retry of a failed provider call. `attempt` is 1-based
63
+ * (the first retry is attempt 1, etc.). `description` is the human-readable
64
+ * one-liner from `ProviderError.describe()` — render this in the CLI/TUI
65
+ * instead of grepping logger output for the raw JSON body.
66
+ */
67
+ 'provider.retry': {
68
+ providerId: string;
69
+ attempt: number;
70
+ delayMs: number;
71
+ status: number;
72
+ description: string;
73
+ };
74
+ /**
75
+ * Fired once when a provider call ultimately fails (retries exhausted, or
76
+ * non-retryable error). Same shape as `provider.retry` minus the delay.
77
+ */
78
+ 'provider.error': {
79
+ providerId: string;
80
+ status: number;
81
+ description: string;
82
+ retryable: boolean;
83
+ };
84
+ 'tool.started': {
85
+ name: string;
86
+ id: string;
87
+ input?: unknown;
88
+ };
89
+ /**
90
+ * Fired for each ToolProgressEvent yielded by `Tool.executeStream`. UIs
91
+ * subscribe to render incremental progress (streaming bash output, file
92
+ * tree counts, etc.) without the tool having to know about the UI.
93
+ */
94
+ 'tool.progress': {
95
+ name: string;
96
+ id: string;
97
+ event: ToolProgressEvent;
98
+ };
99
+ /**
100
+ * Fired when a tool call needs user confirmation and no confirmHandler
101
+ * is registered on the executor. The TUI renders a confirmation dialog
102
+ * from this event. Resolution is driven by calling the resolve function
103
+ * passed in the payload with a decision string ('yes' | 'no' | 'always' | 'deny').
104
+ */
105
+ 'tool.confirm_needed': {
106
+ tool: Tool;
107
+ input: unknown;
108
+ toolUseId: string;
109
+ suggestedPattern: string;
110
+ resolve: (decision: 'yes' | 'no' | 'always' | 'deny') => void;
111
+ };
112
+ /**
113
+ * `output` is a truncated preview of the tool's serialized result text
114
+ * (capped at ~400 chars by the emitter). UIs render this inline in the
115
+ * tool history line without re-fetching from the session log.
116
+ */
117
+ 'tool.executed': {
118
+ /**
119
+ * The tool_use id (e.g. "toolu_…") issued by the provider for this call.
120
+ * Pairs with `tool.started.id` so subscribers can correlate start/finish
121
+ * even when the model fires multiple tools in parallel with identical
122
+ * inputs. Optional only for legacy emit sites — new code should always
123
+ * set it.
124
+ */
125
+ id?: string;
126
+ name: string;
127
+ durationMs: number;
128
+ ok: boolean;
129
+ input?: unknown;
130
+ output?: string;
131
+ /**
132
+ * Full UTF-8 byte length of the serialized tool result that the model
133
+ * actually sees (post-cap, post-scrub). The `output` preview is capped
134
+ * at ~400 chars for transport; this number lets UIs surface what the
135
+ * model is really paying tokens for. Optional only for legacy emit
136
+ * sites that may not yet populate it.
137
+ */
138
+ outputBytes?: number;
139
+ /**
140
+ * Estimated token count for the full result body the model sees.
141
+ * Computed from `outputBytes` with the standard ~3.5 chars/token
142
+ * heuristic. Cheap to show in the TUI; not authoritative — the real
143
+ * provider count lives in `provider.response.usage`. */
144
+ outputTokens?: number;
145
+ /**
146
+ * For tools whose output has a clear "line" notion (file reads with
147
+ * numbered prefixes, grep hits, bash stdout), the agent counts the
148
+ * actual lines the model received and forwards it here. Undefined
149
+ * for tools without a meaningful line count. */
150
+ outputLines?: number;
151
+ };
152
+ 'token.threshold': {
153
+ used: number;
154
+ limit: number;
155
+ };
156
+ 'compaction.fired': {
157
+ before: number;
158
+ after: number;
159
+ };
160
+ /**
161
+ * Fired when the auto-compaction middleware's compactor.compact() call
162
+ * throws. Compaction is best-effort by design so we don't crash the agent
163
+ * loop, but a persistent failure (misconfigured summarizer model, network
164
+ * outage) means the next iteration may hit context overflow. Observability
165
+ * layers / dashboards subscribe to this to surface the silent regression.
166
+ */
167
+ 'compaction.failed': {
168
+ err: Error;
169
+ aggressive: boolean;
170
+ level: 'warn' | 'soft' | 'hard';
171
+ tokens: number;
172
+ maxContext: number;
173
+ load: number;
174
+ fatal: boolean;
175
+ };
176
+ 'mcp.server.connected': {
177
+ name: string;
178
+ toolCount: number;
179
+ };
180
+ 'mcp.server.reconnected': {
181
+ name: string;
182
+ toolCount: number;
183
+ };
184
+ 'mcp.server.disconnected': {
185
+ name: string;
186
+ reason: string;
187
+ };
188
+ 'token.cost_estimate_unavailable': {
189
+ model: string;
190
+ };
191
+ error: {
192
+ err: Error;
193
+ phase: string;
194
+ };
195
+ }
196
+ type EventName = keyof EventMap;
197
+ type Listener<E extends EventName> = (payload: EventMap[E]) => void;
198
+ interface EventLogger {
199
+ error(msg: string, ctx?: unknown): void;
200
+ }
201
+ declare class EventBus {
202
+ private readonly listeners;
203
+ private logger?;
204
+ setLogger(logger: EventLogger): void;
205
+ on<E extends EventName>(event: E, fn: Listener<E>): () => void;
206
+ off<E extends EventName>(event: E, fn: Listener<E>): void;
207
+ once<E extends EventName>(event: E, fn: Listener<E>): () => void;
208
+ emit<E extends EventName>(event: E, payload: EventMap[E]): void;
209
+ clear(): void;
210
+ /**
211
+ * V2-D: introspection helper. Pass an `event` to count handlers for a
212
+ * single key, or omit to get the total across every event. Used by the
213
+ * leak-detection smoke test to flag handler accumulation across runs.
214
+ */
215
+ listenerCount(event?: EventName): number;
216
+ }
217
+
218
+ export { EventBus as E, type Listener as L, type EventName as a, type EventLogger as b, type EventMap as c };
@@ -0,0 +1,260 @@
1
+ export { C as CompactorOptions, D as DefaultErrorHandler, a as DefaultRetryPolicy, H as HybridCompactor, T as ToolExecutor } from '../tool-executor-CpuJPYm9.js';
2
+ import { g as Provider, a0 as Context } from '../context-BmM2xGUZ.js';
3
+ import { C as Compactor, a as CompactReport } from '../compactor-B4mQZXf2.js';
4
+ import { M as MessageSelector } from '../selector-BbJqiEP4.js';
5
+ import { E as EventBus } from '../events-BMNaEFZl.js';
6
+ import { a as MiddlewareHandler } from '../renderer-rk_1Swwc.js';
7
+ import { A as Agent, R as RunResult } from '../plugin-DJk6LL8B.js';
8
+ import { D as DoneCondition } from '../multi-agent-fmkRHtof.js';
9
+ import { a as SkillLoader, b as SkillManifest, S as SkillEntry } from '../skill-DhfSizKv.js';
10
+ import { a as WstackPaths } from '../wstack-paths-BGu2INTm.js';
11
+ import '../models-registry-Y2xbog0E.js';
12
+ import '../observability-BhnVLBLS.js';
13
+ import '../secret-scrubber-CicHLN4G.js';
14
+ import '../config-BU9f_5yH.js';
15
+ import '../logger-BMQgxvdy.js';
16
+
17
+ interface SkillLoaderOptions {
18
+ paths: WstackPaths;
19
+ bundledDir?: string;
20
+ }
21
+ /**
22
+ * Discovery order (later layers shadow earlier ones at boot, but we walk
23
+ * highest priority first and skip names already seen):
24
+ * 1. Project-committed: <project>/.wrongstack/skills/
25
+ * 2. User-global: ~/.wrongstack/skills/
26
+ * 3. Bundled with build: packages/core/skills/
27
+ */
28
+ declare class DefaultSkillLoader implements SkillLoader {
29
+ private readonly dirs;
30
+ private cache?;
31
+ constructor(opts: SkillLoaderOptions);
32
+ list(): Promise<SkillManifest[]>;
33
+ find(name: string): Promise<SkillManifest | undefined>;
34
+ manifestText(): Promise<string>;
35
+ listEntries(): Promise<SkillEntry[]>;
36
+ readBody(name: string): Promise<string>;
37
+ }
38
+
39
+ /**
40
+ * Options for IntelligentCompactor.
41
+ */
42
+ interface IntelligentCompactorOptions {
43
+ /** Provider to use for LLM-assisted summarization. Required. */
44
+ provider: Provider;
45
+ /** Fraction of maxContext that triggers a warning (default 0.6). */
46
+ warnThreshold?: number;
47
+ /** Fraction of maxContext that triggers soft compaction (default 0.75). */
48
+ softThreshold?: number;
49
+ /** Fraction of maxContext that triggers hard compaction (default 0.9). */
50
+ hardThreshold?: number;
51
+ /** Max context window in tokens (used only for threshold fraction math). */
52
+ maxContext?: number;
53
+ /** How many recent (user+assistant) pairs to always preserve (default 4). */
54
+ preserveK?: number;
55
+ /** Token threshold below which tool results are not elided (default 500). */
56
+ eliseThreshold?: number;
57
+ /** System prompt for the summarizer sub-LLM. */
58
+ summarizerPrompt?: string;
59
+ /**
60
+ * Model ID to use for summarization. When not set, the same model as the
61
+ * agent is used (which risks cascading failure on context overflow). Set to
62
+ * a fast/cheap model like `claude-3-5-haiku-20240620` for resilience.
63
+ */
64
+ summarizerModel?: string;
65
+ }
66
+ /**
67
+ * IntelligentCompactor uses an LLM to:
68
+ * - Analyze message importance and preserve critical context
69
+ * - Generate semantic summaries for old message ranges
70
+ * - Make intelligent decisions about what to compact
71
+ *
72
+ * It extends HybridCompactor's elision logic with LLM-assisted summarization.
73
+ */
74
+ declare class IntelligentCompactor implements Compactor {
75
+ private readonly provider;
76
+ private readonly warnThreshold;
77
+ private readonly softThreshold;
78
+ private readonly hardThreshold;
79
+ private readonly maxContext;
80
+ private readonly preserveK;
81
+ private readonly eliseThreshold;
82
+ private readonly summarizerPrompt;
83
+ private readonly summarizerModel?;
84
+ constructor(opts: IntelligentCompactorOptions);
85
+ compact(ctx: Context, opts?: {
86
+ aggressive?: boolean;
87
+ }): Promise<CompactReport>;
88
+ private summarizeAncientTurns;
89
+ private findSafeBoundary;
90
+ private findExchangeStart;
91
+ private callSummarizer;
92
+ private messagesToText;
93
+ private lightweightCompact;
94
+ private eliseOldToolResults;
95
+ private hasTextContent;
96
+ private estimateTokens;
97
+ }
98
+
99
+ /**
100
+ * Options for SelectiveCompactor — the most configurable compactor.
101
+ */
102
+ interface SelectiveCompactorOptions {
103
+ /** Provider for LLM calls (selector + summarizer). Required. */
104
+ provider: Provider;
105
+ /** Selector for LLM-driven importance analysis. */
106
+ selector?: MessageSelector;
107
+ /** Fraction of maxContext that triggers a warning (default 0.6). */
108
+ warnThreshold?: number;
109
+ /** Fraction of maxContext that triggers soft compaction (default 0.75). */
110
+ softThreshold?: number;
111
+ /** Fraction of maxContext that triggers hard compaction (default 0.9). */
112
+ hardThreshold?: number;
113
+ /** Max context window in tokens (used for threshold fraction math). */
114
+ maxContext?: number;
115
+ /** How many recent (user+assistant) pairs to always preserve (default 4). */
116
+ preserveK?: number;
117
+ /** Token threshold below which tool results are not elided (default 500). */
118
+ eliseThreshold?: number;
119
+ /** Model for selector LLM calls (default: same as provider default). */
120
+ selectorModel?: string;
121
+ /** Summarizer model for collapsed ranges (default: same as selectorModel). */
122
+ summarizerModel?: string;
123
+ /** Prompt for the summarizer sub-LLM. */
124
+ summarizerPrompt?: string;
125
+ }
126
+ /**
127
+ * SelectiveCompactor uses an LLM-driven MessageSelector to make
128
+ * surgical decisions about which message ranges to keep vs collapse.
129
+ *
130
+ * Compared to HybridCompactor / IntelligentCompactor:
131
+ * - HybridCompactor: rule-based (preserveK + elision), no LLM calls
132
+ * - IntelligentCompactor: LLM summarization but no structured selection
133
+ * - SelectiveCompactor: full LLM-driven selection + optional summarization
134
+ */
135
+ declare class SelectiveCompactor implements Compactor {
136
+ private readonly provider;
137
+ private readonly selector;
138
+ private readonly warnThreshold;
139
+ private readonly softThreshold;
140
+ private readonly hardThreshold;
141
+ private readonly maxContext;
142
+ private readonly preserveK;
143
+ private readonly eliseThreshold;
144
+ private readonly summarizerModel;
145
+ private readonly summarizerPrompt;
146
+ constructor(opts: SelectiveCompactorOptions);
147
+ compact(ctx: Context, opts?: {
148
+ aggressive?: boolean;
149
+ }): Promise<CompactReport>;
150
+ /**
151
+ * Run the LLM selector to decide what to keep vs collapse.
152
+ * Returns the token savings achieved.
153
+ */
154
+ private runSelector;
155
+ /**
156
+ * Execute a SelectorResult plan: collapse/remove ranges and
157
+ * insert summaries where the selector provided them.
158
+ */
159
+ private executePlan;
160
+ private summarizeRange;
161
+ private messagePreview;
162
+ /**
163
+ * Fallback when selector fails: aggressively trim from the oldest end
164
+ * until we hit targetBudget.
165
+ */
166
+ private aggressiveRecencyTrim;
167
+ private computeTargetBudget;
168
+ private eliseOldToolResults;
169
+ private hasTextContent;
170
+ private estimateTokens;
171
+ private roughTokenEstimate;
172
+ }
173
+
174
+ type CompactionFailureMode = 'throw' | 'throw_on_hard' | 'continue';
175
+ interface AutoCompactionOptions {
176
+ aggressiveOn?: 'hard' | 'soft' | 'warn';
177
+ events?: EventBus;
178
+ failureMode?: CompactionFailureMode;
179
+ }
180
+ /**
181
+ * Pipeline middleware that monitors context token load and automatically
182
+ * triggers compaction when the warn/soft/hard thresholds are crossed.
183
+ * Runs before the next agent iteration.
184
+ */
185
+ declare class AutoCompactionMiddleware {
186
+ readonly name = "AutoCompaction";
187
+ private readonly compactor;
188
+ private readonly warnThreshold;
189
+ private readonly softThreshold;
190
+ private readonly hardThreshold;
191
+ private readonly maxContext;
192
+ private readonly estimator;
193
+ private readonly aggressiveOn;
194
+ private readonly events?;
195
+ private readonly failureMode;
196
+ /**
197
+ * @param compactor Compactor to use for compaction.
198
+ * @param maxContext Provider's max context window in tokens.
199
+ * @param estimator Token estimation function.
200
+ * @param thresholds Threshold fractions (0-1) of maxContext.
201
+ * @param opts Optional behavior. By default, failures at the
202
+ * hard threshold throw AGENT_CONTEXT_OVERFLOW so
203
+ * the agent does not continue into a likely
204
+ * provider context overflow. Warn/soft failures
205
+ * still emit compaction.failed and continue.
206
+ */
207
+ constructor(compactor: Compactor, maxContext: number, estimator: (ctx: Context) => number, thresholds: {
208
+ warn: number;
209
+ soft: number;
210
+ hard: number;
211
+ }, optsOrAggressiveOn?: AutoCompactionOptions | 'hard' | 'soft' | 'warn', events?: EventBus);
212
+ handler(): MiddlewareHandler<Context>;
213
+ private compact;
214
+ }
215
+
216
+ type AutonomousResult = RunResult & {
217
+ toolCalls: number;
218
+ reason?: string;
219
+ };
220
+ interface DoneCheckResult {
221
+ done: boolean;
222
+ reason?: string;
223
+ iterations: number;
224
+ toolCalls: number;
225
+ }
226
+ declare class DoneConditionChecker {
227
+ private readonly condition;
228
+ private readonly compiledRegex;
229
+ constructor(condition: DoneCondition);
230
+ check(state: {
231
+ iterations: number;
232
+ toolCalls: number;
233
+ lastOutput?: string;
234
+ }): DoneCheckResult;
235
+ }
236
+ interface AutonomousRunnerOptions {
237
+ agent: Agent;
238
+ context: Context;
239
+ doneCondition: DoneCondition;
240
+ iterationTimeoutMs?: number;
241
+ onIteration?: (state: {
242
+ iteration: number;
243
+ toolCalls: number;
244
+ }) => void;
245
+ onDone?: (result: AutonomousResult) => void;
246
+ }
247
+ declare class AutonomousRunner {
248
+ private readonly opts;
249
+ private iterations;
250
+ private toolCalls;
251
+ private lastOutput?;
252
+ private stopped;
253
+ private readonly doneChecker;
254
+ constructor(opts: AutonomousRunnerOptions);
255
+ run(): Promise<AutonomousResult>;
256
+ private runLoop;
257
+ stop(): void;
258
+ }
259
+
260
+ export { AutoCompactionMiddleware, AutonomousRunner, type AutonomousRunnerOptions, DefaultSkillLoader, type DoneCheckResult, DoneConditionChecker, IntelligentCompactor, type IntelligentCompactorOptions, SelectiveCompactor, type SelectiveCompactorOptions, type SkillLoaderOptions };