@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
@@ -0,0 +1,101 @@
1
+ import * as Effect from "effect/Effect";
2
+ import * as Predicate from "effect/Predicate";
3
+ import * as Schema from "effect/Schema";
4
+ import { ExtensionId, } from "./extension-contract.js";
5
+ import { viewExtension } from "./extension-client.js";
6
+ import { invokeExtensionHook } from "./internal/extension-hook.js";
7
+ import { rowIdentitySchemaV1, rowLabelSchemaV1, rowSchemaV1, } from "@fungi.computer/gills";
8
+ export { viewExtension } from "./extension-client.js";
9
+ const unsigned = Schema.Int.check(Schema.isGreaterThanOrEqualTo(0));
10
+ const sequence = Schema.Int.check(Schema.isGreaterThan(0));
11
+ const objectArguments = Schema.Record(Schema.String, Schema.Json);
12
+ // Extension commands belong to Shiitake; Gill rows only carry navigation.
13
+ const commandAction = Schema.Struct({
14
+ id: rowIdentitySchemaV1,
15
+ label: rowLabelSchemaV1,
16
+ input: Schema.optional(objectArguments),
17
+ });
18
+ const commandRow = Schema.Struct({
19
+ ...rowSchemaV1.fields,
20
+ actions: Schema.optional(Schema.Array(commandAction).check(Schema.isMaxLength(8))),
21
+ });
22
+ const chipRow = rowSchemaV1.check(Schema.makeFilter((row) => row.open === undefined, {
23
+ message: "Client chips are display only",
24
+ }));
25
+ const panelRow = Schema.Struct({
26
+ ...commandRow.fields,
27
+ inspection: Schema.optionalKey(Schema.Struct({
28
+ commandId: rowIdentitySchemaV1,
29
+ title: rowLabelSchemaV1,
30
+ rows: Schema.Array(chipRow).check(Schema.isMaxLength(200)),
31
+ })),
32
+ });
33
+ /** One display-only status chip; order is local to the entry. */
34
+ export const clientChipSchemaV1 = Schema.Struct({
35
+ id: rowIdentitySchemaV1,
36
+ order: Schema.Number.check(Schema.isFinite()),
37
+ row: chipRow,
38
+ compact: Schema.optional(rowLabelSchemaV1),
39
+ });
40
+ /** One committed presentation event anchored to its real command, if any. */
41
+ export const clientTimelineCellSchemaV1 = Schema.Struct({
42
+ id: rowIdentitySchemaV1,
43
+ sequence,
44
+ at: unsigned,
45
+ commandId: Schema.NullOr(Schema.String),
46
+ rows: Schema.Array(commandRow).check(Schema.isMaxLength(200)),
47
+ }).check(Schema.makeFilter((cell) => cell.id === String(cell.sequence), {
48
+ message: "Client event identity must equal its sequence",
49
+ }));
50
+ const unique = (ids) => new Set(ids).size === ids.length;
51
+ /** Closed, bounded presentation data shared by every renderer. */
52
+ export const clientContributionSchemaV1 = Schema.Struct({
53
+ chips: Schema.Array(clientChipSchemaV1).check(Schema.isMaxLength(4)),
54
+ panel: Schema.Array(panelRow).check(Schema.isMaxLength(16)),
55
+ timeline: Schema.Struct({
56
+ cells: Schema.Array(clientTimelineCellSchemaV1).check(Schema.isMaxLength(32)),
57
+ omitted: unsigned,
58
+ }),
59
+ waiting: Schema.NullOr(Schema.Struct({ summary: rowLabelSchemaV1, cancel: commandAction })),
60
+ }).check(Schema.makeFilter((value) => value.chips.length +
61
+ value.panel.reduce((count, row) => count + 1 + (row.inspection?.rows.length ?? 0), 0) +
62
+ value.timeline.cells.reduce((count, cell) => count + cell.rows.length, 0) <=
63
+ 200, { message: "Client contribution exceeds 200 rows" }), Schema.makeFilter((value) => unique(value.chips.map((chip) => chip.id)) &&
64
+ unique(value.panel.map((row) => row.id)) &&
65
+ value.panel.every((row) => unique((row.inspection?.rows ?? []).map((child) => child.id))) &&
66
+ unique(value.timeline.cells.map((cell) => cell.id)) &&
67
+ value.timeline.cells.every((cell) => unique(cell.rows.map((row) => row.id))), { message: "Client contribution contains duplicate identities" }));
68
+ const entrySchema = Schema.Struct({
69
+ protocol: Schema.Literal("shiitake.client/v1"),
70
+ id: ExtensionId,
71
+ correlatedPrompts: Schema.optionalKey(Schema.Literal("note")),
72
+ attach: Schema.optionalKey(Schema.declare((value) => Predicate.isFunction(value))),
73
+ contribute: Schema.optionalKey(Schema.declare((value) => Predicate.isFunction(value))),
74
+ }).check(Schema.makeFilter((entry) => entry.attach !== undefined || entry.contribute !== undefined, { message: "Client entry requires attach or contribute" }));
75
+ const decodeEntry = Schema.decodeUnknownSync(entrySchema, {
76
+ onExcessProperty: "error",
77
+ });
78
+ /** Admit exactly V1; installed executable code is not sandboxed. */
79
+ export const parseClientEntryV1 = decodeEntry;
80
+ /** One typed author seam, usable with ordinary async attachment code. */
81
+ export function defineClientEntry(contract, client) {
82
+ if (client.contribute !== undefined && contract.projection === null)
83
+ throw new Error("Client contribution requires a projection");
84
+ const entry = {
85
+ protocol: "shiitake.client/v1",
86
+ id: contract.id,
87
+ };
88
+ if (client.correlatedPrompts !== undefined)
89
+ Object.assign(entry, { correlatedPrompts: client.correlatedPrompts });
90
+ const attach = client.attach;
91
+ const contribute = client.contribute;
92
+ if (attach !== undefined)
93
+ Object.assign(entry, {
94
+ attach: (context) => invokeExtensionHook(() => attach(context)),
95
+ });
96
+ if (contribute !== undefined)
97
+ Object.assign(entry, {
98
+ contribute: (slot) => contribute(viewExtension(contract, slot)),
99
+ });
100
+ return Object.freeze(parseClientEntryV1(entry));
101
+ }
@@ -0,0 +1,199 @@
1
+ import * as Schema from "effect/Schema";
2
+ import type { Accepted, CancelResult, ForkedSession, SessionFrame, SessionSnapshot, SessionSummaryPage, SessionTerminal } from "./client.js";
3
+ import { ShiitakeError } from "./errors.js";
4
+ import type { ExtensionSlotV0, ExtensionStatusV0, Json } from "./extensions.js";
5
+ /** Existing terminal wire grammar, shared by exact host settlement facts. */
6
+ export declare const SessionTerminalSchema: Schema.Codec<SessionTerminal>;
7
+ export declare const SessionSnapshotSchema: Schema.Struct<{
8
+ readonly sessionId: Schema.String;
9
+ readonly cursor: Schema.NullOr<Schema.String>;
10
+ readonly hasMore: Schema.Boolean;
11
+ readonly oldestCursor: Schema.optionalKey<Schema.NullOr<Schema.String>>;
12
+ readonly messages: Schema.$Array<Schema.Codec<Readonly<{
13
+ meta?: Json;
14
+ origin?: Readonly<{
15
+ extensionId: string;
16
+ correlation: string | null;
17
+ }>;
18
+ id: string;
19
+ sequence: number;
20
+ commandId: string | null;
21
+ value: import("@earendil-works/pi-ai").Message;
22
+ }>, Readonly<{
23
+ meta?: Json;
24
+ origin?: Readonly<{
25
+ extensionId: string;
26
+ correlation: string | null;
27
+ }>;
28
+ id: string;
29
+ sequence: number;
30
+ commandId: string | null;
31
+ value: import("@earendil-works/pi-ai").Message;
32
+ }>, never, never>>;
33
+ readonly terminals: Schema.$Array<Schema.Codec<Readonly<{
34
+ commandId: string;
35
+ outcome: "completed" | "cancelled" | "failed" | "interrupted";
36
+ sequence: number;
37
+ diagnostic: string | null;
38
+ meta?: Json;
39
+ }>, Readonly<{
40
+ commandId: string;
41
+ outcome: "completed" | "cancelled" | "failed" | "interrupted";
42
+ sequence: number;
43
+ diagnostic: string | null;
44
+ meta?: Json;
45
+ }>, never, never>>;
46
+ readonly sandboxFailures: Schema.optionalKey<Schema.$Array<Schema.Struct<{
47
+ readonly kind: Schema.Literal<"sandbox_failure">;
48
+ readonly ref: Schema.String;
49
+ readonly executionId: Schema.String;
50
+ readonly adapter: Schema.String;
51
+ readonly buildSha: Schema.NullOr<Schema.String>;
52
+ readonly tag: Schema.Literals<readonly ["SourceInvalid", "GuestThrew", "DeadlineExceeded", "Cancelled", "DispatchLost", "SandboxCrashed", "BadResponse", "ResultTooLarge", "ResultNotJson", "CapabilityFailed", "Unknown"]>;
53
+ readonly fields: Schema.$Record<Schema.String, Schema.Codec<import("zod").JSONType, import("zod").JSONType, never, never>>;
54
+ readonly healthAlert: Schema.Boolean;
55
+ }>>>;
56
+ readonly compactions: Schema.optionalKey<Schema.$Array<Schema.Codec<Readonly<{
57
+ id: string;
58
+ sequence: number;
59
+ at: number;
60
+ tokensBefore: number;
61
+ tokensAfter: number | null;
62
+ trigger: import("./client.js").SessionCompactionTrigger | null;
63
+ }>, Readonly<{
64
+ id: string;
65
+ sequence: number;
66
+ at: number;
67
+ tokensBefore: number;
68
+ tokensAfter: number | null;
69
+ trigger: import("./client.js").SessionCompactionTrigger | null;
70
+ }>, never, never>>>;
71
+ readonly compactionNotices: Schema.optionalKey<Schema.$Array<Schema.Codec<Readonly<{
72
+ id: string;
73
+ sequence: number;
74
+ at: number;
75
+ trigger: import("./client.js").SessionCompactionTrigger;
76
+ result: "nothing_to_compact" | "failed";
77
+ diagnostic: string | null;
78
+ }>, Readonly<{
79
+ id: string;
80
+ sequence: number;
81
+ at: number;
82
+ trigger: import("./client.js").SessionCompactionTrigger;
83
+ result: "nothing_to_compact" | "failed";
84
+ diagnostic: string | null;
85
+ }>, never, never>>>;
86
+ readonly pending: Schema.Codec<Readonly<{
87
+ total: number;
88
+ prompts: readonly import("./client.js").SessionPendingPrompt[];
89
+ hasMore: boolean;
90
+ }>, Readonly<{
91
+ total: number;
92
+ prompts: readonly import("./client.js").SessionPendingPrompt[];
93
+ hasMore: boolean;
94
+ }>, never, never>;
95
+ readonly activity: Schema.Codec<Readonly<{
96
+ queue: Readonly<{
97
+ state: "idle";
98
+ }> | Readonly<{
99
+ state: "queued";
100
+ commandId: string;
101
+ runningWork: import("./client.js").AgentRunningWork | null;
102
+ }> | Readonly<{
103
+ state: "running";
104
+ commandId: string;
105
+ }>;
106
+ cancellationRequested: boolean;
107
+ retry: Readonly<{
108
+ attempt: number;
109
+ maxAttempts: number;
110
+ delayMs: number;
111
+ errorMessage: string;
112
+ scheduledAt: number;
113
+ }> | null;
114
+ activeTool: string | null;
115
+ lastModelChoiceSequence: number | null;
116
+ compaction: Readonly<{
117
+ trigger: import("./client.js").SessionCompactionTrigger;
118
+ }> | null;
119
+ }>, Readonly<{
120
+ queue: Readonly<{
121
+ state: "idle";
122
+ }> | Readonly<{
123
+ state: "queued";
124
+ commandId: string;
125
+ runningWork: import("./client.js").AgentRunningWork | null;
126
+ }> | Readonly<{
127
+ state: "running";
128
+ commandId: string;
129
+ }>;
130
+ cancellationRequested: boolean;
131
+ retry: Readonly<{
132
+ attempt: number;
133
+ maxAttempts: number;
134
+ delayMs: number;
135
+ errorMessage: string;
136
+ scheduledAt: number;
137
+ }> | null;
138
+ activeTool: string | null;
139
+ lastModelChoiceSequence: number | null;
140
+ compaction: Readonly<{
141
+ trigger: import("./client.js").SessionCompactionTrigger;
142
+ }> | null;
143
+ }>, never, never>;
144
+ readonly progress: Schema.NullOr<Schema.Codec<Readonly<{
145
+ messageId: string;
146
+ revision: number;
147
+ text: string;
148
+ thinking: string;
149
+ textTruncated: boolean;
150
+ thinkingTruncated: boolean;
151
+ }>, Readonly<{
152
+ messageId: string;
153
+ revision: number;
154
+ text: string;
155
+ thinking: string;
156
+ textTruncated: boolean;
157
+ thinkingTruncated: boolean;
158
+ }>, never, never>>;
159
+ readonly extensions: Schema.$Record<Schema.String, Schema.Codec<ExtensionSlotV0, ExtensionSlotV0, never, never>>;
160
+ readonly attention: Schema.$Array<Schema.Struct<{
161
+ readonly extensionId: Schema.NonEmptyString;
162
+ readonly id: Schema.NonEmptyString;
163
+ readonly kind: Schema.NonEmptyString;
164
+ readonly summary: Schema.NonEmptyString;
165
+ readonly since: Schema.Int;
166
+ readonly expiresAt: Schema.optional<Schema.Int>;
167
+ }>>;
168
+ readonly context: Schema.optionalKey<Schema.Struct<{
169
+ readonly tokens: Schema.Int;
170
+ readonly window: Schema.NullOr<Schema.Int>;
171
+ }>>;
172
+ }>;
173
+ export declare const SessionFrameSchema: Schema.Codec<SessionFrame>;
174
+ /** Decode a durable command acceptance value at an RPC boundary. */
175
+ export declare const AcceptedSchema: Schema.Codec<Accepted>;
176
+ /** Parse one serialized extension status. */
177
+ export declare function parseExtensionStatus(value: string): ExtensionStatusV0;
178
+ /** Parse the serialized list of rostered extension statuses. */
179
+ export declare function parseExtensionStatuses(value: string): readonly ExtensionStatusV0[];
180
+ /** Parse one encoded extension command output; its contract decodes it. */
181
+ export declare function parseExtensionOutput(value: string): Json;
182
+ /** Parse one serialized command acceptance using Shiitake's public grammar. */
183
+ export declare function parseAccepted(value: string): Accepted;
184
+ /** Parse one serialized cancel outcome: accepted, or too late. */
185
+ export declare function parseCancelResult(value: string): CancelResult;
186
+ /** Parse one serialized fork result using Shiitake's public client grammar. */
187
+ export declare function parseForkedSession(value: string): ForkedSession;
188
+ /** Parse one serialized snapshot using Shiitake's public client grammar. */
189
+ export declare function parseSessionSnapshot(value: string): SessionSnapshot;
190
+ /** Parse one serialized frame using Shiitake's public client grammar. */
191
+ export declare function parseSessionFrame(value: string): SessionFrame;
192
+ /** Parse one serialized canonical Shiitake failure. */
193
+ export declare function parseShiitakeError(value: string): ShiitakeError;
194
+ /** Decode the existing bounded saved-conversation projection. */
195
+ export declare function parseSessionSummaryPage(value: string): SessionSummaryPage;
196
+ /** Decode whether the owner deleted an existing Session. */
197
+ export declare function parseDeletedSession(value: string): boolean;
198
+ /** Decode the fresh identity issued by the Agent owner. */
199
+ export declare function parseCreatedSession(value: string): string;
@@ -0,0 +1,271 @@
1
+ import { SessionAttentionListSchema } from "./session-attention.js";
2
+ import { PromptImageSchema } from "./internal/client-boundary.js";
3
+ import { SandboxFailureEventSchema } from "@fungi.computer/mycelium";
4
+ import * as Schema from "effect/Schema";
5
+ import { ShiitakeError, ShiitakeErrorWireSchema } from "./errors.js";
6
+ import { JsonValueSchema } from "./internal/json-value.js";
7
+ import { StoredPiMessageSchema, ExtensionAdmissionOriginSchema, } from "./internal/woodstock/index.js";
8
+ const ExtensionOriginSchema = ExtensionAdmissionOriginSchema.mapFields(({ extensionId, correlation }) => ({ extensionId, correlation }));
9
+ const SessionMessageSchema = Schema.Struct({
10
+ meta: Schema.optionalKey(JsonValueSchema),
11
+ origin: Schema.optionalKey(ExtensionOriginSchema),
12
+ id: Schema.String,
13
+ sequence: Schema.Int.check(Schema.isGreaterThan(0)),
14
+ commandId: Schema.NullOr(Schema.String),
15
+ value: StoredPiMessageSchema,
16
+ });
17
+ const SessionCompactionTriggerSchema = Schema.Literals([
18
+ "manual",
19
+ "threshold",
20
+ "overflow",
21
+ ]);
22
+ const SessionActivitySchema = Schema.Struct({
23
+ queue: Schema.Union([
24
+ Schema.Struct({ state: Schema.Literal("idle") }),
25
+ Schema.Struct({
26
+ state: Schema.Literal("queued"),
27
+ commandId: Schema.NonEmptyString,
28
+ runningWork: Schema.NullOr(Schema.Union([
29
+ Schema.Struct({
30
+ kind: Schema.Literal("session"),
31
+ sessionId: Schema.NonEmptyString,
32
+ commandId: Schema.NonEmptyString,
33
+ }),
34
+ Schema.Struct({
35
+ kind: Schema.Literal("host"),
36
+ lane: Schema.NonEmptyString,
37
+ jobId: Schema.NonEmptyString,
38
+ }),
39
+ ])),
40
+ }),
41
+ Schema.Struct({
42
+ state: Schema.Literal("running"),
43
+ commandId: Schema.NonEmptyString,
44
+ }),
45
+ ]),
46
+ cancellationRequested: Schema.Boolean,
47
+ retry: Schema.NullOr(Schema.Struct({
48
+ attempt: Schema.Int.check(Schema.isGreaterThan(0)),
49
+ maxAttempts: Schema.Int.check(Schema.isGreaterThan(0)),
50
+ delayMs: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)),
51
+ errorMessage: Schema.String,
52
+ scheduledAt: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)),
53
+ })),
54
+ activeTool: Schema.NullOr(Schema.String),
55
+ lastModelChoiceSequence: Schema.NullOr(Schema.Int.check(Schema.isGreaterThan(0))),
56
+ compaction: Schema.NullOr(Schema.Struct({ trigger: SessionCompactionTriggerSchema })),
57
+ });
58
+ const ExtensionRevisionSchema = Schema.String;
59
+ const ExtensionSlotSchema = Schema.Union([
60
+ Schema.Struct({
61
+ status: Schema.Literal("running"),
62
+ revision: ExtensionRevisionSchema,
63
+ value: JsonValueSchema,
64
+ catalog: Schema.optionalKey(JsonValueSchema),
65
+ }),
66
+ Schema.Struct({
67
+ status: Schema.Literal("stopped"),
68
+ revision: ExtensionRevisionSchema,
69
+ reason: Schema.String,
70
+ }),
71
+ ]);
72
+ const ExtensionSlotsSchema = Schema.Record(Schema.String, ExtensionSlotSchema);
73
+ const ExtensionStatusSchema = Schema.Struct({
74
+ id: Schema.String,
75
+ version: Schema.String,
76
+ revision: ExtensionRevisionSchema,
77
+ status: Schema.Literals(["running", "stopped"]),
78
+ reason: Schema.NullOr(Schema.String),
79
+ stoppedAt: Schema.NullOr(Schema.Number),
80
+ });
81
+ /** Existing terminal wire grammar, shared by exact host settlement facts. */
82
+ export const SessionTerminalSchema = Schema.Struct({
83
+ commandId: Schema.String,
84
+ outcome: Schema.Literals([
85
+ "completed",
86
+ "cancelled",
87
+ "failed",
88
+ "interrupted",
89
+ ]),
90
+ sequence: Schema.Int.check(Schema.isGreaterThan(0)),
91
+ diagnostic: Schema.NullOr(Schema.String),
92
+ meta: Schema.optionalKey(JsonValueSchema),
93
+ });
94
+ const SessionCompactionMarkerSchema = Schema.Struct({
95
+ id: Schema.String,
96
+ sequence: Schema.Int.check(Schema.isGreaterThan(0)),
97
+ at: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)),
98
+ tokensBefore: Schema.Number,
99
+ tokensAfter: Schema.NullOr(Schema.Number),
100
+ trigger: Schema.NullOr(SessionCompactionTriggerSchema),
101
+ });
102
+ const SessionCompactionNoticeSchema = Schema.Struct({
103
+ id: Schema.String,
104
+ sequence: Schema.Int.check(Schema.isGreaterThan(0)),
105
+ at: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)),
106
+ trigger: SessionCompactionTriggerSchema,
107
+ result: Schema.Literals(["nothing_to_compact", "failed"]),
108
+ diagnostic: Schema.NullOr(Schema.String),
109
+ });
110
+ const SessionProgressSchema = Schema.Struct({
111
+ messageId: Schema.String,
112
+ revision: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)),
113
+ text: Schema.String,
114
+ thinking: Schema.String,
115
+ textTruncated: Schema.Boolean,
116
+ thinkingTruncated: Schema.Boolean,
117
+ });
118
+ const SessionPendingPromptsSchema = Schema.Struct({
119
+ total: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)),
120
+ prompts: Schema.Array(Schema.Struct({
121
+ commandId: Schema.String,
122
+ meta: Schema.optionalKey(JsonValueSchema),
123
+ origin: Schema.optionalKey(ExtensionOriginSchema),
124
+ text: Schema.String,
125
+ images: Schema.optionalKey(Schema.Array(PromptImageSchema)),
126
+ delivery: Schema.Literals(["steer", "followUp"]),
127
+ })),
128
+ hasMore: Schema.Boolean,
129
+ });
130
+ const SessionContextSchema = Schema.Struct({
131
+ tokens: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)),
132
+ window: Schema.NullOr(Schema.Int.check(Schema.isGreaterThan(0))),
133
+ });
134
+ export const SessionSnapshotSchema = Schema.Struct({
135
+ sessionId: Schema.String,
136
+ cursor: Schema.NullOr(Schema.String),
137
+ hasMore: Schema.Boolean,
138
+ oldestCursor: Schema.optionalKey(Schema.NullOr(Schema.String)),
139
+ messages: Schema.Array(SessionMessageSchema),
140
+ terminals: Schema.Array(SessionTerminalSchema),
141
+ sandboxFailures: Schema.optionalKey(Schema.Array(SandboxFailureEventSchema)),
142
+ compactions: Schema.optionalKey(Schema.Array(SessionCompactionMarkerSchema)),
143
+ compactionNotices: Schema.optionalKey(Schema.Array(SessionCompactionNoticeSchema)),
144
+ pending: SessionPendingPromptsSchema,
145
+ activity: SessionActivitySchema,
146
+ progress: Schema.NullOr(SessionProgressSchema),
147
+ extensions: ExtensionSlotsSchema,
148
+ attention: SessionAttentionListSchema,
149
+ context: Schema.optionalKey(SessionContextSchema),
150
+ });
151
+ export const SessionFrameSchema = Schema.Union([
152
+ Schema.Struct({
153
+ kind: Schema.Literal("update"),
154
+ delivery: Schema.Literals(["replay", "live"]),
155
+ cursor: Schema.NullOr(Schema.String),
156
+ messages: Schema.Array(SessionMessageSchema),
157
+ terminals: Schema.Array(SessionTerminalSchema),
158
+ sandboxFailures: Schema.optionalKey(Schema.Array(SandboxFailureEventSchema)),
159
+ compactions: Schema.optionalKey(Schema.Array(SessionCompactionMarkerSchema)),
160
+ compactionNotices: Schema.optionalKey(Schema.Array(SessionCompactionNoticeSchema)),
161
+ pending: SessionPendingPromptsSchema,
162
+ activity: SessionActivitySchema,
163
+ extensions: ExtensionSlotsSchema,
164
+ attention: SessionAttentionListSchema,
165
+ context: Schema.optionalKey(SessionContextSchema),
166
+ }),
167
+ Schema.Struct({
168
+ kind: Schema.Literal("progress"),
169
+ progress: SessionProgressSchema,
170
+ activity: SessionActivitySchema,
171
+ }),
172
+ Schema.Struct({
173
+ kind: Schema.Literal("reset"),
174
+ reason: Schema.Literal("history_unavailable"),
175
+ cursor: Schema.NullOr(Schema.String),
176
+ baseline: SessionSnapshotSchema,
177
+ }),
178
+ ]);
179
+ /** Decode a durable command acceptance value at an RPC boundary. */
180
+ export const AcceptedSchema = Schema.Struct({
181
+ status: Schema.Literal("accepted"),
182
+ commandId: Schema.String,
183
+ });
184
+ const CancelResultSchema = Schema.Union([
185
+ AcceptedSchema,
186
+ Schema.Struct({
187
+ status: Schema.Literal("too_late"),
188
+ commandId: Schema.String,
189
+ }),
190
+ ]);
191
+ const ForkedSessionSchema = Schema.Struct({
192
+ sessionId: Schema.String,
193
+ });
194
+ const decodeSnapshot = Schema.decodeUnknownSync(Schema.fromJsonString(SessionSnapshotSchema), { onExcessProperty: "error" });
195
+ const decodeFrame = Schema.decodeUnknownSync(Schema.fromJsonString(SessionFrameSchema), { onExcessProperty: "error" });
196
+ const decodeAccepted = Schema.decodeUnknownSync(Schema.fromJsonString(AcceptedSchema));
197
+ const decodeCancelResult = Schema.decodeUnknownSync(Schema.fromJsonString(CancelResultSchema));
198
+ const decodeForkedSession = Schema.decodeUnknownSync(Schema.fromJsonString(ForkedSessionSchema));
199
+ const decodeError = Schema.decodeUnknownSync(Schema.fromJsonString(ShiitakeErrorWireSchema));
200
+ const decodeExtensionStatus = Schema.decodeUnknownSync(Schema.fromJsonString(ExtensionStatusSchema));
201
+ const decodeExtensionStatuses = Schema.decodeUnknownSync(Schema.fromJsonString(Schema.Array(ExtensionStatusSchema)));
202
+ const decodeJsonValue = Schema.decodeUnknownSync(Schema.fromJsonString(JsonValueSchema));
203
+ /** Parse one serialized extension status. */
204
+ export function parseExtensionStatus(value) {
205
+ return decodeExtensionStatus(value);
206
+ }
207
+ /** Parse the serialized list of rostered extension statuses. */
208
+ export function parseExtensionStatuses(value) {
209
+ return decodeExtensionStatuses(value);
210
+ }
211
+ /** Parse one encoded extension command output; its contract decodes it. */
212
+ export function parseExtensionOutput(value) {
213
+ return decodeJsonValue(value);
214
+ }
215
+ /** Parse one serialized command acceptance using Shiitake's public grammar. */
216
+ export function parseAccepted(value) {
217
+ return decodeAccepted(value);
218
+ }
219
+ /** Parse one serialized cancel outcome: accepted, or too late. */
220
+ export function parseCancelResult(value) {
221
+ return decodeCancelResult(value);
222
+ }
223
+ /** Parse one serialized fork result using Shiitake's public client grammar. */
224
+ export function parseForkedSession(value) {
225
+ return decodeForkedSession(value);
226
+ }
227
+ /** Parse one serialized snapshot using Shiitake's public client grammar. */
228
+ export function parseSessionSnapshot(value) {
229
+ return decodeSnapshot(value);
230
+ }
231
+ /** Parse one serialized frame using Shiitake's public client grammar. */
232
+ export function parseSessionFrame(value) {
233
+ return decodeFrame(value);
234
+ }
235
+ /** Parse one serialized canonical Shiitake failure. */
236
+ export function parseShiitakeError(value) {
237
+ const failure = decodeError(value);
238
+ return new ShiitakeError(failure.boundary, failure.cause, failure.message, failure.requestId);
239
+ }
240
+ const decodeSessionSummaryPage = Schema.decodeUnknownSync(Schema.fromJsonString(Schema.Struct({
241
+ sessions: Schema.Array(Schema.Union([
242
+ Schema.Struct({
243
+ sessionId: Schema.NonEmptyString,
244
+ createdAt: Schema.Number,
245
+ lastActivityAt: Schema.Number,
246
+ settledAt: Schema.optionalKey(Schema.Number),
247
+ title: Schema.String,
248
+ state: Schema.Literals(["needs_you", "running", "errored", "done"]),
249
+ }),
250
+ Schema.Struct({
251
+ sessionId: Schema.NonEmptyString,
252
+ state: Schema.Literal("unavailable"),
253
+ }),
254
+ ])),
255
+ next: Schema.optional(Schema.NonEmptyString),
256
+ })));
257
+ /** Decode the existing bounded saved-conversation projection. */
258
+ export function parseSessionSummaryPage(value) {
259
+ const page = decodeSessionSummaryPage(value);
260
+ return { sessions: page.sessions, next: page.next };
261
+ }
262
+ const decodeCreatedSession = Schema.decodeUnknownSync(Schema.fromJsonString(Schema.Struct({ sessionId: Schema.NonEmptyString })));
263
+ const decodeDeletedSession = Schema.decodeUnknownSync(Schema.fromJsonString(Schema.Struct({ deleted: Schema.Boolean })));
264
+ /** Decode whether the owner deleted an existing Session. */
265
+ export function parseDeletedSession(value) {
266
+ return decodeDeletedSession(value).deleted;
267
+ }
268
+ /** Decode the fresh identity issued by the Agent owner. */
269
+ export function parseCreatedSession(value) {
270
+ return decodeCreatedSession(value).sessionId;
271
+ }