nolo-cli 0.1.32 → 0.1.33

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 (230) hide show
  1. package/README.md +0 -6
  2. package/agent-runtime/agentRecordConfig.ts +2 -0
  3. package/agent-runtime/hostAdapter.ts +1 -0
  4. package/agent-runtime/index.ts +0 -21
  5. package/agent-runtime/localToolPolicy.ts +6 -13
  6. package/agent-runtime/localWorkspaceTools.ts +30 -333
  7. package/agent-runtime/platformChatProvider.ts +1 -4
  8. package/agent-runtime/runtimeToolPolicy.ts +47 -32
  9. package/agentAliases.ts +14 -83
  10. package/agentCommandSupport.ts +3 -6
  11. package/agentInternalCommandEntries.ts +2 -13
  12. package/agentListCommands.ts +19 -28
  13. package/agentMachineCommands.ts +40 -336
  14. package/agentPullCommand.ts +36 -56
  15. package/agentRecordCommands.ts +3 -5
  16. package/agentRecordHelpers.ts +22 -189
  17. package/agentRunCommand.ts +438 -107
  18. package/agentRuntimeLocal.ts +0 -10
  19. package/ai/agent/cliExecutor.ts +19 -323
  20. package/authCommands.ts +2 -36
  21. package/cli/agentAliases.ts +14 -83
  22. package/cli/agentCommandSupport.ts +3 -6
  23. package/cli/agentInternalCommandEntries.ts +2 -13
  24. package/cli/agentListCommands.ts +19 -28
  25. package/cli/agentMachineCommands.ts +40 -336
  26. package/cli/agentPullCommand.ts +36 -56
  27. package/cli/agentRecordCommands.ts +3 -5
  28. package/cli/agentRecordHelpers.ts +22 -189
  29. package/cli/agentRunCommand.ts +438 -107
  30. package/cli/agentRuntimeLocal.ts +0 -10
  31. package/cli/authCommands.ts +2 -36
  32. package/cli/cliEnvHelpers.ts +21 -162
  33. package/cli/client/agentRun.ts +853 -57
  34. package/cli/client/localRuntimeAdapter.ts +22 -159
  35. package/cli/client/streamingOutput.ts +3 -1
  36. package/cli/client/taskRunPrompt.ts +24 -7
  37. package/cli/commandRegistry.ts +2 -3
  38. package/cli/connectorRunArtifact.ts +10 -34
  39. package/cli/connectorWebSocketTarget.ts +6 -10
  40. package/cli/internalCommandEntries.ts +0 -8
  41. package/cli/localRuntimeDb.ts +2 -39
  42. package/cli/machineCommands.ts +189 -190
  43. package/cli/machineDaemonCommands.ts +165 -9
  44. package/cli/machineHeartbeatCommands.ts +2 -1
  45. package/cli/machineStatusCommands.ts +13 -5
  46. package/cli/machineWatchCommands.ts +1 -1
  47. package/cli/machineWsRunDispatch.ts +14 -48
  48. package/cli/machineWsSession.ts +0 -2
  49. package/cli/offlineMarxistsAgentCommand.ts +314 -0
  50. package/cli/runtimeDoctorCommands.ts +69 -18
  51. package/cli/scriptCommandEntries.ts +45 -5
  52. package/cli/tableCommands.ts +133 -33
  53. package/cli/taskRunCommand.ts +211 -16
  54. package/cli/tui/session.ts +372 -43
  55. package/cli/workflowInternalCommandEntries.ts +0 -20
  56. package/cliEnvHelpers.ts +21 -162
  57. package/client/agentConfigResolver.test.ts +2 -0
  58. package/client/agentRun.test.ts +12 -208
  59. package/client/agentRun.ts +853 -57
  60. package/client/localRuntimeAdapter.test.ts +9 -168
  61. package/client/localRuntimeAdapter.ts +22 -159
  62. package/client/localToolPolicy.test.ts +4 -28
  63. package/client/streamingOutput.ts +3 -1
  64. package/client/taskRunPrompt.ts +24 -7
  65. package/commandRegistry.ts +2 -3
  66. package/connectorRunArtifact.ts +10 -34
  67. package/connectorWebSocketTarget.ts +6 -10
  68. package/database/server/db.ts +34 -15
  69. package/internalCommandEntries.ts +0 -8
  70. package/localRuntimeDb.ts +2 -39
  71. package/machineCommands.ts +189 -190
  72. package/machineDaemonCommands.ts +165 -9
  73. package/machineHeartbeatCommands.ts +2 -1
  74. package/machineStatusCommands.ts +13 -5
  75. package/machineWatchCommands.ts +1 -1
  76. package/machineWsRunDispatch.ts +14 -48
  77. package/machineWsSession.ts +0 -2
  78. package/offlineMarxistsAgentCommand.ts +314 -0
  79. package/package.json +49 -193
  80. package/runtimeDoctorCommands.ts +69 -18
  81. package/scriptCommandEntries.ts +45 -5
  82. package/tableCommands.ts +133 -33
  83. package/taskRunCommand.ts +211 -16
  84. package/tui/session.ts +372 -43
  85. package/workflowInternalCommandEntries.ts +0 -20
  86. package/agent-runtime/dialogStatus.ts +0 -139
  87. package/agent-runtime/hostRuntimeConfig.ts +0 -86
  88. package/agentCreateCustomCommands.ts +0 -278
  89. package/agentDialogsCommands.ts +0 -227
  90. package/agentDoctorCommands.ts +0 -203
  91. package/agentRunLocalWorkspace.ts +0 -182
  92. package/agentRunParsing.ts +0 -298
  93. package/agentSuperviseCommands.ts +0 -8
  94. package/agentUnpublishCommands.ts +0 -113
  95. package/ai/agent/agentRunDialogLineage.ts +0 -56
  96. package/ai/policy/types.ts +0 -64
  97. package/ai/skills/skillSummaryMarker.ts +0 -26
  98. package/app/types.ts +0 -358
  99. package/build.ts +0 -16
  100. package/buildPublish.ts +0 -138
  101. package/buildPublishArtifactAssembly.ts +0 -724
  102. package/buildPublishImportAnalysis.ts +0 -242
  103. package/chat/messages/fetchMessages.ts +0 -84
  104. package/chat/messages/types.ts +0 -185
  105. package/cli/agentCreateCustomCommands.ts +0 -278
  106. package/cli/agentDialogsCommands.ts +0 -227
  107. package/cli/agentDoctorCommands.ts +0 -203
  108. package/cli/agentRunLocalWorkspace.ts +0 -182
  109. package/cli/agentRunParsing.ts +0 -298
  110. package/cli/agentSuperviseCommands.ts +0 -8
  111. package/cli/agentUnpublishCommands.ts +0 -113
  112. package/cli/buildPublish.ts +0 -138
  113. package/cli/buildPublishArtifactAssembly.ts +0 -724
  114. package/cli/buildPublishImportAnalysis.ts +0 -242
  115. package/cli/cliIoTypes.ts +0 -3
  116. package/cli/cliRuntimeDoctorReport.ts +0 -193
  117. package/cli/client/agentRunInput.ts +0 -10
  118. package/cli/client/agentRunLocalExecution.ts +0 -124
  119. package/cli/client/agentRunLocalExecutor.ts +0 -179
  120. package/cli/client/agentRunRuntimeSelection.ts +0 -145
  121. package/cli/client/agentRunServerTransport.ts +0 -397
  122. package/cli/client/agentRunTaskRunRecorder.ts +0 -176
  123. package/cli/customCodingAgentFlow.ts +0 -208
  124. package/cli/customCodingAgentRecord.ts +0 -179
  125. package/cli/dialogDataAccess.ts +0 -186
  126. package/cli/dialogInternalCommandEntries.ts +0 -11
  127. package/cli/dialogReadCommands.ts +0 -180
  128. package/cli/dialogReadHelpers.ts +0 -226
  129. package/cli/dialogStatusCommands.ts +0 -123
  130. package/cli/docInternalCommandEntries.ts +0 -20
  131. package/cli/hybridReadHelpers.ts +0 -109
  132. package/cli/machineCommandPrompts.ts +0 -79
  133. package/cli/machineCommandResolution.ts +0 -43
  134. package/cli/noloReadBridgePrompt.ts +0 -16
  135. package/cli/pageCreateCommands.ts +0 -219
  136. package/cli/pageDeleteCommands.ts +0 -167
  137. package/cli/pageReadCommands.ts +0 -151
  138. package/cli/pageUpdateCommands.ts +0 -249
  139. package/cli/pageWriteHelpers.ts +0 -209
  140. package/cli/publishPackage.ts +0 -36
  141. package/cli/runtimeInternalCommandEntries.ts +0 -15
  142. package/cli/runtimePassthroughCommands.ts +0 -22
  143. package/cli/scriptPassthroughHelpers.ts +0 -28
  144. package/cli/secretScanHelpers.ts +0 -31
  145. package/cli/spaceAttachCommands.ts +0 -134
  146. package/cli/spaceCategoryCommands.ts +0 -263
  147. package/cli/spaceCommands.ts +0 -295
  148. package/cli/spaceDeleteCommands.ts +0 -312
  149. package/cli/spaceInternalCommandEntries.ts +0 -21
  150. package/cli/spaceMutationHelpers.ts +0 -135
  151. package/cli/spaceReadCommands.ts +0 -323
  152. package/cli/tableDataOutput.ts +0 -41
  153. package/cli/tableDataSafety.ts +0 -26
  154. package/cli/tableMetaCommands.ts +0 -307
  155. package/cli/tableMutationCommands.ts +0 -266
  156. package/cli/tableQueryParsing.ts +0 -90
  157. package/cli/tableQueryRequest.ts +0 -53
  158. package/cli/taskRunActions.ts +0 -122
  159. package/cli/taskRunParsing.ts +0 -86
  160. package/cli/taskRunPromptShared.ts +0 -55
  161. package/cli/tui/tuiCatalog.ts +0 -22
  162. package/cli/tui/tuiCommandInterpreter.ts +0 -253
  163. package/cli/tui/tuiPresentation.ts +0 -146
  164. package/cliIoTypes.ts +0 -3
  165. package/cliRuntimeDoctorReport.ts +0 -193
  166. package/client/agentRunInput.ts +0 -10
  167. package/client/agentRunLocalExecution.test.ts +0 -123
  168. package/client/agentRunLocalExecution.ts +0 -124
  169. package/client/agentRunLocalExecutor.ts +0 -179
  170. package/client/agentRunRuntimeSelection.test.ts +0 -159
  171. package/client/agentRunRuntimeSelection.ts +0 -145
  172. package/client/agentRunServerTransport.ts +0 -397
  173. package/client/agentRunTaskRunRecorder.ts +0 -176
  174. package/connector-experimental/daemonLauncher.ts +0 -223
  175. package/create/space/spaceKeys.ts +0 -65
  176. package/create/types.ts +0 -21
  177. package/customCodingAgentFlow.ts +0 -208
  178. package/customCodingAgentRecord.ts +0 -179
  179. package/database/keys.ts +0 -765
  180. package/database/server/authorityStoreTypes.ts +0 -31
  181. package/database/server/legacyServerDb.ts +0 -58
  182. package/database/server/levelAuthorityStore.ts +0 -75
  183. package/database/server/memoryAuthorityStore.ts +0 -133
  184. package/database/server/serverStoreFactory.ts +0 -124
  185. package/database/tombstones.ts +0 -52
  186. package/database/utils/ulid.ts +0 -1
  187. package/dialogDataAccess.ts +0 -186
  188. package/dialogInternalCommandEntries.ts +0 -11
  189. package/dialogReadCommands.ts +0 -180
  190. package/dialogReadHelpers.ts +0 -226
  191. package/dialogStatusCommands.ts +0 -123
  192. package/docInternalCommandEntries.ts +0 -20
  193. package/hybridReadHelpers.ts +0 -109
  194. package/machineCommandPrompts.ts +0 -79
  195. package/machineCommandResolution.ts +0 -43
  196. package/noloReadBridgePrompt.ts +0 -16
  197. package/pageCreateCommands.ts +0 -219
  198. package/pageDeleteCommands.ts +0 -167
  199. package/pageReadCommands.ts +0 -151
  200. package/pageUpdateCommands.ts +0 -249
  201. package/pageWriteHelpers.ts +0 -209
  202. package/publishPackage.ts +0 -36
  203. package/runtimeInternalCommandEntries.ts +0 -15
  204. package/runtimePassthroughCommands.ts +0 -22
  205. package/scriptPassthroughHelpers.ts +0 -28
  206. package/secretScanHelpers.ts +0 -31
  207. package/share/helpers.ts +0 -302
  208. package/share/keys.ts +0 -243
  209. package/share/types.ts +0 -100
  210. package/spaceAttachCommands.ts +0 -134
  211. package/spaceCategoryCommands.ts +0 -263
  212. package/spaceCommands.ts +0 -295
  213. package/spaceDeleteCommands.ts +0 -312
  214. package/spaceInternalCommandEntries.ts +0 -21
  215. package/spaceMutationHelpers.ts +0 -135
  216. package/spaceReadCommands.ts +0 -323
  217. package/tableDataOutput.ts +0 -41
  218. package/tableDataSafety.ts +0 -26
  219. package/tableMetaCommands.ts +0 -307
  220. package/tableMutationCommands.ts +0 -266
  221. package/tableQueryParsing.ts +0 -90
  222. package/tableQueryRequest.ts +0 -53
  223. package/taskRunActions.ts +0 -122
  224. package/taskRunParsing.ts +0 -86
  225. package/taskRunPromptShared.ts +0 -55
  226. package/tui/tuiCatalog.ts +0 -22
  227. package/tui/tuiCommandInterpreter.test.ts +0 -169
  228. package/tui/tuiCommandInterpreter.ts +0 -253
  229. package/tui/tuiPresentation.test.ts +0 -154
  230. package/tui/tuiPresentation.ts +0 -146
