nolo-cli 0.206.1 → 0.207.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.
Files changed (113) hide show
  1. package/{_executeModel-U2XB3H4R.js → _executeModel-J7C6BIAS.js} +20 -20
  2. package/{agentDeleteCommand-NVXNQ2VQ.js → agentDeleteCommand-KMRFMAZZ.js} +36 -36
  3. package/{agentEmailCommands-VUJOYASY.js → agentEmailCommands-6QO4IX72.js} +35 -35
  4. package/{agentListCommands-KDRCBFUE.js → agentListCommands-CPI4EWX4.js} +27 -47
  5. package/{agentMachineCommands-TGZIF2SL.js → agentMachineCommands-HSSTZYNV.js} +16 -16
  6. package/{agentProviderCommands-SKW4L6NN.js → agentProviderCommands-EMKA6NAN.js} +2 -2
  7. package/{agentPullCommand-LGASFNH7.js → agentPullCommand-2JMJP5BS.js} +1 -1
  8. package/{agentRecordCommands-DM5UHNZM.js → agentRecordCommands-ZL5I4ODT.js} +32 -32
  9. package/{agentRunCommand-T6JGFAFZ.js → agentRunCommand-ROWADWSO.js} +33 -33
  10. package/{agentRunControl-GOH5VSQU.js → agentRunControl-45EM36PW.js} +3 -3
  11. package/{agentRuntimeLocal-N5S7NSJB.js → agentRuntimeLocal-MYHHTO4B.js} +12 -12
  12. package/{agentSlice-6XXGHTPP.js → agentSlice-OGOKIDXG.js} +1 -1
  13. package/{appDeleteCommands-VJNS4HSF.js → appDeleteCommands-DKINMBOK.js} +18 -18
  14. package/{appDeployCommands-HLZIEHUP.js → appDeployCommands-C3JX4GRQ.js} +18 -18
  15. package/{appDeployStatusCommands-PT64TF2T.js → appDeployStatusCommands-LVRMBYUP.js} +18 -18
  16. package/{appGetCommands-FM2ICAF7.js → appGetCommands-CSD32O6F.js} +18 -18
  17. package/{appListCommands-QVC3TKQD.js → appListCommands-YFEJLREL.js} +18 -18
  18. package/authCommand-22FYBEGY.js +69 -0
  19. package/{authCommands-MZUXPRYJ.js → authCommands-WK6E42L2.js} +2 -2
  20. package/{chromeOpsCommands-ECVS6CAO.js → chromeOpsCommands-HEN5AX2J.js} +1 -1
  21. package/{chunk-5ZBZHVMF.js → chunk-2GALTKXN.js} +36 -19
  22. package/{authCommand-NZC3H2EN.js → chunk-2NZUZIHB.js} +18 -43
  23. package/{chunk-JBWLZ3CB.js → chunk-2REKDWYL.js} +2 -2
  24. package/{chunk-DDVXTOFJ.js → chunk-36ZR37HK.js} +8 -8
  25. package/{chunk-PPCUXO3E.js → chunk-3RQVYR4B.js} +103 -0
  26. package/{chunk-YJ6UWOO5.js → chunk-3YYHTRF7.js} +2 -2
  27. package/{chunk-64K7WX26.js → chunk-4WVJLODK.js} +1 -1
  28. package/{chunk-5OJDQAJ2.js → chunk-5FMSOP2W.js} +2 -2
  29. package/{chunk-2Q3LOAFE.js → chunk-6HVBI6TI.js} +2 -2
  30. package/{chunk-U7HTU2S7.js → chunk-7AUQ3WCW.js} +1 -1
  31. package/{chunk-3UCYYSKN.js → chunk-7VTNQXNS.js} +29 -29
  32. package/{chunk-QSAUX2Q2.js → chunk-7WSZHITX.js} +2 -2
  33. package/{chunk-NUAQ3QHF.js → chunk-AFHKLTOB.js} +2 -2
  34. package/{chunk-LKV5K7PW.js → chunk-AJ7K2REY.js} +2 -2
  35. package/{chunk-P64WRQYV.js → chunk-AZMYUSVF.js} +1 -1
  36. package/{chunk-IAYMBPDZ.js → chunk-BRA5E6CI.js} +2 -2
  37. package/{chunk-5XNUQGLF.js → chunk-DLTR5MMT.js} +7 -7
  38. package/{chunk-4RERKW4Q.js → chunk-DTVCIIUZ.js} +5 -5
  39. package/{chunk-5BHQICF2.js → chunk-E32ZPIX6.js} +7 -6
  40. package/{chunk-73PRLLT6.js → chunk-EI77BHWD.js} +5 -5
  41. package/{chunk-WPOKOKZA.js → chunk-EPRYABUO.js} +1 -1
  42. package/{chunk-WC6TH54L.js → chunk-FSGQN6RC.js} +5 -5
  43. package/{chunk-7LJEJV4F.js → chunk-GMEAELJ6.js} +88 -1
  44. package/{chunk-YF4ZRVP3.js → chunk-HXHPAEAN.js} +1 -1
  45. package/{chunk-7DQSP7JU.js → chunk-J5JTMQIA.js} +1 -1
  46. package/{chunk-EVG6HQQ7.js → chunk-JBOUVTZX.js} +2 -2
  47. package/{chunk-D3DGBEYY.js → chunk-JUNMZOX6.js} +2 -2
  48. package/{chunk-7T5TLIY4.js → chunk-LKDF3ATR.js} +1 -1
  49. package/{chunk-LEJSZV6V.js → chunk-P2ZLUIW2.js} +243 -15
  50. package/{chunk-PK5TD4ST.js → chunk-PQTOTGMI.js} +1 -1
  51. package/{chunk-3ZUXGHFS.js → chunk-Q54YKNWP.js} +4 -80
  52. package/{chunk-LDPZBAQK.js → chunk-Q55XFXQ6.js} +2 -2
  53. package/{chunk-L5FZUSB6.js → chunk-QVUYL2TW.js} +3 -3
  54. package/{chunk-XNOILBHV.js → chunk-QWHAFJIJ.js} +1 -1
  55. package/{chunk-W45PCJHS.js → chunk-R56VAYY4.js} +1 -1
  56. package/{chunk-4NWJ3Z3G.js → chunk-RIGJPEBW.js} +1 -1
  57. package/{chunk-K7ZZPUNO.js → chunk-RTAVELOC.js} +12 -12
  58. package/{chunk-5MXA4LWL.js → chunk-U6QSCADP.js} +1 -1
  59. package/{chunk-ZCKXJTCW.js → chunk-UDHMQGMR.js} +10 -10
  60. package/{chunk-7NMNKOW5.js → chunk-UVXVWXYH.js} +2 -2
  61. package/{chunk-JASKVAYJ.js → chunk-UYY2CECP.js} +2 -2
  62. package/{chunk-6AMR3AE6.js → chunk-UZT65S6D.js} +12 -1
  63. package/{chunk-LTI5T3A6.js → chunk-VY3D2DSK.js} +1 -1
  64. package/{chunk-SEOM7GLZ.js → chunk-WADDWY7O.js} +1 -1
  65. package/{chunk-YZGNKHUM.js → chunk-WBSCOXFS.js} +1 -1
  66. package/{chunk-2PW2KOII.js → chunk-XBZDTBTK.js} +2 -2
  67. package/{chunk-ZRDUMMDG.js → chunk-XDLQYUBV.js} +9 -7
  68. package/{chunk-UGCQKKXW.js → chunk-XE4Q46FF.js} +1 -1
  69. package/{chunk-BAPZCPYU.js → chunk-XKH3DAKH.js} +1 -1
  70. package/{chunk-MNWKNN6V.js → chunk-XXYDK7L5.js} +1 -1
  71. package/{chunk-2GKUVGRT.js → chunk-XYKRRB5Z.js} +13 -5
  72. package/{chunk-Y3ASVJWL.js → chunk-ZG6RWZGY.js} +3 -3
  73. package/{chunk-AWVFQMOV.js → chunk-ZYKJBRZ3.js} +5 -1
  74. package/{commandRegistry-PASVNTAX.js → commandRegistry-3WR5YAN4.js} +70 -70
  75. package/{contentThunks-IXBWQP4P.js → contentThunks-4AJV2XJY.js} +4 -4
  76. package/{cooldownCommands-I4ETQ4AO.js → cooldownCommands-YL7H74YB.js} +3 -3
  77. package/{createAgentAutomationAction-7O7PFPDO.js → createAgentAutomationAction-YMY5N7IX.js} +4 -4
  78. package/{createDialogAction-DRHO4XCF.js → createDialogAction-RIMBMOTA.js} +5 -5
  79. package/{createPageAction-TFGJRDZX.js → createPageAction-MDNA4BXK.js} +4 -4
  80. package/{db-2QOTXYGH.js → db-HUCI5R4G.js} +2 -2
  81. package/{dialogCommands-RYIONJLY.js → dialogCommands-LH6ILXLQ.js} +21 -21
  82. package/{dialogSlice-CXIZ5UTI.js → dialogSlice-JWULZZKI.js} +3 -3
  83. package/{dialogUsageCommand-QTG6ILEJ.js → dialogUsageCommand-ZCPPHPJ5.js} +1 -1
  84. package/{docCreateCommands-KC2V2RPX.js → docCreateCommands-ZJV2YVBO.js} +16 -16
  85. package/{docDeleteCommands-S2SDQL2S.js → docDeleteCommands-5YMS6VX6.js} +17 -17
  86. package/{docReadCommands-3YGFKAOZ.js → docReadCommands-UCHOA64J.js} +16 -16
  87. package/{docStore-5AHNSAEI.js → docStore-IGB6VYJW.js} +1 -1
  88. package/{docUpdateCommands-PU6MQTLW.js → docUpdateCommands-R7DXVPBN.js} +16 -16
  89. package/{getPricing-3PQY3TGI.js → getPricing-RPAQXFXY.js} +1 -1
  90. package/{handleSendMessageAction-SO3PD3YA.js → handleSendMessageAction-2TN3FOIF.js} +12 -12
  91. package/index.js +7 -7
  92. package/{localDialogRead-FUXGZ57B.js → localDialogRead-5VCMQQZF.js} +1 -1
  93. package/{localRuntimeAdapter-5B7QODVK.js → localRuntimeAdapter-QLD7V33U.js} +29 -29
  94. package/{localRuntimeAuthority-NEGF3LRQ.js → localRuntimeAuthority-OYH4AE4G.js} +2 -2
  95. package/{localRuntimeDb-SDYFAEKA.js → localRuntimeDb-VBIMCWUC.js} +1 -1
  96. package/{machineCommands-U3DO4TFR.js → machineCommands-3TQNL2KD.js} +30 -30
  97. package/{machineWsRunDispatch-Y3IMIZO7.js → machineWsRunDispatch-6Z6KSDUJ.js} +30 -30
  98. package/package.json +1 -1
  99. package/{providerPresetApply-EQESXT6X.js → providerPresetApply-YKCAQCBR.js} +3 -3
  100. package/{providerRegistry-PZ56P43E.js → providerRegistry-QBBABMUW.js} +3 -3
  101. package/{readlineWorkspace-32IDD2MQ.js → readlineWorkspace-NHPGVRF6.js} +558 -139
  102. package/{removeDialogAgentAction-BDLO7UC2.js → removeDialogAgentAction-GZ56EZZI.js} +1 -1
  103. package/{runAgentClientLoop-ERVJ4LFY.js → runAgentClientLoop-P3ZALQBG.js} +18 -18
  104. package/{runtimeDoctorCommands-3VFVTGPI.js → runtimeDoctorCommands-3R3ZOZVS.js} +5 -5
  105. package/{secretCommands-RLIO3QK5.js → secretCommands-ZCZ4KVET.js} +1 -1
  106. package/{setPrimaryDialogAgentAction-PGBTR247.js → setPrimaryDialogAgentAction-JPTPBQH4.js} +1 -1
  107. package/{spaceCommands-4UWABUD7.js → spaceCommands-VZ4FGE6E.js} +15 -15
  108. package/{streamAgentChatTurn-2M4L7PF4.js → streamAgentChatTurn-TXTRBFOW.js} +22 -22
  109. package/{tools-GINHFGST.js → tools-72N432Y2.js} +13 -13
  110. package/{tuiSummaryLlmCaller-CEIZAKUV.js → tuiSummaryLlmCaller-WJBM4E2H.js} +6 -6
  111. package/{updateCommands-X23W5F73.js → updateCommands-Q6CYAEYJ.js} +3 -3
  112. package/{updateDialogTitleAction-4EIHKTKR.js → updateDialogTitleAction-EWTTA5A4.js} +4 -4
  113. package/{windowsSelfUpdate-SVJKL6VH.js → windowsSelfUpdate-XSQVF2GK.js} +2 -2
