@dirgha/code 1.2.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 (360) hide show
  1. package/LICENSE +101 -0
  2. package/README.md +674 -0
  3. package/dist/dirgha.mjs +2185 -0
  4. package/dist_v2/acp/index.d.ts +1 -0
  5. package/dist_v2/acp/index.js +2 -0
  6. package/dist_v2/acp/server.d.ts +31 -0
  7. package/dist_v2/acp/server.js +137 -0
  8. package/dist_v2/cli/auth-cmd.d.ts +10 -0
  9. package/dist_v2/cli/auth-cmd.js +69 -0
  10. package/dist_v2/cli/config.d.ts +46 -0
  11. package/dist_v2/cli/config.js +70 -0
  12. package/dist_v2/cli/flags.d.ts +10 -0
  13. package/dist_v2/cli/flags.js +49 -0
  14. package/dist_v2/cli/flows/full-cycle.d.ts +30 -0
  15. package/dist_v2/cli/flows/full-cycle.js +39 -0
  16. package/dist_v2/cli/flows/index.d.ts +2 -0
  17. package/dist_v2/cli/flows/index.js +3 -0
  18. package/dist_v2/cli/flows/tarball.d.ts +10 -0
  19. package/dist_v2/cli/flows/tarball.js +47 -0
  20. package/dist_v2/cli/index.d.ts +4 -0
  21. package/dist_v2/cli/index.js +5 -0
  22. package/dist_v2/cli/interactive.d.ts +21 -0
  23. package/dist_v2/cli/interactive.js +207 -0
  24. package/dist_v2/cli/main.d.ts +10 -0
  25. package/dist_v2/cli/main.js +173 -0
  26. package/dist_v2/cli/models-cmd.d.ts +6 -0
  27. package/dist_v2/cli/models-cmd.js +50 -0
  28. package/dist_v2/cli/setup.d.ts +13 -0
  29. package/dist_v2/cli/setup.js +128 -0
  30. package/dist_v2/cli/slash/account.d.ts +10 -0
  31. package/dist_v2/cli/slash/account.js +59 -0
  32. package/dist_v2/cli/slash/clear.d.ts +8 -0
  33. package/dist_v2/cli/slash/clear.js +15 -0
  34. package/dist_v2/cli/slash/compact.d.ts +7 -0
  35. package/dist_v2/cli/slash/compact.js +13 -0
  36. package/dist_v2/cli/slash/config.d.ts +8 -0
  37. package/dist_v2/cli/slash/config.js +49 -0
  38. package/dist_v2/cli/slash/exit.d.ts +7 -0
  39. package/dist_v2/cli/slash/exit.js +16 -0
  40. package/dist_v2/cli/slash/fleet.d.ts +7 -0
  41. package/dist_v2/cli/slash/fleet.js +22 -0
  42. package/dist_v2/cli/slash/help.d.ts +9 -0
  43. package/dist_v2/cli/slash/help.js +31 -0
  44. package/dist_v2/cli/slash/history.d.ts +7 -0
  45. package/dist_v2/cli/slash/history.js +42 -0
  46. package/dist_v2/cli/slash/index.d.ts +30 -0
  47. package/dist_v2/cli/slash/index.js +52 -0
  48. package/dist_v2/cli/slash/init.d.ts +8 -0
  49. package/dist_v2/cli/slash/init.js +57 -0
  50. package/dist_v2/cli/slash/keys.d.ts +8 -0
  51. package/dist_v2/cli/slash/keys.js +101 -0
  52. package/dist_v2/cli/slash/login.d.ts +10 -0
  53. package/dist_v2/cli/slash/login.js +47 -0
  54. package/dist_v2/cli/slash/memory.d.ts +8 -0
  55. package/dist_v2/cli/slash/memory.js +101 -0
  56. package/dist_v2/cli/slash/mode.d.ts +8 -0
  57. package/dist_v2/cli/slash/mode.js +30 -0
  58. package/dist_v2/cli/slash/models.d.ts +8 -0
  59. package/dist_v2/cli/slash/models.js +73 -0
  60. package/dist_v2/cli/slash/resume.d.ts +8 -0
  61. package/dist_v2/cli/slash/resume.js +24 -0
  62. package/dist_v2/cli/slash/session.d.ts +8 -0
  63. package/dist_v2/cli/slash/session.js +74 -0
  64. package/dist_v2/cli/slash/setup.d.ts +8 -0
  65. package/dist_v2/cli/slash/setup.js +50 -0
  66. package/dist_v2/cli/slash/status.d.ts +7 -0
  67. package/dist_v2/cli/slash/status.js +37 -0
  68. package/dist_v2/cli/slash/theme.d.ts +9 -0
  69. package/dist_v2/cli/slash/theme.js +53 -0
  70. package/dist_v2/cli/slash/types.d.ts +14 -0
  71. package/dist_v2/cli/slash/types.js +9 -0
  72. package/dist_v2/cli/slash/upgrade.d.ts +9 -0
  73. package/dist_v2/cli/slash/upgrade.js +66 -0
  74. package/dist_v2/cli/slash.d.ts +72 -0
  75. package/dist_v2/cli/slash.js +77 -0
  76. package/dist_v2/cli/subcommands/ask.d.ts +17 -0
  77. package/dist_v2/cli/subcommands/ask.js +76 -0
  78. package/dist_v2/cli/subcommands/audit.d.ts +15 -0
  79. package/dist_v2/cli/subcommands/audit.js +128 -0
  80. package/dist_v2/cli/subcommands/chat.d.ts +13 -0
  81. package/dist_v2/cli/subcommands/chat.js +72 -0
  82. package/dist_v2/cli/subcommands/compact.d.ts +14 -0
  83. package/dist_v2/cli/subcommands/compact.js +114 -0
  84. package/dist_v2/cli/subcommands/doctor.d.ts +11 -0
  85. package/dist_v2/cli/subcommands/doctor.js +103 -0
  86. package/dist_v2/cli/subcommands/export-session.d.ts +10 -0
  87. package/dist_v2/cli/subcommands/export-session.js +60 -0
  88. package/dist_v2/cli/subcommands/import-session.d.ts +11 -0
  89. package/dist_v2/cli/subcommands/import-session.js +77 -0
  90. package/dist_v2/cli/subcommands/index.d.ts +40 -0
  91. package/dist_v2/cli/subcommands/index.js +38 -0
  92. package/dist_v2/cli/subcommands/init.d.ts +10 -0
  93. package/dist_v2/cli/subcommands/init.js +74 -0
  94. package/dist_v2/cli/subcommands/keys.d.ts +12 -0
  95. package/dist_v2/cli/subcommands/keys.js +136 -0
  96. package/dist_v2/cli/subcommands/login.d.ts +10 -0
  97. package/dist_v2/cli/subcommands/login.js +60 -0
  98. package/dist_v2/cli/subcommands/logout.d.ts +10 -0
  99. package/dist_v2/cli/subcommands/logout.js +21 -0
  100. package/dist_v2/cli/subcommands/models.d.ts +14 -0
  101. package/dist_v2/cli/subcommands/models.js +144 -0
  102. package/dist_v2/cli/subcommands/setup.d.ts +11 -0
  103. package/dist_v2/cli/subcommands/setup.js +107 -0
  104. package/dist_v2/cli/subcommands/stats.d.ts +13 -0
  105. package/dist_v2/cli/subcommands/stats.js +148 -0
  106. package/dist_v2/cli/subcommands/status.d.ts +14 -0
  107. package/dist_v2/cli/subcommands/status.js +91 -0
  108. package/dist_v2/cli/submit-paper.d.ts +15 -0
  109. package/dist_v2/cli/submit-paper.js +68 -0
  110. package/dist_v2/context/_fts.d.ts +62 -0
  111. package/dist_v2/context/_fts.js +195 -0
  112. package/dist_v2/context/branch.d.ts +18 -0
  113. package/dist_v2/context/branch.js +66 -0
  114. package/dist_v2/context/compaction.d.ts +26 -0
  115. package/dist_v2/context/compaction.js +120 -0
  116. package/dist_v2/context/index.d.ts +5 -0
  117. package/dist_v2/context/index.js +6 -0
  118. package/dist_v2/context/knowledge.d.ts +38 -0
  119. package/dist_v2/context/knowledge.js +146 -0
  120. package/dist_v2/context/memory.d.ts +80 -0
  121. package/dist_v2/context/memory.js +276 -0
  122. package/dist_v2/context/mode.d.ts +25 -0
  123. package/dist_v2/context/mode.js +81 -0
  124. package/dist_v2/context/session.d.ts +56 -0
  125. package/dist_v2/context/session.js +108 -0
  126. package/dist_v2/daemon/index.d.ts +2 -0
  127. package/dist_v2/daemon/index.js +3 -0
  128. package/dist_v2/daemon/protocol.d.ts +73 -0
  129. package/dist_v2/daemon/protocol.js +6 -0
  130. package/dist_v2/daemon/server.d.ts +35 -0
  131. package/dist_v2/daemon/server.js +191 -0
  132. package/dist_v2/eval/index.d.ts +5 -0
  133. package/dist_v2/eval/index.js +6 -0
  134. package/dist_v2/eval/regression.d.ts +14 -0
  135. package/dist_v2/eval/regression.js +106 -0
  136. package/dist_v2/eval/reporter.d.ts +7 -0
  137. package/dist_v2/eval/reporter.js +34 -0
  138. package/dist_v2/eval/swe-bench.d.ts +18 -0
  139. package/dist_v2/eval/swe-bench.js +23 -0
  140. package/dist_v2/eval/terminal-bench.d.ts +13 -0
  141. package/dist_v2/eval/terminal-bench.js +19 -0
  142. package/dist_v2/eval/types.d.ts +36 -0
  143. package/dist_v2/eval/types.js +5 -0
  144. package/dist_v2/fleet/apply-back.d.ts +27 -0
  145. package/dist_v2/fleet/apply-back.js +191 -0
  146. package/dist_v2/fleet/cli-command.d.ts +61 -0
  147. package/dist_v2/fleet/cli-command.js +329 -0
  148. package/dist_v2/fleet/index.d.ts +21 -0
  149. package/dist_v2/fleet/index.js +21 -0
  150. package/dist_v2/fleet/runner.d.ts +28 -0
  151. package/dist_v2/fleet/runner.js +347 -0
  152. package/dist_v2/fleet/tripleshot.d.ts +21 -0
  153. package/dist_v2/fleet/tripleshot.js +222 -0
  154. package/dist_v2/fleet/types.d.ts +193 -0
  155. package/dist_v2/fleet/types.js +24 -0
  156. package/dist_v2/fleet/worktree.d.ts +51 -0
  157. package/dist_v2/fleet/worktree.js +176 -0
  158. package/dist_v2/hooks/index.d.ts +1 -0
  159. package/dist_v2/hooks/index.js +2 -0
  160. package/dist_v2/hooks/registry.d.ts +21 -0
  161. package/dist_v2/hooks/registry.js +40 -0
  162. package/dist_v2/index.d.ts +12 -0
  163. package/dist_v2/index.js +11 -0
  164. package/dist_v2/integrations/arniko-client.d.ts +42 -0
  165. package/dist_v2/integrations/arniko-client.js +86 -0
  166. package/dist_v2/integrations/auth.d.ts +45 -0
  167. package/dist_v2/integrations/auth.js +54 -0
  168. package/dist_v2/integrations/billing.d.ts +71 -0
  169. package/dist_v2/integrations/billing.js +107 -0
  170. package/dist_v2/integrations/bucky-client.d.ts +105 -0
  171. package/dist_v2/integrations/bucky-client.js +76 -0
  172. package/dist_v2/integrations/deploy-client.d.ts +60 -0
  173. package/dist_v2/integrations/deploy-client.js +87 -0
  174. package/dist_v2/integrations/device-auth.d.ts +48 -0
  175. package/dist_v2/integrations/device-auth.js +192 -0
  176. package/dist_v2/integrations/entitlements.d.ts +34 -0
  177. package/dist_v2/integrations/entitlements.js +43 -0
  178. package/dist_v2/integrations/http.d.ts +22 -0
  179. package/dist_v2/integrations/http.js +114 -0
  180. package/dist_v2/integrations/index.d.ts +8 -0
  181. package/dist_v2/integrations/index.js +15 -0
  182. package/dist_v2/intelligence/cost.d.ts +28 -0
  183. package/dist_v2/intelligence/cost.js +58 -0
  184. package/dist_v2/intelligence/error-classifier.d.ts +8 -0
  185. package/dist_v2/intelligence/error-classifier.js +71 -0
  186. package/dist_v2/intelligence/index.d.ts +5 -0
  187. package/dist_v2/intelligence/index.js +6 -0
  188. package/dist_v2/intelligence/prices.d.ts +13 -0
  189. package/dist_v2/intelligence/prices.js +26 -0
  190. package/dist_v2/intelligence/smart-router.d.ts +21 -0
  191. package/dist_v2/intelligence/smart-router.js +59 -0
  192. package/dist_v2/intelligence/telemetry.d.ts +22 -0
  193. package/dist_v2/intelligence/telemetry.js +31 -0
  194. package/dist_v2/kernel/agent-loop.d.ts +32 -0
  195. package/dist_v2/kernel/agent-loop.js +151 -0
  196. package/dist_v2/kernel/event-stream.d.ts +18 -0
  197. package/dist_v2/kernel/event-stream.js +102 -0
  198. package/dist_v2/kernel/index.d.ts +4 -0
  199. package/dist_v2/kernel/index.js +5 -0
  200. package/dist_v2/kernel/message.d.ts +29 -0
  201. package/dist_v2/kernel/message.js +118 -0
  202. package/dist_v2/kernel/types.d.ts +206 -0
  203. package/dist_v2/kernel/types.js +9 -0
  204. package/dist_v2/mcp/client.d.ts +44 -0
  205. package/dist_v2/mcp/client.js +63 -0
  206. package/dist_v2/mcp/index.d.ts +3 -0
  207. package/dist_v2/mcp/index.js +4 -0
  208. package/dist_v2/mcp/tool-bridge.d.ts +11 -0
  209. package/dist_v2/mcp/tool-bridge.js +33 -0
  210. package/dist_v2/mcp/transport.d.ts +29 -0
  211. package/dist_v2/mcp/transport.js +73 -0
  212. package/dist_v2/parity/index.d.ts +3 -0
  213. package/dist_v2/parity/index.js +4 -0
  214. package/dist_v2/parity/mock-openai-compat.d.ts +15 -0
  215. package/dist_v2/parity/mock-openai-compat.js +35 -0
  216. package/dist_v2/parity/runner.d.ts +21 -0
  217. package/dist_v2/parity/runner.js +76 -0
  218. package/dist_v2/parity/scenarios.d.ts +20 -0
  219. package/dist_v2/parity/scenarios.js +70 -0
  220. package/dist_v2/providers/anthropic.d.ts +21 -0
  221. package/dist_v2/providers/anthropic.js +191 -0
  222. package/dist_v2/providers/dispatch.d.ts +11 -0
  223. package/dist_v2/providers/dispatch.js +45 -0
  224. package/dist_v2/providers/fireworks.d.ts +18 -0
  225. package/dist_v2/providers/fireworks.js +44 -0
  226. package/dist_v2/providers/gemini.d.ts +19 -0
  227. package/dist_v2/providers/gemini.js +188 -0
  228. package/dist_v2/providers/http.d.ts +41 -0
  229. package/dist_v2/providers/http.js +188 -0
  230. package/dist_v2/providers/iface.d.ts +18 -0
  231. package/dist_v2/providers/iface.js +18 -0
  232. package/dist_v2/providers/index.d.ts +39 -0
  233. package/dist_v2/providers/index.js +51 -0
  234. package/dist_v2/providers/nvidia.d.ts +27 -0
  235. package/dist_v2/providers/nvidia.js +142 -0
  236. package/dist_v2/providers/ollama.d.ts +15 -0
  237. package/dist_v2/providers/ollama.js +37 -0
  238. package/dist_v2/providers/openai-compat.d.ts +29 -0
  239. package/dist_v2/providers/openai-compat.js +239 -0
  240. package/dist_v2/providers/openai.d.ts +20 -0
  241. package/dist_v2/providers/openai.js +107 -0
  242. package/dist_v2/providers/openrouter.d.ts +24 -0
  243. package/dist_v2/providers/openrouter.js +69 -0
  244. package/dist_v2/safety/approval-bus.d.ts +26 -0
  245. package/dist_v2/safety/approval-bus.js +48 -0
  246. package/dist_v2/safety/audit-log.d.ts +27 -0
  247. package/dist_v2/safety/audit-log.js +71 -0
  248. package/dist_v2/safety/index.d.ts +4 -0
  249. package/dist_v2/safety/index.js +5 -0
  250. package/dist_v2/safety/policy.d.ts +32 -0
  251. package/dist_v2/safety/policy.js +131 -0
  252. package/dist_v2/safety/sandbox/bwrap.d.ts +11 -0
  253. package/dist_v2/safety/sandbox/bwrap.js +52 -0
  254. package/dist_v2/safety/sandbox/iface.d.ts +29 -0
  255. package/dist_v2/safety/sandbox/iface.js +8 -0
  256. package/dist_v2/safety/sandbox/index.d.ts +7 -0
  257. package/dist_v2/safety/sandbox/index.js +8 -0
  258. package/dist_v2/safety/sandbox/landlock.d.ts +17 -0
  259. package/dist_v2/safety/sandbox/landlock.js +26 -0
  260. package/dist_v2/safety/sandbox/noop.d.ts +12 -0
  261. package/dist_v2/safety/sandbox/noop.js +52 -0
  262. package/dist_v2/safety/sandbox/seatbelt.d.ts +11 -0
  263. package/dist_v2/safety/sandbox/seatbelt.js +49 -0
  264. package/dist_v2/safety/sandbox/select.d.ts +6 -0
  265. package/dist_v2/safety/sandbox/select.js +42 -0
  266. package/dist_v2/safety/sandbox/windows.d.ts +13 -0
  267. package/dist_v2/safety/sandbox/windows.js +22 -0
  268. package/dist_v2/skills/index.d.ts +3 -0
  269. package/dist_v2/skills/index.js +4 -0
  270. package/dist_v2/skills/loader.d.ts +38 -0
  271. package/dist_v2/skills/loader.js +102 -0
  272. package/dist_v2/skills/matcher.d.ts +14 -0
  273. package/dist_v2/skills/matcher.js +72 -0
  274. package/dist_v2/skills/runtime.d.ts +13 -0
  275. package/dist_v2/skills/runtime.js +40 -0
  276. package/dist_v2/subagents/delegator.d.ts +36 -0
  277. package/dist_v2/subagents/delegator.js +82 -0
  278. package/dist_v2/subagents/index.d.ts +2 -0
  279. package/dist_v2/subagents/index.js +3 -0
  280. package/dist_v2/subagents/pool.d.ts +18 -0
  281. package/dist_v2/subagents/pool.js +31 -0
  282. package/dist_v2/tools/browser.d.ts +27 -0
  283. package/dist_v2/tools/browser.js +179 -0
  284. package/dist_v2/tools/checkpoint.d.ts +25 -0
  285. package/dist_v2/tools/checkpoint.js +222 -0
  286. package/dist_v2/tools/cron.d.ts +32 -0
  287. package/dist_v2/tools/cron.js +160 -0
  288. package/dist_v2/tools/diff.d.ts +18 -0
  289. package/dist_v2/tools/diff.js +117 -0
  290. package/dist_v2/tools/exec.d.ts +19 -0
  291. package/dist_v2/tools/exec.js +49 -0
  292. package/dist_v2/tools/fs-edit.d.ts +11 -0
  293. package/dist_v2/tools/fs-edit.js +81 -0
  294. package/dist_v2/tools/fs-ls.d.ts +7 -0
  295. package/dist_v2/tools/fs-ls.js +57 -0
  296. package/dist_v2/tools/fs-read.d.ts +7 -0
  297. package/dist_v2/tools/fs-read.js +60 -0
  298. package/dist_v2/tools/fs-write.d.ts +8 -0
  299. package/dist_v2/tools/fs-write.js +46 -0
  300. package/dist_v2/tools/git.d.ts +8 -0
  301. package/dist_v2/tools/git.js +57 -0
  302. package/dist_v2/tools/index.d.ts +25 -0
  303. package/dist_v2/tools/index.js +39 -0
  304. package/dist_v2/tools/multimodal.d.ts +41 -0
  305. package/dist_v2/tools/multimodal.js +381 -0
  306. package/dist_v2/tools/permission.d.ts +27 -0
  307. package/dist_v2/tools/permission.js +43 -0
  308. package/dist_v2/tools/registry.d.ts +44 -0
  309. package/dist_v2/tools/registry.js +62 -0
  310. package/dist_v2/tools/search-glob.d.ts +7 -0
  311. package/dist_v2/tools/search-glob.js +98 -0
  312. package/dist_v2/tools/search-grep.d.ts +7 -0
  313. package/dist_v2/tools/search-grep.js +109 -0
  314. package/dist_v2/tools/shell.d.ts +10 -0
  315. package/dist_v2/tools/shell.js +76 -0
  316. package/dist_v2/tools/task.d.ts +8 -0
  317. package/dist_v2/tools/task.js +37 -0
  318. package/dist_v2/tui/approval.d.ts +7 -0
  319. package/dist_v2/tui/approval.js +55 -0
  320. package/dist_v2/tui/index.d.ts +4 -0
  321. package/dist_v2/tui/index.js +5 -0
  322. package/dist_v2/tui/ink/App.d.ts +39 -0
  323. package/dist_v2/tui/ink/App.js +206 -0
  324. package/dist_v2/tui/ink/components/AtFileComplete.d.ts +25 -0
  325. package/dist_v2/tui/ink/components/AtFileComplete.js +158 -0
  326. package/dist_v2/tui/ink/components/HelpOverlay.d.ts +24 -0
  327. package/dist_v2/tui/ink/components/HelpOverlay.js +130 -0
  328. package/dist_v2/tui/ink/components/InputBox.d.ts +35 -0
  329. package/dist_v2/tui/ink/components/InputBox.js +153 -0
  330. package/dist_v2/tui/ink/components/Logo.d.ts +12 -0
  331. package/dist_v2/tui/ink/components/Logo.js +27 -0
  332. package/dist_v2/tui/ink/components/ModelPicker.d.ts +26 -0
  333. package/dist_v2/tui/ink/components/ModelPicker.js +80 -0
  334. package/dist_v2/tui/ink/components/PasteCollapse.d.ts +36 -0
  335. package/dist_v2/tui/ink/components/PasteCollapse.js +59 -0
  336. package/dist_v2/tui/ink/components/StatusBar.d.ts +18 -0
  337. package/dist_v2/tui/ink/components/StatusBar.js +41 -0
  338. package/dist_v2/tui/ink/components/StreamingText.d.ts +14 -0
  339. package/dist_v2/tui/ink/components/StreamingText.js +11 -0
  340. package/dist_v2/tui/ink/components/ThinkingBlock.d.ts +13 -0
  341. package/dist_v2/tui/ink/components/ThinkingBlock.js +13 -0
  342. package/dist_v2/tui/ink/components/ToolBox.d.ts +20 -0
  343. package/dist_v2/tui/ink/components/ToolBox.js +63 -0
  344. package/dist_v2/tui/ink/components/vim-bindings.d.ts +43 -0
  345. package/dist_v2/tui/ink/components/vim-bindings.js +135 -0
  346. package/dist_v2/tui/ink/index.d.ts +39 -0
  347. package/dist_v2/tui/ink/index.js +47 -0
  348. package/dist_v2/tui/ink/use-event-projection.d.ts +51 -0
  349. package/dist_v2/tui/ink/use-event-projection.js +126 -0
  350. package/dist_v2/tui/ink/use-overlays.d.ts +24 -0
  351. package/dist_v2/tui/ink/use-overlays.js +50 -0
  352. package/dist_v2/tui/renderer.d.ts +19 -0
  353. package/dist_v2/tui/renderer.js +64 -0
  354. package/dist_v2/tui/status-bar.d.ts +12 -0
  355. package/dist_v2/tui/status-bar.js +16 -0
  356. package/dist_v2/tui/theme.d.ts +27 -0
  357. package/dist_v2/tui/theme.js +56 -0
  358. package/dist_v2/utils/json-repair.d.ts +7 -0
  359. package/dist_v2/utils/json-repair.js +45 -0
  360. package/package.json +113 -0
