cliclaw 1.0.2 → 1.0.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/config.ts +15 -7
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cliclaw",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "Telegram bot bridging AI CLIs (Claude Code, Codex) to Forum Topics",
5
5
  "main": "index.ts",
6
6
  "scripts": {
package/src/config.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { existsSync, readFileSync } from 'fs'
2
2
  import { execSync } from 'child_process'
3
+ import { join } from 'path'
3
4
 
4
5
  export type AgentName = 'claude' | 'codex'
5
6
  export type PermissionMode = 'auto' | 'session' | 'ask'
@@ -13,18 +14,25 @@ export interface Config {
13
14
  availableAgents: AgentName[]
14
15
  }
15
16
 
17
+ // Resolve package root relative to this file (works for global npm install too)
18
+ // src/config.ts is 1 level below package root
19
+ const PKG_ROOT = join(__dirname, '..')
20
+
16
21
  function checkAgents(): AgentName[] {
17
22
  const available: AgentName[] = []
18
- const tryWhich = (bin: string) => {
19
- try { execSync(`which ${bin}`, { stdio: 'ignore' }); return true } catch { return false }
23
+ const isWindows = process.platform === 'win32'
24
+ const findCmd = isWindows ? 'where' : 'which'
25
+ const tryFind = (bin: string) => {
26
+ try { execSync(`${findCmd} ${bin}`, { stdio: 'ignore' }); return true } catch { return false }
20
27
  }
21
- if (tryWhich('claude')) available.push('claude')
22
- if (tryWhich('codex')) available.push('codex')
28
+ if (tryFind('claude')) available.push('claude')
29
+ if (tryFind('codex')) available.push('codex')
23
30
  return available
24
31
  }
25
32
 
26
33
  export function loadConfig(): Config {
27
- const envFile = process.env.HOME + '/openclaw/.env'
34
+ // CLICLAW_ENV env var allows override; otherwise resolves to <pkg-root>/.env
35
+ const envFile = process.env.CLICLAW_ENV || join(PKG_ROOT, '.env')
28
36
  if (existsSync(envFile)) {
29
37
  const content = readFileSync(envFile, 'utf-8')
30
38
  for (const line of content.split('\n')) {
@@ -45,7 +53,7 @@ export function loadConfig(): Config {
45
53
 
46
54
  const config: Config = {
47
55
  TELEGRAM_BOT_TOKEN: process.env.TELEGRAM_BOT_TOKEN || '',
48
- DATA_DIR: process.env.DATA_DIR || (process.env.HOME + '/openclaw/data'),
56
+ DATA_DIR: process.env.DATA_DIR || join(PKG_ROOT, 'data'),
49
57
  FORUM_GROUP_ID: process.env.FORUM_GROUP_ID || '',
50
58
  TELEGRAM_ADMIN_IDS: (process.env.TELEGRAM_ADMIN_IDS || '')
51
59
  .split(',').map(id => id.trim()).filter(Boolean),
@@ -54,7 +62,7 @@ export function loadConfig(): Config {
54
62
  }
55
63
 
56
64
  if (!config.TELEGRAM_BOT_TOKEN) {
57
- throw new Error('TELEGRAM_BOT_TOKEN not set in .env')
65
+ throw new Error(`TELEGRAM_BOT_TOKEN not set in .env (looked at: ${envFile})`)
58
66
  }
59
67
 
60
68
  if (config.availableAgents.length === 0) {