@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.
Files changed (116) hide show
  1. package/CHANGELOG.md +77 -0
  2. package/LICENSE +21 -0
  3. package/OPERATIONS.md +57 -0
  4. package/README.md +448 -2
  5. package/ROADMAP.md +158 -0
  6. package/TESTING.md +1061 -0
  7. package/agents.ts +8 -0
  8. package/examples/README.md +114 -0
  9. package/examples/gated.ts +28 -0
  10. package/index.ts +9 -0
  11. package/package.json +93 -4
  12. package/skills/pi-delegates/SKILL.md +147 -0
  13. package/skills/pi-delegates/references/control.md +159 -0
  14. package/skills/pi-delegates/references/definitions.md +163 -0
  15. package/skills/pi-delegates/references/gates.md +175 -0
  16. package/skills/pi-delegates/references/launch.md +156 -0
  17. package/src/domain/definitions.test.ts +41 -0
  18. package/src/domain/definitions.ts +161 -0
  19. package/src/domain/ids.ts +13 -0
  20. package/src/domain/names.ts +35 -0
  21. package/src/domain/orchestration/admission.ts +78 -0
  22. package/src/domain/orchestration/control.test.ts +1298 -0
  23. package/src/domain/orchestration/control.ts +436 -0
  24. package/src/domain/orchestration/fanout.test.ts +419 -0
  25. package/src/domain/orchestration/fanout.ts +334 -0
  26. package/src/domain/orchestration/gates.test.ts +686 -0
  27. package/src/domain/orchestration/gates.ts +360 -0
  28. package/src/domain/orchestration/launch.test.ts +173 -0
  29. package/src/domain/orchestration/launch.ts +581 -0
  30. package/src/domain/orchestration/requests.test.ts +700 -0
  31. package/src/domain/orchestration/requests.ts +769 -0
  32. package/src/domain/orchestration/review.test.ts +214 -0
  33. package/src/domain/orchestration/review.ts +168 -0
  34. package/src/domain/orchestration/run-wait.test.ts +262 -0
  35. package/src/domain/orchestration/run-wait.ts +256 -0
  36. package/src/domain/orchestration/workflow-section.test.ts +62 -0
  37. package/src/domain/orchestration/workflow-section.ts +99 -0
  38. package/src/domain/orchestration/workflow.test.ts +1425 -0
  39. package/src/domain/orchestration/workflow.ts +705 -0
  40. package/src/domain/run-records.test.ts +27 -0
  41. package/src/domain/run-records.ts +527 -0
  42. package/src/domain/shapes.test.ts +165 -0
  43. package/src/domain/skills.test.ts +466 -0
  44. package/src/domain/skills.ts +97 -0
  45. package/src/domain/tool-schema.test.ts +46 -0
  46. package/src/domain/tool-schema.ts +20 -0
  47. package/src/domain/toolkit.test.ts +201 -0
  48. package/src/domain/toolkit.ts +379 -0
  49. package/src/domain/view.test.ts +739 -0
  50. package/src/domain/view.ts +459 -0
  51. package/src/example.test.ts +15 -0
  52. package/src/extension/commands.test.ts +481 -0
  53. package/src/extension/commands.ts +227 -0
  54. package/src/extension/entry.test.ts +1118 -0
  55. package/src/extension/entry.ts +342 -0
  56. package/src/extension/gate-alerts.test.ts +235 -0
  57. package/src/extension/gate-alerts.ts +143 -0
  58. package/src/extension/guard.test.ts +48 -0
  59. package/src/extension/guard.ts +31 -0
  60. package/src/extension/host-signals.test.ts +20 -0
  61. package/src/extension/host-signals.ts +13 -0
  62. package/src/extension/inspector-command.test.ts +1191 -0
  63. package/src/extension/inspector-command.ts +638 -0
  64. package/src/extension/prompt.test.ts +110 -0
  65. package/src/extension/prompt.ts +50 -0
  66. package/src/extension/request-alerts.test.ts +183 -0
  67. package/src/extension/request-alerts.ts +181 -0
  68. package/src/extension/revocation.test.ts +81 -0
  69. package/src/extension/revocation.ts +84 -0
  70. package/src/extension/shortcut.test.ts +64 -0
  71. package/src/extension/shortcut.ts +105 -0
  72. package/src/extension/tools.test.ts +993 -0
  73. package/src/extension/tools.ts +505 -0
  74. package/src/extension/version.test.ts +123 -0
  75. package/src/extension/version.ts +97 -0
  76. package/src/harness-policy.test.ts +74 -0
  77. package/src/package-manifest.test.ts +157 -0
  78. package/src/presentation/actions.test.ts +221 -0
  79. package/src/presentation/actions.ts +85 -0
  80. package/src/presentation/activity.test.ts +387 -0
  81. package/src/presentation/activity.ts +66 -0
  82. package/src/presentation/close.test.ts +361 -0
  83. package/src/presentation/inspector.test.ts +679 -0
  84. package/src/presentation/inspector.ts +440 -0
  85. package/src/presentation/overlay.test.ts +555 -0
  86. package/src/presentation/overlay.ts +229 -0
  87. package/src/presentation/repaint.test.ts +329 -0
  88. package/src/presentation/shortcut.ts +2 -0
  89. package/src/presentation/snapshot.test.ts +530 -0
  90. package/src/presentation/snapshot.ts +306 -0
  91. package/src/presentation/strip.test.ts +196 -0
  92. package/src/presentation/strip.ts +74 -0
  93. package/src/presentation/wording.test.ts +238 -0
  94. package/src/presentation/wording.ts +222 -0
  95. package/src/runtime/bridge.test.ts +131 -0
  96. package/src/runtime/bridge.ts +134 -0
  97. package/src/runtime/config.test.ts +44 -0
  98. package/src/runtime/config.ts +87 -0
  99. package/src/runtime/context.test.ts +19 -0
  100. package/src/runtime/context.ts +9 -0
  101. package/src/runtime/execution-env.test.ts +35 -0
  102. package/src/runtime/execution-env.ts +15 -0
  103. package/src/runtime/extensions.test.ts +86 -0
  104. package/src/runtime/extensions.ts +140 -0
  105. package/src/runtime/log.test.ts +128 -0
  106. package/src/runtime/log.ts +68 -0
  107. package/src/runtime/mcp.test.ts +1453 -0
  108. package/src/runtime/mcp.ts +938 -0
  109. package/src/runtime/models.test.ts +145 -0
  110. package/src/runtime/models.ts +259 -0
  111. package/src/runtime/observe.test.ts +50 -0
  112. package/src/runtime/observe.ts +150 -0
  113. package/src/runtime/session.test.ts +359 -0
  114. package/src/runtime/session.ts +425 -0
  115. package/src/runtime/timers.test.ts +31 -0
  116. package/src/runtime/timers.ts +10 -0
