knapsack
Import
Section titled “Import”import * as api from "@fungi.computer/knapsack";Exports
Section titled “Exports”| Kind | Export | Description |
|---|---|---|
| class | FilesEditError | Expected Files edit refusal, kept distinct from unexpected host failures. |
| class | ComputerUnavailableError | One Computer whose advertisement could not be acquired. |
| class | McpServerUnavailableError | One MCP server whose tools could not be acquired. |
| type alias | FilesEditErrorReason | Typed refusal from a bounded or conditional Files edit. |
| type alias | FilesPatch | Host-owned native patch operation receiving the invocation’s deadline and signal. |
| type alias | FilesPort | Captured host file authority; the host owns path confinement and atomic replacement. |
| type alias | FileToolName | Closed set of direct, model-visible Files tools; changing it is an ADR. |
| type alias | FileTool | A MuleTool minted only by this module, named from the closed FileToolName
set. No host can construct one: the brand has no public constructor, so a
host-made MuleTool fails typecheck against files?. |
| type alias | FilesSurface | One Mycelium module and the direct Files tools built from the same port. |
| type alias | FilesConnectionOptions | Host inputs for a captured Files connection. |
| type alias | KnapsackComputer | Generic advertised-call interface supplied by one Computer provider. |
| type alias | ComputerConnectionOptions | Selection and naming required to connect one Computer to Mycelium. |
| type alias | ComputerUnavailableReason | Why one Computer contributed no module to an acquisition. |
| type alias | ComputersConnectionOptions | A captured host connection list; authority remains with its supplying host. |
| type alias | McpServerConnection | One remote MCP server a host has admitted for an Agent. |
| type alias | McpServersConnectionOptions | A captured host list of remote MCP servers; authority stays with the host. |
| type alias | McpServerUnavailableReason | Why one MCP server contributed no module to an acquisition. |
| type alias | UiConnectionOptions | How one Agent host connects its Sessions’ open Apps to Knapsack.ui. |
| type alias | UiConnection | Live commands of the App open in each Agent Session’s browser. The Agent reaches
them through the ui module (ui.discover, ui.execute); the browser runs
them through Whistle over the transport this connection serves. |
| constant | listInputSchema | List one directory level. |
| constant | globInputSchema | Match paths below a directory by glob. |
| constant | grepInputSchema | Search file content, optionally restricted to matching paths. |
| constant | searchOutputSchema | Found paths or matching lines, and which cap (if any) cut the search short. |
| constant | editInputSchema | Text replacement request decoded before the captured Files port is called. |
| constant | filesEditFailureSchema | Structured edit refusal, including its reason and affected path. |
| constant | editOutputSchema | Successful edit metadata or a typed edit refusal. |
| constant | Knapsack | Agent tool connections available for composition through Mycelium. |
| function | edit() | Apply the same edit behavior as the Files edit operation directly through a captured FilesPort. |
| function | presentReadForGuest() | Guest code and MCP callers never receive base64: the image goes through the
execution’s image collector (the images.view path) and the value is a caption. |
FilesEditErrorclass
Section titled “FilesEditError”Expected Files edit refusal, kept distinct from unexpected host failures.
Extends
Section titled “Extends”Error
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new FilesEditError( reason, path, detail): FilesEditError;Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
reason |
FilesEditErrorReason |
path |
string |
detail |
string |
Returns
Section titled “Returns”Overrides
Section titled “Overrides”Error.constructor;Properties
Section titled “Properties”reason
Section titled “reason”readonly reason: FilesEditErrorReason;readonly path: string;ComputerUnavailableErrorclass
Section titled “ComputerUnavailableError”One Computer whose advertisement could not be acquired.
Extends
Section titled “Extends”Error
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new ComputerUnavailableError( computerId, reason, cause?): ComputerUnavailableError;Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
computerId |
string |
reason |
ComputerUnavailableReason |
cause? |
unknown |
Returns
Section titled “Returns”Overrides
Section titled “Overrides”Error.constructor;Properties
Section titled “Properties”readonly name: "ComputerUnavailableError" = "ComputerUnavailableError";Overrides
Section titled “Overrides”Error.name;computerId
Section titled “computerId”readonly computerId: string;reason
Section titled “reason”readonly reason: ComputerUnavailableReason;McpServerUnavailableErrorclass
Section titled “McpServerUnavailableError”One MCP server whose tools could not be acquired.
Extends
Section titled “Extends”Error
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new McpServerUnavailableError( serverId, reason, cause?): McpServerUnavailableError;Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
serverId |
string |
reason |
McpServerUnavailableReason |
cause? |
unknown |
Returns
Section titled “Returns”Overrides
Section titled “Overrides”Error.constructor;Properties
Section titled “Properties”readonly name: "McpServerUnavailableError" = "McpServerUnavailableError";Overrides
Section titled “Overrides”Error.name;serverId
Section titled “serverId”readonly serverId: string;reason
Section titled “reason”readonly reason: McpServerUnavailableReason;FilesEditErrorReasontype alias
Section titled “FilesEditErrorReason”type FilesEditErrorReason = | "not-found" | "ambiguous" | "file-too-large" | "partial-character" | "unchanged" | "not-text" | "conflict";Typed refusal from a bounded or conditional Files edit.
FilesPatchtype alias
Section titled “FilesPatch”type FilesPatch = ( input, context,) => Promise<z.output<typeof patchOutputSchema>>;Host-owned native patch operation receiving the invocation’s deadline and signal.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
input |
z.output<typeof patchInputSchema> |
context |
InvocationContext |
Returns
Section titled “Returns”Promise<z.output<typeof
patchOutputSchema>>
FilesPorttype alias
Section titled “FilesPort”type FilesPort = Readonly<{ patch?: FilesPatch; read: (input, context) => Promise<z.output<typeof readOutputSchema>>; list: (input, context) => Promise<z.output<typeof searchOutputSchema>>; glob: (input, context) => Promise<z.output<typeof searchOutputSchema>>; grep: (input, context) => Promise<z.output<typeof searchOutputSchema>>; replace: ( input, context, ) => Promise< Readonly<{ path: string; bytes: number; }> >;}>;Captured host file authority; the host owns path confinement and atomic replacement.
FileToolNametype alias
Section titled “FileToolName”type FileToolName = "read" | "list" | "glob" | "grep" | "apply_patch";Closed set of direct, model-visible Files tools; changing it is an ADR.
FileTooltype alias
Section titled “FileTool”type FileTool = LabelledTool & Readonly<{ [fileToolBrand]: true; }> & Readonly<{ descriptor: Readonly<{ name: FileToolName; }>; module: "files"; access: Access; }>;A MuleTool minted only by this module, named from the closed FileToolName
set. No host can construct one: the brand has no public constructor, so a
host-made MuleTool fails typecheck against files?.
FilesSurfacetype alias
Section titled “FilesSurface”type FilesSurface = Readonly<{ module: ModuleRegistration; tools: readonly FileTool[];}>;One Mycelium module and the direct Files tools built from the same port.
FilesConnectionOptionstype alias
Section titled “FilesConnectionOptions”type FilesConnectionOptions = Readonly<{ port: FilesPort; pathInstructions?: string;}>;Host inputs for a captured Files connection.
KnapsackComputertype alias
Section titled “KnapsackComputer”type KnapsackComputer = Readonly<{ getCapabilities: (signal) => Promise<MyceliumJsonValue>; call: (capabilityId, input, context) => Promise<MyceliumJsonValue>;}>;Generic advertised-call interface supplied by one Computer provider.
ComputerConnectionOptionstype alias
Section titled “ComputerConnectionOptions”type ComputerConnectionOptions = Readonly<{ id: string; name: string; namespace?: readonly string[]; confirmCalls?: boolean; files?: FilesConnectionOptions; role?: string; computer: KnapsackComputer;}>;Selection and naming required to connect one Computer to Mycelium.
ComputerUnavailableReasontype alias
Section titled “ComputerUnavailableReason”type ComputerUnavailableReason = "rejected" | "timeout" | "invalid-advertisement";Why one Computer contributed no module to an acquisition.
ComputersConnectionOptionstype alias
Section titled “ComputersConnectionOptions”type ComputersConnectionOptions = Readonly<{ id: string; read: () => Readonly<{ version: string; connections: readonly ComputerConnectionOptions[]; }>; subscribe: (invalidate) => () => void; onUnavailable: (error) => void; describeTimeoutMillis?: number;}>;A captured host connection list; authority remains with its supplying host.
McpServerConnectiontype alias
Section titled “McpServerConnection”type McpServerConnection = Readonly<{ id: string; name: string; url: URL; headers?: Readonly<Record<string, string>>;}>;One remote MCP server a host has admitted for an Agent.
McpServersConnectionOptionstype alias
Section titled “McpServersConnectionOptions”type McpServersConnectionOptions = Readonly<{ id: string; read: () => Promise< Readonly<{ version: string; servers: readonly McpServerConnection[]; }> >; subscribe: (invalidate) => () => void; onUnavailable: (error) => void; fetch: (url, init?) => Promise<Response>; namespace?: readonly string[]; connectTimeoutMillis?: number;}>;A captured host list of remote MCP servers; authority stays with the host.
McpServerUnavailableReasontype alias
Section titled “McpServerUnavailableReason”type McpServerUnavailableReason = "rejected" | "unauthorized" | "timeout" | "invalid-advertisement";Why one MCP server contributed no module to an acquisition.
UiConnectionOptionstype alias
Section titled “UiConnectionOptions”type UiConnectionOptions = Readonly<{ id: string; hasSession: (sessionId) => Promise<boolean>;}>;How one Agent host connects its Sessions’ open Apps to Knapsack.ui.
UiConnectiontype alias
Section titled “UiConnection”type UiConnection = Readonly<{ source: CapabilitySource; fetch: (request) => Promise<Response>; close: () => Promise<void>;}>;Live commands of the App open in each Agent Session’s browser. The Agent reaches
them through the ui module (ui.discover, ui.execute); the browser runs
them through Whistle over the transport this connection serves.
listInputSchemaconstant
Section titled “listInputSchema”const listInputSchema: ZodLazy< ZodObject< { path: ZodDefault<ZodLazy<ZodString>>; limit: ZodDefault<ZodNumber>; }, $strict >>;List one directory level.
globInputSchemaconstant
Section titled “globInputSchema”const globInputSchema: ZodLazy< ZodObject< { path: ZodDefault<ZodLazy<ZodString>>; pattern: ZodString; limit: ZodDefault<ZodNumber>; }, $strict >>;Match paths below a directory by glob.
grepInputSchemaconstant
Section titled “grepInputSchema”const grepInputSchema: ZodLazy< ZodObject< { path: ZodDefault<ZodLazy<ZodString>>; pattern: ZodString; include: ZodOptional<ZodString>; regex: ZodDefault<ZodBoolean>; ignoreCase: ZodDefault<ZodBoolean>; limit: ZodDefault<ZodNumber>; }, $strict >>;Search file content, optionally restricted to matching paths.
searchOutputSchemaconstant
Section titled “searchOutputSchema”const searchOutputSchema: ZodLazy< ZodObject< { path: ZodLazy<ZodString>; results: ZodArray< ZodLazy< ZodObject< { path: ZodLazy<ZodString>; type: ZodExactOptional< ZodEnum<{ file: "file"; directory: "directory"; symlink: "symlink"; }> >; line: ZodExactOptional<ZodNumber>; text: ZodExactOptional<ZodString>; }, $strict > > >; truncated: ZodNullable< ZodEnum<{ limit: "limit"; scan: "scan"; }> >; }, $strict >>;Found paths or matching lines, and which cap (if any) cut the search short.
editInputSchemaconstant
Section titled “editInputSchema”const editInputSchema: ZodLazy< ZodObject< { path: ZodLazy<ZodString>; oldText: ZodString; newText: ZodString; }, $strict >>;Text replacement request decoded before the captured Files port is called.
filesEditFailureSchemaconstant
Section titled “filesEditFailureSchema”const filesEditFailureSchema: ZodLazy<ZodObject<{ status: ZodLiteral<"failed">; error: ZodObject<{ kind: ZodEnum<{ not-found: "not-found"; ambiguous: "ambiguous"; file-too-large: "file-too-large"; partial-character: "partial-character"; unchanged: "unchanged"; not-text: "not-text"; conflict: "conflict"; }>; path: ZodLazy<ZodString>; message: ZodString; }, $strict>;}, $strict>>;Structured edit refusal, including its reason and affected path.
editOutputSchemaconstant
Section titled “editOutputSchema”const editOutputSchema: ZodUnion<readonly [ZodLazy<ZodObject<{ path: ZodLazy<ZodString>; bytes: ZodNumber; diff: ZodString; firstChangedLine: ZodNullable<ZodNumber>; unifiedPatch: ZodNullable<ZodString>; unifiedPatchBytes: ZodNumber; unifiedPatchAddedLines: ZodNumber; unifiedPatchRemovedLines: ZodNumber; unifiedPatchTruncated: ZodBoolean;}, $strict>>, ZodLazy<ZodObject<{ status: ZodLiteral<"failed">; error: ZodObject<{ kind: ZodEnum<{ not-found: "not-found"; ambiguous: "ambiguous"; file-too-large: "file-too-large"; partial-character: "partial-character"; unchanged: "unchanged"; not-text: "not-text"; conflict: "conflict"; }>; path: ZodLazy<ZodString>; message: ZodString; }, $strict>;}, $strict>>]>;Successful edit metadata or a typed edit refusal.
Knapsackconstant
Section titled “Knapsack”const Knapsack: Readonly<{ computer: (input) => CapabilitySource; computers: (input) => CapabilitySource; files: (input) => FilesSurface; mcpServers: (input) => CapabilitySource; ui: (options) => UiConnection;}>;Agent tool connections available for composition through Mycelium.
edit()function
Section titled “edit()”function edit( port, input, context,): Promise< | { path: string; bytes: number; diff: string; firstChangedLine: number | null; unifiedPatch: string | null; unifiedPatchBytes: number; unifiedPatchAddedLines: number; unifiedPatchRemovedLines: number; unifiedPatchTruncated: boolean; } | { status: "failed"; error: { kind: | "not-found" | "ambiguous" | "file-too-large" | "partial-character" | "unchanged" | "not-text" | "conflict"; path: string; message: string; }; }>;Apply the same edit behavior as the Files edit operation directly through a captured FilesPort.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
port |
FilesPort |
input |
{ path: string; oldText: string; newText: string; } |
input.path |
string |
input.oldText |
string |
input.newText |
string |
context |
InvocationContext |
Returns
Section titled “Returns”Promise< | { path: string; bytes: number; diff: string;
firstChangedLine: number | null; unifiedPatch: string | null;
unifiedPatchBytes: number; unifiedPatchAddedLines: number;
unifiedPatchRemovedLines: number; unifiedPatchTruncated: boolean; } |
{ status: "failed"; error: { kind: | "not-found" | "ambiguous"
| "file-too-large" | "partial-character" | "unchanged" | "not-text"
| "conflict"; path: string; message: string; }; }>
presentReadForGuest()function
Section titled “presentReadForGuest()”function presentReadForGuest( result, context,): | { path: string; content: string; offset: number; nextOffset: number | null; truncated: boolean; file?: { computerId: string; path: string; }; } | { path: string; image: { ref: string; mimeType: "image/png" | "image/jpeg" | "image/gif" | "image/webp"; bytes: number; }; };Guest code and MCP callers never receive base64: the image goes through the
execution’s image collector (the images.view path) and the value is a caption.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
result |
| { path: string; content: string; offset: number; nextOffset: number | null; truncated: boolean; file?: { computerId: string; path: string; }; } | { path: string; image: { mimeType: "image/png" | "image/jpeg" | "image/gif" | "image/webp"; data: string; bytes: number; }; file?: { computerId: string; path: string; }; } |
context |
InvocationContext |
Returns
Section titled “Returns”Type Literal
Section titled “Type Literal”{ path: string; content: string; offset: number; nextOffset: number | null; truncated: boolean; file?: { computerId: string; path: string; };}| Name | Type | Default value | Description |
|---|---|---|---|
path |
string |
pathSchema |
- |
content |
string |
- | - |
offset |
number |
- | - |
nextOffset |
number | null |
- | - |
truncated |
boolean |
- | - |
file? |
object |
- | Captured hosted file identity; a local Files host may have no Computer identity. |
file.computerId |
string |
- | - |
file.path |
string |
- | - |
Type Literal
Section titled “Type Literal”{ path: string; image: { ref: string; mimeType: "image/png" | "image/jpeg" | "image/gif" | "image/webp"; bytes: number; }}References
Section titled “References”readInputSchema
Section titled “readInputSchema”Re-exports readInputSchema
readOutputSchema
Section titled “readOutputSchema”Re-exports readOutputSchema
readGuestOutputSchema
Section titled “readGuestOutputSchema”Re-exports readGuestOutputSchema
patchInputSchema
Section titled “patchInputSchema”Re-exports patchInputSchema
patchOutputSchema
Section titled “patchOutputSchema”Re-exports patchOutputSchema