deepclause-sdk 0.0.89 → 0.1.1

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 (329) hide show
  1. package/README.md +481 -941
  2. package/dist/agent.d.ts +19 -2
  3. package/dist/agent.d.ts.map +1 -1
  4. package/dist/agent.js +75 -21
  5. package/dist/agent.js.map +1 -1
  6. package/dist/cli/config.d.ts +385 -178
  7. package/dist/cli/config.d.ts.map +1 -1
  8. package/dist/cli/config.js +161 -188
  9. package/dist/cli/config.js.map +1 -1
  10. package/dist/cli/index.d.ts +3 -2
  11. package/dist/cli/index.d.ts.map +1 -1
  12. package/dist/cli/index.js +85 -411
  13. package/dist/cli/index.js.map +1 -1
  14. package/dist/cli/login.d.ts +29 -0
  15. package/dist/cli/login.d.ts.map +1 -0
  16. package/dist/cli/login.js +184 -0
  17. package/dist/cli/login.js.map +1 -0
  18. package/dist/cli/readline.d.ts +6 -0
  19. package/dist/cli/readline.d.ts.map +1 -0
  20. package/dist/cli/readline.js +15 -0
  21. package/dist/cli/readline.js.map +1 -0
  22. package/dist/cli/repl-bin.d.ts +9 -0
  23. package/dist/cli/repl-bin.d.ts.map +1 -0
  24. package/dist/cli/repl-bin.js +16 -0
  25. package/dist/cli/repl-bin.js.map +1 -0
  26. package/dist/cli/repl.d.ts +216 -0
  27. package/dist/cli/repl.d.ts.map +1 -0
  28. package/dist/cli/repl.js +1392 -0
  29. package/dist/cli/repl.js.map +1 -0
  30. package/dist/cli/run.d.ts +17 -18
  31. package/dist/cli/run.d.ts.map +1 -1
  32. package/dist/cli/run.js +202 -183
  33. package/dist/cli/run.js.map +1 -1
  34. package/dist/cli/set-backend.d.ts +53 -0
  35. package/dist/cli/set-backend.d.ts.map +1 -0
  36. package/dist/cli/set-backend.js +259 -0
  37. package/dist/cli/set-backend.js.map +1 -0
  38. package/dist/cli/visualize.d.ts +42 -0
  39. package/dist/cli/visualize.d.ts.map +1 -0
  40. package/dist/cli/visualize.js +150 -0
  41. package/dist/cli/visualize.js.map +1 -0
  42. package/dist/compiler.d.ts +5 -52
  43. package/dist/compiler.d.ts.map +1 -1
  44. package/dist/compiler.js +4 -768
  45. package/dist/compiler.js.map +1 -1
  46. package/dist/index.d.ts +27 -2
  47. package/dist/index.d.ts.map +1 -1
  48. package/dist/index.js +18 -2
  49. package/dist/index.js.map +1 -1
  50. package/dist/prolog/bridge.d.ts +5 -1
  51. package/dist/prolog/bridge.d.ts.map +1 -1
  52. package/dist/prolog/bridge.js +10 -1
  53. package/dist/prolog/bridge.js.map +1 -1
  54. package/dist/prolog-src/deepclause_analysis.pl +10 -2
  55. package/dist/prolog-src/deepclause_mi.pl +2440 -49
  56. package/dist/repl/agent.d.ts +90 -0
  57. package/dist/repl/agent.d.ts.map +1 -0
  58. package/dist/repl/agent.js +410 -0
  59. package/dist/repl/agent.js.map +1 -0
  60. package/dist/repl/auth.d.ts +45 -0
  61. package/dist/repl/auth.d.ts.map +1 -0
  62. package/dist/repl/auth.js +116 -0
  63. package/dist/repl/auth.js.map +1 -0
  64. package/dist/repl/backend.d.ts +321 -0
  65. package/dist/repl/backend.d.ts.map +1 -0
  66. package/dist/repl/backend.js +415 -0
  67. package/dist/repl/backend.js.map +1 -0
  68. package/dist/repl/compaction.d.ts +122 -0
  69. package/dist/repl/compaction.d.ts.map +1 -0
  70. package/dist/repl/compaction.js +318 -0
  71. package/dist/repl/compaction.js.map +1 -0
  72. package/dist/repl/export.d.ts +30 -0
  73. package/dist/repl/export.d.ts.map +1 -0
  74. package/dist/repl/export.js +23 -0
  75. package/dist/repl/export.js.map +1 -0
  76. package/dist/repl/frames.d.ts +21 -0
  77. package/dist/repl/frames.d.ts.map +1 -0
  78. package/dist/repl/frames.js +79 -0
  79. package/dist/repl/frames.js.map +1 -0
  80. package/dist/repl/harness-tools.d.ts +99 -0
  81. package/dist/repl/harness-tools.d.ts.map +1 -0
  82. package/dist/repl/harness-tools.js +192 -0
  83. package/dist/repl/harness-tools.js.map +1 -0
  84. package/dist/repl/highlight.d.ts +30 -0
  85. package/dist/repl/highlight.d.ts.map +1 -0
  86. package/dist/repl/highlight.js +285 -0
  87. package/dist/repl/highlight.js.map +1 -0
  88. package/dist/repl/history.d.ts +234 -0
  89. package/dist/repl/history.d.ts.map +1 -0
  90. package/dist/repl/history.js +661 -0
  91. package/dist/repl/history.js.map +1 -0
  92. package/dist/repl/imagegen.d.ts +29 -0
  93. package/dist/repl/imagegen.d.ts.map +1 -0
  94. package/dist/repl/imagegen.js +84 -0
  95. package/dist/repl/imagegen.js.map +1 -0
  96. package/dist/repl/index.d.ts +130 -0
  97. package/dist/repl/index.d.ts.map +1 -0
  98. package/dist/repl/index.js +112 -0
  99. package/dist/repl/index.js.map +1 -0
  100. package/dist/repl/judge.d.ts +51 -0
  101. package/dist/repl/judge.d.ts.map +1 -0
  102. package/dist/repl/judge.js +58 -0
  103. package/dist/repl/judge.js.map +1 -0
  104. package/dist/repl/markdown.d.ts +25 -0
  105. package/dist/repl/markdown.d.ts.map +1 -0
  106. package/dist/repl/markdown.js +103 -0
  107. package/dist/repl/markdown.js.map +1 -0
  108. package/dist/repl/model-resolver.d.ts +59 -0
  109. package/dist/repl/model-resolver.d.ts.map +1 -0
  110. package/dist/repl/model-resolver.js +156 -0
  111. package/dist/repl/model-resolver.js.map +1 -0
  112. package/dist/repl/picker.d.ts +34 -0
  113. package/dist/repl/picker.d.ts.map +1 -0
  114. package/dist/repl/picker.js +81 -0
  115. package/dist/repl/picker.js.map +1 -0
  116. package/dist/repl/project-context.d.ts +16 -0
  117. package/dist/repl/project-context.d.ts.map +1 -0
  118. package/dist/repl/project-context.js +23 -0
  119. package/dist/repl/project-context.js.map +1 -0
  120. package/dist/repl/render.d.ts +187 -0
  121. package/dist/repl/render.d.ts.map +1 -0
  122. package/dist/repl/render.js +808 -0
  123. package/dist/repl/render.js.map +1 -0
  124. package/dist/repl/session.d.ts +424 -0
  125. package/dist/repl/session.d.ts.map +1 -0
  126. package/dist/repl/session.js +1473 -0
  127. package/dist/repl/session.js.map +1 -0
  128. package/dist/repl/status.d.ts +100 -0
  129. package/dist/repl/status.d.ts.map +1 -0
  130. package/dist/repl/status.js +218 -0
  131. package/dist/repl/status.js.map +1 -0
  132. package/dist/repl/tools.d.ts +53 -0
  133. package/dist/repl/tools.d.ts.map +1 -0
  134. package/dist/repl/tools.js +307 -0
  135. package/dist/repl/tools.js.map +1 -0
  136. package/dist/repl/toolset.d.ts +32 -0
  137. package/dist/repl/toolset.d.ts.map +1 -0
  138. package/dist/repl/toolset.js +82 -0
  139. package/dist/repl/toolset.js.map +1 -0
  140. package/dist/repl/tui/editor.d.ts +17 -0
  141. package/dist/repl/tui/editor.d.ts.map +1 -0
  142. package/dist/repl/tui/editor.js +39 -0
  143. package/dist/repl/tui/editor.js.map +1 -0
  144. package/dist/repl/tui/status-bar.d.ts +26 -0
  145. package/dist/repl/tui/status-bar.d.ts.map +1 -0
  146. package/dist/repl/tui/status-bar.js +47 -0
  147. package/dist/repl/tui/status-bar.js.map +1 -0
  148. package/dist/repl/tui/theme.d.ts +30 -0
  149. package/dist/repl/tui/theme.d.ts.map +1 -0
  150. package/dist/repl/tui/theme.js +81 -0
  151. package/dist/repl/tui/theme.js.map +1 -0
  152. package/dist/repl/tui/transcript.d.ts +41 -0
  153. package/dist/repl/tui/transcript.d.ts.map +1 -0
  154. package/dist/repl/tui/transcript.js +139 -0
  155. package/dist/repl/tui/transcript.js.map +1 -0
  156. package/dist/runner.d.ts +143 -13
  157. package/dist/runner.d.ts.map +1 -1
  158. package/dist/runner.js +532 -290
  159. package/dist/runner.js.map +1 -1
  160. package/dist/sdk.d.ts.map +1 -1
  161. package/dist/sdk.js +0 -32
  162. package/dist/sdk.js.map +1 -1
  163. package/dist/system/assets/docs/AGENT_PROMPT.md +1447 -0
  164. package/dist/system/assets/docs/DML_AUTHORING.md +195 -0
  165. package/dist/system/assets/docs/DML_REFERENCE.md +344 -72
  166. package/dist/system/assets/docs/HARNESS_EXAMPLES.md +172 -0
  167. package/dist/system/assets/docs/HARNESS_PATTERNS.md +562 -0
  168. package/dist/system/assets/docs/META_PROMPT.md +68 -0
  169. package/dist/system/assets/docs/PROLOG_SNIPPETS.md +117 -0
  170. package/dist/system/assets/index.d.ts +9 -17
  171. package/dist/system/assets/index.d.ts.map +1 -1
  172. package/dist/system/assets/index.js +26 -85
  173. package/dist/system/assets/index.js.map +1 -1
  174. package/dist/system/runtime/agentvm-manager.d.ts +9 -2
  175. package/dist/system/runtime/agentvm-manager.d.ts.map +1 -1
  176. package/dist/system/runtime/agentvm-manager.js +70 -44
  177. package/dist/system/runtime/agentvm-manager.js.map +1 -1
  178. package/dist/system/runtime/media.d.ts +23 -0
  179. package/dist/system/runtime/media.d.ts.map +1 -0
  180. package/dist/system/runtime/media.js +55 -0
  181. package/dist/system/runtime/media.js.map +1 -0
  182. package/dist/system/runtime/shell-limits.d.ts +21 -0
  183. package/dist/system/runtime/shell-limits.d.ts.map +1 -0
  184. package/dist/system/runtime/shell-limits.js +39 -0
  185. package/dist/system/runtime/shell-limits.js.map +1 -0
  186. package/dist/system/runtime/shell-manager.d.ts +8 -3
  187. package/dist/system/runtime/shell-manager.d.ts.map +1 -1
  188. package/dist/system/runtime/shell-manager.js +56 -39
  189. package/dist/system/runtime/shell-manager.js.map +1 -1
  190. package/dist/system/runtime/shell-tool-events.js +5 -0
  191. package/dist/system/runtime/shell-tool-events.js.map +1 -1
  192. package/dist/system/runtime/token-usage.d.ts +2 -0
  193. package/dist/system/runtime/token-usage.d.ts.map +1 -1
  194. package/dist/system/runtime/token-usage.js +7 -0
  195. package/dist/system/runtime/token-usage.js.map +1 -1
  196. package/dist/tools.d.ts +3 -21
  197. package/dist/tools.d.ts.map +1 -1
  198. package/dist/tools.js +14 -168
  199. package/dist/tools.js.map +1 -1
  200. package/dist/types.d.ts +136 -119
  201. package/dist/types.d.ts.map +1 -1
  202. package/dist/validate.d.ts +19 -0
  203. package/dist/validate.d.ts.map +1 -0
  204. package/dist/validate.js +338 -0
  205. package/dist/validate.js.map +1 -0
  206. package/dist/visualize/ascii.d.ts +55 -0
  207. package/dist/visualize/ascii.d.ts.map +1 -0
  208. package/dist/visualize/ascii.js +242 -0
  209. package/dist/visualize/ascii.js.map +1 -0
  210. package/dist/visualize/display.d.ts +24 -0
  211. package/dist/visualize/display.d.ts.map +1 -0
  212. package/dist/visualize/display.js +29 -0
  213. package/dist/visualize/display.js.map +1 -0
  214. package/dist/visualize/graphics.d.ts +35 -0
  215. package/dist/visualize/graphics.d.ts.map +1 -0
  216. package/dist/visualize/graphics.js +96 -0
  217. package/dist/visualize/graphics.js.map +1 -0
  218. package/dist/visualize/image.d.ts +38 -0
  219. package/dist/visualize/image.d.ts.map +1 -0
  220. package/dist/visualize/image.js +95 -0
  221. package/dist/visualize/image.js.map +1 -0
  222. package/dist/visualize/index.d.ts +59 -0
  223. package/dist/visualize/index.d.ts.map +1 -0
  224. package/dist/visualize/index.js +198 -0
  225. package/dist/visualize/index.js.map +1 -0
  226. package/dist/visualize/raster.d.ts +23 -0
  227. package/dist/visualize/raster.d.ts.map +1 -0
  228. package/dist/visualize/raster.js +47 -0
  229. package/dist/visualize/raster.js.map +1 -0
  230. package/dist/visualize/svg.d.ts +39 -0
  231. package/dist/visualize/svg.d.ts.map +1 -0
  232. package/dist/visualize/svg.js +148 -0
  233. package/dist/visualize/svg.js.map +1 -0
  234. package/dist/visualize/transcode.d.ts +13 -0
  235. package/dist/visualize/transcode.d.ts.map +1 -0
  236. package/dist/visualize/transcode.js +40 -0
  237. package/dist/visualize/transcode.js.map +1 -0
  238. package/docs/images/repl.png +0 -0
  239. package/package.json +19 -15
  240. package/src/prolog-src/deepclause_analysis.pl +10 -2
  241. package/src/prolog-src/deepclause_mi.pl +2440 -49
  242. package/dist/cli/commands.d.ts +0 -42
  243. package/dist/cli/commands.d.ts.map +0 -1
  244. package/dist/cli/commands.js +0 -246
  245. package/dist/cli/commands.js.map +0 -1
  246. package/dist/cli/compile.d.ts +0 -99
  247. package/dist/cli/compile.d.ts.map +0 -1
  248. package/dist/cli/compile.js +0 -363
  249. package/dist/cli/compile.js.map +0 -1
  250. package/dist/cli/default-skills.d.ts +0 -10
  251. package/dist/cli/default-skills.d.ts.map +0 -1
  252. package/dist/cli/default-skills.js +0 -206
  253. package/dist/cli/default-skills.js.map +0 -1
  254. package/dist/cli/interactive.d.ts +0 -2
  255. package/dist/cli/interactive.d.ts.map +0 -1
  256. package/dist/cli/interactive.js +0 -20
  257. package/dist/cli/interactive.js.map +0 -1
  258. package/dist/cli/mcp.d.ts +0 -56
  259. package/dist/cli/mcp.d.ts.map +0 -1
  260. package/dist/cli/mcp.js +0 -138
  261. package/dist/cli/mcp.js.map +0 -1
  262. package/dist/cli/prompt.d.ts +0 -2
  263. package/dist/cli/prompt.d.ts.map +0 -1
  264. package/dist/cli/prompt.js +0 -2
  265. package/dist/cli/prompt.js.map +0 -1
  266. package/dist/cli/search.d.ts +0 -19
  267. package/dist/cli/search.d.ts.map +0 -1
  268. package/dist/cli/search.js +0 -189
  269. package/dist/cli/search.js.map +0 -1
  270. package/dist/cli/tool-args.d.ts +0 -2
  271. package/dist/cli/tool-args.d.ts.map +0 -1
  272. package/dist/cli/tool-args.js +0 -39
  273. package/dist/cli/tool-args.js.map +0 -1
  274. package/dist/cli/tools.d.ts +0 -36
  275. package/dist/cli/tools.d.ts.map +0 -1
  276. package/dist/cli/tools.js +0 -229
  277. package/dist/cli/tools.js.map +0 -1
  278. package/dist/cli/tui/index.d.ts +0 -22
  279. package/dist/cli/tui/index.d.ts.map +0 -1
  280. package/dist/cli/tui/index.js +0 -29
  281. package/dist/cli/tui/index.js.map +0 -1
  282. package/dist/cli/tui.d.ts +0 -167
  283. package/dist/cli/tui.d.ts.map +0 -1
  284. package/dist/cli/tui.js +0 -5228
  285. package/dist/cli/tui.js.map +0 -1
  286. package/dist/compiler_prompt.d.ts +0 -20
  287. package/dist/compiler_prompt.d.ts.map +0 -1
  288. package/dist/compiler_prompt.js +0 -870
  289. package/dist/compiler_prompt.js.map +0 -1
  290. package/dist/deepclause-cli.skill +0 -0
  291. package/dist/prolog-src/deepclause_mi.pl.bak +0 -570
  292. package/dist/system/assets/docs/CONDUCTOR_PROMPT.md +0 -105
  293. package/dist/system/assets/docs/DML_COMPILER_PROMPT.md +0 -700
  294. package/dist/system/assets/docs/TUI.md +0 -150
  295. package/dist/system/assets/recipes/deepclause-coding-workflow/SKILL.md +0 -100
  296. package/dist/system/assets/skills/conductor.dml +0 -76
  297. package/dist/system/assets/skills/deep-planner.dml +0 -412
  298. package/dist/system/assets/skills/plan.dml +0 -429
  299. package/dist/system/assets/skills/security-planner.dml +0 -337
  300. package/dist/system/assets/skills/skill-creator.dml +0 -187
  301. package/dist/system/runtime/catalog-recipes.d.ts +0 -24
  302. package/dist/system/runtime/catalog-recipes.d.ts.map +0 -1
  303. package/dist/system/runtime/catalog-recipes.js +0 -273
  304. package/dist/system/runtime/catalog-recipes.js.map +0 -1
  305. package/dist/system/runtime/catalog-skills.d.ts +0 -50
  306. package/dist/system/runtime/catalog-skills.d.ts.map +0 -1
  307. package/dist/system/runtime/catalog-skills.js +0 -152
  308. package/dist/system/runtime/catalog-skills.js.map +0 -1
  309. package/dist/system/runtime/conductor.d.ts +0 -105
  310. package/dist/system/runtime/conductor.d.ts.map +0 -1
  311. package/dist/system/runtime/conductor.js +0 -732
  312. package/dist/system/runtime/conductor.js.map +0 -1
  313. package/dist/system/runtime/console-capture.d.ts +0 -9
  314. package/dist/system/runtime/console-capture.d.ts.map +0 -1
  315. package/dist/system/runtime/console-capture.js +0 -67
  316. package/dist/system/runtime/console-capture.js.map +0 -1
  317. package/dist/system/runtime/dml-executor.d.ts +0 -52
  318. package/dist/system/runtime/dml-executor.d.ts.map +0 -1
  319. package/dist/system/runtime/dml-executor.js +0 -203
  320. package/dist/system/runtime/dml-executor.js.map +0 -1
  321. package/dist/system/runtime/runtime-tools.d.ts +0 -31
  322. package/dist/system/runtime/runtime-tools.d.ts.map +0 -1
  323. package/dist/system/runtime/runtime-tools.js +0 -312
  324. package/dist/system/runtime/runtime-tools.js.map +0 -1
  325. package/dist/system/runtime/skill-creator.d.ts +0 -38
  326. package/dist/system/runtime/skill-creator.d.ts.map +0 -1
  327. package/dist/system/runtime/skill-creator.js +0 -763
  328. package/dist/system/runtime/skill-creator.js.map +0 -1
  329. package/src/prolog-src/deepclause_mi.pl.bak +0 -570
