@hasna/hooks 0.9.0 → 0.9.1

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/bin/serve.js CHANGED
@@ -186,10 +186,10 @@ var HOOKS = [
186
186
  name: "trash-guard",
187
187
  displayName: "Trash Guard",
188
188
  description: "Rewrites rm issued through Bash into `trash guard`, so the delete lands in a recoverable trash store; refuses the delete when there is nothing to redirect to (trash absent, a delete verb it cannot rewrite, or the protected class: /, ~, ~/.hasna, ~/.ssh, ~/.aws)",
189
- version: "0.1.0",
189
+ version: "0.1.1",
190
190
  category: "Git Safety",
191
191
  event: "PreToolUse",
192
- matcher: "Bash",
192
+ matcher: "^(Bash|apply_patch|ApplyPatch|functions\\.apply_patch)$",
193
193
  tags: ["rm", "delete", "trash", "recoverable", "guard", "safety", "bash"],
194
194
  rewritesInput: true,
195
195
  timeoutSeconds: 5
@@ -5092,6 +5092,10 @@ function runRetention(db, days) {
5092
5092
 
5093
5093
  // src/db/index.ts
5094
5094
  var instance = null;
5095
+ var localStoreRefusal = null;
5096
+ function isLocalStoreRefused() {
5097
+ return localStoreRefusal !== null;
5098
+ }
5095
5099
  function resolveDataDir() {
5096
5100
  const effective = getEffectiveDataRoot();
5097
5101
  const oldDir = join5(getHomeDir(), ".hooks");
@@ -5115,6 +5119,8 @@ function ensureDir(dbPath) {
5115
5119
  }
5116
5120
  }
5117
5121
  function getDb() {
5122
+ if (localStoreRefusal !== null)
5123
+ throw new Error(localStoreRefusal);
5118
5124
  if (instance)
5119
5125
  return instance;
5120
5126
  const dbPath = getDbPath();
@@ -5150,6 +5156,9 @@ async function sha256File(path) {
5150
5156
  const buf = await readFile(path);
5151
5157
  return sha256Of(buf);
5152
5158
  }
5159
+ function storeDb() {
5160
+ return isLocalStoreRefused() ? null : getDb();
5161
+ }
5153
5162
  function getHookRecord(db, name) {
5154
5163
  return db.query("SELECT * FROM hooks WHERE name = ?").get(name);
5155
5164
  }
@@ -5238,14 +5247,16 @@ function setPinnedHook(name, entry) {
5238
5247
  }
5239
5248
  function retrustHook(name, scriptPath, version, source) {
5240
5249
  const actual = sha256Of(readFileSync3(scriptPath));
5241
- const db = getDb();
5242
- upsertHookRecord(db, {
5243
- name,
5244
- version,
5245
- sha256: actual,
5246
- source_type: source,
5247
- last_verified_at: new Date().toISOString()
5248
- });
5250
+ const db = storeDb();
5251
+ if (db) {
5252
+ upsertHookRecord(db, {
5253
+ name,
5254
+ version,
5255
+ sha256: actual,
5256
+ source_type: source,
5257
+ last_verified_at: new Date().toISOString()
5258
+ });
5259
+ }
5249
5260
  setPinnedHook(name, { version, sha256: actual, source });
5250
5261
  return { ok: true, pinned: true, expected: actual, actual, name };
5251
5262
  }
@@ -5339,7 +5350,7 @@ import { readFileSync as readFileSync5 } from "fs";
5339
5350
  import { dirname as dirname3, join as join8 } from "path";
5340
5351
  import { fileURLToPath as fileURLToPath2 } from "url";
5341
5352
 
5342
- // ../contracts/dist/client/transport.js
5353
+ // ../../node_modules/.bun/@hasna+contracts@1.0.2+e0db24ae03127387/node_modules/@hasna/contracts/dist/client/transport.js
5343
5354
  import { spawnSync } from "child_process";
5344
5355
  import { closeSync, fstatSync, openSync, readFileSync as readFileSync4 } from "fs";
5345
5356
  import { O_NOFOLLOW, O_NONBLOCK, O_RDONLY } from "constants";
@@ -6219,7 +6230,7 @@ function startServeServer(options) {
6219
6230
  return handleServeRequest(req, resolveHooksServePublishKey());
6220
6231
  }
6221
6232
  });
6222
- console.error(`hooks registry listening on http://${host}:${port} (publish requires an API key)`);
6233
+ console.error(`hooks registry listening on http://${host}:${server.port} (publish requires an API key)`);
6223
6234
  return server;
6224
6235
  }
