@fungi.computer/shiitake-extensions 0.6.15 → 0.8.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/dist/almanac/host.js +164 -39
- package/dist/loop/host.js +2 -2
- package/dist/roster/conversation-agents.d.ts +9 -2
- package/dist/roster/conversation-agents.js +9 -4
- package/dist/roster.d.ts +5 -0
- package/dist/roster.js +16 -6
- package/dist/skills/discovery.d.ts +75 -0
- package/dist/skills/discovery.js +144 -0
- package/dist/skills/host.d.ts +9 -1
- package/dist/skills/host.js +9 -7
- package/docs/api/roster/conversation-agents.md +10 -5
- package/docs/api/roster.md +26 -0
- package/docs/api/skills/host.md +3 -3
- package/package.json +9 -4
package/dist/almanac/host.js
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
|
+
import { CapabilityFailed, Mycelium, } from "@fungi.computer/mycelium";
|
|
1
2
|
import { defineCollection, defineExtension, ExtensionCommandError, } from "@fungi.computer/shiitake/extensions";
|
|
3
|
+
import * as Cause from "effect/Cause";
|
|
2
4
|
import * as Clock from "effect/Clock";
|
|
3
5
|
import * as Effect from "effect/Effect";
|
|
6
|
+
import * as Exit from "effect/Exit";
|
|
4
7
|
import * as Result from "effect/Result";
|
|
5
8
|
import * as Option from "effect/Option";
|
|
6
9
|
import { afterAdmitted, afterRefused, cancelled, occurrenceKey, paused, resumed, settled, } from "@fungi.computer/almanac";
|
|
10
|
+
import { z } from "zod";
|
|
11
|
+
import { freshRequestId } from "../internal/catalog.js";
|
|
7
12
|
import { nextOccurrence } from "../internal/cron.js";
|
|
8
13
|
import { almanacContract, Schedule } from "./contract.js";
|
|
9
14
|
/** Hashed policy: every constant Almanac reads comes from here. */
|
|
@@ -12,6 +17,8 @@ const config = {
|
|
|
12
17
|
retryBaseMs: 30_000,
|
|
13
18
|
/** Longest retry delay; one poisoned schedule never blocks the others. */
|
|
14
19
|
retryMaxMs: 3_600_000,
|
|
20
|
+
/** The one idle prompt line; the rules load with forage.describe. */
|
|
21
|
+
idle: "Daily, weekly or one-time work? forage.describe({path:'schedule'}) first.",
|
|
15
22
|
};
|
|
16
23
|
const collections = {
|
|
17
24
|
schedules: defineCollection(Schedule, {
|
|
@@ -49,6 +56,50 @@ function create(ctx, schedule) {
|
|
|
49
56
|
return schedule;
|
|
50
57
|
});
|
|
51
58
|
}
|
|
59
|
+
/** Create a one-shot schedule due at one instant. */
|
|
60
|
+
function createOneShot(ctx, input) {
|
|
61
|
+
return create(ctx, {
|
|
62
|
+
id: input.requestId,
|
|
63
|
+
sessionId: input.sessionId,
|
|
64
|
+
prompt: input.prompt,
|
|
65
|
+
cron: null,
|
|
66
|
+
nextDueAt: input.dueAt,
|
|
67
|
+
state: "active",
|
|
68
|
+
lastCommandId: null,
|
|
69
|
+
lastError: null,
|
|
70
|
+
attempt: 0,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
/** Create a recurring cron schedule; its first occurrence follows now. */
|
|
74
|
+
function createRecurring(ctx, input) {
|
|
75
|
+
return Effect.gen(function* () {
|
|
76
|
+
const cron = { expression: input.expression, timeZone: input.timeZone };
|
|
77
|
+
const now = yield* Clock.currentTimeMillis;
|
|
78
|
+
return yield* create(ctx, {
|
|
79
|
+
id: input.requestId,
|
|
80
|
+
sessionId: input.sessionId,
|
|
81
|
+
prompt: input.prompt,
|
|
82
|
+
cron,
|
|
83
|
+
nextDueAt: yield* nextOccurrence(cron, now),
|
|
84
|
+
state: "active",
|
|
85
|
+
lastCommandId: null,
|
|
86
|
+
lastError: null,
|
|
87
|
+
attempt: 0,
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
/** Cancel future occurrences; a settled schedule is returned as it is. */
|
|
92
|
+
function cancelSchedule(ctx, scheduleId) {
|
|
93
|
+
return Effect.gen(function* () {
|
|
94
|
+
const schedule = yield* requireSchedule(ctx, scheduleId);
|
|
95
|
+
if (settled(schedule))
|
|
96
|
+
return schedule;
|
|
97
|
+
const next = cancelled(schedule);
|
|
98
|
+
yield* ctx.state.schedules.put(next);
|
|
99
|
+
yield* ctx.timers.cancel(schedule.id);
|
|
100
|
+
return next;
|
|
101
|
+
});
|
|
102
|
+
}
|
|
52
103
|
/**
|
|
53
104
|
* Send the due occurrence through the door. The occurrence request id is
|
|
54
105
|
* `id:occurrenceAt`, so a retried admission replays instead of duplicating.
|
|
@@ -86,47 +137,129 @@ function fire(ctx, id, now) {
|
|
|
86
137
|
yield* ctx.timers.set(schedule.id, next.nextDueAt);
|
|
87
138
|
});
|
|
88
139
|
}
|
|
140
|
+
/** What the model reads from `schedule.describe`; also the module's description. */
|
|
141
|
+
const moduleDescription = "Durable schedules that send you a prompt in this Session when due: schedule.create({prompt,when}), schedule.list({}), schedule.cancel({scheduleId}). " +
|
|
142
|
+
"when is {kind:'once',at:ISO-8601 instant with offset} or {kind:'cron',expression,timeZone?}; a cron expression has five fields, so every morning at 8 is '0 8 * * *' and Mondays at 9:30 is '30 9 * * 1', evaluated in timeZone (IANA, default UTC; use the person's zone when you know it). " +
|
|
143
|
+
"Use a schedule for a daily, weekly or other cadence that must outlast a loop's 7 days, or for one future time. Schedules persist until cancelled; tell the person what you scheduled and its id so they can cancel it.";
|
|
144
|
+
/** Run one tool transaction and keep the owner's own diagnostic. */
|
|
145
|
+
function toolCall(ctx, operation, body) {
|
|
146
|
+
return Effect.runPromiseExit(ctx.transact(body)).then((exit) => {
|
|
147
|
+
if (Exit.isSuccess(exit))
|
|
148
|
+
return exit.value;
|
|
149
|
+
const failure = Cause.squash(exit.cause);
|
|
150
|
+
return Promise.reject(new CapabilityFailed({
|
|
151
|
+
namespace: "schedule",
|
|
152
|
+
operation,
|
|
153
|
+
cause: {
|
|
154
|
+
kind: "OperationFailed",
|
|
155
|
+
message: failure instanceof Error ? failure.message : "Schedule tool failed",
|
|
156
|
+
},
|
|
157
|
+
}));
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
// Mycelium's maintained operation interface takes Zod for model-tool I/O.
|
|
161
|
+
const toolSchedule = z.strictObject({
|
|
162
|
+
id: z.string(),
|
|
163
|
+
prompt: z.string(),
|
|
164
|
+
cron: z
|
|
165
|
+
.strictObject({ expression: z.string(), timeZone: z.string() })
|
|
166
|
+
.nullable(),
|
|
167
|
+
nextDueAt: z.number(),
|
|
168
|
+
state: z.enum(["active", "paused", "cancelled", "finished"]),
|
|
169
|
+
lastError: z.string().nullable(),
|
|
170
|
+
});
|
|
171
|
+
function projected(schedule) {
|
|
172
|
+
return {
|
|
173
|
+
id: schedule.id,
|
|
174
|
+
prompt: schedule.prompt,
|
|
175
|
+
cron: schedule.cron,
|
|
176
|
+
nextDueAt: schedule.nextDueAt,
|
|
177
|
+
state: schedule.state,
|
|
178
|
+
lastError: schedule.lastError,
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
/** The model-facing create/list/cancel, over the same commands the Hub and Local read. */
|
|
182
|
+
function scheduleModule(ctx, sessionId) {
|
|
183
|
+
return Mycelium.module({
|
|
184
|
+
id: "botanical.almanac",
|
|
185
|
+
name: "schedule",
|
|
186
|
+
description: moduleDescription,
|
|
187
|
+
operations: {
|
|
188
|
+
create: Mycelium.operation({
|
|
189
|
+
replay: "unsafe",
|
|
190
|
+
description: "Schedule a prompt for this Session, once or on a cron cadence. Returns the schedule with its id and next due time.",
|
|
191
|
+
input: z.strictObject({
|
|
192
|
+
prompt: z.string().trim().min(1).max(4_000),
|
|
193
|
+
when: z.union([
|
|
194
|
+
z.strictObject({
|
|
195
|
+
kind: z.literal("once"),
|
|
196
|
+
at: z.iso.datetime({ offset: true }),
|
|
197
|
+
}),
|
|
198
|
+
z.strictObject({
|
|
199
|
+
kind: z.literal("cron"),
|
|
200
|
+
expression: z.string().trim().min(1).max(256),
|
|
201
|
+
timeZone: z.string().trim().min(1).max(128).default("UTC"),
|
|
202
|
+
}),
|
|
203
|
+
]),
|
|
204
|
+
}),
|
|
205
|
+
output: toolSchedule,
|
|
206
|
+
execute: ({ prompt, when }) => toolCall(ctx, "create", Effect.gen(function* () {
|
|
207
|
+
const requestId = yield* freshRequestId;
|
|
208
|
+
if (when.kind === "cron")
|
|
209
|
+
return projected(yield* createRecurring(ctx, {
|
|
210
|
+
requestId,
|
|
211
|
+
sessionId,
|
|
212
|
+
prompt,
|
|
213
|
+
expression: when.expression,
|
|
214
|
+
timeZone: when.timeZone,
|
|
215
|
+
}));
|
|
216
|
+
const dueAt = Date.parse(when.at);
|
|
217
|
+
const now = yield* Clock.currentTimeMillis;
|
|
218
|
+
if (dueAt <= now)
|
|
219
|
+
return yield* Effect.fail(rejected("invalid", "A one-shot schedule must be in the future"));
|
|
220
|
+
return projected(yield* createOneShot(ctx, {
|
|
221
|
+
requestId,
|
|
222
|
+
sessionId,
|
|
223
|
+
prompt,
|
|
224
|
+
dueAt,
|
|
225
|
+
}));
|
|
226
|
+
})),
|
|
227
|
+
}),
|
|
228
|
+
list: Mycelium.operation({
|
|
229
|
+
replay: "safe",
|
|
230
|
+
description: "List this Agent's schedules, with ids, cadence, state and next due time.",
|
|
231
|
+
input: z.strictObject({}),
|
|
232
|
+
output: z.array(toolSchedule),
|
|
233
|
+
execute: () => toolCall(ctx, "list", ctx.state.schedules
|
|
234
|
+
.page({ limit: 64 })
|
|
235
|
+
.pipe(Effect.map((rows) => rows.map(projected)))),
|
|
236
|
+
}),
|
|
237
|
+
cancel: Mycelium.operation({
|
|
238
|
+
replay: "unsafe",
|
|
239
|
+
description: "Cancel a schedule's future occurrences by id; a finished or cancelled one is returned unchanged.",
|
|
240
|
+
input: z.strictObject({ scheduleId: z.string() }),
|
|
241
|
+
output: toolSchedule,
|
|
242
|
+
execute: ({ scheduleId }) => toolCall(ctx, "cancel", cancelSchedule(ctx, scheduleId).pipe(Effect.map(projected))),
|
|
243
|
+
}),
|
|
244
|
+
},
|
|
245
|
+
});
|
|
246
|
+
}
|
|
89
247
|
/** Botanical's Almanac on Shiitake timers and the one admission door. */
|
|
90
248
|
export const almanacExtension = defineExtension({
|
|
91
249
|
id: almanacContract.id,
|
|
92
|
-
version: "1.
|
|
250
|
+
version: "1.2.0",
|
|
93
251
|
})
|
|
94
252
|
.config(config)
|
|
95
253
|
.state({ version: 1, migrations: {}, collections })
|
|
96
254
|
.define({
|
|
255
|
+
prompt: () => Effect.succeed([{ name: "schedule", text: config.idle }]),
|
|
256
|
+
tools: (ctx, { sessionId }) => Effect.succeed(Option.some(scheduleModule(ctx, sessionId))),
|
|
97
257
|
hooks: { onTimer: (ctx, timer) => fire(ctx, timer.key, timer.firedAt) },
|
|
98
258
|
commands: {
|
|
99
259
|
specs: almanacContract.commands,
|
|
100
260
|
handlers: (ctx) => ({
|
|
101
|
-
createOneShot: ({ input }) =>
|
|
102
|
-
|
|
103
|
-
sessionId: input.sessionId,
|
|
104
|
-
prompt: input.prompt,
|
|
105
|
-
cron: null,
|
|
106
|
-
nextDueAt: input.dueAt,
|
|
107
|
-
state: "active",
|
|
108
|
-
lastCommandId: null,
|
|
109
|
-
lastError: null,
|
|
110
|
-
attempt: 0,
|
|
111
|
-
}),
|
|
112
|
-
createRecurring: ({ input }) => Effect.gen(function* () {
|
|
113
|
-
const cron = {
|
|
114
|
-
expression: input.expression,
|
|
115
|
-
timeZone: input.timeZone,
|
|
116
|
-
};
|
|
117
|
-
const now = yield* Clock.currentTimeMillis;
|
|
118
|
-
return yield* create(ctx, {
|
|
119
|
-
id: input.requestId,
|
|
120
|
-
sessionId: input.sessionId,
|
|
121
|
-
prompt: input.prompt,
|
|
122
|
-
cron,
|
|
123
|
-
nextDueAt: yield* nextOccurrence(cron, now),
|
|
124
|
-
state: "active",
|
|
125
|
-
lastCommandId: null,
|
|
126
|
-
lastError: null,
|
|
127
|
-
attempt: 0,
|
|
128
|
-
});
|
|
129
|
-
}),
|
|
261
|
+
createOneShot: ({ input }) => createOneShot(ctx, input),
|
|
262
|
+
createRecurring: ({ input }) => createRecurring(ctx, input),
|
|
130
263
|
read: ({ input }) => ctx.state.schedules
|
|
131
264
|
.get(input.scheduleId)
|
|
132
265
|
.pipe(Effect.map(Option.getOrNull)),
|
|
@@ -157,15 +290,7 @@ export const almanacExtension = defineExtension({
|
|
|
157
290
|
yield* ctx.timers.set(schedule.id, back.success.nextDueAt);
|
|
158
291
|
return back.success;
|
|
159
292
|
}),
|
|
160
|
-
cancel: ({ input }) =>
|
|
161
|
-
const schedule = yield* requireSchedule(ctx, input.scheduleId);
|
|
162
|
-
if (settled(schedule))
|
|
163
|
-
return schedule;
|
|
164
|
-
const next = cancelled(schedule);
|
|
165
|
-
yield* ctx.state.schedules.put(next);
|
|
166
|
-
yield* ctx.timers.cancel(schedule.id);
|
|
167
|
-
return next;
|
|
168
|
-
}),
|
|
293
|
+
cancel: ({ input }) => cancelSchedule(ctx, input.scheduleId),
|
|
169
294
|
}),
|
|
170
295
|
},
|
|
171
296
|
});
|
package/dist/loop/host.js
CHANGED
|
@@ -13,7 +13,7 @@ import { nextOccurrence } from "../internal/cron.js";
|
|
|
13
13
|
import { Loop, LoopCommandInput, loopContract } from "./contract.js";
|
|
14
14
|
import { loopMenuPrompt, stopConfirmation } from "./prompts.js";
|
|
15
15
|
/** The rules the model follows; the describe page and a live loop's prompt share them. */
|
|
16
|
-
const rules = "You may start loops yourself; one live loop per Session. Failed loop ticks retry with backoff; loop.get shows consecutiveFailures, lastError, and nextDueAt. schedule_next is allowed only in the active self-paced loop's own run, clamped to 60–3600 seconds. Omitting it ends that loop. stop works in any Session run. Human pause/resume/stop and Esc remain user controls. A fixed every-N cadence ends after 7 days;
|
|
16
|
+
const rules = "You may start loops yourself; one live loop per Session. Failed loop ticks retry with backoff; loop.get shows consecutiveFailures, lastError, and nextDueAt. schedule_next is allowed only in the active self-paced loop's own run, clamped to 60–3600 seconds. Omitting it ends that loop. stop works in any Session run. Human pause/resume/stop and Esc remain user controls. A fixed every-N cadence ends after 7 days; for a daily or weekly cadence, or anything longer, use schedule.create (forage.describe({path:'schedule'})) instead, and otherwise tell the person when you start one.";
|
|
17
17
|
/** Hashed prose and policy: every constant loop reads comes from here. */
|
|
18
18
|
const config = {
|
|
19
19
|
minDelaySeconds: 60,
|
|
@@ -380,7 +380,7 @@ function loopModule(ctx, sessionId, workId) {
|
|
|
380
380
|
}),
|
|
381
381
|
start: Mycelium.operation({
|
|
382
382
|
replay: "unsafe",
|
|
383
|
-
description: "Start a Session loop, including autonomously. One live loop per Session; the first prompt runs after the current run. A fixed every-N cadence ends after 7 days.",
|
|
383
|
+
description: "Start a Session loop, including autonomously. One live loop per Session; the first prompt runs after the current run. A fixed every-N cadence ends after 7 days; use schedule.create for longer ones.",
|
|
384
384
|
input: z.strictObject({
|
|
385
385
|
prompt: z
|
|
386
386
|
.string()
|
|
@@ -2,6 +2,7 @@ import { type AgentControlDirectory } from "@fungi.computer/shiitake/agent-contr
|
|
|
2
2
|
import type { CapabilitySource } from "@fungi.computer/mycelium";
|
|
3
3
|
import { type ShiitakeSession } from "@fungi.computer/shiitake/client";
|
|
4
4
|
import type { WatchdogSqliteOwner } from "@fungi.computer/watchdog";
|
|
5
|
+
import type { SkillSource } from "../skills/source.js";
|
|
5
6
|
import type { SubagentSource } from "../subagents/host.js";
|
|
6
7
|
/** Host-pack creation admission; attachments/model selection retain their own owners. */
|
|
7
8
|
export declare function assertOrdinaryAgentCreation(input: Parameters<NonNullable<AgentControlDirectory["create"]>>[0]): void;
|
|
@@ -40,8 +41,14 @@ export declare function createConversationAgents(storage: WatchdogSqliteOwner):
|
|
|
40
41
|
/** The footer rows for one conversation; archived and unknown Agents leave it. */
|
|
41
42
|
source: (directory: Pick<AgentControlDirectory, "list"> & Pick<SubagentSource, "open">) => SubagentSource;
|
|
42
43
|
};
|
|
43
|
-
/**
|
|
44
|
-
|
|
44
|
+
/**
|
|
45
|
+
* Both hosts compose the ordinary roster and its read-only created-Agent
|
|
46
|
+
* footer. A host that can read skills where its Agent works adds them.
|
|
47
|
+
*/
|
|
48
|
+
export declare function oysterAgentExtensions(source: SubagentSource, skills?: Readonly<{
|
|
49
|
+
source: SkillSource;
|
|
50
|
+
empty: string;
|
|
51
|
+
}>): Readonly<{
|
|
45
52
|
roster: readonly import("@fungi.computer/shiitake").RosteredExtensionV0[];
|
|
46
53
|
grants: readonly import("@fungi.computer/shiitake").ExtensionGrantV0[];
|
|
47
54
|
}>;
|
|
@@ -2,7 +2,7 @@ import { AgentCreateRefused, createAgentControlSource, } from "@fungi.computer/s
|
|
|
2
2
|
import { bindSessionExtension, } from "@fungi.computer/shiitake/client";
|
|
3
3
|
import * as Effect from "effect/Effect";
|
|
4
4
|
import * as Schema from "effect/Schema";
|
|
5
|
-
import { botanicalAgentExtensions, botanicalExtensionsWithSubagents, } from "../roster.js";
|
|
5
|
+
import { botanicalAgentExtensions, botanicalExtensionsWithSkillSource, botanicalExtensionsWithSubagents, } from "../roster.js";
|
|
6
6
|
import { goalContract } from "../goal/contract.js";
|
|
7
7
|
/** Host-pack creation admission; attachments/model selection retain their own owners. */
|
|
8
8
|
export function assertOrdinaryAgentCreation(input) {
|
|
@@ -242,7 +242,12 @@ export function createConversationAgents(storage) {
|
|
|
242
242
|
},
|
|
243
243
|
};
|
|
244
244
|
}
|
|
245
|
-
/**
|
|
246
|
-
|
|
247
|
-
|
|
245
|
+
/**
|
|
246
|
+
* Both hosts compose the ordinary roster and its read-only created-Agent
|
|
247
|
+
* footer. A host that can read skills where its Agent works adds them.
|
|
248
|
+
*/
|
|
249
|
+
export function oysterAgentExtensions(source, skills) {
|
|
250
|
+
return botanicalExtensionsWithSubagents(skills === undefined
|
|
251
|
+
? botanicalAgentExtensions
|
|
252
|
+
: botanicalExtensionsWithSkillSource(botanicalAgentExtensions, skills.source, { empty: skills.empty, scanOnStart: false }), source);
|
|
248
253
|
}
|
package/dist/roster.d.ts
CHANGED
|
@@ -9,6 +9,11 @@ import { type SubagentSource } from "./subagents/host.js";
|
|
|
9
9
|
export declare const botanicalAgentExtensions: ExtensionRosterV0;
|
|
10
10
|
/** Compose the goal and footer over one source; an absent goal is a wiring error. */
|
|
11
11
|
export declare function botanicalExtensionsWithSubagents(base: ExtensionRosterV0, source: SubagentSource): ExtensionRosterV0;
|
|
12
|
+
/** Add read-only skill discovery over `source` to any roster. */
|
|
13
|
+
export declare function botanicalExtensionsWithSkillSource(base: ExtensionRosterV0, source: SkillSource, options?: Readonly<{
|
|
14
|
+
empty?: string;
|
|
15
|
+
scanOnStart?: boolean;
|
|
16
|
+
}>): ExtensionRosterV0;
|
|
12
17
|
/** A host with a SkillSource grants read-only skill discovery for its own runs. */
|
|
13
18
|
export declare function botanicalExtensionsWithSkills(source: SkillSource): ExtensionRosterV0;
|
|
14
19
|
/** Route Asks to the Agent that sent the work, only in a host that owns the Local answer door. */
|
package/dist/roster.js
CHANGED
|
@@ -67,7 +67,14 @@ export const botanicalAgentExtensions = Object.freeze({
|
|
|
67
67
|
},
|
|
68
68
|
{
|
|
69
69
|
id: almanacContract.id,
|
|
70
|
-
capabilities: [
|
|
70
|
+
capabilities: [
|
|
71
|
+
"state",
|
|
72
|
+
"send",
|
|
73
|
+
"timers",
|
|
74
|
+
"commands",
|
|
75
|
+
"run_tools",
|
|
76
|
+
"prompt",
|
|
77
|
+
],
|
|
71
78
|
},
|
|
72
79
|
{
|
|
73
80
|
id: planContract.id,
|
|
@@ -89,14 +96,17 @@ export function botanicalExtensionsWithSubagents(base, source) {
|
|
|
89
96
|
grants: [...base.grants, subagentsGrant],
|
|
90
97
|
};
|
|
91
98
|
}
|
|
92
|
-
/**
|
|
93
|
-
export function
|
|
94
|
-
const local = botanicalExtensionsWithSenderRouting();
|
|
99
|
+
/** Add read-only skill discovery over `source` to any roster. */
|
|
100
|
+
export function botanicalExtensionsWithSkillSource(base, source, options = {}) {
|
|
95
101
|
return {
|
|
96
|
-
roster: [...
|
|
97
|
-
grants: [...
|
|
102
|
+
roster: [...base.roster, skillsExtension({ source, ...options })],
|
|
103
|
+
grants: [...base.grants, skillsGrant],
|
|
98
104
|
};
|
|
99
105
|
}
|
|
106
|
+
/** A host with a SkillSource grants read-only skill discovery for its own runs. */
|
|
107
|
+
export function botanicalExtensionsWithSkills(source) {
|
|
108
|
+
return botanicalExtensionsWithSkillSource(botanicalExtensionsWithSenderRouting(), source);
|
|
109
|
+
}
|
|
100
110
|
/** Route Asks to the Agent that sent the work, only in a host that owns the Local answer door. */
|
|
101
111
|
export function botanicalExtensionsWithSenderRouting() {
|
|
102
112
|
return {
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { SkillCatalog, SkillDescription, SkillDiagnostic, SkillOrigin } from "./source.js";
|
|
3
|
+
/**
|
|
4
|
+
* The rules of skill discovery, shared by every host: what a SKILL.md must
|
|
5
|
+
* say, how a name and a file are checked, which bounds apply and how one
|
|
6
|
+
* found skill is admitted to a catalog. A host brings only its own way of
|
|
7
|
+
* walking and reading folders: Local its disk, Oyster an Agent's Computer.
|
|
8
|
+
*/
|
|
9
|
+
/** Most skills one catalog admits. */
|
|
10
|
+
export declare const maximumSkillCount = 64;
|
|
11
|
+
/** Most bytes the catalog's JSON may take. */
|
|
12
|
+
export declare const maximumCatalogBytes = 16000;
|
|
13
|
+
/** Most bytes one skill file may be. */
|
|
14
|
+
export declare const maximumFileBytes: number;
|
|
15
|
+
/** Most folder entries one discovery or supporting-file walk may visit. */
|
|
16
|
+
export declare const maximumDirectoryEntries = 512;
|
|
17
|
+
/** Deepest supporting-file folder nesting. */
|
|
18
|
+
export declare const maximumSupportingDepth = 16;
|
|
19
|
+
/** Deepest folder nesting a discovery walk searches. */
|
|
20
|
+
export declare const maximumDiscoveryDepth = 16;
|
|
21
|
+
/** A refusal whose message is safe to show; any other failure is described generically. */
|
|
22
|
+
export declare class SkillSourceError extends Error {
|
|
23
|
+
}
|
|
24
|
+
/** Lowercase letters, digits and single hyphens, at most 64 characters. */
|
|
25
|
+
export declare const skillNameSchema: z.ZodString;
|
|
26
|
+
/** A supporting file named relative to its skill folder, never leaving it. */
|
|
27
|
+
export declare const skillFileSchema: z.ZodString;
|
|
28
|
+
/** A discovery diagnostic; `cause` defaults to the message itself. */
|
|
29
|
+
export declare function skillDiagnostic(path: string, reason: SkillDiagnostic["reason"], message: string, cause?: unknown): SkillDiagnostic;
|
|
30
|
+
/** The message a refusal carries, else the fallback that hides any other cause. */
|
|
31
|
+
export declare function skillExplanation(cause: unknown, fallback: string): string;
|
|
32
|
+
/** Where a skill's origin is named in a collision message. */
|
|
33
|
+
export declare function describeSkillOrigin(origin: SkillOrigin): string;
|
|
34
|
+
/**
|
|
35
|
+
* Split a SKILL.md into its YAML frontmatter and body, or refuse it plainly:
|
|
36
|
+
* no frontmatter, invalid YAML, wrong field types or no description.
|
|
37
|
+
* `directoryName` names the skill when its frontmatter does not.
|
|
38
|
+
*/
|
|
39
|
+
export declare function parseSkill(content: string, directoryName: string): {
|
|
40
|
+
metadata: {
|
|
41
|
+
name: string;
|
|
42
|
+
description: string;
|
|
43
|
+
"disable-model-invocation": boolean;
|
|
44
|
+
};
|
|
45
|
+
body: string;
|
|
46
|
+
};
|
|
47
|
+
/** What one discovery pass has admitted so far; hosts hand the same state to each skill. */
|
|
48
|
+
export type SkillAdmission = Readonly<{
|
|
49
|
+
skills: SkillDescription[];
|
|
50
|
+
/** Which origin first took each name; the first wins. */
|
|
51
|
+
owners: Map<string, SkillOrigin>;
|
|
52
|
+
diagnostics: SkillDiagnostic[];
|
|
53
|
+
}>;
|
|
54
|
+
/** A fresh, empty admission state. */
|
|
55
|
+
export declare function newSkillAdmission(diagnostics?: SkillDiagnostic[]): SkillAdmission;
|
|
56
|
+
/** The finished catalog of an admission state. */
|
|
57
|
+
export declare function skillCatalogOf(state: SkillAdmission): SkillCatalog;
|
|
58
|
+
/**
|
|
59
|
+
* Admit one parsed skill to the catalog, or say why not: a name that does not
|
|
60
|
+
* match its folder or the naming rule and an overlong description are
|
|
61
|
+
* warnings; a name already taken loses; a skill that disables model
|
|
62
|
+
* invocation is skipped; the catalog's 64-skill and 16 KB bounds hold.
|
|
63
|
+
*/
|
|
64
|
+
export declare function admitSkill(state: SkillAdmission, found: Readonly<{
|
|
65
|
+
metadata: ReturnType<typeof parseSkill>["metadata"];
|
|
66
|
+
/** The folder holding SKILL.md, by name. */
|
|
67
|
+
directoryName: string;
|
|
68
|
+
/** Where SKILL.md is, as discovery reports problems. */
|
|
69
|
+
skillPath: string;
|
|
70
|
+
/** The file the host reads. */
|
|
71
|
+
location: string;
|
|
72
|
+
/** The same file as the model should see it. */
|
|
73
|
+
displayLocation: string;
|
|
74
|
+
origin: SkillOrigin;
|
|
75
|
+
}>): void;
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { parse as parseYaml } from "yaml";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
/**
|
|
4
|
+
* The rules of skill discovery, shared by every host: what a SKILL.md must
|
|
5
|
+
* say, how a name and a file are checked, which bounds apply and how one
|
|
6
|
+
* found skill is admitted to a catalog. A host brings only its own way of
|
|
7
|
+
* walking and reading folders: Local its disk, Oyster an Agent's Computer.
|
|
8
|
+
*/
|
|
9
|
+
/** Most skills one catalog admits. */
|
|
10
|
+
export const maximumSkillCount = 64;
|
|
11
|
+
/** Most bytes the catalog's JSON may take. */
|
|
12
|
+
export const maximumCatalogBytes = 16_000;
|
|
13
|
+
/** Most bytes one skill file may be. */
|
|
14
|
+
export const maximumFileBytes = 128 * 1_024;
|
|
15
|
+
/** Most folder entries one discovery or supporting-file walk may visit. */
|
|
16
|
+
export const maximumDirectoryEntries = 512;
|
|
17
|
+
/** Deepest supporting-file folder nesting. */
|
|
18
|
+
export const maximumSupportingDepth = 16;
|
|
19
|
+
/** Deepest folder nesting a discovery walk searches. */
|
|
20
|
+
export const maximumDiscoveryDepth = 16;
|
|
21
|
+
const utf8 = new TextEncoder();
|
|
22
|
+
/** A refusal whose message is safe to show; any other failure is described generically. */
|
|
23
|
+
export class SkillSourceError extends Error {
|
|
24
|
+
}
|
|
25
|
+
/** Lowercase letters, digits and single hyphens, at most 64 characters. */
|
|
26
|
+
export const skillNameSchema = z
|
|
27
|
+
.string()
|
|
28
|
+
.min(1)
|
|
29
|
+
.max(64)
|
|
30
|
+
.regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/u);
|
|
31
|
+
const frontmatterSchema = z.object({
|
|
32
|
+
name: z.string().optional(),
|
|
33
|
+
description: z.string().optional(),
|
|
34
|
+
"disable-model-invocation": z
|
|
35
|
+
.unknown()
|
|
36
|
+
.default(false)
|
|
37
|
+
.transform((value) => value === true),
|
|
38
|
+
});
|
|
39
|
+
/** A supporting file named relative to its skill folder, never leaving it. */
|
|
40
|
+
export const skillFileSchema = z
|
|
41
|
+
.string()
|
|
42
|
+
.min(1)
|
|
43
|
+
.max(4_096)
|
|
44
|
+
.refine((file) => !file.startsWith("/") &&
|
|
45
|
+
!/^[A-Za-z]:/u.test(file) &&
|
|
46
|
+
!file.includes("\\") &&
|
|
47
|
+
!file.includes("\0") &&
|
|
48
|
+
file
|
|
49
|
+
.split("/")
|
|
50
|
+
.every((part) => part !== "" && part !== "." && part !== ".."), "Skill file must remain a relative path inside its skill directory");
|
|
51
|
+
/** A discovery diagnostic; `cause` defaults to the message itself. */
|
|
52
|
+
export function skillDiagnostic(path, reason, message, cause = new Error(message)) {
|
|
53
|
+
return { path, reason, message, cause };
|
|
54
|
+
}
|
|
55
|
+
/** The message a refusal carries, else the fallback that hides any other cause. */
|
|
56
|
+
export function skillExplanation(cause, fallback) {
|
|
57
|
+
return cause instanceof SkillSourceError ? cause.message : fallback;
|
|
58
|
+
}
|
|
59
|
+
/** Where a skill's origin is named in a collision message. */
|
|
60
|
+
export function describeSkillOrigin(origin) {
|
|
61
|
+
return origin.kind === "extension"
|
|
62
|
+
? `extension ${origin.extensionId}`
|
|
63
|
+
: origin.kind;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Split a SKILL.md into its YAML frontmatter and body, or refuse it plainly:
|
|
67
|
+
* no frontmatter, invalid YAML, wrong field types or no description.
|
|
68
|
+
* `directoryName` names the skill when its frontmatter does not.
|
|
69
|
+
*/
|
|
70
|
+
export function parseSkill(content, directoryName) {
|
|
71
|
+
const normalized = content.replace(/\r\n?/gu, "\n");
|
|
72
|
+
const match = /^---\n([\s\S]*?)\n---(?:\n|$)/u.exec(normalized);
|
|
73
|
+
if (!match)
|
|
74
|
+
throw new SkillSourceError("SKILL.md requires YAML frontmatter");
|
|
75
|
+
let frontmatter;
|
|
76
|
+
try {
|
|
77
|
+
frontmatter = parseYaml(match[1] ?? "");
|
|
78
|
+
}
|
|
79
|
+
catch (cause) {
|
|
80
|
+
throw new SkillSourceError("Skill frontmatter is not valid YAML", {
|
|
81
|
+
cause,
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
const result = frontmatterSchema.safeParse(frontmatter);
|
|
85
|
+
if (!result.success)
|
|
86
|
+
throw new SkillSourceError("Skill frontmatter has invalid field types", {
|
|
87
|
+
cause: result.error,
|
|
88
|
+
});
|
|
89
|
+
const metadata = result.data;
|
|
90
|
+
if (metadata.description === undefined || metadata.description.trim() === "")
|
|
91
|
+
throw new SkillSourceError("description is required");
|
|
92
|
+
const name = metadata.name === "" ? directoryName : (metadata.name ?? directoryName);
|
|
93
|
+
return {
|
|
94
|
+
metadata: { ...metadata, name, description: metadata.description },
|
|
95
|
+
body: normalized.slice(match[0].length),
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
/** A fresh, empty admission state. */
|
|
99
|
+
export function newSkillAdmission(diagnostics = []) {
|
|
100
|
+
return { skills: [], owners: new Map(), diagnostics };
|
|
101
|
+
}
|
|
102
|
+
/** The finished catalog of an admission state. */
|
|
103
|
+
export function skillCatalogOf(state) {
|
|
104
|
+
return { skills: state.skills, diagnostics: state.diagnostics };
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Admit one parsed skill to the catalog, or say why not: a name that does not
|
|
108
|
+
* match its folder or the naming rule and an overlong description are
|
|
109
|
+
* warnings; a name already taken loses; a skill that disables model
|
|
110
|
+
* invocation is skipped; the catalog's 64-skill and 16 KB bounds hold.
|
|
111
|
+
*/
|
|
112
|
+
export function admitSkill(state, found) {
|
|
113
|
+
const { metadata, directoryName, skillPath, origin } = found;
|
|
114
|
+
const { diagnostics } = state;
|
|
115
|
+
if (!skillNameSchema.safeParse(metadata.name).success ||
|
|
116
|
+
metadata.name !== directoryName)
|
|
117
|
+
diagnostics.push(skillDiagnostic(skillPath, "warning", "Skill name should match its directory, use lowercase letters, digits and single hyphens, and be at most 64 characters"));
|
|
118
|
+
if (metadata.description.length > 1_024)
|
|
119
|
+
diagnostics.push(skillDiagnostic(skillPath, "warning", "Skill description exceeds the recommended 1024 characters"));
|
|
120
|
+
const winner = state.owners.get(metadata.name);
|
|
121
|
+
if (winner !== undefined) {
|
|
122
|
+
diagnostics.push(skillDiagnostic(skillPath, "collision", `${describeSkillOrigin(winner)} skill ${metadata.name} wins over ${describeSkillOrigin(origin)}`));
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
state.owners.set(metadata.name, origin);
|
|
126
|
+
if (metadata["disable-model-invocation"]) {
|
|
127
|
+
diagnostics.push(skillDiagnostic(skillPath, "skipped", "Skill disables model invocation"));
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
const skill = {
|
|
131
|
+
name: metadata.name,
|
|
132
|
+
description: metadata.description,
|
|
133
|
+
location: found.location,
|
|
134
|
+
displayLocation: found.displayLocation,
|
|
135
|
+
origin,
|
|
136
|
+
};
|
|
137
|
+
if (state.skills.length >= maximumSkillCount ||
|
|
138
|
+
utf8.encode(JSON.stringify([...state.skills, skill])).byteLength >
|
|
139
|
+
maximumCatalogBytes) {
|
|
140
|
+
diagnostics.push(skillDiagnostic(skillPath, "bound", "Skill catalog exceeds its 64-skill or 16 KB bound"));
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
state.skills.push(skill);
|
|
144
|
+
}
|
package/dist/skills/host.d.ts
CHANGED
|
@@ -3,6 +3,14 @@ import type { SkillSource } from "./source.js";
|
|
|
3
3
|
/** Host admission for skill discovery prompts, load tools and human controls. */
|
|
4
4
|
export declare const skillsGrant: ExtensionGrantV0;
|
|
5
5
|
/** Skills use only the generic prompt and run-tools doors; the host owns files. */
|
|
6
|
-
export declare function skillsExtension({ source, }: Readonly<{
|
|
6
|
+
export declare function skillsExtension({ source, empty, scanOnStart, }: Readonly<{
|
|
7
7
|
source: SkillSource;
|
|
8
|
+
/** What to say when no skills are installed, where the host keeps them. */
|
|
9
|
+
empty?: string | undefined;
|
|
10
|
+
/**
|
|
11
|
+
* Scan when the run activates. A host whose source acquires a Computer
|
|
12
|
+
* leaves this off so addressing a Session acquires nothing; the first
|
|
13
|
+
* model request then takes the scan.
|
|
14
|
+
*/
|
|
15
|
+
scanOnStart?: boolean | undefined;
|
|
8
16
|
}>): RosteredExtensionV0;
|
package/dist/skills/host.js
CHANGED
|
@@ -164,7 +164,7 @@ function reportDiagnostics(catalog) {
|
|
|
164
164
|
})), { discard: true });
|
|
165
165
|
}
|
|
166
166
|
/** Skills use only the generic prompt and run-tools doors; the host owns files. */
|
|
167
|
-
export function skillsExtension({ source, }) {
|
|
167
|
+
export function skillsExtension({ source, empty, scanOnStart = true, }) {
|
|
168
168
|
// Commands run inside a synchronous core transaction, so /skills shows the
|
|
169
169
|
// latest discovery: taken at activation and again before each model request.
|
|
170
170
|
let latest;
|
|
@@ -172,7 +172,7 @@ export function skillsExtension({ source, }) {
|
|
|
172
172
|
latest = found;
|
|
173
173
|
})));
|
|
174
174
|
return defineExtension({ id, version: "1.1.0" })
|
|
175
|
-
.config(config)
|
|
175
|
+
.config(empty === undefined ? config : { ...config, empty })
|
|
176
176
|
.define({
|
|
177
177
|
catalog: commandCatalog([
|
|
178
178
|
{
|
|
@@ -199,11 +199,13 @@ export function skillsExtension({ source, }) {
|
|
|
199
199
|
}),
|
|
200
200
|
},
|
|
201
201
|
hooks: {
|
|
202
|
-
start: () =>
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
202
|
+
start: () => scanOnStart
|
|
203
|
+
? Effect.tryPromise((signal) => source.catalog(signal)).pipe(Effect.tap((found) => Effect.sync(() => {
|
|
204
|
+
latest = found;
|
|
205
|
+
})),
|
|
206
|
+
// A failed first scan leaves /skills waiting for the next run's scan.
|
|
207
|
+
Effect.ignore)
|
|
208
|
+
: Effect.void,
|
|
207
209
|
},
|
|
208
210
|
prompt: () => Effect.gen(function* () {
|
|
209
211
|
const catalog = yield* discover;
|
|
@@ -103,7 +103,10 @@ child.
|
|
|
103
103
|
### oysterAgentExtensions()
|
|
104
104
|
|
|
105
105
|
```ts
|
|
106
|
-
function oysterAgentExtensions(
|
|
106
|
+
function oysterAgentExtensions(
|
|
107
|
+
source,
|
|
108
|
+
skills?,
|
|
109
|
+
): Readonly<{
|
|
107
110
|
roster: readonly RosteredExtensionV0[];
|
|
108
111
|
grants: readonly Readonly<{
|
|
109
112
|
id: string & Brand<"ExtensionId">;
|
|
@@ -113,13 +116,15 @@ function oysterAgentExtensions(source): Readonly<{
|
|
|
113
116
|
}>;
|
|
114
117
|
```
|
|
115
118
|
|
|
116
|
-
Both hosts compose the ordinary roster and its read-only created-Agent footer.
|
|
119
|
+
Both hosts compose the ordinary roster and its read-only created-Agent footer. A
|
|
120
|
+
host that can read skills where its Agent works adds them.
|
|
117
121
|
|
|
118
122
|
#### Parameters
|
|
119
123
|
|
|
120
|
-
| Parameter | Type
|
|
121
|
-
| --------- |
|
|
122
|
-
| `source` | [`SubagentSource`](../subagents/host.md#subagentsource)
|
|
124
|
+
| Parameter | Type |
|
|
125
|
+
| --------- | -------------------------------------------------------------------------------------------------- |
|
|
126
|
+
| `source` | [`SubagentSource`](../subagents/host.md#subagentsource) |
|
|
127
|
+
| `skills?` | `Readonly`\<\{ `source`: [`SkillSource`](../skills/source.md#skillsource); `empty`: `string`; \}\> |
|
|
123
128
|
|
|
124
129
|
#### Returns
|
|
125
130
|
|
package/docs/api/roster.md
CHANGED
|
@@ -43,6 +43,32 @@ Compose the goal and footer over one source; an absent goal is a wiring error.
|
|
|
43
43
|
|
|
44
44
|
---
|
|
45
45
|
|
|
46
|
+
### botanicalExtensionsWithSkillSource()
|
|
47
|
+
|
|
48
|
+
```ts
|
|
49
|
+
function botanicalExtensionsWithSkillSource(
|
|
50
|
+
base,
|
|
51
|
+
source,
|
|
52
|
+
options?,
|
|
53
|
+
): ExtensionRosterV0;
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Add read-only skill discovery over `source` to any roster.
|
|
57
|
+
|
|
58
|
+
#### Parameters
|
|
59
|
+
|
|
60
|
+
| Parameter | Type |
|
|
61
|
+
| --------- | ------------------------------------------------------------------ |
|
|
62
|
+
| `base` | `ExtensionRosterV0` |
|
|
63
|
+
| `source` | [`SkillSource`](skills/source.md#skillsource) |
|
|
64
|
+
| `options` | `Readonly`\<\{ `empty?`: `string`; `scanOnStart?`: `boolean`; \}\> |
|
|
65
|
+
|
|
66
|
+
#### Returns
|
|
67
|
+
|
|
68
|
+
`ExtensionRosterV0`
|
|
69
|
+
|
|
70
|
+
---
|
|
71
|
+
|
|
46
72
|
### botanicalExtensionsWithSkills()
|
|
47
73
|
|
|
48
74
|
```ts
|
package/docs/api/skills/host.md
CHANGED
|
@@ -30,9 +30,9 @@ Skills use only the generic prompt and run-tools doors; the host owns files.
|
|
|
30
30
|
|
|
31
31
|
#### Parameters
|
|
32
32
|
|
|
33
|
-
| Parameter | Type
|
|
34
|
-
| ------------------- |
|
|
35
|
-
| `__namedParameters` | `Readonly`\<\{ `source`: [`SkillSource`](source.md#skillsource); \}\> |
|
|
33
|
+
| Parameter | Type |
|
|
34
|
+
| ------------------- | -------------------------------------------------------------------------------------------------------------------- |
|
|
35
|
+
| `__namedParameters` | `Readonly`\<\{ `source`: [`SkillSource`](source.md#skillsource); `empty?`: `string`; `scanOnStart?`: `boolean`; \}\> |
|
|
36
36
|
|
|
37
37
|
#### Returns
|
|
38
38
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fungi.computer/shiitake-extensions",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"author": "Levi <levi@technomancy.dev>",
|
|
5
5
|
"private": false,
|
|
6
6
|
"description": "Botanical's product Shiitake extensions: goal, loop and Almanac on the generic extension surface",
|
|
@@ -66,6 +66,10 @@
|
|
|
66
66
|
"types": "./dist/plan/host.d.ts",
|
|
67
67
|
"import": "./dist/plan/host.js"
|
|
68
68
|
},
|
|
69
|
+
"./skills/discovery": {
|
|
70
|
+
"types": "./dist/skills/discovery.d.ts",
|
|
71
|
+
"import": "./dist/skills/discovery.js"
|
|
72
|
+
},
|
|
69
73
|
"./skills/source": {
|
|
70
74
|
"types": "./dist/skills/source.d.ts",
|
|
71
75
|
"import": "./dist/skills/source.js"
|
|
@@ -116,12 +120,13 @@
|
|
|
116
120
|
"dependencies": {
|
|
117
121
|
"@fungi.computer/almanac": "0.2.1",
|
|
118
122
|
"@fungi.computer/cairn": "0.1.0",
|
|
119
|
-
"@fungi.computer/knapsack": "0.4.
|
|
120
|
-
"@fungi.computer/mycelium": "0.3.
|
|
121
|
-
"@fungi.computer/shiitake": "0.
|
|
123
|
+
"@fungi.computer/knapsack": "0.4.11",
|
|
124
|
+
"@fungi.computer/mycelium": "0.3.10",
|
|
125
|
+
"@fungi.computer/shiitake": "0.15.0",
|
|
122
126
|
"@fungi.computer/watchdog": "0.1.3",
|
|
123
127
|
"@fungi.computer/whistle": "0.3.0",
|
|
124
128
|
"effect": "4.0.2",
|
|
129
|
+
"yaml": "2.9.0",
|
|
125
130
|
"zod": "4.4.3",
|
|
126
131
|
"@fungi.computer/gills": "0.3.0"
|
|
127
132
|
},
|