package/dist/cli/index.js CHANGED
@@ -1,20 +1,19 @@
1
1
  #!/usr/bin/env node
2
2
  /**
3
- * DeepClause CLI
3
+ * DeepClause CLI.
4
4
  *
5
- * Command-line interface for compiling Markdown to DML and running DML programs.
5
+ * Commands: init, set-model, show-model, list-models, run, repl, login,
6
+ * logout, set-backend.
6
7
  */
7
8
  import { Command } from 'commander';
8
9
  import * as path from 'path';
9
10
  import * as fs from 'fs/promises';
10
- import { deepClauseDirExists, initConfig, setModel, showModel } from './config.js';
11
- import { compile, compileAll } from './compile.js';
11
+ import { deepClauseDirExists, initConfig, loadConfig, setModel, showModel } from './config.js';
12
12
  import { run } from './run.js';
13
- import { listTools } from './tools.js';
14
- import { listCommands } from './commands.js';
15
- import { formatToolArgs } from './tool-args.js';
16
- import { buildModelOverride } from '../system/config/model-slots.js';
17
- import { runPromptHeadless, startTui } from './tui.js';
13
+ import { registerReplCommand } from './repl.js';
14
+ import { registerVisualizeCommand } from './visualize.js';
15
+ import { registerSetBackendCommand, setBackend } from './set-backend.js';
16
+ import { registerLoginCommands } from './login.js';
18
17
  import { readFileSync } from 'fs';
