@wrongstack/core 0.6.0 → 0.6.3

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 (41) hide show
  1. package/dist/{agent-bridge-BKNiE1VH.d.ts → agent-bridge-eb7qnNrd.d.ts} +1 -1
  2. package/dist/coordination/index.d.ts +5 -5
  3. package/dist/coordination/index.js +183 -87
  4. package/dist/coordination/index.js.map +1 -1
  5. package/dist/defaults/index.d.ts +10 -10
  6. package/dist/defaults/index.js +596 -114
  7. package/dist/defaults/index.js.map +1 -1
  8. package/dist/{events-DPQKFX7W.d.ts → events-BHuIHekD.d.ts} +27 -4
  9. package/dist/execution/index.d.ts +149 -6
  10. package/dist/execution/index.js +401 -21
  11. package/dist/execution/index.js.map +1 -1
  12. package/dist/extension/index.d.ts +2 -2
  13. package/dist/{goal-store-BQ3YX1h1.d.ts → goal-store-DVCfj7Ff.d.ts} +20 -0
  14. package/dist/{index-B0qTujQW.d.ts → index-BOn9NK7D.d.ts} +1 -1
  15. package/dist/{index-DkdRz6yK.d.ts → index-CPcDqvZh.d.ts} +11 -4
  16. package/dist/index.d.ts +50 -16
  17. package/dist/index.js +831 -125
  18. package/dist/index.js.map +1 -1
  19. package/dist/infrastructure/index.d.ts +2 -2
  20. package/dist/infrastructure/index.js +1 -1
  21. package/dist/infrastructure/index.js.map +1 -1
  22. package/dist/kernel/index.d.ts +2 -2
  23. package/dist/kernel/index.js.map +1 -1
  24. package/dist/{multi-agent-Cpp7FXUl.d.ts → multi-agent-CxSb-9dQ.d.ts} +30 -5
  25. package/dist/observability/index.d.ts +1 -1
  26. package/dist/observability/index.js +1 -1
  27. package/dist/observability/index.js.map +1 -1
  28. package/dist/{path-resolver--g_hKJ7V.d.ts → path-resolver-CMGNadvq.d.ts} +1 -1
  29. package/dist/{plan-templates-CKJs_sYh.d.ts → plan-templates-BJflQY2i.d.ts} +1 -1
  30. package/dist/{provider-runner-hl4Il3xS.d.ts → provider-runner-BFgNXpaP.d.ts} +1 -1
  31. package/dist/sdd/index.d.ts +2 -2
  32. package/dist/storage/index.d.ts +3 -3
  33. package/dist/storage/index.js +3 -0
  34. package/dist/storage/index.js.map +1 -1
  35. package/dist/{tool-executor-B03CRwu-.d.ts → tool-executor-FoxBjULX.d.ts} +1 -1
  36. package/dist/types/index.d.ts +7 -7
  37. package/dist/types/index.js +30 -4
  38. package/dist/types/index.js.map +1 -1
  39. package/dist/utils/index.js +1 -1
  40. package/dist/utils/index.js.map +1 -1
  41. package/package.json +5 -1
