@diafunc/cli 0.13.0 → 0.15.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 CHANGED
@@ -56,6 +56,10 @@ diafunc config set defaults.project my-project
56
56
  # List your projects
57
57
  diafunc project list
58
58
 
59
+ # Create a table and load a file into it
60
+ diafunc table create my-table --name "My Table"
61
+ diafunc table import my-table data.csv
62
+
59
63
  # View table data
60
64
  diafunc table view my-table
61
65
 
@@ -193,7 +197,7 @@ Nothing is asked when stdin or stdout is not a terminal, with `--output json`, o
193
197
  | `diafunc invoice` | List and download invoices |
194
198
  | `diafunc utilization` | Show current credit utilization, and with `history` what each day of the billing cycle cost |
195
199
  | `diafunc status` | Platform health: summary, per-component status, incidents |
196
- | `diafunc admin` | User management, subscription, settings, backups, index rebuild, permission inspection |
200
+ | `diafunc admin` | User management, subscription, settings, platform settings, backups, index rebuild, permission inspection |
197
201
  | `diafunc completion` | Generate shell completions |
198
202
 
199
203
  Run `diafunc <command> --help` for detailed usage of any command.
@@ -4,13 +4,13 @@ import {
4
4
  PromptCancelled,
5
5
  createProgram,
6
6
  handleError
7
- } from "../chunk-EJLRB75G.js";
7
+ } from "../chunk-XK2UUCKV.js";
8
8
  import {
9
9
  getUpdateNotice
10
- } from "../chunk-GOEDVSWO.js";
10
+ } from "../chunk-37PYSRXA.js";
11
11
  import {
12
12
  package_default
13
- } from "../chunk-TWJWXUZL.js";
13
+ } from "../chunk-VL7FZNQK.js";
14
14
 
15
15
  // bin/diafunc.ts
16
16
  import chalk2 from "chalk";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  package_default
3
- } from "./chunk-TWJWXUZL.js";
3
+ } from "./chunk-VL7FZNQK.js";
4
4
 
5
5
  // src/util/update-check.ts
6
6
  import * as fs from "fs";
