dfcode 1.0.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 (343) hide show
  1. package/LICENSE +21 -0
  2. package/package.json +107 -0
  3. package/packages/dfcode/README.md +15 -0
  4. package/packages/dfcode/bin/dfcode +84 -0
  5. package/packages/dfcode/package.json +115 -0
  6. package/packages/dfcode/src/acp/README.md +164 -0
  7. package/packages/dfcode/src/acp/agent.ts +1437 -0
  8. package/packages/dfcode/src/acp/session.ts +105 -0
  9. package/packages/dfcode/src/acp/types.ts +22 -0
  10. package/packages/dfcode/src/agent/agent.ts +332 -0
  11. package/packages/dfcode/src/agent/generate.txt +75 -0
  12. package/packages/dfcode/src/agent/prompt/compaction.txt +12 -0
  13. package/packages/dfcode/src/agent/prompt/explore.txt +18 -0
  14. package/packages/dfcode/src/agent/prompt/summary.txt +11 -0
  15. package/packages/dfcode/src/agent/prompt/title.txt +44 -0
  16. package/packages/dfcode/src/auth/index.ts +73 -0
  17. package/packages/dfcode/src/bun/index.ts +134 -0
  18. package/packages/dfcode/src/bus/bus-event.ts +43 -0
  19. package/packages/dfcode/src/bus/global.ts +10 -0
  20. package/packages/dfcode/src/bus/index.ts +105 -0
  21. package/packages/dfcode/src/cli/bootstrap.ts +17 -0
  22. package/packages/dfcode/src/cli/cmd/acp.ts +69 -0
  23. package/packages/dfcode/src/cli/cmd/agent.ts +257 -0
  24. package/packages/dfcode/src/cli/cmd/auth.ts +400 -0
  25. package/packages/dfcode/src/cli/cmd/cmd.ts +7 -0
  26. package/packages/dfcode/src/cli/cmd/debug/agent.ts +166 -0
  27. package/packages/dfcode/src/cli/cmd/debug/config.ts +16 -0
  28. package/packages/dfcode/src/cli/cmd/debug/file.ts +97 -0
  29. package/packages/dfcode/src/cli/cmd/debug/index.ts +48 -0
  30. package/packages/dfcode/src/cli/cmd/debug/lsp.ts +52 -0
  31. package/packages/dfcode/src/cli/cmd/debug/ripgrep.ts +87 -0
  32. package/packages/dfcode/src/cli/cmd/debug/scrap.ts +16 -0
  33. package/packages/dfcode/src/cli/cmd/debug/skill.ts +16 -0
  34. package/packages/dfcode/src/cli/cmd/debug/snapshot.ts +52 -0
  35. package/packages/dfcode/src/cli/cmd/export.ts +88 -0
  36. package/packages/dfcode/src/cli/cmd/generate.ts +38 -0
  37. package/packages/dfcode/src/cli/cmd/github.ts +1548 -0
  38. package/packages/dfcode/src/cli/cmd/import.ts +98 -0
  39. package/packages/dfcode/src/cli/cmd/mcp.ts +755 -0
  40. package/packages/dfcode/src/cli/cmd/models.ts +77 -0
  41. package/packages/dfcode/src/cli/cmd/pr.ts +112 -0
  42. package/packages/dfcode/src/cli/cmd/run.ts +395 -0
  43. package/packages/dfcode/src/cli/cmd/serve.ts +20 -0
  44. package/packages/dfcode/src/cli/cmd/session.ts +135 -0
  45. package/packages/dfcode/src/cli/cmd/stats.ts +402 -0
  46. package/packages/dfcode/src/cli/cmd/tui/app.tsx +750 -0
  47. package/packages/dfcode/src/cli/cmd/tui/attach.ts +39 -0
  48. package/packages/dfcode/src/cli/cmd/tui/component/border.tsx +21 -0
  49. package/packages/dfcode/src/cli/cmd/tui/component/dialog-agent.tsx +31 -0
  50. package/packages/dfcode/src/cli/cmd/tui/component/dialog-command.tsx +148 -0
  51. package/packages/dfcode/src/cli/cmd/tui/component/dialog-mcp.tsx +86 -0
  52. package/packages/dfcode/src/cli/cmd/tui/component/dialog-model.tsx +234 -0
  53. package/packages/dfcode/src/cli/cmd/tui/component/dialog-provider.tsx +256 -0
  54. package/packages/dfcode/src/cli/cmd/tui/component/dialog-session-list.tsx +114 -0
  55. package/packages/dfcode/src/cli/cmd/tui/component/dialog-session-rename.tsx +31 -0
  56. package/packages/dfcode/src/cli/cmd/tui/component/dialog-stash.tsx +87 -0
  57. package/packages/dfcode/src/cli/cmd/tui/component/dialog-status.tsx +164 -0
  58. package/packages/dfcode/src/cli/cmd/tui/component/dialog-tag.tsx +44 -0
  59. package/packages/dfcode/src/cli/cmd/tui/component/dialog-theme-list.tsx +50 -0
  60. package/packages/dfcode/src/cli/cmd/tui/component/logo.tsx +88 -0
  61. package/packages/dfcode/src/cli/cmd/tui/component/prompt/autocomplete.tsx +653 -0
  62. package/packages/dfcode/src/cli/cmd/tui/component/prompt/frecency.tsx +89 -0
  63. package/packages/dfcode/src/cli/cmd/tui/component/prompt/history.tsx +108 -0
  64. package/packages/dfcode/src/cli/cmd/tui/component/prompt/index.tsx +1102 -0
  65. package/packages/dfcode/src/cli/cmd/tui/component/prompt/stash.tsx +101 -0
  66. package/packages/dfcode/src/cli/cmd/tui/component/textarea-keybindings.ts +73 -0
  67. package/packages/dfcode/src/cli/cmd/tui/component/tips.tsx +153 -0
  68. package/packages/dfcode/src/cli/cmd/tui/component/todo-item.tsx +32 -0
  69. package/packages/dfcode/src/cli/cmd/tui/context/args.tsx +14 -0
  70. package/packages/dfcode/src/cli/cmd/tui/context/directory.ts +13 -0
  71. package/packages/dfcode/src/cli/cmd/tui/context/exit.tsx +23 -0
  72. package/packages/dfcode/src/cli/cmd/tui/context/helper.tsx +25 -0
  73. package/packages/dfcode/src/cli/cmd/tui/context/keybind.tsx +101 -0
  74. package/packages/dfcode/src/cli/cmd/tui/context/kv.tsx +52 -0
  75. package/packages/dfcode/src/cli/cmd/tui/context/local.tsx +402 -0
  76. package/packages/dfcode/src/cli/cmd/tui/context/prompt.tsx +18 -0
  77. package/packages/dfcode/src/cli/cmd/tui/context/route.tsx +46 -0
  78. package/packages/dfcode/src/cli/cmd/tui/context/sdk.tsx +94 -0
  79. package/packages/dfcode/src/cli/cmd/tui/context/sync.tsx +445 -0
  80. package/packages/dfcode/src/cli/cmd/tui/context/theme/aura.json +69 -0
  81. package/packages/dfcode/src/cli/cmd/tui/context/theme/ayu.json +80 -0
  82. package/packages/dfcode/src/cli/cmd/tui/context/theme/carbonfox.json +248 -0
  83. package/packages/dfcode/src/cli/cmd/tui/context/theme/catppuccin-frappe.json +233 -0
  84. package/packages/dfcode/src/cli/cmd/tui/context/theme/catppuccin-macchiato.json +233 -0
  85. package/packages/dfcode/src/cli/cmd/tui/context/theme/catppuccin.json +112 -0
  86. package/packages/dfcode/src/cli/cmd/tui/context/theme/cobalt2.json +228 -0
  87. package/packages/dfcode/src/cli/cmd/tui/context/theme/cursor.json +249 -0
  88. package/packages/dfcode/src/cli/cmd/tui/context/theme/dfcode.json +245 -0
  89. package/packages/dfcode/src/cli/cmd/tui/context/theme/dracula.json +219 -0
  90. package/packages/dfcode/src/cli/cmd/tui/context/theme/everforest.json +241 -0
  91. package/packages/dfcode/src/cli/cmd/tui/context/theme/flexoki.json +237 -0
  92. package/packages/dfcode/src/cli/cmd/tui/context/theme/github.json +233 -0
  93. package/packages/dfcode/src/cli/cmd/tui/context/theme/gruvbox.json +242 -0
  94. package/packages/dfcode/src/cli/cmd/tui/context/theme/kanagawa.json +77 -0
  95. package/packages/dfcode/src/cli/cmd/tui/context/theme/lucent-orng.json +237 -0
  96. package/packages/dfcode/src/cli/cmd/tui/context/theme/material.json +235 -0
  97. package/packages/dfcode/src/cli/cmd/tui/context/theme/matrix.json +77 -0
  98. package/packages/dfcode/src/cli/cmd/tui/context/theme/mercury.json +252 -0
  99. package/packages/dfcode/src/cli/cmd/tui/context/theme/monokai.json +221 -0
  100. package/packages/dfcode/src/cli/cmd/tui/context/theme/nightowl.json +221 -0
  101. package/packages/dfcode/src/cli/cmd/tui/context/theme/nord.json +223 -0
  102. package/packages/dfcode/src/cli/cmd/tui/context/theme/one-dark.json +84 -0
  103. package/packages/dfcode/src/cli/cmd/tui/context/theme/orng.json +249 -0
  104. package/packages/dfcode/src/cli/cmd/tui/context/theme/osaka-jade.json +93 -0
  105. package/packages/dfcode/src/cli/cmd/tui/context/theme/palenight.json +222 -0
  106. package/packages/dfcode/src/cli/cmd/tui/context/theme/rosepine.json +234 -0
  107. package/packages/dfcode/src/cli/cmd/tui/context/theme/solarized.json +223 -0
  108. package/packages/dfcode/src/cli/cmd/tui/context/theme/synthwave84.json +226 -0
  109. package/packages/dfcode/src/cli/cmd/tui/context/theme/tokyonight.json +243 -0
  110. package/packages/dfcode/src/cli/cmd/tui/context/theme/vercel.json +245 -0
  111. package/packages/dfcode/src/cli/cmd/tui/context/theme/vesper.json +218 -0
  112. package/packages/dfcode/src/cli/cmd/tui/context/theme/zenburn.json +223 -0
  113. package/packages/dfcode/src/cli/cmd/tui/context/theme.tsx +1152 -0
  114. package/packages/dfcode/src/cli/cmd/tui/event.ts +48 -0
  115. package/packages/dfcode/src/cli/cmd/tui/routes/home.tsx +140 -0
  116. package/packages/dfcode/src/cli/cmd/tui/routes/session/dialog-fork-from-timeline.tsx +64 -0
  117. package/packages/dfcode/src/cli/cmd/tui/routes/session/dialog-message.tsx +109 -0
  118. package/packages/dfcode/src/cli/cmd/tui/routes/session/dialog-subagent.tsx +26 -0
  119. package/packages/dfcode/src/cli/cmd/tui/routes/session/dialog-timeline.tsx +47 -0
  120. package/packages/dfcode/src/cli/cmd/tui/routes/session/footer.tsx +91 -0
  121. package/packages/dfcode/src/cli/cmd/tui/routes/session/header.tsx +142 -0
  122. package/packages/dfcode/src/cli/cmd/tui/routes/session/index.tsx +2050 -0
  123. package/packages/dfcode/src/cli/cmd/tui/routes/session/permission.tsx +508 -0
  124. package/packages/dfcode/src/cli/cmd/tui/routes/session/question.tsx +453 -0
  125. package/packages/dfcode/src/cli/cmd/tui/routes/session/sidebar.tsx +313 -0
  126. package/packages/dfcode/src/cli/cmd/tui/thread.ts +165 -0
  127. package/packages/dfcode/src/cli/cmd/tui/ui/dialog-alert.tsx +57 -0
  128. package/packages/dfcode/src/cli/cmd/tui/ui/dialog-confirm.tsx +83 -0
  129. package/packages/dfcode/src/cli/cmd/tui/ui/dialog-export-options.tsx +204 -0
  130. package/packages/dfcode/src/cli/cmd/tui/ui/dialog-help.tsx +43 -0
  131. package/packages/dfcode/src/cli/cmd/tui/ui/dialog-prompt.tsx +77 -0
  132. package/packages/dfcode/src/cli/cmd/tui/ui/dialog-select.tsx +384 -0
  133. package/packages/dfcode/src/cli/cmd/tui/ui/dialog.tsx +167 -0
  134. package/packages/dfcode/src/cli/cmd/tui/ui/link.tsx +28 -0
  135. package/packages/dfcode/src/cli/cmd/tui/ui/spinner.ts +368 -0
  136. package/packages/dfcode/src/cli/cmd/tui/ui/toast.tsx +100 -0
  137. package/packages/dfcode/src/cli/cmd/tui/util/clipboard.ts +160 -0
  138. package/packages/dfcode/src/cli/cmd/tui/util/editor.ts +32 -0
  139. package/packages/dfcode/src/cli/cmd/tui/util/signal.ts +7 -0
  140. package/packages/dfcode/src/cli/cmd/tui/util/terminal.ts +114 -0
  141. package/packages/dfcode/src/cli/cmd/tui/util/transcript.ts +98 -0
  142. package/packages/dfcode/src/cli/cmd/tui/worker.ts +152 -0
  143. package/packages/dfcode/src/cli/cmd/uninstall.ts +357 -0
  144. package/packages/dfcode/src/cli/cmd/upgrade.ts +73 -0
  145. package/packages/dfcode/src/cli/cmd/web.ts +81 -0
  146. package/packages/dfcode/src/cli/error.ts +57 -0
  147. package/packages/dfcode/src/cli/network.ts +53 -0
  148. package/packages/dfcode/src/cli/ui.ts +83 -0
  149. package/packages/dfcode/src/cli/upgrade.ts +25 -0
  150. package/packages/dfcode/src/command/index.ts +131 -0
  151. package/packages/dfcode/src/command/template/initialize.txt +10 -0
  152. package/packages/dfcode/src/command/template/review.txt +99 -0
  153. package/packages/dfcode/src/config/config.ts +1367 -0
  154. package/packages/dfcode/src/config/markdown.ts +93 -0
  155. package/packages/dfcode/src/env/index.ts +26 -0
  156. package/packages/dfcode/src/file/ignore.ts +83 -0
  157. package/packages/dfcode/src/file/index.ts +411 -0
  158. package/packages/dfcode/src/file/ripgrep.ts +407 -0
  159. package/packages/dfcode/src/file/time.ts +69 -0
  160. package/packages/dfcode/src/file/watcher.ts +127 -0
  161. package/packages/dfcode/src/flag/flag.ts +79 -0
  162. package/packages/dfcode/src/format/formatter.ts +357 -0
  163. package/packages/dfcode/src/format/index.ts +137 -0
  164. package/packages/dfcode/src/global/index.ts +55 -0
  165. package/packages/dfcode/src/id/id.ts +83 -0
  166. package/packages/dfcode/src/ide/index.ts +76 -0
  167. package/packages/dfcode/src/index.ts +159 -0
  168. package/packages/dfcode/src/installation/index.ts +246 -0
  169. package/packages/dfcode/src/lsp/client.ts +252 -0
  170. package/packages/dfcode/src/lsp/index.ts +485 -0
  171. package/packages/dfcode/src/lsp/language.ts +119 -0
  172. package/packages/dfcode/src/lsp/server.ts +2046 -0
  173. package/packages/dfcode/src/mcp/auth.ts +135 -0
  174. package/packages/dfcode/src/mcp/index.ts +934 -0
  175. package/packages/dfcode/src/mcp/oauth-callback.ts +200 -0
  176. package/packages/dfcode/src/mcp/oauth-provider.ts +154 -0
  177. package/packages/dfcode/src/patch/index.ts +680 -0
  178. package/packages/dfcode/src/permission/arity.ts +163 -0
  179. package/packages/dfcode/src/permission/index.ts +210 -0
  180. package/packages/dfcode/src/permission/next.ts +280 -0
  181. package/packages/dfcode/src/plugin/codex.ts +506 -0
  182. package/packages/dfcode/src/plugin/copilot.ts +283 -0
  183. package/packages/dfcode/src/plugin/index.ts +135 -0
  184. package/packages/dfcode/src/project/bootstrap.ts +35 -0
  185. package/packages/dfcode/src/project/instance.ts +91 -0
  186. package/packages/dfcode/src/project/project.ts +371 -0
  187. package/packages/dfcode/src/project/state.ts +66 -0
  188. package/packages/dfcode/src/project/vcs.ts +76 -0
  189. package/packages/dfcode/src/provider/auth.ts +147 -0
  190. package/packages/dfcode/src/provider/models.ts +136 -0
  191. package/packages/dfcode/src/provider/provider.ts +1219 -0
  192. package/packages/dfcode/src/provider/sdk/openai-compatible/src/README.md +5 -0
  193. package/packages/dfcode/src/provider/sdk/openai-compatible/src/index.ts +2 -0
  194. package/packages/dfcode/src/provider/sdk/openai-compatible/src/openai-compatible-provider.ts +100 -0
  195. package/packages/dfcode/src/provider/sdk/openai-compatible/src/responses/convert-to-openai-responses-input.ts +303 -0
  196. package/packages/dfcode/src/provider/sdk/openai-compatible/src/responses/map-openai-responses-finish-reason.ts +22 -0
  197. package/packages/dfcode/src/provider/sdk/openai-compatible/src/responses/openai-config.ts +18 -0
  198. package/packages/dfcode/src/provider/sdk/openai-compatible/src/responses/openai-error.ts +22 -0
  199. package/packages/dfcode/src/provider/sdk/openai-compatible/src/responses/openai-responses-api-types.ts +207 -0
  200. package/packages/dfcode/src/provider/sdk/openai-compatible/src/responses/openai-responses-language-model.ts +1732 -0
  201. package/packages/dfcode/src/provider/sdk/openai-compatible/src/responses/openai-responses-prepare-tools.ts +177 -0
  202. package/packages/dfcode/src/provider/sdk/openai-compatible/src/responses/openai-responses-settings.ts +1 -0
  203. package/packages/dfcode/src/provider/sdk/openai-compatible/src/responses/tool/code-interpreter.ts +88 -0
  204. package/packages/dfcode/src/provider/sdk/openai-compatible/src/responses/tool/file-search.ts +128 -0
  205. package/packages/dfcode/src/provider/sdk/openai-compatible/src/responses/tool/image-generation.ts +115 -0
  206. package/packages/dfcode/src/provider/sdk/openai-compatible/src/responses/tool/local-shell.ts +65 -0
  207. package/packages/dfcode/src/provider/sdk/openai-compatible/src/responses/tool/web-search-preview.ts +104 -0
  208. package/packages/dfcode/src/provider/sdk/openai-compatible/src/responses/tool/web-search.ts +103 -0
  209. package/packages/dfcode/src/provider/transform.ts +741 -0
  210. package/packages/dfcode/src/pty/index.ts +241 -0
  211. package/packages/dfcode/src/question/index.ts +171 -0
  212. package/packages/dfcode/src/scheduler/index.ts +61 -0
  213. package/packages/dfcode/src/server/error.ts +36 -0
  214. package/packages/dfcode/src/server/event.ts +7 -0
  215. package/packages/dfcode/src/server/mdns.ts +59 -0
  216. package/packages/dfcode/src/server/routes/config.ts +92 -0
  217. package/packages/dfcode/src/server/routes/experimental.ts +208 -0
  218. package/packages/dfcode/src/server/routes/file.ts +197 -0
  219. package/packages/dfcode/src/server/routes/global.ts +135 -0
  220. package/packages/dfcode/src/server/routes/mcp.ts +225 -0
  221. package/packages/dfcode/src/server/routes/permission.ts +68 -0
  222. package/packages/dfcode/src/server/routes/project.ts +82 -0
  223. package/packages/dfcode/src/server/routes/provider.ts +165 -0
  224. package/packages/dfcode/src/server/routes/pty.ts +169 -0
  225. package/packages/dfcode/src/server/routes/question.ts +98 -0
  226. package/packages/dfcode/src/server/routes/session.ts +939 -0
  227. package/packages/dfcode/src/server/routes/tui.ts +379 -0
  228. package/packages/dfcode/src/server/server.ts +574 -0
  229. package/packages/dfcode/src/session/compaction.ts +225 -0
  230. package/packages/dfcode/src/session/index.ts +498 -0
  231. package/packages/dfcode/src/session/llm.ts +288 -0
  232. package/packages/dfcode/src/session/message-v2.ts +740 -0
  233. package/packages/dfcode/src/session/message.ts +189 -0
  234. package/packages/dfcode/src/session/processor.ts +406 -0
  235. package/packages/dfcode/src/session/prompt/anthropic-20250930.txt +164 -0
  236. package/packages/dfcode/src/session/prompt/anthropic.txt +102 -0
  237. package/packages/dfcode/src/session/prompt/anthropic_spoof.txt +1 -0
  238. package/packages/dfcode/src/session/prompt/beast.txt +147 -0
  239. package/packages/dfcode/src/session/prompt/build-switch.txt +5 -0
  240. package/packages/dfcode/src/session/prompt/codex_header.txt +79 -0
  241. package/packages/dfcode/src/session/prompt/copilot-gpt-5.txt +143 -0
  242. package/packages/dfcode/src/session/prompt/gemini.txt +155 -0
  243. package/packages/dfcode/src/session/prompt/max-steps.txt +16 -0
  244. package/packages/dfcode/src/session/prompt/plan-reminder-anthropic.txt +67 -0
  245. package/packages/dfcode/src/session/prompt/plan.txt +26 -0
  246. package/packages/dfcode/src/session/prompt/qwen.txt +107 -0
  247. package/packages/dfcode/src/session/prompt.ts +1815 -0
  248. package/packages/dfcode/src/session/retry.ts +90 -0
  249. package/packages/dfcode/src/session/revert.ts +121 -0
  250. package/packages/dfcode/src/session/status.ts +76 -0
  251. package/packages/dfcode/src/session/summary.ts +150 -0
  252. package/packages/dfcode/src/session/system.ts +157 -0
  253. package/packages/dfcode/src/session/todo.ts +37 -0
  254. package/packages/dfcode/src/share/share-next.ts +200 -0
  255. package/packages/dfcode/src/share/share.ts +92 -0
  256. package/packages/dfcode/src/shell/shell.ts +67 -0
  257. package/packages/dfcode/src/skill/index.ts +1 -0
  258. package/packages/dfcode/src/skill/skill.ts +135 -0
  259. package/packages/dfcode/src/snapshot/index.ts +236 -0
  260. package/packages/dfcode/src/storage/storage.ts +227 -0
  261. package/packages/dfcode/src/tool/apply_patch.ts +280 -0
  262. package/packages/dfcode/src/tool/apply_patch.txt +33 -0
  263. package/packages/dfcode/src/tool/bash.ts +258 -0
  264. package/packages/dfcode/src/tool/bash.txt +115 -0
  265. package/packages/dfcode/src/tool/batch.ts +175 -0
  266. package/packages/dfcode/src/tool/batch.txt +24 -0
  267. package/packages/dfcode/src/tool/codesearch.ts +132 -0
  268. package/packages/dfcode/src/tool/codesearch.txt +12 -0
  269. package/packages/dfcode/src/tool/edit.ts +645 -0
  270. package/packages/dfcode/src/tool/edit.txt +10 -0
  271. package/packages/dfcode/src/tool/external-directory.ts +32 -0
  272. package/packages/dfcode/src/tool/glob.ts +77 -0
  273. package/packages/dfcode/src/tool/glob.txt +6 -0
  274. package/packages/dfcode/src/tool/grep.ts +154 -0
  275. package/packages/dfcode/src/tool/grep.txt +8 -0
  276. package/packages/dfcode/src/tool/invalid.ts +17 -0
  277. package/packages/dfcode/src/tool/ls.ts +121 -0
  278. package/packages/dfcode/src/tool/ls.txt +1 -0
  279. package/packages/dfcode/src/tool/lsp.ts +96 -0
  280. package/packages/dfcode/src/tool/lsp.txt +19 -0
  281. package/packages/dfcode/src/tool/multiedit.ts +46 -0
  282. package/packages/dfcode/src/tool/multiedit.txt +41 -0
  283. package/packages/dfcode/src/tool/plan-enter.txt +14 -0
  284. package/packages/dfcode/src/tool/plan-exit.txt +13 -0
  285. package/packages/dfcode/src/tool/plan.ts +130 -0
  286. package/packages/dfcode/src/tool/question.ts +33 -0
  287. package/packages/dfcode/src/tool/question.txt +10 -0
  288. package/packages/dfcode/src/tool/read.ts +202 -0
  289. package/packages/dfcode/src/tool/read.txt +12 -0
  290. package/packages/dfcode/src/tool/registry.ts +158 -0
  291. package/packages/dfcode/src/tool/skill.ts +82 -0
  292. package/packages/dfcode/src/tool/task.ts +191 -0
  293. package/packages/dfcode/src/tool/task.txt +60 -0
  294. package/packages/dfcode/src/tool/todo.ts +53 -0
  295. package/packages/dfcode/src/tool/todoread.txt +14 -0
  296. package/packages/dfcode/src/tool/todowrite.txt +167 -0
  297. package/packages/dfcode/src/tool/tool.ts +88 -0
  298. package/packages/dfcode/src/tool/truncation.ts +106 -0
  299. package/packages/dfcode/src/tool/webfetch.ts +188 -0
  300. package/packages/dfcode/src/tool/webfetch.txt +13 -0
  301. package/packages/dfcode/src/tool/websearch.ts +150 -0
  302. package/packages/dfcode/src/tool/websearch.txt +14 -0
  303. package/packages/dfcode/src/tool/write.ts +80 -0
  304. package/packages/dfcode/src/tool/write.txt +8 -0
  305. package/packages/dfcode/src/util/archive.ts +16 -0
  306. package/packages/dfcode/src/util/color.ts +19 -0
  307. package/packages/dfcode/src/util/context.ts +25 -0
  308. package/packages/dfcode/src/util/defer.ts +12 -0
  309. package/packages/dfcode/src/util/eventloop.ts +20 -0
  310. package/packages/dfcode/src/util/filesystem.ts +93 -0
  311. package/packages/dfcode/src/util/fn.ts +11 -0
  312. package/packages/dfcode/src/util/format.ts +20 -0
  313. package/packages/dfcode/src/util/iife.ts +3 -0
  314. package/packages/dfcode/src/util/keybind.ts +103 -0
  315. package/packages/dfcode/src/util/lazy.ts +18 -0
  316. package/packages/dfcode/src/util/locale.ts +81 -0
  317. package/packages/dfcode/src/util/lock.ts +98 -0
  318. package/packages/dfcode/src/util/log.ts +180 -0
  319. package/packages/dfcode/src/util/queue.ts +32 -0
  320. package/packages/dfcode/src/util/rpc.ts +66 -0
  321. package/packages/dfcode/src/util/scrap.ts +10 -0
  322. package/packages/dfcode/src/util/signal.ts +12 -0
  323. package/packages/dfcode/src/util/timeout.ts +14 -0
  324. package/packages/dfcode/src/util/token.ts +7 -0
  325. package/packages/dfcode/src/util/wildcard.ts +56 -0
  326. package/packages/dfcode/src/worktree/index.ts +524 -0
  327. package/packages/plugin/package.json +28 -0
  328. package/packages/plugin/src/example.ts +18 -0
  329. package/packages/plugin/src/index.ts +226 -0
  330. package/packages/plugin/src/shell.ts +136 -0
  331. package/packages/plugin/src/tool.ts +28 -0
  332. package/packages/util/package.json +20 -0
  333. package/packages/util/src/array.ts +10 -0
  334. package/packages/util/src/binary.ts +41 -0
  335. package/packages/util/src/encode.ts +30 -0
  336. package/packages/util/src/error.ts +54 -0
  337. package/packages/util/src/fn.ts +11 -0
  338. package/packages/util/src/identifier.ts +48 -0
  339. package/packages/util/src/iife.ts +3 -0
  340. package/packages/util/src/lazy.ts +11 -0
  341. package/packages/util/src/path.ts +37 -0
  342. package/packages/util/src/retry.ts +41 -0
  343. package/packages/util/src/slug.ts +74 -0
