agroplan-ai-cli 1.0.19 → 1.0.21

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.
@@ -0,0 +1,13 @@
1
+ {
2
+ "cli_version": "1.0.21",
3
+ "backend_template_version": "1.0.21",
4
+ "zarc_index_version": "2025-2026-fast-index-v2",
5
+ "features": [
6
+ "zarc_fast_index",
7
+ "zarc_fallback_sorgo_mandioca",
8
+ "soil_normalization_misto_siltoso",
9
+ "climate_real_data",
10
+ "hybrid_mode"
11
+ ],
12
+ "generated_at": "2026-05-09T18:30:00Z"
13
+ }
package/dist/index.js CHANGED
@@ -1,11 +1,53 @@
1
1
  #!/usr/bin/env bun
2
2
  // @bun
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ function __accessProp(key) {
8
+ return this[key];
9
+ }
10
+ var __toCommonJS = (from) => {
11
+ var entry = (__moduleCache ??= new WeakMap).get(from), desc;
12
+ if (entry)
13
+ return entry;
14
+ entry = __defProp({}, "__esModule", { value: true });
15
+ if (from && typeof from === "object" || typeof from === "function") {
16
+ for (var key of __getOwnPropNames(from))
17
+ if (!__hasOwnProp.call(entry, key))
18
+ __defProp(entry, key, {
19
+ get: __accessProp.bind(from, key),
20
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
21
+ });
22
+ }
23
+ __moduleCache.set(from, entry);
24
+ return entry;
25
+ };
26
+ var __moduleCache;
27
+ var __returnValue = (v) => v;
28
+ function __exportSetter(name, newValue) {
29
+ this[name] = __returnValue.bind(null, newValue);
30
+ }
31
+ var __export = (target, all) => {
32
+ for (var name in all)
33
+ __defProp(target, name, {
34
+ get: all[name],
35
+ enumerable: true,
36
+ configurable: true,
37
+ set: __exportSetter.bind(all, name)
38
+ });
39
+ };
40
+ var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
3
41
  var __require = import.meta.require;
4
42
 
5
- // src/commands/doctor.ts
6
- import { existsSync as existsSync4 } from "fs";
7
-
8
43
  // src/utils/paths.ts
44
+ var exports_paths = {};
45
+ __export(exports_paths, {
46
+ getProjectPaths: () => getProjectPaths,
47
+ getHomeAgroplanDir: () => getHomeAgroplanDir,
48
+ findProjectRoot: () => findProjectRoot,
49
+ ensureAgroplanDir: () => ensureAgroplanDir
50
+ });
9
51
  import { join, dirname } from "path";
10
52
  import { existsSync, mkdirSync } from "fs";
11
53
  import { homedir } from "os";
@@ -76,45 +118,18 @@ function ensureAgroplanDir() {
76
118
  mkdirSync(paths.logsDir, { recursive: true });
77
119
  }
78
120
  }
79
-
80
- // src/utils/python.ts
81
- function checkPython() {
82
- try {
83
- const result = Bun.spawnSync(["python", "--version"]);
84
- if (result.success) {
85
- return {
86
- available: true,
87
- version: result.stdout.toString().trim(),
88
- path: "python"
89
- };
90
- }
91
- } catch {}
92
- try {
93
- const result = Bun.spawnSync(["python3", "--version"]);
94
- if (result.success) {
95
- return {
96
- available: true,
97
- version: result.stdout.toString().trim(),
98
- path: "python3"
99
- };
100
- }
101
- } catch {}
102
- return { available: false };
103
- }
104
- function checkPip() {
105
- try {
106
- const result = Bun.spawnSync(["pip", "--version"]);
107
- if (result.success) {
108
- return {
109
- available: true,
110
- version: result.stdout.toString().trim()
111
- };
112
- }
113
- } catch {}
114
- return { available: false };
115
- }
121
+ var init_paths = () => {};
116
122
 
117
123
  // src/utils/process.ts
