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,323 +0,0 @@
1
- import { ContentType } from "./app/types";
2
- import { parseSkillDocProtocol, resolvePageSkillMetadata } from "./ai/skills/skillDocProtocol";
3
- import { createSpaceKey } from "./create/space/spaceKeys";
4
- import { getReadableCliDb, type AgentCommandDeps } from "./agentCommandSupport";
5
- import { readDbRecord } from "./agentRecordHelpers";
6
- import {
7
- parseUserIdFromAuthToken,
8
- readOption,
9
- resolveAuthToken,
10
- resolveServerCandidates,
11
- resolveServerUrl,
12
- } from "./cliEnvHelpers";
13
- import { readRecordWithCandidates } from "./hybridReadHelpers";
14
- import { parseSpaceIdFromInput } from "./spaceMutationHelpers";
15
-
16
- function readPositionalInput(args: string[]) {
17
- for (let index = 0; index < args.length; index += 1) {
18
- const value = args[index];
19
- if (value === "--content-key") {
20
- index += 1;
21
- continue;
22
- }
23
- if (!value.startsWith("-")) return value;
24
- }
25
- return undefined;
26
- }
27
-
28
- function parseSpaceReadArgs(args: string[]) {
29
- const raw = readPositionalInput(args);
30
- if (!raw) throw new Error("Usage: nolo space read <spaceId|spaceKey|spaceUrl> [--brief] [--content-key <key>] [--include-record]");
31
- const brief = args.includes("--brief");
32
- const contentKeyFilter = readOption(args, "--content-key");
33
- const includeRecord = args.includes("--include-record") || (!brief && !contentKeyFilter);
34
- return {
35
- raw,
36
- brief,
37
- contentKeyFilter,
38
- includeRecord,
39
- };
40
- }
41
-
42
- function buildContentEntries(space: Record<string, any>) {
43
- return Object.entries(space.contents ?? {})
44
- .filter(([, value]) => value && typeof value === "object")
45
- .map(([entryKey, value]) => ({
46
- entryKey,
47
- ...(value as Record<string, any>),
48
- }))
49
- .sort((a, b) => {
50
- const pinnedDiff = Number(Boolean(b.pinned)) - Number(Boolean(a.pinned));
51
- if (pinnedDiff !== 0) return pinnedDiff;
52
- const orderA = typeof a.order === "number" ? a.order : Number.MAX_SAFE_INTEGER;
53
- const orderB = typeof b.order === "number" ? b.order : Number.MAX_SAFE_INTEGER;
54
- if (orderA !== orderB) return orderA - orderB;
55
- return (b.updatedAt ?? 0) - (a.updatedAt ?? 0);
56
- });
57
- }
58
-
59
- function buildCategories(space: Record<string, any>) {
60
- return Object.entries(space.categories ?? {})
61
- .filter(([, value]) => value && typeof value === "object")
62
- .map(([categoryId, value]) => ({
63
- categoryId,
64
- ...(value as Record<string, any>),
65
- }))
66
- .sort((a, b) => {
67
- const orderA = typeof a.order === "number" ? a.order : Number.MAX_SAFE_INTEGER;
68
- const orderB = typeof b.order === "number" ? b.order : Number.MAX_SAFE_INTEGER;
69
- if (orderA !== orderB) return orderA - orderB;
70
- return String(a.name ?? "").localeCompare(String(b.name ?? ""), "zh-Hans");
71
- });
72
- }
73
-
74
- export async function runSpaceReadCommand(
75
- args: string[],
76
- deps: AgentCommandDeps = {}
77
- ) {
78
- const env = deps.env ?? process.env;
79
- const output = deps.output ?? process.stdout;
80
- const { raw, brief, contentKeyFilter, includeRecord } = parseSpaceReadArgs(args);
81
-
82
- const authToken = resolveAuthToken(args, env);
83
- if (!authToken) {
84
- output.write("[nolo] space read requires an auth token. Run `nolo login` or set AUTH_TOKEN.\n");
85
- return 1;
86
- }
87
-
88
- const userId = parseUserIdFromAuthToken(authToken);
89
- if (!userId) {
90
- output.write("[nolo] space read could not read userId from AUTH_TOKEN.\n");
91
- return 1;
92
- }
93
-
94
- const db = deps.db ?? await getReadableCliDb(output);
95
- const fetchImpl = deps.fetchImpl ?? fetch;
96
- const fallbackFetchImpl = deps.fallbackFetchImpl;
97
- const defaultServerUrl = resolveServerUrl(args, env);
98
- const serverCandidates = resolveServerCandidates(args, env, defaultServerUrl);
99
-
100
- try {
101
- const spaceId = parseSpaceIdFromInput(raw);
102
- const spaceKey = createSpaceKey.space(spaceId);
103
- const space = await readRecordWithCandidates<Record<string, any>>({
104
- db,
105
- dbKey: spaceKey,
106
- serverCandidates,
107
- readRemote: async (serverUrl, dbKey) =>
108
- readDbRecord({
109
- authToken,
110
- dbKey,
111
- fallbackFetchImpl,
112
- fetchImpl,
113
- serverUrl,
114
- }),
115
- });
116
-
117
- const categories = buildCategories(space);
118
- const allContents = buildContentEntries(space);
119
- const contents = contentKeyFilter
120
- ? allContents.filter((item) => {
121
- const contentKey =
122
- typeof item.contentKey === "string" && item.contentKey.trim()
123
- ? item.contentKey.trim()
124
- : item.entryKey;
125
- return item.entryKey === contentKeyFilter || contentKey === contentKeyFilter;
126
- })
127
- : allContents;
128
-
129
- const contentCounts = allContents.reduce<Record<string, number>>((acc, item) => {
130
- const type = typeof item.type === "string" ? item.type : "unknown";
131
- acc[type] = (acc[type] ?? 0) + 1;
132
- return acc;
133
- }, {});
134
-
135
- const categoryContentMap = allContents.reduce<Record<string, string[]>>((acc, item) => {
136
- const categoryId =
137
- typeof item.categoryId === "string" && item.categoryId.trim()
138
- ? item.categoryId.trim()
139
- : "";
140
- if (!categoryId) return acc;
141
- if (!acc[categoryId]) acc[categoryId] = [];
142
- acc[categoryId].push(
143
- typeof item.contentKey === "string" && item.contentKey.trim()
144
- ? item.contentKey.trim()
145
- : item.entryKey
146
- );
147
- return acc;
148
- }, {});
149
-
150
- const categoriesWithStats = categories.map((category) => ({
151
- ...category,
152
- itemCount: categoryContentMap[category.categoryId]?.length ?? 0,
153
- contentKeys: categoryContentMap[category.categoryId] ?? [],
154
- }));
155
-
156
- const uncategorizedContentKeys = contents
157
- .filter((item) => !(typeof item.categoryId === "string" && item.categoryId.trim()))
158
- .map((item) =>
159
- typeof item.contentKey === "string" && item.contentKey.trim()
160
- ? item.contentKey.trim()
161
- : item.entryKey
162
- );
163
-
164
- const resolvedAgents = await Promise.all(
165
- contents
166
- .filter((item) => item.type === ContentType.AGENT && !brief)
167
- .map(async (item) => {
168
- const contentKey =
169
- typeof item.contentKey === "string" && item.contentKey.trim()
170
- ? item.contentKey.trim()
171
- : item.entryKey;
172
- try {
173
- const record = await readRecordWithCandidates<Record<string, any>>({
174
- db,
175
- dbKey: contentKey,
176
- serverCandidates,
177
- readRemote: async (serverUrl, dbKey) =>
178
- readDbRecord({
179
- authToken,
180
- dbKey,
181
- fallbackFetchImpl,
182
- fetchImpl,
183
- serverUrl,
184
- }),
185
- });
186
- return {
187
- contentKey,
188
- slotTitle: item.title,
189
- categoryId: item.categoryId ?? null,
190
- pinned: !!item.pinned,
191
- updatedAt: item.updatedAt ?? null,
192
- agentId: record?.id ?? null,
193
- name: record?.name ?? null,
194
- model: record?.model ?? null,
195
- provider: record?.provider ?? record?.apiSource ?? null,
196
- isPublic: typeof record?.isPublic === "boolean" ? record.isPublic : null,
197
- userId: record?.userId ?? null,
198
- tools: Array.isArray(record?.tools) ? record.tools : [],
199
- customProviderUrl: record?.customProviderUrl ?? null,
200
- };
201
- } catch (error) {
202
- return {
203
- contentKey,
204
- slotTitle: item.title,
205
- categoryId: item.categoryId ?? null,
206
- pinned: !!item.pinned,
207
- updatedAt: item.updatedAt ?? null,
208
- readError: error instanceof Error ? error.message : String(error),
209
- };
210
- }
211
- })
212
- );
213
-
214
- const resolvedSkillDocs = (
215
- await Promise.all(
216
- contents
217
- .filter((item) => item.type === ContentType.DOC && !brief)
218
- .map(async (item) => {
219
- const contentKey =
220
- typeof item.contentKey === "string" && item.contentKey.trim()
221
- ? item.contentKey.trim()
222
- : item.entryKey;
223
- try {
224
- const record = await readRecordWithCandidates<Record<string, any>>({
225
- db,
226
- dbKey: contentKey,
227
- serverCandidates,
228
- readRemote: async (serverUrl, dbKey) =>
229
- readDbRecord({
230
- authToken,
231
- dbKey,
232
- fallbackFetchImpl,
233
- fetchImpl,
234
- serverUrl,
235
- }),
236
- });
237
- const parsed = parseSkillDocProtocol(
238
- typeof record?.content === "string" ? record.content : "",
239
- record?.meta,
240
- record?.tools
241
- );
242
- const meta = resolvePageSkillMetadata(record);
243
- const skillConfig = meta?.skillConfig;
244
- if (!(meta?.kind === "skill" || skillConfig)) {
245
- return null;
246
- }
247
- return {
248
- contentKey,
249
- slotTitle: item.title,
250
- title: record?.title ?? item.title ?? null,
251
- categoryId: item.categoryId ?? null,
252
- pinned: !!item.pinned,
253
- updatedAt: item.updatedAt ?? null,
254
- skillId: skillConfig?.id ?? record?.id ?? null,
255
- name: skillConfig?.name ?? null,
256
- description: skillConfig?.description ?? null,
257
- toolNames: skillConfig?.toolNames ?? [],
258
- requiredSkills: skillConfig?.requiredSkills ?? [],
259
- recommendedSkills: skillConfig?.recommendedSkills ?? [],
260
- triggerMode: skillConfig?.triggerMode ?? null,
261
- promptPatch: skillConfig?.promptPatch ?? null,
262
- bodyPreview:
263
- typeof parsed.content === "string" ? parsed.content.slice(0, 240) : "",
264
- };
265
- } catch (error) {
266
- return {
267
- contentKey,
268
- slotTitle: item.title,
269
- categoryId: item.categoryId ?? null,
270
- pinned: !!item.pinned,
271
- updatedAt: item.updatedAt ?? null,
272
- readError: error instanceof Error ? error.message : String(error),
273
- };
274
- }
275
- })
276
- )
277
- ).filter(Boolean);
278
-
279
- const result: Record<string, any> = {
280
- baseUrl: defaultServerUrl,
281
- spaceId,
282
- spaceKey,
283
- name: space?.name ?? null,
284
- description: space?.description ?? null,
285
- ownerId: space?.ownerId ?? null,
286
- visibility: space?.visibility ?? null,
287
- memberCount: Array.isArray(space?.members) ? space.members.length : 0,
288
- members: Array.isArray(space?.members) ? space.members : [],
289
- categoryCount: categories.length,
290
- categories: brief
291
- ? categoriesWithStats.map(({ contentKeys, ...category }) => category)
292
- : categoriesWithStats,
293
- uncategorizedCount: uncategorizedContentKeys.length,
294
- ...(brief ? {} : { uncategorizedContentKeys }),
295
- contentCount: allContents.length,
296
- contentCounts,
297
- contents,
298
- agents: resolvedAgents,
299
- pageCount: allContents.filter((item) => item.type === ContentType.DOC).length,
300
- skillDocCount: resolvedSkillDocs.length,
301
- skillDocs: resolvedSkillDocs,
302
- };
303
-
304
- if (contentKeyFilter) {
305
- result.contentKeyFilter = contentKeyFilter;
306
- result.matchedCount = contents.length;
307
- }
308
-
309
- if (includeRecord) {
310
- result.record = space;
311
- }
312
-
313
- output.write(`${JSON.stringify(result, null, 2)}\n`);
314
- return 0;
315
- } catch (error) {
316
- output.write(
317
- `[nolo] space read failed: ${
318
- error instanceof Error ? error.message : String(error)
319
- }\n`
320
- );
321
- return 1;
322
- }
323
- }
@@ -1,41 +0,0 @@
1
- export type TableDataOutputMode = "full" | "raw" | "items" | "jsonl";
2
-
3
- export function parseTableDataOutputMode(raw?: string): TableDataOutputMode {
4
- const value = raw?.trim();
5
- if (!value) return "full";
6
- if (value === "json") return "raw";
7
- if (value === "full" || value === "raw" || value === "items" || value === "jsonl") {
8
- return value;
9
- }
10
- throw new Error(`--output must be one of full, raw, items, json, jsonl; got ${value}`);
11
- }
12
-
13
- function getItems(result: unknown): unknown[] | undefined {
14
- if (!result || typeof result !== "object") return undefined;
15
- const items = (result as any).items;
16
- return Array.isArray(items) ? items : undefined;
17
- }
18
-
19
- export function formatTableDataOutput(input: {
20
- envelope: unknown;
21
- result: unknown;
22
- mode: TableDataOutputMode;
23
- }): string {
24
- if (input.mode === "full") {
25
- return JSON.stringify(input.envelope, null, 2);
26
- }
27
- if (input.mode === "raw") {
28
- return JSON.stringify(input.result, null, 2);
29
- }
30
-
31
- const items = getItems(input.result);
32
- const value = items ?? input.result;
33
- if (input.mode === "items") {
34
- return JSON.stringify(value, null, 2);
35
- }
36
- if (!Array.isArray(value)) {
37
- return JSON.stringify(value);
38
- }
39
- return value.map((item) => JSON.stringify(item)).join("\n");
40
- }
41
-
@@ -1,26 +0,0 @@
1
- export const TABLE_SCHEMA_WRITE_ACTIONS = new Set(["add-column"]);
2
-
3
- export function isTableSchemaWriteAction(action: string): boolean {
4
- return TABLE_SCHEMA_WRITE_ACTIONS.has(action.trim());
5
- }
6
-
7
- export function tableSchemaWriteSafetyMessage(action: string): string {
8
- return [
9
- `Action "${action}" mutates table schema metadata and must be serialized per table.`,
10
- "Rerun with --schema-write-ok only after confirming no other agent/script is changing the same table schema.",
11
- "Server-side schema CAS/locking is not implemented yet; row-level writes do not need this flag.",
12
- ].join(" ");
13
- }
14
-
15
- export function assertTableSchemaWriteAllowed(input: {
16
- action: string;
17
- allowSchemaWrite: boolean;
18
- }): void {
19
- if (!isTableSchemaWriteAction(input.action)) {
20
- return;
21
- }
22
- if (input.allowSchemaWrite) {
23
- return;
24
- }
25
- throw new Error(tableSchemaWriteSafetyMessage(input.action));
26
- }
@@ -1,307 +0,0 @@
1
- import { ulid } from "ulid";
2
- import { getReadableCliDb, type AgentCommandDeps } from "./agentCommandSupport";
3
- import { readDbRecord } from "./agentRecordHelpers";
4
- import { parseUserIdFromAuthToken, readOption, resolveAuthToken, resolveServerUrl } from "./cliEnvHelpers";
5
- import {
6
- buildTableAttachedSpaceRecord,
7
- parseSpaceIdFromInput,
8
- readSpaceRecordWithFallback,
9
- } from "./spaceMutationHelpers";
10
- import { writeRemoteRecordsThenCache } from "./pageWriteHelpers";
11
-
12
- type ColumnType =
13
- | "text"
14
- | "number"
15
- | "boolean"
16
- | "date"
17
- | "datetime"
18
- | "select"
19
- | "multi_select";
20
-
21
- type ColumnInput = {
22
- id?: string;
23
- name: string;
24
- label?: string;
25
- type?: ColumnType;
26
- description?: string;
27
- required?: boolean;
28
- isPrimary?: boolean;
29
- options?: string[];
30
- };
31
-
32
- function usage() {
33
- return [
34
- "Usage:",
35
- " nolo table meta --name <name> [--table <tableId|metaKey>] [--space <spaceId|spaceKey|spaceUrl>] [--category-id <id>] [--description <text>] [--tags <comma-list>] [--columns <json-array>]",
36
- "",
37
- ].join("\n");
38
- }
39
-
40
- function parseTableArg(raw?: string) {
41
- if (!raw?.trim()) return {};
42
- const trimmed = raw.trim();
43
- if (trimmed.startsWith("meta-")) {
44
- const parts = trimmed.split("-");
45
- return {
46
- tableId: parts.slice(2).join("-"),
47
- dbKey: trimmed,
48
- };
49
- }
50
- return { tableId: trimmed };
51
- }
52
-
53
- function parseTags(raw?: string) {
54
- if (!raw) return undefined;
55
- const tags = raw
56
- .split(",")
57
- .map((value) => value.trim())
58
- .filter(Boolean);
59
- return tags.length > 0 ? tags : undefined;
60
- }
61
-
62
- function defaultColumns(): ColumnInput[] {
63
- return [
64
- {
65
- name: "title",
66
- label: "标题",
67
- type: "text",
68
- description: "这一行记录的主题或名称。",
69
- isPrimary: true,
70
- required: true,
71
- },
72
- {
73
- name: "note",
74
- label: "备注",
75
- type: "text",
76
- description: "对该条目的补充说明。",
77
- },
78
- ];
79
- }
80
-
81
- function normalizeColumns(rawColumns?: string, existingColumns?: any[]) {
82
- if (!rawColumns) {
83
- if (Array.isArray(existingColumns) && existingColumns.length > 0) {
84
- return existingColumns;
85
- }
86
- return defaultColumns().map((column) => ({ ...column, id: ulid() }));
87
- }
88
-
89
- let parsed: unknown;
90
- try {
91
- parsed = JSON.parse(rawColumns);
92
- } catch (error) {
93
- throw new Error(
94
- `--columns must be a valid JSON array: ${
95
- error instanceof Error ? error.message : String(error)
96
- }`
97
- );
98
- }
99
-
100
- if (!Array.isArray(parsed)) {
101
- throw new Error("--columns must be a JSON array.");
102
- }
103
-
104
- const seen = new Set<string>();
105
- const normalized = parsed
106
- .map((value) => {
107
- if (!value || typeof value !== "object" || Array.isArray(value)) return null;
108
- const column = value as ColumnInput;
109
- const name = typeof column.name === "string" ? column.name.trim() : "";
110
- if (!name || seen.has(name)) return null;
111
- seen.add(name);
112
-
113
- const nextColumn: Record<string, unknown> = {
114
- id: typeof column.id === "string" && column.id.trim() ? column.id.trim() : ulid(),
115
- name,
116
- };
117
- if (typeof column.label === "string" && column.label.trim()) nextColumn.label = column.label.trim();
118
- if (typeof column.type === "string" && column.type.trim()) nextColumn.type = column.type.trim();
119
- if (typeof column.description === "string" && column.description.trim()) {
120
- nextColumn.description = column.description.trim();
121
- }
122
- if (typeof column.required === "boolean") nextColumn.required = column.required;
123
- if (typeof column.isPrimary === "boolean") nextColumn.isPrimary = column.isPrimary;
124
- if (Array.isArray(column.options)) {
125
- const options = column.options
126
- .map((option) => (typeof option === "string" ? option.trim() : ""))
127
- .filter(Boolean);
128
- if (options.length > 0) nextColumn.options = options;
129
- }
130
- return nextColumn;
131
- })
132
- .filter(Boolean) as Array<Record<string, unknown>>;
133
-
134
- if (normalized.length === 0) {
135
- throw new Error("--columns did not contain any valid columns.");
136
- }
137
- if (!normalized.some((column) => column.isPrimary === true)) {
138
- normalized[0].isPrimary = true;
139
- }
140
- return normalized;
141
- }
142
-
143
- export async function runTableMetaCommand(
144
- args: string[],
145
- deps: AgentCommandDeps = {}
146
- ) {
147
- const env = deps.env ?? process.env;
148
- const output = deps.output ?? process.stdout;
149
-
150
- if (args.includes("--help") || args.includes("-h")) {
151
- output.write(`${usage()}\n`);
152
- return 0;
153
- }
154
-
155
- const rawName = readOption(args, "--name");
156
- if (!rawName?.trim()) {
157
- output.write(`${usage()}\n`);
158
- return 1;
159
- }
160
-
161
- const authToken = resolveAuthToken(args, env);
162
- const userId = parseUserIdFromAuthToken(authToken);
163
- if (!authToken || !userId) {
164
- output.write("[nolo] table meta requires an auth token with userId. Run `nolo login`.\n");
165
- return 1;
166
- }
167
-
168
- const name = rawName.trim();
169
- const description = readOption(args, "--description")?.trim() || undefined;
170
- const tags = parseTags(readOption(args, "--tags"));
171
- const serverUrl = resolveServerUrl(args, env);
172
- const db = deps.db ?? await getReadableCliDb(output);
173
- const fetchImpl = deps.fetchImpl ?? fetch;
174
- const fallbackFetchImpl = deps.fallbackFetchImpl;
175
-
176
- try {
177
- const parsedTable = parseTableArg(readOption(args, "--table"));
178
- const tableId = parsedTable.tableId ?? ulid();
179
- const dbKey = parsedTable.dbKey ?? `meta-${userId}-${tableId}`;
180
-
181
- let existingRecord: Record<string, any> | null = null;
182
- try {
183
- const value = await db.get(dbKey);
184
- existingRecord = value && typeof value === "object" ? (value as Record<string, any>) : null;
185
- } catch {
186
- try {
187
- existingRecord = await readDbRecord({
188
- authToken,
189
- dbKey,
190
- fallbackFetchImpl,
191
- fetchImpl,
192
- serverUrl,
193
- });
194
- } catch (error) {
195
- const message = error instanceof Error ? error.message : String(error);
196
- if (parsedTable.dbKey || parsedTable.tableId) {
197
- if (!message.includes("404")) {
198
- throw error;
199
- }
200
- }
201
- }
202
- }
203
-
204
- const columns = normalizeColumns(readOption(args, "--columns"), existingRecord?.columns);
205
- const nowIso = new Date().toISOString();
206
- const rawSpace = readOption(args, "--space");
207
- const spaceId =
208
- rawSpace != null
209
- ? parseSpaceIdFromInput(rawSpace)
210
- : typeof existingRecord?.spaceId === "string" && existingRecord.spaceId
211
- ? existingRecord.spaceId
212
- : undefined;
213
- const explicitCategoryId = readOption(args, "--category-id")?.trim() || undefined;
214
- const categoryId =
215
- explicitCategoryId ??
216
- (typeof existingRecord?.categoryId === "string" && existingRecord.categoryId
217
- ? existingRecord.categoryId
218
- : undefined);
219
-
220
- let spaceRecord: Record<string, any> | null = null;
221
- if (spaceId) {
222
- spaceRecord = await readSpaceRecordWithFallback({
223
- authToken,
224
- db,
225
- fallbackFetchImpl,
226
- fetchImpl,
227
- serverCandidates: [serverUrl],
228
- spaceId,
229
- });
230
- if (categoryId && !spaceRecord?.categories?.[categoryId]) {
231
- throw new Error(`space ${spaceId} does not contain category ${categoryId}`);
232
- }
233
- }
234
-
235
- const nextRecord = {
236
- ...(existingRecord ?? {}),
237
- dbKey,
238
- tenantId: userId,
239
- tableId,
240
- spaceId: spaceId ?? null,
241
- displayName: name,
242
- ...(description !== undefined ? { description } : {}),
243
- ...(tags !== undefined ? { tags } : existingRecord?.tags ? { tags: existingRecord.tags } : {}),
244
- ...(categoryId ? { categoryId } : {}),
245
- schemaVersion:
246
- typeof existingRecord?.schemaVersion === "number" ? existingRecord.schemaVersion : 1,
247
- columns,
248
- views: Array.isArray(existingRecord?.views) ? existingRecord.views : [],
249
- triggers: Array.isArray(existingRecord?.triggers) ? existingRecord.triggers : [],
250
- aiConfig: existingRecord?.aiConfig,
251
- createdAt: existingRecord?.createdAt ?? nowIso,
252
- updatedAt: nowIso,
253
- type: "table",
254
- };
255
-
256
- const writeRecords = [{ dbKey, record: nextRecord, serverUrl }];
257
-
258
- if (spaceId && spaceRecord) {
259
- const nextSpaceRecord = buildTableAttachedSpaceRecord({
260
- categoryId,
261
- contentKey: dbKey,
262
- existingSpaceRecord: spaceRecord,
263
- spaceId,
264
- title: name,
265
- });
266
- writeRecords.push({
267
- dbKey: `space-${spaceId}`,
268
- record: nextSpaceRecord,
269
- serverUrl,
270
- });
271
- }
272
-
273
- await writeRemoteRecordsThenCache({
274
- authToken,
275
- db,
276
- fallbackFetchImpl,
277
- fetchImpl,
278
- records: writeRecords,
279
- userId,
280
- });
281
-
282
- output.write(
283
- `${JSON.stringify(
284
- {
285
- ok: true,
286
- action: existingRecord ? "updated" : "created",
287
- baseUrl: serverUrl,
288
- dbKey,
289
- tableId,
290
- spaceId: spaceId ?? null,
291
- categoryId: categoryId ?? null,
292
- table: nextRecord,
293
- },
294
- null,
295
- 2
296
- )}\n`
297
- );
298
- return 0;
299
- } catch (error) {
300
- output.write(
301
- `[nolo] table meta failed: ${
302
- error instanceof Error ? error.message : String(error)
303
- }\n`
304
- );
305
- return 1;
306
- }
307
- }