@hasna/hooks 0.2.20 → 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.
- package/README.md +45 -2
- package/bin/index.js +1157 -84
- package/dist/db/migrations/002_session_events.d.ts +10 -0
- package/dist/db/migrations/003_user_prompt_submit_event.d.ts +10 -0
- package/dist/db/pg-migrations.d.ts +1 -1
- package/dist/db/remote-storage.d.ts +9 -0
- package/dist/db/schema.d.ts +4 -3
- package/dist/db/storage-sync.d.ts +57 -0
- package/dist/index.d.ts +16 -3
- package/dist/index.js +1042 -58
- package/dist/lib/installer.d.ts +25 -5
- package/dist/lib/registry.d.ts +3 -1
- package/dist/storage.d.ts +4 -0
- package/dist/storage.js +696 -0
- package/hooks/codewith-native-common.test.ts +61 -0
- package/hooks/codewith-native-common.ts +478 -0
- package/hooks/hook-agent-rules-version-check/LICENSE +191 -0
- package/hooks/hook-agent-rules-version-check/README.md +50 -0
- package/hooks/hook-agent-rules-version-check/package.json +53 -0
- package/hooks/hook-agent-rules-version-check/src/hook.test.ts +104 -0
- package/hooks/hook-agent-rules-version-check/src/hook.ts +215 -0
- package/hooks/hook-agent-rules-version-check/tsconfig.json +25 -0
- package/hooks/hook-announce-start/README.md +7 -5
- package/hooks/hook-announce-start/package.json +2 -2
- package/hooks/hook-announce-start/src/hook.ts +33 -14
- package/hooks/hook-fleet-blockers-gate/LICENSE +191 -0
- package/hooks/hook-fleet-blockers-gate/README.md +39 -0
- package/hooks/hook-fleet-blockers-gate/package.json +52 -0
- package/hooks/hook-fleet-blockers-gate/src/hook.test.ts +106 -0
- package/hooks/hook-fleet-blockers-gate/src/hook.ts +242 -0
- package/hooks/hook-fleet-blockers-gate/tsconfig.json +25 -0
- package/hooks/hook-fleet-catchup/LICENSE +191 -0
- package/hooks/hook-fleet-catchup/README.md +40 -0
- package/hooks/hook-fleet-catchup/package.json +52 -0
- package/hooks/hook-fleet-catchup/src/hook.test.ts +156 -0
- package/hooks/hook-fleet-catchup/src/hook.ts +283 -0
- package/hooks/hook-fleet-catchup/tsconfig.json +25 -0
- package/hooks/pre-bash/README.md +17 -0
- package/hooks/pre-bash/package.json +12 -0
- package/hooks/pre-bash/src/hook.ts +103 -0
- package/hooks/prompt-guard/README.md +17 -0
- package/hooks/prompt-guard/package.json +12 -0
- package/hooks/prompt-guard/src/hook.ts +76 -0
- package/hooks/session-start/README.md +17 -0
- package/hooks/session-start/package.json +12 -0
- package/hooks/session-start/src/hook.ts +150 -0
- package/hooks/stop-sync/README.md +17 -0
- package/hooks/stop-sync/package.json +12 -0
- package/hooks/stop-sync/src/hook.ts +69 -0
- package/hooks/worktree-guard/README.md +17 -0
- package/hooks/worktree-guard/package.json +12 -0
- package/hooks/worktree-guard/src/hook.ts +88 -0
- package/package.json +14 -6
- package/dist/cli/components/App.d.ts +0 -7
- package/dist/cli/components/CategorySelect.d.ts +0 -7
- package/dist/cli/components/DataTable.d.ts +0 -11
- package/dist/cli/components/Header.d.ts +0 -7
- package/dist/cli/components/HookSelect.d.ts +0 -11
- package/dist/cli/components/InstallProgress.d.ts +0 -9
- package/dist/cli/components/SearchView.d.ts +0 -9
- package/dist/cli/index.d.ts +0 -2
- package/dist/lib/db-writer.d.ts +0 -9
- package/dist/mcp/http.d.ts +0 -16
- package/dist/mcp/server.d.ts +0 -17
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Claude Code Hook: fleet-blockers-gate
|
|
5
|
+
*
|
|
6
|
+
* PreToolUse hook — every-turn insurance against working through a fleet
|
|
7
|
+
* freeze. While an unread [FREEZE] blocking message is active, mutating
|
|
8
|
+
* tools are denied with a reason; read-only tools stay allowed so the agent
|
|
9
|
+
* can read the freeze and react.
|
|
10
|
+
*
|
|
11
|
+
* Design constraints (fleet comms strategy §3):
|
|
12
|
+
* - deterministic local CLI call (`conversations blockers -j`)
|
|
13
|
+
* - hard 500ms fail-open timeout on the check
|
|
14
|
+
* - TTL cache so the common path never spawns a process per tool call
|
|
15
|
+
*
|
|
16
|
+
* Environment:
|
|
17
|
+
* - HOOKS_FLEET_GATE_DISABLE=1 → allow everything (kill switch)
|
|
18
|
+
* - HOOKS_FLEET_GATE_TTL_MS=<n> → cache TTL (default 60000)
|
|
19
|
+
* - HOOKS_FLEET_TIMEOUT_MS=<n> → blockers check exec timeout (default 500)
|
|
20
|
+
* - HOOKS_FLEET_AGENT=<name> → identity passed as --from
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
import { readFileSync, existsSync, mkdirSync, writeFileSync } from "fs";
|
|
24
|
+
import { join } from "path";
|
|
25
|
+
import { homedir } from "os";
|
|
26
|
+
import { execSync } from "child_process";
|
|
27
|
+
|
|
28
|
+
interface HookInput {
|
|
29
|
+
session_id: string;
|
|
30
|
+
cwd: string;
|
|
31
|
+
hook_event_name: string;
|
|
32
|
+
tool_name?: string;
|
|
33
|
+
tool_input?: Record<string, unknown>;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
interface HookOutput {
|
|
37
|
+
continue?: boolean;
|
|
38
|
+
hookSpecificOutput?: {
|
|
39
|
+
hookEventName: "PreToolUse";
|
|
40
|
+
permissionDecision: "allow" | "deny" | "ask";
|
|
41
|
+
permissionDecisionReason: string;
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface FreezeState {
|
|
46
|
+
checked_at: string;
|
|
47
|
+
frozen: boolean;
|
|
48
|
+
reason: string;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const DEFAULT_TTL_MS = 60_000;
|
|
52
|
+
const DEFAULT_TIMEOUT_MS = 500;
|
|
53
|
+
const STATE_DIR = join(homedir(), ".hasna", "hooks", "state");
|
|
54
|
+
const CACHE_FILE = join(STATE_DIR, "fleet-blockers-gate.json");
|
|
55
|
+
|
|
56
|
+
/** Built-in tools that only read state — never gated, so a frozen agent can orient itself. */
|
|
57
|
+
const READ_ONLY_TOOLS = new Set([
|
|
58
|
+
"Read",
|
|
59
|
+
"Glob",
|
|
60
|
+
"Grep",
|
|
61
|
+
"LS",
|
|
62
|
+
"NotebookRead",
|
|
63
|
+
"WebFetch",
|
|
64
|
+
"WebSearch",
|
|
65
|
+
"ToolSearch",
|
|
66
|
+
"AskUserQuestion",
|
|
67
|
+
]);
|
|
68
|
+
|
|
69
|
+
/** MCP operation prefixes treated as read-only (mcp__server__<op>). */
|
|
70
|
+
const READ_ONLY_MCP_PREFIXES = [
|
|
71
|
+
"get",
|
|
72
|
+
"list",
|
|
73
|
+
"read",
|
|
74
|
+
"search",
|
|
75
|
+
"show",
|
|
76
|
+
"describe",
|
|
77
|
+
"check",
|
|
78
|
+
"status",
|
|
79
|
+
"heartbeat",
|
|
80
|
+
"count",
|
|
81
|
+
"recall",
|
|
82
|
+
"inspect",
|
|
83
|
+
];
|
|
84
|
+
|
|
85
|
+
function readStdinJson(): HookInput | null {
|
|
86
|
+
try {
|
|
87
|
+
const input = readFileSync(0, "utf-8").trim();
|
|
88
|
+
if (!input) return null;
|
|
89
|
+
return JSON.parse(input);
|
|
90
|
+
} catch {
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function respond(output: HookOutput): void {
|
|
96
|
+
console.log(JSON.stringify(output));
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function ttlMs(): number {
|
|
100
|
+
const raw = Number(process.env.HOOKS_FLEET_GATE_TTL_MS);
|
|
101
|
+
return Number.isFinite(raw) && raw > 0 ? raw : DEFAULT_TTL_MS;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function timeoutMs(): number {
|
|
105
|
+
const raw = Number(process.env.HOOKS_FLEET_TIMEOUT_MS);
|
|
106
|
+
return Number.isFinite(raw) && raw > 0 ? raw : DEFAULT_TIMEOUT_MS;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** True when the tool cannot mutate anything and must stay usable during a freeze. */
|
|
110
|
+
export function isReadOnlyTool(toolName: string | undefined): boolean {
|
|
111
|
+
if (!toolName) return false;
|
|
112
|
+
if (READ_ONLY_TOOLS.has(toolName)) return true;
|
|
113
|
+
|
|
114
|
+
if (toolName.startsWith("mcp__")) {
|
|
115
|
+
const op = toolName.split("__").pop() || "";
|
|
116
|
+
return READ_ONLY_MCP_PREFIXES.some(
|
|
117
|
+
(prefix) => op === prefix || op.startsWith(`${prefix}_`) || op.startsWith(`${prefix}-`)
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return false;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** Detect an active [FREEZE] in the unread blocking messages list. */
|
|
125
|
+
export function detectFreeze(blockers: unknown[]): { frozen: boolean; reason: string } {
|
|
126
|
+
for (const item of blockers) {
|
|
127
|
+
if (!item || typeof item !== "object") continue;
|
|
128
|
+
const m = item as Record<string, unknown>;
|
|
129
|
+
const body = [m.content, m.preview, m.message, m.title]
|
|
130
|
+
.filter((v): v is string => typeof v === "string")
|
|
131
|
+
.join(" ");
|
|
132
|
+
if (/\[FREEZE\]/.test(body)) {
|
|
133
|
+
const from = typeof m.from === "string" ? m.from : "unknown";
|
|
134
|
+
return {
|
|
135
|
+
frozen: true,
|
|
136
|
+
reason: `Unread [FREEZE] blocking message from ${from}: ${body.slice(0, 240)}`,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return { frozen: false, reason: "" };
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export function parseBlockersJson(raw: string | null): unknown[] {
|
|
144
|
+
if (!raw) return [];
|
|
145
|
+
try {
|
|
146
|
+
const data = JSON.parse(raw);
|
|
147
|
+
if (Array.isArray(data)) return data;
|
|
148
|
+
if (data && typeof data === "object") {
|
|
149
|
+
const inner = (data as Record<string, unknown>).blockers ?? (data as Record<string, unknown>).messages;
|
|
150
|
+
if (Array.isArray(inner)) return inner;
|
|
151
|
+
}
|
|
152
|
+
return [];
|
|
153
|
+
} catch {
|
|
154
|
+
return [];
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function readCache(now: Date): FreezeState | null {
|
|
159
|
+
try {
|
|
160
|
+
if (!existsSync(CACHE_FILE)) return null;
|
|
161
|
+
const state = JSON.parse(readFileSync(CACHE_FILE, "utf-8")) as FreezeState;
|
|
162
|
+
const checkedAt = new Date(state.checked_at).getTime();
|
|
163
|
+
if (Number.isNaN(checkedAt)) return null;
|
|
164
|
+
if (now.getTime() - checkedAt > ttlMs()) return null;
|
|
165
|
+
return state;
|
|
166
|
+
} catch {
|
|
167
|
+
return null;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function writeCache(state: FreezeState): void {
|
|
172
|
+
try {
|
|
173
|
+
mkdirSync(STATE_DIR, { recursive: true });
|
|
174
|
+
writeFileSync(CACHE_FILE, JSON.stringify(state));
|
|
175
|
+
} catch {
|
|
176
|
+
// fail-open: cache is an optimization
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function checkFreeze(now: Date): FreezeState {
|
|
181
|
+
const cached = readCache(now);
|
|
182
|
+
if (cached) return cached;
|
|
183
|
+
|
|
184
|
+
try {
|
|
185
|
+
const agent = process.env.HOOKS_FLEET_AGENT;
|
|
186
|
+
const from = agent && /^[A-Za-z0-9._-]{1,64}$/.test(agent) ? ` --from ${agent}` : "";
|
|
187
|
+
const raw = execSync(`conversations blockers -j${from}`, {
|
|
188
|
+
encoding: "utf-8",
|
|
189
|
+
timeout: timeoutMs(),
|
|
190
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
191
|
+
});
|
|
192
|
+
const result = detectFreeze(parseBlockersJson(raw.trim()));
|
|
193
|
+
const state: FreezeState = { checked_at: now.toISOString(), frozen: result.frozen, reason: result.reason };
|
|
194
|
+
writeCache(state);
|
|
195
|
+
return state;
|
|
196
|
+
} catch {
|
|
197
|
+
// CLI missing / timeout / service down → fail open (never wedge the agent)
|
|
198
|
+
// Do not cache an unverified "not frozen" state; retry on the next mutating tool.
|
|
199
|
+
return { checked_at: now.toISOString(), frozen: false, reason: "" };
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
export function run(): void {
|
|
204
|
+
if (process.env.HOOKS_FLEET_GATE_DISABLE === "1") {
|
|
205
|
+
respond({ continue: true });
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
const input = readStdinJson();
|
|
210
|
+
if (!input) {
|
|
211
|
+
respond({ continue: true });
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// Read-only tools always pass — the agent must stay able to read the freeze.
|
|
216
|
+
if (isReadOnlyTool(input.tool_name)) {
|
|
217
|
+
respond({ continue: true });
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
const state = checkFreeze(new Date());
|
|
222
|
+
|
|
223
|
+
if (state.frozen) {
|
|
224
|
+
respond({
|
|
225
|
+
hookSpecificOutput: {
|
|
226
|
+
hookEventName: "PreToolUse",
|
|
227
|
+
permissionDecision: "deny",
|
|
228
|
+
permissionDecisionReason:
|
|
229
|
+
`[hook-fleet-blockers-gate] Fleet freeze active — mutating tools are blocked. ` +
|
|
230
|
+
`${state.reason} ` +
|
|
231
|
+
`Read the blocking message (conversations blockers), resolve or wait for [UNFREEZE], then retry.`,
|
|
232
|
+
},
|
|
233
|
+
});
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
respond({ continue: true });
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
if (import.meta.main) {
|
|
241
|
+
run();
|
|
242
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ESNext",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"lib": ["ESNext"],
|
|
6
|
+
"moduleResolution": "bundler",
|
|
7
|
+
"allowImportingTsExtensions": true,
|
|
8
|
+
"strict": true,
|
|
9
|
+
"esModuleInterop": true,
|
|
10
|
+
"skipLibCheck": true,
|
|
11
|
+
"forceConsistentCasingInFileNames": true,
|
|
12
|
+
"resolveJsonModule": true,
|
|
13
|
+
"isolatedModules": true,
|
|
14
|
+
"noEmit": true,
|
|
15
|
+
"noUnusedLocals": true,
|
|
16
|
+
"noUnusedParameters": true,
|
|
17
|
+
"declaration": true,
|
|
18
|
+
"declarationMap": true,
|
|
19
|
+
"outDir": "./dist",
|
|
20
|
+
"rootDir": "./src",
|
|
21
|
+
"types": ["bun-types"]
|
|
22
|
+
},
|
|
23
|
+
"include": ["src/**/*"],
|
|
24
|
+
"exclude": ["node_modules", "dist"]
|
|
25
|
+
}
|
|
@@ -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,40 @@
|
|
|
1
|
+
# hook-fleet-catchup
|
|
2
|
+
|
|
3
|
+
A SessionStart hook that catches an agent up on fleet communications before it starts working. Part of the Hasna fleet comms workflow (HACP read-duty).
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
hooks install fleet-catchup
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## How it works
|
|
12
|
+
|
|
13
|
+
On every `SessionStart` event it runs three deterministic, bounded reads against the local `conversations` CLI:
|
|
14
|
+
|
|
15
|
+
1. `conversations blockers -j` — unread blocking messages (must be handled before work)
|
|
16
|
+
2. `conversations notifications --since <last-catchup>` — channel notifications since the last catchup on this machine (bounded to 24h on first run)
|
|
17
|
+
3. `conversations digest announcements --unread --since 7d` — the bounded announcements digest (never hands a fresh session full history as unread)
|
|
18
|
+
|
|
19
|
+
Anything found is injected into the session via `hookSpecificOutput.additionalContext`, ending with the HACP read-duty reminder (unread `[FREEZE]` means stop and escalate).
|
|
20
|
+
|
|
21
|
+
The three reads run in parallel, so the worst-case session-start cost is one timeout, not the sum of three. Every step is fail-open: a missing CLI, dead service, timeout, or unparseable output skips that section and never blocks the session. The last-catchup cursor only advances after a successful notifications read — an outage never silently swallows the missed window.
|
|
22
|
+
|
|
23
|
+
## Configuration
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
export HOOKS_FLEET_CATCHUP_DISABLE=1 # Kill switch — skip entirely
|
|
27
|
+
export HOOKS_FLEET_AGENT="chief" # Identity passed as --from
|
|
28
|
+
export HOOKS_FLEET_TIMEOUT_MS=1500 # Per-command exec timeout (default 1500)
|
|
29
|
+
export HOOKS_FLEET_SINCE=7d # Announcements digest window (default 7d)
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
State: the last-catchup timestamp is stored at `~/.hasna/hooks/state/fleet-catchup.last_seen`.
|
|
33
|
+
|
|
34
|
+
## Requirements
|
|
35
|
+
|
|
36
|
+
- `conversations` CLI (@hasna/conversations) — optional; the hook is a no-op without it
|
|
37
|
+
|
|
38
|
+
## Event
|
|
39
|
+
|
|
40
|
+
- **SessionStart** (fires on startup, resume, and clear)
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@hasna/hook-fleet-catchup",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Claude Code SessionStart hook that injects unread blockers, channel notifications, and the announcements digest into agent context",
|
|
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
|
+
"catchup",
|
|
28
|
+
"blockers",
|
|
29
|
+
"announcements",
|
|
30
|
+
"context",
|
|
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
|
+
}
|