@@ -3,7 +3,7 @@ import {
3
3
  } from "./chunk-YGILMZ7N.js";
4
4
  import {
5
5
  getReadableCliDb
6
- } from "./chunk-7DQSP7JU.js";
6
+ } from "./chunk-J5JTMQIA.js";
7
7
  import {
8
8
  buildCreatedAgentRecord,
9
9
  buildUpdatedAgentRecord,
@@ -13,13 +13,13 @@ import {
13
13
  resolveAgentRecordFromHybridStore,
14
14
  sanitizeAgentRecordForCliOutput,
15
15
  writeAgentRecord
16
- } from "./chunk-2PW2KOII.js";
16
+ } from "./chunk-XBZDTBTK.js";
17
17
  import {
18
18
  clearCliLocalRuntimePreparedAgentCache
19
- } from "./chunk-3UCYYSKN.js";
19
+ } from "./chunk-7VTNQXNS.js";
20
20
  import {
21
21
  readCredentialAvailability
22
- } from "./chunk-W45PCJHS.js";
22
+ } from "./chunk-R56VAYY4.js";
23
23
  import {
24
24
  resolveCliAgentKeyInput
25
25
  } from "./chunk-NBTY7YJF.js";
@@ -244,7 +244,7 @@ async function runAgentCreateCommand(args, deps = {}) {
244
244
  let verifyResult;
245
245
  if (parsed.verify) {
246
246
  try {
247
- const { verifyCustomProvider } = await import("./agentProviderCommands-SKW4L6NN.js");
247
+ const { verifyCustomProvider } = await import("./agentProviderCommands-EMKA6NAN.js");
248
248
  const rec = built.nextRecord;
249
249
  verifyResult = await verifyCustomProvider({
250
250
  providerUrl: rec.customProviderUrl,
@@ -7,7 +7,7 @@ import {
7
7
  } from "./chunk-YUA6OAH5.js";
8
8
  import {
9
9
  CLI_PROVIDER_VALUES
10
- } from "./chunk-5BHQICF2.js";
10
+ } from "./chunk-E32ZPIX6.js";
11
11
  import {
12
12
  normalizeServerOrigin
13
13
  } from "./chunk-CF7PE763.js";
@@ -1,16 +1,16 @@
1
1
  import {
2
2
  createCliLocalRuntimeAdapter,
3
3
  summarizeEndpoint
4
- } from "./chunk-3UCYYSKN.js";
4
+ } from "./chunk-7VTNQXNS.js";
5
5
  import {
6
6
  clipMultilineText
7
- } from "./chunk-QSAUX2Q2.js";
7
+ } from "./chunk-7WSZHITX.js";
8
8
  import {
9
9
  runLocalAgentTurn
10
- } from "./chunk-ZRDUMMDG.js";
10
+ } from "./chunk-XDLQYUBV.js";
11
11
  import {
12
12
  applyToolSurfaceConstraints
13
- } from "./chunk-2Q3LOAFE.js";
13
+ } from "./chunk-6HVBI6TI.js";
14
14
  import {
15
15
  resolveLocalRuntimeEnvFromPolicy
16
16
  } from "./chunk-TRZP7JZ7.js";
