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,79 +0,0 @@
1
- import {
2
- buildMachinePermissionPromptBlock,
3
- resolveMachineRunPermissionPolicy,
4
- type MachineRunPermissionPolicy,
5
- } from "./ai/agent/machineRunPermissions";
6
- import { buildNoloReadOnlyBridgePrompt } from "./noloReadBridgePrompt";
7
-
8
- export function inferTaskRunRole(agentKey: string, agentConfig: any) {
9
- const haystack = [agentKey, agentConfig?.name, agentConfig?.prompt]
10
- .filter(Boolean)
11
- .join("\n")
12
- .toLowerCase();
13
- if (haystack.includes("frontend") || haystack.includes("前端")) return "frontend";
14
- if (haystack.includes("fullstack") || haystack.includes("全栈")) return "fullstack";
15
- if (haystack.includes("review") || haystack.includes("审查")) return "reviewer";
16
- if (haystack.includes("project-manager") || haystack.includes("项目经理")) return "pm";
17
- return "codex";
18
- }
19
-
20
- export function buildTaskRunBridgePrompt(args: {
21
- agentKey: string;
22
- agentConfig: any;
23
- runtimeContext: any;
24
- }) {
25
- const taskRun = args.runtimeContext?.taskRun;
26
- const rowDbKey = typeof taskRun?.rowDbKey === "string" ? taskRun.rowDbKey.trim() : "";
27
- if (!rowDbKey) return "";
28
- const workItemId = typeof taskRun?.workItemId === "string" ? taskRun.workItemId.trim() : "";
29
- const role = inferTaskRunRole(args.agentKey, args.agentConfig);
30
- return [
31
- "--- Nolo task-run tool bridge ---",
32
- "This CLI runtime does not receive server-side function tools directly.",
33
- "Use the local task-run bridge command for durable task state writes. Do not edit meta.taskRun with table or database commands.",
34
- "Run commands from the repository root. The runner already provides server URL and auth in the environment.",
35
- "Release boundary: after review passes, AI/reviewer/Codex may advance alpha for verification. Do not merge, push, or release main/release unless the human owner explicitly authorizes it in the current task context.",
36
- "Cost boundary: read taskRun.control from context. Prefer low-cost/free-window models for routine work, and reserve Codex for supervision, quality gates, complex unblocking, and main/release decisions.",
37
- "Handoff context: start from read-context, then inspect existing refs such as workItems.dialogIds, workItems.outcome, review.dialogId, activityRefs, agentRuns.dialogId/resultSummary, and artifactRefs. Use dialog read/search for exact evidence; do not infer completion from handoff text alone.",
38
- `Read context: bun packages/cli/index.ts task-run read-context --row-dbkey ${JSON.stringify(rowDbKey)}`,
39
- ...(workItemId
40
- ? [
41
- `Claim work item: bun packages/cli/index.ts task-run claim-work-item --row-dbkey ${JSON.stringify(rowDbKey)} --work-item-id ${JSON.stringify(workItemId)} --agent-key ${JSON.stringify(args.agentKey)} --role ${role}`,
42
- `Set blocker: bun packages/cli/index.ts task-run set-blocker --row-dbkey ${JSON.stringify(rowDbKey)} --work-item-id ${JSON.stringify(workItemId)} --layer tool --code <CODE> --message <MESSAGE>`,
43
- `Clear resolved blocker: bun packages/cli/index.ts task-run clear-blocker --row-dbkey ${JSON.stringify(rowDbKey)} --work-item-id ${JSON.stringify(workItemId)} --blocker-id <BLOCKER_ID>`,
44
- `Submit outcome: bun packages/cli/index.ts task-run submit-outcome --row-dbkey ${JSON.stringify(rowDbKey)} --work-item-id ${JSON.stringify(workItemId)} --summary <SUMMARY>`,
45
- `Request review: bun packages/cli/index.ts task-run request-review --row-dbkey ${JSON.stringify(rowDbKey)} --work-item-id ${JSON.stringify(workItemId)} --reviewer-agent-key <AGENT_KEY> --message <MESSAGE>`,
46
- `Record review: bun packages/cli/index.ts task-run record-review --row-dbkey ${JSON.stringify(rowDbKey)} --work-item-id ${JSON.stringify(workItemId)} --review-status <passed|needs_changes|blocked> --reviewer-agent-key ${JSON.stringify(args.agentKey)} --findings <FINDINGS>`,
47
- `Close work item: bun packages/cli/index.ts task-run close-work-item --row-dbkey ${JSON.stringify(rowDbKey)} --work-item-id ${JSON.stringify(workItemId)} --summary <SUMMARY>`,
48
- ]
49
- : []),
50
- "If a bridge command fails, report the exact command and error.",
51
- ].join("\n");
52
- }
53
-
54
- export function buildConnectorCliPrompt(
55
- agentConfig: any,
56
- userInput: string,
57
- bridgeArgs?: {
58
- agentKey: string;
59
- runtimeContext: any;
60
- },
61
- permissionPolicy?: MachineRunPermissionPolicy,
62
- ) {
63
- const policy = permissionPolicy ?? resolveMachineRunPermissionPolicy(agentConfig);
64
- return [
65
- typeof agentConfig?.prompt === "string" ? agentConfig.prompt.trim() : "",
66
- buildNoloReadOnlyBridgePrompt(),
67
- bridgeArgs
68
- ? buildTaskRunBridgePrompt({
69
- agentKey: bridgeArgs.agentKey,
70
- agentConfig,
71
- runtimeContext: bridgeArgs.runtimeContext,
72
- })
73
- : "",
74
- buildMachinePermissionPromptBlock(policy),
75
- `--- User task ---\n${userInput}`,
76
- ]
77
- .filter(Boolean)
78
- .join("\n\n");
79
- }
@@ -1,43 +0,0 @@
1
- import {
2
- hasFlag,
3
- readCliOptionValue,
4
- resolveAuthToken as resolveCliAuthToken,
5
- resolveAuthTokenFromArgs,
6
- resolveServerUrlFromArgs,
7
- resolveServerUrlFromEnv,
8
- type EnvLike,
9
- } from "./cliEnvHelpers";
10
- import type { OutputLike } from "./cliIoTypes";
11
- export type { OutputLike } from "./cliIoTypes";
12
- export { hasFlag };
13
-
14
- export function resolveServerUrl(env: EnvLike) {
15
- return resolveServerUrlFromEnv(env);
16
- }
17
-
18
- export function resolveAuthToken(env: EnvLike) {
19
- return resolveCliAuthToken(env);
20
- }
21
-
22
- export function writeAuthMissing(output: OutputLike) {
23
- output.write(
24
- "[nolo] Machine commands require an auth token. Run `nolo login` or set AUTH_TOKEN.\n"
25
- );
26
- }
27
-
28
- export function readOption(args: string[], flag: string) {
29
- return readCliOptionValue(args, flag);
30
- }
31
-
32
- export function resolveConnectServerUrl(args: string[], env: EnvLike) {
33
- return resolveServerUrlFromArgs(args, env);
34
- }
35
-
36
- export function resolveConnectAuthToken(args: string[], env: EnvLike) {
37
- return resolveAuthTokenFromArgs(args, env);
38
- }
39
-
40
- export function resolveConnectorReconnectDelayMs(env: EnvLike) {
41
- const raw = Number(env.NOLO_CONNECT_RECONNECT_MS ?? "");
42
- return Number.isFinite(raw) && raw >= 0 ? raw : 5_000;
43
- }
@@ -1,16 +0,0 @@
1
- const REPO_CLI_PREFIX = "bun packages/cli/index.ts";
2
-
3
- export function buildNoloReadOnlyBridgePrompt() {
4
- return [
5
- "--- Nolo read-only CLI bridge ---",
6
- "This CLI runtime does not receive server-side function tools directly.",
7
- "Use these repo-local read commands to fetch authoritative Nolo docs and records on demand instead of trusting prompt snapshots or summaries alone.",
8
- "Run commands from the repository root. The runner already provides server URL and auth in the environment.",
9
- `Read doc/page truth: ${REPO_CLI_PREFIX} doc read "<pageKey>"`,
10
- `Read skill doc truth: ${REPO_CLI_PREFIX} skill-doc read "<pageKey>"`,
11
- `Read dialog truth: ${REPO_CLI_PREFIX} dialog read "<dialogId|dialogUrl>"`,
12
- `Read shared space truth: ${REPO_CLI_PREFIX} space read "<spaceId|spaceKey|spaceUrl>"`,
13
- `Read agent truth: ${REPO_CLI_PREFIX} agent read "<agentKey|agentAlias|agentUrl>"`,
14
- "If a read command fails, report the exact command and error.",
15
- ].join("\n");
16
- }
@@ -1,219 +0,0 @@
1
- import type { SkillDocConfig } from "./ai/skills/skillDocProtocol";
2
- import { getReadableCliDb, type AgentCommandDeps } from "./agentCommandSupport";
3
- import { readDbRecord } from "./agentRecordHelpers";
4
- import { parseUserIdFromAuthToken, resolveAuthToken, resolveServerUrl } from "./cliEnvHelpers";
5
- import {
6
- buildDocSpaceRecord,
7
- buildPageKey,
8
- buildPageRecord,
9
- buildSkillDocId,
10
- buildSkillPageRecord,
11
- buildSkillSummaryFromRecord,
12
- createPageId,
13
- parseJsonOption,
14
- readBodyOption,
15
- readOption,
16
- writeRemoteRecordsThenCache,
17
- } from "./pageWriteHelpers";
18
- import { findPotentialSecrets, formatSecretFindings } from "./secretScanHelpers";
19
-
20
- function usage(command: "doc" | "skill-doc") {
21
- return [
22
- "Usage:",
23
- ` nolo ${command} create --title <title> [options]`,
24
- "",
25
- ].join("\n");
26
- }
27
-
28
- async function readSpaceRecord(args: {
29
- authToken: string;
30
- db: Awaited<ReturnType<typeof getReadableCliDb>>;
31
- fetchImpl: typeof fetch;
32
- fallbackFetchImpl?: typeof fetch;
33
- serverUrl: string;
34
- spaceKey: string;
35
- }) {
36
- try {
37
- return await args.db.get(args.spaceKey);
38
- } catch {
39
- return readDbRecord({
40
- authToken: args.authToken,
41
- dbKey: args.spaceKey,
42
- fallbackFetchImpl: args.fallbackFetchImpl,
43
- fetchImpl: args.fetchImpl,
44
- serverUrl: args.serverUrl,
45
- });
46
- }
47
- }
48
-
49
- async function runBasePageCreateCommand(
50
- args: string[],
51
- deps: AgentCommandDeps,
52
- mode: "doc" | "skill-doc"
53
- ) {
54
- const env = deps.env ?? process.env;
55
- const output = deps.output ?? process.stdout;
56
- if (args.includes("--help") || args.includes("-h")) {
57
- output.write(`${usage(mode)}\n`);
58
- return 0;
59
- }
60
-
61
- const title = readOption(args, "--title")?.trim();
62
- const description = readOption(args, "--description")?.trim();
63
- const spaceId = readOption(args, "--space")?.trim() ?? null;
64
- if (!title || !spaceId || (mode === "skill-doc" && !description)) {
65
- output.write(`${usage(mode)}\n`);
66
- return 1;
67
- }
68
-
69
- const authToken = resolveAuthToken(args, env);
70
- const userId = parseUserIdFromAuthToken(authToken);
71
- if (!authToken || !userId) {
72
- output.write(`[nolo] ${mode} create requires an auth token with userId. Run \`nolo login\`.\n`);
73
- return 1;
74
- }
75
-
76
- const body = readBodyOption(args, "");
77
- const secretFindings = findPotentialSecrets(body);
78
- if (secretFindings.length > 0 && !args.includes("--allow-secrets")) {
79
- output.write(
80
- `[nolo] refusing to create ${mode} because the body looks like it contains secrets.\n${formatSecretFindings(secretFindings)}\n`
81
- );
82
- return 1;
83
- }
84
-
85
- const serverUrl = resolveServerUrl(args, env);
86
- const db = deps.db ?? await getReadableCliDb(output);
87
- const fetchImpl = deps.fetchImpl ?? fetch;
88
- const fallbackFetchImpl = deps.fallbackFetchImpl;
89
- const explicitId = readOption(args, "--id")?.trim();
90
- const pageId = explicitId || (mode === "skill-doc" ? buildSkillDocId(title) : createPageId());
91
- const dbKey = buildPageKey(userId, pageId);
92
- const spaceKey = `space-${spaceId}`;
93
- const shouldDryRun = args.includes("--dry-run");
94
- const shouldOutputJson = args.includes("--json");
95
-
96
- const pageRecord =
97
- mode === "skill-doc"
98
- ? buildSkillPageRecord({
99
- body,
100
- dbKey,
101
- existing: null,
102
- skillConfig: {
103
- version: "0.1",
104
- kind: "skill",
105
- id: pageId,
106
- name: title,
107
- description: description!,
108
- ...(readOption(args, "--tools") !== undefined
109
- ? { toolNames: parseJsonOption<string[]>(readOption(args, "--tools"), []) }
110
- : {}),
111
- ...(readOption(args, "--required-skills") !== undefined
112
- ? { requiredSkills: parseJsonOption<string[]>(readOption(args, "--required-skills"), []) }
113
- : {}),
114
- ...(readOption(args, "--recommended-skills") !== undefined
115
- ? { recommendedSkills: parseJsonOption<string[]>(readOption(args, "--recommended-skills"), []) }
116
- : {}),
117
- ...(readOption(args, "--preferred-agents") !== undefined
118
- ? { preferredAgents: parseJsonOption<string[]>(readOption(args, "--preferred-agents"), []) }
119
- : {}),
120
- ...(readOption(args, "--trigger-mode") !== undefined
121
- ? { triggerMode: readOption(args, "--trigger-mode") as SkillDocConfig["triggerMode"] }
122
- : {}),
123
- ...(readOption(args, "--budget-tier") !== undefined
124
- ? { budgetTier: readOption(args, "--budget-tier") as SkillDocConfig["budgetTier"] }
125
- : {}),
126
- ...(readOption(args, "--prompt-patch") !== undefined
127
- ? { promptPatch: readOption(args, "--prompt-patch") || undefined }
128
- : {}),
129
- },
130
- skillId: pageId,
131
- spaceId,
132
- title,
133
- })
134
- : buildPageRecord({
135
- content: body,
136
- dbKey,
137
- meta: description ? { description } : undefined,
138
- pageId,
139
- spaceId,
140
- title,
141
- });
142
-
143
- const summary = {
144
- dryRun: shouldDryRun,
145
- kind: mode === "skill-doc" ? "skill" : "page",
146
- title,
147
- dbKey,
148
- id: pageId,
149
- spaceId,
150
- baseUrl: serverUrl,
151
- secretFindingCount: secretFindings.length,
152
- secretFindings,
153
- };
154
-
155
- if (shouldDryRun) {
156
- output.write(`${JSON.stringify(summary, null, 2)}\n`);
157
- return 0;
158
- }
159
-
160
- try {
161
- const existingSpaceRecord = await readSpaceRecord({
162
- authToken,
163
- db,
164
- fallbackFetchImpl,
165
- fetchImpl,
166
- serverUrl,
167
- spaceKey,
168
- });
169
- const spaceRecord = buildDocSpaceRecord({
170
- contentKey: dbKey,
171
- existingSpaceRecord,
172
- skillSummary: mode === "skill-doc" ? buildSkillSummaryFromRecord(pageRecord) : undefined,
173
- spaceId,
174
- title,
175
- });
176
-
177
- await writeRemoteRecordsThenCache({
178
- authToken,
179
- db,
180
- fallbackFetchImpl,
181
- fetchImpl,
182
- records: [
183
- { dbKey, record: pageRecord, serverUrl },
184
- { dbKey: spaceKey, record: spaceRecord, serverUrl },
185
- ],
186
- userId,
187
- });
188
-
189
- output.write(
190
- `${JSON.stringify(
191
- shouldOutputJson ? summary : { ...summary, ok: true },
192
- null,
193
- 2
194
- )}\n`
195
- );
196
- return 0;
197
- } catch (error) {
198
- output.write(
199
- `[nolo] ${mode} create failed: ${
200
- error instanceof Error ? error.message : String(error)
201
- }\n`
202
- );
203
- return 1;
204
- }
205
- }
206
-
207
- export async function runDocCreateCommand(
208
- args: string[],
209
- deps: AgentCommandDeps = {}
210
- ) {
211
- return runBasePageCreateCommand(args, deps, "doc");
212
- }
213
-
214
- export async function runSkillDocCreateCommand(
215
- args: string[],
216
- deps: AgentCommandDeps = {}
217
- ) {
218
- return runBasePageCreateCommand(args, deps, "skill-doc");
219
- }
@@ -1,167 +0,0 @@
1
- import { parseSkillDocProtocol, resolvePageSkillMetadata } from "./ai/skills/skillDocProtocol";
2
- import { getReadableCliDb, type AgentCommandDeps } from "./agentCommandSupport";
3
- import { deleteDbRecord, readDbRecord, writeDbRecord } from "./agentRecordHelpers";
4
- import {
5
- parseUserIdFromAuthToken,
6
- resolveAuthToken,
7
- resolveServerCandidates,
8
- resolveServerUrl,
9
- } from "./cliEnvHelpers";
10
- import { readRecordWithCandidates } from "./hybridReadHelpers";
11
- import { buildDetachedDocSpaceRecord, readOption } from "./pageWriteHelpers";
12
-
13
- function usage(command: "doc" | "skill-doc") {
14
- return [
15
- "Usage:",
16
- ` nolo ${command} delete --key <pageKey>`,
17
- "",
18
- ].join("\n");
19
- }
20
-
21
- async function readRecord(args: {
22
- authToken: string;
23
- db: Awaited<ReturnType<typeof getReadableCliDb>>;
24
- dbKey: string;
25
- fetchImpl: typeof fetch;
26
- fallbackFetchImpl?: typeof fetch;
27
- serverCandidates: string[];
28
- }) {
29
- return readRecordWithCandidates<Record<string, any>>({
30
- db: args.db,
31
- dbKey: args.dbKey,
32
- serverCandidates: args.serverCandidates,
33
- readRemote: async (serverUrl, dbKey) =>
34
- readDbRecord({
35
- authToken: args.authToken,
36
- dbKey,
37
- fallbackFetchImpl: args.fallbackFetchImpl,
38
- fetchImpl: args.fetchImpl,
39
- serverUrl,
40
- }),
41
- });
42
- }
43
-
44
- export async function runBasePageDeleteCommand(
45
- args: string[],
46
- deps: AgentCommandDeps,
47
- mode: "doc" | "skill-doc"
48
- ) {
49
- const env = deps.env ?? process.env;
50
- const output = deps.output ?? process.stdout;
51
- const dbKey = readOption(args, "--key");
52
- if (!dbKey || dbKey === "-h" || dbKey === "--help") {
53
- output.write(`${usage(mode)}\n`);
54
- return dbKey ? 0 : 1;
55
- }
56
-
57
- const authToken = resolveAuthToken(args, env);
58
- const userId = parseUserIdFromAuthToken(authToken);
59
- if (!authToken || !userId) {
60
- output.write(`[nolo] ${mode} delete requires an auth token with userId. Run \`nolo login\`.\n`);
61
- return 1;
62
- }
63
-
64
- const db = deps.db ?? await getReadableCliDb(output);
65
- const fetchImpl = deps.fetchImpl ?? fetch;
66
- const fallbackFetchImpl = deps.fallbackFetchImpl;
67
- const defaultServerUrl = resolveServerUrl(args, env);
68
- const serverCandidates = resolveServerCandidates(args, env, defaultServerUrl);
69
-
70
- try {
71
- const existing = await readRecord({
72
- authToken,
73
- db,
74
- dbKey,
75
- fetchImpl,
76
- fallbackFetchImpl,
77
- serverCandidates,
78
- });
79
-
80
- if (mode === "doc" && existing?.meta?.kind === "skill") {
81
- throw new Error(`target page is a skill doc; use \`nolo skill-doc delete --key ${dbKey}\``);
82
- }
83
- if (mode === "skill-doc") {
84
- const parsed = parseSkillDocProtocol(
85
- typeof existing?.content === "string" ? existing.content : "",
86
- existing?.meta,
87
- existing?.tools
88
- );
89
- const metadata = resolvePageSkillMetadata({
90
- ...existing,
91
- content: parsed.content,
92
- });
93
- if (!metadata?.skillConfig) {
94
- throw new Error(`target page is not a skill doc: ${dbKey}`);
95
- }
96
- }
97
-
98
- const spaceId =
99
- typeof existing?.spaceId === "string" && existing.spaceId.trim()
100
- ? existing.spaceId
101
- : null;
102
- const spaceKey = spaceId ? `space-${spaceId}` : null;
103
- let pendingSpaceRecord: Record<string, any> | null = null;
104
-
105
- if (spaceId && spaceKey) {
106
- const existingSpaceRecord = await readRecord({
107
- authToken,
108
- db,
109
- dbKey: spaceKey,
110
- fetchImpl,
111
- fallbackFetchImpl,
112
- serverCandidates,
113
- });
114
- const spaceRecord = buildDetachedDocSpaceRecord({
115
- contentKey: dbKey,
116
- existingSpaceRecord,
117
- spaceId,
118
- });
119
- pendingSpaceRecord = spaceRecord;
120
- await writeDbRecord({
121
- authToken,
122
- dbKey: spaceKey,
123
- fallbackFetchImpl,
124
- fetchImpl,
125
- record: spaceRecord,
126
- serverUrl: defaultServerUrl,
127
- userId,
128
- });
129
- }
130
-
131
- const deleteStatus = await deleteDbRecord({
132
- authToken,
133
- dbKey,
134
- fallbackFetchImpl,
135
- fetchImpl,
136
- serverUrl: defaultServerUrl,
137
- userId,
138
- });
139
- if (spaceKey && pendingSpaceRecord) {
140
- await db.put(spaceKey, pendingSpaceRecord);
141
- }
142
- await db.batch([{ type: "del", key: dbKey }]);
143
- output.write(`${JSON.stringify({ ok: true, dbKey, status: deleteStatus, spaceKey }, null, 2)}\n`);
144
- return 0;
145
- } catch (error) {
146
- output.write(
147
- `[nolo] ${mode} delete failed: ${
148
- error instanceof Error ? error.message : String(error)
149
- }\n`
150
- );
151
- return 1;
152
- }
153
- }
154
-
155
- export async function runDocDeleteCommand(
156
- args: string[],
157
- deps: AgentCommandDeps = {}
158
- ) {
159
- return runBasePageDeleteCommand(args, deps, "doc");
160
- }
161
-
162
- export async function runSkillDocDeleteCommand(
163
- args: string[],
164
- deps: AgentCommandDeps = {}
165
- ) {
166
- return runBasePageDeleteCommand(args, deps, "skill-doc");
167
- }
@@ -1,151 +0,0 @@
1
- import { parseSkillDocProtocol, resolvePageSkillMetadata } from "./ai/skills/skillDocProtocol";
2
- import { getReadableCliDb, type AgentCommandDeps } from "./agentCommandSupport";
3
- import { readDbRecord } from "./agentRecordHelpers";
4
- import {
5
- resolveAuthToken,
6
- resolveServerCandidates,
7
- resolveServerUrl,
8
- } from "./cliEnvHelpers";
9
- import { readRecordWithCandidates } from "./hybridReadHelpers";
10
-
11
- type PageReadResult = {
12
- baseUrl: string;
13
- dbKey: string;
14
- title: string | null;
15
- spaceId: string | null;
16
- type: string | null;
17
- content: string | null;
18
- meta: Record<string, any> | null;
19
- record: Record<string, any>;
20
- };
21
-
22
- function usage(command: "doc" | "skill-doc") {
23
- return [
24
- "Usage:",
25
- ` nolo ${command} read <pageKey>`,
26
- "",
27
- ].join("\n");
28
- }
29
-
30
- async function readPageRecord(args: {
31
- db: Awaited<ReturnType<typeof getReadableCliDb>>;
32
- authToken: string;
33
- dbKey: string;
34
- fetchImpl: typeof fetch;
35
- fallbackFetchImpl?: typeof fetch;
36
- serverCandidates: string[];
37
- }) {
38
- return await 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
- function buildPageReadResult(baseUrl: string, dbKey: string, record: Record<string, any>): PageReadResult {
54
- return {
55
- baseUrl,
56
- dbKey,
57
- title: record?.title ?? null,
58
- spaceId: record?.spaceId ?? null,
59
- type: record?.type ?? null,
60
- content: typeof record?.content === "string" ? record.content : null,
61
- meta: record?.meta && typeof record.meta === "object" ? record.meta : null,
62
- record,
63
- };
64
- }
65
-
66
- async function runBasePageReadCommand(
67
- args: string[],
68
- deps: AgentCommandDeps,
69
- mode: "doc" | "skill-doc"
70
- ) {
71
- const env = deps.env ?? process.env;
72
- const output = deps.output ?? process.stdout;
73
- const raw = args[0]?.trim();
74
- if (!raw || raw === "-h" || raw === "--help") {
75
- output.write(`${usage(mode)}\n`);
76
- return raw ? 0 : 1;
77
- }
78
-
79
- const authToken = resolveAuthToken(args, env);
80
- if (!authToken) {
81
- output.write(`[nolo] ${mode} read requires an auth token. Run \`nolo login\` or set AUTH_TOKEN.\n`);
82
- return 1;
83
- }
84
-
85
- const db = deps.db ?? await getReadableCliDb(output);
86
- const fetchImpl = deps.fetchImpl ?? fetch;
87
- const fallbackFetchImpl = deps.fallbackFetchImpl;
88
- const defaultServerUrl = resolveServerUrl(args, env);
89
- const serverCandidates = resolveServerCandidates(args, env, defaultServerUrl);
90
-
91
- try {
92
- const record = await readPageRecord({
93
- db,
94
- authToken,
95
- dbKey: raw,
96
- fetchImpl,
97
- fallbackFetchImpl,
98
- serverCandidates,
99
- });
100
- const result = buildPageReadResult(defaultServerUrl, raw, record);
101
-
102
- if (mode === "doc") {
103
- output.write(`${JSON.stringify(result, null, 2)}\n`);
104
- return 0;
105
- }
106
-
107
- const parsed = parseSkillDocProtocol(
108
- typeof record?.content === "string" ? record.content : "",
109
- record?.meta,
110
- record?.tools
111
- );
112
- const meta = resolvePageSkillMetadata(record);
113
- const skillConfig = meta?.skillConfig ?? null;
114
-
115
- output.write(
116
- `${JSON.stringify(
117
- {
118
- ...result,
119
- isSkill: Boolean(meta?.kind === "skill" || skillConfig),
120
- body: typeof parsed.content === "string" ? parsed.content : "",
121
- meta: meta ?? result.meta,
122
- skillConfig,
123
- },
124
- null,
125
- 2
126
- )}\n`
127
- );
128
- return 0;
129
- } catch (error) {
130
- output.write(
131
- `[nolo] ${mode} read failed: ${
132
- error instanceof Error ? error.message : String(error)
133
- }\n`
134
- );
135
- return 1;
136
- }
137
- }
138
-
139
- export async function runDocReadCommand(
140
- args: string[],
141
- deps: AgentCommandDeps = {}
142
- ) {
143
- return runBasePageReadCommand(args, deps, "doc");
144
- }
145
-
146
- export async function runSkillDocReadCommand(
147
- args: string[],
148
- deps: AgentCommandDeps = {}
149
- ) {
150
- return runBasePageReadCommand(args, deps, "skill-doc");
151
- }