@muhkoo/cli 0.15.0-alpha.14 → 0.15.0-alpha.15
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 +23 -1
- package/bin/muhkoo.js +7 -1
- package/package.json +9 -5
- package/src/commands/deploy.js +87 -46
- package/src/commands/kv.js +0 -2
- package/src/commands/login.js +49 -3
- package/src/commands/logout.js +4 -2
- package/src/commands/mcp.js +28 -0
- package/src/commands/promote.js +0 -1
- package/src/commands/provision.js +17 -1
- package/src/commands/vfs.js +100 -89
- package/src/index.js +7 -3
- package/src/lib/auth.js +7 -2
- package/src/lib/bases.js +8 -0
- package/src/lib/ui.js +30 -5
- package/src/lib/vfs.js +46 -44
- package/src/lib/webLogin.js +85 -20
- package/src/mcp/node.js +90 -0
- package/src/mcp/run.js +125 -0
- package/src/mcp/secrets.js +130 -0
- package/src/mcp/server.js +87 -0
- package/src/mcp/tools.js +782 -0
package/README.md
CHANGED
|
@@ -114,7 +114,7 @@ Account login · logout · devices ls|rm · whoami
|
|
|
114
114
|
Apps apps ls|get|create|slug|rm · keys rotate · tokens ls|create|revoke
|
|
115
115
|
Backend provision · tables · agents · functions · vectors ls|get|create|rm|notices|query
|
|
116
116
|
Files vfs cd|pwd|ls|stat|tree|cat|put|get|mkdir|rm|cp|mv|find|history|restore
|
|
117
|
-
vfs import|mount|ignore · vfs sweep|
|
|
117
|
+
vfs import|mount|ignore · vfs sweep|rehome
|
|
118
118
|
vcs status|commit|log|show|diff|branch|switch|checkout|merge|restore · vcs merge --abort
|
|
119
119
|
kv ls [prefix]
|
|
120
120
|
Hosting deploy · promote · hosting status|rollback|rm-release|unpublish · domains
|
|
@@ -136,6 +136,28 @@ muhkoo agents enable <appId> <agentId> --channel general
|
|
|
136
136
|
muhkoo eject src/agent/agentApp.ts # preview an agent's prompt + tools
|
|
137
137
|
```
|
|
138
138
|
|
|
139
|
+
## Use with Claude
|
|
140
|
+
|
|
141
|
+
`muhkoo mcp` runs the CLI as an MCP server, so Claude can create apps, deploy,
|
|
142
|
+
manage functions, tables and domains, and browse your filesystem for you. It
|
|
143
|
+
uses the login on this computer: run `muhkoo login` first.
|
|
144
|
+
|
|
145
|
+
```bash
|
|
146
|
+
# Claude Code
|
|
147
|
+
claude mcp add muhkoo -- npx -y @muhkoo/cli mcp
|
|
148
|
+
|
|
149
|
+
# Claude Desktop: build the extension, then Settings → Extensions → install it
|
|
150
|
+
npm run build:mcpb # → dist/muhkoo.mcpb
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
- `deploy` goes to your app's **test** environment. Only `promote` reaches
|
|
154
|
+
production, and it, every delete, key rotation and new access token is marked
|
|
155
|
+
so Claude asks you first.
|
|
156
|
+
- Secret keys and access tokens never appear in the conversation. They are
|
|
157
|
+
saved to the project's `.muhkoo-app.json` or `~/.muhkoo/secrets/` (owner-only),
|
|
158
|
+
and Claude gets the file path.
|
|
159
|
+
- Paths on your computer must be absolute; filesystem paths start with `/`.
|
|
160
|
+
|
|
139
161
|
## Syncing a directory
|
|
140
162
|
|
|
141
163
|
This section describes 0.14.0-alpha.9. In 0.14.0-alpha.8,
|
package/bin/muhkoo.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import { run } from "../src/index.js";
|
|
11
|
-
import { printable } from "../src/lib/ui.js";
|
|
11
|
+
import { printable, isJsonMode, json } from "../src/lib/ui.js";
|
|
12
12
|
import { drained } from "../src/lib/drain.js";
|
|
13
13
|
|
|
14
14
|
run(process.argv.slice(2))
|
|
@@ -19,6 +19,12 @@ run(process.argv.slice(2))
|
|
|
19
19
|
// name or a server's words. The message is one line; the stack's frames
|
|
20
20
|
// are Node's own lines.
|
|
21
21
|
const head = e instanceof Error ? `${e.name}: ${e.message}` : String(e);
|
|
22
|
+
// Under --json a program is reading stdout: one {"error"} object, no stack.
|
|
23
|
+
if (isJsonMode()) {
|
|
24
|
+
json({ error: printable(e instanceof Error ? e.message : String(e)) });
|
|
25
|
+
await drained();
|
|
26
|
+
process.exit(1);
|
|
27
|
+
}
|
|
22
28
|
const stack = e instanceof Error && typeof e.stack === "string" ? e.stack : "";
|
|
23
29
|
const frames = stack.startsWith(head) ? stack.slice(head.length).split("\n").filter(Boolean) : [];
|
|
24
30
|
console.error(["", `✗ ${printable(head)}`, ...frames.map(printable), ""].join("\n"));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@muhkoo/cli",
|
|
3
|
-
"version": "0.15.0-alpha.
|
|
3
|
+
"version": "0.15.0-alpha.15",
|
|
4
4
|
"description": "Command-line interface for the Muhkoo platform — provision backends, deploy apps, and manage agents, functions, databases, and domains.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -40,18 +40,22 @@
|
|
|
40
40
|
"sync-version": "node scripts/sync-version.mjs",
|
|
41
41
|
"prepublishOnly": "node scripts/sync-version.mjs --check",
|
|
42
42
|
"test": "vitest run",
|
|
43
|
+
"build:mcpb": "node scripts/build-mcpb.mjs",
|
|
43
44
|
"release": "npm publish --tag alpha && npm dist-tag add @muhkoo/cli@$npm_package_version latest"
|
|
44
45
|
},
|
|
45
46
|
"dependencies": {
|
|
46
|
-
"@
|
|
47
|
-
"
|
|
47
|
+
"@modelcontextprotocol/sdk": "^1.32.2",
|
|
48
|
+
"@muhkoo/connect": "0.15.0-alpha.15",
|
|
49
|
+
"snarkjs": "^0.7.0",
|
|
50
|
+
"zod": "^4.6.7"
|
|
48
51
|
},
|
|
49
52
|
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e",
|
|
50
53
|
"devDependencies": {
|
|
51
|
-
"vitest": "^4.1.
|
|
54
|
+
"vitest": "^4.1.12"
|
|
52
55
|
},
|
|
53
56
|
"overrides": {
|
|
54
57
|
"jsonpath": "^1.3.0",
|
|
55
|
-
"underscore": "^1.13.8"
|
|
58
|
+
"underscore": "^1.13.8",
|
|
59
|
+
"ws": "^8.22.0"
|
|
56
60
|
}
|
|
57
61
|
}
|
package/src/commands/deploy.js
CHANGED
|
@@ -21,15 +21,20 @@ import { resolveBase, loadConfig, resolveToken } from "../lib/config.js";
|
|
|
21
21
|
import { resolveBaseUrl } from "../lib/bases.js";
|
|
22
22
|
import { skCall, devCall, ensure } from "../lib/http.js";
|
|
23
23
|
import { firstOf } from "../lib/args.js";
|
|
24
|
-
import { step, ok, info, warn, die, redact } from "../lib/ui.js";
|
|
24
|
+
import { step, ok, info, warn, die, redact, json, isJsonMode } from "../lib/ui.js";
|
|
25
25
|
|
|
26
26
|
export const help = `muhkoo deploy — deploy a built client to Muhkoo hosting
|
|
27
27
|
|
|
28
28
|
Usage:
|
|
29
|
-
muhkoo deploy [--app <appId>] [--key <mk_*_sk_*>] [--dist dist] [--base <env|url>] [--no-vfs]
|
|
29
|
+
muhkoo deploy [--app <appId>] [--key <mk_*_sk_*>] [--dist dist] [--base <env|url>] [--prod] [--no-vfs]
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
Deploys go to the app's test environment. Check it there, then run
|
|
32
|
+
\`muhkoo promote\` to put it into production, or deploy straight to production
|
|
33
|
+
with --prod.
|
|
34
|
+
|
|
35
|
+
Defaults: --app and --key fall back to .muhkoo-app.json (its test secret key,
|
|
36
|
+
or its live one with --prod), then $MUHKOO_APP_ID / $MUHKOO_DEPLOY_KEY. With no
|
|
37
|
+
app secret key, your developer session is used.
|
|
33
38
|
|
|
34
39
|
Once the release is live, deploy copies the folder you ran it from into your
|
|
35
40
|
filesystem at /apps/<slug>, where the IDE opens it. It is the copy
|
|
@@ -37,11 +42,12 @@ filesystem at /apps/<slug>, where the IDE opens it. It is the copy
|
|
|
37
42
|
(see \`muhkoo vfs --help\`): only files changed here upload, and it never
|
|
38
43
|
deletes. It needs you signed in to the same environment (\`muhkoo login\`) and
|
|
39
44
|
this machine paired, or a terminal to pair it in; without them it says why and
|
|
40
|
-
skips. A failed copy is a warning,
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
(\`muhkoo vfs use-app\`).
|
|
45
|
+
skips. A skipped or failed copy is a warning, printed again in the closing
|
|
46
|
+
summary, because the deploy has already succeeded. Storage for the copy is
|
|
47
|
+
billed to your account, like the rest of your filesystem; no app key is used.
|
|
44
48
|
|
|
49
|
+
--prod deploy to production instead of test (needs the app's live
|
|
50
|
+
secret key or your developer session)
|
|
45
51
|
--no-vfs deploy only; skip the copy`;
|
|
46
52
|
|
|
47
53
|
async function readRecord() {
|
|
@@ -70,11 +76,33 @@ export default async function deploy(args) {
|
|
|
70
76
|
const appId = firstOf(args.app, process.env.MUHKOO_APP_ID, record?.appId);
|
|
71
77
|
if (!appId) die("Missing app id. Pass --app <appId>, set MUHKOO_APP_ID, or run from a provisioned app dir.");
|
|
72
78
|
|
|
79
|
+
// Deploys go to the app's TEST environment. Production needs --prod, and a
|
|
80
|
+
// key for it: the app's live secret key, or your developer session.
|
|
81
|
+
const prod = Boolean(args.prod);
|
|
82
|
+
// Under the MCP server (no terminal), deploy must only ever reach TEST:
|
|
83
|
+
// production is `promote`, which the client asks about first.
|
|
84
|
+
const unattended = process.env.MUHKOO_NONINTERACTIVE === "1";
|
|
85
|
+
if (unattended && prod) die("Under the MCP server, deploy only deploys to test. Use promote to reach production.");
|
|
86
|
+
|
|
73
87
|
// Auth: an app secret key if available, otherwise the developer session token.
|
|
74
|
-
const skFromRecord = record?.keys?.find((k) => k.type === "sk" && k.env === "test")?.plaintext;
|
|
88
|
+
const skFromRecord = record?.keys?.find((k) => k.type === "sk" && k.env === (prod ? "live" : "test"))?.plaintext;
|
|
75
89
|
let auth = firstOf(args.key, process.env.MUHKOO_DEPLOY_KEY, skFromRecord);
|
|
76
90
|
if (auth && !/_sk_/.test(auth)) die("--key must be an app SECRET key (mk_*_sk_*), not a publishable key.");
|
|
91
|
+
if (auth && !prod && !/_test_sk_/.test(auth)) {
|
|
92
|
+
die(
|
|
93
|
+
unattended
|
|
94
|
+
? "Under the MCP server, deploy only deploys to test: use the app's TEST secret key (mk_test_sk_…). Use promote to reach production."
|
|
95
|
+
: "That is a live secret key, which deploys straight to production. Pass --prod to do that, or use the app's test secret key (mk_test_sk_…).",
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
if (auth && prod && /_test_sk_/.test(auth)) {
|
|
99
|
+
die("--prod needs the app's live secret key (mk_live_sk_…) or your developer session; a test key only deploys to test.");
|
|
100
|
+
}
|
|
77
101
|
if (!auth) auth = await resolveToken(args, cfg); // developer session is accepted by hosting
|
|
102
|
+
const viaKey = /_sk_/.test(auth ?? "");
|
|
103
|
+
// A secret key carries its environment; a session goes to live unless asked for test.
|
|
104
|
+
const envQuery = !viaKey && !prod ? "?env=test" : "";
|
|
105
|
+
const deployEnv = prod ? "live" : "test";
|
|
78
106
|
|
|
79
107
|
const dist = args.dist || "dist";
|
|
80
108
|
let files;
|
|
@@ -100,7 +128,7 @@ export default async function deploy(args) {
|
|
|
100
128
|
let uploaded = 0;
|
|
101
129
|
let deduped = 0;
|
|
102
130
|
for (const [sha, bytes] of blobs) {
|
|
103
|
-
const r = await skCall(baseUrl, auth, "PUT", `/api/apps/${appId}/hosting/blob/${sha}`, bytes, { raw: true });
|
|
131
|
+
const r = await skCall(baseUrl, auth, "PUT", `/api/apps/${appId}/hosting/blob/${sha}${envQuery}`, bytes, { raw: true });
|
|
104
132
|
if (!r.ok) die(`Upload failed for ${sha} (${r.status}): ${redact(await r.res.text())}`);
|
|
105
133
|
const body = await r.res.json().catch(() => ({}));
|
|
106
134
|
if (body.dedup) deduped++;
|
|
@@ -110,16 +138,38 @@ export default async function deploy(args) {
|
|
|
110
138
|
|
|
111
139
|
step("Committing release…");
|
|
112
140
|
const rel = ensure(
|
|
113
|
-
await skCall(baseUrl, auth, "POST", `/api/apps/${appId}/hosting/releases`, { manifest }),
|
|
141
|
+
await skCall(baseUrl, auth, "POST", `/api/apps/${appId}/hosting/releases${envQuery}`, { manifest }),
|
|
114
142
|
"Release",
|
|
115
143
|
);
|
|
116
144
|
info("");
|
|
117
145
|
ok("Deployed.");
|
|
146
|
+
info(` env: ${deployEnv === "live" ? "production" : "test"}${deployEnv === "test" ? " (muhkoo promote puts it into production)" : ""}`);
|
|
118
147
|
info(` release: ${rel.body.releaseId}`);
|
|
119
148
|
info(` size: ${(rel.body.bytes / 1024).toFixed(0)} KiB across ${rel.body.files} files`);
|
|
120
|
-
info(`
|
|
149
|
+
info(` url: ${rel.body.url}`);
|
|
121
150
|
|
|
122
|
-
|
|
151
|
+
let warnings = [];
|
|
152
|
+
if (!args["no-vfs"]) {
|
|
153
|
+
warnings = await copyToFilesystem({ args, cfg, record, baseUrl, appId });
|
|
154
|
+
// Said once where it happened and again here, because the copy's output
|
|
155
|
+
// sits above the release details and is easy to scroll past.
|
|
156
|
+
if (warnings.length) {
|
|
157
|
+
info("");
|
|
158
|
+
warn("Deployed, but the project was not copied to your filesystem:", ...warnings);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
if (args.json) {
|
|
162
|
+
json({
|
|
163
|
+
appId,
|
|
164
|
+
base: baseUrl,
|
|
165
|
+
env: deployEnv,
|
|
166
|
+
releaseId: rel.body.releaseId,
|
|
167
|
+
bytes: rel.body.bytes,
|
|
168
|
+
files: rel.body.files,
|
|
169
|
+
url: rel.body.url,
|
|
170
|
+
filesystem: { copied: !args["no-vfs"] && warnings.length === 0, warnings },
|
|
171
|
+
});
|
|
172
|
+
}
|
|
123
173
|
}
|
|
124
174
|
|
|
125
175
|
/**
|
|
@@ -128,8 +178,8 @@ export default async function deploy(args) {
|
|
|
128
178
|
* folder deploy ran from.
|
|
129
179
|
*
|
|
130
180
|
* Best effort by design. The site is already live when this runs, so every
|
|
131
|
-
* reason not to copy is one
|
|
132
|
-
* failed deploy.
|
|
181
|
+
* reason not to copy is one warning, and a failed copy is a warning, never a
|
|
182
|
+
* failed deploy. Resolves to the warning lines, for the closing summary.
|
|
133
183
|
*
|
|
134
184
|
* Import runs in a child process, not in this one, because its failure paths
|
|
135
185
|
* `die()`, which exits the process: an expired session or a revoked pairing
|
|
@@ -137,22 +187,26 @@ export default async function deploy(args) {
|
|
|
137
187
|
*/
|
|
138
188
|
export async function copyToFilesystem(ctx, { run = runImport } = {}) {
|
|
139
189
|
const plan = await planCopy(ctx);
|
|
140
|
-
if (plan.skip)
|
|
190
|
+
if (plan.skip) {
|
|
191
|
+
info("");
|
|
192
|
+
warn(plan.skip);
|
|
193
|
+
return [plan.skip];
|
|
194
|
+
}
|
|
141
195
|
info("");
|
|
142
196
|
step(`Copying the project to ${plan.root} in your filesystem (--no-vfs skips this)…`);
|
|
143
|
-
if (plan.note) info(` ${plan.note}`);
|
|
144
197
|
const code = await run(plan);
|
|
145
|
-
if (code
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
198
|
+
if (code === 0) return [];
|
|
199
|
+
const lines = [
|
|
200
|
+
`The site is live, but copying the project to ${plan.root} failed (see above).`,
|
|
201
|
+
`Retry with: muhkoo vfs import . --path ${plan.root}`,
|
|
202
|
+
];
|
|
203
|
+
warn(...lines);
|
|
204
|
+
return lines;
|
|
151
205
|
}
|
|
152
206
|
|
|
153
207
|
/**
|
|
154
208
|
* Whether and how to copy: `{ skip }`, the line to print instead, or
|
|
155
|
-
* `{ dir, root, base, token
|
|
209
|
+
* `{ dir, root, base, token }` for `runImport`.
|
|
156
210
|
*
|
|
157
211
|
* Everything that can be checked without unlocking is checked here, so a
|
|
158
212
|
* deploy from CI (an app key and no login), from a login to the other
|
|
@@ -204,34 +258,21 @@ export async function planCopy({
|
|
|
204
258
|
};
|
|
205
259
|
}
|
|
206
260
|
|
|
207
|
-
//
|
|
208
|
-
|
|
209
|
-
const pk = (keyEnv) => record?.keys?.find((k) => k.type === "pk" && k.env === keyEnv)?.plaintext;
|
|
210
|
-
const own = (sameApp && (pk("live") || pk("test"))) || cfg.vfsApps?.[slug];
|
|
211
|
-
if (own) return { dir, root, base: baseUrl, token, key: own };
|
|
212
|
-
const fallback = cfg.vfsApp && cfg.vfsApps?.[cfg.vfsApp];
|
|
213
|
-
if (fallback) {
|
|
214
|
-
return {
|
|
215
|
-
dir, root, base: baseUrl, token, key: fallback,
|
|
216
|
-
note: `Storage for the copy is billed to ${cfg.vfsApp}, the app you write your filesystem as.`,
|
|
217
|
-
};
|
|
218
|
-
}
|
|
219
|
-
return {
|
|
220
|
-
skip:
|
|
221
|
-
`No key for ${slug} on this machine, ${notCopied}. Deploy from the folder with its ` +
|
|
222
|
-
`.muhkoo-app.json, or run \`muhkoo vfs use-app ${slug} --key <appKey>\` once.`,
|
|
223
|
-
};
|
|
261
|
+
// Storage is billed to the signed-in account, so there is no key to find.
|
|
262
|
+
return { dir, root, base: baseUrl, token };
|
|
224
263
|
}
|
|
225
264
|
|
|
226
265
|
/** Run `muhkoo vfs import <dir> --path <root>` as a child process; resolves to its exit code. */
|
|
227
|
-
function runImport({ dir, root, base, token
|
|
266
|
+
function runImport({ dir, root, base, token }) {
|
|
228
267
|
const bin = fileURLToPath(new URL("../../bin/muhkoo.js", import.meta.url));
|
|
229
268
|
return new Promise((done) => {
|
|
230
269
|
const child = spawn(process.execPath, [bin, "vfs", "import", dir, "--path", root, "--base", base], {
|
|
231
|
-
|
|
232
|
-
//
|
|
233
|
-
|
|
234
|
-
|
|
270
|
+
// Under --json our stdout is the one result object, so the copy's
|
|
271
|
+
// output goes to stderr with the rest of the progress.
|
|
272
|
+
stdio: isJsonMode() ? ["ignore", 2, 2] : "inherit",
|
|
273
|
+
// The session checked above, in the environment rather than argv so it
|
|
274
|
+
// does not show in the process list.
|
|
275
|
+
env: { ...process.env, MUHKOO_DEV_TOKEN: token },
|
|
235
276
|
});
|
|
236
277
|
child.on("error", () => done(1));
|
|
237
278
|
child.on("exit", (code) => done(code ?? 1));
|
package/src/commands/kv.js
CHANGED
|
@@ -20,8 +20,6 @@ Usage:
|
|
|
20
20
|
muhkoo kv ls [<prefix>] [--json] keys that start with <prefix> (default: all)
|
|
21
21
|
|
|
22
22
|
Options:
|
|
23
|
-
--app <slug> the app the read is made as (default: the one from
|
|
24
|
-
\`muhkoo vfs use-app\`); reads work without one
|
|
25
23
|
--json a JSON array of keys
|
|
26
24
|
|
|
27
25
|
Keys only: this command never reads a value. Put --json after "ls".
|
package/src/commands/login.js
CHANGED
|
@@ -9,7 +9,8 @@ import { zkLogin } from "../lib/auth.js";
|
|
|
9
9
|
import { webLogin, DEFAULT_CLI_APP_ID } from "../lib/webLogin.js";
|
|
10
10
|
import { devCall } from "../lib/http.js";
|
|
11
11
|
import { firstOf } from "../lib/args.js";
|
|
12
|
-
import {
|
|
12
|
+
import { pairWithSeed } from "../lib/vfs.js";
|
|
13
|
+
import { prompt, promptHidden, ok, step, info, die, c, json } from "../lib/ui.js";
|
|
13
14
|
|
|
14
15
|
export const help = `muhkoo login — sign in as a developer
|
|
15
16
|
|
|
@@ -18,10 +19,16 @@ Usage:
|
|
|
18
19
|
muhkoo login [--username <u>] [--password <p>] [--base <env|url>]
|
|
19
20
|
muhkoo login --token <sessionToken> [--base <env|url>]
|
|
20
21
|
|
|
22
|
+
Options:
|
|
23
|
+
--no-pair sign in without pairing this machine (later VFS commands will ask)
|
|
24
|
+
|
|
21
25
|
--web opens auth.muhkoo.dev in your browser (password, passkey, or Google) and
|
|
22
26
|
captures the session over a localhost redirect — no credentials touch the CLI.
|
|
23
27
|
Otherwise credentials are read from flags, then $MUHKOO_USERNAME/$MUHKOO_PASSWORD,
|
|
24
|
-
then a prompt. The session token is saved to ~/.muhkoo/config.json
|
|
28
|
+
then a prompt. The session token is saved to ~/.muhkoo/config.json.
|
|
29
|
+
|
|
30
|
+
Signing in also pairs this machine, so "muhkoo vfs" and deploys need no password
|
|
31
|
+
afterwards. Revoke the pairing any time with: muhkoo devices rm <id>`;
|
|
25
32
|
|
|
26
33
|
export default async function login(args) {
|
|
27
34
|
const cfg = await loadConfig();
|
|
@@ -30,6 +37,7 @@ export default async function login(args) {
|
|
|
30
37
|
let token = args.token || process.env.MUHKOO_DEV_TOKEN;
|
|
31
38
|
let username = args.username || process.env.MUHKOO_USERNAME;
|
|
32
39
|
let commitment;
|
|
40
|
+
let seed = null;
|
|
33
41
|
|
|
34
42
|
if (!token && (args.web || args.browser)) {
|
|
35
43
|
const appId = firstOf(args["app-id"], process.env.MUHKOO_CLI_APP_ID, cfg.cliAppId, DEFAULT_CLI_APP_ID);
|
|
@@ -37,6 +45,7 @@ export default async function login(args) {
|
|
|
37
45
|
token = res.token;
|
|
38
46
|
commitment = res.commitment;
|
|
39
47
|
username = res.username;
|
|
48
|
+
seed = res.seed ?? null;
|
|
40
49
|
} else if (!token) {
|
|
41
50
|
if (!username) username = await prompt("Username: ");
|
|
42
51
|
let password = args.password || process.env.MUHKOO_PASSWORD;
|
|
@@ -46,6 +55,7 @@ export default async function login(args) {
|
|
|
46
55
|
token = res.token;
|
|
47
56
|
commitment = res.commitment;
|
|
48
57
|
username = res.username;
|
|
58
|
+
seed = res.seed ?? null;
|
|
49
59
|
}
|
|
50
60
|
|
|
51
61
|
// Confirm the token works and surface the developer's status.
|
|
@@ -53,8 +63,41 @@ export default async function login(args) {
|
|
|
53
63
|
const me = await devCall({ baseUrl, token }, "GET", "/api/developer/me");
|
|
54
64
|
if (!me.ok && me.status === 401) die("That session token is invalid or expired.");
|
|
55
65
|
|
|
56
|
-
|
|
66
|
+
// `seed: undefined` clears a seed an older CLI left on disk. A pairing made
|
|
67
|
+
// for another user or base is dropped here too: if no new pairing follows
|
|
68
|
+
// (--no-pair, --token, no seed, a failed pairing), the next VFS command must
|
|
69
|
+
// not unlock with the previous user's device key.
|
|
70
|
+
const pairingIsOurs = cfg.username === username && cfg.base === baseUrl;
|
|
71
|
+
const pairing = pairingIsOurs ? {} : { deviceFactorId: undefined, deviceKey: undefined };
|
|
72
|
+
await saveConfig({ ...cfg, ...pairing, base: baseUrl, token, username, commitment, seed: undefined });
|
|
57
73
|
ok(`Signed in${username ? ` as ${c.bold(username)}` : ""} → ${baseUrl}`);
|
|
74
|
+
let paired = false;
|
|
75
|
+
let deviceFactorId;
|
|
76
|
+
if (!args["no-pair"] && args.pair !== false && !args.token && !process.env.MUHKOO_DEV_TOKEN) {
|
|
77
|
+
const alreadyPaired = cfg.deviceFactorId && cfg.deviceKey && cfg.username === username && cfg.base === baseUrl;
|
|
78
|
+
if (alreadyPaired) {
|
|
79
|
+
info("This machine is already paired.");
|
|
80
|
+
paired = true;
|
|
81
|
+
deviceFactorId = cfg.deviceFactorId;
|
|
82
|
+
} else if (seed) {
|
|
83
|
+
try {
|
|
84
|
+
const made = await pairWithSeed({ cfg: await loadConfig(), baseUrl, token, username, commitment, seed });
|
|
85
|
+
info(`Paired this machine as "${made.label}". Revoke it any time: muhkoo devices rm ${made.factorId}`);
|
|
86
|
+
paired = true;
|
|
87
|
+
deviceFactorId = made.factorId;
|
|
88
|
+
} catch (err) {
|
|
89
|
+
info(
|
|
90
|
+
`Signed in, but pairing this machine failed: ${err?.message ?? err}. ` +
|
|
91
|
+
"Run `muhkoo vfs ls` once to pair it.",
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
} else {
|
|
95
|
+
info(
|
|
96
|
+
"Signed in, but this machine is not paired (the browser did not hand over the unlock key). " +
|
|
97
|
+
"Run `muhkoo vfs ls` once in a terminal to pair it.",
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
58
101
|
if (me.ok && me.body?.needsBootstrap) {
|
|
59
102
|
info(
|
|
60
103
|
"",
|
|
@@ -64,4 +107,7 @@ export default async function login(args) {
|
|
|
64
107
|
} else if (me.ok && me.body?.tier) {
|
|
65
108
|
info(` plan: ${me.body.tier}`);
|
|
66
109
|
}
|
|
110
|
+
// Never the session token: this result is read by programs, the MCP
|
|
111
|
+
// server among them, and from there by a model.
|
|
112
|
+
if (args.json) json({ base: baseUrl, username, paired, ...(deviceFactorId ? { deviceFactorId } : {}) });
|
|
67
113
|
}
|
package/src/commands/logout.js
CHANGED
|
@@ -3,15 +3,17 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import { loadConfig, saveConfig } from "../lib/config.js";
|
|
6
|
-
import { ok } from "../lib/ui.js";
|
|
6
|
+
import { ok, json } from "../lib/ui.js";
|
|
7
|
+
import { resolveBaseUrl } from "../lib/bases.js";
|
|
7
8
|
|
|
8
9
|
export const help = `muhkoo logout — clear the stored session token`;
|
|
9
10
|
|
|
10
|
-
export default async function logout() {
|
|
11
|
+
export default async function logout(args = {}) {
|
|
11
12
|
const cfg = await loadConfig();
|
|
12
13
|
delete cfg.token;
|
|
13
14
|
delete cfg.username;
|
|
14
15
|
delete cfg.commitment;
|
|
15
16
|
await saveConfig(cfg);
|
|
16
17
|
ok("Signed out.");
|
|
18
|
+
if (args.json) json({ base: resolveBaseUrl(cfg.base), signedOut: true });
|
|
17
19
|
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `muhkoo mcp` — run as an MCP server for Claude, over stdio.
|
|
3
|
+
*
|
|
4
|
+
* Claude Desktop (via the .mcpb extension) or Claude Code starts this and
|
|
5
|
+
* talks to it on stdin/stdout, so nothing here may print to stdout: that
|
|
6
|
+
* stream belongs to the protocol.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { serveStdio } from "../mcp/server.js";
|
|
10
|
+
|
|
11
|
+
export const help = `muhkoo mcp — run as an MCP server for Claude (stdio)
|
|
12
|
+
|
|
13
|
+
Usage:
|
|
14
|
+
muhkoo mcp
|
|
15
|
+
|
|
16
|
+
Started by Claude, not by hand. It gives Claude a tool for every CLI action,
|
|
17
|
+
signed in as whoever ran \`muhkoo login\` on this computer. Tools that change
|
|
18
|
+
production or delete things are marked so Claude asks first; secret keys and
|
|
19
|
+
access tokens are saved to private files and never shown.
|
|
20
|
+
|
|
21
|
+
Claude Code: claude mcp add muhkoo -- npx -y @muhkoo/cli mcp
|
|
22
|
+
Claude Desktop: install the Muhkoo extension (.mcpb).`;
|
|
23
|
+
|
|
24
|
+
export default async function mcp() {
|
|
25
|
+
await serveStdio();
|
|
26
|
+
// Keep running until the client closes stdin.
|
|
27
|
+
await new Promise((resolve) => process.stdin.on("close", resolve));
|
|
28
|
+
}
|
package/src/commands/promote.js
CHANGED
|
@@ -20,7 +20,8 @@ import { readFile, writeFile, access, chmod } from "node:fs/promises";
|
|
|
20
20
|
import { devContext } from "../lib/config.js";
|
|
21
21
|
import { devCall, appKeyGet, ensure } from "../lib/http.js";
|
|
22
22
|
import { appsSuffixFor } from "../lib/bases.js";
|
|
23
|
-
import { step, ok, warn, info, die, c } from "../lib/ui.js";
|
|
23
|
+
import { step, ok, warn, info, die, c, json } from "../lib/ui.js";
|
|
24
|
+
import { resolve as resolvePath } from "node:path";
|
|
24
25
|
|
|
25
26
|
export const help = `muhkoo provision — provision an app backend from a spec
|
|
26
27
|
|
|
@@ -101,6 +102,21 @@ export default async function provision(args) {
|
|
|
101
102
|
info("", "Next: run the app once so its channels exist, then:");
|
|
102
103
|
info(` muhkoo provision --spec ${args.spec} --enable`);
|
|
103
104
|
}
|
|
105
|
+
if (args.json) {
|
|
106
|
+
json({
|
|
107
|
+
appId: record.appId,
|
|
108
|
+
slug: record.slug,
|
|
109
|
+
base: ctx.baseUrl,
|
|
110
|
+
recordPath: resolvePath(OUT),
|
|
111
|
+
dryRun: DRY,
|
|
112
|
+
tables,
|
|
113
|
+
collections,
|
|
114
|
+
hostingUrl,
|
|
115
|
+
// The record's keys as written. The MCP server seals the secret ones
|
|
116
|
+
// into files before anything reaches a conversation.
|
|
117
|
+
keys: record.keys,
|
|
118
|
+
});
|
|
119
|
+
}
|
|
104
120
|
}
|
|
105
121
|
|
|
106
122
|
async function ensureDeveloper(ctx, email, DRY) {
|