@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.
@@ -13,7 +13,7 @@ export declare class ClaudeSettingsRefusal extends Error {
13
13
  * as any file type. A lookup error other than ENOENT/ENOTDIR counts as present.
14
14
  * Returns the evidence found; an empty list means Skills is genuinely absent. */
15
15
  export declare function claudeSkillsUsage(before: string | null, home: string): string[];
16
- /** Every location the bundled Skills package (@hasna/skills 0.10.71, `getDataRoot`)
16
+ /** Every location the bundled Skills package (@hasna/skills 0.10.73, `getDataRoot`)
17
17
  * considers for `agent-policy.json`, in its resolution order, with the outcome
18
18
  * at each. Only called after Skills found no policy at the selected location. */
19
19
  export declare function skillsPolicyLocations(dataDir?: string): string[];
@@ -2,7 +2,7 @@ import { type NativeSafetyName } from "./native-safety.js";
2
2
  import { verifyNativeSafetyCommand } from "../native-safety.js";
3
3
  /** Exact `codex --version` outputs whose app-server protocol was measured
4
4
  * against the real native binary. Anything else refuses as native_unsupported. */
5
- export declare const SUPPORTED_CODEX_SAFETY_VERSIONS: readonly ["codex-cli 0.153.0", "codex-cli 0.154.0", "codex-cli 0.154.0-alpha.6.1", "codex-cli 0.155.0", "codex-cli 0.155.1", "codex-cli 0.156.1", "codex-cli 0.157.0", "codex-cli 0.157.1", "codex-cli 0.158.0", "codex-cli 0.159.0", "codex-cli 0.159.2", "codex-cli 0.159.3", "codex-cli 0.160.0", "codex-cli 0.160.1", "codex-cli 0.161.0", "codex-cli 0.162.0", "codex-cli 0.162.1"];
5
+ export declare const SUPPORTED_CODEX_SAFETY_VERSIONS: readonly ["codex-cli 0.153.0", "codex-cli 0.154.0", "codex-cli 0.154.0-alpha.6.1", "codex-cli 0.155.0", "codex-cli 0.155.1", "codex-cli 0.156.1", "codex-cli 0.157.0", "codex-cli 0.157.1", "codex-cli 0.158.0", "codex-cli 0.159.0", "codex-cli 0.159.2", "codex-cli 0.159.3", "codex-cli 0.160.0", "codex-cli 0.160.1", "codex-cli 0.161.0", "codex-cli 0.162.0", "codex-cli 0.162.1", "codex-cli 0.163.0"];
6
6
  /** Hard sanity bound on the native Codex executable, which is read whole into
7
7
  * memory for the header check and SHA-256 pin. Not a platform contract: the
8
8
  * measured 0.162.1 binaries are 246.6 MB (darwin-arm64) to 294.4 MB (linux-x64). */
@@ -1,6 +1,6 @@
1
1
  import { createHash } from "node:crypto";
2
- import { constants, closeSync, fstatSync, openSync, readSync, realpathSync, statSync } from "node:fs";
3
- import { isAbsolute, join } from "node:path";
2
+ import { constants, closeSync, fstatSync, openSync, readlinkSync, readSync, statSync } from "node:fs";
3
+ import { dirname, isAbsolute, join } from "node:path";
4
4
  import type { StopReviewEnvelope, StopReviewResult } from "./types";
5
5
 
6
6
  export type NativeHarness = "codex" | "claude";
@@ -199,12 +199,38 @@ export function codexGoalFromResponse(value: unknown, sessionId: string): Native
199
199
  return projected;
200
200
  }
201
201
 
202
+ /** Avoid Bun socket realpath failures and resolve symlinks before any subsequent '..'. */
203
+ function resolveControlSocket(path: string): string {
204
+ const pending = (isAbsolute(path) ? path : `${process.cwd()}/${path}`).split("/");
205
+ let physical = "/", links = 0;
206
+ while (pending.length) {
207
+ const part = pending.shift()!;
208
+ if (!part || part === ".") continue;
209
+ if (part === "..") { physical = dirname(physical); continue; }
210
+ const next = join(physical, part);
211
+ let target: string;
212
+ try {
213
+ target = readlinkSync(next);
214
+ } catch (error) {
215
+ // Only EINVAL means non-symlink. Other errors leave the native goal unreadable.
216
+ if (!object(error) || error.code !== "EINVAL") throw error;
217
+ if (pending.length && !statSync(next).isDirectory()) throw new Error("control_socket_parent_not_directory");
218
+ physical = next;
219
+ continue;
220
+ }
221
+ if (++links > 40) throw new Error("control_socket_symlink_limit");
222
+ if (isAbsolute(target)) physical = "/";
223
+ pending.unshift(...target.split("/"));
224
+ }
225
+ return physical;
226
+ }
227
+
202
228
  /** Existing native daemon only. Path is the rust-v0.161.0 owning resolver's CODEX_HOME-relative control socket. */
