shellward 0.4.0 → 0.5.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.
@@ -8,10 +8,11 @@
8
8
  // - All network failures are silent and cached to avoid repeated timeouts
9
9
 
10
10
  import { get } from 'https'
11
- import { readFileSync, writeFileSync } from 'fs'
11
+ import { mkdirSync, readFileSync, writeFileSync } from 'fs'
12
12
  import { join } from 'path'
13
+ import { getHomeDir } from './utils'
13
14
 
14
- const CACHE_DIR = join(process.env.HOME || '~', '.openclaw', 'shellward')
15
+ const CACHE_DIR = join(getHomeDir(), '.openclaw', 'shellward')
15
16
  const CACHE_FILE = join(CACHE_DIR, 'update-cache.json')
16
17
  const VULN_CACHE_FILE = join(CACHE_DIR, 'vuln-db-cache.json')
17
18
  const CHECK_INTERVAL_MS = 24 * 60 * 60 * 1000 // 24 hours
@@ -179,6 +180,7 @@ function readCache<T>(path: string): T | null {
179
180
 
180
181
  function writeCache(path: string, data: unknown): void {
181
182
  try {
183
+ mkdirSync(CACHE_DIR, { recursive: true, mode: 0o700 })
182
184
  writeFileSync(path, JSON.stringify(data), { mode: 0o600 })
183
185
  } catch { /* ignore */ }
184
186
  }
package/src/utils.ts ADDED
@@ -0,0 +1,10 @@
1
+ // src/utils.ts — Cross-platform path helpers
2
+
3
+ import { homedir } from 'os'
4
+
5
+ /**
6
+ * Get user home directory. Works on Windows (USERPROFILE), Linux/macOS (HOME).
7
+ */
8
+ export function getHomeDir(): string {
9
+ return homedir() || process.env.HOME || process.env.USERPROFILE || '~'
10
+ }