19
18
  import { fileURLToPath } from 'url';
20
19
  import { dirname, join } from 'path';
@@ -25,13 +24,10 @@ const packageJsonPath = join(__dirname, '../../package.json');
25
24
  const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8'));
26
25
  const version = packageJson.version;
27
26
  const program = new Command();
28
- const CLI_SUBCOMMANDS = new Set(['init', 'set-model', 'show-model', 'list-models', 'compile', 'compile-all', 'run', 'plan', 'list-tools', 'list-commands', 'help']);
29
27
  program
30
28
  .name('deepclause')
31
- .description('Compile Markdown to DML and run neurosymbolic AI agents')
32
- .version(version)
33
- .option('-p, --prompt <text>', 'Run a prompt in headless conductor mode with a fresh session')
34
- .option('--sandbox', 'Run shell tools inside AgentVM instead of the local workspace shell');
29
+ .description('Run and build DML skills with the REPL and one-shot runner')
30
+ .version(version);
35
31
  // =============================================================================
36
32
  // Configuration Commands
37
33
  // =============================================================================
@@ -56,9 +52,23 @@ program
56
52
  .description('Set the default LLM model (format: provider:model, or just a model name to search)')
57
53
  .option('--slot <slot>', 'Apply only to a single slot: gateway, run, or compile')