@@ -0,0 +1,226 @@
1
+ import type {
2
+ Event,
3
+ createDfcodeClient,
4
+ Project,
5
+ Model,
6
+ Provider,
7
+ Permission,
8
+ UserMessage,
9
+ Message,
10
+ Part,
11
+ Auth,
12
+ Config,
13
+ } from "@dfcode/sdk"
14
+
15
+ import type { BunShell } from "./shell"
16
+ import { type ToolDefinition } from "./tool"
17
+
18
+ export * from "./tool"
19
+
20
+ export type ProviderContext = {
21
+ source: "env" | "config" | "custom" | "api"
22
+ info: Provider
23
+ options: Record<string, any>
24
+ }
25
+
26
+ export type PluginInput = {
27
+ client: ReturnType<typeof createDfcodeClient>
28
+ project: Project
29
+ directory: string
30
+ worktree: string
31
+ serverUrl: URL
32
+ $: BunShell
33
+ }
34
+
35
+ export type Plugin = (input: PluginInput) => Promise<Hooks>
36
+
37
+ export type AuthHook = {
38
+ provider: string
39
+ loader?: (auth: () => Promise<Auth>, provider: Provider) => Promise<Record<string, any>>
40
+ methods: (
41
+ | {
42
+ type: "oauth"
43
+ label: string
44
+ prompts?: Array<
45
+ | {
46
+ type: "text"
47
+ key: string
48
+ message: string
49
+ placeholder?: string
50
+ validate?: (value: string) => string | undefined
51
+ condition?: (inputs: Record<string, string>) => boolean
52
+ }
53
+ | {
54
+ type: "select"
55
+ key: string
56
+ message: string
57
+ options: Array<{
58
+ label: string
59
+ value: string
60
+ hint?: string
61
+ }>
62
+ condition?: (inputs: Record<string, string>) => boolean
63
+ }
64
+ >
65
+ authorize(inputs?: Record<string, string>): Promise<AuthOuathResult>
66
+ }
67
+ | {
68
+ type: "api"
69
+ label: string
70
+ prompts?: Array<
71
+ | {
72
+ type: "text"
73
+ key: string
74
+ message: string
75
+ placeholder?: string
76
+ validate?: (value: string) => string | undefined
77
+ condition?: (inputs: Record<string, string>) => boolean
78
+ }
79
+ | {
80
+ type: "select"
81
+ key: string
82
+ message: string
83
+ options: Array<{
84
+ label: string
85
+ value: string
86
+ hint?: string
87
+ }>
88
+ condition?: (inputs: Record<string, string>) => boolean
89
+ }
90
+ >
91
+ authorize?(inputs?: Record<string, string>): Promise<
92
+ | {
93
+ type: "success"
94
+ key: string
95
+ provider?: string
96
+ }
97
+ | {
98
+ type: "failed"
99
+ }
100
+ >
101
+ }
102
+ )[]
103
+ }
104
+
105
+ export type AuthOuathResult = { url: string; instructions: string } & (
106
+ | {
107
+ method: "auto"
108
+ callback(): Promise<
109
+ | ({
110
+ type: "success"
111
+ provider?: string
112
+ } & (
113
+ | {
114
+ refresh: string
115
+ access: string
116
+ expires: number
117
+ accountId?: string
118
+ }
119
+ | { key: string }
120
+ ))
121
+ | {
122
+ type: "failed"
123
+ }
124
+ >
125
+ }
126
+ | {
127
+ method: "code"
128
+ callback(code: string): Promise<
129
+ | ({
130
+ type: "success"
131
+ provider?: string
132
+ } & (
133
+ | {
134
+ refresh: string
135
+ access: string
136
+ expires: number
137
+ accountId?: string
138
+ }
139
+ | { key: string }
140
+ ))
141
+ | {
142
+ type: "failed"
143
+ }
144
+ >
145
+ }
146
+ )
147
+
148
+ export interface Hooks {
149
+ event?: (input: { event: Event }) => Promise<void>
150
+ config?: (input: Config) => Promise<void>
151
+ tool?: {
152
+ [key: string]: ToolDefinition
153
+ }
154
+ auth?: AuthHook
155
+ /**
156
+ * Called when a new message is received
157
+ */
158
+ "chat.message"?: (
159
+ input: {
160
+ sessionID: string
161
+ agent?: string
162
+ model?: { providerID: string; modelID: string }
163
+ messageID?: string
164
+ variant?: string
165
+ },
166
+ output: { message: UserMessage; parts: Part[] },
167
+ ) => Promise<void>
168
+ /**
169
+ * Modify parameters sent to LLM
170
+ */
171
+ "chat.params"?: (
172
+ input: { sessionID: string; agent: string; model: Model; provider: ProviderContext; message: UserMessage },
173
+ output: { temperature: number; topP: number; topK: number; options: Record<string, any> },
174
+ ) => Promise<void>
175
+ "chat.headers"?: (
176
+ input: { sessionID: string; agent: string; model: Model; provider: ProviderContext; message: UserMessage },
177
+ output: { headers: Record<string, string> },
178
+ ) => Promise<void>
179
+ "permission.ask"?: (input: Permission, output: { status: "ask" | "deny" | "allow" }) => Promise<void>
180
+ "command.execute.before"?: (
181
+ input: { command: string; sessionID: string; arguments: string },
182
+ output: { parts: Part[] },
183
+ ) => Promise<void>
184
+ "tool.execute.before"?: (
185
+ input: { tool: string; sessionID: string; callID: string },
186
+ output: { args: any },
187
+ ) => Promise<void>
188
+ "tool.execute.after"?: (
189
+ input: { tool: string; sessionID: string; callID: string },
190
+ output: {
191
+ title: string
192
+ output: string
193
+ metadata: any
194
+ },
195
+ ) => Promise<void>
196
+ "experimental.chat.messages.transform"?: (
197
+ input: {},
198
+ output: {
199
+ messages: {
200
+ info: Message
201
+ parts: Part[]
202
+ }[]
203
+ },
204
+ ) => Promise<void>
205
+ "experimental.chat.system.transform"?: (
206
+ input: { sessionID: string },
207
+ output: {
208
+ system: string[]
209
+ },
210
+ ) => Promise<void>
211
+ /**
212
+ * Called before session compaction starts. Allows plugins to customize
213
+ * the compaction prompt.
214
+ *
215
+ * - `context`: Additional context strings appended to the default prompt
216
+ * - `prompt`: If set, replaces the default compaction prompt entirely
217
+ */
218
+ "experimental.session.compacting"?: (
219
+ input: { sessionID: string },
220
+ output: { context: string[]; prompt?: string },
221
+ ) => Promise<void>
222
+ "experimental.text.complete"?: (
223
+ input: { sessionID: string; messageID: string; partID: string },
224
+ output: { text: string },
225
+ ) => Promise<void>
226
+ }
@@ -0,0 +1,136 @@
1
+ export type ShellFunction = (input: Uint8Array) => Uint8Array
2
+
3
+ export type ShellExpression =
4
+ | { toString(): string }
5
+ | Array<ShellExpression>
6
+ | string
7
+ | { raw: string }
8
+ | ReadableStream
9
+
10
+ export interface BunShell {
11
+ (strings: TemplateStringsArray, ...expressions: ShellExpression[]): BunShellPromise
12
+
13
+ /**
14
+ * Perform bash-like brace expansion on the given pattern.
15
+ * @param pattern - Brace pattern to expand
16
+ */
17
+ braces(pattern: string): string[]
18
+
19
+ /**
20
+ * Escape strings for input into shell commands.
21
+ */
22
+ escape(input: string): string
23
+
24
+ /**
25
+ * Change the default environment variables for shells created by this instance.
26
+ */
27
+ env(newEnv?: Record<string, string | undefined>): BunShell
28
+
29
+ /**
30
+ * Default working directory to use for shells created by this instance.
31
+ */
32
+ cwd(newCwd?: string): BunShell
33
+
34
+ /**
35
+ * Configure the shell to not throw an exception on non-zero exit codes.
36
+ */
37
+ nothrow(): BunShell
38
+
39
+ /**
40
+ * Configure whether or not the shell should throw an exception on non-zero exit codes.
41
+ */
42
+ throws(shouldThrow: boolean): BunShell
43
+ }
44
+
45
+ export interface BunShellPromise extends Promise<BunShellOutput> {
46
+ readonly stdin: WritableStream
47
+
48
+ /**
49
+ * Change the current working directory of the shell.
50
+ */
51
+ cwd(newCwd: string): this
52
+
53
+ /**
54
+ * Set environment variables for the shell.
55
+ */
56
+ env(newEnv: Record<string, string> | undefined): this
57
+
58
+ /**
59
+ * By default, the shell will write to the current process's stdout and stderr, as well as buffering that output.
60
+ * This configures the shell to only buffer the output.
61
+ */
62
+ quiet(): this
63
+
64
+ /**
65
+ * Read from stdout as a string, line by line
66
+ * Automatically calls quiet() to disable echoing to stdout.
67
+ */
68
+ lines(): AsyncIterable<string>
69
+
70
+ /**
71
+ * Read from stdout as a string.
72
+ * Automatically calls quiet() to disable echoing to stdout.
73
+ */
74
+ text(encoding?: BufferEncoding): Promise<string>
75
+
76
+ /**
77
+ * Read from stdout as a JSON object
78
+ * Automatically calls quiet()
79
+ */
80
+ json(): Promise<any>
81
+
82
+ /**
83
+ * Read from stdout as an ArrayBuffer
84
+ * Automatically calls quiet()
85
+ */
86
+ arrayBuffer(): Promise<ArrayBuffer>
87
+
88
+ /**
89
+ * Read from stdout as a Blob
90
+ * Automatically calls quiet()
91
+ */
92
+ blob(): Promise<Blob>
93
+
94
+ /**
95
+ * Configure the shell to not throw an exception on non-zero exit codes.
96
+ */
97
+ nothrow(): this
98
+
99
+ /**
100
+ * Configure whether or not the shell should throw an exception on non-zero exit codes.
101
+ */
102
+ throws(shouldThrow: boolean): this
103
+ }
104
+
105
+ export interface BunShellOutput {
106
+ readonly stdout: Buffer
107
+ readonly stderr: Buffer
108
+ readonly exitCode: number
109
+
110
+ /**
111
+ * Read from stdout as a string
112
+ */
113
+ text(encoding?: BufferEncoding): string
114
+
115
+ /**
116
+ * Read from stdout as a JSON object
117
+ */
118
+ json(): any
119
+
120
+ /**
121
+ * Read from stdout as an ArrayBuffer
122
+ */
123
+ arrayBuffer(): ArrayBuffer
124
+
125
+ /**
126
+ * Read from stdout as an Uint8Array
127
+ */
128
+ bytes(): Uint8Array
129
+
130
+ /**
131
+ * Read from stdout as a Blob
132
+ */
133
+ blob(): Blob
134
+ }
135
+
136
+ export type BunShellError = Error & BunShellOutput
@@ -0,0 +1,28 @@
1
+ import { z } from "zod"
2
+
3
+ export type ToolContext = {
4
+ sessionID: string
5
+ messageID: string
6
+ agent: string
7
+ abort: AbortSignal
8
+ metadata(input: { title?: string; metadata?: { [key: string]: any } }): void
9
+ ask(input: AskInput): Promise<void>
10
+ }
11
+
12
+ type AskInput = {
13
+ permission: string
14
+ patterns: string[]
15
+ always: string[]
16
+ metadata: { [key: string]: any }
17
+ }
18
+
19
+ export function tool<Args extends z.ZodRawShape>(input: {
20
+ description: string
21
+ args: Args
22
+ execute(args: z.infer<z.ZodObject<Args>>, context: ToolContext): Promise<string>
23
+ }) {
24
+ return input
25
+ }
26
+ tool.schema = z
27
+
28
+ export type ToolDefinition = ReturnType<typeof tool>
@@ -0,0 +1,20 @@
1
+ {
2
+ "name": "@dfcode/util",
3
+ "version": "1.0.0",
4
+ "private": true,
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "exports": {
8
+ "./*": "./src/*.ts"
9
+ },
10
+ "scripts": {
11
+ "typecheck": "tsc --noEmit"
12
+ },
13
+ "dependencies": {
14
+ "zod": "catalog:"
15
+ },
16
+ "devDependencies": {
17
+ "typescript": "catalog:",
18
+ "@types/bun": "catalog:"
19
+ }
20
+ }
@@ -0,0 +1,10 @@
1
+ export function findLast<T>(
2
+ items: readonly T[],
3
+ predicate: (item: T, index: number, items: readonly T[]) => boolean,
4
+ ): T | undefined {
5
+ for (let i = items.length - 1; i >= 0; i -= 1) {
6
+ const item = items[i]
7
+ if (predicate(item, i, items)) return item
8
+ }
9
+ return undefined
10
+ }
@@ -0,0 +1,41 @@
1
+ export namespace Binary {
2
+ export function search<T>(array: T[], id: string, compare: (item: T) => string): { found: boolean; index: number } {
3
+ let left = 0
4
+ let right = array.length - 1
5
+
6
+ while (left <= right) {
7
+ const mid = Math.floor((left + right) / 2)
8
+ const midId = compare(array[mid])
9
+
10
+ if (midId === id) {
11
+ return { found: true, index: mid }
12
+ } else if (midId < id) {
13
+ left = mid + 1
14
+ } else {
15
+ right = mid - 1
16
+ }
17
+ }
18
+
19
+ return { found: false, index: left }
20
+ }
21
+
22
+ export function insert<T>(array: T[], item: T, compare: (item: T) => string): T[] {
23
+ const id = compare(item)
24
+ let left = 0
25
+ let right = array.length
26
+
27
+ while (left < right) {
28
+ const mid = Math.floor((left + right) / 2)
29
+ const midId = compare(array[mid])
30
+
31
+ if (midId < id) {
32
+ left = mid + 1
33
+ } else {
34
+ right = mid
35
+ }
36
+ }
37
+
38
+ array.splice(left, 0, item)
39
+ return array
40
+ }
41
+ }
@@ -0,0 +1,30 @@
1
+ export function base64Encode(value: string) {
2
+ const bytes = new TextEncoder().encode(value)
3
+ const binary = Array.from(bytes, (b) => String.fromCharCode(b)).join("")
4
+ return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "")
5
+ }
6
+
7
+ export function base64Decode(value: string) {
8
+ const binary = atob(value.replace(/-/g, "+").replace(/_/g, "/"))
9
+ const bytes = Uint8Array.from(binary, (c) => c.charCodeAt(0))
10
+ return new TextDecoder().decode(bytes)
11
+ }
12
+
13
+ export async function hash(content: string, algorithm = "SHA-256"): Promise<string> {
14
+ const encoder = new TextEncoder()
15
+ const data = encoder.encode(content)
16
+ const hashBuffer = await crypto.subtle.digest(algorithm, data)
17
+ const hashArray = Array.from(new Uint8Array(hashBuffer))
18
+ const hashHex = hashArray.map((b) => b.toString(16).padStart(2, "0")).join("")
19
+ return hashHex
20
+ }
21
+
22
+ export function checksum(content: string): string | undefined {
23
+ if (!content) return undefined
24
+ let hash = 0x811c9dc5
25
+ for (let i = 0; i < content.length; i++) {
26
+ hash ^= content.charCodeAt(i)
27
+ hash = Math.imul(hash, 0x01000193)
28
+ }
29
+ return (hash >>> 0).toString(36)
30
+ }
@@ -0,0 +1,54 @@
1
+ import z from "zod"
2
+
3
+ export abstract class NamedError extends Error {
4
+ abstract schema(): z.core.$ZodType
5
+ abstract toObject(): { name: string; data: any }
6
+
7
+ static create<Name extends string, Data extends z.core.$ZodType>(name: Name, data: Data) {
8
+ const schema = z
9
+ .object({
10
+ name: z.literal(name),
11
+ data,
12
+ })
13
+ .meta({
14
+ ref: name,
15
+ })
16
+ const result = class extends NamedError {
17
+ public static readonly Schema = schema
18
+
19
+ public override readonly name = name as Name
20
+
21
+ constructor(
22
+ public readonly data: z.input<Data>,
23
+ options?: ErrorOptions,
24
+ ) {
25
+ super(name, options)
26
+ this.name = name
27
+ }
28
+
29
+ static isInstance(input: any): input is InstanceType<typeof result> {
30
+ return typeof input === "object" && "name" in input && input.name === name
31
+ }
32
+
33
+ schema() {
34
+ return schema
35
+ }
36
+
37
+ toObject() {
38
+ return {
39
+ name: name,
40
+ data: this.data,
41
+ }
42
+ }
43
+ }
44
+ Object.defineProperty(result, "name", { value: name })
45
+ return result
46
+ }
47
+
48
+ public static readonly Unknown = NamedError.create(
49
+ "UnknownError",
50
+ z.object({
51
+ message: z.string(),
52
+ }),
53
+ )
54
+ }
@@ -0,0 +1,11 @@
1
+ import { z } from "zod"
2
+
3
+ export function fn<T extends z.ZodType, Result>(schema: T, cb: (input: z.infer<T>) => Result) {
4
+ const result = (input: z.infer<T>) => {
5
+ const parsed = schema.parse(input)
6
+ return cb(parsed)
7
+ }
8
+ result.force = (input: z.infer<T>) => cb(input)
9
+ result.schema = schema
10
+ return result
11
+ }
@@ -0,0 +1,48 @@
1
+ import { randomBytes } from "crypto"
2
+
3
+ export namespace Identifier {
4
+ const LENGTH = 26
5
+
6
+ // State for monotonic ID generation
7
+ let lastTimestamp = 0
8
+ let counter = 0
9
+
10
+ export function ascending() {
11
+ return create(false)
12
+ }
13
+
14
+ export function descending() {
15
+ return create(true)
16
+ }
17
+
18
+ function randomBase62(length: number): string {
19
+ const chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
20
+ let result = ""
21
+ const bytes = randomBytes(length)
22
+ for (let i = 0; i < length; i++) {
23
+ result += chars[bytes[i] % 62]
24
+ }
25
+ return result
26
+ }
27
+
28
+ export function create(descending: boolean, timestamp?: number): string {
29
+ const currentTimestamp = timestamp ?? Date.now()
30
+
31
+ if (currentTimestamp !== lastTimestamp) {
32
+ lastTimestamp = currentTimestamp
33
+ counter = 0
34
+ }
35
+ counter++
36
+
37
+ let now = BigInt(currentTimestamp) * BigInt(0x1000) + BigInt(counter)
38
+
39
+ now = descending ? ~now : now
40
+
41
+ const timeBytes = Buffer.alloc(6)
42
+ for (let i = 0; i < 6; i++) {
43
+ timeBytes[i] = Number((now >> BigInt(40 - 8 * i)) & BigInt(0xff))
44
+ }
45
+
46
+ return timeBytes.toString("hex") + randomBase62(LENGTH - 12)
47
+ }
48
+ }
@@ -0,0 +1,3 @@
1
+ export function iife<T>(fn: () => T) {
2
+ return fn()
3
+ }
@@ -0,0 +1,11 @@
1
+ export function lazy<T>(fn: () => T) {
2
+ let value: T | undefined
3
+ let loaded = false
4
+
5
+ return (): T => {
6
+ if (loaded) return value as T
7
+ loaded = true
8
+ value = fn()
9
+ return value as T
10
+ }
11
+ }
@@ -0,0 +1,37 @@
1
+ export function getFilename(path: string | undefined) {
2
+ if (!path) return ""
3
+ const trimmed = path.replace(/[\/\\]+$/, "")
4
+ const parts = trimmed.split(/[\/\\]/)
5
+ return parts[parts.length - 1] ?? ""
6
+ }
7
+
8
+ export function getDirectory(path: string | undefined) {
9
+ if (!path) return ""
10
+ const trimmed = path.replace(/[\/\\]+$/, "")
11
+ const parts = trimmed.split(/[\/\\]/)
12
+ return parts.slice(0, parts.length - 1).join("/") + "/"
13
+ }
14
+
15
+ export function getFileExtension(path: string | undefined) {
16
+ if (!path) return ""
17
+ const parts = path.split(".")
18
+ return parts[parts.length - 1]
19
+ }
20
+
21
+ export function getFilenameTruncated(path: string | undefined, maxLength: number = 20) {
22
+ const filename = getFilename(path)
23
+ if (filename.length <= maxLength) return filename
24
+ const lastDot = filename.lastIndexOf(".")
25
+ const ext = lastDot <= 0 ? "" : filename.slice(lastDot)
26
+ const available = maxLength - ext.length - 1 // -1 for ellipsis
27
+ if (available <= 0) return filename.slice(0, maxLength - 1) + "…"
28
+ return filename.slice(0, available) + "…" + ext
29
+ }
30
+
31
+ export function truncateMiddle(text: string, maxLength: number = 20) {
32
+ if (text.length <= maxLength) return text
33
+ const available = maxLength - 1 // -1 for ellipsis
34
+ const start = Math.ceil(available / 2)
35
+ const end = Math.floor(available / 2)
36
+ return text.slice(0, start) + "…" + text.slice(-end)
37
+ }