nolo-cli 0.1.33 → 0.1.35

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 (84) hide show
  1. package/README.md +15 -5
  2. package/agent-runtime/agentRecordConfig.ts +8 -0
  3. package/agent-runtime/hostAdapter.ts +9 -1
  4. package/agent-runtime/index.ts +10 -0
  5. package/agent-runtime/localLoop.ts +49 -2
  6. package/agent-runtime/localToolPolicy.ts +71 -22
  7. package/agent-runtime/localWorkspaceTools.ts +5 -2
  8. package/agent-runtime/openAiCompatibleProvider.ts +7 -3
  9. package/agent-runtime/openAiCompatibleProviderConfig.ts +15 -26
  10. package/agent-runtime/platformChatProvider.ts +48 -71
  11. package/agent-runtime/providerResolution.ts +242 -0
  12. package/agent-runtime/runtimeToolPolicy.ts +33 -0
  13. package/agent-runtime/shellCommandPolicy.ts +120 -0
  14. package/agentCommandSupport.ts +4 -0
  15. package/agentInternalCommandEntries.ts +2 -0
  16. package/agentListCommands.ts +74 -12
  17. package/agentListHelpers.ts +56 -1
  18. package/agentPullCommand.ts +6 -11
  19. package/agentRecordCommands.ts +87 -2
  20. package/agentRecordHelpers.ts +132 -9
  21. package/agentRuntimeLocal.ts +3 -0
  22. package/ai/tools/toolNameAliases.ts +70 -0
  23. package/cli/agentCommandSupport.ts +4 -0
  24. package/cli/agentInternalCommandEntries.ts +2 -0
  25. package/cli/agentListCommands.ts +74 -12
  26. package/cli/agentListHelpers.ts +56 -1
  27. package/cli/agentPullCommand.ts +6 -11
  28. package/cli/agentRecordCommands.ts +87 -2
  29. package/cli/agentRecordHelpers.ts +132 -9
  30. package/cli/agentRuntimeLocal.ts +3 -0
  31. package/cli/cliCommandDispatch.ts +2 -2
  32. package/cli/cliEnvHelpers.ts +80 -12
  33. package/cli/cliSpaceHelpers.ts +39 -0
  34. package/cli/client/agentRun.ts +1 -0
  35. package/cli/client/localRuntimeAdapter.ts +44 -7
  36. package/cli/commandRegistry.ts +2 -2
  37. package/cli/connectorWebSocketTarget.ts +10 -3
  38. package/cli/dialogCommands.ts +446 -0
  39. package/cli/dialogInternalCommandEntries.ts +13 -0
  40. package/cli/globalRecordOperations.ts +258 -0
  41. package/cli/internalCommandEntries.ts +2 -0
  42. package/cli/localRuntimeAuthority.ts +182 -0
  43. package/cli/localRuntimeDb.ts +2 -4
  44. package/cli/machineCommands.ts +1 -1
  45. package/cli/machineWsRunDispatch.ts +29 -12
  46. package/cli/machineWsSession.ts +2 -0
  47. package/cli/offlineMarxistsAgentCommand.ts +1 -1
  48. package/cli/runtimeDoctorCommands.ts +65 -9
  49. package/cli/tableCommands.ts +1 -1
  50. package/cli/taskRunCommand.ts +1 -1
  51. package/cliCommandDispatch.ts +2 -2
  52. package/cliEnvHelpers.ts +80 -12
  53. package/cliSpaceHelpers.ts +39 -0
  54. package/client/agentRun.ts +1 -0
  55. package/client/localProviderResolver.test.ts +26 -2
  56. package/client/localRuntimeAdapter.test.ts +287 -3
  57. package/client/localRuntimeAdapter.ts +44 -7
  58. package/commandRegistry.ts +2 -2
  59. package/connectorWebSocketTarget.ts +10 -3
  60. package/database/server/authorityStoreTypes.ts +31 -0
  61. package/database/server/cliAuthorityBrokerClient.ts +227 -0
  62. package/database/server/cliAuthorityBrokerServer.ts +283 -0
  63. package/database/server/cliAuthorityBrokerTypes.ts +43 -0
  64. package/database/server/cliAuthorityStoreDriver.ts +98 -0
  65. package/database/server/legacyServerDb.ts +58 -0
  66. package/database/server/levelAuthorityStore.ts +95 -0
  67. package/database/tombstones.ts +52 -0
  68. package/database/userDataMerge.ts +95 -0
  69. package/dialogCommands.ts +446 -0
  70. package/dialogInternalCommandEntries.ts +13 -0
  71. package/globalRecordOperations.ts +258 -0
  72. package/internalCommandEntries.ts +2 -0
  73. package/localRuntimeAuthority.ts +182 -0
  74. package/localRuntimeDb.ts +2 -4
  75. package/machineCommands.ts +1 -1
  76. package/machineWsRunDispatch.ts +29 -12
  77. package/machineWsSession.ts +2 -0
  78. package/offlineMarxistsAgentCommand.ts +1 -1
  79. package/package.json +24 -4
  80. package/runtimeDoctorCommands.ts +65 -9
  81. package/tableCommands.ts +1 -1
  82. package/taskRunCommand.ts +1 -1
  83. package/database/server/db.ts +0 -118
  84. package/database/server/ensureDbOpen.ts +0 -12
