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,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
- }