motifcode 0.4.0 → 0.4.2
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.
- package/README.md +16 -9
- package/dist/build-info.json +3 -3
- package/dist/motif.js +283 -54
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -5,26 +5,33 @@ A Claude Code-style terminal session — transcript above, prompt below, `/` com
|
|
|
5
5
|
a permission prompt, a `.motif/` directory behind it — whose tool set, prompt layout, parser and
|
|
6
6
|
failure handling follow from what is measurably true about Motif-3.
|
|
7
7
|
|
|
8
|
-
> **
|
|
9
|
-
>
|
|
10
|
-
>
|
|
8
|
+
> **Choose your provider.** First launch offers [Infron](https://infron.ai) or
|
|
9
|
+
> [Morphfactory (BETA)](https://cbt.morphfactory.io/console?view=keys).
|
|
10
|
+
> Switch later with `/provider` or `/config`; each provider keeps its own API key.
|
|
11
11
|
|
|
12
12
|
> **Not an official Motif project.** Not certified, endorsed, sponsored or maintained by Motif
|
|
13
13
|
> Technologies or by Infron. *Motif* and *Motif-3* are their names; this package is a client of the model.
|
|
14
14
|
|
|
15
15
|
```bash
|
|
16
16
|
cd your-project
|
|
17
|
-
npx motifcode #
|
|
17
|
+
npx motifcode # choose a provider and enter its API key once, then offers to install the `motif` command
|
|
18
18
|
```
|
|
19
19
|
|
|
20
20
|
Or `npm install -g motifcode` directly; either way `motif` (or `motifcode`) opens the session
|
|
21
21
|
from any folder afterwards, with the key saved in `~/.motif/.env`.
|
|
22
22
|
|
|
23
|
-
1.
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
1. Create an API key at [Infron's dashboard](https://infron.ai/dashboard/apiKeys) or
|
|
24
|
+
[Morphfactory's console](https://cbt.morphfactory.io/console?view=keys).
|
|
25
|
+
2. Run `motif`, choose the provider and paste its key. It is checked against the endpoint,
|
|
26
|
+
saved to `~/.motif/.env` (readable only by you), and never shown to the model. Use
|
|
27
|
+
`/provider` to switch, or `/login` and `/logout` to manage the selected provider's key.
|
|
28
|
+
3. Outside a session, use `motif login --provider morphfactory` and
|
|
29
|
+
`motif doctor --provider morphfactory`. `--provider infron` selects Infron.
|
|
30
|
+
|
|
31
|
+
The environment keys are `MOTIF_API_KEY` for Infron and `MOTIF_MORPHFACTORY_API_KEY`
|
|
32
|
+
for Morphfactory. Use `--provider morphfactory` for a single invocation, or choose
|
|
33
|
+
with `/provider` to save the selection. Explicit `--endpoint` and `--model` flags
|
|
34
|
+
still override a provider preset.
|
|
28
35
|
|
|
29
36
|
```bash
|
|
30
37
|
motif # interactive session in the current directory
|
package/dist/build-info.json
CHANGED
package/dist/motif.js
CHANGED
|
@@ -48058,6 +48058,23 @@ var DEFAULT_MODEL = "motif/motif-3";
|
|
|
48058
48058
|
var ENV_ENDPOINT = "MOTIF_ENDPOINT";
|
|
48059
48059
|
var ENV_MODEL = "MOTIF_MODEL";
|
|
48060
48060
|
var ENV_API_KEY = "MOTIF_API_KEY";
|
|
48061
|
+
var ENV_MORPHFACTORY_API_KEY = "MOTIF_MORPHFACTORY_API_KEY";
|
|
48062
|
+
var PROVIDERS = {
|
|
48063
|
+
infron: {
|
|
48064
|
+
label: "Infron",
|
|
48065
|
+
endpoint: DEFAULT_ENDPOINT,
|
|
48066
|
+
model: DEFAULT_MODEL,
|
|
48067
|
+
apiKeyEnv: ENV_API_KEY,
|
|
48068
|
+
keyPage: "https://infron.ai/dashboard/apiKeys"
|
|
48069
|
+
},
|
|
48070
|
+
morphfactory: {
|
|
48071
|
+
label: "Morphfactory (BETA)",
|
|
48072
|
+
endpoint: "https://api-cbt.morphfactory.io",
|
|
48073
|
+
model: DEFAULT_MODEL,
|
|
48074
|
+
apiKeyEnv: ENV_MORPHFACTORY_API_KEY,
|
|
48075
|
+
keyPage: "https://cbt.morphfactory.io/console?view=keys"
|
|
48076
|
+
}
|
|
48077
|
+
};
|
|
48061
48078
|
function parseDotenv(text) {
|
|
48062
48079
|
const out = {};
|
|
48063
48080
|
for (const rawLine of text.split(/\r?\n/)) {
|
|
@@ -48087,6 +48104,18 @@ function isInfronEndpoint(endpoint) {
|
|
|
48087
48104
|
const origin = /^https:\/\/llm\.onerouter\.pro(?=\/|$)/i.exec(value)?.[0];
|
|
48088
48105
|
return origin !== void 0 && ["", "/", "/v1", "/v1/"].includes(value.slice(origin.length));
|
|
48089
48106
|
}
|
|
48107
|
+
function providerForEndpoint(endpoint) {
|
|
48108
|
+
if (isInfronEndpoint(endpoint)) return "infron";
|
|
48109
|
+
try {
|
|
48110
|
+
const url2 = new URL(endpoint.trim());
|
|
48111
|
+
if (url2.origin === PROVIDERS.morphfactory.endpoint && !url2.username && !url2.password && !url2.search && !url2.hash && ["/", "/v1", "/v1/"].includes(url2.pathname)) return "morphfactory";
|
|
48112
|
+
} catch {
|
|
48113
|
+
}
|
|
48114
|
+
return void 0;
|
|
48115
|
+
}
|
|
48116
|
+
function apiKeyEnvForEndpoint(endpoint) {
|
|
48117
|
+
return providerForEndpoint(endpoint) === "morphfactory" ? ENV_MORPHFACTORY_API_KEY : ENV_API_KEY;
|
|
48118
|
+
}
|
|
48090
48119
|
function defaultDotenvPaths(cwd = process.cwd()) {
|
|
48091
48120
|
return [join(cwd, ".env"), join(homedir(), ".motif", ".env")];
|
|
48092
48121
|
}
|
|
@@ -48113,9 +48142,10 @@ function resolveEndpointConfig(opts = {}) {
|
|
|
48113
48142
|
};
|
|
48114
48143
|
const endpoint = pick2(opts.flags?.endpoint, ENV_ENDPOINT, opts.defaults?.endpoint ?? DEFAULT_ENDPOINT);
|
|
48115
48144
|
const model = pick2(opts.flags?.model, ENV_MODEL, opts.defaults?.model ?? DEFAULT_MODEL);
|
|
48116
|
-
const
|
|
48145
|
+
const normalizedEndpoint = normalizeEndpoint(endpoint.value);
|
|
48146
|
+
const apiKey = pick2(void 0, apiKeyEnvForEndpoint(normalizedEndpoint), void 0);
|
|
48117
48147
|
return {
|
|
48118
|
-
endpoint:
|
|
48148
|
+
endpoint: normalizedEndpoint,
|
|
48119
48149
|
model: model.value,
|
|
48120
48150
|
...apiKey.value !== void 0 ? { apiKey: apiKey.value } : {},
|
|
48121
48151
|
sources: {
|
|
@@ -48127,6 +48157,7 @@ function resolveEndpointConfig(opts = {}) {
|
|
|
48127
48157
|
}
|
|
48128
48158
|
function withholdSecrets(env) {
|
|
48129
48159
|
delete env[ENV_API_KEY];
|
|
48160
|
+
delete env[ENV_MORPHFACTORY_API_KEY];
|
|
48130
48161
|
}
|
|
48131
48162
|
function defaultEnvPath(home = homedir()) {
|
|
48132
48163
|
return join(home, ".motif", ".env");
|
|
@@ -48150,17 +48181,17 @@ function removeDotenvKey(text, key) {
|
|
|
48150
48181
|
const out = kept.join("\n").replace(/\n+$/, "");
|
|
48151
48182
|
return out === "" ? "" : out + "\n";
|
|
48152
48183
|
}
|
|
48153
|
-
function saveApiKey(apiKey, path = defaultEnvPath()) {
|
|
48184
|
+
function saveApiKey(apiKey, path = defaultEnvPath(), provider = "infron") {
|
|
48154
48185
|
mkdirSync(dirname(path), { recursive: true, mode: 448 });
|
|
48155
48186
|
const existing = existsSync(path) ? readFileSync(path, "utf8") : "";
|
|
48156
|
-
writeFileSync(path, upsertDotenv(existing,
|
|
48187
|
+
writeFileSync(path, upsertDotenv(existing, PROVIDERS[provider].apiKeyEnv, apiKey), { encoding: "utf8", mode: 384 });
|
|
48157
48188
|
chmodSync(path, 384);
|
|
48158
48189
|
return path;
|
|
48159
48190
|
}
|
|
48160
|
-
function forgetApiKey(path = defaultEnvPath()) {
|
|
48191
|
+
function forgetApiKey(path = defaultEnvPath(), provider = "infron") {
|
|
48161
48192
|
if (!existsSync(path)) return false;
|
|
48162
48193
|
const existing = readFileSync(path, "utf8");
|
|
48163
|
-
const next = removeDotenvKey(existing,
|
|
48194
|
+
const next = removeDotenvKey(existing, PROVIDERS[provider].apiKeyEnv);
|
|
48164
48195
|
if (next === existing) return false;
|
|
48165
48196
|
writeFileSync(path, next, { encoding: "utf8", mode: 384 });
|
|
48166
48197
|
return true;
|
|
@@ -48192,6 +48223,8 @@ var TransportError = class extends Error {
|
|
|
48192
48223
|
* limit hit three more times. The loop waits at least this long.
|
|
48193
48224
|
*/
|
|
48194
48225
|
retryAfterMs;
|
|
48226
|
+
/** The server's own error code, for a `generation` error. */
|
|
48227
|
+
code;
|
|
48195
48228
|
constructor(message2, opts) {
|
|
48196
48229
|
super(message2, opts.cause !== void 0 ? { cause: opts.cause } : void 0);
|
|
48197
48230
|
this.name = "TransportError";
|
|
@@ -48199,6 +48232,7 @@ var TransportError = class extends Error {
|
|
|
48199
48232
|
if (opts.status !== void 0) this.status = opts.status;
|
|
48200
48233
|
if (opts.body !== void 0) this.body = opts.body;
|
|
48201
48234
|
if (opts.retryAfterMs !== void 0) this.retryAfterMs = opts.retryAfterMs;
|
|
48235
|
+
if (opts.code !== void 0) this.code = opts.code;
|
|
48202
48236
|
this.retryable = opts.retryable ?? defaultRetryable(opts.kind, opts.status);
|
|
48203
48237
|
}
|
|
48204
48238
|
};
|
|
@@ -48206,6 +48240,7 @@ function defaultRetryable(kind, status) {
|
|
|
48206
48240
|
switch (kind) {
|
|
48207
48241
|
case "network":
|
|
48208
48242
|
case "timeout":
|
|
48243
|
+
case "generation":
|
|
48209
48244
|
return true;
|
|
48210
48245
|
case "http":
|
|
48211
48246
|
return status !== void 0 && (status >= 500 || status === 429);
|
|
@@ -48290,6 +48325,7 @@ function requestBody(req, model) {
|
|
|
48290
48325
|
if (req.maxTokens !== void 0) body["max_tokens"] = req.maxTokens;
|
|
48291
48326
|
if (req.seed !== void 0) body["seed"] = req.seed;
|
|
48292
48327
|
if (req.stop) body["stop"] = req.stop;
|
|
48328
|
+
if (req.repetitionPenalty !== void 0) body["repetition_penalty"] = req.repetitionPenalty;
|
|
48293
48329
|
if (req.raw) {
|
|
48294
48330
|
if (req.prompt === void 0) throw new Error("raw completion requires a prompt");
|
|
48295
48331
|
body["prompt"] = req.prompt;
|
|
@@ -48366,7 +48402,8 @@ var HttpTransport = class {
|
|
|
48366
48402
|
const detail = text.trim().slice(0, 400);
|
|
48367
48403
|
let message2 = detail ? `${res.status} ${res.statusText} \u2014 ${detail}` : `${res.status} ${res.statusText}`;
|
|
48368
48404
|
if (res.status === 401 || res.status === 403) {
|
|
48369
|
-
|
|
48405
|
+
const keyEnv = apiKeyEnvForEndpoint(this.endpoint);
|
|
48406
|
+
message2 += this.apiKey ? ` (the endpoint rejected the API key that was sent; check ${keyEnv})` : ` (no API key was sent; set ${keyEnv} in the environment or in .env)`;
|
|
48370
48407
|
}
|
|
48371
48408
|
const retryAfterMs = res.status === 429 ? parseRetryAfter(res.headers.get("retry-after")) ?? DEFAULT_RETRY_AFTER_MS : void 0;
|
|
48372
48409
|
throw new TransportError(message2, {
|
|
@@ -48469,6 +48506,7 @@ async function readStream(res, onDelta, signal) {
|
|
|
48469
48506
|
let finish;
|
|
48470
48507
|
let usage;
|
|
48471
48508
|
let cost;
|
|
48509
|
+
let stopped;
|
|
48472
48510
|
const calls = /* @__PURE__ */ new Map();
|
|
48473
48511
|
const handle2 = (line2) => {
|
|
48474
48512
|
if (!line2.startsWith("data:")) return false;
|
|
@@ -48483,6 +48521,13 @@ async function readStream(res, onDelta, signal) {
|
|
|
48483
48521
|
if (typeof chunk !== "object" || chunk === null) return false;
|
|
48484
48522
|
if (chunk.usage) usage = chunk.usage;
|
|
48485
48523
|
cost = parseCost(chunk) ?? cost;
|
|
48524
|
+
if (chunk.error && typeof chunk.error === "object") {
|
|
48525
|
+
stopped = {
|
|
48526
|
+
code: typeof chunk.error.code === "string" ? chunk.error.code : "generation_error",
|
|
48527
|
+
message: typeof chunk.error.message === "string" ? chunk.error.message : ""
|
|
48528
|
+
};
|
|
48529
|
+
return true;
|
|
48530
|
+
}
|
|
48486
48531
|
const choice = chunk.choices?.[0];
|
|
48487
48532
|
if (!choice) return false;
|
|
48488
48533
|
if (choice.finish_reason) finish = choice.finish_reason;
|
|
@@ -48532,6 +48577,13 @@ async function readStream(res, onDelta, signal) {
|
|
|
48532
48577
|
if (finished) break;
|
|
48533
48578
|
}
|
|
48534
48579
|
if (!finished && buffer.trim() !== "") handle2(buffer.trim());
|
|
48580
|
+
if (stopped) {
|
|
48581
|
+
await reader.cancel().catch(() => void 0);
|
|
48582
|
+
throw new TransportError(`the server stopped the generation: ${stopped.code}${stopped.message ? ` (${stopped.message})` : ""}`, {
|
|
48583
|
+
kind: "generation",
|
|
48584
|
+
code: stopped.code
|
|
48585
|
+
});
|
|
48586
|
+
}
|
|
48535
48587
|
const toolCalls = [...calls.entries()].sort((a, b) => a[0] - b[0]).map(([, c]) => ({ ...c.id ? { id: c.id } : {}, type: "function", function: { name: c.name, arguments: c.arguments } }));
|
|
48536
48588
|
return {
|
|
48537
48589
|
choices: [
|
|
@@ -48997,6 +49049,8 @@ var EmptyTaskError = class extends Error {
|
|
|
48997
49049
|
function normalizeSummary(s) {
|
|
48998
49050
|
return s.trim().replace(/\s+/g, " ");
|
|
48999
49051
|
}
|
|
49052
|
+
var MAX_REGENERATIONS = 2;
|
|
49053
|
+
var RETRY_REPETITION_PENALTY = 1.05;
|
|
49000
49054
|
async function runLoop(opts) {
|
|
49001
49055
|
const {
|
|
49002
49056
|
transport,
|
|
@@ -49175,15 +49229,32 @@ async function runLoop(opts) {
|
|
|
49175
49229
|
emit({ type: "prefix", sharedChars, totalChars });
|
|
49176
49230
|
let response;
|
|
49177
49231
|
let attempt = 0;
|
|
49232
|
+
let regenerations = 0;
|
|
49233
|
+
let current = request;
|
|
49178
49234
|
for (; ; ) {
|
|
49179
49235
|
try {
|
|
49180
|
-
response = await transport.complete(
|
|
49236
|
+
response = await transport.complete(current);
|
|
49181
49237
|
break;
|
|
49182
49238
|
} catch (err) {
|
|
49183
49239
|
if (!TransportError.is(err)) throw err;
|
|
49184
49240
|
const te = err;
|
|
49185
49241
|
transportErrors++;
|
|
49186
49242
|
if (te.kind === "aborted") return finish("aborted");
|
|
49243
|
+
if (te.kind === "generation") {
|
|
49244
|
+
if (regenerations < MAX_REGENERATIONS) {
|
|
49245
|
+
regenerations++;
|
|
49246
|
+
current = { ...request, repetitionPenalty: RETRY_REPETITION_PENALTY };
|
|
49247
|
+
emit({
|
|
49248
|
+
type: "notice",
|
|
49249
|
+
level: "warn",
|
|
49250
|
+
text: `${te.message}; retry ${regenerations}/${MAX_REGENERATIONS} with repetition_penalty ${RETRY_REPETITION_PENALTY}`
|
|
49251
|
+
});
|
|
49252
|
+
continue;
|
|
49253
|
+
}
|
|
49254
|
+
emit({ type: "notice", level: "warn", text: `${te.message}; no reply after ${MAX_REGENERATIONS} retries` });
|
|
49255
|
+
response = { content: "", rawText: "", finishReason: "stop", ms: 0 };
|
|
49256
|
+
break;
|
|
49257
|
+
}
|
|
49187
49258
|
if (!te.retryable || attempt >= maxServerRetries) {
|
|
49188
49259
|
emit({ type: "notice", level: "error", text: `${te.kind}: ${te.message}` });
|
|
49189
49260
|
return finish("transport_error");
|
|
@@ -49267,7 +49338,7 @@ async function runLoop(opts) {
|
|
|
49267
49338
|
checkpoint();
|
|
49268
49339
|
continue;
|
|
49269
49340
|
}
|
|
49270
|
-
if (replyEnds && !leaked && response.finishReason !== "length") {
|
|
49341
|
+
if (replyEnds && !leaked && response.finishReason !== "length" && response.content.trim() !== "") {
|
|
49271
49342
|
session.appendAll(codec.serializeAssistant(split.content, split.reasoning, parsed));
|
|
49272
49343
|
checkpoint();
|
|
49273
49344
|
const reply = split.content.trim();
|
|
@@ -49420,7 +49491,20 @@ Repeat that summary verbatim with \`confirm: true\`, or keep working.`,
|
|
|
49420
49491
|
session.appendAll(codec.serializeAssistant(split.content, split.reasoning, parsed, calls));
|
|
49421
49492
|
let anyFailure = false;
|
|
49422
49493
|
let combinedOutput = "";
|
|
49423
|
-
for (const call of calls) {
|
|
49494
|
+
for (const [index, call] of calls.entries()) {
|
|
49495
|
+
if (signal?.aborted) {
|
|
49496
|
+
for (const skipped of calls.slice(index)) {
|
|
49497
|
+
session.appendAll(codec.serializeObservation({
|
|
49498
|
+
callId: skipped.id,
|
|
49499
|
+
name: skipped.name,
|
|
49500
|
+
arguments: skipped.arguments,
|
|
49501
|
+
output: "Tool call not executed: the session was cancelled before this call started.",
|
|
49502
|
+
ok: false
|
|
49503
|
+
}));
|
|
49504
|
+
}
|
|
49505
|
+
checkpoint();
|
|
49506
|
+
return finish("aborted");
|
|
49507
|
+
}
|
|
49424
49508
|
emit({ type: "tool_start", call });
|
|
49425
49509
|
checkpoint({
|
|
49426
49510
|
id: call.id,
|
|
@@ -49446,6 +49530,7 @@ Repeat that summary verbatim with \`confirm: true\`, or keep working.`,
|
|
|
49446
49530
|
if (!result.ok) anyFailure = true;
|
|
49447
49531
|
checkpoint();
|
|
49448
49532
|
}
|
|
49533
|
+
if (signal?.aborted) return finish("aborted");
|
|
49449
49534
|
const verdict = guard.observe(LoopGuard.signature(calls), combinedOutput);
|
|
49450
49535
|
if (verdict.tripped) {
|
|
49451
49536
|
emit({ type: "loop_detected", signature: verdict.signature.slice(0, 120), repeats: verdict.repeats });
|
|
@@ -52203,8 +52288,12 @@ var Composer = class {
|
|
|
52203
52288
|
* Claude Code's behaviour, and for the same reason: a pasted stack trace
|
|
52204
52289
|
* or file turns the composer into a wall the person cannot see their own
|
|
52205
52290
|
* words in. The text goes to the model whole when the draft is sent.
|
|
52291
|
+
*
|
|
52292
|
+
* Line breaks are normalized to LF first: terminals send a pasted break as
|
|
52293
|
+
* CR (xterm.js) or CRLF, and a raw CR would overwrite rows when drawn.
|
|
52206
52294
|
*/
|
|
52207
|
-
paste(
|
|
52295
|
+
paste(raw) {
|
|
52296
|
+
const text = raw.replace(/\r\n?/g, "\n");
|
|
52208
52297
|
const lines = text.split("\n").length;
|
|
52209
52298
|
if (lines <= PASTE_COLLAPSE_LINES && text.length <= PASTE_COLLAPSE_CHARS) {
|
|
52210
52299
|
this.insert(text);
|
|
@@ -53576,7 +53665,7 @@ function installCommand(version2) {
|
|
|
53576
53665
|
|
|
53577
53666
|
// packages/cli/src/login.ts
|
|
53578
53667
|
import { homedir as homedir3 } from "node:os";
|
|
53579
|
-
var KEY_PAGE =
|
|
53668
|
+
var KEY_PAGE = PROVIDERS.infron.keyPage;
|
|
53580
53669
|
async function verifyApiKey(opts) {
|
|
53581
53670
|
const fetchImpl = opts.fetchImpl ?? globalThis.fetch;
|
|
53582
53671
|
const endpoint = normalizeEndpoint(opts.endpoint);
|
|
@@ -53616,15 +53705,14 @@ async function serverMessage(res) {
|
|
|
53616
53705
|
}
|
|
53617
53706
|
function normaliseKeyInput(raw) {
|
|
53618
53707
|
let s = raw.trim();
|
|
53619
|
-
s = s.replace(new RegExp(`^(?:export\\s+)
|
|
53708
|
+
s = s.replace(new RegExp(`^(?:export\\s+)?(?:${ENV_API_KEY}|${ENV_MORPHFACTORY_API_KEY})\\s*=\\s*`), "");
|
|
53620
53709
|
if (s.startsWith('"') && s.endsWith('"') || s.startsWith("'") && s.endsWith("'")) s = s.slice(1, -1);
|
|
53621
53710
|
return s.trim();
|
|
53622
53711
|
}
|
|
53623
|
-
function loginLines(envPath, home = homedir3()) {
|
|
53712
|
+
function loginLines(envPath, home = homedir3(), provider = "infron") {
|
|
53624
53713
|
const shown = envPath.startsWith(home + "/") ? `~${envPath.slice(home.length)}` : envPath;
|
|
53625
53714
|
return [
|
|
53626
|
-
`Get one at ${
|
|
53627
|
-
"Motif-3 is free there through September 2026.",
|
|
53715
|
+
`Get one at ${PROVIDERS[provider].keyPage}`,
|
|
53628
53716
|
`The key is checked with the endpoint and saved to ${shown},`,
|
|
53629
53717
|
"readable only by you and never shown to the model."
|
|
53630
53718
|
];
|
|
@@ -53770,9 +53858,15 @@ var COMMANDS = [
|
|
|
53770
53858
|
description: "probe the endpoint: auth, parsers, cache, channels",
|
|
53771
53859
|
run: async (ctx) => ok("/doctor", await ctx.doctor())
|
|
53772
53860
|
},
|
|
53861
|
+
{
|
|
53862
|
+
name: "provider",
|
|
53863
|
+
description: "choose Infron or Morphfactory (BETA)",
|
|
53864
|
+
usage: "[infron|morphfactory]",
|
|
53865
|
+
run: (ctx, args) => ctx.provider?.(args) ?? fail("/provider", "Provider selection requires an interactive session.")
|
|
53866
|
+
},
|
|
53773
53867
|
{
|
|
53774
53868
|
name: "login",
|
|
53775
|
-
description: "paste
|
|
53869
|
+
description: "paste the selected provider\u2019s API key; it is checked against the endpoint and saved to ~/.motif/.env",
|
|
53776
53870
|
run: async (ctx) => ok("/login", await ctx.login())
|
|
53777
53871
|
},
|
|
53778
53872
|
{
|
|
@@ -53797,7 +53891,9 @@ var COMMANDS = [
|
|
|
53797
53891
|
run: (ctx, args) => {
|
|
53798
53892
|
if (args === "") return ok("/endpoint", [ctx.settings.endpoint]);
|
|
53799
53893
|
if (!/^https?:\/\//.test(args)) return fail("/endpoint", `not a URL: ${args}`);
|
|
53800
|
-
|
|
53894
|
+
const endpoint = args.replace(/\/+$/, "").replace(/\/v1$/, "");
|
|
53895
|
+
if (ctx.setEndpoint) ctx.setEndpoint(endpoint);
|
|
53896
|
+
else ctx.settings.endpoint = endpoint;
|
|
53801
53897
|
return ok("/endpoint", [
|
|
53802
53898
|
`endpoint set to ${ctx.settings.endpoint} for the next task`,
|
|
53803
53899
|
...saved(ctx, "endpoint", ctx.settings.endpoint)
|
|
@@ -54134,6 +54230,7 @@ var CONFIG_FIELDS = [
|
|
|
54134
54230
|
{ key: "maxOutputTokens", label: "Max output tokens", detail: "Positive integer per model step, or off to use the server default." },
|
|
54135
54231
|
{ key: "seed", label: "Sampling seed", detail: "Integer >= 0, or off. The endpoint must support seeded sampling." },
|
|
54136
54232
|
{ key: "compactAt", label: "Compact at", detail: "Context fraction from 0.1 to 1 at which automatic compaction runs." },
|
|
54233
|
+
{ key: "provider", label: "Provider", choices: ["infron", "morphfactory"], detail: "Infron or Morphfactory (BETA). Switches endpoint, model and the provider\u2019s own API key; /login adds a missing key." },
|
|
54137
54234
|
{ key: "theme", label: "Theme", choices: Object.keys(THEMES), detail: "Terminal color palette. Applies immediately; NO_COLOR takes precedence." }
|
|
54138
54235
|
];
|
|
54139
54236
|
function configField(key) {
|
|
@@ -54786,6 +54883,7 @@ async function doctor(opts) {
|
|
|
54786
54883
|
const fetchImpl = opts.fetchImpl ?? globalThis.fetch;
|
|
54787
54884
|
const endpoint = opts.endpoint.replace(/\/+$/, "").replace(/\/v1$/, "");
|
|
54788
54885
|
const checks = [];
|
|
54886
|
+
const apiKeyEnv = apiKeyEnvForEndpoint(endpoint);
|
|
54789
54887
|
const headers = { "content-type": "application/json" };
|
|
54790
54888
|
if (opts.apiKey) headers["authorization"] = `Bearer ${opts.apiKey}`;
|
|
54791
54889
|
const sandbox = detectSandbox();
|
|
@@ -54802,7 +54900,7 @@ async function doctor(opts) {
|
|
|
54802
54900
|
name: "api key",
|
|
54803
54901
|
state: "warn",
|
|
54804
54902
|
detail: "none \u2014 requests go out unauthenticated",
|
|
54805
|
-
fix:
|
|
54903
|
+
fix: `set ${apiKeyEnv} in the environment or in a .env file (not needed for a local server without auth)`
|
|
54806
54904
|
}
|
|
54807
54905
|
);
|
|
54808
54906
|
let models = null;
|
|
@@ -54816,7 +54914,7 @@ async function doctor(opts) {
|
|
|
54816
54914
|
name: "endpoint",
|
|
54817
54915
|
state: "fail",
|
|
54818
54916
|
detail: `${endpoint} returned ${res.status}`,
|
|
54819
|
-
fix: res.status === 401 || res.status === 403 ?
|
|
54917
|
+
fix: res.status === 401 || res.status === 403 ? `the endpoint refused the credentials; check ${apiKeyEnv}` : "start the server, or point --endpoint somewhere else"
|
|
54820
54918
|
});
|
|
54821
54919
|
return checks;
|
|
54822
54920
|
}
|
|
@@ -54900,7 +54998,7 @@ async function doctor(opts) {
|
|
|
54900
54998
|
name: "authentication",
|
|
54901
54999
|
state: "fail",
|
|
54902
55000
|
detail: `the endpoint refused the request (${res.status}${text ? `: ${text}` : ""})`,
|
|
54903
|
-
fix: opts.apiKey ?
|
|
55001
|
+
fix: opts.apiKey ? `the key was sent and rejected; check ${apiKeyEnv}` : `set ${apiKeyEnv}`
|
|
54904
55002
|
});
|
|
54905
55003
|
return checks;
|
|
54906
55004
|
}
|
|
@@ -55409,7 +55507,7 @@ var ToolExecutor = class {
|
|
|
55409
55507
|
return runBash(
|
|
55410
55508
|
str2(args, "command"),
|
|
55411
55509
|
cwd,
|
|
55412
|
-
(num(args, "timeout_s") ??
|
|
55510
|
+
(num(args, "timeout_s") ?? this.timeoutMs / 1e3) * 1e3,
|
|
55413
55511
|
this.policy,
|
|
55414
55512
|
() => this.scratchDir(),
|
|
55415
55513
|
signal
|
|
@@ -58156,7 +58254,7 @@ var PLACEHOLDER = "type a task, / for commands";
|
|
|
58156
58254
|
var IDLE_HINT = "";
|
|
58157
58255
|
var RUNNING_HINT = "esc to interrupt";
|
|
58158
58256
|
var CTRL_C_WINDOW_MS = 2e3;
|
|
58159
|
-
var BLOCKED_WHILE_RUNNING = /* @__PURE__ */ new Set(["new", "clear", "channel", "resume", "cwd", "compact"]);
|
|
58257
|
+
var BLOCKED_WHILE_RUNNING = /* @__PURE__ */ new Set(["new", "clear", "channel", "resume", "cwd", "compact", "provider"]);
|
|
58160
58258
|
var MENU_ITEMS = COMMANDS.map((c) => ({
|
|
58161
58259
|
name: c.name,
|
|
58162
58260
|
description: c.description,
|
|
@@ -58176,6 +58274,9 @@ var Chat = class {
|
|
|
58176
58274
|
this.projectNotes = opts.projectNotes;
|
|
58177
58275
|
this.apiKey = opts.apiKey;
|
|
58178
58276
|
this.apiKeySource = opts.apiKeySource;
|
|
58277
|
+
this.requireKey = opts.requireKey === true;
|
|
58278
|
+
this.providerCredentials = { ...opts.providerCredentials };
|
|
58279
|
+
this.cacheProviderCredential();
|
|
58179
58280
|
this.now = opts.now ?? (() => Date.now());
|
|
58180
58281
|
this.billing = new InfronBilling({
|
|
58181
58282
|
fetchImpl: opts.balanceFetch,
|
|
@@ -58227,6 +58328,8 @@ var Chat = class {
|
|
|
58227
58328
|
apiKey;
|
|
58228
58329
|
apiKeySource;
|
|
58229
58330
|
apiKeyVerified = false;
|
|
58331
|
+
requireKey;
|
|
58332
|
+
providerCredentials;
|
|
58230
58333
|
authGeneration = 0;
|
|
58231
58334
|
verifyingLogin = null;
|
|
58232
58335
|
billing;
|
|
@@ -58287,7 +58390,7 @@ var Chat = class {
|
|
|
58287
58390
|
}
|
|
58288
58391
|
this.screen.setLabel(this.settings.model);
|
|
58289
58392
|
this.screen.setTitle(`motif \xB7 ${this.settings.cwd.split("/").pop() ?? this.settings.cwd}`);
|
|
58290
|
-
if (this.apiKey === void 0 && !this.opts.
|
|
58393
|
+
if (this.apiKey === void 0 && !this.requireKey && !this.opts.chooseProvider) {
|
|
58291
58394
|
this.screen.append({
|
|
58292
58395
|
kind: "notice",
|
|
58293
58396
|
level: "warn",
|
|
@@ -58301,6 +58404,17 @@ var Chat = class {
|
|
|
58301
58404
|
}
|
|
58302
58405
|
/** What happens before the first prompt is free: the login, the resumed conversation, the first task. */
|
|
58303
58406
|
async start() {
|
|
58407
|
+
if (this.opts.chooseProvider) {
|
|
58408
|
+
const choice = await this.chooseProvider();
|
|
58409
|
+
if (this.quitting) return;
|
|
58410
|
+
if (choice === null) return;
|
|
58411
|
+
const result = this.switchProvider(choice);
|
|
58412
|
+
if (result.error) {
|
|
58413
|
+
this.screen.append({ kind: "notice", level: "error", text: result.lines.join(" ") });
|
|
58414
|
+
this.refresh();
|
|
58415
|
+
return;
|
|
58416
|
+
}
|
|
58417
|
+
}
|
|
58304
58418
|
void this.billing.refresh();
|
|
58305
58419
|
if (this.needsLogin) {
|
|
58306
58420
|
const lines = await this.login("startup");
|
|
@@ -58609,7 +58723,7 @@ var Chat = class {
|
|
|
58609
58723
|
return this.opts.envPath ?? defaultEnvPath();
|
|
58610
58724
|
}
|
|
58611
58725
|
get needsLogin() {
|
|
58612
|
-
return this.
|
|
58726
|
+
return this.requireKey && this.apiKey === void 0;
|
|
58613
58727
|
}
|
|
58614
58728
|
/** Take over the prompt for one question; resolves with the index chosen, or null on esc. */
|
|
58615
58729
|
askChoice(title, lines, options, wrap2 = false) {
|
|
@@ -58749,12 +58863,19 @@ var Chat = class {
|
|
|
58749
58863
|
this.invalidateAuthentication();
|
|
58750
58864
|
const generation = this.authGeneration;
|
|
58751
58865
|
const endpoint = this.settings.endpoint;
|
|
58752
|
-
const
|
|
58866
|
+
const model = this.settings.model;
|
|
58867
|
+
const provider = providerForEndpoint(endpoint) ?? "infron";
|
|
58868
|
+
const label3 = PROVIDERS[provider].label;
|
|
58869
|
+
const keyEnv = apiKeyEnvForEndpoint(endpoint);
|
|
58870
|
+
const title = reason === "command" ? `Paste your ${label3} API key` : reason === "task" ? "An API key is needed before the task can run" : `Paste your ${label3} API key to get started`;
|
|
58753
58871
|
const cancelHint = reason === "command" ? "enter to check and save \xB7 esc to cancel" : "enter to check and save \xB7 esc to skip for now";
|
|
58754
58872
|
for (; ; ) {
|
|
58755
|
-
const raw = await this.askSecret(title, loginLines(this.envPath), "key \u203A ", cancelHint);
|
|
58873
|
+
const raw = await this.askSecret(title, loginLines(this.envPath, void 0, provider), "key \u203A ", cancelHint);
|
|
58756
58874
|
if (raw === null) {
|
|
58757
|
-
return reason === "command" ? ["login cancelled"] : [`no key entered; /login when you have one, or put
|
|
58875
|
+
return reason === "command" ? ["login cancelled"] : [`no key entered; /login when you have one, or put ${keyEnv} in ${this.envPath}`];
|
|
58876
|
+
}
|
|
58877
|
+
if (this.quitting || generation !== this.authGeneration || endpoint !== this.settings.endpoint) {
|
|
58878
|
+
return ["login cancelled because the session or endpoint changed; /login to try again"];
|
|
58758
58879
|
}
|
|
58759
58880
|
const key = normaliseKeyInput(raw);
|
|
58760
58881
|
if (key === "") continue;
|
|
@@ -58762,7 +58883,7 @@ var Chat = class {
|
|
|
58762
58883
|
this.screen.setActivity("Checking the key\u2026");
|
|
58763
58884
|
let result;
|
|
58764
58885
|
try {
|
|
58765
|
-
result = await (this.opts.verifyKey ?? ((k) => verifyApiKey({ endpoint
|
|
58886
|
+
result = await (this.opts.verifyKey ?? ((k) => verifyApiKey({ endpoint, model, apiKey: k })))(key);
|
|
58766
58887
|
} finally {
|
|
58767
58888
|
if (this.verifyingLogin === generation) {
|
|
58768
58889
|
this.verifyingLogin = null;
|
|
@@ -58780,10 +58901,12 @@ var Chat = class {
|
|
|
58780
58901
|
this.apiKeyVerified = true;
|
|
58781
58902
|
this.syncBilling();
|
|
58782
58903
|
try {
|
|
58783
|
-
const path = saveApiKey(key, this.envPath);
|
|
58784
|
-
this.apiKeySource = `${path} (
|
|
58904
|
+
const path = saveApiKey(key, this.envPath, provider);
|
|
58905
|
+
this.apiKeySource = `${path} (${keyEnv})`;
|
|
58906
|
+
this.cacheProviderCredential();
|
|
58785
58907
|
} catch (err) {
|
|
58786
58908
|
this.apiKeySource = "this session only";
|
|
58909
|
+
this.cacheProviderCredential();
|
|
58787
58910
|
return [`the key works, but ${this.envPath} could not be written: ${err instanceof Error ? err.message : String(err)}`, "it is kept for this session only"];
|
|
58788
58911
|
}
|
|
58789
58912
|
return [`signed in \xB7 the key is saved to ${this.envPath}`];
|
|
@@ -58793,9 +58916,10 @@ var Chat = class {
|
|
|
58793
58916
|
this.invalidateAuthentication();
|
|
58794
58917
|
const source = this.apiKeySource;
|
|
58795
58918
|
const had = this.apiKey !== void 0;
|
|
58796
|
-
const removed = forgetApiKey(this.envPath);
|
|
58919
|
+
const removed = forgetApiKey(this.envPath, providerForEndpoint(this.settings.endpoint) ?? "infron");
|
|
58797
58920
|
this.apiKey = void 0;
|
|
58798
58921
|
this.apiKeySource = void 0;
|
|
58922
|
+
this.cacheProviderCredential();
|
|
58799
58923
|
this.apiKeyVerified = false;
|
|
58800
58924
|
this.billing.configure(this.settings.endpoint);
|
|
58801
58925
|
if (!had && !removed) return ["no key is set"];
|
|
@@ -59204,12 +59328,7 @@ var Chat = class {
|
|
|
59204
59328
|
this.refresh();
|
|
59205
59329
|
return;
|
|
59206
59330
|
}
|
|
59207
|
-
const previousEndpoint = this.settings.endpoint;
|
|
59208
59331
|
const out = await runSlash(text, this.context());
|
|
59209
|
-
if (previousEndpoint !== this.settings.endpoint) {
|
|
59210
|
-
this.apiKeyVerified = false;
|
|
59211
|
-
this.invalidateAuthentication();
|
|
59212
|
-
}
|
|
59213
59332
|
this.syncBilling();
|
|
59214
59333
|
if (!this.quitting && !out.silent && out.lines.length > 0) {
|
|
59215
59334
|
this.screen.append(
|
|
@@ -59599,6 +59718,7 @@ ${output.slice(0, 8e3)}
|
|
|
59599
59718
|
hooks: this.opts.hooks,
|
|
59600
59719
|
skills: this.opts.skills,
|
|
59601
59720
|
policy: policyForAgent({ root: cwd, tools: toolNames, readOnly: false }),
|
|
59721
|
+
timeoutMs: (this.settings.bashTimeout ?? 120) * 1e3,
|
|
59602
59722
|
callMcp: this.mcpInvoker("root"),
|
|
59603
59723
|
confirm: (call) => this.confirm(call),
|
|
59604
59724
|
onHook: (event, label3, ok2) => this.screen.apply({ type: "hook", event, label: label3, ok: ok2 }),
|
|
@@ -59623,6 +59743,7 @@ ${output.slice(0, 8e3)}
|
|
|
59623
59743
|
const childExecutor = new ToolExecutor({
|
|
59624
59744
|
cwd: this.settings.cwd,
|
|
59625
59745
|
skills: this.opts.skills,
|
|
59746
|
+
timeoutMs: (this.settings.bashTimeout ?? 120) * 1e3,
|
|
59626
59747
|
callMcp: this.mcpInvoker(childScope.scopeId),
|
|
59627
59748
|
confirm: (call) => this.confirm(call),
|
|
59628
59749
|
policy: policyForAgent({
|
|
@@ -59706,6 +59827,16 @@ ${output.slice(0, 8e3)}
|
|
|
59706
59827
|
config: () => this.configLines(),
|
|
59707
59828
|
openPanel: (tab) => this.openPanel(tab),
|
|
59708
59829
|
configure: (args) => this.configure(args),
|
|
59830
|
+
provider: (args) => this.providerCommand(args),
|
|
59831
|
+
setEndpoint: (endpoint) => {
|
|
59832
|
+
if (endpoint === this.settings.endpoint) return;
|
|
59833
|
+
const previous = this.settings.endpoint;
|
|
59834
|
+
this.settings.endpoint = endpoint;
|
|
59835
|
+
this.rebindProviderCredential(previous);
|
|
59836
|
+
this.apiKeyVerified = false;
|
|
59837
|
+
this.invalidateAuthentication();
|
|
59838
|
+
this.syncBilling();
|
|
59839
|
+
},
|
|
59709
59840
|
stats: () => statsRows(this.insights()).flatMap((r) => [`${r.label} ${r.value ?? ""}`, ...r.detail ? [` ${r.detail}`] : []]),
|
|
59710
59841
|
usage: () => [...balanceRows(this.billing.state), ...usageRows(this.insights())].flatMap((r) => [`${r.label} ${r.value ?? ""}`, ...r.detail ? [` ${r.detail}`] : []]),
|
|
59711
59842
|
themes: () => Object.entries(THEMES).map(([name, t]) => `${name.padEnd(10)} ${t.description}`),
|
|
@@ -59764,6 +59895,7 @@ ${output.slice(0, 8e3)}
|
|
|
59764
59895
|
};
|
|
59765
59896
|
}
|
|
59766
59897
|
settingSource(key) {
|
|
59898
|
+
if (key === "provider") return this.settingSource("endpoint");
|
|
59767
59899
|
return this.changedSettings.get(key) ?? this.opts.settingSources?.[key] ?? this.opts.settingsInfo?.sources[key] ?? "default";
|
|
59768
59900
|
}
|
|
59769
59901
|
rememberSetting(key, value) {
|
|
@@ -59772,6 +59904,7 @@ ${output.slice(0, 8e3)}
|
|
|
59772
59904
|
return path;
|
|
59773
59905
|
}
|
|
59774
59906
|
configValue(key) {
|
|
59907
|
+
if (key === "provider") return providerForEndpoint(this.settings.endpoint) ?? "custom";
|
|
59775
59908
|
if (key === "thinking") return String(this.screen.thinkingShown);
|
|
59776
59909
|
if (key === "verbose") return String(this.screen.verboseOutput);
|
|
59777
59910
|
return String(this.settings[key] ?? "off");
|
|
@@ -59784,17 +59917,19 @@ ${output.slice(0, 8e3)}
|
|
|
59784
59917
|
}
|
|
59785
59918
|
applyConfig(field, raw) {
|
|
59786
59919
|
const fail5 = (message2) => ({ title: "/config", error: true, lines: [message2] });
|
|
59787
|
-
if ((this.active || this.shellBusy || this.compacting) && !["thinking", "verbose", "theme"].includes(field.key)) {
|
|
59920
|
+
if ((this.active || this.settlingTask || this.shellBusy || this.compacting) && !["thinking", "verbose", "theme"].includes(field.key)) {
|
|
59788
59921
|
return fail5("Wait for the running task to finish, or close this panel and press Esc to interrupt it.");
|
|
59789
59922
|
}
|
|
59790
59923
|
let value;
|
|
59791
59924
|
let path;
|
|
59792
59925
|
try {
|
|
59793
59926
|
value = parseConfigValue(field, raw);
|
|
59927
|
+
if (field.key === "provider") return this.switchProvider(value);
|
|
59794
59928
|
path = this.rememberSetting(field.key, value);
|
|
59795
59929
|
} catch (err) {
|
|
59796
59930
|
return fail5(err instanceof Error ? err.message : String(err));
|
|
59797
59931
|
}
|
|
59932
|
+
const previousEndpoint = this.settings.endpoint;
|
|
59798
59933
|
switch (field.key) {
|
|
59799
59934
|
case "thinking":
|
|
59800
59935
|
if (this.screen.thinkingShown !== value) this.screen.toggleThinking();
|
|
@@ -59819,6 +59954,7 @@ ${output.slice(0, 8e3)}
|
|
|
59819
59954
|
break;
|
|
59820
59955
|
}
|
|
59821
59956
|
if (field.key === "endpoint") {
|
|
59957
|
+
this.rebindProviderCredential(previousEndpoint);
|
|
59822
59958
|
this.apiKeyVerified = false;
|
|
59823
59959
|
this.invalidateAuthentication();
|
|
59824
59960
|
this.syncBilling();
|
|
@@ -59832,6 +59968,66 @@ ${output.slice(0, 8e3)}
|
|
|
59832
59968
|
]
|
|
59833
59969
|
};
|
|
59834
59970
|
}
|
|
59971
|
+
get providerLabel() {
|
|
59972
|
+
const provider = providerForEndpoint(this.settings.endpoint);
|
|
59973
|
+
return provider ? PROVIDERS[provider].label : "Custom endpoint";
|
|
59974
|
+
}
|
|
59975
|
+
cacheProviderCredential() {
|
|
59976
|
+
const provider = providerForEndpoint(this.settings.endpoint);
|
|
59977
|
+
if (provider) this.providerCredentials[provider] = { apiKey: this.apiKey, source: this.apiKeySource };
|
|
59978
|
+
}
|
|
59979
|
+
rebindProviderCredential(previousEndpoint) {
|
|
59980
|
+
const previous = providerForEndpoint(previousEndpoint);
|
|
59981
|
+
const next = providerForEndpoint(this.settings.endpoint);
|
|
59982
|
+
if (previous === next) return;
|
|
59983
|
+
if (next) this.requireKey = true;
|
|
59984
|
+
if (previous !== "morphfactory" && next !== "morphfactory" && !(next && this.apiKey === void 0)) return;
|
|
59985
|
+
if (previous) this.providerCredentials[previous] = { apiKey: this.apiKey, source: this.apiKeySource };
|
|
59986
|
+
const credential = next ? this.providerCredentials[next] : void 0;
|
|
59987
|
+
this.apiKey = credential?.apiKey;
|
|
59988
|
+
this.apiKeySource = credential?.source;
|
|
59989
|
+
this.requireKey = next !== void 0;
|
|
59990
|
+
}
|
|
59991
|
+
chooseProvider() {
|
|
59992
|
+
const providers = Object.keys(PROVIDERS);
|
|
59993
|
+
return this.askChoice("Choose a provider", ["Both providers serve Motif-3. Each uses its own API key.", "Change this later with /provider or /config provider."], providers.map((id, i) => `${i + 1}. ${PROVIDERS[id].label}`), true).then((choice) => choice === null ? null : providers[choice]);
|
|
59994
|
+
}
|
|
59995
|
+
switchProvider(provider) {
|
|
59996
|
+
const selected = PROVIDERS[provider];
|
|
59997
|
+
try {
|
|
59998
|
+
this.rememberSetting("model", selected.model);
|
|
59999
|
+
this.rememberSetting("endpoint", selected.endpoint);
|
|
60000
|
+
} catch (err) {
|
|
60001
|
+
return { title: "/provider", error: true, lines: [err instanceof Error ? err.message : String(err)] };
|
|
60002
|
+
}
|
|
60003
|
+
this.cacheProviderCredential();
|
|
60004
|
+
this.invalidateAuthentication();
|
|
60005
|
+
this.settings.endpoint = selected.endpoint;
|
|
60006
|
+
this.settings.model = selected.model;
|
|
60007
|
+
this.apiKey = this.providerCredentials[provider]?.apiKey;
|
|
60008
|
+
this.apiKeySource = this.providerCredentials[provider]?.source;
|
|
60009
|
+
this.apiKeyVerified = false;
|
|
60010
|
+
this.requireKey = true;
|
|
60011
|
+
this.screen.setLabel(selected.model);
|
|
60012
|
+
this.syncBilling();
|
|
60013
|
+
return { title: "/provider", lines: [
|
|
60014
|
+
`Provider: ${selected.label} \xB7 ${this.apiKey ? "API key loaded" : "no API key; use /login"}.`,
|
|
60015
|
+
`${selected.endpoint} \xB7 ${selected.model}`,
|
|
60016
|
+
"Saved defaults can be overridden by startup flags, environment or trusted project settings."
|
|
60017
|
+
] };
|
|
60018
|
+
}
|
|
60019
|
+
async providerCommand(args) {
|
|
60020
|
+
if (this.active || this.settlingTask || this.shellBusy || this.compacting) return { title: "/provider", error: true, lines: ["Wait for the running task to finish before changing provider."] };
|
|
60021
|
+
if (args && !Object.hasOwn(PROVIDERS, args)) return { title: "/provider", error: true, lines: ["Choose infron or morphfactory."] };
|
|
60022
|
+
const provider = args ? args : await this.chooseProvider();
|
|
60023
|
+
if (provider === null || this.quitting) return { title: "/provider", lines: ["Provider selection cancelled."] };
|
|
60024
|
+
const result = this.switchProvider(provider);
|
|
60025
|
+
if (!result.error && this.needsLogin) {
|
|
60026
|
+
result.lines.push(...await this.login("command"));
|
|
60027
|
+
if (this.apiKey && providerForEndpoint(this.settings.endpoint) === provider) result.lines[0] = `Provider: ${PROVIDERS[provider].label} \xB7 API key loaded.`;
|
|
60028
|
+
}
|
|
60029
|
+
return result;
|
|
60030
|
+
}
|
|
59835
60031
|
invalidateAuthentication() {
|
|
59836
60032
|
this.authGeneration++;
|
|
59837
60033
|
if (this.verifyingLogin !== null) {
|
|
@@ -59862,9 +60058,10 @@ ${output.slice(0, 8e3)}
|
|
|
59862
60058
|
}
|
|
59863
60059
|
panelView() {
|
|
59864
60060
|
const panel = this.panel;
|
|
59865
|
-
const rows = panel.tab === "config" ? CONFIG_FIELDS.map((f) => ({ label: f.label, value: this.configValue(f.key), detail: `${f.detail}${f.key === "permissions" && this.alwaysAllowed.size ? ` Already allowed this session: ${[...this.alwaysAllowed].join(", ")}.` : ""} Source: ${this.settingSource(f.key)}.` })) : panel.tab === "status" ? [
|
|
60061
|
+
const rows = panel.tab === "config" ? CONFIG_FIELDS.map((f) => ({ label: f.label, value: f.key === "provider" ? this.providerLabel : this.configValue(f.key), detail: `${f.detail}${f.key === "permissions" && this.alwaysAllowed.size ? ` Already allowed this session: ${[...this.alwaysAllowed].join(", ")}.` : ""} Source: ${this.settingSource(f.key)}.` })) : panel.tab === "status" ? [
|
|
59866
60062
|
{ label: "Version", value: this.opts.version },
|
|
59867
60063
|
{ label: "State", value: this.active ? "Running" : this.shellBusy ? "Shell running" : this.compacting ? "Compacting" : "Ready", tone: "good" },
|
|
60064
|
+
{ label: "Provider", value: this.providerLabel },
|
|
59868
60065
|
{ label: "Model", value: this.settings.model },
|
|
59869
60066
|
{ label: "Endpoint", value: this.settings.endpoint },
|
|
59870
60067
|
{ label: "Authentication", value: this.apiKey ? this.apiKeyVerified ? "Verified this session" : "API key loaded" : "No API key \xB7 /login" },
|
|
@@ -59994,6 +60191,7 @@ ${output.slice(0, 8e3)}
|
|
|
59994
60191
|
const s = this.settings;
|
|
59995
60192
|
const src = (key) => this.settingSource(key);
|
|
59996
60193
|
const rows = [
|
|
60194
|
+
["provider", this.providerLabel, src("endpoint")],
|
|
59997
60195
|
["model", s.model, src("model")],
|
|
59998
60196
|
["endpoint", s.endpoint, src("endpoint")],
|
|
59999
60197
|
["channel", s.channel, src("channel")],
|
|
@@ -60004,7 +60202,8 @@ ${output.slice(0, 8e3)}
|
|
|
60004
60202
|
["thinking", String(this.screen.thinkingShown), src("thinking")],
|
|
60005
60203
|
["verbose", String(this.screen.verboseOutput), src("verbose")],
|
|
60006
60204
|
["compactAt", String(s.compactAt), src("compactAt")],
|
|
60007
|
-
["permissions", s.permissions, src("permissions")]
|
|
60205
|
+
["permissions", s.permissions, src("permissions")],
|
|
60206
|
+
["bashTimeout", `${s.bashTimeout ?? 120}s`, src("bashTimeout")]
|
|
60008
60207
|
];
|
|
60009
60208
|
const lines = rows.map(([k, v, from]) => `${k.padEnd(16)} ${v.padEnd(40)} ${from}`);
|
|
60010
60209
|
lines.push("");
|
|
@@ -60021,6 +60220,7 @@ ${output.slice(0, 8e3)}
|
|
|
60021
60220
|
const t = this.totals;
|
|
60022
60221
|
const fmt = (n) => n.toLocaleString("en-US");
|
|
60023
60222
|
return [
|
|
60223
|
+
`provider ${this.providerLabel}`,
|
|
60024
60224
|
`model ${s.model}`,
|
|
60025
60225
|
`endpoint ${s.endpoint}`,
|
|
60026
60226
|
`channel ${s.channel} (policy ${this.opts.channelPolicy})`,
|
|
@@ -60251,7 +60451,8 @@ var KEYS2 = [
|
|
|
60251
60451
|
"thinking",
|
|
60252
60452
|
"verbose",
|
|
60253
60453
|
"compactAt",
|
|
60254
|
-
"permissions"
|
|
60454
|
+
"permissions",
|
|
60455
|
+
"bashTimeout"
|
|
60255
60456
|
];
|
|
60256
60457
|
function userSettingsPath(home = homedir7()) {
|
|
60257
60458
|
return join13(home, ".motif", "settings.json");
|
|
@@ -60291,6 +60492,7 @@ function parseSettings(text) {
|
|
|
60291
60492
|
int2("maxTurns", 1);
|
|
60292
60493
|
int2("maxOutputTokens", 1);
|
|
60293
60494
|
int2("seed", 0);
|
|
60495
|
+
int2("bashTimeout", 1);
|
|
60294
60496
|
for (const key of ["thinking", "verbose"]) {
|
|
60295
60497
|
if (obj2[key] !== void 0) {
|
|
60296
60498
|
if (typeof obj2[key] === "boolean") values[key] = obj2[key];
|
|
@@ -62461,7 +62663,7 @@ function pluginConnectionUi(signal) {
|
|
|
62461
62663
|
}
|
|
62462
62664
|
|
|
62463
62665
|
// packages/cli/src/main.ts
|
|
62464
|
-
var VERSION = "0.4.
|
|
62666
|
+
var VERSION = "0.4.2";
|
|
62465
62667
|
var SHORT_FLAGS = { p: "print", c: "continue", i: "interactive", v: "verbose", h: "help" };
|
|
62466
62668
|
var BOOLEAN_FLAGS = /* @__PURE__ */ new Set([
|
|
62467
62669
|
"print",
|
|
@@ -62669,7 +62871,7 @@ var HELP = `motif ${VERSION} \u2014 a coding agent built for Motif-3 (unofficial
|
|
|
62669
62871
|
motif open the interactive session (a terminal is required)
|
|
62670
62872
|
motif "<task>" run one task and exit; add --interactive to stay
|
|
62671
62873
|
motif -p "<question>" print only the final reply, for scripts and pipes (also --print)
|
|
62672
|
-
motif login paste
|
|
62874
|
+
motif login paste the selected provider's API key; it is checked and saved to ~/.motif/.env
|
|
62673
62875
|
motif logout remove the saved key
|
|
62674
62876
|
motif doctor check the endpoint, the credentials and what the server produces
|
|
62675
62877
|
motif sessions list recorded sessions
|
|
@@ -62697,6 +62899,7 @@ var HELP = `motif ${VERSION} \u2014 a coding agent built for Motif-3 (unofficial
|
|
|
62697
62899
|
motif corpus-render render a corpus JSONL to prompt text, as the harness would
|
|
62698
62900
|
|
|
62699
62901
|
Flags
|
|
62902
|
+
--provider <id> infron | morphfactory (BETA); sets endpoint and model defaults
|
|
62700
62903
|
--endpoint <url> model server (default ${DEFAULT_ENDPOINT}; a trailing /v1 is accepted)
|
|
62701
62904
|
--model <name> model id to request (default ${DEFAULT_MODEL})
|
|
62702
62905
|
--env-file <path> read MOTIF_* settings from this file first
|
|
@@ -62707,6 +62910,7 @@ Flags
|
|
|
62707
62910
|
--channel-policy <p> fixed | adaptive (default fixed)
|
|
62708
62911
|
--max-turns <n> turn ceiling (default 100)
|
|
62709
62912
|
--max-output-tokens <n> cap on each model step
|
|
62913
|
+
--bash-timeout <s> seconds a shell command may run when the model sets no timeout (default 120)
|
|
62710
62914
|
--seed <n> sampling seed, passed to the server
|
|
62711
62915
|
--cwd <path> working directory
|
|
62712
62916
|
--journal <path> write the session record here instead of .motif/sessions
|
|
@@ -62724,9 +62928,11 @@ distil flags
|
|
|
62724
62928
|
--include-children also export subagent scopes
|
|
62725
62929
|
|
|
62726
62930
|
Connection
|
|
62727
|
-
The first session
|
|
62728
|
-
and saves it to ~/.motif/.env;
|
|
62729
|
-
|
|
62931
|
+
The first session offers Infron or Morphfactory (BETA), checks your API key
|
|
62932
|
+
and saves it to ~/.motif/.env; use /provider to switch inside a session.
|
|
62933
|
+
'motif login --provider morphfactory' signs in outside a session.
|
|
62934
|
+
MOTIF_API_KEY (Infron), MOTIF_MORPHFACTORY_API_KEY, MOTIF_ENDPOINT and
|
|
62935
|
+
MOTIF_MODEL are read from the environment,
|
|
62730
62936
|
then from ./.env, then from ~/.motif/.env \u2014 MOTIF_* keys only, and never into
|
|
62731
62937
|
the environment. The key is sent as a bearer token and is withheld from every
|
|
62732
62938
|
command the agent runs.
|
|
@@ -62756,13 +62962,14 @@ channel after repeated parse failures, and that move restarts the conversation
|
|
|
62756
62962
|
because the transcript formats are not interchangeable.
|
|
62757
62963
|
`;
|
|
62758
62964
|
function keyRequired(endpoint) {
|
|
62759
|
-
return endpoint
|
|
62965
|
+
return providerForEndpoint(endpoint) !== void 0;
|
|
62760
62966
|
}
|
|
62761
62967
|
async function loginAtTerminal(endpoint, model) {
|
|
62762
62968
|
const path = defaultEnvPath();
|
|
62969
|
+
const provider = providerForEndpoint(endpoint) ?? "infron";
|
|
62763
62970
|
if (process.stdin.isTTY) {
|
|
62764
62971
|
process.stdout.write(
|
|
62765
|
-
`Paste your
|
|
62972
|
+
`Paste your ${PROVIDERS[provider].label} API key. Get one at ${PROVIDERS[provider].keyPage}.
|
|
62766
62973
|
It is checked against ${endpoint}, then saved to ${path} (readable only by you).
|
|
62767
62974
|
`
|
|
62768
62975
|
);
|
|
@@ -62779,7 +62986,7 @@ It is checked against ${endpoint}, then saved to ${path} (readable only by you).
|
|
|
62779
62986
|
`);
|
|
62780
62987
|
return null;
|
|
62781
62988
|
}
|
|
62782
|
-
saveApiKey(key, path);
|
|
62989
|
+
saveApiKey(key, path, provider);
|
|
62783
62990
|
process.stdout.write(`signed in \xB7 the key is saved to ${path}
|
|
62784
62991
|
`);
|
|
62785
62992
|
const billing = new InfronBilling();
|
|
@@ -62822,12 +63029,15 @@ async function main() {
|
|
|
62822
63029
|
warn: (m) => process.stderr.write(`${m}
|
|
62823
63030
|
`)
|
|
62824
63031
|
});
|
|
63032
|
+
const provider = args.flags["provider"] === void 0 ? void 0 : flagEnum(args.flags, "provider", ["infron", "morphfactory"], "infron");
|
|
63033
|
+
const dotenvPaths = [...envFile ? [envFile] : [], ...defaultDotenvPaths()];
|
|
62825
63034
|
const connection = resolveEndpointConfig({
|
|
62826
63035
|
flags: {
|
|
63036
|
+
...provider ? { endpoint: PROVIDERS[provider].endpoint, model: PROVIDERS[provider].model } : {},
|
|
62827
63037
|
...typeof args.flags["endpoint"] === "string" ? { endpoint: args.flags["endpoint"] } : {},
|
|
62828
63038
|
...typeof args.flags["model"] === "string" ? { model: args.flags["model"] } : {}
|
|
62829
63039
|
},
|
|
62830
|
-
dotenvPaths
|
|
63040
|
+
dotenvPaths,
|
|
62831
63041
|
defaults: {
|
|
62832
63042
|
...stored.values.endpoint !== void 0 ? { endpoint: stored.values.endpoint } : {},
|
|
62833
63043
|
...stored.values.model !== void 0 ? { model: stored.values.model } : {}
|
|
@@ -62842,6 +63052,14 @@ async function main() {
|
|
|
62842
63052
|
const compactAt = stored.values.compactAt ?? 0.75;
|
|
62843
63053
|
const permissions = flagEnum(args.flags, "permissions", ["ask", "auto"], stored.values.permissions ?? "ask");
|
|
62844
63054
|
const { endpoint, model, apiKey } = connection;
|
|
63055
|
+
const providerCredentials = {};
|
|
63056
|
+
for (const id of Object.keys(PROVIDERS)) {
|
|
63057
|
+
const credentials = resolveEndpointConfig({ flags: { endpoint: PROVIDERS[id].endpoint }, dotenvPaths });
|
|
63058
|
+
providerCredentials[id] = {
|
|
63059
|
+
...credentials.apiKey !== void 0 ? { apiKey: credentials.apiKey } : {},
|
|
63060
|
+
...credentials.sources.apiKey !== void 0 ? { source: credentials.sources.apiKey } : {}
|
|
63061
|
+
};
|
|
63062
|
+
}
|
|
62845
63063
|
withholdSecrets(process.env);
|
|
62846
63064
|
let resumeFrom;
|
|
62847
63065
|
switch (args.command) {
|
|
@@ -62936,7 +63154,7 @@ async function main() {
|
|
|
62936
63154
|
}
|
|
62937
63155
|
case "logout": {
|
|
62938
63156
|
const path = defaultEnvPath();
|
|
62939
|
-
process.stdout.write(forgetApiKey(path) ? `the key was removed from ${path}
|
|
63157
|
+
process.stdout.write(forgetApiKey(path, providerForEndpoint(endpoint) ?? "infron") ? `the key was removed from ${path}
|
|
62940
63158
|
` : `no key in ${path}
|
|
62941
63159
|
`);
|
|
62942
63160
|
return 0;
|
|
@@ -62980,7 +63198,9 @@ ${"".padEnd(12)} tools: ${tools}
|
|
|
62980
63198
|
return 0;
|
|
62981
63199
|
}
|
|
62982
63200
|
case "config": {
|
|
63201
|
+
const selectedProvider = providerForEndpoint(endpoint);
|
|
62983
63202
|
const rows = [
|
|
63203
|
+
["provider", selectedProvider ? PROVIDERS[selectedProvider].label : "custom", connection.sources.endpoint],
|
|
62984
63204
|
["model", model, connection.sources.model],
|
|
62985
63205
|
["endpoint", endpoint, connection.sources.endpoint],
|
|
62986
63206
|
["channel", stored.values.channel ?? "toolcall", stored.sources.channel ?? "default"],
|
|
@@ -62991,7 +63211,8 @@ ${"".padEnd(12)} tools: ${tools}
|
|
|
62991
63211
|
["thinking", showThinking ? "shown" : "hidden", args.flags["thinking"] === true ? "flag" : stored.sources.thinking ?? "default"],
|
|
62992
63212
|
["verbose", String(args.flags["verbose"] === true || stored.values.verbose === true), args.flags["verbose"] === true ? "flag" : stored.sources.verbose ?? "default"],
|
|
62993
63213
|
["compactAt", String(compactAt), stored.sources.compactAt ?? "default"],
|
|
62994
|
-
["permissions", permissions, typeof args.flags["permissions"] === "string" ? "flag" : stored.sources.permissions ?? "default"]
|
|
63214
|
+
["permissions", permissions, typeof args.flags["permissions"] === "string" ? "flag" : stored.sources.permissions ?? "default"],
|
|
63215
|
+
["bashTimeout", `${flagInt(args.flags, "bash-timeout", stored.values.bashTimeout ?? 120, 1)}s`, args.flags["bash-timeout"] !== void 0 ? "flag" : stored.sources.bashTimeout ?? "default"]
|
|
62995
63216
|
];
|
|
62996
63217
|
for (const [k, v, from] of rows) process.stdout.write(`${k.padEnd(16)} ${v.padEnd(40)} ${from}
|
|
62997
63218
|
`);
|
|
@@ -63088,6 +63309,7 @@ user file ${stored.userPath}${existsSync16(stored.userPath) ? "" : " (absent
|
|
|
63088
63309
|
const maxTurns = flagInt(args.flags, "max-turns", stored.values.maxTurns ?? 100, 1);
|
|
63089
63310
|
const maxOutputTokens = args.flags["max-output-tokens"] !== void 0 ? flagInt(args.flags, "max-output-tokens", 0, 1) : stored.values.maxOutputTokens;
|
|
63090
63311
|
const seed = args.flags["seed"] !== void 0 ? flagInt(args.flags, "seed", 0, 0) : stored.values.seed;
|
|
63312
|
+
const bashTimeout = flagInt(args.flags, "bash-timeout", stored.values.bashTimeout ?? 120, 1);
|
|
63091
63313
|
const channelFromFlag = typeof args.flags["channel"] === "string";
|
|
63092
63314
|
if (channel !== "toolcall" && channelFromFlag && args.flags["experimental-channel"] !== true) {
|
|
63093
63315
|
throw new UsageError(
|
|
@@ -63191,7 +63413,8 @@ user file ${stored.userPath}${existsSync16(stored.userPath) ? "" : " (absent
|
|
|
63191
63413
|
cwd,
|
|
63192
63414
|
theme: applyTheme(themeName) ? themeName : "motif",
|
|
63193
63415
|
compactAt,
|
|
63194
|
-
permissions
|
|
63416
|
+
permissions,
|
|
63417
|
+
bashTimeout
|
|
63195
63418
|
},
|
|
63196
63419
|
settingsInfo: stored,
|
|
63197
63420
|
settingSources: {
|
|
@@ -63205,6 +63428,7 @@ user file ${stored.userPath}${existsSync16(stored.userPath) ? "" : " (absent
|
|
|
63205
63428
|
["seed", "seed"],
|
|
63206
63429
|
["theme", "theme"],
|
|
63207
63430
|
["thinking", "thinking"],
|
|
63431
|
+
["bashTimeout", "bash-timeout"],
|
|
63208
63432
|
["verbose", "verbose"],
|
|
63209
63433
|
["permissions", "permissions"]
|
|
63210
63434
|
].filter(([, flag]) => args.flags[flag] !== void 0).map(([key]) => [key, "flag"]))
|
|
@@ -63219,6 +63443,8 @@ user file ${stored.userPath}${existsSync16(stored.userPath) ? "" : " (absent
|
|
|
63219
63443
|
...apiKey !== void 0 ? { apiKey } : {},
|
|
63220
63444
|
...connection.sources.apiKey !== void 0 ? { apiKeySource: connection.sources.apiKey } : {},
|
|
63221
63445
|
requireKey: keyRequired(endpoint),
|
|
63446
|
+
chooseProvider: apiKey === void 0 && connection.sources.endpoint === "default" && stored.values.endpoint === void 0,
|
|
63447
|
+
providerCredentials,
|
|
63222
63448
|
envPath: defaultEnvPath(),
|
|
63223
63449
|
offerInstall: ranFromNpx(process.argv[1]) && !commandOnPath("motif"),
|
|
63224
63450
|
skills,
|
|
@@ -63270,7 +63496,7 @@ user file ${stored.userPath}${existsSync16(stored.userPath) ? "" : " (absent
|
|
|
63270
63496
|
let sessionKey = apiKey;
|
|
63271
63497
|
if (sessionKey === void 0 && keyRequired(endpoint)) {
|
|
63272
63498
|
if (!tty) {
|
|
63273
|
-
process.stderr.write(`no API key: run 'motif login', or put
|
|
63499
|
+
process.stderr.write(`no API key: run 'motif login${providerForEndpoint(endpoint) === "morphfactory" ? " --provider morphfactory" : ""}', or put ${apiKeyEnvForEndpoint(endpoint)} in ${defaultEnvPath()}
|
|
63274
63500
|
`);
|
|
63275
63501
|
return 2;
|
|
63276
63502
|
}
|
|
@@ -63285,6 +63511,7 @@ user file ${stored.userPath}${existsSync16(stored.userPath) ? "" : " (absent
|
|
|
63285
63511
|
hooks,
|
|
63286
63512
|
skills,
|
|
63287
63513
|
policy: policyForAgent({ root: cwd, tools: activeToolNames, readOnly: false }),
|
|
63514
|
+
timeoutMs: bashTimeout * 1e3,
|
|
63288
63515
|
callMcp: (server, method, values, signal, observe) => mcp.invoke(server, method, values, { scopeId: "root", signal, observe })
|
|
63289
63516
|
});
|
|
63290
63517
|
try {
|
|
@@ -63377,6 +63604,7 @@ user file ${stored.userPath}${existsSync16(stored.userPath) ? "" : " (absent
|
|
|
63377
63604
|
hooks,
|
|
63378
63605
|
skills,
|
|
63379
63606
|
policy: policyForAgent({ root: cwd, tools: activeToolNames, readOnly: false }),
|
|
63607
|
+
timeoutMs: bashTimeout * 1e3,
|
|
63380
63608
|
callMcp: (server, method, values, signal, observe) => mcp.invoke(server, method, values, { scopeId: "root", signal, observe }),
|
|
63381
63609
|
onHook: (event, label3, ok2) => emit({ type: "hook", event, label: label3, ok: ok2 }),
|
|
63382
63610
|
runAgent: async (name, prompt) => {
|
|
@@ -63399,6 +63627,7 @@ user file ${stored.userPath}${existsSync16(stored.userPath) ? "" : " (absent
|
|
|
63399
63627
|
const childExecutor = new ToolExecutor({
|
|
63400
63628
|
cwd,
|
|
63401
63629
|
skills,
|
|
63630
|
+
timeoutMs: bashTimeout * 1e3,
|
|
63402
63631
|
callMcp: (server, method, values, signal, observe) => mcp.invoke(server, method, values, { scopeId: childScope.scopeId, signal, observe }),
|
|
63403
63632
|
policy: policyForAgent({
|
|
63404
63633
|
root: cwd,
|