124
+ var exports_process = {};
125
+ __export(exports_process, {
126
+ savePid: () => savePid,
127
+ removePidFile: () => removePidFile,
128
+ readPid: () => readPid,
129
+ killProcess: () => killProcess,
130
+ isProcessRunning: () => isProcessRunning,
131
+ checkPort: () => checkPort
132
+ });
118
133
  import { existsSync as existsSync2, readFileSync, writeFileSync, unlinkSync } from "fs";
119
134
  function savePid(pid) {
120
135
  const paths = getProjectPaths();
@@ -172,8 +187,19 @@ function checkPort(port) {
172
187
  }
173
188
  });
174
189
  }
190
+ var init_process = __esm(() => {
191
+ init_paths();
192
+ });
175
193
 
176
194
  // src/utils/setup-state.ts
195
+ var exports_setup_state = {};
196
+ __export(exports_setup_state, {
197
+ saveSetupState: () => saveSetupState,
198
+ removeSetupState: () => removeSetupState,
199
+ readSetupState: () => readSetupState,
200
+ isSetupComplete: () => isSetupComplete,
201
+ getSetupStatePath: () => getSetupStatePath
202
+ });
177
203
  import { existsSync as existsSync3, readFileSync as readFileSync2, writeFileSync as writeFileSync2 } from "fs";
178
204
  import { join as join2 } from "path";
