agroplan-ai-cli 1.0.19 → 1.0.20

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.
Files changed (2) hide show
  1. package/dist/index.js +256 -45
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,10 +1,45 @@
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
9
44
  import { join, dirname } from "path";
10
45
  import { existsSync, mkdirSync } from "fs";
@@ -76,8 +111,70 @@ function ensureAgroplanDir() {
76
111
  mkdirSync(paths.logsDir, { recursive: true });
77
112
  }
78
113
  }
114
+ var init_paths = () => {};
115
+
116
+ // src/utils/setup-state.ts
117
+ var exports_setup_state = {};
118
+ __export(exports_setup_state, {
119
+ saveSetupState: () => saveSetupState,
120
+ removeSetupState: () => removeSetupState,
121
+ readSetupState: () => readSetupState,
122
+ isSetupComplete: () => isSetupComplete,
123
+ getSetupStatePath: () => getSetupStatePath
124
+ });
125
+ import { existsSync as existsSync3, readFileSync as readFileSync2, writeFileSync as writeFileSync2 } from "fs";
126
+ import { join as join2 } from "path";
127
+ function getSetupStatePath() {
128
+ return join2(getHomeAgroplanDir(), "setup.json");
129
+ }
130
+ function readSetupState() {
131
+ const statePath = getSetupStatePath();
132
+ if (!existsSync3(statePath)) {
133
+ return null;
134
+ }
135
+ try {
136
+ const content = readFileSync2(statePath, "utf-8");
137
+ return JSON.parse(content);
138
+ } catch {
139
+ return null;
140
+ }
141
+ }
142
+ function saveSetupState(state) {
143
+ const statePath = getSetupStatePath();
144
+ writeFileSync2(statePath, JSON.stringify(state, null, 2));
145
+ }
146
+ function isSetupComplete() {
147
+ const state = readSetupState();
148
+ if (!state)
149
+ return false;
150
+ const homeDir = getHomeAgroplanDir();
151
+ const backendDir = join2(homeDir, "backend");
152
+ const venvDir = join2(backendDir, ".venv");
153
+ const backendExists = existsSync3(backendDir);
154
+ const venvExists = existsSync3(venvDir);
155
+ const isWindows = process.platform === "win32";
156
+ const uvicornPath = isWindows ? join2(venvDir, "Scripts", "uvicorn.exe") : join2(venvDir, "bin", "uvicorn");
157
+ const uvicornExists = existsSync3(uvicornPath);
158
+ return backendExists && venvExists && uvicornExists && state.dependenciesInstalled;
159
+ }
160
+ function removeSetupState() {
161
+ const statePath = getSetupStatePath();
162
+ if (existsSync3(statePath)) {
163
+ try {
164
+ const { unlinkSync: unlinkSync2 } = __require("fs");
165
+ unlinkSync2(statePath);
166
+ } catch {}
167
+ }
168
+ }
169
+ var init_setup_state = __esm(() => {
170
+ init_paths();
171
+ });
172
+
173
+ // src/commands/doctor.ts
174
+ import { existsSync as existsSync4 } from "fs";
79
175
 
80
176
  // src/utils/python.ts
