permdock 0.0.0 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (290) hide show
  1. package/README.md +268 -1
  2. package/dist/a2a/index.d.ts +178 -0
  3. package/dist/a2a/index.js +271 -0
  4. package/dist/ai-sdk/index.d.ts +74 -0
  5. package/dist/ai-sdk/index.js +137 -0
  6. package/dist/approval-required-TzNB9oQA.js +6 -0
  7. package/dist/approvals/index.d.ts +3 -0
  8. package/dist/approvals/index.js +4 -0
  9. package/dist/approvals-DaxY-Bdg.js +218 -0
  10. package/dist/approvers-aH0PJkmf.js +20 -0
  11. package/dist/arazzo-CTeVuXr5.js +70 -0
  12. package/dist/arazzo-aoTkqYsJ.js +54 -0
  13. package/dist/authzen/index.d.ts +48 -0
  14. package/dist/authzen/index.js +336 -0
  15. package/dist/better-auth/index.d.ts +92 -0
  16. package/dist/better-auth/index.js +324 -0
  17. package/dist/budget-JqcRqyhK.d.ts +11 -0
  18. package/dist/budget-NbEtbJC_.js +11 -0
  19. package/dist/capability-B68OFnZx.js +171 -0
  20. package/dist/capability-BDG_nkxt.d.ts +99 -0
  21. package/dist/catalog/index.d.ts +12 -0
  22. package/dist/catalog/index.js +2 -0
  23. package/dist/catalog-B0E6bggc.js +48 -0
  24. package/dist/catalog-H-vFGwWK.js +55 -0
  25. package/dist/catalog-doc-BSo_Q_-6.js +298 -0
  26. package/dist/catalog-idsHc0vo.js +2 -0
  27. package/dist/catalog-path-CnI0XTFK.js +12 -0
  28. package/dist/claude-agent/index.d.ts +81 -0
  29. package/dist/claude-agent/index.js +83 -0
  30. package/dist/clerk/index.d.ts +56 -0
  31. package/dist/clerk/index.js +280 -0
  32. package/dist/cli/bin.d.ts +1 -0
  33. package/dist/cli/bin.js +20 -0
  34. package/dist/cli/index.d.ts +46 -0
  35. package/dist/cli/index.js +5 -0
  36. package/dist/cloud/index.d.ts +91 -0
  37. package/dist/cloud/index.js +390 -0
  38. package/dist/cloud-BNQTrmrr.js +50 -0
  39. package/dist/cloud-Cuxr6Czw.js +117 -0
  40. package/dist/collect-B7_TIfmg.js +49 -0
  41. package/dist/collect-O-tOtbnk.js +350 -0
  42. package/dist/collect-fRPAQIWb.js +2 -0
  43. package/dist/commands-BMh_Etm2.js +93 -0
  44. package/dist/compact-y6vfu2_f.js +19 -0
  45. package/dist/compare-pfyVnBjE.js +12 -0
  46. package/dist/compile-CQbvyIBr.d.ts +30 -0
  47. package/dist/compile-D22iwvuV.js +558 -0
  48. package/dist/config-BPYmjTOp.js +26 -0
  49. package/dist/connection-JvqwHODC.js +194 -0
  50. package/dist/context-CKEAabd7.js +73 -0
  51. package/dist/context-gtAwAILx.js +6 -0
  52. package/dist/convex/index.d.ts +40 -0
  53. package/dist/convex/index.js +55 -0
  54. package/dist/create-BKF3dgFk.d.ts +162 -0
  55. package/dist/create-CSkhDU9T.js +222 -0
  56. package/dist/credential-B_rkUNlY.js +326 -0
  57. package/dist/credentials-BgRX3WEg.js +268 -0
  58. package/dist/describe-Bt1YD5uS.js +99 -0
  59. package/dist/describe-DernyItf.d.ts +37 -0
  60. package/dist/diff-BUzf5Poi.js +48 -0
  61. package/dist/diff-x5Il8LVa.js +418 -0
  62. package/dist/digest-B3kc_PgQ.d.ts +19 -0
  63. package/dist/digest-BI-6aa6d.js +27 -0
  64. package/dist/doctor-BGle8Gqi.js +1314 -0
  65. package/dist/doctor-Bqo6FwUa.js +53 -0
  66. package/dist/drizzle/index.d.ts +72 -0
  67. package/dist/drizzle/index.js +160 -0
  68. package/dist/duration-xK2jGFVc.js +25 -0
  69. package/dist/elysia/index.d.ts +71 -0
  70. package/dist/elysia/index.js +103 -0
  71. package/dist/errors-DSMnAVNa.js +43 -0
  72. package/dist/errors-DbZ1YOnb.d.ts +138 -0
  73. package/dist/errors-Iy71s7Oj.js +177 -0
  74. package/dist/errors-m3u9TmDu.js +27 -0
  75. package/dist/evaluations-DsAU9ppl.js +479 -0
  76. package/dist/eve/index.d.ts +95 -0
  77. package/dist/eve/index.js +181 -0
  78. package/dist/express/index.d.ts +46 -0
  79. package/dist/express/index.js +108 -0
  80. package/dist/fastify/index.d.ts +56 -0
  81. package/dist/fastify/index.js +141 -0
  82. package/dist/files-B_wAGYmt.js +121 -0
  83. package/dist/fixtures-Cvaw0gDG.js +64 -0
  84. package/dist/freeze-y1_jQL4v.js +31 -0
  85. package/dist/from-snapshot-BMGnhmgv.js +552 -0
  86. package/dist/generate-CH7ThJ14.js +173 -0
  87. package/dist/grantee-Bv04_Vzf.js +521 -0
  88. package/dist/headers-B5RRv3Xm.js +6 -0
  89. package/dist/headers-C8SHQccD.d.ts +6 -0
  90. package/dist/helpers-DnSOrhB9.js +682 -0
  91. package/dist/hono/index.d.ts +70 -0
  92. package/dist/hono/index.js +131 -0
  93. package/dist/hosted-BwKQ1BTA.js +265 -0
  94. package/dist/http-DPuDaChb.d.ts +13 -0
  95. package/dist/http-GgVApX1k.js +111 -0
  96. package/dist/index-CltcQ4Bf.d.ts +138 -0
  97. package/dist/index-LF_hS-yn.d.ts +177 -0
  98. package/dist/index-fG6NSXlc.d.ts +9 -0
  99. package/dist/index-xIxJLwOQ.d.ts +415 -0
  100. package/dist/index.d.ts +11 -0
  101. package/dist/index.js +21 -0
  102. package/dist/jwt/index.d.ts +87 -0
  103. package/dist/jwt/index.js +571 -0
  104. package/dist/kernel-YOGCWNLf.js +211 -0
  105. package/dist/kysely/index.d.ts +77 -0
  106. package/dist/kysely/index.js +129 -0
  107. package/dist/load-BZ24CpZP.js +69 -0
  108. package/dist/load-QOOm1z70.js +2 -0
  109. package/dist/load-jose-BL6LH4bL.js +11 -0
  110. package/dist/lru-8q4WZjBV.js +28 -0
  111. package/dist/manifest-DDQbC6K0.d.ts +118 -0
  112. package/dist/map-DowSO96j.js +158 -0
  113. package/dist/map-claims-B_6I1Rn-.js +360 -0
  114. package/dist/map-error-RJ3ZsUyA.js +16 -0
  115. package/dist/markers-B0hYLvMD.js +60 -0
  116. package/dist/may-use-CnFEjVEp.js +37 -0
  117. package/dist/mcp/index.d.ts +127 -0
  118. package/dist/mcp/index.js +563 -0
  119. package/dist/nest/index.d.ts +80 -0
  120. package/dist/nest/index.js +270 -0
  121. package/dist/next/client.d.ts +24 -0
  122. package/dist/next/client.js +31 -0
  123. package/dist/next/index.d.ts +110 -0
  124. package/dist/next/index.js +195 -0
  125. package/dist/next/plugin.d.ts +14 -0
  126. package/dist/next/plugin.js +2 -0
  127. package/dist/node/index.d.ts +43 -0
  128. package/dist/node/index.js +66 -0
  129. package/dist/openai/index.d.ts +71 -0
  130. package/dist/openai/index.js +105 -0
  131. package/dist/openapi/index.d.ts +93 -0
  132. package/dist/openapi/index.js +3 -0
  133. package/dist/openapi-CwePaF7C.js +164 -0
  134. package/dist/openapi-DWD0Uc_4.js +250 -0
  135. package/dist/openapi-DcqM8nU7.js +306 -0
  136. package/dist/openapi-import-BWRUNNeW.js +5959 -0
  137. package/dist/openapi-schema-D8j_T9tO.js +6902 -0
  138. package/dist/orpc/index.d.ts +64 -0
  139. package/dist/orpc/index.js +188 -0
  140. package/dist/otel/index.d.ts +13 -0
  141. package/dist/otel/index.js +202 -0
  142. package/dist/package-root-zGkxO3oN.js +30 -0
  143. package/dist/parse-DPfIvFMU.js +135 -0
  144. package/dist/pdp/index.d.ts +22 -0
  145. package/dist/pdp/index.js +795 -0
  146. package/dist/peer-BOr_kJE1.js +31 -0
  147. package/dist/permdock-yoZ7EjxX.js +2956 -0
  148. package/dist/permissions-B4apnahQ.d.ts +185 -0
  149. package/dist/permissions-B8vCg_bI.d.ts +52 -0
  150. package/dist/permissions-CofRqesP.js +142 -0
  151. package/dist/permissions-DC7GROPA.js +600 -0
  152. package/dist/pg-4GJWDUxG.js +953 -0
  153. package/dist/pins-CqE1jZuF.js +12 -0
  154. package/dist/plugin-4gr7IxFJ.js +65 -0
  155. package/dist/policy-ANp36PnI.js +971 -0
  156. package/dist/policy-CInmNGkM.d.ts +1959 -0
  157. package/dist/policy-Cq2fB8Q5.d.ts +20 -0
  158. package/dist/prisma/index.d.ts +135 -0
  159. package/dist/prisma/index.js +430 -0
  160. package/dist/problem-Cgp9-KZA.js +226 -0
  161. package/dist/prompt-CXYhLfsS.js +32 -0
  162. package/dist/protected-B4K3BKoX.js +138 -0
  163. package/dist/protected-BuPAycJT.d.ts +26 -0
  164. package/dist/protected-wY7nXhY9.d.ts +23 -0
  165. package/dist/provider-_wx46HpB.js +48 -0
  166. package/dist/provider-wTAUda2v.d.ts +6 -0
  167. package/dist/react/index.d.ts +6 -0
  168. package/dist/react/index.js +6 -0
  169. package/dist/react/provider-client.d.ts +2 -0
  170. package/dist/react/provider-client.js +3 -0
  171. package/dist/react-native/index.d.ts +42 -0
  172. package/dist/react-native/index.js +174 -0
  173. package/dist/refs-ChLSxbST.js +90 -0
  174. package/dist/relations-r4soIFZB.js +426 -0
  175. package/dist/revocations-Cy06JNx2.d.ts +21 -0
  176. package/dist/rls-BOFU3chG.js +233 -0
  177. package/dist/rls-CJVja9Ww.js +2119 -0
  178. package/dist/rls-graph-DxQ39PJj.js +371 -0
  179. package/dist/rls-helpers-BxRuif0l.js +1346 -0
  180. package/dist/rls-import-CXV6LBlS.js +942 -0
  181. package/dist/rls-migrate-DrFPbf8p.js +366 -0
  182. package/dist/row-check-BajTgQZ-.d.ts +43 -0
  183. package/dist/run-CJ6UvS3a.js +155 -0
  184. package/dist/runtime-DP9ttFh1.js +27 -0
  185. package/dist/saas-BRrZzJkM.js +1193 -0
  186. package/dist/schema-P8yoma__.js +296 -0
  187. package/dist/scim/index.d.ts +2 -0
  188. package/dist/scim/index.js +2 -0
  189. package/dist/scim-9NFa0XVZ.js +1445 -0
  190. package/dist/scopes-cKVp_WTw.js +212 -0
  191. package/dist/server/index.d.ts +123 -0
  192. package/dist/server/index.js +8 -0
  193. package/dist/sha256-BO0swRXL.js +150 -0
  194. package/dist/sink-Bd9PSyfq.js +141 -0
  195. package/dist/sink-Cfr9-7YC.d.ts +104 -0
  196. package/dist/skills-C_lpV4Jx.js +50 -0
  197. package/dist/skills-Dx3QLnMY.js +110 -0
  198. package/dist/snapshot-DE8dE_hz.js +1051 -0
  199. package/dist/solid/index.d.ts +63 -0
  200. package/dist/solid/index.js +197 -0
  201. package/dist/source-DoBBYJi2.js +6 -0
  202. package/dist/sources-DOpW5Ila.d.ts +347 -0
  203. package/dist/sources-DVHM3Mwq.js +284 -0
  204. package/dist/sql-Bll1d7y0.js +22 -0
  205. package/dist/src-CTNT-PBW.js +430 -0
  206. package/dist/ssf/index.d.ts +3 -0
  207. package/dist/ssf/index.js +622 -0
  208. package/dist/store-Bq90395i.d.ts +27 -0
  209. package/dist/store-C6hFW6ta.js +508 -0
  210. package/dist/stores-CkG2HrSg.js +140 -0
  211. package/dist/stores-CvOnu_2T.d.ts +41 -0
  212. package/dist/stream-BhMfZOwr.d.ts +12 -0
  213. package/dist/stream-Q_xlB6Ko.js +52 -0
  214. package/dist/style-CTm1AXDT.js +22 -0
  215. package/dist/subject-C6dLxqHU.js +24 -0
  216. package/dist/subject-settings-xt7V845g.js +82 -0
  217. package/dist/supabase/index.d.ts +67 -0
  218. package/dist/supabase/index.js +4 -0
  219. package/dist/supabase/middleware.d.ts +77 -0
  220. package/dist/supabase/middleware.js +68 -0
  221. package/dist/supabase-D8UlBA7Z.js +83 -0
  222. package/dist/supabase-DTxGtYdi.js +796 -0
  223. package/dist/supabase-hook-DW-xP4hU.js +2 -0
  224. package/dist/supabase-hook-D_OqGb_V.js +1528 -0
  225. package/dist/svelte/Protected.svelte +34 -0
  226. package/dist/svelte/index.d.ts +10 -0
  227. package/dist/svelte/index.js +53 -0
  228. package/dist/svelte/runtime.d.ts +6 -0
  229. package/dist/svelte/runtime.js +3 -0
  230. package/dist/svelte/source.d.ts +10 -0
  231. package/dist/svelte/source.js +8 -0
  232. package/dist/terminal/index.d.ts +171 -0
  233. package/dist/terminal/index.js +821 -0
  234. package/dist/testing/index.d.ts +656 -0
  235. package/dist/testing/index.js +3208 -0
  236. package/dist/testing/saas/index.d.ts +194 -0
  237. package/dist/testing/saas/index.js +3 -0
  238. package/dist/testing/saas/permissions.d.ts +2 -0
  239. package/dist/testing/saas/permissions.js +2 -0
  240. package/dist/text-diff-BdkkYSbi.js +15 -0
  241. package/dist/thenable-okc2xDsj.js +10 -0
  242. package/dist/timeout-D51niuQP.js +8 -0
  243. package/dist/trpc/index.d.ts +80 -0
  244. package/dist/trpc/index.js +205 -0
  245. package/dist/types-B8w5PFtS.d.ts +141 -0
  246. package/dist/types-B9dmiiab.d.ts +66 -0
  247. package/dist/types-BBK-exvJ.d.ts +177 -0
  248. package/dist/types-BvBk1wgn.d.ts +118 -0
  249. package/dist/types-CxquUByI.d.ts +9 -0
  250. package/dist/types-D6Z6-rKJ.d.ts +312 -0
  251. package/dist/types-DbWdEfcm.d.ts +87 -0
  252. package/dist/types-bva3i4Gf.d.ts +98 -0
  253. package/dist/types-i4BAOvdb.d.ts +97 -0
  254. package/dist/unplugin/index.d.ts +7 -0
  255. package/dist/unplugin/index.js +30 -0
  256. package/dist/usage-1ozMubLY.js +42 -0
  257. package/dist/usage-CUnK6Ou9.js +530 -0
  258. package/dist/usage-PyEor6GA.js +2 -0
  259. package/dist/validity-D0uRmJKJ.js +224 -0
  260. package/dist/verifier-B90agnhl.js +461 -0
  261. package/dist/version-CnSh33Fj.js +16 -0
  262. package/dist/vocabulary-Dk0fs-Jk.d.ts +56 -0
  263. package/dist/vue/index.d.ts +57 -0
  264. package/dist/vue/index.js +203 -0
  265. package/dist/webmcp/index.d.ts +75 -0
  266. package/dist/webmcp/index.js +313 -0
  267. package/package.json +423 -4
  268. package/rulesets/permdock.yaml +29 -0
  269. package/schemas/catalog-v1.json +507 -0
  270. package/schemas/openapi/oas-3.1.json +1298 -0
  271. package/schemas/openapi/oas-3.2.json +1516 -0
  272. package/schemas/openapi/overlay-1.1.json +79 -0
  273. package/schemas/supabase-claims-v1.json +139 -0
  274. package/schemas/supabase-manifest-v1.json +217 -0
  275. package/skills/permdock/SKILL.md +66 -0
  276. package/skills/permdock-agents/SKILL.md +77 -0
  277. package/skills/permdock-agents/references/runtimes.md +211 -0
  278. package/skills/permdock-approvals/SKILL.md +80 -0
  279. package/skills/permdock-approvals/references/stores-and-resume.md +83 -0
  280. package/skills/permdock-audit/SKILL.md +67 -0
  281. package/skills/permdock-credentials/SKILL.md +55 -0
  282. package/skills/permdock-credentials/references/tokens-keys-links.md +127 -0
  283. package/skills/permdock-data/SKILL.md +57 -0
  284. package/skills/permdock-data/references/queries-and-rls.md +54 -0
  285. package/skills/permdock-data/references/relationships.md +65 -0
  286. package/skills/permdock-tenancy/SKILL.md +77 -0
  287. package/skills/permdock-tenancy/references/ownership-and-custom-roles.md +83 -0
  288. package/skills/permdock-wire/SKILL.md +116 -0
  289. package/skills/permdock-wire/references/adapters.md +480 -0
  290. package/skills/permdock-wire/references/policy-options.md +43 -0