179
205
  function getSetupStatePath() {
@@ -209,8 +235,64 @@ function isSetupComplete() {
209
235
  const uvicornExists = existsSync3(uvicornPath);
210
236
  return backendExists && venvExists && uvicornExists && state.dependenciesInstalled;
211
237
  }
238
+ function removeSetupState() {
239
+ const statePath = getSetupStatePath();
240
+ if (existsSync3(statePath)) {
241
+ try {
242
+ const { unlinkSync: unlinkSync2 } = __require("fs");
243
+ unlinkSync2(statePath);
244
+ } catch {}
245
+ }
246
+ }
247
+ var init_setup_state = __esm(() => {
248
+ init_paths();
249
+ });
250
+
251
+ // src/commands/doctor.ts
252
+ import { existsSync as existsSync4 } from "fs";
253
+
254
+ // src/utils/python.ts
255
+ init_paths();
256
+ function checkPython() {
257
+ try {
258
+ const result = Bun.spawnSync(["python", "--version"]);
259
+ if (result.success) {
260
+ return {
261
+ available: true,
262
+ version: result.stdout.toString().trim(),
263
+ path: "python"
264
+ };
265
+ }
266
+ } catch {}
267
+ try {
268
+ const result = Bun.spawnSync(["python3", "--version"]);
269
+ if (result.success) {
270
+ return {
271
+ available: true,
272
+ version: result.stdout.toString().trim(),
273
+ path: "python3"
274
+ };
275
+ }
276
+ } catch {}
277
+ return { available: false };
278
+ }
279
+ function checkPip() {
280
+ try {
281
+ const result = Bun.spawnSync(["pip", "--version"]);
282
+ if (result.success) {
283
+ return {
284
+ available: true,
285
+ version: result.stdout.toString().trim()
286
+ };
287
+ }
288
+ } catch {}
289
+ return { available: false };
290
+ }
212
291
 
213
292
  // src/commands/doctor.ts
293
+ init_paths();
294
+ init_process();
295
+ init_setup_state();
214
296
  async function doctorCommand() {
215
297
  console.log(`\uD83D\uDD0D AgroPlan AI - Diagn\xF3stico do Sistema
216
298
  `);
@@ -240,11 +322,47 @@ async function doctorCommand() {
240
322
  \uD83D\uDEE0\uFE0F Setup Local:`);
241
323
  const setupComplete = isSetupComplete();
242
324
  const setupState = readSetupState();
325
+ let currentVersion = "1.0.21";
326
+ try {
327
+ const packagePath = __require.resolve("agroplan-ai-cli/package.json");
328
+ const packageJson = __require(packagePath);
329
+ currentVersion = packageJson.version || "1.0.21";
330
+ } catch {
331
+ currentVersion = "1.0.21";
332
+ }
243
333
  if (setupComplete && setupState) {
334
+ const installedVersion = setupState.version || "unknown";
244
335
  console.log(" \u2705 Setup conclu\xEDdo");
245
336
  console.log(` \uD83D\uDCC5 Instalado em: ${new Date(setupState.installedAt).toLocaleString()}`);
246
- console.log(` \uD83D\uDCE6 Vers\xE3o: ${setupState.version}`);
337
+ console.log(` \uD83D\uDCE6 Vers\xE3o CLI: ${installedVersion}`);
247
338
  console.log(` \uD83D\uDC0D Python: ${setupState.python}`);
339
+ try {
340
+ const { getHomeAgroplanDir: getHomeAgroplanDir2 } = await Promise.resolve().then(() => (init_paths(), exports_paths));
341
+ const homeDir = getHomeAgroplanDir2();
342
+ const versionPath = `${homeDir}/backend/VERSION.json`;
343
+ const { existsSync: existsSync5, readFileSync: readFileSync3 } = await import("fs");
344
+ if (existsSync5(versionPath)) {
345
+ const versionContent = readFileSync3(versionPath, "utf-8");
346
+ const versionInfo = JSON.parse(versionContent);
347
+ console.log(` \uD83D\uDCE6 Backend template: ${versionInfo.backend_template_version || "unknown"}`);
348
+ console.log(` \uD83D\uDDC2\uFE0F ZARC index: ${versionInfo.zarc_index_version || "unknown"}`);
349
+ if (versionInfo.features && versionInfo.features.length > 0) {
350
+ console.log(` \u2728 Features: ${versionInfo.features.slice(0, 3).join(", ")}${versionInfo.features.length > 3 ? "..." : ""}`);
351
+ }
352
+ } else {
353
+ console.log(" \u26A0\uFE0F VERSION.json n\xE3o encontrado no backend local");
354
+ }
355
+ } catch (error) {}
356
+ if (installedVersion !== currentVersion) {
357
+ console.log(`
358
+ \u26A0\uFE0F API local desatualizada!`);
359
+ console.log(` Instalada: ${installedVersion}`);
360
+ console.log(` CLI atual: ${currentVersion}`);
361
+ console.log(`
362
+ Execute: agroplan update`);
363
+ console.log(` ou: agroplan setup --force --python="${setupState.pythonPath || "python"}"`);
364
+ allGood = false;
365
+ }
248
366
  } else {
249
367
  console.log(" \u274C Setup n\xE3o conclu\xEDdo");
250
368
  console.log(" Execute: agroplan setup");
@@ -367,6 +485,8 @@ Correja os problemas acima:`);
367
485
  }
368
486
 
369
487
  // src/commands/serve.ts
488
+ init_paths();
489
+ init_process();
370
490
  import { existsSync as existsSync5, readFileSync as readFileSync3, openSync, closeSync } from "fs";
371
491
  import { spawn } from "child_process";
372
492
  async function serveOnCommand() {
@@ -383,6 +503,34 @@ async function serveOnCommand() {
383
503
  console.log(` ${paths.backend}`);
384
504
  return;
385
505
  }
506
+ const { readSetupState: readSetupState2 } = await Promise.resolve().then(() => (init_setup_state(), exports_setup_state));
507
+ const setupState = readSetupState2();
508
+ if (setupState) {
509
+ let currentVersion = "1.0.21";
510
+ try {
511
+ const packagePath = __require.resolve("agroplan-ai-cli/package.json");
512
+ const packageJson = __require(packagePath);
513
+ currentVersion = packageJson.version || "1.0.21";
514
+ } catch {
515
+ currentVersion = "1.0.21";
516
+ }
517
+ const installedVersion = setupState.version || "unknown";
518
+ if (installedVersion !== currentVersion) {
519
+ console.log("\u26A0\uFE0F API local desatualizada detectada!");
520
+ console.log(` Instalada: ${installedVersion}`);
521
+ console.log(` CLI atual: ${currentVersion}`);
522
+ console.log(`
523
+ Algumas funcionalidades podem n\xE3o funcionar corretamente.`);
524
+ console.log(` Recomendamos atualizar antes de continuar:
525
+ `);
526
+ console.log(" agroplan update");
527
+ console.log(` ou: agroplan setup --force --python="${setupState.pythonPath || "python"}"`);
528
+ console.log(`
529
+ Pressione Ctrl+C para cancelar ou aguarde 5 segundos para continuar...
530
+ `);
531
+ await new Promise((resolve) => setTimeout(resolve, 5000));
532
+ }
533
+ }
386
534
  const existingPid = readPid();
387
535
  if (existingPid && isProcessRunning(existingPid)) {
388
536
  console.log("\u2705 API local j\xE1 est\xE1 rodando!");
@@ -615,17 +763,41 @@ function openCommand() {
615
763
  }
616
764
 
617
765
  // src/commands/setup.ts
766
+ init_paths();
618
767
  import { existsSync as existsSync6, cpSync, rmSync } from "fs";
619
768
  import { join as join3, dirname as dirname2 } from "path";
769
+ init_setup_state();
620
770
  async function setupCommand(force = false, pythonPath) {
621
771
  console.log(`\uD83D\uDEE0\uFE0F Configurando AgroPlan AI - API Local
622
772
  `);
623
773
  const homeDir = getHomeAgroplanDir();
624
774
  const backendDir = join3(homeDir, "backend");
625
775
  console.log(`\uD83D\uDCC1 Diret\xF3rio de instala\xE7\xE3o: ${homeDir}`);
776
+ let currentVersion = "1.0.21";
777
+ try {
778
+ const packagePath = __require.resolve("agroplan-ai-cli/package.json");
779
+ const packageJson = __require(packagePath);
780
+ currentVersion = packageJson.version || "1.0.21";
781
+ } catch {
782
+ currentVersion = "1.0.21";
783
+ }
626
784
  if (!force && isSetupComplete()) {
785
+ const setupState = (init_setup_state(), __toCommonJS(exports_setup_state)).readSetupState();
786
+ const installedVersion = setupState?.version || "unknown";
787
+ if (installedVersion !== currentVersion) {
788
+ console.log(`
789
+ \u26A0\uFE0F API local instalada est\xE1 desatualizada!`);
790
+ console.log(` Instalada: ${installedVersion}`);
791
+ console.log(` CLI atual: ${currentVersion}`);
792
+ console.log(`
793
+ \uD83D\uDCA1 Para atualizar:`);
794
+ console.log(" agroplan update");
795
+ console.log(" ou: agroplan setup --force");
796
+ return;
797
+ }
627
798
  console.log(`
628
799
  \u2705 API local j\xE1 est\xE1 configurada!`);
800
+ console.log(` Vers\xE3o: ${installedVersion}`);
629
801
  console.log(`
630
802
  \uD83D\uDE80 Pr\xF3ximos passos:`);
631
803
  console.log(" agroplan serve on # Iniciar API local");
@@ -748,13 +920,13 @@ async function setupCommand(force = false, pythonPath) {
748
920
  return;
749
921
  }
750
922
  console.log(" \u2705 Servidor web configurado");
751
- let version = "1.0.5";
923
+ let version = "1.0.21";
752
924
  try {
753
925
  const packagePath = __require.resolve("agroplan-ai-cli/package.json");
754
926
  const packageJson = __require(packagePath);
755
- version = packageJson.version || "1.0.5";
927
+ version = packageJson.version || "1.0.21";
756
928
  } catch {
757
- version = "1.0.5";
929
+ version = "1.0.21";
758
930
  }
759
931
  saveSetupState({
760
932
  version,
@@ -775,11 +947,133 @@ async function setupCommand(force = false, pythonPath) {
775
947
  \uD83D\uDCA1 A API local ser\xE1 executada em http://localhost:8000`);
776
948
  }
777
949
 
950
+ // src/commands/update.ts
951
+ init_setup_state();
952
+ init_process();
953
+ async function updateCommand() {
954
+ console.log(`\uD83D\uDD04 Atualizando API local do AgroPlan AI...
955
+ `);
956
+ if (!isSetupComplete()) {
957
+ console.log("\u274C API local n\xE3o est\xE1 configurada");
958
+ console.log(`
959
+ \uD83D\uDCA1 Execute primeiro:`);
960
+ console.log(" agroplan setup");
961
+ return;
962
+ }
963
+ const setupState = readSetupState();
964
+ if (!setupState) {
965
+ console.log("\u274C N\xE3o foi poss\xEDvel ler estado do setup");
966
+ console.log(`
967
+ \uD83D\uDCA1 Execute:`);
968
+ console.log(" agroplan setup --force");
969
+ return;
970
+ }
971
+ let currentVersion = "1.0.21";
972
+ try {
973
+ const packagePath = __require.resolve("agroplan-ai-cli/package.json");
974
+ const packageJson = __require(packagePath);
975
+ currentVersion = packageJson.version || "1.0.21";
976
+ } catch {
977
+ currentVersion = "1.0.21";
978
+ }
979
+ const installedVersion = setupState.version || "unknown";
980
+ console.log(`\uD83D\uDCE6 Vers\xE3o instalada: ${installedVersion}`);
981
+ console.log(`\uD83D\uDCE6 Vers\xE3o CLI atual: ${currentVersion}
982
+ `);
983
+ if (installedVersion === currentVersion) {
984
+ console.log("\u2705 API local j\xE1 est\xE1 atualizada!");
985
+ console.log(`
986
+ \uD83D\uDCA1 Para reinstalar mesmo assim:`);
987
+ console.log(" agroplan setup --force");
988
+ return;
989
+ }
990
+ console.log(`\uD83D\uDD04 Iniciando atualiza\xE7\xE3o...
991
+ `);
992
+ const pid = readPid();
993
+ const isRunning = pid ? isProcessRunning(pid) : false;
994
+ if (isRunning) {
995
+ console.log("1\uFE0F\u20E3 Parando API local...");
996
+ await serveOffCommand();
997
+ console.log("");
998
+ } else {
999
+ console.log("1\uFE0F\u20E3 API local n\xE3o est\xE1 rodando");
1000
+ }
1001
+ const { checkPort: checkPort2 } = await Promise.resolve().then(() => (init_process(), exports_process));
1002
+ const portInUse = await checkPort2(8000);
1003
+ if (portInUse) {
1004
+ console.log(`
1005
+ \u26A0\uFE0F Porta 8000 ainda est\xE1 ocupada por outro processo!`);
1006
+ console.log(`
1007
+ \uD83D\uDCA1 Para identificar e encerrar o processo:`);
1008
+ console.log(" netstat -ano | findstr :8000");
1009
+ console.log(" taskkill /PID <PID> /F");
1010
+ console.log(`
1011
+ Depois rode novamente: agroplan update`);
1012
+ return;
1013
+ }
1014
+ console.log("2\uFE0F\u20E3 Removendo backend antigo...");
1015
+ try {
1016
+ const { getHomeAgroplanDir: getHomeAgroplanDir2 } = await Promise.resolve().then(() => (init_paths(), exports_paths));
1017
+ const { existsSync: existsSync7, rmSync: rmSync2 } = await import("fs");
1018
+ const { join: join4 } = await import("path");
1019
+ const homeDir = getHomeAgroplanDir2();
1020
+ const backendDir = join4(homeDir, "backend");
1021
+ if (existsSync7(backendDir)) {
1022
+ rmSync2(backendDir, { recursive: true, force: true });
1023
+ console.log(" \u2705 Backend antigo removido");
1024
+ } else {
1025
+ console.log(" \u2139\uFE0F Nenhum backend antigo encontrado");
1026
+ }
1027
+ } catch (error) {
1028
+ console.log(` \u26A0\uFE0F Erro ao remover backend: ${error}`);
1029
+ }
1030
+ console.log("");
1031
+ console.log(`3\uFE0F\u20E3 Instalando backend atualizado...
1032
+ `);
1033
+ const pythonPath = setupState.pythonPath || undefined;
1034
+ await setupCommand(true, pythonPath);
1035
+ console.log(`
1036
+ 4\uFE0F\u20E3 Verificando instala\xE7\xE3o...`);
1037
+ try {
1038
+ const { getHomeAgroplanDir: getHomeAgroplanDir2 } = await Promise.resolve().then(() => (init_paths(), exports_paths));
1039
+ const { existsSync: existsSync7, readFileSync: readFileSync4 } = await import("fs");
1040
+ const { join: join4 } = await import("path");
1041
+ const homeDir = getHomeAgroplanDir2();
1042
+ const versionPath = join4(homeDir, "backend", "VERSION.json");
1043
+ if (existsSync7(versionPath)) {
1044
+ const versionContent = readFileSync4(versionPath, "utf-8");
1045
+ const versionInfo = JSON.parse(versionContent);
1046
+ console.log(` \u2705 Backend template: ${versionInfo.backend_template_version}`);
1047
+ console.log(` \u2705 ZARC index: ${versionInfo.zarc_index_version}`);
1048
+ console.log(` \u2705 Features: ${versionInfo.features.length} ativas`);
1049
+ } else {
1050
+ console.log(" \u26A0\uFE0F VERSION.json n\xE3o encontrado");
1051
+ }
1052
+ } catch (error) {
1053
+ console.log(` \u26A0\uFE0F Erro ao verificar vers\xE3o: ${error}`);
1054
+ }
1055
+ console.log(`
1056
+ 5\uFE0F\u20E3 Atualiza\xE7\xE3o conclu\xEDda!`);
1057
+ if (isRunning) {
1058
+ console.log(`
1059
+ \uD83D\uDCA1 Para reiniciar a API:`);
1060
+ console.log(" agroplan serve on");
1061
+ } else {
1062
+ console.log(`
1063
+ \uD83D\uDCA1 Para iniciar a API:`);
1064
+ console.log(" agroplan serve on");
1065
+ }
1066
+ console.log(`
1067
+ \uD83D\uDD0D Para verificar a vers\xE3o da API rodando:`);
1068
+ console.log(" http://localhost:8000/debug/version");
1069
+ }
1070
+
778
1071
  // src/index.ts
779
1072
  var COMMANDS = {
780
1073
  setup: "Configura a API local no seu computador",
781
1074
  "setup --force": "Reinstala a API local (remove instala\xE7\xE3o anterior)",
782
1075
  "setup --python=<path>": "Usa Python espec\xEDfico para instala\xE7\xE3o",
1076
+ update: "Atualiza a API local para a vers\xE3o mais recente",
783
1077
  doctor: "Verifica se o sistema est\xE1 configurado corretamente",
784
1078
  "serve on": "Inicia a API local em http://localhost:8000",
785
1079
  "serve off": "Para a API local",
@@ -788,7 +1082,7 @@ var COMMANDS = {
788
1082
  open: "Abre o AgroPlan AI no navegador"
789
1083
  };
790
1084
  function showHelp() {
791
- console.log("\uD83C\uDF31 AgroPlan AI - CLI Local v1.0.8");
1085
+ console.log("\uD83C\uDF31 AgroPlan AI - CLI Local v1.0.21");
792
1086
  console.log(` Launcher para modo local acelerado
793
1087
  `);
794
1088
  console.log("\uD83D\uDCCB Comandos dispon\xEDveis:");
@@ -802,6 +1096,9 @@ function showHelp() {
802
1096
  console.log(" 3. agroplan open # Abrir no navegador");
803
1097
  console.log(" 4. agroplan serve off # Parar quando terminar");
804
1098
  console.log(`
1099
+ \uD83D\uDD04 Atualiza\xE7\xE3o:`);
1100
+ console.log(" agroplan update # Atualizar API local");
1101
+ console.log(`
805
1102
  \uD83D\uDC0D Para Python 3.13 (Windows):`);
806
1103
  console.log(' agroplan setup --python="C:\\Python311\\python.exe"');
807
1104
  console.log(`
@@ -834,6 +1131,9 @@ async function main() {
834
1131
  case "setup":
835
1132
  await setupCommand(force, pythonPath);
836
1133
  break;
1134
+ case "update":
1135
+ await updateCommand();
1136
+ break;
837
1137
  case "doctor":
838
1138
  await doctorCommand();
839
1139
  break;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agroplan-ai-cli",
3
- "version": "1.0.19",
3
+ "version": "1.0.21",
4
4
  "description": "CLI global para AgroPlan AI - modo local acelerado",
5
5
  "type": "module",
6
6
  "bin": {