@wrongstack/core 0.32.0 → 0.51.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 (45) hide show
  1. package/dist/{agent-bridge-D_XcS2HL.d.ts → agent-bridge-CjbD-i7-.d.ts} +1 -1
  2. package/dist/{agent-subagent-runner-DpZTLdBe.d.ts → agent-subagent-runner-DfvlBx5N.d.ts} +3 -3
  3. package/dist/{config-BUEGM4JP.d.ts → config-ZRCf7sTu.d.ts} +21 -1
  4. package/dist/coordination/index.d.ts +10 -10
  5. package/dist/coordination/index.js +3310 -3056
  6. package/dist/coordination/index.js.map +1 -1
  7. package/dist/defaults/index.d.ts +13 -13
  8. package/dist/defaults/index.js +1544 -1390
  9. package/dist/defaults/index.js.map +1 -1
  10. package/dist/{events-BrQiweXN.d.ts → events-Bt44ikPN.d.ts} +135 -1
  11. package/dist/execution/index.d.ts +35 -9
  12. package/dist/execution/index.js +61 -28
  13. package/dist/execution/index.js.map +1 -1
  14. package/dist/extension/index.d.ts +3 -3
  15. package/dist/{index-pXJdVLe0.d.ts → index-OzA1XjHL.d.ts} +35 -3
  16. package/dist/{index-ysfO_DlX.d.ts → index-mAWBdLyJ.d.ts} +2 -2
  17. package/dist/index.d.ts +221 -25
  18. package/dist/index.js +1670 -1017
  19. package/dist/index.js.map +1 -1
  20. package/dist/infrastructure/index.d.ts +4 -4
  21. package/dist/infrastructure/index.js +17 -3
  22. package/dist/infrastructure/index.js.map +1 -1
  23. package/dist/kernel/index.d.ts +4 -4
  24. package/dist/kernel/index.js +3 -1
  25. package/dist/kernel/index.js.map +1 -1
  26. package/dist/{mcp-servers-BzB3r7_c.d.ts → mcp-servers-DONdo-XM.d.ts} +1 -1
  27. package/dist/models/index.js +5 -2
  28. package/dist/models/index.js.map +1 -1
  29. package/dist/{multi-agent-C8Z1i__e.d.ts → multi-agent-Ba9Ni2hC.d.ts} +1 -1
  30. package/dist/{multi-agent-coordinator-DOXSgtom.d.ts → multi-agent-coordinator-BuKq0q89.d.ts} +2 -2
  31. package/dist/{null-fleet-bus-DLsUjOyB.d.ts → null-fleet-bus-C0xd73YP.d.ts} +169 -138
  32. package/dist/observability/index.d.ts +1 -1
  33. package/dist/{path-resolver-DumKAi0n.d.ts → path-resolver-nkmdiFgi.d.ts} +1 -1
  34. package/dist/{plan-templates-BZMi-VpU.d.ts → plan-templates-BmDdJ7UL.d.ts} +2 -2
  35. package/dist/{provider-runner-Dlv8Fvw9.d.ts → provider-runner-BGro2qQB.d.ts} +1 -1
  36. package/dist/sdd/index.d.ts +5 -5
  37. package/dist/storage/index.d.ts +3 -3
  38. package/dist/{tool-executor-BAi4WI2d.d.ts → tool-executor-p4tP9tGF.d.ts} +1 -1
  39. package/dist/types/index.d.ts +8 -8
  40. package/dist/types/index.js +22 -5
  41. package/dist/types/index.js.map +1 -1
  42. package/dist/utils/index.d.ts +107 -1
  43. package/dist/utils/index.js +53 -2
  44. package/dist/utils/index.js.map +1 -1
  45. package/package.json +1 -1
@@ -1,11 +1,139 @@
1
1
  import { $ as Usage, d as Context, X as ToolProgressEvent, Q as Tool } from './context-7u93AcGD.js';
2
2
 
