@hasna/hooks 0.12.21 → 0.12.22
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 +1 -1
- package/bin/hooks/stop-review.js +38 -7
- package/bin/hooks-mcp.js +2222 -1511
- package/bin/index.js +2475 -1782
- package/bin/native-safety-worker.cjs +1 -1
- package/dist/index.js +2389 -1678
- package/dist/lib/claude-skills-coordination.d.ts +1 -1
- package/dist/lib/codex-safety-check.d.ts +1 -1
- package/hooks/hook-stop-review/src/native.ts +29 -3
- package/package.json +2 -2
- package/scripts/validate-package.ts +42 -0
package/README.md
CHANGED
|
@@ -481,7 +481,7 @@ Codex is installed through npm, pass the platform package's native binary rather
|
|
|
481
481
|
than its JavaScript launcher. Executable ownership, permissions, ancestry and
|
|
482
482
|
bytes are checked. Supported protocol versions are 0.153.0, 0.154.0,
|
|
483
483
|
0.154.0-alpha.6.1, 0.155.0, 0.155.1, 0.156.1, 0.157.0, 0.157.1, 0.158.0, 0.159.0, 0.159.2,
|
|
484
|
-
0.159.3, 0.160.0, 0.160.1, 0.161.0, 0.162.0 and 0.
|
|
484
|
+
0.159.3, 0.160.0, 0.160.1, 0.161.0, 0.162.0, 0.162.1 and 0.163.0;
|
|
485
485
|
other versions refuse pending compatibility validation. Updating Codex can
|
|
486
486
|
therefore require a compatible Hooks release before native safety verification
|
|
487
487
|
and trust provisioning succeed. Keep existing hook definitions and trust intact
|
package/bin/hooks/stop-review.js
CHANGED
|
@@ -7,8 +7,8 @@ import { join as join4 } from "path";
|
|
|
7
7
|
|
|
8
8
|
// hooks/hook-stop-review/src/native.ts
|
|
9
9
|
import { createHash } from "crypto";
|
|
10
|
-
import { constants, closeSync, fstatSync, openSync,
|
|
11
|
-
import { isAbsolute, join } from "path";
|
|
10
|
+
import { constants, closeSync, fstatSync, openSync, readlinkSync, readSync, statSync } from "fs";
|
|
11
|
+
import { dirname, isAbsolute, join } from "path";
|
|
12
12
|
var object = (x) => !!x && typeof x === "object" && !Array.isArray(x);
|
|
13
13
|
var id = (x) => typeof x === "string" && /^[A-Za-z0-9][A-Za-z0-9._:-]{0,255}$/.test(x);
|
|
14
14
|
var text = (x, max = Infinity) => typeof x === "string" && x.trim().length > 0 && Buffer.byteLength(x) <= max;
|
|
@@ -239,12 +239,43 @@ function codexGoalFromResponse(value, sessionId) {
|
|
|
239
239
|
Object.defineProperty(projected, nativeGoalRevision, { value: digest([goal.createdAt, goal.updatedAt, goal.tokenBudget, goal.tokensUsed]), enumerable: false });
|
|
240
240
|
return projected;
|
|
241
241
|
}
|
|
242
|
+
function resolveControlSocket(path) {
|
|
243
|
+
const pending = (isAbsolute(path) ? path : `${process.cwd()}/${path}`).split("/");
|
|
244
|
+
let physical = "/", links = 0;
|
|
245
|
+
while (pending.length) {
|
|
246
|
+
const part = pending.shift();
|
|
247
|
+
if (!part || part === ".")
|
|
248
|
+
continue;
|
|
249
|
+
if (part === "..") {
|
|
250
|
+
physical = dirname(physical);
|
|
251
|
+
continue;
|
|
252
|
+
}
|
|
253
|
+
const next = join(physical, part);
|
|
254
|
+
let target;
|
|
255
|
+
try {
|
|
256
|
+
target = readlinkSync(next);
|
|
257
|
+
} catch (error) {
|
|
258
|
+
if (!object(error) || error.code !== "EINVAL")
|
|
259
|
+
throw error;
|
|
260
|
+
if (pending.length && !statSync(next).isDirectory())
|
|
261
|
+
throw new Error("control_socket_parent_not_directory");
|
|
262
|
+
physical = next;
|
|
263
|
+
continue;
|
|
264
|
+
}
|
|
265
|
+
if (++links > 40)
|
|
266
|
+
throw new Error("control_socket_symlink_limit");
|
|
267
|
+
if (isAbsolute(target))
|
|
268
|
+
physical = "/";
|
|
269
|
+
pending.unshift(...target.split("/"));
|
|
270
|
+
}
|
|
271
|
+
return physical;
|
|
272
|
+
}
|
|
242
273
|
async function readCodexGoal(sessionId, options) {
|
|
243
274
|
if (!id(sessionId) || !isAbsolute(options.codexHome))
|
|
244
275
|
return;
|
|
245
276
|
const path = options.socketPath ?? join(options.codexHome, "app-server-control", "app-server-control.sock");
|
|
246
277
|
try {
|
|
247
|
-
const physical =
|
|
278
|
+
const physical = resolveControlSocket(path), socket = statSync(physical);
|
|
248
279
|
if (!socket.isSocket() || socket.uid !== process.getuid?.() || (socket.mode & 63) !== 0)
|
|
249
280
|
return;
|
|
250
281
|
return await new Promise((resolve) => {
|
|
@@ -303,7 +334,7 @@ async function runNativeStop(raw, options, review) {
|
|
|
303
334
|
// hooks/hook-stop-review/src/runtime.ts
|
|
304
335
|
import { spawn } from "child_process";
|
|
305
336
|
import { createHash as createHash2 } from "crypto";
|
|
306
|
-
import { closeSync as closeSync2, constants as constants2, fstatSync as fstatSync2, fsyncSync, lstatSync, mkdirSync, openSync as openSync2, readFileSync, realpathSync
|
|
337
|
+
import { closeSync as closeSync2, constants as constants2, fstatSync as fstatSync2, fsyncSync, lstatSync, mkdirSync, openSync as openSync2, readFileSync, realpathSync, writeFileSync } from "fs";
|
|
307
338
|
import { isAbsolute as isAbsolute2, join as join3 } from "path";
|
|
308
339
|
|
|
309
340
|
// src/lib/app-home.ts
|
|
@@ -881,7 +912,7 @@ var runRuntimeCommand = (invocation) => new Promise((resolve2) => {
|
|
|
881
912
|
finish({ ok: false });
|
|
882
913
|
};
|
|
883
914
|
try {
|
|
884
|
-
const command =
|
|
915
|
+
const command = realpathSync(invocation.command);
|
|
885
916
|
const stat = lstatSync(command);
|
|
886
917
|
if (!stat.isFile() || (stat.mode & 18) !== 0 || process.getuid && ![0, process.getuid()].includes(stat.uid))
|
|
887
918
|
return finish({ ok: false });
|
|
@@ -986,7 +1017,7 @@ function claimStopReviewTurn(envelope, env = process.env, requestHash, instructi
|
|
|
986
1017
|
const root = getEffectiveDataRoot(env);
|
|
987
1018
|
const directory = join3(root, "state", "stop-review", "turn-claims");
|
|
988
1019
|
mkdirSync(directory, { recursive: true, mode: 448 });
|
|
989
|
-
if (
|
|
1020
|
+
if (realpathSync(directory) !== directory)
|
|
990
1021
|
return "unavailable";
|
|
991
1022
|
const stat = lstatSync(directory);
|
|
992
1023
|
if (!stat.isDirectory() || (stat.mode & 63) !== 0 || process.getuid && stat.uid !== process.getuid())
|
|
@@ -1050,7 +1081,7 @@ async function evaluateThroughSecrets(envelope, instruction, config, env, entryp
|
|
|
1050
1081
|
return { ok: false, reason: "invalid_configuration" };
|
|
1051
1082
|
let canonical;
|
|
1052
1083
|
try {
|
|
1053
|
-
canonical =
|
|
1084
|
+
canonical = realpathSync(entrypoint);
|
|
1054
1085
|
const stat = lstatSync(canonical);
|
|
1055
1086
|
if (!stat.isFile() || (stat.mode & 18) !== 0 || process.getuid && ![0, process.getuid()].includes(stat.uid))
|
|
1056
1087
|
return { ok: false, reason: "invalid_configuration" };
|