177
+ init_paths();
81
178
  function checkPython() {
82
179
  try {
83
180
  const result = Bun.spawnSync(["python", "--version"]);
@@ -114,7 +211,11 @@ function checkPip() {
114
211
  return { available: false };
115
212
  }
116
213
 
214
+ // src/commands/doctor.ts
215
+ init_paths();
216
+
117
217
  // src/utils/process.ts
218
+ init_paths();
118
219
  import { existsSync as existsSync2, readFileSync, writeFileSync, unlinkSync } from "fs";
119
220
  function savePid(pid) {
120
221
  const paths = getProjectPaths();
@@ -173,44 +274,8 @@ function checkPort(port) {
173
274
  });
174
275
  }
175
276
 
176
- // src/utils/setup-state.ts
177
- import { existsSync as existsSync3, readFileSync as readFileSync2, writeFileSync as writeFileSync2 } from "fs";
178
- import { join as join2 } from "path";
179
- function getSetupStatePath() {
180
- return join2(getHomeAgroplanDir(), "setup.json");
181
- }
182
- function readSetupState() {
183
- const statePath = getSetupStatePath();
184
- if (!existsSync3(statePath)) {
185
- return null;
186
- }
187
- try {
188
- const content = readFileSync2(statePath, "utf-8");
189
- return JSON.parse(content);
190
- } catch {
191
- return null;
192
- }
193
- }
194
- function saveSetupState(state) {
195
- const statePath = getSetupStatePath();
196
- writeFileSync2(statePath, JSON.stringify(state, null, 2));
197
- }
198
- function isSetupComplete() {
199
- const state = readSetupState();
200
- if (!state)
201
- return false;
202
- const homeDir = getHomeAgroplanDir();
203
- const backendDir = join2(homeDir, "backend");
204
- const venvDir = join2(backendDir, ".venv");
205
- const backendExists = existsSync3(backendDir);
206
- const venvExists = existsSync3(venvDir);
207
- const isWindows = process.platform === "win32";
208
- const uvicornPath = isWindows ? join2(venvDir, "Scripts", "uvicorn.exe") : join2(venvDir, "bin", "uvicorn");
209
- const uvicornExists = existsSync3(uvicornPath);
210
- return backendExists && venvExists && uvicornExists && state.dependenciesInstalled;
211
- }
212
-
213
277
  // src/commands/doctor.ts
278
+ init_setup_state();
214
279
  async function doctorCommand() {
215
280
  console.log(`\uD83D\uDD0D AgroPlan AI - Diagn\xF3stico do Sistema
216
281
  `);
@@ -240,11 +305,30 @@ async function doctorCommand() {
240
305
  \uD83D\uDEE0\uFE0F Setup Local:`);
241
306
  const setupComplete = isSetupComplete();
242
307
  const setupState = readSetupState();
308
+ let currentVersion = "1.0.20";
309
+ try {
310
+ const packagePath = __require.resolve("agroplan-ai-cli/package.json");
311
+ const packageJson = __require(packagePath);
312
+ currentVersion = packageJson.version || "1.0.20";
313
+ } catch {
314
+ currentVersion = "1.0.20";
315
+ }
243
316
  if (setupComplete && setupState) {
317
+ const installedVersion = setupState.version || "unknown";
244
318
  console.log(" \u2705 Setup conclu\xEDdo");
245
319
  console.log(` \uD83D\uDCC5 Instalado em: ${new Date(setupState.installedAt).toLocaleString()}`);
246
- console.log(` \uD83D\uDCE6 Vers\xE3o: ${setupState.version}`);
320
+ console.log(` \uD83D\uDCE6 Vers\xE3o: ${installedVersion}`);
247
321
  console.log(` \uD83D\uDC0D Python: ${setupState.python}`);
322
+ if (installedVersion !== currentVersion) {
323
+ console.log(`
324
+ \u26A0\uFE0F API local desatualizada!`);
325
+ console.log(` Instalada: ${installedVersion}`);
326
+ console.log(` CLI atual: ${currentVersion}`);
327
+ console.log(`
328
+ Execute: agroplan update`);
329
+ console.log(` ou: agroplan setup --force --python="${setupState.pythonPath || "python"}"`);
330
+ allGood = false;
331
+ }
248
332
  } else {
249
333
  console.log(" \u274C Setup n\xE3o conclu\xEDdo");
250
334
  console.log(" Execute: agroplan setup");
@@ -367,6 +451,7 @@ Correja os problemas acima:`);
367
451
  }
368
452
 
369
453
  // src/commands/serve.ts
454
+ init_paths();
370
455
  import { existsSync as existsSync5, readFileSync as readFileSync3, openSync, closeSync } from "fs";
371
456
  import { spawn } from "child_process";
372
457
  async function serveOnCommand() {
@@ -383,6 +468,34 @@ async function serveOnCommand() {
383
468
  console.log(` ${paths.backend}`);
384
469
  return;
385
470
  }
471
+ const { readSetupState: readSetupState2 } = await Promise.resolve().then(() => (init_setup_state(), exports_setup_state));
472
+ const setupState = readSetupState2();
473
+ if (setupState) {
474
+ let currentVersion = "1.0.20";
475
+ try {
476
+ const packagePath = __require.resolve("agroplan-ai-cli/package.json");
477
+ const packageJson = __require(packagePath);
478
+ currentVersion = packageJson.version || "1.0.20";
479
+ } catch {
480
+ currentVersion = "1.0.20";
481
+ }
482
+ const installedVersion = setupState.version || "unknown";
483
+ if (installedVersion !== currentVersion) {
484
+ console.log("\u26A0\uFE0F API local desatualizada detectada!");
485
+ console.log(` Instalada: ${installedVersion}`);
486
+ console.log(` CLI atual: ${currentVersion}`);
487
+ console.log(`
488
+ Algumas funcionalidades podem n\xE3o funcionar corretamente.`);
489
+ console.log(` Recomendamos atualizar antes de continuar:
490
+ `);
491
+ console.log(" agroplan update");
492
+ console.log(` ou: agroplan setup --force --python="${setupState.pythonPath || "python"}"`);
493
+ console.log(`
494
+ Pressione Ctrl+C para cancelar ou aguarde 5 segundos para continuar...
495
+ `);
496
+ await new Promise((resolve) => setTimeout(resolve, 5000));
497
+ }
498
+ }
386
499
  const existingPid = readPid();
387
500
  if (existingPid && isProcessRunning(existingPid)) {
388
501
  console.log("\u2705 API local j\xE1 est\xE1 rodando!");
@@ -615,17 +728,41 @@ function openCommand() {
615
728
  }
616
729
 
617
730
  // src/commands/setup.ts
731
+ init_paths();
618
732
  import { existsSync as existsSync6, cpSync, rmSync } from "fs";
619
733
  import { join as join3, dirname as dirname2 } from "path";
734
+ init_setup_state();
620
735
  async function setupCommand(force = false, pythonPath) {
621
736
  console.log(`\uD83D\uDEE0\uFE0F Configurando AgroPlan AI - API Local
622
737
  `);
623
738
  const homeDir = getHomeAgroplanDir();
624
739
  const backendDir = join3(homeDir, "backend");
625
740
  console.log(`\uD83D\uDCC1 Diret\xF3rio de instala\xE7\xE3o: ${homeDir}`);
741
+ let currentVersion = "1.0.20";
742
+ try {
743
+ const packagePath = __require.resolve("agroplan-ai-cli/package.json");
744
+ const packageJson = __require(packagePath);
745
+ currentVersion = packageJson.version || "1.0.20";
746
+ } catch {
747
+ currentVersion = "1.0.20";
748
+ }
626
749
  if (!force && isSetupComplete()) {
750
+ const setupState = (init_setup_state(), __toCommonJS(exports_setup_state)).readSetupState();
751
+ const installedVersion = setupState?.version || "unknown";
752
+ if (installedVersion !== currentVersion) {
753
+ console.log(`
754
+ \u26A0\uFE0F API local instalada est\xE1 desatualizada!`);
755
+ console.log(` Instalada: ${installedVersion}`);
756
+ console.log(` CLI atual: ${currentVersion}`);
757
+ console.log(`
758
+ \uD83D\uDCA1 Para atualizar:`);
759
+ console.log(" agroplan update");
760
+ console.log(" ou: agroplan setup --force");
761
+ return;
762
+ }
627
763
  console.log(`
628
764
  \u2705 API local j\xE1 est\xE1 configurada!`);
765
+ console.log(` Vers\xE3o: ${installedVersion}`);
629
766
  console.log(`
630
767
  \uD83D\uDE80 Pr\xF3ximos passos:`);
631
768
  console.log(" agroplan serve on # Iniciar API local");
@@ -748,13 +885,13 @@ async function setupCommand(force = false, pythonPath) {
748
885
  return;
749
886
  }
750
887
  console.log(" \u2705 Servidor web configurado");
751
- let version = "1.0.5";
888
+ let version = "1.0.20";
752
889
  try {
753
890
  const packagePath = __require.resolve("agroplan-ai-cli/package.json");
754
891
  const packageJson = __require(packagePath);
755
- version = packageJson.version || "1.0.5";
892
+ version = packageJson.version || "1.0.20";
756
893
  } catch {
757
- version = "1.0.5";
894
+ version = "1.0.20";
758
895
  }
759
896
  saveSetupState({
760
897
  version,
@@ -775,11 +912,79 @@ async function setupCommand(force = false, pythonPath) {
775
912
  \uD83D\uDCA1 A API local ser\xE1 executada em http://localhost:8000`);
776
913
  }
777
914
 
915
+ // src/commands/update.ts
916
+ init_setup_state();
917
+ async function updateCommand() {
918
+ console.log(`\uD83D\uDD04 Atualizando API local do AgroPlan AI...
919
+ `);
920
+ if (!isSetupComplete()) {
921
+ console.log("\u274C API local n\xE3o est\xE1 configurada");
922
+ console.log(`
923
+ \uD83D\uDCA1 Execute primeiro:`);
924
+ console.log(" agroplan setup");
925
+ return;
926
+ }
927
+ const setupState = readSetupState();
928
+ if (!setupState) {
929
+ console.log("\u274C N\xE3o foi poss\xEDvel ler estado do setup");
930
+ console.log(`
931
+ \uD83D\uDCA1 Execute:`);
932
+ console.log(" agroplan setup --force");
933
+ return;
934
+ }
935
+ let currentVersion = "1.0.20";
936
+ try {
937
+ const packagePath = __require.resolve("agroplan-ai-cli/package.json");
938
+ const packageJson = __require(packagePath);
939
+ currentVersion = packageJson.version || "1.0.20";
940
+ } catch {
941
+ currentVersion = "1.0.20";
942
+ }
943
+ const installedVersion = setupState.version || "unknown";
944
+ console.log(`\uD83D\uDCE6 Vers\xE3o instalada: ${installedVersion}`);
945
+ console.log(`\uD83D\uDCE6 Vers\xE3o CLI atual: ${currentVersion}
946
+ `);
947
+ if (installedVersion === currentVersion) {
948
+ console.log("\u2705 API local j\xE1 est\xE1 atualizada!");
949
+ console.log(`
950
+ \uD83D\uDCA1 Para reinstalar mesmo assim:`);
951
+ console.log(" agroplan setup --force");
952
+ return;
953
+ }
954
+ console.log(`\uD83D\uDD04 Iniciando atualiza\xE7\xE3o...
955
+ `);
956
+ const pid = readPid();
957
+ const isRunning = pid ? isProcessRunning(pid) : false;
958
+ if (isRunning) {
959
+ console.log("1\uFE0F\u20E3 Parando API local...");
960
+ await serveOffCommand();
961
+ console.log("");
962
+ } else {
963
+ console.log("1\uFE0F\u20E3 API local n\xE3o est\xE1 rodando");
964
+ }
965
+ console.log(`2\uFE0F\u20E3 Reinstalando backend atualizado...
966
+ `);
967
+ const pythonPath = setupState.pythonPath || undefined;
968
+ await setupCommand(true, pythonPath);
969
+ console.log(`
970
+ 3\uFE0F\u20E3 Atualiza\xE7\xE3o conclu\xEDda!`);
971
+ if (isRunning) {
972
+ console.log(`
973
+ \uD83D\uDCA1 Para reiniciar a API:`);
974
+ console.log(" agroplan serve on");
975
+ } else {
976
+ console.log(`
977
+ \uD83D\uDCA1 Para iniciar a API:`);
978
+ console.log(" agroplan serve on");
979
+ }
980
+ }
981
+
778
982
  // src/index.ts
779
983
  var COMMANDS = {
780
984
  setup: "Configura a API local no seu computador",
781
985
  "setup --force": "Reinstala a API local (remove instala\xE7\xE3o anterior)",
782
986
  "setup --python=<path>": "Usa Python espec\xEDfico para instala\xE7\xE3o",
987
+ update: "Atualiza a API local para a vers\xE3o mais recente",
783
988
  doctor: "Verifica se o sistema est\xE1 configurado corretamente",
784
989
  "serve on": "Inicia a API local em http://localhost:8000",
785
990
  "serve off": "Para a API local",
@@ -788,7 +993,7 @@ var COMMANDS = {
788
993
  open: "Abre o AgroPlan AI no navegador"
789
994
  };
790
995
  function showHelp() {
791
- console.log("\uD83C\uDF31 AgroPlan AI - CLI Local v1.0.8");
996
+ console.log("\uD83C\uDF31 AgroPlan AI - CLI Local v1.0.20");
792
997
  console.log(` Launcher para modo local acelerado
793
998
  `);
794
999
  console.log("\uD83D\uDCCB Comandos dispon\xEDveis:");
@@ -802,6 +1007,9 @@ function showHelp() {
802
1007
  console.log(" 3. agroplan open # Abrir no navegador");
803
1008
  console.log(" 4. agroplan serve off # Parar quando terminar");
804
1009
  console.log(`
1010
+ \uD83D\uDD04 Atualiza\xE7\xE3o:`);
1011
+ console.log(" agroplan update # Atualizar API local");
1012
+ console.log(`
805
1013
  \uD83D\uDC0D Para Python 3.13 (Windows):`);
806
1014
  console.log(' agroplan setup --python="C:\\Python311\\python.exe"');
807
1015
  console.log(`
@@ -834,6 +1042,9 @@ async function main() {
834
1042
  case "setup":
835
1043
  await setupCommand(force, pythonPath);
836
1044
  break;
1045
+ case "update":
1046
+ await updateCommand();
1047
+ break;
837
1048
  case "doctor":
838
1049
  await doctorCommand();
839
1050
  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.20",
4
4
  "description": "CLI global para AgroPlan AI - modo local acelerado",
5
5
  "type": "module",
6
6
  "bin": {