nolo-cli 0.8.0-alpha.2 → 0.8.0-alpha.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.
Files changed (188) hide show
  1. package/README.md +1 -1
  2. package/_executeModel-42U3VOVZ.js +205 -0
  3. package/action-TLI3V62L.js +28 -0
  4. package/addContentAction-57RSIIMR.js +26 -0
  5. package/addDialogAgentAction-G3VWEA6E.js +68 -0
  6. package/agentDeleteCommand-5DD2IM3J.js +327 -0
  7. package/agentEmailCommands-6FACJBU4.js +628 -0
  8. package/agentListCommands-I6KZYCIG.js +223 -0
  9. package/agentMachineCommands-VKLIGMZA.js +425 -0
  10. package/agentPullCommand-O2MTUAFR.js +122 -0
  11. package/agentRecordCommands-7TZICYDT.js +96 -0
  12. package/agentRunCommand-L4OM23KV.js +114 -0
  13. package/agentRunControl-K4VKNEHF.js +57 -0
  14. package/agentRuntimeLocal-ZYEIPTY4.js +104 -0
  15. package/agentSlice-BX7GXSNO.js +42 -0
  16. package/authCommand-EB5JSOX5.js +581 -0
  17. package/authCommands-XPEHTKSM.js +35 -0
  18. package/chunk-25LCXTML.js +175 -0
  19. package/chunk-2ECQG4YX.js +22296 -0
  20. package/chunk-2FTTDCD4.js +675 -0
  21. package/chunk-2JCXITPK.js +1078 -0
  22. package/chunk-3ASDTTEI.js +1774 -0
  23. package/chunk-3EUW3WEO.js +8 -0
  24. package/chunk-3LY4F7SV.js +9293 -0
  25. package/chunk-4CQLVGRV.js +50 -0
  26. package/chunk-4IJYA27C.js +342 -0
  27. package/chunk-4O3CARJ4.js +231 -0
  28. package/chunk-4QEWT7KD.js +933 -0
  29. package/chunk-4SN6J65J.js +38 -0
  30. package/chunk-4VNS5WPM.js +42 -0
  31. package/chunk-4XENYTF5.js +222 -0
  32. package/chunk-4ZDM73SD.js +34 -0
  33. package/chunk-5CS33IBL.js +301 -0
  34. package/chunk-5EFXE3O7.js +138 -0
  35. package/chunk-5KLGBAAR.js +386 -0
  36. package/chunk-5MIDPSSK.js +206 -0
  37. package/chunk-5MMAK75Q.js +15 -0
  38. package/chunk-63W5N6P3.js +150 -0
  39. package/chunk-6HYVJV7B.js +102 -0
  40. package/chunk-6KHNO3SK.js +1948 -0
  41. package/chunk-6WD3OOJS.js +20 -0
  42. package/chunk-7DAJ4AI4.js +191 -0
  43. package/chunk-7GNGZRLZ.js +1939 -0
  44. package/chunk-7KCUSYT2.js +354 -0
  45. package/chunk-7U44LYTR.js +238 -0
  46. package/chunk-AFON4QUU.js +112 -0
  47. package/chunk-AGFH73SK.js +239 -0
  48. package/chunk-AL2KDGR2.js +27339 -0
  49. package/chunk-AS4PVWA4.js +221 -0
  50. package/chunk-ATNTHIZI.js +13 -0
  51. package/chunk-AVMKZHBC.js +85 -0
  52. package/chunk-AZPCASRE.js +36 -0
  53. package/chunk-BBYVOSU2.js +792 -0
  54. package/chunk-C3RUNRHT.js +51 -0
  55. package/chunk-C4FTUXVF.js +146 -0
  56. package/chunk-CF2WZF4N.js +134 -0
  57. package/chunk-CF7PE763.js +10 -0
  58. package/chunk-CKOJQDKR.js +198 -0
  59. package/chunk-CMKUBIGW.js +1550 -0
  60. package/chunk-CWMSB67P.js +34 -0
  61. package/chunk-DCOA4QSN.js +105 -0
  62. package/chunk-DFFIZ25G.js +30 -0
  63. package/chunk-DSZUWUYB.js +478 -0
  64. package/chunk-DWLEOOGR.js +8 -0
  65. package/chunk-DZ3XJVET.js +231 -0
  66. package/chunk-EHLHSX7R.js +1433 -0
  67. package/chunk-ENOG22KJ.js +939 -0
  68. package/chunk-FSO5B7GH.js +171 -0
  69. package/chunk-FVYY6MCS.js +1447 -0
  70. package/chunk-G3SUCT4W.js +8 -0
  71. package/chunk-GAKEBQD6.js +30 -0
  72. package/chunk-GBRG75BQ.js +86 -0
  73. package/chunk-GU3PEVGZ.js +4723 -0
  74. package/chunk-H33743XH.js +25 -0
  75. package/chunk-HNMXYYJR.js +12 -0
  76. package/chunk-HNW7IJSK.js +71 -0
  77. package/chunk-I42VC5KR.js +15 -0
  78. package/chunk-I6XMPTMR.js +113 -0
  79. package/chunk-IDZTNRP2.js +85 -0
  80. package/chunk-ISNCLGUZ.js +146 -0
  81. package/chunk-IWX4UW2E.js +548 -0
  82. package/chunk-JBTJAPUF.js +35 -0
  83. package/chunk-JEXVIMYZ.js +55 -0
  84. package/chunk-JRKKFRAV.js +537 -0
  85. package/chunk-JZPBVBIY.js +94 -0
  86. package/chunk-KKY4B2Q2.js +21 -0
  87. package/chunk-KQHGZWSV.js +63 -0
  88. package/chunk-KUG52IAP.js +8 -0
  89. package/chunk-KX6YBIHG.js +8 -0
  90. package/chunk-LCBAMY2M.js +60 -0
  91. package/chunk-LM6IYQ3F.js +16 -0
  92. package/chunk-LTRXGFMS.js +83 -0
  93. package/chunk-M76ECQRD.js +13658 -0
  94. package/chunk-MRC4Q34M.js +188 -0
  95. package/chunk-MTU75CZ2.js +91 -0
  96. package/chunk-N54XAP77.js +19 -0
  97. package/chunk-O2ZNTTET.js +3272 -0
  98. package/chunk-O4BU24WZ.js +3212 -0
  99. package/chunk-OLZBQWZU.js +6 -0
  100. package/chunk-OOSFSFMA.js +271 -0
  101. package/chunk-OPZYGHUC.js +89 -0
  102. package/chunk-OWOHNGCN.js +50 -0
  103. package/chunk-P3PKED2I.js +962 -0
  104. package/chunk-QSJ3HFEF.js +8 -0
  105. package/chunk-RCSJFQPB.js +9036 -0
  106. package/chunk-RL776AGR.js +190 -0
  107. package/chunk-ROWQEJRP.js +139 -0
  108. package/chunk-S7Z2HMCN.js +25 -0
  109. package/chunk-SDJDLO5W.js +628 -0
  110. package/chunk-SOTZ6RDN.js +69 -0
  111. package/chunk-TILFE6LV.js +381 -0
  112. package/chunk-U4TRT5V4.js +246 -0
  113. package/chunk-U6VC4MU4.js +8 -0
  114. package/chunk-UAD2WT54.js +64 -0
  115. package/chunk-UB6SN4NJ.js +421 -0
  116. package/chunk-URUUZLPA.js +807 -0
  117. package/chunk-UTLZINAP.js +3066 -0
  118. package/chunk-VC6OZXO5.js +298 -0
  119. package/chunk-VF4K2QE6.js +21 -0
  120. package/chunk-VHBWHNVT.js +59 -0
  121. package/chunk-VIDPVFP3.js +20 -0
  122. package/chunk-VP4WJWKW.js +8882 -0
  123. package/chunk-VUW5FBDB.js +573 -0
  124. package/chunk-VVX233PH.js +482 -0
  125. package/chunk-VX3SXJ3N.js +2052 -0
  126. package/chunk-W4NVOSFF.js +37 -0
  127. package/chunk-WWC7I6TA.js +8 -0
  128. package/chunk-WZSRQNQG.js +2587 -0
  129. package/chunk-XBUBEFNX.js +34 -0
  130. package/chunk-XENYHRUE.js +104 -0
  131. package/chunk-Y5GCAMGP.js +9 -0
  132. package/chunk-YPRZSPF3.js +148 -0
  133. package/chunk-Z4NR32XR.js +50 -0
  134. package/chunk-ZNFJWEN4.js +56 -0
  135. package/cliExecutor-K3F7DMRO.js +36 -0
  136. package/clipboardy-BVE3LVEH.js +12001 -0
  137. package/createAgentAutomationAction-RJF3N2QY.js +866 -0
  138. package/createDialogAction-DRSPS6CE.js +55 -0
  139. package/createPageAction-6B2WMNO3.js +172 -0
  140. package/db-HCJ5PRB5.js +271 -0
  141. package/dbSlice-Q3TM2FJV.js +60 -0
  142. package/deleteFile-OW53A6BX.js +41 -0
  143. package/dialogCommands-4IX4XIZE.js +63 -0
  144. package/dialogSlice-3M7KX2TX.js +148 -0
  145. package/docCreateCommands-SIL3NPGT.js +220 -0
  146. package/docDeleteCommands-7IOMLUS4.js +181 -0
  147. package/docReadCommands-FNFXUA5L.js +134 -0
  148. package/docStore-SV7E34D4.js +98 -0
  149. package/docUpdateCommands-X2HNDVUC.js +318 -0
  150. package/fetchMessages-KTNM7QAR.js +17 -0
  151. package/getPricing-3E6UNPKL.js +30 -0
  152. package/handleSendMessageAction-JYETO5RZ.js +185 -0
  153. package/index.js +188 -112958
  154. package/lib-FYYBQIXS.js +19839 -0
  155. package/localDialogRead-2VRI24F4.js +26 -0
  156. package/localFirstLog-DHNOY2NA.js +19 -0
  157. package/localRuntimeAuthority-TEGCOWX4.js +471 -0
  158. package/localRuntimeDb-LGDF6FQP.js +12 -0
  159. package/machineCommands-RIO3RP5Q.js +781 -0
  160. package/machineInfo-M6KB6HZN.js +10 -0
  161. package/machineWsRunDispatch-W7UYLGB5.js +112 -0
  162. package/memoryCommands-O4MIPIWQ.js +476 -0
  163. package/models-4OPOOLFS.js +9 -0
  164. package/offlineMarxistsAgentCommand-BCPJITJL.js +242 -0
  165. package/package.json +4 -24
  166. package/read-GW7ZEI23.js +17 -0
  167. package/readDocTool-HUFU6OCT.js +16 -0
  168. package/readlineWorkspace-27JR7WPW.js +5682 -0
  169. package/removeDialogAgentAction-CXKR4NJI.js +73 -0
  170. package/runAgentClientLoop-HZFAPJHS.js +293 -0
  171. package/runtimeDoctorCommands-LRHLPDRC.js +289 -0
  172. package/setDialogExtraReferencesAction-6RKUSXHX.js +60 -0
  173. package/setPrimaryDialogAgentAction-T3UTBEFG.js +80 -0
  174. package/settingSlice-IVKXJXMG.js +199 -0
  175. package/skillDiscovery-UGSQGX2U.js +16 -0
  176. package/skillSummaryMarker-42HKSXYY.js +9 -0
  177. package/slateToRenderMarkdown-Y5IYN73U.js +7 -0
  178. package/slateUtils-2M7MUTWX.js +19 -0
  179. package/spaceCommands-E7VOF4LO.js +450 -0
  180. package/spaceSlice-TSVROA5U.js +149 -0
  181. package/streamAgentChatTurn-3C5RQZJF.js +4510 -0
  182. package/tableCommands-O7O2LBEG.js +1286 -0
  183. package/toolApiClient-QI3YBNWB.js +26 -0
  184. package/tools-EQDEKR6N.js +87 -0
  185. package/tuiSummaryLlmCaller-RV3THLZF.js +78 -0
  186. package/understanding-3CUQQ6SV.js +271 -0
  187. package/updateCommands-VOSPKXFF.js +31 -0
  188. package/updateDialogTitleAction-3XV7VWSZ.js +188 -0
