@sdkurjnk/blackshell 0.4.0 → 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.
Files changed (2) hide show
  1. package/dist/cli.js +77 -9
  2. package/package.json +6 -6
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 N] Stage a unit for sealing (N = strength 1..3, cumulative L1..LN; default 3)
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,12 @@ 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
+ }
34
42
  const MAX_LEVEL = 3; // L1..L3 are the noising dials defined in the plan §6.
35
43
  // User-facing dial "N" -> the cumulative set {L1..LN} the engine consumes.
36
44
  // The levels stay an orthogonal set in the engine/harness (§9 per-pass toggle);
@@ -135,28 +143,57 @@ export function onePositional(rest) {
135
143
  }
136
144
  return positionals[0];
137
145
  }
138
- // engine argv for sealing one unit; forwards the staged levels (empty = L0).
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).
139
154
  export function enshellArgs(u) {
140
155
  const args = ["enshell", u.path];
141
156
  if (u.levels.length > 0) {
142
157
  args.push("--level", u.levels.join(","));
143
158
  }
159
+ if (u.name !== undefined) {
160
+ args.push("--out", `${u.name}.o`);
161
+ }
144
162
  return args;
145
163
  }
146
164
  // --- commands ---
147
165
  function cmdCheck(rest) {
166
+ const stray = strayOption(rest);
167
+ if (stray !== undefined) {
168
+ console.error(`error: unknown option: ${stray}`);
169
+ return 1;
170
+ }
148
171
  const src = onePositional(rest);
149
172
  if (src === undefined) {
150
173
  console.error("error: expected exactly one <source> argument");
151
174
  return 1;
152
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
+ }
153
184
  const { token, status } = engine(["check", src]);
154
185
  emit(token);
155
186
  return status;
156
187
  }
157
188
  function cmdAdd(rest) {
158
- const opt = popOption(rest, "--level");
159
- const src = onePositional(opt.rest);
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);
160
197
  if (src === undefined) {
161
198
  console.error("error: expected exactly one <source> argument");
162
199
  return 1;
@@ -165,18 +202,48 @@ function cmdAdd(rest) {
165
202
  console.error(`error: file not found: ${src}`);
166
203
  return 1;
167
204
  }
168
- const levels = expandLevel(opt.value);
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);
169
210
  if (levels === null) {
170
211
  console.error(`error: --level must be an integer 1..${MAX_LEVEL}`);
171
212
  return 1;
172
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
+ }
173
229
  const units = readStage().filter((u) => u.path !== src);
174
- units.push({ path: src, levels });
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);
175
236
  writeStage(units);
176
- console.log(`staged: ${src} [${showLevels(levels)}]`);
237
+ const out = unit.name === undefined ? "" : ` -> ${unit.name}.o`;
238
+ console.log(`staged: ${src} [${showLevels(levels)}]${out}`);
177
239
  return 0;
178
240
  }
179
241
  function cmdDrop(rest) {
242
+ const stray = strayOption(rest);
243
+ if (stray !== undefined) {
244
+ console.error(`error: unknown option: ${stray}`);
245
+ return 1;
246
+ }
180
247
  const src = onePositional(rest);
181
248
  if (src === undefined) {
182
249
  console.error("error: expected exactly one <source> argument");
@@ -199,7 +266,8 @@ function cmdList() {
199
266
  return 0;
200
267
  }
201
268
  for (const u of units) {
202
- console.log(` ${u.path} [${showLevels(u.levels)}]`);
269
+ const out = u.name === undefined ? "" : ` -> ${u.name}.o`;
270
+ console.log(` ${u.path} [${showLevels(u.levels)}]${out}`);
203
271
  }
204
272
  return 0;
205
273
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sdkurjnk/blackshell",
3
- "version": "0.4.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.4.0",
49
- "@sdkurjnk/blackshell-darwin-x64": "0.4.0",
50
- "@sdkurjnk/blackshell-linux-arm64": "0.4.0",
51
- "@sdkurjnk/blackshell-linux-x64": "0.4.0",
52
- "@sdkurjnk/blackshell-win32-x64": "0.4.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
  }