@@ -1,4 +1,10 @@
1
1
  import { resolveAgentRuntimeDecision } from "./agent-runtime/runtimeDecision";
2
+ import {
3
+ resolveCliAuthorityBrokerEndpoint,
4
+ resolveCliAuthorityBrokerHealthPath,
5
+ resolveCliAuthorityBrokerMetadataPath,
6
+ resolveCliAuthorityStoreDriver,
7
+ } from "./database/server/cliAuthorityStoreDriver";
2
8
  import {
3
9
  type AgentCommandDeps,
4
10
  type LocalRuntimeProbeResult,
@@ -39,23 +45,57 @@ function detectProviderLabel(env: EnvLike) {
39
45
  async function defaultLocalRuntimeProbe(env: EnvLike): Promise<LocalRuntimeProbeResult> {
40
46
  const { resolveCliLocalRuntimeDbPath } = await import("./localRuntimeDb");
41
47
  const dbPath = resolveCliLocalRuntimeDbPath({ env });
48
+ const authorityDriver = resolveCliAuthorityStoreDriver({ env });
49
+ const authorityEndpoint = resolveCliAuthorityBrokerEndpoint({ transport: "tcp", env });
50
+ const authorityMetadataPath = resolveCliAuthorityBrokerMetadataPath({ transport: "tcp", env });
51
+ const authorityHealthPath = resolveCliAuthorityBrokerHealthPath({ transport: "tcp", env });
42
52
  const agentKey = readLocalAgentKey(env);
43
53
  try {
44
54
  const { getDefaultCliLocalRuntimeDb } = await import("./localRuntimeDb");
45
- const db = await getDefaultCliLocalRuntimeDb();
55
+ const db = await getDefaultCliLocalRuntimeDb({ env });
46
56
  if (!agentKey) {
47
- return { ok: true, dbPath, agentFound: false };
57
+ return {
58
+ ok: true,
59
+ dbPath,
60
+ authorityDriver,
61
+ authorityEndpoint,
62
+ authorityMetadataPath,
63
+ authorityHealthPath,
64
+ agentFound: false,
65
+ };
48
66
  }
49
67
  try {
50
- await db.get(agentKey);
51
- return { ok: true, dbPath, agentFound: true, agentKey };
68
+ const record = await db.get(agentKey);
69
+ return {
70
+ ok: true,
71
+ dbPath,
72
+ authorityDriver,
73
+ authorityEndpoint,
74
+ authorityMetadataPath,
75
+ authorityHealthPath,
76
+ agentFound: record != null,
77
+ agentKey,
78
+ };
52
79
  } catch {
53
- return { ok: true, dbPath, agentFound: false, agentKey };
80
+ return {
81
+ ok: true,
82
+ dbPath,
83
+ authorityDriver,
84
+ authorityEndpoint,
85
+ authorityMetadataPath,
86
+ authorityHealthPath,
87
+ agentFound: false,
88
+ agentKey,
89
+ };
54
90
  }
55
91
  } catch (error) {
56
92
  return {
57
93
  ok: false,
58
94
  dbPath,
95
+ authorityDriver,
96
+ authorityEndpoint,
97
+ authorityMetadataPath,
98
+ authorityHealthPath,
59
99
  agentFound: false,
60
100
  ...(agentKey ? { agentKey } : {}),
61
101
  error: error instanceof Error ? error.message : String(error),
@@ -64,13 +104,13 @@ async function defaultLocalRuntimeProbe(env: EnvLike): Promise<LocalRuntimeProbe
64
104
  }
65
105
 
66
106
  export async function runDoctorRuntimeCommand(
67
- _args: string[],
107
+ args: string[],
68
108
  deps: AgentCommandDeps = {}
69
109
  ) {
70
110
  const env = deps.env ?? process.env;
71
111
  const output = deps.output ?? process.stdout;
72
- const authToken = resolveAuthToken(env);
73
- const serverUrl = resolveServerUrl(env);
112
+ const authToken = resolveAuthToken(args, env);
113
+ const serverUrl = resolveServerUrl(args, env);
74
114
  const localProbe = await (deps.localRuntimeProbe ?? defaultLocalRuntimeProbe)(env);
75
115
  const hasLocalAgentConfig = detectLocalAgentConfig(env) && localProbe.ok && localProbe.agentFound;
76
116
  const hasLocalProvider = detectLocalProvider(env);
@@ -88,13 +128,29 @@ export async function runDoctorRuntimeCommand(
88
128
  hasLocalPersistence: true,
89
129
  missingLocalCapabilities,
90
130
  requiresServer: false,
91
- serverFallbackAvailable: Boolean(authToken || env.NOLO_SERVER || env.BASE_URL),
131
+ serverFallbackAvailable: Boolean(
132
+ authToken ||
133
+ args.includes("--server") ||
134
+ args.includes("--server-url") ||
135
+ env.NOLO_SERVER ||
136
+ env.BASE_URL
137
+ ),
92
138
  });
93
139
 
94
140
  output.write(`Runtime: ${decision.mode}\n`);
95
141
  output.write(`Reason: ${decision.reason}\n`);
96
142
  output.write(`LevelDB: ${localProbe.ok ? "ok" : "failed"}\n`);
97
143
  output.write(`DB path: ${localProbe.dbPath}\n`);
144
+ output.write(`Authority driver: ${localProbe.authorityDriver ?? "unknown"}\n`);
145
+ if (localProbe.authorityEndpoint) {
146
+ output.write(`Authority endpoint: ${localProbe.authorityEndpoint}\n`);
147
+ }
148
+ if (localProbe.authorityMetadataPath) {
149
+ output.write(`Authority metadata: ${localProbe.authorityMetadataPath}\n`);
150
+ }
151
+ if (localProbe.authorityHealthPath) {
152
+ output.write(`Authority health: ${localProbe.authorityHealthPath}\n`);
153
+ }
98
154
  if (!localProbe.ok && localProbe.error) {
99
155
  output.write(`DB error: ${localProbe.error}\n`);
100
156
  }
package/tableCommands.ts CHANGED
@@ -80,7 +80,7 @@ function resolveServerUrl(args: string[], env: EnvLike): string {
80
80
 
81
81
  function resolveAuthToken(args: string[], env: EnvLike): string {
82
82
  return (
83
- readOption(args, "--api-key") ||
83
+ readOption(args, "--machine-key") ||
84
84
  readOption(args, "--token") ||
85
85
  env.AUTH_TOKEN ||
86
86
  env.AUTH ||
package/taskRunCommand.ts CHANGED
@@ -82,7 +82,7 @@ function resolveServerUrl(args: string[], env: EnvLike) {
82
82
 
83
83
  function resolveAuthToken(args: string[], env: EnvLike) {
84
84
  return (
85
- readOption(args, "--api-key") ||
85
+ readOption(args, "--machine-key") ||
86
86
  readOption(args, "--token") ||
87
87
  env.NOLO_TASK_RUN_TOKEN ||
88
88
  env.NOLO_MACHINE_API_KEY ||
@@ -1,118 +0,0 @@
1
- // 文件路径: packages/database/server/db.ts
2
-
3
- import { Level } from "level";
4
- import path from "path";
5
- import fs from "fs";
6
- import { ensureDbOpen } from "./ensureDbOpen";
7
- import { resolveServerDbPath } from "./dbPath";
8
-
9
- const DB_PATH = resolveServerDbPath();
10
-
11
- // 确保目录存在
12
- if (!fs.existsSync(path.dirname(DB_PATH))) {
13
- fs.mkdirSync(path.dirname(DB_PATH), { recursive: true });
14
- }
15
-
16
- console.log("数据库配置:");
17
- console.log("- 当前工作目录:", process.cwd());
18
- console.log("- 数据库路径:", DB_PATH);
19
-
20
- // 安全 JSON 编码:解码失败时返回 null 而非抛异常,防止损坏记录导致进程崩溃
21
- const safeJsonEncoding = {
22
- name: "safe-json",
23
- format: "utf8" as const,
24
- encode: (data: any) => JSON.stringify(data),
25
- decode: (data: string) => {
26
- try {
27
- return JSON.parse(data);
28
- } catch {
29
- console.warn("[LevelDB] Corrupted value:", data?.substring?.(0, 60));
30
- return null;
31
- }
32
- },
33
- };
34
-
35
- export function isServerDbLockError(error: unknown): boolean {
36
- const queue: unknown[] = [error];
37
- const seen = new Set<unknown>();
38
-
39
- while (queue.length > 0) {
40
- const current = queue.shift();
41
- if (!current || seen.has(current)) continue;
42
- seen.add(current);
43
-
44
- const text = `${(current as any)?.code ?? ""} ${(current as any)?.message ?? current}`;
45
- if (/LEVEL_LOCKED|Resource temporarily unavailable|\/LOCK|LOCK:/.test(text)) {
46
- return true;
47
- }
48
-
49
- if ((current as any)?.cause) queue.push((current as any).cause);
50
- if (Array.isArray((current as any)?.errors)) {
51
- queue.push(...(current as any).errors);
52
- }
53
- }
54
-
55
- return false;
56
- }
57
-
58
- // 单例实例:挂在 globalThis 上,--hot 模式下模块重新求值时复用同一实例,避免 LevelDB 锁冲突
59
- if (!(globalThis as any).__serverDb) {
60
- (globalThis as any).__serverDb = new Level<string, any>(DB_PATH, {
61
- valueEncoding: safeJsonEncoding,
62
- });
63
- }
64
- const serverDb: Level<string, any> = (globalThis as any).__serverDb;
65
-
66
- console.log("- LevelDB实际路径:", serverDb.location);
67
-
68
- // ✅ 保留默认导出:兼容现有的 import serverDb from "./db"
69
- export default serverDb;
70
-
71
- // 具名导出:需要的时候可以引用
72
- export { serverDb };
73
-
74
- /**
75
- * 确保数据库处于 open 状态。
76
- * - 已 open / opening:直接返回
77
- * - 其他状态:尝试 open,一旦失败抛错
78
- */
79
- export async function ensureServerDbOpen() {
80
- const status = (serverDb as any).status;
81
- if (status === "open") return;
82
-
83
- try {
84
- await ensureDbOpen(serverDb);
85
- if (status !== "opening") {
86
- console.log("✅ LevelDB 已打开");
87
- }
88
- } catch (err) {
89
- if (isServerDbLockError(err)) {
90
- console.error("❌ 打开 LevelDB 失败: 数据库已被其他进程占用");
91
- } else {
92
- console.error("❌ 打开 LevelDB 失败:", err);
93
- }
94
- throw err;
95
- }
96
- }
97
-
98
- /**
99
- * 兼容入口调用:启动时显式 open 一次
100
- */
101
- export async function openServerDb() {
102
- return ensureServerDbOpen();
103
- }
104
-
105
- /**
106
- * 优雅关机时关闭 DB
107
- */
108
- export async function closeServerDb() {
109
- const status = (serverDb as any).status;
110
- if (status !== "open") return;
111
-
112
- try {
113
- await serverDb.close();
114
- console.log("✅ LevelDB 已关闭");
115
- } catch (err) {
116
- console.error("❌ 关闭 LevelDB 失败:", err);
117
- }
118
- }
@@ -1,12 +0,0 @@
1
- export type DbWithOpenStatus = {
2
- status?: string | null;
3
- open(): Promise<unknown>;
4
- };
5
-
6
- export async function ensureDbOpen(db: DbWithOpenStatus) {
7
- if (db.status === "open") {
8
- return;
9
- }
10
-
11
- await db.open();
12
- }