@fungi.computer/knapsack 0.0.0-stage → 0.0.2

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.
@@ -0,0 +1,733 @@
1
+ <!-- Generated by Botanical API docs (TypeDoc + typedoc-plugin-markdown). Do not edit. -->
2
+
3
+ [**@fungi.computer/knapsack**](README.md)
4
+
5
+ ---
6
+
7
+ [@fungi.computer/knapsack](README.md) / index
8
+
9
+ # index
10
+
11
+ ## Classes
12
+
13
+ ### FilesEditError
14
+
15
+ Expected Files edit refusal, kept distinct from unexpected host failures.
16
+
17
+ #### Extends
18
+
19
+ - `Error`
20
+
21
+ #### Constructors
22
+
23
+ ##### Constructor
24
+
25
+ ```ts
26
+ new FilesEditError(
27
+ reason,
28
+ path,
29
+ detail
30
+ ): FilesEditError;
31
+ ```
32
+
33
+ ###### Parameters
34
+
35
+ | Parameter | Type |
36
+ | --------- | ----------------------------------------------- |
37
+ | `reason` | [`FilesEditErrorReason`](#filesediterrorreason) |
38
+ | `path` | `string` |
39
+ | `detail` | `string` |
40
+
41
+ ###### Returns
42
+
43
+ [`FilesEditError`](#filesediterror)
44
+
45
+ ###### Overrides
46
+
47
+ ```ts
48
+ Error.constructor;
49
+ ```
50
+
51
+ #### Properties
52
+
53
+ ##### reason
54
+
55
+ ```ts
56
+ readonly reason: FilesEditErrorReason;
57
+ ```
58
+
59
+ ##### path
60
+
61
+ ```ts
62
+ readonly path: string;
63
+ ```
64
+
65
+ ---
66
+
67
+ ### ComputerUnavailableError
68
+
69
+ One Computer whose advertisement could not be acquired.
70
+
71
+ #### Extends
72
+
73
+ - `Error`
74
+
75
+ #### Constructors
76
+
77
+ ##### Constructor
78
+
79
+ ```ts
80
+ new ComputerUnavailableError(
81
+ computerId,
82
+ reason,
83
+ cause?
84
+ ): ComputerUnavailableError;
85
+ ```
86
+
87
+ ###### Parameters
88
+
89
+ | Parameter | Type |
90
+ | ------------ | --------------------------------------------------------- |
91
+ | `computerId` | `string` |
92
+ | `reason` | [`ComputerUnavailableReason`](#computerunavailablereason) |
93
+ | `cause?` | `unknown` |
94
+
95
+ ###### Returns
96
+
97
+ [`ComputerUnavailableError`](#computerunavailableerror)
98
+
99
+ ###### Overrides
100
+
101
+ ```ts
102
+ Error.constructor;
103
+ ```
104
+
105
+ #### Properties
106
+
107
+ ##### name
108
+
109
+ ```ts
110
+ readonly name: "ComputerUnavailableError" = "ComputerUnavailableError";
111
+ ```
112
+
113
+ ###### Overrides
114
+
115
+ ```ts
116
+ Error.name;
117
+ ```
118
+
119
+ ##### computerId
120
+
121
+ ```ts
122
+ readonly computerId: string;
123
+ ```
124
+
125
+ ##### reason
126
+
127
+ ```ts
128
+ readonly reason: ComputerUnavailableReason;
129
+ ```
130
+
131
+ ---
132
+
133
+ ### McpServerUnavailableError
134
+
135
+ One MCP server whose tools could not be acquired.
136
+
137
+ #### Extends
138
+
139
+ - `Error`
140
+
141
+ #### Constructors
142
+
143
+ ##### Constructor
144
+
145
+ ```ts
146
+ new McpServerUnavailableError(
147
+ serverId,
148
+ reason,
149
+ cause?
150
+ ): McpServerUnavailableError;
151
+ ```
152
+
153
+ ###### Parameters
154
+
155
+ | Parameter | Type |
156
+ | ---------- | ----------------------------------------------------------- |
157
+ | `serverId` | `string` |
158
+ | `reason` | [`McpServerUnavailableReason`](#mcpserverunavailablereason) |
159
+ | `cause?` | `unknown` |
160
+
161
+ ###### Returns
162
+
163
+ [`McpServerUnavailableError`](#mcpserverunavailableerror)
164
+
165
+ ###### Overrides
166
+
167
+ ```ts
168
+ Error.constructor;
169
+ ```
170
+
171
+ #### Properties
172
+
173
+ ##### name
174
+
175
+ ```ts
176
+ readonly name: "McpServerUnavailableError" = "McpServerUnavailableError";
177
+ ```
178
+
179
+ ###### Overrides
180
+
181
+ ```ts
182
+ Error.name;
183
+ ```
184
+
185
+ ##### serverId
186
+
187
+ ```ts
188
+ readonly serverId: string;
189
+ ```
190
+
191
+ ##### reason
192
+
193
+ ```ts
194
+ readonly reason: McpServerUnavailableReason;
195
+ ```
196
+
197
+ ## Type Aliases
198
+
199
+ ### FilesEditErrorReason
200
+
201
+ ```ts
202
+ type FilesEditErrorReason =
203
+ | "not-found"
204
+ | "ambiguous"
205
+ | "file-too-large"
206
+ | "partial-character"
207
+ | "unchanged"
208
+ | "conflict";
209
+ ```
210
+
211
+ Typed refusal from a bounded or conditional Files edit.
212
+
213
+ ---
214
+
215
+ ### FilesPatch
216
+
217
+ ```ts
218
+ type FilesPatch = (
219
+ input,
220
+ context,
221
+ ) => Promise<z.output<typeof patchOutputSchema>>;
222
+ ```
223
+
224
+ Host-owned native patch operation receiving the invocation's deadline and
225
+ signal.
226
+
227
+ #### Parameters
228
+
229
+ | Parameter | Type |
230
+ | --------- | ---------------------------------------------------------------------------- |
231
+ | `input` | `z.output`\<_typeof_ [`patchInputSchema`](files-patch.md#patchinputschema)\> |
232
+ | `context` | `InvocationContext` |
233
+
234
+ #### Returns
235
+
236
+ `Promise`\<`z.output`\<_typeof_
237
+ [`patchOutputSchema`](files-patch.md#patchoutputschema)\>\>
238
+
239
+ ---
240
+
241
+ ### FilesPort
242
+
243
+ ```ts
244
+ type FilesPort = Readonly<{
245
+ patch?: FilesPatch;
246
+ read: (input, context) => Promise<z.output<typeof readOutputSchema>>;
247
+ list: (input, context) => Promise<z.output<typeof listOutputSchema>>;
248
+ glob: (input, context) => Promise<z.output<typeof globOutputSchema>>;
249
+ grep: (input, context) => Promise<z.output<typeof grepOutputSchema>>;
250
+ replace: (
251
+ input,
252
+ context,
253
+ ) => Promise<
254
+ Readonly<{
255
+ path: string;
256
+ bytes: number;
257
+ }>
258
+ >;
259
+ }>;
260
+ ```
261
+
262
+ Captured host file authority; the host owns path confinement and atomic
263
+ replacement.
264
+
265
+ ---
266
+
267
+ ### FileToolName
268
+
269
+ ```ts
270
+ type FileToolName = "read" | "list" | "glob" | "grep" | "apply_patch";
271
+ ```
272
+
273
+ Closed set of direct, model-visible Files tools; widening one is an ADR.
274
+
275
+ ---
276
+
277
+ ### FileTool
278
+
279
+ ```ts
280
+ type FileTool = LabelledTool &
281
+ Readonly<{
282
+ [fileToolBrand]: true;
283
+ }> &
284
+ Readonly<{
285
+ descriptor: Readonly<{
286
+ name: FileToolName;
287
+ }>;
288
+ module: "files";
289
+ access: Access;
290
+ }>;
291
+ ```
292
+
293
+ A `MuleTool` minted only by this module, named from the closed `FileToolName`
294
+ set. No host can construct one: the brand has no public constructor, so a
295
+ host-made `MuleTool` fails typecheck against `files?`.
296
+
297
+ ---
298
+
299
+ ### FilesSurface
300
+
301
+ ```ts
302
+ type FilesSurface = Readonly<{
303
+ module: ModuleRegistration;
304
+ tools: readonly FileTool[];
305
+ }>;
306
+ ```
307
+
308
+ One Mycelium module and the direct Files tools built from the same port.
309
+
310
+ ---
311
+
312
+ ### FilesConnectionOptions
313
+
314
+ ```ts
315
+ type FilesConnectionOptions = Readonly<{
316
+ port: FilesPort;
317
+ pathInstructions?: string;
318
+ }>;
319
+ ```
320
+
321
+ Host inputs for a captured Files connection.
322
+
323
+ ---
324
+
325
+ ### KnapsackComputer
326
+
327
+ ```ts
328
+ type KnapsackComputer = Readonly<{
329
+ getCapabilities: (signal) => Promise<MyceliumJsonValue>;
330
+ call: (capabilityId, input, context) => Promise<MyceliumJsonValue>;
331
+ }>;
332
+ ```
333
+
334
+ Generic advertised-call interface supplied by one Computer provider.
335
+
336
+ ---
337
+
338
+ ### ComputerConnectionOptions
339
+
340
+ ```ts
341
+ type ComputerConnectionOptions = Readonly<{
342
+ id: string;
343
+ name: string;
344
+ namespace?: readonly string[];
345
+ files?: FilesConnectionOptions;
346
+ role?: string;
347
+ computer: KnapsackComputer;
348
+ }>;
349
+ ```
350
+
351
+ Selection and naming required to connect one Computer to Mycelium.
352
+
353
+ ---
354
+
355
+ ### ComputerUnavailableReason
356
+
357
+ ```ts
358
+ type ComputerUnavailableReason =
359
+ "rejected" | "timeout" | "invalid-advertisement";
360
+ ```
361
+
362
+ Why one Computer contributed no module to an acquisition.
363
+
364
+ ---
365
+
366
+ ### ComputersConnectionOptions
367
+
368
+ ```ts
369
+ type ComputersConnectionOptions = Readonly<{
370
+ id: string;
371
+ read: () => Readonly<{
372
+ version: string;
373
+ connections: readonly ComputerConnectionOptions[];
374
+ }>;
375
+ subscribe: (invalidate) => () => void;
376
+ onUnavailable: (error) => void;
377
+ describeTimeoutMillis?: number;
378
+ }>;
379
+ ```
380
+
381
+ A captured host connection list; authority remains with its supplying host.
382
+
383
+ ---
384
+
385
+ ### McpServerConnection
386
+
387
+ ```ts
388
+ type McpServerConnection = Readonly<{
389
+ id: string;
390
+ name: string;
391
+ url: URL;
392
+ headers?: Readonly<Record<string, string>>;
393
+ }>;
394
+ ```
395
+
396
+ One remote MCP server a host has admitted for an Agent.
397
+
398
+ ---
399
+
400
+ ### McpServersConnectionOptions
401
+
402
+ ```ts
403
+ type McpServersConnectionOptions = Readonly<{
404
+ id: string;
405
+ read: () => Promise<
406
+ Readonly<{
407
+ version: string;
408
+ servers: readonly McpServerConnection[];
409
+ }>
410
+ >;
411
+ subscribe: (invalidate) => () => void;
412
+ onUnavailable: (error) => void;
413
+ fetch: FetchLike;
414
+ namespace?: readonly string[];
415
+ connectTimeoutMillis?: number;
416
+ }>;
417
+ ```
418
+
419
+ A captured host list of remote MCP servers; authority stays with the host.
420
+
421
+ ---
422
+
423
+ ### McpServerUnavailableReason
424
+
425
+ ```ts
426
+ type McpServerUnavailableReason =
427
+ "rejected" | "unauthorized" | "timeout" | "invalid-advertisement";
428
+ ```
429
+
430
+ Why one MCP server contributed no module to an acquisition.
431
+
432
+ ## Variables
433
+
434
+ ### listInputSchema
435
+
436
+ ```ts
437
+ const listInputSchema: ZodObject<
438
+ {
439
+ path: ZodString;
440
+ limit: ZodDefault<ZodNumber>;
441
+ },
442
+ $strict
443
+ >;
444
+ ```
445
+
446
+ Bounded directory listing request.
447
+
448
+ ---
449
+
450
+ ### listOutputSchema
451
+
452
+ ```ts
453
+ const listOutputSchema: ZodObject<
454
+ {
455
+ path: ZodString;
456
+ entries: ZodArray<
457
+ ZodObject<
458
+ {
459
+ path: ZodString;
460
+ name: ZodString;
461
+ type: ZodEnum<{
462
+ file: "file";
463
+ directory: "directory";
464
+ symlink: "symlink";
465
+ }>;
466
+ size: ZodNumber;
467
+ modifiedAt: ZodNumber;
468
+ },
469
+ $strict
470
+ >
471
+ >;
472
+ truncated: ZodBoolean;
473
+ },
474
+ $strict
475
+ >;
476
+ ```
477
+
478
+ Directory entries and an explicit truncation flag.
479
+
480
+ ---
481
+
482
+ ### globInputSchema
483
+
484
+ ```ts
485
+ const globInputSchema: ZodObject<
486
+ {
487
+ path: ZodString;
488
+ pattern: ZodString;
489
+ limit: ZodDefault<ZodNumber>;
490
+ },
491
+ $strict
492
+ >;
493
+ ```
494
+
495
+ Bounded path-pattern search request.
496
+
497
+ ---
498
+
499
+ ### globOutputSchema
500
+
501
+ ```ts
502
+ const globOutputSchema: ZodObject<
503
+ {
504
+ path: ZodString;
505
+ matches: ZodArray<ZodString>;
506
+ truncated: ZodBoolean;
507
+ },
508
+ $strict
509
+ >;
510
+ ```
511
+
512
+ Matching paths and an explicit truncation flag.
513
+
514
+ ---
515
+
516
+ ### grepInputSchema
517
+
518
+ ```ts
519
+ const grepInputSchema: ZodObject<
520
+ {
521
+ path: ZodString;
522
+ pattern: ZodString;
523
+ regex: ZodDefault<ZodBoolean>;
524
+ ignoreCase: ZodDefault<ZodBoolean>;
525
+ limit: ZodDefault<ZodNumber>;
526
+ },
527
+ $strict
528
+ >;
529
+ ```
530
+
531
+ Bounded content-search request with optional regular-expression matching.
532
+
533
+ ---
534
+
535
+ ### grepOutputSchema
536
+
537
+ ```ts
538
+ const grepOutputSchema: ZodObject<
539
+ {
540
+ path: ZodString;
541
+ matches: ZodArray<
542
+ ZodObject<
543
+ {
544
+ path: ZodString;
545
+ line: ZodNumber;
546
+ text: ZodString;
547
+ },
548
+ $strict
549
+ >
550
+ >;
551
+ truncated: ZodBoolean;
552
+ },
553
+ $strict
554
+ >;
555
+ ```
556
+
557
+ Content matches and an explicit truncation flag.
558
+
559
+ ---
560
+
561
+ ### editInputSchema
562
+
563
+ ```ts
564
+ const editInputSchema: ZodObject<
565
+ {
566
+ path: ZodString;
567
+ oldText: ZodString;
568
+ newText: ZodString;
569
+ },
570
+ $strict
571
+ >;
572
+ ```
573
+
574
+ Text replacement request decoded before the captured Files port is called.
575
+
576
+ ---
577
+
578
+ ### filesEditFailureSchema
579
+
580
+ ```ts
581
+ const filesEditFailureSchema: ZodObject<{
582
+ status: ZodLiteral<"failed">;
583
+ error: ZodObject<{
584
+ kind: ZodEnum<{
585
+ not-found: "not-found";
586
+ ambiguous: "ambiguous";
587
+ file-too-large: "file-too-large";
588
+ partial-character: "partial-character";
589
+ unchanged: "unchanged";
590
+ conflict: "conflict";
591
+ }>;
592
+ path: ZodString;
593
+ message: ZodString;
594
+ }, $strict>;
595
+ }, $strict>;
596
+ ```
597
+
598
+ Structured edit refusal, including its reason and affected path.
599
+
600
+ ---
601
+
602
+ ### editOutputSchema
603
+
604
+ ```ts
605
+ const editOutputSchema: ZodUnion<readonly [ZodObject<{
606
+ path: ZodString;
607
+ bytes: ZodNumber;
608
+ diff: ZodString;
609
+ firstChangedLine: ZodNullable<ZodNumber>;
610
+ unifiedPatch: ZodNullable<ZodString>;
611
+ unifiedPatchBytes: ZodNumber;
612
+ unifiedPatchAddedLines: ZodNumber;
613
+ unifiedPatchRemovedLines: ZodNumber;
614
+ unifiedPatchTruncated: ZodBoolean;
615
+ }, $strict>, ZodObject<{
616
+ status: ZodLiteral<"failed">;
617
+ error: ZodObject<{
618
+ kind: ZodEnum<{
619
+ not-found: "not-found";
620
+ ambiguous: "ambiguous";
621
+ file-too-large: "file-too-large";
622
+ partial-character: "partial-character";
623
+ unchanged: "unchanged";
624
+ conflict: "conflict";
625
+ }>;
626
+ path: ZodString;
627
+ message: ZodString;
628
+ }, $strict>;
629
+ }, $strict>]>;
630
+ ```
631
+
632
+ Successful edit metadata or a typed edit refusal.
633
+
634
+ ---
635
+
636
+ ### Knapsack
637
+
638
+ ```ts
639
+ const Knapsack: Readonly<{
640
+ computer: (input) => CapabilitySource;
641
+ computers: (input) => CapabilitySource;
642
+ files: (input) => FilesSurface;
643
+ mcpServers: (input) => CapabilitySource;
644
+ }>;
645
+ ```
646
+
647
+ Agent tool connections available for composition through Mycelium.
648
+
649
+ ## Functions
650
+
651
+ ### edit()
652
+
653
+ ```ts
654
+ function edit(
655
+ port,
656
+ input,
657
+ context,
658
+ ): Promise<
659
+ | {
660
+ path: string;
661
+ bytes: number;
662
+ diff: string;
663
+ firstChangedLine: number | null;
664
+ unifiedPatch: string | null;
665
+ unifiedPatchBytes: number;
666
+ unifiedPatchAddedLines: number;
667
+ unifiedPatchRemovedLines: number;
668
+ unifiedPatchTruncated: boolean;
669
+ }
670
+ | {
671
+ status: "failed";
672
+ error: {
673
+ kind:
674
+ | "not-found"
675
+ | "ambiguous"
676
+ | "file-too-large"
677
+ | "partial-character"
678
+ | "unchanged"
679
+ | "conflict";
680
+ path: string;
681
+ message: string;
682
+ };
683
+ }
684
+ >;
685
+ ```
686
+
687
+ Apply the same edit behavior as the Files edit operation directly through a
688
+ captured FilesPort.
689
+
690
+ #### Parameters
691
+
692
+ | Parameter | Type |
693
+ | --------------- | ----------------------------------------------------------------- |
694
+ | `port` | [`FilesPort`](#filesport) |
695
+ | `input` | \{ `path`: `string`; `oldText`: `string`; `newText`: `string`; \} |
696
+ | `input.path` | `string` |
697
+ | `input.oldText` | `string` |
698
+ | `input.newText` | `string` |
699
+ | `context` | `InvocationContext` |
700
+
701
+ #### Returns
702
+
703
+ `Promise`\< \| \{ `path`: `string`; `bytes`: `number`; `diff`: `string`;
704
+ `firstChangedLine`: `number` \| `null`; `unifiedPatch`: `string` \| `null`;
705
+ `unifiedPatchBytes`: `number`; `unifiedPatchAddedLines`: `number`;
706
+ `unifiedPatchRemovedLines`: `number`; `unifiedPatchTruncated`: `boolean`; \} \|
707
+ \{ `status`: `"failed"`; `error`: \{ `kind`: \| `"not-found"` \| `"ambiguous"`
708
+ \| `"file-too-large"` \| `"partial-character"` \| `"unchanged"` \| `"conflict"`;
709
+ `path`: `string`; `message`: `string`; \}; \}\>
710
+
711
+ ## References
712
+
713
+ ### readInputSchema
714
+
715
+ Re-exports [readInputSchema](files-read.md#readinputschema)
716
+
717
+ ---
718
+
719
+ ### readOutputSchema
720
+
721
+ Re-exports [readOutputSchema](files-read.md#readoutputschema)
722
+
723
+ ---
724
+
725
+ ### patchInputSchema
726
+
727
+ Re-exports [patchInputSchema](files-patch.md#patchinputschema)
728
+
729
+ ---
730
+
731
+ ### patchOutputSchema
732
+
733
+ Re-exports [patchOutputSchema](files-patch.md#patchoutputschema)