@stitchmux/client 0.0.0-stage → 0.96.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +45 -2
  3. package/dist/chunk-wddwdvbj.js +714 -0
  4. package/dist/index.js +4070 -0
  5. package/dist/monitoring.js +279 -0
  6. package/native-stream.json +8 -0
  7. package/package.json +36 -4
  8. package/types/src/agent/claude/native/commandSchema.d.ts +14 -0
  9. package/types/src/agent/custom/config.d.ts +159 -0
  10. package/types/src/agent/custom/endpoint.d.ts +26 -0
  11. package/types/src/agent/transcript/messageSchema.d.ts +153 -0
  12. package/types/src/attachments/reference.d.ts +56 -0
  13. package/types/src/attachments/schema.d.ts +512 -0
  14. package/types/src/chat/communicationAuthorizationSchema.d.ts +77 -0
  15. package/types/src/chat/communicationReceiptSchema.d.ts +82 -0
  16. package/types/src/chat/feedSchema.d.ts +641 -0
  17. package/types/src/chat/holdKind.d.ts +26 -0
  18. package/types/src/chat/identity.d.ts +55 -0
  19. package/types/src/chat/identitySchema.d.ts +121 -0
  20. package/types/src/chat/letterRequestSchema.d.ts +35 -0
  21. package/types/src/chat/messageOperationSchema.d.ts +277 -0
  22. package/types/src/chat/messageSchema.d.ts +284 -0
  23. package/types/src/chat/originSchema.d.ts +67 -0
  24. package/types/src/chat/sentLetterSchema.d.ts +79 -0
  25. package/types/src/client.d.ts +16 -0
  26. package/types/src/config/claudeProfileSchema.d.ts +22 -0
  27. package/types/src/config/launchSchema.d.ts +136 -0
  28. package/types/src/config/location.d.ts +6 -0
  29. package/types/src/config/machineSchema.d.ts +320 -0
  30. package/types/src/config/modelSelectionFlags.d.ts +4 -0
  31. package/types/src/config/paths.d.ts +87 -0
  32. package/types/src/config/remoteTransport.d.ts +12 -0
  33. package/types/src/content/schema.d.ts +312 -0
  34. package/types/src/content/toolSchema.d.ts +36 -0
  35. package/types/src/context/corpusSearchSchema.d.ts +578 -0
  36. package/types/src/context/exactMessageSchema.d.ts +54 -0
  37. package/types/src/context/messageSenderSchema.d.ts +14 -0
  38. package/types/src/context/schema.d.ts +176 -0
  39. package/types/src/context/searchFrames.d.ts +225 -0
  40. package/types/src/context/searchRequestSchema.d.ts +47 -0
  41. package/types/src/context/transcriptJsonSchema.d.ts +210 -0
  42. package/types/src/control/schema/context.d.ts +188 -0
  43. package/types/src/control/schema/contract.d.ts +7142 -0
  44. package/types/src/control/schema/core.d.ts +722 -0
  45. package/types/src/control/schema/directory.d.ts +34 -0
  46. package/types/src/control/schema/eventsContract.d.ts +1423 -0
  47. package/types/src/control/schema/externalList.d.ts +96 -0
  48. package/types/src/control/schema/message.d.ts +280 -0
  49. package/types/src/control/schema/model.d.ts +128 -0
  50. package/types/src/control/schema/native.d.ts +664 -0
  51. package/types/src/control/schema/nativeStreamContract.d.ts +155 -0
  52. package/types/src/control/schema/performance.d.ts +85 -0
  53. package/types/src/control/schema/public.d.ts +48 -0
  54. package/types/src/control/schema/reading.d.ts +24 -0
  55. package/types/src/control/schema/refusals.d.ts +433 -0
  56. package/types/src/control/schema/runtimeOps.d.ts +724 -0
  57. package/types/src/control/schema/searchContract.d.ts +258 -0
  58. package/types/src/control/schema/selection.d.ts +124 -0
  59. package/types/src/control/schema/session.d.ts +272 -0
  60. package/types/src/control/schema/terminalPrompt.d.ts +102 -0
  61. package/types/src/control/transport/boundary.d.ts +7137 -0
  62. package/types/src/control/transport/client.d.ts +10838 -0
  63. package/types/src/control/transport/connection.d.ts +13 -0
  64. package/types/src/control/transport/socketPath.d.ts +3 -0
  65. package/types/src/control-client.d.ts +9 -0
  66. package/types/src/delegation/applicationSchema.d.ts +132 -0
  67. package/types/src/delegation/schema.d.ts +267 -0
  68. package/types/src/events/schema.d.ts +155 -0
  69. package/types/src/external/contentSchema.d.ts +145 -0
  70. package/types/src/external/messageSchema.d.ts +131 -0
  71. package/types/src/external/residentFrames.d.ts +130 -0
  72. package/types/src/external/residentSchema.d.ts +144 -0
  73. package/types/src/external/sessionSchema.d.ts +427 -0
  74. package/types/src/external/turnSchema.d.ts +55 -0
  75. package/types/src/fleet/fleetSchema.d.ts +937 -0
  76. package/types/src/inventory/listSchema.d.ts +442 -0
  77. package/types/src/monitoring/nativeFile.d.ts +7 -0
  78. package/types/src/monitoring/nativeRead.d.ts +14 -0
  79. package/types/src/monitoring/performanceSchema.d.ts +28 -0
  80. package/types/src/monitoring/schema.d.ts +410 -0
  81. package/types/src/monitoring/validate.d.ts +5 -0
  82. package/types/src/monitoring-reader.d.ts +4 -0
  83. package/types/src/policy/reference.d.ts +93 -0
  84. package/types/src/policy/runtimeProfile.d.ts +24 -0
  85. package/types/src/policy/schema.d.ts +177 -0
  86. package/types/src/runtime/capabilities.d.ts +124 -0
  87. package/types/src/runtime/modes.d.ts +47 -0
  88. package/types/src/runtime/permissionScope.d.ts +22 -0
  89. package/types/src/runtime/planLimitsSchema.d.ts +55 -0
  90. package/types/src/runtime/projectionSchema.d.ts +539 -0
  91. package/types/src/runtime/rewindSchema.d.ts +16 -0
  92. package/types/src/runtime/selectionSchema.d.ts +158 -0
  93. package/types/src/runtime/workloadContract.d.ts +55 -0
  94. package/types/src/session/boundary.d.ts +43 -0
  95. package/types/src/session/identitySchema.d.ts +353 -0
  96. package/types/src/session/schema.d.ts +341 -0
  97. package/types/src/session/sleep/schema.d.ts +283 -0
  98. package/types/src/steering/schema.d.ts +197 -0
  99. package/types/src/types.d.ts +48 -0
  100. package/types/src/usage/schema.d.ts +978 -0
  101. package/types/src/util/home.d.ts +9 -0
  102. package/types/src/util/preview.d.ts +13 -0
  103. package/types/src/util/version.d.ts +3 -0
