ei-tui 1.6.8 → 1.7.0

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.
Files changed (47) hide show
  1. package/README.md +4 -0
  2. package/package.json +2 -1
  3. package/skills/coding-harness-reflect/SKILL.md +230 -0
  4. package/skills/ei-curate/SKILL.md +174 -0
  5. package/skills/ei-curate/references/cli.md +160 -0
  6. package/skills/ei-curate/references/provenance.md +88 -0
  7. package/skills/ei-curate/references/recipes.md +144 -0
  8. package/skills/ei-curate/references/talking-to-the-user.md +71 -0
  9. package/skills/ei-persona/SKILL.md +238 -0
  10. package/skills/ei-persona/references/cli.md +265 -0
  11. package/skills/ei-persona/references/recipes.md +247 -0
  12. package/skills/ei-persona/references/talking-to-the-user.md +107 -0
  13. package/src/cli/README.md +72 -2
  14. package/src/cli/commands/personas.ts +46 -1
  15. package/src/cli/corrections-endpoints.ts +297 -0
  16. package/src/cli/corrections-writer.ts +138 -0
  17. package/src/cli/install.ts +252 -157
  18. package/src/cli/mcp.ts +80 -1
  19. package/src/cli/persona-corrections.ts +442 -0
  20. package/src/cli/retrieval.ts +46 -2
  21. package/src/cli.ts +148 -1
  22. package/src/core/corrections.ts +233 -0
  23. package/src/core/handlers/human-extraction.ts +8 -2
  24. package/src/core/handlers/human-matching.ts +2 -2
  25. package/src/core/llm-client.ts +7 -1
  26. package/src/core/orchestrators/human-extraction.ts +1 -0
  27. package/src/core/persona-tools.ts +92 -0
  28. package/src/core/personas/opencode-agent.ts +1 -3
  29. package/src/core/processor.ts +113 -1
  30. package/src/core/state/human.ts +10 -0
  31. package/src/core/state/personas.ts +8 -0
  32. package/src/core/state-manager.ts +11 -0
  33. package/src/core/types/entities.ts +1 -0
  34. package/src/core/utils/identifier-utils.ts +3 -2
  35. package/src/integrations/pi/importer.ts +142 -50
  36. package/src/integrations/pi/reader.ts +1 -0
  37. package/src/integrations/pi/types.ts +4 -0
  38. package/src/storage/file-lock.ts +120 -0
  39. package/tui/README.md +2 -0
  40. package/tui/src/commands/provider.tsx +1 -1
  41. package/tui/src/components/WelcomeOverlay.tsx +3 -3
  42. package/tui/src/context/ei.tsx +14 -0
  43. package/tui/src/index.tsx +13 -1
  44. package/tui/src/storage/file.ts +15 -83
  45. package/tui/src/util/instance-lock.ts +3 -2
  46. package/tui/src/util/provider-detection.ts +4 -2
  47. package/tui/src/util/yaml-persona.ts +7 -38
