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,134 +0,0 @@
1
- import { ContentType } from "./app/types";
2
- import { getReadableCliDb, type AgentCommandDeps } from "./agentCommandSupport";
3
- import { resolveAgentRecordFromHybridStore } from "./agentRecordHelpers";
4
- import {
5
- parseUserIdFromAuthToken,
6
- readOption,
7
- resolveAuthToken,
8
- resolveServerCandidates,
9
- resolveServerUrl,
10
- } from "./cliEnvHelpers";
11
- import {
12
- parseSpaceIdFromInput,
13
- readSpaceRecordWithFallback,
14
- writeSpaceRecord,
15
- } from "./spaceMutationHelpers";
16
-
17
- function usage() {
18
- return [
19
- "Usage:",
20
- " nolo space attach-agent --space <spaceId|spaceKey|spaceUrl> --agent <agentKey|alias|agentUrl>",
21
- "",
22
- ].join("\n");
23
- }
24
-
25
- export async function runSpaceAttachAgentCommand(
26
- args: string[],
27
- deps: AgentCommandDeps = {}
28
- ) {
29
- const env = deps.env ?? process.env;
30
- const output = deps.output ?? process.stdout;
31
-
32
- if (args.includes("--help") || args.includes("-h")) {
33
- output.write(`${usage()}\n`);
34
- return 0;
35
- }
36
-
37
- const rawSpace = readOption(args, "--space");
38
- const rawAgent = readOption(args, "--agent");
39
- if (!rawSpace || !rawAgent) {
40
- output.write(`${usage()}\n`);
41
- return 1;
42
- }
43
-
44
- const authToken = resolveAuthToken(args, env);
45
- const userId = parseUserIdFromAuthToken(authToken);
46
- if (!authToken || !userId) {
47
- output.write("[nolo] space attach-agent requires an auth token with userId. Run `nolo login`.\n");
48
- return 1;
49
- }
50
-
51
- const db = deps.db ?? await getReadableCliDb(output);
52
- const fetchImpl = deps.fetchImpl ?? fetch;
53
- const fallbackFetchImpl = deps.fallbackFetchImpl;
54
- const defaultServerUrl = resolveServerUrl(args, env);
55
- const serverCandidates = resolveServerCandidates(args, env, defaultServerUrl);
56
-
57
- try {
58
- const spaceId = parseSpaceIdFromInput(rawSpace);
59
- const spaceRecord = await readSpaceRecordWithFallback({
60
- authToken,
61
- db,
62
- fallbackFetchImpl,
63
- fetchImpl,
64
- serverCandidates,
65
- spaceId,
66
- });
67
- const resolvedAgent = await resolveAgentRecordFromHybridStore({
68
- agentInput: rawAgent,
69
- cliArgs: args,
70
- env,
71
- db,
72
- fetchImpl,
73
- fallbackFetchImpl,
74
- });
75
- if (!resolvedAgent?.record || typeof resolvedAgent.record !== "object") {
76
- throw new Error(`agent not found: ${rawAgent}`);
77
- }
78
- const agentKey = resolvedAgent.agentKey;
79
-
80
- const title =
81
- typeof resolvedAgent.record.name === "string" && resolvedAgent.record.name.trim()
82
- ? resolvedAgent.record.name.trim()
83
- : agentKey;
84
- const now = Date.now();
85
- const nextSpaceRecord = {
86
- ...spaceRecord,
87
- updatedAt: now,
88
- contents: {
89
- ...(spaceRecord?.contents ?? {}),
90
- [agentKey]: {
91
- ...(spaceRecord?.contents?.[agentKey] ?? {}),
92
- title,
93
- type: ContentType.AGENT,
94
- contentKey: agentKey,
95
- updatedAt: now,
96
- createdAt: spaceRecord?.contents?.[agentKey]?.createdAt ?? now,
97
- },
98
- },
99
- };
100
-
101
- await writeSpaceRecord({
102
- authToken,
103
- db,
104
- fallbackFetchImpl,
105
- fetchImpl,
106
- record: nextSpaceRecord,
107
- serverUrl: defaultServerUrl,
108
- spaceId,
109
- userId,
110
- });
111
-
112
- output.write(
113
- `${JSON.stringify(
114
- {
115
- ok: true,
116
- baseUrl: defaultServerUrl,
117
- spaceId,
118
- agentKey,
119
- title,
120
- },
121
- null,
122
- 2
123
- )}\n`
124
- );
125
- return 0;
126
- } catch (error) {
127
- output.write(
128
- `[nolo] space attach-agent failed: ${
129
- error instanceof Error ? error.message : String(error)
130
- }\n`
131
- );
132
- return 1;
133
- }
134
- }
@@ -1,263 +0,0 @@
1
- import { ulid } from "ulid";
2
- import { getReadableCliDb, type AgentCommandDeps } from "./agentCommandSupport";
3
- import {
4
- parseUserIdFromAuthToken,
5
- readOption,
6
- resolveAuthToken,
7
- resolveServerCandidates,
8
- resolveServerUrl,
9
- } from "./cliEnvHelpers";
10
- import {
11
- parseContentKeys,
12
- parseSpaceIdFromInput,
13
- readSpaceRecordWithFallback,
14
- writeSpaceRecord,
15
- } from "./spaceMutationHelpers";
16
-
17
- function categoryUsage() {
18
- return [
19
- "Usage:",
20
- " nolo space category --space <spaceId|spaceKey|spaceUrl> --name <name> [--category-id <id>] [--order <n>]",
21
- "",
22
- ].join("\n");
23
- }
24
-
25
- function contentCategoryUsage() {
26
- return [
27
- "Usage:",
28
- " nolo space content-category --space <spaceId|spaceKey|spaceUrl> --category-id <id> (--content-key <dbKey> | --content-keys '[\"dbKey1\"]')",
29
- "",
30
- ].join("\n");
31
- }
32
-
33
- export async function runSpaceCategoryCommand(
34
- args: string[],
35
- deps: AgentCommandDeps = {}
36
- ) {
37
- const env = deps.env ?? process.env;
38
- const output = deps.output ?? process.stdout;
39
-
40
- if (args.includes("--help") || args.includes("-h")) {
41
- output.write(`${categoryUsage()}\n`);
42
- return 0;
43
- }
44
-
45
- const rawSpace = readOption(args, "--space");
46
- const rawName = readOption(args, "--name")?.trim();
47
- if (!rawSpace || !rawName) {
48
- output.write(`${categoryUsage()}\n`);
49
- return 1;
50
- }
51
-
52
- const authToken = resolveAuthToken(args, env);
53
- const userId = parseUserIdFromAuthToken(authToken);
54
- if (!authToken || !userId) {
55
- output.write("[nolo] space category requires an auth token with userId. Run `nolo login`.\n");
56
- return 1;
57
- }
58
-
59
- const rawOrder = readOption(args, "--order");
60
- const parsedOrder = rawOrder == null ? undefined : Number.parseInt(rawOrder, 10);
61
- if (rawOrder != null && !Number.isFinite(parsedOrder)) {
62
- output.write("[nolo] --order must be an integer.\n");
63
- return 1;
64
- }
65
-
66
- const db = deps.db ?? await getReadableCliDb(output);
67
- const fetchImpl = deps.fetchImpl ?? fetch;
68
- const fallbackFetchImpl = deps.fallbackFetchImpl;
69
- const defaultServerUrl = resolveServerUrl(args, env);
70
- const serverCandidates = resolveServerCandidates(args, env, defaultServerUrl);
71
-
72
- try {
73
- const spaceId = parseSpaceIdFromInput(rawSpace);
74
- const categoryId = (readOption(args, "--category-id") ?? ulid()).trim();
75
- if (!categoryId) {
76
- throw new Error("categoryId cannot be empty.");
77
- }
78
-
79
- const spaceRecord = await readSpaceRecordWithFallback({
80
- authToken,
81
- db,
82
- fallbackFetchImpl,
83
- fetchImpl,
84
- serverCandidates,
85
- spaceId,
86
- });
87
- const existingCategory = spaceRecord?.categories?.[categoryId];
88
- const existingCategories = Object.values(spaceRecord?.categories ?? {}).filter(
89
- (value) => value && typeof value === "object"
90
- );
91
- const nowIso = new Date().toISOString();
92
- const nextCategory = {
93
- ...(existingCategory && typeof existingCategory === "object" ? existingCategory : {}),
94
- name: rawName,
95
- order:
96
- parsedOrder ??
97
- (typeof existingCategory?.order === "number"
98
- ? existingCategory.order
99
- : existingCategories.length),
100
- updatedAt: nowIso,
101
- };
102
- const nextSpaceRecord = {
103
- ...spaceRecord,
104
- updatedAt: nowIso,
105
- categories: {
106
- ...(spaceRecord?.categories ?? {}),
107
- [categoryId]: nextCategory,
108
- },
109
- };
110
-
111
- await writeSpaceRecord({
112
- authToken,
113
- db,
114
- fallbackFetchImpl,
115
- fetchImpl,
116
- record: nextSpaceRecord,
117
- serverUrl: defaultServerUrl,
118
- spaceId,
119
- userId,
120
- });
121
-
122
- output.write(
123
- `${JSON.stringify(
124
- {
125
- ok: true,
126
- action: existingCategory ? "updated" : "created",
127
- baseUrl: defaultServerUrl,
128
- spaceId,
129
- categoryId,
130
- category: nextCategory,
131
- },
132
- null,
133
- 2
134
- )}\n`
135
- );
136
- return 0;
137
- } catch (error) {
138
- output.write(
139
- `[nolo] space category failed: ${
140
- error instanceof Error ? error.message : String(error)
141
- }\n`
142
- );
143
- return 1;
144
- }
145
- }
146
-
147
- export async function runSpaceContentCategoryCommand(
148
- args: string[],
149
- deps: AgentCommandDeps = {}
150
- ) {
151
- const env = deps.env ?? process.env;
152
- const output = deps.output ?? process.stdout;
153
-
154
- if (args.includes("--help") || args.includes("-h")) {
155
- output.write(`${contentCategoryUsage()}\n`);
156
- return 0;
157
- }
158
-
159
- const rawSpace = readOption(args, "--space");
160
- const categoryId = readOption(args, "--category-id")?.trim();
161
- if (!rawSpace || !categoryId) {
162
- output.write(`${contentCategoryUsage()}\n`);
163
- return 1;
164
- }
165
-
166
- const authToken = resolveAuthToken(args, env);
167
- const userId = parseUserIdFromAuthToken(authToken);
168
- if (!authToken || !userId) {
169
- output.write("[nolo] space content-category requires an auth token with userId. Run `nolo login`.\n");
170
- return 1;
171
- }
172
-
173
- let contentKeys: string[];
174
- try {
175
- contentKeys = parseContentKeys(args);
176
- } catch (error) {
177
- output.write(
178
- `[nolo] space content-category failed: ${
179
- error instanceof Error ? error.message : String(error)
180
- }\n`
181
- );
182
- return 1;
183
- }
184
- if (contentKeys.length === 0) {
185
- output.write("[nolo] space content-category requires at least one content key.\n");
186
- return 1;
187
- }
188
-
189
- const db = deps.db ?? await getReadableCliDb(output);
190
- const fetchImpl = deps.fetchImpl ?? fetch;
191
- const fallbackFetchImpl = deps.fallbackFetchImpl;
192
- const defaultServerUrl = resolveServerUrl(args, env);
193
- const serverCandidates = resolveServerCandidates(args, env, defaultServerUrl);
194
-
195
- try {
196
- const spaceId = parseSpaceIdFromInput(rawSpace);
197
- const spaceRecord = await readSpaceRecordWithFallback({
198
- authToken,
199
- db,
200
- fallbackFetchImpl,
201
- fetchImpl,
202
- serverCandidates,
203
- spaceId,
204
- });
205
-
206
- if (!spaceRecord?.categories?.[categoryId]) {
207
- throw new Error(`target category not found: ${categoryId}`);
208
- }
209
-
210
- const contents = { ...(spaceRecord?.contents ?? {}) } as Record<string, any>;
211
- const now = Date.now();
212
- for (const contentKey of contentKeys) {
213
- const currentContent = contents[contentKey];
214
- if (!currentContent || typeof currentContent !== "object") {
215
- throw new Error(`content not found in space: ${contentKey}`);
216
- }
217
- contents[contentKey] = {
218
- ...currentContent,
219
- categoryId,
220
- updatedAt: now,
221
- };
222
- }
223
-
224
- const nextSpaceRecord = {
225
- ...spaceRecord,
226
- contents,
227
- updatedAt: now,
228
- };
229
-
230
- await writeSpaceRecord({
231
- authToken,
232
- db,
233
- fallbackFetchImpl,
234
- fetchImpl,
235
- record: nextSpaceRecord,
236
- serverUrl: defaultServerUrl,
237
- spaceId,
238
- userId,
239
- });
240
-
241
- output.write(
242
- `${JSON.stringify(
243
- {
244
- ok: true,
245
- baseUrl: defaultServerUrl,
246
- spaceId,
247
- categoryId,
248
- contentKeys,
249
- },
250
- null,
251
- 2
252
- )}\n`
253
- );
254
- return 0;
255
- } catch (error) {
256
- output.write(
257
- `[nolo] space content-category failed: ${
258
- error instanceof Error ? error.message : String(error)
259
- }\n`
260
- );
261
- return 1;
262
- }
263
- }
package/spaceCommands.ts DELETED
@@ -1,295 +0,0 @@
1
- import { createSpaceKey, normalizeSpaceId } from "./create/space/spaceKeys";
2
- import type { CliKvDb } from "./client/hybridRecordStore";
3
- import { getReadableCliDb, type AgentCommandDeps } from "./agentCommandSupport";
4
- import {
5
- parseUserIdFromAuthToken,
6
- readOption,
7
- resolveAuthToken,
8
- resolveServerCandidates,
9
- resolveServerUrl,
10
- } from "./cliEnvHelpers";
11
- import { readDbRecord } from "./agentRecordHelpers";
12
- import { readFromServerCandidates, readThroughList } from "./hybridReadHelpers";
13
-
14
- type SpaceMembership = Record<string, any> & {
15
- spaceId?: string;
16
- name?: string;
17
- spaceName?: string;
18
- title?: string;
19
- role?: string;
20
- };
21
-
22
- type ListedSpace = {
23
- spaceId: string;
24
- spaceKey: string;
25
- name: string;
26
- role: string | null;
27
- ownerId: string | null;
28
- visibility: string | null;
29
- contentCount: number;
30
- updatedAt: string | number | null;
31
- membershipKey: string;
32
- };
33
-
34
- function displayName(value: Record<string, any>) {
35
- return String(value.spaceName ?? value.name ?? value.title ?? value.spaceTitle ?? "").trim();
36
- }
37
-
38
- function parseSpaceListArgs(args: string[]) {
39
- return {
40
- wantJson: args.includes("--json"),
41
- idsOnly: args.includes("--ids-only"),
42
- exactName: readOption(args, "--name"),
43
- nameContains: readOption(args, "--name-contains"),
44
- };
45
- }
46
-
47
- function sortListedSpaces(spaces: ListedSpace[]) {
48
- return spaces.sort((a, b) => {
49
- const ta = a.updatedAt == null ? 0 : new Date(a.updatedAt).getTime();
50
- const tb = b.updatedAt == null ? 0 : new Date(b.updatedAt).getTime();
51
- if (tb !== ta) return tb - ta;
52
- return a.name.localeCompare(b.name, "zh-Hans");
53
- });
54
- }
55
-
56
- function applyFilters(
57
- spaces: ListedSpace[],
58
- filters: ReturnType<typeof parseSpaceListArgs>
59
- ) {
60
- return spaces.filter((space) => {
61
- if (filters.exactName && space.name !== filters.exactName) return false;
62
- if (filters.nameContains && !space.name.includes(filters.nameContains)) return false;
63
- return true;
64
- });
65
- }
66
-
67
- async function listLocalMemberships(args: {
68
- db: CliKvDb;
69
- userId: string;
70
- }) {
71
- const range = createSpaceKey.memberRange(args.userId);
72
- const memberships: SpaceMembership[] = [];
73
- for await (const [key, value] of args.db.iterator({ gte: range.start, lte: range.end })) {
74
- if (!value || typeof value !== "object") continue;
75
- memberships.push({
76
- ...(value as SpaceMembership),
77
- dbKey: typeof (value as any).dbKey === "string" ? (value as any).dbKey : String(key),
78
- });
79
- }
80
- return memberships;
81
- }
82
-
83
- async function readLocalSpaceRecord(args: {
84
- db: CliKvDb;
85
- spaceId: string;
86
- }) {
87
- return await args.db.get(createSpaceKey.space(args.spaceId));
88
- }
89
-
90
- async function fetchRemoteMemberships(args: {
91
- authToken: string;
92
- fetchImpl: typeof fetch;
93
- serverCandidates: string[];
94
- userId: string;
95
- }) {
96
- return await readFromServerCandidates({
97
- serverCandidates: args.serverCandidates,
98
- readRemote: async (serverUrl) => {
99
- const response = await args.fetchImpl(`${serverUrl}/rpc/getUserSpaceMemberships`, {
100
- method: "POST",
101
- headers: {
102
- Authorization: `Bearer ${args.authToken}`,
103
- "Content-Type": "application/json",
104
- },
105
- body: JSON.stringify({ userId: args.userId }),
106
- });
107
- const data = await response.json().catch(() => ({}));
108
- if (!response.ok || !Array.isArray(data)) {
109
- throw new Error(
110
- `Failed to list memberships (${response.status}): ${JSON.stringify(data)}`
111
- );
112
- }
113
- return {
114
- memberships: data as SpaceMembership[],
115
- serverUrl,
116
- };
117
- },
118
- }).then((result) => result.value);
119
- }
120
-
121
- async function readRemoteSpaceRecord(args: {
122
- authToken: string;
123
- fallbackFetchImpl?: typeof fetch;
124
- fetchImpl: typeof fetch;
125
- serverUrl: string;
126
- spaceId: string;
127
- }) {
128
- return await readDbRecord({
129
- authToken: args.authToken,
130
- dbKey: createSpaceKey.space(args.spaceId),
131
- fallbackFetchImpl: args.fallbackFetchImpl,
132
- fetchImpl: args.fetchImpl,
133
- serverUrl: args.serverUrl,
134
- });
135
- }
136
-
137
- async function buildListedSpace(
138
- membership: SpaceMembership,
139
- readSpaceRecord: (spaceId: string) => Promise<Record<string, any>>
140
- ): Promise<ListedSpace | null> {
141
- const spaceId = normalizeSpaceId(String(membership.spaceId ?? ""));
142
- if (!spaceId) return null;
143
-
144
- let spaceRecord: Record<string, any> = {};
145
- try {
146
- const value = await readSpaceRecord(spaceId);
147
- if (value && typeof value === "object") {
148
- spaceRecord = value;
149
- }
150
- } catch {
151
- spaceRecord = {};
152
- }
153
-
154
- const contents = spaceRecord.contents;
155
- return {
156
- spaceId,
157
- spaceKey: createSpaceKey.space(spaceId),
158
- name: displayName(spaceRecord) || displayName(membership) || spaceId,
159
- role: typeof membership.role === "string" ? membership.role : null,
160
- ownerId: typeof spaceRecord.ownerId === "string" ? spaceRecord.ownerId : null,
161
- visibility: typeof spaceRecord.visibility === "string" ? spaceRecord.visibility : null,
162
- contentCount: contents && typeof contents === "object" ? Object.keys(contents).length : 0,
163
- updatedAt:
164
- typeof spaceRecord.updatedAt === "string" || typeof spaceRecord.updatedAt === "number"
165
- ? spaceRecord.updatedAt
166
- : typeof membership.updatedAt === "string" || typeof membership.updatedAt === "number"
167
- ? membership.updatedAt
168
- : null,
169
- membershipKey:
170
- typeof membership.dbKey === "string"
171
- ? membership.dbKey
172
- : createSpaceKey.member(String(membership.userId ?? ""), spaceId),
173
- };
174
- }
175
-
176
- export async function runSpaceListCommand(
177
- args: string[],
178
- deps: AgentCommandDeps = {}
179
- ) {
180
- const env = deps.env ?? process.env;
181
- const output = deps.output ?? process.stdout;
182
- const filters = parseSpaceListArgs(args);
183
-
184
- const authToken = resolveAuthToken(args, env);
185
- if (!authToken) {
186
- output.write("[nolo] space list requires an auth token. Run `nolo login` or set AUTH_TOKEN.\n");
187
- return 1;
188
- }
189
-
190
- const userId = parseUserIdFromAuthToken(authToken);
191
- if (!userId) {
192
- output.write("[nolo] space list could not read userId from AUTH_TOKEN.\n");
193
- return 1;
194
- }
195
-
196
- const db = deps.db ?? await getReadableCliDb(output);
197
- const fetchImpl = deps.fetchImpl ?? fetch;
198
- const fallbackFetchImpl = deps.fallbackFetchImpl;
199
- const defaultServerUrl = resolveServerUrl(args, env);
200
- const serverCandidates = resolveServerCandidates(args, env, defaultServerUrl);
201
-
202
- try {
203
- let spaces: ListedSpace[];
204
- let source: "local-cache" | "remote-cache";
205
- let resolvedBaseUrl = defaultServerUrl;
206
- const loadRemoteSpaces = async () => {
207
- const remote = await fetchRemoteMemberships({
208
- authToken,
209
- fetchImpl,
210
- serverCandidates,
211
- userId,
212
- });
213
- resolvedBaseUrl = remote.serverUrl;
214
- const memberships = remote.memberships;
215
- return (
216
- await Promise.all(
217
- memberships.map((membership) =>
218
- buildListedSpace(membership, async (spaceId) => {
219
- const value = await readRemoteSpaceRecord({
220
- authToken,
221
- fallbackFetchImpl,
222
- fetchImpl,
223
- serverUrl: resolvedBaseUrl,
224
- spaceId,
225
- });
226
- return value && typeof value === "object" ? (value as Record<string, any>) : {};
227
- })
228
- )
229
- )
230
- ).filter((space): space is ListedSpace => space != null);
231
- };
232
-
233
- const result = await readThroughList({
234
- readLocal: async () => {
235
- const memberships = await listLocalMemberships({ db, userId });
236
- return (
237
- await Promise.all(
238
- memberships.map((membership) =>
239
- buildListedSpace(membership, async (spaceId) => {
240
- const value = await readLocalSpaceRecord({ db, spaceId });
241
- return value && typeof value === "object" ? (value as Record<string, any>) : {};
242
- })
243
- )
244
- )
245
- ).filter((space): space is ListedSpace => space != null);
246
- },
247
- readRemote: loadRemoteSpaces,
248
- });
249
- spaces = result.items;
250
- source = result.source;
251
-
252
- spaces = applyFilters(sortListedSpaces(spaces), filters);
253
-
254
- if (filters.idsOnly) {
255
- output.write(`${spaces.map((space) => space.spaceId).join("\n")}\n`);
256
- return 0;
257
- }
258
-
259
- if (filters.wantJson) {
260
- output.write(
261
- JSON.stringify(
262
- {
263
- baseUrl: resolvedBaseUrl,
264
- userId,
265
- total: spaces.length,
266
- source,
267
- spaces,
268
- },
269
- null,
270
- 2
271
- )
272
- );
273
- output.write("\n");
274
- return 0;
275
- }
276
-
277
- output.write(`Base: ${resolvedBaseUrl}\n`);
278
- output.write(`User: ${userId}\n`);
279
- output.write(`Spaces: ${spaces.length}\n`);
280
- output.write(`Source: ${source}\n`);
281
- for (const space of spaces) {
282
- output.write(
283
- `- ${space.name} (${space.spaceId}) role=${space.role ?? "-"} contents=${space.contentCount}\n`
284
- );
285
- }
286
- return 0;
287
- } catch (error) {
288
- output.write(
289
- `[nolo] space list failed: ${
290
- error instanceof Error ? error.message : String(error)
291
- }\n`
292
- );
293
- return 1;
294
- }
295
- }