@@ -0,0 +1,26 @@
1
+ import "./chunk-4VNS5WPM.js";
2
+
3
+ // packages/agent-runtime/localDialogRead.ts
4
+ async function readDialogFromLocalDb(args) {
5
+ const [{ fetchMessages }] = await Promise.all([
6
+ import("./fetchMessages-KTNM7QAR.js")
7
+ ]);
8
+ let serverDb;
9
+ if (args.db) {
10
+ serverDb = args.db;
11
+ } else {
12
+ const dbModule = await import("./db-HCJ5PRB5.js");
13
+ serverDb = dbModule.default;
14
+ await dbModule.ensureServerDbOpen();
15
+ }
16
+ return {
17
+ meta: await serverDb.get(args.dialogKey),
18
+ msgs: await fetchMessages(serverDb, args.dialogId, {
19
+ limit: args.limit,
20
+ throwOnError: true
21
+ })
22
+ };
23
+ }
24
+ export {
25
+ readDialogFromLocalDb
26
+ };
@@ -0,0 +1,19 @@
1
+ import "./chunk-4VNS5WPM.js";
2
+
3
+ // packages/app/localFirst/localFirstLog.ts
4
+ var PREFIX = "[localFirst]";
5
+ function localFirstLog(event, data) {
6
+ const safeEvent = event.trim() || "unknown";
7
+ if (data && Object.keys(data).length > 0) {
8
+ try {
9
+ console.info(PREFIX, safeEvent, JSON.stringify(data));
10
+ } catch {
11
+ console.info(PREFIX, safeEvent, data);
12
+ }
13
+ return;
14
+ }
15
+ console.info(PREFIX, safeEvent);
16
+ }
17
+ export {
18
+ localFirstLog
19
+ };
@@ -0,0 +1,471 @@
1
+ import {
2
+ createCliAuthorityBrokerClient,
3
+ createCliAuthorityBrokerSocketInvoker,
4
+ isCliAuthorityBrokerUnavailableError,
5
+ resolveCliAuthorityBrokerEndpoint,
6
+ resolveCliAuthorityBrokerHealthPath,
7
+ resolveCliAuthorityBrokerMetadataPath
8
+ } from "./chunk-U4TRT5V4.js";
9
+ import {
10
+ createLegacyServerDb,
11
+ createLevelAuthorityStore,
12
+ isLevelLockError
13
+ } from "./chunk-CF2WZF4N.js";
14
+ import "./chunk-6WD3OOJS.js";
15
+ import {
16
+ toErrorMessage
17
+ } from "./chunk-HNMXYYJR.js";
18
+ import {
19
+ resolveNoloHome
20
+ } from "./chunk-LM6IYQ3F.js";
21
+ import "./chunk-4VNS5WPM.js";
22
+
23
+ // packages/cli/localRuntimeAuthority.ts
24
+ import fs2 from "node:fs";
25
+ import path2 from "node:path";
26
+
27
+ // packages/database-engine/cliAuthorityBrokerServer.ts
28
+ import fs from "node:fs";
29
+ import path from "node:path";
30
+ import { createServer } from "node:net";
31
+ var brokerRegistry = /* @__PURE__ */ new Map();
32
+ var DEFAULT_ITERATOR_LIMIT = 200;
33
+ function resolveBrokerListenTarget(endpoint) {
34
+ if (endpoint.startsWith("unix://")) {
35
+ return { kind: "unix", path: endpoint.slice("unix://".length) };
36
+ }
37
+ if (endpoint.startsWith("tcp://")) {
38
+ const url = new URL(endpoint);
39
+ return {
40
+ kind: "tcp",
41
+ host: url.hostname,
42
+ port: Number(url.port)
43
+ };
44
+ }
45
+ throw new Error(`Unsupported CLI authority broker endpoint: ${endpoint}`);
46
+ }
47
+ function buildListeningEndpoint(server, target) {
48
+ if (target.kind === "unix") {
49
+ return `unix://${target.path}`;
50
+ }
51
+ const address = server.address();
52
+ if (!address || typeof address === "string") {
53
+ return `tcp://${target.host}:${target.port}`;
54
+ }
55
+ const info = address;
56
+ return `tcp://${target.host}:${info.port}`;
57
+ }
58
+ function ensureParentDir(filePath) {
59
+ fs.mkdirSync(path.dirname(filePath), { recursive: true });
60
+ }
61
+ function writeJsonFile(filePath, data) {
62
+ if (!filePath) return;
63
+ ensureParentDir(filePath);
64
+ fs.writeFileSync(filePath, `${JSON.stringify(data, null, 2)}
65
+ `, "utf8");
66
+ }
67
+ function removeFileIfPresent(filePath) {
68
+ if (!filePath) return;
69
+ try {
70
+ fs.rmSync(filePath, { force: true });
71
+ } catch {
72
+ }
73
+ }
74
+ async function buildIteratorPage(store, request) {
75
+ const rows = [];
76
+ for await (const entry of store.iterator(request.options ?? {})) {
77
+ rows.push(entry);
78
+ }
79
+ const startIndex = request.cursor ? rows.findIndex(([key]) => key === request.cursor) + 1 : 0;
80
+ const limit = request.limit ?? DEFAULT_ITERATOR_LIMIT;
81
+ const entries = rows.slice(startIndex, startIndex + limit);
82
+ const lastEntry = entries.at(-1) ?? null;
83
+ return {
84
+ entries,
85
+ nextCursor: lastEntry ? lastEntry[0] : null,
86
+ done: startIndex + entries.length >= rows.length
87
+ };
88
+ }
89
+ function createErrorResponse(error) {
90
+ if (typeof error === "object" && error !== null && typeof error.code === "string" && typeof error.message === "string") {
91
+ return {
92
+ ok: false,
93
+ error: {
94
+ code: error.code,
95
+ message: error.message,
96
+ retryable: error.retryable === true
97
+ }
98
+ };
99
+ }
100
+ return {
101
+ ok: false,
102
+ error: {
103
+ code: "BROKER_INTERNAL_ERROR",
104
+ message: toErrorMessage(error)
105
+ }
106
+ };
107
+ }
108
+ async function dispatchCliAuthorityBrokerRequest(store, request) {
109
+ try {
110
+ switch (request.type) {
111
+ case "status":
112
+ return { ok: true, result: { type: "status" } };
113
+ case "open":
114
+ await store.open();
115
+ return { ok: true, result: { type: "open" } };
116
+ case "close":
117
+ await store.close();
118
+ return { ok: true, result: { type: "close" } };
119
+ case "get":
120
+ return { ok: true, result: { type: "get", value: await store.get(request.key) } };
121
+ case "put":
122
+ await store.put(request.key, request.value);
123
+ return { ok: true, result: { type: "put" } };
124
+ case "del":
125
+ await store.del(request.key);
126
+ return { ok: true, result: { type: "del" } };
127
+ case "batchWrite":
128
+ await store.batchWrite(request.ops);
129
+ return { ok: true, result: { type: "batchWrite" } };
130
+ case "iterator":
131
+ return {
132
+ ok: true,
133
+ result: {
134
+ type: "iterator",
135
+ page: await buildIteratorPage(store, request)
136
+ }
137
+ };
138
+ }
139
+ } catch (error) {
140
+ return createErrorResponse(error);
141
+ }
142
+ }
143
+ async function createBrokerHandle(options) {
144
+ const target = resolveBrokerListenTarget(options.endpoint);
145
+ if (target.kind === "unix") {
146
+ ensureParentDir(target.path);
147
+ removeFileIfPresent(target.path);
148
+ }
149
+ const store = await options.createStore();
150
+ await store.open();
151
+ const server = createServer((socket) => {
152
+ bindSocketRequestHandler({ socket, store });
153
+ });
154
+ if ((options.transportMode ?? "socket") === "socket") {
155
+ try {
156
+ await new Promise((resolve, reject) => {
157
+ server.once("error", reject);
158
+ if (target.kind === "unix") {
159
+ server.listen(target.path, () => {
160
+ server.off("error", reject);
161
+ resolve();
162
+ });
163
+ return;
164
+ }
165
+ server.listen(target.port, target.host, () => {
166
+ server.off("error", reject);
167
+ resolve();
168
+ });
169
+ });
170
+ server.unref();
171
+ } catch (error) {
172
+ await store.close().catch(() => {
173
+ });
174
+ throw error;
175
+ }
176
+ }
177
+ const now = options.now ?? Date.now;
178
+ const listeningEndpoint = (options.transportMode ?? "socket") === "socket" ? buildListeningEndpoint(server, target) : options.endpoint;
179
+ writeJsonFile(options.metadataPath, {
180
+ pid: process.pid,
181
+ endpoint: listeningEndpoint,
182
+ location: store.location ?? listeningEndpoint,
183
+ startedAt: new Date(now()).toISOString()
184
+ });
185
+ writeJsonFile(options.healthPath, {
186
+ ok: true,
187
+ pid: process.pid,
188
+ endpoint: listeningEndpoint,
189
+ checkedAt: new Date(now()).toISOString()
190
+ });
191
+ let closed = false;
192
+ return {
193
+ endpoint: options.endpoint,
194
+ listeningEndpoint,
195
+ authorityStore: store,
196
+ request(request) {
197
+ return dispatchCliAuthorityBrokerRequest(store, request);
198
+ },
199
+ async close() {
200
+ if (closed) return;
201
+ closed = true;
202
+ brokerRegistry.delete(options.endpoint);
203
+ if ((options.transportMode ?? "socket") === "socket") {
204
+ await new Promise((resolve, reject) => {
205
+ server.close((error) => error ? reject(error) : resolve());
206
+ });
207
+ }
208
+ await store.close();
209
+ if (target.kind === "unix") {
210
+ removeFileIfPresent(target.path);
211
+ }
212
+ removeFileIfPresent(options.metadataPath);
213
+ removeFileIfPresent(options.healthPath);
214
+ }
215
+ };
216
+ }
217
+ function bindSocketRequestHandler(args) {
218
+ let buffer = "";
219
+ args.socket.setEncoding("utf8");
220
+ args.socket.on("data", async (chunk) => {
221
+ buffer += chunk;
222
+ if (!buffer.includes("\n")) return;
223
+ const [rawRequest] = buffer.split("\n");
224
+ buffer = "";
225
+ let response;
226
+ try {
227
+ response = await dispatchCliAuthorityBrokerRequest(
228
+ args.store,
229
+ JSON.parse(rawRequest)
230
+ );
231
+ } catch (error) {
232
+ response = createErrorResponse(error);
233
+ }
234
+ args.socket.end(`${JSON.stringify(response)}
235
+ `);
236
+ });
237
+ }
238
+ function getOrCreateCliAuthorityBrokerServer(options) {
239
+ const existing = brokerRegistry.get(options.endpoint);
240
+ if (existing) return existing;
241
+ const pending = createBrokerHandle(options).catch((error) => {
242
+ brokerRegistry.delete(options.endpoint);
243
+ throw error;
244
+ });
245
+ brokerRegistry.set(options.endpoint, pending);
246
+ return pending;
247
+ }
248
+
249
+ // packages/cli/localRuntimeAuthority.ts
250
+ function ensureDbParentDir(dbPath) {
251
+ fs2.mkdirSync(path2.dirname(dbPath), { recursive: true });
252
+ }
253
+ function isCliAuthorityLockError(error) {
254
+ if (isLevelLockError(error)) return true;
255
+ const message = toErrorMessage(error);
256
+ return /Database failed to open|EADDRINUSE|Failed to listen/i.test(message);
257
+ }
258
+ async function sleep(ms) {
259
+ await new Promise((resolve) => setTimeout(resolve, ms));
260
+ }
261
+ function resolveCliLocalRuntimeDbPath(options = {}) {
262
+ return path2.join(
263
+ resolveNoloHome({
264
+ env: options.env,
265
+ homeDir: options.homeDir
266
+ }),
267
+ "data",
268
+ "leveldb"
269
+ );
270
+ }
271
+ var defaultCliAuthorityBrokerConnectDeps = {
272
+ createClient: (options) => createCliAuthorityBrokerClient(options),
273
+ startBroker: (options) => getOrCreateCliAuthorityBrokerServer(options),
274
+ sleep
275
+ };
276
+ async function connectCliAuthorityBroker(args) {
277
+ const deps = {
278
+ ...defaultCliAuthorityBrokerConnectDeps,
279
+ ...args.deps
280
+ };
281
+ async function connectClient() {
282
+ const client2 = deps.createClient({
283
+ endpoint: args.endpoint,
284
+ invoke: createCliAuthorityBrokerSocketInvoker({ endpoint: args.endpoint })
285
+ });
286
+ async function attachToExistingBroker(attempts) {
287
+ for (let attempt = 0; attempt < attempts; attempt += 1) {
288
+ await deps.sleep(100);
289
+ try {
290
+ await client2.open();
291
+ return true;
292
+ } catch (error) {
293
+ if (!isCliAuthorityBrokerUnavailableError(error)) throw error;
294
+ }
295
+ }
296
+ return false;
297
+ }
298
+ try {
299
+ await deps.startBroker({
300
+ endpoint: args.endpoint,
301
+ metadataPath: args.metadataPath,
302
+ healthPath: args.healthPath,
303
+ createStore: () => createLevelAuthorityStore(args.dbPath)
304
+ });
305
+ await client2.open();
306
+ return client2;
307
+ } catch (error) {
308
+ if (!isCliAuthorityLockError(error)) throw error;
309
+ if (await attachToExistingBroker(5)) {
310
+ return client2;
311
+ }
312
+ let lastError = error;
313
+ for (let attempt = 0; attempt < 5; attempt += 1) {
314
+ await deps.sleep(100);
315
+ try {
316
+ await deps.startBroker({
317
+ endpoint: args.endpoint,
318
+ metadataPath: args.metadataPath,
319
+ healthPath: args.healthPath,
320
+ createStore: () => createLevelAuthorityStore(args.dbPath)
321
+ });
322
+ await client2.open();
323
+ return client2;
324
+ } catch (retryError) {
325
+ lastError = retryError;
326
+ if (isCliAuthorityLockError(retryError)) {
327
+ if (await attachToExistingBroker(2)) {
328
+ return client2;
329
+ }
330
+ continue;
331
+ }
332
+ if (isCliAuthorityBrokerUnavailableError(retryError)) {
333
+ continue;
334
+ }
335
+ throw retryError;
336
+ }
337
+ }
338
+ throw new Error(`CLI authority broker could not attach or take ownership for ${args.endpoint}`, {
339
+ cause: lastError
340
+ });
341
+ }
342
+ }
343
+ let client = await connectClient();
344
+ let reconnecting = null;
345
+ async function reconnect() {
346
+ reconnecting ??= connectClient();
347
+ try {
348
+ client = await reconnecting;
349
+ return client;
350
+ } finally {
351
+ reconnecting = null;
352
+ }
353
+ }
354
+ async function runWithSelfHealing(operation) {
355
+ try {
356
+ return await operation(client);
357
+ } catch (error) {
358
+ if (!isCliAuthorityBrokerUnavailableError(error)) throw error;
359
+ const recoveredClient = await reconnect();
360
+ return operation(recoveredClient);
361
+ }
362
+ }
363
+ return {
364
+ get location() {
365
+ return client.location;
366
+ },
367
+ get status() {
368
+ return client.status;
369
+ },
370
+ open: () => runWithSelfHealing((activeClient) => activeClient.open()),
371
+ close: () => runWithSelfHealing((activeClient) => activeClient.close()),
372
+ get: (key) => runWithSelfHealing((activeClient) => activeClient.get(key)),
373
+ put: (key, value) => runWithSelfHealing((activeClient) => activeClient.put(key, value)),
374
+ del: (key) => runWithSelfHealing((activeClient) => activeClient.del(key)),
375
+ batchWrite: (ops) => runWithSelfHealing((activeClient) => activeClient.batchWrite(ops)),
376
+ createBatch() {
377
+ const ops = [];
378
+ return {
379
+ put(key, value) {
380
+ ops.push({ type: "put", key, value });
381
+ },
382
+ del(key) {
383
+ ops.push({ type: "del", key });
384
+ },
385
+ write: () => runWithSelfHealing((activeClient) => activeClient.batchWrite(ops))
386
+ };
387
+ },
388
+ iterator(options = {}) {
389
+ return async function* iterate() {
390
+ let activeOptions = options;
391
+ let lastYieldedKey;
392
+ let skipResumeKey = false;
393
+ let recovered = false;
394
+ while (true) {
395
+ try {
396
+ for await (const entry of client.iterator(activeOptions)) {
397
+ if (skipResumeKey && entry[0] === lastYieldedKey) {
398
+ skipResumeKey = false;
399
+ continue;
400
+ }
401
+ skipResumeKey = false;
402
+ lastYieldedKey = entry[0];
403
+ yield entry;
404
+ }
405
+ return;
406
+ } catch (error) {
407
+ if (recovered || !isCliAuthorityBrokerUnavailableError(error)) {
408
+ throw error;
409
+ }
410
+ recovered = true;
411
+ await reconnect();
412
+ if (lastYieldedKey === void 0) {
413
+ activeOptions = options;
414
+ continue;
415
+ }
416
+ if (options.reverse) {
417
+ activeOptions = {
418
+ ...options,
419
+ lt: lastYieldedKey
420
+ };
421
+ continue;
422
+ }
423
+ activeOptions = {
424
+ ...options,
425
+ gte: lastYieldedKey
426
+ };
427
+ skipResumeKey = true;
428
+ }
429
+ }
430
+ }();
431
+ }
432
+ };
433
+ }
434
+ async function getDefaultCliLocalRuntimeAuthority(options = {}) {
435
+ const env = options.env ?? process.env;
436
+ const dbPath = resolveCliLocalRuntimeDbPath({
437
+ env,
438
+ homeDir: options.homeDir
439
+ });
440
+ ensureDbParentDir(dbPath);
441
+ const endpoint = resolveCliAuthorityBrokerEndpoint({
442
+ transport: "tcp",
443
+ env,
444
+ homeDir: options.homeDir
445
+ });
446
+ const metadataPath = resolveCliAuthorityBrokerMetadataPath({
447
+ transport: "tcp",
448
+ env,
449
+ homeDir: options.homeDir
450
+ });
451
+ const healthPath = resolveCliAuthorityBrokerHealthPath({
452
+ transport: "tcp",
453
+ env,
454
+ homeDir: options.homeDir
455
+ });
456
+ return connectCliAuthorityBroker({
457
+ endpoint,
458
+ metadataPath,
459
+ healthPath,
460
+ dbPath
461
+ });
462
+ }
463
+ async function getDefaultCliLocalRuntimeDb(options = {}) {
464
+ const authorityStore = await getDefaultCliLocalRuntimeAuthority(options);
465
+ return createLegacyServerDb(authorityStore);
466
+ }
467
+ export {
468
+ connectCliAuthorityBroker,
469
+ getDefaultCliLocalRuntimeAuthority,
470
+ getDefaultCliLocalRuntimeDb
471
+ };
@@ -0,0 +1,12 @@
1
+ import {
2
+ buildCliLocalRuntimeDbEnv,
3
+ getDefaultCliLocalRuntimeDb,
4
+ resolveCliLocalRuntimeDbPath
5
+ } from "./chunk-H33743XH.js";
6
+ import "./chunk-LM6IYQ3F.js";
7
+ import "./chunk-4VNS5WPM.js";
8
+ export {
9
+ buildCliLocalRuntimeDbEnv,
10
+ getDefaultCliLocalRuntimeDb,
11
+ resolveCliLocalRuntimeDbPath
12
+ };