@@ -0,0 +1,165 @@
1
+ import { assert, it } from "@effect/vitest";
2
+ import { Schema } from "effect";
3
+ import {
4
+ decodeInlineDefinition,
5
+ DefinitionFieldNotAllowed,
6
+ InlineDefinition,
7
+ } from "./definitions.ts";
8
+ import { ControlRequest } from "./orchestration/control.ts";
9
+ import { FanoutRequest } from "./orchestration/fanout.ts";
10
+ import { ReviewRequest, SingleRequest } from "./orchestration/launch.ts";
11
+ import { ChildView, LaneView, RunView, SessionView } from "./view.ts";
12
+
13
+ it("the request shapes decode their wire values", () => {
14
+ assert.deepStrictEqual(
15
+ Schema.decodeSync(SingleRequest)({ kind: "single", agent: "scout", task: "look" }),
16
+ {
17
+ kind: "single",
18
+ agent: "scout",
19
+ task: "look",
20
+ },
21
+ );
22
+ assert.deepStrictEqual(
23
+ Schema.decodeSync(FanoutRequest)({
24
+ kind: "fanout",
25
+ lane: "review",
26
+ agents: [{ agent: "scout", task: "look" }],
27
+ policy: "failFast",
28
+ }),
29
+ {
30
+ kind: "fanout",
31
+ lane: "review",
32
+ agents: [{ agent: "scout", task: "look" }],
33
+ policy: "failFast",
34
+ },
35
+ );
36
+ assert.deepStrictEqual(
37
+ Schema.decodeSync(ReviewRequest)({
38
+ kind: "review",
39
+ task: "review",
40
+ reviewers: [{ agent: "reviewer" }],
41
+ }),
42
+ { kind: "review", task: "review", reviewers: [{ agent: "reviewer" }] },
43
+ );
44
+ assert.deepStrictEqual(
45
+ Schema.decodeSync(ControlRequest)({ action: "steer", run: "r-1", message: "go on" }),
46
+ { action: "steer", run: "r-1", message: "go on" },
47
+ );
48
+ assert.deepStrictEqual(
49
+ Schema.decodeSync(ControlRequest)({ action: "approve", run: "r-1", gate: "deploy" }),
50
+ { action: "approve", run: "r-1", gate: "deploy" },
51
+ );
52
+ });
53
+
54
+ it("the view shapes decode their values", () => {
55
+ const child = Schema.decodeSync(ChildView)({
56
+ child: 0,
57
+ runId: "r-1",
58
+ conversationId: null,
59
+ taskId: null,
60
+ agent: "scout",
61
+ status: "answered",
62
+ answer: "done",
63
+ durationMs: 3_000,
64
+ });
65
+ const lane = Schema.decodeSync(LaneView)({
66
+ name: "default",
67
+ running: 0,
68
+ queued: 0,
69
+ answered: 1,
70
+ });
71
+ const run = Schema.decodeSync(RunView)({
72
+ runId: "r-1",
73
+ definition: "scout",
74
+ mode: "single",
75
+ lane: "default",
76
+ conversationId: null,
77
+ taskId: null,
78
+ status: "answered",
79
+ answer: "done",
80
+ durationMs: 3_000,
81
+ children: [child],
82
+ missing: [],
83
+ gates: [],
84
+ requests: [],
85
+ diagnostic: null,
86
+ });
87
+ assert.deepStrictEqual(
88
+ Schema.decodeSync(SessionView)({
89
+ runs: [run],
90
+ lanes: [lane],
91
+ gates: [],
92
+ requests: [],
93
+ reviews: [],
94
+ }),
95
+ { runs: [run], lanes: [lane], gates: [], requests: [], reviews: [] },
96
+ );
97
+ });
98
+
99
+ it("an inline definition decodes as part of a single request", () => {
100
+ const definition = decodeInlineDefinition({
101
+ name: "custom",
102
+ role: "helper",
103
+ prompt: { role: "help" },
104
+ tools: ["read"],
105
+ });
106
+ assert.deepStrictEqual(
107
+ Schema.decodeSync(SingleRequest)({
108
+ kind: "single",
109
+ agent: "custom",
110
+ task: "look",
111
+ definition,
112
+ }),
113
+ { kind: "single", agent: "custom", task: "look", definition },
114
+ );
115
+ });
116
+
117
+ const inlineValue = {
118
+ name: "custom",
119
+ role: "helper",
120
+ prompt: { role: "help" },
121
+ tools: ["read"],
122
+ };
123
+
124
+ it("an inline definition cannot carry extensions or approval", () => {
125
+ const forbidden = [
126
+ ["extensions", ["coding"]],
127
+ ["approval", { gates: [] }],
128
+ ] as const;
129
+ for (const [field, value] of forbidden) {
130
+ let caught: unknown;
131
+ try {
132
+ decodeInlineDefinition({ ...inlineValue, [field]: value });
133
+ } catch (error) {
134
+ caught = error;
135
+ }
136
+ assert.ok(
137
+ caught instanceof DefinitionFieldNotAllowed &&
138
+ caught.field === field &&
139
+ caught.message.includes(field),
140
+ `${field} was not refused`,
141
+ );
142
+ }
143
+ });
144
+
145
+ it("an inline definition strips other unknown keys", () => {
146
+ const decoded = decodeInlineDefinition({ ...inlineValue, extra: true, nested: { value: 1 } });
147
+ assert.deepStrictEqual(decoded, inlineValue);
148
+ });
149
+
150
+ it("a valid inline definition carries no extensions or approval", () => {
151
+ const decoded = Schema.decodeSync(InlineDefinition)({
152
+ ...inlineValue,
153
+ model: { provider: "stub", modelId: "stub-1" },
154
+ thinkingLevel: "low",
155
+ cwd: "/tmp/work",
156
+ });
157
+ assert.deepStrictEqual(decoded, {
158
+ ...inlineValue,
159
+ model: { provider: "stub", modelId: "stub-1" },
160
+ thinkingLevel: "low",
161
+ cwd: "/tmp/work",
162
+ });
163
+ assert.ok(!("extensions" in decoded));
164
+ assert.ok(!("approval" in decoded));
165
+ });
@@ -0,0 +1,466 @@
1
+ import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
2
+ import { defineDoc, MemoryStorage, type JsonObject } from "@earendil-works/pi-durable";
3
+ import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";
4
+ import { tmpdir } from "node:os";
5
+ import { join } from "node:path";
6
+ import { Effect } from "effect";
7
+ import { assert, it } from "@effect/vitest";
8
+ import { rejects, throws } from "../../test-support/assertions.ts";
9
+ import { stubHostSource, type StubModelSource } from "../../test-support/stub-model-source.ts";
10
+ import {
11
+ createCatalogue,
12
+ decodeInlineDefinition,
13
+ defineAgent,
14
+ DefinitionFieldNotAllowed,
15
+ type AgentDefinition,
16
+ } from "./definitions.ts";
17
+ import { CODING_EXTENSION, SKILLS_EXTENSION } from "./names.ts";
18
+ import { RunDoc, RunIndexDoc } from "./run-records.ts";
19
+ import { resolverFor } from "./run-records.ts";
20
+ import { emptySkills } from "./skills.ts";
21
+ import { bindToolkit, ToolkitDoc, ToolkitUnresolved, type ToolkitResolver } from "./toolkit.ts";
22
+ import { HostModelAdapter } from "../runtime/models.ts";
23
+ import { createDelegatesRegistry } from "../runtime/extensions.ts";
24
+ import {
25
+ openReadOnlyRuntime,
26
+ openSessionRuntime,
27
+ storePathFor,
28
+ type SessionIdentity,
29
+ type SessionRuntime,
30
+ } from "../runtime/session.ts";
31
+ import { launch, type HostDefaults } from "./orchestration/launch.ts";
32
+ import { viewRun } from "./view.ts";
33
+
34
+ const identityFor = async (sessionId: string): Promise<SessionIdentity> => {
35
+ const sessionDir = await mkdtemp(join(tmpdir(), "delegates-skills-"));
36
+ return { sessionId, sessionDir, cwd: sessionDir, agentDir: sessionDir };
37
+ };
38
+
39
+ const openRuntime = (identity: SessionIdentity, skillPaths: readonly string[] = []) =>
40
+ openSessionRuntime({
41
+ identity,
42
+ models: new HostModelAdapter(stubHostSource()),
43
+ storage: new MemoryStorage(),
44
+ skills: { cwd: identity.cwd, agentDir: identity.agentDir, skillPaths },
45
+ });
46
+
47
+ const openWithSource = (
48
+ identity: SessionIdentity,
49
+ skillPaths: readonly string[],
50
+ source: StubModelSource,
51
+ ) =>
52
+ openSessionRuntime({
53
+ identity,
54
+ models: new HostModelAdapter(source),
55
+ storage: new MemoryStorage(),
56
+ skills: { cwd: identity.cwd, agentDir: identity.agentDir, skillPaths },
57
+ });
58
+
59
+ const openPersistent = (identity: SessionIdentity, skillPaths: readonly string[]) =>
60
+ openSessionRuntime({
61
+ identity,
62
+ models: new HostModelAdapter(stubHostSource()),
63
+ skills: { cwd: identity.cwd, agentDir: identity.agentDir, skillPaths },
64
+ });
65
+
66
+ /** An admission host for a registry a test only reads sections from. */
67
+ const quiet = {
68
+ inspect: () => Promise.resolve({ tasks: [] }) as never,
69
+ caps: () => ({ laneCap: 0, sessionCeiling: 0 }),
70
+ pollMs: 1000,
71
+ };
72
+
73
+ /** A prompt input whose committed document read returns the given declared skills. */
74
+ const promptInput = (skills: readonly string[]) =>
75
+ ({
76
+ conversationId: 1,
77
+ agent: { tools: [] },
78
+ env: undefined,
79
+ shown: {},
80
+ read: {
81
+ snapshot: () =>
82
+ Promise.resolve({
83
+ definition: "tester",
84
+ runId: "",
85
+ childRunId: "",
86
+ approval: { gates: [] },
87
+ skills,
88
+ }),
89
+ snapshotAsOf: () => Promise.resolve(undefined),
90
+ },
91
+ }) as never;
92
+
93
+ const host: HostDefaults = { model: { provider: "stub", modelId: "stub-1" }, thinkingLevel: "low" };
94
+
95
+ const skillFile = (name: string, options: { readonly hidden?: boolean } = {}): string =>
96
+ [
97
+ "---",
98
+ `name: ${name}`,
99
+ `description: The ${name} skill`,
100
+ ...((options.hidden ?? false) ? ["disable-model-invocation: true"] : []),
101
+ "---",
102
+ "",
103
+ `${name.toUpperCase()}_BODY_MARKER`,
104
+ "",
105
+ ].join("\n");
106
+
107
+ /** A temp root holding `<name>/SKILL.md` for each entry. */
108
+ const skillRoot = async (
109
+ entries: readonly (string | { readonly name: string; readonly hidden: boolean })[] = [],
110
+ ): Promise<string> => {
111
+ const root = await mkdtemp(join(tmpdir(), "delegates-skill-root-"));
112
+ for (const entry of entries) {
113
+ const name = typeof entry === "string" ? entry : entry.name;
114
+ const hidden = typeof entry === "string" ? false : entry.hidden;
115
+ await mkdir(join(root, name), { recursive: true });
116
+ await writeFile(join(root, name, "SKILL.md"), skillFile(name, { hidden }));
117
+ }
118
+ return root;
119
+ };
120
+
121
+ const tester = (skills: readonly string[]): AgentDefinition =>
122
+ defineAgent({
123
+ name: "tester",
124
+ role: "Test agent",
125
+ prompt: { role: "You test skills." },
126
+ tools: ["read"],
127
+ extensions: [CODING_EXTENSION],
128
+ approval: { gates: [] },
129
+ ...(skills.length === 0 ? {} : { skills: [...skills] }),
130
+ });
131
+
132
+ const launchDeps = (runtime: SessionRuntime, definition: AgentDefinition) => ({
133
+ runtime,
134
+ catalogue: createCatalogue([definition]),
135
+ host,
136
+ waitMs: 5_000,
137
+ });
138
+
139
+ /** The version 1 record a store written before this change holds. */
140
+ const LegacyToolkit = defineDoc<{
141
+ definition: string;
142
+ runId: string;
143
+ childRunId: string;
144
+ approval: JsonObject;
145
+ }>({
146
+ kind: "delegates.toolkit",
147
+ version: 1,
148
+ scope: "conversation",
149
+ history: "latest",
150
+ fork: "current",
151
+ initial: () => ({ definition: "", runId: "", childRunId: "", approval: { gates: [] } }),
152
+ checkpointWhen: () => true,
153
+ });
154
+
155
+ it("a version 1 toolkit document opens with no declared skills", async () => {
156
+ const runtime = await openRuntime(await identityFor("s-1"));
157
+ try {
158
+ const childId = await runtime.run((context) =>
159
+ runtime.harness.commit(async (tx) => {
160
+ const conversation = await tx.createConversation({ ownership: { kind: "ownerless" } });
161
+ const doc = await tx.doc(LegacyToolkit, conversation.id);
162
+ doc.definition = "legacy";
163
+ doc.runId = "run:legacy";
164
+ doc.childRunId = "run:legacy";
165
+ return conversation.id;
166
+ }, context),
167
+ );
168
+
169
+ const read = await runtime.run((context) =>
170
+ runtime.harness.snapshot(ToolkitDoc, childId, context),
171
+ );
172
+ assert.deepStrictEqual(read?.skills, []);
173
+ assert.strictEqual(read?.definition, "legacy");
174
+ } finally {
175
+ await runtime.close();
176
+ }
177
+ });
178
+
179
+ it("a version 2 document keeps the declared names", async () => {
180
+ const runtime = await openRuntime(await identityFor("s-1"));
181
+ try {
182
+ const childId = await runtime.run((context) =>
183
+ runtime.harness.commit(async (tx) => {
184
+ const conversation = await tx.createConversation({ ownership: { kind: "ownerless" } });
185
+ const doc = await tx.doc(ToolkitDoc, conversation.id);
186
+ doc.definition = "tester";
187
+ doc.runId = "run:tester";
188
+ doc.childRunId = "run:tester";
189
+ doc.skills = ["alpha", "beta"];
190
+ return conversation.id;
191
+ }, context),
192
+ );
193
+
194
+ const read = await runtime.run((context) =>
195
+ runtime.harness.snapshot(ToolkitDoc, childId, context),
196
+ );
197
+ assert.deepStrictEqual(read?.skills, ["alpha", "beta"]);
198
+ } finally {
199
+ await runtime.close();
200
+ }
201
+ });
202
+
203
+ it("an inline definition cannot declare skills", () => {
204
+ throws(
205
+ () =>
206
+ decodeInlineDefinition({
207
+ name: "nomad",
208
+ role: "audit",
209
+ prompt: { role: "audit" },
210
+ tools: ["read"],
211
+ skills: ["alpha"],
212
+ }),
213
+ (error: unknown) => error instanceof DefinitionFieldNotAllowed && error.field === "skills",
214
+ );
215
+ });
216
+
217
+ it("an unknown skill name fails before any run is claimed", async () => {
218
+ const root = await skillRoot(["alpha"]);
219
+ const runtime = await openRuntime(await identityFor("s-1"), [root]);
220
+ try {
221
+ const definition = tester(["gamma"]);
222
+ await rejects(
223
+ launch({ kind: "single", agent: "tester", task: "look" }, launchDeps(runtime, definition)),
224
+ (error: unknown) =>
225
+ error instanceof ToolkitUnresolved &&
226
+ error.message.includes("gamma") &&
227
+ error.message.includes("alpha"),
228
+ );
229
+ const index = await runtime.snapshot(RunIndexDoc);
230
+ assert.deepStrictEqual(index?.runIds ?? [], []);
231
+ } finally {
232
+ await runtime.close();
233
+ }
234
+ });
235
+
236
+ it("a declared skill binds and is carried by name", async () => {
237
+ const root = await skillRoot(["alpha", "beta"]);
238
+ const runtime = await openRuntime(await identityFor("s-1"), [root]);
239
+ try {
240
+ const definition = tester(["alpha"]);
241
+ const bound = await Effect.runPromise(
242
+ bindToolkit(
243
+ definition,
244
+ resolverFor({ registry: runtime.registry.snapshot(), skills: runtime.skills }),
245
+ ),
246
+ );
247
+ assert.deepStrictEqual(bound.names.skills, ["alpha"]);
248
+ assert.deepStrictEqual(bound.names.extensions, [CODING_EXTENSION, SKILLS_EXTENSION]);
249
+ } finally {
250
+ await runtime.close();
251
+ }
252
+ });
253
+
254
+ it("an empty catalogue names no available skills", async () => {
255
+ const skills = emptySkills();
256
+ const resolver: ToolkitResolver = {
257
+ availableExtensions: [],
258
+ availableTools: [],
259
+ availableSkills: skills.all().map((skill) => skill.name),
260
+ extension: () => undefined,
261
+ tool: () => undefined,
262
+ skill: skills.find,
263
+ mcpServers: [],
264
+ codemodeTools: [],
265
+ unconnected: undefined,
266
+ matchTools: () => [],
267
+ };
268
+ const failure = await bindToolkit(
269
+ defineAgent({
270
+ name: "tester",
271
+ role: "Test agent",
272
+ prompt: { role: "You test." },
273
+ tools: [],
274
+ extensions: [],
275
+ approval: { gates: [] },
276
+ skills: ["alpha"],
277
+ }),
278
+ resolver,
279
+ ).pipe(Effect.flip, Effect.runPromise);
280
+ assert.ok(failure instanceof ToolkitUnresolved);
281
+ assert.ok(failure.message.endsWith("Available skills: (none)."), failure.message);
282
+ });
283
+
284
+ it("a child prompt lists only its declared skills", async () => {
285
+ const root = await skillRoot(["alpha", "beta"]);
286
+ const source = stubHostSource({ text: "ok" });
287
+ const runtime = await openWithSource(await identityFor("s-1"), [root], source);
288
+ try {
289
+ const result = await launch(
290
+ { kind: "single", agent: "tester", task: "look" },
291
+ launchDeps(runtime, tester(["alpha"])),
292
+ );
293
+ assert.strictEqual(result.view.status, "answered");
294
+ const prompt = source.requests[0]?.systemPrompt ?? "";
295
+ assert.ok(prompt.includes("alpha"), prompt);
296
+ assert.ok(prompt.includes("read tool"), prompt);
297
+ assert.ok(!prompt.includes("beta"), prompt);
298
+ assert.ok(!prompt.includes("BETA_BODY_MARKER"), prompt);
299
+ } finally {
300
+ await runtime.close();
301
+ }
302
+ });
303
+
304
+ it("a skill marked disable-model-invocation is omitted from the prompt", async () => {
305
+ const root = await skillRoot(["alpha", { name: "gamma", hidden: true }]);
306
+ const source = stubHostSource({ text: "ok" });
307
+ const runtime = await openWithSource(await identityFor("s-1"), [root], source);
308
+ try {
309
+ const result = await launch(
310
+ { kind: "single", agent: "tester", task: "look" },
311
+ launchDeps(runtime, tester(["alpha", "gamma"])),
312
+ );
313
+ assert.strictEqual(result.view.status, "answered");
314
+ const prompt = source.requests[0]?.systemPrompt ?? "";
315
+ assert.ok(prompt.includes("alpha"), prompt);
316
+ assert.ok(!prompt.includes("gamma"), prompt);
317
+ } finally {
318
+ await runtime.close();
319
+ }
320
+ });
321
+
322
+ it("the toolkit document records the names and no bodies", async () => {
323
+ const root = await skillRoot(["alpha"]);
324
+ const runtime = await openRuntime(await identityFor("s-1"), [root]);
325
+ try {
326
+ const result = await launch(
327
+ { kind: "single", agent: "tester", task: "look" },
328
+ launchDeps(runtime, tester(["alpha"])),
329
+ );
330
+ const doc = await runtime.snapshot(RunDoc, result.view.runId);
331
+ const childId = doc!.childConversationId!;
332
+ const toolkit = await runtime.run((context) =>
333
+ runtime.harness.snapshot(ToolkitDoc, childId as never, context),
334
+ );
335
+ assert.deepStrictEqual(toolkit?.skills, ["alpha"]);
336
+ assert.ok(!JSON.stringify(toolkit).includes("ALPHA_BODY_MARKER"));
337
+ } finally {
338
+ await runtime.close();
339
+ }
340
+ });
341
+
342
+ it("the skills section renders nothing without declared skills", async () => {
343
+ const registry = createDelegatesRegistry({ admission: quiet, skills: emptySkills() }).registry;
344
+ const found = registry
345
+ .snapshot()
346
+ .sections()
347
+ .find((entry) => entry.section.key === "skills");
348
+ assert.ok(found !== undefined);
349
+ const rendered = await found.section.render(promptInput([]), BACKGROUND_CONTEXT);
350
+ assert.strictEqual(rendered, undefined);
351
+ });
352
+
353
+ it("reload sees a skill added since the session opened", async () => {
354
+ const root = await skillRoot(["alpha"]);
355
+ const runtime = await openRuntime(await identityFor("s-1"), [root]);
356
+ try {
357
+ assert.deepStrictEqual(
358
+ runtime.skills.all().map((skill) => skill.name),
359
+ ["alpha"],
360
+ );
361
+ await mkdir(join(root, "delta"), { recursive: true });
362
+ await writeFile(join(root, "delta", "SKILL.md"), skillFile("delta"));
363
+
364
+ await Effect.runPromise(runtime.skills.reload);
365
+
366
+ assert.deepStrictEqual(
367
+ runtime.skills.all().map((skill) => skill.name),
368
+ ["alpha", "delta"],
369
+ );
370
+ assert.ok(runtime.skills.all().every((skill) => !("body" in skill)));
371
+ } finally {
372
+ await runtime.close();
373
+ }
374
+ });
375
+
376
+ it("a reopened session sees the new skill and keeps declared names", async () => {
377
+ const root = await skillRoot(["alpha"]);
378
+ const identity = await identityFor("s-1");
379
+ const first = await openPersistent(identity, [root]);
380
+ let runId = "";
381
+ let childId = 0;
382
+ try {
383
+ const result = await launch(
384
+ { kind: "single", agent: "tester", task: "look" },
385
+ launchDeps(first, tester(["alpha"])),
386
+ );
387
+ runId = result.view.runId;
388
+ const doc = await first.snapshot(RunDoc, runId);
389
+ childId = doc!.childConversationId!;
390
+ assert.ok(childId > 0);
391
+ } finally {
392
+ await first.close();
393
+ }
394
+
395
+ await mkdir(join(root, "delta"), { recursive: true });
396
+ await writeFile(join(root, "delta", "SKILL.md"), skillFile("delta"));
397
+
398
+ const second = await openSessionRuntime({
399
+ identity,
400
+ models: new HostModelAdapter(stubHostSource()),
401
+ skills: { cwd: identity.cwd, agentDir: identity.agentDir, skillPaths: [root] },
402
+ });
403
+ try {
404
+ const toolkit = await second.run((context) =>
405
+ second.harness.snapshot(ToolkitDoc, childId as never, context),
406
+ );
407
+ assert.deepStrictEqual(toolkit?.skills, ["alpha"]);
408
+ assert.ok(second.skills.all().some((skill) => skill.name === "delta"));
409
+ } finally {
410
+ await second.close();
411
+ }
412
+ });
413
+
414
+ it("a viewer resolves the skills section from its own registry", async () => {
415
+ const root = await skillRoot(["alpha"]);
416
+ const identity = await identityFor("s-1");
417
+ const first = await openPersistent(identity, [root]);
418
+ let childId = 0;
419
+ try {
420
+ const result = await launch(
421
+ { kind: "single", agent: "tester", task: "look" },
422
+ launchDeps(first, tester(["alpha"])),
423
+ );
424
+ const doc = await first.snapshot(RunDoc, result.view.runId);
425
+ childId = doc!.childConversationId!;
426
+ assert.ok(childId > 0);
427
+ } finally {
428
+ await first.close();
429
+ }
430
+
431
+ const viewer = await openReadOnlyRuntime({
432
+ storePath: storePathFor(identity),
433
+ models: new HostModelAdapter(stubHostSource()),
434
+ });
435
+ try {
436
+ const conversation = await viewer.harness.conversation(childId as never, BACKGROUND_CONTEXT);
437
+ assert.ok(conversation !== undefined);
438
+ const agent = await conversation.agent(BACKGROUND_CONTEXT);
439
+ assert.ok(agent.extensions.some((extension) => extension.name === SKILLS_EXTENSION));
440
+ const skills = agent.sections.find((entry) => entry.key === "skills");
441
+ assert.ok(skills !== undefined);
442
+ // The viewer scanned no roots: the section exists but resolves nothing.
443
+ assert.strictEqual(await skills.render(promptInput(["alpha"]), BACKGROUND_CONTEXT), undefined);
444
+ } finally {
445
+ await viewer.close();
446
+ }
447
+ });
448
+
449
+ it("a skill deleted after open joins the view's missing list", async () => {
450
+ const root = await skillRoot(["alpha"]);
451
+ const runtime = await openRuntime(await identityFor("s-1"), [root]);
452
+ try {
453
+ const result = await launch(
454
+ { kind: "single", agent: "tester", task: "look" },
455
+ launchDeps(runtime, tester(["alpha"])),
456
+ );
457
+ await rm(join(root, "alpha", "SKILL.md"));
458
+ await Effect.runPromise(runtime.skills.reload);
459
+
460
+ const view = await viewRun(result.view.runId, runtime);
461
+ assert.deepStrictEqual(view.missing, ["alpha"]);
462
+ assert.strictEqual(view.status, result.view.status);
463
+ } finally {
464
+ await runtime.close();
465
+ }
466
+ });