@hasna/hooks 0.7.10 → 0.9.0
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 +32 -6
- package/bin/index.js +2640 -1820
- package/bin/serve.js +742 -551
- package/dist/config.d.ts +25 -19
- package/dist/index.d.ts +3 -2
- package/dist/index.js +1251 -717
- package/dist/lib/app-home.d.ts +9 -0
- package/dist/lib/installer.d.ts +40 -10
- package/dist/lib/local-opt-in.d.ts +80 -0
- package/dist/lib/profiles.d.ts +10 -0
- package/dist/lib/registration.d.ts +75 -0
- package/dist/lib/registry.d.ts +14 -0
- package/dist/lib/resolver-types.d.ts +45 -0
- package/dist/lib/sync.d.ts +13 -8
- package/dist/lib/transport.d.ts +87 -0
- package/dist/openapi.d.ts +1 -1
- package/dist/storage.js +54 -63
- package/hooks/hook-affected-tests/package.json +1 -1
- package/hooks/hook-agent-rules-version-check/README.md +1 -1
- package/hooks/hook-agent-rules-version-check/package.json +1 -1
- package/hooks/hook-agentmessages/package.json +1 -1
- package/hooks/hook-announce-start/package.json +1 -1
- package/hooks/hook-announce-stop/package.json +1 -1
- package/hooks/hook-autoformat/package.json +1 -1
- package/hooks/hook-branchprotect/package.json +1 -1
- package/hooks/hook-checkbugs/package.json +1 -1
- package/hooks/hook-checkdocs/package.json +1 -1
- package/hooks/hook-checkfiles/package.json +1 -1
- package/hooks/hook-checklint/package.json +1 -1
- package/hooks/hook-checkpoint/package.json +1 -1
- package/hooks/hook-checksecurity/package.json +1 -1
- package/hooks/hook-checktasks/package.json +1 -1
- package/hooks/hook-checktests/package.json +1 -1
- package/hooks/hook-conflict-detect/package.json +1 -1
- package/hooks/hook-contextrefresh/package.json +1 -1
- package/hooks/hook-desktopnotify/package.json +1 -1
- package/hooks/hook-dm-inject/package.json +1 -1
- package/hooks/hook-envsetup/package.json +1 -1
- package/hooks/hook-failure-to-task/package.json +1 -1
- package/hooks/hook-filelock/package.json +1 -1
- package/hooks/hook-fleet-blockers-gate/package.json +1 -1
- package/hooks/hook-fleet-catchup/package.json +1 -1
- package/hooks/hook-gitguard/package.json +1 -1
- package/hooks/hook-packageage/package.json +1 -1
- package/hooks/hook-permissionguard/package.json +1 -1
- package/hooks/hook-phonenotify/package.json +1 -1
- package/hooks/hook-precompact/package.json +1 -1
- package/hooks/hook-protectfiles/package.json +1 -1
- package/hooks/hook-stylescheck/package.json +1 -1
- package/hooks/hook-trash-guard/README.md +132 -0
- package/hooks/hook-trash-guard/package.json +12 -0
- package/hooks/hook-trash-guard/src/hook.ts +1114 -0
- package/hooks/hook-typecheck-gate/package.json +1 -1
- package/package.json +7 -10
- package/scripts/ensure-profiles-dir.mjs +52 -1
- package/hooks/codewith-native-common.test.ts +0 -1935
- package/hooks/hook-affected-tests/tsconfig.json +0 -25
- package/hooks/hook-agent-rules-version-check/src/hook.test.ts +0 -104
- package/hooks/hook-agent-rules-version-check/tsconfig.json +0 -25
- package/hooks/hook-announce-start/tsconfig.json +0 -25
- package/hooks/hook-announce-stop/tsconfig.json +0 -25
- package/hooks/hook-autoformat/tsconfig.json +0 -25
- package/hooks/hook-branchprotect/tsconfig.json +0 -25
- package/hooks/hook-checkbugs/tsconfig.json +0 -15
- package/hooks/hook-checkdocs/tsconfig.json +0 -15
- package/hooks/hook-checkfiles/tsconfig.json +0 -15
- package/hooks/hook-checklint/tsconfig.json +0 -15
- package/hooks/hook-checkpoint/tsconfig.json +0 -25
- package/hooks/hook-checksecurity/tsconfig.json +0 -15
- package/hooks/hook-checktasks/tsconfig.json +0 -20
- package/hooks/hook-checktests/tsconfig.json +0 -15
- package/hooks/hook-conflict-detect/tsconfig.json +0 -25
- package/hooks/hook-contextrefresh/tsconfig.json +0 -25
- package/hooks/hook-desktopnotify/tsconfig.json +0 -25
- package/hooks/hook-dm-inject/tsconfig.json +0 -25
- package/hooks/hook-envsetup/tsconfig.json +0 -25
- package/hooks/hook-failure-to-task/tsconfig.json +0 -25
- package/hooks/hook-filelock/tsconfig.json +0 -25
- package/hooks/hook-fleet-blockers-gate/src/hook.test.ts +0 -302
- package/hooks/hook-fleet-blockers-gate/tsconfig.json +0 -25
- package/hooks/hook-fleet-catchup/src/hook.test.ts +0 -156
- package/hooks/hook-fleet-catchup/tsconfig.json +0 -25
- package/hooks/hook-gitguard/tsconfig.json +0 -25
- package/hooks/hook-knowledge-context/src/hook.test.ts +0 -379
- package/hooks/hook-packageage/tsconfig.json +0 -25
- package/hooks/hook-permissionguard/tsconfig.json +0 -25
- package/hooks/hook-phonenotify/tsconfig.json +0 -25
- package/hooks/hook-precompact/tsconfig.json +0 -25
- package/hooks/hook-protectfiles/tsconfig.json +0 -25
- package/hooks/hook-scanoutput/src/hook.test.ts +0 -217
- package/hooks/hook-spiral-detector/src/hook.test.ts +0 -72
- package/hooks/hook-stylescheck/tsconfig.json +0 -25
- package/hooks/hook-typecheck-gate/tsconfig.json +0 -25
- package/hooks/hook-workspace-repos-guard/src/hook.test.ts +0 -466
- package/hooks/hook-workspace-repos-guard/tsconfig.json +0 -21
- package/hooks/mention-context/src/hook.test.ts +0 -68
package/dist/lib/app-home.d.ts
CHANGED
|
@@ -11,6 +11,15 @@
|
|
|
11
11
|
* physically migrated there, so a live store at the legacy home never becomes
|
|
12
12
|
* invisible on upgrade.
|
|
13
13
|
*/
|
|
14
|
+
export type PathKind = "config" | "data" | "state" | "cache";
|
|
15
|
+
export interface PathsResolverOptions {
|
|
16
|
+
app: string;
|
|
17
|
+
internal?: boolean;
|
|
18
|
+
platform?: string;
|
|
19
|
+
home?: string;
|
|
20
|
+
env?: Record<string, string | undefined>;
|
|
21
|
+
}
|
|
22
|
+
export declare function dataDir(options: PathsResolverOptions): string;
|
|
14
23
|
/** Resolve the user's home directory: $HOME, then $USERPROFILE, then the OS user database. */
|
|
15
24
|
export declare function getHomeDir(env?: NodeJS.ProcessEnv): string;
|
|
16
25
|
/**
|
package/dist/lib/installer.d.ts
CHANGED
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
* Hooks run directly from the globally installed @hasna/hooks package.
|
|
10
10
|
* No files are copied. The settings entry points to `hooks run <name>`.
|
|
11
11
|
*/
|
|
12
|
-
import { type HookEvent } from "./registry.js";
|
|
12
|
+
import { type HookEvent, type HookMeta } from "./registry.js";
|
|
13
|
+
import { type StaleRegistration } from "./registration.js";
|
|
13
14
|
export type Scope = "global" | "project";
|
|
14
15
|
export type Target = "claude" | "gemini" | "codewith" | "all";
|
|
15
16
|
type SingleTarget = Exclude<Target, "all">;
|
|
@@ -47,6 +48,18 @@ export declare function hookExists(name: string): boolean;
|
|
|
47
48
|
/** Whether a hook's event can be registered for the given target */
|
|
48
49
|
export declare function isEventSupported(internalEvent: HookEvent, target: SingleTarget): boolean;
|
|
49
50
|
export declare function buildCodewithTomlFragment(name: string, profile?: string): string;
|
|
51
|
+
/**
|
|
52
|
+
* The one conflict class that BLOCKS an install: two PreToolUse hooks on
|
|
53
|
+
* overlapping matchers that both rewrite the tool input
|
|
54
|
+
* (`hookSpecificOutput.updatedInput`). The harness keeps ONE rewrite per tool
|
|
55
|
+
* call — last writer wins — so whichever guard loses is silently disarmed
|
|
56
|
+
* with no error anywhere. `trash-guard` is the first such hook.
|
|
57
|
+
*
|
|
58
|
+
* Every other conflict stays advisory: it still installs, with the warning.
|
|
59
|
+
*/
|
|
60
|
+
export declare function detectRewriteConflict(name: string, scope: Scope, target: SingleTarget,
|
|
61
|
+
/** Injected for tests: the rewrite claim is a registry concern, the overlap is not. */
|
|
62
|
+
lookup?: (hookName: string) => HookMeta | undefined): string | undefined;
|
|
50
63
|
export declare function installHook(name: string, options?: InstallOptions): InstallResult;
|
|
51
64
|
export declare function installHooks(names: string[], options?: InstallOptions): InstallResult[];
|
|
52
65
|
export declare function getRegisteredHooksForTarget(scope?: Scope, target?: SingleTarget): string[];
|
|
@@ -54,6 +67,32 @@ export declare function getRegisteredHooks(scope?: Scope): string[];
|
|
|
54
67
|
/** @deprecated Use getRegisteredHooks instead */
|
|
55
68
|
export declare const getInstalledHooks: typeof getRegisteredHooks;
|
|
56
69
|
export declare function removeHook(name: string, scope?: Scope, target?: Target): boolean;
|
|
70
|
+
/**
|
|
71
|
+
* Every settings registration for the scope whose hook name does not resolve.
|
|
72
|
+
*
|
|
73
|
+
* A stale registration makes the agent spawn `hooks run <name>` on every event
|
|
74
|
+
* it is wired to, and each spawn fails — the failure is invisible to `hooks
|
|
75
|
+
* install`/`hooks remove` because nothing re-checks names already written.
|
|
76
|
+
*/
|
|
77
|
+
export declare function scanStaleRegistrations(scope?: Scope): StaleRegistration[];
|
|
78
|
+
export interface PruneStaleResult {
|
|
79
|
+
/** Settings file edited. */
|
|
80
|
+
file: string;
|
|
81
|
+
/** The registrations removed from it. */
|
|
82
|
+
removed: StaleRegistration[];
|
|
83
|
+
/** Sibling backup of the pre-edit bytes (`<settings>.bak`). */
|
|
84
|
+
backupPath: string;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Remove every stale registration the scope carries, and nothing else.
|
|
88
|
+
*
|
|
89
|
+
* Edits only the entries whose own command is stale: sibling hooks in the same
|
|
90
|
+
* entry, unrelated event keys, matchers and every non-hook settings key are
|
|
91
|
+
* preserved, the file stays valid JSON, and a `.bak` sibling is written before
|
|
92
|
+
* the edit. Idempotent — a second call finds nothing stale and writes nothing.
|
|
93
|
+
* A registration whose hook resolves is never touched.
|
|
94
|
+
*/
|
|
95
|
+
export declare function pruneStaleRegistrations(scope?: Scope): PruneStaleResult[];
|
|
57
96
|
export interface UninstallResult {
|
|
58
97
|
name: string;
|
|
59
98
|
removed: boolean;
|
|
@@ -81,14 +120,5 @@ export declare function removeCodewithHookEntry(configText: string, name: string
|
|
|
81
120
|
text: string;
|
|
82
121
|
removed: boolean;
|
|
83
122
|
};
|
|
84
|
-
/**
|
|
85
|
-
* Full uninstall — the settings registration, the store directory (custom
|
|
86
|
-
* hooks), the lock pin and the DB record are all removed. Bundled hooks keep
|
|
87
|
-
* their package files (they belong to the package, not the store).
|
|
88
|
-
*
|
|
89
|
-
* Resolves custom and registry-synced hooks, which live in the custom store
|
|
90
|
-
* dir, as well as bundled ones (QA-1 BUG-A / QA-4: remove was bundled-only
|
|
91
|
-
* and never cleaned the store/lock/DB).
|
|
92
|
-
*/
|
|
93
123
|
export declare function uninstallHook(name: string, scope?: Scope, target?: Target): UninstallResult;
|
|
94
124
|
export {};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import type { HooksCredentialOptions, HooksLocalOptInEnv } from "./resolver-types.js";
|
|
2
|
+
/** The deliberate unhosted opt-in, canonical name first. */
|
|
3
|
+
export declare const HOOKS_LOCAL_OPT_IN_ENV_KEYS: readonly ["HASNA_HOOKS_LOCAL", "HOOKS_LOCAL"];
|
|
4
|
+
/** True when the operator deliberately asked for the unhosted local store. */
|
|
5
|
+
export declare function isHooksLocalOptIn(env?: HooksLocalOptInEnv): boolean;
|
|
6
|
+
/** Every env name that can configure a hooks authority or credential, resolver-derived. */
|
|
7
|
+
export declare function hooksAuthorityEnvKeys(): string[];
|
|
8
|
+
/**
|
|
9
|
+
* Does the ENVIRONMENT itself configure a hooks authority or credential?
|
|
10
|
+
*
|
|
11
|
+
* Deliberately narrower than "does a credential resolve": answering it must not
|
|
12
|
+
* touch the Keychain or the filesystem, because doing so would defeat the
|
|
13
|
+
* isolation the opt-in short-circuit exists to provide. It reads the env
|
|
14
|
+
* dictionary and nothing else.
|
|
15
|
+
*
|
|
16
|
+
* A DECLARED-BUT-BLANK variable counts as absent HERE — a blank has always been
|
|
17
|
+
* this package's spelling for "not configured", and helpers in the wild blank
|
|
18
|
+
* rather than delete. It is NOT absent once we do go hosted: the resolver
|
|
19
|
+
* refuses a blank loudly rather than falling through to another identity, which
|
|
20
|
+
* is the behaviour that matters at that point.
|
|
21
|
+
*/
|
|
22
|
+
export declare function hasHooksEnvAuthorityIntent(env?: HooksLocalOptInEnv): boolean;
|
|
23
|
+
/** True when this environment should be served by the on-box bundled store. */
|
|
24
|
+
export declare function selectsHooksLocalStore(env?: HooksLocalOptInEnv): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* The environment as the resolver should see it: every authority/credential
|
|
27
|
+
* variable that is DECLARED BUT BLANK removed.
|
|
28
|
+
*
|
|
29
|
+
* A blank has always been this package's spelling for "not configured".
|
|
30
|
+
* @hasna/contracts takes the opposite and, for its purposes, correct view: a
|
|
31
|
+
* declared-but-blank credential is a misconfiguration it refuses loudly rather
|
|
32
|
+
* than resolving around, because a blank that fell through would authenticate
|
|
33
|
+
* as a different principal than the operator named.
|
|
34
|
+
*
|
|
35
|
+
* Both are right at their own layer, and the mismatch is not hypothetical: an
|
|
36
|
+
* environment carrying a real `HASNA_HOOKS_API_KEY` alongside a blank legacy
|
|
37
|
+
* alias — the exact shape a scrubbed-then-overridden fixture produces — is a
|
|
38
|
+
* complete, unambiguous configuration that would otherwise be refused for the
|
|
39
|
+
* alias nobody set. Normalising here keeps "blank means unset" true at the
|
|
40
|
+
* hooks seam while leaving the resolver's stricter rule intact for everything
|
|
41
|
+
* it does receive: a value that is present is still policed, and two aliases
|
|
42
|
+
* that actually disagree still refuse.
|
|
43
|
+
*/
|
|
44
|
+
export declare function hooksResolverEnv<T extends HooksLocalOptInEnv>(env: T): T;
|
|
45
|
+
/** The env object and credential options a hooks surface hands @hasna/contracts. */
|
|
46
|
+
export interface HooksResolverInputs<T extends HooksLocalOptInEnv> {
|
|
47
|
+
/** The environment with every declared-but-blank authority variable removed. */
|
|
48
|
+
env: T;
|
|
49
|
+
/** The chain options, with the Keychain tier's ambient gate already decided. */
|
|
50
|
+
credentials: HooksCredentialOptions;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Build the resolver's inputs: the normalised environment AND the credential
|
|
54
|
+
* options that keep the machine's Keychain tier reachable across it.
|
|
55
|
+
*
|
|
56
|
+
* WHY THIS IS NOT JUST {@link hooksResolverEnv}. Blanking a variable and
|
|
57
|
+
* deleting it are not the same operation to @hasna/contracts, because dropping
|
|
58
|
+
* a key forces us to hand the resolver a COPY, and the resolver gates its
|
|
59
|
+
* ambient tiers on OBJECT IDENTITY (`env === process.env`, or the registry
|
|
60
|
+
* symbol its own snapshot carries). A copy is, by that test, a caller-built
|
|
61
|
+
* world — the hermetic seam — so the Keychain is outside it and tier 3 turns
|
|
62
|
+
* itself off. Silently: there is no error, no warning and no diagnostic.
|
|
63
|
+
*
|
|
64
|
+
* The consequence is the one failure this whole ruling exists to prevent. On a
|
|
65
|
+
* station whose Keychain holds `hasna.credentials.hooks.api-key`, ONE
|
|
66
|
+
* declared-but-blank authority variable dropped the run from the Keychain
|
|
67
|
+
* identity to whatever came next: to `~/.hasna/hooks/config/credentials`, a
|
|
68
|
+
* DIFFERENT principal, with no notice; or, with nothing on disk, to a bare
|
|
69
|
+
* REMOTE_API_CONFIG_MISSING on a station that is in fact configured. A
|
|
70
|
+
* deliberate tier must never fall through to another identity, so the gate is
|
|
71
|
+
* decided HERE, on the original env, and carried across the copy as the
|
|
72
|
+
* documented `keychain.enabled` control rather than being left to an identity
|
|
73
|
+
* test the copy cannot pass.
|
|
74
|
+
*
|
|
75
|
+
* An explicit `enabled` from the caller still wins, and an injected `run`
|
|
76
|
+
* (which @hasna/contracts already treats as "enabled") is left alone, so the
|
|
77
|
+
* hermetic seam tests rely on is untouched. When there is no blank to remove
|
|
78
|
+
* the inputs pass through by identity, exactly as before.
|
|
79
|
+
*/
|
|
80
|
+
export declare function hooksResolverInputs<T extends HooksLocalOptInEnv>(env: T, credentials?: HooksCredentialOptions): HooksResolverInputs<T>;
|
package/dist/lib/profiles.d.ts
CHANGED
|
@@ -20,6 +20,16 @@ export interface CreateProfileInput {
|
|
|
20
20
|
agent_type: "claude" | "gemini" | "custom";
|
|
21
21
|
name?: string;
|
|
22
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* The profiles directory under the effective data root.
|
|
25
|
+
*
|
|
26
|
+
* Resolved on every call, never snapshotted at module load: the effective
|
|
27
|
+
* data root is env-driven (HASNA_HOOKS_DATA_DIR / HASNA_HOOKS_HOME / the XDG
|
|
28
|
+
* adoption in app-home), and bun test runs test files in one process with a
|
|
29
|
+
* SHARED process.env — a module-load snapshot froze the dir to whatever the
|
|
30
|
+
* env held at import time, so a concurrent file pinning a data-root override
|
|
31
|
+
* silently moved every profile operation of this module with it.
|
|
32
|
+
*/
|
|
23
33
|
export declare function getProfilesDir(): string;
|
|
24
34
|
export declare function createProfile(input: CreateProfileInput): AgentProfile;
|
|
25
35
|
export declare function getProfile(id: string): AgentProfile | null;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Settings registration checks shared by the CLI doctor and the MCP
|
|
3
|
+
* hooks_doctor.
|
|
4
|
+
*
|
|
5
|
+
* Event and matcher are separate settings fields — settings.hooks[event] is
|
|
6
|
+
* an array of { matcher?, hooks: [...] } entries — so a composite event such
|
|
7
|
+
* as 'PreToolUse:Bash' must be split before lookup, never used as a key.
|
|
8
|
+
*/
|
|
9
|
+
/** A settings registration whose hook name cannot resolve. */
|
|
10
|
+
export interface StaleRegistration {
|
|
11
|
+
/** Settings file the registration lives in. */
|
|
12
|
+
file: string;
|
|
13
|
+
/** Settings event key holding the entry (PreToolUse, …). */
|
|
14
|
+
event: string;
|
|
15
|
+
/** The registered hook name that does not resolve. */
|
|
16
|
+
hook: string;
|
|
17
|
+
/** The raw command string from the settings entry. */
|
|
18
|
+
command: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Find settings registrations whose hook does not resolve.
|
|
22
|
+
*
|
|
23
|
+
* A registration is a `hooks run <name>` (or legacy `hook-<name>`) command;
|
|
24
|
+
* it is stale when `resolveHook(name)` finds no bundled, custom or stored
|
|
25
|
+
* hook — exactly the lookup `hooks run` performs, so a stale registration
|
|
26
|
+
* fails on every tool call it is wired to. Direct-path wiring outside the
|
|
27
|
+
* installer's own command forms is reported by `countSettingsWiring`, never
|
|
28
|
+
* treated as a hook registration.
|
|
29
|
+
*/
|
|
30
|
+
export declare function findStaleRegistrations(settings: Record<string, unknown>, file: string, resolves?: (name: string) => boolean): StaleRegistration[];
|
|
31
|
+
/**
|
|
32
|
+
* Whether two tool matchers can select the same tool call. Deliberately loose
|
|
33
|
+
* (identical, or one a substring of the other) — a false positive costs one
|
|
34
|
+
* advisory warning, a false negative costs a silently disarmed guard.
|
|
35
|
+
*/
|
|
36
|
+
export declare function matchersOverlap(a: string, b: string): boolean;
|
|
37
|
+
/** The metadata slice `findRewriteOverlaps` needs from a hook. */
|
|
38
|
+
export interface RewriteHookInfo {
|
|
39
|
+
matcher?: string;
|
|
40
|
+
event?: string;
|
|
41
|
+
events?: string[];
|
|
42
|
+
rewritesInput?: boolean;
|
|
43
|
+
}
|
|
44
|
+
/** Two installed hooks that both rewrite the tool input on the same tool. */
|
|
45
|
+
export interface RewriteOverlap {
|
|
46
|
+
hooks: [string, string];
|
|
47
|
+
event: string;
|
|
48
|
+
matchers: [string, string];
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Installed hooks that both rewrite the tool input
|
|
52
|
+
* (`hookSpecificOutput.updatedInput`) on an overlapping PreToolUse matcher.
|
|
53
|
+
*
|
|
54
|
+
* This is a real defect, not a style nit: the harness applies ONE rewrite per
|
|
55
|
+
* tool call, so one of the two guards is silently disarmed. The installer
|
|
56
|
+
* refuses the pairing up front; doctor reports it for settings files it did
|
|
57
|
+
* not write (hand-edited, or written before the rule existed).
|
|
58
|
+
*/
|
|
59
|
+
export declare function findRewriteOverlaps(names: string[], lookup: (name: string) => RewriteHookInfo | undefined): RewriteOverlap[];
|
|
60
|
+
/**
|
|
61
|
+
* Whether a hook is registered in a settings file.
|
|
62
|
+
*
|
|
63
|
+
* An entry matches when it carries a `hooks run <name>` command and, when the
|
|
64
|
+
* hook declares a matcher, the entry's matcher is absent (fires on all tools)
|
|
65
|
+
* or consistent with the hook's matcher (equal, or one regex matches the
|
|
66
|
+
* other).
|
|
67
|
+
*/
|
|
68
|
+
/**
|
|
69
|
+
* Count every raw hook entry wired in a settings file — including
|
|
70
|
+
* direct-path entries that never went through the CLI (`command` values that
|
|
71
|
+
* are not `hooks run <name>`). Doctor reports this count alongside the
|
|
72
|
+
* registered count so its "healthy" verdict names its bounds (P2-16b).
|
|
73
|
+
*/
|
|
74
|
+
export declare function countSettingsWiring(settings: Record<string, unknown>): number;
|
|
75
|
+
export declare function hookRegisteredInSettings(settings: Record<string, unknown>, name: string, eventSpec: string, hookMatcher: string): boolean;
|
package/dist/lib/registry.d.ts
CHANGED
|
@@ -13,6 +13,20 @@ export interface HookMeta {
|
|
|
13
13
|
events?: HookEvent[];
|
|
14
14
|
matcher: string;
|
|
15
15
|
tags: string[];
|
|
16
|
+
/**
|
|
17
|
+
* This hook rewrites the tool input (`hookSpecificOutput.updatedInput`).
|
|
18
|
+
* The agent harness keeps ONE rewrite per tool call — last writer wins — so
|
|
19
|
+
* two input-rewriting hooks on overlapping PreToolUse matchers silently
|
|
20
|
+
* disarm each other. Install refuses that pairing, and `hooks doctor`
|
|
21
|
+
* reports it.
|
|
22
|
+
*/
|
|
23
|
+
rewritesInput?: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Timeout (seconds) written into the agent's settings entry for this hook.
|
|
26
|
+
* The harness default is 600s, and a TIMED-OUT HOOK DOES NOT BLOCK: a guard
|
|
27
|
+
* that needs a verdict on stdout must declare a timeout it can meet.
|
|
28
|
+
*/
|
|
29
|
+
timeoutSeconds?: number;
|
|
16
30
|
}
|
|
17
31
|
export declare const CATEGORIES: readonly ["Git Safety", "Code Quality", "Security", "Notifications", "Context Management", "Workflow Automation", "Environment", "Permissions", "Observability", "Agent Teams"];
|
|
18
32
|
export type Category = (typeof CATEGORIES)[number];
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The @hasna/contracts client types that @hasna/hooks PUBLISHES or hands back
|
|
3
|
+
* across its public seam, spelled locally.
|
|
4
|
+
*
|
|
5
|
+
* WHY THIS FILE EXISTS. `@hasna/contracts` is a BUILD-TIME dependency of this
|
|
6
|
+
* package (pinned 1.0.2, inlined by `bun build --target bun`), so the emitted
|
|
7
|
+
* `dist/**/*.d.ts` must never `import ... from "@hasna/contracts/client"` —
|
|
8
|
+
* a published declaration that references a package consumers do not have is
|
|
9
|
+
* a broken install (hasna/apps#1782). Every public signature therefore uses
|
|
10
|
+
* these local spellings, which are structurally identical to the resolver's
|
|
11
|
+
* own types (`CredentialChainOptions` / `KeychainCommandResult`). The
|
|
12
|
+
* `credential chain shape` test in `transport.test.ts` pins the local
|
|
13
|
+
* spellings against the real @hasna/contracts types so they cannot drift.
|
|
14
|
+
*/
|
|
15
|
+
export type HooksLocalOptInEnv = Record<string, string | undefined>;
|
|
16
|
+
/** What an injected `security` runner returns: an exit status plus output. */
|
|
17
|
+
export interface HooksKeychainCommandResult {
|
|
18
|
+
/** Exit status; null when the tool could not be started or was killed. */
|
|
19
|
+
status: number | null;
|
|
20
|
+
stdout: string;
|
|
21
|
+
stderr: string;
|
|
22
|
+
}
|
|
23
|
+
/** Tier 3 (Keychain) controls — structurally `KeychainTierOptions`. */
|
|
24
|
+
export interface HooksKeychainTierOptions {
|
|
25
|
+
/** Whether the Keychain is consulted for a caller-built env object. */
|
|
26
|
+
enabled?: boolean;
|
|
27
|
+
/** Defaults to `process.platform`; the tier exists only on `"darwin"`. */
|
|
28
|
+
platform?: string;
|
|
29
|
+
/** The machine's host name when `HASNA_STATION` is unset. */
|
|
30
|
+
hostname?: () => string;
|
|
31
|
+
/** The `security` runner. Defaults to spawning `/usr/bin/security`. */
|
|
32
|
+
run?: (argv: readonly string[]) => HooksKeychainCommandResult;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Tier-1 credential inputs and Keychain-tier controls — structurally
|
|
36
|
+
* `CredentialChainOptions` from @hasna/contracts/client, spelled locally.
|
|
37
|
+
*/
|
|
38
|
+
export interface HooksCredentialOptions {
|
|
39
|
+
/** Tier 1: an explicit key, e.g. from `--api-key`. */
|
|
40
|
+
apiKey?: string;
|
|
41
|
+
/** Tier 1: an explicit profile name. Beats `HASNA_PROFILE`. */
|
|
42
|
+
profile?: string;
|
|
43
|
+
/** Tier 3: Keychain controls — a fake `security` runner in tests, an opt-out on CI. */
|
|
44
|
+
keychain?: HooksKeychainTierOptions;
|
|
45
|
+
}
|
package/dist/lib/sync.d.ts
CHANGED
|
@@ -6,7 +6,16 @@
|
|
|
6
6
|
* failure mid-sync leaves the local store untouched. Local-only hooks are
|
|
7
7
|
* never deleted by a remote sync.
|
|
8
8
|
*/
|
|
9
|
+
import type { HooksCredentialOptions } from "./resolver-types.js";
|
|
9
10
|
import { parseManifest } from "./manifest.js";
|
|
11
|
+
type Env = Record<string, string | undefined>;
|
|
12
|
+
export interface HooksSyncOptions {
|
|
13
|
+
dryRun?: boolean;
|
|
14
|
+
/** Injectable environment (tests). Defaults to `process.env`. */
|
|
15
|
+
env?: Env;
|
|
16
|
+
/** Injectable credential-chain inputs (tests: fake `security` runner). */
|
|
17
|
+
credentials?: HooksCredentialOptions;
|
|
18
|
+
}
|
|
10
19
|
export interface SyncDiff {
|
|
11
20
|
added: string[];
|
|
12
21
|
updated: string[];
|
|
@@ -39,12 +48,8 @@ interface RemoteLock {
|
|
|
39
48
|
versions?: string[];
|
|
40
49
|
}>;
|
|
41
50
|
}
|
|
42
|
-
export declare function planSync(options?:
|
|
43
|
-
|
|
44
|
-
}): Promise<SyncPlan>;
|
|
45
|
-
export declare function syncHooks(options?: {
|
|
46
|
-
dryRun?: boolean;
|
|
47
|
-
}): Promise<SyncPlan>;
|
|
51
|
+
export declare function planSync(options?: HooksSyncOptions): Promise<SyncPlan>;
|
|
52
|
+
export declare function syncHooks(options?: HooksSyncOptions): Promise<SyncPlan>;
|
|
48
53
|
/**
|
|
49
54
|
* One fully-validated artifact ready to be committed. Nothing has touched
|
|
50
55
|
* the store at this point: every fetch, sha check and manifest parse has
|
|
@@ -64,7 +69,7 @@ export interface StagedSyncArtifact {
|
|
|
64
69
|
* written. A failure here (network, sha mismatch, malformed manifest,
|
|
65
70
|
* containment violation) throws with the store untouched.
|
|
66
71
|
*/
|
|
67
|
-
export declare function stageSyncArtifacts(apiUrl: string, names: string[], remoteLock: RemoteLock): Promise<StagedSyncArtifact[]>;
|
|
72
|
+
export declare function stageSyncArtifacts(apiUrl: string, apiKey: string, names: string[], remoteLock: RemoteLock): Promise<StagedSyncArtifact[]>;
|
|
68
73
|
/**
|
|
69
74
|
* P1-9 commit phase, ordered so a mid-commit failure cannot leave a partial
|
|
70
75
|
* store that reads as trusted:
|
|
@@ -101,5 +106,5 @@ export interface PinnedHookInstall {
|
|
|
101
106
|
* the user is fetched from the versioned registry — older-than-latest pins
|
|
102
107
|
* are first-class, never rejected as "not the latest".
|
|
103
108
|
*/
|
|
104
|
-
export declare function fetchPinnedHook(name: string, version: string, apiUrl: string): Promise<PinnedHookInstall>;
|
|
109
|
+
export declare function fetchPinnedHook(name: string, version: string, apiUrl: string, apiKey: string): Promise<PinnedHookInstall>;
|
|
105
110
|
export {};
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import type { HooksCredentialOptions, HooksLocalOptInEnv } from "./resolver-types.js";
|
|
2
|
+
/** The unhosted mode: bundled registry + local SQLite store. Never a default. */
|
|
3
|
+
export type HooksTransportMode = "remote" | "local";
|
|
4
|
+
/** The resolved remote-registry authority pair. Never carries a value besides `apiKey`. */
|
|
5
|
+
export interface HooksRemoteAuthority {
|
|
6
|
+
/**
|
|
7
|
+
* Registry origin WITHOUT the `/v1` suffix the resolver appends — the sync
|
|
8
|
+
* client composes `/api/v1/...` routes on top of it.
|
|
9
|
+
*/
|
|
10
|
+
origin: string;
|
|
11
|
+
/** The credential, resolved together with the authority it will be sent to. */
|
|
12
|
+
apiKey: string;
|
|
13
|
+
/** WHERE the authority came from: an env key NAME, a Keychain item reference, a file PATH, or "default". */
|
|
14
|
+
apiUrlSource: string | null;
|
|
15
|
+
/** WHERE the credential came from: an env key NAME, a Keychain item reference, or a file PATH. Never a value. */
|
|
16
|
+
apiKeySource: string | null;
|
|
17
|
+
/** Which tier of the chain supplied the credential. */
|
|
18
|
+
apiKeyTier: string | null;
|
|
19
|
+
/** The resolver's `<origin>/v1` base, for diagnostics. */
|
|
20
|
+
v1BaseUrl: string;
|
|
21
|
+
/** Human-readable warning, or null. Never contains secret values. */
|
|
22
|
+
warning: string | null;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* The transport decision every hosted surface makes: remote (resolver-backed)
|
|
26
|
+
* or local (explicit opt-in, resolver never consulted).
|
|
27
|
+
*
|
|
28
|
+
* Local mode returns `authority: null` and carries no key. Remote mode always
|
|
29
|
+
* carries a fully resolved pair — the seam throws before returning a
|
|
30
|
+
* half-configured one.
|
|
31
|
+
*/
|
|
32
|
+
export interface HooksTransportResolution {
|
|
33
|
+
mode: HooksTransportMode;
|
|
34
|
+
/** `"local-opt-in"` for the deliberate unhosted store, else `"<api key source>+<api url source>"`. */
|
|
35
|
+
source: string;
|
|
36
|
+
/** The resolved remote pair; null in local mode. */
|
|
37
|
+
authority: HooksRemoteAuthority | null;
|
|
38
|
+
}
|
|
39
|
+
/** Where the one-line local-mode notice goes. Defaults to `process.stderr`. */
|
|
40
|
+
export type HooksTransportNotice = (line: string) => void;
|
|
41
|
+
/** Reset the once-per-process local-mode notice. Test seam only. */
|
|
42
|
+
export declare function __resetHooksLocalNotice(): void;
|
|
43
|
+
/**
|
|
44
|
+
* Announce the unhosted mode on stderr, once per process. Surfaces that never
|
|
45
|
+
* resolve the transport (the CLI gate opening through the opt-in) still have
|
|
46
|
+
* to SAY the run is local — the "local on stderr" doctrine (2026-09-04).
|
|
47
|
+
*/
|
|
48
|
+
export declare function announceHooksLocalMode(reason?: string, notice?: HooksTransportNotice): void;
|
|
49
|
+
/** Strip the `/v1` suffix the resolver normalised onto the authority. */
|
|
50
|
+
export declare function hooksRegistryOrigin(v1BaseUrl: string): string;
|
|
51
|
+
/**
|
|
52
|
+
* Re-throw a `@hasna/contracts` resolution failure as hooks' own fail-closed
|
|
53
|
+
* diagnostic, preserving the resolver's message (which names every tier it
|
|
54
|
+
* consulted) behind the stable `REMOTE_API_*` code callers match on. Nothing
|
|
55
|
+
* here ever returns a client or a local store: every arm throws.
|
|
56
|
+
*/
|
|
57
|
+
export declare function rethrowHooksAuthorityFailure(error: unknown): never;
|
|
58
|
+
/** Tier-1 credential inputs and Keychain-tier controls, forwarded verbatim. */
|
|
59
|
+
export type { HooksCredentialOptions } from "./resolver-types.js";
|
|
60
|
+
export interface HooksTransportOptions {
|
|
61
|
+
/** Tier-1 credential inputs (`--api-key` / `--profile`) and the injectable `security` runner tests use. */
|
|
62
|
+
credentials?: HooksCredentialOptions;
|
|
63
|
+
/** Where the one-line local-mode notice goes. Defaults to `process.stderr`. */
|
|
64
|
+
notice?: HooksTransportNotice;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Resolve the hooks transport. The deliberate unhosted opt-in is answered
|
|
68
|
+
* first and WITHOUT consulting the resolver; otherwise `@hasna/contracts`
|
|
69
|
+
* resolves the credential AND the authority together as one strict pair, and
|
|
70
|
+
* any failure to do so is a throw — the client never defaults to the on-box
|
|
71
|
+
* store (owner ruling 2026-09-04). Resolved fresh on every call.
|
|
72
|
+
*/
|
|
73
|
+
export declare function resolveHooksTransport(env?: HooksLocalOptInEnv, options?: HooksTransportOptions): HooksTransportResolution;
|
|
74
|
+
/**
|
|
75
|
+
* The registry keys the publish surface checks. Local-by-design commands
|
|
76
|
+
* (`hooks serve`) never pick a transport; they only need to know whether a
|
|
77
|
+
* credential exists to honour a PUT. Resolved fresh on every call, through the
|
|
78
|
+
* same chain as {@link resolveHooksTransport}, so a key rotation heals a
|
|
79
|
+
* long-lived server without a restart.
|
|
80
|
+
*
|
|
81
|
+
* Returns `undefined` when no credential resolves — reads stay open and
|
|
82
|
+
* publish refuses — and THROWS on a deliberate tier that exists but cannot be
|
|
83
|
+
* honoured (a locked Keychain, an unsafe credential file), because falling
|
|
84
|
+
* through to another identity is the one silent failure the chain exists to
|
|
85
|
+
* end.
|
|
86
|
+
*/
|
|
87
|
+
export declare function resolveHooksServePublishKey(env?: HooksLocalOptInEnv, options?: HooksTransportOptions): string | undefined;
|
package/dist/openapi.d.ts
CHANGED
|
@@ -209,7 +209,7 @@ export declare const openApiDocument: {
|
|
|
209
209
|
readonly apiKey: {
|
|
210
210
|
readonly type: "http";
|
|
211
211
|
readonly scheme: "bearer";
|
|
212
|
-
readonly description: "The registry API key (HASNA_HOOKS_API_KEY /
|
|
212
|
+
readonly description: "The registry API key — resolved by the client through the @hasna/contracts chain (HASNA_HOOKS_API_KEY, the Keychain item hasna.credentials.hooks.api-key, or ~/.hasna/hooks/config/credentials); the server compares the inbound bearer/x-api-key value.";
|
|
213
213
|
};
|
|
214
214
|
};
|
|
215
215
|
};
|