@miphamai/cli 0.50.0 → 0.52.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 (57) hide show
  1. package/bin/mipham.ts +1 -9
  2. package/package.json +1 -2
  3. package/skills/standard/web-access/references/cdp-api.md +2 -1
  4. package/skills/standard/web-access/scripts/cdp-proxy.mjs +75 -1
  5. package/skills/standard/web-access/scripts/check-deps.mjs +17 -2
  6. package/skills/standard/web-access/scripts/find-url.mjs +0 -0
  7. package/skills/standard/web-access/scripts/match-site.mjs +0 -0
  8. package/skills/standard/web-access.SKILL.md +10 -3
  9. package/src/commands/keys.ts +26 -0
  10. package/src/commands/project.ts +1 -1
  11. package/src/config/credential-crypto.ts +114 -0
  12. package/src/config/defaults.ts +6 -1
  13. package/src/config/loader.ts +65 -14
  14. package/src/core/auto-memory.ts +3 -3
  15. package/src/core/constitution-loader.ts +0 -2
  16. package/src/core/context.ts +0 -1
  17. package/src/core/credential-masker/index.ts +1 -0
  18. package/src/core/credential-masker/matcher.ts +18 -7
  19. package/src/core/credential-masker/search.ts +73 -0
  20. package/src/core/credential-masker.ts +1 -0
  21. package/src/core/crsi-sandbox.ts +0 -1
  22. package/src/core/dream-engine.ts +0 -2
  23. package/src/core/instructions.ts +36 -12
  24. package/src/core/memory/memory-loader.ts +3 -1
  25. package/src/core/permission-rules.ts +23 -12
  26. package/src/core/rules-loader.ts +8 -10
  27. package/src/daemon/database.ts +0 -1
  28. package/src/daemon/feishu/adapter.ts +2 -1
  29. package/src/daemon/index.ts +18 -8
  30. package/src/daemon/server.ts +53 -10
  31. package/src/daemon/session-manager.ts +5 -4
  32. package/src/daemon/telegram/adapter.ts +70 -0
  33. package/src/daemon/telegram/api.ts +45 -0
  34. package/src/daemon/telegram/env.ts +14 -0
  35. package/src/daemon/telegram/poller.ts +64 -0
  36. package/src/daemon/telegram/types.ts +10 -0
  37. package/src/i18n-core/locales/en-US.json +123 -0
  38. package/src/i18n-core/locales/zh-CN.json +123 -0
  39. package/src/index.tsx +10 -8
  40. package/src/mcp/token-store.ts +2 -37
  41. package/src/shared/package-info.ts +1 -1
  42. package/src/shared/types.ts +5 -3
  43. package/src/skills/bin-check.ts +40 -0
  44. package/src/skills/bundled-skill-assets.ts +5 -5
  45. package/src/skills/bundled-skills.ts +1 -1
  46. package/src/skills/loader.ts +35 -10
  47. package/src/skills/sanitizer.ts +1 -2
  48. package/src/skills/seam.ts +1 -1
  49. package/src/tools/agent/exit-plan.ts +1 -3
  50. package/src/tools/agent/memory.ts +2 -1
  51. package/src/tools/agent/skill.ts +14 -0
  52. package/src/tools/file/glob.ts +38 -23
  53. package/src/tools/file/grep.ts +86 -64
  54. package/src/tools/index.ts +5 -5
  55. package/src/ui/commands.ts +191 -119
  56. package/src/ui/config-wizard.tsx +5 -2
  57. package/src/core/tokenizer.ts +0 -80
@@ -13,11 +13,12 @@ import { Box, Text, useInput } from 'ink'
13
13
  import { useI18n } from '../i18n-context'
14
14
  import TextInput from 'ink-text-input'
15
15
  import { DEFAULT_PROVIDERS, OLLAMA_PRESET_MODELS } from '../shared/constants'
16
- import type { ProviderConfig, ModelInfo } from '../shared/types'
16
+ import type { ModelInfo } from '../shared/types'
17
17
  import { mkdirSync, writeFileSync } from 'node:fs'
