Explorar o código

fix(evolve.ps1): 修复Windows PowerShell兼容性问题

- 添加UTF-8 BOM解决WinPS 5.x编码乱码
- 移动param()到脚本顶部(WinPS 5.x要求)
- here-string中预计算路径避免-replace嵌套解析
- Join-Path链式调用修复三层路径拼接

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
nonvioce hai 5 meses
pai
achega
38e66f64f0
Modificáronse 1 ficheiros con 21 adicións e 17 borrados
  1. 21 17
      scripts/evolve.ps1

+ 21 - 17
scripts/evolve.ps1

@@ -1,4 +1,4 @@
-#!/usr/bin/env pwsh
+#!/usr/bin/env pwsh
 # ═══════════════════════════════════════════════════════════════
 # ═══════════════════════════════════════════════════════════════
 # evolve.ps1 — novel-write 自优化编排器 (PowerShell)
 # evolve.ps1 — novel-write 自优化编排器 (PowerShell)
 # 进化结果写入 evolution/ 文件夹,不修改 SKILL.md
 # 进化结果写入 evolution/ 文件夹,不修改 SKILL.md
@@ -13,6 +13,15 @@
 #   .\evolve.ps1 -Compile      # 编译:从事件日志重建进化状态
 #   .\evolve.ps1 -Compile      # 编译:从事件日志重建进化状态
 # ═══════════════════════════════════════════════════════════════
 # ═══════════════════════════════════════════════════════════════
 
 
+param(
+    [string]$Project = "",
+    [switch]$Quick,
+    [switch]$Full,
+    [switch]$Sync,
+    [switch]$Report,
+    [switch]$Compile
+)
+
 $ErrorActionPreference = "Stop"
 $ErrorActionPreference = "Stop"
 
 
 $SCRIPT_DIR = Split-Path -Parent $MyInvocation.MyCommand.Path
 $SCRIPT_DIR = Split-Path -Parent $MyInvocation.MyCommand.Path
@@ -134,11 +143,13 @@ function Find-Project {
 function Get-GenreId {
 function Get-GenreId {
     param([string]$ProjectPath)
     param([string]$ProjectPath)
     try {
     try {
+        $scriptDirUnix = $SCRIPT_DIR -replace '\\', '/'
+        $projectPathUnix = $ProjectPath -replace '\\', '/'
         $result = & $PYTHON -c @"
         $result = & $PYTHON -c @"
-import sys; sys.path.insert(0, '$($SCRIPT_DIR -replace '\\','/')')
+import sys; sys.path.insert(0, '$scriptDirUnix')
 from utils import find_project_genre, map_genre_to_inkos_id
 from utils import find_project_genre, map_genre_to_inkos_id
 from pathlib import Path
 from pathlib import Path
-print(map_genre_to_inkos_id(find_project_genre(Path('$($ProjectPath -replace '\\','/')'))))
+print(map_genre_to_inkos_id(find_project_genre(Path('$projectPathUnix'))))
 "@ 2>$null
 "@ 2>$null
         if ($result) { return $result.Trim() }
         if ($result) { return $result.Trim() }
     } catch { }
     } catch { }
@@ -169,12 +180,13 @@ function Invoke-PhaseCollect {
     Write-Log "  题材: $genreId"
     Write-Log "  题材: $genreId"
 
 
     # 首次使用:初始化题材进化目录
     # 首次使用:初始化题材进化目录
-    $genreDir = Join-Path $EVOLUTION_DIR "genres" $genreId
+    $genreDir = Join-Path (Join-Path $EVOLUTION_DIR "genres") $genreId
     if (-not (Test-Path $genreDir)) {
     if (-not (Test-Path $genreDir)) {
         Write-Log "  初始化题材进化目录: evolution/genres/$genreId/"
         Write-Log "  初始化题材进化目录: evolution/genres/$genreId/"
         try {
         try {
+            $scriptDirUnix = $SCRIPT_DIR -replace '\\', '/'
             & $PYTHON -c @"
             & $PYTHON -c @"
-import sys; sys.path.insert(0, '$($SCRIPT_DIR -replace '\\','/')')
+import sys; sys.path.insert(0, '$scriptDirUnix')
 from seed_extractor import SeedExtractor
 from seed_extractor import SeedExtractor
 SeedExtractor().initialize_genre('$genreId')
 SeedExtractor().initialize_genre('$genreId')
 "@ 2>$null
 "@ 2>$null
@@ -233,7 +245,7 @@ function Invoke-PhaseReport {
     if ($Project) {
     if ($Project) {
         $genreId = Get-GenreId -ProjectPath $Project
         $genreId = Get-GenreId -ProjectPath $Project
         if ($genreId) {
         if ($genreId) {
-            $genreDir = Join-Path $EVOLUTION_DIR "genres" $genreId
+            $genreDir = Join-Path (Join-Path $EVOLUTION_DIR "genres") $genreId
             if (Test-Path $genreDir) {
             if (Test-Path $genreDir) {
                 Write-Host ""
                 Write-Host ""
                 Write-Host "## 题材级进化 (evolution/genres/$genreId/)" -ForegroundColor Cyan
                 Write-Host "## 题材级进化 (evolution/genres/$genreId/)" -ForegroundColor Cyan
@@ -272,9 +284,10 @@ function Invoke-PhaseReport {
     $sessionFile = Join-Path $EVOLUTION_DIR "session_state.json"
     $sessionFile = Join-Path $EVOLUTION_DIR "session_state.json"
     if (Test-Path $sessionFile) {
     if (Test-Path $sessionFile) {
         try {
         try {
+            $sessionFileUnix = $sessionFile -replace '\\', '/'
             & $PYTHON -c @"
             & $PYTHON -c @"
 import json
 import json
-state = json.loads(open('$($sessionFile -replace '\\','/')').read())
+state = json.loads(open('$sessionFileUnix').read())
 print(f'  反馈数: {state.get(\"total_feedback_count\", 0)}')
 print(f'  反馈数: {state.get(\"total_feedback_count\", 0)}')
 recent = state.get('recent_chapters', [])
 recent = state.get('recent_chapters', [])
 if recent:
 if recent:
@@ -404,7 +417,7 @@ function Main {
     if ($Project) {
     if ($Project) {
         $genreId = Get-GenreId -ProjectPath $Project
         $genreId = Get-GenreId -ProjectPath $Project
         if ($genreId) {
         if ($genreId) {
-            $genreDir = Join-Path $EVOLUTION_DIR "genres" $genreId
+            $genreDir = Join-Path (Join-Path $EVOLUTION_DIR "genres") $genreId
             if (Test-Path $genreDir) {
             if (Test-Path $genreDir) {
                 Write-Host ""
                 Write-Host ""
                 Write-Host "  evolution/ 目录内容 (题材级: $genreId):"
                 Write-Host "  evolution/ 目录内容 (题材级: $genreId):"
@@ -422,13 +435,4 @@ function Main {
 
 
 # ── 入口 ───────────────────────────────────────────────
 # ── 入口 ───────────────────────────────────────────────
 
 
-param(
-    [string]$Project = "",
-    [switch]$Quick,
-    [switch]$Full,
-    [switch]$Sync,
-    [switch]$Report,
-    [switch]$Compile
-)
-
 Main -Project $Project -Quick:$Quick -Full:$Full -Sync:$Sync -Report:$Report -Compile:$Compile
 Main -Project $Project -Quick:$Quick -Full:$Full -Sync:$Sync -Report:$Report -Compile:$Compile