@dharta/cli 0.6.77 → 0.6.78

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 (293) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +215 -11
  3. package/dist/agent.js +3 -2
  4. package/dist/agent.js.map +1 -1
  5. package/dist/api-error.js +6 -6
  6. package/dist/api-error.js.map +1 -1
  7. package/dist/cli.d.ts +3 -0
  8. package/dist/cli.js +860 -149
  9. package/dist/cli.js.map +1 -1
  10. package/dist/command-tree.d.ts +3 -0
  11. package/dist/command-tree.js +10 -0
  12. package/dist/command-tree.js.map +1 -0
  13. package/dist/commands/agents.d.ts +54 -17
  14. package/dist/commands/agents.js +246 -136
  15. package/dist/commands/agents.js.map +1 -1
  16. package/dist/commands/analytics.js +6 -5
  17. package/dist/commands/analytics.js.map +1 -1
  18. package/dist/commands/api.js +71 -86
  19. package/dist/commands/api.js.map +1 -1
  20. package/dist/commands/appearance.js +5 -6
  21. package/dist/commands/appearance.js.map +1 -1
  22. package/dist/commands/artifact.js +7 -6
  23. package/dist/commands/artifact.js.map +1 -1
  24. package/dist/commands/audit-log.js +2 -1
  25. package/dist/commands/audit-log.js.map +1 -1
  26. package/dist/commands/auth.js +26 -6
  27. package/dist/commands/auth.js.map +1 -1
  28. package/dist/commands/caps.js +11 -15
  29. package/dist/commands/caps.js.map +1 -1
  30. package/dist/commands/deploy.js +25 -10
  31. package/dist/commands/deploy.js.map +1 -1
  32. package/dist/commands/dev.d.ts +10 -1
  33. package/dist/commands/dev.js +56 -25
  34. package/dist/commands/dev.js.map +1 -1
  35. package/dist/commands/doctor.d.ts +2 -0
  36. package/dist/commands/doctor.js +60 -0
  37. package/dist/commands/doctor.js.map +1 -1
  38. package/dist/commands/embed-keys.js +4 -13
  39. package/dist/commands/embed-keys.js.map +1 -1
  40. package/dist/commands/env.js +4 -7
  41. package/dist/commands/env.js.map +1 -1
  42. package/dist/commands/files.js +3 -4
  43. package/dist/commands/files.js.map +1 -1
  44. package/dist/commands/fleet.d.ts +129 -0
  45. package/dist/commands/fleet.js +408 -0
  46. package/dist/commands/fleet.js.map +1 -0
  47. package/dist/commands/genui.d.ts +2 -0
  48. package/dist/commands/genui.js +53 -0
  49. package/dist/commands/genui.js.map +1 -0
  50. package/dist/commands/git-credential.js +2 -3
  51. package/dist/commands/git-credential.js.map +1 -1
  52. package/dist/commands/kartas.d.ts +9 -0
  53. package/dist/commands/kartas.js +33 -11
  54. package/dist/commands/kartas.js.map +1 -1
  55. package/dist/commands/keys.d.ts +17 -18
  56. package/dist/commands/keys.js +108 -19
  57. package/dist/commands/keys.js.map +1 -1
  58. package/dist/commands/login.js +2 -1
  59. package/dist/commands/login.js.map +1 -1
  60. package/dist/commands/members.d.ts +10 -0
  61. package/dist/commands/members.js +20 -6
  62. package/dist/commands/members.js.map +1 -1
  63. package/dist/commands/model-connections.d.ts +44 -0
  64. package/dist/commands/model-connections.js +435 -0
  65. package/dist/commands/model-connections.js.map +1 -0
  66. package/dist/commands/open.d.ts +2 -2
  67. package/dist/commands/open.js +4 -3
  68. package/dist/commands/open.js.map +1 -1
  69. package/dist/commands/org.d.ts +9 -0
  70. package/dist/commands/org.js +42 -0
  71. package/dist/commands/org.js.map +1 -0
  72. package/dist/commands/organization.d.ts +16 -0
  73. package/dist/commands/organization.js +118 -0
  74. package/dist/commands/organization.js.map +1 -0
  75. package/dist/commands/parity.js +1 -3
  76. package/dist/commands/parity.js.map +1 -1
  77. package/dist/commands/repos.d.ts +4 -0
  78. package/dist/commands/repos.js +17 -0
  79. package/dist/commands/repos.js.map +1 -0
  80. package/dist/commands/rollback.js +2 -3
  81. package/dist/commands/rollback.js.map +1 -1
  82. package/dist/commands/schedules.js +26 -21
  83. package/dist/commands/schedules.js.map +1 -1
  84. package/dist/commands/scopes.js +8 -1
  85. package/dist/commands/scopes.js.map +1 -1
  86. package/dist/commands/sessions.js +9 -3
  87. package/dist/commands/sessions.js.map +1 -1
  88. package/dist/commands/setup.js +5 -4
  89. package/dist/commands/setup.js.map +1 -1
  90. package/dist/commands/update.d.ts +1 -0
  91. package/dist/commands/update.js +24 -11
  92. package/dist/commands/update.js.map +1 -1
  93. package/dist/commands/webhooks.d.ts +4 -1
  94. package/dist/commands/webhooks.js +21 -16
  95. package/dist/commands/webhooks.js.map +1 -1
  96. package/dist/completions.js +24 -13
  97. package/dist/completions.js.map +1 -1
  98. package/dist/config.d.ts +12 -0
  99. package/dist/config.js +121 -7
  100. package/dist/config.js.map +1 -1
  101. package/dist/context.d.ts +2 -0
  102. package/dist/context.js +23 -7
  103. package/dist/context.js.map +1 -1
  104. package/dist/docs/cli-reference.d.ts +2 -0
  105. package/dist/docs/cli-reference.js +191 -0
  106. package/dist/docs/cli-reference.js.map +1 -0
  107. package/dist/exit-codes.d.ts +25 -0
  108. package/dist/exit-codes.js +107 -0
  109. package/dist/exit-codes.js.map +1 -0
  110. package/dist/genui.d.ts +178 -0
  111. package/dist/genui.js +1130 -0
  112. package/dist/genui.js.map +1 -0
  113. package/dist/harnesses.js +2 -1
  114. package/dist/harnesses.js.map +1 -1
  115. package/dist/jq.d.ts +4 -0
  116. package/dist/jq.js +91 -0
  117. package/dist/jq.js.map +1 -0
  118. package/dist/login-offer.js +6 -2
  119. package/dist/login-offer.js.map +1 -1
  120. package/dist/manifest.d.ts +12 -0
  121. package/dist/manifest.js +126 -0
  122. package/dist/manifest.js.map +1 -1
  123. package/dist/model-auth.d.ts +29 -0
  124. package/dist/model-auth.js +117 -0
  125. package/dist/model-auth.js.map +1 -0
  126. package/dist/model-settings.d.ts +23 -0
  127. package/dist/model-settings.js +186 -0
  128. package/dist/model-settings.js.map +1 -0
  129. package/dist/money.js +2 -1
  130. package/dist/money.js.map +1 -1
  131. package/dist/output.d.ts +6 -0
  132. package/dist/output.js +54 -0
  133. package/dist/output.js.map +1 -1
  134. package/dist/runtime.d.ts +1 -1
  135. package/dist/runtime.js +1 -1
  136. package/dist/scaffold.js +2 -1
  137. package/dist/scaffold.js.map +1 -1
  138. package/dist/validators.js +17 -11
  139. package/dist/validators.js.map +1 -1
  140. package/dist/version-check.d.ts +1 -1
  141. package/dist/version-check.js +1 -1
  142. package/dist/version-check.js.map +1 -1
  143. package/node_modules/@dharta/contracts/LICENSE +21 -0
  144. package/node_modules/@dharta/contracts/README.md +45 -0
  145. package/node_modules/@dharta/contracts/artifact-runtime.json +750 -0
  146. package/node_modules/@dharta/contracts/dist/activity.d.ts +62 -0
  147. package/node_modules/@dharta/contracts/dist/activity.d.ts.map +1 -0
  148. package/node_modules/@dharta/contracts/dist/activity.js +178 -0
  149. package/node_modules/@dharta/contracts/dist/activity.js.map +1 -0
  150. package/node_modules/@dharta/contracts/dist/artifact-runtime-formats.d.ts +20 -0
  151. package/node_modules/@dharta/contracts/dist/artifact-runtime-formats.d.ts.map +1 -0
  152. package/node_modules/@dharta/contracts/dist/artifact-runtime-formats.js +53 -0
  153. package/node_modules/@dharta/contracts/dist/artifact-runtime-formats.js.map +1 -0
  154. package/node_modules/@dharta/contracts/dist/artifact-runtime-validators.generated.d.ts +37 -0
  155. package/node_modules/@dharta/contracts/dist/artifact-runtime-validators.generated.d.ts.map +1 -0
  156. package/node_modules/@dharta/contracts/dist/artifact-runtime-validators.generated.js +5107 -0
  157. package/node_modules/@dharta/contracts/dist/artifact-runtime-validators.generated.js.map +1 -0
  158. package/node_modules/@dharta/contracts/dist/artifact-runtime.d.ts +154 -0
  159. package/node_modules/@dharta/contracts/dist/artifact-runtime.d.ts.map +1 -0
  160. package/node_modules/@dharta/contracts/dist/artifact-runtime.generated.d.ts +1670 -0
  161. package/node_modules/@dharta/contracts/dist/artifact-runtime.generated.d.ts.map +1 -0
  162. package/node_modules/@dharta/contracts/dist/artifact-runtime.generated.js +1903 -0
  163. package/node_modules/@dharta/contracts/dist/artifact-runtime.generated.js.map +1 -0
  164. package/node_modules/@dharta/contracts/dist/artifact-runtime.js +377 -0
  165. package/node_modules/@dharta/contracts/dist/artifact-runtime.js.map +1 -0
  166. package/node_modules/@dharta/contracts/dist/index.d.ts +6 -0
  167. package/node_modules/@dharta/contracts/dist/index.d.ts.map +1 -0
  168. package/node_modules/@dharta/contracts/dist/index.js +6 -0
  169. package/node_modules/@dharta/contracts/dist/index.js.map +1 -0
  170. package/node_modules/@dharta/contracts/dist/model-auth.d.ts +31 -0
  171. package/node_modules/@dharta/contracts/dist/model-auth.d.ts.map +1 -0
  172. package/node_modules/@dharta/contracts/dist/model-auth.js +45 -0
  173. package/node_modules/@dharta/contracts/dist/model-auth.js.map +1 -0
  174. package/node_modules/@dharta/contracts/dist/tasks.d.ts +44 -0
  175. package/node_modules/@dharta/contracts/dist/tasks.d.ts.map +1 -0
  176. package/node_modules/@dharta/contracts/dist/tasks.js +127 -0
  177. package/node_modules/@dharta/contracts/dist/tasks.js.map +1 -0
  178. package/node_modules/@dharta/contracts/dist/wire-events.d.ts +71 -0
  179. package/node_modules/@dharta/contracts/dist/wire-events.d.ts.map +1 -0
  180. package/node_modules/@dharta/contracts/dist/wire-events.js +48 -0
  181. package/node_modules/@dharta/contracts/dist/wire-events.js.map +1 -0
  182. package/node_modules/@dharta/contracts/model-auth-capabilities-v1.json +168 -0
  183. package/node_modules/@dharta/contracts/model-auth-reasons-v1.json +38 -0
  184. package/node_modules/@dharta/contracts/package.json +44 -0
  185. package/node_modules/@dharta/contracts/src/activity.ts +215 -0
  186. package/node_modules/@dharta/contracts/src/artifact-runtime-formats.ts +54 -0
  187. package/node_modules/@dharta/contracts/src/artifact-runtime-validators.generated.ts +29 -0
  188. package/node_modules/@dharta/contracts/src/artifact-runtime.generated.ts +2093 -0
  189. package/node_modules/@dharta/contracts/src/artifact-runtime.ts +520 -0
  190. package/node_modules/@dharta/contracts/src/index.ts +5 -0
  191. package/node_modules/@dharta/contracts/src/model-auth.ts +82 -0
  192. package/node_modules/@dharta/contracts/src/tasks.ts +142 -0
  193. package/node_modules/@dharta/contracts/src/wire-events.ts +150 -0
  194. package/node_modules/@dharta/contracts/wire-events.json +29 -0
  195. package/node_modules/@dharta/sdk/LICENSE +1 -1
  196. package/node_modules/@dharta/sdk/README.md +22 -8
  197. package/node_modules/@dharta/sdk/dist/errors.d.ts +9 -7
  198. package/node_modules/@dharta/sdk/dist/errors.d.ts.map +1 -1
  199. package/node_modules/@dharta/sdk/dist/errors.js +36 -18
  200. package/node_modules/@dharta/sdk/dist/errors.js.map +1 -1
  201. package/node_modules/@dharta/sdk/dist/fleet.d.ts +69 -0
  202. package/node_modules/@dharta/sdk/dist/fleet.d.ts.map +1 -0
  203. package/node_modules/@dharta/sdk/dist/fleet.js +240 -0
  204. package/node_modules/@dharta/sdk/dist/fleet.js.map +1 -0
  205. package/node_modules/@dharta/sdk/dist/http.d.ts +6 -2
  206. package/node_modules/@dharta/sdk/dist/http.d.ts.map +1 -1
  207. package/node_modules/@dharta/sdk/dist/http.js +71 -12
  208. package/node_modules/@dharta/sdk/dist/http.js.map +1 -1
  209. package/node_modules/@dharta/sdk/dist/idempotency.d.ts +12 -0
  210. package/node_modules/@dharta/sdk/dist/idempotency.d.ts.map +1 -0
  211. package/node_modules/@dharta/sdk/dist/idempotency.js +72 -0
  212. package/node_modules/@dharta/sdk/dist/idempotency.js.map +1 -0
  213. package/node_modules/@dharta/sdk/dist/index.d.ts +20 -6
  214. package/node_modules/@dharta/sdk/dist/index.d.ts.map +1 -1
  215. package/node_modules/@dharta/sdk/dist/index.js +27 -4
  216. package/node_modules/@dharta/sdk/dist/index.js.map +1 -1
  217. package/node_modules/@dharta/sdk/dist/resources.d.ts +108 -13
  218. package/node_modules/@dharta/sdk/dist/resources.d.ts.map +1 -1
  219. package/node_modules/@dharta/sdk/dist/resources.js +403 -57
  220. package/node_modules/@dharta/sdk/dist/resources.js.map +1 -1
  221. package/node_modules/@dharta/sdk/dist/types.d.ts +436 -16
  222. package/node_modules/@dharta/sdk/dist/types.d.ts.map +1 -1
  223. package/node_modules/@dharta/sdk/dist/types.js +31 -2
  224. package/node_modules/@dharta/sdk/dist/types.js.map +1 -1
  225. package/node_modules/@dharta/sdk/package.json +9 -3
  226. package/node_modules/@dharta/sdk/src/errors.ts +41 -18
  227. package/node_modules/@dharta/sdk/src/fleet.ts +339 -0
  228. package/node_modules/@dharta/sdk/src/http.ts +110 -17
  229. package/node_modules/@dharta/sdk/src/idempotency.ts +101 -0
  230. package/node_modules/@dharta/sdk/src/index.ts +50 -11
  231. package/node_modules/@dharta/sdk/src/resources.ts +549 -68
  232. package/node_modules/@dharta/sdk/src/types.ts +629 -20
  233. package/package.json +16 -6
  234. package/src/agent.ts +3 -2
  235. package/src/api-error.ts +6 -5
  236. package/src/cli.ts +978 -163
  237. package/src/command-tree.ts +13 -0
  238. package/src/commands/agents.ts +365 -167
  239. package/src/commands/analytics.ts +6 -5
  240. package/src/commands/api.ts +73 -92
  241. package/src/commands/appearance.ts +5 -6
  242. package/src/commands/artifact.ts +7 -6
  243. package/src/commands/audit-log.ts +2 -1
  244. package/src/commands/auth.ts +25 -5
  245. package/src/commands/caps.ts +11 -15
  246. package/src/commands/deploy.ts +18 -4
  247. package/src/commands/dev.ts +86 -25
  248. package/src/commands/doctor.ts +69 -0
  249. package/src/commands/embed-keys.ts +4 -14
  250. package/src/commands/env.ts +4 -7
  251. package/src/commands/files.ts +3 -4
  252. package/src/commands/fleet.ts +672 -0
  253. package/src/commands/genui.ts +59 -0
  254. package/src/commands/git-credential.ts +2 -3
  255. package/src/commands/kartas.ts +45 -11
  256. package/src/commands/keys.ts +152 -35
  257. package/src/commands/login.ts +2 -1
  258. package/src/commands/members.ts +31 -6
  259. package/src/commands/model-connections.ts +547 -0
  260. package/src/commands/open.ts +5 -4
  261. package/src/commands/org.ts +57 -0
  262. package/src/commands/organization.ts +153 -0
  263. package/src/commands/parity.ts +1 -3
  264. package/src/commands/repos.ts +23 -0
  265. package/src/commands/rollback.ts +2 -3
  266. package/src/commands/schedules.ts +33 -22
  267. package/src/commands/scopes.ts +8 -1
  268. package/src/commands/sessions.ts +9 -3
  269. package/src/commands/setup.ts +5 -4
  270. package/src/commands/update.ts +28 -12
  271. package/src/commands/webhooks.ts +30 -19
  272. package/src/completions.ts +25 -13
  273. package/src/config.ts +141 -9
  274. package/src/context.ts +34 -7
  275. package/src/docs/cli-reference.ts +206 -0
  276. package/src/exit-codes.ts +122 -0
  277. package/src/genui.ts +1398 -0
  278. package/src/harnesses.ts +2 -1
  279. package/src/jq.ts +109 -0
  280. package/src/login-offer.ts +6 -2
  281. package/src/manifest.ts +134 -0
  282. package/src/model-auth.ts +173 -0
  283. package/src/model-settings.ts +222 -0
  284. package/src/money.ts +5 -1
  285. package/src/output.ts +60 -0
  286. package/src/runtime.ts +1 -1
  287. package/src/scaffold.ts +2 -1
  288. package/src/validators.ts +18 -11
  289. package/src/version-check.ts +1 -1
  290. package/dist/commands/model-keys.d.ts +0 -22
  291. package/dist/commands/model-keys.js +0 -222
  292. package/dist/commands/model-keys.js.map +0 -1
  293. package/src/commands/model-keys.ts +0 -278
