@b3os/cli 0.1.0 → 0.2.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/README.md +72 -26
- package/bin/b3os.js +13 -3
- package/dist/commands/_common.d.ts +49 -0
- package/dist/commands/_common.js +174 -0
- package/dist/commands/_common.js.map +1 -0
- package/dist/commands/actions.d.ts +43 -0
- package/dist/commands/actions.js +184 -0
- package/dist/commands/actions.js.map +1 -0
- package/dist/commands/api.d.ts +24 -0
- package/dist/commands/api.js +14 -8
- package/dist/commands/api.js.map +1 -1
- package/dist/commands/app.d.ts +2 -0
- package/dist/commands/app.js +577 -0
- package/dist/commands/app.js.map +1 -0
- package/dist/commands/auth.d.ts +58 -0
- package/dist/commands/auth.js +228 -20
- package/dist/commands/auth.js.map +1 -1
- package/dist/commands/bench.d.ts +22 -0
- package/dist/commands/bench.js +19 -7
- package/dist/commands/bench.js.map +1 -1
- package/dist/commands/connect.d.ts +52 -0
- package/dist/commands/connect.js +221 -0
- package/dist/commands/connect.js.map +1 -0
- package/dist/commands/infer.d.ts +47 -0
- package/dist/commands/infer.js +152 -0
- package/dist/commands/infer.js.map +1 -0
- package/dist/commands/init.d.ts +45 -0
- package/dist/commands/init.js +267 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/commands/keys.d.ts +42 -0
- package/dist/commands/keys.js +70 -38
- package/dist/commands/keys.js.map +1 -1
- package/dist/commands/manifest.d.ts +63 -0
- package/dist/commands/manifest.js +398 -0
- package/dist/commands/manifest.js.map +1 -0
- package/dist/commands/mcp.d.ts +65 -0
- package/dist/commands/mcp.js +167 -50
- package/dist/commands/mcp.js.map +1 -1
- package/dist/commands/render.d.ts +119 -0
- package/dist/commands/render.js +294 -0
- package/dist/commands/render.js.map +1 -0
- package/dist/commands/requests.d.ts +41 -0
- package/dist/commands/requests.js +99 -0
- package/dist/commands/requests.js.map +1 -0
- package/dist/commands/routine.d.ts +53 -1
- package/dist/commands/routine.js +246 -110
- package/dist/commands/routine.js.map +1 -1
- package/dist/commands/sandbox.d.ts +130 -0
- package/dist/commands/sandbox.js +327 -55
- package/dist/commands/sandbox.js.map +1 -1
- package/dist/commands/vision.d.ts +196 -0
- package/dist/commands/vision.js +478 -0
- package/dist/commands/vision.js.map +1 -0
- package/dist/commands/webhooks.d.ts +20 -0
- package/dist/commands/webhooks.js +76 -0
- package/dist/commands/webhooks.js.map +1 -0
- package/dist/ctx.d.ts +80 -6
- package/dist/ctx.js +233 -24
- package/dist/ctx.js.map +1 -1
- package/dist/main.d.ts +4 -1
- package/dist/main.js +78 -41
- package/dist/main.js.map +1 -1
- package/dist/manifest/apply.d.ts +79 -0
- package/dist/manifest/apply.js +123 -0
- package/dist/manifest/apply.js.map +1 -0
- package/dist/manifest/grant.d.ts +1 -0
- package/dist/manifest/grant.js +3 -0
- package/dist/manifest/grant.js.map +1 -0
- package/dist/manifest/load.d.ts +6 -0
- package/dist/manifest/load.js +35 -0
- package/dist/manifest/load.js.map +1 -0
- package/dist/manifest/plan.d.ts +1 -0
- package/dist/manifest/plan.js +4 -0
- package/dist/manifest/plan.js.map +1 -0
- package/dist/manifest/record.d.ts +98 -0
- package/dist/manifest/record.js +233 -0
- package/dist/manifest/record.js.map +1 -0
- package/dist/manifest/skip.d.ts +1 -0
- package/dist/manifest/skip.js +3 -0
- package/dist/manifest/skip.js.map +1 -0
- package/dist/manifest/source.d.ts +48 -0
- package/dist/manifest/source.js +223 -0
- package/dist/manifest/source.js.map +1 -0
- package/dist/registry.d.ts +19 -0
- package/dist/registry.js +52 -0
- package/dist/registry.js.map +1 -0
- package/dist/suggest.d.ts +9 -0
- package/dist/suggest.js +51 -0
- package/dist/suggest.js.map +1 -0
- package/package.json +9 -6
- package/dist/commands/web.d.ts +0 -4
- package/dist/commands/web.js +0 -205
- package/dist/commands/web.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"skip.js","sourceRoot":"","sources":["../../src/manifest/skip.ts"],"names":[],"mappings":"AAAA,kHAAkH;AAElH,OAAO,EAAE,iBAAiB,EAAgB,WAAW,EAAqB,YAAY,EAAE,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { type CommitSource, type PathKind, type Repository } from "@b3os/deploy";
|
|
2
|
+
export { MAX_SOURCE_BYTES, SourceError, secretLooking, sha256 } from "@b3os/deploy";
|
|
3
|
+
/** The repository a folder is in (its real top-level path), or null outside git. */
|
|
4
|
+
export declare function repoOf(dir: string): string | null;
|
|
5
|
+
/** `path` (absolute) relative to the repository, with `/` separators; `.` for the top level. */
|
|
6
|
+
export declare function inRepo(repo: string, path: string): string;
|
|
7
|
+
/** Join repository-relative parts (`.` is the top level). */
|
|
8
|
+
export declare function join(...parts: string[]): string;
|
|
9
|
+
/**
|
|
10
|
+
* The full commit id of `rev` (HEAD, a 12-hex prefix from a tag), or null when the repository lacks it. git reads a
|
|
11
|
+
* name before a short commit id, so a tag or a local branch named like a commit's first hex resolves to its own
|
|
12
|
+
* commit: when `rev` is hex, only a commit that starts with it is an answer.
|
|
13
|
+
*/
|
|
14
|
+
export declare function resolveCommit(repo: string, rev: string): string | null;
|
|
15
|
+
/** The first line of a commit's message (at most 500 characters), or null. */
|
|
16
|
+
export declare function commitSubject(repo: string, commit: string): string | null;
|
|
17
|
+
/** The branch checked out, or null when HEAD is detached (or outside git). */
|
|
18
|
+
export declare function currentBranch(repo: string): string | null;
|
|
19
|
+
/** Whether the working tree has changes (tracked or untracked, not ignored) under any of `paths`. */
|
|
20
|
+
export declare function dirty(repo: string, paths: string[]): boolean;
|
|
21
|
+
/** Those of `paths` (files) that differ from HEAD in the working tree or the index, or are not in HEAD at all
|
|
22
|
+
* (untracked, or ignored). */
|
|
23
|
+
export declare function uncommitted(repo: string, paths: string[]): string[];
|
|
24
|
+
/** The git object id of a folder or file at a commit: the tree hash that goes into a service's spec digest. */
|
|
25
|
+
export declare function treeHash(repo: string, commit: string, path: string): string;
|
|
26
|
+
/** A file's bytes at a commit. */
|
|
27
|
+
export declare function showFile(repo: string, commit: string, path: string): Buffer;
|
|
28
|
+
/** Whether a file exists at a commit. */
|
|
29
|
+
export declare function fileAt(repo: string, commit: string, path: string): boolean;
|
|
30
|
+
/** The tracked files under `path` at a commit, relative to `path`. */
|
|
31
|
+
export declare function trackedFiles(repo: string, commit: string, path: string): string[];
|
|
32
|
+
/**
|
|
33
|
+
* A gzip tarball of the folder at a commit, its contents at the top level (`git archive <commit>:<path>`): tracked
|
|
34
|
+
* files only, so ignored files such as `.env` or `node_modules` never leave the machine.
|
|
35
|
+
*/
|
|
36
|
+
export declare function sourceTarball(repo: string, commit: string, path: string): Buffer;
|
|
37
|
+
/** What is at `path` in a commit: a folder, a file, or nothing. */
|
|
38
|
+
export declare function kindAt(repo: string, commit: string, path: string): PathKind | null;
|
|
39
|
+
/** The local clone at `root` (its top level), as @b3os/deploy reads a repository. */
|
|
40
|
+
export declare class GitRepository implements Repository {
|
|
41
|
+
private readonly commits;
|
|
42
|
+
readonly root: string;
|
|
43
|
+
constructor(root: string);
|
|
44
|
+
resolve(rev: string): Promise<string | null>;
|
|
45
|
+
at(commit: string): CommitSource;
|
|
46
|
+
/** Files under `path` that differ between the two commits: one `git diff --name-only`. Null when git cannot say. */
|
|
47
|
+
changedFiles(from: string, to: string, path: string): Promise<number | null>;
|
|
48
|
+
}
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
// b3os.yaml v1: what apply deploys comes from a git commit, never from the working tree, so a deploy can be
|
|
2
|
+
// repeated from its `b3os.rev` tag (keepalive recreates a lost harness that way). Everything here runs the local
|
|
3
|
+
// `git` binary; no new dependency. Paths are relative to the repository's top level, with `/` separators.
|
|
4
|
+
// `GitRepository` is the CLI's side of @b3os/deploy's source interface (packages/deploy/src/source.ts); the edge's
|
|
5
|
+
// deployer reads the same things from GitHub instead.
|
|
6
|
+
import { execFileSync } from "node:child_process";
|
|
7
|
+
import { realpathSync } from "node:fs";
|
|
8
|
+
import { relative, sep } from "node:path";
|
|
9
|
+
import { MAX_SOURCE_BYTES, SourceError, tooLargeMessage, } from "@b3os/deploy";
|
|
10
|
+
export { MAX_SOURCE_BYTES, SourceError, secretLooking, sha256 } from "@b3os/deploy";
|
|
11
|
+
/** The most a git command may print here: room for a tarball just over the limit, so its size can be reported. */
|
|
12
|
+
const GIT_MAX_BYTES = MAX_SOURCE_BYTES + 16 * 1024 * 1024;
|
|
13
|
+
function git(repo, args, input) {
|
|
14
|
+
try {
|
|
15
|
+
return execFileSync("git", ["-C", repo, ...args], {
|
|
16
|
+
maxBuffer: GIT_MAX_BYTES,
|
|
17
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
18
|
+
...(input ? { input } : {}),
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
catch (e) {
|
|
22
|
+
const err = e;
|
|
23
|
+
if (err.code === "ENOBUFS")
|
|
24
|
+
throw new SourceError(`git ${args[0]}: over ${GIT_MAX_BYTES} bytes`, "too_large");
|
|
25
|
+
const why = err.stderr?.toString().trim().split("\n")[0] || err.message;
|
|
26
|
+
throw new SourceError(`git ${args[0]}: ${why}`);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
const text = (b) => b.toString("utf8").trim();
|
|
30
|
+
/** The repository a folder is in (its real top-level path), or null outside git. */
|
|
31
|
+
export function repoOf(dir) {
|
|
32
|
+
try {
|
|
33
|
+
return text(execFileSync("git", ["-C", dir, "rev-parse", "--show-toplevel"], { stdio: ["ignore", "pipe", "ignore"] }));
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/** `path` (absolute) relative to the repository, with `/` separators; `.` for the top level. */
|
|
40
|
+
export function inRepo(repo, path) {
|
|
41
|
+
const r = relative(realpathSync(repo), realpathSync(path)).split(sep).join("/");
|
|
42
|
+
return r === "" ? "." : r;
|
|
43
|
+
}
|
|
44
|
+
/** Join repository-relative parts (`.` is the top level). */
|
|
45
|
+
export function join(...parts) {
|
|
46
|
+
const out = parts.filter((p) => p && p !== ".").join("/");
|
|
47
|
+
return out === "" ? "." : out;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* The full commit id of `rev` (HEAD, a 12-hex prefix from a tag), or null when the repository lacks it. git reads a
|
|
51
|
+
* name before a short commit id, so a tag or a local branch named like a commit's first hex resolves to its own
|
|
52
|
+
* commit: when `rev` is hex, only a commit that starts with it is an answer.
|
|
53
|
+
*/
|
|
54
|
+
export function resolveCommit(repo, rev) {
|
|
55
|
+
let sha;
|
|
56
|
+
try {
|
|
57
|
+
sha = text(git(repo, ["rev-parse", "--verify", "--quiet", `${rev}^{commit}`]));
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
return /^[0-9a-f]{7,40}$/.test(rev) && !sha.startsWith(rev) ? null : sha;
|
|
63
|
+
}
|
|
64
|
+
/** The first line of a commit's message (at most 500 characters), or null. */
|
|
65
|
+
export function commitSubject(repo, commit) {
|
|
66
|
+
try {
|
|
67
|
+
const s = text(git(repo, ["log", "-1", "--format=%s", commit]));
|
|
68
|
+
return s ? s.slice(0, 500) : null;
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/** The branch checked out, or null when HEAD is detached (or outside git). */
|
|
75
|
+
export function currentBranch(repo) {
|
|
76
|
+
try {
|
|
77
|
+
const b = text(git(repo, ["symbolic-ref", "--quiet", "--short", "HEAD"]));
|
|
78
|
+
return b || null;
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/** Whether the working tree has changes (tracked or untracked, not ignored) under any of `paths`. */
|
|
85
|
+
export function dirty(repo, paths) {
|
|
86
|
+
const out = text(git(repo, ["status", "--porcelain", "--untracked-files=normal", "--", ...paths]));
|
|
87
|
+
return out.length > 0;
|
|
88
|
+
}
|
|
89
|
+
/** Those of `paths` (files) that differ from HEAD in the working tree or the index, or are not in HEAD at all
|
|
90
|
+
* (untracked, or ignored). */
|
|
91
|
+
export function uncommitted(repo, paths) {
|
|
92
|
+
return paths.filter((p) => dirty(repo, [p]) || !fileAt(repo, "HEAD", p));
|
|
93
|
+
}
|
|
94
|
+
/** The git object id of a folder or file at a commit: the tree hash that goes into a service's spec digest. */
|
|
95
|
+
export function treeHash(repo, commit, path) {
|
|
96
|
+
return text(git(repo, ["rev-parse", path === "." ? `${commit}^{tree}` : `${commit}:${path}`]));
|
|
97
|
+
}
|
|
98
|
+
/** A file's bytes at a commit. */
|
|
99
|
+
export function showFile(repo, commit, path) {
|
|
100
|
+
return git(repo, ["show", `${commit}:${path}`]);
|
|
101
|
+
}
|
|
102
|
+
/** Whether a file exists at a commit. */
|
|
103
|
+
export function fileAt(repo, commit, path) {
|
|
104
|
+
try {
|
|
105
|
+
git(repo, ["cat-file", "-e", `${commit}:${path}`]);
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
108
|
+
catch {
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/** The tracked files under `path` at a commit, relative to `path`. */
|
|
113
|
+
export function trackedFiles(repo, commit, path) {
|
|
114
|
+
const out = text(git(repo, ["ls-tree", "-r", "--name-only", "--full-tree", commit, "--", path === "." ? "." : path]));
|
|
115
|
+
const prefix = path === "." ? "" : `${path}/`;
|
|
116
|
+
return out
|
|
117
|
+
.split("\n")
|
|
118
|
+
.filter(Boolean)
|
|
119
|
+
.map((f) => (prefix && f.startsWith(prefix) ? f.slice(prefix.length) : f));
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* A gzip tarball of the folder at a commit, its contents at the top level (`git archive <commit>:<path>`): tracked
|
|
123
|
+
* files only, so ignored files such as `.env` or `node_modules` never leave the machine.
|
|
124
|
+
*/
|
|
125
|
+
export function sourceTarball(repo, commit, path) {
|
|
126
|
+
const tree = path === "." ? commit : `${commit}:${path}`;
|
|
127
|
+
const over = (size) => new SourceError(tooLargeMessage(path, commit, size), "too_large");
|
|
128
|
+
let out;
|
|
129
|
+
try {
|
|
130
|
+
out = git(repo, ["archive", "--format=tar.gz", tree]);
|
|
131
|
+
}
|
|
132
|
+
catch (e) {
|
|
133
|
+
if (e instanceof SourceError && e.code === "too_large")
|
|
134
|
+
throw over(`more than ${GIT_MAX_BYTES}`);
|
|
135
|
+
throw e;
|
|
136
|
+
}
|
|
137
|
+
if (out.length > MAX_SOURCE_BYTES)
|
|
138
|
+
throw over(String(out.length));
|
|
139
|
+
return out;
|
|
140
|
+
}
|
|
141
|
+
/** What is at `path` in a commit: a folder, a file, or nothing. */
|
|
142
|
+
export function kindAt(repo, commit, path) {
|
|
143
|
+
if (path === ".")
|
|
144
|
+
return "dir";
|
|
145
|
+
try {
|
|
146
|
+
const t = text(git(repo, ["cat-file", "-t", `${commit}:${path}`]));
|
|
147
|
+
return t === "tree" ? "dir" : t === "blob" ? "file" : null;
|
|
148
|
+
}
|
|
149
|
+
catch {
|
|
150
|
+
return null;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
/** One commit of the local clone, read with git. The tarball of a folder is made once and uploaded as made. */
|
|
154
|
+
class GitCommit {
|
|
155
|
+
archives = new Map();
|
|
156
|
+
repo;
|
|
157
|
+
commit;
|
|
158
|
+
constructor(repo, commit) {
|
|
159
|
+
this.repo = repo;
|
|
160
|
+
this.commit = commit;
|
|
161
|
+
}
|
|
162
|
+
async kind(path) {
|
|
163
|
+
return kindAt(this.repo, this.commit, path);
|
|
164
|
+
}
|
|
165
|
+
async read(path, max) {
|
|
166
|
+
if (kindAt(this.repo, this.commit, path) !== "file")
|
|
167
|
+
return null;
|
|
168
|
+
const b = showFile(this.repo, this.commit, path);
|
|
169
|
+
if (b.length > max)
|
|
170
|
+
throw new SourceError(`${path} is ${b.length} bytes, over ${max}`, "too_large");
|
|
171
|
+
return b;
|
|
172
|
+
}
|
|
173
|
+
async objectId(path) {
|
|
174
|
+
return treeHash(this.repo, this.commit, path);
|
|
175
|
+
}
|
|
176
|
+
async files(path) {
|
|
177
|
+
return trackedFiles(this.repo, this.commit, path);
|
|
178
|
+
}
|
|
179
|
+
async archiveSize(path) {
|
|
180
|
+
return this.tarball(path).length;
|
|
181
|
+
}
|
|
182
|
+
async archive(path) {
|
|
183
|
+
return this.tarball(path);
|
|
184
|
+
}
|
|
185
|
+
tarball(path) {
|
|
186
|
+
let t = this.archives.get(path);
|
|
187
|
+
if (!t) {
|
|
188
|
+
t = sourceTarball(this.repo, this.commit, path);
|
|
189
|
+
this.archives.set(path, t);
|
|
190
|
+
}
|
|
191
|
+
return t;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
/** The local clone at `root` (its top level), as @b3os/deploy reads a repository. */
|
|
195
|
+
export class GitRepository {
|
|
196
|
+
commits = new Map();
|
|
197
|
+
root;
|
|
198
|
+
constructor(root) {
|
|
199
|
+
this.root = root;
|
|
200
|
+
}
|
|
201
|
+
async resolve(rev) {
|
|
202
|
+
return resolveCommit(this.root, rev);
|
|
203
|
+
}
|
|
204
|
+
at(commit) {
|
|
205
|
+
let c = this.commits.get(commit);
|
|
206
|
+
if (!c) {
|
|
207
|
+
c = new GitCommit(this.root, commit);
|
|
208
|
+
this.commits.set(commit, c);
|
|
209
|
+
}
|
|
210
|
+
return c;
|
|
211
|
+
}
|
|
212
|
+
/** Files under `path` that differ between the two commits: one `git diff --name-only`. Null when git cannot say. */
|
|
213
|
+
async changedFiles(from, to, path) {
|
|
214
|
+
try {
|
|
215
|
+
const out = text(git(this.root, ["diff", "--name-only", "--no-renames", from, to, "--", path || "."]));
|
|
216
|
+
return out ? out.split("\n").filter(Boolean).length : 0;
|
|
217
|
+
}
|
|
218
|
+
catch {
|
|
219
|
+
return null;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
//# sourceMappingURL=source.js.map
|
|
@@ -0,0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
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Ctx, Options } from "./ctx.ts";
|
|
2
|
+
export interface CliCommand {
|
|
3
|
+
/** What a user types: `b3os <name>`. */
|
|
4
|
+
name: string;
|
|
5
|
+
/** One line for `b3os --help`. */
|
|
6
|
+
summary: string;
|
|
7
|
+
/** Position in `b3os --help`, lowest first (gaps of 10 leave room). */
|
|
8
|
+
order: number;
|
|
9
|
+
run: (ctx: Ctx, argv: string[]) => Promise<number>;
|
|
10
|
+
/** The options the command takes beside the global ones, for the name check (test/names.test.ts). */
|
|
11
|
+
options?: Options;
|
|
12
|
+
/** Subcommands it still takes under an older name, old name to current (`run` for `action call`). */
|
|
13
|
+
oldSubcommands?: Readonly<Record<string, string>>;
|
|
14
|
+
}
|
|
15
|
+
/** The module files of a commands folder, for the extension this build runs from (.ts in src, .js in dist). */
|
|
16
|
+
export declare function commandFiles(dir: URL, ext: ".ts" | ".js"): string[];
|
|
17
|
+
/** Import every command module in `dir` and return their commands in help order. Throws on a module without a
|
|
18
|
+
* valid `commands` export, or on two commands with one name, so a broken module fails every test at once. */
|
|
19
|
+
export declare function loadCommands(dir: URL, ext: ".ts" | ".js"): Promise<CliCommand[]>;
|
package/dist/registry.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// The CLI's command registry (W3-0b-2). Each module in commands/ exports `commands: CliCommand[]`; main.ts finds
|
|
2
|
+
// the modules by listing that folder, so a product adds a command by adding (or editing) its own module, never
|
|
3
|
+
// main.ts. A file whose name starts with `_` is a helper, not a command module. From src/ the modules are .ts
|
|
4
|
+
// files (node --conditions=b3os-source, vitest); from the published package they are dist/commands/*.js, which
|
|
5
|
+
// sit beside dist/main.js the same way, so discovery needs no generated index.
|
|
6
|
+
var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
|
|
7
|
+
if (typeof path === "string" && /^\.\.?\//.test(path)) {
|
|
8
|
+
return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
|
|
9
|
+
return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
return path;
|
|
13
|
+
};
|
|
14
|
+
import { readdirSync } from "node:fs";
|
|
15
|
+
const NAME = /^[a-z][a-z0-9-]{0,31}$/;
|
|
16
|
+
/** Words main.ts answers itself. */
|
|
17
|
+
const RESERVED = new Set(["help", "version"]);
|
|
18
|
+
/** The module files of a commands folder, for the extension this build runs from (.ts in src, .js in dist). */
|
|
19
|
+
export function commandFiles(dir, ext) {
|
|
20
|
+
return readdirSync(dir)
|
|
21
|
+
.filter((f) => f.endsWith(ext) && !f.endsWith(".d.ts") && !f.startsWith("_") && !f.startsWith("."))
|
|
22
|
+
.sort();
|
|
23
|
+
}
|
|
24
|
+
/** Import every command module in `dir` and return their commands in help order. Throws on a module without a
|
|
25
|
+
* valid `commands` export, or on two commands with one name, so a broken module fails every test at once. */
|
|
26
|
+
export async function loadCommands(dir, ext) {
|
|
27
|
+
const out = [];
|
|
28
|
+
const from = new Map();
|
|
29
|
+
for (const file of commandFiles(dir, ext)) {
|
|
30
|
+
const mod = await import(__rewriteRelativeImportExtension(new URL(file, dir).href));
|
|
31
|
+
if (!Array.isArray(mod.commands))
|
|
32
|
+
throw new Error(`commands/${file} exports no commands array`);
|
|
33
|
+
for (const c of mod.commands) {
|
|
34
|
+
const where = `commands/${file}`;
|
|
35
|
+
if (typeof c?.name !== "string" || !NAME.test(c.name) || RESERVED.has(c.name))
|
|
36
|
+
throw new Error(`${where}: bad command name ${JSON.stringify(c?.name)}`);
|
|
37
|
+
if (typeof c.summary !== "string" || c.summary.length === 0 || c.summary.length > 100)
|
|
38
|
+
throw new Error(`${where}: ${c.name} needs a one-line summary (at most 100 characters)`);
|
|
39
|
+
if (typeof c.order !== "number" || !Number.isFinite(c.order))
|
|
40
|
+
throw new Error(`${where}: ${c.name} needs a numeric order`);
|
|
41
|
+
if (typeof c.run !== "function")
|
|
42
|
+
throw new Error(`${where}: ${c.name} has no run function`);
|
|
43
|
+
const prev = from.get(c.name);
|
|
44
|
+
if (prev)
|
|
45
|
+
throw new Error(`${where}: ${c.name} is also defined in ${prev}`);
|
|
46
|
+
from.set(c.name, where);
|
|
47
|
+
out.push(c);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return out.sort((a, b) => a.order - b.order || a.name.localeCompare(b.name));
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAAA,iHAAiH;AACjH,+GAA+G;AAC/G,8GAA8G;AAC9G,+GAA+G;AAC/G,+EAA+E;;;;;;;;;AAE/E,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAiBtC,MAAM,IAAI,GAAG,wBAAwB,CAAC;AACtC,oCAAoC;AACpC,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC;AAE9C,+GAA+G;AAC/G,MAAM,UAAU,YAAY,CAAC,GAAQ,EAAE,GAAkB;IACvD,OAAO,WAAW,CAAC,GAAG,CAAC;SACpB,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;SAClG,IAAI,EAAE,CAAC;AACZ,CAAC;AAED;6GAC6G;AAC7G,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,GAAQ,EAAE,GAAkB;IAC7D,MAAM,GAAG,G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OAAO,CAAC,CAAC,GAAG,KAAK,UAAU;gBAAE,MAAM,IAAI,KAAK,CAAC,GAAG,KAAK,KAAK,CAAC,CAAC,IAAI,sBAAsB,CAAC,CAAC;YAC5F,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;YAC9B,IAAI,IAAI;gBAAE,MAAM,IAAI,KAAK,CAAC,GAAG,KAAK,KAAK,CAAC,CAAC,IAAI,uBAAuB,IAAI,EAAE,CAAC,CAAC;YAC5E,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;YACxB,GAAG,CAAC,IAAI,CAAC,CAAe,CAAC,CAAC;QAC5B,CAAC;IACH,CAAC;IACD,OAAO,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;AAC/E,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** Edits between two words: insertions, deletions, substitutions and swaps of two neighbours (`sandbxo`). */
|
|
2
|
+
export declare function distance(a: string, b: string): number;
|
|
3
|
+
/**
|
|
4
|
+
* Up to three of `known` that `word` is probably a typo of, closest first: one edit away for a word of up to four
|
|
5
|
+
* letters, two up to eight, three beyond; or a word that starts with what was typed (three letters or more).
|
|
6
|
+
*/
|
|
7
|
+
export declare function suggest(word: string, known: Iterable<string>): string[];
|
|
8
|
+
/** `"sandbox"`, `"sandbox or session"`, `"a, b or c"`: a short list for a sentence. */
|
|
9
|
+
export declare function orList(words: readonly string[]): string;
|
package/dist/suggest.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// "Did you mean": the known words closest to one the user typed (commands, subcommands, flags).
|
|
2
|
+
/** Edits between two words: insertions, deletions, substitutions and swaps of two neighbours (`sandbxo`). */
|
|
3
|
+
export function distance(a, b) {
|
|
4
|
+
const d = Array.from({ length: a.length + 1 }, (_, i) => [i, ...Array(b.length).fill(0)]);
|
|
5
|
+
for (let j = 1; j <= b.length; j++)
|
|
6
|
+
d[0][j] = j;
|
|
7
|
+
for (let i = 1; i <= a.length; i++) {
|
|
8
|
+
const row = d[i];
|
|
9
|
+
const prev = d[i - 1];
|
|
10
|
+
for (let j = 1; j <= b.length; j++) {
|
|
11
|
+
const cost = a[i - 1] === b[j - 1] ? 0 : 1;
|
|
12
|
+
let v = Math.min(prev[j] + 1, row[j - 1] + 1, prev[j - 1] + cost);
|
|
13
|
+
if (i > 1 && j > 1 && a[i - 1] === b[j - 2] && a[i - 2] === b[j - 1])
|
|
14
|
+
v = Math.min(v, d[i - 2][j - 2] + 1);
|
|
15
|
+
row[j] = v;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return d[a.length][b.length];
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Up to three of `known` that `word` is probably a typo of, closest first: one edit away for a word of up to four
|
|
22
|
+
* letters, two up to eight, three beyond; or a word that starts with what was typed (three letters or more).
|
|
23
|
+
*/
|
|
24
|
+
export function suggest(word, known) {
|
|
25
|
+
const w = word.toLowerCase();
|
|
26
|
+
if (!w)
|
|
27
|
+
return [];
|
|
28
|
+
const max = w.length <= 4 ? 1 : w.length <= 8 ? 2 : 3;
|
|
29
|
+
const hits = [];
|
|
30
|
+
for (const name of new Set(known)) {
|
|
31
|
+
if (name === word)
|
|
32
|
+
continue;
|
|
33
|
+
const n = name.toLowerCase();
|
|
34
|
+
const d = distance(w, n);
|
|
35
|
+
if (d <= max)
|
|
36
|
+
hits.push({ name, d });
|
|
37
|
+
else if (w.length >= 3 && n.startsWith(w))
|
|
38
|
+
hits.push({ name, d: max + 1 });
|
|
39
|
+
}
|
|
40
|
+
return hits
|
|
41
|
+
.sort((x, y) => x.d - y.d)
|
|
42
|
+
.slice(0, 3)
|
|
43
|
+
.map((h) => h.name);
|
|
44
|
+
}
|
|
45
|
+
/** `"sandbox"`, `"sandbox or session"`, `"a, b or c"`: a short list for a sentence. */
|
|
46
|
+
export function orList(words) {
|
|
47
|
+
if (words.length <= 1)
|
|
48
|
+
return words[0] ?? "";
|
|
49
|
+
return `${words.slice(0, -1).join(", ")} or ${words.at(-1)}`;
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=suggest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"suggest.js","sourceRoot":"","sources":["../src/suggest.ts"],"names":[],"mappings":"AAAA,gGAAgG;AAEhG,6GAA6G;AAC7G,MAAM,UAAU,QAAQ,CAAC,CAAS,EAAE,CAAS;IAC3C,MAAM,CAAC,GAAe,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,GAAG,KAAK,CAAS,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC9G,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE;QAAG,CAAC,CAAC,CAAC,CAAc,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;IAC9D,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACnC,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC,CAAa,CAAC;QAC7B,MAAM,IAAI,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAa,CAAC;QAClC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YACnC,MAAM,IAAI,GAAG,CAAC,CAAC,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|
|
4
|
-
"description": "The B3OS command line:
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "The B3OS command line: vision, render, infer, sandboxes, routines, actions and vault, plus keys and MCP setup.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"engines": {
|
|
8
|
-
"node": ">=
|
|
8
|
+
"node": ">=22.3"
|
|
9
9
|
},
|
|
10
10
|
"bin": {
|
|
11
11
|
"b3os": "./bin/b3os.js"
|
|
@@ -30,11 +30,14 @@
|
|
|
30
30
|
"dev": "node --conditions=b3os-source src/main.ts"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@b3os/
|
|
34
|
-
"@b3os/mcp": "0.
|
|
33
|
+
"@b3os/deploy": "0.2.0",
|
|
34
|
+
"@b3os/mcp": "0.2.0",
|
|
35
|
+
"@b3os/sdk": "0.2.0",
|
|
36
|
+
"yaml": "2.9.1"
|
|
35
37
|
},
|
|
36
38
|
"devDependencies": {
|
|
37
|
-
"@types/node": "24.19.2"
|
|
39
|
+
"@types/node": "24.19.2",
|
|
40
|
+
"ajv": "8.20.0"
|
|
38
41
|
},
|
|
39
42
|
"homepage": "https://beta.b3os.org",
|
|
40
43
|
"repository": {
|
package/dist/commands/web.d.ts
DELETED