tianshu-harness 3.23.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 (255) hide show
  1. package/LICENSE +189 -0
  2. package/README.en.md +1066 -0
  3. package/README.ja.md +1214 -0
  4. package/README.ko.md +1216 -0
  5. package/README.md +309 -0
  6. package/completions/rivet.bash +118 -0
  7. package/completions/rivet.fish +110 -0
  8. package/completions/rivet.ps1 +230 -0
  9. package/completions/rivet.zsh +187 -0
  10. package/dist/account-OAEKORZE.js +47 -0
  11. package/dist/account-login-V6FOLHJR.js +65 -0
  12. package/dist/account-status-KHNPPAFL.js +23 -0
  13. package/dist/agent/worker-process/child.js +407 -0
  14. package/dist/browser-cli-FLNY5ZHI.js +19 -0
  15. package/dist/browser-readiness-LWVGSBD5.js +12 -0
  16. package/dist/build-backends-5KXKR2S4.js +13 -0
  17. package/dist/build-options-66Y4ZE7C.js +9 -0
  18. package/dist/bundled-skills/brainstorming/SKILL.md +139 -0
  19. package/dist/bundled-skills/visual-acceptance/SKILL.md +64 -0
  20. package/dist/chain-7MAMFXZ3.js +10 -0
  21. package/dist/checkpoint-MND4DUIX.js +33 -0
  22. package/dist/chunk-2E6CK2RC.js +392 -0
  23. package/dist/chunk-2EBWGAXD.js +51 -0
  24. package/dist/chunk-2HDP7RMR.js +119 -0
  25. package/dist/chunk-2HKD2UFM.js +1000 -0
  26. package/dist/chunk-2VYRLULP.js +51 -0
  27. package/dist/chunk-2XN7PM4N.js +125 -0
  28. package/dist/chunk-35H7GVNR.js +66 -0
  29. package/dist/chunk-3C3R7JXY.js +77 -0
  30. package/dist/chunk-3VGD2FXB.js +118 -0
  31. package/dist/chunk-424AP7FM.js +534 -0
  32. package/dist/chunk-4J5TZGOE.js +3707 -0
  33. package/dist/chunk-4QJ3Y5JM.js +898 -0
  34. package/dist/chunk-4U2ET7ZY.js +1326 -0
  35. package/dist/chunk-4XPFLICE.js +876 -0
  36. package/dist/chunk-5B2OCU5P.js +31707 -0
  37. package/dist/chunk-5GGOGLSN.js +73 -0
  38. package/dist/chunk-5JRZPLI6.js +251 -0
  39. package/dist/chunk-5TQ3JYBU.js +397 -0
  40. package/dist/chunk-66JPZSGX.js +55 -0
  41. package/dist/chunk-6HSVXHCZ.js +764 -0
  42. package/dist/chunk-6S5FPUS7.js +21 -0
  43. package/dist/chunk-722LQO64.js +131 -0
  44. package/dist/chunk-73NJ7IT7.js +354 -0
  45. package/dist/chunk-7FW3I7WC.js +95 -0
  46. package/dist/chunk-7KUCBNLB.js +173 -0
  47. package/dist/chunk-7RDOV3DF.js +201 -0
  48. package/dist/chunk-A5MNH4ER.js +79 -0
  49. package/dist/chunk-ADIVZ2D5.js +15 -0
  50. package/dist/chunk-AE3P3F6W.js +366 -0
  51. package/dist/chunk-AERM3VGP.js +280 -0
  52. package/dist/chunk-AEWHC4WM.js +246 -0
  53. package/dist/chunk-AOVQ7VIF.js +169 -0
  54. package/dist/chunk-AOYHP3WI.js +12411 -0
  55. package/dist/chunk-B3YEBABJ.js +7160 -0
  56. package/dist/chunk-BCQXEZPJ.js +154 -0
  57. package/dist/chunk-BKTQAYO2.js +418 -0
  58. package/dist/chunk-BSECIPAQ.js +80 -0
  59. package/dist/chunk-BUIMGNDD.js +52 -0
  60. package/dist/chunk-BXHV3GSB.js +10320 -0
  61. package/dist/chunk-C6ZVZCPP.js +139 -0
  62. package/dist/chunk-CEZNQVWM.js +82 -0
  63. package/dist/chunk-CGFZGR7G.js +1492 -0
  64. package/dist/chunk-CGOADM2X.js +337 -0
  65. package/dist/chunk-CI4R6P2B.js +24 -0
  66. package/dist/chunk-D2TCGRSX.js +73 -0
  67. package/dist/chunk-D4PTYFOG.js +154 -0
  68. package/dist/chunk-D54ZWG4T.js +717 -0
  69. package/dist/chunk-DEBI37QB.js +145 -0
  70. package/dist/chunk-DWROHPXP.js +1051 -0
  71. package/dist/chunk-DZ6UOJ5D.js +92 -0
  72. package/dist/chunk-EBJTVRQN.js +81 -0
  73. package/dist/chunk-EGEI2RQA.js +1167 -0
  74. package/dist/chunk-EHHUASO5.js +1305 -0
  75. package/dist/chunk-EPKTIOED.js +41 -0
  76. package/dist/chunk-ER5JW2QZ.js +5681 -0
  77. package/dist/chunk-ETHFACAB.js +315 -0
  78. package/dist/chunk-EXUE5W2F.js +112 -0
  79. package/dist/chunk-EXXICUIW.js +73 -0
  80. package/dist/chunk-FFQSZJOO.js +169 -0
  81. package/dist/chunk-FHFKPGDO.js +85 -0
  82. package/dist/chunk-FW3QKMFX.js +158 -0
  83. package/dist/chunk-GD4ZNZ7W.js +30 -0
  84. package/dist/chunk-GHVMWF2I.js +581 -0
  85. package/dist/chunk-GMKAXSYQ.js +297 -0
  86. package/dist/chunk-HBVF6BWO.js +325 -0
  87. package/dist/chunk-HV4YGVMS.js +379 -0
  88. package/dist/chunk-ILBCKAV6.js +89 -0
  89. package/dist/chunk-J4U4AW46.js +440 -0
  90. package/dist/chunk-J6ESSM47.js +1791 -0
  91. package/dist/chunk-JBZHIC6T.js +2309 -0
  92. package/dist/chunk-JCFWOULR.js +245 -0
  93. package/dist/chunk-JRF5L6OD.js +131 -0
  94. package/dist/chunk-JSS75KCG.js +2014 -0
  95. package/dist/chunk-JSXWIWWJ.js +225 -0
  96. package/dist/chunk-JYV7I2QH.js +98 -0
  97. package/dist/chunk-KIOXTQQL.js +1596 -0
  98. package/dist/chunk-KWVTXT5B.js +89 -0
  99. package/dist/chunk-KX22RD6R.js +33 -0
  100. package/dist/chunk-LA6IPTGH.js +709 -0
  101. package/dist/chunk-LH5VCGLB.js +1796 -0
  102. package/dist/chunk-LQQ6XJ2Y.js +269 -0
  103. package/dist/chunk-MJQ55WZZ.js +65 -0
  104. package/dist/chunk-ML3UKMH3.js +40 -0
  105. package/dist/chunk-MOZPLHSU.js +5526 -0
  106. package/dist/chunk-NGEWJ4DF.js +89 -0
  107. package/dist/chunk-NH6VIOAR.js +211 -0
  108. package/dist/chunk-O5VZQKCB.js +26106 -0
  109. package/dist/chunk-OHSV42QB.js +748 -0
  110. package/dist/chunk-OO3TAHO5.js +4070 -0
  111. package/dist/chunk-OTNHSAGN.js +38282 -0
  112. package/dist/chunk-OUWAC7AQ.js +442 -0
  113. package/dist/chunk-OXMIV4WE.js +270 -0
  114. package/dist/chunk-P5KJURUR.js +229 -0
  115. package/dist/chunk-P6GJOVO6.js +307 -0
  116. package/dist/chunk-QARAGUXX.js +23 -0
  117. package/dist/chunk-R43HJCDX.js +2711 -0
  118. package/dist/chunk-RAXBAWRN.js +210 -0
  119. package/dist/chunk-RK3JHWPT.js +39 -0
  120. package/dist/chunk-RWA23GMM.js +24 -0
  121. package/dist/chunk-S4K4L6IM.js +179 -0
  122. package/dist/chunk-SAXK6LVF.js +124 -0
  123. package/dist/chunk-SEPGEJNK.js +1607 -0
  124. package/dist/chunk-SUJERP5I.js +285 -0
  125. package/dist/chunk-T3ED6BY2.js +913 -0
  126. package/dist/chunk-THKDVSEC.js +90 -0
  127. package/dist/chunk-TI4GSEL5.js +52 -0
  128. package/dist/chunk-TPI73L57.js +164 -0
  129. package/dist/chunk-TVHW77C7.js +338 -0
  130. package/dist/chunk-TWNHOSDT.js +1073 -0
  131. package/dist/chunk-UFMN76QD.js +347 -0
  132. package/dist/chunk-UHGLFRZE.js +205 -0
  133. package/dist/chunk-UTZYPKBF.js +15231 -0
  134. package/dist/chunk-UXNLELW6.js +25 -0
  135. package/dist/chunk-UXXS53EA.js +166 -0
  136. package/dist/chunk-V5DHFGI7.js +171 -0
  137. package/dist/chunk-V5YIPMHV.js +2353 -0
  138. package/dist/chunk-WMUWEO2C.js +754 -0
  139. package/dist/chunk-WOE3D7JM.js +945 -0
  140. package/dist/chunk-X2IK5LVR.js +2592 -0
  141. package/dist/chunk-XU2YXCDL.js +459 -0
  142. package/dist/chunk-YJG5HIX5.js +203 -0
  143. package/dist/chunk-Z3QE7TZM.js +72 -0
  144. package/dist/chunk-Z5Z3JHJY.js +64 -0
  145. package/dist/chunk-ZDIFBJFT.js +168 -0
  146. package/dist/chunk-ZGGCEXDC.js +176 -0
  147. package/dist/chunk-ZMZCZNKU.js +263 -0
  148. package/dist/chunk-ZNC5T65N.js +17 -0
  149. package/dist/chunk-ZO3I3A7O.js +308 -0
  150. package/dist/chunk-ZQKXBUB7.js +217 -0
  151. package/dist/chunk-ZTRINFM2.js +78 -0
  152. package/dist/chunk-ZU7JZCVP.js +193 -0
  153. package/dist/chunk-ZZAWNALS.js +350 -0
  154. package/dist/cli/entry.js +54 -0
  155. package/dist/connector-L5QQTR6Y.js +26 -0
  156. package/dist/context-62DC6EC3.js +31 -0
  157. package/dist/council-convene-NJWPNBDU.js +46 -0
  158. package/dist/create-agent-config-ODSQWNVC.js +55 -0
  159. package/dist/default-registry-2PU3BTAU.js +68 -0
  160. package/dist/deliver-task-KONV4C4M.js +57 -0
  161. package/dist/delivery-gate-v2-F2YVMVGK.js +27 -0
  162. package/dist/domain-knowledge-store-DDZ3F4J7.js +11 -0
  163. package/dist/fetch-core-ZPPYDSZH.js +14 -0
  164. package/dist/galaxy-K72BBDQN.js +91 -0
  165. package/dist/goal-criteria-SCALAU2D.js +141 -0
  166. package/dist/goal-persist-XWY2GDQX.js +19 -0
  167. package/dist/goal-tracker-FXMJ2GVK.js +11 -0
  168. package/dist/headless-LSB6I7PT.js +162 -0
  169. package/dist/headless-coordinator-VDPDMVUT.js +90 -0
  170. package/dist/inject-U55SMB6A.js +39 -0
  171. package/dist/login-flow-CD4ZGXOC.js +59 -0
  172. package/dist/logs-cli-SQVYFMMN.js +283 -0
  173. package/dist/loop-ULZYBDA3.js +76 -0
  174. package/dist/main.js +4064 -0
  175. package/dist/manager-ROZBCWPA.js +171 -0
  176. package/dist/manager-Z7XFFUOM.js +10670 -0
  177. package/dist/meridian-indexer-ZIW363L7.js +21 -0
  178. package/dist/native-resolver-PN34UIVV.js +13 -0
  179. package/dist/node_modules/better-sqlite3/lib/database.js +90 -0
  180. package/dist/node_modules/better-sqlite3/lib/index.js +3 -0
  181. package/dist/node_modules/better-sqlite3/lib/methods/aggregate.js +43 -0
  182. package/dist/node_modules/better-sqlite3/lib/methods/backup.js +67 -0
  183. package/dist/node_modules/better-sqlite3/lib/methods/function.js +31 -0
  184. package/dist/node_modules/better-sqlite3/lib/methods/inspect.js +7 -0
  185. package/dist/node_modules/better-sqlite3/lib/methods/pragma.js +12 -0
  186. package/dist/node_modules/better-sqlite3/lib/methods/serialize.js +16 -0
  187. package/dist/node_modules/better-sqlite3/lib/methods/table.js +189 -0
  188. package/dist/node_modules/better-sqlite3/lib/methods/transaction.js +78 -0
  189. package/dist/node_modules/better-sqlite3/lib/methods/wrappers.js +54 -0
  190. package/dist/node_modules/better-sqlite3/lib/sqlite-error.js +20 -0
  191. package/dist/node_modules/better-sqlite3/lib/util.js +12 -0
  192. package/dist/node_modules/better-sqlite3/package.json +59 -0
  193. package/dist/ownership-ledger-E3WIEKPL.js +9 -0
  194. package/dist/package.json +3 -0
  195. package/dist/path-grants-XRRXHXG7.js +40 -0
  196. package/dist/paths-LVV5IMQN.js +49 -0
  197. package/dist/plan-fact-anchors-LMVQZCW5.js +13 -0
  198. package/dist/plan-store-ODLTTPFB.js +17 -0
  199. package/dist/plan-templates-5FPFBOL6.js +109 -0
  200. package/dist/plugin-loader-ZZKX7ZE6.js +22 -0
  201. package/dist/prefix-budget-62OV5HQC.js +13 -0
  202. package/dist/project-trust-5WS5MOMU.js +31 -0
  203. package/dist/provider-cli-ALDQXIT7.js +37 -0
  204. package/dist/providers-XQYTAVPK.js +11 -0
  205. package/dist/proxy-resolver-V2Y6534D.js +15 -0
  206. package/dist/recovery-cli-KPGY6FY3.js +106 -0
  207. package/dist/review-discipline-MNSYCST5.js +55 -0
  208. package/dist/review-router-BVQZW3MX.js +18 -0
  209. package/dist/seed-capsules/seed-capsule-attack-methodology.md +62 -0
  210. package/dist/seed-capsules/seed-capsule-changgeng.md +31 -0
  211. package/dist/seed-capsules/seed-capsule-design-aesthetics.md +38 -0
  212. package/dist/seed-capsules/seed-capsule-diagnostic-ladder.md +54 -0
  213. package/dist/seed-capsules/seed-capsule-fu.md +39 -0
  214. package/dist/seed-capsules/seed-capsule-huagai.md +73 -0
  215. package/dist/seed-capsules/seed-capsule-kaiyang.md +65 -0
  216. package/dist/seed-capsules/seed-capsule-knowledge-work.md +40 -0
  217. package/dist/seed-capsules/seed-capsule-tanlang.md +47 -0
  218. package/dist/seed-capsules/seed-capsule-tianfu.md +23 -0
  219. package/dist/seed-capsules/seed-capsule-tianliang.md +63 -0
  220. package/dist/seed-capsules/seed-capsule-tianquan.md +32 -0
  221. package/dist/seed-capsules/seed-capsule-tianxuan-ccr.md +22 -0
  222. package/dist/seed-capsules/seed-capsule-tianxuan.md +64 -0
  223. package/dist/seed-capsules/seed-capsule-yaoguang.md +87 -0
  224. package/dist/serve-X2R2UTLF.js +170 -0
  225. package/dist/serve-agent-KHSU6RVV.js +965 -0
  226. package/dist/session-persist-HUUC772H.js +37 -0
  227. package/dist/session-registry-6XUD5C4Y.js +15 -0
  228. package/dist/skill-loader-CK3RMO47.js +48 -0
  229. package/dist/skills/cli-harness-sop.md +207 -0
  230. package/dist/spawn-git-4HFU65AH.js +29 -0
  231. package/dist/sse-EYUTBWUK.js +512 -0
  232. package/dist/starflow-NOFBMPFU.js +30 -0
  233. package/dist/streamableHttp-V67CNJMO.js +447 -0
  234. package/dist/task-contract-6XHBNJQK.js +32 -0
  235. package/dist/task-ledger-3K4TJIER.js +9 -0
  236. package/dist/team-orchestrate-S6NHZP7X.js +64 -0
  237. package/dist/title-extract-QX4XGCYN.js +50 -0
  238. package/dist/todo-QDXGRZZP.js +31 -0
  239. package/dist/todo-store-V3TTO5AH.js +12 -0
  240. package/dist/tool-preset-LU5BYEDZ.js +23 -0
  241. package/dist/tool-tiers-GD742YBN.js +23 -0
  242. package/dist/turndown.es-OI55K6C3.js +17373 -0
  243. package/dist/verification-attribution-EKG4CNUV.js +13 -0
  244. package/dist/volatile-git-MBTST7RA.js +15 -0
  245. package/dist/wave-checkpoint-XLIIHXQA.js +30 -0
  246. package/dist/web-cli-DUG4I35O.js +233 -0
  247. package/dist/web-search-3IK542AA.js +34 -0
  248. package/dist/workers/cpu-worker.js +45 -0
  249. package/dist/workflow-runner-HX7UBAYG.js +297 -0
  250. package/dist/worktree-baseline-O5NCU6M2.js +9 -0
  251. package/package.json +122 -0
  252. package/scripts/check-mobile-env.mjs +76 -0
  253. package/scripts/fetch-native-sqlite.js +392 -0
  254. package/scripts/prune-installed-wasms.js +45 -0
  255. package/scripts/tree-sitter-wasm-keep.js +40 -0
