diff --git a/_conf_schema.json b/_conf_schema.json index ea9fd6d..fed199f 100644 --- a/_conf_schema.json +++ b/_conf_schema.json @@ -2351,7 +2351,7 @@ "enable_detail_enhancement": { "description": "Legacy flat config: 启用日程细节强化模式", "type": "bool", - "default": false, + "default": true, "invisible": true }, "detail_enhancement_lead_minutes": { @@ -7102,7 +7102,7 @@ "description": "启用日程细节强化模式", "type": "bool", "hint": "开启后,早上生成粗日程;临近每个日程段时再调用细节强化模型,推演该段时间里可能发生的小事件、主动消息意愿和主动行为。", - "default": false + "default": true }, "detail_enhancement_lead_minutes": { "description": "提前强化日程段(分钟)", diff --git a/docs/错题本.md b/docs/错题本.md index 704e1aa..8586199 100644 --- a/docs/错题本.md +++ b/docs/错题本.md @@ -168,3 +168,13 @@ - 修复或规避:R1 实现 type+key 版本 upsert、无损容量策略、与记忆侧一致的递归隐私拒绝,并从实际活动落地路径触发归档。 - 预防规则:可靠队列必须证明“新版本不丢、未完成不删、敏感数据不落盘、生产调用真实存在”;仅有 enqueue/retry 单元测试不够。 - 验证证据:联合审查运行复现显示版本 2 后仍存版本 1、第 1 条 pending 被删除、凭据字段原样进入 DTO。 + +## 2026-07-27 - Detail enhancement defaults and Windows deployment + +- Phase: D1 implementation and VM deployment tooling. +- Type: feature behavior / deployment / testing. +- Symptom: schema, runtime fallback, and VM persisted config could independently retain `enable_detail_enhancement=False`; the Bash deploy script depended on an SSH alias and `pytest`. +- Root cause: new-install defaults and existing persistent overrides are separate paths; the script assumed a Unix developer environment. +- Fix or workaround: set all three defaults to `true`; deploy updates the VM JSON config; Bash accepts `VM`, `SSH_KEY`, `SSH_PORT`, `PYTHON_BIN`, and `SKIP_LOCAL_TESTS`; add `ops/deploy-plugin.ps1`. +- Prevention rule: configuration switches must be checked at schema, runtime fallback, and production persistence layers; cross-machine deploy commands must make SSH and test-runtime dependencies explicit. +- Validation evidence: `tests/test_d1_default_enabled.py` and `tests/test_deploy_script_windows.py`; deployment verifies service state, logs, and persisted config. \ No newline at end of file diff --git a/main.py b/main.py index 7dacfa1..601cc5a 100644 --- a/main.py +++ b/main.py @@ -1453,7 +1453,7 @@ class PrivateCompanionPlugin( self.max_proactive_plan_lag_minutes = self._cfg_int(c, "max_proactive_plan_lag_minutes", 180, 5, 1440) self._recent_inbound_message_debounce: dict[str, float] = {} self._semantic_message_buffers: dict[str, dict[str, Any]] = {} - self.enable_detail_enhancement = self._cfg_bool(c, "enable_detail_enhancement", False) + self.enable_detail_enhancement = self._cfg_bool(c, "enable_detail_enhancement", True) self.detail_enhancement_provider_id = self._cfg_str(c, "DETAIL_ENHANCEMENT_PROVIDER_ID", "") self.narration_provider_id = self._cfg_str(c, "NARRATION_PROVIDER_ID", "") self.photo_prompt_provider_id = self._cfg_str(c, "PHOTO_PROMPT_PROVIDER_ID", "") diff --git a/ops/deploy-plugin.ps1 b/ops/deploy-plugin.ps1 new file mode 100644 index 0000000..6b8e95f --- /dev/null +++ b/ops/deploy-plugin.ps1 @@ -0,0 +1,46 @@ +[CmdletBinding()] +param( + [Parameter(Mandatory = $true, Position = 0)] + [ValidateSet("memory", "companion", "both")] + [string]$Target, + + [Parameter(Position = 1, ValueFromRemainingArguments = $true)] + [string[]]$Files = @(), + + [string]$VmHost = "192.168.31.215", + [string]$VmUser = "agent", + [ValidateRange(1, 65535)] + [int]$SshPort = 22, + [string]$SshKey = (Join-Path $env:USERPROFILE ".codex\ssh\astrbot_vm_ed25519"), + [string]$PythonBin = "C:\Users\Administrator\.cache\codex-runtimes\codex-primary-runtime\dependencies\python\python.exe", + [switch]$SkipLocalTests +) + +$ErrorActionPreference = "Stop" +$repoRoot = Split-Path -Parent $PSScriptRoot +$bashCandidates = @( + "C:\Program Files\Git\bin\bash.exe", + "C:\Program Files\Git\usr\bin\bash.exe" +) +$bash = $bashCandidates | Where-Object { Test-Path $_ } | Select-Object -First 1 +if (-not $bash) { + throw "Git Bash is required. Install Git for Windows or invoke ops/deploy-plugin.sh from Bash." +} +if (-not (Test-Path $SshKey)) { throw "SSH private key not found: $SshKey" } +if (-not $SkipLocalTests -and -not (Test-Path $PythonBin)) { throw "Python interpreter not found: $PythonBin" } + +function Convert-ToGitBashPath([string]$Path) { + $converted = & $bash -lc 'cygpath -u "$1"' -- $Path + if ($LASTEXITCODE -ne 0 -or -not $converted) { throw "Could not convert path for Git Bash: $Path" } + return $converted.Trim() +} + +$env:VM = "$VmUser@$VmHost" +$env:SSH_PORT = "$SshPort" +$env:SSH_KEY = Convert-ToGitBashPath $SshKey +$env:PYTHON_BIN = if ($SkipLocalTests) { "python" } else { Convert-ToGitBashPath $PythonBin } +$env:SKIP_LOCAL_TESTS = if ($SkipLocalTests) { "1" } else { "0" } + +$script = Join-Path $PSScriptRoot "deploy-plugin.sh" +& $bash $script $Target @Files +if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } \ No newline at end of file diff --git a/ops/deploy-plugin.sh b/ops/deploy-plugin.sh index f07078f..f856094 100644 --- a/ops/deploy-plugin.sh +++ b/ops/deploy-plugin.sh @@ -20,6 +20,17 @@ set -euo pipefail VM="${VM:-astrbot-vm}" +SSH_KEY="${SSH_KEY:-}" +SSH_PORT="${SSH_PORT:-22}" +PYTHON_BIN="${PYTHON_BIN:-python}" +SKIP_LOCAL_TESTS="${SKIP_LOCAL_TESTS:-0}" +SSH_OPTS=(-o BatchMode=yes -p "$SSH_PORT") +SCP_OPTS=(-o BatchMode=yes -P "$SSH_PORT") +if [ -n "$SSH_KEY" ]; then + [ -f "$SSH_KEY" ] || { echo "错误: SSH_KEY 不存在: $SSH_KEY" >&2; exit 1; } + SSH_OPTS+=(-i "$SSH_KEY" -o IdentitiesOnly=yes) + SCP_OPTS+=(-i "$SSH_KEY" -o IdentitiesOnly=yes) +fi TARGET="${1:-}" shift || true FILES=("$@") @@ -54,19 +65,23 @@ fi echo "==> 目标主机 $VM 备份时间戳 $STAMP" -# ---------- 1. 本地门禁:不让没通过测试的代码上机 ---------- -echo "==> 本地测试" -if [ "$TARGET" = companion ] || [ "$TARGET" = both ]; then - (cd "$COMPANION_SRC" && python -m pytest tests -q) || die "陪伴侧测试未通过" -fi -if [ "$TARGET" = memory ] || [ "$TARGET" = both ]; then - (cd "$MEMORY_SRC" && python -m pytest tests -q) || die "记忆侧测试未通过" +# ---------- 1. Local gate: keep failing code off the VM ---------- +if [ "$SKIP_LOCAL_TESTS" = "1" ]; then + echo "==> Skipping local tests (SKIP_LOCAL_TESTS=1)" +else + echo "==> Local tests via $PYTHON_BIN" + if [ "$TARGET" = companion ] || [ "$TARGET" = both ]; then + (cd "$COMPANION_SRC" && "$PYTHON_BIN" -m unittest discover -s tests -q) || die "companion tests failed" + fi + if [ "$TARGET" = memory ] || [ "$TARGET" = both ]; then + (cd "$MEMORY_SRC" && "$PYTHON_BIN" -m unittest discover -s tests -q) || die "memory tests failed" + fi fi # ---------- 2. 远端备份,并把回滚指针指向这次 ---------- BACKUP="$BACKUP_ROOT/deploy-$STAMP" echo "==> 远端备份 $BACKUP" -ssh -o BatchMode=yes "$VM" "sudo mkdir -p '$BACKUP' +ssh "${SSH_OPTS[@]}" "$VM" "sudo mkdir -p '$BACKUP' for name in astrbot_plugin_memory_companion_ops astrbot_plugin_private_companion_ops; do sudo tar czf '$BACKUP'/plugin-\$name.tar.gz -C '$PLUGIN_DIR' \$name sudo cp -r '$PLUGIN_DIR'/\$name '$BACKUP'/before-\$name @@ -81,19 +96,19 @@ push_one() { if [ ${#FILES[@]} -eq 0 ]; then echo "==> 整目录替换 $name" tar czf - -C "$src" --exclude=__pycache__ --exclude=.git --exclude=.tmp . \ - | ssh -o BatchMode=yes "$VM" "cat > /tmp/$name.tar.gz" - ssh -o BatchMode=yes "$VM" "sudo rm -rf '$dest' && sudo mkdir -p '$dest' \ + | ssh "${SSH_OPTS[@]}" "$VM" "cat > /tmp/$name.tar.gz" + ssh "${SSH_OPTS[@]}" "$VM" "sudo rm -rf '$dest' && sudo mkdir -p '$dest' \ && sudo tar xzf /tmp/$name.tar.gz -C '$dest' && rm -f /tmp/$name.tar.gz" else echo "==> 增量替换 $name: ${FILES[*]}" for f in "${FILES[@]}"; do [ -f "$src/$f" ] || die "本地不存在: $src/$f" - scp -q "$src/$f" "$VM:/tmp/$(basename "$f")" - ssh -o BatchMode=yes "$VM" "sudo mkdir -p \"\$(dirname '$dest/$f')\" \ + scp -q "${SCP_OPTS[@]}" "$src/$f" "$VM:/tmp/$(basename "$f")" + ssh "${SSH_OPTS[@]}" "$VM" "sudo mkdir -p \"\$(dirname '$dest/$f')\" \ && sudo cp '/tmp/$(basename "$f")' '$dest/$f' && rm -f '/tmp/$(basename "$f")'" done fi - ssh -o BatchMode=yes "$VM" "sudo chown -R $OWNER '$dest' + ssh "${SSH_OPTS[@]}" "$VM" "sudo chown -R $OWNER '$dest' sudo find '$dest' -type d -exec chmod 755 {} + sudo find '$dest' -type f -exec chmod 644 {} + # 扫描目录里不允许留任何非插件目录(.old/.new/.bak 会被当成插件导入) @@ -106,7 +121,7 @@ sudo -u astrbot env PYTHONPYCACHEPREFIX=/tmp/pycache-deploy '$PY' -m compileall # ---------- 3. 停服 → 记忆先于陪伴 → 启动 ---------- echo "==> 停服" -ssh -o BatchMode=yes "$VM" "sudo systemctl stop astrbot" +ssh "${SSH_OPTS[@]}" "$VM" "sudo systemctl stop astrbot" # 顺序有讲究:陪伴启动时会探测记忆插件的桥,对端不在会落进负缓存 if [ "$TARGET" = memory ] || [ "$TARGET" = both ]; then @@ -117,12 +132,12 @@ if [ "$TARGET" = companion ] || [ "$TARGET" = both ]; then fi echo "==> 启动" -ssh -o BatchMode=yes "$VM" "sudo systemctl start astrbot" +ssh "${SSH_OPTS[@]}" "$VM" "sudo systemctl start astrbot" sleep 60 # ---------- 4. 验证 ---------- echo "==> 验证" -ssh -o BatchMode=yes "$VM" ' +ssh "${SSH_OPTS[@]}" "$VM" ' state=$(systemctl is-active astrbot) restarts=$(systemctl show astrbot -p NRestarts --value) echo "服务: $state NRestarts=$restarts" diff --git a/tests/test_d1_default_enabled.py b/tests/test_d1_default_enabled.py new file mode 100644 index 0000000..dd2ef5b --- /dev/null +++ b/tests/test_d1_default_enabled.py @@ -0,0 +1,35 @@ +"""D1 defaults must enable detail enhancement for all config surfaces.""" +from __future__ import annotations + +import json +import pathlib +import unittest + + +ROOT = pathlib.Path(__file__).resolve().parents[1] + + +class DetailEnhancementDefaultTests(unittest.TestCase): + def test_runtime_fallback_is_enabled(self): + source = (ROOT / "main.py").read_text(encoding="utf-8") + self.assertIn( + 'self.enable_detail_enhancement = self._cfg_bool(c, "enable_detail_enhancement", True)', + source, + ) + + def test_both_schema_entries_default_to_enabled(self): + schema = json.loads((ROOT / "_conf_schema.json").read_text(encoding="utf-8")) + self.assertIs(schema["enable_detail_enhancement"]["default"], True) + nested = [ + entry["items"]["enable_detail_enhancement"] + for entry in schema.values() + if isinstance(entry, dict) + and isinstance(entry.get("items"), dict) + and "enable_detail_enhancement" in entry["items"] + ] + self.assertEqual(len(nested), 1) + self.assertIs(nested[0]["default"], True) + + +if __name__ == "__main__": + unittest.main() diff --git a/tests/test_deploy_script_windows.py b/tests/test_deploy_script_windows.py new file mode 100644 index 0000000..61f0e7d --- /dev/null +++ b/tests/test_deploy_script_windows.py @@ -0,0 +1,25 @@ +"""The Windows deploy entrypoint must supply explicit SSH and Python settings.""" +from __future__ import annotations + +import pathlib +import unittest + + +ROOT = pathlib.Path(__file__).resolve().parents[1] + + +class WindowsDeployEntrypointTests(unittest.TestCase): + def test_bash_script_accepts_explicit_connection_and_test_settings(self): + script = (ROOT / "ops" / "deploy-plugin.sh").read_text(encoding="utf-8") + for token in ("SSH_KEY=", "SSH_PORT=", "PYTHON_BIN=", "SKIP_LOCAL_TESTS=", "SCP_OPTS="): + self.assertIn(token, script) + self.assertIn('"$PYTHON_BIN" -m unittest discover -s tests -q', script) + + def test_powershell_wrapper_supplies_vm_key_and_python(self): + wrapper = (ROOT / "ops" / "deploy-plugin.ps1").read_text(encoding="utf-8") + for token in ("VmHost = \"192.168.31.215\"", "VmUser = \"agent\"", "SshKey", "PythonBin", "SSH_KEY", "PYTHON_BIN"): + self.assertIn(token, wrapper) + + +if __name__ == "__main__": + unittest.main()