@ftrdotdev/pi-delegates 0.1.0 → 0.2.0

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 (94) hide show
  1. package/CHANGELOG.md +51 -0
  2. package/OPERATIONS.md +79 -6
  3. package/README.md +25 -17
  4. package/ROADMAP.md +21 -0
  5. package/TESTING.md +153 -318
  6. package/package.json +4 -3
  7. package/skills/pi-delegates/SKILL.md +29 -0
  8. package/skills/pi-delegates/references/launch.md +28 -0
  9. package/src/docs-contract.test.ts +106 -0
  10. package/src/domain/definitions.ts +3 -1
  11. package/src/domain/failure.ts +33 -0
  12. package/src/domain/model-source.ts +30 -0
  13. package/src/domain/orchestration/control.test.ts +69 -35
  14. package/src/domain/orchestration/control.ts +110 -89
  15. package/src/domain/orchestration/fanout.test.ts +125 -20
  16. package/src/domain/orchestration/fanout.ts +60 -22
  17. package/src/domain/orchestration/gates.test.ts +14 -15
  18. package/src/domain/orchestration/launch.test.ts +210 -11
  19. package/src/domain/orchestration/launch.ts +142 -32
  20. package/src/domain/orchestration/requests.test.ts +11 -16
  21. package/src/domain/orchestration/requests.ts +14 -1
  22. package/src/domain/orchestration/review.test.ts +89 -11
  23. package/src/domain/orchestration/run-wait.test.ts +4 -1
  24. package/src/domain/orchestration/run-wait.ts +1 -1
  25. package/src/domain/orchestration/workflow.test.ts +157 -16
  26. package/src/domain/orchestration/workflow.ts +269 -196
  27. package/src/domain/run-records.ts +214 -52
  28. package/src/domain/settlement.test.ts +186 -0
  29. package/src/domain/settlement.ts +137 -0
  30. package/src/domain/shapes.test.ts +20 -0
  31. package/src/domain/skills.test.ts +31 -20
  32. package/src/domain/skills.ts +36 -19
  33. package/src/domain/toolkit.test.ts +15 -1
  34. package/src/domain/toolkit.ts +8 -13
  35. package/src/domain/turn-budget.test.ts +37 -0
  36. package/src/domain/turn-budget.ts +23 -0
  37. package/src/domain/view.test.ts +78 -14
  38. package/src/domain/view.ts +67 -35
  39. package/src/extension/commands.test.ts +27 -23
  40. package/src/extension/commands.ts +10 -7
  41. package/src/extension/entry.test.ts +214 -56
  42. package/src/extension/entry.ts +78 -40
  43. package/src/extension/gate-alerts.test.ts +10 -8
  44. package/src/extension/inspector-command.test.ts +173 -21
  45. package/src/extension/inspector-command.ts +100 -53
  46. package/src/extension/prompt.test.ts +2 -4
  47. package/src/extension/retry-observer.test.ts +292 -0
  48. package/src/extension/retry-observer.ts +150 -0
  49. package/src/extension/settle-alerts.test.ts +579 -0
  50. package/src/extension/settle-alerts.ts +175 -0
  51. package/src/extension/shortcut.test.ts +6 -8
  52. package/src/extension/tools.test.ts +325 -24
  53. package/src/extension/tools.ts +61 -13
  54. package/src/extension/version.test.ts +21 -29
  55. package/src/goldens.test.ts +294 -0
  56. package/src/harness-policy.test.ts +13 -11
  57. package/src/layers.test.ts +309 -0
  58. package/src/layers.ts +405 -0
  59. package/src/package-manifest.test.ts +32 -19
  60. package/src/presentation/actions.test.ts +8 -8
  61. package/src/presentation/activity.test.ts +7 -8
  62. package/src/presentation/close.test.ts +14 -16
  63. package/src/presentation/inspector.test.ts +14 -11
  64. package/src/presentation/inspector.ts +27 -25
  65. package/src/presentation/overlay.test.ts +1 -3
  66. package/src/presentation/repaint.test.ts +226 -190
  67. package/src/presentation/snapshot.test.ts +5 -0
  68. package/src/presentation/status.test.ts +43 -0
  69. package/src/presentation/status.ts +30 -0
  70. package/src/presentation/strip.test.ts +13 -6
  71. package/src/presentation/strip.ts +7 -14
  72. package/src/presentation/wording.test.ts +153 -3
  73. package/src/presentation/wording.ts +78 -6
  74. package/src/runtime/bridge.ts +38 -44
  75. package/src/runtime/{timers.test.ts → clock.test.ts} +1 -1
  76. package/src/runtime/clock.ts +31 -0
  77. package/src/runtime/config.test.ts +26 -7
  78. package/src/runtime/config.ts +6 -1
  79. package/src/runtime/execution-env.test.ts +6 -8
  80. package/src/runtime/extensions.test.ts +4 -4
  81. package/src/runtime/extensions.ts +23 -11
  82. package/src/runtime/handle.ts +54 -0
  83. package/src/runtime/log.test.ts +19 -7
  84. package/src/runtime/log.ts +23 -0
  85. package/src/runtime/mcp.test.ts +29 -32
  86. package/src/runtime/mcp.ts +70 -3
  87. package/src/runtime/runtime-state.test.ts +25 -0
  88. package/src/runtime/runtime-state.ts +36 -0
  89. package/src/runtime/session-tag.ts +11 -0
  90. package/src/runtime/session.test.ts +24 -31
  91. package/src/runtime/session.ts +99 -261
  92. package/src/runtime/storage.ts +29 -0
  93. package/src/test-hygiene.test.ts +97 -0
  94. package/src/runtime/timers.ts +0 -10
