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,249 +0,0 @@
1
- import { parseSkillDocProtocol, resolvePageSkillMetadata, type SkillDocConfig } from "../ai/skills/skillDocProtocol";
2
- import { getReadableCliDb, type AgentCommandDeps } from "./agentCommandSupport";
3
- import { readDbRecord } from "./agentRecordHelpers";
4
- import {
5
- parseUserIdFromAuthToken,
6
- resolveAuthToken,
7
- resolveServerCandidates,
8
- resolveServerUrl,
9
- } from "./cliEnvHelpers";
10
- import { readRecordWithCandidates } from "./hybridReadHelpers";
11
- import {
12
- buildDocSpaceRecord,
13
- buildPageRecord,
14
- buildSkillPageRecord,
15
- buildSkillSummaryFromRecord,
16
- parseJsonOption,
17
- readBodyOption,
18
- readOption,
19
- writeRemoteRecordsThenCache,
20
- } from "./pageWriteHelpers";
21
-
22
- function usage(command: "doc" | "skill-doc") {
23
- return [
24
- "Usage:",
25
- ` nolo ${command} update --key <pageKey> [options]`,
26
- "",
27
- ].join("\n");
28
- }
29
-
30
- async function readRecord(args: {
31
- authToken: string;
32
- db: Awaited<ReturnType<typeof getReadableCliDb>>;
33
- dbKey: string;
34
- fetchImpl: typeof fetch;
35
- fallbackFetchImpl?: typeof fetch;
36
- serverCandidates: string[];
37
- }) {
38
- return readRecordWithCandidates<Record<string, any>>({
39
- db: args.db,
40
- dbKey: args.dbKey,
41
- serverCandidates: args.serverCandidates,
42
- readRemote: async (serverUrl, dbKey) =>
43
- readDbRecord({
44
- authToken: args.authToken,
45
- dbKey,
46
- fallbackFetchImpl: args.fallbackFetchImpl,
47
- fetchImpl: args.fetchImpl,
48
- serverUrl,
49
- }),
50
- });
51
- }
52
-
53
- async function runBasePageUpdateCommand(
54
- args: string[],
55
- deps: AgentCommandDeps,
56
- mode: "doc" | "skill-doc"
57
- ) {
58
- const env = deps.env ?? process.env;
59
- const output = deps.output ?? process.stdout;
60
- const dbKey = readOption(args, "--key");
61
- if (!dbKey || dbKey === "-h" || dbKey === "--help") {
62
- output.write(`${usage(mode)}\n`);
63
- return dbKey ? 0 : 1;
64
- }
65
-
66
- const authToken = resolveAuthToken(args, env);
67
- const userId = parseUserIdFromAuthToken(authToken);
68
- if (!authToken || !userId) {
69
- output.write(`[nolo] ${mode} update requires an auth token with userId. Run \`nolo login\`.\n`);
70
- return 1;
71
- }
72
-
73
- const db = deps.db ?? await getReadableCliDb(output);
74
- const fetchImpl = deps.fetchImpl ?? fetch;
75
- const fallbackFetchImpl = deps.fallbackFetchImpl;
76
- const defaultServerUrl = resolveServerUrl(args, env);
77
- const serverCandidates = resolveServerCandidates(args, env, defaultServerUrl);
78
- const writeTargets = [defaultServerUrl];
79
-
80
- try {
81
- const existing = await readRecord({
82
- authToken,
83
- db,
84
- dbKey,
85
- fetchImpl,
86
- fallbackFetchImpl,
87
- serverCandidates,
88
- });
89
- const spaceId = readOption(args, "--space") ?? (typeof existing?.spaceId === "string" ? existing.spaceId : null);
90
- if (!spaceId) {
91
- throw new Error(`unable to resolve space for ${dbKey}`);
92
- }
93
-
94
- const spaceKey = `space-${spaceId}`;
95
- const existingSpaceRecord = await readRecord({
96
- authToken,
97
- db,
98
- dbKey: spaceKey,
99
- fetchImpl,
100
- fallbackFetchImpl,
101
- serverCandidates,
102
- });
103
-
104
- if (mode === "doc") {
105
- if (existing?.meta?.kind === "skill") {
106
- throw new Error(`target page is a skill doc; use \`nolo skill-doc update --key ${dbKey}\``);
107
- }
108
- const title = readOption(args, "--title") ?? existing?.title;
109
- if (!title) {
110
- throw new Error(`missing title for ${dbKey}`);
111
- }
112
- const content = readBodyOption(args, typeof existing?.content === "string" ? existing.content : "");
113
- const pageId =
114
- typeof existing?.id === "string" && existing.id.trim()
115
- ? existing.id
116
- : dbKey.split("-").slice(-1)[0];
117
- const pageRecord = buildPageRecord({
118
- content,
119
- dbKey,
120
- existing,
121
- meta: existing?.meta ?? undefined,
122
- pageId,
123
- spaceId,
124
- title,
125
- });
126
- const spaceRecord = buildDocSpaceRecord({
127
- contentKey: dbKey,
128
- existingSpaceRecord,
129
- spaceId,
130
- title,
131
- });
132
-
133
- await writeRemoteRecordsThenCache({
134
- authToken,
135
- db,
136
- fetchImpl,
137
- fallbackFetchImpl,
138
- records: [
139
- ...writeTargets.map((serverUrl) => ({ dbKey, record: pageRecord, serverUrl })),
140
- ...writeTargets.map((serverUrl) => ({ dbKey: spaceKey, record: spaceRecord, serverUrl })),
141
- ],
142
- userId,
143
- });
144
-
145
- output.write(`${JSON.stringify({ ok: true, dbKey, spaceKey, baseUrl: defaultServerUrl }, null, 2)}\n`);
146
- return 0;
147
- }
148
-
149
- const parsed = parseSkillDocProtocol(
150
- typeof existing?.content === "string" ? existing.content : "",
151
- existing?.meta,
152
- existing?.tools
153
- );
154
- const metadata = resolvePageSkillMetadata(existing);
155
- const currentConfig = metadata?.skillConfig;
156
- if (!currentConfig) {
157
- throw new Error(`target page is not a skill doc: ${dbKey}`);
158
- }
159
-
160
- const title = readOption(args, "--title") ?? existing?.title ?? currentConfig.name;
161
- const description = readOption(args, "--description") ?? currentConfig.description;
162
- if (!title || !description) {
163
- throw new Error(`skill doc requires title and description: ${dbKey}`);
164
- }
165
- const mergedSkillConfig: SkillDocConfig = {
166
- ...currentConfig,
167
- name: title,
168
- description,
169
- ...(readOption(args, "--tools") !== undefined
170
- ? { toolNames: parseJsonOption<string[]>(readOption(args, "--tools"), []) }
171
- : {}),
172
- ...(readOption(args, "--required-skills") !== undefined
173
- ? { requiredSkills: parseJsonOption<string[]>(readOption(args, "--required-skills"), []) }
174
- : {}),
175
- ...(readOption(args, "--recommended-skills") !== undefined
176
- ? { recommendedSkills: parseJsonOption<string[]>(readOption(args, "--recommended-skills"), []) }
177
- : {}),
178
- ...(readOption(args, "--preferred-agents") !== undefined
179
- ? { preferredAgents: parseJsonOption<string[]>(readOption(args, "--preferred-agents"), []) }
180
- : {}),
181
- ...(readOption(args, "--trigger-mode") !== undefined
182
- ? { triggerMode: readOption(args, "--trigger-mode") as SkillDocConfig["triggerMode"] }
183
- : {}),
184
- ...(readOption(args, "--budget-tier") !== undefined
185
- ? { budgetTier: readOption(args, "--budget-tier") as SkillDocConfig["budgetTier"] }
186
- : {}),
187
- ...(readOption(args, "--prompt-patch") !== undefined
188
- ? { promptPatch: readOption(args, "--prompt-patch") || undefined }
189
- : {}),
190
- };
191
- const body = readBodyOption(args, parsed.content ?? "");
192
- const skillId =
193
- typeof existing?.id === "string" && existing.id.trim()
194
- ? existing.id
195
- : dbKey.split("-").slice(-1)[0];
196
- const pageRecord = buildSkillPageRecord({
197
- body,
198
- dbKey,
199
- existing,
200
- skillConfig: mergedSkillConfig,
201
- skillId,
202
- spaceId,
203
- title,
204
- });
205
- const spaceRecord = buildDocSpaceRecord({
206
- contentKey: dbKey,
207
- existingSpaceRecord,
208
- skillSummary: buildSkillSummaryFromRecord(pageRecord),
209
- spaceId,
210
- title,
211
- });
212
-
213
- await writeRemoteRecordsThenCache({
214
- authToken,
215
- db,
216
- fetchImpl,
217
- fallbackFetchImpl,
218
- records: [
219
- ...writeTargets.map((serverUrl) => ({ dbKey, record: pageRecord, serverUrl })),
220
- ...writeTargets.map((serverUrl) => ({ dbKey: spaceKey, record: spaceRecord, serverUrl })),
221
- ],
222
- userId,
223
- });
224
-
225
- output.write(`${JSON.stringify({ ok: true, dbKey, spaceKey, baseUrl: defaultServerUrl }, null, 2)}\n`);
226
- return 0;
227
- } catch (error) {
228
- output.write(
229
- `[nolo] ${mode} update failed: ${
230
- error instanceof Error ? error.message : String(error)
231
- }\n`
232
- );
233
- return 1;
234
- }
235
- }
236
-
237
- export async function runDocUpdateCommand(
238
- args: string[],
239
- deps: AgentCommandDeps = {}
240
- ) {
241
- return runBasePageUpdateCommand(args, deps, "doc");
242
- }
243
-
244
- export async function runSkillDocUpdateCommand(
245
- args: string[],
246
- deps: AgentCommandDeps = {}
247
- ) {
248
- return runBasePageUpdateCommand(args, deps, "skill-doc");
249
- }
@@ -1,209 +0,0 @@
1
- import { readFileSync } from "node:fs";
2
- import { buildSkillDocMarkdown, type SkillDocConfig } from "../ai/skills/skillDocProtocol";
3
- import { buildSkillSummaryMarker } from "../ai/skills/skillSummaryMarker";
4
- import { ContentType, type SpaceContent } from "../app/types";
5
- import { createSpaceKey } from "../create/space/spaceKeys";
6
- import { ulid } from "ulid";
7
- import { writeDbRecord } from "./agentRecordHelpers";
8
- import type { CliKvDb } from "./client/hybridRecordStore";
9
-
10
- export async function writeRemoteRecordsThenCache(args: {
11
- authToken: string;
12
- db: CliKvDb;
13
- fallbackFetchImpl?: typeof fetch;
14
- fetchImpl: typeof fetch;
15
- records: Array<{
16
- dbKey: string;
17
- record: Record<string, any>;
18
- serverUrl: string;
19
- }>;
20
- userId: string;
21
- }) {
22
- for (const item of args.records) {
23
- await writeDbRecord({
24
- authToken: args.authToken,
25
- dbKey: item.dbKey,
26
- fallbackFetchImpl: args.fallbackFetchImpl,
27
- fetchImpl: args.fetchImpl,
28
- record: item.record,
29
- serverUrl: item.serverUrl,
30
- userId: args.userId,
31
- });
32
- }
33
-
34
- for (const item of args.records) {
35
- await args.db.put(item.dbKey, item.record);
36
- }
37
- }
38
-
39
- export function readBodyOption(args: string[], fallback = "") {
40
- const bodyFile = readOption(args, "--body-file");
41
- if (bodyFile !== undefined) {
42
- return readFileSync(bodyFile, "utf8");
43
- }
44
- return readOption(args, "--body") ?? fallback;
45
- }
46
-
47
- export function buildPageRecord(args: {
48
- dbKey: string;
49
- pageId: string;
50
- title: string;
51
- spaceId: string | null;
52
- content: string;
53
- existing?: Record<string, any> | null;
54
- meta?: Record<string, any> | null;
55
- slateData?: Record<string, any>[] | null;
56
- }) {
57
- const { content, dbKey, existing, meta, pageId, slateData, spaceId, title } = args;
58
- const now = Date.now();
59
- const createdAt = typeof existing?.createdAt === "number" ? existing.createdAt : now;
60
- const created =
61
- typeof existing?.created === "string" ? existing.created : new Date(createdAt).toISOString();
62
-
63
- const nextRecord: Record<string, any> = {
64
- ...(existing ?? {}),
65
- id: existing?.id ?? pageId,
66
- dbKey,
67
- type: "page",
68
- title,
69
- spaceId,
70
- content,
71
- updatedAt: now,
72
- createdAt,
73
- created,
74
- };
75
-
76
- if (meta !== undefined) {
77
- if (meta === null) {
78
- delete nextRecord.meta;
79
- } else {
80
- nextRecord.meta = meta;
81
- }
82
- }
83
-
84
- if (slateData !== undefined) {
85
- if (slateData === null) {
86
- delete nextRecord.slateData;
87
- } else {
88
- nextRecord.slateData = slateData;
89
- }
90
- }
91
-
92
- return nextRecord;
93
- }
94
-
95
- export function buildSkillPageRecord(args: {
96
- dbKey: string;
97
- skillId: string;
98
- title: string;
99
- spaceId: string | null;
100
- body: string;
101
- skillConfig: SkillDocConfig;
102
- existing?: Record<string, any> | null;
103
- }) {
104
- const { body, dbKey, existing, skillConfig, skillId, spaceId, title } = args;
105
- return buildPageRecord({
106
- dbKey,
107
- pageId: skillId,
108
- title,
109
- spaceId,
110
- content: buildSkillDocMarkdown({ body, skillConfig }),
111
- existing,
112
- meta: {
113
- ...(existing?.meta ?? {}),
114
- kind: "skill",
115
- skillConfig,
116
- },
117
- slateData: null,
118
- });
119
- }
120
-
121
- export function buildDocSpaceRecord(args: {
122
- contentKey: string;
123
- spaceId: string;
124
- title: string;
125
- existingSpaceRecord: Record<string, any>;
126
- skillSummary?: SpaceContent["skillSummary"] | null;
127
- }) {
128
- const { contentKey, existingSpaceRecord, skillSummary, spaceId, title } = args;
129
- const now = Date.now();
130
- const existingContent = existingSpaceRecord?.contents?.[contentKey];
131
-
132
- return {
133
- ...existingSpaceRecord,
134
- dbKey: createSpaceKey.space(spaceId),
135
- updatedAt: now,
136
- contents: {
137
- ...(existingSpaceRecord?.contents ?? {}),
138
- [contentKey]: {
139
- ...(existingContent ?? {}),
140
- title,
141
- type: ContentType.DOC,
142
- contentKey,
143
- ...(skillSummary !== undefined ? { skillSummary } : {}),
144
- updatedAt: now,
145
- createdAt: existingContent?.createdAt ?? now,
146
- },
147
- },
148
- };
149
- }
150
-
151
- export function buildSkillSummaryFromRecord(record: Record<string, any>) {
152
- return buildSkillSummaryMarker(record?.meta);
153
- }
154
-
155
- export function buildDetachedDocSpaceRecord(args: {
156
- contentKey: string;
157
- existingSpaceRecord: Record<string, any>;
158
- spaceId: string;
159
- }) {
160
- const { contentKey, existingSpaceRecord, spaceId } = args;
161
- const nextContents = { ...(existingSpaceRecord?.contents ?? {}) };
162
- delete nextContents[contentKey];
163
- return {
164
- ...existingSpaceRecord,
165
- dbKey: createSpaceKey.space(spaceId),
166
- updatedAt: Date.now(),
167
- contents: nextContents,
168
- };
169
- }
170
-
171
- export function readOption(args: string[], flag: string) {
172
- const index = args.indexOf(flag);
173
- return index >= 0 ? args[index + 1] : undefined;
174
- }
175
-
176
- export function parseJsonOption<T>(raw: string | undefined, fallback: T): T {
177
- if (raw === undefined) return fallback;
178
- return JSON.parse(raw) as T;
179
- }
180
-
181
- export function createPageId() {
182
- return ulid();
183
- }
184
-
185
- export function buildPageKey(userId: string, pageId: string) {
186
- return `page-${userId}-${pageId}`;
187
- }
188
-
189
- export function normalizeSkillSeed(input: string) {
190
- return input
191
- .trim()
192
- .toLowerCase()
193
- .replace(/[^a-z0-9\u4e00-\u9fa5]+/g, "-")
194
- .replace(/^-+|-+$/g, "");
195
- }
196
-
197
- export function deterministicId(prefix: string, seed: string) {
198
- let hash = 0x811c9dc5;
199
- for (let index = 0; index < seed.length; index += 1) {
200
- hash ^= seed.charCodeAt(index);
201
- hash = (hash * 0x01000193) >>> 0;
202
- }
203
- const suffix = hash.toString(36).toUpperCase().padStart(14, "0");
204
- return (prefix + suffix).slice(0, 26);
205
- }
206
-
207
- export function buildSkillDocId(input: string) {
208
- return deterministicId("01SK", normalizeSkillSeed(input) || input);
209
- }
@@ -1,36 +0,0 @@
1
- /**
2
- * Build a publish-safe package.json manifest by removing workspace dependencies.
3
- *
4
- * Workspace dependencies (e.g., "workspace:*") should not be published to npm
5
- * as they only resolve within the monorepo workspace.
6
- *
7
- * @param manifest - The input package.json manifest object
8
- * @returns A new manifest with workspace dependencies removed
9
- */
10
- export function buildPublishManifest(manifest: Record<string, any>): Record<string, any> {
11
- const result = { ...manifest };
12
-
13
- // Strip workspace deps from all dependency fields
14
- const depFields = ["dependencies", "devDependencies", "peerDependencies"] as const;
15
-
16
- for (const field of depFields) {
17
- if (result[field]) {
18
- const filtered: Record<string, string> = {};
19
- for (const [name, version] of Object.entries(result[field])) {
20
- // Skip workspace: protocol dependencies
21
- if (typeof version === "string" && !version.startsWith("workspace:")) {
22
- filtered[name] = version;
23
- }
24
- }
25
-
26
- // Only set the field if there are non-workspace deps
27
- if (Object.keys(filtered).length > 0) {
28
- result[field] = filtered;
29
- } else {
30
- delete result[field];
31
- }
32
- }
33
- }
34
-
35
- return result;
36
- }
@@ -1,15 +0,0 @@
1
- import { createArgsCommand } from "./cliCommandFactories";
2
- import type { CommandEntry } from "./cliCommandTypes";
3
- import {
4
- runDevPassthroughCommand,
5
- runLlamaPassthroughCommand,
6
- runModelRuntimePassthroughCommand,
7
- } from "./runtimePassthroughCommands";
8
-
9
- export function getRuntimeInternalCommandEntries(): CommandEntry[] {
10
- return [
11
- createArgsCommand(["llama"], "Manage the llama.cpp runtime", runLlamaPassthroughCommand),
12
- createArgsCommand(["model-runtime"], "Manage local model runtime processes", runModelRuntimePassthroughCommand),
13
- createArgsCommand(["dev"], "Manage the local dev environment", runDevPassthroughCommand),
14
- ];
15
- }
@@ -1,22 +0,0 @@
1
- import { runScriptPassthrough, type ScriptPassthroughDeps } from "./scriptPassthroughHelpers";
2
-
3
- export async function runLlamaPassthroughCommand(
4
- args: string[],
5
- deps: ScriptPassthroughDeps = {}
6
- ) {
7
- return runScriptPassthrough("scripts/runtime/llamaServerSupervisor.ts", args, deps);
8
- }
9
-
10
- export async function runModelRuntimePassthroughCommand(
11
- args: string[],
12
- deps: ScriptPassthroughDeps = {}
13
- ) {
14
- return runScriptPassthrough("scripts/runtime/localModelRuntimeSupervisor.ts", args, deps);
15
- }
16
-
17
- export async function runDevPassthroughCommand(
18
- args: string[],
19
- deps: ScriptPassthroughDeps = {}
20
- ) {
21
- return runScriptPassthrough("scripts/dev/devControl.ts", args, deps);
22
- }
@@ -1,28 +0,0 @@
1
- import path from "node:path";
2
-
3
- export type ScriptPassthroughDeps = {
4
- env?: NodeJS.ProcessEnv;
5
- spawnCommand?: (command: string[]) => Promise<number>;
6
- };
7
-
8
- async function defaultSpawnCommand(command: string[]) {
9
- const proc = Bun.spawn({
10
- cmd: command,
11
- cwd: process.cwd(),
12
- env: process.env,
13
- stdout: "inherit",
14
- stderr: "inherit",
15
- stdin: "inherit",
16
- });
17
- return await proc.exited;
18
- }
19
-
20
- export async function runScriptPassthrough(
21
- relativeScriptPath: string,
22
- args: string[],
23
- deps: ScriptPassthroughDeps = {}
24
- ) {
25
- const spawnCommand = deps.spawnCommand ?? defaultSpawnCommand;
26
- const command = [process.execPath, path.join(process.cwd(), relativeScriptPath), ...args];
27
- return await spawnCommand(command);
28
- }
@@ -1,31 +0,0 @@
1
- export type SecretFinding = {
2
- label: string;
3
- line: number;
4
- preview: string;
5
- };
6
-
7
- const SECRET_PATTERNS: Array<{ label: string; pattern: RegExp }> = [
8
- { label: "password", pattern: /\bpassword\s*[:=]\s*["']?[^"',\s#]{8,}/i },
9
- { label: "psk", pattern: /\bpsk\s*[:=]\s*["']?[^"',\s#]{8,}/i },
10
- { label: "api key", pattern: /\b(api[_-]?key|apikey)\s*[:=]\s*["']?[^"',\s#]{12,}/i },
11
- { label: "token", pattern: /\b(token|secret)\s*[:=]\s*["']?[^"',\s#]{12,}/i },
12
- { label: "private key", pattern: /-----BEGIN [A-Z ]*PRIVATE KEY-----/ },
13
- ];
14
-
15
- export function findPotentialSecrets(text: string): SecretFinding[] {
16
- return text
17
- .split(/\r?\n/)
18
- .flatMap((line, index) =>
19
- SECRET_PATTERNS.filter(({ pattern }) => pattern.test(line)).map(({ label }) => ({
20
- label,
21
- line: index + 1,
22
- preview: line.length > 120 ? `${line.slice(0, 117)}...` : line,
23
- }))
24
- );
25
- }
26
-
27
- export function formatSecretFindings(findings: SecretFinding[]) {
28
- return findings
29
- .map((finding) => ` line ${finding.line} (${finding.label}): ${finding.preview}`)
30
- .join("\n");
31
- }