@hasna/brains 0.0.26 → 0.0.28
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/cli/index.js +829 -157
- package/dist/index.js +33 -35
- package/dist/mcp/index.js +53 -57
- package/dist/server/index.js +36 -38
- package/package.json +3 -2
package/dist/server/index.js
CHANGED
|
@@ -3708,13 +3708,13 @@ import { join, relative } from "path";
|
|
|
3708
3708
|
import { existsSync as existsSync2, mkdirSync as mkdirSync2, readFileSync, writeFileSync } from "fs";
|
|
3709
3709
|
import { homedir as homedir2 } from "os";
|
|
3710
3710
|
import { join as join2 } from "path";
|
|
3711
|
-
import { readdirSync as
|
|
3712
|
-
import { join as
|
|
3711
|
+
import { readdirSync as readdirSync3, existsSync as existsSync6 } from "fs";
|
|
3712
|
+
import { join as join6 } from "path";
|
|
3713
|
+
import { homedir as homedir5 } from "os";
|
|
3713
3714
|
import { homedir as homedir3 } from "os";
|
|
3714
|
-
import {
|
|
3715
|
-
import { join as
|
|
3716
|
-
import {
|
|
3717
|
-
import { homedir as homedir5, platform } from "os";
|
|
3715
|
+
import { join as join3 } from "path";
|
|
3716
|
+
import { join as join5, dirname } from "path";
|
|
3717
|
+
import { homedir as homedir4, platform } from "os";
|
|
3718
3718
|
var __create = Object.create;
|
|
3719
3719
|
var __getProtoOf = Object.getPrototypeOf;
|
|
3720
3720
|
var __defProp2 = Object.defineProperty;
|
|
@@ -13000,7 +13000,7 @@ var exports_discover = {};
|
|
|
13000
13000
|
__export2(exports_discover, {
|
|
13001
13001
|
isSyncExcludedTable: () => isSyncExcludedTable,
|
|
13002
13002
|
getServiceDbPath: () => getServiceDbPath,
|
|
13003
|
-
discoverSyncableServices: () =>
|
|
13003
|
+
discoverSyncableServices: () => discoverSyncableServices2,
|
|
13004
13004
|
discoverServices: () => discoverServices,
|
|
13005
13005
|
SYNC_EXCLUDED_TABLE_PATTERNS: () => SYNC_EXCLUDED_TABLE_PATTERNS,
|
|
13006
13006
|
KNOWN_PG_SERVICES: () => KNOWN_PG_SERVICES
|
|
@@ -13009,11 +13009,11 @@ function isSyncExcludedTable(table) {
|
|
|
13009
13009
|
return SYNC_EXCLUDED_TABLE_PATTERNS.some((p) => p.test(table));
|
|
13010
13010
|
}
|
|
13011
13011
|
function discoverServices() {
|
|
13012
|
-
const dataDir =
|
|
13013
|
-
if (!
|
|
13012
|
+
const dataDir = join6(homedir5(), ".hasna");
|
|
13013
|
+
if (!existsSync6(dataDir))
|
|
13014
13014
|
return [];
|
|
13015
13015
|
try {
|
|
13016
|
-
const entries =
|
|
13016
|
+
const entries = readdirSync3(dataDir, { withFileTypes: true });
|
|
13017
13017
|
return entries.filter((e) => {
|
|
13018
13018
|
if (!e.isDirectory())
|
|
13019
13019
|
return false;
|
|
@@ -13025,30 +13025,30 @@ function discoverServices() {
|
|
|
13025
13025
|
return [];
|
|
13026
13026
|
}
|
|
13027
13027
|
}
|
|
13028
|
-
function
|
|
13028
|
+
function discoverSyncableServices2() {
|
|
13029
13029
|
const local = discoverServices();
|
|
13030
13030
|
const pgSet = new Set(KNOWN_PG_SERVICES);
|
|
13031
13031
|
return local.filter((s) => pgSet.has(s));
|
|
13032
13032
|
}
|
|
13033
13033
|
function getServiceDbPath(service) {
|
|
13034
|
-
const dataDir =
|
|
13035
|
-
if (!
|
|
13034
|
+
const dataDir = join6(homedir5(), ".hasna", service);
|
|
13035
|
+
if (!existsSync6(dataDir))
|
|
13036
13036
|
return null;
|
|
13037
13037
|
const candidates = [
|
|
13038
|
-
|
|
13039
|
-
|
|
13040
|
-
|
|
13038
|
+
join6(dataDir, `${service}.db`),
|
|
13039
|
+
join6(dataDir, "data.db"),
|
|
13040
|
+
join6(dataDir, "database.db")
|
|
13041
13041
|
];
|
|
13042
13042
|
try {
|
|
13043
|
-
const files =
|
|
13043
|
+
const files = readdirSync3(dataDir);
|
|
13044
13044
|
for (const f of files) {
|
|
13045
13045
|
if (f.endsWith(".db") && !f.endsWith("-wal") && !f.endsWith("-shm")) {
|
|
13046
|
-
candidates.push(
|
|
13046
|
+
candidates.push(join6(dataDir, f));
|
|
13047
13047
|
}
|
|
13048
13048
|
}
|
|
13049
13049
|
} catch {}
|
|
13050
13050
|
for (const p of candidates) {
|
|
13051
|
-
if (
|
|
13051
|
+
if (existsSync6(p))
|
|
13052
13052
|
return p;
|
|
13053
13053
|
}
|
|
13054
13054
|
return null;
|
|
@@ -13238,15 +13238,13 @@ class SyncProgressTracker {
|
|
|
13238
13238
|
}
|
|
13239
13239
|
}
|
|
13240
13240
|
}
|
|
13241
|
-
init_adapter();
|
|
13242
13241
|
init_config();
|
|
13243
|
-
|
|
13244
|
-
var AUTO_SYNC_CONFIG_PATH = join4(homedir4(), ".hasna", "cloud", "config.json");
|
|
13242
|
+
var AUTO_SYNC_CONFIG_PATH = join3(homedir3(), ".hasna", "cloud", "config.json");
|
|
13245
13243
|
init_config();
|
|
13246
13244
|
init_adapter();
|
|
13247
13245
|
init_dotfile();
|
|
13248
13246
|
init_config();
|
|
13249
|
-
var CONFIG_DIR2 =
|
|
13247
|
+
var CONFIG_DIR2 = join5(homedir4(), ".hasna", "cloud");
|
|
13250
13248
|
init_adapter();
|
|
13251
13249
|
init_config();
|
|
13252
13250
|
init_discover();
|
|
@@ -13364,7 +13362,7 @@ function getDb(dbPath) {
|
|
|
13364
13362
|
}
|
|
13365
13363
|
|
|
13366
13364
|
// src/lib/package-metadata.ts
|
|
13367
|
-
import { existsSync as
|
|
13365
|
+
import { existsSync as existsSync3, readFileSync as readFileSync2 } from "fs";
|
|
13368
13366
|
import { dirname as dirname2, resolve as resolve2 } from "path";
|
|
13369
13367
|
import { fileURLToPath } from "url";
|
|
13370
13368
|
var DEFAULT_VERSION = "0.0.0";
|
|
@@ -13377,7 +13375,7 @@ function getPackageVersion() {
|
|
|
13377
13375
|
return cachedVersion;
|
|
13378
13376
|
}
|
|
13379
13377
|
const packageJsonPath = getPackageJsonPath();
|
|
13380
|
-
if (!
|
|
13378
|
+
if (!existsSync3(packageJsonPath)) {
|
|
13381
13379
|
cachedVersion = DEFAULT_VERSION;
|
|
13382
13380
|
return cachedVersion;
|
|
13383
13381
|
}
|
|
@@ -13393,7 +13391,7 @@ function getPackageVersion() {
|
|
|
13393
13391
|
// src/lib/gatherers/todos.ts
|
|
13394
13392
|
import { Database as Database3 } from "bun:sqlite";
|
|
13395
13393
|
import { homedir as homedir6 } from "os";
|
|
13396
|
-
import { join as
|
|
13394
|
+
import { join as join4 } from "path";
|
|
13397
13395
|
var SYSTEM_PROMPT = "You are a task management assistant that helps users create, update, search, and manage tasks and projects.";
|
|
13398
13396
|
function taskToCreateExample(task) {
|
|
13399
13397
|
const userMsg = `Create a task: ${task.title}${task.description ? `
|
|
@@ -13444,7 +13442,7 @@ ${matched.map((t) => `- [${t.short_id ?? t.id}] ${t.title} (${t.status})`).join(
|
|
|
13444
13442
|
};
|
|
13445
13443
|
}
|
|
13446
13444
|
async function gatherFromTodos(options = {}) {
|
|
13447
|
-
const dbPath =
|
|
13445
|
+
const dbPath = join4(homedir6(), ".todos", "todos.db");
|
|
13448
13446
|
const db = new Database3(dbPath, { readonly: true, create: false });
|
|
13449
13447
|
try {
|
|
13450
13448
|
let query = "SELECT * FROM tasks WHERE 1=1";
|
|
@@ -13570,7 +13568,7 @@ async function gatherFromMementos(options = {}) {
|
|
|
13570
13568
|
// src/lib/gatherers/conversations.ts
|
|
13571
13569
|
import { Database as Database5 } from "bun:sqlite";
|
|
13572
13570
|
import { homedir as homedir9 } from "os";
|
|
13573
|
-
import { join as
|
|
13571
|
+
import { join as join9 } from "path";
|
|
13574
13572
|
var SYSTEM_PROMPT3 = "You are a helpful AI assistant participating in multi-agent conversations. You communicate clearly and collaboratively with other agents and users.";
|
|
13575
13573
|
function windowToExample(window) {
|
|
13576
13574
|
if (window.length < 2)
|
|
@@ -13598,7 +13596,7 @@ function windowToExample(window) {
|
|
|
13598
13596
|
return { messages };
|
|
13599
13597
|
}
|
|
13600
13598
|
async function gatherFromConversations(options = {}) {
|
|
13601
|
-
const dbPath =
|
|
13599
|
+
const dbPath = join9(homedir9(), ".conversations", "messages.db");
|
|
13602
13600
|
const db = new Database5(dbPath, { readonly: true, create: false });
|
|
13603
13601
|
try {
|
|
13604
13602
|
let query = "SELECT * FROM messages WHERE 1=1";
|
|
@@ -13641,8 +13639,8 @@ async function gatherFromConversations(options = {}) {
|
|
|
13641
13639
|
|
|
13642
13640
|
// src/lib/gatherers/sessions.ts
|
|
13643
13641
|
import { readdir, readFile, stat } from "fs/promises";
|
|
13644
|
-
import { existsSync as
|
|
13645
|
-
import { join as
|
|
13642
|
+
import { existsSync as existsSync5 } from "fs";
|
|
13643
|
+
import { join as join10 } from "path";
|
|
13646
13644
|
import { homedir as homedir10 } from "os";
|
|
13647
13645
|
var SYSTEM_PROMPT4 = "You are Claude Code, an AI assistant built by Anthropic that helps developers with coding, architecture, debugging, and software engineering tasks.";
|
|
13648
13646
|
function extractText(content) {
|
|
@@ -13654,22 +13652,22 @@ function extractText(content) {
|
|
|
13654
13652
|
async function gatherFromSessions(options = {}) {
|
|
13655
13653
|
const { limit = 1000 } = options;
|
|
13656
13654
|
const examples = [];
|
|
13657
|
-
const claudeDir =
|
|
13658
|
-
if (!
|
|
13655
|
+
const claudeDir = join10(homedir10(), ".claude", "projects");
|
|
13656
|
+
if (!existsSync5(claudeDir)) {
|
|
13659
13657
|
return { source: "sessions", examples: [], count: 0 };
|
|
13660
13658
|
}
|
|
13661
13659
|
const projectDirs = await readdir(claudeDir).catch(() => []);
|
|
13662
13660
|
for (const projectDir of projectDirs) {
|
|
13663
13661
|
if (examples.length >= limit)
|
|
13664
13662
|
break;
|
|
13665
|
-
const projectPath =
|
|
13663
|
+
const projectPath = join10(claudeDir, projectDir);
|
|
13666
13664
|
const files = await readdir(projectPath).catch(() => []);
|
|
13667
13665
|
for (const file of files) {
|
|
13668
13666
|
if (examples.length >= limit)
|
|
13669
13667
|
break;
|
|
13670
13668
|
if (!file.endsWith(".jsonl"))
|
|
13671
13669
|
continue;
|
|
13672
|
-
const filePath =
|
|
13670
|
+
const filePath = join10(projectPath, file);
|
|
13673
13671
|
if (options.since) {
|
|
13674
13672
|
const fileStat = await stat(filePath).catch(() => null);
|
|
13675
13673
|
if (fileStat && fileStat.mtime < options.since)
|
|
@@ -14051,7 +14049,7 @@ async function gatherAll(sources, options = {}) {
|
|
|
14051
14049
|
|
|
14052
14050
|
// src/server/index.ts
|
|
14053
14051
|
import { mkdirSync as mkdirSync3, writeFileSync as writeFileSync2 } from "fs";
|
|
14054
|
-
import { join as
|
|
14052
|
+
import { join as join11 } from "path";
|
|
14055
14053
|
import { homedir as homedir11 } from "os";
|
|
14056
14054
|
function json(data, status = 200) {
|
|
14057
14055
|
return Response.json(data, { status });
|
|
@@ -14161,7 +14159,7 @@ async function handleGather(req) {
|
|
|
14161
14159
|
}
|
|
14162
14160
|
const sources = body.sources ?? ["todos", "mementos", "conversations", "sessions"];
|
|
14163
14161
|
const limit = body.limit ?? 500;
|
|
14164
|
-
const outDir = body.output_dir ??
|
|
14162
|
+
const outDir = body.output_dir ?? join11(homedir11(), ".hasna", "brains", "datasets");
|
|
14165
14163
|
mkdirSync3(outDir, { recursive: true });
|
|
14166
14164
|
const results = await gatherAll(sources, { limit });
|
|
14167
14165
|
const db = getDb();
|
|
@@ -14171,7 +14169,7 @@ async function handleGather(req) {
|
|
|
14171
14169
|
if (result.count === 0)
|
|
14172
14170
|
continue;
|
|
14173
14171
|
const fileName = `${result.source}-${now}.jsonl`;
|
|
14174
|
-
const filePath =
|
|
14172
|
+
const filePath = join11(outDir, fileName);
|
|
14175
14173
|
writeFileSync2(filePath, result.examples.map((e) => JSON.stringify(e)).join(`
|
|
14176
14174
|
`) + `
|
|
14177
14175
|
`, "utf8");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hasna/brains",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.28",
|
|
4
4
|
"description": "Fine-tuned model tracker and trainer — wraps OpenAI + Thinker Labs, gathers training data from todos/mementos/conversations/sessions",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -64,7 +64,8 @@
|
|
|
64
64
|
"author": "Andrei Hasna <andrei@hasna.com>",
|
|
65
65
|
"license": "Apache-2.0",
|
|
66
66
|
"dependencies": {
|
|
67
|
-
"@hasna/cloud": "
|
|
67
|
+
"@hasna/cloud": "0.1.24",
|
|
68
|
+
"@hasna/events": "^0.1.6",
|
|
68
69
|
"@modelcontextprotocol/sdk": "^1.12.1",
|
|
69
70
|
"chalk": "^5.4.1",
|
|
70
71
|
"commander": "^13.1.0",
|