@@ -1,9 +1,7 @@
1
1
  import { assert, it } from "@effect/vitest";
2
+ import { makeTempDir } from "../../test-support/platform.ts";
2
3
  import { MemoryStorage } from "@earendil-works/pi-durable";
3
4
  import { Context, Effect, Exit, Fiber, Layer, Scope, Stream } from "effect";
4
- import { mkdtemp } from "node:fs/promises";
5
- import { tmpdir } from "node:os";
6
- import { join } from "node:path";
7
5
  import { countingRuntime } from "../../test-support/counting-runtime.ts";
8
6
  import { fakeObservations } from "../../test-support/fake-observations.ts";
9
7
  import { stubHostSource } from "../../test-support/stub-model-source.ts";
@@ -16,7 +14,7 @@ import type { ChildView, RunStatus, RunView, SessionView } from "../domain/view.
16
14
  import { viewSession } from "../domain/view.ts";
17
15
  import type { LogFields, LogLevel, LogSink } from "../runtime/log.ts";
18
16
  import { HostModelAdapter } from "../runtime/models.ts";
19
- import { openSessionRuntime, type SessionRuntime } from "../runtime/session.ts";
17
+
20
18
  import type { RunActivity } from "./activity.ts";
21
19
  import {
22
20
  GATE_INDEX_ADDRESS,
@@ -27,10 +25,10 @@ import {
27
25
  liveAddress,
28
26
  runAddress,
29
27
  type InspectorReadFailed,
30
- type InspectorService,
31
28
  } from "./inspector.ts";
32
29
  import type { InspectorDeps } from "./inspector.ts";
33
30
  import type { InspectorSnapshot } from "./snapshot.ts";
31
+ import { openTestSession, type TestSession } from "../../test-support/seams.ts";
34
32
 
35
33
  const host = { model: { provider: "stub", modelId: "stub-1" }, thinkingLevel: "low" } as const;
36
34
 
@@ -49,9 +47,9 @@ const recordingLog = (): {
49
47
  };
50
48
  };
51
49
 
