ei-tui 1.3.2 → 1.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/package.json +1 -1
- package/src/core/llm-client.ts +2 -2
- package/src/core/utils/index.ts +2 -1
- package/src/core/utils/resolve-data-path.ts +27 -0
- package/tui/src/commands/reflect.tsx +3 -8
- package/tui/src/storage/file.ts +2 -7
- package/tui/src/util/logger.ts +2 -7
- package/tui/src/util/resolve-data-path.ts +7 -0
package/package.json
CHANGED
package/src/core/llm-client.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ChatMessage, ProviderAccount, ModelConfig } from "./types.js";
|
|
2
|
+
import { resolveDataPath } from "./utils/resolve-data-path.js";
|
|
2
3
|
const DEFAULT_TOKEN_LIMIT = 8192;
|
|
3
4
|
const DEFAULT_MAX_OUTPUT_TOKENS = 8000;
|
|
4
5
|
|
|
@@ -11,8 +12,7 @@ async function writeNetworkDump(
|
|
|
11
12
|
request: unknown,
|
|
12
13
|
response: unknown
|
|
13
14
|
): Promise<void> {
|
|
14
|
-
const dataPath = (
|
|
15
|
-
(typeof Bun !== "undefined" && (Bun as Record<string, unknown>).env && ((Bun as { env: Record<string, string> }).env.EI_DATA_PATH));
|
|
15
|
+
const dataPath = resolveDataPath();
|
|
16
16
|
if (!dataPath) return;
|
|
17
17
|
|
|
18
18
|
try {
|
package/src/core/utils/index.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { crossFind } from "./crossFind.js";
|
|
2
2
|
import { applyDecayToValue } from "./decay.js";
|
|
3
3
|
import { UUID_REGEX, sanitizeEiPersonaIdentifiers } from "./identifier-utils.js";
|
|
4
|
+
import { resolveDataPath } from "./resolve-data-path.js";
|
|
4
5
|
|
|
5
|
-
export { crossFind, applyDecayToValue, UUID_REGEX, sanitizeEiPersonaIdentifiers };
|
|
6
|
+
export { crossFind, applyDecayToValue, UUID_REGEX, sanitizeEiPersonaIdentifiers, resolveDataPath };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolves the Ei data directory path using the same precedence everywhere:
|
|
3
|
+
* 1. EI_DATA_PATH env var (explicit override)
|
|
4
|
+
* 2. $XDG_DATA_HOME/ei
|
|
5
|
+
* 3. ~/.local/share/ei
|
|
6
|
+
*
|
|
7
|
+
* Cross-env: works in Bun, Node, and browser (browser will always return null
|
|
8
|
+
* since no filesystem env is available, which is the correct behaviour there).
|
|
9
|
+
*
|
|
10
|
+
* Trailing slashes are stripped so callers can safely do `path.join(dataPath, "logs")`.
|
|
11
|
+
*/
|
|
12
|
+
export function resolveDataPath(): string | null {
|
|
13
|
+
const env: Record<string, string | undefined> =
|
|
14
|
+
(typeof Bun !== "undefined" && (Bun as { env?: Record<string, string> }).env) ||
|
|
15
|
+
(typeof process !== "undefined" && process.env) ||
|
|
16
|
+
{};
|
|
17
|
+
|
|
18
|
+
const raw = env.EI_DATA_PATH ||
|
|
19
|
+
(() => {
|
|
20
|
+
const xdg = env.XDG_DATA_HOME ||
|
|
21
|
+
(env.HOME ? `${env.HOME}/.local/share` : null);
|
|
22
|
+
return xdg ? `${xdg}/ei` : null;
|
|
23
|
+
})();
|
|
24
|
+
|
|
25
|
+
if (!raw) return null;
|
|
26
|
+
return raw.replace(/\/+$/, "");
|
|
27
|
+
}
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
personaPreviewFromYAML,
|
|
12
12
|
} from "../util/yaml-serializers.js";
|
|
13
13
|
import { useKeyboardNav } from "../context/keyboard.js";
|
|
14
|
+
import { resolveDataPath } from "../util/resolve-data-path.js";
|
|
14
15
|
|
|
15
16
|
function wrapComment(text: string, width = 78): string {
|
|
16
17
|
const words = text.split(/\s+/);
|
|
@@ -28,16 +29,10 @@ function wrapComment(text: string, width = 78): string {
|
|
|
28
29
|
return lines.join("\n");
|
|
29
30
|
}
|
|
30
31
|
|
|
31
|
-
function getDataPath(): string {
|
|
32
|
-
const raw = process.env.EI_DATA_PATH ??
|
|
33
|
-
join(process.env.XDG_DATA_HOME ?? join(homedir(), ".local", "share"), "ei");
|
|
34
|
-
return raw.replace(/\/+$/, "");
|
|
35
|
-
}
|
|
36
|
-
|
|
37
32
|
function getReflectFolder(persona: PersonaEntity): string {
|
|
38
33
|
const datePrefix = persona.pending_update!.created_at.slice(0, 10);
|
|
39
34
|
const safeName = persona.display_name.replace(/\s+/g, "_");
|
|
40
|
-
return join(
|
|
35
|
+
return join(resolveDataPath(), "reflect", `${datePrefix}_${safeName}`);
|
|
41
36
|
}
|
|
42
37
|
|
|
43
38
|
async function resolveReflectionPersona(
|
|
@@ -102,7 +97,7 @@ export const reflectCommand: Command = {
|
|
|
102
97
|
|
|
103
98
|
const headerName = hasPending ? activePersona!.display_name : undefined;
|
|
104
99
|
const pendingNames = pendingPersonas.map(p => p.display_name);
|
|
105
|
-
const dataPath =
|
|
100
|
+
const dataPath = resolveDataPath();
|
|
106
101
|
|
|
107
102
|
ctx.showOverlay((hideOverlay, _hideForEditor) => {
|
|
108
103
|
const { setOverlayActive } = useKeyboardNav();
|
package/tui/src/storage/file.ts
CHANGED
|
@@ -3,6 +3,7 @@ import type { Storage } from "../../../src/storage/interface";
|
|
|
3
3
|
import { encodeAllEmbeddings, decodeAllEmbeddings } from "../../../src/storage/embeddings";
|
|
4
4
|
import { join } from "path";
|
|
5
5
|
import { mkdir, rename, unlink, readdir } from "fs/promises";
|
|
6
|
+
import { resolveDataPath } from "../util/resolve-data-path.js";
|
|
6
7
|
|
|
7
8
|
const STATE_FILE = "state.json";
|
|
8
9
|
const BACKUP_FILE = "state.backup.json";
|
|
@@ -14,13 +15,7 @@ export class FileStorage implements Storage {
|
|
|
14
15
|
private readonly dataPath: string;
|
|
15
16
|
|
|
16
17
|
constructor(dataPath?: string) {
|
|
17
|
-
|
|
18
|
-
if (raw) {
|
|
19
|
-
this.dataPath = raw.replace(/\/+$/, "");
|
|
20
|
-
} else {
|
|
21
|
-
const xdgData = process.env.XDG_DATA_HOME || join(process.env.HOME || "~", ".local", "share");
|
|
22
|
-
this.dataPath = join(xdgData, "ei");
|
|
23
|
-
}
|
|
18
|
+
this.dataPath = resolveDataPath(dataPath);
|
|
24
19
|
}
|
|
25
20
|
|
|
26
21
|
getDataPath(): string {
|
package/tui/src/util/logger.ts
CHANGED
|
@@ -2,17 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
import { appendFileSync, mkdirSync, existsSync, readdirSync, unlinkSync, renameSync } from "node:fs";
|
|
4
4
|
import { join } from "node:path";
|
|
5
|
+
import { resolveDataPath } from "./resolve-data-path.js";
|
|
5
6
|
|
|
6
7
|
const MAX_ROLLED_LOGS = 10;
|
|
7
8
|
|
|
8
|
-
function getDataPath(): string {
|
|
9
|
-
if (Bun.env.EI_DATA_PATH) return Bun.env.EI_DATA_PATH;
|
|
10
|
-
const xdgData = Bun.env.XDG_DATA_HOME || join(Bun.env.HOME || "~", ".local", "share");
|
|
11
|
-
return join(xdgData, "ei");
|
|
12
|
-
}
|
|
13
|
-
|
|
14
9
|
function getLogPath(): string {
|
|
15
|
-
return join(
|
|
10
|
+
return join(resolveDataPath(), "tui.log");
|
|
16
11
|
}
|
|
17
12
|
|
|
18
13
|
type LogLevel = "debug" | "info" | "warn" | "error";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { join } from "node:path";
|
|
2
|
+
|
|
3
|
+
export function resolveDataPath(override?: string): string {
|
|
4
|
+
const raw = override ?? Bun.env.EI_DATA_PATH ??
|
|
5
|
+
join(Bun.env.XDG_DATA_HOME ?? join(Bun.env.HOME ?? "~", ".local", "share"), "ei");
|
|
6
|
+
return raw.replace(/\/+$/, "");
|
|
7
|
+
}
|