@leo000001/codex-mcp 2.0.2 → 2.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/dist/index.js CHANGED
@@ -191,6 +191,7 @@ var COMMAND_DECISIONS = [
191
191
  "accept",
192
192
  "acceptForSession",
193
193
  "acceptWithExecpolicyAmendment",
194
+ "applyNetworkPolicyAmendment",
194
195
  "decline",
195
196
  "cancel"
196
197
  ];
@@ -199,6 +200,7 @@ var ALL_DECISIONS = [
199
200
  "accept",
200
201
  "acceptForSession",
201
202
  "acceptWithExecpolicyAmendment",
203
+ "applyNetworkPolicyAmendment",
202
204
  "decline",
203
205
  "cancel"
204
206
  ];
@@ -233,7 +235,7 @@ var DEFAULT_TERMINAL_CLEANUP_MS = 5 * 60 * 1e3;
233
235
  var CLEANUP_INTERVAL_MS = 6e4;
234
236
 
235
237
  // src/app-server/client.ts
236
- var CLIENT_VERSION = true ? "2.0.2" : "0.0.0-dev";
238
+ var CLIENT_VERSION = true ? "2.1.0" : "0.0.0-dev";
237
239
  var DEFAULT_REQUEST_TIMEOUT = 3e4;
238
240
  var STARTUP_REQUEST_TIMEOUT = 9e4;
239
241
  var MAX_WRITE_QUEUE_BYTES = 5 * 1024 * 1024;
@@ -1119,6 +1121,10 @@ var SessionManager = class {
1119
1121
  approvalId: req.approvalId,
1120
1122
  commandActions: req.commandActions,
1121
1123
  proposedExecpolicyAmendment: req.proposedExecpolicyAmendment,
1124
+ availableDecisions: req.availableDecisions,
1125
+ proposedNetworkPolicyAmendments: req.proposedNetworkPolicyAmendments,
1126
+ additionalPermissions: req.additionalPermissions,
1127
+ networkApprovalContext: req.networkApprovalContext,
1122
1128
  createdAt: req.createdAt
1123
1129
  });
1124
1130
  }
@@ -1220,6 +1226,17 @@ var SessionManager = class {
1220
1226
  );
1221
1227
  }
