@alexwkleung/reika 0.1.2 → 0.2.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.
package/dist/config.js CHANGED
@@ -1,14 +1,61 @@
1
1
  import dotenv from 'dotenv';
2
+ import { readFileSync } from 'node:fs';
2
3
  import { homedir } from 'node:os';
3
4
  import { join } from 'node:path';
4
5
  import { DEFAULT_MIN_GEN_TOKENS } from './provider/budget.js';
5
6
  import { parseMcpServers } from './mcp/config.js';
7
+ // The cwd .env belongs to whatever repo reika was opened in, which may not be the user's. A cloned
8
+ // repo's file must not turn the sandbox or approvals off, start a program (MCP), redirect where
9
+ // requests or logs go, or reach child processes (NODE_OPTIONS, GIT_*, TMPDIR — the last also names
10
+ // a sandbox-writable path), so only REIKA_* keys are read from it and these are not.
11
+ const PROJECT_ENV_DENIED = new Set([
12
+ 'REIKA_SANDBOX',
13
+ 'REIKA_AUTO_APPROVE',
14
+ 'REIKA_MCP',
15
+ 'REIKA_MCP_SERVERS',
16
+ 'REIKA_PASTE_FETCH',
17
+ 'REIKA_SKILL_AUTO',
18
+ 'REIKA_URL_GROUNDING',
19
+ 'REIKA_CDP_SEARCH',
20
+ 'REIKA_CDP_PORT',
21
+ 'REIKA_DEBUG_FILE',
22
+ ]);
23
+ export function isDeniedFromProjectEnv(key) {
24
+ // Every endpoint and key, including REIKA_<NAME>_BASE_URL for a profile the global file defines.
25
+ return PROJECT_ENV_DENIED.has(key) || /_(URL|API_KEY)$/.test(key);
26
+ }
27
+ // Returns the denied keys that would otherwise have taken effect, for the startup notice.
28
+ export function applyProjectEnv(text, env) {
29
+ const ignored = [];
30
+ for (const [key, value] of Object.entries(dotenv.parse(text))) {
31
+ if (!key.startsWith('REIKA_') || key in env)
32
+ continue;
33
+ if (isDeniedFromProjectEnv(key))
34
+ ignored.push(key);
35
+ else
36
+ env[key] = value;
37
+ }
38
+ return ignored;
39
+ }
40
+ export function projectEnvNotice(ignored) {
41
+ if (ignored.length === 0)
42
+ return undefined;
43
+ return `Ignored ${ignored.join(', ')} from ./.env: settings for the sandbox, approvals, endpoints, keys and MCP servers are read only from your shell or ~/.config/reika/.env.`;
44
+ }
45
+ function readTextOrEmpty(path) {
46
+ try {
47
+ return readFileSync(path, 'utf8');
48
+ }
49
+ catch {
50
+ return '';
51
+ }
52
+ }
6
53
  // Precedence: shell env > cwd .env > ~/.config/reika/.env
7
- // dotenv defaults to no-override, so loading cwd first then global gives the right order.
54
+ // Neither file overrides a key already set, so loading cwd first then global gives the right order.
8
55
  // The keys already present before dotenv runs are the ones set at launch (`REIKA_X=1 reika`, or an
9
56
  // export in the shell rc); the persisted session state (#365) defers to those and beats the files.
10
57
  const launchEnvKeys = new Set(Object.keys(process.env));
11
- dotenv.config();
58
+ const ignoredProjectEnvKeys = applyProjectEnv(readTextOrEmpty(join(process.cwd(), '.env')), process.env);
12
59
  dotenv.config({ path: join(homedir(), '.config', 'reika', '.env') });
13
60
  export function setAtLaunch(name) {
14
61
  return launchEnvKeys.has(name);
@@ -88,6 +135,7 @@ export function loadConfig() {
88
135
  cdpPort: parseIntOrUndef(process.env.REIKA_CDP_PORT),
89
136
  profiles,
90
137
  ...parseModeModels(process.env.REIKA_MODE_MODELS, profiles, models),
138
+ projectEnvNotice: projectEnvNotice(ignoredProjectEnvKeys),
91
139
  maxSearchesPerTurn: parseInt(process.env.REIKA_MAX_SEARCHES_PER_TURN ?? '3', 10),
92
140
  maxFetchesPerTurn: parseInt(process.env.REIKA_MAX_FETCHES_PER_TURN ?? '5', 10),
93
141
  bashTimeoutMs: parseInt(process.env.REIKA_BASH_TIMEOUT_MS ?? '1800000', 10),
package/dist/headless.js CHANGED
@@ -110,6 +110,8 @@ export async function runHeadless(args, io) {
110
110
  // The same startup line the TUI shows for a REIKA_MODE_MODELS entry it could not use (#616).
111
111
  for (const problem of config.modeModelErrors ?? [])
112
112
  io.stderr(`reika: ${problem}\n`);
113
+ if (config.projectEnvNotice)
114
+ io.stderr(`reika: ${config.projectEnvNotice}\n`);
113
115
  // An MCP tool typed as a slash command (#265): the same direct call the TUI makes, answered with
114
116
  // the tool's own output instead of a model turn. There is no question for the model to answer —
115
117
  // the user named the tool and its arguments — so this runs before any prompt is built.
package/dist/ui/App.js CHANGED
@@ -479,6 +479,13 @@ export function App() {
479
479
  { role: 'system', content: problem, tone: 'warn', skipAutosave: true },
480
480
  ]);
481
481
  }
482
+ if (cfg.projectEnvNotice) {
483
+ const content = cfg.projectEnvNotice;
484
+ setMessages(prev => [
485
+ ...prev,
486
+ { role: 'system', content, tone: 'warn', skipAutosave: true },
487
+ ]);
488
+ }
482
489
  // MCP: what connected, what failed, and any config error (#265). The healthy summary is the
483
490
  // only line that is good news — the shape `connectNotices` emits — so everything else that
484
491
  // reaches here (a server that did not start, a document that did not parse) is worth
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alexwkleung/reika",
3
- "version": "0.1.2",
3
+ "version": "0.2.0",
4
4
  "description": "Coding agent CLI for local and hosted models, designed around small local models first.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Alex Leung",