@wrongstack/core 0.5.7 → 0.6.1
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-BKNiE1VH.d.ts → agent-bridge-DaCvA_uK.d.ts} +1 -1
- package/dist/coordination/index.d.ts +5 -5
- package/dist/coordination/index.js +218 -78
- package/dist/coordination/index.js.map +1 -1
- package/dist/defaults/index.d.ts +10 -9
- package/dist/defaults/index.js +1127 -180
- package/dist/defaults/index.js.map +1 -1
- package/dist/{events-DPQKFX7W.d.ts → events-CzkeaVVl.d.ts} +8 -2
- package/dist/execution/index.d.ts +281 -5
- package/dist/execution/index.js +785 -3
- package/dist/execution/index.js.map +1 -1
- package/dist/extension/index.d.ts +2 -2
- package/dist/extension/index.js +2 -1
- package/dist/extension/index.js.map +1 -1
- package/dist/goal-store-DVCfj7Ff.d.ts +95 -0
- package/dist/{index-j2WyAyML.d.ts → index-BkKLQjea.d.ts} +34 -2
- package/dist/{index-Bf9Bpkdc.d.ts → index-i9rPR53g.d.ts} +11 -4
- package/dist/index.d.ts +51 -16
- package/dist/index.js +1506 -247
- package/dist/index.js.map +1 -1
- package/dist/infrastructure/index.d.ts +2 -2
- package/dist/kernel/index.d.ts +2 -2
- package/dist/kernel/index.js.map +1 -1
- package/dist/models/index.js +2 -3
- package/dist/models/index.js.map +1 -1
- package/dist/{multi-agent-Cpp7FXUl.d.ts → multi-agent-MfI6dmv-.d.ts} +30 -5
- package/dist/observability/index.d.ts +1 -1
- package/dist/{path-resolver--g_hKJ7V.d.ts → path-resolver-CWINz5XR.d.ts} +1 -1
- package/dist/{plan-templates-Bveo2W8n.d.ts → plan-templates-Bne1pB4d.d.ts} +6 -5
- package/dist/{provider-runner-hl4Il3xS.d.ts → provider-runner-CZYIzeBp.d.ts} +1 -1
- package/dist/sdd/index.d.ts +5 -3
- package/dist/sdd/index.js +102 -68
- package/dist/sdd/index.js.map +1 -1
- package/dist/security/index.js +82 -82
- package/dist/security/index.js.map +1 -1
- package/dist/skills/index.js +102 -38
- package/dist/skills/index.js.map +1 -1
- package/dist/storage/index.d.ts +3 -2
- package/dist/storage/index.js +134 -22
- package/dist/storage/index.js.map +1 -1
- package/dist/{tool-executor-DbAFkHdP.d.ts → tool-executor-40Q6shR-.d.ts} +1 -1
- package/dist/types/index.d.ts +7 -7
- package/dist/types/index.js +116 -103
- package/dist/types/index.js.map +1 -1
- package/dist/utils/index.js +5 -0
- package/dist/utils/index.js.map +1 -1
- 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
|
-
/**
|
|
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;
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
export { C as CompactorOptions, a as DefaultErrorHandler, b as DefaultRetryPolicy, H as HybridCompactor, T as ToolExecutor } from '../tool-executor-
|
|
1
|
+
export { C as CompactorOptions, a as DefaultErrorHandler, b as DefaultRetryPolicy, H as HybridCompactor, T as ToolExecutor } from '../tool-executor-40Q6shR-.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-
|
|
5
|
+
import { E as EventBus } from '../events-CzkeaVVl.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-
|
|
9
|
-
import { D as DoneCondition } from '../multi-agent-
|
|
8
|
+
import { r as Agent, R as RunResult, j as SystemPromptContributor } from '../index-BkKLQjea.js';
|
|
9
|
+
import { D as DoneCondition } from '../multi-agent-MfI6dmv-.js';
|
|
10
|
+
import { J as JournalEntry } from '../goal-store-DVCfj7Ff.js';
|
|
10
11
|
import { a as SkillLoader, b as SkillManifest, S as SkillEntry } from '../skill-CxuWrsKK.js';
|
|
11
12
|
import { W as WstackPaths } from '../wstack-paths-86YPFktR.js';
|
|
12
13
|
import '../retry-policy-LKS8MHsB.js';
|
|
@@ -273,4 +274,279 @@ declare class AutonomousRunner {
|
|
|
273
274
|
stop(): void;
|
|
274
275
|
}
|
|
275
276
|
|
|
276
|
-
|
|
277
|
+
/**
|
|
278
|
+
* Sense-decide-execute-reflect loop on top of a long-running Goal.
|
|
279
|
+
*
|
|
280
|
+
* Each iteration:
|
|
281
|
+
* 1. Sense — read goal, pending todos, `git status --porcelain`.
|
|
282
|
+
* 2. Decide — pick a source (todo / git / brainstorm) and a task.
|
|
283
|
+
* 3. Execute — single agent.run with a directive prompt.
|
|
284
|
+
* 4. Reflect — append a journal entry, persist state to disk.
|
|
285
|
+
*
|
|
286
|
+
* The loop runs forever until `stop()` is called externally (REPL SIGINT
|
|
287
|
+
* handler, /autonomy stop). No internal time/cost cap by design — the
|
|
288
|
+
* user wants "sittin sene". Failures are logged and the loop continues
|
|
289
|
+
* with a different source on the next tick.
|
|
290
|
+
*/
|
|
291
|
+
interface EternalAutonomyOptions {
|
|
292
|
+
agent: Agent;
|
|
293
|
+
projectRoot: string;
|
|
294
|
+
/**
|
|
295
|
+
* Per-iteration agent timeout. Defaults to 5 minutes. A single hung
|
|
296
|
+
* provider call should not freeze the whole eternal loop.
|
|
297
|
+
*/
|
|
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;
|
|
306
|
+
/**
|
|
307
|
+
* Minimum sleep between iterations. Defaults to 1 s — enough for
|
|
308
|
+
* SIGINT handlers to fire mid-loop without pegging a core when the
|
|
309
|
+
* provider is being rate-limited.
|
|
310
|
+
*/
|
|
311
|
+
cycleGapMs?: number;
|
|
312
|
+
/**
|
|
313
|
+
* Maximum consecutive failures before the source rotation forces a
|
|
314
|
+
* brainstorm cycle. Default 3. Acts as a soft-recovery, not a stop.
|
|
315
|
+
*/
|
|
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;
|
|
333
|
+
/** Side-channel notifications (logging, UI updates). */
|
|
334
|
+
onIteration?: (entry: JournalEntry) => void;
|
|
335
|
+
onError?: (err: Error, iteration: number) => void;
|
|
336
|
+
/**
|
|
337
|
+
* Optional injected git status reader — production code uses git, tests
|
|
338
|
+
* stub this out so they don't shell out.
|
|
339
|
+
*/
|
|
340
|
+
gitStatusReader?: () => Promise<string>;
|
|
341
|
+
/**
|
|
342
|
+
* Optional clock — tests stub for deterministic timestamps.
|
|
343
|
+
*/
|
|
344
|
+
now?: () => Date;
|
|
345
|
+
/**
|
|
346
|
+
* Optional compactor. When provided, the engine runs compaction every
|
|
347
|
+
* `compactEveryNIterations` iterations to keep the agent's message
|
|
348
|
+
* history under control during multi-day eternal loops. Without
|
|
349
|
+
* compaction, an infinite loop will eventually overflow the provider's
|
|
350
|
+
* context window and start failing.
|
|
351
|
+
*/
|
|
352
|
+
compactor?: Compactor;
|
|
353
|
+
/** How many iterations between compaction calls. Default 25. */
|
|
354
|
+
compactEveryNIterations?: number;
|
|
355
|
+
/**
|
|
356
|
+
* Aggressive compaction threshold. When ctx token usage exceeds this
|
|
357
|
+
* fraction of `maxContextTokens`, compaction runs in aggressive mode
|
|
358
|
+
* regardless of the iteration cadence. 0.85 by default.
|
|
359
|
+
*/
|
|
360
|
+
aggressiveCompactRatio?: number;
|
|
361
|
+
/**
|
|
362
|
+
* Model's max context window in tokens. When set, the engine watches
|
|
363
|
+
* `currentRequestTokens()` against this and triggers aggressive compact
|
|
364
|
+
* before the next iteration would overflow. Omit to disable threshold
|
|
365
|
+
* checks (iteration cadence still applies).
|
|
366
|
+
*/
|
|
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;
|
|
382
|
+
}
|
|
383
|
+
type EternalEngineState = 'idle' | 'running' | 'stopped';
|
|
384
|
+
declare class EternalAutonomyEngine {
|
|
385
|
+
private readonly opts;
|
|
386
|
+
private state;
|
|
387
|
+
private stopRequested;
|
|
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;
|
|
397
|
+
private currentCtrl;
|
|
398
|
+
private iterationsSinceCompact;
|
|
399
|
+
private readonly goalPath;
|
|
400
|
+
constructor(opts: EternalAutonomyOptions);
|
|
401
|
+
/** Current engine state — readable for UIs. */
|
|
402
|
+
get currentState(): EternalEngineState;
|
|
403
|
+
/** Synchronously request stop. Resolves once the running iteration aborts. */
|
|
404
|
+
stop(): void;
|
|
405
|
+
/**
|
|
406
|
+
* Mark the engine as 'running' on disk + reset stop state so a new
|
|
407
|
+
* batch of `runOneIteration()` calls can proceed. Called by the REPL
|
|
408
|
+
* when the user invokes `/autonomy eternal`. Idempotent.
|
|
409
|
+
*/
|
|
410
|
+
prime(): Promise<void>;
|
|
411
|
+
/**
|
|
412
|
+
* Main loop. Returns when stop() is called or the goal file is removed.
|
|
413
|
+
* Does NOT throw — every iteration is wrapped to keep the loop alive.
|
|
414
|
+
*/
|
|
415
|
+
run(): Promise<void>;
|
|
416
|
+
/**
|
|
417
|
+
* Execute a single sense-decide-execute-reflect cycle.
|
|
418
|
+
* Returns true on success, false on handled failure / no-op.
|
|
419
|
+
*
|
|
420
|
+
* Exposed publicly so the REPL can pace iterations from its main loop
|
|
421
|
+
* — running the engine and the REPL as a single sequential consumer of
|
|
422
|
+
* `agent.run()` avoids race conditions on the shared Context.
|
|
423
|
+
*/
|
|
424
|
+
runOneIteration(): Promise<boolean>;
|
|
425
|
+
/**
|
|
426
|
+
* Run compaction when either trigger fires:
|
|
427
|
+
* - We've done >= compactEveryNIterations since the last compact.
|
|
428
|
+
* - Current request tokens exceed aggressiveCompactRatio * maxContext.
|
|
429
|
+
*
|
|
430
|
+
* The second check uses *aggressive* mode to free more headroom; the
|
|
431
|
+
* cadence check uses non-aggressive (cheaper).
|
|
432
|
+
*/
|
|
433
|
+
private maybeCompact;
|
|
434
|
+
/**
|
|
435
|
+
* Hybrid idea source.
|
|
436
|
+
* 1. Pending todos on the agent's context.
|
|
437
|
+
* 2. Dirty git working tree → propose a "review and finish this" task.
|
|
438
|
+
* 3. Otherwise: brainstorm via the LLM against the goal.
|
|
439
|
+
*
|
|
440
|
+
* After failureBudget consecutive failures, force brainstorm so the
|
|
441
|
+
* engine doesn't loop on the same broken todo or stuck git state.
|
|
442
|
+
*/
|
|
443
|
+
private decide;
|
|
444
|
+
private pickPendingTodo;
|
|
445
|
+
private pickGitTask;
|
|
446
|
+
private readGitStatus;
|
|
447
|
+
private brainstormTask;
|
|
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;
|
|
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;
|
|
479
|
+
private appendFailure;
|
|
480
|
+
private persistEngineState;
|
|
481
|
+
}
|
|
482
|
+
|
|
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 };
|