@@ -38,7 +38,7 @@ import {
38
38
  } from "./chunk-4O22PGNQ.js";
39
39
  import {
40
40
  t
41
- } from "./chunk-PPCUXO3E.js";
41
+ } from "./chunk-3RQVYR4B.js";
42
42
  import {
43
43
  asTrimmedNonEmptyStringArray
44
44
  } from "./chunk-I42VC5KR.js";
@@ -70,6 +70,85 @@ function parseResetsInMs(text) {
70
70
  var DEFAULT_QUOTA_BREAKER_MS = 6 * 3600 * 1e3;
71
71
  var DEFAULT_AGENT_NOT_FOUND_BREAKER_MS = 15 * 60 * 1e3;
72
72
 
73
+ // packages/ai/agent/quotaSnapshot.ts
74
+ function isQuotaWindowExpired(window, now) {
75
+ const resetAt = window?.resetAt;
76
+ return typeof resetAt === "number" && Number.isFinite(resetAt) && resetAt <= now;
77
+ }
78
+ function findTightestQuotaWindow(quota, now = Date.now()) {
79
+ if (!quota || !Array.isArray(quota.windows) || quota.windows.length === 0) {
80
+ return void 0;
81
+ }
82
+ let best;
83
+ let bestScore = -Infinity;
84
+ for (const w of quota.windows) {
85
+ let score = 0;
86
+ if (typeof w.utilization === "number" && w.utilization >= 0) {
87
+ score = 500 + Math.min(w.utilization, 1) * 500;
88
+ } else if (typeof w.remaining === "number" && typeof w.limit === "number" && w.limit > 0) {
89
+ const util = Math.max(0, 1 - w.remaining / w.limit);
90
+ score = 500 + util * 500;
91
+ } else if (typeof w.resetAt === "number" && w.resetAt > now) {
92
+ score = 200;
93
+ } else if (typeof w.remaining === "number") {
94
+ score = 100;
95
+ }
96
+ if (score > bestScore) {
97
+ bestScore = score;
98
+ best = w;
99
+ }
100
+ }
101
+ return best ?? quota.windows[0];
102
+ }
103
+ function formatQuotaSummary(quota, now = Date.now(), options) {
104
+ const compact = options?.compact === true;
105
+ const planText = formatPlanLabel(quota?.plan);
106
+ const planName = typeof quota?.plan?.name === "string" ? quota.plan.name.trim() : "";
107
+ const tightest = findTightestQuotaWindow(quota, now);
108
+ if (!tightest) return compact ? planName || void 0 : planText;
109
+ const parts = [];
110
+ if (typeof tightest.utilization === "number") {
111
+ const pct = Math.round(tightest.utilization * 100);
112
+ parts.push(`${pct}%\u5DF2\u7528`);
113
+ } else if (typeof tightest.remaining === "number") {
114
+ if (typeof tightest.limit === "number") {
115
+ parts.push(`${tightest.remaining}/${tightest.limit}${tightest.unit ? ` ${tightest.unit}` : ""}`);
116
+ } else {
117
+ parts.push(`\u4F59${tightest.remaining}${tightest.unit ? ` ${tightest.unit}` : ""}`);
118
+ }
119
+ }
120
+ if (compact) {
121
+ const head = parts.length > 0 ? parts[0] : void 0;
122
+ return [planName || void 0, head].filter(Boolean).join(" \xB7 ") || void 0;
123
+ }
124
+ if (tightest.scope && tightest.scope !== "user" && tightest.scope !== "project" && tightest.scope !== tightest.unit) {
125
+ parts.push(tightest.scope);
126
+ }
127
+ if (typeof tightest.resetAt === "number" && tightest.resetAt > now) {
128
+ const diffSec = Math.round((tightest.resetAt - now) / 1e3);
129
+ if (diffSec < 60) {
130
+ parts.push(`${diffSec}s\u540E\u91CD\u7F6E`);
131
+ } else if (diffSec < 3600) {
132
+ parts.push(`${Math.round(diffSec / 60)}m\u540E\u91CD\u7F6E`);
133
+ } else if (diffSec < 86400) {
134
+ const hours = (diffSec / 3600).toFixed(1).replace(/\.0$/, "");
135
+ parts.push(`${hours}h\u540E\u91CD\u7F6E`);
136
+ } else {
137
+ const days = (diffSec / 86400).toFixed(1).replace(/\.0$/, "");
138
+ parts.push(`${days}d\u540E\u91CD\u7F6E`);
139
+ }
140
+ }
141
+ const onlyScope = parts.length === 0 || parts.length === 1 && parts[0] === tightest.scope;
142
+ if (onlyScope) return planText;
143
+ return [planText, ...parts].filter(Boolean).join(" \xB7 ");
144
+ }
145
+ function formatPlanLabel(plan) {
146
+ const name = typeof plan?.name === "string" ? plan.name.trim() : "";
147
+ if (!name) return void 0;
148
+ const credits = typeof plan?.monthlyCreditsUsd === "number" && Number.isFinite(plan.monthlyCreditsUsd) && plan.monthlyCreditsUsd > 0 ? `\u6708\u5EA6\u989D\u5EA6 $${plan.monthlyCreditsUsd}` : void 0;
149
+ return [`${name} \u5957\u9910`, credits].filter(Boolean).join(" \xB7 ");
150
+ }
151
+
73
152
  // packages/ai/agent/agentAvailabilityShared.ts
74
153
  var DEFAULT_PROVIDER_RETRY_MS = 5 * 60 * 1e3;
75
154
  var THIN_RATE_LIMIT_COOLDOWN_MS = 60 * 1e3;
@@ -110,7 +189,8 @@ function shouldClearCooldownFromQuota(entry, quota, now, options) {
110
189
  );
111
190
  const subscriptionWindows = relevantWindows.filter(isSubscriptionPeriodWindow);
112
191
  if (subscriptionWindows.length === 0) return false;
113
- if (relevantWindows.some((window) => !isSubscriptionPeriodWindow(window) && isExhaustedWindow(window))) return false;
192
+ if (relevantWindows.some(isExhaustedWindow)) return false;
193
+ if (subscriptionWindows.some((window) => isQuotaWindowExpired(window, now))) return false;
114
194
  return subscriptionWindows.every((window) => {
115
195
  const hasUtilization = typeof window.utilization === "number";
116
196
  const hasRemaining = typeof window.remaining === "number";
@@ -194,6 +274,12 @@ function resolveAgentAvailability(agent, now = Date.now()) {
194
274
  reason: "stale_quota_snapshot"
195
275
  };
196
276
  }
277
+ if (!relevantWindows.some((window) => !isQuotaWindowExpired(window, now))) {
278
+ return {
279
+ status: "unverified",
280
+ reason: "quota_window_reset"
281
+ };
282
+ }
197
283
  return {
198
284
  status: "available",
199
285
  reason: "quota_ok"
@@ -573,6 +659,7 @@ function classifyFailureSubclass(input, now = Date.now()) {
573
659
  export {
574
660
  QUOTA_ERROR_PATTERNS,
575
661
  isQuotaExhaustedError,
662
+ formatQuotaSummary,
576
663
  DEFAULT_PROVIDER_RETRY_MS,
577
664
  shouldClearCooldownFromQuota,
578
665
  isAgentUnavailableNow,
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  trimTrailingSlash
3
- } from "./chunk-WPOKOKZA.js";
3
+ } from "./chunk-EPRYABUO.js";
4
4
  import {
5
5
  commandCodeModels,
6
6
  kimiCodeModels,
@@ -4,7 +4,7 @@ import {
4
4
 
5
5
  // packages/cli/agentCommandSupport.ts
6
6
  async function getDefaultCliDb() {
7
- const { getDefaultCliLocalRuntimeDb } = await import("./localRuntimeDb-SDYFAEKA.js");
7
+ const { getDefaultCliLocalRuntimeDb } = await import("./localRuntimeDb-VBIMCWUC.js");
8
8
  return getDefaultCliLocalRuntimeDb();
9
9
  }
10
10
  function createNullCliDb() {
@@ -15,10 +15,10 @@ import {
15
15
  } from "./chunk-4O22PGNQ.js";
16
16
  import {
17
17
  scheduleWindowsSelfUpdate
18
- } from "./chunk-7T5TLIY4.js";
18
+ } from "./chunk-LKDF3ATR.js";
19
19
  import {
20
20
  t
21
- } from "./chunk-PPCUXO3E.js";
21
+ } from "./chunk-3RQVYR4B.js";
22
22
 
23
23
  // packages/cli/updateCommands.ts
24
24
  import { existsSync, readFileSync, accessSync, constants } from "node:fs";
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  requireTokenUser
3
- } from "./chunk-4NWJ3Z3G.js";
3
+ } from "./chunk-RIGJPEBW.js";
4
4
  import {
5
5
  resolveServerUrl
6
6
  } from "./chunk-WACI5I6V.js";
7
7
  import {
8
8
  t
9
- } from "./chunk-PPCUXO3E.js";
9
+ } from "./chunk-3RQVYR4B.js";
10
10
 
11
11
  // packages/cli/cliApiClient.ts
12
12
  var CliApiError = class extends Error {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  t
3
- } from "./chunk-PPCUXO3E.js";
3
+ } from "./chunk-3RQVYR4B.js";
4
4
 