@@ -0,0 +1,55 @@
1
+ import { a as formatCatalogMarkdown, i as formatCatalogJson, r as catalogSchemaDocument, t as buildCatalog } from "./catalog-doc-BSo_Q_-6.js";
2
+ import { n as listSourceFiles, t as defaultSrcPath } from "./files-B_wAGYmt.js";
3
+ import { a as loadModule, i as loadConfiguredPolicy, o as pickNamed, r as leavesOf, t as asPermissionTree } from "./load-BZ24CpZP.js";
4
+ import { n as scanSources, t as runCollect } from "./collect-O-tOtbnk.js";
5
+ import { existsSync } from "node:fs";
6
+ import { resolve } from "node:path";
7
+ //#region src/cli/catalog.ts
8
+ async function runCatalog(input) {
9
+ if (input.format === "schema") return {
10
+ code: 0,
11
+ output: `${JSON.stringify(catalogSchemaDocument(), null, 2)}\n`
12
+ };
13
+ const from = input.from ?? input.config.permissions;
14
+ let document;
15
+ if (from !== void 0) {
16
+ const abs = resolve(input.cwd, from);
17
+ if (!existsSync(abs)) return {
18
+ code: 2,
19
+ output: `PermDock CLI: module not found: ${from}`
20
+ };
21
+ const tree = asPermissionTree(pickNamed(await loadModule(abs), ["permissions"]));
22
+ const srcPath = input.config.collect?.srcPath ?? defaultSrcPath();
23
+ const files = listSourceFiles(input.cwd, srcPath);
24
+ const scan = scanSources(input.cwd, files, new Set(leavesOf(tree).map((leaf) => leaf.key)));
25
+ document = buildCatalog(tree, scan, input.now.toISOString(), await loadConfiguredPolicy(input.cwd, input.config.policy));
26
+ } else {
27
+ const collected = await runCollect({
28
+ cwd: input.cwd,
29
+ config: input.config,
30
+ collect: input.config.collect ?? {},
31
+ check: false,
32
+ now: input.now,
33
+ io: input.io
34
+ });
35
+ if (collected.document === void 0) return {
36
+ code: collected.code,
37
+ output: collected.message
38
+ };
39
+ document = collected.document;
40
+ }
41
+ const filtered = input.include.length === 0 ? document : {
42
+ ...document,
43
+ permissions: document.permissions.filter((permission) => input.include.some((prefix) => permission.key === prefix || permission.key.startsWith(`${prefix}.`) || permission.resource === prefix))
44
+ };
45
+ if (input.format === "markdown") return {
46
+ code: 0,
47
+ output: formatCatalogMarkdown(filtered)
48
+ };
49
+ return {
50
+ code: 0,
51
+ output: formatCatalogJson(filtered)
52
+ };
53
+ }
54
+ //#endregion
55
+ export { runCatalog as t };
@@ -0,0 +1,298 @@
1
+ import { a as formerKeys, c as getResource, g as listPermissions } from "./permissions-DC7GROPA.js";
2
+ import { t as catalogFingerprint } from "./src-CTNT-PBW.js";
3
+ import { b as findRole } from "./grantee-Bv04_Vzf.js";
4
+ import { l as canonicalJson } from "./snapshot-DE8dE_hz.js";
5
+ import { t as byCodePoint } from "./compare-pfyVnBjE.js";
6
+ import { t as catalogSchema } from "./schema-P8yoma__.js";
7
+ import { o as generatorBanner, t as CATALOG_SCHEMA } from "./version-CnSh33Fj.js";
8
+ //#region src/cli/catalog-doc.ts
9
+ const ROW_GRANTEES = /* @__PURE__ */ new Set([
10
+ "relation",
11
+ "plan",
12
+ "actor",
13
+ "assurance"
14
+ ]);
15
+ /**
16
+ * Whether a grant depends on more than the role and the scope: a row or body
17
+ * condition, a closure, a field list, a purpose, a break-glass override, a
18
+ * validity window, or a relation, plan, actor or assurance grantee. The SQL helpers
19
+ * (`permdock_has`, `permitted_<scope>_ids`) check only role and scope, so a
20
+ * policy that calls them for such a permission would widen access.
21
+ */
22
+ function grantHasRowConditions(grant) {
23
+ const grantees = Array.isArray(grant.to) ? grant.to : [grant.to];
24
+ return grant.where !== void 0 || grant.check !== void 0 || grant.closure !== void 0 || !grant.portable || grant.fields !== void 0 || grant.purpose !== void 0 || grant.breakGlass !== void 0 || grant.validity !== void 0 || grantees.some((grantee) => ROW_GRANTEES.has(grantee.kind));
25
+ }
26
+ /** Per permission key, whether any code grant for it has row conditions. */
27
+ function policyRowConditionKeys(policy) {
28
+ const keys = /* @__PURE__ */ new Set();
29
+ for (const grant of [...policy.grants, ...policy.roles.flatMap((binding) => binding.grants)]) if (grant.hosted === void 0 && grantHasRowConditions(grant)) keys.add(grant.permission.key);
30
+ return keys;
31
+ }
32
+ /** With `policy`, permissions carry `hostable` and a known `rowConditions` (without, it is `true`), and roles carry `on`, `assignable` and their ownership rules. */
33
+ function buildCatalog(tree, scan, generatedAt, policy) {
34
+ const hostable = new Set(policy?.hostable ?? []);
35
+ const rowConditions = policy === void 0 ? void 0 : policyRowConditionKeys(policy);
36
+ const resources = {};
37
+ const definedIn = scan.definitionFiles["permissions"];
38
+ for (const leaf of listPermissions(tree)) {
39
+ if (resources[leaf.resource] !== void 0) continue;
40
+ const node = getResource(tree, leaf.resource);
41
+ resources[leaf.resource] = compactResource(definedIn === void 0 ? {
42
+ id: node?.id ?? "id",
43
+ schema: node === void 0 ? null : jsonSchemaOf(node),
44
+ relations: node?.relations,
45
+ version: node?.version,
46
+ restricted: node?.restricted
47
+ } : {
48
+ id: node?.id ?? "id",
49
+ schema: node === void 0 ? null : jsonSchemaOf(node),
50
+ definedIn,
51
+ relations: node?.relations,
52
+ version: node?.version,
53
+ restricted: node?.restricted
54
+ });
55
+ }
56
+ const approvals = codeApprovals(policy);
57
+ const breakGlass = codeBreakGlass(policy);
58
+ const body = {
59
+ resources,
60
+ permissions: listPermissions(tree).map((leaf) => withDefined({
61
+ key: leaf.key,
62
+ scope: leaf.scope,
63
+ resource: leaf.resource,
64
+ action: leaf.action,
65
+ arity: leaf.kind,
66
+ meta: metaRecord(leaf.meta),
67
+ usages: scan.usages[leaf.key] ?? [],
68
+ renamedFrom: formerKeys(leaf).length === 0 ? void 0 : formerKeys(leaf),
69
+ hostable: hostable.has(leaf.key) ? true : void 0,
70
+ rowConditions: rowConditions?.has(leaf.key) ?? true,
71
+ approvals: approvals.get(leaf.key),
72
+ breakGlass: breakGlass.get(leaf.key)
73
+ })).toSorted((a, b) => byCodePoint(a.key, b.key)),
74
+ ...catalogScopes(policy),
75
+ ...catalogRoles(scan.roleNames, policy),
76
+ ...scan.planNames.length === 0 ? {} : { plans: scan.planNames.map((key) => ({ key })) },
77
+ ...policy === void 0 ? {} : { grants: catalogGrants(policy) },
78
+ ...policy?.delegations === void 0 ? {} : { delegations: catalogDelegations(policy) }
79
+ };
80
+ const head = {
81
+ $schema: CATALOG_SCHEMA,
82
+ version: 1,
83
+ generatedAt,
84
+ generator: generatorBanner()
85
+ };
86
+ return {
87
+ ...head,
88
+ fingerprint: catalogFingerprint({
89
+ ...head,
90
+ ...body
91
+ }),
92
+ ...body
93
+ };
94
+ }
95
+ function catalogApproval(approval) {
96
+ if (approval === void 0) return;
97
+ return approval === "human" ? "human" : withDefined({
98
+ by: approval.by,
99
+ mode: approval.mode,
100
+ stages: approval.stages,
101
+ distinct: approval.distinct,
102
+ staleOn: approval.staleOn,
103
+ quorum: approval.quorum,
104
+ ttl: approval.ttl,
105
+ escalation: approval.escalation
106
+ });
107
+ }
108
+ /**
109
+ * Every code grant in canonical order: by permission, allows before denies,
110
+ * then by role (top-level grants last) and finally by canonical JSON, so two
111
+ * catalogs of the same policy list the same grants in the same order
112
+ * whatever the declaration order was.
113
+ */
114
+ function catalogGrant(grant) {
115
+ const limit = grant.limit === void 0 ? void 0 : withDefined({
116
+ count: grant.limit.count,
117
+ per: grant.limit.per,
118
+ mode: grant.limit.mode
119
+ });
120
+ return {
121
+ permission: grant.permission.key,
122
+ effect: grant.effect,
123
+ role: grant.role,
124
+ to: grant.to,
125
+ scope: grant.scope,
126
+ ...withDefined({
127
+ where: grant.portable ? grant.where : void 0,
128
+ check: grant.portable ? grant.check : void 0,
129
+ approval: catalogApproval(grant.approval),
130
+ fields: grant.fields,
131
+ validity: grant.validity,
132
+ name: grant.name,
133
+ purpose: grant.purpose,
134
+ limit,
135
+ portable: grant.portable ? void 0 : false
136
+ })
137
+ };
138
+ }
139
+ /** The sort key of a catalog grant: permission, allows first, role (top-level last), then the canonical JSON. */
140
+ function catalogGrantKey(grant) {
141
+ return [
142
+ grant.permission,
143
+ grant.effect === "allow" ? "0" : "1",
144
+ grant.role ?? "￿",
145
+ canonicalJson(grant)
146
+ ].join("\0");
147
+ }
148
+ function catalogGrants(policy) {
149
+ const keys = /* @__PURE__ */ new Map();
150
+ const entries = policy.grants.filter((grant) => grant.hosted === void 0).map(catalogGrant);
151
+ for (const entry of entries) keys.set(entry, catalogGrantKey(entry));
152
+ const keyOf = (grant) => keys.get(grant) ?? "";
153
+ return entries.toSorted((a, b) => {
154
+ const left = keyOf(a);
155
+ const right = keyOf(b);
156
+ return left < right ? -1 : left > right ? 1 : 0;
157
+ });
158
+ }
159
+ /** Every policy delegation, sorted by canonical JSON so declaration order does not matter. */
160
+ function catalogDelegations(policy) {
161
+ return (policy.delegations ?? []).map((delegation) => withDefined({
162
+ from: delegation.from,
163
+ to: delegation.to,
164
+ permissions: delegation.permissions,
165
+ validity: delegation.validity
166
+ })).toSorted((a, b) => {
167
+ const left = canonicalJson(a);
168
+ const right = canonicalJson(b);
169
+ return left < right ? -1 : left > right ? 1 : 0;
170
+ });
171
+ }
172
+ /** Per permission key, the distinct approvals the code allows require, in policy order. */
173
+ function codeApprovals(policy) {
174
+ const out = /* @__PURE__ */ new Map();
175
+ const seen = /* @__PURE__ */ new Set();
176
+ for (const grant of policy?.grants ?? []) {
177
+ if (grant.effect !== "allow" || grant.hosted !== void 0 || grant.approval === void 0) continue;
178
+ const approval = catalogApproval(grant.approval);
179
+ if (approval === void 0) continue;
180
+ const id = `${grant.permission.key}\u0000${JSON.stringify(approval)}`;
181
+ if (seen.has(id)) continue;
182
+ seen.add(id);
183
+ out.set(grant.permission.key, [...out.get(grant.permission.key) ?? [], approval]);
184
+ }
185
+ return out;
186
+ }
187
+ /** Per permission key, the break-glass override a `breakGlass` grant declares. */
188
+ function codeBreakGlass(policy) {
189
+ const out = /* @__PURE__ */ new Map();
190
+ for (const grant of policy?.grants ?? []) {
191
+ if (grant.breakGlass === void 0) continue;
192
+ out.set(grant.permission.key, withDefined({
193
+ overrides: grant.breakGlass.overrides,
194
+ purpose: grant.breakGlass.purpose,
195
+ reason: grant.breakGlass.reason,
196
+ maxDuration: grant.breakGlass.maxDuration,
197
+ obligations: grant.breakGlass.obligations
198
+ }));
199
+ }
200
+ return out;
201
+ }
202
+ function catalogScopes(policy) {
203
+ const scopes = policy?.scopes ?? [];
204
+ return scopes.length === 0 ? {} : { scopes: scopes.map((scope) => withDefined({
205
+ name: scope.name,
206
+ key: scope.key ?? "",
207
+ within: scope.within
208
+ })) };
209
+ }
210
+ function catalogRoles(scanned, policy) {
211
+ if (policy === void 0) return scanned.length === 0 ? {} : { roles: scanned.map((key) => ({ key })) };
212
+ const names = [.../* @__PURE__ */ new Set([...scanned, ...policy.roles.map((role) => role.name)])].toSorted();
213
+ if (names.length === 0) return {};
214
+ return { roles: names.map((key) => {
215
+ const binding = policy.rolesByName.get(key);
216
+ if (binding === void 0) return { key };
217
+ const audience = binding.meta?.audience ?? findRole(policy.vocabulary.roles, key)?.meta.audience;
218
+ return withDefined({
219
+ key,
220
+ on: binding.on === void 0 ? void 0 : typeof binding.on === "string" ? binding.on : "resource",
221
+ assignable: binding.assignable,
222
+ min: binding.min === 0 ? void 0 : binding.min,
223
+ max: binding.max,
224
+ transferOnly: binding.transferOnly === true ? true : void 0,
225
+ assigns: binding.assigns,
226
+ for: binding.for,
227
+ exclusiveWith: binding.exclusiveWith,
228
+ audience,
229
+ activation: binding.activation === void 0 ? void 0 : withDefined({
230
+ maxDuration: binding.activation.maxDuration,
231
+ justification: binding.activation.justification,
232
+ approval: binding.activation.approval === void 0 ? void 0 : true,
233
+ assurance: binding.activation.assurance
234
+ }),
235
+ supportAccess: binding.support === void 0 ? void 0 : {
236
+ actorRequired: binding.support.actorRequired,
237
+ group: binding.support.group,
238
+ durations: binding.support.consent.durations
239
+ }
240
+ });
241
+ }) };
242
+ }
243
+ function withDefined(value) {
244
+ return Object.fromEntries(Object.entries(value).filter(([, entry]) => entry !== void 0));
245
+ }
246
+ function compactResource(resource) {
247
+ const relations = resource.relations !== void 0 && Object.keys(resource.relations).length > 0 ? resource.relations : void 0;
248
+ return {
249
+ id: resource.id,
250
+ schema: resource.schema,
251
+ ...withDefined({
252
+ definedIn: resource.definedIn,
253
+ relations,
254
+ version: resource.version,
255
+ restricted: resource.restricted
256
+ })
257
+ };
258
+ }
259
+ function metaRecord(meta) {
260
+ return { ...meta };
261
+ }
262
+ function jsonSchemaOf(node) {
263
+ const output = node.schema?.["~standard"]?.jsonSchema?.output;
264
+ if (typeof output === "function") try {
265
+ return output({ target: "draft-2020-12" });
266
+ } catch {
267
+ return null;
268
+ }
269
+ return null;
270
+ }
271
+ function formatCatalogJson(doc) {
272
+ return `${JSON.stringify(doc, null, 2)}\n`;
273
+ }
274
+ function catalogForCompare(doc) {
275
+ const { generatedAt: _generatedAt, generator: _generator, ...rest } = doc;
276
+ return `${JSON.stringify(rest, null, 2)}\n`;
277
+ }
278
+ function formatCatalogMarkdown(doc) {
279
+ const lines = ["# Permissions", ""];
280
+ const byResource = /* @__PURE__ */ new Map();
281
+ for (const permission of doc.permissions) {
282
+ const current = byResource.get(permission.resource) ?? [];
283
+ byResource.set(permission.resource, [...current, permission]);
284
+ }
285
+ for (const resource of [...byResource.keys()].toSorted()) {
286
+ lines.push(`## ${resource}`, "");
287
+ lines.push("| Action | Arity | Scope | Usages |");
288
+ lines.push("| --- | --- | --- | --- |");
289
+ for (const permission of byResource.get(resource) ?? []) lines.push(`| \`${permission.action}\` | ${permission.arity} | \`${permission.scope}\` | ${String(permission.usages.length)} |`);
290
+ lines.push("");
291
+ }
292
+ return `${lines.join("\n")}\n`;
293
+ }
294
+ function catalogSchemaDocument() {
295
+ return catalogSchema;
296
+ }
297
+ //#endregion
298
+ export { formatCatalogMarkdown as a, formatCatalogJson as i, catalogForCompare as n, jsonSchemaOf as o, catalogSchemaDocument as r, policyRowConditionKeys as s, buildCatalog as t };
@@ -0,0 +1,2 @@
1
+ import { t as runCatalog } from "./catalog-H-vFGwWK.js";
2
+ export { runCatalog };
@@ -0,0 +1,12 @@
1
+ import { resolve } from "node:path";
2
+ //#region src/cli/catalog-path.ts
3
+ /**
4
+ * The absolute path `permdock collect` writes the catalog to: `collect.out`,
5
+ * then `catalog.out`, then `permissions.catalog.json`, resolved against `cwd`.
6
+ * `out` overrides the config, as `collect --out` does.
7
+ */
8
+ function catalogPath(config, cwd, out) {
9
+ return resolve(cwd, out ?? config.collect?.out ?? config.catalog?.out ?? "permissions.catalog.json");
10
+ }
11
+ //#endregion
12
+ export { catalogPath as t };
@@ -0,0 +1,81 @@
1
+ import { $ as DecisionSink, C as Policy, E as PolicyVocabulary, Zt as PermDock, at as LimitStore, ct as MembershipSource, ft as RelationSource, mr as Principal, pt as RoleSource, sn as PolicySource, tt as EntitlementSource, ur as Delegation, xt as SnapshotSource } from "../policy-CInmNGkM.js";
2
+ import { f as ApprovalStore } from "../types-B8w5PFtS.js";
3
+ import { t as ToolMap } from "../types-CxquUByI.js";
4
+ //#region src/claude-agent/create.d.ts
5
+ /** Structural `McpServerProvenance` from `@anthropic-ai/claude-agent-sdk`. */
6
+ type ClaudeMcpServer = {
7
+ readonly name: string;
8
+ readonly source: string;
9
+ };
10
+ /**
11
+ * What `subject`, `actor` and `tenant` receive: the `canUseTool` options or
12
+ * the hook input. The subject comes from the app that started the query,
13
+ * never from these fields.
14
+ */
15
+ type ClaudeAgentContext = {
16
+ readonly toolName: string;
17
+ readonly mcpServer?: ClaudeMcpServer;
18
+ readonly sessionId?: string;
19
+ readonly agentId?: string;
20
+ };
21
+ type ClaudeAgentPermDockOptions<TUser = unknown> = {
22
+ readonly subject: (context: ClaudeAgentContext) => TUser | Promise<TUser>;
23
+ readonly actor?: (context: ClaudeAgentContext) => unknown;
24
+ readonly delegation?: (context: ClaudeAgentContext) => Delegation | undefined | Promise<Delegation | undefined>;
25
+ readonly tenant?: string | ((context: ClaudeAgentContext) => string | undefined | Promise<string | undefined>);
26
+ readonly tools: ToolMap;
27
+ /** MCP server sources whose `mcp__*` tools may be decided; default `['sdk']`. */
28
+ readonly mcpSources?: readonly string[];
29
+ readonly memberships?: MembershipSource | readonly MembershipSource[];
30
+ /** The object graph for relation grants that walk a parent chain; without it they deny. */
31
+ readonly relations?: RelationSource;
32
+ readonly entitlements?: EntitlementSource;
33
+ readonly customRoles?: RoleSource;
34
+ /** Hosted grants, read once per instance; see `PolicySource`. */
35
+ readonly policies?: PolicySource;
36
+ readonly store?: ApprovalStore;
37
+ readonly sink?: DecisionSink;
38
+ readonly limits?: LimitStore;
39
+ readonly snapshots?: SnapshotSource;
40
+ };
41
+ type PermissionResult = {
42
+ readonly behavior: "allow";
43
+ readonly updatedInput: Record<string, unknown>;
44
+ } | {
45
+ readonly behavior: "deny";
46
+ readonly message: string;
47
+ };
48
+ /** Structural `canUseTool` options from `@anthropic-ai/claude-agent-sdk`. */
49
+ type CanUseToolOptions = {
50
+ readonly signal?: AbortSignal;
51
+ readonly mcpServer?: ClaudeMcpServer;
52
+ readonly agentID?: string;
53
+ readonly toolUseID?: string;
54
+ };
55
+ /** Structural `HookInput`; only `PermissionRequest` events are answered. */
56
+ type PermissionRequestHookInput = {
57
+ readonly hook_event_name: string;
58
+ readonly session_id?: string;
59
+ readonly agent_id?: string;
60
+ readonly tool_name?: string;
61
+ readonly tool_input?: unknown;
62
+ readonly mcp_server?: ClaudeMcpServer;
63
+ };
64
+ type PermissionRequestHookOutput = {
65
+ readonly hookSpecificOutput: {
66
+ readonly hookEventName: "PermissionRequest";
67
+ readonly decision: PermissionResult;
68
+ };
69
+ } | Record<string, never>;
70
+ type ClaudeAgentPermDock<V extends PolicyVocabulary = PolicyVocabulary> = {
71
+ /** A `CanUseTool`: pass it as the query's `canUseTool` option. */
72
+ readonly canUseTool: (toolName: string, input: Record<string, unknown>, options?: CanUseToolOptions) => Promise<PermissionResult>;
73
+ /** A `HookCallback` for the `PermissionRequest` event. */
74
+ readonly permissionRequestHook: (input: PermissionRequestHookInput, toolUseID?: string, options?: {
75
+ readonly signal?: AbortSignal;
76
+ }) => Promise<PermissionRequestHookOutput>;
77
+ readonly permdock: (context: ClaudeAgentContext) => Promise<PermDock<V>>;
78
+ };
79
+ export declare function createPermDock<TUser, TPrincipal extends Principal = Principal, V extends PolicyVocabulary = PolicyVocabulary>(policy: Policy<TUser, TPrincipal, V>, options: ClaudeAgentPermDockOptions<TUser>): ClaudeAgentPermDock<V>;
80
+ //#endregion
81
+ export type { CanUseToolOptions, ClaudeAgentContext, ClaudeAgentPermDock, ClaudeAgentPermDockOptions, ClaudeMcpServer, PermissionRequestHookInput, PermissionRequestHookOutput, PermissionResult };
@@ -0,0 +1,83 @@
1
+ import { t as compact } from "../compact-y6vfu2_f.js";
2
+ import { n as createAgentKernel } from "../kernel-YOGCWNLf.js";
3
+ //#region src/claude-agent/create.ts
4
+ const MCP_PREFIX = "mcp__";
5
+ function asInput(input) {
6
+ if (input !== null && typeof input === "object" && !Array.isArray(input)) return input;
7
+ return {};
8
+ }
9
+ function untrustedServer(context, sources) {
10
+ if (!context.toolName.startsWith(MCP_PREFIX)) return;
11
+ const server = context.mcpServer;
12
+ if (server === void 0) return `Denied: ${context.toolName} has no MCP server provenance.`;
13
+ if (!sources.includes(server.source)) return `Denied: ${context.toolName} comes from an untrusted MCP server source.`;
14
+ if (!context.toolName.startsWith(`${MCP_PREFIX}${server.name}__`)) return `Denied: ${context.toolName} is not served by the MCP server that claims it.`;
15
+ }
16
+ function toResult(verdict, input) {
17
+ if (verdict.outcome === "granted") return {
18
+ behavior: "allow",
19
+ updatedInput: asInput(input)
20
+ };
21
+ if (verdict.outcome === "denied") return {
22
+ behavior: "deny",
23
+ message: verdict.reason
24
+ };
25
+ return {
26
+ behavior: "deny",
27
+ message: `${verdict.summary} Approval ${verdict.token} is pending; retry the call once it is approved.`
28
+ };
29
+ }
30
+ function createPermDock(policy, options) {
31
+ const sources = options.mcpSources ?? ["sdk"];
32
+ const kernel = createAgentKernel(policy, {
33
+ ...compact({
34
+ actor: options.actor,
35
+ delegation: options.delegation,
36
+ tenant: options.tenant,
37
+ memberships: options.memberships,
38
+ relations: options.relations,
39
+ entitlements: options.entitlements,
40
+ customRoles: options.customRoles,
41
+ policies: options.policies,
42
+ store: options.store,
43
+ sink: options.sink,
44
+ limits: options.limits,
45
+ snapshots: options.snapshots
46
+ }),
47
+ subject: options.subject,
48
+ tools: options.tools,
49
+ adapter: "claude-agent"
50
+ });
51
+ const decide = async (context, input) => {
52
+ const untrusted = untrustedServer(context, sources);
53
+ if (untrusted !== void 0) return {
54
+ behavior: "deny",
55
+ message: untrusted
56
+ };
57
+ return toResult(await kernel.decideTool(context.toolName, input, context), input);
58
+ };
59
+ const canUseTool = (toolName, input, sdkOptions = {}) => decide(compact({
60
+ toolName,
61
+ mcpServer: sdkOptions.mcpServer,
62
+ agentId: sdkOptions.agentID
63
+ }), input);
64
+ const permissionRequestHook = async (input) => {
65
+ if (input.hook_event_name !== "PermissionRequest" || typeof input.tool_name !== "string") return {};
66
+ return { hookSpecificOutput: {
67
+ hookEventName: "PermissionRequest",
68
+ decision: await decide(compact({
69
+ toolName: input.tool_name,
70
+ mcpServer: input.mcp_server,
71
+ sessionId: input.session_id,
72
+ agentId: input.agent_id
73
+ }), input.tool_input)
74
+ } };
75
+ };
76
+ return {
77
+ canUseTool,
78
+ permissionRequestHook,
79
+ permdock: (context) => kernel.instance(context)
80
+ };
81
+ }
82
+ //#endregion
83
+ export { createPermDock };
@@ -0,0 +1,56 @@
1
+ import { hr as Subject, mr as Principal, pt as RoleSource } from "../policy-CInmNGkM.js";
2
+ import { d as Permission } from "../permissions-B4apnahQ.js";
3
+ import { StandardSchemaV1 } from "@standard-schema/spec";
4
+ //#region src/clerk/types.d.ts
5
+ type ClerkPrincipal = Principal & {
6
+ readonly clerkPermissions?: readonly string[];
7
+ readonly claims?: Readonly<Record<string, unknown>>;
8
+ readonly featureSources?: Readonly<Record<string, "o" | "u">>;
9
+ };
10
+ type ClerkMembershipListItem = {
11
+ readonly organization?: {
12
+ readonly id?: string;
13
+ };
14
+ readonly organizationId?: string;
15
+ readonly role?: string;
16
+ readonly publicUserData?: {
17
+ readonly userId?: string;
18
+ } | null;
19
+ };
20
+ type ClerkBackend = {
21
+ readonly users?: {
22
+ readonly getOrganizationMembershipList?: (args: {
23
+ readonly userId: string;
24
+ readonly limit?: number;
25
+ readonly offset?: number;
26
+ }) => Promise<{
27
+ readonly data?: readonly ClerkMembershipListItem[];
28
+ readonly totalCount?: number;
29
+ } | readonly ClerkMembershipListItem[]>;
30
+ };
31
+ };
32
+ type ClerkGlobalRoles = string | ((claims: Readonly<Record<string, unknown>>) => readonly string[]);
33
+ type ClerkSubjectOptions = {
34
+ readonly memberships?: "active" | "all";
35
+ readonly backend?: ClerkBackend;
36
+ readonly customRoles?: RoleSource;
37
+ readonly permissions?: Readonly<Record<string, Permission>>;
38
+ readonly schema?: StandardSchemaV1;
39
+ readonly globalRoles?: ClerkGlobalRoles;
40
+ readonly features?: Readonly<Record<string, string>>;
41
+ readonly declared?: readonly string[];
42
+ };
43
+ type ClerkAuthObject = {
44
+ readonly userId?: string | null;
45
+ readonly orgId?: string | null;
46
+ readonly orgRole?: string | null;
47
+ readonly orgPermissions?: readonly string[] | null;
48
+ readonly sessionId?: string | null;
49
+ readonly sessionClaims?: Readonly<Record<string, unknown>> | null;
50
+ readonly has?: (...args: never[]) => unknown;
51
+ };
52
+ //#endregion
53
+ //#region src/clerk/subject.d.ts
54
+ export declare function subjectFromClerk(authObject: unknown, options?: ClerkSubjectOptions): Promise<Subject<ClerkPrincipal>>;
55
+ //#endregion
56
+ export type { ClerkAuthObject, ClerkBackend, ClerkGlobalRoles, ClerkMembershipListItem, ClerkPrincipal, ClerkSubjectOptions };