58
54
  .option('--provider <provider>', 'Non-interactive: specify provider directly (openai, anthropic, google, openrouter, custom:name)')
55
+ .option('--thinking <level>', 'thinking level for reasoning models (off|minimal|low|medium|high|xhigh|max)')
59
56
  .action(async (model, options) => {
60
57
  try {
61
58
  const slot = options.slot;
59
+ // With the pi backend the model comes from pi's catalog, so route the
60
+ // change through set-backend (which validates auth and persists the
61
+ // model + thinking level together). The env backend keeps the DB flow.
62
+ const config = await loadConfig(process.cwd());
63
+ if ((config.backend?.kind ?? 'pi') === 'pi') {
64
+ const result = await setBackend(process.cwd(), 'pi', {
65
+ model: model.includes(':') || model.includes('/') ? model.replace(':', '/') : model,
66
+ provider: options.provider,
67
+ thinking: options.thinking,
68
+ });
69
+ console.log(result.info);
70
+ return;
71
+ }
62
72
  // If the model already has a provider prefix (contains : or is custom:), use as-is
63
73
  const hasProviderPrefix = model.includes(':') || model.startsWith('custom:');
64
74
  let finalModel = model;
@@ -108,7 +118,7 @@ program
108
118
  if (results.length > 10) {
109
119
  console.log(` ... and ${results.length - 10} more. Refine your search for fewer results.`);
110
120
  }
111
- const { promptUser } = await import('./interactive.js');
121
+ const { promptUser } = await import('./readline.js');
112
122
  const answer = await promptUser(`Enter choice (1-${choices.length}) or press Enter for #1:`);
113
123
  const choice = parseInt(answer.trim()) || 1;
114
124
  if (choice < 1 || choice > choices.length) {
@@ -186,162 +196,38 @@ program
186
196
  process.exit(1);
187
197
  }
188
198
  });
189
- // =============================================================================
190
- // Compilation Commands
191
- // =============================================================================
192
199
  program
193
- .command('compile <source> [output]')
194
- .description('Compile Markdown task description to DML')
195
- .option('-f, --force', 'Force recompilation even if source unchanged')
196
- .option('--validate-only', 'Validate without saving output')
197
- .option('--headless', 'Plain output only, no live formatting')
198
- .option('--sandbox', 'Run shell tools inside AgentVM instead of the local workspace shell')
199
- .option('--trace <file>', 'Save compilation trace to file')
200
- .option('--model <model>', 'Override model for compilation')
201
- .option('--provider <provider>', 'Override provider for compilation (openai, anthropic, google, openrouter)')
202
- .option('--temperature <number>', 'Override temperature (0.0-2.0)', parseFloat)
203
- .option('--max-attempts <number>', 'Max compilation attempts (default: 3)', parseInt)
204
- .option('-v, --verbose', 'Show debug output including tool calls')
205
- .option('--stream', 'Stream LLM responses in real-time')
206
- .option('--no-audit', 'Disable the LLM security audit (static analysis still runs)')
207
- .action(async (source, output, options) => {
200
+ .command('image-models')
201
+ .description('List image-generation models for /gen and task(…, media(X))')
202
+ .option('--json', 'Output as JSON')
203
+ .action(async (options) => {
208
204
  try {
209
- const outputDir = output || '.deepclause/tools';
210
- const liveOutput = [];
211
- const onEvent = (event) => {
212
- switch (event.type) {
213
- case 'output':
214
- if (event.content) {
215
- liveOutput.push(event.content);
216
- if (!options.headless) {
217
- process.stdout.write(`${event.content}\n`);
218
- }
219
- }
220
- break;
221
- case 'stream':
222
- if (options.stream && !options.headless && event.content) {
223
- process.stdout.write(event.content);
224
- }
225
- if (options.stream && !options.headless && event.done) {
226
- process.stdout.write('\n');
227
- }
228
- break;
229
- case 'log':
230
- if (options.verbose && !options.headless && event.content) {
231
- process.stdout.write(`[log] ${event.content}\n`);
232
- }
233
- break;
234
- case 'tool_call':
235
- if (options.verbose && !options.headless && event.toolName) {
236
- process.stdout.write(` 🔧 ${event.toolName}(${formatToolArgs(event.toolArgs)})\n`);
237
- }
238
- break;
239
- case 'input_required':
240
- if (options.verbose && !options.headless && event.prompt) {
241
- process.stdout.write(`[input_required] ${event.prompt}\n`);
242
- }
243
- break;
244
- default:
245
- break;
246
- }
247
- };
248
- const result = await compile(source, outputDir, {
249
- force: options.force,
250
- validateOnly: options.validateOnly,
251
- headless: options.headless,
252
- sandbox: options.sandbox,
253
- trace: options.trace,
254
- model: buildModelOverride(options.model, options.provider),
255
- provider: options.provider,
256
- temperature: options.temperature,
257
- maxAttempts: options.maxAttempts,
258
- verbose: options.verbose,
259
- stream: options.stream,
260
- audit: options.audit !== false,
261
- onEvent,
262
- });
263
- if (result.analysis?.warnings?.length) {
264
- console.log('\n⚠️ Static Analysis Warnings:');
265
- for (const warning of result.analysis.warnings) {
266
- const icon = warning.level === 'critical' ? '🔴' : warning.level === 'high' ? '🟠' : warning.level === 'medium' ? '🟡' : '⚪';
267
- console.log(` ${icon} [${warning.level.toUpperCase()}] ${warning.message}`);
268
- }
269
- }
270
- if (result.analysis?.auditorReport) {
271
- console.log('\n🛡️ LLM Security Audit:\n');
272
- console.log(result.analysis.auditorReport);
273
- }
274
- if (options.headless) {
275
- for (const out of result.runtimeOutput ?? liveOutput) {
276
- console.log(out);
277
- }
205
+ const { openPiRuntime } = await import('../repl/backend.js');
206
+ const handle = await openPiRuntime({});
207
+ const runtime = handle.runtime;
208
+ const all = runtime.getModelsOfType?.('image') ?? [];
209
+ const available = typeof runtime.getAvailableOfType === 'function'
210
+ ? await runtime.getAvailableOfType('image')
211
+ : [];
212
+ const ready = new Set(available.map((m) => `${m.provider}:${m.id}`));
213
+ const rows = all.map((m) => ({ model: `${m.provider}:${m.id}`, authenticated: ready.has(`${m.provider}:${m.id}`) }));
214
+ if (options.json) {
215
+ console.log(JSON.stringify(rows, null, 2));
278
216
  }
279
- if (result.skipped) {
280
- console.log(`⏭️ Skipped (unchanged): ${source}`);
217
+ else if (all.length === 0) {
218
+ console.log('No image-generation models are known. Run `deepclause login` and sign in to a provider that offers image models.');
281
219
  }
282
220
  else {
283
- console.log('\n✅ Compilation successful!\n');
284
- if (result.explanation) {
285
- console.log(result.explanation);
286
- }
287
- }
288
- if (!result.skipped && !options.validateOnly) {
289
- console.log(`\n Output: ${result.output}`);
290
- console.log(` Tools: ${result.tools.join(', ') || 'none'}`);
291
- if (result.attempts && result.attempts > 1) {
292
- console.log(` Attempts: ${result.attempts}`);
221
+ console.log(`Image models (${available.length} available)\n`);
222
+ for (const row of rows) {
223
+ console.log(` ${row.model} [${row.authenticated ? 'ready' : 'needs auth'}]`);
293
224
  }
294
- }
295
- if (!result.skipped && options.trace) {
296
- console.log(`\n📊 Trace saved to: ${options.trace}`);
297
- }
298
- }
299
- catch (error) {
300
- const compileError = error;
301
- if (options.headless && Array.isArray(compileError.runtimeOutput)) {
302
- for (const out of compileError.runtimeOutput) {
303
- console.log(out);
225
+ const first = available[0];
226
+ if (first) {
227
+ console.log(`\nUse one with: deepclause repl --image-model ${first.provider}:${first.id}`);
228
+ console.log('or set "repl": { "media": { "imageModel": "' + `${first.provider}:${first.id}` + '" } } in .deepclause/config.json');
304
229
  }
305
230
  }
306
- const message = error instanceof Error && error.message
307
- ? error.message
308
- : String(error);
309
- console.error(message.startsWith('❌') ? message : `❌ Error: ${message}`);
310
- if (options.trace && compileError.trace) {
311
- console.log(`\n📊 Trace saved to: ${options.trace}`);
312
- }
313
- if (options.verbose && error instanceof Error && error.stack) {
314
- console.error(error.stack);
315
- }
316
- process.exit(1);
317
- }
318
- });
319
- program
320
- .command('compile-all <sourceDir> [outputDir]')
321
- .description('Compile all Markdown files in a directory')
322
- .option('-f, --force', 'Force recompilation of all files')
323
- .option('--sandbox', 'Run shell tools inside AgentVM instead of the local workspace shell')
324
- .option('--model <model>', 'Override model for compilation')
325
- .option('--provider <provider>', 'Override provider for compilation (openai, anthropic, google, openrouter)')
326
- .option('--temperature <number>', 'Override temperature (0.0-2.0)', parseFloat)
327
- .option('--max-attempts <number>', 'Max compilation attempts per file (default: 3)', parseInt)
328
- .option('--no-audit', 'Disable the LLM security audit (static analysis still runs)')
329
- .action(async (sourceDir, outputDir, options) => {
330
- try {
331
- const out = outputDir || '.deepclause/tools';
332
- const result = await compileAll(sourceDir, out, {
333
- force: options.force,
334
- sandbox: options.sandbox,
335
- model: buildModelOverride(options.model, options.provider),
336
- provider: options.provider,
337
- temperature: options.temperature,
338
- maxAttempts: options.maxAttempts,
339
- audit: options.audit !== false,
340
- });
341
- console.log(`\n📊 Compilation Summary:`);
342
- console.log(` Compiled: ${result.compiled}`);
343
- console.log(` Skipped: ${result.skipped}`);
344
- console.log(` Failed: ${result.failed}`);
345
231
  }
346
232
  catch (error) {
347
233
  console.error('❌ Error:', error.message);
@@ -353,173 +239,73 @@ program
353
239
  // =============================================================================
354
240
  program
355
241
  .command('run [file] [args...]')
356
- .description('Execute a compiled DML program or generate and run DML from a prompt')
242
+ .description('Execute a DML file (one-shot)')
357
243
  .option('--workspace <path>', 'Working directory for file operations', './')
244
+ .option('--backend <kind>', 'Model backend: pi (default) or env')
245
+ .option('--goal <dml>', 'Run this goal instead of agent_main/N')
358
246
  .option('--verbose', 'Show debug output including tool calls')
359
- .option('--stream', 'Stream LLM responses in real-time')
360
- .option('--headless', 'Plain output only, no TUI formatting')
247
+ .option('--no-stream', 'Hide streamed model text/reasoning (show only outputs and answers)')
248
+ .option('--show-reasoning <mode>', 'How much model reasoning to show: off|summary|full', (value) => {
249
+ if (value !== 'off' && value !== 'summary' && value !== 'full') {
250
+ throw new Error(`invalid --show-reasoning: ${value} (use off, summary, or full)`);
251
+ }
252
+ return value;
253
+ })
254
+ .option('--no-events', 'Hide task activity, tool calls, usage, and logs')
255
+ .option('--plain', 'No color/formatting')
256
+ .option('--json', 'Emit events as JSON lines')
361
257
  .option('--sandbox', 'Run shell tools inside AgentVM instead of the local workspace shell')
362
258
  .option('--trace <file>', 'Save execution trace to file')
363
259
  .option('--dry-run', 'Show what would be executed without running')
364
- .option('--model <model>', 'Override configured model (can be provider/model format, e.g., google/gemini-2.5-pro)')
260
+ .option('--model <model>', 'Override configured model (provider/model)')
365
261
  .option('--provider <provider>', 'Override configured provider (openai, anthropic, google, openrouter)')
366
262
  .option('--temperature <number>', 'Override temperature (0.0-2.0)', parseFloat)
367
- .option('--no-audit', 'Disable the LLM security audit for one-shot prompt compilation')
368
263
  .option('--gas-limit <number>', 'Maximum number of execution steps', parseInt)
369
264
  .option('--usage <file>', 'Save token usage summary to file')
370
- .option('-p, --prompt <text>', 'One-shot prompt: generate and run DML from natural language')
371
265
  .option('-P, --param <key=value>', 'Pass named parameter (can be repeated)', collectParams, {})
372
266
  .action(async (file, args, options) => {
373
267
  try {
374
- // Parse provider/model format if provided (e.g., "google/gemini-2.5-pro")
268
+ // Parse provider/model format if provided (e.g., "google/gemini-2.5-pro").
375
269
  let model = options.model;
376
270
  let provider = options.provider;
377
271
  if (model && model.includes('/')) {
378
272
  const [parsedProvider, ...modelParts] = model.split('/');
379
273
  provider = provider || parsedProvider;
380
- model = modelParts.join('/'); // Handle models with / in name
274
+ model = modelParts.join('/');
381
275
  }
382
276
  const result = await run(file, args, {
383
277
  workspace: options.workspace,
278
+ backend: options.backend,
279
+ goal: options.goal,
384
280
  verbose: options.verbose,
385
281
  stream: options.stream,
386
- headless: options.headless,
282
+ events: options.events,
283
+ showReasoning: options.showReasoning,
284
+ plain: options.plain,
285
+ json: options.json,
387
286
  sandbox: options.sandbox,
388
287
  trace: options.trace,
389
288
  dryRun: options.dryRun,
390
289
  model,
391
290
  provider: provider,
392
291
  temperature: options.temperature,
393
- audit: options.audit !== false,
394
292
  gasLimit: options.gasLimit,
395
293
  params: options.param,
396
- prompt: options.prompt
397
294
  });
398
295
  if (options.dryRun) {
399
296
  console.log(result.wouldExecute);
400
- }
401
- else {
402
- // Show outputs only in headless mode (in interactive mode they were already shown)
403
- if (options.headless && result.output.length > 0) {
404
- for (const out of result.output) {
405
- console.log(out);
406
- }
407
- }
408
- // Show answer
409
- if (result.answer) {
410
- if (result.output.length > 0) {
411
- console.log(''); // Blank line before answer
412
- }
413
- console.log(result.answer);
414
- }
415
- // Show error
416
- if (result.error) {
417
- console.error('❌ Error:', result.error);
418
- process.exit(1);
419
- }
420
- // Show trace location if saved
421
- if (options.trace) {
422
- console.log(`\n📊 Trace saved to: ${options.trace}`);
423
- }
424
- // Save usage data if requested
425
- if (options.usage && result.usageByModel && Object.keys(result.usageByModel).length > 0) {
426
- const usagePath = path.resolve(options.usage);
427
- await fs.writeFile(usagePath, JSON.stringify(result.usageByModel, null, 2) + '\n', 'utf8');
428
- if (options.verbose) {
429
- console.log(`📊 Usage saved to: ${usagePath}`);
430
- }
431
- }
432
- }
433
- }
434
- catch (error) {
435
- console.error('❌ Error:', error.message);
436
- if (options.verbose) {
437
- console.error(error.stack);
438
- }
439
- process.exit(1);
440
- }
441
- });
442
- // =============================================================================
443
- // Plan Command
444
- // =============================================================================
445
- program
446
- .command('plan [file]')
447
- .description('Generate a standalone DML plan from a Markdown specification (same as /plan in the TUI)')
448
- .option('--workspace <path>', 'Working directory for file operations', './')
449
- .option('--verbose', 'Show debug output including tool calls')
450
- .option('--stream', 'Stream LLM responses in real-time')
451
- .option('--headless', 'Plain output only, no TUI formatting')
452
- .option('--sandbox', 'Run shell tools inside AgentVM instead of the local workspace shell')
453
- .option('--model <model>', 'Override configured model (can be provider/model format, e.g., google/gemini-2.5-pro)')
454
- .option('--provider <provider>', 'Override configured provider (openai, anthropic, google, openrouter)')
455
- .option('--temperature <number>', 'Override temperature (0.0-2.0)', parseFloat)
456
- .option('--gas-limit <number>', 'Maximum number of execution steps', parseInt)
457
- .option('--usage <file>', 'Save token usage summary to file')
458
- .action(async (file, options) => {
459
- try {
460
- const configRoot = path.resolve(options.workspace ?? './');
461
- const { getSystemAssetSourcePaths } = await import('../system/assets/index.js');
462
- const planDmlPath = getSystemAssetSourcePaths(configRoot).planDml;
463
- let requestContent;
464
- if (file) {
465
- const filePath = path.resolve(configRoot, file);
466
- try {
467
- requestContent = await fs.readFile(filePath, 'utf8');
468
- }
469
- catch {
470
- console.error(`❌ Cannot read file: ${filePath}`);
471
- process.exit(1);
472
- }
473
- }
474
- else if (!process.stdin.isTTY) {
475
- const chunks = [];
476
- for await (const chunk of process.stdin) {
477
- chunks.push(chunk);
478
- }
479
- requestContent = Buffer.concat(chunks).toString('utf8');
480
- if (!requestContent.trim()) {
481
- console.error('❌ No input provided. Usage: deepclause plan <file> or cat spec.md | deepclause plan');
482
- process.exit(1);
483
- }
484
- }
485
- else {
486
- console.error('❌ No input provided. Usage: deepclause plan <file> or cat spec.md | deepclause plan');
487
- process.exit(1);
488
- }
489
- let model = options.model;
490
- let provider = options.provider;
491
- if (model && model.includes('/')) {
492
- const [parsedProvider, ...modelParts] = model.split('/');
493
- provider = provider || parsedProvider;
494
- model = modelParts.join('/');
495
- }
496
- const result = await run(planDmlPath, [requestContent], {
497
- configRoot,
498
- workspace: options.workspace,
499
- verbose: options.verbose,
500
- stream: options.stream,
501
- headless: options.headless ?? true,
502
- sandbox: options.sandbox,
503
- model,
504
- provider: provider,
505
- temperature: options.temperature,
506
- gasLimit: options.gasLimit,
507
- });
508
- if (options.headless !== false && result.output.length > 0) {
509
- for (const out of result.output) {
510
- console.log(out);
511
- }
512
- }
513
- if (result.answer) {
514
- if (result.output.length > 0) {
515
- console.log('');
516
- }
517
- console.log(result.answer);
297
+ return;
518
298
  }
519
299
  if (result.error) {
520
300
  console.error('❌ Error:', result.error);
521
301
  process.exit(1);
522
302
  }
303
+ if (options.trace && result.trace) {
304
+ console.log(`\n📊 Trace saved to: ${options.trace}`);
305
+ }
306
+ else if (options.trace) {
307
+ console.log('\n(no execution trace was produced for this run)');
308
+ }
523
309
  if (options.usage && result.usageByModel && Object.keys(result.usageByModel).length > 0) {
524
310
  const usagePath = path.resolve(options.usage);
525
311
  await fs.writeFile(usagePath, JSON.stringify(result.usageByModel, null, 2) + '\n', 'utf8');
@@ -537,96 +323,12 @@ program
537
323
  }
538
324
  });
539
325
  // =============================================================================
540
- // Listing Commands
326
+ // REPL Command
541
327
  // =============================================================================
542
- program
543
- .command('list-tools')
544
- .description('List all available built-in runtime tools and MCP server tools')
545
- .option('--json', 'Output as JSON')
546
- .action(async (options) => {
547
- try {
548
- const tools = await listTools(process.cwd(), { json: options.json });
549
- if (options.json) {
550
- console.log(tools);
551
- }
552
- else {
553
- console.log('Available Tools:\n');
554
- console.log(tools);
555
- }
556
- }
557
- catch (error) {
558
- console.error('❌ Error:', error.message);
559
- process.exit(1);
560
- }
561
- });
562
- program
563
- .command('list-commands')
564
- .description('List all compiled DML commands')
565
- .option('--json', 'Output as JSON')
566
- .option('--detailed', 'Show parameters and tool dependencies')
567
- .action(async (options) => {
568
- try {
569
- const commands = await listCommands(process.cwd(), {
570
- json: options.json,
571
- detailed: options.detailed
572
- });
573
- if (options.json) {
574
- console.log(JSON.stringify(commands, null, 2));
575
- }
576
- else {
577
- console.log('Compiled Commands:\n');
578
- for (const cmd of commands) {
579
- const label = cmd.displayName && cmd.displayName !== cmd.name
580
- ? `${cmd.displayName} (${cmd.name})`
581
- : cmd.name;
582
- console.log(`📋 ${label}`);
583
- console.log(` ${cmd.description}`);
584
- console.log(` Usage: ${cmd.usage}`);
585
- if (options.detailed) {
586
- if (cmd.triggerPhrases?.length) {
587
- console.log(' Trigger Phrases:');
588
- for (const phrase of cmd.triggerPhrases) {
589
- console.log(` • ${phrase}`);
590
- }
591
- }
592
- if (cmd.parameters?.length) {
593
- console.log(' Arguments:');
594
- for (const p of cmd.parameters) {
595
- const status = p.required === false
596
- ? (p.default !== undefined ? `optional, default: ${p.default}` : 'optional')
597
- : 'required';
598
- const description = p.description ? ` - ${p.description}` : '';
599
- console.log(` • ${p.name} (${status})${description}`);
600
- }
601
- }
602
- if (cmd.capabilities?.length) {
603
- console.log(' Capabilities:');
604
- for (const capability of cmd.capabilities) {
605
- console.log(` • ${capability}`);
606
- }
607
- }
608
- if (cmd.tools?.length) {
609
- console.log(' Tool Dependencies:');
610
- for (const t of cmd.tools) {
611
- console.log(` • ${t}`);
612
- }
613
- }
614
- if (cmd.model) {
615
- console.log(` Model: ${cmd.model}`);
616
- }
617
- if (cmd.compiledAt) {
618
- console.log(` Compiled: ${cmd.compiledAt}`);
619
- }
620
- }
621
- console.log('');
622
- }
623
- }
624
- }
625
- catch (error) {
626
- console.error('❌ Error:', error.message);
627
- process.exit(1);
628
- }
629
- });
328
+ registerReplCommand(program);
329
+ registerVisualizeCommand(program);
330
+ registerSetBackendCommand(program);
331
+ registerLoginCommands(program);
630
332
  // =============================================================================
631
333
  // Helper Functions
632
334
  // =============================================================================
@@ -639,45 +341,17 @@ function collectParams(value, previous) {
639
341
  }
640
342
  async function main() {
641
343
  const argv = process.argv.slice(2);
642
- const rootPrompt = readRootPrompt(argv);
643
- const rootSandbox = hasRootSandbox(argv);
644
344
  if (requiresInitializedWorkspace(argv) && !await deepClauseDirExists(process.cwd())) {
645
345
  console.warn('⚠️ No .deepclause directory found in this workspace.');
646
346
  console.warn(" Run 'deepclause init' first.");
647
347
  process.exit(1);
648
348
  }
649
- if (rootPrompt && !hasSubcommand(argv)) {
650
- await runPromptHeadless(rootPrompt, process.cwd(), { sandbox: rootSandbox });
651
- return;
652
- }
653
349
  if (argv.length === 0) {
654
- await startTui(process.cwd(), { sandbox: rootSandbox });
655
- return;
656
- }
657
- if (argv.length === 1 && rootSandbox) {
658
- await startTui(process.cwd(), { sandbox: true });
350
+ program.help();
659
351
  return;
660
352
  }
661
353
  await program.parseAsync(process.argv);
662
354
  }
663
- function hasSubcommand(argv) {
664
- return argv.some((arg) => !arg.startsWith('-') && CLI_SUBCOMMANDS.has(arg));
665
- }
666
- function readRootPrompt(argv) {
667
- for (let index = 0; index < argv.length; index++) {
668
- const arg = argv[index];
669
- if (arg === '-p' || arg === '--prompt') {
670
- return argv[index + 1];
671
- }
672
- if (arg.startsWith('--prompt=')) {
673
- return arg.slice('--prompt='.length);
674
- }
675
- }
676
- return undefined;
677
- }
678
- function hasRootSandbox(argv) {
679
- return argv.includes('--sandbox');
680
- }
681
355
  function requiresInitializedWorkspace(argv) {
682
356
  if (argv.includes('-h') || argv.includes('--help') || argv.includes('-V') || argv.includes('--version')) {
683
357
  return false;
@@ -686,7 +360,7 @@ function requiresInitializedWorkspace(argv) {
686
360
  if (!firstPositional) {
687
361
  return true;
688
362
  }
689
- return firstPositional !== 'init' && firstPositional !== 'help';
363
+ return firstPositional !== 'init' && firstPositional !== 'help' && firstPositional !== 'repl';
690
364
  }
691
365
  main().catch((error) => {
692
366
  console.error('❌ Error:', error.message);