尧图网站设计 尧图网站设计YAOTU DESIGN
ARTICLE DETAIL

资讯详情

深耕网站设计与一线实操的经验洞察。

Plandex 如何用 .plandexignore 防止敏感文件被加载进上下文

Plandex 如何用 .plandexignore 防止敏感文件被加载进上下文 Plandex 如何用 .plandexignore 防止敏感文件被加载进上下文【免费下载链接】plandexOpen source AI coding agent. Designed for large projects and real world tasks.项目地址: https://gitcode.com/GitHub_Trending/pl/plandex使用 Plandex 时plandex load会把你指定的文件、目录含--recursive递归加载的整个目录树放进 plan 的上下文供 LLM 读取。问题在于目录里往往混着.env、密钥等不该让模型看到的内容。本文说明如何用.plandexignore文件声明忽略规则让这些敏感文件在加载上下文时被跳过并用plandex ls验证结果。忽略机制的两种来源Plandex 判断一个文件是否被忽略时参考两个来源见 Security 文档 和 Context Management 文档.gitignore如果你在 git 仓库中工作Plandex 会遵守.gitignore被忽略的文件不会加载。.plandexignore你可以在任意目录下放置一个.plandexignore文件里面写入 ignore patterns对匹配的文件生效。也就是说.gitignore依赖项目是 git 仓库而.plandexignore是 Plandex 自己的补充手段——即使文件没被 git 忽略也可以单独排除它。CLI 端在 GetPlandexIgnore 中读取并解析该文件解析失败时会报error reading .plandexignore file之类的错误所以写入内容后值得实际跑一次加载确认格式没问题。配置 .plandexignore在要保护的文件所在目录通常是项目根目录创建.plandexignore文件每行写一条 ignore pattern。文档给出的典型对象是.env.env如果敏感文件在其他位置按同样方式把对应路径写入文件即可。该文件不影响 git只影响 Plandex 的上下文加载。执行加载并观察跳过提示在已有 plan 的终端目录下加载当前目录或具体目录plandex load .如果有路径因.gitignore或.plandexignore被跳过CLI 会在加载输出后显示如下提示见 printIgnoredMsgℹ️ Due to .gitignore or .plandexignore, some paths werent loaded. Use --force / -f to load ignored paths.看到这条提示说明忽略规则已经生效被匹配的路径没有被加载。验证敏感文件确实不在上下文里用plandex ls列出当前 plan 的全部上下文输出包含索引、名称、类型和 token 大小plandex ls确认被忽略的文件如.env不在列表中。如果怀疑某个已加载的条目包含不该有的内容还可以用plandex show查看具体内容plandex show component.ts # show the content of component.ts plandex show 2 # show the content of the second item in the plandex ls list反过来如果确实需要临时加载一个被忽略的文件用--force/-f跳过忽略规则plandex load .env --force # loads the .env file even if its in .gitignore or .plandexignore该 flag 在 CLI Reference 中的说明是--force/-f: Load files even when ignored by .gitignore or .plandexignore。限制与边界.gitignore的自动遵守只在 git 仓库中生效非 git 目录里只能靠.plandexignore。忽略规则只影响是否加载进上下文。如果文件已经在上下文里忽略规则加入之前加载的需要先用plandex rm name或plandex rm 2-5按plandex ls的索引移除。上下文变更本身有版本控制记录加载与移除操作都作用于当前 plan。完成以上步骤后敏感文件即被排除在当前及后续 plan 的上下文加载之外后续如果调整了.plandexignore的内容重复一次plandex load加plandex ls的核对即可确认新的生效范围。【免费下载链接】plandexOpen source AI coding agent. Designed for large projects and real world tasks.项目地址: https://gitcode.com/GitHub_Trending/pl/plandex创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
返回列表