@darkhunt-security/endpoint-codex 0.9.11 → 0.9.13

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.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "darkhunt-guard",
3
- "version": "0.9.11",
3
+ "version": "0.9.13",
4
4
  "hooks": "./hooks/hooks.json",
5
5
  "description": "Darkhunt endpoint plugin for Codex CLI \u2014 full session trace capture and PreToolUse guardrails.",
6
6
  "author": {
@@ -22017,28 +22017,41 @@ function budgeted(steps) {
22017
22017
  }
22018
22018
  return kept;
22019
22019
  }
22020
- function unwrapExecOutput(value) {
22021
- if (typeof value !== "string")
22022
- return { output: value };
22020
+ function execEnvelope(text) {
22023
22021
  let parsed;
22024
22022
  try {
22025
- parsed = JSON.parse(value);
22023
+ parsed = JSON.parse(text);
22026
22024
  } catch {
22027
- return { output: value };
22025
+ return void 0;
22028
22026
  }
22029
22027
  if (!parsed || typeof parsed !== "object" || Array.isArray(parsed))
22030
- return { output: value };
22028
+ return void 0;
22031
22029
  const bag = parsed;
22032
22030
  if (!Object.prototype.hasOwnProperty.call(bag, "output"))
22033
- return { output: value };
22031
+ return void 0;
22034
22032
  const metadata = bag["metadata"];
22035
- if (!metadata || typeof metadata !== "object")
22036
- return { output: value };
22037
- const exitCode = num(metadata["exit_code"]);
22033
+ const exitCode = num(bag["exit_code"]) ?? (metadata && typeof metadata === "object" ? num(metadata["exit_code"]) : void 0);
22038
22034
  if (exitCode === void 0)
22039
- return { output: value };
22035
+ return void 0;
22040
22036
  return { output: bag["output"], exitCode };
22041
22037
  }
22038
+ function execResult(value) {
22039
+ if (typeof value === "string")
22040
+ return execEnvelope(value) ?? { output: value };
22041
+ if (Array.isArray(value)) {
22042
+ for (const block of value) {
22043
+ if (!block || typeof block !== "object")
22044
+ continue;
22045
+ const text = block["text"];
22046
+ if (typeof text !== "string")
22047
+ continue;
22048
+ const envelope = execEnvelope(text);
22049
+ if (envelope)
22050
+ return envelope;
22051
+ }
22052
+ }
22053
+ return { output: textOf(value) ?? value };
22054
+ }
22042
22055
  function jwtClaims(token) {
22043
22056
  const parts = token.split(".");
22044
22057
  if (parts.length !== 3 || !parts[1])
@@ -22238,8 +22251,7 @@ var codexTranscript = {
22238
22251
  }
22239
22252
  ];
22240
22253
  case "function_call_output": {
22241
- const flattened = textOf(payload["output"]) ?? payload["output"];
22242
- const { output, exitCode } = unwrapExecOutput(flattened);
22254
+ const { output, exitCode } = execResult(payload["output"]);
22243
22255
  return [
22244
22256
  {
22245
22257
  ...base,
@@ -22270,8 +22282,7 @@ var codexTranscript = {
22270
22282
  }
22271
22283
  ];
22272
22284
  case "custom_tool_call_output": {
22273
- const flattened = textOf(payload["output"]) ?? payload["output"];
22274
- const { output, exitCode } = unwrapExecOutput(flattened);
22285
+ const { output, exitCode } = execResult(payload["output"]);
22275
22286
  return [
22276
22287
  {
22277
22288
  ...base,
@@ -22004,28 +22004,41 @@ function budgeted(steps) {
22004
22004
  }
22005
22005
  return kept;
22006
22006
  }
22007
- function unwrapExecOutput(value) {
22008
- if (typeof value !== "string")
22009
- return { output: value };
22007
+ function execEnvelope(text) {
22010
22008
  let parsed;
22011
22009
  try {
22012
- parsed = JSON.parse(value);
22010
+ parsed = JSON.parse(text);
22013
22011
  } catch {
22014
- return { output: value };
22012
+ return void 0;
22015
22013
  }
22016
22014
  if (!parsed || typeof parsed !== "object" || Array.isArray(parsed))
22017
- return { output: value };
22015
+ return void 0;
22018
22016
  const bag = parsed;
22019
22017
  if (!Object.prototype.hasOwnProperty.call(bag, "output"))
22020
- return { output: value };
22018
+ return void 0;
22021
22019
  const metadata = bag["metadata"];
22022
- if (!metadata || typeof metadata !== "object")
22023
- return { output: value };
22024
- const exitCode = num(metadata["exit_code"]);
22020
+ const exitCode = num(bag["exit_code"]) ?? (metadata && typeof metadata === "object" ? num(metadata["exit_code"]) : void 0);
22025
22021
  if (exitCode === void 0)
22026
- return { output: value };
22022
+ return void 0;
22027
22023
  return { output: bag["output"], exitCode };
22028
22024
  }
22025
+ function execResult(value) {
22026
+ if (typeof value === "string")
22027
+ return execEnvelope(value) ?? { output: value };
22028
+ if (Array.isArray(value)) {
22029
+ for (const block of value) {
22030
+ if (!block || typeof block !== "object")
22031
+ continue;
22032
+ const text = block["text"];
22033
+ if (typeof text !== "string")
22034
+ continue;
22035
+ const envelope = execEnvelope(text);
22036
+ if (envelope)
22037
+ return envelope;
22038
+ }
22039
+ }
22040
+ return { output: textOf(value) ?? value };
22041
+ }
22029
22042
  function jwtClaims(token) {
22030
22043
  const parts = token.split(".");
22031
22044
  if (parts.length !== 3 || !parts[1])
@@ -22225,8 +22238,7 @@ var codexTranscript = {
22225
22238
  }
22226
22239
  ];
22227
22240
  case "function_call_output": {
22228
- const flattened = textOf(payload["output"]) ?? payload["output"];
22229
- const { output, exitCode } = unwrapExecOutput(flattened);
22241
+ const { output, exitCode } = execResult(payload["output"]);
22230
22242
  return [
22231
22243
  {
22232
22244
  ...base,
@@ -22257,8 +22269,7 @@ var codexTranscript = {
22257
22269
  }
22258
22270
  ];
22259
22271
  case "custom_tool_call_output": {
22260
- const flattened = textOf(payload["output"]) ?? payload["output"];
22261
- const { output, exitCode } = unwrapExecOutput(flattened);
22272
+ const { output, exitCode } = execResult(payload["output"]);
22262
22273
  return [
22263
22274
  {
22264
22275
  ...base,
@@ -1378,6 +1378,14 @@ var codexCodec = {
1378
1378
  };
1379
1379
  },
1380
1380
  encodeDecision(decision) {
1381
+ const noOpinion = decision.decision === "allow" && decision.updatedInput === void 0 && (decision.ruleId === null || decision.enforcement === "advisory");
1382
+ if (noOpinion) {
1383
+ const message = [decision.reason, decision.remediation].filter(Boolean).join(" ");
1384
+ return {
1385
+ stdout: message ? JSON.stringify({ systemMessage: message }) : "",
1386
+ exitCode: 0
1387
+ };
1388
+ }
1381
1389
  const hookSpecificOutput = {
1382
1390
  hookEventName: "PreToolUse",
1383
1391
  permissionDecision: decision.decision
@@ -1180,6 +1180,14 @@ var codexCodec = {
1180
1180
  };
1181
1181
  },
1182
1182
  encodeDecision(decision) {
1183
+ const noOpinion = decision.decision === "allow" && decision.updatedInput === void 0 && (decision.ruleId === null || decision.enforcement === "advisory");
1184
+ if (noOpinion) {
1185
+ const message = [decision.reason, decision.remediation].filter(Boolean).join(" ");
1186
+ return {
1187
+ stdout: message ? JSON.stringify({ systemMessage: message }) : "",
1188
+ exitCode: 0
1189
+ };
1190
+ }
1183
1191
  const hookSpecificOutput = {
1184
1192
  hookEventName: "PreToolUse",
1185
1193
  permissionDecision: decision.decision
@@ -1286,28 +1286,41 @@ function budgeted(steps) {
1286
1286
  }
1287
1287
  return kept;
1288
1288
  }
1289
- function unwrapExecOutput(value) {
1290
- if (typeof value !== "string")
1291
- return { output: value };
1289
+ function execEnvelope(text) {
1292
1290
  let parsed;
1293
1291
  try {
1294
- parsed = JSON.parse(value);
1292
+ parsed = JSON.parse(text);
1295
1293
  } catch {
1296
- return { output: value };
1294
+ return void 0;
1297
1295
  }
1298
1296
  if (!parsed || typeof parsed !== "object" || Array.isArray(parsed))
1299
- return { output: value };
1297
+ return void 0;
1300
1298
  const bag = parsed;
1301
1299
  if (!Object.prototype.hasOwnProperty.call(bag, "output"))
1302
- return { output: value };
1300
+ return void 0;
1303
1301
  const metadata = bag["metadata"];
1304
- if (!metadata || typeof metadata !== "object")
1305
- return { output: value };
1306
- const exitCode = num(metadata["exit_code"]);
1302
+ const exitCode = num(bag["exit_code"]) ?? (metadata && typeof metadata === "object" ? num(metadata["exit_code"]) : void 0);
1307
1303
  if (exitCode === void 0)
1308
- return { output: value };
1304
+ return void 0;
1309
1305
  return { output: bag["output"], exitCode };
1310
1306
  }
1307
+ function execResult(value) {
1308
+ if (typeof value === "string")
1309
+ return execEnvelope(value) ?? { output: value };
1310
+ if (Array.isArray(value)) {
1311
+ for (const block of value) {
1312
+ if (!block || typeof block !== "object")
1313
+ continue;
1314
+ const text = block["text"];
1315
+ if (typeof text !== "string")
1316
+ continue;
1317
+ const envelope = execEnvelope(text);
1318
+ if (envelope)
1319
+ return envelope;
1320
+ }
1321
+ }
1322
+ return { output: textOf(value) ?? value };
1323
+ }
1311
1324
  function jwtClaims(token) {
1312
1325
  const parts = token.split(".");
1313
1326
  if (parts.length !== 3 || !parts[1])
@@ -1507,8 +1520,7 @@ var codexTranscript = {
1507
1520
  }
1508
1521
  ];
1509
1522
  case "function_call_output": {
1510
- const flattened = textOf(payload["output"]) ?? payload["output"];
1511
- const { output, exitCode } = unwrapExecOutput(flattened);
1523
+ const { output, exitCode } = execResult(payload["output"]);
1512
1524
  return [
1513
1525
  {
1514
1526
  ...base,
@@ -1539,8 +1551,7 @@ var codexTranscript = {
1539
1551
  }
1540
1552
  ];
1541
1553
  case "custom_tool_call_output": {
1542
- const flattened = textOf(payload["output"]) ?? payload["output"];
1543
- const { output, exitCode } = unwrapExecOutput(flattened);
1554
+ const { output, exitCode } = execResult(payload["output"]);
1544
1555
  return [
1545
1556
  {
1546
1557
  ...base,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@darkhunt-security/endpoint-codex",
3
- "version": "0.9.11",
3
+ "version": "0.9.13",
4
4
  "type": "module",
5
5
  "description": "Darkhunt endpoint adapter for Codex CLI: hook codec, rollout transcript mapper, plugin manifest.",
6
6
  "bin": {