codex-computer-use-mcp 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CONTRIBUTING.md +26 -0
- package/LICENSE +21 -0
- package/PROOF.md +81 -0
- package/README.md +195 -0
- package/SECURITY.md +38 -0
- package/dist/audit.d.ts +25 -0
- package/dist/audit.js +42 -0
- package/dist/audit.js.map +1 -0
- package/dist/config.d.ts +12 -0
- package/dist/config.js +105 -0
- package/dist/config.js.map +1 -0
- package/dist/lock.d.ts +16 -0
- package/dist/lock.js +108 -0
- package/dist/lock.js.map +1 -0
- package/dist/mcp-server.d.ts +2 -0
- package/dist/mcp-server.js +134 -0
- package/dist/mcp-server.js.map +1 -0
- package/dist/policy.d.ts +42 -0
- package/dist/policy.js +428 -0
- package/dist/policy.js.map +1 -0
- package/dist/prompt.d.ts +62 -0
- package/dist/prompt.js +119 -0
- package/dist/prompt.js.map +1 -0
- package/dist/runner.d.ts +55 -0
- package/dist/runner.js +494 -0
- package/dist/runner.js.map +1 -0
- package/dist/service.d.ts +17 -0
- package/dist/service.js +382 -0
- package/dist/service.js.map +1 -0
- package/dist/system.d.ts +17 -0
- package/dist/system.js +228 -0
- package/dist/system.js.map +1 -0
- package/integrations/pi/README.md +50 -0
- package/integrations/pi/index.ts +135 -0
- package/integrations/pi/mcp.json.example +15 -0
- package/npm-shrinkwrap.json +1600 -0
- package/package.json +65 -0
package/dist/policy.js
ADDED
|
@@ -0,0 +1,428 @@
|
|
|
1
|
+
export const MODEL = "gpt-5.6-sol";
|
|
2
|
+
export const MODEL_REASONING = "xhigh";
|
|
3
|
+
export const COMPUTER_USE_TOOLS = [
|
|
4
|
+
"list_apps",
|
|
5
|
+
"get_app_state",
|
|
6
|
+
"click",
|
|
7
|
+
"perform_secondary_action",
|
|
8
|
+
"set_value",
|
|
9
|
+
"select_text",
|
|
10
|
+
"scroll",
|
|
11
|
+
"drag",
|
|
12
|
+
"press_key",
|
|
13
|
+
"type_text",
|
|
14
|
+
];
|
|
15
|
+
export const DICTIONARY_BUNDLE_ID = "com.apple.Dictionary";
|
|
16
|
+
export const DICTIONARY_NEUTRAL_QUERY = "dictionary";
|
|
17
|
+
export class PolicyError extends Error {
|
|
18
|
+
constructor(message) {
|
|
19
|
+
super(message);
|
|
20
|
+
this.name = "PolicyError";
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
const BLOCKED_APP_PATTERNS = [
|
|
24
|
+
{
|
|
25
|
+
pattern: /(?:^|\b)(?:terminal|iterm\w*|ghostty|cmux|warp|wezterm|alacritty|kitty|hyper|tabby)(?:\b|$)/i,
|
|
26
|
+
category: "terminal/shell",
|
|
27
|
+
},
|
|
28
|
+
{ pattern: /(?:^|\b)(?:chatgpt|codex)(?:\b|$)/i, category: "agent host" },
|
|
29
|
+
{ pattern: /(?:^|\b)(?:keychain|1password|bitwarden|dashlane|lastpass|password)(?:\b|$)/i, category: "credentials" },
|
|
30
|
+
{ pattern: /(?:^|\b)(?:mail|messages|slack|whatsapp|teams|discord|telegram|signal)(?:\b|$)/i, category: "communications" },
|
|
31
|
+
{
|
|
32
|
+
pattern: /(?:^|\b)(?:safari|chrome|firefox|arc|browser|edge|opera|vivaldi|brave|orion)(?:\b|$)/i,
|
|
33
|
+
category: "browser",
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
pattern: /(?:^|\b)(?:vscode|vs code|visual studio code|cursor|windsurf|zed)(?:\b|$)/i,
|
|
37
|
+
category: "editor/agent host",
|
|
38
|
+
},
|
|
39
|
+
{ pattern: /(?:^|\b)(?:system settings|system preferences|settings|wallet|app store)(?:\b|$)/i, category: "system/payment settings" },
|
|
40
|
+
];
|
|
41
|
+
const BLOCKED_BUNDLE_ID_PATTERNS = [
|
|
42
|
+
{
|
|
43
|
+
pattern: /(?:^|\.)(?:terminal|iterm2?|ghostty|cmuxterm|warp(?:-stable)?|wezterm|alacritty|kitty|hyper|tabby)(?:\.|$)/i,
|
|
44
|
+
category: "terminal/shell",
|
|
45
|
+
},
|
|
46
|
+
{ pattern: /(?:^|\.)(?:chatgpt|codex|chat)(?:\.|$)/i, category: "agent host" },
|
|
47
|
+
{
|
|
48
|
+
pattern: /(?:^|\.)(?:keychainaccess|1password|bitwarden|dashlane\w*|lastpass\w*|passwords?)(?:\.|$)/i,
|
|
49
|
+
category: "credentials",
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
pattern: /(?:^|\.)(?:mail|mobilesms|slack(?:macgap)?|whatsapp|teams2?|discord|telegram|signal(?:-desktop)?)(?:\.|$)/i,
|
|
53
|
+
category: "communications",
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
pattern: /(?:^|\.)(?:safari|chrome|firefox|browser|edgemac|opera|vivaldi|brave|orion|kagimacos)(?:\.|$)/i,
|
|
57
|
+
category: "browser",
|
|
58
|
+
},
|
|
59
|
+
{ pattern: /(?:^|\.)(?:vscode\w*|cursor|windsurf|zed)(?:\.|$)/i, category: "editor/agent host" },
|
|
60
|
+
{ pattern: /(?:^|\.)(?:systempreferences|wallet|appstore)(?:\.|$)/i, category: "system/payment settings" },
|
|
61
|
+
];
|
|
62
|
+
const BLOCKED_OPAQUE_BUNDLE_IDS = new Map([
|
|
63
|
+
["com.todesktop.230313mzl4w4u92", "editor/agent host"], // Cursor
|
|
64
|
+
]);
|
|
65
|
+
function blockedSafeAppCategory(value) {
|
|
66
|
+
for (const blocked of BLOCKED_APP_PATTERNS) {
|
|
67
|
+
if (blocked.pattern.test(value))
|
|
68
|
+
return blocked.category;
|
|
69
|
+
}
|
|
70
|
+
if (/^[A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)+$/.test(value)) {
|
|
71
|
+
const exactCategory = BLOCKED_OPAQUE_BUNDLE_IDS.get(value.toLowerCase());
|
|
72
|
+
if (exactCategory)
|
|
73
|
+
return exactCategory;
|
|
74
|
+
for (const blocked of BLOCKED_BUNDLE_ID_PATTERNS) {
|
|
75
|
+
if (blocked.pattern.test(value))
|
|
76
|
+
return blocked.category;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return undefined;
|
|
80
|
+
}
|
|
81
|
+
const BLOCKED_TASK_PATTERNS = [
|
|
82
|
+
{ pattern: /\b(?:send|post|publish|share|upload|message|email|call)\b/i, category: "external communication" },
|
|
83
|
+
{ pattern: /\b(?:buy|purchase|checkout|pay|payment|subscribe)\b/i, category: "purchase/payment" },
|
|
84
|
+
{ pattern: /\b(?:password|passcode|credential|secret|token|api key|login|log in|sign in|authenticate)\b/i, category: "credentials/authentication" },
|
|
85
|
+
{ pattern: /\b(?:sudo|admin|administrator|privacy prompt|permission prompt|tcc)\b/i, category: "admin/privacy approval" },
|
|
86
|
+
{ pattern: /\b(?:delete|erase|trash|uninstall|wipe)\b/i, category: "destructive deletion" },
|
|
87
|
+
];
|
|
88
|
+
function validateSafeApp(app) {
|
|
89
|
+
if (typeof app !== "string")
|
|
90
|
+
throw new PolicyError("inspect/act requires an app name or bundle identifier");
|
|
91
|
+
const trimmed = app.trim();
|
|
92
|
+
if (!trimmed || trimmed.length > 120)
|
|
93
|
+
throw new PolicyError("App must be 1-120 characters");
|
|
94
|
+
if (/[\u0000-\u001f\u007f\n\r]/.test(trimmed) || trimmed.includes("/") || /:/.test(trimmed)) {
|
|
95
|
+
throw new PolicyError("App must be a name or bundle identifier, not a path, URL, or control string");
|
|
96
|
+
}
|
|
97
|
+
const blockedCategory = blockedSafeAppCategory(trimmed);
|
|
98
|
+
if (blockedCategory)
|
|
99
|
+
throw new PolicyError(`App is blocked by the ${blockedCategory} safety policy`);
|
|
100
|
+
return trimmed;
|
|
101
|
+
}
|
|
102
|
+
function validateFullApp(app) {
|
|
103
|
+
if (typeof app !== "string")
|
|
104
|
+
throw new PolicyError("inspect/act requires an app target");
|
|
105
|
+
const trimmed = app.trim();
|
|
106
|
+
if (!trimmed || trimmed.length > 500)
|
|
107
|
+
throw new PolicyError("Full-permissions app target must be 1-500 characters");
|
|
108
|
+
if (/[\u0000-\u001f\u007f]/.test(trimmed))
|
|
109
|
+
throw new PolicyError("App target contains unsupported control characters");
|
|
110
|
+
return trimmed;
|
|
111
|
+
}
|
|
112
|
+
function validateSafeTask(task) {
|
|
113
|
+
if (typeof task !== "string")
|
|
114
|
+
throw new PolicyError("act requires a concrete task");
|
|
115
|
+
const trimmed = task.trim();
|
|
116
|
+
if (!trimmed || trimmed.length > 1000)
|
|
117
|
+
throw new PolicyError("Task must be 1-1000 characters");
|
|
118
|
+
if (/[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f]/.test(trimmed)) {
|
|
119
|
+
throw new PolicyError("Task contains unsupported control characters");
|
|
120
|
+
}
|
|
121
|
+
for (const blocked of BLOCKED_TASK_PATTERNS) {
|
|
122
|
+
if (blocked.pattern.test(trimmed))
|
|
123
|
+
throw new PolicyError(`Task is blocked as ${blocked.category}`);
|
|
124
|
+
}
|
|
125
|
+
return trimmed;
|
|
126
|
+
}
|
|
127
|
+
function isDictionarySelector(value) {
|
|
128
|
+
if (typeof value !== "string")
|
|
129
|
+
return false;
|
|
130
|
+
const normalized = value.trim().toLowerCase();
|
|
131
|
+
return normalized === "dictionary" || normalized === DICTIONARY_BUNDLE_ID.toLowerCase();
|
|
132
|
+
}
|
|
133
|
+
function validateFullTask(task) {
|
|
134
|
+
if (typeof task !== "string")
|
|
135
|
+
throw new PolicyError("act requires a concrete task");
|
|
136
|
+
const trimmed = task.trim();
|
|
137
|
+
if (!trimmed || trimmed.length > 4000)
|
|
138
|
+
throw new PolicyError("Full-permissions task must be 1-4000 characters");
|
|
139
|
+
if (/[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f]/.test(trimmed)) {
|
|
140
|
+
throw new PolicyError("Task contains unsupported control characters");
|
|
141
|
+
}
|
|
142
|
+
return trimmed;
|
|
143
|
+
}
|
|
144
|
+
function validateDictionaryQuery(value) {
|
|
145
|
+
if (typeof value !== "string")
|
|
146
|
+
throw new PolicyError("dictionary_lookup requires a query");
|
|
147
|
+
const trimmed = value.trim();
|
|
148
|
+
if (!trimmed || trimmed.length > 200)
|
|
149
|
+
throw new PolicyError("Dictionary query must be 1-200 characters");
|
|
150
|
+
if (/[\u0000-\u001f\u007f]/.test(trimmed))
|
|
151
|
+
throw new PolicyError("Dictionary query contains unsupported control characters");
|
|
152
|
+
return trimmed;
|
|
153
|
+
}
|
|
154
|
+
function validateCleanupInstructions(value, permissionMode) {
|
|
155
|
+
if (value === undefined)
|
|
156
|
+
return undefined;
|
|
157
|
+
if (typeof value !== "string")
|
|
158
|
+
throw new PolicyError("cleanup_instructions must be text");
|
|
159
|
+
const trimmed = value.trim();
|
|
160
|
+
const maxLength = permissionMode === "full-permissions" ? 2000 : 500;
|
|
161
|
+
if (!trimmed || trimmed.length > maxLength)
|
|
162
|
+
throw new PolicyError(`cleanup_instructions must be 1-${maxLength} characters`);
|
|
163
|
+
if (/[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f]/.test(trimmed)) {
|
|
164
|
+
throw new PolicyError("Cleanup instructions contain unsupported control characters");
|
|
165
|
+
}
|
|
166
|
+
if (permissionMode === "safe") {
|
|
167
|
+
for (const blocked of BLOCKED_TASK_PATTERNS) {
|
|
168
|
+
if (blocked.pattern.test(trimmed))
|
|
169
|
+
throw new PolicyError(`Cleanup instructions are blocked as ${blocked.category}`);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return trimmed;
|
|
173
|
+
}
|
|
174
|
+
function validateRequiredCapabilities(value) {
|
|
175
|
+
if (value === undefined)
|
|
176
|
+
return [];
|
|
177
|
+
if (!Array.isArray(value))
|
|
178
|
+
throw new PolicyError("required_capabilities must be an array");
|
|
179
|
+
const available = new Set(COMPUTER_USE_TOOLS);
|
|
180
|
+
const result = [];
|
|
181
|
+
for (const item of value) {
|
|
182
|
+
if (typeof item !== "string" || !available.has(item))
|
|
183
|
+
throw new PolicyError(`Unknown Computer Use capability: ${String(item)}`);
|
|
184
|
+
if (item === "list_apps" || item === "get_app_state")
|
|
185
|
+
continue;
|
|
186
|
+
if (!result.includes(item))
|
|
187
|
+
result.push(item);
|
|
188
|
+
}
|
|
189
|
+
return result;
|
|
190
|
+
}
|
|
191
|
+
export function validateRequest(input, permissionMode = "safe") {
|
|
192
|
+
if (!input || typeof input !== "object")
|
|
193
|
+
throw new PolicyError("Request must be an object");
|
|
194
|
+
if (permissionMode !== "safe" && permissionMode !== "full-permissions")
|
|
195
|
+
throw new PolicyError("Invalid permission mode");
|
|
196
|
+
if (permissionMode === "safe" && input.mode !== "list") {
|
|
197
|
+
throw new PolicyError("Standalone safe mode permits only list: target and argument checks are observable only after the signed official client dispatches a call. Enable explicit full-permissions only if that broad authorization is acceptable.");
|
|
198
|
+
}
|
|
199
|
+
switch (input.mode) {
|
|
200
|
+
case "list":
|
|
201
|
+
if (input.app !== undefined ||
|
|
202
|
+
input.task !== undefined ||
|
|
203
|
+
input.query !== undefined ||
|
|
204
|
+
input.cleanup !== undefined ||
|
|
205
|
+
input.cleanup_instructions !== undefined ||
|
|
206
|
+
input.required_capabilities !== undefined) {
|
|
207
|
+
throw new PolicyError("list accepts only mode");
|
|
208
|
+
}
|
|
209
|
+
return {
|
|
210
|
+
mode: "list",
|
|
211
|
+
permissionMode,
|
|
212
|
+
cleanup: true,
|
|
213
|
+
requiredCapabilities: [],
|
|
214
|
+
mutating: false,
|
|
215
|
+
maxComputerUseCalls: 1,
|
|
216
|
+
reasoningEffort: "low",
|
|
217
|
+
};
|
|
218
|
+
case "inspect":
|
|
219
|
+
if (input.task !== undefined ||
|
|
220
|
+
input.query !== undefined ||
|
|
221
|
+
input.cleanup !== undefined ||
|
|
222
|
+
input.cleanup_instructions !== undefined ||
|
|
223
|
+
input.required_capabilities !== undefined) {
|
|
224
|
+
throw new PolicyError("inspect accepts only app");
|
|
225
|
+
}
|
|
226
|
+
return {
|
|
227
|
+
mode: "inspect",
|
|
228
|
+
permissionMode,
|
|
229
|
+
app: permissionMode === "full-permissions" ? validateFullApp(input.app) : validateSafeApp(input.app),
|
|
230
|
+
cleanup: true,
|
|
231
|
+
requiredCapabilities: [],
|
|
232
|
+
mutating: false,
|
|
233
|
+
maxComputerUseCalls: 3,
|
|
234
|
+
reasoningEffort: "high",
|
|
235
|
+
};
|
|
236
|
+
case "act": {
|
|
237
|
+
const app = permissionMode === "full-permissions" ? validateFullApp(input.app) : validateSafeApp(input.app);
|
|
238
|
+
if (permissionMode === "safe" && isDictionarySelector(app)) {
|
|
239
|
+
throw new PolicyError("Dictionary is restricted to inspect or dictionary_lookup in safe mode");
|
|
240
|
+
}
|
|
241
|
+
if (input.query !== undefined)
|
|
242
|
+
throw new PolicyError("act does not accept query; use task");
|
|
243
|
+
const cleanup = input.cleanup ?? (permissionMode === "safe");
|
|
244
|
+
if (!cleanup && input.cleanup_instructions !== undefined) {
|
|
245
|
+
throw new PolicyError("act does not accept cleanup_instructions when cleanup is false");
|
|
246
|
+
}
|
|
247
|
+
return {
|
|
248
|
+
mode: "act",
|
|
249
|
+
permissionMode,
|
|
250
|
+
app,
|
|
251
|
+
task: permissionMode === "full-permissions" ? validateFullTask(input.task) : validateSafeTask(input.task),
|
|
252
|
+
cleanup,
|
|
253
|
+
cleanupInstructions: cleanup ? validateCleanupInstructions(input.cleanup_instructions, permissionMode) : undefined,
|
|
254
|
+
requiredCapabilities: validateRequiredCapabilities(input.required_capabilities),
|
|
255
|
+
mutating: true,
|
|
256
|
+
maxComputerUseCalls: 50,
|
|
257
|
+
reasoningEffort: "xhigh",
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
case "dictionary_lookup":
|
|
261
|
+
if (input.app !== undefined ||
|
|
262
|
+
input.task !== undefined ||
|
|
263
|
+
input.cleanup !== undefined ||
|
|
264
|
+
input.cleanup_instructions !== undefined ||
|
|
265
|
+
input.required_capabilities !== undefined) {
|
|
266
|
+
throw new PolicyError("dictionary_lookup accepts only query");
|
|
267
|
+
}
|
|
268
|
+
return {
|
|
269
|
+
mode: "dictionary_lookup",
|
|
270
|
+
permissionMode,
|
|
271
|
+
app: DICTIONARY_BUNDLE_ID,
|
|
272
|
+
query: validateDictionaryQuery(input.query),
|
|
273
|
+
cleanup: true,
|
|
274
|
+
requiredCapabilities: ["set_value"],
|
|
275
|
+
mutating: true,
|
|
276
|
+
maxComputerUseCalls: 8,
|
|
277
|
+
reasoningEffort: "high",
|
|
278
|
+
};
|
|
279
|
+
default:
|
|
280
|
+
throw new PolicyError(`Unsupported mode: ${String(input.mode)}`);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
export function allowedToolsForRequest(request) {
|
|
284
|
+
switch (request.mode) {
|
|
285
|
+
case "list":
|
|
286
|
+
return ["list_apps"];
|
|
287
|
+
case "inspect":
|
|
288
|
+
return ["list_apps", "get_app_state"];
|
|
289
|
+
case "act":
|
|
290
|
+
return [...COMPUTER_USE_TOOLS];
|
|
291
|
+
case "dictionary_lookup":
|
|
292
|
+
return ["get_app_state", "set_value", "scroll"];
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
export function isDictionaryAlwaysAllowed(request, resolvedBundleId, verifiedSystemDictionary) {
|
|
296
|
+
return (request.permissionMode === "safe" &&
|
|
297
|
+
verifiedSystemDictionary &&
|
|
298
|
+
resolvedBundleId === DICTIONARY_BUNDLE_ID &&
|
|
299
|
+
(request.mode === "inspect" || request.mode === "dictionary_lookup"));
|
|
300
|
+
}
|
|
301
|
+
export function requiresPiConfirmation(request, resolvedBundleId, verifiedSystemDictionary) {
|
|
302
|
+
if (request.permissionMode === "full-permissions")
|
|
303
|
+
return false;
|
|
304
|
+
return request.mode !== "list" && !isDictionaryAlwaysAllowed(request, resolvedBundleId, verifiedSystemDictionary);
|
|
305
|
+
}
|
|
306
|
+
export function validateResolvedAppIdentity(request, resolvedBundleId, verifiedSystemDictionary) {
|
|
307
|
+
if (request.permissionMode === "safe" && resolvedBundleId) {
|
|
308
|
+
const blockedCategory = blockedSafeAppCategory(resolvedBundleId);
|
|
309
|
+
if (blockedCategory) {
|
|
310
|
+
throw new PolicyError(`Resolved app is blocked by the ${blockedCategory} safety policy`);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
if (request.mode === "dictionary_lookup" && !verifiedSystemDictionary) {
|
|
314
|
+
throw new PolicyError("Dictionary lookup requires the running Apple-signed system Dictionary at its fixed system path");
|
|
315
|
+
}
|
|
316
|
+
if (request.permissionMode === "safe" && request.mode === "act" && verifiedSystemDictionary) {
|
|
317
|
+
throw new PolicyError("Generic actions against Dictionary are blocked after canonical identity resolution in safe mode");
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
export function createDictionaryArgumentValidator(query) {
|
|
321
|
+
let setCount = 0;
|
|
322
|
+
let searchElement;
|
|
323
|
+
return (tool, args) => {
|
|
324
|
+
if (tool === "set_value") {
|
|
325
|
+
if (typeof args.element_index !== "string" || typeof args.value !== "string") {
|
|
326
|
+
return "Dictionary set_value arguments were not typed strings";
|
|
327
|
+
}
|
|
328
|
+
setCount += 1;
|
|
329
|
+
if (setCount === 1) {
|
|
330
|
+
if (args.value !== query)
|
|
331
|
+
return "Dictionary lookup attempted to set a value other than the approved query";
|
|
332
|
+
searchElement = args.element_index;
|
|
333
|
+
return undefined;
|
|
334
|
+
}
|
|
335
|
+
if (setCount === 2) {
|
|
336
|
+
if (args.element_index !== searchElement)
|
|
337
|
+
return "Dictionary cleanup targeted a different element than the lookup";
|
|
338
|
+
if (args.value !== DICTIONARY_NEUTRAL_QUERY)
|
|
339
|
+
return "Dictionary cleanup did not restore the fixed neutral query";
|
|
340
|
+
return undefined;
|
|
341
|
+
}
|
|
342
|
+
return "Dictionary lookup attempted more than two value assignments";
|
|
343
|
+
}
|
|
344
|
+
if (tool === "scroll") {
|
|
345
|
+
if (!["up", "down"].includes(String(args.direction)))
|
|
346
|
+
return "Dictionary lookup attempted a non-vertical scroll";
|
|
347
|
+
if (args.pages !== undefined && (typeof args.pages !== "number" || args.pages <= 0 || args.pages > 3)) {
|
|
348
|
+
return "Dictionary lookup attempted an out-of-bounds scroll";
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
return undefined;
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
const MUTATION_METHODS = new Set([
|
|
355
|
+
"click",
|
|
356
|
+
"perform_secondary_action",
|
|
357
|
+
"set_value",
|
|
358
|
+
"select_text",
|
|
359
|
+
"scroll",
|
|
360
|
+
"drag",
|
|
361
|
+
"press_key",
|
|
362
|
+
"type_text",
|
|
363
|
+
]);
|
|
364
|
+
export function validateObservedMethods(request, methods) {
|
|
365
|
+
if (methods.length === 0)
|
|
366
|
+
throw new PolicyError("Codex completed without an observed Computer Use method call");
|
|
367
|
+
if (methods.length > request.maxComputerUseCalls) {
|
|
368
|
+
throw new PolicyError(`Computer Use call budget exceeded (${methods.length}/${request.maxComputerUseCalls})`);
|
|
369
|
+
}
|
|
370
|
+
const available = new Set(allowedToolsForRequest(request));
|
|
371
|
+
for (const method of methods) {
|
|
372
|
+
if (!available.has(method))
|
|
373
|
+
throw new PolicyError(`Computer Use method is outside policy: ${method}`);
|
|
374
|
+
}
|
|
375
|
+
if (request.mode === "list") {
|
|
376
|
+
if (methods.length !== 1 || methods[0] !== "list_apps")
|
|
377
|
+
throw new PolicyError("list must make exactly one list_apps call");
|
|
378
|
+
return;
|
|
379
|
+
}
|
|
380
|
+
if (!methods.includes("get_app_state"))
|
|
381
|
+
throw new PolicyError(`${request.mode} must inspect app state`);
|
|
382
|
+
if (request.mode === "inspect") {
|
|
383
|
+
if (methods.some((method) => MUTATION_METHODS.has(method))) {
|
|
384
|
+
throw new PolicyError("inspect attempted a mutating Computer Use method");
|
|
385
|
+
}
|
|
386
|
+
return;
|
|
387
|
+
}
|
|
388
|
+
if (request.mode === "dictionary_lookup") {
|
|
389
|
+
const stateIndexes = methods
|
|
390
|
+
.map((method, index) => (method === "get_app_state" ? index : -1))
|
|
391
|
+
.filter((index) => index >= 0);
|
|
392
|
+
const setIndexes = methods
|
|
393
|
+
.map((method, index) => (method === "set_value" ? index : -1))
|
|
394
|
+
.filter((index) => index >= 0);
|
|
395
|
+
if (setIndexes.length !== 2)
|
|
396
|
+
throw new PolicyError("dictionary_lookup must set the query once and restore the fixed neutral query once");
|
|
397
|
+
if (stateIndexes[0] > setIndexes[0])
|
|
398
|
+
throw new PolicyError("dictionary_lookup did not inspect Dictionary before setting the query");
|
|
399
|
+
if (!stateIndexes.some((index) => index > setIndexes[0] && index < setIndexes[1])) {
|
|
400
|
+
throw new PolicyError("dictionary_lookup did not inspect the lookup result before cleanup");
|
|
401
|
+
}
|
|
402
|
+
if (!stateIndexes.some((index) => index > setIndexes[1])) {
|
|
403
|
+
throw new PolicyError("dictionary_lookup did not verify restoration of the fixed neutral query");
|
|
404
|
+
}
|
|
405
|
+
return;
|
|
406
|
+
}
|
|
407
|
+
const mutationIndexes = methods
|
|
408
|
+
.map((method, index) => (MUTATION_METHODS.has(method) ? index : -1))
|
|
409
|
+
.filter((index) => index >= 0);
|
|
410
|
+
const stateIndexes = methods
|
|
411
|
+
.map((method, index) => (method === "get_app_state" ? index : -1))
|
|
412
|
+
.filter((index) => index >= 0);
|
|
413
|
+
if (mutationIndexes.length === 0)
|
|
414
|
+
throw new PolicyError("act completed without a mutating Computer Use method");
|
|
415
|
+
if (stateIndexes[0] > mutationIndexes[0])
|
|
416
|
+
throw new PolicyError("act did not inspect the target before mutation");
|
|
417
|
+
if (!stateIndexes.some((index) => index > mutationIndexes.at(-1))) {
|
|
418
|
+
throw new PolicyError("act did not verify target state after the final mutation");
|
|
419
|
+
}
|
|
420
|
+
for (const capability of request.requiredCapabilities) {
|
|
421
|
+
if (!methods.includes(capability))
|
|
422
|
+
throw new PolicyError(`Required Computer Use capability was not exercised: ${capability}`);
|
|
423
|
+
}
|
|
424
|
+
if (request.cleanup && stateIndexes.filter((index) => index > mutationIndexes[0]).length < 2) {
|
|
425
|
+
throw new PolicyError("act did not separately verify task result and cleanup state");
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
//# sourceMappingURL=policy.js.map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E,CAAC,KAAK,GAAG,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC9F,MAAM,IAAI,WAAW,CAAC,6DAA6D,CAAC,CAAC;IACtF,CAAC;AACF,CAAC"}
|
package/dist/prompt.d.ts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { type ValidatedRequest } from "./policy.ts";
|
|
2
|
+
export declare const RESULT_SCHEMA: {
|
|
3
|
+
readonly type: "object";
|
|
4
|
+
readonly additionalProperties: false;
|
|
5
|
+
readonly required: readonly ["status", "app", "mode", "summary", "cleaned", "approvalRequired", "usedCapabilities", "apps", "message"];
|
|
6
|
+
readonly properties: {
|
|
7
|
+
readonly status: {
|
|
8
|
+
readonly type: "string";
|
|
9
|
+
readonly enum: readonly ["ok", "approval_required", "blocked", "error"];
|
|
10
|
+
};
|
|
11
|
+
readonly app: {
|
|
12
|
+
readonly type: "string";
|
|
13
|
+
readonly maxLength: 500;
|
|
14
|
+
};
|
|
15
|
+
readonly mode: {
|
|
16
|
+
readonly type: "string";
|
|
17
|
+
readonly enum: readonly ["list", "inspect", "act", "dictionary_lookup"];
|
|
18
|
+
};
|
|
19
|
+
readonly summary: {
|
|
20
|
+
readonly type: "string";
|
|
21
|
+
readonly maxLength: 1000;
|
|
22
|
+
};
|
|
23
|
+
readonly cleaned: {
|
|
24
|
+
readonly type: "boolean";
|
|
25
|
+
};
|
|
26
|
+
readonly approvalRequired: {
|
|
27
|
+
readonly type: "boolean";
|
|
28
|
+
};
|
|
29
|
+
readonly usedCapabilities: {
|
|
30
|
+
readonly type: "array";
|
|
31
|
+
readonly maxItems: 50;
|
|
32
|
+
readonly items: {
|
|
33
|
+
readonly type: "string";
|
|
34
|
+
readonly enum: readonly ["list_apps", "get_app_state", "click", "perform_secondary_action", "set_value", "select_text", "scroll", "drag", "press_key", "type_text"];
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
readonly apps: {
|
|
38
|
+
readonly type: "array";
|
|
39
|
+
readonly maxItems: 100;
|
|
40
|
+
readonly items: {
|
|
41
|
+
readonly type: "object";
|
|
42
|
+
readonly additionalProperties: false;
|
|
43
|
+
readonly required: readonly ["name", "bundleId"];
|
|
44
|
+
readonly properties: {
|
|
45
|
+
readonly name: {
|
|
46
|
+
readonly type: "string";
|
|
47
|
+
readonly maxLength: 120;
|
|
48
|
+
};
|
|
49
|
+
readonly bundleId: {
|
|
50
|
+
readonly type: "string";
|
|
51
|
+
readonly maxLength: 160;
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
readonly message: {
|
|
57
|
+
readonly type: "string";
|
|
58
|
+
readonly maxLength: 256;
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
export declare function buildPrompt(request: ValidatedRequest, canonicalTargetApp?: string): string;
|
package/dist/prompt.js
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { DICTIONARY_NEUTRAL_QUERY } from "./policy.js";
|
|
2
|
+
export const RESULT_SCHEMA = {
|
|
3
|
+
type: "object",
|
|
4
|
+
additionalProperties: false,
|
|
5
|
+
required: [
|
|
6
|
+
"status",
|
|
7
|
+
"app",
|
|
8
|
+
"mode",
|
|
9
|
+
"summary",
|
|
10
|
+
"cleaned",
|
|
11
|
+
"approvalRequired",
|
|
12
|
+
"usedCapabilities",
|
|
13
|
+
"apps",
|
|
14
|
+
"message",
|
|
15
|
+
],
|
|
16
|
+
properties: {
|
|
17
|
+
status: { type: "string", enum: ["ok", "approval_required", "blocked", "error"] },
|
|
18
|
+
app: { type: "string", maxLength: 500 },
|
|
19
|
+
mode: { type: "string", enum: ["list", "inspect", "act", "dictionary_lookup"] },
|
|
20
|
+
summary: { type: "string", maxLength: 1000 },
|
|
21
|
+
cleaned: { type: "boolean" },
|
|
22
|
+
approvalRequired: { type: "boolean" },
|
|
23
|
+
usedCapabilities: {
|
|
24
|
+
type: "array",
|
|
25
|
+
maxItems: 50,
|
|
26
|
+
items: {
|
|
27
|
+
type: "string",
|
|
28
|
+
enum: [
|
|
29
|
+
"list_apps",
|
|
30
|
+
"get_app_state",
|
|
31
|
+
"click",
|
|
32
|
+
"perform_secondary_action",
|
|
33
|
+
"set_value",
|
|
34
|
+
"select_text",
|
|
35
|
+
"scroll",
|
|
36
|
+
"drag",
|
|
37
|
+
"press_key",
|
|
38
|
+
"type_text",
|
|
39
|
+
],
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
apps: {
|
|
43
|
+
type: "array",
|
|
44
|
+
maxItems: 100,
|
|
45
|
+
items: {
|
|
46
|
+
type: "object",
|
|
47
|
+
additionalProperties: false,
|
|
48
|
+
required: ["name", "bundleId"],
|
|
49
|
+
properties: {
|
|
50
|
+
name: { type: "string", maxLength: 120 },
|
|
51
|
+
bundleId: { type: "string", maxLength: 160 },
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
message: { type: "string", maxLength: 256 },
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
function enabledToolNames(request) {
|
|
59
|
+
switch (request.mode) {
|
|
60
|
+
case "list":
|
|
61
|
+
return "computer-use/list_apps";
|
|
62
|
+
case "inspect":
|
|
63
|
+
return "computer-use/list_apps, computer-use/get_app_state";
|
|
64
|
+
case "act":
|
|
65
|
+
return [
|
|
66
|
+
"list_apps",
|
|
67
|
+
"get_app_state",
|
|
68
|
+
"click",
|
|
69
|
+
"perform_secondary_action",
|
|
70
|
+
"set_value",
|
|
71
|
+
"select_text",
|
|
72
|
+
"scroll",
|
|
73
|
+
"drag",
|
|
74
|
+
"press_key",
|
|
75
|
+
"type_text",
|
|
76
|
+
].map((tool) => `computer-use/${tool}`).join(", ");
|
|
77
|
+
case "dictionary_lookup":
|
|
78
|
+
return ["get_app_state", "set_value", "scroll"].map((tool) => `computer-use/${tool}`).join(", ");
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
function operationInstructions(request, targetApp = request.app) {
|
|
82
|
+
switch (request.mode) {
|
|
83
|
+
case "list":
|
|
84
|
+
return `Call list_apps exactly once. Return every discovered app as name + bundleId only. Do not include paths, PIDs, titles, windows, or app contents.`;
|
|
85
|
+
case "inspect":
|
|
86
|
+
return `Target only ${JSON.stringify(targetApp)}. Call get_app_state. Use list_apps only if the exact target is rejected and must be resolved. Do not mutate anything. Summarize the target's operational state without reproducing sensitive or unrelated text. Return apps=[].`;
|
|
87
|
+
case "act": {
|
|
88
|
+
const cleanup = request.cleanup
|
|
89
|
+
? request.cleanupInstructions ??
|
|
90
|
+
(request.permissionMode === "full-permissions"
|
|
91
|
+
? "Restore transient state created only for this task, without undoing the requested durable result."
|
|
92
|
+
: "Restore transient controls/content changed by this task to a neutral pre-task state without saving, sending, deleting, or affecting another app.")
|
|
93
|
+
: "Cleanup was disabled; leave the requested target-app result in place.";
|
|
94
|
+
const required = request.requiredCapabilities.length
|
|
95
|
+
? `The following capabilities must genuinely be exercised as part of the task and reported: ${request.requiredCapabilities.join(", ")}.`
|
|
96
|
+
: request.permissionMode === "full-permissions"
|
|
97
|
+
? "Use any of the complete official typed Computer Use methods needed for the task."
|
|
98
|
+
: "Choose the least disruptive Computer Use actions that complete the task.";
|
|
99
|
+
const authorization = request.permissionMode === "full-permissions"
|
|
100
|
+
? "The configured full-permissions mode broadly authorizes this wrapper to execute official-service actions without a wrapper per-operation confirmation."
|
|
101
|
+
: "The task has been confirmed in Pi safe mode.";
|
|
102
|
+
return `Target only ${JSON.stringify(targetApp)}. ${authorization} The requested task is: ${JSON.stringify(request.task)}. First call get_app_state, then perform the task using the typed Computer Use tools, then call get_app_state to verify the result. ${required} Cleanup requirement: ${cleanup} ${request.cleanup ? "After observing the task result, perform cleanup and call get_app_state again to verify the cleaned state." : "Do not invent cleanup."} Return apps=[].`;
|
|
103
|
+
}
|
|
104
|
+
case "dictionary_lookup":
|
|
105
|
+
return `Target only ${JSON.stringify(targetApp)}, which must resolve to the Apple-signed system Dictionary app. This is a narrowly authorized local dictionary lookup for ${JSON.stringify(request.query)}. Call get_app_state. Call set_value exactly once on Dictionary's search field with the exact approved query. Call get_app_state to read and summarize the definition; scroll only the definition area vertically by at most three pages if needed. Then call set_value exactly once on the same search field with the fixed neutral value ${JSON.stringify(DICTIONARY_NEUTRAL_QUERY)} and call get_app_state to verify that neutral state. Do not click, type, press keys, invoke secondary actions, drag, raise, activate, save, copy, share, open links, or operate any other control or app. Return apps=[].`;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
export function buildPrompt(request, canonicalTargetApp) {
|
|
109
|
+
if (request.mode === "list") {
|
|
110
|
+
return `Call computer-use/list_apps exactly once. Do not call any other tool. Then return the required JSON object with status="ok", app="app inventory", mode="list", cleaned=true, approvalRequired=false, usedCapabilities=["list_apps"], apps containing every discovered name and bundleId only, and a minimal summary/message. Do not include paths, PIDs, titles, windows, app contents, screenshots, tool output, or reasoning.`;
|
|
111
|
+
}
|
|
112
|
+
const targetApp = canonicalTargetApp ?? request.app;
|
|
113
|
+
return `Use only these fully qualified MCP tools: ${enabledToolNames(request)}. Target exactly ${JSON.stringify(targetApp)} and no other app. Keep it in the background; do not raise, activate, or focus it. Make at most ${request.maxComputerUseCalls} calls.
|
|
114
|
+
|
|
115
|
+
${operationInstructions(request, targetApp)}
|
|
116
|
+
|
|
117
|
+
If an official app-approval elicitation is cancelled or unavailable, stop immediately and return status="approval_required", approvalRequired=true, cleaned=false, and only the methods that actually completed. Otherwise return status="ok" only after observing the requested result. In the final JSON, set app=${JSON.stringify(request.app)}. usedCapabilities must exactly list successfully completed Computer Use method names in order, including duplicates; apps must be empty. Return only the required JSON object with a minimal summary/message and no screenshots, paths, PIDs, raw accessibility tree, unrelated content, tool output, or reasoning.`;
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=prompt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt.js","sourceRoot":"","sources":["../src/prompt.ts"],"names":[],"mappings":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