@0xmaxma/claude-gateway 2.1.9 → 2.1.11

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 (271) hide show
  1. package/config.template.json +4 -0
  2. package/dist/agent/runner.d.ts +93 -6
  3. package/dist/agent/runner.d.ts.map +1 -1
  4. package/dist/agent/runner.js +342 -108
  5. package/dist/agent/runner.js.map +1 -1
  6. package/dist/api/async-guard.d.ts +13 -0
  7. package/dist/api/async-guard.d.ts.map +1 -0
  8. package/dist/api/async-guard.js +38 -0
  9. package/dist/api/async-guard.js.map +1 -0
  10. package/dist/api/auth.d.ts +5 -0
  11. package/dist/api/auth.d.ts.map +1 -1
  12. package/dist/api/auth.js +3 -0
  13. package/dist/api/auth.js.map +1 -1
  14. package/dist/api/browser-bindings-router.d.ts.map +1 -1
  15. package/dist/api/browser-bindings-router.js +2 -0
  16. package/dist/api/browser-bindings-router.js.map +1 -1
  17. package/dist/api/capabilities.d.ts +47 -2
  18. package/dist/api/capabilities.d.ts.map +1 -1
  19. package/dist/api/capabilities.js +51 -8
  20. package/dist/api/capabilities.js.map +1 -1
  21. package/dist/api/files-router.d.ts +23 -0
  22. package/dist/api/files-router.d.ts.map +1 -0
  23. package/dist/api/files-router.js +102 -0
  24. package/dist/api/files-router.js.map +1 -0
  25. package/dist/api/gateway-router.d.ts +4 -2
  26. package/dist/api/gateway-router.d.ts.map +1 -1
  27. package/dist/api/gateway-router.js +20 -2
  28. package/dist/api/gateway-router.js.map +1 -1
  29. package/dist/api/git-router.d.ts +4 -0
  30. package/dist/api/git-router.d.ts.map +1 -0
  31. package/dist/api/git-router.js +51 -0
  32. package/dist/api/git-router.js.map +1 -0
  33. package/dist/api/manifest-sources.d.ts.map +1 -1
  34. package/dist/api/manifest-sources.js +6 -0
  35. package/dist/api/manifest-sources.js.map +1 -1
  36. package/dist/api/processes-router.d.ts +28 -0
  37. package/dist/api/processes-router.d.ts.map +1 -0
  38. package/dist/api/processes-router.js +179 -0
  39. package/dist/api/processes-router.js.map +1 -0
  40. package/dist/api/router.d.ts +41 -1
  41. package/dist/api/router.d.ts.map +1 -1
  42. package/dist/api/router.js +112 -25
  43. package/dist/api/router.js.map +1 -1
  44. package/dist/api/voice-router.d.ts.map +1 -1
  45. package/dist/api/voice-router.js +2 -0
  46. package/dist/api/voice-router.js.map +1 -1
  47. package/dist/automation/browser-outcome.d.ts +3 -1
  48. package/dist/automation/browser-outcome.d.ts.map +1 -1
  49. package/dist/automation/browser-outcome.js +2 -2
  50. package/dist/automation/browser-outcome.js.map +1 -1
  51. package/dist/automation/command-speech.d.ts +9 -1
  52. package/dist/automation/command-speech.d.ts.map +1 -1
  53. package/dist/automation/command-speech.js +18 -0
  54. package/dist/automation/command-speech.js.map +1 -1
  55. package/dist/automation/command-steps.d.ts +2 -0
  56. package/dist/automation/command-steps.d.ts.map +1 -1
  57. package/dist/automation/command-steps.js +34 -2
  58. package/dist/automation/command-steps.js.map +1 -1
  59. package/dist/automation/computer-command.d.ts +1 -0
  60. package/dist/automation/computer-command.d.ts.map +1 -1
  61. package/dist/automation/computer-command.js +31 -5
  62. package/dist/automation/computer-command.js.map +1 -1
  63. package/dist/automation/computer-outcome.d.ts +26 -3
  64. package/dist/automation/computer-outcome.d.ts.map +1 -1
  65. package/dist/automation/computer-outcome.js +183 -13
  66. package/dist/automation/computer-outcome.js.map +1 -1
  67. package/dist/automation/computer-policy.d.ts +10 -1
  68. package/dist/automation/computer-policy.d.ts.map +1 -1
  69. package/dist/automation/computer-policy.js +20 -6
  70. package/dist/automation/computer-policy.js.map +1 -1
  71. package/dist/automation/computer-use.d.ts +34 -0
  72. package/dist/automation/computer-use.d.ts.map +1 -1
  73. package/dist/automation/computer-use.js +211 -17
  74. package/dist/automation/computer-use.js.map +1 -1
  75. package/dist/automation/direct-command.d.ts +8 -0
  76. package/dist/automation/direct-command.d.ts.map +1 -1
  77. package/dist/automation/direct-command.js +12 -0
  78. package/dist/automation/direct-command.js.map +1 -1
  79. package/dist/automation/model-choice-evaluator.d.ts +3 -0
  80. package/dist/automation/model-choice-evaluator.d.ts.map +1 -1
  81. package/dist/automation/model-choice-evaluator.js +3 -1
  82. package/dist/automation/model-choice-evaluator.js.map +1 -1
  83. package/dist/automation/vision-decider.d.ts +4 -2
  84. package/dist/automation/vision-decider.d.ts.map +1 -1
  85. package/dist/automation/vision-decider.js +69 -15
  86. package/dist/automation/vision-decider.js.map +1 -1
  87. package/dist/build-provenance.json +4 -4
  88. package/dist/cli/redact.d.ts +1 -0
  89. package/dist/cli/redact.d.ts.map +1 -1
  90. package/dist/cli/redact.js +12 -0
  91. package/dist/cli/redact.js.map +1 -1
  92. package/dist/config/loader.d.ts +5 -0
  93. package/dist/config/loader.d.ts.map +1 -1
  94. package/dist/config/loader.js +121 -0
  95. package/dist/config/loader.js.map +1 -1
  96. package/dist/config/reload-policy.d.ts.map +1 -1
  97. package/dist/config/reload-policy.js +1 -0
  98. package/dist/config/reload-policy.js.map +1 -1
  99. package/dist/config/watcher.d.ts.map +1 -1
  100. package/dist/config/watcher.js +1 -0
  101. package/dist/config/watcher.js.map +1 -1
  102. package/dist/files/config.d.ts +6 -0
  103. package/dist/files/config.d.ts.map +1 -0
  104. package/dist/files/config.js +15 -0
  105. package/dist/files/config.js.map +1 -0
  106. package/dist/files/delete.d.ts +27 -0
  107. package/dist/files/delete.d.ts.map +1 -0
  108. package/dist/files/delete.js +143 -0
  109. package/dist/files/delete.js.map +1 -0
  110. package/dist/files/fs.d.ts +70 -0
  111. package/dist/files/fs.d.ts.map +1 -0
  112. package/dist/files/fs.js +319 -0
  113. package/dist/files/fs.js.map +1 -0
  114. package/dist/files/holds.d.ts +11 -0
  115. package/dist/files/holds.d.ts.map +1 -0
  116. package/dist/files/holds.js +20 -0
  117. package/dist/files/holds.js.map +1 -0
  118. package/dist/files/paths.d.ts +26 -0
  119. package/dist/files/paths.d.ts.map +1 -0
  120. package/dist/files/paths.js +112 -0
  121. package/dist/files/paths.js.map +1 -0
  122. package/dist/files/session-cwd.d.ts +8 -0
  123. package/dist/files/session-cwd.d.ts.map +1 -0
  124. package/dist/files/session-cwd.js +139 -0
  125. package/dist/files/session-cwd.js.map +1 -0
  126. package/dist/git/read.d.ts +25 -0
  127. package/dist/git/read.d.ts.map +1 -0
  128. package/dist/git/read.js +166 -0
  129. package/dist/git/read.js.map +1 -0
  130. package/dist/git/runner.d.ts +46 -0
  131. package/dist/git/runner.d.ts.map +1 -0
  132. package/dist/git/runner.js +176 -0
  133. package/dist/git/runner.js.map +1 -0
  134. package/dist/git/status.d.ts +119 -0
  135. package/dist/git/status.d.ts.map +1 -0
  136. package/dist/git/status.js +273 -0
  137. package/dist/git/status.js.map +1 -0
  138. package/dist/index.js +7 -2
  139. package/dist/index.js.map +1 -1
  140. package/dist/jev/browser-contract.d.ts +3 -0
  141. package/dist/jev/browser-contract.d.ts.map +1 -1
  142. package/dist/jev/browser-contract.js +6 -0
  143. package/dist/jev/browser-contract.js.map +1 -1
  144. package/dist/orchestration/agent-tool-schemas.d.ts +18 -0
  145. package/dist/orchestration/agent-tool-schemas.d.ts.map +1 -1
  146. package/dist/orchestration/agent-tool-schemas.js +11 -3
  147. package/dist/orchestration/agent-tool-schemas.js.map +1 -1
  148. package/dist/orchestration/bridge.d.ts.map +1 -1
  149. package/dist/orchestration/bridge.js +26 -5
  150. package/dist/orchestration/bridge.js.map +1 -1
  151. package/dist/orchestration/browser-routing.d.ts.map +1 -1
  152. package/dist/orchestration/browser-routing.js +2 -1
  153. package/dist/orchestration/browser-routing.js.map +1 -1
  154. package/dist/orchestration/computer-decisions.d.ts +1 -1
  155. package/dist/orchestration/computer-decisions.d.ts.map +1 -1
  156. package/dist/orchestration/computer-decisions.js +21 -7
  157. package/dist/orchestration/computer-decisions.js.map +1 -1
  158. package/dist/orchestration/computer-live.d.ts +62 -0
  159. package/dist/orchestration/computer-live.d.ts.map +1 -0
  160. package/dist/orchestration/computer-live.js +126 -0
  161. package/dist/orchestration/computer-live.js.map +1 -0
  162. package/dist/orchestration/container-tool-schemas.d.ts.map +1 -1
  163. package/dist/orchestration/container-tool-schemas.js +3 -0
  164. package/dist/orchestration/container-tool-schemas.js.map +1 -1
  165. package/dist/orchestration/decisions.d.ts +3 -1
  166. package/dist/orchestration/decisions.d.ts.map +1 -1
  167. package/dist/orchestration/decisions.js +4 -2
  168. package/dist/orchestration/decisions.js.map +1 -1
  169. package/dist/orchestration/gateway-tasks/browser.d.ts +1 -1
  170. package/dist/orchestration/gateway-tasks/browser.d.ts.map +1 -1
  171. package/dist/orchestration/gateway-tasks/browser.js +4 -3
  172. package/dist/orchestration/gateway-tasks/browser.js.map +1 -1
  173. package/dist/orchestration/gateway-tasks/computer-context.d.ts +4 -1
  174. package/dist/orchestration/gateway-tasks/computer-context.d.ts.map +1 -1
  175. package/dist/orchestration/gateway-tasks/computer-context.js +3 -1
  176. package/dist/orchestration/gateway-tasks/computer-context.js.map +1 -1
  177. package/dist/orchestration/gateway-tasks/computer.d.ts +78 -15
  178. package/dist/orchestration/gateway-tasks/computer.d.ts.map +1 -1
  179. package/dist/orchestration/gateway-tasks/computer.js +298 -31
  180. package/dist/orchestration/gateway-tasks/computer.js.map +1 -1
  181. package/dist/orchestration/gateway-tasks/controller.d.ts +14 -2
  182. package/dist/orchestration/gateway-tasks/controller.d.ts.map +1 -1
  183. package/dist/orchestration/gateway-tasks/controller.js +63 -2
  184. package/dist/orchestration/gateway-tasks/controller.js.map +1 -1
  185. package/dist/orchestration/notification-mailbox.js +3 -3
  186. package/dist/orchestration/notification-mailbox.js.map +1 -1
  187. package/dist/orchestration/process-turn.d.ts.map +1 -1
  188. package/dist/orchestration/process-turn.js +4 -1
  189. package/dist/orchestration/process-turn.js.map +1 -1
  190. package/dist/orchestration/response-errors.d.ts.map +1 -1
  191. package/dist/orchestration/response-errors.js +2 -0
  192. package/dist/orchestration/response-errors.js.map +1 -1
  193. package/dist/orchestration/runtime.d.ts +32 -2
  194. package/dist/orchestration/runtime.d.ts.map +1 -1
  195. package/dist/orchestration/runtime.js +106 -10
  196. package/dist/orchestration/runtime.js.map +1 -1
  197. package/dist/orchestration/task-controls.d.ts +8 -0
  198. package/dist/orchestration/task-controls.d.ts.map +1 -1
  199. package/dist/orchestration/task-controls.js +3 -2
  200. package/dist/orchestration/task-controls.js.map +1 -1
  201. package/dist/orchestration/tasks/automation-session.d.ts +42 -11
  202. package/dist/orchestration/tasks/automation-session.d.ts.map +1 -1
  203. package/dist/orchestration/tasks/automation-session.js +101 -21
  204. package/dist/orchestration/tasks/automation-session.js.map +1 -1
  205. package/dist/orchestration/tasks/driver.d.ts.map +1 -1
  206. package/dist/orchestration/tasks/driver.js +19 -1
  207. package/dist/orchestration/tasks/driver.js.map +1 -1
  208. package/dist/orchestration/tasks/service.d.ts +48 -2
  209. package/dist/orchestration/tasks/service.d.ts.map +1 -1
  210. package/dist/orchestration/tasks/service.js +165 -16
  211. package/dist/orchestration/tasks/service.js.map +1 -1
  212. package/dist/orchestration/telegram-tool-status.d.ts.map +1 -1
  213. package/dist/orchestration/telegram-tool-status.js +2 -0
  214. package/dist/orchestration/telegram-tool-status.js.map +1 -1
  215. package/dist/orchestration/types.d.ts +21 -0
  216. package/dist/orchestration/types.d.ts.map +1 -1
  217. package/dist/orchestration/types.js.map +1 -1
  218. package/dist/processes/listeners.d.ts +41 -0
  219. package/dist/processes/listeners.d.ts.map +1 -0
  220. package/dist/processes/listeners.js +140 -0
  221. package/dist/processes/listeners.js.map +1 -0
  222. package/dist/processes/start.d.ts +39 -0
  223. package/dist/processes/start.d.ts.map +1 -0
  224. package/dist/processes/start.js +208 -0
  225. package/dist/processes/start.js.map +1 -0
  226. package/dist/processes/stop.d.ts +37 -0
  227. package/dist/processes/stop.d.ts.map +1 -0
  228. package/dist/processes/stop.js +94 -0
  229. package/dist/processes/stop.js.map +1 -0
  230. package/dist/session/cwd.d.ts +65 -0
  231. package/dist/session/cwd.d.ts.map +1 -0
  232. package/dist/session/cwd.js +24 -0
  233. package/dist/session/cwd.js.map +1 -0
  234. package/dist/session/process.d.ts +17 -0
  235. package/dist/session/process.d.ts.map +1 -1
  236. package/dist/session/process.js +58 -3
  237. package/dist/session/process.js.map +1 -1
  238. package/dist/session/runtime-profile.d.ts +4 -0
  239. package/dist/session/runtime-profile.d.ts.map +1 -1
  240. package/dist/session/runtime-profile.js +1 -0
  241. package/dist/session/runtime-profile.js.map +1 -1
  242. package/dist/session/store.d.ts +13 -1
  243. package/dist/session/store.d.ts.map +1 -1
  244. package/dist/session/store.js +50 -4
  245. package/dist/session/store.js.map +1 -1
  246. package/dist/types.d.ts +19 -0
  247. package/dist/types.d.ts.map +1 -1
  248. package/dist/ui/voice-call-client.d.ts +3 -0
  249. package/dist/ui/voice-call-client.d.ts.map +1 -1
  250. package/dist/ui/voice-call-client.js +10 -1
  251. package/dist/ui/voice-call-client.js.map +1 -1
  252. package/dist/utils/paths.d.ts +5 -0
  253. package/dist/utils/paths.d.ts.map +1 -1
  254. package/dist/utils/paths.js +15 -0
  255. package/dist/utils/paths.js.map +1 -1
  256. package/dist/utils/result.d.ts +16 -0
  257. package/dist/utils/result.d.ts.map +1 -0
  258. package/dist/utils/result.js +8 -0
  259. package/dist/utils/result.js.map +1 -0
  260. package/dist/voice/errors.js +1 -1
  261. package/dist/voice/errors.js.map +1 -1
  262. package/dist/voice/providers/elevenlabs-tts.d.ts.map +1 -1
  263. package/dist/voice/providers/elevenlabs-tts.js +17 -1
  264. package/dist/voice/providers/elevenlabs-tts.js.map +1 -1
  265. package/dist/voice/providers/socket.js +25 -6
  266. package/dist/voice/providers/socket.js.map +1 -1
  267. package/dist/voice/session.js +3 -2
  268. package/dist/voice/session.js.map +1 -1
  269. package/mcp/server.ts +1 -1
  270. package/mcp/tools/tasks/module.ts +2 -1
  271. package/package.json +1 -1
