@diafunc/cli 0.20.0 → 0.22.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.
@@ -4,13 +4,13 @@ import {
4
4
  PromptCancelled,
5
5
  createProgram,
6
6
  handleError
7
- } from "../chunk-D7AJH4Y3.js";
7
+ } from "../chunk-LEDCBZ3S.js";
8
8
  import {
9
9
  getUpdateNotice
10
- } from "../chunk-4STLEQUJ.js";
10
+ } from "../chunk-KIHRD6SW.js";
11
11
  import {
12
12
  package_default
13
- } from "../chunk-V2VLVFWP.js";
13
+ } from "../chunk-5WKI5YMX.js";
14
14
 
15
15
  // bin/diafunc.ts
16
16
  import chalk2 from "chalk";
@@ -1,7 +1,7 @@
1
1
  // package.json
2
2
  var package_default = {
3
3
  name: "@diafunc/cli",
4
- version: "0.20.0",
4
+ version: "0.22.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-V2VLVFWP.js.map
65
+ //# sourceMappingURL=chunk-5WKI5YMX.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../package.json"],"sourcesContent":["{\n \"name\": \"@diafunc/cli\",\n \"version\": \"0.20.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.22.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-V2VLVFWP.js";
3
+ } from "./chunk-5WKI5YMX.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-4STLEQUJ.js.map
75
+ //# sourceMappingURL=chunk-KIHRD6SW.js.map
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  package_default
3
- } from "./chunk-V2VLVFWP.js";
3
+ } from "./chunk-5WKI5YMX.js";
4
4
 
5
5
  // src/index.ts
6
6
  import chalk37 from "chalk";
@@ -1559,6 +1559,14 @@ function createAnalysisService(client) {
1559
1559
  path: `/${encodeURIComponent(analysisId)}`
1560
1560
  });
1561
1561
  },
1562
+ /** The depth the platform would give the caller's next analysis if its creation named none. */
1563
+ async getDepthDefault() {
1564
+ return client.request({
1565
+ method: "GET",
1566
+ service: SERVICE2,
1567
+ path: "/depth-default"
1568
+ });
1569
+ },
1562
1570
  // ----- Public analyses: readable without signing in --------------------------------
1563
1571
  /** One page of the public analyses. `cursor` is the `nextCursor` of the page before. */
1564
1572
  async listPublic(page = {}) {
@@ -1683,6 +1691,15 @@ function createAnalysisService(client) {
1683
1691
  path: `/${encodeURIComponent(analysisId)}/sources`
1684
1692
  });
1685
1693
  },