@@ -0,0 +1,285 @@
1
+ #!/usr/bin/env -S node --expose-gc --max-old-space-size=4096
2
+ import { createRequire as __rivetCreateRequire } from 'node:module'; const require = __rivetCreateRequire(import.meta.url);
3
+ import {
4
+ debugLog
5
+ } from "./chunk-CI4R6P2B.js";
6
+ import {
7
+ rawOutputDir
8
+ } from "./chunk-XU2YXCDL.js";
9
+ import {
10
+ expandHome
11
+ } from "./chunk-ETHFACAB.js";
12
+ import {
13
+ writeFileAtomicSync
14
+ } from "./chunk-A5MNH4ER.js";
15
+ import {
16
+ init_paths,
17
+ rivetHome
18
+ } from "./chunk-BCQXEZPJ.js";
19
+ import {
20
+ init_esm_shims
21
+ } from "./chunk-5GGOGLSN.js";
22
+
23
+ // src/tools/path-grants.ts
24
+ init_esm_shims();
25
+ import { existsSync, mkdirSync, readFileSync, realpathSync } from "fs";
26
+ import { homedir } from "os";
27
+ import { join, resolve, sep } from "path";
28
+ init_paths();
29
+ var RIVET_DIR = rivetHome();
30
+ var _grants = [];
31
+ function scopeVisible(g, cwd) {
32
+ if (!cwd) return true;
33
+ if (g.scope === void 0) return true;
34
+ return g.scope === canonicalize(cwd);
35
+ }
36
+ function canonicalize(p) {
37
+ const abs = resolve(p);
38
+ try {
39
+ return realpathSync(abs);
40
+ } catch {
41
+ let current = abs;
42
+ const tail = [];
43
+ while (!existsSync(current)) {
44
+ const parent = resolve(current, "..");
45
+ if (parent === current) return abs;
46
+ tail.unshift(current.slice(parent.length + 1));
47
+ current = parent;
48
+ }
49
+ try {
50
+ return join(realpathSync(current), ...tail);
51
+ } catch {
52
+ return abs;
53
+ }
54
+ }
55
+ }
56
+ var CASE_INSENSITIVE_FS = process.platform === "win32";
57
+ function foldCase(p) {
58
+ return CASE_INSENSITIVE_FS ? p.toLowerCase() : p;
59
+ }
60
+ function isPathUnder(root, child, caseInsensitive = CASE_INSENSITIVE_FS) {
61
+ const fold = (p) => {
62
+ const norm = sep === "\\" ? p.replace(/\//g, "\\") : p;
63
+ return caseInsensitive ? norm.toLowerCase() : norm;
64
+ };
65
+ const r = fold(root);
66
+ const c = fold(child);
67
+ if (c === r) return true;
68
+ const prefix = r.endsWith(sep) ? r : r + sep;
69
+ return c.startsWith(prefix);
70
+ }
71
+ function isUnder(root, child) {
72
+ return isPathUnder(root, child);
73
+ }
74
+ function grantsFile(cwd) {
75
+ const slug = canonicalize(cwd).replace(/[^a-zA-Z0-9]/g, "_").slice(-64);
76
+ return join(RIVET_DIR, `path-grants-${slug}.json`);
77
+ }
78
+ function grantPath(root, mode, opts) {
79
+ const canonical = canonicalize(root);
80
+ const scope = opts?.cwd ? canonicalize(opts.cwd) : void 0;
81
+ const persist = opts?.persist === true;
82
+ const existing = _grants.find(
83
+ (g) => foldCase(g.root) === foldCase(canonical) && g.scope === scope
84
+ );
85
+ let grant;
86
+ if (existing) {
87
+ if (mode === "write") existing.mode = "write";
88
+ if (persist) existing.persisted = true;
89
+ grant = existing;
90
+ } else {
91
+ grant = { root: canonical, mode, grantedAt: Date.now(), ...persist ? { persisted: true } : {}, ...scope ? { scope } : {} };
92
+ _grants.push(grant);
93
+ }
94
+ if (persist && opts?.cwd) persistGrants(opts.cwd);
95
+ return grant;
96
+ }
97
+ function isReadGranted(absPath, cwd) {
98
+ const target = canonicalize(absPath);
99
+ return _grants.some((g) => scopeVisible(g, cwd) && isUnder(g.root, target));
100
+ }
101
+ function isWriteGranted(absPath, cwd) {
102
+ const target = canonicalize(absPath);
103
+ return _grants.some((g) => g.mode === "write" && scopeVisible(g, cwd) && isUnder(g.root, target));
104
+ }
105
+ function writeGrantedRoots(cwd) {
106
+ return _grants.filter((g) => g.mode === "write" && scopeVisible(g, cwd)).map((g) => g.root);
107
+ }
108
+ function listGrants() {
109
+ return _grants.map((g) => ({ ...g }));
110
+ }
111
+ function readPersistedFile(cwd) {
112
+ const file = grantsFile(cwd);
113
+ if (!existsSync(file)) return [];
114
+ try {
115
+ const parsed = JSON.parse(readFileSync(file, "utf-8"));
116
+ if (!Array.isArray(parsed)) return [];
117
+ return parsed.filter((g) => !!g && typeof g.root === "string");
118
+ } catch {
119
+ return [];
120
+ }
121
+ }
122
+ function listPersistedGrants(cwd) {
123
+ return readPersistedFile(cwd).map((g) => ({
124
+ root: g.root,
125
+ mode: g.mode === "write" ? "write" : "read",
126
+ grantedAt: typeof g.grantedAt === "number" ? g.grantedAt : 0,
127
+ persisted: true
128
+ }));
129
+ }
130
+ function revokeGrant(root, opts) {
131
+ const canonical = canonicalize(root);
132
+ const matches = (candidate) => foldCase(canonicalize(candidate)) === foldCase(canonical);
133
+ const revocable = (g) => matches(g.root) && (g.scope === void 0 || g.scope === canonicalize(opts.cwd));
134
+ const hadInMemory = _grants.some(revocable);
135
+ if (hadInMemory) _grants = _grants.filter((g) => !revocable(g));
136
+ const onDisk = readPersistedFile(opts.cwd);
137
+ const kept = onDisk.filter((g) => !matches(g.root));
138
+ const removedFromDisk = kept.length < onDisk.length;
139
+ if (removedFromDisk) {
140
+ try {
141
+ mkdirSync(RIVET_DIR, { recursive: true });
142
+ writeFileAtomicSync(grantsFile(opts.cwd), JSON.stringify(kept, null, 2));
143
+ } catch {
144
+ }
145
+ }
146
+ return hadInMemory || removedFromDisk;
147
+ }
148
+ function persistGrants(cwd) {
149
+ try {
150
+ mkdirSync(RIVET_DIR, { recursive: true });
151
+ const scope = canonicalize(cwd);
152
+ const toSave = _grants.filter((g) => g.persisted && g.scope === scope);
153
+ writeFileAtomicSync(grantsFile(cwd), JSON.stringify(toSave, null, 2));
154
+ } catch {
155
+ }
156
+ }
157
+ function loadPersistedGrants(cwd) {
158
+ const file = grantsFile(cwd);
159
+ if (!existsSync(file)) return;
160
+ let saved;
161
+ try {
162
+ saved = JSON.parse(readFileSync(file, "utf-8"));
163
+ } catch {
164
+ return;
165
+ }
166
+ if (!Array.isArray(saved)) return;
167
+ for (const g of saved) {
168
+ if (!g || typeof g.root !== "string") continue;
169
+ if (!existsSync(g.root)) continue;
170
+ const mode = g.mode === "write" ? "write" : "read";
171
+ grantPath(g.root, mode, { persist: false, cwd });
172
+ const stored = _grants.find(
173
+ (x) => foldCase(x.root) === foldCase(canonicalize(g.root)) && x.scope === canonicalize(cwd)
174
+ );
175
+ if (stored) stored.persisted = true;
176
+ }
177
+ }
178
+ var ROOT_EXISTS_TTL_MS = 3e4;
179
+ var rootExistsMemo = /* @__PURE__ */ new Map();
180
+ function resetRootExistsMemoForTest() {
181
+ rootExistsMemo.clear();
182
+ }
183
+ function rootExistsCached(root, force = false) {
184
+ const now = Date.now();
185
+ if (!force) {
186
+ const hit = rootExistsMemo.get(root);
187
+ if (hit && now - hit.at < ROOT_EXISTS_TTL_MS) return hit.exists;
188
+ }
189
+ const exists = existsSync(root);
190
+ rootExistsMemo.set(root, { exists, at: now });
191
+ return exists;
192
+ }
193
+ function applyConfiguredPathGrants(permissions, opts) {
194
+ if (!permissions) return;
195
+ const apply = (dirs, mode) => {
196
+ for (const raw of dirs ?? []) {
197
+ const trimmed = raw.trim();
198
+ if (!trimmed) continue;
199
+ const root = resolve(expandHome(trimmed));
200
+ if (!rootExistsCached(root, opts?.force)) continue;
201
+ grantPath(root, mode, { persist: false });
202
+ }
203
+ };
204
+ apply(permissions.additionalReadDirs, "read");
205
+ apply(permissions.additionalWriteDirs, "write");
206
+ }
207
+ var DEFAULT_DEPENDENCY_READ_DIRS = [
208
+ ".npm",
209
+ ".npm-cache",
210
+ ".cache",
211
+ ".cargo",
212
+ ".rustup",
213
+ ".gradle",
214
+ ".m2",
215
+ ".pub-cache",
216
+ ".pnpm-store",
217
+ ".yarn",
218
+ ".bun",
219
+ ".deno",
220
+ ".cocoapods",
221
+ ".gem",
222
+ ".bundle",
223
+ ".composer",
224
+ ".config/composer",
225
+ ".android",
226
+ ".nuget",
227
+ // .NET NuGet packages
228
+ ".nvm",
229
+ // Node Version Manager installations
230
+ ".pyenv",
231
+ // Python version manager installs
232
+ "go"
233
+ // In-project node_modules / vendor / Pods already live under cwd and need no
234
+ // grant; this list only covers $HOME-level global caches.
235
+ ];
236
+ var ENV_OVERRIDES = {
237
+ ".cargo": "CARGO_HOME",
238
+ ".rustup": "RUSTUP_HOME",
239
+ ".gradle": "GRADLE_USER_HOME",
240
+ ".pub-cache": "PUB_CACHE",
241
+ ".gem": "GEM_HOME"
242
+ };
243
+ function applyDefaultDependencyReadGrants() {
244
+ const home = homedir();
245
+ const granted = [];
246
+ const skipped = [];
247
+ for (const rel of DEFAULT_DEPENDENCY_READ_DIRS) {
248
+ const envVar = ENV_OVERRIDES[rel];
249
+ const root = envVar && process.env[envVar] ? resolve(process.env[envVar]) : resolve(join(home, rel));
250
+ if (!existsSync(root)) {
251
+ skipped.push(rel);
252
+ continue;
253
+ }
254
+ grantPath(root, "read", { persist: false });
255
+ granted.push(rel);
256
+ }
257
+ debugLog(`dep read grants: ${granted.length} granted` + (granted.length ? ` (${granted.join(", ")})` : "") + (skipped.length ? `; ${skipped.length} skipped (${skipped.join(", ")})` : ""));
258
+ }
259
+ function applyRivetRuntimeReadGrants() {
260
+ const roots = [rawOutputDir()];
261
+ for (const root of roots) {
262
+ grantPath(root, "read", { persist: false });
263
+ }
264
+ debugLog(`rivet runtime read grants: ${roots.join(", ")}`);
265
+ }
266
+ function _resetGrantsForTest() {
267
+ _grants = [];
268
+ }
269
+
270
+ export {
271
+ isPathUnder,
272
+ grantPath,
273
+ isReadGranted,
274
+ isWriteGranted,
275
+ writeGrantedRoots,
276
+ listGrants,
277
+ listPersistedGrants,
278
+ revokeGrant,
279
+ loadPersistedGrants,
280
+ resetRootExistsMemoForTest,
281
+ applyConfiguredPathGrants,
282
+ applyDefaultDependencyReadGrants,
283
+ applyRivetRuntimeReadGrants,
284
+ _resetGrantsForTest
285
+ };