nolo-cli 0.1.32 → 0.1.34

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 (234) hide show
  1. package/README.md +4 -10
  2. package/agent-runtime/agentRecordConfig.ts +10 -0
  3. package/agent-runtime/hostAdapter.ts +10 -1
  4. package/agent-runtime/index.ts +9 -20
  5. package/agent-runtime/localLoop.ts +49 -2
  6. package/agent-runtime/localToolPolicy.ts +76 -34
  7. package/agent-runtime/localWorkspaceTools.ts +30 -333
  8. package/agent-runtime/openAiCompatibleProvider.ts +7 -3
  9. package/agent-runtime/openAiCompatibleProviderConfig.ts +15 -26
  10. package/agent-runtime/platformChatProvider.ts +47 -73
  11. package/agent-runtime/providerResolution.ts +244 -0
  12. package/agent-runtime/runtimeToolPolicy.ts +77 -29
  13. package/agent-runtime/shellCommandPolicy.ts +120 -0
  14. package/agentAliases.ts +14 -83
  15. package/agentCommandSupport.ts +3 -6
  16. package/agentInternalCommandEntries.ts +4 -13
  17. package/agentListCommands.ts +18 -27
  18. package/agentMachineCommands.ts +40 -336
  19. package/agentPullCommand.ts +30 -55
  20. package/agentRecordCommands.ts +84 -1
  21. package/agentRecordHelpers.ts +102 -186
  22. package/agentRunCommand.ts +438 -107
  23. package/agentRuntimeLocal.ts +2 -9
  24. package/ai/agent/cliExecutor.ts +19 -323
  25. package/ai/tools/toolNameAliases.ts +70 -0
  26. package/authCommands.ts +2 -36
  27. package/cli/agentAliases.ts +14 -83
  28. package/cli/agentCommandSupport.ts +3 -6
  29. package/cli/agentInternalCommandEntries.ts +4 -13
  30. package/cli/agentListCommands.ts +18 -27
  31. package/cli/agentMachineCommands.ts +40 -336
  32. package/cli/agentPullCommand.ts +30 -55
  33. package/cli/agentRecordCommands.ts +84 -1
  34. package/cli/agentRecordHelpers.ts +102 -186
  35. package/cli/agentRunCommand.ts +438 -107
  36. package/cli/agentRuntimeLocal.ts +2 -9
  37. package/cli/authCommands.ts +2 -36
  38. package/cli/cliCommandDispatch.ts +2 -2
  39. package/cli/cliEnvHelpers.ts +34 -107
  40. package/cli/client/agentRun.ts +854 -57
  41. package/cli/client/localRuntimeAdapter.ts +59 -159
  42. package/cli/client/streamingOutput.ts +3 -1
  43. package/cli/client/taskRunPrompt.ts +24 -7
  44. package/cli/commandRegistry.ts +4 -5
  45. package/cli/connectorRunArtifact.ts +10 -34
  46. package/cli/connectorWebSocketTarget.ts +6 -10
  47. package/cli/internalCommandEntries.ts +0 -8
  48. package/cli/localRuntimeDb.ts +2 -39
  49. package/cli/machineCommands.ts +189 -190
  50. package/cli/machineDaemonCommands.ts +165 -9
  51. package/cli/machineHeartbeatCommands.ts +2 -1
  52. package/cli/machineStatusCommands.ts +13 -5
  53. package/cli/machineWatchCommands.ts +1 -1
  54. package/cli/machineWsRunDispatch.ts +30 -44
  55. package/cli/machineWsSession.ts +0 -2
  56. package/cli/offlineMarxistsAgentCommand.ts +314 -0
  57. package/cli/runtimeDoctorCommands.ts +72 -15
  58. package/cli/scriptCommandEntries.ts +45 -5
  59. package/cli/tableCommands.ts +133 -33
  60. package/cli/taskRunCommand.ts +211 -16
  61. package/cli/tui/session.ts +372 -43
  62. package/cli/workflowInternalCommandEntries.ts +0 -20
  63. package/cliCommandDispatch.ts +2 -2
  64. package/cliEnvHelpers.ts +34 -107
  65. package/client/agentConfigResolver.test.ts +2 -0
  66. package/client/agentRun.test.ts +12 -208
  67. package/client/agentRun.ts +854 -57
  68. package/client/localProviderResolver.test.ts +26 -2
  69. package/client/localRuntimeAdapter.test.ts +296 -171
  70. package/client/localRuntimeAdapter.ts +59 -159
  71. package/client/localToolPolicy.test.ts +4 -28
  72. package/client/streamingOutput.ts +3 -1
  73. package/client/taskRunPrompt.ts +24 -7
  74. package/commandRegistry.ts +4 -5
  75. package/connectorRunArtifact.ts +10 -34
  76. package/connectorWebSocketTarget.ts +6 -10
  77. package/database/server/serverStoreFactory.ts +2 -8
  78. package/internalCommandEntries.ts +0 -8
  79. package/localRuntimeDb.ts +2 -39
  80. package/machineCommands.ts +189 -190
  81. package/machineDaemonCommands.ts +165 -9
  82. package/machineHeartbeatCommands.ts +2 -1
  83. package/machineStatusCommands.ts +13 -5
  84. package/machineWatchCommands.ts +1 -1
  85. package/machineWsRunDispatch.ts +30 -44
  86. package/machineWsSession.ts +0 -2
  87. package/offlineMarxistsAgentCommand.ts +314 -0
  88. package/package.json +52 -188
  89. package/runtimeDoctorCommands.ts +72 -15
  90. package/scriptCommandEntries.ts +45 -5
  91. package/tableCommands.ts +133 -33
  92. package/taskRunCommand.ts +211 -16
  93. package/tui/session.ts +372 -43
  94. package/workflowInternalCommandEntries.ts +0 -20
  95. package/agent-runtime/dialogStatus.ts +0 -139
  96. package/agent-runtime/hostRuntimeConfig.ts +0 -86
  97. package/agentCreateCustomCommands.ts +0 -278
  98. package/agentDialogsCommands.ts +0 -227
  99. package/agentDoctorCommands.ts +0 -203
  100. package/agentRunLocalWorkspace.ts +0 -182
  101. package/agentRunParsing.ts +0 -298
  102. package/agentSuperviseCommands.ts +0 -8
  103. package/agentUnpublishCommands.ts +0 -113
  104. package/ai/agent/agentRunDialogLineage.ts +0 -56
  105. package/ai/policy/types.ts +0 -64
  106. package/ai/skills/skillSummaryMarker.ts +0 -26
  107. package/app/types.ts +0 -358
  108. package/build.ts +0 -16
  109. package/buildPublish.ts +0 -138
  110. package/buildPublishArtifactAssembly.ts +0 -724
  111. package/buildPublishImportAnalysis.ts +0 -242
  112. package/chat/messages/fetchMessages.ts +0 -84
  113. package/chat/messages/types.ts +0 -185
  114. package/cli/agentCreateCustomCommands.ts +0 -278
  115. package/cli/agentDialogsCommands.ts +0 -227
  116. package/cli/agentDoctorCommands.ts +0 -203
  117. package/cli/agentRunLocalWorkspace.ts +0 -182
  118. package/cli/agentRunParsing.ts +0 -298
  119. package/cli/agentSuperviseCommands.ts +0 -8
  120. package/cli/agentUnpublishCommands.ts +0 -113
  121. package/cli/buildPublish.ts +0 -138
  122. package/cli/buildPublishArtifactAssembly.ts +0 -724
  123. package/cli/buildPublishImportAnalysis.ts +0 -242
  124. package/cli/cliIoTypes.ts +0 -3
  125. package/cli/cliRuntimeDoctorReport.ts +0 -193
  126. package/cli/client/agentRunInput.ts +0 -10
  127. package/cli/client/agentRunLocalExecution.ts +0 -124
  128. package/cli/client/agentRunLocalExecutor.ts +0 -179
  129. package/cli/client/agentRunRuntimeSelection.ts +0 -145
  130. package/cli/client/agentRunServerTransport.ts +0 -397
  131. package/cli/client/agentRunTaskRunRecorder.ts +0 -176
  132. package/cli/customCodingAgentFlow.ts +0 -208
  133. package/cli/customCodingAgentRecord.ts +0 -179
  134. package/cli/dialogDataAccess.ts +0 -186
  135. package/cli/dialogInternalCommandEntries.ts +0 -11
  136. package/cli/dialogReadCommands.ts +0 -180
  137. package/cli/dialogReadHelpers.ts +0 -226
  138. package/cli/dialogStatusCommands.ts +0 -123
  139. package/cli/docInternalCommandEntries.ts +0 -20
  140. package/cli/hybridReadHelpers.ts +0 -109
  141. package/cli/machineCommandPrompts.ts +0 -79
  142. package/cli/machineCommandResolution.ts +0 -43
  143. package/cli/noloReadBridgePrompt.ts +0 -16
  144. package/cli/pageCreateCommands.ts +0 -219
  145. package/cli/pageDeleteCommands.ts +0 -167
  146. package/cli/pageReadCommands.ts +0 -151
  147. package/cli/pageUpdateCommands.ts +0 -249
  148. package/cli/pageWriteHelpers.ts +0 -209
  149. package/cli/publishPackage.ts +0 -36
  150. package/cli/runtimeInternalCommandEntries.ts +0 -15
  151. package/cli/runtimePassthroughCommands.ts +0 -22
  152. package/cli/scriptPassthroughHelpers.ts +0 -28
  153. package/cli/secretScanHelpers.ts +0 -31
  154. package/cli/spaceAttachCommands.ts +0 -134
  155. package/cli/spaceCategoryCommands.ts +0 -263
  156. package/cli/spaceCommands.ts +0 -295
  157. package/cli/spaceDeleteCommands.ts +0 -312
  158. package/cli/spaceInternalCommandEntries.ts +0 -21
  159. package/cli/spaceMutationHelpers.ts +0 -135
  160. package/cli/spaceReadCommands.ts +0 -323
  161. package/cli/tableDataOutput.ts +0 -41
  162. package/cli/tableDataSafety.ts +0 -26
  163. package/cli/tableMetaCommands.ts +0 -307
  164. package/cli/tableMutationCommands.ts +0 -266
  165. package/cli/tableQueryParsing.ts +0 -90
  166. package/cli/tableQueryRequest.ts +0 -53
  167. package/cli/taskRunActions.ts +0 -122
  168. package/cli/taskRunParsing.ts +0 -86
  169. package/cli/taskRunPromptShared.ts +0 -55
  170. package/cli/tui/tuiCatalog.ts +0 -22
  171. package/cli/tui/tuiCommandInterpreter.ts +0 -253
  172. package/cli/tui/tuiPresentation.ts +0 -146
  173. package/cliIoTypes.ts +0 -3
  174. package/cliRuntimeDoctorReport.ts +0 -193
  175. package/client/agentRunInput.ts +0 -10
  176. package/client/agentRunLocalExecution.test.ts +0 -123
  177. package/client/agentRunLocalExecution.ts +0 -124
  178. package/client/agentRunLocalExecutor.ts +0 -179
  179. package/client/agentRunRuntimeSelection.test.ts +0 -159
  180. package/client/agentRunRuntimeSelection.ts +0 -145
  181. package/client/agentRunServerTransport.ts +0 -397
  182. package/client/agentRunTaskRunRecorder.ts +0 -176
  183. package/connector-experimental/daemonLauncher.ts +0 -223
  184. package/create/space/spaceKeys.ts +0 -65
  185. package/create/types.ts +0 -21
  186. package/customCodingAgentFlow.ts +0 -208
  187. package/customCodingAgentRecord.ts +0 -179
  188. package/database/keys.ts +0 -765
  189. package/database/tombstones.ts +0 -52
  190. package/database/utils/ulid.ts +0 -1
  191. package/dialogDataAccess.ts +0 -186
  192. package/dialogInternalCommandEntries.ts +0 -11
  193. package/dialogReadCommands.ts +0 -180
  194. package/dialogReadHelpers.ts +0 -226
  195. package/dialogStatusCommands.ts +0 -123
  196. package/docInternalCommandEntries.ts +0 -20
  197. package/hybridReadHelpers.ts +0 -109
  198. package/machineCommandPrompts.ts +0 -79
  199. package/machineCommandResolution.ts +0 -43
  200. package/noloReadBridgePrompt.ts +0 -16
  201. package/pageCreateCommands.ts +0 -219
  202. package/pageDeleteCommands.ts +0 -167
  203. package/pageReadCommands.ts +0 -151
  204. package/pageUpdateCommands.ts +0 -249
  205. package/pageWriteHelpers.ts +0 -209
  206. package/publishPackage.ts +0 -36
  207. package/runtimeInternalCommandEntries.ts +0 -15
  208. package/runtimePassthroughCommands.ts +0 -22
  209. package/scriptPassthroughHelpers.ts +0 -28
  210. package/secretScanHelpers.ts +0 -31
  211. package/share/helpers.ts +0 -302
  212. package/share/keys.ts +0 -243
  213. package/share/types.ts +0 -100
  214. package/spaceAttachCommands.ts +0 -134
  215. package/spaceCategoryCommands.ts +0 -263
  216. package/spaceCommands.ts +0 -295
  217. package/spaceDeleteCommands.ts +0 -312
  218. package/spaceInternalCommandEntries.ts +0 -21
  219. package/spaceMutationHelpers.ts +0 -135
  220. package/spaceReadCommands.ts +0 -323
  221. package/tableDataOutput.ts +0 -41
  222. package/tableDataSafety.ts +0 -26
  223. package/tableMetaCommands.ts +0 -307
  224. package/tableMutationCommands.ts +0 -266
  225. package/tableQueryParsing.ts +0 -90
  226. package/tableQueryRequest.ts +0 -53
  227. package/taskRunActions.ts +0 -122
  228. package/taskRunParsing.ts +0 -86
  229. package/taskRunPromptShared.ts +0 -55
  230. package/tui/tuiCatalog.ts +0 -22
  231. package/tui/tuiCommandInterpreter.test.ts +0 -169
  232. package/tui/tuiCommandInterpreter.ts +0 -253
  233. package/tui/tuiPresentation.test.ts +0 -154
  234. 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
- }