@enerlence/suntropy-cli 0.10.0 → 0.11.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.
@@ -4392,8 +4392,168 @@ function registerGeocodeCommands(program2) {
4392
4392
  });
4393
4393
  }
4394
4394
 
4395
+ // src/access.ts
4396
+ var COMMAND_TIERS = ["read", "write", "delete"];
4397
+ var TIER_VALUE = { read: 0, write: 1, delete: 2 };
4398
+ var DEFAULT_TIER = "delete";
4399
+ var ENV_VAR = "SUNTROPY_COMMAND_PROFILE";
4400
+ function tierValue(t) {
4401
+ return TIER_VALUE[t];
4402
+ }
4403
+ function isValidTier(value) {
4404
+ return typeof value === "string" && COMMAND_TIERS.includes(value);
4405
+ }
4406
+ function getActiveCommandProfile() {
4407
+ const envRaw = process.env[ENV_VAR]?.trim();
4408
+ if (envRaw) {
4409
+ const envNorm = envRaw.toLowerCase();
4410
+ if (isValidTier(envNorm)) return { tier: envNorm, source: "env" };
4411
+ const fallback = resolveFromConfig();
4412
+ return { ...fallback, invalidEnv: envRaw };
4413
+ }
4414
+ return resolveFromConfig();
4415
+ }
4416
+ function resolveFromConfig() {
4417
+ try {
4418
+ const cfg = loadConfig();
4419
+ if (isValidTier(cfg.commandProfile)) return { tier: cfg.commandProfile, source: "config" };
4420
+ } catch {
4421
+ }
4422
+ return { tier: DEFAULT_TIER, source: "default" };
4423
+ }
4424
+ function setStoredCommandProfile(tier) {
4425
+ const cfg = loadConfig();
4426
+ if (tier === null) delete cfg.commandProfile;
4427
+ else cfg.commandProfile = tier;
4428
+ saveConfig(cfg);
4429
+ }
4430
+ var DELETE_VERBS = /* @__PURE__ */ new Set(["delete", "delete-batch", "archive"]);
4431
+ var WRITE_VERBS = /* @__PURE__ */ new Set([
4432
+ "create",
4433
+ "update",
4434
+ "edit",
4435
+ "set",
4436
+ "add",
4437
+ "remove",
4438
+ "assemble",
4439
+ "featured",
4440
+ "save",
4441
+ "init",
4442
+ "init-default",
4443
+ "add-comment",
4444
+ "comment",
4445
+ "calculate-results",
4446
+ "optimize-peakpower"
4447
+ ]);
4448
+ var PATH_OVERRIDES = {
4449
+ "studies calculate production": "write"
4450
+ };
4451
+ function classifyPath(segs) {
4452
+ const key = segs.join(" ");
4453
+ if (PATH_OVERRIDES[key]) return PATH_OVERRIDES[key];
4454
+ let tier = "read";
4455
+ for (const seg of segs) {
4456
+ if (DELETE_VERBS.has(seg)) return "delete";
4457
+ if (WRITE_VERBS.has(seg)) tier = "write";
4458
+ }
4459
+ return tier;
4460
+ }
4461
+ var EXEMPT_CONFIG_LEAVES = /* @__PURE__ */ new Set(["set", "get", "list", "create-profile", "use"]);
4462
+ function isExemptPath(segs) {
4463
+ if (segs[0] === "auth") return true;
4464
+ if (segs[0] === "command-profile") return true;
4465
+ if (segs[0] === "config" && segs.length === 2 && EXEMPT_CONFIG_LEAVES.has(segs[1])) return true;
4466
+ return false;
4467
+ }
4468
+ function applyCommandProfile(program2) {
4469
+ const resolved = getActiveCommandProfile();
4470
+ pruneChildren(program2, [], tierValue(resolved.tier));
4471
+ return resolved;
4472
+ }
4473
+ function pruneChildren(parent, parentSegs, max) {
4474
+ const kept = parent.commands.filter((child) => {
4475
+ const segs = [...parentSegs, child.name()];
4476
+ return keepCommand(child, segs, max);
4477
+ });
4478
+ const mutable = parent.commands;
4479
+ mutable.length = 0;
4480
+ mutable.push(...kept);
4481
+ }
4482
+ function keepCommand(cmd, segs, max) {
4483
+ if (cmd.commands.length > 0) {
4484
+ pruneChildren(cmd, segs, max);
4485
+ if (cmd.commands.length > 0) return true;
4486
+ return isExemptPath(segs);
4487
+ }
4488
+ if (isExemptPath(segs)) return true;
4489
+ return tierValue(classifyPath(segs)) <= max;
4490
+ }
4491
+
4492
+ // src/commands/command-profile.ts
4493
+ function getGlobalOpts16(cmd) {
4494
+ let root = cmd;
4495
+ while (root.parent) root = root.parent;
4496
+ return root.opts();
4497
+ }
4498
+ function registerCommandProfileCommand(program2) {
4499
+ program2.command("command-profile [tier]", { hidden: true }).description("Admin: get/set the command access profile (read | write | delete | reset)").action((tier) => {
4500
+ try {
4501
+ const global = getGlobalOpts16(program2);
4502
+ if (!tier) {
4503
+ const resolved = getActiveCommandProfile();
4504
+ output(
4505
+ {
4506
+ commandProfile: resolved.tier,
4507
+ source: resolved.source,
4508
+ ...resolved.invalidEnv ? { warning: `Ignoring invalid ${ENV_VAR}="${resolved.invalidEnv}" (expected: ${COMMAND_TIERS.join(" | ")})` } : {},
4509
+ available: COMMAND_TIERS,
4510
+ envVar: ENV_VAR
4511
+ },
4512
+ global
4513
+ );
4514
+ return;
4515
+ }
4516
+ const value = tier.trim().toLowerCase();
4517
+ if (value === "reset") {
4518
+ setStoredCommandProfile(null);
4519
+ const resolved = getActiveCommandProfile();
4520
+ output(
4521
+ {
4522
+ success: true,
4523
+ message: `Stored command profile cleared. Effective tier: ${resolved.tier} (${resolved.source}).`,
4524
+ commandProfile: resolved.tier,
4525
+ source: resolved.source
4526
+ },
4527
+ global
4528
+ );
4529
+ return;
4530
+ }
4531
+ if (!isValidTier(value)) {
4532
+ outputError(new Error(`Invalid tier "${tier}". Expected one of: ${COMMAND_TIERS.join(", ")}, or "reset".`));
4533
+ return;
4534
+ }
4535
+ setStoredCommandProfile(value);
4536
+ const envOverride = getActiveCommandProfile();
4537
+ const message = envOverride.source === "env" ? `Stored command profile set to "${value}", but ${ENV_VAR}="${process.env[ENV_VAR]}" overrides it (effective: ${envOverride.tier}). Unset the env var for the stored value to apply.` : `Command profile set to "${value}". Takes effect on the next command.`;
4538
+ output(
4539
+ {
4540
+ success: true,
4541
+ commandProfile: value,
4542
+ effectiveTier: envOverride.tier,
4543
+ effectiveSource: envOverride.source,
4544
+ default: DEFAULT_TIER,
4545
+ message
4546
+ },
4547
+ global
4548
+ );
4549
+ } catch (err) {
4550
+ outputError(err);
4551
+ }
4552
+ });
4553
+ }
4554
+
4395
4555
  // src/index.ts
4396
- var CLI_VERSION = true ? "0.10.0" : "0.0.0-dev";
4556
+ var CLI_VERSION = true ? "0.11.0" : "0.0.0-dev";
4397
4557
  function createProgram() {
4398
4558
  const program2 = new Command3();
4399
4559
  program2.name("suntropy").description("Agent-first CLI for Suntropy solar platform. Optimized for programmatic data manipulation and progressive exploration.").version(CLI_VERSION).option("--format <format>", "Output format: json (default), human, csv", "json").option("--fields <fields>", "Comma-separated fields to include in output").option("--server <url>", "Override API server URL").option("--token <jwt>", "Override authentication token").option("--profile <name>", "Use a specific config profile").option("--verbose", "Show HTTP request/response details on stderr").option("--quiet", "Suppress non-data output").option("--save <file>", "Save output to file (also writes to stdout)");
@@ -4408,6 +4568,8 @@ function createProgram() {
4408
4568
  registerShareableCommands(program2);
4409
4569
  registerTemplatesCommands(program2);
4410
4570
  registerGeocodeCommands(program2);
4571
+ registerCommandProfileCommand(program2);
4572
+ applyCommandProfile(program2);
4411
4573
  return program2;
4412
4574
  }
4413
4575