nolo-cli 0.1.34 → 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.
- package/README.md +11 -1
- package/agent-runtime/localToolPolicy.ts +1 -1
- package/agent-runtime/localWorkspaceTools.ts +5 -2
- package/agent-runtime/providerResolution.ts +1 -3
- package/agentCommandSupport.ts +4 -0
- package/agentListCommands.ts +73 -11
- package/agentListHelpers.ts +56 -1
- package/agentRecordHelpers.ts +45 -5
- package/cli/agentCommandSupport.ts +4 -0
- package/cli/agentListCommands.ts +73 -11
- package/cli/agentListHelpers.ts +56 -1
- package/cli/agentRecordHelpers.ts +45 -5
- package/cli/cliSpaceHelpers.ts +39 -0
- package/cli/connectorWebSocketTarget.ts +10 -3
- package/cli/dialogCommands.ts +446 -0
- package/cli/dialogInternalCommandEntries.ts +13 -0
- package/cli/globalRecordOperations.ts +258 -0
- package/cli/internalCommandEntries.ts +2 -0
- package/cli/localRuntimeAuthority.ts +182 -0
- package/cli/localRuntimeDb.ts +2 -4
- package/cli/machineWsRunDispatch.ts +0 -3
- package/cli/machineWsSession.ts +2 -0
- package/cli/runtimeDoctorCommands.ts +55 -5
- package/cliSpaceHelpers.ts +39 -0
- package/connectorWebSocketTarget.ts +10 -3
- package/database/server/cliAuthorityBrokerClient.ts +227 -0
- package/database/server/cliAuthorityBrokerServer.ts +283 -0
- package/database/server/cliAuthorityBrokerTypes.ts +43 -0
- package/database/server/cliAuthorityStoreDriver.ts +98 -0
- package/database/server/levelAuthorityStore.ts +46 -26
- package/database/tombstones.ts +52 -0
- package/database/userDataMerge.ts +95 -0
- package/dialogCommands.ts +446 -0
- package/dialogInternalCommandEntries.ts +13 -0
- package/globalRecordOperations.ts +258 -0
- package/internalCommandEntries.ts +2 -0
- package/localRuntimeAuthority.ts +182 -0
- package/localRuntimeDb.ts +2 -4
- package/machineWsRunDispatch.ts +0 -3
- package/machineWsSession.ts +2 -0
- package/package.json +18 -6
- package/runtimeDoctorCommands.ts +55 -5
- package/database/server/db.ts +0 -99
- package/database/server/ensureDbOpen.ts +0 -12
- package/database/server/memoryAuthorityStore.ts +0 -133
- package/database/server/serverStoreFactory.ts +0 -118
package/database/server/db.ts
DELETED
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
// 文件路径: packages/database/server/db.ts
|
|
2
|
-
|
|
3
|
-
import { ensureDbOpen } from "./ensureDbOpen";
|
|
4
|
-
import { resolveServerDbPath } from "./dbPath";
|
|
5
|
-
import type { LegacyServerDb } from "./legacyServerDb";
|
|
6
|
-
import type { AuthorityStore } from "./authorityStoreTypes";
|
|
7
|
-
import { getOrCreateServerStoreRuntime } from "./serverStoreFactory";
|
|
8
|
-
|
|
9
|
-
const DB_PATH = resolveServerDbPath();
|
|
10
|
-
|
|
11
|
-
console.log("数据库配置:");
|
|
12
|
-
console.log("- 当前工作目录:", process.cwd());
|
|
13
|
-
console.log("- 数据库路径:", DB_PATH);
|
|
14
|
-
|
|
15
|
-
export function isServerDbLockError(error: unknown): boolean {
|
|
16
|
-
const queue: unknown[] = [error];
|
|
17
|
-
const seen = new Set<unknown>();
|
|
18
|
-
|
|
19
|
-
while (queue.length > 0) {
|
|
20
|
-
const current = queue.shift();
|
|
21
|
-
if (!current || seen.has(current)) continue;
|
|
22
|
-
seen.add(current);
|
|
23
|
-
|
|
24
|
-
const text = `${(current as any)?.code ?? ""} ${(current as any)?.message ?? current}`;
|
|
25
|
-
if (/LEVEL_LOCKED|Resource temporarily unavailable|\/LOCK|LOCK:/.test(text)) {
|
|
26
|
-
return true;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
if ((current as any)?.cause) queue.push((current as any).cause);
|
|
30
|
-
if (Array.isArray((current as any)?.errors)) {
|
|
31
|
-
queue.push(...(current as any).errors);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return false;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const {
|
|
39
|
-
authorityStore,
|
|
40
|
-
serverDb,
|
|
41
|
-
}: { authorityStore: AuthorityStore; serverDb: LegacyServerDb } =
|
|
42
|
-
getOrCreateServerStoreRuntime(DB_PATH);
|
|
43
|
-
|
|
44
|
-
console.log("- LevelDB实际路径:", serverDb.location);
|
|
45
|
-
|
|
46
|
-
// ✅ 保留默认导出:兼容现有的 import serverDb from "./db"
|
|
47
|
-
export default serverDb;
|
|
48
|
-
|
|
49
|
-
// 具名导出:需要的时候可以引用
|
|
50
|
-
export { serverDb };
|
|
51
|
-
export function getServerAuthorityStore() {
|
|
52
|
-
return authorityStore;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* 确保数据库处于 open 状态。
|
|
57
|
-
* - 已 open / opening:直接返回
|
|
58
|
-
* - 其他状态:尝试 open,一旦失败抛错
|
|
59
|
-
*/
|
|
60
|
-
export async function ensureServerDbOpen() {
|
|
61
|
-
const status = authorityStore.status;
|
|
62
|
-
if (status === "open") return;
|
|
63
|
-
|
|
64
|
-
try {
|
|
65
|
-
await ensureDbOpen(authorityStore);
|
|
66
|
-
if (status !== "opening") {
|
|
67
|
-
console.log("✅ LevelDB 已打开");
|
|
68
|
-
}
|
|
69
|
-
} catch (err) {
|
|
70
|
-
if (isServerDbLockError(err)) {
|
|
71
|
-
console.error("❌ 打开 LevelDB 失败: 数据库已被其他进程占用");
|
|
72
|
-
} else {
|
|
73
|
-
console.error("❌ 打开 LevelDB 失败:", err);
|
|
74
|
-
}
|
|
75
|
-
throw err;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* 兼容入口调用:启动时显式 open 一次
|
|
81
|
-
*/
|
|
82
|
-
export async function openServerDb() {
|
|
83
|
-
return ensureServerDbOpen();
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* 优雅关机时关闭 DB
|
|
88
|
-
*/
|
|
89
|
-
export async function closeServerDb() {
|
|
90
|
-
const status = authorityStore.status;
|
|
91
|
-
if (status !== "open") return;
|
|
92
|
-
|
|
93
|
-
try {
|
|
94
|
-
await authorityStore.close();
|
|
95
|
-
console.log("✅ LevelDB 已关闭");
|
|
96
|
-
} catch (err) {
|
|
97
|
-
console.error("❌ 关闭 LevelDB 失败:", err);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
AuthorityBatchOperation,
|
|
3
|
-
AuthorityBatchWriter,
|
|
4
|
-
AuthorityIteratorOptions,
|
|
5
|
-
AuthorityStore,
|
|
6
|
-
} from "./authorityStoreTypes";
|
|
7
|
-
|
|
8
|
-
type MemoryEntry = {
|
|
9
|
-
key: string;
|
|
10
|
-
value: unknown;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
const createNotFoundError = () => {
|
|
14
|
-
const error = new Error("NotFound") as Error & { notFound: true };
|
|
15
|
-
error.notFound = true;
|
|
16
|
-
return error;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
class MemoryAuthorityBacking {
|
|
20
|
-
readonly location: string;
|
|
21
|
-
status: "closed" | "open" = "closed";
|
|
22
|
-
private readonly data = new Map<string, unknown>();
|
|
23
|
-
|
|
24
|
-
constructor(location: string) {
|
|
25
|
-
this.location = location;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
async open() {
|
|
29
|
-
this.status = "open";
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
async close() {
|
|
33
|
-
this.status = "closed";
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
async get<T = any>(key: string): Promise<T> {
|
|
37
|
-
if (!this.data.has(key)) {
|
|
38
|
-
throw createNotFoundError();
|
|
39
|
-
}
|
|
40
|
-
return this.data.get(key) as T;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
async put(key: string, value: unknown) {
|
|
44
|
-
this.data.set(key, value);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
async del(key: string) {
|
|
48
|
-
this.data.delete(key);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
async batchWrite(ops: AuthorityBatchOperation[]) {
|
|
52
|
-
for (const op of ops) {
|
|
53
|
-
if (op.type === "put") {
|
|
54
|
-
this.data.set(op.key, op.value);
|
|
55
|
-
} else {
|
|
56
|
-
this.data.delete(op.key);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
createBatch(): AuthorityBatchWriter {
|
|
62
|
-
const buffered: AuthorityBatchOperation[] = [];
|
|
63
|
-
return {
|
|
64
|
-
put(key: string, value: unknown) {
|
|
65
|
-
buffered.push({ type: "put", key, value });
|
|
66
|
-
},
|
|
67
|
-
del(key: string) {
|
|
68
|
-
buffered.push({ type: "del", key });
|
|
69
|
-
},
|
|
70
|
-
write: async () => {
|
|
71
|
-
await this.batchWrite(buffered);
|
|
72
|
-
},
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
async *iterator(
|
|
77
|
-
options: AuthorityIteratorOptions = {}
|
|
78
|
-
): AsyncIterableIterator<[string, unknown]> {
|
|
79
|
-
const entries: MemoryEntry[] = Array.from(this.data.entries())
|
|
80
|
-
.sort(([left], [right]) => left.localeCompare(right))
|
|
81
|
-
.map(([key, value]) => ({ key, value }));
|
|
82
|
-
|
|
83
|
-
if (options.reverse) {
|
|
84
|
-
entries.reverse();
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
for (const entry of entries) {
|
|
88
|
-
if (options.gte && entry.key < options.gte) continue;
|
|
89
|
-
if (options.lte && entry.key > options.lte) continue;
|
|
90
|
-
if (options.lt && entry.key >= options.lt) continue;
|
|
91
|
-
yield [entry.key, entry.value];
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
export function createMemoryAuthorityStore(
|
|
97
|
-
location = ":memory:"
|
|
98
|
-
): AuthorityStore {
|
|
99
|
-
const backing = new MemoryAuthorityBacking(location);
|
|
100
|
-
|
|
101
|
-
return {
|
|
102
|
-
get location() {
|
|
103
|
-
return backing.location;
|
|
104
|
-
},
|
|
105
|
-
get status() {
|
|
106
|
-
return backing.status;
|
|
107
|
-
},
|
|
108
|
-
async open() {
|
|
109
|
-
await backing.open();
|
|
110
|
-
},
|
|
111
|
-
async close() {
|
|
112
|
-
await backing.close();
|
|
113
|
-
},
|
|
114
|
-
async get<T = any>(key: string) {
|
|
115
|
-
return backing.get<T>(key);
|
|
116
|
-
},
|
|
117
|
-
async put(key: string, value: unknown) {
|
|
118
|
-
await backing.put(key, value);
|
|
119
|
-
},
|
|
120
|
-
async del(key: string) {
|
|
121
|
-
await backing.del(key);
|
|
122
|
-
},
|
|
123
|
-
async batchWrite(ops: AuthorityBatchOperation[]) {
|
|
124
|
-
await backing.batchWrite(ops);
|
|
125
|
-
},
|
|
126
|
-
createBatch() {
|
|
127
|
-
return backing.createBatch();
|
|
128
|
-
},
|
|
129
|
-
iterator(options: AuthorityIteratorOptions = {}) {
|
|
130
|
-
return backing.iterator(options);
|
|
131
|
-
},
|
|
132
|
-
};
|
|
133
|
-
}
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import fs from "fs";
|
|
2
|
-
import path from "path";
|
|
3
|
-
import { Level } from "level";
|
|
4
|
-
|
|
5
|
-
import type { AuthorityStore } from "./authorityStoreTypes";
|
|
6
|
-
import { createLegacyServerDb, type LegacyServerDb } from "./legacyServerDb";
|
|
7
|
-
import { createLevelAuthorityStore } from "./levelAuthorityStore";
|
|
8
|
-
import { createMemoryAuthorityStore } from "./memoryAuthorityStore";
|
|
9
|
-
|
|
10
|
-
export type ServerStoreDriver = "level" | "memory";
|
|
11
|
-
|
|
12
|
-
export type ServerStoreFactoryEnv = {
|
|
13
|
-
NOLO_SERVER_AUTHORITY_DRIVER?: string | undefined;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export const safeJsonEncoding = {
|
|
17
|
-
name: "safe-json",
|
|
18
|
-
format: "utf8" as const,
|
|
19
|
-
encode: (data: any) => JSON.stringify(data),
|
|
20
|
-
decode: (data: string) => {
|
|
21
|
-
try {
|
|
22
|
-
return JSON.parse(data);
|
|
23
|
-
} catch {
|
|
24
|
-
console.warn("[LevelDB] Corrupted value:", data?.substring?.(0, 60));
|
|
25
|
-
return null;
|
|
26
|
-
}
|
|
27
|
-
},
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
export type ServerStoreRuntime = {
|
|
31
|
-
authorityStore: AuthorityStore;
|
|
32
|
-
serverDb: LegacyServerDb;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
export type ServerStoreFactoryOptions = {
|
|
36
|
-
driver?: ServerStoreDriver;
|
|
37
|
-
env?: ServerStoreFactoryEnv;
|
|
38
|
-
globalScope?: Record<string, unknown>;
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
export function ensureServerDbDirectory(dbPath: string) {
|
|
42
|
-
const dir = path.dirname(dbPath);
|
|
43
|
-
if (!fs.existsSync(dir)) {
|
|
44
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export function createLevelBackedAuthorityStore(dbPath: string): AuthorityStore {
|
|
49
|
-
const levelDb = new Level<string, any>(dbPath, {
|
|
50
|
-
valueEncoding: safeJsonEncoding,
|
|
51
|
-
});
|
|
52
|
-
return createLevelAuthorityStore(levelDb);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export function resolveServerStoreDriver(
|
|
56
|
-
env: ServerStoreFactoryEnv = process.env
|
|
57
|
-
): ServerStoreDriver {
|
|
58
|
-
const rawDriver = env.NOLO_SERVER_AUTHORITY_DRIVER?.trim().toLowerCase();
|
|
59
|
-
if (!rawDriver) return "level";
|
|
60
|
-
if (rawDriver === "level") return "level";
|
|
61
|
-
if (rawDriver === "memory") return "memory";
|
|
62
|
-
throw new Error(`Unsupported server authority store driver: ${rawDriver}`);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export function createAuthorityStoreForDriver(
|
|
66
|
-
driver: ServerStoreDriver,
|
|
67
|
-
dbPath: string
|
|
68
|
-
): AuthorityStore {
|
|
69
|
-
switch (driver) {
|
|
70
|
-
case "level":
|
|
71
|
-
return createLevelBackedAuthorityStore(dbPath);
|
|
72
|
-
case "memory":
|
|
73
|
-
return createMemoryAuthorityStore(dbPath);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export function getOrCreateServerStoreRuntime(
|
|
78
|
-
dbPath: string,
|
|
79
|
-
options: ServerStoreFactoryOptions = {}
|
|
80
|
-
): ServerStoreRuntime {
|
|
81
|
-
const globalScope =
|
|
82
|
-
options.globalScope ?? (globalThis as Record<string, unknown>);
|
|
83
|
-
const driver = options.driver ?? resolveServerStoreDriver(options.env);
|
|
84
|
-
const cachedDriver = globalScope.__serverAuthorityStoreDriver;
|
|
85
|
-
|
|
86
|
-
ensureServerDbDirectory(dbPath);
|
|
87
|
-
|
|
88
|
-
if (
|
|
89
|
-
globalScope.__serverAuthorityStore &&
|
|
90
|
-
typeof cachedDriver === "string" &&
|
|
91
|
-
cachedDriver !== driver
|
|
92
|
-
) {
|
|
93
|
-
throw new Error(
|
|
94
|
-
`Server authority store already initialized with driver ${cachedDriver}, cannot reuse it for ${driver}`
|
|
95
|
-
);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
if (!globalScope.__serverAuthorityStore) {
|
|
99
|
-
globalScope.__serverAuthorityStore = createAuthorityStoreForDriver(
|
|
100
|
-
driver,
|
|
101
|
-
dbPath
|
|
102
|
-
);
|
|
103
|
-
globalScope.__serverAuthorityStoreDriver = driver;
|
|
104
|
-
} else if (!cachedDriver) {
|
|
105
|
-
globalScope.__serverAuthorityStoreDriver = driver;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
const authorityStore = globalScope.__serverAuthorityStore as AuthorityStore;
|
|
109
|
-
|
|
110
|
-
if (!globalScope.__serverDb) {
|
|
111
|
-
globalScope.__serverDb = createLegacyServerDb(authorityStore);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
return {
|
|
115
|
-
authorityStore,
|
|
116
|
-
serverDb: globalScope.__serverDb as LegacyServerDb,
|
|
117
|
-
};
|
|
118
|
-
}
|