@spencerboucher/switchyard 0.11.0 → 0.13.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/README.md +5 -2
- package/dist/bridge/agent-channel.js +449 -0
- package/dist/bridge/agent-tools.js +235 -0
- package/dist/bridge/message-delivery.js +185 -0
- package/dist/bridge/policy.js +213 -0
- package/dist/bridge/switchyard-bridge.js +73 -3
- package/dist/bridge/switchyard-terminal.js +77 -11
- package/dist/bridge/tool-preflight.js +155 -0
- package/dist/policies/worker.js +2951 -0
- package/dist/switchyard.mjs +15480 -6064
- package/package.json +3 -1
- package/web-dist/assets/AutomationView-Cg7yk8nb.js +2 -0
- package/web-dist/assets/AutomationView-Cg7yk8nb.js.map +1 -0
- package/web-dist/assets/{Card-XMb6DfZU.js → Card-sHm0eI2Q.js} +2 -2
- package/web-dist/assets/{Card-XMb6DfZU.js.map → Card-sHm0eI2Q.js.map} +1 -1
- package/web-dist/assets/{Checkbox-CeUPbVi7.js → Checkbox-CEvKyfJz.js} +2 -2
- package/web-dist/assets/{Checkbox-CeUPbVi7.js.map → Checkbox-CEvKyfJz.js.map} +1 -1
- package/web-dist/assets/{Copy-CGnl0Vga.js → Copy-BHOLVthK.js} +2 -2
- package/web-dist/assets/{Copy-CGnl0Vga.js.map → Copy-BHOLVthK.js.map} +1 -1
- package/web-dist/assets/{InteractionCard-1ePc4XOF.js → InteractionCard-B-yhxwKs.js} +4 -4
- package/web-dist/assets/{InteractionCard-1ePc4XOF.js.map → InteractionCard-B-yhxwKs.js.map} +1 -1
- package/web-dist/assets/{Menu-CYZQ97c0.js → Menu-Cyt18mF2.js} +2 -2
- package/web-dist/assets/{Menu-CYZQ97c0.js.map → Menu-Cyt18mF2.js.map} +1 -1
- package/web-dist/assets/Overlay-BPNYBq3V.js +2 -0
- package/web-dist/assets/{Overlay-DlLhg1cK.js.map → Overlay-BPNYBq3V.js.map} +1 -1
- package/web-dist/assets/{Priority-BCHLJqWN.js → Priority-xSUsxoXm.js} +2 -2
- package/web-dist/assets/{Priority-BCHLJqWN.js.map → Priority-xSUsxoXm.js.map} +1 -1
- package/web-dist/assets/{SegmentedControl-CSO0EMTX.js → SegmentedControl-DaBwumC0.js} +2 -2
- package/web-dist/assets/{SegmentedControl-CSO0EMTX.js.map → SegmentedControl-DaBwumC0.js.map} +1 -1
- package/web-dist/assets/{Select-Dgmnmpz3.js → Select-C5xlhWYb.js} +2 -2
- package/web-dist/assets/{Select-Dgmnmpz3.js.map → Select-C5xlhWYb.js.map} +1 -1
- package/web-dist/assets/{Switch-DS4NRENd.js → Switch-dVcf-7Je.js} +2 -2
- package/web-dist/assets/{Switch-DS4NRENd.js.map → Switch-dVcf-7Je.js.map} +1 -1
- package/web-dist/assets/{Tabs-9xp-tGja.js → Tabs-93APobOB.js} +2 -2
- package/web-dist/assets/{Tabs-9xp-tGja.js.map → Tabs-93APobOB.js.map} +1 -1
- package/web-dist/assets/{TextArea-PfVKaz29.js → TextArea-D8WB5GD8.js} +2 -2
- package/web-dist/assets/{TextArea-PfVKaz29.js.map → TextArea-D8WB5GD8.js.map} +1 -1
- package/web-dist/assets/{TextLink-CYqiAUlK.js → TextLink-CrfA8AeH.js} +2 -2
- package/web-dist/assets/{TextLink-CYqiAUlK.js.map → TextLink-CrfA8AeH.js.map} +1 -1
- package/web-dist/assets/attention-C8rfu6Uw.js +2 -0
- package/web-dist/assets/{attention-CTkX5JXq.js.map → attention-C8rfu6Uw.js.map} +1 -1
- package/web-dist/assets/{automations-CsdtA3xp.js → automations-DQxUzi5Q.js} +2 -2
- package/web-dist/assets/{automations-CsdtA3xp.js.map → automations-DQxUzi5Q.js.map} +1 -1
- package/web-dist/assets/board-aS6ooJpx.js +10 -0
- package/web-dist/assets/board-aS6ooJpx.js.map +1 -0
- package/web-dist/assets/code-Zr5DqwWI.js +25 -0
- package/web-dist/assets/code-Zr5DqwWI.js.map +1 -0
- package/web-dist/assets/{describe-DjRsBpcB.js → describe-w4KmQFfU.js} +3 -3
- package/web-dist/assets/{describe-DjRsBpcB.js.map → describe-w4KmQFfU.js.map} +1 -1
- package/web-dist/assets/{enroll-DcEYGgoX.js → enroll-DPKdD0en.js} +2 -2
- package/web-dist/assets/{enroll-DcEYGgoX.js.map → enroll-DPKdD0en.js.map} +1 -1
- package/web-dist/assets/index-DFNY2EUd.css +2 -0
- package/web-dist/assets/index-DPScWz2I.js +11 -0
- package/web-dist/assets/index-DPScWz2I.js.map +1 -0
- package/web-dist/assets/{more-BQSa_-H6.js → more-CiyGP5GD.js} +2 -2
- package/web-dist/assets/{more-BQSa_-H6.js.map → more-CiyGP5GD.js.map} +1 -1
- package/web-dist/assets/policyLogic-7OOzM_xa.js +2 -0
- package/web-dist/assets/policyLogic-7OOzM_xa.js.map +1 -0
- package/web-dist/assets/{preload-helper-Huh16h6r.js → preload-helper-B2m1UyXR.js} +5 -5
- package/web-dist/assets/preload-helper-B2m1UyXR.js.map +1 -0
- package/web-dist/assets/queue-BcbJqzTY.js +2 -0
- package/web-dist/assets/{queue-CCjBjQhT.js.map → queue-BcbJqzTY.js.map} +1 -1
- package/web-dist/assets/{repo-pkFfpra6.js → repo-BA_bnCvu.js} +2 -2
- package/web-dist/assets/{repo-pkFfpra6.js.map → repo-BA_bnCvu.js.map} +1 -1
- package/web-dist/assets/settings-D03MF_Kx.js +7 -0
- package/web-dist/assets/settings-D03MF_Kx.js.map +1 -0
- package/web-dist/assets/shared-Bxc2JM1K.js +3 -0
- package/web-dist/assets/shared-Bxc2JM1K.js.map +1 -0
- package/web-dist/assets/states-DynH8-o6.js +58 -0
- package/web-dist/assets/states-DynH8-o6.js.map +1 -0
- package/web-dist/assets/terminal-login-C0n8cXqn.js +2 -0
- package/web-dist/assets/{terminal-login-D9enO0EH.js.map → terminal-login-C0n8cXqn.js.map} +1 -1
- package/web-dist/assets/{useBreakpoint-LY_qlpRG.js → useBreakpoint-CYDIV-KM.js} +2 -2
- package/web-dist/assets/{useBreakpoint-LY_qlpRG.js.map → useBreakpoint-CYDIV-KM.js.map} +1 -1
- package/web-dist/assets/useNow-0tMsLHnB.js +2 -0
- package/web-dist/assets/useNow-0tMsLHnB.js.map +1 -0
- package/web-dist/assets/{useResource-Dul6MTDM.js → useResource-DHtFcID5.js} +2 -2
- package/web-dist/assets/{useResource-Dul6MTDM.js.map → useResource-DHtFcID5.js.map} +1 -1
- package/web-dist/index.html +8 -8
- package/web-dist/sw.js +1 -1
- package/web-dist/sw.js.map +1 -1
- package/web-dist/assets/AutomationView-CrKqim2i.js +0 -2
- package/web-dist/assets/AutomationView-CrKqim2i.js.map +0 -1
- package/web-dist/assets/Field-DVurWE-E.js +0 -2
- package/web-dist/assets/Field-DVurWE-E.js.map +0 -1
- package/web-dist/assets/Overlay-DlLhg1cK.js +0 -2
- package/web-dist/assets/attention-CTkX5JXq.js +0 -2
- package/web-dist/assets/board-CJL75uGb.js +0 -10
- package/web-dist/assets/board-CJL75uGb.js.map +0 -1
- package/web-dist/assets/code-CEYPZt-J.js +0 -21
- package/web-dist/assets/code-CEYPZt-J.js.map +0 -1
- package/web-dist/assets/index-BeJqGnFE.css +0 -2
- package/web-dist/assets/index-DSJZdQ79.js +0 -11
- package/web-dist/assets/index-DSJZdQ79.js.map +0 -1
- package/web-dist/assets/preload-helper-Huh16h6r.js.map +0 -1
- package/web-dist/assets/queue-CCjBjQhT.js +0 -2
- package/web-dist/assets/settings-vrxspmWN.js +0 -7
- package/web-dist/assets/settings-vrxspmWN.js.map +0 -1
- package/web-dist/assets/shared-Bm6Rhfqw.js +0 -3
- package/web-dist/assets/shared-Bm6Rhfqw.js.map +0 -1
- package/web-dist/assets/states-BQxrRFdh.js +0 -56
- package/web-dist/assets/states-BQxrRFdh.js.map +0 -1
- package/web-dist/assets/terminal-login-D9enO0EH.js +0 -2
- package/web-dist/assets/useNow-BUvGqrfn.js +0 -2
- package/web-dist/assets/useNow-BUvGqrfn.js.map +0 -1
|
@@ -0,0 +1,2951 @@
|
|
|
1
|
+
// packages/coordinator/dist/policies/worker.js
|
|
2
|
+
import { parentPort } from "node:worker_threads";
|
|
3
|
+
import { Environment } from "@marcbachmann/cel-js";
|
|
4
|
+
|
|
5
|
+
// packages/protocol/dist/agent-wire.js
|
|
6
|
+
import { z as z3 } from "zod";
|
|
7
|
+
|
|
8
|
+
// packages/protocol/dist/errors.js
|
|
9
|
+
import { z } from "zod";
|
|
10
|
+
var ERROR_CODES = [
|
|
11
|
+
"unauthorized",
|
|
12
|
+
"forbidden",
|
|
13
|
+
"not_found",
|
|
14
|
+
"invalid_request",
|
|
15
|
+
"conflict",
|
|
16
|
+
"already_answered",
|
|
17
|
+
"stale_control",
|
|
18
|
+
"host_unreachable",
|
|
19
|
+
"pi_incompatible",
|
|
20
|
+
"native_session_missing",
|
|
21
|
+
"invalid_transition",
|
|
22
|
+
"dependency_cycle",
|
|
23
|
+
"workspace_dirty",
|
|
24
|
+
"workspace_unmerged",
|
|
25
|
+
"workspace_active_sessions",
|
|
26
|
+
"branch_invalid",
|
|
27
|
+
"path_collision",
|
|
28
|
+
"not_a_git_repo",
|
|
29
|
+
"repo_mismatch",
|
|
30
|
+
"enrollment_expired",
|
|
31
|
+
"enrollment_used",
|
|
32
|
+
"device_revoked",
|
|
33
|
+
"unsupported_capability",
|
|
34
|
+
"too_large",
|
|
35
|
+
"ui_tree_too_large",
|
|
36
|
+
"timeout",
|
|
37
|
+
"rate_limited",
|
|
38
|
+
"internal"
|
|
39
|
+
];
|
|
40
|
+
var ErrorCode = z.enum(ERROR_CODES);
|
|
41
|
+
var ErrorBody = z.object({
|
|
42
|
+
code: ErrorCode,
|
|
43
|
+
message: z.string(),
|
|
44
|
+
details: z.unknown().optional()
|
|
45
|
+
});
|
|
46
|
+
var ApiError = z.object({ error: ErrorBody });
|
|
47
|
+
|
|
48
|
+
// packages/protocol/dist/policies.js
|
|
49
|
+
import { z as z2 } from "zod";
|
|
50
|
+
var Id = z2.string().min(1).max(200);
|
|
51
|
+
var Revision = z2.number().int().safe().min(1);
|
|
52
|
+
var Instant = z2.string().refine((s) => {
|
|
53
|
+
try {
|
|
54
|
+
return new Date(s).toISOString() === s;
|
|
55
|
+
} catch {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
var Text = z2.string().max(4e3);
|
|
60
|
+
var Reason = Text.min(1);
|
|
61
|
+
var Fingerprint = z2.string().regex(/^[0-9a-f]{64}$/);
|
|
62
|
+
var forbidden = /* @__PURE__ */ new Set(["__proto__", "prototype", "constructor"]);
|
|
63
|
+
var bytes = (s) => new TextEncoder().encode(s).length;
|
|
64
|
+
function validJson(value, depth = 0, seen = /* @__PURE__ */ new Set()) {
|
|
65
|
+
if (depth > 20)
|
|
66
|
+
return false;
|
|
67
|
+
if (value === null || typeof value === "string" || typeof value === "boolean")
|
|
68
|
+
return true;
|
|
69
|
+
if (typeof value === "number")
|
|
70
|
+
return Number.isFinite(value) && (!Number.isInteger(value) || Number.isSafeInteger(value));
|
|
71
|
+
if (typeof value !== "object" || seen.has(value))
|
|
72
|
+
return false;
|
|
73
|
+
const prototype = Object.getPrototypeOf(value);
|
|
74
|
+
if (Array.isArray(value) ? prototype !== Array.prototype : prototype !== Object.prototype && prototype !== null)
|
|
75
|
+
return false;
|
|
76
|
+
seen.add(value);
|
|
77
|
+
try {
|
|
78
|
+
const descriptors = Object.getOwnPropertyDescriptors(value);
|
|
79
|
+
const keys = Reflect.ownKeys(descriptors);
|
|
80
|
+
if (Array.isArray(value) && keys.length !== value.length + 1)
|
|
81
|
+
return false;
|
|
82
|
+
return keys.every((key) => {
|
|
83
|
+
if (typeof key !== "string" || forbidden.has(key))
|
|
84
|
+
return false;
|
|
85
|
+
if (Array.isArray(value)) {
|
|
86
|
+
if (key === "length")
|
|
87
|
+
return true;
|
|
88
|
+
if (!/^(0|[1-9][0-9]*)$/.test(key) || Number(key) >= value.length)
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
const descriptor = descriptors[key];
|
|
92
|
+
return descriptor.enumerable === true && "value" in descriptor && validJson(descriptor.value, depth + 1, seen);
|
|
93
|
+
});
|
|
94
|
+
} finally {
|
|
95
|
+
seen.delete(value);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
var JsonObject = z2.custom((v) => !!v && typeof v === "object" && !Array.isArray(v) && validJson(v));
|
|
99
|
+
var CompletedUsageWatermark = z2.object({ runtimeId: Id, settleSeq: Revision }).strict();
|
|
100
|
+
var scopeShape = { scope: z2.enum(["session", "profile", "server"]), scopeId: Id.nullable() };
|
|
101
|
+
var scopeValid = (v) => v.scope === "server" === (v.scopeId === null);
|
|
102
|
+
var PolicyPhase = z2.enum(["tool_call", "request"]);
|
|
103
|
+
var PolicyVerdict = z2.enum(["ALLOW", "ASK", "DENY"]);
|
|
104
|
+
var PolicyRequestAction = z2.enum([
|
|
105
|
+
"task.create",
|
|
106
|
+
"message.send",
|
|
107
|
+
"inbox.read",
|
|
108
|
+
"run.continue"
|
|
109
|
+
]);
|
|
110
|
+
var PolicyScope = scopeShape.scope;
|
|
111
|
+
var PolicyCounterMap = z2.record(z2.string().regex(/^[A-Za-z_][A-Za-z0-9_]{0,63}$/).refine((k) => !forbidden.has(k)), z2.number().int().safe()).refine((v) => Object.keys(v).length <= 64);
|
|
112
|
+
var phases = z2.array(PolicyPhase).min(1).max(2).refine((v) => new Set(v).size === v.length);
|
|
113
|
+
var ruleFields = {
|
|
114
|
+
priority: z2.number().int().safe().min(-1e6).max(1e6),
|
|
115
|
+
enabled: z2.boolean(),
|
|
116
|
+
phases,
|
|
117
|
+
name: z2.string().min(1).max(120),
|
|
118
|
+
expression: z2.string().min(1).max(8192)
|
|
119
|
+
};
|
|
120
|
+
var PolicyRule = z2.object({
|
|
121
|
+
id: Id,
|
|
122
|
+
...scopeShape,
|
|
123
|
+
...ruleFields,
|
|
124
|
+
revision: Revision,
|
|
125
|
+
builtIn: z2.boolean(),
|
|
126
|
+
createdAt: Instant,
|
|
127
|
+
updatedAt: Instant
|
|
128
|
+
}).strict().refine(scopeValid);
|
|
129
|
+
var PolicyToolSafety = z2.object({
|
|
130
|
+
destructiveDelete: z2.boolean(),
|
|
131
|
+
forcePush: z2.boolean(),
|
|
132
|
+
defaultBranchPush: z2.boolean(),
|
|
133
|
+
uncertain: z2.boolean(),
|
|
134
|
+
reasons: z2.array(z2.string().min(1).max(1e3)).max(16)
|
|
135
|
+
}).strict();
|
|
136
|
+
function normalizePosixPath(value) {
|
|
137
|
+
const parts = [];
|
|
138
|
+
for (const part of value.split("/")) {
|
|
139
|
+
if (part === "..")
|
|
140
|
+
parts.pop();
|
|
141
|
+
else if (part && part !== ".")
|
|
142
|
+
parts.push(part);
|
|
143
|
+
}
|
|
144
|
+
return `/${parts.join("/")}`;
|
|
145
|
+
}
|
|
146
|
+
var hostPath = z2.string().min(1).max(8192).refine((value) => value.startsWith("/") && !value.includes("\0"), "Expected absolute POSIX path").transform(normalizePosixPath);
|
|
147
|
+
function relativePosixPath(from, to) {
|
|
148
|
+
const fromParts = from.split("/").filter(Boolean);
|
|
149
|
+
const toParts = to.split("/").filter(Boolean);
|
|
150
|
+
let shared = 0;
|
|
151
|
+
while (shared < fromParts.length && fromParts[shared] === toParts[shared])
|
|
152
|
+
shared++;
|
|
153
|
+
return [...fromParts.slice(shared).map(() => ".."), ...toParts.slice(shared)].join("/");
|
|
154
|
+
}
|
|
155
|
+
var HostPolicyBoundary = z2.object({
|
|
156
|
+
cwd: hostPath,
|
|
157
|
+
workspaceRoot: hostPath,
|
|
158
|
+
cwdReal: hostPath,
|
|
159
|
+
workspaceRootReal: hostPath
|
|
160
|
+
}).strict().refine((boundary) => {
|
|
161
|
+
const relative = relativePosixPath(boundary.workspaceRootReal, boundary.cwdReal);
|
|
162
|
+
return relative !== ".." && !relative.startsWith("../");
|
|
163
|
+
}, "Real cwd must be within the real workspace boundary.");
|
|
164
|
+
var HostToolPolicyContext = z2.object({
|
|
165
|
+
version: z2.literal(1),
|
|
166
|
+
toolCallId: Id,
|
|
167
|
+
toolHash: Fingerprint,
|
|
168
|
+
boundary: HostPolicyBoundary,
|
|
169
|
+
defaultBranch: z2.string().min(1).max(255).nullable(),
|
|
170
|
+
safety: PolicyToolSafety
|
|
171
|
+
}).strict();
|
|
172
|
+
var PolicyToolContext = z2.object({ name: Id, args: JsonObject, safety: PolicyToolSafety }).strict();
|
|
173
|
+
var PolicyRequestContext = z2.object({ method: PolicyRequestAction, args: JsonObject }).strict();
|
|
174
|
+
var absolutePath = z2.string().min(1).max(8192).refine((v) => v.startsWith("/") || /^[A-Za-z]:[\\/]/.test(v));
|
|
175
|
+
var controlMode = z2.enum(["human", "automation"]);
|
|
176
|
+
var PolicySessionContext = z2.object({
|
|
177
|
+
id: Id,
|
|
178
|
+
hostId: Id,
|
|
179
|
+
nativeSessionId: Id.nullable(),
|
|
180
|
+
runtimeId: Id.nullable(),
|
|
181
|
+
profileId: Id,
|
|
182
|
+
projectId: Id.nullable(),
|
|
183
|
+
taskId: Id.nullable(),
|
|
184
|
+
runId: Id.nullable(),
|
|
185
|
+
controlMode,
|
|
186
|
+
controlRevision: Revision,
|
|
187
|
+
cwd: absolutePath,
|
|
188
|
+
workspaceRoot: absolutePath,
|
|
189
|
+
repository: z2.string().min(1).max(2048).nullable(),
|
|
190
|
+
defaultBranch: z2.string().min(1).max(255).nullable(),
|
|
191
|
+
readOnly: z2.boolean()
|
|
192
|
+
}).strict();
|
|
193
|
+
var PolicyTaskContext = z2.object({
|
|
194
|
+
id: Id,
|
|
195
|
+
projectId: Id,
|
|
196
|
+
rootTaskId: Id,
|
|
197
|
+
parentTaskId: Id.nullable(),
|
|
198
|
+
title: z2.string().min(1).max(300),
|
|
199
|
+
state: z2.enum(["backlog", "ready", "in_progress", "review", "done", "canceled"])
|
|
200
|
+
}).strict();
|
|
201
|
+
var PolicyTargetContext = z2.object({
|
|
202
|
+
id: Id,
|
|
203
|
+
hostId: Id,
|
|
204
|
+
projectId: Id.nullable(),
|
|
205
|
+
taskId: Id.nullable(),
|
|
206
|
+
controlMode,
|
|
207
|
+
controlRevision: Revision,
|
|
208
|
+
runtime: z2.enum([
|
|
209
|
+
"starting",
|
|
210
|
+
"idle",
|
|
211
|
+
"running",
|
|
212
|
+
"waiting_input",
|
|
213
|
+
"interrupted",
|
|
214
|
+
"failed",
|
|
215
|
+
"stopped"
|
|
216
|
+
]),
|
|
217
|
+
readOnly: z2.boolean()
|
|
218
|
+
}).strict();
|
|
219
|
+
var PolicyCostContext = z2.object({
|
|
220
|
+
tokens: z2.number().int().safe().nonnegative().nullable(),
|
|
221
|
+
costUsd: z2.number().finite().nonnegative().nullable(),
|
|
222
|
+
maxTokens: z2.number().int().safe().positive().nullable(),
|
|
223
|
+
maxCostUsd: z2.number().finite().positive().nullable(),
|
|
224
|
+
accounting: z2.enum(["available", "unavailable"]),
|
|
225
|
+
fresh: z2.boolean(),
|
|
226
|
+
watermark: CompletedUsageWatermark.nullable(),
|
|
227
|
+
provider: Id.nullable(),
|
|
228
|
+
modelId: z2.string().min(1).max(512).nullable(),
|
|
229
|
+
classification: z2.enum(["cheap", "expensive", "unclassified"]),
|
|
230
|
+
expensive: z2.boolean()
|
|
231
|
+
}).strict().refine((v) => v.expensive === (v.classification !== "cheap") && (v.provider !== null && v.modelId !== null || v.classification === "unclassified") && v.accounting === "available" === (v.tokens !== null || v.costUsd !== null));
|
|
232
|
+
var PolicyContext = z2.object({
|
|
233
|
+
phase: PolicyPhase,
|
|
234
|
+
action: z2.union([z2.literal("tool.call"), PolicyRequestAction]),
|
|
235
|
+
tool: PolicyToolContext.nullable(),
|
|
236
|
+
request: PolicyRequestContext.nullable(),
|
|
237
|
+
session: PolicySessionContext,
|
|
238
|
+
task: PolicyTaskContext.nullable(),
|
|
239
|
+
target: PolicyTargetContext.nullable(),
|
|
240
|
+
cost: PolicyCostContext,
|
|
241
|
+
counters: PolicyCounterMap
|
|
242
|
+
}).strict().refine((v) => (v.phase === "tool_call" ? v.action === "tool.call" && v.tool !== null && v.request === null : v.tool === null && v.request !== null && v.action === v.request.method) && (v.action === "message.send" ? v.target !== null : v.target === null)).refine((v) => bytes(JSON.stringify(v)) <= 65536, "Policy input is too large to evaluate.");
|
|
243
|
+
var PolicyRuleResult = z2.union([
|
|
244
|
+
z2.null(),
|
|
245
|
+
z2.object({ verdict: PolicyVerdict, reason: Text, state_updates: PolicyCounterMap.optional() }).strict().refine((v) => v.verdict === "ALLOW" || v.reason.length > 0)
|
|
246
|
+
]);
|
|
247
|
+
var webUrl = z2.string().max(4096).refine((s) => {
|
|
248
|
+
try {
|
|
249
|
+
const u = new URL(s);
|
|
250
|
+
return ["http:", "https:"].includes(u.protocol) && !u.username && !u.password;
|
|
251
|
+
} catch {
|
|
252
|
+
return false;
|
|
253
|
+
}
|
|
254
|
+
});
|
|
255
|
+
var PolicyEvaluation = z2.discriminatedUnion("verdict", [
|
|
256
|
+
z2.object({ verdict: z2.literal("ALLOW") }).strict(),
|
|
257
|
+
z2.object({ verdict: z2.literal("DENY"), reason: Reason }).strict(),
|
|
258
|
+
z2.object({
|
|
259
|
+
verdict: z2.literal("ASK"),
|
|
260
|
+
decisionId: Id,
|
|
261
|
+
interactionId: Id,
|
|
262
|
+
interactionUrl: webUrl
|
|
263
|
+
}).strict()
|
|
264
|
+
]);
|
|
265
|
+
var PolicyPermission = z2.object({
|
|
266
|
+
kind: z2.literal("policy"),
|
|
267
|
+
decisionId: Id,
|
|
268
|
+
rootTaskId: Id.nullable(),
|
|
269
|
+
ruleId: Id,
|
|
270
|
+
ruleRevision: Revision,
|
|
271
|
+
fingerprint: Fingerprint
|
|
272
|
+
}).strict();
|
|
273
|
+
var PolicyGrant = z2.object({
|
|
274
|
+
id: Id,
|
|
275
|
+
scope: z2.object({ kind: z2.enum(["task", "session"]), id: Id }).strict(),
|
|
276
|
+
ruleId: Id,
|
|
277
|
+
ruleRevision: Revision,
|
|
278
|
+
fingerprint: Fingerprint,
|
|
279
|
+
approvedByDeviceId: Id,
|
|
280
|
+
approvedAt: Instant
|
|
281
|
+
}).strict();
|
|
282
|
+
var trimmed = (max) => z2.string().min(1).max(max).refine((s) => s.trim() === s);
|
|
283
|
+
var PolicyModelClassification = z2.object({
|
|
284
|
+
provider: trimmed(200),
|
|
285
|
+
modelId: trimmed(512),
|
|
286
|
+
classification: z2.enum(["cheap", "expensive"])
|
|
287
|
+
}).strict();
|
|
288
|
+
var classifications = z2.array(PolicyModelClassification).max(1e3).refine((v) => new Set(v.map((x) => JSON.stringify([x.provider, x.modelId]))).size === v.length);
|
|
289
|
+
var PolicySettings = z2.object({ revision: Revision, modelClassifications: classifications, updatedAt: Instant }).strict();
|
|
290
|
+
var toolInput = z2.object({ name: Id, args: JsonObject }).strict();
|
|
291
|
+
var sampleIdentity = { sessionId: Id, nativeSessionId: Id, runtimeId: Id, sampleId: Id };
|
|
292
|
+
var HostPolicySampleRequest = z2.object({ ...sampleIdentity, tool: toolInput }).strict();
|
|
293
|
+
var HostPolicySampleResult = z2.object({
|
|
294
|
+
...sampleIdentity,
|
|
295
|
+
toolHash: Fingerprint,
|
|
296
|
+
boundary: HostPolicyBoundary,
|
|
297
|
+
defaultBranch: z2.string().min(1).max(255).nullable(),
|
|
298
|
+
safety: PolicyToolSafety
|
|
299
|
+
}).strict();
|
|
300
|
+
var PolicyEvaluateRequest = z2.object({ evaluationId: Id, toolCallId: Id, tool: toolInput }).strict();
|
|
301
|
+
var PolicyStatusRequest = z2.object({ decisionId: Id, waitMs: z2.literal(25e3) }).strict();
|
|
302
|
+
var PolicyStatusResult = z2.discriminatedUnion("state", [
|
|
303
|
+
z2.object({ state: z2.literal("pending") }).strict(),
|
|
304
|
+
z2.object({ state: z2.literal("allowed") }).strict(),
|
|
305
|
+
z2.object({ state: z2.literal("denied"), reason: Reason }).strict(),
|
|
306
|
+
z2.object({ state: z2.literal("canceled"), reason: Reason }).strict()
|
|
307
|
+
]);
|
|
308
|
+
var PolicyCancelRequest = z2.object({ decisionId: Id }).strict();
|
|
309
|
+
var PolicyCancelResult = z2.object({ state: z2.enum(["canceled", "already_resolved"]) }).strict();
|
|
310
|
+
var PolicyTrace = z2.object({
|
|
311
|
+
ruleId: Id,
|
|
312
|
+
ruleRevision: Revision,
|
|
313
|
+
...scopeShape,
|
|
314
|
+
verdict: PolicyVerdict.nullable(),
|
|
315
|
+
reason: Text.nullable(),
|
|
316
|
+
granted: z2.boolean(),
|
|
317
|
+
overridden: z2.boolean(),
|
|
318
|
+
proposedStateUpdates: PolicyCounterMap
|
|
319
|
+
}).strict().refine(scopeValid);
|
|
320
|
+
var PolicyTestResult = z2.object({
|
|
321
|
+
verdict: PolicyVerdict,
|
|
322
|
+
reason: Text.nullable(),
|
|
323
|
+
trace: z2.array(PolicyTrace).max(128),
|
|
324
|
+
proposedStateUpdates: z2.record(Id, PolicyCounterMap),
|
|
325
|
+
enforcement: z2.object({
|
|
326
|
+
phases: z2.array(PolicyPhase),
|
|
327
|
+
modelRequest: z2.literal(false),
|
|
328
|
+
explanation: z2.string()
|
|
329
|
+
}).strict()
|
|
330
|
+
}).strict();
|
|
331
|
+
var CreatePolicyRuleRequest = z2.object({ ...scopeShape, ...ruleFields }).strict().refine(scopeValid);
|
|
332
|
+
var UpdatePolicyRuleRequest = z2.object({
|
|
333
|
+
expectedRevision: Revision,
|
|
334
|
+
name: ruleFields.name.optional(),
|
|
335
|
+
priority: ruleFields.priority.optional(),
|
|
336
|
+
enabled: z2.boolean().optional(),
|
|
337
|
+
phases: phases.optional(),
|
|
338
|
+
expression: ruleFields.expression.optional()
|
|
339
|
+
}).strict().refine((v) => Object.keys(v).length > 1);
|
|
340
|
+
var DeletePolicyRuleQuery = z2.object({ expectedRevision: Revision }).strict();
|
|
341
|
+
var UpdatePolicySettingsRequest = z2.object({ expectedRevision: Revision, modelClassifications: classifications }).strict();
|
|
342
|
+
var PolicyTestRequest = z2.object({
|
|
343
|
+
sessionId: Id,
|
|
344
|
+
phase: PolicyPhase,
|
|
345
|
+
tool: toolInput.nullable(),
|
|
346
|
+
request: PolicyRequestContext.nullable()
|
|
347
|
+
}).strict().refine((v) => v.phase === "tool_call" ? v.tool !== null && v.request === null : v.tool === null && v.request !== null);
|
|
348
|
+
|
|
349
|
+
// packages/protocol/dist/agent-wire.js
|
|
350
|
+
var Id2 = z3.string().min(1).max(200);
|
|
351
|
+
var Instant2 = z3.string().refine((value) => {
|
|
352
|
+
const date = new Date(value);
|
|
353
|
+
return Number.isFinite(date.getTime()) && date.toISOString() === value;
|
|
354
|
+
}, "Expected canonical UTC timestamp");
|
|
355
|
+
var AGENT_FRAME_MAX_BYTES = 128 * 1024;
|
|
356
|
+
var AgentMethod = z3.enum([
|
|
357
|
+
"session.bind",
|
|
358
|
+
"task.create",
|
|
359
|
+
"message.send",
|
|
360
|
+
"inbox.read",
|
|
361
|
+
"receipt.peek",
|
|
362
|
+
"policy.evaluate",
|
|
363
|
+
"policy.status",
|
|
364
|
+
"policy.cancel"
|
|
365
|
+
]);
|
|
366
|
+
var AgentToolMethod = z3.enum(["task.create", "message.send", "inbox.read"]);
|
|
367
|
+
var RequestHash = z3.string().regex(/^[a-f0-9]{64}$/);
|
|
368
|
+
var AgentReceiptPeekRequest = z3.object({ method: AgentToolMethod, args: z3.record(z3.string(), z3.json()) }).strict();
|
|
369
|
+
var AgentReceiptPeekResult = z3.discriminatedUnion("found", [
|
|
370
|
+
z3.object({ found: z3.literal(false) }).strict(),
|
|
371
|
+
z3.object({ found: z3.literal(true), requestHash: RequestHash }).strict()
|
|
372
|
+
]);
|
|
373
|
+
var AgentReceiptReplay = z3.object({ requestHash: RequestHash }).strict();
|
|
374
|
+
var CreateAgentTask = z3.object({
|
|
375
|
+
objective: z3.string().min(1).max(16e3),
|
|
376
|
+
acceptance: z3.array(z3.string().min(1).max(2e3)).max(100).default([]),
|
|
377
|
+
dependencies: z3.array(Id2).max(100).default([]),
|
|
378
|
+
parentTaskId: Id2.nullable().optional(),
|
|
379
|
+
hostId: Id2.optional(),
|
|
380
|
+
profileId: Id2.optional(),
|
|
381
|
+
notifyOnFinish: z3.boolean().default(true)
|
|
382
|
+
});
|
|
383
|
+
var SendAgentMessage = z3.object({
|
|
384
|
+
sessionId: Id2,
|
|
385
|
+
body: z3.string().min(1).max(16e3),
|
|
386
|
+
mode: z3.enum(["steer", "queue"]),
|
|
387
|
+
replyTo: Id2.optional()
|
|
388
|
+
});
|
|
389
|
+
var ReadAgentInbox = z3.object({
|
|
390
|
+
after: z3.number().int().nonnegative().default(0),
|
|
391
|
+
limit: z3.number().int().min(1).max(100).default(20)
|
|
392
|
+
});
|
|
393
|
+
var DeliveryState = z3.enum([
|
|
394
|
+
"pending",
|
|
395
|
+
"held",
|
|
396
|
+
"deferred",
|
|
397
|
+
"accepted",
|
|
398
|
+
"queued",
|
|
399
|
+
"appended",
|
|
400
|
+
"uncertain",
|
|
401
|
+
"failed"
|
|
402
|
+
]);
|
|
403
|
+
var AgentMessageFields = {
|
|
404
|
+
seq: z3.number().int().positive(),
|
|
405
|
+
id: Id2,
|
|
406
|
+
recipientSessionId: Id2,
|
|
407
|
+
replyTo: Id2.nullable(),
|
|
408
|
+
chainId: Id2,
|
|
409
|
+
depth: z3.number().int().min(0).max(4),
|
|
410
|
+
body: z3.unknown(),
|
|
411
|
+
requestedMode: z3.enum(["steer", "queue"]),
|
|
412
|
+
deliveryState: DeliveryState,
|
|
413
|
+
holdUntil: z3.string(),
|
|
414
|
+
readAt: z3.string().nullable(),
|
|
415
|
+
createdAt: z3.string()
|
|
416
|
+
};
|
|
417
|
+
var AgentMessage = z3.discriminatedUnion("kind", [
|
|
418
|
+
z3.object({ ...AgentMessageFields, kind: z3.literal("message"), senderSessionId: Id2 }),
|
|
419
|
+
z3.object({
|
|
420
|
+
...AgentMessageFields,
|
|
421
|
+
kind: z3.literal("completion"),
|
|
422
|
+
senderSessionId: Id2.nullable()
|
|
423
|
+
})
|
|
424
|
+
]);
|
|
425
|
+
var AgentInbox = z3.object({
|
|
426
|
+
messages: z3.array(AgentMessage),
|
|
427
|
+
nextAfter: z3.number().int().nonnegative(),
|
|
428
|
+
hasMore: z3.boolean()
|
|
429
|
+
});
|
|
430
|
+
var AgentToolPolicyWait = PolicyEvaluation.options[2].omit({ verdict: true }).extend({ type: z3.literal("policy.required") }).strict();
|
|
431
|
+
var AgentRequestFrame = z3.object({
|
|
432
|
+
type: z3.literal("agent.request"),
|
|
433
|
+
requestId: Id2,
|
|
434
|
+
sessionId: Id2,
|
|
435
|
+
nativeSessionId: Id2,
|
|
436
|
+
runtimeId: Id2,
|
|
437
|
+
context: z3.object({ humanInputId: Id2.nullable(), causalMessageId: Id2.nullable() }).strict(),
|
|
438
|
+
toolCallId: Id2.optional(),
|
|
439
|
+
receiptReplay: AgentReceiptReplay.optional(),
|
|
440
|
+
// Tool-method ingress requires this separately; legacy/non-tool frames remain compatible.
|
|
441
|
+
deadlineAt: Instant2.optional(),
|
|
442
|
+
method: AgentMethod,
|
|
443
|
+
args: z3.unknown()
|
|
444
|
+
}).strict().superRefine((frame, ctx) => {
|
|
445
|
+
if (frame.method === "receipt.peek") {
|
|
446
|
+
if (!frame.toolCallId) {
|
|
447
|
+
ctx.addIssue({
|
|
448
|
+
code: "custom",
|
|
449
|
+
path: ["toolCallId"],
|
|
450
|
+
message: "Receipt lookup requires a tool call ID."
|
|
451
|
+
});
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
if (Object.hasOwn(frame, "receiptReplay") && !AgentToolMethod.safeParse(frame.method).success) {
|
|
455
|
+
ctx.addIssue({
|
|
456
|
+
code: "custom",
|
|
457
|
+
path: ["receiptReplay"],
|
|
458
|
+
message: "Receipt replay is only valid for tool methods."
|
|
459
|
+
});
|
|
460
|
+
}
|
|
461
|
+
});
|
|
462
|
+
var AgentResultFrame = z3.discriminatedUnion("ok", [
|
|
463
|
+
z3.object({
|
|
464
|
+
type: z3.literal("agent.result"),
|
|
465
|
+
requestId: Id2,
|
|
466
|
+
runtimeId: Id2,
|
|
467
|
+
ok: z3.literal(true),
|
|
468
|
+
result: z3.unknown()
|
|
469
|
+
}),
|
|
470
|
+
z3.object({
|
|
471
|
+
type: z3.literal("agent.result"),
|
|
472
|
+
requestId: Id2,
|
|
473
|
+
runtimeId: Id2,
|
|
474
|
+
ok: z3.literal(false),
|
|
475
|
+
error: ErrorBody
|
|
476
|
+
})
|
|
477
|
+
]);
|
|
478
|
+
|
|
479
|
+
// packages/protocol/dist/api.js
|
|
480
|
+
import { z as z11 } from "zod";
|
|
481
|
+
|
|
482
|
+
// packages/protocol/dist/entities.js
|
|
483
|
+
import { z as z7 } from "zod";
|
|
484
|
+
|
|
485
|
+
// packages/protocol/dist/contributions.js
|
|
486
|
+
import { z as z5 } from "zod";
|
|
487
|
+
|
|
488
|
+
// packages/protocol/dist/ui.js
|
|
489
|
+
import { z as z4 } from "zod";
|
|
490
|
+
var ToneSchema = z4.enum(["default", "muted", "success", "warning", "danger"]);
|
|
491
|
+
var ShowIfSchema = z4.object({ field: z4.string(), values: z4.array(z4.string()) });
|
|
492
|
+
var OptionSchema = z4.object({
|
|
493
|
+
value: z4.string(),
|
|
494
|
+
label: z4.string(),
|
|
495
|
+
description: z4.string().optional(),
|
|
496
|
+
preview: z4.string().optional()
|
|
497
|
+
});
|
|
498
|
+
var AllowOther = z4.object({ label: z4.string(), placeholder: z4.string().optional() });
|
|
499
|
+
var FieldSchema = z4.discriminatedUnion("kind", [
|
|
500
|
+
z4.object({
|
|
501
|
+
kind: z4.literal("select"),
|
|
502
|
+
name: z4.string(),
|
|
503
|
+
label: z4.string(),
|
|
504
|
+
options: z4.array(OptionSchema),
|
|
505
|
+
allowOther: AllowOther.optional(),
|
|
506
|
+
showIf: ShowIfSchema.optional()
|
|
507
|
+
}),
|
|
508
|
+
z4.object({
|
|
509
|
+
kind: z4.literal("multiselect"),
|
|
510
|
+
name: z4.string(),
|
|
511
|
+
label: z4.string(),
|
|
512
|
+
options: z4.array(OptionSchema),
|
|
513
|
+
allowOther: AllowOther.optional(),
|
|
514
|
+
min: z4.number().int().min(0).optional(),
|
|
515
|
+
max: z4.number().int().min(1).optional(),
|
|
516
|
+
showIf: ShowIfSchema.optional()
|
|
517
|
+
}),
|
|
518
|
+
z4.object({
|
|
519
|
+
kind: z4.literal("text"),
|
|
520
|
+
name: z4.string(),
|
|
521
|
+
label: z4.string(),
|
|
522
|
+
placeholder: z4.string().optional(),
|
|
523
|
+
multiline: z4.boolean().optional(),
|
|
524
|
+
prefill: z4.string().optional(),
|
|
525
|
+
showIf: ShowIfSchema.optional()
|
|
526
|
+
})
|
|
527
|
+
]);
|
|
528
|
+
var RefSchema = z4.discriminatedUnion("kind", [
|
|
529
|
+
z4.object({ kind: z4.literal("file"), path: z4.string() }),
|
|
530
|
+
z4.object({ kind: z4.literal("session"), sessionId: z4.string() }),
|
|
531
|
+
z4.object({ kind: z4.literal("task"), taskId: z4.string() }),
|
|
532
|
+
z4.object({ kind: z4.literal("native_session"), hostId: z4.string(), sessionFile: z4.string() })
|
|
533
|
+
]);
|
|
534
|
+
var UINodeSchema = z4.lazy(() => z4.discriminatedUnion("t", [
|
|
535
|
+
z4.object({ t: z4.literal("text"), text: z4.string(), tone: ToneSchema.optional() }),
|
|
536
|
+
z4.object({ t: z4.literal("markdown"), text: z4.string() }),
|
|
537
|
+
z4.object({ t: z4.literal("code"), text: z4.string(), lang: z4.string().optional() }),
|
|
538
|
+
z4.object({ t: z4.literal("diff"), patch: z4.string() }),
|
|
539
|
+
z4.object({
|
|
540
|
+
t: z4.literal("list"),
|
|
541
|
+
items: z4.array(UINodeSchema),
|
|
542
|
+
ordered: z4.boolean().optional()
|
|
543
|
+
}),
|
|
544
|
+
z4.object({
|
|
545
|
+
t: z4.literal("table"),
|
|
546
|
+
columns: z4.array(z4.string()),
|
|
547
|
+
rows: z4.array(z4.array(z4.string()))
|
|
548
|
+
}),
|
|
549
|
+
z4.object({
|
|
550
|
+
t: z4.literal("section"),
|
|
551
|
+
title: z4.string().optional(),
|
|
552
|
+
collapsible: z4.boolean().optional(),
|
|
553
|
+
children: z4.array(UINodeSchema)
|
|
554
|
+
}),
|
|
555
|
+
z4.object({
|
|
556
|
+
t: z4.literal("tabs"),
|
|
557
|
+
tabs: z4.array(z4.object({ id: z4.string(), label: z4.string(), children: z4.array(UINodeSchema) }))
|
|
558
|
+
}),
|
|
559
|
+
z4.object({
|
|
560
|
+
t: z4.literal("progress"),
|
|
561
|
+
label: z4.string(),
|
|
562
|
+
value: z4.number().min(0).max(1).optional(),
|
|
563
|
+
status: z4.enum(["running", "ok", "error"]).optional()
|
|
564
|
+
}),
|
|
565
|
+
z4.object({ t: z4.literal("ref"), ref: RefSchema, label: z4.string() }),
|
|
566
|
+
z4.object({
|
|
567
|
+
t: z4.literal("form"),
|
|
568
|
+
formId: z4.string(),
|
|
569
|
+
fields: z4.array(FieldSchema),
|
|
570
|
+
submitLabel: z4.string(),
|
|
571
|
+
cancelLabel: z4.string().optional()
|
|
572
|
+
}),
|
|
573
|
+
z4.object({
|
|
574
|
+
t: z4.literal("confirm"),
|
|
575
|
+
message: z4.string(),
|
|
576
|
+
confirmLabel: z4.string(),
|
|
577
|
+
cancelLabel: z4.string(),
|
|
578
|
+
destructive: z4.boolean().optional()
|
|
579
|
+
}),
|
|
580
|
+
z4.object({
|
|
581
|
+
t: z4.literal("actions"),
|
|
582
|
+
actions: z4.array(z4.object({
|
|
583
|
+
id: z4.string(),
|
|
584
|
+
label: z4.string(),
|
|
585
|
+
tone: z4.enum(["default", "primary", "danger"]).optional()
|
|
586
|
+
}))
|
|
587
|
+
})
|
|
588
|
+
]));
|
|
589
|
+
var FormValueSchema = z4.union([
|
|
590
|
+
z4.string(),
|
|
591
|
+
z4.array(z4.string()),
|
|
592
|
+
z4.object({ other: z4.string() })
|
|
593
|
+
]);
|
|
594
|
+
var InteractionResponseSchema = z4.discriminatedUnion("kind", [
|
|
595
|
+
z4.object({ kind: z4.literal("form"), values: z4.record(z4.string(), FormValueSchema) }),
|
|
596
|
+
z4.object({ kind: z4.literal("confirm"), confirmed: z4.boolean() }),
|
|
597
|
+
z4.object({ kind: z4.literal("action"), actionId: z4.string() }),
|
|
598
|
+
z4.object({ kind: z4.literal("cancel") })
|
|
599
|
+
]);
|
|
600
|
+
|
|
601
|
+
// packages/protocol/dist/contributions.js
|
|
602
|
+
var ContributionPlacement = z5.enum([
|
|
603
|
+
"sidebar.header",
|
|
604
|
+
"sidebar.footer",
|
|
605
|
+
"session.panel",
|
|
606
|
+
"composer.pill",
|
|
607
|
+
"palette.item",
|
|
608
|
+
"slash.command"
|
|
609
|
+
]);
|
|
610
|
+
var Id3 = z5.string().regex(/^[a-zA-Z0-9][a-zA-Z0-9._-]{0,79}$/);
|
|
611
|
+
var ActionId = z5.string().min(1).max(200);
|
|
612
|
+
var Keywords = z5.array(z5.string().min(1).max(80)).max(20);
|
|
613
|
+
var Common = {
|
|
614
|
+
placement: ContributionPlacement,
|
|
615
|
+
order: z5.number().int().min(-1e3).max(1e3).optional(),
|
|
616
|
+
actionId: ActionId.optional()
|
|
617
|
+
};
|
|
618
|
+
var ContributionDescriptor = z5.object({
|
|
619
|
+
id: Id3,
|
|
620
|
+
...Common,
|
|
621
|
+
name: z5.string().regex(/^[a-z][a-z0-9-]{0,39}$/).optional(),
|
|
622
|
+
keywords: Keywords.optional()
|
|
623
|
+
}).strict().superRefine((v, ctx) => {
|
|
624
|
+
if (v.placement === "slash.command" && (!v.name || !v.actionId)) {
|
|
625
|
+
ctx.addIssue({ code: "custom", message: "Slash commands need name and actionId" });
|
|
626
|
+
}
|
|
627
|
+
if (v.placement === "palette.item" && !v.actionId) {
|
|
628
|
+
ctx.addIssue({ code: "custom", message: "Palette items need actionId" });
|
|
629
|
+
}
|
|
630
|
+
if (v.placement !== "slash.command" && v.name !== void 0) {
|
|
631
|
+
ctx.addIssue({ code: "custom", message: "Only slash commands have names" });
|
|
632
|
+
}
|
|
633
|
+
if (v.placement !== "palette.item" && v.keywords !== void 0) {
|
|
634
|
+
ctx.addIssue({ code: "custom", message: "Only palette items have keywords" });
|
|
635
|
+
}
|
|
636
|
+
if (v.placement === "composer.pill" && v.actionId !== void 0) {
|
|
637
|
+
ctx.addIssue({ code: "custom", message: "Composer pills are not interactive" });
|
|
638
|
+
}
|
|
639
|
+
});
|
|
640
|
+
var ContributionInput = z5.object({
|
|
641
|
+
...Common,
|
|
642
|
+
title: z5.string().min(1).max(100),
|
|
643
|
+
node: z5.unknown(),
|
|
644
|
+
mobileFallback: z5.string().min(1).max(2e3),
|
|
645
|
+
state: z5.unknown().optional(),
|
|
646
|
+
name: z5.string().regex(/^[a-z][a-z0-9-]{0,39}$/).optional(),
|
|
647
|
+
keywords: Keywords.optional()
|
|
648
|
+
}).strict();
|
|
649
|
+
|
|
650
|
+
// packages/protocol/dist/github.js
|
|
651
|
+
import { z as z6 } from "zod";
|
|
652
|
+
var Id4 = z6.string().min(1).max(200);
|
|
653
|
+
var Instant3 = z6.string().refine((s) => {
|
|
654
|
+
try {
|
|
655
|
+
return new Date(s).toISOString() === s;
|
|
656
|
+
} catch {
|
|
657
|
+
return false;
|
|
658
|
+
}
|
|
659
|
+
});
|
|
660
|
+
var positive = z6.number().int().safe().positive();
|
|
661
|
+
var nonnegative = z6.number().int().safe().nonnegative();
|
|
662
|
+
var reason = z6.string().min(1).max(2e3);
|
|
663
|
+
var hash = z6.string().regex(/^[0-9a-f]{64}$/);
|
|
664
|
+
var actionsId = z6.string().regex(/^[1-9][0-9]{0,19}$/);
|
|
665
|
+
var bytes2 = (s) => new TextEncoder().encode(s).length;
|
|
666
|
+
var displayUrl = z6.string().max(4096).refine((s) => {
|
|
667
|
+
try {
|
|
668
|
+
const u = new URL(s);
|
|
669
|
+
return ["http:", "https:"].includes(u.protocol) && !u.username && !u.password;
|
|
670
|
+
} catch {
|
|
671
|
+
return false;
|
|
672
|
+
}
|
|
673
|
+
});
|
|
674
|
+
var githubUrl = displayUrl.refine((s) => {
|
|
675
|
+
try {
|
|
676
|
+
const u = new URL(s);
|
|
677
|
+
return u.protocol === "https:" && u.hostname === "github.com" && !u.port && /^https:\/\/github\.com(?:[/?#]|$)/i.test(s);
|
|
678
|
+
} catch {
|
|
679
|
+
return false;
|
|
680
|
+
}
|
|
681
|
+
});
|
|
682
|
+
var GitHubRepository = z6.string().regex(/^[A-Za-z0-9](?:[A-Za-z0-9-]{0,37}[A-Za-z0-9])?\/(?!\.{1,2}$)[A-Za-z0-9_.-]{1,100}$/);
|
|
683
|
+
var issuePath = /^[hH][tT][tT][pP][sS]:\/\/[gG][iI][tT][hH][uU][bB]\.[cC][oO][mM]\/([^/]+)\/([^/]+)\/issues\/([1-9][0-9]*)$/;
|
|
684
|
+
var GitHubIssueUrl = z6.string().trim().transform((raw, ctx) => {
|
|
685
|
+
const match = issuePath.exec(raw);
|
|
686
|
+
const number = match ? Number(match[3]) : NaN;
|
|
687
|
+
if (!match || !GitHubRepository.safeParse(`${match[1]}/${match[2]}`).success || !Number.isSafeInteger(number)) {
|
|
688
|
+
ctx.addIssue({ code: "custom", message: "Invalid GitHub issue URL" });
|
|
689
|
+
return z6.NEVER;
|
|
690
|
+
}
|
|
691
|
+
return `https://github.com/${match[1]}/${match[2]}/issues/${number}`;
|
|
692
|
+
});
|
|
693
|
+
function issueParts(url) {
|
|
694
|
+
const match = issuePath.exec(url);
|
|
695
|
+
return { repository: `${match[1]}/${match[2]}`, number: Number(match[3]) };
|
|
696
|
+
}
|
|
697
|
+
function issuePrompt(url) {
|
|
698
|
+
return `${url}
|
|
699
|
+
|
|
700
|
+
Read it with \`gh issue view ${url}\`.`;
|
|
701
|
+
}
|
|
702
|
+
var GitHubIssueIdentity = z6.object({
|
|
703
|
+
repository: GitHubRepository,
|
|
704
|
+
number: positive,
|
|
705
|
+
url: GitHubIssueUrl
|
|
706
|
+
}).strict().refine((v) => {
|
|
707
|
+
const parts = issueParts(v.url);
|
|
708
|
+
return v.repository === parts.repository && v.number === parts.number;
|
|
709
|
+
});
|
|
710
|
+
var GitHubIssue = z6.object({
|
|
711
|
+
repository: GitHubRepository,
|
|
712
|
+
number: positive,
|
|
713
|
+
url: GitHubIssueUrl,
|
|
714
|
+
launchPrompt: z6.string()
|
|
715
|
+
}).strict().refine((v) => {
|
|
716
|
+
const parts = issueParts(v.url);
|
|
717
|
+
return v.repository === parts.repository && v.number === parts.number && v.launchPrompt === issuePrompt(v.url);
|
|
718
|
+
});
|
|
719
|
+
function githubIssueFromUrl(raw) {
|
|
720
|
+
const url = GitHubIssueUrl.parse(raw);
|
|
721
|
+
return { ...issueParts(url), url, launchPrompt: issuePrompt(url) };
|
|
722
|
+
}
|
|
723
|
+
var GitHubSha = z6.string().regex(/^[0-9a-f]{40}$/);
|
|
724
|
+
var prUrl = githubUrl.refine((s) => {
|
|
725
|
+
try {
|
|
726
|
+
const u = new URL(s);
|
|
727
|
+
return /^\/[^/]+\/[^/]+\/pull\/[1-9][0-9]*$/.test(u.pathname) && !u.search && !u.hash;
|
|
728
|
+
} catch {
|
|
729
|
+
return false;
|
|
730
|
+
}
|
|
731
|
+
});
|
|
732
|
+
function matchesPr(url, repository, number) {
|
|
733
|
+
try {
|
|
734
|
+
const u = new URL(url);
|
|
735
|
+
return u.pathname.toLowerCase() === `/${repository}/pull/${number}`.toLowerCase();
|
|
736
|
+
} catch {
|
|
737
|
+
return false;
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
var HostGitHub = z6.object({ available: z6.boolean(), reason: reason.nullable() }).strict().refine((v) => v.available === (v.reason === null));
|
|
741
|
+
var GitHubCheck = z6.object({
|
|
742
|
+
id: hash,
|
|
743
|
+
name: z6.string().min(1).max(300),
|
|
744
|
+
state: z6.string().min(1).max(100),
|
|
745
|
+
bucket: z6.enum(["pass", "fail", "pending", "skipping", "cancel", "unknown"]),
|
|
746
|
+
link: displayUrl.nullable(),
|
|
747
|
+
workflow: z6.string().max(300).nullable(),
|
|
748
|
+
event: z6.string().max(100).nullable(),
|
|
749
|
+
startedAt: Instant3.nullable(),
|
|
750
|
+
completedAt: Instant3.nullable(),
|
|
751
|
+
description: z6.string().max(2e3).nullable(),
|
|
752
|
+
actionsJob: z6.object({ runId: actionsId, jobId: actionsId, attempt: positive }).strict().nullable()
|
|
753
|
+
}).strict();
|
|
754
|
+
var GitHubComment = z6.object({
|
|
755
|
+
id: Id4,
|
|
756
|
+
author: z6.string().min(1).max(200).nullable(),
|
|
757
|
+
body: z6.string().refine((v) => [...v].length <= 8e3),
|
|
758
|
+
bodyTruncated: z6.boolean(),
|
|
759
|
+
url: githubUrl,
|
|
760
|
+
createdAt: Instant3.nullable()
|
|
761
|
+
}).strict();
|
|
762
|
+
var GitHubThread = z6.object({
|
|
763
|
+
id: Id4,
|
|
764
|
+
isResolved: z6.literal(false),
|
|
765
|
+
isOutdated: z6.boolean(),
|
|
766
|
+
path: z6.string().max(8192).nullable(),
|
|
767
|
+
line: positive.nullable(),
|
|
768
|
+
startLine: positive.nullable(),
|
|
769
|
+
side: z6.enum(["LEFT", "RIGHT"]).nullable(),
|
|
770
|
+
comments: z6.array(GitHubComment).max(10),
|
|
771
|
+
commentsComplete: z6.boolean()
|
|
772
|
+
}).strict();
|
|
773
|
+
var GitHubPullRequest = z6.object({
|
|
774
|
+
nodeId: z6.string().min(1).optional(),
|
|
775
|
+
number: positive,
|
|
776
|
+
url: prUrl,
|
|
777
|
+
title: z6.string().min(1).max(1e3),
|
|
778
|
+
state: z6.enum(["OPEN", "CLOSED", "MERGED"]),
|
|
779
|
+
isDraft: z6.boolean(),
|
|
780
|
+
headRefName: z6.string().min(1).max(255),
|
|
781
|
+
headRefOid: GitHubSha,
|
|
782
|
+
headRepository: GitHubRepository.nullable(),
|
|
783
|
+
baseRefName: z6.string().min(1).max(255),
|
|
784
|
+
mergeable: z6.string().min(1).max(100),
|
|
785
|
+
mergeStateStatus: z6.string().min(1).max(100),
|
|
786
|
+
reviewDecision: z6.enum(["APPROVED", "REVIEW_REQUIRED", "CHANGES_REQUESTED"]).nullable(),
|
|
787
|
+
mergeQueueEnabled: z6.boolean(),
|
|
788
|
+
inMergeQueue: z6.boolean(),
|
|
789
|
+
autoMergeEnabled: z6.boolean(),
|
|
790
|
+
squashMergeAllowed: z6.boolean()
|
|
791
|
+
}).strict().refine((v) => {
|
|
792
|
+
try {
|
|
793
|
+
return new URL(v.url).pathname.endsWith(`/pull/${v.number}`);
|
|
794
|
+
} catch {
|
|
795
|
+
return false;
|
|
796
|
+
}
|
|
797
|
+
});
|
|
798
|
+
var WorkspaceGitHub = z6.object({
|
|
799
|
+
repository: GitHubRepository.nullable(),
|
|
800
|
+
headRepository: GitHubRepository.nullable(),
|
|
801
|
+
branch: z6.string().min(1).max(255).nullable(),
|
|
802
|
+
fetchedAt: Instant3.nullable(),
|
|
803
|
+
attemptedAt: Instant3,
|
|
804
|
+
status: z6.enum(["ready", "unavailable", "error", "ambiguous"]),
|
|
805
|
+
reason: reason.nullable(),
|
|
806
|
+
pullRequest: GitHubPullRequest.nullable(),
|
|
807
|
+
checks: z6.array(GitHubCheck).max(500),
|
|
808
|
+
checksComplete: z6.boolean(),
|
|
809
|
+
threads: z6.array(GitHubThread).max(500),
|
|
810
|
+
threadsComplete: z6.boolean(),
|
|
811
|
+
truncated: z6.boolean()
|
|
812
|
+
}).strict().refine((v) => {
|
|
813
|
+
if (bytes2(JSON.stringify(v)) > 512 * 1024 || new Set(v.checks.map((c) => c.id)).size !== v.checks.length)
|
|
814
|
+
return false;
|
|
815
|
+
if (v.pullRequest && (!v.repository || !matchesPr(v.pullRequest.url, v.repository, v.pullRequest.number)))
|
|
816
|
+
return false;
|
|
817
|
+
if (v.threads.some((t) => !t.commentsComplete || t.comments.some((c) => c.bodyTruncated)) && (v.threadsComplete || !v.truncated))
|
|
818
|
+
return false;
|
|
819
|
+
if (v.status !== "ready")
|
|
820
|
+
return v.reason !== null && !v.checksComplete && !v.threadsComplete;
|
|
821
|
+
return v.reason === null && v.fetchedAt !== null && v.repository !== null && v.headRepository !== null && v.branch !== null && (v.pullRequest !== null || v.checks.length === 0 && v.threads.length === 0 && v.checksComplete && v.threadsComplete);
|
|
822
|
+
});
|
|
823
|
+
var GitHubViewResult = z6.object({ github: HostGitHub, snapshot: WorkspaceGitHub }).strict();
|
|
824
|
+
var GitHubViewResponse = z6.object({ github: HostGitHub.nullable(), snapshot: WorkspaceGitHub.nullable() }).strict();
|
|
825
|
+
function lineCount(s) {
|
|
826
|
+
if (!s)
|
|
827
|
+
return 0;
|
|
828
|
+
const lines = s.replace(/\r\n/g, "\n").split("\n");
|
|
829
|
+
if (lines[lines.length - 1] === "")
|
|
830
|
+
lines.pop();
|
|
831
|
+
return lines.length;
|
|
832
|
+
}
|
|
833
|
+
var GitHubJobLog = z6.object({
|
|
834
|
+
checkId: hash,
|
|
835
|
+
name: z6.string().min(1).max(300),
|
|
836
|
+
url: displayUrl.nullable(),
|
|
837
|
+
runId: actionsId.nullable(),
|
|
838
|
+
jobId: actionsId.nullable(),
|
|
839
|
+
attempt: positive.nullable(),
|
|
840
|
+
status: z6.enum([
|
|
841
|
+
"available",
|
|
842
|
+
"unmapped",
|
|
843
|
+
"incomplete",
|
|
844
|
+
"expired",
|
|
845
|
+
"forbidden",
|
|
846
|
+
"timeout",
|
|
847
|
+
"error"
|
|
848
|
+
]),
|
|
849
|
+
outputTail: z6.string().nullable(),
|
|
850
|
+
lineCount: nonnegative.max(150),
|
|
851
|
+
truncated: z6.boolean(),
|
|
852
|
+
reason: reason.nullable()
|
|
853
|
+
}).strict().refine((v) => v.status === "available" ? v.runId !== null && v.jobId !== null && v.attempt !== null && v.outputTail !== null && bytes2(v.outputTail) <= 65536 && lineCount(v.outputTail) === v.lineCount && v.reason === null : v.outputTail === null && v.lineCount === 0 && v.reason !== null);
|
|
854
|
+
var GitHubLogs = z6.object({
|
|
855
|
+
github: HostGitHub,
|
|
856
|
+
repository: GitHubRepository,
|
|
857
|
+
number: positive,
|
|
858
|
+
headOid: GitHubSha,
|
|
859
|
+
fetchedAt: Instant3,
|
|
860
|
+
status: z6.enum(["ready", "unavailable", "error"]),
|
|
861
|
+
reason: reason.nullable(),
|
|
862
|
+
jobs: z6.array(GitHubJobLog).max(10),
|
|
863
|
+
complete: z6.boolean(),
|
|
864
|
+
truncated: z6.boolean(),
|
|
865
|
+
omittedJobs: nonnegative.nullable()
|
|
866
|
+
}).strict().refine((v) => bytes2(JSON.stringify(v)) <= 1024 * 1024 && (v.status === "ready" ? v.github.available && v.reason === null && (!v.complete || v.omittedJobs === 0 && v.jobs.every((j) => j.status === "available")) : v.reason !== null && v.jobs.length === 0 && !v.complete));
|
|
867
|
+
var GitHubLogsRequest = z6.object({ expectedHeadOid: GitHubSha }).strict();
|
|
868
|
+
var GitHubMergeRequest = z6.object({ expectedHeadOid: GitHubSha }).strict();
|
|
869
|
+
var mergeFields = {
|
|
870
|
+
github: HostGitHub,
|
|
871
|
+
repository: GitHubRepository,
|
|
872
|
+
number: positive,
|
|
873
|
+
url: prUrl,
|
|
874
|
+
expectedHeadOid: GitHubSha
|
|
875
|
+
};
|
|
876
|
+
var GitHubMergeResult = z6.discriminatedUnion("status", [
|
|
877
|
+
z6.object({
|
|
878
|
+
status: z6.literal("merged"),
|
|
879
|
+
...mergeFields,
|
|
880
|
+
mergeCommitOid: GitHubSha.nullable(),
|
|
881
|
+
confirmedAt: Instant3
|
|
882
|
+
}).strict(),
|
|
883
|
+
z6.object({
|
|
884
|
+
status: z6.literal("outcome_unknown"),
|
|
885
|
+
...mergeFields,
|
|
886
|
+
reason,
|
|
887
|
+
attemptedAt: Instant3
|
|
888
|
+
}).strict()
|
|
889
|
+
]).refine((v) => matchesPr(v.url, v.repository, v.number));
|
|
890
|
+
var path = z6.string().min(1).max(8192);
|
|
891
|
+
var GitHubHostViewRequest = z6.object({ path }).strict();
|
|
892
|
+
var GitHubHostLogsRequest = z6.object({ path, repository: GitHubRepository, number: positive, expectedHeadOid: GitHubSha }).strict();
|
|
893
|
+
var GitHubHostMergeRequest = GitHubHostLogsRequest.extend({
|
|
894
|
+
expectedPullRequestNodeId: z6.string().min(1)
|
|
895
|
+
});
|
|
896
|
+
|
|
897
|
+
// packages/protocol/dist/entities.js
|
|
898
|
+
var Iso = z7.string();
|
|
899
|
+
var Id5 = z7.string();
|
|
900
|
+
var Connectivity = z7.enum(["connected", "reconnecting", "unreachable"]);
|
|
901
|
+
var ControlMode = z7.enum(["automation", "human"]);
|
|
902
|
+
var Platform = z7.enum(["darwin", "linux"]);
|
|
903
|
+
var DeviceKind = z7.enum(["browser", "pwa", "terminal", "cli"]);
|
|
904
|
+
var DiagnosticLevel = z7.enum(["info", "warning", "error"]);
|
|
905
|
+
var DEFAULT_WORKTREE_DIR = ".worktrees";
|
|
906
|
+
var CoreCapabilities = z7.object({
|
|
907
|
+
prompt: z7.boolean(),
|
|
908
|
+
steer: z7.boolean(),
|
|
909
|
+
followUp: z7.boolean(),
|
|
910
|
+
abort: z7.boolean(),
|
|
911
|
+
resume: z7.boolean(),
|
|
912
|
+
rename: z7.boolean(),
|
|
913
|
+
importInactive: z7.boolean(),
|
|
914
|
+
extensionDialogs: z7.boolean(),
|
|
915
|
+
customUi: z7.boolean(),
|
|
916
|
+
widgetsText: z7.boolean(),
|
|
917
|
+
widgetsComponent: z7.boolean(),
|
|
918
|
+
tokenAccounting: z7.boolean(),
|
|
919
|
+
costAccounting: z7.boolean()
|
|
920
|
+
});
|
|
921
|
+
var CAPABILITY_KEYS = CoreCapabilities.keyof().options;
|
|
922
|
+
var RuntimeCapabilities = CoreCapabilities.extend({
|
|
923
|
+
/** The host runs sessions as interactive Pi in a terminal that clients can attach to. */
|
|
924
|
+
terminal: z7.boolean().optional(),
|
|
925
|
+
/** The host answers session.models, session.commands, session.setModel, session.setThinking and session.compact. */
|
|
926
|
+
sessionControls: z7.boolean().optional(),
|
|
927
|
+
/** The host answers session.navigate for terminal sessions. */
|
|
928
|
+
treeNavigation: z7.boolean().optional(),
|
|
929
|
+
agentRequests: z7.boolean().optional(),
|
|
930
|
+
messageDelivery: z7.boolean().optional(),
|
|
931
|
+
policies: z7.boolean().optional(),
|
|
932
|
+
unsupported: z7.array(z7.object({ capability: z7.string(), reason: z7.string() }))
|
|
933
|
+
});
|
|
934
|
+
var ProjectScan = z7.object({
|
|
935
|
+
state: z7.enum(["running", "done", "failed"]),
|
|
936
|
+
startedAt: Iso,
|
|
937
|
+
finishedAt: Iso.nullable(),
|
|
938
|
+
/** Repositories found across all folders. */
|
|
939
|
+
repositories: z7.number().int(),
|
|
940
|
+
/** New projects created by this scan. */
|
|
941
|
+
projectsCreated: z7.number().int(),
|
|
942
|
+
/** New checkouts (including the ones of new projects). */
|
|
943
|
+
checkoutsAdded: z7.number().int(),
|
|
944
|
+
/** "<folder>: <message>" per folder that failed; for state "failed", the reason last. */
|
|
945
|
+
errors: z7.array(z7.string())
|
|
946
|
+
});
|
|
947
|
+
var UsageWindow = z7.object({
|
|
948
|
+
id: z7.enum(["five_hour", "weekly"]),
|
|
949
|
+
usedPct: z7.number(),
|
|
950
|
+
resetsAt: Iso.nullable()
|
|
951
|
+
});
|
|
952
|
+
var ProviderUsage = z7.object({
|
|
953
|
+
provider: z7.enum(["anthropic", "openai-codex"]),
|
|
954
|
+
status: z7.enum(["available", "expired", "rejected", "error"]),
|
|
955
|
+
message: z7.string().nullable(),
|
|
956
|
+
windows: z7.array(UsageWindow),
|
|
957
|
+
fetchedAt: Iso
|
|
958
|
+
});
|
|
959
|
+
var Host = z7.object({
|
|
960
|
+
id: Id5,
|
|
961
|
+
name: z7.string(),
|
|
962
|
+
platform: Platform,
|
|
963
|
+
agentVersion: z7.string(),
|
|
964
|
+
piVersion: z7.string().nullable(),
|
|
965
|
+
piCompatible: z7.boolean(),
|
|
966
|
+
capabilities: RuntimeCapabilities.nullable(),
|
|
967
|
+
connectivity: Connectivity,
|
|
968
|
+
lastSeenAt: Iso.nullable(),
|
|
969
|
+
revokedAt: Iso.nullable(),
|
|
970
|
+
createdAt: Iso,
|
|
971
|
+
/** Folders on the host whose git repositories become projects (absolute or ~/...). */
|
|
972
|
+
projectFolders: z7.array(z7.string()).optional(),
|
|
973
|
+
projectScan: ProjectScan.nullable().optional(),
|
|
974
|
+
/** Subscription limits (host-reported, refreshed every few minutes). */
|
|
975
|
+
usage: z7.array(ProviderUsage).optional(),
|
|
976
|
+
github: HostGitHub.optional()
|
|
977
|
+
});
|
|
978
|
+
var WorktreeDir = z7.string().min(1).refine((d) => !d.startsWith("/") && !d.includes("\\"), "must be a relative path").refine((d) => !d.split("/").includes(".."), "must stay inside the repository").refine((d) => d.split("/").every((s) => s.length > 0 && s !== "."), "must be a plain relative path");
|
|
979
|
+
var Project = z7.object({
|
|
980
|
+
id: Id5,
|
|
981
|
+
name: z7.string().min(1),
|
|
982
|
+
repoIdentity: z7.string(),
|
|
983
|
+
defaultProfileId: Id5.nullable(),
|
|
984
|
+
defaultHostId: Id5.nullable(),
|
|
985
|
+
maxConcurrentRuns: z7.number().int().min(1).max(32),
|
|
986
|
+
automationEnabled: z7.boolean(),
|
|
987
|
+
setupCommand: z7.string().nullable(),
|
|
988
|
+
checks: z7.array(z7.string()),
|
|
989
|
+
workspaceSharing: z7.enum(["single_writer", "shared"]),
|
|
990
|
+
worktreeDir: WorktreeDir.default(DEFAULT_WORKTREE_DIR),
|
|
991
|
+
createdAt: Iso,
|
|
992
|
+
updatedAt: Iso
|
|
993
|
+
});
|
|
994
|
+
var Checkout = z7.object({
|
|
995
|
+
id: Id5,
|
|
996
|
+
projectId: Id5,
|
|
997
|
+
hostId: Id5,
|
|
998
|
+
path: z7.string(),
|
|
999
|
+
commonDir: z7.string(),
|
|
1000
|
+
defaultBranch: z7.string(),
|
|
1001
|
+
createdAt: Iso
|
|
1002
|
+
});
|
|
1003
|
+
var GitState = z7.object({
|
|
1004
|
+
dirty: z7.boolean(),
|
|
1005
|
+
changedFiles: z7.number().int(),
|
|
1006
|
+
ahead: z7.number().int(),
|
|
1007
|
+
behind: z7.number().int(),
|
|
1008
|
+
unmerged: z7.boolean()
|
|
1009
|
+
});
|
|
1010
|
+
var Workspace = z7.object({
|
|
1011
|
+
id: Id5,
|
|
1012
|
+
checkoutId: Id5,
|
|
1013
|
+
projectId: Id5,
|
|
1014
|
+
hostId: Id5,
|
|
1015
|
+
path: z7.string(),
|
|
1016
|
+
branch: z7.string().nullable(),
|
|
1017
|
+
baseBranch: z7.string().nullable(),
|
|
1018
|
+
provenance: z7.enum(["managed", "discovered", "main"]),
|
|
1019
|
+
git: GitState,
|
|
1020
|
+
setup: z7.object({
|
|
1021
|
+
state: z7.enum(["none", "running", "succeeded", "failed"]),
|
|
1022
|
+
log: z7.string()
|
|
1023
|
+
}),
|
|
1024
|
+
archivedAt: Iso.nullable(),
|
|
1025
|
+
updatedAt: Iso,
|
|
1026
|
+
github: WorkspaceGitHub.optional()
|
|
1027
|
+
});
|
|
1028
|
+
var ThinkingLevel = z7.enum(["off", "minimal", "low", "medium", "high", "xhigh", "max"]);
|
|
1029
|
+
var SessionModel = z7.object({
|
|
1030
|
+
provider: z7.string(),
|
|
1031
|
+
id: z7.string(),
|
|
1032
|
+
name: z7.string().nullable(),
|
|
1033
|
+
contextWindow: z7.number().nullable(),
|
|
1034
|
+
reasoning: z7.boolean(),
|
|
1035
|
+
/** In Pi's scoped (favorite) model list; set only when Pi has one. */
|
|
1036
|
+
scoped: z7.boolean().optional(),
|
|
1037
|
+
/** Effort levels this model accepts, in Pi's order; ["off"] without reasoning. */
|
|
1038
|
+
thinkingLevels: z7.array(ThinkingLevel),
|
|
1039
|
+
/** Prompt-cache lifetimes in seconds from Pi's model metadata. */
|
|
1040
|
+
promptCache: z7.object({ short: z7.number().optional(), long: z7.number().optional() }).nullable().optional()
|
|
1041
|
+
});
|
|
1042
|
+
var SlashCommand = z7.object({
|
|
1043
|
+
name: z7.string().min(1),
|
|
1044
|
+
description: z7.string().nullable(),
|
|
1045
|
+
source: z7.enum(["extension", "prompt", "skill"]),
|
|
1046
|
+
argumentHint: z7.string().nullable().optional()
|
|
1047
|
+
});
|
|
1048
|
+
var ContextUsage = z7.object({
|
|
1049
|
+
/** Estimated tokens in context; null right after compaction until the next reply. */
|
|
1050
|
+
tokens: z7.number().nullable(),
|
|
1051
|
+
window: z7.number(),
|
|
1052
|
+
percent: z7.number().nullable()
|
|
1053
|
+
});
|
|
1054
|
+
var FORBIDDEN_EXTRA_ARGS = ["--mode", "--fork", "--no-session", "-e", "--extension"];
|
|
1055
|
+
var ExtraArg = z7.string().refine((a) => a.startsWith("--") || !a.startsWith("-"), "extra args must be long flags").refine((a) => !FORBIDDEN_EXTRA_ARGS.includes(a.split("=")[0]) && !a.startsWith("--session"), "this flag is managed by Switchyard");
|
|
1056
|
+
var Profile = z7.object({
|
|
1057
|
+
id: Id5,
|
|
1058
|
+
name: z7.string().min(1),
|
|
1059
|
+
provider: z7.string().nullable(),
|
|
1060
|
+
model: z7.string().nullable(),
|
|
1061
|
+
thinking: ThinkingLevel.nullable(),
|
|
1062
|
+
projectTrust: z7.enum(["ask", "approve", "ignore"]),
|
|
1063
|
+
extraArgs: z7.array(ExtraArg),
|
|
1064
|
+
/** "vanilla": --no-extensions --no-skills --no-prompt-templates. Undefined means "all". */
|
|
1065
|
+
resources: z7.enum(["all", "vanilla"]).optional()
|
|
1066
|
+
});
|
|
1067
|
+
var ViewClient = z7.object({
|
|
1068
|
+
/** `${kind}:${name}@${machine}` */
|
|
1069
|
+
id: z7.string().min(1),
|
|
1070
|
+
kind: z7.enum(["herdr", "tmux"]),
|
|
1071
|
+
name: z7.string().min(1),
|
|
1072
|
+
machine: z7.string().min(1),
|
|
1073
|
+
lastSeenAt: Iso
|
|
1074
|
+
});
|
|
1075
|
+
var View = z7.object({
|
|
1076
|
+
id: Id5,
|
|
1077
|
+
name: z7.string().min(1).max(60),
|
|
1078
|
+
mode: z7.enum(["all", "pinned"]),
|
|
1079
|
+
projectIds: z7.array(z7.string()).nullable(),
|
|
1080
|
+
hostIds: z7.array(z7.string()).nullable(),
|
|
1081
|
+
sessionIds: z7.array(z7.string()),
|
|
1082
|
+
clients: z7.array(ViewClient),
|
|
1083
|
+
createdAt: Iso,
|
|
1084
|
+
updatedAt: Iso
|
|
1085
|
+
});
|
|
1086
|
+
var RuntimeState = z7.enum([
|
|
1087
|
+
"starting",
|
|
1088
|
+
"idle",
|
|
1089
|
+
"running",
|
|
1090
|
+
"waiting_input",
|
|
1091
|
+
"interrupted",
|
|
1092
|
+
"failed",
|
|
1093
|
+
"stopped"
|
|
1094
|
+
]);
|
|
1095
|
+
var NativeHandle = z7.object({ sessionId: z7.string(), sessionFile: z7.string() });
|
|
1096
|
+
var SessionStats = z7.object({
|
|
1097
|
+
tokens: z7.number().nullable(),
|
|
1098
|
+
costUsd: z7.number().nullable(),
|
|
1099
|
+
/** Completed usage, refreshed for this exact settlement; absent on older hosts or failure. */
|
|
1100
|
+
watermark: CompletedUsageWatermark.optional(),
|
|
1101
|
+
context: ContextUsage.nullable().optional()
|
|
1102
|
+
});
|
|
1103
|
+
var PromptCacheInfo = z7.object({
|
|
1104
|
+
at: Iso,
|
|
1105
|
+
provider: z7.string(),
|
|
1106
|
+
model: z7.string(),
|
|
1107
|
+
cacheRead: z7.number(),
|
|
1108
|
+
cacheWrite: z7.number(),
|
|
1109
|
+
cacheWrite1h: z7.number()
|
|
1110
|
+
});
|
|
1111
|
+
var Session = z7.object({
|
|
1112
|
+
id: Id5,
|
|
1113
|
+
title: z7.string(),
|
|
1114
|
+
subtitle: z7.string().nullable(),
|
|
1115
|
+
hostId: Id5,
|
|
1116
|
+
workspaceId: Id5.nullable(),
|
|
1117
|
+
projectId: Id5.nullable(),
|
|
1118
|
+
cwd: z7.string(),
|
|
1119
|
+
nativeHandle: NativeHandle.nullable(),
|
|
1120
|
+
profileSnapshot: Profile,
|
|
1121
|
+
runtime: RuntimeState,
|
|
1122
|
+
runtimeDetail: z7.string().nullable(),
|
|
1123
|
+
connectivity: Connectivity,
|
|
1124
|
+
runId: Id5.nullable(),
|
|
1125
|
+
taskId: Id5.nullable(),
|
|
1126
|
+
provenance: z7.enum(["created", "imported", "subagent"]),
|
|
1127
|
+
readOnly: z7.boolean(),
|
|
1128
|
+
lastActivityAt: Iso,
|
|
1129
|
+
archivedAt: Iso.nullable(),
|
|
1130
|
+
queue: z7.object({ steering: z7.array(z7.string()), followUp: z7.array(z7.string()) }),
|
|
1131
|
+
stats: SessionStats.nullable(),
|
|
1132
|
+
/** The live model (host-owned; last known when stopped). */
|
|
1133
|
+
model: SessionModel.nullable().optional(),
|
|
1134
|
+
/** The live effort (Pi's thinking level). */
|
|
1135
|
+
thinking: ThinkingLevel.nullable().optional(),
|
|
1136
|
+
/** Pi is compacting the context. */
|
|
1137
|
+
compacting: z7.boolean().optional(),
|
|
1138
|
+
lastAssistantText: z7.string().nullable(),
|
|
1139
|
+
createdAt: Iso,
|
|
1140
|
+
/** A live terminal session: `switchyard tui` can attach to its Pi terminal. */
|
|
1141
|
+
terminal: z7.boolean().optional(),
|
|
1142
|
+
/** Set when the session finished or failed with nobody viewing it; cleared when viewed (coordinator-owned). */
|
|
1143
|
+
unreadSince: Iso.nullable().optional(),
|
|
1144
|
+
/** Bumped when the transcript is rebuilt (rewind); clients drop cached copies (coordinator-owned). */
|
|
1145
|
+
transcriptEpoch: z7.number().int().min(0).optional(),
|
|
1146
|
+
bridge: z7.object({
|
|
1147
|
+
version: z7.literal(1),
|
|
1148
|
+
runtimeId: Id5,
|
|
1149
|
+
nativeSessionId: Id5,
|
|
1150
|
+
/** Host-generated local-controller identity, not Pi's private binding credential. */
|
|
1151
|
+
controllerEpoch: Id5.optional(),
|
|
1152
|
+
agentTools: z7.boolean(),
|
|
1153
|
+
messageDelivery: z7.boolean(),
|
|
1154
|
+
policyState: z7.enum(["initializing", "active", "unsupported", "lost"]),
|
|
1155
|
+
policyPhases: z7.array(PolicyPhase)
|
|
1156
|
+
}).optional(),
|
|
1157
|
+
/** Last assistant message's cache usage (host-owned). */
|
|
1158
|
+
promptCache: PromptCacheInfo.nullable().optional(),
|
|
1159
|
+
/** Warn before the prompt cache expires; non-null means on (coordinator-owned). */
|
|
1160
|
+
cacheAlert: z7.object({ ttlSec: z7.number().int().min(60).max(86400).nullable(), warnedFor: Iso.nullable() }).nullable().optional()
|
|
1161
|
+
});
|
|
1162
|
+
var ContinuationPolicy = z7.discriminatedUnion("enabled", [
|
|
1163
|
+
z7.object({ enabled: z7.literal(false) }),
|
|
1164
|
+
z7.object({
|
|
1165
|
+
enabled: z7.literal(true),
|
|
1166
|
+
objective: z7.string().min(1),
|
|
1167
|
+
maxContinuations: z7.number().int().min(1).max(50),
|
|
1168
|
+
maxElapsedMinutes: z7.number().int().min(1).max(1440),
|
|
1169
|
+
maxTokens: z7.number().int().positive().nullable(),
|
|
1170
|
+
maxCostUsd: z7.number().positive().nullable()
|
|
1171
|
+
})
|
|
1172
|
+
]);
|
|
1173
|
+
var CompletionPolicy = z7.object({
|
|
1174
|
+
checks: z7.array(z7.string()).nullable(),
|
|
1175
|
+
requireHumanReview: z7.boolean()
|
|
1176
|
+
});
|
|
1177
|
+
var WorkspacePolicy = z7.discriminatedUnion("mode", [
|
|
1178
|
+
z7.object({
|
|
1179
|
+
mode: z7.literal("new_worktree"),
|
|
1180
|
+
branch: z7.string().nullable(),
|
|
1181
|
+
base: z7.string().nullable()
|
|
1182
|
+
}),
|
|
1183
|
+
z7.object({ mode: z7.literal("existing"), workspaceId: Id5 })
|
|
1184
|
+
]);
|
|
1185
|
+
var TaskPolicy = z7.object({
|
|
1186
|
+
hostId: Id5.nullable(),
|
|
1187
|
+
profileId: Id5.nullable(),
|
|
1188
|
+
workspace: WorkspacePolicy,
|
|
1189
|
+
continuation: ContinuationPolicy,
|
|
1190
|
+
completion: CompletionPolicy
|
|
1191
|
+
});
|
|
1192
|
+
var TaskState = z7.enum(["backlog", "ready", "in_progress", "review", "done", "canceled"]);
|
|
1193
|
+
var Priority = z7.union([z7.literal(0), z7.literal(1), z7.literal(2), z7.literal(3)]);
|
|
1194
|
+
var TaskOrigin = z7.discriminatedUnion("kind", [
|
|
1195
|
+
z7.object({ kind: z7.literal("manual") }),
|
|
1196
|
+
z7.object({
|
|
1197
|
+
kind: z7.literal("automation"),
|
|
1198
|
+
automationId: Id5,
|
|
1199
|
+
occurrenceId: Id5,
|
|
1200
|
+
routine: z7.boolean()
|
|
1201
|
+
})
|
|
1202
|
+
]);
|
|
1203
|
+
var Task = z7.object({
|
|
1204
|
+
id: Id5,
|
|
1205
|
+
projectId: Id5,
|
|
1206
|
+
title: z7.string().min(1),
|
|
1207
|
+
objective: z7.string(),
|
|
1208
|
+
acceptanceCriteria: z7.array(z7.string()),
|
|
1209
|
+
dependencies: z7.array(Id5),
|
|
1210
|
+
priority: Priority,
|
|
1211
|
+
position: z7.number(),
|
|
1212
|
+
state: TaskState,
|
|
1213
|
+
blocked: z7.object({ reason: z7.string() }).nullable(),
|
|
1214
|
+
notBefore: Iso.nullable(),
|
|
1215
|
+
policy: TaskPolicy,
|
|
1216
|
+
origin: TaskOrigin,
|
|
1217
|
+
groupingKey: z7.string().nullable(),
|
|
1218
|
+
parentTaskId: Id5.nullable().optional(),
|
|
1219
|
+
agentOrigin: z7.object({ sessionId: Id5, toolCallId: Id5 }).optional(),
|
|
1220
|
+
githubIssue: GitHubIssue.optional(),
|
|
1221
|
+
currentRunId: Id5.nullable(),
|
|
1222
|
+
sessionId: Id5.nullable(),
|
|
1223
|
+
review: z7.object({ feedback: z7.array(z7.string()), changesRequested: z7.boolean() }),
|
|
1224
|
+
hiddenFromBoard: z7.boolean(),
|
|
1225
|
+
lastActivityAt: Iso,
|
|
1226
|
+
createdAt: Iso,
|
|
1227
|
+
updatedAt: Iso
|
|
1228
|
+
});
|
|
1229
|
+
var RunState = z7.enum([
|
|
1230
|
+
"queued",
|
|
1231
|
+
"dispatching",
|
|
1232
|
+
"uncertain",
|
|
1233
|
+
"running",
|
|
1234
|
+
"waiting_input",
|
|
1235
|
+
"checking",
|
|
1236
|
+
"succeeded",
|
|
1237
|
+
"failed",
|
|
1238
|
+
"interrupted",
|
|
1239
|
+
"canceled"
|
|
1240
|
+
]);
|
|
1241
|
+
var CheckResult = z7.object({
|
|
1242
|
+
command: z7.string(),
|
|
1243
|
+
exitCode: z7.number().int().nullable(),
|
|
1244
|
+
outputTail: z7.string()
|
|
1245
|
+
});
|
|
1246
|
+
var Run = z7.object({
|
|
1247
|
+
id: Id5,
|
|
1248
|
+
taskId: Id5,
|
|
1249
|
+
sessionId: Id5.nullable(),
|
|
1250
|
+
hostId: Id5.nullable(),
|
|
1251
|
+
dispatchKey: z7.string(),
|
|
1252
|
+
attempt: z7.number().int().min(1),
|
|
1253
|
+
state: RunState,
|
|
1254
|
+
controlMode: ControlMode,
|
|
1255
|
+
controlRevision: z7.number().int().min(1),
|
|
1256
|
+
continuationsUsed: z7.number().int().min(0),
|
|
1257
|
+
infraRetries: z7.number().int().min(0),
|
|
1258
|
+
nextAttemptAt: Iso.nullable(),
|
|
1259
|
+
startedAt: Iso.nullable(),
|
|
1260
|
+
endedAt: Iso.nullable(),
|
|
1261
|
+
outcome: z7.object({
|
|
1262
|
+
kind: z7.enum(["review", "failed", "blocked", "no_change", "canceled"]),
|
|
1263
|
+
summary: z7.string()
|
|
1264
|
+
}).nullable(),
|
|
1265
|
+
limits: ContinuationPolicy,
|
|
1266
|
+
usage: z7.object({
|
|
1267
|
+
tokens: z7.number().nullable(),
|
|
1268
|
+
costUsd: z7.number().nullable(),
|
|
1269
|
+
accounting: z7.enum(["available", "unavailable"]),
|
|
1270
|
+
note: z7.string().nullable()
|
|
1271
|
+
}),
|
|
1272
|
+
checks: z7.array(CheckResult),
|
|
1273
|
+
createdAt: Iso,
|
|
1274
|
+
updatedAt: Iso
|
|
1275
|
+
});
|
|
1276
|
+
var Trigger = z7.discriminatedUnion("kind", [
|
|
1277
|
+
z7.object({ kind: z7.literal("manual") }),
|
|
1278
|
+
z7.object({ kind: z7.literal("once"), at: Iso }),
|
|
1279
|
+
z7.object({ kind: z7.literal("cron"), expr: z7.string().min(1), timezone: z7.string().min(1) }),
|
|
1280
|
+
z7.object({ kind: z7.literal("webhook") }),
|
|
1281
|
+
z7.object({ kind: z7.literal("dependency"), taskId: Id5 })
|
|
1282
|
+
]);
|
|
1283
|
+
var TaskTemplate = z7.object({
|
|
1284
|
+
title: z7.string().min(1),
|
|
1285
|
+
objective: z7.string(),
|
|
1286
|
+
acceptanceCriteria: z7.array(z7.string()),
|
|
1287
|
+
priority: Priority
|
|
1288
|
+
});
|
|
1289
|
+
var Automation = z7.object({
|
|
1290
|
+
id: Id5,
|
|
1291
|
+
name: z7.string().min(1),
|
|
1292
|
+
enabled: z7.boolean(),
|
|
1293
|
+
projectId: Id5,
|
|
1294
|
+
trigger: Trigger,
|
|
1295
|
+
filters: z7.array(z7.object({ path: z7.string(), equals: z7.string() })),
|
|
1296
|
+
template: TaskTemplate,
|
|
1297
|
+
hostId: Id5.nullable(),
|
|
1298
|
+
profileId: Id5.nullable(),
|
|
1299
|
+
mode: z7.enum(["fresh", "continue", "watch"]),
|
|
1300
|
+
groupingKey: z7.string().nullable(),
|
|
1301
|
+
overlap: z7.enum(["skip", "queue_one", "append"]),
|
|
1302
|
+
missed: z7.enum(["skip", "run_once"]),
|
|
1303
|
+
continuation: ContinuationPolicy,
|
|
1304
|
+
completion: CompletionPolicy,
|
|
1305
|
+
nextAt: Iso.nullable(),
|
|
1306
|
+
lastEvaluatedAt: Iso.nullable(),
|
|
1307
|
+
lastOutcome: z7.string().nullable(),
|
|
1308
|
+
failureCount: z7.number().int().min(0),
|
|
1309
|
+
webhookTokenSet: z7.boolean(),
|
|
1310
|
+
createdAt: Iso,
|
|
1311
|
+
updatedAt: Iso
|
|
1312
|
+
});
|
|
1313
|
+
var OccurrenceState = z7.enum([
|
|
1314
|
+
"fired",
|
|
1315
|
+
"skipped_overlap",
|
|
1316
|
+
"skipped_missed",
|
|
1317
|
+
"queued",
|
|
1318
|
+
"appended",
|
|
1319
|
+
"failed",
|
|
1320
|
+
"filtered"
|
|
1321
|
+
]);
|
|
1322
|
+
var Occurrence = z7.object({
|
|
1323
|
+
id: Id5,
|
|
1324
|
+
automationId: Id5,
|
|
1325
|
+
key: z7.string(),
|
|
1326
|
+
scheduledFor: Iso.nullable(),
|
|
1327
|
+
state: OccurrenceState,
|
|
1328
|
+
taskId: Id5.nullable(),
|
|
1329
|
+
reason: z7.string().nullable(),
|
|
1330
|
+
outcome: z7.string().nullable(),
|
|
1331
|
+
createdAt: Iso
|
|
1332
|
+
});
|
|
1333
|
+
var InteractionState = z7.preprocess((v) => v === "cancelled" ? "canceled" : v, z7.enum(["pending", "resolved", "expired", "canceled", "unsupported"]));
|
|
1334
|
+
var Interaction = z7.object({
|
|
1335
|
+
id: Id5,
|
|
1336
|
+
sessionId: Id5,
|
|
1337
|
+
revision: z7.number().int().min(1),
|
|
1338
|
+
source: z7.discriminatedUnion("kind", [
|
|
1339
|
+
z7.object({
|
|
1340
|
+
kind: z7.literal("extension_ui"),
|
|
1341
|
+
method: z7.enum(["select", "confirm", "input", "editor"]),
|
|
1342
|
+
piRequestIds: z7.array(z7.string())
|
|
1343
|
+
}),
|
|
1344
|
+
z7.object({ kind: z7.literal("unsupported_custom"), title: z7.string().nullable() })
|
|
1345
|
+
]),
|
|
1346
|
+
adapterId: z7.string().nullable(),
|
|
1347
|
+
permission: PolicyPermission.optional(),
|
|
1348
|
+
title: z7.string(),
|
|
1349
|
+
presentation: UINodeSchema,
|
|
1350
|
+
state: InteractionState,
|
|
1351
|
+
resolution: z7.object({ by: z7.string(), summary: z7.string(), at: Iso }).nullable(),
|
|
1352
|
+
createdAt: Iso
|
|
1353
|
+
});
|
|
1354
|
+
var AttentionReason = z7.enum([
|
|
1355
|
+
"needs_input",
|
|
1356
|
+
"failed",
|
|
1357
|
+
"ready_for_review",
|
|
1358
|
+
"unsupported_interaction",
|
|
1359
|
+
"host_unreachable",
|
|
1360
|
+
"cache_expiring"
|
|
1361
|
+
]);
|
|
1362
|
+
var AttentionItem = z7.object({
|
|
1363
|
+
id: Id5,
|
|
1364
|
+
sessionId: Id5.nullable(),
|
|
1365
|
+
taskId: Id5.nullable(),
|
|
1366
|
+
projectId: Id5.nullable(),
|
|
1367
|
+
reason: AttentionReason,
|
|
1368
|
+
severity: z7.enum(["info", "warning", "critical"]),
|
|
1369
|
+
summary: z7.string(),
|
|
1370
|
+
interactionId: Id5.nullable(),
|
|
1371
|
+
deepLink: z7.string(),
|
|
1372
|
+
acknowledgedAt: Iso.nullable(),
|
|
1373
|
+
resolvedAt: Iso.nullable(),
|
|
1374
|
+
createdAt: Iso
|
|
1375
|
+
});
|
|
1376
|
+
var Device = z7.object({
|
|
1377
|
+
id: Id5,
|
|
1378
|
+
name: z7.string(),
|
|
1379
|
+
kind: DeviceKind,
|
|
1380
|
+
createdAt: Iso,
|
|
1381
|
+
lastSeenAt: Iso.nullable(),
|
|
1382
|
+
revokedAt: Iso.nullable(),
|
|
1383
|
+
push: z7.object({
|
|
1384
|
+
subscribed: z7.boolean(),
|
|
1385
|
+
permission: z7.enum(["granted", "denied", "default", "unknown"])
|
|
1386
|
+
}),
|
|
1387
|
+
preferredMobile: z7.boolean(),
|
|
1388
|
+
enrolledVia: z7.enum(["enrollment", "passkey", "oidc", "admin", "approval"]).default("enrollment")
|
|
1389
|
+
});
|
|
1390
|
+
var ToolItemData = z7.object({
|
|
1391
|
+
toolCallId: z7.string(),
|
|
1392
|
+
name: z7.string(),
|
|
1393
|
+
status: z7.enum(["running", "ok", "error"]),
|
|
1394
|
+
args: z7.unknown(),
|
|
1395
|
+
summary: z7.string(),
|
|
1396
|
+
output: z7.string(),
|
|
1397
|
+
startedAt: Iso,
|
|
1398
|
+
durationMs: z7.number().nullable(),
|
|
1399
|
+
card: UINodeSchema.nullable(),
|
|
1400
|
+
adapterId: z7.string().nullable()
|
|
1401
|
+
});
|
|
1402
|
+
var TranscriptItem = z7.discriminatedUnion("kind", [
|
|
1403
|
+
z7.object({
|
|
1404
|
+
id: Id5,
|
|
1405
|
+
sessionId: Id5,
|
|
1406
|
+
order: z7.number().int(),
|
|
1407
|
+
at: Iso,
|
|
1408
|
+
kind: z7.literal("user"),
|
|
1409
|
+
data: z7.object({
|
|
1410
|
+
text: z7.string(),
|
|
1411
|
+
images: z7.number().int().optional(),
|
|
1412
|
+
/** Pi session entry id, for rewind and fork from this message. */
|
|
1413
|
+
entryId: z7.string().optional()
|
|
1414
|
+
})
|
|
1415
|
+
}),
|
|
1416
|
+
z7.object({
|
|
1417
|
+
id: Id5,
|
|
1418
|
+
sessionId: Id5,
|
|
1419
|
+
order: z7.number().int(),
|
|
1420
|
+
at: Iso,
|
|
1421
|
+
kind: z7.literal("assistant"),
|
|
1422
|
+
data: z7.object({ text: z7.string(), streaming: z7.boolean().optional() })
|
|
1423
|
+
}),
|
|
1424
|
+
z7.object({
|
|
1425
|
+
id: Id5,
|
|
1426
|
+
sessionId: Id5,
|
|
1427
|
+
order: z7.number().int(),
|
|
1428
|
+
at: Iso,
|
|
1429
|
+
kind: z7.literal("thinking"),
|
|
1430
|
+
data: z7.object({ text: z7.string() })
|
|
1431
|
+
}),
|
|
1432
|
+
z7.object({
|
|
1433
|
+
id: Id5,
|
|
1434
|
+
sessionId: Id5,
|
|
1435
|
+
order: z7.number().int(),
|
|
1436
|
+
at: Iso,
|
|
1437
|
+
kind: z7.literal("tool"),
|
|
1438
|
+
data: ToolItemData
|
|
1439
|
+
}),
|
|
1440
|
+
z7.object({
|
|
1441
|
+
id: Id5,
|
|
1442
|
+
sessionId: Id5,
|
|
1443
|
+
order: z7.number().int(),
|
|
1444
|
+
at: Iso,
|
|
1445
|
+
kind: z7.literal("notice"),
|
|
1446
|
+
data: z7.object({
|
|
1447
|
+
level: DiagnosticLevel,
|
|
1448
|
+
text: z7.string(),
|
|
1449
|
+
customType: z7.string().min(1).max(200).optional(),
|
|
1450
|
+
card: UINodeSchema.optional(),
|
|
1451
|
+
adapterId: z7.string().optional()
|
|
1452
|
+
}).refine((data) => !data.card || !!data.adapterId, "Card requires adapterId")
|
|
1453
|
+
}),
|
|
1454
|
+
z7.object({
|
|
1455
|
+
id: Id5,
|
|
1456
|
+
sessionId: Id5,
|
|
1457
|
+
order: z7.number().int(),
|
|
1458
|
+
at: Iso,
|
|
1459
|
+
kind: z7.literal("interaction"),
|
|
1460
|
+
data: z7.object({ interactionId: Id5 })
|
|
1461
|
+
}),
|
|
1462
|
+
z7.object({
|
|
1463
|
+
id: Id5,
|
|
1464
|
+
sessionId: Id5,
|
|
1465
|
+
order: z7.number().int(),
|
|
1466
|
+
at: Iso,
|
|
1467
|
+
kind: z7.literal("subagent"),
|
|
1468
|
+
data: z7.object({
|
|
1469
|
+
runId: z7.string(),
|
|
1470
|
+
label: z7.string(),
|
|
1471
|
+
status: z7.string(),
|
|
1472
|
+
sessionFile: z7.string().nullable(),
|
|
1473
|
+
linkedSessionId: Id5.nullable()
|
|
1474
|
+
})
|
|
1475
|
+
}),
|
|
1476
|
+
z7.object({
|
|
1477
|
+
id: Id5,
|
|
1478
|
+
sessionId: Id5,
|
|
1479
|
+
order: z7.number().int(),
|
|
1480
|
+
at: Iso,
|
|
1481
|
+
kind: z7.literal("system"),
|
|
1482
|
+
data: z7.object({ text: z7.string(), suggestion: z7.boolean().optional() })
|
|
1483
|
+
})
|
|
1484
|
+
]);
|
|
1485
|
+
var Panel = z7.object({
|
|
1486
|
+
sessionId: Id5,
|
|
1487
|
+
adapterId: z7.string(),
|
|
1488
|
+
slot: z7.string(),
|
|
1489
|
+
title: z7.string(),
|
|
1490
|
+
node: UINodeSchema.nullable(),
|
|
1491
|
+
webRenderer: z7.boolean(),
|
|
1492
|
+
mobileFallback: z7.string().nullable(),
|
|
1493
|
+
contribution: ContributionDescriptor.optional(),
|
|
1494
|
+
state: z7.unknown().optional(),
|
|
1495
|
+
updatedAt: Iso
|
|
1496
|
+
});
|
|
1497
|
+
var Diagnostic = z7.object({
|
|
1498
|
+
sessionId: Id5.nullable(),
|
|
1499
|
+
adapterId: z7.string().nullable(),
|
|
1500
|
+
level: DiagnosticLevel,
|
|
1501
|
+
message: z7.string(),
|
|
1502
|
+
at: Iso
|
|
1503
|
+
});
|
|
1504
|
+
var AdapterInfo = z7.object({
|
|
1505
|
+
id: z7.string(),
|
|
1506
|
+
version: z7.string(),
|
|
1507
|
+
tier: z7.enum(["project", "owner", "plugin", "bundled"]),
|
|
1508
|
+
target: z7.object({
|
|
1509
|
+
extension: z7.string(),
|
|
1510
|
+
versionRange: z7.string(),
|
|
1511
|
+
testedVersions: z7.array(z7.string())
|
|
1512
|
+
}),
|
|
1513
|
+
capabilities: z7.array(z7.string()),
|
|
1514
|
+
webRenderer: z7.boolean(),
|
|
1515
|
+
status: z7.enum(["active", "disabled", "error"]),
|
|
1516
|
+
detail: z7.string().nullable()
|
|
1517
|
+
});
|
|
1518
|
+
var Passkey = z7.object({
|
|
1519
|
+
id: z7.string(),
|
|
1520
|
+
name: z7.string(),
|
|
1521
|
+
createdAt: Iso,
|
|
1522
|
+
lastUsedAt: Iso.nullable(),
|
|
1523
|
+
transports: z7.array(z7.string())
|
|
1524
|
+
});
|
|
1525
|
+
|
|
1526
|
+
// packages/protocol/dist/host-wire.js
|
|
1527
|
+
import { z as z10 } from "zod";
|
|
1528
|
+
|
|
1529
|
+
// packages/protocol/dist/events.js
|
|
1530
|
+
import { z as z8 } from "zod";
|
|
1531
|
+
var EventDataSchemas = {
|
|
1532
|
+
"host.updated": Host,
|
|
1533
|
+
"project.updated": Project,
|
|
1534
|
+
"project.deleted": z8.object({ id: z8.string() }),
|
|
1535
|
+
"checkout.updated": Checkout,
|
|
1536
|
+
"workspace.updated": Workspace,
|
|
1537
|
+
"workspace.deleted": z8.object({ id: z8.string() }),
|
|
1538
|
+
"profile.updated": Profile,
|
|
1539
|
+
"profile.deleted": z8.object({ id: z8.string() }),
|
|
1540
|
+
"view.updated": View,
|
|
1541
|
+
"view.deleted": z8.object({ id: z8.string() }),
|
|
1542
|
+
"session.updated": Session,
|
|
1543
|
+
"transcript.item": TranscriptItem,
|
|
1544
|
+
"transcript.reset": z8.object({ sessionId: z8.string(), epoch: z8.number().int() }),
|
|
1545
|
+
"interaction.updated": Interaction,
|
|
1546
|
+
"panel.updated": Panel,
|
|
1547
|
+
"adapters.updated": z8.object({ hostId: z8.string(), adapters: z8.array(AdapterInfo) }),
|
|
1548
|
+
diagnostic: Diagnostic,
|
|
1549
|
+
"task.updated": Task,
|
|
1550
|
+
"task.deleted": z8.object({ id: z8.string() }),
|
|
1551
|
+
"run.updated": Run,
|
|
1552
|
+
"automation.updated": Automation,
|
|
1553
|
+
"automation.deleted": z8.object({ id: z8.string() }),
|
|
1554
|
+
"occurrence.created": Occurrence,
|
|
1555
|
+
"occurrence.updated": Occurrence,
|
|
1556
|
+
"attention.updated": AttentionItem,
|
|
1557
|
+
"device.updated": Device,
|
|
1558
|
+
"settings.updated": z8.object({ dispatchPaused: z8.boolean() })
|
|
1559
|
+
};
|
|
1560
|
+
var EVENT_TYPES = Object.keys(EventDataSchemas);
|
|
1561
|
+
var LEGACY_EVENT_TYPES = {
|
|
1562
|
+
"workspace.removed": "workspace.deleted"
|
|
1563
|
+
};
|
|
1564
|
+
function canonicalEventType(type) {
|
|
1565
|
+
return LEGACY_EVENT_TYPES[type] ?? type;
|
|
1566
|
+
}
|
|
1567
|
+
var canonical = (v) => typeof v === "string" ? canonicalEventType(v) : v;
|
|
1568
|
+
var EventTypeSchema = z8.preprocess(canonical, z8.enum(EVENT_TYPES));
|
|
1569
|
+
var EventScope = z8.object({
|
|
1570
|
+
hostId: z8.string().optional(),
|
|
1571
|
+
sessionId: z8.string().optional(),
|
|
1572
|
+
taskId: z8.string().optional(),
|
|
1573
|
+
projectId: z8.string().optional()
|
|
1574
|
+
});
|
|
1575
|
+
var EventEnvelope = EventScope.extend({
|
|
1576
|
+
seq: z8.number().int(),
|
|
1577
|
+
id: z8.string(),
|
|
1578
|
+
type: EventTypeSchema,
|
|
1579
|
+
at: z8.string(),
|
|
1580
|
+
data: z8.unknown()
|
|
1581
|
+
});
|
|
1582
|
+
var HOST_EVENT_TYPES = [
|
|
1583
|
+
"session.updated",
|
|
1584
|
+
"transcript.item",
|
|
1585
|
+
"interaction.updated",
|
|
1586
|
+
"panel.updated",
|
|
1587
|
+
"adapters.updated",
|
|
1588
|
+
"diagnostic",
|
|
1589
|
+
"workspace.updated",
|
|
1590
|
+
"workspace.deleted"
|
|
1591
|
+
];
|
|
1592
|
+
var HostEvent = EventScope.extend({
|
|
1593
|
+
eventId: z8.string(),
|
|
1594
|
+
type: z8.preprocess(canonical, z8.enum(HOST_EVENT_TYPES)),
|
|
1595
|
+
at: z8.string(),
|
|
1596
|
+
data: z8.unknown()
|
|
1597
|
+
});
|
|
1598
|
+
var StreamDelta = z8.object({
|
|
1599
|
+
sessionId: z8.string(),
|
|
1600
|
+
itemId: z8.string(),
|
|
1601
|
+
kind: z8.enum(["text", "thinking", "tool_args", "tool_output"]),
|
|
1602
|
+
delta: z8.string(),
|
|
1603
|
+
order: z8.number().int().optional()
|
|
1604
|
+
});
|
|
1605
|
+
|
|
1606
|
+
// packages/protocol/dist/terminal-wire.js
|
|
1607
|
+
import { z as z9 } from "zod";
|
|
1608
|
+
var Cols = z9.number().int().min(10).max(1e3);
|
|
1609
|
+
var Rows = z9.number().int().min(5).max(500);
|
|
1610
|
+
var TermViewerToServer = z9.discriminatedUnion("t", [
|
|
1611
|
+
z9.object({ t: z9.literal("in"), d: z9.string() }),
|
|
1612
|
+
z9.object({ t: z9.literal("resize"), cols: Cols, rows: Rows }),
|
|
1613
|
+
z9.object({ t: z9.literal("claim") })
|
|
1614
|
+
]);
|
|
1615
|
+
var TermServerToViewer = z9.discriminatedUnion("t", [
|
|
1616
|
+
z9.object({ t: z9.literal("out"), d: z9.string() }),
|
|
1617
|
+
z9.object({ t: z9.literal("closed"), reason: z9.string() }),
|
|
1618
|
+
z9.object({ t: z9.literal("size"), cols: Cols, rows: Rows, owner: z9.boolean() })
|
|
1619
|
+
]);
|
|
1620
|
+
var TermCoordinatorMsg = z9.discriminatedUnion("t", [
|
|
1621
|
+
z9.object({
|
|
1622
|
+
t: z9.literal("open"),
|
|
1623
|
+
sessionId: z9.string(),
|
|
1624
|
+
cols: Cols,
|
|
1625
|
+
rows: Rows,
|
|
1626
|
+
passive: z9.boolean().optional()
|
|
1627
|
+
}),
|
|
1628
|
+
z9.object({ t: z9.literal("claim") }),
|
|
1629
|
+
z9.object({ t: z9.literal("in"), d: z9.string() }),
|
|
1630
|
+
z9.object({ t: z9.literal("resize"), cols: Cols, rows: Rows }),
|
|
1631
|
+
z9.object({ t: z9.literal("close") })
|
|
1632
|
+
]);
|
|
1633
|
+
|
|
1634
|
+
// packages/protocol/dist/host-wire.js
|
|
1635
|
+
var Origin = z10.enum(["human", "automation"]);
|
|
1636
|
+
var HostCommand = z10.discriminatedUnion("type", [
|
|
1637
|
+
z10.object({
|
|
1638
|
+
type: z10.literal("session.start"),
|
|
1639
|
+
sessionId: z10.string(),
|
|
1640
|
+
title: z10.string(),
|
|
1641
|
+
workspacePath: z10.string(),
|
|
1642
|
+
projectId: z10.string().nullable(),
|
|
1643
|
+
profile: Profile,
|
|
1644
|
+
nativeHandle: NativeHandle.nullable(),
|
|
1645
|
+
initialPrompt: z10.string().nullable(),
|
|
1646
|
+
dispatchKey: z10.string().nullable(),
|
|
1647
|
+
controlRevision: z10.number().int(),
|
|
1648
|
+
controlMode: ControlMode,
|
|
1649
|
+
origin: Origin,
|
|
1650
|
+
readOnly: z10.boolean().default(false),
|
|
1651
|
+
policyRequired: z10.boolean().optional()
|
|
1652
|
+
}),
|
|
1653
|
+
z10.object({
|
|
1654
|
+
type: z10.literal("session.deliverMessage"),
|
|
1655
|
+
sessionId: z10.string(),
|
|
1656
|
+
messageId: z10.string(),
|
|
1657
|
+
payload: z10.object({
|
|
1658
|
+
deliveryId: z10.string(),
|
|
1659
|
+
kind: z10.enum(["message", "completion"]),
|
|
1660
|
+
text: z10.string()
|
|
1661
|
+
}),
|
|
1662
|
+
mode: z10.enum(["steer", "queue"]),
|
|
1663
|
+
holdUntil: z10.string()
|
|
1664
|
+
}),
|
|
1665
|
+
HostPolicySampleRequest.extend({ type: z10.literal("session.classifyPolicySample") }),
|
|
1666
|
+
z10.object({
|
|
1667
|
+
type: z10.literal("session.messageStatus"),
|
|
1668
|
+
sessionId: z10.string(),
|
|
1669
|
+
messageIds: z10.array(z10.string().min(1)).min(1).max(100)
|
|
1670
|
+
}),
|
|
1671
|
+
z10.object({
|
|
1672
|
+
type: z10.literal("session.prompt"),
|
|
1673
|
+
sessionId: z10.string(),
|
|
1674
|
+
text: z10.string(),
|
|
1675
|
+
images: z10.array(z10.object({ mimeType: z10.string(), data: z10.string() })).default([]),
|
|
1676
|
+
mode: z10.enum(["prompt", "steer", "followUp"]),
|
|
1677
|
+
origin: Origin,
|
|
1678
|
+
controlRevision: z10.number().int()
|
|
1679
|
+
}),
|
|
1680
|
+
z10.object({ type: z10.literal("session.abort"), sessionId: z10.string(), clearQueue: z10.boolean() }),
|
|
1681
|
+
z10.object({ type: z10.literal("session.stop"), sessionId: z10.string() }),
|
|
1682
|
+
z10.object({
|
|
1683
|
+
type: z10.literal("session.answer"),
|
|
1684
|
+
sessionId: z10.string(),
|
|
1685
|
+
interactionId: z10.string(),
|
|
1686
|
+
revision: z10.number().int(),
|
|
1687
|
+
response: InteractionResponseSchema,
|
|
1688
|
+
deviceId: z10.string()
|
|
1689
|
+
}),
|
|
1690
|
+
z10.object({
|
|
1691
|
+
type: z10.literal("session.adapterAction"),
|
|
1692
|
+
sessionId: z10.string(),
|
|
1693
|
+
adapterId: z10.string(),
|
|
1694
|
+
actionId: z10.string(),
|
|
1695
|
+
payload: z10.unknown()
|
|
1696
|
+
}),
|
|
1697
|
+
z10.object({
|
|
1698
|
+
type: z10.literal("session.setControl"),
|
|
1699
|
+
sessionId: z10.string(),
|
|
1700
|
+
controlRevision: z10.number().int(),
|
|
1701
|
+
mode: ControlMode
|
|
1702
|
+
}),
|
|
1703
|
+
z10.object({ type: z10.literal("session.rename"), sessionId: z10.string(), title: z10.string() }),
|
|
1704
|
+
z10.object({ type: z10.literal("session.importable") }),
|
|
1705
|
+
z10.object({ type: z10.literal("session.readNative"), sessionFile: z10.string() }),
|
|
1706
|
+
z10.object({ type: z10.literal("session.snapshot"), sessionId: z10.string() }),
|
|
1707
|
+
z10.object({ type: z10.literal("session.models"), sessionId: z10.string() }),
|
|
1708
|
+
z10.object({ type: z10.literal("session.commands"), sessionId: z10.string() }),
|
|
1709
|
+
z10.object({
|
|
1710
|
+
type: z10.literal("session.complete"),
|
|
1711
|
+
sessionId: z10.string(),
|
|
1712
|
+
text: z10.string().max(500)
|
|
1713
|
+
}),
|
|
1714
|
+
z10.object({ type: z10.literal("session.tree"), sessionId: z10.string() }),
|
|
1715
|
+
z10.object({
|
|
1716
|
+
type: z10.literal("session.branch"),
|
|
1717
|
+
sessionId: z10.string(),
|
|
1718
|
+
entryId: z10.string().nullable(),
|
|
1719
|
+
fork: z10.boolean()
|
|
1720
|
+
}),
|
|
1721
|
+
z10.object({
|
|
1722
|
+
type: z10.literal("session.navigate"),
|
|
1723
|
+
sessionId: z10.string(),
|
|
1724
|
+
entryId: z10.string(),
|
|
1725
|
+
summarize: z10.boolean(),
|
|
1726
|
+
instructions: z10.string().max(2e3).nullable()
|
|
1727
|
+
}),
|
|
1728
|
+
z10.object({ type: z10.literal("session.reload"), sessionId: z10.string() }),
|
|
1729
|
+
z10.object({ type: z10.literal("session.export"), sessionId: z10.string() }),
|
|
1730
|
+
z10.object({
|
|
1731
|
+
type: z10.literal("session.setModel"),
|
|
1732
|
+
sessionId: z10.string(),
|
|
1733
|
+
provider: z10.string().min(1),
|
|
1734
|
+
modelId: z10.string().min(1)
|
|
1735
|
+
}),
|
|
1736
|
+
z10.object({ type: z10.literal("session.setThinking"), sessionId: z10.string(), level: ThinkingLevel }),
|
|
1737
|
+
z10.object({
|
|
1738
|
+
type: z10.literal("session.compact"),
|
|
1739
|
+
sessionId: z10.string(),
|
|
1740
|
+
instructions: z10.string().nullable()
|
|
1741
|
+
}),
|
|
1742
|
+
z10.object({ type: z10.literal("checkout.inspect"), path: z10.string() }),
|
|
1743
|
+
z10.object({ type: z10.literal("projects.scan"), folder: z10.string().min(1) }),
|
|
1744
|
+
z10.object({
|
|
1745
|
+
type: z10.literal("projects.suggest"),
|
|
1746
|
+
days: z10.number().int().min(1).max(365).default(30)
|
|
1747
|
+
}),
|
|
1748
|
+
z10.object({
|
|
1749
|
+
type: z10.literal("workspace.discover"),
|
|
1750
|
+
checkoutPath: z10.string(),
|
|
1751
|
+
worktreeDir: z10.string().default(DEFAULT_WORKTREE_DIR)
|
|
1752
|
+
}),
|
|
1753
|
+
z10.object({
|
|
1754
|
+
type: z10.literal("workspace.create"),
|
|
1755
|
+
checkoutPath: z10.string(),
|
|
1756
|
+
branch: z10.string(),
|
|
1757
|
+
base: z10.string(),
|
|
1758
|
+
setupCommand: z10.string().nullable(),
|
|
1759
|
+
worktreeDir: z10.string().default(DEFAULT_WORKTREE_DIR)
|
|
1760
|
+
}),
|
|
1761
|
+
z10.object({ type: z10.literal("workspace.status"), path: z10.string(), base: z10.string().nullable() }),
|
|
1762
|
+
z10.object({
|
|
1763
|
+
type: z10.literal("workspace.remove"),
|
|
1764
|
+
path: z10.string(),
|
|
1765
|
+
checkoutPath: z10.string(),
|
|
1766
|
+
base: z10.string().nullable(),
|
|
1767
|
+
force: z10.object({ dirty: z10.boolean(), unmerged: z10.boolean() })
|
|
1768
|
+
}),
|
|
1769
|
+
z10.object({
|
|
1770
|
+
type: z10.literal("workspace.diff"),
|
|
1771
|
+
path: z10.string(),
|
|
1772
|
+
base: z10.string().nullable(),
|
|
1773
|
+
file: z10.string().nullable()
|
|
1774
|
+
}),
|
|
1775
|
+
z10.object({ type: z10.literal("workspace.files"), path: z10.string(), dir: z10.string() }),
|
|
1776
|
+
z10.object({ type: z10.literal("workspace.readFile"), path: z10.string(), file: z10.string() }),
|
|
1777
|
+
GitHubHostViewRequest.extend({ type: z10.literal("workspace.prView") }),
|
|
1778
|
+
GitHubHostLogsRequest.extend({ type: z10.literal("workspace.prFailedLogs") }),
|
|
1779
|
+
GitHubHostMergeRequest.extend({ type: z10.literal("workspace.prMerge") }),
|
|
1780
|
+
z10.object({
|
|
1781
|
+
type: z10.literal("dispatch.start"),
|
|
1782
|
+
dispatchKey: z10.string(),
|
|
1783
|
+
runId: z10.string(),
|
|
1784
|
+
taskId: z10.string(),
|
|
1785
|
+
sessionId: z10.string(),
|
|
1786
|
+
projectId: z10.string(),
|
|
1787
|
+
title: z10.string(),
|
|
1788
|
+
workspace: z10.union([
|
|
1789
|
+
z10.object({ path: z10.string() }),
|
|
1790
|
+
z10.object({
|
|
1791
|
+
createFrom: z10.object({
|
|
1792
|
+
checkoutPath: z10.string(),
|
|
1793
|
+
branch: z10.string(),
|
|
1794
|
+
base: z10.string(),
|
|
1795
|
+
setupCommand: z10.string().nullable(),
|
|
1796
|
+
worktreeDir: z10.string().default(DEFAULT_WORKTREE_DIR)
|
|
1797
|
+
})
|
|
1798
|
+
})
|
|
1799
|
+
]),
|
|
1800
|
+
nativeHandle: NativeHandle.nullable(),
|
|
1801
|
+
profile: Profile,
|
|
1802
|
+
prompt: z10.string(),
|
|
1803
|
+
/** The launch's own revision; a takeover always carries a newer one. */
|
|
1804
|
+
controlRevision: z10.number().int(),
|
|
1805
|
+
controlMode: ControlMode.default("automation"),
|
|
1806
|
+
policyRequired: z10.boolean().optional()
|
|
1807
|
+
}),
|
|
1808
|
+
z10.object({ type: z10.literal("dispatch.reconcile"), dispatchKey: z10.string() }),
|
|
1809
|
+
z10.object({
|
|
1810
|
+
type: z10.literal("checks.run"),
|
|
1811
|
+
sessionId: z10.string(),
|
|
1812
|
+
path: z10.string(),
|
|
1813
|
+
commands: z10.array(z10.string())
|
|
1814
|
+
})
|
|
1815
|
+
]);
|
|
1816
|
+
var ImportableSession = z10.object({
|
|
1817
|
+
sessionFile: z10.string(),
|
|
1818
|
+
sessionId: z10.string(),
|
|
1819
|
+
cwd: z10.string(),
|
|
1820
|
+
name: z10.string().nullable(),
|
|
1821
|
+
mtime: z10.string(),
|
|
1822
|
+
inactive: z10.boolean()
|
|
1823
|
+
});
|
|
1824
|
+
var DiscoveredWorktree = z10.object({
|
|
1825
|
+
path: z10.string(),
|
|
1826
|
+
head: z10.string().nullable(),
|
|
1827
|
+
branch: z10.string().nullable(),
|
|
1828
|
+
bare: z10.boolean(),
|
|
1829
|
+
detached: z10.boolean(),
|
|
1830
|
+
locked: z10.boolean(),
|
|
1831
|
+
prunable: z10.boolean(),
|
|
1832
|
+
provenance: z10.enum(["managed", "discovered", "main"]),
|
|
1833
|
+
git: GitState.nullable()
|
|
1834
|
+
});
|
|
1835
|
+
var CheckoutInfo = z10.object({
|
|
1836
|
+
root: z10.string(),
|
|
1837
|
+
commonDir: z10.string(),
|
|
1838
|
+
repoIdentity: z10.string(),
|
|
1839
|
+
defaultBranch: z10.string()
|
|
1840
|
+
});
|
|
1841
|
+
var ScannedRepository = CheckoutInfo.extend({ name: z10.string() });
|
|
1842
|
+
var ProjectFolderScan = z10.object({
|
|
1843
|
+
/** The folder, ~ expanded and realpath'd. */
|
|
1844
|
+
folder: z10.string(),
|
|
1845
|
+
repositories: z10.array(ScannedRepository)
|
|
1846
|
+
});
|
|
1847
|
+
var ProjectSuggestion = z10.object({
|
|
1848
|
+
rootPath: z10.string(),
|
|
1849
|
+
sessionCount: z10.number().int(),
|
|
1850
|
+
lastActivityAt: z10.string()
|
|
1851
|
+
});
|
|
1852
|
+
var ProjectSuggestions = z10.object({ suggestions: z10.array(ProjectSuggestion) });
|
|
1853
|
+
var DiffFile = z10.object({
|
|
1854
|
+
path: z10.string(),
|
|
1855
|
+
oldPath: z10.string().nullable(),
|
|
1856
|
+
added: z10.number().int(),
|
|
1857
|
+
deleted: z10.number().int(),
|
|
1858
|
+
status: z10.enum(["added", "modified", "deleted", "renamed", "untracked", "binary"])
|
|
1859
|
+
});
|
|
1860
|
+
var DiffResult = z10.object({
|
|
1861
|
+
base: z10.string(),
|
|
1862
|
+
files: z10.array(DiffFile),
|
|
1863
|
+
patch: z10.string().nullable()
|
|
1864
|
+
});
|
|
1865
|
+
var FileEntry = z10.object({
|
|
1866
|
+
name: z10.string(),
|
|
1867
|
+
path: z10.string(),
|
|
1868
|
+
kind: z10.enum(["file", "dir", "symlink"]),
|
|
1869
|
+
size: z10.number().int().nullable()
|
|
1870
|
+
});
|
|
1871
|
+
var ReconcileResult = z10.union([
|
|
1872
|
+
z10.object({ known: z10.literal(false) }),
|
|
1873
|
+
z10.object({
|
|
1874
|
+
known: z10.literal(true),
|
|
1875
|
+
sessionId: z10.string().nullable(),
|
|
1876
|
+
state: z10.enum(["accepted", "workspace_ready", "started", "failed"]),
|
|
1877
|
+
runtime: RuntimeState.nullable(),
|
|
1878
|
+
workspacePath: z10.string().nullable(),
|
|
1879
|
+
nativeHandle: NativeHandle.nullable(),
|
|
1880
|
+
error: z10.string().nullable(),
|
|
1881
|
+
/** `{started: "unknown"}` when the host restarted after Pi may have been spawned. */
|
|
1882
|
+
errorDetails: z10.record(z10.string(), z10.unknown()).nullable().default(null)
|
|
1883
|
+
})
|
|
1884
|
+
]);
|
|
1885
|
+
var DispatchStartResult = z10.object({
|
|
1886
|
+
sessionId: z10.string(),
|
|
1887
|
+
workspacePath: z10.string(),
|
|
1888
|
+
nativeHandle: NativeHandle.nullable(),
|
|
1889
|
+
reused: z10.boolean(),
|
|
1890
|
+
/** Why the launch prompt was not delivered to Pi (the session itself started), if it was not. */
|
|
1891
|
+
promptError: z10.string().nullable().optional()
|
|
1892
|
+
});
|
|
1893
|
+
var AnswerResult = z10.object({
|
|
1894
|
+
status: z10.enum(["answered", "already_answered"]),
|
|
1895
|
+
interaction: Interaction
|
|
1896
|
+
});
|
|
1897
|
+
var SnapshotResult = z10.object({
|
|
1898
|
+
partial: z10.array(TranscriptItem),
|
|
1899
|
+
pendingInteractions: z10.array(Interaction)
|
|
1900
|
+
});
|
|
1901
|
+
var ChecksResult = z10.object({ results: z10.array(CheckResult) });
|
|
1902
|
+
var Receipt = z10.union([
|
|
1903
|
+
z10.object({ commandId: z10.string(), ok: z10.literal(true), result: z10.unknown() }),
|
|
1904
|
+
z10.object({ commandId: z10.string(), ok: z10.literal(false), error: ErrorBody })
|
|
1905
|
+
]);
|
|
1906
|
+
var HostAgentRequestFrame = AgentRequestFrame.safeExtend({
|
|
1907
|
+
policyContext: HostToolPolicyContext.optional()
|
|
1908
|
+
}).strict().superRefine((frame, ctx) => {
|
|
1909
|
+
if (frame.method === "policy.evaluate" ? frame.policyContext === void 0 : Object.hasOwn(frame, "policyContext")) {
|
|
1910
|
+
ctx.addIssue({
|
|
1911
|
+
code: "custom",
|
|
1912
|
+
path: ["policyContext"],
|
|
1913
|
+
message: "Host policy context is required only for policy.evaluate."
|
|
1914
|
+
});
|
|
1915
|
+
}
|
|
1916
|
+
try {
|
|
1917
|
+
if (new TextEncoder().encode(JSON.stringify(frame)).length <= AGENT_FRAME_MAX_BYTES)
|
|
1918
|
+
return;
|
|
1919
|
+
} catch {
|
|
1920
|
+
}
|
|
1921
|
+
ctx.addIssue({ code: "custom", message: "Host agent frame exceeds 128 KiB or is not JSON." });
|
|
1922
|
+
});
|
|
1923
|
+
var HostToCoordinator = z10.discriminatedUnion("type", [
|
|
1924
|
+
z10.object({
|
|
1925
|
+
type: z10.literal("hello"),
|
|
1926
|
+
hostId: z10.string(),
|
|
1927
|
+
credential: z10.string(),
|
|
1928
|
+
name: z10.string(),
|
|
1929
|
+
agentVersion: z10.string(),
|
|
1930
|
+
piVersion: z10.string().nullable(),
|
|
1931
|
+
piCompatible: z10.boolean(),
|
|
1932
|
+
platform: Platform,
|
|
1933
|
+
capabilities: RuntimeCapabilities.nullable(),
|
|
1934
|
+
github: HostGitHub.optional(),
|
|
1935
|
+
protocolVersion: z10.number().int(),
|
|
1936
|
+
features: z10.array(z10.string()).optional()
|
|
1937
|
+
}),
|
|
1938
|
+
HostAgentRequestFrame,
|
|
1939
|
+
z10.object({ type: z10.literal("event"), hostSeq: z10.number().int(), event: HostEvent }),
|
|
1940
|
+
z10.object({ type: z10.literal("stream"), delta: StreamDelta }),
|
|
1941
|
+
z10.object({ type: z10.literal("receipt"), receipt: Receipt }),
|
|
1942
|
+
z10.object({ type: z10.literal("pong") }),
|
|
1943
|
+
z10.object({ type: z10.literal("usage"), usage: z10.array(ProviderUsage) }),
|
|
1944
|
+
z10.object({ type: z10.literal("term"), streamId: z10.string(), msg: TermServerToViewer })
|
|
1945
|
+
]);
|
|
1946
|
+
var CoordinatorToHost = z10.discriminatedUnion("type", [
|
|
1947
|
+
z10.object({
|
|
1948
|
+
type: z10.literal("welcome"),
|
|
1949
|
+
coordinatorVersion: z10.string(),
|
|
1950
|
+
ackedHostSeq: z10.number().int(),
|
|
1951
|
+
features: z10.array(z10.string()).optional()
|
|
1952
|
+
}),
|
|
1953
|
+
AgentResultFrame,
|
|
1954
|
+
z10.object({ type: z10.literal("ack"), hostSeq: z10.number().int() }),
|
|
1955
|
+
z10.object({ type: z10.literal("command"), commandId: z10.string(), command: HostCommand }),
|
|
1956
|
+
z10.object({ type: z10.literal("ping") }),
|
|
1957
|
+
z10.object({ type: z10.literal("reject"), error: ErrorBody }),
|
|
1958
|
+
z10.object({ type: z10.literal("term"), streamId: z10.string(), msg: TermCoordinatorMsg })
|
|
1959
|
+
]);
|
|
1960
|
+
|
|
1961
|
+
// packages/protocol/dist/api.js
|
|
1962
|
+
var EnrollRequest = z11.object({
|
|
1963
|
+
token: z11.string().min(1),
|
|
1964
|
+
name: z11.string().min(1).max(80),
|
|
1965
|
+
kind: DeviceKind
|
|
1966
|
+
});
|
|
1967
|
+
var EnrollResponse = z11.object({ deviceId: z11.string(), credential: z11.string() });
|
|
1968
|
+
var CreateEnrollmentRequest = z11.object({ kind: z11.enum(["device", "host"]) });
|
|
1969
|
+
var CreateEnrollmentResponse = z11.object({
|
|
1970
|
+
token: z11.string(),
|
|
1971
|
+
url: z11.string(),
|
|
1972
|
+
expiresAt: z11.string(),
|
|
1973
|
+
qrSvg: z11.string(),
|
|
1974
|
+
command: z11.string().nullable()
|
|
1975
|
+
});
|
|
1976
|
+
var HostEnrollRequest = z11.union([
|
|
1977
|
+
z11.object({
|
|
1978
|
+
token: z11.string().min(1),
|
|
1979
|
+
name: z11.string().min(1).max(80),
|
|
1980
|
+
platform: Platform
|
|
1981
|
+
}),
|
|
1982
|
+
z11.object({
|
|
1983
|
+
secret: z11.string().min(1),
|
|
1984
|
+
name: z11.string().min(1).max(80),
|
|
1985
|
+
platform: Platform
|
|
1986
|
+
})
|
|
1987
|
+
]);
|
|
1988
|
+
var HostEnrollResponse = z11.object({ hostId: z11.string(), credential: z11.string() });
|
|
1989
|
+
var CreateProjectRequest = z11.object({
|
|
1990
|
+
name: z11.string().min(1),
|
|
1991
|
+
hostId: z11.string(),
|
|
1992
|
+
path: z11.string().min(1),
|
|
1993
|
+
defaultProfileId: z11.string().nullable().optional(),
|
|
1994
|
+
setupCommand: z11.string().nullable().optional(),
|
|
1995
|
+
checks: z11.array(z11.string()).optional(),
|
|
1996
|
+
maxConcurrentRuns: z11.number().int().min(1).max(32).optional(),
|
|
1997
|
+
worktreeDir: WorktreeDir.optional()
|
|
1998
|
+
});
|
|
1999
|
+
var UpdateProjectRequest = z11.object({
|
|
2000
|
+
name: z11.string().min(1).optional(),
|
|
2001
|
+
defaultProfileId: z11.string().nullable().optional(),
|
|
2002
|
+
defaultHostId: z11.string().nullable().optional(),
|
|
2003
|
+
maxConcurrentRuns: z11.number().int().min(1).max(32).optional(),
|
|
2004
|
+
automationEnabled: z11.boolean().optional(),
|
|
2005
|
+
setupCommand: z11.string().nullable().optional(),
|
|
2006
|
+
checks: z11.array(z11.string()).optional(),
|
|
2007
|
+
workspaceSharing: z11.enum(["single_writer", "shared"]).optional(),
|
|
2008
|
+
worktreeDir: WorktreeDir.optional()
|
|
2009
|
+
});
|
|
2010
|
+
var AddCheckoutRequest = z11.object({ hostId: z11.string(), path: z11.string().min(1) });
|
|
2011
|
+
function isProjectFolderPath(s) {
|
|
2012
|
+
if (s.includes("\0"))
|
|
2013
|
+
return false;
|
|
2014
|
+
return s === "~" || s.startsWith("~/") || s.startsWith("/");
|
|
2015
|
+
}
|
|
2016
|
+
var ProjectFolder = z11.string().trim().min(1).max(1024).refine(isProjectFolderPath, "must be an absolute path or start with ~/");
|
|
2017
|
+
var UpdateHostRequest = z11.object({
|
|
2018
|
+
projectFolders: z11.array(ProjectFolder).max(20).optional()
|
|
2019
|
+
});
|
|
2020
|
+
var ProjectScanResult = ProjectScan.extend({
|
|
2021
|
+
added: z11.array(z11.object({
|
|
2022
|
+
projectId: z11.string(),
|
|
2023
|
+
name: z11.string(),
|
|
2024
|
+
path: z11.string(),
|
|
2025
|
+
newProject: z11.boolean()
|
|
2026
|
+
}))
|
|
2027
|
+
});
|
|
2028
|
+
var ProfileInput = z11.object({
|
|
2029
|
+
name: z11.string().min(1),
|
|
2030
|
+
provider: z11.string().nullable().default(null),
|
|
2031
|
+
model: z11.string().nullable().default(null),
|
|
2032
|
+
thinking: ThinkingLevel.nullable().default(null),
|
|
2033
|
+
projectTrust: z11.enum(["ask", "approve", "ignore"]).default("ask"),
|
|
2034
|
+
extraArgs: z11.array(ExtraArg).default([]),
|
|
2035
|
+
resources: z11.enum(["all", "vanilla"]).default("all")
|
|
2036
|
+
});
|
|
2037
|
+
var CreateWorkspaceRequest = z11.object({
|
|
2038
|
+
checkoutId: z11.string(),
|
|
2039
|
+
branch: z11.string().min(1),
|
|
2040
|
+
base: z11.string().nullable().optional()
|
|
2041
|
+
});
|
|
2042
|
+
var RemoveWorkspaceRequest = z11.object({
|
|
2043
|
+
force: z11.object({ dirty: z11.boolean(), unmerged: z11.boolean() }).default({ dirty: false, unmerged: false })
|
|
2044
|
+
});
|
|
2045
|
+
var CreateSessionRequest = z11.object({
|
|
2046
|
+
projectId: z11.string(),
|
|
2047
|
+
workspace: z11.union([
|
|
2048
|
+
z11.object({ existingId: z11.string() }),
|
|
2049
|
+
z11.object({
|
|
2050
|
+
checkoutId: z11.string(),
|
|
2051
|
+
newBranch: z11.string().min(1),
|
|
2052
|
+
base: z11.string().nullable().optional()
|
|
2053
|
+
})
|
|
2054
|
+
]),
|
|
2055
|
+
profileId: z11.string().nullable().optional(),
|
|
2056
|
+
prompt: z11.string().default(""),
|
|
2057
|
+
title: z11.string().optional(),
|
|
2058
|
+
viewId: z11.string().optional()
|
|
2059
|
+
});
|
|
2060
|
+
var PromptRequest = z11.object({
|
|
2061
|
+
text: z11.string().min(1),
|
|
2062
|
+
mode: z11.enum(["prompt", "steer", "followUp"]).default("prompt"),
|
|
2063
|
+
images: z11.array(z11.object({ mimeType: z11.string(), data: z11.string() })).default([]),
|
|
2064
|
+
clientMessageId: z11.string().optional()
|
|
2065
|
+
});
|
|
2066
|
+
var CacheAlertRequest = z11.object({
|
|
2067
|
+
enabled: z11.boolean(),
|
|
2068
|
+
ttlSec: z11.number().int().min(60).max(86400).nullable().default(null)
|
|
2069
|
+
});
|
|
2070
|
+
var RenameRequest = z11.object({ title: z11.string().min(1).max(200) });
|
|
2071
|
+
var SetModelRequest = z11.object({
|
|
2072
|
+
provider: z11.string().min(1),
|
|
2073
|
+
modelId: z11.string().min(1)
|
|
2074
|
+
});
|
|
2075
|
+
var SetThinkingRequest = z11.object({ level: ThinkingLevel });
|
|
2076
|
+
var CompactRequest = z11.object({ instructions: z11.string().max(4e3).optional() });
|
|
2077
|
+
var SessionModelsResult = z11.object({ models: z11.array(SessionModel) });
|
|
2078
|
+
var SessionCommandsResult = z11.object({ commands: z11.array(SlashCommand) });
|
|
2079
|
+
var CompleteRequest = z11.object({ text: z11.string().min(1).max(500) });
|
|
2080
|
+
var CompletionItem = z11.object({
|
|
2081
|
+
value: z11.string(),
|
|
2082
|
+
label: z11.string(),
|
|
2083
|
+
description: z11.string().nullable()
|
|
2084
|
+
});
|
|
2085
|
+
var SessionCompleteResult = z11.object({
|
|
2086
|
+
items: z11.array(CompletionItem).max(50),
|
|
2087
|
+
prefix: z11.string()
|
|
2088
|
+
});
|
|
2089
|
+
var TreeRow = z11.object({
|
|
2090
|
+
entryId: z11.string(),
|
|
2091
|
+
parentId: z11.string().nullable(),
|
|
2092
|
+
depth: z11.number().int(),
|
|
2093
|
+
role: z11.enum(["user", "assistant"]),
|
|
2094
|
+
text: z11.string(),
|
|
2095
|
+
activeBranch: z11.boolean(),
|
|
2096
|
+
leaf: z11.boolean(),
|
|
2097
|
+
label: z11.string().nullable(),
|
|
2098
|
+
at: z11.string().nullable()
|
|
2099
|
+
});
|
|
2100
|
+
var SessionTreeResult = z11.object({ rows: z11.array(TreeRow) });
|
|
2101
|
+
var BranchRequest = z11.object({
|
|
2102
|
+
entryId: z11.string().nullable(),
|
|
2103
|
+
fork: z11.boolean().default(false)
|
|
2104
|
+
});
|
|
2105
|
+
var HostBranchResult = z11.object({
|
|
2106
|
+
sessionFile: z11.string().nullable(),
|
|
2107
|
+
prefill: z11.string().nullable()
|
|
2108
|
+
});
|
|
2109
|
+
var TranscriptPage = z11.object({
|
|
2110
|
+
items: z11.array(TranscriptItem),
|
|
2111
|
+
hasMore: z11.boolean(),
|
|
2112
|
+
epoch: z11.number().int().optional(),
|
|
2113
|
+
rev: z11.number().int().optional(),
|
|
2114
|
+
delta: z11.boolean().optional(),
|
|
2115
|
+
reset: z11.boolean().optional()
|
|
2116
|
+
});
|
|
2117
|
+
var NavigateRequest = z11.object({
|
|
2118
|
+
entryId: z11.string().min(1),
|
|
2119
|
+
summarize: z11.boolean().default(false),
|
|
2120
|
+
instructions: z11.string().max(2e3).nullable().default(null)
|
|
2121
|
+
});
|
|
2122
|
+
var HostNavigateResult = z11.object({
|
|
2123
|
+
items: z11.array(TranscriptItem),
|
|
2124
|
+
prefill: z11.string().nullable()
|
|
2125
|
+
});
|
|
2126
|
+
var NavigateResult = z11.object({
|
|
2127
|
+
prefill: z11.string().nullable(),
|
|
2128
|
+
epoch: z11.number().int()
|
|
2129
|
+
});
|
|
2130
|
+
var BranchResult = z11.object({
|
|
2131
|
+
session: Session.nullable(),
|
|
2132
|
+
prefill: z11.string().nullable()
|
|
2133
|
+
});
|
|
2134
|
+
var SessionExportResult = z11.object({ fileName: z11.string(), content: z11.string() });
|
|
2135
|
+
var CommandViewAction = z11.object({
|
|
2136
|
+
label: z11.string().min(1).max(80),
|
|
2137
|
+
command: z11.string().startsWith("/").max(500),
|
|
2138
|
+
tone: z11.enum(["default", "primary", "danger"]).optional()
|
|
2139
|
+
});
|
|
2140
|
+
var CommandView = z11.object({
|
|
2141
|
+
title: z11.string().min(1).max(200),
|
|
2142
|
+
body: UINodeSchema,
|
|
2143
|
+
actions: z11.array(CommandViewAction).max(30).default([])
|
|
2144
|
+
});
|
|
2145
|
+
var ModelStateResult = z11.object({
|
|
2146
|
+
model: SessionModel.nullable(),
|
|
2147
|
+
thinking: ThinkingLevel.nullable()
|
|
2148
|
+
});
|
|
2149
|
+
var ImportSessionRequest = z11.object({
|
|
2150
|
+
hostId: z11.string(),
|
|
2151
|
+
sessionFile: z11.string(),
|
|
2152
|
+
projectId: z11.string().nullable().optional()
|
|
2153
|
+
});
|
|
2154
|
+
var AnswerRequest = z11.object({
|
|
2155
|
+
revision: z11.number().int(),
|
|
2156
|
+
response: InteractionResponseSchema
|
|
2157
|
+
});
|
|
2158
|
+
var AdapterActionRequest = z11.object({
|
|
2159
|
+
adapterId: z11.string(),
|
|
2160
|
+
actionId: z11.string(),
|
|
2161
|
+
payload: z11.unknown().optional()
|
|
2162
|
+
});
|
|
2163
|
+
var TaskPolicyPatch = z11.object({
|
|
2164
|
+
hostId: z11.string().nullable().optional(),
|
|
2165
|
+
profileId: z11.string().nullable().optional(),
|
|
2166
|
+
workspace: z11.object({
|
|
2167
|
+
mode: z11.enum(["new_worktree", "existing"]).optional(),
|
|
2168
|
+
branch: z11.string().nullable().optional(),
|
|
2169
|
+
base: z11.string().nullable().optional(),
|
|
2170
|
+
workspaceId: z11.string().optional()
|
|
2171
|
+
}).optional(),
|
|
2172
|
+
continuation: z11.object({
|
|
2173
|
+
enabled: z11.boolean().optional(),
|
|
2174
|
+
objective: z11.string().min(1).optional(),
|
|
2175
|
+
maxContinuations: z11.number().int().min(1).max(50).optional(),
|
|
2176
|
+
maxElapsedMinutes: z11.number().int().min(1).max(1440).optional(),
|
|
2177
|
+
maxTokens: z11.number().int().positive().nullable().optional(),
|
|
2178
|
+
maxCostUsd: z11.number().positive().nullable().optional()
|
|
2179
|
+
}).optional(),
|
|
2180
|
+
completion: CompletionPolicy.partial().optional()
|
|
2181
|
+
});
|
|
2182
|
+
var CreateTaskRequest = z11.object({
|
|
2183
|
+
projectId: z11.string(),
|
|
2184
|
+
title: z11.string().max(300).optional(),
|
|
2185
|
+
githubIssueUrl: GitHubIssueUrl.optional(),
|
|
2186
|
+
githubIssue: z11.never().optional(),
|
|
2187
|
+
launchPrompt: z11.never().optional(),
|
|
2188
|
+
objective: z11.string().default(""),
|
|
2189
|
+
acceptanceCriteria: z11.array(z11.string()).default([]),
|
|
2190
|
+
dependencies: z11.array(z11.string()).default([]),
|
|
2191
|
+
parentTaskId: z11.string().nullable().optional(),
|
|
2192
|
+
priority: Priority.default(2),
|
|
2193
|
+
state: z11.enum(["backlog", "ready"]).default("backlog"),
|
|
2194
|
+
notBefore: z11.string().nullable().optional(),
|
|
2195
|
+
policy: TaskPolicyPatch.optional()
|
|
2196
|
+
}).superRefine((v, ctx) => {
|
|
2197
|
+
if (v.githubIssueUrl === void 0) {
|
|
2198
|
+
if (v.title === void 0 || v.title.length === 0)
|
|
2199
|
+
ctx.addIssue({ code: "custom", path: ["title"], message: "Title is required." });
|
|
2200
|
+
return;
|
|
2201
|
+
}
|
|
2202
|
+
if (v.objective.trim())
|
|
2203
|
+
ctx.addIssue({
|
|
2204
|
+
code: "custom",
|
|
2205
|
+
path: ["objective"],
|
|
2206
|
+
message: "Issue imports use the issue as their initial objective; leave Objective empty."
|
|
2207
|
+
});
|
|
2208
|
+
if (v.acceptanceCriteria.length)
|
|
2209
|
+
ctx.addIssue({
|
|
2210
|
+
code: "custom",
|
|
2211
|
+
path: ["acceptanceCriteria"],
|
|
2212
|
+
message: "Issue imports read acceptance from the issue; leave acceptance criteria empty at creation."
|
|
2213
|
+
});
|
|
2214
|
+
if (v.policy?.continuation?.enabled === true)
|
|
2215
|
+
ctx.addIssue({
|
|
2216
|
+
code: "custom",
|
|
2217
|
+
path: ["policy", "continuation", "enabled"],
|
|
2218
|
+
message: "Issue imports start with continuation disabled."
|
|
2219
|
+
});
|
|
2220
|
+
if (v.policy?.completion?.requireHumanReview === false)
|
|
2221
|
+
ctx.addIssue({
|
|
2222
|
+
code: "custom",
|
|
2223
|
+
path: ["policy", "completion", "requireHumanReview"],
|
|
2224
|
+
message: "Issue imports require human review when created."
|
|
2225
|
+
});
|
|
2226
|
+
}).transform((v) => {
|
|
2227
|
+
if (v.githubIssueUrl === void 0)
|
|
2228
|
+
return { ...v, title: v.title };
|
|
2229
|
+
const issue = githubIssueFromUrl(v.githubIssueUrl);
|
|
2230
|
+
return { ...v, title: v.title?.trim() || `${issue.repository} #${issue.number}` };
|
|
2231
|
+
});
|
|
2232
|
+
var UpdateTaskRequest = z11.object({
|
|
2233
|
+
githubIssueUrl: z11.never().optional(),
|
|
2234
|
+
githubIssue: z11.never().optional(),
|
|
2235
|
+
launchPrompt: z11.never().optional(),
|
|
2236
|
+
title: z11.string().min(1).max(300).optional(),
|
|
2237
|
+
objective: z11.string().optional(),
|
|
2238
|
+
acceptanceCriteria: z11.array(z11.string()).optional(),
|
|
2239
|
+
dependencies: z11.array(z11.string()).optional(),
|
|
2240
|
+
parentTaskId: z11.string().nullable().optional(),
|
|
2241
|
+
priority: Priority.optional(),
|
|
2242
|
+
position: z11.number().optional(),
|
|
2243
|
+
notBefore: z11.string().nullable().optional(),
|
|
2244
|
+
policy: TaskPolicyPatch.optional()
|
|
2245
|
+
});
|
|
2246
|
+
var MoveTaskRequest = z11.object({
|
|
2247
|
+
to: TaskState,
|
|
2248
|
+
confirm: z11.boolean().optional(),
|
|
2249
|
+
onRunning: z11.enum(["pause", "stop"]).optional(),
|
|
2250
|
+
position: z11.number().optional()
|
|
2251
|
+
});
|
|
2252
|
+
var RequestChangesRequest = z11.object({ feedback: z11.array(z11.string().min(1)).min(1) });
|
|
2253
|
+
var Eligibility = z11.union([
|
|
2254
|
+
z11.object({ eligible: z11.literal(true), hostId: z11.string(), hostName: z11.string() }),
|
|
2255
|
+
z11.object({
|
|
2256
|
+
eligible: z11.literal(false),
|
|
2257
|
+
wait: z11.enum([
|
|
2258
|
+
"dependency",
|
|
2259
|
+
"host_offline",
|
|
2260
|
+
"project_limit",
|
|
2261
|
+
"workspace_occupied",
|
|
2262
|
+
"scheduled_time",
|
|
2263
|
+
"invalid_configuration",
|
|
2264
|
+
"dispatch_paused",
|
|
2265
|
+
"project_automation_disabled",
|
|
2266
|
+
"not_ready",
|
|
2267
|
+
"already_dispatched",
|
|
2268
|
+
"retry_backoff"
|
|
2269
|
+
]),
|
|
2270
|
+
message: z11.string()
|
|
2271
|
+
})
|
|
2272
|
+
]);
|
|
2273
|
+
var NowResponse = z11.object({
|
|
2274
|
+
running: z11.array(z11.object({ taskId: z11.string(), runId: z11.string(), sessionId: z11.string().nullable() })),
|
|
2275
|
+
queued: z11.array(z11.object({ taskId: z11.string(), eligibility: Eligibility })),
|
|
2276
|
+
dispatchPaused: z11.boolean()
|
|
2277
|
+
});
|
|
2278
|
+
var AutomationInput = z11.object({
|
|
2279
|
+
name: z11.string().min(1),
|
|
2280
|
+
enabled: z11.boolean().default(true),
|
|
2281
|
+
projectId: z11.string(),
|
|
2282
|
+
trigger: Trigger,
|
|
2283
|
+
filters: z11.array(z11.object({ path: z11.string(), equals: z11.string() })).default([]),
|
|
2284
|
+
template: TaskTemplate,
|
|
2285
|
+
hostId: z11.string().nullable().default(null),
|
|
2286
|
+
profileId: z11.string().nullable().default(null),
|
|
2287
|
+
mode: z11.enum(["fresh", "continue", "watch"]).default("fresh"),
|
|
2288
|
+
groupingKey: z11.string().nullable().default(null),
|
|
2289
|
+
overlap: z11.enum(["skip", "queue_one", "append"]).default("skip"),
|
|
2290
|
+
missed: z11.enum(["skip", "run_once"]).default("skip"),
|
|
2291
|
+
continuation: ContinuationPolicy.default({ enabled: false }),
|
|
2292
|
+
completion: CompletionPolicy.default({ checks: null, requireHumanReview: true })
|
|
2293
|
+
});
|
|
2294
|
+
var AutomationView = Automation.extend({ summary: z11.string() });
|
|
2295
|
+
var AutomationPreview = z11.object({
|
|
2296
|
+
summary: z11.string(),
|
|
2297
|
+
task: TaskTemplate,
|
|
2298
|
+
next: z11.array(z11.string())
|
|
2299
|
+
});
|
|
2300
|
+
var WebhookTokenResponse = z11.object({ token: z11.string(), url: z11.string() });
|
|
2301
|
+
var PushSubscriptionRequest = z11.object({
|
|
2302
|
+
endpoint: z11.string().url(),
|
|
2303
|
+
keys: z11.object({ p256dh: z11.string(), auth: z11.string() }),
|
|
2304
|
+
permission: z11.enum(["granted", "denied", "default", "unknown"]).default("granted")
|
|
2305
|
+
});
|
|
2306
|
+
var NotificationSettings = z11.object({
|
|
2307
|
+
quietHours: z11.object({
|
|
2308
|
+
start: z11.string().regex(/^\d{2}:\d{2}$/),
|
|
2309
|
+
end: z11.string().regex(/^\d{2}:\d{2}$/),
|
|
2310
|
+
timezone: z11.string()
|
|
2311
|
+
}).nullable(),
|
|
2312
|
+
privatePreviews: z11.boolean(),
|
|
2313
|
+
preferredDeviceId: z11.string().nullable()
|
|
2314
|
+
});
|
|
2315
|
+
var PushPayload = z11.union([
|
|
2316
|
+
z11.object({
|
|
2317
|
+
type: z11.literal("show"),
|
|
2318
|
+
title: z11.string(),
|
|
2319
|
+
body: z11.string(),
|
|
2320
|
+
tag: z11.string(),
|
|
2321
|
+
url: z11.string(),
|
|
2322
|
+
renotify: z11.boolean()
|
|
2323
|
+
}),
|
|
2324
|
+
z11.object({ type: z11.literal("clear"), tag: z11.string() })
|
|
2325
|
+
]);
|
|
2326
|
+
var SetupState = z11.object({
|
|
2327
|
+
passkey: z11.object({
|
|
2328
|
+
available: z11.boolean(),
|
|
2329
|
+
registered: z11.boolean(),
|
|
2330
|
+
reason: z11.string().nullable()
|
|
2331
|
+
}),
|
|
2332
|
+
oidc: z11.object({ label: z11.string() }).nullable()
|
|
2333
|
+
});
|
|
2334
|
+
var PasskeyRegisterOptionsResponse = z11.object({
|
|
2335
|
+
challengeId: z11.string(),
|
|
2336
|
+
options: z11.unknown()
|
|
2337
|
+
});
|
|
2338
|
+
var PasskeyRegisterVerifyRequest = z11.object({
|
|
2339
|
+
challengeId: z11.string(),
|
|
2340
|
+
name: z11.string().min(1).max(80),
|
|
2341
|
+
response: z11.unknown()
|
|
2342
|
+
});
|
|
2343
|
+
var PasskeySignInOptionsResponse = z11.object({
|
|
2344
|
+
challengeId: z11.string(),
|
|
2345
|
+
options: z11.unknown()
|
|
2346
|
+
});
|
|
2347
|
+
var PasskeySignInVerifyRequest = z11.object({
|
|
2348
|
+
challengeId: z11.string(),
|
|
2349
|
+
response: z11.unknown(),
|
|
2350
|
+
deviceName: z11.string().min(1).max(80),
|
|
2351
|
+
kind: DeviceKind.extract(["browser", "pwa"])
|
|
2352
|
+
});
|
|
2353
|
+
var OidcBeginRequest = z11.object({
|
|
2354
|
+
deviceName: z11.string().min(1).max(80),
|
|
2355
|
+
kind: DeviceKind.extract(["browser", "pwa"]),
|
|
2356
|
+
next: z11.string().default("/"),
|
|
2357
|
+
handoff: z11.boolean().default(false)
|
|
2358
|
+
});
|
|
2359
|
+
var OidcBeginResponse = z11.object({
|
|
2360
|
+
authorizeUrl: z11.string(),
|
|
2361
|
+
flowId: z11.string().nullable(),
|
|
2362
|
+
pollToken: z11.string().nullable()
|
|
2363
|
+
});
|
|
2364
|
+
var OidcClaimRequest = z11.object({ flowId: z11.string(), pollToken: z11.string() });
|
|
2365
|
+
var OidcClaimResponse = z11.union([
|
|
2366
|
+
z11.object({ status: z11.literal("pending") }),
|
|
2367
|
+
z11.object({ status: z11.literal("done"), deviceId: z11.string() })
|
|
2368
|
+
]);
|
|
2369
|
+
var TerminalLoginStartRequest = z11.object({ name: z11.string().min(1).max(80) });
|
|
2370
|
+
var TerminalLoginStartResponse = z11.object({
|
|
2371
|
+
userCode: z11.string(),
|
|
2372
|
+
pollToken: z11.string(),
|
|
2373
|
+
verifyUrl: z11.string(),
|
|
2374
|
+
expiresAt: z11.string(),
|
|
2375
|
+
intervalMs: z11.number().int()
|
|
2376
|
+
});
|
|
2377
|
+
var TerminalLoginClaimRequest = z11.object({
|
|
2378
|
+
userCode: z11.string().min(1),
|
|
2379
|
+
pollToken: z11.string().min(1)
|
|
2380
|
+
});
|
|
2381
|
+
var TerminalLoginClaimResponse = z11.union([
|
|
2382
|
+
z11.object({ status: z11.literal("pending") }),
|
|
2383
|
+
z11.object({ status: z11.literal("denied") }),
|
|
2384
|
+
z11.object({ status: z11.literal("done"), deviceId: z11.string(), credential: z11.string() })
|
|
2385
|
+
]);
|
|
2386
|
+
var TerminalLoginRequest = z11.object({
|
|
2387
|
+
userCode: z11.string(),
|
|
2388
|
+
name: z11.string(),
|
|
2389
|
+
requestedFrom: z11.string(),
|
|
2390
|
+
createdAt: z11.string(),
|
|
2391
|
+
expiresAt: z11.string(),
|
|
2392
|
+
status: z11.enum(["pending", "approved", "denied"])
|
|
2393
|
+
});
|
|
2394
|
+
var AuthMethods = z11.object({
|
|
2395
|
+
passkeys: z11.array(Passkey),
|
|
2396
|
+
passkeyAvailability: z11.object({ available: z11.boolean(), reason: z11.string().nullable() }),
|
|
2397
|
+
oidc: z11.object({
|
|
2398
|
+
issuer: z11.string(),
|
|
2399
|
+
label: z11.string(),
|
|
2400
|
+
ownerMatch: z11.string(),
|
|
2401
|
+
status: z11.enum(["ready", "error"]),
|
|
2402
|
+
error: z11.string().nullable()
|
|
2403
|
+
}).nullable()
|
|
2404
|
+
});
|
|
2405
|
+
var MeResponse = z11.object({
|
|
2406
|
+
device: Device,
|
|
2407
|
+
admin: z11.boolean(),
|
|
2408
|
+
publicUrl: z11.string()
|
|
2409
|
+
});
|
|
2410
|
+
var ViewInput = View.pick({
|
|
2411
|
+
name: true,
|
|
2412
|
+
mode: true,
|
|
2413
|
+
projectIds: true,
|
|
2414
|
+
hostIds: true
|
|
2415
|
+
}).partial({
|
|
2416
|
+
mode: true,
|
|
2417
|
+
projectIds: true,
|
|
2418
|
+
hostIds: true
|
|
2419
|
+
});
|
|
2420
|
+
var ViewPatch = ViewInput.partial();
|
|
2421
|
+
var ViewClientReport = ViewClient.omit({ lastSeenAt: true });
|
|
2422
|
+
var ProjectSuggestionsResponse = z11.object({
|
|
2423
|
+
suggestions: z11.array(ProjectSuggestion.extend({ name: z11.string(), preselected: z11.boolean() }))
|
|
2424
|
+
});
|
|
2425
|
+
|
|
2426
|
+
// packages/protocol/dist/client-wire.js
|
|
2427
|
+
import { z as z12 } from "zod";
|
|
2428
|
+
var SyncState = z12.object({
|
|
2429
|
+
hosts: z12.array(Host),
|
|
2430
|
+
projects: z12.array(Project),
|
|
2431
|
+
checkouts: z12.array(Checkout),
|
|
2432
|
+
workspaces: z12.array(Workspace),
|
|
2433
|
+
profiles: z12.array(Profile),
|
|
2434
|
+
views: z12.array(View),
|
|
2435
|
+
sessions: z12.array(Session),
|
|
2436
|
+
tasks: z12.array(Task),
|
|
2437
|
+
runs: z12.array(Run),
|
|
2438
|
+
automations: z12.array(Automation),
|
|
2439
|
+
attention: z12.array(AttentionItem),
|
|
2440
|
+
interactions: z12.array(Interaction),
|
|
2441
|
+
panels: z12.array(Panel),
|
|
2442
|
+
devices: z12.array(Device),
|
|
2443
|
+
adapters: z12.record(z12.string(), z12.array(AdapterInfo)),
|
|
2444
|
+
dispatchPaused: z12.boolean()
|
|
2445
|
+
});
|
|
2446
|
+
var Presence = z12.object({
|
|
2447
|
+
foreground: z12.boolean(),
|
|
2448
|
+
interactedAt: z12.string().nullable(),
|
|
2449
|
+
viewing: z12.object({ sessionId: z12.string() }).nullable()
|
|
2450
|
+
});
|
|
2451
|
+
var CLIENT_CAPABILITIES = ["adapter.slots.v1", "timeline.cards.v1"];
|
|
2452
|
+
var ClientToServer = z12.discriminatedUnion("type", [
|
|
2453
|
+
z12.object({
|
|
2454
|
+
type: z12.literal("hello"),
|
|
2455
|
+
cursor: z12.number().int().nullable(),
|
|
2456
|
+
capabilities: z12.array(z12.string().min(1).max(80)).max(32).optional(),
|
|
2457
|
+
projectionId: z12.string().max(256).nullable().optional()
|
|
2458
|
+
}),
|
|
2459
|
+
z12.object({ type: z12.literal("presence"), presence: Presence }),
|
|
2460
|
+
z12.object({ type: z12.literal("ping") })
|
|
2461
|
+
]);
|
|
2462
|
+
var ServerToClient = z12.discriminatedUnion("type", [
|
|
2463
|
+
z12.object({
|
|
2464
|
+
type: z12.literal("replay"),
|
|
2465
|
+
seq: z12.number().int(),
|
|
2466
|
+
events: z12.array(EventEnvelope),
|
|
2467
|
+
capabilities: z12.array(z12.enum(CLIENT_CAPABILITIES)).optional(),
|
|
2468
|
+
projectionId: z12.string().optional()
|
|
2469
|
+
}),
|
|
2470
|
+
z12.object({
|
|
2471
|
+
type: z12.literal("snapshot"),
|
|
2472
|
+
seq: z12.number().int(),
|
|
2473
|
+
state: SyncState,
|
|
2474
|
+
capabilities: z12.array(z12.enum(CLIENT_CAPABILITIES)).optional(),
|
|
2475
|
+
projectionId: z12.string().optional()
|
|
2476
|
+
}),
|
|
2477
|
+
z12.object({ type: z12.literal("event"), event: EventEnvelope }),
|
|
2478
|
+
z12.object({ type: z12.literal("stream"), delta: StreamDelta }),
|
|
2479
|
+
z12.object({ type: z12.literal("pong") }),
|
|
2480
|
+
z12.object({ type: z12.literal("force_logout"), reason: z12.string() })
|
|
2481
|
+
]);
|
|
2482
|
+
|
|
2483
|
+
// packages/protocol/dist/ids.js
|
|
2484
|
+
import { monotonicFactory } from "ulid";
|
|
2485
|
+
var ulid = monotonicFactory();
|
|
2486
|
+
|
|
2487
|
+
// packages/protocol/dist/views.js
|
|
2488
|
+
var CLIENT_OPEN_MS = 10 * 6e4;
|
|
2489
|
+
|
|
2490
|
+
// packages/protocol/dist/web-bridge.js
|
|
2491
|
+
import { z as z13 } from "zod";
|
|
2492
|
+
var FRAME_MAX_HEIGHT = 4e3;
|
|
2493
|
+
var FrameToParentMessageSchema = z13.discriminatedUnion("type", [
|
|
2494
|
+
z13.object({
|
|
2495
|
+
type: z13.literal("action"),
|
|
2496
|
+
actionId: z13.string().min(1).max(200),
|
|
2497
|
+
payload: z13.unknown().optional()
|
|
2498
|
+
}),
|
|
2499
|
+
z13.object({
|
|
2500
|
+
type: z13.literal("resize"),
|
|
2501
|
+
height: z13.number().finite().min(0).max(FRAME_MAX_HEIGHT)
|
|
2502
|
+
})
|
|
2503
|
+
]);
|
|
2504
|
+
|
|
2505
|
+
// packages/coordinator/dist/policies/evaluator.js
|
|
2506
|
+
import { existsSync } from "node:fs";
|
|
2507
|
+
import { Worker } from "node:worker_threads";
|
|
2508
|
+
var PolicyEvaluatorError = class extends Error {
|
|
2509
|
+
failure;
|
|
2510
|
+
constructor(failure) {
|
|
2511
|
+
super(failure.message);
|
|
2512
|
+
this.failure = failure;
|
|
2513
|
+
this.name = "PolicyEvaluatorError";
|
|
2514
|
+
}
|
|
2515
|
+
};
|
|
2516
|
+
var forbidden2 = /* @__PURE__ */ new Set(["__proto__", "prototype", "constructor"]);
|
|
2517
|
+
var fail = (kind, message) => new PolicyEvaluatorError({ kind, message, range: null });
|
|
2518
|
+
function checkPolicyJson(value, maxBytes, context = false) {
|
|
2519
|
+
let bytes3 = 0;
|
|
2520
|
+
const ancestors = /* @__PURE__ */ new Set();
|
|
2521
|
+
const add = (n) => {
|
|
2522
|
+
bytes3 += n;
|
|
2523
|
+
if (bytes3 > maxBytes)
|
|
2524
|
+
throw fail("limit", "Policy input is too large to evaluate.");
|
|
2525
|
+
};
|
|
2526
|
+
const visit = (v, path2) => {
|
|
2527
|
+
if (path2.length > 20)
|
|
2528
|
+
throw fail("limit", "Policy input exceeds depth 20.");
|
|
2529
|
+
if (v === null || typeof v === "boolean")
|
|
2530
|
+
return add(v === null ? 4 : v ? 4 : 5);
|
|
2531
|
+
if (typeof v === "string")
|
|
2532
|
+
return add(Buffer.byteLength(JSON.stringify(v)));
|
|
2533
|
+
if (typeof v === "number") {
|
|
2534
|
+
const usd = context && path2.length === 2 && path2[0] === "cost" && (path2[1] === "costUsd" || path2[1] === "maxCostUsd");
|
|
2535
|
+
if (!Number.isFinite(v) || !usd && Number.isInteger(v) && !Number.isSafeInteger(v))
|
|
2536
|
+
throw fail("limit", "Policy numbers must be finite and integers must be safe.");
|
|
2537
|
+
return add(Buffer.byteLength(JSON.stringify(v)));
|
|
2538
|
+
}
|
|
2539
|
+
if (typeof v !== "object" || ancestors.has(v))
|
|
2540
|
+
throw fail("limit", "Policy input must be acyclic JSON.");
|
|
2541
|
+
const array = Array.isArray(v);
|
|
2542
|
+
if (Object.getPrototypeOf(v) !== (array ? Array.prototype : Object.prototype) && Object.getPrototypeOf(v) !== null)
|
|
2543
|
+
throw fail("limit", "Policy input must contain only plain JSON objects.");
|
|
2544
|
+
if (Object.getOwnPropertySymbols(v).length)
|
|
2545
|
+
throw fail("limit", "Policy input has symbol keys.");
|
|
2546
|
+
const keys = Object.getOwnPropertyNames(v).filter((k) => !array || k !== "length");
|
|
2547
|
+
if (array && (keys.length !== v.length || keys.some((k, i) => k !== String(i))))
|
|
2548
|
+
throw fail("limit", "Policy input must contain dense JSON arrays.");
|
|
2549
|
+
ancestors.add(v);
|
|
2550
|
+
add(2);
|
|
2551
|
+
for (const [i, key] of keys.entries()) {
|
|
2552
|
+
const descriptor = Object.getOwnPropertyDescriptor(v, key);
|
|
2553
|
+
if (forbidden2.has(key) || !descriptor.enumerable || !("value" in descriptor))
|
|
2554
|
+
throw fail("limit", "Policy input has a forbidden key or non-JSON property.");
|
|
2555
|
+
if (i)
|
|
2556
|
+
add(1);
|
|
2557
|
+
if (!array)
|
|
2558
|
+
add(Buffer.byteLength(JSON.stringify(key)) + 1);
|
|
2559
|
+
visit(descriptor.value, [...path2, key]);
|
|
2560
|
+
}
|
|
2561
|
+
ancestors.delete(v);
|
|
2562
|
+
};
|
|
2563
|
+
visit(value, []);
|
|
2564
|
+
return bytes3;
|
|
2565
|
+
}
|
|
2566
|
+
function workerUrl() {
|
|
2567
|
+
for (const path2 of ["./worker.js", "./policies/worker.js", "../../dist/policies/worker.js"]) {
|
|
2568
|
+
const url = new URL(path2, import.meta.url);
|
|
2569
|
+
if (existsSync(url))
|
|
2570
|
+
return url;
|
|
2571
|
+
}
|
|
2572
|
+
throw fail("worker", "Policy worker is missing. Build the coordinator before evaluating policies.");
|
|
2573
|
+
}
|
|
2574
|
+
var PolicyEvaluator = class {
|
|
2575
|
+
slots = [];
|
|
2576
|
+
queue = [];
|
|
2577
|
+
sequence = 0;
|
|
2578
|
+
closed = false;
|
|
2579
|
+
closing;
|
|
2580
|
+
terminations = /* @__PURE__ */ new Set();
|
|
2581
|
+
/** Parse and type-check off-thread. Does not evaluate the expression or change counters. */
|
|
2582
|
+
async validateRule(rule) {
|
|
2583
|
+
try {
|
|
2584
|
+
checkPolicyJson(rule, 2 * 1024 * 1024);
|
|
2585
|
+
return await this.submit({ type: "validate", rule });
|
|
2586
|
+
} catch (error) {
|
|
2587
|
+
return {
|
|
2588
|
+
valid: false,
|
|
2589
|
+
error: error instanceof PolicyEvaluatorError ? error.failure : {
|
|
2590
|
+
kind: "worker",
|
|
2591
|
+
message: "Policy validation failed.",
|
|
2592
|
+
range: null
|
|
2593
|
+
}
|
|
2594
|
+
};
|
|
2595
|
+
}
|
|
2596
|
+
}
|
|
2597
|
+
/** One result per supplied rule, in order. Inapplicable rules are no-match.
|
|
2598
|
+
* Rule state is isolated by id; pool/input failures return result:null,error for every rule.
|
|
2599
|
+
*/
|
|
2600
|
+
async evaluateRules(rules, context, countersByRule) {
|
|
2601
|
+
if (!Array.isArray(rules) || Object.keys(rules).length !== rules.length)
|
|
2602
|
+
throw fail("limit", "Policy rules must be a dense JSON array.");
|
|
2603
|
+
const identities = Array.isArray(rules) ? Array.from({ length: rules.length }, (_, i) => {
|
|
2604
|
+
const rule = Object.getOwnPropertyDescriptor(rules, String(i))?.value;
|
|
2605
|
+
return {
|
|
2606
|
+
ruleId: rule && typeof rule === "object" ? Object.getOwnPropertyDescriptor(rule, "id")?.value : "",
|
|
2607
|
+
ruleRevision: rule && typeof rule === "object" ? Object.getOwnPropertyDescriptor(rule, "revision")?.value : 0
|
|
2608
|
+
};
|
|
2609
|
+
}) : [];
|
|
2610
|
+
try {
|
|
2611
|
+
const ruleBytes = checkPolicyJson(rules, 2 * 1024 * 1024);
|
|
2612
|
+
const contextBytes = checkPolicyJson(context, 65536, true);
|
|
2613
|
+
const counterBytes = checkPolicyJson(countersByRule, 2 * 1024 * 1024);
|
|
2614
|
+
if (!Array.isArray(rules) || rules.some((rule) => !rule || typeof rule !== "object") || !context || typeof context !== "object" || Array.isArray(context) || !countersByRule || typeof countersByRule !== "object" || Array.isArray(countersByRule))
|
|
2615
|
+
throw fail("limit", "Invalid policy evaluation input.");
|
|
2616
|
+
if (ruleBytes + contextBytes + counterBytes > 2 * 1024 * 1024)
|
|
2617
|
+
throw fail("limit", "Policy input is too large to evaluate.");
|
|
2618
|
+
if (rules.filter((rule) => rule.enabled).length > 128)
|
|
2619
|
+
throw fail("limit", "At most 128 enabled policy rules may be evaluated.");
|
|
2620
|
+
for (const rule of rules) {
|
|
2621
|
+
if (!rule.enabled)
|
|
2622
|
+
continue;
|
|
2623
|
+
const counters = Object.hasOwn(countersByRule, rule.id) ? countersByRule[rule.id] : {};
|
|
2624
|
+
checkPolicyJson({ ...context, counters }, 65536, true);
|
|
2625
|
+
}
|
|
2626
|
+
return await this.submit({
|
|
2627
|
+
type: "evaluate",
|
|
2628
|
+
rules,
|
|
2629
|
+
context,
|
|
2630
|
+
countersByRule
|
|
2631
|
+
});
|
|
2632
|
+
} catch (error) {
|
|
2633
|
+
const failure = error instanceof PolicyEvaluatorError ? error.failure : {
|
|
2634
|
+
kind: "worker",
|
|
2635
|
+
message: "Policy evaluator failed.",
|
|
2636
|
+
range: null
|
|
2637
|
+
};
|
|
2638
|
+
return identities.map((identity) => ({ ...identity, result: null, error: failure }));
|
|
2639
|
+
}
|
|
2640
|
+
}
|
|
2641
|
+
submit(input) {
|
|
2642
|
+
if (this.closed)
|
|
2643
|
+
return Promise.reject(fail("worker", "Policy evaluator is closed."));
|
|
2644
|
+
if (this.queue.length >= 256)
|
|
2645
|
+
return Promise.reject(fail("limit", "Policy evaluator queue is full."));
|
|
2646
|
+
const json = JSON.stringify(input);
|
|
2647
|
+
if (Buffer.byteLength(json) > 2 * 1024 * 1024)
|
|
2648
|
+
return Promise.reject(fail("limit", "Policy input is too large to evaluate."));
|
|
2649
|
+
return new Promise((resolve, reject) => {
|
|
2650
|
+
this.queue.push({ id: ++this.sequence, input: JSON.parse(json), resolve, reject });
|
|
2651
|
+
this.fill();
|
|
2652
|
+
});
|
|
2653
|
+
}
|
|
2654
|
+
fill() {
|
|
2655
|
+
if (this.closed)
|
|
2656
|
+
return;
|
|
2657
|
+
try {
|
|
2658
|
+
while (this.slots.length < 2)
|
|
2659
|
+
this.start();
|
|
2660
|
+
} catch (error) {
|
|
2661
|
+
this.rejectQueue(error instanceof PolicyEvaluatorError ? error : fail("worker", "Policy worker could not be started."));
|
|
2662
|
+
for (const slot of this.slots)
|
|
2663
|
+
if (slot.ready && !slot.job)
|
|
2664
|
+
slot.worker.unref();
|
|
2665
|
+
return;
|
|
2666
|
+
}
|
|
2667
|
+
for (const slot of this.slots) {
|
|
2668
|
+
if (!slot.ready || slot.job)
|
|
2669
|
+
continue;
|
|
2670
|
+
const job = this.queue.shift();
|
|
2671
|
+
if (!job) {
|
|
2672
|
+
slot.worker.unref();
|
|
2673
|
+
continue;
|
|
2674
|
+
}
|
|
2675
|
+
slot.job = job;
|
|
2676
|
+
slot.worker.ref();
|
|
2677
|
+
slot.timer = setTimeout(() => this.broken(slot, fail("timeout", "Policy evaluation exceeded 250 ms.")), 250);
|
|
2678
|
+
try {
|
|
2679
|
+
slot.worker.postMessage({ id: job.id, job: job.input });
|
|
2680
|
+
} catch {
|
|
2681
|
+
this.broken(slot, fail("worker", "Policy worker could not accept the job."));
|
|
2682
|
+
}
|
|
2683
|
+
}
|
|
2684
|
+
}
|
|
2685
|
+
start() {
|
|
2686
|
+
const worker = new Worker(workerUrl(), {
|
|
2687
|
+
execArgv: [],
|
|
2688
|
+
resourceLimits: { maxOldGenerationSizeMb: 64, stackSizeMb: 4 }
|
|
2689
|
+
});
|
|
2690
|
+
const slot = { worker, ready: false };
|
|
2691
|
+
this.slots.push(slot);
|
|
2692
|
+
slot.timer = setTimeout(() => this.broken(slot, fail("timeout", "Policy worker startup exceeded 5 seconds.")), 5e3);
|
|
2693
|
+
worker.on("message", (reply) => {
|
|
2694
|
+
if (!this.slots.includes(slot))
|
|
2695
|
+
return;
|
|
2696
|
+
if (reply.type === "ready" && !slot.ready) {
|
|
2697
|
+
clearTimeout(slot.timer);
|
|
2698
|
+
slot.ready = true;
|
|
2699
|
+
this.fill();
|
|
2700
|
+
} else if (slot.ready && slot.job && reply.type !== "ready" && reply.id === slot.job.id) {
|
|
2701
|
+
clearTimeout(slot.timer);
|
|
2702
|
+
const job = slot.job;
|
|
2703
|
+
slot.job = void 0;
|
|
2704
|
+
if (reply.type === "failure")
|
|
2705
|
+
job.reject(new PolicyEvaluatorError(reply.error));
|
|
2706
|
+
else
|
|
2707
|
+
job.resolve(reply.value);
|
|
2708
|
+
this.fill();
|
|
2709
|
+
} else
|
|
2710
|
+
this.broken(slot, fail("worker", "Invalid policy worker response."));
|
|
2711
|
+
});
|
|
2712
|
+
worker.on("error", () => this.broken(slot, fail("worker", "Policy worker failed or exceeded its resource limits.")));
|
|
2713
|
+
worker.on("exit", () => this.broken(slot, fail("worker", "Policy worker exited unexpectedly.")));
|
|
2714
|
+
}
|
|
2715
|
+
rejectQueue(error) {
|
|
2716
|
+
for (const job of this.queue.splice(0))
|
|
2717
|
+
job.reject(error);
|
|
2718
|
+
}
|
|
2719
|
+
broken(slot, error) {
|
|
2720
|
+
if (!this.slots.includes(slot))
|
|
2721
|
+
return;
|
|
2722
|
+
this.slots.splice(this.slots.indexOf(slot), 1);
|
|
2723
|
+
clearTimeout(slot.timer);
|
|
2724
|
+
slot.job?.reject(error);
|
|
2725
|
+
this.terminate(slot.worker);
|
|
2726
|
+
if (!slot.ready)
|
|
2727
|
+
this.rejectQueue(error);
|
|
2728
|
+
if (!this.closed && slot.ready)
|
|
2729
|
+
this.fill();
|
|
2730
|
+
}
|
|
2731
|
+
terminate(worker) {
|
|
2732
|
+
const pending = worker.terminate();
|
|
2733
|
+
this.terminations.add(pending);
|
|
2734
|
+
void pending.then(() => this.terminations.delete(pending), () => this.terminations.delete(pending));
|
|
2735
|
+
}
|
|
2736
|
+
close() {
|
|
2737
|
+
if (this.closing)
|
|
2738
|
+
return this.closing;
|
|
2739
|
+
this.closed = true;
|
|
2740
|
+
const error = fail("worker", "Policy evaluator is closed.");
|
|
2741
|
+
this.rejectQueue(error);
|
|
2742
|
+
for (const slot of this.slots.splice(0)) {
|
|
2743
|
+
clearTimeout(slot.timer);
|
|
2744
|
+
slot.job?.reject(error);
|
|
2745
|
+
this.terminate(slot.worker);
|
|
2746
|
+
}
|
|
2747
|
+
this.closing = Promise.all(this.terminations).then(() => void 0);
|
|
2748
|
+
return this.closing;
|
|
2749
|
+
}
|
|
2750
|
+
};
|
|
2751
|
+
var evaluator = new PolicyEvaluator();
|
|
2752
|
+
|
|
2753
|
+
// packages/coordinator/dist/policies/worker.js
|
|
2754
|
+
var env = new Environment({
|
|
2755
|
+
unlistedVariablesAreDyn: false,
|
|
2756
|
+
homogeneousAggregateLiterals: false,
|
|
2757
|
+
limits: {
|
|
2758
|
+
maxAstNodes: 2e3,
|
|
2759
|
+
maxDepth: 40,
|
|
2760
|
+
maxListElements: 100,
|
|
2761
|
+
maxMapEntries: 100,
|
|
2762
|
+
maxCallArguments: 16
|
|
2763
|
+
}
|
|
2764
|
+
});
|
|
2765
|
+
for (const name of [
|
|
2766
|
+
"phase",
|
|
2767
|
+
"action",
|
|
2768
|
+
"tool",
|
|
2769
|
+
"request",
|
|
2770
|
+
"session",
|
|
2771
|
+
"task",
|
|
2772
|
+
"target",
|
|
2773
|
+
"cost",
|
|
2774
|
+
"counters"
|
|
2775
|
+
]) {
|
|
2776
|
+
env.registerVariable(name, name === "phase" || name === "action" ? "string" : name === "counters" ? "map<string, int>" : "dyn");
|
|
2777
|
+
}
|
|
2778
|
+
var cache = /* @__PURE__ */ new Map();
|
|
2779
|
+
function compile(rule) {
|
|
2780
|
+
const key = JSON.stringify([rule.id, rule.revision]);
|
|
2781
|
+
const cached = cache.get(key);
|
|
2782
|
+
if (cached) {
|
|
2783
|
+
if (cached.expression !== rule.expression)
|
|
2784
|
+
throw new PolicyEvaluatorError({
|
|
2785
|
+
kind: "type",
|
|
2786
|
+
message: "Policy expression changed without a new revision.",
|
|
2787
|
+
range: null
|
|
2788
|
+
});
|
|
2789
|
+
cache.delete(key);
|
|
2790
|
+
cache.set(key, cached);
|
|
2791
|
+
return cached;
|
|
2792
|
+
}
|
|
2793
|
+
let callable;
|
|
2794
|
+
try {
|
|
2795
|
+
callable = env.parse(rule.expression);
|
|
2796
|
+
} catch (error) {
|
|
2797
|
+
throw new PolicyEvaluatorError(diagnostic(error, "parse"));
|
|
2798
|
+
}
|
|
2799
|
+
checkMapKeys(callable.ast);
|
|
2800
|
+
const checked = callable.check();
|
|
2801
|
+
if (!checked.valid)
|
|
2802
|
+
throw new PolicyEvaluatorError(diagnostic(checked.error, "type"));
|
|
2803
|
+
const returnType = checked.type === "null" ? "null_type" : checked.type;
|
|
2804
|
+
if (returnType !== "null_type" && returnType !== "dyn" && returnType !== "map" && !returnType.startsWith("map<"))
|
|
2805
|
+
throw new PolicyEvaluatorError({
|
|
2806
|
+
kind: "type",
|
|
2807
|
+
message: "Policy expression must return null or a verdict map.",
|
|
2808
|
+
range: null
|
|
2809
|
+
});
|
|
2810
|
+
cache.set(key, { expression: rule.expression, callable, returnType });
|
|
2811
|
+
if (cache.size > 256)
|
|
2812
|
+
cache.delete(cache.keys().next().value);
|
|
2813
|
+
return { callable, returnType };
|
|
2814
|
+
}
|
|
2815
|
+
function checkMapKeys(node) {
|
|
2816
|
+
if (node.op === "map") {
|
|
2817
|
+
for (const [key] of node.args) {
|
|
2818
|
+
if (key.op === "value" && ["__proto__", "prototype", "constructor"].includes(String(key.args)))
|
|
2819
|
+
throw new PolicyEvaluatorError({
|
|
2820
|
+
kind: "type",
|
|
2821
|
+
message: "Policy maps contain a forbidden key.",
|
|
2822
|
+
range: key.range
|
|
2823
|
+
});
|
|
2824
|
+
}
|
|
2825
|
+
}
|
|
2826
|
+
const visit = (value) => {
|
|
2827
|
+
if (Array.isArray(value))
|
|
2828
|
+
value.forEach(visit);
|
|
2829
|
+
else if (value && typeof value === "object" && "op" in value && "args" in value)
|
|
2830
|
+
checkMapKeys(value);
|
|
2831
|
+
};
|
|
2832
|
+
visit(node.args);
|
|
2833
|
+
}
|
|
2834
|
+
function diagnostic(error, kind) {
|
|
2835
|
+
if (error instanceof PolicyEvaluatorError)
|
|
2836
|
+
return error.failure;
|
|
2837
|
+
const e = error;
|
|
2838
|
+
return {
|
|
2839
|
+
kind,
|
|
2840
|
+
message: (e?.message || "Policy evaluation failed.").slice(0, 4e3),
|
|
2841
|
+
range: e?.range ? { start: e.range.start, end: e.range.end } : null
|
|
2842
|
+
};
|
|
2843
|
+
}
|
|
2844
|
+
function toCel(value, path2 = []) {
|
|
2845
|
+
if (typeof value === "number") {
|
|
2846
|
+
const usd = path2.length === 2 && path2[0] === "cost" && (path2[1] === "costUsd" || path2[1] === "maxCostUsd");
|
|
2847
|
+
return Number.isInteger(value) && !usd ? BigInt(value) : value;
|
|
2848
|
+
}
|
|
2849
|
+
if (value === null || typeof value !== "object")
|
|
2850
|
+
return value;
|
|
2851
|
+
if (Array.isArray(value))
|
|
2852
|
+
return value.map((v, i) => toCel(v, [...path2, String(i)]));
|
|
2853
|
+
return Object.fromEntries(Object.entries(value).map(([k, v]) => [k, toCel(v, [...path2, k])]));
|
|
2854
|
+
}
|
|
2855
|
+
function fromCel(value, depth = 0) {
|
|
2856
|
+
if (depth > 20)
|
|
2857
|
+
throw new Error("Policy result exceeds depth 20.");
|
|
2858
|
+
if (typeof value === "bigint") {
|
|
2859
|
+
if (value > BigInt(Number.MAX_SAFE_INTEGER) || value < BigInt(Number.MIN_SAFE_INTEGER))
|
|
2860
|
+
throw new Error("Policy result integer is outside the safe JSON range.");
|
|
2861
|
+
return Number(value);
|
|
2862
|
+
}
|
|
2863
|
+
if (value === null || typeof value === "string" || typeof value === "boolean" || typeof value === "number")
|
|
2864
|
+
return value;
|
|
2865
|
+
if (Array.isArray(value))
|
|
2866
|
+
return value.map((v) => fromCel(v, depth + 1));
|
|
2867
|
+
if (value instanceof Map) {
|
|
2868
|
+
if ([...value.keys()].some((key) => typeof key !== "string"))
|
|
2869
|
+
throw new Error("Policy result map keys must be strings.");
|
|
2870
|
+
return Object.fromEntries([...value].map(([key, v]) => [key, fromCel(v, depth + 1)]));
|
|
2871
|
+
}
|
|
2872
|
+
if (typeof value !== "object" || Object.getPrototypeOf(value) !== Object.prototype && Object.getPrototypeOf(value) !== null)
|
|
2873
|
+
throw new Error("Policy result must be JSON.");
|
|
2874
|
+
return Object.fromEntries(Object.entries(value).map(([k, v]) => [k, fromCel(v, depth + 1)]));
|
|
2875
|
+
}
|
|
2876
|
+
function evaluate(job) {
|
|
2877
|
+
checkPolicyJson(job.rules, 2 * 1024 * 1024);
|
|
2878
|
+
checkPolicyJson(job.context, 65536, true);
|
|
2879
|
+
checkPolicyJson(job.countersByRule, 2 * 1024 * 1024);
|
|
2880
|
+
if (Buffer.byteLength(JSON.stringify(job)) > 2 * 1024 * 1024)
|
|
2881
|
+
throw new PolicyEvaluatorError({
|
|
2882
|
+
kind: "limit",
|
|
2883
|
+
message: "Policy input is too large to evaluate.",
|
|
2884
|
+
range: null
|
|
2885
|
+
});
|
|
2886
|
+
const rules = job.rules.map((r) => PolicyRule.parse(r));
|
|
2887
|
+
if (rules.filter((r) => r.enabled).length > 128)
|
|
2888
|
+
throw new Error("At most 128 enabled policy rules may be evaluated.");
|
|
2889
|
+
PolicyContext.parse({ ...job.context, counters: {} });
|
|
2890
|
+
return rules.map((rule) => {
|
|
2891
|
+
const identity = { ruleId: rule.id, ruleRevision: rule.revision };
|
|
2892
|
+
if (!rule.enabled || !rule.phases.includes(job.context.phase))
|
|
2893
|
+
return { ...identity, result: null, error: null };
|
|
2894
|
+
try {
|
|
2895
|
+
const counters = PolicyCounterMap.parse(Object.hasOwn(job.countersByRule, rule.id) ? job.countersByRule[rule.id] : {});
|
|
2896
|
+
const input = { ...job.context, counters };
|
|
2897
|
+
checkPolicyJson(input, 65536, true);
|
|
2898
|
+
const context = PolicyContext.parse(input);
|
|
2899
|
+
const { callable } = compile(rule);
|
|
2900
|
+
let raw;
|
|
2901
|
+
try {
|
|
2902
|
+
raw = callable(toCel(context));
|
|
2903
|
+
} catch (error) {
|
|
2904
|
+
throw new PolicyEvaluatorError(diagnostic(error, "runtime"));
|
|
2905
|
+
}
|
|
2906
|
+
try {
|
|
2907
|
+
if (raw && typeof raw === "object" && "state_updates" in raw) {
|
|
2908
|
+
const updates = raw.state_updates;
|
|
2909
|
+
if (!updates || typeof updates !== "object" || Array.isArray(updates) || (updates instanceof Map ? [...updates.values()] : Object.values(updates)).some((v) => typeof v !== "bigint"))
|
|
2910
|
+
throw new Error("Policy state_updates must be a map of CEL int values.");
|
|
2911
|
+
}
|
|
2912
|
+
const result = fromCel(raw);
|
|
2913
|
+
checkPolicyJson(result, 65536);
|
|
2914
|
+
const parsed = PolicyRuleResult.parse(result);
|
|
2915
|
+
if (parsed?.state_updates)
|
|
2916
|
+
PolicyCounterMap.parse({ ...counters, ...parsed.state_updates });
|
|
2917
|
+
return { ...identity, result: parsed, error: null };
|
|
2918
|
+
} catch (error) {
|
|
2919
|
+
throw new PolicyEvaluatorError(diagnostic(error, "runtime"));
|
|
2920
|
+
}
|
|
2921
|
+
} catch (error) {
|
|
2922
|
+
return { ...identity, result: null, error: diagnostic(error, "type") };
|
|
2923
|
+
}
|
|
2924
|
+
});
|
|
2925
|
+
}
|
|
2926
|
+
if (parentPort) {
|
|
2927
|
+
const port = parentPort;
|
|
2928
|
+
port.on("message", ({ id, job }) => {
|
|
2929
|
+
let reply;
|
|
2930
|
+
try {
|
|
2931
|
+
if (job.type === "validate") {
|
|
2932
|
+
try {
|
|
2933
|
+
checkPolicyJson(job.rule, 2 * 1024 * 1024);
|
|
2934
|
+
const { returnType } = compile(PolicyRule.parse(job.rule));
|
|
2935
|
+
reply = { type: "result", id, value: { valid: true, returnType } };
|
|
2936
|
+
} catch (error) {
|
|
2937
|
+
reply = {
|
|
2938
|
+
type: "result",
|
|
2939
|
+
id,
|
|
2940
|
+
value: { valid: false, error: diagnostic(error, "type") }
|
|
2941
|
+
};
|
|
2942
|
+
}
|
|
2943
|
+
} else
|
|
2944
|
+
reply = { type: "result", id, value: evaluate(job) };
|
|
2945
|
+
} catch (error) {
|
|
2946
|
+
reply = { type: "failure", id, error: diagnostic(error, "type") };
|
|
2947
|
+
}
|
|
2948
|
+
port.postMessage(reply);
|
|
2949
|
+
});
|
|
2950
|
+
port.postMessage({ type: "ready" });
|
|
2951
|
+
}
|