@hasna/hooks 0.12.20 → 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.
@@ -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, readSync, realpathSync, statSync } from "fs";
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 = realpathSync(path), socket = statSync(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 as realpathSync2, writeFileSync } from "fs";
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 = realpathSync2(invocation.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 (realpathSync2(directory) !== directory)
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 = realpathSync2(entrypoint);
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" };