3
+ /**
4
+ * Brain coordination primitives.
5
+ *
6
+ * Brain is an authority layer above a leader/director but below the human. It is
7
+ * intentionally modeled as a decision interface first, not as an autonomous
8
+ * bypass: callers ask for a decision, Brain either answers within policy or
9
+ * escalates to the human.
10
+ */
11
+
12
+ type BrainDecisionSource = 'autophase' | 'director' | 'tool' | 'user' | 'system';
13
+ type BrainRisk = 'low' | 'medium' | 'high' | 'critical';
14
+ type BrainFallback = 'ask_human' | 'deny' | 'continue';
15
+ interface BrainDecisionOption {
16
+ id: string;
17
+ label: string;
18
+ consequence?: string;
19
+ risk?: BrainRisk;
20
+ recommended?: boolean;
21
+ }
22
+ interface BrainDecisionRequest {
23
+ id: string;
24
+ source: BrainDecisionSource;
25
+ question: string;
26
+ context?: string;
27
+ options?: BrainDecisionOption[];
28
+ risk: BrainRisk;
29
+ /** What a non-LLM/default Brain should do when policy cannot decide safely. */
30
+ fallback: BrainFallback;
31
+ }
32
+ type BrainDecision = {
33
+ type: 'answer';
34
+ optionId?: string;
35
+ text: string;
36
+ rationale?: string;
37
+ } | {
38
+ type: 'ask_human';
39
+ prompt: string;
40
+ options?: BrainDecisionOption[];
41
+ rationale?: string;
42
+ } | {
43
+ type: 'deny';
44
+ reason: string;
45
+ };
46
+ interface BrainArbiter {
47
+ decide(request: BrainDecisionRequest): Promise<BrainDecision>;
48
+ }
49
+ /**
50
+ * Event-emitting decorator for any Brain implementation. Hosts wire this around
51
+ * their actual arbiter so TUI/session surfaces can render Brain decisions
52
+ * without coupling to the caller that requested the decision.
53
+ */
54
+ declare class ObservableBrainArbiter implements BrainArbiter {
55
+ private readonly inner;
56
+ private readonly events;
57
+ constructor(inner: BrainArbiter, events: EventBus);
58
+ decide(request: BrainDecisionRequest): Promise<BrainDecision>;
59
+ }
60
+ interface BrainDecisionQueueOptions {
61
+ /** Safety fallback if the human never answers. Default: no timeout. */
62
+ timeoutMs?: number;
63
+ }
64
+ /**
65
+ * Bridge between an `ask_human` Brain decision and the UI. It emits the visible
66
+ * ask-human event, then resolves when the TUI emits `brain.human_answered`.
67
+ */
68
+ declare class BrainDecisionQueue {
69
+ private readonly events;
70
+ private readonly opts;
71
+ private readonly pending;
72
+ private readonly offAnswer;
73
+ constructor(events: EventBus, opts?: BrainDecisionQueueOptions);
74
+ requestHumanDecision(request: BrainDecisionRequest): Promise<BrainDecision>;
75
+ dispose(): void;
76
+ }
77
+ /**
78
+ * Decorator that turns `ask_human` into an actual awaited human decision.
79
+ * The wrapped Brain remains policy-only; this layer owns the UI/event bridge.
80
+ */
81
+ declare class HumanEscalatingBrainArbiter implements BrainArbiter {
82
+ private readonly inner;
83
+ private readonly queue;
84
+ constructor(inner: BrainArbiter, queue: BrainDecisionQueue);
85
+ decide(request: BrainDecisionRequest): Promise<BrainDecision>;
86
+ }
87
+ interface DefaultBrainArbiterOptions {
88
+ /** Allow deterministic auto-answering for low-risk requests. Default true. */
89
+ allowLowRiskAutoAnswer?: boolean;
90
+ }
91
+ /**
92
+ * Conservative deterministic Brain implementation.
93
+ *
94
+ * It only auto-answers low-risk requests when the caller provided a recommended
95
+ * option. Everything else follows the request fallback. This gives hosts a safe
96
+ * policy object to wire before an LLM-backed Brain exists.
97
+ */
98
+ declare class DefaultBrainArbiter implements BrainArbiter {
99
+ private readonly allowLowRiskAutoAnswer;
100
+ constructor(opts?: DefaultBrainArbiterOptions);
101
+ decide(request: BrainDecisionRequest): Promise<BrainDecision>;
102
+ }
103
+ declare function formatHumanPrompt(request: BrainDecisionRequest): string;
104
+
3
105
  /**
4
106
  * EventBus — observe-only typed event bus.
5
107
  * Subscribers cannot modify or cancel. Subscriber exceptions are caught.
6
108
  */
