failproofai 0.0.6-beta.2 → 0.0.6-beta.3

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 (119) hide show
  1. package/.next/standalone/.next/BUILD_ID +1 -1
  2. package/.next/standalone/.next/build-manifest.json +3 -3
  3. package/.next/standalone/.next/prerender-manifest.json +3 -3
  4. package/.next/standalone/.next/required-server-files.json +1 -1
  5. package/.next/standalone/.next/server/app/_global-error/page/server-reference-manifest.json +1 -1
  6. package/.next/standalone/.next/server/app/_global-error/page.js.nft.json +1 -1
  7. package/.next/standalone/.next/server/app/_global-error/page_client-reference-manifest.js +1 -1
  8. package/.next/standalone/.next/server/app/_global-error.html +1 -1
  9. package/.next/standalone/.next/server/app/_global-error.rsc +7 -7
  10. package/.next/standalone/.next/server/app/_global-error.segments/__PAGE__.segment.rsc +2 -2
  11. package/.next/standalone/.next/server/app/_global-error.segments/_full.segment.rsc +7 -7
  12. package/.next/standalone/.next/server/app/_global-error.segments/_head.segment.rsc +3 -3
  13. package/.next/standalone/.next/server/app/_global-error.segments/_index.segment.rsc +3 -3
  14. package/.next/standalone/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  15. package/.next/standalone/.next/server/app/_not-found/page/server-reference-manifest.json +1 -1
  16. package/.next/standalone/.next/server/app/_not-found/page.js.nft.json +1 -1
  17. package/.next/standalone/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  18. package/.next/standalone/.next/server/app/_not-found.html +2 -2
  19. package/.next/standalone/.next/server/app/_not-found.rsc +15 -15
  20. package/.next/standalone/.next/server/app/_not-found.segments/_full.segment.rsc +15 -15
  21. package/.next/standalone/.next/server/app/_not-found.segments/_head.segment.rsc +4 -4
  22. package/.next/standalone/.next/server/app/_not-found.segments/_index.segment.rsc +10 -10
  23. package/.next/standalone/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +2 -2
  24. package/.next/standalone/.next/server/app/_not-found.segments/_not-found.segment.rsc +3 -3
  25. package/.next/standalone/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
  26. package/.next/standalone/.next/server/app/index.html +1 -1
  27. package/.next/standalone/.next/server/app/index.rsc +15 -15
  28. package/.next/standalone/.next/server/app/index.segments/__PAGE__.segment.rsc +2 -2
  29. package/.next/standalone/.next/server/app/index.segments/_full.segment.rsc +15 -15
  30. package/.next/standalone/.next/server/app/index.segments/_head.segment.rsc +4 -4
  31. package/.next/standalone/.next/server/app/index.segments/_index.segment.rsc +10 -10
  32. package/.next/standalone/.next/server/app/index.segments/_tree.segment.rsc +1 -1
  33. package/.next/standalone/.next/server/app/page/server-reference-manifest.json +1 -1
  34. package/.next/standalone/.next/server/app/page.js.nft.json +1 -1
  35. package/.next/standalone/.next/server/app/page_client-reference-manifest.js +1 -1
  36. package/.next/standalone/.next/server/app/policies/page/server-reference-manifest.json +8 -8
  37. package/.next/standalone/.next/server/app/policies/page.js.nft.json +1 -1
  38. package/.next/standalone/.next/server/app/policies/page_client-reference-manifest.js +1 -1
  39. package/.next/standalone/.next/server/app/project/[name]/page/server-reference-manifest.json +1 -1
  40. package/.next/standalone/.next/server/app/project/[name]/page.js.nft.json +1 -1
  41. package/.next/standalone/.next/server/app/project/[name]/page_client-reference-manifest.js +1 -1
  42. package/.next/standalone/.next/server/app/project/[name]/session/[sessionId]/page/react-loadable-manifest.json +2 -2
  43. package/.next/standalone/.next/server/app/project/[name]/session/[sessionId]/page/server-reference-manifest.json +2 -2
  44. package/.next/standalone/.next/server/app/project/[name]/session/[sessionId]/page.js.nft.json +1 -1
  45. package/.next/standalone/.next/server/app/project/[name]/session/[sessionId]/page_client-reference-manifest.js +1 -1
  46. package/.next/standalone/.next/server/app/projects/page/server-reference-manifest.json +1 -1
  47. package/.next/standalone/.next/server/app/projects/page.js.nft.json +1 -1
  48. package/.next/standalone/.next/server/app/projects/page_client-reference-manifest.js +1 -1
  49. package/.next/standalone/.next/server/chunks/[root-of-the-server]__0g72weg._.js +1 -1
  50. package/.next/standalone/.next/server/chunks/package_json_[json]_cjs_0z7w.hh._.js +1 -1
  51. package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__092s1ta._.js +2 -2
  52. package/.next/standalone/.next/server/chunks/ssr/{[root-of-the-server]__05akje6._.js → [root-of-the-server]__096k.db._.js} +2 -2
  53. package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__09icjsf._.js +2 -2
  54. package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0g.lg8b._.js +2 -2
  55. package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0h..k-e._.js +2 -2
  56. package/.next/standalone/.next/server/chunks/ssr/{[root-of-the-server]__0i5kvry._.js → [root-of-the-server]__0kyh86x._.js} +2 -2
  57. package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0okos0k._.js +2 -2
  58. package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0w6l33k._.js +2 -2
  59. package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__11pa2ra._.js +2 -2
  60. package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__12t-wym._.js +2 -2
  61. package/.next/standalone/.next/server/chunks/ssr/_10lm7or._.js +2 -2
  62. package/.next/standalone/.next/server/chunks/ssr/app_global-error_tsx_0xerkr6._.js +1 -1
  63. package/.next/standalone/.next/server/chunks/ssr/app_policies_hooks-client_tsx_0q-m0y-._.js +1 -1
  64. package/.next/standalone/.next/server/middleware-build-manifest.js +3 -3
  65. package/.next/standalone/.next/server/pages/404.html +2 -2
  66. package/.next/standalone/.next/server/pages/500.html +1 -1
  67. package/.next/standalone/.next/server/server-reference-manifest.js +1 -1
  68. package/.next/standalone/.next/server/server-reference-manifest.json +9 -9
  69. package/.next/standalone/.next/static/chunks/{1052sguyd-.ka.js → 0-dm_9a6nsc2l.js} +1 -1
  70. package/.next/standalone/.next/static/chunks/{05j1px0r8yzh6.js → 01pmw1-asbek~.js} +2 -2
  71. package/.next/standalone/.next/static/chunks/{14cl9poem30dq.js → 051m32nx~n5yr.js} +1 -1
  72. package/.next/standalone/.next/static/chunks/{0badv41uxa56..js → 0a-yctdwn368y.js} +1 -1
  73. package/.next/standalone/.next/static/chunks/{0xpl.oscrakvx.js → 0l-mu4okl-cj1.js} +1 -1
  74. package/.next/standalone/.next/static/chunks/{00j0rr7rh8ef8.js → 0mazj-p-~2kc6.js} +1 -1
  75. package/.next/standalone/.next/static/chunks/0qakntsrpc~1j.js +6 -0
  76. package/.next/standalone/.next/static/chunks/{0npb~873.wvg3.js → 156zca6aewyr-.js} +1 -1
  77. package/.next/standalone/CHANGELOG.md +7 -0
  78. package/.next/standalone/bin/failproofai.mjs +91 -4
  79. package/.next/standalone/dist/cli.mjs +1155 -54
  80. package/.next/standalone/docs/ar/built-in-policies.mdx +118 -118
  81. package/.next/standalone/docs/built-in-policies.mdx +2 -2
  82. package/.next/standalone/docs/de/built-in-policies.mdx +48 -48
  83. package/.next/standalone/docs/es/built-in-policies.mdx +82 -82
  84. package/.next/standalone/docs/fr/built-in-policies.mdx +72 -72
  85. package/.next/standalone/docs/he/built-in-policies.mdx +129 -128
  86. package/.next/standalone/docs/hi/built-in-policies.mdx +178 -182
  87. package/.next/standalone/docs/it/built-in-policies.mdx +64 -64
  88. package/.next/standalone/docs/ja/built-in-policies.mdx +128 -128
  89. package/.next/standalone/docs/ko/built-in-policies.mdx +111 -111
  90. package/.next/standalone/docs/pt-br/built-in-policies.mdx +65 -65
  91. package/.next/standalone/docs/ru/built-in-policies.mdx +72 -72
  92. package/.next/standalone/docs/tr/built-in-policies.mdx +99 -99
  93. package/.next/standalone/docs/vi/built-in-policies.mdx +69 -72
  94. package/.next/standalone/docs/zh/built-in-policies.mdx +76 -78
  95. package/.next/standalone/package.json +1 -1
  96. package/.next/standalone/server.js +1 -1
  97. package/.next/standalone/src/auth/login.ts +104 -0
  98. package/.next/standalone/src/auth/logout.ts +50 -0
  99. package/.next/standalone/src/auth/token-store.ts +64 -0
  100. package/.next/standalone/src/hooks/builtin-policies.ts +22 -20
  101. package/.next/standalone/src/hooks/handler.ts +35 -15
  102. package/.next/standalone/src/relay/daemon.ts +362 -0
  103. package/.next/standalone/src/relay/pid.ts +76 -0
  104. package/.next/standalone/src/relay/queue.ts +225 -0
  105. package/bin/failproofai.mjs +91 -4
  106. package/dist/cli.mjs +1155 -54
  107. package/package.json +1 -1
  108. package/src/auth/login.ts +104 -0
  109. package/src/auth/logout.ts +50 -0
  110. package/src/auth/token-store.ts +64 -0
  111. package/src/hooks/builtin-policies.ts +22 -20
  112. package/src/hooks/handler.ts +35 -15
  113. package/src/relay/daemon.ts +362 -0
  114. package/src/relay/pid.ts +76 -0
  115. package/src/relay/queue.ts +225 -0
  116. package/.next/standalone/.next/static/chunks/0ijk_kek9_wyx.js +0 -6
  117. /package/.next/standalone/.next/static/{A9pNTZdoYJTVyPAYwQMx5 → r-wX0MuAfCjbhJm3phQc8}/_buildManifest.js +0 -0
  118. /package/.next/standalone/.next/static/{A9pNTZdoYJTVyPAYwQMx5 → r-wX0MuAfCjbhJm3phQc8}/_clientMiddlewareManifest.js +0 -0
  119. /package/.next/standalone/.next/static/{A9pNTZdoYJTVyPAYwQMx5 → r-wX0MuAfCjbhJm3phQc8}/_ssgManifest.js +0 -0