203
229
  export async function readCodexGoal(sessionId: string, options: { codexHome: string; socketPath?: string; timeoutMs?: number }): Promise<NativeGoal> {
204
230
  if (!id(sessionId) || !isAbsolute(options.codexHome)) return undefined;
205
231
  const path = options.socketPath ?? join(options.codexHome, "app-server-control", "app-server-control.sock");
206
232
  try {
207
- const physical = realpathSync(path), socket = statSync(physical);
233
+ const physical = resolveControlSocket(path), socket = statSync(physical);
208
234
  if (!socket.isSocket() || socket.uid !== process.getuid?.() || (socket.mode & 0o077) !== 0) return undefined;
209
235
  // Bun's WebSocket supports ws+unix transport; no TCP endpoint, proxy subprocess, or daemon launch.
210
236
  return await new Promise<NativeGoal>((resolve) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hasna/hooks",
3
- "version": "0.12.21",
3
+ "version": "0.12.22",
4
4
  "description": "Open source hooks library for AI coding agents - Install safety, quality, and automation hooks with a single command",
5
5
  "type": "module",
6
6
  "bin": {
@@ -87,7 +87,7 @@
87
87
  "@hasna/contracts": "~1.2.1"
88
88
  },
89
89
  "dependencies": {
90
- "@hasna/skills": "0.10.71",
90
+ "@hasna/skills": "0.10.73",
91
91
  "@hasna/events": "^0.1.16",
92
92
  "@hasna/secrets": "0.4.2",
93
93
  "@modelcontextprotocol/sdk": "1.31.0",
@@ -231,6 +231,47 @@ console.log("packed credential-file reference, rotation and terminal failure pas
231
231
  * Lanes: CLI help, serve /health, MCP stdio startup (initialize handshake),
232
232
  * a runtime SDK import, and one bundled-hook run with an isolated data dir.
233
233
  */
234
+ /** HO-00079: exercise the extracted Hooks parser, not the source Skills parser.
235
+ * The generator uses the exact declared installed Skills dependency. Only the
236
+ * fixtures are planner-generated test data; neither check applies a registration. */
237
+ async function validatePackedSkillsPolicy(pkg: PackageJson, packageDir: string, smokeDir: string): Promise<void> {
238
+ const installedSkills = Bun.resolveSync("@hasna/skills", join(root, "src/test"));
239
+ const dependency = await readPackageJson(join(dirname(dirname(installedSkills)), "package.json"));
240
+ const declaredVersion = pkg.dependencies?.["@hasna/skills"];
241
+ if (!declaredVersion || dependency.name !== "@hasna/skills" || dependency.version !== declaredVersion)
242
+ throw new Error("Packed policy validation requires the exact declared Skills dependency");
243
+ const home = join(smokeDir, "skills-policy-home");
244
+ await mkdir(home, { mode: 0o700 });
245
+ const fixture = join(smokeDir, "skills-policy-smoke.ts");
246
+ await writeFile(fixture, `
247
+ import assert from "node:assert/strict";
248
+ import { join } from "node:path";
249
+ import { planNativeSafetyRegistration } from ${JSON.stringify(join(packageDir, "dist/index.js"))};
250
+ import { generatePackedReaderPolicy, policyHashModes, treeSnapshot, withPolicyMutation } from ${JSON.stringify(join(root, "src/test/skills-policy-fixture.ts"))};
251
+ const home = process.env.HOME, dataDir = join(home, "skills-data");
252
+ generatePackedReaderPolicy(home, dataDir);
253
+ assert.deepEqual(policyHashModes(dataDir).codex, ["codex-settings-v6", "bytes"]);
254
+ const options = { target: "claude" }, dependencies = { verify: async () => ({}) };
255
+ const before = treeSnapshot(home);
256
+ const plan = await planNativeSafetyRegistration(options, dependencies);
257
+ assert.equal(plan.action, "register");
258
+ assert.equal(plan.nativeAdoptionVerified, false);
259
+ assert.deepEqual(treeSnapshot(home), before);
260
+ withPolicyMutation(dataDir, policy => { policy.bridge.discovery.codex.sources[0].hashMode = "codex-settings-v99"; });
261
+ const damaged = treeSnapshot(home);
262
+ await assert.rejects(() => planNativeSafetyRegistration(options, dependencies), error =>
263
+ error.code === "writer_refused" && error.refusal?.message === "The Skills agent loading policy has invalid collection bounds; refusing legacy fallback.");
264
+ assert.deepEqual(treeSnapshot(home), damaged);
265
+ console.log("packed Hooks accepts codex-settings-v6 and refuses unknown mode without writes");
266
+ `);
267
+ const result = spawnSync(process.execPath, ["--config=/dev/null", "--no-env-file", "--no-macros", "--no-install", fixture], {
268
+ cwd: smokeDir, env: { HOME: home, PATH: process.env.PATH, HASNA_SKILLS_DIR: join(home, "skills-data") },
269
+ encoding: "utf8", timeout: 30_000,
270
+ });
271
+ if (result.status !== 0) throw new Error(`Packed Skills policy compatibility failed: ${result.stderr}`);
272
+ console.log(result.stdout.trim());
273
+ }
274
+
234
275
  async function validatePackedNativeSafety(packageDir: string, smokeDir: string): Promise<void> {
235
276
  const worker = join(packageDir, "bin/native-safety-entry.js");
236
277
  const bytes = await readFile(worker);
@@ -457,6 +498,7 @@ async function validateExtractedSmoke(pkg: PackageJson): Promise<void> {
457
498
  if (sdkOut.sdk !== "fail-closed" || !sdkOut.hasClient) throw new Error(`packed ./sdk export did not fail closed with nothing configured: ${JSON.stringify(sdkOut)}`);
458
499
  await validatePackedCredentialReferences(pkg, packageDir, smokeDir);
459
500
  await validatePackedNativeSafety(packageDir, smokeDir);
501
+ await validatePackedSkillsPolicy(pkg, packageDir, smokeDir);
460
502
 
461
503
  // 5. One bundled-hook run from the packed artifact (isolated data dir;
462
504
  // first run self-trusts, then executes).