18
18
  import { join } from 'node:path'
19
19
  import { homedir } from 'node:os'
20
20
  import { execSync } from 'node:child_process'
21
+ import { getCredentialKey, encryptApiKey } from '../config/credential-crypto'
21
22
 
22
23
  // ── Types ──
23
24
 
@@ -93,6 +94,8 @@ function writeConfigFile(providerId: string, modelId: string, apiKey: string): v
93
94
  }
94
95
  return result
95
96
  }
97
+ const storedKey = encryptApiKey(apiKey, getCredentialKey(configDir))
98
+
96
99
  const lines = [
97
100
  '# Mipham Code Configuration',
98
101
  `# Generated by Config Wizard — ${new Date().toISOString()}`,
@@ -107,7 +110,7 @@ function writeConfigFile(providerId: string, modelId: string, apiKey: string): v
107
110
  ` name: ${provider?.name || providerId}`,
108
111
  ` protocol: ${provider?.protocol || 'openai-compatible'}`,
109
112
  ...(provider?.baseUrl ? [` baseUrl: ${provider.baseUrl}`] : []),
110
- ` apiKey: ${apiKey}`,
113
+ ` apiKey: ${storedKey}`,
111
114
  ` models:`,
112
115
  ...models.map((m) => ` - id: ${m.id}`),
113
116
  ]
@@ -1,80 +0,0 @@
1
- import type { Tiktoken } from 'js-tiktoken'
2
- import type { Message } from '../shared/types'
3
-
4
- let encoder: Tiktoken | null = null
5
- let initPromise: Promise<void> | null = null
6
-
7
- async function getEncoder(): Promise<Tiktoken> {
8
- if (encoder) return encoder
9
- if (!initPromise) {
10
- initPromise = (async () => {
11
- const { getEncoding } = await import('js-tiktoken')
12
- encoder = getEncoding('cl100k_base')
13
- })()
14
- }
15
- await initPromise
16
- return encoder!
17
- }
18
-
19
- export class TokenCounter {
20
- private cache = new Map<string, number>()
21
- private initialized = false
22
-
23
- private async ensureInit(): Promise<void> {
24
- if (!this.initialized) {
25
- await getEncoder()
26
- this.initialized = true
27
- }
28
- }
29
-
30
- async count(text: string): Promise<number> {
31
- if (!text) return 0
32
- const cached = this.cache.get(text)
33
- if (cached !== undefined) return cached
34
- await this.ensureInit()
35
- const tokens = encoder!.encode(text).length
36
- this.cache.set(text, tokens)
37
- return tokens
38
- }
39
-
40
- /** Synchronous fallback — chars/4 heuristic when WASM not loaded. */
41
- countSync(text: string): number {
42
- if (!text) return 0
43
- const cached = this.cache.get(text)
44
- if (cached !== undefined) return cached
45
- return Math.ceil(text.length / 4)
46
- }
47
-
48
- async countMessages(messages: Message[]): Promise<number> {
49
- let total = 0
50
- for (const msg of messages) {
51
- if (typeof msg.content === 'string') {
52
- total += await this.count(msg.content)
53
- } else if (Array.isArray(msg.content)) {
54
- for (const block of msg.content) {
55
- if (block.type === 'text' && block.text) {
56
- total += await this.count(block.text)
57
- }
58
- }
59
- }
60
- total += 4 // per-message format overhead
61
- }
62
- return total
63
- }
64
-
65
- async truncateToTokens(text: string, maxTokens: number): Promise<string> {
66
- await this.ensureInit()
67
- const tokens = encoder!.encode(text)
68
- if (tokens.length <= maxTokens) return text
69
- return text.slice(0, Math.floor(text.length * (maxTokens / tokens.length)))
70
- }
71
-
72
- invalidateCache(): void {
73
- this.cache.clear()
74
- }
75
-
76
- static reset(): void {
77
- encoder = null
78
- initPromise = null
79
- }
80
- }