openmoneta-dev-kit 1.9.0 → 1.9.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/README.md CHANGED
@@ -10,19 +10,23 @@
10
10
  ## Cài đặt nhanh (npm)
11
11
 
12
12
  ```bash
13
- npm install -g openmoneta-dev-kit
14
- openmoneta install
13
+ npm install -g openmoneta-dev-kit && openmoneta install
15
14
  ```
16
15
 
17
- Không cần git, không cần clone repo. Sau cài, dùng `openmoneta` thay cho các lệnh bash:
16
+ 1 lệnh cài cho cả Cursor + OpenCode. Sau đó khởi tạo project:
18
17
 
19
- | Lệnh cũ | Lệnh mới |
18
+ ```bash
19
+ cd /path/to/project
20
+ openmoneta init
21
+ ```
22
+
23
+ | Lệnh mới | Tương đương lệnh cũ |
20
24
  |---|---|
21
- | `bash ~/OpenMoneta-Dev-Kit/install.sh` | `openmoneta install` |
22
- | `bash ~/.cursor/scripts/init-project.sh .` | `openmoneta init` |
23
- | `bash ~/OpenMoneta-Dev-Kit/update.sh --check` | `openmoneta check` |
24
- | `bash ~/OpenMoneta-Dev-Kit/update.sh --yes` | `openmoneta update --yes` |
25
- | `bash ~/OpenMoneta-Dev-Kit/uninstall.sh` | `openmoneta uninstall` |
25
+ | `openmoneta install` | `install.sh` + `install-opencode.sh` |
26
+ | `openmoneta init` | `init-project.sh .` |
27
+ | `openmoneta check` | `update.sh --check` |
28
+ | `openmoneta update --yes` | `update.sh --yes` |
29
+ | `openmoneta uninstall` | `uninstall.sh` |
26
30
 
27
31
  ### Khởi tạo project
28
32
 
@@ -60,31 +64,6 @@ bash ~/OpenMoneta-Dev-Kit/install.sh
60
64
  - **Safe Push** — sync remote trước push, không đè code người khác
61
65
  - **OpenCode Support** — global rules/skills/agents + plugin guard
62
66
 
63
- ## Cài đặt Cursor: 2 cấp độ
64
-
65
- OpenMoneta Dev Kit cài theo **2 bước riêng biệt**:
66
-
67
- | Bước | Khi nào | Lệnh | File hướng dẫn |
68
- |---|---|---|---|
69
- | **1. User-level** (1 lần / máy) | Cài Cursor lần đầu trên máy mới | `bash install.sh` | [`01-cai-dat.md`](./docs/01-cai-dat.md) |
70
- | **2. Project-level** (1 lần / project) | Mỗi khi tạo / clone project mới | `bash ~/.cursor/scripts/init-project.sh .` | [`06-khoi-tao-du-an.md`](./docs/06-khoi-tao-du-an.md) |
71
-
72
- > **Lưu ý**: Bước 1 cài hooks/skills/agents vào `~/.cursor/` (dùng chung mọi project trên máy). Bước 2 tạo/sync **4 file thiết yếu** (`AGENTS.md`, `docs/INDEX.md`, `plans/INDEX.md`, `.gitignore`) cho **từng project**. Từ v1.7.1, chạy lại `init-project.sh` sẽ cập nhật template mới nhưng giữ các block riêng của project.
73
-
74
- ## Cài đặt OpenCode
75
-
76
- ```bash
77
- # npm (khuyến nghị)
78
- openmoneta install --opencode
79
- openmoneta init --opencode
80
-
81
- # Hoặc thủ công
82
- cd ~/OpenMoneta-Dev-Kit
83
- bash install-opencode.sh
84
- ```
85
-
86
- Chi tiết: [`docs/11-opencode.md`](./docs/11-opencode.md).
87
-
88
67
  ## Đóng góp
89
68
 
90
69
  Xem [`docs/09-customize-va-dong-gop.md`](./docs/09-customize-va-dong-gop.md):