@@ -57,6 +57,7 @@ interface EventMap {
57
57
  'provider.tool_use_stop': {
58
58
  ctx: Context;
59
59
  id: string;
60
+ name: string;
60
61
  };
61
62
  /**
62
63
  * Fired before each retry of a failed provider call. `attempt` is 1-based
@@ -175,15 +176,20 @@ interface EventMap {
175
176
  * runner/budget classes.
176
177
  */
177
178
  'budget.threshold_reached': {
178
- kind: 'iterations' | 'tool_calls' | 'tokens' | 'cost';
179
+ kind: 'iterations' | 'tool_calls' | 'tokens' | 'cost' | 'timeout';
179
180
  used: number;
180
181
  limit: number;
181
- /** Call to grant more of the same budget type. */
182
+ /**
183
+ * Call to grant more of the same budget type. `timeoutMs` extends the
184
+ * wall-clock budget; the coordinator's watchdog observes the patched
185
+ * limit and re-arms its timer for the new remainder.
186
+ */
182
187
  extend: (extra: Partial<{
183
188
  maxIterations: number;
184
189
  maxToolCalls: number;
185
190
  maxTokens: number;
186
191
  maxCostUsd: number;
192
+ timeoutMs: number;
187
193
  }>) => void;
188
194
  /** Call to deny the extension — subagent will stop. */
189
195
  deny: () => void;
@@ -198,8 +204,25 @@ interface EventMap {
198
204
  removedMessages: number;
199
205
  };
200
206
  'compaction.fired': {
201
- before: number;
202
- after: number;
207
+ /** Threshold level that triggered compaction (warn / soft / hard). */
208
+ level: 'warn' | 'soft' | 'hard';
209
+ /** Tokens estimated before compaction ran. */
210
+ tokens: number;
211
+ /** Fraction of maxContext at the time compaction fired. */
212
+ load: number;
213
+ /** Provider's max context window in tokens. */
214
+ maxContext: number;
215
+ /** Full compaction report from the compactor. */
216
+ report: {
217
+ before: number;
218
+ after: number;
219
+ reductions: {
220
+ phase: string;
221
+ saved: number;
222
+ }[];
223
+ };
224
+ /** Whether aggressive (summary) mode was used. */
225
+ aggressive: boolean;
203
226
  };
204
227
  /**
205
228
  * Fired when the auto-compaction middleware's compactor.compact() call
@@ -1,13 +1,13 @@
1
- export { C as CompactorOptions, a as DefaultErrorHandler, b as DefaultRetryPolicy, H as HybridCompactor, T as ToolExecutor } from '../tool-executor-B03CRwu-.js';
1
+ export { C as CompactorOptions, a as DefaultErrorHandler, b as DefaultRetryPolicy, H as HybridCompactor, T as ToolExecutor } from '../tool-executor-FoxBjULX.js';
2
2
  import { g as Provider, a2 as Context } from '../context-CDRyrkKQ.js';
3
3
  import { a as Compactor, C as CompactReport } from '../compactor-RIPuTtWK.js';
4
4
  import { M as MessageSelector } from '../selector-C7HqnZJU.js';
5
- import { E as EventBus } from '../events-DPQKFX7W.js';
5
+ import { E as EventBus } from '../events-BHuIHekD.js';
6
6
  import { c as MiddlewareHandler } from '../system-prompt-Dl2QY1_B.js';
7
7
  import { e as ContextWindowAggressiveOn, i as ContextWindowPolicy } from '../config-BGGuP_Ar.js';
8
- import { r as Agent, R as RunResult } from '../index-B0qTujQW.js';
9
- import { D as DoneCondition } from '../multi-agent-Cpp7FXUl.js';
10
- import { J as JournalEntry } from '../goal-store-BQ3YX1h1.js';
8
+ import { r as Agent, R as RunResult, j as SystemPromptContributor } from '../index-BOn9NK7D.js';
9
+ import { D as DoneCondition } from '../multi-agent-CxSb-9dQ.js';
10
+ import { J as JournalEntry } from '../goal-store-DVCfj7Ff.js';
11
11
  import { a as SkillLoader, b as SkillManifest, S as SkillEntry } from '../skill-CxuWrsKK.js';
12
12
  import { W as WstackPaths } from '../wstack-paths-86YPFktR.js';
13
13
  import '../retry-policy-LKS8MHsB.js';
@@ -296,6 +296,13 @@ interface EternalAutonomyOptions {
296
296
  * provider call should not freeze the whole eternal loop.
297
297
  */
298
298
  iterationTimeoutMs?: number;
299
+ /**
300
+ * Maximum number of internal agent.run iterations the engine grants per
301
+ * eternal-loop tick. The engine sets `autonomousContinue: true` so the
302
+ * agent can run multi-step tasks end-to-end within one tick instead of
303
+ * bouncing back to the engine after every single tool call. Default 50.
304
+ */
305
+ iterationMaxAgentSteps?: number;
299
306
  /**
300
307
  * Minimum sleep between iterations. Defaults to 1 s — enough for
301
308
  * SIGINT handlers to fire mid-loop without pegging a core when the
@@ -307,6 +314,22 @@ interface EternalAutonomyOptions {
307
314
  * brainstorm cycle. Default 3. Acts as a soft-recovery, not a stop.
308
315
  */
309
316
  failureBudget?: number;
317
+ /**
318
+ * Per-todo failed-attempt ceiling. When the engine picks the same todo
319
+ * and the iteration fails this many times in total, the todo is taken
320
+ * out of rotation (engine prefers other sources) until it changes
321
+ * status. Default 3. Prevents the loop from spinning forever on one
322
+ * stuck task.
323
+ */
324
+ todoMaxAttempts?: number;
325
+ /**
326
+ * Consecutive brainstorm-DONE responses required to consider the goal
327
+ * complete and stop the engine. When the LLM's brainstorm step keeps
328
+ * answering `DONE`, the engine treats that as "no more work" and, after
329
+ * this many in a row, marks the goal as completed instead of sleeping
330
+ * forever. Default 3.
331
+ */
332
+ brainstormDoneStopThreshold?: number;
310
333
  /** Side-channel notifications (logging, UI updates). */
311
334
  onIteration?: (entry: JournalEntry) => void;
312
335
  onError?: (err: Error, iteration: number) => void;
@@ -342,6 +365,20 @@ interface EternalAutonomyOptions {
342
365
  * checks (iteration cadence still applies).
343
366
  */
344
367
  maxContextTokens?: number;
368
+ /**
369
+ * Base delay (ms) for the first transient-error backoff. Subsequent
370
+ * transient failures double this, capped at `transientBackoffMaxMs`.
371
+ * Default 2_000.
372
+ *
373
+ * "Transient" means the underlying error is recoverable per
374
+ * `WrongStackError.recoverable` (ProviderError sets this for 429/529/5xx
375
+ * /network errors). Permanent errors (auth/invalid request) skip the
376
+ * backoff and count toward `failureBudget` like before — backing off
377
+ * on a permanent failure is wasted time.
378
+ */
379
+ transientBackoffBaseMs?: number;
380
+ /** Ceiling for the exponential backoff. Default 60_000 (60 s). */
381
+ transientBackoffMaxMs?: number;
345
382
  }
346
383
  type EternalEngineState = 'idle' | 'running' | 'stopped';
347
384
  declare class EternalAutonomyEngine {
@@ -349,6 +386,14 @@ declare class EternalAutonomyEngine {
349
386
  private state;
350
387
  private stopRequested;
351
388
  private consecutiveFailures;
389
+ private consecutiveBrainstormDone;
390
+ /**
391
+ * Count of consecutive transient (recoverable) provider failures. Drives
392
+ * the exponential backoff between iterations. Reset on the first
393
+ * successful iteration so a single bad afternoon doesn't permanently
394
+ * slow the loop down.
395
+ */
396
+ private consecutiveTransientRetries;
352
397
  private currentCtrl;
353
398
  private iterationsSinceCompact;
354
399
  private readonly goalPath;
@@ -401,9 +446,107 @@ declare class EternalAutonomyEngine {
401
446
  private readGitStatus;
402
447
  private brainstormTask;
403
448
  private buildDirective;
449
+ /**
450
+ * Exponential backoff for transient provider errors. `2^N * base`
451
+ * capped at `transientBackoffMaxMs`. Zero base disables backoff.
452
+ * Public-private to keep `runOneIteration` readable; the value is
453
+ * recomputed each call from the current retry count, so callers
454
+ * don't have to track state.
455
+ */
456
+ private computeTransientBackoffMs;
457
+ /**
458
+ * Sleep that wakes early if `stopRequested` flips. Polls every 250 ms
459
+ * so SIGINT / `/autonomy stop` can land in the middle of a long
460
+ * backoff instead of waiting up to a minute for the timer.
461
+ */
462
+ private sleepInterruptible;
404
463
  private appendIterationEntry;
464
+ /**
465
+ * Persistent per-todo failure counter. Skipped silently when the goal
466
+ * file has been removed (graceful clear). Each non-success iteration
467
+ * against a todo source bumps the counter by 1; `pickPendingTodo` reads
468
+ * the counter to rotate past stuck todos once they cross `todoMaxAttempts`.
469
+ */
470
+ private bumpTodoAttempt;
471
+ /**
472
+ * Flip the mission to `completed` and journal it. Called from two
473
+ * paths: (a) `[GOAL_COMPLETE]` marker in a successful iteration's
474
+ * finalText, (b) `brainstorm` returning DONE consecutively past the
475
+ * configured threshold. Idempotent — re-entry is a no-op once the
476
+ * goal is already `completed`.
477
+ */
478
+ private markGoalCompleted;
405
479
  private appendFailure;
406
480
  private persistEngineState;
407
481
  }
408
482
 
409
- export { AutoCompactionMiddleware, AutonomousRunner, type AutonomousRunnerOptions, DefaultSkillLoader, type DoneCheckResult, DoneConditionChecker, EternalAutonomyEngine, type EternalAutonomyOptions, type EternalEngineState, IntelligentCompactor, type IntelligentCompactorOptions, SelectiveCompactor, type SelectiveCompactorOptions, type SkillLoaderOptions };
483
+ /**
484
+ * System-prompt contributor that surfaces eternal-autonomy state to the
485
+ * model on every turn.
486
+ *
487
+ * Why this exists: when the engine drives a long-running loop, the
488
+ * per-iteration directive carries the rules. But the directive is a USER
489
+ * message — it scrolls out of working memory after a few compactions and
490
+ * the model forgets it's in autonomy mode (forgets `[GOAL_COMPLETE]`,
491
+ * forgets the todo-state protocol, forgets the no-confirmation rule).
492
+ * Injecting the same anchor as a CACHED system-prompt block solves that
493
+ * — the rules sit next to the identity layer and survive compactions.
494
+ *
495
+ * Block is tagged `ephemeral` so its content (journal tail, iteration
496
+ * counter) changes each turn without invalidating the upstream prefix
497
+ * cache.
498
+ */
499
+
500
+ interface AutonomyPromptContributorOptions {
501
+ /** Absolute path to the project's `goal.json`. */
502
+ goalPath: string;
503
+ /**
504
+ * Gating function. The contributor consults this on every build and
505
+ * returns an empty array when `false` — without this, the block would
506
+ * leak into interactive runs that happen to have a goal on disk and
507
+ * teach the model loop-control markers it shouldn't emit.
508
+ *
509
+ * Typical wiring: `() => autonomyMode === 'eternal'`.
510
+ */
511
+ enabled: () => boolean;
512
+ /** Number of journal entries to include in the recent-tail block. Default 5. */
513
+ journalTailSize?: number;
514
+ }
515
+ /**
516
+ * Build a contributor that renders the autonomy-state system block.
517
+ * Returns `[]` when disabled, no goal exists, or the goal has been
518
+ * completed/abandoned — all silent fast-paths.
519
+ */
520
+ declare function makeAutonomyPromptContributor(opts: AutonomyPromptContributorOptions): SystemPromptContributor;
521
+
522
+ /**
523
+ * `/goal <description>` preamble — the "no force can stop this" mode.
524
+ *
525
+ * Unlike STEERING (which redirects mid-flight), GOAL is a contract:
526
+ * the user hands over a problem, the agent commits to verifiably
527
+ * finishing it, and every iteration re-reads this preamble from the
528
+ * conversation history. The hardening is entirely prompt-level —
529
+ * the system has already removed implicit budget caps, so this
530
+ * preamble's job is to remove the MODEL's tendency to hedge, ask
531
+ * permission, or declare premature success.
532
+ *
533
+ * The four sections are intentional:
534
+ * 1. AUTHORITY — explicit grant of unbounded fan-out + model
535
+ * switching. Without this the model self-throttles ("I shouldn't
536
+ * spawn too many…") even when budgets are unlimited.
537
+ * 2. DONE — concrete bar for completion. Forces a verifiable
538
+ * artifact (test passing, file written, bug re-run clean).
539
+ * Without this the model returns "I believe it's fixed" and
540
+ * counts that as done.
541
+ * 3. NOT DONE — explicit anti-patterns. Each item is something we
542
+ * saw real agents do as a "completion" that wasn't.
543
+ * 4. PERSISTENCE — three-angle rule for blockers. Stops the model
544
+ * from giving up on the first tool failure.
545
+ *
546
+ * Located in @wrongstack/core (rather than @wrongstack/tui) so headless
547
+ * callers and the WebUI can issue `/goal set` without dragging the TUI
548
+ * package in. The tui re-exports this for backward compatibility.
549
+ */
550
+ declare function buildGoalPreamble(goal: string): string;
551
+
552
+ export { AutoCompactionMiddleware, AutonomousRunner, type AutonomousRunnerOptions, type AutonomyPromptContributorOptions, DefaultSkillLoader, type DoneCheckResult, DoneConditionChecker, EternalAutonomyEngine, type EternalAutonomyOptions, type EternalEngineState, IntelligentCompactor, type IntelligentCompactorOptions, SelectiveCompactor, type SelectiveCompactorOptions, type SkillLoaderOptions, buildGoalPreamble, makeAutonomyPromptContributor };