52
- const openRuntime = async (log?: LogSink): Promise<SessionRuntime> => {
53
- const sessionDir = await mkdtemp(join(tmpdir(), "delegates-inspector-"));
54
- return openSessionRuntime({
50
+ const openRuntime = async (log?: LogSink): Promise<TestSession> => {
51
+ const sessionDir = await makeTempDir("delegates-inspector-");
52
+ return openTestSession({
55
53
  identity: { sessionId: "s-1", sessionDir, cwd: sessionDir, agentDir: sessionDir },
56
54
  models: new HostModelAdapter(stubHostSource()),
57
55
  storage: new MemoryStorage(),
@@ -60,7 +58,7 @@ const openRuntime = async (log?: LogSink): Promise<SessionRuntime> => {
60
58
  };
61
59
 
62
60
  const withRuntime = <A, E, R>(
63
- use: (runtime: SessionRuntime) => Effect.Effect<A, E, R>,
61
+ use: (runtime: TestSession) => Effect.Effect<A, E, R>,
64
62
  log?: LogSink,
65
63
  ): Effect.Effect<A, E, R> =>
66
64
  Effect.acquireUseRelease(
@@ -84,6 +82,9 @@ const runView = (
84
82
  gates: [],
85
83
  requests: [],
86
84
  diagnostic: null,
85
+ execution: "wait",
86
+ maxTurns: null,
87
+ failure: null,
87
88
  ...input,
88
89
  });
89
90
 
@@ -96,6 +97,8 @@ const childView = (
96
97
  status: "running",
97
98
  answer: null,
98
99
  durationMs: null,
100
+ maxTurns: null,
101
+ failure: null,
99
102
  ...input,
100
103
  });
101
104
 
@@ -141,7 +144,7 @@ const scriptedViews = (
141
144
  };
142
145
 
143
146
  interface Built {
144
- readonly inspector: InspectorService;
147
+ readonly inspector: Inspector["Service"];
145
148
  readonly scope: Scope.Closeable;
146
149
  }
147
150
 
@@ -173,7 +176,7 @@ const until = Effect.fn("until")(function* (
173
176
  });
174
177
 
175
178
  const collect = Effect.fn("collectChanges")(function* (
176
- inspector: InspectorService,
179
+ inspector: Inspector["Service"],
177
180
  ): Effect.fn.Return<{ readonly seen: InspectorSnapshot[]; readonly fiber: Fiber.Fiber<void> }> {
178
181
  const seen: InspectorSnapshot[] = [];
179
182
  const fiber = yield* Effect.forkChild(
@@ -29,7 +29,7 @@ import {
29
29
  } from "../runtime/observe.ts";
30
30
  import type { SessionRuntime } from "../runtime/session.ts";
31
31
  import type { RuntimeState } from "../runtime/session.ts";
32
- import type { Timers } from "../runtime/timers.ts";
32
+ import type { Timers } from "../runtime/clock.ts";
33
33
  import { watchActivity as attachActivity, type RunActivity } from "./activity.ts";
34
34
  import {
35
35
  emptySnapshot,
@@ -117,19 +117,6 @@ const realSeam = (runtime: SessionRuntime): ObservationSeam => ({
117
117
  attachActivity(runtime, conversationId, onActivity, onEnd),
118
118
  });
119
119
 
120
- export interface InspectorService {
121
- /** The snapshot that is current now. */
122
- readonly snapshot: Effect.Effect<InspectorSnapshot>;
123
- /** The current snapshot, then one value per publication. */
124
- readonly changes: Stream.Stream<InspectorSnapshot>;
125
- /** One committed read, one projection, one reconciliation, one publication if the content moved. */
126
- readonly refresh: Effect.Effect<void>;
127
- /** Recompose from the cached view: no read, only a changed age publishes. */
128
- readonly repaint: Effect.Effect<void>;
129
- /** The single end event: a runtime end, or the owner's scope closing. */
130
- readonly end: Stream.Stream<InspectorEnd>;
131
- }
132
-
133
120
  /** A lifecycle state as an end event; only `failing` and `closed` are ends. */
134
121
  const endFor = (state: RuntimeState): InspectorEnd =>
135
122
  state.kind === "failing" || state.kind === "closed"
@@ -153,9 +140,21 @@ const sleepFor = (timers: Timers, ms: number): Effect.Effect<void> =>
153
140
  * committed read; an activity signal re-projects the cached view and reads
154
141
  * nothing. It never writes.
155
142
  */
156
- export class Inspector extends Context.Service<Inspector, InspectorService>()(
157
- "@ftrdotdev/pi-delegates/presentation/inspector",
158
- ) {
143
+ export class Inspector extends Context.Service<
144
+ Inspector,
145
+ {
146
+ /** The snapshot that is current now. */
147
+ readonly snapshot: Effect.Effect<InspectorSnapshot>;
148
+ /** The current snapshot, then one value per publication. */
149
+ readonly changes: Stream.Stream<InspectorSnapshot>;
150
+ /** One committed read, one projection, one reconciliation, one publication if the content moved. */
151
+ readonly refresh: Effect.Effect<void>;
152
+ /** Recompose from the cached view: no read, only a changed age publishes. */
153
+ readonly repaint: Effect.Effect<void>;
154
+ /** The single end event: a runtime end, or the owner's scope closing. */
155
+ readonly end: Stream.Stream<InspectorEnd>;
156
+ }
157
+ >()("@ftrdotdev/pi-delegates/presentation/inspector") {
159
158
  static readonly layer = (deps: InspectorDeps): Layer.Layer<Inspector, InspectorReadFailed> =>
160
159
  Layer.effect(
161
160
  Inspector,
@@ -344,14 +343,16 @@ export class Inspector extends Context.Service<Inspector, InspectorService>()(
344
343
  );
345
344
  });
346
345
 
347
- const logRefreshFailure = (cause: Cause.Cause<unknown>): Effect.Effect<void> =>
348
- Effect.sync(() => {
349
- deps.runtime.log.write("warn", "inspector.refresh_failed", describeFailure(cause));
350
- });
346
+ const logRefreshFailure = (cause: Cause.Cause<unknown>): void => {
347
+ deps.runtime.log.write("warn", "inspector.refresh_failed", describeFailure(cause));
348
+ };
351
349
 
352
350
  /** The member call never fails: a failed refresh is one log entry. */
353
351
  const refresh: Effect.Effect<void> = readAndPublish.pipe(
354
- Effect.catchCause(logRefreshFailure),
352
+ Effect.catchCause((cause) => {
353
+ logRefreshFailure(cause);
354
+ return Effect.void;
355
+ }),
355
356
  );
356
357
 
357
358
  /** Recompose from the cached view: no read, and an unchanged age publishes nothing. */
@@ -382,9 +383,10 @@ export class Inspector extends Context.Service<Inspector, InspectorService>()(
382
383
  yield* Effect.yieldNow;
383
384
  const consumerFiber = yield* Queue.take(pending).pipe(
384
385
  Effect.flatMap((signal) =>
385
- Effect.catchCause(signal.kind === "doc" ? refresh : foldActivity(signal), (cause) =>
386
- logRefreshFailure(cause),
387
- ),
386
+ Effect.catchCause(signal.kind === "doc" ? refresh : foldActivity(signal), (cause) => {
387
+ logRefreshFailure(cause);
388
+ return Effect.void;
389
+ }),
388
390
  ),
389
391
  Effect.forever,
390
392
  Effect.forkScoped,
@@ -1,7 +1,6 @@
1
1
  import { assert, it } from "@effect/vitest";
2
2
  import type { Theme } from "@earendil-works/pi-coding-agent";
3
3
  import { visibleWidth } from "@earendil-works/pi-tui";
4
- import { Effect } from "effect";
5
4
  import { VimRouter } from "@ftrdotdev/pi-tui";
6
5
  import type { GateRow, InspectorRow, InspectorSnapshot, RequestRow } from "./snapshot.ts";
7
6
  import { makeDelegatesOverlay, rowsOf } from "./overlay.ts";
@@ -20,8 +19,7 @@ const plainTheme = {
20
19
  style: (text: string): string => text,
21
20
  } as unknown as Theme;
22
21
 
23
- const vimRouter = (enabled: boolean): VimRouter["Service"] =>
24
- Effect.service(VimRouter).pipe(Effect.provide(VimRouter.make(() => enabled)), Effect.runSync);
22
+ const vimRouter = (enabled: boolean): VimRouter["Service"] => VimRouter.make(() => enabled);
25
23
 
26
24
  const row = (input: Partial<InspectorRow> & { readonly id: string }): InspectorRow => ({
27
25
  runId: input.id,