@miphamai/cli 0.81.7 → 0.81.9

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 (64) hide show
  1. package/README.md +1 -1
  2. package/bin/mipham.ts +35 -1
  3. package/package.json +1 -1
  4. package/src/agent/message-bus.ts +10 -3
  5. package/src/agent/sub-agent.ts +60 -12
  6. package/src/agent/types.ts +14 -1
  7. package/src/artifacts/manifest.ts +90 -34
  8. package/src/artifacts/paths.ts +19 -0
  9. package/src/artifacts/server.ts +48 -8
  10. package/src/config/credential-crypto.ts +28 -5
  11. package/src/config/defaults.ts +18 -10
  12. package/src/config/keys-manager.ts +14 -9
  13. package/src/config/loader.ts +202 -63
  14. package/src/config/preferences.ts +5 -2
  15. package/src/core/credential-masker/output-scrub.ts +16 -2
  16. package/src/core/cron-poller.ts +30 -6
  17. package/src/core/engine.ts +7 -2
  18. package/src/core/hooks-executor.ts +30 -2
  19. package/src/core/hooks.ts +51 -4
  20. package/src/core/paths.ts +44 -1
  21. package/src/core/permission-config.ts +146 -14
  22. package/src/core/permission-rules.ts +157 -6
  23. package/src/core/permission.ts +81 -13
  24. package/src/core/rules-loader.ts +35 -5
  25. package/src/core/session-log.ts +49 -2
  26. package/src/core/session-store.ts +11 -1
  27. package/src/core/workspace-trust.ts +42 -4
  28. package/src/daemon/auth.ts +15 -14
  29. package/src/daemon/engine-capabilities.ts +12 -2
  30. package/src/daemon/remote-engine.ts +9 -4
  31. package/src/daemon/server.ts +29 -1
  32. package/src/daemon/session-worker.ts +15 -0
  33. package/src/i18n-core/locales/en-US.json +12 -8
  34. package/src/i18n-core/locales/zh-CN.json +12 -8
  35. package/src/index.tsx +47 -19
  36. package/src/mcp/client.ts +24 -0
  37. package/src/mcp/http-transport.ts +35 -3
  38. package/src/plugin/plugin-manager.ts +30 -8
  39. package/src/providers/anthropic.ts +74 -13
  40. package/src/providers/openai-compat.ts +14 -1
  41. package/src/security/gate.ts +18 -0
  42. package/src/security/path.ts +25 -2
  43. package/src/shared/arg-validation.ts +37 -2
  44. package/src/shared/atomic-write.ts +28 -5
  45. package/src/shared/package-info.ts +1 -1
  46. package/src/shared/sanitize.ts +27 -2
  47. package/src/shared/types.ts +17 -0
  48. package/src/shared/update.ts +22 -5
  49. package/src/tools/agent/agent.ts +3 -0
  50. package/src/tools/artifact/artifact.ts +14 -4
  51. package/src/tools/exec/bash.ts +146 -24
  52. package/src/tools/exec/enter-worktree.ts +9 -3
  53. package/src/tools/exec/exit-worktree.ts +6 -3
  54. package/src/tools/exec/git.ts +83 -3
  55. package/src/tools/file/glob.ts +19 -3
  56. package/src/tools/file/grep.ts +70 -16
  57. package/src/tools/file/read.ts +151 -45
  58. package/src/tools/index.ts +12 -4
  59. package/src/tools/scheduling/cron.ts +34 -5
  60. package/src/tools/system/config.ts +6 -2
  61. package/src/ui/app.tsx +47 -11
  62. package/src/ui/commands.ts +187 -41
  63. package/src/workflow/primitives/agent.ts +4 -0
  64. package/src/artifacts/versioning.ts +0 -127
