@sdkurjnk/blackshell 0.3.3 → 0.5.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 +2 -2
- package/dist/cli.js +101 -9
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -49,7 +49,7 @@ Units are **source files**. git-style staging — stage units, then seal the set
|
|
|
49
49
|
|
|
50
50
|
```sh
|
|
51
51
|
blackshell check <source> # preview: is this region eligible? (gate only)
|
|
52
|
-
blackshell add <source> --level
|
|
52
|
+
blackshell add <source> --level 2 # stage a unit (N=1..3, cumulative L1..LN; default 3)
|
|
53
53
|
blackshell list # show staged units and levels
|
|
54
54
|
blackshell drop <source> # unstage
|
|
55
55
|
blackshell enshell # seal all staged units -> object files
|
|
@@ -58,7 +58,7 @@ blackshell enshell # seal all staged units -> object files
|
|
|
58
58
|
Example:
|
|
59
59
|
|
|
60
60
|
```sh
|
|
61
|
-
blackshell add src/engine/examples/add2.c --level
|
|
61
|
+
blackshell add src/engine/examples/add2.c --level 2
|
|
62
62
|
blackshell enshell
|
|
63
63
|
```
|
|
64
64
|
|
package/dist/cli.js
CHANGED
|
@@ -7,13 +7,15 @@ import { spawnSync } from "node:child_process";
|
|
|
7
7
|
import { readFileSync, writeFileSync, existsSync, mkdirSync } from "node:fs";
|
|
8
8
|
import { fileURLToPath } from "node:url";
|
|
9
9
|
import { createRequire } from "node:module";
|
|
10
|
-
import { dirname, join } from "node:path";
|
|
10
|
+
import { dirname, join, extname } from "node:path";
|
|
11
11
|
const here = (p) => fileURLToPath(new URL(p, import.meta.url));
|
|
12
12
|
const pkg = JSON.parse(readFileSync(here("../package.json"), "utf8"));
|
|
13
13
|
const USAGE = `blackshell <command> [options]
|
|
14
14
|
|
|
15
15
|
check <source> Gate verdict only (dummy: accept-all)
|
|
16
|
-
add <source> [--level
|
|
16
|
+
add <source> [--level N] [--name NAME]
|
|
17
|
+
Stage a unit for sealing (N = strength 1..3, cumulative
|
|
18
|
+
L1..LN; default 3). --name sets the output to NAME.o.
|
|
17
19
|
drop <source> Unstage a unit
|
|
18
20
|
list Show staged units and their levels
|
|
19
21
|
enshell Seal every staged unit -> object files
|
|
@@ -31,6 +33,24 @@ export function writeStage(units) {
|
|
|
31
33
|
mkdirSync(".blackshell", { recursive: true });
|
|
32
34
|
writeFileSync(STAGE_FILE, JSON.stringify(units, null, 2) + "\n");
|
|
33
35
|
}
|
|
36
|
+
// Source extensions the Clang frontend accepts. MVP = C/C++; a new frontend
|
|
37
|
+
// module later just adds its extensions here. Lowercase, with the dot.
|
|
38
|
+
const TARGET_EXTENSIONS = [".c", ".cpp", ".cc", ".cxx"];
|
|
39
|
+
export function isTargetSource(path) {
|
|
40
|
+
return TARGET_EXTENSIONS.includes(extname(path).toLowerCase());
|
|
41
|
+
}
|
|
42
|
+
const MAX_LEVEL = 3; // L1..L3 are the noising dials defined in the plan §6.
|
|
43
|
+
// User-facing dial "N" -> the cumulative set {L1..LN} the engine consumes.
|
|
44
|
+
// The levels stay an orthogonal set in the engine/harness (§9 per-pass toggle);
|
|
45
|
+
// this ladder is only the simple front-door UX. undefined -> full strength.
|
|
46
|
+
// Returns null on an invalid dial so the caller can reject at the boundary.
|
|
47
|
+
export function expandLevel(value) {
|
|
48
|
+
const n = value === undefined ? MAX_LEVEL : Number(value);
|
|
49
|
+
if (!Number.isInteger(n) || n < 1 || n > MAX_LEVEL) {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
return Array.from({ length: n }, (_, i) => `L${i + 1}`);
|
|
53
|
+
}
|
|
34
54
|
export function showLevels(levels) {
|
|
35
55
|
if (levels.length === 0) {
|
|
36
56
|
return "L0 (identity)";
|
|
@@ -123,20 +143,57 @@ export function onePositional(rest) {
|
|
|
123
143
|
}
|
|
124
144
|
return positionals[0];
|
|
125
145
|
}
|
|
146
|
+
// First leftover "--flag" once the command's known options are popped off.
|
|
147
|
+
// A command calls this on its remaining args to reject typos/unsupported flags
|
|
148
|
+
// instead of silently dropping them (onePositional filters "--" tokens out).
|
|
149
|
+
export function strayOption(rest) {
|
|
150
|
+
return rest.find((a) => a.startsWith("--"));
|
|
151
|
+
}
|
|
152
|
+
// engine argv for sealing one unit; forwards the staged levels (empty = L0) and,
|
|
153
|
+
// if named, the output path (engine owns file I/O; we pass an opaque path).
|
|
154
|
+
export function enshellArgs(u) {
|
|
155
|
+
const args = ["enshell", u.path];
|
|
156
|
+
if (u.levels.length > 0) {
|
|
157
|
+
args.push("--level", u.levels.join(","));
|
|
158
|
+
}
|
|
159
|
+
if (u.name !== undefined) {
|
|
160
|
+
args.push("--out", `${u.name}.o`);
|
|
161
|
+
}
|
|
162
|
+
return args;
|
|
163
|
+
}
|
|
126
164
|
// --- commands ---
|
|
127
165
|
function cmdCheck(rest) {
|
|
166
|
+
const stray = strayOption(rest);
|
|
167
|
+
if (stray !== undefined) {
|
|
168
|
+
console.error(`error: unknown option: ${stray}`);
|
|
169
|
+
return 1;
|
|
170
|
+
}
|
|
128
171
|
const src = onePositional(rest);
|
|
129
172
|
if (src === undefined) {
|
|
130
173
|
console.error("error: expected exactly one <source> argument");
|
|
131
174
|
return 1;
|
|
132
175
|
}
|
|
176
|
+
if (!existsSync(src)) {
|
|
177
|
+
console.error(`error: file not found: ${src}`);
|
|
178
|
+
return 1;
|
|
179
|
+
}
|
|
180
|
+
if (!isTargetSource(src)) {
|
|
181
|
+
console.error(`error: unsupported source type: ${src} (target: ${TARGET_EXTENSIONS.join(" ")})`);
|
|
182
|
+
return 1;
|
|
183
|
+
}
|
|
133
184
|
const { token, status } = engine(["check", src]);
|
|
134
185
|
emit(token);
|
|
135
186
|
return status;
|
|
136
187
|
}
|
|
137
188
|
function cmdAdd(rest) {
|
|
138
|
-
const
|
|
139
|
-
const
|
|
189
|
+
const levelOpt = popOption(rest, "--level");
|
|
190
|
+
const nameOpt = popOption(levelOpt.rest, "--name");
|
|
191
|
+
const stray = strayOption(nameOpt.rest);
|
|
192
|
+
if (stray !== undefined) {
|
|
193
|
+
console.error(`error: unknown option: ${stray}`);
|
|
194
|
+
return 1;
|
|
195
|
+
}
|
|
196
|
+
const src = onePositional(nameOpt.rest);
|
|
140
197
|
if (src === undefined) {
|
|
141
198
|
console.error("error: expected exactly one <source> argument");
|
|
142
199
|
return 1;
|
|
@@ -145,14 +202,48 @@ function cmdAdd(rest) {
|
|
|
145
202
|
console.error(`error: file not found: ${src}`);
|
|
146
203
|
return 1;
|
|
147
204
|
}
|
|
148
|
-
|
|
205
|
+
if (!isTargetSource(src)) {
|
|
206
|
+
console.error(`error: unsupported source type: ${src} (target: ${TARGET_EXTENSIONS.join(" ")})`);
|
|
207
|
+
return 1;
|
|
208
|
+
}
|
|
209
|
+
const levels = expandLevel(levelOpt.value);
|
|
210
|
+
if (levels === null) {
|
|
211
|
+
console.error(`error: --level must be an integer 1..${MAX_LEVEL}`);
|
|
212
|
+
return 1;
|
|
213
|
+
}
|
|
214
|
+
// --name was given but swallowed the next flag / had no value.
|
|
215
|
+
if (rest.includes("--name") && (nameOpt.value === undefined || nameOpt.value === "" || nameOpt.value.startsWith("--"))) {
|
|
216
|
+
console.error("error: --name requires a value");
|
|
217
|
+
return 1;
|
|
218
|
+
}
|
|
219
|
+
// --name is a bare object stem, not a path: reject separators so the output
|
|
220
|
+
// can't escape the working dir (we hand it to the engine as the object path).
|
|
221
|
+
if (nameOpt.value !== undefined && /[/\\]/.test(nameOpt.value)) {
|
|
222
|
+
console.error("error: --name must be a bare filename (no path separators)");
|
|
223
|
+
return 1;
|
|
224
|
+
}
|
|
225
|
+
const unit = { path: src, levels };
|
|
226
|
+
if (nameOpt.value !== undefined) {
|
|
227
|
+
unit.name = nameOpt.value;
|
|
228
|
+
}
|
|
149
229
|
const units = readStage().filter((u) => u.path !== src);
|
|
150
|
-
units
|
|
230
|
+
// Two units sharing an output name would clobber each other at enshell time.
|
|
231
|
+
if (unit.name !== undefined && units.some((u) => u.name === unit.name)) {
|
|
232
|
+
console.error(`error: output name already staged: ${unit.name}.o`);
|
|
233
|
+
return 1;
|
|
234
|
+
}
|
|
235
|
+
units.push(unit);
|
|
151
236
|
writeStage(units);
|
|
152
|
-
|
|
237
|
+
const out = unit.name === undefined ? "" : ` -> ${unit.name}.o`;
|
|
238
|
+
console.log(`staged: ${src} [${showLevels(levels)}]${out}`);
|
|
153
239
|
return 0;
|
|
154
240
|
}
|
|
155
241
|
function cmdDrop(rest) {
|
|
242
|
+
const stray = strayOption(rest);
|
|
243
|
+
if (stray !== undefined) {
|
|
244
|
+
console.error(`error: unknown option: ${stray}`);
|
|
245
|
+
return 1;
|
|
246
|
+
}
|
|
156
247
|
const src = onePositional(rest);
|
|
157
248
|
if (src === undefined) {
|
|
158
249
|
console.error("error: expected exactly one <source> argument");
|
|
@@ -175,7 +266,8 @@ function cmdList() {
|
|
|
175
266
|
return 0;
|
|
176
267
|
}
|
|
177
268
|
for (const u of units) {
|
|
178
|
-
|
|
269
|
+
const out = u.name === undefined ? "" : ` -> ${u.name}.o`;
|
|
270
|
+
console.log(` ${u.path} [${showLevels(u.levels)}]${out}`);
|
|
179
271
|
}
|
|
180
272
|
return 0;
|
|
181
273
|
}
|
|
@@ -187,7 +279,7 @@ function cmdEnshell() {
|
|
|
187
279
|
}
|
|
188
280
|
let code = 0;
|
|
189
281
|
for (const u of units) {
|
|
190
|
-
const { token, status } = engine(
|
|
282
|
+
const { token, status } = engine(enshellArgs(u));
|
|
191
283
|
emit(token);
|
|
192
284
|
if (status !== 0) {
|
|
193
285
|
code = status;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sdkurjnk/blackshell",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Build-stage protection tool that seals critical code regions at the compiler IR level, communicating with the outside only by value.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -45,10 +45,10 @@
|
|
|
45
45
|
"typescript": "^7.0.2"
|
|
46
46
|
},
|
|
47
47
|
"optionalDependencies": {
|
|
48
|
-
"@sdkurjnk/blackshell-darwin-arm64": "0.
|
|
49
|
-
"@sdkurjnk/blackshell-darwin-x64": "0.
|
|
50
|
-
"@sdkurjnk/blackshell-linux-arm64": "0.
|
|
51
|
-
"@sdkurjnk/blackshell-linux-x64": "0.
|
|
52
|
-
"@sdkurjnk/blackshell-win32-x64": "0.
|
|
48
|
+
"@sdkurjnk/blackshell-darwin-arm64": "0.5.0",
|
|
49
|
+
"@sdkurjnk/blackshell-darwin-x64": "0.5.0",
|
|
50
|
+
"@sdkurjnk/blackshell-linux-arm64": "0.5.0",
|
|
51
|
+
"@sdkurjnk/blackshell-linux-x64": "0.5.0",
|
|
52
|
+
"@sdkurjnk/blackshell-win32-x64": "0.5.0"
|
|
53
53
|
}
|
|
54
54
|
}
|