1222
1228
  if (req.kind === "command") {
1229
+ const available = parseAvailableDecisionSet(req.availableDecisions);
1230
+ if (available && !available.has(decision)) {
1231
+ throw new Error(
1232
+ `Error [${"INVALID_ARGUMENT" /* INVALID_ARGUMENT */}]: Decision '${decision}' is not available for this approval prompt`
1233
+ );
1234
+ }
1235
+ if (!available && decision === "applyNetworkPolicyAmendment") {
1236
+ throw new Error(
1237
+ `Error [${"INVALID_ARGUMENT" /* INVALID_ARGUMENT */}]: Decision '${decision}' is not supported by this Codex CLI version (missing availableDecisions)`
1238
+ );
1239
+ }
1223
1240
  if (!COMMAND_DECISIONS.includes(decision)) {
1224
1241
  throw new Error(
1225
1242
  `Error [${"INVALID_ARGUMENT" /* INVALID_ARGUMENT */}]: Invalid command decision '${decision}'`
@@ -1230,6 +1247,33 @@ var SessionManager = class {
1230
1247
  `Error [${"INVALID_ARGUMENT" /* INVALID_ARGUMENT */}]: execpolicy_amendment required for acceptWithExecpolicyAmendment`
1231
1248
  );
1232
1249
  }
1250
+ if (decision !== "acceptWithExecpolicyAmendment" && extra?.execpolicy_amendment !== void 0) {
1251
+ throw new Error(
1252
+ `Error [${"INVALID_ARGUMENT" /* INVALID_ARGUMENT */}]: execpolicy_amendment is only valid for acceptWithExecpolicyAmendment`
1253
+ );
1254
+ }
1255
+ if (decision === "applyNetworkPolicyAmendment") {
1256
+ const amendment = extra?.network_policy_amendment;
1257
+ if (!amendment) {
1258
+ throw new Error(
1259
+ `Error [${"INVALID_ARGUMENT" /* INVALID_ARGUMENT */}]: network_policy_amendment required for applyNetworkPolicyAmendment`
1260
+ );
1261
+ }
1262
+ if (amendment.action !== "allow" && amendment.action !== "deny") {
1263
+ throw new Error(
1264
+ `Error [${"INVALID_ARGUMENT" /* INVALID_ARGUMENT */}]: network_policy_amendment.action must be 'allow' or 'deny'`
1265
+ );
1266
+ }
1267
+ if (!amendment.host) {
1268
+ throw new Error(
1269
+ `Error [${"INVALID_ARGUMENT" /* INVALID_ARGUMENT */}]: network_policy_amendment.host required for applyNetworkPolicyAmendment`
1270
+ );
1271
+ }
1272
+ } else if (extra?.network_policy_amendment !== void 0) {
1273
+ throw new Error(
1274
+ `Error [${"INVALID_ARGUMENT" /* INVALID_ARGUMENT */}]: network_policy_amendment is only valid for applyNetworkPolicyAmendment`
1275
+ );
1276
+ }
1233
1277
  } else if (req.kind === "fileChange") {
1234
1278
  if (!FILE_CHANGE_DECISIONS.includes(decision)) {
1235
1279
  throw new Error(
@@ -1243,7 +1287,10 @@ var SessionManager = class {
1243
1287
  }
1244
1288
  let response;
1245
1289
  if (req.kind === "command") {
1246
- response = buildCommandApprovalResponse(decision, extra?.execpolicy_amendment);
1290
+ response = buildCommandApprovalResponse(decision, {
1291
+ execpolicy_amendment: extra?.execpolicy_amendment,
1292
+ network_policy_amendment: extra?.network_policy_amendment
1293
+ });
1247
1294
  } else if (req.kind === "fileChange") {
1248
1295
  response = { decision };
1249
1296
  }
@@ -1501,6 +1548,12 @@ var SessionManager = class {
1501
1548
  const proposedExecpolicyAmendment = normalizeStringArrayOrNull(
1502
1549
  approvalParams.proposedExecpolicyAmendment
1503
1550
  );
1551
+ const availableDecisions = Array.isArray(approvalParams.availableDecisions) ? approvalParams.availableDecisions : null;
1552
+ const proposedNetworkPolicyAmendments = Array.isArray(
1553
+ approvalParams.proposedNetworkPolicyAmendments
1554
+ ) ? approvalParams.proposedNetworkPolicyAmendments : null;
1555
+ const additionalPermissions = "additionalPermissions" in approvalParams ? approvalParams.additionalPermissions : void 0;
1556
+ const networkApprovalContext = "networkApprovalContext" in approvalParams ? approvalParams.networkApprovalContext : void 0;
1504
1557
  const pending = {
1505
1558
  requestId,
1506
1559
  kind: "command",
@@ -1512,6 +1565,10 @@ var SessionManager = class {
1512
1565
  approvalId,
1513
1566
  commandActions,
1514
1567
  proposedExecpolicyAmendment,
1568
+ availableDecisions,
1569
+ proposedNetworkPolicyAmendments,
1570
+ additionalPermissions,
1571
+ networkApprovalContext,
1515
1572
  createdAt: (/* @__PURE__ */ new Date()).toISOString(),
1516
1573
  resolved: false,
1517
1574
  respond: (result) => client.respondToServer(id, result)
@@ -1559,7 +1616,11 @@ var SessionManager = class {
1559
1616
  cwd: approvalParams.cwd,
1560
1617
  reason,
1561
1618
  commandActions,
1562
- proposedExecpolicyAmendment
1619
+ proposedExecpolicyAmendment,
1620
+ availableDecisions,
1621
+ proposedNetworkPolicyAmendments,
1622
+ additionalPermissions,
1623
+ networkApprovalContext
1563
1624
  },
1564
1625
  true
1565
1626
  );
@@ -1878,7 +1939,11 @@ function compactActionsForBudget(actions) {
1878
1939
  itemId: action.itemId,
1879
1940
  createdAt: action.createdAt,
1880
1941
  commandActions: action.commandActions,
1881
- proposedExecpolicyAmendment: action.proposedExecpolicyAmendment
1942
+ proposedExecpolicyAmendment: action.proposedExecpolicyAmendment,
1943
+ availableDecisions: action.availableDecisions,
1944
+ additionalPermissions: action.additionalPermissions,
1945
+ networkApprovalContext: action.networkApprovalContext,
1946
+ proposedNetworkPolicyAmendments: action.proposedNetworkPolicyAmendments
1882
1947
  }));
1883
1948
  }
1884
1949
  function compactActionParamsForBudget(action) {
@@ -1911,7 +1976,11 @@ function compactActionsToMinimum(actions) {
1911
1976
  itemId: first.itemId,
1912
1977
  createdAt: first.createdAt,
1913
1978
  commandActions: first.commandActions,
1914
- proposedExecpolicyAmendment: first.proposedExecpolicyAmendment
1979
+ proposedExecpolicyAmendment: first.proposedExecpolicyAmendment,
1980
+ availableDecisions: first.availableDecisions,
1981
+ additionalPermissions: first.additionalPermissions,
1982
+ networkApprovalContext: first.networkApprovalContext,
1983
+ proposedNetworkPolicyAmendments: first.proposedNetworkPolicyAmendments
1915
1984
  }
1916
1985
  ];
1917
1986
  }
@@ -2135,8 +2204,9 @@ function toSensitiveInfo(session) {
2135
2204
  config: session.config
2136
2205
  };
2137
2206
  }
2138
- function buildCommandApprovalResponse(decision, execpolicy_amendment) {
2207
+ function buildCommandApprovalResponse(decision, extra) {
2139
2208
  if (decision === "acceptWithExecpolicyAmendment") {
2209
+ const execpolicy_amendment = extra?.execpolicy_amendment;
2140
2210
  if (!execpolicy_amendment || execpolicy_amendment.length === 0) {
2141
2211
  throw new Error(
2142
2212
  `Error [${"INVALID_ARGUMENT" /* INVALID_ARGUMENT */}]: execpolicy_amendment required for acceptWithExecpolicyAmendment`
@@ -2150,11 +2220,41 @@ function buildCommandApprovalResponse(decision, execpolicy_amendment) {
2150
2220
  }
2151
2221
  };
2152
2222
  }
2223
+ if (decision === "applyNetworkPolicyAmendment") {
2224
+ const amendment = extra?.network_policy_amendment;
2225
+ if (!amendment) {
2226
+ throw new Error(
2227
+ `Error [${"INVALID_ARGUMENT" /* INVALID_ARGUMENT */}]: network_policy_amendment required for applyNetworkPolicyAmendment`
2228
+ );
2229
+ }
2230
+ return {
2231
+ decision: {
2232
+ applyNetworkPolicyAmendment: {
2233
+ network_policy_amendment: amendment
2234
+ }
2235
+ }
2236
+ };
2237
+ }
2153
2238
  return { decision };
2154
2239
  }
2155
2240
  function isRecord(value) {
2156
2241
  return typeof value === "object" && value !== null;
2157
2242
  }
2243
+ function parseAvailableDecisionSet(available) {
2244
+ if (!Array.isArray(available) || available.length === 0) return null;
2245
+ const set = /* @__PURE__ */ new Set();
2246
+ for (const entry of available) {
2247
+ if (typeof entry === "string") {
2248
+ set.add(entry);
2249
+ continue;
2250
+ }
2251
+ if (isRecord(entry)) {
2252
+ if ("acceptWithExecpolicyAmendment" in entry) set.add("acceptWithExecpolicyAmendment");
2253
+ if ("applyNetworkPolicyAmendment" in entry) set.add("applyNetworkPolicyAmendment");
2254
+ }
2255
+ }
2256
+ return set.size > 0 ? set : null;
2257
+ }
2158
2258
  function extractThreadId(result) {
2159
2259
  if (!isRecord(result)) {
2160
2260
  throw new Error(`Error [${"INTERNAL" /* INTERNAL */}]: Invalid thread response: expected object`);
@@ -2272,9 +2372,9 @@ function executeCodexCheck(args, sessionManager) {
2272
2372
  const pollOptions = args.pollOptions;
2273
2373
  switch (args.action) {
2274
2374
  case "poll": {
2275
- if (args.requestId !== void 0 || args.decision !== void 0 || args.execpolicy_amendment !== void 0 || args.denyMessage !== void 0 || args.answers !== void 0) {
2375
+ if (args.requestId !== void 0 || args.decision !== void 0 || args.execpolicy_amendment !== void 0 || args.network_policy_amendment !== void 0 || args.denyMessage !== void 0 || args.answers !== void 0) {
2276
2376
  return {
2277
- error: `Error [${"INVALID_ARGUMENT" /* INVALID_ARGUMENT */}]: requestId/decision/execpolicy_amendment/denyMessage/answers are only valid for respond_* actions`,
2377
+ error: `Error [${"INVALID_ARGUMENT" /* INVALID_ARGUMENT */}]: requestId/decision/execpolicy_amendment/network_policy_amendment/denyMessage/answers are only valid for respond_* actions`,
2278
2378
  isError: true
2279
2379
  };
2280
2380
  }
@@ -2310,6 +2410,31 @@ function executeCodexCheck(args, sessionManager) {
2310
2410
  isError: true
2311
2411
  };
2312
2412
  }
2413
+ if (args.decision === "applyNetworkPolicyAmendment") {
2414
+ if (!args.network_policy_amendment) {
2415
+ return {
2416
+ error: `Error [${"INVALID_ARGUMENT" /* INVALID_ARGUMENT */}]: network_policy_amendment required for applyNetworkPolicyAmendment`,
2417
+ isError: true
2418
+ };
2419
+ }
2420
+ if (args.network_policy_amendment.action !== "allow" && args.network_policy_amendment.action !== "deny") {
2421
+ return {
2422
+ error: `Error [${"INVALID_ARGUMENT" /* INVALID_ARGUMENT */}]: network_policy_amendment.action must be 'allow' or 'deny'`,
2423
+ isError: true
2424
+ };
2425
+ }
2426
+ if (!args.network_policy_amendment.host) {
2427
+ return {
2428
+ error: `Error [${"INVALID_ARGUMENT" /* INVALID_ARGUMENT */}]: network_policy_amendment.host required for applyNetworkPolicyAmendment`,
2429
+ isError: true
2430
+ };
2431
+ }
2432
+ } else if (args.network_policy_amendment !== void 0) {
2433
+ return {
2434
+ error: `Error [${"INVALID_ARGUMENT" /* INVALID_ARGUMENT */}]: network_policy_amendment is only valid with decision='applyNetworkPolicyAmendment'`,
2435
+ isError: true
2436
+ };
2437
+ }
2313
2438
  if (!ALL_DECISIONS.includes(args.decision)) {
2314
2439
  return {
2315
2440
  error: `Error [${"INVALID_ARGUMENT" /* INVALID_ARGUMENT */}]: Unknown decision '${args.decision}'`,
@@ -2319,6 +2444,7 @@ function executeCodexCheck(args, sessionManager) {
2319
2444
  try {
2320
2445
  sessionManager.resolveApproval(args.sessionId, args.requestId, args.decision, {
2321
2446
  execpolicy_amendment: args.execpolicy_amendment,
2447
+ network_policy_amendment: args.network_policy_amendment,
2322
2448
  denyMessage: args.denyMessage
2323
2449
  });
2324
2450
  } catch (err) {
@@ -2338,9 +2464,9 @@ function executeCodexCheck(args, sessionManager) {
2338
2464
  isError: true
2339
2465
  };
2340
2466
  }
2341
- if (args.decision !== void 0 || args.execpolicy_amendment !== void 0 || args.denyMessage !== void 0) {
2467
+ if (args.decision !== void 0 || args.execpolicy_amendment !== void 0 || args.network_policy_amendment !== void 0 || args.denyMessage !== void 0) {
2342
2468
  return {
2343
- error: `Error [${"INVALID_ARGUMENT" /* INVALID_ARGUMENT */}]: decision/execpolicy_amendment/denyMessage are only valid for respond_permission`,
2469
+ error: `Error [${"INVALID_ARGUMENT" /* INVALID_ARGUMENT */}]: decision/execpolicy_amendment/network_policy_amendment/denyMessage are only valid for respond_permission`,
2344
2470
  isError: true
2345
2471
  };
2346
2472
  }
@@ -2935,7 +3061,7 @@ function registerResources(server, deps) {
2935
3061
  }
2936
3062
 
2937
3063
  // src/server.ts
2938
- var SERVER_VERSION = true ? "2.0.2" : "0.0.0-dev";
3064
+ var SERVER_VERSION = true ? "2.1.0" : "0.0.0-dev";
2939
3065
  function formatErrorMessage(err) {
2940
3066
  const message = err instanceof Error ? err.message : String(err);
2941
3067
  const m = /^Error \[([A-Z_]+)\]:\s*(.*)$/.exec(message);
@@ -3004,9 +3130,13 @@ function createServer(serverCwd) {
3004
3130
  // respond_permission
3005
3131
  requestId: z.string().optional().describe("Request ID from actions[]"),
3006
3132
  decision: z.enum(ALL_DECISIONS).optional().describe(
3007
- "Approval decision for respond_permission. acceptWithExecpolicyAmendment requires execpolicy_amendment."
3133
+ "Approval decision for respond_permission. acceptWithExecpolicyAmendment requires execpolicy_amendment; applyNetworkPolicyAmendment requires network_policy_amendment."
3008
3134
  ),
3009
3135
  execpolicy_amendment: z.array(z.string()).optional().describe("For acceptWithExecpolicyAmendment only"),
3136
+ network_policy_amendment: z.object({
3137
+ action: z.enum(["allow", "deny"]),
3138
+ host: z.string().min(1)
3139
+ }).optional().describe("For applyNetworkPolicyAmendment only"),
3010
3140
  denyMessage: z.string().optional().describe("Deny reason (not sent to agent)"),
3011
3141
  // respond_user_input
3012
3142
  answers: z.record(
@@ -3043,6 +3173,12 @@ function createServer(serverCwd) {
3043
3173
  "execpolicy_amendment is only allowed for action='respond_permission'."
3044
3174
  );
3045
3175
  }
3176
+ if (value.network_policy_amendment !== void 0) {
3177
+ addIssue(
3178
+ "network_policy_amendment",
3179
+ "network_policy_amendment is only allowed for action='respond_permission'."
3180
+ );
3181
+ }
3046
3182
  if (value.denyMessage !== void 0) {
3047
3183
  addIssue("denyMessage", "denyMessage is only allowed for action='respond_permission'.");
3048
3184
  }
@@ -3062,6 +3198,7 @@ function createServer(serverCwd) {
3062
3198
  addIssue("answers", "answers is only allowed for action='respond_user_input'.");
3063
3199
  }
3064
3200
  const needsExecpolicy = value.decision === "acceptWithExecpolicyAmendment";
3201
+ const needsNetworkPolicy = value.decision === "applyNetworkPolicyAmendment";
3065
3202
  if (needsExecpolicy && (!value.execpolicy_amendment || value.execpolicy_amendment.length === 0)) {
3066
3203
  addIssue(
3067
3204
  "execpolicy_amendment",
@@ -3074,6 +3211,18 @@ function createServer(serverCwd) {
3074
3211
  "execpolicy_amendment is only allowed when decision='acceptWithExecpolicyAmendment'."
3075
3212
  );
3076
3213
  }
3214
+ if (needsNetworkPolicy && !value.network_policy_amendment) {
3215
+ addIssue(
3216
+ "network_policy_amendment",
3217
+ "network_policy_amendment is required when decision='applyNetworkPolicyAmendment'."
3218
+ );
3219
+ }
3220
+ if (!needsNetworkPolicy && value.network_policy_amendment !== void 0) {
3221
+ addIssue(
3222
+ "network_policy_amendment",
3223
+ "network_policy_amendment is only allowed when decision='applyNetworkPolicyAmendment'."
3224
+ );
3225
+ }
3077
3226
  break;
3078
3227
  }
3079
3228
  case "respond_user_input": {
@@ -3092,6 +3241,12 @@ function createServer(serverCwd) {
3092
3241
  "execpolicy_amendment is only allowed for action='respond_permission'."
3093
3242
  );
3094
3243
  }
3244
+ if (value.network_policy_amendment !== void 0) {
3245
+ addIssue(
3246
+ "network_policy_amendment",
3247
+ "network_policy_amendment is only allowed for action='respond_permission'."
3248
+ );
3249
+ }
3095
3250
  if (value.denyMessage !== void 0) {
3096
3251
  addIssue("denyMessage", "denyMessage is only allowed for action='respond_permission'.");
3097
3252
  }