@hasna/hooks 0.8.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.
Files changed (63) hide show
  1. package/README.md +33 -5
  2. package/bin/hooks-mcp.js +4862 -0
  3. package/bin/index.js +592 -170
  4. package/bin/serve.js +33 -10
  5. package/dist/db/index.d.ts +8 -0
  6. package/dist/index.d.ts +4 -1
  7. package/dist/index.js +2870 -2709
  8. package/dist/lib/db-writer.d.ts +30 -1
  9. package/dist/lib/installer.d.ts +40 -1
  10. package/dist/lib/local-opt-in.d.ts +26 -0
  11. package/dist/lib/registration.d.ts +75 -0
  12. package/dist/lib/registry.d.ts +14 -0
  13. package/dist/lib/sync.d.ts +17 -1
  14. package/dist/sdk/index.d.ts +103 -0
  15. package/dist/sdk/index.js +1050 -0
  16. package/dist/storage.js +15 -1
  17. package/hooks/hook-agent-rules-version-check/README.md +1 -1
  18. package/hooks/hook-trash-guard/README.md +147 -0
  19. package/hooks/hook-trash-guard/package.json +12 -0
  20. package/hooks/hook-trash-guard/src/hook.ts +1142 -0
  21. package/package.json +10 -3
  22. package/scripts/validate-package.ts +31 -4
  23. package/hooks/codewith-native-common.test.ts +0 -1935
  24. package/hooks/hook-affected-tests/tsconfig.json +0 -25
  25. package/hooks/hook-agent-rules-version-check/src/hook.test.ts +0 -104
  26. package/hooks/hook-agent-rules-version-check/tsconfig.json +0 -25
  27. package/hooks/hook-announce-start/tsconfig.json +0 -25
  28. package/hooks/hook-announce-stop/tsconfig.json +0 -25
  29. package/hooks/hook-autoformat/tsconfig.json +0 -25
  30. package/hooks/hook-branchprotect/tsconfig.json +0 -25
  31. package/hooks/hook-checkbugs/tsconfig.json +0 -15
  32. package/hooks/hook-checkdocs/tsconfig.json +0 -15
  33. package/hooks/hook-checkfiles/tsconfig.json +0 -15
  34. package/hooks/hook-checklint/tsconfig.json +0 -15
  35. package/hooks/hook-checkpoint/tsconfig.json +0 -25
  36. package/hooks/hook-checksecurity/tsconfig.json +0 -15
  37. package/hooks/hook-checktasks/tsconfig.json +0 -20
  38. package/hooks/hook-checktests/tsconfig.json +0 -15
  39. package/hooks/hook-conflict-detect/tsconfig.json +0 -25
  40. package/hooks/hook-contextrefresh/tsconfig.json +0 -25
  41. package/hooks/hook-desktopnotify/tsconfig.json +0 -25
  42. package/hooks/hook-dm-inject/tsconfig.json +0 -25
  43. package/hooks/hook-envsetup/tsconfig.json +0 -25
  44. package/hooks/hook-failure-to-task/tsconfig.json +0 -25
  45. package/hooks/hook-filelock/tsconfig.json +0 -25
  46. package/hooks/hook-fleet-blockers-gate/src/hook.test.ts +0 -302
  47. package/hooks/hook-fleet-blockers-gate/tsconfig.json +0 -25
  48. package/hooks/hook-fleet-catchup/src/hook.test.ts +0 -156
  49. package/hooks/hook-fleet-catchup/tsconfig.json +0 -25
  50. package/hooks/hook-gitguard/tsconfig.json +0 -25
  51. package/hooks/hook-knowledge-context/src/hook.test.ts +0 -379
  52. package/hooks/hook-packageage/tsconfig.json +0 -25
  53. package/hooks/hook-permissionguard/tsconfig.json +0 -25
  54. package/hooks/hook-phonenotify/tsconfig.json +0 -25
  55. package/hooks/hook-precompact/tsconfig.json +0 -25
  56. package/hooks/hook-protectfiles/tsconfig.json +0 -25
  57. package/hooks/hook-scanoutput/src/hook.test.ts +0 -217
  58. package/hooks/hook-spiral-detector/src/hook.test.ts +0 -72
  59. package/hooks/hook-stylescheck/tsconfig.json +0 -25
  60. package/hooks/hook-typecheck-gate/tsconfig.json +0 -25
  61. package/hooks/hook-workspace-repos-guard/src/hook.test.ts +0 -466
  62. package/hooks/hook-workspace-repos-guard/tsconfig.json +0 -21
  63. package/hooks/mention-context/src/hook.test.ts +0 -68