@@ -72,4 +72,4 @@ async function getUpdateNotice() {
72
72
  export {
73
73
  getUpdateNotice
74
74
  };
75
- //# sourceMappingURL=chunk-GOEDVSWO.js.map
75
+ //# sourceMappingURL=chunk-37PYSRXA.js.map
@@ -1,7 +1,7 @@
1
1
  // package.json
2
2
  var package_default = {
3
3
  name: "@diafunc/cli",
4
- version: "0.13.0",
4
+ version: "0.15.0",
5
5
  description: "Diafunc CLI: the command-line interface for the Diafunc platform",
6
6
  type: "module",
7
7
  bin: {
@@ -62,4 +62,4 @@ var package_default = {
62
62
  export {
63
63
  package_default
64
64
  };
65
- //# sourceMappingURL=chunk-TWJWXUZL.js.map
65
+ //# sourceMappingURL=chunk-VL7FZNQK.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../package.json"],"sourcesContent":["{\n \"name\": \"@diafunc/cli\",\n \"version\": \"0.13.0\",\n \"description\": \"Diafunc CLI: the command-line interface for the Diafunc platform\",\n \"type\": \"module\",\n \"bin\": {\n \"diafunc\": \"./dist/bin/diafunc.js\"\n },\n \"homepage\": \"https://diafunc.com\",\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"git+https://gitlab.com/diafunc/cli.git\"\n },\n \"bugs\": {\n \"url\": \"https://gitlab.com/diafunc/cli/-/issues\"\n },\n \"author\": \"Markus Pollak <markus.pollak@diafunc.com>\",\n \"scripts\": {\n \"build\": \"tsup && node -e \\\"const fs=require('fs');const f='dist/bin/diafunc.js';fs.writeFileSync(f,'#!/usr/bin/env node\\\\n'+fs.readFileSync(f,'utf8'))\\\"\",\n \"dev\": \"tsup --watch\",\n \"test\": \"vitest run\",\n \"test:watch\": \"vitest\",\n \"lint\": \"tsc --noEmit\",\n \"start\": \"node dist/bin/diafunc.js\",\n \"prepublishOnly\": \"npm run lint && npm test && npm run build\"\n },\n \"files\": [\n \"dist\",\n \"LICENSE\",\n \"README.md\"\n ],\n \"keywords\": [\n \"diafunc\",\n \"cli\",\n \"data-science\",\n \"symbolic-regression\"\n ],\n \"license\": \"Apache-2.0\",\n \"publishConfig\": {\n \"access\": \"public\",\n \"registry\": \"https://registry.npmjs.org/\"\n },\n \"engines\": {\n \"node\": \">=20.0.0\"\n },\n \"dependencies\": {\n \"@inquirer/prompts\": \"^7.0.0\",\n \"chalk\": \"^5.4.0\",\n \"cli-table3\": \"^0.6.5\",\n \"commander\": \"^12.1.0\",\n \"ora\": \"^8.1.0\"\n },\n \"devDependencies\": {\n \"@types/node\": \"^22.0.0\",\n \"tsup\": \"^8.3.0\",\n \"typescript\": \"^5.6.0\",\n \"vitest\": \"^2.1.0\"\n }\n}\n"],"mappings":";AAAA;AAAA,EACE,MAAQ;AAAA,EACR,SAAW;AAAA,EACX,aAAe;AAAA,EACf,MAAQ;AAAA,EACR,KAAO;AAAA,IACL,SAAW;AAAA,EACb;AAAA,EACA,UAAY;AAAA,EACZ,YAAc;AAAA,IACZ,MAAQ;AAAA,IACR,KAAO;AAAA,EACT;AAAA,EACA,MAAQ;AAAA,IACN,KAAO;AAAA,EACT;AAAA,EACA,QAAU;AAAA,EACV,SAAW;AAAA,IACT,OAAS;AAAA,IACT,KAAO;AAAA,IACP,MAAQ;AAAA,IACR,cAAc;AAAA,IACd,MAAQ;AAAA,IACR,OAAS;AAAA,IACT,gBAAkB;AAAA,EACpB;AAAA,EACA,OAAS;AAAA,IACP;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAAA,EACA,UAAY;AAAA,IACV;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAAA,EACA,SAAW;AAAA,EACX,eAAiB;AAAA,IACf,QAAU;AAAA,IACV,UAAY;AAAA,EACd;AAAA,EACA,SAAW;AAAA,IACT,MAAQ;AAAA,EACV;AAAA,EACA,cAAgB;AAAA,IACd,qBAAqB;AAAA,IACrB,OAAS;AAAA,IACT,cAAc;AAAA,IACd,WAAa;AAAA,IACb,KAAO;AAAA,EACT;AAAA,EACA,iBAAmB;AAAA,IACjB,eAAe;AAAA,IACf,MAAQ;AAAA,IACR,YAAc;AAAA,IACd,QAAU;AAAA,EACZ;AACF;","names":[]}
1
+ {"version":3,"sources":["../package.json"],"sourcesContent":["{\n \"name\": \"@diafunc/cli\",\n \"version\": \"0.15.0\",\n \"description\": \"Diafunc CLI: the command-line interface for the Diafunc platform\",\n \"type\": \"module\",\n \"bin\": {\n \"diafunc\": \"./dist/bin/diafunc.js\"\n },\n \"homepage\": \"https://diafunc.com\",\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"git+https://gitlab.com/diafunc/cli.git\"\n },\n \"bugs\": {\n \"url\": \"https://gitlab.com/diafunc/cli/-/issues\"\n },\n \"author\": \"Markus Pollak <markus.pollak@diafunc.com>\",\n \"scripts\": {\n \"build\": \"tsup && node -e \\\"const fs=require('fs');const f='dist/bin/diafunc.js';fs.writeFileSync(f,'#!/usr/bin/env node\\\\n'+fs.readFileSync(f,'utf8'))\\\"\",\n \"dev\": \"tsup --watch\",\n \"test\": \"vitest run\",\n \"test:watch\": \"vitest\",\n \"lint\": \"tsc --noEmit\",\n \"start\": \"node dist/bin/diafunc.js\",\n \"prepublishOnly\": \"npm run lint && npm test && npm run build\"\n },\n \"files\": [\n \"dist\",\n \"LICENSE\",\n \"README.md\"\n ],\n \"keywords\": [\n \"diafunc\",\n \"cli\",\n \"data-science\",\n \"symbolic-regression\"\n ],\n \"license\": \"Apache-2.0\",\n \"publishConfig\": {\n \"access\": \"public\",\n \"registry\": \"https://registry.npmjs.org/\"\n },\n \"engines\": {\n \"node\": \">=20.0.0\"\n },\n \"dependencies\": {\n \"@inquirer/prompts\": \"^7.0.0\",\n \"chalk\": \"^5.4.0\",\n \"cli-table3\": \"^0.6.5\",\n \"commander\": \"^12.1.0\",\n \"ora\": \"^8.1.0\"\n },\n \"devDependencies\": {\n \"@types/node\": \"^22.0.0\",\n \"tsup\": \"^8.3.0\",\n \"typescript\": \"^5.6.0\",\n \"vitest\": \"^2.1.0\"\n }\n}\n"],"mappings":";AAAA;AAAA,EACE,MAAQ;AAAA,EACR,SAAW;AAAA,EACX,aAAe;AAAA,EACf,MAAQ;AAAA,EACR,KAAO;AAAA,IACL,SAAW;AAAA,EACb;AAAA,EACA,UAAY;AAAA,EACZ,YAAc;AAAA,IACZ,MAAQ;AAAA,IACR,KAAO;AAAA,EACT;AAAA,EACA,MAAQ;AAAA,IACN,KAAO;AAAA,EACT;AAAA,EACA,QAAU;AAAA,EACV,SAAW;AAAA,IACT,OAAS;AAAA,IACT,KAAO;AAAA,IACP,MAAQ;AAAA,IACR,cAAc;AAAA,IACd,MAAQ;AAAA,IACR,OAAS;AAAA,IACT,gBAAkB;AAAA,EACpB;AAAA,EACA,OAAS;AAAA,IACP;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAAA,EACA,UAAY;AAAA,IACV;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAAA,EACA,SAAW;AAAA,EACX,eAAiB;AAAA,IACf,QAAU;AAAA,IACV,UAAY;AAAA,EACd;AAAA,EACA,SAAW;AAAA,IACT,MAAQ;AAAA,EACV;AAAA,EACA,cAAgB;AAAA,IACd,qBAAqB;AAAA,IACrB,OAAS;AAAA,IACT,cAAc;AAAA,IACd,WAAa;AAAA,IACb,KAAO;AAAA,EACT;AAAA,EACA,iBAAmB;AAAA,IACjB,eAAe;AAAA,IACf,MAAQ;AAAA,IACR,YAAc;AAAA,IACd,QAAU;AAAA,EACZ;AACF;","names":[]}
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  package_default
3
- } from "./chunk-TWJWXUZL.js";
3
+ } from "./chunk-VL7FZNQK.js";
4
4
 
5
5
  // src/index.ts
6
6
  import chalk36 from "chalk";
@@ -270,6 +270,7 @@ ${bodyPreview}`));
270
270
  body = JSON.stringify(opts.body);
271
271
  }
272
272
  headers["User-Agent"] = `diafunc-cli/${package_default.version} (${process.platform}; node ${process.versions.node})`;
273
+ headers["X-Diafunc-Client"] = `cli/${package_default.version}`;
273
274
  const retryable = RETRYABLE_METHODS.has(opts.method);
274
275
  const maxAttempts = retryable ? MAX_ATTEMPTS : 1;
275
276
  let lastError;
@@ -689,6 +690,7 @@ function createAdminService(client) {
689
690
  path: "/settings/"
690
691
  });
691
692
  },
693
+ // The platform expects one { name, value } pair, not a map keyed by the setting name.
692
694
  async mergeSetting(setting) {
693
695
  return client.request({
694
696
  method: "PUT",
@@ -697,6 +699,23 @@ function createAdminService(client) {
697
699
  body: setting
698
700
  });
699
701
  },
702
+ // Platform settings: the operator-facing catalogue, distinct from the per-user settings above.
703
+ // Every entry carries its compiled default, so an unset override reads as null rather than absent.
704
+ async listPlatformSettings() {
705
+ return client.request({
706
+ method: "GET",
707
+ service: SERVICE,
708
+ path: "/platform-settings"
709
+ });
710
+ },
711
+ async updatePlatformSetting(key, value, reason2) {
712
+ return client.request({
713
+ method: "PUT",
714
+ service: SERVICE,
715
+ path: `/platform-settings/${encodeURIComponent(key)}`,
716
+ body: { value, reason: reason2 }
717
+ });
718
+ },
700
719
  // Subscription
701
720
  async getCurrentSubscription() {
702
721
  return client.request({
@@ -1850,11 +1869,12 @@ function createStorageService(client) {
1850
1869
  });
1851
1870
  },
1852
1871
  // --- Linked Entities ---
1853
- async getLinkedEntities(direction, ref) {
1872
+ async getLinkedEntities(direction, ref, linkId) {
1873
+ const byLink = linkId ? `/${enc(linkId)}` : "";
1854
1874
  return client.request({
1855
1875
  method: "GET",
1856
1876
  service: SERVICE3,
1857
- path: `/linked-entities/${enc(direction)}${entityPath(ref)}`
1877
+ path: `/linked-entities/${enc(direction)}${entityPath(ref)}${byLink}`
1858
1878
  });
1859
1879
  },
1860
1880
  async saveLinkedEntities(ref, linkId, entities) {
@@ -3151,6 +3171,25 @@ function percent(fraction) {
3151
3171
  const clamped = Math.max(0, Math.min(1, Number.isFinite(fraction) ? fraction : 0));
3152
3172
  return `${Math.round(clamped * 100)}%`.padStart(4);
3153
3173
  }
3174
+ var QUALITY_MAX_DECIMALS = 4;
3175
+ function qualityPercent(quality) {
3176
+ const unit = Math.max(0, Math.min(Number.isFinite(quality) ? quality : 0, 1));
3177
+ if (unit >= 1) return "100%";
3178
+ let decimals = 1;
3179
+ let shown = flooredPercent(unit, decimals);
3180
+ while (decimals < QUALITY_MAX_DECIMALS && /\.9+$/.test(shown)) {
3181
+ decimals++;
3182
+ shown = flooredPercent(unit, decimals);
3183
+ }
3184
+ return `${decimals > 1 ? shown.replace(/0+$/, "") : shown}%`;
3185
+ }
3186
+ function flooredPercent(unit, decimals) {
3187
+ return (shift(Math.floor(shift(unit, decimals + 2)), -(decimals + 2)) * 100).toFixed(decimals);
3188
+ }
3189
+ function shift(value, exponent) {
3190
+ const [mantissa, magnitude] = value.toExponential().split("e");
3191
+ return Number(`${mantissa}e${Number(magnitude) + exponent}`);
3192
+ }
3154
3193
 
3155
3194
  // src/commands/bundle-helpers.ts
3156
3195
  async function streamResponseToFile(response, outFile) {
@@ -3372,6 +3411,11 @@ Showing ${capped.length} of ${projects.length}. Pass --limit 0 to see them all.`
3372
3411
  language: options.language,
3373
3412
  active: true
3374
3413
  });
3414
+ await api.storage.createProjectBranch({
3415
+ projectId: p.projectId,
3416
+ sourceProjectBranch: null,
3417
+ targetProjectBranch: "main"
3418
+ });
3375
3419
  if (outputFormat === "human") {
3376
3420
  success("Project created.");
3377
3421
  console.log(` Project ID: ${chalk12.bold(p.projectId)}`);
@@ -4528,7 +4572,60 @@ function decodeCellValue(value, type) {
4528
4572
  return bytes.toString("utf-8");
4529
4573
  }
4530
4574
 
4575
+ // src/util/entity-attributes.ts
4576
+ function encodeTextAttribute(value) {
4577
+ return Buffer.from(value, "utf-8").toString("base64");
4578
+ }
4579
+ function decodeTextAttribute(value) {
4580
+ if (value === null || value === void 0) return null;
4581
+ return Buffer.from(value, "base64").toString("utf-8");
4582
+ }
4583
+ function encodeLongAttribute(value) {
4584
+ if (!Number.isSafeInteger(value)) {
4585
+ throw new RangeError(`Not an integer attribute value: ${value}`);
4586
+ }
4587
+ const bytes = Buffer.alloc(8);
4588
+ bytes.writeBigInt64BE(BigInt(value));
4589
+ return bytes.toString("base64");
4590
+ }
4591
+
4592
+ // src/util/table-entity.ts
4593
+ function buildTableEntity(args) {
4594
+ const now = Date.now();
4595
+ const attributes = { name: encodeTextAttribute(args.name) };
4596
+ const attributeTypes = { name: "text" };
4597
+ if (args.index !== void 0) {
4598
+ attributes.index = encodeLongAttribute(args.index);
4599
+ attributeTypes.index = "integer";
4600
+ }
4601
+ return {
4602
+ projectId: args.projectId,
4603
+ projectBranch: args.projectBranch,
4604
+ entityId: args.entityId,
4605
+ entityBranch: args.entityBranch,
4606
+ head: true,
4607
+ version: 1,
4608
+ type: "table",
4609
+ attributes,
4610
+ attributeTypes,
4611
+ metaAttributes: {},
4612
+ metaAttributeTypes: {},
4613
+ tags: [],
4614
+ modified: now,
4615
+ created: now,
4616
+ versioned: false,
4617
+ versionTtl: null,
4618
+ retain: false,
4619
+ contentAvailable: false,
4620
+ contentLoaded: false,
4621
+ contentType: null,
4622
+ contentSize: null,
4623
+ content: null
4624
+ };
4625
+ }
4626
+
4531
4627
  // src/commands/table/index.ts
4628
+ import { randomUUID } from "crypto";
4532
4629
  function getOutputFormat7(cmd) {
4533
4630
  const config = loadConfig();
4534
4631
  const globalOpts = cmd.optsWithGlobals();
@@ -4551,9 +4648,39 @@ function deriveOutFile(entityId, extension, archive, compression) {
4551
4648
  }
4552
4649
  return name;
4553
4650
  }
4651
+ function projectPlacement(table) {
4652
+ return {
4653
+ parent: { projectId: table.projectId, projectBranch: table.projectBranch, entityId: table.projectId, entityBranch: "main" },
4654
+ linkId: "main"
4655
+ };
4656
+ }
4657
+ async function notebookPlacement(api, notebook, table) {
4658
+ const parent = parseEntityReference(notebook, { project: table.projectId, branch: table.projectBranch });
4659
+ if (parent.projectId !== table.projectId || parent.projectBranch !== table.projectBranch) {
4660
+ throw new CliError("The notebook must be in the same project and branch as the table.");
4661
+ }
4662
+ const entity = await api.storage.getEntity(parent, false).catch((error) => {
4663
+ if (error instanceof ApiError && error.status === 404) {
4664
+ throw new CliError(`There is no notebook "${parent.entityId}".`, {
4665
+ hint: `List what the project holds with 'diafunc entity list ${parent.projectId}/${parent.projectBranch}'.`
4666
+ });
4667
+ }
4668
+ throw error;
4669
+ });
4670
+ if (entity.type !== "notebook" && entity.type !== "chapter") {
4671
+ throw new CliError(`"${parent.entityId}" is a ${entity.type ?? "untyped entity"}, not a notebook or chapter.`);
4672
+ }
4673
+ const sections = await api.storage.getLinkedEntities("FORWARD", parent, "sections");
4674
+ const last = sections.map((section) => decodeLongAttribute(section.attributes?.index)).filter((index) => index !== null).reduce((highest, index) => Math.max(highest, index), -1);
4675
+ return { parent, linkId: "sections", index: last + 1 };
4676
+ }
4677
+ function formatReference(ref) {
4678
+ return `${ref.projectId}/${ref.projectBranch}/${ref.entityId}/${ref.entityBranch}`;
4679
+ }
4554
4680
  function registerTableCommands(program) {
4555
4681
  const table = program.command("table").description("Manage tables").addHelpText("after", `
4556
4682
  Examples:
4683
+ $ diafunc table create sales an empty table named "sales"
4557
4684
  $ diafunc table view <ref> --rows 0:20 the first twenty rows
4558
4685
  $ diafunc table import <ref> data.csv load a file
4559
4686
  $ diafunc table export <ref> parquet write one out
@@ -4614,6 +4741,49 @@ Examples:
4614
4741
  handleError(error);
4615
4742
  }
4616
4743
  });
4744
+ table.command("create").description("Create an empty table, at project level or as a section of a notebook").argument("[ref]", "The new table's entity reference (default: a new id in the default project)").option("--name <name>", 'Display name (defaults to the entity id, or "Table" for a generated id)').option("--notebook <ref>", "Add the table as a section of this notebook or chapter instead of at project level").addHelpText("after", `
4745
+ A table at project level is linked from the project, where 'diafunc entity list' shows it. With --notebook it
4746
+ becomes the notebook's last section, as Add Table in the Lab does. Either way it starts empty; load it with
4747
+ 'diafunc table import <ref> <file>'.
4748
+
4749
+ Examples:
4750
+ $ diafunc table create sales --name "Sales 2026"
4751
+ $ diafunc table create --notebook <notebookId>
4752
+ `).action(async (ref, options, cmd) => {
4753
+ try {
4754
+ const outputFormat = getOutputFormat7(cmd);
4755
+ const overrides = getOverrides6(cmd);
4756
+ const resolved = parseEntityReference(ref ?? randomUUID(), overrides);
4757
+ if (resolved.entityId.includes(".partition.")) {
4758
+ throw new CliError(`"${resolved.entityId}" contains ".partition.", which names a table's storage blocks.`, {
4759
+ exitCode: EXIT_USAGE,
4760
+ hint: "Choose an id without it."
4761
+ });
4762
+ }
4763
+ const api = createApiClient();
4764
+ if (await api.storage.entityExists(resolved)) {
4765
+ throw new CliError(`An entity "${resolved.entityId}" already exists in this project.`, {
4766
+ hint: `Import into it with 'diafunc table import ${formatReference(resolved)} <file>', or choose another id.`
4767
+ });
4768
+ }
4769
+ const name = options.name ?? (ref ? resolved.entityId : "Table");
4770
+ const placement = options.notebook ? await notebookPlacement(api, options.notebook, resolved) : projectPlacement(resolved);
4771
+ const entity = buildTableEntity({ ...resolved, name, index: placement.index });
4772
+ await api.storage.saveLinkedEntities(placement.parent, placement.linkId, [entity]);
4773
+ const created = formatReference(resolved);
4774
+ if (outputFormat === "json") {
4775
+ format(
4776
+ { ...resolved, name, parent: placement.parent.entityId, linkId: placement.linkId, index: placement.index ?? null },
4777
+ { format: outputFormat }
4778
+ );
4779
+ return;
4780
+ }
4781
+ success(`Table "${name}" created: ${created}`);
4782
+ hint(`Load data with 'diafunc table import ${created} <file>'.`);
4783
+ } catch (error) {
4784
+ handleError(error);
4785
+ }
4786
+ });
4617
4787
  table.command("import").description("Import data from a file (any supported format; see `table import-formats`)").argument("<ref>", "Table entity reference").argument("<file>", "File to import").option("--selection <id>", "Pin a sheet / inner-table id for multi-table sources (Excel sheets, SQLite tables, archive entries)").action(async (ref, file, options, cmd) => {
4618
4788
  try {
4619
4789
  const overrides = getOverrides6(cmd);
@@ -4630,7 +4800,14 @@ Examples:
4630
4800
  const importId = await withStatus(
4631
4801
  `Uploading ${path3.basename(file)}`,
4632
4802
  () => api.storage.importTable(resolved, formData, options.selection)
4633
- );
4803
+ ).catch((error) => {
4804
+ if (error instanceof ApiError && error.status === 404) {
4805
+ throw new CliError(`There is no table "${resolved.entityId}" to import into.`, {
4806
+ hint: `Create it first with 'diafunc table create ${ref}', then import again.`
4807
+ });
4808
+ }
4809
+ throw error;
4810
+ });
4634
4811
  const pollInterval = 1e3;
4635
4812
  const maxAttempts = 300;
4636
4813
  const status = new Status();
@@ -5096,7 +5273,7 @@ import * as fs6 from "fs";
5096
5273
  import * as os2 from "os";
5097
5274
  import * as path5 from "path";
5098
5275
  import { spawn } from "child_process";
5099
- import { randomUUID } from "crypto";
5276
+ import { randomUUID as randomUUID2 } from "crypto";
5100
5277
 
5101
5278
  // src/util/time-uuid.ts
5102
5279
  import { randomBytes } from "crypto";
@@ -5160,11 +5337,11 @@ function buildFunctionEntity(args) {
5160
5337
  const attributes = {};
5161
5338
  const attributeTypes = {};
5162
5339
  if (args.language !== null && args.language !== void 0) {
5163
- attributes.language = args.language;
5340
+ attributes.language = encodeTextAttribute(args.language);
5164
5341
  attributeTypes.language = "text";
5165
5342
  }
5166
5343
  if (args.name !== null && args.name !== void 0) {
5167
- attributes.name = args.name;
5344
+ attributes.name = encodeTextAttribute(args.name);
5168
5345
  attributeTypes.name = "text";
5169
5346
  }
5170
5347
  return {
@@ -5509,9 +5686,9 @@ Examples:
5509
5686
  const api = createApiClient();
5510
5687
  const entity = await api.storage.getEntity(resolved, true);
5511
5688
  const currentSource = decodeFunctionSource(entity);
5512
- const language = entity.attributes?.["language"] ?? "txt";
5689
+ const language = decodeTextAttribute(entity.attributes?.["language"]) ?? "txt";
5513
5690
  const ext = extensionFor(language);
5514
- const tmpFile = path5.join(os2.tmpdir(), `diafunc-${resolved.entityId}-${randomUUID()}.${ext}`);
5691
+ const tmpFile = path5.join(os2.tmpdir(), `diafunc-${resolved.entityId}-${randomUUID2()}.${ext}`);
5515
5692
  fs6.writeFileSync(tmpFile, currentSource);
5516
5693
  const editor = process.env.VISUAL ?? process.env.EDITOR ?? "vi";
5517
5694
  await new Promise((resolve, reject) => {
@@ -5969,7 +6146,7 @@ var HELP = [
5969
6146
  ];
5970
6147
  async function runChatRepl(options) {
5971
6148
  const { input: promptInput } = await import("@inquirer/prompts");
5972
- const { getUpdateNotice } = await import("./update-check-V23VUFO4.js");
6149
+ const { getUpdateNotice } = await import("./update-check-2GASRVMF.js");
5973
6150
  let sessionId = options.session;
5974
6151
  let lastReportedSession;
5975
6152
  console.log(chalk19.bold("Diafunc chat") + chalk19.dim(" \xB7 /help for commands, /quit to exit"));
@@ -6423,12 +6600,32 @@ function registerAdminCommands(program) {
6423
6600
  settings.command("set").description("Update a setting").argument("<key>", "Setting key").argument("<value>", "Setting value").action(async (key, value) => {
6424
6601
  try {
6425
6602
  const api = createApiClient();
6426
- await api.admin.mergeSetting({ [key]: value });
6603
+ await api.admin.mergeSetting({ name: key, value });
6427
6604
  success(`Setting "${key}" updated.`);
6428
6605
  } catch (error) {
6429
6606
  handleError(error);
6430
6607
  }
6431
6608
  });
6609
+ const platformSettings = admin.command("platform-settings").description("Manage platform-wide settings (admin only)");
6610
+ platformSettings.command("list").description("Show every platform setting with its default and current override").action(async (_options, cmd) => {
6611
+ try {
6612
+ const outputFormat = getOutputFormat14(cmd);
6613
+ const api = createApiClient();
6614
+ const settingsList = await api.admin.listPlatformSettings();
6615
+ format(settingsList, { format: outputFormat });
6616
+ } catch (error) {
6617
+ handleError(error);
6618
+ }
6619
+ });
6620
+ platformSettings.command("set").description("Override one platform setting (an empty value restores the default)").argument("<key>", "Setting key, as shown by `platform-settings list`").argument("<value>", "New value; an empty string restores the compiled default").option("--reason <reason>", "Why it was changed; stored alongside the override").action(async (key, value, options) => {
6621
+ try {
6622
+ const api = createApiClient();
6623
+ await api.admin.updatePlatformSetting(key, value, options.reason);
6624
+ success(`Platform setting "${key}" set to "${value}".`);
6625
+ } catch (error) {
6626
+ handleError(error);
6627
+ }
6628
+ });
6432
6629
  const backup = admin.command("backup").description("Manage backups");
6433
6630
  backup.command("create-full").description("Create a full system short-term backup").option("--long-term", "Create a long-term backup instead").action(async (options) => {
6434
6631
  try {
@@ -6838,7 +7035,7 @@ function phaseDetail(run) {
6838
7035
  parts.push(`generation ${formatNumber(run.fitGeneration)}`);
6839
7036
  }
6840
7037
  if (run.fitQuality !== null && run.fitQuality !== void 0) {
6841
- parts.push(`quality ${Math.floor(Math.max(0, Math.min(run.fitQuality, 1)) * 100)}%`);
7038
+ parts.push(`quality ${qualityPercent(run.fitQuality)}`);
6842
7039
  }
6843
7040
  if (run.fitBudgetFraction !== null && run.fitBudgetFraction !== void 0) {
6844
7041
  parts.push(`${Math.round(run.fitBudgetFraction * 100)}% of budget used`);
@@ -9228,7 +9425,7 @@ import * as fs11 from "fs";
9228
9425
  import * as os3 from "os";
9229
9426
  import * as path8 from "path";
9230
9427
  import { spawn as spawn3 } from "child_process";
9231
- import { randomUUID as randomUUID2 } from "crypto";
9428
+ import { randomUUID as randomUUID3 } from "crypto";
9232
9429
  function extensionFor2(language) {
9233
9430
  const l = language.toLowerCase();
9234
9431
  if (l === "java") return "java";
@@ -9239,7 +9436,7 @@ function extensionFor2(language) {
9239
9436
  return "txt";
9240
9437
  }
9241
9438
  async function openInEditor(initial, ext) {
9242
- const tmpFile = path8.join(os3.tmpdir(), `diafunc-shell-${randomUUID2()}.${ext}`);
9439
+ const tmpFile = path8.join(os3.tmpdir(), `diafunc-shell-${randomUUID3()}.${ext}`);
9243
9440
  fs11.writeFileSync(tmpFile, initial);
9244
9441
  const editor = process.env.VISUAL ?? process.env.EDITOR ?? "vi";
9245
9442
  await new Promise((resolve, reject) => {
@@ -9324,7 +9521,7 @@ function registerShellCommand(program) {
9324
9521
  });
9325
9522
  const api = createApiClient();
9326
9523
  const { input: promptInput } = await import("@inquirer/prompts");
9327
- const { getUpdateNotice } = await import("./update-check-V23VUFO4.js");
9524
+ const { getUpdateNotice } = await import("./update-check-2GASRVMF.js");
9328
9525
  const resolvedLanguage = await resolveLanguage(api, fnRef.projectId, options.language);
9329
9526
  console.log(chalk31.bold("Diafunc shell") + chalk31.dim(` \xB7 function ${fnRef.entityId} \xB7 ${resolvedLanguage}`));
9330
9527
  console.log(chalk31.dim(`Endpoint: ${config.profiles[config.currentProfile]?.endpoint}`));
@@ -10369,4 +10566,4 @@ export {
10369
10566
  PromptCancelled,
10370
10567
  createProgram
10371
10568
  };
10372
- //# sourceMappingURL=chunk-EJLRB75G.js.map
10569
+ //# sourceMappingURL=chunk-XK2UUCKV.js.map