@melra/cli 0.3.0-alpha.11 → 0.3.0-alpha.12
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 +11 -6
- package/dist/activity.d.ts +26 -0
- package/dist/activity.d.ts.map +1 -0
- package/dist/activity.js +401 -0
- package/dist/activity.js.map +1 -0
- package/dist/client-status.d.ts +24 -0
- package/dist/client-status.d.ts.map +1 -0
- package/dist/client-status.js +273 -0
- package/dist/client-status.js.map +1 -0
- package/dist/clients.d.ts +32 -0
- package/dist/clients.d.ts.map +1 -0
- package/dist/clients.js +584 -0
- package/dist/clients.js.map +1 -0
- package/dist/conformance.d.ts.map +1 -1
- package/dist/conformance.js +4 -2
- package/dist/conformance.js.map +1 -1
- package/dist/demo-workflow.d.ts +46 -0
- package/dist/demo-workflow.d.ts.map +1 -0
- package/dist/demo-workflow.js +58 -0
- package/dist/demo-workflow.js.map +1 -0
- package/dist/environment.d.ts +3 -1
- package/dist/environment.d.ts.map +1 -1
- package/dist/environment.js +13 -1
- package/dist/environment.js.map +1 -1
- package/dist/human.d.ts +67 -0
- package/dist/human.d.ts.map +1 -0
- package/dist/human.js +257 -0
- package/dist/human.js.map +1 -0
- package/dist/index.js +236 -49
- package/dist/index.js.map +1 -1
- package/dist/isolation.d.ts +35 -0
- package/dist/isolation.d.ts.map +1 -0
- package/dist/isolation.js +66 -0
- package/dist/isolation.js.map +1 -0
- package/dist/jsonc.d.ts +24 -0
- package/dist/jsonc.d.ts.map +1 -0
- package/dist/jsonc.js +238 -0
- package/dist/jsonc.js.map +1 -0
- package/dist/output.d.ts +28 -0
- package/dist/output.d.ts.map +1 -0
- package/dist/output.js +77 -0
- package/dist/output.js.map +1 -0
- package/package.json +10 -10
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// Copyright 2026 XAGI Labs Private Limited
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import { existsSync } from "node:fs";
|
|
4
|
+
import { readFile } from "node:fs/promises";
|
|
5
|
+
/**
|
|
6
|
+
* Read the restrictions out of `/proc/self/status` and `/proc/self/mountinfo`.
|
|
7
|
+
* Pure, so the parsing is testable without a container.
|
|
8
|
+
*/
|
|
9
|
+
export function parseIsolation(status, mountinfo, container) {
|
|
10
|
+
const field = (name) => new RegExp(`^${name}:\\s*(\\S+)`, "m").exec(status)?.[1];
|
|
11
|
+
const capabilities = field("CapEff");
|
|
12
|
+
// mountinfo: id parent major:minor root mount-point options ...
|
|
13
|
+
const root = mountinfo
|
|
14
|
+
.split("\n")
|
|
15
|
+
.map((line) => line.split(" "))
|
|
16
|
+
.filter((parts) => parts[4] === "/")
|
|
17
|
+
.at(-1); // the last mount over / is the one in effect
|
|
18
|
+
return {
|
|
19
|
+
noCapabilities: capabilities !== undefined && /^0+$/.test(capabilities),
|
|
20
|
+
noNewPrivileges: field("NoNewPrivs") === "1",
|
|
21
|
+
seccomp: field("Seccomp") === "2",
|
|
22
|
+
readOnlyRoot: root?.[5]?.split(",").includes("ro") ?? false,
|
|
23
|
+
container,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
export async function detectIsolation() {
|
|
27
|
+
if (process.platform !== "linux")
|
|
28
|
+
return undefined;
|
|
29
|
+
try {
|
|
30
|
+
const [status, mountinfo] = await Promise.all([
|
|
31
|
+
readFile("/proc/self/status", "utf8"),
|
|
32
|
+
readFile("/proc/self/mountinfo", "utf8"),
|
|
33
|
+
]);
|
|
34
|
+
return parseIsolation(status, mountinfo, existsSync("/.dockerenv") || existsSync("/run/.containerenv"));
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* The doctor line. Never a `fail`: isolation is the operator's to arrange, and
|
|
42
|
+
* a laptop in developer mode needs none. Enforced mode with nothing in effect
|
|
43
|
+
* is a `warn`, because that is the case the operator should know about.
|
|
44
|
+
*/
|
|
45
|
+
export function isolationCheck(isolation, mode) {
|
|
46
|
+
const name = "isolation";
|
|
47
|
+
const unbacked = mode === "enforced" ? "warn" : "pass";
|
|
48
|
+
if (isolation === undefined) {
|
|
49
|
+
return {
|
|
50
|
+
name,
|
|
51
|
+
status: unbacked,
|
|
52
|
+
detail: `not visible on ${process.platform}; a macOS sandbox profile or a Windows Job Object cannot be read from inside`,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
const active = [
|
|
56
|
+
isolation.container && "container",
|
|
57
|
+
isolation.noCapabilities && "no capabilities",
|
|
58
|
+
isolation.noNewPrivileges && "no_new_privs",
|
|
59
|
+
isolation.seccomp && "seccomp filter",
|
|
60
|
+
isolation.readOnlyRoot && "read-only root",
|
|
61
|
+
].filter((item) => item !== false);
|
|
62
|
+
return active.length === 0
|
|
63
|
+
? { name, status: unbacked, detail: "none in effect: full capabilities, no seccomp filter, writable root" }
|
|
64
|
+
: { name, status: "pass", detail: active.join(", ") };
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=isolation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isolation.js","sourceRoot":"","sources":["../src/isolation.ts"],"names":[],"mappings":"AAAA,2CAA2C;AAC3C,sCAAsC;AAEtC,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAqB5C;;;GAGG;AACH,MAAM,UAAU,cAAc,CAAC,MAAc,EAAE,SAAiB,EAAE,SAAkB;IAClF,MAAM,KAAK,GAAG,CAAC,IAAY,EAAE,EAAE,CAAC,IAAI,MAAM,CAAC,IAAI,IAAI,aAAa,EAAE,GAAG,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IACzF,MAAM,YAAY,GAAG,KAAK,CAAC,QAAQ,CAAC,CAAC;IACrC,gEAAgE;IAChE,MAAM,IAAI,GAAG,SAAS;SACnB,KAAK,CAA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,IAAI,KAAK,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC;IACvD,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;QAC5B,OAAO;YACL,IAAI;YACJ,MAAM,EAAE,QAAQ;YAChB,MAAM,EAAE,kBAAkB,OAAO,CAAC,QAAQ,8EAA8E;SACzH,CAAC;IACJ,CAAC;IACD,MAAM,MAAM,GAAG;QACb,SAAS,CAAC,SAAS,IAAI,WAAW;QAClC,SAAS,CAAC,cAAc,IAAI,iBAAiB;QAC7C,SAAS,CAAC,eAAe,IAAI,cAAc;QAC3C,SAAS,CAAC,OAAO,IAAI,gBAAgB;QACrC,SAAS,CAAC,YAAY,IAAI,gBAAgB;KAC3C,CAAC,MAAM,CAAC,CAAC,IAAI,EAAkB,EAAE,CAAC,IAAI,KAAK,KAAK,CAAC,CAAC;IACnD,OAAO,MAAM,CAAC,MAAM,KAAK,CAAC;QACxB,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,qEAAqE,EAAE;QAC3G,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;AAC1D,CAAC"}
|
package/dist/jsonc.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export interface JsoncMember {
|
|
2
|
+
key: string;
|
|
3
|
+
keyStart: number;
|
|
4
|
+
value: JsoncNode;
|
|
5
|
+
}
|
|
6
|
+
export interface JsoncNode {
|
|
7
|
+
start: number;
|
|
8
|
+
end: number;
|
|
9
|
+
value: unknown;
|
|
10
|
+
members?: JsoncMember[];
|
|
11
|
+
trailingComma?: number;
|
|
12
|
+
}
|
|
13
|
+
export declare function parseJsonc(text: string): JsoncNode;
|
|
14
|
+
/**
|
|
15
|
+
* Set `path` to `value` in JSONC `text`, rewriting only that member and
|
|
16
|
+
* leaving every other byte (comments, trailing commas, formatting, key order,
|
|
17
|
+
* line endings) as it was. A missing member is inserted into the deepest
|
|
18
|
+
* object that exists, indented to match its siblings. With `keepExisting`, a
|
|
19
|
+
* member that is already there is left alone. Throws when the root or a step
|
|
20
|
+
* of the path is not an object, or a step appears twice in one object, since
|
|
21
|
+
* which duplicate a client honours is not knowable from here.
|
|
22
|
+
*/
|
|
23
|
+
export declare function upsertJsonc(text: string, path: string[], value: unknown, keepExisting?: boolean): string;
|
|
24
|
+
//# sourceMappingURL=jsonc.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jsonc.d.ts","sourceRoot":"","sources":["../src/jsonc.ts"],"names":[],"mappings":"AAUA,MAAM,WAAW,WAAW;IAC1B,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,SAAS,CAAC;CAClB;AAED,MAAM,WAAW,SAAS;IAExB,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,OAAO,CAAC;IAGf,OAAO,CAAC,EAAE,WAAW,EAAE,CAAC;IAExB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAMD,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,CAoHlD;AAqCD;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CACzB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EAAE,EACd,KAAK,EAAE,OAAO,EACd,YAAY,UAAQ,GACnB,MAAM,CA0ER"}
|
package/dist/jsonc.js
ADDED
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
// Copyright 2026 XAGI Labs Private Limited
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
const NUMBER_OR_LITERAL = /-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?|true|false|null/y;
|
|
4
|
+
export function parseJsonc(text) {
|
|
5
|
+
let at = 0;
|
|
6
|
+
const error = (what) => new Error(`${what} at line ${text.slice(0, at).split("\n").length}`);
|
|
7
|
+
const skip = () => {
|
|
8
|
+
for (;;) {
|
|
9
|
+
const c = text[at];
|
|
10
|
+
if (c === " " || c === "\t" || c === "\n" || c === "\r" || (c === "" && at === 0)) {
|
|
11
|
+
at++;
|
|
12
|
+
}
|
|
13
|
+
else if (text.startsWith("//", at)) {
|
|
14
|
+
const newline = text.indexOf("\n", at);
|
|
15
|
+
at = newline === -1 ? text.length : newline;
|
|
16
|
+
}
|
|
17
|
+
else if (text.startsWith("/*", at)) {
|
|
18
|
+
const close = text.indexOf("*/", at + 2);
|
|
19
|
+
if (close === -1)
|
|
20
|
+
throw error("unterminated comment");
|
|
21
|
+
at = close + 2;
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
// Find the closing quote by hand so `//` or `/*` inside a string is never
|
|
29
|
+
// taken for a comment, then let JSON.parse decode and validate the escapes.
|
|
30
|
+
const string = () => {
|
|
31
|
+
const start = at++;
|
|
32
|
+
for (;;) {
|
|
33
|
+
const c = text[at];
|
|
34
|
+
if (c === undefined)
|
|
35
|
+
throw error("unterminated string");
|
|
36
|
+
at += c === "\\" ? 2 : 1;
|
|
37
|
+
if (c === '"')
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
try {
|
|
41
|
+
return JSON.parse(text.slice(start, at));
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
throw error("invalid string");
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
const object = () => {
|
|
48
|
+
const start = at++;
|
|
49
|
+
const members = [];
|
|
50
|
+
const value = {};
|
|
51
|
+
let trailingComma;
|
|
52
|
+
skip();
|
|
53
|
+
while (text[at] !== "}") {
|
|
54
|
+
if (text[at] !== '"')
|
|
55
|
+
throw error("expected a quoted key or '}'");
|
|
56
|
+
const keyStart = at;
|
|
57
|
+
const key = string();
|
|
58
|
+
skip();
|
|
59
|
+
if (text[at] !== ":")
|
|
60
|
+
throw error("expected ':'");
|
|
61
|
+
at++;
|
|
62
|
+
const node = parse();
|
|
63
|
+
members.push({ key, keyStart, value: node });
|
|
64
|
+
// defineProperty, not assignment, so a `__proto__` key stays plain data.
|
|
65
|
+
Object.defineProperty(value, key, {
|
|
66
|
+
value: node.value,
|
|
67
|
+
enumerable: true,
|
|
68
|
+
writable: true,
|
|
69
|
+
configurable: true,
|
|
70
|
+
});
|
|
71
|
+
skip();
|
|
72
|
+
trailingComma = undefined;
|
|
73
|
+
if (text[at] === ",") {
|
|
74
|
+
trailingComma = at++;
|
|
75
|
+
skip();
|
|
76
|
+
}
|
|
77
|
+
else if (text[at] !== "}") {
|
|
78
|
+
throw error("expected ',' or '}'");
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
at++;
|
|
82
|
+
return { start, end: at, value, members, ...(trailingComma === undefined ? {} : { trailingComma }) };
|
|
83
|
+
};
|
|
84
|
+
const array = () => {
|
|
85
|
+
const start = at++;
|
|
86
|
+
const items = [];
|
|
87
|
+
skip();
|
|
88
|
+
while (text[at] !== "]") {
|
|
89
|
+
items.push(parse().value);
|
|
90
|
+
skip();
|
|
91
|
+
if (text[at] === ",") {
|
|
92
|
+
at++;
|
|
93
|
+
skip();
|
|
94
|
+
}
|
|
95
|
+
else if (text[at] !== "]") {
|
|
96
|
+
throw error("expected ',' or ']'");
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
at++;
|
|
100
|
+
return { start, end: at, value: items };
|
|
101
|
+
};
|
|
102
|
+
const parse = () => {
|
|
103
|
+
skip();
|
|
104
|
+
const start = at;
|
|
105
|
+
const c = text[at];
|
|
106
|
+
if (c === "{")
|
|
107
|
+
return object();
|
|
108
|
+
if (c === "[")
|
|
109
|
+
return array();
|
|
110
|
+
if (c === '"') {
|
|
111
|
+
const value = string();
|
|
112
|
+
return { start, end: at, value };
|
|
113
|
+
}
|
|
114
|
+
NUMBER_OR_LITERAL.lastIndex = at;
|
|
115
|
+
const match = NUMBER_OR_LITERAL.exec(text);
|
|
116
|
+
if (match === null) {
|
|
117
|
+
throw error(c === undefined ? "unexpected end of file" : `unexpected ${JSON.stringify(c)}`);
|
|
118
|
+
}
|
|
119
|
+
at = NUMBER_OR_LITERAL.lastIndex;
|
|
120
|
+
return { start, end: at, value: JSON.parse(match[0]) };
|
|
121
|
+
};
|
|
122
|
+
const root = parse();
|
|
123
|
+
skip();
|
|
124
|
+
if (at < text.length)
|
|
125
|
+
throw error("unexpected content after the value");
|
|
126
|
+
return root;
|
|
127
|
+
}
|
|
128
|
+
const splice = (text, from, to, insert) => `${text.slice(0, from)}${insert}${text.slice(to)}`;
|
|
129
|
+
const lineStart = (text, offset) => text.lastIndexOf("\n", offset - 1) + 1;
|
|
130
|
+
// The run of spaces and tabs that starts the line holding `offset`.
|
|
131
|
+
const lineIndent = (text, offset) => /^[ \t]*/.exec(text.slice(lineStart(text, offset), offset))?.[0] ?? "";
|
|
132
|
+
const startsLine = (text, offset) => text.slice(lineStart(text, offset), offset).trim() === "";
|
|
133
|
+
// The end of the line after `from` when only blanks and comments follow it
|
|
134
|
+
// there, so a member inserted after `"a": 1, // why` lands below the comment
|
|
135
|
+
// instead of stealing it; otherwise `from` itself.
|
|
136
|
+
function endOfTriviaLine(text, from) {
|
|
137
|
+
let at = from;
|
|
138
|
+
for (;;) {
|
|
139
|
+
while (text[at] === " " || text[at] === "\t")
|
|
140
|
+
at++;
|
|
141
|
+
if (text.startsWith("//", at)) {
|
|
142
|
+
const newline = text.indexOf("\n", at);
|
|
143
|
+
if (newline === -1)
|
|
144
|
+
return from;
|
|
145
|
+
at = newline;
|
|
146
|
+
}
|
|
147
|
+
else if (text.startsWith("/*", at)) {
|
|
148
|
+
const close = text.indexOf("*/", at);
|
|
149
|
+
if (close === -1 || text.slice(at, close).includes("\n"))
|
|
150
|
+
return from;
|
|
151
|
+
at = close + 2;
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
if (text[at] === "\r" && text[at + 1] === "\n")
|
|
155
|
+
return at;
|
|
156
|
+
if (text[at] === "\n")
|
|
157
|
+
return text[at - 1] === "\r" ? at - 1 : at;
|
|
158
|
+
return from;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Set `path` to `value` in JSONC `text`, rewriting only that member and
|
|
163
|
+
* leaving every other byte (comments, trailing commas, formatting, key order,
|
|
164
|
+
* line endings) as it was. A missing member is inserted into the deepest
|
|
165
|
+
* object that exists, indented to match its siblings. With `keepExisting`, a
|
|
166
|
+
* member that is already there is left alone. Throws when the root or a step
|
|
167
|
+
* of the path is not an object, or a step appears twice in one object, since
|
|
168
|
+
* which duplicate a client honours is not knowable from here.
|
|
169
|
+
*/
|
|
170
|
+
export function upsertJsonc(text, path, value, keepExisting = false) {
|
|
171
|
+
const root = parseJsonc(text);
|
|
172
|
+
if (root.members === undefined)
|
|
173
|
+
throw new Error("it does not hold a JSON object");
|
|
174
|
+
const eol = text.includes("\r\n") ? "\r\n" : "\n";
|
|
175
|
+
const rootIndent = lineIndent(text, root.start);
|
|
176
|
+
const nested = root.members.find((member) => startsLine(text, member.keyStart));
|
|
177
|
+
const unit = (nested === undefined ? "" : lineIndent(text, nested.keyStart).slice(rootIndent.length)) ||
|
|
178
|
+
" ";
|
|
179
|
+
// An object written on one line gets its new member on that line too.
|
|
180
|
+
const render = (data, indent, inline) => inline
|
|
181
|
+
? JSON.stringify(data)
|
|
182
|
+
: JSON.stringify(data, null, unit).replaceAll("\n", `${eol}${indent}`);
|
|
183
|
+
let object = root;
|
|
184
|
+
for (const [depth, key] of path.entries()) {
|
|
185
|
+
const name = JSON.stringify(path.slice(0, depth + 1).join("."));
|
|
186
|
+
const matches = object.members.filter((member) => member.key === key);
|
|
187
|
+
if (matches.length > 1) {
|
|
188
|
+
throw new Error(`${name} appears more than once, so which one is read is ambiguous`);
|
|
189
|
+
}
|
|
190
|
+
const inline = !text.slice(object.start, object.end).includes("\n");
|
|
191
|
+
const found = matches[0];
|
|
192
|
+
if (found !== undefined && depth === path.length - 1) {
|
|
193
|
+
if (keepExisting)
|
|
194
|
+
return text;
|
|
195
|
+
const indent = lineIndent(text, found.keyStart);
|
|
196
|
+
return splice(text, found.value.start, found.value.end, render(value, indent, inline));
|
|
197
|
+
}
|
|
198
|
+
if (found !== undefined) {
|
|
199
|
+
if (found.value.members === undefined)
|
|
200
|
+
throw new Error(`${name} is not an object`);
|
|
201
|
+
object = found.value;
|
|
202
|
+
continue;
|
|
203
|
+
}
|
|
204
|
+
// Insert `"key": value`, wrapping it in whatever of the path is missing.
|
|
205
|
+
const data = path
|
|
206
|
+
.slice(depth + 1)
|
|
207
|
+
.reduceRight((inner, step) => ({ [step]: inner }), value);
|
|
208
|
+
const last = object.members.at(-1);
|
|
209
|
+
const objectIndent = lineIndent(text, object.start);
|
|
210
|
+
const indent = last !== undefined && startsLine(text, last.keyStart)
|
|
211
|
+
? lineIndent(text, last.keyStart)
|
|
212
|
+
: `${objectIndent}${unit}`;
|
|
213
|
+
const member = `${JSON.stringify(key)}: ${render(data, indent, inline && last !== undefined)}`;
|
|
214
|
+
if (last === undefined) {
|
|
215
|
+
const close = object.end - 1;
|
|
216
|
+
if (text.slice(object.start + 1, close).trim() === "") {
|
|
217
|
+
return splice(text, object.start + 1, close, `${eol}${indent}${member}${eol}${objectIndent}`);
|
|
218
|
+
}
|
|
219
|
+
// Only comments inside: keep them, and put the member just above `}`.
|
|
220
|
+
if (startsLine(text, close)) {
|
|
221
|
+
const at = lineStart(text, close);
|
|
222
|
+
return splice(text, at, at, `${indent}${member}${eol}`);
|
|
223
|
+
}
|
|
224
|
+
return splice(text, close, close, `${eol}${indent}${member}${eol}${objectIndent}`);
|
|
225
|
+
}
|
|
226
|
+
// Append after the last member, keeping the object's trailing-comma style:
|
|
227
|
+
// with one, the new last member gets one too; without, the old last
|
|
228
|
+
// member gains the separating comma.
|
|
229
|
+
const comma = object.trailingComma;
|
|
230
|
+
const anchor = comma === undefined ? last.value.end : comma + 1;
|
|
231
|
+
const at = inline ? anchor : endOfTriviaLine(text, anchor);
|
|
232
|
+
const added = splice(text, at, at, `${inline ? " " : `${eol}${indent}`}${member}${comma === undefined ? "" : ","}`);
|
|
233
|
+
return comma === undefined ? splice(added, anchor, anchor, ",") : added;
|
|
234
|
+
}
|
|
235
|
+
// Only reachable with an empty path, which no caller passes.
|
|
236
|
+
throw new Error("nothing to set");
|
|
237
|
+
}
|
|
238
|
+
//# sourceMappingURL=jsonc.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jsonc.js","sourceRoot":"","sources":["../src/jsonc.ts"],"names":[],"mappings":"AAAA,2CAA2C;AAC3C,sCAAsC;AA6BtC,MAAM,iBAAiB,GAAG,8DAA8D,CAAC;AAEzF,MAAM,UAAU,UAAU,CAAC,IAAY;IACrC,IAAI,EAAE,GAAG,CAAC,CAAC;IACX,MAAM,KAAK,GAAG,CAAC,IAAY,EAAE,EAAE,CAC7B,IAAI,KAAK,CAAC,GAAG,IAAI,YAAY,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC;IAEvE,MAAM,IAAI,GAAG,GAAG,EAAE;QAChB,SAAS,CAAC;YACR,MAAM,CAAC,GAAG,IAAI,CAAC,EAAE,CAAC,CAAC;YACnB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,CAAC,KAAK,GAAG,IAAI,EAAE,KAAK,CAAC,CAAC,EAAE,CAAC;gBACnF,EAAE,EAAE,CAAC;YACP,CAAC;iBAAM,IAAI,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,EAAE,CAAC,EAAE,CAAC;gBACrC,MAAM,OAAO,GAAG,IAAI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M,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IAC1E,CAAC;IACD,6DAA6D;IAC7D,MAAM,IAAI,KAAK,CAAC,gBAAgB,CAAC,CAAC;AACpC,CAAC"}
|
package/dist/output.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export type Status = "pass" | "warn" | "fail";
|
|
2
|
+
/** A readable report for this invocation, rather than JSON. */
|
|
3
|
+
export declare function isHuman(args: readonly string[], stream?: {
|
|
4
|
+
isTTY?: boolean;
|
|
5
|
+
}): boolean;
|
|
6
|
+
export declare const paint: {
|
|
7
|
+
ok: (text: string) => string;
|
|
8
|
+
warn: (text: string) => string;
|
|
9
|
+
fail: (text: string) => string;
|
|
10
|
+
dim: (text: string) => string;
|
|
11
|
+
bold: (text: string) => string;
|
|
12
|
+
};
|
|
13
|
+
/** The coloured status symbol: ✓ ⚠ ✗, or [ok] [warn] [fail] where those would not render. */
|
|
14
|
+
export declare function mark(status: Status): string;
|
|
15
|
+
/**
|
|
16
|
+
* Rows as aligned columns, one line per row. Every column but the last is
|
|
17
|
+
* padded to its widest cell, so a two-column table is a key/value list.
|
|
18
|
+
*/
|
|
19
|
+
export declare function table(rows: readonly (readonly string[])[], options?: {
|
|
20
|
+
indent?: number;
|
|
21
|
+
}): string;
|
|
22
|
+
/**
|
|
23
|
+
* The one place a command decides between its JSON and its human report. The
|
|
24
|
+
* JSON branch is exactly what the CLI has always written, so a script cannot
|
|
25
|
+
* tell this function exists.
|
|
26
|
+
*/
|
|
27
|
+
export declare function printJsonOrHuman<T>(value: T, renderHuman: (value: T) => string, args: readonly string[]): void;
|
|
28
|
+
//# sourceMappingURL=output.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"output.d.ts","sourceRoot":"","sources":["../src/output.ts"],"names":[],"mappings":"AAUA,MAAM,MAAM,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;AAE9C,+DAA+D;AAC/D,wBAAgB,OAAO,CACrB,IAAI,EAAE,SAAS,MAAM,EAAE,EACvB,MAAM,GAAE;IAAE,KAAK,CAAC,EAAE,OAAO,CAAA;CAAmB,GAC3C,OAAO,CAET;AAkBD,eAAO,MAAM,KAAK;eAHkC,MAAM;iBAAN,MAAM;iBAAN,MAAM;gBAAN,MAAM;iBAAN,MAAM;CASzD,CAAC;AAYF,6FAA6F;AAC7F,wBAAgB,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAQ3C;AAKD;;;GAGG;AACH,wBAAgB,KAAK,CACnB,IAAI,EAAE,SAAS,CAAC,SAAS,MAAM,EAAE,CAAC,EAAE,EACpC,OAAO,GAAE;IAAE,MAAM,CAAC,EAAE,MAAM,CAAA;CAAO,GAChC,MAAM,CAqBR;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAChC,KAAK,EAAE,CAAC,EACR,WAAW,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,MAAM,EACjC,IAAI,EAAE,SAAS,MAAM,EAAE,GACtB,IAAI,CAIN"}
|
package/dist/output.js
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
// Copyright 2026 XAGI Labs Private Limited
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
/** A readable report for this invocation, rather than JSON. */
|
|
4
|
+
export function isHuman(args, stream = process.stdout) {
|
|
5
|
+
return !args.includes("--json") && stream.isTTY === true;
|
|
6
|
+
}
|
|
7
|
+
// https://no-color.org: a non-empty NO_COLOR turns colour off whatever else is
|
|
8
|
+
// set. FORCE_COLOR follows Node's own reading ("0"/"false" off, anything else
|
|
9
|
+
// on). Checked here rather than through `tty.WriteStream.hasColors()`, which
|
|
10
|
+
// answers the same but prints a process warning when both are set.
|
|
11
|
+
function colorEnabled() {
|
|
12
|
+
const { NO_COLOR, FORCE_COLOR, TERM } = process.env;
|
|
13
|
+
if (NO_COLOR !== undefined && NO_COLOR !== "")
|
|
14
|
+
return false;
|
|
15
|
+
if (FORCE_COLOR !== undefined)
|
|
16
|
+
return FORCE_COLOR !== "0" && FORCE_COLOR !== "false";
|
|
17
|
+
return process.stdout.isTTY === true && TERM !== "dumb";
|
|
18
|
+
}
|
|
19
|
+
// Read per call, not once at load, so a test can change the environment. An
|
|
20
|
+
// empty string stays empty, so a blank table cell leaves no trailing codes.
|
|
21
|
+
const sgr = (open, close) => (text) => text !== "" && colorEnabled() ? `\u001b[${open}m${text}\u001b[${close}m` : text;
|
|
22
|
+
export const paint = {
|
|
23
|
+
ok: sgr(32, 39),
|
|
24
|
+
warn: sgr(33, 39),
|
|
25
|
+
fail: sgr(31, 39),
|
|
26
|
+
dim: sgr(2, 22),
|
|
27
|
+
bold: sgr(1, 22),
|
|
28
|
+
};
|
|
29
|
+
// The legacy Windows console renders ✓ ⚠ ✗ as boxes. Windows Terminal (which
|
|
30
|
+
// sets WT_SESSION) and VS Code's terminal do not, so only the old one gets ASCII.
|
|
31
|
+
function unicode() {
|
|
32
|
+
return (process.platform !== "win32" ||
|
|
33
|
+
process.env.WT_SESSION !== undefined ||
|
|
34
|
+
process.env.TERM_PROGRAM === "vscode");
|
|
35
|
+
}
|
|
36
|
+
/** The coloured status symbol: ✓ ⚠ ✗, or [ok] [warn] [fail] where those would not render. */
|
|
37
|
+
export function mark(status) {
|
|
38
|
+
const [symbol, ascii, color] = status === "pass"
|
|
39
|
+
? ["✓", "[ok]", paint.ok]
|
|
40
|
+
: status === "warn"
|
|
41
|
+
? ["⚠", "[warn]", paint.warn]
|
|
42
|
+
: ["✗", "[fail]", paint.fail];
|
|
43
|
+
return color(unicode() ? symbol : ascii);
|
|
44
|
+
}
|
|
45
|
+
// Colour codes take no columns on screen, so alignment measures without them.
|
|
46
|
+
const width = (text) => text.replace(/\u001b\[[0-9;]*m/g, "").length;
|
|
47
|
+
/**
|
|
48
|
+
* Rows as aligned columns, one line per row. Every column but the last is
|
|
49
|
+
* padded to its widest cell, so a two-column table is a key/value list.
|
|
50
|
+
*/
|
|
51
|
+
export function table(rows, options = {}) {
|
|
52
|
+
const widths = [];
|
|
53
|
+
for (const row of rows) {
|
|
54
|
+
row.forEach((cell, column) => {
|
|
55
|
+
widths[column] = Math.max(widths[column] ?? 0, width(cell));
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
const indent = " ".repeat(options.indent ?? 0);
|
|
59
|
+
return rows
|
|
60
|
+
.map((row) => indent +
|
|
61
|
+
row
|
|
62
|
+
.map((cell, column) => column === row.length - 1
|
|
63
|
+
? cell
|
|
64
|
+
: cell + " ".repeat((widths[column] ?? 0) - width(cell)))
|
|
65
|
+
.join(" ")
|
|
66
|
+
.trimEnd())
|
|
67
|
+
.join("\n");
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* The one place a command decides between its JSON and its human report. The
|
|
71
|
+
* JSON branch is exactly what the CLI has always written, so a script cannot
|
|
72
|
+
* tell this function exists.
|
|
73
|
+
*/
|
|
74
|
+
export function printJsonOrHuman(value, renderHuman, args) {
|
|
75
|
+
process.stdout.write(isHuman(args) ? `${renderHuman(value)}\n` : `${JSON.stringify(value, null, 2)}\n`);
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=output.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"output.js","sourceRoot":"","sources":["../src/output.ts"],"names":[],"mappings":"AAAA,2CAA2C;AAC3C,sCAAsC;AAWtC,+DAA+D;AAC/D,MAAM,UAAU,OAAO,CACrB,IAAuB,EACvB,SAA8B,OAAO,CAAC,MAAM;IAE5C,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,MAAM,CAAC,KAAK,KAAK,IAAI,CAAC;AAC3D,CAAC;AAED,+EAA+E;AAC/E,8EAA8E;AAC9E,6EAA6E;AAC7E,mEAAmE;AACnE,SAAS,YAAY;IACnB,MAAM,EAAE,QAAQ,EAAE,WAAW,EAAE,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AG,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,CAC3D;aACA,IAAI,CAAC,IAAI,CAAC;aACV,OAAO,EAAE,CACb;SACA,IAAI,CAAC,IAAI,CAAC,CAAC;AAChB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAC9B,KAAQ,EACR,WAAiC,EACjC,IAAuB;IAEvB,OAAO,CAAC,MAAM,CAAC,KAAK,CAClB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,CAClF,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@melra/cli",
|
|
3
|
-
"version": "0.3.0-alpha.
|
|
3
|
+
"version": "0.3.0-alpha.12",
|
|
4
4
|
"description": "MELRA autonomy kernel and command-line interface.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -25,14 +25,14 @@
|
|
|
25
25
|
"README.md"
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@modelcontextprotocol/sdk": "1.
|
|
29
|
-
"@melra/browser-runtime": "0.3.0-alpha.
|
|
30
|
-
"@melra/computer-runtime": "0.3.0-alpha.
|
|
31
|
-
"@melra/policy-core": "0.3.0-alpha.
|
|
32
|
-
"@melra/runtime-core": "0.3.0-alpha.
|
|
33
|
-
"@melra/
|
|
34
|
-
"@melra/
|
|
35
|
-
"@melra/
|
|
28
|
+
"@modelcontextprotocol/sdk": "1.32.1",
|
|
29
|
+
"@melra/browser-runtime": "0.3.0-alpha.12",
|
|
30
|
+
"@melra/computer-runtime": "0.3.0-alpha.12",
|
|
31
|
+
"@melra/policy-core": "0.3.0-alpha.12",
|
|
32
|
+
"@melra/runtime-core": "0.3.0-alpha.12",
|
|
33
|
+
"@melra/server": "0.3.0-alpha.12",
|
|
34
|
+
"@melra/protocol": "0.3.0-alpha.12",
|
|
35
|
+
"@melra/storage-sqlite": "0.3.0-alpha.12"
|
|
36
36
|
},
|
|
37
37
|
"scripts": {
|
|
38
38
|
"build": "tsc -p tsconfig.json && chmod +x dist/bin.js dist/index.js",
|
|
@@ -41,6 +41,6 @@
|
|
|
41
41
|
"start": "tsx src/index.ts",
|
|
42
42
|
"pack:check": "npm pack --dry-run",
|
|
43
43
|
"test": "vitest run --testTimeout=20000",
|
|
44
|
-
"typecheck": "tsc -p tsconfig.json
|
|
44
|
+
"typecheck": "tsc -p tsconfig.test.json"
|
|
45
45
|
}
|
|
46
46
|
}
|