package/bin/serve.js CHANGED
@@ -182,6 +182,18 @@ var HOOKS = [
182
182
  matcher: "^(Bash|Write|Edit|MultiEdit|NotebookEdit|apply_patch|ApplyPatch|functions\\.apply_patch)$",
183
183
  tags: ["workspace", "repos", "structure", "guard", "safety", "orgs", "multi-agent"]
184
184
  },
185
+ {
186
+ name: "trash-guard",
187
+ displayName: "Trash Guard",
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.1",
190
+ category: "Git Safety",
191
+ event: "PreToolUse",
192
+ matcher: "^(Bash|apply_patch|ApplyPatch|functions\\.apply_patch)$",
193
+ tags: ["rm", "delete", "trash", "recoverable", "guard", "safety", "bash"],
194
+ rewritesInput: true,
195
+ timeoutSeconds: 5
196
+ },
185
197
  {
186
198
  name: "checktests",
187
199
  displayName: "Check Tests",
@@ -5080,6 +5092,10 @@ function runRetention(db, days) {
5080
5092
 
5081
5093
  // src/db/index.ts
5082
5094
  var instance = null;
5095
+ var localStoreRefusal = null;
5096
+ function isLocalStoreRefused() {
5097
+ return localStoreRefusal !== null;
5098
+ }
5083
5099
  function resolveDataDir() {
5084
5100
  const effective = getEffectiveDataRoot();
5085
5101
  const oldDir = join5(getHomeDir(), ".hooks");
@@ -5103,6 +5119,8 @@ function ensureDir(dbPath) {
5103
5119
  }
5104
5120
  }
5105
5121
  function getDb() {
5122
+ if (localStoreRefusal !== null)
5123
+ throw new Error(localStoreRefusal);
5106
5124
  if (instance)
5107
5125
  return instance;
5108
5126
  const dbPath = getDbPath();
@@ -5138,6 +5156,9 @@ async function sha256File(path) {
5138
5156
  const buf = await readFile(path);
5139
5157
  return sha256Of(buf);
5140
5158
  }
5159
+ function storeDb() {
5160
+ return isLocalStoreRefused() ? null : getDb();
5161
+ }
5141
5162
  function getHookRecord(db, name) {
5142
5163
  return db.query("SELECT * FROM hooks WHERE name = ?").get(name);
5143
5164
  }
@@ -5226,14 +5247,16 @@ function setPinnedHook(name, entry) {
5226
5247
  }
5227
5248
  function retrustHook(name, scriptPath, version, source) {
5228
5249
  const actual = sha256Of(readFileSync3(scriptPath));
5229
- const db = getDb();
5230
- upsertHookRecord(db, {
5231
- name,
5232
- version,
5233
- sha256: actual,
5234
- source_type: source,
5235
- last_verified_at: new Date().toISOString()
5236
- });
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
+ }
5237
5260
  setPinnedHook(name, { version, sha256: actual, source });
5238
5261
  return { ok: true, pinned: true, expected: actual, actual, name };
5239
5262
  }
@@ -5327,7 +5350,7 @@ import { readFileSync as readFileSync5 } from "fs";
5327
5350
  import { dirname as dirname3, join as join8 } from "path";
5328
5351
  import { fileURLToPath as fileURLToPath2 } from "url";
5329
5352
 
5330
- // ../contracts/dist/client/transport.js
5353
+ // ../../node_modules/.bun/@hasna+contracts@1.0.2+e0db24ae03127387/node_modules/@hasna/contracts/dist/client/transport.js
5331
5354
  import { spawnSync } from "child_process";
5332
5355
  import { closeSync, fstatSync, openSync, readFileSync as readFileSync4 } from "fs";
5333
5356
  import { O_NOFOLLOW, O_NONBLOCK, O_RDONLY } from "constants";
@@ -6207,7 +6230,7 @@ function startServeServer(options) {
6207
6230
  return handleServeRequest(req, resolveHooksServePublishKey());
6208
6231
  }
6209
6232
  });
6210
- 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)`);
6211
6234
  return server;
6212
6235
  }
6213
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";