@hasna/brains 0.0.8 → 0.0.10

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/LICENSE ADDED
@@ -0,0 +1,170 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship made available under
36
+ the License, as indicated by a copyright notice that is included in
37
+ or attached to the work (an example is provided in the Appendix below).
38
+
39
+ "Derivative Works" shall mean any work, whether in Source or Object
40
+ form, that is based on (or derived from) the Work and for which the
41
+ editorial revisions, annotations, elaborations, or other modifications
42
+ represent, as a whole, an original work of authorship. For the purposes
43
+ of this License, Derivative Works shall not include works that remain
44
+ separable from, or merely link (or bind by name) to the interfaces of,
45
+ the Work and Derivative Works thereof.
46
+
47
+ "Contribution" shall mean, as submitted to the Licensor for inclusion
48
+ in the Work by the copyright owner or by an individual or Legal Entity
49
+ authorized to submit on behalf of the copyright owner. For the purposes
50
+ of this definition, "submitted" means any form of electronic, verbal,
51
+ or written communication sent to the Licensor or its representatives,
52
+ including but not limited to communication on electronic mailing lists,
53
+ source code control systems, and issue tracking systems that are managed
54
+ by, or on behalf of, the Licensor for the purpose of recording and
55
+ discussing the Work, but excluding communication that is conspicuously
56
+ marked or designated in writing by the copyright owner as "Not a
57
+ Contribution."
58
+
59
+ "Contributor" shall mean Licensor and any Legal Entity on behalf of
60
+ whom a Contribution has been received by the Licensor and included
61
+ within the Work.
62
+
63
+ 2. Grant of Copyright License. Subject to the terms and conditions of
64
+ this License, each Contributor hereby grants to You a perpetual,
65
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
66
+ copyright license to reproduce, prepare Derivative Works of,
67
+ publicly display, publicly perform, sublicense, and distribute the
68
+ Work and such Derivative Works in Source or Object form.
69
+
70
+ 3. Grant of Patent License. Subject to the terms and conditions of
71
+ this License, each Contributor hereby grants to You a perpetual,
72
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
73
+ (except as stated in this section) patent license to make, have made,
74
+ use, offer to sell, sell, import, and otherwise transfer the Work,
75
+ where such license applies only to those patent contributions
76
+ Licensors can make available under this License.
77
+
78
+ 4. Redistribution. You may reproduce and distribute copies of the
79
+ Work or Derivative Works thereof in any medium, with or without
80
+ modifications, and in Source or Object form, provided that You
81
+ meet the following conditions:
82
+
83
+ (a) You must give any other recipients of the Work or Derivative Works
84
+ a copy of this License; and
85
+
86
+ (b) You must cause any modified files to carry prominent notices
87
+ stating that You changed the files; and
88
+
89
+ (c) You must retain, in the Source form of any Derivative Works
90
+ that You distribute, all copyright, patent, trademark, and
91
+ attribution notices from the Source form of the Work,
92
+ excluding those notices that do not pertain to any part of
93
+ the Derivative Works; and
94
+
95
+ (d) If the Work includes a "NOTICE" text file as part of its
96
+ distribution, You must include a readable copy of the attribution
97
+ notices contained within such NOTICE file, in at least one
98
+ of the following places: within a NOTICE text file distributed
99
+ as part of the Derivative Works; within the Source form or
100
+ documentation, if provided along with the Derivative Works; or,
101
+ within a display generated by the Derivative Works, if and
102
+ wherever such third-party notices normally appear. The contents
103
+ of the NOTICE file are for informational purposes only and
104
+ do not modify the License. You may add Your own attribution
105
+ notices within Derivative Works that You distribute, alongside
106
+ or as an addendum to the NOTICE text from the Work, provided
107
+ that such additional attribution notices cannot be construed
108
+ as modifying the License.
109
+
110
+ You may add Your own license statement for Your modifications and
111
+ may provide additional grant of rights to use, copy, modify, merge,
112
+ publish, distribute, sublicense, and/or sell copies of the Software.
113
+
114
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
115
+ any Contribution intentionally submitted for inclusion in the Work
116
+ by You to the Licensor shall be under the terms and conditions of
117
+ this License, without any additional terms or conditions.
118
+ Notwithstanding the above, nothing herein shall supersede or modify
119
+ the terms of any separate license agreement you may have executed
120
+ with Licensor regarding such Contributions.
121
+
122
+ 6. Trademarks. This License does not grant permission to use the trade
123
+ names, trademarks, service marks, or product names of the Licensor,
124
+ except as required for reasonable and customary use in describing the
125
+ origin of the Work and reproducing the content of the NOTICE file.
126
+
127
+ 7. Disclaimer of Warranty. Unless required by applicable law or
128
+ agreed to in writing, Licensor provides the Work (and each
129
+ Contributor provides its Contributions) on an "AS IS" BASIS,
130
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
131
+ implied, including, without limitation, any warranties or conditions
132
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
133
+ PARTICULAR PURPOSE. You are solely responsible for determining the
134
+ appropriateness of using or redistributing the Work and assume any
135
+ risks associated with Your exercise of permissions under this License.
136
+
137
+ 8. Limitation of Liability. In no event and under no legal theory,
138
+ whether in tort (including negligence), contract, or otherwise,
139
+ unless required by applicable law (such as deliberate and grossly
140
+ negligent acts) or agreed to in writing, shall any Contributor be
141
+ liable to You for damages, including any direct, indirect, special,
142
+ incidental, or exemplary damages of any character arising as a
143
+ result of this License or out of the use or inability to use the
144
+ Work (including but not limited to damages for loss of goodwill,
145
+ work stoppage, computer failure or malfunction, or all other
146
+ commercial damages or losses), even if such Contributor has been
147
+ advised of the possibility of such damages.
148
+
149
+ 9. Accepting Warranty or Additional Liability. While redistributing
150
+ the Work or Derivative Works thereof, You may choose to offer,
151
+ and charge a fee for, acceptance of support, warranty, indemnity,
152
+ or other liability obligations and/or rights consistent with this
153
+ License. However, in accepting such obligations, You may offer only
154
+ conditions consistent with this License.
155
+
156
+ END OF TERMS AND CONDITIONS
157
+
158
+ Copyright 2024 hasna.com
159
+
160
+ Licensed under the Apache License, Version 2.0 (the "License");
161
+ you may not use this file except in compliance with the License.
162
+ You may obtain a copy of the License at
163
+
164
+ http://www.apache.org/licenses/LICENSE-2.0
165
+
166
+ Unless required by applicable law or agreed to in writing, software
167
+ distributed under the License is distributed on an "AS IS" BASIS,
168
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
169
+ See the License for the specific language governing permissions and
170
+ limitations under the License.
package/dist/cli/index.js CHANGED
@@ -5,25 +5,43 @@ var __getProtoOf = Object.getPrototypeOf;
5
5
  var __defProp = Object.defineProperty;
6
6
  var __getOwnPropNames = Object.getOwnPropertyNames;
7
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ function __accessProp(key) {
9
+ return this[key];
10
+ }
11
+ var __toESMCache_node;
12
+ var __toESMCache_esm;
8
13
  var __toESM = (mod, isNodeMode, target) => {
14
+ var canCache = mod != null && typeof mod === "object";
15
+ if (canCache) {
16
+ var cache = isNodeMode ? __toESMCache_node ??= new WeakMap : __toESMCache_esm ??= new WeakMap;
17
+ var cached = cache.get(mod);
18
+ if (cached)
19
+ return cached;
20
+ }
9
21
  target = mod != null ? __create(__getProtoOf(mod)) : {};
10
22
  const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
11
23
  for (let key of __getOwnPropNames(mod))
12
24
  if (!__hasOwnProp.call(to, key))
13
25
  __defProp(to, key, {
14
- get: () => mod[key],
26
+ get: __accessProp.bind(mod, key),
15
27
  enumerable: true
16
28
  });
29
+ if (canCache)
30
+ cache.set(mod, to);
17
31
  return to;
18
32
  };
19
33
  var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
