@andorra-labs/code 0.1.11 → 0.1.13

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 (614) hide show
  1. package/README.md +8 -2
  2. package/THIRD_PARTY_NOTICES.md +15 -0
  3. package/dist/src/account-presentation.d.ts +1 -37
  4. package/dist/src/account-presentation.js +2 -42
  5. package/dist/src/activity.d.ts +0 -25
  6. package/dist/src/activity.js +1 -23
  7. package/dist/src/agent-definitions.d.ts +0 -26
  8. package/dist/src/agent-definitions.js +0 -43
  9. package/dist/src/agent-execution.d.ts +0 -2
  10. package/dist/src/agent-execution.js +59 -414
  11. package/dist/src/agent-mcp-catalog.d.ts +0 -8
  12. package/dist/src/agent-mcp-catalog.js +0 -2
  13. package/dist/src/agent-mcp.d.ts +0 -56
  14. package/dist/src/agent-mcp.js +14 -153
  15. package/dist/src/agent-modifiers.d.ts +0 -1
  16. package/dist/src/agent-modifiers.js +25 -68
  17. package/dist/src/analytics.d.ts +0 -66
  18. package/dist/src/analytics.js +0 -45
  19. package/dist/src/anthropic-console-auth.d.ts +0 -24
  20. package/dist/src/anthropic-console-auth.js +0 -37
  21. package/dist/src/anthropic-credentials.d.ts +0 -25
  22. package/dist/src/anthropic-credentials.js +0 -28
  23. package/dist/src/app-server/protocol.d.ts +19 -244
  24. package/dist/src/app-server/protocol.js +1 -132
  25. package/dist/src/app-server/reasoning.d.ts +0 -31
  26. package/dist/src/app-server/reasoning.js +0 -54
  27. package/dist/src/app-server/terminal.d.ts +0 -36
  28. package/dist/src/app-server/terminal.js +3 -39
  29. package/dist/src/app-server/workspace.d.ts +0 -167
  30. package/dist/src/app-server/workspace.js +4 -406
  31. package/dist/src/app-server.d.ts +33 -918
  32. package/dist/src/app-server.js +608 -2984
  33. package/dist/src/artifacts.d.ts +0 -10
  34. package/dist/src/artifacts.js +1 -11
  35. package/dist/src/attachments.d.ts +4 -98
  36. package/dist/src/attachments.js +10 -130
  37. package/dist/src/auth/AuthManager.d.ts +0 -93
  38. package/dist/src/auth/AuthManager.js +3 -165
  39. package/dist/src/auth/callback-page.d.ts +0 -1
  40. package/dist/src/auth/callback-page.js +0 -4
  41. package/dist/src/auth/callback.d.ts +0 -25
  42. package/dist/src/auth/callback.js +1 -29
  43. package/dist/src/auth/deployment.d.ts +0 -16
  44. package/dist/src/auth/deployment.js +0 -16
  45. package/dist/src/auth/index.d.ts +0 -11
  46. package/dist/src/auth/index.js +0 -11
  47. package/dist/src/auth/lock.d.ts +0 -1
  48. package/dist/src/auth/lock.js +0 -1
  49. package/dist/src/auth/store.d.ts +7 -108
  50. package/dist/src/auth/store.js +21 -129
  51. package/dist/src/auth/types.d.ts +0 -8
  52. package/dist/src/auth-commands.d.ts +0 -5
  53. package/dist/src/auth-commands.js +0 -1
  54. package/dist/src/automation-runner.d.ts +0 -9
  55. package/dist/src/automation-runner.js +0 -11
  56. package/dist/src/automation-service.d.ts +0 -10
  57. package/dist/src/automation-service.js +3 -17
  58. package/dist/src/automation-tool.js +0 -5
  59. package/dist/src/automation-worker-shutdown.d.ts +0 -1
  60. package/dist/src/automation-worker-shutdown.js +0 -3
  61. package/dist/src/automations.d.ts +23 -2
  62. package/dist/src/automations.js +91 -12
  63. package/dist/src/background-tasks.d.ts +0 -23
  64. package/dist/src/background-tasks.js +0 -11
  65. package/dist/src/boot-trace.d.ts +0 -13
  66. package/dist/src/boot-trace.js +1 -14
  67. package/dist/src/browser-activity.js +0 -2
  68. package/dist/src/browser-bridge.d.ts +0 -2
  69. package/dist/src/browser-bridge.js +0 -27
  70. package/dist/src/browser-captcha-tool.d.ts +0 -13
  71. package/dist/src/browser-captcha-tool.js +3 -35
  72. package/dist/src/browser-extensions-tool.d.ts +24 -0
  73. package/dist/src/browser-extensions-tool.js +137 -0
  74. package/dist/src/browser-extensions.d.ts +127 -0
  75. package/dist/src/browser-extensions.js +729 -0
  76. package/dist/src/browser-observation.d.ts +0 -15
  77. package/dist/src/browser-observation.js +1 -22
  78. package/dist/src/browser-panel-tool.d.ts +10 -25
  79. package/dist/src/browser-panel-tool.js +64 -60
  80. package/dist/src/browser-runner.d.ts +0 -1
  81. package/dist/src/browser-runner.js +7 -46
  82. package/dist/src/browser-server.d.ts +0 -6
  83. package/dist/src/browser-server.js +6 -229
  84. package/dist/src/browser-session.d.ts +0 -25
  85. package/dist/src/browser-session.js +1 -71
  86. package/dist/src/browser-stealth.d.ts +0 -12
  87. package/dist/src/browser-stealth.js +0 -36
  88. package/dist/src/browser-ui/app.js +7 -174
  89. package/dist/src/browser-ui/style.css +0 -68
  90. package/dist/src/browser-ui/tokens.css +11 -93
  91. package/dist/src/browser-view.d.ts +52 -290
  92. package/dist/src/browser-view.js +354 -567
  93. package/dist/src/capabilities.d.ts +0 -8
  94. package/dist/src/capabilities.js +0 -29
  95. package/dist/src/capsolver.d.ts +0 -13
  96. package/dist/src/capsolver.js +0 -15
  97. package/dist/src/clarification-ui.d.ts +0 -7
  98. package/dist/src/clarification-ui.js +0 -8
  99. package/dist/src/claude-executable.d.ts +0 -1
  100. package/dist/src/claude-executable.js +1 -2
  101. package/dist/src/claude-provider.d.ts +6 -19
  102. package/dist/src/claude-provider.js +166 -61
  103. package/dist/src/cli-executable.d.ts +0 -16
  104. package/dist/src/cli-executable.js +0 -7
  105. package/dist/src/cli-process.d.ts +0 -26
  106. package/dist/src/cli-process.js +0 -18
  107. package/dist/src/cli-sign-in.d.ts +0 -20
  108. package/dist/src/cli-sign-in.js +1 -17
  109. package/dist/src/cli.d.ts +3 -56
  110. package/dist/src/cli.js +193 -702
  111. package/dist/src/code-intelligence/CodeIntelligenceManager.d.ts +4 -59
  112. package/dist/src/code-intelligence/CodeIntelligenceManager.js +27 -100
  113. package/dist/src/code-intelligence/ContextLedger.d.ts +0 -4
  114. package/dist/src/code-intelligence/ContextLedger.js +0 -10
  115. package/dist/src/code-intelligence/ContextRouter.d.ts +0 -6
  116. package/dist/src/code-intelligence/ContextRouter.js +0 -8
  117. package/dist/src/code-intelligence/codegraph/CodeGraphProjectSession.d.ts +0 -2
  118. package/dist/src/code-intelligence/codegraph/CodeGraphProjectSession.js +5 -12
  119. package/dist/src/code-intelligence/codegraph/CodeGraphProvider.d.ts +0 -6
  120. package/dist/src/code-intelligence/codegraph/CodeGraphProvider.js +0 -6
  121. package/dist/src/code-intelligence/codegraph/CodeGraphSyncBarrier.d.ts +0 -5
  122. package/dist/src/code-intelligence/codegraph/CodeGraphSyncBarrier.js +1 -17
  123. package/dist/src/code-intelligence/codegraph/repoExploreTool.d.ts +0 -5
  124. package/dist/src/code-intelligence/codegraph/repoExploreTool.js +0 -5
  125. package/dist/src/code-intelligence/repository.d.ts +0 -9
  126. package/dist/src/code-intelligence/repository.js +1 -11
  127. package/dist/src/code-intelligence/types.d.ts +0 -8
  128. package/dist/src/codex-auth.d.ts +0 -44
  129. package/dist/src/codex-auth.js +0 -45
  130. package/dist/src/codex-browser-auth.d.ts +0 -13
  131. package/dist/src/codex-browser-auth.js +3 -20
  132. package/dist/src/codex-errors.js +0 -2
  133. package/dist/src/codex-executable.d.ts +0 -2
  134. package/dist/src/codex-executable.js +1 -7
  135. package/dist/src/codex-provider.d.ts +0 -13
  136. package/dist/src/codex-provider.js +1 -26
  137. package/dist/src/codex-rpc.d.ts +0 -10
  138. package/dist/src/codex-rpc.js +0 -12
  139. package/dist/src/coding-tools.d.ts +6 -27
  140. package/dist/src/coding-tools.js +193 -205
  141. package/dist/src/command-metrics.d.ts +0 -4
  142. package/dist/src/command-output-tap.d.ts +0 -11
  143. package/dist/src/command-output-tap.js +0 -3
  144. package/dist/src/command-screens.d.ts +24 -0
  145. package/dist/src/command-screens.js +132 -100
  146. package/dist/src/commands.d.ts +6 -63
  147. package/dist/src/commands.js +20 -100
  148. package/dist/src/completion-gates.d.ts +0 -47
  149. package/dist/src/completion-gates.js +0 -14
  150. package/dist/src/completion.d.ts +2 -58
  151. package/dist/src/completion.js +90 -186
  152. package/dist/src/config.d.ts +12 -116
  153. package/dist/src/config.js +41 -171
  154. package/dist/src/context-budget.d.ts +0 -22
  155. package/dist/src/context-budget.js +0 -44
  156. package/dist/src/context-compaction.d.ts +29 -6
  157. package/dist/src/context-compaction.js +94 -25
  158. package/dist/src/context-selection.d.ts +0 -24
  159. package/dist/src/context-selection.js +0 -34
  160. package/dist/src/dashboard-view.d.ts +0 -2
  161. package/dist/src/dashboard-view.js +0 -35
  162. package/dist/src/dashboard.d.ts +0 -2
  163. package/dist/src/dashboard.js +0 -9
  164. package/dist/src/deadline.d.ts +0 -45
  165. package/dist/src/deadline.js +0 -54
  166. package/dist/src/decision/ContinuationAdapter.d.ts +0 -5
  167. package/dist/src/decision/ContinuationAdapter.js +0 -5
  168. package/dist/src/decision/DecisionEngine.d.ts +0 -4
  169. package/dist/src/decision/DecisionManager.d.ts +0 -1
  170. package/dist/src/decision/DecisionManager.js +2 -7
  171. package/dist/src/decision/DecisionPolicy.d.ts +0 -1
  172. package/dist/src/decision/DecisionPolicy.js +0 -1
  173. package/dist/src/decision/FactContinuations.d.ts +11 -43
  174. package/dist/src/decision/FactContinuations.js +126 -95
  175. package/dist/src/decision/FactServiceGate.d.ts +0 -1
  176. package/dist/src/decision/FactServiceGate.js +0 -4
  177. package/dist/src/decision/PreparedSteps.d.ts +0 -15
  178. package/dist/src/decision/PreparedSteps.js +1 -11
  179. package/dist/src/decision/applyToolMenu.d.ts +0 -1
  180. package/dist/src/decision/applyToolMenu.js +1 -5
  181. package/dist/src/decision/checks.d.ts +15 -28
  182. package/dist/src/decision/checks.js +118 -49
  183. package/dist/src/decision/facts.d.ts +0 -16
  184. package/dist/src/decision/facts.js +0 -30
  185. package/dist/src/decision/guidancePolicy.js +0 -1
  186. package/dist/src/decision/hostedPolicy.d.ts +0 -6
  187. package/dist/src/decision/hostedPolicy.js +0 -7
  188. package/dist/src/decision/hostedSkills.d.ts +0 -19
  189. package/dist/src/decision/hostedSkills.js +0 -19
  190. package/dist/src/decision/optimizationPolicy.d.ts +0 -3
  191. package/dist/src/decision/optimizationPolicy.js +1 -4
  192. package/dist/src/decision/providers/AndorraDecisionProvider.d.ts +0 -7
  193. package/dist/src/decision/providers/AndorraDecisionProvider.js +4 -27
  194. package/dist/src/decision/providers/HttpDecisionProvider.d.ts +0 -2
  195. package/dist/src/decision/providers/HttpDecisionProvider.js +0 -6
  196. package/dist/src/decision/routeTools.d.ts +0 -8
  197. package/dist/src/decision/routeTools.js +1 -8
  198. package/dist/src/decision/toolFamilies.d.ts +0 -1
  199. package/dist/src/decision/toolFamilies.js +0 -1
  200. package/dist/src/decision/toolMenu.d.ts +0 -3
  201. package/dist/src/decision/toolMenu.js +0 -4
  202. package/dist/src/decision/types.d.ts +0 -6
  203. package/dist/src/default-graph.d.ts +0 -9
  204. package/dist/src/default-graph.js +0 -9
  205. package/dist/src/delegation-changes.d.ts +0 -56
  206. package/dist/src/delegation-changes.js +15 -124
  207. package/dist/src/diff-preview.d.ts +1 -1
  208. package/dist/src/diff-preview.js +4 -12
  209. package/dist/src/duration.d.ts +0 -50
  210. package/dist/src/duration.js +0 -50
  211. package/dist/src/efficiency.d.ts +0 -39
  212. package/dist/src/efficiency.js +0 -16
  213. package/dist/src/engine/protocol.d.ts +0 -2
  214. package/dist/src/engine/protocol.js +0 -2
  215. package/dist/src/engine-streams.d.ts +13 -0
  216. package/dist/src/engine-streams.js +16 -0
  217. package/dist/src/extensions.d.ts +3 -2
  218. package/dist/src/extensions.js +76 -37
  219. package/dist/src/favicons.d.ts +0 -26
  220. package/dist/src/favicons.js +0 -34
  221. package/dist/src/file-diff.d.ts +2 -58
  222. package/dist/src/file-diff.js +0 -32
  223. package/dist/src/file-read-key.d.ts +1 -0
  224. package/dist/src/file-read-key.js +5 -0
  225. package/dist/src/file-read-state.d.ts +0 -1
  226. package/dist/src/file-read-state.js +0 -4
  227. package/dist/src/firefox-cookies.d.ts +0 -34
  228. package/dist/src/firefox-cookies.js +1 -55
  229. package/dist/src/git-identity-audit.d.ts +27 -0
  230. package/dist/src/git-identity-audit.js +286 -0
  231. package/dist/src/git-identity-guard.d.ts +4 -0
  232. package/dist/src/git-identity-guard.js +998 -0
  233. package/dist/src/git-identity-hold.d.ts +12 -0
  234. package/dist/src/git-identity-hold.js +81 -0
  235. package/dist/src/git-summary.d.ts +0 -58
  236. package/dist/src/git-summary.js +2 -212
  237. package/dist/src/goal-completion-verification.d.ts +2 -2
  238. package/dist/src/goal-completion-verification.js +3 -6
  239. package/dist/src/graph-account.d.ts +0 -21
  240. package/dist/src/graph-account.js +0 -17
  241. package/dist/src/graph-editor-session.d.ts +0 -1
  242. package/dist/src/graph-editor-session.js +1 -3
  243. package/dist/src/graph-health.d.ts +7 -49
  244. package/dist/src/graph-health.js +35 -46
  245. package/dist/src/graph-manager-chat.d.ts +27 -128
  246. package/dist/src/graph-manager-chat.js +36 -166
  247. package/dist/src/graph-provider-portability.d.ts +1 -21
  248. package/dist/src/graph-provider-portability.js +6 -45
  249. package/dist/src/graph-quota.d.ts +0 -33
  250. package/dist/src/graph-quota.js +1 -44
  251. package/dist/src/graph-runner.d.ts +0 -1
  252. package/dist/src/graph-runner.js +47 -387
  253. package/dist/src/graph-selection.d.ts +0 -14
  254. package/dist/src/graph-selection.js +0 -14
  255. package/dist/src/graph-server.d.ts +3 -11
  256. package/dist/src/graph-server.js +70 -111
  257. package/dist/src/graph-studio-features.d.ts +0 -5
  258. package/dist/src/graph-studio-features.js +2 -42
  259. package/dist/src/graph-sync.d.ts +0 -78
  260. package/dist/src/graph-sync.js +5 -201
  261. package/dist/src/graph-tool.d.ts +0 -18
  262. package/dist/src/graph-tool.js +0 -27
  263. package/dist/src/graph-ui/app.js +229 -498
  264. package/dist/src/graph-ui/compat.js +0 -7
  265. package/dist/src/graph-ui/controls.css +47 -43
  266. package/dist/src/graph-ui/controls.js +0 -88
  267. package/dist/src/graph-ui/drafts.js +0 -12
  268. package/dist/src/graph-ui/edge-router.js +0 -62
  269. package/dist/src/graph-ui/embed.js +0 -59
  270. package/dist/src/graph-ui/icons.js +2 -7
  271. package/dist/src/graph-ui/index.html +2 -2
  272. package/dist/src/graph-ui/library.css +0 -5
  273. package/dist/src/graph-ui/manager-markdown.js +0 -11
  274. package/dist/src/graph-ui/manager-state.js +110 -49
  275. package/dist/src/graph-ui/manager.css +2 -20
  276. package/dist/src/graph-ui/manager.js +251 -166
  277. package/dist/src/graph-ui/model-picker.js +250 -0
  278. package/dist/src/graph-ui/provider-glyphs/alibaba-cloud.png +0 -0
  279. package/dist/src/graph-ui/provider-glyphs/anthropic.png +0 -0
  280. package/dist/src/graph-ui/provider-glyphs/aws-bedrock.png +0 -0
  281. package/dist/src/graph-ui/provider-glyphs/claude.png +0 -0
  282. package/dist/src/graph-ui/provider-glyphs/deepseek.png +0 -0
  283. package/dist/src/graph-ui/provider-glyphs/fireworks.png +0 -0
  284. package/dist/src/graph-ui/provider-glyphs/kimi.png +0 -0
  285. package/dist/src/graph-ui/provider-glyphs/minimax.png +0 -0
  286. package/dist/src/graph-ui/provider-glyphs/openai.png +0 -0
  287. package/dist/src/graph-ui/provider-glyphs/opencode.png +0 -0
  288. package/dist/src/graph-ui/provider-glyphs/openrouter.png +0 -0
  289. package/dist/src/graph-ui/provider-glyphs/xai.png +0 -0
  290. package/dist/src/graph-ui/provider-glyphs/xiaomi-mimo.png +0 -0
  291. package/dist/src/graph-ui/provider-glyphs/zai.png +0 -0
  292. package/dist/src/graph-ui/sidebar.js +2 -3
  293. package/dist/src/graph-ui/skill-picker.js +373 -39
  294. package/dist/src/graph-ui/studio-canvas.js +3 -38
  295. package/dist/src/graph-ui/studio.css +0 -18
  296. package/dist/src/graph-ui/studio.js +3 -71
  297. package/dist/src/graph-ui/style.css +11 -134
  298. package/dist/src/graph-ui/theme.js +1 -26
  299. package/dist/src/graph-ui/tokens.css +15 -114
  300. package/dist/src/graphs.d.ts +7 -156
  301. package/dist/src/graphs.js +72 -273
  302. package/dist/src/grep-regex-worker.js +0 -2
  303. package/dist/src/grep-regex.d.ts +1 -5
  304. package/dist/src/grep-regex.js +6 -8
  305. package/dist/src/grok-provider.d.ts +0 -17
  306. package/dist/src/grok-provider.js +1 -26
  307. package/dist/src/handoffs.d.ts +0 -11
  308. package/dist/src/handoffs.js +0 -13
  309. package/dist/src/hardened-runtime.d.ts +0 -10
  310. package/dist/src/hardened-runtime.js +8 -46
  311. package/dist/src/harness-home.d.ts +21 -0
  312. package/dist/src/harness-home.js +87 -0
  313. package/dist/src/host-process-guard.d.ts +0 -50
  314. package/dist/src/host-process-guard.js +0 -641
  315. package/dist/src/limits.d.ts +0 -64
  316. package/dist/src/limits.js +0 -62
  317. package/dist/src/managed-sign-in.d.ts +0 -12
  318. package/dist/src/managed-sign-in.js +0 -16
  319. package/dist/src/markdown.d.ts +0 -28
  320. package/dist/src/markdown.js +1 -175
  321. package/dist/src/mcp.d.ts +21 -82
  322. package/dist/src/mcp.js +228 -237
  323. package/dist/src/membership-errors.d.ts +0 -14
  324. package/dist/src/membership-errors.js +0 -13
  325. package/dist/src/membership.d.ts +2 -60
  326. package/dist/src/membership.js +0 -85
  327. package/dist/src/memory/LocalToolMemory.d.ts +0 -1
  328. package/dist/src/memory/LocalToolMemory.js +2 -7
  329. package/dist/src/memory/MemoryDistiller.js +0 -15
  330. package/dist/src/memory/MemoryManager.d.ts +0 -3
  331. package/dist/src/memory/MemoryManager.js +6 -18
  332. package/dist/src/memory/MemoryPolicy.d.ts +0 -2
  333. package/dist/src/memory/MemoryPolicy.js +0 -2
  334. package/dist/src/memory/MemoryProvider.d.ts +0 -6
  335. package/dist/src/memory/MemoryRetriever.js +0 -7
  336. package/dist/src/memory/PermissionMemoryProvider.d.ts +0 -1
  337. package/dist/src/memory/PermissionMemoryProvider.js +0 -1
  338. package/dist/src/memory/ProjectMemory.d.ts +42 -0
  339. package/dist/src/memory/ProjectMemory.js +285 -0
  340. package/dist/src/memory/ToolFailureLessons.d.ts +0 -3
  341. package/dist/src/memory/ToolFailureLessons.js +0 -6
  342. package/dist/src/memory/index.d.ts +1 -0
  343. package/dist/src/memory/index.js +1 -0
  344. package/dist/src/memory/providers/NoOpMemoryProvider.d.ts +0 -1
  345. package/dist/src/memory/providers/NoOpMemoryProvider.js +0 -1
  346. package/dist/src/memory/redaction.d.ts +0 -5
  347. package/dist/src/memory/redaction.js +0 -11
  348. package/dist/src/memory/repository.d.ts +0 -6
  349. package/dist/src/memory/repository.js +2 -12
  350. package/dist/src/memory/types.d.ts +0 -1
  351. package/dist/src/model-health-cache.d.ts +0 -38
  352. package/dist/src/model-health-cache.js +1 -49
  353. package/dist/src/model-metadata.d.ts +0 -18
  354. package/dist/src/model-metadata.js +2 -42
  355. package/dist/src/model-override.d.ts +0 -36
  356. package/dist/src/model-override.js +0 -43
  357. package/dist/src/model-tiers.d.ts +0 -13
  358. package/dist/src/model-tiers.js +0 -23
  359. package/dist/src/opencode-catalog.d.ts +0 -2
  360. package/dist/src/opencode-catalog.js +0 -11
  361. package/dist/src/opencode-cli-provider.d.ts +0 -35
  362. package/dist/src/opencode-cli-provider.js +1 -44
  363. package/dist/src/opencode-provider.d.ts +0 -2
  364. package/dist/src/opencode-provider.js +6 -22
  365. package/dist/src/package-name.d.ts +1 -0
  366. package/dist/src/package-name.js +1 -0
  367. package/dist/src/paged-transcript.d.ts +0 -11
  368. package/dist/src/paged-transcript.js +2 -20
  369. package/dist/src/palette.d.ts +0 -63
  370. package/dist/src/palette.js +0 -63
  371. package/dist/src/permissions.d.ts +0 -15
  372. package/dist/src/permissions.js +0 -17
  373. package/dist/src/powershell-pool.d.ts +0 -9
  374. package/dist/src/powershell-pool.js +3 -26
  375. package/dist/src/process-warnings.d.ts +4 -0
  376. package/dist/src/process-warnings.js +103 -0
  377. package/dist/src/profile.d.ts +0 -43
  378. package/dist/src/profile.js +0 -43
  379. package/dist/src/project-reservation.d.ts +11 -0
  380. package/dist/src/project-reservation.js +143 -0
  381. package/dist/src/provider-connection.d.ts +0 -18
  382. package/dist/src/provider-connection.js +0 -39
  383. package/dist/src/provider-engine.d.ts +0 -21
  384. package/dist/src/provider-engine.js +3 -98
  385. package/dist/src/provider-import.d.ts +0 -49
  386. package/dist/src/provider-import.js +0 -60
  387. package/dist/src/provider-keys.d.ts +1 -36
  388. package/dist/src/provider-keys.js +5 -48
  389. package/dist/src/provider-settings.d.ts +0 -2
  390. package/dist/src/provider-settings.js +0 -32
  391. package/dist/src/providers.d.ts +0 -217
  392. package/dist/src/providers.js +0 -315
  393. package/dist/src/pull-requests.d.ts +0 -173
  394. package/dist/src/pull-requests.js +5 -195
  395. package/dist/src/qa/browser/PlaywrightRunner.d.ts +0 -7
  396. package/dist/src/qa/browser/PlaywrightRunner.js +2 -16
  397. package/dist/src/qa/command-policy.d.ts +0 -23
  398. package/dist/src/qa/command-policy.js +0 -30
  399. package/dist/src/qa/guidance.d.ts +0 -21
  400. package/dist/src/qa/guidance.js +0 -20
  401. package/dist/src/qa/profile/ProjectInspector.d.ts +0 -4
  402. package/dist/src/qa/profile/ProjectInspector.js +0 -6
  403. package/dist/src/qa/profile/QaConfigLoader.d.ts +0 -7
  404. package/dist/src/qa/profile/QaConfigLoader.js +0 -6
  405. package/dist/src/qa/profile/QaProfile.d.ts +0 -7
  406. package/dist/src/qa/profile/QaProfile.js +0 -7
  407. package/dist/src/qa/profile/yaml.d.ts +0 -9
  408. package/dist/src/qa/profile/yaml.js +0 -13
  409. package/dist/src/qa/qa-authorize.d.ts +0 -19
  410. package/dist/src/qa/qa-authorize.js +4 -11
  411. package/dist/src/qa/runtime/ProcessManager.d.ts +0 -31
  412. package/dist/src/qa/runtime/ProcessManager.js +4 -41
  413. package/dist/src/qa/runtime/PtyManager.d.ts +0 -4
  414. package/dist/src/qa/runtime/PtyManager.js +2 -7
  415. package/dist/src/qa/runtime/changes.d.ts +0 -11
  416. package/dist/src/qa/runtime/changes.js +1 -3
  417. package/dist/src/qa/tools.d.ts +0 -10
  418. package/dist/src/qa/tools.js +0 -12
  419. package/dist/src/qa/types.d.ts +0 -13
  420. package/dist/src/react-runtime.d.ts +2 -21
  421. package/dist/src/react-runtime.js +106 -418
  422. package/dist/src/read-document-doc.d.ts +0 -6
  423. package/dist/src/read-document-doc.js +0 -55
  424. package/dist/src/read-document-docx.d.ts +0 -16
  425. package/dist/src/read-document-docx.js +2 -69
  426. package/dist/src/read-document-text.d.ts +0 -17
  427. package/dist/src/read-document-text.js +0 -22
  428. package/dist/src/read-document-tool.d.ts +0 -31
  429. package/dist/src/read-document-tool.js +0 -30
  430. package/dist/src/read-document.d.ts +0 -49
  431. package/dist/src/read-document.js +1 -67
  432. package/dist/src/read-image.d.ts +0 -32
  433. package/dist/src/read-image.js +0 -33
  434. package/dist/src/remote/cert.d.ts +1 -19
  435. package/dist/src/remote/cert.js +2 -51
  436. package/dist/src/remote/client.d.ts +0 -70
  437. package/dist/src/remote/client.js +2 -117
  438. package/dist/src/remote/command.js +0 -17
  439. package/dist/src/remote/engine-pool.d.ts +0 -152
  440. package/dist/src/remote/engine-pool.js +17 -335
  441. package/dist/src/remote/errors.d.ts +0 -15
  442. package/dist/src/remote/errors.js +0 -7
  443. package/dist/src/remote/network.d.ts +0 -26
  444. package/dist/src/remote/network.js +1 -34
  445. package/dist/src/remote/pairing.d.ts +16 -51
  446. package/dist/src/remote/pairing.js +50 -57
  447. package/dist/src/remote/pem.d.ts +2 -0
  448. package/dist/src/remote/pem.js +7 -0
  449. package/dist/src/remote/roots.d.ts +0 -20
  450. package/dist/src/remote/roots.js +0 -8
  451. package/dist/src/remote/serve.d.ts +0 -47
  452. package/dist/src/remote/serve.js +0 -30
  453. package/dist/src/remote/server.d.ts +0 -14
  454. package/dist/src/remote/server.js +1 -79
  455. package/dist/src/remote/types.d.ts +1 -32
  456. package/dist/src/remote/types.js +0 -10
  457. package/dist/src/run-control.d.ts +0 -7
  458. package/dist/src/run-control.js +0 -7
  459. package/dist/src/run-progress.d.ts +0 -170
  460. package/dist/src/run-progress.js +0 -285
  461. package/dist/src/run-records.d.ts +0 -443
  462. package/dist/src/run-records.js +44 -678
  463. package/dist/src/run-temp.d.ts +12 -0
  464. package/dist/src/run-temp.js +50 -0
  465. package/dist/src/runtime.d.ts +11 -227
  466. package/dist/src/runtime.js +0 -127
  467. package/dist/src/sandbox-child.js +0 -1
  468. package/dist/src/save-lock.d.ts +0 -12
  469. package/dist/src/save-lock.js +0 -28
  470. package/dist/src/screen-selection.d.ts +0 -23
  471. package/dist/src/screen-selection.js +0 -22
  472. package/dist/src/secret-redaction.d.ts +0 -12
  473. package/dist/src/secret-redaction.js +0 -45
  474. package/dist/src/session-changes.d.ts +4 -80
  475. package/dist/src/session-changes.js +25 -130
  476. package/dist/src/session-goal.d.ts +129 -0
  477. package/dist/src/session-goal.js +230 -0
  478. package/dist/src/session-monitor.d.ts +1 -10
  479. package/dist/src/session-monitor.js +2 -39
  480. package/dist/src/session-reaper.d.ts +0 -15
  481. package/dist/src/session-reaper.js +0 -14
  482. package/dist/src/session-skills.d.ts +15 -44
  483. package/dist/src/session-skills.js +75 -60
  484. package/dist/src/session-summary.d.ts +0 -26
  485. package/dist/src/session-summary.js +0 -32
  486. package/dist/src/session-title.d.ts +0 -1
  487. package/dist/src/session-title.js +0 -2
  488. package/dist/src/sessions.d.ts +2 -120
  489. package/dist/src/sessions.js +9 -178
  490. package/dist/src/shell.d.ts +3 -20
  491. package/dist/src/shell.js +8 -72
  492. package/dist/src/side-panel.d.ts +5 -99
  493. package/dist/src/side-panel.js +76 -133
  494. package/dist/src/sign-in-detection.d.ts +43 -0
  495. package/dist/src/sign-in-detection.js +154 -0
  496. package/dist/src/sign-in-offer.d.ts +17 -0
  497. package/dist/src/sign-in-offer.js +103 -0
  498. package/dist/src/skill-commands.d.ts +0 -1
  499. package/dist/src/skill-commands.js +1 -4
  500. package/dist/src/skills/bundled/control-browser/SKILL.md +1 -1
  501. package/dist/src/skills/bundled/graph-manager/SKILL.md +22 -4
  502. package/dist/src/skills/bundled/provenance.json +2 -2
  503. package/dist/src/skills/invocable-skills.d.ts +0 -18
  504. package/dist/src/skills/invocable-skills.js +0 -17
  505. package/dist/src/skills/project-skills.d.ts +0 -1
  506. package/dist/src/skills/project-skills.js +0 -3
  507. package/dist/src/skills/prompt-skills.js +0 -14
  508. package/dist/src/skills/runtime-skills.d.ts +1 -8
  509. package/dist/src/skills/runtime-skills.js +8 -32
  510. package/dist/src/stall-recovery.d.ts +0 -25
  511. package/dist/src/stall-recovery.js +0 -38
  512. package/dist/src/stray-files.d.ts +5 -0
  513. package/dist/src/stray-files.js +65 -0
  514. package/dist/src/structured-step.d.ts +0 -22
  515. package/dist/src/structured-step.js +0 -22
  516. package/dist/src/subagent-run.d.ts +0 -163
  517. package/dist/src/subagent-run.js +10 -374
  518. package/dist/src/subagent-tree.d.ts +32 -0
  519. package/dist/src/subagent-tree.js +128 -0
  520. package/dist/src/telemetry/aggregate.d.ts +0 -37
  521. package/dist/src/telemetry/aggregate.js +0 -40
  522. package/dist/src/telemetry/capture-core.d.ts +0 -87
  523. package/dist/src/telemetry/capture-core.js +0 -67
  524. package/dist/src/telemetry/capture.d.ts +0 -1
  525. package/dist/src/telemetry/capture.js +0 -3
  526. package/dist/src/telemetry/classify.d.ts +0 -58
  527. package/dist/src/telemetry/classify.js +0 -60
  528. package/dist/src/telemetry/decision-capture.d.ts +0 -1
  529. package/dist/src/telemetry/emitter.d.ts +0 -30
  530. package/dist/src/telemetry/emitter.js +1 -62
  531. package/dist/src/telemetry/gate.d.ts +0 -29
  532. package/dist/src/telemetry/gate.js +0 -22
  533. package/dist/src/telemetry/identity.d.ts +0 -13
  534. package/dist/src/telemetry/identity.js +0 -29
  535. package/dist/src/telemetry/outbox.d.ts +0 -64
  536. package/dist/src/telemetry/outbox.js +1 -108
  537. package/dist/src/telemetry/schema.d.ts +1 -49
  538. package/dist/src/telemetry/schema.js +1 -82
  539. package/dist/src/telemetry/state.d.ts +0 -53
  540. package/dist/src/telemetry/state.js +0 -64
  541. package/dist/src/telemetry/surface.d.ts +0 -31
  542. package/dist/src/telemetry/surface.js +1 -39
  543. package/dist/src/telemetry/uploader.d.ts +0 -11
  544. package/dist/src/telemetry/uploader.js +0 -46
  545. package/dist/src/telemetry/uploads.d.ts +0 -11
  546. package/dist/src/telemetry/uploads.js +0 -11
  547. package/dist/src/telemetry/version.d.ts +0 -4
  548. package/dist/src/telemetry/version.js +0 -14
  549. package/dist/src/telemetry/workspace.d.ts +0 -7
  550. package/dist/src/telemetry/workspace.js +1 -22
  551. package/dist/src/terminal-ui.d.ts +15 -524
  552. package/dist/src/terminal-ui.js +80 -876
  553. package/dist/src/test-edit-guard.d.ts +74 -0
  554. package/dist/src/test-edit-guard.js +269 -0
  555. package/dist/src/text.d.ts +0 -1
  556. package/dist/src/text.js +0 -1
  557. package/dist/src/time-limit.d.ts +0 -36
  558. package/dist/src/time-limit.js +0 -37
  559. package/dist/src/timers.d.ts +0 -161
  560. package/dist/src/timers.js +0 -126
  561. package/dist/src/todos.d.ts +0 -1
  562. package/dist/src/todos.js +0 -3
  563. package/dist/src/token-rate.d.ts +0 -94
  564. package/dist/src/token-rate.js +0 -154
  565. package/dist/src/tool-activity.d.ts +0 -6
  566. package/dist/src/tool-activity.js +1 -8
  567. package/dist/src/tool-availability.d.ts +0 -13
  568. package/dist/src/tool-availability.js +1 -14
  569. package/dist/src/tool-call-clock.d.ts +1 -4
  570. package/dist/src/tool-call-clock.js +0 -13
  571. package/dist/src/tool-catalog.d.ts +0 -11
  572. package/dist/src/tool-catalog.js +0 -23
  573. package/dist/src/tool-dependencies.d.ts +0 -5
  574. package/dist/src/tool-dependencies.js +0 -4
  575. package/dist/src/tool-diff-stats.d.ts +0 -23
  576. package/dist/src/tool-diff-stats.js +0 -49
  577. package/dist/src/tool-errors.d.ts +9 -7
  578. package/dist/src/tool-errors.js +13 -6
  579. package/dist/src/tool-failure-tracker.d.ts +3 -11
  580. package/dist/src/tool-failure-tracker.js +19 -27
  581. package/dist/src/tool-names.d.ts +0 -16
  582. package/dist/src/tool-names.js +0 -12
  583. package/dist/src/tool-profile.d.ts +6 -0
  584. package/dist/src/tool-profile.js +23 -0
  585. package/dist/src/tool-result-filter.d.ts +0 -19
  586. package/dist/src/tool-result-filter.js +1 -66
  587. package/dist/src/tool-schema-compatibility.d.ts +1 -2
  588. package/dist/src/tool-schema-compatibility.js +2 -7
  589. package/dist/src/tools.d.ts +0 -4
  590. package/dist/src/tools.js +11 -114
  591. package/dist/src/trajectory.d.ts +0 -13
  592. package/dist/src/trajectory.js +23 -79
  593. package/dist/src/transcript.d.ts +1 -37
  594. package/dist/src/transcript.js +11 -61
  595. package/dist/src/types.d.ts +2 -167
  596. package/dist/src/untracked-file-removal.d.ts +3 -0
  597. package/dist/src/untracked-file-removal.js +105 -0
  598. package/dist/src/update-check.d.ts +0 -14
  599. package/dist/src/update-check.js +2 -16
  600. package/dist/src/update.d.ts +4 -29
  601. package/dist/src/update.js +20 -98
  602. package/dist/src/usage-analytics.d.ts +17 -17
  603. package/dist/src/usage-analytics.js +168 -209
  604. package/dist/src/web-search.d.ts +0 -23
  605. package/dist/src/web-search.js +1 -27
  606. package/dist/src/widgets.d.ts +0 -25
  607. package/dist/src/widgets.js +0 -24
  608. package/dist/src/workspace-facts.d.ts +0 -12
  609. package/dist/src/workspace-facts.js +1 -18
  610. package/dist/src/workspace-git-metadata.d.ts +4 -5
  611. package/dist/src/workspace-git-metadata.js +37 -9
  612. package/dist/src/workspace-instructions.d.ts +3 -15
  613. package/dist/src/workspace-instructions.js +7 -20
  614. package/package.json +2 -2