@@ -2,6 +2,12 @@
2
2
  // scripts generated statically by walking the commander program - no
3
3
  // runtime dependency, no shelling out. The output is a snapshot of this
4
4
  // CLI version's command surface; regenerate after updating.
5
+ import { visibleSubcommands } from "./command-tree.js";
6
+ // zsh looks up `_<command>` by convention and bash needs a legal shell
7
+ // identifier, so non-word characters in the binary name become underscores.
8
+ function completionFunctionName(bin) {
9
+ return `_${bin.replace(/[^A-Za-z0-9_]/g, "_")}`;
10
+ }
5
11
  export function specFromCommand(cmd) {
6
12
  return {
7
13
  name: cmd.name(),
@@ -12,9 +18,7 @@ export function specFromCommand(cmd) {
12
18
  "--help",
13
19
  ],
14
20
  argChoices: cmd.registeredArguments.flatMap((a) => a.argChoices ?? []),
15
- subs: cmd.commands
16
- .filter((c) => !c._hidden)
17
- .map((c) => specFromCommand(c)),
21
+ subs: visibleSubcommands(cmd).map((c) => specFromCommand(c)),
18
22
  };
19
23
  }
20
24
  // First sentence, single line. Shell-specific escaping happens when rendering
@@ -78,10 +82,15 @@ function escapeZshDescription(value) {
78
82
  export function bashCompletion(program) {
79
83
  const spec = specFromCommand(program);
80
84
  const entries = completionEntries(spec);
85
+ // The binary name comes from the program, never a literal: these scripts
86
+ // bound `karta` for the whole life of the renamed CLI, so `complete -F`
87
+ // attached to a command that no longer exists and completion was dead.
88
+ const bin = program.name();
89
+ const fn = completionFunctionName(bin);
81
90
  const lines = [
82
- "# bash completion for karta - generated by `dharta completion bash`",
83
- "# Load with: source <(dharta completion bash) (or append to ~/.bash_completion)",
84
- "_karta() {",
91
+ `# bash completion for ${bin} - generated by \`${bin} completion bash\``,
92
+ `# Load with: source <(${bin} completion bash) (or append to ~/.bash_completion)`,
93
+ `${fn}() {`,
85
94
  ' local cur="${COMP_WORDS[COMP_CWORD]}"',
86
95
  ' local path="${COMP_WORDS[@]:1:$((COMP_CWORD - 1))}"',
87
96
  ' local words=""',
@@ -90,18 +99,20 @@ export function bashCompletion(program) {
90
99
  for (const entry of entries) {
91
100
  lines.push(` "${escapeBashCase(entry.path)}") words="${escapeBashCase(entry.words)}" ;;`);
92
101
  }
93
- lines.push(" esac", ' COMPREPLY=( $(compgen -W "$words" -- "$cur") )', "}", "complete -F _karta karta");
102
+ lines.push(" esac", ' COMPREPLY=( $(compgen -W "$words" -- "$cur") )', "}", `complete -F ${fn} ${bin}`);
94
103
  return lines.join("\n");
95
104
  }
96
105
  export function zshCompletion(program) {
97
106
  const spec = specFromCommand(program);
98
107
  const entries = completionEntries(spec);
108
+ const bin = program.name();
109
+ const fn = completionFunctionName(bin);
99
110
  const lines = [
100
- "#compdef karta",
101
- "# zsh completion for karta - generated by `dharta completion zsh`",
102
- "# Install: dharta completion zsh > ~/.zfunc/_dharta (with fpath+=(~/.zfunc) before compinit)",
111
+ `#compdef ${bin}`,
112
+ `# zsh completion for ${bin} - generated by \`${bin} completion zsh\``,
113
+ `# Install: ${bin} completion zsh > ~/.zfunc/${fn} (with fpath+=(~/.zfunc) before compinit)`,
103
114
  "",
104
- "_karta() {",
115
+ `${fn}() {`,
105
116
  " local -a reply",
106
117
  ' local path=""',
107
118
  " if (( CURRENT > 2 )); then",
@@ -111,10 +122,10 @@ export function zshCompletion(program) {
111
122
  ];
112
123
  for (const entry of entries) {
113
124
  lines.push(` ${zshCasePattern(entry.path)})`, entry.describedCommands
114
- ? ` reply=( ${entry.describedCommands} ); _describe -t commands 'dharta command' reply`
125
+ ? ` reply=( ${entry.describedCommands} ); _describe -t commands '${bin} command' reply`
115
126
  : " true", entry.words ? ` compadd -- ${entry.words}` : " true", " return", " ;;");
116
127
  }
117
- lines.push(" esac", "}", "", '_karta "$@"');
128
+ lines.push(" esac", "}", "", `${fn} "$@"`);
118
129
  return lines.join("\n");
119
130
  }
120
131
  //# sourceMappingURL=completions.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"completions.js","sourceRoot":"","sources":["../src/completions.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,qEAAqE;AACrE,wEAAwE;AACxE,4DAA4D;AAgB5D,MAAM,UAAU,eAAe,CAAC,GAAY;IAC1C,OAAO;QACL,IAAI,EAAE,GAAG,CAAC,IAAI,EAAE;QAChB,OAAO,EAAE,cAAc,CAAC,GAAG,CAAC;QAC5B,WAAW,EAAE,QAAQ,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC;QACxC,OAAO,EAAE;YACP,GAAG,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,MAAM,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,CAAC,IAAc,CAAC;YAC9F,QAAQ;SACT;QACD,UAAU,EAAE,GAAG,CAAC,mBAAmB,CAAC,OAAO,CAAC,CAAC,CAAW,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,IAAI,EAAE,CAAC;QAChF,IAAI,EAAE,GAAG,CAAC,QAAQ;aACf,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAE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AAC,CAAC;IACtC,MAAM,OAAO,GAAG,iBAAiB,CAAC,IAAI,CAAC,CAAC;IACxC,MAAM,GAAG,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;IAC3B,MAAM,EAAE,GAAG,sBAAsB,CAAC,GAAG,CAAC,CAAC;IAEvC,MAAM,KAAK,GAAa;QACtB,YAAY,GAAG,EAAE;QACjB,wBAAwB,GAAG,qBAAqB,GAAG,mBAAmB;QACtE,cAAc,GAAG,8BAA8B,EAAE,4CAA4C;QAC7F,EAAE;QACF,GAAG,EAAE,MAAM;QACX,kBAAkB;QAClB,iBAAiB;QACjB,8BAA8B;QAC9B,+CAA+C;QAC/C,MAAM;QACN,mBAAmB;KACpB,CAAC;IACF,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;QAC5B,KAAK,CAAC,IAAI,CACR,OAAO,cAAc,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EACpC,KAAK,CAAC,iBAAiB;YACrB,CAAC,CAAC,iBAAiB,KAAK,CAAC,iBAAiB,8BAA8B,GAAG,iBAAiB;YAC5F,CAAC,CAAC,YAAY,EAChB,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,oBAAoB,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,YAAY,EAC9D,cAAc,EACd,UAAU,CACX,CAAC;IACJ,CAAC;IACD,KAAK,CAAC,IAAI,CAAC,QAAQ,EAAE,GAAG,EAAE,EAAE,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC;IAC5C,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC"}
package/dist/config.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import { MAX_IDEMPOTENCY_KEY_LENGTH } from "@dharta/sdk";
2
+ import { CliUsageError } from "./exit-codes.js";
1
3
  export interface Profile {
2
4
  api_key: string;
3
5
  base_url: string;
@@ -9,6 +11,15 @@ export interface Config {
9
11
  profiles: Record<string, Profile>;
10
12
  }
11
13
  export declare function setHomeForTesting(home: string | undefined): void;
14
+ export declare function setRequestedProfile(name: string | undefined): void;
15
+ export declare const MAX_OPERATION_SUFFIX_LENGTH = 55;
16
+ export { MAX_IDEMPOTENCY_KEY_LENGTH };
17
+ export declare const MAX_ROOT_IDEMPOTENCY_KEY_LENGTH: number;
18
+ export declare function setRequestedIdempotencyKey(key: string | undefined): void;
19
+ export declare function requestedIdempotencyKeyValue(): string | undefined;
20
+ export declare function mintIdempotencyKey(operation: string): string;
21
+ export declare function explicitProfileName(): string | undefined;
22
+ export declare function requestedProfileName(): string | undefined;
12
23
  export declare function configPath(): string;
13
24
  declare const DEFAULT_BASE_URL = "https://dharta.ai";
14
25
  declare const DEFAULT_GIT_BASE_URL = "https://git.dharta.ai";
@@ -16,5 +27,6 @@ export declare function loadConfig(): Promise<Config | null>;
16
27
  export declare function saveProfile(name: string, profile: Profile): Promise<string>;
17
28
  export declare function removeProfile(name: string): Promise<boolean>;
18
29
  export declare function activeProfile(): Promise<Profile>;
30
+ export declare function profileNotFoundError(name: string): CliUsageError;
19
31
  export declare function resolveBaseUrl(): Promise<string>;
20
32
  export { DEFAULT_BASE_URL, DEFAULT_GIT_BASE_URL };
package/dist/config.js CHANGED
@@ -1,12 +1,109 @@
1
+ import { randomUUID } from "node:crypto";
1
2
  import { promises as fs } from "node:fs";
2
3
  import { homedir } from "node:os";
3
4
  import * as path from "node:path";
4
5
  import TOML from "@iarna/toml";
6
+ import { assertIdempotencyKey, MAX_IDEMPOTENCY_KEY_LENGTH } from "@dharta/sdk";
7
+ import { CliUsageError } from "./exit-codes.js";
8
+ import { normalizeNonBlank } from "./validators.js";
5
9
  // Allow tests to redirect HOME without setting process.env.HOME globally.
6
10
  let homeOverride;
7
11
  export function setHomeForTesting(home) {
8
12
  homeOverride = home;
9
13
  }
14
+ // The profile named by the global `--profile` flag, recorded once per run by
15
+ // the root preAction hook in cli.ts. Resolution order for every command is:
16
+ // explicit --profile, then DHARTA_PROFILE, then the config's default_profile
17
+ // (the aws --profile shape, RFC 0048 D2).
18
+ let requestedProfile;
19
+ export function setRequestedProfile(name) {
20
+ requestedProfile = name === undefined ? undefined : normalizeNonBlank(name, "--profile");
21
+ }
22
+ // The Idempotency-Key named by the global `--idempotency-key` flag, recorded
23
+ // once per run by the same preAction hook. It rides here rather than in each
24
+ // command because it is a property of the RUN, not of one call: a CI job that
25
+ // reruns after an ambiguous failure has to present the key the first run used,
26
+ // and every curated command mints a fresh one per process otherwise.
27
+ //
28
+ // What a key may contain is the SDK's rule (`assertIdempotencyKey`), written
29
+ // down once in sdks/typescript/src/idempotency.ts and enforced by the client on
30
+ // every key it is handed. The CLI checks it here as well, so a bad flag value is
31
+ // a usage error before any request goes out rather than a failure part way
32
+ // through a run.
33
+ // A command that performs more than one mutation cannot send the root key on
34
+ // both: the server binds a key to the first request it saw and answers the
35
+ // second with a 422. Such a command derives one key per operation instead (see
36
+ // mintIdempotencyKey), which keeps the writes apart from each other and stable
37
+ // across reruns. The cap applies to the WHOLE header value, so the root has to
38
+ // leave room for the longest suffix we append.
39
+ export const MAX_OPERATION_SUFFIX_LENGTH = 55;
40
+ export { MAX_IDEMPOTENCY_KEY_LENGTH };
41
+ export const MAX_ROOT_IDEMPOTENCY_KEY_LENGTH = MAX_IDEMPOTENCY_KEY_LENGTH - MAX_OPERATION_SUFFIX_LENGTH;
42
+ let requestedIdempotencyKey;
43
+ export function setRequestedIdempotencyKey(key) {
44
+ if (key === undefined) {
45
+ requestedIdempotencyKey = undefined;
46
+ return;
47
+ }
48
+ const normalized = normalizeNonBlank(key, "--idempotency-key");
49
+ try {
50
+ assertIdempotencyKey(normalized, "--idempotency-key");
51
+ }
52
+ catch (error) {
53
+ // The SDK owns what a key may contain; the CLI owns what a rejected flag
54
+ // value exits with. Re-wrapping keeps both true and keeps the wording in
55
+ // one place.
56
+ throw new CliUsageError(error.message);
57
+ }
58
+ if (normalized.length > MAX_ROOT_IDEMPOTENCY_KEY_LENGTH) {
59
+ throw new CliUsageError(`--idempotency-key must be at most ${MAX_ROOT_IDEMPOTENCY_KEY_LENGTH} characters. ` +
60
+ `The server accepts ${MAX_IDEMPOTENCY_KEY_LENGTH}; the difference is reserved for the ` +
61
+ "per-operation suffix a multi-mutation command appends.");
62
+ }
63
+ requestedIdempotencyKey = normalized;
64
+ }
65
+ export function requestedIdempotencyKeyValue() {
66
+ return requestedIdempotencyKey;
67
+ }
68
+ // Dotted lowercase, so a derived key reads as `<root>.sessions.turn.2` and the
69
+ // operation cannot smuggle in whitespace or a separator of its own.
70
+ const IDEMPOTENCY_OPERATION_PATTERN = /^[a-z0-9]+(?:[.-][a-z0-9]+)*$/;
71
+ // The Idempotency-Key for ONE mutation. With no root key this is a fresh UUID,
72
+ // which is what every command did before the flag existed. With a root key it
73
+ // is `<root>.<operation>`: two mutations in the same run get different keys, and
74
+ // the same mutation in a later run with the same root gets the same key, which
75
+ // is what makes the rerun replay instead of repeating the work.
76
+ //
77
+ // `operation` is written by us, never by the caller, so a bad one is a
78
+ // programming error and throws a plain Error (exit 1), not a usage error.
79
+ export function mintIdempotencyKey(operation) {
80
+ if (!IDEMPOTENCY_OPERATION_PATTERN.test(operation)) {
81
+ throw new Error(`Idempotency operation ${JSON.stringify(operation)} is not a dotted lowercase token.`);
82
+ }
83
+ const suffix = `.${operation}`;
84
+ if (suffix.length > MAX_OPERATION_SUFFIX_LENGTH) {
85
+ throw new Error(`Idempotency operation ${JSON.stringify(operation)} exceeds the ` +
86
+ `${MAX_OPERATION_SUFFIX_LENGTH}-character reserve.`);
87
+ }
88
+ return requestedIdempotencyKey === undefined
89
+ ? randomUUID()
90
+ : `${requestedIdempotencyKey}${suffix}`;
91
+ }
92
+ // The profile named by the flag alone, ignoring DHARTA_PROFILE. An explicit
93
+ // flag is a deliberate act and outranks an ambient credential in the
94
+ // environment; the env var does not.
95
+ export function explicitProfileName() {
96
+ return requestedProfile;
97
+ }
98
+ // The explicitly requested profile, or undefined to mean "the default one".
99
+ // Commands that operate ON a profile (login, auth logout) read this rather
100
+ // than the resolved name, so omitting the flag keeps their existing meaning.
101
+ export function requestedProfileName() {
102
+ if (requestedProfile !== undefined)
103
+ return requestedProfile;
104
+ const fromEnv = process.env.DHARTA_PROFILE?.trim();
105
+ return fromEnv ? fromEnv : undefined;
106
+ }
10
107
  export function configPath() {
11
108
  const home = homeOverride ?? process.env.HOME ?? homedir();
12
109
  return path.join(home, ".dharta", "config.toml");
@@ -67,13 +164,17 @@ export async function removeProfile(name) {
67
164
  }
68
165
  export async function activeProfile() {
69
166
  const cfg = await loadConfig();
167
+ const requested = requestedProfileName();
70
168
  if (!cfg) {
71
- throw new Error("Not logged in. Run `dharta login` to store an API key in ~/.dharta/config.toml.");
169
+ throw new Error(`Not logged in. Run \`dharta login${requested ? ` --profile ${requested}` : ""}\` ` +
170
+ "to store an API key in ~/.dharta/config.toml.");
72
171
  }
73
- const profile = cfg.profiles[cfg.default_profile];
172
+ const name = requested ?? cfg.default_profile;
173
+ const profile = cfg.profiles[name];
74
174
  if (!profile) {
75
- throw new Error(`Default profile '${cfg.default_profile}' not found in ${configPath()}. ` +
76
- "Run `dharta login` to recreate it.");
175
+ throw requested
176
+ ? profileNotFoundError(name)
177
+ : new CliUsageError(`Default profile '${name}' not found in ${configPath()}. Run \`dharta login\` to recreate it.`);
77
178
  }
78
179
  return {
79
180
  api_key: profile.api_key,
@@ -82,15 +183,28 @@ export async function activeProfile() {
82
183
  workspace_git_base_url: profile.workspace_git_base_url,
83
184
  };
84
185
  }
186
+ // One message for "you named a profile that is not stored", shared by
187
+ // activeProfile, `auth token`, and `auth logout` so the three agree on what
188
+ // happened and on the exit code (2, a usage error).
189
+ export function profileNotFoundError(name) {
190
+ return new CliUsageError(`Profile '${name}' not found in ${configPath()}. ` +
191
+ `Run \`dharta login --profile ${name}\` to create it, or \`dharta auth status\` to list profiles.`);
192
+ }
85
193
  // Base URL for commands that work without a credential (init's template
86
- // fetch): env override, then the stored profile, then the default.
194
+ // fetch): env override, then the stored profile, then the default. An explicit
195
+ // --profile pins the host to that profile, the same rule buildContext applies.
87
196
  export async function resolveBaseUrl() {
88
- if (process.env.DHARTA_BASE_URL)
197
+ const pinnedToProfile = explicitProfileName() !== undefined;
198
+ if (process.env.DHARTA_BASE_URL && !pinnedToProfile)
89
199
  return process.env.DHARTA_BASE_URL;
90
200
  try {
91
201
  return (await activeProfile()).base_url;
92
202
  }
93
- catch {
203
+ catch (err) {
204
+ // A profile the user named and that does not exist is their mistake, not a
205
+ // missing credential: say so instead of quietly using the default host.
206
+ if (pinnedToProfile)
207
+ throw err;
94
208
  return DEFAULT_BASE_URL;
95
209
  }
96
210
  }
@@ -1 +1 @@
1
- {"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,IAAI,MAAM,aAAa,CAAC;AA6B/B,0EAA0E;AAC1E,IAAI,YAAgC,CAAC;AAErC,MAAM,UAAU,iBAAiB,CAAC,IAAwB;IACxD,YAAY,GAAG,IAAI,CAAC;AACtB,CAAC;AAED,MAAM,UAAU,UAAU;IACxB,MAAM,IAAI,GAAG,YAAY,IAAI,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,OAAO,EAAE,CAAC;IAC3D,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,SAAS,EAAE,aAAa,CAAC,CAAC;AACnD,CAAC;AAED,wEAAwE;AACxE,oEAAoE;AACpE,0BAA0B;AAC1B,MAAM,gBAAgB,GAAG,mBAAmB,CAAC;AAC7C,MAAM,oBAAoB,GAAG,uBAAuB,CAAC;AAErD,MAAM,CAAC,KAAK,UAAU,UAAU;IAC9B,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,UAAU,EAAE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AAC,CAAC,QAAQ,CAAC;IAC1C,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,2EAA2E;QAC3E,wEAAwE;QACxE,IAAI,eAAe;YAAE,MAAM,GAAG,CAAC;QAC/B,OAAO,gBAAgB,CAAC;IAC1B,CAAC;AACH,CAAC;AAED,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,CAAC"}
package/dist/context.d.ts CHANGED
@@ -5,10 +5,12 @@ export interface CliContext {
5
5
  baseUrl: string;
6
6
  apiKey: string;
7
7
  fetch?: typeof fetch;
8
+ idempotencyKey?: string;
8
9
  }
9
10
  export interface CtxOverrides {
10
11
  apiKey?: string;
11
12
  baseUrl?: string;
12
13
  fetch?: typeof fetch;
14
+ idempotencyKey?: string;
13
15
  }
14
16
  export declare function buildContext(over?: CtxOverrides): Promise<CliContext>;
package/dist/context.js CHANGED
@@ -1,14 +1,21 @@
1
1
  import { Dharta, HttpClient } from "@dharta/sdk";
2
- import { activeProfile, DEFAULT_BASE_URL } from "./config.js";
2
+ import { activeProfile, explicitProfileName, requestedIdempotencyKeyValue, DEFAULT_BASE_URL, } from "./config.js";
3
3
  import { cliFormatError, cliFormatNetworkError } from "./api-error.js";
4
4
  export async function buildContext(over = {}) {
5
5
  let apiKey = over.apiKey;
6
6
  let baseUrl = over.baseUrl;
7
- // Env overrides config everywhere (the GH_TOKEN pattern, RFC 0013
8
- // §2); explicit per-call overrides beat both. DHARTA_BASE_URL applies
9
- // regardless of where the key came from, matching resolveBaseUrl.
10
- baseUrl = baseUrl ?? process.env.DHARTA_BASE_URL;
11
- if (!apiKey && process.env.DHARTA_API_KEY) {
7
+ // An explicit `--profile` outranks BOTH ambient settings: the key and the
8
+ // host are one credential. Without this, a shell that exports a key would
9
+ // silently send `--profile staging` at whatever org that key belongs to, and
10
+ // an exported DHARTA_BASE_URL would send the profile's key to a host it was
11
+ // never issued for. DHARTA_PROFILE does NOT get this treatment: two ambient
12
+ // settings, and the environment still wins.
13
+ const pinnedToProfile = explicitProfileName() !== undefined;
14
+ // Env overrides config everywhere (the GH_TOKEN pattern, RFC 0013 §2);
15
+ // explicit per-call overrides beat both.
16
+ if (!pinnedToProfile)
17
+ baseUrl = baseUrl ?? process.env.DHARTA_BASE_URL;
18
+ if (!apiKey && process.env.DHARTA_API_KEY && !pinnedToProfile) {
12
19
  apiKey = process.env.DHARTA_API_KEY;
13
20
  }
14
21
  if (!apiKey) {
@@ -19,12 +26,20 @@ export async function buildContext(over = {}) {
19
26
  if (!baseUrl)
20
27
  baseUrl = DEFAULT_BASE_URL;
21
28
  const fetchImpl = over.fetch;
29
+ // The global `--idempotency-key`, applied once here rather than threaded
30
+ // through every curated command. The client sends it on every request that
31
+ // does not name a key of its own, which is what makes a CI rerun after an
32
+ // ambiguous failure replay the first response instead of performing the
33
+ // mutation a second time. A command that writes more than once names a
34
+ // derived key per write, and those survive.
35
+ const idempotencyKey = over.idempotencyKey ?? requestedIdempotencyKeyValue();
22
36
  const sdk = new Dharta({
23
37
  apiKey,
24
38
  baseUrl,
25
39
  fetch: fetchImpl,
26
40
  formatError: cliFormatError,
27
41
  formatNetworkError: cliFormatNetworkError,
42
+ idempotencyKey,
28
43
  });
29
44
  const http = new HttpClient({
30
45
  apiKey,
@@ -32,7 +47,8 @@ export async function buildContext(over = {}) {
32
47
  fetch: fetchImpl,
33
48
  formatError: cliFormatError,
34
49
  formatNetworkError: cliFormatNetworkError,
50
+ idempotencyKey,
35
51
  });
36
- return { sdk, http, baseUrl, apiKey, fetch: fetchImpl };
52
+ return { sdk, http, baseUrl, apiKey, fetch: fetchImpl, idempotencyKey };
37
53
  }
38
54
  //# sourceMappingURL=context.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC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,GAAG,IAAI,CAAC,cAAc,IAAI,4BAA4B,EAAE,CAAC;IAC7E,MAAM,GAAG,GAAG,IAAI,MAAM,CAAC;QACrB,MAAM;QACN,OAAO;QACP,KAAK,EAAE,SAAS;QAChB,WAAW,EAAE,cAAc;QAC3B,kBAAkB,EAAE,qBAAqB;QACzC,cAAc;KACf,CAAC,CAAC;IACH,MAAM,IAAI,GAAG,IAAI,UAAU,CAAC;QAC1B,MAAM;QACN,OAAO;QACP,KAAK,EAAE,SAAS;QAChB,WAAW,EAAE,cAAc;QAC3B,kBAAkB,EAAE,qBAAqB;QACzC,cAAc;KACf,CAAC,CAAC;IACH,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,CAAC;AAC1E,CAAC"}
@@ -0,0 +1,2 @@
1
+ import type { Command } from "commander";
2
+ export declare function renderCliReference(program: Command): string;
@@ -0,0 +1,191 @@
1
+ // The public CLI reference (apps/docs-site/cli/reference.mdx) is generated from
2
+ // the command tree, not written by hand (RFC 0048 P5). A hand-maintained page
3
+ // is a second copy of the command surface, and the old one had drifted: it
4
+ // never listed `files` or `artifact`, and it still told readers to run
5
+ // `karta --help`.
6
+ //
7
+ // `npm run docs:cli` rewrites the page. A vitest gate renders the same text in
8
+ // memory and fails when the committed file differs, so a new command cannot
9
+ // ship undocumented.
10
+ import { visibleSubcommands } from "../command-tree.js";
11
+ // Flags registered on every node by cli.ts. They belong in one section, not in
12
+ // every row of every table.
13
+ const GLOBAL_FLAGS = new Set([
14
+ "--json",
15
+ "--jq",
16
+ "--profile",
17
+ "--idempotency-key",
18
+ "--help",
19
+ "--version",
20
+ ]);
21
+ const FRONT_MATTER = `---
22
+ title: CLI command reference
23
+ sidebarTitle: Command reference
24
+ description: "Every dharta CLI command, grouped the way \`dharta --help\` groups them, with arguments, options, global flags, and exit codes."
25
+ ---`;
26
+ const INTRO = `{/* Generated by \`npm run docs:cli\` in sdks/typescript-cli. Do not edit by hand. */}
27
+
28
+ The fastest local reference is always:
29
+
30
+ \`\`\`bash
31
+ dharta --help
32
+ dharta <command> --help
33
+ \`\`\`
34
+
35
+ The groups below are the groups \`dharta --help\` prints. Commands that take a
36
+ positional agent slug infer it from the current folder when you leave it out.`;
37
+ const GLOBAL_FLAGS_SECTION = `## Global flags
38
+
39
+ These work on every command, wherever you put them on the line.
40
+
41
+ | Flag | Purpose |
42
+ | --- | --- |
43
+ | \`--json\` | Print the result as JSON on stdout. Progress narration goes to stderr, so stdout stays parseable. Stream commands (\`dev\`, \`logs\`, \`completion\`, and git-mode \`deploy\`) reject it instead of ignoring it. |
44
+ | \`--jq <expr>\` | Filter the JSON result through a built-in jq. Implies \`--json\`. Each result prints on its own line, compact; a result that is a string prints without quotes, so \`--jq .name\` pipes cleanly. A filter that matches nothing prints nothing. Rejected wherever \`--json\` is rejected. |
45
+ | \`--profile <name>\` | Use a named profile from \`~/.dharta/config.toml\`. Resolution order is \`--profile\`, then \`DHARTA_PROFILE\`, then the config's default profile. \`dharta login --profile <name>\` creates one; \`dharta auth logout --profile <name>\` removes it. |
46
+ | \`--idempotency-key <key>\` | Send this \`Idempotency-Key\` on every request the command makes, instead of the fresh one each mutation mints. Give a CI job a key it can reuse and a rerun after an ambiguous failure replays the first response, including a secret that is otherwise shown once. Printable ASCII with no spaces, at most 200 characters; the SDK enforces the same shape on every key it is handed, up to the API's 255. |
47
+
48
+ ### Reusing an idempotency key
49
+
50
+ A mutation that times out may or may not have been performed, and without a key
51
+ you have no way to find out but to look. Every \`dharta\` mutation mints a fresh
52
+ key per process, which protects one run from itself but cannot help a second
53
+ run: to the platform, the retry is a new request.
54
+
55
+ Pin the key to the job, not to the process:
56
+
57
+ \`\`\`bash
58
+ dharta keys create ci-release --scope releases:write \\
59
+ --idempotency-key "release-$GITHUB_RUN_ID"
60
+ \`\`\`
61
+
62
+ Rerun that step with the same \`GITHUB_RUN_ID\` and you get the first run's
63
+ response back, secret included, instead of a second key.
64
+
65
+ Four rules come with it:
66
+
67
+ - **One key per command.** The platform binds a key to the request it first saw
68
+ and answers a different request under the same key with \`422\`. Two commands
69
+ sharing one key collide, so give each mutating step its own.
70
+ - **A command that writes more than once splits the key for you.** \`dharta
71
+ send\` opens a session and then runs a turn; \`dharta schedules create
72
+ --run-now\` creates a schedule and then queues a run of it; \`dharta dev\`
73
+ runs a turn per prompt. Each write gets a suffix naming its operation, so the
74
+ wire carries \`<key>.sessions.create\` and \`<key>.sessions.turn\`, or
75
+ \`<key>.schedules.create\` and \`<key>.schedules.run\`. The writes never
76
+ collide with each other, and a rerun under the same key replays every one of
77
+ them instead of opening a second session, creating a second schedule, or
78
+ paying for a second inference. That is why the key is capped at 200 rather
79
+ than the platform's 255 - the rest is reserved for the suffix. A command that
80
+ writes once sends your key exactly as you typed it.
81
+ - **Retry \`5xx\` and \`429\` with the same key.** Those answers are never
82
+ stored, so reusing the key re-drives the work rather than replaying a failure.
83
+ - **A command with nothing to protect refuses the flag.** \`dharta login\`,
84
+ \`create\`, \`setup\`, \`genui\`, \`artifact\`, \`doctor\`,
85
+ \`update\`, \`completion\`, \`auth token\` and \`auth logout\` perform
86
+ no mutation the key could cover. Some of them do call Dharta - \`login\`
87
+ reads \`/me\`, \`create\` fetches the template list - but none of them
88
+ writes. Passing the key there exits 2 rather than being quietly dropped.
89
+ Read-only commands do accept it, because they are steps in a run that writes
90
+ and the header is ignored server-side.
91
+
92
+ ## Exit codes
93
+
94
+ Scripts can branch on the exit code instead of parsing messages.
95
+
96
+ | Code | Meaning |
97
+ | --- | --- |
98
+ | 0 | Success. |
99
+ | 1 | General failure. |
100
+ | 2 | Usage error: an unknown flag, a bad value, a missing argument, or an unknown profile. |
101
+ | 3 | Not authenticated. No credential is stored, or the API answered 401. |
102
+ | 4 | Forbidden. The API answered 403, usually a missing scope on the key. |
103
+ | 5 | Not found. The API answered 404. |
104
+ | 6 | Validation failure. The API answered 409 or 422. |
105
+ | 7 | The API host could not be reached. |
106
+
107
+ \`dharta doctor\` is the exception: it exits 1 when a local check fails, which is
108
+ a report, not an error.`;
109
+ export function renderCliReference(program) {
110
+ const sections = groupCommands(program).map(([group, commands]) => renderGroup(group, commands));
111
+ return [FRONT_MATTER, "", INTRO, "", ...sections, GLOBAL_FLAGS_SECTION, ""].join("\n");
112
+ }
113
+ // Group heading -> the top-level commands in it, in tree order. Commander
114
+ // stores the heading with a trailing colon ("Management:"); the page uses it as
115
+ // a title, so the colon comes off.
116
+ function groupCommands(program) {
117
+ const groups = new Map();
118
+ for (const cmd of visibleSubcommands(program)) {
119
+ const heading = cmd.helpGroup().replace(/:$/, "");
120
+ if (!heading) {
121
+ throw new Error(`\`dharta ${cmd.name()}\` has no help group, so it has nowhere to go in the reference.`);
122
+ }
123
+ const bucket = groups.get(heading);
124
+ if (bucket)
125
+ bucket.push(cmd);
126
+ else
127
+ groups.set(heading, [cmd]);
128
+ }
129
+ return [...groups.entries()];
130
+ }
131
+ function renderGroup(heading, commands) {
132
+ const rows = commands.flatMap((cmd) => flatten(cmd)).map(renderRow);
133
+ return [
134
+ `## ${heading}`,
135
+ "",
136
+ "| Command | Arguments | Options | Description |",
137
+ "| --- | --- | --- | --- |",
138
+ ...rows,
139
+ "",
140
+ ].join("\n");
141
+ }
142
+ function flatten(cmd) {
143
+ return [cmd, ...visibleSubcommands(cmd).flatMap(flatten)];
144
+ }
145
+ function renderRow(cmd) {
146
+ return `| ${code(commandPath(cmd))} | ${code(argumentList(cmd))} | ${optionList(cmd)} | ${prose(cmd.description())} |`;
147
+ }
148
+ // `dharta send|run`, matching how commander prints an aliased command.
149
+ function commandPath(cmd) {
150
+ const names = [];
151
+ let cursor = cmd;
152
+ while (cursor) {
153
+ const aliases = cursor.aliases();
154
+ names.unshift(cursor === cmd && aliases.length > 0 ? [cursor.name(), ...aliases].join("|") : cursor.name());
155
+ cursor = cursor.parent;
156
+ }
157
+ return names.join(" ");
158
+ }
159
+ function argumentList(cmd) {
160
+ return cmd.registeredArguments
161
+ .map((arg) => {
162
+ const name = `${arg.name()}${arg.variadic ? "..." : ""}`;
163
+ return arg.required ? `<${name}>` : `[${name}]`;
164
+ })
165
+ .join(" ");
166
+ }
167
+ function optionList(cmd) {
168
+ const flags = cmd.options
169
+ .filter((option) => !option.hidden && !GLOBAL_FLAGS.has(option.long ?? ""))
170
+ .map((option) => code(option.flags));
171
+ return flags.length > 0 ? flags.join(", ") : escapePipes("Global flags only");
172
+ }
173
+ function code(text) {
174
+ return text ? `\`${escapePipes(text)}\`` : "";
175
+ }
176
+ function prose(text) {
177
+ const collapsed = text.replace(/\s+/g, " ").trim();
178
+ // MDX parses `<` as JSX and `{` as an expression, but not inside an inline
179
+ // code span - and escaping inside one would print the entity. Split on code
180
+ // spans and escape only the prose between them.
181
+ const escaped = collapsed
182
+ .split(/(`[^`]*`)/)
183
+ .map((part) => (part.startsWith("`") ? part : part.replace(/</g, "&lt;").replace(/\{/g, "&#123;")))
184
+ .join("");
185
+ return escapePipes(escaped);
186
+ }
187
+ // A bare `|` would end the table cell, including inside a code span.
188
+ function escapePipes(text) {
189
+ return text.replace(/\|/g, "\\|");
190
+ }
191
+ //# sourceMappingURL=cli-reference.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli-reference.js","sourceRoot":"","sources":["../../src/docs/cli-reference.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,8EAA8E;AAC9E,2EAA2E;AAC3E,uEAAuE;AACvE,kBAAkB;AAClB,EAAE;AACF,+EAA+E;AAC/E,4EAA4E;AAC5E,qBAAqB;AAIrB,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAExD,+EAA+E;AAC/E,4BAA4B;AAC5B,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC;IAC3B,QAAQ;IACR,MAAM;IACN,WAAW;IACX,mBAAmB;IACnB,QAAQ;IACR,WAAW;CACZ,CAAC,CAAC;AAEH,MAAM,YAAY,GAAG;;;;IAIjB,CAAC;AAEL,MAAM,KAA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AAC;IACnD,2EAA2E;IAC3E,4EAA4E;IAC5E,gDAAgD;IAChD,MAAM,OAAO,GAAG,SAAS;SACtB,KAAK,CAAC,WAAW,CAAC;SAClB,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC;SAClG,IAAI,CAAC,EAAE,CAAC,CAAC;IACZ,OAAO,WAAW,CAAC,OAAO,CAAC,CAAC;AAC9B,CAAC;AAED,qEAAqE;AACrE,SAAS,WAAW,CAAC,IAAY;IAC/B,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;AACpC,CAAC"}
@@ -0,0 +1,25 @@
1
+ export declare const EXIT_SUCCESS = 0;
2
+ export declare const EXIT_GENERAL = 1;
3
+ export declare const EXIT_USAGE = 2;
4
+ export declare const EXIT_NOT_AUTHENTICATED = 3;
5
+ export declare const EXIT_FORBIDDEN = 4;
6
+ export declare const EXIT_NOT_FOUND = 5;
7
+ export declare const EXIT_VALIDATION = 6;
8
+ export declare const EXIT_NETWORK = 7;
9
+ export declare class CliUsageError extends Error {
10
+ constructor(message: string);
11
+ }
12
+ export declare class CliApiError extends Error {
13
+ readonly status: number;
14
+ readonly body: unknown;
15
+ constructor(message: string, status: number, body: unknown);
16
+ }
17
+ export declare class CliNetworkError extends Error {
18
+ readonly url: string;
19
+ constructor(message: string, url: string);
20
+ }
21
+ export declare function isCommanderError(err: unknown): boolean;
22
+ export declare function exitCodeForError(err: unknown): number;
23
+ export declare function isInvalidIdempotencyKeyError(err: unknown): boolean;
24
+ export declare function isNotAuthenticatedError(err: unknown): boolean;
25
+ export declare function exitCodeForStatus(status: number): number;