package/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.9.1
@@ -0,0 +1,192 @@
1
+ # install-opencode.ps1 - Cài OpenMoneta Dev Kit vào %USERPROFILE%\.config\opencode\
2
+ #
3
+ # Usage:
4
+ # pwsh .\install-opencode.ps1 # Cài bình thường
5
+ # pwsh .\install-opencode.ps1 -Yes # Cài không hỏi xác nhận
6
+ # pwsh .\install-opencode.ps1 -NoBackup # Skip backup
7
+
8
+ [CmdletBinding()]
9
+ param(
10
+ [switch]$Yes,
11
+ [switch]$NoBackup
12
+ )
13
+
14
+ $ErrorActionPreference = 'Stop'
15
+
16
+ $RepoDir = $PSScriptRoot
17
+ $OpenCodeDir = Join-Path $env:USERPROFILE '.config\opencode'
18
+ $Timestamp = Get-Date -Format 'yyyyMMdd-HHmmss'
19
+ $BackupDir = Join-Path $OpenCodeDir ".backup-openmoneta-$Timestamp"
20
+
21
+ Write-Host "==> OpenMoneta Dev Kit Installer for OpenCode (Windows)"
22
+ Write-Host " Source: $RepoDir"
23
+ Write-Host " Target: $OpenCodeDir"
24
+ Write-Host ""
25
+
26
+ $VersionFile = Join-Path $RepoDir 'VERSION'
27
+ if (-not (Test-Path $VersionFile)) {
28
+ Write-Error "Không phải repo OpenMoneta Dev Kit (thiếu VERSION). Abort."
29
+ exit 1
30
+ }
31
+ $NewVersion = (Get-Content $VersionFile -Raw).Trim()
32
+
33
+ $VersionTrack = Join-Path $OpenCodeDir '.openmoneta-version'
34
+ $RepoTrack = Join-Path $OpenCodeDir '.openmoneta-repo'
35
+ $InstallTrack = Join-Path $OpenCodeDir '.openmoneta-installed-at'
36
+
37
+ $ExistingVersion = ""
38
+ if (Test-Path $VersionTrack) {
39
+ $ExistingVersion = (Get-Content $VersionTrack -Raw).Trim()
40
+ }
41
+
42
+ if ($ExistingVersion) {
43
+ Write-Host "Phát hiện OpenMoneta Dev Kit for OpenCode hiện tại: v$ExistingVersion -> sẽ ghi đè bằng v$NewVersion"
44
+ } else {
45
+ Write-Host "Cài đặt mới OpenMoneta Dev Kit for OpenCode: v$NewVersion"
46
+ }
47
+
48
+ if ((Test-Path $OpenCodeDir) -and (-not $NoBackup)) {
49
+ Write-Host "Backup config cũ vào: $BackupDir"
50
+ }
51
+
52
+ if (-not $Yes) {
53
+ $ans = Read-Host "Tiếp tục? [y/N]"
54
+ if ($ans -notin @('y', 'Y', 'yes', 'YES')) {
55
+ Write-Host "Hủy."
56
+ exit 0
57
+ }
58
+ }
59
+
60
+ New-Item -ItemType Directory -Path $OpenCodeDir -Force | Out-Null
61
+
62
+ if (-not $NoBackup) {
63
+ Write-Host ""
64
+ Write-Host "==> Backup OpenCode config hiện tại..."
65
+ New-Item -ItemType Directory -Path $BackupDir -Force | Out-Null
66
+ $BackupItems = @('AGENTS.md', 'templates', 'skills', 'agents', 'plugin', 'plugins', 'scripts', 'opencode.json', '.openmoneta-version')
67
+ $Backed = 0
68
+ foreach ($item in $BackupItems) {
69
+ $src = Join-Path $OpenCodeDir $item
70
+ if (Test-Path $src) {
71
+ Copy-Item -Path $src -Destination $BackupDir -Recurse -Force
72
+ Write-Host " + $item"
73
+ $Backed++
74
+ }
75
+ }
76
+ if ($Backed -eq 0) {
77
+ Remove-Item $BackupDir -Force -ErrorAction SilentlyContinue
78
+ Write-Host " (không có gì để backup)"
79
+ }
80
+ }
81
+
82
+ Write-Host ""
83
+ Write-Host "==> Cài OpenMoneta config cho OpenCode..."
84
+
85
+ Copy-Item -Path (Join-Path $RepoDir 'opencode\AGENTS.md.tpl') -Destination (Join-Path $OpenCodeDir 'AGENTS.md') -Force
86
+ Write-Host " + AGENTS.md"
87
+
88
+ $TemplatesTarget = Join-Path $OpenCodeDir 'templates'
89
+ if (Test-Path $TemplatesTarget) { Remove-Item $TemplatesTarget -Recurse -Force }
90
+ Copy-Item -Path (Join-Path $RepoDir 'templates') -Destination $TemplatesTarget -Recurse -Force
91
+ Write-Host " + templates\ (overwrite)"
92
+
93
+ $SkillsTarget = Join-Path $OpenCodeDir 'skills'
94
+ if (Test-Path $SkillsTarget) { Remove-Item $SkillsTarget -Recurse -Force }
95
+ Copy-Item -Path (Join-Path $RepoDir 'skills') -Destination $SkillsTarget -Recurse -Force
96
+ Write-Host " + skills\ (overwrite)"
97
+
98
+ $AgentsTarget = Join-Path $OpenCodeDir 'agents'
99
+ if (Test-Path $AgentsTarget) { Remove-Item $AgentsTarget -Recurse -Force }
100
+ Copy-Item -Path (Join-Path $RepoDir 'opencode\agents') -Destination $AgentsTarget -Recurse -Force
101
+ Write-Host " + agents\ (overwrite)"
102
+
103
+ $PluginsTarget = Join-Path $OpenCodeDir 'plugins'
104
+ New-Item -ItemType Directory -Path $PluginsTarget -Force | Out-Null
105
+ Copy-Item -Path (Join-Path $RepoDir 'opencode\plugins\openmoneta-guard.ts') -Destination (Join-Path $PluginsTarget 'openmoneta-guard.ts') -Force
106
+ Write-Host " + plugins\openmoneta-guard.ts"
107
+
108
+ $PluginCompatTarget = Join-Path $OpenCodeDir 'plugin'
109
+ New-Item -ItemType Directory -Path $PluginCompatTarget -Force | Out-Null
110
+ Copy-Item -Path (Join-Path $RepoDir 'opencode\plugins\openmoneta-guard.ts') -Destination (Join-Path $PluginCompatTarget 'openmoneta-guard.ts') -Force
111
+ Write-Host " + plugin\openmoneta-guard.ts (compat)"
112
+
113
+ $ScriptsTarget = Join-Path $OpenCodeDir 'scripts'
114
+ if (Test-Path $ScriptsTarget) { Remove-Item $ScriptsTarget -Recurse -Force }
115
+ Copy-Item -Path (Join-Path $RepoDir 'scripts') -Destination $ScriptsTarget -Recurse -Force
116
+ Write-Host " + scripts\ (overwrite)"
117
+
118
+ $ConfigFile = Join-Path $OpenCodeDir 'opencode.json'
119
+ if (-not (Test-Path $ConfigFile)) {
120
+ @'
121
+ {
122
+ "$schema": "https://opencode.ai/config.json",
123
+ "permission": {
124
+ "skill": {
125
+ "*": "allow"
126
+ },
127
+ "bash": {
128
+ "git push --force*": "deny",
129
+ "git push -f*": "deny",
130
+ "git push*": "ask"
131
+ }
132
+ }
133
+ }
134
+ '@ | Set-Content -Path $ConfigFile -NoNewline
135
+ Write-Host " + opencode.json (created)"
136
+ } else {
137
+ Write-Host " - opencode.json (merge plugin, giữ config hiện có)"
138
+ }
139
+
140
+ $PluginFile = Join-Path $PluginsTarget 'openmoneta-guard.ts'
141
+ $PluginUri = ([System.Uri](Resolve-Path $PluginFile).Path).AbsoluteUri
142
+ $ConfigJson = Get-Content $ConfigFile -Raw | ConvertFrom-Json -ErrorAction Stop
143
+
144
+ if (-not $ConfigJson.PSObject.Properties.Name.Contains('$schema')) {
145
+ $ConfigJson | Add-Member -NotePropertyName '$schema' -NotePropertyValue 'https://opencode.ai/config.json'
146
+ }
147
+
148
+ $ExistingPlugin = @()
149
+ if ($ConfigJson.PSObject.Properties.Name.Contains('plugin')) {
150
+ if ($ConfigJson.plugin -is [array]) {
151
+ $ExistingPlugin = @($ConfigJson.plugin)
152
+ } elseif ($null -ne $ConfigJson.plugin) {
153
+ $ExistingPlugin = @($ConfigJson.plugin)
154
+ }
155
+ }
156
+ if ($ExistingPlugin -notcontains $PluginUri) {
157
+ $ExistingPlugin += $PluginUri
158
+ }
159
+ if ($ConfigJson.PSObject.Properties.Name.Contains('plugin')) {
160
+ $ConfigJson.plugin = $ExistingPlugin
161
+ } else {
162
+ $ConfigJson | Add-Member -NotePropertyName 'plugin' -NotePropertyValue $ExistingPlugin
163
+ }
164
+
165
+ if (-not $ConfigJson.PSObject.Properties.Name.Contains('permission')) {
166
+ $ConfigJson | Add-Member -NotePropertyName 'permission' -NotePropertyValue ([pscustomobject]@{})
167
+ }
168
+ if (-not $ConfigJson.permission.PSObject.Properties.Name.Contains('skill')) {
169
+ $ConfigJson.permission | Add-Member -NotePropertyName 'skill' -NotePropertyValue ([pscustomobject]@{'*' = 'allow'})
170
+ }
171
+
172
+ $ConfigJson | ConvertTo-Json -Depth 10 | Set-Content -Path $ConfigFile
173
+ Write-Host " + opencode.json plugin=file://.../openmoneta-guard.ts"
174
+
175
+ Set-Content -Path $VersionTrack -Value $NewVersion -NoNewline
176
+ Set-Content -Path $RepoTrack -Value $RepoDir -NoNewline
177
+ Set-Content -Path $InstallTrack -Value (Get-Date -Format 'yyyy-MM-ddTHH:mm:ssK') -NoNewline
178
+
179
+ Write-Host ""
180
+ Write-Host "================================================" -ForegroundColor Green
181
+ Write-Host "Cài đặt thành công OpenMoneta Dev Kit for OpenCode v$NewVersion" -ForegroundColor Green
182
+ Write-Host "================================================" -ForegroundColor Green
183
+ Write-Host ""
184
+ Write-Host "Đã cài vào: $OpenCodeDir\"
185
+ if ((-not $NoBackup) -and (Test-Path $BackupDir)) {
186
+ Write-Host "Backup tại: $BackupDir\"
187
+ }
188
+ Write-Host ""
189
+ Write-Host "Bước tiếp theo:"
190
+ Write-Host " 1. Mở project cần dùng OpenCode."
191
+ Write-Host " 2. Chạy: bash $OpenCodeDir\scripts\init-project.sh ."
192
+ Write-Host " 3. Chạy: opencode"
@@ -0,0 +1,168 @@
1
+ #!/usr/bin/env bash
2
+ # install-opencode.sh - Cài OpenMoneta Dev Kit vào ~/.config/opencode/
3
+ #
4
+ # Usage:
5
+ # bash install-opencode.sh # Cài bình thường (interactive confirm)
6
+ # bash install-opencode.sh --yes # Cài không hỏi xác nhận
7
+ # bash install-opencode.sh --no-backup # Skip backup (không khuyến nghị)
8
+
9
+ set -euo pipefail
10
+
11
+ AUTO_YES=0
12
+ DO_BACKUP=1
13
+ for arg in "$@"; do
14
+ case "$arg" in
15
+ --yes|-y) AUTO_YES=1 ;;
16
+ --no-backup) DO_BACKUP=0 ;;
17
+ --help|-h)
18
+ grep '^#' "$0" | sed 's/^# \?//' | head -10
19
+ exit 0
20
+ ;;
21
+ esac
22
+ done
23
+
24
+ REPO_DIR="$(cd "$(dirname "$0")" && pwd)"
25
+ OPENCODE_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/opencode"
26
+ TIMESTAMP=$(date +%Y%m%d-%H%M%S)
27
+ BACKUP_DIR="$OPENCODE_DIR/.backup-openmoneta-$TIMESTAMP"
28
+
29
+ echo "==> OpenMoneta Dev Kit Installer for OpenCode"
30
+ echo " Source: $REPO_DIR"
31
+ echo " Target: $OPENCODE_DIR"
32
+ echo ""
33
+
34
+ if [[ ! -f "$REPO_DIR/VERSION" ]]; then
35
+ echo "[!] Không phải repo OpenMoneta Dev Kit (thiếu VERSION). Abort." >&2
36
+ exit 1
37
+ fi
38
+ NEW_VERSION=$(cat "$REPO_DIR/VERSION")
39
+
40
+ case "$(uname -s)" in
41
+ Darwin*|Linux*) ;;
42
+ *)
43
+ echo "[!] OS $(uname -s) không hỗ trợ bởi install-opencode.sh. Dùng install-opencode.ps1 cho Windows." >&2
44
+ exit 1
45
+ ;;
46
+ esac
47
+
48
+ for required in bash cp mkdir rm python3; do
49
+ command -v "$required" >/dev/null 2>&1 || {
50
+ echo "[!] Thiếu dependency: $required" >&2
51
+ exit 1
52
+ }
53
+ done
54
+
55
+ VERSION_FILE="$OPENCODE_DIR/.openmoneta-version"
56
+ REPO_FILE="$OPENCODE_DIR/.openmoneta-repo"
57
+ INSTALL_FILE="$OPENCODE_DIR/.openmoneta-installed-at"
58
+
59
+ EXISTING_VERSION=""
60
+ if [[ -f "$VERSION_FILE" ]]; then
61
+ EXISTING_VERSION=$(cat "$VERSION_FILE" 2>/dev/null || echo "unknown")
62
+ fi
63
+
64
+ if [[ -n "$EXISTING_VERSION" ]]; then
65
+ echo "Phát hiện OpenMoneta Dev Kit for OpenCode hiện tại: v$EXISTING_VERSION → sẽ ghi đè bằng v$NEW_VERSION"
66
+ else
67
+ echo "Cài đặt mới OpenMoneta Dev Kit for OpenCode: v$NEW_VERSION"
68
+ fi
69
+
70
+ if [[ -d "$OPENCODE_DIR" && $DO_BACKUP -eq 1 ]]; then
71
+ echo "Backup config cũ vào: $BACKUP_DIR"
72
+ fi
73
+
74
+ if [[ $AUTO_YES -eq 0 ]]; then
75
+ read -r -p "Tiếp tục? [y/N] " ans
76
+ if [[ "$ans" != "y" && "$ans" != "Y" ]]; then
77
+ echo "Hủy."
78
+ exit 0
79
+ fi
80
+ fi
81
+
82
+ mkdir -p "$OPENCODE_DIR"
83
+
84
+ if [[ $DO_BACKUP -eq 1 ]]; then
85
+ echo ""
86
+ echo "==> Backup OpenCode config hiện tại..."
87
+ mkdir -p "$BACKUP_DIR"
88
+ for item in AGENTS.md templates skills agents plugin plugins scripts opencode.json .openmoneta-version; do
89
+ src="$OPENCODE_DIR/$item"
90
+ if [[ -e "$src" ]]; then
91
+ cp -R "$src" "$BACKUP_DIR/"
92
+ echo " + $item"
93
+ fi
94
+ done
95
+ if [[ -z "$(ls -A "$BACKUP_DIR" 2>/dev/null)" ]]; then
96
+ rmdir "$BACKUP_DIR" 2>/dev/null || true
97
+ echo " (không có gì để backup)"
98
+ fi
99
+ fi
100
+
101
+ echo ""
102
+ echo "==> Cài OpenMoneta config cho OpenCode..."
103
+
104
+ cp "$REPO_DIR/opencode/AGENTS.md.tpl" "$OPENCODE_DIR/AGENTS.md"
105
+ echo " + AGENTS.md"
106
+
107
+ rm -rf "$OPENCODE_DIR/templates"
108
+ cp -R "$REPO_DIR/templates" "$OPENCODE_DIR/templates"
109
+ echo " + templates/ (overwrite)"
110
+
111
+ rm -rf "$OPENCODE_DIR/skills"
112
+ cp -R "$REPO_DIR/skills" "$OPENCODE_DIR/skills"
113
+ echo " + skills/ (overwrite)"
114
+
115
+ rm -rf "$OPENCODE_DIR/agents"
116
+ cp -R "$REPO_DIR/opencode/agents" "$OPENCODE_DIR/agents"
117
+ echo " + agents/ (overwrite)"
118
+
119
+ mkdir -p "$OPENCODE_DIR/plugins"
120
+ cp "$REPO_DIR/opencode/plugins/openmoneta-guard.ts" "$OPENCODE_DIR/plugins/openmoneta-guard.ts"
121
+ echo " + plugins/openmoneta-guard.ts"
122
+
123
+ rm -rf "$OPENCODE_DIR/scripts"
124
+ cp -R "$REPO_DIR/scripts" "$OPENCODE_DIR/scripts"
125
+ chmod +x "$OPENCODE_DIR/scripts/"*.sh 2>/dev/null || true
126
+ echo " + scripts/ (overwrite)"
127
+
128
+ if [[ ! -f "$OPENCODE_DIR/opencode.json" ]]; then
129
+ cat > "$OPENCODE_DIR/opencode.json" <<'EOF'
130
+ {
131
+ "$schema": "https://opencode.ai/config.json",
132
+ "permission": {
133
+ "skill": {
134
+ "*": "allow"
135
+ },
136
+ "bash": {
137
+ "git push --force*": "deny",
138
+ "git push -f*": "deny",
139
+ "git push*": "ask"
140
+ }
141
+ }
142
+ }
143
+ EOF
144
+ echo " + opencode.json (created)"
145
+ else
146
+ echo " - opencode.json (đã có, giữ nguyên)"
147
+ fi
148
+
149
+ echo "$NEW_VERSION" > "$VERSION_FILE"
150
+ echo "$REPO_DIR" > "$REPO_FILE"
151
+ date -Iseconds > "$INSTALL_FILE"
152
+
153
+ echo ""
154
+ echo "================================================"
155
+ echo "✅ Cài đặt thành công OpenMoneta Dev Kit for OpenCode v$NEW_VERSION"
156
+ echo "================================================"
157
+ echo ""
158
+ echo "Đã cài vào: $OPENCODE_DIR/"
159
+ if [[ $DO_BACKUP -eq 1 && -d "$BACKUP_DIR" ]]; then
160
+ echo "Backup tại: $BACKUP_DIR/"
161
+ fi
162
+ echo ""
163
+ echo "Bước tiếp theo:"
164
+ echo " 1. Mở project cần dùng OpenCode."
165
+ echo " 2. Chạy: bash ${OPENCODE_DIR}/scripts/init-project.sh ."
166
+ echo " 3. Chạy: opencode"
167
+ echo ""
168
+ echo "Lưu ý: project-level AGENTS.md là source of truth cho từng repo."
package/install.ps1 ADDED
@@ -0,0 +1,162 @@
1
+ # install.ps1 - Cài OpenMoneta Dev Kit vào ~/.cursor/ (Windows PowerShell version)
2
+ # STRICT MODE: overwrite hoàn toàn config (templates/skills/agents/hooks/scripts/hooks.json).
3
+ # An toàn: backup config cũ vào %USERPROFILE%\.cursor\.backup-YYYYMMDD-HHMMSS\
4
+ #
5
+ # Usage:
6
+ # pwsh ./install.ps1 # Cài bình thường (interactive confirm)
7
+ # pwsh ./install.ps1 -Yes # Cài không hỏi xác nhận
8
+ # pwsh ./install.ps1 -NoBackup # Skip backup (không khuyến nghị)
9
+ #
10
+ # Yêu cầu: PowerShell 5.1+ hoặc PowerShell Core 7+, Windows 10/11.
11
+ # Lưu ý: Hooks dùng bash - team Windows phải có Git Bash hoặc WSL để hook chạy.
12
+
13
+ [CmdletBinding()]
14
+ param(
15
+ [switch]$Yes,
16
+ [switch]$NoBackup
17
+ )
18
+
19
+ $ErrorActionPreference = 'Stop'
20
+
21
+ $RepoDir = $PSScriptRoot
22
+ $CursorDir = Join-Path $env:USERPROFILE '.cursor'
23
+ $Timestamp = Get-Date -Format 'yyyyMMdd-HHmmss'
24
+ $BackupDir = Join-Path $CursorDir ".backup-$Timestamp"
25
+
26
+ Write-Host "==> OpenMoneta Dev Kit Installer (Windows)"
27
+ Write-Host " Source: $RepoDir"
28
+ Write-Host " Target: $CursorDir"
29
+ Write-Host ""
30
+
31
+ $VersionFile = Join-Path $RepoDir 'VERSION'
32
+ if (-not (Test-Path $VersionFile)) {
33
+ Write-Error "Không phải repo OpenMoneta Dev Kit (thiếu VERSION). Abort."
34
+ exit 1
35
+ }
36
+ $NewVersion = (Get-Content $VersionFile -Raw).Trim()
37
+
38
+ $BashCmd = Get-Command bash -ErrorAction SilentlyContinue
39
+ if (-not $BashCmd) {
40
+ Write-Host "[WARNING] Không tìm thấy 'bash' trên PATH." -ForegroundColor Yellow
41
+ Write-Host " Hooks (sessionStart, preToolUse, ...) là bash scripts."
42
+ Write-Host " Cài Git for Windows (https://git-scm.com/download/win) - đi kèm Git Bash."
43
+ Write-Host " Hoặc dùng WSL (https://learn.microsoft.com/windows/wsl/install)."
44
+ Write-Host ""
45
+ }
46
+
47
+ $JqCmd = Get-Command jq -ErrorAction SilentlyContinue
48
+ if (-not $JqCmd) {
49
+ Write-Host "[WARNING] 'jq' không có trên PATH. Hooks vẫn chạy nhưng nên cài để có message tốt hơn:" -ForegroundColor Yellow
50
+ Write-Host " winget install jqlang.jq"
51
+ Write-Host ""
52
+ }
53
+
54
+ # === Migration từ tên cũ ===
55
+ $LegacyVersionTrack = Join-Path $CursorDir '.cursor-team-dev-version'
56
+ $LegacyRepoTrack = Join-Path $CursorDir '.cursor-team-dev-repo'
57
+ $LegacyInstallTrack = Join-Path $CursorDir '.cursor-team-dev-installed-at'
58
+ $LegacyCheckTrack = Join-Path $CursorDir '.cursor-team-dev-update-check'
59
+
60
+ $VersionTrack = Join-Path $CursorDir '.openmoneta-version'
61
+ $RepoTrack = Join-Path $CursorDir '.openmoneta-repo'
62
+ $InstallTrack = Join-Path $CursorDir '.openmoneta-installed-at'
63
+ $CheckTrack = Join-Path $CursorDir '.openmoneta-update-check'
64
+
65
+ if ((Test-Path $LegacyVersionTrack) -and (-not (Test-Path $VersionTrack))) {
66
+ Write-Host "==> Phát hiện cài đặt cũ 'Cursor Team Developer'. Migration sang 'OpenMoneta Dev Kit'..."
67
+ if (Test-Path $LegacyVersionTrack) { Move-Item $LegacyVersionTrack $VersionTrack -Force }
68
+ if (Test-Path $LegacyRepoTrack) { Move-Item $LegacyRepoTrack $RepoTrack -Force }
69
+ if (Test-Path $LegacyInstallTrack) { Move-Item $LegacyInstallTrack $InstallTrack -Force }
70
+ if (Test-Path $LegacyCheckTrack) { Remove-Item $LegacyCheckTrack -Force }
71
+ Write-Host " + Migration tracking files xong."
72
+ }
73
+
74
+ $ExistingVersion = ""
75
+ if (Test-Path $VersionTrack) {
76
+ $ExistingVersion = (Get-Content $VersionTrack -Raw).Trim()
77
+ }
78
+
79
+ if ($ExistingVersion) {
80
+ Write-Host "Phát hiện cài đặt hiện tại: v$ExistingVersion -> sẽ ghi đè bằng v$NewVersion"
81
+ } else {
82
+ Write-Host "Cài đặt mới: v$NewVersion"
83
+ }
84
+
85
+ if ((Test-Path $CursorDir) -and (-not $NoBackup)) {
86
+ Write-Host "Backup config cũ vào: $BackupDir"
87
+ }
88
+
89
+ if (-not $Yes) {
90
+ $ans = Read-Host "Tiếp tục? [y/N]"
91
+ if ($ans -notin @('y', 'Y', 'yes', 'YES')) {
92
+ Write-Host "Hủy."
93
+ exit 0
94
+ }
95
+ }
96
+
97
+ if (-not (Test-Path $CursorDir)) {
98
+ New-Item -ItemType Directory -Path $CursorDir -Force | Out-Null
99
+ }
100
+
101
+ if (-not $NoBackup) {
102
+ Write-Host ""
103
+ Write-Host "==> Backup config hiện tại..."
104
+ New-Item -ItemType Directory -Path $BackupDir -Force | Out-Null
105
+ $BackupItems = @('templates', 'skills', 'agents', 'hooks', 'scripts', 'hooks.json', '.openmoneta-version')
106
+ $Backed = 0
107
+ foreach ($item in $BackupItems) {
108
+ $src = Join-Path $CursorDir $item
109
+ if (Test-Path $src) {
110
+ Copy-Item -Path $src -Destination $BackupDir -Recurse -Force
111
+ Write-Host " + $item"
112
+ $Backed++
113
+ }
114
+ }
115
+ if ($Backed -eq 0) {
116
+ Remove-Item $BackupDir -Force -ErrorAction SilentlyContinue
117
+ Write-Host " (không có gì để backup)"
118
+ }
119
+ }
120
+
121
+ Write-Host ""
122
+ Write-Host "==> Cài đặt config mới..."
123
+ foreach ($dir in @('templates', 'skills', 'agents', 'hooks', 'scripts')) {
124
+ $target = Join-Path $CursorDir $dir
125
+ if (Test-Path $target) {
126
+ Remove-Item $target -Recurse -Force
127
+ }
128
+ Copy-Item -Path (Join-Path $RepoDir $dir) -Destination $target -Recurse -Force
129
+ Write-Host " + $dir/ (overwrite)"
130
+ }
131
+
132
+ Copy-Item -Path (Join-Path $RepoDir 'hooks.json') -Destination (Join-Path $CursorDir 'hooks.json') -Force
133
+ Write-Host " + hooks.json"
134
+
135
+ Set-Content -Path $VersionTrack -Value $NewVersion -NoNewline
136
+ Set-Content -Path $RepoTrack -Value $RepoDir -NoNewline
137
+ Set-Content -Path $InstallTrack -Value (Get-Date -Format 'yyyy-MM-ddTHH:mm:ssK') -NoNewline
138
+ if (Test-Path $CheckTrack) { Remove-Item $CheckTrack -Force }
139
+
140
+ Write-Host ""
141
+ Write-Host "================================================" -ForegroundColor Green
142
+ Write-Host "Cài đặt thành công OpenMoneta Dev Kit v$NewVersion" -ForegroundColor Green
143
+ Write-Host "================================================" -ForegroundColor Green
144
+ Write-Host ""
145
+ Write-Host "Đã cài vào: $CursorDir\"
146
+ if ((-not $NoBackup) -and (Test-Path $BackupDir)) {
147
+ Write-Host "Backup tại: $BackupDir\"
148
+ }
149
+ Write-Host ""
150
+ Write-Host "Bước tiếp theo:"
151
+ Write-Host " 1. Restart Cursor để hooks.json được load."
152
+ Write-Host " 2. Mở chat mới - quy trình 6 bước (Adaptive Planning, B6 conditional, Lean Mode v$NewVersion) sẽ tự inject."
153
+ Write-Host " 3. Áp dụng cho project: bash ~/.cursor/scripts/init-project.sh /path/to/project"
154
+ Write-Host " (Windows: chạy qua Git Bash hoặc WSL)"
155
+ Write-Host ""
156
+ Write-Host "Tài liệu chi tiết: $RepoDir\docs\INDEX.md"
157
+ Write-Host ""
158
+ Write-Host "Update sau này:"
159
+ Write-Host " pwsh $RepoDir\update.ps1"
160
+ Write-Host ""
161
+ Write-Host "Uninstall:"
162
+ Write-Host " pwsh $RepoDir\uninstall.ps1"