@miphamai/cli 0.81.0 → 0.81.1

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@miphamai/cli",
3
- "version": "0.81.0",
3
+ "version": "0.81.1",
4
4
  "description": "Mipham Code — Multi-model open-core intelligent coding terminal by MiphamAI",
5
5
  "keywords": [
6
6
  "ai",
@@ -1,5 +1,6 @@
1
1
  import { mkdirSync, readFileSync, writeFileSync, existsSync, unlinkSync } from 'node:fs'
2
2
  import { join } from 'node:path'
3
+ import { homedir } from 'node:os'
3
4
  import { ExperienceRuleExtractor, type ExperienceRule } from './experience-rules.js'
4
5
 
5
6
  const MAX_EXPERIENCES = 20
@@ -10,7 +11,7 @@ export class AgentExperience {
10
11
 
11
12
  constructor(
12
13
  private readonly agentName: string,
13
- baseDir: string = join(process.env.HOME || '~', '.mipham', 'agent-memory'),
14
+ baseDir: string = join(homedir(), '.mipham', 'agent-memory'),
14
15
  ) {
15
16
  this.expDir = join(baseDir, agentName)
16
17
  this.expFile = join(this.expDir, 'experience.md')
@@ -1,5 +1,6 @@
1
1
  import { mkdirSync, readFileSync, writeFileSync, existsSync } from 'node:fs'
2
2
  import { join, dirname } from 'node:path'
3
+ import { homedir } from 'node:os'
3
4
  import type { CrsiProvenanceBridge, CrsiVerdict } from './crsi-provenance-bridge.js'
4
5
  import { isRecoverableToolFailure } from './recoverable-failure.js'
5
6
 
@@ -31,7 +32,7 @@ export class EffectivenessTracker {
31
32
  private storePath: string
32
33
  private provenanceBridge?: CrsiProvenanceBridge
33
34
 
34
- constructor(storeDir: string = join(process.env.HOME || '~', '.mipham', 'rule-engine')) {
35
+ constructor(storeDir: string = join(homedir(), '.mipham', 'rule-engine')) {
35
36
  this.storePath = join(storeDir, STORE_FILE)
36
37
  this.data = new Map()
37
38
  }
@@ -11,6 +11,7 @@
11
11
 
12
12
  import { mkdirSync, writeFileSync, existsSync, chmodSync } from 'node:fs'
13
13
  import { join, resolve } from 'node:path'
14
+ import { homedir } from 'node:os'
14
15
 
15
16
  export interface ScaffoldResult {
16
17
  created: string[]
@@ -87,7 +88,7 @@ export function scaffoldLoopKit(basePath: string): ScaffoldResult {
87
88
  const created: string[] = []
88
89
  const skipped: string[] = []
89
90
 
90
- const resolved = resolve(basePath.replace(/^~/, process.env.HOME || '~'))
91
+ const resolved = resolve(basePath.replace(/^~/, homedir()))
91
92
  const miphamDir = join(resolved, '.mipham')
92
93
 
93
94
  // ── .mipham/ root ──
@@ -8,6 +8,7 @@
8
8
  import type { CommandHandler, CommandContext, CommandResult } from '../ui/commands.js'
9
9
  import { getWorkspaceTrust } from '../core/workspace-trust'
10
10
  import { atomicWriteFileSync } from '../shared/atomic-write'
11
+ import { homedir } from 'node:os'
11
12
 
12
13
  export {
13
14
  initCmd,
@@ -311,7 +312,7 @@ const setupCmd: CommandHandler = async (ctx, args) => {
311
312
  const { existsSync } = await import('node:fs')
312
313
  const { join } = await import('node:path')
313
314
  const cwd = process.cwd()
314
- const home = process.env.HOME || '~'
315
+ const home = homedir()
315
316
 
316
317
  const hasProjectMipham = existsSync(join(cwd, 'MIPHAM.md'))
317
318
  const hasProjectConfig = existsSync(join(cwd, '.mipham', 'config.yml'))
@@ -688,7 +689,7 @@ permission boundaries. Adding directories here extends read/write access.`,
688
689
 
689
690
  const { existsSync } = await import('node:fs')
690
691
  const { resolve } = await import('node:path')
691
- const resolved = resolve(dir.replace(/^~/, process.env.HOME || '~'))
692
+ const resolved = resolve(dir.replace(/^~/, homedir()))
692
693
 
693
694
  if (!existsSync(resolved)) {
694
695
  return { content: `✗ Directory not found: ${resolved}\n\nCheck the path and try again.` }
@@ -1,5 +1,6 @@
1
1
  import { readFileSync, existsSync } from 'node:fs'
2
2
  import { join, resolve, relative, sep, isAbsolute } from 'node:path'
3
+ import { homedir } from 'node:os'
3
4
  import { execSync } from 'node:child_process'
4
5
  import { parse as parseYaml } from 'yaml'
5
6
  import type { InstructionFile } from '../shared/index.ts'
@@ -126,7 +127,7 @@ export class InstructionsLoader {
126
127
  })
127
128
 
128
129
  // Tier 3: 用户层 ~/.mipham/USER.md
129
- const home = process.env.HOME || '~'
130
+ const home = homedir()
130
131
  this.tryLoad(join(home, '.mipham', 'USER.md'), 'user')
131
132
 
132
133
  // CRSI 教训召回:读 crsi-lessons.md 提取精华,注入系统提示(只写不读 → 写后召回)
@@ -1,6 +1,7 @@
1
1
  import type { ExperienceRule } from '../agent/experience-rules.js'
2
2
  import { mkdirSync, writeFileSync, readFileSync, existsSync } from 'node:fs'
3
3
  import { join, dirname } from 'node:path'
4
+ import { homedir } from 'node:os'
4
5
  import { MANAGED_RULES } from './crsi-managed-rules'
5
6
 
6
7
  export interface ToolRule {
@@ -61,7 +62,7 @@ export class ExperienceRuleEngine {
61
62
  private rules: ToolRule[]
62
63
  private storePath: string
63
64
 
64
- constructor(storeDir: string = join(process.env.HOME || '~', '.mipham', 'rule-engine')) {
65
+ constructor(storeDir: string = join(homedir(), '.mipham', 'rule-engine')) {
65
66
  this.rules = [...BUILTIN_RULES, ...MANAGED_RULES].map((r) => ({ ...r }))
66
67
  this.storePath = join(storeDir, 'rules.json')
67
68
  this.load()
@@ -1,4 +1,5 @@
1
1
  import { appendFileSync, readFileSync, mkdirSync, existsSync } from 'node:fs'
2
+ import { homedir } from 'node:os'
2
3
  import { join } from 'node:path'
3
4
  import { createHash } from 'node:crypto'
4
5
  import type { Message, ToolUseContent, ToolResultContent, ToolResult } from '../shared/types'
@@ -101,7 +102,7 @@ export function deriveMessages(events: SessionEvent[]): Message[] {
101
102
  return out
102
103
  }
103
104
 
104
- const HOME = process.env.HOME || '~'
105
+ const HOME = homedir()
105
106
  const LOG_DIR = join(HOME, '.mipham', 'sessions')
106
107
 
107
108
  /** 将会话名消毒为安全文件名(与 SessionStore 共用;防路径穿越)。 */
@@ -8,6 +8,7 @@ import {
8
8
  existsSync,
9
9
  statSync,
10
10
  } from 'node:fs'
11
+ import { homedir } from 'node:os'
11
12
  import { join } from 'node:path'
12
13
  import { createHash } from 'node:crypto'
13
14
  import type { Message } from '../shared/types'
@@ -28,7 +29,7 @@ export interface StoredSession {
28
29
  messages: Message[]
29
30
  }
30
31
 
31
- const HOME = process.env.HOME || '~'
32
+ const HOME = homedir()
32
33
  const SESSIONS_DIR = join(HOME, '.mipham', 'sessions')
33
34
  const INDEX_FILE = join(SESSIONS_DIR, '.index.json')
34
35
  const SUMMARIES_DIR = join(SESSIONS_DIR, '.summaries')
@@ -1,6 +1,7 @@
1
1
  // apps/cli/src/daemon/database.ts
2
2
  import { Database } from 'bun:sqlite'
3
3
  import { readdirSync, readFileSync, existsSync } from 'node:fs'
4
+ import { homedir } from 'node:os'
4
5
  import { join } from 'node:path'
5
6
  import type {
6
7
  DaemonSession,
@@ -339,7 +340,7 @@ export class DaemonDatabase {
339
340
  // ── Migration ──────────────────────────────────────────────
340
341
 
341
342
  migrateFromJsonl(): number {
342
- const sessionsDir = join(process.env.HOME || '/tmp', '.mipham', 'sessions')
343
+ const sessionsDir = join(homedir(), '.mipham', 'sessions')
343
344
 
344
345
  if (!existsSync(sessionsDir)) return 0
345
346
 
@@ -9,7 +9,7 @@
9
9
  export const PACKAGE_NAME = '@miphamai/cli' as const
10
10
 
11
11
  /** 当前发布版本 */
12
- export const PACKAGE_VERSION = '0.81.0' as const
12
+ export const PACKAGE_VERSION = '0.81.1' as const
13
13
 
14
14
  /** npm install 全局安装命令 */
15
15
  export const NPM_INSTALL_COMMAND = `npm install -g ${PACKAGE_NAME}` as const
@@ -1,9 +1,10 @@
1
1
  import { readFileSync, writeFileSync, existsSync, mkdirSync } from 'node:fs'
2
2
  import { join } from 'node:path'
3
+ import { homedir } from 'node:os'
3
4
  import { parse as parseYaml, stringify } from 'yaml'
4
5
  import type { ToolDefinition } from '../../shared/index.ts'
5
6
 
6
- const MIPHAM_DIR = join(process.env.HOME || '~', '.mipham')
7
+ const MIPHAM_DIR = join(homedir(), '.mipham')
7
8
  const USER_CONFIG = join(MIPHAM_DIR, 'config.yml')
8
9
 
9
10
  export const configTool: ToolDefinition = {
package/src/ui/chat.tsx CHANGED
@@ -2,6 +2,7 @@ import React, { useMemo } from 'react'
2
2
  import { Box, Text } from 'ink'
3
3
  import { useI18n } from '../i18n-context'
4
4
  import type { ChatMessage } from './app'
5
+ import { homedir } from 'node:os'
5
6
 
6
7
  interface ChatPanelProps {
7
8
  messages: ChatMessage[]
@@ -11,7 +12,7 @@ interface ChatPanelProps {
11
12
  /** Format cwd for display: replace HOME with ~, truncate if too long */
12
13
  function displayCwd(): string {
13
14
  const cwd = process.cwd()
14
- const home = process.env.HOME || ''
15
+ const home = homedir()
15
16
  if (home && cwd.startsWith(home)) {
16
17
  return '~' + cwd.slice(home.length)
17
18
  }
@@ -18,6 +18,7 @@ import { InstructionsLoader } from '../core/instructions'
18
18
  import { findDerivableSections, DERIVABLE_HINTS } from '../core/claude-md-audit'
19
19
  import { fixDoctor, fixConfig, fixCache, selectRepoClaudeFiles } from '../core/fix'
20
20
  import { fixCodeTarget } from '../core/fix-code'
21
+ import { homedir } from 'node:os'
21
22
  import { runCrsiModification, approvePending, rejectPending, hasPending } from '../core/crsi-modify'
22
23
  import {
23
24
  produceCrsiProposal,
@@ -2573,7 +2574,7 @@ const installPluginCmd: CommandHandler = async (ctx, args) => {
2573
2574
 
2574
2575
  if (isLocalPath) {
2575
2576
  const { resolve } = await import('node:path')
2576
- const resolved = resolve(target.replace(/^~/, process.env.HOME || '~'))
2577
+ const resolved = resolve(target.replace(/^~/, homedir()))
2577
2578
  result = manager.install(resolved)
2578
2579
  } else {
2579
2580
  // Treat as npm package name
@@ -2882,7 +2883,7 @@ const loopCmd: CommandHandler = async (ctx, args) => {
2882
2883
  const { scaffoldLoopKit } = await import('../commands/loop-scaffold')
2883
2884
  const { created, skipped } = scaffoldLoopKit(targetPath)
2884
2885
  const { resolve } = await import('node:path')
2885
- const resolved = resolve(targetPath.replace(/^~/, process.env.HOME || '~'))
2886
+ const resolved = resolve(targetPath.replace(/^~/, homedir()))
2886
2887
 
2887
2888
  const lines: string[] = ['── LoopKit Vault Created ──', '', `Location: ${resolved}`, '']
2888
2889
 
@@ -3721,7 +3722,7 @@ const cdCmd: CommandHandler = async (ctx, args) => {
3721
3722
 
3722
3723
  const { existsSync } = await import('node:fs')
3723
3724
  const { resolve } = await import('node:path')
3724
- const resolved = resolve(target.replace(/^~/, process.env.HOME || '~'))
3725
+ const resolved = resolve(target.replace(/^~/, homedir()))
3725
3726
 
3726
3727
  if (!existsSync(resolved)) {
3727
3728
  const suggestions = suggestDirectories(resolved)
@@ -4118,7 +4119,7 @@ const memoryCmd: CommandHandler = async (ctx, args) => {
4118
4119
  const { existsSync, readdirSync, readFileSync, statSync } = await import('node:fs')
4119
4120
  const { join } = await import('node:path')
4120
4121
 
4121
- const home = process.env.HOME || '~'
4122
+ const home = homedir()
4122
4123
  const memoryDir = join(home, '.mipham', 'memory')
4123
4124
 
4124
4125
  // /memory gc — 记忆卫生:归档「0 召回 + 过期」的 auto-* 记忆(手写只报告)
@@ -4320,7 +4321,7 @@ const workflowsCmd: CommandHandler = async () => {
4320
4321
 
4321
4322
  const locations = [
4322
4323
  join(process.cwd(), '.claude', 'workflows'),
4323
- join(process.env.HOME || '~', '.claude', 'workflows'),
4324
+ join(homedir(), '.claude', 'workflows'),
4324
4325
  ]
4325
4326
 
4326
4327
  const lines: string[] = ['─ Workflows ─', '']
@@ -4418,7 +4419,7 @@ const workflowRunCmd = async (name: string): Promise<CommandResult> => {
4418
4419
 
4419
4420
  const locations = [
4420
4421
  join(process.cwd(), '.claude', 'workflows'),
4421
- join(process.env.HOME || '~', '.claude', 'workflows'),
4422
+ join(homedir(), '.claude', 'workflows'),
4422
4423
  ]
4423
4424
 
4424
4425
  for (const loc of locations) {
@@ -4739,7 +4740,7 @@ const logoutCmd: CommandHandler = async () => {
4739
4740
  const { existsSync } = await import('node:fs')
4740
4741
  const { join } = await import('node:path')
4741
4742
 
4742
- const home = process.env.HOME || '~'
4743
+ const home = homedir()
4743
4744
  const userConfig = join(home, '.mipham', 'config.yml')
4744
4745
  const hasUserConfig = existsSync(userConfig)
4745
4746