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,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
- }
package/publishPackage.ts DELETED
@@ -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
- }
package/share/helpers.ts DELETED
@@ -1,302 +0,0 @@
1
- import {
2
- createAgentKey,
3
- createCybotKey,
4
- isAgentKey,
5
- splitKey,
6
- } from "../database/keys";
7
- import { DataType } from "../create/types";
8
- import type { ShareType } from "./types";
9
-
10
- // ── String normalization ────────────────────────────────────────────
11
-
12
- export const toSafeString = (value: unknown): string =>
13
- typeof value === "string" ? value.trim() : "";
14
-
15
- export const toNonEmptyString = (value: unknown): string | undefined => {
16
- const text = toSafeString(value);
17
- return text || undefined;
18
- };
19
-
20
- export const normalizeUserId = (value: unknown): string => {
21
- const text = toSafeString(value);
22
- return text.startsWith("user:") ? text.slice(5) : text;
23
- };
24
-
25
- export const normalizeAuthorName = (value: unknown): string => {
26
- const text = toSafeString(value);
27
- if (!text) return "";
28
- const lower = text.toLowerCase();
29
- if (lower === "unknown" || lower === "unknown user") return "";
30
- return text;
31
- };
32
-
33
- export const toSafeAgentKey = (value: unknown): string => {
34
- const text = toSafeString(value);
35
- return text && isAgentKey(text) ? text : "";
36
- };
37
-
38
- // ── Time helpers ────────────────────────────────────────────────────
39
-
40
- export const toSafeTimestamp = (value: unknown): number => {
41
- const num = Number(value);
42
- if (Number.isFinite(num) && num > 0) return num;
43
- if (typeof value !== "string") return 0;
44
- const parsed = Date.parse(value);
45
- return Number.isFinite(parsed) && parsed > 0 ? parsed : 0;
46
- };
47
-
48
- const SHARE_TIME_FORMATTER = new Intl.DateTimeFormat("zh-CN", {
49
- timeZone: "Asia/Shanghai",
50
- year: "numeric",
51
- month: "2-digit",
52
- day: "2-digit",
53
- hour: "2-digit",
54
- minute: "2-digit",
55
- second: "2-digit",
56
- hour12: false,
57
- });
58
-
59
- export const formatShareTime = (timestamp: number): string => {
60
- if (!timestamp) return "时间未知";
61
- const date = new Date(timestamp);
62
- return Number.isFinite(date.getTime()) ? SHARE_TIME_FORMATTER.format(date) : "时间未知";
63
- };
64
-
65
- // ── Agent extraction ────────────────────────────────────────────────
66
-
67
- const findAgentKeyInMessages = (messages: unknown[]): string => {
68
- for (const raw of messages) {
69
- if (!raw || typeof raw !== "object") continue;
70
- const key = toSafeAgentKey((raw as Record<string, unknown>).cybotKey);
71
- if (key) return key;
72
- }
73
- return "";
74
- };
75
-
76
- const findAgentKeyInArray = (items: unknown[]): string => {
77
- for (const raw of items) {
78
- const direct = toSafeAgentKey(raw);
79
- if (direct) return direct;
80
- if (!raw || typeof raw !== "object") continue;
81
- const item = raw as Record<string, unknown>;
82
- const key = toSafeAgentKey(item.dbKey) || toSafeAgentKey(item.id);
83
- if (key) return key;
84
- }
85
- return "";
86
- };
87
-
88
- const findAgentNameInMessages = (messages: unknown[]): string => {
89
- for (const raw of messages) {
90
- if (!raw || typeof raw !== "object") continue;
91
- const msg = raw as Record<string, unknown>;
92
- const name =
93
- toSafeString(msg.agentName) ||
94
- toSafeString(msg.cybotName) ||
95
- toSafeString(msg.sourceAgentName);
96
- if (name) return name;
97
- }
98
- return "";
99
- };
100
-
101
- const findAgentNameInArray = (items: unknown[]): string => {
102
- for (const raw of items) {
103
- if (!raw || typeof raw !== "object") continue;
104
- const item = raw as Record<string, unknown>;
105
- const name =
106
- toSafeString(item.name) ||
107
- toSafeString(item.agentName) ||
108
- toSafeString(item.cybotName) ||
109
- toSafeString(item.sourceAgentName);
110
- if (name) return name;
111
- }
112
- return "";
113
- };
114
-
115
- export const extractAgentInfo = (
116
- type: ShareType,
117
- data: Record<string, unknown>
118
- ): { sourceAgentKey?: string; sourceAgentName?: string } => {
119
- const meta = data.meta as Record<string, unknown> | undefined;
120
-
121
- // Candidate keys in priority order
122
- const keyCandidates: unknown[] = [
123
- meta?.sourceAgentKey,
124
- meta?.agentKey,
125
- data.sourceAgentKey,
126
- data.agentKey,
127
- data.cybotKey,
128
- type === DataType.CYBOT ? (data.dbKey ?? data.id) : undefined,
129
- ];
130
-
131
- let agentKey = "";
132
- for (const candidate of keyCandidates) {
133
- agentKey = toSafeAgentKey(candidate);
134
- if (agentKey) break;
135
- }
136
-
137
- // Fallback: search in arrays
138
- if (!agentKey && Array.isArray(data.cybots)) {
139
- agentKey = findAgentKeyInArray(data.cybots);
140
- }
141
- if (!agentKey && Array.isArray(data.messages)) {
142
- agentKey = findAgentKeyInMessages(data.messages as unknown[]);
143
- }
144
- if (!agentKey && Array.isArray(data.history)) {
145
- agentKey = findAgentKeyInMessages(data.history as unknown[]);
146
- }
147
-
148
- // Agent name
149
- const nameCandidates: unknown[] = [
150
- meta?.sourceAgentName,
151
- meta?.agentName,
152
- meta?.cybotName,
153
- data.sourceAgentName,
154
- data.agentName,
155
- data.cybotName,
156
- type === DataType.CYBOT ? data.name : undefined,
157
- ];
158
-
159
- let agentName = "";
160
- for (const candidate of nameCandidates) {
161
- agentName = toSafeString(candidate);
162
- if (agentName) break;
163
- }
164
- if (!agentName && Array.isArray(data.cybots)) {
165
- agentName = findAgentNameInArray(data.cybots);
166
- }
167
- if (!agentName && Array.isArray(data.messages)) {
168
- agentName = findAgentNameInMessages(data.messages as unknown[]);
169
- }
170
- if (!agentName && Array.isArray(data.history)) {
171
- agentName = findAgentNameInMessages(data.history as unknown[]);
172
- }
173
-
174
- return {
175
- ...(agentKey ? { sourceAgentKey: agentKey } : {}),
176
- ...(agentName ? { sourceAgentName: agentName } : {}),
177
- };
178
- };
179
-
180
- // ── Cover image extraction ──────────────────────────────────────────
181
-
182
- const extractImageFromContent = (content: unknown): string | undefined => {
183
- if (Array.isArray(content)) {
184
- const part = content.find(
185
- (p: any) => p?.type === "image_url" && typeof p?.image_url?.url === "string"
186
- );
187
- if (part?.image_url?.url) return part.image_url.url;
188
- }
189
- if (typeof content === "string") {
190
- const match = content.match(/!\[.*?\]\((.*?)\)/);
191
- if (match?.[1]) return match[1];
192
- }
193
- return undefined;
194
- };
195
-
196
- export const extractCoverImage = (
197
- type: ShareType,
198
- data: Record<string, unknown>
199
- ): string | undefined => {
200
- if (type === DataType.IMAGE) {
201
- return toNonEmptyString(data.url);
202
- }
203
- if (type === DataType.APP) {
204
- return toNonEmptyString(data.coverImage);
205
- }
206
- if (type !== DataType.DIALOG) return undefined;
207
-
208
- const messages = (Array.isArray(data.messages)
209
- ? data.messages
210
- : Array.isArray(data.history)
211
- ? data.history
212
- : []) as Record<string, unknown>[];
213
-
214
- for (const msg of messages) {
215
- const fromContent = extractImageFromContent(msg.content);
216
- if (fromContent) return fromContent;
217
-
218
- const image = toNonEmptyString(msg.image);
219
- if (image) return image;
220
-
221
- if (Array.isArray(msg.images)) {
222
- const first = (msg.images as unknown[]).find(
223
- (u) => typeof u === "string" && u.trim().length > 0
224
- );
225
- if (first) return first as string;
226
- }
227
- }
228
- return undefined;
229
- };
230
-
231
- // ── Author extraction ────────────────────────────────────────────────
232
-
233
- export const toPublicAgentKey = (value: unknown): string => {
234
- const key = toSafeAgentKey(value);
235
- if (!key) return "";
236
-
237
- const parts = splitKey(key);
238
- if (parts.length < 3) return "";
239
-
240
- const [type, owner] = parts;
241
- const agentId = parts[parts.length - 1];
242
- if (!agentId) return "";
243
- if (owner === "pub") return key;
244
-
245
- if (type === DataType.AGENT) {
246
- return createAgentKey.public(agentId);
247
- }
248
- if (type === DataType.CYBOT) {
249
- return createCybotKey.public(agentId);
250
- }
251
- return "";
252
- };
253
-
254
- export const resolveShareAuthorIdentity = (args: {
255
- user?: Record<string, unknown> | null;
256
- profile?: Record<string, unknown> | null;
257
- fallbackName?: unknown;
258
- fallbackAvatar?: unknown;
259
- }): { authorName?: string; authorAvatar?: string } => {
260
- const authorName =
261
- toNonEmptyString(args.profile?.nickname) ??
262
- toNonEmptyString(args.user?.name) ??
263
- toNonEmptyString(args.user?.nickname) ??
264
- toNonEmptyString(args.user?.username) ??
265
- toNonEmptyString(args.fallbackName);
266
- const authorAvatar =
267
- toNonEmptyString(args.profile?.avatar) ??
268
- toNonEmptyString(args.user?.avatar) ??
269
- toNonEmptyString(args.fallbackAvatar);
270
-
271
- return {
272
- ...(authorName ? { authorName } : {}),
273
- ...(authorAvatar ? { authorAvatar } : {}),
274
- };
275
- };
276
-
277
- // ── Error helpers ───────────────────────────────────────────────────
278
-
279
- export const isLevelNotFoundError = (error: unknown): boolean => {
280
- if (!error || typeof error !== "object") return false;
281
- const e = error as Record<string, unknown>;
282
- return (
283
- e.notFound === true ||
284
- e.name === "NotFoundError" ||
285
- e.code === "LEVEL_NOT_FOUND" ||
286
- e.code === "LEVEL_NOT_FOUND_ERROR"
287
- );
288
- };
289
-
290
- // ── Sanitization ────────────────────────────────────────────────────
291
-
292
- const SENSITIVE_FIELDS = ["apiKey", "secret", "password"] as const;
293
-
294
- export const sanitizeShareData = (
295
- data: Record<string, unknown>
296
- ): Record<string, unknown> => {
297
- const snapshot = { ...data };
298
- for (const field of SENSITIVE_FIELDS) {
299
- delete snapshot[field];
300
- }
301
- return snapshot;
302
- };