@@ -0,0 +1,131 @@
1
+ /**
2
+ * Policy engine. Evaluates a PermissionCheck against an ordered rule
3
+ * list and returns a decision (allow / deny / require_approval). The
4
+ * default ruleset ships in-code; user and project rules are merged at
5
+ * config load time.
6
+ */
7
+ import { resolve } from 'node:path';
8
+ export const DEFAULT_RULES = [
9
+ {
10
+ id: 'read-inside-cwd',
11
+ applies: { actions: ['read'] },
12
+ when: { outsideCwd: false },
13
+ effect: 'allow',
14
+ reason: 'reads inside the working directory are permitted without prompting',
15
+ },
16
+ {
17
+ id: 'read-outside-cwd',
18
+ applies: { actions: ['read'] },
19
+ when: { outsideCwd: true },
20
+ effect: 'require_approval',
21
+ reason: 'reading outside the working directory requires approval',
22
+ },
23
+ {
24
+ id: 'write-inside-cwd',
25
+ applies: { actions: ['write'] },
26
+ when: { outsideCwd: false },
27
+ effect: 'require_approval',
28
+ reason: 'writes inside the working directory require approval',
29
+ },
30
+ {
31
+ id: 'write-outside-cwd',
32
+ applies: { actions: ['write'] },
33
+ when: { outsideCwd: true },
34
+ effect: 'deny',
35
+ reason: 'writes outside the working directory are forbidden by default',
36
+ },
37
+ {
38
+ id: 'delete',
39
+ applies: { actions: ['delete'] },
40
+ effect: 'require_approval',
41
+ reason: 'deletions require approval',
42
+ },
43
+ {
44
+ id: 'exec-danger-force',
45
+ applies: { actions: ['exec'] },
46
+ when: { commandMatches: '(?:rm -rf|git push --force|git reset --hard|DROP TABLE|kubectl delete)' },
47
+ effect: 'require_approval',
48
+ reason: 'potentially destructive command requires explicit approval',
49
+ },
50
+ {
51
+ id: 'exec-default',
52
+ applies: { actions: ['exec'] },
53
+ effect: 'require_approval',
54
+ reason: 'shell execution requires approval',
55
+ },
56
+ {
57
+ id: 'network-default',
58
+ applies: { actions: ['network'] },
59
+ effect: 'require_approval',
60
+ reason: 'network access requires approval',
61
+ },
62
+ ];
63
+ export function createPolicyEngine(opts) {
64
+ const cwd = resolve(opts.cwd);
65
+ const rules = [...(opts.rules ?? []), ...DEFAULT_RULES];
66
+ const evaluate = (req) => {
67
+ for (const rule of rules) {
68
+ if (!appliesTo(rule, req))
69
+ continue;
70
+ if (!conditionMatches(rule.when, req, cwd))
71
+ continue;
72
+ return decisionFor(rule);
73
+ }
74
+ return {
75
+ allowed: true,
76
+ reason: 'default catch-all allow-with-approval',
77
+ requiresApproval: true,
78
+ };
79
+ };
80
+ return { evaluate };
81
+ }
82
+ function appliesTo(rule, req) {
83
+ if (rule.applies.tools && !rule.applies.tools.includes(req.tool))
84
+ return false;
85
+ if (rule.applies.actions && !rule.applies.actions.includes(req.action))
86
+ return false;
87
+ return true;
88
+ }
89
+ function conditionMatches(cond, req, cwd) {
90
+ if (!cond)
91
+ return true;
92
+ if (cond.outsideCwd !== undefined) {
93
+ const inside = isInside(cwd, req.target);
94
+ if (cond.outsideCwd && inside)
95
+ return false;
96
+ if (!cond.outsideCwd && !inside)
97
+ return false;
98
+ }
99
+ if (cond.commandMatches) {
100
+ try {
101
+ const rx = new RegExp(cond.commandMatches);
102
+ if (!rx.test(req.target))
103
+ return false;
104
+ }
105
+ catch {
106
+ return false;
107
+ }
108
+ }
109
+ if (cond.startsWith && !req.target.startsWith(cond.startsWith))
110
+ return false;
111
+ return true;
112
+ }
113
+ function decisionFor(rule) {
114
+ switch (rule.effect) {
115
+ case 'allow':
116
+ return { allowed: true, reason: `${rule.id}: ${rule.reason}`, requiresApproval: false };
117
+ case 'deny':
118
+ return { allowed: false, reason: `${rule.id}: ${rule.reason}`, requiresApproval: false };
119
+ case 'require_approval':
120
+ return { allowed: true, reason: `${rule.id}: ${rule.reason}`, requiresApproval: true };
121
+ }
122
+ }
123
+ function isInside(root, target) {
124
+ if (!target)
125
+ return false;
126
+ if (!target.startsWith('/'))
127
+ return true;
128
+ const normRoot = root.replace(/\/+$/, '');
129
+ return target === normRoot || target.startsWith(`${normRoot}/`);
130
+ }
131
+ //# sourceMappingURL=policy.js.map
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Linux bubblewrap adapter. Binds the cwd read-write, binds selected
3
+ * paths read-only, unshares network when not allowed. Bubblewrap must
4
+ * be installed; falls back via availability check.
5
+ */
6
+ import type { SandboxAdapter, SandboxExecOptions, SandboxResult } from './iface.js';
7
+ export declare class BwrapSandbox implements SandboxAdapter {
8
+ readonly platform: "linux-bwrap";
9
+ available(): Promise<boolean>;
10
+ exec(opts: SandboxExecOptions): Promise<SandboxResult>;
11
+ }
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Linux bubblewrap adapter. Binds the cwd read-write, binds selected
3
+ * paths read-only, unshares network when not allowed. Bubblewrap must
4
+ * be installed; falls back via availability check.
5
+ */
6
+ import { accessSync, constants } from 'node:fs';
7
+ import { join } from 'node:path';
8
+ import { runDirect } from './noop.js';
9
+ const BWRAP = '/usr/bin/bwrap';
10
+ export class BwrapSandbox {
11
+ platform = 'linux-bwrap';
12
+ async available() {
13
+ try {
14
+ accessSync(BWRAP, constants.X_OK);
15
+ return true;
16
+ }
17
+ catch {
18
+ return false;
19
+ }
20
+ }
21
+ async exec(opts) {
22
+ const args = [
23
+ '--die-with-parent',
24
+ '--new-session',
25
+ '--proc', '/proc',
26
+ '--dev', '/dev',
27
+ '--tmpfs', '/tmp',
28
+ '--ro-bind', '/usr', '/usr',
29
+ '--ro-bind', '/etc', '/etc',
30
+ '--ro-bind', '/lib', '/lib',
31
+ '--ro-bind', '/lib64', '/lib64',
32
+ '--bind', opts.cwd, opts.cwd,
33
+ '--chdir', opts.cwd,
34
+ ];
35
+ for (const path of opts.readOnlyPaths ?? []) {
36
+ args.push('--ro-bind', path, path);
37
+ }
38
+ for (const path of opts.writablePaths ?? []) {
39
+ args.push('--bind', path, path);
40
+ }
41
+ if (!opts.networkAllowed)
42
+ args.push('--unshare-net');
43
+ args.push('--unshare-ipc', '--unshare-pid', '--unshare-uts', '--unshare-cgroup-try');
44
+ const result = await runDirect({
45
+ ...opts,
46
+ command: [BWRAP, ...args, ...opts.command],
47
+ }, 'linux-bwrap');
48
+ return result;
49
+ }
50
+ }
51
+ void join;
52
+ //# sourceMappingURL=bwrap.js.map
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Sandbox adapter contract. The command-execution layer calls exec()
3
+ * and receives stdout/stderr/exit-code. Adapters decide how to contain
4
+ * the child process: macOS Seatbelt, Linux Landlock/bwrap, Windows
5
+ * JobObject, or a noop pass-through when no platform support exists.
6
+ */
7
+ export type SandboxPlatform = 'macos' | 'linux' | 'linux-bwrap' | 'windows' | 'noop';
8
+ export interface SandboxExecOptions {
9
+ command: string[];
10
+ cwd: string;
11
+ env: Record<string, string>;
12
+ readOnlyPaths?: string[];
13
+ writablePaths?: string[];
14
+ networkAllowed: boolean;
15
+ timeoutMs: number;
16
+ signal?: AbortSignal;
17
+ }
18
+ export interface SandboxResult {
19
+ stdout: string;
20
+ stderr: string;
21
+ exitCode: number;
22
+ timedOut: boolean;
23
+ platform: SandboxPlatform;
24
+ }
25
+ export interface SandboxAdapter {
26
+ readonly platform: SandboxPlatform;
27
+ available(): Promise<boolean>;
28
+ exec(opts: SandboxExecOptions): Promise<SandboxResult>;
29
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Sandbox adapter contract. The command-execution layer calls exec()
3
+ * and receives stdout/stderr/exit-code. Adapters decide how to contain
4
+ * the child process: macOS Seatbelt, Linux Landlock/bwrap, Windows
5
+ * JobObject, or a noop pass-through when no platform support exists.
6
+ */
7
+ export {};
8
+ //# sourceMappingURL=iface.js.map
@@ -0,0 +1,7 @@
1
+ export * from './iface.js';
2
+ export * from './noop.js';
3
+ export * from './seatbelt.js';
4
+ export * from './landlock.js';
5
+ export * from './bwrap.js';
6
+ export * from './windows.js';
7
+ export * from './select.js';
@@ -0,0 +1,8 @@
1
+ export * from './iface.js';
2
+ export * from './noop.js';
3
+ export * from './seatbelt.js';
4
+ export * from './landlock.js';
5
+ export * from './bwrap.js';
6
+ export * from './windows.js';
7
+ export * from './select.js';
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Linux Landlock adapter.
3
+ *
4
+ * Landlock is a kernel-level LSM (Linux 5.13+) that lets an unprivileged
5
+ * process restrict its own filesystem view. Native use requires a small
6
+ * C helper to call landlock_create_ruleset / landlock_add_rule /
7
+ * landlock_restrict_self before exec. The v1 implementation here is a
8
+ * safe fallback that delegates to bwrap when that adapter is available;
9
+ * the native Landlock path ships as a prebuilt helper binary in a later
10
+ * sprint.
11
+ */
12
+ import type { SandboxAdapter, SandboxExecOptions, SandboxResult } from './iface.js';
13
+ export declare class LandlockSandbox implements SandboxAdapter {
14
+ readonly platform: "linux";
15
+ available(): Promise<boolean>;
16
+ exec(opts: SandboxExecOptions): Promise<SandboxResult>;
17
+ }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Linux Landlock adapter.
3
+ *
4
+ * Landlock is a kernel-level LSM (Linux 5.13+) that lets an unprivileged
5
+ * process restrict its own filesystem view. Native use requires a small
6
+ * C helper to call landlock_create_ruleset / landlock_add_rule /
7
+ * landlock_restrict_self before exec. The v1 implementation here is a
8
+ * safe fallback that delegates to bwrap when that adapter is available;
9
+ * the native Landlock path ships as a prebuilt helper binary in a later
10
+ * sprint.
11
+ */
12
+ import { BwrapSandbox } from './bwrap.js';
13
+ import { NoopSandbox } from './noop.js';
14
+ export class LandlockSandbox {
15
+ platform = 'linux';
16
+ async available() {
17
+ return false;
18
+ }
19
+ async exec(opts) {
20
+ const bwrap = new BwrapSandbox();
21
+ if (await bwrap.available())
22
+ return bwrap.exec(opts);
23
+ return new NoopSandbox().exec(opts);
24
+ }
25
+ }
26
+ //# sourceMappingURL=landlock.js.map
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Fallback sandbox that runs the command as the current user without
3
+ * isolation. Used when no platform adapter is available; clearly
4
+ * reports platform 'noop' so callers can warn.
5
+ */
6
+ import type { SandboxAdapter, SandboxExecOptions, SandboxResult } from './iface.js';
7
+ export declare class NoopSandbox implements SandboxAdapter {
8
+ readonly platform: "noop";
9
+ available(): Promise<boolean>;
10
+ exec(opts: SandboxExecOptions): Promise<SandboxResult>;
11
+ }
12
+ export declare function runDirect(opts: SandboxExecOptions, platform: 'noop' | 'macos' | 'linux' | 'linux-bwrap' | 'windows'): Promise<SandboxResult>;
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Fallback sandbox that runs the command as the current user without
3
+ * isolation. Used when no platform adapter is available; clearly
4
+ * reports platform 'noop' so callers can warn.
5
+ */
6
+ import { spawn } from 'node:child_process';
7
+ export class NoopSandbox {
8
+ platform = 'noop';
9
+ async available() {
10
+ return true;
11
+ }
12
+ async exec(opts) {
13
+ return runDirect(opts, 'noop');
14
+ }
15
+ }
16
+ export async function runDirect(opts, platform) {
17
+ return new Promise(resolve => {
18
+ const child = spawn(opts.command[0], opts.command.slice(1), {
19
+ cwd: opts.cwd,
20
+ env: opts.env,
21
+ stdio: ['ignore', 'pipe', 'pipe'],
22
+ });
23
+ const stdout = [];
24
+ const stderr = [];
25
+ let timedOut = false;
26
+ const timer = setTimeout(() => {
27
+ timedOut = true;
28
+ child.kill('SIGKILL');
29
+ }, opts.timeoutMs);
30
+ if (opts.signal) {
31
+ const onAbort = () => { child.kill('SIGKILL'); };
32
+ opts.signal.addEventListener('abort', onAbort, { once: true });
33
+ }
34
+ child.stdout.on('data', buf => stdout.push(buf));
35
+ child.stderr.on('data', buf => stderr.push(buf));
36
+ child.on('error', () => {
37
+ clearTimeout(timer);
38
+ resolve({ stdout: Buffer.concat(stdout).toString('utf8'), stderr: Buffer.concat(stderr).toString('utf8'), exitCode: -1, timedOut, platform });
39
+ });
40
+ child.on('exit', code => {
41
+ clearTimeout(timer);
42
+ resolve({
43
+ stdout: Buffer.concat(stdout).toString('utf8'),
44
+ stderr: Buffer.concat(stderr).toString('utf8'),
45
+ exitCode: code ?? -1,
46
+ timedOut,
47
+ platform,
48
+ });
49
+ });
50
+ });
51
+ }
52
+ //# sourceMappingURL=noop.js.map
@@ -0,0 +1,11 @@
1
+ /**
2
+ * macOS Seatbelt adapter. Wraps the command in `sandbox-exec` with a
3
+ * generated profile that allows reads inside the cwd, allows writes to
4
+ * the declared writablePaths, and gates network access per options.
5
+ */
6
+ import type { SandboxAdapter, SandboxExecOptions, SandboxResult } from './iface.js';
7
+ export declare class SeatbeltSandbox implements SandboxAdapter {
8
+ readonly platform: "macos";
9
+ available(): Promise<boolean>;
10
+ exec(opts: SandboxExecOptions): Promise<SandboxResult>;
11
+ }
@@ -0,0 +1,49 @@
1
+ /**
2
+ * macOS Seatbelt adapter. Wraps the command in `sandbox-exec` with a
3
+ * generated profile that allows reads inside the cwd, allows writes to
4
+ * the declared writablePaths, and gates network access per options.
5
+ */
6
+ import { accessSync, constants } from 'node:fs';
7
+ import { runDirect } from './noop.js';
8
+ const SANDBOX_EXEC = '/usr/bin/sandbox-exec';
9
+ export class SeatbeltSandbox {
10
+ platform = 'macos';
11
+ async available() {
12
+ try {
13
+ accessSync(SANDBOX_EXEC, constants.X_OK);
14
+ return true;
15
+ }
16
+ catch {
17
+ return false;
18
+ }
19
+ }
20
+ async exec(opts) {
21
+ const profile = buildProfile(opts);
22
+ return runDirect({
23
+ ...opts,
24
+ command: [SANDBOX_EXEC, '-p', profile, ...opts.command],
25
+ }, 'macos');
26
+ }
27
+ }
28
+ function buildProfile(opts) {
29
+ const read = (opts.readOnlyPaths ?? [opts.cwd]).map(p => `(subpath "${escape(p)}")`).join(' ');
30
+ const write = (opts.writablePaths ?? [opts.cwd]).map(p => `(subpath "${escape(p)}")`).join(' ');
31
+ const net = opts.networkAllowed ? '(allow network*)' : '(deny network*)';
32
+ return `
33
+ (version 1)
34
+ (deny default)
35
+ (allow process-exec)
36
+ (allow process-fork)
37
+ (allow signal)
38
+ (allow file-read* ${read})
39
+ (allow file-read* (literal "/dev/null") (literal "/dev/urandom") (literal "/dev/random") (literal "/dev/tty"))
40
+ (allow file-write* ${write} (literal "/dev/null") (literal "/dev/stdout") (literal "/dev/stderr"))
41
+ (allow sysctl-read)
42
+ (allow mach-lookup)
43
+ ${net}
44
+ `.trim();
45
+ }
46
+ function escape(path) {
47
+ return path.replace(/"/g, '\\"');
48
+ }
49
+ //# sourceMappingURL=seatbelt.js.map
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Sandbox selector. Picks the best available adapter for the current
3
+ * platform. DIRGHA_SANDBOX env overrides the choice.
4
+ */
5
+ import type { SandboxAdapter } from './iface.js';
6
+ export declare function selectSandbox(override?: string): Promise<SandboxAdapter>;
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Sandbox selector. Picks the best available adapter for the current
3
+ * platform. DIRGHA_SANDBOX env overrides the choice.
4
+ */
5
+ import { platform as osPlatform } from 'node:os';
6
+ import { NoopSandbox } from './noop.js';
7
+ import { SeatbeltSandbox } from './seatbelt.js';
8
+ import { BwrapSandbox } from './bwrap.js';
9
+ import { LandlockSandbox } from './landlock.js';
10
+ import { WindowsSandbox } from './windows.js';
11
+ export async function selectSandbox(override) {
12
+ const choice = override ?? process.env.DIRGHA_SANDBOX;
13
+ if (choice === 'noop')
14
+ return new NoopSandbox();
15
+ if (choice === 'seatbelt')
16
+ return new SeatbeltSandbox();
17
+ if (choice === 'landlock')
18
+ return new LandlockSandbox();
19
+ if (choice === 'bwrap')
20
+ return new BwrapSandbox();
21
+ if (choice === 'windows')
22
+ return new WindowsSandbox();
23
+ const current = osPlatform();
24
+ if (current === 'darwin') {
25
+ const seatbelt = new SeatbeltSandbox();
26
+ if (await seatbelt.available())
27
+ return seatbelt;
28
+ }
29
+ if (current === 'linux') {
30
+ const landlock = new LandlockSandbox();
31
+ if (await landlock.available())
32
+ return landlock;
33
+ const bwrap = new BwrapSandbox();
34
+ if (await bwrap.available())
35
+ return bwrap;
36
+ }
37
+ if (current === 'win32') {
38
+ return new WindowsSandbox();
39
+ }
40
+ return new NoopSandbox();
41
+ }
42
+ //# sourceMappingURL=select.js.map
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Windows adapter. Full JobObject + integrity-level restriction needs a
3
+ * native helper; v1 relies on path + environment scoping plus a
4
+ * dedicated child process group and falls back to noop semantics for
5
+ * actual containment. Declared as platform 'windows' so telemetry can
6
+ * surface the status accurately.
7
+ */
8
+ import type { SandboxAdapter, SandboxExecOptions, SandboxResult } from './iface.js';
9
+ export declare class WindowsSandbox implements SandboxAdapter {
10
+ readonly platform: "windows";
11
+ available(): Promise<boolean>;
12
+ exec(opts: SandboxExecOptions): Promise<SandboxResult>;
13
+ }
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Windows adapter. Full JobObject + integrity-level restriction needs a
3
+ * native helper; v1 relies on path + environment scoping plus a
4
+ * dedicated child process group and falls back to noop semantics for
5
+ * actual containment. Declared as platform 'windows' so telemetry can
6
+ * surface the status accurately.
7
+ */
8
+ import { runDirect } from './noop.js';
9
+ export class WindowsSandbox {
10
+ platform = 'windows';
11
+ async available() {
12
+ return process.platform === 'win32';
13
+ }
14
+ async exec(opts) {
15
+ const env = { ...opts.env };
16
+ if (!opts.networkAllowed) {
17
+ env['DIRGHA_NETWORK_DISABLED'] = '1';
18
+ }
19
+ return runDirect({ ...opts, env }, 'windows');
20
+ }
21
+ }
22
+ //# sourceMappingURL=windows.js.map
@@ -0,0 +1,3 @@
1
+ export * from './loader.js';
2
+ export * from './matcher.js';
3
+ export * from './runtime.js';
@@ -0,0 +1,4 @@
1
+ export * from './loader.js';
2
+ export * from './matcher.js';
3
+ export * from './runtime.js';
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Skill discovery and loading.
3
+ *
4
+ * Skills are markdown files with YAML frontmatter. They are loaded from
5
+ * three source roots in precedence order:
6
+ * 1. <cwd>/.dirgha/skills/**<slash>SKILL.md (project-local)
7
+ * 2. ~/.dirgha/skills/**<slash>SKILL.md (user-global)
8
+ * 3. node_modules/dirgha-skill-* (npm-distributed)
9
+ *
10
+ * Frontmatter is a simple key: value dialect (no nested structures).
11
+ * The body below the closing `---` is the skill content injected into
12
+ * the agent as a user message when the skill matches.
13
+ */
14
+ export type SkillPlatform = 'cli' | 'daemon' | 'gateway' | 'acp';
15
+ export interface SkillMeta {
16
+ name: string;
17
+ description: string;
18
+ version?: string;
19
+ platforms?: SkillPlatform[];
20
+ triggers?: {
21
+ keywords?: string[];
22
+ filePatterns?: string[];
23
+ };
24
+ related?: string[];
25
+ }
26
+ export interface Skill {
27
+ meta: SkillMeta;
28
+ body: string;
29
+ path: string;
30
+ source: 'project' | 'user' | 'package';
31
+ }
32
+ export interface LoadSkillsOptions {
33
+ cwd?: string;
34
+ userHome?: string;
35
+ packageRoots?: string[];
36
+ }
37
+ export declare function loadSkills(opts?: LoadSkillsOptions): Promise<Skill[]>;
38
+ export declare function parseSkill(text: string, path: string, source: Skill['source']): Skill | undefined;
@@ -0,0 +1,102 @@
1
+ /**
2
+ * Skill discovery and loading.
3
+ *
4
+ * Skills are markdown files with YAML frontmatter. They are loaded from
5
+ * three source roots in precedence order:
6
+ * 1. <cwd>/.dirgha/skills/**<slash>SKILL.md (project-local)
7
+ * 2. ~/.dirgha/skills/**<slash>SKILL.md (user-global)
8
+ * 3. node_modules/dirgha-skill-* (npm-distributed)
9
+ *
10
+ * Frontmatter is a simple key: value dialect (no nested structures).
11
+ * The body below the closing `---` is the skill content injected into
12
+ * the agent as a user message when the skill matches.
13
+ */
14
+ import { readFile, readdir, stat } from 'node:fs/promises';
15
+ import { join } from 'node:path';
16
+ import { homedir } from 'node:os';
17
+ export async function loadSkills(opts = {}) {
18
+ const cwd = opts.cwd ?? process.cwd();
19
+ const home = opts.userHome ?? homedir();
20
+ const packageRoots = opts.packageRoots ?? [];
21
+ const projectSkills = await discover(join(cwd, '.dirgha', 'skills'), 'project');
22
+ const userSkills = await discover(join(home, '.dirgha', 'skills'), 'user');
23
+ const packageSkills = (await Promise.all(packageRoots.map(root => discover(root, 'package')))).flat();
24
+ const byName = new Map();
25
+ for (const skill of [...packageSkills, ...userSkills, ...projectSkills]) {
26
+ byName.set(skill.meta.name, skill);
27
+ }
28
+ return [...byName.values()];
29
+ }
30
+ async function discover(root, source) {
31
+ const exists = await stat(root).then(s => s.isDirectory()).catch(() => false);
32
+ if (!exists)
33
+ return [];
34
+ const out = [];
35
+ await walk(root, async (abs) => {
36
+ if (!abs.endsWith('/SKILL.md') && !abs.endsWith('SKILL.md'))
37
+ return;
38
+ const text = await readFile(abs, 'utf8').catch(() => undefined);
39
+ if (!text)
40
+ return;
41
+ const parsed = parseSkill(text, abs, source);
42
+ if (parsed)
43
+ out.push(parsed);
44
+ });
45
+ return out;
46
+ }
47
+ async function walk(dir, onFile) {
48
+ const entries = await readdir(dir).catch(() => []);
49
+ for (const name of entries) {
50
+ const abs = join(dir, name);
51
+ const info = await stat(abs).catch(() => undefined);
52
+ if (!info)
53
+ continue;
54
+ if (info.isDirectory())
55
+ await walk(abs, onFile);
56
+ else if (info.isFile())
57
+ await onFile(abs);
58
+ }
59
+ }
60
+ export function parseSkill(text, path, source) {
61
+ const match = text.match(/^---\n([\s\S]*?)\n---\n?([\s\S]*)$/);
62
+ if (!match)
63
+ return undefined;
64
+ const meta = parseFrontmatter(match[1]);
65
+ if (!meta.name || !meta.description)
66
+ return undefined;
67
+ return {
68
+ meta: meta,
69
+ body: match[2].trim(),
70
+ path,
71
+ source,
72
+ };
73
+ }
74
+ function parseFrontmatter(raw) {
75
+ const out = {};
76
+ for (const line of raw.split('\n')) {
77
+ if (!line.trim() || line.startsWith('#'))
78
+ continue;
79
+ const idx = line.indexOf(':');
80
+ if (idx < 0)
81
+ continue;
82
+ const key = line.slice(0, idx).trim();
83
+ const value = line.slice(idx + 1).trim();
84
+ out[key] = parseValue(value);
85
+ }
86
+ return out;
87
+ }
88
+ function parseValue(v) {
89
+ if (v.startsWith('[') && v.endsWith(']')) {
90
+ return v.slice(1, -1).split(',').map(s => s.trim().replace(/^["']|["']$/g, '')).filter(Boolean);
91
+ }
92
+ if (v.startsWith('"') && v.endsWith('"')) {
93
+ try {
94
+ return JSON.parse(v);
95
+ }
96
+ catch {
97
+ return v.slice(1, -1);
98
+ }
99
+ }
100
+ return v;
101
+ }
102
+ //# sourceMappingURL=loader.js.map