@adhdev/daemon-core 0.9.82-rc.172 → 0.9.82-rc.173
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/dist/config/mesh-config.d.ts +1 -0
- package/dist/index.d.ts +1 -3
- package/dist/index.js +775 -693
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +772 -692
- package/dist/index.mjs.map +1 -1
- package/dist/mesh/beads-db.d.ts +1 -1
- package/dist/mesh/mesh-events.d.ts +1 -0
- package/dist/mesh/mesh-fast-forward.d.ts +2 -0
- package/dist/mesh/mesh-work-queue.d.ts +10 -1
- package/dist/repo-mesh-types.d.ts +2 -0
- package/package.json +1 -1
- package/src/config/mesh-config.ts +16 -0
- package/src/index.ts +1 -3
- package/src/mesh/beads-db.ts +20 -13
- package/src/mesh/mesh-events.ts +88 -10
- package/src/mesh/mesh-fast-forward.ts +11 -3
- package/src/mesh/mesh-work-queue.ts +49 -3
- package/src/repo-mesh-types.ts +2 -0
- package/dist/mesh/mesh-sync.d.ts +0 -53
- package/src/mesh/mesh-sync.ts +0 -111
package/src/mesh/mesh-sync.ts
DELETED
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Mesh Sync — Sync local mesh metadata to/from cloud D1
|
|
3
|
-
*
|
|
4
|
-
* When cloud is available, this module pushes local mesh config
|
|
5
|
-
* to the server and pulls remote meshes that were created from
|
|
6
|
-
* other machines. The local ~/.adhdev/meshes.json remains the
|
|
7
|
-
* canonical source; cloud is a membership/metadata layer only.
|
|
8
|
-
* Task/chat/ledger evidence remains local-first and must not be
|
|
9
|
-
* synchronized through Cloud/D1.
|
|
10
|
-
*
|
|
11
|
-
* This is called lazily (not on daemon startup) — only when the
|
|
12
|
-
* user explicitly opens the mesh page or runs `adhdev mesh sync`.
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
import { listMeshes, getMesh, createMesh, deleteMesh, addNode, removeNode } from '../config/mesh-config.js';
|
|
16
|
-
import type { LocalMeshEntry, LocalMeshNodeEntry } from '../repo-mesh-types.js';
|
|
17
|
-
|
|
18
|
-
export interface MeshSyncTransport {
|
|
19
|
-
/** GET /api/v1/repo-meshes */
|
|
20
|
-
listRemoteMeshes(): Promise<{ meshes: RemoteMeshRecord[] }>;
|
|
21
|
-
/** POST /api/v1/repo-meshes */
|
|
22
|
-
createRemoteMesh(data: {
|
|
23
|
-
name: string;
|
|
24
|
-
repo_identity: string;
|
|
25
|
-
repo_remote_url?: string;
|
|
26
|
-
default_branch?: string;
|
|
27
|
-
policy?: string;
|
|
28
|
-
}): Promise<{ mesh: RemoteMeshRecord }>;
|
|
29
|
-
/** DELETE /api/v1/repo-meshes/:id */
|
|
30
|
-
deleteRemoteMesh(meshId: string): Promise<void>;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export interface RemoteMeshRecord {
|
|
34
|
-
id: string;
|
|
35
|
-
name: string;
|
|
36
|
-
repo_identity: string;
|
|
37
|
-
repo_remote_url: string | null;
|
|
38
|
-
default_branch: string | null;
|
|
39
|
-
policy: string;
|
|
40
|
-
status: string;
|
|
41
|
-
created_at: string;
|
|
42
|
-
updated_at: string;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export interface MeshSyncResult {
|
|
46
|
-
pushed: number;
|
|
47
|
-
pulled: number;
|
|
48
|
-
deleted: number;
|
|
49
|
-
errors: string[];
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Push local meshes to cloud (upsert by repo_identity).
|
|
54
|
-
* Pull remote meshes that don't exist locally.
|
|
55
|
-
*/
|
|
56
|
-
export async function syncMeshes(transport: MeshSyncTransport): Promise<MeshSyncResult> {
|
|
57
|
-
const result: MeshSyncResult = { pushed: 0, pulled: 0, deleted: 0, errors: [] };
|
|
58
|
-
|
|
59
|
-
let remoteMeshes: RemoteMeshRecord[];
|
|
60
|
-
try {
|
|
61
|
-
const res = await transport.listRemoteMeshes();
|
|
62
|
-
remoteMeshes = res.meshes;
|
|
63
|
-
} catch (e: any) {
|
|
64
|
-
result.errors.push(`Failed to list remote meshes: ${e.message}`);
|
|
65
|
-
return result;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const localMeshes = listMeshes();
|
|
69
|
-
const remoteByIdentity = new Map(remoteMeshes.map(m => [m.repo_identity, m]));
|
|
70
|
-
const localByIdentity = new Map(localMeshes.map(m => [m.repoIdentity, m]));
|
|
71
|
-
|
|
72
|
-
// Push: local meshes not in cloud
|
|
73
|
-
for (const local of localMeshes) {
|
|
74
|
-
if (!remoteByIdentity.has(local.repoIdentity)) {
|
|
75
|
-
try {
|
|
76
|
-
await transport.createRemoteMesh({
|
|
77
|
-
name: local.name,
|
|
78
|
-
repo_identity: local.repoIdentity,
|
|
79
|
-
repo_remote_url: local.repoRemoteUrl,
|
|
80
|
-
default_branch: local.defaultBranch,
|
|
81
|
-
policy: JSON.stringify(local.policy),
|
|
82
|
-
});
|
|
83
|
-
result.pushed++;
|
|
84
|
-
} catch (e: any) {
|
|
85
|
-
result.errors.push(`Push failed for "${local.name}": ${e.message}`);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// Pull: remote meshes not in local
|
|
91
|
-
for (const remote of remoteMeshes) {
|
|
92
|
-
if (!localByIdentity.has(remote.repo_identity)) {
|
|
93
|
-
try {
|
|
94
|
-
let policy;
|
|
95
|
-
try { policy = JSON.parse(remote.policy); } catch { policy = undefined; }
|
|
96
|
-
createMesh({
|
|
97
|
-
name: remote.name,
|
|
98
|
-
repoIdentity: remote.repo_identity,
|
|
99
|
-
repoRemoteUrl: remote.repo_remote_url || undefined,
|
|
100
|
-
defaultBranch: remote.default_branch || undefined,
|
|
101
|
-
policy,
|
|
102
|
-
});
|
|
103
|
-
result.pulled++;
|
|
104
|
-
} catch (e: any) {
|
|
105
|
-
result.errors.push(`Pull failed for "${remote.name}": ${e.message}`);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
return result;
|
|
111
|
-
}
|