@@ -0,0 +1,139 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.createCwdResolver = createCwdResolver;
37
+ const fs_1 = require("fs");
38
+ const path = __importStar(require("path"));
39
+ const paths_1 = require("../utils/paths");
40
+ const result_1 = require("../utils/result");
41
+ const read_1 = require("../git/read");
42
+ const status_1 = require("../git/status");
43
+ const config_1 = require("./config");
44
+ const fs_2 = require("./fs");
45
+ const holds_1 = require("./holds");
46
+ const paths_2 = require("./paths");
47
+ /** A branch name the note may carry verbatim. Git allows far more, and the note is a prompt. */
48
+ const PLAIN_BRANCH_RE = /^[\w./-]{1,100}$/;
49
+ const UNAVAILABLE = {
50
+ not_found: 'not_found',
51
+ path_escape: 'outside_root',
52
+ not_a_directory: 'not_a_directory',
53
+ permission_denied: 'permission_denied',
54
+ };
55
+ /**
56
+ * Session working folders under `gateway.files.root`. A cwd is any folder under the root except the root itself, named
57
+ * by a path the files API accepts. It is stored as an absolute path and resolved again at every spawn and turn.
58
+ */
59
+ function createCwdResolver(config, logger) {
60
+ const root = () => (0, config_1.resolveFilesRoot)(config);
61
+ /** The root-relative path of `abs`, under the real root or the configured spelling of it. */
62
+ async function relUnderRoot(abs) {
63
+ const realRoot = await fs_1.promises.realpath(root()).catch(() => null);
64
+ if (!realRoot)
65
+ return (0, result_1.err)('not_found');
66
+ const base = [realRoot, root()].find((r) => (0, paths_1.pathWithin)(r, abs));
67
+ if (base === undefined)
68
+ return (0, result_1.err)('outside_root');
69
+ const rel = (0, paths_2.parseRelPath)(path.relative(base, abs).split(path.sep).join('/'));
70
+ return rel.ok ? (0, result_1.ok)({ realRoot, rel: rel.value }) : (0, result_1.err)('invalid');
71
+ }
72
+ /** Exact match on the real folder, no inheritance into subfolders, and never through a symlink alias. */
73
+ function trusted(realRoot, rel, dir) {
74
+ if (dir !== path.join(realRoot, rel))
75
+ return false;
76
+ return (config.gateway.files?.trusted ?? []).some((entry) => path.join(realRoot, entry) === dir);
77
+ }
78
+ async function resolveAt(abs) {
79
+ if (!(0, config_1.filesEnabled)(config))
80
+ return (0, result_1.err)('disabled');
81
+ const where = await relUnderRoot(abs);
82
+ if (!where.ok)
83
+ return where;
84
+ const { realRoot, rel } = where.value;
85
+ const dir = await (0, fs_2.resolveDir)(root(), rel);
86
+ if (!dir.ok)
87
+ return (0, result_1.err)(UNAVAILABLE[dir.error] ?? 'internal');
88
+ const hold = (0, holds_1.findHold)(dir.value);
89
+ if (hold)
90
+ return (0, result_1.err)('deleting');
91
+ const st = await fs_1.promises.stat(dir.value).catch(() => null);
92
+ if (!st)
93
+ return (0, result_1.err)('not_found');
94
+ const stored = path.join(realRoot, rel);
95
+ return (0, result_1.ok)({
96
+ path: stored,
97
+ dir: dir.value,
98
+ trusted: trusted(realRoot, rel, dir.value),
99
+ identity: `${st.dev}:${st.ino}`,
100
+ location: `You are working in the folder ${rel} at ${dir.value}.`,
101
+ });
102
+ }
103
+ return {
104
+ async parse(raw) {
105
+ // A trailing slash is refused in both forms, as the files API refuses it, so one folder has one spelling.
106
+ if (typeof raw !== 'string' || raw === '' || raw.includes('\0') || (raw.length > 1 && raw.endsWith('/')))
107
+ return (0, result_1.err)('invalid');
108
+ if (!(0, config_1.filesEnabled)(config))
109
+ return (0, result_1.err)('disabled');
110
+ if (path.isAbsolute(raw))
111
+ return path.normalize(raw) === raw ? resolveAt(raw) : (0, result_1.err)('invalid');
112
+ const rel = (0, paths_2.parseRelPath)(raw);
113
+ if (!rel.ok)
114
+ return (0, result_1.err)('invalid');
115
+ const realRoot = await fs_1.promises.realpath(root()).catch(() => null);
116
+ return resolveAt(path.join(realRoot ?? root(), rel.value));
117
+ },
118
+ async resolve(abs) {
119
+ if (!path.isAbsolute(abs))
120
+ return (0, result_1.err)('outside_root');
121
+ const resolved = await resolveAt(path.normalize(abs));
122
+ return resolved.ok || resolved.error !== 'invalid' ? resolved : (0, result_1.err)('outside_root');
123
+ },
124
+ async note(cwd) {
125
+ const status = await (0, read_1.readStatusSummary)(cwd.dir, logger).catch(() => null);
126
+ if (!status?.ok)
127
+ return cwd.location;
128
+ const s = status.value;
129
+ const host = s.remote ? (0, status_1.remoteHostname)(s.remote.url) : null;
130
+ const git = [
131
+ ...(s.branch === null ? ['detached HEAD'] : PLAIN_BRANCH_RE.test(s.branch) ? [`branch ${s.branch}`] : []),
132
+ `${s.change_count} ${s.change_count === 1 ? 'change' : 'changes'}`,
133
+ ...(host ? [`remote ${host}`] : []),
134
+ ];
135
+ return `${cwd.location} Git: ${git.join(', ')}.`;
136
+ },
137
+ };
138
+ }
139
+ //# sourceMappingURL=session-cwd.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session-cwd.js","sourceRoot":"","sources":["../../src/files/session-cwd.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BA,8CAuEC;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CAAC,CAAC,CAAC,MAAM,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;gBACzG,GAAG,CAAC,CAAC,YAAY,IAAI,CAAC,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,EAAE;gBAClE,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,UAAU,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;aACpC,CAAC;YACF,OAAO,GAAG,GAAG,CAAC,QAAQ,SAAS,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC;QACnD,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,25 @@
1
+ import { GitCommitInfo, GitStatus, GitSummary } from './status';
2
+ import { FilesErrorCode, RelPath } from '../files/paths';
3
+ import type { Logger } from '../types';
4
+ import { Result } from '../utils/result';
5
+ export type GitErrorCode = 'not_a_git_repo'
6
+ /** git refuses a repository that another user owns (`safe.directory`). */
7
+ | 'git_unsafe_owner'
8
+ /** There is a `.git` that git cannot read: permissions, damage, a bad config, or a filter setup the gateway cannot make safe. */
9
+ | 'git_unreadable' | 'timeout'
10
+ /** git is not installed or not on the gateway's PATH. */
11
+ | 'git_unavailable' | 'git_failed';
12
+ export type GitError = {
13
+ code: GitErrorCode | FilesErrorCode;
14
+ };
15
+ export type GitResult<T> = Result<T, GitError>;
16
+ export declare function parseCommitInfo(stdout: string): GitCommitInfo | null;
17
+ /** The cheaper read for a summary or a chat's context note: an untracked folder counts once, and no last commit or operation. */
18
+ export declare function readStatusSummary(dir: string, logger: Logger): Promise<GitResult<GitStatus>>;
19
+ /** Git status of the folder `rel` names under `root`. The root itself is refused. */
20
+ export declare function getStatus(root: string, rel: RelPath, logger: Logger): Promise<GitResult<GitStatus>>;
21
+ /** Every folder directly under `rel` with a `.git`, keyed by name; null when its status timed out or failed. Others are left out. */
22
+ export declare function getSummaries(root: string, rel: RelPath, logger: Logger): Promise<GitResult<{
23
+ summaries: Record<string, GitSummary | null>;
24
+ }>>;
25
+ //# sourceMappingURL=read.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"read.d.ts","sourceRoot":"","sources":["../../src/git/read.ts"],"names":[],"mappings":"AAIA,OAAO,EAEL,aAAa,EAEb,SAAS,EACT,UAAU,EAKX,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,EAAW,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAElD,MAAM,MAAM,YAAY,GACpB,gBAAgB;AAClB,0EAA0E;GACxE,kBAAkB;AACpB,iIAAiI;GAC/H,gBAAgB,GAChB,SAAS;AACX,yDAAyD;GACvD,iBAAiB,GACjB,YAAY,CAAC;AAEjB,MAAM,MAAM,QAAQ,GAAG;IAAE,IAAI,EAAE,YAAY,GAAG,cAAc,CAAA;CAAE,CAAC;AAE/D,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI,MAAM,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC;AAwB/C,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,aAAa,GAAG,IAAI,CAGpE;AA8ED,iIAAiI;AACjI,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,CAE5F;AAED,qFAAqF;AACrF,wBAAsB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,CAGzG;AAED,qIAAqI;AACrI,wBAAsB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC;IAAE,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI,CAAC,CAAA;CAAE,CAAC,CAAC,CAYnJ"}
@@ -0,0 +1,166 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.parseCommitInfo = parseCommitInfo;
37
+ exports.readStatusSummary = readStatusSummary;
38
+ exports.getStatus = getStatus;
39
+ exports.getSummaries = getSummaries;
40
+ const fs_1 = require("fs");
41
+ const path = __importStar(require("path"));
42
+ const fs_2 = require("../files/fs");
43
+ const runner_1 = require("./runner");
44
+ const status_1 = require("./status");
45
+ const result_1 = require("../utils/result");
46
+ const fail = (code) => (0, result_1.err)({ code });
47
+ const SUMMARY_CONCURRENCY = 4;
48
+ const COMMIT_FORMAT = '%H%x00%s%x00%an%x00%cI';
49
+ /** First match wins: a rebase also leaves files a merge would. */
50
+ const OPERATION_MARKERS = [
51
+ ['rebase-merge', 'rebase'],
52
+ ['rebase-apply', 'rebase'],
53
+ ['MERGE_HEAD', 'merge'],
54
+ ['CHERRY_PICK_HEAD', 'cherry_pick'],
55
+ ['REVERT_HEAD', 'revert'],
56
+ ['BISECT_LOG', 'bisect'],
57
+ ];
58
+ async function operationIn(gitDir) {
59
+ for (const [marker, op] of OPERATION_MARKERS) {
60
+ if (await fs_1.promises.lstat(path.join(gitDir, marker)).then(() => true, () => false))
61
+ return op;
62
+ }
63
+ return 'none';
64
+ }
65
+ function parseCommitInfo(stdout) {
66
+ const [sha, subject, author, committed_at] = stdout.replace(/\n$/, '').split('\0');
67
+ return sha && committed_at ? { sha, subject, author, committed_at } : null;
68
+ }
69
+ const DETAIL_READ = { timeoutMs: runner_1.GIT_READ_TIMEOUT_MS, untracked: 'all', commitAndOperation: true };
70
+ const SUMMARY_READ = { timeoutMs: runner_1.GIT_READ_TIMEOUT_MS, untracked: 'normal', commitAndOperation: false };
71
+ /** What git said when it could not read the repository, in words the client can act on. LC_ALL=C keeps these messages stable. */
72
+ async function readFailure(dir, out) {
73
+ if (/detected dubious ownership/.test(out.stderr))
74
+ return { code: 'git_unsafe_owner' };
75
+ if (/not a git repository/i.test(out.stderr)) {
76
+ // A `.git` entry git cannot open reads as "not a repository": say it is there but unreadable.
77
+ return { code: (await fs_1.promises.lstat(path.join(dir, '.git')).then(() => true, () => false)) ? 'git_unreadable' : 'not_a_git_repo' };
78
+ }
79
+ if (/permission denied|cannot (open|read|access)|unable to (open|read|access)|operation not permitted|bad config|invalid gitfile/i.test(out.stderr))
80
+ return { code: 'git_unreadable' };
81
+ // Git versions differ in the message for a broken gitfile. A present .git entry means the repository itself failed to open.
82
+ if (await fs_1.promises.lstat(path.join(dir, '.git')).then(() => true, () => false))
83
+ return { code: 'git_unreadable' };
84
+ return { code: 'git_failed' };
85
+ }
86
+ /**
87
+ * The config is listed first, by git itself, so the includes, the worktree config and the scopes are git's reading and
88
+ * not ours. Every filter driver the repository's own config defines is then blanked for the status call, which would
89
+ * otherwise run a driver's clean command on any file whose stat changed. A driver that cannot be blanked safely makes
90
+ * the repository unreadable rather than risking the run.
91
+ */
92
+ async function readRepo(dir, read, logger) {
93
+ const started = Date.now();
94
+ const listed = await (0, runner_1.runGit)(dir, ['config', '--list', '-z', '--show-scope'], { timeoutMs: read.timeoutMs, logger });
95
+ if (!listed.ok)
96
+ return fail(listed.error);
97
+ if (listed.value.code !== 0)
98
+ return (0, result_1.err)(await readFailure(dir, listed.value));
99
+ if ((0, status_1.hasUndecodableFilterKey)(listed.value.stdoutBytes))
100
+ return fail('git_unreadable');
101
+ const { config, filterKeys } = (0, status_1.parseConfigList)(listed.value.stdout);
102
+ if (filterKeys.length > runner_1.MAX_BLANKED_FILTER_KEYS || filterKeys.some((k) => k.length > runner_1.MAX_FILTER_KEY))
103
+ return fail('git_unreadable');
104
+ const opts = { timeoutMs: Math.max(read.timeoutMs - (Date.now() - started), 1), blankFilterKeys: filterKeys, logger };
105
+ const skipped = Promise.resolve((0, result_1.ok)({ code: 0, stdout: '', stdoutBytes: Buffer.alloc(0), stderr: '' }));
106
+ const full = read.commitAndOperation;
107
+ const runs = await Promise.all([
108
+ full ? (0, runner_1.runGit)(dir, ['rev-parse', '--absolute-git-dir'], opts) : skipped,
109
+ // Submodules are compared by commit only: checking their worktrees would run git, and its filters, inside each one.
110
+ (0, runner_1.runGit)(dir, ['status', '--porcelain=v2', '--branch', '-z', '--ignore-submodules=dirty', `--untracked-files=${read.untracked}`], opts),
111
+ // --no-show-signature: log.showSignature would run the repository's gpg.program.
112
+ full ? (0, runner_1.runGit)(dir, ['log', '-1', '-z', '--no-show-signature', `--format=${COMMIT_FORMAT}`], opts) : skipped,
113
+ ]);
114
+ for (const r of runs)
115
+ if (!r.ok)
116
+ return fail(r.error);
117
+ const [gitDir, status, log] = runs.map((r) => (r.ok ? r.value : null));
118
+ if (gitDir.code !== 0)
119
+ return (0, result_1.err)(await readFailure(dir, gitDir));
120
+ if (status.code !== 0)
121
+ return (0, result_1.err)(await readFailure(dir, status));
122
+ const parsed = (0, status_1.parseStatusV2)(status.stdout);
123
+ if (parsed.oid === null && parsed.upstream !== null)
124
+ parsed.behind = await unbornBehind(dir, opts);
125
+ return (0, result_1.ok)((0, status_1.buildStatus)({
126
+ parsed,
127
+ config,
128
+ lastCommit: full && log.code === 0 ? parseCommitInfo(log.stdout) : null,
129
+ operation: full ? await operationIn(gitDir.stdout.trim()) : 'none',
130
+ }));
131
+ }
132
+ /** git prints no `branch.ab` for an unborn branch, so count what a pull would bring: every commit the tracking branch has, or 0 without one. */
133
+ async function unbornBehind(dir, opts) {
134
+ const count = await (0, runner_1.runGit)(dir, ['rev-list', '--count', '@{upstream}', '--'], opts);
135
+ return count.ok && count.value.code === 0 ? Number(count.value.stdout.trim()) || 0 : 0;
136
+ }
137
+ /** The detailed read: every untracked file, the last commit and any operation in progress. `dir` must be a real folder under the root. */
138
+ function readStatus(dir, logger) {
139
+ return readRepo(dir, DETAIL_READ, logger);
140
+ }
141
+ /** The cheaper read for a summary or a chat's context note: an untracked folder counts once, and no last commit or operation. */
142
+ function readStatusSummary(dir, logger) {
143
+ return readRepo(dir, SUMMARY_READ, logger);
144
+ }
145
+ /** Git status of the folder `rel` names under `root`. The root itself is refused. */
146
+ async function getStatus(root, rel, logger) {
147
+ const dir = await (0, fs_2.resolveDir)(root, rel);
148
+ return dir.ok ? readStatus(dir.value, logger) : fail(dir.error);
149
+ }
150
+ /** Every folder directly under `rel` with a `.git`, keyed by name; null when its status timed out or failed. Others are left out. */
151
+ async function getSummaries(root, rel, logger) {
152
+ const list = await (0, fs_2.listDir)(root, rel);
153
+ if (!list.ok)
154
+ return fail(list.error);
155
+ const repos = list.value.entries.filter((e) => e.is_git);
156
+ const reads = await (0, fs_2.mapLimit)(repos, SUMMARY_CONCURRENCY, async (e) => {
157
+ const dir = await (0, fs_2.resolveDir)(root, e.path);
158
+ return dir.ok ? readStatusSummary(dir.value, logger) : fail(dir.error);
159
+ });
160
+ const noGit = reads.find((r) => !r.ok && r.error.code === 'git_unavailable');
161
+ if (noGit && !noGit.ok)
162
+ return fail(noGit.error.code);
163
+ const results = reads.map((r) => (r.ok ? (0, status_1.toSummary)(r.value) : null));
164
+ return (0, result_1.ok)({ summaries: Object.fromEntries(repos.map((e, i) => [e.name, results[i]])) });
165
+ }
166
+ //# sourceMappingURL=read.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"read.js","sourceRoot":"","sources":["../../src/git/read.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwDA,0CAGC;AA+ED,8CAEC;AAGD,8BAGC;AAGD,oCAYC;AAjKD,2BAAqC;AACrC,2CAA6B;AAC7B,oCAA4D;AAC5D,qCAAuH;AACvH,qCAUkB;AAGlB,4CAAkD;AAiBlD,MAAM,IAAI,GAAG,CAAC,IAAmC,EAAE,EAAE,CAAC,IAAA,YAAG,EAAC,EAAE,IAAI,EAAE,CAAC,CAAC;AAEpE,MAAM,mBAAmB,GAAG,CAAC,CAAC;AAC9B,MAAM,aAAa,GAAG,wBAAwB,CAAC;AAE/C,kEAAkE;AAClE,MAAM,iBAAiB,GAAkC;IACvD,CAAC,cAAc,EAAE,QAAQ,CAAC;IAC1B,CAAC,cAAc,EAAE,QAAQ,CAAC;IAC1B,CAAC,YAAY,EAAE,OAAO,CAAC;IACvB,CAAC,kBAAkB,EAAE,aAAa,CAAC;IACn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AC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;IACrE,OAAO,IAAA,WAAE,EAAC,EAAE,SAAS,EAAE,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;AAC1F,CAAC"}
@@ -0,0 +1,46 @@
1
+ import { Result } from '../utils/result';
2
+ import type { Logger } from '../types';
3
+ export declare const GIT_READ_TIMEOUT_MS = 3000;
4
+ export interface GitOutput {
5
+ /** Exit code; a non-zero exit is data for the caller to classify, not a failure here. */
6
+ code: number;
7
+ stdout: string;
8
+ /** The bytes behind `stdout`, for output whose text is not guaranteed to be UTF-8. */
9
+ stdoutBytes: Buffer;
10
+ stderr: string;
11
+ }
12
+ export type GitRunFailure = 'timeout' | 'git_failed' | 'git_unavailable';
13
+ /**
14
+ * The environment git runs with: an allowlist of process.env, and no GIT_DIR/GIT_WORK_TREE that would aim git at
15
+ * another repository. Built from process.env explicitly: jest gives tests a copy that child_process ignores.
16
+ *
17
+ * `GIT_ALLOW_PROTOCOL` set empty allows no transport at all, and unlike `protocol.<name>.allow` in the repository's
18
+ * config it cannot be overridden by the repository. Git can start a fetch on its own during a read, to fetch a missing
19
+ * object of a partial clone, so this is what keeps a repository's `core.sshCommand`, `uploadpack`, `ext::` URL or
20
+ * credential helper from ever running. `GIT_NO_LAZY_FETCH` (git 2.44 and later) stops that fetch from being tried.
21
+ */
22
+ export declare function gitEnv(): NodeJS.ProcessEnv;
23
+ /** `filter.*` keys a status read may blank; more than this, or a longer key, and the repository is refused. */
24
+ export declare const MAX_BLANKED_FILTER_KEYS = 64;
25
+ export declare const MAX_FILTER_KEY = 1024;
26
+ /**
27
+ * The command line and environment every git call of the gateway uses, reads and `git init` alike. `core.fsmonitor`
28
+ * is a command from the repository's config, so it is turned off for every call. A call that can run a clean filter
29
+ * (status) names the repository's `filter.*` keys in `blankFilterKeys` so no driver runs.
30
+ */
31
+ export declare function hardenedGit(cwd: string, args: string[], blankFilterKeys?: readonly string[]): {
32
+ argv: string[];
33
+ env: NodeJS.ProcessEnv;
34
+ };
35
+ export interface RunOptions {
36
+ timeoutMs: number;
37
+ logger: Logger;
38
+ /** The repository's own `filter.*` keys, to blank for this call. */
39
+ blankFilterKeys?: readonly string[];
40
+ }
41
+ /**
42
+ * Runs git in the folder `cwd`. Discovery stops at `cwd`, so a folder inside some
43
+ * other repository never reads as a repo itself.
44
+ */
45
+ export declare function runGit(cwd: string, args: string[], opts: RunOptions): Promise<Result<GitOutput, GitRunFailure>>;
46
+ //# sourceMappingURL=runner.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runner.d.ts","sourceRoot":"","sources":["../../src/git/runner.ts"],"names":[],"mappings":"AAGA,OAAO,EAAW,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAElD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAEvC,eAAO,MAAM,mBAAmB,OAAQ,CAAC;AAIzC,MAAM,WAAW,SAAS;IACxB,yFAAyF;IACzF,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,sFAAsF;IACtF,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,MAAM,aAAa,GAAG,SAAS,GAAG,YAAY,GAAG,iBAAiB,CAAC;AAYzE;;;;;;;;GAQG;AACH,wBAAgB,MAAM,IAAI,MAAM,CAAC,UAAU,CAG1C;AAED,+GAA+G;AAC/G,eAAO,MAAM,uBAAuB,KAAK,CAAC;AAC1C,eAAO,MAAM,cAAc,OAAO,CAAC;AAiBnC;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,eAAe,GAAE,SAAS,MAAM,EAAO,GAAG;IAAE,IAAI,EAAE,MAAM,EAAE,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC,UAAU,CAAA;CAAE,CAK5I;AAED,MAAM,WAAW,UAAU;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,oEAAoE;IACpE,eAAe,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CACrC;AAQD;;;GAGG;AACH,wBAAsB,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,SAAS,EAAE,aAAa,CAAC,CAAC,CAsErH"}
@@ -0,0 +1,176 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.MAX_FILTER_KEY = exports.MAX_BLANKED_FILTER_KEYS = exports.GIT_READ_TIMEOUT_MS = void 0;
37
+ exports.gitEnv = gitEnv;
38
+ exports.hardenedGit = hardenedGit;
39
+ exports.runGit = runGit;
40
+ const child_process_1 = require("child_process");
41
+ const fs_1 = require("fs");
42
+ const path = __importStar(require("path"));
43
+ const result_1 = require("../utils/result");
44
+ const status_1 = require("./status");
45
+ exports.GIT_READ_TIMEOUT_MS = 3000;
46
+ const MAX_OUTPUT = 32 * 1024 * 1024;
47
+ let warnedGitMissing = false;
48
+ /**
49
+ * What git and the operator's filters may inherit. Anything not named here is dropped, so the gateway's own API keys
50
+ * and bot tokens never reach a filter program. No network call is made, so no proxy, credential or ssh variables pass.
51
+ * `HOME`, `XDG_CONFIG_HOME` and the three `GIT_CONFIG_*` selectors decide which operator config files git reads
52
+ * (filters such as `git lfs install`, `safe.directory`).
53
+ */
54
+ const PASSTHROUGH_ENV = new Set(['PATH', 'HOME', 'TMPDIR', 'XDG_CONFIG_HOME', 'GIT_CONFIG_GLOBAL', 'GIT_CONFIG_SYSTEM', 'GIT_CONFIG_NOSYSTEM']);
55
+ /**
56
+ * The environment git runs with: an allowlist of process.env, and no GIT_DIR/GIT_WORK_TREE that would aim git at
57
+ * another repository. Built from process.env explicitly: jest gives tests a copy that child_process ignores.
58
+ *
59
+ * `GIT_ALLOW_PROTOCOL` set empty allows no transport at all, and unlike `protocol.<name>.allow` in the repository's
60
+ * config it cannot be overridden by the repository. Git can start a fetch on its own during a read, to fetch a missing
61
+ * object of a partial clone, so this is what keeps a repository's `core.sshCommand`, `uploadpack`, `ext::` URL or
62
+ * credential helper from ever running. `GIT_NO_LAZY_FETCH` (git 2.44 and later) stops that fetch from being tried.
63
+ */
64
+ function gitEnv() {
65
+ const env = Object.fromEntries(Object.entries(process.env).filter(([k]) => PASSTHROUGH_ENV.has(k)));
66
+ return { ...env, GIT_TERMINAL_PROMPT: '0', LC_ALL: 'C', GIT_ALLOW_PROTOCOL: '', GIT_NO_LAZY_FETCH: '1' };
67
+ }
68
+ /** `filter.*` keys a status read may blank; more than this, or a longer key, and the repository is refused. */
69
+ exports.MAX_BLANKED_FILTER_KEYS = 64;
70
+ exports.MAX_FILTER_KEY = 1024;
71
+ /**
72
+ * `GIT_CONFIG_COUNT/KEY_n/VALUE_n` entries that empty each named `filter.*` key. Every key is taken whole as git
73
+ * printed it, never split into driver name and variable, so no name (empty, dotted, holding `=`) can slip past a
74
+ * parser. Unlike `-c name=value` they take the key whole, and they rank as command-line config, above every file.
75
+ * An empty clean, smudge or process command runs nothing, and an empty `required` is false.
76
+ */
77
+ function blankFilterEnv(keys) {
78
+ const env = { GIT_CONFIG_COUNT: String(keys.length) };
79
+ keys.forEach((key, i) => {
80
+ env[`GIT_CONFIG_KEY_${i}`] = key;
81
+ env[`GIT_CONFIG_VALUE_${i}`] = '';
82
+ });
83
+ return env;
84
+ }
85
+ /**
86
+ * The command line and environment every git call of the gateway uses, reads and `git init` alike. `core.fsmonitor`
87
+ * is a command from the repository's config, so it is turned off for every call. A call that can run a clean filter
88
+ * (status) names the repository's `filter.*` keys in `blankFilterKeys` so no driver runs.
89
+ */
90
+ function hardenedGit(cwd, args, blankFilterKeys = []) {
91
+ return {
92
+ argv: ['--no-optional-locks', '-c', 'core.fsmonitor=false', ...args],
93
+ env: { ...gitEnv(), GIT_CEILING_DIRECTORIES: path.dirname(cwd), ...blankFilterEnv(blankFilterKeys) },
94
+ };
95
+ }
96
+ /** How long a timed-out git gets to clean up its lock files after SIGTERM before the group is killed. */
97
+ /** After git exits, how long its pipes get to deliver the rest of the output. */
98
+ const EXIT_DRAIN_MS = 200;
99
+ const KILL_GRACE_MS = 1000;
100
+ /**
101
+ * Runs git in the folder `cwd`. Discovery stops at `cwd`, so a folder inside some
102
+ * other repository never reads as a repo itself.
103
+ */
104
+ async function runGit(cwd, args, opts) {
105
+ const { argv, env } = hardenedGit(cwd, args, opts.blankFilterKeys);
106
+ return new Promise((resolve) => {
107
+ // Its own process group, so a timeout also reaches the hooks, filters and ssh that git started.
108
+ const child = (0, child_process_1.spawn)('git', argv, { cwd, env, detached: true, stdio: ['ignore', 'pipe', 'pipe'] });
109
+ const signalGroup = (signal) => {
110
+ try {
111
+ if (child.pid)
112
+ process.kill(-child.pid, signal);
113
+ }
114
+ catch {
115
+ // The group has already exited.
116
+ }
117
+ };
118
+ let settled = false;
119
+ const settle = (r) => {
120
+ if (settled)
121
+ return;
122
+ settled = true;
123
+ clearTimeout(timer);
124
+ resolve(r);
125
+ };
126
+ const stdout = [];
127
+ const stderr = [];
128
+ let size = 0;
129
+ const collect = (into) => (chunk) => {
130
+ size += chunk.length;
131
+ if (size > MAX_OUTPUT) {
132
+ signalGroup('SIGKILL');
133
+ return settle((0, result_1.err)('git_failed'));
134
+ }
135
+ into.push(chunk);
136
+ };
137
+ child.stdout.on('data', collect(stdout));
138
+ child.stderr.on('data', collect(stderr));
139
+ child.on('error', (e) => {
140
+ // ENOENT is also what a missing cwd gives, and the folder going away mid-read is not a missing git.
141
+ if (e.code === 'ENOENT' && (0, fs_1.existsSync)(cwd)) {
142
+ if (!warnedGitMissing) {
143
+ warnedGitMissing = true;
144
+ opts.logger.warn('git: git is not installed or not on PATH, so git status is unavailable');
145
+ }
146
+ return settle((0, result_1.err)('git_unavailable'));
147
+ }
148
+ opts.logger.warn(`git: git ${args[0]} in ${cwd} failed: ${(0, status_1.redactCredentials)(e.message)}`);
149
+ settle((0, result_1.err)('git_failed'));
150
+ });
151
+ const finish = (code) => {
152
+ if (code === null)
153
+ return settle((0, result_1.err)('git_failed'));
154
+ settle((0, result_1.ok)({ code, stdout: Buffer.concat(stdout).toString('utf8'), stdoutBytes: Buffer.concat(stdout), stderr: Buffer.concat(stderr).toString('utf8') }));
155
+ };
156
+ child.on('close', finish);
157
+ // A hook's backgrounded child keeps the pipes open long after git is done; take what arrived and let go.
158
+ child.on('exit', (code) => {
159
+ setTimeout(() => {
160
+ child.stdout.destroy();
161
+ child.stderr.destroy();
162
+ finish(code);
163
+ }, EXIT_DRAIN_MS).unref();
164
+ });
165
+ const timer = setTimeout(() => {
166
+ // TERM first: git removes its index.lock on TERM but leaves it behind on KILL.
167
+ signalGroup('SIGTERM');
168
+ setTimeout(() => signalGroup('SIGKILL'), KILL_GRACE_MS).unref();
169
+ // An orphan that escaped the group can still hold the pipes open; let go of them now.
170
+ child.stdout.destroy();
171
+ child.stderr.destroy();
172
+ settle((0, result_1.err)('timeout'));
173
+ }, opts.timeoutMs);
174
+ });
175
+ }
176
+ //# sourceMappingURL=runner.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runner.js","sourceRoot":"","sources":["../../src/git/runner.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,wBAGC;AA0BD,kCAKC;AAmBD,wBAsEC;AApKD,iDAAsC;AACtC,2BAAgC;AAChC,2CAA6B;AAC7B,4CAAkD;AAClD,qCAA6C;AAGhC,QAAA,mBAAmB,GAAG,IAAK,CAAC;AAEzC,MAAM,UAAU,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC;AAapC,IAAI,gBAAgB,GAAG,KAAK,CAAC;AAE7B;;;;;GAKG;AACH,MAAM,eAAe,GAAG,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,qBAAqB,CAAC,CAAC,CAAC;AAEhJ;;;;;;;;GAQG;AACH,SAAgB,MAAM;IACpB,MAAM,GAAG,GAAG,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,eAAe,CAAC,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