@muhkoo/cli 0.7.0-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +122 -0
- package/bin/muhkoo.js +17 -0
- package/package.json +44 -0
- package/src/commands/_eject-runner.mjs +59 -0
- package/src/commands/agents.js +88 -0
- package/src/commands/apps.js +119 -0
- package/src/commands/deploy.js +101 -0
- package/src/commands/domains.js +75 -0
- package/src/commands/eject.js +40 -0
- package/src/commands/functions.js +108 -0
- package/src/commands/hosting.js +76 -0
- package/src/commands/login.js +66 -0
- package/src/commands/logout.js +17 -0
- package/src/commands/logs.js +45 -0
- package/src/commands/provision.js +232 -0
- package/src/commands/tables.js +60 -0
- package/src/commands/whoami.js +26 -0
- package/src/index.js +105 -0
- package/src/lib/args.js +32 -0
- package/src/lib/auth.js +62 -0
- package/src/lib/bases.js +28 -0
- package/src/lib/browser.js +20 -0
- package/src/lib/config.js +66 -0
- package/src/lib/http.js +59 -0
- package/src/lib/pkce.js +18 -0
- package/src/lib/spaces.js +41 -0
- package/src/lib/ui.js +102 -0
- package/src/lib/webLogin.js +140 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Muhkoo
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
# @muhkoo/cli
|
|
2
|
+
|
|
3
|
+
The command-line interface for the [Muhkoo](https://muhkoo.dev) platform. Provision
|
|
4
|
+
app backends, deploy hosted clients, and manage agents, functions, databases, and
|
|
5
|
+
custom domains — everything the Muhkoo app builder does, from your terminal.
|
|
6
|
+
|
|
7
|
+
Built on top of [`@muhkoo/connect`](https://www.npmjs.com/package/@muhkoo/connect).
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install -g @muhkoo/cli
|
|
13
|
+
# or run without installing:
|
|
14
|
+
npx @muhkoo/cli --help
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Requires Node.js 20+.
|
|
18
|
+
|
|
19
|
+
## Quickstart
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
# 1. Sign in (zero-knowledge login — your password never leaves the machine)
|
|
23
|
+
muhkoo login
|
|
24
|
+
|
|
25
|
+
# 2. Create an app and provision its backend from a spec
|
|
26
|
+
muhkoo apps create --slug my-app --email you@example.com
|
|
27
|
+
muhkoo provision --spec app.json
|
|
28
|
+
|
|
29
|
+
# 3. Build your client, then deploy it
|
|
30
|
+
muhkoo deploy
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
`provision` writes `.muhkoo-app.json` (app id + keys). `deploy` reads it, so once an
|
|
34
|
+
app is provisioned both commands run with no extra flags.
|
|
35
|
+
|
|
36
|
+
## Sign in
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
muhkoo login --web # opens auth.muhkoo.dev in your browser (recommended)
|
|
40
|
+
muhkoo login # zero-knowledge login from the terminal (prompts)
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
`--web` opens the hosted sign-in page, you authenticate however you like (password,
|
|
44
|
+
passkey, or Google), and the CLI captures the session over a one-time `localhost`
|
|
45
|
+
redirect — your credentials never touch the CLI. The terminal flow runs the
|
|
46
|
+
zero-knowledge login locally; your password still never leaves your machine.
|
|
47
|
+
|
|
48
|
+
## Authentication
|
|
49
|
+
|
|
50
|
+
Most commands use your **developer session**, established by `muhkoo login` and stored
|
|
51
|
+
in `~/.muhkoo/config.json`. You can override per-invocation:
|
|
52
|
+
|
|
53
|
+
| Source | How |
|
|
54
|
+
| --- | --- |
|
|
55
|
+
| Flag | `--token <sessionToken>` |
|
|
56
|
+
| Env | `MUHKOO_DEV_TOKEN` |
|
|
57
|
+
| Stored | written by `muhkoo login` |
|
|
58
|
+
|
|
59
|
+
`deploy` also accepts an app **secret key** (`--key mk_*_sk_*` or `MUHKOO_DEPLOY_KEY`),
|
|
60
|
+
which is what CI typically uses.
|
|
61
|
+
|
|
62
|
+
## Environments
|
|
63
|
+
|
|
64
|
+
`--base` selects the API base for any command:
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
muhkoo apps ls --base staging
|
|
68
|
+
muhkoo deploy --base local # http://localhost:8787
|
|
69
|
+
muhkoo whoami --base https://api.example.com
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
`prod` is the default. The chosen base is remembered by `muhkoo login`.
|
|
73
|
+
|
|
74
|
+
## Commands
|
|
75
|
+
|
|
76
|
+
```
|
|
77
|
+
Account login · logout · whoami
|
|
78
|
+
Apps apps ls|get|create|slug|rm · keys rotate
|
|
79
|
+
Backend provision · tables · agents · functions
|
|
80
|
+
Hosting deploy · hosting status|rollback|rm-release|unpublish · domains
|
|
81
|
+
Tools logs · eject
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Run `muhkoo <command> --help` for details. A few highlights:
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
muhkoo apps ls # list your apps
|
|
88
|
+
muhkoo provision --spec app.json --dry-run # preview API calls
|
|
89
|
+
muhkoo provision --spec app.json --enable # enable agents/functions on channels
|
|
90
|
+
muhkoo hosting status <appId> # releases + current pointer
|
|
91
|
+
muhkoo hosting rollback <appId> --release <id> # instant rollback
|
|
92
|
+
muhkoo domains add <appId> app.example.com # attach a custom domain
|
|
93
|
+
muhkoo agents enable <appId> <agentId> --channel general
|
|
94
|
+
muhkoo eject src/agent/agentApp.ts # preview an agent's prompt + tools
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## The provision spec
|
|
98
|
+
|
|
99
|
+
```jsonc
|
|
100
|
+
{
|
|
101
|
+
"slug": "team-standup",
|
|
102
|
+
"allowedOrigins": "*",
|
|
103
|
+
"email": "you@example.com", // only needed to bootstrap a new developer
|
|
104
|
+
"tables": [
|
|
105
|
+
{
|
|
106
|
+
"table": "tasks",
|
|
107
|
+
"columns": [
|
|
108
|
+
{ "name": "title", "type": "text", "nullable": false },
|
|
109
|
+
{ "name": "done", "type": "boolean", "nullable": false, "default": false }
|
|
110
|
+
]
|
|
111
|
+
}
|
|
112
|
+
],
|
|
113
|
+
"agents": [ { "handle": "@helper", "model": "...", "systemPrompt": "...", "enableChannel": "general" } ],
|
|
114
|
+
"functions": [ { "name": "hello", "code": "export default { async fetch() { return new Response('hi'); } }" } ]
|
|
115
|
+
}
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
`provision` is idempotent — re-running updates tables/agents/functions in place.
|
|
119
|
+
|
|
120
|
+
## License
|
|
121
|
+
|
|
122
|
+
MIT
|
package/bin/muhkoo.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* muhkoo — Muhkoo platform CLI.
|
|
4
|
+
*
|
|
5
|
+
* Thin launcher: delegates to src/index.js, which owns routing. Top-level errors
|
|
6
|
+
* are printed cleanly and exit non-zero. An explicit exit keeps a programmatic ZK
|
|
7
|
+
* login (which leaves prover worker threads alive) from hanging the process.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { run } from "../src/index.js";
|
|
11
|
+
|
|
12
|
+
run(process.argv.slice(2))
|
|
13
|
+
.then(() => process.exit(0))
|
|
14
|
+
.catch((e) => {
|
|
15
|
+
console.error(`\n✗ ${e?.stack || e?.message || String(e)}\n`);
|
|
16
|
+
process.exit(1);
|
|
17
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@muhkoo/cli",
|
|
3
|
+
"version": "0.7.0-alpha.4",
|
|
4
|
+
"description": "Command-line interface for the Muhkoo platform — provision backends, deploy apps, and manage agents, functions, databases, and domains.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"author": "muhkoo",
|
|
8
|
+
"repository": "https://github.com/muhkoo/cli.git",
|
|
9
|
+
"homepage": "https://docs.muhkoo.dev",
|
|
10
|
+
"bugs": "https://github.com/muhkoo/cli/issues",
|
|
11
|
+
"keywords": [
|
|
12
|
+
"muhkoo",
|
|
13
|
+
"cli",
|
|
14
|
+
"deploy",
|
|
15
|
+
"serverless",
|
|
16
|
+
"edge",
|
|
17
|
+
"zero-knowledge"
|
|
18
|
+
],
|
|
19
|
+
"publishConfig": {
|
|
20
|
+
"access": "public"
|
|
21
|
+
},
|
|
22
|
+
"bin": {
|
|
23
|
+
"muhkoo": "bin/muhkoo.js"
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"bin/**",
|
|
27
|
+
"src/**",
|
|
28
|
+
"README.md",
|
|
29
|
+
"LICENSE"
|
|
30
|
+
],
|
|
31
|
+
"engines": {
|
|
32
|
+
"node": ">=20"
|
|
33
|
+
},
|
|
34
|
+
"scripts": {
|
|
35
|
+
"muhkoo": "node bin/muhkoo.js",
|
|
36
|
+
"lint": "node --check bin/muhkoo.js",
|
|
37
|
+
"sync-version": "node scripts/sync-version.mjs",
|
|
38
|
+
"prepublishOnly": "node scripts/sync-version.mjs --check"
|
|
39
|
+
},
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"@muhkoo/connect": "0.7.0-alpha.4"
|
|
42
|
+
},
|
|
43
|
+
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
|
|
44
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal runner for `muhkoo eject`. Prints the system prompt + tools config for
|
|
3
|
+
* a `@Muhkoo*`-decorated agent description module. Run under `tsx` so it can
|
|
4
|
+
* import a TypeScript target with `experimentalDecorators` enabled.
|
|
5
|
+
*
|
|
6
|
+
* Two supported shapes:
|
|
7
|
+
* 1. The module exports `agentPrompt()` + `agentTools()` helpers — used directly.
|
|
8
|
+
* 2. The module exports the decorated class — we resolve `@muhkoo/connect` from
|
|
9
|
+
* the target's own project and eject from the class.
|
|
10
|
+
*/
|
|
11
|
+
import { createRequire } from "node:module";
|
|
12
|
+
import { pathToFileURL } from "node:url";
|
|
13
|
+
import { resolve } from "node:path";
|
|
14
|
+
|
|
15
|
+
async function main() {
|
|
16
|
+
const target = process.argv[2];
|
|
17
|
+
const exportName = process.argv[3];
|
|
18
|
+
if (!target) {
|
|
19
|
+
console.error("usage: _eject-runner.mjs <file.ts> [ExportName]");
|
|
20
|
+
process.exit(1);
|
|
21
|
+
}
|
|
22
|
+
const targetAbs = resolve(target);
|
|
23
|
+
const mod = await import(pathToFileURL(targetAbs).href);
|
|
24
|
+
|
|
25
|
+
let prompt;
|
|
26
|
+
let tools;
|
|
27
|
+
|
|
28
|
+
if (typeof mod.agentPrompt === "function" && typeof mod.agentTools === "function") {
|
|
29
|
+
prompt = mod.agentPrompt();
|
|
30
|
+
tools = mod.agentTools();
|
|
31
|
+
} else {
|
|
32
|
+
const require = createRequire(targetAbs);
|
|
33
|
+
const connectUrl = pathToFileURL(require.resolve("@muhkoo/connect")).href;
|
|
34
|
+
const { ejectAgentPrompt, ejectAgentTools } = await import(connectUrl);
|
|
35
|
+
|
|
36
|
+
let cls;
|
|
37
|
+
if (exportName) cls = mod[exportName];
|
|
38
|
+
else if (typeof mod.default === "function") cls = mod.default;
|
|
39
|
+
else cls = Object.values(mod).find((v) => typeof v === "function");
|
|
40
|
+
|
|
41
|
+
if (typeof cls !== "function") {
|
|
42
|
+
console.error(
|
|
43
|
+
`No decorated class or agentPrompt/agentTools exports found in ${target}. ` +
|
|
44
|
+
"Export the class (default or named, or pass its name) or the helper functions.",
|
|
45
|
+
);
|
|
46
|
+
process.exit(1);
|
|
47
|
+
}
|
|
48
|
+
prompt = ejectAgentPrompt(cls);
|
|
49
|
+
tools = ejectAgentTools(cls);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
console.log("\n===================== system prompt =====================\n");
|
|
53
|
+
console.log(prompt);
|
|
54
|
+
console.log("\n====================== tools config =====================\n");
|
|
55
|
+
console.log(JSON.stringify(tools, null, 2));
|
|
56
|
+
console.log("");
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
void main();
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `muhkoo agents` — list, inspect, remove, and enable/disable an app's agents.
|
|
3
|
+
* Agents are usually created via `muhkoo provision`; this manages them after.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { devContext } from "../lib/config.js";
|
|
7
|
+
import { devCall, ensure } from "../lib/http.js";
|
|
8
|
+
import { resolveSpace } from "../lib/spaces.js";
|
|
9
|
+
import { table, json, ok, info, die } from "../lib/ui.js";
|
|
10
|
+
|
|
11
|
+
export const help = `muhkoo agents — manage programmable agents
|
|
12
|
+
|
|
13
|
+
Usage:
|
|
14
|
+
muhkoo agents ls <appId> [--json]
|
|
15
|
+
muhkoo agents get <appId> <agentId> [--json]
|
|
16
|
+
muhkoo agents rm <appId> <agentId>
|
|
17
|
+
muhkoo agents enable <appId> <agentId> --space <spaceId>
|
|
18
|
+
muhkoo agents disable <appId> <agentId> --space <spaceId>
|
|
19
|
+
muhkoo agents models list models that support agents`;
|
|
20
|
+
|
|
21
|
+
export default async function agents(args) {
|
|
22
|
+
const sub = args._[1];
|
|
23
|
+
if (sub === "models") return models(args);
|
|
24
|
+
const ctx = await devContext(args);
|
|
25
|
+
const appId = args._[2] || args.app;
|
|
26
|
+
if (!appId) die("Missing app id. Usage: muhkoo agents <ls|get|rm|enable|disable> <appId>");
|
|
27
|
+
|
|
28
|
+
switch (sub) {
|
|
29
|
+
case "ls":
|
|
30
|
+
case undefined:
|
|
31
|
+
return list(ctx, appId, args);
|
|
32
|
+
case "get":
|
|
33
|
+
return get(ctx, appId, args);
|
|
34
|
+
case "rm":
|
|
35
|
+
case "delete":
|
|
36
|
+
return remove(ctx, appId, args);
|
|
37
|
+
case "enable":
|
|
38
|
+
return toggle(ctx, appId, args, "enable");
|
|
39
|
+
case "disable":
|
|
40
|
+
return toggle(ctx, appId, args, "disable");
|
|
41
|
+
default:
|
|
42
|
+
die(`Unknown subcommand "agents ${sub}". See \`muhkoo agents --help\`.`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
async function list(ctx, appId, args) {
|
|
47
|
+
const r = ensure(await devCall(ctx, "GET", `/api/apps/${appId}/agents`), "List agents");
|
|
48
|
+
const items = r.body?.agents || [];
|
|
49
|
+
if (args.json) return json(items);
|
|
50
|
+
if (!items.length) return info("No agents. Define them in a provision spec and run `muhkoo provision`.");
|
|
51
|
+
table(
|
|
52
|
+
["HANDLE", "AGENT ID", "MODEL"],
|
|
53
|
+
items.map((a) => [a.handle, a.agentId, a.model ?? ""]),
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async function get(ctx, appId, args) {
|
|
58
|
+
const agentId = args._[3];
|
|
59
|
+
if (!agentId) die("Usage: muhkoo agents get <appId> <agentId>");
|
|
60
|
+
const r = ensure(await devCall(ctx, "GET", `/api/apps/${appId}/agents/${agentId}`), "Get agent");
|
|
61
|
+
json(r.body);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async function remove(ctx, appId, args) {
|
|
65
|
+
const agentId = args._[3];
|
|
66
|
+
if (!agentId) die("Usage: muhkoo agents rm <appId> <agentId>");
|
|
67
|
+
ensure(await devCall(ctx, "DELETE", `/api/apps/${appId}/agents/${agentId}`), "Delete agent");
|
|
68
|
+
ok(`Deleted agent ${agentId}.`);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** Enable/disable an agent on a Space. `--space` may be a spaceId or `#channel`. */
|
|
72
|
+
async function toggle(ctx, appId, args, action) {
|
|
73
|
+
const agentId = args._[3];
|
|
74
|
+
if (!agentId) die(`Usage: muhkoo agents ${action} <appId> <agentId> --space <spaceId|#channel>`);
|
|
75
|
+
const targetSpaceId = await resolveSpace(ctx, args);
|
|
76
|
+
const r = await devCall(ctx, "POST", `/api/apps/${appId}/agents/${agentId}/${action}`, { targetSpaceId });
|
|
77
|
+
if (r.status === 402) die("Agents need a paid plan.");
|
|
78
|
+
ensure(r, `${action} agent`);
|
|
79
|
+
ok(`${action === "enable" ? "Enabled" : "Disabled"} ${agentId} on ${targetSpaceId}.`);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
async function models(args) {
|
|
83
|
+
const ctx = await devContext(args);
|
|
84
|
+
const r = ensure(await devCall(ctx, "GET", "/api/apps/agent-models"), "Agent models");
|
|
85
|
+
if (args.json) return json(r.body);
|
|
86
|
+
info("Function-calling models (usable by agents):");
|
|
87
|
+
for (const m of r.body?.fnCallingModels || []) info(` ${m}`);
|
|
88
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `muhkoo apps` — list, inspect, create, and delete apps, plus key rotation.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { devContext } from "../lib/config.js";
|
|
6
|
+
import { devCall, ensure } from "../lib/http.js";
|
|
7
|
+
import { table, json, ok, step, info, die, warn, c } from "../lib/ui.js";
|
|
8
|
+
import { appsSuffixFor } from "../lib/bases.js";
|
|
9
|
+
|
|
10
|
+
export const help = `muhkoo apps — manage your apps
|
|
11
|
+
|
|
12
|
+
Usage:
|
|
13
|
+
muhkoo apps ls [--json]
|
|
14
|
+
muhkoo apps get <appId> [--json]
|
|
15
|
+
muhkoo apps create --slug <slug> [--email <e>] [--origins <list>] [--json]
|
|
16
|
+
muhkoo apps slug <slug> check whether a slug is available
|
|
17
|
+
muhkoo apps rm <appId> delete an app and revoke its keys
|
|
18
|
+
muhkoo keys rotate <appId> [--json] rotate all four app keys`;
|
|
19
|
+
|
|
20
|
+
export default async function apps(args) {
|
|
21
|
+
const sub = args._[1];
|
|
22
|
+
const ctx = await devContext(args);
|
|
23
|
+
switch (sub) {
|
|
24
|
+
case "ls":
|
|
25
|
+
case undefined:
|
|
26
|
+
return list(ctx, args);
|
|
27
|
+
case "get":
|
|
28
|
+
return get(ctx, args);
|
|
29
|
+
case "create":
|
|
30
|
+
return create(ctx, args);
|
|
31
|
+
case "slug":
|
|
32
|
+
return slug(ctx, args);
|
|
33
|
+
case "rm":
|
|
34
|
+
case "delete":
|
|
35
|
+
return remove(ctx, args);
|
|
36
|
+
default:
|
|
37
|
+
die(`Unknown subcommand "apps ${sub}". See \`muhkoo apps --help\`.`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async function list(ctx, args) {
|
|
42
|
+
const r = ensure(await devCall(ctx, "GET", "/api/apps"), "List apps");
|
|
43
|
+
const apps = r.body?.apps || r.body || [];
|
|
44
|
+
if (args.json) return json(apps);
|
|
45
|
+
if (!apps.length) return info("No apps yet. Create one with `muhkoo apps create --slug <name>`.");
|
|
46
|
+
table(
|
|
47
|
+
["SLUG", "APP ID", "ORIGINS"],
|
|
48
|
+
apps.map((a) => [a.slug, a.appId, a.allowedOrigins ?? "*"]),
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async function get(ctx, args) {
|
|
53
|
+
const appId = args._[2] || args.app;
|
|
54
|
+
if (!appId) die("Usage: muhkoo apps get <appId>");
|
|
55
|
+
const r = ensure(await devCall(ctx, "GET", `/api/apps/${appId}`), "Get app");
|
|
56
|
+
if (args.json) return json(r.body);
|
|
57
|
+
const a = r.body;
|
|
58
|
+
info(`${c.bold("slug")} ${a.slug}`);
|
|
59
|
+
info(`${c.bold("appId")} ${a.appId}`);
|
|
60
|
+
info(`${c.bold("origins")} ${a.allowedOrigins ?? "*"}`);
|
|
61
|
+
info(`${c.bold("hosting")} https://${a.slug}.${appsSuffixFor(ctx.baseUrl)}`);
|
|
62
|
+
if (Array.isArray(a.keys)) {
|
|
63
|
+
info(`${c.bold("keys")}`);
|
|
64
|
+
for (const k of a.keys) info(` ${k.env}/${k.type} ${k.keyId}`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async function create(ctx, args) {
|
|
69
|
+
const slugName = args.slug || args._[2];
|
|
70
|
+
if (!slugName) die("Usage: muhkoo apps create --slug <slug> [--email <e>]");
|
|
71
|
+
const body = { slug: slugName, allowedOrigins: args.origins || "*" };
|
|
72
|
+
if (args.email) body.email = args.email;
|
|
73
|
+
step(`Creating app "${slugName}"…`);
|
|
74
|
+
let r = await devCall(ctx, "POST", "/api/apps", body);
|
|
75
|
+
if (!r.ok && r.status === 402 && args.email) {
|
|
76
|
+
step("Bootstrapping developer account…");
|
|
77
|
+
ensure(await devCall(ctx, "POST", "/api/developer/bootstrap", { email: args.email }), "Bootstrap");
|
|
78
|
+
r = await devCall(ctx, "POST", "/api/apps", body);
|
|
79
|
+
}
|
|
80
|
+
if (!r.ok && r.status === 402) {
|
|
81
|
+
die("This developer account needs a billing email. Re-run with `--email you@example.com`.");
|
|
82
|
+
}
|
|
83
|
+
ensure(r, "Create app");
|
|
84
|
+
if (args.json) return json(r.body);
|
|
85
|
+
const keys = r.body.keys || [];
|
|
86
|
+
ok(`Created ${c.bold(r.body.slug)} (${r.body.appId})`);
|
|
87
|
+
info(` hosting: https://${r.body.slug}.${appsSuffixFor(ctx.baseUrl)}`);
|
|
88
|
+
info(" keys:");
|
|
89
|
+
for (const k of keys) info(` ${k.env}/${k.type} ${k.plaintext}`);
|
|
90
|
+
warn("Save the secret (sk) keys now — they are shown only once.");
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
async function slug(ctx, args) {
|
|
94
|
+
const name = args._[2] || args.slug;
|
|
95
|
+
if (!name) die("Usage: muhkoo apps slug <slug>");
|
|
96
|
+
const r = ensure(
|
|
97
|
+
await devCall(ctx, "GET", `/api/apps/slug-available?slug=${encodeURIComponent(name)}`),
|
|
98
|
+
"Slug check",
|
|
99
|
+
);
|
|
100
|
+
info(r.body?.available ? `${c.green("available")} ${name}` : `${c.red("taken")} ${name}`);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
async function remove(ctx, args) {
|
|
104
|
+
const appId = args._[2] || args.app;
|
|
105
|
+
if (!appId) die("Usage: muhkoo apps rm <appId>");
|
|
106
|
+
ensure(await devCall(ctx, "DELETE", `/api/apps/${appId}`), "Delete app");
|
|
107
|
+
ok(`Deleted app ${appId} and revoked its keys.`);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** `muhkoo keys rotate <appId>` — routed here from index.js. */
|
|
111
|
+
export async function keysRotate(args) {
|
|
112
|
+
const ctx = await devContext(args);
|
|
113
|
+
const appId = args._[2] || args.app;
|
|
114
|
+
if (!appId) die("Usage: muhkoo keys rotate <appId>");
|
|
115
|
+
const r = ensure(await devCall(ctx, "POST", `/api/apps/${appId}/keys/rotate`), "Rotate keys");
|
|
116
|
+
if (args.json) return json(r.body);
|
|
117
|
+
ok(`Rotated keys for ${appId} — old keys are now revoked.`);
|
|
118
|
+
for (const k of r.body.keys || []) info(` ${k.env}/${k.type} ${k.plaintext}`);
|
|
119
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `muhkoo deploy` — deploy a built `dist/` to Muhkoo hosting. Content-addressed:
|
|
3
|
+
* each file uploads by its sha256 (only changed files transfer), then a release
|
|
4
|
+
* is committed (an atomic pointer flip; instant + rollback-able).
|
|
5
|
+
*
|
|
6
|
+
* Auth accepts EITHER an app secret key (--key / $MUHKOO_DEPLOY_KEY) or your
|
|
7
|
+
* developer session (`muhkoo login`). The app id and key are read from
|
|
8
|
+
* .muhkoo-app.json when present, so a provisioned app deploys with no flags.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { readFile, readdir, stat, access } from "node:fs/promises";
|
|
12
|
+
import { createHash } from "node:crypto";
|
|
13
|
+
import { join, relative, sep } from "node:path";
|
|
14
|
+
import { resolveBase, loadConfig, resolveToken } from "../lib/config.js";
|
|
15
|
+
import { skCall, ensure } from "../lib/http.js";
|
|
16
|
+
import { firstOf } from "../lib/args.js";
|
|
17
|
+
import { step, ok, info, die } from "../lib/ui.js";
|
|
18
|
+
|
|
19
|
+
export const help = `muhkoo deploy — deploy a built client to Muhkoo hosting
|
|
20
|
+
|
|
21
|
+
Usage:
|
|
22
|
+
muhkoo deploy [--app <appId>] [--key <mk_*_sk_*>] [--dist dist] [--base <env|url>]
|
|
23
|
+
|
|
24
|
+
Defaults: --app and --key fall back to .muhkoo-app.json, then $MUHKOO_APP_ID /
|
|
25
|
+
$MUHKOO_DEPLOY_KEY. With no app secret key, your developer session is used.`;
|
|
26
|
+
|
|
27
|
+
async function readRecord() {
|
|
28
|
+
try {
|
|
29
|
+
await access(".muhkoo-app.json");
|
|
30
|
+
return JSON.parse(await readFile(".muhkoo-app.json", "utf8"));
|
|
31
|
+
} catch {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async function walk(dir) {
|
|
37
|
+
const out = [];
|
|
38
|
+
for (const entry of await readdir(dir, { withFileTypes: true })) {
|
|
39
|
+
const full = join(dir, entry.name);
|
|
40
|
+
if (entry.isDirectory()) out.push(...(await walk(full)));
|
|
41
|
+
else if (entry.isFile()) out.push(full);
|
|
42
|
+
}
|
|
43
|
+
return out;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export default async function deploy(args) {
|
|
47
|
+
const cfg = await loadConfig();
|
|
48
|
+
const record = await readRecord();
|
|
49
|
+
const baseUrl = args.base ? await resolveBase(args, cfg) : record?.baseUrl || (await resolveBase(args, cfg));
|
|
50
|
+
const appId = firstOf(args.app, process.env.MUHKOO_APP_ID, record?.appId);
|
|
51
|
+
if (!appId) die("Missing app id. Pass --app <appId>, set MUHKOO_APP_ID, or run from a provisioned app dir.");
|
|
52
|
+
|
|
53
|
+
// 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;
|
|
55
|
+
let auth = firstOf(args.key, process.env.MUHKOO_DEPLOY_KEY, skFromRecord);
|
|
56
|
+
if (auth && !/_sk_/.test(auth)) die("--key must be an app SECRET key (mk_*_sk_*), not a publishable key.");
|
|
57
|
+
if (!auth) auth = await resolveToken(args, cfg); // developer session is accepted by hosting
|
|
58
|
+
|
|
59
|
+
const dist = args.dist || "dist";
|
|
60
|
+
let files;
|
|
61
|
+
try {
|
|
62
|
+
if (!(await stat(dist)).isDirectory()) throw new Error();
|
|
63
|
+
files = await walk(dist);
|
|
64
|
+
} catch {
|
|
65
|
+
die(`No build output at "${dist}". Build your client first (or pass --dist).`);
|
|
66
|
+
}
|
|
67
|
+
if (!files.length) die(`"${dist}" is empty.`);
|
|
68
|
+
|
|
69
|
+
step(`Deploying ${files.length} files from ${dist}/ → ${baseUrl}`);
|
|
70
|
+
|
|
71
|
+
const manifest = {};
|
|
72
|
+
const blobs = new Map();
|
|
73
|
+
for (const file of files) {
|
|
74
|
+
const bytes = await readFile(file);
|
|
75
|
+
const sha = createHash("sha256").update(bytes).digest("hex");
|
|
76
|
+
manifest[relative(dist, file).split(sep).join("/")] = sha;
|
|
77
|
+
if (!blobs.has(sha)) blobs.set(sha, bytes);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
let uploaded = 0;
|
|
81
|
+
let deduped = 0;
|
|
82
|
+
for (const [sha, bytes] of blobs) {
|
|
83
|
+
const r = await skCall(baseUrl, auth, "PUT", `/api/apps/${appId}/hosting/blob/${sha}`, bytes, { raw: true });
|
|
84
|
+
if (!r.ok) die(`Upload failed for ${sha} (${r.status}): ${await r.res.text()}`);
|
|
85
|
+
const body = await r.res.json().catch(() => ({}));
|
|
86
|
+
if (body.dedup) deduped++;
|
|
87
|
+
else uploaded++;
|
|
88
|
+
}
|
|
89
|
+
info(` ${uploaded} uploaded, ${deduped} unchanged (${blobs.size} unique files)`);
|
|
90
|
+
|
|
91
|
+
step("Committing release…");
|
|
92
|
+
const rel = ensure(
|
|
93
|
+
await skCall(baseUrl, auth, "POST", `/api/apps/${appId}/hosting/releases`, { manifest }),
|
|
94
|
+
"Release",
|
|
95
|
+
);
|
|
96
|
+
info("");
|
|
97
|
+
ok("Deployed.");
|
|
98
|
+
info(` release: ${rel.body.releaseId}`);
|
|
99
|
+
info(` size: ${(rel.body.bytes / 1024).toFixed(0)} KiB across ${rel.body.files} files`);
|
|
100
|
+
info(` live at: ${rel.body.url}`);
|
|
101
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `muhkoo domains` — attach and manage custom domains for an app's hosted site.
|
|
3
|
+
* Custom domains require a paid plan. Adding one returns the DNS records to set.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { devContext } from "../lib/config.js";
|
|
7
|
+
import { devCall, ensure } from "../lib/http.js";
|
|
8
|
+
import { table, json, ok, info, warn, die, c } from "../lib/ui.js";
|
|
9
|
+
|
|
10
|
+
export const help = `muhkoo domains — manage custom domains
|
|
11
|
+
|
|
12
|
+
Usage:
|
|
13
|
+
muhkoo domains ls <appId> [--json]
|
|
14
|
+
muhkoo domains add <appId> <hostname> [--json]
|
|
15
|
+
muhkoo domains rm <appId> <hostname>`;
|
|
16
|
+
|
|
17
|
+
export default async function domains(args) {
|
|
18
|
+
const sub = args._[1];
|
|
19
|
+
const ctx = await devContext(args);
|
|
20
|
+
const appId = args._[2] || args.app;
|
|
21
|
+
if (!appId) die("Missing app id. Usage: muhkoo domains <ls|add|rm> <appId> [hostname]");
|
|
22
|
+
|
|
23
|
+
switch (sub) {
|
|
24
|
+
case "ls":
|
|
25
|
+
case undefined:
|
|
26
|
+
return list(ctx, appId, args);
|
|
27
|
+
case "add":
|
|
28
|
+
return add(ctx, appId, args);
|
|
29
|
+
case "rm":
|
|
30
|
+
case "remove":
|
|
31
|
+
return remove(ctx, appId, args);
|
|
32
|
+
default:
|
|
33
|
+
die(`Unknown subcommand "domains ${sub}". See \`muhkoo domains --help\`.`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async function list(ctx, appId, args) {
|
|
38
|
+
const r = ensure(await devCall(ctx, "GET", `/api/apps/${appId}/hosting/domains`), "List domains");
|
|
39
|
+
if (args.json) return json(r.body);
|
|
40
|
+
const items = r.body?.domains || [];
|
|
41
|
+
if (!items.length) return info("No custom domains. Add one with `muhkoo domains add <appId> <hostname>`.");
|
|
42
|
+
table(
|
|
43
|
+
["HOSTNAME", "STATUS", "SSL", "VERIFIED"],
|
|
44
|
+
items.map((d) => [d.hostname, d.status ?? "", d.sslStatus ?? "", d.verified ? "yes" : "no"]),
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async function add(ctx, appId, args) {
|
|
49
|
+
const hostname = args._[3] || args.hostname;
|
|
50
|
+
if (!hostname) die("Usage: muhkoo domains add <appId> <hostname>");
|
|
51
|
+
const r = await devCall(ctx, "POST", `/api/apps/${appId}/hosting/domains`, { hostname });
|
|
52
|
+
if (r.status === 402) die("Custom domains need a paid plan.");
|
|
53
|
+
ensure(r, "Add domain");
|
|
54
|
+
if (args.json) return json(r.body);
|
|
55
|
+
ok(`Attached ${c.bold(hostname)}.`);
|
|
56
|
+
const records = r.body?.records || r.body?.dnsRecords || [];
|
|
57
|
+
if (records.length) {
|
|
58
|
+
info("\nAdd these DNS records at your registrar:");
|
|
59
|
+
table(
|
|
60
|
+
["TYPE", "NAME", "VALUE"],
|
|
61
|
+
records.map((d) => [d.type, d.name, d.value]),
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
warn("SSL is issued after DNS validates — this can take a few minutes.");
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
async function remove(ctx, appId, args) {
|
|
68
|
+
const hostname = args._[3] || args.hostname;
|
|
69
|
+
if (!hostname) die("Usage: muhkoo domains rm <appId> <hostname>");
|
|
70
|
+
ensure(
|
|
71
|
+
await devCall(ctx, "DELETE", `/api/apps/${appId}/hosting/domains/${encodeURIComponent(hostname)}`),
|
|
72
|
+
"Remove domain",
|
|
73
|
+
);
|
|
74
|
+
ok(`Removed ${hostname}.`);
|
|
75
|
+
}
|