@ziniao-open/cli 0.1.0-beta.89 → 0.1.0-beta.91

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/README.md CHANGED
@@ -28,7 +28,7 @@ Windows PowerShell 执行:
28
28
  ziniao-cli doctor fix-path
29
29
  ```
30
30
 
31
- 脚本只探测 `ziniao.app` / `ziniao` 的安装目录;它会在 AppCache `cli` 目录缺少 CLI 或文件内容发生变化时,从紫鸟安装目录的 `envkit/cli` 同步最新文件,并注册当前用户 PATH。找不到源文件时只提示并继续,不阻断 PATH 配置。若安装目录无法自动探测,可设置 `ZINIAO_INSTALL_DIR`;若 AppCache 位置不同,可设置 `ZINIAO_APP_CACHE_DIR`。
31
+ 脚本只探测 `ziniao.app` / `ziniao` 的安装目录;Windows 会优先查询卸载注册表中 `DisplayIcon` 包含 `ziniao.exe` 的条目,再从本体目录的 `resources/app.asar.unpacked/envkit/cli` 查找 CLI。Windows 使用 `%APPDATA%\ziniaobrowser\cli`,macOS/Linux 使用 `~/.local/bin`,在目标目录缺少 CLI 或文件内容发生变化时同步最新文件,并注册当前用户 PATH。找不到源文件时只提示并继续,不阻断 PATH 配置。若安装目录无法自动探测,可设置 `ZINIAO_INSTALL_DIR`;若目标位置不同,可设置 `ZINIAO_APP_CACHE_DIR`。
32
32
 
33
33
  安装时会自动下载当前平台对应的预编译二进制(支持 macOS / Linux / Windows × amd64 / arm64),并做 SHA-256 校验。
34
34
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ziniao-open/cli",
3
- "version": "0.1.0-beta.89",
3
+ "version": "0.1.0-beta.91",
4
4
  "description": "紫鸟开放平台命令行工具,为开发者和 AI Agent 提供统一的接口调用入口。",
5
5
  "license": "UNLICENSED",
6
6
  "bin": {
@@ -23,48 +23,66 @@ switch ($arch.ToLowerInvariant()) {
23
23
 
24
24
  $sourceName = "ziniao.exe"
25
25
  $sourceRelative = Join-Path "envkit\cli\win32\$archDir" $sourceName
26
- $homeDir = [Environment]::GetFolderPath("UserProfile")
27
-
28
- function Get-FirstExistingDirectory([string[]]$Candidates) {
29
- foreach ($candidate in $Candidates) {
30
- if ($candidate -and (Test-Path -LiteralPath $candidate -PathType Container)) { return $candidate }
31
- }
32
- return $null
33
- }
26
+ $resourceRoot = "resources\app.asar.unpacked"
34
27
 
35
28
  $sourcePath = $null
29
+ $checkedSourcePaths = @()
36
30
  if ($env:ZINIAO_CLI_SOURCE -and (Test-Path -LiteralPath $env:ZINIAO_CLI_SOURCE -PathType Leaf)) {
37
31
  $sourcePath = $env:ZINIAO_CLI_SOURCE
38
32
  }
39
33
  if (-not $sourcePath -and $env:ZINIAO_INSTALL_DIR) {
40
- $candidate = Join-Path $env:ZINIAO_INSTALL_DIR $sourceRelative
41
- if (Test-Path -LiteralPath $candidate -PathType Leaf) { $sourcePath = $candidate }
34
+ $candidate = Join-Path $env:ZINIAO_INSTALL_DIR "$resourceRoot\$sourceRelative"
35
+ $checkedSourcePaths += $candidate
36
+ if (Test-Path -LiteralPath $candidate -PathType Leaf) {
37
+ $sourcePath = $candidate
38
+ }
42
39
  }
43
40
  if (-not $sourcePath) {
44
- $installRoots = @(
45
- (Join-Path $env:LOCALAPPDATA "Programs\ziniao\resources\app.asar.unpacked"),
46
- (Join-Path $env:ProgramFiles "Ziniao\resources\app.asar.unpacked"),
47
- (Join-Path $env:APPDATA "ziniao\resources\app.asar.unpacked")
41
+ $uninstallKeys = @(
42
+ "HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*",
43
+ "HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*",
44
+ "HKLM:\Software\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*"
48
45
  )
49
- foreach ($root in $installRoots) {
50
- $candidate = Join-Path $root $sourceRelative
51
- if (Test-Path -LiteralPath $candidate -PathType Leaf) { $sourcePath = $candidate; break }
46
+ $uninstallEntries = Get-ItemProperty $uninstallKeys -ErrorAction SilentlyContinue |
47
+ Where-Object { $_.DisplayIcon -and $_.DisplayIcon -match "ziniao\.exe" }
48
+ foreach ($entry in $uninstallEntries) {
49
+ $displayIcon = ([string]$entry.DisplayIcon).Trim()
50
+ if ($displayIcon -match '^\s*"([^"]+\.exe)"') {
51
+ $executablePath = $matches[1]
52
+ } elseif ($displayIcon -match '^\s*(.*?\.exe)(?:,\d+)?(?:\s|$)') {
53
+ $executablePath = $matches[1]
54
+ } else {
55
+ continue
56
+ }
57
+ $installDir = Split-Path -Parent $executablePath
58
+ $candidate = Join-Path $installDir "$resourceRoot\$sourceRelative"
59
+ $checkedSourcePaths += $candidate
60
+ if (Test-Path -LiteralPath $candidate -PathType Leaf) {
61
+ $sourcePath = $candidate
62
+ Write-Log "Found the Ziniao installation from the uninstall registry: $installDir"
63
+ break
64
+ }
52
65
  }
53
66
  }
54
67
  if ($env:ZINIAO_APP_CACHE_DIR) {
55
- $targetDir = Join-Path $env:ZINIAO_APP_CACHE_DIR "cli"
68
+ $appCacheDir = $env:ZINIAO_APP_CACHE_DIR
56
69
  } else {
57
- $targetDir = Join-Path $env:APPDATA "ziniaobrowser\cli"
70
+ # The Windows GUI installs its CLI under %APPDATA%\ziniaobrowser\cli.
71
+ $appCacheDir = Join-Path $env:APPDATA "ziniaobrowser"
58
72
  }
59
73
 
74
+ $targetDir = Join-Path $appCacheDir "cli"
60
75
  $targetPath = Join-Path $targetDir $sourceName
61
76
  New-Item -ItemType Directory -Path $targetDir -Force | Out-Null
62
77
 
63
78
  if (-not $sourcePath) {
79
+ foreach ($checkedPath in ($checkedSourcePaths | Select-Object -Unique)) {
80
+ Write-Log "Checked CLI source path: $checkedPath"
81
+ }
64
82
  if (Test-Path -LiteralPath $targetPath -PathType Leaf) {
65
- Write-Log "Desktop CLI source not found; keeping existing AppCache CLI: $targetPath"
83
+ Write-Log "CLI source was not found in the install directory; keeping the existing AppCache CLI: $targetPath"
66
84
  } else {
67
- Write-Log "WARN: ${sourceName} was not found in the desktop installation; skipping copy. Set `$env:ZINIAO_INSTALL_DIR or `$env:ZINIAO_CLI_SOURCE."
85
+ Write-Log "WARN: ${sourceName} was not found in the install directory; skipping copy. Set `$env:ZINIAO_INSTALL_DIR or `$env:ZINIAO_CLI_SOURCE to override."
68
86
  }
69
87
  } else {
70
88
  $needsCopy = -not (Test-Path -LiteralPath $targetPath -PathType Leaf)
@@ -73,32 +91,39 @@ if (-not $sourcePath) {
73
91
  }
74
92
  if ($needsCopy) {
75
93
  Copy-Item -LiteralPath $sourcePath -Destination $targetPath -Force
76
- Write-Log "Synchronized CLI: $sourcePath -> $targetPath"
94
+ Write-Log "Synced CLI: $sourcePath -> $targetPath"
77
95
  } else {
78
- Write-Log "AppCache CLI is already up to date: $targetPath"
96
+ Write-Log "AppCache CLI is up to date: $targetPath"
79
97
  }
80
98
  }
81
99
 
82
100
  function Install-PathShim {
83
101
  if (-not (Test-Path -LiteralPath $targetPath -PathType Leaf)) { return }
102
+ $windowsAppsDir = Join-Path $env:LOCALAPPDATA "Microsoft\WindowsApps"
84
103
  foreach ($pathEntry in @($env:Path -split ";" | Where-Object { $_ })) {
85
- if ($pathEntry.TrimEnd('\') -ieq $targetDir.TrimEnd('\')) {
86
- $script:shimInstalled = $true
87
- Write-Log "Current PATH already contains the AppCache CLI directory: $targetDir"
104
+ $normalizedPath = $pathEntry.TrimEnd('\')
105
+ if ($normalizedPath -ieq $windowsAppsDir.TrimEnd('\') -and (Test-Path -LiteralPath $windowsAppsDir -PathType Container)) {
106
+ $shimPath = Join-Path $windowsAppsDir $sourceName
107
+ if (-not (Test-Path -LiteralPath $shimPath)) {
108
+ try {
109
+ Copy-Item -LiteralPath $targetPath -Destination $shimPath -ErrorAction Stop
110
+ $script:shimInstalled = $true
111
+ Write-Log "Created the CLI shim in WindowsApps: $shimPath"
112
+ } catch {
113
+ Write-Log "WARN: Could not create the CLI shim in WindowsApps: $($_.Exception.Message)"
114
+ }
115
+ } else {
116
+ Write-Log "WindowsApps already contains a file named $sourceName; leaving it unchanged"
117
+ }
88
118
  return
89
119
  }
90
- $shimPath = Join-Path $pathEntry $sourceName
91
- if (Test-Path -LiteralPath $shimPath -PathType Leaf) { continue }
92
- try {
93
- Copy-Item -LiteralPath $targetPath -Destination $shimPath -Force -ErrorAction Stop
120
+ if ($normalizedPath -ieq $targetDir.TrimEnd('\')) {
94
121
  $script:shimInstalled = $true
95
- Write-Log "Created a CLI shim in an existing PATH directory: $shimPath"
122
+ Write-Log "The current PATH already contains the AppCache CLI directory: $targetDir"
96
123
  return
97
- } catch {
98
- continue
99
124
  }
100
125
  }
101
- Write-Log "WARN: No writable existing PATH directory was found; the ziniao command is not immediately available."
126
+ Write-Log "The AppCache CLI directory is not on the current PATH; no shim was created in another directory."
102
127
  }
103
128
 
104
129
  $shimInstalled = $false
@@ -116,10 +141,10 @@ if (-not ($currentEntries | Where-Object { $_.TrimEnd('\') -ieq $targetDir.TrimE
116
141
  $env:Path = "$targetDir;$env:Path"
117
142
  }
118
143
  if ($shimInstalled) {
119
- Write-Log "CLI is already available through the current PATH; no PowerShell refresh is required."
144
+ Write-Log "The CLI is already available on the current PATH; this PowerShell session needs no PATH refresh"
120
145
  } elseif ($isDotSourced) {
121
- Write-Log "Refreshed the current PowerShell PATH."
146
+ Write-Log "The current PowerShell PATH was refreshed"
122
147
  } else {
123
- Write-Log "Refreshed this process PATH; dot-source the script or open a new terminal to refresh the parent PowerShell."
148
+ Write-Log "The current process PATH was refreshed; dot-source this script in the parent PowerShell or reopen the terminal"
124
149
  }
125
- Write-Log "Verify with: Get-Command ziniao"
150
+ Write-Log "Verification command: Get-Command ziniao"
@@ -83,26 +83,15 @@ find_source() {
83
83
  }
84
84
 
85
85
  if [ -n "${ZINIAO_APP_CACHE_DIR:-}" ]; then
86
- app_cache_dir="$ZINIAO_APP_CACHE_DIR"
86
+ target_dir="$ZINIAO_APP_CACHE_DIR/cli"
87
87
  else
88
- app_data_dir="$(first_existing_dir \
89
- "$home_dir/Library/Application Support/ziniao" \
90
- "$home_dir/.config/ziniao" \
91
- "$home_dir/.local/share/ziniao" \
92
- 2>/dev/null || true)"
93
- if [ -z "$app_data_dir" ]; then
94
- case "$platform_dir" in
95
- darwin) app_data_dir="$home_dir/Library/Application Support/ziniao" ;;
96
- *) app_data_dir="$home_dir/.config/ziniao" ;;
97
- esac
98
- fi
99
- app_cache_dir="$app_data_dir/app-cache"
88
+ # The macOS/Linux GUI reads the CLI from the user's local bin directory.
89
+ target_dir="$home_dir/.local/bin"
100
90
  fi
101
91
 
102
- target_dir="$app_cache_dir/cli"
103
92
  source_path="$(find_source || true)"
104
- mkdir -p "$target_dir"
105
93
  target_path="$target_dir/$source_name"
94
+ mkdir -p "$target_dir"
106
95
  if [ -z "$source_path" ]; then
107
96
  if [ -f "$target_path" ]; then
108
97
  log "未找到安装目录中的 CLI 源文件,保留现有 AppCache CLI: $target_path"
@@ -120,36 +109,15 @@ fi
120
109
  shim_installed=0
121
110
  install_path_shim() {
122
111
  [ -f "$target_path" ] || return 0
123
- old_ifs="$IFS"
124
- IFS=:
125
- for path_entry in ${PATH:-}; do
126
- [ -d "$path_entry" ] || continue
127
- [ -w "$path_entry" ] || continue
128
- if [ "$path_entry" = "$target_dir" ]; then
112
+ case ":${PATH:-}:" in
113
+ *:"$target_dir":*)
129
114
  shim_installed=1
130
115
  log "当前 PATH 已包含 AppCache CLI 目录: $target_dir"
131
- IFS="$old_ifs"
132
- return 0
133
- fi
134
- shim_path="$path_entry/$source_name"
135
- if [ -e "$shim_path" ] || [ -L "$shim_path" ]; then
136
- if [ -L "$shim_path" ] && [ "$(readlink "$shim_path" 2>/dev/null || true)" = "$target_path" ]; then
137
- log "现有 PATH 已包含 CLI shim: $shim_path"
138
- shim_installed=1
139
- IFS="$old_ifs"
140
- return 0
141
- fi
142
- continue
143
- fi
144
- if ln -s "$target_path" "$shim_path" 2>/dev/null; then
145
- log "已在现有 PATH 中创建 CLI shim: $shim_path"
146
- shim_installed=1
147
- IFS="$old_ifs"
148
- return 0
149
- fi
150
- done
151
- IFS="$old_ifs"
152
- log "WARN: 没有可写的现有 PATH 目录,无法立即提供 ziniao 命令。"
116
+ ;;
117
+ *)
118
+ log "AppCache CLI 目录不在当前 PATH 中;不会在其他目录创建 shim: $target_dir"
119
+ ;;
120
+ esac
153
121
  }
154
122
 
155
123
  install_path_shim