ray-finance 0.3.2 → 0.3.3
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/ai/context.js +17 -10
- package/package.json +1 -1
package/dist/ai/context.js
CHANGED
|
@@ -1,27 +1,33 @@
|
|
|
1
1
|
import { readFileSync, writeFileSync, existsSync, mkdirSync, chmodSync } from "fs";
|
|
2
|
-
import { resolve } from "path";
|
|
3
|
-
import {
|
|
4
|
-
|
|
2
|
+
import { resolve, dirname, basename } from "path";
|
|
3
|
+
import { config } from "../config.js";
|
|
4
|
+
function getContextFilePath() {
|
|
5
|
+
const dbFile = basename(config.dbPath, ".db");
|
|
6
|
+
const contextFile = dbFile === "finance" ? "context.md" : `context-${dbFile}.md`;
|
|
7
|
+
return resolve(dirname(config.dbPath), "..", contextFile);
|
|
8
|
+
}
|
|
5
9
|
export function getContextPath() {
|
|
6
|
-
return
|
|
10
|
+
return getContextFilePath();
|
|
7
11
|
}
|
|
8
12
|
export function readContext() {
|
|
9
|
-
|
|
13
|
+
const contextPath = getContextFilePath();
|
|
14
|
+
if (!existsSync(contextPath))
|
|
10
15
|
return "";
|
|
11
16
|
try {
|
|
12
|
-
return readFileSync(
|
|
17
|
+
return readFileSync(contextPath, "utf-8");
|
|
13
18
|
}
|
|
14
19
|
catch {
|
|
15
20
|
return "";
|
|
16
21
|
}
|
|
17
22
|
}
|
|
18
23
|
export function writeContext(content) {
|
|
19
|
-
const
|
|
24
|
+
const contextPath = getContextFilePath();
|
|
25
|
+
const dir = dirname(contextPath);
|
|
20
26
|
if (!existsSync(dir))
|
|
21
27
|
mkdirSync(dir, { recursive: true });
|
|
22
|
-
writeFileSync(
|
|
28
|
+
writeFileSync(contextPath, content, { encoding: "utf-8", mode: 0o600 });
|
|
23
29
|
try {
|
|
24
|
-
chmodSync(
|
|
30
|
+
chmodSync(contextPath, 0o600);
|
|
25
31
|
}
|
|
26
32
|
catch { }
|
|
27
33
|
}
|
|
@@ -64,7 +70,8 @@ export function replaceContextSection(section, content) {
|
|
|
64
70
|
writeContext(current);
|
|
65
71
|
}
|
|
66
72
|
export function createContextTemplate(userName) {
|
|
67
|
-
|
|
73
|
+
const contextPath = getContextFilePath();
|
|
74
|
+
if (existsSync(contextPath))
|
|
68
75
|
return; // don't overwrite existing
|
|
69
76
|
const template = `# Financial Context for ${userName}
|
|
70
77
|
|