@@ -1,127 +0,0 @@
1
- import { mkdirSync, writeFileSync, readFileSync, existsSync, readdirSync, statSync } from 'node:fs'
2
- import { join } from 'node:path'
3
- import { homedir } from 'node:os'
4
-
5
- const DEFAULT_VERSIONS_DIR = join(homedir(), '.mipham', 'artifacts')
6
-
7
- export interface ArtifactVersion {
8
- name: string
9
- version: number
10
- path: string
11
- createdAt: string
12
- size: number
13
- }
14
-
15
- /**
16
- * Manages artifact version snapshots on disk.
17
- *
18
- * Directory layout:
19
- * <dir>/<name>/versions/v1.html
20
- * <dir>/<name>/versions/v2.html
21
- * <dir>/<name>/current.html (latest snapshot)
22
- * <dir>/<name>/manifest.json ({ name, currentVersion, versionCount })
23
- */
24
- export class ArtifactVersioning {
25
- private dir: string
26
-
27
- constructor(dir?: string) {
28
- this.dir = dir ?? DEFAULT_VERSIONS_DIR
29
- mkdirSync(this.dir, { recursive: true })
30
- }
31
-
32
- /** Save a new version of an artifact. Returns the assigned version number. */
33
- saveVersion(name: string, content: string): number {
34
- const artifactDir = join(this.dir, name)
35
- const versionsDir = join(artifactDir, 'versions')
36
- mkdirSync(versionsDir, { recursive: true })
37
-
38
- // Determine next version number
39
- const existing = this.listVersions(name)
40
- const nextVersion = (existing.length > 0 ? Math.max(...existing.map((v) => v.version)) : 0) + 1
41
-
42
- // Save versioned file
43
- const versionPath = join(versionsDir, `v${nextVersion}.html`)
44
- writeFileSync(versionPath, content, 'utf-8')
45
-
46
- // Update current.html
47
- writeFileSync(join(artifactDir, 'current.html'), content, 'utf-8')
48
-
49
- // Update manifest
50
- writeFileSync(
51
- join(artifactDir, 'manifest.json'),
52
- JSON.stringify(
53
- {
54
- name,
55
- currentVersion: nextVersion,
56
- versionCount: nextVersion,
57
- },
58
- null,
59
- 2,
60
- ),
61
- )
62
-
63
- return nextVersion
64
- }
65
-
66
- /** List all saved versions for an artifact, newest first. */
67
- listVersions(name: string): ArtifactVersion[] {
68
- const versionsDir = join(this.dir, name, 'versions')
69
- if (!existsSync(versionsDir)) return []
70
-
71
- try {
72
- return readdirSync(versionsDir)
73
- .filter((f) => f.startsWith('v') && f.endsWith('.html'))
74
- .map((f) => {
75
- const vNum = parseInt(f.replace('v', '').replace('.html', ''), 10)
76
- const path = join(versionsDir, f)
77
- const stat = statSync(path)
78
- return {
79
- name,
80
- version: vNum,
81
- path,
82
- createdAt: stat.birthtime.toISOString(),
83
- size: stat.size,
84
- }
85
- })
86
- .sort((a, b) => b.version - a.version)
87
- } catch {
88
- return []
89
- }
90
- }
91
-
92
- /**
93
- * Get artifact content.
94
- * - If a version number is given, returns that specific version.
95
- * - Otherwise returns the latest (current.html).
96
- * Returns null if the requested version does not exist.
97
- */
98
- getVersion(name: string, version?: number): string | null {
99
- const artifactDir = join(this.dir, name)
100
-
101
- if (version !== undefined) {
102
- const vPath = join(artifactDir, 'versions', `v${version}.html`)
103
- return existsSync(vPath) ? readFileSync(vPath, 'utf-8') : null
104
- }
105
-
106
- const currentPath = join(artifactDir, 'current.html')
107
- return existsSync(currentPath) ? readFileSync(currentPath, 'utf-8') : null
108
- }
109
-
110
- /** Produce a simple line-by-line text diff between two versions. */
111
- diff(name: string, v1: number, v2: number): string {
112
- const content1 = this.getVersion(name, v1) || ''
113
- const content2 = this.getVersion(name, v2) || ''
114
- const lines1 = content1.split('\n')
115
- const lines2 = content2.split('\n')
116
-
117
- const diffLines: string[] = []
118
- const maxLen = Math.max(lines1.length, lines2.length)
119
- for (let i = 0; i < maxLen; i++) {
120
- if (lines1[i] !== lines2[i]) {
121
- if (lines1[i] !== undefined) diffLines.push(`- ${lines1[i]}`)
122
- if (lines2[i] !== undefined) diffLines.push(`+ ${lines2[i]}`)
123
- }
124
- }
125
- return diffLines.length > 0 ? diffLines.join('\n') : '(no changes)'
126
- }
127
- }