envshed 0.18.0 → 0.19.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 (254) hide show
  1. package/README.md +1 -0
  2. package/bin/envshed.js +1 -1
  3. package/dist/agent/claude-code-hook.d.ts +9 -0
  4. package/dist/agent/claude-code-hook.d.ts.map +1 -0
  5. package/dist/agent/claude-code-hook.js +55 -0
  6. package/dist/agent/claude-code-hook.js.map +1 -0
  7. package/dist/agent/claude-code-hook.test.d.ts +2 -0
  8. package/dist/agent/claude-code-hook.test.d.ts.map +1 -0
  9. package/dist/agent/claude-code-hook.test.js +200 -0
  10. package/dist/agent/claude-code-hook.test.js.map +1 -0
  11. package/dist/agent/claude-code.d.ts +3 -0
  12. package/dist/agent/claude-code.d.ts.map +1 -0
  13. package/dist/agent/claude-code.js +206 -0
  14. package/dist/agent/claude-code.js.map +1 -0
  15. package/dist/agent/claude-code.test.d.ts +2 -0
  16. package/dist/agent/claude-code.test.d.ts.map +1 -0
  17. package/dist/agent/claude-code.test.js +302 -0
  18. package/dist/agent/claude-code.test.js.map +1 -0
  19. package/dist/agent/guard.d.ts +8 -0
  20. package/dist/agent/guard.d.ts.map +1 -0
  21. package/dist/agent/guard.js +357 -0
  22. package/dist/agent/guard.js.map +1 -0
  23. package/dist/agent/guard.test.d.ts +2 -0
  24. package/dist/agent/guard.test.d.ts.map +1 -0
  25. package/dist/agent/guard.test.js +263 -0
  26. package/dist/agent/guard.test.js.map +1 -0
  27. package/dist/agent/hook-main.d.ts +8 -0
  28. package/dist/agent/hook-main.d.ts.map +1 -0
  29. package/dist/agent/hook-main.js +45 -0
  30. package/dist/agent/hook-main.js.map +1 -0
  31. package/dist/agent/hook-messages.d.ts +7 -0
  32. package/dist/agent/hook-messages.d.ts.map +1 -0
  33. package/dist/agent/hook-messages.js +18 -0
  34. package/dist/agent/hook-messages.js.map +1 -0
  35. package/dist/agent/registry.d.ts +5 -0
  36. package/dist/agent/registry.d.ts.map +1 -0
  37. package/dist/agent/registry.js +6 -0
  38. package/dist/agent/registry.js.map +1 -0
  39. package/dist/agent/skill-content.d.ts +6 -0
  40. package/dist/agent/skill-content.d.ts.map +1 -0
  41. package/dist/agent/skill-content.js +62 -0
  42. package/dist/agent/skill-content.js.map +1 -0
  43. package/dist/agent/skill-content.test.d.ts +2 -0
  44. package/dist/agent/skill-content.test.d.ts.map +1 -0
  45. package/dist/agent/skill-content.test.js +15 -0
  46. package/dist/agent/skill-content.test.js.map +1 -0
  47. package/dist/agent/types.d.ts +35 -0
  48. package/dist/agent/types.d.ts.map +1 -0
  49. package/dist/agent/types.js +9 -0
  50. package/dist/agent/types.js.map +1 -0
  51. package/dist/commands/agent-session.d.ts +11 -0
  52. package/dist/commands/agent-session.d.ts.map +1 -0
  53. package/dist/commands/agent-session.js +300 -0
  54. package/dist/commands/agent-session.js.map +1 -0
  55. package/dist/commands/agent-session.test.d.ts +2 -0
  56. package/dist/commands/agent-session.test.d.ts.map +1 -0
  57. package/dist/commands/agent-session.test.js +381 -0
  58. package/dist/commands/agent-session.test.js.map +1 -0
  59. package/dist/commands/agent.d.ts +15 -0
  60. package/dist/commands/agent.d.ts.map +1 -0
  61. package/dist/commands/agent.js +114 -0
  62. package/dist/commands/agent.js.map +1 -0
  63. package/dist/commands/agent.test.d.ts +2 -0
  64. package/dist/commands/agent.test.d.ts.map +1 -0
  65. package/dist/commands/agent.test.js +132 -0
  66. package/dist/commands/agent.test.js.map +1 -0
  67. package/dist/commands/completions.d.ts.map +1 -1
  68. package/dist/commands/completions.js +37 -3
  69. package/dist/commands/completions.js.map +1 -1
  70. package/dist/commands/login.d.ts.map +1 -1
  71. package/dist/commands/login.js +42 -4
  72. package/dist/commands/login.js.map +1 -1
  73. package/dist/commands/login.test.js +55 -5
  74. package/dist/commands/login.test.js.map +1 -1
  75. package/dist/commands/pull.d.ts.map +1 -1
  76. package/dist/commands/pull.js +2 -1
  77. package/dist/commands/pull.js.map +1 -1
  78. package/dist/commands/request.d.ts +25 -0
  79. package/dist/commands/request.d.ts.map +1 -0
  80. package/dist/commands/request.js +157 -0
  81. package/dist/commands/request.js.map +1 -0
  82. package/dist/commands/request.test.d.ts +2 -0
  83. package/dist/commands/request.test.d.ts.map +1 -0
  84. package/dist/commands/request.test.js +177 -0
  85. package/dist/commands/request.test.js.map +1 -0
  86. package/dist/commands/run-redact.test.d.ts +2 -0
  87. package/dist/commands/run-redact.test.d.ts.map +1 -0
  88. package/dist/commands/run-redact.test.js +479 -0
  89. package/dist/commands/run-redact.test.js.map +1 -0
  90. package/dist/commands/run.d.ts +7 -1
  91. package/dist/commands/run.d.ts.map +1 -1
  92. package/dist/commands/run.js +169 -29
  93. package/dist/commands/run.js.map +1 -1
  94. package/dist/commands/run.test.js +214 -1
  95. package/dist/commands/run.test.js.map +1 -1
  96. package/dist/commands/scan.d.ts +9 -0
  97. package/dist/commands/scan.d.ts.map +1 -0
  98. package/dist/commands/scan.js +324 -0
  99. package/dist/commands/scan.js.map +1 -0
  100. package/dist/commands/scan.test.d.ts +2 -0
  101. package/dist/commands/scan.test.d.ts.map +1 -0
  102. package/dist/commands/scan.test.js +334 -0
  103. package/dist/commands/scan.test.js.map +1 -0
  104. package/dist/commands/token.d.ts.map +1 -1
  105. package/dist/commands/token.js +28 -11
  106. package/dist/commands/token.js.map +1 -1
  107. package/dist/commands/token.test.js +41 -7
  108. package/dist/commands/token.test.js.map +1 -1
  109. package/dist/commands/whoami.d.ts.map +1 -1
  110. package/dist/commands/whoami.js +8 -1
  111. package/dist/commands/whoami.js.map +1 -1
  112. package/dist/commands/whoami.test.js +16 -0
  113. package/dist/commands/whoami.test.js.map +1 -1
  114. package/dist/config-token.test.d.ts +2 -0
  115. package/dist/config-token.test.d.ts.map +1 -0
  116. package/dist/config-token.test.js +134 -0
  117. package/dist/config-token.test.js.map +1 -0
  118. package/dist/config.d.ts +16 -0
  119. package/dist/config.d.ts.map +1 -1
  120. package/dist/config.js +65 -3
  121. package/dist/config.js.map +1 -1
  122. package/dist/entry.d.ts +3 -0
  123. package/dist/entry.d.ts.map +1 -0
  124. package/dist/entry.js +15 -0
  125. package/dist/entry.js.map +1 -0
  126. package/dist/i18n.d.ts.map +1 -1
  127. package/dist/i18n.js +4 -16
  128. package/dist/i18n.js.map +1 -1
  129. package/dist/index.js +6 -0
  130. package/dist/index.js.map +1 -1
  131. package/dist/lib/agent-mode.d.ts +16 -0
  132. package/dist/lib/agent-mode.d.ts.map +1 -0
  133. package/dist/lib/agent-mode.js +24 -0
  134. package/dist/lib/agent-mode.js.map +1 -0
  135. package/dist/lib/agent-mode.test.d.ts +2 -0
  136. package/dist/lib/agent-mode.test.d.ts.map +1 -0
  137. package/dist/lib/agent-mode.test.js +35 -0
  138. package/dist/lib/agent-mode.test.js.map +1 -0
  139. package/dist/lib/agent-sessions.d.ts +37 -0
  140. package/dist/lib/agent-sessions.d.ts.map +1 -0
  141. package/dist/lib/agent-sessions.js +64 -0
  142. package/dist/lib/agent-sessions.js.map +1 -0
  143. package/dist/lib/allow-file.d.ts +21 -0
  144. package/dist/lib/allow-file.d.ts.map +1 -0
  145. package/dist/lib/allow-file.js +63 -0
  146. package/dist/lib/allow-file.js.map +1 -0
  147. package/dist/lib/allow-file.test.d.ts +2 -0
  148. package/dist/lib/allow-file.test.d.ts.map +1 -0
  149. package/dist/lib/allow-file.test.js +58 -0
  150. package/dist/lib/allow-file.test.js.map +1 -0
  151. package/dist/lib/command-spawn.d.ts +18 -0
  152. package/dist/lib/command-spawn.d.ts.map +1 -0
  153. package/dist/lib/command-spawn.js +46 -0
  154. package/dist/lib/command-spawn.js.map +1 -0
  155. package/dist/lib/command-spawn.test.d.ts +2 -0
  156. package/dist/lib/command-spawn.test.d.ts.map +1 -0
  157. package/dist/lib/command-spawn.test.js +46 -0
  158. package/dist/lib/command-spawn.test.js.map +1 -0
  159. package/dist/lib/duration.d.ts +3 -0
  160. package/dist/lib/duration.d.ts.map +1 -0
  161. package/dist/lib/duration.js +10 -0
  162. package/dist/lib/duration.js.map +1 -0
  163. package/dist/lib/duration.test.d.ts +2 -0
  164. package/dist/lib/duration.test.d.ts.map +1 -0
  165. package/dist/lib/duration.test.js +17 -0
  166. package/dist/lib/duration.test.js.map +1 -0
  167. package/dist/lib/env-format.d.ts +3 -0
  168. package/dist/lib/env-format.d.ts.map +1 -0
  169. package/dist/lib/env-format.js +20 -0
  170. package/dist/lib/env-format.js.map +1 -0
  171. package/dist/lib/history-clean.d.ts +42 -0
  172. package/dist/lib/history-clean.d.ts.map +1 -0
  173. package/dist/lib/history-clean.js +507 -0
  174. package/dist/lib/history-clean.js.map +1 -0
  175. package/dist/lib/history-clean.test.d.ts +2 -0
  176. package/dist/lib/history-clean.test.d.ts.map +1 -0
  177. package/dist/lib/history-clean.test.js +451 -0
  178. package/dist/lib/history-clean.test.js.map +1 -0
  179. package/dist/lib/history-scan.d.ts +108 -0
  180. package/dist/lib/history-scan.d.ts.map +1 -0
  181. package/dist/lib/history-scan.js +318 -0
  182. package/dist/lib/history-scan.js.map +1 -0
  183. package/dist/lib/history-scan.test.d.ts +2 -0
  184. package/dist/lib/history-scan.test.d.ts.map +1 -0
  185. package/dist/lib/history-scan.test.js +160 -0
  186. package/dist/lib/history-scan.test.js.map +1 -0
  187. package/dist/lib/keychain.d.ts +28 -0
  188. package/dist/lib/keychain.d.ts.map +1 -0
  189. package/dist/lib/keychain.js +87 -0
  190. package/dist/lib/keychain.js.map +1 -0
  191. package/dist/lib/keychain.test.d.ts +2 -0
  192. package/dist/lib/keychain.test.d.ts.map +1 -0
  193. package/dist/lib/keychain.test.js +128 -0
  194. package/dist/lib/keychain.test.js.map +1 -0
  195. package/dist/lib/locale-env.d.ts +3 -0
  196. package/dist/lib/locale-env.d.ts.map +1 -0
  197. package/dist/lib/locale-env.js +21 -0
  198. package/dist/lib/locale-env.js.map +1 -0
  199. package/dist/lib/oidc.d.ts +22 -0
  200. package/dist/lib/oidc.d.ts.map +1 -0
  201. package/dist/lib/oidc.js +84 -0
  202. package/dist/lib/oidc.js.map +1 -0
  203. package/dist/lib/oidc.test.d.ts +2 -0
  204. package/dist/lib/oidc.test.d.ts.map +1 -0
  205. package/dist/lib/oidc.test.js +107 -0
  206. package/dist/lib/oidc.test.js.map +1 -0
  207. package/dist/lib/redact.d.ts +60 -0
  208. package/dist/lib/redact.d.ts.map +1 -0
  209. package/dist/lib/redact.js +222 -0
  210. package/dist/lib/redact.js.map +1 -0
  211. package/dist/lib/redact.test.d.ts +2 -0
  212. package/dist/lib/redact.test.d.ts.map +1 -0
  213. package/dist/lib/redact.test.js +259 -0
  214. package/dist/lib/redact.test.js.map +1 -0
  215. package/dist/lib/redacted-output.d.ts +35 -0
  216. package/dist/lib/redacted-output.d.ts.map +1 -0
  217. package/dist/lib/redacted-output.js +155 -0
  218. package/dist/lib/redacted-output.js.map +1 -0
  219. package/dist/lib/secret-detector.d.ts +26 -0
  220. package/dist/lib/secret-detector.d.ts.map +1 -0
  221. package/dist/lib/secret-detector.js +332 -0
  222. package/dist/lib/secret-detector.js.map +1 -0
  223. package/dist/lib/secret-detector.test.d.ts +2 -0
  224. package/dist/lib/secret-detector.test.d.ts.map +1 -0
  225. package/dist/lib/secret-detector.test.js +207 -0
  226. package/dist/lib/secret-detector.test.js.map +1 -0
  227. package/dist/lib/shell-parse.d.ts +17 -0
  228. package/dist/lib/shell-parse.d.ts.map +1 -0
  229. package/dist/lib/shell-parse.js +191 -0
  230. package/dist/lib/shell-parse.js.map +1 -0
  231. package/dist/lib/shell-parse.test.d.ts +2 -0
  232. package/dist/lib/shell-parse.test.d.ts.map +1 -0
  233. package/dist/lib/shell-parse.test.js +41 -0
  234. package/dist/lib/shell-parse.test.js.map +1 -0
  235. package/dist/lib/token-input.d.ts +6 -0
  236. package/dist/lib/token-input.d.ts.map +1 -0
  237. package/dist/lib/token-input.js +42 -0
  238. package/dist/lib/token-input.js.map +1 -0
  239. package/dist/lib/token-input.test.d.ts +2 -0
  240. package/dist/lib/token-input.test.d.ts.map +1 -0
  241. package/dist/lib/token-input.test.js +38 -0
  242. package/dist/lib/token-input.test.js.map +1 -0
  243. package/dist/locales/en.json +222 -6
  244. package/dist/locales/es.json +219 -3
  245. package/dist/locales/pt-BR.json +219 -3
  246. package/dist/utils.d.ts +1 -1
  247. package/dist/utils.d.ts.map +1 -1
  248. package/dist/utils.js +5 -24
  249. package/dist/utils.js.map +1 -1
  250. package/dist/utils.test.js +14 -0
  251. package/dist/utils.test.js.map +1 -1
  252. package/package.json +5 -3
  253. package/dist/bin/envshed-linux-x64 +0 -4
  254. package/dist/bundle.cjs +0 -48909
