@makine/cli 0.1.4

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 (50) hide show
  1. package/LICENSE +34 -0
  2. package/dist/index.d.ts +63 -0
  3. package/dist/index.d.ts.map +1 -0
  4. package/dist/index.js +380 -0
  5. package/dist/index.js.map +1 -0
  6. package/dist/main.d.ts +3 -0
  7. package/dist/main.d.ts.map +1 -0
  8. package/dist/main.js +31 -0
  9. package/dist/main.js.map +1 -0
  10. package/dist/migrate/command.d.ts +39 -0
  11. package/dist/migrate/command.d.ts.map +1 -0
  12. package/dist/migrate/command.js +257 -0
  13. package/dist/migrate/command.js.map +1 -0
  14. package/dist/migrate/credentials.d.ts +29 -0
  15. package/dist/migrate/credentials.d.ts.map +1 -0
  16. package/dist/migrate/credentials.js +56 -0
  17. package/dist/migrate/credentials.js.map +1 -0
  18. package/dist/migrate/litellm.d.ts +13 -0
  19. package/dist/migrate/litellm.d.ts.map +1 -0
  20. package/dist/migrate/litellm.js +454 -0
  21. package/dist/migrate/litellm.js.map +1 -0
  22. package/dist/migrate/nodes.d.ts +7 -0
  23. package/dist/migrate/nodes.d.ts.map +1 -0
  24. package/dist/migrate/nodes.js +17 -0
  25. package/dist/migrate/nodes.js.map +1 -0
  26. package/dist/migrate/paths.d.ts +17 -0
  27. package/dist/migrate/paths.d.ts.map +1 -0
  28. package/dist/migrate/paths.js +94 -0
  29. package/dist/migrate/paths.js.map +1 -0
  30. package/dist/migrate/portkey.d.ts +22 -0
  31. package/dist/migrate/portkey.d.ts.map +1 -0
  32. package/dist/migrate/portkey.js +371 -0
  33. package/dist/migrate/portkey.js.map +1 -0
  34. package/dist/migrate/render.d.ts +22 -0
  35. package/dist/migrate/render.d.ts.map +1 -0
  36. package/dist/migrate/render.js +124 -0
  37. package/dist/migrate/render.js.map +1 -0
  38. package/dist/migrate/runtime-rules.d.ts +55 -0
  39. package/dist/migrate/runtime-rules.d.ts.map +1 -0
  40. package/dist/migrate/runtime-rules.js +203 -0
  41. package/dist/migrate/runtime-rules.js.map +1 -0
  42. package/dist/migrate/translate.d.ts +96 -0
  43. package/dist/migrate/translate.d.ts.map +1 -0
  44. package/dist/migrate/translate.js +305 -0
  45. package/dist/migrate/translate.js.map +1 -0
  46. package/dist/migrate/types.d.ts +63 -0
  47. package/dist/migrate/types.d.ts.map +1 -0
  48. package/dist/migrate/types.js +9 -0
  49. package/dist/migrate/types.js.map +1 -0
  50. package/package.json +40 -0