5
5
  // packages/cli/windowsSelfUpdate.ts
6
6
  import { spawn } from "node:child_process";
@@ -1,8 +1,9 @@
1
1
  import {
2
+ Level,
2
3
  createLegacyServerDb,
3
4
  createLevelAuthorityStore,
4
5
  isLevelLockError
5
- } from "./chunk-AWVFQMOV.js";
6
+ } from "./chunk-ZYKJBRZ3.js";
6
7
  import {
7
8
  createCliAuthorityBrokerClient,
8
9
  createCliAuthorityBrokerSocketInvoker,
@@ -21,13 +22,188 @@ import {
21
22
  } from "./chunk-HNMXYYJR.js";
22
23
 
23
24
  // packages/cli/localRuntimeAuthority.ts
24
- import fs2 from "node:fs";
25
- import path2 from "node:path";
25
+ import fs4 from "node:fs";
26
+ import path4 from "node:path";
26
27
 
27
28
  // packages/database-engine/cliAuthorityBrokerServer.ts
29
+ import fs3 from "node:fs";
30
+ import path3 from "node:path";
31
+ import { createServer } from "node:net";
32
+
33
+ // packages/database-engine/levelDbCorruptionRecovery.ts
28
34
  import fs from "node:fs";
29
35
  import path from "node:path";
30
- import { createServer } from "node:net";
36
+ var CORRUPTION_CODE = "LEVEL_CORRUPTION";
37
+ var CORRUPTION_MESSAGE = /Corruption:|missing files/i;
38
+ var levelClassWithRepair = Level;
39
+ function isLevelCorruptionError(error) {
40
+ const seen = /* @__PURE__ */ new Set();
41
+ let current = error;
42
+ while (current && !seen.has(current)) {
43
+ seen.add(current);
44
+ if (current.code === CORRUPTION_CODE) return true;
45
+ if (CORRUPTION_MESSAGE.test(toErrorMessage(current))) return true;
46
+ current = current.cause;
47
+ }
48
+ return false;
49
+ }
50
+ function formatUtcStamp(now) {
51
+ return new Date(now).toISOString().replace(/[-:]/g, "").replace(/\.\d{3}Z$/, "").replace("T", "-");
52
+ }
53
+ function resolveBackupPath(dbPath, now) {
54
+ const base = `${dbPath}.corrupt-${formatUtcStamp(now)}`;
55
+ let candidate = base;
56
+ for (let index = 2; fs.existsSync(candidate); index += 1) {
57
+ candidate = `${base}-${index}`;
58
+ }
59
+ return candidate;
60
+ }
61
+ async function repairLevelDatabase(dbPath) {
62
+ await levelClassWithRepair.repair(dbPath);
63
+ }
64
+ async function recoverCorruptedLevelDb(options) {
65
+ const { dbPath } = options;
66
+ const log = options.log ?? ((message) => console.warn(message));
67
+ const repair = options.repair ?? repairLevelDatabase;
68
+ const backupPath = resolveBackupPath(dbPath, (options.now ?? Date.now)());
69
+ fs.renameSync(dbPath, backupPath);
70
+ try {
71
+ fs.cpSync(backupPath, dbPath, { recursive: true, preserveTimestamps: true });
72
+ await repair(dbPath);
73
+ } catch (error) {
74
+ try {
75
+ fs.rmSync(dbPath, { recursive: true, force: true });
76
+ fs.renameSync(backupPath, dbPath);
77
+ } catch (rollbackError) {
78
+ throw Object.assign(
79
+ new Error(
80
+ `Failed to repair the local database at ${dbPath} and could not restore the original. The untouched copy is at ${backupPath}; stop every Nolo process before retrying. Do not delete ${path.join(dbPath, "LOCK")} and do not reinstall Nolo: ${toErrorMessage(error)}`,
81
+ { cause: new AggregateError([error, rollbackError], "LevelDB repair and rollback both failed") }
82
+ ),
83
+ { code: CORRUPTION_CODE, backupPath }
84
+ );
85
+ }
86
+ throw Object.assign(
87
+ new Error(
88
+ `Failed to repair the local database at ${dbPath}; the original database was restored unchanged. Stop every Nolo process and run the CLI again. Do not delete ${path.join(dbPath, "LOCK")} and do not reinstall Nolo: ${toErrorMessage(error)}`,
89
+ { cause: error }
90
+ ),
91
+ { code: CORRUPTION_CODE, backupPath }
92
+ );
93
+ }
94
+ log(
95
+ `[nolo] local database corruption detected; preserved original at ${backupPath} and repaired a copy.`
96
+ );
97
+ return { backupPath };
98
+ }
99
+
100
+ // packages/database-engine/levelDbOwnershipLock.ts
101
+ import fs2 from "node:fs";
102
+ import path2 from "node:path";
103
+ var LOCKED_CODE = "LEVEL_LOCKED";
104
+ var UNWRITTEN_LOCK_GRACE_MS = 5e3;
105
+ function createLockError(lockPath, ownerPid) {
106
+ const detail = ownerPid === void 0 ? `the lock file ${lockPath} exists but its owner process is unknown` : `it is held by process ${ownerPid}`;
107
+ return Object.assign(
108
+ new Error(
109
+ `CLI authority database is already open by another process: ${detail} (${lockPath}). Wait for that process to exit, or stop it before starting Nolo again.`
110
+ ),
111
+ { code: LOCKED_CODE, lockPath, ownerPid }
112
+ );
113
+ }
114
+ function isProcessAlive(pid) {
115
+ try {
116
+ process.kill(pid, 0);
117
+ return true;
118
+ } catch (error) {
119
+ return error.code === "EPERM";
120
+ }
121
+ }
122
+ function readLockHolder(lockPath) {
123
+ let raw;
124
+ try {
125
+ raw = fs2.readFileSync(lockPath, "utf8");
126
+ } catch (error) {
127
+ if (error.code === "ENOENT") return void 0;
128
+ throw error;
129
+ }
130
+ let pid;
131
+ try {
132
+ const parsed = JSON.parse(raw);
133
+ if (typeof parsed.pid === "number" && Number.isInteger(parsed.pid) && parsed.pid > 0) {
134
+ pid = parsed.pid;
135
+ }
136
+ } catch {
137
+ }
138
+ let mtimeMs = Date.now();
139
+ try {
140
+ mtimeMs = fs2.statSync(lockPath).mtimeMs;
141
+ } catch {
142
+ }
143
+ return { pid, mtimeMs };
144
+ }
145
+ function acquireLevelDbOwnershipLock(dbPath) {
146
+ const lockPath = `${dbPath}.owner`;
147
+ fs2.mkdirSync(path2.dirname(lockPath), { recursive: true });
148
+ const content = `${JSON.stringify({ pid: process.pid, startedAt: (/* @__PURE__ */ new Date()).toISOString() })}
149
+ `;
150
+ for (let attempt = 0; attempt < 3; attempt += 1) {
151
+ let fd;
152
+ try {
153
+ fd = fs2.openSync(lockPath, "wx", 420);
154
+ } catch (error) {
155
+ if (error.code !== "EEXIST") throw error;
156
+ const holder = readLockHolder(lockPath);
157
+ if (!holder) continue;
158
+ if (holder.pid !== void 0 && isProcessAlive(holder.pid)) {
159
+ throw createLockError(lockPath, holder.pid);
160
+ }
161
+ if (holder.pid === void 0 && Date.now() - holder.mtimeMs < UNWRITTEN_LOCK_GRACE_MS) {
162
+ throw createLockError(lockPath);
163
+ }
164
+ const quarantine = `${lockPath}.stale-${process.pid}-${Date.now()}`;
165
+ try {
166
+ fs2.renameSync(lockPath, quarantine);
167
+ fs2.rmSync(quarantine, { force: true });
168
+ } catch (renameError) {
169
+ if (renameError.code !== "ENOENT") throw renameError;
170
+ }
171
+ continue;
172
+ }
173
+ try {
174
+ fs2.writeSync(fd, content);
175
+ } catch (error) {
176
+ try {
177
+ fs2.closeSync(fd);
178
+ } catch {
179
+ }
180
+ try {
181
+ fs2.rmSync(lockPath, { force: true });
182
+ } catch {
183
+ }
184
+ throw error;
185
+ }
186
+ let released = false;
187
+ return {
188
+ lockPath,
189
+ release() {
190
+ if (released) return;
191
+ released = true;
192
+ try {
193
+ fs2.closeSync(fd);
194
+ } catch {
195
+ }
196
+ try {
197
+ fs2.rmSync(lockPath, { force: true });
198
+ } catch {
199
+ }
200
+ }
201
+ };
202
+ }
203
+ throw createLockError(lockPath);
204
+ }
205
+
206
+ // packages/database-engine/cliAuthorityBrokerServer.ts
31
207
  var brokerRegistry = /* @__PURE__ */ new Map();
32
208
  var databaseOwners = /* @__PURE__ */ new Map();
33
209
  var DEFAULT_ITERATOR_LIMIT = 200;
@@ -57,18 +233,18 @@ function buildListeningEndpoint(server, target) {
57
233
  return `tcp://${target.host}:${info.port}`;
58
234
  }
59
235
  function ensureParentDir(filePath) {
60
- fs.mkdirSync(path.dirname(filePath), { recursive: true });
236
+ fs3.mkdirSync(path3.dirname(filePath), { recursive: true });
61
237
  }
62
238
  function writeJsonFile(filePath, data) {
63
239
  if (!filePath) return;
64
240
  ensureParentDir(filePath);
65
- fs.writeFileSync(filePath, `${JSON.stringify(data, null, 2)}
241
+ fs3.writeFileSync(filePath, `${JSON.stringify(data, null, 2)}
66
242
  `, "utf8");
67
243
  }
68
244
  function removeFileIfPresent(filePath) {
69
245
  if (!filePath) return;
70
246
  try {
71
- fs.rmSync(filePath, { force: true });
247
+ fs3.rmSync(filePath, { force: true });
72
248
  } catch {
73
249
  }
74
250
  }
@@ -140,10 +316,55 @@ async function dispatchCliAuthorityBrokerRequest(store, request) {
140
316
  return createErrorResponse(error);
141
317
  }
142
318
  }
319
+ async function openAuthorityStoreWithCorruptionRecovery(options, track) {
320
+ let attemptStore;
321
+ try {
322
+ attemptStore = await options.createStore();
323
+ track(attemptStore);
324
+ await attemptStore.open();
325
+ return attemptStore;
326
+ } catch (error) {
327
+ if (!options.dbPath || !isLevelCorruptionError(error)) throw error;
328
+ if (attemptStore) {
329
+ try {
330
+ await attemptStore.close();
331
+ } catch (closeError) {
332
+ throw Object.assign(
333
+ new Error(
334
+ `LevelDB corruption detected at ${options.dbPath}, but the failed database handle could not be closed; on-disk files were left untouched. Stop every Nolo process and retry: ${toErrorMessage(closeError)}`,
335
+ { cause: closeError }
336
+ ),
337
+ { code: "LEVEL_CORRUPTION" }
338
+ );
339
+ }
340
+ track(void 0);
341
+ attemptStore = void 0;
342
+ }
343
+ const { backupPath } = await recoverCorruptedLevelDb({
344
+ dbPath: options.dbPath,
345
+ now: options.now
346
+ });
347
+ try {
348
+ attemptStore = await options.createStore();
349
+ track(attemptStore);
350
+ await attemptStore.open();
351
+ return attemptStore;
352
+ } catch (retryError) {
353
+ throw Object.assign(
354
+ new Error(
355
+ `Local database corruption at ${options.dbPath} was preserved at ${backupPath}, but reopening the repaired copy failed: ${toErrorMessage(retryError)}. Do not reinstall Nolo and do not delete ${path3.join(options.dbPath, "LOCK")}; the preserved original database is at ${backupPath}.`,
356
+ { cause: retryError }
357
+ ),
358
+ { code: "LEVEL_CORRUPTION", backupPath }
359
+ );
360
+ }
361
+ }
362
+ }
143
363
  async function createBrokerHandle(options) {
144
364
  const target = resolveBrokerListenTarget(options.endpoint);
145
365
  const socketMode = (options.transportMode ?? "socket") === "socket";
146
366
  let store;
367
+ let ownershipLock;
147
368
  const sockets = /* @__PURE__ */ new Set();
148
369
  const server = createServer((socket) => {
149
370
  sockets.add(socket);
@@ -174,8 +395,12 @@ async function createBrokerHandle(options) {
174
395
  });
175
396
  server.unref();
176
397
  }
177
- store = await options.createStore();
178
- await store.open();
398
+ if (options.dbPath) {
399
+ ownershipLock = acquireLevelDbOwnershipLock(options.dbPath);
400
+ }
401
+ store = await openAuthorityStoreWithCorruptionRecovery(options, (created) => {
402
+ store = created;
403
+ });
179
404
  storeReady = true;
180
405
  const readyStore = store;
181
406
  const now = options.now ?? Date.now;
@@ -212,6 +437,8 @@ async function createBrokerHandle(options) {
212
437
  await readyStore.close();
213
438
  brokerRegistry.delete(options.endpoint);
214
439
  releaseDatabaseOwnership(options);
440
+ ownershipLock?.release();
441
+ ownershipLock = void 0;
215
442
  removeFileIfPresent(options.metadataPath);
216
443
  removeFileIfPresent(options.healthPath);
217
444
  })().catch((error) => {
@@ -234,6 +461,7 @@ async function createBrokerHandle(options) {
234
461
  throw Object.assign(new AggregateError([error, closeError], "Broker startup failed and the native authority store could not close"), { retainAuthorityOwnership: true });
235
462
  }
236
463
  }
464
+ ownershipLock?.release();
237
465
  throw error;
238
466
  }
239
467
  }
@@ -259,14 +487,14 @@ function bindSocketRequestHandler(args) {
259
487
  });
260
488
  }
261
489
  function canonicalDatabasePath(dbPath) {
262
- const absolute = path.resolve(dbPath);
490
+ const absolute = path3.resolve(dbPath);
263
491
  try {
264
- return fs.realpathSync(absolute);
492
+ return fs3.realpathSync(absolute);
265
493
  } catch (error) {
266
494
  if (error.code !== "ENOENT") throw error;
267
- const parent = path.dirname(absolute);
495
+ const parent = path3.dirname(absolute);
268
496
  if (parent === absolute) throw error;
269
- return path.join(canonicalDatabasePath(parent), path.basename(absolute));
497
+ return path3.join(canonicalDatabasePath(parent), path3.basename(absolute));
270
498
  }
271
499
  }
272
500
  function releaseDatabaseOwnership(options) {
@@ -302,7 +530,7 @@ function getOrCreateCliAuthorityBrokerServer(options) {
302
530
 
303
531
  // packages/cli/localRuntimeAuthority.ts
304
532
  function ensureDbParentDir(dbPath) {
305
- fs2.mkdirSync(path2.dirname(dbPath), { recursive: true });
533
+ fs4.mkdirSync(path4.dirname(dbPath), { recursive: true });
306
534
  }
307
535
  function findCliAuthorityCorruption(error) {
308
536
  const seen = /* @__PURE__ */ new Set();
@@ -336,7 +564,7 @@ async function sleep(ms) {
336
564
  await new Promise((resolve) => setTimeout(resolve, ms));
337
565
  }
338
566
  function resolveCliLocalRuntimeDbPath(options = {}) {
339
- return path2.join(
567
+ return path4.join(
340
568
  resolveNoloHome({
341
569
  env: options.env,
342
570
  homeDir: options.homeDir
@@ -7,7 +7,7 @@ import {
7
7
  } from "./chunk-XPHZK3PJ.js";
8
8
  import {
9
9
  resolvePlatformAuthToken
10
- } from "./chunk-WPOKOKZA.js";
10
+ } from "./chunk-EPRYABUO.js";
11
11
  import {
12
12
  isRecord
13
13
  } from "./chunk-KUG52IAP.js";