@@ -1,312 +0,0 @@
1
- import { createSpaceKey, normalizeSpaceId } from "../create/space/spaceKeys";
2
- import { getReadableCliDb, type AgentCommandDeps } from "./agentCommandSupport";
3
- import { parseUserIdFromAuthToken, readOption, resolveAuthToken, resolveServerUrl } from "./cliEnvHelpers";
4
- import { readSpaceRecordWithFallback } from "./spaceMutationHelpers";
5
-
6
- type SpaceMembership = Record<string, any> & {
7
- spaceId?: string;
8
- name?: string;
9
- spaceName?: string;
10
- title?: string;
11
- };
12
-
13
- type DeleteTarget = {
14
- spaceId: string;
15
- name: string;
16
- spaceKey: string;
17
- memberKeys: string[];
18
- contentCount: number;
19
- };
20
-
21
- type SkippedTarget = {
22
- spaceId: string;
23
- name: string;
24
- reason: string;
25
- };
26
-
27
- function usage() {
28
- return [
29
- "Usage:",
30
- " nolo space delete --name-prefix <prefix> [--yes] [--json]",
31
- " nolo space delete --name <exact-name> [--yes] [--json]",
32
- " nolo space delete --space <spaceId|spaceKey|spaceUrl> [--yes] [--json]",
33
- "",
34
- ].join("\n");
35
- }
36
-
37
- function displayName(membership: SpaceMembership) {
38
- return String(
39
- membership.spaceName ??
40
- membership.name ??
41
- membership.title ??
42
- membership.spaceTitle ??
43
- ""
44
- ).trim();
45
- }
46
-
47
- function matchesMembership(args: string[], membership: SpaceMembership) {
48
- const requestedSpace = readOption(args, "--space");
49
- if (requestedSpace) {
50
- return normalizeSpaceId(String(membership.spaceId ?? "")) === normalizeSpaceId(requestedSpace);
51
- }
52
-
53
- const name = displayName(membership);
54
- const exactName = readOption(args, "--name");
55
- if (exactName) return name === exactName;
56
-
57
- const prefix = readOption(args, "--name-prefix");
58
- if (prefix) return name.startsWith(prefix);
59
-
60
- throw new Error("space delete requires --space, --name, or --name-prefix");
61
- }
62
-
63
- function listMemberKeys(spaceRecord: Record<string, any>, userId: string, spaceId: string) {
64
- const memberIds = new Set<string>();
65
- memberIds.add(userId);
66
-
67
- const members = spaceRecord.members;
68
- if (Array.isArray(members)) {
69
- for (const memberId of members) {
70
- if (typeof memberId === "string" && memberId.trim()) {
71
- memberIds.add(memberId.trim());
72
- }
73
- }
74
- } else if (members && typeof members === "object") {
75
- for (const memberId of Object.keys(members)) {
76
- if (memberId.trim()) memberIds.add(memberId.trim());
77
- }
78
- }
79
-
80
- return Array.from(memberIds).map((memberId) => createSpaceKey.member(memberId, spaceId));
81
- }
82
-
83
- async function fetchMemberships(args: {
84
- authToken: string;
85
- fetchImpl: typeof fetch;
86
- serverUrl: string;
87
- userId: string;
88
- }) {
89
- const response = await args.fetchImpl(`${args.serverUrl}/rpc/getUserSpaceMemberships`, {
90
- method: "POST",
91
- headers: {
92
- Authorization: `Bearer ${args.authToken}`,
93
- "Content-Type": "application/json",
94
- },
95
- body: JSON.stringify({ userId: args.userId }),
96
- });
97
- const data = await response.json().catch(() => ({}));
98
- if (!response.ok || !Array.isArray(data)) {
99
- throw new Error(`failed to list memberships (${response.status}): ${JSON.stringify(data)}`);
100
- }
101
- return data as SpaceMembership[];
102
- }
103
-
104
- async function buildTarget(args: {
105
- authToken: string;
106
- db: Awaited<ReturnType<typeof getReadableCliDb>>;
107
- fallbackFetchImpl?: typeof fetch;
108
- fetchImpl: typeof fetch;
109
- membership: SpaceMembership;
110
- serverUrl: string;
111
- userId: string;
112
- }): Promise<DeleteTarget | SkippedTarget> {
113
- const spaceId = normalizeSpaceId(String(args.membership.spaceId ?? ""));
114
- const name = displayName(args.membership) || spaceId;
115
- if (!spaceId) {
116
- return { spaceId: "", name, reason: "membership has no spaceId" };
117
- }
118
-
119
- let spaceRecord: Record<string, any>;
120
- try {
121
- spaceRecord = await readSpaceRecordWithFallback({
122
- authToken: args.authToken,
123
- db: args.db,
124
- fallbackFetchImpl: args.fallbackFetchImpl,
125
- fetchImpl: args.fetchImpl,
126
- serverCandidates: [args.serverUrl],
127
- spaceId,
128
- });
129
- } catch (error) {
130
- const message = error instanceof Error ? error.message : String(error);
131
- return { spaceId, name, reason: `failed to read space record: ${message}` };
132
- }
133
-
134
- const ownerId = typeof spaceRecord.ownerId === "string" ? spaceRecord.ownerId : "";
135
- if (ownerId && ownerId !== args.userId) {
136
- return { spaceId, name, reason: `current user is not owner (${ownerId})` };
137
- }
138
-
139
- const contents = spaceRecord.contents;
140
- return {
141
- spaceId,
142
- name: displayName(args.membership) || String(spaceRecord.name ?? spaceRecord.title ?? spaceId),
143
- spaceKey: createSpaceKey.space(spaceId),
144
- memberKeys: listMemberKeys(spaceRecord, args.userId, spaceId),
145
- contentCount: contents && typeof contents === "object" ? Object.keys(contents).length : 0,
146
- };
147
- }
148
-
149
- async function deleteKey(args: {
150
- authToken: string;
151
- fetchImpl: typeof fetch;
152
- key: string;
153
- serverUrl: string;
154
- }) {
155
- const response = await args.fetchImpl(
156
- `${args.serverUrl}/api/v1/db/delete/${encodeURIComponent(args.key)}`,
157
- {
158
- method: "DELETE",
159
- headers: {
160
- Authorization: `Bearer ${args.authToken}`,
161
- },
162
- }
163
- );
164
- const text = await response.text();
165
- let data: any = {};
166
- if (text) {
167
- try {
168
- data = JSON.parse(text);
169
- } catch {
170
- data = {};
171
- }
172
- }
173
- if (!response.ok) {
174
- throw new Error(`delete ${args.key} failed (${response.status}): ${JSON.stringify(data)}`);
175
- }
176
- }
177
-
178
- export async function runSpaceDeleteCommand(
179
- args: string[],
180
- deps: AgentCommandDeps = {}
181
- ) {
182
- const env = deps.env ?? process.env;
183
- const output = deps.output ?? process.stdout;
184
-
185
- if (args.includes("--help") || args.includes("-h")) {
186
- output.write(`${usage()}\n`);
187
- return 0;
188
- }
189
-
190
- const requestedSpace = readOption(args, "--space");
191
- const exactName = readOption(args, "--name");
192
- const prefix = readOption(args, "--name-prefix");
193
- if (!requestedSpace && !exactName && !prefix) {
194
- output.write(`${usage()}\n`);
195
- return 1;
196
- }
197
-
198
- const authToken = resolveAuthToken(args, env);
199
- const userId = parseUserIdFromAuthToken(authToken);
200
- if (!authToken || !userId) {
201
- output.write("[nolo] space delete requires an auth token with userId. Run `nolo login`.\n");
202
- return 1;
203
- }
204
-
205
- const shouldDelete = args.includes("--yes");
206
- const wantJson = args.includes("--json");
207
- const db = deps.db ?? await getReadableCliDb(output);
208
- const fetchImpl = deps.fetchImpl ?? fetch;
209
- const fallbackFetchImpl = deps.fallbackFetchImpl;
210
- const serverUrl = resolveServerUrl(args, env);
211
-
212
- try {
213
- const memberships = await fetchMemberships({
214
- authToken,
215
- fetchImpl,
216
- serverUrl,
217
- userId,
218
- });
219
- const matchingMemberships = memberships.filter((membership) => matchesMembership(args, membership));
220
- const inspected = await Promise.all(
221
- matchingMemberships.map((membership) =>
222
- buildTarget({
223
- authToken,
224
- db,
225
- fallbackFetchImpl,
226
- fetchImpl,
227
- membership,
228
- serverUrl,
229
- userId,
230
- })
231
- )
232
- );
233
-
234
- const targets = inspected.filter((item): item is DeleteTarget => "spaceKey" in item);
235
- const skipped = inspected.filter((item): item is SkippedTarget => !("spaceKey" in item));
236
- const deletedKeys: string[] = [];
237
-
238
- if (shouldDelete) {
239
- for (const target of targets) {
240
- for (const memberKey of target.memberKeys) {
241
- await deleteKey({
242
- authToken,
243
- fetchImpl,
244
- key: memberKey,
245
- serverUrl,
246
- });
247
- deletedKeys.push(memberKey);
248
- }
249
- await deleteKey({
250
- authToken,
251
- fetchImpl,
252
- key: target.spaceKey,
253
- serverUrl,
254
- });
255
- deletedKeys.push(target.spaceKey);
256
- await db.batch([
257
- ...target.memberKeys.map((key) => ({ type: "del" as const, key })),
258
- { type: "del" as const, key: target.spaceKey },
259
- ]);
260
- }
261
- }
262
-
263
- const result = {
264
- baseUrl: serverUrl,
265
- userId,
266
- dryRun: !shouldDelete,
267
- totalMemberships: memberships.length,
268
- matchCount: matchingMemberships.length,
269
- deletableCount: targets.length,
270
- skipped,
271
- targets: targets.map((target) => ({
272
- spaceId: target.spaceId,
273
- name: target.name,
274
- spaceKey: target.spaceKey,
275
- memberKeys: target.memberKeys,
276
- contentCount: target.contentCount,
277
- })),
278
- deletedKeys,
279
- };
280
-
281
- if (wantJson) {
282
- output.write(`${JSON.stringify(result, null, 2)}\n`);
283
- return 0;
284
- }
285
-
286
- output.write(`Base: ${result.baseUrl}\n`);
287
- output.write(`User: ${result.userId}\n`);
288
- output.write(`Matched spaces: ${result.matchCount}\n`);
289
- for (const target of result.targets) {
290
- output.write(`- ${target.name} (${target.spaceId})\n`);
291
- output.write(` space key: ${target.spaceKey}\n`);
292
- output.write(` member keys: ${target.memberKeys.join(", ") || "(none)"}\n`);
293
- output.write(` contents preserved: ${target.contentCount}\n`);
294
- }
295
- for (const item of skipped) {
296
- output.write(`- skipped ${item.name || item.spaceId}: ${item.reason}\n`);
297
- }
298
- output.write(
299
- shouldDelete
300
- ? `Deleted keys: ${deletedKeys.length}\n`
301
- : "Dry-run only. Add --yes to delete the matched spaces.\n"
302
- );
303
- return 0;
304
- } catch (error) {
305
- output.write(
306
- `[nolo] space delete failed: ${
307
- error instanceof Error ? error.message : String(error)
308
- }\n`
309
- );
310
- return 1;
311
- }
312
- }
@@ -1,21 +0,0 @@
1
- import { createEnvCommand } from "./cliCommandFactories";
2
- import type { CommandEntry } from "./cliCommandTypes";
3
- import { runSpaceAttachAgentCommand } from "./spaceAttachCommands";
4
- import {
5
- runSpaceCategoryCommand,
6
- runSpaceContentCategoryCommand,
7
- } from "./spaceCategoryCommands";
8
- import { runSpaceDeleteCommand } from "./spaceDeleteCommands";
9
- import { runSpaceListCommand } from "./spaceCommands";
10
- import { runSpaceReadCommand } from "./spaceReadCommands";
11
-
12
- export function getSpaceInternalCommandEntries(): CommandEntry[] {
13
- return [
14
- createEnvCommand(["space", "list"], "List joined spaces", runSpaceListCommand),
15
- createEnvCommand(["space", "read"], "Read a space", runSpaceReadCommand),
16
- createEnvCommand(["space", "attach-agent"], "Attach an existing agent to a space", runSpaceAttachAgentCommand),
17
- createEnvCommand(["space", "category"], "Create or update a space category", runSpaceCategoryCommand),
18
- createEnvCommand(["space", "content-category"], "Move content into a space category", runSpaceContentCategoryCommand),
19
- createEnvCommand(["space", "delete"], "Delete spaces by safe filters", runSpaceDeleteCommand),
20
- ];
21
- }
@@ -1,135 +0,0 @@
1
- import { createSpaceKey, normalizeSpaceId } from "../create/space/spaceKeys";
2
- import type { CliKvDb } from "./client/hybridRecordStore";
3
- import { readDbRecord, writeDbRecord } from "./agentRecordHelpers";
4
-
5
- export function parseSpaceIdFromInput(raw: string): string {
6
- const trimmed = raw.trim();
7
- if (!trimmed) {
8
- throw new Error("Space id/url is empty.");
9
- }
10
-
11
- if (trimmed.startsWith("http://") || trimmed.startsWith("https://")) {
12
- const url = new URL(trimmed);
13
- const fromQuery = url.searchParams.get("spaceId");
14
- if (fromQuery) {
15
- return normalizeSpaceId(fromQuery);
16
- }
17
-
18
- const parts = url.pathname.split("/").filter(Boolean);
19
- const spaceIndex = parts.findIndex((part) => part === "space");
20
- if (spaceIndex >= 0 && parts[spaceIndex + 1]) {
21
- return normalizeSpaceId(parts[spaceIndex + 1]);
22
- }
23
-
24
- throw new Error(`Unsupported space URL: ${trimmed}`);
25
- }
26
-
27
- return normalizeSpaceId(trimmed);
28
- }
29
-
30
- export async function readSpaceRecordWithFallback(args: {
31
- authToken: string;
32
- db: CliKvDb;
33
- fallbackFetchImpl?: typeof fetch;
34
- fetchImpl: typeof fetch;
35
- serverCandidates: string[];
36
- spaceId: string;
37
- }) {
38
- const spaceKey = createSpaceKey.space(args.spaceId);
39
- try {
40
- return await args.db.get(spaceKey);
41
- } catch {
42
- let lastError: Error | null = null;
43
- for (const serverUrl of args.serverCandidates) {
44
- try {
45
- return await readDbRecord({
46
- authToken: args.authToken,
47
- dbKey: spaceKey,
48
- fallbackFetchImpl: args.fallbackFetchImpl,
49
- fetchImpl: args.fetchImpl,
50
- serverUrl,
51
- });
52
- } catch (error) {
53
- lastError = error instanceof Error ? error : new Error(String(error));
54
- }
55
- }
56
- throw lastError ?? new Error(`Failed to read ${spaceKey}`);
57
- }
58
- }
59
-
60
- export async function writeSpaceRecord(args: {
61
- authToken: string;
62
- db: CliKvDb;
63
- fallbackFetchImpl?: typeof fetch;
64
- fetchImpl: typeof fetch;
65
- record: Record<string, any>;
66
- serverUrl: string;
67
- spaceId: string;
68
- userId: string;
69
- }) {
70
- const spaceKey = createSpaceKey.space(args.spaceId);
71
- await writeDbRecord({
72
- authToken: args.authToken,
73
- dbKey: spaceKey,
74
- fallbackFetchImpl: args.fallbackFetchImpl,
75
- fetchImpl: args.fetchImpl,
76
- record: args.record,
77
- serverUrl: args.serverUrl,
78
- userId: args.userId,
79
- });
80
- await args.db.put(spaceKey, args.record);
81
- }
82
-
83
- export function buildTableAttachedSpaceRecord(args: {
84
- categoryId?: string;
85
- contentKey: string;
86
- existingSpaceRecord: Record<string, any>;
87
- spaceId: string;
88
- title: string;
89
- }) {
90
- const { categoryId, contentKey, existingSpaceRecord, spaceId, title } = args;
91
- const now = Date.now();
92
- const existingContent = existingSpaceRecord?.contents?.[contentKey];
93
- const categoryIdForStorage =
94
- categoryId && existingSpaceRecord?.categories?.[categoryId] ? categoryId : undefined;
95
-
96
- return {
97
- ...existingSpaceRecord,
98
- dbKey: createSpaceKey.space(spaceId),
99
- updatedAt: now,
100
- contents: {
101
- ...(existingSpaceRecord?.contents ?? {}),
102
- [contentKey]: {
103
- ...(existingContent ?? {}),
104
- title,
105
- type: "table",
106
- contentKey,
107
- ...(categoryIdForStorage ? { categoryId: categoryIdForStorage } : {}),
108
- updatedAt: now,
109
- createdAt: existingContent?.createdAt ?? now,
110
- },
111
- },
112
- };
113
- }
114
-
115
- export function parseContentKeys(args: string[]) {
116
- const keys = new Set<string>();
117
- const singleIndex = args.indexOf("--content-key");
118
- if (singleIndex >= 0 && args[singleIndex + 1]?.trim()) {
119
- keys.add(args[singleIndex + 1].trim());
120
- }
121
- const listIndex = args.indexOf("--content-keys");
122
- if (listIndex >= 0) {
123
- const raw = args[listIndex + 1];
124
- const parsed = JSON.parse(raw ?? "null");
125
- if (!Array.isArray(parsed)) {
126
- throw new Error("--content-keys must be a JSON array.");
127
- }
128
- for (const item of parsed) {
129
- if (typeof item === "string" && item.trim()) {
130
- keys.add(item.trim());
131
- }
132
- }
133
- }
134
- return Array.from(keys);
135
- }