nolo-cli 0.6.1 → 0.8.0-alpha.10

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 (175) hide show
  1. package/_executeModel-CPDNUUQV.js +198 -0
  2. package/action-PAXRPJJF.js +27 -0
  3. package/addContentAction-CZVWF3QZ.js +25 -0
  4. package/addDialogAgentAction-CCIDTPHC.js +67 -0
  5. package/agentDeleteCommand-OSUMJMZM.js +323 -0
  6. package/agentEmailCommands-OQTJIPQU.js +621 -0
  7. package/agentListCommands-FATQEUYT.js +219 -0
  8. package/agentMachineCommands-6LZWF4GL.js +421 -0
  9. package/agentPullCommand-O2MTUAFR.js +122 -0
  10. package/agentRecordCommands-TIHFU65Z.js +89 -0
  11. package/agentRunCommand-R64Y3HCH.js +102 -0
  12. package/agentRunControl-K4VKNEHF.js +57 -0
  13. package/agentRuntimeLocal-6PIWAHLQ.js +99 -0
  14. package/agentSlice-TP4VARJF.js +41 -0
  15. package/authCommand-WXMD3IPR.js +574 -0
  16. package/authCommands-X74AFDTC.js +26 -0
  17. package/chunk-2EISRLRC.js +238 -0
  18. package/chunk-2FTTDCD4.js +675 -0
  19. package/chunk-2MALU52L.js +51 -0
  20. package/chunk-2TPUKEU7.js +1078 -0
  21. package/chunk-3ASDTTEI.js +1774 -0
  22. package/chunk-3EUW3WEO.js +8 -0
  23. package/chunk-3LY4F7SV.js +9293 -0
  24. package/chunk-4CQLVGRV.js +50 -0
  25. package/chunk-4IJYA27C.js +342 -0
  26. package/chunk-4SN6J65J.js +38 -0
  27. package/chunk-4VNS5WPM.js +42 -0
  28. package/chunk-572EKYLF.js +792 -0
  29. package/chunk-5MIDPSSK.js +206 -0
  30. package/chunk-5MMAK75Q.js +15 -0
  31. package/chunk-5VV37AT4.js +222 -0
  32. package/chunk-63W5N6P3.js +150 -0
  33. package/chunk-6A5EF6IR.js +929 -0
  34. package/chunk-6HYVJV7B.js +102 -0
  35. package/chunk-6P2WX5IA.js +3631 -0
  36. package/chunk-6WD3OOJS.js +20 -0
  37. package/chunk-ATNTHIZI.js +13 -0
  38. package/chunk-AUGHVUFE.js +69 -0
  39. package/chunk-AVMKZHBC.js +85 -0
  40. package/chunk-AZPCASRE.js +36 -0
  41. package/chunk-BNMT7YY5.js +34 -0
  42. package/chunk-BR2WP3DF.js +548 -0
  43. package/chunk-BSTNFPHD.js +231 -0
  44. package/chunk-BU4OPIXC.js +171 -0
  45. package/chunk-CF2WZF4N.js +134 -0
  46. package/chunk-CF7PE763.js +10 -0
  47. package/chunk-CKOJQDKR.js +198 -0
  48. package/chunk-CM54RSSA.js +206 -0
  49. package/chunk-CWMSB67P.js +34 -0
  50. package/chunk-DA2OEKS6.js +27 -0
  51. package/chunk-DFFIZ25G.js +30 -0
  52. package/chunk-DWLEOOGR.js +8 -0
  53. package/chunk-DZ3XJVET.js +231 -0
  54. package/chunk-EHLHSX7R.js +1433 -0
  55. package/chunk-ELRRLDWI.js +478 -0
  56. package/chunk-EYEEHCU4.js +3066 -0
  57. package/chunk-FQZWM5YX.js +628 -0
  58. package/chunk-G3SUCT4W.js +8 -0
  59. package/chunk-G5H7RNFL.js +807 -0
  60. package/chunk-GAKEBQD6.js +30 -0
  61. package/chunk-GBRG75BQ.js +86 -0
  62. package/chunk-H2RMRZJE.js +113 -0
  63. package/chunk-H33743XH.js +25 -0
  64. package/chunk-HD63YREL.js +19 -0
  65. package/chunk-HEIIIZBX.js +104 -0
  66. package/chunk-HNMXYYJR.js +12 -0
  67. package/chunk-HOMYP7GZ.js +2152 -0
  68. package/chunk-HZFOMJRA.js +4300 -0
  69. package/chunk-IAXBCTTE.js +175 -0
  70. package/chunk-IDZTNRP2.js +85 -0
  71. package/chunk-IHHA5Y2S.js +9013 -0
  72. package/chunk-ISNCLGUZ.js +146 -0
  73. package/chunk-IYQV26RA.js +138 -0
  74. package/chunk-J4576WMJ.js +91 -0
  75. package/chunk-JBTJAPUF.js +35 -0
  76. package/chunk-JZPBVBIY.js +94 -0
  77. package/chunk-KQHGZWSV.js +63 -0
  78. package/chunk-KUG52IAP.js +8 -0
  79. package/chunk-KX6YBIHG.js +8 -0
  80. package/chunk-LCBAMY2M.js +60 -0
  81. package/chunk-LM25IZBJ.js +902 -0
  82. package/chunk-LM6IYQ3F.js +16 -0
  83. package/chunk-M76ECQRD.js +13658 -0
  84. package/chunk-MRC4Q34M.js +188 -0
  85. package/chunk-NEMRK4EK.js +944 -0
  86. package/chunk-NXZGF7F7.js +2878 -0
  87. package/chunk-OF5H3QWS.js +300 -0
  88. package/chunk-OLZBQWZU.js +6 -0
  89. package/chunk-OOYVBFM7.js +191 -0
  90. package/chunk-OWOHNGCN.js +50 -0
  91. package/chunk-PN7AFLOK.js +3401 -0
  92. package/chunk-POCFIDGQ.js +562 -0
  93. package/chunk-Q6WACBKB.js +1949 -0
  94. package/chunk-QFV2OAIM.js +421 -0
  95. package/chunk-QJ6V2NIN.js +1447 -0
  96. package/chunk-QSJ3HFEF.js +8 -0
  97. package/chunk-QUWDTOUP.js +190 -0
  98. package/chunk-QYXLLLGL.js +4519 -0
  99. package/chunk-ROWQEJRP.js +139 -0
  100. package/chunk-S7Z2HMCN.js +25 -0
  101. package/chunk-TDIQFT2F.js +301 -0
  102. package/chunk-TILFE6LV.js +381 -0
  103. package/chunk-TKOUBWBO.js +24674 -0
  104. package/chunk-TYH5JE6N.js +27158 -0
  105. package/chunk-U4TRT5V4.js +246 -0
  106. package/chunk-U6VC4MU4.js +8 -0
  107. package/chunk-UAD2WT54.js +64 -0
  108. package/chunk-USZMK5UT.js +105 -0
  109. package/chunk-VEJLAVTC.js +2052 -0
  110. package/chunk-VF4K2QE6.js +21 -0
  111. package/chunk-VHBWHNVT.js +59 -0
  112. package/chunk-VIDPVFP3.js +20 -0
  113. package/chunk-VP4WJWKW.js +8882 -0
  114. package/chunk-VQ2AJRGD.js +148 -0
  115. package/chunk-W4NVOSFF.js +37 -0
  116. package/chunk-WWC7I6TA.js +8 -0
  117. package/chunk-X7W4TNB4.js +1550 -0
  118. package/chunk-XDVAYP26.js +537 -0
  119. package/chunk-XKIMRZO2.js +221 -0
  120. package/chunk-Y5GCAMGP.js +9 -0
  121. package/chunk-YWPXYBY7.js +360 -0
  122. package/chunk-Z4NR32XR.js +50 -0
  123. package/chunk-ZNFJWEN4.js +56 -0
  124. package/cliExecutor-DNE7TCC4.js +36 -0
  125. package/clipboardy-BVE3LVEH.js +12001 -0
  126. package/createAgentAutomationAction-KLKS2HGU.js +864 -0
  127. package/createDialogAction-Z33JMBF5.js +52 -0
  128. package/createPageAction-AQVNOAAI.js +169 -0
  129. package/db-HCJ5PRB5.js +271 -0
  130. package/dbSlice-C4UJLRZP.js +59 -0
  131. package/deleteFile-4SKGPHOZ.js +41 -0
  132. package/dialogCommands-W5PD6MZU.js +59 -0
  133. package/dialogSlice-RBJYVSAR.js +146 -0
  134. package/docCreateCommands-MM34S4Z3.js +215 -0
  135. package/docDeleteCommands-JJTU722V.js +176 -0
  136. package/docReadCommands-GLYDMCTU.js +129 -0
  137. package/docStore-5TYME4DO.js +96 -0
  138. package/docUpdateCommands-ZCGQ7URR.js +313 -0
  139. package/fetchMessages-JOCYIFKL.js +16 -0
  140. package/getPricing-PWPJ6MNV.js +30 -0
  141. package/handleSendMessageAction-KA2MRW6E.js +183 -0
  142. package/index.js +184 -112254
  143. package/lib-FYYBQIXS.js +19839 -0
  144. package/localDialogRead-D3BELSTF.js +26 -0
  145. package/localFirstLog-DHNOY2NA.js +19 -0
  146. package/localRuntimeAuthority-TEGCOWX4.js +471 -0
  147. package/localRuntimeDb-LGDF6FQP.js +12 -0
  148. package/machineCommands-ZB5WUSPF.js +774 -0
  149. package/machineInfo-M6KB6HZN.js +10 -0
  150. package/machineWsRunDispatch-GWCAPPCM.js +105 -0
  151. package/memoryCommands-O4MIPIWQ.js +476 -0
  152. package/models-XLEOET3E.js +9 -0
  153. package/offlineMarxistsAgentCommand-BCPJITJL.js +242 -0
  154. package/package.json +3 -25
  155. package/read-RIJCIVKX.js +17 -0
  156. package/readDocTool-GZD2N3LO.js +16 -0
  157. package/readlineWorkspace-FEDY44AA.js +5357 -0
  158. package/removeDialogAgentAction-CXLST3N6.js +72 -0
  159. package/runAgentClientLoop-W4NKE64V.js +288 -0
  160. package/runtimeDoctorCommands-LRHLPDRC.js +289 -0
  161. package/setDialogExtraReferencesAction-LP6VYGU7.js +59 -0
  162. package/setPrimaryDialogAgentAction-D3GGH23T.js +79 -0
  163. package/settingSlice-J4I3Z5H7.js +198 -0
  164. package/skillSummaryMarker-42HKSXYY.js +9 -0
  165. package/slateToRenderMarkdown-Y5IYN73U.js +7 -0
  166. package/slateUtils-2M7MUTWX.js +19 -0
  167. package/spaceCommands-LC4FDAKE.js +450 -0
  168. package/spaceSlice-32XOGBEF.js +145 -0
  169. package/streamAgentChatTurn-YQW32AQH.js +4503 -0
  170. package/tableCommands-GOFP7QKA.js +1286 -0
  171. package/toolApiClient-QI3YBNWB.js +26 -0
  172. package/tools-XGTFRYD7.js +83 -0
  173. package/understanding-HCSFPE7R.js +318 -0
  174. package/updateCommands-VOSPKXFF.js +31 -0
  175. package/updateDialogTitleAction-4LHQDNHQ.js +185 -0
