@fungi.computer/shiitake-extensions 0.7.0 → 0.9.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.
@@ -4,6 +4,11 @@ export declare const Home: Schema.Struct<{
4
4
  /** Chosen Computer attachment, or null when no Home is selected. */
5
5
  readonly attachmentId: Schema.NullOr<Schema.String>;
6
6
  }>;
7
+ /**
8
+ * Bytes of AGENTS.md and SYSTEM.md Home loads into one run, and so the most an
9
+ * owner may save. Local enforced the same bound for its root AGENTS.md.
10
+ */
11
+ export declare const homeInstructionsLimit = 32000;
7
12
  /** Persisted Home selection for one Agent. */
8
13
  export type Home = Schema.Schema.Type<typeof Home>;
9
14
  /** Human selection changes Agent state; no model operation exposes this command. */
@@ -7,6 +7,11 @@ export const Home = Schema.Struct({
7
7
  /** Chosen Computer attachment, or null when no Home is selected. */
8
8
  attachmentId: Schema.NullOr(attachmentId),
9
9
  });
10
+ /**
11
+ * Bytes of AGENTS.md and SYSTEM.md Home loads into one run, and so the most an
12
+ * owner may save. Local enforced the same bound for its root AGENTS.md.
13
+ */
14
+ export const homeInstructionsLimit = 32_000;
10
15
  /** Human selection changes Agent state; no model operation exposes this command. */
