@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
@@ -1,98 +0,0 @@
1
- #!/usr/bin/env bun
2
- // @bun
3
-
4
- // src/hook.ts
5
- import { readFileSync, existsSync, mkdirSync, writeFileSync } from "fs";
6
- import { join } from "path";
7
- import { tmpdir } from "os";
8
- import { execSync } from "child_process";
9
- var STATE_DIR = join(tmpdir(), "hook-announce-start");
10
- function readStdinJson() {
11
- try {
12
- const input = readFileSync(0, "utf-8").trim();
13
- if (!input)
14
- return null;
15
- return JSON.parse(input);
16
- } catch {
17
- return null;
18
- }
19
- }
20
- function respond(output) {
21
- console.log(JSON.stringify(output));
22
- }
23
- function sanitizeId(id) {
24
- return id.replace(/[^a-zA-Z0-9_-]/g, "-").slice(0, 64);
25
- }
26
- function hasAlreadyAnnounced(sessionId) {
27
- const safe = sanitizeId(sessionId);
28
- return existsSync(join(STATE_DIR, `${safe}.announced`));
29
- }
30
- function markAnnounced(sessionId) {
31
- mkdirSync(STATE_DIR, { recursive: true });
32
- const safe = sanitizeId(sessionId);
33
- writeFileSync(join(STATE_DIR, `${safe}.announced`), new Date().toISOString());
34
- }
35
- function registerAgentProfile() {
36
- try {
37
- execSync("hooks init", {
38
- encoding: "utf-8",
39
- timeout: 5000,
40
- stdio: ["pipe", "pipe", "pipe"]
41
- });
42
- } catch {}
43
- }
44
- function fetchContext() {
45
- try {
46
- const output = execSync("conversations context", {
47
- encoding: "utf-8",
48
- timeout: 1e4,
49
- stdio: ["pipe", "pipe", "pipe"]
50
- });
51
- return output.trim() || null;
52
- } catch {
53
- return null;
54
- }
55
- }
56
- function announceToSpace(cwd, sessionId) {
57
- const project = cwd.split("/").filter(Boolean).pop() || "project";
58
- const agent = process.env.HOOKS_AGENT_NAME || `session:${sessionId.slice(0, 8)}`;
59
- const space = process.env.HOOKS_SPACE || "general";
60
- const message = `Agent **${agent}** started a session on **${project}**`;
61
- try {
62
- execSync(`conversations send "${message}" --space "${space}"`, {
63
- encoding: "utf-8",
64
- timeout: 1e4,
65
- stdio: ["pipe", "pipe", "pipe"]
66
- });
67
- console.error(`[hook-announce-start] Announced to space '${space}'`);
68
- } catch {
69
- console.error(`[hook-announce-start] Could not post to space`);
70
- }
71
- }
72
- function run() {
73
- const input = readStdinJson();
74
- if (!input) {
75
- respond({ continue: true });
76
- return;
77
- }
78
- if (hasAlreadyAnnounced(input.session_id)) {
79
- respond({ continue: true });
80
- return;
81
- }
82
- markAnnounced(input.session_id);
83
- registerAgentProfile();
84
- const context = fetchContext();
85
- if (context) {
86
- process.stderr.write(`[hook-announce-start] Session context:
87
- ${context}
88
- `);
89
- }
90
- announceToSpace(input.cwd, input.session_id);
91
- respond({ continue: true });
92
- }
93
- if (__require.main == __require.module) {
94
- run();
95
- }
96
- export {
97
- run
98
- };