@@ -0,0 +1,450 @@
1
+ import {
2
+ readLiveDbRecordAfterTombstoneMerge
3
+ } from "./chunk-QUWDTOUP.js";
4
+ import {
5
+ readDbRecord,
6
+ writeAgentRecord
7
+ } from "./chunk-FQZWM5YX.js";
8
+ import "./chunk-HD63YREL.js";
9
+ import "./chunk-VHBWHNVT.js";
10
+ import "./chunk-KQHGZWSV.js";
11
+ import {
12
+ authRoutes
13
+ } from "./chunk-MRC4Q34M.js";
14
+ import {
15
+ createSpaceKey,
16
+ normalizeSpaceId
17
+ } from "./chunk-UAD2WT54.js";
18
+ import "./chunk-IDZTNRP2.js";
19
+ import {
20
+ parseUserIdFromAuthToken,
21
+ readOption,
22
+ resolveAuthToken,
23
+ resolveServerCandidates,
24
+ resolveServerUrl
25
+ } from "./chunk-ISNCLGUZ.js";
26
+ import "./chunk-OLZBQWZU.js";
27
+ import "./chunk-6P2WX5IA.js";
28
+ import "./chunk-ZNFJWEN4.js";
29
+ import "./chunk-TILFE6LV.js";
30
+ import "./chunk-NEMRK4EK.js";
31
+ import "./chunk-XDVAYP26.js";
32
+ import "./chunk-LM25IZBJ.js";
33
+ import "./chunk-5MMAK75Q.js";
34
+ import "./chunk-572EKYLF.js";
35
+ import "./chunk-TDIQFT2F.js";
36
+ import "./chunk-JZPBVBIY.js";
37
+ import "./chunk-BR2WP3DF.js";
38
+ import "./chunk-DWLEOOGR.js";
39
+ import "./chunk-HNMXYYJR.js";
40
+ import {
41
+ resolveFileCategory
42
+ } from "./chunk-AZPCASRE.js";
43
+ import "./chunk-KX6YBIHG.js";
44
+ import {
45
+ require_index_umd
46
+ } from "./chunk-PN7AFLOK.js";
47
+ import "./chunk-WWC7I6TA.js";
48
+ import "./chunk-QSJ3HFEF.js";
49
+ import "./chunk-GBRG75BQ.js";
50
+ import "./chunk-4SN6J65J.js";
51
+ import "./chunk-LCBAMY2M.js";
52
+ import "./chunk-3EUW3WEO.js";
53
+ import "./chunk-U6VC4MU4.js";
54
+ import "./chunk-CF7PE763.js";
55
+ import "./chunk-G3SUCT4W.js";
56
+ import "./chunk-KUG52IAP.js";
57
+ import {
58
+ __toESM
59
+ } from "./chunk-4VNS5WPM.js";
60
+
61
+ // packages/cli/spaceCommands.ts
62
+ var import_ulid = __toESM(require_index_umd(), 1);
63
+ import { readFileSync } from "node:fs";
64
+ import { basename, extname } from "node:path";
65
+ var VALID_INVITE_ROLES = /* @__PURE__ */ new Set([
66
+ "admin" /* ADMIN */,
67
+ "member" /* MEMBER */,
68
+ "guest" /* GUEST */
69
+ ]);
70
+ function hasHelpArg(args) {
71
+ return args.includes("--help") || args.includes("-h");
72
+ }
73
+ function hasFlag(args, flag) {
74
+ return args.includes(flag);
75
+ }
76
+ function writeOutput(deps, text) {
77
+ (deps.output ?? process.stdout).write(text);
78
+ }
79
+ function requireTokenUser(args, env) {
80
+ const authToken = resolveAuthToken(args, env);
81
+ const userId = parseUserIdFromAuthToken(authToken) || env.USER_ID || "";
82
+ if (!authToken) {
83
+ throw new Error("space command requires an auth token. Pass --token or set AUTH_TOKEN.");
84
+ }
85
+ if (!userId) {
86
+ throw new Error("auth token does not contain userId. Pass a user-scoped token.");
87
+ }
88
+ return { authToken, userId };
89
+ }
90
+ function printCreateUsage(output) {
91
+ output.write(`Usage:
92
+ nolo space create --name <name> [--description <text>] [--id <spaceId>]
93
+
94
+ Options:
95
+ --visibility private|public Defaults to private.
96
+ --public Shortcut for --visibility public.
97
+ --server <url> Default write target.
98
+ --token <jwt> Auth token. Required for writes.
99
+ --json Print machine-readable JSON.
100
+ `);
101
+ }
102
+ function printInviteUsage(output) {
103
+ output.write(`Usage:
104
+ nolo space invite --space <spaceId> --member <userId> [--role member|admin|guest]
105
+
106
+ Options:
107
+ --server <url> Default write target.
108
+ --token <jwt> Auth token. Required for writes.
109
+ --json Print machine-readable JSON.
110
+
111
+ Note:
112
+ Use --member for an existing Nolo user id, or --email to send a pending
113
+ space invitation email.
114
+ `);
115
+ }
116
+ function printAcceptInviteUsage(output) {
117
+ output.write(`Usage:
118
+ nolo space accept-invite --invite <inviteToken>
119
+
120
+ Options:
121
+ --server <url> Default API target.
122
+ --token <jwt> Auth token. Required for accepting.
123
+ --invite <inviteToken> Space invite token from the email link.
124
+ --space-invite <inviteToken> Alias for --invite.
125
+ --json Print machine-readable JSON.
126
+ `);
127
+ }
128
+ function printUploadUsage(output) {
129
+ output.write(`Usage:
130
+ nolo space upload --space <spaceId> --file <path>
131
+
132
+ Options:
133
+ --server <url> Default API target.
134
+ --token <jwt> Auth token. Required for writes.
135
+ --json Print machine-readable JSON.
136
+
137
+ Note:
138
+ Currently only YAML files (.yaml, .yml) are supported.
139
+ `);
140
+ }
141
+ async function writeDbRecord(args) {
142
+ await writeAgentRecord({
143
+ agentKey: args.dbKey,
144
+ authToken: args.authToken,
145
+ fetchImpl: args.fetchImpl,
146
+ serverUrl: args.serverUrl,
147
+ userId: args.userId,
148
+ record: args.record
149
+ });
150
+ }
151
+ async function runSpaceCreateCommand(args, deps) {
152
+ if (hasHelpArg(args)) {
153
+ printCreateUsage(deps.output ?? process.stdout);
154
+ return 0;
155
+ }
156
+ const name = readOption(args, "--name") ?? args.find((value) => !value.startsWith("-"));
157
+ if (!name?.trim()) {
158
+ throw new Error("space create requires --name <name>.");
159
+ }
160
+ const { authToken, userId } = requireTokenUser(args, deps.env);
161
+ const serverUrl = resolveServerUrl(args, deps.env);
162
+ const fetchImpl = deps.fetchImpl ?? fetch;
163
+ const spaceId = normalizeSpaceId(readOption(args, "--id") ?? (0, import_ulid.ulid)());
164
+ const now = Date.now();
165
+ const nowISO = new Date(now).toISOString();
166
+ const visibilityRaw = readOption(args, "--visibility");
167
+ const visibility = hasFlag(args, "--public") || visibilityRaw === "public" /* PUBLIC */ ? "public" /* PUBLIC */ : "private" /* PRIVATE */;
168
+ const description = readOption(args, "--description") ?? "";
169
+ const spaceKey = createSpaceKey.space(spaceId);
170
+ const memberKey = createSpaceKey.member(userId, spaceId);
171
+ const spaceRecord = {
172
+ id: spaceId,
173
+ dbKey: spaceKey,
174
+ type: "space" /* SPACE */,
175
+ name: name.trim(),
176
+ description,
177
+ ownerId: userId,
178
+ visibility,
179
+ members: [userId],
180
+ categories: {},
181
+ contents: {},
182
+ createdAt: now,
183
+ updatedAt: now
184
+ };
185
+ const memberRecord = {
186
+ dbKey: memberKey,
187
+ type: "space" /* SPACE */,
188
+ userId,
189
+ role: "owner" /* OWNER */,
190
+ joinedAt: now,
191
+ spaceId,
192
+ spaceName: name.trim(),
193
+ ownerId: userId,
194
+ visibility,
195
+ createdAt: nowISO,
196
+ updatedAt: nowISO,
197
+ spaceCreatedAt: now,
198
+ spaceUpdatedAt: now
199
+ };
200
+ await writeDbRecord({ authToken, dbKey: spaceKey, fetchImpl, record: spaceRecord, serverUrl, userId });
201
+ await writeDbRecord({ authToken, dbKey: memberKey, fetchImpl, record: memberRecord, serverUrl, userId });
202
+ const result = { spaceId, spaceKey, memberKey, name: name.trim(), visibility, serverUrl };
203
+ if (hasFlag(args, "--json")) {
204
+ writeOutput(deps, `${JSON.stringify(result, null, 2)}
205
+ `);
206
+ } else {
207
+ writeOutput(deps, `Created space ${spaceId} (${name.trim()})
208
+ `);
209
+ }
210
+ return 0;
211
+ }
212
+ async function runSpaceInviteCommand(args, deps) {
213
+ if (hasHelpArg(args)) {
214
+ printInviteUsage(deps.output ?? process.stdout);
215
+ return 0;
216
+ }
217
+ const spaceIdRaw = readOption(args, "--space") ?? readOption(args, "--space-id");
218
+ const email = readOption(args, "--email");
219
+ const memberId = readOption(args, "--member") ?? readOption(args, "--member-id");
220
+ if (!spaceIdRaw?.trim()) throw new Error("space invite requires --space <spaceId>.");
221
+ if (!memberId?.trim() && !email?.trim()) {
222
+ throw new Error("space invite requires --member <userId> or --email <address>.");
223
+ }
224
+ const role = readOption(args, "--role") ?? "member" /* MEMBER */;
225
+ if (!VALID_INVITE_ROLES.has(role)) {
226
+ throw new Error("--role must be one of member, admin, or guest.");
227
+ }
228
+ const { authToken, userId } = requireTokenUser(args, deps.env);
229
+ const serverUrl = resolveServerUrl(args, deps.env);
230
+ const fetchImpl = deps.fetchImpl ?? fetch;
231
+ const spaceId = normalizeSpaceId(spaceIdRaw);
232
+ if (email?.trim()) {
233
+ const response = await fetchImpl(`${serverUrl}${authRoutes.users.spaceInvite.path}`, {
234
+ method: authRoutes.users.spaceInvite.method,
235
+ headers: {
236
+ Authorization: `Bearer ${authToken}`,
237
+ "Content-Type": "application/json"
238
+ },
239
+ body: JSON.stringify({
240
+ spaceId,
241
+ email: email.trim(),
242
+ role
243
+ })
244
+ });
245
+ const data = await response.json().catch(() => ({}));
246
+ if (!response.ok) {
247
+ throw new Error(
248
+ data?.error?.message || data?.error || `space invite failed: HTTP ${response.status}`
249
+ );
250
+ }
251
+ if (hasFlag(args, "--json")) {
252
+ writeOutput(deps, `${JSON.stringify(data, null, 2)}
253
+ `);
254
+ } else {
255
+ writeOutput(deps, `Invited ${email.trim()} to space ${spaceId} as ${role}
256
+ `);
257
+ }
258
+ return 0;
259
+ }
260
+ const spaceKey = createSpaceKey.space(spaceId);
261
+ const spaceRecord = await readDbRecord({
262
+ dbKey: spaceKey,
263
+ authToken,
264
+ fetchImpl,
265
+ serverUrl
266
+ });
267
+ const members = Array.isArray(spaceRecord?.members) ? spaceRecord.members : [];
268
+ if (!members.includes(userId)) {
269
+ throw new Error("current user is not a member of this space.");
270
+ }
271
+ if (members.includes(memberId)) {
272
+ throw new Error("member already exists in this space.");
273
+ }
274
+ const now = Date.now();
275
+ const updatedSpaceRecord = {
276
+ ...spaceRecord,
277
+ members: [...members, memberId],
278
+ updatedAt: now
279
+ };
280
+ if (!memberId?.trim()) {
281
+ throw new Error("space invite requires --member <userId>.");
282
+ }
283
+ const memberKey = createSpaceKey.member(memberId.trim(), spaceId);
284
+ const memberRecord = {
285
+ dbKey: memberKey,
286
+ type: "space" /* SPACE */,
287
+ userId: memberId,
288
+ role,
289
+ joinedAt: now,
290
+ updatedAt: now,
291
+ spaceId,
292
+ spaceName: spaceRecord.name ?? spaceId,
293
+ ownerId: spaceRecord.ownerId,
294
+ visibility: spaceRecord.visibility ?? "private" /* PRIVATE */,
295
+ spaceCreatedAt: spaceRecord.createdAt,
296
+ spaceUpdatedAt: now
297
+ };
298
+ await writeDbRecord({ authToken, dbKey: spaceKey, fetchImpl, record: updatedSpaceRecord, serverUrl, userId });
299
+ await writeDbRecord({ authToken, dbKey: memberKey, fetchImpl, record: memberRecord, serverUrl, userId });
300
+ const result = { spaceId, spaceKey, memberKey, memberId, role, serverUrl };
301
+ if (hasFlag(args, "--json")) {
302
+ writeOutput(deps, `${JSON.stringify(result, null, 2)}
303
+ `);
304
+ } else {
305
+ writeOutput(deps, `Invited ${memberId} to space ${spaceId} as ${role}
306
+ `);
307
+ }
308
+ return 0;
309
+ }
310
+ async function runSpaceAcceptInviteCommand(args, deps) {
311
+ if (hasHelpArg(args)) {
312
+ printAcceptInviteUsage(deps.output ?? process.stdout);
313
+ return 0;
314
+ }
315
+ const inviteToken = readOption(args, "--invite") ?? readOption(args, "--space-invite") ?? readOption(args, "--invite-token");
316
+ if (!inviteToken?.trim()) {
317
+ throw new Error("space accept-invite requires --invite <inviteToken>.");
318
+ }
319
+ const { authToken } = requireTokenUser(args, deps.env);
320
+ const serverUrl = resolveServerUrl(args, deps.env);
321
+ const fetchImpl = deps.fetchImpl ?? fetch;
322
+ const response = await fetchImpl(`${serverUrl}${authRoutes.users.spaceInviteAccept.path}`, {
323
+ method: authRoutes.users.spaceInviteAccept.method,
324
+ headers: {
325
+ Authorization: `Bearer ${authToken}`,
326
+ "Content-Type": "application/json"
327
+ },
328
+ body: JSON.stringify({
329
+ token: inviteToken.trim()
330
+ })
331
+ });
332
+ const data = await response.json().catch(() => ({}));
333
+ if (!response.ok) {
334
+ throw new Error(
335
+ data?.error?.message || data?.error || `space invite accept failed: HTTP ${response.status}`
336
+ );
337
+ }
338
+ if (hasFlag(args, "--json")) {
339
+ writeOutput(deps, `${JSON.stringify(data, null, 2)}
340
+ `);
341
+ } else {
342
+ writeOutput(deps, `Accepted invite for space ${data?.spaceId ?? ""}
343
+ `);
344
+ }
345
+ return 0;
346
+ }
347
+ async function runSpaceUploadCommand(args, deps) {
348
+ if (hasHelpArg(args)) {
349
+ printUploadUsage(deps.output ?? process.stdout);
350
+ return 0;
351
+ }
352
+ const spaceIdRaw = readOption(args, "--space") ?? readOption(args, "--space-id");
353
+ const filePath = readOption(args, "--file");
354
+ if (!spaceIdRaw?.trim()) throw new Error("space upload requires --space <spaceId>.");
355
+ if (!filePath?.trim()) throw new Error("space upload requires --file <path>.");
356
+ const ext = extname(filePath).toLowerCase();
357
+ if (ext !== ".yaml" && ext !== ".yml") {
358
+ throw new Error("Only YAML files (.yaml, .yml) are supported for space upload.");
359
+ }
360
+ const { authToken, userId } = requireTokenUser(args, deps.env);
361
+ const serverUrl = resolveServerUrl(args, deps.env);
362
+ const fetchImpl = deps.fetchImpl ?? fetch;
363
+ const spaceId = normalizeSpaceId(spaceIdRaw);
364
+ const fileContent = readFileSync(filePath);
365
+ const spaceKey = createSpaceKey.space(spaceId);
366
+ const uploadName = basename(filePath);
367
+ const mimeType = "application/yaml";
368
+ const now = Date.now();
369
+ const nowIso = new Date(now).toISOString();
370
+ const { record: spaceRecord } = await readLiveDbRecordAfterTombstoneMerge({
371
+ dbKey: spaceKey,
372
+ authToken,
373
+ fetchImpl,
374
+ serverUrls: resolveServerCandidates(args, deps.env, serverUrl)
375
+ });
376
+ const formData = new FormData();
377
+ formData.append("file", new Blob([fileContent], { type: mimeType }), uploadName);
378
+ const fileId = (0, import_ulid.ulid)();
379
+ const fileDbKey = `file-${userId}-${fileId}`;
380
+ formData.append("metadata", JSON.stringify({
381
+ id: fileId,
382
+ title: uploadName,
383
+ originalName: uploadName,
384
+ fileName: `${fileId}${ext}`,
385
+ filePath: "",
386
+ size: fileContent.length,
387
+ mimeType,
388
+ type: "file" /* FILE */,
389
+ fileCategory: resolveFileCategory({
390
+ mimeType,
391
+ fileName: uploadName
392
+ }),
393
+ dbKey: fileDbKey,
394
+ userId,
395
+ ownerType: "space",
396
+ ownerId: spaceId,
397
+ ownerDbKey: spaceKey,
398
+ source: "cli-space-upload",
399
+ createdAt: nowIso,
400
+ updatedAt: nowIso
401
+ }));
402
+ formData.append("customKey", fileDbKey);
403
+ formData.append("userId", userId);
404
+ formData.append("ownerType", "space");
405
+ formData.append("ownerId", spaceId);
406
+ const uploadRes = await fetchImpl(`${serverUrl}/api/v1/db/upload`, {
407
+ method: "POST",
408
+ headers: {
409
+ Authorization: `Bearer ${authToken}`
410
+ },
411
+ body: formData
412
+ });
413
+ const uploadData = await uploadRes.json().catch(() => ({}));
414
+ if (!uploadRes.ok) {
415
+ throw new Error(
416
+ uploadData?.error?.message || uploadData?.error || `space upload failed: HTTP ${uploadRes.status}`
417
+ );
418
+ }
419
+ const contents = spaceRecord.contents || {};
420
+ contents[fileDbKey] = {
421
+ ...contents[fileDbKey] ?? {},
422
+ title: uploadName,
423
+ type: "file" /* FILE */,
424
+ contentKey: fileDbKey,
425
+ createdAt: contents[fileDbKey]?.createdAt ?? now,
426
+ updatedAt: now
427
+ };
428
+ await writeDbRecord({
429
+ authToken,
430
+ dbKey: spaceKey,
431
+ fetchImpl,
432
+ record: { ...spaceRecord, contents, updatedAt: now },
433
+ serverUrl,
434
+ userId
435
+ });
436
+ if (hasFlag(args, "--json")) {
437
+ writeOutput(deps, `${JSON.stringify({ ...uploadData, spaceId, spaceKey }, null, 2)}
438
+ `);
439
+ } else {
440
+ writeOutput(deps, `Uploaded ${uploadName} to space ${spaceId} (fileId: ${fileId})
441
+ `);
442
+ }
443
+ return 0;
444
+ }
445
+ export {
446
+ runSpaceAcceptInviteCommand,
447
+ runSpaceCreateCommand,
448
+ runSpaceInviteCommand,
449
+ runSpaceUploadCommand
450
+ };
@@ -0,0 +1,145 @@
1
+ import {
2
+ DEFAULT_COLLAPSED_CATEGORIES,
3
+ addCategory,
4
+ addContentToSpace,
5
+ addMember,
6
+ addSpace,
7
+ applySpaceEvent,
8
+ changeSpace,
9
+ dedupeMemberSpacesById,
10
+ deleteCategory,
11
+ deleteContentFromSpace,
12
+ deleteMultipleContent,
13
+ deleteSpace,
14
+ fetchSpace,
15
+ fetchSpaceSidebarState,
16
+ fetchUserSpaceMemberships,
17
+ fixSpace,
18
+ hydrateMemberSpacesFromLocal,
19
+ markDialogRead,
20
+ moveContentToSpace,
21
+ removeMember,
22
+ reorderCategories,
23
+ resetSpace,
24
+ selectAllMemberSpaces,
25
+ selectCollapsedCategories,
26
+ selectCurrentSpace,
27
+ selectCurrentSpaceId,
28
+ selectDialogEventTimestamps,
29
+ selectDialogStatus,
30
+ selectDialogStatusFromEntity,
31
+ selectDialogStatuses,
32
+ selectDialogTitles,
33
+ selectIsCategoryCollapsed,
34
+ selectIsDialogUnread,
35
+ selectIsDialogUnreadFromEntity,
36
+ selectMembershipStatus,
37
+ selectOwnedMemberSpaces,
38
+ selectSpaceInitialized,
39
+ selectSpaceLoading,
40
+ selectUnreadDialogIds,
41
+ selectViewMode,
42
+ setAllCategoriesCollapsed,
43
+ setViewMode,
44
+ spaceSlice_default,
45
+ toggleCategoryCollapse,
46
+ updateCategoryName,
47
+ updateContentCategory,
48
+ updateContentPinned,
49
+ updateContentTitle,
50
+ updateSpace,
51
+ uploadAndAddFileToSpace
52
+ } from "./chunk-TKOUBWBO.js";
53
+ import "./chunk-MRC4Q34M.js";
54
+ import "./chunk-J4576WMJ.js";
55
+ import "./chunk-CWMSB67P.js";
56
+ import "./chunk-POCFIDGQ.js";
57
+ import "./chunk-IYQV26RA.js";
58
+ import "./chunk-Z4NR32XR.js";
59
+ import "./chunk-M76ECQRD.js";
60
+ import "./chunk-AUGHVUFE.js";
61
+ import "./chunk-H2RMRZJE.js";
62
+ import "./chunk-UAD2WT54.js";
63
+ import "./chunk-USZMK5UT.js";
64
+ import "./chunk-5MMAK75Q.js";
65
+ import "./chunk-572EKYLF.js";
66
+ import "./chunk-TDIQFT2F.js";
67
+ import "./chunk-JZPBVBIY.js";
68
+ import "./chunk-BR2WP3DF.js";
69
+ import "./chunk-DFFIZ25G.js";
70
+ import "./chunk-3ASDTTEI.js";
71
+ import "./chunk-DWLEOOGR.js";
72
+ import "./chunk-HNMXYYJR.js";
73
+ import "./chunk-VEJLAVTC.js";
74
+ import "./chunk-Y5GCAMGP.js";
75
+ import "./chunk-G5H7RNFL.js";
76
+ import "./chunk-AZPCASRE.js";
77
+ import "./chunk-2EISRLRC.js";
78
+ import "./chunk-KX6YBIHG.js";
79
+ import "./chunk-PN7AFLOK.js";
80
+ import "./chunk-WWC7I6TA.js";
81
+ import "./chunk-QSJ3HFEF.js";
82
+ import "./chunk-ELRRLDWI.js";
83
+ import "./chunk-EYEEHCU4.js";
84
+ import "./chunk-QYXLLLGL.js";
85
+ import "./chunk-GBRG75BQ.js";
86
+ import "./chunk-4SN6J65J.js";
87
+ import "./chunk-LCBAMY2M.js";
88
+ import "./chunk-3EUW3WEO.js";
89
+ import "./chunk-U6VC4MU4.js";
90
+ import "./chunk-CF7PE763.js";
91
+ import "./chunk-G3SUCT4W.js";
92
+ import "./chunk-KUG52IAP.js";
93
+ import "./chunk-4VNS5WPM.js";
94
+ export {
95
+ DEFAULT_COLLAPSED_CATEGORIES,
96
+ addCategory,
97
+ addContentToSpace,
98
+ addMember,
99
+ addSpace,
100
+ applySpaceEvent,
101
+ changeSpace,
102
+ dedupeMemberSpacesById,
103
+ spaceSlice_default as default,
104
+ deleteCategory,
105
+ deleteContentFromSpace,
106
+ deleteMultipleContent,
107
+ deleteSpace,
108
+ fetchSpace,
109
+ fetchSpaceSidebarState,
110
+ fetchUserSpaceMemberships,
111
+ fixSpace,
112
+ hydrateMemberSpacesFromLocal,
113
+ markDialogRead,
114
+ moveContentToSpace,
115
+ removeMember,
116
+ reorderCategories,
117
+ resetSpace,
118
+ selectAllMemberSpaces,
119
+ selectCollapsedCategories,
120
+ selectCurrentSpace,
121
+ selectCurrentSpaceId,
122
+ selectDialogEventTimestamps,
123
+ selectDialogStatus,
124
+ selectDialogStatusFromEntity,
125
+ selectDialogStatuses,
126
+ selectDialogTitles,
127
+ selectIsCategoryCollapsed,
128
+ selectIsDialogUnread,
129
+ selectIsDialogUnreadFromEntity,
130
+ selectMembershipStatus,
131
+ selectOwnedMemberSpaces,
132
+ selectSpaceInitialized,
133
+ selectSpaceLoading,
134
+ selectUnreadDialogIds,
135
+ selectViewMode,
136
+ setAllCategoriesCollapsed,
137
+ setViewMode,
138
+ toggleCategoryCollapse,
139
+ updateCategoryName,
140
+ updateContentCategory,
141
+ updateContentPinned,
142
+ updateContentTitle,
143
+ updateSpace,
144
+ uploadAndAddFileToSpace
145
+ };