@buildanagent/harness 0.0.0-stage → 0.1.0-alpha.28

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 (364) hide show
  1. package/LICENSE +54 -0
  2. package/LICENSE-APACHE +202 -0
  3. package/LICENSE-MIT +21 -0
  4. package/README.md +716 -2
  5. package/dist/ablation.d.ts +2 -0
  6. package/dist/ablation.js +3 -0
  7. package/dist/ablation.js.map +1 -0
  8. package/dist/completion/check.d.ts +64 -0
  9. package/dist/completion/check.js +152 -0
  10. package/dist/completion/check.js.map +1 -0
  11. package/dist/completion/checks.d.ts +45 -0
  12. package/dist/completion/checks.js +173 -0
  13. package/dist/completion/checks.js.map +1 -0
  14. package/dist/completion/flags.d.ts +25 -0
  15. package/dist/completion/flags.js +87 -0
  16. package/dist/completion/flags.js.map +1 -0
  17. package/dist/completion/index.d.ts +8 -0
  18. package/dist/completion/index.js +9 -0
  19. package/dist/completion/index.js.map +1 -0
  20. package/dist/completion/snapshot.d.ts +33 -0
  21. package/dist/completion/snapshot.js +83 -0
  22. package/dist/completion/snapshot.js.map +1 -0
  23. package/dist/context/cap.d.ts +32 -0
  24. package/dist/context/cap.js +50 -0
  25. package/dist/context/cap.js.map +1 -0
  26. package/dist/context/estimate.d.ts +18 -0
  27. package/dist/context/estimate.js +20 -0
  28. package/dist/context/estimate.js.map +1 -0
  29. package/dist/context/file-spill.d.ts +5 -0
  30. package/dist/context/file-spill.js +25 -0
  31. package/dist/context/file-spill.js.map +1 -0
  32. package/dist/context/index.d.ts +10 -0
  33. package/dist/context/index.js +10 -0
  34. package/dist/context/index.js.map +1 -0
  35. package/dist/context/mask.d.ts +27 -0
  36. package/dist/context/mask.js +71 -0
  37. package/dist/context/mask.js.map +1 -0
  38. package/dist/context/mid-turn.d.ts +40 -0
  39. package/dist/context/mid-turn.js +82 -0
  40. package/dist/context/mid-turn.js.map +1 -0
  41. package/dist/context/policy.d.ts +9 -0
  42. package/dist/context/policy.js +140 -0
  43. package/dist/context/policy.js.map +1 -0
  44. package/dist/context/spill-ledger.d.ts +25 -0
  45. package/dist/context/spill-ledger.js +54 -0
  46. package/dist/context/spill-ledger.js.map +1 -0
  47. package/dist/context/spill.d.ts +6 -0
  48. package/dist/context/spill.js +14 -0
  49. package/dist/context/spill.js.map +1 -0
  50. package/dist/context/summarize.d.ts +53 -0
  51. package/dist/context/summarize.js +204 -0
  52. package/dist/context/summarize.js.map +1 -0
  53. package/dist/context/summary-template.d.ts +29 -0
  54. package/dist/context/summary-template.js +69 -0
  55. package/dist/context/summary-template.js.map +1 -0
  56. package/dist/context/types.d.ts +150 -0
  57. package/dist/context/types.js +2 -0
  58. package/dist/context/types.js.map +1 -0
  59. package/dist/context/write-cap.d.ts +19 -0
  60. package/dist/context/write-cap.js +41 -0
  61. package/dist/context/write-cap.js.map +1 -0
  62. package/dist/create-harness.d.ts +7 -0
  63. package/dist/create-harness.js +21 -0
  64. package/dist/create-harness.js.map +1 -0
  65. package/dist/credentials/addresses.d.ts +14 -0
  66. package/dist/credentials/addresses.js +144 -0
  67. package/dist/credentials/addresses.js.map +1 -0
  68. package/dist/credentials/allowlist.d.ts +34 -0
  69. package/dist/credentials/allowlist.js +77 -0
  70. package/dist/credentials/allowlist.js.map +1 -0
  71. package/dist/credentials/egress-proxy.d.ts +70 -0
  72. package/dist/credentials/egress-proxy.js +482 -0
  73. package/dist/credentials/egress-proxy.js.map +1 -0
  74. package/dist/credentials/index.d.ts +9 -0
  75. package/dist/credentials/index.js +10 -0
  76. package/dist/credentials/index.js.map +1 -0
  77. package/dist/credentials/scrub.d.ts +16 -0
  78. package/dist/credentials/scrub.js +93 -0
  79. package/dist/credentials/scrub.js.map +1 -0
  80. package/dist/errors.d.ts +56 -0
  81. package/dist/errors.js +63 -0
  82. package/dist/errors.js.map +1 -0
  83. package/dist/extensions/compose.d.ts +27 -0
  84. package/dist/extensions/compose.js +83 -0
  85. package/dist/extensions/compose.js.map +1 -0
  86. package/dist/extensions/context-files-node.d.ts +28 -0
  87. package/dist/extensions/context-files-node.js +74 -0
  88. package/dist/extensions/context-files-node.js.map +1 -0
  89. package/dist/extensions/context-files.d.ts +68 -0
  90. package/dist/extensions/context-files.js +214 -0
  91. package/dist/extensions/context-files.js.map +1 -0
  92. package/dist/extensions/digest.d.ts +6 -0
  93. package/dist/extensions/digest.js +68 -0
  94. package/dist/extensions/digest.js.map +1 -0
  95. package/dist/extensions/index.d.ts +10 -0
  96. package/dist/extensions/index.js +10 -0
  97. package/dist/extensions/index.js.map +1 -0
  98. package/dist/extensions/load.d.ts +42 -0
  99. package/dist/extensions/load.js +211 -0
  100. package/dist/extensions/load.js.map +1 -0
  101. package/dist/extensions/lock.d.ts +8 -0
  102. package/dist/extensions/lock.js +95 -0
  103. package/dist/extensions/lock.js.map +1 -0
  104. package/dist/extensions/node.d.ts +10 -0
  105. package/dist/extensions/node.js +11 -0
  106. package/dist/extensions/node.js.map +1 -0
  107. package/dist/extensions/project-dirs.d.ts +24 -0
  108. package/dist/extensions/project-dirs.js +97 -0
  109. package/dist/extensions/project-dirs.js.map +1 -0
  110. package/dist/extensions/skills-node.d.ts +34 -0
  111. package/dist/extensions/skills-node.js +123 -0
  112. package/dist/extensions/skills-node.js.map +1 -0
  113. package/dist/extensions/skills.d.ts +51 -0
  114. package/dist/extensions/skills.js +175 -0
  115. package/dist/extensions/skills.js.map +1 -0
  116. package/dist/extensions/trust-file.d.ts +3 -0
  117. package/dist/extensions/trust-file.js +62 -0
  118. package/dist/extensions/trust-file.js.map +1 -0
  119. package/dist/extensions/trust-store-node.d.ts +10 -0
  120. package/dist/extensions/trust-store-node.js +33 -0
  121. package/dist/extensions/trust-store-node.js.map +1 -0
  122. package/dist/extensions/types.d.ts +42 -0
  123. package/dist/extensions/types.js +2 -0
  124. package/dist/extensions/types.js.map +1 -0
  125. package/dist/harness.d.ts +156 -0
  126. package/dist/harness.js +2 -0
  127. package/dist/harness.js.map +1 -0
  128. package/dist/index.d.ts +4 -0
  129. package/dist/index.js +5 -0
  130. package/dist/index.js.map +1 -0
  131. package/dist/mcp/connection.d.ts +22 -0
  132. package/dist/mcp/connection.js +267 -0
  133. package/dist/mcp/connection.js.map +1 -0
  134. package/dist/mcp/content.d.ts +27 -0
  135. package/dist/mcp/content.js +177 -0
  136. package/dist/mcp/content.js.map +1 -0
  137. package/dist/mcp/errors.d.ts +19 -0
  138. package/dist/mcp/errors.js +21 -0
  139. package/dist/mcp/errors.js.map +1 -0
  140. package/dist/mcp/index.d.ts +10 -0
  141. package/dist/mcp/index.js +10 -0
  142. package/dist/mcp/index.js.map +1 -0
  143. package/dist/mcp/manager.d.ts +7 -0
  144. package/dist/mcp/manager.js +173 -0
  145. package/dist/mcp/manager.js.map +1 -0
  146. package/dist/mcp/record.d.ts +7 -0
  147. package/dist/mcp/record.js +20 -0
  148. package/dist/mcp/record.js.map +1 -0
  149. package/dist/mcp/stdio.d.ts +39 -0
  150. package/dist/mcp/stdio.js +382 -0
  151. package/dist/mcp/stdio.js.map +1 -0
  152. package/dist/mcp/types.d.ts +172 -0
  153. package/dist/mcp/types.js +2 -0
  154. package/dist/mcp/types.js.map +1 -0
  155. package/dist/memory/index.d.ts +2 -0
  156. package/dist/memory/index.js +3 -0
  157. package/dist/memory/index.js.map +1 -0
  158. package/dist/permissions/default-rules.d.ts +7 -0
  159. package/dist/permissions/default-rules.js +42 -0
  160. package/dist/permissions/default-rules.js.map +1 -0
  161. package/dist/permissions/errors.d.ts +11 -0
  162. package/dist/permissions/errors.js +14 -0
  163. package/dist/permissions/errors.js.map +1 -0
  164. package/dist/permissions/index.d.ts +9 -0
  165. package/dist/permissions/index.js +9 -0
  166. package/dist/permissions/index.js.map +1 -0
  167. package/dist/permissions/match.d.ts +33 -0
  168. package/dist/permissions/match.js +287 -0
  169. package/dist/permissions/match.js.map +1 -0
  170. package/dist/permissions/pipeline.d.ts +9 -0
  171. package/dist/permissions/pipeline.js +235 -0
  172. package/dist/permissions/pipeline.js.map +1 -0
  173. package/dist/permissions/rules.d.ts +22 -0
  174. package/dist/permissions/rules.js +74 -0
  175. package/dist/permissions/rules.js.map +1 -0
  176. package/dist/permissions/shadow.d.ts +5 -0
  177. package/dist/permissions/shadow.js +22 -0
  178. package/dist/permissions/shadow.js.map +1 -0
  179. package/dist/permissions/types.d.ts +104 -0
  180. package/dist/permissions/types.js +2 -0
  181. package/dist/permissions/types.js.map +1 -0
  182. package/dist/sandbox/base.d.ts +35 -0
  183. package/dist/sandbox/base.js +60 -0
  184. package/dist/sandbox/base.js.map +1 -0
  185. package/dist/sandbox/docker/index.d.ts +35 -0
  186. package/dist/sandbox/docker/index.js +448 -0
  187. package/dist/sandbox/docker/index.js.map +1 -0
  188. package/dist/sandbox/errors.d.ts +16 -0
  189. package/dist/sandbox/errors.js +22 -0
  190. package/dist/sandbox/errors.js.map +1 -0
  191. package/dist/sandbox/host-files.d.ts +63 -0
  192. package/dist/sandbox/host-files.js +248 -0
  193. package/dist/sandbox/host-files.js.map +1 -0
  194. package/dist/sandbox/index.d.ts +8 -0
  195. package/dist/sandbox/index.js +8 -0
  196. package/dist/sandbox/index.js.map +1 -0
  197. package/dist/sandbox/none.d.ts +17 -0
  198. package/dist/sandbox/none.js +108 -0
  199. package/dist/sandbox/none.js.map +1 -0
  200. package/dist/sandbox/process.d.ts +61 -0
  201. package/dist/sandbox/process.js +253 -0
  202. package/dist/sandbox/process.js.map +1 -0
  203. package/dist/sandbox/spawn-env.d.ts +20 -0
  204. package/dist/sandbox/spawn-env.js +128 -0
  205. package/dist/sandbox/spawn-env.js.map +1 -0
  206. package/dist/sandbox/srt/index.d.ts +35 -0
  207. package/dist/sandbox/srt/index.js +264 -0
  208. package/dist/sandbox/srt/index.js.map +1 -0
  209. package/dist/sandbox/srt/settings.d.ts +48 -0
  210. package/dist/sandbox/srt/settings.js +31 -0
  211. package/dist/sandbox/srt/settings.js.map +1 -0
  212. package/dist/sandbox/types.d.ts +88 -0
  213. package/dist/sandbox/types.js +6 -0
  214. package/dist/sandbox/types.js.map +1 -0
  215. package/dist/server/answers.d.ts +16 -0
  216. package/dist/server/answers.js +43 -0
  217. package/dist/server/answers.js.map +1 -0
  218. package/dist/server/connection.d.ts +99 -0
  219. package/dist/server/connection.js +309 -0
  220. package/dist/server/connection.js.map +1 -0
  221. package/dist/server/dispatcher.d.ts +86 -0
  222. package/dist/server/dispatcher.js +800 -0
  223. package/dist/server/dispatcher.js.map +1 -0
  224. package/dist/server/index.d.ts +13 -0
  225. package/dist/server/index.js +12 -0
  226. package/dist/server/index.js.map +1 -0
  227. package/dist/server/local-transport.d.ts +44 -0
  228. package/dist/server/local-transport.js +103 -0
  229. package/dist/server/local-transport.js.map +1 -0
  230. package/dist/server/outbox.d.ts +31 -0
  231. package/dist/server/outbox.js +130 -0
  232. package/dist/server/outbox.js.map +1 -0
  233. package/dist/server/params.d.ts +25 -0
  234. package/dist/server/params.js +112 -0
  235. package/dist/server/params.js.map +1 -0
  236. package/dist/server/protocol.schema.json +2448 -0
  237. package/dist/server/rpc-session.d.ts +43 -0
  238. package/dist/server/rpc-session.js +167 -0
  239. package/dist/server/rpc-session.js.map +1 -0
  240. package/dist/server/stdio-streams.d.ts +67 -0
  241. package/dist/server/stdio-streams.js +218 -0
  242. package/dist/server/stdio-streams.js.map +1 -0
  243. package/dist/server/stdio.d.ts +59 -0
  244. package/dist/server/stdio.js +189 -0
  245. package/dist/server/stdio.js.map +1 -0
  246. package/dist/server/websocket.d.ts +106 -0
  247. package/dist/server/websocket.js +327 -0
  248. package/dist/server/websocket.js.map +1 -0
  249. package/dist/session/approvals.d.ts +81 -0
  250. package/dist/session/approvals.js +217 -0
  251. package/dist/session/approvals.js.map +1 -0
  252. package/dist/session/code-call-log.d.ts +42 -0
  253. package/dist/session/code-call-log.js +63 -0
  254. package/dist/session/code-call-log.js.map +1 -0
  255. package/dist/session/code-call-result.d.ts +19 -0
  256. package/dist/session/code-call-result.js +95 -0
  257. package/dist/session/code-call-result.js.map +1 -0
  258. package/dist/session/code-call.d.ts +49 -0
  259. package/dist/session/code-call.js +345 -0
  260. package/dist/session/code-call.js.map +1 -0
  261. package/dist/session/effect-scope.d.ts +11 -0
  262. package/dist/session/effect-scope.js +10 -0
  263. package/dist/session/effect-scope.js.map +1 -0
  264. package/dist/session/errors.d.ts +19 -0
  265. package/dist/session/errors.js +27 -0
  266. package/dist/session/errors.js.map +1 -0
  267. package/dist/session/file-index.d.ts +8 -0
  268. package/dist/session/file-index.js +70 -0
  269. package/dist/session/file-index.js.map +1 -0
  270. package/dist/session/file-key-store.d.ts +16 -0
  271. package/dist/session/file-key-store.js +169 -0
  272. package/dist/session/file-key-store.js.map +1 -0
  273. package/dist/session/file-lock.d.ts +52 -0
  274. package/dist/session/file-lock.js +324 -0
  275. package/dist/session/file-lock.js.map +1 -0
  276. package/dist/session/index.d.ts +22 -0
  277. package/dist/session/index.js +20 -0
  278. package/dist/session/index.js.map +1 -0
  279. package/dist/session/jsonl-store.d.ts +37 -0
  280. package/dist/session/jsonl-store.js +386 -0
  281. package/dist/session/jsonl-store.js.map +1 -0
  282. package/dist/session/jsonl.d.ts +9 -0
  283. package/dist/session/jsonl.js +10 -0
  284. package/dist/session/jsonl.js.map +1 -0
  285. package/dist/session/lock.d.ts +19 -0
  286. package/dist/session/lock.js +2 -0
  287. package/dist/session/lock.js.map +1 -0
  288. package/dist/session/memory-store.d.ts +12 -0
  289. package/dist/session/memory-store.js +60 -0
  290. package/dist/session/memory-store.js.map +1 -0
  291. package/dist/session/migrate.d.ts +41 -0
  292. package/dist/session/migrate.js +86 -0
  293. package/dist/session/migrate.js.map +1 -0
  294. package/dist/session/pointer.d.ts +15 -0
  295. package/dist/session/pointer.js +22 -0
  296. package/dist/session/pointer.js.map +1 -0
  297. package/dist/session/rebuild.d.ts +53 -0
  298. package/dist/session/rebuild.js +230 -0
  299. package/dist/session/rebuild.js.map +1 -0
  300. package/dist/session/resume.d.ts +26 -0
  301. package/dist/session/resume.js +128 -0
  302. package/dist/session/resume.js.map +1 -0
  303. package/dist/session/retention.d.ts +97 -0
  304. package/dist/session/retention.js +702 -0
  305. package/dist/session/retention.js.map +1 -0
  306. package/dist/session/runner.d.ts +156 -0
  307. package/dist/session/runner.js +656 -0
  308. package/dist/session/runner.js.map +1 -0
  309. package/dist/session/scheduler.d.ts +47 -0
  310. package/dist/session/scheduler.js +85 -0
  311. package/dist/session/scheduler.js.map +1 -0
  312. package/dist/session/secret-key-store.d.ts +47 -0
  313. package/dist/session/secret-key-store.js +79 -0
  314. package/dist/session/secret-key-store.js.map +1 -0
  315. package/dist/session/session.d.ts +106 -0
  316. package/dist/session/session.js +353 -0
  317. package/dist/session/session.js.map +1 -0
  318. package/dist/session/sticky.d.ts +48 -0
  319. package/dist/session/sticky.js +232 -0
  320. package/dist/session/sticky.js.map +1 -0
  321. package/dist/session/store.d.ts +108 -0
  322. package/dist/session/store.js +163 -0
  323. package/dist/session/store.js.map +1 -0
  324. package/dist/telemetry/index.d.ts +2 -0
  325. package/dist/telemetry/index.js +3 -0
  326. package/dist/telemetry/index.js.map +1 -0
  327. package/dist/testing/fake-sandbox.d.ts +34 -0
  328. package/dist/testing/fake-sandbox.js +221 -0
  329. package/dist/testing/fake-sandbox.js.map +1 -0
  330. package/dist/testing/index.d.ts +10 -0
  331. package/dist/testing/index.js +11 -0
  332. package/dist/testing/index.js.map +1 -0
  333. package/dist/testing/key-store-conformance.d.ts +22 -0
  334. package/dist/testing/key-store-conformance.js +97 -0
  335. package/dist/testing/key-store-conformance.js.map +1 -0
  336. package/dist/testing/run-cases.d.ts +21 -0
  337. package/dist/testing/run-cases.js +20 -0
  338. package/dist/testing/run-cases.js.map +1 -0
  339. package/dist/testing/sandbox-conformance.d.ts +64 -0
  340. package/dist/testing/sandbox-conformance.js +361 -0
  341. package/dist/testing/sandbox-conformance.js.map +1 -0
  342. package/dist/testing/scheduler-conformance.d.ts +32 -0
  343. package/dist/testing/scheduler-conformance.js +72 -0
  344. package/dist/testing/scheduler-conformance.js.map +1 -0
  345. package/dist/testing/store-conformance.d.ts +21 -0
  346. package/dist/testing/store-conformance.js +320 -0
  347. package/dist/testing/store-conformance.js.map +1 -0
  348. package/dist/tools/errors.d.ts +13 -0
  349. package/dist/tools/errors.js +17 -0
  350. package/dist/tools/errors.js.map +1 -0
  351. package/dist/tools/index.d.ts +8 -0
  352. package/dist/tools/index.js +8 -0
  353. package/dist/tools/index.js.map +1 -0
  354. package/dist/tools/registry.d.ts +3 -0
  355. package/dist/tools/registry.js +234 -0
  356. package/dist/tools/registry.js.map +1 -0
  357. package/dist/tools/tool-search.d.ts +30 -0
  358. package/dist/tools/tool-search.js +118 -0
  359. package/dist/tools/tool-search.js.map +1 -0
  360. package/dist/tools/types.d.ts +106 -0
  361. package/dist/tools/types.js +2 -0
  362. package/dist/tools/types.js.map +1 -0
  363. package/llms.txt +435 -0
  364. package/package.json +118 -3
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/memory/index.ts"],"names":[],"mappings":"AAAA,wGAAwG;AACxG,OAAO,EAAE,CAAC","sourcesContent":["/** `@buildanagent/harness/memory`: a stub that holds the entry's place until its component is built. */\nexport {};\n"]}
@@ -0,0 +1,7 @@
1
+ import type { Rule } from "./types.js";
2
+ /**
3
+ * The ask rules the harness ships: a change to a test file, and a change to a hook, CI configuration or a rules file.
4
+ * They match by path, so they ask for every change to such a file and can't tell a deleted test from an edited one; a
5
+ * product that wants to tell them apart does it in a hook. A bash command that edits these files is not covered.
6
+ */
7
+ export declare const defaultAskRules: readonly Rule[];
@@ -0,0 +1,42 @@
1
+ // The tools that change or remove a file, under the names the built-in tools use.
2
+ const EDIT_TOOLS = /^(write|edit|multi_edit|apply_patch|delete|remove|move|rename)$/;
3
+ const TEST_PATHS = [
4
+ "**/*.test.*",
5
+ "**/*.spec.*",
6
+ "**/*_test.*",
7
+ "**/test_*.*",
8
+ "**/__tests__/**",
9
+ "**/test/**",
10
+ "**/tests/**",
11
+ ];
12
+ // The files that decide what runs or what is allowed: hooks, CI, and the rules files that steer an agent.
13
+ const CONTROL_PATHS = [
14
+ "**/.git/hooks/**",
15
+ "**/.husky/**",
16
+ "**/.github/workflows/**",
17
+ "**/.gitlab-ci.yml",
18
+ "**/.circleci/**",
19
+ "**/Jenkinsfile",
20
+ "**/lefthook.yml",
21
+ "**/.pre-commit-config.yaml",
22
+ "**/AGENTS.md",
23
+ "**/CLAUDE.md",
24
+ "**/.claude/**",
25
+ "**/.agents/**",
26
+ "**/.cursor/rules/**",
27
+ ];
28
+ /**
29
+ * The ask rules the harness ships: a change to a test file, and a change to a hook, CI configuration or a rules file.
30
+ * They match by path, so they ask for every change to such a file and can't tell a deleted test from an edited one; a
31
+ * product that wants to tell them apart does it in a hook. A bash command that edits these files is not covered.
32
+ */
33
+ export const defaultAskRules = [
34
+ { tool: EDIT_TOOLS, paths: TEST_PATHS, reason: "This changes a test file, and a test is how the change is checked." },
35
+ {
36
+ tool: EDIT_TOOLS,
37
+ paths: CONTROL_PATHS,
38
+ reason: "This changes a hook, CI configuration or a rules file, which decide what runs and what is allowed.",
39
+ },
40
+ { tool: "bash", commandPrefix: ["git", "rm"], reason: "This deletes tracked files, which may include tests." },
41
+ ];
42
+ //# sourceMappingURL=default-rules.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"default-rules.js","sourceRoot":"","sources":["../../src/permissions/default-rules.ts"],"names":[],"mappings":"AAEA,kFAAkF;AAClF,MAAM,UAAU,GAAG,iEAAiE,CAAC;AAErF,MAAM,UAAU,GAAG;IACjB,aAAa;IACb,aAAa;IACb,aAAa;IACb,aAAa;IACb,iBAAiB;IACjB,YAAY;IACZ,aAAa;CACd,CAAC;AAEF,0GAA0G;AAC1G,MAAM,aAAa,GAAG;IACpB,kBAAkB;IAClB,cAAc;IACd,yBAAyB;IACzB,mBAAmB;IACnB,iBAAiB;IACjB,gBAAgB;IAChB,iBAAiB;IACjB,4BAA4B;IAC5B,cAAc;IACd,cAAc;IACd,eAAe;IACf,eAAe;IACf,qBAAqB;CACtB,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,eAAe,GAAoB;IAC9C,EAAE,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,oEAAoE,EAAE;IACrH;QACE,IAAI,EAAE,UAAU;QAChB,KAAK,EAAE,aAAa;QACpB,MAAM,EAAE,oGAAoG;KAC7G;IACD,EAAE,IAAI,EAAE,MAAM,EAAE,aAAa,EAAE,CAAC,KAAK,EAAE,IAAI,CAAC,EAAE,MAAM,EAAE,sDAAsD,EAAE;CAC/G,CAAC","sourcesContent":["import type { Rule } from \"./types.js\";\n\n// The tools that change or remove a file, under the names the built-in tools use.\nconst EDIT_TOOLS = /^(write|edit|multi_edit|apply_patch|delete|remove|move|rename)$/;\n\nconst TEST_PATHS = [\n \"**/*.test.*\",\n \"**/*.spec.*\",\n \"**/*_test.*\",\n \"**/test_*.*\",\n \"**/__tests__/**\",\n \"**/test/**\",\n \"**/tests/**\",\n];\n\n// The files that decide what runs or what is allowed: hooks, CI, and the rules files that steer an agent.\nconst CONTROL_PATHS = [\n \"**/.git/hooks/**\",\n \"**/.husky/**\",\n \"**/.github/workflows/**\",\n \"**/.gitlab-ci.yml\",\n \"**/.circleci/**\",\n \"**/Jenkinsfile\",\n \"**/lefthook.yml\",\n \"**/.pre-commit-config.yaml\",\n \"**/AGENTS.md\",\n \"**/CLAUDE.md\",\n \"**/.claude/**\",\n \"**/.agents/**\",\n \"**/.cursor/rules/**\",\n];\n\n/**\n * The ask rules the harness ships: a change to a test file, and a change to a hook, CI configuration or a rules file.\n * They match by path, so they ask for every change to such a file and can't tell a deleted test from an edited one; a\n * product that wants to tell them apart does it in a hook. A bash command that edits these files is not covered.\n */\nexport const defaultAskRules: readonly Rule[] = [\n { tool: EDIT_TOOLS, paths: TEST_PATHS, reason: \"This changes a test file, and a test is how the change is checked.\" },\n {\n tool: EDIT_TOOLS,\n paths: CONTROL_PATHS,\n reason: \"This changes a hook, CI configuration or a rules file, which decide what runs and what is allowed.\",\n },\n { tool: \"bash\", commandPrefix: [\"git\", \"rm\"], reason: \"This deletes tracked files, which may include tests.\" },\n];\n"]}
@@ -0,0 +1,11 @@
1
+ /** The permission pipeline's named error: a `HarnessError` with the code `invalid_permission_config`. */
2
+ import { HarnessError } from "../errors.js";
3
+ /**
4
+ * Thrown when a permission configuration could never work as written. Today that is one case: an allow rule that
5
+ * covers every call to a tool while a host callback is set, so the callback could never decide a call to that tool. A
6
+ * configuration of deny rules, hooks and a host callback with no allow rules never throws it.
7
+ */
8
+ export declare class PermissionConfigError extends HarnessError {
9
+ readonly name = "PermissionConfigError";
10
+ constructor(message: string);
11
+ }
@@ -0,0 +1,14 @@
1
+ /** The permission pipeline's named error: a `HarnessError` with the code `invalid_permission_config`. */
2
+ import { HarnessError } from "../errors.js";
3
+ /**
4
+ * Thrown when a permission configuration could never work as written. Today that is one case: an allow rule that
5
+ * covers every call to a tool while a host callback is set, so the callback could never decide a call to that tool. A
6
+ * configuration of deny rules, hooks and a host callback with no allow rules never throws it.
7
+ */
8
+ export class PermissionConfigError extends HarnessError {
9
+ name = "PermissionConfigError";
10
+ constructor(message) {
11
+ super("invalid_permission_config", message);
12
+ }
13
+ }
14
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/permissions/errors.ts"],"names":[],"mappings":"AAAA,yGAAyG;AACzG,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C;;;;GAIG;AACH,MAAM,OAAO,qBAAsB,SAAQ,YAAY;IACnC,IAAI,GAAG,uBAAuB,CAAC;IAEjD,YAAY,OAAe;QACzB,KAAK,CAAC,2BAA2B,EAAE,OAAO,CAAC,CAAC;IAC9C,CAAC;CACF","sourcesContent":["/** The permission pipeline's named error: a `HarnessError` with the code `invalid_permission_config`. */\nimport { HarnessError } from \"../errors.js\";\n\n/**\n * Thrown when a permission configuration could never work as written. Today that is one case: an allow rule that\n * covers every call to a tool while a host callback is set, so the callback could never decide a call to that tool. A\n * configuration of deny rules, hooks and a host callback with no allow rules never throws it.\n */\nexport class PermissionConfigError extends HarnessError {\n override readonly name = \"PermissionConfigError\";\n\n constructor(message: string) {\n super(\"invalid_permission_config\", message);\n }\n}\n"]}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * `@buildanagent/harness/permissions`: the permission pipeline that decides every tool call. It runs hooks, deny rules,
3
+ * ask rules, the mode, allow rules and a host callback in that order, and a call no rule settles asks when a person can
4
+ * answer and is denied when none can.
5
+ */
6
+ export { defaultAskRules } from "./default-rules.js";
7
+ export { PermissionConfigError } from "./errors.js";
8
+ export { createPermissionPipeline } from "./pipeline.js";
9
+ export type { Decision, HookDecision, PermissionConfig, PermissionHook, PermissionMode, PermissionPipeline, PolicyContext, PolicyInput, PolicySession, RecordedEntry, Rule, ToolCall, } from "./types.js";
@@ -0,0 +1,9 @@
1
+ /**
2
+ * `@buildanagent/harness/permissions`: the permission pipeline that decides every tool call. It runs hooks, deny rules,
3
+ * ask rules, the mode, allow rules and a host callback in that order, and a call no rule settles asks when a person can
4
+ * answer and is denied when none can.
5
+ */
6
+ export { defaultAskRules } from "./default-rules.js";
7
+ export { PermissionConfigError } from "./errors.js";
8
+ export { createPermissionPipeline } from "./pipeline.js";
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/permissions/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC","sourcesContent":["/**\n * `@buildanagent/harness/permissions`: the permission pipeline that decides every tool call. It runs hooks, deny rules,\n * ask rules, the mode, allow rules and a host callback in that order, and a call no rule settles asks when a person can\n * answer and is denied when none can.\n */\nexport { defaultAskRules } from \"./default-rules.js\";\nexport { PermissionConfigError } from \"./errors.js\";\nexport { createPermissionPipeline } from \"./pipeline.js\";\nexport type {\n Decision,\n HookDecision,\n PermissionConfig,\n PermissionHook,\n PermissionMode,\n PermissionPipeline,\n PolicyContext,\n PolicyInput,\n PolicySession,\n RecordedEntry,\n Rule,\n ToolCall,\n} from \"./types.js\";\n"]}
@@ -0,0 +1,33 @@
1
+ /**
2
+ * What a rule reads from a call: the paths in its input, and the commands in its shell command. The reading is
3
+ * heuristic, and the limits are in the README: a path in a field this file doesn't know, or a command built by a shell
4
+ * feature it doesn't parse, is not seen.
5
+ */
6
+ /** A path made absolute-or-relative but never containing `.`, `..` or a double slash, with `/` as the separator. */
7
+ export declare function normalizePath(path: string): string;
8
+ /** The paths an input names, normalised. */
9
+ export declare function pathsOf(input: unknown): string[];
10
+ /**
11
+ * A glob as a regular expression: `*` is any run of characters but `/`, `**` any run, `?` one character but `/`. With
12
+ * `anywhere`, a relative glob also matches below any directory, because the pipeline doesn't know the working
13
+ * directory and a deny or ask rule must not miss `/repo/secrets/a` for `secrets/**`.
14
+ */
15
+ export declare function globToRegExp(glob: string, anywhere?: boolean): RegExp;
16
+ /** A name pattern: a `*` matches any run of characters. */
17
+ export declare function nameMatches(pattern: string, name: string): boolean;
18
+ /** A shell command as the words of each simple command in it. `opaque` is true when it hides commands in a substitution. */
19
+ export interface ParsedCommand {
20
+ readonly parts: string[][];
21
+ readonly opaque: boolean;
22
+ /** True when a substitution or `-c` script lay deeper than the parser reads, so a rule can't tell what it runs. */
23
+ readonly unreadable: boolean;
24
+ }
25
+ /** The commands an input carries, or `undefined` when it has no command field. A list is one command's words. */
26
+ export declare function commandOf(input: unknown): ParsedCommand | undefined;
27
+ /**
28
+ * A command's words without leading `NAME=value` words, group and keyword leaders such as `{` and `!`, and wrappers
29
+ * such as `sudo -u root` or `env -i`, for a deny or ask rule.
30
+ */
31
+ export declare function strippedWords(words: readonly string[]): string[];
32
+ /** Whether `words` begins with `prefix`, word for word. */
33
+ export declare function startsWithWords(words: readonly string[], prefix: readonly string[]): boolean;
@@ -0,0 +1,287 @@
1
+ /**
2
+ * What a rule reads from a call: the paths in its input, and the commands in its shell command. The reading is
3
+ * heuristic, and the limits are in the README: a path in a field this file doesn't know, or a command built by a shell
4
+ * feature it doesn't parse, is not seen.
5
+ */
6
+ const PATH_KEYS = ["path", "file", "file_path", "filePath", "target", "destination", "source"];
7
+ const PATH_LIST_KEYS = ["paths", "files"];
8
+ const COMMAND_KEYS = ["command", "cmd"];
9
+ // Words that start a command without changing which program runs, so a deny or ask rule looks past them. The value is
10
+ // the options that take a value, which are skipped with it.
11
+ const WRAPPERS = new Map([
12
+ ["sudo", ["-u", "-g", "-h", "-p", "-C", "-D", "-R", "-T", "-U"]],
13
+ ["env", ["-u", "-C", "-S"]],
14
+ ["nice", ["-n"]],
15
+ ["time", ["-f", "-o"]],
16
+ ["exec", ["-a"]],
17
+ ["command", []],
18
+ ["nohup", []],
19
+ ["doas", ["-u", "-C"]],
20
+ ["xargs", ["-I", "-n", "-P", "-L", "-s", "-d", "-E"]],
21
+ ["timeout", ["-s", "-k"]],
22
+ ]);
23
+ // Wrappers whose options are followed by positional words that are not the program, such as timeout's duration.
24
+ const WRAPPER_POSITIONALS = new Map([["timeout", 1]]);
25
+ /** A program's name without its directory, so `/usr/bin/git` is `git`. */
26
+ const programName = (word) => word.split("/").at(-1) || word;
27
+ // Shell syntax that starts a command without being its program: a group, a negation or a keyword.
28
+ const LEADERS = new Set(["{", "}", "!", "if", "then", "else", "elif", "do", "while", "until"]);
29
+ const SHELLS = new Set(["bash", "sh", "zsh", "dash"]);
30
+ const MAX_DEPTH = 3;
31
+ /** A path made absolute-or-relative but never containing `.`, `..` or a double slash, with `/` as the separator. */
32
+ export function normalizePath(path) {
33
+ const absolute = path.startsWith("/") || path.startsWith("\\");
34
+ const kept = [];
35
+ for (const part of path.split(/[\\/]+/)) {
36
+ if (part === "" || part === ".")
37
+ continue;
38
+ if (part !== "..")
39
+ kept.push(part);
40
+ else if (kept.length > 0 && kept.at(-1) !== "..")
41
+ kept.pop();
42
+ else if (!absolute)
43
+ kept.push("..");
44
+ }
45
+ return `${absolute ? "/" : ""}${kept.join("/")}`;
46
+ }
47
+ /** The paths an input names, normalised. */
48
+ export function pathsOf(input) {
49
+ if (typeof input !== "object" || input === null)
50
+ return [];
51
+ const record = input;
52
+ const found = PATH_KEYS.map((key) => record[key]);
53
+ for (const key of PATH_LIST_KEYS) {
54
+ const list = record[key];
55
+ if (Array.isArray(list))
56
+ found.push(...list);
57
+ }
58
+ return found.filter((value) => typeof value === "string").map(normalizePath);
59
+ }
60
+ const escapeRegExp = (text) => text.replace(/[.+?^${}()|[\]\\]/g, "\\$&");
61
+ const isRelative = (pattern) => !pattern.startsWith("/") && !pattern.startsWith("**");
62
+ /**
63
+ * A glob as a regular expression: `*` is any run of characters but `/`, `**` any run, `?` one character but `/`. With
64
+ * `anywhere`, a relative glob also matches below any directory, because the pipeline doesn't know the working
65
+ * directory and a deny or ask rule must not miss `/repo/secrets/a` for `secrets/**`.
66
+ */
67
+ export function globToRegExp(glob, anywhere = false) {
68
+ const pattern = normalizePath(glob);
69
+ const prefix = anywhere && isRelative(pattern) ? "(?:.*/)?" : "";
70
+ return new RegExp(`^${prefix}${globBody(pattern)}$`);
71
+ }
72
+ /** The regular expression source of a glob's text. */
73
+ function globBody(pattern) {
74
+ let source = "";
75
+ for (let i = 0; i < pattern.length; i += 1) {
76
+ const char = pattern[i];
77
+ if (char === "*" && pattern[i + 1] === "*") {
78
+ const slash = pattern[i + 2] === "/";
79
+ source += slash ? "(?:.*/)?" : ".*";
80
+ i += slash ? 2 : 1;
81
+ }
82
+ else if (char === "*")
83
+ source += "[^/]*";
84
+ else if (char === "?")
85
+ source += "[^/]";
86
+ else
87
+ source += escapeRegExp(char);
88
+ }
89
+ return source;
90
+ }
91
+ /** A name pattern: a `*` matches any run of characters. */
92
+ export function nameMatches(pattern, name) {
93
+ if (!pattern.includes("*"))
94
+ return pattern === name;
95
+ return new RegExp(`^${pattern.split("*").map(escapeRegExp).join(".*")}$`).test(name);
96
+ }
97
+ function endWord(scan) {
98
+ if (scan.inWord)
99
+ scan.words.push(scan.word);
100
+ scan.word = "";
101
+ scan.inWord = false;
102
+ }
103
+ function endPart(scan) {
104
+ endWord(scan);
105
+ if (scan.words.length > 0)
106
+ scan.parts.push(scan.words);
107
+ scan.words = [];
108
+ }
109
+ /** The length of the separator that starts at `i`, or 0. A `(` or `)` ends a command, as a subshell's edges do. */
110
+ function separatorAt(text, i) {
111
+ const pair = text.slice(i, i + 2);
112
+ if (pair === "&&" || pair === "||" || pair === "|&")
113
+ return 2;
114
+ // An & beside a redirection, as in 2>&1 and &>file, is part of it and not a separator.
115
+ if (text[i] === "&" && (text[i - 1] === ">" || text[i - 1] === "<" || text[i + 1] === ">"))
116
+ return 0;
117
+ return ";|&\n()".includes(text[i]) ? 1 : 0;
118
+ }
119
+ /** Reads one quoted run starting at the quote at `i` and returns where it ended. */
120
+ function readQuoted(text, i, scan) {
121
+ const quote = text[i];
122
+ // `$'...'` is ANSI-C quoting, and the `$` is not part of the word.
123
+ if (quote === "'" && scan.word === "$")
124
+ scan.word = "";
125
+ scan.inWord = true;
126
+ let at = i + 1;
127
+ for (; at < text.length && text[at] !== quote; at += 1) {
128
+ if (quote === '"' && text[at] === "\\" && at + 1 < text.length)
129
+ at += 1;
130
+ scan.word += text[at];
131
+ }
132
+ return at;
133
+ }
134
+ /** Adds the plain character at `i` to the current word, and returns where reading goes on. A backslash escapes the next one. */
135
+ function readPlain(text, i, scan) {
136
+ if (text[i] !== "\\" || i + 1 >= text.length) {
137
+ scan.word += text[i];
138
+ scan.inWord = true;
139
+ return i;
140
+ }
141
+ // A backslash-newline joins the lines, so the word goes on without it.
142
+ if (text[i + 1] !== "\n") {
143
+ scan.word += text[i + 1];
144
+ scan.inWord = true;
145
+ }
146
+ return i + 1;
147
+ }
148
+ function splitWords(text) {
149
+ const scan = { parts: [], words: [], word: "", inWord: false };
150
+ for (let i = 0; i < text.length; i += 1) {
151
+ const char = text[i];
152
+ const separator = separatorAt(text, i);
153
+ if (separator > 0 && !(char === "(" && text[i - 1] === "$")) {
154
+ endPart(scan);
155
+ i += separator - 1;
156
+ }
157
+ else if (char === "'" || char === '"')
158
+ i = readQuoted(text, i, scan);
159
+ else if (/\s/.test(char))
160
+ endWord(scan);
161
+ else
162
+ i = readPlain(text, i, scan);
163
+ }
164
+ endPart(scan);
165
+ return scan.parts;
166
+ }
167
+ /** The text between the parenthesis at `open` and its match, with nesting, or the rest of the text when unbalanced. */
168
+ function balanced(text, open) {
169
+ let level = 0;
170
+ for (let i = open; i < text.length; i += 1) {
171
+ if (text[i] === "(")
172
+ level += 1;
173
+ else if (text[i] === ")") {
174
+ level -= 1;
175
+ if (level === 0)
176
+ return text.slice(open + 1, i);
177
+ }
178
+ }
179
+ return text.slice(open + 1);
180
+ }
181
+ /** The texts a command runs inside `$( )`, backticks and process substitution, which the outer words don't show. */
182
+ function substitutions(text) {
183
+ const found = [];
184
+ for (let i = 0; i < text.length; i += 1) {
185
+ if ((text[i] === "$" || text[i] === "<" || text[i] === ">") && text[i + 1] === "(")
186
+ found.push(balanced(text, i + 1));
187
+ else if (text[i] === "`") {
188
+ const end = text.indexOf("`", i + 1);
189
+ found.push(text.slice(i + 1, end < 0 ? text.length : end));
190
+ if (end < 0)
191
+ break;
192
+ i = end;
193
+ }
194
+ }
195
+ return found;
196
+ }
197
+ /** The script a `bash -c` style part runs, when it is one: a shell whose options include `-c`. */
198
+ function shellScript(words) {
199
+ const [program, ...rest] = strippedWords(words);
200
+ if (program === "eval")
201
+ return rest.join(" ");
202
+ if (program === undefined || !SHELLS.has(program))
203
+ return undefined;
204
+ const flag = rest.findIndex((word) => /^-[a-z]*c[a-z]*$/.test(word));
205
+ return flag < 0 ? undefined : rest.slice(flag + 1).find((word) => !word.startsWith("-"));
206
+ }
207
+ /**
208
+ * The commands of `base`, of the substitutions `inner` and of the `-c` scripts of any of them, read to a fixed depth.
209
+ * A command still unread at the limit is `unreadable`, which a deny or ask rule treats as a match.
210
+ */
211
+ function assemble(base, inner, depth, opaque) {
212
+ const read = depth < MAX_DEPTH;
213
+ const nested = read ? inner.map((text) => parseCommandAt(text, depth + 1)) : [];
214
+ const parts = [...base, ...nested.flatMap((command) => command.parts)];
215
+ const scripts = parts.map(shellScript).filter((script) => script !== undefined);
216
+ const scripted = read ? scripts.map((text) => parseCommandAt(text, depth + 1)) : [];
217
+ const deeper = [...nested, ...scripted];
218
+ return {
219
+ parts: [...parts, ...scripted.flatMap((command) => command.parts)],
220
+ opaque: opaque || inner.length > 0,
221
+ unreadable: (!read && (inner.length > 0 || scripts.length > 0)) || deeper.some((command) => command.unreadable),
222
+ };
223
+ }
224
+ function parseCommandAt(text, depth) {
225
+ return assemble(splitWords(text), substitutions(text), depth, /\$'[^']*\\/.test(text));
226
+ }
227
+ /** The commands an input carries, or `undefined` when it has no command field. A list is one command's words. */
228
+ export function commandOf(input) {
229
+ if (typeof input !== "object" || input === null)
230
+ return undefined;
231
+ const record = input;
232
+ for (const key of COMMAND_KEYS) {
233
+ const value = record[key];
234
+ if (typeof value === "string")
235
+ return parseCommandAt(value, 0);
236
+ if (Array.isArray(value) && value.every((word) => typeof word === "string")) {
237
+ return assemble(value.length === 0 ? [] : [value], [], 0, false);
238
+ }
239
+ }
240
+ return undefined;
241
+ }
242
+ /** The index after a wrapper's options, skipping the value of each option that takes one. */
243
+ function skipOptions(words, from, withValue) {
244
+ let at = from;
245
+ while (at < words.length && words[at].startsWith("-")) {
246
+ if (words[at] === "--")
247
+ return at + 1;
248
+ at += withValue.includes(words[at]) ? 2 : 1;
249
+ }
250
+ return at;
251
+ }
252
+ /**
253
+ * A command's words without leading `NAME=value` words, group and keyword leaders such as `{` and `!`, and wrappers
254
+ * such as `sudo -u root` or `env -i`, for a deny or ask rule.
255
+ */
256
+ export function strippedWords(words) {
257
+ let at = 0;
258
+ while (at < words.length) {
259
+ const word = programName(words[at]);
260
+ const options = WRAPPERS.get(word);
261
+ if (options !== undefined)
262
+ at = skipOptions(words, at + 1, options) + (WRAPPER_POSITIONALS.get(word) ?? 0);
263
+ else if (LEADERS.has(word) || /^[A-Za-z_][A-Za-z0-9_]*=/.test(word))
264
+ at += 1;
265
+ else
266
+ break;
267
+ }
268
+ if (at >= words.length)
269
+ return [];
270
+ const program = programName(words[at]);
271
+ return program === "git" ? ["git", ...words.slice(skipGitOptions(words, at + 1))] : [program, ...words.slice(at + 1)];
272
+ }
273
+ // Options that go before a git subcommand, and take a value as the next word when written without `=`.
274
+ const GIT_VALUE_OPTIONS = ["-C", "-c", "--git-dir", "--work-tree", "--namespace", "--exec-path"];
275
+ /** The index of git's subcommand: after its global options and their values. */
276
+ function skipGitOptions(words, from) {
277
+ let at = from;
278
+ while (at < words.length && words[at].startsWith("-")) {
279
+ at += GIT_VALUE_OPTIONS.includes(words[at]) ? 2 : 1;
280
+ }
281
+ return at;
282
+ }
283
+ /** Whether `words` begins with `prefix`, word for word. */
284
+ export function startsWithWords(words, prefix) {
285
+ return prefix.length > 0 && prefix.length <= words.length && prefix.every((word, index) => words[index] === word);
286
+ }
287
+ //# sourceMappingURL=match.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"match.js","sourceRoot":"","sources":["../../src/permissions/match.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,SAAS,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,QAAQ,EAAE,aAAa,EAAE,QAAQ,CAAC,CAAC;AAC/F,MAAM,cAAc,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;AAC1C,MAAM,YAAY,GAAG,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;AACxC,sHAAsH;AACtH,4DAA4D;AAC5D,MAAM,QAAQ,GAA2C,IAAI,GAAG,CAAC;IAC/D,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,IAAI,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,OAAO,OAAO,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,GAAG,KAAK,CAAC,KAAK,CAAC,cAAc,CAAC,KAAK,EAAE,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,GAAG,KAAK,CAAC,KAAK,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC;AACxH,CAAC;AAED,uGAAuG;AACvG,MAAM,iBAAiB,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,WAAW,EAAE,aAAa,EAAE,aAAa,EAAE,aAAa,CAAC,CAAC;AAEjG,gFAAgF;AAChF,SAAS,cAAc,CAAC,KAAwB,EAAE,IAAY;IAC5D,IAAI,EAAE,GAAG,IAAI,CAAC;IACd,OAAO,EAAE,GAAG,KAAK,CAAC,MAAM,IAAK,KAAK,CAAC,EAAE,CAAY,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QAClE,EAAE,IAAI,iBAAiB,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAChE,CAAC;IACD,OAAO,EAAE,CAAC;AACZ,CAAC;AAED,2DAA2D;AAC3D,MAAM,UAAU,eAAe,CAAC,KAAwB,EAAE,MAAyB;IACjF,OAAO,MAAM,CAAC,MAAM,GAAG,CAAC,IAAI,MAAM,CAAC,MAAM,IAAI,KAAK,CAAC,MAAM,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,IAAI,CAAC,CAAC;AACpH,CAAC","sourcesContent":["/**\n * What a rule reads from a call: the paths in its input, and the commands in its shell command. The reading is\n * heuristic, and the limits are in the README: a path in a field this file doesn't know, or a command built by a shell\n * feature it doesn't parse, is not seen.\n */\n\nconst PATH_KEYS = [\"path\", \"file\", \"file_path\", \"filePath\", \"target\", \"destination\", \"source\"];\nconst PATH_LIST_KEYS = [\"paths\", \"files\"];\nconst COMMAND_KEYS = [\"command\", \"cmd\"];\n// Words that start a command without changing which program runs, so a deny or ask rule looks past them. The value is\n// the options that take a value, which are skipped with it.\nconst WRAPPERS: ReadonlyMap<string, readonly string[]> = new Map([\n [\"sudo\", [\"-u\", \"-g\", \"-h\", \"-p\", \"-C\", \"-D\", \"-R\", \"-T\", \"-U\"]],\n [\"env\", [\"-u\", \"-C\", \"-S\"]],\n [\"nice\", [\"-n\"]],\n [\"time\", [\"-f\", \"-o\"]],\n [\"exec\", [\"-a\"]],\n [\"command\", []],\n [\"nohup\", []],\n [\"doas\", [\"-u\", \"-C\"]],\n [\"xargs\", [\"-I\", \"-n\", \"-P\", \"-L\", \"-s\", \"-d\", \"-E\"]],\n [\"timeout\", [\"-s\", \"-k\"]],\n]);\n// Wrappers whose options are followed by positional words that are not the program, such as timeout's duration.\nconst WRAPPER_POSITIONALS: ReadonlyMap<string, number> = new Map([[\"timeout\", 1]]);\n\n/** A program's name without its directory, so `/usr/bin/git` is `git`. */\nconst programName = (word: string): string => word.split(\"/\").at(-1) || word;\n// Shell syntax that starts a command without being its program: a group, a negation or a keyword.\nconst LEADERS = new Set([\"{\", \"}\", \"!\", \"if\", \"then\", \"else\", \"elif\", \"do\", \"while\", \"until\"]);\nconst SHELLS = new Set([\"bash\", \"sh\", \"zsh\", \"dash\"]);\nconst MAX_DEPTH = 3;\n\n/** A path made absolute-or-relative but never containing `.`, `..` or a double slash, with `/` as the separator. */\nexport function normalizePath(path: string): string {\n const absolute = path.startsWith(\"/\") || path.startsWith(\"\\\\\");\n const kept: string[] = [];\n for (const part of path.split(/[\\\\/]+/)) {\n if (part === \"\" || part === \".\") continue;\n if (part !== \"..\") kept.push(part);\n else if (kept.length > 0 && kept.at(-1) !== \"..\") kept.pop();\n else if (!absolute) kept.push(\"..\");\n }\n return `${absolute ? \"/\" : \"\"}${kept.join(\"/\")}`;\n}\n\n/** The paths an input names, normalised. */\nexport function pathsOf(input: unknown): string[] {\n if (typeof input !== \"object\" || input === null) return [];\n const record = input as Record<string, unknown>;\n const found: unknown[] = PATH_KEYS.map((key) => record[key]);\n for (const key of PATH_LIST_KEYS) {\n const list = record[key];\n if (Array.isArray(list)) found.push(...list);\n }\n return found.filter((value): value is string => typeof value === \"string\").map(normalizePath);\n}\n\nconst escapeRegExp = (text: string): string => text.replace(/[.+?^${}()|[\\]\\\\]/g, \"\\\\$&\");\n\nconst isRelative = (pattern: string): boolean => !pattern.startsWith(\"/\") && !pattern.startsWith(\"**\");\n\n/**\n * A glob as a regular expression: `*` is any run of characters but `/`, `**` any run, `?` one character but `/`. With\n * `anywhere`, a relative glob also matches below any directory, because the pipeline doesn't know the working\n * directory and a deny or ask rule must not miss `/repo/secrets/a` for `secrets/**`.\n */\nexport function globToRegExp(glob: string, anywhere = false): RegExp {\n const pattern = normalizePath(glob);\n const prefix = anywhere && isRelative(pattern) ? \"(?:.*/)?\" : \"\";\n return new RegExp(`^${prefix}${globBody(pattern)}$`);\n}\n\n/** The regular expression source of a glob's text. */\nfunction globBody(pattern: string): string {\n let source = \"\";\n for (let i = 0; i < pattern.length; i += 1) {\n const char = pattern[i] as string;\n if (char === \"*\" && pattern[i + 1] === \"*\") {\n const slash = pattern[i + 2] === \"/\";\n source += slash ? \"(?:.*/)?\" : \".*\";\n i += slash ? 2 : 1;\n } else if (char === \"*\") source += \"[^/]*\";\n else if (char === \"?\") source += \"[^/]\";\n else source += escapeRegExp(char);\n }\n return source;\n}\n\n/** A name pattern: a `*` matches any run of characters. */\nexport function nameMatches(pattern: string, name: string): boolean {\n if (!pattern.includes(\"*\")) return pattern === name;\n return new RegExp(`^${pattern.split(\"*\").map(escapeRegExp).join(\".*\")}$`).test(name);\n}\n\n/** A shell command as the words of each simple command in it. `opaque` is true when it hides commands in a substitution. */\nexport interface ParsedCommand {\n readonly parts: string[][];\n readonly opaque: boolean;\n /** True when a substitution or `-c` script lay deeper than the parser reads, so a rule can't tell what it runs. */\n readonly unreadable: boolean;\n}\n\ninterface Scan {\n parts: string[][];\n words: string[];\n word: string;\n inWord: boolean;\n}\n\nfunction endWord(scan: Scan): void {\n if (scan.inWord) scan.words.push(scan.word);\n scan.word = \"\";\n scan.inWord = false;\n}\n\nfunction endPart(scan: Scan): void {\n endWord(scan);\n if (scan.words.length > 0) scan.parts.push(scan.words);\n scan.words = [];\n}\n\n/** The length of the separator that starts at `i`, or 0. A `(` or `)` ends a command, as a subshell's edges do. */\nfunction separatorAt(text: string, i: number): number {\n const pair = text.slice(i, i + 2);\n if (pair === \"&&\" || pair === \"||\" || pair === \"|&\") return 2;\n // An & beside a redirection, as in 2>&1 and &>file, is part of it and not a separator.\n if (text[i] === \"&\" && (text[i - 1] === \">\" || text[i - 1] === \"<\" || text[i + 1] === \">\")) return 0;\n return \";|&\\n()\".includes(text[i] as string) ? 1 : 0;\n}\n\n/** Reads one quoted run starting at the quote at `i` and returns where it ended. */\nfunction readQuoted(text: string, i: number, scan: Scan): number {\n const quote = text[i] as string;\n // `$'...'` is ANSI-C quoting, and the `$` is not part of the word.\n if (quote === \"'\" && scan.word === \"$\") scan.word = \"\";\n scan.inWord = true;\n let at = i + 1;\n for (; at < text.length && text[at] !== quote; at += 1) {\n if (quote === '\"' && text[at] === \"\\\\\" && at + 1 < text.length) at += 1;\n scan.word += text[at];\n }\n return at;\n}\n\n/** Adds the plain character at `i` to the current word, and returns where reading goes on. A backslash escapes the next one. */\nfunction readPlain(text: string, i: number, scan: Scan): number {\n if (text[i] !== \"\\\\\" || i + 1 >= text.length) {\n scan.word += text[i];\n scan.inWord = true;\n return i;\n }\n // A backslash-newline joins the lines, so the word goes on without it.\n if (text[i + 1] !== \"\\n\") {\n scan.word += text[i + 1];\n scan.inWord = true;\n }\n return i + 1;\n}\n\nfunction splitWords(text: string): string[][] {\n const scan: Scan = { parts: [], words: [], word: \"\", inWord: false };\n for (let i = 0; i < text.length; i += 1) {\n const char = text[i] as string;\n const separator = separatorAt(text, i);\n if (separator > 0 && !(char === \"(\" && text[i - 1] === \"$\")) {\n endPart(scan);\n i += separator - 1;\n } else if (char === \"'\" || char === '\"') i = readQuoted(text, i, scan);\n else if (/\\s/.test(char)) endWord(scan);\n else i = readPlain(text, i, scan);\n }\n endPart(scan);\n return scan.parts;\n}\n\n/** The text between the parenthesis at `open` and its match, with nesting, or the rest of the text when unbalanced. */\nfunction balanced(text: string, open: number): string {\n let level = 0;\n for (let i = open; i < text.length; i += 1) {\n if (text[i] === \"(\") level += 1;\n else if (text[i] === \")\") {\n level -= 1;\n if (level === 0) return text.slice(open + 1, i);\n }\n }\n return text.slice(open + 1);\n}\n\n/** The texts a command runs inside `$( )`, backticks and process substitution, which the outer words don't show. */\nfunction substitutions(text: string): string[] {\n const found: string[] = [];\n for (let i = 0; i < text.length; i += 1) {\n if ((text[i] === \"$\" || text[i] === \"<\" || text[i] === \">\") && text[i + 1] === \"(\")\n found.push(balanced(text, i + 1));\n else if (text[i] === \"`\") {\n const end = text.indexOf(\"`\", i + 1);\n found.push(text.slice(i + 1, end < 0 ? text.length : end));\n if (end < 0) break;\n i = end;\n }\n }\n return found;\n}\n\n/** The script a `bash -c` style part runs, when it is one: a shell whose options include `-c`. */\nfunction shellScript(words: readonly string[]): string | undefined {\n const [program, ...rest] = strippedWords(words);\n if (program === \"eval\") return rest.join(\" \");\n if (program === undefined || !SHELLS.has(program)) return undefined;\n const flag = rest.findIndex((word) => /^-[a-z]*c[a-z]*$/.test(word));\n return flag < 0 ? undefined : rest.slice(flag + 1).find((word) => !word.startsWith(\"-\"));\n}\n\n/**\n * The commands of `base`, of the substitutions `inner` and of the `-c` scripts of any of them, read to a fixed depth.\n * A command still unread at the limit is `unreadable`, which a deny or ask rule treats as a match.\n */\nfunction assemble(base: string[][], inner: readonly string[], depth: number, opaque: boolean): ParsedCommand {\n const read = depth < MAX_DEPTH;\n const nested = read ? inner.map((text) => parseCommandAt(text, depth + 1)) : [];\n const parts = [...base, ...nested.flatMap((command) => command.parts)];\n const scripts = parts.map(shellScript).filter((script): script is string => script !== undefined);\n const scripted = read ? scripts.map((text) => parseCommandAt(text, depth + 1)) : [];\n const deeper = [...nested, ...scripted];\n return {\n parts: [...parts, ...scripted.flatMap((command) => command.parts)],\n opaque: opaque || inner.length > 0,\n unreadable: (!read && (inner.length > 0 || scripts.length > 0)) || deeper.some((command) => command.unreadable),\n };\n}\n\nfunction parseCommandAt(text: string, depth: number): ParsedCommand {\n return assemble(splitWords(text), substitutions(text), depth, /\\$'[^']*\\\\/.test(text));\n}\n\n/** The commands an input carries, or `undefined` when it has no command field. A list is one command's words. */\nexport function commandOf(input: unknown): ParsedCommand | undefined {\n if (typeof input !== \"object\" || input === null) return undefined;\n const record = input as Record<string, unknown>;\n for (const key of COMMAND_KEYS) {\n const value = record[key];\n if (typeof value === \"string\") return parseCommandAt(value, 0);\n if (Array.isArray(value) && value.every((word) => typeof word === \"string\")) {\n return assemble(value.length === 0 ? [] : [value as string[]], [], 0, false);\n }\n }\n return undefined;\n}\n\n/** The index after a wrapper's options, skipping the value of each option that takes one. */\nfunction skipOptions(words: readonly string[], from: number, withValue: readonly string[]): number {\n let at = from;\n while (at < words.length && (words[at] as string).startsWith(\"-\")) {\n if ((words[at] as string) === \"--\") return at + 1;\n at += withValue.includes(words[at] as string) ? 2 : 1;\n }\n return at;\n}\n\n/**\n * A command's words without leading `NAME=value` words, group and keyword leaders such as `{` and `!`, and wrappers\n * such as `sudo -u root` or `env -i`, for a deny or ask rule.\n */\nexport function strippedWords(words: readonly string[]): string[] {\n let at = 0;\n while (at < words.length) {\n const word = programName(words[at] as string);\n const options = WRAPPERS.get(word);\n if (options !== undefined) at = skipOptions(words, at + 1, options) + (WRAPPER_POSITIONALS.get(word) ?? 0);\n else if (LEADERS.has(word) || /^[A-Za-z_][A-Za-z0-9_]*=/.test(word)) at += 1;\n else break;\n }\n if (at >= words.length) return [];\n const program = programName(words[at] as string);\n return program === \"git\" ? [\"git\", ...words.slice(skipGitOptions(words, at + 1))] : [program, ...words.slice(at + 1)];\n}\n\n// Options that go before a git subcommand, and take a value as the next word when written without `=`.\nconst GIT_VALUE_OPTIONS = [\"-C\", \"-c\", \"--git-dir\", \"--work-tree\", \"--namespace\", \"--exec-path\"];\n\n/** The index of git's subcommand: after its global options and their values. */\nfunction skipGitOptions(words: readonly string[], from: number): number {\n let at = from;\n while (at < words.length && (words[at] as string).startsWith(\"-\")) {\n at += GIT_VALUE_OPTIONS.includes(words[at] as string) ? 2 : 1;\n }\n return at;\n}\n\n/** Whether `words` begins with `prefix`, word for word. */\nexport function startsWithWords(words: readonly string[], prefix: readonly string[]): boolean {\n return prefix.length > 0 && prefix.length <= words.length && prefix.every((word, index) => words[index] === word);\n}\n"]}
@@ -0,0 +1,9 @@
1
+ import type { ToolRegistry } from "../tools/types.js";
2
+ import type { PermissionConfig, PermissionPipeline } from "./types.js";
3
+ /**
4
+ * Creates the pipeline. It throws a `PermissionConfigError` when an allow rule covers every call to a registered tool
5
+ * while a host callback is set. Deny rules, hooks and a host callback with no allow rules never throw it.
6
+ *
7
+ * With no host callback, a call that no rule settles asks when `interactive` is true and is denied when it is false.
8
+ */
9
+ export declare function createPermissionPipeline(config: PermissionConfig, registry: ToolRegistry): PermissionPipeline;