package/LICENSE ADDED
@@ -0,0 +1,34 @@
1
+ Makine.ai Client Software Licence
2
+
3
+ Copyright (c) 2026 Osman Baytaroglu. All rights reserved.
4
+
5
+ This licence covers the software in this package (the "Software"). The Software is licensed, not
6
+ sold.
7
+
8
+ 1. Grant. The copyright holder grants you a worldwide, non-exclusive, non-transferable,
9
+ royalty-free licence to install, run and copy the Software, and to incorporate it unmodified in
10
+ your own applications, solely to connect to and use a Makine.ai service or a Makine.ai
11
+ deployment that you are authorised to use.
12
+
13
+ 2. Restrictions. You may not:
14
+ a. modify, adapt or create derivative works of the Software, except where applicable law permits
15
+ it despite this restriction;
16
+ b. distribute, sublicense, sell, rent or lease the Software on its own, or offer it as a
17
+ standalone product, except as part of an application covered by section 1;
18
+ c. use the Software to build or operate a product or service that competes with Makine.ai; or
19
+ d. remove or alter this notice.
20
+
21
+ 3. Your Makine.ai agreement. Your use of a Makine.ai service or deployment is governed by the
22
+ agreement you hold for it. Where that agreement conflicts with this licence, the agreement
23
+ prevails.
24
+
25
+ 4. Termination. This licence ends automatically if you breach it. When it ends, you must stop using
26
+ the Software and delete every copy in your control.
27
+
28
+ 5. No warranty. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
29
+ INCLUDING THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
30
+ NON-INFRINGEMENT.
31
+
32
+ 6. Limitation of liability. TO THE EXTENT PERMITTED BY LAW, THE COPYRIGHT HOLDER IS NOT LIABLE FOR
33
+ ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, ARISING FROM OR IN
34
+ CONNECTION WITH THE SOFTWARE OR ITS USE.
@@ -0,0 +1,63 @@
1
+ import { type GatewayOptimizeFor } from "@makine/sdk";
2
+ /**
3
+ * Exit codes are the CLI's actual contract — a script reads them, not the prose.
4
+ *
5
+ * The distinction that matters is `RESULT_NOT_ACCEPTED` versus everything else: it means Makine ran
6
+ * the request and the answer did not clear the acceptance gate. That is a verdict, not a fault, and
7
+ * conflating it with a transport failure is how a pipeline ends up treating a rejected answer as a
8
+ * flake and retrying it.
9
+ */
10
+ export declare const EXIT: {
11
+ /** The run was accepted. */
12
+ readonly ACCEPTED: 0;
13
+ /** Bad arguments, missing base URL or API key. Nothing was sent. */
14
+ readonly USAGE: 1;
15
+ /**
16
+ * No accepted result came back: a non-accepted verdict, a parked human review, or an outcome
17
+ * this request could not determine. In the last case the run may still finish successfully —
18
+ * poll the Task surface rather than re-sending.
19
+ */
20
+ readonly RESULT_NOT_ACCEPTED: 2;
21
+ /** 401/403. The workspace API key is missing, wrong, or not entitled. */
22
+ readonly AUTH: 3;
23
+ /** The Gateway refused to run it: 503, 404 unknown model, 429 over a limit. */
24
+ readonly GATEWAY: 4;
25
+ /** The Gateway was not reachable at all — DNS, connection refused, TLS, timeout. */
26
+ readonly UNREACHABLE: 5;
27
+ };
28
+ export type ExitCode = (typeof EXIT)[keyof typeof EXIT];
29
+ export interface CliIo {
30
+ out: (line: string) => void;
31
+ err: (line: string) => void;
32
+ env: Record<string, string | undefined>;
33
+ fetchImpl?: typeof fetch;
34
+ /** Overridable file read, used by `migrate`. Defaults to `node:fs`. */
35
+ readFileImpl?: (path: string) => string;
36
+ }
37
+ interface ParsedArgs {
38
+ command: "run" | "models" | "migrate" | "help" | "version";
39
+ /** Positional arguments: the prompt for `run`, the config file for `migrate`. */
40
+ prompt: string[];
41
+ baseUrl?: string;
42
+ apiKey?: string;
43
+ model?: string;
44
+ system?: string;
45
+ maxTokens?: number;
46
+ temperature?: number;
47
+ optimizeFor?: GatewayOptimizeFor;
48
+ acceptanceContract?: string;
49
+ from?: string;
50
+ shape?: string;
51
+ json: boolean;
52
+ }
53
+ type ParseResult = {
54
+ ok: true;
55
+ args: ParsedArgs;
56
+ } | {
57
+ ok: false;
58
+ message: string;
59
+ };
60
+ export declare function parseArgs(argv: readonly string[]): ParseResult;
61
+ export declare function runCli(argv: readonly string[], io: CliIo): Promise<ExitCode>;
62
+ export {};
63
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAqBA,OAAO,EAKL,KAAK,kBAAkB,EACxB,MAAM,aAAa,CAAC;AAIrB;;;;;;;GAOG;AACH,eAAO,MAAM,IAAI;IACf,4BAA4B;;IAE5B,oEAAoE;;IAEpE;;;;OAIG;;IAEH,yEAAyE;;IAEzE,+EAA+E;;IAE/E,oFAAoF;;CAE5E,CAAC;AAEX,MAAM,MAAM,QAAQ,GAAG,CAAC,OAAO,IAAI,CAAC,CAAC,MAAM,OAAO,IAAI,CAAC,CAAC;AAExD,MAAM,WAAW,KAAK;IACpB,GAAG,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAC5B,GAAG,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAC5B,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;IACxC,SAAS,CAAC,EAAE,OAAO,KAAK,CAAC;IACzB,uEAAuE;IACvE,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;CACzC;AA8CD,UAAU,UAAU;IAClB,OAAO,EAAE,KAAK,GAAG,QAAQ,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAAC;IAC3D,iFAAiF;IACjF,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,kBAAkB,CAAC;IACjC,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,OAAO,CAAC;CACf;AAED,KAAK,WAAW,GAAG;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,UAAU,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AAEnF,wBAAgB,SAAS,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,GAAG,WAAW,CA0F9D;AAmCD,wBAAsB,MAAM,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,EAAE,EAAE,EAAE,KAAK,GAAG,OAAO,CAAC,QAAQ,CAAC,CAuElF"}
package/dist/index.js ADDED
@@ -0,0 +1,380 @@
1
+ /// <reference types="node" />
2
+ /**
3
+ * The `makine` CLI (mak164b / G31).
4
+ *
5
+ * The shortest path from "installed" to "saw an accepted result": point it at a Gateway, send a
6
+ * prompt, read the acceptance verdict, and let the exit code carry the verdict into a shell script
7
+ * or a CI step.
8
+ *
9
+ * The whole CLI is `runCli(argv, io)` — argument parsing, execution and rendering — returning an
10
+ * exit code rather than calling `process.exit`. `./main.ts` is the eight-line shim that turns that
11
+ * into a process. That split exists so the exit codes below are testable against a real Gateway
12
+ * (see `packages/cli/test/cli.test.ts`): a CLI whose failure path can only be observed by spawning
13
+ * a process tends to be a CLI whose failure path is never observed at all.
14
+ *
15
+ * It talks to the Gateway through `@makine/sdk`'s `MakineGatewayClient` and adds no protocol of its
16
+ * own.
17
+ */
18
+ import { readFileSync } from "node:fs";
19
+ import { MakineGatewayClient, MakineGatewayError, } from "@makine/sdk";
20
+ import { runMigrate } from "./migrate/command.js";
21
+ /**
22
+ * Exit codes are the CLI's actual contract — a script reads them, not the prose.
23
+ *
24
+ * The distinction that matters is `RESULT_NOT_ACCEPTED` versus everything else: it means Makine ran
25
+ * the request and the answer did not clear the acceptance gate. That is a verdict, not a fault, and
26
+ * conflating it with a transport failure is how a pipeline ends up treating a rejected answer as a
27
+ * flake and retrying it.
28
+ */
29
+ export const EXIT = {
30
+ /** The run was accepted. */
31
+ ACCEPTED: 0,
32
+ /** Bad arguments, missing base URL or API key. Nothing was sent. */
33
+ USAGE: 1,
34
+ /**
35
+ * No accepted result came back: a non-accepted verdict, a parked human review, or an outcome
36
+ * this request could not determine. In the last case the run may still finish successfully —
37
+ * poll the Task surface rather than re-sending.
38
+ */
39
+ RESULT_NOT_ACCEPTED: 2,
40
+ /** 401/403. The workspace API key is missing, wrong, or not entitled. */
41
+ AUTH: 3,
42
+ /** The Gateway refused to run it: 503, 404 unknown model, 429 over a limit. */
43
+ GATEWAY: 4,
44
+ /** The Gateway was not reachable at all — DNS, connection refused, TLS, timeout. */
45
+ UNREACHABLE: 5,
46
+ };
47
+ const USAGE = `makine — talk to a Makine Gateway
48
+
49
+ USAGE
50
+ makine run [prompt...] Send one buffered chat completion and print the verdict
51
+ makine models List the model aliases this workspace may call
52
+ makine migrate <file> Translate a Portkey or LiteLLM config into makine.env settings
53
+ makine help | --help
54
+ makine version | --version
55
+
56
+ CONNECTION (flag wins over environment)
57
+ --base-url <url> MAKINE_BASE_URL Gateway root, e.g. http://127.0.0.1:3000
58
+ --api-key <key> MAKINE_API_KEY Workspace API key (mak_...)
59
+ --model <alias> MAKINE_MODEL A model alias from \`makine models\`
60
+
61
+ RUN OPTIONS
62
+ --system <text> Prepend a system message
63
+ --max-tokens <n>
64
+ --temperature <n>
65
+ --optimize-for <cost|latency|balanced>
66
+ --acceptance-contract <id@version>
67
+ --json Print the whole response as JSON instead of prose
68
+
69
+ With no prompt argument, \`run\` reads the prompt from stdin.
70
+
71
+ MIGRATE OPTIONS (offline — reads the file, never calls a provider)
72
+ --from <litellm|portkey> Required. Which config format the file is in.
73
+ --shape <onprem|direct> How the API is started; decides which variables can reach it.
74
+ Default onprem: \`docker compose -f docker-compose.onprem.yml up\`.
75
+ Use direct when the API process gets the file's variables itself.
76
+ --json Print the settings, the field mapping and the report as JSON.
77
+
78
+ Prints the settings it could produce, then a report naming every construct it did not
79
+ translate and why. Nothing is silently dropped, and no credential field is copied. An
80
+ endpoint is copied whole, path included, because the path is the endpoint.
81
+ See docs/developers/migrating-from-portkey-or-litellm.md.
82
+
83
+ EXIT CODES
84
+ 0 accepted 2 no accepted result (verdict, or not finished) 4 gateway refused
85
+ 1 usage error 3 auth refused 5 gateway unreachable
86
+
87
+ NOTES
88
+ Prefer MAKINE_API_KEY over --api-key: a flag lands in your shell history and in \`ps\`.
89
+ Streaming is not supported here; \`stream: true\` is a Gateway boundary, not a bug.`;
90
+ export function parseArgs(argv) {
91
+ const args = { command: "help", prompt: [], json: false };
92
+ let index = 0;
93
+ const head = argv[0];
94
+ if (head === undefined || head === "help" || head === "--help" || head === "-h") {
95
+ return { ok: true, args: { ...args, command: "help" } };
96
+ }
97
+ if (head === "version" || head === "--version" || head === "-V") {
98
+ return { ok: true, args: { ...args, command: "version" } };
99
+ }
100
+ if (head === "run" || head === "models" || head === "migrate") {
101
+ args.command = head;
102
+ index = 1;
103
+ }
104
+ else {
105
+ return { ok: false, message: `Unknown command \`${head}\`. Try \`makine help\`.` };
106
+ }
107
+ const needsValue = (flag, value) => {
108
+ if (value === undefined)
109
+ throw new CliUsageError(`${flag} needs a value.`);
110
+ return true;
111
+ };
112
+ try {
113
+ for (; index < argv.length; index += 1) {
114
+ const token = argv[index];
115
+ if (token === undefined)
116
+ break;
117
+ if (token === "--") {
118
+ args.prompt.push(...argv.slice(index + 1));
119
+ break;
120
+ }
121
+ if (!token.startsWith("--")) {
122
+ args.prompt.push(token);
123
+ continue;
124
+ }
125
+ const next = argv[index + 1];
126
+ switch (token) {
127
+ case "--json":
128
+ args.json = true;
129
+ break;
130
+ case "--base-url":
131
+ if (needsValue(token, next))
132
+ args.baseUrl = next;
133
+ index += 1;
134
+ break;
135
+ case "--api-key":
136
+ if (needsValue(token, next))
137
+ args.apiKey = next;
138
+ index += 1;
139
+ break;
140
+ case "--model":
141
+ if (needsValue(token, next))
142
+ args.model = next;
143
+ index += 1;
144
+ break;
145
+ case "--system":
146
+ if (needsValue(token, next))
147
+ args.system = next;
148
+ index += 1;
149
+ break;
150
+ case "--max-tokens":
151
+ if (needsValue(token, next))
152
+ args.maxTokens = parseNumber(token, next);
153
+ index += 1;
154
+ break;
155
+ case "--temperature":
156
+ if (needsValue(token, next))
157
+ args.temperature = parseNumber(token, next);
158
+ index += 1;
159
+ break;
160
+ case "--optimize-for":
161
+ if (needsValue(token, next))
162
+ args.optimizeFor = parseOptimizeFor(next);
163
+ index += 1;
164
+ break;
165
+ case "--acceptance-contract":
166
+ if (needsValue(token, next))
167
+ args.acceptanceContract = next;
168
+ index += 1;
169
+ break;
170
+ case "--from":
171
+ if (needsValue(token, next))
172
+ args.from = next;
173
+ index += 1;
174
+ break;
175
+ case "--shape":
176
+ if (needsValue(token, next))
177
+ args.shape = next;
178
+ index += 1;
179
+ break;
180
+ default:
181
+ throw new CliUsageError(`Unknown option \`${token}\`. Try \`makine help\`.`);
182
+ }
183
+ }
184
+ }
185
+ catch (error) {
186
+ if (error instanceof CliUsageError)
187
+ return { ok: false, message: error.message };
188
+ throw error;
189
+ }
190
+ return { ok: true, args };
191
+ }
192
+ class CliUsageError extends Error {
193
+ }
194
+ /**
195
+ * What `makine version` prints, read from the manifest rather than restated here.
196
+ *
197
+ * A literal would be a second version source of truth, and the release cross-checks only the
198
+ * manifests — so a stale literal would ship happily and tell every installed user the wrong number.
199
+ * `0.0.0` was that literal, and it survived three releases.
200
+ *
201
+ * The manifest sits one directory above this module in BOTH layouts that matter: `src/index.ts` in a
202
+ * source checkout, and `package/dist/index.js` beside `package/package.json` in the published
203
+ * tarball. That is what lets the release workflow install the tarball in a clean directory and
204
+ * assert that the installed binary reports the version it just published.
205
+ */
206
+ function packageVersion() {
207
+ const manifest = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8"));
208
+ const version = manifest.version;
209
+ return typeof version === "string" ? version : "unknown";
210
+ }
211
+ function parseNumber(flag, value) {
212
+ const parsed = Number(value);
213
+ if (!Number.isFinite(parsed))
214
+ throw new CliUsageError(`${flag} must be a number, got \`${value}\`.`);
215
+ return parsed;
216
+ }
217
+ function parseOptimizeFor(value) {
218
+ if (value === "cost" || value === "latency" || value === "balanced")
219
+ return value;
220
+ throw new CliUsageError(`--optimize-for must be cost, latency or balanced, got \`${value}\`.`);
221
+ }
222
+ export async function runCli(argv, io) {
223
+ const parsed = parseArgs(argv);
224
+ if (!parsed.ok) {
225
+ io.err(parsed.message);
226
+ return EXIT.USAGE;
227
+ }
228
+ const args = parsed.args;
229
+ if (args.command === "help") {
230
+ io.out(USAGE);
231
+ return EXIT.ACCEPTED;
232
+ }
233
+ if (args.command === "version") {
234
+ io.out(`makine ${packageVersion()}`);
235
+ return EXIT.ACCEPTED;
236
+ }
237
+ if (args.command === "migrate") {
238
+ // Offline and local: it reads a file the caller already has. Requiring a Gateway address and
239
+ // a workspace key here would mean a user cannot see what their migration looks like until
240
+ // they have already stood Makine up, which is backwards.
241
+ const ok = runMigrate({
242
+ json: args.json,
243
+ files: args.prompt,
244
+ ...(args.from === undefined ? {} : { from: args.from }),
245
+ ...(args.shape === undefined ? {} : { shape: args.shape }),
246
+ }, {
247
+ out: io.out,
248
+ err: io.err,
249
+ ...(io.readFileImpl === undefined ? {} : { readFile: io.readFileImpl }),
250
+ });
251
+ return ok ? EXIT.ACCEPTED : EXIT.USAGE;
252
+ }
253
+ const baseUrl = args.baseUrl ?? io.env.MAKINE_BASE_URL;
254
+ if (baseUrl === undefined || baseUrl.trim().length === 0) {
255
+ io.err("No Gateway address. Set MAKINE_BASE_URL or pass --base-url.");
256
+ return EXIT.USAGE;
257
+ }
258
+ const apiKey = args.apiKey ?? io.env.MAKINE_API_KEY;
259
+ if (apiKey === undefined || apiKey.trim().length === 0) {
260
+ // Worth spelling out: this is the single most common first failure, and the Gateway's own 401
261
+ // cannot distinguish "no key" from "wrong key" (`apps/api/src/gateway/v1.ts:794-813`).
262
+ io.err("No workspace API key. Set MAKINE_API_KEY or pass --api-key.\n" +
263
+ "The Gateway needs BOTH the address and a key — it never falls back to a default workspace.");
264
+ return EXIT.USAGE;
265
+ }
266
+ const client = new MakineGatewayClient({
267
+ baseUrl,
268
+ apiKey,
269
+ headers: {
270
+ ...(args.acceptanceContract === undefined
271
+ ? {}
272
+ : { acceptanceContract: args.acceptanceContract }),
273
+ ...(args.optimizeFor === undefined ? {} : { optimizeFor: args.optimizeFor }),
274
+ },
275
+ ...(io.fetchImpl === undefined ? {} : { fetchImpl: io.fetchImpl }),
276
+ });
277
+ try {
278
+ return args.command === "models"
279
+ ? await commandModels(client, args, io)
280
+ : await commandRun(client, args, io);
281
+ }
282
+ catch (error) {
283
+ return reportError(error, io);
284
+ }
285
+ }
286
+ async function commandModels(client, args, io) {
287
+ const list = await client.listModels();
288
+ if (args.json) {
289
+ io.out(JSON.stringify(list, null, 2));
290
+ return EXIT.ACCEPTED;
291
+ }
292
+ if (list.data.length === 0) {
293
+ io.out("No models are registered for this workspace.");
294
+ return EXIT.ACCEPTED;
295
+ }
296
+ for (const model of list.data)
297
+ io.out(`${model.id}\t(${model.owned_by})`);
298
+ return EXIT.ACCEPTED;
299
+ }
300
+ async function commandRun(client, args, io) {
301
+ const model = args.model ?? io.env.MAKINE_MODEL;
302
+ if (model === undefined || model.trim().length === 0) {
303
+ io.err("No model. Set MAKINE_MODEL or pass --model. `makine models` lists what is available.");
304
+ return EXIT.USAGE;
305
+ }
306
+ const prompt = args.prompt.join(" ").trim();
307
+ if (prompt.length === 0) {
308
+ io.err("Empty prompt. Pass it as an argument or pipe it on stdin.");
309
+ return EXIT.USAGE;
310
+ }
311
+ const messages = [
312
+ ...(args.system === undefined ? [] : [{ role: "system", content: args.system }]),
313
+ { role: "user", content: prompt },
314
+ ];
315
+ const request = {
316
+ model,
317
+ messages,
318
+ ...(args.maxTokens === undefined ? {} : { max_tokens: args.maxTokens }),
319
+ ...(args.temperature === undefined ? {} : { temperature: args.temperature }),
320
+ };
321
+ const completion = await client.chatCompletion(request);
322
+ const makine = completion.body.makine;
323
+ if (args.json) {
324
+ io.out(JSON.stringify({ headers: completion.headers, body: completion.body }, null, 2));
325
+ }
326
+ else {
327
+ io.out(completion.body.choices[0]?.message.content ?? "");
328
+ io.err("");
329
+ io.err(`verdict ${makine.acceptance_verdict}`);
330
+ io.err(`task ${makine.task_id}`);
331
+ io.err(`executor ${makine.executor_ref} (${makine.model})`);
332
+ io.err(`run purpose ${makine.run_purpose}`);
333
+ io.err(`poll ${makine.poll_url}`);
334
+ }
335
+ // The verdict, not the HTTP status, decides the exit code. A `deferred` verdict is a 200 whose
336
+ // answer has NOT cleared the acceptance gate; exiting 0 there would be the CLI lying by omission.
337
+ if (makine.acceptance_verdict !== "accepted") {
338
+ io.err(`Not accepted: verdict is \`${makine.acceptance_verdict}\`.`);
339
+ return EXIT.RESULT_NOT_ACCEPTED;
340
+ }
341
+ return EXIT.ACCEPTED;
342
+ }
343
+ function reportError(error, io) {
344
+ if (error instanceof MakineGatewayError) {
345
+ io.err(`${error.code}: ${error.message}`);
346
+ if (error.headers.taskId !== undefined)
347
+ io.err(`task ${error.headers.taskId}`);
348
+ if (error.status === 401 || error.status === 403) {
349
+ io.err("Check MAKINE_API_KEY. The Gateway requires a workspace key and has no default.");
350
+ return EXIT.AUTH;
351
+ }
352
+ if (error.code === "awaiting_human_review") {
353
+ io.err("Parked for human review — poll the Task surface for the resolution.");
354
+ return EXIT.RESULT_NOT_ACCEPTED;
355
+ }
356
+ if (error.code === "outcome_indeterminate") {
357
+ // Not a fault and not a verdict: the work is submitted and addressable, this request just
358
+ // did not carry it to the end. Re-running would submit it a second time.
359
+ io.err("Not finished on this request — the run is still in flight. Poll the Task surface with\n" +
360
+ "the task id above; do not re-send the request, which would create a second run.");
361
+ return EXIT.RESULT_NOT_ACCEPTED;
362
+ }
363
+ if (error.status === 503 && error.code === "gateway_unavailable") {
364
+ io.err("This deployment has no executor registry wired. Set MAKINE_LOCAL_PROVIDER_BASE_URL and\n" +
365
+ "MAKINE_LOCAL_PROVIDER_MODEL (or a cloud provider key) and restart the API.");
366
+ return EXIT.GATEWAY;
367
+ }
368
+ if (error.status >= 500 || error.status === 404 || error.status === 429)
369
+ return EXIT.GATEWAY;
370
+ // Everything else in 4xx is the caller's request: a bad model, a malformed contract header, a
371
+ // field this surface does not implement.
372
+ return EXIT.RESULT_NOT_ACCEPTED;
373
+ }
374
+ // fetch() rejects rather than resolving when the connection never happened.
375
+ const message = error instanceof Error ? error.message : String(error);
376
+ const cause = error instanceof Error && error.cause instanceof Error ? error.cause.message : "";
377
+ io.err(`Could not reach the Gateway: ${message}${cause === "" ? "" : ` (${cause})`}`);
378
+ return EXIT.UNREACHABLE;
379
+ }
380
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,8BAA8B;AAE9B;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvC,OAAO,EACL,mBAAmB,EACnB,kBAAkB,GAInB,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAElD;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,IAAI,GAAG;IAClB,4BAA4B;IAC5B,QAAQ,EAAE,CAAC;IACX,oE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AAmB,CAAC;IAClC,CAAC;IAED,4EAA4E;IAC5E,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACvE,MAAM,KAAK,GAAG,KAAK,YAAY,KAAK,IAAI,KAAK,CAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;IAChG,EAAE,CAAC,GAAG,CAAC,gCAAgC,OAAO,GAAG,KAAK,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,KAAK,GAAG,EAAE,CAAC,CAAC;IACtF,OAAO,IAAI,CAAC,WAAW,CAAC;AAC1B,CAAC"}
package/dist/main.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=main.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":""}
package/dist/main.js ADDED
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env node
2
+ /// <reference types="node" />
3
+ /**
4
+ * The process shim. Everything interesting is in `./index.ts`'s `runCli`, which returns an exit
5
+ * code instead of ending the process so the exit codes can be tested against a real Gateway.
6
+ *
7
+ * The only behaviour that lives here is reading a piped prompt, because that needs a real stdin.
8
+ */
9
+ import { parseArgs, runCli } from "./index.js";
10
+ async function readPipedStdin() {
11
+ if (process.stdin.isTTY === true)
12
+ return "";
13
+ process.stdin.setEncoding("utf8");
14
+ let text = "";
15
+ for await (const chunk of process.stdin)
16
+ text += chunk;
17
+ return text.trim();
18
+ }
19
+ const argv = process.argv.slice(2);
20
+ // Re-parsed inside `runCli`; parsing here too is the cheapest way to know whether a prompt was
21
+ // supplied without duplicating the flag table and getting flag VALUES wrong (`--model local-chat`
22
+ // looks exactly like a bare prompt word to a naive scan).
23
+ const preview = parseArgs(argv);
24
+ const wantsStdin = preview.ok && preview.args.command === "run" && preview.args.prompt.length === 0;
25
+ const piped = wantsStdin ? await readPipedStdin() : "";
26
+ process.exitCode = await runCli(piped === "" ? argv : [...argv, "--", piped], {
27
+ out: (line) => process.stdout.write(`${line}\n`),
28
+ err: (line) => process.stderr.write(`${line}\n`),
29
+ env: process.env,
30
+ });
31
+ //# sourceMappingURL=main.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"main.js","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":";AACA,8BAA8B;AAE9B;;;;;GAKG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAE/C,KAAK,UAAU,cAAc;IAC3B,IAAI,OAAO,CAAC,KAAK,CAAC,KAAK,KAAK,IAAI;QAAE,OAAO,EAAE,CAAC;IAC5C,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;IAClC,IAAI,IAAI,GAAG,EAAE,CAAC;IACd,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,OAAO,CAAC,KAAK;QAAE,IAAI,IAAI,KAAe,CAAC;IACjE,OAAO,IAAI,CAAC,IAAI,EAAE,CAAC;AACrB,CAAC;AAED,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AAEnC,+FAA+F;AAC/F,kGAAkG;AAClG,0DAA0D;AAC1D,MAAM,OAAO,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC;AAChC,MAAM,UAAU,GAAG,OAAO,CAAC,EAAE,IAAI,OAAO,CAAC,IAAI,CAAC,OAAO,KAAK,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,KAAK,CAAC,CAAC;AACpG,MAAM,KAAK,GAAG,UAAU,CAAC,CAAC,CAAC,MAAM,cAAc,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;AAEvD,OAAO,CAAC,QAAQ,GAAG,MAAM,MAAM,CAAC,KAAK,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,EAAE,IAAI,EAAE,KAAK,CAAC,EAAE;IAC5E,GAAG,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,IAAI,IAAI,CAAC;IAChD,GAAG,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,IAAI,IAAI,CAAC;IAChD,GAAG,EAAE,OAAO,CAAC,GAAG;CACjB,CAAC,CAAC"}
@@ -0,0 +1,39 @@
1
+ /**
2
+ * `makine migrate` — the only part of the translator that touches the world.
3
+ *
4
+ * Reads one file, parses it, translates, prints. No network call is made on any path: a migration
5
+ * tool that phoned a provider to "check" a config would be sending someone else's credentials to
6
+ * someone else's endpoint on their behalf.
7
+ */
8
+ import type { MigrationSource } from "./types.js";
9
+ export interface MigrateIo {
10
+ out: (line: string) => void;
11
+ err: (line: string) => void;
12
+ /** Overridable so a test can drive an unreadable file without depending on the filesystem. */
13
+ readFile?: (path: string) => string;
14
+ }
15
+ export interface MigrateInvocation {
16
+ from?: string;
17
+ shape?: string;
18
+ json: boolean;
19
+ files: readonly string[];
20
+ }
21
+ /** `true` when the input parsed and a report was produced — gaps or not. */
22
+ export declare function runMigrate(invocation: MigrateInvocation, io: MigrateIo): boolean;
23
+ export type ParseOutcome = {
24
+ ok: true;
25
+ value: unknown;
26
+ } | {
27
+ ok: false;
28
+ message: string;
29
+ };
30
+ /**
31
+ * Exported so the reconciliation test walks EXACTLY the tree the command translates.
32
+ *
33
+ * The leaf walker in `packages/cli/test/migrate.test.ts` is deliberately written there rather than
34
+ * imported — a walker imported from the translator would agree with the translator's own bugs. The
35
+ * parser is the opposite case: if the test parsed with different options, it would reconcile a
36
+ * different document, and a YAML merge key would appear as a leaf in one and not in the other.
37
+ */
38
+ export declare function parseConfigText(text: string, source: MigrationSource, path: string): ParseOutcome;
39
+ //# sourceMappingURL=command.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"command.d.ts","sourceRoot":"","sources":["../../src/migrate/command.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAgBH,OAAO,KAAK,EAAkB,eAAe,EAAE,MAAM,YAAY,CAAC;AAElE,MAAM,WAAW,SAAS;IACxB,GAAG,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAC5B,GAAG,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAC5B,8FAA8F;IAC9F,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;CACrC;AAED,MAAM,WAAW,iBAAiB;IAChC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,OAAO,CAAC;IACd,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;CAC1B;AAKD,4EAA4E;AAC5E,wBAAgB,UAAU,CAAC,UAAU,EAAE,iBAAiB,EAAE,EAAE,EAAE,SAAS,GAAG,OAAO,CAuDhF;AAMD,MAAM,MAAM,YAAY,GAAG;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AAEzF;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,GAAG,YAAY,CAEjG"}