@muhkoo/cli 0.15.0-alpha.13 → 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 +37 -7
- package/bin/muhkoo.js +7 -1
- package/package.json +9 -5
- package/src/commands/deploy.js +192 -9
- 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 +110 -98
- package/src/index.js +7 -3
- package/src/lib/auth.js +7 -2
- package/src/lib/bases.js +8 -0
- package/src/lib/mount.js +3 -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
|
@@ -39,6 +39,13 @@ app is provisioned every command runs with no extra flags. `deploy` publishes to
|
|
|
39
39
|
app's **test** environment; once it looks right on the test URL, `promote` copies that
|
|
40
40
|
release onto **production**, in place.
|
|
41
41
|
|
|
42
|
+
Once the release is live, `deploy` also copies the project into your filesystem at
|
|
43
|
+
`/apps/<slug>`, where the IDE opens it. It is the copy `muhkoo vfs import . --path
|
|
44
|
+
/apps/<slug>` makes (see [Syncing a directory](#syncing-a-directory)), and it needs you
|
|
45
|
+
signed in to the same environment with this machine paired, or a terminal to pair it
|
|
46
|
+
in. Without them, as in CI, `deploy` says why in one line and skips the copy. A failed
|
|
47
|
+
copy is a warning, not a failed deploy. `--no-vfs` skips it.
|
|
48
|
+
|
|
42
49
|
## Sign in
|
|
43
50
|
|
|
44
51
|
```bash
|
|
@@ -107,7 +114,7 @@ Account login · logout · devices ls|rm · whoami
|
|
|
107
114
|
Apps apps ls|get|create|slug|rm · keys rotate · tokens ls|create|revoke
|
|
108
115
|
Backend provision · tables · agents · functions · vectors ls|get|create|rm|notices|query
|
|
109
116
|
Files vfs cd|pwd|ls|stat|tree|cat|put|get|mkdir|rm|cp|mv|find|history|restore
|
|
110
|
-
vfs import|mount|ignore · vfs sweep|
|
|
117
|
+
vfs import|mount|ignore · vfs sweep|rehome
|
|
111
118
|
vcs status|commit|log|show|diff|branch|switch|checkout|merge|restore · vcs merge --abort
|
|
112
119
|
kv ls [prefix]
|
|
113
120
|
Hosting deploy · promote · hosting status|rollback|rm-release|unpublish · domains
|
|
@@ -120,7 +127,7 @@ Run `muhkoo <command> --help` for details. A few highlights:
|
|
|
120
127
|
muhkoo apps ls # list your apps
|
|
121
128
|
muhkoo provision --spec app.json --dry-run # preview API calls
|
|
122
129
|
muhkoo provision --spec app.json --enable # enable agents/functions on channels
|
|
123
|
-
muhkoo deploy # publish dist/ to the test env
|
|
130
|
+
muhkoo deploy # publish dist/ to the test env, copy the project to /apps/<slug>
|
|
124
131
|
muhkoo promote # promote test → production, in place
|
|
125
132
|
muhkoo hosting status <appId> # releases + current pointer
|
|
126
133
|
muhkoo hosting rollback <appId> --release <id> # instant rollback
|
|
@@ -129,6 +136,28 @@ muhkoo agents enable <appId> <agentId> --channel general
|
|
|
129
136
|
muhkoo eject src/agent/agentApp.ts # preview an agent's prompt + tools
|
|
130
137
|
```
|
|
131
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
|
+
|
|
132
161
|
## Syncing a directory
|
|
133
162
|
|
|
134
163
|
This section describes 0.14.0-alpha.9. In 0.14.0-alpha.8,
|
|
@@ -181,11 +210,12 @@ and it cannot reach this disk except through these checks:
|
|
|
181
210
|
- **Some paths never sync, in either direction.** No flag and no ignore rule
|
|
182
211
|
changes that: `.git`, `.ssh`, `.muhkoo`, `node_modules`, `.husky`, editor and
|
|
183
212
|
agent directories (`.vscode`, `.idea`, `.config`, `.claude`, `.cursor`,
|
|
184
|
-
`.zed`, `.fleet`), and credential and shell start-up files
|
|
185
|
-
`.
|
|
186
|
-
and the rest). Each one either holds
|
|
187
|
-
|
|
188
|
-
|
|
213
|
+
`.zed`, `.fleet`), and credential and shell start-up files
|
|
214
|
+
(`.muhkoo-app.json`, `.envrc`, `.npmrc`, `.netrc`, `.gitconfig`, `.profile`,
|
|
215
|
+
`.bashrc`, `.zshrc`, `.zshenv` and the rest). Each one either holds
|
|
216
|
+
credentials (`.muhkoo-app.json` holds an app's secret keys) or can run code
|
|
217
|
+
without an execute bit. Names are compared the way a case-folding volume
|
|
218
|
+
would compare them, so `Node_Modules`, `.GIT` and `GIT~1` are refused too.
|
|
189
219
|
- **Never your home directory.** Both commands refuse the filesystem root, your
|
|
190
220
|
home directory, and anything that contains it. There is no override.
|
|
191
221
|
- **One write boundary.** Every write and delete on disk checks each part of
|
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
|
@@ -3,6 +3,10 @@
|
|
|
3
3
|
* each file uploads by its sha256 (only changed files transfer), then a release
|
|
4
4
|
* is committed (an atomic pointer flip; instant + rollback-able).
|
|
5
5
|
*
|
|
6
|
+
* Once the release is live, it copies the project into the deployer's
|
|
7
|
+
* filesystem at /apps/<slug>, where the IDE opens it (`copyToFilesystem`).
|
|
8
|
+
* `--no-vfs` skips that.
|
|
9
|
+
*
|
|
6
10
|
* Auth accepts EITHER an app secret key (--key / $MUHKOO_DEPLOY_KEY) or your
|
|
7
11
|
* developer session (`muhkoo login`). The app id and key are read from
|
|
8
12
|
* .muhkoo-app.json when present, so a provisioned app deploys with no flags.
|
|
@@ -10,19 +14,41 @@
|
|
|
10
14
|
|
|
11
15
|
import { readFile, readdir, stat, access } from "node:fs/promises";
|
|
12
16
|
import { createHash } from "node:crypto";
|
|
17
|
+
import { spawn } from "node:child_process";
|
|
18
|
+
import { fileURLToPath } from "node:url";
|
|
13
19
|
import { join, relative, sep } from "node:path";
|
|
14
20
|
import { resolveBase, loadConfig, resolveToken } from "../lib/config.js";
|
|
15
|
-
import {
|
|
21
|
+
import { resolveBaseUrl } from "../lib/bases.js";
|
|
22
|
+
import { skCall, devCall, ensure } from "../lib/http.js";
|
|
16
23
|
import { firstOf } from "../lib/args.js";
|
|
17
|
-
import { step, ok, info, die, redact } from "../lib/ui.js";
|
|
24
|
+
import { step, ok, info, warn, die, redact, json, isJsonMode } from "../lib/ui.js";
|
|
18
25
|
|
|
19
26
|
export const help = `muhkoo deploy — deploy a built client to Muhkoo hosting
|
|
20
27
|
|
|
21
28
|
Usage:
|
|
22
|
-
muhkoo deploy [--app <appId>] [--key <mk_*_sk_*>] [--dist dist] [--base <env|url>]
|
|
29
|
+
muhkoo deploy [--app <appId>] [--key <mk_*_sk_*>] [--dist dist] [--base <env|url>] [--prod] [--no-vfs]
|
|
30
|
+
|
|
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.
|
|
23
38
|
|
|
24
|
-
|
|
25
|
-
|
|
39
|
+
Once the release is live, deploy copies the folder you ran it from into your
|
|
40
|
+
filesystem at /apps/<slug>, where the IDE opens it. It is the copy
|
|
41
|
+
\`muhkoo vfs import . --path /apps/<slug>\` makes, under the same ignore rules
|
|
42
|
+
(see \`muhkoo vfs --help\`): only files changed here upload, and it never
|
|
43
|
+
deletes. It needs you signed in to the same environment (\`muhkoo login\`) and
|
|
44
|
+
this machine paired, or a terminal to pair it in; without them it says why and
|
|
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.
|
|
48
|
+
|
|
49
|
+
--prod deploy to production instead of test (needs the app's live
|
|
50
|
+
secret key or your developer session)
|
|
51
|
+
--no-vfs deploy only; skip the copy`;
|
|
26
52
|
|
|
27
53
|
async function readRecord() {
|
|
28
54
|
try {
|
|
@@ -50,11 +76,33 @@ export default async function deploy(args) {
|
|
|
50
76
|
const appId = firstOf(args.app, process.env.MUHKOO_APP_ID, record?.appId);
|
|
51
77
|
if (!appId) die("Missing app id. Pass --app <appId>, set MUHKOO_APP_ID, or run from a provisioned app dir.");
|
|
52
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
|
+
|
|
53
87
|
// Auth: an app secret key if available, otherwise the developer session token.
|
|
54
|
-
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;
|
|
55
89
|
let auth = firstOf(args.key, process.env.MUHKOO_DEPLOY_KEY, skFromRecord);
|
|
56
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
|
+
}
|
|
57
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";
|
|
58
106
|
|
|
59
107
|
const dist = args.dist || "dist";
|
|
60
108
|
let files;
|
|
@@ -80,7 +128,7 @@ export default async function deploy(args) {
|
|
|
80
128
|
let uploaded = 0;
|
|
81
129
|
let deduped = 0;
|
|
82
130
|
for (const [sha, bytes] of blobs) {
|
|
83
|
-
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 });
|
|
84
132
|
if (!r.ok) die(`Upload failed for ${sha} (${r.status}): ${redact(await r.res.text())}`);
|
|
85
133
|
const body = await r.res.json().catch(() => ({}));
|
|
86
134
|
if (body.dedup) deduped++;
|
|
@@ -90,12 +138,147 @@ export default async function deploy(args) {
|
|
|
90
138
|
|
|
91
139
|
step("Committing release…");
|
|
92
140
|
const rel = ensure(
|
|
93
|
-
await skCall(baseUrl, auth, "POST", `/api/apps/${appId}/hosting/releases`, { manifest }),
|
|
141
|
+
await skCall(baseUrl, auth, "POST", `/api/apps/${appId}/hosting/releases${envQuery}`, { manifest }),
|
|
94
142
|
"Release",
|
|
95
143
|
);
|
|
96
144
|
info("");
|
|
97
145
|
ok("Deployed.");
|
|
146
|
+
info(` env: ${deployEnv === "live" ? "production" : "test"}${deployEnv === "test" ? " (muhkoo promote puts it into production)" : ""}`);
|
|
98
147
|
info(` release: ${rel.body.releaseId}`);
|
|
99
148
|
info(` size: ${(rel.body.bytes / 1024).toFixed(0)} KiB across ${rel.body.files} files`);
|
|
100
|
-
info(`
|
|
149
|
+
info(` url: ${rel.body.url}`);
|
|
150
|
+
|
|
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
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Copy the project into the deployer's filesystem at /apps/<slug>, where the
|
|
177
|
+
* portal's "Open in IDE" looks for it, by running `muhkoo vfs import` on the
|
|
178
|
+
* folder deploy ran from.
|
|
179
|
+
*
|
|
180
|
+
* Best effort by design. The site is already live when this runs, so every
|
|
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.
|
|
183
|
+
*
|
|
184
|
+
* Import runs in a child process, not in this one, because its failure paths
|
|
185
|
+
* `die()`, which exits the process: an expired session or a revoked pairing
|
|
186
|
+
* would otherwise turn a deploy that succeeded into exit 1.
|
|
187
|
+
*/
|
|
188
|
+
export async function copyToFilesystem(ctx, { run = runImport } = {}) {
|
|
189
|
+
const plan = await planCopy(ctx);
|
|
190
|
+
if (plan.skip) {
|
|
191
|
+
info("");
|
|
192
|
+
warn(plan.skip);
|
|
193
|
+
return [plan.skip];
|
|
194
|
+
}
|
|
195
|
+
info("");
|
|
196
|
+
step(`Copying the project to ${plan.root} in your filesystem (--no-vfs skips this)…`);
|
|
197
|
+
const code = await run(plan);
|
|
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;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Whether and how to copy: `{ skip }`, the line to print instead, or
|
|
209
|
+
* `{ dir, root, base, token }` for `runImport`.
|
|
210
|
+
*
|
|
211
|
+
* Everything that can be checked without unlocking is checked here, so a
|
|
212
|
+
* deploy from CI (an app key and no login), from a login to the other
|
|
213
|
+
* environment, or from a machine that cannot pair without a terminal says so
|
|
214
|
+
* in one line instead of starting an import that can only fail.
|
|
215
|
+
*/
|
|
216
|
+
export async function planCopy({
|
|
217
|
+
args,
|
|
218
|
+
cfg,
|
|
219
|
+
record,
|
|
220
|
+
baseUrl,
|
|
221
|
+
appId,
|
|
222
|
+
dir = process.cwd(),
|
|
223
|
+
env = process.env,
|
|
224
|
+
interactive = Boolean(process.stdin.isTTY),
|
|
225
|
+
}) {
|
|
226
|
+
const notCopied = "so the project was not copied to your filesystem";
|
|
227
|
+
|
|
228
|
+
// The session the import runs on. One passed explicitly is taken to be for
|
|
229
|
+
// the base being deployed to; the stored one belongs to the base `muhkoo
|
|
230
|
+
// login` signed in at, and there is only ever one.
|
|
231
|
+
const explicit = firstOf(args.token, env.MUHKOO_DEV_TOKEN);
|
|
232
|
+
const token = firstOf(explicit, cfg.token);
|
|
233
|
+
if (!token) return { skip: `Not signed in, ${notCopied}. Run \`muhkoo login\` and deploy again to copy it.` };
|
|
234
|
+
if (!explicit) {
|
|
235
|
+
const signedInAt = resolveBaseUrl(cfg.base);
|
|
236
|
+
if (trimSlash(signedInAt) !== trimSlash(baseUrl)) {
|
|
237
|
+
return { skip: `Signed in to ${signedInAt}, not ${baseUrl}, ${notCopied}.` };
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
// The app's own slug, from the server: the IDE reads /apps/<slug>, whatever
|
|
242
|
+
// the folder is called (muhkoo.com deploys from a folder named `website`).
|
|
243
|
+
// A record for this same app stands in when the lookup fails.
|
|
244
|
+
const sameApp = Boolean(record) && record.appId === appId;
|
|
245
|
+
const found = await devCall({ baseUrl, token }, "GET", `/api/apps/${appId}`).catch(() => null);
|
|
246
|
+
const slug = (found?.ok && found.body?.slug) || (sameApp && record.slug) || null;
|
|
247
|
+
if (!slug) {
|
|
248
|
+
return { skip: `Could not look up the app's slug${found ? ` (${found.status})` : ""}, ${notCopied}.` };
|
|
249
|
+
}
|
|
250
|
+
const root = `/apps/${slug}`;
|
|
251
|
+
|
|
252
|
+
// Unlocking needs MUHKOO_SEED, this machine's pairing, or a terminal to
|
|
253
|
+
// sign in and pair from.
|
|
254
|
+
const paired = Boolean(cfg.deviceFactorId && cfg.deviceKey && cfg.username);
|
|
255
|
+
if (!env.MUHKOO_SEED && !paired && !interactive) {
|
|
256
|
+
return {
|
|
257
|
+
skip: `This machine is not paired, ${notCopied}. Run \`muhkoo vfs import . --path ${root}\` once in a terminal to pair it.`,
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
// Storage is billed to the signed-in account, so there is no key to find.
|
|
262
|
+
return { dir, root, base: baseUrl, token };
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/** Run `muhkoo vfs import <dir> --path <root>` as a child process; resolves to its exit code. */
|
|
266
|
+
function runImport({ dir, root, base, token }) {
|
|
267
|
+
const bin = fileURLToPath(new URL("../../bin/muhkoo.js", import.meta.url));
|
|
268
|
+
return new Promise((done) => {
|
|
269
|
+
const child = spawn(process.execPath, [bin, "vfs", "import", dir, "--path", root, "--base", base], {
|
|
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 },
|
|
276
|
+
});
|
|
277
|
+
child.on("error", () => done(1));
|
|
278
|
+
child.on("exit", (code) => done(code ?? 1));
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
function trimSlash(url) {
|
|
283
|
+
return String(url).replace(/\/+$/, "");
|
|
101
284
|
}
|
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) {
|