@ftrdotdev/pi-delegates 0.0.0-stage → 0.1.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 +77 -0
- package/LICENSE +21 -0
- package/OPERATIONS.md +57 -0
- package/README.md +448 -2
- package/ROADMAP.md +158 -0
- package/TESTING.md +1061 -0
- package/agents.ts +8 -0
- package/examples/README.md +114 -0
- package/examples/gated.ts +28 -0
- package/index.ts +9 -0
- package/package.json +93 -4
- package/skills/pi-delegates/SKILL.md +147 -0
- package/skills/pi-delegates/references/control.md +159 -0
- package/skills/pi-delegates/references/definitions.md +163 -0
- package/skills/pi-delegates/references/gates.md +175 -0
- package/skills/pi-delegates/references/launch.md +156 -0
- package/src/domain/definitions.test.ts +41 -0
- package/src/domain/definitions.ts +161 -0
- package/src/domain/ids.ts +13 -0
- package/src/domain/names.ts +35 -0
- package/src/domain/orchestration/admission.ts +78 -0
- package/src/domain/orchestration/control.test.ts +1298 -0
- package/src/domain/orchestration/control.ts +436 -0
- package/src/domain/orchestration/fanout.test.ts +419 -0
- package/src/domain/orchestration/fanout.ts +334 -0
- package/src/domain/orchestration/gates.test.ts +686 -0
- package/src/domain/orchestration/gates.ts +360 -0
- package/src/domain/orchestration/launch.test.ts +173 -0
- package/src/domain/orchestration/launch.ts +581 -0
- package/src/domain/orchestration/requests.test.ts +700 -0
- package/src/domain/orchestration/requests.ts +769 -0
- package/src/domain/orchestration/review.test.ts +214 -0
- package/src/domain/orchestration/review.ts +168 -0
- package/src/domain/orchestration/run-wait.test.ts +262 -0
- package/src/domain/orchestration/run-wait.ts +256 -0
- package/src/domain/orchestration/workflow-section.test.ts +62 -0
- package/src/domain/orchestration/workflow-section.ts +99 -0
- package/src/domain/orchestration/workflow.test.ts +1425 -0
- package/src/domain/orchestration/workflow.ts +705 -0
- package/src/domain/run-records.test.ts +27 -0
- package/src/domain/run-records.ts +527 -0
- package/src/domain/shapes.test.ts +165 -0
- package/src/domain/skills.test.ts +466 -0
- package/src/domain/skills.ts +97 -0
- package/src/domain/tool-schema.test.ts +46 -0
- package/src/domain/tool-schema.ts +20 -0
- package/src/domain/toolkit.test.ts +201 -0
- package/src/domain/toolkit.ts +379 -0
- package/src/domain/view.test.ts +739 -0
- package/src/domain/view.ts +459 -0
- package/src/example.test.ts +15 -0
- package/src/extension/commands.test.ts +481 -0
- package/src/extension/commands.ts +227 -0
- package/src/extension/entry.test.ts +1118 -0
- package/src/extension/entry.ts +342 -0
- package/src/extension/gate-alerts.test.ts +235 -0
- package/src/extension/gate-alerts.ts +143 -0
- package/src/extension/guard.test.ts +48 -0
- package/src/extension/guard.ts +31 -0
- package/src/extension/host-signals.test.ts +20 -0
- package/src/extension/host-signals.ts +13 -0
- package/src/extension/inspector-command.test.ts +1191 -0
- package/src/extension/inspector-command.ts +638 -0
- package/src/extension/prompt.test.ts +110 -0
- package/src/extension/prompt.ts +50 -0
- package/src/extension/request-alerts.test.ts +183 -0
- package/src/extension/request-alerts.ts +181 -0
- package/src/extension/revocation.test.ts +81 -0
- package/src/extension/revocation.ts +84 -0
- package/src/extension/shortcut.test.ts +64 -0
- package/src/extension/shortcut.ts +105 -0
- package/src/extension/tools.test.ts +993 -0
- package/src/extension/tools.ts +505 -0
- package/src/extension/version.test.ts +123 -0
- package/src/extension/version.ts +97 -0
- package/src/harness-policy.test.ts +74 -0
- package/src/package-manifest.test.ts +157 -0
- package/src/presentation/actions.test.ts +221 -0
- package/src/presentation/actions.ts +85 -0
- package/src/presentation/activity.test.ts +387 -0
- package/src/presentation/activity.ts +66 -0
- package/src/presentation/close.test.ts +361 -0
- package/src/presentation/inspector.test.ts +679 -0
- package/src/presentation/inspector.ts +440 -0
- package/src/presentation/overlay.test.ts +555 -0
- package/src/presentation/overlay.ts +229 -0
- package/src/presentation/repaint.test.ts +329 -0
- package/src/presentation/shortcut.ts +2 -0
- package/src/presentation/snapshot.test.ts +530 -0
- package/src/presentation/snapshot.ts +306 -0
- package/src/presentation/strip.test.ts +196 -0
- package/src/presentation/strip.ts +74 -0
- package/src/presentation/wording.test.ts +238 -0
- package/src/presentation/wording.ts +222 -0
- package/src/runtime/bridge.test.ts +131 -0
- package/src/runtime/bridge.ts +134 -0
- package/src/runtime/config.test.ts +44 -0
- package/src/runtime/config.ts +87 -0
- package/src/runtime/context.test.ts +19 -0
- package/src/runtime/context.ts +9 -0
- package/src/runtime/execution-env.test.ts +35 -0
- package/src/runtime/execution-env.ts +15 -0
- package/src/runtime/extensions.test.ts +86 -0
- package/src/runtime/extensions.ts +140 -0
- package/src/runtime/log.test.ts +128 -0
- package/src/runtime/log.ts +68 -0
- package/src/runtime/mcp.test.ts +1453 -0
- package/src/runtime/mcp.ts +938 -0
- package/src/runtime/models.test.ts +145 -0
- package/src/runtime/models.ts +259 -0
- package/src/runtime/observe.test.ts +50 -0
- package/src/runtime/observe.ts +150 -0
- package/src/runtime/session.test.ts +359 -0
- package/src/runtime/session.ts +425 -0
- package/src/runtime/timers.test.ts +31 -0
- package/src/runtime/timers.ts +10 -0
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
4
|
+
import { Option, Schema } from "effect";
|
|
5
|
+
|
|
6
|
+
export type VersionSignals = {
|
|
7
|
+
readonly durablePin: string | undefined;
|
|
8
|
+
readonly hostResolved: string | undefined;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export type VersionVerdict =
|
|
12
|
+
| { readonly kind: "clear"; readonly note?: "unverified" }
|
|
13
|
+
| { readonly kind: "refused"; readonly message: string };
|
|
14
|
+
|
|
15
|
+
/** The manifest fields the version check reads; a malformed field reads as absent. */
|
|
16
|
+
const ManifestSchema = Schema.Struct({
|
|
17
|
+
version: Schema.optional(Schema.String),
|
|
18
|
+
dependencies: Schema.optional(Schema.Record(Schema.String, Schema.String)),
|
|
19
|
+
peerDependencies: Schema.optional(Schema.Record(Schema.String, Schema.String)),
|
|
20
|
+
});
|
|
21
|
+
type Manifest = typeof ManifestSchema.Type;
|
|
22
|
+
|
|
23
|
+
/** The nearest `package.json` above a resolved entry. Node blocks most `./package.json` subpaths. */
|
|
24
|
+
const manifestPathFor = (entry: string): string | undefined => {
|
|
25
|
+
let directory = dirname(entry);
|
|
26
|
+
for (;;) {
|
|
27
|
+
const candidate = join(directory, "package.json");
|
|
28
|
+
if (existsSync(candidate)) return candidate;
|
|
29
|
+
const parent = dirname(directory);
|
|
30
|
+
if (parent === directory) return undefined;
|
|
31
|
+
directory = parent;
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/** Reads durable's pinned `@earendil-works/pi-ai` and the host-resolved version. */
|
|
36
|
+
export const readVersionSignals = (
|
|
37
|
+
resolve: (specifier: string, parent?: string) => string | undefined,
|
|
38
|
+
): VersionSignals => {
|
|
39
|
+
const manifestOf = (entry: string): Manifest | undefined => {
|
|
40
|
+
const path = manifestPathFor(entry);
|
|
41
|
+
if (path === undefined) return undefined;
|
|
42
|
+
try {
|
|
43
|
+
return Option.getOrUndefined(
|
|
44
|
+
Schema.decodeUnknownOption(ManifestSchema)(JSON.parse(readFileSync(path, "utf8"))),
|
|
45
|
+
);
|
|
46
|
+
} catch {
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
const readManifest = (specifier: string, parent?: string): Manifest | undefined => {
|
|
51
|
+
const entry = resolve(specifier, parent);
|
|
52
|
+
return entry === undefined ? undefined : manifestOf(entry);
|
|
53
|
+
};
|
|
54
|
+
const piAiPin = (manifest: Manifest | undefined): string | undefined =>
|
|
55
|
+
manifest?.dependencies?.["@earendil-works/pi-ai"] ??
|
|
56
|
+
manifest?.peerDependencies?.["@earendil-works/pi-ai"];
|
|
57
|
+
|
|
58
|
+
const hostEntry = resolve("@earendil-works/pi-coding-agent");
|
|
59
|
+
const host = hostEntry === undefined ? undefined : manifestOf(hostEntry);
|
|
60
|
+
const durable = readManifest("@earendil-works/pi-durable");
|
|
61
|
+
const installedPiAi = readManifest("@earendil-works/pi-ai", hostEntry);
|
|
62
|
+
return {
|
|
63
|
+
durablePin: piAiPin(durable) ?? durable?.version,
|
|
64
|
+
hostResolved: installedPiAi?.version ?? piAiPin(host),
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
/** The identity constraint, checked before anything registers. */
|
|
69
|
+
export const versionVerdict = (signals: VersionSignals): VersionVerdict => {
|
|
70
|
+
if (signals.durablePin === undefined) {
|
|
71
|
+
return { kind: "clear", note: "unverified" };
|
|
72
|
+
}
|
|
73
|
+
if (signals.hostResolved === undefined) {
|
|
74
|
+
return { kind: "clear", note: "unverified" };
|
|
75
|
+
}
|
|
76
|
+
if (signals.durablePin === signals.hostResolved) return { kind: "clear" };
|
|
77
|
+
return {
|
|
78
|
+
kind: "refused",
|
|
79
|
+
message:
|
|
80
|
+
`@ftrdotdev/pi-delegates needs @earendil-works/pi-ai ${signals.durablePin}, the version pi-durable ` +
|
|
81
|
+
`pins, but the host resolved ${signals.hostResolved}. Run pi update, then reinstall ` +
|
|
82
|
+
`@ftrdotdev/pi-delegates so both packages share one copy.`,
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
/** Resolves a package entry through the installed package graph; ESM, so `import` conditions apply. */
|
|
87
|
+
export const resolveFromPackage = (specifier: string, parent?: string): string | undefined => {
|
|
88
|
+
try {
|
|
89
|
+
const resolved =
|
|
90
|
+
parent === undefined
|
|
91
|
+
? import.meta.resolve(specifier)
|
|
92
|
+
: import.meta.resolve(specifier, pathToFileURL(parent).href);
|
|
93
|
+
return fileURLToPath(resolved);
|
|
94
|
+
} catch {
|
|
95
|
+
return undefined;
|
|
96
|
+
}
|
|
97
|
+
};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { expect, it, vi } from "@effect/vitest";
|
|
2
|
+
import { readdirSync, readFileSync } from "node:fs";
|
|
3
|
+
import { join, relative } from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import { createVitest } from "vitest/node";
|
|
6
|
+
|
|
7
|
+
const PACKAGE_ROOT = fileURLToPath(new URL("..", import.meta.url));
|
|
8
|
+
const PROBE = "PI_HARNESS_PROBE";
|
|
9
|
+
const REAL_LOG = console.log;
|
|
10
|
+
|
|
11
|
+
/** Every `*.test.ts` under `dir`, as paths relative to `PACKAGE_ROOT`. */
|
|
12
|
+
const walkTests = (dir: string, found: string[] = []): string[] => {
|
|
13
|
+
for (const entry of readdirSync(join(PACKAGE_ROOT, dir), { withFileTypes: true })) {
|
|
14
|
+
const path = join(dir, entry.name);
|
|
15
|
+
if (entry.isDirectory()) walkTests(path, found);
|
|
16
|
+
else if (entry.name.endsWith(".test.ts")) found.push(path);
|
|
17
|
+
}
|
|
18
|
+
return found;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/** The project's resolved config, read from the config this package ships. */
|
|
22
|
+
const project = async () => {
|
|
23
|
+
const vitest = await createVitest({ root: PACKAGE_ROOT, watch: false });
|
|
24
|
+
try {
|
|
25
|
+
return { config: vitest.projects.at(0)?.config, specs: await vitest.globTestSpecifications() };
|
|
26
|
+
} finally {
|
|
27
|
+
await vitest.close();
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
it("this package resolves the shared policy without stating it", async () => {
|
|
32
|
+
const { config } = await project();
|
|
33
|
+
|
|
34
|
+
expect(config?.name).toBe("delegates");
|
|
35
|
+
expect(config?.restoreMocks).toBe(true);
|
|
36
|
+
expect(config?.unstubEnvs).toBe(true);
|
|
37
|
+
expect(config?.unstubGlobals).toBe(true);
|
|
38
|
+
expect(config?.isolate).toBe(false);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("the package config states no shared key", () => {
|
|
42
|
+
const source = readFileSync(new URL("../vitest.config.ts", import.meta.url), "utf8");
|
|
43
|
+
|
|
44
|
+
expect(source).toContain("baseTestConfig");
|
|
45
|
+
for (const key of ["restoreMocks", "unstubEnvs", "unstubGlobals", "fakeTimers", "isolate"]) {
|
|
46
|
+
expect(source).not.toContain(key);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it("the project collects the source tree, the scripts and the test support", async () => {
|
|
51
|
+
const { specs } = await project();
|
|
52
|
+
const collected = specs.map((spec) => relative(PACKAGE_ROOT, spec.moduleId)).sort();
|
|
53
|
+
|
|
54
|
+
expect(collected).toEqual(
|
|
55
|
+
[...walkTests("src"), ...walkTests("scripts"), ...walkTests("test-support")].sort(),
|
|
56
|
+
);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it("a stubbed environment variable is set for the test that stubs it", () => {
|
|
60
|
+
vi.stubEnv(PROBE, "1");
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("a stubbed environment variable is absent in the next test", () => {
|
|
64
|
+
expect(process.env[PROBE]).toBeUndefined();
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it("a spy made in one test replaces the function for that test", () => {
|
|
68
|
+
vi.spyOn(console, "log").mockImplementation(() => {});
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it("a spy made in one test is not a mock in the next", () => {
|
|
72
|
+
expect(vi.isMockFunction(console.log)).toBe(false);
|
|
73
|
+
expect(console.log).toBe(REAL_LOG);
|
|
74
|
+
});
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { readFile, readdir, stat } from "node:fs/promises";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import { assert, it } from "@effect/vitest";
|
|
5
|
+
|
|
6
|
+
const PACKAGE_ROOT = fileURLToPath(new URL("..", import.meta.url));
|
|
7
|
+
const PACKAGE_MANIFEST = join(PACKAGE_ROOT, "package.json");
|
|
8
|
+
const WORKSPACE_ROOT = fileURLToPath(new URL("../../..", import.meta.url));
|
|
9
|
+
|
|
10
|
+
interface Manifest {
|
|
11
|
+
readonly name?: string;
|
|
12
|
+
readonly version?: string;
|
|
13
|
+
readonly publishConfig?: { readonly access?: string };
|
|
14
|
+
readonly exports?: Readonly<Record<string, string>>;
|
|
15
|
+
readonly files?: readonly string[];
|
|
16
|
+
readonly dependencies?: Readonly<Record<string, string>>;
|
|
17
|
+
readonly devDependencies?: Readonly<Record<string, string>>;
|
|
18
|
+
readonly peerDependencies?: Readonly<Record<string, string>>;
|
|
19
|
+
readonly catalogs?: Readonly<Record<string, Readonly<Record<string, string>>>>;
|
|
20
|
+
readonly pi?: {
|
|
21
|
+
readonly extensions?: readonly string[];
|
|
22
|
+
readonly skills?: readonly string[];
|
|
23
|
+
};
|
|
24
|
+
readonly scripts?: Readonly<Record<string, string>>;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const readManifest = async (path: string): Promise<Manifest> =>
|
|
28
|
+
JSON.parse(await readFile(path, "utf8")) as Manifest;
|
|
29
|
+
|
|
30
|
+
const exists = async (path: string): Promise<boolean> =>
|
|
31
|
+
stat(path).then(
|
|
32
|
+
() => true,
|
|
33
|
+
() => false,
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
it("the manifest points Pi at paths that exist", async () => {
|
|
37
|
+
const manifest = await readManifest(PACKAGE_MANIFEST);
|
|
38
|
+
|
|
39
|
+
assert.strictEqual(manifest.name, "@ftrdotdev/pi-delegates");
|
|
40
|
+
assert.strictEqual(manifest.publishConfig?.access, "public");
|
|
41
|
+
assert.ok(manifest.files?.includes("examples"), "the package publishes examples");
|
|
42
|
+
assert.ok(
|
|
43
|
+
manifest.files?.includes("OPERATIONS.md"),
|
|
44
|
+
"the package publishes the operations guide",
|
|
45
|
+
);
|
|
46
|
+
assert.strictEqual(manifest.dependencies?.["@earendil-works/pi-durable"], "1.6.0");
|
|
47
|
+
assert.strictEqual(manifest.dependencies?.["@earendil-works/pi-codemode"], "catalog:pi");
|
|
48
|
+
assert.strictEqual(manifest.peerDependencies?.["@earendil-works/pi-coding-agent"], "1.6.0");
|
|
49
|
+
assert.strictEqual(
|
|
50
|
+
manifest.scripts?.["check:identity"],
|
|
51
|
+
"bun run scripts/check-dependency-identity.ts",
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
const declared = [
|
|
55
|
+
...(manifest.pi?.extensions ?? []),
|
|
56
|
+
...(manifest.pi?.skills ?? []),
|
|
57
|
+
...Object.values(manifest.exports ?? {}),
|
|
58
|
+
];
|
|
59
|
+
assert.ok(declared.length > 0, "the manifest declares at least one entry");
|
|
60
|
+
for (const relative of declared) {
|
|
61
|
+
const path = join(PACKAGE_ROOT, relative);
|
|
62
|
+
assert.ok(await exists(path), `${relative} exists`);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
const WORKSPACE_PACKAGES = ["inquiry", "qrspi", "test-kit", "tracker", "tui", "delegates"];
|
|
67
|
+
|
|
68
|
+
it("the manifest declares the house UI dependency and the host terminal peer", async () => {
|
|
69
|
+
const manifest = await readManifest(PACKAGE_MANIFEST);
|
|
70
|
+
|
|
71
|
+
assert.strictEqual(manifest.dependencies?.["@ftrdotdev/pi-tui"], "^0.8.0");
|
|
72
|
+
assert.strictEqual(manifest.peerDependencies?.["@earendil-works/pi-tui"], "*");
|
|
73
|
+
assert.strictEqual(manifest.devDependencies?.["@earendil-works/pi-tui"], "catalog:pi");
|
|
74
|
+
assert.strictEqual(manifest.peerDependencies?.["@earendil-works/pi-coding-agent"], "1.6.0");
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it("the house UI package resolves from inside this package", async () => {
|
|
78
|
+
const house = (await import("@ftrdotdev/pi-tui")) as {
|
|
79
|
+
readonly defineComponent?: unknown;
|
|
80
|
+
};
|
|
81
|
+
assert.strictEqual(typeof house.defineComponent, "function");
|
|
82
|
+
const component = (
|
|
83
|
+
house as unknown as {
|
|
84
|
+
readonly defineComponent: (methods: {
|
|
85
|
+
readonly render: (width: number) => string[];
|
|
86
|
+
readonly invalidate: () => void;
|
|
87
|
+
}) => { readonly render: (width: number) => string[] };
|
|
88
|
+
}
|
|
89
|
+
).defineComponent({ render: () => ["row"], invalidate: () => {} });
|
|
90
|
+
assert.ok(Array.isArray(component.render(10)));
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it("the terminal types resolve from inside this package", async () => {
|
|
94
|
+
const terminal = (await import("@earendil-works/pi-tui")) as {
|
|
95
|
+
readonly matchesKey?: unknown;
|
|
96
|
+
readonly Key?: unknown;
|
|
97
|
+
readonly visibleWidth?: unknown;
|
|
98
|
+
};
|
|
99
|
+
assert.strictEqual(typeof terminal.matchesKey, "function");
|
|
100
|
+
assert.ok(terminal.Key !== undefined);
|
|
101
|
+
assert.strictEqual(typeof terminal.visibleWidth, "function");
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it("the workspace pins one effect version", async () => {
|
|
105
|
+
const root = await readManifest(join(WORKSPACE_ROOT, "package.json"));
|
|
106
|
+
const effect = root.catalogs?.effect;
|
|
107
|
+
assert.strictEqual(effect?.["effect"], "4.1.5");
|
|
108
|
+
assert.strictEqual(effect?.["@effect/vitest"], "4.1.5");
|
|
109
|
+
assert.strictEqual(effect?.["@effect/platform-node"], "4.1.5");
|
|
110
|
+
|
|
111
|
+
const specifiers = ["effect", "@effect/vitest", "@effect/platform-node"];
|
|
112
|
+
for (const packageName of WORKSPACE_PACKAGES) {
|
|
113
|
+
const path = join(WORKSPACE_ROOT, "packages", packageName, "package.json");
|
|
114
|
+
const manifest = await readManifest(path);
|
|
115
|
+
for (const name of specifiers) {
|
|
116
|
+
const specifier =
|
|
117
|
+
manifest.dependencies?.[name] ??
|
|
118
|
+
manifest.devDependencies?.[name] ??
|
|
119
|
+
manifest.peerDependencies?.[name];
|
|
120
|
+
if (specifier === undefined) continue;
|
|
121
|
+
assert.strictEqual(specifier, "catalog:effect", `${packageName}: ${name}`);
|
|
122
|
+
}
|
|
123
|
+
const tsgo = manifest.devDependencies?.["@effect/tsgo"];
|
|
124
|
+
if (tsgo !== undefined) {
|
|
125
|
+
assert.strictEqual(tsgo, "catalog:effect", `${packageName}: @effect/tsgo`);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it("the package ships at least one changeset and a grouped roadmap", async () => {
|
|
131
|
+
const changesetDir = join(WORKSPACE_ROOT, ".changeset");
|
|
132
|
+
const entries = await readdir(changesetDir);
|
|
133
|
+
const fixed = ["@ftrdotdev/pi-tui", "@ftrdotdev/pi-tracker", "@ftrdotdev/pi-inquiry"];
|
|
134
|
+
|
|
135
|
+
const namingDelegates: string[] = [];
|
|
136
|
+
for (const entry of entries.filter((name) => name.endsWith(".md"))) {
|
|
137
|
+
const text = await readFile(join(changesetDir, entry), "utf8");
|
|
138
|
+
const frontmatter = /^---\n([\s\S]*?)\n---/.exec(text)?.[1] ?? "";
|
|
139
|
+
if (!frontmatter.includes('"@ftrdotdev/pi-delegates"')) continue;
|
|
140
|
+
namingDelegates.push(entry);
|
|
141
|
+
for (const name of fixed) {
|
|
142
|
+
assert.ok(!frontmatter.includes(`"${name}"`), `${entry} names ${name}`);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
assert.ok(namingDelegates.length >= 1, "no @ftrdotdev/pi-delegates changeset");
|
|
146
|
+
|
|
147
|
+
const roadmap = await readFile(join(PACKAGE_ROOT, "ROADMAP.md"), "utf8");
|
|
148
|
+
for (const heading of [
|
|
149
|
+
"Durability and hosts",
|
|
150
|
+
"Work items and authorization",
|
|
151
|
+
"Surfaces and observability",
|
|
152
|
+
"Agent definitions and toolkits",
|
|
153
|
+
"Isolation and execution",
|
|
154
|
+
]) {
|
|
155
|
+
assert.ok(roadmap.includes(heading), `roadmap names ${heading}`);
|
|
156
|
+
}
|
|
157
|
+
});
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import { MemoryStorage } from "@earendil-works/pi-durable";
|
|
2
|
+
import { mkdtemp } from "node:fs/promises";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { assert, it } from "@effect/vitest";
|
|
6
|
+
import { stubHostSource } from "../../test-support/stub-model-source.ts";
|
|
7
|
+
import { createCatalogue, defineAgent } from "../domain/definitions.ts";
|
|
8
|
+
import { CODING_EXTENSION } from "../domain/names.ts";
|
|
9
|
+
import { control } from "../domain/orchestration/control.ts";
|
|
10
|
+
import { launch, type HostDefaults } from "../domain/orchestration/launch.ts";
|
|
11
|
+
import { RunDoc } from "../domain/run-records.ts";
|
|
12
|
+
import { HostModelAdapter } from "../runtime/models.ts";
|
|
13
|
+
import type { LogFields, LogLevel, LogSink } from "../runtime/log.ts";
|
|
14
|
+
import type { Timers } from "../runtime/timers.ts";
|
|
15
|
+
import { openSessionRuntime, type SessionRuntime } from "../runtime/session.ts";
|
|
16
|
+
import { runInspectorAction } from "./actions.ts";
|
|
17
|
+
|
|
18
|
+
const host: HostDefaults = {
|
|
19
|
+
model: { provider: "stub", modelId: "stub-1" },
|
|
20
|
+
thinkingLevel: "low",
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const deployer = defineAgent({
|
|
24
|
+
name: "deployer",
|
|
25
|
+
role: "Deploy agent",
|
|
26
|
+
prompt: { role: "You deploy things." },
|
|
27
|
+
tools: ["bash"],
|
|
28
|
+
extensions: [CODING_EXTENSION],
|
|
29
|
+
approval: { gates: [{ name: "deploy", tools: ["bash"], match: "deploy" }] },
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const catalogue = createCatalogue([deployer]);
|
|
33
|
+
|
|
34
|
+
interface Recorder {
|
|
35
|
+
readonly timers: Timers;
|
|
36
|
+
readonly delays: number[];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Real timers with a delay log, so the harness still schedules. */
|
|
40
|
+
const recordingTimers = (): Recorder => {
|
|
41
|
+
const delays: number[] = [];
|
|
42
|
+
return {
|
|
43
|
+
delays,
|
|
44
|
+
timers: {
|
|
45
|
+
setTimeout: (callback, ms) => {
|
|
46
|
+
delays.push(ms);
|
|
47
|
+
return setTimeout(callback, ms);
|
|
48
|
+
},
|
|
49
|
+
clearTimeout: (handle) => clearTimeout(handle as ReturnType<typeof setTimeout>),
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const recordingLog = (): {
|
|
55
|
+
readonly sink: LogSink;
|
|
56
|
+
readonly entries: { level: LogLevel; code: string; fields: LogFields }[];
|
|
57
|
+
} => {
|
|
58
|
+
const entries: { level: LogLevel; code: string; fields: LogFields }[] = [];
|
|
59
|
+
return {
|
|
60
|
+
entries,
|
|
61
|
+
sink: {
|
|
62
|
+
write: (level, code, fields = {}) => {
|
|
63
|
+
entries.push({ level, code, fields });
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const openRuntime = async (clock: Recorder, log?: LogSink): Promise<SessionRuntime> => {
|
|
70
|
+
const sessionDir = await mkdtemp(join(tmpdir(), "delegates-actions-"));
|
|
71
|
+
return openSessionRuntime({
|
|
72
|
+
identity: { sessionId: "s-1", sessionDir, cwd: sessionDir, agentDir: sessionDir },
|
|
73
|
+
models: new HostModelAdapter(
|
|
74
|
+
stubHostSource({
|
|
75
|
+
text: "deployed",
|
|
76
|
+
toolCall: { name: "bash", arguments: { command: "echo deploy" } },
|
|
77
|
+
}),
|
|
78
|
+
),
|
|
79
|
+
storage: new MemoryStorage(),
|
|
80
|
+
timers: clock.timers,
|
|
81
|
+
...(log === undefined ? {} : { log }),
|
|
82
|
+
});
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const parkedRun = async (runtime: SessionRuntime): Promise<string> => {
|
|
86
|
+
const result = await launch(
|
|
87
|
+
{ kind: "single", agent: "deployer", task: "deploy it" },
|
|
88
|
+
{ runtime, catalogue, host, waitMs: 10_000 },
|
|
89
|
+
);
|
|
90
|
+
return result.view.runId;
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
it("the commit policy arms no settlement wait and returns no view", async () => {
|
|
94
|
+
const clock = recordingTimers();
|
|
95
|
+
const runtime = await openRuntime(clock);
|
|
96
|
+
try {
|
|
97
|
+
const runId = await parkedRun(runtime);
|
|
98
|
+
const result = await control(
|
|
99
|
+
{ action: "stop", run: runId },
|
|
100
|
+
{ runtime, wait: { policy: "commit" } },
|
|
101
|
+
);
|
|
102
|
+
assert.ok(!("view" in result));
|
|
103
|
+
assert.ok(!clock.delays.includes(4_321), clock.delays.join(","));
|
|
104
|
+
} finally {
|
|
105
|
+
await runtime.close();
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it("the settle policy still arms one wait and returns a view", async () => {
|
|
110
|
+
const clock = recordingTimers();
|
|
111
|
+
const runtime = await openRuntime(clock);
|
|
112
|
+
try {
|
|
113
|
+
const runId = await parkedRun(runtime);
|
|
114
|
+
const result = await control(
|
|
115
|
+
{ action: "stop", run: runId },
|
|
116
|
+
{ runtime, wait: { policy: "settle", waitMs: 4_321 } },
|
|
117
|
+
);
|
|
118
|
+
assert.ok(clock.delays.includes(4_321), clock.delays.join(","));
|
|
119
|
+
assert.ok(result.view !== undefined);
|
|
120
|
+
} finally {
|
|
121
|
+
await runtime.close();
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it("a verb that does not apply renders the pinned line and writes nothing", async () => {
|
|
126
|
+
const clock = recordingTimers();
|
|
127
|
+
const runtime = await openRuntime(clock);
|
|
128
|
+
let refreshed = 0;
|
|
129
|
+
try {
|
|
130
|
+
const result = await runInspectorAction({
|
|
131
|
+
runtime,
|
|
132
|
+
target: { rowId: "child:r1", runId: "r1" },
|
|
133
|
+
verb: "approve",
|
|
134
|
+
refresh: async () => {
|
|
135
|
+
refreshed += 1;
|
|
136
|
+
},
|
|
137
|
+
});
|
|
138
|
+
assert.deepStrictEqual(result, {
|
|
139
|
+
ok: false,
|
|
140
|
+
message: "approve does not apply to run r1",
|
|
141
|
+
});
|
|
142
|
+
assert.strictEqual(refreshed, 0);
|
|
143
|
+
} finally {
|
|
144
|
+
await runtime.close();
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
it("an already-decided gate renders the pinned refusal naming gate and run", async () => {
|
|
149
|
+
const clock = recordingTimers();
|
|
150
|
+
const log = recordingLog();
|
|
151
|
+
const runtime = await openRuntime(clock, log.sink);
|
|
152
|
+
let refreshed = 0;
|
|
153
|
+
try {
|
|
154
|
+
const runId = await parkedRun(runtime);
|
|
155
|
+
await control(
|
|
156
|
+
{ action: "approve", run: runId, gate: "deploy" },
|
|
157
|
+
{ runtime, wait: { policy: "settle", waitMs: 10_000 } },
|
|
158
|
+
);
|
|
159
|
+
const result = await runInspectorAction({
|
|
160
|
+
runtime,
|
|
161
|
+
target: { rowId: `gate:${runId}:deploy`, runId, gate: "deploy" },
|
|
162
|
+
verb: "approve",
|
|
163
|
+
refresh: async () => {
|
|
164
|
+
refreshed += 1;
|
|
165
|
+
},
|
|
166
|
+
});
|
|
167
|
+
assert.strictEqual(result.ok, false);
|
|
168
|
+
assert.ok(result.message.startsWith(`gate deploy on run ${runId}: `), result.message);
|
|
169
|
+
assert.strictEqual(refreshed, 0);
|
|
170
|
+
const failures = log.entries.filter((entry) => entry.code === "inspector.action_failed");
|
|
171
|
+
assert.strictEqual(failures.length, 1);
|
|
172
|
+
assert.strictEqual(failures[0]?.fields.target, `gate deploy on run ${runId}`);
|
|
173
|
+
} finally {
|
|
174
|
+
await runtime.close();
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
it("a committed action asks for an immediate refresh", async () => {
|
|
179
|
+
const clock = recordingTimers();
|
|
180
|
+
const runtime = await openRuntime(clock);
|
|
181
|
+
const events: string[] = [];
|
|
182
|
+
try {
|
|
183
|
+
const runId = await parkedRun(runtime);
|
|
184
|
+
const result = await runInspectorAction({
|
|
185
|
+
runtime,
|
|
186
|
+
target: { rowId: `child:${runId}`, runId },
|
|
187
|
+
verb: "stop",
|
|
188
|
+
refresh: async () => {
|
|
189
|
+
events.push("refresh");
|
|
190
|
+
},
|
|
191
|
+
});
|
|
192
|
+
events.push("resolved");
|
|
193
|
+
assert.deepStrictEqual(result, { ok: true, message: `stopped run ${runId}` });
|
|
194
|
+
assert.deepStrictEqual(events, ["refresh", "resolved"]);
|
|
195
|
+
const doc = await runtime.snapshot(RunDoc, runId);
|
|
196
|
+
assert.ok(doc !== undefined);
|
|
197
|
+
} finally {
|
|
198
|
+
await runtime.close();
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
it("a refused write names the target and writes no notification", async () => {
|
|
203
|
+
const clock = recordingTimers();
|
|
204
|
+
const runtime = await openRuntime(clock);
|
|
205
|
+
const notices: string[] = [];
|
|
206
|
+
try {
|
|
207
|
+
const result = await runInspectorAction({
|
|
208
|
+
runtime,
|
|
209
|
+
target: { rowId: "child:run-absent", runId: "run-absent" },
|
|
210
|
+
verb: "stop",
|
|
211
|
+
refresh: async () => {
|
|
212
|
+
notices.push("refresh");
|
|
213
|
+
},
|
|
214
|
+
});
|
|
215
|
+
assert.strictEqual(result.ok, false);
|
|
216
|
+
assert.ok(result.message.startsWith("run run-absent: "), result.message);
|
|
217
|
+
assert.deepStrictEqual(notices, []);
|
|
218
|
+
} finally {
|
|
219
|
+
await runtime.close();
|
|
220
|
+
}
|
|
221
|
+
});
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { control, type ControlRequest } from "../domain/orchestration/control.ts";
|
|
2
|
+
import { errorFields, reasonOf } from "../runtime/log.ts";
|
|
3
|
+
import type { SessionRuntime } from "../runtime/session.ts";
|
|
4
|
+
import type { OverlayVerb } from "./overlay.ts";
|
|
5
|
+
|
|
6
|
+
/** The pinned status lines; every one names its target. */
|
|
7
|
+
export const actionLine = {
|
|
8
|
+
stopped: (runId: string) => `stopped run ${runId}`,
|
|
9
|
+
approved: (gate: string, runId: string) => `approved gate ${gate} on run ${runId}`,
|
|
10
|
+
denied: (gate: string, runId: string) => `denied gate ${gate} on run ${runId}`,
|
|
11
|
+
notApplicable: (verb: OverlayVerb, target: string) => `${verb} does not apply to ${target}`,
|
|
12
|
+
refused: (target: string, message: string) => `${target}: ${message}`,
|
|
13
|
+
} as const;
|
|
14
|
+
|
|
15
|
+
export interface ActionTarget {
|
|
16
|
+
readonly rowId: string;
|
|
17
|
+
readonly runId: string;
|
|
18
|
+
readonly gate?: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** `run r1`, or `gate deploy on run r1` — the target every line names. */
|
|
22
|
+
export const targetLabel = (target: ActionTarget): string =>
|
|
23
|
+
target.gate === undefined ? `run ${target.runId}` : `gate ${target.gate} on run ${target.runId}`;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The one map from an activation to one existing write: `stop` on a run row,
|
|
27
|
+
* `approve` or `deny` on a gate row.
|
|
28
|
+
*/
|
|
29
|
+
export const requestFor = (target: ActionTarget, verb: OverlayVerb): ControlRequest | undefined => {
|
|
30
|
+
if (verb === "stop") {
|
|
31
|
+
return target.gate === undefined ? { action: "stop", run: target.runId } : undefined;
|
|
32
|
+
}
|
|
33
|
+
return target.gate === undefined
|
|
34
|
+
? undefined
|
|
35
|
+
: { action: verb, run: target.runId, gate: target.gate };
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export interface ActionResult {
|
|
39
|
+
readonly ok: boolean;
|
|
40
|
+
/** The status line: names the target on success, the target and the refusal on failure. */
|
|
41
|
+
readonly message: string;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const successLine = (target: ActionTarget, verb: OverlayVerb): string => {
|
|
45
|
+
if (target.gate === undefined) return actionLine.stopped(target.runId);
|
|
46
|
+
return verb === "deny"
|
|
47
|
+
? actionLine.denied(target.gate, target.runId)
|
|
48
|
+
: actionLine.approved(target.gate, target.runId);
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* One activation, one existing write. The control call commits and returns;
|
|
53
|
+
* the owner's refresh runs immediately after, so the row settles on the next
|
|
54
|
+
* push without the keypress waiting for settlement. A refusal is one line and
|
|
55
|
+
* never a chat notification.
|
|
56
|
+
*/
|
|
57
|
+
export const runInspectorAction = async (input: {
|
|
58
|
+
readonly runtime: SessionRuntime;
|
|
59
|
+
readonly target: ActionTarget;
|
|
60
|
+
readonly verb: OverlayVerb;
|
|
61
|
+
/** The owner's refresh effect, run by the host after the write: not a settlement wait. */
|
|
62
|
+
readonly refresh: () => Promise<void>;
|
|
63
|
+
}): Promise<ActionResult> => {
|
|
64
|
+
const request = requestFor(input.target, input.verb);
|
|
65
|
+
if (request === undefined) {
|
|
66
|
+
return {
|
|
67
|
+
ok: false,
|
|
68
|
+
message: actionLine.notApplicable(input.verb, targetLabel(input.target)),
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
try {
|
|
72
|
+
await control(request, { runtime: input.runtime, wait: { policy: "commit" } });
|
|
73
|
+
} catch (error) {
|
|
74
|
+
input.runtime.log.write("warn", "inspector.action_failed", {
|
|
75
|
+
target: targetLabel(input.target),
|
|
76
|
+
...errorFields(error),
|
|
77
|
+
});
|
|
78
|
+
return {
|
|
79
|
+
ok: false,
|
|
80
|
+
message: actionLine.refused(targetLabel(input.target), reasonOf(error)),
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
await input.refresh();
|
|
84
|
+
return { ok: true, message: successLine(input.target, input.verb) };
|
|
85
|
+
};
|