@diafunc/cli 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.
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  package_default
3
- } from "./chunk-H5CNMAQX.js";
3
+ } from "./chunk-BQ453MK3.js";
4
4
 
5
5
  // src/index.ts
6
6
  import { Command } from "commander";
@@ -989,6 +989,30 @@ var PRESETS_SERVICE = "analysis-presets";
989
989
  var TRIGGERS_SERVICE = "triggers";
990
990
  function createAnalysisService(client) {
991
991
  return {
992
+ // ----- Lifecycle: create / read / replace / delete --------------------------------
993
+ async create(request) {
994
+ return client.request({
995
+ method: "POST",
996
+ service: SERVICE2,
997
+ path: "/",
998
+ body: request
999
+ });
1000
+ },
1001
+ async update(analysisId, request) {
1002
+ return client.request({
1003
+ method: "PUT",
1004
+ service: SERVICE2,
1005
+ path: `/${encodeURIComponent(analysisId)}`,
1006
+ body: request
1007
+ });
1008
+ },
1009
+ async delete(analysisId) {
1010
+ return client.request({
1011
+ method: "DELETE",
1012
+ service: SERVICE2,
1013
+ path: `/${encodeURIComponent(analysisId)}`
1014
+ });
1015
+ },
992
1016
  async getLast() {
993
1017
  return client.request({
994
1018
  method: "GET",
@@ -1011,34 +1035,120 @@ function createAnalysisService(client) {
1011
1035
  path: `/${encodeURIComponent(analysisId)}`
1012
1036
  });
1013
1037
  },
1014
- async save(analysis) {
1038
+ // ----- Typed PATCH per editable field --------------------------------------------
1039
+ async patchName(analysisId, request) {
1040
+ return client.request({
1041
+ method: "PATCH",
1042
+ service: SERVICE2,
1043
+ path: `/${encodeURIComponent(analysisId)}/name`,
1044
+ body: request
1045
+ });
1046
+ },
1047
+ async patchDescription(analysisId, request) {
1048
+ return client.request({
1049
+ method: "PATCH",
1050
+ service: SERVICE2,
1051
+ path: `/${encodeURIComponent(analysisId)}/description`,
1052
+ body: request
1053
+ });
1054
+ },
1055
+ async patchVisibility(analysisId, request) {
1056
+ return client.request({
1057
+ method: "PATCH",
1058
+ service: SERVICE2,
1059
+ path: `/${encodeURIComponent(analysisId)}/visibility`,
1060
+ body: request
1061
+ });
1062
+ },
1063
+ async patchIntroduction(analysisId, request) {
1064
+ return client.request({
1065
+ method: "PATCH",
1066
+ service: SERVICE2,
1067
+ path: `/${encodeURIComponent(analysisId)}/introduction`,
1068
+ body: request
1069
+ });
1070
+ },
1071
+ async patchHours(analysisId, request) {
1072
+ return client.request({
1073
+ method: "PATCH",
1074
+ service: SERVICE2,
1075
+ path: `/${encodeURIComponent(analysisId)}/hours`,
1076
+ body: request
1077
+ });
1078
+ },
1079
+ async patchBudget(analysisId, request) {
1080
+ return client.request({
1081
+ method: "PATCH",
1082
+ service: SERVICE2,
1083
+ path: `/${encodeURIComponent(analysisId)}/budget`,
1084
+ body: request
1085
+ });
1086
+ },
1087
+ async patchTargets(analysisId, request) {
1088
+ return client.request({
1089
+ method: "PATCH",
1090
+ service: SERVICE2,
1091
+ path: `/${encodeURIComponent(analysisId)}/targets`,
1092
+ body: request
1093
+ });
1094
+ },
1095
+ async patchQuestions(analysisId, request) {
1096
+ return client.request({
1097
+ method: "PATCH",
1098
+ service: SERVICE2,
1099
+ path: `/${encodeURIComponent(analysisId)}/questions`,
1100
+ body: request
1101
+ });
1102
+ },
1103
+ async patchSegment(analysisId, request) {
1104
+ return client.request({
1105
+ method: "PATCH",
1106
+ service: SERVICE2,
1107
+ path: `/${encodeURIComponent(analysisId)}/segment`,
1108
+ body: request
1109
+ });
1110
+ },
1111
+ // ----- Data ingest ----------------------------------------------------------------
1112
+ async uploadDataMultipart(analysisId, formData) {
1015
1113
  return client.request({
1016
1114
  method: "POST",
1017
1115
  service: SERVICE2,
1018
- path: "/",
1019
- body: analysis
1116
+ path: `/${encodeURIComponent(analysisId)}/data`,
1117
+ rawBody: formData
1118
+ });
1119
+ },
1120
+ async uploadDataUrl(analysisId, request) {
1121
+ return client.request({
1122
+ method: "POST",
1123
+ service: SERVICE2,
1124
+ path: `/${encodeURIComponent(analysisId)}/data/url`,
1125
+ body: request
1020
1126
  });
1021
1127
  },
1022
- /**
1023
- * Combined create-and-run in one round-trip. Body is a fresh recipe (analysisId
1024
- * must be null); server saves it and queues a run. Returns AnalysisRun with
1025
- * analysisId populated. Preferred over save+rerun for one-shot tools.
1026
- */
1027
- async createAndRun(analysis) {
1128
+ async uploadDataInline(analysisId, request) {
1028
1129
  return client.request({
1029
1130
  method: "POST",
1030
1131
  service: SERVICE2,
1031
- path: "/runs",
1032
- body: analysis
1132
+ path: `/${encodeURIComponent(analysisId)}/data/inline`,
1133
+ body: request
1134
+ });
1135
+ },
1136
+ async getColumns(analysisId) {
1137
+ return client.request({
1138
+ method: "GET",
1139
+ service: SERVICE2,
1140
+ path: `/${encodeURIComponent(analysisId)}/columns`
1141
+ });
1142
+ },
1143
+ async getNavigation(analysisId) {
1144
+ return client.request({
1145
+ method: "GET",
1146
+ service: SERVICE2,
1147
+ path: `/${encodeURIComponent(analysisId)}/navigation`
1033
1148
  });
1034
1149
  },
1035
- /**
1036
- * Enqueues a new run for an existing analysis recipe. Returns the newly created
1037
- * run in state QUEUED; the dispatcher pool picks it up within ~5s and transitions
1038
- * it through DISPATCHING -> RUNNING -> COMPLETED / FAILED. Poll getRun(runId) to
1039
- * follow progress.
1040
- */
1041
- async rerun(analysisId) {
1150
+ // ----- Runs -----------------------------------------------------------------------
1151
+ async runAnalysis(analysisId) {
1042
1152
  return client.request({
1043
1153
  method: "POST",
1044
1154
  service: SERVICE2,
@@ -1067,7 +1177,14 @@ function createAnalysisService(client) {
1067
1177
  path: `/${encodeURIComponent(runId)}/cancel`
1068
1178
  });
1069
1179
  },
1070
- // ---------- presets ----------
1180
+ async getRunOutputs(analysisId, runId) {
1181
+ return client.request({
1182
+ method: "GET",
1183
+ service: SERVICE2,
1184
+ path: `/${encodeURIComponent(analysisId)}/runs/${encodeURIComponent(runId)}/outputs`
1185
+ });
1186
+ },
1187
+ // ----- Presets --------------------------------------------------------------------
1071
1188
  async getPresets() {
1072
1189
  return client.request({
1073
1190
  method: "GET",
@@ -1097,7 +1214,7 @@ function createAnalysisService(client) {
1097
1214
  path: `/${encodeURIComponent(presetId)}`
1098
1215
  });
1099
1216
  },
1100
- // ---------- triggers ----------
1217
+ // ----- Triggers -------------------------------------------------------------------
1101
1218
  async createTrigger(analysisId, body) {
1102
1219
  return client.request({
1103
1220
  method: "POST",
@@ -3576,7 +3693,7 @@ Error: ${event.content}`));
3576
3693
  }
3577
3694
  async function runChatRepl(options) {
3578
3695
  const { input: promptInput } = await import("@inquirer/prompts");
3579
- const { getUpdateNotice } = await import("./update-check-5JBBCRL3.js");
3696
+ const { getUpdateNotice } = await import("./update-check-BCZ3WECC.js");
3580
3697
  let sessionId = options.session;
3581
3698
  console.log(chalk17.bold("Diafunc chat") + chalk17.dim(" \xB7 /help for commands, /quit to exit"));
3582
3699
  if (sessionId) {
@@ -4316,54 +4433,6 @@ import chalk23 from "chalk";
4316
4433
  import * as fs6 from "fs";
4317
4434
  import * as path5 from "path";
4318
4435
  import { spawn as spawn2 } from "child_process";
4319
- import { randomUUID as randomUUID3 } from "crypto";
4320
- function createEntity(projectId, entityId, entityType, name, description, attributes, tags, contentType, content) {
4321
- const now = Date.now();
4322
- const entity = {
4323
- projectId,
4324
- projectBranch: "main",
4325
- entityId,
4326
- entityBranch: "main",
4327
- head: true,
4328
- version: 1,
4329
- type: entityType,
4330
- attributes: {},
4331
- attributeTypes: {},
4332
- metaAttributes: {},
4333
- metaAttributeTypes: {},
4334
- tags,
4335
- modified: now,
4336
- created: now,
4337
- versioned: false,
4338
- versionTtl: null,
4339
- retain: false,
4340
- contentAvailable: content !== null,
4341
- contentLoaded: content !== null,
4342
- contentType,
4343
- contentSize: null,
4344
- content
4345
- };
4346
- if (name !== null) {
4347
- entity.attributeTypes["name"] = "text";
4348
- entity.attributes["name"] = name;
4349
- }
4350
- if (description !== null) {
4351
- entity.attributeTypes["description"] = "text";
4352
- entity.attributes["description"] = description;
4353
- }
4354
- if (attributes) {
4355
- for (const [key, value] of Object.entries(attributes)) {
4356
- if (typeof value === "string") {
4357
- entity.attributeTypes[key] = "text";
4358
- entity.attributes[key] = value;
4359
- } else if (typeof value === "number") {
4360
- entity.attributeTypes[key] = "integer";
4361
- entity.attributes[key] = String(value);
4362
- }
4363
- }
4364
- }
4365
- return entity;
4366
- }
4367
4436
  function formatDuration(ms) {
4368
4437
  const seconds = Math.floor(ms / 1e3);
4369
4438
  const minutes = Math.floor(seconds / 60);
@@ -4372,9 +4441,6 @@ function formatDuration(ms) {
4372
4441
  if (minutes > 0) return `${minutes}m ${seconds % 60}s`;
4373
4442
  return `${seconds}s`;
4374
4443
  }
4375
- function analysisUrl(analysis, endpoint) {
4376
- return `${endpoint}/lab/${analysis.projectId}/main/entities/${analysis.notebookId}/main`;
4377
- }
4378
4444
  function openUrl(url) {
4379
4445
  const cmd = process.platform === "darwin" ? "open" : process.platform === "win32" ? "cmd" : "xdg-open";
4380
4446
  const args = process.platform === "win32" ? ["/c", "start", '""', url] : [url];
@@ -4389,125 +4455,62 @@ function parseCsv(value) {
4389
4455
  if (value === void 0) return null;
4390
4456
  return value.split(",").map((s) => s.trim()).filter((s) => s.length > 0);
4391
4457
  }
4458
+ function parseVisibility(value) {
4459
+ const upper = value.toUpperCase();
4460
+ if (upper !== "PRIVATE" && upper !== "PUBLIC") {
4461
+ throw new Error(`Invalid visibility "${value}" \u2014 must be PRIVATE or PUBLIC.`);
4462
+ }
4463
+ return upper;
4464
+ }
4392
4465
  function isTerminalState(state) {
4393
4466
  return state === "COMPLETED" || state === "FAILED" || state === "CANCELLED";
4394
4467
  }
4468
+ function multipartFromFile(file) {
4469
+ const buffer = fs6.readFileSync(file);
4470
+ const blob = new Blob([buffer]);
4471
+ const formData = new FormData();
4472
+ formData.append("content", blob, path5.basename(file));
4473
+ return formData;
4474
+ }
4395
4475
  async function runAnalysis(file, options, cmd) {
4396
4476
  if (!fs6.existsSync(file)) {
4397
4477
  console.error(chalk23.red(`File not found: ${file}`));
4398
4478
  process.exit(1);
4399
4479
  }
4400
4480
  const api = createApiClient();
4401
- const projectName = options.name ?? path5.basename(file, path5.extname(file));
4402
- const visibility = options.visibility.toUpperCase();
4403
- const recipe = {
4404
- userId: null,
4405
- analysisId: null,
4406
- phase: "PREPARATION",
4407
- step: "LAUNCH_ANALYSIS",
4408
- projectName,
4409
- projectDescription: options.description,
4481
+ const visibility = parseVisibility(options.visibility);
4482
+ const name = options.name ?? path5.basename(file, path5.extname(file));
4483
+ const request = {
4484
+ name,
4485
+ description: options.description || null,
4410
4486
  visibility,
4411
- time: options.time,
4487
+ introduction: options.introduction ?? null,
4488
+ hours: options.hours,
4412
4489
  budget: options.budget,
4413
- projectId: null,
4414
- notebookId: null,
4415
- rawDataTableId: null,
4416
- analysisFunctionId: null,
4417
- analysisChapterId: null,
4418
- year: null,
4419
- month: null,
4420
- day: null,
4421
- hour: null,
4422
- evaluationId: null,
4423
- started: null,
4424
- targetKeys: parseCsv(options.targets),
4490
+ targets: parseCsv(options.targets),
4425
4491
  questions: parseCsv(options.questions),
4426
- segmentKey: options.segment ?? null
4492
+ segment: options.segment ?? null
4427
4493
  };
4428
- process.stdout.write(`Creating project "${projectName}" ...`);
4429
- const { projectId, rawDataTableId } = await provisionProject(api, recipe);
4430
- recipe.projectId = projectId;
4431
- recipe.rawDataTableId = rawDataTableId;
4494
+ process.stdout.write(`Creating analysis "${name}" ...`);
4495
+ const created = await api.analysis.create(request);
4432
4496
  console.log(chalk23.green(" done"));
4433
- process.stdout.write(`Importing ${path5.basename(file)} ...`);
4434
- await importData(api, projectId, rawDataTableId, file);
4497
+ console.log(chalk23.dim(` analysisId: ${created.analysisId}`));
4498
+ process.stdout.write(`Uploading ${path5.basename(file)} ...`);
4499
+ await api.analysis.uploadDataMultipart(created.analysisId, multipartFromFile(file));
4435
4500
  console.log(chalk23.green(" done"));
4436
4501
  process.stdout.write("Queuing analysis run ...");
4437
- const run = await api.analysis.createAndRun(recipe);
4502
+ const run = await api.analysis.runAnalysis(created.analysisId);
4438
4503
  console.log(chalk23.green(" done"));
4439
- console.log(chalk23.dim(` analysisId: ${run.analysisId}`));
4440
4504
  console.log(chalk23.dim(` runId: ${run.runId}`));
4441
4505
  console.log();
4442
- await monitorRun(api, run.runId, recipe, cmd);
4443
- }
4444
- async function provisionProject(api, recipe) {
4445
- const project = await api.admin.createProject({
4446
- visibility: recipe.visibility,
4447
- language: "Java",
4448
- active: true
4449
- });
4450
- await api.storage.createProjectBranch({
4451
- projectId: project.projectId,
4452
- sourceProjectBranch: null,
4453
- targetProjectBranch: "main"
4454
- });
4455
- const projectEntity = createEntity(
4456
- project.projectId,
4457
- project.projectId,
4458
- "project",
4459
- recipe.projectName,
4460
- recipe.projectDescription,
4461
- null,
4462
- [],
4463
- null,
4464
- null
4465
- );
4466
- await api.storage.saveEntities([projectEntity]);
4467
- const rawDataTableId = randomUUID3();
4468
- const rawDataTable = createEntity(
4469
- project.projectId,
4470
- rawDataTableId,
4471
- "table",
4472
- "Raw Data Table",
4473
- null,
4474
- null,
4475
- [],
4476
- null,
4477
- null
4478
- );
4479
- await api.storage.saveEntities([rawDataTable]);
4480
- return { projectId: project.projectId, rawDataTableId };
4481
- }
4482
- async function importData(api, projectId, rawDataTableId, file) {
4483
- const ref = {
4484
- projectId,
4485
- projectBranch: "main",
4486
- entityId: rawDataTableId,
4487
- entityBranch: "main"
4488
- };
4489
- const fileBuffer = fs6.readFileSync(file);
4490
- const blob = new Blob([fileBuffer]);
4491
- const formData = new FormData();
4492
- formData.append("content", blob, path5.basename(file));
4493
- const importId = await api.storage.importTable(ref, formData, true);
4494
- for (let i = 0; i < 300; i++) {
4495
- await new Promise((resolve) => setTimeout(resolve, 1e3));
4496
- const imp = await api.storage.getImport(ref, importId);
4497
- if (imp.finished !== null) {
4498
- if (!imp.succeeded) throw new Error(`Import failed: ${imp.error}`);
4499
- return;
4500
- }
4501
- }
4502
- throw new Error("Import did not finish within 5 minutes");
4506
+ await monitorRun(api, created.analysisId, run.runId, parseFloat(options.hours), cmd);
4503
4507
  }
4504
- async function monitorRun(api, runId, recipe, cmd) {
4508
+ async function monitorRun(api, analysisId, runId, hoursForProgress, cmd) {
4505
4509
  const config = loadConfig();
4506
4510
  const outputFormat = getOutputFormat14(cmd);
4507
- const computationMs = parseFloat(recipe.time) * 60 * 60 * 1e3;
4511
+ const computationMs = hoursForProgress * 60 * 60 * 1e3;
4508
4512
  const startMs = Date.now();
4509
4513
  const seenOutputIds = /* @__PURE__ */ new Set();
4510
- let observedAnalysisId = recipe.analysisId;
4511
4514
  for (let i = 0; ; i++) {
4512
4515
  await new Promise((resolve) => setTimeout(resolve, 2e3));
4513
4516
  let run = null;
@@ -4517,20 +4520,17 @@ async function monitorRun(api, runId, recipe, cmd) {
4517
4520
  } catch {
4518
4521
  }
4519
4522
  if (!run) continue;
4520
- if (run.analysisId) observedAnalysisId = run.analysisId;
4521
- if (run.evaluationId && recipe.projectId) {
4522
- try {
4523
- const outputs = await api.evaluation.getOutputs(recipe.projectId, run.evaluationId);
4524
- for (const out of outputs) {
4525
- if (!seenOutputIds.has(out.outputId)) {
4526
- seenOutputIds.add(out.outputId);
4527
- if (outputFormat === "human") {
4528
- console.log(` ${chalk23.dim("Output:")} ${out.output}`);
4529
- }
4523
+ try {
4524
+ const outputs = await api.analysis.getRunOutputs(analysisId, runId);
4525
+ for (const out of outputs) {
4526
+ if (!seenOutputIds.has(out.outputId)) {
4527
+ seenOutputIds.add(out.outputId);
4528
+ if (outputFormat === "human") {
4529
+ console.log(` ${chalk23.dim("Output:")} ${out.output}`);
4530
4530
  }
4531
4531
  }
4532
- } catch {
4533
4532
  }
4533
+ } catch {
4534
4534
  }
4535
4535
  if (isTerminalState(run.state)) {
4536
4536
  console.log();
@@ -4540,42 +4540,27 @@ async function monitorRun(api, runId, recipe, cmd) {
4540
4540
  if (run.state === "COMPLETED") {
4541
4541
  if (outputFormat === "human") {
4542
4542
  console.log(chalk23.green(`Analysis complete! (${durationStr})`));
4543
- if (observedAnalysisId) {
4544
- try {
4545
- const opt = await api.analysis.get(observedAnalysisId);
4546
- if (opt.analysis?.notebookId) {
4547
- const endpoint = config.profiles[config.currentProfile]?.endpoint ?? "https://diafunc.com";
4548
- console.log(` Project: ${analysisUrl(opt.analysis, endpoint)}`);
4549
- }
4550
- } catch {
4551
- }
4543
+ try {
4544
+ const nav = await api.analysis.getNavigation(analysisId);
4545
+ const endpoint = config.profiles[config.currentProfile]?.endpoint ?? "https://diafunc.com";
4546
+ console.log(` Project: ${endpoint}${nav.labUrl}`);
4547
+ } catch {
4552
4548
  }
4553
4549
  } else {
4554
- format({
4555
- status: "completed",
4556
- runId,
4557
- analysisId: observedAnalysisId,
4558
- duration,
4559
- projectId: recipe.projectId
4560
- }, { format: outputFormat });
4550
+ format({ status: "completed", runId, analysisId, duration }, { format: outputFormat });
4561
4551
  }
4562
4552
  } else if (run.state === "CANCELLED") {
4563
4553
  if (outputFormat === "human") {
4564
4554
  console.log(chalk23.yellow("Analysis cancelled."));
4565
4555
  } else {
4566
- format({ status: "cancelled", runId, analysisId: observedAnalysisId }, { format: outputFormat });
4556
+ format({ status: "cancelled", runId, analysisId }, { format: outputFormat });
4567
4557
  }
4568
4558
  } else {
4569
4559
  if (outputFormat === "human") {
4570
4560
  console.log(chalk23.red("Analysis failed."));
4571
4561
  if (run.errorMessage) console.log(` Error: ${run.errorMessage}`);
4572
4562
  } else {
4573
- format({
4574
- status: "failed",
4575
- runId,
4576
- analysisId: observedAnalysisId,
4577
- error: run.errorMessage
4578
- }, { format: outputFormat });
4563
+ format({ status: "failed", runId, analysisId, error: run.errorMessage }, { format: outputFormat });
4579
4564
  }
4580
4565
  }
4581
4566
  return;
@@ -4595,17 +4580,18 @@ async function listAnalyses(limit, cmd) {
4595
4580
  const outputFormat = getOutputFormat14(cmd);
4596
4581
  const api = createApiClient();
4597
4582
  const analyses = await api.analysis.getRecent(limit);
4598
- const rows = analyses.map((a) => ({
4599
- analysisId: a.analysisId ?? "\u2014",
4600
- projectName: a.projectName ?? "\u2014",
4601
- projectId: a.projectId ?? "\u2014",
4602
- phase: a.phase,
4603
- step: a.step,
4604
- started: a.started ? new Date(a.started).toISOString() : "\u2014"
4605
- }));
4606
- format(rows, {
4583
+ format(analyses.map((a) => ({
4584
+ analysisId: a.analysisId,
4585
+ name: a.name,
4586
+ visibility: a.visibility,
4587
+ hours: a.hours,
4588
+ budget: a.budget,
4589
+ targets: (a.targets ?? []).join(", "),
4590
+ latestRunState: a.latestRunState ?? "\u2014",
4591
+ createdAt: a.createdAt ?? "\u2014"
4592
+ })), {
4607
4593
  format: outputFormat,
4608
- columns: ["analysisId", "projectName", "phase", "step", "started"]
4594
+ columns: ["analysisId", "name", "visibility", "hours", "budget", "targets", "latestRunState", "createdAt"]
4609
4595
  });
4610
4596
  }
4611
4597
  async function getAnalysisDetails(analysisId, cmd) {
@@ -4626,10 +4612,6 @@ async function watchAnalysis(analysisId, cmd) {
4626
4612
  return;
4627
4613
  }
4628
4614
  const recipe = result.analysis;
4629
- if (!recipe.analysisId) {
4630
- console.log(chalk23.dim("Analysis has no analysisId yet."));
4631
- return;
4632
- }
4633
4615
  const runs = await api.analysis.getRunsForAnalysis(recipe.analysisId, 1);
4634
4616
  if (runs.length === 0) {
4635
4617
  console.log(chalk23.dim("No runs for this analysis."));
@@ -4638,102 +4620,123 @@ async function watchAnalysis(analysisId, cmd) {
4638
4620
  const latest = runs[0];
4639
4621
  if (isTerminalState(latest.state)) {
4640
4622
  console.log(chalk23.green(`Latest run already in terminal state: ${latest.state}`));
4641
- if (recipe.projectId && recipe.notebookId) {
4623
+ try {
4624
+ const nav = await api.analysis.getNavigation(recipe.analysisId);
4642
4625
  const config = loadConfig();
4643
4626
  const endpoint = config.profiles[config.currentProfile]?.endpoint ?? "https://diafunc.com";
4644
- console.log(` Project: ${analysisUrl(recipe, endpoint)}`);
4627
+ console.log(` Project: ${endpoint}${nav.labUrl}`);
4628
+ } catch {
4645
4629
  }
4646
4630
  return;
4647
4631
  }
4648
4632
  console.log(`Watching run ${latest.runId} for analysis ${recipe.analysisId} ...`);
4649
- await monitorRun(api, latest.runId, recipe, cmd);
4633
+ await monitorRun(api, recipe.analysisId, latest.runId, parseFloat(recipe.hours), cmd);
4650
4634
  }
4651
4635
  async function rerunAnalysis(analysisId) {
4652
4636
  const api = createApiClient();
4653
- const run = await api.analysis.rerun(analysisId);
4637
+ const run = await api.analysis.runAnalysis(analysisId);
4654
4638
  console.log(chalk23.green(`\u2713 Queued new run ${run.runId} for analysis ${analysisId}`));
4655
4639
  console.log(chalk23.dim(` State: ${run.state}`));
4656
4640
  console.log();
4657
- console.log(chalk23.dim("The dispatcher picks up queued runs every few seconds."));
4658
- console.log(chalk23.dim(`Track progress: diafunc analyze watch ${analysisId}`));
4641
+ console.log(chalk23.dim("Track progress: diafunc analyze watch " + analysisId));
4659
4642
  }
4660
4643
  async function openAnalysis(analysisId) {
4661
4644
  const api = createApiClient();
4662
4645
  const result = analysisId ? await api.analysis.get(analysisId) : await api.analysis.getLast();
4663
- if (!result.analysis?.projectId) {
4664
- console.log(chalk23.dim("No analysis found (or analysis has no project yet)."));
4646
+ if (!result.analysis) {
4647
+ console.log(chalk23.dim("No analysis found."));
4665
4648
  return;
4666
4649
  }
4667
4650
  const config = loadConfig();
4668
4651
  const endpoint = config.profiles[config.currentProfile]?.endpoint ?? "https://diafunc.com";
4669
- const url = analysisUrl(result.analysis, endpoint);
4670
- console.log(`Opening ${url} ...`);
4671
- openUrl(url);
4652
+ try {
4653
+ const nav = await api.analysis.getNavigation(result.analysis.analysisId);
4654
+ const url = `${endpoint}${nav.labUrl}`;
4655
+ console.log(`Opening ${url} ...`);
4656
+ openUrl(url);
4657
+ } catch {
4658
+ console.log(chalk23.dim("Notebook not yet provisioned \u2014 run the analysis first."));
4659
+ }
4672
4660
  }
4673
4661
  async function createRecipe(options, cmd) {
4674
4662
  const outputFormat = getOutputFormat14(cmd);
4675
4663
  const api = createApiClient();
4676
- const visibility = options.visibility.toUpperCase();
4677
- const recipe = {
4678
- userId: null,
4679
- analysisId: null,
4680
- phase: "PREPARATION",
4681
- step: "LAUNCH_ANALYSIS",
4682
- projectName: options.name ?? "CLI Analysis",
4683
- projectDescription: options.description ?? "",
4664
+ const visibility = parseVisibility(options.visibility);
4665
+ const request = {
4666
+ name: options.name ?? "CLI Analysis",
4667
+ description: options.description ?? null,
4684
4668
  visibility,
4685
- time: options.hours,
4686
- budget: options.budget,
4687
- projectId: options.projectId,
4688
- notebookId: null,
4689
- rawDataTableId: options.rawDataTableId,
4690
- analysisFunctionId: null,
4691
- analysisChapterId: null,
4692
- year: null,
4693
- month: null,
4694
- day: null,
4695
- hour: null,
4696
- evaluationId: null,
4697
- started: null,
4698
- targetKeys: parseCsv(options.targets),
4669
+ introduction: options.introduction ?? null,
4670
+ hours: options.hours ?? null,
4671
+ budget: options.budget ?? null,
4672
+ targets: parseCsv(options.targets),
4699
4673
  questions: parseCsv(options.questions),
4700
- segmentKey: options.segment ?? null
4674
+ segment: options.segment ?? null
4701
4675
  };
4702
- const saved = await api.analysis.save(recipe);
4703
- format(saved, { format: outputFormat });
4676
+ const created = await api.analysis.create(request);
4677
+ format(created, { format: outputFormat });
4678
+ }
4679
+ async function deleteAnalysis(analysisId) {
4680
+ const api = createApiClient();
4681
+ await api.analysis.delete(analysisId);
4682
+ console.log(chalk23.green(`\u2713 Deleted analysis ${analysisId}`));
4704
4683
  }
4705
- async function updateRecipe(analysisId, options, cmd) {
4684
+ async function patchAndPrint(analysisId, value, handler, successLabel, cmd) {
4706
4685
  const outputFormat = getOutputFormat14(cmd);
4707
4686
  const api = createApiClient();
4708
- const opt = await api.analysis.get(analysisId);
4709
- if (!opt.analysis) {
4710
- console.error(chalk23.red(`Analysis not found: ${analysisId}`));
4687
+ const updated = await handler(api, analysisId, value);
4688
+ if (outputFormat === "human") {
4689
+ console.log(chalk23.green(`\u2713 ${successLabel} updated for analysis ${analysisId}`));
4690
+ } else {
4691
+ format(updated, { format: outputFormat });
4692
+ }
4693
+ }
4694
+ async function uploadData(analysisId, file, options) {
4695
+ const api = createApiClient();
4696
+ if (options.url) {
4697
+ if (file) {
4698
+ console.error(chalk23.red("Provide either a file or --url, not both."));
4699
+ process.exit(1);
4700
+ }
4701
+ process.stdout.write(`Uploading from ${options.url} ...`);
4702
+ await api.analysis.uploadDataUrl(analysisId, { dataUrl: options.url });
4703
+ console.log(chalk23.green(" done"));
4704
+ return;
4705
+ }
4706
+ if (!file) {
4707
+ console.error(chalk23.red("Provide a file path or --url <URL>."));
4711
4708
  process.exit(1);
4712
4709
  }
4713
- const recipe = opt.analysis;
4714
- if (options.targets !== void 0) recipe.targetKeys = parseCsv(options.targets);
4715
- if (options.hours !== void 0) recipe.time = options.hours;
4716
- if (options.budget !== void 0) recipe.budget = options.budget;
4717
- if (options.questions !== void 0) recipe.questions = parseCsv(options.questions);
4718
- if (options.segment !== void 0) recipe.segmentKey = options.segment;
4719
- if (options.name !== void 0) recipe.projectName = options.name;
4720
- if (options.description !== void 0) recipe.projectDescription = options.description;
4721
- const saved = await api.analysis.save(recipe);
4722
- format(saved, { format: outputFormat });
4710
+ if (!fs6.existsSync(file)) {
4711
+ console.error(chalk23.red(`File not found: ${file}`));
4712
+ process.exit(1);
4713
+ }
4714
+ process.stdout.write(`Uploading ${path5.basename(file)} ...`);
4715
+ await api.analysis.uploadDataMultipart(analysisId, multipartFromFile(file));
4716
+ console.log(chalk23.green(" done"));
4717
+ }
4718
+ async function listColumns(analysisId, cmd) {
4719
+ const outputFormat = getOutputFormat14(cmd);
4720
+ const api = createApiClient();
4721
+ const columns = await api.analysis.getColumns(analysisId);
4722
+ if (columns.length === 0) {
4723
+ console.log(chalk23.dim("No columns yet \u2014 upload data first."));
4724
+ return;
4725
+ }
4726
+ format(columns, { format: outputFormat, columns: ["name", "valueType"] });
4723
4727
  }
4724
4728
  async function listRuns(analysisId, count, cmd) {
4725
4729
  const outputFormat = getOutputFormat14(cmd);
4726
4730
  const api = createApiClient();
4727
4731
  const runs = await api.analysis.getRunsForAnalysis(analysisId, count);
4728
- const rows = runs.map((r) => ({
4732
+ format(runs.map((r) => ({
4729
4733
  runId: r.runId,
4730
4734
  state: r.state,
4731
4735
  submittedAt: r.submittedAt ? new Date(r.submittedAt).toISOString() : "\u2014",
4732
4736
  startedAt: r.startedAt ? new Date(r.startedAt).toISOString() : "\u2014",
4733
4737
  endedAt: r.endedAt ? new Date(r.endedAt).toISOString() : "\u2014",
4734
4738
  evaluationId: r.evaluationId ?? "\u2014"
4735
- }));
4736
- format(rows, {
4739
+ })), {
4737
4740
  format: outputFormat,
4738
4741
  columns: ["runId", "state", "submittedAt", "endedAt", "evaluationId"]
4739
4742
  });
@@ -4842,7 +4845,7 @@ async function toggleTrigger(triggerId, active, cmd) {
4842
4845
  }
4843
4846
  function registerAnalyzeCommand(program) {
4844
4847
  const analyze = program.command("analyze").description("Run and manage automatic analyses");
4845
- analyze.argument("[file]", "CSV or Excel file to analyze").option("--name <name>", "Project name (derived from filename if omitted)").option("--description <text>", "Project description", "").option("--visibility <vis>", "Project visibility (PRIVATE or PUBLIC)", "PRIVATE").option("--time <hours>", "Computation time in hours", "4").option("--budget <credits>", "Credit budget", "400").option("--targets <keys>", "Comma-separated target column keys").option("--questions <list>", "Comma-separated questions to answer").option("--segment <key>", "Column key to segment the analysis by").action(async (file, options, cmd) => {
4848
+ analyze.argument("[file]", "CSV or Excel file to analyze").option("--name <name>", "Analysis name (derived from filename if omitted)").option("--description <text>", "Analysis description", "").option("--visibility <vis>", "PRIVATE or PUBLIC", "PRIVATE").option("--hours <hours>", "Computation time in hours", "4").option("--budget <credits>", "Credit budget", "400").option("--targets <csv>", "Comma-separated target column names").option("--questions <csv>", "Comma-separated questions to answer").option("--segment <name>", "Column to segment the analysis by").option("--introduction <markdown>", "Markdown introduction at notebook position 0").action(async (file, options, cmd) => {
4846
4849
  try {
4847
4850
  if (!file) {
4848
4851
  analyze.help();
@@ -4867,37 +4870,171 @@ function registerAnalyzeCommand(program) {
4867
4870
  handleError(error);
4868
4871
  }
4869
4872
  });
4870
- analyze.command("watch").description("Live-monitor the latest run of an analysis with progress and streaming outputs").argument("[id]", "Analysis ID (defaults to the most recent)").action(async (id, _options, cmd) => {
4873
+ analyze.command("watch").description("Live-monitor the latest run of an analysis").argument("[id]", "Analysis ID (defaults to the most recent)").action(async (id, _options, cmd) => {
4871
4874
  try {
4872
4875
  await watchAnalysis(id, cmd);
4873
4876
  } catch (error) {
4874
4877
  handleError(error);
4875
4878
  }
4876
4879
  });
4877
- analyze.command("open").description("Open an analysis project in your browser").argument("[id]", "Analysis ID (defaults to the most recent)").action(async (id) => {
4880
+ analyze.command("open").description("Open an analysis notebook in your browser").argument("[id]", "Analysis ID (defaults to the most recent)").action(async (id) => {
4878
4881
  try {
4879
4882
  await openAnalysis(id);
4880
4883
  } catch (error) {
4881
4884
  handleError(error);
4882
4885
  }
4883
4886
  });
4884
- analyze.command("rerun").description("Rerun an existing analysis as a new run \u2014 reuses the recipe and data").argument("<id>", "Analysis ID to rerun").action(async (id) => {
4887
+ analyze.command("rerun").description("Queue a fresh run on an existing analysis").argument("<id>", "Analysis ID to rerun").action(async (id) => {
4885
4888
  try {
4886
4889
  await rerunAnalysis(id);
4887
4890
  } catch (error) {
4888
4891
  handleError(error);
4889
4892
  }
4890
4893
  });
4891
- analyze.command("create").description("Create a recipe without queuing a run (use `analyze rerun <id>` later to launch)").requiredOption("--project-id <id>", "Project ID hosting the raw-data table").requiredOption("--raw-data-table-id <id>", "Raw-data table entity ID").requiredOption("--targets <keys>", "Comma-separated target column keys").option("--hours <h>", "Computation hours", "4").option("--budget <credits>", "Credit budget", "400").option("--questions <list>", "Comma-separated questions").option("--segment <key>", "Segmentation column key").option("--name <name>", "Recipe name").option("--description <text>", "Recipe description").option("--visibility <vis>", "PRIVATE or PUBLIC", "PRIVATE").action(async (options, cmd) => {
4894
+ analyze.command("create").description("Create an analysis recipe without uploading data or running").option("--name <name>", "Analysis name").option("--description <text>", "Analysis description").option("--visibility <vis>", "PRIVATE or PUBLIC", "PRIVATE").option("--hours <h>", "Computation hours").option("--budget <credits>", "Credit budget").option("--targets <csv>", "Comma-separated target column names").option("--questions <csv>", "Comma-separated questions").option("--segment <name>", "Segmentation column").option("--introduction <markdown>", "Markdown introduction").action(async (options, cmd) => {
4892
4895
  try {
4893
4896
  await createRecipe(options, cmd);
4894
4897
  } catch (error) {
4895
4898
  handleError(error);
4896
4899
  }
4897
4900
  });
4898
- analyze.command("update").description("Update fields of an existing analysis recipe").argument("<id>", "Analysis ID to update").option("--targets <keys>", "New comma-separated target keys").option("--hours <h>", "New compute hours").option("--budget <credits>", "New token budget").option("--questions <list>", "New comma-separated questions").option("--segment <key>", "New segment key").option("--name <name>", "New name").option("--description <text>", "New description").action(async (id, options, cmd) => {
4901
+ analyze.command("delete").description("Delete an analysis (cancels in-flight run; removes underlying project)").argument("<id>", "Analysis ID").action(async (id) => {
4902
+ try {
4903
+ await deleteAnalysis(id);
4904
+ } catch (error) {
4905
+ handleError(error);
4906
+ }
4907
+ });
4908
+ analyze.command("rename").description("Set the analysis name").argument("<id>", "Analysis ID").argument("<name>", "New name").action(async (id, name, _options, cmd) => {
4909
+ try {
4910
+ await patchAndPrint(
4911
+ id,
4912
+ name,
4913
+ (api, aid, v) => api.analysis.patchName(aid, { name: v }),
4914
+ "Name",
4915
+ cmd
4916
+ );
4917
+ } catch (error) {
4918
+ handleError(error);
4919
+ }
4920
+ });
4921
+ analyze.command("description").description("Set or clear the analysis description (empty string clears)").argument("<id>", "Analysis ID").argument("<text>", "New description (empty string to clear)").action(async (id, text, _options, cmd) => {
4899
4922
  try {
4900
- await updateRecipe(id, options, cmd);
4923
+ await patchAndPrint(
4924
+ id,
4925
+ text,
4926
+ (api, aid, v) => api.analysis.patchDescription(aid, { description: v === "" ? null : v }),
4927
+ "Description",
4928
+ cmd
4929
+ );
4930
+ } catch (error) {
4931
+ handleError(error);
4932
+ }
4933
+ });
4934
+ analyze.command("visibility").description("Set analysis visibility (PRIVATE or PUBLIC)").argument("<id>", "Analysis ID").argument("<vis>", "PRIVATE or PUBLIC").action(async (id, vis, _options, cmd) => {
4935
+ try {
4936
+ const visibility = parseVisibility(vis);
4937
+ await patchAndPrint(
4938
+ id,
4939
+ visibility,
4940
+ (api, aid, v) => api.analysis.patchVisibility(aid, { visibility: v }),
4941
+ "Visibility",
4942
+ cmd
4943
+ );
4944
+ } catch (error) {
4945
+ handleError(error);
4946
+ }
4947
+ });
4948
+ analyze.command("introduction").description("Set or clear the markdown introduction").argument("<id>", "Analysis ID").argument("<markdown>", "New introduction (empty string to clear)").action(async (id, markdown, _options, cmd) => {
4949
+ try {
4950
+ await patchAndPrint(
4951
+ id,
4952
+ markdown,
4953
+ (api, aid, v) => api.analysis.patchIntroduction(aid, { introduction: v === "" ? null : v }),
4954
+ "Introduction",
4955
+ cmd
4956
+ );
4957
+ } catch (error) {
4958
+ handleError(error);
4959
+ }
4960
+ });
4961
+ analyze.command("hours").description("Set the compute-hours budget for the next run").argument("<id>", "Analysis ID").argument("<hours>", "Compute hours (e.g. 4)").action(async (id, hours, _options, cmd) => {
4962
+ try {
4963
+ await patchAndPrint(
4964
+ id,
4965
+ hours,
4966
+ (api, aid, v) => api.analysis.patchHours(aid, { hours: v }),
4967
+ "Hours",
4968
+ cmd
4969
+ );
4970
+ } catch (error) {
4971
+ handleError(error);
4972
+ }
4973
+ });
4974
+ analyze.command("budget").description("Set the token-credit budget for the next run").argument("<id>", "Analysis ID").argument("<credits>", "Credit budget (e.g. 10000)").action(async (id, credits, _options, cmd) => {
4975
+ try {
4976
+ await patchAndPrint(
4977
+ id,
4978
+ credits,
4979
+ (api, aid, v) => api.analysis.patchBudget(aid, { budget: v }),
4980
+ "Budget",
4981
+ cmd
4982
+ );
4983
+ } catch (error) {
4984
+ handleError(error);
4985
+ }
4986
+ });
4987
+ analyze.command("targets").description("Set the target column names (comma-separated)").argument("<id>", "Analysis ID").argument("<csv>", "Comma-separated target column names").action(async (id, csv, _options, cmd) => {
4988
+ try {
4989
+ const targets = parseCsv(csv) ?? [];
4990
+ await patchAndPrint(
4991
+ id,
4992
+ csv,
4993
+ (api, aid) => api.analysis.patchTargets(aid, { targets }),
4994
+ "Targets",
4995
+ cmd
4996
+ );
4997
+ } catch (error) {
4998
+ handleError(error);
4999
+ }
5000
+ });
5001
+ analyze.command("questions").description("Set the questions list (comma-separated)").argument("<id>", "Analysis ID").argument("<csv>", "Comma-separated questions (empty string to clear)").action(async (id, csv, _options, cmd) => {
5002
+ try {
5003
+ const questions = parseCsv(csv) ?? [];
5004
+ await patchAndPrint(
5005
+ id,
5006
+ csv,
5007
+ (api, aid) => api.analysis.patchQuestions(aid, { questions }),
5008
+ "Questions",
5009
+ cmd
5010
+ );
5011
+ } catch (error) {
5012
+ handleError(error);
5013
+ }
5014
+ });
5015
+ analyze.command("segment").description("Set or clear the segmentation column (empty string clears)").argument("<id>", "Analysis ID").argument("<name>", "Column name (empty string to clear)").action(async (id, name, _options, cmd) => {
5016
+ try {
5017
+ await patchAndPrint(
5018
+ id,
5019
+ name,
5020
+ (api, aid, v) => api.analysis.patchSegment(aid, { segment: v === "" ? null : v }),
5021
+ "Segment",
5022
+ cmd
5023
+ );
5024
+ } catch (error) {
5025
+ handleError(error);
5026
+ }
5027
+ });
5028
+ analyze.command("upload").description("Replace the analysis raw-data table with a new CSV (file path or --url)").argument("<id>", "Analysis ID").argument("[file]", "CSV file to upload").option("--url <url>", "HTTPS URL to fetch the CSV from (mutually exclusive with file)").action(async (id, file, options) => {
5029
+ try {
5030
+ await uploadData(id, file, options);
5031
+ } catch (error) {
5032
+ handleError(error);
5033
+ }
5034
+ });
5035
+ analyze.command("columns").description("List columns of the analysis raw-data table").argument("<id>", "Analysis ID").action(async (id, _options, cmd) => {
5036
+ try {
5037
+ await listColumns(id, cmd);
4901
5038
  } catch (error) {
4902
5039
  handleError(error);
4903
5040
  }
@@ -4931,7 +5068,7 @@ function registerAnalyzeCommand(program) {
4931
5068
  handleError(error);
4932
5069
  }
4933
5070
  });
4934
- presets.command("save").description("Create a new preset (omit --id) or update an existing one (with --id)").requiredOption("--name <name>", "Preset name").requiredOption("--targets <keys>", "Comma-separated target keys").requiredOption("--hours <h>", "Compute hours").requiredOption("--budget <credits>", "Credit budget").option("--questions <list>", "Comma-separated questions").option("--segment <key>", "Segmentation key").option("--id <id>", "Existing preset ID (update mode)").action(async (options, cmd) => {
5071
+ presets.command("save").description("Create a new preset (omit --id) or update an existing one (with --id)").requiredOption("--name <name>", "Preset name").requiredOption("--targets <csv>", "Comma-separated target column names").requiredOption("--hours <h>", "Compute hours").requiredOption("--budget <credits>", "Credit budget").option("--questions <csv>", "Comma-separated questions").option("--segment <name>", "Segmentation column").option("--id <id>", "Existing preset ID (update mode)").action(async (options, cmd) => {
4935
5072
  try {
4936
5073
  await savePreset(options, cmd);
4937
5074
  } catch (error) {
@@ -5447,7 +5584,7 @@ import * as fs8 from "fs";
5447
5584
  import * as os3 from "os";
5448
5585
  import * as path6 from "path";
5449
5586
  import { spawn as spawn3 } from "child_process";
5450
- import { randomUUID as randomUUID4 } from "crypto";
5587
+ import { randomUUID as randomUUID3 } from "crypto";
5451
5588
  function extensionFor2(language) {
5452
5589
  const l = language.toLowerCase();
5453
5590
  if (l === "java") return "java";
@@ -5458,7 +5595,7 @@ function extensionFor2(language) {
5458
5595
  return "txt";
5459
5596
  }
5460
5597
  async function openInEditor(initial, ext) {
5461
- const tmpFile = path6.join(os3.tmpdir(), `diafunc-shell-${randomUUID4()}.${ext}`);
5598
+ const tmpFile = path6.join(os3.tmpdir(), `diafunc-shell-${randomUUID3()}.${ext}`);
5462
5599
  fs8.writeFileSync(tmpFile, initial);
5463
5600
  const editor = process.env.VISUAL ?? process.env.EDITOR ?? "vi";
5464
5601
  await new Promise((resolve, reject) => {
@@ -5490,7 +5627,7 @@ async function evaluate(api, fnRef, language, sourceCode) {
5490
5627
  sourceCode
5491
5628
  });
5492
5629
  await api.storage.saveEntities([entity]);
5493
- const evaluationId = randomUUID4();
5630
+ const evaluationId = randomUUID3();
5494
5631
  const nowParts = utcNowParts();
5495
5632
  const result = await api.evaluation.call({
5496
5633
  evaluationId,
@@ -5543,7 +5680,7 @@ function registerShellCommand(program) {
5543
5680
  });
5544
5681
  const api = createApiClient();
5545
5682
  const { input: promptInput } = await import("@inquirer/prompts");
5546
- const { getUpdateNotice } = await import("./update-check-5JBBCRL3.js");
5683
+ const { getUpdateNotice } = await import("./update-check-BCZ3WECC.js");
5547
5684
  console.log(chalk28.bold("Diafunc shell") + chalk28.dim(` \xB7 function ${fnRef.entityId} \xB7 ${options.language}`));
5548
5685
  console.log(chalk28.dim(`Endpoint: ${config.profiles[config.currentProfile]?.endpoint}`));
5549
5686
  console.log(chalk28.dim("Commands: /edit (multi-line in $EDITOR), /lang <name>, /file <path>, /help, /quit"));
@@ -5647,7 +5784,8 @@ function detectInstall() {
5647
5784
 
5648
5785
  // src/commands/update/index.ts
5649
5786
  var MANIFEST_URL = "https://diafunc.com/cli/latest.json";
5650
- var INSTALLER_URL = "https://diafunc.com/cli/install.sh";
5787
+ var POSIX_INSTALLER_URL = "https://diafunc.com/cli/install.sh";
5788
+ var WINDOWS_INSTALLER_URL = "https://diafunc.com/cli/install.ps1";
5651
5789
  async function fetchLatestVersion() {
5652
5790
  const res = await fetch(MANIFEST_URL);
5653
5791
  if (!res.ok) throw new Error(`Failed to fetch ${MANIFEST_URL}: HTTP ${res.status}`);
@@ -5657,7 +5795,10 @@ async function fetchLatestVersion() {
5657
5795
  }
5658
5796
  function runInstaller(installDir) {
5659
5797
  return new Promise((resolve, reject) => {
5660
- const child = spawn4("sh", ["-c", `curl -fsSL ${INSTALLER_URL} | sh`], {
5798
+ const isWindows = process.platform === "win32";
5799
+ const cmd = isWindows ? "powershell.exe" : "sh";
5800
+ const args = isWindows ? ["-NoProfile", "-Command", `& { iwr -useb ${WINDOWS_INSTALLER_URL} | iex }`] : ["-c", `curl -fsSL ${POSIX_INSTALLER_URL} | sh`];
5801
+ const child = spawn4(cmd, args, {
5661
5802
  stdio: "inherit",
5662
5803
  env: { ...process.env, DIAFUNC_CLI_INSTALL_DIR: installDir }
5663
5804
  });
@@ -5681,12 +5822,6 @@ function registerUpdateCommand(program) {
5681
5822
  console.log(chalk29.bold(` npm install -g @diafunc/cli@${latest}`));
5682
5823
  return;
5683
5824
  }
5684
- if (process.platform === "win32") {
5685
- console.log();
5686
- console.log("In-place update is not supported on Windows. Re-download from:");
5687
- console.log(chalk29.bold(" https://diafunc.com/cli/diafunc-windows-x64.zip"));
5688
- return;
5689
- }
5690
5825
  const installDir = path7.dirname(install.binaryPath);
5691
5826
  console.log(`Installing diafunc ${latest} to ${installDir}...`);
5692
5827
  console.log();
@@ -5699,6 +5834,7 @@ function registerUpdateCommand(program) {
5699
5834
 
5700
5835
  // src/commands/uninstall/index.ts
5701
5836
  import chalk30 from "chalk";
5837
+ import { spawn as spawn5 } from "child_process";
5702
5838
  import * as fs10 from "fs";
5703
5839
  import * as os4 from "os";
5704
5840
  import * as path8 from "path";
@@ -5717,11 +5853,6 @@ function registerUninstallCommand(program) {
5717
5853
  }
5718
5854
  return;
5719
5855
  }
5720
- if (process.platform === "win32") {
5721
- console.log("Self-uninstall is not supported on Windows (the running .exe is locked).");
5722
- console.log(`Delete the binary manually: ${install.binaryPath}`);
5723
- return;
5724
- }
5725
5856
  const { confirm } = await import("@inquirer/prompts");
5726
5857
  const removeBinary = options.yes ? true : await confirm({
5727
5858
  message: `Remove binary at ${install.binaryPath}?`,
@@ -5742,6 +5873,19 @@ function registerUninstallCommand(program) {
5742
5873
  fs10.rmSync(configDir, { recursive: true, force: true });
5743
5874
  console.log(chalk30.dim(`Removed ${configDir}`));
5744
5875
  }
5876
+ if (process.platform === "win32") {
5877
+ const cmd = `timeout /t 2 /nobreak >nul & del /f /q "${install.binaryPath}"`;
5878
+ const child = spawn5("cmd.exe", ["/c", cmd], {
5879
+ detached: true,
5880
+ stdio: "ignore",
5881
+ windowsHide: true
5882
+ });
5883
+ child.unref();
5884
+ console.log(chalk30.dim(`Removing ${install.binaryPath} on exit...`));
5885
+ console.log();
5886
+ console.log("diafunc uninstalled.");
5887
+ return;
5888
+ }
5745
5889
  fs10.rmSync(install.binaryPath, { force: true });
5746
5890
  console.log(chalk30.dim(`Removed ${install.binaryPath}`));
5747
5891
  console.log();
@@ -5793,4 +5937,4 @@ function createProgram() {
5793
5937
  export {
5794
5938
  createProgram
5795
5939
  };
5796
- //# sourceMappingURL=chunk-ECAKWLCR.js.map
5940
+ //# sourceMappingURL=chunk-BPJNQJQS.js.map