@@ -0,0 +1,998 @@
1
+ // Refuses agent commands that commit under an identity other than the configured one.
2
+ //
3
+ // On 2026-11-18 a model ran `git -c user.name="mnishniak" -c user.email="4164738+mnishniak@users.noreply.github.com" commit`
4
+ // and pushed it. GitHub reads the leading number of a noreply address as an account id, so the commit
5
+ // was credited to an unrelated GitHub user. Commits made by the agent must carry the identity the user
6
+ // configured in git; nothing the agent types may replace it.
7
+ const IDENTITY_KEY = String.raw `(?:user|author|committer)\.(?:name|email)`;
8
+ const IDENTITY_VARIABLE = String.raw `GIT_(?:AUTHOR|COMMITTER)_(?:NAME|EMAIL)`;
9
+ // `scriptOnly` rules match only inside a script an interpreter runs; in shell text git's own arguments are
10
+ // parsed instead, so `Select-String -Pattern 'git -c user.name=x'` only searches.
11
+ const RULES = [
12
+ // git -c user.name=x, -c"user.email=x", --config-env=user.name=VAR
13
+ { pattern: new RegExp(String.raw `(?:^|[\s"'(\[,])-c(?:["']?\s*,)?\s*["']?${IDENTITY_KEY}=`, 'i'), what: 'a -c override of the git identity', scriptOnly: true },
14
+ { pattern: new RegExp(String.raw `--config-env\s*=?\s*["']?${IDENTITY_KEY}=`, 'i'), what: 'a --config-env override of the git identity', scriptOnly: true },
15
+ // GIT_AUTHOR_NAME=x, $env:GIT_AUTHOR_NAME = 'x', set GIT_COMMITTER_EMAIL=x, os.environ["GIT_AUTHOR_NAME"] = x, { GIT_AUTHOR_EMAIL: 'x' }
16
+ { pattern: new RegExp(String.raw `\b${IDENTITY_VARIABLE}["'\]]*\s*(?:\+?=(?!=)|:(?!:))`, 'i'), what: 'a GIT_AUTHOR_* or GIT_COMMITTER_* variable' },
17
+ { pattern: new RegExp(String.raw `\b(?:set-item|new-item|si|ni)\s+(?:-path\s+)?["']?env:${IDENTITY_VARIABLE}\b`, 'i'), what: 'a GIT_AUTHOR_* or GIT_COMMITTER_* variable' },
18
+ // GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=user.email GIT_CONFIG_VALUE_0=x, and GIT_CONFIG_PARAMETERS="'user.name'='x'":
19
+ // configuration supplied through the environment overrides the config files.
20
+ { pattern: new RegExp(String.raw `\bGIT_CONFIG_KEY_\d+["'\]]*\s*(?:\+?=|:)\s*["']?${IDENTITY_KEY}\b`, 'i'), what: 'a GIT_CONFIG_KEY_* override of the git identity' },
21
+ { pattern: new RegExp(String.raw `\bGIT_CONFIG_PARAMETERS\b[^\n]*?${IDENTITY_KEY}\b`, 'i'), what: 'a GIT_CONFIG_PARAMETERS override of the git identity' },
22
+ ];
23
+ // commit --author and filter-repo rewrites are found by parsing git's arguments (segmentIdentity, inlineGitArgv),
24
+ // never by matching the words in text, so `git log --grep=commit --author=Mark` stays a read.
25
+ const GIT_PROGRAM = /(?:^|[\\/])git(?:\.exe)?$/i;
26
+ // The actions that read or remove a value. Output-format flags such as -z, --null or --show-origin
27
+ // do not choose an action, so `git config -z user.email x` still writes.
28
+ const NON_WRITING_CONFIG_ACTIONS = new Set(['--get', '--get-all', '--get-regexp', '--get-urlmatch', '--get-color', '--get-colorbool', '--list', '-l',
29
+ '--unset', '--unset-all', '--remove-section', '--edit', '-e', 'get', 'list', 'unset', 'remove-section', 'edit']);
30
+ const CONFIG_VALUE_OPTIONS = new Set(['-f', '--file', '--blob', '--type', '--default', '--comment', '--value', '--url']);
31
+ const CONFIG_LONG_OPTIONS = ['--global', '--system', '--local', '--worktree', '--file', '--blob', '--get', '--get-all', '--get-regexp',
32
+ '--get-urlmatch', '--replace-all', '--add', '--unset', '--unset-all', '--rename-section', '--remove-section', '--list', '--edit',
33
+ '--get-color', '--get-colorbool', '--type', '--bool', '--int', '--bool-or-int', '--path', '--expiry-date', '--null', '--name-only',
34
+ '--includes', '--show-origin', '--show-scope', '--show-names', '--bool-or-str', '--default', '--comment', '--fixed-value', '--value',
35
+ '--url', '--all', '--regexp'];
36
+ const CONFIG_NEGATED_OPTIONS = CONFIG_LONG_OPTIONS.map(option => `--no-${option.slice(2)}`);
37
+ // git's option parser accepts any unambiguous prefix of a long option. Returns the full option name
38
+ // (without any `=value`) when `argument` names exactly one of `options`, and undefined otherwise; an
39
+ // ambiguous prefix is rejected by git itself, so it needs no handling here.
40
+ function resolveLong(argument, options) {
41
+ const name = argument.split('=', 1)[0].toLowerCase();
42
+ if (name.length < 3 || !name.startsWith('--'))
43
+ return undefined;
44
+ if (options.includes(name))
45
+ return name;
46
+ const matches = options.filter(option => option.startsWith(name));
47
+ return matches.length === 1 ? matches[0] : undefined;
48
+ }
49
+ const IDENTITY_KEY_ONLY = new RegExp(`^${IDENTITY_KEY}$`, 'i');
50
+ // Removes redirections and their targets (`2>/dev/null`, `> out`, `2>&1`), which the shell takes away
51
+ // before git runs, so `git 2>/dev/null config user.email x` is still `git config user.email x`.
52
+ function withoutRedirections(tokens) {
53
+ const words = [];
54
+ for (let index = 0; index < tokens.length; index += 1) {
55
+ const token = tokens[index];
56
+ if (token.redirection) {
57
+ // `2>&1` and `>&-` carry their target; any other operator takes the next word as its target.
58
+ if (!/&(?:\d+|-)$/.test(token.text))
59
+ index += 1;
60
+ continue;
61
+ }
62
+ words.push(token.text);
63
+ }
64
+ return words;
65
+ }
66
+ // Splits a segment into the words the shell passes on. Quotes group and are removed, and adjacent quoted
67
+ // and bare parts join. An unquoted redirection operator (`>`, `2>>`, `&>`, `<`, `2>&1`, PowerShell `*>`)
68
+ // is its own token even when it touches a word (`user.email>/dev/null`). With `posix`, an unquoted
69
+ // backslash escapes the next character as bash does (`user\.email` is `user.email`); without it the
70
+ // backslash is kept, as Windows shells and paths need.
71
+ const ANSI_C_ESCAPES = { n: '\n', t: '\t', r: '\r', a: '\x07', b: '\b', e: '\x1b', E: '\x1b', f: '\f', v: '\v', '\\': '\\', "'": "'", '"': '"', '?': '?' };
72
+ function decodeAnsiC(raw) {
73
+ return raw.replace(/\\(x[0-9a-fA-F]{1,2}|u[0-9a-fA-F]{1,4}|U[0-9a-fA-F]{1,8}|[0-7]{1,3}|c.|.)/g, (_match, escape) => {
74
+ if (/^[xuU]/.test(escape))
75
+ return String.fromCodePoint(parseInt(escape.slice(1), 16));
76
+ if (/^[0-7]/.test(escape))
77
+ return String.fromCharCode(parseInt(escape, 8));
78
+ if (escape.startsWith('c'))
79
+ return String.fromCharCode(escape.charCodeAt(1) & 0x1f);
80
+ return ANSI_C_ESCAPES[escape] ?? `\\${escape}`;
81
+ });
82
+ }
83
+ // The interpreter that runs, at the executable position (after wrappers), or handed to find -exec.
84
+ function interpreterIndex(words) {
85
+ const program = programIndex(words);
86
+ if (program >= 0 && INTERPRETERS.has(programName(words[program])))
87
+ return program;
88
+ return words.findIndex((word, index) => index > 0 && INTERPRETERS.has(programName(word)) && /^-(?:exec|execdir|ok|okdir)$/.test(words[index - 1]));
89
+ }
90
+ function shellTokens(segment, posix) {
91
+ const words = [];
92
+ let word = '';
93
+ let started = false;
94
+ let quoted = false;
95
+ const finish = () => {
96
+ if (started)
97
+ words.push({ text: word, quoted, redirection: false });
98
+ word = '';
99
+ started = false;
100
+ quoted = false;
101
+ };
102
+ for (let index = 0; index < segment.length; index += 1) {
103
+ const character = segment[index];
104
+ if (/\s/.test(character)) {
105
+ finish();
106
+ }
107
+ else if (character === "'" || character === '"') {
108
+ started = true;
109
+ quoted = true;
110
+ let close = segment.indexOf(character, index + 1);
111
+ while (character === '"' && close > 0 && segment[close - 1] === '\\')
112
+ close = segment.indexOf(character, close + 1);
113
+ const end = close < 0 ? segment.length : close;
114
+ const inner = segment.slice(index + 1, end);
115
+ word += character === '"' ? inner.replace(/\\(["\\$`])/g, '$1') : inner;
116
+ index = end;
117
+ }
118
+ else if (posix && character === '$' && segment[index + 1] === "'") {
119
+ // bash ANSI-C quoting: $'user\x2eemail' is user.email.
120
+ started = true;
121
+ quoted = true;
122
+ let end = index + 2;
123
+ let raw = '';
124
+ while (end < segment.length && segment[end] !== "'") {
125
+ if (segment[end] === '\\' && end + 1 < segment.length) {
126
+ raw += segment.slice(end, end + 2);
127
+ end += 2;
128
+ continue;
129
+ }
130
+ raw += segment[end];
131
+ end += 1;
132
+ }
133
+ word += decodeAnsiC(raw);
134
+ index = end;
135
+ }
136
+ else if (posix && character === '\\' && index + 1 < segment.length) {
137
+ word += segment[index + 1];
138
+ started = true;
139
+ quoted = true;
140
+ index += 1;
141
+ }
142
+ else if (character === '>' || character === '<' || (character === '&' && segment[index + 1] === '>')) {
143
+ // A word of only digits (or `*`) right before the operator is its file descriptor: `2>`, `*>`.
144
+ let operator = !quoted && /^(?:\d+|\*)$/.test(word) ? word : '';
145
+ if (operator) {
146
+ word = '';
147
+ started = false;
148
+ }
149
+ else
150
+ finish();
151
+ let end = index;
152
+ while (end < segment.length && /[<>&]/.test(segment[end]))
153
+ end += 1;
154
+ operator += segment.slice(index, end);
155
+ if (operator.endsWith('&')) {
156
+ const target = /^(?:\d+|-)/.exec(segment.slice(end));
157
+ if (target) {
158
+ operator += target[0];
159
+ end += target[0].length;
160
+ }
161
+ }
162
+ words.push({ text: operator, quoted: false, redirection: true });
163
+ index = end - 1;
164
+ }
165
+ else {
166
+ word += character;
167
+ started = true;
168
+ }
169
+ }
170
+ finish();
171
+ return words;
172
+ }
173
+ // The word that is actually run: environment assignments and wrappers (sudo, env, nohup, timeout 10,
174
+ // xargs, PowerShell's & call operator, if/then/do, ...) and their options are skipped, so
175
+ // `echo git config user.email x` runs echo, while `sudo -u me git config user.email x` runs git.
176
+ const WRAPPERS = new Set(['sudo', 'doas', 'env', 'command', 'exec', 'nohup', 'time', 'timeout', 'nice', 'ionice', 'stdbuf', 'setsid',
177
+ 'builtin', 'noglob', 'nocorrect', 'xargs', 'call', 'if', 'elif', 'then', 'else', 'do', 'while', 'until', '!', '{', '&', '.']);
178
+ const WRAPPER_VALUES = {
179
+ sudo: new Set(['-u', '--user', '-g', '--group', '-C', '--close-from', '-D', '--chdir', '-h', '--host', '-p', '--prompt', '-r', '--role', '-t', '--type']),
180
+ doas: new Set(['-u', '-C']),
181
+ env: new Set(['-u', '--unset', '-C', '--chdir', '-S', '--split-string']),
182
+ timeout: new Set(['-s', '--signal', '-k', '--kill-after']),
183
+ nice: new Set(['-n', '--adjustment']),
184
+ ionice: new Set(['-c', '--class', '-n', '--classdata', '-p', '--pid']),
185
+ stdbuf: new Set(['-i', '-o', '-e']),
186
+ xargs: new Set(['-I', '-i', '-n', '--max-args', '-L', '-l', '--max-lines', '-P', '--max-procs', '-s', '--max-chars', '-d', '--delimiter', '-E', '-e', '--eof', '-a', '--arg-file', '--replace']),
187
+ };
188
+ function programIndex(words) {
189
+ let wrapper;
190
+ for (let index = 0; index < words.length; index += 1) {
191
+ const word = words[index];
192
+ if (/^[A-Za-z_][A-Za-z0-9_]*=/.test(word))
193
+ continue;
194
+ if (wrapper !== undefined) {
195
+ if (word.startsWith('-')) {
196
+ if (WRAPPER_VALUES[wrapper]?.has(word))
197
+ index += 1;
198
+ continue;
199
+ }
200
+ if (wrapper === 'timeout' && /^\d+(?:\.\d+)?[smhd]?$/.test(word))
201
+ continue;
202
+ }
203
+ const name = programName(word);
204
+ if (name === 'function') {
205
+ index += 1;
206
+ wrapper = undefined;
207
+ continue;
208
+ }
209
+ if (WRAPPERS.has(name)) {
210
+ wrapper = name;
211
+ continue;
212
+ }
213
+ return index;
214
+ }
215
+ return -1;
216
+ }
217
+ // git is run when it is the program, or when find hands it to -exec/-execdir/-ok/-okdir.
218
+ function gitIndex(words) {
219
+ const program = programIndex(words);
220
+ if (program >= 0 && GIT_PROGRAM.test(words[program]))
221
+ return program;
222
+ return words.findIndex((word, index) => index > 0 && GIT_PROGRAM.test(word) && /^-(?:exec|execdir|ok|okdir)$/.test(words[index - 1]));
223
+ }
224
+ // `git config [--global] user.email someone@example.com` writes the identity; reading it does not.
225
+ // `args` are the arguments after `config`. In shell text a redirection and its target (`2>/dev/null`,
226
+ // `> out`) are removed by the shell and skipped here; the arguments after them still reach git.
227
+ // argv passed straight to git has no redirections, so a value such as `2026+bot@example.com` stays a value.
228
+ const REDIRECTION = /^(?:\d*>>?|&>>?|\d*<|\d*>&)(.*)$/;
229
+ const SHORT_ACTIONS = { '-l': '--list', '-e': '--edit' };
230
+ function configWritesIdentity(args, shell) {
231
+ // Options come first. Once `--` or the first name has been seen, every later argument is positional,
232
+ // so `git config user.email -x@example.com` and `git config -- user.email --get` are writes.
233
+ const positional = [];
234
+ let options = true;
235
+ let action;
236
+ for (let index = 0; index < args.length; index += 1) {
237
+ const argument = args[index];
238
+ // git accepts any unambiguous prefix of a long option (`--rename-sec` is --rename-section).
239
+ const lower = options && argument.startsWith('--') ? resolveLong(argument, CONFIG_LONG_OPTIONS) ?? argument.toLowerCase() : argument.toLowerCase();
240
+ const redirection = shell ? REDIRECTION.exec(argument) : null;
241
+ if (redirection) {
242
+ if (redirection[1] === '')
243
+ index += 1;
244
+ continue;
245
+ }
246
+ if (options) {
247
+ if (argument === '--') {
248
+ options = false;
249
+ continue;
250
+ }
251
+ // `--rename-section replacement user` turns another section into the identity.
252
+ if (lower === '--rename-section' || lower === 'rename-section') {
253
+ const names = [];
254
+ for (let position = index + 1; position < args.length; position += 1) {
255
+ const operand = args[position];
256
+ if (shell && REDIRECTION.test(operand))
257
+ continue;
258
+ if (operand === '--') {
259
+ names.push(...args.slice(position + 1));
260
+ break;
261
+ }
262
+ if (operand.startsWith('-')) {
263
+ const option = operand.startsWith('--') ? resolveLong(operand, CONFIG_LONG_OPTIONS) ?? operand.toLowerCase() : operand;
264
+ if (CONFIG_VALUE_OPTIONS.has(option) && !operand.includes('=') && !/^-f./.test(operand))
265
+ position += 1;
266
+ continue;
267
+ }
268
+ names.push(operand);
269
+ }
270
+ return /^(?:user|author|committer)$/i.test(names[1] ?? '');
271
+ }
272
+ // A subcommand action (`git config get ...`) decides at once; an option action can be negated
273
+ // later (`--get --no-get`), so only the one still in force at the end counts.
274
+ if (NON_WRITING_CONFIG_ACTIONS.has(lower) && !lower.startsWith('-'))
275
+ return false;
276
+ if (NON_WRITING_CONFIG_ACTIONS.has(lower)) {
277
+ action = SHORT_ACTIONS[lower] ?? lower;
278
+ continue;
279
+ }
280
+ // The negation may be abbreviated too: `--no-lis` is --no-list.
281
+ if (lower.startsWith('--no-') && action !== undefined && resolveLong(argument, CONFIG_NEGATED_OPTIONS) === `--no-${action.slice(2)}`) {
282
+ action = undefined;
283
+ continue;
284
+ }
285
+ if (lower === 'set')
286
+ continue;
287
+ if (CONFIG_VALUE_OPTIONS.has(lower)) {
288
+ if (!argument.includes('='))
289
+ index += 1;
290
+ continue;
291
+ }
292
+ if (argument.startsWith('-'))
293
+ continue;
294
+ options = false;
295
+ }
296
+ positional.push(argument);
297
+ }
298
+ if (action)
299
+ return false;
300
+ const key = positional.findIndex(token => IDENTITY_KEY_ONLY.test(token));
301
+ if (key >= 0 && key < positional.length - 1)
302
+ return true;
303
+ // `git config alias.rec 'commit --author=X'` stores an override for a later `git rec`.
304
+ const alias = positional.findIndex(token => ALIAS_KEY.test(token));
305
+ if (alias >= 0 && alias < positional.length - 1 && aliasIdentity(positional[alias + 1], 0) !== undefined)
306
+ return true;
307
+ // `git config core.editor 'git config user.email x #'` stores a command git runs later.
308
+ const executed = positional.findIndex(token => EXECUTED_CONFIG.test(token));
309
+ return executed >= 0 && executed < positional.length - 1 && executedConfigIdentity(positional[executed], positional[executed + 1]) !== undefined;
310
+ }
311
+ // A shell segment that runs git is checked word by word, exactly like NativeExec argv, so quoting an
312
+ // option ('--author=X') or abbreviating it cannot hide it from the check.
313
+ // A word that holds several words of its own (node -e "...", bash -c '...', a quoted command string
314
+ // inside a script) can run git too, so it is checked as command text, a few levels deep.
315
+ const NESTING_LIMIT = 4;
316
+ const INTERPRETERS = new Set(['node', 'nodejs', 'deno', 'bun', 'python', 'python3', 'py', 'bash', 'sh', 'zsh', 'dash', 'ksh', 'fish',
317
+ 'pwsh', 'powershell', 'cmd', 'ruby', 'perl', 'eval', 'iex', 'invoke-expression', 'invoke-command', 'wsl']);
318
+ function programName(word) {
319
+ return word.replace(/^.*[\\/]/, '').replace(/\.exe$/i, '').toLowerCase();
320
+ }
321
+ // Splits command text at the separators the shell acts on: ; newline | || && and &.
322
+ // Nothing inside single quotes splits a command, and inside double quotes nothing does either.
323
+ // A substitution ($(...), `...`) or a parenthesised subexpression or subshell ((...)) runs its own
324
+ // command: its contents are returned in `inner` to be checked on their own, and the outer command keeps
325
+ // a placeholder word in its place, so `git -C "$(pwd)" config user.email x` stays one git invocation.
326
+ // The & of a redirection (2>&1, &>) is kept.
327
+ const PLACEHOLDER = 'SUBSTITUTION';
328
+ function closingParenthesis(text, start) {
329
+ let depth = 1;
330
+ let quote;
331
+ for (let index = start; index < text.length; index += 1) {
332
+ const character = text[index];
333
+ if (quote === "'") {
334
+ if (character === "'")
335
+ quote = undefined;
336
+ continue;
337
+ }
338
+ if (character === '\\') {
339
+ index += 1;
340
+ continue;
341
+ }
342
+ if (quote === '"') {
343
+ if (character === '"')
344
+ quote = undefined;
345
+ continue;
346
+ }
347
+ if (character === "'" || character === '"')
348
+ quote = character;
349
+ else if (character === '(')
350
+ depth += 1;
351
+ else if (character === ')' && --depth === 0)
352
+ return index;
353
+ }
354
+ return text.length;
355
+ }
356
+ function closingBacktick(text, start) {
357
+ for (let index = start; index < text.length; index += 1) {
358
+ if (text[index] === '\\') {
359
+ index += 1;
360
+ continue;
361
+ }
362
+ if (text[index] === '`')
363
+ return index;
364
+ }
365
+ return text.length;
366
+ }
367
+ // The index of the ' that closes an ANSI-C quoted word whose text starts at `start`.
368
+ function ansiCEnd(text, start) {
369
+ let index = start;
370
+ while (index < text.length && text[index] !== "'")
371
+ index += text[index] === '\\' ? 2 : 1;
372
+ return Math.min(index, text.length - 1);
373
+ }
374
+ function splitCommands(text) {
375
+ const segments = [];
376
+ // piped[i] is true when segment i pipes its output into segment i + 1 (a single |).
377
+ const piped = [];
378
+ const inner = [];
379
+ let current = '';
380
+ let quote;
381
+ const cut = (pipe = false) => { segments.push(current); piped.push(pipe); current = ''; };
382
+ for (let index = 0; index < text.length; index += 1) {
383
+ const character = text[index];
384
+ const next = text[index + 1];
385
+ if (quote === "'") {
386
+ current += character;
387
+ if (character === "'")
388
+ quote = undefined;
389
+ continue;
390
+ }
391
+ // An unquoted # that starts a word comments out the rest of the line (bash and PowerShell), so an
392
+ // apostrophe in `# Don't ...` is not a quote and cannot hide the next line.
393
+ // bash ANSI-C quoting: $'don\'t' is one quoted word; \' inside it does not end it.
394
+ if (character === '$' && next === "'" && quote === undefined) {
395
+ const end = ansiCEnd(text, index + 2);
396
+ current += text.slice(index, end + 1);
397
+ index = end;
398
+ continue;
399
+ }
400
+ if (character === '#' && quote === undefined && (current === '' || /\s$/.test(current))) {
401
+ while (index + 1 < text.length && text[index + 1] !== '\n')
402
+ index += 1;
403
+ continue;
404
+ }
405
+ if (character === '\\' && next !== undefined) {
406
+ current += character + next;
407
+ index += 1;
408
+ continue;
409
+ }
410
+ // `name() { ...; }` defines a function: the empty () is no subexpression, and { starts the body, whose
411
+ // commands run when the function is called, so they are split and checked like any others.
412
+ if (character === '(' && quote === undefined && /^\s*\)/.test(text.slice(index + 1))) {
413
+ index = text.indexOf(')', index);
414
+ cut();
415
+ continue;
416
+ }
417
+ if ((character === '{' || character === '}') && quote === undefined && (current.trim() === '' || /\s$/.test(current))
418
+ && (next === undefined || /[\s;]/.test(next))) {
419
+ cut();
420
+ continue;
421
+ }
422
+ const opensParen = character === '$' && next === '(' ? 2 : character === '(' && quote === undefined ? 1 : 0;
423
+ if (opensParen) {
424
+ const end = closingParenthesis(text, index + opensParen);
425
+ inner.push(text.slice(index + opensParen, end));
426
+ current += PLACEHOLDER;
427
+ index = end;
428
+ continue;
429
+ }
430
+ if (character === '`') {
431
+ const end = closingBacktick(text, index + 1);
432
+ inner.push(text.slice(index + 1, end));
433
+ current += PLACEHOLDER;
434
+ index = end;
435
+ continue;
436
+ }
437
+ if (quote === '"') {
438
+ if (character === '"')
439
+ quote = undefined;
440
+ current += character;
441
+ continue;
442
+ }
443
+ if (character === "'" || character === '"') {
444
+ quote = character;
445
+ current += character;
446
+ continue;
447
+ }
448
+ if (character === '\n' || character === ';' || character === ')') {
449
+ cut();
450
+ continue;
451
+ }
452
+ if (character === '|') {
453
+ if (next === '|') {
454
+ index += 1;
455
+ cut();
456
+ }
457
+ else
458
+ cut(true);
459
+ continue;
460
+ }
461
+ if (character === '&') {
462
+ if (next === '&') {
463
+ index += 1;
464
+ cut();
465
+ continue;
466
+ }
467
+ const previous = text[index - 1];
468
+ if (previous === '>' || previous === '<' || next === '>') {
469
+ current += character;
470
+ continue;
471
+ }
472
+ cut();
473
+ continue;
474
+ }
475
+ current += character;
476
+ }
477
+ cut();
478
+ return { segments, inner, piped };
479
+ }
480
+ // `env -S "git config user.email x"` (also -S<cmd>, --split-string <cmd>, --split-string=<cmd>) splits its
481
+ // value into the program and arguments env runs, so the value replaces the option in the words.
482
+ function expandEnvSplit(words) {
483
+ const env = words.findIndex(word => programName(word) === 'env');
484
+ if (env < 0)
485
+ return [...words];
486
+ for (let index = env + 1; index < words.length; index += 1) {
487
+ const word = words[index];
488
+ if (!word.startsWith('-'))
489
+ break;
490
+ const long = word.startsWith('--') && '--split-string'.startsWith(word.split('=', 1)[0]) && word.length >= 4;
491
+ let value;
492
+ let used = 1;
493
+ if (word === '-S' || (long && !word.includes('='))) {
494
+ value = words[index + 1];
495
+ used = 2;
496
+ }
497
+ else if (/^-S./.test(word))
498
+ value = word.slice(2);
499
+ else if (long)
500
+ value = word.slice(word.indexOf('=') + 1);
501
+ if (value !== undefined) {
502
+ const expanded = withoutRedirections(shellTokens(value, true));
503
+ return [...words.slice(0, index), ...expanded, ...words.slice(index + used)];
504
+ }
505
+ }
506
+ return [...words];
507
+ }
508
+ // Configuration whose value git runs as a shell command, and the environment variables that do the same.
509
+ const EXECUTED_CONFIG = /^(?:core\.(?:editor|pager|sshcommand|askpass|fsmonitor)|sequence\.editor|pager\..+|diff\.external|diff\..+\.(?:textconv|command)|merge\..+\.driver|filter\..+\.(?:clean|smudge|process)|credential(?:\..+)?\.helper|gpg(?:\..+)?\.program|interactive\.difffilter|(?:diff|merge)tool\..+\.cmd|sendemail\.(?:sendmailcmd|tocmd|cccmd))$/i;
510
+ const EXECUTED_VARIABLE = /^(?:GIT_EDITOR|GIT_SEQUENCE_EDITOR|EDITOR|VISUAL|GIT_PAGER|PAGER|GIT_SSH_COMMAND|GIT_SSH|GIT_ASKPASS|GIT_EXTERNAL_DIFF)\+?=(.+)$/;
511
+ function executedConfigIdentity(key, value) {
512
+ return EXECUTED_CONFIG.test(key) ? identityIn(value.replace(/^\s*!/, ''), 1) : undefined;
513
+ }
514
+ function segmentIdentity(segment, depth) {
515
+ // The tool may run bash (backslash escapes) or a Windows shell (backslash is literal), so a
516
+ // segment is refused when either reading of it overrides the identity.
517
+ let found;
518
+ for (const posix of [true, false]) {
519
+ const read = expandEnvSplit(withoutRedirections(shellTokens(segment, posix)));
520
+ const git = gitIndex(read);
521
+ found = git < 0 ? undefined : gitArgvIdentity(read.slice(git + 1), false);
522
+ if (found)
523
+ return found;
524
+ // GIT_EDITOR='...' git commit, EDITOR=... and similar assignments name a command git will run.
525
+ for (const word of read) {
526
+ const assignment = EXECUTED_VARIABLE.exec(word);
527
+ found = assignment && depth < NESTING_LIMIT ? identityIn(assignment[1], depth + 1) : undefined;
528
+ if (found)
529
+ return found;
530
+ }
531
+ }
532
+ if (depth >= NESTING_LIMIT)
533
+ return undefined;
534
+ const words = withoutRedirections(shellTokens(segment, false));
535
+ // Only an interpreter runs its arguments (node -e, bash -c, powershell -Command); inside such a script
536
+ // any string can be a command. `rg -F 'git config user.email x'` only searches, so it is not looked into.
537
+ const interpreter = depth > 0 ? -1 : interpreterIndex(words);
538
+ if (depth === 0 && interpreter < 0)
539
+ return undefined;
540
+ for (const word of words.slice(interpreter + 1)) {
541
+ if (!/\s/.test(word.trim()))
542
+ continue;
543
+ const nested = identityIn(word, depth + 1);
544
+ if (nested)
545
+ return nested;
546
+ }
547
+ return undefined;
548
+ }
549
+ // A backslash (bash, cmd uses ^) or backtick (PowerShell) at the end of a line continues the command,
550
+ // so `git commit \` + newline + `--author=x` is one command and must not be split at the newline.
551
+ // bash and cmd remove the pair entirely, so `user.\` + newline + `email` is `user.email`; PowerShell's
552
+ // backtick continuation separates words, so it becomes a space.
553
+ const CONTINUATION = /(?:\\|\^)\r?\n/g;
554
+ const POWERSHELL_CONTINUATION = /`\r?\n/g;
555
+ // Inline scripts that start git with an argument array: execFileSync('git', ['config', ...]),
556
+ // spawn("git", [...]), subprocess.run(['git', 'config', ...]). The string literals of the array are
557
+ // git's argv and are checked exactly like NativeExec argv.
558
+ const STRING_LITERAL = /'((?:[^'\\]|\\.)*)'|"((?:[^"\\]|\\.)*)"/g;
559
+ const GIT_LITERAL = String.raw `(['"])(?:[^'"]*[\\/])?git(?:\.exe)?\1`;
560
+ const GIT_ARGV_CALLS = [
561
+ new RegExp(String.raw `${GIT_LITERAL}\s*,\s*\[([^\]]*)\]`, 'gi'),
562
+ new RegExp(String.raw `\[\s*${GIT_LITERAL}\s*,([^\]]*)\]`, 'gi'),
563
+ ];
564
+ function inlineGitArgv(command) {
565
+ const text = command.replace(/\\(["'])/g, '$1');
566
+ for (const pattern of GIT_ARGV_CALLS) {
567
+ for (const match of text.matchAll(pattern)) {
568
+ const args = [...match[2].matchAll(STRING_LITERAL)].map(literal => (literal[1] ?? literal[2] ?? '').replace(/\\(.)/g, '$1'));
569
+ const found = gitArgvIdentity(args, false);
570
+ if (found)
571
+ return found;
572
+ }
573
+ }
574
+ return undefined;
575
+ }
576
+ // Heredocs (`<<EOF`, `<<-'EOF'`) and here-strings (`<<< "..."`) feed text to a command's standard input.
577
+ // The text is a script only when that command is an interpreter (`node <<'EOF'`, `bash <<EOF`); for any
578
+ // other command (`cat <<EOF > file`) it is data. Bodies are taken out of the command text either way, and
579
+ // the scripts are returned to be checked as interpreter scripts.
580
+ const HERESTRING = /<<<\s*/g;
581
+ // True when the command before a heredoc or here-string runs its standard input as a script: an interpreter
582
+ // with no script given another way (`python3 -c '<prog>' <<EOF` reads the heredoc as data).
583
+ function pipesIntoInterpreter(lineAfter) {
584
+ const visible = unquotedOnly(lineAfter);
585
+ for (const pipe of visible.matchAll(/(?<!\|)\|(?!\|)/g)) {
586
+ const receiver = lineAfter.slice(pipe.index + 1).split(/[;&|]/)[0] ?? '';
587
+ const words = withoutRedirections(shellTokens(receiver, true));
588
+ const program = programIndex(words);
589
+ if (program >= 0 && INTERPRETERS.has(programName(words[program])) && readsScriptFromStdin(words.slice(program + 1)))
590
+ return true;
591
+ }
592
+ return false;
593
+ }
594
+ function feedsInterpreter(lineBefore) {
595
+ const command = lineBefore.split(/[;|&]/).pop() ?? '';
596
+ const words = withoutRedirections(shellTokens(command, true));
597
+ const program = programIndex(words);
598
+ return program >= 0 && INTERPRETERS.has(programName(words[program])) && readsScriptFromStdin(words.slice(program + 1));
599
+ }
600
+ // The line with every quoted character blanked, so operators are looked for only where the shell sees
601
+ // them: `printf '%s' 'example <<EOF'` has no heredoc. Positions match the original line.
602
+ function unquotedOnly(line) {
603
+ let masked = '';
604
+ let quote;
605
+ for (let index = 0; index < line.length; index += 1) {
606
+ const character = line[index];
607
+ if (quote) {
608
+ if (character === '\\' && quote !== "'" && index + 1 < line.length) {
609
+ masked += '\u0000\u0000';
610
+ index += 1;
611
+ continue;
612
+ }
613
+ if (character === quote) {
614
+ quote = undefined;
615
+ masked += character;
616
+ continue;
617
+ }
618
+ masked += '\u0000';
619
+ }
620
+ else if (character === '\\' && index + 1 < line.length) {
621
+ masked += '\u0000\u0000';
622
+ index += 1;
623
+ }
624
+ else if (character === '$' && line[index + 1] === "'") {
625
+ const end = ansiCEnd(line, index + 2);
626
+ masked += '\u0000'.repeat(end - index + 1);
627
+ index = end;
628
+ }
629
+ else if (character === '#' && (index === 0 || /[\s;&|(]/.test(line[index - 1]))) {
630
+ // A comment: nothing after it is an operator (`# example <<EOF` starts no heredoc).
631
+ masked += '\u0000'.repeat(line.length - index);
632
+ break;
633
+ }
634
+ else {
635
+ if (character === "'" || character === '"')
636
+ quote = character;
637
+ masked += character;
638
+ }
639
+ }
640
+ return masked;
641
+ }
642
+ // `scripts` are bodies given to an interpreter; `shell` are commands the shell itself runs while expanding
643
+ // an unquoted heredoc body (`$(...)`, backticks), whatever command receives the text.
644
+ function extractHeredocs(command) {
645
+ const lines = command.split('\n');
646
+ const kept = [];
647
+ const scripts = [];
648
+ const shell = [];
649
+ for (let index = 0; index < lines.length; index += 1) {
650
+ const line = lines[index];
651
+ const visible = unquotedOnly(line);
652
+ kept.push(line);
653
+ for (const operator of visible.matchAll(HERESTRING)) {
654
+ const start = operator.index + operator[0].length;
655
+ const word = shellTokens(line.slice(start), true)[0];
656
+ if (word && feedsInterpreter(line.slice(0, operator.index)))
657
+ scripts.push(word.text);
658
+ }
659
+ for (const found of visible.matchAll(/(?<!<)<<(?!<)/g)) {
660
+ const operator = /^<<(-?)\s*(['"]?)([A-Za-z_][\w.-]*)\2/.exec(line.slice(found.index));
661
+ if (!operator)
662
+ continue;
663
+ const stripTabs = operator[1] === '-';
664
+ const literal = operator[2] !== '';
665
+ const delimiter = operator[3];
666
+ const body = [];
667
+ while (index + 1 < lines.length) {
668
+ index += 1;
669
+ const bodyLine = lines[index].replace(/\r$/, '');
670
+ if ((stripTabs ? bodyLine.replace(/^\t+/, '') : bodyLine) === delimiter)
671
+ break;
672
+ body.push(bodyLine);
673
+ }
674
+ const text = body.join('\n');
675
+ // The body is a script when its command is an interpreter reading stdin, or when the line pipes it on into
676
+ // one (`cat <<'EOF' | bash`).
677
+ if (feedsInterpreter(line.slice(0, found.index)) || pipesIntoInterpreter(line.slice(found.index)))
678
+ scripts.push(text);
679
+ // An unquoted delimiter makes the shell expand $(...) and backticks in the body before handing it over.
680
+ if (!literal)
681
+ shell.push(...splitCommands(text.replace(/['"]/g, ' ')).inner);
682
+ }
683
+ }
684
+ return { text: kept.join('\n'), scripts, shell };
685
+ }
686
+ // `printf '%s\n' '<script>' | bash`: what a command prints into an interpreter's pipe is that
687
+ // interpreter's script. The producer's literal arguments are returned (each one, and all of them joined),
688
+ // only when the receiving command is an interpreter, so an ordinary `echo ... | grep` is not inspected.
689
+ // An interpreter runs its standard input as the script only when no script is given another way:
690
+ // `bash`, `node`, `python3 -`, `sh -s` do; `python3 -c '<prog>'`, `node -e ...`, `bash script.sh` read stdin as data.
691
+ const SCRIPT_OPTIONS = /^(?:-c|-e|--eval|-p|--print|-m|-r|--require|-x|-command|-encodedcommand|-ec|-file|-f|\/c|\/k)$/i;
692
+ function readsScriptFromStdin(args) {
693
+ if (args.includes('-') || args.includes('-s'))
694
+ return true;
695
+ if (args.some(argument => SCRIPT_OPTIONS.test(argument) || /^--?(?:eval|print|command)=/i.test(argument)))
696
+ return false;
697
+ return !args.some(argument => !argument.startsWith('-') && !argument.startsWith('/'));
698
+ }
699
+ function pipedScripts(segments, piped) {
700
+ const scripts = [];
701
+ for (let index = 0; index + 1 < segments.length; index += 1) {
702
+ if (!piped[index])
703
+ continue;
704
+ const receiver = withoutRedirections(shellTokens(segments[index + 1], true));
705
+ const program = programIndex(receiver);
706
+ if (program < 0 || !INTERPRETERS.has(programName(receiver[program])) || !readsScriptFromStdin(receiver.slice(program + 1)))
707
+ continue;
708
+ const producer = withoutRedirections(shellTokens(segments[index], true));
709
+ const start = programIndex(producer);
710
+ const args = start < 0 ? [] : producer.slice(start + 1).filter(argument => !/^-[a-zA-Z]+$/.test(argument));
711
+ scripts.push(...args, args.join('\n'), args.join(' '));
712
+ }
713
+ return scripts.filter(script => script.trim() !== '');
714
+ }
715
+ // Commands that only search or print their arguments.
716
+ const READ_ONLY_PROGRAMS = new Set(['rg', 'grep', 'egrep', 'fgrep', 'ag', 'ack', 'select-string', 'sls', 'findstr', 'echo', 'printf',
717
+ 'write-output', 'write-host', 'cat', 'type', 'get-content', 'gc', 'less', 'more', 'head', 'tail', 'wc', 'ls', 'dir', 'get-childitem']);
718
+ function readsOnly(segment) {
719
+ const words = withoutRedirections(shellTokens(segment, true));
720
+ const program = programIndex(words);
721
+ return program >= 0 && READ_ONLY_PROGRAMS.has(programName(words[program]));
722
+ }
723
+ function identityIn(command, depth) {
724
+ const { text, scripts, shell } = extractHeredocs(command);
725
+ for (const expanded of shell) {
726
+ const found = identityIn(expanded, depth);
727
+ if (found)
728
+ return found;
729
+ }
730
+ for (const script of scripts) {
731
+ const found = depth < NESTING_LIMIT ? identityIn(script, depth + 1) : undefined;
732
+ if (found)
733
+ return found;
734
+ }
735
+ const joined = text.replace(CONTINUATION, '').replace(POWERSHELL_CONTINUATION, ' ');
736
+ const scrubbed = scrubMessages(joined);
737
+ // Inside a script every rule applies to the whole text. In shell text the rules apply per command, and not
738
+ // to a command that only reads or prints its arguments (`rg -n 'GIT_AUTHOR_NAME=' src`); an assignment in
739
+ // front of such a command only reaches that command.
740
+ const rule = depth > 0
741
+ ? RULES.find(candidate => candidate.pattern.test(scrubbed))
742
+ : RULES.find(candidate => !candidate.scriptOnly && splitCommands(scrubbed).segments.some(segment => !readsOnly(segment) && candidate.pattern.test(segment)));
743
+ if (rule)
744
+ return rule.what;
745
+ // depth > 0 is a script an interpreter runs, where an argument array can start git.
746
+ const inline = depth > 0 ? inlineGitArgv(joined) : undefined;
747
+ if (inline)
748
+ return inline;
749
+ const { segments, inner, piped } = splitCommands(scrubbed);
750
+ for (const segment of segments) {
751
+ const found = segmentIdentity(segment, depth);
752
+ if (found)
753
+ return found;
754
+ }
755
+ const pipedScript = depth < NESTING_LIMIT ? pipedScripts(segments, piped) : [];
756
+ for (const script of pipedScript) {
757
+ const found = identityIn(script, depth + 1);
758
+ if (found)
759
+ return found;
760
+ }
761
+ // A substitution is run by the same shell, so its contents are checked at the same depth.
762
+ for (const command of inner) {
763
+ const found = identityIn(command, depth);
764
+ if (found)
765
+ return found;
766
+ }
767
+ return undefined;
768
+ }
769
+ // A commit message may mention --author or GIT_AUTHOR_NAME=; only what the command does counts.
770
+ // A double-quoted message that runs a substitution ($(...) or backticks) is still a command, so it is kept.
771
+ const MESSAGE = /(\s(?:-[A-Za-z]*m|--message)(?:\s+|=))("(?:[^"\\]|\\.)*"|'[^']*')/g;
772
+ // Only a message of a `git commit` in the same command is scrubbed; `bash -cm '...'` is a script.
773
+ const GIT_COMMIT_BEFORE = /(?:^|[\s"'\\/&(])git(?:\.exe)?["']?\s(?:[^\n;|&]*\s)?commit\s(?:[^\n;|&]*\s)?$/i;
774
+ function scrubMessages(command) {
775
+ return command.replace(MESSAGE, (match, prefix, message, offset) => {
776
+ const before = command.slice(0, offset).split(/[\n;|]|&&/).pop() ?? '';
777
+ if (!GIT_COMMIT_BEFORE.test(`${before} `))
778
+ return match;
779
+ return message.startsWith('"') && /\$\(|`/.test(message) ? match : `${prefix}""`;
780
+ });
781
+ }
782
+ function refusal(what) {
783
+ return `Refused: this command sets the git author or committer (${what}). Commits must carry the git identity the user configured. `
784
+ + 'Do not pass -c user.name/user.email, --author, or GIT_AUTHOR_*/GIT_COMMITTER_* variables, and do not change user.name or user.email with git config. '
785
+ + 'Run the command without the override; if a different identity is really needed, ask the user to change their git configuration.';
786
+ }
787
+ const CONFIG_WRITE = 'a git config write of user.name or user.email, or of an alias that overrides them';
788
+ export function gitIdentityRefusal(command) {
789
+ const what = identityIn(command, 0);
790
+ return what ? refusal(what) : undefined;
791
+ }
792
+ const GIT_GLOBAL_VALUE_OPTIONS = new Set(['-C', '--git-dir', '--work-tree', '--namespace', '--super-prefix', '--list-cmds', '--attr-source']);
793
+ const COMMIT_VALUE_OPTIONS = new Set(['-m', '--message', '-F', '--file', '-C', '--reuse-message', '-c', '--reedit-message', '-t', '--template',
794
+ '--trailer', '--fixup', '--squash', '--date', '--cleanup', '--pathspec-from-file']);
795
+ // -u/--untracked-files and -S/--gpg-sign take an optional value, which git accepts only when attached
796
+ // (-uno, --gpg-sign=KEY), so the argument after them is never theirs and is checked like any other.
797
+ // Every long option of `git commit` (git 2.55), so an abbreviation such as `--mes` resolves to one of them.
798
+ const COMMIT_LONG_OPTIONS = ['--ahead-behind', '--all', '--allow-empty', '--allow-empty-message', '--amend', '--author', '--branch',
799
+ '--cleanup', '--date', '--dry-run', '--edit', '--file', '--fixup', '--gpg-sign', '--include', '--inter-hunk-context', '--interactive',
800
+ '--long', '--message', '--no-post-rewrite', '--no-verify', '--no-edit', '--null', '--only', '--patch', '--pathspec-file-nul',
801
+ '--pathspec-from-file', '--porcelain', '--post-rewrite', '--quiet', '--reedit-message', '--reset-author', '--reuse-message', '--short',
802
+ '--signoff', '--squash', '--status', '--template', '--trailer', '--unified', '--untracked-files', '--verbose', '--verify'];
803
+ const COMMIT_LONG_VALUES = new Set(['--message', '--file', '--reuse-message', '--reedit-message', '--template', '--trailer', '--fixup',
804
+ '--squash', '--date', '--cleanup', '--pathspec-from-file', '--inter-hunk-context', '--unified']);
805
+ // Commands git itself runs from its arguments: `rebase --exec/-x <cmd>`, `bisect run <cmd...>`,
806
+ // `submodule foreach <cmd...>` and `filter-branch --*-filter <cmd>`. They are checked as shell commands.
807
+ const REBASE_LONG_OPTIONS = ['--abort', '--apply', '--autosquash', '--autostash', '--committer-date-is-author-date', '--continue',
808
+ '--edit-todo', '--empty', '--exec', '--ff', '--force-rebase', '--fork-point', '--gpg-sign', '--ignore-whitespace', '--interactive',
809
+ '--keep-base', '--merge', '--no-ff', '--no-stat', '--no-verify', '--onto', '--quiet', '--quit', '--reapply-cherry-picks',
810
+ '--rebase-merges', '--rerere-autoupdate', '--reschedule-failed-exec', '--reset-author-date', '--root', '--show-current-patch',
811
+ '--signoff', '--skip', '--stat', '--strategy', '--strategy-option', '--trailer', '--update-refs', '--verbose', '--verify', '--whitespace'];
812
+ const FILTER_BRANCH_FILTERS = /^--(?:env|tree|index|parent|msg|commit|tag-name)-filter$/;
813
+ function executedCommands(subcommand, rest) {
814
+ const commands = [];
815
+ if (subcommand === 'rebase') {
816
+ for (let index = 0; index < rest.length; index += 1) {
817
+ const argument = rest[index];
818
+ if (argument === '--')
819
+ break;
820
+ const short = /^-[a-zA-Z]*x(.*)$/.exec(argument);
821
+ if (!argument.startsWith('--') && short) {
822
+ if (short[1])
823
+ commands.push(short[1]);
824
+ else {
825
+ commands.push(rest[index + 1] ?? '');
826
+ index += 1;
827
+ }
828
+ }
829
+ else if (resolveLong(argument, REBASE_LONG_OPTIONS) === '--exec') {
830
+ const equals = argument.indexOf('=');
831
+ if (equals >= 0)
832
+ commands.push(argument.slice(equals + 1));
833
+ else {
834
+ commands.push(rest[index + 1] ?? '');
835
+ index += 1;
836
+ }
837
+ }
838
+ }
839
+ }
840
+ else if (subcommand === 'bisect' && rest[0]?.toLowerCase() === 'run') {
841
+ // bisect run executes its arguments as argv; quoting keeps `sh -c '<script>'` one script argument.
842
+ commands.push(rest.slice(1).map(shellQuote).join(' '));
843
+ }
844
+ else if (subcommand === 'submodule') {
845
+ const foreach = rest.findIndex(argument => argument === 'foreach');
846
+ // One argument is a shell command string; several are passed on as argv (`-- "$@"`), so they are
847
+ // quoted to keep `sh -c '<script>'` one script argument.
848
+ const command = foreach < 0 ? [] : rest.slice(foreach + 1).filter(argument => !/^--(?:recursive|quiet)$/.test(argument) && argument !== '-q' && argument !== '--');
849
+ if (command.length === 1)
850
+ commands.push(command[0]);
851
+ else if (command.length > 1)
852
+ commands.push(command.map(shellQuote).join(' '));
853
+ }
854
+ else if (subcommand === 'filter-branch') {
855
+ for (let index = 0; index < rest.length; index += 1) {
856
+ if (FILTER_BRANCH_FILTERS.test(rest[index]))
857
+ commands.push(rest[index + 1] ?? '');
858
+ }
859
+ }
860
+ return commands.filter(command => command.trim() !== '');
861
+ }
862
+ // Bundled short options (`-am msg`): the first letter that takes a value takes the rest of the bundle,
863
+ // or the next argument when it ends the bundle. -u and -S take only an attached value.
864
+ const COMMIT_SHORT_VALUES = new Set(['m', 'F', 'C', 'c', 't']);
865
+ const COMMIT_SHORT_OPTIONAL = new Set(['u', 'S']);
866
+ function shortBundleTakesNext(bundle) {
867
+ for (let index = 1; index < bundle.length; index += 1) {
868
+ const letter = bundle[index];
869
+ if (COMMIT_SHORT_OPTIONAL.has(letter))
870
+ return false;
871
+ if (COMMIT_SHORT_VALUES.has(letter))
872
+ return index === bundle.length - 1;
873
+ }
874
+ return false;
875
+ }
876
+ // git argv is inspected argument by argument, so a commit message that mentions --author stays a message.
877
+ // git accepts any unambiguous prefix of a long option, and for commit `--au` already means --author.
878
+ const AUTHOR_OPTION = /^--au(?:t(?:h(?:or?)?)?)?(?:=|$)/;
879
+ // A git alias runs either git with more arguments (`commit --author=X`) or, after `!`, a shell command.
880
+ // Its definition is checked the way the expansion would run.
881
+ const ALIAS_KEY = /^alias\.([^=]+)$/i;
882
+ // Quotes one argument for a POSIX shell, so argv can be rebuilt as command text without losing its boundaries.
883
+ function shellQuote(argument) {
884
+ return /^[\w@%+=:,./-]+$/.test(argument) ? argument : `'${argument.replace(/'/g, `'\\''`)}'`;
885
+ }
886
+ // A `!` alias runs its definition in a shell with the remaining arguments appended, so
887
+ // `git -c 'alias.run=!sh -c' run '<script>'` runs `sh -c '<script>'`.
888
+ function aliasIdentity(value, nesting, extra = []) {
889
+ const definition = value.trim();
890
+ if (definition.startsWith('!'))
891
+ return identityIn([definition.slice(1), ...extra.map(shellQuote)].join(' '), 0);
892
+ return gitArgvIdentity(withoutRedirections(shellTokens(definition, true)), false, nesting + 1);
893
+ }
894
+ function gitArgvIdentity(args, shell, nesting = 0) {
895
+ if (nesting > NESTING_LIMIT)
896
+ return undefined;
897
+ const aliases = new Map();
898
+ const configPair = (pair) => {
899
+ if (new RegExp(`^${IDENTITY_KEY}=`, 'i').test(pair))
900
+ return 'a -c override of the git identity';
901
+ const equals = pair.indexOf('=');
902
+ const alias = equals > 0 ? ALIAS_KEY.exec(pair.slice(0, equals)) : null;
903
+ if (alias)
904
+ aliases.set(alias[1].toLowerCase(), pair.slice(equals + 1));
905
+ // `-c 'core.editor=git config user.email x #'` runs its value when git opens the editor.
906
+ return equals > 0 ? executedConfigIdentity(pair.slice(0, equals), pair.slice(equals + 1)) : undefined;
907
+ };
908
+ let index = 0;
909
+ for (; index < args.length; index += 1) {
910
+ const argument = args[index];
911
+ if (!argument.startsWith('-'))
912
+ break;
913
+ if (argument === '-c') {
914
+ const found = configPair(args[index + 1] ?? '');
915
+ if (found)
916
+ return found;
917
+ index += 1;
918
+ }
919
+ else if (argument === '--config-env') {
920
+ if (new RegExp(`^${IDENTITY_KEY}=`, 'i').test(args[index + 1] ?? ''))
921
+ return 'a --config-env override of the git identity';
922
+ index += 1;
923
+ }
924
+ else if (/^-c./.test(argument)) {
925
+ const found = configPair(argument.slice(2));
926
+ if (found)
927
+ return found;
928
+ }
929
+ else if (new RegExp(`^--config-env=${IDENTITY_KEY}=`, 'i').test(argument))
930
+ return 'a --config-env override of the git identity';
931
+ else if (GIT_GLOBAL_VALUE_OPTIONS.has(argument))
932
+ index += 1;
933
+ }
934
+ const subcommand = args[index]?.toLowerCase();
935
+ const rest = args.slice(index + 1);
936
+ // `git -c 'alias.record=commit --author=X' record ...` runs the alias with the remaining arguments.
937
+ const alias = subcommand === undefined ? undefined : aliases.get(subcommand);
938
+ if (alias !== undefined) {
939
+ if (alias.trim().startsWith('!'))
940
+ return aliasIdentity(alias, nesting, rest);
941
+ const expanded = withoutRedirections(shellTokens(alias, true));
942
+ const found = gitArgvIdentity([...args.slice(0, index), ...expanded, ...rest], false, nesting + 1);
943
+ if (found)
944
+ return found;
945
+ }
946
+ if (subcommand === 'commit') {
947
+ for (let position = 0; position < rest.length; position += 1) {
948
+ const argument = rest[position];
949
+ if (argument === '--')
950
+ break;
951
+ const long = argument.startsWith('--') ? resolveLong(argument, COMMIT_LONG_OPTIONS) : undefined;
952
+ if (AUTHOR_OPTION.test(argument) || long === '--author')
953
+ return 'a commit --author override';
954
+ if (COMMIT_VALUE_OPTIONS.has(argument))
955
+ position += 1;
956
+ else if (long !== undefined && COMMIT_LONG_VALUES.has(long) && !argument.includes('='))
957
+ position += 1;
958
+ else if (/^-[^-]./.test(argument) && shortBundleTakesNext(argument))
959
+ position += 1;
960
+ }
961
+ }
962
+ for (const command of executedCommands(subcommand, rest)) {
963
+ const found = identityIn(command, 0);
964
+ if (found)
965
+ return found;
966
+ }
967
+ if (subcommand === 'config' && configWritesIdentity(rest, shell))
968
+ return CONFIG_WRITE;
969
+ if (subcommand === 'filter-repo' && rest.some(argument => /^--(?:name-c|email-c|mai)[\w-]*(?:=|$)/.test(argument)))
970
+ return 'a filter-repo identity rewrite';
971
+ return undefined;
972
+ }
973
+ export function gitIdentityRefusalForArgv(program, args) {
974
+ if (GIT_PROGRAM.test(program)) {
975
+ const what = gitArgvIdentity(args, false);
976
+ return what ? refusal(what) : undefined;
977
+ }
978
+ // An interpreter (node -e ...) runs its arguments, so each is checked as a script. Other programs
979
+ // (rg, a search pattern) only read their arguments and are not inspected.
980
+ if (!INTERPRETERS.has(programName(program)))
981
+ return undefined;
982
+ for (const argument of args) {
983
+ const what = identityIn(argument, 1);
984
+ if (what)
985
+ return refusal(what);
986
+ }
987
+ return undefined;
988
+ }
989
+ export function assertNotGitIdentityOverride(command) {
990
+ const found = gitIdentityRefusal(command);
991
+ if (found)
992
+ throw new Error(found);
993
+ }
994
+ export function assertNotGitIdentityOverrideArgv(program, args) {
995
+ const found = gitIdentityRefusalForArgv(program, args);
996
+ if (found)
997
+ throw new Error(found);
998
+ }