@hasna/hooks 0.2.19 → 0.3.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.
Files changed (61) hide show
  1. package/README.md +45 -5
  2. package/bin/index.js +1262 -9569
  3. package/dist/db/index.d.ts +11 -0
  4. package/dist/db/legacy-import.d.ts +11 -0
  5. package/dist/db/migrations/001_initial.d.ts +6 -0
  6. package/dist/db/migrations/002_session_events.d.ts +10 -0
  7. package/dist/db/migrations/003_user_prompt_submit_event.d.ts +10 -0
  8. package/dist/db/migrations/index.d.ts +7 -0
  9. package/dist/db/pg-migrations.d.ts +7 -0
  10. package/dist/db/remote-storage.d.ts +9 -0
  11. package/dist/db/retention.d.ts +8 -0
  12. package/dist/db/schema.d.ts +22 -0
  13. package/dist/db/storage-sync.d.ts +57 -0
  14. package/dist/index.d.ts +72 -0
  15. package/dist/index.js +1042 -58
  16. package/dist/lib/installer.d.ts +56 -0
  17. package/dist/lib/profiles.d.ts +33 -0
  18. package/dist/lib/registry.d.ts +21 -0
  19. package/dist/storage.d.ts +4 -0
  20. package/dist/storage.js +696 -0
  21. package/hooks/codewith-native-common.test.ts +61 -0
  22. package/hooks/codewith-native-common.ts +478 -0
  23. package/hooks/hook-agent-rules-version-check/LICENSE +191 -0
  24. package/hooks/hook-agent-rules-version-check/README.md +50 -0
  25. package/hooks/hook-agent-rules-version-check/package.json +53 -0
  26. package/hooks/hook-agent-rules-version-check/src/hook.test.ts +104 -0
  27. package/hooks/hook-agent-rules-version-check/src/hook.ts +215 -0
  28. package/hooks/hook-agent-rules-version-check/tsconfig.json +25 -0
  29. package/hooks/hook-announce-start/README.md +7 -5
  30. package/hooks/hook-announce-start/package.json +2 -2
  31. package/hooks/hook-announce-start/src/hook.ts +33 -14
  32. package/hooks/hook-fleet-blockers-gate/LICENSE +191 -0
  33. package/hooks/hook-fleet-blockers-gate/README.md +39 -0
  34. package/hooks/hook-fleet-blockers-gate/package.json +52 -0
  35. package/hooks/hook-fleet-blockers-gate/src/hook.test.ts +106 -0
  36. package/hooks/hook-fleet-blockers-gate/src/hook.ts +242 -0
  37. package/hooks/hook-fleet-blockers-gate/tsconfig.json +25 -0
  38. package/hooks/hook-fleet-catchup/LICENSE +191 -0
  39. package/hooks/hook-fleet-catchup/README.md +40 -0
  40. package/hooks/hook-fleet-catchup/package.json +52 -0
  41. package/hooks/hook-fleet-catchup/src/hook.test.ts +156 -0
  42. package/hooks/hook-fleet-catchup/src/hook.ts +283 -0
  43. package/hooks/hook-fleet-catchup/tsconfig.json +25 -0
  44. package/hooks/pre-bash/README.md +17 -0
  45. package/hooks/pre-bash/package.json +12 -0
  46. package/hooks/pre-bash/src/hook.ts +103 -0
  47. package/hooks/prompt-guard/README.md +17 -0
  48. package/hooks/prompt-guard/package.json +12 -0
  49. package/hooks/prompt-guard/src/hook.ts +76 -0
  50. package/hooks/session-start/README.md +17 -0
  51. package/hooks/session-start/package.json +12 -0
  52. package/hooks/session-start/src/hook.ts +150 -0
  53. package/hooks/stop-sync/README.md +17 -0
  54. package/hooks/stop-sync/package.json +12 -0
  55. package/hooks/stop-sync/src/hook.ts +69 -0
  56. package/hooks/worktree-guard/README.md +17 -0
  57. package/hooks/worktree-guard/package.json +12 -0
  58. package/hooks/worktree-guard/src/hook.ts +88 -0
  59. package/package.json +14 -7
  60. package/hooks/hook-affected-tests/dist/hook.js +0 -106
  61. package/hooks/hook-announce-start/dist/hook.js +0 -98