@@ -0,0 +1 @@
1
+ {"version":3,"file":"guard.test.js","sourceRoot":"","sources":["../../src/agent/guard.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE5D,MAAM,IAAI,GAAG,cAAc,CAAC,EAAE,CAAC,CAAC;AAChC,MAAM,IAAI,GAAG,CAAC,OAAe,EAAE,KAAK,GAAG,IAAI,EAAE,EAAE,CAAC,eAAe,CAAC,MAAM,EAAE,EAAE,OAAO,EAAE,EAAE,KAAK,CAAC,CAAC;AAE5F,QAAQ,CAAC,oCAAoC,EAAE,GAAG,EAAE;IAClD,EAAE,CAAC,IAAI,CAAC;QACN,CAAC,4BAA4B,EAAE,YAAY,CAAC;QAC5C,CAAC,kDAAkD,EAAE,YAAY,CAAC;QAClE,CAAC,gCAAgC,EAAE,YAAY,CAAC;QAChD,CAAC,0CAA0C,EAAE,YAAY,CAAC;QAC1D,CAAC,sCAAsC,EAAE,YAAY,CAAC;QACtD,CAAC,oCAAoC,EAAE,YAAY,CAAC;QACpD,CAAC,iDAAiD,EAAE,YAAY,CAAC;QACjE,CAAC,wCAAwC,EAAE,YAAY,CAAC;QACxD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AAC,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACzC,CAAC,CAAC,CAAC;IACH,EAAE,CAAC,IAAI,CAAC,CAAC,cAAc,EAAE,aAAa,EAAE,eAAe,EAAE,WAAW,EAAE,aAAa,EAAE,eAAe,EAAE,gBAAgB,EAAE,QAAQ,EAAE,aAAa,EAAE,iBAAiB,CAAC,CAAC,CAClK,WAAW,EACX,CAAC,IAAI,EAAE,EAAE;QACP,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC1C,CAAC,CACF,CAAC;AACJ,CAAC,CAAC,CAAC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Entry point of `envshed agent hook <event>`. Any failure must not lock the user
3
+ * out of their agent, so it ends in exit 1 with one line on stderr: Claude Code
4
+ * treats that as a non-blocking error and shows the line. The error itself is
5
+ * never printed, because a JSON parse error can quote the prompt it failed on.
6
+ */
7
+ export declare function runHookCli(eventName: string | undefined): Promise<void>;
8
+ //# sourceMappingURL=hook-main.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hook-main.d.ts","sourceRoot":"","sources":["../../src/agent/hook-main.ts"],"names":[],"mappings":"AA2BA;;;;;GAKG;AACH,wBAAsB,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,CAW7E"}
@@ -0,0 +1,45 @@
1
+ import { handleClaudeCodeHook } from "./claude-code-hook.js";
2
+ import { createHookTranslator } from "./hook-messages.js";
3
+ const STDIN_TIMEOUT_MS = 5_000;
4
+ function readStdin() {
5
+ return new Promise((resolve, reject) => {
6
+ const chunks = [];
7
+ const timer = setTimeout(() => reject(new Error("stdin timeout")), STDIN_TIMEOUT_MS);
8
+ timer.unref();
9
+ process.stdin.on("data", (chunk) => chunks.push(chunk));
10
+ process.stdin.on("end", () => {
11
+ clearTimeout(timer);
12
+ resolve(Buffer.concat(chunks).toString("utf-8"));
13
+ });
14
+ process.stdin.on("error", reject);
15
+ });
16
+ }
17
+ function failOpenNote() {
18
+ try {
19
+ return createHookTranslator()("failOpen");
20
+ }
21
+ catch {
22
+ return "envshed: agent hook failed; this action was not checked.";
23
+ }
24
+ }
25
+ /**
26
+ * Entry point of `envshed agent hook <event>`. Any failure must not lock the user
27
+ * out of their agent, so it ends in exit 1 with one line on stderr: Claude Code
28
+ * treats that as a non-blocking error and shows the line. The error itself is
29
+ * never printed, because a JSON parse error can quote the prompt it failed on.
30
+ */
31
+ export async function runHookCli(eventName) {
32
+ try {
33
+ const output = handleClaudeCodeHook(eventName, await readStdin());
34
+ if (output)
35
+ process.stdout.write(output);
36
+ process.exitCode = 0;
37
+ }
38
+ catch {
39
+ process.stderr.write(`${failOpenNote()}\n`);
40
+ process.exitCode = 1;
41
+ }
42
+ // A stdin that never closes would otherwise keep the process alive.
43
+ process.stdin.destroy();
44
+ }
45
+ //# sourceMappingURL=hook-main.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hook-main.js","sourceRoot":"","sources":["../../src/agent/hook-main.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAE1D,MAAM,gBAAgB,GAAG,KAAK,CAAC;AAE/B,SAAS,SAAS;IAChB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,MAAM,MAAM,GAAa,EAAE,CAAC;QAC5B,MAAM,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,eAAe,CAAC,CAAC,EAAE,gBAAgB,CAAC,CAAC;QACrF,KAAK,CAAC,KAAK,EAAE,CAAC;QACd,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,KAAa,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;QAChE,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE;YAC3B,YAAY,CAAC,KAAK,CAAC,CAAC;YACpB,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC;QACnD,CAAC,CAAC,CAAC;QACH,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IACpC,CAAC,CAAC,CAAC;AACL,CAAC;AAED,SAAS,YAAY;IACnB,IAAI,CAAC;QACH,OAAO,oBAAoB,EAAE,CAAC,UAAU,CAAC,CAAC;IAC5C,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,0DAA0D,CAAC;IACpE,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,SAA6B;IAC5D,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,oBAAoB,CAAC,SAAS,EAAE,MAAM,SAAS,EAAE,CAAC,CAAC;QAClE,IAAI,MAAM;YAAE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QACzC,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;IACvB,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,YAAY,EAAE,IAAI,CAAC,CAAC;QAC5C,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;IACvB,CAAC;IACD,oEAAoE;IACpE,OAAO,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;AAC1B,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Translations for the hook path. It skips i18n.ts on purpose: that module reads
3
+ * ~/.envshed/config.json, which holds the token, and hooks must not touch it.
4
+ * The locale therefore comes from LC_ALL or LANG only.
5
+ */
6
+ export declare function createHookTranslator(env?: NodeJS.ProcessEnv): (key: string, values?: Record<string, string>) => string;
7
+ //# sourceMappingURL=hook-messages.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hook-messages.d.ts","sourceRoot":"","sources":["../../src/agent/hook-messages.ts"],"names":[],"mappings":"AAUA;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,GAAE,MAAM,CAAC,UAAwB,IAI/D,KAAK,MAAM,EAAE,SAAQ,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,YAEzD"}
@@ -0,0 +1,18 @@
1
+ import fs from "node:fs";
2
+ import { localeFromEnv } from "../lib/locale-env.js";
3
+ function loadMessages(locale) {
4
+ const url = new URL(`../locales/${locale}.json`, import.meta.url);
5
+ return JSON.parse(fs.readFileSync(url, "utf-8")).agentHook ?? {};
6
+ }
7
+ /**
8
+ * Translations for the hook path. It skips i18n.ts on purpose: that module reads
9
+ * ~/.envshed/config.json, which holds the token, and hooks must not touch it.
10
+ * The locale therefore comes from LC_ALL or LANG only.
11
+ */
12
+ export function createHookTranslator(env = process.env) {
13
+ const locale = localeFromEnv(env) ?? "en";
14
+ const english = loadMessages("en");
15
+ const messages = locale === "en" ? english : { ...english, ...loadMessages(locale) };
16
+ return (key, values = {}) => (messages[key] ?? key).replace(/\{\{(\w+)\}\}/g, (_, name) => values[name] ?? "");
17
+ }
18
+ //# sourceMappingURL=hook-messages.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hook-messages.js","sourceRoot":"","sources":["../../src/agent/hook-messages.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAIrD,SAAS,YAAY,CAAC,MAAc;IAClC,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,cAAc,MAAM,OAAO,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAClE,OAAO,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC,SAAS,IAAI,EAAE,CAAC;AACnE,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,oBAAoB,CAAC,MAAyB,OAAO,CAAC,GAAG;IACvE,MAAM,MAAM,GAAG,aAAa,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC;IAC1C,MAAM,OAAO,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC;IACnC,MAAM,QAAQ,GAAG,MAAM,KAAK,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,GAAG,OAAO,EAAE,GAAG,YAAY,CAAC,MAAM,CAAC,EAAE,CAAC;IACrF,OAAO,CAAC,GAAW,EAAE,SAAiC,EAAE,EAAE,EAAE,CAC1D,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,CAAC,OAAO,CAAC,gBAAgB,EAAE,CAAC,CAAC,EAAE,IAAY,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;AAC9F,CAAC"}
@@ -0,0 +1,5 @@
1
+ import type { AgentAdapter } from "./types.js";
2
+ export declare const DEFAULT_AGENT: string;
3
+ export declare const agentIds: () => string[];
4
+ export declare const findAgent: (id: string) => AgentAdapter | undefined;
5
+ //# sourceMappingURL=registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/agent/registry.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAI/C,eAAO,MAAM,aAAa,QAAuB,CAAC;AAClD,eAAO,MAAM,QAAQ,gBAA8C,CAAC;AACpE,eAAO,MAAM,SAAS,GAAI,IAAI,MAAM,6BAAkD,CAAC"}
@@ -0,0 +1,6 @@
1
+ import { claudeCodeAdapter } from "./claude-code.js";
2
+ const ADAPTERS = [claudeCodeAdapter];
3
+ export const DEFAULT_AGENT = claudeCodeAdapter.id;
4
+ export const agentIds = () => ADAPTERS.map((adapter) => adapter.id);
5
+ export const findAgent = (id) => ADAPTERS.find((adapter) => adapter.id === id);
6
+ //# sourceMappingURL=registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/agent/registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAGrD,MAAM,QAAQ,GAAmB,CAAC,iBAAiB,CAAC,CAAC;AAErD,MAAM,CAAC,MAAM,aAAa,GAAG,iBAAiB,CAAC,EAAE,CAAC;AAClD,MAAM,CAAC,MAAM,QAAQ,GAAG,GAAG,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;AACpE,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,EAAU,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC"}
@@ -0,0 +1,6 @@
1
+ /** Lives apart from the general `envshed` skill, so installing never overwrites it. */
2
+ export declare const SKILL_NAME = "envshed-agent-safety";
3
+ /** Files without this marker are not ours: install and uninstall leave them alone. */
4
+ export declare const SKILL_MARKER = "<!-- managed by envshed agent install -->";
5
+ export declare const SKILL_CONTENT = "---\nname: envshed-agent-safety\ndescription: Rules for handling secrets in projects that use Envshed. Use whenever a task needs an API key, password, token or other credential, or touches environment variables or .env files.\n---\n\n<!-- managed by envshed agent install -->\n\n# Handling secrets with Envshed\n\nValues you see end up in the chat history and at the model provider. Work so that you never see them.\n\n## Rules\n\n- Never ask anyone to paste a secret into the chat. If one is missing, ask for it through Envshed, so a person enters the value in the dashboard.\n- Never print a secret value, and never put one in a command line, a tool argument, a file, a commit or your reply.\n- To use secrets at runtime, inject them: `envshed run -- <command>` in a shell, or the `@envshed/node` SDK inside your own tool, so the model sees only the result.\n- If a value reached the chat, tell the user at once. It needs rotating, which is their step.\n- A block or a refusal is not an obstacle to work around. Do what the message says, and if it looks wrong, tell the user.\n- Do not run `envshed secret get`, `envshed pull --stdout`, `envshed diff --show-values` or `envshed share open` without `--file`.\n- Do not read `.env` files or anything under `~/.envshed/`. `.env.example` is fine.\n- Do not run `envshed run -- printenv`, `envshed run -- env` or anything else that prints the injected environment.\n\n## Using a secret\n\nRun the program with the secrets injected. It gets the values and you do not:\n\n```bash\nenvshed run -e development -- npm test\n```\n\n## When a secret is missing\n\nAsk for it. If the key already exists, the command says so and changes nothing. Otherwise a person fills it in the dashboard, and the value never passes through this session:\n\n```bash\nenvshed request GITHUB_PAT --reason \"configure the runner\" -e development --no-wait\n```\n\nShell tools limit how long a command can run, so do not sit in a long wait:\n\n1. Run it with `--no-wait`, or in the background, so the tool does not time out.\n2. Tell the user who can fill it and give them the printed link.\n3. Run the same command again to check. An open request is reused, not duplicated.\n\nExit codes: `0` ready, `2` still pending, `3` declined, `4` timed out, `5` unusable, `1` error. Add `--output json` to read the status from a script. Do not retry after a decline: talk to the user.\n\n## When a secret may have leaked\n\nIf a value reached this chat, tell the user at once. It needs rotating, which is their step. `envshed scan` reports which keys appear in agent histories, by name only, and marks them as exposed. Do not run `envshed scan --clean` or `--undo` unless the user asks.\n\n## When a hook blocks you\n\nEnvshed hooks may stop a command or a prompt. Do not look for another way to reach the value. Do what the message says, usually `envshed run` or `envshed request`. If the block looks wrong, tell the user: exceptions in `.envshed-allow` are their decision, and that file holds patterns, never values.\n\nThese hooks prevent accidents. They are not a security boundary, and working around them is still a leak.\n";
6
+ //# sourceMappingURL=skill-content.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"skill-content.d.ts","sourceRoot":"","sources":["../../src/agent/skill-content.ts"],"names":[],"mappings":"AAAA,uFAAuF;AACvF,eAAO,MAAM,UAAU,yBAAyB,CAAC;AAEjD,sFAAsF;AACtF,eAAO,MAAM,YAAY,8CAA8C,CAAC;AAGxE,eAAO,MAAM,aAAa,ykGAuDzB,CAAC"}
@@ -0,0 +1,62 @@
1
+ /** Lives apart from the general `envshed` skill, so installing never overwrites it. */
2
+ export const SKILL_NAME = "envshed-agent-safety";
3
+ /** Files without this marker are not ours: install and uninstall leave them alone. */
4
+ export const SKILL_MARKER = "<!-- managed by envshed agent install -->";
5
+ // Instructions for the agent itself, so they stay in English and are not translated.
6
+ export const SKILL_CONTENT = `---
7
+ name: ${SKILL_NAME}
8
+ description: Rules for handling secrets in projects that use Envshed. Use whenever a task needs an API key, password, token or other credential, or touches environment variables or .env files.
9
+ ---
10
+
11
+ ${SKILL_MARKER}
12
+
13
+ # Handling secrets with Envshed
14
+
15
+ Values you see end up in the chat history and at the model provider. Work so that you never see them.
16
+
17
+ ## Rules
18
+
19
+ - Never ask anyone to paste a secret into the chat. If one is missing, ask for it through Envshed, so a person enters the value in the dashboard.
20
+ - Never print a secret value, and never put one in a command line, a tool argument, a file, a commit or your reply.
21
+ - To use secrets at runtime, inject them: \`envshed run -- <command>\` in a shell, or the \`@envshed/node\` SDK inside your own tool, so the model sees only the result.
22
+ - If a value reached the chat, tell the user at once. It needs rotating, which is their step.
23
+ - A block or a refusal is not an obstacle to work around. Do what the message says, and if it looks wrong, tell the user.
24
+ - Do not run \`envshed secret get\`, \`envshed pull --stdout\`, \`envshed diff --show-values\` or \`envshed share open\` without \`--file\`.
25
+ - Do not read \`.env\` files or anything under \`~/.envshed/\`. \`.env.example\` is fine.
26
+ - Do not run \`envshed run -- printenv\`, \`envshed run -- env\` or anything else that prints the injected environment.
27
+
28
+ ## Using a secret
29
+
30
+ Run the program with the secrets injected. It gets the values and you do not:
31
+
32
+ \`\`\`bash
33
+ envshed run -e development -- npm test
34
+ \`\`\`
35
+
36
+ ## When a secret is missing
37
+
38
+ Ask for it. If the key already exists, the command says so and changes nothing. Otherwise a person fills it in the dashboard, and the value never passes through this session:
39
+
40
+ \`\`\`bash
41
+ envshed request GITHUB_PAT --reason "configure the runner" -e development --no-wait
42
+ \`\`\`
43
+
44
+ Shell tools limit how long a command can run, so do not sit in a long wait:
45
+
46
+ 1. Run it with \`--no-wait\`, or in the background, so the tool does not time out.
47
+ 2. Tell the user who can fill it and give them the printed link.
48
+ 3. Run the same command again to check. An open request is reused, not duplicated.
49
+
50
+ Exit codes: \`0\` ready, \`2\` still pending, \`3\` declined, \`4\` timed out, \`5\` unusable, \`1\` error. Add \`--output json\` to read the status from a script. Do not retry after a decline: talk to the user.
51
+
52
+ ## When a secret may have leaked
53
+
54
+ If a value reached this chat, tell the user at once. It needs rotating, which is their step. \`envshed scan\` reports which keys appear in agent histories, by name only, and marks them as exposed. Do not run \`envshed scan --clean\` or \`--undo\` unless the user asks.
55
+
56
+ ## When a hook blocks you
57
+
58
+ Envshed hooks may stop a command or a prompt. Do not look for another way to reach the value. Do what the message says, usually \`envshed run\` or \`envshed request\`. If the block looks wrong, tell the user: exceptions in \`.envshed-allow\` are their decision, and that file holds patterns, never values.
59
+
60
+ These hooks prevent accidents. They are not a security boundary, and working around them is still a leak.
61
+ `;
62
+ //# sourceMappingURL=skill-content.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"skill-content.js","sourceRoot":"","sources":["../../src/agent/skill-content.ts"],"names":[],"mappings":"AAAA,uFAAuF;AACvF,MAAM,CAAC,MAAM,UAAU,GAAG,sBAAsB,CAAC;AAEjD,sFAAsF;AACtF,MAAM,CAAC,MAAM,YAAY,GAAG,2CAA2C,CAAC;AAExE,qFAAqF;AACrF,MAAM,CAAC,MAAM,aAAa,GAAG;QACrB,UAAU;;;;EAIhB,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkDb,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=skill-content.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"skill-content.test.d.ts","sourceRoot":"","sources":["../../src/agent/skill-content.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,15 @@
1
+ import { readFileSync } from "node:fs";
2
+ import { describe, expect, it } from "vitest";
3
+ import { SKILL_CONTENT } from "./skill-content.js";
4
+ // The CLI does not depend on @envshed/shared, so this reads the source of the rules.
5
+ const source = readFileSync(new URL("../../../../packages/shared/src/agent-guidance.ts", import.meta.url), "utf-8");
6
+ const rules = [...source.matchAll(/^ {2}"(.+)",$/gm)].map((match) => match[1]);
7
+ describe("skill content", () => {
8
+ it("finds the shared rules", () => {
9
+ expect(rules.length).toBeGreaterThan(0);
10
+ });
11
+ it.each(rules)("carries the shared rule: %s", (rule) => {
12
+ expect(SKILL_CONTENT).toContain(`- ${rule}`);
13
+ });
14
+ });
15
+ //# sourceMappingURL=skill-content.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"skill-content.test.js","sourceRoot":"","sources":["../../src/agent/skill-content.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,qFAAqF;AACrF,MAAM,MAAM,GAAG,YAAY,CAAC,IAAI,GAAG,CAAC,mDAAmD,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC,CAAC;AACpH,MAAM,KAAK,GAAG,CAAC,GAAG,MAAM,CAAC,QAAQ,CAAC,iBAAiB,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;AAE/E,QAAQ,CAAC,eAAe,EAAE,GAAG,EAAE;IAC7B,EAAE,CAAC,wBAAwB,EAAE,GAAG,EAAE;QAChC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;IAC1C,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,6BAA6B,EAAE,CAAC,IAAI,EAAE,EAAE;QACrD,MAAM,CAAC,aAAa,CAAC,CAAC,SAAS,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC;IAC/C,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,35 @@
1
+ export type AgentScope = "user" | "project";
2
+ export type ChangeStatus = "added" | "updated" | "unchanged" | "removed" | "absent" | "skipped-foreign";
3
+ export interface AgentContext {
4
+ scope: AgentScope;
5
+ /** Directory the project scope resolves against. */
6
+ cwd: string;
7
+ home: string;
8
+ env: NodeJS.ProcessEnv;
9
+ /** How hooks call this CLI, for example `envshed`. */
10
+ cliCommand: string;
11
+ }
12
+ export interface InstallReport {
13
+ settingsPath: string;
14
+ skillPath: string;
15
+ hooks: Array<{
16
+ event: string;
17
+ status: ChangeStatus;
18
+ }>;
19
+ skill: ChangeStatus;
20
+ }
21
+ /** One coding agent. Add a module implementing this and register it in `registry.ts`. */
22
+ export interface AgentAdapter {
23
+ id: string;
24
+ displayName: string;
25
+ install(context: AgentContext): InstallReport;
26
+ uninstall(context: AgentContext): InstallReport;
27
+ /** Where this agent keeps its local history, for `envshed scan`. */
28
+ historyRoots(context: Pick<AgentContext, "home" | "env">): string[];
29
+ }
30
+ /** The agent's settings file cannot be merged safely. It was left untouched. */
31
+ export declare class AgentSettingsError extends Error {
32
+ readonly settingsPath: string;
33
+ constructor(settingsPath: string);
34
+ }
35
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/agent/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,SAAS,CAAC;AAE5C,MAAM,MAAM,YAAY,GAAG,OAAO,GAAG,SAAS,GAAG,WAAW,GAAG,SAAS,GAAG,QAAQ,GAAG,iBAAiB,CAAC;AAExG,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,UAAU,CAAC;IAClB,oDAAoD;IACpD,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC,UAAU,CAAC;IACvB,sDAAsD;IACtD,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,aAAa;IAC5B,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,KAAK,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,YAAY,CAAA;KAAE,CAAC,CAAC;IACtD,KAAK,EAAE,YAAY,CAAC;CACrB;AAED,yFAAyF;AACzF,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,OAAO,EAAE,YAAY,GAAG,aAAa,CAAC;IAC9C,SAAS,CAAC,OAAO,EAAE,YAAY,GAAG,aAAa,CAAC;IAChD,oEAAoE;IACpE,YAAY,CAAC,OAAO,EAAE,IAAI,CAAC,YAAY,EAAE,MAAM,GAAG,KAAK,CAAC,GAAG,MAAM,EAAE,CAAC;CACrE;AAED,gFAAgF;AAChF,qBAAa,kBAAmB,SAAQ,KAAK;aACf,YAAY,EAAE,MAAM;gBAApB,YAAY,EAAE,MAAM;CAGjD"}
@@ -0,0 +1,9 @@
1
+ /** The agent's settings file cannot be merged safely. It was left untouched. */
2
+ export class AgentSettingsError extends Error {
3
+ settingsPath;
4
+ constructor(settingsPath) {
5
+ super(settingsPath);
6
+ this.settingsPath = settingsPath;
7
+ }
8
+ }
9
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/agent/types.ts"],"names":[],"mappings":"AA+BA,gFAAgF;AAChF,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IACf;IAA5B,YAA4B,YAAoB;QAC9C,KAAK,CAAC,YAAY,CAAC,CAAC;QADM,iBAAY,GAAZ,YAAY,CAAQ;IAEhD,CAAC;CACF"}
@@ -0,0 +1,11 @@
1
+ import { Command } from "commander";
2
+ /** Agents branch on these, so they are part of the command's contract. Same style as `request`. */
3
+ export declare const AGENT_SESSION_EXIT: {
4
+ readonly active: 0;
5
+ readonly error: 1;
6
+ readonly pending: 2;
7
+ readonly declined: 3;
8
+ readonly timeout: 4;
9
+ };
10
+ export declare const agentSessionCommand: Command;
11
+ //# sourceMappingURL=agent-session.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-session.d.ts","sourceRoot":"","sources":["../../src/commands/agent-session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAWpC,mGAAmG;AACnG,eAAO,MAAM,kBAAkB;;;;;;CAMrB,CAAC;AA0IX,eAAO,MAAM,mBAAmB,SAiL5B,CAAC"}
@@ -0,0 +1,300 @@
1
+ import { Command } from "commander";
2
+ import chalk from "chalk";
3
+ import ora from "ora";
4
+ import Table from "cli-table3";
5
+ import { apiGet, apiPost } from "../api.js";
6
+ import { getApiUrl, getToken, hasProjectConfig, logContext, resolveOpts } from "../config.js";
7
+ import { t } from "../i18n.js";
8
+ import { parseDurationSeconds } from "../lib/duration.js";
9
+ import { readLocalSessions, removeLocalSession, saveLocalSession } from "../lib/agent-sessions.js";
10
+ import { pollStatus } from "./request.js";
11
+ /** Agents branch on these, so they are part of the command's contract. Same style as `request`. */
12
+ export const AGENT_SESSION_EXIT = {
13
+ active: 0,
14
+ error: 1,
15
+ pending: 2,
16
+ declined: 3,
17
+ timeout: 4,
18
+ };
19
+ const SECRET_KEY_REGEX = /^[A-Za-z_][A-Za-z0-9_]*$/;
20
+ const MAX_TTL_SECONDS = 24 * 60 * 60;
21
+ const MIN_TTL_SECONDS = 60;
22
+ const POLL_INTERVAL_MS = 3_000;
23
+ const MAX_POLL_INTERVAL_MS = 30_000;
24
+ const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
25
+ /** Which agent this is, for the audit log. Self-reported, so never treated as an identity check. */
26
+ function detectAgentName(flag) {
27
+ if (flag)
28
+ return flag;
29
+ if (process.env.ENVSHED_AGENT_NAME)
30
+ return process.env.ENVSHED_AGENT_NAME;
31
+ if (process.env.CLAUDECODE)
32
+ return "claude-code";
33
+ return "cli";
34
+ }
35
+ function parseKeys(raw) {
36
+ if (raw === undefined)
37
+ return undefined;
38
+ const keys = raw.split(",").map((k) => k.trim()).filter(Boolean);
39
+ if (keys.length === 0 || keys.some((k) => !SECRET_KEY_REGEX.test(k)))
40
+ return null;
41
+ return keys;
42
+ }
43
+ const listCommand = new Command("list")
44
+ .description(t("agentSession.listDescription"))
45
+ .option("-o, --org <slug>", t("common.orgOption"))
46
+ .option("--output <format>", t("output.jsonOption"))
47
+ .action(async (_opts, command) => {
48
+ const opts = command.optsWithGlobals();
49
+ const { org } = resolveOpts(opts);
50
+ if (!org) {
51
+ console.error(chalk.red(t("agentSession.missingOrg")));
52
+ process.exit(AGENT_SESSION_EXIT.error);
53
+ }
54
+ const json = opts.output === "json";
55
+ const spinner = ora({ text: t("agentSession.fetching"), isSilent: json }).start();
56
+ try {
57
+ const res = await apiGet(`/agent-sessions/${org}`);
58
+ const { sessions } = (await res.json());
59
+ spinner.stop();
60
+ if (json) {
61
+ console.log(JSON.stringify(sessions, null, 2));
62
+ return;
63
+ }
64
+ if (sessions.length === 0) {
65
+ console.log(chalk.dim(t("agentSession.noSessions")));
66
+ return;
67
+ }
68
+ const table = new Table({
69
+ head: [
70
+ t("agentSession.headId"),
71
+ t("agentSession.headAgent"),
72
+ t("agentSession.headEnv"),
73
+ t("agentSession.headKeys"),
74
+ t("agentSession.headExpires"),
75
+ t("agentSession.headCreatedBy"),
76
+ ],
77
+ });
78
+ for (const s of sessions) {
79
+ table.push([
80
+ s.id,
81
+ s.agentName ?? "",
82
+ `${s.project}/${s.env}`,
83
+ s.allowedKeys ? s.allowedKeys.join(", ") : t("agentSession.allKeys"),
84
+ new Date(s.expiresAt).toLocaleString(),
85
+ s.createdBy,
86
+ ]);
87
+ }
88
+ console.log(table.toString());
89
+ }
90
+ catch (err) {
91
+ spinner.stop();
92
+ console.error(chalk.red(t("agentSession.failed", { message: err.message })));
93
+ process.exit(AGENT_SESSION_EXIT.error);
94
+ }
95
+ });
96
+ const revokeCommand = new Command("revoke")
97
+ .description(t("agentSession.revokeDescription"))
98
+ .argument("<id>", t("agentSession.idArg"))
99
+ .option("-o, --org <slug>", t("common.orgOption"))
100
+ .action(async (id, _opts, command) => {
101
+ const opts = command.optsWithGlobals();
102
+ const local = readLocalSessions().find((s) => s.id === id);
103
+ const org = opts.org ?? local?.org ?? resolveOpts(opts).org;
104
+ if (!org) {
105
+ console.error(chalk.red(t("agentSession.missingOrg")));
106
+ process.exit(AGENT_SESSION_EXIT.error);
107
+ }
108
+ try {
109
+ const res = await fetch(`${getApiUrl()}/api/v1/agent-sessions/${org}/sessions/${id}`, {
110
+ method: "DELETE",
111
+ headers: { Authorization: `Bearer ${getToken()}` },
112
+ });
113
+ // Gone on the server means revoked as far as anyone can tell: clear the local copy.
114
+ if (res.status === 404 && local) {
115
+ removeLocalSession(id);
116
+ console.log(chalk.yellow(t("agentSession.clearedLocal", { id })));
117
+ return;
118
+ }
119
+ if (!res.ok) {
120
+ const body = (await res.json().catch(() => ({})));
121
+ throw new Error(body.error ?? `HTTP ${res.status}`);
122
+ }
123
+ removeLocalSession(id);
124
+ console.log(chalk.green(t("agentSession.revoked", { id })));
125
+ }
126
+ catch (err) {
127
+ console.error(chalk.red(t("agentSession.failed", { message: err.message })));
128
+ process.exit(AGENT_SESSION_EXIT.error);
129
+ }
130
+ });
131
+ export const agentSessionCommand = new Command("session")
132
+ .description(t("agentSession.description"))
133
+ // Commander gives -o and --output to this command even when they follow `list`,
134
+ // so its subcommands read them with optsWithGlobals().
135
+ .option("-o, --org <slug>", t("common.orgOption"))
136
+ .option("-p, --project <slug>", t("common.projectOption"))
137
+ .option("-e, --env <slug>", t("common.envOption"))
138
+ .option("--ttl <duration>", t("agentSession.ttlOption"), "1h")
139
+ .option("--keys <list>", t("agentSession.keysOption"))
140
+ .option("--agent <name>", t("agentSession.agentOption"))
141
+ .option("--reason <text>", t("agentSession.reasonOption"))
142
+ .option("--timeout <duration>", t("agentSession.timeoutOption"), "10m")
143
+ .option("--no-wait", t("agentSession.noWaitOption"))
144
+ .option("--output <format>", t("output.jsonOption"))
145
+ .addCommand(listCommand)
146
+ .addCommand(revokeCommand)
147
+ .action(async (opts) => {
148
+ const json = opts.output === "json";
149
+ const fail = (message) => {
150
+ console.error(chalk.red(message));
151
+ process.exit(AGENT_SESSION_EXIT.error);
152
+ };
153
+ const ttlSeconds = parseDurationSeconds(opts.ttl);
154
+ if (ttlSeconds === null)
155
+ return fail(t("agentSession.invalidTtl", { value: opts.ttl }));
156
+ if (ttlSeconds < MIN_TTL_SECONDS || ttlSeconds > MAX_TTL_SECONDS) {
157
+ return fail(t("agentSession.ttlOutOfRange"));
158
+ }
159
+ const timeoutSeconds = parseDurationSeconds(opts.timeout);
160
+ if (timeoutSeconds === null)
161
+ return fail(t("agentSession.invalidTimeout", { value: opts.timeout }));
162
+ const keys = parseKeys(opts.keys);
163
+ if (keys === null)
164
+ return fail(t("agentSession.invalidKeys"));
165
+ const { org, project, env } = resolveOpts(opts);
166
+ if (!org || !project || !env) {
167
+ return fail(!hasProjectConfig() && (!opts.org || !opts.project)
168
+ ? t("common.noProjectConfig")
169
+ : t("common.missingOrgProjectEnv"));
170
+ }
171
+ if (!json)
172
+ logContext({ org, project, env });
173
+ const agentName = detectAgentName(opts.agent);
174
+ const basePath = `/agent-sessions/${org}/envs/${project}/${env}`;
175
+ const spinner = ora({ text: t("agentSession.starting"), isSilent: json });
176
+ const activate = (session, token) => {
177
+ saveLocalSession({
178
+ id: session.id,
179
+ org,
180
+ project,
181
+ env,
182
+ apiUrl: getApiUrl(),
183
+ agentName: session.agentName,
184
+ allowedKeys: session.allowedKeys,
185
+ expiresAt: session.expiresAt,
186
+ }, token);
187
+ // The token stops here: nothing below may print it, in text or in JSON.
188
+ const expires = new Date(session.expiresAt).toLocaleString();
189
+ const scope = session.allowedKeys
190
+ ? t("agentSession.limitedTo", { keys: session.allowedKeys.join(", ") })
191
+ : t("agentSession.allKeysInEnv");
192
+ return {
193
+ code: AGENT_SESSION_EXIT.active,
194
+ payload: {
195
+ status: "active",
196
+ id: session.id,
197
+ org,
198
+ project,
199
+ env,
200
+ agentName: session.agentName,
201
+ allowedKeys: session.allowedKeys,
202
+ expiresAt: session.expiresAt,
203
+ },
204
+ line: [
205
+ chalk.green(t("agentSession.started", { id: session.id })),
206
+ chalk.dim(` ${scope}`),
207
+ chalk.dim(` ${t("agentSession.expiresAt", { date: expires })}`),
208
+ chalk.dim(` ${t("agentSession.runHint", { command: `envshed run -e ${env} -- <command>` })}`),
209
+ ].join("\n"),
210
+ };
211
+ };
212
+ // Returns instead of exiting, so the catch below only ever sees real failures.
213
+ const execute = async () => {
214
+ spinner.start();
215
+ const created = (await apiPost(basePath, {
216
+ agentName,
217
+ ttlSeconds,
218
+ ...(keys && { keys }),
219
+ ...(opts.reason && { reason: opts.reason }),
220
+ }));
221
+ spinner.stop();
222
+ if (created.status === "active")
223
+ return activate(created.session, created.token);
224
+ let request = created.request;
225
+ const url = `${getApiUrl()}${created.path}`;
226
+ const describe = { id: request.id, url };
227
+ if (!json) {
228
+ console.log(chalk.bold(t("agentSession.approvalNeeded", { env })));
229
+ console.log(`\n ${t("agentSession.approveInBrowser")}\n ${chalk.cyan(url)}\n`);
230
+ }
231
+ if (!opts.wait && request.status === "pending") {
232
+ return {
233
+ code: AGENT_SESSION_EXIT.pending,
234
+ payload: { status: "pending", ...describe },
235
+ line: chalk.dim(t("agentSession.notWaiting")),
236
+ };
237
+ }
238
+ const waiting = ora({ text: t("agentSession.waiting"), isSilent: json }).start();
239
+ const deadline = Date.now() + timeoutSeconds * 1000;
240
+ let interval = POLL_INTERVAL_MS;
241
+ let polledOnce = false;
242
+ while ((request.status === "pending" || request.status === "approved") &&
243
+ Date.now() < deadline) {
244
+ // An approved request re-attached by a re-run has nothing left to wait for.
245
+ if (polledOnce || request.status === "pending") {
246
+ await sleep(Math.min(interval, Math.max(0, deadline - Date.now())));
247
+ }
248
+ polledOnce = true;
249
+ const polled = await pollStatus(`${basePath}/requests/${request.id}`);
250
+ if (polled && "request" in polled) {
251
+ request = polled.request;
252
+ interval = POLL_INTERVAL_MS;
253
+ if (polled.token && polled.session) {
254
+ waiting.stop();
255
+ return activate(polled.session, polled.token);
256
+ }
257
+ }
258
+ else if (polled) {
259
+ interval = Math.min(polled.retryAfterMs, MAX_POLL_INTERVAL_MS);
260
+ }
261
+ else {
262
+ interval = Math.min(interval * 2, MAX_POLL_INTERVAL_MS);
263
+ }
264
+ }
265
+ waiting.stop();
266
+ if (request.status === "declined") {
267
+ return {
268
+ code: AGENT_SESSION_EXIT.declined,
269
+ payload: { status: "declined", ...describe },
270
+ line: chalk.red(t("agentSession.declined", { env })),
271
+ };
272
+ }
273
+ if (request.status === "released") {
274
+ // Released, but not to this process: the token can never be fetched again.
275
+ return { code: AGENT_SESSION_EXIT.error, error: t("agentSession.alreadyCollected") };
276
+ }
277
+ return {
278
+ code: AGENT_SESSION_EXIT.timeout,
279
+ payload: { status: request.status === "expired" ? "expired" : "timeout", ...describe },
280
+ line: chalk.yellow(t(request.status === "expired" ? "agentSession.expired" : "agentSession.timedOut")),
281
+ };
282
+ };
283
+ let outcome;
284
+ try {
285
+ outcome = await execute();
286
+ }
287
+ catch (err) {
288
+ spinner.stop();
289
+ console.error(chalk.red(t("agentSession.failed", { message: err.message })));
290
+ process.exit(AGENT_SESSION_EXIT.error);
291
+ }
292
+ if (outcome.error)
293
+ console.error(chalk.red(outcome.error));
294
+ else if (json)
295
+ console.log(JSON.stringify(outcome.payload));
296
+ else if (outcome.line)
297
+ console.log(outcome.line);
298
+ process.exit(outcome.code);
299
+ });
300
+ //# sourceMappingURL=agent-session.js.map