-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobsidian-sync.ts
More file actions
77 lines (60 loc) · 2.83 KB
/
Copy pathobsidian-sync.ts
File metadata and controls
77 lines (60 loc) · 2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import { EventStore } from "../src/history/event-store.js";
import { ObsidianOrchestrator } from "../src/integrations/obsidian/obsidian-orchestrator.js";
import { ConfigManager } from "../src/core/config.js";
import * as path from "path";
import * as fs from "fs";
/**
* Historical Migration Script
* Sweeps the EventStore (events.db) and pushes all old session data to the Obsidian Vault.
*/
async function migrate() {
console.log("Starting Historical Migration to Obsidian...");
// Force the orchestrator to use the global obsidian vault
ConfigManager.getObsidianConfig = () => ({ vaultPath: "C:\\repo\\global.obsidian" });
const store = EventStore.getInstance();
const db = (store as any).db;
// 1. Get all unique projects (repo_ids)
const repos = db.prepare("SELECT DISTINCT repo_id FROM prompts WHERE repo_id IS NOT NULL").all() as { repo_id: string }[];
console.log(`Found ${repos.length} projects with history.`);
for (const { repo_id } of repos) {
console.log(`\nMigrating project: ${repo_id}...`);
// Simulate a rootPath for the orchestrator (it uses basename(rootPath) as repoId)
// We'll use a dummy path that ends with the repo_id
const dummyRootPath = `C:\\repo\\${repo_id}`;
// 2. Fetch all successful executions for this repo
const executions = db.prepare(`
SELECT p.raw_prompt, e.result_summary, e.ended_at, e.executor_name
FROM prompts p
JOIN executions e ON p.id = e.prompt_id
WHERE p.repo_id = ? AND e.status = 'completed'
ORDER BY e.ended_at ASC
`).all(repo_id) as any[];
console.log(`- Found ${executions.length} historical executions.`);
for (const exec of executions) {
const summary = `Historical: ${exec.result_summary || "Agent execution"}`;
const rationale = `Prompt: ${exec.raw_prompt}\n\nExecutor: ${exec.executor_name}\nDate: ${new Date(exec.ended_at).toLocaleString()}`;
await ObsidianOrchestrator.logActivity(dummyRootPath, summary, rationale);
}
// 3. Fetch all commits for this repo
const commits = db.prepare(`
SELECT message, committed_at, author, sha
FROM commits
WHERE repo_id = ?
ORDER BY committed_at ASC
`).all(repo_id) as any[];
console.log(`- Found ${commits.length} historical commits.`);
for (const commit of commits) {
const summary = `Historical Commit: ${commit.sha.substring(0, 7)} - ${commit.message}`;
const rationale = `Author: ${commit.author}\nDate: ${new Date(commit.committed_at).toLocaleString()}`;
await ObsidianOrchestrator.logActivity(dummyRootPath, summary, rationale);
}
// 4. Sync lessons (Engineering Mandates)
await ObsidianOrchestrator.syncToWiki(dummyRootPath);
}
console.log("\nMigration Complete!");
process.exit(0);
}
migrate().catch(err => {
console.error("Migration failed:", err);
process.exit(1);
});