@hasna/hooks 0.9.0 → 0.9.2
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 +43 -5
- package/bin/hooks-mcp.js +4980 -0
- package/bin/index.js +586 -252
- package/bin/serve.js +34 -12
- package/dist/db/index.d.ts +8 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.js +3016 -2782
- package/dist/lib/codex-settings.d.ts +3 -0
- package/dist/lib/db-writer.d.ts +30 -1
- package/dist/lib/installer.d.ts +1 -1
- package/dist/lib/local-opt-in.d.ts +26 -0
- package/dist/lib/sync.d.ts +17 -1
- package/dist/sdk/index.d.ts +103 -0
- package/dist/sdk/index.js +1050 -0
- package/dist/storage.js +15 -1
- package/hooks/hook-mementos-context/README.md +80 -0
- package/hooks/hook-mementos-context/src/hook.ts +116 -0
- package/hooks/hook-trash-guard/README.md +20 -5
- package/hooks/hook-trash-guard/package.json +1 -1
- package/hooks/hook-trash-guard/src/hook.ts +45 -17
- package/package.json +11 -5
- package/scripts/validate-package.ts +31 -4
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.
|
|
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
|
|
@@ -345,6 +345,17 @@ var HOOKS = [
|
|
|
345
345
|
matcher: "",
|
|
346
346
|
tags: ["knowledge", "context", "codewith", "deterministic", "session-start", "prompt", "subagent"]
|
|
347
347
|
},
|
|
348
|
+
{
|
|
349
|
+
name: "mementos-context",
|
|
350
|
+
displayName: "Mementos Prompt Context",
|
|
351
|
+
description: "Retrieves scoped memories for a user prompt, with optional relevance judgments",
|
|
352
|
+
version: "0.1.0",
|
|
353
|
+
category: "Context Management",
|
|
354
|
+
event: "UserPromptSubmit",
|
|
355
|
+
matcher: "",
|
|
356
|
+
timeoutSeconds: 12,
|
|
357
|
+
tags: ["mementos", "memory", "prompt", "codex", "claude", "codewith", "opt-in"]
|
|
358
|
+
},
|
|
348
359
|
{
|
|
349
360
|
name: "autoformat",
|
|
350
361
|
displayName: "Auto Format",
|
|
@@ -5092,6 +5103,10 @@ function runRetention(db, days) {
|
|
|
5092
5103
|
|
|
5093
5104
|
// src/db/index.ts
|
|
5094
5105
|
var instance = null;
|
|
5106
|
+
var localStoreRefusal = null;
|
|
5107
|
+
function isLocalStoreRefused() {
|
|
5108
|
+
return localStoreRefusal !== null;
|
|
5109
|
+
}
|
|
5095
5110
|
function resolveDataDir() {
|
|
5096
5111
|
const effective = getEffectiveDataRoot();
|
|
5097
5112
|
const oldDir = join5(getHomeDir(), ".hooks");
|
|
@@ -5115,6 +5130,8 @@ function ensureDir(dbPath) {
|
|
|
5115
5130
|
}
|
|
5116
5131
|
}
|
|
5117
5132
|
function getDb() {
|
|
5133
|
+
if (localStoreRefusal !== null)
|
|
5134
|
+
throw new Error(localStoreRefusal);
|
|
5118
5135
|
if (instance)
|
|
5119
5136
|
return instance;
|
|
5120
5137
|
const dbPath = getDbPath();
|
|
@@ -5150,6 +5167,9 @@ async function sha256File(path) {
|
|
|
5150
5167
|
const buf = await readFile(path);
|
|
5151
5168
|
return sha256Of(buf);
|
|
5152
5169
|
}
|
|
5170
|
+
function storeDb() {
|
|
5171
|
+
return isLocalStoreRefused() ? null : getDb();
|
|
5172
|
+
}
|
|
5153
5173
|
function getHookRecord(db, name) {
|
|
5154
5174
|
return db.query("SELECT * FROM hooks WHERE name = ?").get(name);
|
|
5155
5175
|
}
|
|
@@ -5238,14 +5258,16 @@ function setPinnedHook(name, entry) {
|
|
|
5238
5258
|
}
|
|
5239
5259
|
function retrustHook(name, scriptPath, version, source) {
|
|
5240
5260
|
const actual = sha256Of(readFileSync3(scriptPath));
|
|
5241
|
-
const db =
|
|
5242
|
-
|
|
5243
|
-
|
|
5244
|
-
|
|
5245
|
-
|
|
5246
|
-
|
|
5247
|
-
|
|
5248
|
-
|
|
5261
|
+
const db = storeDb();
|
|
5262
|
+
if (db) {
|
|
5263
|
+
upsertHookRecord(db, {
|
|
5264
|
+
name,
|
|
5265
|
+
version,
|
|
5266
|
+
sha256: actual,
|
|
5267
|
+
source_type: source,
|
|
5268
|
+
last_verified_at: new Date().toISOString()
|
|
5269
|
+
});
|
|
5270
|
+
}
|
|
5249
5271
|
setPinnedHook(name, { version, sha256: actual, source });
|
|
5250
5272
|
return { ok: true, pinned: true, expected: actual, actual, name };
|
|
5251
5273
|
}
|
|
@@ -5339,7 +5361,7 @@ import { readFileSync as readFileSync5 } from "fs";
|
|
|
5339
5361
|
import { dirname as dirname3, join as join8 } from "path";
|
|
5340
5362
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
5341
5363
|
|
|
5342
|
-
//
|
|
5364
|
+
// ../../node_modules/.bun/@hasna+contracts@1.0.2+e0db24ae03127387/node_modules/@hasna/contracts/dist/client/transport.js
|
|
5343
5365
|
import { spawnSync } from "child_process";
|
|
5344
5366
|
import { closeSync, fstatSync, openSync, readFileSync as readFileSync4 } from "fs";
|
|
5345
5367
|
import { O_NOFOLLOW, O_NONBLOCK, O_RDONLY } from "constants";
|
|
@@ -6219,7 +6241,7 @@ function startServeServer(options) {
|
|
|
6219
6241
|
return handleServeRequest(req, resolveHooksServePublishKey());
|
|
6220
6242
|
}
|
|
6221
6243
|
});
|
|
6222
|
-
console.error(`hooks registry listening on http://${host}:${port} (publish requires an API key)`);
|
|
6244
|
+
console.error(`hooks registry listening on http://${host}:${server.port} (publish requires an API key)`);
|
|
6223
6245
|
return server;
|
|
6224
6246
|
}
|
|
6225
6247
|
if (import.meta.main) {
|
package/dist/db/index.d.ts
CHANGED
|
@@ -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";
|