@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/README.md +33 -5
- package/bin/hooks-mcp.js +4862 -0
- package/bin/index.js +283 -109
- package/bin/serve.js +23 -12
- package/dist/db/index.d.ts +8 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.js +2870 -2757
- package/dist/lib/db-writer.d.ts +30 -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-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 +7 -2
- package/scripts/validate-package.ts +31 -4
package/dist/lib/db-writer.d.ts
CHANGED
|
@@ -1,8 +1,37 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Shared hook DB writer — single write path for all observability hooks.
|
|
3
3
|
* Never throws: errors are written to stderr only.
|
|
4
|
+
*
|
|
5
|
+
* GATED (hasna/apps#1720 fail-closed ruling, W6 2026-09-11). This used to be
|
|
6
|
+
* the one ungated path to ~/.hasna/hooks/hooks.db: every `hooks run`, every
|
|
7
|
+
* MCP run tool and four bundled hook runtimes called it, and it created the
|
|
8
|
+
* store on first write with no credential decision at all — a silent local
|
|
9
|
+
* default. It now writes ONLY when the environment selects the on-box store
|
|
10
|
+
* through the explicit opt-in (HASNA_HOOKS_LOCAL=1 / HOOKS_LOCAL=1, answered
|
|
11
|
+
* from the env dictionary alone — no Keychain or disk read on the per-event
|
|
12
|
+
* hot path). On the hosted route (a process-wide refusal installed by the CLI
|
|
13
|
+
* gate / MCP startup, or any authority variable set in the env) and in an
|
|
14
|
+
* unconfigured environment it prints ONE stderr line naming the opt-in and
|
|
15
|
+
* writes nothing: the hosted registry has no event route to port to.
|
|
16
|
+
*/
|
|
17
|
+
import type { HookEventRow } from "../db/schema.js";
|
|
18
|
+
import type { HooksLocalOptInEnv } from "./resolver-types.js";
|
|
19
|
+
/** Where a hook event may land: the on-box store, or nowhere (with the reason). */
|
|
20
|
+
export type HookEventSink = {
|
|
21
|
+
kind: "local";
|
|
22
|
+
} | {
|
|
23
|
+
kind: "refused";
|
|
24
|
+
reason: string;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Decide the event sink from the env dictionary and the process-wide store
|
|
28
|
+
* refusal ONLY — never the resolver, so agents' per-event `hooks run` and the
|
|
29
|
+
* bundled hook children never pay a `security` spawn here (the CLI gate
|
|
30
|
+
* already decided the route for the parent process).
|
|
4
31
|
*/
|
|
5
|
-
|
|
32
|
+
export declare function resolveHookEventSink(env?: HooksLocalOptInEnv): HookEventSink;
|
|
33
|
+
/** Reset the once-per-process sink refusal notice. Test seam only. */
|
|
34
|
+
export declare function __resetHookEventSinkNotice(): void;
|
|
6
35
|
export type HookEventInput = Omit<HookEventRow, "id" | "timestamp"> & {
|
|
7
36
|
timestamp?: string;
|
|
8
37
|
};
|
|
@@ -22,6 +22,32 @@ export declare function hooksAuthorityEnvKeys(): string[];
|
|
|
22
22
|
export declare function hasHooksEnvAuthorityIntent(env?: HooksLocalOptInEnv): boolean;
|
|
23
23
|
/** True when this environment should be served by the on-box bundled store. */
|
|
24
24
|
export declare function selectsHooksLocalStore(env?: HooksLocalOptInEnv): boolean;
|
|
25
|
+
/** The credential tiers every fail-closed line names, in chain order. Never a value. */
|
|
26
|
+
export declare const HOOKS_CREDENTIAL_TIERS = "the Keychain item hasna.credentials.hooks.api-key, ~/.hasna/hooks/config/credentials, or HASNA_HOOKS_API_KEY";
|
|
27
|
+
/** The opt-in every refusal names, canonical spelling first. */
|
|
28
|
+
export declare const HOOKS_LOCAL_OPT_IN_HINT = "HASNA_HOOKS_LOCAL=1 (alias HOOKS_LOCAL=1)";
|
|
29
|
+
/**
|
|
30
|
+
* The ONE line an unconfigured client surface prints before exiting non-zero
|
|
31
|
+
* (hasna/apps#1720 ruling, W6 target state): the stable code, the tiers
|
|
32
|
+
* consulted, the opt-in, and the refusal — no credential value, no local
|
|
33
|
+
* default. The CLI gate, the MCP server and the SDK all print this spelling.
|
|
34
|
+
*/
|
|
35
|
+
export declare function hooksFailClosedLine(detail?: string): string;
|
|
36
|
+
/**
|
|
37
|
+
* The refusal every local-only verb / tool returns on the HOSTED route: the
|
|
38
|
+
* on-box SQLite store is a different dataset from the registry authority the
|
|
39
|
+
* run is routed to, so it is never opened — not even to answer an empty
|
|
40
|
+
* result. Installed process-wide through `refuseLocalStore()` in
|
|
41
|
+
* `src/db/index.ts`. Mirrors todos' `REMOTE_COMMAND_UNSUPPORTED`.
|
|
42
|
+
*/
|
|
43
|
+
export declare function hooksHostedRouteLocalStoreRefusal(authority: string): string;
|
|
44
|
+
/**
|
|
45
|
+
* The line the hook-event writer prints (once per process) when it has no
|
|
46
|
+
* sink: the hosted registry has no event route, so without the explicit
|
|
47
|
+
* local opt-in there is nowhere to record the event — and it is NOT written
|
|
48
|
+
* to a silently created hooks.db.
|
|
49
|
+
*/
|
|
50
|
+
export declare function hooksEventSinkRefusal(): string;
|
|
25
51
|
/**
|
|
26
52
|
* The environment as the resolver should see it: every authority/credential
|
|
27
53
|
* variable that is DECLARED BUT BLANK removed.
|
package/dist/lib/sync.d.ts
CHANGED
|
@@ -92,7 +92,8 @@ export interface PinnedHookInstall {
|
|
|
92
92
|
sha256: string;
|
|
93
93
|
source: string;
|
|
94
94
|
source_ref: string;
|
|
95
|
-
artifact
|
|
95
|
+
/** The registry artifact for remote pins; null for bundled-registry pins. */
|
|
96
|
+
artifact: ArtifactResponse | null;
|
|
96
97
|
scriptPath: string;
|
|
97
98
|
}
|
|
98
99
|
/**
|
|
@@ -107,4 +108,19 @@ export interface PinnedHookInstall {
|
|
|
107
108
|
* are first-class, never rejected as "not the latest".
|
|
108
109
|
*/
|
|
109
110
|
export declare function fetchPinnedHook(name: string, version: string, apiUrl: string, apiKey: string): Promise<PinnedHookInstall>;
|
|
111
|
+
/**
|
|
112
|
+
* Pin an exact hook version from the BUNDLED registry (the on-box catalog).
|
|
113
|
+
* Powers `hooks install <name>@<version>` / `hooks update <name>@<version>`
|
|
114
|
+
* under the explicit local opt-in (HASNA_HOOKS_LOCAL=1) — the only route on
|
|
115
|
+
* which `resolveHooksTransport` returns `mode: "local"`; with nothing
|
|
116
|
+
* configured the CLI gate has already failed closed, and on the hosted route
|
|
117
|
+
* the remote registry answers the pin. The exact version named must be the
|
|
118
|
+
* bundled one, and the script stays at its bundled path — the pin (lock + DB
|
|
119
|
+
* record) is the trust anchor, exactly as local `hooks sync` pins the catalog.
|
|
120
|
+
* Carried from hasna/apps#1888 (its good half).
|
|
121
|
+
*
|
|
122
|
+
* A name or version the bundled registry does not carry is a DATA error with
|
|
123
|
+
* the available version named — the same shape as a remote pin miss.
|
|
124
|
+
*/
|
|
125
|
+
export declare function installPinnedFromBundled(name: string, version: string): Promise<PinnedHookInstall>;
|
|
110
126
|
export {};
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@hasna/hooks/sdk` — the hosted hooks registry client (package-surfaces
|
|
3
|
+
* rule: one package, four surfaces; this is the importable one).
|
|
4
|
+
*
|
|
5
|
+
* SELF-CONTAINED. The built bundle (`dist/sdk/index.js`, `bun build --target
|
|
6
|
+
* bun`) imports node builtins only: the `@hasna/contracts/client` credential
|
|
7
|
+
* seam is inlined at build time, and nothing here reaches `bun:sqlite` or the
|
|
8
|
+
* on-box store — the SDK has no local mode. `src/sdk/index.test.ts` pins both.
|
|
9
|
+
*
|
|
10
|
+
* FAIL CLOSED (hasna/apps#1720). `createHooksClient()` resolves the registry
|
|
11
|
+
* authority and credential through the ONE @hasna/contracts chain (env pair →
|
|
12
|
+
* Keychain item `hasna.credentials.hooks.api-key` → `~/.hasna/hooks/config/
|
|
13
|
+
* credentials`), as a strict pair, fresh per call. With nothing resolved it
|
|
14
|
+
* THROWS the `REMOTE_API_*` diagnostic naming the tiers and the opt-in; it
|
|
15
|
+
* never returns a client that answers from a local file. The explicit local
|
|
16
|
+
* opt-in (`HASNA_HOOKS_LOCAL=1`) is refused here by name: the SDK is a hosted
|
|
17
|
+
* client and the on-box store is the CLI's, opt-in only.
|
|
18
|
+
*/
|
|
19
|
+
import { hooksRegistryOrigin, type HooksRemoteAuthority, type HooksTransportOptions } from "../lib/transport.js";
|
|
20
|
+
import type { HooksCredentialOptions, HooksLocalOptInEnv } from "../lib/resolver-types.js";
|
|
21
|
+
export type { HooksRemoteAuthority, HooksCredentialOptions, HooksLocalOptInEnv };
|
|
22
|
+
export { hooksRegistryOrigin };
|
|
23
|
+
/** One row of `GET /api/v1/catalog` — the registry's latest version of a hook. */
|
|
24
|
+
export interface HooksRegistryCatalogEntry {
|
|
25
|
+
name: string;
|
|
26
|
+
version: string;
|
|
27
|
+
sha256: string;
|
|
28
|
+
events: string[];
|
|
29
|
+
description: string;
|
|
30
|
+
source: string;
|
|
31
|
+
versions: string[];
|
|
32
|
+
}
|
|
33
|
+
/** One pin of `GET /api/v1/lock` — the exact version the registry wants clients on. */
|
|
34
|
+
export interface HooksRegistryLockEntry {
|
|
35
|
+
version: string;
|
|
36
|
+
sha256: string;
|
|
37
|
+
source?: string;
|
|
38
|
+
versions?: string[];
|
|
39
|
+
}
|
|
40
|
+
export interface HooksRegistryLock {
|
|
41
|
+
hooks: Record<string, HooksRegistryLockEntry>;
|
|
42
|
+
}
|
|
43
|
+
/** `GET /api/v1/hooks/:name/:version` — a versioned artifact (manifest + script). */
|
|
44
|
+
export interface HooksRegistryArtifact {
|
|
45
|
+
manifest: {
|
|
46
|
+
name: string;
|
|
47
|
+
version: string;
|
|
48
|
+
description?: string;
|
|
49
|
+
events: string[];
|
|
50
|
+
script: string;
|
|
51
|
+
script_kind?: "inline" | "file";
|
|
52
|
+
args?: string[];
|
|
53
|
+
timeout_ms?: number;
|
|
54
|
+
};
|
|
55
|
+
script: string;
|
|
56
|
+
/** The registry's `x-hook-sha256` header for the served row, when present. */
|
|
57
|
+
sha256: string | null;
|
|
58
|
+
}
|
|
59
|
+
export interface HooksClientOptions {
|
|
60
|
+
/** Injectable environment (tests). Defaults to `process.env`. */
|
|
61
|
+
env?: HooksLocalOptInEnv;
|
|
62
|
+
/** Tier-1 credential inputs and the injectable `security` runner. */
|
|
63
|
+
credentials?: HooksCredentialOptions;
|
|
64
|
+
/** Injectable fetch (tests). Defaults to the global `fetch`. */
|
|
65
|
+
fetch?: typeof fetch;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Resolve the hosted authority the SDK will talk to. Throws — never returns a
|
|
69
|
+
* local fallback — when nothing resolves, and refuses the local opt-in by
|
|
70
|
+
* name: there is no SDK surface for the on-box store.
|
|
71
|
+
*/
|
|
72
|
+
export declare function resolveHooksSdkAuthority(env?: HooksLocalOptInEnv, options?: Omit<HooksTransportOptions, "notice">): HooksRemoteAuthority;
|
|
73
|
+
/**
|
|
74
|
+
* Hosted registry client. Holds the resolved credential privately and sends
|
|
75
|
+
* it only to the authority it was resolved together with (strict pair).
|
|
76
|
+
*/
|
|
77
|
+
export declare class HooksClient {
|
|
78
|
+
#private;
|
|
79
|
+
/** Registry origin WITHOUT `/v1` — the registry routes hang off `<origin>/api/v1`. */
|
|
80
|
+
readonly origin: string;
|
|
81
|
+
/** The resolver's `<origin>/v1` authority, for diagnostics. */
|
|
82
|
+
readonly v1BaseUrl: string;
|
|
83
|
+
/** WHERE the credential came from (env NAME, Keychain reference, file PATH). Never a value. */
|
|
84
|
+
readonly apiKeySource: string | null;
|
|
85
|
+
/** WHERE the authority came from. Never a value. */
|
|
86
|
+
readonly apiUrlSource: string | null;
|
|
87
|
+
constructor(authority: HooksRemoteAuthority, options?: {
|
|
88
|
+
fetch?: typeof fetch;
|
|
89
|
+
});
|
|
90
|
+
/** Build the request URL for a registry route (exposed so callers can log WHERE without a key). */
|
|
91
|
+
urlFor(path: string): string;
|
|
92
|
+
health(): Promise<{
|
|
93
|
+
status: string;
|
|
94
|
+
name: string;
|
|
95
|
+
}>;
|
|
96
|
+
catalog(): Promise<HooksRegistryCatalogEntry[]>;
|
|
97
|
+
lock(): Promise<HooksRegistryLock>;
|
|
98
|
+
artifact(name: string, version: string): Promise<HooksRegistryArtifact>;
|
|
99
|
+
private request;
|
|
100
|
+
private getJson;
|
|
101
|
+
}
|
|
102
|
+
/** Resolve the hosted authority (fail closed) and return a client bound to it. */
|
|
103
|
+
export declare function createHooksClient(options?: HooksClientOptions): HooksClient;
|