@stitchmux/client 0.0.0-stage → 0.96.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.
- package/LICENSE +21 -0
- package/README.md +45 -2
- package/dist/chunk-szdg2ww3.js +714 -0
- package/dist/index.js +4070 -0
- package/dist/monitoring.js +279 -0
- package/native-stream.json +8 -0
- package/package.json +36 -4
- package/types/src/agent/claude/native/commandSchema.d.ts +14 -0
- package/types/src/agent/custom/config.d.ts +159 -0
- package/types/src/agent/custom/endpoint.d.ts +26 -0
- package/types/src/agent/transcript/messageSchema.d.ts +153 -0
- package/types/src/attachments/reference.d.ts +56 -0
- package/types/src/attachments/schema.d.ts +512 -0
- package/types/src/chat/communicationAuthorizationSchema.d.ts +77 -0
- package/types/src/chat/communicationReceiptSchema.d.ts +82 -0
- package/types/src/chat/feedSchema.d.ts +641 -0
- package/types/src/chat/holdKind.d.ts +26 -0
- package/types/src/chat/identity.d.ts +55 -0
- package/types/src/chat/identitySchema.d.ts +121 -0
- package/types/src/chat/letterRequestSchema.d.ts +35 -0
- package/types/src/chat/messageOperationSchema.d.ts +277 -0
- package/types/src/chat/messageSchema.d.ts +284 -0
- package/types/src/chat/originSchema.d.ts +67 -0
- package/types/src/chat/sentLetterSchema.d.ts +79 -0
- package/types/src/client.d.ts +16 -0
- package/types/src/config/claudeProfileSchema.d.ts +22 -0
- package/types/src/config/launchSchema.d.ts +136 -0
- package/types/src/config/location.d.ts +6 -0
- package/types/src/config/machineSchema.d.ts +320 -0
- package/types/src/config/modelSelectionFlags.d.ts +4 -0
- package/types/src/config/paths.d.ts +87 -0
- package/types/src/config/remoteTransport.d.ts +12 -0
- package/types/src/content/schema.d.ts +312 -0
- package/types/src/content/toolSchema.d.ts +36 -0
- package/types/src/context/corpusSearchSchema.d.ts +578 -0
- package/types/src/context/exactMessageSchema.d.ts +54 -0
- package/types/src/context/messageSenderSchema.d.ts +14 -0
- package/types/src/context/schema.d.ts +176 -0
- package/types/src/context/searchFrames.d.ts +225 -0
- package/types/src/context/searchRequestSchema.d.ts +47 -0
- package/types/src/context/transcriptJsonSchema.d.ts +210 -0
- package/types/src/control/schema/context.d.ts +188 -0
- package/types/src/control/schema/contract.d.ts +7142 -0
- package/types/src/control/schema/core.d.ts +722 -0
- package/types/src/control/schema/directory.d.ts +34 -0
- package/types/src/control/schema/eventsContract.d.ts +1423 -0
- package/types/src/control/schema/externalList.d.ts +96 -0
- package/types/src/control/schema/message.d.ts +280 -0
- package/types/src/control/schema/model.d.ts +128 -0
- package/types/src/control/schema/native.d.ts +664 -0
- package/types/src/control/schema/nativeStreamContract.d.ts +155 -0
- package/types/src/control/schema/performance.d.ts +85 -0
- package/types/src/control/schema/public.d.ts +48 -0
- package/types/src/control/schema/reading.d.ts +24 -0
- package/types/src/control/schema/refusals.d.ts +433 -0
- package/types/src/control/schema/runtimeOps.d.ts +724 -0
- package/types/src/control/schema/searchContract.d.ts +258 -0
- package/types/src/control/schema/selection.d.ts +124 -0
- package/types/src/control/schema/session.d.ts +272 -0
- package/types/src/control/schema/terminalPrompt.d.ts +102 -0
- package/types/src/control/transport/boundary.d.ts +7137 -0
- package/types/src/control/transport/client.d.ts +10838 -0
- package/types/src/control/transport/connection.d.ts +13 -0
- package/types/src/control/transport/socketPath.d.ts +3 -0
- package/types/src/control-client.d.ts +9 -0
- package/types/src/delegation/applicationSchema.d.ts +132 -0
- package/types/src/delegation/schema.d.ts +267 -0
- package/types/src/events/schema.d.ts +155 -0
- package/types/src/external/contentSchema.d.ts +145 -0
- package/types/src/external/messageSchema.d.ts +131 -0
- package/types/src/external/residentFrames.d.ts +130 -0
- package/types/src/external/residentSchema.d.ts +144 -0
- package/types/src/external/sessionSchema.d.ts +427 -0
- package/types/src/external/turnSchema.d.ts +55 -0
- package/types/src/fleet/fleetSchema.d.ts +937 -0
- package/types/src/inventory/listSchema.d.ts +442 -0
- package/types/src/monitoring/nativeFile.d.ts +7 -0
- package/types/src/monitoring/nativeRead.d.ts +14 -0
- package/types/src/monitoring/performanceSchema.d.ts +28 -0
- package/types/src/monitoring/schema.d.ts +410 -0
- package/types/src/monitoring/validate.d.ts +5 -0
- package/types/src/monitoring-reader.d.ts +4 -0
- package/types/src/policy/reference.d.ts +93 -0
- package/types/src/policy/runtimeProfile.d.ts +24 -0
- package/types/src/policy/schema.d.ts +177 -0
- package/types/src/runtime/capabilities.d.ts +124 -0
- package/types/src/runtime/modes.d.ts +47 -0
- package/types/src/runtime/permissionScope.d.ts +22 -0
- package/types/src/runtime/planLimitsSchema.d.ts +55 -0
- package/types/src/runtime/projectionSchema.d.ts +539 -0
- package/types/src/runtime/rewindSchema.d.ts +16 -0
- package/types/src/runtime/selectionSchema.d.ts +158 -0
- package/types/src/runtime/workloadContract.d.ts +55 -0
- package/types/src/session/boundary.d.ts +43 -0
- package/types/src/session/identitySchema.d.ts +353 -0
- package/types/src/session/schema.d.ts +341 -0
- package/types/src/session/sleep/schema.d.ts +283 -0
- package/types/src/steering/schema.d.ts +197 -0
- package/types/src/types.d.ts +48 -0
- package/types/src/usage/schema.d.ts +978 -0
- package/types/src/util/home.d.ts +9 -0
- package/types/src/util/preview.d.ts +13 -0
- package/types/src/util/version.d.ts +3 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,4070 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
SESSION_NAME_RE,
|
|
4
|
+
RC_PREFIX_RE,
|
|
5
|
+
AgentKindSchema,
|
|
6
|
+
ManagedPeerSchema,
|
|
7
|
+
ChatPrincipalSchema2,
|
|
8
|
+
ChatTargetSchema2,
|
|
9
|
+
PolicyIdSchema,
|
|
10
|
+
PolicyDigestSchema,
|
|
11
|
+
ApplicationPolicyReferenceSchema2,
|
|
12
|
+
ApplicationPolicyMetadataSchema2,
|
|
13
|
+
ApplicationPolicyEvidenceSchema2,
|
|
14
|
+
NativeModelSelectionSchema,
|
|
15
|
+
NativeTurnOptionsSchema2,
|
|
16
|
+
AcceptedTurnOptionsSchema2,
|
|
17
|
+
NativeSelectionEvidenceSchema2,
|
|
18
|
+
MAX_DECLARED_CUSTOM_TOOLS,
|
|
19
|
+
NativeSessionSchema,
|
|
20
|
+
LaunchRecipeReferenceSchema2,
|
|
21
|
+
ModelSelectionSchema2,
|
|
22
|
+
LaunchRecipeMetadataSchema2,
|
|
23
|
+
MessageAttributionSchema2,
|
|
24
|
+
MessageOriginSchema2,
|
|
25
|
+
NotificationAudienceSchema2,
|
|
26
|
+
ApplicationParentSchema2,
|
|
27
|
+
ApplicationBindingSchema2,
|
|
28
|
+
ApplicationDelegationGrantSchema2,
|
|
29
|
+
ApplicationAuthorityOpenSchema2,
|
|
30
|
+
ApplicationAuthoritySelectorSchema2,
|
|
31
|
+
ApplicationAuthorityUpdateSchema2,
|
|
32
|
+
ApplicationAuthoritySchema2,
|
|
33
|
+
ApplicationAuthorityCapabilitiesSchema2,
|
|
34
|
+
DelegatedPolicySchema2,
|
|
35
|
+
DelegationRequestSchema2,
|
|
36
|
+
DelegationSchema2,
|
|
37
|
+
DelegationEvidenceSchema2,
|
|
38
|
+
DelegationCancelSchema,
|
|
39
|
+
DelegationCancelReceiptSchema,
|
|
40
|
+
ProfileNameSchema,
|
|
41
|
+
machineConfigPath,
|
|
42
|
+
resolveMonitoringLocation,
|
|
43
|
+
VERSION
|
|
44
|
+
} from "./chunk-szdg2ww3.js";
|
|
45
|
+
|
|
46
|
+
// src/control/schema/core.ts
|
|
47
|
+
import { z as z6 } from "zod";
|
|
48
|
+
|
|
49
|
+
// src/policy/runtimeProfile.ts
|
|
50
|
+
import { z } from "zod";
|
|
51
|
+
var RuntimeAppliedProfileSchema = z.object({
|
|
52
|
+
runtime: z.literal("custom"),
|
|
53
|
+
turnId: z.string().min(1).max(256),
|
|
54
|
+
observedAt: z.iso.datetime(),
|
|
55
|
+
recipeDigest: PolicyDigestSchema,
|
|
56
|
+
model: NativeModelSelectionSchema,
|
|
57
|
+
providerLabel: z.string().max(64).nullable().default(null),
|
|
58
|
+
tools: z.array(PolicyIdSchema).max(MAX_DECLARED_CUSTOM_TOOLS),
|
|
59
|
+
resources: z.array(z.object({
|
|
60
|
+
id: PolicyIdSchema,
|
|
61
|
+
digest: PolicyDigestSchema,
|
|
62
|
+
kind: z.enum(["instruction", "skill", "resource"])
|
|
63
|
+
}).strict()).max(32)
|
|
64
|
+
}).strict();
|
|
65
|
+
|
|
66
|
+
// src/runtime/capabilities.ts
|
|
67
|
+
import { z as z2 } from "zod";
|
|
68
|
+
var RuntimeCapabilitiesSchema = z2.object({
|
|
69
|
+
runtime: AgentKindSchema,
|
|
70
|
+
structured: z2.boolean(),
|
|
71
|
+
creation: z2.object({
|
|
72
|
+
noInference: z2.boolean(),
|
|
73
|
+
inference: z2.enum(["required", "not-guaranteed", "deferred"]),
|
|
74
|
+
requirements: z2.array(z2.enum(["delegation", "explicit-model"])).max(2).optional(),
|
|
75
|
+
reason: z2.enum([
|
|
76
|
+
"native-rollout-requires-bootstrap",
|
|
77
|
+
"provider-initialization-not-certified",
|
|
78
|
+
"delegated-input-only"
|
|
79
|
+
])
|
|
80
|
+
}).strict(),
|
|
81
|
+
delegation: z2.boolean().optional(),
|
|
82
|
+
sleep: z2.boolean().optional(),
|
|
83
|
+
modelCatalog: z2.boolean(),
|
|
84
|
+
modelSelection: z2.boolean(),
|
|
85
|
+
approval: z2.boolean(),
|
|
86
|
+
input: z2.boolean(),
|
|
87
|
+
nativeStream: z2.boolean(),
|
|
88
|
+
interrupt: z2.boolean(),
|
|
89
|
+
resume: z2.boolean(),
|
|
90
|
+
imageInput: z2.boolean(),
|
|
91
|
+
selectionDefaults: z2.boolean(),
|
|
92
|
+
turnOptions: z2.boolean(),
|
|
93
|
+
turnSteering: z2.boolean(),
|
|
94
|
+
history: z2.boolean(),
|
|
95
|
+
fork: z2.boolean(),
|
|
96
|
+
compaction: z2.boolean(),
|
|
97
|
+
rollback: z2.boolean(),
|
|
98
|
+
applicationPolicy: z2.boolean(),
|
|
99
|
+
commandCatalog: z2.boolean(),
|
|
100
|
+
permissionModes: z2.boolean(),
|
|
101
|
+
fileCheckpoints: z2.boolean(),
|
|
102
|
+
mcpControl: z2.boolean()
|
|
103
|
+
}).strict();
|
|
104
|
+
var RuntimeCatalogInputSchema = z2.object({}).strict();
|
|
105
|
+
var RuntimeCatalogSchema = z2.object({
|
|
106
|
+
runtimes: z2.array(z2.object({
|
|
107
|
+
runtime: AgentKindSchema,
|
|
108
|
+
mode: z2.enum(["tui", "app-server", "native"]),
|
|
109
|
+
availability: z2.enum(["configured", "unavailable"]),
|
|
110
|
+
reason: z2.string().nullable(),
|
|
111
|
+
capabilities: RuntimeCapabilitiesSchema
|
|
112
|
+
}).strict()).max(8)
|
|
113
|
+
}).strict();
|
|
114
|
+
var uncertifiedCreation = {
|
|
115
|
+
noInference: false,
|
|
116
|
+
inference: "not-guaranteed",
|
|
117
|
+
reason: "provider-initialization-not-certified"
|
|
118
|
+
};
|
|
119
|
+
var unsupportedNativeOperations = {
|
|
120
|
+
creation: uncertifiedCreation,
|
|
121
|
+
commandCatalog: false,
|
|
122
|
+
permissionModes: false,
|
|
123
|
+
fileCheckpoints: false,
|
|
124
|
+
mcpControl: false,
|
|
125
|
+
imageInput: false,
|
|
126
|
+
selectionDefaults: false,
|
|
127
|
+
turnOptions: false,
|
|
128
|
+
turnSteering: false,
|
|
129
|
+
history: false,
|
|
130
|
+
fork: false,
|
|
131
|
+
compaction: false,
|
|
132
|
+
rollback: false,
|
|
133
|
+
applicationPolicy: false
|
|
134
|
+
};
|
|
135
|
+
var nativeOperations = {
|
|
136
|
+
...unsupportedNativeOperations,
|
|
137
|
+
imageInput: true,
|
|
138
|
+
selectionDefaults: true,
|
|
139
|
+
turnOptions: true,
|
|
140
|
+
history: true,
|
|
141
|
+
fork: true,
|
|
142
|
+
compaction: true,
|
|
143
|
+
applicationPolicy: true
|
|
144
|
+
};
|
|
145
|
+
var capabilities = {
|
|
146
|
+
claude: {
|
|
147
|
+
runtime: "claude",
|
|
148
|
+
structured: true,
|
|
149
|
+
modelCatalog: true,
|
|
150
|
+
modelSelection: true,
|
|
151
|
+
approval: true,
|
|
152
|
+
input: true,
|
|
153
|
+
nativeStream: true,
|
|
154
|
+
interrupt: true,
|
|
155
|
+
resume: true,
|
|
156
|
+
...unsupportedNativeOperations,
|
|
157
|
+
creation: {
|
|
158
|
+
noInference: true,
|
|
159
|
+
inference: "deferred",
|
|
160
|
+
reason: "delegated-input-only",
|
|
161
|
+
requirements: ["delegation", "explicit-model"]
|
|
162
|
+
},
|
|
163
|
+
selectionDefaults: true,
|
|
164
|
+
turnOptions: true,
|
|
165
|
+
imageInput: true,
|
|
166
|
+
commandCatalog: true,
|
|
167
|
+
permissionModes: true,
|
|
168
|
+
fileCheckpoints: true,
|
|
169
|
+
mcpControl: true,
|
|
170
|
+
history: true,
|
|
171
|
+
fork: true,
|
|
172
|
+
compaction: true
|
|
173
|
+
},
|
|
174
|
+
codex: {
|
|
175
|
+
runtime: "codex",
|
|
176
|
+
structured: true,
|
|
177
|
+
modelCatalog: true,
|
|
178
|
+
modelSelection: true,
|
|
179
|
+
approval: true,
|
|
180
|
+
input: true,
|
|
181
|
+
nativeStream: true,
|
|
182
|
+
interrupt: true,
|
|
183
|
+
resume: true,
|
|
184
|
+
...nativeOperations,
|
|
185
|
+
turnSteering: true,
|
|
186
|
+
creation: {
|
|
187
|
+
noInference: false,
|
|
188
|
+
inference: "required",
|
|
189
|
+
reason: "native-rollout-requires-bootstrap"
|
|
190
|
+
}
|
|
191
|
+
},
|
|
192
|
+
opencode: {
|
|
193
|
+
runtime: "opencode",
|
|
194
|
+
structured: true,
|
|
195
|
+
modelCatalog: true,
|
|
196
|
+
modelSelection: true,
|
|
197
|
+
approval: true,
|
|
198
|
+
input: true,
|
|
199
|
+
nativeStream: true,
|
|
200
|
+
interrupt: true,
|
|
201
|
+
resume: true,
|
|
202
|
+
...nativeOperations
|
|
203
|
+
},
|
|
204
|
+
custom: {
|
|
205
|
+
runtime: "custom",
|
|
206
|
+
structured: true,
|
|
207
|
+
modelCatalog: true,
|
|
208
|
+
modelSelection: true,
|
|
209
|
+
approval: true,
|
|
210
|
+
input: false,
|
|
211
|
+
nativeStream: true,
|
|
212
|
+
interrupt: true,
|
|
213
|
+
resume: true,
|
|
214
|
+
...unsupportedNativeOperations,
|
|
215
|
+
selectionDefaults: true,
|
|
216
|
+
turnOptions: true,
|
|
217
|
+
history: true,
|
|
218
|
+
imageInput: true
|
|
219
|
+
},
|
|
220
|
+
antigravity: {
|
|
221
|
+
runtime: "antigravity",
|
|
222
|
+
structured: true,
|
|
223
|
+
modelCatalog: true,
|
|
224
|
+
modelSelection: true,
|
|
225
|
+
approval: true,
|
|
226
|
+
input: false,
|
|
227
|
+
nativeStream: true,
|
|
228
|
+
interrupt: true,
|
|
229
|
+
resume: true,
|
|
230
|
+
...unsupportedNativeOperations,
|
|
231
|
+
selectionDefaults: true,
|
|
232
|
+
turnOptions: true,
|
|
233
|
+
imageInput: true,
|
|
234
|
+
permissionModes: true,
|
|
235
|
+
history: true
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
// src/runtime/projectionSchema.ts
|
|
240
|
+
import { z as z5 } from "zod";
|
|
241
|
+
|
|
242
|
+
// src/runtime/permissionScope.ts
|
|
243
|
+
import { z as z3 } from "zod";
|
|
244
|
+
var Resource = z3.string().min(1).max(1024).regex(/^[^\p{Cc}\p{Cf}]+$/u).refine((value) => new TextEncoder().encode(value).byteLength <= 1024, "Permission pattern exceeds byte budget");
|
|
245
|
+
var Resources = z3.object({
|
|
246
|
+
patterns: z3.array(Resource).max(8),
|
|
247
|
+
omitted: z3.number().int().nonnegative(),
|
|
248
|
+
complete: z3.boolean()
|
|
249
|
+
}).strict();
|
|
250
|
+
var PermissionScopeSchema = z3.object({
|
|
251
|
+
operation: z3.string().min(1).max(128),
|
|
252
|
+
kind: z3.literal("filesystem-patterns"),
|
|
253
|
+
requested: Resources,
|
|
254
|
+
session: Resources
|
|
255
|
+
}).strict();
|
|
256
|
+
|
|
257
|
+
// src/runtime/planLimitsSchema.ts
|
|
258
|
+
import { z as z4 } from "zod";
|
|
259
|
+
var PlanWindowSchema = z4.object({
|
|
260
|
+
key: z4.string().min(1).max(64),
|
|
261
|
+
label: z4.string().min(1).max(128).nullable(),
|
|
262
|
+
percent: z4.number().min(0).max(100),
|
|
263
|
+
windowMinutes: z4.number().int().positive().nullable(),
|
|
264
|
+
resetsAt: z4.iso.datetime().nullable(),
|
|
265
|
+
scope: z4.string().min(1).max(128).nullable()
|
|
266
|
+
}).strict();
|
|
267
|
+
var PlanLimitsSchema = z4.object({
|
|
268
|
+
answer: z4.enum(["known", "no-plan-limit", "unpublished"]),
|
|
269
|
+
plan: z4.string().min(1).max(64).nullable(),
|
|
270
|
+
windows: z4.array(PlanWindowSchema).max(32),
|
|
271
|
+
observedAt: z4.iso.datetime(),
|
|
272
|
+
source: z4.enum(["native", "statusline", "probe"]).default("native"),
|
|
273
|
+
error: z4.string().max(160).nullable().default(null)
|
|
274
|
+
}).strict();
|
|
275
|
+
|
|
276
|
+
// src/runtime/projectionSchema.ts
|
|
277
|
+
var NATIVE_RUNTIME_MAX_BYTES = 128 * 1024;
|
|
278
|
+
var NATIVE_RUNTIME_MAX_EVENTS = 128;
|
|
279
|
+
var NATIVE_RUNTIME_MAX_NATIVE_ITEMS = 128;
|
|
280
|
+
var NativeStateSchema = z5.enum([
|
|
281
|
+
"working",
|
|
282
|
+
"idle",
|
|
283
|
+
"waiting-approval",
|
|
284
|
+
"waiting-input",
|
|
285
|
+
"unknown"
|
|
286
|
+
]);
|
|
287
|
+
var NativeTurnSchema = z5.object({
|
|
288
|
+
id: z5.string().min(1).max(256),
|
|
289
|
+
status: z5.enum(["inProgress", "completed", "interrupted", "failed"]),
|
|
290
|
+
startedAt: z5.iso.datetime().nullable()
|
|
291
|
+
}).strict();
|
|
292
|
+
var NativeEventSchema = z5.object({
|
|
293
|
+
sequence: z5.number().int().positive(),
|
|
294
|
+
at: z5.iso.datetime(),
|
|
295
|
+
kind: z5.enum(["state", "turn-start", "turn-end", "unavailable"]),
|
|
296
|
+
state: NativeStateSchema,
|
|
297
|
+
turn: NativeTurnSchema.nullable()
|
|
298
|
+
}).strict();
|
|
299
|
+
var NativeUsageSchema = z5.object({
|
|
300
|
+
totalTokens: z5.number().int().nonnegative().nullable(),
|
|
301
|
+
inputTokens: z5.number().int().nonnegative().nullable(),
|
|
302
|
+
cachedInputTokens: z5.number().int().nonnegative().nullable(),
|
|
303
|
+
outputTokens: z5.number().int().nonnegative().nullable(),
|
|
304
|
+
reasoningOutputTokens: z5.number().int().nonnegative().nullable()
|
|
305
|
+
}).strict();
|
|
306
|
+
var NativeItemSchema = z5.object({
|
|
307
|
+
sequence: z5.number().int().positive(),
|
|
308
|
+
at: z5.iso.datetime(),
|
|
309
|
+
kind: z5.enum([
|
|
310
|
+
"user",
|
|
311
|
+
"assistant",
|
|
312
|
+
"reasoning",
|
|
313
|
+
"tool",
|
|
314
|
+
"approval",
|
|
315
|
+
"input",
|
|
316
|
+
"usage",
|
|
317
|
+
"terminal"
|
|
318
|
+
]),
|
|
319
|
+
stage: z5.enum(["started", "completed", "updated", "requested", "submitted", "resolved"]),
|
|
320
|
+
nativeId: z5.string().min(1).max(256),
|
|
321
|
+
turnId: z5.string().min(1).max(256).nullable(),
|
|
322
|
+
requestId: z5.string().min(1).max(256).nullable(),
|
|
323
|
+
status: z5.string().max(64).nullable(),
|
|
324
|
+
text: z5.string().max(8192).nullable(),
|
|
325
|
+
tool: z5.string().max(128).nullable(),
|
|
326
|
+
usage: NativeUsageSchema.nullable()
|
|
327
|
+
}).strict();
|
|
328
|
+
var NativeQuestionSchema = z5.object({
|
|
329
|
+
id: z5.string().min(1).max(256),
|
|
330
|
+
header: z5.string().max(256),
|
|
331
|
+
question: z5.string().max(2048),
|
|
332
|
+
isOther: z5.boolean(),
|
|
333
|
+
isSecret: z5.boolean(),
|
|
334
|
+
options: z5.array(z5.object({
|
|
335
|
+
label: z5.string().max(256),
|
|
336
|
+
description: z5.string().max(1024)
|
|
337
|
+
}).strict()).max(32).nullable(),
|
|
338
|
+
multiple: z5.boolean().optional()
|
|
339
|
+
}).strict();
|
|
340
|
+
var NativePendingRequestSchema = z5.object({
|
|
341
|
+
requestId: z5.string().min(1).max(256),
|
|
342
|
+
rpcId: z5.union([z5.number(), z5.string()]),
|
|
343
|
+
kind: z5.enum(["approval", "input"]),
|
|
344
|
+
approvalKind: z5.enum(["command", "file", "tool"]).nullable(),
|
|
345
|
+
turnId: z5.string().min(1).max(256),
|
|
346
|
+
itemId: z5.string().min(1).max(256),
|
|
347
|
+
reason: z5.string().max(2048).nullable(),
|
|
348
|
+
scope: PermissionScopeSchema.nullable().default(null),
|
|
349
|
+
decisions: z5.array(z5.enum(["accept", "acceptForSession", "decline", "cancel"])).max(4),
|
|
350
|
+
questions: z5.array(NativeQuestionSchema).max(4),
|
|
351
|
+
requestedAt: z5.iso.datetime()
|
|
352
|
+
}).strict();
|
|
353
|
+
var PermissionModeSchema = z5.enum(["default", "plan", "acceptEdits", "bypassPermissions"]);
|
|
354
|
+
var NativeContextUsageSchema = z5.object({
|
|
355
|
+
usedTokens: z5.number().int().nonnegative(),
|
|
356
|
+
limitTokens: z5.number().int().positive(),
|
|
357
|
+
rawLimitTokens: z5.number().int().positive(),
|
|
358
|
+
percent: z5.number().min(0).max(100),
|
|
359
|
+
window: z5.enum(["model-limit", "compaction-window"]),
|
|
360
|
+
observedAt: z5.iso.datetime()
|
|
361
|
+
}).strict();
|
|
362
|
+
var NativeAccountSchema = z5.object({
|
|
363
|
+
label: z5.string().min(1).max(256).nullable(),
|
|
364
|
+
organization: z5.string().max(256).nullable(),
|
|
365
|
+
subscription: z5.string().max(128).nullable(),
|
|
366
|
+
provider: z5.string().max(64).nullable()
|
|
367
|
+
}).strict();
|
|
368
|
+
var NativeSpendSchema = z5.object({ totalCostUsd: z5.number().nonnegative().nullable(), observedAt: z5.iso.datetime() }).strict();
|
|
369
|
+
var NativeMcpServerSchema = z5.object({
|
|
370
|
+
name: z5.string().min(1).max(128),
|
|
371
|
+
status: z5.enum(["connected", "failed", "needs-auth", "pending", "disabled", "unknown"]),
|
|
372
|
+
scope: z5.string().max(64).nullable(),
|
|
373
|
+
tools: z5.number().int().nonnegative().nullable(),
|
|
374
|
+
error: z5.string().max(512).nullable()
|
|
375
|
+
}).strict();
|
|
376
|
+
var NativeSnapshotSchema = z5.object({
|
|
377
|
+
protocol: z5.literal(1),
|
|
378
|
+
provider: z5.enum(["codex", "opencode", "custom", "claude", "antigravity"]),
|
|
379
|
+
machine: z5.string().min(1).max(128),
|
|
380
|
+
session: z5.string().min(1).max(256),
|
|
381
|
+
threadId: z5.uuid(),
|
|
382
|
+
generation: z5.uuid(),
|
|
383
|
+
sequence: z5.number().int().nonnegative(),
|
|
384
|
+
pid: z5.number().int().positive(),
|
|
385
|
+
providerPid: z5.number().int().positive(),
|
|
386
|
+
version: z5.string().max(64),
|
|
387
|
+
connected: z5.boolean(),
|
|
388
|
+
state: NativeStateSchema,
|
|
389
|
+
reason: z5.string().max(256).nullable(),
|
|
390
|
+
observedAt: z5.iso.datetime(),
|
|
391
|
+
expiresAt: z5.iso.datetime(),
|
|
392
|
+
turn: NativeTurnSchema.nullable(),
|
|
393
|
+
events: z5.array(NativeEventSchema).max(NATIVE_RUNTIME_MAX_EVENTS),
|
|
394
|
+
nativeSequence: z5.number().int().nonnegative().default(0),
|
|
395
|
+
nativeItems: z5.array(NativeItemSchema).max(NATIVE_RUNTIME_MAX_NATIVE_ITEMS).default([]),
|
|
396
|
+
pendingRequests: z5.array(NativePendingRequestSchema).max(16).default([]),
|
|
397
|
+
applicationPolicy: ApplicationPolicyEvidenceSchema2.optional(),
|
|
398
|
+
nativeProfile: RuntimeAppliedProfileSchema.optional(),
|
|
399
|
+
nativeSelection: NativeSelectionEvidenceSchema2.nullable().default(null),
|
|
400
|
+
permissionMode: PermissionModeSchema.optional(),
|
|
401
|
+
contextUsage: NativeContextUsageSchema.optional(),
|
|
402
|
+
account: NativeAccountSchema.optional(),
|
|
403
|
+
planLimits: PlanLimitsSchema.optional(),
|
|
404
|
+
spend: NativeSpendSchema.optional(),
|
|
405
|
+
fileCheckpoints: z5.boolean().optional(),
|
|
406
|
+
mcpServers: z5.array(NativeMcpServerSchema).max(64).optional()
|
|
407
|
+
}).strict();
|
|
408
|
+
|
|
409
|
+
// src/control/schema/core.ts
|
|
410
|
+
var CONTROL_MAX_BYTES = 512 * 1024;
|
|
411
|
+
var CONTROL_RESPONSE_MAX_BYTES = 4 * 1024 * 1024;
|
|
412
|
+
var CONTROL_MAX_READERS = 32;
|
|
413
|
+
var ControlTargetSchema = z6.object({ target: ManagedPeerSchema }).strict();
|
|
414
|
+
var ControlRowSchema = z6.object({
|
|
415
|
+
identity: ManagedPeerSchema,
|
|
416
|
+
registrationGeneration: z6.uuid().nullable(),
|
|
417
|
+
runtime: z6.enum(["cli", "app-server", "native"]),
|
|
418
|
+
pinned: z6.boolean(),
|
|
419
|
+
memoryBytes: z6.number().int().nonnegative().nullable().optional(),
|
|
420
|
+
nativeSession: NativeSessionSchema.optional(),
|
|
421
|
+
driverCapabilities: RuntimeCapabilitiesSchema.optional(),
|
|
422
|
+
sleep: z6.object({
|
|
423
|
+
phase: z6.enum(["requested", "sleeping", "waking", "awake"]),
|
|
424
|
+
operationId: z6.uuid(),
|
|
425
|
+
updatedAt: z6.iso.datetime()
|
|
426
|
+
}).strict().optional(),
|
|
427
|
+
state: z6.enum([
|
|
428
|
+
"working",
|
|
429
|
+
"idle",
|
|
430
|
+
"waiting-approval",
|
|
431
|
+
"waiting-input",
|
|
432
|
+
"prompt",
|
|
433
|
+
"stopped",
|
|
434
|
+
"blocked",
|
|
435
|
+
"unknown"
|
|
436
|
+
]),
|
|
437
|
+
availability: z6.enum(["live", "stale", "unavailable"]),
|
|
438
|
+
reason: z6.string().max(512).nullable(),
|
|
439
|
+
observedAt: z6.iso.datetime(),
|
|
440
|
+
expiresAt: z6.iso.datetime(),
|
|
441
|
+
turn: NativeTurnSchema.nullable(),
|
|
442
|
+
model: z6.string().max(512).nullable(),
|
|
443
|
+
launchRecipe: LaunchRecipeMetadataSchema2.optional(),
|
|
444
|
+
selection: AcceptedTurnOptionsSchema2.nullable(),
|
|
445
|
+
nativeSelection: NativeSelectionEvidenceSchema2.nullable(),
|
|
446
|
+
applicationPolicy: ApplicationPolicyEvidenceSchema2.optional(),
|
|
447
|
+
delegation: DelegationEvidenceSchema2.optional(),
|
|
448
|
+
nativeProfile: RuntimeAppliedProfileSchema.optional(),
|
|
449
|
+
capabilities: z6.object({
|
|
450
|
+
message: z6.boolean(),
|
|
451
|
+
start: z6.boolean(),
|
|
452
|
+
interrupt: z6.boolean(),
|
|
453
|
+
wait: z6.boolean()
|
|
454
|
+
}).strict()
|
|
455
|
+
}).strict();
|
|
456
|
+
var ControlSnapshotSchema = z6.object({
|
|
457
|
+
protocol: z6.literal(1),
|
|
458
|
+
version: z6.string().max(64),
|
|
459
|
+
machine: z6.string().max(128),
|
|
460
|
+
generation: z6.uuid(),
|
|
461
|
+
sequence: z6.number().int().nonnegative(),
|
|
462
|
+
status: z6.enum(["live", "stale", "unavailable"]),
|
|
463
|
+
reason: z6.string().max(512).nullable(),
|
|
464
|
+
observedAt: z6.iso.datetime(),
|
|
465
|
+
expiresAt: z6.iso.datetime(),
|
|
466
|
+
omitted: z6.number().int().nonnegative(),
|
|
467
|
+
sessions: z6.array(ControlRowSchema).max(256)
|
|
468
|
+
}).strict();
|
|
469
|
+
// src/control/schema/message.ts
|
|
470
|
+
import { z as z9 } from "zod";
|
|
471
|
+
|
|
472
|
+
// src/attachments/reference.ts
|
|
473
|
+
import { z as z7 } from "zod";
|
|
474
|
+
var ATTACHMENT_LIMITS = {
|
|
475
|
+
imageBytes: 8 * 1024 * 1024,
|
|
476
|
+
messageBytes: 16 * 1024 * 1024,
|
|
477
|
+
imagesPerMessage: 4,
|
|
478
|
+
chunkBytes: 24 * 1024,
|
|
479
|
+
dimension: 8192,
|
|
480
|
+
pixels: 16 * 1024 * 1024,
|
|
481
|
+
uploadTtlMs: 30 * 60 * 1000,
|
|
482
|
+
unretainedTtlMs: 24 * 60 * 60 * 1000,
|
|
483
|
+
hostBytes: 256 * 1024 * 1024,
|
|
484
|
+
hostUploads: 32,
|
|
485
|
+
targetUploads: 8,
|
|
486
|
+
records: 1024,
|
|
487
|
+
pins: 4096,
|
|
488
|
+
decodeDeadlineMs: 30000
|
|
489
|
+
};
|
|
490
|
+
var AttachmentMediaTypeSchema = z7.enum(["image/png", "image/jpeg"]);
|
|
491
|
+
var AttachmentDigestSchema = z7.string().regex(/^[0-9a-f]{64}$/);
|
|
492
|
+
var AttachmentReferenceSchema = z7.object({
|
|
493
|
+
id: z7.uuid(),
|
|
494
|
+
digest: AttachmentDigestSchema,
|
|
495
|
+
mediaType: AttachmentMediaTypeSchema,
|
|
496
|
+
bytes: z7.number().int().positive().max(ATTACHMENT_LIMITS.imageBytes),
|
|
497
|
+
width: z7.number().int().positive().max(ATTACHMENT_LIMITS.dimension),
|
|
498
|
+
height: z7.number().int().positive().max(ATTACHMENT_LIMITS.dimension)
|
|
499
|
+
}).strict().refine((value) => value.width * value.height <= ATTACHMENT_LIMITS.pixels);
|
|
500
|
+
var AttachmentReferencesSchema = z7.array(AttachmentReferenceSchema).max(ATTACHMENT_LIMITS.imagesPerMessage).refine((values) => values.reduce((bytes, value) => bytes + value.bytes, 0) <= ATTACHMENT_LIMITS.messageBytes);
|
|
501
|
+
|
|
502
|
+
// src/chat/communicationAuthorizationSchema.ts
|
|
503
|
+
import { z as z8 } from "zod";
|
|
504
|
+
var CommunicationBasisSchema = z8.enum([
|
|
505
|
+
"user-instruction",
|
|
506
|
+
"peer-letter",
|
|
507
|
+
"thread-continuation"
|
|
508
|
+
]);
|
|
509
|
+
function parseLedgerMessageRef(ref) {
|
|
510
|
+
const parts = ref.trim().split("#");
|
|
511
|
+
if (parts.length !== 2)
|
|
512
|
+
return null;
|
|
513
|
+
const parsed = z8.object({ threadId: z8.uuid(), messageId: z8.uuid() }).safeParse({
|
|
514
|
+
threadId: parts[0],
|
|
515
|
+
messageId: parts[1]
|
|
516
|
+
});
|
|
517
|
+
return parsed.success ? parsed.data : null;
|
|
518
|
+
}
|
|
519
|
+
var CommunicationAuthorizationSchema = z8.object({
|
|
520
|
+
basis: CommunicationBasisSchema.optional().describe("Which fact authorizes this message: the user instruction you hold, a peer letter that carried the permission, or an authorization already established in this correspondence."),
|
|
521
|
+
whyThisCommunicationIsNecessaryAndWithinTheUserAuthorizedScope: z8.string().trim().min(40).max(4000).optional().describe("Explain why this recipient is necessary, the intended result, and why contacting them is within the current user-authorized scope. Do not infer permission from tool availability. Omitted only by a thread continuation, which repeats nothing."),
|
|
522
|
+
userAuthorizationQuote: z8.string().min(1).max(4000).refine((value) => value.trim().length > 0, "A verbatim user authorization quote is required").optional().describe("Quote the actual user instruction permitting this communication verbatim \u2014 as the user said it, or as the peer letter reported it. Never invent consent, and never present an agent\u2019s own words as the user\u2019s. Omitted only by a thread continuation."),
|
|
523
|
+
sourceMessageRef: z8.string().trim().min(1).max(1000).describe("Where the authorization lives: the source user message for `user-instruction`, or `<peer thread uuid>#<message uuid>` for `peer-letter` and `thread-continuation`. A stitchmux reference is resolved against this machine\u2019s own records; a prose reference is not automatically verified by the transport.")
|
|
524
|
+
}).strict().superRefine((value, ctx) => {
|
|
525
|
+
const named = (path, message) => ctx.addIssue({ code: "custom", path: [path], message });
|
|
526
|
+
if (value.basis === "thread-continuation") {
|
|
527
|
+
if (value.whyThisCommunicationIsNecessaryAndWithinTheUserAuthorizedScope !== undefined)
|
|
528
|
+
named("whyThisCommunicationIsNecessaryAndWithinTheUserAuthorizedScope", "A thread continuation repeats no rationale: the authorization it points at holds it");
|
|
529
|
+
if (value.userAuthorizationQuote !== undefined)
|
|
530
|
+
named("userAuthorizationQuote", "A thread continuation repeats no quote: the authorization it points at holds it");
|
|
531
|
+
} else {
|
|
532
|
+
if (value.whyThisCommunicationIsNecessaryAndWithinTheUserAuthorizedScope === undefined)
|
|
533
|
+
named("whyThisCommunicationIsNecessaryAndWithinTheUserAuthorizedScope", "Required: why this recipient, what result, and under which user-authorized scope");
|
|
534
|
+
if (value.userAuthorizationQuote === undefined)
|
|
535
|
+
named("userAuthorizationQuote", "Required: the user authorization, quoted verbatim");
|
|
536
|
+
}
|
|
537
|
+
if ((value.basis === "peer-letter" || value.basis === "thread-continuation") && parseLedgerMessageRef(value.sourceMessageRef) === null)
|
|
538
|
+
named("sourceMessageRef", "This basis references a stitchmux record: <peer thread uuid>#<message uuid>, both copied from the chat line");
|
|
539
|
+
});
|
|
540
|
+
var CommunicationAuthorizationInputSchema = CommunicationAuthorizationSchema.safeExtend({
|
|
541
|
+
basis: CommunicationBasisSchema
|
|
542
|
+
});
|
|
543
|
+
|
|
544
|
+
// src/control/schema/message.ts
|
|
545
|
+
var ControlMessageSchema = ControlTargetSchema.extend({
|
|
546
|
+
communicationAuthorization: CommunicationAuthorizationInputSchema.nullable().describe("Required basis: user-instruction (rationale, verbatim quote, sourceMessageRef), peer-letter (same fields, reference <peer thread uuid>#<message uuid>), or thread-continuation (sourceMessageRef only, same pair and task). References resolve on the originating host. Null is reserved for server-admitted human input. A claim is not a verified grant or file-transfer authority."),
|
|
547
|
+
messageId: z9.uuid(),
|
|
548
|
+
origin: MessageAttributionSchema2.optional(),
|
|
549
|
+
notification: NotificationAudienceSchema2.optional(),
|
|
550
|
+
registrationGeneration: z9.uuid().optional(),
|
|
551
|
+
body: z9.string().trim().max(16384).default(""),
|
|
552
|
+
images: AttachmentReferencesSchema.default([]),
|
|
553
|
+
options: NativeTurnOptionsSchema2.optional(),
|
|
554
|
+
defer: z9.boolean().default(true),
|
|
555
|
+
notBefore: z9.iso.datetime().nullable().default(null),
|
|
556
|
+
task: z9.string().max(256).nullable().default(null)
|
|
557
|
+
}).strict().refine((value) => value.body.length > 0 || value.images.length > 0, "Message input is empty");
|
|
558
|
+
var ControlMessageReceiptSchema = z9.object({
|
|
559
|
+
messageId: z9.uuid(),
|
|
560
|
+
origin: MessageOriginSchema2,
|
|
561
|
+
notification: NotificationAudienceSchema2,
|
|
562
|
+
registrationGeneration: z9.uuid().nullable(),
|
|
563
|
+
accepted: z9.literal(true),
|
|
564
|
+
duplicate: z9.boolean(),
|
|
565
|
+
turnOptions: AcceptedTurnOptionsSchema2.nullable()
|
|
566
|
+
}).strict();
|
|
567
|
+
var ControlMessageCancelSchema = z9.object({ messageId: z9.uuid() }).strict();
|
|
568
|
+
var ControlMessageCancelReceiptSchema = z9.object({
|
|
569
|
+
messageId: z9.uuid(),
|
|
570
|
+
outcome: z9.enum(["cancelled", "delivered", "undeliverable", "unknown", "not-yours"])
|
|
571
|
+
}).strict();
|
|
572
|
+
var ControlInterruptSchema = ControlTargetSchema.extend({
|
|
573
|
+
generation: z9.uuid(),
|
|
574
|
+
turnId: z9.string().min(1).max(256)
|
|
575
|
+
}).strict();
|
|
576
|
+
var ControlKeysSchema = ControlTargetSchema.extend({
|
|
577
|
+
text: z9.string().min(1).max(16 * 1024)
|
|
578
|
+
}).strict();
|
|
579
|
+
var ControlStopReceiptSchema = z9.object({
|
|
580
|
+
target: ManagedPeerSchema,
|
|
581
|
+
accepted: z9.literal(true),
|
|
582
|
+
stopped: z9.boolean(),
|
|
583
|
+
lingering: z9.int().nullable()
|
|
584
|
+
}).strict();
|
|
585
|
+
var ControlActionReceiptSchema = z9.object({ target: ManagedPeerSchema, accepted: z9.literal(true) }).strict();
|
|
586
|
+
// src/control/schema/nativeStreamContract.ts
|
|
587
|
+
import { z as z16 } from "zod";
|
|
588
|
+
|
|
589
|
+
// src/chat/identity.ts
|
|
590
|
+
function managedPeerKey(peer) {
|
|
591
|
+
return `${peer.source}:${peer.machine}:${peer.agent}:${peer.session}:${peer.threadId}`;
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
// src/control/schema/native.ts
|
|
595
|
+
import { z as z15 } from "zod";
|
|
596
|
+
|
|
597
|
+
// src/content/schema.ts
|
|
598
|
+
import { z as z11 } from "zod";
|
|
599
|
+
|
|
600
|
+
// src/content/toolSchema.ts
|
|
601
|
+
import { z as z10 } from "zod";
|
|
602
|
+
var ToolNameSchema = z10.string().min(1).max(128);
|
|
603
|
+
var ToolLifecycleSchema = z10.enum(["pending", "running", "completed", "unknown"]);
|
|
604
|
+
var ToolOutcomeSchema = z10.enum([
|
|
605
|
+
"unknown",
|
|
606
|
+
"succeeded",
|
|
607
|
+
"failed",
|
|
608
|
+
"interrupted",
|
|
609
|
+
"declined"
|
|
610
|
+
]);
|
|
611
|
+
var ToolObservationSchema = z10.object({
|
|
612
|
+
callId: z10.string().min(1).max(256).nullable(),
|
|
613
|
+
name: ToolNameSchema.nullable(),
|
|
614
|
+
lifecycle: ToolLifecycleSchema,
|
|
615
|
+
outcome: ToolOutcomeSchema,
|
|
616
|
+
exitCode: z10.number().int().nullable()
|
|
617
|
+
}).strict().refine((tool) => tool.lifecycle === "completed" || tool.outcome === "unknown" && tool.exitCode === null, "Nonterminal tool observation cannot claim an outcome");
|
|
618
|
+
|
|
619
|
+
// src/content/schema.ts
|
|
620
|
+
var CONTENT_FILE_MAX_BYTES = 512 * 1024;
|
|
621
|
+
var CONTENT_REPLAY_BYTES = 192 * 1024;
|
|
622
|
+
var CONTENT_BASELINE_BYTES = 192 * 1024;
|
|
623
|
+
var CONTENT_ITEM_BYTES = 64 * 1024;
|
|
624
|
+
var CONTENT_MAX_RECORDS = 512;
|
|
625
|
+
var CONTENT_MAX_ITEMS = 64;
|
|
626
|
+
var ContentCursorSchema = z11.object({
|
|
627
|
+
generation: z11.uuid(),
|
|
628
|
+
sequence: z11.number().int().nonnegative()
|
|
629
|
+
}).strict();
|
|
630
|
+
var ContentKindSchema = z11.enum([
|
|
631
|
+
"assistant",
|
|
632
|
+
"reasoning-summary",
|
|
633
|
+
"tool",
|
|
634
|
+
"usage",
|
|
635
|
+
"request",
|
|
636
|
+
"terminal"
|
|
637
|
+
]);
|
|
638
|
+
var ContentRecordSchema = z11.object({
|
|
639
|
+
sequence: z11.number().int().nonnegative(),
|
|
640
|
+
at: z11.iso.datetime(),
|
|
641
|
+
kind: ContentKindSchema,
|
|
642
|
+
operation: z11.enum(["append", "replace", "lifecycle"]),
|
|
643
|
+
turnId: z11.string().min(1).max(256).nullable(),
|
|
644
|
+
itemId: z11.string().min(1).max(256),
|
|
645
|
+
revision: z11.number().int().positive(),
|
|
646
|
+
offsetBytes: z11.number().int().nonnegative(),
|
|
647
|
+
prefixKnown: z11.boolean(),
|
|
648
|
+
text: z11.string().nullable(),
|
|
649
|
+
totalBytes: z11.number().int().nonnegative(),
|
|
650
|
+
omittedBytes: z11.number().int().nonnegative(),
|
|
651
|
+
complete: z11.boolean(),
|
|
652
|
+
status: z11.string().max(128).nullable(),
|
|
653
|
+
tool: ToolObservationSchema.nullable().default(null)
|
|
654
|
+
}).strict();
|
|
655
|
+
var ContentSnapshotSchema = z11.object({
|
|
656
|
+
protocol: z11.literal(1),
|
|
657
|
+
target: ManagedPeerSchema,
|
|
658
|
+
registrationGeneration: z11.uuid().nullable(),
|
|
659
|
+
nativeId: z11.string().min(1).max(256),
|
|
660
|
+
generation: z11.uuid(),
|
|
661
|
+
sequence: z11.number().int().nonnegative(),
|
|
662
|
+
droppedThrough: z11.number().int().nonnegative(),
|
|
663
|
+
contextBoundary: z11.number().int().nonnegative(),
|
|
664
|
+
omittedRecords: z11.number().int().nonnegative(),
|
|
665
|
+
status: z11.enum(["live", "unavailable"]),
|
|
666
|
+
records: z11.array(ContentRecordSchema).max(CONTENT_MAX_RECORDS),
|
|
667
|
+
baseline: z11.array(ContentRecordSchema).max(CONTENT_MAX_ITEMS)
|
|
668
|
+
}).strict();
|
|
669
|
+
var ContentReadSchema = ContentSnapshotSchema.omit({
|
|
670
|
+
droppedThrough: true,
|
|
671
|
+
contextBoundary: true
|
|
672
|
+
}).extend({
|
|
673
|
+
reset: z11.enum(["initial", "gap", "generation", "context"]).nullable()
|
|
674
|
+
}).strict();
|
|
675
|
+
|
|
676
|
+
// src/context/transcriptJsonSchema.ts
|
|
677
|
+
import { z as z14 } from "zod";
|
|
678
|
+
|
|
679
|
+
// src/agent/transcript/messageSchema.ts
|
|
680
|
+
import { z as z12 } from "zod";
|
|
681
|
+
var TranscriptRoleSchema = z12.enum(["user", "assistant", "tool", "system", "unknown"]);
|
|
682
|
+
var TranscriptKindSchema = z12.enum([
|
|
683
|
+
"message",
|
|
684
|
+
"tool_call",
|
|
685
|
+
"tool_result",
|
|
686
|
+
"thinking",
|
|
687
|
+
"image",
|
|
688
|
+
"event",
|
|
689
|
+
"unknown"
|
|
690
|
+
]);
|
|
691
|
+
var TranscriptImageSchema = z12.object({
|
|
692
|
+
address: z12.string().min(1).max(256),
|
|
693
|
+
mediaType: z12.string().min(1).max(128).nullable(),
|
|
694
|
+
bytes: z12.number().int().nonnegative().nullable(),
|
|
695
|
+
digest: z12.string().length(64).nullable(),
|
|
696
|
+
unavailable: z12.enum(["unsupported-source", "malformed", "too-large"]).nullable()
|
|
697
|
+
});
|
|
698
|
+
var TranscriptUsageSchema = z12.object({
|
|
699
|
+
inputTokens: z12.number().int().nonnegative().nullable(),
|
|
700
|
+
outputTokens: z12.number().int().nonnegative().nullable(),
|
|
701
|
+
cacheReadTokens: z12.number().int().nonnegative().nullable(),
|
|
702
|
+
cacheCreationTokens: z12.number().int().nonnegative().nullable()
|
|
703
|
+
});
|
|
704
|
+
var TranscriptAgentSchema = z12.object({
|
|
705
|
+
id: z12.string(),
|
|
706
|
+
type: z12.string().nullable(),
|
|
707
|
+
description: z12.string().nullable(),
|
|
708
|
+
model: z12.string().nullable(),
|
|
709
|
+
state: z12.enum(["running", "finished"]),
|
|
710
|
+
startedAt: z12.string().nullable(),
|
|
711
|
+
finishedAt: z12.string().nullable(),
|
|
712
|
+
toolCalls: z12.number().int().nonnegative().nullable(),
|
|
713
|
+
usage: TranscriptUsageSchema.nullable(),
|
|
714
|
+
available: z12.boolean()
|
|
715
|
+
});
|
|
716
|
+
var TranscriptMessageSchema = z12.object({
|
|
717
|
+
id: z12.string(),
|
|
718
|
+
seq: z12.number(),
|
|
719
|
+
createdAt: z12.string().nullable(),
|
|
720
|
+
role: TranscriptRoleSchema,
|
|
721
|
+
kind: TranscriptKindSchema,
|
|
722
|
+
text: z12.string().nullable(),
|
|
723
|
+
title: z12.string().nullable(),
|
|
724
|
+
toolName: z12.string().nullable(),
|
|
725
|
+
toolCallId: z12.string().nullable(),
|
|
726
|
+
status: z12.enum(["error"]).nullable(),
|
|
727
|
+
rawType: z12.string().nullable(),
|
|
728
|
+
done: z12.boolean(),
|
|
729
|
+
result: z12.string().nullable(),
|
|
730
|
+
input: z12.string().nullable(),
|
|
731
|
+
image: TranscriptImageSchema.nullable().default(null),
|
|
732
|
+
resultImages: z12.array(TranscriptImageSchema).optional(),
|
|
733
|
+
usage: TranscriptUsageSchema.nullable().default(null),
|
|
734
|
+
resultText: z12.string().nullable(),
|
|
735
|
+
doneAt: z12.string().nullable().default(null),
|
|
736
|
+
agent: TranscriptAgentSchema.nullable().default(null)
|
|
737
|
+
});
|
|
738
|
+
|
|
739
|
+
// src/usage/schema.ts
|
|
740
|
+
import { z as z13 } from "zod";
|
|
741
|
+
var USAGE_MAX_BYTES = 256 * 1024;
|
|
742
|
+
var USAGE_SLICE_BYTES = 4 * 1024 * 1024;
|
|
743
|
+
var UsageMetricsSchema = z13.object({
|
|
744
|
+
inputTokens: z13.int().nonnegative().nullable(),
|
|
745
|
+
outputTokens: z13.int().nonnegative().nullable(),
|
|
746
|
+
cacheReadTokens: z13.int().nonnegative().nullable(),
|
|
747
|
+
cacheCreationTokens: z13.int().nonnegative().nullable(),
|
|
748
|
+
reasoningTokens: z13.int().nonnegative().nullable(),
|
|
749
|
+
totalTokens: z13.int().nonnegative().nullable()
|
|
750
|
+
}).strict();
|
|
751
|
+
var UsageProvenanceSchema = z13.record(UsageMetricsSchema.keyof(), z13.string().max(64));
|
|
752
|
+
var UsageDetailsSchema = z13.object({
|
|
753
|
+
canonicalModel: z13.string().max(256).nullable(),
|
|
754
|
+
costBasis: z13.enum(["list", "managed", "unknown"]).nullable(),
|
|
755
|
+
webSearchRequests: z13.int().nonnegative().nullable(),
|
|
756
|
+
contextWindow: z13.int().nonnegative().nullable(),
|
|
757
|
+
maxOutputTokens: z13.int().nonnegative().nullable()
|
|
758
|
+
}).strict();
|
|
759
|
+
var USAGE_FIELDS = UsageMetricsSchema.keyof().options;
|
|
760
|
+
var UsageFactSchema = z13.object({
|
|
761
|
+
id: z13.string().min(1).max(512),
|
|
762
|
+
runtime: z13.enum(["claude", "codex", "opencode", "custom", "antigravity"]),
|
|
763
|
+
model: z13.string().max(256).nullable(),
|
|
764
|
+
provider: z13.string().max(128).nullable(),
|
|
765
|
+
at: z13.iso.datetime().nullable(),
|
|
766
|
+
observedAt: z13.iso.datetime(),
|
|
767
|
+
scope: z13.enum(["message", "turn", "run", "session"]),
|
|
768
|
+
mode: z13.enum(["replacement", "cumulative"]),
|
|
769
|
+
epoch: z13.string().min(1).max(256),
|
|
770
|
+
inputIncludesCache: z13.boolean().nullable(),
|
|
771
|
+
outputIncludesReasoning: z13.boolean().nullable(),
|
|
772
|
+
metrics: UsageMetricsSchema,
|
|
773
|
+
provenance: UsageProvenanceSchema.optional(),
|
|
774
|
+
cost: z13.object({
|
|
775
|
+
value: z13.number().nonnegative(),
|
|
776
|
+
currency: z13.string().min(1).max(16),
|
|
777
|
+
provenance: z13.string().max(64).optional()
|
|
778
|
+
}).strict().nullable(),
|
|
779
|
+
identity: z13.enum(["native", "record"]),
|
|
780
|
+
details: UsageDetailsSchema.optional(),
|
|
781
|
+
counterAmbiguous: z13.boolean().optional()
|
|
782
|
+
}).strict();
|
|
783
|
+
var UsageQuerySchema = z13.object({
|
|
784
|
+
since: z13.iso.datetime().transform((value) => new Date(value).toISOString()).optional(),
|
|
785
|
+
until: z13.iso.datetime().transform((value) => new Date(value).toISOString()).optional(),
|
|
786
|
+
timezone: z13.string().max(128).refine((value) => {
|
|
787
|
+
try {
|
|
788
|
+
new Intl.DateTimeFormat("en", { timeZone: value });
|
|
789
|
+
return true;
|
|
790
|
+
} catch {
|
|
791
|
+
return false;
|
|
792
|
+
}
|
|
793
|
+
}, "Invalid IANA timezone").default("UTC"),
|
|
794
|
+
cursor: z13.string().max(2048).nullable().default(null),
|
|
795
|
+
pipelineCursor: z13.string().max(2048).nullable().default(null),
|
|
796
|
+
limit: z13.int().min(1).max(100).default(100)
|
|
797
|
+
}).strict().refine((q) => !q.since || !q.until || q.since < q.until, "Expected since < until").refine((q) => !q.since || !q.until || Date.parse(q.until) - Date.parse(q.since) <= 366 * 86400000, "Explicit intervals are limited to 366 days");
|
|
798
|
+
var UsageReadSchema = z13.object({
|
|
799
|
+
address: z13.string().min(1).max(512),
|
|
800
|
+
query: UsageQuerySchema.prefault({})
|
|
801
|
+
}).strict();
|
|
802
|
+
var UsageListSchema = z13.object({
|
|
803
|
+
query: UsageQuerySchema.prefault({}),
|
|
804
|
+
cursor: z13.string().max(2048).nullable().default(null),
|
|
805
|
+
limit: z13.int().min(1).max(100).default(100)
|
|
806
|
+
}).strict();
|
|
807
|
+
var UsageAggregateSchema = z13.object({
|
|
808
|
+
values: UsageMetricsSchema,
|
|
809
|
+
observations: z13.int().nonnegative(),
|
|
810
|
+
measured: z13.record(UsageMetricsSchema.keyof(), z13.int().nonnegative()),
|
|
811
|
+
fieldCoverage: z13.record(UsageMetricsSchema.keyof(), z13.enum(["full", "partial", "unknown"])),
|
|
812
|
+
coverage: z13.enum(["full", "partial", "unknown"]),
|
|
813
|
+
costs: z13.array(z13.object({
|
|
814
|
+
currency: z13.string(),
|
|
815
|
+
reported: z13.number().nonnegative(),
|
|
816
|
+
observations: z13.int().nonnegative(),
|
|
817
|
+
provenance: z13.string().nullable()
|
|
818
|
+
}).strict()).max(32)
|
|
819
|
+
}).strict();
|
|
820
|
+
var UsageBucketSchema = z13.object({
|
|
821
|
+
day: z13.string().nullable(),
|
|
822
|
+
model: z13.string().nullable(),
|
|
823
|
+
provider: z13.string().nullable(),
|
|
824
|
+
inputIncludesCache: z13.boolean().nullable(),
|
|
825
|
+
outputIncludesReasoning: z13.boolean().nullable(),
|
|
826
|
+
details: UsageDetailsSchema.optional(),
|
|
827
|
+
provenance: UsageProvenanceSchema.optional(),
|
|
828
|
+
...UsageAggregateSchema.shape
|
|
829
|
+
}).strict();
|
|
830
|
+
var UsageEventRangeSchema = z13.object({ first: z13.iso.datetime().nullable(), last: z13.iso.datetime().nullable() }).strict();
|
|
831
|
+
var UsageSummarySchema = z13.object({
|
|
832
|
+
address: z13.string(),
|
|
833
|
+
runtime: z13.string(),
|
|
834
|
+
identity: z13.object({ sessionId: z13.string().nullable(), nativeSessionId: z13.string().nullable() }).strict(),
|
|
835
|
+
additivity: z13.literal("session-only"),
|
|
836
|
+
source: z13.enum(["readable", "missing", "unreadable", "unsupported"]),
|
|
837
|
+
state: z13.enum(["building", "ready", "stale", "failed"]),
|
|
838
|
+
reason: z13.string().nullable(),
|
|
839
|
+
retryAfterMs: z13.int().positive().nullable().optional(),
|
|
840
|
+
sourceCoverage: z13.object({
|
|
841
|
+
basis: z13.literal("source-snapshot"),
|
|
842
|
+
targetBytes: z13.int().nonnegative(),
|
|
843
|
+
throughBytes: z13.int().nonnegative(),
|
|
844
|
+
complete: z13.boolean()
|
|
845
|
+
}).strict().optional(),
|
|
846
|
+
revision: z13.string(),
|
|
847
|
+
observedAt: z13.iso.datetime().nullable(),
|
|
848
|
+
sourceEventRange: UsageEventRangeSchema,
|
|
849
|
+
indexedBytes: z13.int().nonnegative(),
|
|
850
|
+
sourceBytes: z13.int().nonnegative().nullable(),
|
|
851
|
+
malformedRecords: z13.int().nonnegative(),
|
|
852
|
+
history: z13.enum(["native-history", "observed-live"]),
|
|
853
|
+
self: UsageAggregateSchema,
|
|
854
|
+
unattributed: UsageAggregateSchema,
|
|
855
|
+
delegated: z13.object({
|
|
856
|
+
coverage: z13.enum(["unknown", "partial", "full"]),
|
|
857
|
+
addresses: z13.array(z13.string()).max(100)
|
|
858
|
+
}).strict(),
|
|
859
|
+
reportedPipeline: z13.object({
|
|
860
|
+
scope: z13.literal("query-pipeline-inclusive"),
|
|
861
|
+
sourceEventRange: UsageEventRangeSchema,
|
|
862
|
+
usage: UsageAggregateSchema,
|
|
863
|
+
state: z13.enum(["building", "ready"]),
|
|
864
|
+
reset: z13.boolean(),
|
|
865
|
+
unattributed: UsageAggregateSchema,
|
|
866
|
+
buckets: z13.array(UsageBucketSchema).max(100),
|
|
867
|
+
nextCursor: z13.string().nullable()
|
|
868
|
+
}).strict().nullable(),
|
|
869
|
+
buckets: z13.array(UsageBucketSchema).max(100),
|
|
870
|
+
timezone: z13.string(),
|
|
871
|
+
nextCursor: z13.string().nullable(),
|
|
872
|
+
reset: z13.boolean()
|
|
873
|
+
}).strict();
|
|
874
|
+
var UsageListResultSchema = z13.object({
|
|
875
|
+
machine: z13.string(),
|
|
876
|
+
data: z13.array(UsageSummarySchema).max(100),
|
|
877
|
+
nextCursor: z13.string().nullable(),
|
|
878
|
+
reset: z13.boolean()
|
|
879
|
+
}).strict();
|
|
880
|
+
|
|
881
|
+
// src/context/transcriptJsonSchema.ts
|
|
882
|
+
var TranscriptStatsSchema = z14.object({
|
|
883
|
+
messages: z14.number(),
|
|
884
|
+
user: z14.number(),
|
|
885
|
+
assistant: z14.number(),
|
|
886
|
+
toolCalls: z14.number(),
|
|
887
|
+
thinking: z14.number(),
|
|
888
|
+
usage: UsageAggregateSchema.optional()
|
|
889
|
+
});
|
|
890
|
+
var TranscriptJsonSchema = z14.object({
|
|
891
|
+
version: z14.string(),
|
|
892
|
+
generatedAt: z14.string(),
|
|
893
|
+
session: z14.object({
|
|
894
|
+
name: z14.string(),
|
|
895
|
+
uuid: z14.string(),
|
|
896
|
+
rc: z14.string(),
|
|
897
|
+
dir: z14.string(),
|
|
898
|
+
machine: z14.string()
|
|
899
|
+
}),
|
|
900
|
+
source: z14.object({
|
|
901
|
+
kind: z14.string(),
|
|
902
|
+
path: z14.string(),
|
|
903
|
+
available: z14.boolean(),
|
|
904
|
+
error: z14.string().nullable()
|
|
905
|
+
}),
|
|
906
|
+
cursor: z14.object({
|
|
907
|
+
opaque: z14.string().nullable(),
|
|
908
|
+
line: z14.number().nullable(),
|
|
909
|
+
byteOffset: z14.null(),
|
|
910
|
+
mtimeMs: z14.number().nullable()
|
|
911
|
+
}),
|
|
912
|
+
window: z14.object({
|
|
913
|
+
firstLine: z14.number(),
|
|
914
|
+
lastLine: z14.number(),
|
|
915
|
+
reachedStart: z14.boolean(),
|
|
916
|
+
earlierFiles: z14.number().int().nonnegative()
|
|
917
|
+
}),
|
|
918
|
+
stats: TranscriptStatsSchema,
|
|
919
|
+
messages: z14.array(TranscriptMessageSchema)
|
|
920
|
+
});
|
|
921
|
+
|
|
922
|
+
// src/control/schema/native.ts
|
|
923
|
+
var ControlTranscriptReadSchema = ControlTargetSchema.extend({
|
|
924
|
+
tail: z15.number().int().min(1).max(200).default(120),
|
|
925
|
+
cursor: z15.number().int().nonnegative().nullable().default(null),
|
|
926
|
+
before: z15.number().int().positive().nullable().default(null),
|
|
927
|
+
limit: z15.number().int().min(1).max(200).nullable().default(null),
|
|
928
|
+
textLimit: z15.number().int().min(1).max(65536).nullable().default(null),
|
|
929
|
+
agent: z15.string().regex(/^[0-9a-f]{1,64}$/).nullable().default(null)
|
|
930
|
+
}).strict();
|
|
931
|
+
var ControlTranscriptResultSchema = TranscriptJsonSchema.extend(ControlTargetSchema.shape).strict();
|
|
932
|
+
var ControlNativeCursorSchema = ContentCursorSchema;
|
|
933
|
+
var ControlNativeReadSchema = ControlTargetSchema.extend({
|
|
934
|
+
cursor: ControlNativeCursorSchema.nullable().default(null)
|
|
935
|
+
}).strict();
|
|
936
|
+
var ControlNativeSnapshotSchema = ContentReadSchema.extend({
|
|
937
|
+
observedAt: z15.iso.datetime(),
|
|
938
|
+
expiresAt: z15.iso.datetime(),
|
|
939
|
+
pending: z15.array(NativePendingRequestSchema.omit({ rpcId: true })).max(16),
|
|
940
|
+
omittedPending: z15.number().int().nonnegative(),
|
|
941
|
+
launchRecipe: LaunchRecipeMetadataSchema2.optional(),
|
|
942
|
+
selection: AcceptedTurnOptionsSchema2.nullable(),
|
|
943
|
+
nativeSelection: NativeSelectionEvidenceSchema2.nullable(),
|
|
944
|
+
applicationPolicy: ApplicationPolicyEvidenceSchema2.optional(),
|
|
945
|
+
nativeSession: NativeSessionSchema.optional(),
|
|
946
|
+
nativeProfile: RuntimeAppliedProfileSchema.optional(),
|
|
947
|
+
driverCapabilities: RuntimeCapabilitiesSchema.optional()
|
|
948
|
+
}).strict();
|
|
949
|
+
var ControlNativeResponseSchema = ControlTargetSchema.extend({
|
|
950
|
+
operationId: z15.uuid(),
|
|
951
|
+
generation: z15.uuid(),
|
|
952
|
+
requestId: z15.string().min(1).max(256),
|
|
953
|
+
kind: z15.enum(["approval", "input"]),
|
|
954
|
+
decision: z15.enum(["accept", "acceptForSession", "decline", "cancel"]).nullable().default(null),
|
|
955
|
+
answers: z15.record(z15.string().min(1).max(256), z15.array(z15.string().max(4096)).min(1).max(32)).nullable().default(null)
|
|
956
|
+
}).strict();
|
|
957
|
+
var ControlNativeResponseReceiptSchema = z15.object({
|
|
958
|
+
operationId: z15.uuid(),
|
|
959
|
+
requestId: z15.string(),
|
|
960
|
+
outcome: z15.enum(["submitted", "uncertain"])
|
|
961
|
+
}).strict();
|
|
962
|
+
|
|
963
|
+
// src/control/schema/nativeStreamContract.ts
|
|
964
|
+
var STITCHMUX_NATIVE_STREAM_PROFILE = "stitchmux-native";
|
|
965
|
+
var STITCHMUX_NATIVE_STREAM_COMMAND = "control-native-stream";
|
|
966
|
+
var STITCHMUX_NATIVE_STREAM_MAX_INPUT_BYTES = 4096;
|
|
967
|
+
var STITCHMUX_NATIVE_STREAM_MAX_CHUNK_BYTES = 32 * 1024;
|
|
968
|
+
var STITCHMUX_NATIVE_STREAM_MAX_FRAME_BYTES = STITCHMUX_NATIVE_STREAM_MAX_CHUNK_BYTES * 2;
|
|
969
|
+
var STITCHMUX_NATIVE_STREAM_HEARTBEAT_MS = 2000;
|
|
970
|
+
var ControlNativeStreamCursorPayloadSchema = z16.object({
|
|
971
|
+
v: z16.literal(2),
|
|
972
|
+
target: ManagedPeerSchema,
|
|
973
|
+
cursor: ControlNativeCursorSchema
|
|
974
|
+
}).strict();
|
|
975
|
+
var ControlNativeStreamCursorTokenSchema = z16.string().min(1).max(512).regex(/^ccn_[A-Za-z0-9_-]+$/);
|
|
976
|
+
var ControlNativeStreamRequestSchema = z16.object({
|
|
977
|
+
target: ManagedPeerSchema,
|
|
978
|
+
cursor: ControlNativeStreamCursorTokenSchema.nullable().default(null)
|
|
979
|
+
}).strict();
|
|
980
|
+
var ControlNativeStreamCursorSchema = ControlNativeStreamCursorTokenSchema.transform((token, ctx) => {
|
|
981
|
+
try {
|
|
982
|
+
const encoded = token.slice(4).replace(/-/g, "+").replace(/_/g, "/");
|
|
983
|
+
const padding = "=".repeat((4 - encoded.length % 4) % 4);
|
|
984
|
+
const binary = atob(encoded + padding);
|
|
985
|
+
const bytes = Uint8Array.from(binary, (character) => character.charCodeAt(0));
|
|
986
|
+
return ControlNativeStreamCursorPayloadSchema.parse(JSON.parse(new TextDecoder().decode(bytes)));
|
|
987
|
+
} catch {
|
|
988
|
+
ctx.addIssue({ code: "custom", message: "invalid native stream cursor" });
|
|
989
|
+
return z16.NEVER;
|
|
990
|
+
}
|
|
991
|
+
});
|
|
992
|
+
function controlNativeStreamFrameBytes(frame) {
|
|
993
|
+
return new TextEncoder().encode(`${JSON.stringify(frame)}
|
|
994
|
+
`).byteLength;
|
|
995
|
+
}
|
|
996
|
+
var ControlNativeStreamFrameSchema = z16.object({
|
|
997
|
+
channel: z16.literal("data"),
|
|
998
|
+
data: z16.string(),
|
|
999
|
+
cursor: ControlNativeStreamCursorTokenSchema
|
|
1000
|
+
}).strict().refine((frame) => controlNativeStreamFrameBytes(frame) <= STITCHMUX_NATIVE_STREAM_MAX_FRAME_BYTES, "native stream frame exceeds the line budget").refine((frame) => new TextEncoder().encode(frame.data).byteLength <= STITCHMUX_NATIVE_STREAM_MAX_CHUNK_BYTES, "native stream payload exceeds the chunk budget");
|
|
1001
|
+
function encodeControlNativeStreamCursor(target, cursor) {
|
|
1002
|
+
const payload = JSON.stringify(ControlNativeStreamCursorPayloadSchema.parse({ v: 2, target, cursor }));
|
|
1003
|
+
const bytes = new TextEncoder().encode(payload);
|
|
1004
|
+
let binary = "";
|
|
1005
|
+
for (const byte of bytes)
|
|
1006
|
+
binary += String.fromCharCode(byte);
|
|
1007
|
+
return `ccn_${btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/g, "")}`;
|
|
1008
|
+
}
|
|
1009
|
+
function readControlNativeStreamCursor(token, target) {
|
|
1010
|
+
if (token === null)
|
|
1011
|
+
return null;
|
|
1012
|
+
const parsed = ControlNativeStreamCursorSchema.parse(token);
|
|
1013
|
+
if (managedPeerKey(parsed.target) !== managedPeerKey(target))
|
|
1014
|
+
throw new Error("Native stream cursor belongs to another target");
|
|
1015
|
+
return parsed.cursor;
|
|
1016
|
+
}
|
|
1017
|
+
|
|
1018
|
+
class NativeStreamFrameUnrepresentable extends Error {
|
|
1019
|
+
bytes;
|
|
1020
|
+
constructor(bytes) {
|
|
1021
|
+
super(`native stream frame is ${bytes} bytes with nothing left to shed, over the ${STITCHMUX_NATIVE_STREAM_MAX_FRAME_BYTES}-byte budget`);
|
|
1022
|
+
this.name = "NativeStreamFrameUnrepresentable";
|
|
1023
|
+
this.bytes = bytes;
|
|
1024
|
+
}
|
|
1025
|
+
}
|
|
1026
|
+
function controlNativeStreamFrame(snapshot) {
|
|
1027
|
+
const native = ControlNativeSnapshotSchema.parse(snapshot);
|
|
1028
|
+
const cursor = encodeControlNativeStreamCursor(native.target, {
|
|
1029
|
+
generation: native.generation,
|
|
1030
|
+
sequence: native.sequence
|
|
1031
|
+
});
|
|
1032
|
+
const build = (records, baseline, pending) => ({
|
|
1033
|
+
channel: "data",
|
|
1034
|
+
data: JSON.stringify({
|
|
1035
|
+
...native,
|
|
1036
|
+
records,
|
|
1037
|
+
baseline,
|
|
1038
|
+
pending,
|
|
1039
|
+
omittedRecords: native.omittedRecords + (native.records.length - records.length) + (native.baseline.length - baseline.length),
|
|
1040
|
+
omittedPending: native.omittedPending + (native.pending.length - pending.length)
|
|
1041
|
+
}),
|
|
1042
|
+
cursor
|
|
1043
|
+
});
|
|
1044
|
+
const fits = (records, baseline, pending) => {
|
|
1045
|
+
const candidate = build(records, baseline, pending);
|
|
1046
|
+
return controlNativeStreamFrameBytes(candidate) <= STITCHMUX_NATIVE_STREAM_MAX_FRAME_BYTES && new TextEncoder().encode(candidate.data).byteLength <= STITCHMUX_NATIVE_STREAM_MAX_CHUNK_BYTES;
|
|
1047
|
+
};
|
|
1048
|
+
const keepNewest = (items, count) => items.slice(items.length - count);
|
|
1049
|
+
const keepOldest = (items, count) => items.slice(0, count);
|
|
1050
|
+
const largestFitting = (length, probe) => {
|
|
1051
|
+
let low = 0;
|
|
1052
|
+
let high = length;
|
|
1053
|
+
while (low < high) {
|
|
1054
|
+
const middle = Math.ceil((low + high) / 2);
|
|
1055
|
+
if (probe(middle))
|
|
1056
|
+
low = middle;
|
|
1057
|
+
else
|
|
1058
|
+
high = middle - 1;
|
|
1059
|
+
}
|
|
1060
|
+
return low;
|
|
1061
|
+
};
|
|
1062
|
+
const shedObservation = (pending) => {
|
|
1063
|
+
if (fits(native.records, native.baseline, pending))
|
|
1064
|
+
return { records: native.records, baseline: native.baseline };
|
|
1065
|
+
const records = keepNewest(native.records, largestFitting(native.records.length, (count) => fits(keepNewest(native.records, count), native.baseline, pending)));
|
|
1066
|
+
if (records.length > 0)
|
|
1067
|
+
return { records, baseline: native.baseline };
|
|
1068
|
+
const baseline = keepNewest(native.baseline, largestFitting(native.baseline.length, (count) => fits(records, keepNewest(native.baseline, count), pending)));
|
|
1069
|
+
return { records, baseline };
|
|
1070
|
+
};
|
|
1071
|
+
let pending = native.pending;
|
|
1072
|
+
let { records, baseline } = shedObservation(pending);
|
|
1073
|
+
if (!fits(records, baseline, pending)) {
|
|
1074
|
+
pending = keepOldest(native.pending, largestFitting(native.pending.length, (count) => fits([], [], keepOldest(native.pending, count))));
|
|
1075
|
+
({ records, baseline } = shedObservation(pending));
|
|
1076
|
+
}
|
|
1077
|
+
if (!fits(records, baseline, pending))
|
|
1078
|
+
throw new NativeStreamFrameUnrepresentable(controlNativeStreamFrameBytes(build(records, baseline, pending)));
|
|
1079
|
+
return ControlNativeStreamFrameSchema.parse(build(records, baseline, pending));
|
|
1080
|
+
}
|
|
1081
|
+
var StitchmuxNativeStreamProfileSchema = z16.object({
|
|
1082
|
+
bin: z16.string().startsWith("/"),
|
|
1083
|
+
argv: z16.tuple([z16.literal(STITCHMUX_NATIVE_STREAM_COMMAND)]),
|
|
1084
|
+
callerArgs: z16.object({ mode: z16.literal("none") }).strict(),
|
|
1085
|
+
stdin: z16.object({
|
|
1086
|
+
mode: z16.literal("text"),
|
|
1087
|
+
maxBytes: z16.literal(STITCHMUX_NATIVE_STREAM_MAX_INPUT_BYTES)
|
|
1088
|
+
}).strict(),
|
|
1089
|
+
env: z16.object({ inherit: z16.tuple([]), set: z16.object({}).strict() }).strict(),
|
|
1090
|
+
timeoutMs: z16.literal(900000),
|
|
1091
|
+
maxBytes: z16.literal(64 * 1024 * 1024),
|
|
1092
|
+
concurrency: z16.literal(4),
|
|
1093
|
+
format: z16.object({ mode: z16.literal("ndjson"), stableCursor: z16.literal(true) }).strict()
|
|
1094
|
+
}).strict();
|
|
1095
|
+
function createStitchmuxNativeStreamProfile(bin) {
|
|
1096
|
+
return StitchmuxNativeStreamProfileSchema.parse({
|
|
1097
|
+
bin,
|
|
1098
|
+
argv: [STITCHMUX_NATIVE_STREAM_COMMAND],
|
|
1099
|
+
callerArgs: { mode: "none" },
|
|
1100
|
+
stdin: { mode: "text", maxBytes: STITCHMUX_NATIVE_STREAM_MAX_INPUT_BYTES },
|
|
1101
|
+
env: { inherit: [], set: {} },
|
|
1102
|
+
timeoutMs: 900000,
|
|
1103
|
+
maxBytes: 64 * 1024 * 1024,
|
|
1104
|
+
concurrency: 4,
|
|
1105
|
+
format: { mode: "ndjson", stableCursor: true }
|
|
1106
|
+
});
|
|
1107
|
+
}
|
|
1108
|
+
// src/control/schema/runtimeOps.ts
|
|
1109
|
+
import { z as z19 } from "zod";
|
|
1110
|
+
|
|
1111
|
+
// src/agent/claude/native/commandSchema.ts
|
|
1112
|
+
import { z as z17 } from "zod";
|
|
1113
|
+
var ControlCommandSchema = z17.object({
|
|
1114
|
+
name: z17.string().min(1).max(128),
|
|
1115
|
+
description: z17.string().max(1024),
|
|
1116
|
+
argumentHint: z17.string().max(256),
|
|
1117
|
+
aliases: z17.array(z17.string().min(1).max(128)).max(16)
|
|
1118
|
+
}).strict();
|
|
1119
|
+
|
|
1120
|
+
// src/runtime/rewindSchema.ts
|
|
1121
|
+
import { z as z18 } from "zod";
|
|
1122
|
+
var RewindResultSchema = z18.object({
|
|
1123
|
+
canRewind: z18.boolean(),
|
|
1124
|
+
error: z18.string().max(512).nullable(),
|
|
1125
|
+
filesChanged: z18.array(z18.string().max(1024)).max(512),
|
|
1126
|
+
insertions: z18.number().int().nonnegative().nullable(),
|
|
1127
|
+
deletions: z18.number().int().nonnegative().nullable(),
|
|
1128
|
+
skippedLinks: z18.number().int().nonnegative().nullable()
|
|
1129
|
+
}).strict();
|
|
1130
|
+
|
|
1131
|
+
// src/control/schema/runtimeOps.ts
|
|
1132
|
+
var ControlCommandsReadSchema = ControlTargetSchema.strict();
|
|
1133
|
+
var ControlCommandCatalogSchema = z19.object({
|
|
1134
|
+
target: ManagedPeerSchema,
|
|
1135
|
+
data: z19.array(ControlCommandSchema).max(512)
|
|
1136
|
+
}).strict();
|
|
1137
|
+
var ControlRunCommandSchema = ControlTargetSchema.extend({
|
|
1138
|
+
command: z19.string().min(1).max(128),
|
|
1139
|
+
args: z19.string().max(4096).optional(),
|
|
1140
|
+
operationId: z19.uuid()
|
|
1141
|
+
}).strict();
|
|
1142
|
+
var ControlRunCommandReceiptSchema = z19.object({
|
|
1143
|
+
target: ManagedPeerSchema,
|
|
1144
|
+
accepted: z19.literal(true),
|
|
1145
|
+
turnId: z19.string().min(1).max(256),
|
|
1146
|
+
text: z19.string().min(1).max(4224)
|
|
1147
|
+
}).strict();
|
|
1148
|
+
var ControlPermissionModeSchema = ControlTargetSchema.extend({
|
|
1149
|
+
operationId: z19.uuid(),
|
|
1150
|
+
mode: PermissionModeSchema
|
|
1151
|
+
}).strict();
|
|
1152
|
+
var ControlPermissionModeReceiptSchema = z19.object({ target: ManagedPeerSchema, mode: PermissionModeSchema }).strict();
|
|
1153
|
+
var ControlPermissionReadSchema = ControlTargetSchema.extend({
|
|
1154
|
+
registrationGeneration: z19.uuid()
|
|
1155
|
+
}).strict();
|
|
1156
|
+
var ControlPermissionResultSchema = z19.object({
|
|
1157
|
+
target: ManagedPeerSchema,
|
|
1158
|
+
native: z19.object({ mode: PermissionModeSchema, observedAt: z19.string().max(64) }).strict().nullable(),
|
|
1159
|
+
supported: z19.array(PermissionModeSchema).max(16)
|
|
1160
|
+
}).strict();
|
|
1161
|
+
var ControlPermissionUpdateSchema = ControlTargetSchema.extend({
|
|
1162
|
+
registrationGeneration: z19.uuid(),
|
|
1163
|
+
operationId: z19.uuid(),
|
|
1164
|
+
expectedMode: PermissionModeSchema,
|
|
1165
|
+
mode: PermissionModeSchema
|
|
1166
|
+
}).strict();
|
|
1167
|
+
var ControlRewindSchema = ControlTargetSchema.extend({
|
|
1168
|
+
messageId: z19.uuid(),
|
|
1169
|
+
dryRun: z19.boolean().default(false),
|
|
1170
|
+
operationId: z19.uuid()
|
|
1171
|
+
}).strict();
|
|
1172
|
+
var ControlRewindReceiptSchema = z19.object({ target: ManagedPeerSchema, dryRun: z19.boolean(), result: RewindResultSchema }).strict();
|
|
1173
|
+
var ControlMcpReadSchema = ControlTargetSchema.strict();
|
|
1174
|
+
var ControlMcpListSchema = z19.object({ target: ManagedPeerSchema, data: z19.array(NativeMcpServerSchema).max(64) }).strict();
|
|
1175
|
+
var ControlMcpControlSchema = ControlTargetSchema.extend({
|
|
1176
|
+
server: z19.string().min(1).max(128),
|
|
1177
|
+
action: z19.enum(["enable", "disable", "reconnect"]),
|
|
1178
|
+
operationId: z19.uuid()
|
|
1179
|
+
}).strict();
|
|
1180
|
+
var ControlMcpControlReceiptSchema = z19.object({
|
|
1181
|
+
target: ManagedPeerSchema,
|
|
1182
|
+
server: z19.string().min(1).max(128),
|
|
1183
|
+
status: z19.string().min(1).max(64)
|
|
1184
|
+
}).strict();
|
|
1185
|
+
var ControlWaitSchema = ControlTargetSchema.extend({
|
|
1186
|
+
timeoutMs: z19.number().int().min(1).max(60000).default(30000)
|
|
1187
|
+
}).strict();
|
|
1188
|
+
var ControlWaitResultSchema = z19.object({
|
|
1189
|
+
target: ManagedPeerSchema,
|
|
1190
|
+
outcome: z19.enum(["idle", "completed", "interrupted", "failed", "timeout", "unavailable"]),
|
|
1191
|
+
state: ControlRowSchema.nullable()
|
|
1192
|
+
}).strict();
|
|
1193
|
+
function currentControlSnapshot(snapshot, now = Date.now()) {
|
|
1194
|
+
const current = structuredClone(snapshot);
|
|
1195
|
+
if (Date.parse(current.observedAt) > now) {
|
|
1196
|
+
current.status = "unavailable";
|
|
1197
|
+
current.reason = "clock-skew";
|
|
1198
|
+
}
|
|
1199
|
+
if (current.status === "live" && Date.parse(current.expiresAt) <= now) {
|
|
1200
|
+
current.status = "stale";
|
|
1201
|
+
current.reason = "observation-expired";
|
|
1202
|
+
}
|
|
1203
|
+
for (const row of current.sessions) {
|
|
1204
|
+
if (row.availability === "live" && (Date.parse(row.expiresAt) <= now || Date.parse(row.observedAt) > now || current.status !== "live")) {
|
|
1205
|
+
row.availability = current.status === "unavailable" ? "unavailable" : "stale";
|
|
1206
|
+
row.state = "unknown";
|
|
1207
|
+
row.reason = current.reason ?? "observation-expired";
|
|
1208
|
+
if (row.applicationPolicy !== undefined) {
|
|
1209
|
+
row.applicationPolicy.state = "unavailable";
|
|
1210
|
+
row.applicationPolicy.reason = row.reason;
|
|
1211
|
+
}
|
|
1212
|
+
delete row.nativeProfile;
|
|
1213
|
+
}
|
|
1214
|
+
}
|
|
1215
|
+
return current;
|
|
1216
|
+
}
|
|
1217
|
+
// src/control/transport/boundary.ts
|
|
1218
|
+
import { createClient } from "stitchkit";
|
|
1219
|
+
import { z as z50 } from "zod";
|
|
1220
|
+
|
|
1221
|
+
// src/control/schema/contract.ts
|
|
1222
|
+
import { defineContract as defineContract3 } from "stitchkit";
|
|
1223
|
+
import { z as z49 } from "zod";
|
|
1224
|
+
|
|
1225
|
+
// src/attachments/schema.ts
|
|
1226
|
+
import { z as z20 } from "zod";
|
|
1227
|
+
var AttachmentUploadSelectorSchema = z20.object({ target: ManagedPeerSchema, uploadId: z20.uuid() }).strict();
|
|
1228
|
+
var AttachmentBeginSchema = AttachmentUploadSelectorSchema.extend({
|
|
1229
|
+
mediaType: AttachmentMediaTypeSchema,
|
|
1230
|
+
totalBytes: z20.number().int().positive().max(ATTACHMENT_LIMITS.imageBytes),
|
|
1231
|
+
digest: AttachmentDigestSchema
|
|
1232
|
+
}).strict();
|
|
1233
|
+
var AttachmentChunkSchema = AttachmentUploadSelectorSchema.extend({
|
|
1234
|
+
offset: z20.number().int().nonnegative().max(ATTACHMENT_LIMITS.imageBytes),
|
|
1235
|
+
data: z20.string().min(4).max(ATTACHMENT_LIMITS.chunkBytes / 3 * 4).regex(/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/)
|
|
1236
|
+
}).strict();
|
|
1237
|
+
var AttachmentReadSchema = z20.object({
|
|
1238
|
+
target: ManagedPeerSchema,
|
|
1239
|
+
reference: AttachmentReferenceSchema,
|
|
1240
|
+
offset: z20.number().int().nonnegative().max(ATTACHMENT_LIMITS.imageBytes)
|
|
1241
|
+
}).strict();
|
|
1242
|
+
var AttachmentUploadReceiptSchema = z20.object({
|
|
1243
|
+
uploadId: z20.uuid(),
|
|
1244
|
+
receivedBytes: z20.number().int().nonnegative().max(ATTACHMENT_LIMITS.imageBytes),
|
|
1245
|
+
totalBytes: z20.number().int().positive().max(ATTACHMENT_LIMITS.imageBytes),
|
|
1246
|
+
expiresAt: z20.iso.datetime(),
|
|
1247
|
+
phase: z20.enum(["uploading", "verified", "retained"])
|
|
1248
|
+
}).strict();
|
|
1249
|
+
var AttachmentReadReceiptSchema = z20.object({
|
|
1250
|
+
reference: AttachmentReferenceSchema,
|
|
1251
|
+
offset: z20.number().int().nonnegative(),
|
|
1252
|
+
data: z20.string().max(ATTACHMENT_LIMITS.chunkBytes / 3 * 4),
|
|
1253
|
+
nextOffset: z20.number().int().nonnegative(),
|
|
1254
|
+
complete: z20.boolean()
|
|
1255
|
+
}).strict();
|
|
1256
|
+
var AttachmentCancelReceiptSchema = z20.object({ uploadId: z20.uuid(), cancelled: z20.literal(true) }).strict();
|
|
1257
|
+
var AttachmentRecordSchema = z20.object({
|
|
1258
|
+
id: z20.uuid(),
|
|
1259
|
+
target: ManagedPeerSchema,
|
|
1260
|
+
principal: ChatPrincipalSchema2,
|
|
1261
|
+
registration: z20.uuid(),
|
|
1262
|
+
mediaType: AttachmentMediaTypeSchema,
|
|
1263
|
+
bytes: z20.number().int().positive().max(ATTACHMENT_LIMITS.imageBytes),
|
|
1264
|
+
digest: AttachmentDigestSchema,
|
|
1265
|
+
received: z20.number().int().nonnegative().max(ATTACHMENT_LIMITS.imageBytes),
|
|
1266
|
+
phase: z20.enum(["uploading", "verified", "retained"]),
|
|
1267
|
+
createdAt: z20.number().int().nonnegative(),
|
|
1268
|
+
expiresAt: z20.number().int().nonnegative(),
|
|
1269
|
+
reference: AttachmentReferenceSchema.nullable()
|
|
1270
|
+
}).strict().refine((row) => row.received <= row.bytes && (row.phase === "uploading" ? row.reference === null : row.received === row.bytes && row.reference !== null && row.reference.id === row.id && row.reference.digest === row.digest && row.reference.bytes === row.bytes && row.reference.mediaType === row.mediaType));
|
|
1271
|
+
var AttachmentPinSchema = z20.object({
|
|
1272
|
+
messageId: z20.uuid(),
|
|
1273
|
+
target: ManagedPeerSchema,
|
|
1274
|
+
registration: z20.uuid(),
|
|
1275
|
+
principal: ChatPrincipalSchema2,
|
|
1276
|
+
references: AttachmentReferencesSchema
|
|
1277
|
+
}).strict();
|
|
1278
|
+
var AttachmentCancellationSchema = z20.object({
|
|
1279
|
+
id: z20.uuid(),
|
|
1280
|
+
target: ManagedPeerSchema,
|
|
1281
|
+
registration: z20.uuid(),
|
|
1282
|
+
principal: ChatPrincipalSchema2,
|
|
1283
|
+
expiresAt: z20.number().int().nonnegative()
|
|
1284
|
+
}).strict();
|
|
1285
|
+
var AttachmentStoreSchema = z20.object({
|
|
1286
|
+
version: z20.literal(1),
|
|
1287
|
+
records: z20.array(AttachmentRecordSchema).max(ATTACHMENT_LIMITS.records),
|
|
1288
|
+
pins: z20.array(AttachmentPinSchema).max(ATTACHMENT_LIMITS.pins),
|
|
1289
|
+
cancelled: z20.array(AttachmentCancellationSchema).max(ATTACHMENT_LIMITS.records)
|
|
1290
|
+
}).strict();
|
|
1291
|
+
|
|
1292
|
+
// src/chat/feedSchema.ts
|
|
1293
|
+
import { z as z22 } from "zod";
|
|
1294
|
+
|
|
1295
|
+
// src/chat/communicationReceiptSchema.ts
|
|
1296
|
+
import { z as z21 } from "zod";
|
|
1297
|
+
var CommunicationReceiptSchema = z21.object({
|
|
1298
|
+
rootMessageId: z21.uuid(),
|
|
1299
|
+
authorization: CommunicationAuthorizationSchema.refine((value) => value.basis === "user-instruction" || value.basis === "peer-letter", "The root must state an opening basis"),
|
|
1300
|
+
sourceLetter: z21.object({
|
|
1301
|
+
id: z21.uuid(),
|
|
1302
|
+
ts: z21.string(),
|
|
1303
|
+
from: ChatPrincipalSchema2,
|
|
1304
|
+
to: ChatTargetSchema2,
|
|
1305
|
+
task: z21.string().nullable(),
|
|
1306
|
+
body: z21.string().max(16384)
|
|
1307
|
+
}).strict().nullable()
|
|
1308
|
+
}).strict();
|
|
1309
|
+
|
|
1310
|
+
// src/chat/feedSchema.ts
|
|
1311
|
+
var LogRowSchema = z22.object({
|
|
1312
|
+
messageId: z22.uuid().nullable(),
|
|
1313
|
+
sender: ChatPrincipalSchema2.nullable(),
|
|
1314
|
+
target: ChatTargetSchema2.nullable(),
|
|
1315
|
+
origin: MessageOriginSchema2,
|
|
1316
|
+
communicationAuthorization: CommunicationAuthorizationSchema.optional().describe("Unverified caller claim; absence means no evidence was recorded, not permission."),
|
|
1317
|
+
notification: NotificationAudienceSchema2,
|
|
1318
|
+
communicationReceipt: CommunicationReceiptSchema.optional(),
|
|
1319
|
+
registrationGeneration: z22.uuid().nullable(),
|
|
1320
|
+
machine: z22.string(),
|
|
1321
|
+
ts: z22.string(),
|
|
1322
|
+
kind: z22.enum(["chat", "sent"]),
|
|
1323
|
+
from: z22.string(),
|
|
1324
|
+
to: z22.string(),
|
|
1325
|
+
task: z22.string().nullable().default(null),
|
|
1326
|
+
body: z22.string(),
|
|
1327
|
+
note: z22.string().default("")
|
|
1328
|
+
});
|
|
1329
|
+
var LogMachineSchema = z22.object({
|
|
1330
|
+
machine: z22.string(),
|
|
1331
|
+
ok: z22.boolean().default(true),
|
|
1332
|
+
error: z22.string().nullable().default(null)
|
|
1333
|
+
});
|
|
1334
|
+
var LogPayloadSchema = z22.object({
|
|
1335
|
+
machines: z22.array(LogMachineSchema).default([]),
|
|
1336
|
+
rows: z22.array(LogRowSchema).default([])
|
|
1337
|
+
});
|
|
1338
|
+
var LOG_FRAME_MAX_BYTES = 32 * 1024;
|
|
1339
|
+
var LogFrameSchema = z22.discriminatedUnion("kind", [
|
|
1340
|
+
z22.object({ kind: z22.literal("row"), cursor: z22.string(), row: LogRowSchema }).strict(),
|
|
1341
|
+
z22.object({ kind: z22.literal("machine"), cursor: z22.string(), machine: LogMachineSchema }).strict()
|
|
1342
|
+
]);
|
|
1343
|
+
|
|
1344
|
+
// src/chat/letterRequestSchema.ts
|
|
1345
|
+
import { z as z23 } from "zod";
|
|
1346
|
+
var LetterRequestSchema = z23.object({
|
|
1347
|
+
to: z23.string().min(1).max(512),
|
|
1348
|
+
body: z23.string().min(1).max(1024 * 1024),
|
|
1349
|
+
task: z23.string().min(1).max(512).nullable().default(null),
|
|
1350
|
+
interrupt: z23.boolean().default(false),
|
|
1351
|
+
onBehalfOf: z23.string().min(1).max(512).nullable().default(null),
|
|
1352
|
+
afterSeconds: z23.int().min(1).max(30 * 24 * 3600).nullable().default(null),
|
|
1353
|
+
toAgent: AgentKindSchema.nullable().default(null),
|
|
1354
|
+
toThread: z23.uuid().nullable().default(null),
|
|
1355
|
+
communicationAuthorization: CommunicationAuthorizationInputSchema.optional()
|
|
1356
|
+
}).strict();
|
|
1357
|
+
|
|
1358
|
+
// src/chat/messageOperationSchema.ts
|
|
1359
|
+
import { z as z25 } from "zod";
|
|
1360
|
+
|
|
1361
|
+
// src/chat/holdKind.ts
|
|
1362
|
+
import { z as z24 } from "zod";
|
|
1363
|
+
var ChatHoldKindSchema = z24.enum([
|
|
1364
|
+
"working",
|
|
1365
|
+
"queued-input",
|
|
1366
|
+
"menu",
|
|
1367
|
+
"input-busy",
|
|
1368
|
+
"not-drawn",
|
|
1369
|
+
"rate-limited",
|
|
1370
|
+
"human-typing",
|
|
1371
|
+
"not-settled",
|
|
1372
|
+
"sleeping",
|
|
1373
|
+
"other"
|
|
1374
|
+
]);
|
|
1375
|
+
|
|
1376
|
+
// src/chat/messageOperationSchema.ts
|
|
1377
|
+
var NativeMessageSessionSchema = z25.object({
|
|
1378
|
+
runtime: z25.enum(["codex", "opencode", "custom", "claude", "antigravity"]),
|
|
1379
|
+
id: z25.string().min(1).max(256)
|
|
1380
|
+
}).strict();
|
|
1381
|
+
var MESSAGE_OPERATION_LIMITS = {
|
|
1382
|
+
records: 256,
|
|
1383
|
+
bytes: 512 * 1024,
|
|
1384
|
+
terminalTtlMs: 7 * 24 * 60 * 60 * 1000
|
|
1385
|
+
};
|
|
1386
|
+
var NativeContinuationSchema = z25.object({
|
|
1387
|
+
requestId: z25.string().min(1).max(256),
|
|
1388
|
+
parentTurnId: z25.string().min(1).max(256),
|
|
1389
|
+
responseOperationId: z25.uuid(),
|
|
1390
|
+
responseFingerprint: z25.string().regex(/^[a-f0-9]{64}$/),
|
|
1391
|
+
turnId: z25.string().min(1).max(256),
|
|
1392
|
+
decision: z25.enum(["accept", "decline"])
|
|
1393
|
+
}).strict();
|
|
1394
|
+
var NativePendingApprovalSchema = z25.object({
|
|
1395
|
+
requestId: z25.string().min(1).max(256),
|
|
1396
|
+
turnId: z25.string().min(1).max(256),
|
|
1397
|
+
callId: z25.string().min(1).max(256)
|
|
1398
|
+
}).strict();
|
|
1399
|
+
var NativeContinuationsSchema = z25.array(NativeContinuationSchema).max(32);
|
|
1400
|
+
var MessageOperationReadSchema = z25.object({
|
|
1401
|
+
target: ManagedPeerSchema,
|
|
1402
|
+
registrationGeneration: z25.uuid(),
|
|
1403
|
+
messageId: z25.uuid()
|
|
1404
|
+
}).strict();
|
|
1405
|
+
var MessageOperationStateSchema = z25.enum([
|
|
1406
|
+
"queued",
|
|
1407
|
+
"uncertain",
|
|
1408
|
+
"admitted",
|
|
1409
|
+
"completed",
|
|
1410
|
+
"interrupted",
|
|
1411
|
+
"failed"
|
|
1412
|
+
]);
|
|
1413
|
+
var binding = {
|
|
1414
|
+
turnId: z25.string().min(1).max(256).nullable(),
|
|
1415
|
+
continuations: NativeContinuationsSchema.default([]),
|
|
1416
|
+
pendingApprovals: z25.array(NativePendingApprovalSchema).max(16).default([]),
|
|
1417
|
+
observedAt: z25.iso.datetime(),
|
|
1418
|
+
expiresAt: z25.iso.datetime().nullable()
|
|
1419
|
+
};
|
|
1420
|
+
var TERMINAL = ["completed", "interrupted", "failed"];
|
|
1421
|
+
var MessageOperationEvidenceSchema = z25.object({
|
|
1422
|
+
state: MessageOperationStateSchema,
|
|
1423
|
+
nativeSession: NativeMessageSessionSchema,
|
|
1424
|
+
...binding,
|
|
1425
|
+
hold: z25.object({
|
|
1426
|
+
kind: ChatHoldKindSchema,
|
|
1427
|
+
text: z25.string().max(512),
|
|
1428
|
+
heldForMs: z25.number().int().nonnegative()
|
|
1429
|
+
}).strict().nullable().default(null)
|
|
1430
|
+
}).strict().refine((value) => (value.state === "queued" || value.state === "uncertain") === (value.turnId === null), "Native binding does not match admission state").refine((value) => TERMINAL.includes(value.state) === (value.expiresAt !== null), "Retention deadline does not match terminal state");
|
|
1431
|
+
var MessageOperationResultSchema = MessageOperationReadSchema.extend({
|
|
1432
|
+
outcome: z25.enum(["available", "unavailable", "expired"]),
|
|
1433
|
+
evidence: MessageOperationEvidenceSchema.nullable()
|
|
1434
|
+
}).strict().refine((value) => value.outcome === "available" === (value.evidence !== null), "Unavailable evidence must not carry a binding");
|
|
1435
|
+
var MessageOperationRecordSchema = z25.object({
|
|
1436
|
+
messageId: z25.uuid(),
|
|
1437
|
+
principal: z25.string().regex(/^[0-9a-f]{64}$/),
|
|
1438
|
+
fingerprint: z25.string().regex(/^[0-9a-f]{64}$/),
|
|
1439
|
+
phase: z25.enum(["preparing", ...MessageOperationStateSchema.options]),
|
|
1440
|
+
...binding
|
|
1441
|
+
}).strict().refine((value) => ["preparing", "queued", "uncertain"].includes(value.phase) === (value.turnId === null), "Native binding does not match receipt phase").refine((value) => TERMINAL.includes(value.phase) === (value.expiresAt !== null), "Receipt retention deadline does not match terminal phase");
|
|
1442
|
+
var MessageOperationJournalSchema = z25.object({
|
|
1443
|
+
registrationGeneration: z25.uuid(),
|
|
1444
|
+
nativeSession: NativeMessageSessionSchema,
|
|
1445
|
+
records: z25.array(MessageOperationRecordSchema).max(MESSAGE_OPERATION_LIMITS.records)
|
|
1446
|
+
}).strict().refine((value) => new Set(value.records.map((record) => record.messageId)).size === value.records.length, "Duplicate message receipt").refine((value) => {
|
|
1447
|
+
const turns = value.records.flatMap((record) => record.turnId === null ? [] : [record.turnId]);
|
|
1448
|
+
return new Set(turns).size === turns.length;
|
|
1449
|
+
}, "Duplicate native turn binding");
|
|
1450
|
+
|
|
1451
|
+
// src/chat/sentLetterSchema.ts
|
|
1452
|
+
import { z as z26 } from "zod";
|
|
1453
|
+
var SentLetterStateSchema = z26.enum(["accepted", "held", "refused", "recorded", "undelivered"]).describe("accepted: in the recipient's ledger, shown to it at its next turn boundary. held: not accepted yet \u2014 its machine was not reached or answered no \u2014 and kept for retry. refused: its side will refuse it however often it is sent; settled, not retried. recorded: addressed where stitchmux does not deliver; mirrored to the owner. undelivered: held past the retry window.");
|
|
1454
|
+
var SentLetterSchema = z26.object({
|
|
1455
|
+
ref: z26.string().nullable().describe("What a thread-continuation to the same recipient cites as its sourceMessageRef; null unless the letter is accepted by a recipient that has a thread."),
|
|
1456
|
+
state: SentLetterStateSchema,
|
|
1457
|
+
id: z26.string().min(1),
|
|
1458
|
+
thread: z26.string().nullable(),
|
|
1459
|
+
to: z26.string().min(1),
|
|
1460
|
+
task: z26.string().nullable(),
|
|
1461
|
+
ts: z26.string(),
|
|
1462
|
+
preview: z26.string()
|
|
1463
|
+
});
|
|
1464
|
+
var SentListSchema = z26.object({
|
|
1465
|
+
sender: z26.string().min(1),
|
|
1466
|
+
sent: z26.array(SentLetterSchema),
|
|
1467
|
+
fromEarlierLives: z26.int().nonnegative()
|
|
1468
|
+
});
|
|
1469
|
+
var SendReceiptSchema = SentLetterSchema.extend({
|
|
1470
|
+
from: z26.string().min(1),
|
|
1471
|
+
notBefore: z26.string().nullable(),
|
|
1472
|
+
note: z26.string().nullable().describe("What the sender is told beside the state \u2014 why it is held, who refused it, where a recorded letter goes; null when the state says everything.")
|
|
1473
|
+
});
|
|
1474
|
+
|
|
1475
|
+
// src/context/exactMessageSchema.ts
|
|
1476
|
+
import { z as z28 } from "zod";
|
|
1477
|
+
|
|
1478
|
+
// src/context/messageSenderSchema.ts
|
|
1479
|
+
import { z as z27 } from "zod";
|
|
1480
|
+
var MessageSenderSchema = z27.object({
|
|
1481
|
+
verdict: z27.enum([
|
|
1482
|
+
"person",
|
|
1483
|
+
"session-letter",
|
|
1484
|
+
"routed-input",
|
|
1485
|
+
"harness",
|
|
1486
|
+
"stitchmux-keys",
|
|
1487
|
+
"unverifiable"
|
|
1488
|
+
]).describe("person: entered in the provider's own client \u2014 typed, pasted, dictated, sent while a turn was running \u2014 and not by stitchmux. session-letter: a letter from another session, delivered by stitchmux and found in its ledger. routed-input: input that came through a router or an application, whose tag says so; its author is not a verified person. harness: the harness speaking \u2014 a hook's output, a task notification, a reminder, the output of a local command. stitchmux-keys: typed into the pane by `stitchmux send`. unverifiable: it reads as a delivered letter or routed input, but this machine's ledger holds no such message \u2014 or the text was read cut and cannot be judged; read it whole by its id."),
|
|
1489
|
+
reason: z27.string().max(256)
|
|
1490
|
+
}).strict();
|
|
1491
|
+
|
|
1492
|
+
// src/context/exactMessageSchema.ts
|
|
1493
|
+
var EXACT_MESSAGE_LIMITS = {
|
|
1494
|
+
textBytes: 256 * 1024
|
|
1495
|
+
};
|
|
1496
|
+
var ExactMessageOutcomeSchema = z28.enum([
|
|
1497
|
+
"resolved",
|
|
1498
|
+
"not-found",
|
|
1499
|
+
"not-user-input",
|
|
1500
|
+
"ambiguous",
|
|
1501
|
+
"too-large",
|
|
1502
|
+
"unsupported",
|
|
1503
|
+
"unavailable"
|
|
1504
|
+
]);
|
|
1505
|
+
var ExactMessageResultSchema = z28.object({
|
|
1506
|
+
target: z28.string().min(1),
|
|
1507
|
+
messageId: z28.string().min(1),
|
|
1508
|
+
outcome: ExactMessageOutcomeSchema,
|
|
1509
|
+
observedAt: z28.iso.datetime(),
|
|
1510
|
+
message: z28.object({
|
|
1511
|
+
id: z28.string().min(1),
|
|
1512
|
+
seq: z28.int().positive(),
|
|
1513
|
+
recordedAt: z28.string().nullable(),
|
|
1514
|
+
text: z28.string(),
|
|
1515
|
+
sender: MessageSenderSchema
|
|
1516
|
+
}).strict().nullable()
|
|
1517
|
+
}).strict();
|
|
1518
|
+
|
|
1519
|
+
// src/context/schema.ts
|
|
1520
|
+
import { z as z29 } from "zod";
|
|
1521
|
+
var HISTORY_LIMITS = {
|
|
1522
|
+
entries: 64,
|
|
1523
|
+
textBytes: 128 * 1024,
|
|
1524
|
+
itemBytes: 16 * 1024,
|
|
1525
|
+
fileBytes: 384 * 1024,
|
|
1526
|
+
deadlineMs: 5000
|
|
1527
|
+
};
|
|
1528
|
+
var Id = z29.string().min(1).max(256);
|
|
1529
|
+
var NativeHistoryQuerySchema = z29.object({
|
|
1530
|
+
limit: z29.number().int().min(1).max(HISTORY_LIMITS.entries).default(32),
|
|
1531
|
+
cursor: z29.string().min(1).max(8192).optional()
|
|
1532
|
+
}).strict();
|
|
1533
|
+
var NativeHistoryEntrySchema = z29.object({
|
|
1534
|
+
turnId: Id,
|
|
1535
|
+
itemId: Id,
|
|
1536
|
+
kind: z29.enum(["user", "assistant", "reasoning-summary", "tool", "compaction", "other"]),
|
|
1537
|
+
text: z29.string().nullable(),
|
|
1538
|
+
omittedBytes: z29.number().int().nonnegative(),
|
|
1539
|
+
images: AttachmentReferencesSchema,
|
|
1540
|
+
omittedImages: z29.number().int().nonnegative(),
|
|
1541
|
+
status: z29.enum(["inProgress", "completed", "failed", "unknown"]),
|
|
1542
|
+
tool: ToolObservationSchema.nullable().default(null)
|
|
1543
|
+
}).strict();
|
|
1544
|
+
var NativeHistoryPageSchema = z29.object({
|
|
1545
|
+
runtime: z29.enum(["codex", "opencode", "custom", "claude", "antigravity"]),
|
|
1546
|
+
nativeId: Id,
|
|
1547
|
+
revision: z29.number().int().nonnegative(),
|
|
1548
|
+
entries: z29.array(NativeHistoryEntrySchema).max(HISTORY_LIMITS.entries),
|
|
1549
|
+
nextCursor: z29.string().max(8192).nullable(),
|
|
1550
|
+
completeness: z29.enum(["complete", "more", "unknown"]),
|
|
1551
|
+
omittedItems: z29.number().int().nonnegative(),
|
|
1552
|
+
omittedBytes: z29.number().int().nonnegative()
|
|
1553
|
+
}).strict();
|
|
1554
|
+
var CompactRequestSchema = z29.object({ operationId: z29.uuid(), generation: z29.uuid() }).strict();
|
|
1555
|
+
var NativeForkRequestSchema = z29.object({
|
|
1556
|
+
target: ManagedPeerSchema,
|
|
1557
|
+
registrationGeneration: z29.uuid(),
|
|
1558
|
+
generation: z29.uuid(),
|
|
1559
|
+
requestId: z29.uuid(),
|
|
1560
|
+
name: z29.string().min(1).max(128).regex(/^[a-zA-Z0-9][a-zA-Z0-9._-]*$/)
|
|
1561
|
+
}).strict();
|
|
1562
|
+
var ContextOperationSchema = z29.object({
|
|
1563
|
+
operationId: z29.uuid(),
|
|
1564
|
+
generation: z29.uuid(),
|
|
1565
|
+
state: z29.enum(["queued", "dispatching", "running", "completed", "uncertain", "rejected"]),
|
|
1566
|
+
revision: z29.number().int().nonnegative(),
|
|
1567
|
+
markerBefore: Id.nullable(),
|
|
1568
|
+
createdAt: z29.number(),
|
|
1569
|
+
updatedAt: z29.number()
|
|
1570
|
+
}).strict();
|
|
1571
|
+
|
|
1572
|
+
// src/external/contentSchema.ts
|
|
1573
|
+
import { z as z30 } from "zod";
|
|
1574
|
+
var EXTERNAL_CONTENT_LIMITS = {
|
|
1575
|
+
sourceBytes: 8 * 1024 * 1024,
|
|
1576
|
+
chunkBytes: 256 * 1024,
|
|
1577
|
+
recordBytes: 256 * 1024,
|
|
1578
|
+
snapshotBytes: 16 * 1024 * 1024,
|
|
1579
|
+
cacheBytes: 64 * 1024 * 1024,
|
|
1580
|
+
snapshots: 16,
|
|
1581
|
+
concurrentBuilds: 2,
|
|
1582
|
+
snapshotTtlMs: 10 * 60 * 1000,
|
|
1583
|
+
metadataBytes: 256 * 1024,
|
|
1584
|
+
textCharacters: 4096,
|
|
1585
|
+
entries: 64,
|
|
1586
|
+
lookupEntries: 8192,
|
|
1587
|
+
lookupDepth: 8,
|
|
1588
|
+
responseBytes: 384 * 1024
|
|
1589
|
+
};
|
|
1590
|
+
var ExternalContentTargetSchema = z30.object({
|
|
1591
|
+
provider: z30.enum(["codex", "claude"]),
|
|
1592
|
+
machine: z30.string().regex(RC_PREFIX_RE).max(128),
|
|
1593
|
+
threadId: z30.uuid()
|
|
1594
|
+
}).strict();
|
|
1595
|
+
var ExternalContentReadSchema = z30.object({
|
|
1596
|
+
target: ExternalContentTargetSchema,
|
|
1597
|
+
cursor: z30.string().max(2048).nullable().default(null),
|
|
1598
|
+
limit: z30.number().int().min(1).max(EXTERNAL_CONTENT_LIMITS.entries).default(32)
|
|
1599
|
+
}).strict();
|
|
1600
|
+
var ExternalContentSelectorSchema = z30.object({ target: ExternalContentTargetSchema }).strict();
|
|
1601
|
+
var ExternalContentStateSchema = z30.enum([
|
|
1602
|
+
"available",
|
|
1603
|
+
"history-absent",
|
|
1604
|
+
"unavailable",
|
|
1605
|
+
"stale"
|
|
1606
|
+
]);
|
|
1607
|
+
var ExternalContentEntrySchema = z30.object({
|
|
1608
|
+
id: z30.string().max(128),
|
|
1609
|
+
role: z30.enum(["user", "assistant"]),
|
|
1610
|
+
text: z30.string().max(EXTERNAL_CONTENT_LIMITS.textCharacters),
|
|
1611
|
+
truncated: z30.boolean()
|
|
1612
|
+
}).strict();
|
|
1613
|
+
var ExternalContentResultSchema = z30.object({
|
|
1614
|
+
target: ExternalContentTargetSchema,
|
|
1615
|
+
outcome: ExternalContentStateSchema,
|
|
1616
|
+
revision: z30.string().regex(/^[a-f0-9]{64}$/).nullable(),
|
|
1617
|
+
observedAt: z30.iso.datetime(),
|
|
1618
|
+
entries: z30.array(ExternalContentEntrySchema).max(EXTERNAL_CONTENT_LIMITS.entries),
|
|
1619
|
+
nextCursor: z30.string().max(2048).nullable(),
|
|
1620
|
+
truncated: z30.boolean(),
|
|
1621
|
+
omittedRecords: z30.number().int().nonnegative(),
|
|
1622
|
+
earlierFiles: z30.number().int().nonnegative(),
|
|
1623
|
+
sourceWindow: z30.strictObject({
|
|
1624
|
+
startByte: z30.int().nonnegative(),
|
|
1625
|
+
endByte: z30.int().nonnegative()
|
|
1626
|
+
}).nullable()
|
|
1627
|
+
}).strict();
|
|
1628
|
+
var UnsupportedControlSchema = z30.object({
|
|
1629
|
+
supported: z30.literal(false),
|
|
1630
|
+
reason: z30.literal("not-exposed")
|
|
1631
|
+
}).strict();
|
|
1632
|
+
var ExternalContentCapabilitiesSchema = z30.object({
|
|
1633
|
+
target: ExternalContentTargetSchema,
|
|
1634
|
+
history: z30.object({
|
|
1635
|
+
outcome: ExternalContentStateSchema,
|
|
1636
|
+
source: z30.literal("provider-storage"),
|
|
1637
|
+
projection: z30.literal("authored-text"),
|
|
1638
|
+
pageEntries: z30.literal(EXTERNAL_CONTENT_LIMITS.entries),
|
|
1639
|
+
sourceBytes: z30.literal(EXTERNAL_CONTENT_LIMITS.sourceBytes)
|
|
1640
|
+
}).strict(),
|
|
1641
|
+
control: z30.object({
|
|
1642
|
+
message: UnsupportedControlSchema,
|
|
1643
|
+
interrupt: UnsupportedControlSchema,
|
|
1644
|
+
respond: UnsupportedControlSchema,
|
|
1645
|
+
fork: UnsupportedControlSchema,
|
|
1646
|
+
compact: UnsupportedControlSchema
|
|
1647
|
+
}).strict()
|
|
1648
|
+
}).strict();
|
|
1649
|
+
|
|
1650
|
+
// src/external/messageSchema.ts
|
|
1651
|
+
import { z as z31 } from "zod";
|
|
1652
|
+
var EXTERNAL_MESSAGE_LIMITS = {
|
|
1653
|
+
sourceBytes: 2 * 1024 * 1024 * 1024,
|
|
1654
|
+
recordBytes: 4 * 1024 * 1024,
|
|
1655
|
+
textBytes: 256 * 1024,
|
|
1656
|
+
turns: 1e5
|
|
1657
|
+
};
|
|
1658
|
+
var ExternalMessageReadSchema = z31.object({ target: ExternalContentTargetSchema, messageId: z31.uuid() }).strict();
|
|
1659
|
+
var ExternalMessageAuthorshipSchema = z31.object({
|
|
1660
|
+
verdict: z31.enum(["person", "not-person", "unverifiable"]),
|
|
1661
|
+
trigger: z31.string().max(64).nullable(),
|
|
1662
|
+
position: z31.enum(["turn-opening", "mid-turn"]),
|
|
1663
|
+
reason: z31.string().max(256)
|
|
1664
|
+
}).strict();
|
|
1665
|
+
var ExternalMessageSchema = z31.object({
|
|
1666
|
+
id: z31.uuid(),
|
|
1667
|
+
clientId: z31.string().max(128).nullable(),
|
|
1668
|
+
turnId: z31.string().max(128),
|
|
1669
|
+
recordedAt: z31.iso.datetime().nullable(),
|
|
1670
|
+
text: z31.string(),
|
|
1671
|
+
images: z31.number().int().nonnegative(),
|
|
1672
|
+
authorship: ExternalMessageAuthorshipSchema
|
|
1673
|
+
}).strict();
|
|
1674
|
+
var ExternalMessageOutcomeSchema = z31.enum([
|
|
1675
|
+
"resolved",
|
|
1676
|
+
"not-found",
|
|
1677
|
+
"not-user-input",
|
|
1678
|
+
"ambiguous",
|
|
1679
|
+
"too-large",
|
|
1680
|
+
"unsupported",
|
|
1681
|
+
"history-absent",
|
|
1682
|
+
"unavailable"
|
|
1683
|
+
]);
|
|
1684
|
+
var ExternalMessageResultSchema = z31.object({
|
|
1685
|
+
target: ExternalContentTargetSchema,
|
|
1686
|
+
messageId: z31.uuid(),
|
|
1687
|
+
outcome: ExternalMessageOutcomeSchema,
|
|
1688
|
+
revision: z31.string().regex(/^[a-f0-9]{64}$/).nullable(),
|
|
1689
|
+
observedAt: z31.iso.datetime(),
|
|
1690
|
+
message: ExternalMessageSchema.nullable()
|
|
1691
|
+
}).strict();
|
|
1692
|
+
|
|
1693
|
+
// src/fleet/fleetSchema.ts
|
|
1694
|
+
import { z as z34 } from "zod";
|
|
1695
|
+
|
|
1696
|
+
// src/events/schema.ts
|
|
1697
|
+
import { z as z32 } from "zod";
|
|
1698
|
+
var SessionEventKindSchema = z32.enum([
|
|
1699
|
+
"turn-start",
|
|
1700
|
+
"turn-end",
|
|
1701
|
+
"waiting",
|
|
1702
|
+
"resumed",
|
|
1703
|
+
"session-start",
|
|
1704
|
+
"session-stop",
|
|
1705
|
+
"session-blocked",
|
|
1706
|
+
"inventory"
|
|
1707
|
+
]);
|
|
1708
|
+
var InventoryRowSchema = z32.object({
|
|
1709
|
+
name: z32.string().min(1),
|
|
1710
|
+
agent: AgentKindSchema,
|
|
1711
|
+
uuid: z32.uuid(),
|
|
1712
|
+
address: z32.string().min(1),
|
|
1713
|
+
archived: z32.boolean(),
|
|
1714
|
+
running: z32.boolean(),
|
|
1715
|
+
sleeping: z32.boolean().optional(),
|
|
1716
|
+
pinned: z32.boolean().optional(),
|
|
1717
|
+
state: z32.string().min(1),
|
|
1718
|
+
model: z32.string().nullable(),
|
|
1719
|
+
contextPercent: z32.number().int().min(0).max(100).nullable(),
|
|
1720
|
+
startedAt: z32.iso.datetime().nullable(),
|
|
1721
|
+
turnStartedAt: z32.iso.datetime().nullable(),
|
|
1722
|
+
step: z32.object({
|
|
1723
|
+
kind: z32.string(),
|
|
1724
|
+
role: z32.string(),
|
|
1725
|
+
toolName: z32.string().nullable(),
|
|
1726
|
+
at: z32.string().nullable()
|
|
1727
|
+
}).loose().nullable()
|
|
1728
|
+
}).loose();
|
|
1729
|
+
var InventoryRevisionSchema = z32.object({
|
|
1730
|
+
generation: z32.uuid(),
|
|
1731
|
+
sequence: z32.number().int().nonnegative()
|
|
1732
|
+
});
|
|
1733
|
+
var InventorySnapshotSchema = InventoryRevisionSchema.extend({
|
|
1734
|
+
pid: z32.number().int().positive(),
|
|
1735
|
+
sessions: z32.array(InventoryRowSchema)
|
|
1736
|
+
}).loose();
|
|
1737
|
+
var SessionEventSchema = z32.object({
|
|
1738
|
+
v: z32.number().int().positive(),
|
|
1739
|
+
id: z32.uuid(),
|
|
1740
|
+
ts: z32.iso.datetime(),
|
|
1741
|
+
machine: z32.string().regex(RC_PREFIX_RE),
|
|
1742
|
+
session: z32.string().min(1).regex(SESSION_NAME_RE),
|
|
1743
|
+
agent: AgentKindSchema,
|
|
1744
|
+
threadId: z32.uuid(),
|
|
1745
|
+
event: SessionEventKindSchema,
|
|
1746
|
+
durationMs: z32.number().nonnegative().optional(),
|
|
1747
|
+
interrupted: z32.boolean().optional(),
|
|
1748
|
+
detail: z32.string().optional(),
|
|
1749
|
+
inventory: InventoryRevisionSchema.optional(),
|
|
1750
|
+
row: InventoryRowSchema.nullable().optional()
|
|
1751
|
+
}).loose();
|
|
1752
|
+
|
|
1753
|
+
// src/inventory/listSchema.ts
|
|
1754
|
+
import { z as z33 } from "zod";
|
|
1755
|
+
var SessionStateSchema = z33.enum(["working", "idle", "stopped", "blocked", "external"]);
|
|
1756
|
+
var ContextInfoSchema = z33.object({
|
|
1757
|
+
text: z33.string().nullable(),
|
|
1758
|
+
usedTokens: z33.number().nullable(),
|
|
1759
|
+
limitTokens: z33.number().nullable(),
|
|
1760
|
+
percent: z33.number().nullable(),
|
|
1761
|
+
rawLimitTokens: z33.number().nullable().default(null),
|
|
1762
|
+
window: z33.enum(["model-limit", "compaction-window"]).nullable().default(null)
|
|
1763
|
+
});
|
|
1764
|
+
var ListItemSchema = z33.object({
|
|
1765
|
+
name: z33.string(),
|
|
1766
|
+
agent: AgentKindSchema,
|
|
1767
|
+
dir: z33.string(),
|
|
1768
|
+
uuid: z33.string(),
|
|
1769
|
+
rc: z33.string(),
|
|
1770
|
+
running: z33.boolean(),
|
|
1771
|
+
archived: z33.boolean(),
|
|
1772
|
+
sleeping: z33.boolean().default(false),
|
|
1773
|
+
pinned: z33.boolean().default(false),
|
|
1774
|
+
state: SessionStateSchema,
|
|
1775
|
+
atPrompt: z33.string().nullable().default(null),
|
|
1776
|
+
waitingFor: z33.string().nullable().default(null),
|
|
1777
|
+
lifecycleError: z33.string().nullable(),
|
|
1778
|
+
model: z33.string().nullable(),
|
|
1779
|
+
modelId: z33.string().nullable().default(null),
|
|
1780
|
+
context: ContextInfoSchema,
|
|
1781
|
+
uptime: z33.object({ text: z33.string().nullable(), seconds: z33.number().nullable() }),
|
|
1782
|
+
stale: z33.array(z33.string()).default([]),
|
|
1783
|
+
staleUnknown: z33.string().max(200).nullable().default(null),
|
|
1784
|
+
role: z33.string().nullable().default(null),
|
|
1785
|
+
turnStartedAt: z33.string().nullable().default(null),
|
|
1786
|
+
account: NativeAccountSchema.nullable().default(null),
|
|
1787
|
+
planLimits: PlanLimitsSchema.loose().nullable().default(null),
|
|
1788
|
+
costUsd: z33.number().nullable().default(null),
|
|
1789
|
+
envFile: z33.object({ path: z33.string(), present: z33.boolean() }).nullable().default(null),
|
|
1790
|
+
profile: z33.string().optional(),
|
|
1791
|
+
createdAt: z33.string().nullable(),
|
|
1792
|
+
lastMessage: TranscriptMessageSchema.nullable(),
|
|
1793
|
+
letters: z33.object({ total: z33.number().int().nonnegative(), lastAt: z33.string().nullable() }).nullable().default(null),
|
|
1794
|
+
tmux: z33.object({
|
|
1795
|
+
socket: z33.string().nullable(),
|
|
1796
|
+
session: z33.string(),
|
|
1797
|
+
agentPane: z33.string().nullable()
|
|
1798
|
+
}).nullable().default(null)
|
|
1799
|
+
});
|
|
1800
|
+
var ReleaseStandingSchema = z33.object({
|
|
1801
|
+
current: z33.string(),
|
|
1802
|
+
latest: z33.string().nullable().default(null),
|
|
1803
|
+
latestAt: z33.string().nullable().default(null),
|
|
1804
|
+
checkedAt: z33.string().nullable().default(null),
|
|
1805
|
+
ok: z33.boolean().default(true),
|
|
1806
|
+
checksOverdue: z33.boolean().default(false)
|
|
1807
|
+
});
|
|
1808
|
+
var ListJsonSchema = z33.object({
|
|
1809
|
+
version: z33.string(),
|
|
1810
|
+
generatedAt: z33.string(),
|
|
1811
|
+
rcPrefix: z33.string(),
|
|
1812
|
+
stateDir: z33.string(),
|
|
1813
|
+
release: ReleaseStandingSchema,
|
|
1814
|
+
sessions: z33.array(ListItemSchema),
|
|
1815
|
+
inventory: InventorySnapshotSchema.nullable()
|
|
1816
|
+
});
|
|
1817
|
+
|
|
1818
|
+
// src/fleet/fleetSchema.ts
|
|
1819
|
+
var RemoteSessionSchema = ListItemSchema.extend({
|
|
1820
|
+
agent: AgentKindSchema.nullable().default(null),
|
|
1821
|
+
state: z34.string().default("?"),
|
|
1822
|
+
running: z34.boolean().default(false),
|
|
1823
|
+
archived: z34.boolean().default(false),
|
|
1824
|
+
dir: z34.string().nullable().default(null),
|
|
1825
|
+
uuid: z34.string().nullable().default(null),
|
|
1826
|
+
rc: z34.string().nullable().default(null),
|
|
1827
|
+
lifecycleError: z34.string().nullable().default(null),
|
|
1828
|
+
model: z34.string().nullable().default(null),
|
|
1829
|
+
createdAt: z34.string().nullable().default(null),
|
|
1830
|
+
lastMessage: TranscriptMessageSchema.partial().extend({
|
|
1831
|
+
kind: z34.string().optional(),
|
|
1832
|
+
role: z34.string().optional(),
|
|
1833
|
+
status: z34.string().nullish()
|
|
1834
|
+
}).loose().nullable().default(null),
|
|
1835
|
+
uptime: z34.object({
|
|
1836
|
+
text: z34.string().nullable().default(null),
|
|
1837
|
+
seconds: z34.number().nullable().default(null)
|
|
1838
|
+
}).default(() => ({ text: null, seconds: null })),
|
|
1839
|
+
context: ContextInfoSchema.default(() => ({
|
|
1840
|
+
text: null,
|
|
1841
|
+
usedTokens: null,
|
|
1842
|
+
limitTokens: null,
|
|
1843
|
+
percent: null,
|
|
1844
|
+
rawLimitTokens: null,
|
|
1845
|
+
window: null
|
|
1846
|
+
}))
|
|
1847
|
+
}).loose();
|
|
1848
|
+
var ProjectedPlanLimitsSchema = PlanLimitsSchema.extend({
|
|
1849
|
+
stale: z34.boolean(),
|
|
1850
|
+
windows: z34.array(PlanWindowSchema.extend({ expired: z34.boolean() })).max(32)
|
|
1851
|
+
});
|
|
1852
|
+
var AccountProfileSchema = z34.object({
|
|
1853
|
+
machine: z34.string(),
|
|
1854
|
+
profile: z34.string(),
|
|
1855
|
+
sessions: z34.int().nonnegative(),
|
|
1856
|
+
error: z34.string().nullable(),
|
|
1857
|
+
attemptedAt: z34.string().nullable()
|
|
1858
|
+
});
|
|
1859
|
+
var FleetAccountSchema = z34.object({
|
|
1860
|
+
id: z34.string(),
|
|
1861
|
+
label: z34.string(),
|
|
1862
|
+
provider: z34.string().nullable(),
|
|
1863
|
+
plan: z34.string().nullable(),
|
|
1864
|
+
subscription: z34.string().nullable(),
|
|
1865
|
+
costUsd: z34.number().nullable(),
|
|
1866
|
+
sessions: z34.array(z34.string()),
|
|
1867
|
+
profiles: z34.array(AccountProfileSchema),
|
|
1868
|
+
limits: ProjectedPlanLimitsSchema.nullable()
|
|
1869
|
+
});
|
|
1870
|
+
var FleetMachineSchema = z34.object({
|
|
1871
|
+
machine: z34.string(),
|
|
1872
|
+
alias: z34.string().nullable(),
|
|
1873
|
+
ok: z34.boolean(),
|
|
1874
|
+
error: z34.string().nullable(),
|
|
1875
|
+
version: z34.string(),
|
|
1876
|
+
release: ReleaseStandingSchema.nullable(),
|
|
1877
|
+
behind: z34.enum(["patch", "minor", "major"]).nullable(),
|
|
1878
|
+
sessions: z34.array(RemoteSessionSchema),
|
|
1879
|
+
inventory: InventorySnapshotSchema.nullable(),
|
|
1880
|
+
fallback: z34.string().nullable()
|
|
1881
|
+
});
|
|
1882
|
+
var FleetViewSchema = z34.object({
|
|
1883
|
+
latest: z34.string().nullable(),
|
|
1884
|
+
latestAt: z34.string().nullable(),
|
|
1885
|
+
machines: z34.array(FleetMachineSchema)
|
|
1886
|
+
});
|
|
1887
|
+
var FleetAnswerSchema = FleetViewSchema.extend({
|
|
1888
|
+
version: z34.string(),
|
|
1889
|
+
generatedAt: z34.iso.datetime(),
|
|
1890
|
+
accounts: z34.array(FleetAccountSchema)
|
|
1891
|
+
});
|
|
1892
|
+
|
|
1893
|
+
// src/session/identitySchema.ts
|
|
1894
|
+
import { z as z35 } from "zod";
|
|
1895
|
+
var DeclaredProjectSchema = z35.string().min(1).describe("The project the repository of `dir` belongs to, as repositories declare it in `.passport.json`: the `identity.project` of the checkout itself, or of a checkout in the same parent directory whose `source.repositoryId` names this repository; for a directory that holds checkouts, the one project all of them resolve to. The key exactly as written (a slug such as `acme-api`, without a slash, the same for every repository of one product). Absent when nothing declares one or the declarations disagree; never derived from the name of a repository or of a directory.");
|
|
1896
|
+
var SessionLifeSchema = z35.object({
|
|
1897
|
+
id: z35.string().min(1),
|
|
1898
|
+
current: z35.boolean(),
|
|
1899
|
+
firstAt: z35.iso.datetime().nullable(),
|
|
1900
|
+
lastAt: z35.iso.datetime().nullable()
|
|
1901
|
+
});
|
|
1902
|
+
var SessionIdentitySchema = z35.object({
|
|
1903
|
+
address: z35.string().min(1),
|
|
1904
|
+
machine: z35.string().regex(RC_PREFIX_RE),
|
|
1905
|
+
name: z35.string().regex(SESSION_NAME_RE),
|
|
1906
|
+
provider: AgentKindSchema,
|
|
1907
|
+
title: z35.string().min(1),
|
|
1908
|
+
dir: z35.string().startsWith("/"),
|
|
1909
|
+
repository: z35.string().nullable(),
|
|
1910
|
+
project: DeclaredProjectSchema.optional(),
|
|
1911
|
+
checkouts: z35.array(z35.object({
|
|
1912
|
+
dir: z35.string().startsWith("/"),
|
|
1913
|
+
repository: z35.string().nullable(),
|
|
1914
|
+
role: z35.string().min(1).describe("The role the checkout declares (`identity.role`); failing that `private-workspace` for one that names the source it is the working half of, and `source` for any other."),
|
|
1915
|
+
current: z35.boolean().describe("The session's directory is in this checkout.")
|
|
1916
|
+
})).optional().describe("The checkouts of the session's project on its machine: those in one directory \u2014 beside the session's own checkout, or inside the folder it was opened on \u2014 that resolve to the same `project`. Where a product's private working half is, it holds the task queue and the working rules. Present with `project`."),
|
|
1917
|
+
archived: z35.boolean(),
|
|
1918
|
+
running: z35.boolean().nullable(),
|
|
1919
|
+
sleeping: z35.boolean().optional(),
|
|
1920
|
+
pinned: z35.boolean().optional(),
|
|
1921
|
+
conversation: z35.string().min(1),
|
|
1922
|
+
conversations: z35.array(SessionLifeSchema).min(1),
|
|
1923
|
+
createdAt: z35.iso.datetime().nullable(),
|
|
1924
|
+
lastActivityAt: z35.iso.datetime().nullable()
|
|
1925
|
+
});
|
|
1926
|
+
var StrayConversationSchema = z35.object({
|
|
1927
|
+
provider: z35.enum(["claude", "codex"]),
|
|
1928
|
+
id: z35.string().min(1),
|
|
1929
|
+
machine: z35.string().regex(RC_PREFIX_RE),
|
|
1930
|
+
address: z35.string().min(1),
|
|
1931
|
+
title: z35.string().nullable(),
|
|
1932
|
+
dir: z35.string().nullable(),
|
|
1933
|
+
repository: z35.string().nullable(),
|
|
1934
|
+
project: DeclaredProjectSchema.optional()
|
|
1935
|
+
});
|
|
1936
|
+
var WhoisMachineSchema = z35.union([
|
|
1937
|
+
z35.object({ machine: z35.string().min(1), status: z35.literal("asked") }),
|
|
1938
|
+
z35.object({ machine: z35.string().min(1), status: z35.literal("unavailable"), error: z35.string() })
|
|
1939
|
+
]);
|
|
1940
|
+
var WhoisBySchema = z35.enum(["address", "title", "conversation"]);
|
|
1941
|
+
var WhoisCandidateSchema = z35.object({ by: WhoisBySchema, session: SessionIdentitySchema });
|
|
1942
|
+
var WhoisAnswerSchema = z35.object({
|
|
1943
|
+
query: z35.string(),
|
|
1944
|
+
found: z35.enum(["session", "conversation", "ambiguous", "none"]),
|
|
1945
|
+
by: WhoisBySchema.nullable(),
|
|
1946
|
+
session: SessionIdentitySchema.nullable(),
|
|
1947
|
+
conversation: StrayConversationSchema.nullable(),
|
|
1948
|
+
candidates: z35.array(WhoisCandidateSchema),
|
|
1949
|
+
machines: z35.array(WhoisMachineSchema)
|
|
1950
|
+
});
|
|
1951
|
+
var WhoisListSchema = z35.object({
|
|
1952
|
+
sessions: z35.array(SessionIdentitySchema),
|
|
1953
|
+
machines: z35.array(WhoisMachineSchema)
|
|
1954
|
+
});
|
|
1955
|
+
var WhoisEventSchema = z35.union([
|
|
1956
|
+
z35.object({ event: z35.literal("session"), session: SessionIdentitySchema }),
|
|
1957
|
+
...WhoisMachineSchema.options.map((standing) => standing.extend({ event: z35.literal("machine") }).describe("A machine as the follower last found it: sent after the first `session` lines of that machine, and again each time its status or the reason changes. The sessions of an unavailable machine are not known to be gone.")),
|
|
1958
|
+
z35.object({
|
|
1959
|
+
event: z35.literal("gone"),
|
|
1960
|
+
address: z35.string().min(1),
|
|
1961
|
+
machine: z35.string().regex(RC_PREFIX_RE),
|
|
1962
|
+
name: z35.string().regex(SESSION_NAME_RE)
|
|
1963
|
+
})
|
|
1964
|
+
]);
|
|
1965
|
+
|
|
1966
|
+
// src/session/sleep/schema.ts
|
|
1967
|
+
import { z as z36 } from "zod";
|
|
1968
|
+
var ProcessIdentitySchema = z36.object({ pid: z36.number().int().positive(), startTime: z36.string() }).strict();
|
|
1969
|
+
var SleepTargetSchema = z36.object({ target: ManagedPeerSchema, registrationGeneration: z36.uuid() }).strict();
|
|
1970
|
+
var IdleProofSchema = SleepTargetSchema.extend({
|
|
1971
|
+
revision: z36.string().regex(/^[a-f0-9]{64}$/),
|
|
1972
|
+
generation: z36.uuid().nullable(),
|
|
1973
|
+
observedAt: z36.iso.datetime(),
|
|
1974
|
+
eligible: z36.boolean(),
|
|
1975
|
+
reason: z36.string().nullable(),
|
|
1976
|
+
run: z36.enum(["idle", "active", "unknown"]),
|
|
1977
|
+
queue: z36.number().int().nonnegative().nullable(),
|
|
1978
|
+
approvals: z36.number().int().nonnegative().nullable(),
|
|
1979
|
+
children: z36.number().int().nonnegative().nullable(),
|
|
1980
|
+
background: z36.number().int().nonnegative().nullable(),
|
|
1981
|
+
processes: z36.array(ProcessIdentitySchema).max(256)
|
|
1982
|
+
}).strict();
|
|
1983
|
+
var SleepRequestSchema = SleepTargetSchema.extend({
|
|
1984
|
+
operationId: z36.uuid(),
|
|
1985
|
+
revision: z36.string().regex(/^[a-f0-9]{64}$/),
|
|
1986
|
+
forcePolicy: z36.boolean().optional()
|
|
1987
|
+
}).strict();
|
|
1988
|
+
var WakeRequestSchema = SleepTargetSchema.extend({ operationId: z36.uuid() }).strict();
|
|
1989
|
+
var PinRequestSchema = z36.object({
|
|
1990
|
+
target: ManagedPeerSchema,
|
|
1991
|
+
pinned: z36.boolean()
|
|
1992
|
+
}).strict();
|
|
1993
|
+
var PinReceiptSchema = z36.object({
|
|
1994
|
+
target: ManagedPeerSchema,
|
|
1995
|
+
pinned: z36.boolean()
|
|
1996
|
+
}).strict();
|
|
1997
|
+
var SleepRecordSchema = SleepTargetSchema.extend({
|
|
1998
|
+
operationId: z36.uuid(),
|
|
1999
|
+
proof: IdleProofSchema,
|
|
2000
|
+
phase: z36.enum(["requested", "sleeping", "waking", "awake"]),
|
|
2001
|
+
forcePolicy: z36.boolean().optional(),
|
|
2002
|
+
updatedAt: z36.iso.datetime()
|
|
2003
|
+
}).strict();
|
|
2004
|
+
var SleepReceiptSchema = SleepTargetSchema.extend({
|
|
2005
|
+
operationId: z36.uuid(),
|
|
2006
|
+
state: z36.enum(["sleeping", "awake", "unchanged"]),
|
|
2007
|
+
release: z36.enum(["processReleased", "unsupported"]),
|
|
2008
|
+
nativeId: z36.string().nullable(),
|
|
2009
|
+
duplicate: z36.boolean()
|
|
2010
|
+
}).strict();
|
|
2011
|
+
var SleepIdleRequestSchema = z36.object({
|
|
2012
|
+
idleAfterMinutes: z36.number().int().min(1).max(43200),
|
|
2013
|
+
dryRun: z36.boolean().default(false)
|
|
2014
|
+
}).strict();
|
|
2015
|
+
var SleepIdleReceiptSchema = z36.object({
|
|
2016
|
+
target: ManagedPeerSchema,
|
|
2017
|
+
outcome: z36.enum(["slept", "would-sleep", "skipped", "refused", "not-attempted"]),
|
|
2018
|
+
code: z36.string().min(1).max(64).nullable(),
|
|
2019
|
+
reason: z36.string().max(1024).nullable()
|
|
2020
|
+
}).strict();
|
|
2021
|
+
var SleepIdleResultSchema = z36.object({
|
|
2022
|
+
machine: z36.string().min(1).max(128),
|
|
2023
|
+
dryRun: z36.boolean(),
|
|
2024
|
+
receipts: z36.array(SleepIdleReceiptSchema).max(256)
|
|
2025
|
+
}).strict();
|
|
2026
|
+
|
|
2027
|
+
// src/steering/schema.ts
|
|
2028
|
+
import { z as z37 } from "zod";
|
|
2029
|
+
var STEERING_LIMITS = {
|
|
2030
|
+
operations: 256,
|
|
2031
|
+
journalBytes: 256 * 1024,
|
|
2032
|
+
bodyBytes: 24 * 1024,
|
|
2033
|
+
requestBytes: 32 * 1024,
|
|
2034
|
+
deadlineMs: 15000
|
|
2035
|
+
};
|
|
2036
|
+
var SteeringSelectorSchema = z37.object({ target: ManagedPeerSchema, registrationGeneration: z37.uuid(), operationId: z37.uuid() }).strict();
|
|
2037
|
+
var SteeringInputSchema = SteeringSelectorSchema.extend({
|
|
2038
|
+
generation: z37.uuid(),
|
|
2039
|
+
expectedTurnId: z37.string().min(1).max(256),
|
|
2040
|
+
body: z37.string().max(STEERING_LIMITS.bodyBytes).default(""),
|
|
2041
|
+
images: AttachmentReferencesSchema.default([])
|
|
2042
|
+
}).strict().refine((value) => value.body.trim().length > 0 || value.images.length > 0, "Steering requires text or an image").refine((value) => new TextEncoder().encode(value.body).length <= STEERING_LIMITS.bodyBytes, "Steering text exceeds its byte limit");
|
|
2043
|
+
var SteeringReceiptSchema = z37.object({
|
|
2044
|
+
protocol: z37.literal(1),
|
|
2045
|
+
operationId: z37.uuid(),
|
|
2046
|
+
target: ManagedPeerSchema,
|
|
2047
|
+
registrationGeneration: z37.uuid(),
|
|
2048
|
+
generation: z37.uuid(),
|
|
2049
|
+
turnId: z37.string().min(1).max(256),
|
|
2050
|
+
clientUserMessageId: z37.string().max(64),
|
|
2051
|
+
state: z37.enum(["submitted", "uncertain"]),
|
|
2052
|
+
observedAt: z37.iso.datetime()
|
|
2053
|
+
}).strict().refine((value) => value.clientUserMessageId === `steer:${value.operationId}`, "Native steering identity must match the operation");
|
|
2054
|
+
var SteeringReadResultSchema = z37.object({ operation: SteeringReceiptSchema.nullable() }).strict();
|
|
2055
|
+
var SteeringOperationSchema = z37.object({
|
|
2056
|
+
fingerprint: z37.string().regex(/^[a-f0-9]{64}$/),
|
|
2057
|
+
principal: z37.string().min(1).max(1024),
|
|
2058
|
+
phase: z37.enum(["intent", "submitted", "uncertain"]),
|
|
2059
|
+
receipt: SteeringReceiptSchema,
|
|
2060
|
+
reason: z37.string().max(128).nullable()
|
|
2061
|
+
}).strict();
|
|
2062
|
+
var SteeringJournalSchema = z37.object({
|
|
2063
|
+
registration: z37.uuid(),
|
|
2064
|
+
threadId: z37.uuid(),
|
|
2065
|
+
operations: z37.array(SteeringOperationSchema).max(STEERING_LIMITS.operations)
|
|
2066
|
+
}).strict();
|
|
2067
|
+
|
|
2068
|
+
// src/control/schema/context.ts
|
|
2069
|
+
import { z as z39 } from "zod";
|
|
2070
|
+
|
|
2071
|
+
// src/control/schema/selection.ts
|
|
2072
|
+
import { z as z38 } from "zod";
|
|
2073
|
+
var SelectionReadSchema = ControlTargetSchema.extend({
|
|
2074
|
+
registrationGeneration: z38.uuid()
|
|
2075
|
+
}).strict();
|
|
2076
|
+
var SelectionResultSchema = z38.object({
|
|
2077
|
+
protocol: z38.literal(1),
|
|
2078
|
+
registrationGeneration: z38.uuid(),
|
|
2079
|
+
current: AcceptedTurnOptionsSchema2
|
|
2080
|
+
}).strict();
|
|
2081
|
+
var SelectionUpdateSchema = SelectionReadSchema.extend({
|
|
2082
|
+
operationId: z38.uuid(),
|
|
2083
|
+
expectedRevision: z38.number().int().nonnegative(),
|
|
2084
|
+
options: NativeTurnOptionsSchema2
|
|
2085
|
+
}).strict();
|
|
2086
|
+
|
|
2087
|
+
// src/control/schema/context.ts
|
|
2088
|
+
var ControlHistoryReadSchema = SelectionReadSchema.extend(NativeHistoryQuerySchema.shape).strict();
|
|
2089
|
+
var ControlHistoryResultSchema = NativeHistoryPageSchema.extend(SelectionReadSchema.shape).strict();
|
|
2090
|
+
var ControlCompactSchema = SelectionReadSchema.extend(CompactRequestSchema.shape).strict();
|
|
2091
|
+
var ControlContextOperationReadSchema = SelectionReadSchema.extend({
|
|
2092
|
+
operationId: z39.uuid()
|
|
2093
|
+
}).strict();
|
|
2094
|
+
var PublicContextOperationSchema = ContextOperationSchema.omit({
|
|
2095
|
+
markerBefore: true
|
|
2096
|
+
}).strip();
|
|
2097
|
+
var ControlContextOperationResultSchema = SelectionReadSchema.extend({
|
|
2098
|
+
operation: PublicContextOperationSchema.nullable()
|
|
2099
|
+
}).strict();
|
|
2100
|
+
|
|
2101
|
+
// src/control/schema/directory.ts
|
|
2102
|
+
import { z as z40 } from "zod";
|
|
2103
|
+
var ControlDirectoryReadSchema = z40.object({
|
|
2104
|
+
path: z40.string().startsWith("/").max(4096).optional(),
|
|
2105
|
+
cursor: z40.string().max(8192).nullable().default(null),
|
|
2106
|
+
limit: z40.number().int().min(1).max(512).default(128),
|
|
2107
|
+
includeHidden: z40.boolean().default(false)
|
|
2108
|
+
}).strict();
|
|
2109
|
+
var ControlDirectoryEntrySchema = z40.object({
|
|
2110
|
+
name: z40.string().max(1024),
|
|
2111
|
+
kind: z40.enum(["dir", "file", "symlink", "other"]),
|
|
2112
|
+
path: z40.string().max(4096)
|
|
2113
|
+
}).strict();
|
|
2114
|
+
var ControlDirectoryResultSchema = z40.object({
|
|
2115
|
+
path: z40.string().max(4096),
|
|
2116
|
+
parent: z40.string().max(4096).nullable(),
|
|
2117
|
+
entries: z40.array(ControlDirectoryEntrySchema).max(512),
|
|
2118
|
+
nextCursor: z40.string().max(8192).nullable()
|
|
2119
|
+
}).strict();
|
|
2120
|
+
|
|
2121
|
+
// src/control/schema/externalList.ts
|
|
2122
|
+
import { defineContract } from "stitchkit/contract";
|
|
2123
|
+
|
|
2124
|
+
// src/external/residentSchema.ts
|
|
2125
|
+
import { z as z42 } from "zod";
|
|
2126
|
+
|
|
2127
|
+
// src/external/turnSchema.ts
|
|
2128
|
+
import { z as z41 } from "zod";
|
|
2129
|
+
var CONNECTION_REASONS = [
|
|
2130
|
+
"endpoint-absent",
|
|
2131
|
+
"endpoint-not-listening",
|
|
2132
|
+
"upgrade-refused",
|
|
2133
|
+
"connection-lost",
|
|
2134
|
+
"connection-unavailable"
|
|
2135
|
+
];
|
|
2136
|
+
var ExternalTurnStateSchema = z41.object({
|
|
2137
|
+
state: z41.enum(["working", "idle", "waiting-approval", "waiting-input", "unknown"]),
|
|
2138
|
+
evidence: z41.enum(["observed", "unknown", "unavailable", "stale"]),
|
|
2139
|
+
source: z41.enum(["codex-app-server", "unsupported"]),
|
|
2140
|
+
turnId: z41.string().min(1).max(128).nullable(),
|
|
2141
|
+
startedAt: z41.iso.datetime().nullable(),
|
|
2142
|
+
observedAt: z41.iso.datetime().nullable(),
|
|
2143
|
+
expiresAt: z41.iso.datetime().nullable(),
|
|
2144
|
+
reason: z41.enum([
|
|
2145
|
+
"native-status",
|
|
2146
|
+
"not-loaded",
|
|
2147
|
+
"system-error",
|
|
2148
|
+
"unsupported-status",
|
|
2149
|
+
"unsupported-provider",
|
|
2150
|
+
"unsupported-runtime",
|
|
2151
|
+
"not-observed",
|
|
2152
|
+
"not-reported",
|
|
2153
|
+
"read-limit",
|
|
2154
|
+
...CONNECTION_REASONS,
|
|
2155
|
+
"deadline"
|
|
2156
|
+
]),
|
|
2157
|
+
remedy: z41.string().min(1).max(200).nullable()
|
|
2158
|
+
}).strict().superRefine((value, ctx) => {
|
|
2159
|
+
if (value.startedAt !== null && value.turnId === null || (value.state === "unknown" || value.state === "idle") && (value.turnId !== null || value.startedAt !== null)) {
|
|
2160
|
+
ctx.addIssue({
|
|
2161
|
+
code: "custom",
|
|
2162
|
+
message: "native turn metadata belongs to an observed active turn"
|
|
2163
|
+
});
|
|
2164
|
+
}
|
|
2165
|
+
if (value.state !== "unknown" !== (value.evidence === "observed")) {
|
|
2166
|
+
ctx.addIssue({
|
|
2167
|
+
code: "custom",
|
|
2168
|
+
message: "only observed native evidence may claim a turn state"
|
|
2169
|
+
});
|
|
2170
|
+
}
|
|
2171
|
+
if (value.evidence === "observed" && (value.observedAt === null || value.expiresAt === null || value.source !== "codex-app-server")) {
|
|
2172
|
+
ctx.addIssue({
|
|
2173
|
+
code: "custom",
|
|
2174
|
+
message: "observed turn state requires native provenance and freshness"
|
|
2175
|
+
});
|
|
2176
|
+
}
|
|
2177
|
+
});
|
|
2178
|
+
function remedyFor(reason) {
|
|
2179
|
+
switch (reason) {
|
|
2180
|
+
case "endpoint-absent":
|
|
2181
|
+
return "The configured control endpoint is absent. The thread owner must expose a shared Unix listener; a Desktop host using only stdio is not connectable here.";
|
|
2182
|
+
case "endpoint-not-listening":
|
|
2183
|
+
return "The control endpoint has no listener. Check the owning host transport: stdio alone is not shared. Restore its Unix listener; do not start a second thread writer.";
|
|
2184
|
+
case "upgrade-refused":
|
|
2185
|
+
return "Something answers on the control endpoint but refuses the RPC upgrade \u2014 check which app owns it.";
|
|
2186
|
+
case "connection-lost":
|
|
2187
|
+
return "The control connection dropped mid-read; the next observation reconnects. Restart the Codex app if it keeps dropping.";
|
|
2188
|
+
case "connection-unavailable":
|
|
2189
|
+
return "The control endpoint failed in a way this build cannot name \u2014 connect to it by hand to see the operating system error.";
|
|
2190
|
+
case "unsupported-runtime":
|
|
2191
|
+
return "This Codex version does not report thread status. Update the app.";
|
|
2192
|
+
default:
|
|
2193
|
+
return null;
|
|
2194
|
+
}
|
|
2195
|
+
}
|
|
2196
|
+
|
|
2197
|
+
// src/external/residentSchema.ts
|
|
2198
|
+
var CONNECTION_REASON_SET = new Set(CONNECTION_REASONS);
|
|
2199
|
+
var EXTERNAL_MAX_ROWS = 512;
|
|
2200
|
+
var EXTERNAL_MAX_BYTES = 1024 * 1024;
|
|
2201
|
+
var ExternalStatusRowSchema = z42.object({
|
|
2202
|
+
identity: z42.object({
|
|
2203
|
+
provider: z42.literal("codex"),
|
|
2204
|
+
machine: z42.string().min(1).max(128),
|
|
2205
|
+
threadId: z42.uuid()
|
|
2206
|
+
}).strict(),
|
|
2207
|
+
name: z42.string().max(4096).nullable(),
|
|
2208
|
+
dir: z42.string().max(4096).nullable(),
|
|
2209
|
+
updatedAt: z42.iso.datetime().nullable(),
|
|
2210
|
+
turnState: ExternalTurnStateSchema
|
|
2211
|
+
}).strict();
|
|
2212
|
+
var ExternalStatusSnapshotSchema = z42.object({
|
|
2213
|
+
protocol: z42.literal(1),
|
|
2214
|
+
version: z42.string().max(64),
|
|
2215
|
+
machine: z42.string().min(1).max(128),
|
|
2216
|
+
generation: z42.uuid(),
|
|
2217
|
+
sequence: z42.number().int().nonnegative(),
|
|
2218
|
+
source: z42.literal("codex-app-server"),
|
|
2219
|
+
status: z42.enum(["live", "stale", "unavailable"]),
|
|
2220
|
+
reason: z42.enum([
|
|
2221
|
+
"observation-pending",
|
|
2222
|
+
...CONNECTION_REASONS,
|
|
2223
|
+
"unsupported-runtime",
|
|
2224
|
+
"deadline",
|
|
2225
|
+
"invalid-response",
|
|
2226
|
+
"config-changed",
|
|
2227
|
+
"daemon-stopped",
|
|
2228
|
+
"observation-expired",
|
|
2229
|
+
"clock-skew"
|
|
2230
|
+
]).nullable(),
|
|
2231
|
+
observedAt: z42.iso.datetime().nullable(),
|
|
2232
|
+
expiresAt: z42.iso.datetime().nullable(),
|
|
2233
|
+
truncated: z42.boolean(),
|
|
2234
|
+
omitted: z42.number().int().nonnegative(),
|
|
2235
|
+
sessions: z42.array(ExternalStatusRowSchema).max(EXTERNAL_MAX_ROWS)
|
|
2236
|
+
}).strict();
|
|
2237
|
+
function currentExternalStatus(snapshot, now = Date.now()) {
|
|
2238
|
+
const current = structuredClone(snapshot);
|
|
2239
|
+
if (current.observedAt !== null && Date.parse(current.observedAt) > now) {
|
|
2240
|
+
current.status = "unavailable";
|
|
2241
|
+
current.reason = "clock-skew";
|
|
2242
|
+
} else if (current.status === "live" && (current.expiresAt === null || Date.parse(current.expiresAt) <= now)) {
|
|
2243
|
+
current.status = "stale";
|
|
2244
|
+
current.reason = "observation-expired";
|
|
2245
|
+
}
|
|
2246
|
+
for (const row of current.sessions) {
|
|
2247
|
+
const state = row.turnState;
|
|
2248
|
+
if (state.evidence === "observed" && (current.status !== "live" || state.expiresAt === null || Date.parse(state.expiresAt) <= now || state.observedAt !== null && Date.parse(state.observedAt) > now)) {
|
|
2249
|
+
state.state = "unknown";
|
|
2250
|
+
state.turnId = null;
|
|
2251
|
+
state.startedAt = null;
|
|
2252
|
+
state.evidence = current.status === "unavailable" ? "unavailable" : "stale";
|
|
2253
|
+
state.reason = current.status !== "unavailable" ? "deadline" : current.reason !== null && CONNECTION_REASON_SET.has(current.reason) ? current.reason : "connection-unavailable";
|
|
2254
|
+
state.remedy = remedyFor(state.reason);
|
|
2255
|
+
}
|
|
2256
|
+
}
|
|
2257
|
+
return current;
|
|
2258
|
+
}
|
|
2259
|
+
|
|
2260
|
+
// src/control/schema/externalList.ts
|
|
2261
|
+
var externalListContract = defineContract({ prefix: "control", scope: "local" }, {
|
|
2262
|
+
"external.list": {
|
|
2263
|
+
method: "POST",
|
|
2264
|
+
path: "/external",
|
|
2265
|
+
effect: "read",
|
|
2266
|
+
desc: "Read prepared external native thread states; does not adopt or start threads",
|
|
2267
|
+
expose: ["HTTP", "CLI", "MCP"],
|
|
2268
|
+
output: ExternalStatusSnapshotSchema,
|
|
2269
|
+
tool: { name: "external" }
|
|
2270
|
+
}
|
|
2271
|
+
});
|
|
2272
|
+
|
|
2273
|
+
// src/control/schema/model.ts
|
|
2274
|
+
import { z as z43 } from "zod";
|
|
2275
|
+
var CONTROL_MODELS_MAX_PAGE = 64;
|
|
2276
|
+
var ControlModelsReadSchema = z43.object({
|
|
2277
|
+
runtime: AgentKindSchema.optional(),
|
|
2278
|
+
target: ManagedPeerSchema.optional(),
|
|
2279
|
+
launchRecipe: LaunchRecipeReferenceSchema2.optional(),
|
|
2280
|
+
profile: ProfileNameSchema.optional(),
|
|
2281
|
+
cursor: z43.string().min(1).max(4096).nullable().default(null),
|
|
2282
|
+
limit: z43.number().int().min(1).max(CONTROL_MODELS_MAX_PAGE).default(CONTROL_MODELS_MAX_PAGE),
|
|
2283
|
+
includeHidden: z43.boolean().default(false)
|
|
2284
|
+
}).strict().refine((input) => input.target === undefined || input.launchRecipe === undefined && input.profile === undefined, "Choose a host recipe or an exact managed runtime, not both");
|
|
2285
|
+
var ControlModelSchema = z43.object({
|
|
2286
|
+
provider: z43.string().min(1).max(128).optional(),
|
|
2287
|
+
id: z43.string().min(1).max(256),
|
|
2288
|
+
model: z43.string().min(1).max(256).optional(),
|
|
2289
|
+
displayName: z43.string().min(1).max(256),
|
|
2290
|
+
description: z43.string().max(2048),
|
|
2291
|
+
hidden: z43.boolean(),
|
|
2292
|
+
isDefault: z43.boolean(),
|
|
2293
|
+
inputModalities: z43.array(z43.string().min(1).max(64)).max(16),
|
|
2294
|
+
serviceTiers: z43.array(z43.object({
|
|
2295
|
+
id: z43.string().min(1).max(64),
|
|
2296
|
+
name: z43.string().min(1).max(256),
|
|
2297
|
+
description: z43.string().max(1024)
|
|
2298
|
+
}).strict()).max(16),
|
|
2299
|
+
supportedReasoningEfforts: z43.array(z43.object({
|
|
2300
|
+
reasoningEffort: z43.string().min(1).max(64),
|
|
2301
|
+
description: z43.string().max(1024)
|
|
2302
|
+
}).strict()).max(32).optional(),
|
|
2303
|
+
defaultReasoningEffort: z43.string().min(1).max(64).optional(),
|
|
2304
|
+
variants: z43.array(z43.string().min(1).max(128)).max(64).optional()
|
|
2305
|
+
}).strict();
|
|
2306
|
+
var ControlModelCatalogSchema = z43.object({
|
|
2307
|
+
target: ManagedPeerSchema.optional(),
|
|
2308
|
+
source: z43.object({
|
|
2309
|
+
kind: z43.enum(["host", "session"]),
|
|
2310
|
+
machine: z43.string().min(1),
|
|
2311
|
+
provider: z43.string().min(1).max(128).nullable(),
|
|
2312
|
+
providerLabel: z43.string().max(64).nullable().default(null),
|
|
2313
|
+
runtime: AgentKindSchema,
|
|
2314
|
+
profile: ProfileNameSchema.optional(),
|
|
2315
|
+
launchRecipe: LaunchRecipeMetadataSchema2.optional(),
|
|
2316
|
+
observedAt: z43.string().max(64).nullable().default(null),
|
|
2317
|
+
freshness: z43.enum(["live", "stale"]).nullable().default(null)
|
|
2318
|
+
}).strict(),
|
|
2319
|
+
data: z43.array(ControlModelSchema).max(CONTROL_MODELS_MAX_PAGE),
|
|
2320
|
+
agents: z43.array(z43.string().min(1).max(128)).max(128).optional(),
|
|
2321
|
+
nextCursor: z43.string().max(4096).nullable()
|
|
2322
|
+
}).strict().refine((catalog) => catalog.source.kind === "host" ? catalog.target === undefined : catalog.target !== undefined && catalog.target.agent === catalog.source.runtime && catalog.target.machine === catalog.source.machine, "Catalog source must match its exact managed identity");
|
|
2323
|
+
|
|
2324
|
+
// src/control/schema/performance.ts
|
|
2325
|
+
import { defineContract as defineContract2 } from "stitchkit/contract";
|
|
2326
|
+
import { z as z45 } from "zod";
|
|
2327
|
+
|
|
2328
|
+
// src/monitoring/performanceSchema.ts
|
|
2329
|
+
import { z as z44 } from "zod";
|
|
2330
|
+
var CpuSchema = z44.object({ userUs: z44.number().nonnegative(), systemUs: z44.number().nonnegative() }).strict();
|
|
2331
|
+
var DaemonPerformanceSchema = z44.object({
|
|
2332
|
+
basis: z44.literal("exclusive-operation-windows-and-sync-spans"),
|
|
2333
|
+
enabled: z44.boolean(),
|
|
2334
|
+
since: z44.iso.datetime(),
|
|
2335
|
+
elapsedMs: z44.number().nonnegative(),
|
|
2336
|
+
cpu: CpuSchema,
|
|
2337
|
+
unattributed: CpuSchema,
|
|
2338
|
+
producers: z44.record(z44.string(), z44.record(z44.string(), z44.number().nonnegative())),
|
|
2339
|
+
scopes: z44.array(z44.object({
|
|
2340
|
+
name: z44.string().max(128),
|
|
2341
|
+
runs: z44.number().int().nonnegative(),
|
|
2342
|
+
failures: z44.number().int().nonnegative(),
|
|
2343
|
+
active: z44.number().int().nonnegative(),
|
|
2344
|
+
durationMs: z44.number().nonnegative(),
|
|
2345
|
+
cpu: CpuSchema.nullable()
|
|
2346
|
+
}).strict()).max(128)
|
|
2347
|
+
}).strict();
|
|
2348
|
+
|
|
2349
|
+
// src/control/schema/performance.ts
|
|
2350
|
+
var PerformanceReadSchema = z45.object({}).strict();
|
|
2351
|
+
var PerformanceConfigureSchema = z45.object({ enabled: z45.boolean(), reset: z45.boolean().optional() }).strict();
|
|
2352
|
+
var performanceContract = defineContract2(externalListContract.meta, {
|
|
2353
|
+
"daemon.performance": {
|
|
2354
|
+
method: "POST",
|
|
2355
|
+
path: "/daemon/performance",
|
|
2356
|
+
effect: "read",
|
|
2357
|
+
desc: "Read daemon CPU windows without changing collection",
|
|
2358
|
+
input: PerformanceReadSchema,
|
|
2359
|
+
output: DaemonPerformanceSchema,
|
|
2360
|
+
expose: ["HTTP", "CLI", "MCP"],
|
|
2361
|
+
tool: { name: "performance" }
|
|
2362
|
+
},
|
|
2363
|
+
"daemon.performance.configure": {
|
|
2364
|
+
method: "POST",
|
|
2365
|
+
path: "/daemon/performance/configure",
|
|
2366
|
+
effect: "write",
|
|
2367
|
+
desc: "Enable or disable daemon CPU collection; reset only on transition or explicit reset",
|
|
2368
|
+
input: PerformanceConfigureSchema,
|
|
2369
|
+
output: DaemonPerformanceSchema,
|
|
2370
|
+
expose: ["HTTP", "CLI", "MCP"],
|
|
2371
|
+
tool: { name: "performance_configure" }
|
|
2372
|
+
}
|
|
2373
|
+
});
|
|
2374
|
+
|
|
2375
|
+
// src/control/schema/reading.ts
|
|
2376
|
+
import { z as z46 } from "zod";
|
|
2377
|
+
var IdentityWhoisReadSchema = z46.object({
|
|
2378
|
+
query: z46.string().min(1).max(1024),
|
|
2379
|
+
local: z46.boolean().default(false)
|
|
2380
|
+
}).strict();
|
|
2381
|
+
var IdentityListReadSchema = z46.object({ local: z46.boolean().default(false) }).strict();
|
|
2382
|
+
var ExactMessageReadSchema = z46.object({
|
|
2383
|
+
address: z46.string().min(1).max(256),
|
|
2384
|
+
messageId: z46.string().min(1).max(256)
|
|
2385
|
+
}).strict();
|
|
2386
|
+
var ChatLogReadSchema = z46.object({
|
|
2387
|
+
limit: z46.int().min(1).max(1000).default(30),
|
|
2388
|
+
fleet: z46.boolean().default(false)
|
|
2389
|
+
}).strict();
|
|
2390
|
+
var ChatFollowReadSchema = z46.object({ since: z46.string().min(1).max(128).nullable().default(null) }).strict();
|
|
2391
|
+
var SentLettersReadSchema = z46.object({ task: z46.string().min(1).max(256).nullable().default(null) }).strict();
|
|
2392
|
+
|
|
2393
|
+
// src/control/schema/refusals.ts
|
|
2394
|
+
import { defineErrors } from "stitchkit/contract";
|
|
2395
|
+
var refusals = defineErrors({
|
|
2396
|
+
APPLICATION_POLICY_UNAVAILABLE: {
|
|
2397
|
+
status: 409,
|
|
2398
|
+
retryable: false,
|
|
2399
|
+
message: "The application authority this session runs under is unavailable"
|
|
2400
|
+
},
|
|
2401
|
+
ARCHIVED: { status: 409, retryable: false, message: "The session is archived" },
|
|
2402
|
+
ATTACHMENT_UNAVAILABLE: {
|
|
2403
|
+
status: 409,
|
|
2404
|
+
retryable: false,
|
|
2405
|
+
message: "The attachment is unavailable"
|
|
2406
|
+
},
|
|
2407
|
+
BUSY: { status: 429, retryable: true, message: "The daemon is at capacity; try again shortly" },
|
|
2408
|
+
CANCELLED: { status: 499, retryable: true, message: "The operation was cancelled" },
|
|
2409
|
+
CAPACITY: { status: 429, retryable: true, message: "Capacity is exhausted; try again shortly" },
|
|
2410
|
+
CHAT_DISABLED: { status: 409, retryable: false, message: "Chat is disabled for this session" },
|
|
2411
|
+
COLLABORATION_MODE_UNAVAILABLE: {
|
|
2412
|
+
status: 409,
|
|
2413
|
+
retryable: false,
|
|
2414
|
+
message: "The requested collaboration mode is unavailable"
|
|
2415
|
+
},
|
|
2416
|
+
COMMUNICATION_AUTHORIZATION_REQUIRED: {
|
|
2417
|
+
status: 403,
|
|
2418
|
+
retryable: false,
|
|
2419
|
+
message: "This message needs a communication authorization"
|
|
2420
|
+
},
|
|
2421
|
+
COMMUNICATION_AUTHORIZATION_UNVERIFIED: {
|
|
2422
|
+
status: 403,
|
|
2423
|
+
retryable: false,
|
|
2424
|
+
message: "The communication authorization could not be verified"
|
|
2425
|
+
},
|
|
2426
|
+
CONFIG_CHANGED: {
|
|
2427
|
+
status: 503,
|
|
2428
|
+
retryable: true,
|
|
2429
|
+
message: "The machine configuration changed; retry the read"
|
|
2430
|
+
},
|
|
2431
|
+
CONTEXT_BUSY: { status: 409, retryable: true, message: "Another context operation is running" },
|
|
2432
|
+
CONTEXT_CAPACITY: {
|
|
2433
|
+
status: 409,
|
|
2434
|
+
retryable: false,
|
|
2435
|
+
message: "The context operation journal is full"
|
|
2436
|
+
},
|
|
2437
|
+
CONTEXT_CONFLICT: {
|
|
2438
|
+
status: 409,
|
|
2439
|
+
retryable: false,
|
|
2440
|
+
message: "The context operation conflicts with another"
|
|
2441
|
+
},
|
|
2442
|
+
CONTEXT_RPC_PENDING: {
|
|
2443
|
+
status: 409,
|
|
2444
|
+
retryable: true,
|
|
2445
|
+
message: "A context request to the provider is still pending"
|
|
2446
|
+
},
|
|
2447
|
+
CONTEXT_UNAVAILABLE: {
|
|
2448
|
+
status: 503,
|
|
2449
|
+
retryable: true,
|
|
2450
|
+
message: "Context operations are unavailable"
|
|
2451
|
+
},
|
|
2452
|
+
CORRUPT_STATE: { status: 503, retryable: true, message: "Stored state is unreadable" },
|
|
2453
|
+
CREATE_CAPACITY: {
|
|
2454
|
+
status: 409,
|
|
2455
|
+
retryable: false,
|
|
2456
|
+
message: "No more sessions can be created now"
|
|
2457
|
+
},
|
|
2458
|
+
CREATE_FAILED: { status: 409, retryable: false, message: "The session could not be created" },
|
|
2459
|
+
CREATE_PENDING: { status: 503, retryable: true, message: "The session is still being created" },
|
|
2460
|
+
CURSOR_MISMATCH: { status: 409, retryable: false, message: "The cursor belongs to another read" },
|
|
2461
|
+
DELEGATION_REFUSED: {
|
|
2462
|
+
status: 409,
|
|
2463
|
+
retryable: false,
|
|
2464
|
+
message: "The delegation does not allow this"
|
|
2465
|
+
},
|
|
2466
|
+
DIRECTORY_TOO_LARGE: {
|
|
2467
|
+
status: 413,
|
|
2468
|
+
retryable: false,
|
|
2469
|
+
message: "The directory has too many entries to list"
|
|
2470
|
+
},
|
|
2471
|
+
FORBIDDEN: { status: 403, retryable: false, message: "This caller may not do that" },
|
|
2472
|
+
FORK_BUSY: { status: 409, retryable: true, message: "A fork of this session is in progress" },
|
|
2473
|
+
FORK_PENDING: { status: 503, retryable: true, message: "The fork has not settled yet" },
|
|
2474
|
+
FORK_UNAVAILABLE: { status: 409, retryable: false, message: "This session cannot be forked" },
|
|
2475
|
+
FORK_UNCERTAIN: {
|
|
2476
|
+
status: 409,
|
|
2477
|
+
retryable: false,
|
|
2478
|
+
message: "Whether the fork happened is unknown"
|
|
2479
|
+
},
|
|
2480
|
+
HISTORY_CURSOR: {
|
|
2481
|
+
status: 409,
|
|
2482
|
+
retryable: false,
|
|
2483
|
+
message: "The history cursor is no longer valid"
|
|
2484
|
+
},
|
|
2485
|
+
HISTORY_UNAVAILABLE: {
|
|
2486
|
+
status: 503,
|
|
2487
|
+
retryable: true,
|
|
2488
|
+
message: "The conversation history is unavailable"
|
|
2489
|
+
},
|
|
2490
|
+
IDEMPOTENCY_CONFLICT: {
|
|
2491
|
+
status: 409,
|
|
2492
|
+
retryable: false,
|
|
2493
|
+
message: "The same operation ID was used with a different request"
|
|
2494
|
+
},
|
|
2495
|
+
IDENTITY_MISMATCH: {
|
|
2496
|
+
status: 409,
|
|
2497
|
+
retryable: false,
|
|
2498
|
+
message: "The exact session identity does not match"
|
|
2499
|
+
},
|
|
2500
|
+
INVALID_CURSOR: { status: 400, retryable: false, message: "The cursor is invalid" },
|
|
2501
|
+
INVALID_INPUT: { status: 400, retryable: false, message: "The input is invalid" },
|
|
2502
|
+
INVALID_OPTION: { status: 400, retryable: false, message: "The option is invalid" },
|
|
2503
|
+
INVALID_RECIPE_CREATE: {
|
|
2504
|
+
status: 409,
|
|
2505
|
+
retryable: false,
|
|
2506
|
+
message: "The launch recipe cannot create this session"
|
|
2507
|
+
},
|
|
2508
|
+
INVALID_TARGET: { status: 400, retryable: false, message: "The target is invalid" },
|
|
2509
|
+
INVALID_WORKSPACE: { status: 400, retryable: false, message: "The workspace is invalid" },
|
|
2510
|
+
JOURNAL_CAPACITY: { status: 409, retryable: false, message: "The selection journal is full" },
|
|
2511
|
+
LAGGED: {
|
|
2512
|
+
status: 409,
|
|
2513
|
+
retryable: false,
|
|
2514
|
+
message: "The reader fell behind the feed; resume from its last cursor"
|
|
2515
|
+
},
|
|
2516
|
+
LAUNCH_RECIPE_UNAVAILABLE: {
|
|
2517
|
+
status: 409,
|
|
2518
|
+
retryable: false,
|
|
2519
|
+
message: "The launch recipe is unavailable"
|
|
2520
|
+
},
|
|
2521
|
+
LETTER_REFUSED: { status: 409, retryable: false, message: "The letter was refused" },
|
|
2522
|
+
MESSAGE_EVIDENCE_UNAVAILABLE: {
|
|
2523
|
+
status: 503,
|
|
2524
|
+
retryable: true,
|
|
2525
|
+
message: "The message evidence is unavailable"
|
|
2526
|
+
},
|
|
2527
|
+
MENU_OPEN: { status: 409, retryable: false, message: "The session is at a selection menu" },
|
|
2528
|
+
MIN_AWAKE_PER_PROFILE: {
|
|
2529
|
+
status: 409,
|
|
2530
|
+
retryable: false,
|
|
2531
|
+
message: "The profile must keep its minimum number of awake sessions"
|
|
2532
|
+
},
|
|
2533
|
+
MODEL_UNAVAILABLE: {
|
|
2534
|
+
status: 409,
|
|
2535
|
+
retryable: false,
|
|
2536
|
+
message: "The model is not in this host\u2019s catalog"
|
|
2537
|
+
},
|
|
2538
|
+
NO_INFERENCE_CREATE_REQUIREMENTS: {
|
|
2539
|
+
status: 409,
|
|
2540
|
+
retryable: false,
|
|
2541
|
+
message: "A create without inference needs an explicit model and runtime"
|
|
2542
|
+
},
|
|
2543
|
+
NO_INFERENCE_CREATE_UNSUPPORTED: {
|
|
2544
|
+
status: 409,
|
|
2545
|
+
retryable: false,
|
|
2546
|
+
message: "This runtime cannot guarantee a create without inference"
|
|
2547
|
+
},
|
|
2548
|
+
NOT_A_DIRECTORY: { status: 400, retryable: false, message: "The path is not a directory" },
|
|
2549
|
+
NOT_FOUND: { status: 404, retryable: false, message: "No such session or item" },
|
|
2550
|
+
NOT_IDLE: { status: 409, retryable: false, message: "The session is busy" },
|
|
2551
|
+
NOT_RUNNING: { status: 409, retryable: false, message: "The session is not running" },
|
|
2552
|
+
NOT_SLEEPING: { status: 409, retryable: false, message: "The session is not sleeping" },
|
|
2553
|
+
ORIGIN_REFUSED: {
|
|
2554
|
+
status: 403,
|
|
2555
|
+
retryable: false,
|
|
2556
|
+
message: "The request origin is not allowed here"
|
|
2557
|
+
},
|
|
2558
|
+
PERMISSION_DENIED: { status: 403, retryable: false, message: "Permission denied" },
|
|
2559
|
+
PERMISSION_MODE_UNAVAILABLE: {
|
|
2560
|
+
status: 409,
|
|
2561
|
+
retryable: false,
|
|
2562
|
+
message: "The permission mode is unavailable"
|
|
2563
|
+
},
|
|
2564
|
+
PINNED_SESSION: { status: 409, retryable: false, message: "The session is pinned awake" },
|
|
2565
|
+
PRECONDITION_FAILED: {
|
|
2566
|
+
status: 409,
|
|
2567
|
+
retryable: false,
|
|
2568
|
+
message: "The request cannot run in the session\u2019s or host\u2019s current state"
|
|
2569
|
+
},
|
|
2570
|
+
PROFILE_UNAVAILABLE: {
|
|
2571
|
+
status: 409,
|
|
2572
|
+
retryable: false,
|
|
2573
|
+
message: "The account profile is unavailable"
|
|
2574
|
+
},
|
|
2575
|
+
PROMPT_UNCONFIRMED: {
|
|
2576
|
+
status: 409,
|
|
2577
|
+
retryable: false,
|
|
2578
|
+
message: "The prompt was not confirmed by the session"
|
|
2579
|
+
},
|
|
2580
|
+
REGISTRATION_UNAVAILABLE: {
|
|
2581
|
+
status: 409,
|
|
2582
|
+
retryable: false,
|
|
2583
|
+
message: "The session has no registration generation"
|
|
2584
|
+
},
|
|
2585
|
+
RESOURCE_EXHAUSTED: {
|
|
2586
|
+
status: 429,
|
|
2587
|
+
retryable: true,
|
|
2588
|
+
message: "A bounded resource is exhausted; try again"
|
|
2589
|
+
},
|
|
2590
|
+
REVISION_CONFLICT: {
|
|
2591
|
+
status: 409,
|
|
2592
|
+
retryable: false,
|
|
2593
|
+
message: "The state changed since it was read"
|
|
2594
|
+
},
|
|
2595
|
+
ROLLBACK_UNSUPPORTED: { status: 409, retryable: false, message: "This session cannot roll back" },
|
|
2596
|
+
SELECTION_UNAVAILABLE: {
|
|
2597
|
+
status: 409,
|
|
2598
|
+
retryable: false,
|
|
2599
|
+
message: "The model selection is unavailable"
|
|
2600
|
+
},
|
|
2601
|
+
SESSION_BLOCKED: {
|
|
2602
|
+
status: 409,
|
|
2603
|
+
retryable: false,
|
|
2604
|
+
message: "The session is blocked until it is repaired"
|
|
2605
|
+
},
|
|
2606
|
+
SESSION_SLEEPING: {
|
|
2607
|
+
status: 409,
|
|
2608
|
+
retryable: false,
|
|
2609
|
+
message: "The session is sleeping; wake it first"
|
|
2610
|
+
},
|
|
2611
|
+
SLEEP_PENDING: { status: 409, retryable: true, message: "A sleep operation is pending" },
|
|
2612
|
+
SLEEP_SUPERSEDED: {
|
|
2613
|
+
status: 409,
|
|
2614
|
+
retryable: false,
|
|
2615
|
+
message: "The sleep was followed by another lifecycle operation"
|
|
2616
|
+
},
|
|
2617
|
+
STALE_CURSOR: { status: 409, retryable: false, message: "The cursor needs a fresh baseline" },
|
|
2618
|
+
STEERING_UNAVAILABLE: {
|
|
2619
|
+
status: 503,
|
|
2620
|
+
retryable: true,
|
|
2621
|
+
message: "Steering the running turn is unavailable"
|
|
2622
|
+
},
|
|
2623
|
+
STALE_PROMPT: {
|
|
2624
|
+
status: 409,
|
|
2625
|
+
retryable: false,
|
|
2626
|
+
message: "The prompt is no longer the current one"
|
|
2627
|
+
},
|
|
2628
|
+
STALE_REQUEST: {
|
|
2629
|
+
status: 409,
|
|
2630
|
+
retryable: false,
|
|
2631
|
+
message: "The request refers to a state that has moved on"
|
|
2632
|
+
},
|
|
2633
|
+
SYMLINK_REFUSED: { status: 409, retryable: false, message: "Symbolic links are refused here" },
|
|
2634
|
+
TIMEOUT: { status: 504, retryable: true, message: "The operation did not finish in time" },
|
|
2635
|
+
TOO_LARGE: { status: 413, retryable: false, message: "The content exceeds its byte budget" },
|
|
2636
|
+
TURN_MISMATCH: { status: 409, retryable: false, message: "The turn is not the current one" },
|
|
2637
|
+
UNAUTHORIZED: { status: 401, retryable: false, message: "The caller is not authenticated" },
|
|
2638
|
+
UNAVAILABLE: { status: 503, retryable: true, message: "The runtime or service is unavailable" },
|
|
2639
|
+
UNSUPPORTED: {
|
|
2640
|
+
status: 409,
|
|
2641
|
+
retryable: false,
|
|
2642
|
+
message: "This session or runtime does not support that"
|
|
2643
|
+
},
|
|
2644
|
+
VALIDATION_ERROR: { status: 400, retryable: false, message: "The request failed validation" },
|
|
2645
|
+
WAKE_CAPACITY: { status: 409, retryable: false, message: "The wake journal is full" },
|
|
2646
|
+
WAKE_FAILED: { status: 409, retryable: false, message: "The session could not be woken" },
|
|
2647
|
+
WAKE_PENDING: { status: 409, retryable: true, message: "A wake is pending" }
|
|
2648
|
+
});
|
|
2649
|
+
|
|
2650
|
+
// src/control/schema/session.ts
|
|
2651
|
+
import { z as z47 } from "zod";
|
|
2652
|
+
var ControlCreateSchema = z47.object({
|
|
2653
|
+
runtime: AgentKindSchema.optional(),
|
|
2654
|
+
mode: z47.enum(["tui", "native"]).optional(),
|
|
2655
|
+
initialization: z47.enum(["allow-inference", "no-inference"]).optional(),
|
|
2656
|
+
requestId: z47.uuid(),
|
|
2657
|
+
name: z47.string().min(1).max(256).regex(SESSION_NAME_RE),
|
|
2658
|
+
workspace: z47.string().startsWith("/").max(4096),
|
|
2659
|
+
flags: z47.array(z47.string().max(4096)).max(32).default([]),
|
|
2660
|
+
launchRecipe: LaunchRecipeReferenceSchema2.optional(),
|
|
2661
|
+
profile: ProfileNameSchema.optional(),
|
|
2662
|
+
modelSelection: ModelSelectionSchema2.optional(),
|
|
2663
|
+
applicationPolicy: ApplicationPolicyReferenceSchema2.optional(),
|
|
2664
|
+
delegation: DelegationRequestSchema2.optional()
|
|
2665
|
+
}).strict();
|
|
2666
|
+
var ControlCreateReceiptSchema = z47.object({
|
|
2667
|
+
requestId: z47.uuid(),
|
|
2668
|
+
target: ManagedPeerSchema,
|
|
2669
|
+
workspace: z47.string().startsWith("/").max(4096),
|
|
2670
|
+
registrationGeneration: z47.uuid(),
|
|
2671
|
+
duplicate: z47.boolean(),
|
|
2672
|
+
profile: ProfileNameSchema.optional(),
|
|
2673
|
+
launchRecipe: LaunchRecipeMetadataSchema2.optional(),
|
|
2674
|
+
modelSelection: ModelSelectionSchema2.optional(),
|
|
2675
|
+
applicationPolicy: ApplicationPolicyEvidenceSchema2.optional(),
|
|
2676
|
+
delegation: DelegationEvidenceSchema2.optional(),
|
|
2677
|
+
nativeSession: NativeSessionSchema.optional(),
|
|
2678
|
+
driverCapabilities: RuntimeCapabilitiesSchema.optional()
|
|
2679
|
+
}).strict();
|
|
2680
|
+
var ControlArchiveReceiptSchema = z47.object({
|
|
2681
|
+
target: ManagedPeerSchema,
|
|
2682
|
+
archived: z47.literal(true),
|
|
2683
|
+
duplicate: z47.boolean(),
|
|
2684
|
+
stopped: z47.boolean()
|
|
2685
|
+
}).strict();
|
|
2686
|
+
|
|
2687
|
+
// src/control/schema/terminalPrompt.ts
|
|
2688
|
+
import { z as z48 } from "zod";
|
|
2689
|
+
var TerminalMenuSchema = z48.object({
|
|
2690
|
+
kind: z48.enum([
|
|
2691
|
+
"folder-trust",
|
|
2692
|
+
"declared-permissions",
|
|
2693
|
+
"resume-picker",
|
|
2694
|
+
"external-imports",
|
|
2695
|
+
"unrecognised"
|
|
2696
|
+
]),
|
|
2697
|
+
title: z48.string().max(256),
|
|
2698
|
+
options: z48.array(z48.object({ id: z48.string().max(64), label: z48.string().max(256) }).strict()).max(20),
|
|
2699
|
+
selected: z48.int().min(0).max(19).nullable()
|
|
2700
|
+
}).strict();
|
|
2701
|
+
var TerminalPromptReadSchema = z48.object({ target: ManagedPeerSchema }).strict();
|
|
2702
|
+
var TerminalPromptResultSchema = z48.object({
|
|
2703
|
+
target: ManagedPeerSchema,
|
|
2704
|
+
observationId: z48.uuid().nullable(),
|
|
2705
|
+
expiresAt: z48.iso.datetime().nullable(),
|
|
2706
|
+
menu: TerminalMenuSchema.nullable()
|
|
2707
|
+
}).strict();
|
|
2708
|
+
var TerminalPromptRespondSchema = z48.object({
|
|
2709
|
+
target: ManagedPeerSchema,
|
|
2710
|
+
observationId: z48.uuid(),
|
|
2711
|
+
optionId: z48.string().min(1).max(64)
|
|
2712
|
+
}).strict();
|
|
2713
|
+
var TerminalPromptReceiptSchema = z48.object({
|
|
2714
|
+
target: ManagedPeerSchema,
|
|
2715
|
+
observationId: z48.uuid(),
|
|
2716
|
+
optionId: z48.string(),
|
|
2717
|
+
outcome: z48.literal("submitted")
|
|
2718
|
+
}).strict();
|
|
2719
|
+
|
|
2720
|
+
// src/control/schema/contract.ts
|
|
2721
|
+
var refuse = refusals.errors;
|
|
2722
|
+
var SHARED_SESSION_REFUSALS = [
|
|
2723
|
+
refuse.BUSY,
|
|
2724
|
+
refuse.CANCELLED,
|
|
2725
|
+
refuse.CORRUPT_STATE,
|
|
2726
|
+
refuse.DELEGATION_REFUSED,
|
|
2727
|
+
refuse.FORBIDDEN,
|
|
2728
|
+
refuse.IDENTITY_MISMATCH,
|
|
2729
|
+
refuse.ORIGIN_REFUSED,
|
|
2730
|
+
refuse.TIMEOUT,
|
|
2731
|
+
refuse.UNAVAILABLE
|
|
2732
|
+
];
|
|
2733
|
+
var controlContract = defineContract3({
|
|
2734
|
+
...externalListContract.meta
|
|
2735
|
+
}, {
|
|
2736
|
+
...externalListContract.endpoints,
|
|
2737
|
+
...performanceContract.endpoints,
|
|
2738
|
+
"terminal.prompt": {
|
|
2739
|
+
method: "POST",
|
|
2740
|
+
path: "/terminal/prompt",
|
|
2741
|
+
effect: "read",
|
|
2742
|
+
desc: "Observe a supported interactive terminal menu before choosing an option",
|
|
2743
|
+
input: TerminalPromptReadSchema,
|
|
2744
|
+
output: TerminalPromptResultSchema,
|
|
2745
|
+
expose: ["HTTP", "CLI", "MCP"],
|
|
2746
|
+
tool: { name: "terminal_prompt" },
|
|
2747
|
+
timeout: 7000
|
|
2748
|
+
},
|
|
2749
|
+
"terminal.respond": {
|
|
2750
|
+
method: "POST",
|
|
2751
|
+
path: "/terminal/respond",
|
|
2752
|
+
effect: "write",
|
|
2753
|
+
desc: "Submit one option from an unexpired single-use terminal observation",
|
|
2754
|
+
input: TerminalPromptRespondSchema,
|
|
2755
|
+
output: TerminalPromptReceiptSchema,
|
|
2756
|
+
expose: ["HTTP", "CLI", "MCP"],
|
|
2757
|
+
tool: { name: "terminal_respond" },
|
|
2758
|
+
timeout: 7000
|
|
2759
|
+
},
|
|
2760
|
+
"usage.read": {
|
|
2761
|
+
method: "POST",
|
|
2762
|
+
path: "/usage",
|
|
2763
|
+
effect: "read",
|
|
2764
|
+
desc: "Read measured usage without conversation content",
|
|
2765
|
+
input: UsageReadSchema,
|
|
2766
|
+
output: UsageSummarySchema,
|
|
2767
|
+
idempotent: true,
|
|
2768
|
+
expose: ["HTTP", "CLI", "MCP"],
|
|
2769
|
+
timeout: 7000,
|
|
2770
|
+
tool: { name: "usage" }
|
|
2771
|
+
},
|
|
2772
|
+
"usage.list": {
|
|
2773
|
+
method: "POST",
|
|
2774
|
+
path: "/usage/list",
|
|
2775
|
+
effect: "read",
|
|
2776
|
+
desc: "Read a bounded page of local session usage",
|
|
2777
|
+
input: UsageListSchema,
|
|
2778
|
+
output: UsageListResultSchema,
|
|
2779
|
+
idempotent: true,
|
|
2780
|
+
expose: ["HTTP", "CLI", "MCP"],
|
|
2781
|
+
timeout: 7000,
|
|
2782
|
+
tool: { name: "usage_list" }
|
|
2783
|
+
},
|
|
2784
|
+
"identity.whois": {
|
|
2785
|
+
method: "POST",
|
|
2786
|
+
path: "/identity/whois",
|
|
2787
|
+
effect: "read",
|
|
2788
|
+
desc: "Which session a window title, an address or a provider conversation id is, asked of every fleet machine; a machine that was not asked is named",
|
|
2789
|
+
input: IdentityWhoisReadSchema,
|
|
2790
|
+
output: WhoisAnswerSchema,
|
|
2791
|
+
idempotent: true,
|
|
2792
|
+
expose: ["HTTP", "CLI", "MCP"],
|
|
2793
|
+
timeout: 30000,
|
|
2794
|
+
tool: { name: "whois" }
|
|
2795
|
+
},
|
|
2796
|
+
"identity.list": {
|
|
2797
|
+
method: "POST",
|
|
2798
|
+
path: "/identity/list",
|
|
2799
|
+
effect: "read",
|
|
2800
|
+
desc: "Every session of the fleet with its directory, repository, project, checkouts and conversation ids",
|
|
2801
|
+
input: IdentityListReadSchema,
|
|
2802
|
+
output: WhoisListSchema,
|
|
2803
|
+
idempotent: true,
|
|
2804
|
+
expose: ["HTTP", "CLI", "MCP"],
|
|
2805
|
+
timeout: 30000,
|
|
2806
|
+
tool: { name: "identities" }
|
|
2807
|
+
},
|
|
2808
|
+
"chat.log": {
|
|
2809
|
+
method: "POST",
|
|
2810
|
+
path: "/chat/log",
|
|
2811
|
+
effect: "read",
|
|
2812
|
+
desc: "The newest letters received and sent, of this machine or merged across the fleet in time order; a machine that did not answer is named",
|
|
2813
|
+
input: ChatLogReadSchema,
|
|
2814
|
+
output: LogPayloadSchema,
|
|
2815
|
+
idempotent: true,
|
|
2816
|
+
expose: ["HTTP", "CLI", "MCP"],
|
|
2817
|
+
timeout: 30000,
|
|
2818
|
+
tool: { name: "chat_log" }
|
|
2819
|
+
},
|
|
2820
|
+
"fleet.list": {
|
|
2821
|
+
method: "POST",
|
|
2822
|
+
path: "/fleet/list",
|
|
2823
|
+
effect: "read",
|
|
2824
|
+
desc: "Every session on every fleet machine with its state, the release each machine runs and the accounts they spend on; a machine that did not answer is a row that says why",
|
|
2825
|
+
input: z49.object({}).strict(),
|
|
2826
|
+
output: FleetAnswerSchema,
|
|
2827
|
+
idempotent: true,
|
|
2828
|
+
expose: ["HTTP", "CLI", "MCP"],
|
|
2829
|
+
timeout: 30000,
|
|
2830
|
+
tool: { name: "fleet" }
|
|
2831
|
+
},
|
|
2832
|
+
"message.read": {
|
|
2833
|
+
method: "POST",
|
|
2834
|
+
path: "/message/read",
|
|
2835
|
+
effect: "read",
|
|
2836
|
+
desc: "One user message of a fleet session, whole, by its id, with who sent it; another machine's session is read by that machine's daemon",
|
|
2837
|
+
input: ExactMessageReadSchema,
|
|
2838
|
+
output: ExactMessageResultSchema,
|
|
2839
|
+
idempotent: true,
|
|
2840
|
+
expose: ["HTTP", "CLI", "MCP"],
|
|
2841
|
+
timeout: 30000,
|
|
2842
|
+
tool: { name: "read_message" }
|
|
2843
|
+
},
|
|
2844
|
+
"letter.list": {
|
|
2845
|
+
method: "POST",
|
|
2846
|
+
path: "/letter/list",
|
|
2847
|
+
effect: "read",
|
|
2848
|
+
desc: "The letters the caller sent, each with its state and the reference a continuation cites",
|
|
2849
|
+
input: SentLettersReadSchema,
|
|
2850
|
+
output: SentListSchema,
|
|
2851
|
+
idempotent: true,
|
|
2852
|
+
expose: ["HTTP", "CLI", "MCP"],
|
|
2853
|
+
timeout: 7000,
|
|
2854
|
+
tool: { name: "sent_letters" }
|
|
2855
|
+
},
|
|
2856
|
+
"letter.send": {
|
|
2857
|
+
method: "POST",
|
|
2858
|
+
path: "/letter/send",
|
|
2859
|
+
effect: "write",
|
|
2860
|
+
desc: "A letter from the caller to a fleet session, an App thread or the owner, with the receipt stitchmux msg --json prints; another machine's recipient is resolved and handed the letter there",
|
|
2861
|
+
input: LetterRequestSchema,
|
|
2862
|
+
output: SendReceiptSchema,
|
|
2863
|
+
expose: ["HTTP", "CLI", "MCP"],
|
|
2864
|
+
timeout: 30000,
|
|
2865
|
+
tool: { name: "send_letter" }
|
|
2866
|
+
},
|
|
2867
|
+
"external.history": {
|
|
2868
|
+
method: "POST",
|
|
2869
|
+
path: "/external/history",
|
|
2870
|
+
effect: "read",
|
|
2871
|
+
desc: "Read bounded external authored text without writer mutation",
|
|
2872
|
+
input: ExternalContentReadSchema,
|
|
2873
|
+
output: ExternalContentResultSchema,
|
|
2874
|
+
idempotent: true,
|
|
2875
|
+
timeout: 7000
|
|
2876
|
+
},
|
|
2877
|
+
"external.message": {
|
|
2878
|
+
method: "POST",
|
|
2879
|
+
path: "/external/message",
|
|
2880
|
+
effect: "read",
|
|
2881
|
+
desc: "Resolve one exact native message of an external thread with its recorded submitter",
|
|
2882
|
+
input: ExternalMessageReadSchema,
|
|
2883
|
+
output: ExternalMessageResultSchema,
|
|
2884
|
+
idempotent: true,
|
|
2885
|
+
timeout: 7000
|
|
2886
|
+
},
|
|
2887
|
+
"external.capabilities": {
|
|
2888
|
+
method: "POST",
|
|
2889
|
+
path: "/external/capabilities",
|
|
2890
|
+
effect: "read",
|
|
2891
|
+
desc: "Read exact external content and control eligibility",
|
|
2892
|
+
input: ExternalContentSelectorSchema,
|
|
2893
|
+
output: ExternalContentCapabilitiesSchema,
|
|
2894
|
+
idempotent: true,
|
|
2895
|
+
timeout: 7000
|
|
2896
|
+
},
|
|
2897
|
+
"message.cancel": {
|
|
2898
|
+
method: "POST",
|
|
2899
|
+
path: "/message/cancel",
|
|
2900
|
+
effect: "write",
|
|
2901
|
+
desc: "Withdraw one accepted letter of the caller that has not been delivered",
|
|
2902
|
+
input: ControlMessageCancelSchema,
|
|
2903
|
+
output: ControlMessageCancelReceiptSchema,
|
|
2904
|
+
idempotent: true
|
|
2905
|
+
},
|
|
2906
|
+
"message.operation": {
|
|
2907
|
+
method: "POST",
|
|
2908
|
+
path: "/message/operation",
|
|
2909
|
+
effect: "read",
|
|
2910
|
+
desc: "Read retained exact message-to-native-turn evidence without resubmission",
|
|
2911
|
+
input: MessageOperationReadSchema,
|
|
2912
|
+
output: MessageOperationResultSchema,
|
|
2913
|
+
idempotent: true
|
|
2914
|
+
},
|
|
2915
|
+
"transcript.read": {
|
|
2916
|
+
method: "POST",
|
|
2917
|
+
path: "/transcript",
|
|
2918
|
+
effect: "read",
|
|
2919
|
+
desc: "Read a bounded transcript window with the cursor a caller pages by",
|
|
2920
|
+
input: ControlTranscriptReadSchema,
|
|
2921
|
+
output: ControlTranscriptResultSchema,
|
|
2922
|
+
idempotent: true,
|
|
2923
|
+
timeout: 7000
|
|
2924
|
+
},
|
|
2925
|
+
"history.read": {
|
|
2926
|
+
method: "POST",
|
|
2927
|
+
path: "/history",
|
|
2928
|
+
effect: "read",
|
|
2929
|
+
desc: "Read a bounded native history page through its existing owner",
|
|
2930
|
+
input: ControlHistoryReadSchema,
|
|
2931
|
+
output: ControlHistoryResultSchema,
|
|
2932
|
+
idempotent: true,
|
|
2933
|
+
timeout: 7000
|
|
2934
|
+
},
|
|
2935
|
+
"context.compact": {
|
|
2936
|
+
method: "POST",
|
|
2937
|
+
path: "/context/compact",
|
|
2938
|
+
effect: "write",
|
|
2939
|
+
desc: "Accept an exact idle native compaction operation",
|
|
2940
|
+
input: ControlCompactSchema,
|
|
2941
|
+
output: ControlContextOperationResultSchema,
|
|
2942
|
+
idempotent: true
|
|
2943
|
+
},
|
|
2944
|
+
"context.operation": {
|
|
2945
|
+
method: "POST",
|
|
2946
|
+
path: "/context/operation",
|
|
2947
|
+
effect: "read",
|
|
2948
|
+
desc: "Read durable native compaction completion evidence",
|
|
2949
|
+
input: ControlContextOperationReadSchema,
|
|
2950
|
+
output: ControlContextOperationResultSchema,
|
|
2951
|
+
idempotent: true
|
|
2952
|
+
},
|
|
2953
|
+
"delegation.application.capabilities": {
|
|
2954
|
+
method: "POST",
|
|
2955
|
+
path: "/delegation/application/capabilities",
|
|
2956
|
+
effect: "read",
|
|
2957
|
+
input: z49.object({}).strict(),
|
|
2958
|
+
output: ApplicationAuthorityCapabilitiesSchema2,
|
|
2959
|
+
idempotent: true,
|
|
2960
|
+
timeout: 7000,
|
|
2961
|
+
desc: "Application-attested parent authority: capabilities",
|
|
2962
|
+
expose: ["HTTP", "CLI", "MCP"]
|
|
2963
|
+
},
|
|
2964
|
+
"delegation.application.open": {
|
|
2965
|
+
method: "POST",
|
|
2966
|
+
path: "/delegation/application/open",
|
|
2967
|
+
effect: "write",
|
|
2968
|
+
input: ApplicationAuthorityOpenSchema2,
|
|
2969
|
+
output: ApplicationAuthoritySchema2,
|
|
2970
|
+
idempotent: true,
|
|
2971
|
+
timeout: 7000,
|
|
2972
|
+
desc: "Application-attested parent authority: open",
|
|
2973
|
+
expose: ["HTTP", "CLI", "MCP"]
|
|
2974
|
+
},
|
|
2975
|
+
"delegation.application.renew": {
|
|
2976
|
+
method: "POST",
|
|
2977
|
+
path: "/delegation/application/renew",
|
|
2978
|
+
effect: "write",
|
|
2979
|
+
input: ApplicationAuthorityUpdateSchema2,
|
|
2980
|
+
output: ApplicationAuthoritySchema2,
|
|
2981
|
+
idempotent: true,
|
|
2982
|
+
timeout: 7000,
|
|
2983
|
+
desc: "Application-attested parent authority: renew",
|
|
2984
|
+
expose: ["HTTP", "CLI", "MCP"]
|
|
2985
|
+
},
|
|
2986
|
+
"delegation.application.close": {
|
|
2987
|
+
method: "POST",
|
|
2988
|
+
path: "/delegation/application/close",
|
|
2989
|
+
effect: "write",
|
|
2990
|
+
input: ApplicationAuthorityUpdateSchema2,
|
|
2991
|
+
output: ApplicationAuthoritySchema2,
|
|
2992
|
+
idempotent: true,
|
|
2993
|
+
timeout: 7000,
|
|
2994
|
+
desc: "Application-attested parent authority: close",
|
|
2995
|
+
expose: ["HTTP", "CLI", "MCP"]
|
|
2996
|
+
},
|
|
2997
|
+
"delegation.cancel": {
|
|
2998
|
+
method: "POST",
|
|
2999
|
+
path: "/delegation/cancel",
|
|
3000
|
+
effect: "write",
|
|
3001
|
+
input: DelegationCancelSchema,
|
|
3002
|
+
output: DelegationCancelReceiptSchema,
|
|
3003
|
+
idempotent: true,
|
|
3004
|
+
timeout: 15000,
|
|
3005
|
+
desc: "Cancel exact parent-owned delegated work",
|
|
3006
|
+
expose: ["HTTP", "CLI", "MCP"]
|
|
3007
|
+
},
|
|
3008
|
+
"session.idle": {
|
|
3009
|
+
method: "POST",
|
|
3010
|
+
path: "/session/idle",
|
|
3011
|
+
effect: "read",
|
|
3012
|
+
input: SleepTargetSchema,
|
|
3013
|
+
output: IdleProofSchema,
|
|
3014
|
+
idempotent: true,
|
|
3015
|
+
refuses: [
|
|
3016
|
+
...SHARED_SESSION_REFUSALS,
|
|
3017
|
+
refuse.CONTEXT_UNAVAILABLE,
|
|
3018
|
+
refuse.REGISTRATION_UNAVAILABLE
|
|
3019
|
+
],
|
|
3020
|
+
desc: "Measure an exact managed session idle proof",
|
|
3021
|
+
expose: ["HTTP", "CLI", "MCP"]
|
|
3022
|
+
},
|
|
3023
|
+
"session.sleep": {
|
|
3024
|
+
method: "POST",
|
|
3025
|
+
path: "/session/sleep",
|
|
3026
|
+
effect: "write",
|
|
3027
|
+
input: SleepRequestSchema,
|
|
3028
|
+
output: SleepReceiptSchema,
|
|
3029
|
+
idempotent: true,
|
|
3030
|
+
timeout: 30000,
|
|
3031
|
+
refuses: [
|
|
3032
|
+
...SHARED_SESSION_REFUSALS,
|
|
3033
|
+
refuse.CONTEXT_UNAVAILABLE,
|
|
3034
|
+
refuse.IDEMPOTENCY_CONFLICT,
|
|
3035
|
+
refuse.MIN_AWAKE_PER_PROFILE,
|
|
3036
|
+
refuse.NOT_IDLE,
|
|
3037
|
+
refuse.PINNED_SESSION,
|
|
3038
|
+
refuse.PROFILE_UNAVAILABLE,
|
|
3039
|
+
refuse.REGISTRATION_UNAVAILABLE,
|
|
3040
|
+
refuse.REVISION_CONFLICT,
|
|
3041
|
+
refuse.SLEEP_PENDING,
|
|
3042
|
+
refuse.SLEEP_SUPERSEDED
|
|
3043
|
+
],
|
|
3044
|
+
desc: "Put one idle managed session to sleep using revision CAS",
|
|
3045
|
+
expose: ["HTTP", "CLI", "MCP"]
|
|
3046
|
+
},
|
|
3047
|
+
"session.sleep-idle": {
|
|
3048
|
+
method: "POST",
|
|
3049
|
+
path: "/session/sleep-idle",
|
|
3050
|
+
effect: "write",
|
|
3051
|
+
input: SleepIdleRequestSchema,
|
|
3052
|
+
output: SleepIdleResultSchema,
|
|
3053
|
+
timeout: 30000,
|
|
3054
|
+
desc: "Put every session idle at least N minutes to sleep, or with dryRun say which would be, with a receipt per session",
|
|
3055
|
+
expose: ["HTTP", "CLI", "MCP"]
|
|
3056
|
+
},
|
|
3057
|
+
"session.wake": {
|
|
3058
|
+
method: "POST",
|
|
3059
|
+
path: "/session/wake",
|
|
3060
|
+
effect: "write",
|
|
3061
|
+
input: WakeRequestSchema,
|
|
3062
|
+
output: SleepReceiptSchema,
|
|
3063
|
+
idempotent: true,
|
|
3064
|
+
timeout: 30000,
|
|
3065
|
+
refuses: [
|
|
3066
|
+
...SHARED_SESSION_REFUSALS,
|
|
3067
|
+
refuse.NOT_SLEEPING,
|
|
3068
|
+
refuse.SESSION_BLOCKED,
|
|
3069
|
+
refuse.SLEEP_PENDING,
|
|
3070
|
+
refuse.SLEEP_SUPERSEDED,
|
|
3071
|
+
refuse.WAKE_CAPACITY,
|
|
3072
|
+
refuse.WAKE_FAILED,
|
|
3073
|
+
refuse.WAKE_PENDING
|
|
3074
|
+
],
|
|
3075
|
+
desc: "Wake a sleeping managed session",
|
|
3076
|
+
expose: ["HTTP", "CLI", "MCP"]
|
|
3077
|
+
},
|
|
3078
|
+
"session.pin": {
|
|
3079
|
+
method: "POST",
|
|
3080
|
+
path: "/session/pin",
|
|
3081
|
+
effect: "write",
|
|
3082
|
+
input: PinRequestSchema,
|
|
3083
|
+
output: PinReceiptSchema,
|
|
3084
|
+
idempotent: true,
|
|
3085
|
+
timeout: 15000,
|
|
3086
|
+
refuses: [...SHARED_SESSION_REFUSALS, refuse.ARCHIVED],
|
|
3087
|
+
desc: "Pin or unpin a managed session against sleep without restarting it",
|
|
3088
|
+
expose: ["HTTP", "CLI", "MCP"]
|
|
3089
|
+
},
|
|
3090
|
+
"session.fork": {
|
|
3091
|
+
method: "POST",
|
|
3092
|
+
path: "/fork",
|
|
3093
|
+
effect: "write",
|
|
3094
|
+
desc: "Fork one idle native conversation without changing its source",
|
|
3095
|
+
input: NativeForkRequestSchema,
|
|
3096
|
+
output: ControlCreateReceiptSchema,
|
|
3097
|
+
idempotent: true,
|
|
3098
|
+
timeout: 30000
|
|
3099
|
+
},
|
|
3100
|
+
"turn.steer": {
|
|
3101
|
+
method: "POST",
|
|
3102
|
+
path: "/turn/steer",
|
|
3103
|
+
effect: "write",
|
|
3104
|
+
desc: "Submit content to an exact active native turn",
|
|
3105
|
+
input: SteeringInputSchema,
|
|
3106
|
+
output: SteeringReceiptSchema,
|
|
3107
|
+
idempotent: true,
|
|
3108
|
+
timeout: 15000
|
|
3109
|
+
},
|
|
3110
|
+
"turn.steering-operation": {
|
|
3111
|
+
method: "POST",
|
|
3112
|
+
path: "/turn/steering-operation",
|
|
3113
|
+
effect: "read",
|
|
3114
|
+
desc: "Read exact steering acceptance without resubmission",
|
|
3115
|
+
input: SteeringSelectorSchema,
|
|
3116
|
+
output: SteeringReadResultSchema,
|
|
3117
|
+
idempotent: true
|
|
3118
|
+
},
|
|
3119
|
+
"selection.read": {
|
|
3120
|
+
method: "POST",
|
|
3121
|
+
path: "/selection",
|
|
3122
|
+
effect: "read",
|
|
3123
|
+
desc: "Read the exact session's revisioned native turn defaults",
|
|
3124
|
+
input: SelectionReadSchema,
|
|
3125
|
+
output: SelectionResultSchema,
|
|
3126
|
+
idempotent: true
|
|
3127
|
+
},
|
|
3128
|
+
"selection.update": {
|
|
3129
|
+
method: "POST",
|
|
3130
|
+
path: "/selection/update",
|
|
3131
|
+
effect: "write",
|
|
3132
|
+
desc: "Change native turn defaults between turns with revision CAS",
|
|
3133
|
+
input: SelectionUpdateSchema,
|
|
3134
|
+
output: SelectionResultSchema,
|
|
3135
|
+
idempotent: true
|
|
3136
|
+
},
|
|
3137
|
+
"attachment.begin": {
|
|
3138
|
+
method: "POST",
|
|
3139
|
+
path: "/attachment/begin",
|
|
3140
|
+
effect: "write",
|
|
3141
|
+
desc: "Reserve one bounded image upload for an exact target",
|
|
3142
|
+
input: AttachmentBeginSchema,
|
|
3143
|
+
output: AttachmentUploadReceiptSchema,
|
|
3144
|
+
idempotent: true
|
|
3145
|
+
},
|
|
3146
|
+
"attachment.chunk": {
|
|
3147
|
+
method: "POST",
|
|
3148
|
+
path: "/attachment/chunk",
|
|
3149
|
+
effect: "write",
|
|
3150
|
+
desc: "Append one authenticated bounded image chunk",
|
|
3151
|
+
input: AttachmentChunkSchema,
|
|
3152
|
+
output: AttachmentUploadReceiptSchema,
|
|
3153
|
+
idempotent: true
|
|
3154
|
+
},
|
|
3155
|
+
"attachment.finalize": {
|
|
3156
|
+
method: "POST",
|
|
3157
|
+
path: "/attachment/finalize",
|
|
3158
|
+
effect: "write",
|
|
3159
|
+
desc: "Verify complete image bytes and return an immutable reference",
|
|
3160
|
+
input: AttachmentUploadSelectorSchema,
|
|
3161
|
+
output: AttachmentReferenceSchema,
|
|
3162
|
+
idempotent: true
|
|
3163
|
+
},
|
|
3164
|
+
"attachment.cancel": {
|
|
3165
|
+
method: "POST",
|
|
3166
|
+
path: "/attachment/cancel",
|
|
3167
|
+
effect: "write",
|
|
3168
|
+
desc: "Cancel an unretained image upload",
|
|
3169
|
+
input: AttachmentUploadSelectorSchema,
|
|
3170
|
+
output: AttachmentCancelReceiptSchema,
|
|
3171
|
+
idempotent: true
|
|
3172
|
+
},
|
|
3173
|
+
"attachment.read": {
|
|
3174
|
+
method: "POST",
|
|
3175
|
+
path: "/attachment/read",
|
|
3176
|
+
effect: "read",
|
|
3177
|
+
desc: "Read one authorized preview chunk; never expose owner paths",
|
|
3178
|
+
input: AttachmentReadSchema,
|
|
3179
|
+
output: AttachmentReadReceiptSchema,
|
|
3180
|
+
idempotent: true
|
|
3181
|
+
},
|
|
3182
|
+
"runtime.list": {
|
|
3183
|
+
method: "POST",
|
|
3184
|
+
path: "/runtimes",
|
|
3185
|
+
effect: "read",
|
|
3186
|
+
desc: "Discover configured execution runtimes and explicit capabilities",
|
|
3187
|
+
expose: ["HTTP", "CLI", "MCP"],
|
|
3188
|
+
idempotent: true,
|
|
3189
|
+
input: RuntimeCatalogInputSchema,
|
|
3190
|
+
output: RuntimeCatalogSchema,
|
|
3191
|
+
tool: { name: "runtimes" }
|
|
3192
|
+
},
|
|
3193
|
+
"directory.list": {
|
|
3194
|
+
method: "POST",
|
|
3195
|
+
path: "/directories",
|
|
3196
|
+
effect: "read",
|
|
3197
|
+
desc: "List directory names without following symlinks",
|
|
3198
|
+
expose: ["HTTP", "CLI", "MCP"],
|
|
3199
|
+
idempotent: true,
|
|
3200
|
+
input: ControlDirectoryReadSchema,
|
|
3201
|
+
output: ControlDirectoryResultSchema,
|
|
3202
|
+
tool: { name: "directories" }
|
|
3203
|
+
},
|
|
3204
|
+
"session.list": {
|
|
3205
|
+
method: "POST",
|
|
3206
|
+
path: "/sessions",
|
|
3207
|
+
effect: "read",
|
|
3208
|
+
desc: "Read the prepared managed-session snapshot",
|
|
3209
|
+
expose: ["HTTP", "CLI", "MCP"],
|
|
3210
|
+
output: ControlSnapshotSchema,
|
|
3211
|
+
refuses: [],
|
|
3212
|
+
tool: { name: "sessions" }
|
|
3213
|
+
},
|
|
3214
|
+
"session.get": {
|
|
3215
|
+
method: "POST",
|
|
3216
|
+
path: "/session",
|
|
3217
|
+
effect: "read",
|
|
3218
|
+
desc: "Read one exact managed session",
|
|
3219
|
+
expose: ["HTTP", "CLI", "MCP"],
|
|
3220
|
+
idempotent: true,
|
|
3221
|
+
input: ControlTargetSchema,
|
|
3222
|
+
output: ControlRowSchema,
|
|
3223
|
+
tool: { name: "session" }
|
|
3224
|
+
},
|
|
3225
|
+
"session.create": {
|
|
3226
|
+
method: "POST",
|
|
3227
|
+
path: "/create",
|
|
3228
|
+
effect: "write",
|
|
3229
|
+
desc: "Idempotently create one workspace-scoped managed runtime session",
|
|
3230
|
+
expose: ["HTTP", "CLI", "MCP"],
|
|
3231
|
+
idempotent: true,
|
|
3232
|
+
input: ControlCreateSchema,
|
|
3233
|
+
output: ControlCreateReceiptSchema,
|
|
3234
|
+
timeout: 30000,
|
|
3235
|
+
tool: { name: "create_session" }
|
|
3236
|
+
},
|
|
3237
|
+
"session.archive": {
|
|
3238
|
+
method: "POST",
|
|
3239
|
+
path: "/archive",
|
|
3240
|
+
effect: "write",
|
|
3241
|
+
desc: "Archive and stop one exact managed identity without deleting provider history",
|
|
3242
|
+
expose: ["HTTP", "CLI", "MCP"],
|
|
3243
|
+
idempotent: true,
|
|
3244
|
+
input: ControlTargetSchema,
|
|
3245
|
+
output: ControlArchiveReceiptSchema,
|
|
3246
|
+
tool: { name: "archive_session" }
|
|
3247
|
+
},
|
|
3248
|
+
"message.send": {
|
|
3249
|
+
method: "POST",
|
|
3250
|
+
path: "/message",
|
|
3251
|
+
effect: "write",
|
|
3252
|
+
desc: "Accept an identity-pinned message into durable chat; acceptance is not completion",
|
|
3253
|
+
expose: ["HTTP", "CLI", "MCP"],
|
|
3254
|
+
idempotent: true,
|
|
3255
|
+
input: ControlMessageSchema,
|
|
3256
|
+
output: ControlMessageReceiptSchema,
|
|
3257
|
+
tool: { name: "message" }
|
|
3258
|
+
},
|
|
3259
|
+
"session.start": {
|
|
3260
|
+
method: "POST",
|
|
3261
|
+
path: "/start",
|
|
3262
|
+
effect: "write",
|
|
3263
|
+
desc: "Start an existing registered session without changing its identity",
|
|
3264
|
+
expose: ["HTTP", "CLI", "MCP"],
|
|
3265
|
+
input: ControlTargetSchema,
|
|
3266
|
+
output: ControlActionReceiptSchema,
|
|
3267
|
+
tool: { name: "start" }
|
|
3268
|
+
},
|
|
3269
|
+
"session.stop": {
|
|
3270
|
+
method: "POST",
|
|
3271
|
+
path: "/stop",
|
|
3272
|
+
effect: "write",
|
|
3273
|
+
desc: "Stop one registered session; it stays registered and can be started again",
|
|
3274
|
+
expose: ["HTTP", "CLI", "MCP"],
|
|
3275
|
+
idempotent: true,
|
|
3276
|
+
input: ControlTargetSchema,
|
|
3277
|
+
output: ControlStopReceiptSchema,
|
|
3278
|
+
tool: { name: "stop" }
|
|
3279
|
+
},
|
|
3280
|
+
"session.restart": {
|
|
3281
|
+
method: "POST",
|
|
3282
|
+
path: "/restart",
|
|
3283
|
+
effect: "write",
|
|
3284
|
+
desc: "Stop one registered session and start it again under the same identity; the relaunch continues after this answer",
|
|
3285
|
+
expose: ["HTTP", "CLI", "MCP"],
|
|
3286
|
+
input: ControlTargetSchema,
|
|
3287
|
+
output: ControlActionReceiptSchema,
|
|
3288
|
+
tool: { name: "restart" }
|
|
3289
|
+
},
|
|
3290
|
+
"session.remove": {
|
|
3291
|
+
method: "POST",
|
|
3292
|
+
path: "/remove",
|
|
3293
|
+
effect: "write",
|
|
3294
|
+
desc: "Stop one session and take it out of the registry; the provider history stays on disk",
|
|
3295
|
+
expose: ["HTTP", "CLI", "MCP"],
|
|
3296
|
+
input: ControlTargetSchema,
|
|
3297
|
+
output: ControlStopReceiptSchema,
|
|
3298
|
+
tool: { name: "remove_session" }
|
|
3299
|
+
},
|
|
3300
|
+
"session.keys": {
|
|
3301
|
+
method: "POST",
|
|
3302
|
+
path: "/keys",
|
|
3303
|
+
effect: "write",
|
|
3304
|
+
desc: "Type text and Enter into a session terminal composer \u2014 a slash command or a numbered menu answer \u2014 and record that stitchmux typed it; a message to an agent is message.send",
|
|
3305
|
+
expose: ["HTTP", "CLI", "MCP"],
|
|
3306
|
+
input: ControlKeysSchema,
|
|
3307
|
+
output: ControlActionReceiptSchema,
|
|
3308
|
+
tool: { name: "keys" }
|
|
3309
|
+
},
|
|
3310
|
+
"turn.interrupt": {
|
|
3311
|
+
method: "POST",
|
|
3312
|
+
path: "/interrupt",
|
|
3313
|
+
effect: "write",
|
|
3314
|
+
desc: "Interrupt the exact active native turn; never answer an approval or input request",
|
|
3315
|
+
expose: ["HTTP", "CLI", "MCP"],
|
|
3316
|
+
input: ControlInterruptSchema,
|
|
3317
|
+
output: ControlActionReceiptSchema,
|
|
3318
|
+
tool: { name: "interrupt" }
|
|
3319
|
+
},
|
|
3320
|
+
"native.read": {
|
|
3321
|
+
method: "POST",
|
|
3322
|
+
path: "/native",
|
|
3323
|
+
effect: "read",
|
|
3324
|
+
desc: "Read a bounded native item snapshot after an optional cursor",
|
|
3325
|
+
expose: ["HTTP", "CLI", "MCP"],
|
|
3326
|
+
idempotent: true,
|
|
3327
|
+
input: ControlNativeReadSchema,
|
|
3328
|
+
output: ControlNativeSnapshotSchema,
|
|
3329
|
+
tool: { name: "native_items" }
|
|
3330
|
+
},
|
|
3331
|
+
"model.list": {
|
|
3332
|
+
method: "POST",
|
|
3333
|
+
path: "/models",
|
|
3334
|
+
effect: "read",
|
|
3335
|
+
desc: "Read the connected App Server model catalog after an optional cursor; provider-owned and read-only",
|
|
3336
|
+
expose: ["HTTP", "CLI", "MCP"],
|
|
3337
|
+
idempotent: true,
|
|
3338
|
+
timeout: 1e4,
|
|
3339
|
+
input: ControlModelsReadSchema,
|
|
3340
|
+
output: ControlModelCatalogSchema,
|
|
3341
|
+
tool: { name: "models" }
|
|
3342
|
+
},
|
|
3343
|
+
"command.list": {
|
|
3344
|
+
method: "POST",
|
|
3345
|
+
path: "/commands",
|
|
3346
|
+
effect: "read",
|
|
3347
|
+
desc: "Read the slash commands this session runtime offers",
|
|
3348
|
+
expose: ["HTTP", "CLI", "MCP"],
|
|
3349
|
+
idempotent: true,
|
|
3350
|
+
input: ControlCommandsReadSchema,
|
|
3351
|
+
output: ControlCommandCatalogSchema,
|
|
3352
|
+
tool: { name: "commands" }
|
|
3353
|
+
},
|
|
3354
|
+
"command.run": {
|
|
3355
|
+
method: "POST",
|
|
3356
|
+
path: "/command",
|
|
3357
|
+
effect: "write",
|
|
3358
|
+
desc: "Run one slash command the runtime offers, as a turn of its own",
|
|
3359
|
+
expose: ["HTTP", "CLI", "MCP"],
|
|
3360
|
+
idempotent: true,
|
|
3361
|
+
input: ControlRunCommandSchema,
|
|
3362
|
+
output: ControlRunCommandReceiptSchema,
|
|
3363
|
+
tool: { name: "run_command" }
|
|
3364
|
+
},
|
|
3365
|
+
"permission.mode": {
|
|
3366
|
+
method: "POST",
|
|
3367
|
+
path: "/permission-mode",
|
|
3368
|
+
effect: "write",
|
|
3369
|
+
desc: "Set the permission mode the session runs its next turns under",
|
|
3370
|
+
expose: ["HTTP", "CLI", "MCP"],
|
|
3371
|
+
idempotent: true,
|
|
3372
|
+
input: ControlPermissionModeSchema,
|
|
3373
|
+
output: ControlPermissionModeReceiptSchema,
|
|
3374
|
+
tool: { name: "permission_mode" }
|
|
3375
|
+
},
|
|
3376
|
+
"permission.read": {
|
|
3377
|
+
method: "POST",
|
|
3378
|
+
path: "/permission",
|
|
3379
|
+
effect: "read",
|
|
3380
|
+
desc: "Read the permission mode accepted for future turns and the one observed natively",
|
|
3381
|
+
expose: ["HTTP", "CLI", "MCP"],
|
|
3382
|
+
idempotent: true,
|
|
3383
|
+
input: ControlPermissionReadSchema,
|
|
3384
|
+
output: ControlPermissionResultSchema,
|
|
3385
|
+
tool: { name: "permission_read" }
|
|
3386
|
+
},
|
|
3387
|
+
"permission.update": {
|
|
3388
|
+
method: "POST",
|
|
3389
|
+
path: "/permission/update",
|
|
3390
|
+
effect: "write",
|
|
3391
|
+
desc: "Replace the accepted permission mode, refusing a stale expected revision",
|
|
3392
|
+
expose: ["HTTP", "CLI", "MCP"],
|
|
3393
|
+
idempotent: true,
|
|
3394
|
+
input: ControlPermissionUpdateSchema,
|
|
3395
|
+
output: ControlPermissionResultSchema,
|
|
3396
|
+
tool: { name: "permission_update" }
|
|
3397
|
+
},
|
|
3398
|
+
"mcp.list": {
|
|
3399
|
+
method: "POST",
|
|
3400
|
+
path: "/mcp",
|
|
3401
|
+
effect: "read",
|
|
3402
|
+
desc: "Read the MCP servers of a session and each one connection status",
|
|
3403
|
+
expose: ["HTTP", "CLI", "MCP"],
|
|
3404
|
+
idempotent: true,
|
|
3405
|
+
input: ControlMcpReadSchema,
|
|
3406
|
+
output: ControlMcpListSchema,
|
|
3407
|
+
tool: { name: "mcp_servers" }
|
|
3408
|
+
},
|
|
3409
|
+
"mcp.control": {
|
|
3410
|
+
method: "POST",
|
|
3411
|
+
path: "/mcp/control",
|
|
3412
|
+
effect: "write",
|
|
3413
|
+
desc: "Enable, disable or reconnect one MCP server of a session",
|
|
3414
|
+
expose: ["HTTP", "CLI", "MCP"],
|
|
3415
|
+
idempotent: true,
|
|
3416
|
+
timeout: 30000,
|
|
3417
|
+
input: ControlMcpControlSchema,
|
|
3418
|
+
output: ControlMcpControlReceiptSchema,
|
|
3419
|
+
tool: { name: "mcp_control" }
|
|
3420
|
+
},
|
|
3421
|
+
"session.rewind": {
|
|
3422
|
+
method: "POST",
|
|
3423
|
+
path: "/rewind",
|
|
3424
|
+
effect: "write",
|
|
3425
|
+
desc: "Preview or perform a rewind of the files a session modified",
|
|
3426
|
+
expose: ["HTTP", "CLI", "MCP"],
|
|
3427
|
+
idempotent: true,
|
|
3428
|
+
timeout: 30000,
|
|
3429
|
+
input: ControlRewindSchema,
|
|
3430
|
+
output: ControlRewindReceiptSchema,
|
|
3431
|
+
tool: { name: "rewind_files" }
|
|
3432
|
+
},
|
|
3433
|
+
"native.respond": {
|
|
3434
|
+
method: "POST",
|
|
3435
|
+
path: "/native/respond",
|
|
3436
|
+
effect: "write",
|
|
3437
|
+
desc: "Answer one exact current native approval or input request",
|
|
3438
|
+
expose: ["HTTP", "CLI", "MCP"],
|
|
3439
|
+
idempotent: true,
|
|
3440
|
+
input: ControlNativeResponseSchema,
|
|
3441
|
+
output: ControlNativeResponseReceiptSchema,
|
|
3442
|
+
tool: { name: "respond_native" }
|
|
3443
|
+
},
|
|
3444
|
+
"session.wait": {
|
|
3445
|
+
method: "POST",
|
|
3446
|
+
path: "/wait",
|
|
3447
|
+
effect: "read",
|
|
3448
|
+
desc: "Wait for a native session between turns, including pending chat pickup",
|
|
3449
|
+
expose: ["HTTP", "CLI", "MCP"],
|
|
3450
|
+
idempotent: true,
|
|
3451
|
+
input: ControlWaitSchema,
|
|
3452
|
+
output: ControlWaitResultSchema,
|
|
3453
|
+
tool: { name: "wait" }
|
|
3454
|
+
}
|
|
3455
|
+
});
|
|
3456
|
+
|
|
3457
|
+
// src/control/transport/boundary.ts
|
|
3458
|
+
var ControlTransportCallerSchema = z50.string().max(128).regex(RC_PREFIX_RE);
|
|
3459
|
+
function createInjectedControlClient(fetch, timeoutMs = 30000) {
|
|
3460
|
+
return createClient(controlContract, {
|
|
3461
|
+
baseUrl: "http://stitchmux.local",
|
|
3462
|
+
fetch,
|
|
3463
|
+
timeout: timeoutMs,
|
|
3464
|
+
retry: { limit: 0 }
|
|
3465
|
+
});
|
|
3466
|
+
}
|
|
3467
|
+
// src/control/schema/eventsContract.ts
|
|
3468
|
+
import { defineContract as defineContract5 } from "stitchkit";
|
|
3469
|
+
|
|
3470
|
+
// src/control/schema/searchContract.ts
|
|
3471
|
+
import { defineContract as defineContract4 } from "stitchkit";
|
|
3472
|
+
|
|
3473
|
+
// src/context/searchFrames.ts
|
|
3474
|
+
import { z as z52 } from "zod";
|
|
3475
|
+
|
|
3476
|
+
// src/context/corpusSearchSchema.ts
|
|
3477
|
+
import { z as z51 } from "zod";
|
|
3478
|
+
var ConversationRefSchema = z51.object({
|
|
3479
|
+
address: z51.string().min(1),
|
|
3480
|
+
provider: z51.enum(["claude", "codex"]),
|
|
3481
|
+
threadId: z51.string().min(1),
|
|
3482
|
+
session: z51.string().nullable(),
|
|
3483
|
+
ofSession: z51.string().nullable(),
|
|
3484
|
+
dir: z51.string().nullable(),
|
|
3485
|
+
repository: z51.string().nullable(),
|
|
3486
|
+
project: DeclaredProjectSchema.optional()
|
|
3487
|
+
});
|
|
3488
|
+
var CorpusMatchSchema = ConversationRefSchema.extend({
|
|
3489
|
+
lines: z51.boolean(),
|
|
3490
|
+
seq: z51.int().positive(),
|
|
3491
|
+
createdAt: z51.string().nullable(),
|
|
3492
|
+
role: TranscriptRoleSchema,
|
|
3493
|
+
kind: TranscriptKindSchema,
|
|
3494
|
+
toolName: z51.string().nullable(),
|
|
3495
|
+
field: z51.enum(["text", "input", "output"]),
|
|
3496
|
+
count: z51.int().positive(),
|
|
3497
|
+
excerpt: z51.object({ before: z51.string(), match: z51.string(), after: z51.string() }),
|
|
3498
|
+
text: z51.string().nullable()
|
|
3499
|
+
});
|
|
3500
|
+
var ConversationHitsSchema = ConversationRefSchema.extend({
|
|
3501
|
+
total: z51.int().positive(),
|
|
3502
|
+
user: z51.int().nonnegative(),
|
|
3503
|
+
assistant: z51.int().nonnegative(),
|
|
3504
|
+
firstAt: z51.string().nullable(),
|
|
3505
|
+
lastAt: z51.string().nullable(),
|
|
3506
|
+
sample: CorpusMatchSchema
|
|
3507
|
+
});
|
|
3508
|
+
var DeliverySchema = ConversationRefSchema.extend({
|
|
3509
|
+
lines: z51.boolean(),
|
|
3510
|
+
seq: z51.int().positive(),
|
|
3511
|
+
receivedAt: z51.string().nullable().describe("When the first message carrying the mark in this conversation was written; null when it does not say."),
|
|
3512
|
+
role: TranscriptRoleSchema,
|
|
3513
|
+
messageId: z51.string().describe("The provider's id of that message within its conversation. A Claude session continued in a new file carries copies of its earlier messages under the same id; such copies are one delivery."),
|
|
3514
|
+
sender: MessageSenderSchema.nullable().optional().describe("Who sent that first message, in the words of `transcript --json`: person, session-letter, routed-input, harness, stitchmux-keys or unverifiable. Null when the message is not on the user's side. Absent when the machine holding the conversation runs a release that does not say \u2014 not the same as null.")
|
|
3515
|
+
});
|
|
3516
|
+
var RECEIPT_MARKS_MAX = 1e4;
|
|
3517
|
+
var receiptsOf = (delivery) => z51.object({
|
|
3518
|
+
truncated: z51.boolean().describe("More distinct marks matched than are listed: narrow the pattern or the dates."),
|
|
3519
|
+
marks: z51.array(z51.object({
|
|
3520
|
+
mark: z51.string().describe("What the pattern matched: its first capture group, or the whole match when it has none."),
|
|
3521
|
+
deliveries: z51.array(delivery).min(1).describe("Every conversation that holds the mark, one entry each, by when it arrived there, oldest first. `ofSession` on its machine is the session it belongs to; `limit` does not apply.")
|
|
3522
|
+
}))
|
|
3523
|
+
});
|
|
3524
|
+
var ReceiptsSchema = receiptsOf(DeliverySchema);
|
|
3525
|
+
var MachineCoverageSchema = z51.object({
|
|
3526
|
+
machine: z51.string().min(1),
|
|
3527
|
+
status: z51.literal("searched"),
|
|
3528
|
+
elapsedMs: z51.int().nonnegative(),
|
|
3529
|
+
conversations: z51.int().nonnegative(),
|
|
3530
|
+
files: z51.int().nonnegative(),
|
|
3531
|
+
bytes: z51.int().nonnegative(),
|
|
3532
|
+
skippedFiles: z51.int().nonnegative(),
|
|
3533
|
+
unreadableFiles: z51.int().nonnegative(),
|
|
3534
|
+
total: z51.int().nonnegative()
|
|
3535
|
+
});
|
|
3536
|
+
var MachineUnavailableSchema = z51.object({
|
|
3537
|
+
machine: z51.string().min(1),
|
|
3538
|
+
status: z51.literal("unavailable"),
|
|
3539
|
+
error: z51.string()
|
|
3540
|
+
});
|
|
3541
|
+
var onMachine = { machine: z51.string().min(1) };
|
|
3542
|
+
var FleetConversationHitsSchema = ConversationHitsSchema.extend(onMachine);
|
|
3543
|
+
var FleetMatchSchema = CorpusMatchSchema.extend(onMachine);
|
|
3544
|
+
var FleetDeliverySchema = DeliverySchema.extend(onMachine);
|
|
3545
|
+
var CorpusSearchJsonSchema = z51.object({
|
|
3546
|
+
query: z51.object({
|
|
3547
|
+
pattern: z51.string().nullable(),
|
|
3548
|
+
flags: z51.string(),
|
|
3549
|
+
roles: z51.array(TranscriptRoleSchema).nullable(),
|
|
3550
|
+
kinds: z51.array(TranscriptKindSchema),
|
|
3551
|
+
providers: z51.array(z51.enum(["claude", "codex"])).nullable(),
|
|
3552
|
+
project: z51.string().nullable(),
|
|
3553
|
+
since: z51.string().nullable(),
|
|
3554
|
+
until: z51.string().nullable(),
|
|
3555
|
+
limit: z51.int().positive(),
|
|
3556
|
+
full: z51.boolean(),
|
|
3557
|
+
receipts: z51.boolean().optional()
|
|
3558
|
+
}),
|
|
3559
|
+
machines: z51.array(z51.union([MachineCoverageSchema, MachineUnavailableSchema])),
|
|
3560
|
+
total: z51.int().nonnegative(),
|
|
3561
|
+
truncated: z51.boolean(),
|
|
3562
|
+
conversations: z51.array(FleetConversationHitsSchema),
|
|
3563
|
+
matches: z51.array(FleetMatchSchema),
|
|
3564
|
+
receipts: receiptsOf(FleetDeliverySchema).optional()
|
|
3565
|
+
});
|
|
3566
|
+
|
|
3567
|
+
// src/context/searchFrames.ts
|
|
3568
|
+
var SEARCH_FRAME_MAX_BYTES = 6 * 1024 * 1024;
|
|
3569
|
+
var Summary = CorpusSearchJsonSchema.pick({
|
|
3570
|
+
query: true,
|
|
3571
|
+
machines: true,
|
|
3572
|
+
total: true,
|
|
3573
|
+
truncated: true
|
|
3574
|
+
});
|
|
3575
|
+
var SearchFrameSchema = z52.discriminatedUnion("frame", [
|
|
3576
|
+
z52.object({ frame: z52.literal("match"), match: FleetMatchSchema }),
|
|
3577
|
+
z52.object({ frame: z52.literal("conversation"), conversation: FleetConversationHitsSchema }),
|
|
3578
|
+
z52.object({
|
|
3579
|
+
frame: z52.literal("mark"),
|
|
3580
|
+
mark: z52.string(),
|
|
3581
|
+
deliveries: z52.array(FleetDeliverySchema).min(1)
|
|
3582
|
+
}),
|
|
3583
|
+
Summary.extend({
|
|
3584
|
+
frame: z52.literal("end"),
|
|
3585
|
+
marksTruncated: z52.boolean().optional()
|
|
3586
|
+
})
|
|
3587
|
+
]);
|
|
3588
|
+
class SearchStreamCutError extends Error {
|
|
3589
|
+
constructor() {
|
|
3590
|
+
super("the search stream ended before its last frame; what arrived is not the whole answer");
|
|
3591
|
+
}
|
|
3592
|
+
}
|
|
3593
|
+
async function collectSearch(frames) {
|
|
3594
|
+
const conversations = [];
|
|
3595
|
+
const matches = [];
|
|
3596
|
+
const marks = [];
|
|
3597
|
+
for await (const frame of frames) {
|
|
3598
|
+
if (frame.frame === "conversation")
|
|
3599
|
+
conversations.push(frame.conversation);
|
|
3600
|
+
else if (frame.frame === "match")
|
|
3601
|
+
matches.push(frame.match);
|
|
3602
|
+
else if (frame.frame === "mark")
|
|
3603
|
+
marks.push({ mark: frame.mark, deliveries: frame.deliveries });
|
|
3604
|
+
else {
|
|
3605
|
+
const { frame: _end, marksTruncated, ...summary } = frame;
|
|
3606
|
+
return {
|
|
3607
|
+
...summary,
|
|
3608
|
+
conversations,
|
|
3609
|
+
matches,
|
|
3610
|
+
...marksTruncated === undefined ? {} : { receipts: { truncated: marksTruncated, marks } }
|
|
3611
|
+
};
|
|
3612
|
+
}
|
|
3613
|
+
}
|
|
3614
|
+
throw new SearchStreamCutError;
|
|
3615
|
+
}
|
|
3616
|
+
|
|
3617
|
+
// src/context/searchRequestSchema.ts
|
|
3618
|
+
import { z as z53 } from "zod";
|
|
3619
|
+
var DEFAULT_MATCHES = 50;
|
|
3620
|
+
var PROVIDERS = ["claude", "codex"];
|
|
3621
|
+
var SEARCH_PROVIDERS = PROVIDERS;
|
|
3622
|
+
var SEARCH_LIMIT_MAX = 1e6;
|
|
3623
|
+
var SearchRequestSchema = z53.object({
|
|
3624
|
+
pattern: z53.string().min(1).max(4096).nullable().default(null),
|
|
3625
|
+
fixed: z53.boolean().default(false),
|
|
3626
|
+
caseMode: z53.enum(["smart", "ignore", "sensitive"]).default("smart"),
|
|
3627
|
+
roles: z53.array(TranscriptRoleSchema).min(1).nullable().default(null),
|
|
3628
|
+
kinds: z53.array(TranscriptKindSchema).min(1).nullable().default(null),
|
|
3629
|
+
providers: z53.array(z53.enum(PROVIDERS)).min(1).nullable().default(null),
|
|
3630
|
+
project: z53.string().min(1).max(1024).nullable().default(null),
|
|
3631
|
+
since: z53.string().min(1).max(64).nullable().default(null),
|
|
3632
|
+
until: z53.string().min(1).max(64).nullable().default(null),
|
|
3633
|
+
limit: z53.int().min(1).max(SEARCH_LIMIT_MAX).default(DEFAULT_MATCHES),
|
|
3634
|
+
full: z53.boolean().default(false),
|
|
3635
|
+
receipts: z53.boolean().default(false),
|
|
3636
|
+
machines: z53.array(z53.string().min(1).max(64)).max(64).nullable().default(null)
|
|
3637
|
+
}).strict();
|
|
3638
|
+
|
|
3639
|
+
// src/control/schema/searchContract.ts
|
|
3640
|
+
var searchContract = defineContract4({ prefix: "control-events", scope: "local" }, {
|
|
3641
|
+
search: {
|
|
3642
|
+
method: "POST",
|
|
3643
|
+
path: "/search",
|
|
3644
|
+
desc: "Search every stored conversation of the fleet; the answer arrives in frames and ends with what was searched and what was not",
|
|
3645
|
+
input: SearchRequestSchema,
|
|
3646
|
+
stream: {
|
|
3647
|
+
item: SearchFrameSchema,
|
|
3648
|
+
format: "ndjson",
|
|
3649
|
+
maxFrameBytes: SEARCH_FRAME_MAX_BYTES + 1024,
|
|
3650
|
+
heartbeatMs: 2000
|
|
3651
|
+
}
|
|
3652
|
+
}
|
|
3653
|
+
});
|
|
3654
|
+
|
|
3655
|
+
// src/control/schema/eventsContract.ts
|
|
3656
|
+
var controlEventsContract = defineContract5({ prefix: "control-events", scope: "local" }, {
|
|
3657
|
+
watch: {
|
|
3658
|
+
method: "GET",
|
|
3659
|
+
path: "/",
|
|
3660
|
+
desc: "Subscribe to bounded absolute snapshots; reconnect establishes a fresh baseline",
|
|
3661
|
+
stream: {
|
|
3662
|
+
item: ControlSnapshotSchema,
|
|
3663
|
+
format: "ndjson",
|
|
3664
|
+
maxFrameBytes: CONTROL_MAX_BYTES + 1024,
|
|
3665
|
+
heartbeatMs: 2000
|
|
3666
|
+
}
|
|
3667
|
+
},
|
|
3668
|
+
watchExternal: {
|
|
3669
|
+
method: "GET",
|
|
3670
|
+
path: "/external",
|
|
3671
|
+
desc: "Subscribe to prepared external native status, including unavailable and stale outcomes",
|
|
3672
|
+
stream: {
|
|
3673
|
+
item: ExternalStatusSnapshotSchema,
|
|
3674
|
+
format: "ndjson",
|
|
3675
|
+
maxFrameBytes: EXTERNAL_MAX_BYTES + 1024,
|
|
3676
|
+
heartbeatMs: 2000
|
|
3677
|
+
}
|
|
3678
|
+
},
|
|
3679
|
+
watchNative: {
|
|
3680
|
+
method: "POST",
|
|
3681
|
+
path: "/native",
|
|
3682
|
+
desc: "Subscribe to bounded native item frames; reset marks cursor resync",
|
|
3683
|
+
input: ControlNativeReadSchema,
|
|
3684
|
+
stream: {
|
|
3685
|
+
item: ControlNativeSnapshotSchema,
|
|
3686
|
+
format: "ndjson",
|
|
3687
|
+
maxFrameBytes: CONTROL_MAX_BYTES + 1024,
|
|
3688
|
+
heartbeatMs: 2000
|
|
3689
|
+
}
|
|
3690
|
+
},
|
|
3691
|
+
watchIdentities: {
|
|
3692
|
+
method: "POST",
|
|
3693
|
+
path: "/identities",
|
|
3694
|
+
desc: "Every session of the fleet once, then each change of its directory, project or conversation id; a machine line says a machine was read or could not be",
|
|
3695
|
+
input: IdentityListReadSchema,
|
|
3696
|
+
stream: {
|
|
3697
|
+
item: WhoisEventSchema,
|
|
3698
|
+
format: "ndjson",
|
|
3699
|
+
maxFrameBytes: CONTROL_MAX_BYTES + 1024,
|
|
3700
|
+
heartbeatMs: 2000
|
|
3701
|
+
}
|
|
3702
|
+
},
|
|
3703
|
+
watchChatLog: {
|
|
3704
|
+
method: "POST",
|
|
3705
|
+
path: "/chat",
|
|
3706
|
+
desc: "This machine's chat log from a cursor it gave \u2014 each letter received and sent, as it is written; a machine frame first. Each frame carries the cursor to resume from",
|
|
3707
|
+
input: ChatFollowReadSchema,
|
|
3708
|
+
stream: {
|
|
3709
|
+
item: LogFrameSchema,
|
|
3710
|
+
format: "ndjson",
|
|
3711
|
+
maxFrameBytes: LOG_FRAME_MAX_BYTES + 1024,
|
|
3712
|
+
heartbeatMs: 2000
|
|
3713
|
+
}
|
|
3714
|
+
},
|
|
3715
|
+
...searchContract.endpoints
|
|
3716
|
+
});
|
|
3717
|
+
// src/control/transport/client.ts
|
|
3718
|
+
import { createClient as createClient2, readContractIdentity } from "stitchkit";
|
|
3719
|
+
import { implementRemote } from "stitchkit/remote";
|
|
3720
|
+
|
|
3721
|
+
// src/control/transport/connection.ts
|
|
3722
|
+
import { existsSync, readFileSync } from "fs";
|
|
3723
|
+
import { createHttpClient } from "stitchkit";
|
|
3724
|
+
import { createUnixClientTransport } from "stitchkit/server";
|
|
3725
|
+
import { z as z54 } from "zod";
|
|
3726
|
+
|
|
3727
|
+
// src/control/transport/socketPath.ts
|
|
3728
|
+
import { join } from "path";
|
|
3729
|
+
function controlSocket(m) {
|
|
3730
|
+
return join(m.stateDir, "control", "api.sock");
|
|
3731
|
+
}
|
|
3732
|
+
|
|
3733
|
+
// src/control/transport/connection.ts
|
|
3734
|
+
var ControlClientOptionsSchema = z54.object({
|
|
3735
|
+
socket: z54.string().startsWith("/").optional(),
|
|
3736
|
+
session: z54.string().min(1).optional(),
|
|
3737
|
+
credential: z54.string().min(1).optional(),
|
|
3738
|
+
timeoutMs: z54.number().int().min(1).max(65000).default(65000)
|
|
3739
|
+
}).strict().refine((value) => value.session === undefined === (value.credential === undefined), "Managed session and credential must be supplied together");
|
|
3740
|
+
function createControlConnection(options) {
|
|
3741
|
+
const config = ControlClientOptionsSchema.parse(options);
|
|
3742
|
+
const headers = {};
|
|
3743
|
+
if (config.session && config.credential) {
|
|
3744
|
+
headers["x-stitchmux-session"] = config.session;
|
|
3745
|
+
headers.authorization = `Bearer ${config.credential}`;
|
|
3746
|
+
}
|
|
3747
|
+
const path = machineConfigPath();
|
|
3748
|
+
const socket = config.socket ?? controlSocket(resolveMonitoringLocation(existsSync(path) ? JSON.parse(readFileSync(path, "utf8")) : {}));
|
|
3749
|
+
const common = {
|
|
3750
|
+
socketPath: socket,
|
|
3751
|
+
maxRequestBytes: 64 * 1024,
|
|
3752
|
+
maxHeaderBytes: 16 * 1024,
|
|
3753
|
+
headersTimeoutMs: config.timeoutMs
|
|
3754
|
+
};
|
|
3755
|
+
const unary = createUnixClientTransport({
|
|
3756
|
+
...common,
|
|
3757
|
+
maxConnections: 128,
|
|
3758
|
+
maxResponseBytes: CONTROL_RESPONSE_MAX_BYTES + 1024
|
|
3759
|
+
});
|
|
3760
|
+
let streaming;
|
|
3761
|
+
let stream;
|
|
3762
|
+
return {
|
|
3763
|
+
http: createHttpClient({
|
|
3764
|
+
baseUrl: "http://stitchmux.local",
|
|
3765
|
+
fetch: unary.fetch,
|
|
3766
|
+
timeout: config.timeoutMs,
|
|
3767
|
+
retry: { limit: 0 },
|
|
3768
|
+
headers
|
|
3769
|
+
}),
|
|
3770
|
+
get stream() {
|
|
3771
|
+
streaming ??= createUnixClientTransport({
|
|
3772
|
+
...common,
|
|
3773
|
+
maxConnections: CONTROL_MAX_READERS,
|
|
3774
|
+
responseBodyMode: "streaming"
|
|
3775
|
+
});
|
|
3776
|
+
stream ??= createHttpClient({
|
|
3777
|
+
baseUrl: "http://stitchmux.local",
|
|
3778
|
+
fetch: streaming.fetch,
|
|
3779
|
+
timeout: config.timeoutMs,
|
|
3780
|
+
retry: { limit: 0 },
|
|
3781
|
+
headers
|
|
3782
|
+
});
|
|
3783
|
+
return stream;
|
|
3784
|
+
},
|
|
3785
|
+
close: async () => {
|
|
3786
|
+
await Promise.all([unary.close(), streaming?.close()]);
|
|
3787
|
+
}
|
|
3788
|
+
};
|
|
3789
|
+
}
|
|
3790
|
+
|
|
3791
|
+
// src/control/transport/client.ts
|
|
3792
|
+
var CONTRACTS = [controlContract, controlEventsContract];
|
|
3793
|
+
function createControlClient(options = {}) {
|
|
3794
|
+
const transport = createControlConnection(options);
|
|
3795
|
+
return {
|
|
3796
|
+
...createClient2(controlContract, transport.http),
|
|
3797
|
+
...createClient2(controlEventsContract, transport.stream),
|
|
3798
|
+
identity: () => readContractIdentity(CONTRACTS, transport.http),
|
|
3799
|
+
close: transport.close
|
|
3800
|
+
};
|
|
3801
|
+
}
|
|
3802
|
+
function createControlProxy(options = {}) {
|
|
3803
|
+
const transport = createControlConnection(options);
|
|
3804
|
+
return { ...implementRemote(controlContract, transport.http), close: transport.close };
|
|
3805
|
+
}
|
|
3806
|
+
// src/external/residentFrames.ts
|
|
3807
|
+
import { isDeepStrictEqual } from "util";
|
|
3808
|
+
import { z as z55 } from "zod";
|
|
3809
|
+
var ExternalStatusRenewalSchema = z55.object({
|
|
3810
|
+
frame: z55.literal("renewal"),
|
|
3811
|
+
generation: z55.uuid(),
|
|
3812
|
+
after: z55.number().int().nonnegative(),
|
|
3813
|
+
sequence: z55.number().int().nonnegative(),
|
|
3814
|
+
observedAt: z55.iso.datetime().nullable(),
|
|
3815
|
+
expiresAt: z55.iso.datetime().nullable()
|
|
3816
|
+
}).strict();
|
|
3817
|
+
var ExternalStatusFrameSchema = z55.discriminatedUnion("frame", [
|
|
3818
|
+
z55.object({ frame: z55.literal("snapshot"), snapshot: ExternalStatusSnapshotSchema }).strict(),
|
|
3819
|
+
ExternalStatusRenewalSchema
|
|
3820
|
+
]);
|
|
3821
|
+
function applyExternalStatusFrame(held, frame) {
|
|
3822
|
+
if (frame.frame === "snapshot")
|
|
3823
|
+
return frame.snapshot;
|
|
3824
|
+
if (held === null || held.generation !== frame.generation || held.sequence !== frame.after)
|
|
3825
|
+
return null;
|
|
3826
|
+
return {
|
|
3827
|
+
...held,
|
|
3828
|
+
sequence: frame.sequence,
|
|
3829
|
+
observedAt: frame.observedAt,
|
|
3830
|
+
expiresAt: frame.expiresAt,
|
|
3831
|
+
sessions: held.sessions.map((row) => row.turnState.observedAt === held.observedAt && row.turnState.expiresAt === held.expiresAt ? {
|
|
3832
|
+
...row,
|
|
3833
|
+
turnState: {
|
|
3834
|
+
...row.turnState,
|
|
3835
|
+
observedAt: frame.observedAt,
|
|
3836
|
+
expiresAt: frame.expiresAt
|
|
3837
|
+
}
|
|
3838
|
+
} : row)
|
|
3839
|
+
};
|
|
3840
|
+
}
|
|
3841
|
+
function createExternalStatusEncoder() {
|
|
3842
|
+
let held = null;
|
|
3843
|
+
return (snapshot) => {
|
|
3844
|
+
if (held !== null) {
|
|
3845
|
+
const renewal = {
|
|
3846
|
+
frame: "renewal",
|
|
3847
|
+
generation: snapshot.generation,
|
|
3848
|
+
after: held.sequence,
|
|
3849
|
+
sequence: snapshot.sequence,
|
|
3850
|
+
observedAt: snapshot.observedAt,
|
|
3851
|
+
expiresAt: snapshot.expiresAt
|
|
3852
|
+
};
|
|
3853
|
+
if (isDeepStrictEqual(applyExternalStatusFrame(held, renewal), snapshot)) {
|
|
3854
|
+
held = snapshot;
|
|
3855
|
+
return renewal;
|
|
3856
|
+
}
|
|
3857
|
+
}
|
|
3858
|
+
held = snapshot;
|
|
3859
|
+
return { frame: "snapshot", snapshot };
|
|
3860
|
+
};
|
|
3861
|
+
}
|
|
3862
|
+
export {
|
|
3863
|
+
ATTACHMENT_LIMITS,
|
|
3864
|
+
AcceptedTurnOptionsSchema2 as AcceptedTurnOptionsSchema,
|
|
3865
|
+
AccountProfileSchema,
|
|
3866
|
+
ApplicationAuthorityCapabilitiesSchema2 as ApplicationAuthorityCapabilitiesSchema,
|
|
3867
|
+
ApplicationAuthorityOpenSchema2 as ApplicationAuthorityOpenSchema,
|
|
3868
|
+
ApplicationAuthoritySchema2 as ApplicationAuthoritySchema,
|
|
3869
|
+
ApplicationAuthoritySelectorSchema2 as ApplicationAuthoritySelectorSchema,
|
|
3870
|
+
ApplicationAuthorityUpdateSchema2 as ApplicationAuthorityUpdateSchema,
|
|
3871
|
+
ApplicationBindingSchema2 as ApplicationBindingSchema,
|
|
3872
|
+
ApplicationDelegationGrantSchema2 as ApplicationDelegationGrantSchema,
|
|
3873
|
+
ApplicationParentSchema2 as ApplicationParentSchema,
|
|
3874
|
+
ApplicationPolicyEvidenceSchema2 as ApplicationPolicyEvidenceSchema,
|
|
3875
|
+
ApplicationPolicyMetadataSchema2 as ApplicationPolicyMetadataSchema,
|
|
3876
|
+
ApplicationPolicyReferenceSchema2 as ApplicationPolicyReferenceSchema,
|
|
3877
|
+
AttachmentBeginSchema,
|
|
3878
|
+
AttachmentCancelReceiptSchema,
|
|
3879
|
+
AttachmentChunkSchema,
|
|
3880
|
+
AttachmentMediaTypeSchema,
|
|
3881
|
+
AttachmentReadReceiptSchema,
|
|
3882
|
+
AttachmentReadSchema,
|
|
3883
|
+
AttachmentReferenceSchema,
|
|
3884
|
+
AttachmentReferencesSchema,
|
|
3885
|
+
AttachmentUploadReceiptSchema,
|
|
3886
|
+
AttachmentUploadSelectorSchema,
|
|
3887
|
+
VERSION as CONTROL_CLIENT_VERSION,
|
|
3888
|
+
ChatLogReadSchema,
|
|
3889
|
+
ChatPrincipalSchema2 as ChatPrincipalSchema,
|
|
3890
|
+
ChatTargetSchema2 as ChatTargetSchema,
|
|
3891
|
+
CommunicationAuthorizationInputSchema,
|
|
3892
|
+
CommunicationAuthorizationSchema,
|
|
3893
|
+
CommunicationReceiptSchema,
|
|
3894
|
+
ContentCursorSchema,
|
|
3895
|
+
ContentReadSchema,
|
|
3896
|
+
ContentRecordSchema,
|
|
3897
|
+
ControlActionReceiptSchema,
|
|
3898
|
+
ControlArchiveReceiptSchema,
|
|
3899
|
+
ControlClientOptionsSchema,
|
|
3900
|
+
ControlCompactSchema,
|
|
3901
|
+
ControlContextOperationReadSchema,
|
|
3902
|
+
ControlContextOperationResultSchema,
|
|
3903
|
+
ControlCreateReceiptSchema,
|
|
3904
|
+
ControlCreateSchema,
|
|
3905
|
+
ControlDirectoryReadSchema,
|
|
3906
|
+
ControlDirectoryResultSchema,
|
|
3907
|
+
ControlHistoryReadSchema,
|
|
3908
|
+
ControlHistoryResultSchema,
|
|
3909
|
+
ControlInterruptSchema,
|
|
3910
|
+
ControlKeysSchema,
|
|
3911
|
+
ControlMessageReceiptSchema,
|
|
3912
|
+
ControlMessageSchema,
|
|
3913
|
+
ControlModelCatalogSchema,
|
|
3914
|
+
ControlModelSchema,
|
|
3915
|
+
ControlModelsReadSchema,
|
|
3916
|
+
ControlNativeCursorSchema,
|
|
3917
|
+
ControlNativeReadSchema,
|
|
3918
|
+
ControlNativeResponseReceiptSchema,
|
|
3919
|
+
ControlNativeResponseSchema,
|
|
3920
|
+
ControlNativeSnapshotSchema,
|
|
3921
|
+
ControlNativeStreamCursorSchema,
|
|
3922
|
+
ControlNativeStreamFrameSchema,
|
|
3923
|
+
ControlNativeStreamRequestSchema,
|
|
3924
|
+
ControlRowSchema,
|
|
3925
|
+
ControlSnapshotSchema,
|
|
3926
|
+
ControlStopReceiptSchema,
|
|
3927
|
+
ControlTargetSchema,
|
|
3928
|
+
ControlTransportCallerSchema,
|
|
3929
|
+
ControlWaitResultSchema,
|
|
3930
|
+
ConversationHitsSchema,
|
|
3931
|
+
ConversationRefSchema,
|
|
3932
|
+
CorpusMatchSchema,
|
|
3933
|
+
CorpusSearchJsonSchema,
|
|
3934
|
+
DEFAULT_MATCHES,
|
|
3935
|
+
DeclaredProjectSchema,
|
|
3936
|
+
DelegatedPolicySchema2 as DelegatedPolicySchema,
|
|
3937
|
+
DelegationEvidenceSchema2 as DelegationEvidenceSchema,
|
|
3938
|
+
DelegationRequestSchema2 as DelegationRequestSchema,
|
|
3939
|
+
DelegationSchema2 as DelegationSchema,
|
|
3940
|
+
DeliverySchema,
|
|
3941
|
+
EXACT_MESSAGE_LIMITS,
|
|
3942
|
+
EXTERNAL_CONTENT_LIMITS,
|
|
3943
|
+
ExactMessageOutcomeSchema,
|
|
3944
|
+
ExactMessageReadSchema,
|
|
3945
|
+
ExactMessageResultSchema,
|
|
3946
|
+
ExternalContentCapabilitiesSchema,
|
|
3947
|
+
ExternalContentReadSchema,
|
|
3948
|
+
ExternalContentResultSchema,
|
|
3949
|
+
ExternalContentSelectorSchema,
|
|
3950
|
+
ExternalContentTargetSchema,
|
|
3951
|
+
ExternalMessageAuthorshipSchema,
|
|
3952
|
+
ExternalMessageReadSchema,
|
|
3953
|
+
ExternalMessageResultSchema,
|
|
3954
|
+
ExternalMessageSchema,
|
|
3955
|
+
ExternalStatusFrameSchema,
|
|
3956
|
+
ExternalStatusRenewalSchema,
|
|
3957
|
+
ExternalStatusRowSchema,
|
|
3958
|
+
ExternalStatusSnapshotSchema,
|
|
3959
|
+
FleetAccountSchema,
|
|
3960
|
+
FleetAnswerSchema,
|
|
3961
|
+
FleetConversationHitsSchema,
|
|
3962
|
+
FleetDeliverySchema,
|
|
3963
|
+
FleetMachineSchema,
|
|
3964
|
+
FleetMatchSchema,
|
|
3965
|
+
FleetViewSchema,
|
|
3966
|
+
IdentityListReadSchema,
|
|
3967
|
+
IdentityWhoisReadSchema,
|
|
3968
|
+
IdleProofSchema,
|
|
3969
|
+
LaunchRecipeMetadataSchema2 as LaunchRecipeMetadataSchema,
|
|
3970
|
+
LaunchRecipeReferenceSchema2 as LaunchRecipeReferenceSchema,
|
|
3971
|
+
LogFrameSchema,
|
|
3972
|
+
LogMachineSchema,
|
|
3973
|
+
LogPayloadSchema,
|
|
3974
|
+
LogRowSchema,
|
|
3975
|
+
MESSAGE_OPERATION_LIMITS,
|
|
3976
|
+
MachineCoverageSchema,
|
|
3977
|
+
MachineUnavailableSchema,
|
|
3978
|
+
MessageAttributionSchema2 as MessageAttributionSchema,
|
|
3979
|
+
MessageOperationEvidenceSchema,
|
|
3980
|
+
MessageOperationReadSchema,
|
|
3981
|
+
MessageOperationResultSchema,
|
|
3982
|
+
MessageOperationStateSchema,
|
|
3983
|
+
MessageOriginSchema2 as MessageOriginSchema,
|
|
3984
|
+
MessageSenderSchema,
|
|
3985
|
+
ModelSelectionSchema2 as ModelSelectionSchema,
|
|
3986
|
+
NativeForkRequestSchema,
|
|
3987
|
+
NativeHistoryEntrySchema,
|
|
3988
|
+
NativeHistoryPageSchema,
|
|
3989
|
+
NativeHistoryQuerySchema,
|
|
3990
|
+
NativeSelectionEvidenceSchema2 as NativeSelectionEvidenceSchema,
|
|
3991
|
+
NativeTurnOptionsSchema2 as NativeTurnOptionsSchema,
|
|
3992
|
+
NotificationAudienceSchema2 as NotificationAudienceSchema,
|
|
3993
|
+
PermissionScopeSchema,
|
|
3994
|
+
PinReceiptSchema,
|
|
3995
|
+
PinRequestSchema,
|
|
3996
|
+
ProjectedPlanLimitsSchema,
|
|
3997
|
+
PublicContextOperationSchema,
|
|
3998
|
+
RECEIPT_MARKS_MAX,
|
|
3999
|
+
ReceiptsSchema,
|
|
4000
|
+
RemoteSessionSchema,
|
|
4001
|
+
RuntimeCapabilitiesSchema,
|
|
4002
|
+
RuntimeCatalogInputSchema,
|
|
4003
|
+
RuntimeCatalogSchema,
|
|
4004
|
+
SEARCH_FRAME_MAX_BYTES,
|
|
4005
|
+
SEARCH_LIMIT_MAX,
|
|
4006
|
+
SEARCH_PROVIDERS,
|
|
4007
|
+
STITCHMUX_NATIVE_STREAM_COMMAND,
|
|
4008
|
+
STITCHMUX_NATIVE_STREAM_HEARTBEAT_MS,
|
|
4009
|
+
STITCHMUX_NATIVE_STREAM_MAX_FRAME_BYTES,
|
|
4010
|
+
STITCHMUX_NATIVE_STREAM_MAX_INPUT_BYTES,
|
|
4011
|
+
STITCHMUX_NATIVE_STREAM_PROFILE,
|
|
4012
|
+
SearchFrameSchema,
|
|
4013
|
+
SearchRequestSchema,
|
|
4014
|
+
SearchStreamCutError,
|
|
4015
|
+
SelectionReadSchema,
|
|
4016
|
+
SelectionResultSchema,
|
|
4017
|
+
SelectionUpdateSchema,
|
|
4018
|
+
SendReceiptSchema,
|
|
4019
|
+
SentLetterSchema,
|
|
4020
|
+
SentLetterStateSchema,
|
|
4021
|
+
SentLettersReadSchema,
|
|
4022
|
+
SentListSchema,
|
|
4023
|
+
SessionIdentitySchema,
|
|
4024
|
+
SessionLifeSchema,
|
|
4025
|
+
SleepReceiptSchema,
|
|
4026
|
+
SleepRequestSchema,
|
|
4027
|
+
SleepTargetSchema,
|
|
4028
|
+
SteeringInputSchema,
|
|
4029
|
+
SteeringReadResultSchema,
|
|
4030
|
+
SteeringReceiptSchema,
|
|
4031
|
+
SteeringSelectorSchema,
|
|
4032
|
+
StitchmuxNativeStreamProfileSchema,
|
|
4033
|
+
StrayConversationSchema,
|
|
4034
|
+
TerminalMenuSchema,
|
|
4035
|
+
TerminalPromptReadSchema,
|
|
4036
|
+
TerminalPromptReceiptSchema,
|
|
4037
|
+
TerminalPromptRespondSchema,
|
|
4038
|
+
TerminalPromptResultSchema,
|
|
4039
|
+
ToolLifecycleSchema,
|
|
4040
|
+
ToolNameSchema,
|
|
4041
|
+
ToolObservationSchema,
|
|
4042
|
+
ToolOutcomeSchema,
|
|
4043
|
+
UsageListResultSchema,
|
|
4044
|
+
UsageListSchema,
|
|
4045
|
+
UsageQuerySchema,
|
|
4046
|
+
UsageReadSchema,
|
|
4047
|
+
UsageSummarySchema,
|
|
4048
|
+
WakeRequestSchema,
|
|
4049
|
+
WhoisAnswerSchema,
|
|
4050
|
+
WhoisBySchema,
|
|
4051
|
+
WhoisCandidateSchema,
|
|
4052
|
+
WhoisEventSchema,
|
|
4053
|
+
WhoisListSchema,
|
|
4054
|
+
WhoisMachineSchema,
|
|
4055
|
+
applyExternalStatusFrame,
|
|
4056
|
+
collectSearch,
|
|
4057
|
+
controlContract,
|
|
4058
|
+
controlEventsContract,
|
|
4059
|
+
controlNativeStreamFrame,
|
|
4060
|
+
createControlClient,
|
|
4061
|
+
createControlProxy,
|
|
4062
|
+
createExternalStatusEncoder,
|
|
4063
|
+
createInjectedControlClient,
|
|
4064
|
+
createStitchmuxNativeStreamProfile,
|
|
4065
|
+
currentControlSnapshot,
|
|
4066
|
+
currentExternalStatus,
|
|
4067
|
+
encodeControlNativeStreamCursor,
|
|
4068
|
+
readControlNativeStreamCursor,
|
|
4069
|
+
refusals
|
|
4070
|
+
};
|