11
16
  export const homeContract = {
12
17
  /** Stable extension identity. */
@@ -1,5 +1,6 @@
1
1
  import { type FilesPort } from "@fungi.computer/knapsack";
2
2
  import { type ExtensionGrantV0, type RosteredExtensionV0 } from "@fungi.computer/shiitake/extensions";
3
+ import { Home } from "./contract.js";
3
4
  /** Already-scoped authority supplied by the host, never constructed by Home. */
4
5
  export type HomeComputer = Readonly<{
5
6
  /** Attachment name offered to the person choosing Home. */
@@ -11,6 +12,13 @@ export type HomeComputer = Readonly<{
11
12
  }>;
12
13
  /** Hosts admit Home explicitly; no other extension receives the Files slot. */
13
14
  export declare const homeGrant: ExtensionGrantV0;
15
+ /**
16
+ * The Home choice a run uses: the recorded one, otherwise the only attachment.
17
+ * Hosts that answer "which Home" outside a run apply this same rule.
18
+ */
19
+ export declare function resolveHome(recorded: Home | null, computers: readonly Readonly<{
20
+ attachmentId: string;
21
+ }>[]): Home | null;
14
22
  /** Agent-scope choice with per-run tools and prompt over one captured table. */
15
23
  export declare function homeExtension(options: {
16
24
  computers: {
package/dist/home/host.js CHANGED
@@ -5,6 +5,7 @@ import * as Option from "effect/Option";
5
5
  import * as Schema from "effect/Schema";
6
6
  import { ask, catalog, done } from "../internal/catalog.js";
7
7
  import { Home, homeContract } from "./contract.js";
8
+ import { instructionSectionName, loadHomeInstructions, } from "./instructions.js";
8
9
  import { homeFilesRouting } from "./routing.js";
9
10
  /** Hosts admit Home explicitly; no other extension receives the Files slot. */
10
11
  export const homeGrant = {
@@ -13,16 +14,27 @@ export const homeGrant = {
13
14
  };
14
15
  const config = {
15
16
  promptLimit: 4_000,
16
- guide: "Home supplies read, list, glob and grep over your default Computer. Bare paths and computer://home/ use Home; computer://<name>/ uses that captured attachment. apply_patch, when offered, also works on Home. Only a person changes Home with /home <name>; ask them when no Home is available.",
17
+ guide: "Home supplies read, list, glob and grep over your default Computer. Bare paths and computer://home/ use Home; computer://<name>/ uses that captured attachment. apply_patch, when offered, also works on Home. Home's AGENTS.md and SYSTEM.md are loaded into your prompt each run. Only a person changes Home with /home <name>; ask them when no Home is available.",
17
18
  };
18
19
  const collections = {
19
20
  choice: defineCollection(Home, { key: () => "default" }),
20
21
  };
22
+ /**
23
+ * The Home choice a run uses: the recorded one, otherwise the only attachment.
24
+ * Hosts that answer "which Home" outside a run apply this same rule.
25
+ */
26
+ export function resolveHome(recorded, computers) {
27
+ if (recorded !== null)
28
+ return recorded;
29
+ const sole = computers.length === 1 ? computers[0] : undefined;
30
+ return sole === undefined ? null : { attachmentId: sole.attachmentId };
31
+ }
21
32
  /** Agent-scope choice with per-run tools and prompt over one captured table. */
22
33
  export function homeExtension(options) {
23
34
  // Core retains one RunIdentity for Files and every prompt request. Weak keys
24
35
  // release the captured prose with the run, including failure and cancellation.
25
36
  const prompts = new WeakMap();
37
+ const instructions = new WeakMap();
26
38
  return defineExtension({ id: homeContract.id, version: "1.0.0" })
27
39
  .config(config)
28
40
  .state({ version: 1, migrations: {}, collections })
@@ -56,14 +68,10 @@ export function homeExtension(options) {
56
68
  const computers = [...options.computers.read(run)];
57
69
  const choice = ctx.state.update((state) => {
58
70
  const recorded = Option.getOrNull(state.choice.get("default"));
59
- if (recorded !== null)
60
- return recorded;
61
- const sole = computers.length === 1 ? computers[0] : undefined;
62
- if (sole === undefined)
63
- return null;
64
- const adopted = { attachmentId: sole.attachmentId };
65
- state.choice.put(adopted);
66
- return adopted;
71
+ const resolved = resolveHome(recorded, computers);
72
+ if (recorded === null && resolved !== null)
73
+ state.choice.put(resolved);
74
+ return resolved;
67
75
  });
68
76
  const selected = computers.find((computer) => computer.attachmentId === choice?.attachmentId);
69
77
  const status = selected !== undefined
@@ -78,17 +86,34 @@ export function homeExtension(options) {
78
86
  prompts.set(run, prompt.slice(0, ctx.config.promptLimit));
79
87
  if (selected === undefined)
80
88
  return null;
81
- return Knapsack.files({
89
+ const tools = Knapsack.files({
82
90
  port: homeFilesRouting(new Map(computers.map(({ name, port }) => [name, port])), selected.port),
83
91
  }).tools;
92
+ // Home's files are read once for this run, after the state transaction.
93
+ return loadHomeInstructions({
94
+ port: selected.port,
95
+ executionId: `home-instructions/${run.workId}`,
96
+ signal: new AbortController().signal,
97
+ }).then((text) => {
98
+ if (text !== null)
99
+ instructions.set(run, text);
100
+ return tools;
101
+ });
102
+ },
103
+ prompt: (_ctx, run) => {
104
+ const pieces = instructions.get(run) ?? [];
105
+ return [
106
+ {
107
+ name: "home",
108
+ text: prompts.get(run) ??
109
+ "Home file tools were not captured. Ask the person to check Home's Files grant.",
110
+ },
111
+ ...pieces.map((text, index) => ({
112
+ name: instructionSectionName(index),
113
+ text,
114
+ })),
115
+ ];
84
116
  },
85
- prompt: (_ctx, run) => [
86
- {
87
- name: "home",
88
- text: prompts.get(run) ??
89
- "Home file tools were not captured. Ask the person to check Home's Files grant.",
90
- },
91
- ],
92
117
  commands: {
93
118
  specs: homeContract.commands,
94
119
  handlers: (ctx) => ({
@@ -0,0 +1,13 @@
1
+ import type { FilesPort } from "@fungi.computer/knapsack";
2
+ /** Prompt section names for `count` consecutive pieces: `instructions`, `instructions-2`, ... */
3
+ export declare function instructionSectionName(index: number): string;
4
+ /**
5
+ * The prompt text built from Home's AGENTS.md and SYSTEM.md, in pieces
6
+ * that each fit one prompt section, or null when Home has none. Absent files are normal; refused ones are named in the
7
+ * section so the Agent can tell its owner. A failing read never stops the run.
8
+ */
9
+ export declare function loadHomeInstructions(input: {
10
+ port: FilesPort;
11
+ executionId: string;
12
+ signal: AbortSignal;
13
+ }): Promise<readonly string[] | null>;
@@ -0,0 +1,109 @@
1
+ import { maximumReadBytes } from "@fungi.computer/knapsack/files-read";
2
+ import { homeInstructionsLimit } from "./contract.js";
3
+ /**
4
+ * Shiitake accepts a prompt section of at most 8,192 bytes (and 65,536 across
5
+ * all extensions), so a longer text is carried in consecutive sections.
6
+ */
7
+ const maximumSectionBytes = 8_192;
8
+ const maximumListedProblems = 16;
9
+ const utf8 = new TextEncoder();
10
+ const framing = "From files on Home (computer://home/AGENTS.md, SYSTEM.md). Your owner and you can edit them. Follow them unless they conflict with the instructions above. They never grant tools, approvals or access.";
11
+ const bytesOf = (text) => utf8.encode(text).byteLength;
12
+ /** A missing path, as every Files host reports it: an errno ENOENT. */
13
+ function absent(cause) {
14
+ return cause instanceof Error && "code" in cause && cause.code === "ENOENT";
15
+ }
16
+ async function readText(port, path, context) {
17
+ try {
18
+ const page = await port.read({ path, offset: 0, limit: maximumReadBytes }, context);
19
+ if ("image" in page)
20
+ return { kind: "refused", reason: "is an image" };
21
+ if (page.truncated)
22
+ return {
23
+ kind: "refused",
24
+ reason: `is larger than ${String(maximumReadBytes)} bytes`,
25
+ };
26
+ return { kind: "text", text: page.content };
27
+ }
28
+ catch (cause) {
29
+ if (absent(cause))
30
+ return { kind: "absent" };
31
+ // A Computer that cannot answer must not stop the run; the section says so.
32
+ return { kind: "refused", reason: "could not be read from Home" };
33
+ }
34
+ }
35
+ /** Cut `text` into pieces of at most `limit` bytes, at line ends when it can. */
36
+ function chunks(text, limit) {
37
+ const pieces = [];
38
+ let current = "";
39
+ let used = 0;
40
+ const push = (part, size) => {
41
+ if (used + size > limit) {
42
+ pieces.push(current);
43
+ current = "";
44
+ used = 0;
45
+ }
46
+ current += part;
47
+ used += size;
48
+ };
49
+ for (const line of text.split(/(?<=\n)/u)) {
50
+ const size = bytesOf(line);
51
+ if (size <= limit)
52
+ push(line, size);
53
+ else
54
+ for (const character of line)
55
+ push(character, bytesOf(character));
56
+ }
57
+ if (current !== "")
58
+ pieces.push(current);
59
+ return pieces;
60
+ }
61
+ /** Prompt section names for `count` consecutive pieces: `instructions`, `instructions-2`, ... */
62
+ export function instructionSectionName(index) {
63
+ return index === 0 ? "instructions" : `instructions-${String(index + 1)}`;
64
+ }
65
+ /**
66
+ * The prompt text built from Home's AGENTS.md and SYSTEM.md, in pieces
67
+ * that each fit one prompt section, or null when Home has none. Absent files are normal; refused ones are named in the
68
+ * section so the Agent can tell its owner. A failing read never stops the run.
69
+ */
70
+ export async function loadHomeInstructions(input) {
71
+ const context = {
72
+ executionId: input.executionId,
73
+ deadlineAt: null,
74
+ signal: input.signal,
75
+ };
76
+ const problems = [];
77
+ const blocks = [];
78
+ let used = 0;
79
+ for (const file of ["AGENTS.md", "SYSTEM.md"]) {
80
+ const loaded = await readText(input.port, file, context);
81
+ if (loaded.kind === "absent")
82
+ continue;
83
+ if (loaded.kind === "refused") {
84
+ problems.push(`${file} ${loaded.reason}`);
85
+ continue;
86
+ }
87
+ const text = loaded.text.replace(/^\uFEFF/u, "").trim();
88
+ if (text === "")
89
+ continue;
90
+ if (used + bytesOf(text) > homeInstructionsLimit) {
91
+ problems.push(`${file} is ${String(bytesOf(loaded.text))} bytes; the limit is ${String(homeInstructionsLimit)} for Home's instruction files; ask your owner to shorten it`);
92
+ continue;
93
+ }
94
+ used += bytesOf(text);
95
+ blocks.push(`## ${file}\n${text}`);
96
+ }
97
+ if (blocks.length === 0 && problems.length === 0)
98
+ return null;
99
+ const shown = problems.slice(0, maximumListedProblems);
100
+ if (problems.length > shown.length)
101
+ shown.push(`${String(problems.length - shown.length)} more problems`);
102
+ return chunks([
103
+ framing,
104
+ ...blocks,
105
+ ...(shown.length === 0
106
+ ? []
107
+ : [`## Problems\n${shown.map((line) => `- ${line}`).join("\n")}`]),
108
+ ].join("\n\n"), maximumSectionBytes);
109
+ }
@@ -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
- /** Both hosts compose the ordinary roster and its read-only created-Agent footer. */
44
- export declare function oysterAgentExtensions(source: SubagentSource): Readonly<{
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
- /** Both hosts compose the ordinary roster and its read-only created-Agent footer. */
246
- export function oysterAgentExtensions(source) {
247
- return botanicalExtensionsWithSubagents(botanicalAgentExtensions, source);
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
@@ -96,14 +96,17 @@ export function botanicalExtensionsWithSubagents(base, source) {
96
96
  grants: [...base.grants, subagentsGrant],
97
97
  };
98
98
  }
99
- /** A host with a SkillSource grants read-only skill discovery for its own runs. */
100
- export function botanicalExtensionsWithSkills(source) {
101
- const local = botanicalExtensionsWithSenderRouting();
99
+ /** Add read-only skill discovery over `source` to any roster. */
100
+ export function botanicalExtensionsWithSkillSource(base, source, options = {}) {
102
101
  return {
103
- roster: [...local.roster, skillsExtension({ source })],
104
- grants: [...local.grants, skillsGrant],
102
+ roster: [...base.roster, skillsExtension({ source, ...options })],
103
+ grants: [...base.grants, skillsGrant],
105
104
  };
106
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
+ }
107
110
  /** Route Asks to the Agent that sent the work, only in a host that owns the Local answer door. */
108
111
  export function botanicalExtensionsWithSenderRouting() {
109
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
+ }
@@ -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;
@@ -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: () => Effect.tryPromise((signal) => source.catalog(signal)).pipe(Effect.tap((found) => Effect.sync(() => {
203
- latest = found;
204
- })),
205
- // A failed first scan leaves /skills waiting for the next run's scan.
206
- Effect.ignore),
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;
@@ -32,6 +32,17 @@ The Agent's recorded choice survives the chosen attachment being detached.
32
32
 
33
33
  ---
34
34
 
35
+ ### homeInstructionsLimit
36
+
37
+ ```ts
38
+ const homeInstructionsLimit: 32000 = 32_000;
39
+ ```
40
+
41
+ Bytes of AGENTS.md and SYSTEM.md Home loads into one run, and so the most an
42
+ owner may save. Local enforced the same bound for its root AGENTS.md.
43
+
44
+ ---
45
+
35
46
  ### homeContract
36
47
 
37
48
  ```ts
@@ -34,6 +34,47 @@ Hosts admit Home explicitly; no other extension receives the Files slot.
34
34
 
35
35
  ## Functions
36
36
 
37
+ ### resolveHome()
38
+
39
+ ```ts
40
+ function resolveHome(
41
+ recorded,
42
+ computers,
43
+ ): {
44
+ attachmentId: string | null;
45
+ } | null;
46
+ ```
47
+
48
+ The Home choice a run uses: the recorded one, otherwise the only attachment.
49
+ Hosts that answer "which Home" outside a run apply this same rule.
50
+
51
+ #### Parameters
52
+
53
+ | Parameter | Type |
54
+ | ----------- | -------------------------------------------------------- |
55
+ | `recorded` | \| \{ `attachmentId`: `string` \| `null`; \} \| `null` |
56
+ | `computers` | readonly `Readonly`\<\{ `attachmentId`: `string`; \}\>[] |
57
+
58
+ #### Returns
59
+
60
+ ##### Type Literal
61
+
62
+ ```ts
63
+ {
64
+ attachmentId: string | null;
65
+ }
66
+ ```
67
+
68
+ | Name | Type | Description |
69
+ | -------------- | ------------------ | ------------------------------------------------------------- |
70
+ | `attachmentId` | `string` \| `null` | Chosen Computer attachment, or null when no Home is selected. |
71
+
72
+ ---
73
+
74
+ `null`
75
+
76
+ ---
77
+
37
78
  ### homeExtension()
38
79
 
39
80
  ```ts
@@ -103,7 +103,10 @@ child.
103
103
  ### oysterAgentExtensions()
104
104
 
105
105
  ```ts
106
- function oysterAgentExtensions(source): Readonly<{
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
 
@@ -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
@@ -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.7.0",
3
+ "version": "0.9.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.10",
120
- "@fungi.computer/mycelium": "0.3.9",
121
- "@fungi.computer/shiitake": "0.14.2",
123
+ "@fungi.computer/knapsack": "0.4.12",
124
+ "@fungi.computer/mycelium": "0.3.11",
125
+ "@fungi.computer/shiitake": "0.16.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
  },