@wrongstack/core 0.6.5 → 0.6.6

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.
@@ -7,7 +7,7 @@ import { c as MiddlewareHandler } from '../system-prompt-gL06H9P4.js';
7
7
  import { e as ContextWindowAggressiveOn, i as ContextWindowPolicy } from '../config-DfC6g6KV.js';
8
8
  import { A as Agent, R as RunResult, j as SystemPromptContributor } from '../index-DcnXDPdY.js';
9
9
  import { D as DoneCondition } from '../multi-agent-D5IbASk_.js';
10
- import { J as JournalEntry } from '../goal-store-_Er467ya.js';
10
+ import { J as JournalEntry } from '../goal-store-HHgaq5ue.js';
11
11
  import { A as AgentFactory } from '../agent-subagent-runner-DsSm9lKN.js';
12
12
  import { a as SkillLoader, b as SkillManifest, S as SkillEntry } from '../skill-CxuWrsKK.js';
13
13
  import { W as WstackPaths } from '../wstack-paths-86YPFktR.js';
@@ -334,6 +334,13 @@ interface EternalAutonomyOptions {
334
334
  /** Side-channel notifications (logging, UI updates). */
335
335
  onIteration?: (entry: JournalEntry) => void;
336
336
  onError?: (err: Error, iteration: number) => void;
337
+ /**
338
+ * Per-iteration phase notifications for live UI updates (TUI status bar,
339
+ * etc.). Fires at each major stage transition: idle → decide → execute →
340
+ * reflect → (sleep | paused | stopped). Fire-and-forget — the engine
341
+ * does not await the callback.
342
+ */
343
+ onStage?: (stage: IterationStage) => void;
337
344
  /**
338
345
  * Optional injected git status reader — production code uses git, tests
339
346
  * stub this out so they don't shell out.
@@ -382,6 +389,33 @@ interface EternalAutonomyOptions {
382
389
  transientBackoffMaxMs?: number;
383
390
  }
384
391
  type EternalEngineState = 'idle' | 'running' | 'stopped';
392
+ /**
393
+ * Per-iteration phase emitted via `onStage` so UIs can render the
394
+ * engine's live location in the sense-decide-execute-reflect loop.
395
+ */
396
+ type IterationStage = {
397
+ phase: 'idle';
398
+ } | {
399
+ phase: 'decide';
400
+ reason: string;
401
+ } | {
402
+ phase: 'execute';
403
+ task: string;
404
+ } | {
405
+ phase: 'reflect';
406
+ status: 'success' | 'failure' | 'aborted' | 'skipped';
407
+ note?: string;
408
+ } | {
409
+ phase: 'sleep';
410
+ ms: number;
411
+ } | {
412
+ phase: 'paused';
413
+ } | {
414
+ phase: 'stopped';
415
+ } | {
416
+ phase: 'error';
417
+ message: string;
418
+ };
385
419
  declare class EternalAutonomyEngine {
386
420
  private readonly opts;
387
421
  private state;
@@ -618,4 +652,4 @@ declare function makeAutonomyPromptContributor(opts: AutonomyPromptContributorOp
618
652
  */
619
653
  declare function buildGoalPreamble(goal: string): string;
620
654
 
621
- export { AutoCompactionMiddleware, AutonomousRunner, type AutonomousRunnerOptions, type AutonomyPromptContributorOptions, DefaultSkillLoader, type DoneCheckResult, DoneConditionChecker, EternalAutonomyEngine, type EternalAutonomyOptions, type EternalEngineState, IntelligentCompactor, type IntelligentCompactorOptions, type ParallelEngineState, ParallelEternalEngine, type ParallelEternalOptions, SelectiveCompactor, type SelectiveCompactorOptions, type SkillLoaderOptions, buildGoalPreamble, makeAutonomyPromptContributor };
655
+ 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 };
@@ -1789,23 +1789,33 @@ var EternalAutonomyEngine = class {
1789
1789
  * `agent.run()` avoids race conditions on the shared Context.
1790
1790
  */
1791
1791
  async runOneIteration() {
1792
+ const emit = (stage) => {
1793
+ this.opts.onStage?.(stage);
1794
+ };
1792
1795
  const goal = await loadGoal(this.goalPath);
1793
1796
  if (!goal) {
1797
+ emit({ phase: "stopped" });
1794
1798
  this.stopRequested = true;
1795
1799
  return false;
1796
1800
  }
1797
1801
  const missionState = goal.goalState ?? "active";
1798
1802
  if (missionState !== "active") {
1803
+ emit({ phase: missionState === "paused" ? "paused" : "stopped" });
1799
1804
  this.stopRequested = true;
1800
1805
  return false;
1801
1806
  }
1807
+ emit({ phase: "decide", reason: "picking next task" });
1802
1808
  const action = await this.decide(goal);
1803
1809
  if (!action) {
1804
1810
  if (!this.stopRequested) {
1811
+ emit({ phase: "sleep", ms: 5e3 });
1805
1812
  await sleep(5e3);
1813
+ } else {
1814
+ emit({ phase: "stopped" });
1806
1815
  }
1807
1816
  return false;
1808
1817
  }
1818
+ emit({ phase: "execute", task: action.task });
1809
1819
  const ctrl = new AbortController();
1810
1820
  this.currentCtrl = ctrl;
1811
1821
  const timer = setTimeout(
@@ -1883,6 +1893,7 @@ var EternalAutonomyEngine = class {
1883
1893
  tokens,
1884
1894
  costUsd
1885
1895
  });
1896
+ emit({ phase: "reflect", status, note });
1886
1897
  let iterationIndex = 0;
1887
1898
  try {
1888
1899
  const reloaded = await loadGoal(this.goalPath);
@@ -1904,6 +1915,7 @@ var EternalAutonomyEngine = class {
1904
1915
  this.consecutiveTransientRetries++;
1905
1916
  const delay = this.computeTransientBackoffMs();
1906
1917
  if (delay > 0) {
1918
+ emit({ phase: "sleep", ms: delay });
1907
1919
  await this.sleepInterruptible(delay);
1908
1920
  }
1909
1921
  return false;
@@ -1917,6 +1929,9 @@ var EternalAutonomyEngine = class {
1917
1929
  return false;
1918
1930
  }
1919
1931
  this.consecutiveTransientRetries = 0;
1932
+ const cycleGapMs = this.opts.cycleGapMs ?? 1e3;
1933
+ emit({ phase: "sleep", ms: cycleGapMs });
1934
+ await sleep(cycleGapMs);
1920
1935
  if (GOAL_COMPLETE_MARKER.test(finalText)) {
1921
1936
  await this.markGoalCompleted(action, finalText);
1922
1937
  this.stopRequested = true;