@@ -3,28 +3,34 @@
3
3
  /**
4
4
  * Claude Code Hook: announce-start
5
5
  *
6
- * Notification hook that fires on session start (first notification).
6
+ * SessionStart hook that fires when a session starts (or resumes).
7
7
  * - Registers the agent profile if not already registered
8
- * - Reads unread DMs and injects them into context
8
+ * - Reads unread DMs/context and injects them into session context
9
9
  * - Announces presence to the team space
10
10
  *
11
- * Uses a per-session marker to only fire once per session.
11
+ * Uses a per-session marker so resume/clear/compact SessionStart events
12
+ * do not re-announce the same session.
12
13
  */
13
14
 
14
15
  import { readFileSync, existsSync, mkdirSync, writeFileSync } from "fs";
15
16
  import { join } from "path";
16
- import { homedir, tmpdir } from "os";
17
+ import { tmpdir } from "os";
17
18
  import { execSync } from "child_process";
18
19
 
19
20
  interface HookInput {
20
21
  session_id: string;
21
22
  cwd: string;
22
23
  hook_event_name: string;
23
- notification_type?: string;
24
+ /** SessionStart provides how the session began: startup | resume | clear | compact */
25
+ source?: string;
24
26
  }
25
27
 
26
28
  interface HookOutput {
27
29
  continue: boolean;
30
+ hookSpecificOutput?: {
31
+ hookEventName: "SessionStart";
32
+ additionalContext: string;
33
+ };
28
34
  }
29
35
 
30
36
  const STATE_DIR = join(tmpdir(), "hook-announce-start");
@@ -81,10 +87,16 @@ function fetchContext(): string | null {
81
87
  }
82
88
  }
83
89
 