@@ -0,0 +1,714 @@
1
+ // @bun
2
+ // src/chat/identitySchema.ts
3
+ import { z } from "zod";
4
+ var SESSION_NAME_RE = /^[^|\s#:]+$/;
5
+ var RC_PREFIX_RE = /^[a-z][a-z0-9-]*$/;
6
+ var AgentKindSchema = z.enum(["claude", "codex", "opencode", "custom", "antigravity"]);
7
+ var ManagedPeerSchema = z.object({
8
+ kind: z.literal("managed"),
9
+ source: z.literal("stitchmux"),
10
+ machine: z.string().regex(RC_PREFIX_RE),
11
+ agent: AgentKindSchema,
12
+ session: z.string().min(1).regex(SESSION_NAME_RE),
13
+ threadId: z.uuid()
14
+ }).strict();
15
+ var CliPrincipalSchema = z.object({
16
+ kind: z.literal("cli"),
17
+ source: z.literal("stitchmux"),
18
+ machine: z.string().regex(RC_PREFIX_RE)
19
+ }).strict();
20
+ var ServicePrincipalSchema = z.object({
21
+ kind: z.literal("service"),
22
+ source: z.literal("stitchmux"),
23
+ machine: z.string().regex(RC_PREFIX_RE),
24
+ transport: z.enum(["local", "declared-service"])
25
+ }).strict();
26
+ var CodexAppPeerSchema = z.object({
27
+ kind: z.literal("codex-app"),
28
+ source: z.literal("codex-app"),
29
+ machine: z.string().regex(RC_PREFIX_RE),
30
+ agent: z.literal("codex"),
31
+ threadId: z.uuid(),
32
+ name: z.string().min(1).max(240).nullable()
33
+ }).strict();
34
+ var ChatPrincipalSchema2 = z.union([
35
+ ManagedPeerSchema,
36
+ CodexAppPeerSchema,
37
+ CliPrincipalSchema,
38
+ ServicePrincipalSchema
39
+ ]);
40
+ var OwnerTargetSchema = z.object({ kind: z.literal("owner") }).strict();
41
+ var ExternalTargetSchema = z.object({
42
+ kind: z.literal("external"),
43
+ source: z.literal("stitchmux"),
44
+ name: z.string().min(1).regex(SESSION_NAME_RE)
45
+ }).strict();
46
+ var ChatTargetSchema2 = z.union([
47
+ ManagedPeerSchema,
48
+ CodexAppPeerSchema,
49
+ OwnerTargetSchema,
50
+ ExternalTargetSchema
51
+ ]);
52
+
53
+ // src/config/launchSchema.ts
54
+ import { z as z6 } from "zod";
55
+
56
+ // src/agent/custom/config.ts
57
+ import { z as z5 } from "zod";
58
+
59
+ // src/policy/schema.ts
60
+ import { z as z3 } from "zod";
61
+
62
+ // src/policy/reference.ts
63
+ import { z as z2 } from "zod";
64
+ var PolicyIdSchema = z2.string().min(1).max(128).regex(/^[a-zA-Z0-9][a-zA-Z0-9._-]*$/);
65
+ var PolicyDigestSchema = z2.string().regex(/^[a-f0-9]{64}$/);
66
+ var ApplicationPolicyReferenceSchema2 = z2.object({ id: PolicyIdSchema, revision: PolicyIdSchema }).strict();
67
+ var PolicyCapabilitySchema = z2.enum([
68
+ "developer-instructions",
69
+ "native-skills",
70
+ "native-agent",
71
+ "tool-denials"
72
+ ]);
73
+ var ApplicationPolicyMetadataSchema2 = ApplicationPolicyReferenceSchema2.extend({
74
+ digest: PolicyDigestSchema,
75
+ runtime: z2.enum(["codex", "opencode"]),
76
+ sources: z2.array(z2.object({
77
+ id: PolicyIdSchema,
78
+ digest: PolicyDigestSchema,
79
+ kind: z2.enum(["instructions", "skill", "agent"])
80
+ }).strict()).min(1).max(32),
81
+ capabilities: z2.array(PolicyCapabilitySchema).min(1).max(4)
82
+ }).strict();
83
+ var PolicyUnavailableReasonSchema = z2.string().regex(/^[a-z][a-z0-9-]{0,63}$/);
84
+ var ApplicationPolicyEvidenceSchema2 = z2.object({
85
+ policy: ApplicationPolicyMetadataSchema2,
86
+ state: z2.enum(["desired", "applied", "unavailable"]),
87
+ reason: PolicyUnavailableReasonSchema.optional()
88
+ }).strict().refine((value) => value.reason === undefined || value.state === "unavailable", "Only an unavailable policy has a reason");
89
+
90
+ // src/policy/schema.ts
91
+ var PathSchema = z3.string().min(1).max(4096).refine((value) => value.startsWith("/") && !value.includes("\x00") && (value === "/" || value.slice(1).split("/").every((part) => part !== "" && part !== "." && part !== "..")), "canonical absolute path required");
92
+ var PolicySourceSchema = z3.object({ id: PolicyIdSchema, path: PathSchema, sha256: PolicyDigestSchema }).strict();
93
+ var NativeSkillSchema = PolicySourceSchema.extend({ name: PolicyIdSchema }).strict();
94
+ var hostFields = { revision: PolicyIdSchema, trustedRoots: z3.array(PathSchema).min(1).max(16) };
95
+ var CodexAgentPolicySchema = z3.object({
96
+ ...hostFields,
97
+ runtime: z3.literal("codex"),
98
+ instructionSources: z3.array(PolicySourceSchema).max(16).default([]),
99
+ skills: z3.array(NativeSkillSchema).max(16).default([])
100
+ }).strict().refine((value) => value.instructionSources.length + value.skills.length > 0, "policy requires a canonical source");
101
+ var OpenCodeAgentPolicySchema = z3.object({
102
+ ...hostFields,
103
+ runtime: z3.literal("opencode"),
104
+ agent: z3.object({ name: PolicyIdSchema, source: PolicySourceSchema }).strict(),
105
+ denyTools: z3.array(PolicyIdSchema).max(64).default([])
106
+ }).strict();
107
+ var HostAgentPolicySchema = z3.discriminatedUnion("runtime", [
108
+ CodexAgentPolicySchema,
109
+ OpenCodeAgentPolicySchema
110
+ ]);
111
+ var AgentPoliciesSchema = z3.record(PolicyIdSchema, HostAgentPolicySchema).default({});
112
+ var PrivateSourceSchema = PolicySourceSchema.extend({ body: z3.string() }).strict();
113
+ var MaterializedPolicySchema = z3.discriminatedUnion("runtime", [
114
+ z3.object({
115
+ runtime: z3.literal("codex"),
116
+ metadata: ApplicationPolicyMetadataSchema2,
117
+ instructionSources: z3.array(PrivateSourceSchema),
118
+ skills: z3.array(PrivateSourceSchema.extend({ name: PolicyIdSchema }).strict())
119
+ }).strict(),
120
+ z3.object({
121
+ runtime: z3.literal("opencode"),
122
+ metadata: ApplicationPolicyMetadataSchema2,
123
+ agent: z3.object({ name: PolicyIdSchema, source: PrivateSourceSchema, prompt: z3.string() }).strict(),
124
+ denyTools: z3.array(PolicyIdSchema)
125
+ }).strict()
126
+ ]);
127
+
128
+ // src/runtime/selectionSchema.ts
129
+ import { z as z4 } from "zod";
130
+ var printableKey = (value) => {
131
+ for (const character of value) {
132
+ const code = character.codePointAt(0) ?? 0;
133
+ if (code <= 32 || code >= 127 && code <= 159)
134
+ return false;
135
+ }
136
+ return true;
137
+ };
138
+ var NativeModelSelectionSchema = z4.object({
139
+ provider: z4.string().min(1).max(128).regex(/^[A-Za-z0-9][A-Za-z0-9._-]*$/),
140
+ model: z4.string().min(1).max(256).refine(printableKey, "Model key must not contain whitespace or control characters")
141
+ }).strict();
142
+ var NativeTurnOptionsSchema2 = z4.discriminatedUnion("runtime", [
143
+ z4.object({ runtime: z4.literal("custom"), model: NativeModelSelectionSchema }).strict(),
144
+ z4.object({
145
+ runtime: z4.literal("claude"),
146
+ model: NativeModelSelectionSchema,
147
+ effort: z4.string().min(1).max(64).optional()
148
+ }).strict(),
149
+ z4.object({
150
+ runtime: z4.literal("codex"),
151
+ model: NativeModelSelectionSchema,
152
+ mode: z4.enum(["default", "plan"]),
153
+ effort: z4.string().min(1).max(64).optional()
154
+ }).strict(),
155
+ z4.object({
156
+ runtime: z4.literal("opencode"),
157
+ model: NativeModelSelectionSchema,
158
+ agent: z4.string().min(1).max(128).optional(),
159
+ variant: z4.string().min(1).max(128).optional()
160
+ }).strict(),
161
+ z4.object({
162
+ runtime: z4.literal("antigravity"),
163
+ model: NativeModelSelectionSchema,
164
+ effort: z4.string().min(1).max(64).optional()
165
+ }).strict()
166
+ ]);
167
+ var AcceptedTurnOptionsSchema2 = z4.object({
168
+ revision: z4.number().int().nonnegative(),
169
+ options: NativeTurnOptionsSchema2
170
+ }).strict();
171
+ var NativeSelectionEvidenceSchema2 = z4.object({
172
+ model: NativeModelSelectionSchema,
173
+ options: NativeTurnOptionsSchema2.nullable(),
174
+ source: z4.enum(["admission", "settings", "assistant", "reroute"]),
175
+ turnId: z4.string().min(1).max(256).nullable()
176
+ }).strict();
177
+
178
+ // src/agent/custom/endpoint.ts
179
+ var V4_LOCAL = [
180
+ { octets: [127], bits: 8 },
181
+ { octets: [10], bits: 8 },
182
+ { octets: [172, 16], bits: 12 },
183
+ { octets: [192, 168], bits: 16 },
184
+ { octets: [169, 254], bits: 16 }
185
+ ];
186
+ function v4Octets(hostname) {
187
+ const parts = hostname.split(".");
188
+ if (parts.length !== 4)
189
+ return null;
190
+ const octets = parts.map((part) => /^\d{1,3}$/.test(part) ? Number(part) : Number.NaN);
191
+ return octets.every((octet) => Number.isInteger(octet) && octet >= 0 && octet <= 255) ? octets : null;
192
+ }
193
+ function isLocalAddress(hostname) {
194
+ const host = hostname.toLowerCase();
195
+ if (host === "localhost")
196
+ return true;
197
+ const v4 = v4Octets(host);
198
+ if (v4) {
199
+ return V4_LOCAL.some(({ octets, bits }) => {
200
+ const mask = ~((1 << 32 - bits) - 1);
201
+ const value = (a) => (a[0] ?? 0) << 24 | (a[1] ?? 0) << 16 | (a[2] ?? 0) << 8 | (a[3] ?? 0);
202
+ const prefix = value([...octets, 0, 0, 0].slice(0, 4));
203
+ return (value(v4) & mask) === (prefix & mask);
204
+ });
205
+ }
206
+ if (host.startsWith("[") && host.endsWith("]")) {
207
+ const v6 = host.slice(1, -1);
208
+ if (v6 === "::1")
209
+ return true;
210
+ const head = v6.split(":")[0] ?? "";
211
+ if (/^f[cd][0-9a-f]{2}$/.test(head))
212
+ return true;
213
+ if (/^fe[89ab][0-9a-f]$/.test(head))
214
+ return true;
215
+ }
216
+ return false;
217
+ }
218
+ function parseLocalEndpoint(raw) {
219
+ let url;
220
+ try {
221
+ url = new URL(raw);
222
+ } catch {
223
+ return { refused: "not-a-url" };
224
+ }
225
+ if (url.protocol !== "http:" && url.protocol !== "https:")
226
+ return { refused: "protocol" };
227
+ if (url.username !== "" || url.password !== "")
228
+ return { refused: "embedded-credentials" };
229
+ if (url.search !== "" || url.hash !== "")
230
+ return { refused: "query-or-fragment" };
231
+ if (!isLocalAddress(url.hostname))
232
+ return { refused: "not-local" };
233
+ return { url };
234
+ }
235
+ var ENDPOINT_REFUSAL_TEXT = {
236
+ "not-a-url": "Local provider endpoint must be an absolute URL",
237
+ protocol: "Local provider endpoint must use http or https",
238
+ "embedded-credentials": "Local provider endpoint must not embed credentials",
239
+ "query-or-fragment": "Local provider endpoint must not carry a query or fragment",
240
+ "not-local": "Local provider endpoint must be a loopback or private address literal"
241
+ };
242
+
243
+ // src/agent/custom/config.ts
244
+ var EnvironmentNameSchema = z5.string().regex(/^[A-Za-z_][A-Za-z0-9_]*$/);
245
+ var CustomToolNameSchema = z5.enum([
246
+ "read_file",
247
+ "write_file",
248
+ "edit_file",
249
+ "search_files",
250
+ "glob",
251
+ "list_directory",
252
+ "run_command",
253
+ "read_output",
254
+ "read_resource"
255
+ ]);
256
+ var CustomProviderSchema = z5.discriminatedUnion("kind", [
257
+ z5.object({ kind: z5.literal("openrouter"), credentialEnv: EnvironmentNameSchema }).strict(),
258
+ z5.object({
259
+ kind: z5.literal("local"),
260
+ endpoint: z5.string().min(1).max(2048),
261
+ credentialEnv: EnvironmentNameSchema.optional(),
262
+ label: z5.string().regex(/^[a-z0-9][a-z0-9._-]{0,63}$/).optional()
263
+ }).strict()
264
+ ]);
265
+ var MAX_SERVICES = 8;
266
+ var MAX_SERVICE_TOOLS = 32;
267
+ var MAX_DECLARED_CUSTOM_TOOLS = CustomToolNameSchema.options.length + MAX_SERVICES * MAX_SERVICE_TOOLS;
268
+ var CustomServiceSchema = z5.object({
269
+ id: z5.string().regex(/^[a-z0-9][a-z0-9._-]{0,63}$/),
270
+ command: z5.string().startsWith("/").max(4096),
271
+ args: z5.array(z5.string().max(4096)).max(16).default([]),
272
+ credentialEnv: EnvironmentNameSchema.optional(),
273
+ tools: z5.array(z5.string().regex(/^[a-z0-9][a-z0-9._-]{0,127}$/)).min(1).max(MAX_SERVICE_TOOLS)
274
+ }).strict();
275
+ var CustomLaunchConfigSchema = z5.object({
276
+ provider: CustomProviderSchema,
277
+ models: z5.array(z5.object({
278
+ selection: NativeModelSelectionSchema,
279
+ contextWindow: z5.number().int().min(4096).max(4194304),
280
+ capabilities: z5.array(z5.enum(["tools", "vision", "reasoning", "files"])).max(4)
281
+ }).strict()).min(1).max(128),
282
+ defaultModel: NativeModelSelectionSchema,
283
+ trustedRoots: z5.array(z5.string().startsWith("/").max(4096)).max(16),
284
+ resources: z5.array(PolicySourceSchema.extend({
285
+ kind: z5.enum(["instruction", "skill", "resource"])
286
+ }).strict()).max(32),
287
+ tools: z5.array(CustomToolNameSchema).max(CustomToolNameSchema.options.length),
288
+ approvalTools: z5.array(CustomToolNameSchema).max(CustomToolNameSchema.options.length),
289
+ services: z5.array(CustomServiceSchema).max(MAX_SERVICES).default([]),
290
+ approvalSecretEnv: EnvironmentNameSchema,
291
+ executables: z5.record(z5.string().regex(/^[A-Za-z][A-Za-z0-9_-]{0,63}$/), z5.string().startsWith("/").max(4096)),
292
+ commandEnvironment: z5.array(EnvironmentNameSchema).max(32)
293
+ }).strict().superRefine((value, ctx) => {
294
+ for (const values of [value.tools, value.approvalTools, value.commandEnvironment])
295
+ if (new Set(values).size !== values.length)
296
+ ctx.addIssue({ code: "custom", message: "Host capability lists must be unique" });
297
+ for (const [name, missing, needs] of [
298
+ ["run_command", Object.keys(value.executables).length === 0, "a declared executable"],
299
+ ["read_resource", value.resources.length === 0, "a declared resource"]
300
+ ])
301
+ if (value.tools.includes(name) && missing)
302
+ ctx.addIssue({
303
+ code: "custom",
304
+ message: `Tool ${name} needs ${needs} in this recipe`,
305
+ path: ["tools"]
306
+ });
307
+ if (value.commandEnvironment.some((name) => name === value.provider.credentialEnv || name === value.approvalSecretEnv))
308
+ ctx.addIssue({
309
+ code: "custom",
310
+ message: "Execution credentials are not command capabilities"
311
+ });
312
+ if (value.provider.kind === "local") {
313
+ const endpoint = parseLocalEndpoint(value.provider.endpoint);
314
+ if ("refused" in endpoint)
315
+ ctx.addIssue({
316
+ code: "custom",
317
+ message: ENDPOINT_REFUSAL_TEXT[endpoint.refused],
318
+ path: ["provider", "endpoint"]
319
+ });
320
+ }
321
+ if (new Set(value.resources.map(({ id }) => id)).size !== value.resources.length)
322
+ ctx.addIssue({ code: "custom", message: "Resource identities must be unique" });
323
+ const key = (model) => JSON.stringify(model);
324
+ if (new Set(value.models.map(({ selection }) => key(selection))).size !== value.models.length)
325
+ ctx.addIssue({ code: "custom", message: "Model identities must be unique" });
326
+ if (!value.models.some(({ selection }) => key(selection) === key(value.defaultModel)))
327
+ ctx.addIssue({ code: "custom", message: "Default model must be in the host registry" });
328
+ if (value.models.some(({ selection }) => selection.provider !== value.provider.kind))
329
+ ctx.addIssue({ code: "custom", message: "Model provider must match the host adapter" });
330
+ if (value.approvalTools.some((name) => !value.tools.includes(name)))
331
+ ctx.addIssue({ code: "custom", message: "Approval tool must be enabled" });
332
+ if (Object.keys(value.executables).length > 32)
333
+ ctx.addIssue({ code: "custom", message: "Executable catalog exceeds its bound" });
334
+ if (value.resources.length > 0 && value.trustedRoots.length === 0)
335
+ ctx.addIssue({ code: "custom", message: "Resources require trusted roots" });
336
+ });
337
+
338
+ // src/config/launchSchema.ts
339
+ var PermissionModeSchema = z6.enum([
340
+ "auto",
341
+ "manual",
342
+ "plan",
343
+ "acceptEdits",
344
+ "dontAsk",
345
+ "bypassPermissions"
346
+ ]);
347
+ var NativeSessionSchema = z6.object({
348
+ runtime: z6.enum(["opencode", "custom", "claude", "antigravity"]),
349
+ id: z6.string().min(1).max(256),
350
+ version: z6.string().min(1).max(64)
351
+ }).strict();
352
+ var LaunchRecipeIdSchema = z6.string().min(1).max(128).regex(/^[a-z][a-z0-9._-]*$/);
353
+ var LaunchRecipeRevisionSchema = z6.string().min(1).max(128).regex(/^[A-Za-z0-9][A-Za-z0-9._-]*$/);
354
+ var LaunchRecipeCapabilitySchema = z6.string().min(1).max(128).regex(/^[a-z][a-z0-9._-]*$/);
355
+ var CodexCollaborationModeSchema = z6.enum(["default", "plan"]);
356
+ var LaunchRecipeReferenceSchema2 = z6.object({
357
+ id: LaunchRecipeIdSchema,
358
+ revision: LaunchRecipeRevisionSchema
359
+ }).strict();
360
+ var ModelSelectionSchema2 = NativeModelSelectionSchema;
361
+ var LaunchRecipeMetadataSchema2 = LaunchRecipeReferenceSchema2.extend({
362
+ digest: z6.string().regex(/^[0-9a-f]{64}$/),
363
+ capabilities: z6.array(LaunchRecipeCapabilitySchema).max(32),
364
+ collaborationMode: CodexCollaborationModeSchema.optional()
365
+ }).strict();
366
+ var MachineLaunchRecipeSchema = z6.object({
367
+ revision: LaunchRecipeRevisionSchema,
368
+ envFile: z6.string().min(1).optional(),
369
+ flags: z6.array(z6.string().min(1).max(4096)).max(32).default([]),
370
+ environment: z6.array(z6.string().regex(/^[A-Za-z_][A-Za-z0-9_]*$/)).max(32).default([]),
371
+ capabilities: z6.array(LaunchRecipeCapabilitySchema).max(32).default([]),
372
+ collaborationMode: CodexCollaborationModeSchema.optional(),
373
+ custom: CustomLaunchConfigSchema.optional()
374
+ }).strict();
375
+
376
+ // src/delegation/schema.ts
377
+ import { z as z9 } from "zod";
378
+
379
+ // src/delegation/applicationSchema.ts
380
+ import { z as z8 } from "zod";
381
+
382
+ // src/chat/originSchema.ts
383
+ import { z as z7 } from "zod";
384
+ var TokenSchema = z7.string().min(1).max(128).regex(/^[a-zA-Z0-9][a-zA-Z0-9._-]*$/);
385
+ var AttributedActorSchema = z7.enum(["human", "agent", "application"]);
386
+ var MessageAttributionSchema2 = z7.object({
387
+ applicationId: TokenSchema,
388
+ channelId: TokenSchema,
389
+ actor: AttributedActorSchema
390
+ }).strict();
391
+ var MessageApplicationsSchema = z7.record(TokenSchema, z7.object({
392
+ revision: TokenSchema,
393
+ callers: z7.array(TokenSchema).min(1).max(64),
394
+ channels: z7.array(TokenSchema).min(1).max(64),
395
+ actors: z7.array(AttributedActorSchema).min(1).max(3),
396
+ ownerNotifications: z7.boolean().default(false)
397
+ }).strict()).default({});
398
+ var MessageOriginSchema2 = z7.object({
399
+ ingress: z7.enum(["cli", "local-control", "service", "managed", "codex-app", "unknown"]),
400
+ actor: z7.enum(["human", "agent", "application", "unknown"]),
401
+ assurance: z7.enum(["runtime-identity", "application-attested", "unknown"]),
402
+ application: MessageAttributionSchema2.extend({
403
+ revision: TokenSchema,
404
+ digest: z7.string().regex(/^[a-f0-9]{64}$/)
405
+ }).strict().nullable()
406
+ }).strict();
407
+ var NotificationAudienceSchema2 = z7.enum(["conversation", "owner"]);
408
+
409
+ // src/delegation/applicationSchema.ts
410
+ var ApplicationParentSchema2 = z8.object({
411
+ kind: z8.literal("application"),
412
+ machine: z8.string().regex(RC_PREFIX_RE),
413
+ applicationId: MessageAttributionSchema2.shape.applicationId,
414
+ authorityId: z8.uuid()
415
+ }).strict();
416
+ var ApplicationBindingSchema2 = MessageAttributionSchema2.extend({
417
+ actor: z8.literal("agent"),
418
+ revision: z8.string().min(1).max(128)
419
+ }).strict();
420
+ var PolicySchema = z8.object({
421
+ access: z8.enum(["read-only", "workspace-write"]),
422
+ readScope: z8.literal("host"),
423
+ workspace: z8.string().startsWith("/").max(4096),
424
+ network: z8.literal(false)
425
+ }).strict();
426
+ var ApplicationDelegationGrantSchema2 = z8.object({
427
+ binding: ApplicationBindingSchema2,
428
+ policy: PolicySchema,
429
+ leaseMs: z8.number().int().min(1000).max(60000),
430
+ lifetimeMs: z8.number().int().min(1000).max(86400000)
431
+ }).strict();
432
+ var ApplicationAuthorityOpenSchema2 = z8.object({
433
+ operationId: z8.uuid(),
434
+ binding: ApplicationBindingSchema2,
435
+ conversationId: z8.string().min(1).max(256),
436
+ runId: z8.string().min(1).max(256),
437
+ sourceMessageRef: z8.string().min(1).max(256),
438
+ authorizationQuote: z8.string().min(1).max(4000).refine((value) => value.trim().length > 0)
439
+ }).strict();
440
+ var ApplicationAuthoritySelectorSchema2 = z8.object({
441
+ parent: z8.object({
442
+ target: ApplicationParentSchema2,
443
+ registrationGeneration: z8.uuid()
444
+ }).strict()
445
+ }).strict();
446
+ var ApplicationAuthorityUpdateSchema2 = ApplicationAuthoritySelectorSchema2.extend({
447
+ operationId: z8.uuid(),
448
+ expectedExpiresAt: z8.iso.datetime().optional()
449
+ }).strict();
450
+ var ApplicationAuthoritySchema2 = ApplicationAuthorityOpenSchema2.extend({
451
+ parent: ApplicationAuthoritySelectorSchema2.shape.parent,
452
+ caller: z8.string().regex(RC_PREFIX_RE),
453
+ assurance: z8.literal("application-attested"),
454
+ bindingDigest: z8.string().regex(/^[a-f0-9]{64}$/),
455
+ policy: PolicySchema,
456
+ issuedAt: z8.iso.datetime(),
457
+ expiresAt: z8.iso.datetime(),
458
+ deadlineAt: z8.iso.datetime(),
459
+ closedAt: z8.iso.datetime().nullable(),
460
+ lastOperationId: z8.uuid()
461
+ }).strict();
462
+ var ApplicationAuthorityCapabilitiesSchema2 = z8.object({
463
+ bindings: z8.array(ApplicationDelegationGrantSchema2).max(64),
464
+ assurance: z8.literal("application-attested"),
465
+ requiresTrustedRunAttestation: z8.literal(true)
466
+ }).strict();
467
+
468
+ // src/delegation/schema.ts
469
+ var DelegatedPolicySchema2 = z9.object({
470
+ access: z9.enum(["read-only", "workspace-write", "full-access"]),
471
+ readScope: z9.literal("host"),
472
+ workspace: z9.string().startsWith("/").max(4096),
473
+ network: z9.literal(false)
474
+ }).strict();
475
+ var DelegationParentSchema = z9.object({
476
+ target: z9.union([ManagedPeerSchema, ApplicationParentSchema2]),
477
+ registrationGeneration: z9.uuid()
478
+ }).strict();
479
+ var DelegationRequestSchema2 = z9.object({
480
+ parent: DelegationParentSchema,
481
+ policy: DelegatedPolicySchema2,
482
+ deadlineAt: z9.iso.datetime().optional()
483
+ }).strict();
484
+ var DelegationAuthoritySchema = DelegationRequestSchema2;
485
+ var DelegationSchema2 = DelegationRequestSchema2.extend({
486
+ requestId: z9.uuid(),
487
+ applicationAuthority: ApplicationAuthoritySelectorSchema2.shape.parent.optional(),
488
+ policyDigest: z9.string().regex(/^[a-f0-9]{64}$/)
489
+ }).strict();
490
+ var DelegationEvidenceSchema2 = z9.object({
491
+ delegation: DelegationSchema2,
492
+ state: z9.enum(["applied", "unavailable"]),
493
+ generation: z9.uuid().nullable(),
494
+ observedAt: z9.iso.datetime()
495
+ }).strict();
496
+ var DelegationCancelSchema = z9.object({
497
+ parent: DelegationParentSchema,
498
+ target: ManagedPeerSchema,
499
+ registrationGeneration: z9.uuid(),
500
+ operationId: z9.uuid()
501
+ }).strict();
502
+ var DelegationCancelReceiptSchema = z9.object({
503
+ target: ManagedPeerSchema,
504
+ registrationGeneration: z9.uuid(),
505
+ operationId: z9.uuid(),
506
+ stopped: z9.literal(true)
507
+ }).strict();
508
+
509
+ // src/config/claudeProfileSchema.ts
510
+ import { z as z10 } from "zod";
511
+ var ProfileNameSchema = z10.string().min(1).max(128).regex(/^[a-zA-Z0-9][a-zA-Z0-9._-]*$/);
512
+ var ProfileDirectorySchema = z10.string().startsWith("/").max(4096);
513
+ var accountDigest = z10.string().regex(/^[a-f0-9]{64}$/).optional();
514
+ var named = { name: ProfileNameSchema, configDir: ProfileDirectorySchema, accountDigest };
515
+ var ClaudeProfileBindingSchema = z10.discriminatedUnion("source", [
516
+ z10.strictObject({
517
+ source: z10.literal("default"),
518
+ name: z10.literal("default"),
519
+ configDir: z10.null(),
520
+ accountDigest
521
+ }),
522
+ z10.strictObject({ ...named, source: z10.literal("machine") }),
523
+ z10.strictObject({
524
+ ...named,
525
+ source: z10.literal("claude-multiprofile"),
526
+ registryPath: ProfileDirectorySchema
527
+ })
528
+ ]);
529
+
530
+ // src/util/home.ts
531
+ import { homedir } from "os";
532
+ var PLATFORM = process.platform;
533
+ var UID = process.getuid?.() ?? 0;
534
+ var HOME = homedir();
535
+
536
+ // src/config/machineSchema.ts
537
+ import { AcpMcpServerSchema } from "stitchkit/agent-executor/acp";
538
+ import { z as z13 } from "zod";
539
+
540
+ // src/runtime/workloadContract.ts
541
+ import { z as z11 } from "zod";
542
+ var FiniteWorkloadsSchema = z11.strictObject({
543
+ launcherBin: z11.string().startsWith("/"),
544
+ profileFile: z11.string().startsWith("/")
545
+ });
546
+ var WorkloadOutcomeSchema = z11.discriminatedUnion("status", [
547
+ z11.strictObject({
548
+ schema: z11.literal("node-workload-result/v1"),
549
+ status: z11.literal("completed"),
550
+ admissionId: z11.uuid(),
551
+ exitCode: z11.int().min(0).max(255).nullable(),
552
+ signal: z11.string().nullable(),
553
+ reason: z11.string().nullable(),
554
+ failures: z11.array(z11.strictObject({
555
+ source: z11.enum(["payload", "monitor"]),
556
+ message: z11.string(),
557
+ detail: z11.string()
558
+ })).optional()
559
+ }),
560
+ z11.strictObject({
561
+ schema: z11.literal("node-workload-result/v1"),
562
+ status: z11.literal("refused"),
563
+ reason: z11.string().min(1),
564
+ detail: z11.string()
565
+ }),
566
+ z11.strictObject({
567
+ schema: z11.literal("node-workload-result/v1"),
568
+ status: z11.literal("failed"),
569
+ reason: z11.string().min(1),
570
+ detail: z11.string()
571
+ })
572
+ ]);
573
+ var WorkloadProtocolSchema = z11.looseObject({
574
+ schema: z11.literal("node-workload-protocol/v1"),
575
+ command: z11.literal("node-workload-run"),
576
+ platform: z11.literal("linux"),
577
+ mode: z11.literal("disposable"),
578
+ supervisor: z11.literal("direct-parent-process-instance")
579
+ });
580
+
581
+ // src/config/remoteTransport.ts
582
+ import { z as z12 } from "zod";
583
+ var path = z12.string().startsWith("/");
584
+ var RemoteTransportSchema = z12.strictObject({
585
+ kind: z12.literal("stitchwire"),
586
+ peers: z12.array(z12.string().regex(RC_PREFIX_RE)).default([]),
587
+ trustedAncestor: z12.strictObject({ executable: path, argument: z12.string().min(1).max(128) }).optional(),
588
+ agentSocket: path.optional(),
589
+ serviceDirectory: path.optional()
590
+ });
591
+
592
+ // src/config/machineSchema.ts
593
+ var TelegramConfigSchema = z13.object({
594
+ botToken: z13.string().min(1),
595
+ chatId: z13.string().min(1),
596
+ topicId: z13.number().int().positive().optional()
597
+ });
598
+ var MachineConfigSchema = z13.object({
599
+ finiteWorkloads: FiniteWorkloadsSchema.optional(),
600
+ claudeBin: z13.string().startsWith("/"),
601
+ claudeProfiles: z13.record(ProfileNameSchema, ProfileDirectorySchema).optional(),
602
+ codexBin: z13.string().startsWith("/").optional(),
603
+ opencodeBin: z13.string().startsWith("/").optional(),
604
+ antigravityBin: z13.string().startsWith("/").optional(),
605
+ antigravityDataDir: z13.string().startsWith("/").optional(),
606
+ antigravityMcpServers: z13.array(AcpMcpServerSchema).max(32).optional(),
607
+ claudeNativeRuntime: z13.boolean().default(false),
608
+ claudeNativeSdk: z13.string().startsWith("/").optional(),
609
+ tmuxBin: z13.string().startsWith("/"),
610
+ tmuxSocket: z13.string().min(1).optional(),
611
+ remoteControl: z13.boolean().default(true),
612
+ projectsDir: z13.string().startsWith("/"),
613
+ codexSessionsDir: z13.string().startsWith("/").optional(),
614
+ codexHome: z13.string().startsWith("/").optional(),
615
+ codexCorrelationTimeoutMs: z13.number().int().min(100).default(30000),
616
+ launchRecipes: z13.record(LaunchRecipeIdSchema, MachineLaunchRecipeSchema).default({}),
617
+ agentPolicies: AgentPoliciesSchema,
618
+ applicationDelegationAuthorities: z13.array(ApplicationDelegationGrantSchema2).max(64).optional(),
619
+ delegationAuthorities: z13.array(DelegationAuthoritySchema).max(64).optional(),
620
+ messageApplications: MessageApplicationsSchema,
621
+ rcPrefix: z13.string().regex(RC_PREFIX_RE, "rcPrefix must be a lowercase slug (e.g. local, dev, prod, staging)"),
622
+ fleet: z13.record(z13.string().regex(RC_PREFIX_RE), z13.string().regex(/^[A-Za-z0-9][A-Za-z0-9._@-]*$/, "fleet alias must be an ssh host alias (no leading '-', no spaces)")).optional(),
623
+ sessionEvents: z13.boolean().default(true),
624
+ externals: z13.record(z13.string().regex(SESSION_NAME_RE), z13.string().min(1)).default({}),
625
+ remoteTransport: RemoteTransportSchema.optional(),
626
+ transitPreflight: z13.array(z13.string().min(1)).min(1).optional(),
627
+ stateDir: z13.string().startsWith("/"),
628
+ ensureInterval: z13.number().int().positive().default(30),
629
+ idleSleep: z13.object({
630
+ enabled: z13.boolean().default(false),
631
+ idleAfterMinutes: z13.number().int().positive().default(60),
632
+ minAwakePerProfile: z13.number().int().nonnegative().default(1),
633
+ checkIntervalSeconds: z13.number().int().positive().default(60)
634
+ }).strict().default({
635
+ enabled: false,
636
+ idleAfterMinutes: 60,
637
+ minAwakePerProfile: 1,
638
+ checkIntervalSeconds: 60
639
+ }),
640
+ oomScoreAdj: z13.number().int().min(-1000).max(-1).nullable().default(-300),
641
+ permissionMode: PermissionModeSchema.default("auto"),
642
+ allowEscalatedUnderRoot: z13.boolean().default(false),
643
+ chatEnabled: z13.boolean().default(false),
644
+ externalInventory: z13.boolean().default(false),
645
+ bootLabel: z13.string().min(1),
646
+ tmuxBootLabel: z13.string().min(1).optional(),
647
+ macosBundleId: z13.string().min(1).optional(),
648
+ releaseUrl: z13.url().optional(),
649
+ releaseAllowPrivateHosts: z13.boolean().default(false),
650
+ releaseTrustKeys: z13.record(z13.string().min(1), z13.string().min(1)).optional(),
651
+ autoUpdate: z13.boolean().default(false),
652
+ updateCheckInterval: z13.number().int().positive().default(300),
653
+ autoUpdateSettleSeconds: z13.number().int().nonnegative().default(600),
654
+ extraFlags: z13.array(z13.string()).default([]),
655
+ logLevel: z13.enum(["debug", "info", "warn", "error"]).default("info"),
656
+ resumePicker: z13.enum(["full", "summary", "off"]).default("full"),
657
+ trustPrompt: z13.enum(["off", "folder", "declared"]).default("folder"),
658
+ quota: z13.object({
659
+ probe: z13.enum(["auto", "off"]).default("auto"),
660
+ refreshMinutes: z13.number().int().min(5).max(24 * 60).default(15)
661
+ }).default({ probe: "auto", refreshMinutes: 15 }),
662
+ telegram: TelegramConfigSchema.optional(),
663
+ ownerLang: z13.string().min(1).optional()
664
+ });
665
+ var ReleaseSchema = z13.object({
666
+ version: z13.string().regex(/^\d+\.\d+\.\d+$/),
667
+ notes: z13.string().default(""),
668
+ sha256: z13.string().length(64),
669
+ url: z13.url(),
670
+ releasedAt: z13.iso.datetime().optional()
671
+ });
672
+
673
+ // src/config/paths.ts
674
+ import { join } from "path";
675
+ if (false)
676
+ ;
677
+ function xdgRoot(envValue, fallback) {
678
+ return envValue?.startsWith("/") ? envValue : fallback;
679
+ }
680
+ var STATE_DIR = process.env.STITCHMUX_STATE_DIR ?? join(xdgRoot(process.env.XDG_STATE_HOME, join(HOME, ".local", "state")), "stitchmux");
681
+ var DEFAULT_DATA_DIR = join(xdgRoot(process.env.XDG_DATA_HOME, join(HOME, ".local", "share")), "stitchmux");
682
+ var DATA_DIR = process.env.STITCHMUX_DATA_DIR ?? DEFAULT_DATA_DIR;
683
+ var CACHE_DIR = process.env.STITCHMUX_CACHE_DIR ?? join(xdgRoot(process.env.XDG_CACHE_HOME, join(HOME, ".cache")), "stitchmux");
684
+ var APP_DIR = join(DATA_DIR, "app");
685
+ var APP_BUNDLE = join(APP_DIR, "stitchmux.js");
686
+ var NATIVE_BACKEND_DIR = join(DATA_DIR, "native");
687
+ var STAGED_BUNDLE = join(CACHE_DIR, "staged", "stitchmux.js");
688
+ var RELEASES_DIR = join(CACHE_DIR, "releases");
689
+ var RELEASE_BUNDLE = join(RELEASES_DIR, "stitchmux.js");
690
+ var RELEASE_MANIFEST = join(RELEASES_DIR, "release.json");
691
+ var BOOT_ATTEMPTS = join(STATE_DIR, "boot-attempts");
692
+ var STATUS_DIR = join(STATE_DIR, "status");
693
+ var monitoringStatusPath = (m) => join(m.stateDir, "monitoring-status.json");
694
+
695
+ // src/config/location.ts
696
+ var LocationSchema = MachineConfigSchema.pick({ stateDir: true, rcPrefix: true }).partial();
697
+ function machineConfigPath() {
698
+ return process.env.STITCHMUX_CONFIG ?? `${HOME}/.config/stitchmux/machine.json`;
699
+ }
700
+ function resolveMonitoringLocation(raw) {
701
+ const file = LocationSchema.parse(raw);
702
+ return {
703
+ stateDir: file.stateDir ?? STATE_DIR,
704
+ rcPrefix: process.env.STITCHMUX_RC_PREFIX || file.rcPrefix || "local"
705
+ };
706
+ }
707
+
708
+ // package.json
709
+ var package_default = { version: "0.96.1" };
710
+
711
+ // src/util/version.ts
712
+ var VERSION = package_default.version;
713
+
714
+ export { SESSION_NAME_RE, RC_PREFIX_RE, AgentKindSchema, ManagedPeerSchema, ChatPrincipalSchema2, ChatTargetSchema2, PolicyIdSchema, PolicyDigestSchema, ApplicationPolicyReferenceSchema2, ApplicationPolicyMetadataSchema2, ApplicationPolicyEvidenceSchema2, NativeModelSelectionSchema, NativeTurnOptionsSchema2, AcceptedTurnOptionsSchema2, NativeSelectionEvidenceSchema2, MAX_DECLARED_CUSTOM_TOOLS, NativeSessionSchema, LaunchRecipeReferenceSchema2, ModelSelectionSchema2, LaunchRecipeMetadataSchema2, MessageAttributionSchema2, MessageOriginSchema2, NotificationAudienceSchema2, ApplicationParentSchema2, ApplicationBindingSchema2, ApplicationDelegationGrantSchema2, ApplicationAuthorityOpenSchema2, ApplicationAuthoritySelectorSchema2, ApplicationAuthorityUpdateSchema2, ApplicationAuthoritySchema2, ApplicationAuthorityCapabilitiesSchema2, DelegatedPolicySchema2, DelegationRequestSchema2, DelegationSchema2, DelegationEvidenceSchema2, DelegationCancelSchema, DelegationCancelReceiptSchema, ProfileNameSchema, monitoringStatusPath, machineConfigPath, resolveMonitoringLocation, VERSION };