@muhkoo/cli 0.10.11-alpha.0 → 0.12.0-alpha.0
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/bin/muhkoo.js +0 -0
- package/package.json +8 -4
- package/src/commands/devices.js +58 -0
- package/src/commands/vcs.js +229 -0
- package/src/commands/vfs.js +425 -0
- package/src/index.js +9 -0
- package/src/lib/auth.js +2 -2
- package/src/lib/ignore.js +174 -0
- package/src/lib/mount.js +396 -0
- package/src/lib/syncPlan.js +54 -0
- package/src/lib/vfs.js +182 -0
package/bin/muhkoo.js
CHANGED
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@muhkoo/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0-alpha.0",
|
|
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",
|
|
@@ -35,11 +35,15 @@
|
|
|
35
35
|
"muhkoo": "node bin/muhkoo.js",
|
|
36
36
|
"lint": "node --check bin/muhkoo.js",
|
|
37
37
|
"sync-version": "node scripts/sync-version.mjs",
|
|
38
|
-
"prepublishOnly": "node scripts/sync-version.mjs --check"
|
|
38
|
+
"prepublishOnly": "node scripts/sync-version.mjs --check",
|
|
39
|
+
"test": "vitest run"
|
|
39
40
|
},
|
|
40
41
|
"dependencies": {
|
|
41
|
-
"@muhkoo/connect": "0.
|
|
42
|
+
"@muhkoo/connect": "0.12.0-alpha.0",
|
|
42
43
|
"snarkjs": "^0.7.0"
|
|
43
44
|
},
|
|
44
|
-
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
|
|
45
|
+
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e",
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"vitest": "^2.1.9"
|
|
48
|
+
}
|
|
45
49
|
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `muhkoo devices` — machines paired to your account.
|
|
3
|
+
*
|
|
4
|
+
* A paired machine holds a key that unwraps the master seed held (encrypted) in
|
|
5
|
+
* your vault. The seed itself is never on that machine's disk, so revoking here
|
|
6
|
+
* genuinely withdraws its access — unlike a copied seed, which nothing can
|
|
7
|
+
* reach out and un-store.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { openClient } from "../lib/vfs.js";
|
|
11
|
+
import { loadConfig, saveConfig } from "../lib/config.js";
|
|
12
|
+
import { table, json, ok, info, die } from "../lib/ui.js";
|
|
13
|
+
|
|
14
|
+
export const help = `muhkoo devices — machines paired to your account
|
|
15
|
+
|
|
16
|
+
Usage:
|
|
17
|
+
muhkoo devices ls [--json] list paired machines
|
|
18
|
+
muhkoo devices rm <factorId> withdraw a machine's access`;
|
|
19
|
+
|
|
20
|
+
export default async function devices(args) {
|
|
21
|
+
const sub = args._[1] ?? "ls";
|
|
22
|
+
const client = await openClient(args);
|
|
23
|
+
const cfg = await loadConfig();
|
|
24
|
+
|
|
25
|
+
switch (sub) {
|
|
26
|
+
case "ls": {
|
|
27
|
+
const list = await client.auth.zk.listDevices();
|
|
28
|
+
if (args.json) return json(list);
|
|
29
|
+
if (!list.length) return info("No paired machines.");
|
|
30
|
+
return table(
|
|
31
|
+
["ID", "LABEL", "PAIRED", ""],
|
|
32
|
+
list.map((d) => [
|
|
33
|
+
d.id,
|
|
34
|
+
d.label ?? "-",
|
|
35
|
+
d.createdAt ? new Date(d.createdAt).toISOString().slice(0, 10) : "-",
|
|
36
|
+
d.id === cfg.deviceFactorId ? "← this machine" : "",
|
|
37
|
+
]),
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
case "rm": {
|
|
42
|
+
const id = args._[2];
|
|
43
|
+
if (!id) die("Missing device id. Usage: muhkoo devices rm <factorId>");
|
|
44
|
+
const deleted = await client.auth.zk.revokeDevice(id);
|
|
45
|
+
if (!deleted) return die(`No paired machine with id ${id}.`);
|
|
46
|
+
// Revoking THIS machine must clear the now-useless local key, or every
|
|
47
|
+
// later command retries a pairing the server has already forgotten.
|
|
48
|
+
if (id === cfg.deviceFactorId) {
|
|
49
|
+
await saveConfig({ ...cfg, deviceFactorId: undefined, deviceKey: undefined });
|
|
50
|
+
return ok("Revoked this machine. Run any `muhkoo vfs` command to pair it again.");
|
|
51
|
+
}
|
|
52
|
+
return ok(`Revoked ${id}.`);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
default:
|
|
56
|
+
return die(`Unknown subcommand "devices ${sub}". See \`muhkoo devices --help\`.`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `muhkoo vcs` — version control over your Muhkoo filesystem.
|
|
3
|
+
*
|
|
4
|
+
* Drives `client.vcs` through the SDK, for the same reason `muhkoo vfs` does:
|
|
5
|
+
* commit hashes are computed from a canonical encoding, and a second
|
|
6
|
+
* implementation here would only have to agree byte-for-byte forever. The first
|
|
7
|
+
* one to drift would fork the history of a project silently.
|
|
8
|
+
*
|
|
9
|
+
* There is no `push` or `pull`. The repository already lives in your account
|
|
10
|
+
* rather than on your disk, so every machine you sign in from is looking at the
|
|
11
|
+
* same objects — there is nowhere to push it to.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { openClient } from "../lib/vfs.js";
|
|
15
|
+
import { loadConfig, saveConfig } from "../lib/config.js";
|
|
16
|
+
import { table, json, ok, info, warn, die, c } from "../lib/ui.js";
|
|
17
|
+
|
|
18
|
+
export const help = `muhkoo vcs — version control for your projects
|
|
19
|
+
|
|
20
|
+
Usage:
|
|
21
|
+
muhkoo vcs status what has changed since the last commit
|
|
22
|
+
muhkoo vcs commit -m <message> record the current state
|
|
23
|
+
muhkoo vcs log [-n <count>] history, newest first
|
|
24
|
+
muhkoo vcs show <commit> what one commit changed
|
|
25
|
+
muhkoo vcs diff [<a>] [<b>] compare two commits (default: last vs now)
|
|
26
|
+
muhkoo vcs branch [<name>] list branches, or start one here
|
|
27
|
+
muhkoo vcs switch <name> move onto a branch
|
|
28
|
+
muhkoo vcs checkout <commit> inspect an old state (detaches HEAD)
|
|
29
|
+
muhkoo vcs merge <name> bring a branch into this one
|
|
30
|
+
muhkoo vcs restore <path> [<commit>] put one file back
|
|
31
|
+
|
|
32
|
+
Options:
|
|
33
|
+
--project <slug> which project (default: taken from your vfs working
|
|
34
|
+
directory, so \`vfs cd /apps/my-app\` then \`vcs log\`)
|
|
35
|
+
-m <message> the commit message
|
|
36
|
+
-n <count> how many entries to show
|
|
37
|
+
--discard throw away uncommitted changes instead of refusing to move
|
|
38
|
+
--json machine-readable output
|
|
39
|
+
|
|
40
|
+
There is no push or pull: the repository lives in your account, so every
|
|
41
|
+
machine you sign in from already has it.`;
|
|
42
|
+
|
|
43
|
+
export default async function vcs(args) {
|
|
44
|
+
const sub = args._[1];
|
|
45
|
+
if (sub === undefined) return die("Missing subcommand. See `muhkoo vcs --help`.");
|
|
46
|
+
|
|
47
|
+
// `-m "message"` and `-n 20`, pulled out of the positionals by hand.
|
|
48
|
+
//
|
|
49
|
+
// The shared parser only understands `--flags`, and teaching it single-dash
|
|
50
|
+
// options would break the commands that pass `-r` and friends as positionals.
|
|
51
|
+
// Committing without `-m` is muscle memory though, so it is worth the seam.
|
|
52
|
+
const message = pullFlag(args, "-m") ?? args.message ?? (args.m === true ? undefined : args.m);
|
|
53
|
+
const count = pullFlag(args, "-n") ?? args.n;
|
|
54
|
+
|
|
55
|
+
const client = await openClient(args);
|
|
56
|
+
const slug = await resolveProject(args);
|
|
57
|
+
const repo = client.vcs.open(slug);
|
|
58
|
+
const a = (n, dflt) => args._[n] ?? dflt;
|
|
59
|
+
|
|
60
|
+
switch (sub) {
|
|
61
|
+
case "status": {
|
|
62
|
+
const changes = await repo.status();
|
|
63
|
+
const branch = (await repo.currentBranch()) ?? `${c.dim("detached at")} ${short(await repo.current())}`;
|
|
64
|
+
const pending = await repo.pendingMerge();
|
|
65
|
+
if (args.json) return json({ project: slug, branch, changes, merging: pending?.name ?? null });
|
|
66
|
+
|
|
67
|
+
info(`${c.bold(slug)} on ${branch}`);
|
|
68
|
+
if (pending) warn(`Merging ${pending.name} — resolve the files below, then commit to finish it.`);
|
|
69
|
+
if (!changes.length) return info("Nothing has changed since the last commit.");
|
|
70
|
+
return table(["", "PATH"], changes.map((ch) => [mark(ch.kind), ch.path]));
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
case "commit": {
|
|
74
|
+
if (!message) return die("A commit needs a message: `muhkoo vcs commit -m \"what changed\"`");
|
|
75
|
+
const hash = await repo.commit(String(message));
|
|
76
|
+
return ok(`${short(hash)} ${message}`);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
case "log": {
|
|
80
|
+
const entries = await repo.log(Number(count ?? 20));
|
|
81
|
+
if (args.json) return json(entries);
|
|
82
|
+
if (!entries.length) return info("No commits yet.");
|
|
83
|
+
return table(
|
|
84
|
+
["COMMIT", "WHEN", "MESSAGE"],
|
|
85
|
+
entries.map((e) => [
|
|
86
|
+
short(e.hash) + (e.parents.length > 1 ? c.dim(" (merge)") : ""),
|
|
87
|
+
when(e.at),
|
|
88
|
+
e.message,
|
|
89
|
+
]),
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
case "show": {
|
|
94
|
+
const hash = await repo.resolve(required(a(2), "show <commit>"));
|
|
95
|
+
// The first commit has no parent to compare against; everything in it is
|
|
96
|
+
// an addition, which is what `diff(null, …)` reports.
|
|
97
|
+
const parent = await parentOf(repo, hash);
|
|
98
|
+
const changes = await repo.diff(parent, hash);
|
|
99
|
+
if (args.json) return json(changes);
|
|
100
|
+
return table(["", "PATH"], changes.map((ch) => [mark(ch.kind), ch.path]));
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
case "diff": {
|
|
104
|
+
// No arguments means the question people actually ask: what have I
|
|
105
|
+
// changed that is not committed yet.
|
|
106
|
+
if (a(2) === undefined) {
|
|
107
|
+
const pending = await repo.status();
|
|
108
|
+
if (args.json) return json(pending);
|
|
109
|
+
if (!pending.length) return info("No differences.");
|
|
110
|
+
return table(["", "PATH"], pending.map((ch) => [mark(ch.kind), ch.path]));
|
|
111
|
+
}
|
|
112
|
+
const from = await repo.resolve(a(2));
|
|
113
|
+
const to = a(3) === undefined ? await repo.resolve("HEAD") : await repo.resolve(a(3));
|
|
114
|
+
const changes = await repo.diff(from, to);
|
|
115
|
+
if (args.json) return json(changes);
|
|
116
|
+
if (!changes.length) return info("No differences.");
|
|
117
|
+
return table(["", "PATH"], changes.map((ch) => [mark(ch.kind), ch.path]));
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
case "branch": {
|
|
121
|
+
const name = a(2);
|
|
122
|
+
if (name) {
|
|
123
|
+
await repo.branch(name);
|
|
124
|
+
return ok(`Branch ${name} starts here. \`muhkoo vcs switch ${name}\` to move onto it.`);
|
|
125
|
+
}
|
|
126
|
+
const branches = await repo.branches();
|
|
127
|
+
const current = await repo.currentBranch();
|
|
128
|
+
if (args.json) return json({ branches, current });
|
|
129
|
+
if (!branches.length) return info("No branches yet — commit something first.");
|
|
130
|
+
return table(["", "BRANCH"], branches.map((b) => [b === current ? "*" : " ", b]));
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
case "switch": {
|
|
134
|
+
const name = required(a(2), "switch <name>");
|
|
135
|
+
await repo.switchTo(name, { discardChanges: Boolean(args.discard) });
|
|
136
|
+
return ok(`On ${name}.`);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
case "checkout": {
|
|
140
|
+
const hash = await repo.resolve(required(a(2), "checkout <commit>"));
|
|
141
|
+
await repo.checkout(hash, { discardChanges: Boolean(args.discard) });
|
|
142
|
+
// Say what happened, not just that it worked: a detached HEAD surprises
|
|
143
|
+
// people, and committing from one loses work if they did not expect it.
|
|
144
|
+
return ok(
|
|
145
|
+
`Your files are as they were at ${short(hash)}. HEAD is detached — ` +
|
|
146
|
+
`\`muhkoo vcs switch <branch>\` to go back to working normally.`,
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
case "merge": {
|
|
151
|
+
const name = required(a(2), "merge <name>");
|
|
152
|
+
const result = await repo.merge(name, { discardChanges: Boolean(args.discard) });
|
|
153
|
+
if (result.kind === "up-to-date") return info(`Already up to date with ${name}.`);
|
|
154
|
+
if (result.kind === "fast-forward") return ok(`Fast-forwarded to ${short(result.commit)}.`);
|
|
155
|
+
if (result.kind === "merged") return ok(`Merged ${name} — ${short(result.commit)}.`);
|
|
156
|
+
|
|
157
|
+
warn(`Merged ${name}, but ${result.conflicts.length} file(s) need you:`);
|
|
158
|
+
table(["", "PATH"], result.conflicts.map((cf) => [c.dim(cf.reason), cf.path]));
|
|
159
|
+
return info("Edit them, then `muhkoo vcs commit -m \"...\"` to finish the merge.");
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
case "restore": {
|
|
163
|
+
const path = required(a(2), "restore <path> [<commit>]");
|
|
164
|
+
await repo.restore(path, a(3));
|
|
165
|
+
return ok(`Restored ${path}.`);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
default:
|
|
169
|
+
return die(`Unknown subcommand "${sub}". See \`muhkoo vcs --help\`.`);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Which project this command is about.
|
|
175
|
+
*
|
|
176
|
+
* Taken from the VFS working directory when it can be, so `vfs cd /apps/my-app`
|
|
177
|
+
* followed by `vcs log` does what you would expect rather than making you name
|
|
178
|
+
* the project twice.
|
|
179
|
+
*/
|
|
180
|
+
async function resolveProject(args) {
|
|
181
|
+
if (args.project) return String(args.project);
|
|
182
|
+
const cfg = await loadConfig();
|
|
183
|
+
const cwd = cfg.vfsCwd ?? "/";
|
|
184
|
+
const match = cwd.match(/^\/apps\/([^/]+)/);
|
|
185
|
+
if (match) return match[1];
|
|
186
|
+
return die(
|
|
187
|
+
"Which project? Pass `--project <slug>`, or `muhkoo vfs cd /apps/<slug>` first.",
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Take a `-x value` pair out of the positionals and return the value.
|
|
193
|
+
*
|
|
194
|
+
* Mutates `args._` so the positional indices the subcommands read still line up
|
|
195
|
+
* with what the user typed.
|
|
196
|
+
*/
|
|
197
|
+
function pullFlag(args, flag) {
|
|
198
|
+
const i = args._.indexOf(flag);
|
|
199
|
+
if (i === -1) return undefined;
|
|
200
|
+
const [, value] = args._.splice(i, 2);
|
|
201
|
+
return value;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/** A commit's first parent, or null for the very first commit. */
|
|
205
|
+
async function parentOf(repo, hash) {
|
|
206
|
+
try {
|
|
207
|
+
return await repo.resolve(`${hash}^`);
|
|
208
|
+
} catch {
|
|
209
|
+
return null;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
function required(value, usage) {
|
|
214
|
+
if (value === undefined) die(`Usage: muhkoo vcs ${usage}`);
|
|
215
|
+
return value;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/** Commit hashes are long; the first 8 characters identify one in practice. */
|
|
219
|
+
function short(hash) {
|
|
220
|
+
return hash ? String(hash).slice(0, 8) : "-";
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
function mark(kind) {
|
|
224
|
+
return kind === "added" ? c.dim("+") : kind === "removed" ? c.dim("-") : c.dim("~");
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
function when(at) {
|
|
228
|
+
return new Date(at).toISOString().replace("T", " ").slice(0, 16);
|
|
229
|
+
}
|