@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.
- package/CHANGELOG.md +51 -0
- package/OPERATIONS.md +79 -6
- package/README.md +25 -17
- package/ROADMAP.md +21 -0
- package/TESTING.md +153 -318
- package/package.json +4 -3
- package/skills/pi-delegates/SKILL.md +29 -0
- package/skills/pi-delegates/references/launch.md +28 -0
- package/src/docs-contract.test.ts +106 -0
- package/src/domain/definitions.ts +3 -1
- package/src/domain/failure.ts +33 -0
- package/src/domain/model-source.ts +30 -0
- package/src/domain/orchestration/control.test.ts +69 -35
- package/src/domain/orchestration/control.ts +110 -89
- package/src/domain/orchestration/fanout.test.ts +125 -20
- package/src/domain/orchestration/fanout.ts +60 -22
- package/src/domain/orchestration/gates.test.ts +14 -15
- package/src/domain/orchestration/launch.test.ts +210 -11
- package/src/domain/orchestration/launch.ts +142 -32
- package/src/domain/orchestration/requests.test.ts +11 -16
- package/src/domain/orchestration/requests.ts +14 -1
- package/src/domain/orchestration/review.test.ts +89 -11
- package/src/domain/orchestration/run-wait.test.ts +4 -1
- package/src/domain/orchestration/run-wait.ts +1 -1
- package/src/domain/orchestration/workflow.test.ts +157 -16
- package/src/domain/orchestration/workflow.ts +269 -196
- package/src/domain/run-records.ts +214 -52
- package/src/domain/settlement.test.ts +186 -0
- package/src/domain/settlement.ts +137 -0
- package/src/domain/shapes.test.ts +20 -0
- package/src/domain/skills.test.ts +31 -20
- package/src/domain/skills.ts +36 -19
- package/src/domain/toolkit.test.ts +15 -1
- package/src/domain/toolkit.ts +8 -13
- package/src/domain/turn-budget.test.ts +37 -0
- package/src/domain/turn-budget.ts +23 -0
- package/src/domain/view.test.ts +78 -14
- package/src/domain/view.ts +67 -35
- package/src/extension/commands.test.ts +27 -23
- package/src/extension/commands.ts +10 -7
- package/src/extension/entry.test.ts +214 -56
- package/src/extension/entry.ts +78 -40
- package/src/extension/gate-alerts.test.ts +10 -8
- package/src/extension/inspector-command.test.ts +173 -21
- package/src/extension/inspector-command.ts +100 -53
- package/src/extension/prompt.test.ts +2 -4
- package/src/extension/retry-observer.test.ts +292 -0
- package/src/extension/retry-observer.ts +150 -0
- package/src/extension/settle-alerts.test.ts +579 -0
- package/src/extension/settle-alerts.ts +175 -0
- package/src/extension/shortcut.test.ts +6 -8
- package/src/extension/tools.test.ts +325 -24
- package/src/extension/tools.ts +61 -13
- package/src/extension/version.test.ts +21 -29
- package/src/goldens.test.ts +294 -0
- package/src/harness-policy.test.ts +13 -11
- package/src/layers.test.ts +309 -0
- package/src/layers.ts +405 -0
- package/src/package-manifest.test.ts +32 -19
- package/src/presentation/actions.test.ts +8 -8
- package/src/presentation/activity.test.ts +7 -8
- package/src/presentation/close.test.ts +14 -16
- package/src/presentation/inspector.test.ts +14 -11
- package/src/presentation/inspector.ts +27 -25
- package/src/presentation/overlay.test.ts +1 -3
- package/src/presentation/repaint.test.ts +226 -190
- package/src/presentation/snapshot.test.ts +5 -0
- package/src/presentation/status.test.ts +43 -0
- package/src/presentation/status.ts +30 -0
- package/src/presentation/strip.test.ts +13 -6
- package/src/presentation/strip.ts +7 -14
- package/src/presentation/wording.test.ts +153 -3
- package/src/presentation/wording.ts +78 -6
- package/src/runtime/bridge.ts +38 -44
- package/src/runtime/{timers.test.ts → clock.test.ts} +1 -1
- package/src/runtime/clock.ts +31 -0
- package/src/runtime/config.test.ts +26 -7
- package/src/runtime/config.ts +6 -1
- package/src/runtime/execution-env.test.ts +6 -8
- package/src/runtime/extensions.test.ts +4 -4
- package/src/runtime/extensions.ts +23 -11
- package/src/runtime/handle.ts +54 -0
- package/src/runtime/log.test.ts +19 -7
- package/src/runtime/log.ts +23 -0
- package/src/runtime/mcp.test.ts +29 -32
- package/src/runtime/mcp.ts +70 -3
- package/src/runtime/runtime-state.test.ts +25 -0
- package/src/runtime/runtime-state.ts +36 -0
- package/src/runtime/session-tag.ts +11 -0
- package/src/runtime/session.test.ts +24 -31
- package/src/runtime/session.ts +99 -261
- package/src/runtime/storage.ts +29 -0
- package/src/test-hygiene.test.ts +97 -0
- 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
|
-
|
|
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<
|
|
53
|
-
const sessionDir = await
|
|
54
|
-
return
|
|
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:
|
|
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:
|
|
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:
|
|
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/
|
|
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<
|
|
157
|
-
|
|
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>):
|
|
348
|
-
|
|
349
|
-
|
|
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(
|
|
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,
|