@@ -3,6 +3,7 @@ import {
3
3
  useContext,
4
4
  onMount,
5
5
  onCleanup,
6
+ For,
6
7
  Match,
7
8
  Switch,
8
9
  createSignal,
@@ -183,6 +184,7 @@ export const EiProvider: ParentComponent = (props) => {
183
184
  const [showWelcomeOverlay, setShowWelcomeOverlay] = createSignal(false);
184
185
  const [detectedProviders, setDetectedProviders] = createSignal<ProviderDetectionStatus[]>([]);
185
186
  const [firstBootDefaultModel, setFirstBootDefaultModel] = createSignal<string | undefined>(undefined);
187
+ const [bootError, setBootError] = createSignal<string | null>(null);
186
188
  const [conflictData, setConflictData] = createSignal<StateConflictData | null>(null);
187
189
 
188
190
  let processor: Processor | null = null;
@@ -970,6 +972,7 @@ export const EiProvider: ParentComponent = (props) => {
970
972
  await finishBootstrap();
971
973
  } catch (err: any) {
972
974
  logger.error(`bootstrap() failed: ${err?.message || err}`);
975
+ setBootError(err?.message || String(err));
973
976
  }
974
977
  }
975
978
 
@@ -1089,6 +1092,17 @@ export const EiProvider: ParentComponent = (props) => {
1089
1092
  <Match when={store.ready}>
1090
1093
  <EiContext.Provider value={value}>{props.children}</EiContext.Provider>
1091
1094
  </Match>
1095
+ <Match when={bootError()}>
1096
+ <box width="100%" height="100%" justifyContent="center" alignItems="center" flexDirection="column">
1097
+ <text fg="#dc322f">Ei failed to start</text>
1098
+ <text> </text>
1099
+ <For each={bootError()!.split('\n')}>
1100
+ {(line) => <text fg="#93a1a1">{line || " "}</text>}
1101
+ </For>
1102
+ <text> </text>
1103
+ <text fg="#586e75">Press Ctrl+C to exit</text>
1104
+ </box>
1105
+ </Match>
1092
1106
  <Match when={!store.ready}>
1093
1107
  <box width="100%" height="100%" justifyContent="center" alignItems="center">
1094
1108
  <text>Loading Ei...</text>
package/tui/src/index.tsx CHANGED
@@ -14,7 +14,19 @@ if (args.includes("--version") || args.includes("version") || args.includes("-v"
14
14
 
15
15
  const storage = new FileStorage(Bun.env.EI_DATA_PATH);
16
16
  const lock = new InstanceLock(storage.getDataPath());
17
- const lockResult = await lock.acquire();
17
+ const lockResult = await lock.acquire().catch((e) => {
18
+ const msg = e instanceof Error ? e.message : String(e);
19
+ const dataPath = storage.getDataPath();
20
+ process.stderr.write(
21
+ `\nEi cannot start: cannot write to data directory.\n\n` +
22
+ ` Path: ${dataPath}\n` +
23
+ ` Error: ${msg}\n\n` +
24
+ `Fix options:\n` +
25
+ ` - Fix Permissions (sudo chown $USER $EI_DATA_PATH)\n` +
26
+ ` - Change Data Path (EI_DATA_PATH=~/ei-data ei)\n\n`
27
+ );
28
+ process.exit(1);
29
+ });
18
30
 
19
31
  if (!lockResult.acquired) {
20
32
  process.stderr.write(
@@ -1,6 +1,7 @@
1
1
  import type { StorageState } from "../../../src/core/types";
2
2
  import type { Storage } from "../../../src/storage/interface";
3
3
  import { encodeAllEmbeddings, decodeAllEmbeddings } from "../../../src/storage/embeddings";
4
+ import { withLock, atomicWrite } from "../../../src/storage/file-lock";
4
5
  import { join } from "path";
5
6
  import { mkdir, rename, unlink, readdir } from "fs/promises";
6
7
  import { resolveDataPath } from "../util/resolve-data-path.js";
@@ -8,8 +9,6 @@ import { resolveDataPath } from "../util/resolve-data-path.js";
8
9
  const STATE_FILE = "state.json";
9
10
  const BACKUP_FILE = "state.backup.json";
10
11
  const BACKUPS_DIR = "backups";
11
- const LOCK_TIMEOUT_MS = 5000;
12
- const LOCK_RETRY_DELAY_MS = 50;
13
12
 
14
13
  export class FileStorage implements Storage {
15
14
  private readonly dataPath: string;
@@ -39,9 +38,9 @@ export class FileStorage implements Storage {
39
38
  const filePath = join(this.dataPath, STATE_FILE);
40
39
  state.timestamp = new Date().toISOString();
41
40
 
42
- await this.withLock(filePath, async () => {
41
+ await withLock(filePath, async () => {
43
42
  try {
44
- await this.atomicWrite(filePath, JSON.stringify(encodeAllEmbeddings(state), null, 2));
43
+ await atomicWrite(filePath, JSON.stringify(encodeAllEmbeddings(state), null, 2));
45
44
  } catch (e) {
46
45
  if (this.isQuotaError(e)) {
47
46
  throw new Error("STORAGE_SAVE_FAILED: Disk quota exceeded");
@@ -89,7 +88,7 @@ export class FileStorage implements Storage {
89
88
  async saveBackup(state: StorageState): Promise<void> {
90
89
  await this.ensureDataDir();
91
90
  const backupPath = join(this.dataPath, BACKUP_FILE);
92
- await this.atomicWrite(backupPath, JSON.stringify(encodeAllEmbeddings(state), null, 2));
91
+ await atomicWrite(backupPath, JSON.stringify(encodeAllEmbeddings(state), null, 2));
93
92
  }
94
93
 
95
94
  /**
@@ -130,7 +129,7 @@ export class FileStorage implements Storage {
130
129
  ].join("") + ".json";
131
130
 
132
131
  const destPath = join(backupsPath, name);
133
- await this.atomicWrite(destPath, JSON.stringify(encodeAllEmbeddings(state), null, 2));
132
+ await atomicWrite(destPath, JSON.stringify(encodeAllEmbeddings(state), null, 2));
134
133
 
135
134
  // Prune: keep only the newest maxBackups files
136
135
  const entries = await readdir(backupsPath);
@@ -149,8 +148,16 @@ export class FileStorage implements Storage {
149
148
  private async ensureDataDir(): Promise<void> {
150
149
  try {
151
150
  await mkdir(this.dataPath, { recursive: true });
152
- } catch {
153
- return;
151
+ } catch (e: any) {
152
+ if (e?.code === 'EACCES' || e?.code === 'EPERM') {
153
+ throw new Error(
154
+ `Cannot create data directory: ${this.dataPath}\n` +
155
+ `Fix options:\n` +
156
+ ` - Fix Permissions (sudo chown $USER $EI_DATA_PATH)\n` +
157
+ ` - Change Data Path (EI_DATA_PATH=~/ei-data ei-tui)`
158
+ );
159
+ }
160
+ // Other errors (e.g., race conditions) are safe to ignore
154
161
  }
155
162
  }
156
163
 
@@ -160,79 +167,4 @@ export class FileStorage implements Storage {
160
167
  (e.message.includes("ENOSPC") || e.message.includes("quota"))
161
168
  );
162
169
  }
163
-
164
- private async atomicWrite(filePath: string, content: string): Promise<void> {
165
- const tempPath = `${filePath}.tmp.${Date.now()}.${Math.random().toString(36).slice(2)}`;
166
- try {
167
- await Bun.write(tempPath, content);
168
- await rename(tempPath, filePath);
169
- } catch (e) {
170
- try {
171
- await unlink(tempPath);
172
- } catch {}
173
- throw e;
174
- }
175
- }
176
-
177
- private getLockPath(filePath: string): string {
178
- return `${filePath}.lock`;
179
- }
180
-
181
- private async acquireLock(filePath: string): Promise<boolean> {
182
- const lockPath = this.getLockPath(filePath);
183
- const startTime = Date.now();
184
-
185
- while (Date.now() - startTime < LOCK_TIMEOUT_MS) {
186
- const lockFile = Bun.file(lockPath);
187
- if (await lockFile.exists()) {
188
- // Read may throw if another writer deleted the lock between exists() and text() —
189
- // treat that as "lock is gone, proceed to acquire" by falling through.
190
- let lockContent: string;
191
- try {
192
- lockContent = await lockFile.text();
193
- } catch {
194
- // Lock vanished in the race window — retry from top to re-check state cleanly.
195
- await new Promise((r) => setTimeout(r, LOCK_RETRY_DELAY_MS));
196
- continue;
197
- }
198
- const lockTime = parseInt(lockContent, 10);
199
- if (!isNaN(lockTime) && Date.now() - lockTime > LOCK_TIMEOUT_MS) {
200
- try {
201
- await unlink(lockPath);
202
- } catch {}
203
- } else {
204
- await new Promise((r) => setTimeout(r, LOCK_RETRY_DELAY_MS));
205
- continue;
206
- }
207
- }
208
-
209
- try {
210
- await Bun.write(lockPath, Date.now().toString());
211
- return true;
212
- } catch {
213
- await new Promise((r) => setTimeout(r, LOCK_RETRY_DELAY_MS));
214
- }
215
- }
216
-
217
- return false;
218
- }
219
-
220
- private async releaseLock(filePath: string): Promise<void> {
221
- const lockPath = this.getLockPath(filePath);
222
- try {
223
- await unlink(lockPath);
224
- } catch {}
225
- }
226
-
227
- private async withLock<T>(filePath: string, fn: () => Promise<T>): Promise<T> {
228
- const acquired = await this.acquireLock(filePath);
229
- if (!acquired) {
230
- throw new Error("STORAGE_LOCK_TIMEOUT: Could not acquire file lock");
231
- }
232
- try {
233
- return await fn();
234
- } finally {
235
- await this.releaseLock(filePath);
236
- }
237
- }
238
170
  }
@@ -1,5 +1,5 @@
1
- import { join } from "path";
2
- import { unlink } from "fs/promises";
1
+ import { join, dirname } from "path";
2
+ import { unlink, mkdir } from "fs/promises";
3
3
 
4
4
  const LOCK_FILE = "ei.lock";
5
5
 
@@ -69,6 +69,7 @@ export class InstanceLock {
69
69
  }
70
70
 
71
71
  private async writeLock(): Promise<void> {
72
+ await mkdir(dirname(this.lockPath), { recursive: true });
72
73
  const data: LockData = {
73
74
  pid: process.pid,
74
75
  started: new Date().toISOString(),
@@ -63,8 +63,10 @@ export const ALL_PROVIDER_NAMES: ReadonlyArray<string> = [
63
63
  // For example, Haiku's advertised context is 200k but real-world extraction quality degrades
64
64
  // above ~100k, so we cap it there. When adding new models, prefer conservative values based
65
65
  // on actual usage over marketing specs.
66
- export const KNOWN_MODEL_LIMITS: Readonly<Record<string, { token_limit?: number; max_output_tokens?: number }>> = {
66
+ export const KNOWN_MODEL_LIMITS: Readonly<Record<string, { token_limit?: number; max_output_tokens?: number; temperature_disabled?: boolean }>> = {
67
67
  // Anthropic — claude-opus-4.x
68
+ // Models from 4-8 onward always use extended thinking and reject the temperature parameter.
69
+ "claude-opus-4-8": { token_limit: 200000, max_output_tokens: 128000, temperature_disabled: true },
68
70
  "claude-opus-4-7": { token_limit: 200000, max_output_tokens: 128000 },
69
71
  "claude-opus-4-6": { token_limit: 200000, max_output_tokens: 128000 },
70
72
  "claude-opus-4-5-20251101": { token_limit: 200000, max_output_tokens: 64000 },
@@ -361,9 +363,9 @@ export function buildProviderAccounts(
361
363
  name: modelName,
362
364
  ...(limits?.token_limit !== undefined && { token_limit: limits.token_limit }),
363
365
  ...(limits?.max_output_tokens !== undefined && { max_output_tokens: limits.max_output_tokens }),
366
+ ...(limits?.temperature_disabled === true && { temperature_disabled: true }),
364
367
  };
365
368
  };
366
-
367
369
  const seenNames = new Set<string>();
368
370
  const models: ModelConfig[] = [];
369
371
 
@@ -7,6 +7,7 @@ import type {
7
7
  ProviderAccount,
8
8
  } from "../../../src/core/types.js";
9
9
  import { modelGuidToDisplay, displayToModelGuid } from "./yaml-shared.js";
10
+ import { buildPersonaToolsMap, resolvePersonaToolsFromMap, preserveHiddenToolGrants } from "../../../src/core/persona-tools.js";
10
11
  import { parseDuration, formatDuration } from "./duration.js";
11
12
 
12
13
  const PLACEHOLDER_LONG_DESC = "Detailed description of this persona's personality, background, and role";
@@ -62,43 +63,6 @@ const PLACEHOLDER_TOPIC: YAMLPersonaTopic = {
62
63
  exposure_desired: 0.5,
63
64
  };
64
65
 
65
- function buildPersonaToolsMap(
66
- enabledToolIds: string[],
67
- allTools: ToolDefinition[],
68
- allProviders: import('../../../src/core/types.js').ToolProvider[]
69
- ): Record<string, Record<string, boolean>> | undefined {
70
- if (allTools.length === 0) return undefined;
71
- const enabledSet = new Set(enabledToolIds);
72
- const result: Record<string, Record<string, boolean>> = {};
73
- for (const provider of allProviders.filter(p => p.enabled)) {
74
- const providerTools = allTools.filter(t => t.provider_id === provider.id);
75
- if (providerTools.length === 0) continue;
76
- result[provider.display_name] = Object.fromEntries(
77
- providerTools.map(t => [t.display_name, enabledSet.has(t.id)])
78
- );
79
- }
80
- return Object.keys(result).length > 0 ? result : undefined;
81
- }
82
-
83
- function resolvePersonaToolsFromMap(
84
- toolsMap: Record<string, Record<string, boolean>> | undefined,
85
- allTools: ToolDefinition[],
86
- allProviders: import('../../../src/core/types.js').ToolProvider[]
87
- ): string[] | undefined {
88
- if (!toolsMap) return undefined;
89
- const enabledIds: string[] = [];
90
- for (const [providerDisplayName, toolToggles] of Object.entries(toolsMap)) {
91
- const provider = allProviders.find(p => p.display_name === providerDisplayName);
92
- if (!provider) continue;
93
- for (const [toolDisplayName, enabled] of Object.entries(toolToggles)) {
94
- if (!enabled) continue;
95
- const tool = allTools.find(t => t.provider_id === provider.id && t.display_name === toolDisplayName);
96
- if (tool) enabledIds.push(tool.id);
97
- }
98
- }
99
- return enabledIds.length > 0 ? enabledIds : [];
100
- }
101
-
102
66
  export function newPersonaToYAML(name: string, allTools?: ToolDefinition[], allProviders?: import('../../../src/core/types.js').ToolProvider[]): string {
103
67
  const toolsMap = buildPersonaToolsMap([], allTools ?? [], allProviders ?? []);
104
68
 
@@ -337,7 +301,12 @@ export function personaFromYAML(yamlContent: string, original: PersonaEntity, al
337
301
  pause_until: data.pause_until,
338
302
  is_static: data.is_static ?? false,
339
303
  include_message_timestamps: data.include_message_timestamps ?? false,
340
- tools: resolvePersonaToolsFromMap(data.tools, allTools ?? [], allProviders ?? []),
304
+ tools: preserveHiddenToolGrants(
305
+ resolvePersonaToolsFromMap(data.tools, allTools ?? [], allProviders ?? []),
306
+ original.tools,
307
+ allTools ?? [],
308
+ allProviders ?? []
309
+ ),
341
310
  last_updated: new Date().toISOString(),
342
311
  };
343
312