蓝色天空.知识 · 实践 · 创造
我的收藏
在线代码实验室

运行 Roo Code DeepSeek 配置脱敏校验与 @ 上下文文件/符号解析离线实验

PYTHONWindows x64、CPython 3.12.14、Playwright 与本地浏览器/标准库。explore-deepseek.py
explore-deepseek.py88 行
"""Offline VS Code Roo Code + DeepSeek config & @-context resolver verifier for Ch22."""
import json
import re

VERSION = "CPython 3.12.14 offline Roo Code DeepSeek config & context verifier"


def check(name, summary, expected, actual):
    return {
        "name": name,
        "summary": summary,
        "expected": expected,
        "actual": actual,
        "passed": actual == expected,
    }


def mask_secret(key: str) -> str:
    return key[:3] + "*" * max(0, len(key) - 7) + key[-4:]


def main():
    cases = []

    # Case 1: Roo Code DeepSeek provider profile, modes, and API key masking
    raw_key = "sk-demo1234567890abcd"
    config = {
        "extension_id": "RooVeterinaryInc.roo-cline",
        "provider": "deepseek",
        "api_key_masked": mask_secret(raw_key),
        "preset_modes": ["Code", "Architect", "Ask"],
        "custom_modes": ["QA"],
        "supports_ollama": True,
        "token_plan_models": ["DeepSeek", "Kimi", "GLM", "Doubao", "MiniMax"],
    }
    cases.append(
        check(
            "roo_code_deepseek_provider_config",
            "Verify Roo Code DeepSeek configuration, preset/custom modes, and masked API key handling",
            {
                "extension_id": "RooVeterinaryInc.roo-cline",
                "provider": "deepseek",
                "secret_masked": True,
                "total_modes": 4,
                "token_plan_model_count": 5,
            },
            {
                "extension_id": config["extension_id"],
                "provider": config["provider"],
                "secret_masked": raw_key not in config["api_key_masked"] and config["api_key_masked"].endswith("abcd"),
                "total_modes": len(config["preset_modes"]) + len(config["custom_modes"]),
                "token_plan_model_count": len(config["token_plan_models"]),
            },
        )
    )

    # Case 2: @-symbol context mention resolution for files & code symbols
    workspace_index = {
        "files": ["src/app.py", "src/utils.py", "tests/test_app.py"],
        "symbols": ["say_hello", "parse_config"],
    }
    prompt = "请检查 @src/app.py 中的 @say_hello 函数并补充异常校验"
    mentions = re.findall(r"@([A-Za-z0-9_./-]+)", prompt)
    resolved_files = [m for m in mentions if m in workspace_index["files"]]
    resolved_symbols = [m for m in mentions if m in workspace_index["symbols"]]
    cases.append(
        check(
            "at_context_mention_resolver",
            "Verify @-prefix file and code symbol context extraction in Roo Code chat prompt",
            {
                "mentions": ["src/app.py", "say_hello"],
                "resolved_files": ["src/app.py"],
                "resolved_symbols": ["say_hello"],
            },
            {
                "mentions": mentions,
                "resolved_files": resolved_files,
                "resolved_symbols": resolved_symbols,
            },
        )
    )

    print(json.dumps({"version": VERSION, "cases": cases}, ensure_ascii=False, indent=2))


if __name__ == "__main__":
    main()
本例需在 Windows x64、CPython 3.12.14、Playwright 与本地浏览器/标准库。 中运行,请复制源码、保存文件或下载工程包后在本地执行验证。
运行说明与环境独立工程

运行环境:Windows x64、CPython 3.12.14、Playwright 与本地浏览器/标准库。

入口文件:projects/vscode-deepseek-lab/explore-deepseek.py

本地运行步骤快速上手
  1. 点击上方“保存源码”保存为 explore-deepseek.py,或下载右侧课程工程包。
  2. 确认本地已准备 Windows x64、CPython 3.12.14、Playwright 与本地浏览器/标准库。。
  3. 按对应章节命令执行,结合正文核对实际输出。
附件与关联工程包下载

下载课程关联工程包:VS Code

课程关联工程包(登记关联1章) · 含当前章节或实例 · mbskycom202612a2207.zip

下载课程关联工程包:VS Code

课程关联工程包(登记关联25章) · 含当前章节或实例 · mbskycom202612a2203.zip
SITE SEARCH

搜索教程、工具与资讯

热门搜索

JavaScriptJSON格式化正则表达式AI 编程AI 翻译AI导航专题标签
Esc 关闭

欢迎登录蓝色天空网

使用会员账号,继续你的学习