34
+ var __returnValue = (v) => v;
35
+ function __exportSetter(name, newValue) {
36
+ this[name] = __returnValue.bind(null, newValue);
37
+ }
20
38
  var __export = (target, all) => {
21
39
  for (var name in all)
22
40
  __defProp(target, name, {
23
41
  get: all[name],
24
42
  enumerable: true,
25
43
  configurable: true,
26
- set: (newValue) => all[name] = () => newValue
44
+ set: __exportSetter.bind(all, name)
27
45
  });
28
46
  };
29
47
  var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
@@ -2333,7 +2351,7 @@ __export(exports_sessions2, {
2333
2351
  gatherFromSessions: () => gatherFromSessions
2334
2352
  });
2335
2353
  import { readdir, readFile, stat } from "fs/promises";
2336
- import { existsSync as existsSync2 } from "fs";
2354
+ import { existsSync as existsSync3 } from "fs";
2337
2355
  import { join as join6 } from "path";
2338
2356
  import { homedir as homedir6 } from "os";
2339
2357
  function extractText(content) {
@@ -2346,7 +2364,7 @@ async function gatherFromSessions(options = {}) {
2346
2364
  const { limit: limit2 = 1000 } = options;
2347
2365
  const examples = [];
2348
2366
  const claudeDir = join6(homedir6(), ".claude", "projects");
2349
- if (!existsSync2(claudeDir)) {
2367
+ if (!existsSync3(claudeDir)) {
2350
2368
  return { source: "sessions", examples: [], count: 0 };
2351
2369
  }
2352
2370
  const projectDirs = await readdir(claudeDir).catch(() => []);
@@ -3783,7 +3801,7 @@ function mapRelationalRow(tablesConfig, tableConfig, row, buildQueryResultSelect
3783
3801
 
3784
3802
  // src/cli/index.ts
3785
3803
  import { randomUUID } from "crypto";
3786
- import { readFileSync as readFileSync3, existsSync as existsSync3, mkdirSync as mkdirSync3, writeFileSync as writeFileSync2 } from "fs";
3804
+ import { readFileSync as readFileSync3, existsSync as existsSync4, mkdirSync as mkdirSync3, writeFileSync as writeFileSync2 } from "fs";
3787
3805
  import { join as join7 } from "path";
3788
3806
  import { homedir as homedir7 } from "os";
3789
3807
 
@@ -6108,7 +6126,7 @@ function migrate(db, config) {
6108
6126
 
6109
6127
  // src/db/index.ts
6110
6128
  import { Database as Database2 } from "bun:sqlite";
6111
- import { mkdirSync } from "fs";
6129
+ import { mkdirSync, existsSync, readdirSync, copyFileSync, statSync } from "fs";
6112
6130
  import { dirname, join, resolve } from "path";
6113
6131
  import { homedir } from "os";
6114
6132
 
@@ -6157,7 +6175,28 @@ var trainingDatasets = sqliteTable("training_datasets", {
6157
6175
  });
6158
6176
 
6159
6177
  // src/db/index.ts
6160
- var DEFAULT_DB_PATH = join(homedir(), ".brains", "brains.db");
6178
+ function resolveDefaultDbPath() {
6179
+ const home = process.env["HOME"] || process.env["USERPROFILE"] || homedir();
6180
+ const newDir = join(home, ".hasna", "brains");
6181
+ const oldDir = join(home, ".brains");
6182
+ if (existsSync(oldDir) && !existsSync(newDir)) {
6183
+ mkdirSync(newDir, { recursive: true });
6184
+ try {
6185
+ for (const file of readdirSync(oldDir)) {
6186
+ const oldPath = join(oldDir, file);
6187
+ const newPath = join(newDir, file);
6188
+ try {
6189
+ if (statSync(oldPath).isFile()) {
6190
+ copyFileSync(oldPath, newPath);
6191
+ }
6192
+ } catch {}
6193
+ }
6194
+ } catch {}
6195
+ }
6196
+ mkdirSync(newDir, { recursive: true });
6197
+ return join(newDir, "brains.db");
6198
+ }
6199
+ var DEFAULT_DB_PATH = resolveDefaultDbPath();
6161
6200
  function ensureDir(filePath) {
6162
6201
  mkdirSync(dirname(filePath), { recursive: true });
6163
6202
  }
@@ -9676,11 +9715,11 @@ class ChatCompletionStream extends AbstractChatCompletionRunner {
9676
9715
  }
9677
9716
  return this._addChatCompletion(__classPrivateFieldGet6(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_endRequest).call(this));
9678
9717
  }
9679
- [(_ChatCompletionStream_params = new WeakMap, _ChatCompletionStream_choiceEventStates = new WeakMap, _ChatCompletionStream_currentChatCompletionSnapshot = new WeakMap, _ChatCompletionStream_instances = new WeakSet, _ChatCompletionStream_beginRequest = function _ChatCompletionStream_beginRequest() {
9718
+ [(_ChatCompletionStream_params = new WeakMap, _ChatCompletionStream_choiceEventStates = new WeakMap, _ChatCompletionStream_currentChatCompletionSnapshot = new WeakMap, _ChatCompletionStream_instances = new WeakSet, _ChatCompletionStream_beginRequest = function _ChatCompletionStream_beginRequest2() {
9680
9719
  if (this.ended)
9681
9720
  return;
9682
9721
  __classPrivateFieldSet5(this, _ChatCompletionStream_currentChatCompletionSnapshot, undefined, "f");
9683
- }, _ChatCompletionStream_getChoiceEventState = function _ChatCompletionStream_getChoiceEventState(choice) {
9722
+ }, _ChatCompletionStream_getChoiceEventState = function _ChatCompletionStream_getChoiceEventState2(choice) {
9684
9723
  let state = __classPrivateFieldGet6(this, _ChatCompletionStream_choiceEventStates, "f")[choice.index];
9685
9724
  if (state) {
9686
9725
  return state;
@@ -9695,7 +9734,7 @@ class ChatCompletionStream extends AbstractChatCompletionRunner {
9695
9734
  };
9696
9735
  __classPrivateFieldGet6(this, _ChatCompletionStream_choiceEventStates, "f")[choice.index] = state;
9697
9736
  return state;
9698
- }, _ChatCompletionStream_addChunk = function _ChatCompletionStream_addChunk(chunk) {
9737
+ }, _ChatCompletionStream_addChunk = function _ChatCompletionStream_addChunk2(chunk) {
9699
9738
  if (this.ended)
9700
9739
  return;
9701
9740
  const completion = __classPrivateFieldGet6(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_accumulateChatCompletion).call(this, chunk);
@@ -9762,7 +9801,7 @@ class ChatCompletionStream extends AbstractChatCompletionRunner {
9762
9801
  }
9763
9802
  }
9764
9803
  }
9765
- }, _ChatCompletionStream_emitToolCallDoneEvent = function _ChatCompletionStream_emitToolCallDoneEvent(choiceSnapshot, toolCallIndex) {
9804
+ }, _ChatCompletionStream_emitToolCallDoneEvent = function _ChatCompletionStream_emitToolCallDoneEvent2(choiceSnapshot, toolCallIndex) {
9766
9805
  const state = __classPrivateFieldGet6(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_getChoiceEventState).call(this, choiceSnapshot);
9767
9806
  if (state.done_tool_calls.has(toolCallIndex)) {
9768
9807
  return;
@@ -9785,7 +9824,7 @@ class ChatCompletionStream extends AbstractChatCompletionRunner {
9785
9824
  } else {
9786
9825
  assertNever2(toolCallSnapshot.type);
9787
9826
  }
9788
- }, _ChatCompletionStream_emitContentDoneEvents = function _ChatCompletionStream_emitContentDoneEvents(choiceSnapshot) {
9827
+ }, _ChatCompletionStream_emitContentDoneEvents = function _ChatCompletionStream_emitContentDoneEvents2(choiceSnapshot) {
9789
9828
  const state = __classPrivateFieldGet6(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_getChoiceEventState).call(this, choiceSnapshot);
9790
9829
  if (choiceSnapshot.message.content && !state.content_done) {
9791
9830
  state.content_done = true;
@@ -9807,7 +9846,7 @@ class ChatCompletionStream extends AbstractChatCompletionRunner {
9807
9846
  state.logprobs_refusal_done = true;
9808
9847
  this._emit("logprobs.refusal.done", { refusal: choiceSnapshot.logprobs.refusal });
9809
9848
  }
9810
- }, _ChatCompletionStream_endRequest = function _ChatCompletionStream_endRequest() {
9849
+ }, _ChatCompletionStream_endRequest = function _ChatCompletionStream_endRequest2() {
9811
9850
  if (this.ended) {
9812
9851
  throw new OpenAIError(`stream has ended, this shouldn't happen`);
9813
9852
  }
@@ -9818,13 +9857,13 @@ class ChatCompletionStream extends AbstractChatCompletionRunner {
9818
9857
  __classPrivateFieldSet5(this, _ChatCompletionStream_currentChatCompletionSnapshot, undefined, "f");
9819
9858
  __classPrivateFieldSet5(this, _ChatCompletionStream_choiceEventStates, [], "f");
9820
9859
  return finalizeChatCompletion(snapshot, __classPrivateFieldGet6(this, _ChatCompletionStream_params, "f"));
9821
- }, _ChatCompletionStream_getAutoParseableResponseFormat = function _ChatCompletionStream_getAutoParseableResponseFormat() {
9860
+ }, _ChatCompletionStream_getAutoParseableResponseFormat = function _ChatCompletionStream_getAutoParseableResponseFormat2() {
9822
9861
  const responseFormat = __classPrivateFieldGet6(this, _ChatCompletionStream_params, "f")?.response_format;
9823
9862
  if (isAutoParsableResponseFormat(responseFormat)) {
9824
9863
  return responseFormat;
9825
9864
  }
9826
9865
  return null;
9827
- }, _ChatCompletionStream_accumulateChatCompletion = function _ChatCompletionStream_accumulateChatCompletion(chunk) {
9866
+ }, _ChatCompletionStream_accumulateChatCompletion = function _ChatCompletionStream_accumulateChatCompletion2(chunk) {
9828
9867
  var _a, _b, _c, _d;
9829
9868
  let snapshot = __classPrivateFieldGet6(this, _ChatCompletionStream_currentChatCompletionSnapshot, "f");
9830
9869
  const { choices, ...rest } = chunk;
@@ -11050,11 +11089,11 @@ class ResponseStream extends EventStream {
11050
11089
  }
11051
11090
  return __classPrivateFieldGet7(this, _ResponseStream_instances, "m", _ResponseStream_endRequest).call(this);
11052
11091
  }
11053
- [(_ResponseStream_params = new WeakMap, _ResponseStream_currentResponseSnapshot = new WeakMap, _ResponseStream_finalResponse = new WeakMap, _ResponseStream_instances = new WeakSet, _ResponseStream_beginRequest = function _ResponseStream_beginRequest() {
11092
+ [(_ResponseStream_params = new WeakMap, _ResponseStream_currentResponseSnapshot = new WeakMap, _ResponseStream_finalResponse = new WeakMap, _ResponseStream_instances = new WeakSet, _ResponseStream_beginRequest = function _ResponseStream_beginRequest2() {
11054
11093
  if (this.ended)
11055
11094
  return;
11056
11095
  __classPrivateFieldSet6(this, _ResponseStream_currentResponseSnapshot, undefined, "f");
11057
- }, _ResponseStream_addEvent = function _ResponseStream_addEvent(event, starting_after) {
11096
+ }, _ResponseStream_addEvent = function _ResponseStream_addEvent2(event, starting_after) {
11058
11097
  if (this.ended)
11059
11098
  return;
11060
11099
  const maybeEmit = (name, event2) => {
@@ -11102,7 +11141,7 @@ class ResponseStream extends EventStream {
11102
11141
  maybeEmit(event.type, event);
11103
11142
  break;
11104
11143
  }
11105
- }, _ResponseStream_endRequest = function _ResponseStream_endRequest() {
11144
+ }, _ResponseStream_endRequest = function _ResponseStream_endRequest2() {
11106
11145
  if (this.ended) {
11107
11146
  throw new OpenAIError(`stream has ended, this shouldn't happen`);
11108
11147
  }
@@ -11114,7 +11153,7 @@ class ResponseStream extends EventStream {
11114
11153
  const parsedResponse = finalizeResponse(snapshot, __classPrivateFieldGet7(this, _ResponseStream_params, "f"));
11115
11154
  __classPrivateFieldSet6(this, _ResponseStream_finalResponse, parsedResponse, "f");
11116
11155
  return parsedResponse;
11117
- }, _ResponseStream_accumulateResponse = function _ResponseStream_accumulateResponse(event) {
11156
+ }, _ResponseStream_accumulateResponse = function _ResponseStream_accumulateResponse2(event) {
11118
11157
  let snapshot = __classPrivateFieldGet7(this, _ResponseStream_currentResponseSnapshot, "f");
11119
11158
  if (!snapshot) {
11120
11159
  if (event.type !== "response.created") {
@@ -11700,13 +11739,34 @@ var openai_default = OpenAI;
11700
11739
  import { readFileSync as readFileSync2 } from "fs";
11701
11740
 
11702
11741
  // src/lib/config.ts
11703
- import { readFileSync, writeFileSync, mkdirSync as mkdirSync2, existsSync } from "fs";
11742
+ import { readFileSync, writeFileSync, mkdirSync as mkdirSync2, existsSync as existsSync2, readdirSync as readdirSync2, copyFileSync as copyFileSync2, statSync as statSync2 } from "fs";
11704
11743
  import { join as join2, dirname as dirname2 } from "path";
11705
11744
  import { homedir as homedir2 } from "os";
11706
11745
  var CONFIG_KEYS = ["OPENAI_API_KEY", "THINKER_LABS_API_KEY", "THINKER_LABS_BASE_URL"];
11707
- var CONFIG_PATH = join2(homedir2(), ".brains", "config.json");
11746
+ function resolveConfigPath() {
11747
+ const home = process.env["HOME"] || process.env["USERPROFILE"] || homedir2();
11748
+ const newDir = join2(home, ".hasna", "brains");
11749
+ const oldDir = join2(home, ".brains");
11750
+ if (existsSync2(oldDir) && !existsSync2(newDir)) {
11751
+ mkdirSync2(newDir, { recursive: true });
11752
+ try {
11753
+ for (const file of readdirSync2(oldDir)) {
11754
+ const oldPath = join2(oldDir, file);
11755
+ const newPath = join2(newDir, file);
11756
+ try {
11757
+ if (statSync2(oldPath).isFile()) {
11758
+ copyFileSync2(oldPath, newPath);
11759
+ }
11760
+ } catch {}
11761
+ }
11762
+ } catch {}
11763
+ }
11764
+ mkdirSync2(newDir, { recursive: true });
11765
+ return join2(newDir, "config.json");
11766
+ }
11767
+ var CONFIG_PATH = resolveConfigPath();
11708
11768
  function readConfigFile() {
11709
- if (!existsSync(CONFIG_PATH))
11769
+ if (!existsSync2(CONFIG_PATH))
11710
11770
  return {};
11711
11771
  try {
11712
11772
  return JSON.parse(readFileSync(CONFIG_PATH, "utf-8"));
@@ -12184,7 +12244,7 @@ finetuneCmd.command("start").description("Start a fine-tuning job").requiredOpti
12184
12244
  datasetPath = latest.filePath;
12185
12245
  printInfo(`Using latest dataset: ${datasetPath} (${latest.exampleCount} examples)`);
12186
12246
  }
12187
- if (!existsSync3(datasetPath)) {
12247
+ if (!existsSync4(datasetPath)) {
12188
12248
  printError(`Dataset file not found: ${datasetPath}`);
12189
12249
  process.exit(1);
12190
12250
  }
@@ -12422,7 +12482,7 @@ dataCmd.command("gather").description("Gather training data from agent memory so
12422
12482
  }
12423
12483
  });
12424
12484
  dataCmd.command("preview <file>").description("Preview a JSONL training file").option("-n, --count <n>", "Number of examples to show", "5").action((file, opts) => {
12425
- if (!existsSync3(file)) {
12485
+ if (!existsSync4(file)) {
12426
12486
  printError(`File not found: ${file}`);
12427
12487
  process.exit(1);
12428
12488
  }
@@ -12460,7 +12520,7 @@ dataCmd.command("preview <file>").description("Preview a JSONL training file").o
12460
12520
  dataCmd.command("merge <files...>").description("Merge multiple JSONL datasets into one").option("--output <path>", "Output file path", join7(DEFAULT_DATASETS_DIR, `merged-${Date.now()}.jsonl`)).option("--no-dedupe", "Skip deduplication").action(async (files, opts) => {
12461
12521
  try {
12462
12522
  for (const f of files) {
12463
- if (!existsSync3(f)) {
12523
+ if (!existsSync4(f)) {
12464
12524
  printError(`File not found: ${f}`);
12465
12525
  process.exit(1);
12466
12526
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/db/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAItC,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AAEtC,cAAc,aAAa,CAAC;AAS5B,wBAAgB,KAAK,CAAC,MAAM,CAAC,EAAE,MAAM;;EAqDpC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/db/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAItC,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AAEtC,cAAc,aAAa,CAAC;AAsC5B,wBAAgB,KAAK,CAAC,MAAM,CAAC,EAAE,MAAM;;EAqDpC"}
package/dist/index.js CHANGED
@@ -1,12 +1,16 @@
1
1
  // @bun
2
2
  var __defProp = Object.defineProperty;
3
+ var __returnValue = (v) => v;
4
+ function __exportSetter(name, newValue) {
5
+ this[name] = __returnValue.bind(null, newValue);
6
+ }
3
7
  var __export = (target, all) => {
4
8
  for (var name in all)
5
9
  __defProp(target, name, {
6
10
  get: all[name],
7
11
  enumerable: true,
8
12
  configurable: true,
9
- set: (newValue) => all[name] = () => newValue
13
+ set: __exportSetter.bind(all, name)
10
14
  });
11
15
  };
12
16
  // node_modules/drizzle-orm/bun-sqlite/driver.js
@@ -3686,7 +3690,7 @@ function migrate(db, config) {
3686
3690
 
3687
3691
  // src/db/index.ts
3688
3692
  import { Database as Database2 } from "bun:sqlite";
3689
- import { mkdirSync } from "fs";
3693
+ import { mkdirSync, existsSync, readdirSync, copyFileSync, statSync } from "fs";
3690
3694
  import { dirname, join, resolve } from "path";
3691
3695
  import { homedir } from "os";
3692
3696
 
@@ -3735,7 +3739,28 @@ var trainingDatasets = sqliteTable("training_datasets", {
3735
3739
  });
3736
3740
 
3737
3741
  // src/db/index.ts
3738
- var DEFAULT_DB_PATH = join(homedir(), ".brains", "brains.db");
3742
+ function resolveDefaultDbPath() {
3743
+ const home = process.env["HOME"] || process.env["USERPROFILE"] || homedir();
3744
+ const newDir = join(home, ".hasna", "brains");
3745
+ const oldDir = join(home, ".brains");
3746
+ if (existsSync(oldDir) && !existsSync(newDir)) {
3747
+ mkdirSync(newDir, { recursive: true });
3748
+ try {
3749
+ for (const file of readdirSync(oldDir)) {
3750
+ const oldPath = join(oldDir, file);
3751
+ const newPath = join(newDir, file);
3752
+ try {
3753
+ if (statSync(oldPath).isFile()) {
3754
+ copyFileSync(oldPath, newPath);
3755
+ }
3756
+ } catch {}
3757
+ }
3758
+ } catch {}
3759
+ }
3760
+ mkdirSync(newDir, { recursive: true });
3761
+ return join(newDir, "brains.db");
3762
+ }
3763
+ var DEFAULT_DB_PATH = resolveDefaultDbPath();
3739
3764
  function ensureDir(filePath) {
3740
3765
  mkdirSync(dirname(filePath), { recursive: true });
3741
3766
  }
@@ -7253,11 +7278,11 @@ class ChatCompletionStream extends AbstractChatCompletionRunner {
7253
7278
  }
7254
7279
  return this._addChatCompletion(__classPrivateFieldGet6(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_endRequest).call(this));
7255
7280
  }
7256
- [(_ChatCompletionStream_params = new WeakMap, _ChatCompletionStream_choiceEventStates = new WeakMap, _ChatCompletionStream_currentChatCompletionSnapshot = new WeakMap, _ChatCompletionStream_instances = new WeakSet, _ChatCompletionStream_beginRequest = function _ChatCompletionStream_beginRequest() {
7281
+ [(_ChatCompletionStream_params = new WeakMap, _ChatCompletionStream_choiceEventStates = new WeakMap, _ChatCompletionStream_currentChatCompletionSnapshot = new WeakMap, _ChatCompletionStream_instances = new WeakSet, _ChatCompletionStream_beginRequest = function _ChatCompletionStream_beginRequest2() {
7257
7282
  if (this.ended)
7258
7283
  return;
7259
7284
  __classPrivateFieldSet5(this, _ChatCompletionStream_currentChatCompletionSnapshot, undefined, "f");
7260
- }, _ChatCompletionStream_getChoiceEventState = function _ChatCompletionStream_getChoiceEventState(choice) {
7285
+ }, _ChatCompletionStream_getChoiceEventState = function _ChatCompletionStream_getChoiceEventState2(choice) {
7261
7286
  let state = __classPrivateFieldGet6(this, _ChatCompletionStream_choiceEventStates, "f")[choice.index];
7262
7287
  if (state) {
7263
7288
  return state;
@@ -7272,7 +7297,7 @@ class ChatCompletionStream extends AbstractChatCompletionRunner {
7272
7297
  };
7273
7298
  __classPrivateFieldGet6(this, _ChatCompletionStream_choiceEventStates, "f")[choice.index] = state;
7274
7299
  return state;
7275
- }, _ChatCompletionStream_addChunk = function _ChatCompletionStream_addChunk(chunk) {
7300
+ }, _ChatCompletionStream_addChunk = function _ChatCompletionStream_addChunk2(chunk) {
7276
7301
  if (this.ended)
7277
7302
  return;
7278
7303
  const completion = __classPrivateFieldGet6(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_accumulateChatCompletion).call(this, chunk);
@@ -7339,7 +7364,7 @@ class ChatCompletionStream extends AbstractChatCompletionRunner {
7339
7364
  }
7340
7365
  }
7341
7366
  }
7342
- }, _ChatCompletionStream_emitToolCallDoneEvent = function _ChatCompletionStream_emitToolCallDoneEvent(choiceSnapshot, toolCallIndex) {
7367
+ }, _ChatCompletionStream_emitToolCallDoneEvent = function _ChatCompletionStream_emitToolCallDoneEvent2(choiceSnapshot, toolCallIndex) {
7343
7368
  const state = __classPrivateFieldGet6(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_getChoiceEventState).call(this, choiceSnapshot);
7344
7369
  if (state.done_tool_calls.has(toolCallIndex)) {
7345
7370
  return;
@@ -7362,7 +7387,7 @@ class ChatCompletionStream extends AbstractChatCompletionRunner {
7362
7387
  } else {
7363
7388
  assertNever2(toolCallSnapshot.type);
7364
7389
  }
7365
- }, _ChatCompletionStream_emitContentDoneEvents = function _ChatCompletionStream_emitContentDoneEvents(choiceSnapshot) {
7390
+ }, _ChatCompletionStream_emitContentDoneEvents = function _ChatCompletionStream_emitContentDoneEvents2(choiceSnapshot) {
7366
7391
  const state = __classPrivateFieldGet6(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_getChoiceEventState).call(this, choiceSnapshot);
7367
7392
  if (choiceSnapshot.message.content && !state.content_done) {
7368
7393
  state.content_done = true;
@@ -7384,7 +7409,7 @@ class ChatCompletionStream extends AbstractChatCompletionRunner {
7384
7409
  state.logprobs_refusal_done = true;
7385
7410
  this._emit("logprobs.refusal.done", { refusal: choiceSnapshot.logprobs.refusal });
7386
7411
  }
7387
- }, _ChatCompletionStream_endRequest = function _ChatCompletionStream_endRequest() {
7412
+ }, _ChatCompletionStream_endRequest = function _ChatCompletionStream_endRequest2() {
7388
7413
  if (this.ended) {
7389
7414
  throw new OpenAIError(`stream has ended, this shouldn't happen`);
7390
7415
  }
@@ -7395,13 +7420,13 @@ class ChatCompletionStream extends AbstractChatCompletionRunner {
7395
7420
  __classPrivateFieldSet5(this, _ChatCompletionStream_currentChatCompletionSnapshot, undefined, "f");
7396
7421
  __classPrivateFieldSet5(this, _ChatCompletionStream_choiceEventStates, [], "f");
7397
7422
  return finalizeChatCompletion(snapshot, __classPrivateFieldGet6(this, _ChatCompletionStream_params, "f"));
7398
- }, _ChatCompletionStream_getAutoParseableResponseFormat = function _ChatCompletionStream_getAutoParseableResponseFormat() {
7423
+ }, _ChatCompletionStream_getAutoParseableResponseFormat = function _ChatCompletionStream_getAutoParseableResponseFormat2() {
7399
7424
  const responseFormat = __classPrivateFieldGet6(this, _ChatCompletionStream_params, "f")?.response_format;
7400
7425
  if (isAutoParsableResponseFormat(responseFormat)) {
7401
7426
  return responseFormat;
7402
7427
  }
7403
7428
  return null;
7404
- }, _ChatCompletionStream_accumulateChatCompletion = function _ChatCompletionStream_accumulateChatCompletion(chunk) {
7429
+ }, _ChatCompletionStream_accumulateChatCompletion = function _ChatCompletionStream_accumulateChatCompletion2(chunk) {
7405
7430
  var _a, _b, _c, _d;
7406
7431
  let snapshot = __classPrivateFieldGet6(this, _ChatCompletionStream_currentChatCompletionSnapshot, "f");
7407
7432
  const { choices, ...rest } = chunk;
@@ -8627,11 +8652,11 @@ class ResponseStream extends EventStream {
8627
8652
  }
8628
8653
  return __classPrivateFieldGet7(this, _ResponseStream_instances, "m", _ResponseStream_endRequest).call(this);
8629
8654
  }
8630
- [(_ResponseStream_params = new WeakMap, _ResponseStream_currentResponseSnapshot = new WeakMap, _ResponseStream_finalResponse = new WeakMap, _ResponseStream_instances = new WeakSet, _ResponseStream_beginRequest = function _ResponseStream_beginRequest() {
8655
+ [(_ResponseStream_params = new WeakMap, _ResponseStream_currentResponseSnapshot = new WeakMap, _ResponseStream_finalResponse = new WeakMap, _ResponseStream_instances = new WeakSet, _ResponseStream_beginRequest = function _ResponseStream_beginRequest2() {
8631
8656
  if (this.ended)
8632
8657
  return;
8633
8658
  __classPrivateFieldSet6(this, _ResponseStream_currentResponseSnapshot, undefined, "f");
8634
- }, _ResponseStream_addEvent = function _ResponseStream_addEvent(event, starting_after) {
8659
+ }, _ResponseStream_addEvent = function _ResponseStream_addEvent2(event, starting_after) {
8635
8660
  if (this.ended)
8636
8661
  return;
8637
8662
  const maybeEmit = (name, event2) => {
@@ -8679,7 +8704,7 @@ class ResponseStream extends EventStream {
8679
8704
  maybeEmit(event.type, event);
8680
8705
  break;
8681
8706
  }
8682
- }, _ResponseStream_endRequest = function _ResponseStream_endRequest() {
8707
+ }, _ResponseStream_endRequest = function _ResponseStream_endRequest2() {
8683
8708
  if (this.ended) {
8684
8709
  throw new OpenAIError(`stream has ended, this shouldn't happen`);
8685
8710
  }
@@ -8691,7 +8716,7 @@ class ResponseStream extends EventStream {
8691
8716
  const parsedResponse = finalizeResponse(snapshot, __classPrivateFieldGet7(this, _ResponseStream_params, "f"));
8692
8717
  __classPrivateFieldSet6(this, _ResponseStream_finalResponse, parsedResponse, "f");
8693
8718
  return parsedResponse;
8694
- }, _ResponseStream_accumulateResponse = function _ResponseStream_accumulateResponse(event) {
8719
+ }, _ResponseStream_accumulateResponse = function _ResponseStream_accumulateResponse2(event) {
8695
8720
  let snapshot = __classPrivateFieldGet7(this, _ResponseStream_currentResponseSnapshot, "f");
8696
8721
  if (!snapshot) {
8697
8722
  if (event.type !== "response.created") {
@@ -9277,13 +9302,34 @@ var openai_default = OpenAI;
9277
9302
  import { readFileSync as readFileSync2 } from "fs";
9278
9303
 
9279
9304
  // src/lib/config.ts
9280
- import { readFileSync, writeFileSync, mkdirSync as mkdirSync2, existsSync } from "fs";
9305
+ import { readFileSync, writeFileSync, mkdirSync as mkdirSync2, existsSync as existsSync2, readdirSync as readdirSync2, copyFileSync as copyFileSync2, statSync as statSync2 } from "fs";
9281
9306
  import { join as join2, dirname as dirname2 } from "path";
9282
9307
  import { homedir as homedir2 } from "os";
9283
9308
  var CONFIG_KEYS = ["OPENAI_API_KEY", "THINKER_LABS_API_KEY", "THINKER_LABS_BASE_URL"];
9284
- var CONFIG_PATH = join2(homedir2(), ".brains", "config.json");
9309
+ function resolveConfigPath() {
9310
+ const home = process.env["HOME"] || process.env["USERPROFILE"] || homedir2();
9311
+ const newDir = join2(home, ".hasna", "brains");
9312
+ const oldDir = join2(home, ".brains");
9313
+ if (existsSync2(oldDir) && !existsSync2(newDir)) {
9314
+ mkdirSync2(newDir, { recursive: true });
9315
+ try {
9316
+ for (const file of readdirSync2(oldDir)) {
9317
+ const oldPath = join2(oldDir, file);
9318
+ const newPath = join2(newDir, file);
9319
+ try {
9320
+ if (statSync2(oldPath).isFile()) {
9321
+ copyFileSync2(oldPath, newPath);
9322
+ }
9323
+ } catch {}
9324
+ }
9325
+ } catch {}
9326
+ }
9327
+ mkdirSync2(newDir, { recursive: true });
9328
+ return join2(newDir, "config.json");
9329
+ }
9330
+ var CONFIG_PATH = resolveConfigPath();
9285
9331
  function readConfigFile() {
9286
- if (!existsSync(CONFIG_PATH))
9332
+ if (!existsSync2(CONFIG_PATH))
9287
9333
  return {};
9288
9334
  try {
9289
9335
  return JSON.parse(readFileSync(CONFIG_PATH, "utf-8"));
@@ -9538,7 +9584,7 @@ class ThinkerLabsProvider {
9538
9584
  }
9539
9585
  }
9540
9586
  // src/lib/package-metadata.ts
9541
- import { existsSync as existsSync2, readFileSync as readFileSync3 } from "fs";
9587
+ import { existsSync as existsSync3, readFileSync as readFileSync3 } from "fs";
9542
9588
  import { dirname as dirname3, resolve as resolve2 } from "path";
9543
9589
  import { fileURLToPath } from "url";
9544
9590
  var DEFAULT_VERSION = "0.0.0";
@@ -9551,7 +9597,7 @@ function getPackageVersion() {
9551
9597
  return cachedVersion;
9552
9598
  }
9553
9599
  const packageJsonPath = getPackageJsonPath();
9554
- if (!existsSync2(packageJsonPath)) {
9600
+ if (!existsSync3(packageJsonPath)) {
9555
9601
  cachedVersion = DEFAULT_VERSION;
9556
9602
  return cachedVersion;
9557
9603
  }
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/lib/config.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,WAAW,8EAA+E,CAAC;AACxG,MAAM,MAAM,SAAS,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC;AAkBrD,wBAAgB,cAAc,CAAC,GAAG,EAAE,SAAS,GAAG,MAAM,GAAG,SAAS,CAIjE;AAED,wBAAgB,cAAc,CAAC,GAAG,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAIlE;AAED,wBAAgB,UAAU,IAAI,KAAK,CAAC;IAAE,GAAG,EAAE,SAAS,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,KAAK,GAAG,MAAM,GAAG,OAAO,CAAA;CAAE,CAAC,CAOvG;AAED,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,SAAS,GAAG,IAAI,CAItD"}
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/lib/config.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,WAAW,8EAA+E,CAAC;AACxG,MAAM,MAAM,SAAS,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC;AA+CrD,wBAAgB,cAAc,CAAC,GAAG,EAAE,SAAS,GAAG,MAAM,GAAG,SAAS,CAIjE;AAED,wBAAgB,cAAc,CAAC,GAAG,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAIlE;AAED,wBAAgB,UAAU,IAAI,KAAK,CAAC;IAAE,GAAG,EAAE,SAAS,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,KAAK,GAAG,MAAM,GAAG,OAAO,CAAA;CAAE,CAAC,CAOvG;AAED,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,SAAS,GAAG,IAAI,CAItD"}
package/dist/mcp/index.js CHANGED
@@ -1,28 +1,17 @@
1
1
  #!/usr/bin/env bun
2
2
  // @bun
3
- var __create = Object.create;
4
- var __getProtoOf = Object.getPrototypeOf;
5
3
  var __defProp = Object.defineProperty;
6
- var __getOwnPropNames = Object.getOwnPropertyNames;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __toESM = (mod, isNodeMode, target) => {
9
- target = mod != null ? __create(__getProtoOf(mod)) : {};
10
- const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
11
- for (let key of __getOwnPropNames(mod))
12
- if (!__hasOwnProp.call(to, key))
13
- __defProp(to, key, {
14
- get: () => mod[key],
15
- enumerable: true
16
- });
17
- return to;
18
- };
4
+ var __returnValue = (v) => v;
5
+ function __exportSetter(name, newValue) {
6
+ this[name] = __returnValue.bind(null, newValue);
7
+ }
19
8
  var __export = (target, all) => {
20
9
  for (var name in all)
21
10
  __defProp(target, name, {
22
11
  get: all[name],
23
12
  enumerable: true,
24
13
  configurable: true,
25
- set: (newValue) => all[name] = () => newValue
14
+ set: __exportSetter.bind(all, name)
26
15
  });
27
16
  };
28
17
  var __require = import.meta.require;
@@ -34,7 +23,7 @@ import {
34
23
  CallToolRequestSchema,
35
24
  ListToolsRequestSchema
36
25
  } from "@modelcontextprotocol/sdk/types.js";
37
- import { readFileSync as readFileSync4, existsSync as existsSync4 } from "fs";
26
+ import { readFileSync as readFileSync4, existsSync as existsSync5 } from "fs";
38
27
  import { resolve as resolve3 } from "path";
39
28
  import { homedir as homedir7 } from "os";
40
29
 
@@ -3715,7 +3704,7 @@ function migrate(db, config) {
3715
3704
 
3716
3705
  // src/db/index.ts
3717
3706
  import { Database as Database2 } from "bun:sqlite";
3718
- import { mkdirSync } from "fs";
3707
+ import { mkdirSync, existsSync, readdirSync, copyFileSync, statSync } from "fs";
3719
3708
  import { dirname, join, resolve } from "path";
3720
3709
  import { homedir } from "os";
3721
3710
 
@@ -3764,7 +3753,28 @@ var trainingDatasets = sqliteTable("training_datasets", {
3764
3753
  });
3765
3754
 
3766
3755
  // src/db/index.ts
3767
- var DEFAULT_DB_PATH = join(homedir(), ".brains", "brains.db");
3756
+ function resolveDefaultDbPath() {
3757
+ const home = process.env["HOME"] || process.env["USERPROFILE"] || homedir();
3758
+ const newDir = join(home, ".hasna", "brains");
3759
+ const oldDir = join(home, ".brains");
3760
+ if (existsSync(oldDir) && !existsSync(newDir)) {
3761
+ mkdirSync(newDir, { recursive: true });
3762
+ try {
3763
+ for (const file of readdirSync(oldDir)) {
3764
+ const oldPath = join(oldDir, file);
3765
+ const newPath = join(newDir, file);
3766
+ try {
3767
+ if (statSync(oldPath).isFile()) {
3768
+ copyFileSync(oldPath, newPath);
3769
+ }
3770
+ } catch {}
3771
+ }
3772
+ } catch {}
3773
+ }
3774
+ mkdirSync(newDir, { recursive: true });
3775
+ return join(newDir, "brains.db");
3776
+ }
3777
+ var DEFAULT_DB_PATH = resolveDefaultDbPath();
3768
3778
  function ensureDir(filePath) {
3769
3779
  mkdirSync(dirname(filePath), { recursive: true });
3770
3780
  }
@@ -7283,11 +7293,11 @@ class ChatCompletionStream extends AbstractChatCompletionRunner {
7283
7293
  }
7284
7294
  return this._addChatCompletion(__classPrivateFieldGet6(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_endRequest).call(this));
7285
7295
  }
7286
- [(_ChatCompletionStream_params = new WeakMap, _ChatCompletionStream_choiceEventStates = new WeakMap, _ChatCompletionStream_currentChatCompletionSnapshot = new WeakMap, _ChatCompletionStream_instances = new WeakSet, _ChatCompletionStream_beginRequest = function _ChatCompletionStream_beginRequest() {
7296
+ [(_ChatCompletionStream_params = new WeakMap, _ChatCompletionStream_choiceEventStates = new WeakMap, _ChatCompletionStream_currentChatCompletionSnapshot = new WeakMap, _ChatCompletionStream_instances = new WeakSet, _ChatCompletionStream_beginRequest = function _ChatCompletionStream_beginRequest2() {
7287
7297
  if (this.ended)
7288
7298
  return;
7289
7299
  __classPrivateFieldSet5(this, _ChatCompletionStream_currentChatCompletionSnapshot, undefined, "f");
7290
- }, _ChatCompletionStream_getChoiceEventState = function _ChatCompletionStream_getChoiceEventState(choice) {
7300
+ }, _ChatCompletionStream_getChoiceEventState = function _ChatCompletionStream_getChoiceEventState2(choice) {
7291
7301
  let state = __classPrivateFieldGet6(this, _ChatCompletionStream_choiceEventStates, "f")[choice.index];
7292
7302
  if (state) {
7293
7303
  return state;
@@ -7302,7 +7312,7 @@ class ChatCompletionStream extends AbstractChatCompletionRunner {
7302
7312
  };
7303
7313
  __classPrivateFieldGet6(this, _ChatCompletionStream_choiceEventStates, "f")[choice.index] = state;
7304
7314
  return state;
7305
- }, _ChatCompletionStream_addChunk = function _ChatCompletionStream_addChunk(chunk) {
7315
+ }, _ChatCompletionStream_addChunk = function _ChatCompletionStream_addChunk2(chunk) {
7306
7316
  if (this.ended)
7307
7317
  return;
7308
7318
  const completion = __classPrivateFieldGet6(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_accumulateChatCompletion).call(this, chunk);
@@ -7369,7 +7379,7 @@ class ChatCompletionStream extends AbstractChatCompletionRunner {
7369
7379
  }
7370
7380
  }
7371
7381
  }
7372
- }, _ChatCompletionStream_emitToolCallDoneEvent = function _ChatCompletionStream_emitToolCallDoneEvent(choiceSnapshot, toolCallIndex) {
7382
+ }, _ChatCompletionStream_emitToolCallDoneEvent = function _ChatCompletionStream_emitToolCallDoneEvent2(choiceSnapshot, toolCallIndex) {
7373
7383
  const state = __classPrivateFieldGet6(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_getChoiceEventState).call(this, choiceSnapshot);
7374
7384
  if (state.done_tool_calls.has(toolCallIndex)) {
7375
7385
  return;
@@ -7392,7 +7402,7 @@ class ChatCompletionStream extends AbstractChatCompletionRunner {
7392
7402
  } else {
7393
7403
  assertNever2(toolCallSnapshot.type);
7394
7404
  }
7395
- }, _ChatCompletionStream_emitContentDoneEvents = function _ChatCompletionStream_emitContentDoneEvents(choiceSnapshot) {
7405
+ }, _ChatCompletionStream_emitContentDoneEvents = function _ChatCompletionStream_emitContentDoneEvents2(choiceSnapshot) {
7396
7406
  const state = __classPrivateFieldGet6(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_getChoiceEventState).call(this, choiceSnapshot);
7397
7407
  if (choiceSnapshot.message.content && !state.content_done) {
7398
7408
  state.content_done = true;
@@ -7414,7 +7424,7 @@ class ChatCompletionStream extends AbstractChatCompletionRunner {
7414
7424
  state.logprobs_refusal_done = true;
7415
7425
  this._emit("logprobs.refusal.done", { refusal: choiceSnapshot.logprobs.refusal });
7416
7426
  }
7417
- }, _ChatCompletionStream_endRequest = function _ChatCompletionStream_endRequest() {
7427
+ }, _ChatCompletionStream_endRequest = function _ChatCompletionStream_endRequest2() {
7418
7428
  if (this.ended) {
7419
7429
  throw new OpenAIError(`stream has ended, this shouldn't happen`);
7420
7430
  }
@@ -7425,13 +7435,13 @@ class ChatCompletionStream extends AbstractChatCompletionRunner {
7425
7435
  __classPrivateFieldSet5(this, _ChatCompletionStream_currentChatCompletionSnapshot, undefined, "f");
7426
7436
  __classPrivateFieldSet5(this, _ChatCompletionStream_choiceEventStates, [], "f");
7427
7437
  return finalizeChatCompletion(snapshot, __classPrivateFieldGet6(this, _ChatCompletionStream_params, "f"));
7428
- }, _ChatCompletionStream_getAutoParseableResponseFormat = function _ChatCompletionStream_getAutoParseableResponseFormat() {
7438
+ }, _ChatCompletionStream_getAutoParseableResponseFormat = function _ChatCompletionStream_getAutoParseableResponseFormat2() {
7429
7439
  const responseFormat = __classPrivateFieldGet6(this, _ChatCompletionStream_params, "f")?.response_format;
7430
7440
  if (isAutoParsableResponseFormat(responseFormat)) {
7431
7441
  return responseFormat;
7432
7442
  }
7433
7443
  return null;
7434
- }, _ChatCompletionStream_accumulateChatCompletion = function _ChatCompletionStream_accumulateChatCompletion(chunk) {
7444
+ }, _ChatCompletionStream_accumulateChatCompletion = function _ChatCompletionStream_accumulateChatCompletion2(chunk) {
7435
7445
  var _a, _b, _c, _d;
7436
7446
  let snapshot = __classPrivateFieldGet6(this, _ChatCompletionStream_currentChatCompletionSnapshot, "f");
7437
7447
  const { choices, ...rest } = chunk;
@@ -8657,11 +8667,11 @@ class ResponseStream extends EventStream {
8657
8667
  }
8658
8668
  return __classPrivateFieldGet7(this, _ResponseStream_instances, "m", _ResponseStream_endRequest).call(this);
8659
8669
  }
8660
- [(_ResponseStream_params = new WeakMap, _ResponseStream_currentResponseSnapshot = new WeakMap, _ResponseStream_finalResponse = new WeakMap, _ResponseStream_instances = new WeakSet, _ResponseStream_beginRequest = function _ResponseStream_beginRequest() {
8670
+ [(_ResponseStream_params = new WeakMap, _ResponseStream_currentResponseSnapshot = new WeakMap, _ResponseStream_finalResponse = new WeakMap, _ResponseStream_instances = new WeakSet, _ResponseStream_beginRequest = function _ResponseStream_beginRequest2() {
8661
8671
  if (this.ended)
8662
8672
  return;
8663
8673
  __classPrivateFieldSet6(this, _ResponseStream_currentResponseSnapshot, undefined, "f");
8664
- }, _ResponseStream_addEvent = function _ResponseStream_addEvent(event, starting_after) {
8674
+ }, _ResponseStream_addEvent = function _ResponseStream_addEvent2(event, starting_after) {
8665
8675
  if (this.ended)
8666
8676
  return;
8667
8677
  const maybeEmit = (name, event2) => {
@@ -8709,7 +8719,7 @@ class ResponseStream extends EventStream {
8709
8719
  maybeEmit(event.type, event);
8710
8720
  break;
8711
8721
  }
8712
- }, _ResponseStream_endRequest = function _ResponseStream_endRequest() {
8722
+ }, _ResponseStream_endRequest = function _ResponseStream_endRequest2() {
8713
8723
  if (this.ended) {
8714
8724
  throw new OpenAIError(`stream has ended, this shouldn't happen`);
8715
8725
  }
@@ -8721,7 +8731,7 @@ class ResponseStream extends EventStream {
8721
8731
  const parsedResponse = finalizeResponse(snapshot, __classPrivateFieldGet7(this, _ResponseStream_params, "f"));
8722
8732
  __classPrivateFieldSet6(this, _ResponseStream_finalResponse, parsedResponse, "f");
8723
8733
  return parsedResponse;
8724
- }, _ResponseStream_accumulateResponse = function _ResponseStream_accumulateResponse(event) {
8734
+ }, _ResponseStream_accumulateResponse = function _ResponseStream_accumulateResponse2(event) {
8725
8735
  let snapshot = __classPrivateFieldGet7(this, _ResponseStream_currentResponseSnapshot, "f");
8726
8736
  if (!snapshot) {
8727
8737
  if (event.type !== "response.created") {
@@ -9307,12 +9317,33 @@ var openai_default = OpenAI;
9307
9317
  import { readFileSync as readFileSync2 } from "fs";
9308
9318
 
9309
9319
  // src/lib/config.ts
9310
- import { readFileSync, writeFileSync, mkdirSync as mkdirSync2, existsSync } from "fs";
9320
+ import { readFileSync, writeFileSync, mkdirSync as mkdirSync2, existsSync as existsSync2, readdirSync as readdirSync2, copyFileSync as copyFileSync2, statSync as statSync2 } from "fs";
9311
9321
  import { join as join2, dirname as dirname2 } from "path";
9312
9322
  import { homedir as homedir2 } from "os";
9313
- var CONFIG_PATH = join2(homedir2(), ".brains", "config.json");
9323
+ function resolveConfigPath() {
9324
+ const home = process.env["HOME"] || process.env["USERPROFILE"] || homedir2();
9325
+ const newDir = join2(home, ".hasna", "brains");
9326
+ const oldDir = join2(home, ".brains");
9327
+ if (existsSync2(oldDir) && !existsSync2(newDir)) {
9328
+ mkdirSync2(newDir, { recursive: true });
9329
+ try {
9330
+ for (const file of readdirSync2(oldDir)) {
9331
+ const oldPath = join2(oldDir, file);
9332
+ const newPath = join2(newDir, file);
9333
+ try {
9334
+ if (statSync2(oldPath).isFile()) {
9335
+ copyFileSync2(oldPath, newPath);
9336
+ }
9337
+ } catch {}
9338
+ }
9339
+ } catch {}
9340
+ }
9341
+ mkdirSync2(newDir, { recursive: true });
9342
+ return join2(newDir, "config.json");
9343
+ }
9344
+ var CONFIG_PATH = resolveConfigPath();
9314
9345
  function readConfigFile() {
9315
- if (!existsSync(CONFIG_PATH))
9346
+ if (!existsSync2(CONFIG_PATH))
9316
9347
  return {};
9317
9348
  try {
9318
9349
  return JSON.parse(readFileSync(CONFIG_PATH, "utf-8"));
@@ -9794,7 +9825,7 @@ async function gatherFromConversations(options = {}) {
9794
9825
 
9795
9826
  // src/lib/gatherers/sessions.ts
9796
9827
  import { readdir, readFile, stat } from "fs/promises";
9797
- import { existsSync as existsSync2 } from "fs";
9828
+ import { existsSync as existsSync3 } from "fs";
9798
9829
  import { join as join6 } from "path";
9799
9830
  import { homedir as homedir6 } from "os";
9800
9831
  var SYSTEM_PROMPT4 = "You are Claude Code, an AI assistant built by Anthropic that helps developers with coding, architecture, debugging, and software engineering tasks.";
@@ -9808,7 +9839,7 @@ async function gatherFromSessions(options = {}) {
9808
9839
  const { limit: limit2 = 1000 } = options;
9809
9840
  const examples = [];
9810
9841
  const claudeDir = join6(homedir6(), ".claude", "projects");
9811
- if (!existsSync2(claudeDir)) {
9842
+ if (!existsSync3(claudeDir)) {
9812
9843
  return { source: "sessions", examples: [], count: 0 };
9813
9844
  }
9814
9845
  const projectDirs = await readdir(claudeDir).catch(() => []);
@@ -9870,7 +9901,7 @@ async function gatherFromSessions(options = {}) {
9870
9901
  }
9871
9902
 
9872
9903
  // src/lib/package-metadata.ts
9873
- import { existsSync as existsSync3, readFileSync as readFileSync3 } from "fs";
9904
+ import { existsSync as existsSync4, readFileSync as readFileSync3 } from "fs";
9874
9905
  import { dirname as dirname3, resolve as resolve2 } from "path";
9875
9906
  import { fileURLToPath } from "url";
9876
9907
  var DEFAULT_VERSION = "0.0.0";
@@ -9883,7 +9914,7 @@ function getPackageVersion() {
9883
9914
  return cachedVersion;
9884
9915
  }
9885
9916
  const packageJsonPath = getPackageJsonPath();
9886
- if (!existsSync3(packageJsonPath)) {
9917
+ if (!existsSync4(packageJsonPath)) {
9887
9918
  cachedVersion = DEFAULT_VERSION;
9888
9919
  return cachedVersion;
9889
9920
  }
@@ -14090,7 +14121,7 @@ function createMcpServer() {
14090
14121
  }
14091
14122
  resolvedPath = latest.filePath;
14092
14123
  }
14093
- if (!existsSync4(resolvedPath)) {
14124
+ if (!existsSync5(resolvedPath)) {
14094
14125
  return {
14095
14126
  content: [
14096
14127
  {
@@ -14216,7 +14247,7 @@ function createMcpServer() {
14216
14247
  case "preview_training_data": {
14217
14248
  const { file_path, limit: limit2 = 5 } = args;
14218
14249
  const resolvedPath = resolve3(file_path);
14219
- if (!existsSync4(resolvedPath)) {
14250
+ if (!existsSync5(resolvedPath)) {
14220
14251
  return {
14221
14252
  content: [
14222
14253
  { type: "text", text: `File not found: ${resolvedPath}` }
@@ -1,28 +1,17 @@
1
1
  #!/usr/bin/env bun
2
2
  // @bun
3
- var __create = Object.create;
4
- var __getProtoOf = Object.getPrototypeOf;
5
3
  var __defProp = Object.defineProperty;
6
- var __getOwnPropNames = Object.getOwnPropertyNames;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __toESM = (mod, isNodeMode, target) => {
9
- target = mod != null ? __create(__getProtoOf(mod)) : {};
10
- const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
11
- for (let key of __getOwnPropNames(mod))
12
- if (!__hasOwnProp.call(to, key))
13
- __defProp(to, key, {
14
- get: () => mod[key],
15
- enumerable: true
16
- });
17
- return to;
18
- };
4
+ var __returnValue = (v) => v;
5
+ function __exportSetter(name, newValue) {
6
+ this[name] = __returnValue.bind(null, newValue);
7
+ }
19
8
  var __export = (target, all) => {
20
9
  for (var name in all)
21
10
  __defProp(target, name, {
22
11
  get: all[name],
23
12
  enumerable: true,
24
13
  configurable: true,
25
- set: (newValue) => all[name] = () => newValue
14
+ set: __exportSetter.bind(all, name)
26
15
  });
27
16
  };
28
17
  var __require = import.meta.require;
@@ -3707,7 +3696,7 @@ function migrate(db, config) {
3707
3696
 
3708
3697
  // src/db/index.ts
3709
3698
  import { Database as Database2 } from "bun:sqlite";
3710
- import { mkdirSync } from "fs";
3699
+ import { mkdirSync, existsSync, readdirSync, copyFileSync, statSync } from "fs";
3711
3700
  import { dirname, join, resolve } from "path";
3712
3701
  import { homedir } from "os";
3713
3702
 
@@ -3756,7 +3745,28 @@ var trainingDatasets = sqliteTable("training_datasets", {
3756
3745
  });
3757
3746
 
3758
3747
  // src/db/index.ts
3759
- var DEFAULT_DB_PATH = join(homedir(), ".brains", "brains.db");
3748
+ function resolveDefaultDbPath() {
3749
+ const home = process.env["HOME"] || process.env["USERPROFILE"] || homedir();
3750
+ const newDir = join(home, ".hasna", "brains");
3751
+ const oldDir = join(home, ".brains");
3752
+ if (existsSync(oldDir) && !existsSync(newDir)) {
3753
+ mkdirSync(newDir, { recursive: true });
3754
+ try {
3755
+ for (const file of readdirSync(oldDir)) {
3756
+ const oldPath = join(oldDir, file);
3757
+ const newPath = join(newDir, file);
3758
+ try {
3759
+ if (statSync(oldPath).isFile()) {
3760
+ copyFileSync(oldPath, newPath);
3761
+ }
3762
+ } catch {}
3763
+ }
3764
+ } catch {}
3765
+ }
3766
+ mkdirSync(newDir, { recursive: true });
3767
+ return join(newDir, "brains.db");
3768
+ }
3769
+ var DEFAULT_DB_PATH = resolveDefaultDbPath();
3760
3770
  function ensureDir(filePath) {
3761
3771
  mkdirSync(dirname(filePath), { recursive: true });
3762
3772
  }
@@ -3812,7 +3822,7 @@ function getDb(dbPath) {
3812
3822
  }
3813
3823
 
3814
3824
  // src/lib/package-metadata.ts
3815
- import { existsSync, readFileSync } from "fs";
3825
+ import { existsSync as existsSync2, readFileSync } from "fs";
3816
3826
  import { dirname as dirname2, resolve as resolve2 } from "path";
3817
3827
  import { fileURLToPath } from "url";
3818
3828
  var DEFAULT_VERSION = "0.0.0";
@@ -3825,7 +3835,7 @@ function getPackageVersion() {
3825
3835
  return cachedVersion;
3826
3836
  }
3827
3837
  const packageJsonPath = getPackageJsonPath();
3828
- if (!existsSync(packageJsonPath)) {
3838
+ if (!existsSync2(packageJsonPath)) {
3829
3839
  cachedVersion = DEFAULT_VERSION;
3830
3840
  return cachedVersion;
3831
3841
  }
@@ -4089,7 +4099,7 @@ async function gatherFromConversations(options = {}) {
4089
4099
 
4090
4100
  // src/lib/gatherers/sessions.ts
4091
4101
  import { readdir, readFile, stat } from "fs/promises";
4092
- import { existsSync as existsSync2 } from "fs";
4102
+ import { existsSync as existsSync3 } from "fs";
4093
4103
  import { join as join5 } from "path";
4094
4104
  import { homedir as homedir5 } from "os";
4095
4105
  var SYSTEM_PROMPT4 = "You are Claude Code, an AI assistant built by Anthropic that helps developers with coding, architecture, debugging, and software engineering tasks.";
@@ -4103,7 +4113,7 @@ async function gatherFromSessions(options = {}) {
4103
4113
  const { limit = 1000 } = options;
4104
4114
  const examples = [];
4105
4115
  const claudeDir = join5(homedir5(), ".claude", "projects");
4106
- if (!existsSync2(claudeDir)) {
4116
+ if (!existsSync3(claudeDir)) {
4107
4117
  return { source: "sessions", examples: [], count: 0 };
4108
4118
  }
4109
4119
  const projectDirs = await readdir(claudeDir).catch(() => []);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hasna/brains",
3
- "version": "0.0.8",
3
+ "version": "0.0.10",
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",
@@ -46,6 +46,7 @@
46
46
  "cli"
47
47
  ],
48
48
  "publishConfig": {
49
+ "registry": "https://registry.npmjs.org",
49
50
  "access": "public"
50
51
  },
51
52
  "repository": {