1694
+ /** Sets whether a source is read as uploaded, rather than through the reshape its shape suggests. */
1695
+ async updateSource(analysisId, sourceId, changes) {
1696
+ return client.request({
1697
+ method: "PATCH",
1698
+ service: SERVICE2,
1699
+ path: `/${encodeURIComponent(analysisId)}/sources/${encodeURIComponent(sourceId)}`,
1700
+ body: changes
1701
+ });
1702
+ },
1686
1703
  async removeSource(analysisId, sourceId) {
1687
1704
  return client.request({
1688
1705
  method: "DELETE",
@@ -1690,6 +1707,17 @@ function createAnalysisService(client) {
1690
1707
  path: `/${encodeURIComponent(analysisId)}/sources/${encodeURIComponent(sourceId)}`
1691
1708
  });
1692
1709
  },
1710
+ /**
1711
+ * The tables of the analysis's files that do not look like one row per observation, read from their
1712
+ * first rows only. Empty when the data is as it should be.
1713
+ */
1714
+ async sourceShapes(analysisId) {
1715
+ return client.request({
1716
+ method: "GET",
1717
+ service: SERVICE2,
1718
+ path: `/${encodeURIComponent(analysisId)}/sources/shapes`
1719
+ });
1720
+ },
1693
1721
  /** What building from the sources would yield: for `recipe`, or for the platform's proposal when it is null. */
1694
1722
  async planSources(analysisId, recipe) {
1695
1723
  return client.request({
@@ -6287,7 +6315,7 @@ var HELP = [
6287
6315
  ];
6288
6316
  async function runChatRepl(options) {
6289
6317
  const { input: promptInput } = await import("@inquirer/prompts");
6290
- const { getUpdateNotice } = await import("./update-check-7F4ABBDC.js");
6318
+ const { getUpdateNotice } = await import("./update-check-RWCYYDVC.js");
6291
6319
  let sessionId = options.session;
6292
6320
  let lastReportedSession;
6293
6321
  console.log(chalk19.bold("Diafunc chat") + chalk19.dim(" \xB7 /help for commands, /quit to exit"));
@@ -7443,8 +7471,12 @@ var DEPTH_PRESETS = [
7443
7471
  { name: "Thorough", hours: "8", budget: "40000" },
7444
7472
  { name: "Deep", hours: "24", budget: "150000" }
7445
7473
  ];
7446
- var DEFAULT_HOURS = "4";
7447
- var DEFAULT_BUDGET = "10000";
7474
+ var STARTING_DEPTH_RULE = "Defaults to the account's starting depth: Express (1 hour, 500 credits) until the account has a finished analysis, Standard (4 hours, 10,000 credits) afterwards.";
7475
+ function depthOf(hours, budget) {
7476
+ const h = hours?.trim();
7477
+ const b = budget?.trim();
7478
+ return h && b ? { hours: h, budget: b } : null;
7479
+ }
7448
7480
  async function promptCreationFields(prompter, supplied, fallbackName) {
7449
7481
  const name = supplied.name ?? await prompter.input({
7450
7482
  message: "Analysis name",
@@ -7480,7 +7512,7 @@ function positiveNumber(label) {
7480
7512
  };
7481
7513
  }
7482
7514
  async function promptRunFields(prompter, options) {
7483
- const { columns } = options;
7515
+ const { columns, depthDefault } = options;
7484
7516
  const named = columns.filter((c) => c.name && c.name.length > 0);
7485
7517
  let supplied = { ...options.supplied };
7486
7518
  const nothingSupplied = supplied.targets === void 0 && supplied.segment === void 0 && supplied.questions === void 0 && supplied.hours === void 0 && supplied.budget === void 0;
@@ -7573,7 +7605,7 @@ async function promptRunFields(prompter, options) {
7573
7605
  if (hours === void 0 && budget === void 0) {
7574
7606
  const chosen = await prompter.select({
7575
7607
  message: "Depth: how long may the search run, and what may it spend?",
7576
- default: DEPTH_PRESETS.find((p) => p.name === "Standard") ?? null,
7608
+ default: matchDepthPreset(depthDefault?.hours, depthDefault?.budget) ?? void 0,
7577
7609
  choices: [
7578
7610
  ...DEPTH_PRESETS.map((p) => ({
7579
7611
  name: p.name,
@@ -7591,14 +7623,14 @@ async function promptRunFields(prompter, options) {
7591
7623
  if (hours === void 0) {
7592
7624
  hours = await prompter.input({
7593
7625
  message: "Time budget (hours)",
7594
- default: DEFAULT_HOURS,
7626
+ default: depthDefault?.hours,
7595
7627
  validate: positiveNumber("Time budget")
7596
7628
  });
7597
7629
  }
7598
7630
  if (budget === void 0) {
7599
7631
  budget = await prompter.input({
7600
7632
  message: "Credit budget",
7601
- default: DEFAULT_BUDGET,
7633
+ default: depthDefault?.budget,
7602
7634
  validate: positiveNumber("Credit budget")
7603
7635
  });
7604
7636
  }
@@ -7611,7 +7643,9 @@ async function promptRunFields(prompter, options) {
7611
7643
  };
7612
7644
  }
7613
7645
  function describePreset(preset) {
7614
- const parts = [`${preset.time || DEFAULT_HOURS}h`, `${preset.budget || DEFAULT_BUDGET} credits`];
7646
+ const parts = [];
7647
+ if (preset.time) parts.push(`${preset.time}h`);
7648
+ if (preset.budget) parts.push(`${preset.budget} credits`);
7615
7649
  if (preset.targetKeys.length > 0) parts.push(`targets: ${preset.targetKeys.join(", ")}`);
7616
7650
  if (preset.segmentKey) parts.push(`segmented by ${preset.segmentKey}`);
7617
7651
  return parts.join(" \xB7 ");
@@ -7626,11 +7660,14 @@ function summaryLines(creation, run) {
7626
7660
  if (run.questions && run.questions.length > 0) {
7627
7661
  lines.push(`Questions: ${run.questions.length}`);
7628
7662
  }
7629
- const depth = matchDepthPreset(run.hours, run.budget);
7630
- const named = depth ? `${depth.name}, ` : "";
7631
- lines.push(`Depth: ${named}${run.hours}h \xB7 ${run.budget} credits`);
7663
+ lines.push(`Depth: ${depthLabel(run)}`);
7632
7664
  return lines;
7633
7665
  }
7666
+ function depthLabel(depth) {
7667
+ const preset = matchDepthPreset(depth.hours, depth.budget);
7668
+ const named = preset ? `${preset.name}, ` : "";
7669
+ return `${named}${depth.hours}h \xB7 ${depth.budget} credits`;
7670
+ }
7634
7671
  function missingRunFields(recipe) {
7635
7672
  const missing = [];
7636
7673
  if (!recipe.hours || recipe.hours.trim().length === 0) missing.push("hours");
@@ -8026,7 +8063,8 @@ var CAUTIONS = /* @__PURE__ */ new Set([
8026
8063
  "MANY_TO_MANY",
8027
8064
  "NO_KEY",
8028
8065
  "TOO_LARGE",
8029
- "HINT_REJECTED"
8066
+ "HINT_REJECTED",
8067
+ "RESHAPE_REFUSED"
8030
8068
  ]);
8031
8069
  function recipeWithChoices(proposal, choices) {
8032
8070
  if (proposal.parts.length < 2) return null;
@@ -8053,6 +8091,50 @@ function recipeWithRowsOf(proposal, rowsOf) {
8053
8091
  hint: alternative ? `The rows can come from ${rows} or from ${alternative.parts.map((part) => part.label).join(", ")}.` : `These files have one reading: the rows come from ${rows}.`
8054
8092
  });
8055
8093
  }
8094
+ function sourcesAsUploaded(uploaded, asUploaded) {
8095
+ const chosen = [];
8096
+ for (const name of asUploaded) {
8097
+ const wanted = path7.basename(name).trim().toLowerCase();
8098
+ const matches = uploaded.filter((source) => {
8099
+ const fileName = source.fileName.trim().toLowerCase();
8100
+ return fileName === wanted || labelOf(fileName) === labelOf(wanted);
8101
+ });
8102
+ if (matches.length === 0) {
8103
+ throw new CliError(`--as-uploaded names ${name}, which is not among the files.`, {
8104
+ exitCode: EXIT_USAGE,
8105
+ hint: `The files are: ${uploaded.map((source) => source.fileName).join(", ")}.`
8106
+ });
8107
+ }
8108
+ for (const match of matches) {
8109
+ if (!chosen.includes(match)) chosen.push(match);
8110
+ }
8111
+ }
8112
+ return chosen;
8113
+ }
8114
+ function readsReshaped(recipe) {
8115
+ const parts = [...recipe.parts, ...(recipe.lookups ?? []).flatMap((lookup) => lookup.parts)];
8116
+ return parts.some((part) => (part.reshapes ?? []).length > 0);
8117
+ }
8118
+ async function reshapeSingle(api, analysisId, human) {
8119
+ let plan;
8120
+ try {
8121
+ if ((await api.analysis.sourceShapes(analysisId)).length === 0) return null;
8122
+ plan = await withStatus("Reading how the file should be read", () => api.analysis.planSources(analysisId, null));
8123
+ } catch (error) {
8124
+ if (error instanceof ApiError && error.status >= 400 && error.status < 500 && error.status !== 401 && error.status !== 403) {
8125
+ return null;
8126
+ }
8127
+ throw error;
8128
+ }
8129
+ if (!readsReshaped(plan.recipe)) return null;
8130
+ if (human) {
8131
+ for (const finding of plan.findings) {
8132
+ if (finding.kind === "RESHAPED") detail(finding.message);
8133
+ }
8134
+ hint("The reshape is a function in the analysis's project and can be changed in the Lab. To read the file exactly as it is, add --as-uploaded.");
8135
+ }
8136
+ return withStatus("Building the data from the reshaped file", () => api.analysis.buildSources(analysisId, plan.recipe));
8137
+ }
8056
8138
  function planLines(plan) {
8057
8139
  const lines = [{
8058
8140
  text: `One table of ${plan.rows.toLocaleString("en-US")} rows and ${plan.columns.toLocaleString("en-US")} columns.`,
@@ -8077,8 +8159,12 @@ async function uploadSeveral(api, analysisId, files, choices, human) {
8077
8159
  for (const earlier of await api.analysis.listSources(analysisId)) {
8078
8160
  await api.analysis.removeSource(analysisId, earlier.sourceId);
8079
8161
  }
8162
+ const uploaded = [];
8080
8163
  for (const file of files) {
8081
- await withStatus(`Uploading ${path7.basename(file)}`, () => api.analysis.addSource(analysisId, multipart(file)));
8164
+ uploaded.push(await withStatus(`Uploading ${path7.basename(file)}`, () => api.analysis.addSource(analysisId, multipart(file))));
8165
+ }
8166
+ for (const source of sourcesAsUploaded(uploaded, choices.asUploaded ?? [])) {
8167
+ await api.analysis.updateSource(analysisId, source.sourceId, { asUploaded: true });
8082
8168
  }
8083
8169
  let other = null;
8084
8170
  const plan = await withStatus("Reading the files together", async () => {
@@ -8097,6 +8183,9 @@ async function uploadSeveral(api, analysisId, files, choices, human) {
8097
8183
  if (line.caution) warn(line.text);
8098
8184
  else detail(line.text);
8099
8185
  }
8186
+ if (readsReshaped(plan.recipe)) {
8187
+ hint("A reshape is a function in the analysis's project and can be changed in the Lab. To read a file exactly as it is, add --as-uploaded <file>.");
8188
+ }
8100
8189
  if (other) {
8101
8190
  hint(`These files can be read two ways. For one row per row of ${other}, add --rows-of ${other}.`);
8102
8191
  }
@@ -8159,6 +8248,12 @@ function parseVisibility(value) {
8159
8248
  function isTerminalState(state) {
8160
8249
  return state === "COMPLETED" || state === "FAILED" || state === "CANCELLED";
8161
8250
  }
8251
+ function namedDepth(options) {
8252
+ const depth = {};
8253
+ if (options.hours?.trim()) depth.hours = options.hours.trim();
8254
+ if (options.budget?.trim()) depth.budget = options.budget.trim();
8255
+ return depth;
8256
+ }
8162
8257
  function budgetHoursOf(hours) {
8163
8258
  if (hours === null || hours === void 0) return null;
8164
8259
  const parsed = Number(hours);
@@ -8199,8 +8294,8 @@ async function runAnalysis(files, options, cmd) {
8199
8294
  if (options.targets === void 0 && p.targetKeys.length > 0) presetTargets = p.targetKeys;
8200
8295
  if (options.question === void 0 && p.questions.length > 0) options.question = [...p.questions];
8201
8296
  if (options.segment === void 0 && p.segmentKey) options.segment = p.segmentKey;
8202
- if (options.hours === void 0) options.hours = p.time;
8203
- if (options.budget === void 0) options.budget = p.budget;
8297
+ if (options.hours === void 0 && p.time?.trim()) options.hours = p.time;
8298
+ if (options.budget === void 0 && p.budget?.trim()) options.budget = p.budget;
8204
8299
  }
8205
8300
  const typedTargets = occurrences(options.targets)?.filter((entry) => entry.trim().length > 0);
8206
8301
  const targetsGiven = (typedTargets?.length ?? 0) > 0 || (presetTargets?.length ?? 0) > 0;
@@ -8226,8 +8321,7 @@ async function runAnalysis(files, options, cmd) {
8226
8321
  description: creation.description,
8227
8322
  visibility: creation.visibility,
8228
8323
  introduction: options.introduction ?? null,
8229
- hours: options.hours ?? DEFAULT_HOURS,
8230
- budget: options.budget ?? DEFAULT_BUDGET,
8324
+ ...namedDepth(options),
8231
8325
  // The targets and the segment are column names, and the columns exist only once the file is
8232
8326
  // uploaded. They are set below, read against the real header.
8233
8327
  targets: null,
@@ -8240,10 +8334,21 @@ async function runAnalysis(files, options, cmd) {
8240
8334
  return;
8241
8335
  }
8242
8336
  detail(`analysisId: ${created.analysisId}`);
8243
- await sendData(importContext(api, created.analysisId, cmd, "stream"), () => files.length > 1 ? uploadSeveral(api, created.analysisId, files, stackChoices(options), outputFormat === "human") : withStatus(
8244
- `Uploading ${path8.basename(file)}`,
8245
- () => api.analysis.uploadDataMultipart(created.analysisId, multipartFromFile(file))
8246
- ));
8337
+ const stored = depthOf(created.hours, created.budget);
8338
+ const recipe = { ...request, hours: created.hours, budget: created.budget };
8339
+ if (!interactive) {
8340
+ if (!stored) {
8341
+ throw new CliError(
8342
+ `The platform gave analysis ${created.analysisId} no depth, and ${whyNoPrompt(outputFormat, noInteractive)}.`,
8343
+ {
8344
+ exitCode: EXIT_USAGE,
8345
+ hint: `Pass --hours and --budget. Analysis ${created.analysisId} is created and holds no data yet; remove it with 'diafunc analyze delete ${created.analysisId}'.`
8346
+ }
8347
+ );
8348
+ }
8349
+ detail(`depth: ${depthLabel(stored)}${created.depthPreselection ? " (the account's starting depth)" : ""}`);
8350
+ }
8351
+ await sendData(importContext(api, created.analysisId, cmd, "stream"), () => files.length > 1 ? uploadSeveral(api, created.analysisId, files, stackChoices(options, files), outputFormat === "human") : uploadOne(api, created.analysisId, file, asUploadedOf(options.asUploaded, files), outputFormat === "human"));
8247
8352
  const columns = await readColumns(api, created.analysisId);
8248
8353
  const named = namedColumns(
8249
8354
  created.analysisId,
@@ -8251,9 +8356,9 @@ async function runAnalysis(files, options, cmd) {
8251
8356
  interactive,
8252
8357
  { typedTargets, presetTargets, segment: options.segment }
8253
8358
  );
8254
- let runHours = request.hours;
8359
+ let runHours = created.hours;
8255
8360
  if (interactive) {
8256
- const configuredHours = await configureInteractively(api, prompter, created.analysisId, request, {
8361
+ const configuredHours = await configureInteractively(api, prompter, created.analysisId, recipe, {
8257
8362
  targets: named.targets,
8258
8363
  segment: named.segment,
8259
8364
  questions: options.question === void 0 ? void 0 : questionsOf(options.question),
@@ -8264,7 +8369,7 @@ async function runAnalysis(files, options, cmd) {
8264
8369
  runHours = configuredHours;
8265
8370
  } else {
8266
8371
  await withStatus("Saving the analysis settings", () => api.analysis.update(created.analysisId, {
8267
- ...request,
8372
+ ...recipe,
8268
8373
  targets: named.targets ?? null,
8269
8374
  segment: named.segment ?? null
8270
8375
  }));
@@ -8301,10 +8406,12 @@ function namedColumns(analysisId, columns, interactive, given) {
8301
8406
  async function configureInteractively(api, prompter, analysisId, recipe, supplied, knownColumns) {
8302
8407
  const columns = knownColumns ?? await readColumns(api, analysisId);
8303
8408
  const presets = await readPresets(api);
8409
+ const depthAsked = supplied.hours === void 0 || supplied.budget === void 0;
8410
+ const depthDefault = depthAsked ? await readDepthDefault(api, recipe) : null;
8304
8411
  console.log();
8305
- const answers = await promptRunFields(prompter, { columns, presets, supplied });
8412
+ const answers = await promptRunFields(prompter, { columns, presets, supplied, depthDefault });
8306
8413
  console.log();
8307
- await withStatus("Saving the analysis settings", () => api.analysis.update(analysisId, {
8414
+ const saved = await withStatus("Saving the analysis settings", () => api.analysis.update(analysisId, {
8308
8415
  ...recipe,
8309
8416
  targets: answers.targets,
8310
8417
  questions: answers.questions,
@@ -8319,14 +8426,24 @@ async function configureInteractively(api, prompter, analysisId, recipe, supplie
8319
8426
  description: recipe.description ?? null,
8320
8427
  visibility: recipe.visibility ?? "PRIVATE"
8321
8428
  };
8322
- for (const line of summaryLines(identity, answers)) detail(line);
8429
+ const depth = depthOf(saved?.hours, saved?.budget) ?? { hours: answers.hours, budget: answers.budget };
8430
+ for (const line of summaryLines(identity, { ...answers, ...depth })) detail(line);
8323
8431
  console.log();
8324
8432
  if (!await prompter.confirm({ message: "Start the analysis?", default: true })) {
8325
8433
  warn("Not started. The analysis and these settings are saved.");
8326
8434
  hint(`Start it later with 'diafunc analyze rerun ${analysisId}'.`);
8327
8435
  return null;
8328
8436
  }
8329
- return answers.hours;
8437
+ return depth.hours;
8438
+ }
8439
+ async function readDepthDefault(api, stored) {
8440
+ try {
8441
+ const answer = await api.analysis.getDepthDefault();
8442
+ const depth = depthOf(answer?.hours, answer?.budget);
8443
+ if (depth) return depth;
8444
+ } catch {
8445
+ }
8446
+ return depthOf(stored.hours, stored.budget);
8330
8447
  }
8331
8448
  async function readColumns(api, analysisId) {
8332
8449
  for (let attempt = 0; attempt < COLUMN_READ_ATTEMPTS; attempt++) {
@@ -8638,8 +8755,7 @@ async function createAnalysis(options, cmd) {
8638
8755
  description: options.description ?? null,
8639
8756
  visibility,
8640
8757
  introduction: options.introduction ?? null,
8641
- hours: options.hours ?? null,
8642
- budget: options.budget ?? null,
8758
+ ...namedDepth(options),
8643
8759
  targets: typedColumns(options.targets),
8644
8760
  questions: questionsOf(options.question),
8645
8761
  segment: options.segment ?? null
@@ -8682,14 +8798,35 @@ async function patchColumns(analysisId, given, send, successLabel, cmd) {
8682
8798
  const columns = resolveColumnArguments(occurrences(given) ?? [], await columnNames(api, analysisId), analysisId);
8683
8799
  await patchAndPrint(analysisId, "", () => send(api, columns), successLabel, cmd);
8684
8800
  }
8685
- function stackChoices(options) {
8801
+ function collectAsUploaded(value, previous) {
8802
+ return [...Array.isArray(previous) ? previous : [], value];
8803
+ }
8804
+ var AS_UPLOADED_HELP = "Read a file exactly as it is, without the reshape its shape suggests (a column per year read as a row per year, a header over several rows, several numbers in one cell). Without a file name: every file; repeat the flag for several";
8805
+ function asUploadedOf(asUploaded, files) {
8806
+ if (asUploaded === true) return files;
8807
+ return asUploaded ?? [];
8808
+ }
8809
+ function stackChoices(options, files) {
8686
8810
  return {
8811
+ asUploaded: asUploadedOf(options.asUploaded, files),
8687
8812
  fileColumn: options.fileColumn !== false,
8688
8813
  keepDuplicates: options.keepDuplicates === true,
8689
8814
  rowsOf: options.rowsOf,
8690
8815
  planOnly: options.planOnly === true
8691
8816
  };
8692
8817
  }
8818
+ async function uploadOne(api, analysisId, file, asUploaded, human) {
8819
+ const uploaded = await withStatus(
8820
+ `Uploading ${path8.basename(file)}`,
8821
+ () => api.analysis.uploadDataMultipart(analysisId, multipartFromFile(file))
8822
+ );
8823
+ if (isDryRun() || uploaded.dataImport) return uploaded;
8824
+ if (asUploaded.length > 0) {
8825
+ sourcesAsUploaded([{ fileName: path8.basename(file) }], asUploaded);
8826
+ return uploaded;
8827
+ }
8828
+ return await reshapeSingle(api, analysisId, human) ?? uploaded;
8829
+ }
8693
8830
  async function uploadData(analysisId, files, options, cmd) {
8694
8831
  const api = createApiClient();
8695
8832
  const outputFormat = getOutputFormat15(cmd);
@@ -8701,7 +8838,7 @@ async function uploadData(analysisId, files, options, cmd) {
8701
8838
  }
8702
8839
  const built = await sendData(
8703
8840
  ctx,
8704
- () => uploadSeveral(api, analysisId, files, stackChoices(options), outputFormat === "human")
8841
+ () => uploadSeveral(api, analysisId, files, stackChoices(options, files), outputFormat === "human")
8705
8842
  );
8706
8843
  if (outputFormat !== "human") {
8707
8844
  format({
@@ -8728,10 +8865,7 @@ async function uploadData(analysisId, files, options, cmd) {
8728
8865
  throw new CliError(`File not found: ${file}`, { exitCode: EXIT_USAGE });
8729
8866
  }
8730
8867
  }
8731
- const uploaded = await sendData(ctx, () => dataUrl ? withStatus(`Uploading from ${dataUrl}`, () => api.analysis.uploadDataUrl(analysisId, { dataUrl })) : withStatus(
8732
- `Uploading ${path8.basename(file)}`,
8733
- () => api.analysis.uploadDataMultipart(analysisId, multipartFromFile(file))
8734
- ));
8868
+ const uploaded = await sendData(ctx, () => dataUrl ? withStatus(`Uploading from ${dataUrl}`, () => api.analysis.uploadDataUrl(analysisId, { dataUrl })) : uploadOne(api, analysisId, file, asUploadedOf(options.asUploaded, files), outputFormat === "human"));
8735
8869
  if (isDryRun()) {
8736
8870
  hint("Dry run: nothing was uploaded.");
8737
8871
  return;
@@ -8940,7 +9074,7 @@ var COLUMN_LIST_HELP = "one argument each or comma-separated; a name that contai
8940
9074
  var TARGETS_HELP = `Target column names: repeat the flag or separate them with commas; a name that contains a comma is one flag of its own, or goes in double quotes inside a list`;
8941
9075
  function registerAnalyzeCommand(program) {
8942
9076
  const analyze = program.command("analyze").description("Run and manage automatic analyses");
8943
- analyze.command("run", { isDefault: true }).description("Create an analysis from a data file, configure it and run it (the default: `analyze <file>`)").argument("[files...]", "Data file to analyze (CSV, Excel and more than 45 file formats; see `table import-formats`). Several files are combined into one table: files with the same columns are stacked, a file that shares a key adds its columns").option("--name <name>", "Analysis name (asked for, or derived from the filename)").option("--description <text>", "Analysis description").option("--visibility <vis>", "PRIVATE or PUBLIC (default: PRIVATE)").option("--hours <hours>", `Time budget (hours). Default ${DEFAULT_HOURS}, the Standard preset; a saved preset applies when omitted`).option("--budget <credits>", `Credit budget. Default ${Number(DEFAULT_BUDGET).toLocaleString("en-US")}, the Standard preset; a saved preset applies when omitted`).option("--targets <columns>", `${TARGETS_HELP} (required when not interactive)`, collectColumns).option("--question <text>", "A question for the analysis to answer; repeat the flag for several", collectQuestion).option("--segment <name>", "Column to segment the analysis by").option("--introduction <markdown>", "Markdown introduction shown at the top of the notebook").option("--preset <id>", "Apply a saved preset as defaults (explicit flags override it)").option("--no-file-column", "With several files: do not add the column that records the file each row came from").option("--keep-duplicates", "With several files: keep rows that occur in more than one file").option("--rows-of <file>", "With several files that can be read two ways: the file in which one row is one observation").action(async (files, options, cmd) => {
9077
+ analyze.command("run", { isDefault: true }).description("Create an analysis from a data file, configure it and run it (the default: `analyze <file>`)").argument("[files...]", "Data file to analyze (CSV, Excel and more than 45 file formats; see `table import-formats`). Several files are combined into one table: files with the same columns are stacked, a file that shares a key adds its columns").option("--name <name>", "Analysis name (asked for, or derived from the filename)").option("--description <text>", "Analysis description").option("--visibility <vis>", "PRIVATE or PUBLIC (default: PRIVATE)").option("--hours <hours>", `Time budget (hours). ${STARTING_DEPTH_RULE}`).option("--budget <credits>", `Credit budget. ${STARTING_DEPTH_RULE}`).option("--targets <columns>", `${TARGETS_HELP} (required when not interactive)`, collectColumns).option("--question <text>", "A question for the analysis to answer; repeat the flag for several", collectQuestion).option("--segment <name>", "Column to segment the analysis by").option("--introduction <markdown>", "Markdown introduction shown at the top of the notebook").option("--preset <id>", "Apply a saved preset as defaults (explicit flags override it)").option("--no-file-column", "With several files: do not add the column that records the file each row came from").option("--keep-duplicates", "With several files: keep rows that occur in more than one file").option("--rows-of <file>", "With several files that can be read two ways: the file in which one row is one observation").option("--as-uploaded [file]", AS_UPLOADED_HELP, collectAsUploaded).action(async (files, options, cmd) => {
8944
9078
  try {
8945
9079
  if (files.length === 0) {
8946
9080
  analyze.help();
@@ -8986,7 +9120,7 @@ function registerAnalyzeCommand(program) {
8986
9120
  reportCommandError(error);
8987
9121
  }
8988
9122
  });
8989
- analyze.command("create").description("Create an analysis without uploading data or running it").option("--name <name>", "Analysis name").option("--description <text>", "Analysis description").option("--visibility <vis>", "PRIVATE or PUBLIC", "PRIVATE").option("--hours <hours>", "Time budget (hours)").option("--budget <credits>", "Credit budget").option("--targets <columns>", TARGETS_HELP, collectColumns).option("--question <text>", "A question for the analysis to answer; repeat the flag for several", collectQuestion).option("--segment <name>", "Column to segment the analysis by").option("--introduction <markdown>", "Markdown introduction shown at the top of the notebook").action(async (options, cmd) => {
9123
+ analyze.command("create").description("Create an analysis without uploading data or running it").option("--name <name>", "Analysis name").option("--description <text>", "Analysis description").option("--visibility <vis>", "PRIVATE or PUBLIC", "PRIVATE").option("--hours <hours>", `Time budget (hours). ${STARTING_DEPTH_RULE}`).option("--budget <credits>", `Credit budget. ${STARTING_DEPTH_RULE}`).option("--targets <columns>", TARGETS_HELP, collectColumns).option("--question <text>", "A question for the analysis to answer; repeat the flag for several", collectQuestion).option("--segment <name>", "Column to segment the analysis by").option("--introduction <markdown>", "Markdown introduction shown at the top of the notebook").action(async (options, cmd) => {
8990
9124
  try {
8991
9125
  await createAnalysis(options, cmd);
8992
9126
  } catch (error) {
@@ -9148,7 +9282,7 @@ function registerAnalyzeCommand(program) {
9148
9282
  handleError(error);
9149
9283
  }
9150
9284
  });
9151
- analyze.command("upload").description("Replace the analysis data with a new file (any supported format; see `table import-formats`). An import that takes long is followed until it has finished").argument("<id>", "Analysis ID").argument("[files...]", "Data file to upload (CSV, Excel and more than 45 file formats; see `table import-formats`). Several files are combined into one table: files with the same columns are stacked, a file that shares a key adds its columns").option("--url <url>", "HTTPS URL to fetch the data file from, instead of a file path").option("--no-file-column", "With several files: do not add the column that records the file each row came from").option("--keep-duplicates", "With several files: keep rows that occur in more than one file").option("--rows-of <file>", "With several files that can be read two ways: the file in which one row is one observation").option("--plan-only", "With several files: store them and print how they fit together, without building the table").action(async (id, files, options, cmd) => {
9285
+ analyze.command("upload").description("Replace the analysis data with a new file (any supported format; see `table import-formats`). An import that takes long is followed until it has finished").argument("<id>", "Analysis ID").argument("[files...]", "Data file to upload (CSV, Excel and more than 45 file formats; see `table import-formats`). Several files are combined into one table: files with the same columns are stacked, a file that shares a key adds its columns").option("--url <url>", "HTTPS URL to fetch the data file from, instead of a file path").option("--no-file-column", "With several files: do not add the column that records the file each row came from").option("--keep-duplicates", "With several files: keep rows that occur in more than one file").option("--rows-of <file>", "With several files that can be read two ways: the file in which one row is one observation").option("--as-uploaded [file]", AS_UPLOADED_HELP, collectAsUploaded).option("--plan-only", "With several files: store them and print how they fit together, without building the table").action(async (id, files, options, cmd) => {
9152
9286
  try {
9153
9287
  await uploadData(id, files, options, cmd);
9154
9288
  } catch (error) {
@@ -10659,7 +10793,7 @@ function registerShellCommand(program) {
10659
10793
  });
10660
10794
  const api = createApiClient();
10661
10795
  const { input: promptInput } = await import("@inquirer/prompts");
10662
- const { getUpdateNotice } = await import("./update-check-7F4ABBDC.js");
10796
+ const { getUpdateNotice } = await import("./update-check-RWCYYDVC.js");
10663
10797
  const resolvedLanguage = await resolveLanguage(api, fnRef.projectId, options.language);
10664
10798
  console.log(chalk32.bold("Diafunc shell") + chalk32.dim(` \xB7 function ${fnRef.entityId} \xB7 ${resolvedLanguage}`));
10665
10799
  console.log(chalk32.dim(`Endpoint: ${config.profiles[config.currentProfile]?.endpoint}`));
@@ -11709,4 +11843,4 @@ export {
11709
11843
  PromptCancelled,
11710
11844
  createProgram
11711
11845
  };
11712
- //# sourceMappingURL=chunk-D7AJH4Y3.js.map
11846
+ //# sourceMappingURL=chunk-LEDCBZ3S.js.map