90
+ /** Strip anything shell-unsafe from values interpolated into the announce command. */
91
+ function shellSafe(value: string, fallback: string): string {
92
+ const cleaned = value.replace(/[^A-Za-z0-9 ._:-]/g, "").trim().slice(0, 64);
93
+ return cleaned || fallback;
94
+ }
95
+
84
96
  function announceToSpace(cwd: string, sessionId: string): void {
85
- const project = cwd.split("/").filter(Boolean).pop() || "project";
86
- const agent = process.env.HOOKS_AGENT_NAME || `session:${sessionId.slice(0, 8)}`;
87
- const space = process.env.HOOKS_SPACE || "general";
97
+ const project = shellSafe(cwd.split("/").filter(Boolean).pop() || "", "project");
98
+ const agent = shellSafe(process.env.HOOKS_AGENT_NAME || "", `session:${sanitizeId(sessionId).slice(0, 8)}`);
99
+ const space = shellSafe(process.env.HOOKS_SPACE || "", "general");
88
100
  const message = `Agent **${agent}** started a session on **${project}**`;
89
101
 
90
102
  try {
@@ -107,7 +119,7 @@ export function run(): void {
107
119
  return;
108
120
  }
109
121
 
110
- // Only fire once per session
122
+ // Only fire once per session (SessionStart also fires on resume/clear/compact)
111
123
  if (hasAlreadyAnnounced(input.session_id)) {
112
124
  respond({ continue: true });
113
125
  return;
@@ -120,15 +132,22 @@ export function run(): void {
120
132
 
121
133
  // 2. Fetch context (unread DMs + online agents + spaces)
122
134
  const context = fetchContext();
123
- if (context) {
124
- process.stderr.write(
125
- `[hook-announce-start] Session context:\n${context}\n`
126
- );
127
- }
128
135
 
129
136
  // 3. Announce to team space
130
137
  announceToSpace(input.cwd, input.session_id);
131
138
 
139
+ // 4. Inject fetched context into the session (SessionStart supports additionalContext)
140
+ if (context) {
141
+ respond({
142
+ continue: true,
143
+ hookSpecificOutput: {
144
+ hookEventName: "SessionStart",
145
+ additionalContext: `[hook-announce-start] Session context:\n${context}`,
146
+ },
147
+ });
148
+ return;
149
+ }
150
+
132
151
  respond({ continue: true });
133
152
  }
134
153
 
@@ -0,0 +1,191 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to the Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by the Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding any notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ Copyright 2025 Hasna
180
+
181
+ Licensed under the Apache License, Version 2.0 (the "License");
182
+ you may not use this file except in compliance with the License.
183
+ You may obtain a copy of the License at
184
+
185
+ http://www.apache.org/licenses/LICENSE-2.0
186
+
187
+ Unless required by applicable law or agreed to in writing, software
188
+ distributed under the License is distributed on an "AS IS" BASIS,
189
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
190
+ See the License for the specific language governing permissions and
191
+ limitations under the License.
@@ -0,0 +1,39 @@
1
+ # hook-fleet-blockers-gate
2
+
3
+ A PreToolUse hook that stops an agent from working through a fleet freeze. While an unread `[FREEZE]` blocking message is active, mutating tools are denied with a clear reason; read-only tools stay allowed so the agent can read the freeze and react. Part of the Hasna fleet comms workflow (every-turn insurance).
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ hooks install fleet-blockers-gate
9
+ ```
10
+
11
+ ## How it works
12
+
13
+ On each `PreToolUse` event:
14
+
15
+ 1. **Read-only tools pass immediately** — `Read`, `Glob`, `Grep`, `WebFetch`, MCP `get_*`/`list_*`/`search_*`-style operations, etc. A frozen agent must stay able to orient itself.
16
+ 2. **Freeze state is TTL-cached** (`~/.hasna/hooks/state/fleet-blockers-gate.json`, default 60s) so the common path never spawns a process per tool call.
17
+ 3. On cache expiry it runs `conversations blockers -j` with a hard 500ms timeout and scans unread blocking messages for the `[FREEZE]` severity tag.
18
+ 4. If frozen, mutating tools are denied via `permissionDecision: "deny"` with the freeze reason; the agent is told to read the blocker and wait for `[UNFREEZE]`.
19
+
20
+ Fail-open by design: if the `conversations` CLI is missing, the service is down, or the check times out, tools are allowed — the gate must never wedge an agent.
21
+
22
+ The freeze clears when the blocking message is no longer unread (read + resolved), after which the next cache refresh allows tools again.
23
+
24
+ ## Configuration
25
+
26
+ ```bash
27
+ export HOOKS_FLEET_GATE_DISABLE=1 # Kill switch — allow everything
28
+ export HOOKS_FLEET_GATE_TTL_MS=60000 # Cache TTL (default 60000)
29
+ export HOOKS_FLEET_TIMEOUT_MS=500 # Blockers check timeout (default 500)
30
+ export HOOKS_FLEET_AGENT="chief" # Identity passed as --from
31
+ ```
32
+
33
+ ## Requirements
34
+
35
+ - `conversations` CLI (@hasna/conversations) — optional; the gate fails open without it
36
+
37
+ ## Event
38
+
39
+ - **PreToolUse** (all tools; read-only tools short-circuit to allow)
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "@hasna/hook-fleet-blockers-gate",
3
+ "version": "0.1.0",
4
+ "description": "Claude Code PreToolUse hook that blocks mutating tools while an unread [FREEZE] blocker is active (TTL-cached, fail-open under 500ms)",
5
+ "type": "module",
6
+ "main": "./dist/hook.js",
7
+ "exports": {
8
+ ".": {
9
+ "import": "./dist/hook.js",
10
+ "types": "./dist/hook.d.ts"
11
+ }
12
+ },
13
+ "files": [
14
+ "dist",
15
+ "README.md"
16
+ ],
17
+ "scripts": {
18
+ "build": "bun build ./src/hook.ts --outdir ./dist --target node",
19
+ "prepublishOnly": "bun run build",
20
+ "typecheck": "tsc --noEmit"
21
+ },
22
+ "keywords": [
23
+ "claude-code",
24
+ "claude",
25
+ "hook",
26
+ "fleet",
27
+ "freeze",
28
+ "blockers",
29
+ "gate",
30
+ "safety",
31
+ "agent-teams"
32
+ ],
33
+ "author": "Hasna",
34
+ "license": "Apache-2.0",
35
+ "repository": {
36
+ "type": "git",
37
+ "url": "https://github.com/hasna/hooks.git"
38
+ },
39
+ "publishConfig": {
40
+ "access": "public",
41
+ "registry": "https://registry.npmjs.org/"
42
+ },
43
+ "engines": {
44
+ "node": ">=18",
45
+ "bun": ">=1.0"
46
+ },
47
+ "devDependencies": {
48
+ "@types/bun": "^1.3.8",
49
+ "@types/node": "^20",
50
+ "typescript": "^5.0.0"
51
+ }
52
+ }
@@ -0,0 +1,106 @@
1
+ import { describe, test, expect } from "bun:test";
2
+ import { isReadOnlyTool, detectFreeze, parseBlockersJson } from "./hook";
3
+
4
+ describe("hook-fleet-blockers-gate", () => {
5
+ describe("isReadOnlyTool", () => {
6
+ test("built-in read-only tools pass", () => {
7
+ expect(isReadOnlyTool("Read")).toBe(true);
8
+ expect(isReadOnlyTool("Glob")).toBe(true);
9
+ expect(isReadOnlyTool("Grep")).toBe(true);
10
+ expect(isReadOnlyTool("WebFetch")).toBe(true);
11
+ expect(isReadOnlyTool("WebSearch")).toBe(true);
12
+ });
13
+
14
+ test("mutating built-ins are gated", () => {
15
+ expect(isReadOnlyTool("Bash")).toBe(false);
16
+ expect(isReadOnlyTool("Edit")).toBe(false);
17
+ expect(isReadOnlyTool("Write")).toBe(false);
18
+ expect(isReadOnlyTool("NotebookEdit")).toBe(false);
19
+ expect(isReadOnlyTool("Task")).toBe(false);
20
+ expect(isReadOnlyTool("TodoWrite")).toBe(false);
21
+ });
22
+
23
+ test("read-style MCP operations pass", () => {
24
+ expect(isReadOnlyTool("mcp__conversations__list_channels")).toBe(true);
25
+ expect(isReadOnlyTool("mcp__conversations__get_blockers")).toBe(true);
26
+ expect(isReadOnlyTool("mcp__todos__search_tools")).toBe(true);
27
+ expect(isReadOnlyTool("mcp__monitor__heartbeat")).toBe(true);
28
+ });
29
+
30
+ test("mutating MCP operations are gated", () => {
31
+ expect(isReadOnlyTool("mcp__conversations__send_message")).toBe(false);
32
+ expect(isReadOnlyTool("mcp__todos__create_task")).toBe(false);
33
+ expect(isReadOnlyTool("mcp__configs__apply_config")).toBe(false);
34
+ expect(isReadOnlyTool("mcp__emails__delete_domain")).toBe(false);
35
+ });
36
+
37
+ test("missing tool name is gated (conservative)", () => {
38
+ expect(isReadOnlyTool(undefined)).toBe(false);
39
+ expect(isReadOnlyTool("")).toBe(false);
40
+ });
41
+
42
+ test("prefix matching does not overmatch (getaway is not get)", () => {
43
+ expect(isReadOnlyTool("mcp__x__getaway_driver")).toBe(false);
44
+ expect(isReadOnlyTool("mcp__x__listen_events")).toBe(false);
45
+ });
46
+ });
47
+
48
+ describe("detectFreeze", () => {
49
+ test("finds [FREEZE] in blocker content", () => {
50
+ const result = detectFreeze([
51
+ { from: "chief", content: "[FREEZE] cutover in progress — stop all publishes" },
52
+ ]);
53
+ expect(result.frozen).toBe(true);
54
+ expect(result.reason).toContain("chief");
55
+ expect(result.reason).toContain("[FREEZE]");
56
+ });
57
+
58
+ test("finds [FREEZE] in preview field", () => {
59
+ const result = detectFreeze([{ from: "chief", preview: "[FREEZE] db migration" }]);
60
+ expect(result.frozen).toBe(true);
61
+ });
62
+
63
+ test("non-freeze blockers do not freeze", () => {
64
+ const result = detectFreeze([
65
+ { from: "worker", content: "please review PR #42 when you can" },
66
+ ]);
67
+ expect(result.frozen).toBe(false);
68
+ });
69
+
70
+ test("empty list does not freeze", () => {
71
+ expect(detectFreeze([]).frozen).toBe(false);
72
+ });
73
+
74
+ test("garbage entries are ignored", () => {
75
+ expect(detectFreeze([null, 42, "string", {}]).frozen).toBe(false);
76
+ });
77
+
78
+ test("lowercase freeze tag does not trigger (exact uppercase per HACP)", () => {
79
+ expect(detectFreeze([{ content: "[freeze] not a real tag" }]).frozen).toBe(false);
80
+ });
81
+ });
82
+
83
+ describe("parseBlockersJson", () => {
84
+ test("parses a bare array", () => {
85
+ expect(parseBlockersJson('[{"content":"x"}]')).toHaveLength(1);
86
+ });
87
+
88
+ test("parses wrapped blockers", () => {
89
+ expect(parseBlockersJson('{"blockers":[{"content":"x"}]}')).toHaveLength(1);
90
+ });
91
+
92
+ test("parses wrapped messages", () => {
93
+ expect(parseBlockersJson('{"messages":[{"content":"x"}]}')).toHaveLength(1);
94
+ });
95
+
96
+ test("returns empty on invalid JSON", () => {
97
+ expect(parseBlockersJson("not json")).toHaveLength(0);
98
+ });
99
+
100
+ test("returns empty on null/empty", () => {
101
+ expect(parseBlockersJson(null)).toHaveLength(0);
102
+ expect(parseBlockersJson("")).toHaveLength(0);
103
+ });
104
+ });
105
+
106
+ });