@fungi.computer/shiitake 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (164) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +454 -2
  3. package/dist/agar-extension.d.ts +9 -0
  4. package/dist/agar-extension.js +38 -0
  5. package/dist/agent-control.d.ts +77 -0
  6. package/dist/agent-control.js +434 -0
  7. package/dist/client-entry.d.ts +211 -0
  8. package/dist/client-entry.js +101 -0
  9. package/dist/client-wire.d.ts +199 -0
  10. package/dist/client-wire.js +271 -0
  11. package/dist/client.d.ts +439 -0
  12. package/dist/client.js +4 -0
  13. package/dist/cloudflare.d.ts +220 -0
  14. package/dist/cloudflare.js +531 -0
  15. package/dist/effect.d.ts +42 -0
  16. package/dist/effect.js +20 -0
  17. package/dist/errors.d.ts +50 -0
  18. package/dist/errors.js +81 -0
  19. package/dist/extension-client.d.ts +38 -0
  20. package/dist/extension-client.js +56 -0
  21. package/dist/extension-contract.d.ts +73 -0
  22. package/dist/extension-contract.js +11 -0
  23. package/dist/extensions.d.ts +589 -0
  24. package/dist/extensions.js +263 -0
  25. package/dist/fleet.d.ts +313 -0
  26. package/dist/fleet.js +540 -0
  27. package/dist/hosted.d.ts +133 -0
  28. package/dist/hosted.js +265 -0
  29. package/dist/http-routes.d.ts +772 -0
  30. package/dist/http-routes.js +242 -0
  31. package/dist/http.d.ts +1 -0
  32. package/dist/http.js +1 -0
  33. package/dist/index.d.ts +35 -0
  34. package/dist/index.js +13 -0
  35. package/dist/internal/accepted-run-executor.d.ts +23 -0
  36. package/dist/internal/accepted-run-executor.js +129 -0
  37. package/dist/internal/admission-door.d.ts +75 -0
  38. package/dist/internal/admission-door.js +105 -0
  39. package/dist/internal/agent-close.d.ts +4 -0
  40. package/dist/internal/agent-close.js +42 -0
  41. package/dist/internal/browser-sessions.d.ts +31 -0
  42. package/dist/internal/browser-sessions.js +173 -0
  43. package/dist/internal/client-boundary.d.ts +262 -0
  44. package/dist/internal/client-boundary.js +202 -0
  45. package/dist/internal/compaction/compaction.d.ts +54 -0
  46. package/dist/internal/compaction/compaction.js +291 -0
  47. package/dist/internal/compaction/session-compaction.d.ts +69 -0
  48. package/dist/internal/compaction/session-compaction.js +330 -0
  49. package/dist/internal/compaction/settings.d.ts +11 -0
  50. package/dist/internal/compaction/settings.js +40 -0
  51. package/dist/internal/compaction/utils.d.ts +45 -0
  52. package/dist/internal/compaction/utils.js +319 -0
  53. package/dist/internal/contracts.d.ts +235 -0
  54. package/dist/internal/contracts.js +1 -0
  55. package/dist/internal/coordinator.d.ts +18 -0
  56. package/dist/internal/coordinator.js +362 -0
  57. package/dist/internal/document-codec.d.ts +11 -0
  58. package/dist/internal/document-codec.js +39 -0
  59. package/dist/internal/effect-client.d.ts +13 -0
  60. package/dist/internal/effect-client.js +102 -0
  61. package/dist/internal/effect-contracts.d.ts +236 -0
  62. package/dist/internal/effect-contracts.js +2 -0
  63. package/dist/internal/extension-command-registry.d.ts +11 -0
  64. package/dist/internal/extension-command-registry.js +29 -0
  65. package/dist/internal/extension-command-tools.d.ts +17 -0
  66. package/dist/internal/extension-command-tools.js +50 -0
  67. package/dist/internal/extension-context.d.ts +25 -0
  68. package/dist/internal/extension-context.js +35 -0
  69. package/dist/internal/extension-definitions.d.ts +5 -0
  70. package/dist/internal/extension-definitions.js +6 -0
  71. package/dist/internal/extension-hook.d.ts +25 -0
  72. package/dist/internal/extension-hook.js +46 -0
  73. package/dist/internal/extension-roster.d.ts +23 -0
  74. package/dist/internal/extension-roster.js +228 -0
  75. package/dist/internal/extension-runtime.d.ts +63 -0
  76. package/dist/internal/extension-runtime.js +1004 -0
  77. package/dist/internal/failure.d.ts +2 -0
  78. package/dist/internal/failure.js +9 -0
  79. package/dist/internal/host-meta.d.ts +41 -0
  80. package/dist/internal/host-meta.js +39 -0
  81. package/dist/internal/json-value.d.ts +4 -0
  82. package/dist/internal/json-value.js +3 -0
  83. package/dist/internal/model-acquisition.d.ts +21 -0
  84. package/dist/internal/model-acquisition.js +98 -0
  85. package/dist/internal/model-preference.d.ts +21 -0
  86. package/dist/internal/model-preference.js +20 -0
  87. package/dist/internal/observation-kernel.d.ts +28 -0
  88. package/dist/internal/observation-kernel.js +169 -0
  89. package/dist/internal/promise-facade.d.ts +18 -0
  90. package/dist/internal/promise-facade.js +172 -0
  91. package/dist/internal/run-scope.d.ts +27 -0
  92. package/dist/internal/run-scope.js +214 -0
  93. package/dist/internal/runtime-coordinator.d.ts +34 -0
  94. package/dist/internal/runtime-coordinator.js +233 -0
  95. package/dist/internal/runtime-core.d.ts +19 -0
  96. package/dist/internal/runtime-core.js +39 -0
  97. package/dist/internal/runtime-reconciliation.d.ts +18 -0
  98. package/dist/internal/runtime-reconciliation.js +162 -0
  99. package/dist/internal/session-context.d.ts +11 -0
  100. package/dist/internal/session-context.js +67 -0
  101. package/dist/internal/session-status.d.ts +10 -0
  102. package/dist/internal/session-status.js +52 -0
  103. package/dist/internal/woodstock/agent-reply.d.ts +25 -0
  104. package/dist/internal/woodstock/agent-reply.js +67 -0
  105. package/dist/internal/woodstock/client-projection.d.ts +29 -0
  106. package/dist/internal/woodstock/client-projection.js +512 -0
  107. package/dist/internal/woodstock/compaction-activity.d.ts +17 -0
  108. package/dist/internal/woodstock/compaction-activity.js +32 -0
  109. package/dist/internal/woodstock/cursor.d.ts +9 -0
  110. package/dist/internal/woodstock/cursor.js +44 -0
  111. package/dist/internal/woodstock/extension-store.d.ts +72 -0
  112. package/dist/internal/woodstock/extension-store.js +262 -0
  113. package/dist/internal/woodstock/fleet-store.d.ts +36 -0
  114. package/dist/internal/woodstock/fleet-store.js +100 -0
  115. package/dist/internal/woodstock/identities.d.ts +6 -0
  116. package/dist/internal/woodstock/identities.js +11 -0
  117. package/dist/internal/woodstock/index.d.ts +170 -0
  118. package/dist/internal/woodstock/index.js +546 -0
  119. package/dist/internal/woodstock/progress.d.ts +32 -0
  120. package/dist/internal/woodstock/progress.js +89 -0
  121. package/dist/internal/woodstock/run-recovery.d.ts +8 -0
  122. package/dist/internal/woodstock/run-recovery.js +95 -0
  123. package/dist/internal/woodstock/session-attention.d.ts +16 -0
  124. package/dist/internal/woodstock/session-attention.js +88 -0
  125. package/dist/internal/woodstock/session-documents.d.ts +18 -0
  126. package/dist/internal/woodstock/session-documents.js +51 -0
  127. package/dist/internal/woodstock/session-entry.d.ts +478 -0
  128. package/dist/internal/woodstock/session-entry.js +484 -0
  129. package/dist/internal/woodstock/session-grants.d.ts +24 -0
  130. package/dist/internal/woodstock/session-grants.js +84 -0
  131. package/dist/internal/woodstock/session-inbox.d.ts +56 -0
  132. package/dist/internal/woodstock/session-inbox.js +307 -0
  133. package/dist/internal/woodstock/session-store.d.ts +432 -0
  134. package/dist/internal/woodstock/session-store.js +2006 -0
  135. package/dist/internal/woodstock/storage-admission.d.ts +14 -0
  136. package/dist/internal/woodstock/storage-admission.js +44 -0
  137. package/dist/model-preference.d.ts +20 -0
  138. package/dist/model-preference.js +30 -0
  139. package/dist/node.d.ts +64 -0
  140. package/dist/node.js +256 -0
  141. package/dist/remote-client.d.ts +11 -0
  142. package/dist/remote-client.js +298 -0
  143. package/dist/session-attention.d.ts +35 -0
  144. package/dist/session-attention.js +22 -0
  145. package/dist/session-documents.d.ts +28 -0
  146. package/dist/session-documents.js +1 -0
  147. package/dist/testing.d.ts +54 -0
  148. package/dist/testing.js +215 -0
  149. package/docs/api/README.md +26 -0
  150. package/docs/api/agar-extension.md +40 -0
  151. package/docs/api/agent-control.md +151 -0
  152. package/docs/api/client-entry.md +344 -0
  153. package/docs/api/client.md +1112 -0
  154. package/docs/api/cloudflare.md +500 -0
  155. package/docs/api/effect.md +884 -0
  156. package/docs/api/extensions.md +2003 -0
  157. package/docs/api/fleet.md +734 -0
  158. package/docs/api/hosted.md +382 -0
  159. package/docs/api/http.md +111 -0
  160. package/docs/api/index.md +1116 -0
  161. package/docs/api/model-preference.md +151 -0
  162. package/docs/api/node.md +142 -0
  163. package/docs/api/testing.md +250 -0
  164. package/package.json +130 -3