7
109
 
8
110
  interface EventMap {
111
+ 'brain.decision_requested': {
112
+ request: BrainDecisionRequest;
113
+ at: number;
114
+ };
115
+ 'brain.decision_answered': {
116
+ request: BrainDecisionRequest;
117
+ decision: BrainDecision;
118
+ at: number;
119
+ };
120
+ 'brain.decision_ask_human': {
121
+ request: BrainDecisionRequest;
122
+ decision: BrainDecision;
123
+ at: number;
124
+ };
125
+ 'brain.human_answered': {
126
+ id: string;
127
+ optionId?: string;
128
+ deny?: boolean;
129
+ text?: string;
130
+ at: number;
131
+ };
132
+ 'brain.decision_denied': {
133
+ request: BrainDecisionRequest;
134
+ decision: BrainDecision;
135
+ at: number;
136
+ };
9
137
  'session.started': {
10
138
  id: string;
11
139
  };
@@ -174,6 +302,12 @@ interface EventMap {
174
302
  /** Provider's max context window. */
175
303
  maxContext: number;
176
304
  };
305
+ /** Fired when the active model's resolved context window changes. */
306
+ 'ctx.max_context': {
307
+ providerId: string;
308
+ modelId: string;
309
+ maxContext: number;
310
+ };
177
311
  'token.threshold': {
178
312
  used: number;
179
313
  limit: number;
@@ -654,4 +788,4 @@ declare class ScopedEventBus extends EventBus {
654
788
  get scopedListenerCount(): number;
655
789
  }
656
790
 
657
- export { EventBus as E, type Listener as L, ScopedEventBus as S, type EventLogger as a, type EventMap as b, type EventName as c };
791
+ export { type BrainArbiter as B, DefaultBrainArbiter as D, EventBus as E, HumanEscalatingBrainArbiter as H, type Listener as L, ObservableBrainArbiter as O, ScopedEventBus as S, type BrainDecision as a, type BrainDecisionOption as b, BrainDecisionQueue as c, type BrainDecisionRequest as d, type BrainDecisionSource as e, type BrainFallback as f, type BrainRisk as g, type DefaultBrainArbiterOptions as h, type EventLogger as i, type EventMap as j, type EventName as k, formatHumanPrompt as l };
@@ -1,15 +1,15 @@
1
- export { C as CompactorOptions, a as DefaultErrorHandler, b as DefaultRetryPolicy, H as HybridCompactor, T as ToolExecutor } from '../tool-executor-BAi4WI2d.js';
1
+ export { C as CompactorOptions, a as DefaultErrorHandler, b as DefaultRetryPolicy, H as HybridCompactor, T as ToolExecutor } from '../tool-executor-p4tP9tGF.js';
2
2
  import { m as Provider, d as Context } from '../context-7u93AcGD.js';
3
3
  import { a as Compactor, C as CompactReport } from '../compactor-D1RHFRmF.js';
4
4
  import { M as MessageSelector } from '../selector-DmXxpFyM.js';
5
- import { E as EventBus } from '../events-BrQiweXN.js';
5
+ import { E as EventBus } from '../events-Bt44ikPN.js';
6
6
  import { b as MiddlewareHandler } from '../system-prompt-CM6zOhd2.js';
7
7
  import { a as SessionEventBridge, J as JournalEntry } from '../goal-store-BeRsj7YX.js';
8
- import { e as ContextWindowAggressiveOn, i as ContextWindowPolicy } from '../config-BUEGM4JP.js';
9
- import { c as Agent, R as RunResult, w as SystemPromptContributor } from '../index-ysfO_DlX.js';
10
- import { D as DoneCondition } from '../multi-agent-C8Z1i__e.js';
11
- import { A as AgentFactory } from '../agent-subagent-runner-DpZTLdBe.js';
12
- import { f as DispatchClassifier, d as DefaultMultiAgentCoordinator } from '../multi-agent-coordinator-DOXSgtom.js';
8
+ import { e as ContextWindowAggressiveOn, i as ContextWindowPolicy } from '../config-ZRCf7sTu.js';
9
+ import { c as Agent, R as RunResult, w as SystemPromptContributor } from '../index-mAWBdLyJ.js';
10
+ import { D as DoneCondition } from '../multi-agent-Ba9Ni2hC.js';
11
+ import { A as AgentFactory } from '../agent-subagent-runner-DfvlBx5N.js';
12
+ import { f as DispatchClassifier, d as DefaultMultiAgentCoordinator } from '../multi-agent-coordinator-BuKq0q89.js';
13
13
  import { a as SkillLoader, b as SkillManifest, S as SkillEntry } from '../skill-CxuWrsKK.js';
14
14
  import { a as WstackPaths } from '../wstack-paths-eMXnY1_X.js';
15
15
  import '../retry-policy-KF18W4dg.js';
@@ -566,6 +566,30 @@ declare class EternalAutonomyEngine {
566
566
  }
567
567
 
568
568
  type ParallelEngineState = 'idle' | 'running' | 'stopped';
569
+ type ParallelIterationStage = {
570
+ phase: 'idle';
571
+ } | {
572
+ phase: 'decompose';
573
+ } | {
574
+ phase: 'fanout';
575
+ slots: number;
576
+ } | {
577
+ phase: 'await';
578
+ taskIds: string[];
579
+ } | {
580
+ phase: 'aggregate';
581
+ successCount: number;
582
+ total: number;
583
+ goalComplete: boolean;
584
+ } | {
585
+ phase: 'sleep';
586
+ ms: number;
587
+ } | {
588
+ phase: 'stopped';
589
+ } | {
590
+ phase: 'error';
591
+ message: string;
592
+ };
569
593
  interface ParallelEternalOptions {
570
594
  /** The coordinating agent — NOT a subagent. Owns container/tools/providers. */
571
595
  agent: Agent;
@@ -586,6 +610,8 @@ interface ParallelEternalOptions {
586
610
  iterationTimeoutMs?: number;
587
611
  onIteration?: (entry: JournalEntry) => void;
588
612
  onError?: (err: Error, iteration: number) => void;
613
+ /** Per-tick phase notifications for live UI/status updates. */
614
+ onStage?: (stage: ParallelIterationStage) => void;
589
615
  gitStatusReader?: () => Promise<string>;
590
616
  now?: () => Date;
591
617
  compactor?: Compactor;
@@ -685,7 +711,7 @@ interface AutonomyPromptContributorOptions {
685
711
  * leak into interactive runs that happen to have a goal on disk and
686
712
  * teach the model loop-control markers it shouldn't emit.
687
713
  *
688
- * Typical wiring: `() => autonomyMode === 'eternal'`.
714
+ * Typical wiring: enable while `eternal` or `eternal-parallel` autonomy is active.
689
715
  */
690
716
  enabled: () => boolean;
691
717
  /** Number of journal entries to include in the recent-tail block. Default 5. */
@@ -728,4 +754,4 @@ declare function makeAutonomyPromptContributor(opts: AutonomyPromptContributorOp
728
754
  */
729
755
  declare function buildGoalPreamble(goal: string): string;
730
756
 
731
- export { AutoCompactionMiddleware, AutonomousRunner, type AutonomousRunnerOptions, type AutonomyPromptContributorOptions, DefaultSkillLoader, type DoneCheckResult, DoneConditionChecker, EternalAutonomyEngine, type EternalAutonomyOptions, type EternalEngineState, IntelligentCompactor, type IntelligentCompactorOptions, type IterationStage, type ParallelEngineState, ParallelEternalEngine, type ParallelEternalOptions, SelectiveCompactor, type SelectiveCompactorOptions, type SkillLoaderOptions, buildGoalPreamble, makeAutonomyPromptContributor };
757
+ export { AutoCompactionMiddleware, AutonomousRunner, type AutonomousRunnerOptions, type AutonomyPromptContributorOptions, DefaultSkillLoader, type DoneCheckResult, DoneConditionChecker, EternalAutonomyEngine, type EternalAutonomyOptions, type EternalEngineState, IntelligentCompactor, type IntelligentCompactorOptions, type IterationStage, type ParallelEngineState, ParallelEternalEngine, type ParallelEternalOptions, type ParallelIterationStage, SelectiveCompactor, type SelectiveCompactorOptions, type SkillLoaderOptions, buildGoalPreamble, makeAutonomyPromptContributor };
@@ -6521,8 +6521,14 @@ var ParallelEternalEngine = class {
6521
6521
  await this.runOneIteration();
6522
6522
  } catch (err) {
6523
6523
  this.consecutiveFailures++;
6524
- this.opts.onError?.(err instanceof Error ? err : new Error(String(err)), this.consecutiveFailures);
6525
- await this.appendFailure("engine error", err instanceof Error ? err.message : String(err));
6524
+ this.opts.onError?.(
6525
+ err instanceof Error ? err : new Error(String(err)),
6526
+ this.consecutiveFailures
6527
+ );
6528
+ await this.appendFailure(
6529
+ "engine error",
6530
+ err instanceof Error ? err.message : String(err)
6531
+ );
6526
6532
  }
6527
6533
  if (this.stopRequested) break;
6528
6534
  await sleep2(2e3);
@@ -6538,14 +6544,19 @@ var ParallelEternalEngine = class {
6538
6544
  * Called by the REPL in its main loop (REPL drives, engine is stateless per tick).
6539
6545
  */
6540
6546
  async runOneIteration() {
6547
+ const emit = (stage) => {
6548
+ this.opts.onStage?.(stage);
6549
+ };
6541
6550
  this.iterations++;
6542
6551
  const goal = await loadGoal(this.goalPath);
6543
6552
  if (!goal) {
6544
6553
  this.stopRequested = true;
6554
+ emit({ phase: "stopped" });
6545
6555
  return false;
6546
6556
  }
6547
6557
  if (goal.goalState !== "active") {
6548
6558
  this.stopRequested = true;
6559
+ emit({ phase: "stopped" });
6549
6560
  return false;
6550
6561
  }
6551
6562
  if (!this.coordinator) {
@@ -6558,10 +6569,13 @@ var ParallelEternalEngine = class {
6558
6569
  const runner = makeAgentSubagentRunner({ factory: this.agentFactory });
6559
6570
  this.coordinator.setRunner?.(runner);
6560
6571
  }
6572
+ emit({ phase: "decompose" });
6561
6573
  const tasks = await this.decomposeGoal(goal);
6562
6574
  if (!tasks || tasks.length === 0) {
6575
+ emit({ phase: "sleep", ms: 2e3 });
6563
6576
  return false;
6564
6577
  }
6578
+ emit({ phase: "fanout", slots: Math.min(this.slots, tasks.length) });
6565
6579
  const fanOut = await this.fanOut(goal, tasks);
6566
6580
  this.iterationsSinceCompact++;
6567
6581
  const successCount = fanOut.results.filter((r) => r.status === "success").length;
@@ -6578,12 +6592,20 @@ var ParallelEternalEngine = class {
6578
6592
  status,
6579
6593
  note
6580
6594
  });
6595
+ emit({
6596
+ phase: "aggregate",
6597
+ successCount,
6598
+ total: fanOut.results.length,
6599
+ goalComplete: fanOut.goalComplete
6600
+ });
6581
6601
  if (fanOut.goalComplete) {
6582
6602
  this.stopRequested = true;
6583
6603
  this.state = "stopped";
6604
+ emit({ phase: "stopped" });
6584
6605
  return true;
6585
6606
  }
6586
6607
  await this.maybeCompact();
6608
+ emit({ phase: "sleep", ms: 2e3 });
6587
6609
  return fanOut.allSuccessful;
6588
6610
  }
6589
6611
  // -------------------------------------------------------------------------
@@ -6597,7 +6619,9 @@ var ParallelEternalEngine = class {
6597
6619
  (t) => dispatchAgent(t, { classifier: this.dispatchClassifier }).catch(() => null)
6598
6620
  )
6599
6621
  ) : [];
6600
- const recentJournal = goal.journal.slice(-5).map((e) => ` #${e.iteration} [${e.status}] ${e.task}${e.note ? ` \u2014 ${e.note.slice(0, 80)}` : ""}`).join("\n");
6622
+ const recentJournal = goal.journal.slice(-5).map(
6623
+ (e) => ` #${e.iteration} [${e.status}] ${e.task}${e.note ? ` \u2014 ${e.note.slice(0, 80)}` : ""}`
6624
+ ).join("\n");
6601
6625
  const directivePreamble = [
6602
6626
  "\u2550\u2550\u2550 ETERNAL AUTONOMY \u2014 parallel task slot \u2550\u2550\u2550",
6603
6627
  "",
@@ -6640,35 +6664,44 @@ ${personaLine}Task: ${task}
6640
6664
  role: route?.role ?? "generic",
6641
6665
  method: route?.method ?? "none"
6642
6666
  });
6643
- spawnPromises.push((async () => {
6644
- try {
6645
- await coordinator.spawn(
6646
- route ? {
6647
- id: subagentId,
6648
- name: route.definition.config.name,
6649
- role: route.role,
6650
- tools: route.definition.config.tools,
6651
- systemPromptOverride: route.definition.config.prompt,
6652
- timeoutMs: this.timeoutMs
6653
- } : {
6654
- id: subagentId,
6655
- name: `slot-${subagentId.slice(-6)}`,
6656
- // Let the coordinator apply its default budget (roster or generic).
6657
- // Hardcoding low limits here defeats the x10 budget improvement.
6658
- timeoutMs: this.timeoutMs
6659
- }
6660
- );
6661
- subagentIds.push(subagentId);
6662
- taskIds.push(taskId);
6663
- await coordinator.assign(spec);
6664
- } catch {
6665
- }
6666
- })());
6667
+ spawnPromises.push(
6668
+ (async () => {
6669
+ try {
6670
+ await coordinator.spawn(
6671
+ route ? {
6672
+ id: subagentId,
6673
+ name: route.definition.config.name,
6674
+ role: route.role,
6675
+ tools: route.definition.config.tools,
6676
+ systemPromptOverride: route.definition.config.prompt,
6677
+ timeoutMs: this.timeoutMs
6678
+ } : {
6679
+ id: subagentId,
6680
+ name: `slot-${subagentId.slice(-6)}`,
6681
+ // Let the coordinator apply its default budget (roster or generic).
6682
+ // Hardcoding low limits here defeats the x10 budget improvement.
6683
+ timeoutMs: this.timeoutMs
6684
+ }
6685
+ );
6686
+ subagentIds.push(subagentId);
6687
+ taskIds.push(taskId);
6688
+ await coordinator.assign(spec);
6689
+ } catch {
6690
+ }
6691
+ })()
6692
+ );
6667
6693
  }
6668
6694
  await Promise.all(spawnPromises);
6669
6695
  if (taskIds.length === 0) {
6670
- return { results: [], allSuccessful: false, goalComplete: false, partialOutput: "", routes: routeInfo };
6696
+ return {
6697
+ results: [],
6698
+ allSuccessful: false,
6699
+ goalComplete: false,
6700
+ partialOutput: "",
6701
+ routes: routeInfo
6702
+ };
6671
6703
  }
6704
+ this.opts.onStage?.({ phase: "await", taskIds: [...taskIds] });
6672
6705
  let results = [];
6673
6706
  try {
6674
6707
  const ctrl = new AbortController();