6225
6236
  if (import.meta.main) {
@@ -7,6 +7,14 @@
7
7
  * Supports HASNA_HOOKS_DATA_DIR / HOOKS_DATA_DIR and HASNA_HOOKS_DB_PATH / HOOKS_DB_PATH env overrides.
8
8
  */
9
9
  import { Database } from "bun:sqlite";
10
+ /** Refuse every local-store open for the rest of this process. */
11
+ export declare function refuseLocalStore(message: string): void;
12
+ /** Lift a refusal installed by {@link refuseLocalStore}. Test seam. */
13
+ export declare function allowLocalStore(): void;
14
+ /** True while {@link refuseLocalStore} is in force for this process. */
15
+ export declare function isLocalStoreRefused(): boolean;
16
+ /** The installed refusal text, or null when the store is not refused. */
17
+ export declare function localStoreRefusalMessage(): string | null;
10
18
  export declare function getDbPath(): string;
11
19
  export declare function getDb(): Database;
12
20
  export declare function closeDb(): void;
package/dist/index.d.ts CHANGED
@@ -77,6 +77,9 @@ export type { StorageBackend, StorageEnv, StorageStatus, SyncMeta, SyncResult }
77
77
  export { getHooksDataDir, getCustomHooksDir, getLockPath, } from "./config.js";
78
78
  export { resolveHooksTransport, resolveHooksServePublishKey, hooksRegistryOrigin, type HooksRemoteAuthority, type HooksCredentialOptions, type HooksTransportMode, type HooksTransportNotice, type HooksTransportOptions, type HooksTransportResolution, } from "./lib/transport.js";
79
79
  export type { HooksLocalOptInEnv } from "./lib/resolver-types.js";
80
+ export { HOOKS_LOCAL_OPT_IN_ENV_KEYS, isHooksLocalOptIn, hasHooksEnvAuthorityIntent, selectsHooksLocalStore, hooksFailClosedLine, hooksHostedRouteLocalStoreRefusal, hooksEventSinkRefusal, } from "./lib/local-opt-in.js";
81
+ export { refuseLocalStore, allowLocalStore, isLocalStoreRefused } from "./db/index.js";
82
+ export { resolveHookEventSink, type HookEventSink } from "./lib/db-writer.js";
80
83
  export { getHookRecord, listHookRecords, upsertHookRecord, removeHookRecord, readLock, writeLock, setPinnedHook, getPinnedHook, removePinnedHook, pinInstalledHook, removeHookFromStore, verifyScriptHash, checkScriptHash, retrustHook, sha256Of, sha256File, } from "./lib/store.js";
81
84
  export type { HookRecord, LockEntry, LockFile, TrustCheck } from "./lib/store.js";
82
85
  export { parseManifest, readCustomManifest, listCustomHooks, writeCustomHook, resolveScript, } from "./lib/manifest.js";
@@ -85,7 +88,7 @@ export { resolveHook, resolveHookDir, resolveHookMeta, resolveScriptPath, } from
85
88
  export type { ResolvedHook, HookSource } from "./lib/resolve.js";
86
89
  export { installCustomSource, isCustomSource, } from "./lib/custom-install.js";
87
90
  export type { CustomInstallResult, CustomSourceKind } from "./lib/custom-install.js";
88
- export { planSync, syncHooks, fetchPinnedHook, } from "./lib/sync.js";
91
+ export { planSync, syncHooks, fetchPinnedHook, installPinnedFromBundled, } from "./lib/sync.js";
89
92
  export type { SyncDiff, SyncPlan, ArtifactResponse, PinnedHookInstall } from "./lib/sync.js";
90
93
  export { handleServeRequest, startServeServer, DEFAULT_SERVE_PORT, } from "./serve.js";
91
94
  export type { CatalogEntry, ArtifactPayload } from "./serve.js";