@@ -0,0 +1,50 @@
1
+ import { readTokens, clearTokens } from "./token-store";
2
+ import { stopRelay } from "../relay/pid";
3
+
4
+ const LOGOUT_TIMEOUT_MS = 3_000;
5
+
6
+ export async function logout(): Promise<void> {
7
+ const tokens = readTokens();
8
+ if (!tokens) {
9
+ console.log("Not logged in.");
10
+ return;
11
+ }
12
+
13
+ // Best-effort server revoke with a short timeout — the local logout
14
+ // must not block on a slow network.
15
+ try {
16
+ await fetch(`${tokens.server_url}/api/v1/auth/logout`, {
17
+ method: "POST",
18
+ headers: { "Content-Type": "application/json" },
19
+ body: JSON.stringify({ refresh_token: tokens.refresh_token }),
20
+ signal: AbortSignal.timeout(LOGOUT_TIMEOUT_MS),
21
+ });
22
+ } catch {
23
+ // Network or timeout — proceed to local clear anyway
24
+ }
25
+
26
+ try {
27
+ stopRelay();
28
+ } catch {
29
+ // Best-effort daemon stop
30
+ }
31
+
32
+ clearTokens();
33
+ console.log("Logged out.");
34
+ }
35
+
36
+ export function whoami(): void {
37
+ const tokens = readTokens();
38
+ if (!tokens) {
39
+ console.log("Not logged in. Run `failproofai login` to authenticate.");
40
+ process.exit(1);
41
+ }
42
+ console.log(`Logged in as ${tokens.user_email}`);
43
+ console.log(`Server: ${tokens.server_url}`);
44
+ const expiresIn = tokens.expires_at - Math.floor(Date.now() / 1000);
45
+ if (expiresIn > 0) {
46
+ console.log(`Access token expires in ${Math.floor(expiresIn / 60)} minutes`);
47
+ } else {
48
+ console.log(`Access token expired (will refresh on next use)`);
49
+ }
50
+ }
@@ -0,0 +1,64 @@
1
+ import {
2
+ readFileSync,
3
+ writeFileSync,
4
+ existsSync,
5
+ mkdirSync,
6
+ unlinkSync,
7
+ renameSync,
8
+ openSync,
9
+ closeSync,
10
+ } from "node:fs";
11
+ import { join } from "node:path";
12
+ import { homedir } from "node:os";
13
+
14
+ export interface AuthTokens {
15
+ access_token: string;
16
+ refresh_token: string;
17
+ expires_at: number;
18
+ user_email: string;
19
+ user_id: string;
20
+ server_url: string;
21
+ }
22
+
23
+ const AUTH_DIR = join(homedir(), ".failproofai");
24
+ const AUTH_FILE = join(AUTH_DIR, "auth.json");
25
+
26
+ function ensureAuthDir(): void {
27
+ if (!existsSync(AUTH_DIR)) mkdirSync(AUTH_DIR, { recursive: true, mode: 0o700 });
28
+ }
29
+
30
+ export function readTokens(): AuthTokens | null {
31
+ if (!existsSync(AUTH_FILE)) return null;
32
+ try {
33
+ const raw = readFileSync(AUTH_FILE, "utf8");
34
+ return JSON.parse(raw) as AuthTokens;
35
+ } catch {
36
+ return null;
37
+ }
38
+ }
39
+
40
+ /**
41
+ * Write tokens atomically with 0600 permissions *from creation*.
42
+ * We open with O_WRONLY|O_CREAT|O_TRUNC and explicit mode 0600 so the
43
+ * file is never world-readable, not even briefly during the write.
44
+ * Then rename into place (atomic on POSIX).
45
+ */
46
+ export function writeTokens(tokens: AuthTokens): void {
47
+ ensureAuthDir();
48
+ const tmpPath = `${AUTH_FILE}.tmp`;
49
+ const fd = openSync(tmpPath, "w", 0o600);
50
+ try {
51
+ writeFileSync(fd, JSON.stringify(tokens, null, 2));
52
+ } finally {
53
+ closeSync(fd);
54
+ }
55
+ renameSync(tmpPath, AUTH_FILE);
56
+ }
57
+
58
+ export function clearTokens(): void {
59
+ if (existsSync(AUTH_FILE)) unlinkSync(AUTH_FILE);
60
+ }
61
+
62
+ export function isLoggedIn(): boolean {
63
+ return existsSync(AUTH_FILE);
64
+ }
@@ -171,7 +171,7 @@ function getCurrentBranch(cwd: string): string | null {
171
171
  if (branch === undefined) {
172
172
  branch = execSync("git rev-parse --abbrev-ref HEAD", {
173
173
  cwd,
174
- encoding: "utf8",
174
+ encoding: "utf8", stdio: ["pipe", "pipe", "pipe"],
175
175
  timeout: 3000,
176
176
  }).trim();
177
177
  gitBranchCache.set(cwd, branch);
@@ -186,7 +186,7 @@ function getHeadSha(cwd: string): string | null {
186
186
  try {
187
187
  const sha = execSync("git rev-parse HEAD", {
188
188
  cwd,
189
- encoding: "utf8",
189
+ encoding: "utf8", stdio: ["pipe", "pipe", "pipe"],
190
190
  timeout: 3000,
191
191
  }).trim();
192
192
  return sha || null;
@@ -214,7 +214,7 @@ function getThirdPartyCheckRuns(cwd: string, sha: string): CiCheck[] {
214
214
  ],
215
215
  {
216
216
  cwd,
217
- encoding: "utf8",
217
+ encoding: "utf8", stdio: ["pipe", "pipe", "pipe"],
218
218
  timeout: 15000,
219
219
  },
220
220
  ).trim();
@@ -239,7 +239,7 @@ function getCommitStatuses(cwd: string, sha: string): CiCheck[] {
239
239
  ],
240
240
  {
241
241
  cwd,
242
- encoding: "utf8",
242
+ encoding: "utf8", stdio: ["pipe", "pipe", "pipe"],
243
243
  timeout: 15000,
244
244
  },
245
245
  ).trim();
@@ -676,7 +676,9 @@ function extractAbsolutePaths(command: string): string[] {
676
676
  }
677
677
 
678
678
  function blockReadOutsideCwd(ctx: PolicyContext): PolicyResult {
679
- const cwd = ctx.session?.cwd;
679
+ // Prefer $CLAUDE_PROJECT_DIR (stable project root) over ctx.session.cwd,
680
+ // which tracks the live shell CWD and drifts when Claude `cd`s into a subdir.
681
+ const cwd = process.env.CLAUDE_PROJECT_DIR || ctx.session?.cwd;
680
682
  if (!cwd) return allow(); // Can't enforce without cwd
681
683
 
682
684
  const allowPaths = ((ctx.params?.allowPaths ?? []) as string[]);
@@ -964,7 +966,7 @@ function requireCommitBeforeStop(ctx: PolicyContext): PolicyResult {
964
966
  try {
965
967
  const status = execSync("git status --porcelain", {
966
968
  cwd,
967
- encoding: "utf8",
969
+ encoding: "utf8", stdio: ["pipe", "pipe", "pipe"],
968
970
  timeout: 5000,
969
971
  }).trim();
970
972
 
@@ -986,7 +988,7 @@ function requirePushBeforeStop(ctx: PolicyContext): PolicyResult {
986
988
  try {
987
989
  const remotes = execSync("git remote", {
988
990
  cwd,
989
- encoding: "utf8",
991
+ encoding: "utf8", stdio: ["pipe", "pipe", "pipe"],
990
992
  timeout: 3000,
991
993
  }).trim();
992
994
 
@@ -1009,7 +1011,7 @@ function requirePushBeforeStop(ctx: PolicyContext): PolicyResult {
1009
1011
  const ahead = execFileSync(
1010
1012
  "git",
1011
1013
  ["log", `${remote}/${baseBranch}..HEAD`, "--oneline"],
1012
- { cwd, encoding: "utf8", timeout: 5000 },
1014
+ { cwd, encoding: "utf8", stdio: ["pipe", "pipe", "pipe"], timeout: 5000 },
1013
1015
  ).trim();
1014
1016
 
1015
1017
  if (!ahead) {
@@ -1022,7 +1024,7 @@ function requirePushBeforeStop(ctx: PolicyContext): PolicyResult {
1022
1024
  const diff = execFileSync(
1023
1025
  "git",
1024
1026
  ["diff", "--stat", `${remote}/${baseBranch}`, "HEAD"],
1025
- { cwd, encoding: "utf8", timeout: 5000 },
1027
+ { cwd, encoding: "utf8", stdio: ["pipe", "pipe", "pipe"], timeout: 5000 },
1026
1028
  ).trim();
1027
1029
 
1028
1030
  if (!diff) {
@@ -1037,7 +1039,7 @@ function requirePushBeforeStop(ctx: PolicyContext): PolicyResult {
1037
1039
  try {
1038
1040
  execFileSync("git", ["rev-parse", "--verify", `${remote}/${branch}`], {
1039
1041
  cwd,
1040
- encoding: "utf8",
1042
+ encoding: "utf8", stdio: ["pipe", "pipe", "pipe"],
1041
1043
  timeout: 3000,
1042
1044
  });
1043
1045
  hasTracking = true;
@@ -1055,7 +1057,7 @@ function requirePushBeforeStop(ctx: PolicyContext): PolicyResult {
1055
1057
  // Check for unpushed commits
1056
1058
  const unpushed = execFileSync("git", ["log", `${remote}/${branch}..HEAD`, "--oneline"], {
1057
1059
  cwd,
1058
- encoding: "utf8",
1060
+ encoding: "utf8", stdio: ["pipe", "pipe", "pipe"],
1059
1061
  timeout: 5000,
1060
1062
  }).trim();
1061
1063
 
@@ -1080,7 +1082,7 @@ function requirePrBeforeStop(ctx: PolicyContext): PolicyResult {
1080
1082
  try {
1081
1083
  // Check if gh CLI is available
1082
1084
  try {
1083
- execSync("gh --version", { cwd, encoding: "utf8", timeout: 3000 });
1085
+ execSync("gh --version", { cwd, encoding: "utf8", stdio: ["pipe", "pipe", "pipe"], timeout: 3000 });
1084
1086
  } catch {
1085
1087
  return allow("GitHub CLI (gh) not installed, skipping PR check.");
1086
1088
  }
@@ -1100,7 +1102,7 @@ function requirePrBeforeStop(ctx: PolicyContext): PolicyResult {
1100
1102
  const ahead = execFileSync(
1101
1103
  "git",
1102
1104
  ["log", `origin/${baseBranch}..HEAD`, "--oneline"],
1103
- { cwd, encoding: "utf8", timeout: 5000 },
1105
+ { cwd, encoding: "utf8", stdio: ["pipe", "pipe", "pipe"], timeout: 5000 },
1104
1106
  ).trim();
1105
1107
 
1106
1108
  if (!ahead) {
@@ -1113,7 +1115,7 @@ function requirePrBeforeStop(ctx: PolicyContext): PolicyResult {
1113
1115
  const diff = execFileSync(
1114
1116
  "git",
1115
1117
  ["diff", "--stat", `origin/${baseBranch}`, "HEAD"],
1116
- { cwd, encoding: "utf8", timeout: 5000 },
1118
+ { cwd, encoding: "utf8", stdio: ["pipe", "pipe", "pipe"], timeout: 5000 },
1117
1119
  ).trim();
1118
1120
 
1119
1121
  if (!diff) {
@@ -1128,7 +1130,7 @@ function requirePrBeforeStop(ctx: PolicyContext): PolicyResult {
1128
1130
  try {
1129
1131
  prJson = execSync("gh pr view --json number,url,state", {
1130
1132
  cwd,
1131
- encoding: "utf8",
1133
+ encoding: "utf8", stdio: ["pipe", "pipe", "pipe"],
1132
1134
  timeout: 15000,
1133
1135
  }).trim();
1134
1136
  } catch {
@@ -1151,13 +1153,13 @@ function requirePrBeforeStop(ctx: PolicyContext): PolicyResult {
1151
1153
  try {
1152
1154
  execFileSync("git", ["fetch", "origin", `+refs/heads/${baseBranch}:refs/remotes/origin/${baseBranch}`], {
1153
1155
  cwd,
1154
- encoding: "utf8",
1156
+ encoding: "utf8", stdio: ["pipe", "pipe", "pipe"],
1155
1157
  timeout: 10000,
1156
1158
  });
1157
1159
  const freshAhead = execFileSync(
1158
1160
  "git",
1159
1161
  ["log", `origin/${baseBranch}..HEAD`, "--oneline"],
1160
- { cwd, encoding: "utf8", timeout: 5000 },
1162
+ { cwd, encoding: "utf8", stdio: ["pipe", "pipe", "pipe"], timeout: 5000 },
1161
1163
  ).trim();
1162
1164
  if (!freshAhead) {
1163
1165
  return allow(`PR #${pr.number} was merged; branch is up to date with ${baseBranch}.`);
@@ -1165,7 +1167,7 @@ function requirePrBeforeStop(ctx: PolicyContext): PolicyResult {
1165
1167
  const freshDiff = execFileSync(
1166
1168
  "git",
1167
1169
  ["diff", "--stat", `origin/${baseBranch}`, "HEAD"],
1168
- { cwd, encoding: "utf8", timeout: 5000 },
1170
+ { cwd, encoding: "utf8", stdio: ["pipe", "pipe", "pipe"], timeout: 5000 },
1169
1171
  ).trim();
1170
1172
  if (!freshDiff) {
1171
1173
  return allow(`PR #${pr.number} was merged; no file changes vs ${baseBranch}.`);
@@ -1190,7 +1192,7 @@ function requireCiGreenBeforeStop(ctx: PolicyContext): PolicyResult {
1190
1192
  try {
1191
1193
  // Check if gh CLI is available
1192
1194
  try {
1193
- execSync("gh --version", { cwd, encoding: "utf8", timeout: 3000 });
1195
+ execSync("gh --version", { cwd, encoding: "utf8", stdio: ["pipe", "pipe", "pipe"], timeout: 3000 });
1194
1196
  } catch {
1195
1197
  return allow("GitHub CLI (gh) not installed, skipping CI check.");
1196
1198
  }
@@ -1204,7 +1206,7 @@ function requireCiGreenBeforeStop(ctx: PolicyContext): PolicyResult {
1204
1206
  const runsJson = execFileSync(
1205
1207
  "gh",
1206
1208
  ["run", "list", "--branch", branch, "--limit", "5", "--json", "status,conclusion,name"],
1207
- { cwd, encoding: "utf8", timeout: 15000 },
1209
+ { cwd, encoding: "utf8", stdio: ["pipe", "pipe", "pipe"], timeout: 15000 },
1208
1210
  ).trim();
1209
1211
 
1210
1212
  if (runsJson && runsJson !== "[]") {
@@ -148,26 +148,46 @@ export async function handleHookEvent(eventType: string): Promise<number> {
148
148
  }
149
149
 
150
150
  // Persist activity to disk (visible in /policies activity tab)
151
+ const activityEntry = {
152
+ timestamp: Date.now(),
153
+ eventType,
154
+ toolName: (parsed.tool_name as string) ?? null,
155
+ policyName: result.policyName,
156
+ policyNames: result.policyNames,
157
+ decision: result.decision,
158
+ reason: result.reason,
159
+ durationMs,
160
+ sessionId: session.sessionId,
161
+ transcriptPath: session.transcriptPath,
162
+ cwd: session.cwd,
163
+ permissionMode: session.permissionMode,
164
+ hookEventName: session.hookEventName,
165
+ };
151
166
  try {
152
- persistHookActivity({
153
- timestamp: Date.now(),
154
- eventType,
155
- toolName: (parsed.tool_name as string) ?? null,
156
- policyName: result.policyName,
157
- policyNames: result.policyNames,
158
- decision: result.decision,
159
- reason: result.reason,
160
- durationMs,
161
- sessionId: session.sessionId,
162
- transcriptPath: session.transcriptPath,
163
- cwd: session.cwd,
164
- permissionMode: session.permissionMode,
165
- hookEventName: session.hookEventName,
166
- });
167
+ persistHookActivity(activityEntry);
167
168
  } catch {
168
169
  hookLogWarn("activity persistence failed");
169
170
  }
170
171
 
172
+ // Enqueue for server relay — fire-and-forget, never blocks hook.
173
+ // queue.ts is a no-op if the user is not logged in (no auth.json), and
174
+ // sanitizes the entry before persisting (drops toolInput/transcriptPath,
175
+ // hashes cwd, redacts known secret patterns in `reason`).
176
+ try {
177
+ const { appendToServerQueue } = await import("../relay/queue");
178
+ appendToServerQueue(activityEntry);
179
+ } catch {
180
+ // Server queue is best-effort; fail-open
181
+ }
182
+
183
+ // Lazy-start relay daemon if user is logged in — ~1ms when already running
184
+ try {
185
+ const { ensureRelayRunning } = await import("../relay/daemon");
186
+ ensureRelayRunning();
187
+ } catch {
188
+ // Relay is best-effort; hook must succeed regardless
189
+ }
190
+
171
191
  // Fire PostHog telemetry for decisions that affect Claude's behavior
172
192
  if (result.decision === "deny" || result.decision === "instruct") {
173
193
  try {