package/dist/errors.js ADDED
@@ -0,0 +1,81 @@
1
+ import * as Schema from "effect/Schema";
2
+ /** Stable boundary that rejected a Shiitake operation. */
3
+ const ShiitakeErrorBoundarySchema = Schema.Literals([
4
+ "contract",
5
+ "extensions",
6
+ "instructions",
7
+ "model",
8
+ "runtime",
9
+ "store",
10
+ "tools",
11
+ ]);
12
+ /** Safe failure category exposed by both Shiitake facades. */
13
+ const ShiitakeErrorCauseSchema = Schema.Literals([
14
+ "closed",
15
+ "conflict",
16
+ "incompatible",
17
+ "invalid",
18
+ "rejected",
19
+ "unavailable",
20
+ /** Owner storage is near its budget; new Sessions and prompts wait. */
21
+ "storage_pressure",
22
+ /** One model context read is larger than the owner can safely decode. */
23
+ "context_too_large",
24
+ ]);
25
+ const requestIdSchema = Schema.String.pipe(Schema.check(Schema.isMinLength(1)), Schema.check(Schema.isMaxLength(256)));
26
+ /** Canonical serialized Shiitake failure. */
27
+ export const ShiitakeErrorWireSchema = Schema.Struct({
28
+ _tag: Schema.Literal("ShiitakeError"),
29
+ boundary: ShiitakeErrorBoundarySchema,
30
+ cause: ShiitakeErrorCauseSchema,
31
+ message: Schema.String,
32
+ requestId: Schema.optionalKey(requestIdSchema),
33
+ });
34
+ /** Sanitized failure from a parsed Shiitake boundary. */
35
+ export class ShiitakeError extends Error {
36
+ boundary;
37
+ requestId;
38
+ /** Stable runtime tag for typed Shiitake failures. */
39
+ _tag = "ShiitakeError";
40
+ /** Safe category describing why it was rejected. */
41
+ cause;
42
+ /** Original cause retained only for server-side diagnosis. */
43
+ underlying;
44
+ /** Construct a sanitized boundary failure. */
45
+ constructor(
46
+ /** Boundary that rejected the operation. */
47
+ boundary,
48
+ /** Safe category describing why it was rejected. */
49
+ category,
50
+ /** Human-readable message safe for callers to display. */
51
+ message,
52
+ /** Request identity recoverable when a send may have reached the owner. */
53
+ requestId,
54
+ /**
55
+ * The original thrown value, kept for server-side diagnosis only. It is
56
+ * never serialized: the wire encoder copies named fields only.
57
+ */
58
+ cause) {
59
+ super(message);
60
+ this.boundary = boundary;
61
+ this.requestId = requestId;
62
+ this.name = "ShiitakeError";
63
+ this.cause = category;
64
+ this.underlying = cause;
65
+ }
66
+ }
67
+ /** Sanitize one caught host failure for Shiitake's public wire. */
68
+ export function toShiitakeErrorWire(cause) {
69
+ const failure = cause instanceof ShiitakeError
70
+ ? cause
71
+ : new ShiitakeError("runtime", "unavailable", "Shiitake operation failed");
72
+ const wire = {
73
+ _tag: failure._tag,
74
+ boundary: failure.boundary,
75
+ cause: failure.cause,
76
+ message: failure.message,
77
+ };
78
+ if (failure.requestId !== undefined)
79
+ Object.assign(wire, { requestId: failure.requestId });
80
+ return Object.freeze(wire);
81
+ }
@@ -0,0 +1,38 @@
1
+ import type { SessionExtensionSlots, ShiitakeAgent, ShiitakeSession } from "./client.js";
2
+ import type { CommandsV0, ExtensionContractV0, ExtensionSlotV0 } from "./extensions.js";
3
+ /** What one client sees of an extension in a Session observation. */
4
+ export type ExtensionViewV0<P> = Readonly<{
5
+ status: "unavailable";
6
+ }> | Readonly<{
7
+ status: "stopped";
8
+ reason: string;
9
+ }> | Readonly<{
10
+ status: "running";
11
+ value: P | null;
12
+ }>;
13
+ /** Command names of one scope, typed by the shared contract. */
14
+ export type ScopedCommandsV0<C extends CommandsV0, S extends "session" | "agent"> = {
15
+ [K in keyof C & string]: C[K]["scope"] extends S ? K : never;
16
+ }[keyof C & string];
17
+ /** Typed call surface of one contract's commands in one scope. */
18
+ export type BoundCallV0<C extends CommandsV0, S extends "session" | "agent"> = <K extends ScopedCommandsV0<C, S>>(name: K, input: C[K]["input"]["Type"]) => Promise<C[K]["output"]["Type"]>;
19
+ /** One Session bound to one extension contract. */
20
+ export type BoundSessionExtensionV0<C extends CommandsV0, P> = Readonly<{
21
+ /** Decode this extension's slot from a snapshot or update frame. */
22
+ view: (observation: Readonly<{
23
+ extensions: SessionExtensionSlots;
24
+ }>) => ExtensionViewV0<P>;
25
+ /** Encode, call, and decode one Session-scope command. */
26
+ call: BoundCallV0<C, "session">;
27
+ }>;
28
+ /** One Agent bound to one extension contract. */
29
+ export type BoundAgentExtensionV0<C extends CommandsV0> = Readonly<{
30
+ /** Encode, call, and decode one Agent-scope command. */
31
+ call: BoundCallV0<C, "agent">;
32
+ }>;
33
+ /** Decode one observed slot using its owning contract's projection. */
34
+ export declare function viewExtension<C extends CommandsV0, P, PI>(contract: ExtensionContractV0<C, P, PI>, slot: ExtensionSlotV0 | undefined): ExtensionViewV0<P>;
35
+ /** Bind one Session to one extension contract; the contract's schemas decode. */
36
+ export declare function bindSessionExtension<C extends CommandsV0, P, PI>(session: Pick<ShiitakeSession, "extension">, contract: ExtensionContractV0<C, P, PI>): BoundSessionExtensionV0<C, P>;
37
+ /** Bind one Agent to one extension contract's Agent-scope commands. */
38
+ export declare function bindAgentExtension<C extends CommandsV0, P, PI>(agent: Pick<ShiitakeAgent, "extensions">, contract: ExtensionContractV0<C, P, PI>): BoundAgentExtensionV0<C>;
@@ -0,0 +1,56 @@
1
+ import * as Result from "effect/Result";
2
+ import * as Schema from "effect/Schema";
3
+ import { ShiitakeError } from "./errors.js";
4
+ import { JsonValueSchema } from "./internal/json-value.js";
5
+ const decodeJson = Schema.decodeUnknownResult(JsonValueSchema);
6
+ function contractFailure(message) {
7
+ return new ShiitakeError("contract", "invalid", message);
8
+ }
9
+ function typedCall(contract, send) {
10
+ return async (name, input) => {
11
+ const spec = Object.hasOwn(contract.commands, name)
12
+ ? contract.commands[name]
13
+ : undefined;
14
+ if (spec === undefined)
15
+ throw contractFailure("Extension command is unknown");
16
+ const encoded = Schema.encodeUnknownResult(spec.input)(input).pipe(Result.flatMap(decodeJson));
17
+ if (encoded._tag === "Failure")
18
+ throw contractFailure("Extension command input is invalid");
19
+ const output = Schema.decodeUnknownResult(spec.output)(await send(name, encoded.success));
20
+ if (output._tag === "Failure")
21
+ throw contractFailure("Extension output does not match its contract");
22
+ return output.success;
23
+ };
24
+ }
25
+ /** Decode one observed slot using its owning contract's projection. */
26
+ export function viewExtension(contract, slot) {
27
+ if (slot === undefined)
28
+ return { status: "unavailable" };
29
+ if (slot.status === "stopped")
30
+ return { status: "stopped", reason: slot.reason };
31
+ if (slot.value === null || contract.projection === null)
32
+ return { status: "running", value: null };
33
+ const decoded = Schema.decodeUnknownResult(contract.projection.schema)(slot.value);
34
+ return decoded._tag === "Success"
35
+ ? { status: "running", value: decoded.success }
36
+ : {
37
+ status: "stopped",
38
+ reason: "Extension projection does not match this client",
39
+ };
40
+ }
41
+ /** Bind one Session to one extension contract; the contract's schemas decode. */
42
+ export function bindSessionExtension(session, contract) {
43
+ const address = session.extension(contract.id);
44
+ return Object.freeze({
45
+ view: (observation) => viewExtension(contract, Object.hasOwn(observation.extensions, contract.id)
46
+ ? observation.extensions[contract.id]
47
+ : undefined),
48
+ call: typedCall(contract, (command, input) => address.call(command, input)),
49
+ });
50
+ }
51
+ /** Bind one Agent to one extension contract's Agent-scope commands. */
52
+ export function bindAgentExtension(agent, contract) {
53
+ return Object.freeze({
54
+ call: typedCall(contract, (command, input) => agent.extensions.call(contract.id, command, input)),
55
+ });
56
+ }
@@ -0,0 +1,73 @@
1
+ import * as Schema from "effect/Schema";
2
+ /** Host extension protocol; client-entry protocol is versioned independently. */
3
+ export type ShiitakeExtensionProtocolV0 = "shiitake.extension/v0";
4
+ /** ASCII extension identity shared by the host definition and its clients. */
5
+ export declare const extensionIdentifier: Schema.String;
6
+ /** SemVer spelling used by host admission. */
7
+ export declare const extensionVersion: Schema.String;
8
+ /** ASCII extension identity shared by the host definition and its clients. */
9
+ export declare const ExtensionId: Schema.brand<Schema.String, "ExtensionId">;
10
+ /** ASCII extension identity shared by the server definition and its clients. */
11
+ export type ExtensionId = Schema.Schema.Type<typeof ExtensionId>;
12
+ /** Core digest of one normalized extension definition. */
13
+ export declare const extensionRevisionSchema: Schema.brand<Schema.String, "ExtensionRevision">;
14
+ /** Core digest of one revision and its sorted granted capabilities. */
15
+ export declare const extensionFingerprintSchema: Schema.brand<Schema.String, "ExtensionFingerprint">;
16
+ /** Closed, versioned, feature-free capability vocabulary. */
17
+ export type ExtensionCapabilityV0 =
18
+ /** Namespaced schema-typed durable records. */
19
+ "state"
20
+ /** Namespaced durable requests for human attention. */
21
+ | "attention"
22
+ /** Exactly-once delivery of settled runs from a core-owned cursor. */
23
+ | "settled"
24
+ /** The one accepted-command door. */
25
+ | "send"
26
+ /** Durable per-extension wake timers. */
27
+ | "timers"
28
+ /** Session- and agent-scope commands over the generic call surface. */
29
+ | "commands"
30
+ /** One encoded slot in every Session snapshot and frame. */
31
+ | "projection"
32
+ /** A Mycelium module attached to runs this extension participates in. */
33
+ | "run_tools"
34
+ /** Exclusive Knapsack Files tools captured once per run. */
35
+ | "files"
36
+ /** Named system-prompt sections, evaluated before each model request. */
37
+ | "prompt"
38
+ /** The single exclusive compaction handoff slot. */
39
+ | "compaction_handoff";
40
+ /** Static identity and requested capabilities of one v0 extension. */
41
+ export type ExtensionManifestV0 = Readonly<{
42
+ protocol: ShiitakeExtensionProtocolV0;
43
+ id: ExtensionId;
44
+ /** Semver; bump when behaviour changes outside config and schemas. */
45
+ version: string;
46
+ requests: readonly ExtensionCapabilityV0[];
47
+ }>;
48
+ /** One command's scope and its encoded input and output schemas. */
49
+ export type CommandSpecV0<S extends "session" | "agent", I, II, O, OI> = Readonly<{
50
+ scope: S;
51
+ input: Schema.Codec<I, II>;
52
+ output: Schema.Codec<O, OI>;
53
+ }>;
54
+ /** Existential command spec. */
55
+ export type AnyCommandSpecV0 = Readonly<{
56
+ scope: "session" | "agent";
57
+ input: Schema.Codec<unknown>;
58
+ output: Schema.Codec<unknown>;
59
+ }>;
60
+ /** Commands declared by one extension contract. */
61
+ export type CommandsV0 = Readonly<Record<string, AnyCommandSpecV0>>;
62
+ /** The encoded Session projection slot. */
63
+ export type ProjectionSpecV0<P, PI> = Readonly<{
64
+ schema: Schema.Codec<P, PI>;
65
+ }>;
66
+ /** Shared by the host definition and the client binding: one schema set. */
67
+ export type ExtensionContractV0<C extends CommandsV0, P, PI> = Readonly<{
68
+ id: ExtensionId;
69
+ commands: C;
70
+ projection: ProjectionSpecV0<P, PI> | null;
71
+ }>;
72
+ /** Activity already observed by the client, never an execution authority. */
73
+ export type ClientActivityV0 = "idle" | "working" | "blocked" | "unknown";
@@ -0,0 +1,11 @@
1
+ import * as Schema from "effect/Schema";
2
+ /** ASCII extension identity shared by the host definition and its clients. */
3
+ export const extensionIdentifier = Schema.String.pipe(Schema.check(Schema.isMinLength(1)), Schema.check(Schema.isMaxLength(128)), Schema.check(Schema.isPattern(/^[a-z][a-z0-9]*(?:[-_.][a-z0-9]+)*$/u)));
4
+ /** SemVer spelling used by host admission. */
5
+ export const extensionVersion = Schema.String.pipe(Schema.check(Schema.isMinLength(1)), Schema.check(Schema.isMaxLength(64)), Schema.check(Schema.isPattern(/^(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)(?:-[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/u)));
6
+ /** ASCII extension identity shared by the host definition and its clients. */
7
+ export const ExtensionId = extensionIdentifier.pipe(Schema.brand("ExtensionId"));
8
+ /** Core digest of one normalized extension definition. */
9
+ export const extensionRevisionSchema = Schema.String.pipe(Schema.check(Schema.isPattern(/^sha256:[0-9a-f]{64}$/u)), Schema.brand("ExtensionRevision"));
10
+ /** Core digest of one revision and its sorted granted capabilities. */
11
+ export const extensionFingerprintSchema = Schema.String.pipe(Schema.check(Schema.isPattern(/^sha256:[0-9a-f]{64}$/u)), Schema.brand("ExtensionFingerprint"));